Whamcloud - gitweb
LU-14526 flr: mirror split downgrade SOM
authorBobi Jam <bobijam@whamcloud.com>
Tue, 30 Mar 2021 11:20:26 +0000 (19:20 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 19 Jul 2021 21:53:41 +0000 (21:53 +0000)
After mirror split, the file's blocks on SoM is not accurate, this
patch downgrade the SoM from STRICT so that size glimpse does not
trust the SoM from the MDS.

Lustre-change: https://review.whamcloud.com/43168
Lustre-commit: a30750ad2cc5f10d9d1cc0e30199073091c06f2b

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: I02350c24190d96af93fed8c1b8a0bc6beb2c4bc2
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Yingjin Qian <qian@ddn.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/44253
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/mdt/mdt_open.c
lustre/tests/sanity-flr.sh

index 1b15fbe..6d57b07 100644 (file)
@@ -2138,9 +2138,26 @@ int mdt_close_handle_layouts(struct mdt_thread_info *info,
                struct lu_buf *buf = &info->mti_buf;
                struct md_rejig_data mrd;
 
-               mrd.mrd_obj = mdt_object_child(o == o1 ? o2 : o1);
-               if (ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SPLIT)
+               if (o2) {
+                       mrd.mrd_obj = mdt_object_child(o == o1 ? o2 : o1);
+               } else {
+                       if (!(ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SPLIT)) {
+                               /* paranoid check again */
+                               CERROR(DFID
+                                 ":only mirror split support NULL o2 object\n",
+                                       PFID(mdt_object_fid(o)));
+                               GOTO(out_unlock1, rc = -EINVAL);
+                       }
+
+                       /* set NULL mrd_obj for deleting mirror objects */
+                       mrd.mrd_obj = NULL;
+               }
+
+               if (ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SPLIT) {
                        mrd.mrd_mirror_id = data->cd_mirror_id;
+                       /* set a small enough blocks in the SoM */
+                       ma->ma_attr.la_blocks >>= 1;
+               }
 
                buf->lb_len = sizeof(mrd);
                buf->lb_buf = &mrd;
@@ -2148,11 +2165,18 @@ int mdt_close_handle_layouts(struct mdt_thread_info *info,
                                  XATTR_LUSTRE_LOV,
                                  ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SPLIT ?
                                  LU_XATTR_SPLIT : LU_XATTR_MERGE);
-               if (rc == 0 && ma->ma_attr.la_valid & (LA_SIZE | LA_BLOCKS)) {
+               if (rc == 0 && ma->ma_attr.la_valid & (LA_SIZE | LA_BLOCKS |
+                                                      LA_LSIZE | LA_LBLOCKS)) {
                        int rc2;
+                       enum lustre_som_flags lsf;
+
+                       if (ma->ma_attr.la_valid & (LA_SIZE | LA_BLOCKS))
+                               lsf = SOM_FL_STRICT;
+                       else
+                               lsf = SOM_FL_LAZY;
 
                        mutex_lock(&o->mot_som_mutex);
-                       rc2 = mdt_set_som(info, o, SOM_FL_STRICT,
+                       rc2 = mdt_set_som(info, o, lsf,
                                          ma->ma_attr.la_size,
                                          ma->ma_attr.la_blocks);
                        mutex_unlock(&o->mot_som_mutex);
index cdc83fa..09fc405 100644 (file)
@@ -1951,6 +1951,42 @@ test_44() {
 }
 run_test 44 "lfs mirror split check"
 
+test_44c() {
+       local tf=$DIR/$tdir/$tfile
+
+       stack_trap "rm -f $tf"
+
+       [ $MDS1_VERSION -ge $(version_code 2.14.0.4) ] ||
+               skip "Need MDS version at least 2.14.0.4"
+
+       [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
+
+       mkdir -p $DIR/$tdir || error "create directroy failed"
+
+       dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
+       sync
+       block1=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
+
+       $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
+       sync
+       block2=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
+
+       $LFS mirror split -d --mirror-id=2 $tf ||
+               error "mirror split $tfile failed"
+       $LFS mirror split -d --mirror-id=3 $tf ||
+               error "mirror split $tfile failed"
+       sync
+       lfs getsom $tf
+       block3=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
+
+       [[ $block1 -eq $block3 ]] ||
+               error "mirror split does not reduce block# $block3 != $block1"
+}
+run_test 44c "lfs mirror split reduces block size of a file"
+
 test_45() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"