Whamcloud - gitweb
LU-13703 utils: fix lfs_migrate with PFL arguments
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 17 Jun 2020 10:14:39 +0000 (04:14 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 14 Feb 2023 19:11:19 +0000 (19:11 +0000)
Pass the '-c', '-S', and '--pool' options to "lfs migrate" when
they are part of a PFL component (after -E), rather than using
them to set the stripe_count and stripe_size of the whole file.

This precludes using '-A' and '-R' with explicitly specified PFL
file layouts, but that didn't make sense in the first place.

Fix the handling of "--pool <pool>" to use "-p <pool>" since
the script later only strips "-p " from the pool name.

Lustre-change: https://review.whamcloud.com/39145
Lustre-commit: 28597c233c980f53732ab7628c2ec38efbff5364

Test-Parameters: trivial
Fixes: 60c5bc25025 ("LU-8235 scripts: pass unrecognized options to lfs migrate")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ib7fb6e08d81dbae77e8348fc5f09837c612540e5
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/49868
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/scripts/lfs_migrate
lustre/tests/sanity.sh

index d04dccb..b958e55 100755 (executable)
@@ -83,7 +83,8 @@ usage: lfs_migrate [--dry-run|-n] [--help|-h] [--no-rsync|--rsync|--cp]
        -y         answer 'y' to usage question (only when --rsync/--cp used)
        -0         input file names on stdin are separated by a null character
 
-Options '-A', '-c', and '-R' are mutually exclusive.
+Options '-A', and '-R' are mutually exclusive with each other, and any
+specific layout (e.g. any specific parameters like '-c', '-S', '-E', '-p').
 Options '-C', '-M', and '-X' are ignored if '-A' is not set.
 Options --rsync, --cp, --no-rsync may not be used at the same time.
 
@@ -96,7 +97,7 @@ through to the 'lfs migrate' utility.
 If emptying an active OST, new files may continue to be allocated there.
 To prevent this, on each MDS run the following for each OST being emptied:
 
-    lctl set_param osp.<fsname>-OSTNNNN*.max_create_count=0'
+    lctl set_param osp.<fsname>-OSTxxxx*.max_create_count=0
 
 Examples:
       lfs_migrate /mnt/lustre/dir
@@ -151,43 +152,48 @@ while [ -n "$*" ]; do
                # these options have files as arguments, pass both through
                OPT_LAYOUT+="$arg $2 "; shift;;
        --dry-run) OPT_DRYRUN=true; OPT_YES=true;;
-       -c|--stripe-count) OPT_STRIPE_COUNT="$2"; shift;;
+       -c|--stripe-count) # if within a component, pass through stripe_count
+               $OPT_COMP && OPT_LAYOUT+="$arg $2 " || OPT_STRIPE_COUNT="$2"
+               shift;;
        -C) OPT_CAP="$2"; shift;;
+       -D) LFS_OPT_DIRECTIO="-D";;
+       -E|--comp-end|--component-end) OPT_COMP=true; OPT_LAYOUT+="$arg ";;
        -h|--help) usage;;
        -l|--link) ;; # maintained backward compatibility for now
        -M|--min-free) OPT_MINFREE="$2"; shift;;
        -n) OPT_DRYRUN=true; OPT_YES=true
                echo "$PROG: -n deprecated, use --dry-run or --non-block" 1>&2;;
-       -p|--pool) OPT_POOL="$arg $2"; OPT_LAYOUT+="$OPT_POOL "; shift;;
+       -p|--pool) # if within a component, pass through pool
+               $OPT_COMP && OPT_LAYOUT+="$arg $2 " || OPT_POOL="-p $2";
+               shift;;
        -q|--quiet) ECHO=:;;
        -R|--restripe) OPT_RESTRIPE=true;;
        --no-rsync) OPT_NO_RSYNC=true; OPT_RSYNC=false;;
        --rsync) [[ "$RSYNC" != "rsync" ]] && OPT_NO_RSYNC=true || OPT_NO_RSYNC=false
                OPT_RSYNC=true;;
        -s|--skip) OPT_CHECK=false;;
