From cbeffd6a981b8c6a79cd83a6b063bf55d4e9bb2b Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Wed, 5 Apr 2017 03:54:15 -0400 Subject: [PATCH] LU-8998 tools: parse optional argument properly Use standard way '-S[opt_arg]' or '--long[=opt_arg]' to specify optional arguments for 'lfs getstripe', the former way of parsing optional argument is flawed. Reverted use of '+' (at least), '-' (at most) for --component-start and --component-end options. Support "EOF/eof/-1" for the --component-end of 'lfs getstripe' & 'lfs find'. Updated man pages and test scripts accordingly. Signed-off-by: Niu Yawei Change-Id: I51980e9186675e3668a4b40a1edc5da6d2a1801c Reviewed-on: https://review.whamcloud.com/26491 Reviewed-by: Andreas Dilger Tested-by: Jenkins Reviewed-by: Bobi Jam Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/doc/lfs.1 | 62 ++++++++++++-------- lustre/tests/sanity-lfsck.sh | 48 ++++++++-------- lustre/tests/sanity-pfl.sh | 42 +++++++------- lustre/utils/lfs.c | 132 +++++++++++++++++++++++++++---------------- lustre/utils/liblustreapi.c | 57 ++++++++++++------- 5 files changed, 202 insertions(+), 139 deletions(-) diff --git a/lustre/doc/lfs.1 b/lustre/doc/lfs.1 index 852f574..707ca48 100644 --- a/lustre/doc/lfs.1 +++ b/lustre/doc/lfs.1 @@ -35,13 +35,18 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the .br .B lfs getname [-h]|[path ...] .br -.B lfs getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] - \fB[--stripe-count|-c ] [--stripe-index|-i] [--mdt-index|-M] [--fid|-F] - \fB[--stripe-size|-S] [--directory|-d] [--layout|-L] [--generation|-g] - \fB[--component-id|-I [comp_id]] [--component-flags [comp_flags]] - \fB[--component-count] [--component-start [+-][N][kMGTPE]] - \fB[--component-end|-E [+-][N][kMGTPE]] - \fB[--pool|-p] [--recursive|-r] [--raw|-R] ...\fR +.B lfs getstripe [\fB--obd\fR|\fB-O\fR <\fIuuid\fR>] [\fB--quiet\fR|\fB-q\fR] + [\fB--verbose\fR|\fB-v\fR] [\fB--stripe-count\fR|\fB-c\fR] + [\fB--stripe-index\fR|\fB-i\fR] [\fB--mdt-index\fR|\fB-M\fR] + [\fB--fid\fR|\fB-F\fR] [\fB--stripe-size\fR|\fB-S\fR] + [\fB--directory\fR|\fB-d\fR] [\fB--layout\fR|\fB-L\fR] + [\fB--generation\fR|\fB-g\fR] + [\fB--component-id\fR[=\fIcomp_id\fR]|\fB-I\fR[\fIcomp_id\fR]] + [\fB--component-flags\fR[=\fIcomp_flags\fR]] [\fB--component-count\fR] + [\fB--component-start\fR[=[+-]\fIN\fR[kMGTPE]]] + [\fB--component-end\fR[=[+-]\fIN\fR[kMGTPE]]|\fB-E\fR[[+-]\fIN\fR[kMGTPE]]] + [\fB--pool\fR|\fB-p\fR] [\fB--recursive\fR|\fB-r\fR] [\fB--raw\fR|\fB-R\fR] + <\fIdirname\fR|\fIfilename\fR> ... .br .B lfs migrate \fB-m \fR .IR directory @@ -170,15 +175,18 @@ List all the OSTs for all mounted filesystems. If a \fBpath\fR is provided that is located on a lustre mounted file system then only the OSTs belonging to that filesystem are displayed. .TP -.B getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] - \fB[--count | -c ] [--index | -i | --offset | -o ] - \fB[--pool | -p ] [--size | -s ] [--directory | -d ] - \fB[--layout | -L ] [--fid | -F ] [--generation | -g ] - \fB[--component-id|-I [comp_id]] - \fB[--component-flags [comp_flags]] - \fB[--component-count] [--component-start [+-][N][kMGTPE]] - \fB[--component-end|-E [+-][N][kMGTPE]] - \fB[--recursive | -r ] [--raw | -R ] \fR +.B getstripe [\fB--obd\fR|\fB-O\fR <\fIuuid\fR>] [\fB--quiet\fR|\fB-q\fR] + [\fB--verbose\fR|\fB-v\fR] [\fB--stripe-count\fR|\fB-c\fR] + [\fB--stripe-index\fR|\fB-i\fR] [\fB--mdt-index\fR|\fB-M\fR] + [\fB--fid\fR|\fB-F\fR] [\fB--stripe-size\fR|\fB-S\fR] + [\fB--directory\fR|\fB-d\fR] [\fB--layout\fR|\fB-L\fR] + [\fB--generation\fR|\fB-g\fR] + [\fB--component-id\fR[=\fIcomp_id\fR]|\fB-I\fR[\fIcomp_id\fR]] + [\fB--component-flags\fR[=\fIcomp_flags\fR]] [\fB--component-count\fR] + [\fB--component-start\fR[=[+-]\fIN\fR[kMGTPE]]] + [\fB--component-end\fR[=[+-]\fIN\fR[kMGTPE]]|\fB-E\fR[[+-]\fIN\fR[kMGTPE]]] + [\fB--pool\fR|\fB-p\fR] [\fB--recursive\fR|\fB-r\fR] [\fB--raw\fR|\fB-R\fR] + <\fIdirname\fR|\fIfilename\fR> ... .br List the striping information for a given filename or directory tree. By default the stripe count, size, and offset will be returned. If you @@ -229,12 +237,12 @@ The layout generation can be printed with the .B --generation option. You can limit the displayed content by specifing argument for -.B --component-id +.B --component-id|-I .B --component-flags .B --component-start -.B --component-end -options. For example, "--component-id 1" will only display the information -for component 1. +.B --component-end|-E +options. For example, "--component-id=2" or "-I2" will only display the layout +attributes for the component with id equal to 2. .TP .B fid2path [--link ] ... Print out the pathname(s) for the specified \fIfid\fR(s) from the filesystem @@ -331,11 +339,17 @@ Quit the interactive lfs session .B $ lfs getstripe -v /mnt/lustre/file1 Lists the detailed object allocation of a given file .TP -.B $ lfs getstripe -v --component-id 2 /mnt/lustre/file1 +.B $ lfs getstripe -v -I2 /mnt/lustre/file1 Lists the detailed information of the component 2 in a given file .TP -.B $ lfs getstripe -E -64M /mnt/lustre/file1 -Lists the information of the components in a file which has at least 64M extent end +.B $ lfs getstripe --component-flags=^init -I /mnt/lustre/file1 +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 +.TP +.B $ lfs getstripe -I3 --component-start /mnt/lustre/file1 +Print only the component start for the component with ID of 3 .TP .B $ lfs find /mnt/lustre Efficiently lists all files in a given directory and its subdirectories @@ -347,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 most 3 components. +Recursively list all files that have at least 3 components. .TP .B $ lfs check servers Check the status of all servers (MDT, OST) diff --git a/lustre/tests/sanity-lfsck.sh b/lustre/tests/sanity-lfsck.sh index 8e3fe72..a4d68b2 100644 --- a/lustre/tests/sanity-lfsck.sh +++ b/lustre/tests/sanity-lfsck.sh @@ -3373,38 +3373,38 @@ test_20b() { $LFS getstripe -v $name || error "(7.1) cannot getstripe on $name" - local pattern=$($LFS getstripe -L -I 1 $name) + local pattern=$($LFS getstripe -L -I1 $name) [[ "$pattern" = "$PATTERN_WITHOUT_HOLE" ]] || error "(7.2.1) NOT expect pattern flag hole, but got $pattern" - pattern=$($LFS getstripe -L -I 2 $name) + pattern=$($LFS getstripe -L -I2 $name) [[ "$pattern" = "$PATTERN_WITHOUT_HOLE" ]] || error "(7.2.2) NOT expect pattern flag hole, but got $pattern" - local stripes=$($LFS getstripe -c -I 1 $name) + local stripes=$($LFS getstripe -c -I1 $name) [ $stripes -eq 2 ] || error "(7.3.1) expect 2 stripes, but got $stripes" - stripes=$($LFS getstripe -c -I 2 $name) + stripes=$($LFS getstripe -c -I2 $name) [ $stripes -eq 2 ] || error "(7.3.2) expect 2 stripes, but got $stripes" - local e_start=$($LFS getstripe -I 1 $name | + local e_start=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 0 ] || error "(7.4.1) expect the COMP1 start at 0, got $e_start" - local e_end=$($LFS getstripe -I 1 $name | + local e_end=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ $e_end -eq 2097152 ] || error "(7.4.2) expect the COMP1 end at 2097152, got $e_end" - e_start=$($LFS getstripe -I 2 $name | + e_start=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 2097152 ] || error "(7.5.1) expect the COMP2 start at 2097152, got $e_start" - e_end=$($LFS getstripe -I 2 $name | + e_end=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ "$e_end" = "EOF" ] || error "(7.5.2) expect the COMP2 end at (EOF), got $e_end" @@ -3431,38 +3431,38 @@ test_20b() { $LFS getstripe -v $name || error "(8.1) cannot getstripe on $name" - pattern=$($LFS getstripe -L -I 1 $name) + pattern=$($LFS getstripe -L -I1 $name) [[ "$pattern" = "$PATTERN_WITH_HOLE" ]] || error "(8.2.1) expect pattern flag hole, but got $pattern" - pattern=$($LFS getstripe -L -I 2 $name) + pattern=$($LFS getstripe -L -I2 $name) [[ "$pattern" = "$PATTERN_WITH_HOLE" ]] || error "(8.2.2) expect pattern flag hole, but got $pattern" - stripes=$($LFS getstripe -c -I 1 $name) + stripes=$($LFS getstripe -c -I1 $name) [ $stripes -eq 2 ] || error "(8.3.2) expect 2 stripes, but got $stripes" - stripes=$($LFS getstripe -c -I 2 $name) + stripes=$($LFS getstripe -c -I2 $name) [ $stripes -eq 2 ] || error "(8.3.2) expect 2 stripes, but got $stripes" - e_start=$($LFS getstripe -I 1 $name | + e_start=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 0 ] || error "(8.4.1) expect the COMP1 start at 0, got $e_start" - e_end=$($LFS getstripe -I 1 $name | + e_end=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ $e_end -eq 2097152 ] || error "(8.4.2) expect the COMP1 end at 2097152, got $e_end" - e_start=$($LFS getstripe -I 2 $name | + e_start=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 2097152 ] || error "(8.5.1) expect the COMP2 start at 2097152, got $e_start" - e_end=$($LFS getstripe -I 2 $name | + e_end=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ "$e_end" = "EOF" ] || error "(8.5.2) expect the COMP2 end at (EOF), got $e_end" @@ -3506,38 +3506,38 @@ test_20b() { $LFS getstripe -v $name || error "(9.1) cannot getstripe on $name" - pattern=$($LFS getstripe -L -I 1 $name) + pattern=$($LFS getstripe -L -I1 $name) [[ "$pattern" = "$PATTERN_WITH_HOLE" ]] || error "(9.2.1) expect pattern flag hole, but got $pattern" - pattern=$($LFS getstripe -L -I 2 $name) + pattern=$($LFS getstripe -L -I2 $name) [[ "$pattern" = "$PATTERN_WITH_HOLE" ]] || error "(9.2.2) expect pattern flag hole, but got $pattern" - stripes=$($LFS getstripe -c -I 1 $name) + stripes=$($LFS getstripe -c -I1 $name) [ $stripes -eq 2 ] || error "(9.3.2) expect 2 stripes, but got $stripes" - stripes=$($LFS getstripe -c -I 2 $name) + stripes=$($LFS getstripe -c -I2 $name) [ $stripes -eq 2 ] || error "(9.3.2) expect 2 stripes, but got $stripes" - e_start=$($LFS getstripe -I 1 $name | + e_start=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 0 ] || error "(9.4.1) expect the COMP1 start at 0, got $e_start" - e_end=$($LFS getstripe -I 1 $name | + e_end=$($LFS getstripe -I1 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ $e_end -eq 2097152 ] || error "(9.4.2) expect the COMP1 end at 2097152, got $e_end" - e_start=$($LFS getstripe -I 2 $name | + e_start=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_start:/ { print $2 }') [ $e_start -eq 2097152 ] || error "(9.5.1) expect the COMP2 start at 2097152, got $e_start" - e_end=$($LFS getstripe -I 2 $name | + e_end=$($LFS getstripe -I2 $name | awk '/lcme_extent.e_end:/ { print $2 }') [ "$e_end" = "EOF" ] || error "(9.5.2) expect the COMP2 end at (EOF), got $e_end" diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index e49c7cb..33159c2 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -51,8 +51,8 @@ test_0() { #instantiate all components, so that objs are allocted dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k - local ost_idx1=$($LFS getstripe -I 1 -i $comp_file) - local ost_idx2=$($LFS getstripe -I 2 -i $comp_file) + local ost_idx1=$($LFS getstripe -I1 -i $comp_file) + local ost_idx2=$($LFS getstripe -I2 -i $comp_file) [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2" @@ -75,8 +75,8 @@ test_1() { #instantiate all components, so that objs are allocted dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k - local ost_idx1=$($LFS getstripe -I 1 -i $comp_file) - local ost_idx2=$($LFS getstripe -I 2 -i $comp_file) + local ost_idx1=$($LFS getstripe -I1 -i $comp_file) + local ost_idx2=$($LFS getstripe -I2 -i $comp_file) [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2" @@ -210,11 +210,11 @@ test_5() { #instantiate all components, so that objs are allocted dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k - local ost_idx=$($LFS getstripe -I 1 -i $comp_file) + local ost_idx=$($LFS getstripe -I1 -i $comp_file) [ $ost_idx -ne 0 ] && error "component 1 ost_idx $ost_idx != 0" - ost_idx=$($LFS getstripe -I 2 -i $comp_file) + ost_idx=$($LFS getstripe -I2 -i $comp_file) [ $ost_idx -ne 0 ] && error "component 2 ost_idx $ost_idx != 0" @@ -330,11 +330,11 @@ test_8() { -E -1 -c 4 -S 4M $parent || error "Set default layout to $parent failed" - sh rundbench -C -D $parent 2 || error "debench failed" + sh rundbench -C -D $parent 2 || error "dbench failed" rm -fr $parent || error "Delete dir $parent failed" } -run_test 8 "Run debench over composite files" +run_test 8 "Run dbench over composite files" test_9() { local comp_file=$DIR/$tdir/$tfile @@ -353,12 +353,12 @@ test_9() { # instantiate the 2nd component dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k - local f1=$($LFS getstripe -I 2 $comp_file | + local f1=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}') echo "before MDS recovery, the ost fid of 2nd component is $f1" fail $SINGLEMDS - local f2=$($LFS getstripe -I 2 $comp_file | + local f2=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}') echo "after MDS recovery, the ost fid of 2nd component is $f2" [ $f1 == $f2 ] || error "$f1 != $f2" @@ -427,34 +427,34 @@ test_11() { $LFS setstripe -E 1m -E 2m -E 3m -E -1 $comp_file || error "Create $comp_file failed" - local f1=$($LFS getstripe -I 1 $comp_file | grep "l_fid") + local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid") [[ -z $f1 ]] && error "1: 1st component uninstantiated" - local f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid") + local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid") [[ -n $f2 ]] && error "1: 2nd component instantiated" - local f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid") + local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid") [[ -n $f3 ]] && error "1: 3rd component instantiated" - local f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid") + local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid") [[ -n $f4 ]] && error "1: 4th component instantiated" # the first 2 components instantiated $TRUNCATE $comp_file $((1024*1024*1+1)) - f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid") + f2=$($LFS getstripe -I2 $comp_file | grep "l_fid") [[ -z $f2 ]] && error "2: 2nd component uninstantiated" - f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid") + f3=$($LFS getstripe -I3 $comp_file | grep "l_fid") [[ -n $f3 ]] && error "2: 3rd component instantiated" - f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid") + f4=$($LFS getstripe -I4 $comp_file | grep "l_fid") [[ -n $f4 ]] && error "2: 4th component instantiated" # the first 3 components instantiated $TRUNCATE $comp_file $((1024*1024*3)) $TRUNCATE $comp_file $((1024*1024*1+1)) - f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid") + f2=$($LFS getstripe -I2 $comp_file | grep "l_fid") [[ -z $f2 ]] && error "2: 2nd component uninstantiated" - f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid") + f3=$($LFS getstripe -I3 $comp_file | grep "l_fid") [[ -z $f3 ]] && error "3: 3rd component uninstantiated" - f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid") + f4=$($LFS getstripe -I4 $comp_file | grep "l_fid") [[ -n $f4 ]] && error "3: 4th component instantiated" # all 4 components instantiated, using append write @@ -463,7 +463,7 @@ test_11() { rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1 ls -l $comp_file - f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid") + f4=$($LFS getstripe -I4 $comp_file | grep "l_fid") [[ -z $f4 ]] && error "4: 4th component uninstantiated" return 0 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4b21114..2ae6ab0 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -203,11 +203,11 @@ command_t cmdlist[] = { " [--pool|-p] [--stripe-size|-S] [--directory|-d]\n" " [--mdt|-m] [--recursive|-r] [--raw|-R] [--yaml|-y]\n" " [--layout|-L] [--fid|-F] [--generation|-g]\n" - " [--component-id|-I [comp_id]]\n" - " [--component-flags [comp_flags]]\n" - " [--component-count [comp_count]]\n" - " [--component-start [comp_start]]\n" - " [--component-end|-E [comp_end]]\n" + " [--component-id[=comp_id]|-I[comp_id]]\n" + " [--component-flags[=comp_flags]]\n" + " [--component-count]\n" + " [--component-start[=[+-]comp_start]]\n" + " [--component-end[=[+-]comp_end]|-E[[+-]comp_end]]\n" " ..."}, {"setdirstripe", lfs_setdirstripe, 0, "To create a striped directory on a specified MDT. This can only\n" @@ -1167,7 +1167,16 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout) return -EINVAL; } - /* Current component of 'head' should be tail of component list. */ + /* Current component of 'head' should be tail of component list by + * default, but we do an extra move cursor operation here to test + * if the layout is non-composite. */ + rc = llapi_layout_comp_use(head, LLAPI_LAYOUT_COMP_USE_LAST); + if (rc < 0) { + fprintf(stderr, "'%s' isn't a composite file?\n", fname); + llapi_layout_free(head); + return rc; + } + rc = llapi_layout_comp_extent_get(head, &start, &prev_end); if (rc) { fprintf(stderr, "Get prev extent failed. %s\n", @@ -1273,6 +1282,13 @@ static int comp_name2flags(__u32 *flags, char *name) return 0; } +static inline bool arg_is_eof(char *arg) +{ + return !strncmp(arg, "-1", strlen("-1")) || + !strncmp(arg, "EOF", strlen("EOF")) || + !strncmp(arg, "eof", strlen("eof")); +} + enum { LFS_POOL_OPT = 3, LFS_COMP_COUNT_OPT, @@ -1430,9 +1446,7 @@ static int lfs_setstripe(int argc, char **argv) setstripe_args_init(&lsa); } - if (!strncmp(optarg, "-1", strlen("-1")) || - !strncmp(optarg, "EOF", strlen("EOF")) || - !strncmp(optarg, "eof", strlen("eof"))) { + if (arg_is_eof(optarg)) { lsa.lsa_comp_end = LUSTRE_EOF; } else { result = llapi_parse_size(optarg, @@ -1459,7 +1473,8 @@ static int lfs_setstripe(int argc, char **argv) break; case 'I': comp_id = strtoul(optarg, &end, 0); - if (*end != '\0' || comp_id == 0) { + if (*end != '\0' || comp_id == 0 || + comp_id > LCME_ID_MAX) { fprintf(stderr, "error: %s: bad comp ID " "'%s'\n", argv[0], optarg); goto error; @@ -1607,10 +1622,9 @@ static int lfs_setstripe(int argc, char **argv) goto error; } - /* support --component-id option for migrate later. */ - if (migrate_mode && comp_id != 0) { - fprintf(stderr, "error: %s: -I isn't supported yet.\n", - argv[0]); + if (!comp_del && !comp_set && comp_id != 0) { + fprintf(stderr, "error: %s: -I can only be used with " + "--component-del.\n", argv[0]); goto error; } @@ -1965,7 +1979,7 @@ static int lfs_find(int argc, char **argv) break; case LFS_COMP_FLAGS_OPT: rc = comp_name2flags(¶m.fp_comp_flags, optarg); - if (rc) { + if (rc || comp_flags_is_neg(param.fp_comp_flags)) { fprintf(stderr, "error: bad component flags " "'%s'\n", optarg); goto err; @@ -2023,8 +2037,15 @@ static int lfs_find(int argc, char **argv) optarg++; } - rc = llapi_parse_size(optarg, ¶m.fp_comp_end, - ¶m.fp_comp_end_units, 0); + if (arg_is_eof(optarg)) { + param.fp_comp_end = LUSTRE_EOF; + param.fp_comp_end_units = 1; + rc = 0; + } else { + rc = llapi_parse_size(optarg, + ¶m.fp_comp_end, + ¶m.fp_comp_end_units, 0); + } if (rc) { fprintf(stderr, "error: bad component end " "'%s'\n", optarg); @@ -2327,10 +2348,10 @@ static int lfs_getstripe_internal(int argc, char **argv, struct option long_opts[] = { {"comp-count", no_argument, 0, LFS_COMP_COUNT_OPT}, {"component-count", no_argument, 0, LFS_COMP_COUNT_OPT}, - {"comp-flags", required_argument, 0, LFS_COMP_FLAGS_OPT}, - {"component-flags", required_argument, 0, LFS_COMP_FLAGS_OPT}, - {"comp-start", required_argument, 0, LFS_COMP_START_OPT}, - {"component-start", required_argument, 0, LFS_COMP_START_OPT}, + {"comp-flags", optional_argument, 0, LFS_COMP_FLAGS_OPT}, + {"component-flags", optional_argument, 0, LFS_COMP_FLAGS_OPT}, + {"comp-start", optional_argument, 0, LFS_COMP_START_OPT}, + {"component-start", optional_argument, 0, LFS_COMP_START_OPT}, #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 59, 0) /* This formerly implied "stripe-count", but was explicitly * made "stripe-count" for consistency with other options, @@ -2341,8 +2362,8 @@ static int lfs_getstripe_internal(int argc, char **argv, {"stripe_count", no_argument, 0, 'c'}, {"directory", no_argument, 0, 'd'}, {"default", no_argument, 0, 'D'}, - {"comp-end", required_argument, 0, 'E'}, - {"component-end", required_argument, 0, 'E'}, + {"comp-end", optional_argument, 0, 'E'}, + {"component-end", optional_argument, 0, 'E'}, {"fid", no_argument, 0, 'F'}, {"generation", no_argument, 0, 'g'}, /* dirstripe {"mdt-hash", required_argument, 0, 'H'}, */ @@ -2354,8 +2375,8 @@ static int lfs_getstripe_internal(int argc, char **argv, #endif {"stripe-index", no_argument, 0, 'i'}, {"stripe_index", no_argument, 0, 'i'}, - {"comp-id", required_argument, 0, 'I'}, - {"component-id", required_argument, 0, 'I'}, + {"comp-id", optional_argument, 0, 'I'}, + {"component-id", optional_argument, 0, 'I'}, {"layout", no_argument, 0, 'L'}, {"mdt", no_argument, 0, 'm'}, {"mdt-index", no_argument, 0, 'm'}, @@ -2392,7 +2413,7 @@ static int lfs_getstripe_internal(int argc, char **argv, int c, rc; char *end, *tmp; - while ((c = getopt_long(argc, argv, "cdDE:FghiI:LmMoO:pqrRsSvy", + while ((c = getopt_long(argc, argv, "cdDE::FghiI::LmMoO:pqrRsSvy", long_opts, NULL)) != -1) { switch (c) { case 'c': @@ -2410,15 +2431,18 @@ static int lfs_getstripe_internal(int argc, char **argv, break; case LFS_COMP_FLAGS_OPT: if (optarg != NULL) { - rc = comp_name2flags(¶m->fp_comp_flags, - optarg); + __u32 *flags = ¶m->fp_comp_flags; + rc = comp_name2flags(flags, optarg); if (rc != 0) { - param->fp_verbose |= - VERBOSE_COMP_FLAGS; - param->fp_max_depth = 0; - optind--; + fprintf(stderr, "error: %s bad " + "component flags '%s'.\n", + argv[0], optarg); + return CMD_HELP; } else { param->fp_check_comp_flags = 1; + param->fp_exclude_comp_flags = + comp_flags_is_neg(*flags); + comp_flags_clear_neg(flags); } } else { param->fp_verbose |= VERBOSE_COMP_FLAGS; @@ -2429,19 +2453,20 @@ static int lfs_getstripe_internal(int argc, char **argv, if (optarg != NULL) { tmp = optarg; if (tmp[0] == '+') { - param->fp_comp_start_sign = 1; + param->fp_comp_start_sign = -1; tmp++; } else if (tmp[0] == '-') { - param->fp_comp_start_sign = -1; + param->fp_comp_start_sign = 1; tmp++; } rc = llapi_parse_size(tmp, ¶m->fp_comp_start, ¶m->fp_comp_start_units, 0); if (rc != 0) { - param->fp_verbose |= VERBOSE_COMP_START; - param->fp_max_depth = 0; - optind--; + fprintf(stderr, "error: %s bad " + "component start '%s'.\n", + argv[0], tmp); + return CMD_HELP; } else { param->fp_check_comp_start = 1; } @@ -2460,22 +2485,29 @@ static int lfs_getstripe_internal(int argc, char **argv, if (optarg != NULL) { tmp = optarg; if (tmp[0] == '+') { - param->fp_comp_end_sign = 1; + param->fp_comp_end_sign = -1; tmp++; } else if (tmp[0] == '-') { - param->fp_comp_end_sign = -1; + param->fp_comp_end_sign = 1; tmp++; } - rc = llapi_parse_size(tmp, + + if (arg_is_eof(tmp)) { + param->fp_comp_end = LUSTRE_EOF; + param->fp_comp_end_units = 1; + rc = 0; + } else { + rc = llapi_parse_size(tmp, ¶m->fp_comp_end, ¶m->fp_comp_end_units, 0); + } if (rc != 0) { - param->fp_verbose |= VERBOSE_COMP_END; - param->fp_max_depth = 0; - optind--; - } else { - param->fp_check_comp_end = 1; + fprintf(stderr, "error: %s bad " + "component end '%s'.\n", + argv[0], tmp); + return CMD_HELP; } + param->fp_check_comp_end = 1; } else { param->fp_verbose |= VERBOSE_COMP_END; param->fp_max_depth = 0; @@ -2512,10 +2544,12 @@ static int lfs_getstripe_internal(int argc, char **argv, case 'I': if (optarg != NULL) { param->fp_comp_id = strtoul(optarg, &end, 0); - if (*end != '\0') { - param->fp_verbose |= VERBOSE_COMP_ID; - param->fp_max_depth = 0; - optind--; + if (*end != '\0' || param->fp_comp_id == 0 || + param->fp_comp_id > LCME_ID_MAX) { + fprintf(stderr, "error: %s bad " + "component id '%s'\n", + argv[0], optarg); + return CMD_HELP; } else { param->fp_check_comp_id = 1; } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 5073a73..59759ab 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2779,6 +2779,31 @@ print_last_init_comp(struct find_param *param) return true; } +static int find_comp_end_cmp(unsigned long long end, struct find_param *param) +{ + int match; + + if (param->fp_comp_end == LUSTRE_EOF) { + if (param->fp_comp_end_sign == 0) /* equal to EOF */ + match = end == LUSTRE_EOF ? 1 : -1; + else if (param->fp_comp_end_sign > 0) /* at most EOF */ + match = end == LUSTRE_EOF ? -1 : 1; + else /* at least EOF */ + match = -1; + if (param->fp_exclude_comp_end) + match = ~match + 1; + } else { + unsigned long long margin; + + margin = end == LUSTRE_EOF ? 0 : param->fp_comp_end_units; + match = find_value_cmp(end, param->fp_comp_end, + param->fp_comp_end_sign, + param->fp_exclude_comp_end, margin, 0); + } + + return match; +} + /** * An example of "getstripe -v" for a two components PFL file: * @@ -2870,9 +2895,13 @@ static void lov_dump_comp_v1(struct find_param *param, char *path, for (i = 0; i < comp_v1->lcm_entry_count; i++) { entry = &comp_v1->lcm_entries[i]; - if (param->fp_check_comp_flags && - !(param->fp_comp_flags & entry->lcme_flags)) - continue; + if (param->fp_check_comp_flags) { + if ((param->fp_exclude_comp_flags && + (param->fp_comp_flags & entry->lcme_flags)) || + (!param->fp_exclude_comp_flags && + !(param->fp_comp_flags & entry->lcme_flags))) + continue; + } if (param->fp_check_comp_id && param->fp_comp_id != entry->lcme_id) @@ -2889,15 +2918,8 @@ static void lov_dump_comp_v1(struct find_param *param, char *path, } if (param->fp_check_comp_end) { - unsigned long long margin; - - margin = entry->lcme_extent.e_end == LUSTRE_EOF ? - 0 : param->fp_comp_end_units; - - match = find_value_cmp(entry->lcme_extent.e_end, - param->fp_comp_end, - param->fp_comp_end_sign, - 0, margin, 0); + match = find_comp_end_cmp(entry->lcme_extent.e_end, + param); if (match == -1) continue; } @@ -3432,17 +3454,10 @@ static int find_check_comp_options(struct find_param *param) if (param->fp_check_comp_end) { for (i = 0; i < comp_v1->lcm_entry_count; i++) { - unsigned long long margin; entry = &comp_v1->lcm_entries[i]; - margin = entry->lcme_extent.e_end == LUSTRE_EOF ? - 0 : param->fp_comp_end_units; - - ret = find_value_cmp(entry->lcme_extent.e_end, - param->fp_comp_end, - param->fp_comp_end_sign, - param->fp_exclude_comp_end, margin, - 0); + ret = find_comp_end_cmp(entry->lcme_extent.e_end, + param); /* If any extent end matches */ if (ret != -1) break; -- 1.8.3.1