From: Bobi Jam Date: Wed, 28 Jun 2023 18:37:22 +0000 (+0800) Subject: EX-6856 utils: support 'lfs find --printf %LZ' X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=fde613d01af60bd7d0dfbfeeb358a5af93a9cd15;p=fs%2Flustre-release.git EX-6856 utils: support 'lfs find --printf %LZ' Add support for "lfs find --printf %LZ" to print the compression type:level of the last instantiated component of a file. Signed-off-by: Bobi Jam Change-Id: Iaf1b6c031b06c70e7b5be51354697aa6bdcc9850 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51498 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/doc/lfs-find.1 b/lustre/doc/lfs-find.1 index 6a23616c..fd1337e 100644 --- a/lustre/doc/lfs-find.1 +++ b/lustre/doc/lfs-find.1 @@ -388,6 +388,11 @@ Numeric project ID assigned to the file or directory. .B %LS File's stripe size. For a composite file, this is the stripe size of the last instantiated component. +.TP +.B %LZ +File's compression information in ":" format. For a +composite file, this is the compression information of the last instantiated +component. .RE .TP .BR --projid diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 44ccbd4..3a4cbb7 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -927,6 +927,8 @@ int llapi_layout_stripe_size_set(struct llapi_layout *layout, uint64_t size); int llapi_layout_compress_set(struct llapi_layout *layout, enum ll_compr_type type, int level, __u32 chunk_size, unsigned long long stripe_size); +int llapi_layout_compress_get(struct llapi_layout *layout, + __u8 *type, __u8 *level); /******************** Extension Size ********************/ diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 61d647c..4a5178e 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -2034,7 +2034,7 @@ test_43c() { $LCTL set_param llite.*.enable_compression=1 test_mkdir $DIR/$tdir - $LFS setstripe -N -Eeof -Z gzip -N -Eeof $tf || + $LFS setstripe -N -Eeof -Z gzip -N -Eeof -Z none $tf || error "setstripe $tf failed" #define OBD_FAIL_LOV_MIRROR_INIT 0x1425 @@ -2042,7 +2042,10 @@ test_43c() { cat $tf || error "read $tf failed" local index=$($LCTL get_param fail_val -n) - ((index == 1)) || error "should read 2nd mirror instead of $((index+1))" + ((index == 1)) || { + $LFS getstripe $tf + error "should read 2nd mirror instead of $((index+1))" + } } run_test 43c "read prefer uncompressed mirror" @@ -2061,7 +2064,7 @@ test_43d() { test_mkdir $DIR/$tdir ## mirror 0 compressed ## mirror 1 uncompressed - $LFS mirror create -N -Eeof -Z gzip -N -Eeof $tf || + $LFS mirror create -N -Eeof -Z gzip -N -Eeof -Z none $tf || error "create 2 mirrors file $tf failed" dd if=/dev/zero of=$tf bs=1M count=1 || error "failed to write $tf" diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index bfff04e..982faa2 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -2805,6 +2805,51 @@ test_100e() { } run_test 100e "don't set compress file with llite.*.enable_compression=0" +test_100f() { + (( $MDS1_VERSION >= $(version_code 2.14.0.91) )) || + skip "Need MDS >= 2.14.0.91 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=1 + + test_mkdir $DIR/$tdir + $LFS setstripe -E1M -Z gzip:1 -E4M -E6M -Z none -Eeof -Z gzip:4 $tf || + error "setstripe $tf failed" + + + z1=$($LFS find -printf %LZ $tf) + [[ $z1 == "gzip:1" ]] || { + $LFS getstripe $tf + error "1st component compress info $z1 is not gzip:1" + } + + dd if=/dev/zero of=$tf bs=1M count=2 || error "write $tf failed" + z2=$($LFS find -printf %LZ $tf) + [[ $z2 == "gzip:1" ]] || { + $LFS getstripe $tf + error "2nd component compress info $z2 is not gzip:1" + } + + dd if=/dev/zero of=$tf bs=1M count=1 seek=4 || error "write $tf failed" + z3=$($LFS find -printf %LZ $tf) + [[ $z3 == "none:0" ]] || { + $LFS getstripe $tf + error "3rd component compress info $z3 is not none:0" + } + + dd if=/dev/zero of=$tf bs=1M count=1 seek=6 || error "write $tf failed" + z4=$($LFS find -printf %LZ $tf) + [[ $z4 == "gzip:4" ]] || { + $LFS getstripe $tf + error "3rd component compress info $z4 is not gzip:4" + } +} +run_test 100f "lfs find -printf %LZ support" + export LFS_SETSTRIPE_COMPR_OK="" complete_test $SECONDS diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index bccb772..abae0c9 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2907,16 +2907,25 @@ static inline void setstripe_args_init_inherit(struct lfs_setstripe_args *lsa) unsigned long long stripe_size; long long stripe_count; char *pool_name = NULL; + enum ll_compr_type compr_type; + int compr_lvl; + __u32 compr_chunk_size; stripe_size = lsa->lsa_stripe_size; stripe_count = lsa->lsa_stripe_count; pool_name = lsa->lsa_pool_name; + compr_type = lsa->lsa_compr_type; + compr_lvl = lsa->lsa_compr_lvl; + compr_chunk_size = lsa->lsa_compr_chunk_size; setstripe_args_init(lsa); lsa->lsa_stripe_size = stripe_size; lsa->lsa_stripe_count = stripe_count; lsa->lsa_pool_name = pool_name; + lsa->lsa_compr_type = compr_type; + lsa->lsa_compr_lvl = compr_lvl; + lsa->lsa_compr_chunk_size = compr_chunk_size; } static inline bool setstripe_args_specified(struct lfs_setstripe_args *lsa) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 3fa86f4..e50df41 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4969,9 +4969,10 @@ int printf_format_lustre(char *seq, char *buffer, size_t size, int *wrote, /* Other formats for files/dirs need to be handled differently */ if (d == -1) { /* file */ - //layout = llapi_layout_get_by_xattr(¶m->fp_lmd->lmd_lmm, - // param->fp_lum_size, 0); - layout = llapi_layout_get_by_path(path, 0); + layout = llapi_layout_get_by_xattr(¶m->fp_lmd->lmd_lmm, + param->fp_lum_size, 0); + if (layout == NULL) + layout = llapi_layout_get_by_path(path, 0); if (layout == NULL) { llapi_error(LLAPI_MSG_ERROR, errno, "error: cannot get file layout\n"); @@ -5034,6 +5035,21 @@ int printf_format_lustre(char *seq, char *buffer, size_t size, int *wrote, } *wrote = snprintf(buffer, size, "%"PRIu64, str_size); break; + case 'Z': { /* compression information */ + __u8 type; + __u8 lvl; + + err = llapi_layout_compress_get(layout, &type, &lvl); + if (err) { + llapi_error(LLAPI_MSG_ERROR, rc, + "error: cannot get compression information\n"); + goto format_done; + } + *wrote = snprintf(buffer, size, "%s:%d", + compress_type_2str(type), + mapback_compress_level(type, lvl)); + break; + } default: rc = 0; break; @@ -6061,7 +6077,7 @@ int validate_printf_fmt(char *c) { char *valid_fmt_single = "abcGkmnpstUwy%"; char *valid_fmt_double = "ACTW"; - char *valid_fmt_lustre = "cFhioPpS"; + char *valid_fmt_lustre = "cFhioPpSZ"; char curr = *c, next; if (curr == '\0') { diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index bceb431..7cb5367 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -650,6 +650,12 @@ struct llapi_layout *llapi_layout_get_by_xattr(void *lov_xattr, comp->llc_flags = ent->lcme_flags; if (comp->llc_flags & LCME_FL_NOSYNC) comp->llc_timestamp = ent->lcme_timestamp; + if (v1->lmm_pattern & LOV_PATTERN_COMPRESS) { + comp->llc_compr_type = ent->lcme_compr_type; + comp->llc_compr_lvl = ent->lcme_compr_lvl; + comp->llc_compr_chunk_log_bits = + ent->lcme_compr_chunk_log_bits; + } } else { comp->llc_extent.e_start = 0; comp->llc_extent.e_end = LUSTRE_EOF; @@ -1621,6 +1627,23 @@ fail: return -1; } +int llapi_layout_compress_get(struct llapi_layout *layout, + __u8 *type, __u8 *level) +{ + struct llapi_layout_comp *comp; + + comp = __llapi_layout_cur_comp(layout); + if (comp == NULL) + return -1; + + if (type) + *type = comp->llc_compr_type; + if (level) + *level = comp->llc_compr_lvl; + + return 0; +} + /** * Get the RAID pattern of \a layout. *