From f1ac6aa3ab2ecb03bd944cec092b74543bb6f060 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Wed, 21 Jun 2023 12:00:07 +0000 Subject: [PATCH] EX-7715 utils: error for invalid compression level Not all compression types accept a compression level (e.g. lzo in its kernel implementation). For those, return an error if a compression level is provided on 'lfs setstripe' command-line. Signed-off-by: Sebastien Buisson Change-Id: I6c367c4bfd76cc81c890a89ba9f994f4fd9f4f80 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51394 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/tests/sanity-pfl.sh | 77 ++++++++++++++++++++++++-------------- lustre/tests/sanity.sh | 7 +++- lustre/utils/liblustreapi_layout.c | 19 ++++++++-- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index cb6603d..bbf9db7 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -2466,7 +2466,9 @@ test_100b() { skip "Need MDS >= 2.14.0.88 for compression support" local tf=$DIR/$tdir/$tfile - local type="gzip lz4 lz4hc lzo" + local type="gzip lz4 lz4hc" + # lzo does not grok a compression level, add here other such algs + local type_nolvl="lzo" local l1=1 local c1="64" local p="$TMP/$TESTSUITE-$TESTNAME.parameters" @@ -2505,11 +2507,15 @@ test_100b() { } # normal compress type - for t1 in $type; do + for t1 in $type $type_nolvl; do + local has_level="" + rm -f $tf - $LFS setstripe -Eeof -S4M -Z $t1:$l1 --compress-chunk=${c1} \ - $tf || error "set a compress component in $tf failed" + [[ "$type_nolvl" =~ "$t1" ]] || has_level="y" + $LFS setstripe -Eeof -S4M -Z $t1${has_level:+":$l1"} \ + --compress-chunk=${c1} $tf || + error "set a compress component in $tf failed" local t2=$($LFS getstripe --compr-type $tf) local l2=$($LFS getstripe --compr-level $tf) @@ -2520,7 +2526,7 @@ test_100b() { $LFS getstripe $tf error "compress type $t1 != $t2" } - (( $l1 == $l2 )) || { + [[ -z "$has_level" || "$l1" == "$l2" ]] || { $LFS getstripe $tf error "compress level $l1 != $l2" } @@ -2638,10 +2644,15 @@ test_100d() { skip "Need MDS >= 2.14.0.88 for compression support" local tf=$DIR/$tdir/$tfile - local type="gzip lz4 lz4hc lzo" + local type="gzip lz4 lz4hc" + local type_num=$(wc -w <<< $type) + # lzo does not grok a compression level, add here other such algs + local type_nolvl="lzo" + local type_nolvl_num=$(wc -w <<< $type_nolvl) local lvl=1 local cs="64" local p="$TMP/$TESTSUITE-$TESTNAME.parameters" + local expect save_lustre_params client "llite.*.enable_compression" > $p stack_trap "rm -rf $DIR/$tdir; restore_lustre_params < $p" EXIT @@ -2652,10 +2663,13 @@ test_100d() { error "setstripe upon $DIR/$tdir failed" # create compress component files - for tp in $type; do - $LFS setstripe -Eeof -Z $tp:$lvl --compress-chunk=${cs} \ - ${tf}_${tp} || - error "set a compress component in $tf_${tp} failed" + for tp in $type $type_nolvl; do + local has_level="" + + [[ "$type_nolvl" =~ "$tp" ]] || has_level="y" + $LFS setstripe -Eeof -Z $tp${has_level:+":$lvl"} \ + --compress-chunk=${cs} ${tf}_${tp} || + error "set a compress component in $tf_${tp} failed" $LFS setstripe -Eeof --comp-flags=nocompr ${tf}_nocompr_${tp} || error "set a nocompr component in $tf_nocompr_${tp} failed" $LFS setstripe -Eeof ${tf}_not_${tp} || @@ -2667,44 +2681,51 @@ test_100d() { local flg_opts="--comp-flags=compress" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 4 )) || - error "found $found compress (--comp-flags) file != 4" + expect=$((type_num + type_nolvl_num)) + (( found == expect )) || + error "found $found compress (--comp-flags) files != $expect" flg_opts="--comp-flags=nocompr" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 4 )) || error "found $found nocompr file != 4" + (( found == expect )) || + error "found $found nocompr file != $expect" flg_opts="--comp-flags=^compress" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 9 )) || error "found $found ^compress file != 9" + (( found == 2*expect+1 )) || + error "found $found ^compress file != $((2*expect+1))" flg_opts="-L compress" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 4 )) || error "found $found compress (--layout) file != 4" + (( found == expect )) || + error "found $found compress (--layout) file != $expect" - for tp in $type; do + for tp in $type $type_nolvl; do flg_opts="--compr-type=$tp" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 1 )) || error "found $found $tp compress file != 1" + (( found == 1 )) || error "found $found $tp compress file != 1" done + flg_opts="--compr-level=0" + found=$($LFS find $flg_opts $DIR/$tdir | wc -l) + (( found == type_nolvl_num )) || + error "found $found compr level $lvl file != $type_nolvl_num" - for lvl in $(seq 1 4); do + for lvl in $(seq 1 $type_num); do flg_opts="--compr-level=$lvl" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 1 )) || + (( found == 1 )) || error "found $found compress level $lvl file != 1" - flg_opts="--compr-level=+$lvl" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - expect=$((4 - lvl)) - (( $found == $expect )) || + expect=$(($type_num - lvl)) + (( found == expect )) || error "found $found compress level +$lvl file != $expect" flg_opts="--compr-level=-$lvl" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - expect=$lvl - (( $found == $expect )) || + expect=$((lvl + type_nolvl_num)) + (( found == expect )) || error "found $found compress level -$lvl file != $expect" done @@ -2727,19 +2748,19 @@ test_100d() { for chunk in $cs; do flg_opts="--compr-chunk=$chunk" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - (( $found == 1 )) || + (( found == 1 )) || error "found $found compress $chunk file != 1" flg_opts="--compr-chunk=+$chunk" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) - expect=$((4 - i)) - (( $found == $expect )) || + expect=$(($type_num + $type_nolvl_num - i)) + (( found == expect )) || error "found $found compress chunk +$chunk file != $expect" flg_opts="--compr-chunk=-$chunk" found=$($LFS find $flg_opts $DIR/$tdir | wc -l) expect=$i - (( $found == $expect )) || + (( found == expect )) || error "found $found compress chunk -$chunk file != $expect" ((i++)) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e7dc2f2..27e53fd 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -27525,8 +27525,13 @@ compress_type() { local decomp2=$TMP/$tdir/$tfile.dec_$orig_short.$t1$l1$c1.cp local decomp3=$TMP/$tdir/$tfile.dec_$orig_short.$t1$l1$c1.32.1.5 local decomp4=$TMP/$tdir/$tfile.dec_$orig_short.$t1$l1$c1.32.1.5.orig + # lzo does not grok a compression level, add here other such algs + local type_nolvl="lzo" + local has_level="" - $LFS setstripe -E 512K -Z $t1:$l1 -E 768K -Z none -E -1 -Z $t1:$l1 \ + [[ "$type_nolvl" =~ "$t1" ]] || has_level="y" + $LFS setstripe -E 512K -Z $t1${has_level:+":$l1"} -E 768K -Z none \ + -E -1 -Z $t1${has_level:+":$l1"} \ --compress-chunk=$c1 $stored_dir || error "set a compress component in $stored failed" diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index df5b987..4db23c1 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1546,7 +1546,7 @@ int llapi_layout_compress_set(struct llapi_layout *layout, comp = __llapi_layout_cur_comp(layout); if (comp == NULL) - return -1; + goto fail; /* type 0 means this is not a compress component */ comp->llc_compr_type = type; @@ -1569,10 +1569,17 @@ int llapi_layout_compress_set(struct llapi_layout *layout, } } if (!compr_level_set) { - if (level == -1) + if (level == -1) { comp->llc_compr_lvl = 0; - else + } else if (type == LL_COMPR_TYPE_FAST || + type == LL_COMPR_TYPE_BEST) { comp->llc_compr_lvl = level & 0xf; + } else { + fprintf(stderr, + "ERROR: compression type %s does not accept a compression level.\n", + compr_type_table[i].ctn_name); + goto fail; + } } /** @@ -1595,12 +1602,16 @@ int llapi_layout_compress_set(struct llapi_layout *layout, log_bits--; if (log_bits < 16 || log_bits > 31) - return -1; + goto fail; else comp->llc_compr_chunk_log_bits = log_bits - 16; } return 0; + +fail: + errno = EINVAL; + return -1; } /** -- 1.8.3.1