-       -S|--stripe-size) OPT_STRIPE_SIZE="$2"; shift;;
+       -S|--stripe-size) # if within a component, pass through stripe_size
+               $OPT_COMP && OPT_LAYOUT+="$arg $2 " || OPT_STRIPE_SIZE="$2"
+               shift;;
        -v|--verbose) OPT_DEBUG=true; ECHO=echo;;
        -X|--max-free) OPT_MAXFREE="$2"; shift;;
        -y|--yes) OPT_YES=true;;
        -0) OPT_NULL=true;;
        *) # Pass other non-file layout options to 'lfs migrate'
-          [ -e "$arg" ] && OPT_FILE+="$arg " && break || OPT_LAYOUT+="$arg "
+          [[ -e "$arg" ]] && OPT_FILE+="$arg " && break || OPT_LAYOUT+="$arg "
        esac
        shift
 done
 
-if $OPT_RESTRIPE || $OPT_AUTOSTRIPE && [ -n "$OPT_LAYOUT" ]; then
-       echo "$PROG error: Options '$OPT_LAYOUT' can't be used with -R or -A" \
-               1>&2
+if ( $OPT_RESTRIPE || $OPT_AUTOSTRIPE ) &&
+   [[ -n "$OPT_STRIPE_COUNT" || -n "$OPT_STRIPE_SIZE" || -n "$OPT_POOL" ]]; then
+       echo "$PROG error: option -R or -A cannot be used with -c, -S, or -p" 1>&2
        exit 1
-elif $OPT_RESTRIPE && [[ "$OPT_STRIPE_COUNT" || "$OPT_STRIPE_SIZE" ]]; then
-       echo "$PROG error: Option -R can't be used with -c or -S" 1>&2
+elif ( $OPT_RESTRIPE || $OPT_AUTOSTRIPE ) && [[ -n "$OPT_LAYOUT" ]]; then
+       echo "$PROG error: option -R or -A cannot be used with $OPT_LAYOUT" 1>&2
        exit 1
-elif $OPT_AUTOSTRIPE && [ -n "$OPT_STRIPE_COUNT" ]; then
-       echo "$PROG error: Option -A can't be used with -c" 1>&2
-       exit 1
-elif $OPT_AUTOSTRIPE && $OPT_RESTRIPE; then
-       echo "$PROG error: Option -A can't be used with -R" 1>&2
+elif $OPT_RESTRIPE && $OPT_AUTOSTRIPE; then
+       echo "$PROG error: option -R cannot be used with -A" 1>&2
        exit 1
 fi
 
