Whamcloud - gitweb
EX-8282 lfs: migrate compressed file without stripe info
authorBobi Jam <bobijam@whamcloud.com>
Wed, 8 Nov 2023 10:41:21 +0000 (18:41 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 24 Nov 2023 09:30:42 +0000 (09:30 +0000)
lfs migrate file without specifying stripe info will get layout info
from the file as the target layout template, and
llapi_layout_get_by_xattr() tries to convert LOV_PATTERN_* values
to user scope LLAPI_LAYOUT_* values, while LOV_PATTERN_COMPRESS
is missed in this conversion.

This patch add a function llapi_pattern_from_lov() to handle this
conversion specifically.

This patch also add more error messages for llapi_layout_file_open().

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: I49a43cc7761cd2baed7a5da7d4e7cff2152ff9bb
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53039
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/doc/lfs-mirror-extend.1
lustre/include/lustre/lustreapi.h
lustre/tests/sanity-pfl.sh
lustre/utils/liblustreapi_layout.c

index 34f31d9..b7e79e0 100644 (file)
@@ -26,7 +26,8 @@ must follow the option without a space.
 .br
 The \fIsetstripe_options\fR specify the specific layout for the mirror. It can
 be a plain layout with specific striping pattern or a composite layout like
-Progressive File Layout (PFL) (see \fBlfs-setstripe\fR(1)).
+Progressive File Layout (PFL), including specifying compression component
+(see \fBlfs-setstripe\fR(1)).
 If \fIsetstripe_options\fR are not specified,
 then the stripe options inherited from the previous component will be used.
 If \fIvictim_file\fR exists, then the
@@ -53,7 +54,8 @@ if specified, it must follow the option without a space.
 .TP
 .I setstripe_options
 The layout of one mirror. The options are the same as those for
-\fBlfs-setstripe\fR(1) command.
+\fBlfs-setstripe\fR(1) command, including options for setting compression
+component.
 If \fIsetstripe_options\fR are not specified, then the stripe options inherited
 from the previous component will be used. This option cannot be specified with
 \fB\-f\fR <\fIvictim_file\fR> option.
index a279b3b..8935250 100644 (file)
@@ -155,6 +155,7 @@ enum {
 };
 
 __u32 llapi_pattern_to_lov(uint64_t pattern);
+uint64_t llapi_pattern_from_lov(__u32 lov_pattern);
 
 int llapi_file_open_param(const char *name, int flags, mode_t mode,
                          const struct llapi_stripe_param *param);
index 039de1e..33d3c2c 100644 (file)
@@ -3005,6 +3005,39 @@ test_100k() {
 }
 run_test 100k "create with DoM compression component"
 
+test_100l() {
+       (( $MDS1_VERSION >= $(version_code 2.14.0.91) )) ||
+               skip "Need MDS >= 2.14.0.91 for compression support"
+
+       local tf=$DIR/$tdir/$tfile
+       local tf2=$DIR/$tdir/${tfile}_compr
+       local flags
+       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=1
+
+       test_mkdir $DIR/$tdir
+
+       $LFS setstripe -E eof -c -1 -Z none $tf || error "setstripe $tf failed"
+       cp /etc/hosts $tf || error "error writing file $tf"
+       $LFS migrate $tf || {
+               $LFS getstripe $tf
+               error "cannot migrate $tf"
+       }
+       $LFS getstripe $tf
+
+       $LFS setstripe -E eof -c -1 -Z gzip:4 $tf2 ||
+               error "setstripe compressed file $tf2 failed"
+       cp /etc/hosts $tf2 || error "error writing file $tf2"
+       $LFS migrate $tf2|| {
+               $LFS getstripe $tf2
+               error "cannot migrate $tf2"
+       }
+       $LFS getstripe $tf2
+}
+run_test 100l "lfs migrate compressed file"
 export LFS_SETSTRIPE_COMPR_OK=""
 
 complete_test $SECONDS
index dc27a41..d27582b 100644 (file)
@@ -670,18 +670,7 @@ struct llapi_layout *llapi_layout_get_by_xattr(void *lov_xattr,
                        goto comp_add;
                }
 
-               if (v1->lmm_pattern == LOV_PATTERN_RAID0)
-                       comp->llc_pattern = LLAPI_LAYOUT_RAID0;
-               else if (v1->lmm_pattern == (LOV_PATTERN_RAID0 |
-                                        LOV_PATTERN_OVERSTRIPING))
-                       comp->llc_pattern = LLAPI_LAYOUT_OVERSTRIPING;
-               else if (v1->lmm_pattern & LOV_PATTERN_MDT)
-                       comp->llc_pattern = LLAPI_LAYOUT_MDT;
-               else
-                       /* Lustre only supports RAID0, overstripping,
-                        * DoM and FOREIGN/HSM for now.
-                        */
-                       comp->llc_pattern = v1->lmm_pattern;
+               comp->llc_pattern = llapi_pattern_from_lov(v1->lmm_pattern);
 
                if (v1->lmm_stripe_size == 0)
                        comp->llc_stripe_size = LLAPI_LAYOUT_DEFAULT;
@@ -774,6 +763,36 @@ __u32 llapi_pattern_to_lov(uint64_t pattern)
        return lov_pattern;
 }
 
