From 8ef1b1f59948970b828d889ba8afabc2cc57e8cf Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 22 Apr 2013 14:18:38 -0500 Subject: [PATCH] LU-3203 mdd: check result of dt_trans_create() using IS_ERR(). In mdd_convert_linkea() and orphan_object_destroy() check the result of dt_trans_create() using IS_ERR(). In mdd_close() avoid passing an error pointer to mdd_trans_stop(). In local_oid_storage_init() avoid a spurious mutex unlock after failure in dt_trans_create(). Trivially simplify cleanup in mdd_convert_remove_dots() and mdd_convert_lma(). Signed-off-by: John L. Hammond Change-Id: I4a5c53d3efa9c69c1428a8e5a875a531c9206d12 Reviewed-on: http://review.whamcloud.com/6117 Tested-by: Hudson Reviewed-by: Fan Yong Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/mdd/mdd_compat.c | 19 ++++++++++--------- lustre/mdd/mdd_object.c | 9 +++++---- lustre/mdd/mdd_orphans.c | 11 ++++++----- lustre/obdclass/local_storage.c | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lustre/mdd/mdd_compat.c b/lustre/mdd/mdd_compat.c index 91b97ea..76b5511 100644 --- a/lustre/mdd/mdd_compat.c +++ b/lustre/mdd/mdd_compat.c @@ -56,7 +56,7 @@ static int mdd_convert_remove_dots(const struct lu_env *env, struct mdd_device *mdd, struct mdd_object *o) { - struct thandle *th = NULL; + struct thandle *th; const struct dt_key *dot = (const struct dt_key *)"."; const struct dt_key *dotdot = (const struct dt_key *)".."; int rc; @@ -68,6 +68,7 @@ static int mdd_convert_remove_dots(const struct lu_env *env, th = dt_trans_create(env, mdd->mdd_child); if (IS_ERR(th)) RETURN(PTR_ERR(th)); + rc = dt_declare_delete(env, mdd_object_child(o), dot, th); if (rc) GOTO(out, rc); @@ -91,8 +92,7 @@ static int mdd_convert_remove_dots(const struct lu_env *env, GOTO(out, rc); out: - if (th) - dt_trans_stop(env, mdd->mdd_child, th); + dt_trans_stop(env, mdd->mdd_child, th); RETURN(rc); } @@ -101,12 +101,15 @@ static int mdd_convert_linkea(const struct lu_env *env, struct mdd_object *o, const struct lu_name *name) { - struct thandle *th = NULL; + struct thandle *th; struct lu_fid oldfid; int rc; ENTRY; th = dt_trans_create(env, mdd->mdd_child); + if (IS_ERR(th)) + RETURN(PTR_ERR(th)); + rc = mdd_declare_links_add(env, o, th, NULL); if (rc) GOTO(out, rc); @@ -123,8 +126,7 @@ static int mdd_convert_linkea(const struct lu_env *env, rc = 0; out: - if (th) - dt_trans_stop(env, mdd->mdd_child, th); + dt_trans_stop(env, mdd->mdd_child, th); RETURN(rc); } @@ -171,7 +173,7 @@ static int mdd_convert_lma(const struct lu_env *env, struct mdd_device *mdd, struct mdd_object *o) { struct lustre_mdt_attrs *lma; - struct thandle *th = NULL; + struct thandle *th; struct lu_fid fid; struct lu_buf buf; int rc; @@ -196,8 +198,7 @@ static int mdd_convert_lma(const struct lu_env *env, struct mdd_device *mdd, GOTO(out, rc); rc = mdo_xattr_set(env, o, &buf, XATTR_NAME_LMA, 0, th, BYPASS_CAPA); out: - if (th) - dt_trans_stop(env, mdd->mdd_child, th); + dt_trans_stop(env, mdd->mdd_child, th); RETURN(rc); } diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 7c338e8..a73e5b3 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1738,7 +1738,7 @@ out: if (handle == NULL) { handle = mdd_trans_create(env, mdo2mdd(obj)); if (IS_ERR(handle)) - GOTO(stop, rc = IS_ERR(handle)); + GOTO(stop, rc = PTR_ERR(handle)); rc = mdd_declare_changelog_store(env, mdd, NULL, handle); @@ -1755,9 +1755,10 @@ out: } stop: - if (handle != NULL) - mdd_trans_stop(env, mdd, rc, handle); - return rc; + if (handle != NULL && !IS_ERR(handle)) + mdd_trans_stop(env, mdd, rc, handle); + + return rc; } /* diff --git a/lustre/mdd/mdd_orphans.c b/lustre/mdd/mdd_orphans.c index 38e9849..8b48962 100644 --- a/lustre/mdd/mdd_orphans.c +++ b/lustre/mdd/mdd_orphans.c @@ -326,11 +326,12 @@ static int orphan_object_destroy(const struct lu_env *env, int rc = 0; ENTRY; - th = mdd_trans_create(env, mdd); - if (IS_ERR(th)) { - CERROR("Cannot get thandle\n"); - RETURN(-ENOMEM); - } + th = mdd_trans_create(env, mdd); + if (IS_ERR(th)) { + CERROR("Cannot get thandle\n"); + RETURN(PTR_ERR(th)); + } + rc = orph_declare_index_delete(env, obj, th); if (rc) GOTO(stop, rc); diff --git a/lustre/obdclass/local_storage.c b/lustre/obdclass/local_storage.c index 80d0439..7f5fd79 100644 --- a/lustre/obdclass/local_storage.c +++ b/lustre/obdclass/local_storage.c @@ -738,7 +738,7 @@ int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev, th = dt_trans_create(env, dev); if (IS_ERR(th)) - GOTO(out_lock, rc = PTR_ERR(th)); + GOTO(out_los, rc = PTR_ERR(th)); dti->dti_attr.la_valid = LA_MODE | LA_TYPE; dti->dti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; -- 1.8.3.1