From 0549031b991ec0bbf570a41c7d28b8a7fd4b41c3 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 29 Sep 2021 20:51:51 -0600 Subject: [PATCH] LU-15045 utils: fix lfs_migrate for files with spaces Fix the lfs_migrate script to properly quote "$OLDNAME" so that it works for filenames with spaces and other characters in them. Test-Parameters: trivial Fixes: 8bedfa377fbd ("LU-11510 lfs: migrate a composite layout file correctly") Fixes: 128137adfc53 ("LU-13090 utils: fix lfs_migrate -p for file with pool") Signed-off-by: Andreas Dilger Change-Id: Ic00f41f3a91ad9dfa491ff57768a3da0c6300c1e Reviewed-on: https://review.whamcloud.com/45173 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Oleg Drokin --- lustre/scripts/lfs_migrate | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lustre/scripts/lfs_migrate b/lustre/scripts/lfs_migrate index f410840..9ed0f35 100755 --- a/lustre/scripts/lfs_migrate +++ b/lustre/scripts/lfs_migrate @@ -245,7 +245,7 @@ function calc_stripe() ost_min_kb=$avail fi fi - done < <($LFS df $OPT_POOL $OLDNAME | awk '/OST/ { print $4 }') + done < <($LFS df $OPT_POOL "$OLDNAME" | awk '/OST/ { print $4 }') if [ $ost_max_count -eq 0 ]; then # no OSTs with enough space, stripe over all of them @@ -362,6 +362,7 @@ lfs_migrate() { fi fi + 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" @@ -381,14 +382,14 @@ lfs_migrate() { local l_stripe_count=2 local l_stripe_size=3 local l_stripe_pool=4 - local layout_info=($($LFS getstripe $stripe_opts $OLDNAME \ + local layout_info=($($LFS getstripe $stripe_opts "$OLDNAME" \ 2>/dev/null | awk '{ print $2 }')) layout="${OPT_PASSTHROUGH[@]} " if $OPT_RESTRIPE; then UNLINK="" - layout+="--copy $(dirname $OLDNAME)" + layout+="--copy $olddir" OPT_COMP=true else # If rsync copies Lustre xattrs properly in the future @@ -425,7 +426,7 @@ lfs_migrate() { if $OPT_RESTRIPE; then parent_layout=($($LFS getstripe $stripe_opts \ - -d $(dirname $OLDNAME) 2>/dev/null | + -d "$olddir" 2>/dev/null | awk '{print $2 }')) parent_count=${parent_layout[$l_stripe_count]} parent_size=${parent_layout[$l_stripe_size]} @@ -481,7 +482,9 @@ lfs_migrate() { # first try to migrate via Lustre tools, then fall back to rsync if ! $OPT_RSYNC; then - $OPT_DEBUG && echo -e "\n$LFS migrate $layout $OLDNAME" + if $OPT_DEBUG; then + echo -e "\n$LFS migrate $layout \"$OLDNAME\"" + fi if $LFS migrate $layout "$OLDNAME"; then $ECHO "done" # no-op if hlinks empty for 1-link files @@ -498,8 +501,7 @@ lfs_migrate() { fi fi - local olddir=$(dirname $OLDNAME) - local oldfile=$(basename $OLDNAME) + local oldfile=$(basename "$OLDNAME") NEWNAME=$(mktemp $UNLINK "$olddir/.$oldfile.XXXXXX") if [ $? -ne 0 -o -z "$NEWNAME" ]; then echo -e "\r$OLDNAME: cannot make temp file, skipped" 1>&2 -- 1.8.3.1