Whamcloud - gitweb
LU-3203 mdd: check result of dt_trans_create() using IS_ERR().
authorJohn L. Hammond <john.hammond@intel.com>
Mon, 22 Apr 2013 19:18:38 +0000 (14:18 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 1 May 2013 06:59:41 +0000 (02:59 -0400)
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 <john.hammond@intel.com>
Change-Id: I4a5c53d3efa9c69c1428a8e5a875a531c9206d12
Reviewed-on: http://review.whamcloud.com/6117
Tested-by: Hudson
Reviewed-by: Fan Yong <fan.yong@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/mdd/mdd_compat.c
lustre/mdd/mdd_object.c
lustre/mdd/mdd_orphans.c
lustre/obdclass/local_storage.c

index 91b97ea..76b5511 100644 (file)
@@ -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);
 }
 
index 7c338e8..a73e5b3 100644 (file)
@@ -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;
 }
 
 /*
index 38e9849..8b48962 100644 (file)
@@ -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);
index 80d0439..7f5fd79 100644 (file)
@@ -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;