From a4d5ae9810bab13c2c46c02145aeb8963aa8e4a2 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Wed, 17 Jun 2020 17:05:28 +0300 Subject: [PATCH] LU-13668 mdt: change lock mode for lease make it PW so that lfs getstripe and open-for-read do not interrupt replication. Lustre-change: https://review.whamcloud.com/38964 Lustre-commit: TBD (from a1738536459d9ea87b4d89e54cde624487fbc53d) Signed-off-by: Alex Zhuravlev Change-Id: I20f4bbbc4e7bf9055333aba1b8cca80aa899c664 Reviewed-on: https://review.whamcloud.com/41840 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/mdt/mdt_open.c | 11 +++++++---- lustre/tests/sanity-pcc.sh | 2 +- lustre/tests/sanity.sh | 12 ++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index ef12eb1..0bdeb34 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -868,8 +868,8 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, GOTO(out, rc = -EPROTO); } - /* XXX: only exclusive open is supported. */ - lm = LCK_EX; + /* should conflict with new opens for write/execute */ + lm = LCK_PW; *ibits = MDS_INODELOCK_OPEN; /* never grant LCK_EX layout lock to client */ @@ -987,8 +987,11 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, PFID(mdt_object_fid(obj)), atomic_read(&obj->mot_open_count), open_count); - if (atomic_read(&obj->mot_open_count) > open_count) - GOTO(out, rc = -EBUSY); + if (atomic_read(&obj->mot_open_count) > open_count) { + /* fail if anyone *else* has opened file for write */ + if (mdt_write_read(obj) > 1) + GOTO(out, rc = -EBUSY); + } } GOTO(out, rc); diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index 3ed0599..91cad2c 100644 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -1044,7 +1044,7 @@ test_12() { sleep 3 wait_request_state $(path2fid $file) RESTORE SUCCEED $LFS hsm_remove $file || error "hsm remove $file failed" - wait $pid && error "RW-PCC attach $file should fail" + wait $pid do_facet $SINGLEAGT "[ -f $lpcc_path ]" && error "RW-PCC cached file '$lpcc_path' should be removed" diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index ce8630e..fe21cfe 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -17015,23 +17015,23 @@ test_208() { $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error" echo "==== test 2: verify lease can be broken by upcoming open" - $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc & + $MULTIOP $DIR/$tfile oO_RDWR:eR_E-eUc & local PID=$! sleep 1 - $MULTIOP $DIR/$tfile oO_RDONLY:c + $MULTIOP $DIR/$tfile oO_RDWR:c kill -USR1 $PID && wait $PID || error "break lease error" echo "==== test 3: verify lease can't be granted if an open already exists" - $MULTIOP $DIR/$tfile oO_RDONLY:_c & + $MULTIOP $DIR/$tfile oO_RDWR:_c & local PID=$! sleep 1 - $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail" + $MULTIOP $DIR/$tfile oO_RDWR:eReUc && error "apply lease should fail" kill -USR1 $PID && wait $PID || error "open file error" echo "==== test 4: lease can sustain over recovery" - $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc & + $MULTIOP $DIR/$tfile oO_RDWR:eR_E+eUc & PID=$! sleep 1 @@ -17040,7 +17040,7 @@ test_208() { kill -USR1 $PID && wait $PID || error "lease broken over recovery" echo "==== test 5: lease broken can't be regained by replay" - $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc & + $MULTIOP $DIR/$tfile oO_RDWR:eR_E-eUc & PID=$! sleep 1 -- 1.8.3.1