From 0f670d1ca9dd5af697bfbf3b95a301c61a8b4447 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Wed, 10 Oct 2018 14:23:55 +0800 Subject: [PATCH] LU-11239 lfs: fix mirror resync error handling This patch returns error for partially successful mirror resync. Signed-off-by: Bobi Jam Change-Id: I9d6c9ef5aca1674ceb7a9cbc6b790f3f7276ff5d Reviewed-on: https://review.whamcloud.com/33537 Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/utils/lfs.c | 29 +++++++++++++++-------------- lustre/utils/liblustreapi_layout.c | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 40be0b3..78d1ec7 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -8963,6 +8963,7 @@ int lfs_mirror_resync_file(const char *fname, struct ll_ioc_lease *ioc, int idx; int fd; int rc; + int rc2; if (stat(fname, &stbuf) < 0) { fprintf(stderr, "%s: cannot stat file '%s': %s.\n", @@ -9027,7 +9028,7 @@ int lfs_mirror_resync_file(const char *fname, struct ll_ioc_lease *ioc, else fprintf(stderr, "%s: '%s' llapi_lease_get_ext resync failed: %s.\n", - progname, fname, strerror(errno)); + progname, fname, strerror(-rc)); goto free_layout; } @@ -9051,10 +9052,10 @@ int lfs_mirror_resync_file(const char *fname, struct ll_ioc_lease *ioc, rc = llapi_mirror_resync_many(fd, layout, comp_array, comp_size, start, end); if (rc < 0) - fprintf(stderr, "%s: '%s' llapi_mirror_resync_many: %d.\n", - progname, fname, rc); + fprintf(stderr, "%s: '%s' llapi_mirror_resync_many: %s.\n", + progname, fname, strerror(-rc)); - /* prepare ioc for lease put */ + /* need to do the lease unlock even resync fails */ ioc->lil_mode = LL_LEASE_UNLCK; ioc->lil_flags = LL_LEASE_RESYNC_DONE; ioc->lil_count = 0; @@ -9065,19 +9066,19 @@ int lfs_mirror_resync_file(const char *fname, struct ll_ioc_lease *ioc, } } - rc = llapi_lease_set(fd, ioc); - if (rc <= 0) { - if (rc == 0) /* lost lease lock */ - rc = -EBUSY; - fprintf(stderr, "%s: resync file '%s' failed: %s.\n", - progname, fname, strerror(errno)); - goto free_layout; - } + rc2 = llapi_lease_set(fd, ioc); /** * llapi_lease_set returns lease mode when it request to unlock - * the lease lock + * the lease lock. */ - rc = 0; + if (rc2 <= 0) { + /* rc2 == 0 means lost lease lock */ + if (rc2 == 0 && rc == 0) + rc = -EBUSY; + fprintf(stderr, "%s: resync file '%s' failed: %s.\n", + progname, fname, + rc2 == 0 ? "lost lease lock" : strerror(-rc2)); + } free_layout: llapi_layout_free(layout); diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 5ff220c..fefb4f2 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -2855,6 +2855,7 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, uint64_t pos = start; int i; int rc; + int rc2 = 0; rc = posix_memalign(&buf, page_size, buflen); if (rc) @@ -2933,6 +2934,11 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, * meanings. */ comp_array[i].lrc_synced = true; + llapi_error(LLAPI_MSG_ERROR, written, + "component %u not synced\n", + comp_array[i].lrc_id); + if (rc2 == 0) + rc2 = (int)written; continue; } assert(written == to_write2); @@ -2945,11 +2951,17 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, free(buf); if (rc < 0) { + /* fatal error happens */ for (i = 0; i < comp_size; i++) comp_array[i].lrc_synced = false; return rc; } + /** + * no fatal error happens, each lrc_synced tells whether the component + * has been resync successfully (note: we'd reverse the value to + * 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)) { @@ -2960,8 +2972,11 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, } } - /* partially successful is successful */ - return 0; + /** + * returns the first error code for partially successful resync if + * possible. + */ + return rc2; } enum llapi_layout_comp_sanity_error { -- 1.8.3.1