# to be 100% safe the administrator needs to ensure this is safe.
RSYNC=${RSYNC:-rsync}
+LFS_MIGRATE_RSYNC_MODE=${LFS_MIGRATE_RSYNC_MODE:-false}
ECHO=echo
LFS=${LFS:-lfs}
+LFS_SIZE_OPT="-s"
usage() {
cat -- <<USAGE 1>&2
-c <stripe_count>
restripe file using the specified stripe count
-h show this usage message
- -l migrate files with hard links (skip by default)
+ -l migrate files with hard links (skip by default for rsync)
-n only print the names of files to be migrated
-q run quietly (don't print filenames or status)
-R restripe file using default directory striping
echo "lfs_migrate is currently 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 OST(s) that are not disabled on the MDS, new" 1>&2
- echo "files may use them. To prevent MDS allocating any files on" 1>&2
- echo "OSTNNNN run 'lctl --device %{fsname}-OSTNNNN-osc deactivate'" 1>&2
- echo "on the MDS." 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
# 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 IFS='' read -d '' OLDNAME; do
$ECHO -n "$OLDNAME: "
continue
fi
- if [ -z "$OPT_NLINK" -a ${TYPE_LINK[0]} -gt 1 ]; then
- echo -e "multiple hard links, skipped"
- continue
- fi
-
# working out write perms is hard, let the shell do it
if [ ! -w "$OLDNAME" ]; then
echo -e "no write permission, skipped"
continue
fi
-
if [ "$OPT_RESTRIPE" ]; then
UNLINK=""
else
[ "$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 [[ $LFS_MIGRATE_RSYNC_MODE == false ]]; then
+ if $LFS migrate -c${COUNT} ${SIZE} "$OLDNAME"; then
+ $ECHO "done"
+ continue
+ else
+ echo "falling back to rsync-based migration"
+ LFS_MIGRATE_RSYNC_MODE=true
+ fi
+ fi
+
+ if [ -z "$OPT_NLINK" -a ${TYPE_LINK[0]} -gt 1 ]; then
+ echo -e "multiple hard links, skipped"
+ continue
+ 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
exit 4
fi
- if [ "$OPT_CHECK" ] && ! cmp "$OLDNAME" "$NEWNAME"; then
+ if [ "$OPT_CHECK" ] && ! cmp -s "$OLDNAME" "$NEWNAME"; then
echo -e "\r$NEWNAME: compare failed, exiting" 1>&2
exit 8
fi