From: Bobi Jam Date: Thu, 24 Aug 2023 01:43:04 +0000 (+0800) Subject: LU-16896 flr: resync should not change file size X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=55d26e61eece21845b8177ee9e0bd4a9734944f7;p=fs%2Flustre-release.git 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. Lustre-change: https://review.whamcloud.com/51344 Lustre-commit: b9ce342ee196af48d2d25e2811121fe4471f5fd2 Also pick up commit 4cd4bfba473fb370767e1f2014d9fe1531889f82 ("LU-16813 utils: move mirror_end initialization) to move initialization for mirror_end variable in llapi_mirror_resync_many(), otherwise lfs mirror resync may fail since mirror_end gets reset on each pass of the loop. Lustre-change: https://review.whamcloud.com/50919 Lustre-commit: 4cd4bfba473fb370767e1f2014d9fe1531889f82 Signed-off-by: Bobi Jam Change-Id: Ia0fc1f220a32a60f3516c69e86867796ae5c35c7 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52061 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 68c9537..d907fbb 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -3386,6 +3386,7 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout, void *buf; uint64_t pos = start; uint64_t data_off = pos, data_end = pos; + uint64_t mirror_end = LUSTRE_EOF; uint32_t src = 0; int i; int rc; @@ -3414,14 +3415,13 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout, now = last_bw_print = start_time; while (pos < end) { - uint64_t mirror_end; 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, @@ -3479,15 +3479,14 @@ int llapi_mirror_resync_many_params(int fd, struct llapi_layout *layout, */ rc = llapi_mirror_truncate(fd, mid, cur_pos); - else + else if (to_punch) rc = llapi_mirror_punch(fd, mid, cur_pos, to_punch); /** - * hole at the end of file, so just - * truncate up to set size. + * hole at the end of file, so just truncate up + * to set size. */ - if (!rc && data_off == data_end && - data_end == stbuf.st_size) + if (!rc && data_off == data_end && !data_size) rc = llapi_mirror_truncate(fd, mid, data_end);