From e656cccbdcf3793c9a036fab265400a3ebddf5e5 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Fri, 27 Nov 2020 14:00:46 +0300 Subject: [PATCH] LU-14156 utils: mirror split to check for last in-sync early currently this check to prevent last in-sync component is done once the file is open with O_RDWR which interrupts on-going resync/extend process. instead we can do this check early once the layout is fetched (after the first open with O_RDONLY). Signed-off-by: Alex Zhuravlev Change-Id: Iee08d23008b44d2a7b2127358116a95ace40b7dd Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/40782 Reviewed-by: Andreas Dilger Reviewed-by: Zhenyu Xu Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/tests/sanity.sh | 30 ++++++++++++++++++++++++++++++ lustre/utils/lfs.c | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index c7186a1..3c73faf 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -20414,6 +20414,36 @@ test_210() { } run_test 210 "lfs getstripe does not break leases" +function test_211() { + local PID + local id + local rc + + stack_trap "rm -f $DIR/$tfile" EXIT + dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=10 oflag=direct || + error "can't create file" + $LFS mirror extend -N $DIR/$tfile || + error "can't create a replica" + dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1 oflag=direct + $LFS getstripe $DIR/$tfile + stale=$($LFS getstripe $DIR/$tfile | grep stale | wc -l) + (( $stale != 1 )) && error "expected 1 stale, found $stale" + + $MULTIOP $DIR/$tfile OeW_E+eUc & + PID=$! + sleep 0.3 + + id=$($LFS getstripe $DIR/$tfile | + awk '/lcme_mirror_id:/{id=$2}/lcme_flags.*init$/{print id}') + $LFS mirror split -d --mirror-id $id $DIR/$tfile && + error "removed last in-sync replica?" + + kill -USR1 $PID + wait $PID + (( $? == 0 )) || error "failed split broke the lease" +} +run_test 211 "failed mirror split doesn't break write lease" + test_212() { size=`date +%s` size=$((size % 8192 + 1)) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 6c439de..bab249e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2318,6 +2318,14 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, } } + if (last_non_stale_mirror(mirror_id, layout)) { + rc = -EUCLEAN; + fprintf(stderr, + "%s: cannot destroy the last non-stale mirror of file '%s'\n", + progname, fname); + goto free_layout; + } + if (!victim_file && mflags & MF_DESTROY) /* Allow mirror split even without the key on encrypted files, * and in this case of a 'split -d', open file with O_DIRECT -- 1.8.3.1