From: Alex Zhuravlev Date: Wed, 20 Nov 2024 20:28:55 +0000 (-0500) Subject: LU-18468 llapi: always truncate mirrors on resync X-Git-Tag: 2.16.51~132 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=b5db891cad71f17dda00ab157332db819d2292f8;p=fs%2Flustre-release.git LU-18468 llapi: always truncate mirrors on resync 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 Signed-off-by: Alex Zhuravlev Change-Id: I767a1b3ef58c855f57967228d37b04fa0ab87e57 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57090 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Zhenyu Xu Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 69778e5..93155a2 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -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 diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 7e3ad0d..e61ef67 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -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; } /** diff --git a/lustre/utils/liblustreapi_mirror.c b/lustre/utils/liblustreapi_mirror.c index bf63a62..50e0e51 100644 --- a/lustre/utils/liblustreapi_mirror.c +++ b/lustre/utils/liblustreapi_mirror.c @@ -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,