Whamcloud - gitweb
LU-13375 flr: inherit the correct layout by "mirror extend -N" 79/38079/4
authorEmoly Liu <emoly@whamcloud.com>
Thu, 9 Apr 2020 10:22:28 +0000 (18:22 +0800)
committerOleg Drokin <green@whamcloud.com>
Sun, 19 Apr 2020 08:45:24 +0000 (08:45 +0000)
For PFL files, if stripe information is not specified to the cmd
"lfs mirror extend -N", the layout of the last initialized comp of
this file should be inherited by the mirror.
For example,
  lcm_mirror_count:  2
  lcm_entry_count:   4
    lcme_id:             65537
    lcme_mirror_id:      1
    lcme_flags:          init
    lcme_extent.e_start: 0
    lcme_extent.e_end:   10485760
      lmm_stripe_count:  1
      lmm_stripe_size:   1048576
      lmm_objects:
      - 0: { l_ost_idx: 2, l_fid: [0x100020000:0x102:0x0] }

    lcme_id:             65538
    lcme_mirror_id:      1
    lcme_flags:          init
    lcme_extent.e_start: 10485760
    lcme_extent.e_end:   20971520
      lmm_stripe_count:  2
      lmm_stripe_size:   2097152
      lmm_objects:
      - 0: { l_ost_idx: 3, l_fid: [0x100030000:0x91:0x0] }
      - 1: { l_ost_idx: 0, l_fid: [0x100000000:0x13d:0x0] }

    lcme_id:             65539
    lcme_mirror_id:      1
    lcme_flags:          0
    lcme_extent.e_start: 20971520
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  -1
      lmm_stripe_size:   4194304

    lcme_id:             131073
    lcme_mirror_id:      2
    lcme_flags:          init
    lcme_extent.e_start: 0
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  2
      lmm_stripe_size:   2097152
      lmm_pool:          archive
      lmm_objects:
      - 0: { l_ost_idx: 1, l_fid: [0x100010000:0x17c:0x0] }
      - 1: { l_ost_idx: 2, l_fid: [0x100020000:0x103:0x0] }

sanity-flr.sh test_0f is modified to verify this patch.

Signed-off-by: Emoly Liu <emoly@whamcloud.com>
Change-Id: If7db3ec7ce9414a04a32e9995ba24f322fb93ab5
Reviewed-on: https://review.whamcloud.com/38079
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre/lustreapi.h
lustre/tests/sanity-flr.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi_layout.c

