Whamcloud - gitweb
LU-11239 lfs: fix mirror resync error handling 41/36341/2
authorBobi Jam <bobijam@whamcloud.com>
Wed, 10 Oct 2018 06:23:55 +0000 (14:23 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 21 Nov 2019 07:31:39 +0000 (07:31 +0000)
This patch returns error for partially successful mirror resync.

Lustre-change: https://review.whamcloud.com/33537
Lustre-commit: 0f670d1ca9dd5af697bfbf3b95a301c61a8b4447

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: I9d6c9ef5aca1674ceb7a9cbc6b790f3f7276ff5d
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/36341
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/lfs.c
lustre/utils/liblustreapi_layout.c

index 251eedf..df7936d 100644 (file)
@@ -8328,6 +8328,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",
@@ -8392,7 +8393,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;
        }
 
@@ -8416,10 +8417,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;
@@ -8430,19 +8431,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);
index bb1b5fc..f641d0b 100644 (file)
@@ -2602,6 +2602,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)
@@ -2680,6 +2681,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);
@@ -2692,11 +2698,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)) {
@@ -2707,6 +2719,9 @@ 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;
 }