From 156883002a78d23645fa01931ae5e39a570fefbf Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Fri, 28 Apr 2017 14:18:47 +0800 Subject: [PATCH] LU-9324 lfs: add setstripe --copy=lustre_file_or_dir parameter Add a "lfs setstripe --copy= " usage to set stripe using stripe info from a source lustre file/dir. Signed-off-by: Bobi Jam Change-Id: Ibcd80f98c53bdff5b41ba9b1010fceefd6c9d8b7 Reviewed-on: https://review.whamcloud.com/26879 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Lai Siyao --- lustre/tests/sanity-flr.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++ lustre/tests/sanity-pfl.sh | 3 ++ lustre/utils/lfs.c | 36 +++++++++++++++++++--- 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index bdcb3bf..8e69a4e 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -32,6 +32,9 @@ assert_DIR build_test_filter +assert_DIR +rm -rf $DIR/[Rdfs][0-9]* + # global array to store mirror IDs declare -a mirror_array get_mirror_ids() { @@ -1788,6 +1791,78 @@ test_45() { } run_test 45 "Verify setstripe/getstripe with YAML with FLR file" +verify_46() { + local src=$1 + local dst=$2 + local msg_prefix=$3 + + $LFS setstripe --copy=$src $dst || error "setstripe $dst failed" + + local layout1=$(get_layout_param $src) + local layout2=$(get_layout_param $dst) + # compare their layout info + [ "$layout1" == "$layout2" ] || + error "$msg_prefix $src <=> $dst layouts are not equal" +} + +test_46() { + [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return + + local file=$DIR/$tdir/$tfile + test_mkdir $DIR/$tdir + + ########################### 1. PFL file ############################# + echo " ** 1. PFL file" + rm -f $file + $LFS setstripe -E1m -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 $file || + error "1. Create PFL $file failed" + + rm -f $file.copy + verify_46 $file $file.copy "1. PFL file" + + ########################### 2. plain file ########################### + echo " ** 2. plain file" + rm -f $file + $LFS setstripe -c2 -o0,1 -i1 $file || + error "2. Create plain $file failed" + + rm -f $file.copy + verify_46 $file $file.copy "2. plain file" + + ########################### 3. FLR file ############################# + echo " ** 3. FLR file" + rm -f $file + $LFS setstripe -N -E1m -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof $file || + error "3. Create FLR $file failed" + + rm -f $file.copy + verify_46 $file $file.copy "3. FLR file" + + local dir=$DIR/$tdir/dir + ########################### 4. PFL dir ############################## + echo " ** 4. PFL dir" + test_mkdir $dir + $LFS setstripe -E1m -c2 -E2m -c1 -E-1 $dir || + error "4. setstripe PFL $dir failed" + + test_mkdir $dir.copy + verify_46 $dir $dir.copy "3. PFL dir" + + ########################### 5. plain dir ############################ + echo " ** 5. plain dir" + $LFS setstripe -c2 -i-1 $dir || error "4. setstripe plain $dir failed" + + verify_46 $dir $dir.copy "5. plain dir" + + ########################### 6. FLR dir ############################## + echo " ** 6. FLR dir" + $LFS setstripe -N -E1m -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir || + error "6. setstripe FLR $dir failed" + + verify_46 $dir $dir.copy "6. FLR dir" +} +run_test 46 "Verify setstripe --copy option" + ctrl_file=$(mktemp /tmp/CTRL.XXXXXX) lock_file=$(mktemp /var/lock/FLR.XXXXXX) diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index ca63b90..98c148a 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -36,6 +36,9 @@ build_test_filter error "\$RUNAS_ID set to 0, but \$UID is also 0!" check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS +assert_DIR +rm -rf $DIR/[Rdfs][0-9]* + test_0() { [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index d0ba643..3242c5b 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -159,10 +159,11 @@ static inline int lfs_mirror_split(int argc, char **argv) " [--stripe-count|-c ]\n" \ " [--stripe-index|-i ]\n" \ " [--stripe-size|-S ]\n" \ - " [--layout|-L ]\n" \ + " [--layout|-L ]\n" \ " [--pool|-p ]\n" \ " [--ost|-o ]\n" \ - " [--yaml|-y ]\n" + " [--yaml|-y ]\n" \ + " [--copy=]\n" #define SSM_HELP_COMMON \ "\tstripe_count: Number of OSTs to stripe over (0=fs default, -1 all)\n" \ @@ -185,7 +186,10 @@ static inline int lfs_mirror_split(int argc, char **argv) "\t stripe_size.\n" \ "\tyaml_template_file:\n" \ "\t YAML layout template file, can't be used with -c,\n" \ - "\t -i, -S, -p, -o, or -E arguments.\n" + "\t -i, -S, -p, -o, or -E arguments.\n" \ + "\tlustre_src: Lustre file/dir whose layout info is used to set\n" \ + "\t another lustre file or directory, can't used with\n" \ + "\t -c, -i, -S, -p, -o, or -E arguments.\n" #define MIRROR_CREATE_HELP \ "\tmirror_count: Number of mirrors to be created with the upcoming\n" \ @@ -2459,6 +2463,7 @@ enum { LFS_MIRROR_FLAGS_OPT, LFS_MIRROR_ID_OPT, LFS_MIRROR_STATE_OPT, + LFS_LAYOUT_COPY, }; /* functions */ @@ -2498,6 +2503,7 @@ static int lfs_setstripe_internal(int argc, char **argv, __u16 mirror_id = 0; char cmd[PATH_MAX]; bool from_yaml = false; + bool from_copy = false; char *template = NULL; struct option long_opts[] = { @@ -2528,6 +2534,8 @@ static int lfs_setstripe_internal(int argc, char **argv, .name = "flags", .has_arg = required_argument}, { .val = LFS_MIRROR_ID_OPT, .name = "mirror-id", .has_arg = required_argument}, + { .val = LFS_LAYOUT_COPY, + .name = "copy", .has_arg = required_argument}, { .val = 'c', .name = "stripe-count", .has_arg = required_argument}, { .val = 'c', .name = "stripe_count", .has_arg = required_argument}, /* find { .val = 'C', .name = "ctime", .has_arg = required_argument }*/ @@ -2657,6 +2665,10 @@ static int lfs_setstripe_internal(int argc, char **argv, } break; } + case LFS_LAYOUT_COPY: + from_copy = true; + template = optarg; + break; case 'b': if (!migrate_mode) { fprintf(stderr, @@ -3033,7 +3045,15 @@ static int lfs_setstripe_internal(int argc, char **argv, goto error; } - if (from_yaml && (setstripe_args_specified(&lsa) || layout != NULL)) { + if (from_yaml && from_copy) { + fprintf(stderr, + "%s: can't specify --yaml and --copy together\n", + progname); + goto error; + } + + if ((from_yaml || from_copy) && + (setstripe_args_specified(&lsa) || layout != NULL)) { fprintf(stderr, "error: %s: can't specify --yaml with " "-c, -S, -i, -o, -p or -E options.\n", argv[0]); @@ -3126,6 +3146,14 @@ static int lfs_setstripe_internal(int argc, char **argv, argv[0], template); goto error; } + } else if (from_copy) { + layout = llapi_layout_get_by_path(template, 0); + if (layout == NULL) { + fprintf(stderr, + "%s: can't create composite layout from file %s.\n", + progname, template); + goto error; + } } for (fname = argv[optind]; fname != NULL; fname = argv[++optind]) { -- 1.8.3.1