Whamcloud - gitweb
LU-18579 utils: lfs_migrate should inherit OST pool 19/57519/11
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 19 Dec 2024 01:58:18 +0000 (18:58 -0700)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Feb 2025 01:29:08 +0000 (01:29 +0000)
Fix the lfs_migrate script so that it inherits the OST pool name
from the source file, if it was specified.

Fix the parsing of the existing file layout so that it can properly
handle various YAML formats.

Test-Parameters: trivial
Fixes: 109b5499d3 ("LU-15565 utils: updated lfs getstripe yaml format")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: If06d3a682e3807e3856f1f5d2cbbecf31c7fa361
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57519
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Sergey Cheremencev <scherementsev@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/scripts/lfs_migrate
lustre/tests/ost-pools.sh
lustre/tests/sanity.sh

index dbc5ad2..b3d3693 100755 (executable)
@@ -398,23 +398,35 @@ lfs_migrate() {
                        #      lmm_stripe_count:  1
                        #      lmm_stripe_size:   1048576
                        #      lmm_pool:          pool_abc
-                       local l_mirror_count
-                       local l_comp_count
-                       local l_stripe_count
-                       local l_stripe_size
-                       local l_stripe_pool
-                       local layout_info
-
-                       layout_info=($($LFS getstripe $getstripe_opts $OLDNAME \
-                                      2>/dev/null | awk '{ print }'))
-
-                       for ((i = 0; i < ${#layout_info[*]}; i++)); do
-                               case "${layout_info[$i]}" in
-                               *mirror_count*) l_mirror_count=$((i + 1));;
-                               *entry_count*) l_comp_count=$((i + 1));;
-                               *stripe_count*) l_stripe_count=$((i + 1));;
-                               *stripe_size*) l_stripe_size=$((i + 1));;
-                               *stripe_pool*) l_stripe_pool=$((i + 1));;
+                       local old_stripe_count
+                       local old_stripe_size
+                       local old_layout
+
+                       old_layout=($($LFS getstripe $getstripe_opts $OLDNAME \
+                                     2>/dev/null | awk '{ print }'))
+
+                       for ((i = 0; i < ${#old_layout[*]}; i++)); do
+                               local info_this=${old_layout[$i]}
+                               local info_next=${old_layout[$i+1]}
+                               local idx=$((i + 1))
+
+                               $OPT_DEBUG && echo "$i: $info_this"
+                               case "${old_layout[$i]}" in
+                               *mirror_count:)
+                                       mirror_count=${old_layout[$idx]}
+                                       $OPT_DEBUG && echo "mirror=$info_next";;
+                               *entry_count:)
+                                       comp_count=${old_layout[$idx]}
+                                       $OPT_DEBUG && echo "comp=$info_next";;
+                               *stripe_count:)
+                                       old_stripe_count=${old_layout[$idx]}
+                                       $OPT_DEBUG && echo "count=$info_next";;
+                               *stripe_size:)
+                                       old_stripe_size=${old_layout[$idx]}
+                                       $OPT_DEBUG && echo "size=$info_next";;
+                               *lmm_pool:)
+                                       stripe_pool=${stripe_pool:-${old_layout[$idx]}}
+                                       $OPT_DEBUG && echo "pool=$info_next";;
                                esac
                        done
 
@@ -423,26 +435,20 @@ lfs_migrate() {
                        # striping) then we don't need this getstripe stuff.
                        UNLINK="-u"
 
-                       [ -n "$OPT_POOL" ] ||
-                               stripe_pool=${layout_info[$l_stripe_pool]}
-                       mirror_count=${layout_info[$l_mirror_count]}
-
                        if $OPT_AUTOSTRIPE; then
                                local filekb=$((${nlink_type[$nlink_idx_size]} /
                                                1024))
 
                                read stripe_count OBJ_MAX_KB < <(calc_stripe \
                                        "$OLDNAME" "$filekb" "$OBJ_MAX_KB")
-                               [ -z "$stripe_count" ] && exit 1
-                               [ $stripe_count -lt 1 ] && stripe_count=1
+                               [[ -n "$stripe_count" ]] || exit 1
+                               (( $stripe_count >= 1 )) || stripe_count=1
                        else
-                               [ -n "$stripe_count" ] ||
-                                       stripe_count=${layout_info[$l_stripe_count]}
+                               stripe_count=${stripe_count:-$old_stripe_count}
                        fi
-                       [ -n "$stripe_size" ] ||
-                               stripe_size=${layout_info[$l_stripe_size]}
+                       stripe_size=${stripe_size:-$old_stripe_size}
 
-                       [ -z "$stripe_count" -o -z "$stripe_size" ] && UNLINK=""
+                       [[ -n "$stripe_count" && -n "$stripe_size" ]] || UNLINK=
                fi
 
                if $OPT_DEBUG; then
@@ -452,18 +458,28 @@ lfs_migrate() {
 
                        if $OPT_RESTRIPE; then
                                parent_layout=($($LFS getstripe $getstripe_opts\
-                                               -d "$olddir" 2>/dev/null |
-                                               awk '{print $2 }'))
-                               parent_count=${parent_layout[$l_stripe_count]}
-                               parent_size=${parent_layout[$l_stripe_size]}
-                               stripe_pool=${parent_layout[$l_stripe_pool]}
-                               mirror_count=${parent_layout[$l_mirror_count]}
+                                                -d "$olddir" 2>/dev/null |
+                                                awk '{ print }'))
+                               for ((i = 0; i < ${#parent_layout[*]}; i++)); do
+                                       local idx=$((i + 1))
+
+                                       case "${parent_layout[$i]}" in
+                                       *stripe_count:)
+                                          parent_count=${parent_layout[$idx]};;
+                                       *stripe_size:)
+                                          parent_size=${parent_layout[$idx]};;
+                                       *pool:)
+                                          stripe_pool=${parent_layout[$idx]};;
+                                       *mirror_count:)
+                                          mirror_count=${parent_layout[$idx]};;
+                                       esac
+                               done
                        fi
 
                        $ECHO -n "stripe_count=${stripe_count:-$parent_count},stripe_size=${stripe_size:-$parent_size}"
