From: Jinshan Xiong Date: Fri, 26 Jul 2013 00:48:22 +0000 (-0700) Subject: LU-3643 ofd: get data version only if file exists X-Git-Tag: 2.4.53~8 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F7124%2F3;p=fs%2Flustre-release.git LU-3643 ofd: get data version only if file exists 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 Signed-off-by: Aurelien Degremont Change-Id: I450fb78b85ea86d813ccad4de2f14f5bd4fca645 Reviewed-on: http://review.whamcloud.com/7124 Tested-by: Hudson Tested-by: Maloo Reviewed-by: James Nunez Reviewed-by: Oleg Drokin --- diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index 429023b..ab8c3f5 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -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);