From 6086d0d69c84ce57c4daff18595fa7b620ed2b04 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Fri, 9 Jun 2017 20:39:11 -0600 Subject: [PATCH] LU-6051 utils: allow lfs_migrate to migrate links When running on a server that supports "lfs migrate", it is possible to migrate hard links transparently. This is still not possible for servers that do not support "lfs migrate" (layout swap) so we still need to keep the hard-link check if "lfs migrate" fails. Add test for migrating many hardlinks on supported kernels. Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: I7fa1c70611aa7dd61f822844d5fe339f730640e5 Reviewed-on: https://review.whamcloud.com/27553 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Steve Guminski Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- lustre/scripts/lfs_migrate | 19 +++++----- lustre/tests/sanity.sh | 95 ++++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/lustre/scripts/lfs_migrate b/lustre/scripts/lfs_migrate index 6bc0797..37e8ee0 100755 --- a/lustre/scripts/lfs_migrate +++ b/lustre/scripts/lfs_migrate @@ -15,6 +15,7 @@ set -e # 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" @@ -26,7 +27,7 @@ usage: lfs_migrate [-c ] [-h] [-l] [-n] [-q] [-R] [-s] [-y] [-0] -c 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 @@ -101,8 +102,6 @@ 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: " @@ -116,11 +115,6 @@ lfs_migrate() { 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" @@ -152,16 +146,21 @@ lfs_migrate() { # first try to migrate inside lustre # if failed go back to old rsync mode - if [[ $RSYNC_MODE == false ]]; then + 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" - RSYNC_MODE=true + 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 diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 55d91e0..978d93d 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -5047,54 +5047,59 @@ test_56w() { [ $PARALLEL == "yes" ] && skip "skip parallel run" && return TDIR=$DIR/${tdir}w - rm -rf $TDIR || error "remove $TDIR failed" - setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1" - - local stripe_size - stripe_size=$($GETSTRIPE -S -d $TDIR) || - error "$GETSTRIPE -S -d $TDIR failed" - stripe_size=${stripe_size%% *} - - local file_size=$((stripe_size * OSTCOUNT)) - local file_num=$((NUMDIRS * NUMFILES + NUMFILES)) - local required_space=$((file_num * file_size)) - - local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail | - head -n1) - [[ $free_space -le $((required_space / 1024)) ]] && - skip_env "need at least $required_space bytes free space," \ - "have $free_space kbytes" && return - - local dd_bs=65536 - local dd_count=$((file_size / dd_bs)) - - # write data into the files - local i - local j - local file - for i in $(seq 1 $NUMFILES); do - file=$TDIR/file$i - yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 || - error "write data into $file failed" - done - for i in $(seq 1 $NUMDIRS); do - for j in $(seq 1 $NUMFILES); do - file=$TDIR/dir$i/file$j - yes | dd bs=$dd_bs count=$dd_count of=$file \ - >/dev/null 2>&1 || - error "write data into $file failed" - done - done + rm -rf $TDIR || error "remove $TDIR failed" + setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1" + + local stripe_size + stripe_size=$($GETSTRIPE -S -d $TDIR) || + error "$GETSTRIPE -S -d $TDIR failed" + stripe_size=${stripe_size%% *} + + local file_size=$((stripe_size * OSTCOUNT)) + local file_num=$((NUMDIRS * NUMFILES + NUMFILES)) + local required_space=$((file_num * file_size)) + + local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail | + head -n1) + [[ $free_space -le $((required_space / 1024)) ]] && + skip_env "need $required_space bytes, have $free_space KB" && + return - local expected=-1 - [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1)) + local dd_bs=65536 + local dd_count=$((file_size / dd_bs)) - # lfs_migrate file - local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1" - echo "$cmd" - eval $cmd || error "$cmd failed" + # write data into the files + local i + local j + local file + for i in $(seq 1 $NUMFILES); do + file=$TDIR/file$i + yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null || + error "write data into $file failed" + done + for i in $(seq 1 $NUMDIRS); do + for j in $(seq 1 $NUMFILES); do + file=$TDIR/dir$i/file$j + yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null || + error "write data into $file failed" + done + done + + # $LFS_MIGRATE will fail if hard link migration is unsupported + if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then + createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 || + error "creating links to $TDIR/dir1/file1 failed" + fi + + local expected=-1 + [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1)) + + # lfs_migrate file + local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1" + echo "$cmd" + eval $cmd || error "$cmd failed" - check_stripe_count $TDIR/file1 $expected + check_stripe_count $TDIR/file1 $expected if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ]; then -- 1.8.3.1