@@ -370,33 +376,35 @@ lfs_migrate() {
                local olddir=$(dirname "$OLDNAME")
                local stripe_size="$OPT_STRIPE_SIZE"
                local stripe_count="$OPT_STRIPE_COUNT"
-               local stripe_opts="-N --comp-count -c -S -p -y"
+               local getstripe_opts="-N --comp-count -c -S -p -y"
                local parent_count=""
                local parent_size=""
                local stripe_pool="${OPT_POOL#-p }"
                local mirror_count=1
                local comp_count=0
-               # avoid multiple getstripe calls
-               #   lcm_mirror_count:  1
-               #   lcm_entry_count:   0
-               #      lmm_stripe_count:  1
-               #      lmm_stripe_size:   1048576
-               #      lmm_pool:          pool_abc
-               local l_mirror_count=0
-               local l_comp_count=1
-               local l_stripe_count=2
-               local l_stripe_size=3
-               local l_stripe_pool=4
-               local layout_info=($($LFS getstripe $stripe_opts "$OLDNAME" \
-                       2>/dev/null | awk '{ print $2 }'))
 
                layout="${OPT_PASSTHROUGH[@]} "
 
                if $OPT_RESTRIPE; then
                        UNLINK=""
                        layout+="--copy $olddir"
-                       OPT_COMP=true
-               else
+                       OPT_COPY=true
+               elif ! $OPT_COMP; then
+                       # avoid multiple getstripe calls
+                       #   lcm_mirror_count:  1
+                       #   lcm_entry_count:   0
+                       #      lmm_stripe_count:  1
+                       #      lmm_stripe_size:   1048576
+                       #      lmm_pool:          pool_abc
+                       local l_mirror_count=0
+                       local l_comp_count=1
+                       local l_stripe_count=2
+                       local l_stripe_size=3
+                       local l_stripe_pool=4
+                       local layout_info
+
+                       layout_info=($($LFS getstripe $getstripe_opts $OLDNAME \
+                                      2>/dev/null | awk '{ print $2 }'))
                        # If rsync copies Lustre xattrs properly in the future
                        # (i.e. before the file data, so that it preserves
                        # striping) then we don't need this getstripe stuff.
@@ -430,7 +438,7 @@ lfs_migrate() {
                        local parent_layout
 
                        if $OPT_RESTRIPE; then
-                               parent_layout=($($LFS getstripe $stripe_opts \
+                               parent_layout=($($LFS getstripe $getstripe_opts\
                                                -d "$olddir" 2>/dev/null |
                                                awk '{print $2 }'))
                                parent_count=${parent_layout[$l_stripe_count]}
index ba1803a..fbaa7fc 100755 (executable)
@@ -6835,8 +6835,8 @@ test_56v() {
 }
 run_test 56v "check 'lfs find -m match with lfs getstripe -m'"
 
-test_56w() {
-       [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
+test_56wa() {
+       (( $OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
        local dir=$DIR/$tdir
@@ -6852,7 +6852,7 @@ test_56w() {
        local required_space=$((file_num * file_size))
        local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
                           head -n1)
-       [[ $free_space -le $((required_space / 1024)) ]] &&
+       (( free_space >= required_space / 1024 )) ||
                skip_env "need $required_space, have $free_space kbytes"
 
        local dd_bs=65536
@@ -6863,13 +6863,13 @@ test_56w() {
        local j
        local file
 
-       for i in $(seq $NUMFILES); do
+       for ((i = 1; i <= NUMFILES; i++ )); do
                file=$dir/file$i
                yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
                        error "write data into $file failed"
        done
-       for i in $(seq $NUMDIRS); do
-               for j in $(seq $NUMFILES); do
+       for ((i = 1; i <= NUMDIRS; i++ )); do
+               for ((j = 1; j <= NUMFILES; j++ )); do
                        file=$dir/dir$i/file$j
                        yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
                                error "write data into $file failed"
@@ -6877,14 +6877,14 @@ test_56w() {
        done
 
        # $LFS_MIGRATE will fail if hard link migration is unsupported
-       if [[ $MDS1_VERSION -gt $(version_code 2.5.55) ]]; then
+       if (( MDS1_VERSION > $(version_code 2.5.55) )); then
                createmany -l$dir/dir1/file1 $dir/dir1/link 200 ||
                        error "creating links to $dir/dir1/file1 failed"
        fi
 
        local expected=-1
 
-       [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
+       (( OSTCOUNT <= 1 )) || expected=$((OSTCOUNT - 1))
 
        # lfs_migrate file
        local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
@@ -6894,8 +6894,7 @@ test_56w() {
 
        check_stripe_count $dir/file1 $expected
 
-       if [ $MDS1_VERSION -ge $(version_code 2.6.90) ];
-       then
+       if (( $MDS1_VERSION >= $(version_code 2.6.90) )); then
                # lfs_migrate file onto OST 0 if it is on OST 1, or onto
                # OST 1 if it is on OST 0. This file is small enough to
                # be on only one stripe.
@@ -6906,7 +6905,7 @@ test_56w() {
                local oldmd5=$(md5sum $file)
                local newobdidx=0
 
-               [[ $obdidx -eq 0 ]] && newobdidx=1
+               (( obdidx != 0 )) || newobdidx=1
                cmd="$LFS migrate -i $newobdidx $file"
                echo $cmd
                eval $cmd || error "$cmd failed"
@@ -6914,10 +6913,9 @@ test_56w() {
                local realobdix=$($LFS getstripe -i $file)
                local newmd5=$(md5sum $file)
 
-               [[ $newobdidx -ne $realobdix ]] &&
-                       error "new OST is different (was=$obdidx, "\
-                             "wanted=$newobdidx, got=$realobdix)"
-               [[ "$oldmd5" != "$newmd5" ]] &&
+               (( $newobdidx == $realobdix )) ||
+                       error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
+               [[ "$oldmd5" == "$newmd5" ]] ||
                        error "md5sum differ: $oldmd5, $newmd5"
        fi
 
@@ -6926,7 +6924,7 @@ test_56w() {
        echo "$cmd"
        eval $cmd || error "$cmd failed"
 
-       for j in $(seq $NUMFILES); do
+       for (( j = 1; j <= NUMFILES; j++ )); do
                check_stripe_count $dir/dir1/file$j $expected
        done
 
@@ -6936,16 +6934,16 @@ test_56w() {
        echo "$cmd"
        eval $cmd || error "$cmd failed"
 
-       for i in $(seq 2 $NUMFILES); do
+       for (( i = 2; i <= NUMFILES; i++ )); do
                check_stripe_count $dir/file$i $expected
        done
-       for i in $(seq 2 $NUMDIRS); do
-               for j in $(seq $NUMFILES); do
-               check_stripe_count $dir/dir$i/file$j $expected
+       for (( i = 2; i <= NUMDIRS; i++ )); do
+               for (( j = 1; j <= NUMFILES; j++ )); do
+                       check_stripe_count $dir/dir$i/file$j $expected
                done
        done
 }
-run_test 56w "check lfs_migrate -c stripe_count works"
+run_test 56wa "check lfs_migrate -c stripe_count works"
 
 test_56wb() {
        local file1=$DIR/$tdir/file1
@@ -7027,12 +7025,15 @@ test_56wb() {
 run_test 56wb "check lfs_migrate pool support"
 
 test_56wc() {
-       local file1="$DIR/$tdir/file1"
+       local file1="$DIR/$tdir/$tfile"
+       local md5
        local parent_ssize
        local parent_scount
        local cur_ssize
        local cur_scount
        local orig_ssize
+       local new_scount
+       local cur_comp
 
        echo -n "Creating test dir..."
        test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
@@ -7044,48 +7045,68 @@ test_56wc() {
        $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
                error "cannot set stripe"
        cur_ssize=$($LFS getstripe -S "$file1")
-       [ $cur_ssize -eq 524288 ] || error "setstripe -S $cur_ssize != 524288"
+       (( cur_ssize == 524288 )) || error "setstripe -S $cur_ssize != 524288"
        echo "done."
 
+       dd if=/dev/urandom of=$file1 bs=1M count=12 || error "dd $file1 failed"
+       stack_trap "rm -f $file1"
+       md5="$(md5sum $file1)"
+
        # File currently set to -S 512K -c 1
 
        # Ensure -c and -S options are rejected when -R is set
        echo -n "Verifying incompatible options are detected..."
-       $LFS_MIGRATE -y -R -c 1 "$file1" &> /dev/null &&
-               error "incompatible -c and -R options not detected"
-       $LFS_MIGRATE -y -R -S 1M "$file1" &> /dev/null &&
-               error "incompatible -S and -R options not detected"
+       $LFS_MIGRATE -R -c 1 "$file1" &&
+               error "incompatible -R and -c options not detected"
+       $LFS_MIGRATE -R -S 1M "$file1" &&
+               error "incompatible -R and -S options not detected"
+       $LFS_MIGRATE -R -p pool "$file1" &&
+               error "incompatible -R and -p options not detected"
+       $LFS_MIGRATE -R -E eof -c 1 "$file1" &&
+               error "incompatible -R and -E options not detected"
+       $LFS_MIGRATE -R -A "$file1" &&
+               error "incompatible -R and -A options not detected"
+       $LFS_MIGRATE -A -c 1 "$file1" &&
+               error "incompatible -A and -c options not detected"
+       $LFS_MIGRATE -A -S 1M "$file1" &&
+               error "incompatible -A and -S options not detected"
+       $LFS_MIGRATE -A -p pool "$file1" &&
+               error "incompatible -A and -p options not detected"
+       $LFS_MIGRATE -A -E eof -c 1 "$file1" &&
+               error "incompatible -A and -E options not detected"
        echo "done."
 
        # Ensure unrecognized options are passed through to 'lfs migrate'
        echo -n "Verifying -S option is passed through to lfs migrate..."
-       $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
-               error "migration failed"
+       $LFS_MIGRATE -y -S 1M "$file1" || error "migration failed"
        cur_ssize=$($LFS getstripe -S "$file1")
-       [ $cur_ssize -eq 1048576 ] || error "migrate -S $cur_ssize != 1048576"
+       (( cur_ssize == 1048576 )) || error "migrate -S $cur_ssize != 1048576"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (1)"
        echo "done."
 
        # File currently set to -S 1M -c 1
 
        # Ensure long options are supported
        echo -n "Verifying long options supported..."
-       $LFS_MIGRATE -y --non-block "$file1" &> /dev/null ||
+       $LFS_MIGRATE --non-block "$file1" ||
                error "long option without argument not supported"
-       $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
+       $LFS_MIGRATE --stripe-size 512K "$file1" ||
                error "long option with argument not supported"
        cur_ssize=$($LFS getstripe -S "$file1")
-       [ $cur_ssize -eq 524288 ] ||
+       (( cur_ssize == 524288 )) ||
                error "migrate --stripe-size $cur_ssize != 524288"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (2)"
        echo "done."
 
        # File currently set to -S 512K -c 1
 
-       if [ "$OSTCOUNT" -gt 1 ]; then
+       if (( OSTCOUNT > 1 )); then
                echo -n "Verifying explicit stripe count can be set..."
-               $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
-                       error "migrate failed"
+               $LFS_MIGRATE -c 2 "$file1" || error "migrate failed"
                cur_scount=$($LFS getstripe -c "$file1")
-               [ $cur_scount -eq 2 ] || error "migrate -c $cur_scount != 2"
+               (( cur_scount == 2 )) || error "migrate -c $cur_scount != 2"
+               [[ "$(md5sum $file1)" == "$md5" ]] ||
+                       error "file data has changed (3)"
                echo "done."
        fi
 
@@ -7096,19 +7117,20 @@ test_56wc() {
        echo -n "Setting stripe for parent directory..."
        $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
                error "cannot set stripe '-S 2M -c 1'"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (4)"
        echo "done."
 
        echo -n "Verifying restripe option uses parent stripe settings..."
        parent_ssize=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
        parent_scount=$($LFS getstripe -c $DIR/$tdir 2>/dev/null)
-       $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
-               error "migrate failed"
+       $LFS_MIGRATE -R "$file1" || error "migrate failed"
        cur_ssize=$($LFS getstripe -S "$file1")
-       [ $cur_ssize -eq $parent_ssize ] ||
+       (( cur_ssize == parent_ssize )) ||
                error "migrate -R stripe_size $cur_ssize != $parent_ssize"
        cur_scount=$($LFS getstripe -c "$file1")
-       [ $cur_scount -eq $parent_scount ] ||
+       (( cur_scount == parent_scount )) ||
                error "migrate -R stripe_count $cur_scount != $parent_scount"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (5)"
        echo "done."
 
        # File currently set to -S 1M -c 1
@@ -7119,21 +7141,32 @@ test_56wc() {
        orig_ssize=$($LFS getstripe -S "$file1" 2>/dev/null)
        $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
                error "cannot set stripe on parent directory"
-       $LFS_MIGRATE -y "$file1" &> /dev/null ||
-               error "migrate failed"
+       $LFS_MIGRATE "$file1" || error "migrate failed"
        cur_ssize=$($LFS getstripe -S "$file1")
-       [ $cur_ssize -eq $orig_ssize ] ||
+       (( cur_ssize == orig_ssize )) ||
                error "migrate by default $cur_ssize != $orig_ssize"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (6)"
        echo "done."
 
        # Ensure file name properly detected when final option has no argument
        echo -n "Verifying file name properly detected..."
-       $LFS_MIGRATE -y "$file1" &> /dev/null ||
+       $LFS_MIGRATE "$file1" ||
                error "file name interpreted as option argument"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (7)"
        echo "done."
 
-       # Clean up
-       rm -f "$file1"
+       # Ensure PFL arguments are passed through properly
+       echo -n "Verifying PFL options passed through..."
+       new_scount=$(((OSTCOUNT + 1) / 2))
+       $LFS_MIGRATE -E 1M -c 1 -E 16M -c $new_scount -E eof -c -1 "$file1" ||
+               error "migrate PFL arguments failed"
+       cur_comp=$($LFS getstripe --comp-count $file1)
+       (( cur_comp == 3 )) || error "component count '$cur_comp' != 3"
+       cur_scount=$($LFS getstripe --stripe-count $file1)
+       (( cur_scount == new_scount)) ||
+               error "PFL stripe count $cur_scount != $new_scount"
+       [[ "$(md5sum $file1)" == "$md5" ]] || error "file data has changed (8)"
+       echo "done."
 }
 run_test 56wc "check unrecognized options for lfs_migrate are passed through"