Whamcloud - gitweb
LU-9371 tools: handle component options properly 66/26766/13
authorNiu Yawei <yawei.niu@intel.com>
Fri, 21 Apr 2017 01:44:09 +0000 (21:44 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 3 Jun 2017 03:55:12 +0000 (03:55 +0000)
'lfs find' should match the file when any individual component of
the file matches all criteria. The component options should be
combined checking against individual component are:
--component-start, --component-end and --component-flags.

Fixed man page and usage message for 'lfs find':
'+N' actually means more than N, but not 'AT LEAST'
'-N' actually means less than N, but not 'AT MOST'

Test-Parameters: testlist=sanity-pfl
Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Change-Id: Ibdcd3167eb4b2de6d1754b9de563d3ec46828379
Reviewed-on: https://review.whamcloud.com/26766
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Emoly Liu <emoly.liu@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/doc/lfs.1
lustre/tests/sanity-pfl.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 707ca48..1187274 100644 (file)
@@ -161,7 +161,7 @@ for details of
 usage.
 .TP
 .B find
-To search the directory tree rooted at the given dir/file name for the files that match the given parameters: \fB--atime\fR (file was last accessed N*24 hours ago), \fB--ctime\fR (file's status was last changed N*24 hours ago), \fB--mtime\fR (file's data was last modified N*24 hours ago), \fB--obd\fR (file has an object on a specific OST or OSTs), \fB--size\fR (file has size in bytes, or \fBk\fRilo-, \fBM\fRega-, \fBG\fRiga-, \fBT\fRera-, \fBP\fReta-, or \fBE\fRxabytes if a suffix is given), \fB--type\fR (file has the type: \fBb\fRlock, \fBc\fRharacter, \fBd\fRirectory, \fBp\fRipe, \fBf\fRile, sym\fBl\fRink, \fBs\fRocket, or \fBD\fRoor (Solaris)), \fB--uid\fR (file has specific numeric user ID), \fB--user\fR (file owned by specific user, numeric user ID allowed), \fB--gid\fR (file has specific group ID), \fB--group\fR (file belongs to specific group, numeric group ID allowed),\fB--projid\fR (file has specific numeric project ID), \fB--layout\fR (file has a raid0 layout or is released). The option \fB--maxdepth\fR limits find to decend at most N levels of directory tree. The options \fB--print\fR and \fB--print0\fR print full file name, followed by a newline or NUL character correspondingly.  Using \fB!\fR before an option negates its meaning (\fIfiles NOT matching the parameter\fR).  Using \fB+\fR before a numeric value means \fIfiles with the parameter OR MORE\fR, while \fB-\fR before a numeric value means \fIfiles with the parameter OR LESS\fR.
+To search the directory tree rooted at the given dir/file name for the files that match the given parameters: \fB--atime\fR (file was last accessed N*24 hours ago), \fB--ctime\fR (file's status was last changed N*24 hours ago), \fB--mtime\fR (file's data was last modified N*24 hours ago), \fB--obd\fR (file has an object on a specific OST or OSTs), \fB--size\fR (file has size in bytes, or \fBk\fRilo-, \fBM\fRega-, \fBG\fRiga-, \fBT\fRera-, \fBP\fReta-, or \fBE\fRxabytes if a suffix is given), \fB--type\fR (file has the type: \fBb\fRlock, \fBc\fRharacter, \fBd\fRirectory, \fBp\fRipe, \fBf\fRile, sym\fBl\fRink, \fBs\fRocket, or \fBD\fRoor (Solaris)), \fB--uid\fR (file has specific numeric user ID), \fB--user\fR (file owned by specific user, numeric user ID allowed), \fB--gid\fR (file has specific group ID), \fB--group\fR (file belongs to specific group, numeric group ID allowed),\fB--projid\fR (file has specific numeric project ID), \fB--layout\fR (file has a raid0 layout or is released). The option \fB--maxdepth\fR limits find to decend at most N levels of directory tree. The options \fB--print\fR and \fB--print0\fR print full file name, followed by a newline or NUL character correspondingly.  Using \fB!\fR before an option negates its meaning (\fIfiles NOT matching the parameter\fR).  Using \fB+\fR before a numeric value means 'more than n', while \fB-\fR before a numeric value means 'less than n'.
 .TP
 .B getname [-h]|[path ...]
 Report all the Lustre mount points and the corresponding Lustre filesystem
@@ -346,7 +346,7 @@ Lists the detailed information of the component 2 in a given file
 Print only the component IDs for all the uninstantiated components
 .TP
 .B $ lfs getstripe -E-64M /mnt/lustre/file1
-Lists the information of the components in a file which has at most 64M extent end
+Lists the information of the components in a file which has less than 64M extent end
 .TP
 .B $ lfs getstripe -I3 --component-start /mnt/lustre/file1
 Print only the component start for the component with ID of 3
@@ -361,7 +361,7 @@ Recursively list all regular files in given directory more than 30 days old
 Recursively list all files in a given directory that have objects on OST2-UUID.
 .TP
 .B $ lfs find --component-count +3 /mnt/lustre
-Recursively list all files that have at least 3 components.
+Recursively list all files that have more than 3 components.
 .TP
 .B $ lfs check servers
 Check the status of all servers (MDT, OST)
index 33159c2..e893344 100644 (file)
@@ -566,6 +566,70 @@ test_14() {
 }
 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
 
+test_15() {
+       local parent=$DIR/$tdir
+
+       rm -fr $parent
+       test_mkdir -p $parent || error "Create dir $parent failed"
+
+       $LFS setstripe -d $parent || error "delete default layout"
+
+       $LFS setstripe -E 1M -E 10M -E eof $parent/f1 || error "create f1"
+       $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
+       test_mkdir -p $parent/subdir || error "create subdir"
+       $LFS setstripe -E 6M -E 30M -E eof $parent/subdir ||
+               error "setstripe to subdir"
+       $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
+       $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
+
+       # none
+       local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
+       [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
+
+       # f2, f3
+       found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
+       [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
+
+       # subdir
+       found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
+       [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
+
+       local flg_opts="--component-flags init"
+       # none
+       found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
+       [ $found -eq 0 ] ||
+               error "before write: start=1M, end=10M, flag=init, $found != 0"
+
+       dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
+               error "dd $parent/f1 failed"
+
+       # f1
+       found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
+       [ $found -eq 1 ] ||
+               error "after write: start=1M, end=10M, flag=init, $found != 1"
+
+       local ext_opts="--component-start -1M -E +5M"
+       # subdir, f3
+       found=$($LFS find $ext_opts $parent | wc -l)
+       [ $found -eq 2 ] || error "start-1M, end+5M, $found != 2"
+
+       local cnt_opts="--component-count +2"
+       # subdir
+       found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
+       [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
+
+       # none
+       found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
+       [ $found -eq 0 ] ||
+               error "start-1M, end+5M, count+2, flag=init, $found != 0"
+
+       # f3
+       found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
+       [ $found -eq 1 ] ||
+               error "start-1M, end+5M, !count+2, flag=init, $found != 1"
+}
+run_test 15 "Verify component options for lfs find"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status
index 2ae6ab0..7ba9003 100644 (file)
@@ -257,8 +257,8 @@ command_t cmdlist[] = {
         "     [[!] --mdt-count|-T [+-]<stripes>]\n"
         "     [[!] --mdt-hash|-H <hashtype>\n"
          "\t !: used before an option indicates 'NOT' requested attribute\n"
-         "\t -: used before a value indicates 'AT MOST' requested value\n"
-         "\t +: used before a value indicates 'AT LEAST' requested value\n"
+         "\t -: used before a value indicates less than requested value\n"
+         "\t +: used before a value indicates more than requested value\n"
         "\tmdt-hash:   hash type of the striped directory.\n"
         "\t            fnv_1a_64 FNV-1a hash algorithm\n"
         "\t            all_char  sum of characters % MDT_COUNT\n"},
index 59759ab..ff3940f 100644 (file)
@@ -3416,10 +3416,11 @@ static int find_check_comp_options(struct find_param *param)
                        return -1;
        }
 
-       if (param->fp_check_comp_flags) {
-               for (i = 0; i < comp_v1->lcm_entry_count; i++) {
-                       entry = &comp_v1->lcm_entries[i];
+       ret = 1;
+       for (i = 0; i < comp_v1->lcm_entry_count; i++) {
+               entry = &comp_v1->lcm_entries[i];
 
+               if (param->fp_check_comp_flags) {
                        if (((entry->lcme_flags & param->fp_comp_flags) &&
                             param->fp_exclude_comp_flags) ||
                            (!(entry->lcme_flags & param->fp_comp_flags) &&
@@ -3427,46 +3428,33 @@ static int find_check_comp_options(struct find_param *param)
                                ret = -1;
                        else
                                ret = 1;
-                       /* If any flags matches */
-                       if (ret != -1)
-                               break;
-               }
-               if (ret == -1)
-                       return ret;
-       }
 
-       if (param->fp_check_comp_start) {
-               for (i = 0; i < comp_v1->lcm_entry_count; i++) {
-                       entry = &comp_v1->lcm_entries[i];
+                       if (ret == -1)
+                               continue;
+               }
 
+               if (param->fp_check_comp_start) {
                        ret = find_value_cmp(entry->lcme_extent.e_start,
                                             param->fp_comp_start,
                                             param->fp_comp_start_sign,
                                             param->fp_exclude_comp_start,
                                             param->fp_comp_start_units, 0);
-                       /* If any extent start matches */
-                       if (ret != -1)
-                               break;
+                       if (ret == -1)
+                               continue;
                }
-               if (ret == -1)
-                       return ret;
-       }
-
-       if (param->fp_check_comp_end) {
-               for (i = 0; i < comp_v1->lcm_entry_count; i++) {
-                       entry = &comp_v1->lcm_entries[i];
 
+               if (param->fp_check_comp_end) {
                        ret = find_comp_end_cmp(entry->lcme_extent.e_end,
                                                param);
-                       /* If any extent end matches */
-                       if (ret != -1)
-                               break;
+                       if (ret == -1)
+                               continue;
                }
-               if (ret == -1)
-                       return ret;
+
+               /* the component matches all criteria */
+               break;
        }
 
-       return 1;
+       return ret;
 }
 
 static bool find_check_lmm_info(struct find_param *param)