index 7ed703e..a9ecd8d 100644 (file)
@@ -615,6 +615,9 @@ ssize_t llapi_mirror_write(int fd, unsigned int id, const void *buf,
 uint32_t llapi_mirror_find(struct llapi_layout *layout,
                           uint64_t file_start, uint64_t file_end,
                           uint64_t *endp);
+int llapi_layout_get_last_init_comp(struct llapi_layout *layout);
+int llapi_layout_mirror_inherit(struct llapi_layout *f_layout,
+                               struct llapi_layout *m_layout);
 int llapi_mirror_find_stale(struct llapi_layout *layout,
                struct llapi_resync_comp *comp, size_t comp_size,
                __u16 *mirror_ids, int ids_nr);
index 07e52af..923518f 100644 (file)
@@ -608,11 +608,12 @@ test_0f() {
                error "create mirrored file $tf failed"
 
        # extend the mirrored file with composite layout mirrors
-       $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
+       $mirror_cmd -N -p archive \
+                   -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
                    -N -c -1 -p none \
                    -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
                error "extend mirrored file $tf failed"
-       verify_mirror_count $tf 7
+       verify_mirror_count $tf 8
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
 
        # verify component ${ids[0]}
@@ -627,8 +628,14 @@ test_0f() {
        verify_comp_attr pool $tf ${ids[1]} ssd
        verify_comp_extent $tf ${ids[1]} 33554432 EOF
 
-       # verify components ${ids[2]} and ${ids[4]}
-       for i in 2 4; do
+       # verify component ${ids[2]}
+       verify_comp_attr stripe-size $tf ${ids[0]} 16777216
+       verify_comp_attr_with_default stripe-count $tf ${ids[2]}
+       verify_comp_attr pool $tf ${ids[2]} archive
+       verify_comp_extent $tf ${ids[2]} 0 EOF
+
+       # verify components ${ids[3]} and ${ids[5]}
+       for i in 3 5; do
                verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr stripe-index $tf ${ids[$i]} 1
@@ -636,30 +643,30 @@ test_0f() {
                verify_comp_extent $tf ${ids[$i]} 0 4194304
        done
 
-       # verify components ${ids[3]} and ${ids[5]}
-       for i in 3 5; do
+       # verify components ${ids[4]} and ${ids[6]}
+       for i in 4 6; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr pool $tf ${ids[$i]} flash
                verify_comp_extent $tf ${ids[$i]} 4194304 EOF
        done
 
-       # verify component ${ids[6]}
-       verify_comp_attr stripe-size $tf ${ids[6]} 4194304
-       verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
-       verify_comp_attr_with_parent pool $tf ${ids[6]}
-       verify_comp_extent $tf ${ids[6]} 0 EOF
+       # verify component ${ids[7]}
+       verify_comp_attr stripe-size $tf ${ids[7]} 4194304
+       verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
+       verify_comp_attr_with_parent pool $tf ${ids[7]}
+       verify_comp_extent $tf ${ids[7]} 0 EOF
 
-       # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
-       for i in 7 9 11; do
+       # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
+       for i in 8 10 12; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
                verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 0 536870912
        done
 
-       # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
-       for i in 8 10 12; do
+       # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
+       for i in 9 11 13; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
                verify_comp_attr stripe-count $tf ${ids[$i]} -1
                verify_comp_attr pool $tf ${ids[$i]} archive
index 96ed408..6151625 100644 (file)
@@ -1387,6 +1387,7 @@ struct mirror_args {
        struct llapi_layout     *m_layout;
        const char              *m_file;
        struct mirror_args      *m_next;
+       bool                    m_inherit;
 };
 
 /**
@@ -1738,14 +1739,36 @@ out:
        return rc;
 }
 
-static int mirror_extend_layout(char *name, struct llapi_layout *layout)
+static int mirror_extend_layout(char *name, struct llapi_layout *m_layout,
+                               bool inherit)
 {
+       struct llapi_layout *f_layout = NULL;
        struct ll_ioc_lease *data = NULL;
        int fd = -1;
        int fdv = -1;
-       int rc;
+       int rc = 0;
 
-       rc = migrate_open_files(name, 0, NULL, layout, &fd, &fdv);
+       if (inherit) {
+               f_layout = llapi_layout_get_by_path(name, 0);
+               if (f_layout == NULL) {
+                       fprintf(stderr, "%s: cannot get layout\n", progname);
+                       goto out;
+               }
+               rc = llapi_layout_get_last_init_comp(f_layout);
+               if (rc) {
+                       fprintf(stderr, "%s: cannot get the last init comp\n",
+                               progname);
+                       goto out;
+               }
+               rc = llapi_layout_mirror_inherit(f_layout, m_layout);
+               if (rc) {
+                       fprintf(stderr,
+                               "%s: cannot inherit from the last init comp\n",
+                               progname);
+                       goto out;
+               }
+       }
+       rc = migrate_open_files(name, 0, NULL, m_layout, &fd, &fdv);
        if (rc < 0)
                goto out;
 
@@ -1813,7 +1836,8 @@ static int mirror_extend(char *fname, struct mirror_args *mirror_list,
 
                        while (mirror_count > 0) {
                                rc = mirror_extend_layout(fname,
-                                                       mirror_list->m_layout);
+                                                       mirror_list->m_layout,
+                                                       mirror_list->m_inherit);
                                if (rc)
                                        break;
 
@@ -2397,13 +2421,12 @@ new_comp:
                        return rc;
                }
 
-               if (lsa->lsa_first_comp)
+               if (lsa->lsa_first_comp) {
                        prev_end = 0;
-
-               if (lsa->lsa_first_comp)
                        rc = llapi_layout_add_first_comp(layout);
-               else
+               } else {
                        rc = llapi_layout_comp_add(layout);
+               }
                if (rc) {
                        fprintf(stderr, "Add component failed. %s\n",
                                strerror(errno));
@@ -2928,8 +2951,10 @@ static struct mirror_args *lfs_mirror_alloc(void)
 
        while (1) {
                mirror = calloc(1, sizeof(*mirror));
-               if (mirror != NULL)
+               if (mirror != NULL) {
+                       mirror->m_inherit = false;
                        break;
+               }
 
                sleep(1);
        }
@@ -3475,6 +3500,8 @@ static int lfs_setstripe_internal(int argc, char **argv,
 
                        if (last_mirror != NULL) {
                                /* wrap up last mirror */
+                               if (!setstripe_args_specified(&lsa))
+                                       last_mirror->m_inherit = true;
                                if (lsa.lsa_comp_end == 0)
                                        lsa.lsa_comp_end = LUSTRE_EOF;
 
@@ -3626,6 +3653,8 @@ static int lfs_setstripe_internal(int argc, char **argv,
        }
 
        if (mirror_mode) {
+               if (!setstripe_args_specified(&lsa))
+                       last_mirror->m_inherit = true;
                if (lsa.lsa_comp_end == 0)
                        lsa.lsa_comp_end = LUSTRE_EOF;
        }
index aefde5d..c2cd0ad 100644 (file)
@@ -2702,6 +2702,71 @@ error:
 }
 
 /**
+ * Get the last initialized component
+ *
+ * \param[in] layout   component layout list.
+ *
+ * \retval 0           found
+ * \retval -EINVAL     not found
+ * \retval -EISDIR     directory layout
+ */
+int llapi_layout_get_last_init_comp(struct llapi_layout *layout)
+{
+       struct llapi_layout_comp *comp = NULL, *head = NULL;
+
+       if (!layout->llot_is_composite)
+               return 0;
+
+       head = list_entry(layout->llot_comp_list.next, typeof(*comp), llc_list);
+       if (head == NULL)
+               return -EINVAL;
+       if (head->llc_id == 0 && !(head->llc_flags & LCME_FL_INIT))
+               /* a directory */
+               return -EISDIR;
+
+       /* traverse the components from the tail to find the last init one */
+       comp = list_entry(layout->llot_comp_list.prev, typeof(*comp), llc_list);
+       while (comp != head) {
+               if (comp->llc_flags & LCME_FL_INIT)
+                       break;
+               comp = list_entry(comp->llc_list.prev, typeof(*comp), llc_list);
+       }
+
+       layout->llot_cur_comp = comp;
+
+       return comp->llc_flags & LCME_FL_INIT ? 0 : -EINVAL;
+}
+
+/**
+ * Interit stripe info from the file's component to the mirror
+ *
+ * \param[in] layout   file component layout list.
+ * \param[in] layout   mirro component layout list.
+ *
+ * \retval 0           on success
+ * \retval -EINVAL     on error
+ */
+int llapi_layout_mirror_inherit(struct llapi_layout *f_layout,
+                               struct llapi_layout *m_layout)
+{
+       struct llapi_layout_comp *m_comp = NULL;
+       struct llapi_layout_comp *f_comp = NULL;
+       int rc = 0;
+
+       f_comp = __llapi_layout_cur_comp(f_layout);
+       if (f_comp == NULL)
+               return -EINVAL;
+       m_comp = __llapi_layout_cur_comp(m_layout);
+       if (m_comp == NULL)
+               return -EINVAL;
+
+       m_comp->llc_stripe_size = f_comp->llc_stripe_size;
+       m_comp->llc_stripe_count = f_comp->llc_stripe_count;
+
+       return rc;
+}
+
+/**
  * Find all stale components.
  *
  * \param[in] layout           component layout list.