-                       [ -n "$stripe_pool" ] &&
+                       [[ -z "$stripe_pool" ]] ||
                                $ECHO -n ",pool=${stripe_pool}"
-                       [[ $mirror_count -gt 1 ]] &&
+                       (( $mirror_count <= 1 )) ||
                                $ECHO -n ",mirror_count=${mirror_count}"
                        $ECHO -n " "
                fi
@@ -474,16 +490,15 @@ lfs_migrate() {
                fi
 
                if ! $OPT_COPY && ! $OPT_COMP && ! $OPT_RSYNC &&
-                  (( ${layout_info[$l_comp_count]} > 0 )); then
+                  (( $comp_count > 0 )); then
                        layout+="--copy $OLDNAME"
                        OPT_COPY=true
                fi
                if ! $OPT_COPY && ! $OPT_COMP; then
-                       [ -n "$stripe_count" ] && layout+="-c $stripe_count "
-                       [ -n "$stripe_size" ] && layout+="-S $stripe_size "
-                       [ -n "$OPT_POOL" -a -n "$stripe_pool" ] &&
-                                               layout+="-p $stripe_pool "
-                       [[ $mirror_count -gt 1 ]] && layout+="-N $mirror_count "
+                       [[ -z "$stripe_count" ]] || layout+="-c $stripe_count "
+                       [[ -z "$stripe_size" ]] || layout+="-S $stripe_size "
+                       [[ -z "$stripe_pool" ]] || layout+="-p $stripe_pool "
+                       (( $mirror_count <= 1 )) || layout+="-N $mirror_count "
                fi
                layout+="$OPT_LAYOUT"
 
index f339500..5522477 100755 (executable)
@@ -1611,6 +1611,14 @@ test_28() {
                error "$tfile is in '$pool', not migrated to $POOL2"
        local csum2=$(cksum $DIR/$tfile)
        [[ "$csum" == "$csum2" ]] || error "checksum error after migration"
+       $LFS_MIGRATE -y -v $DIR/$tfile ||
+               error "migrate $tfile without explicit pool failed"
+       $LFS getstripe $DIR/$tfile
+       pool="$($LFS getstripe -p $DIR/$tfile)"
+       [[ "$pool" == "$POOL2" ]] ||
+               error "$tfile is in '$pool', not left in $POOL2"
+       local csum2=$(cksum $DIR/$tfile)
+       [[ "$csum" == "$csum2" ]] || error "checksum error after pool migration"
        stop_full_debug_logging
 }
 run_test 28 "lfs_migrate with pool name"
index 8b8ec22..6aadbae 100755 (executable)
@@ -7972,7 +7972,7 @@ test_56wa() {
        (( OSTCOUNT <= 1 )) || expected=$((OSTCOUNT - 1))
 
        # lfs_migrate file
-       local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
+       local cmd="$LFS_MIGRATE -y -v -c $expected $dir/file1"
 
        echo "$cmd"
        eval $cmd || error "$cmd failed"
@@ -8005,7 +8005,7 @@ test_56wa() {
        fi
 
        # lfs_migrate dir
-       cmd="$LFS_MIGRATE -y -c $expected $dir/dir1"
+       cmd="$LFS_MIGRATE -y -v -c $expected $dir/dir1"
        echo "$cmd"
        eval $cmd || error "$cmd failed"
 
@@ -8015,7 +8015,7 @@ test_56wa() {
 
        # lfs_migrate works with lfs find
        cmd="$LFS find -stripe_count $OSTCOUNT -type f $dir |
-            $LFS_MIGRATE -y -c $expected"
+            $LFS_MIGRATE -y -v -c $expected"
        echo "$cmd"
        eval $cmd || error "$cmd failed"