Whamcloud - gitweb
LU-14156 utils: mirror split to check for last in-sync early 82/40782/47
authorAlex Zhuravlev <bzzz@whamcloud.com>
Fri, 27 Nov 2020 11:00:46 +0000 (14:00 +0300)
committerOleg Drokin <green@whamcloud.com>
Thu, 31 Aug 2023 06:21:00 +0000 (06:21 +0000)
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 <bzzz@whamcloud.com>
Change-Id: Iee08d23008b44d2a7b2127358116a95ace40b7dd
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/40782
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Zhenyu Xu <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/lfs.c

index c7186a1..3c73faf 100755 (executable)
@@ -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))
index 6c439de..bab249e 100644 (file)
@@ -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