Whamcloud - gitweb
LU-16036 test: make sanity-lfsck 15d more robust
[fs/lustre-release.git] / lustre / tests / sanity-lfsck.sh
index 87a96d1..960b4d3 100644 (file)
@@ -10,7 +10,7 @@ ONLY=${ONLY:-"$*"}
 
 LUSTRE=${LUSTRE:-$(dirname $0)/..}
 . $LUSTRE/tests/test-framework.sh
-init_test_env $@
+init_test_env "$@"
 init_logging
 
 # bug number for skipped test:
@@ -947,7 +947,7 @@ run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
 namespace_error()
 {
        $SHOW_NAMESPACE
-       error $@
+       error "$@"
 }
 
 test_8()
@@ -1174,7 +1174,7 @@ test_9a() {
        # We allow another 20% schedule error.
        local TIME_DIFF=2
        # MAX_MARGIN = 1.3 = 13 / 10
-       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
+       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) /
                           RUN_TIME1 * 13 / 10))
        [ $SPEED -lt $MAX_SPEED ] || {
                $SHOW_LAYOUT
@@ -1191,8 +1191,8 @@ test_9a() {
 
        SPEED=$($SHOW_LAYOUT | awk '/^average_speed_phase1/ { print $2 }')
        # MIN_MARGIN = 0.7 = 7 / 10
-       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
-                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
+       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) +
+                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) /
                           (RUN_TIME1 + RUN_TIME2) * 7 / 10))
        [ $SPEED -gt $MIN_SPEED ] || {
                if [ $mds1_FSTYPE != ldiskfs ]; then
@@ -1205,8 +1205,8 @@ test_9a() {
        }
 
        # MAX_MARGIN = 1.3 = 13 / 10
-       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
-                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
+       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) +
+                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) /
                     (RUN_TIME1 + RUN_TIME2) * 13 / 10))
        [ $SPEED -lt $MAX_SPEED ] || {
                $SHOW_LAYOUT
@@ -1272,7 +1272,7 @@ test_9b() {
        # We allow another 20% schedule error.
        local TIME_DIFF=2
        # MAX_MARGIN = 1.3 = 13 / 10
-       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
+       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) /
                          RUN_TIME1 * 13 / 10))
        [ $SPEED -lt $MAX_SPEED ] || {
                $SHOW_NAMESPACE
@@ -1289,8 +1289,8 @@ test_9b() {
 
        SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
        # MIN_MARGIN = 0.7 = 7 / 10
-       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
-                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
+       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) +
+                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) /
                           (RUN_TIME1 + RUN_TIME2) * 7 / 10))
        [ $SPEED -gt $MIN_SPEED ] || {
                if [ $mds1_FSTYPE != ldiskfs ]; then
@@ -1303,8 +1303,8 @@ test_9b() {
        }
 
        # MAX_MARGIN = 1.3 = 13 / 10
-       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
-                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
+       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) +
+                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) /
                     (RUN_TIME1 + RUN_TIME2) * 13 / 10))
        [ $SPEED -lt $MAX_SPEED ] || {
                $SHOW_NAMESPACE
@@ -1988,6 +1988,53 @@ test_15c() {
 }
 run_test 15c "LFSCK can repair unmatched MDT-object/OST-object pairs (3)"
 
+test_15d() {
+       (( $MDSCOUNT > 1 )) || skip "needs >= 2 MDTs"
+
+       check_mount_and_prep
+       rm -rf $DIR/$tdir
+       $LFS mkdir -c -1 $DIR/$tdir || error "create $tdir failed"
+       $LFS setdirstripe -D -i -1 -c 1 $DIR/$tdir ||
+               error "setdirstripe failed"
+
+       createmany -o $DIR/$tdir/f 100 || error "create sub files failed"
+       createmany -d $DIR/$tdir/s 100 || error "create sub dirs failed"
+
+       echo "Migrate $DIR/$tdir to MDT1"
+       $LFS migrate -m 1 $DIR/$tdir &
+       pid=$!
+
+       sleep 2
+       # fail sub transactions on random MDTs, which may cause some file
+       # inaccessible
+       #define OBD_FAIL_OUT_EIO                0x1709
+       for ((i = 0; i < $MDSCOUNT; i++)); do
+               do_facet mds$i $LCTL set_param fail_loc=0x1709
+               sleep 0.1
+               do_facet mds$i $LCTL set_param fail_loc=0
+       done
+
+       wait $pid
+
+       # LFSCK can't fully fix migrating directories, and may leave some
+       # files inaccessible, but it shouldn't cause crash
+       $START_NAMESPACE -A -r ||
+               error "Fail to start LFSCK for namespace"
+
+       wait_all_targets_blocked namespace completed 1
+
+       # resume migration may fail because some file may be inaccessible, but
+       # it shouldn't cause crash
+       $LFS migrate -m 1 $DIR/$tdir
+
+       # rm $tdir to avoid cleanup failure in the end
+       rm -rf $DIR/$tdir/*
+       $LFS rm_entry $DIR/$tdir/*
+       rm -rf $DIR/$tdir
+       REFORMAT="yes" cleanup_and_setup_lustre
+}
+run_test 15d "LFSCK don't crash upon dir migration failure"
+
 test_16() {
        (( $MDS1_VERSION > $(version_code 2.5.55) )) ||
                skip "MDS older than 2.5.55, LU-3594"