Whamcloud - gitweb
LU-5144 mdt: rename vs link deadlock 70/10570/4
authorVitaly Fertman <vitaly_fertman@xyratex.com>
Tue, 3 Jun 2014 10:58:13 +0000 (14:58 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 16 Jun 2014 01:53:53 +0000 (01:53 +0000)
it may happen that tgt child for rename is a directory, which is used
as tgt dir for link in parallel, as the result rename locks src child,
tgt child what may deadlock with tgt dir, src file locking of link.

As not dir cannot replace dir, check it before locking the tgt child.

Signed-off-by: Vitaly Fertman <vitaly_fertman@xyratex.com>
Xyratex-bug-id: MRP-1921
Change-Id: If8b91d27e4d978853e4b8fbb025667d22c9d2f02
Reviewed-on: http://review.whamcloud.com/10570
Tested-by: Jenkins
Tested-by: Oleg Drokin <oleg.drokin@intel.com>
Reviewed-by: wangdi <di.wang@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_reint.c
lustre/tests/sanityn.sh

index e76bf9d..fc4461c 100644 (file)
@@ -1118,6 +1118,8 @@ static int mdt_reint_link(struct mdt_thread_info *info,
         if (rc)
                 GOTO(out_unlock_parent, rc);
 
         if (rc)
                 GOTO(out_unlock_parent, rc);
 
+       OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
+
         /* step 2: find & lock the source */
         lhs = &info->mti_lh[MDT_LH_CHILD];
         mdt_lock_reg_init(lhs, LCK_EX);
         /* step 2: find & lock the source */
         lhs = &info->mti_lh[MDT_LH_CHILD];
         mdt_lock_reg_init(lhs, LCK_EX);
@@ -1879,6 +1881,10 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info,
                        GOTO(out_put_new, rc = -EXDEV);
                }
 
                        GOTO(out_put_new, rc = -EXDEV);
                }
 
+               if (S_ISDIR(lu_object_attr(&mnew->mot_obj)) &&
+                   !S_ISDIR(lu_object_attr(&mold->mot_obj)))
+                       GOTO(out_put_new, rc = -EISDIR);
+
                lh_oldp = &info->mti_lh[MDT_LH_OLD];
                mdt_lock_reg_init(lh_oldp, LCK_EX);
                rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
                lh_oldp = &info->mti_lh[MDT_LH_OLD];
                mdt_lock_reg_init(lh_oldp, LCK_EX);
                rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
index 4b46cc4..bcf6199 100644 (file)
@@ -2473,6 +2473,31 @@ test_55b()
 }
 run_test 55b "rename vs unlink source dir"
 
 }
 run_test 55b "rename vs unlink source dir"
 
+test_55d()
+{
+       touch $DIR/f1
+
+#define OBD_FAIL_MDS_RENAME3              0x155
+       do_facet mds $LCTL set_param fail_loc=0x155
+       mv $DIR/f1 $DIR/d1 &
+       PID1=$!
+       sleep 2
+
+       # while rename is sleeping, create d2, but as a directory
+       mkdir -p $DIR2/d1 || error "(1) mkdir failed"
+
+       # link in reverse locking order
+       ln $DIR2/f1 $DIR2/d1/
+
+       wait $PID1 && error "(2) mv succeeded"
+       lctl dk > ../log1
+       ls -la $DIR/
+       ls -la $DIR/d1
+
+       rm -rf $DIR/d1
+}
+run_test 55d "rename file vs link"
+
 test_60() {
        [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
        { skip "Need MDS version at least 2.3.0"; return; }
 test_60() {
        [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
        { skip "Need MDS version at least 2.3.0"; return; }