Whamcloud - gitweb
LU-3133 lfsck: remove objects from OST
[fs/lustre-release.git] / lustre / tests / lfsck.sh
index 2c58f5f..88aa5bd 100644 (file)
@@ -20,21 +20,20 @@ OBJGRP=${OBJGRP:-0} # the OST object group
 [ -d "$SHARED_DIRECTORY" ] || \
     { skip "SHARED_DIRECTORY should be specified with a shared directory \
 which can be accessable on all of the nodes" && exit 0; }
+[[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
+       skip "Only applicable to ldiskfs-based MDTs" && exit 0
+[[ $(facet_fstype OST) != ldiskfs ]] &&
+       skip "Only applicable to ldiskfs-based OST" && 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.
@@ -121,23 +120,24 @@ get_ost_node() {
 
 # Get the OST target device (given the OST facet name and OST index).
 get_ost_dev() {
-    local node=$1
-    local obdidx=$2
-    local ost_name
-    local ost_dev
-
-    ost_name=$(ostname_from_index $obdidx)
-    ost_dev=$(do_node $node "lctl get_param -n obdfilter.${ost_name}.mntdev")
-    [ ${PIPESTATUS[0]} -ne 0 ] && \
-        echo "failed to find the OST device with index $obdidx on $facet" && \
-        return 1
-
-    if [[ $ost_dev = *loop* ]]; then
-        ost_dev=$(do_node $node "losetup $ost_dev" | \
-                sed -e "s/.*(//" -e "s/).*//")
-    fi
-
-    echo $ost_dev
+       local node=$1
+       local obdidx=$2
+       local ost_name
+       local ost_dev
+
+       ost_name=$(ostname_from_index $obdidx)
+       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
+       fi
+
+       if [[ $ost_dev = *loop* ]]; then
+               ost_dev=$(do_node $node "losetup $ost_dev" | \
+                         sed -e "s/.*(//" -e "s/).*//")
+       fi
+
+       echo $ost_dev
 }
 
 # Get the file names to be duplicated or removed on the MDS.
@@ -161,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"
@@ -172,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.
@@ -213,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
@@ -227,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
@@ -239,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
@@ -259,8 +238,10 @@ fi
 generate_db
 
 # remount filesystem
+ORIG_REFORMAT=$REFORMAT
 REFORMAT=""
 check_and_setup_lustre
+REFORMAT=$ORIG_REFORMAT
 
 # run lfsck
 rc=0
@@ -281,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