Whamcloud - gitweb
LU-11022 lfs: remove mirror by pool name 94/36194/3
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 16 Sep 2019 19:07:20 +0000 (12:07 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 23 Sep 2019 08:43:41 +0000 (08:43 +0000)
lfs mirror split --pool <poolname> <file>

This patch is back-ported from the following one:
Lustre-commit: 0c710a46cfb43366dc57ff6e83e414086b1d0e6c
Lustre-change: https://review.whamcloud.com/35329

Change-Id: I012e68729b94657236ba3fc530fc7b7485529ed2
Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/36194
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/doc/lfs-mirror-split.1
lustre/tests/sanity-flr.sh
lustre/utils/lfs.c

index a86754b..34386f9 100644 (file)
@@ -4,15 +4,15 @@ lfs mirror split \- split a specified mirror from an existing mirrored file
 .SH SYNOPSIS
 .B lfs mirror split
 {\fB\-\-mirror\-id\fR <\fImirror_id\fR> | \fB\-\-component\-id\fR|\fB\-I\fR
-<\fIcomp_id\fR>}
+<\fIcomp_id\fR> |\fB\-\-pool\fR <\fIpool\fR>}
 [\fB\-\-destroy\fR|\fB\-d\fR]
 [\fB\-f\fR <\fInew_file\fR>]
 <\fImirrored_file\fR>
 .SH DESCRIPTION
 This command splits a mirror with mirror ID <\fImirror_id\fR> or containing
-a component with <\fIcomp_id\fR> out of a mirrored
-file specified by the path name \fImirrored_file\fR. By default, the layout of
-the split mirror will be stored into a new file named
+a component with <\fIcomp_id\fR> or containing a component on <\fIpool\fR>
+out of a mirrored file specified by the path name \fImirrored_file\fR.
+By default, the layout of the split mirror will be stored into a new file named
 <\fImirrored_file\fR>.mirror~<\fImirror_id\fR>. If \fB\-\-destroy\fR|\fB\-d\fR
 option is specified, then the split mirror will be destroyed.
 If \fB\-f\fR <\fInew_file\fR> option is specified, then the layout of the split
@@ -31,7 +31,10 @@ mirrored file and is automatically assigned at file creation or extension time.
 It can be fetched by \fBlfs getstripe\fR command (see \fBlfs(1)\fR).
 .TP
 .BR \-\-comp\-id\fR\ <\fIcomp_id\fR>
-The numerical unique identifier for a component contained withiin a mirror.
+The numerical unique identifier for a component contained within a mirror.
+.TP
+.BR \-\-pool\fR\ <\fIpool\fR>
+The pool storing a component contained within a mirror.
 .TP
 .BR \-\-destroy\fR|\fB\-d\fR
 This option indicates the split mirror will be destroyed.
@@ -51,6 +54,9 @@ Split a mirror with ID 2 out of /mnt/lustre/file1 and destroy it.
 .B lfs mirror split --mirror-id 3 -f /mnt/lustre/file2 /mnt/lustre/file1
 Split a mirror with ID 3 out of /mnt/lustre/file1 and store it into
 /mnt/lustre/file2.
+.TP
+.B lfs mirror split --pool lustre-nvme -d /mnt/lustre/file1
+Split a mirror on pool lustre-nvme out of /mnt/lustre/file1 and destroy it.
 .SH AUTHOR
 The \fBlfs mirror split\fR command is part of the Lustre filesystem.
 .SH SEE ALSO
