From b2c2cfc24fa461b3e54cd204a697eeee9a89d49c Mon Sep 17 00:00:00 2001 From: Vitaly Fertman Date: Tue, 3 Jun 2014 14:58:13 +0400 Subject: [PATCH] LU-5144 mdt: rename vs link deadlock 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 Xyratex-bug-id: MRP-1921 Change-Id: If8b91d27e4d978853e4b8fbb025667d22c9d2f02 Reviewed-on: http://review.whamcloud.com/10570 Tested-by: Jenkins Tested-by: Oleg Drokin Reviewed-by: wangdi Reviewed-by: John L. Hammond Tested-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_reint.c | 6 ++++++ lustre/tests/sanityn.sh | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index e76bf9d..fc4461c 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -1118,6 +1118,8 @@ static int mdt_reint_link(struct mdt_thread_info *info, 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); @@ -1879,6 +1881,10 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, 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 | diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 4b46cc4..bcf6199 100644 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -2473,6 +2473,31 @@ test_55b() } 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; } -- 1.8.3.1