# to be 100% safe the administrator needs to ensure this is safe.
RSYNC=${RSYNC:-rsync}
-LFS_MIGRATE_RSYNC_MODE=${LFS_MIGRATE_RSYNC_MODE:-false}
+OPT_RSYNC=${LFS_MIGRATE_RSYNC_MODE:-false}
ECHO=echo
LFS=${LFS:-lfs}
RSYNC_WITH_HLINKS=false
MIGRATED_SET="$(mktemp ${LFS_MIGRATE_TMP}/lfs_migrate.links.XXXXXX)"
NEWNAME=""
REMOVE_FID='s/^\[[0-9a-fx:]*\] //'
+PROG=$(basename $0)
add_to_set() {
local old_fid="$1"
local path="$2"
- echo -e "$old_fid $path" >> "$MIGRATED_SET"
+ echo "$old_fid $path" >> "$MIGRATED_SET"
}
path_in_set() {
usage() {
cat -- <<USAGE 1>&2
-usage: lfs_migrate [--dry-run] [-h] [--no-rsync|--rsync] [-q] [-R] [-s]
- [-v] [-y] [-0] [FILE|DIR...]
- --dry-run only print the names of files to be migrated
- -h show this usage message
+usage: lfs_migrate [--dry-run|-n] [--help|-h] [--no-rsync|--rsync] [--quiet|-q]
+ [--auto-stripe|-A [-C <cap>]
+ [--min-free|-M <min_free>] [--max-free|-X <max_free>]]
+ [--pool|-p <pool>] [--stripe-count|-c <stripe_count>]
+ [--stripe-size|-S <stripe_size>]
+ [-D] [-h] [-n] [-S]
+ [--restripe|-R] [--skip|-s] [--verbose|-v] [--yes|-y] [-0]
+ [FILE|DIR...]
+ -A restripe file using an automatically selected stripe count,
+ uses stripe_count = sqrt(size_in_GB) + 1
+ -c <stripe_count>
+ restripe file using the specified <stripe_count>
+ -C <cap> when -A is set, limit the migrated file to use on each OST
+ at most 1/<cap> of the available space of the smallest OST
+ -D do not use direct I/O to copy file contents
+ -h show this usage message
+ -M <min_free>
+ when -A is set, an OST must contain more available space than
+ <min_free> KB in order for it to be considered available for
+ use in the migration
--no-rsync do not fall back to rsync mode even if lfs migrate fails
- -q run quietly (don't print filenames or status)
- --rsync force rsync mode instead of using lfs migrate
- -R restripe file using default directory striping
- -s skip file data comparison after migrate
- -v show verbose debug messages
- -y answer 'y' to usage question
- -0 input file names on stdin are separated by a null character
-
-The -c <stripe_count> and -S <stripe_size> options may not be specified at
-the same time as the -R option.
+ -n only print the names of files to be migrated
+ -p <pool> use the specified OST pool for the destination file
+ -q run quietly (don't print filenames or status)
+ --rsync force rsync mode instead of using lfs migrate
+ -R restripe file using default directory striping
+ -s skip file data comparison after migrate
+ -S <stripe_size>
+ restripe file using the specified stripe size
+ -v show verbose debug messages
+ -X <max_free>
+ when -A is set, limit the amount of space on each OST that
+ can be considered available for the migration to
+ <max_free> KB
+ -y answer 'y' to usage question
+ -0 input file names on stdin are separated by a null character
+
+Options '-A', '-c', and '-R' are mutually exclusive.
+Options '-C', '-M', and '-X' are ignored if '-A' is not set.
The --rsync and --no-rsync options may not be specified at the same time.
OPT_CHECK=true
OPT_DEBUG=false
-OPT_NO_RSYNC=false
OPT_DRYRUN=false
-OPT_YES=false
-OPT_RESTRIPE=false
+OPT_FILE=()
+OPT_LAYOUT=()
+OPT_NO_RSYNC=false
+OPT_NO_DIRECT=false
OPT_NULL=false
OPT_PASSTHROUGH=()
-STRIPE_COUNT=""
-STRIPE_SIZE=""
-POOL=""
+OPT_POOL=""
+OPT_RESTRIPE=false
+OPT_YES=false
+LFS_OPT_DIRECTIO=""
+OPT_AUTOSTRIPE=false
+OPT_STRIPE_COUNT=""
+OPT_STRIPE_SIZE=""
+OPT_MINFREE=262144
+OPT_MAXFREE=""
+OPT_CAP=100
# Examine any long options and arguments. getopts does not support long
# options, so they must be stripped out and classified as either options
# for the script, or passed through to "lfs migrate".
-LONG_OPT=false
-SHORT_OPT=false
-OPTS=()
-
-for f in $(seq 1 $#); do
- arg=${!f}
- if [ "${arg:0:2}" = "--" ]; then
- SHORT_OPT=false
- if [ "$arg" = "--block" ]; then
- BLOCK="$arg"
- OPT_YES=true
- elif [ "$arg" = "--non-block" ]; then
- BLOCK="$arg"
- elif [ "$arg" = "--dry-run" ]; then
- OPT_DRYRUN=true
- OPT_YES=true
- elif [ "$arg" = "--rsync" ]; then
- LFS_MIGRATE_RSYNC_MODE=true
- elif [ "$arg" = "--no-rsync" ]; then
- OPT_NO_RSYNC=true
- OPT_YES=true
- else
- LONG_OPT=true
- OPT_PASSTHROUGH+=("$arg")
- fi
- elif [ "${arg:0:1}" = "-" ]; then
- LONG_OPT=false
- if [ "$arg" == "-b" ]; then
- BLOCK="$arg"
- else
- SHORT_OPT=true
- OPTS+=("$arg")
- fi
- elif $LONG_OPT; then
- LONG_OPT=false
- # This will prevent long options from having file name
- # arguments, but allows long options with no arguments to work.
- if [ -f "$arg" -o -d "$arg" ]; then
- OPTS+=("$arg")
- else
- [ "${OPT_PASSTHROUGH[-1]}" = "--stripe-count" ] &&
- STRIPE_COUNT="$arg"
- [ "${OPT_PASSTHROUGH[-1]}" = "--stripe-size" ] &&
- STRIPE_SIZE="$arg"
- [ "${OPT_PASSTHROUGH[-1]}" = "--pool" ] &&
- POOL="$arg"
- OPT_PASSTHROUGH+=("$arg")
- fi
- elif $SHORT_OPT; then
- [ "${OPTS[-1]}" = "-c" ] &&
- STRIPE_COUNT="$arg"
- [ "${OPTS[-1]}" = "-S" ] &&
- STRIPE_SIZE="$arg"
- [ "${OPTS[-1]}" = "-p" ] &&
- POOL="$arg"
- SHORT_OPT=false
- OPTS+=("$arg")
- else
- OPTS+=("$arg")
- fi
-done
-
-# Reset the argument list to include only the short options and file names
-set -- "${OPTS[@]}"
-
-while getopts ":hlnqRsvy0" opt $*; do
- case $opt in
- h) usage;;
- l) ;; # maintained for backward compatibility
- n) OPT_DRYRUN=true
- OPT_YES=true
- echo "$(basename $0): -n deprecated, use --dry-run instead" 1>&2
- echo "$(basename $0): to specify non-block, use --non-block instead" 1>&2;;
- q) ECHO=:;;
- R) OPT_RESTRIPE=true;;
- s) OPT_CHECK=false;;
- v) OPT_DEBUG=true; ECHO=echo; OPT_PASSTHROUGH+=("-v");;
- y) OPT_YES=true;;
- 0) OPT_NULL=true;;
- *) # Pass through any unrecognized options to 'lfs migrate'
- OPT_PASSTHROUGH+=("-$OPTARG")
- if [[ ${!OPTIND:0:1} != "-" && ! -f "${!OPTIND}" &&
- ! -d "${!OPTIND}" ]]; then
- OPT_PASSTHROUGH+=("${!OPTIND}")
- ((OPTIND++))
- fi;;
- esac
+while [ -n "$*" ]; do
+ arg="$1"
+ case "$arg" in
+ -h|--help) usage;;
+ -l|--link) ;; # maintained backward compatibility for now
+ -n) OPT_DRYRUN=true; OPT_YES=true
+ echo "$PROG: -n deprecated, use --dry-run or --non-block" 1>&2;;
+ --dry-run) OPT_DRYRUN=true; OPT_YES=true;;
+ -p|--pool) OPT_POOL="$arg $2"; OPT_LAYOUT+="$OPT_POOL "; shift;;
+ -q|--quiet) ECHO=:;;
+ -R|--restripe) OPT_RESTRIPE=true;;
+ -s|--skip) OPT_CHECK=false;;
+ -v|--verbose) OPT_DEBUG=true; ECHO=echo;;
+ -y|--yes) OPT_YES=true;;
+ -0) OPT_NULL=true;;
+ -b|--block|--non-block|--non-direct|--no-verify)
+ # Always pass non-layout options to 'lfs migrate'
+ OPT_PASSTHROUGH+=("$arg");;
+ --rsync) OPT_RSYNC=true;;
+ --no-rsync) OPT_NO_RSYNC=true;;
+ --copy|--yaml|--file)
+ # these options have files as arguments, pass both through
+ OPT_LAYOUT+="$arg $2 "; shift;;
+ --auto-stripe|-A) OPT_AUTOSTRIPE=true;;
+ -C) OPT_CAP="$2"; shift;;
+ -D) LFS_OPT_DIRECTIO="-D";;
+ -M|--min-free) OPT_MINFREE="$2"; shift;;
+ -X|--max-free) OPT_MAXFREE="$2"; shift;;
+ -c|--stripe-count) OPT_STRIPE_COUNT="$2"; shift;;
+ -S|--stripe-size) OPT_STRIPE_SIZE="$2"; shift;;
+ *) # Pass other non-file layout options to 'lfs migrate'
+ [ -e "$arg" ] && OPT_FILE+="$arg " && break || OPT_LAYOUT+="$arg "
+ esac
+ shift
done
-shift $((OPTIND - 1))
-if $OPT_RESTRIPE && [[ "$STRIPE_COUNT" || "$STRIPE_SIZE" ]]; then
+if $OPT_RESTRIPE && [ -n "$OPT_LAYOUT" ]; then
+ echo "$PROG: Options $OPT_LAYOUT cannot be used with the -R option" 1>&2
+ exit 1
+elif $OPT_RESTRIPE && [[ "$OPT_STRIPE_COUNT" || "$OPT_STRIPE_SIZE" ]]; then
echo "$(basename $0): Options -c <stripe_count> and -S <stripe_size> "\
"may not be specified at the same time as the -R option." 1>&2
exit 1
+elif $OPT_AUTOSTRIPE && [ -n "$OPT_STRIPE_COUNT" ]; then
+ echo ""
+ echo "$(basename $0) error: The -c <stripe_count> option may not" 1>&2
+ echo "be specified at the same time as the -A option." 1>&2
+ exit 1
+elif $OPT_AUTOSTRIPE && $OPT_RESTRIPE; then
+ echo ""
+ echo "$(basename $0) error: The -A option may not be specified at" 1>&2
+ echo "the same time as the -R option." 1>&2
+ exit 1
fi
-if $LFS_MIGRATE_RSYNC_MODE && $OPT_NO_RSYNC; then
- echo "$(basename $0): Options --rsync and --no-rsync may not be "\
- "specified at the same time." 1>&2
+if $OPT_RSYNC && $OPT_NO_RSYNC; then
+ echo "$PROG: Options --rsync and --no-rsync may not be" \
+ "specified at the same time." 1>&2
exit 1
fi
# access the temporary file.
umask 0077
+# Use stripe count = sqrt(size_in_GB) + 1, but cap object size per OST.
+function calc_stripe()
+{
+ local filename=$1
+ local filekb=$2
+ local obj_max_kb=$3
+ local filegb=$((filekb / 1048576))
+ local stripe_count=1
+ local ost_max_count=0
+
+ # Files up to 1GB will have 1 stripe if they fit within the object max
+ if [[ $filegb -lt 1 && "$obj_max_kb" && $filekb -le $obj_max_kb ]]; then
+ echo 1 "$obj_max_kb" && return
+ fi
+
+ stripe_count=$(bc <<< "scale=0; 1 + sqrt($filegb)" 2> /dev/null) ||
+ { echo "cannot auto calculate stripe count" >&2; return; }
+
+ if [ -z "$obj_max_kb" ]; then
+ local ost_min_kb=$((1 << 62))
+
+ # Calculate cap on object size at 1% of smallest OST
+ # but only include OSTs that have 256MB+ available space
+ while IFS='' read avail; do
+ [[ "$OPT_MAXFREE" && $avail -gt $OPT_MAXFREE ]] &&
+ avail=$OPT_MAXFREE
+ if [ $avail -ge $OPT_MINFREE ]; then
+ ost_max_count=$((ost_max_count + 1))
+ if [ $avail -lt $ost_min_kb ]; then
+ ost_min_kb=$avail
+ fi
+ fi
+ 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
+ echo "-1" "0"
+ return
+ fi
+
+ if (( ost_min_kb == (1 << 62) )); then
+ echo "warning: unable to determine minimum OST size, " \
+ "object size not capped" >&2
+ echo "$stripe_count" "0"
+ return
+ fi
+
+ obj_max_kb=$((ost_min_kb / $OPT_CAP))
+ elif [ $obj_max_kb -eq 0 ]; then
+ echo "warning: unable to determine minimum OST size " \
+ "from previous migrate, object size not capped" >&2
+ echo "$stripe_count" "$obj_max_kb"
+ return
+ fi
+
+ # If disk usage would exceed the cap, increase the number of stripes.
+ # Round up to the nearest MB to ensure file will fit.
+ (( filekb > stripe_count * obj_max_kb )) &&
+ stripe_count=$(((filekb + obj_max_kb - 1024) / obj_max_kb))
+
+ # Limit the count to the number of eligible OSTs
+ if [ "$stripe_count" -gt $ost_max_count ]; then
+ echo "$ost_max_count" "$obj_max_kb"
+ else
+ echo "$stripe_count" "$obj_max_kb"
+ fi
+}
+
lfs_migrate() {
+ local last_dev
+ local mntpoint
+
while IFS='' read -d '' OLDNAME; do
local hlinks=()
- local stripe_size="$STRIPE_SIZE"
- local stripe_count="$STRIPE_COUNT"
+ local stripe_size="$OPT_STRIPE_SIZE"
+ local stripe_count="$OPT_STRIPE_COUNT"
local parent_count=""
local parent_size=""
+ local stripe_pool="${OPT_POOL#-p }"
+ local mirror_count
+ local layout
+ local fid
$ECHO -n "$OLDNAME: "
- # avoid duplicate stat if possible
- local nlink_type=($(LANG=C stat -c "%h %F" "$OLDNAME" \
+ # avoid duplicate stat call by fetching all attrs at once
+ local nlink_idx_link=0 # %h is the hard link count
+ local nlink_idx_type=1 # %F is "regular file", ignore others
+ local nlink_idx_file=2 # "file" is here
+ local nlink_idx_size=3 # %s is file size in bytes
+ local nlink_idx_dev=4 # %D is the underlying device number
+ # nlink_type=(1 regular file 1234 0x810)
+ local nlink_type=($(LANG=C stat -c "%h %F %s %D" "$OLDNAME" \
2> /dev/null))
# skip non-regular files, since they don't have any objects
# and there is no point in trying to migrate them.
- if [ "${nlink_type[1]}" != "regular" ]; then
- echo -e "\r\e[K$OLDNAME: not a regular file, skipped"
+ if [ "${nlink_type[$nlink_idx_type]}" != "regular" ]; then
+ echo -e "\r$OLDNAME: not a regular file, skipped" 1>&2
continue
fi
# working out write perms is hard, let the shell do it
if [ ! -w "$OLDNAME" ]; then
- echo -e "\r\e[K$OLDNAME: no write permission, skipped"
+ echo -e "\r$OLDNAME: no write permission, skipped" 1>&2
continue
fi
# also absolute so that the names can be compared
local oldname_absolute=$(readlink -f "$OLDNAME")
if [ -z "$oldname_absolute" ]; then
- echo -e "\r\e[K$OLDNAME: cannot resolve full path, skipped"
+ echo -e "\r$OLDNAME: cannot resolve full path, skipped" 1>&2
continue
fi
OLDNAME=$oldname_absolute
- # In the future, the path2fid and fid2path calls below
- # should be replaced with a single call to
- # "lfs path2links" once that command is available. The logic
- # for detecting unlisted hard links could then be removed.
- local fid=$($LFS path2fid "$OLDNAME" 2> /dev/null)
- if [ $? -ne 0 ]; then
- echo -n "\r\e[K$OLDNAME: cannot determine FID; skipping; "
- echo "is this a Lustre file system?"
- continue
- fi
+ if [[ ${nlink_type[$nlink_idx_link]} -gt 1 ]] ||
+ $RSYNC_WITH_HLINKS; then
+ fid=$($LFS path2fid "$OLDNAME" 2> /dev/null)
+ if [ $? -ne 0 ]; then
+ echo -e "\r$OLDNAME: cannot get FID, skipping; is this a Lustre file system?" 1>&2
+ continue
+ fi
- if [[ ${nlink_type[0]} -gt 1 ]] || $RSYNC_WITH_HLINKS; then
# don't migrate a hard link if it was already migrated
if path_in_set "$OLDNAME"; then
- $ECHO -e "$OLDNAME: already migrated via another hard link"
+ $ECHO "already migrated via another hard link"
continue
fi
# being migrated.
local migrated=$(old_fid_in_set "$fid")
if [ -n "$migrated" ]; then
- $ECHO -e "$OLDNAME: already migrated via another hard link"
- if $LFS_MIGRATE_RSYNC_MODE; then
- # Only the rsync case has to relink.
- # The lfs migrate case preserves the
- # inode so the links are already
- # correct.
- [ "$migrated" != "$OLDNAME" ] &&
- ln -f "$migrated" "$OLDNAME"
- fi
+ $ECHO "already migrated via another hard link"
+ # Only the rsync case has to relink. The
+ # "lfs migrate" case keeps the same inode so
+ # all of the links are already correct.
+ $OPT_RSYNC && [ "$migrated" != "$OLDNAME" ] &&
+ ln -f "$migrated" "$OLDNAME"
+
add_to_set "$fid" "$OLDNAME"
continue;
fi
if $OPT_RESTRIPE; then
UNLINK=""
else
- # 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 to do this getstripe/mktemp stuff.
+ # 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.
UNLINK="-u"
- [ -z "$stripe_count" ] &&
- stripe_count=$($LFS getstripe -c "$OLDNAME" 2> /dev/null)
+ [ -n "$OPT_POOL" ] ||
+ stripe_pool=$($LFS getstripe -p "$OLDNAME" 2>/dev/null)
+ mirror_count=$($LFS getstripe -N "$OLDFILE" 2>/dev/null)
- [ -z "$stripe_size" ] &&
+ 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
+ else
+ [ -n "$stripe_count" ] ||
+ stripe_count=$($LFS getstripe -c "$OLDNAME" \
+ 2> /dev/null)
+ fi
+ [ -n "$stripe_size" ] ||
stripe_size=$($LFS getstripe -S "$OLDNAME" 2> /dev/null)
[ -z "$stripe_count" -o -z "$stripe_size" ] && UNLINK=""
fi
if $OPT_DEBUG; then
+ local parent_count
+ local parent_size
+
if $OPT_RESTRIPE; then
parent_count=$($LFS getstripe -c \
$(dirname "$OLDNAME") 2> \
parent_size=$($LFS getstripe -S \
$(dirname "$OLDNAME") 2> \
/dev/null)
+ stripe_pool=$($LFS getstripe --pool \
+ $(dirname "$OLDNAME") 2> \
+ /dev/null)
+ mirror_count=$($LFS getstripe -N \
+ $(dirname "$OLDFILE") 2> \
+ /dev/null)
fi
- $ECHO -n "stripe" \
- "count=${stripe_count:-$parent_count}," \
- "size=${stripe_size:-$parent_size}," \
- "pool=${POOL:-not in a pool}: "
+ $ECHO -n "stripe_count=${stripe_count:-$parent_count},stripe_size=${stripe_size:-$parent_size}"
+ [ -n "$stripe_pool" ] &&
+ $ECHO -n ",pool=${stripe_pool}"
+ [ -n "$mirror_count" ] &&
+ $ECHO -n ",mirror_count=${mirror_count}"
+ $ECHO -n " "
fi
if $OPT_DRYRUN; then
- $ECHO "dry run, skipped"
+ $ECHO " dry run, skipped"
continue
fi
- if [[ "$stripe_count" && -z "$STRIPE_COUNT" ]]; then
- stripe_count="-c $stripe_count"
- else
- stripe_count=""
- fi
- if [[ "$stripe_size" && -z "$STRIPE_SIZE" ]]; then
- stripe_size="-S $stripe_size"
- else
- stripe_size=""
- fi
+ layout="${OPT_PASSTHROUGH[@]} "
+ [ -n "$stripe_count" ] && layout+="-c $stripe_count "
+ [ -n "$stripe_size" ] && layout+="-S $stripe_size "
+ [ -z "$OPT_POOL" -a -n "$stripe_pool" ] &&
+ layout+="-p $stripe_pool "
+ [ -n "$mirror_count" ] && layout+="-N $mirror_count "
+ layout+="$OPT_LAYOUT"
# detect other hard links and store them on a global
# list so we don't re-migrate them
- local mntpoint=$(df -P "$OLDNAME" |
- awk 'NR==2 { print $NF; exit }')
- if [ -z "$mntpoint" ]; then
- echo -e "\r\e[K$OLDNAME: cannot determine mount point; skipped"
- continue
- fi
- hlinks=$($LFS fid2path "$mntpoint" "$fid" 2> /dev/null)
- if [ $? -ne 0 ]; then
- echo -e "\r\e[K$OLDNAME: cannot determine hard link paths, skipped"
- continue
+ if [[ ${nlink_type[$nlink_idx_link]} -gt 1 ]]; then
+ [ "${nlink_type[$nlink_idx_dev]}" == "$last_dev" ] ||
+ mntpoint=$(df -P "$OLDNAME" |
+ awk 'NR==2 { print $NF }')
+ if [ -z "$mntpoint" ]; then
+ echo -e "\r$OLDNAME: cannot determine mount point; skipped" 1>&2
+ continue
+ fi
+ hlinks=$($LFS fid2path "$mntpoint" "$fid" 2> /dev/null)
+ if $OPT_RSYNC && [ $? -ne 0 ]; then
+ echo -e "\r$OLDNAME: cannot determine hard link paths, skipped" 1>&2
+ continue
+ fi
+ hlinks+=("$OLDNAME")
+ else
+ hlinks=
fi
- hlinks+=("$OLDNAME")
# first try to migrate via Lustre tools, then fall back to rsync
- if ! $LFS_MIGRATE_RSYNC_MODE; then
- if $LFS migrate "${OPT_PASSTHROUGH[@]}" ${BLOCK} \
- ${stripe_count} ${stripe_size} "$OLDNAME" &> \
- /dev/null; then
- $ECHO "done migrate"
+ if ! $OPT_RSYNC; then
+ if $LFS migrate $layout "$OLDNAME"; then
+ $ECHO "done"
+ # no-op if hlinks empty for 1-link files
for link in ${hlinks[*]}; do
add_to_set "$fid" "$link"
done
continue
elif $OPT_NO_RSYNC; then
- echo -e "\r\e[K$OLDNAME: refusing to fall back to rsync, skipped" 1>&2
+ echo -e "\r$OLDNAME: refusing to fall back to rsync, skipped" 1>&2
continue
else
$ECHO -n "falling back to rsync: "
- LFS_MIGRATE_RSYNC_MODE=true
+ OPT_RSYNC=true
fi
fi
- NEWNAME=$(mktemp $UNLINK "$OLDNAME-lfs_migrate.tmp.XXXXXX")
+ local olddir=$(dirname $OLDNAME)
+ local oldfile=$(basename $OLDNAME)
+ NEWNAME=$(mktemp $UNLINK "$olddir/.$oldfile.XXXXXX")
if [ $? -ne 0 -o -z "$NEWNAME" ]; then
- echo -e "\r\e[K$OLDNAME: can't make temp file, skipped" 1>&2
+ echo -e "\r$OLDNAME: cannot make temp file, skipped" 1>&2
continue
fi
- [ "$UNLINK" ] && $LFS setstripe ${OPT_PASSTHROUGH} \
- ${stripe_count} ${stripe_size} \
- "$NEWNAME" &> /dev/null
+ if [ "$UNLINK" ]; then
+ if ! $LFS setstripe $layout "$NEWNAME"; then
+ echo -e "\r$NEWNAME: setstripe failed, exiting" 1>&2
+ exit 2
+ fi
+ fi
# we use --inplace, since we created our own temp file already
if ! $RSYNC -a --inplace $RSYNC_OPTS "$OLDNAME" "$NEWNAME";then
- echo -e "\r\e[K$OLDNAME: copy error, exiting" 1>&2
+ echo -e "\r$OLDNAME: copy error, exiting" 1>&2
exit 4
fi
if $OPT_CHECK && ! cmp -s "$OLDNAME" "$NEWNAME"; then
- echo -e "\r\e[K$NEWNAME: compare failed, exiting" 1>&2
+ echo -e "\r$NEWNAME: compare failed, exiting" 1>&2
exit 8
fi
if ! mv "$NEWNAME" "$OLDNAME"; then
- echo -e "\r\e[K$OLDNAME: rename error, exiting" 1>&2
+ echo -e "\r$OLDNAME: rename error, exiting" 1>&2
exit 12
fi
- $ECHO "done migrate via rsync"
+ $ECHO "done rsync"
+ # no-op if hlinks empty for 1-link files
for link in ${hlinks[*]}; do
if [ "$link" != "$OLDNAME" ]; then
ln -f "$OLDNAME" "$link"
# of 1 (all other links will point to the new inode).
# This flag indicates that even paths with a link count of
# 1 are potentially part of a link set.
- [ ${#hlinks[*]} -gt 1 ] && RSYNC_WITH_HLINKS=true
+ (( ${#hlinks[*]} == 1 )) || RSYNC_WITH_HLINKS=true
done
}