Whamcloud - gitweb
EX-7714 utils: logical AND for 'lfs find' compression exprs
authorSebastien Buisson <sbuisson@ddn.com>
Wed, 21 Jun 2023 11:07:36 +0000 (11:07 +0000)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 23 Jun 2023 06:47:41 +0000 (06:47 +0000)
All search expressions provided to 'lfs find' must be combined as a
logical AND. Fix newly added options for compression support, so that
they comply with this logical AND.

Fixes: 093bd2f343 ("EX-6856 utils: add 'lfs find' support for compressed file")
Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: I3b28cd87c1d304df6d04753b413d46f5abcfe16e
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51393
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/tests/sanity-pfl.sh
lustre/utils/liblustreapi.c

index d8f9a00..48f7e9c 100644 (file)
@@ -2709,6 +2709,20 @@ test_100d() {
                        error "found $found compress level -$lvl file != $expect"
        done
 
+       # test combination of compr type and compr level
+       flg_opts="--compr-type=gzip --compr-level=1"
+       found=$($LFS find $flg_opts $DIR/$tdir | wc -l)
+       (( $found == 1 )) ||
+               error "found $found compress type gzip level 1 files != 1"
+       flg_opts="--compr-type=gzip ! --compr-level=1"
+       found=$($LFS find $flg_opts $DIR/$tdir | wc -l)
+       (( $found == 0 )) ||
+               error "found $found compress type gzip ! level 1 files != 0"
+       flg_opts="--compr-type=gzip --compr-level=2"
+       found=$($LFS find $flg_opts $DIR/$tdir | wc -l)
+       (( $found == 0 )) ||
+               error "found $found compress type gzip level 2 files != 0"
+
        cs="64 128 256 512"
        local i=1
        for chunk in $cs; do
index 8dc5dbb..7575ba8 100644 (file)
@@ -4364,6 +4364,7 @@ static int find_check_compress(struct find_param *param)
        int i, j;
        bool valid = false;
        bool found_type = false, found_lvl = false, found_chunk = false;
+       bool found;
        unsigned long long val;
 
        if (v1->lmm_magic != LOV_USER_MAGIC_COMP_V1)
@@ -4373,6 +4374,7 @@ static int find_check_compress(struct find_param *param)
 
        for (i = 0; i < comp_v1->lcm_entry_count; i++) {
                entry = &comp_v1->lcm_entries[i];
+               found = true;
 
                /**
                 * if it's not a compress file, don't count it as a valid
@@ -4431,27 +4433,33 @@ static int find_check_compress(struct find_param *param)
                        }
                }
 
-               if ((param->fp_check_compr_type && found_type) ||
-                   (param->fp_check_compr_lvl && found_lvl) ||
-                   (param->fp_check_compr_chunk && found_chunk))
+               if (param->fp_check_compr_type && !found_type)
+                       found = false;
+               if (param->fp_check_compr_lvl && !found_lvl)
+                       found = false;
+               if (param->fp_check_compr_chunk && !found_chunk)
+                       found = false;
+
+               if (found)
                        break;
        }
 
        if (!valid)
                return -1;
 
+       found = true;
        if (param->fp_check_compr_type &&
-           ((found_type && !param->fp_exclude_compr_type) ||
-            (!found_type && param->fp_exclude_compr_type)))
-               return 1;
+           ((!found_type && !param->fp_exclude_compr_type) ||
+            (found_type && param->fp_exclude_compr_type)))
+               found = false;
 
-       if (param->fp_check_compr_lvl && found_lvl)
-               return 1;
+       if (param->fp_check_compr_lvl && !found_lvl)
+               found = false;
 
-       if (param->fp_check_compr_chunk && found_chunk)
-               return 1;
+       if (param->fp_check_compr_chunk && !found_chunk)
+               found = false;
 
-       return -1;
+       return found ? 1 : -1;
 }
 
 #define LOV_PATTERN_INVALID    0xFFFFFFFF