From 413b6c2e365cf3ff986611e20dd77186ed25a3ac Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 16 Jan 2013 05:53:19 -0600 Subject: [PATCH] LU-1546 mdd: return nlink as zero for dead objects In mdd_attr_get_internal() check for dead objects and set nlink to zero accordingly. Add a sanity check to verify that this works as expected. Change-Id: I9dd574cce63bcbf47c9f8f3c7ae6d151c704a45a Signed-off-by: John L. Hammond Reviewed-on: http://review.whamcloud.com/3154 Tested-by: Hudson Reviewed-by: Bobi Jam Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/mdd/mdd_object.c | 15 ++++++++++----- lustre/tests/sanity.sh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 5dbb9ef..5844799 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -532,12 +532,17 @@ int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj) int mdd_attr_get(const struct lu_env *env, struct md_object *obj, struct md_attr *ma) { - int rc; - ENTRY; + struct mdd_object *mdd_obj = md2mdd_obj(obj); + int rc; - return mdd_la_get(env, md2mdd_obj(obj), &ma->ma_attr, - mdd_object_capa(env, md2mdd_obj(obj))); - RETURN(rc); + ENTRY; + + rc = mdd_la_get(env, mdd_obj, &ma->ma_attr, + mdd_object_capa(env, md2mdd_obj(obj))); + if ((ma->ma_need & MA_INODE) != 0 && mdd_is_dead_obj(mdd_obj)) + ma->ma_attr.la_nlink = 0; + + RETURN(rc); } /* diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 052ddfa..16a0410 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2001,6 +2001,22 @@ test_31m() { } run_test 31m "link to file: the same, non-existing, dir===============" +test_31n() { + [ -e /proc/self/fd/173 ] && echo "skipping, fd 173 is in use" && return + touch $DIR/$tfile || error "cannot create '$DIR/$tfile'" + nlink=$(stat --format=%h $DIR/$tfile) + [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1" + exec 173<$DIR/$tfile + trap "exec 173<&-" EXIT + nlink=$(stat --dereference --format=%h /proc/self/fd/173) + [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1" + rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'" + nlink=$(stat --dereference --format=%h /proc/self/fd/173) + [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0" + exec 173<&- +} +run_test 31n "check link count of unlinked file" + cleanup_test32_mount() { trap 0 $UMOUNT $DIR/$tdir/ext2-mountpoint -- 1.8.3.1