From: Yang Sheng Date: Fri, 22 Nov 2024 01:52:58 +0000 (+0800) Subject: LU-17276 flock: fix for lock split X-Git-Tag: 2.16.52~81 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=f785bca0a92e499493fa0702fe7c0fb05e7b51ca;p=fs%2Flustre-release.git LU-17276 flock: fix for lock split Fix the logic in lock split case. Also add test case to verify it works well. Fixes: ea012dfb2a (LU-17276 ldlm: use interval tree for searching in flock) Signed-off-by: Yang Sheng Change-Id: I9599592eba217ce79956c45c0bbb58a7f5e805d0 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57105 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Andreas Dilger Reviewed-by: Andriy Skulysh Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/ldlm/ldlm_flock.c b/lustre/ldlm/ldlm_flock.c index 46cdda0..14dd612 100644 --- a/lustre/ldlm/ldlm_flock.c +++ b/lustre/ldlm/ldlm_flock.c @@ -554,7 +554,8 @@ reprocess: continue; } if (LAST(new) >= LAST(lock)) { - ldlm_flock_range_update(lock, START(lock), LAST(new) - 1); + ldlm_flock_range_update(lock, START(lock), + START(new) - 1); continue; } diff --git a/lustre/tests/flocks_test.c b/lustre/tests/flocks_test.c index b734f96..e6bbd29 100644 --- a/lustre/tests/flocks_test.c +++ b/lustre/tests/flocks_test.c @@ -845,8 +845,8 @@ static int t6(int argc, char *argv[]) } rc = t_fcntl(get_cfd(), F_OFD_SETLKW, &lock); if (rc != 0) { - fprintf(stderr, "%d: cannot set lock: %s\n", - getpid(), strerror(errno)); + fprintf(stderr, "%s: cannot set lock(%d): %s\n", + argv[0], errno, strerror(errno)); rc = EXIT_FAILURE; break; } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e5d5217..a22a0d8 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -13713,6 +13713,50 @@ test_105g() { } run_test 105g "ldlm_lock_debug stack test" +test_105h() { + local info + touch $DIR/$tfile + + stack_trap "rm $DIR/$tfile" EXIT + # enqueue 2 non-overlap locks + info=$(echo -e "W20,40\nR100,200\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xW20,40;R100,200.' ] || error "flock error1-$info" + # enqueue overlap locks + info=$(echo -e "W20,400\nR100,2000\nR10,1000\nW500,1000\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xR10,490;W500,1000;R1500,600.' ] || error "flock error2-$info" + # split a lock + info=$(echo -e "W2000,1000\nR2200, 200\nT0" |flocks_test 6 $DIR/$tfile) + [ x$info == 'xW2000,200;R2200,200;W2400,600.' ] || error "flock error3-$info" + # merge 2 locks + info=$(echo -e "R200,1000\nR9000,200\nW100,10000\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xW100,10000.' ] || error "flock error4-$info" + # adjoining locks + info=$(echo -e "R200,100\nR300, 200\nR500,100\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xR200,400.' ] || error "flock error5-$info" + # adjoining locks with diff mode + info=$(echo -e "R200,100\nW300, 200\nR500,100\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xR200,100;W300,200;R500,100.' ] || error "flock error6-$info" + # split & merge + info=$(echo -e "R200,1000\nW300, 200\nR100,200\nR300,200\nT0" | flocks_test 6 $DIR/$tfile) + [ x$info == 'xR100,1100.' ] || error "flock error7-$info" +} +run_test 105h "Flock functional verify" + +test_105i() { + local tmpfile=$TMP/tmpf.$$ + touch $DIR/$tfile + + stack_trap "rm $tmpfile $DIR/$tfile" EXIT + # enqueue 2 non-overlap locks + >$tmpfile + echo -e "R20,200\nP5\nW10,1000" | flocks_test 6 $DIR/$tfile 2>>$tmpfile & + echo -e "R20,200\nP5\nW10,1000" | flocks_test 6 $DIR/$tfile 2>>$tmpfile & + wait + # Check for EDEADLK + grep 'cannot set lock(35)' $tmpfile +} +run_test 105i "Flock deadlock verify" + test_106() { #bug 10921 test_mkdir $DIR/$tdir $DIR/$tdir && error "exec $DIR/$tdir succeeded"