RSYNC=${RSYNC:-"rsync"}
RSYNC_OPTS=${RSYNC_OPTS:-"-a --inplace"}
-OPT_RSYNC=${LFS_MIGRATE_RSYNC_MODE:-false}
ECHO=echo
LFS=${LFS:-lfs}
RSYNC_WITH_HLINKS=false
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
+ --no-rsync do not fall back to rsync even if lfs migrate fails (default)
-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)
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
+ -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 '-C', '-M', and '-X' are ignored if '-A' is not set.
-Options --rsync, --cp, --no-rsync may not be specified at the same time.
+Options --rsync, --cp, --no-rsync may not be used at the same time.
If a directory is an argument, all files in the directory are migrated.
If no file/directory is given, the file list is read from standard input.
Any arguments that are not explicitly recognized by the script are passed
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'
+
Examples:
lfs_migrate /mnt/lustre/dir
lfs_migrate -p newpool /mnt/lustre/dir
- lfs find /test -O test-OST0004 -size +4G | lfs_migrate -y
+ lfs find /test -O test-OST0004 -size +4G | lfs_migrate
USAGE
exit 1
}
trap cleanup EXIT
+OPT_AUTOSTRIPE=false
OPT_CHECK=true
OPT_DEBUG=false
OPT_DRYRUN=false
OPT_FILE=()
OPT_LAYOUT=()
OPT_COMP=false
-OPT_NO_RSYNC=false
+OPT_COPY=false
OPT_NO_DIRECT=false
+OPT_NO_RSYNC=true
OPT_NULL=false
OPT_PASSTHROUGH=()
OPT_POOL=""
OPT_RESTRIPE=false
-OPT_YES=false
-OPT_AUTOSTRIPE=false
+OPT_RSYNC=false
OPT_STRIPE_COUNT=""
OPT_STRIPE_SIZE=""
+OPT_YES=false
OPT_MINFREE=262144
OPT_MAXFREE=""
OPT_CAP=100
case "$arg" in
--auto-stripe|-A) OPT_AUTOSTRIPE=true;;
-b|--block|--non-block|--non-direct|-D|--no-verify)
- # Always pass non-layout options to 'lfs migrate'
- OPT_PASSTHROUGH+=("$arg");;
+ # Always pass non-layout options to 'lfs migrate'
+ OPT_PASSTHROUGH+=("$arg");;
--cp) $OPT_RSYNC && [[ "$RSYNC" != "cp" ]] && OPT_NO_RSYNC=true
- OPT_RSYNC=true; RSYNC="cp"; RSYNC_OPTS="-p";;
- --copy|--yaml|--file) OPT_COMP=true;
- # these options have files as arguments, pass both through
- OPT_LAYOUT+="$arg $2 "; shift;;
+ OPT_RSYNC=true; RSYNC="cp"; RSYNC_OPTS="-p";;
+ --copy|--yaml|--file) OPT_COPY=true;
+ # 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) OPT_CAP="$2"; shift;;
-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;;
+ echo "$PROG: -n deprecated, use --dry-run or --non-block" 1>&2;;
-p|--pool) OPT_POOL="$arg $2"; OPT_LAYOUT+="$OPT_POOL "; shift;;
-q|--quiet) ECHO=:;;
-R|--restripe) OPT_RESTRIPE=true;;
- --no-rsync) OPT_NO_RSYNC=true;;
- --rsync) $OPT_RSYNC && [[ "$RSYNC" != "rsync" ]] && OPT_NO_RSYNC=true
- OPT_RSYNC=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;;
-v|--verbose) OPT_DEBUG=true; ECHO=echo;;
fi
if $OPT_RSYNC && $OPT_NO_RSYNC; then
- echo "$PROG: Options --cp, --rsync, and --no-rsync may not be" \
- "specified at the same time." 1>&2
+ echo "$PROG: Options --cp, --rsync, --no-rsync may not be used together." 1>&2
exit 1
fi
-if ! $OPT_YES; then
+if $OPT_RSYNC && ! $OPT_YES; then
echo ""
- echo "lfs_migrate is currently NOT SAFE for moving in-use files." 1>&2
+ echo "'lfs_migrate --$RSYNC' is NOT SAFE for moving in-use files." 1>&2
echo "Use it only when you are sure migrated files are unused." 1>&2
echo "" 1>&2
- echo "If emptying an OST that is active on the MDS, new files may" 1>&2
- echo "use it. To stop allocating any new objects on OSTNNNN run:" 1>&2
- echo " lctl set_param osp.<fsname>-OSTNNNN*.max_create_count=0'" 1>&2
- echo "on each MDS using the OST(s) being emptied." 1>&2
echo -n "Continue? (y/n) "
read CHECK
[ "$CHECK" != "y" -a "$CHECK" != "yes" ] && exit 1
continue
fi
- if ! $OPT_COMP && ! $OPT_RSYNC &&
+ if ! $OPT_COPY && ! $OPT_COMP && ! $OPT_RSYNC &&
(( ${layout_info[$l_comp_count]} > 0 )); then
layout+="--copy $OLDNAME"
- OPT_COMP=true
+ OPT_COPY=true
fi
- if ! $OPT_COMP; then
+ 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" ] &&
run_test 56wc "check unrecognized options for lfs_migrate are passed through"
test_56wd() {
- [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
+ (( $OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
- local file1=$DIR/$tdir/file1
+ local file1=$DIR/$tdir/$tfile
echo -n "Creating test dir..."
test_mkdir $DIR/$tdir || error "cannot create dir"
echo "done."
echo -n "Creating test file..."
- touch $file1
+ echo "$tfile" > $file1
echo "done."
# Ensure 'lfs migrate' will fail by using a non-existent option,
grep -q 'falling back to rsync' &&
error "lfs migrate was called with --rsync set"
echo "done."
-
- echo -n "Make sure --rsync and --no-rsync options are exclusive..."
- $LFS_MIGRATE -y --rsync --no-rsync $file1 2>&1 |
- grep -q 'at the same time' ||
- error "--rsync and --no-rsync accepted concurrently"
- echo "done."
-
- # Clean up
- rm -f $file1
}
run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
run_test 56xa "lfs migration --block support"
check_migrate_links() {
+ [[ "$1" == "--rsync" ]] && local opts="--rsync -y" && shift
local dir="$1"
local file1="$dir/file1"
local begin="$2"
fi
echo -n "migrating files..."
- local migrate_out=$($runas $LFS_MIGRATE -y -S '1m' $dir)
+ local migrate_out=$($runas $LFS_MIGRATE $opts -S '1m' $dir)
local rc=$?
[ $rc -eq 0 ] || error "migrate failed rc = $rc"
echo "done"
test_mkdir "$dir" || error "cannot create dir $dir"
echo "testing lfs migrate mode when all links fit within xattrs"
- LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 2 99
+ check_migrate_links "$dir" 2 99
echo "testing rsync mode when all links fit within xattrs"
- LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 2 99
+ check_migrate_links --rsync "$dir" 2 99
echo "testing lfs migrate mode when all links do not fit within xattrs"
- LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100
+ check_migrate_links "$dir" 101 100
echo "testing rsync mode when all links do not fit within xattrs"
- LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 101 100
+ check_migrate_links --rsync "$dir" 101 100
- chown -R $RUNAS_ID $dir
+ chown -R $RUNAS_ID:$RUNAS_GID $dir
echo "testing non-root lfs migrate mode when not all links are in xattr"
- LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100 "$RUNAS"
+ check_migrate_links "$dir" 101 100 "$RUNAS"
# clean up
rm -rf $dir