From 24429b8219351b2ea32435a8b683161db53fd123 Mon Sep 17 00:00:00 2001 From: Jinshan Xiong Date: Thu, 25 Jul 2013 17:48:22 -0700 Subject: [PATCH] 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 --- lustre/ofd/ofd_obd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index c93f6d1..0c1df46 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -1365,7 +1365,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; @@ -1383,19 +1382,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); -- 1.8.3.1