Whamcloud - gitweb
EX-7593 csdc: don't set compression layout when disabled
authorBobi Jam <bobijam@whamcloud.com>
Thu, 8 Jun 2023 03:42:46 +0000 (11:42 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 23 Jun 2023 07:30:57 +0000 (07:30 +0000)
When llite_enable_compression is disabled
(lfs set_param llite.*.enable_compression=0), we should check
it before sending it to MDS lest we get a file with compressed
component which we cannot handle.

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: Ib1e2123ffdb239c3e1401d682ae9c2c49e3f4a6f
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51250
Tested-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lustre_swab.h
lustre/llite/file.c
lustre/llite/xattr.c
lustre/lov/lov_ea.c
lustre/ptlrpc/pack_generic.c
lustre/tests/sanity-pfl.sh

index 7db43f6..7d85f5b 100644 (file)
@@ -97,9 +97,11 @@ void lustre_swab_fiemap_info_key(struct ll_fiemap_info_key *fiemap_info);
 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum);
 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum);
 void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum);
+int lustre_check_lov_comp_md_v1(struct lov_comp_md_v1 *lum);
 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
                                     int stripe_count);
 void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size);
+int lustre_check_lov_user_md(struct lov_user_md *lum);
 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm);
 void lustre_swab_idx_info(struct idx_info *ii);
 void lustre_swab_lip_header(struct lu_idxpage *lip);
index cc7fb9f..eb66796 100644 (file)
@@ -2450,6 +2450,10 @@ int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry,
                lustre_swab_lov_user_md(lum, 0);
        }
 
+       rc = lustre_check_lov_user_md(lum);
+       if (rc < 0)
+               RETURN(rc);
+
        ll_inode_size_lock(inode);
        rc = ll_intent_file_open(dentry, lum, lum_size, &oit);
        if (rc < 0)
