Whamcloud - gitweb
LU-3133 lfsck: remove objects from OST
[fs/lustre-release.git] / lustre / tests / lfsck.sh
index 1c805a1..88aa5bd 100644 (file)
@@ -28,17 +28,12 @@ which can be accessable on all of the nodes" && exit 0; }
 which getfattr &>/dev/null || { skip_env "could not find getfattr" && exit 0; }
 which setfattr &>/dev/null || { skip_env "could not find setfattr" && exit 0; }
 
-if [ ! -x `which $LFSCK_BIN` ]; then
-    log "$($E2FSCK -V)"
-    error "e2fsprogs does not support lfsck"
-fi
-
 MOUNT_2=""
 check_and_setup_lustre
 
 assert_DIR
 
-SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
+SAMPLE_FILE=$TMP/$TESTSUITE.junk
 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
 
 # Create some dirs and files on the filesystem.
@@ -131,7 +126,7 @@ get_ost_dev() {
        local ost_dev
 
        ost_name=$(ostname_from_index $obdidx)
-       ost_dev=$(get_obdfilter_param $node $ost_name mntdev)
+       ost_dev=$(get_osd_param $node $ost_name mntdev)
        if [ $? -ne 0 ]; then
                printf "unable to find OST%04x on $facet\n" $obdidx
                return 1
@@ -166,7 +161,7 @@ get_files() {
     esac
 
     local files=""
-    local f 
+    local f
     for f in $(seq -f testfile.%g $first $last); do
         test_file=$test_dir/$f
         files="$files $test_file"
@@ -177,28 +172,7 @@ get_files() {
 
 # Remove objects associated with files.
 remove_objects() {
-    local node=$1
-    shift
-    local ostdev=$1
-    shift
-    local group=$1
-    shift
-    local objids="$@"
-    local tmp
-    local i
-    local rc
-
-    echo "removing objects from $ostdev on $facet: $objids"
-    tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
-    for i in $objids; do
-        echo "rm O/$group/d$((i % 32))/$i" >> $tmp
-    done
-
-    do_node $node "$DEBUGFS -w -f $tmp $ostdev"
-    rc=${PIPESTATUS[0]}
-    rm -f $tmp
-
-    return $rc
+       do_rpc_nodes $1 remove_ost_objects $@
 }
 
 # Remove files from MDS.
@@ -218,9 +192,9 @@ init_logging
 # get the server target devices
 get_svr_devs
 
+TESTDIR=$DIR/d0.$TESTSUITE
 if is_empty_fs $MOUNT; then
     # create test directory
-    TESTDIR=$DIR/d0.$TESTSUITE
     mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
 
     # create some dirs and files on the filesystem
@@ -232,7 +206,7 @@ if is_empty_fs $MOUNT; then
 
     # get the node name and target device for the OST with index $OSTIDX
     OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
-    OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
+    OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) ||
        error "get_ost_dev $OSTNODE $OSTIDX failed"
 
     # get the file names to be duplicated on the MDS
@@ -244,14 +218,14 @@ if is_empty_fs $MOUNT; then
 
     # remove objects associated with files in group $OBJGRP
     # on the OST with index $OSTIDX
-    remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
+       remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE ||
         error "removing objects failed"
 
     # remove files from MDS
     remove_files $SINGLEMDS $MDTDEV $MDS_REMOVE || error "removing files failed"
 
     # create EAs on files so objects are referenced from different files
-    duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE || \
+    duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE ||
         error "duplicating files failed"
     FSCK_MAX_ERR=1   # file system errors corrected
 else # is_empty_fs $MOUNT
@@ -264,8 +238,10 @@ fi
 generate_db
 
 # remount filesystem
+ORIG_REFORMAT=$REFORMAT
 REFORMAT=""
 check_and_setup_lustre
+REFORMAT=$ORIG_REFORMAT
 
 # run lfsck
 rc=0
@@ -286,6 +262,15 @@ else
     fi
 fi
 
-complete $(basename $0) $SECONDS
+complete $SECONDS
+# The test directory contains some files referencing to some object
+# which could cause error when removing the directory.
+RMCNT=0
+while [ -d $TESTDIR ]; do
+       RMCNT=$((RMCNT + 1))
+       rm -fr $TESTDIR || echo "$RMCNT round: rm $TESTDIR failed"
+       [ $RMCNT -ge 10 ] && error "cleanup $TESTDIR failed $RMCNT times"
+       remount_client $MOUNT
+done
 check_and_cleanup_lustre
 exit_status