Whamcloud - gitweb
LU-14971 test: align mirror_io resync implementation
[fs/lustre-release.git] / lustre / tests / mirror_io.c
index bf48699..f3734b2 100644 (file)
@@ -45,7 +45,7 @@
 #include <sys/param.h>
 #include <err.h>
 
-#include <uapi/linux/lustre/lustre_idl.h>
+#include <linux/lustre/lustre_idl.h>
 #include <lustre/lustreapi.h>
 
 #define syserr(exp, str, args...)                                      \
@@ -204,7 +204,7 @@ static void mirror_dump(int argc, char *argv[])
        free(buf);
 }
 
-static size_t add_tids(unsigned int *ids, size_t count, char *arg)
+static size_t add_tids(__u16 *ids, size_t count, char *arg)
 {
        while (*arg) {
                char *end;
@@ -240,7 +240,7 @@ static void mirror_copy(int argc, char *argv[])
        int c;
        int i;
 
-       unsigned int ids[4096] = { 0 };
+       __u16 ids[4096] = { 0 };
        size_t count = 0;
        ssize_t result;
 
@@ -374,6 +374,8 @@ static void mirror_resync(int argc, char *argv[])
        struct llapi_resync_comp comp_array[1024] = { { 0 } };
        size_t comp_size = 0;
        uint32_t flr_state;
+       uint64_t start;
+       uint64_t end;
 
        opterr = 0;
        while ((c = getopt(argc, argv, "e:d:")) != -1) {
@@ -403,10 +405,10 @@ static void mirror_resync(int argc, char *argv[])
 
        ioc->lil_mode = LL_LEASE_WRLCK;
        ioc->lil_flags = LL_LEASE_RESYNC;
-       rc = llapi_lease_get_ext(fd, ioc);
+       rc = llapi_lease_set(fd, ioc);
        if (rc < 0)
                free(ioc);
-       syserr(rc < 0, "llapi_lease_get_ext resync");
+       syserr(rc < 0, "llapi_lease_set resync");
 
        if (error_inject & AFTER_RESYNC_START) {
                free(ioc);
@@ -438,52 +440,28 @@ static void mirror_resync(int argc, char *argv[])
 
        printf("%s: found %zd stale components\n", fname, comp_size);
 
-       idx = 0;
-       while (idx < comp_size) {
-               ssize_t res;
-               uint64_t end;
-               uint32_t mirror_id;
-               int i;
+       /* get the read range [start, end) */
+       start = comp_array[0].lrc_start;
+       end = comp_array[0].lrc_end;
+       for (idx = 1; idx < comp_size; idx++) {
+               if (comp_array[idx].lrc_start < start)
+                       start = comp_array[idx].lrc_start;
+               if (end < comp_array[idx].lrc_end)
+                       end = comp_array[idx].lrc_end;
+       }
 
-               rc = llapi_lease_check(fd);
+       rc = llapi_lease_check(fd);
+       if (rc != LL_LEASE_WRLCK) {
+               free(ioc);
                syserr(rc != LL_LEASE_WRLCK, "lost lease lock");
-
-               mirror_id = comp_array[idx].lrc_mirror_id;
-               end = comp_array[idx].lrc_end;
-
-               printf("%s: resyncing mirror: %u, components: %u ",
-                       fname, mirror_id, comp_array[idx].lrc_id);
-
-               for (i = idx + 1; i < comp_size; i++) {
-                       if (mirror_id != comp_array[i].lrc_mirror_id ||
-                           end != comp_array[i].lrc_start)
-                               break;
-
-                       printf("%u ", comp_array[i].lrc_id);
-                       end = comp_array[i].lrc_end;
-               }
-               printf("\b\n");
-
-               res = llapi_mirror_resync_one(fd, layout, mirror_id,
-                                             comp_array[idx].lrc_start, end);
-               if (res > 0) {
-                       int j;
-
-                       printf("components synced: ");
-                       for (j = idx; j < i; j++) {
-                               comp_array[j].lrc_synced = true;
-                               printf("%u ", comp_array[j].lrc_id);
-                       }
-                       printf("\n");
-               }
-
-               if (res < 0)
-                       free(ioc);
-               syserrx(res < 0, "llapi_mirror_copy_many");
-
-               idx = i;
        }
 
+       rc = llapi_mirror_resync_many(fd, layout, comp_array, comp_size, start,
+                                     end);
+       if (rc < 0)
+               free(ioc);
+       syserrx(rc < 0, "llapi_mirror_resync_many");
+
        /* prepare ioc for lease put */
        ioc->lil_mode = LL_LEASE_UNLCK;
        ioc->lil_flags = LL_LEASE_RESYNC_DONE;
@@ -506,8 +484,10 @@ static void mirror_resync(int argc, char *argv[])
        if (error_inject & OPEN_TEST_FILE) /* break lease */
                close(open(argv[optind], O_RDONLY));
 
-       rc = llapi_lease_get_ext(fd, ioc);
-       syserr(rc <= 0, "llapi_lease_get_ext resync failed");
+       rc = llapi_lease_set(fd, ioc);
+       syserr(rc <= 0, "llapi_lease_set resync failed");
+       if (rc <= 0)
+               llapi_lease_release(fd);
 
        free(ioc);
        close(fd);