X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fscripts%2Flfs_migrate;h=e9c8aaeddec4a9f7efac364ad6740accb4cb3293;hb=76dca841869d87df2b625cb9d186d531c406fc9b;hp=969386ed5616506fddc962fb8fc626355cfe8aa9;hpb=d40ad918bd688d9b5b3307ded042dd6d03cc414c;p=fs%2Flustre-release.git diff --git a/lustre/scripts/lfs_migrate b/lustre/scripts/lfs_migrate old mode 100644 new mode 100755 index 969386e..e9c8aae --- a/lustre/scripts/lfs_migrate +++ b/lustre/scripts/lfs_migrate @@ -17,10 +17,11 @@ set -e RSYNC=${RSYNC:-rsync} ECHO=echo LFS=${LFS:-lfs} +LFS_SIZE_OPT="-s" usage() { cat -- <&2 -usage: lfs_migrate [-c ] [-h] [-l] [-n] [-q] [-R] [-s] [-y] +usage: lfs_migrate [-c ] [-h] [-l] [-n] [-q] [-R] [-s] [-y] [-0] [file|dir ...] -c restripe file using the specified stripe count @@ -31,6 +32,7 @@ usage: lfs_migrate [-c ] [-h] [-l] [-n] [-q] [-R] [-s] [-y] -R restripe file using default directory striping -s skip file data comparison after migrate -y answer 'y' to usage question + -0 input file names on stdin are separated by a null character The -c option may not be specified at the same time as the -R option. @@ -47,7 +49,7 @@ USAGE OPT_CHECK=y OPT_STRIPE_COUNT="" -while getopts "c:hlnqRsy" opt $*; do +while getopts "c:hlnqRsy0" opt $*; do case $opt in c) OPT_STRIPE_COUNT=$OPTARG;; l) OPT_NLINK=y;; @@ -56,6 +58,7 @@ while getopts "c:hlnqRsy" opt $*; do R) OPT_RESTRIPE=y;; s) OPT_CHECK="";; y) OPT_YES=y;; + 0) OPT_NULL=y;; h|\?) usage;; esac done @@ -88,12 +91,23 @@ $RSYNC --help 2>&1 | grep -q acls && RSYNC_OPTS="$RSYNC_OPTS -A" # If rsync copies lustre xattrs in the future, then we can skip lfs (bug 22189) strings $(which $RSYNC) 2>&1 | grep -q lustre && LFS=: +# rsync creates its temporary files with lenient permissions, even if +# permissions on the original files are more strict. Tighten umask here +# to avoid the brief window where unprivileged users might be able to +# access the temporary file. +umask 0077 + +# This is needed for 1.8 Interoperability and can be removed in the future +$LFS getstripe --help 2>&1 | grep -q stripe-size && LFS_SIZE_OPT="-S" + lfs_migrate() { - while read OLDNAME; do + local RSYNC_MODE=false + + while IFS='' read -d '' OLDNAME; do $ECHO -n "$OLDNAME: " # avoid duplicate stat if possible - TYPE_LINK=($(stat -c "%h %F" "$OLDNAME" || true)) + TYPE_LINK=($(LANG=C stat -c "%h %F" "$OLDNAME" || true)) # skip non-regular files, since they don't have any objects # and there is no point in trying to migrate them. @@ -118,7 +132,6 @@ lfs_migrate() { continue fi - if [ "$OPT_RESTRIPE" ]; then UNLINK="" else @@ -130,17 +143,32 @@ lfs_migrate() { [ "$OPT_STRIPE_COUNT" ] && COUNT=$OPT_STRIPE_COUNT || COUNT=$($LFS getstripe -c "$OLDNAME" \ 2> /dev/null) - SIZE=$($LFS getstripe -S "$OLDNAME" 2> /dev/null) + SIZE=$($LFS getstripe $LFS_SIZE_OPT "$OLDNAME" \ + 2> /dev/null) [ -z "$COUNT" -o -z "$SIZE" ] && UNLINK="" + SIZE=${LFS_SIZE_OPT}${SIZE} fi + + # first try to migrate inside lustre + # if failed go back to old rsync mode + if [[ $RSYNC_MODE == false ]]; then + if $LFS migrate -c${COUNT} ${SIZE} "$OLDNAME"; then + $ECHO "done" + continue + else + echo "falling back to rsync-based migration" + RSYNC_MODE=true + fi + fi + NEWNAME=$(mktemp $UNLINK "$OLDNAME.tmp.XXXXXX") if [ $? -ne 0 -o -z "$NEWNAME" ]; then echo -e "\r$OLDNAME: can't make temp file, skipped" 1>&2 continue fi - [ "$UNLINK" ] && $LFS setstripe -c${COUNT} -S${SIZE} "$NEWNAME" + [ "$UNLINK" ] && $LFS setstripe -c${COUNT} ${SIZE} "$NEWNAME" # we use --inplace, since we created our own temp file already if ! $RSYNC -a --inplace $RSYNC_OPTS "$OLDNAME" "$NEWNAME";then @@ -163,13 +191,17 @@ lfs_migrate() { } if [ "$#" -eq 0 ]; then - lfs_migrate + if [ "$OPT_NULL" ]; then + lfs_migrate + else + tr '\n' '\0' | lfs_migrate + fi else while [ "$1" ]; do if [ -d "$1" ]; then - lfs find "$1" -type f | lfs_migrate + lfs find "$1" -type f -print0 | lfs_migrate else - echo $1 | lfs_migrate + echo -en "$1\0" | lfs_migrate fi shift done