Whamcloud - gitweb
LU-2915 lfsck: LFSCK 1.5 technical debts (3)
[fs/lustre-release.git] / lustre / tests / sanity-lfsck.sh
index 5e454d6..81cea0f 100644 (file)
@@ -30,6 +30,11 @@ MDSSIZE=100000
 OSTSIZE=100000
 
 check_and_setup_lustre
+
+[[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.2.90) ]] &&
+        skip "Need MDS version at least 2.2.90" && check_and_cleanup_lustre &&
+        exit 0
+
 build_test_filter
 
 $LCTL set_param debug=+lfsck > /dev/null || true
@@ -52,21 +57,21 @@ lfsck_prep() {
        echo "formatall"
        formatall > /dev/null
 
+       echo "setupall"
+       setupall > /dev/null
+
        if [ ! -z $igif ]; then
                #define OBD_FAIL_FID_IGIF       0x1504
                do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
        fi
 
-       echo "setupall"
-       setupall > /dev/null
-
        echo "preparing... ${nfiles} * ${ndirs} files will be created."
        mkdir -p $DIR/$tdir
-       cp $LUSTRE/tests/*.sh $DIR/$tdir/
-       for ((i=0; i<${ndirs}; i++)); do
+       cp $LUSTRE/tests/*.sh $DIR/
+       for ((i = 0; i < ${ndirs}; i++)); do
                mkdir $DIR/$tdir/d${i}
                touch $DIR/$tdir/f${i}
-               for ((j=0; j<${nfiles}; j++)); do
+               for ((j = 0; j < ${nfiles}; j++)); do
                        touch $DIR/$tdir/d${i}/f${j}
                done
                mkdir $DIR/$tdir/e${i}
@@ -279,6 +284,45 @@ test_2b()
 }
 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
 
+test_2c()
+{
+       lfsck_prep 1 1
+       echo "start $SINGLEMDS"
+       start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
+               error "(1) Fail to start MDS!"
+
+       mount_client $MOUNT || error "(2) Fail to start client!"
+
+       #define OBD_FAIL_LFSCK_LINKEA_MORE2     0x1605
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1605
+       touch $DIR/$tdir/dummy
+
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0
+       umount_client $MOUNT
+       $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
+
+       sleep 3
+       local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "completed" ] ||
+               error "(4) Expect 'completed', but got '$STATUS'"
+
+       local repaired=$($SHOW_NAMESPACE |
+                        awk '/^updated_phase2/ { print $2 }')
+       [ $repaired -eq 1 ] ||
+               error "(5) Fail to repair crashed linkEA: $repaired"
+
+       mount_client $MOUNT || error "(6) Fail to start client!"
+
+       stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
+               error "(7) Fail to stat $DIR/$tdir/dummy"
+
+       local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
+       local dummyname=$($LFS fid2path $DIR $dummyfid)
+       [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
+               error "(8) Fail to repair linkEA: $dummyfid $dummyname"
+}
+run_test 2c "LFSCK can find out and remove repeated linkEA entry"
+
 test_4()
 {
        lfsck_prep 3 3
@@ -480,7 +524,7 @@ test_6b() {
        local POSITION1=$($SHOW_NAMESPACE |
                          awk '/^latest_start_position/ { print $4 }')
        if [ $POSITION0 -gt $POSITION1 ]; then
-               [ $POSITION1 -eq 0 -a $POSITINO0 -eq $((POSITION1 + 1)) ] ||
+               [ $POSITION1 -eq 0 -a $POSITION0 -eq $((POSITION1 + 1)) ] ||
                error "(7) Expect larger than: $POSITION0, but got $POSITION1"
        fi
 
@@ -542,7 +586,7 @@ test_7b()
 
        #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
-       for ((i=0; i<10; i++)); do
+       for ((i = 0; i < 20; i++)); do
                touch $DIR/$tdir/dummy${i}
        done
 
@@ -595,7 +639,7 @@ test_8()
 
        #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
-       for ((i=0; i<5; i++)); do
+       for ((i = 0; i < 5; i++)); do
                touch $DIR/$tdir/dummy${i}
        done
 
@@ -717,32 +761,48 @@ test_9a() {
        [ "$STATUS" == "init" ] ||
                error "(2) Expect 'init', but got '$STATUS'"
 
-       $START_NAMESPACE -s 100 || error "(3) Fail to start LFSCK!"
+       local BASE_SPEED1=100
+       local RUN_TIME1=10
+       $START_NAMESPACE -s $BASE_SPEED1 || error "(3) Fail to start LFSCK!"
 
-       sleep 10
+       sleep $RUN_TIME1
        STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
        [ "$STATUS" == "scanning-phase1" ] ||
                error "(3) Expect 'scanning-phase1', but got '$STATUS'"
 
        local SPEED=$($SHOW_NAMESPACE |
                      awk '/^average_speed_phase1/ { print $2 }')
-       # (100 * (10 + 1)) / 10 = 110
-       [ $SPEED -lt 120 ] ||
-               error "(4) Unexpected speed $SPEED, should not more than 120"
+
+       # There may be time error, normally it should be less than 2 seconds.
+       # We allow another 20% schedule error.
+       local TIME_DIFF=2
+       # MAX_MARGIN = 1.2 = 12 / 10
+       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
+                          RUN_TIME1 * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(4) Got speed $SPEED, expected less than $MAX_SPEED"
 
        # adjust speed limit
+       local BASE_SPEED2=300
+       local RUN_TIME2=10
        do_facet $SINGLEMDS \
-               $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 300
-       sleep 10
+               $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
+       sleep $RUN_TIME2
 
        SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
-       # (100 * (10 - 1) + 300 * (10 - 1)) / 20 = 180
-       [ $SPEED -lt 170 ] &&
-               error "(5) Unexpected speed $SPEED, should not less than 170"
-
-       # (100 * (10 + 1) + 300 * (10 + 1)) / 20 = 220
-       [ $SPEED -lt 230 ] ||
-               error "(6) Unexpected speed $SPEED, should not more than 230"
+       # MIN_MARGIN = 0.8 = 8 / 10
+       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
+                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
+                          (RUN_TIME1 + RUN_TIME2) * 8 / 10))
+       [ $SPEED -gt $MIN_SPEED ] ||
+               error "(5) Got speed $SPEED, expected more than $MIN_SPEED"
+
+       # MAX_MARGIN = 1.2 = 12 / 10
+       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
+                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
+                    (RUN_TIME1 + RUN_TIME2) * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(6) Got speed $SPEED, expected less than $MAX_SPEED"
 
        do_facet $SINGLEMDS \
                $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
@@ -769,10 +829,10 @@ test_9b() {
        echo "Another preparing... 50 * 50 files (with error) will be created."
        #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
-       for ((i=0; i<50; i++)); do
+       for ((i = 0; i < 50; i++)); do
                mkdir -p $DIR/$tdir/d${i}
                touch $DIR/$tdir/f${i}
-               for ((j=0; j<50; j++)); do
+               for ((j = 0; j < 50; j++)); do
                        touch $DIR/$tdir/d${i}/f${j}
                done
        done
@@ -791,32 +851,48 @@ test_9b() {
                error "(5) Expect 'stopped', but got '$STATUS'"
 
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0
-       $START_NAMESPACE -s 50 || error "(6) Fail to start LFSCK!"
 
-       sleep 10
+       local BASE_SPEED1=50
+       local RUN_TIME1=10
+       $START_NAMESPACE -s $BASE_SPEED1 || error "(6) Fail to start LFSCK!"
+
+       sleep $RUN_TIME1
        STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
        [ "$STATUS" == "scanning-phase2" ] ||
                error "(7) Expect 'scanning-phase2', but got '$STATUS'"
 
        local SPEED=$($SHOW_NAMESPACE |
                      awk '/^average_speed_phase2/ { print $2 }')
-       # (50 * (10 + 1)) / 10 = 55
-       [ $SPEED -lt 60 ] ||
-               error "(8) Unexpected speed $SPEED, should not more than 60"
+       # There may be time error, normally it should be less than 2 seconds.
+       # We allow another 20% schedule error.
+       local TIME_DIFF=2
+       # MAX_MARGIN = 1.2 = 12 / 10
+       local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
+                         RUN_TIME1 * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(8) Got speed $SPEED, expected less than $MAX_SPEED"
 
        # adjust speed limit
+       local BASE_SPEED2=150
+       local RUN_TIME2=10
        do_facet $SINGLEMDS \
-               $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 150
-       sleep 10
+               $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
+       sleep $RUN_TIME2
 
        SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
-       # (50 * (10 - 1) + 150 * (10 - 1)) / 20 = 90
-       [ $SPEED -lt 85 ] &&
-               error "(9) Unexpected speed $SPEED, should not less than 85"
-
-       # (50 * (10 + 1) + 150 * (10 + 1)) / 20 = 110
-       [ $SPEED -lt 115 ] ||
-               error "(10) Unexpected speed $SPEED, should not more than 115"
+       # MIN_MARGIN = 0.8 = 8 / 10
+       local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
+                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
+                          (RUN_TIME1 + RUN_TIME2) * 8 / 10))
+       [ $SPEED -gt $MIN_SPEED ] ||
+               error "(9) Got speed $SPEED, expected more than $MIN_SPEED"
+
+       # MAX_MARGIN = 1.2 = 12 / 10
+       MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
+                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
+                    (RUN_TIME1 + RUN_TIME2) * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(10) Got speed $SPEED, expected less than $MAX_SPEED"
 
        do_facet $SINGLEMDS \
                $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
@@ -838,20 +914,20 @@ test_10()
 
        #define OBD_FAIL_LFSCK_LINKEA_CRASH     0x1603
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
-       for ((i=0; i<1000; i=$((i+2)))); do
+       for ((i = 0; i < 1000; i = $((i+2)))); do
                mkdir -p $DIR/$tdir/d${i}
                touch $DIR/$tdir/f${i}
-               for ((j=0; j<5; j++)); do
+               for ((j = 0; j < 5; j++)); do
                        touch $DIR/$tdir/d${i}/f${j}
                done
        done
 
        #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
-       for ((i=1; i<1000; i=$((i+2)))); do
+       for ((i = 1; i < 1000; i = $((i+2)))); do
                mkdir -p $DIR/$tdir/d${i}
                touch $DIR/$tdir/f${i}
-               for ((j=0; j<5; j++)); do
+               for ((j = 0; j < 5; j++)); do
                        touch $DIR/$tdir/d${i}/f${j}
                done
        done