index 25dff23..3ca94ad 100644 (file)
@@ -351,6 +351,7 @@ static int ll_xattr_set(const struct xattr_handler *handler,
        ktime_t kstart = ktime_get();
        int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR :
                                               LPROC_LL_SETXATTR;
+       struct lov_user_md *lum = (struct lov_user_md *)value;
        int rc;
 
        LASSERT(inode);
@@ -361,8 +362,7 @@ static int ll_xattr_set(const struct xattr_handler *handler,
 
        /* lustre/trusted.lov.xxx would be passed through xattr API */
        if (!strcmp(name, "lov")) {
-               rc = ll_setstripe_ea(dentry, (struct lov_user_md *)value,
-                                      size);
+               rc = ll_setstripe_ea(dentry, lum, size);
                ll_stats_ops_tally(ll_i2sbi(inode), op_type,
                                   ktime_us_delta(ktime_get(), kstart));
                return rc;
@@ -372,10 +372,15 @@ static int ll_xattr_set(const struct xattr_handler *handler,
                return 0;
        }
 
-       if (strncmp(name, "lov.", 4) == 0 &&
-           (__swab32(((struct lov_user_md *)value)->lmm_magic) &
-           le32_to_cpu(LOV_MAGIC_MASK)) == le32_to_cpu(LOV_MAGIC_MAGIC))
-               lustre_swab_lov_user_md((struct lov_user_md *)value, 0);
+       if (strncmp(name, "lov.", 4) == 0) {
+               if ((__swab32(lum->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
+                   le32_to_cpu(LOV_MAGIC_MAGIC))
+                       lustre_swab_lov_user_md(lum, 0);
+
+               rc = lustre_check_lov_user_md(lum);
+               if (rc < 0)
+                       return rc;
+       }
 
        return ll_xattr_set_common(handler, mnt_userns, dentry, inode, name,
                                   value, size, flags);
index 77fd60e..f5f1225 100644 (file)
@@ -44,9 +44,6 @@
 #include <lustre_lib.h>
 #include "lov_internal.h"
 
-int llite_enable_compression;
-EXPORT_SYMBOL(llite_enable_compression);
-
 static inline void
 lu_extent_le_to_cpu(struct lu_extent *dst, const struct lu_extent *src)
 {
index 4838de7..c5f66e4 100644 (file)
@@ -54,6 +54,9 @@
 
 #include "ptlrpc_internal.h"
 
+int llite_enable_compression;
+EXPORT_SYMBOL(llite_enable_compression);
+
 static inline __u32 lustre_msg_hdr_size_v2(__u32 count)
 {
        return cfs_size_round(offsetof(struct lustre_msg_v2,
@@ -2531,6 +2534,24 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
 }
 EXPORT_SYMBOL(lustre_swab_lov_comp_md_v1);
 
+int lustre_check_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
+{
+       struct lov_comp_md_entry_v1 *ent;
+       int i;
+       int rc = 0;
+
+       for (i = 0; i < lum->lcm_entry_count; i++) {
+               ent = &lum->lcm_entries[i];
+               if (!llite_enable_compression &&
+                   ent->lcme_compr_type != LL_COMPR_TYPE_NONE) {
+                       return -ENOTSUPP;
+               }
+       }
+       return rc;
+}
+EXPORT_SYMBOL(lustre_check_lov_comp_md_v1);
+
+
 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
                                     int stripe_count)
 {
@@ -2620,6 +2641,26 @@ void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size)
 }
 EXPORT_SYMBOL(lustre_swab_lov_user_md);
 
+int lustre_check_lov_user_md(struct lov_user_md *lum)
+{
+       int rc = 0;
+       switch (lum->lmm_magic) {
+       case LOV_USER_MAGIC_V1:
+       case LOV_USER_MAGIC_V3:
+       case LOV_USER_MAGIC_SPECIFIC:
+       case LOV_USER_MAGIC_FOREIGN:
+               break;
+       case LOV_USER_MAGIC_COMP_V1:
+               rc = lustre_check_lov_comp_md_v1((struct lov_comp_md_v1 *)lum);
+               break;
+       default:
+               CDEBUG(D_IOCTL, "Invalid LOV magic %08x\n", lum->lmm_magic);
+       }
+
+       return rc;
+}
+EXPORT_SYMBOL(lustre_check_lov_user_md);
+
 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
 {
        ENTRY;
index 48f7e9c..cb6603d 100644 (file)
@@ -2632,7 +2632,6 @@ test_100c() {
        }
 }
 run_test 100c "create compress file with improper compress arguments"
-export LFS_SETSTRIPE_COMPR_OK=""
 
 test_100d() {
        (( $MDS1_VERSION >= $(version_code 2.14.0.88) )) ||
@@ -2748,6 +2747,31 @@ test_100d() {
 }
 run_test 100d "lfs find compress component"
 
+test_100e() {
+       (( $MDS1_VERSION >= $(version_code 2.14.0.88) )) ||
+               skip "Need MDS >= 2.14.0.88 for compression support"
+
+       local tf=$DIR/$tdir/$tfile
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+
+       save_lustre_params client "llite.*.enable_compression" > $p
+       stack_trap "rm -rf $DIR/$tdir; restore_lustre_params < $p" EXIT
+       $LCTL set_param llite.*.enable_compression=0
+
+       test_mkdir $DIR/$tdir
+       $LFS setstripe -E1024 -Eeof -Z lz4:5 --compress-chunk=64 $tf &&
+               error "should not set compress file $tf"
+       local stripe_info=$($LFS getstripe $tf)
+       if ! grep -q "has no stripe info" <<< "$stripe_info" ; then
+               echo $stripe_info
+               error "$tf should has no stripe info"
+       fi
+       rm -f $tf || error "delete $tf failed"
+}
+run_test 100e "don't set compress file with llite.*.enable_compression=0"
+
+export LFS_SETSTRIPE_COMPR_OK=""
+
 complete_test $SECONDS
 check_and_cleanup_lustre
 exit_status