Whamcloud - gitweb
LU-1546 mdd: return nlink as zero for dead objects
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 16 Jan 2013 11:53:19 +0000 (05:53 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 27 Feb 2013 09:33:38 +0000 (04:33 -0500)
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 <john.hammond@intel.com>
Reviewed-on: http://review.whamcloud.com/3154
Tested-by: Hudson
Reviewed-by: Bobi Jam <bobijam@gmail.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/mdd/mdd_object.c
lustre/tests/sanity.sh

index 5dbb9ef..5844799 100644 (file)
@@ -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 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);
 }
 
 /*
 }
 
 /*
index 052ddfa..16a0410 100644 (file)
@@ -2001,6 +2001,22 @@ test_31m() {
 }
 run_test 31m "link to file: the same, non-existing, dir==============="
 
 }
 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
 cleanup_test32_mount() {
        trap 0
        $UMOUNT $DIR/$tdir/ext2-mountpoint