Whamcloud - gitweb
LU-11212 lod: preserve mirror ID on mirror extension 38/32938/7
authorBobi Jam <bobijam.xu@intel.com>
Tue, 12 Jun 2018 11:28:16 +0000 (19:28 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 28 Aug 2018 05:52:54 +0000 (05:52 +0000)
When merging/expanding existing mirrors of a FLR file, we need keep
its existing mirror's mirror ID.

Signed-off-by: Bobi Jam <bobijam.xu@intel.com>
Change-Id: If139076c37c33bb1a330e1a5e997f8f56015fd9a
Reviewed-on: https://review.whamcloud.com/32938
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/lod/lod_object.c
lustre/tests/sanity-flr.sh

index 91b901b..4c367bb 100644 (file)
@@ -2898,8 +2898,12 @@ static int lod_declare_layout_merge(const struct lu_env *env,
 
                offset += le32_to_cpu(lcme->lcme_size);
 
-               if (mirror_count == 1) {
-                       /* new mirrored file, create new mirror ID */
+               if (mirror_count == 1 &&
+                   mirror_id_of(le32_to_cpu(lcme->lcme_id)) == 0) {
+                       /* Add mirror from a non-flr file, create new mirror ID.
+                        * Otherwise, keep existing mirror's component ID, used
+                        * for mirror extension.
+                        */
                        id = pflr_id(1, i + 1);
                        lcme->lcme_id = cpu_to_le32(id);
                }
@@ -4906,16 +4910,28 @@ int lod_striped_create(const struct lu_env *env, struct dt_object *dt,
 
        LASSERT(lo->ldo_comp_cnt != 0 && lo->ldo_comp_entries != NULL);
 
-       mirror_id = lo->ldo_mirror_count > 1 ? 1 : 0;
+       mirror_id = 0; /* non-flr file's mirror_id is 0 */
+       if (lo->ldo_mirror_count > 1) {
+               for (i = 0; i < lo->ldo_comp_cnt; i++) {
+                       lod_comp = &lo->ldo_comp_entries[i];
+                       if (lod_comp->llc_id != LCME_ID_INVAL &&
+                           mirror_id_of(lod_comp->llc_id) > mirror_id)
+                               mirror_id = mirror_id_of(lod_comp->llc_id);
+               }
+       }
 
        /* create all underlying objects */
        for (i = 0; i < lo->ldo_comp_cnt; i++) {
                lod_comp = &lo->ldo_comp_entries[i];
 
-               if (lod_comp->llc_extent.e_start == 0 && i > 0) /* new mirror */
-                       ++mirror_id;
-
                if (lod_comp->llc_id == LCME_ID_INVAL) {
+                       /* only the component of FLR layout with more than 1
+                        * mirror has mirror ID in its component ID.
+                        */
+                       if (lod_comp->llc_extent.e_start == 0 &&
+                           lo->ldo_mirror_count > 1)
+                               ++mirror_id;
+
                        lod_comp->llc_id = lod_gen_component_id(lo,
                                                                mirror_id, i);
                        if (lod_comp->llc_id == LCME_ID_INVAL)
index b732065..e906140 100644 (file)
@@ -2161,6 +2161,39 @@ test_202() {
 }
 run_test 202 "lfs setstripe --add-component wide striping"
 
+test_203() {
+       [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+
+       local tf=$DIR/$tfile
+
+       #create 2 mirrors
+       $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
+       #delete first mirror
+       $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror"
+
+       $LFS getstripe $tf
+       local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
+       local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
+               error "getstripe count of mirror 2"
+       [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
+
+       #extend a mirror with 2 OSTs
+       $LFS mirror extend -N -c2 $tf || error "extend mirror"
+       $LFS getstripe $tf
+
+       local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
+       count=$($LFS getstripe --mirror-id=2 -c $tf) ||
+               error "getstripe count of mirror 2"
+       [[ x$oldid = x$newid ]] ||
+               error "mirror 2 changed ID from $old_id to $new_id"
+       [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
+
+       count=$($LFS getstripe --mirror-id=3 -c $tf) ||
+               error "getstripe count of mirror 3"
+       [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
+}
+run_test 203 "mirror file preserve mirror ID"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status