From 5c61e053874caafe75f84c149de933050e9ec660 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Fri, 19 Dec 2014 17:03:34 -0700 Subject: [PATCH] LU-2430 utils: fix "lfs mv" command parsing Fix the lfs_mv() long option parsing so that it uses "--mdt-index" instead of incorrectly requiring "----mdt-index" for the short "-M" option. Fix up some error messages in lfs_mv() as well, and change a test case to use the long option form. Signed-off-by: Andreas Dilger Change-Id: I20ffde97fb5d31364e91d6b21d407eb3323ebbe5 Reviewed-on: http://review.whamcloud.com/13161 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Nathaniel Clark Reviewed-by: wangdi Reviewed-by: Oleg Drokin --- lustre/tests/sanity.sh | 26 +++++++++++++------------- lustre/utils/lfs.c | 11 ++++++----- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index b22ccfe..c17769d 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -664,7 +664,7 @@ test_17n() { check_fs_consistency_17n || error "e2fsck report error after create files under remote dir" - for ((i=0;i<10;i++)); do + for ((i = 0; i < 10; i++)); do rm -rf $DIR/$tdir/remote_dir_${i} || error "destroy remote dir error $i" done @@ -675,16 +675,16 @@ test_17n() { [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] && skip "lustre < 2.4.50 does not support migrate mv " && return - for ((i=0; i<10; i++)); do + for ((i = 0; i < 10; i++)); do mkdir -p $DIR/$tdir/remote_dir_${i} createmany -o $DIR/$tdir/remote_dir_${i}/f 10 || error "create files under remote dir failed $i" - $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} || + $LFS mv --mdt-index 1 $DIR/$tdir/remote_dir_${i} || error "migrate remote dir error $i" done check_fs_consistency_17n || error "e2fsck report error after migration" - for ((i=0;i<10;i++)); do + for ((i = 0; i < 10; i++)); do rm -rf $DIR/$tdir/remote_dir_${i} || error "destroy remote dir error $i" done @@ -12439,10 +12439,10 @@ test_230b() { ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other $LFS mv -v -M $MDTIDX $migrate_dir || - error "migrate remote dir error" + error "migrate remote dir error" echo "migratate to MDT1, then checking.." - for ((i=0; i<10; i++)); do + for ((i = 0; i < 10; i++)); do for file in $(find $migrate_dir/dir_${i}); do mdt_index=$($LFS getstripe -M $file) [ $mdt_index == $MDTIDX ] || @@ -12494,16 +12494,16 @@ test_230b() { stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2) [ $stripe_count = 2 ] || - error "dir strpe_count $d != 2 after migration." + error "dir strpe_count $d != 2 after migration." stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2) [ $stripe_count = 2 ] || - error "file strpe_count $d != 2 after migration." + error "file strpe_count $d != 2 after migration." #migrate back to MDT0 MDTIDX=0 $LFS mv -v -M $MDTIDX $migrate_dir || - error "migrate remote dir error" + error "migrate remote dir error" echo "migrate back to MDT0, checking.." for file in $(find $migrate_dir); do @@ -12576,10 +12576,10 @@ test_230c() { #OBD_FAIL_MIGRATE_ENTRIES 0x1801 do_facet mds1 lctl set_param fail_loc=0x20001801 do_facet mds1 lctl set_param fail_val=5 - local t=`ls $DIR/$tdir | wc -l` - $LFS mv -M $MDTIDX $DIR/$tdir && - error "migrate should failed after 5 entries" - local u=`ls $DIR/$tdir | wc -l` + local t=$(ls $DIR/$tdir | wc -l) + $LFS mv --mdt-index $MDTIDX $DIR/$tdir && + error "migrate should fail after 5 entries" + local u=$(ls $DIR/$tdir | wc -l) [ "$u" == "$t" ] || error "$u != $t during migration" for file in $(find $DIR/$tdir); do diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4ab76a3..539c591 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1787,7 +1787,7 @@ static int lfs_mv(int argc, char **argv) int c; int rc = 0; struct option long_opts[] = { - {"--mdt-index", required_argument, 0, 'M'}, + {"mdt-index", required_argument, 0, 'M'}, {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; @@ -1815,20 +1815,21 @@ static int lfs_mv(int argc, char **argv) } if (param.fp_mdt_index == -1) { - fprintf(stderr, "%s MDT index must be indicated\n", argv[0]); + fprintf(stderr, "%s: MDT index must be specified\n", argv[0]); return CMD_HELP; } if (optind >= argc) { - fprintf(stderr, "%s missing operand path\n", argv[0]); + fprintf(stderr, "%s: missing operand path\n", argv[0]); return CMD_HELP; } param.fp_migrate = 1; rc = llapi_mv(argv[optind], ¶m); if (rc != 0) - fprintf(stderr, "cannot migrate '%s' to MDT%04x: %s\n", - argv[optind], param.fp_mdt_index, strerror(-rc)); + fprintf(stderr, "%s: cannot migrate '%s' to MDT%04x: %s\n", + argv[0], argv[optind], param.fp_mdt_index, + strerror(-rc)); return rc; } -- 1.8.3.1