Whamcloud - gitweb
LU-9439 scripts: Provide a sample lnet.conf file
[fs/lustre-release.git] / lustre / scripts / lfs_migrate
index a09c368..f9cf91c 100755 (executable)
@@ -101,6 +101,8 @@ umask 0077
 $LFS getstripe --help 2>&1 | grep -q stripe-size && LFS_SIZE_OPT="-S"
 
 lfs_migrate() {
+       local RSYNC_MODE=false
+
        while IFS='' read -d '' OLDNAME; do
                $ECHO -n "$OLDNAME: "
 
@@ -130,7 +132,6 @@ lfs_migrate() {
                        continue
                fi
 
-
                if [ "$OPT_RESTRIPE" ]; then
                        UNLINK=""
                else
@@ -146,15 +147,28 @@ lfs_migrate() {
                               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} \
-                                     ${LFS_SIZE_OPT}${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,7 +177,7 @@ lfs_migrate() {
                        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