Whamcloud - gitweb
LU-5957 mdt: Update MDT flags after layout swap 77/12877/2
authorHenri Doreau <henri.doreau@cea.fr>
Thu, 27 Nov 2014 13:51:09 +0000 (14:51 +0100)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 3 Feb 2015 18:09:56 +0000 (18:09 +0000)
Swap MOF_LOV_CREATED flags between MDT objects after a layout swap to
guarantee that layout will be re-created on next write if its LOV has
been deleted.

Signed-off-by: Henri Doreau <henri.doreau@cea.fr>
Change-Id: I3d0497d8be2a7335c1fb43e10af2b222243e6a81
Reviewed-on: http://review.whamcloud.com/12877
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: frank zago <fzago@cray.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_handler.c
lustre/tests/sanity.sh

index b19f7c7..aec10b3 100644 (file)
@@ -1234,6 +1234,32 @@ out:
        return rc;
 }
 
+/**
+ * Exchange MOF_LOV_CREATED flags between two objects after a
+ * layout swap. No assumption is made on whether o1 or o2 have
+ * created objects or not.
+ *
+ * \param[in,out] o1   First swap layout object
+ * \param[in,out] o2   Second swap layout object
+ */
+static void mdt_swap_lov_flag(struct mdt_object *o1, struct mdt_object *o2)
+{
+       __u64   o1_flags;
+
+       mutex_lock(&o1->mot_lov_mutex);
+       mutex_lock(&o2->mot_lov_mutex);
+
+       o1_flags = o1->mot_flags;
+       o1->mot_flags = (o1->mot_flags & ~MOF_LOV_CREATED) |
+                       (o2->mot_flags & MOF_LOV_CREATED);
+
+       o2->mot_flags = (o2->mot_flags & ~MOF_LOV_CREATED) |
+                       (o1_flags & MOF_LOV_CREATED);
+
+       mutex_unlock(&o2->mot_lov_mutex);
+       mutex_unlock(&o1->mot_lov_mutex);
+}
+
 static int mdt_swap_layouts(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info;
@@ -1319,7 +1345,11 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi)
 
        rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
                             mdt_object_child(o2), msl->msl_flags);
-       GOTO(unlock2, rc);
+       if (rc < 0)
+               GOTO(unlock2, rc);
+
+       mdt_swap_lov_flag(o1, o2);
+
 unlock2:
        mdt_object_unlock(info, o2, lh2, rc);
 unlock1:
index e06ab8e..b22ccfe 100644 (file)
@@ -11148,6 +11148,39 @@ test_184d() {
 }
 run_test 184d "allow stripeless layouts swap"
 
+test_184e() {
+       check_swap_layouts_support && return 0
+       [ -z "$(which getfattr 2>/dev/null)" ] &&
+               skip "no getfattr command" && return 0
+
+       local file1=$DIR/$tdir/$tfile-1
+       local file2=$DIR/$tdir/$tfile-2
+       local file3=$DIR/$tdir/$tfile-3
+       local lovea
+
+       mkdir -p $DIR/$tdir
+       touch $file1 || error "create $file1 failed"
+       $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
+               error "create $file2 failed"
+       $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
+               error "create $file3 failed"
+
+       $LFS swap_layouts $file1 $file2 ||
+               error "swap $file1 $file2 layouts failed"
+
+       lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
+       [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
+
+       echo 123 > $file1 || error "Should be able to write into $file1"
+
+       $LFS swap_layouts $file1 $file3 ||
+               error "swap $file1 $file3 layouts failed"
+
+       echo 123 > $file1 || error "Should be able to write into $file1"
+
+       rm -rf $file1 $file2 $file3
+}
+run_test 184e "Recreate layout after stripeless layout swaps"
 
 test_185() { # LU-2441
        # LU-3553 - no volatile file support in old servers