From: Andreas Dilger Date: Thu, 26 Jan 2012 10:45:20 +0000 (-0700) Subject: LU-611 utils: lfs find --stripe-{count,size,index} X-Git-Tag: 2.2.51~41 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=7a4548535558479bff6851fd5d29347f8efd56d7 LU-611 utils: lfs find --stripe-{count,size,index} Add options to "lfs find" so it can find files by their stripe-count, stripe-index, and stripe-size. For stripe-index (alias ost-index) it is possible to specify a comma-separated list of OST indexes. Make the short options for these consistent between "lfs find", "lfs getstripe" and "lfs setstripe", keeping the old options for usage compatibility. Add sanity.sh tests for the new "lfs find -c, -i, -S" options. Add a verbose deprecation for "lfs {get,set}stripe --offset" (which is too vague a term) and suggest "lfs {get,set}stripe --index", which existed since Lustre 1.8.1 and can be used for interop tests. The prefered long-term option name is --stripe-index, but this is not available in Lustre 1.8.x and would break interop tests. Remove deprecated "-v", "-q", and "-r" options from "lfs find". These are holdovers from when "lfs find" and "lfs getstripe" were the same command, and have been verbosely deprecated since the 1.6.4 release. Signed-off-by: Andreas Dilger Change-Id: Ia90de17e39e38543bcd9bc5a9861533accf6c158 Reviewed-on: http://review.whamcloud.com/1264 Reviewed-by: Yu Jian Reviewed-by: Li Wei Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/doc/lfs.1 b/lustre/doc/lfs.1 index d5d8d44..4e093e7 100644 --- a/lustre/doc/lfs.1 +++ b/lustre/doc/lfs.1 @@ -13,23 +13,26 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the .br .B lfs df [-i] [-h] [--pool|-p [.] [path] .br -.B lfs find [[!] --atime|-A [-+]N] [[!] --mtime|-M [-+]N] - \fB[[!] --ctime|-C [-+]N] [--maxdepth|-D N] [--name|-n pattern] - \fB[--print|-p] \fB[--print0|-P] [[!] --obd|-O ] - \fB[[!] --size|-S [-+]N[kMGTPE]] [--type |-t {bcdflpsD}] - \fB[[!] --gid|-g|--group|-G |] - \fB[[!] --uid|-u|--user|-U |] - \fB\fR +.B lfs find + \fB[[!] --atime|-A [-+]N] [[!] --mtime|-M [-+]N] [[!] --ctime|-C [+-]N] + \fB[--maxdepth|-D N] [[!] --mdt|-m ] [--name|-n pattern] + \fB[[!] --ost|-O ] [--print|-p] [--print0|-P] + \fB[[!] --size|-s [-+]N[kMGTPE]] + \fB[[!] --stripe-count|-c [+-]] + \fB[[!] --stripe-index|-i ] + \fB[[!] --stripe-size|-S [+-]N[kMG]] + \fB[--type |-t {bcdflpsD}] [[!] --gid|-g|--group|-G |] + \fB[[!] --uid|-u|--user|-U |] [[!] --pool ]\fR .br .B lfs getname [-h]|[path ...] .br .B lfs getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] - \fB[--count | -c ] [--index | -i | --offset | -o ] - \fB[--size | -s ] [--pool | -p ] [--directory | -d ] - \fB[--recursive | -r] [--raw|-R] ...\fR + \fB[--stripe-count|-c ] [--stripe-index|-i] [--mdt-index|-M] + \fB[--stripe-size|-S] [--directory|-d] + \fB[--pool|-p] [--recursive|-r] [--raw|-R] ...\fR .br -.B lfs setstripe [--size|-s stripe-size] [--count|-c stripe-cnt] - \fB[--index|-i|--offset|-o start_ost_index ] [--pool|-p ] +.B lfs setstripe [--stripe-size|-S stripe_size] [--stripe-count|-c stripe_count] + \fB[--stripe-index|-i start_ost_index ] [--pool|-p ] \fB\fR .br .B lfs setstripe -d @@ -159,8 +162,8 @@ can be used to limit the information, like You can limit the returned files to those with objects on a specific OST with .BR --obd . .TP -.B setstripe [--count|-c stripe_cnt] [--size|-s stripe_size] - \fB[--index|-i|--offset|-o start_ost_index] [--pool ] +.B setstripe [--stripe-count|-c stripe_count] [--stripe-size|-S stripe_size] + \fB[--stripe-index|-i start_ost_index] [--pool ] \fB\fR .br To create a new file, or set the directory default, with the specified striping parameters. The @@ -173,7 +176,7 @@ of -1 means to stripe over all available OSTs. The .I stripe_size is the number of bytes to store on each OST before moving to the next OST. A .I stripe_size -of 0 means to use the filesystem-wide default stripe size (default 1MB). The +of 0 means to use the filesystem-wide default stripe_size (default 1MB). The .I start_ost_index is the OST index (starting at 0) on which to start striping for this file. A .I start_ost_index diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index 331d3ee..9cb9f92 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -100,6 +100,7 @@ extern int llapi_file_lookup(int dirfd, const char *name); #define VERBOSE_DETAIL 0x10 #define VERBOSE_OBJID 0x20 #define VERBOSE_GENERATION 0x40 +#define VERBOSE_MDTINDEX 0x80 #define VERBOSE_ALL (VERBOSE_COUNT | VERBOSE_SIZE | VERBOSE_OFFSET | \ VERBOSE_POOL | VERBOSE_OBJID | VERBOSE_GENERATION) @@ -108,39 +109,41 @@ struct find_param { time_t atime; time_t mtime; time_t ctime; - int asign; - int csign; + int asign; /* cannot be bitfields due to using pointers to */ + int csign; /* access them during argument parsing. */ int msign; int type; + int size_sign:2, /* these need to be signed values */ + stripesize_sign:2, + stripecount_sign:2; unsigned long long size; - int size_sign; unsigned long long size_units; uid_t uid; gid_t gid; unsigned long zeroend:1, recursive:1, - got_uuids:1, - obds_printed:1, exclude_pattern:1, exclude_type:1, exclude_obd:1, exclude_mdt:1, - have_fileinfo:1, exclude_gid:1, exclude_uid:1, - check_gid:1, - check_uid:1, - check_pool:1, - check_size:1, + check_gid:1, /* group ID */ + check_uid:1, /* user ID */ + check_pool:1, /* LOV pool name */ + check_size:1, /* file size */ exclude_pool:1, exclude_size:1, exclude_atime:1, exclude_mtime:1, exclude_ctime:1, - get_mdt_index:1, - get_lmv:1, - raw:1; + get_lmv:1, /* get MDT list from LMV */ + raw:1, /* do not fill in defaults */ + check_stripesize:1, /* LOV stripe size */ + exclude_stripesize:1, + check_stripecount:1, /* LOV stripe count */ + exclude_stripecount:1; int verbose; int quiet; @@ -166,11 +169,18 @@ struct find_param { int lumlen; struct lov_user_mds_data *lmd; - /* In-precess parameters. */ - unsigned int depth; - dev_t st_dev; - char poolname[LOV_MAXPOOLNAME + 1]; + + unsigned long long stripesize; + unsigned long long stripesize_units; + unsigned long long stripecount; + + /* In-process parameters. */ + unsigned long got_uuids:1, + obds_printed:1, + have_fileinfo:1; /* file attrs and LOV xattr */ + unsigned int depth; + dev_t st_dev; }; extern int llapi_ostlist(char *path, struct find_param *param); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index f61d6da..8972b17 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -3306,17 +3306,20 @@ run_test 56a "check lfs getstripe ====================================" NUMFILES=3 NUMDIRS=3 setup_56() { - LOCAL_NUMFILES=$1 - LOCAL_NUMDIRS=$2 - if [ ! -d "$DIR/${tdir}g" ] ; then - mkdir -p $DIR/${tdir}g + local LOCAL_NUMFILES="$1" + local LOCAL_NUMDIRS="$2" + local MKDIR_PARAMS="$3" + + if [ ! -d "$TDIR" ] ; then + mkdir -p $TDIR + [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR for i in `seq 1 $LOCAL_NUMFILES` ; do - touch $DIR/${tdir}g/file$i + touch $TDIR/file$i done for i in `seq 1 $LOCAL_NUMDIRS` ; do - mkdir $DIR/${tdir}g/dir$i + mkdir $TDIR/dir$i for j in `seq 1 $LOCAL_NUMFILES` ; do - touch $DIR/${tdir}g/dir$i/file$j + touch $TDIR/dir$i/file$j done done fi @@ -3325,7 +3328,6 @@ setup_56() { setup_56_special() { LOCAL_NUMFILES=$1 LOCAL_NUMDIRS=$2 - TDIR=$DIR/${tdir}g setup_56 $1 $2 if [ ! -e "$TDIR/loop1b" ] ; then for i in `seq 1 $LOCAL_NUMFILES` ; do @@ -3342,34 +3344,36 @@ setup_56_special() { } test_56g() { - $LSTRIPE -d $DIR + $SETSTRIPE -d $DIR + TDIR=$DIR/${tdir}g setup_56 $NUMFILES $NUMDIRS EXPECTED=$(($NUMDIRS + 2)) # test lfs find with -name - for i in `seq 1 $NUMFILES` ; do - NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || error \ - "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + for i in $(seq 1 $NUMFILES) ; do + NUMS=$($LFIND -name "*$i" $TDIR | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "lfs find -name \"*$i\" $TDIR wrong: "\ + "found $NUMS, expected $EXPECTED" done - echo "lfs find -name passed." } run_test 56g "check lfs find -name =============================" test_56h() { - $LSTRIPE -d $DIR + $SETSTRIPE -d $DIR + TDIR=$DIR/${tdir}g setup_56 $NUMFILES $NUMDIRS - EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES)) + EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES)) # test lfs find with ! -name - for i in `seq 1 $NUMFILES` ; do - NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || error \ - "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + for i in $(seq 1 $NUMFILES) ; do + NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "lfs find ! -name \"*$i\" $TDIR wrong: "\ + "found $NUMS, expected $EXPECTED" done - echo "lfs find ! -name passed." } run_test 56h "check lfs find ! -name =============================" @@ -3377,64 +3381,74 @@ test_56i() { tdir=${tdir}i mkdir -p $DIR/$tdir UUID=$(ostuuid_from_index 0 $DIR/$tdir) - OUT=$($LFIND -obd $UUID $DIR/$tdir) - [ "$OUT" ] && error "$LFIND -obd returned directory '$OUT'" || true + CMD="$LFIND -ost $UUID $DIR/$tdir" + OUT=$($CMD) + [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'" } -run_test 56i "check 'lfs find -obd UUID' skips directories =======" +run_test 56i "check 'lfs find -ost UUID' skips directories =======" test_56j() { + TDIR=$DIR/${tdir}g setup_56_special $NUMFILES $NUMDIRS - EXPECTED=$((NUMDIRS+1)) - NUMS=`$LFIND -type d $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -type d $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + EXPECTED=$((NUMDIRS + 1)) + CMD="$LFIND -type d $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56j "check lfs find -type d =============================" test_56k() { + TDIR=$DIR/${tdir}g setup_56_special $NUMFILES $NUMDIRS - EXPECTED=$(((NUMDIRS+1) * NUMFILES)) - NUMS=`$LFIND -type f $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -type f $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + EXPECTED=$(((NUMDIRS + 1) * NUMFILES)) + CMD="$LFIND -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56k "check lfs find -type f =============================" test_56l() { + TDIR=$DIR/${tdir}g setup_56_special $NUMFILES $NUMDIRS EXPECTED=$((NUMDIRS + NUMFILES)) - NUMS=`$LFIND -type b $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -type b $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -type b $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56l "check lfs find -type b =============================" test_56m() { + TDIR=$DIR/${tdir}g setup_56_special $NUMFILES $NUMDIRS EXPECTED=$((NUMDIRS + NUMFILES)) - NUMS=`$LFIND -type c $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -type c $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -type c $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56m "check lfs find -type c =============================" test_56n() { + TDIR=$DIR/${tdir}g setup_56_special $NUMFILES $NUMDIRS EXPECTED=$((NUMDIRS + NUMFILES)) - NUMS=`$LFIND -type l $DIR/${tdir}g | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -type l $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -type l $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56n "check lfs find -type l =============================" test_56o() { - TDIR=$DIR/${tdir}g - rm -rf $TDIR + TDIR=$DIR/${tdir}o setup_56 $NUMFILES $NUMDIRS utime $TDIR/file1 > /dev/null || error "utime (1)" @@ -3450,109 +3464,250 @@ test_56o() { error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED" EXPECTED=12 - NUMS=`$LFIND -mtime 0 $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -mtime 0 $TDIR wrong: found $NUMS, expected $EXPECTED" - + CMD="$LFIND -mtime 0 $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56o "check lfs find -mtime for old files ==========================" test_56p() { - [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return - - TDIR=$DIR/${tdir}g - rm -rf $TDIR + [ $RUNAS_ID -eq $UID ] && + skip_env "RUNAS_ID = UID = $UID -- skipping" && return + TDIR=$DIR/${tdir}p setup_56 $NUMFILES $NUMDIRS chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed" EXPECTED=$NUMFILES - NUMS="`$LFIND -uid $RUNAS_ID $TDIR | wc -l`" + CMD="$LFIND -uid $RUNAS_ID $TDIR" + NUMS=$($CMD | wc -l) [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -uid $TDIR wrong: found $NUMS, expected $EXPECTED" + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" - EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1)) - NUMS="`$LFIND ! -uid $RUNAS_ID $TDIR | wc -l`" + EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1)) + CMD="$LFIND ! -uid $RUNAS_ID $TDIR" + NUMS=$($CMD | wc -l) [ $NUMS -eq $EXPECTED ] || \ - error "lfs find ! -uid $TDIR wrong: found $NUMS, expected $EXPECTED" - - echo "lfs find -uid and ! -uid passed." + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56p "check lfs find -uid and ! -uid ===============================" test_56q() { - [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return - - TDIR=$DIR/${tdir}g - rm -rf $TDIR + [ $RUNAS_ID -eq $UID ] && + skip_env "RUNAS_ID = UID = $UID -- skipping" && return + TDIR=$DIR/${tdir}q setup_56 $NUMFILES $NUMDIRS - chgrp $RUNAS_GID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed" + chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed" + EXPECTED=$NUMFILES - NUMS="`$LFIND -gid $RUNAS_GID $TDIR | wc -l`" - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find -gid $TDIR wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -gid $RUNAS_GID $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1)) - NUMS="`$LFIND ! -gid $RUNAS_GID $TDIR | wc -l`" - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find ! -gid $TDIR wrong: found $NUMS, expected $EXPECTED" - - echo "lfs find -gid and ! -gid passed." + CMD="$LFIND ! -gid $RUNAS_GID $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } run_test 56q "check lfs find -gid and ! -gid ===============================" test_56r() { + TDIR=$DIR/${tdir}r setup_56 $NUMFILES $NUMDIRS - TDIR=$DIR/${tdir}g EXPECTED=12 - NUMS=`$LFIND -size 0 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR -size 0 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -size 0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=0 - NUMS=`$LFIND ! -size 0 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR ! -size 0 wrong: found $NUMS, expected $EXPECTED" - echo "test" > $TDIR/56r && sync - echo "test2" > $TDIR/56r2 && sync + CMD="$LFIND ! -size 0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + echo "test" > $TDIR/$tfile + echo "test2" > $TDIR/$tfile.2 && sync EXPECTED=1 - NUMS=`$LFIND -size 5 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR -size 5 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -size 5 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=1 - NUMS=`$LFIND -size +5 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR -size +5 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -size +5 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=2 - NUMS=`$LFIND -size +0 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR -size +0 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -size +0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=2 - NUMS=`$LFIND ! -size -5 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR ! -size -5 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND ! -size -5 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" EXPECTED=12 - NUMS=`$LFIND -size -5 -t f $TDIR | wc -l` - [ $NUMS -eq $EXPECTED ] || \ - error "lfs find $TDIR -size -5 wrong: found $NUMS, expected $EXPECTED" + CMD="$LFIND -size -5 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" } - run_test 56r "check lfs find -size works ==========================" +test_56s() { # LU-611 + TDIR=$DIR/${tdir}s + setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" + + if [ $OSTCOUNT -gt 1 ]; then + $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3} + ONESTRIPE=4 + EXTRA=4 + else + ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES)) + EXTRA=0 + fi + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES)) + CMD="$LFIND -stripe_count $OSTCOUNT -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA)) + CMD="$LFIND -stripe_count +0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=$ONESTRIPE + CMD="$LFIND -stripe_count 1 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + CMD="$LFIND -stripe_count -2 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=0 + CMD="$LFIND -stripe_count $((OSTCOUNT + 1)) -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" +} +run_test 56s "check lfs find -stripe_count works" + +test_56t() { # LU-611 + TDIR=$DIR/${tdir}t + setup_56 $NUMFILES $NUMDIRS "-s 512k" + + $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3} + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES)) + CMD="$LFIND -stripe_size 512k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + CMD="$LFIND -stripe_size +320k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4)) + CMD="$LFIND -stripe_size +200k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + CMD="$LFIND -stripe_size -640k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=4 + CMD="$LFIND -stripe_size 256k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + CMD="$LFIND -stripe_size -320k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=0 + CMD="$LFIND -stripe_size 1024k -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" +} +run_test 56t "check lfs find -stripe_size works" + +test_56u() { # LU-611 + TDIR=$DIR/${tdir}u + setup_56 $NUMFILES $NUMDIRS "-i 0" + + if [ $OSTCOUNT -gt 1 ]; then + $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3} + ONESTRIPE=4 + else + ONESTRIPE=0 + fi + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES)) + CMD="$LFIND -stripe-index 0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=$ONESTRIPE + CMD="$LFIND -stripe-index 1 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + CMD="$LFIND ! -stripe-index 0 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=0 + # This should produce an error and not return any files + CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR" + NUMS=$($CMD 2>/dev/null | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" + + EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE)) + CMD="$LFIND -stripe-index 0,1 -type f $TDIR" + NUMS=$($CMD | wc -l) + [ $NUMS -eq $EXPECTED ] || + error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED" +} +run_test 56u "check lfs find -stripe-index works" + test_56v() { - local FIND_MDT_IDX=0 + local MDT_IDX=0 - TDIR=${tdir}g + TDIR=$DIR/${tdir}v rm -rf $TDIR setup_56 $NUMFILES $NUMDIRS - UUID=$(mdtuuid_from_index $FIND_MDT_IDX $DIR/$TDIR) - for file in $($LFIND -mdt $UUID $DIR/$TDIR); do + UUID=$(mdtuuid_from_index $MDT_IDX $TDIR) + [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX" + + for file in $($LFIND -mdt $UUID $TDIR); do file_mdt_idx=$($GETSTRIPE -M $file) - [ $file_mdt_idx -eq $FIND_MDT_IDX ] || - error "wrong lfind -m not match getstripe -M" + [ $file_mdt_idx -eq $MDT_IDX ] || + error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)" done } run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' =======" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 8ffc411..c2f190a 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -3476,7 +3476,7 @@ check_grant() { # get server grant server_grant=`do_nodes $(comma_list $(osts_nodes)) \ - "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \ + "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | awk '{total += $1} END{print total}'` # check whether client grant == server grant @@ -3522,7 +3522,7 @@ index_from_ostuuid() mdtuuid_from_index() { - $LFS mdts $2 | awk '/^'$1'/ { print $2 }' + $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p" } remote_node () { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index a52bd08..7a0198f 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -122,41 +122,45 @@ command_t cmdlist[] = { "Create a new file with a specific striping pattern or\n" "set the default striping pattern on an existing directory or\n" "delete the default striping pattern from an existing directory\n" - "usage: setstripe [--size|-s stripe_size] [--count|-c stripe_count]\n" - " [--index|-i|--offset|-o start_ost_index]\n" - " [--pool|-p ] \n" - " or \n" + "usage: setstripe [--stripe-count|-c ]\n" + " [--stripe-index|-i ]\n" + " [--stripe-size|-S ]\n" + " [--pool|-p ] \n" + " or\n" " setstripe -d (to delete default striping)\n" "\tstripe_size: Number of bytes on each OST (0 filesystem default)\n" "\t Can be specified with k, m or g (in KB, MB and GB\n" "\t respectively)\n" - "\tstart_ost_index: OST index of first stripe (-1 default)\n" + "\tstart_ost_idx: OST index of first stripe (-1 default)\n" "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n" - "\tpool: Name of OST pool to use (default none)"}, + "\tpool_name: Name of OST pool to use (default none)"}, {"getstripe", lfs_getstripe, 0, "To list the striping info for a given file or files in a\n" "directory or recursively for all files in a directory tree.\n" - "usage: getstripe [--obd|-O ] [--quiet | -q] [--verbose | -v]\n" - " [--count | -c ] [--index | -i | --offset | -o]\n" - " [--size | -s ] [--pool | -p ] [--directory | -d]\n" - " [--mdt | -M] [--recursive | -r] [--raw | -R]\n" + "usage: getstripe [--ost|-O ] [--quiet | -q] [--verbose | -v]\n" + " [--stripe-count|-c] [--stripe-index|-i]\n" + " [--pool|-p] [--stripe-size|-S] [--directory|-d]\n" + " [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n" " ..."}, {"pool_list", lfs_poollist, 0, "List pools or pool OSTs\n" "usage: pool_list [.] | \n"}, {"find", lfs_find, 0, - "To find files that match given parameters recursively in a directory tree.\n" + "find files matching given attributes recursively in directory tree.\n" "usage: find ...\n" - " [[!] --atime|-A [+-]N] [[!] --mtime|-M [+-]N] [[!] --ctime|-C [+-]N]\n" - " [--maxdepth|-D N] [[!] --name|-n ] [--print0|-P]\n" - " [--print|-p] [[!] --obd|-O ] [[!] --mdt|-m ]\n" + " [[!] --atime|-A [+-]N] [[!] --ctime|-C [+-]N]\n" + " [[!] --mtime|-M [+-]N] [[!] --mdt|-m ]\n" + " [--maxdepth|-D N] [[!] --name|-n ]\n" + " [[!] --ost|-O ] [--print|-p] [--print0|-P]\n" + " [[!] --size|-s [+-]N[bkMGTPE]]\n" + " [[!] --stripe-count|-c [+-]]\n" + " [[!] --stripe-index|-i ]\n" + " [[!] --stripe-size|-S [+-]N[kMGT]] [[!] --type|-t ]\n" " [[!] --gid|-g|--group|-G |]\n" - " [[!] --uid|-u|--user|-U |]\n" - " [[!] --pool ]\n" - "\t !: used before an option indicates 'NOT' the requested attribute\n" - "\t -: used before an value indicates 'AT MOST' the requested value\n" - "\t +: used before an option indicates 'AT LEAST' the requested value\n"}, + " [[!] --uid|-u|--user|-U |] [[!] --pool ]\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"}, {"check", lfs_check, 0, "Display the status of MDS or OSTs (as specified in the command)\n" "or all the servers (MDS and OSTs).\n" @@ -293,12 +297,46 @@ static int lfs_setstripe(int argc, char **argv) unsigned long long size_units = 1; struct option long_opts[] = { - {"count", required_argument, 0, 'c'}, - {"delete", no_argument, 0, 'd'}, - {"index", required_argument, 0, 'i'}, - {"offset", required_argument, 0, 'o'}, - {"pool", required_argument, 0, 'p'}, - {"size", required_argument, 0, 's'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --count option" +#else + /* This formerly implied "stripe-count", but was explicitly + * made "stripe-count" for consistency with other options, + * and to separate it from "mdt-count" when DNE arrives. */ + {"count", required_argument, 0, 'c'}, +#endif + {"stripe-count", required_argument, 0, 'c'}, + {"stripe_count", required_argument, 0, 'c'}, + {"delete", no_argument, 0, 'd'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --index option" +#else + /* This formerly implied "stripe-index", but was explicitly + * made "stripe-index" for consistency with other options, + * and to separate it from "mdt-index" when DNE arrives. */ + {"index", required_argument, 0, 'i'}, +#endif + {"stripe-index", required_argument, 0, 'i'}, + {"stripe_index", required_argument, 0, 'i'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --offset option" +#else + /* This formerly implied "stripe-index", but was confusing + * with "file offset" (which will eventually be needed for + * with different layouts by offset), so deprecate it. */ + {"offset", required_argument, 0, 'o'}, +#endif + {"pool", required_argument, 0, 'p'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --size option" +#else + /* This formerly implied "--stripe-size", but was confusing + * with "lfs find --size|-s", which means "file size", so use + * the consistent "--stripe-size|-S" for all commands. */ + {"size", required_argument, 0, 's'}, +#endif + {"stripe-size", required_argument, 0, 'S'}, + {"stripe_size", required_argument, 0, 'S'}, {0, 0, 0, 0} }; @@ -310,45 +348,70 @@ static int lfs_setstripe(int argc, char **argv) if (argc == 5 && argv[1][0] != '-' && isnumber(argv[2]) && isnumber(argv[3]) && isnumber(argv[4])) { fprintf(stderr, "error: obsolete usage of setstripe " - "positional parameters. Use -c, -i, -s instead.\n"); + "positional parameters. Use -c, -i, -S instead.\n"); return CMD_HELP; } else #else -#warning "remove obsolete positional parameter code" +#warning "remove obsolete positional parameter error" #endif { optind = 0; - while ((c = getopt_long(argc, argv, "c:di:o:p:s:", + while ((c = getopt_long(argc, argv, "c:di:o:p:s:S:", long_opts, NULL)) >= 0) { - switch (c) { - case 0: - /* Long options. */ - break; - case 'c': - stripe_count_arg = optarg; - break; - case 'd': - /* delete the default striping pattern */ - delete = 1; - break; - case 'i': - case 'o': - stripe_off_arg = optarg; - break; - case 's': - stripe_size_arg = optarg; - break; - case 'p': - pool_name_arg = optarg; - break; - case '?': - return CMD_HELP; - default: - fprintf(stderr, "error: %s: option '%s' " - "unrecognized\n", - argv[0], argv[optind - 1]); - return CMD_HELP; - } + switch (c) { + case 0: + /* Long options. */ + break; + case 'c': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --count option" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + if (strcmp(argv[optind - 1], "--count") == 0) + fprintf(stderr, "warning: '--count' deprecated" + ", use '--stripe-count' instead\n"); +#endif + stripe_count_arg = optarg; + break; + case 'd': + /* delete the default striping pattern */ + delete = 1; + break; + case 'o': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0) + fprintf(stderr, "warning: '--offset|-o' deprecated, " + "use '--stripe-index|-i' instead\n"); +#else + if (strcmp(argv[optind - 1], "--offset") == 0) + /* need --stripe-index established first */ + fprintf(stderr, "warning: '--offset' deprecated" + ", use '--index' instead\n"); +#endif + case 'i': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --offset and --index options" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + if (strcmp(argv[optind - 1], "--index") == 0) + fprintf(stderr, "warning: '--index' deprecated" + ", use '--stripe-index' instead\n"); +#endif + stripe_off_arg = optarg; + break; + case 's': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --size option" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + fprintf(stderr, "warning: '--size|-s' deprecated, " + "use '--stripe-size|-S' instead\n"); +#endif + case 'S': + stripe_size_arg = optarg; + break; + case 'p': + pool_name_arg = optarg; + break; + default: + return CMD_HELP; + } } fname = argv[optind]; @@ -357,7 +420,7 @@ static int lfs_setstripe(int argc, char **argv) (stripe_size_arg != NULL || stripe_off_arg != NULL || stripe_count_arg != NULL || pool_name_arg != NULL)) { fprintf(stderr, "error: %s: cannot specify -d with " - "-s, -c -o or -p options\n", + "-s, -c, -o, or -p options\n", argv[0]); return CMD_HELP; } @@ -373,7 +436,7 @@ static int lfs_setstripe(int argc, char **argv) if (stripe_size_arg != NULL) { result = parse_size(stripe_size_arg, &st_size, &size_units, 0); if (result) { - fprintf(stderr, "error: %s: bad size '%s'\n", + fprintf(stderr, "error: %s: bad stripe size '%s'\n", argv[0], stripe_size_arg); return result; } @@ -504,33 +567,34 @@ static int id2name(char **name, unsigned int id, int type) #define FIND_POOL_OPT 3 static int lfs_find(int argc, char **argv) { - int new_fashion = 1; int c, ret; time_t t; - struct find_param param = { .maxdepth = -1, .size_units = 0 }; + struct find_param param = { .maxdepth = -1, .quiet = 1 }; struct option long_opts[] = { - {"atime", required_argument, 0, 'A'}, - {"ctime", required_argument, 0, 'C'}, - {"maxdepth", required_argument, 0, 'D'}, - {"gid", required_argument, 0, 'g'}, - {"group", required_argument, 0, 'G'}, - {"mtime", required_argument, 0, 'M'}, - {"mdt", required_argument, 0, 'm'}, - {"name", required_argument, 0, 'n'}, - /* --obd is considered as a new option. */ - {"obd", required_argument, 0, 'O'}, - {"ost", required_argument, 0, 'O'}, + {"atime", required_argument, 0, 'A'}, + {"stripe-count", required_argument, 0, 'c'}, + {"stripe_count", required_argument, 0, 'c'}, + {"ctime", required_argument, 0, 'C'}, + {"maxdepth", required_argument, 0, 'D'}, + {"gid", required_argument, 0, 'g'}, + {"group", required_argument, 0, 'G'}, + {"stripe-index", required_argument, 0, 'i'}, + {"stripe_index", required_argument, 0, 'i'}, + {"mdt", required_argument, 0, 'm'}, + {"mtime", required_argument, 0, 'M'}, + {"name", required_argument, 0, 'n'}, + {"obd", required_argument, 0, 'O'}, + {"ost", required_argument, 0, 'O'}, /* no short option for pool, p/P already used */ - {"pool", required_argument, 0, FIND_POOL_OPT}, - {"print0", no_argument, 0, 'p'}, - {"print", no_argument, 0, 'P'}, - {"quiet", no_argument, 0, 'q'}, - {"recursive", no_argument, 0, 'r'}, - {"size", required_argument, 0, 's'}, - {"type", required_argument, 0, 't'}, - {"uid", required_argument, 0, 'u'}, - {"user", required_argument, 0, 'U'}, - {"verbose", no_argument, 0, 'v'}, + {"pool", required_argument, 0, FIND_POOL_OPT}, + {"print0", no_argument, 0, 'p'}, + {"print", no_argument, 0, 'P'}, + {"size", required_argument, 0, 's'}, + {"stripe-size", required_argument, 0, 'S'}, + {"stripe_size", required_argument, 0, 'S'}, + {"type", required_argument, 0, 't'}, + {"uid", required_argument, 0, 'u'}, + {"user", required_argument, 0, 'U'}, {0, 0, 0, 0} }; int pathstart = -1; @@ -545,8 +609,9 @@ static int lfs_find(int argc, char **argv) optind = 0; /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */ - while ((c = getopt_long_only(argc, argv, "-A:C:D:g:G:M:m:n:O:" - "Ppqrs:t:u:U:v", long_opts, NULL)) >= 0) { + while ((c = getopt_long_only(argc, argv, + "-A:c:C:D:g:G:i:m:M:n:O:Ppqrs:S:t:u:U:v", + long_opts, NULL)) >= 0) { xtime = NULL; xsign = NULL; if (neg_opt) @@ -568,13 +633,8 @@ static int lfs_find(int argc, char **argv) } if (!isoption && pathstart == -1) pathstart = optind - 1; - if (isoption && pathstart != -1 && pathend == -1) { + if (isoption && pathstart != -1 && pathend == -1) pathend = optind - 2; - if ((c == 1 && strcmp(optarg, "!") == 0) || - c == 'P' || c == 'p' || c == 'O' || - c == 'q' || c == 'r' || c == 'v') - pathend = optind - 1; - } switch (c) { case 0: /* Long options. */ @@ -590,19 +650,20 @@ static int lfs_find(int argc, char **argv) xtime = ¶m.atime; xsign = ¶m.asign; param.exclude_atime = !!neg_opt; + /* no break, this falls through to 'C' for ctime */ case 'C': if (c == 'C') { xtime = ¶m.ctime; xsign = ¶m.csign; param.exclude_ctime = !!neg_opt; } + /* no break, this falls through to 'M' for mtime */ case 'M': if (c == 'M') { xtime = ¶m.mtime; xsign = ¶m.msign; param.exclude_mtime = !!neg_opt; } - new_fashion = 1; ret = set_time(&t, xtime, optarg); if (ret == INT_MAX) { ret = -1; @@ -611,13 +672,30 @@ static int lfs_find(int argc, char **argv) if (ret) *xsign = ret; break; + case 'c': + if (optarg[0] == '+') { + param.stripecount_sign = -1; + optarg++; + } else if (optarg[0] == '-') { + param.stripecount_sign = 1; + optarg++; + } + + param.stripecount = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr,"error: bad stripe_count '%s'\n", + optarg); + ret = -1; + goto err; + } + param.check_stripecount = 1; + param.exclude_stripecount = !!neg_opt; + break; case 'D': - new_fashion = 1; param.maxdepth = strtol(optarg, 0, 0); break; case 'g': case 'G': - new_fashion = 1; ret = name2id(¶m.gid, optarg, GROUP); if (ret) { param.gid = strtoul(optarg, &endptr, 10); @@ -633,7 +711,6 @@ static int lfs_find(int argc, char **argv) break; case 'u': case 'U': - new_fashion = 1; ret = name2id(¶m.uid, optarg, USER); if (ret) { param.uid = strtoul(optarg, &endptr, 10); @@ -648,7 +725,6 @@ static int lfs_find(int argc, char **argv) param.check_uid = 1; break; case FIND_POOL_OPT: - new_fashion = 1; if (strlen(optarg) > LOV_MAXPOOLNAME) { fprintf(stderr, "Pool name %s is too long" @@ -665,11 +741,11 @@ static int lfs_find(int argc, char **argv) param.check_pool = 1; break; case 'n': - new_fashion = 1; param.pattern = (char *)optarg; param.exclude_pattern = !!neg_opt; break; case 'm': + case 'i': case 'O': { char *buf, *token, *next, *p; int len = 1; @@ -691,16 +767,7 @@ static int lfs_find(int argc, char **argv) token++; } } - if (c == 'O') { - param.exclude_obd = !!neg_opt; - param.num_alloc_obds += len; - tmp = realloc(param.obduuid, - param.num_alloc_obds * - sizeof(*param.obduuid)); - if (tmp == NULL) - GOTO(err_free, ret = -ENOMEM); - param.obduuid = tmp; - } else { + if (c == 'm') { param.exclude_mdt = !!neg_opt; param.num_alloc_mdts += len; tmp = realloc(param.mdtuuid, @@ -709,15 +776,24 @@ static int lfs_find(int argc, char **argv) if (tmp == NULL) GOTO(err_free, ret = -ENOMEM); param.mdtuuid = tmp; + } else { + param.exclude_obd = !!neg_opt; + param.num_alloc_obds += len; + tmp = realloc(param.obduuid, + param.num_alloc_obds * + sizeof(*param.obduuid)); + if (tmp == NULL) + GOTO(err_free, ret = -ENOMEM); + param.obduuid = tmp; } for (token = buf; token && *token; token = next) { char *uuid; - if (c == 'O') + if (c == 'm') uuid = - param.obduuid[param.num_obds++].uuid; + param.mdtuuid[param.num_mdts++].uuid; else uuid = - param.mdtuuid[param.num_mdts++].uuid; + param.obduuid[param.num_obds++].uuid; p = strchr(token, ','); next = 0; if (p) { @@ -732,19 +808,47 @@ err_free: break; } case 'p': - new_fashion = 1; param.zeroend = 1; break; case 'P': break; - case 'q': - new_fashion = 0; - param.quiet++; - param.verbose = 0; + case 's': + if (optarg[0] == '+') { + param.size_sign = -1; + optarg++; + } else if (optarg[0] == '-') { + param.size_sign = 1; + optarg++; + } + + ret = parse_size(optarg, ¶m.size, + ¶m.size_units, 0); + if (ret) { + fprintf(stderr, "error: bad file size '%s'\n", + optarg); + goto err; + } + param.check_size = 1; + param.exclude_size = !!neg_opt; break; - case 'r': - new_fashion = 0; - param.recursive = 1; + case 'S': + if (optarg[0] == '+') { + param.stripesize_sign = -1; + optarg++; + } else if (optarg[0] == '-') { + param.stripesize_sign = 1; + optarg++; + } + + ret = parse_size(optarg, ¶m.stripesize, + ¶m.stripesize_units, 0); + if (ret) { + fprintf(stderr, "error: bad stripe_size '%s'\n", + optarg); + goto err; + } + param.check_stripesize = 1; + param.exclude_stripesize = !!neg_opt; break; case 't': param.exclude_type = !!neg_opt; @@ -765,35 +869,7 @@ err_free: goto err; }; break; - case 's': - if (optarg[0] == '+') - param.size_sign = -1; - else if (optarg[0] == '-') - param.size_sign = +1; - - if (param.size_sign) - optarg++; - ret = parse_size(optarg, ¶m.size, - ¶m.size_units, 0); - if (ret) { - fprintf(stderr,"error: bad size '%s'\n", - optarg); - goto err; - } - param.check_size = 1; - param.exclude_size = !!neg_opt; - break; - case 'v': - new_fashion = 0; - param.verbose++; - param.quiet = 0; - break; - case '?': - ret = CMD_HELP; - goto err; default: - fprintf(stderr, "error: %s: option '%s' unrecognized\n", - argv[0], argv[optind - 1]); ret = CMD_HELP; goto err; }; @@ -809,24 +885,8 @@ err_free: pathend = argc; } - if (new_fashion) { - param.quiet = 1; - } else { - static int deprecated_warning; - if (!deprecated_warning) { - fprintf(stderr, "lfs find: -q, -r, -v options " - "deprecated. Use 'lfs getstripe' instead.\n"); - deprecated_warning = 1; - } - if (!param.recursive && param.maxdepth == -1) - param.maxdepth = 1; - } - do { - if (new_fashion) - ret = llapi_find(argv[pathstart], ¶m); - else - ret = llapi_getstripe(argv[pathstart], ¶m); + ret = llapi_find(argv[pathstart], ¶m); } while (++pathstart < pathend && !ret); if (ret) @@ -845,19 +905,55 @@ err: static int lfs_getstripe(int argc, char **argv) { struct option long_opts[] = { - {"count", 0, 0, 'c'}, - {"directory", 0, 0, 'd'}, - {"generation", 0, 0, 'g'}, - {"index", 0, 0, 'i'}, - {"mdt", 0, 0, 'M'}, - {"offset", 0, 0, 'o'}, - {"obd", 1, 0, 'O'}, - {"pool", 0, 0, 'p'}, - {"quiet", 0, 0, 'q'}, - {"recursive", 0, 0, 'r'}, - {"raw", 0, 0, 'R'}, - {"size", 0, 0, 's'}, - {"verbose", 0, 0, 'v'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --count option" +#else + /* This formerly implied "stripe-count", but was explicitly + * made "stripe-count" for consistency with other options, + * and to separate it from "mdt-count" when DNE arrives. */ + {"count", no_argument, 0, 'c'}, +#endif + {"stripe-count", no_argument, 0, 'c'}, + {"stripe_count", no_argument, 0, 'c'}, + {"directory", no_argument, 0, 'd'}, + {"generation", no_argument, 0, 'g'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --index option" +#else + /* This formerly implied "stripe-index", but was explicitly + * made "stripe-index" for consistency with other options, + * and to separate it from "mdt-index" when DNE arrives. */ + {"index", no_argument, 0, 'i'}, +#endif + {"stripe-index", no_argument, 0, 'i'}, + {"stripe_index", no_argument, 0, 'i'}, + {"mdt-index", no_argument, 0, 'M'}, + {"mdt_index", no_argument, 0, 'M'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --offset option" +#else + /* This formerly implied "stripe-index", but was confusing + * with "file offset" (which will eventually be needed for + * with different layouts by offset), so deprecate it. */ + {"offset", no_argument, 0, 'o'}, +#endif + {"obd", required_argument, 0, 'O'}, + {"ost", required_argument, 0, 'O'}, + {"pool", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"recursive", no_argument, 0, 'r'}, + {"raw", no_argument, 0, 'R'}, +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --size option" +#else + /* This formerly implied "--stripe-size", but was confusing + * with "lfs find --size|-s", which means "file size", so use + * the consistent "--stripe-size|-S" for all commands. */ + {"size", no_argument, 0, 's'}, +#endif + {"stripe-size", no_argument, 0, 'S'}, + {"stripe_size", no_argument, 0, 'S'}, + {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; int c, rc; @@ -865,7 +961,7 @@ static int lfs_getstripe(int argc, char **argv) param.maxdepth = 1; optind = 0; - while ((c = getopt_long(argc, argv, "cdghiMoO:pqrRsv", + while ((c = getopt_long(argc, argv, "cdghiMoO:pqrRsSv", long_opts, NULL)) != -1) { switch (c) { case 'O': @@ -890,19 +986,49 @@ static int lfs_getstripe(int argc, char **argv) param.verbose = VERBOSE_ALL | VERBOSE_DETAIL; break; case 'c': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --count option" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + if (strcmp(argv[optind - 1], "--count") == 0) + fprintf(stderr, "warning: '--count' deprecated," + " use '--stripe-count' instead\n"); +#endif if (!(param.verbose & VERBOSE_DETAIL)) { param.verbose |= VERBOSE_COUNT; param.maxdepth = 0; } break; case 's': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --size option" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + fprintf(stderr, "warning: '--size|-s' deprecated, " + "use '--stripe-size|-S' instead\n"); +#endif + case 'S': if (!(param.verbose & VERBOSE_DETAIL)) { param.verbose |= VERBOSE_SIZE; param.maxdepth = 0; } break; - case 'i': case 'o': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0) + fprintf(stderr, "warning: '--offset|-o' deprecated, " + "use '--stripe-index|-i' instead\n"); +#else + if (strcmp(argv[optind - 1], "--offset") == 0) + /* need --stripe-index established first */ + fprintf(stderr, "warning: '--offset' deprecated" + ", use '--index' instead\n"); +#endif + case 'i': +#if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0) +#warning "remove deprecated --offset and --index options" +#elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0) + if (strcmp(argv[optind - 1], "--index") == 0) + fprintf(stderr, "warning: '--index' deprecated" + ", use '--stripe-index' instead\n"); +#endif if (!(param.verbose & VERBOSE_DETAIL)) { param.verbose |= VERBOSE_OFFSET; param.maxdepth = 0; @@ -923,16 +1049,12 @@ static int lfs_getstripe(int argc, char **argv) case 'M': if (!(param.verbose & VERBOSE_DETAIL)) param.maxdepth = 0; - param.get_mdt_index = 1; + param.verbose |= VERBOSE_MDTINDEX; break; case 'R': param.raw = 1; break; - case '?': - return CMD_HELP; default: - fprintf(stderr, "error: %s: option '%s' unrecognized\n", - argv[0], argv[optind - 1]); return CMD_HELP; } } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 0584319..b07281c 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1624,12 +1624,21 @@ retry_get_uuids: } for (obdnum = 0; obdnum < num_obds; obdnum++) { - for (i = 0; i < obdcount; i++) { - if (llapi_uuid_match(uuids[i].uuid, - obduuids[obdnum].uuid)) { - indexes[obdnum] = i; - obd_valid++; - break; + char *end = NULL; + + /* The user may have specified a simple index */ + i = strtol(obduuids[obdnum].uuid, &end, 0); + if (end && *end == '\0' && i < obdcount) { + indexes[obdnum] = i; + obd_valid++; + } else { + for (i = 0; i < obdcount; i++) { + if (llapi_uuid_match(uuids[i].uuid, + obduuids[obdnum].uuid)) { + indexes[obdnum] = i; + obd_valid++; + break; + } } } if (i >= obdcount) { @@ -2351,7 +2360,8 @@ static int cb_find_init(char *path, DIR *parent, DIR *dir, * to be compared. */ if (param->obduuid || param->mdtuuid || param->check_uid || param->check_gid || param->check_pool || param->atime || - param->ctime || param->mtime || param->check_size) + param->ctime || param->mtime || param->check_size || + param->check_stripecount || param->check_stripesize) decision = 0; if (param->type && checked_type == 0) @@ -2438,6 +2448,26 @@ static int cb_find_init(char *path, DIR *parent, DIR *dir, } } + if (param->check_stripesize) { + decision = find_value_cmp(param->lmd->lmd_lmm.lmm_stripe_size, + param->stripesize, + param->stripesize_sign, + param->exclude_stripesize, + param->stripesize_units, 0); + if (decision == -1) + goto decided; + } + + if (param->check_stripecount) { + decision = find_value_cmp(param->lmd->lmd_lmm.lmm_stripe_count, + param->stripecount, + param->stripecount_sign, + param->exclude_stripecount, 1, 0); + if (decision == -1) + goto decided; + } + + /* If an OBD UUID is specified but none matches, skip this file. */ if ((param->obduuid && param->obdindex == OBD_NOT_FOUND) || (param->mdtuuid && param->mdtindex == OBD_NOT_FOUND)) goto decided; @@ -2656,7 +2686,7 @@ static int cb_get_mdt_index(char *path, DIR *parent, DIR *d, void *data, if (param->quiet || !(param->verbose & VERBOSE_DETAIL)) llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx); else - llapi_printf(LLAPI_MSG_NORMAL, "%s MDT index: %d\n", + llapi_printf(LLAPI_MSG_NORMAL, "%s\nmdt_index:\t%d\n", path, mdtidx); out: @@ -2740,7 +2770,7 @@ static int cb_getstripe(char *path, DIR *parent, DIR *d, void *data, } dump: - if (!param->get_mdt_index) + if (!(param->verbose & VERBOSE_MDTINDEX)) llapi_lov_dump_user_lmm(param, path, d ? 1 : 0); out: @@ -2754,7 +2784,7 @@ out: int llapi_getstripe(char *path, struct find_param *param) { - return param_callback(path, param->get_mdt_index ? + return param_callback(path, (param->verbose & VERBOSE_MDTINDEX) ? cb_get_mdt_index : cb_getstripe, cb_common_fini, param); }