Whamcloud - gitweb
LU-14646 flr: write a FLR file downgrade SoM
authorBobi Jam <bobijam@whamcloud.com>
Wed, 28 Apr 2021 04:43:11 +0000 (12:43 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 29 Jul 2021 14:22:42 +0000 (14:22 +0000)
Seek over file size and write a FLR file does not change its SoM
and that makes file size incorrect.

This patch also fixes rename connect flags "pccro" to "pcc_ro"
which causes that PCC-RO related tests in sanity-pcc.sh are all
skipped.

Lustre-change: https://review.whamcloud.com/43471
Lustre-commit: f437134e80a1b320e575d774061e693042f3eb4c

Fixes: 25836ff90 ("LU-10948 mdt: New connect flag for non-open-by-fid lock")
Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: I3075389721bdd40be60e9206c37f6c1bea514cce
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/44273
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
lustre/mdd/mdd_object.c
lustre/tests/sanity-pcc.sh

index 32a9dac..2e63862 100644 (file)
@@ -2768,9 +2768,19 @@ mdd_layout_update_rdonly(const struct lu_env *env, struct mdd_object *obj,
                RETURN(rc);
 
        if (rc > 0) {
+               struct layout_intent *intent = mlc->mlc_intent;
+
                lustre_som_swab(som);
                if (som->lsa_valid & SOM_FL_STRICT)
                        fl = LU_XATTR_REPLACE;
+
+               if (mlc->mlc_opc == MD_LAYOUT_WRITE &&
+                   intent->li_extent.e_end > som->lsa_size) {
+                       fl = LU_XATTR_REPLACE;
+                       som->lsa_size = intent->li_extent.e_end;
+                       if (intent->li_opc == LAYOUT_INTENT_TRUNC)
+                               som->lsa_size -= 1;
+               }
        }
 
        rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
@@ -2833,6 +2843,9 @@ mdd_layout_update_write_pending(const struct lu_env *env,
                struct thandle *handle)
 {
        struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
+       struct lu_buf *som_buf = &mdd_env_info(env)->mti_buf[1];
+       struct lustre_som_attrs *som = &mlc->mlc_som;
+       int fl = 0;
        int rc;
        ENTRY;
 
@@ -2845,8 +2858,28 @@ mdd_layout_update_write_pending(const struct lu_env *env,
                 * resync state. */
                break;
        case MD_LAYOUT_WRITE:
-               /* legal race for concurrent write, the file state has been
-                * changed by another client. */
+               /**
+                * legal race for concurrent write, the file state has been
+                * changed by another client. Or a jump over file size and
+                * write.
+                */
+               som_buf->lb_buf = som;
+               som_buf->lb_len = sizeof(*som);
+               rc = mdo_xattr_get(env, obj, som_buf, XATTR_NAME_SOM);
+               if (rc < 0 && rc != -ENODATA)
+                       RETURN(rc);
+
+               if (rc > 0) {
+                       struct layout_intent *intent = mlc->mlc_intent;
+
+                       lustre_som_swab(som);
+                       if (intent->li_extent.e_end > som->lsa_size) {
+                               fl = LU_XATTR_REPLACE;
+                               som->lsa_size = intent->li_extent.e_end;
+                               if (intent->li_opc == LAYOUT_INTENT_TRUNC)
+                                       som->lsa_size -= 1;
+                       }
+               }
                break;
        default:
                RETURN(-EBUSY);
@@ -2856,6 +2889,13 @@ mdd_layout_update_write_pending(const struct lu_env *env,
        if (rc)
                GOTO(out, rc);
 
+       if (fl) {
+               rc = mdd_declare_xattr_set(env, mdd, obj, som_buf,
+                                          XATTR_NAME_SOM, fl, handle);
+               if (rc)
+                       GOTO(out, rc);
+       }
+
        rc = mdd_trans_start(env, mdd, handle);
        if (rc)
                GOTO(out, rc);
@@ -2865,6 +2905,12 @@ mdd_layout_update_write_pending(const struct lu_env *env,
 
        mdd_write_lock(env, obj, DT_TGT_CHILD);
        rc = mdo_layout_change(env, obj, mlc, handle);
+       if (!rc && fl) {
+               som->lsa_valid = SOM_FL_STALE;
+               lustre_som_swab(som);
+               rc = mdo_xattr_set(env, obj, som_buf, XATTR_NAME_SOM,
+                                  fl, handle);
+       }
        mdd_write_unlock(env, obj);
        if (rc)
                GOTO(out, rc);
index 16bb1d9..a1cbb87 100644 (file)
@@ -646,7 +646,7 @@ test_3a() {
        local file=$DIR/$tdir/$tfile
        local file2=$DIR2/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
@@ -1067,7 +1067,7 @@ test_10b() {
 run_test 10b "Test RW-PCC with group quota on loop PCC device"
 
 test_10c() {
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        test_usrgrp_quota "u" "-r"
@@ -1075,7 +1075,7 @@ test_10c() {
 run_test 10c "Test RO-PCC with user quota on loop PCC device"
 
 test_10d() {
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        test_usrgrp_quota "g" "-r"
@@ -1090,7 +1090,7 @@ test_usrgrp_edquot() {
        local id=$RUNAS_ID
        local ug=$1
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        [[ $ug == "g" ]] && id=$RUNAS_GID
@@ -1379,7 +1379,7 @@ run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
 test_14() {
        local file=$DIR/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
@@ -1420,7 +1420,7 @@ test_15() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1514,7 +1514,7 @@ test_16() {
        local file=$DIR/$tfile
        local -a lpcc_path
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1721,7 +1721,7 @@ test_21a() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1762,7 +1762,7 @@ test_21b() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1806,7 +1806,7 @@ test_21c() {
        local file=$DIR/$tfile
        local fid
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1845,7 +1845,7 @@ test_21d() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1874,7 +1874,7 @@ test_21e() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1903,7 +1903,7 @@ test_21f() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1938,7 +1938,7 @@ test_21g() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -1967,7 +1967,7 @@ test_21h() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2012,7 +2012,7 @@ test_21i() {
        local file2=$DIR2/$tfile
        local fid
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2063,7 +2063,7 @@ test_22() {
        local file2=$DIR2/$tfile
        local fid
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2134,7 +2134,7 @@ test_23() {
        local file=$DIR/$tfile
        local -a lpcc_path
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2203,7 +2203,7 @@ test_24a() {
        local file=$DIR/$tdir/$tfile
        local -a lpcc_path
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2257,7 +2257,7 @@ test_24b() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2302,7 +2302,7 @@ test_25() {
        local file=$DIR/$tdir/$tfile
        local content
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2358,7 +2358,7 @@ test_26() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2457,7 +2457,7 @@ test_27() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2578,7 +2578,7 @@ test_29a() {
        local file=$DIR/$tdir/$tfile
        local file2=$DIR2/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        is_project_quota_supported || skip "project quota is not supported"
@@ -2618,7 +2618,7 @@ test_29b() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/myfile.dat
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2651,7 +2651,7 @@ test_30() {
        local hsm_root="$mntpt/$tdir"
        local file
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2691,7 +2691,7 @@ test_31() {
        local -a lpcc_path3
        local file
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2753,7 +2753,7 @@ test_32() {
        local file=$DIR/$tfile
        local -a lpcc_path
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2798,7 +2798,7 @@ test_33() {
        local file=$DIR/myfile.doc
        local file2=$DIR2/myfile.doc
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -2866,7 +2866,7 @@ test_34() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        is_project_quota_supported || skip "project quota is not supported"
@@ -2945,7 +2945,7 @@ test_35() {
        local file=$DIR/$tfile
        local -a lpcc_path
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50
@@ -3010,7 +3010,7 @@ test_36a() {
 run_test 36a "Stale RW-PCC copy should be deleted after remove the PCC backend"
 
 test_36b() {
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        test_36_base "-r"
@@ -3025,7 +3025,7 @@ test_37() {
        local file=$DIR/$tdir/$tfile
        local file2=$DIR2/$tdir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
@@ -3067,7 +3067,7 @@ test_38() {
        local dir=$DIR/$tdir
        local file=$dir/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        is_project_quota_supported || skip "project quota is not supported"
@@ -3095,7 +3095,7 @@ test_38() {
 run_test 38 "Verify LFS pcc state does not trigger prefetch for auto PCC-RO"
 
 test_39() {
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        quotaon --help |& grep -q 'project quotas' ||
@@ -3164,7 +3164,7 @@ calc_stats_facet() {
 }
 
 test_40() {
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        is_project_quota_supported || skip "project quota is not supported"
@@ -3280,7 +3280,7 @@ test_41() {
        local hsm_root="$mntpt/$tdir"
        local file=$DIR/$tfile
 
-       $LCTL get_param -n mdc.*.connect_flags | grep -q pccro ||
+       $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
                skip "Server does not support PCC-RO"
 
        setup_loopdev $SINGLEAGT $loopfile $mntpt 50