index ef57108..3053aba 100644 (file)
@@ -382,6 +382,17 @@ test_0b() {
        verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
        verify_comp_attr_with_parent pool $tf ${ids[5]}
 
+       if [[ $MDS1_VERSION -ge $(version_code 2.12.56) ]] ||
+          [[ $MDS1_VERSION -ge $(version_code 2.12.2) &&
+             $MDS1_VERSION -lt $(version_code 2.12.50) ]]; then
+               # LU-11022 - remove mirror by pool name
+               local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
+               [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
+               $LFS mirror split --pool archive -d $tf || error "delete mirror"
+               cnt=$($LFS getstripe $tf | grep archive | wc -l)
+               [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
+       fi
+
        # destroy OST pool
        destroy_test_pools
 }
index 98564a9..4fb2fd5 100644 (file)
@@ -274,12 +274,13 @@ command_t mirror_cmdlist[] = {
          MIRROR_EXTEND_HELP },
        { .pc_name = "split", .pc_func = lfs_mirror_split,
          .pc_help = "Split a mirrored file.\n"
-       "usage: lfs mirror split <--mirror-id <mirror_id> | \n"
-       "\t             <--component-id|-I <comp_id>> [--destroy|-d] \n"
+       "usage: lfs mirror split <--mirror-id <mirror_id> |\n"
+       "\t             <--component-id|-I <comp_id>|-p <pool>> [--destroy|-d]\n"
        "\t             [-f <new_file>] <mirrored file>\n"
        "\tmirror_id:   The numerical unique identifier for a mirror. It\n"
        "\t             can be fetched by lfs getstripe command.\n"
        "\tcomp_id:     Unique component ID within a mirror.\n"
+       "\tpool:        Components on specified pool.\n"
        "\tnew_file:    This option indicates the layout of the split\n"
        "\t             mirror will be stored into. If not specified,\n"
        "\t             a new file named <mirrored_file>.mirror~<mirror_id>\n"
@@ -1294,6 +1295,7 @@ enum mirror_flags {
        MF_NO_VERIFY    = 0x1,
        MF_DESTROY      = 0x2,
        MF_COMP_ID      = 0x4,
+       MF_COMP_POOL    = 0x8,
 };
 
 /**
@@ -1743,7 +1745,33 @@ static int find_comp_id(struct llapi_layout *layout, void *cbdata)
 
        return LLAPI_LAYOUT_ITER_CONT;
 }
-static int mirror_split(const char *fname, __u32 id,
+
+struct pool_to_id_cbdata {
+       const char *pool;
+       __u32 id;
+};
+static int find_comp_id_by_pool(struct llapi_layout *layout, void *cbdata)
+{
+       char buf[LOV_MAXPOOLNAME + 1];
+       struct pool_to_id_cbdata *d = (void *)cbdata;
+       uint32_t id;
+       int rc;
+
+       rc = llapi_layout_pool_name_get(layout, buf, sizeof(buf));
+       if (rc < 0)
+               return rc;
+       if (strcmp(d->pool, buf))
+               return LLAPI_LAYOUT_ITER_CONT;
+
+       rc = llapi_layout_mirror_id_get(layout, &id);
+       if (rc < 0)
+               return rc;
+       d->id = id;
+
+       return LLAPI_LAYOUT_ITER_STOP;
+}
+
+static int mirror_split(const char *fname, __u32 id, const char *pool,
                        enum mirror_flags mflags, const char *victim_file)
 {
        struct llapi_layout *layout;
@@ -1784,7 +1812,13 @@ static int mirror_split(const char *fname, __u32 id,
                goto free_layout;
        }
 
-       if (mflags & MF_COMP_ID) {
+       if (mflags & MF_COMP_POOL) {
+               struct pool_to_id_cbdata data = { .pool = pool };
+
+               rc = llapi_layout_comp_iterate(layout, find_comp_id_by_pool,
+                                              &data);
+               id = data.id;
+       } else if (mflags & MF_COMP_ID) {
                rc = llapi_layout_comp_iterate(layout, find_comp_id, &id);
                id = mirror_id_of(id);
        } else {
@@ -2048,7 +2082,6 @@ static inline bool setstripe_args_specified(struct lfs_setstripe_args *lsa)
                lsa->lsa_stripe_count != LLAPI_LAYOUT_DEFAULT ||
                lsa->lsa_stripe_off != LLAPI_LAYOUT_DEFAULT ||
                lsa->lsa_pattern != LLAPI_LAYOUT_RAID0 ||
-               lsa->lsa_pool_name != NULL ||
                lsa->lsa_comp_end != 0);
 }
 
@@ -3334,17 +3367,20 @@ static int lfs_setstripe_internal(int argc, char **argv,
                        result = mirror_extend(fname, mirror_list,
                                               mirror_flags);
                } else if (opc == SO_MIRROR_SPLIT) {
-                       if (mirror_id == 0 && comp_id == 0) {
+                       if (!mirror_id && !comp_id && !lsa.lsa_pool_name) {
                                fprintf(stderr,
-                       "%s %s: no mirror id or component id is specified\n",
-                                       progname, argv[0]);
+                       "%s %s: no mirror id or component id or pool name"
+                       " is specified\n", progname, argv[0]);
                                goto usage_error;
                        }
-                       if (mirror_id != 0)
+                       if (lsa.lsa_pool_name)
+                               mirror_flags |= MF_COMP_POOL;
+                       else if (mirror_id != 0)
                                comp_id = mirror_id;
                        else
                                mirror_flags |= MF_COMP_ID;
-                       result = mirror_split(fname, comp_id, mirror_flags,
+                       result = mirror_split(fname, comp_id, lsa.lsa_pool_name,
+                                             mirror_flags,
                                              has_m_file ? mirror_list->m_file :
                                              NULL);
                } else if (layout != NULL) {