Whamcloud - gitweb
LU-3335 scrub: control OI scrub on OST from user space
[fs/lustre-release.git] / lustre / tests / sanity-scrub.sh
index a6754e9..f8bc0d6 100644 (file)
@@ -17,10 +17,6 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
 init_logging
 
-[ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
-       skip "test OI scrub only for ldiskfs" && exit 0
-[[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.2.90) ]] &&
-       skip "Need MDS version at least 2.2.90" && exit 0
 require_dsh_mds || exit 0
 
 SAVED_MDSSIZE=${MDSSIZE}
@@ -30,15 +26,31 @@ SAVED_OSTSIZE=${OSTSIZE}
 MDSSIZE=100000
 OSTSIZE=100000
 
+MOUNT_2=""
 check_and_setup_lustre
+
+[ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
+       skip "test OI scrub only for ldiskfs" && check_and_cleanup_lustre &&
+       exit 0
+[[ $(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
+
+[[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.90) ]] &&
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 1a"
+
 build_test_filter
 
 MDT_DEV="${FSNAME}-MDT0000"
+OST_DEV="${FSNAME}-OST0000"
 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
 START_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_start -M ${MDT_DEV}"
+START_SCRUB_ON_OST="do_facet ost1 $LCTL lfsck_start -M ${OST_DEV}"
 STOP_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
 SHOW_SCRUB="do_facet $SINGLEMDS \
                $LCTL get_param -n osd-ldiskfs.${MDT_DEV}.oi_scrub"
+SHOW_SCRUB_ON_OST="do_facet ost1 \
+               $LCTL get_param -n osd-ldiskfs.${OST_DEV}.oi_scrub"
 MOUNT_OPTS_SCRUB="-o user_xattr"
 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
 
@@ -84,6 +96,46 @@ run_test 0 "Do not auto trigger OI scrub for non-backup/restore case"
 
 test_1a() {
        scrub_prep 0
+       echo "start $SINGLEMDS without disabling OI scrub"
+       start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
+               error "(1) Fail to start MDS!"
+
+       local STATUS=$($SHOW_SCRUB | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "init" ] ||
+               error "(2) Expect 'init', but got '$STATUS'"
+
+       local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
+       [ -z "$FLAGS" ] || error "(3) Expect empty flags, but got '$FLAGS'"
+
+       mount_client $MOUNT || error "(4) Fail to start client!"
+
+       #define OBD_FAIL_OSD_FID_MAPPING                        0x193
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x193
+       # update .lustre OI mapping
+       touch $MOUNT/.lustre
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0
+
+       umount_client $MOUNT || error "(5) Fail to stop client!"
+
+       echo "stop $SINGLEMDS"
+       stop $SINGLEMDS > /dev/null || error "(6) Fail to stop MDS!"
+
+       echo "start $SINGLEMDS with disabling OI scrub"
+       start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
+               error "(7) Fail to start MDS!"
+
+       local STATUS=$($SHOW_SCRUB | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "init" ] ||
+               error "(8) Expect 'init', but got '$STATUS'"
+
+       local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
+       [ "$FLAGS" == "inconsistent" ] ||
+               error "(9) Expect 'inconsistent', but got '$FLAGS'"
+}
+run_test 1a "Auto trigger initial OI scrub when server mounts"
+
+test_1b() {
+       scrub_prep 0
        mds_remove_ois || error "(1) Fail to remove/recreate!"
 
        echo "start $SINGLEMDS without disabling OI scrub"
@@ -100,9 +152,9 @@ test_1a() {
        diff -q $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
                error "(5) File diff failed unexpected!"
 }
-run_test 1a "Trigger OI scrub when MDT mounts for OI files remove/recreate case"
+run_test 1b "Trigger OI scrub when MDT mounts for OI files remove/recreate case"
 
-test_1b() {
+test_1c() {
        local index
 
        # OI files to be removed:
@@ -135,7 +187,7 @@ test_1b() {
                        error "(6) Expect empty flags, but got '$FLAGS'"
        done
 }
-run_test 1b "Auto detect kinds of OI file(s) removed/recreated cases"
+run_test 1c "Auto detect kinds of OI file(s) removed/recreated cases"
 
 test_2() {
        scrub_prep 0
@@ -435,7 +487,7 @@ test_7() {
 run_test 7 "System is available during OI scrub scanning"
 
 test_8() {
-       scrub_prep 0
+       scrub_prep 128
        mds_backup_restore || error "(1) Fail to backup/restore!"
 
        echo "start $SINGLEMDS with disabling OI scrub"
@@ -451,7 +503,7 @@ test_8() {
                error "(4) Expect 'inconsistent', but got '$FLAGS'"
 
        #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
-       do_facet $SINGLEMDS $LCTL set_param fail_val=3
+       do_facet $SINGLEMDS $LCTL set_param fail_val=1
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x190
        $START_SCRUB || error "(5) Fail to start OI scrub!"
 
@@ -504,10 +556,12 @@ test_9() {
        [ "$FLAGS" == "inconsistent" ] ||
                error "(4) Expect 'inconsistent', but got '$FLAGS'"
 
+       local BASE_SPEED1=100
+       local RUN_TIME1=10
        # OI scrub should run with full speed under inconsistent case
-       $START_SCRUB -s 100 || error "(5) Fail to start OI scrub!"
+       $START_SCRUB -s $BASE_SPEED1 || error "(5) Fail to start OI scrub!"
 
-       sleep 10
+       sleep $RUN_TIME1
        STATUS=$($SHOW_SCRUB | awk '/^status/ { print $2 }')
        [ "$STATUS" == "completed" ] ||
                error "(6) Expect 'completed', but got '$STATUS'"
@@ -516,31 +570,49 @@ test_9() {
        [ -z "$FLAGS" ] || error "(7) Expect empty flags, but got '$FLAGS'"
 
        # OI scrub should run with limited speed under non-inconsistent case
-       $START_SCRUB -s 100 -r || error "(8) Fail to start OI scrub!"
+       $START_SCRUB -s $BASE_SPEED1 -r || error "(8) Fail to start OI scrub!"
 
-       sleep 10
+       sleep $RUN_TIME1
        STATUS=$($SHOW_SCRUB | awk '/^status/ { print $2 }')
        [ "$STATUS" == "scanning" ] ||
                error "(9) Expect 'scanning', but got '$STATUS'"
 
-       # Do NOT ignore that there are 1024 pre-fetched items.
-       # So the max speed may be (1024 + 100 * 10) / 10.
-       # And there may be time error, so the max speed may be more large.
        local SPEED=$($SHOW_SCRUB | awk '/^average_speed/ { print $2 }')
-       [ $SPEED -gt 220 ] &&
-               error "(10) Unexpected speed $SPEED, should not more than 220"
+
+       # Do NOT ignore that there are 1024 pre-fetched items. And there
+       # may be time error, normally it should be less than 2 seconds.
+       # We allow another 20% schedule error.
+       local PRE_FETCHED=1024
+       local TIME_DIFF=2
+       # MAX_MARGIN = 1.2 = 12 / 10
+       local MAX_SPEED=$(((PRE_FETCHED + BASE_SPEED1 * \
+                           (RUN_TIME1 + TIME_DIFF)) / RUN_TIME1 * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(10) 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_SCRUB | awk '/^average_speed/ { print $2 }')
-       [ $SPEED -lt 220 ] &&
-               error "(11) Unexpected speed $SPEED, should not less than 220"
-
-       [ $SPEED -gt 300 ] &&
-               error "(12) Unexpected speed $SPEED, should not more than 300"
+       # MIN_MARGIN = 0.8 = 8 / 10
+       local MIN_SPEED=$(((PRE_FETCHED + \
+                           BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
+                           BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
+                          (RUN_TIME1 + RUN_TIME2) * 8 / 10))
+       [ $SPEED -gt $MIN_SPEED ] ||
+               error "(11) Got speed $SPEED, expected more than $MIN_SPEED"
+
+       # MAX_MARGIN = 1.2 = 12 / 10
+       MAX_SPEED=$(((PRE_FETCHED + \
+                     BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
+                     BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
+                    (RUN_TIME1 + RUN_TIME2) * 12 / 10))
+       [ $SPEED -lt $MAX_SPEED ] ||
+               error "(12) Got speed $SPEED, expected less than $MAX_SPEED"
 
        do_facet $SINGLEMDS \
                $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
@@ -572,7 +644,7 @@ test_10a() {
        do_facet $SINGLEMDS \
                $LCTL set_param -n osd-ldiskfs.${MDT_DEV}.auto_scrub 1
        #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
-       do_facet $SINGLEMDS $LCTL set_param fail_val=3
+       do_facet $SINGLEMDS $LCTL set_param fail_val=1
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x190
        diff -q $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
                error "(6) File diff failed unexpected!"
@@ -617,6 +689,7 @@ test_10a() {
 }
 run_test 10a "non-stopped OI scrub should auto restarts after MDS remount (1)"
 
+# test_10b is obsolete, it will be coverded by related sanity-lfsck tests.
 test_10b() {
        scrub_prep 0
        mds_backup_restore || error "(1) Fail to backup/restore!"
@@ -675,11 +748,13 @@ test_10b() {
        FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
        [ -z "$FLAGS" ] || error "(14) Expect empty flags, but got '$FLAGS'"
 }
-run_test 10b "non-stopped OI scrub should auto restarts after MDS remount (2)"
+#run_test 10b "non-stopped OI scrub should auto restarts after MDS remount (2)"
 
 test_11() {
        echo "stopall"
        stopall > /dev/null
+       echo "formatall"
+       formatall > /dev/null
        echo "setupall"
        setupall > /dev/null
 
@@ -690,6 +765,9 @@ test_11() {
 
        createmany -o $MOUNT/$tname/f $CREATED || error "(2) Fail to create!"
 
+       cleanup_mount $MOUNT
+       do_facet $SINGLEMDS $LCTL clear
+       start_full_debug_logging
        # reset OI scrub start point by force
        $START_SCRUB -r || error "(3) Fail to start OI scrub!"
        sleep 3
@@ -701,10 +779,10 @@ test_11() {
        local SKIPPED=$($SHOW_SCRUB | awk '/^noscrub/ { print $2 }')
        # notice we're creating a new llog for every OST on every startup
        # new features can make this even less stable, so we only check
-       # that the number of skipped files is less than 1.5x the number of files
-       local MAXIMUM=$((CREATED * 3 / 2))
+       # that the number of skipped files is less than 2x the number of files
+       local MAXIMUM=$((CREATED * 2))
        local MINIMUM=$((CREATED + 1)) # files + directory
-       [ $SKIPPED -ge $MAXIMUM -o $SKIPPED -lt $MINIMUM] &&
+       [ $SKIPPED -ge $MAXIMUM -o $SKIPPED -lt $MINIMUM ] &&
        error "(5) Expect [ $MINIMUM , $MAXIMUM ) objects skipped, got $SKIPPED"
 
        # reset OI scrub start point by force
@@ -719,17 +797,84 @@ test_11() {
        [ $SKIPPED -eq 0 ] ||
                error "(8) Expect 0 objects skipped, but got $SKIPPED"
 
+       stop_full_debug_logging
+       restore_mount $MOUNT || error "(9) Fail to start client!"
        rm -rf $MOUNT/$tname > /dev/null
 }
 run_test 11 "OI scrub skips the new created objects only once"
 
-# restore the ${facet}_MKFS_OPTS variables
-for facet in MGS MDS OST; do
-       opts=SAVED_${facet}_MKFS_OPTS
-       if [[ -n ${!opts} ]]; then
-               eval ${facet}_MKFS_OPTS=\"${!opts}\"
-       fi
-done
+test_12() {
+       echo "stopall"
+       stopall > /dev/null
+       echo "formatall"
+       formatall > /dev/null
+       echo "setupall"
+       setupall > /dev/null
+
+       mkdir -p $DIR/$tdir
+       $SETSTRIPE -c 1 -i 0 $DIR/$tdir
+
+       #define OBD_FAIL_OSD_COMPAT_INVALID_ENTRY               0x195
+       do_facet ost1 $LCTL set_param fail_loc=0x195
+       createmany -o $DIR/$tdir/f 1000
+
+       echo "stopall"
+       stopall > /dev/null
+       echo "setupall"
+       setupall > /dev/null
+
+       do_facet ost1 $LCTL set_param fail_loc=0
+       local STATUS=$($SHOW_SCRUB_ON_OST | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "init" ] ||
+               error "(1) Expect 'init', but got '$STATUS'"
+
+       ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(2) ls should fail"
+
+       sleep 3
+       local STATUS=$($SHOW_SCRUB_ON_OST | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "completed" ] ||
+               error "(3) Expect 'completed', but got '$STATUS'"
+
+       ls -ail $DIR/$tdir > /dev/null 2>&1 || error "(4) ls should succeed"
+}
+run_test 12 "OI scrub can rebuild invalid /O entries"
+
+test_13() {
+       echo "stopall"
+       stopall > /dev/null
+       echo "formatall"
+       formatall > /dev/null
+       echo "setupall"
+       setupall > /dev/null
+
+       mkdir -p $DIR/$tdir
+       $SETSTRIPE -c 1 -i 0 $DIR/$tdir
+
+       #define OBD_FAIL_OSD_COMPAT_NO_ENTRY            0x196
+       do_facet ost1 $LCTL set_param fail_loc=0x196
+       createmany -o $DIR/$tdir/f 1000
+       do_facet ost1 $LCTL set_param fail_loc=0
+
+       echo "stopall"
+       stopall > /dev/null
+       echo "setupall"
+       setupall > /dev/null
+
+       local STATUS=$($SHOW_SCRUB_ON_OST | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "init" ] ||
+               error "(1) Expect 'init', but got '$STATUS'"
+
+       ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(2) ls should fail"
+
+       $START_SCRUB_ON_OST || error "(3) Fail to start OI scrub on OST!"
+       sleep 3
+       local STATUS=$($SHOW_SCRUB_ON_OST | awk '/^status/ { print $2 }')
+       [ "$STATUS" == "completed" ] ||
+               error "(4) Expect 'completed', but got '$STATUS'"
+
+       ls -ail $DIR/$tdir > /dev/null 2>&1 || error "(5) ls should succeed"
+}
+run_test 13 "OI scrub can rebuild missed /O entries"
 
 # restore MDS/OST size
 MDSSIZE=${SAVED_MDSSIZE}