Whamcloud - gitweb
LU-3643 ofd: get data version only if file exists 24/7124/3
authorJinshan Xiong <jinshan.xiong@intel.com>
Fri, 26 Jul 2013 00:48:22 +0000 (17:48 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 29 Jul 2013 16:19:08 +0000 (16:19 +0000)
In ofd_getattr(), dt_version_get() could be called on a non-existant
object, leading to a NULL pointer for its inode.
It should try to call dt_version_get() only if attr_get returns
success; otherwise it will crash.

Signed-off-by: Jinshan Xiong <jinshan.xiong@intel.com>
Signed-off-by: Aurelien Degremont <aurelien.degremont@cea.fr>
Change-Id: I450fb78b85ea86d813ccad4de2f14f5bd4fca645
Reviewed-on: http://review.whamcloud.com/7124
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: James Nunez <james.a.nunez@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/ofd/ofd_obd.c

index 429023b..ab8c3f5 100644 (file)
@@ -1367,7 +1367,6 @@ int ofd_getattr(const struct lu_env *env, struct obd_export *exp,
        struct ofd_device       *ofd = ofd_exp(exp);
        struct ofd_thread_info  *info;
        struct ofd_object       *fo;
-       __u64                    curr_version;
        int                      rc = 0;
 
        ENTRY;
@@ -1385,19 +1384,27 @@ int ofd_getattr(const struct lu_env *env, struct obd_export *exp,
        fo = ofd_object_find(env, ofd, &info->fti_fid);
        if (IS_ERR(fo))
                GOTO(out, rc = PTR_ERR(fo));
+       if (!ofd_object_exists(fo))
+               GOTO(out_put, rc = -ENOENT);
+
        LASSERT(fo != NULL);
        rc = ofd_attr_get(env, fo, &info->fti_attr);
        oinfo->oi_oa->o_valid = OBD_MD_FLID;
-       if (rc == 0)
+       if (rc == 0) {
+               __u64 curr_version;
+
                obdo_from_la(oinfo->oi_oa, &info->fti_attr,
                             OFD_VALID_FLAGS | LA_UID | LA_GID);
 
-       /* Store object version in reply */
-       curr_version = dt_version_get(env, ofd_object_child(fo));
-       if ((__s64)curr_version != -EOPNOTSUPP) {
-               oinfo->oi_oa->o_valid |= OBD_MD_FLDATAVERSION;
-               oinfo->oi_oa->o_data_version = curr_version;
+               /* Store object version in reply */
+               curr_version = dt_version_get(env, ofd_object_child(fo));
+               if ((__s64)curr_version != -EOPNOTSUPP) {
+                       oinfo->oi_oa->o_valid |= OBD_MD_FLDATAVERSION;
+                       oinfo->oi_oa->o_data_version = curr_version;
+               }
        }
+
+out_put:
        ofd_object_put(env, fo);
 out:
        RETURN(rc);