From b9ce342ee196af48d2d25e2811121fe4471f5fd2 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Sat, 17 Jun 2023 08:51:26 +0800 Subject: [PATCH] LU-16896 flr: resync should not change file size mirror resync could punch a hole reaching the end of file in a mirror, which could change the file size when the mirror is referred. This patch calls truncate after punch in this case to keep the file size unchanged in the mirror. Signed-off-by: Bobi Jam Change-Id: Ia0fc1f220a32a60f3516c69e86867796ae5c35c7 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51344 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Mikhail Pershin Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/fsx.c | 4 ++-- lustre/tests/sanity-flr.sh | 2 +- lustre/utils/lfs.c | 7 ++++--- lustre/utils/liblustreapi_layout.c | 23 +++++++++++------------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index d621295..9290f72 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -1465,12 +1465,12 @@ do_mirror_ops(int op) rc = system(cmd); if (rc < 0) { - prt("%s: %d\n", cmd, errno); + prt("mirror op %d: %s: %d\n", op, cmd, errno); report_failure(184); } else if (WIFEXITED(rc)) { rc = WEXITSTATUS(rc); if (rc > 0) { - prt("%s: %d\n", cmd, rc); + prt("mirror op %d: %s: %d\n", op, cmd, rc); snprintf(cmd, sizeof(cmd), "lfs mirror verify -v %s", tf->path); rc = system(cmd); diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 5ddf98d..e9f49d6 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -3269,7 +3269,7 @@ test_70a() { error "setstripe $tf failed" FSXNUM=${FSXNUM:-1000} - $FSX -p 5 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed" + $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed" } run_test 70a "flr mode fsx test" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index bab249e..bf4ba78 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -12532,10 +12532,11 @@ int lfs_mirror_verify_chunk(int fd, size_t file_size, rc = -EINVAL; fprintf(stderr, - "%s: chunk "DEXT" has different checksum value on mirror %u and mirror %u.\n", + "%s: chunk "DEXT" has different checksum value on mirror %u:%lx and mirror %u:%lx.\n", progname, PEXT(&chunk->chunk), - chunk->mirror_id[0], - chunk->mirror_id[i]); + chunk->mirror_id[0], crc_array[0], + chunk->mirror_id[i], crc_array[i]); + print_checksums(chunk, crc_array, pos, buflen); } } diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 271e44b..6e4a844 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -3023,10 +3023,10 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout, ssize_t bytes_read; size_t to_read; size_t to_write; + size_t data_size; if (pos >= data_end) { off_t tmp_off; - size_t data_size; if (pos >= mirror_end || !src) { rc = llapi_mirror_find(layout, pos, end, @@ -3078,23 +3078,22 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout, else to_punch = data_off - cur_pos; - if (comp_array[i].lrc_end == OBD_OBJECT_EOF) { + if (comp_array[i].lrc_end == OBD_OBJECT_EOF) /* the last component can be truncated * safely */ rc = llapi_mirror_truncate(fd, mid, cur_pos); - /* hole at the end of file, so just - * truncate up to set size. - */ - if (!rc && data_off == data_end) - rc = llapi_mirror_truncate(fd, + else if (data_size) + rc = llapi_mirror_punch(fd, mid, + cur_pos, to_punch); + /** + * hole at the end of file, so just truncate up + * to set size. + */ + if (!rc && data_off == data_end && !data_size) + rc = llapi_mirror_truncate(fd, mid, data_end); - } else { - rc = llapi_mirror_punch(fd, - comp_array[i].lrc_mirror_id, - cur_pos, to_punch); - } /* if failed then read failed hole range */ if (rc < 0) { rc = 0; -- 1.8.3.1