Whamcloud - gitweb
LU-18468 llapi: always truncate mirrors on resync 90/57090/5
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 20 Nov 2024 20:28:55 +0000 (15:28 -0500)
committerOleg Drokin <green@whamcloud.com>
Mon, 9 Dec 2024 06:03:22 +0000 (06:03 +0000)
When mirrors are synced, all mirrors should be truncated to
match the size of the source/primary mirror.  This was
skipped if the size was unaligned, but that is a mistake.

Test-Parameters: testlist=sanity-flr,sanity-flr,sanity-flr
Test-Parameters: testlist=sanity-pfl,sanity-pfl,sanity-pfl
Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I767a1b3ef58c855f57967228d37b04fa0ab87e57
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57090
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Zhenyu Xu <bobijam@hotmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-flr.sh
lustre/utils/liblustreapi_layout.c
lustre/utils/liblustreapi_mirror.c

index 69778e5..93155a2 100644 (file)
@@ -4535,6 +4535,33 @@ test_210b() {
 }
 run_test 210b "handle broken mirrored lovea (unlink)"
 
+# LU-18468
+test_211() {
+       local tf=$DIR/$tfile
+
+       dd if=/dev/zero of=$tf bs=4k count=10 oflag=direct ||
+               error "error writing initial data to '$tf'"
+
+       $LFS mirror extend -N $tf || error "error extending mirror for '$tf'"
+
+       dd if=/dev/zero of=$tf bs=4k count=1 oflag=direct ||
+               error "error writing 4k to '$tf'"
+       echo "size after second write"
+       ls -la $tf
+       md5_1=$(md5sum $tf) || error "error getting first md5sum of '$tf'"
+
+       $LFS mirror resync $tf || error "error resync-ing '$tf'"
+
+       $LFS mirror delete --mirror-id=1 $tf ||
+               error "error deleting mirror 1 of '$tf'"
+       echo "size after mirror delete"
+       ls -la $tf
+       md5_2=$(md5sum $tf) || error "error getting second md5sum of '$tf'"
+       [[ "${md5_1%% *}" = "${md5_2%% *}" ]] ||
+               error "md5sums don't match after mirror ops on '$tf'"
+}
+run_test 211 "mirror delete should not cause bad size"
+
 complete_test $SECONDS
 check_and_cleanup_lustre
 exit_status
index 7e3ad0d..e61ef67 100644 (file)
@@ -3254,15 +3254,13 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout,
        size_t total_bytes_read = 0;
        size_t total_bytes_written = 0;
        off_t write_estimation_bytes = 0;
+       struct stat st;
 
-       if (bandwidth_bytes_sec > 0 || stats_interval_sec) {
-               struct stat st;
-
-               rc = fstat(fd, &st);
-               if (rc < 0)
-                       return -errno;
+       rc = fstat(fd, &st);
+       if (rc < 0)
+               return -errno;
+       if (bandwidth_bytes_sec > 0 || stats_interval_sec)
                write_estimation_bytes = st.st_size * comp_size;
-       }
 
        /* limit transfer size to what can be sent in one second */
        if (bandwidth_bytes_sec && bandwidth_bytes_sec < buflen)
@@ -3522,17 +3520,28 @@ do_read:
         * reflect its true meaning.
         */
        for (i = 0; i < comp_size; i++) {
-               comp_array[i].lrc_synced = !comp_array[i].lrc_synced;
-               if (comp_array[i].lrc_synced && pos & (page_size - 1)) {
-                       rc = llapi_mirror_truncate(fd,
-                                       comp_array[i].lrc_mirror_id, pos);
-                       /* Ignore truncate error on encrypted file without the
-                        * key if tried on LUSTRE_ENCRYPTION_UNIT_SIZE boundary.
-                        */
-                       if (rc < 0 && (rc != -ENOKEY ||
-                                      pos & ~LUSTRE_ENCRYPTION_MASK))
-                               comp_array[i].lrc_synced = false;
+               struct llapi_resync_comp *comp = comp_array + i;
+
+               comp->lrc_synced = !comp->lrc_synced;
+
+               if (!comp->lrc_synced)
+                       continue;
+               if (pos < comp->lrc_start || pos >= comp->lrc_end)
+                       continue;
+
+               if (pos < st.st_size) {
+                       llapi_mirror_punch(fd, comp->lrc_mirror_id, pos,
+                                          comp_array[i].lrc_end - pos);
+                       continue;
                }
+
+               rc = llapi_mirror_truncate(fd, comp->lrc_mirror_id, pos);
+               /* Ignore truncate error on encrypted file without the
+                * key if tried on LUSTRE_ENCRYPTION_UNIT_SIZE boundary.
+                */
+               if (rc < 0 && (rc != -ENOKEY ||
+                              pos & ~LUSTRE_ENCRYPTION_MASK))
+                       comp->lrc_synced = false;
        }
 
        /**
index bf63a62..50e0e51 100644 (file)
@@ -512,7 +512,7 @@ int llapi_mirror_copy(int fd, unsigned int src, unsigned int dst, off_t pos,
 
        free(buf);
 
-       if (result > 0 && pos & (page_size - 1)) {
+       if (result > 0) {
                rc = llapi_mirror_truncate(fd, dst, pos);
                if (rc < 0) {
                        llapi_error(LLAPI_MSG_ERROR, result,