+uint64_t llapi_pattern_from_lov(__u32 lov_pattern)
+{
+       uint64_t pattern;
+
+       switch (lov_pattern) {
+       case LOV_PATTERN_RAID0:
+               pattern = LLAPI_LAYOUT_RAID0;
+               break;
+       case LOV_PATTERN_MDT:
+               pattern = LLAPI_LAYOUT_MDT;
+               break;
+       case LOV_PATTERN_FOREIGN:
+               pattern = LLAPI_LAYOUT_FOREIGN;
+               break;
+       case LOV_PATTERN_OVERSTRIPING | LOV_PATTERN_RAID0:
+               pattern = LLAPI_LAYOUT_OVERSTRIPING;
+               break;
+       case LOV_PATTERN_RAID0 | LOV_PATTERN_COMPRESS:
+               pattern = LLAPI_LAYOUT_RAID0 | LLAPI_LAYOUT_COMPRESS;
+               break;
+       case LOV_PATTERN_MDT | LOV_PATTERN_COMPRESS:
+               pattern = LLAPI_LAYOUT_MDT | LLAPI_LAYOUT_COMPRESS;
+               break;
+       default:
+               pattern = lov_pattern;
+       }
+
+       return pattern;
+}
+
 /**
  * Convert the data from a llapi_layout to a newly allocated lov_user_md.
  * The caller is responsible for freeing the returned pointer.
@@ -1950,6 +1969,11 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
 
        if (path == NULL ||
            (layout != NULL && layout->llot_magic != LLAPI_LAYOUT_MAGIC)) {
+               if (path == NULL)
+                       fprintf(stderr, "Empty file name\n");
+               else
+                       fprintf(stderr, "Invalid layout magic %x\n",
+                               layout->llot_magic);
                errno = EINVAL;
                return -1;
        }
@@ -1970,8 +1994,11 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
 
        fd = open(path, open_flags, mode);
 
-       if (layout == NULL || fd < 0)
+       if (layout == NULL || fd < 0) {
+               if (fd < 0)
+                       fprintf(stderr, "Cannot open file %s: %d\n", path, fd);
                return fd;
+       }
 
        lum = llapi_layout_to_lum(layout);
 
@@ -1979,6 +2006,7 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
                tmp = errno;
                close(fd);
                errno = tmp;
+               fprintf(stderr, "Invalid layout: %s\n", strerror(errno));
                return -1;
        }
 
@@ -1995,6 +2023,7 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode,
                tmp = errno;
                close(fd);
                errno = tmp;
+               fprintf(stderr, "Cannot set layout EA: %s\n", strerror(errno));
                fd = -1;
        }