3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 ALWAYS_EXCEPT="$SANITY_SCRUB_EXCEPT"
11 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
15 . $LUSTRE/tests/test-framework.sh
17 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
20 require_dsh_mds || exit 0
22 SAVED_MDSSIZE=${MDSSIZE}
23 SAVED_OSTSIZE=${OSTSIZE}
24 SAVED_OSTCOUNT=${OSTCOUNT}
25 # use small MDS + OST size to speed formatting time
26 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
27 # 200M MDT device can guarantee uninitialized groups during the OI scrub
30 # no need too much OSTs, to reduce the format/start/stop overhead
31 [ $OSTCOUNT -gt 4 ] && OSTCOUNT=4
35 # build up a clean test environment.
39 [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
40 skip "test OI scrub only for ldiskfs" && check_and_cleanup_lustre &&
42 [ $(facet_fstype ost1) != "ldiskfs" ] &&
43 skip "test OI scrub only for ldiskfs" && check_and_cleanup_lustre &&
45 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.2.90) ]] &&
46 skip "Need MDS version at least 2.2.90" && check_and_cleanup_lustre &&
49 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.90) ]] &&
50 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 1a"
52 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.6.50) ]] &&
53 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4"
55 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.4.1) ]] &&
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 15"
58 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.90) ]] &&
59 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.50) ]] &&
60 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 15"
62 [[ $(lustre_version_code ost1) -lt $(version_code 2.4.50) ]] &&
63 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 12 13 14"
65 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] &&
70 MDT_DEV="${FSNAME}-MDT0000"
71 OST_DEV="${FSNAME}-OST0000"
72 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
78 # use "lfsck_start -A" when we no longer need testing interop
79 for n in $(seq $MDSCOUNT); do
80 do_facet mds$n $LCTL lfsck_start -M $(facet_svc mds$n) \
82 error "($error_id) Failed to start OI scrub on mds$n"
90 # use "lfsck_stop -A" when we no longer need testing interop
91 for n in $(seq $MDSCOUNT); do
92 do_facet mds$n $LCTL lfsck_stop -M $(facet_svc mds$n) ||
93 error "($error_id) Failed to stop OI scrub on mds$n"
100 do_facet mds$n $LCTL get_param -n \
101 osd-ldiskfs.$(facet_svc mds$n).oi_scrub
104 START_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_start -M ${MDT_DEV} $SCRUB_ONLY"
105 START_SCRUB_ON_OST="do_facet ost1 $LCTL lfsck_start -M ${OST_DEV} $SCRUB_ONLY"
106 STOP_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
107 SHOW_SCRUB="do_facet $SINGLEMDS \
108 $LCTL get_param -n osd-ldiskfs.${MDT_DEV}.oi_scrub"
109 SHOW_SCRUB_ON_OST="do_facet ost1 \
110 $LCTL get_param -n osd-ldiskfs.${OST_DEV}.oi_scrub"
111 MOUNT_OPTS_SCRUB="-o user_xattr"
112 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
120 echo "preparing... $(date)"
121 for n in $(seq $MDSCOUNT); do
122 echo "creating $nfiles files on mds$n"
123 if [ $n -eq 1 ]; then
124 mkdir $DIR/$tdir/mds$n ||
125 error "Failed to create directory mds$n"
127 $LFS mkdir -i $((n - 1)) $DIR/$tdir/mds$n ||
128 error "Failed to create remote directory mds$n"
130 cp $LUSTRE/tests/*.sh $DIR/$tdir/mds$n ||
131 error "Failed to copy files to mds$n"
132 mkdir -p $DIR/$tdir/mds$n/d_$tfile ||
133 error "mkdir failed on mds$n"
134 createmany -m $DIR/$tdir/mds$n/d_$tfile/f 2 > \
135 /dev/null || error "create failed on mds$n"
136 if [[ $nfiles -gt 0 ]]; then
137 createmany -m $DIR/$tdir/mds$n/$tfile $nfiles > \
138 /dev/null || error "createmany failed on mds$n"
141 echo "prepared $(date)."
142 cleanup_mount $MOUNT > /dev/null || error "Fail to stop client!"
143 for n in $(seq $MDSCOUNT); do
145 stop mds$n > /dev/null || error "Fail to stop MDS$n!"
154 for n in $(seq $MDSCOUNT); do
155 start mds$n $(mdsdevname $n) $opts >/dev/null ||
156 error "($error_id) Failed to start mds$n"
164 for n in $(seq $MDSCOUNT); do
165 echo "stopping mds$n"
166 stop mds$n >/dev/null ||
167 error "($error_id) Failed to stop mds$n"
171 scrub_check_status() {
176 for n in $(seq $MDSCOUNT); do
177 wait_update_facet mds$n "$LCTL get_param -n \
178 osd-ldiskfs.$(facet_svc mds$n).oi_scrub |
179 awk '/^status/ { print \\\$2 }'" "$expected" 6 ||
180 error "($error_id) Expected '$expected' on mds$n"
184 scrub_check_flags() {
190 for n in $(seq $MDSCOUNT); do
191 actual=$(do_facet mds$n $LCTL get_param -n \
192 osd-ldiskfs.$(facet_svc mds$n).oi_scrub |
193 awk '/^flags/ { print $2 }')
194 if [ "$actual" != "$expected" ]; then
195 error "($error_id) Expected '$expected' on mds$n, but" \
201 scrub_check_params() {
207 for n in $(seq $MDSCOUNT); do
208 actual=$(do_facet mds$n $LCTL get_param -n \
209 osd-ldiskfs.$(facet_svc mds$n).oi_scrub |
210 awk '/^param/ { print $2 }')
211 if [ "$actual" != "$expected" ]; then
212 error "($error_id) Expected '$expected' on mds$n, but" \
218 scrub_check_repaired() {
224 for n in $(seq $MDSCOUNT); do
225 actual=$(do_facet mds$n $LCTL get_param -n \
226 osd-ldiskfs.$(facet_svc mds$n).oi_scrub |
227 awk '/^updated/ { print $2 }')
229 if [ $expected -eq 0 -a $actual -ne 0 ]; then
230 error "($error_id) Expected no repaired on mds$n, but" \
234 if [ $expected -ne 0 -a $actual -lt $expected ]; then
235 error "($error_id) Expected '$expected' on mds$n, but" \
245 for n in $(seq $MDSCOUNT); do
246 diff -q $LUSTRE/tests/test-framework.sh \
247 $DIR/$tdir/mds$n/test-framework.sh ||
248 error "($error_id) File data check failed"
252 scrub_check_data2() {
257 for n in $(seq $MDSCOUNT); do
258 diff -q $LUSTRE/tests/$filename \
259 $DIR/$tdir/mds$n/$filename ||
260 error "($error_id) File data check failed"
269 for n in $(seq $MDSCOUNT); do
270 mds_remove_ois mds$n $index ||
271 error "($error_id) Failed to remove OI .$index on mds$n"
275 scrub_backup_restore() {
280 for n in $(seq $MDSCOUNT); do
281 mds_backup_restore mds$n $igif ||
282 error "(error_id) Backup/restore on mds$n failed"
286 scrub_enable_auto() {
287 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
288 osd-ldiskfs.*.auto_scrub=1
292 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.6.50) ]] &&
297 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
298 osd-ldiskfs.*.full_scrub_ratio=$ratio
301 full_scrub_threshold_rate() {
302 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.6.50) ]] &&
307 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
308 osd-ldiskfs.*.full_scrub_threshold_rate=$rate
313 echo "starting MDTs without disabling OI scrub"
314 scrub_start_mds 1 "$MOUNT_OPTS_SCRUB"
315 scrub_check_status 2 init
316 scrub_check_flags 3 ""
317 mount_client $MOUNT || error "(4) Fail to start client!"
320 run_test 0 "Do not auto trigger OI scrub for non-backup/restore case"
324 echo "start $SINGLEMDS without disabling OI scrub"
325 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
326 error "(1) Fail to start MDS!"
328 local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
329 [ -z "$FLAGS" ] || error "(3) Expect empty flags, but got '$FLAGS'"
331 mount_client $MOUNT || error "(4) Fail to start client!"
332 #define OBD_FAIL_OSD_FID_MAPPING 0x193
333 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x193
334 # update .lustre OI mapping
336 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
337 umount_client $MOUNT || error "(5) Fail to stop client!"
339 echo "stop $SINGLEMDS"
340 stop $SINGLEMDS > /dev/null || error "(6) Fail to stop MDS!"
342 echo "start $SINGLEMDS with disabling OI scrub"
343 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
344 error "(7) Fail to start MDS!"
346 local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
347 [ "$FLAGS" == "inconsistent" ] ||
348 error "(9) Expect 'inconsistent', but got '$FLAGS'"
350 run_test 1a "Auto trigger initial OI scrub when server mounts"
355 echo "start MDTs without disabling OI scrub"
356 scrub_start_mds 2 "$MOUNT_OPTS_SCRUB"
357 scrub_check_status 3 completed
358 mount_client $MOUNT || error "(4) Fail to start client!"
361 run_test 1b "Trigger OI scrub when MDT mounts for OI files remove/recreate case"
366 # OI files to be removed:
368 # idx 2: oi.16.{2,4,8,16,32}
369 # idx 3: oi.16.{3,9,27}
370 for index in 0 2 3; do
372 scrub_remove_ois 1 $index
373 echo "start MDTs with OI scrub disabled"
374 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
375 scrub_check_flags 3 recreated
377 scrub_check_status 5 completed
378 scrub_check_flags 6 ""
381 run_test 1c "Auto detect kinds of OI file(s) removed/recreated cases"
385 scrub_backup_restore 1
386 echo "starting MDTs without disabling OI scrub"
387 scrub_start_mds 2 "$MOUNT_OPTS_SCRUB"
388 scrub_check_status 3 completed
389 mount_client $MOUNT || error "(4) Fail to start client!"
392 run_test 2 "Trigger OI scrub when MDT mounts for backup/restore case"
394 # test_3 is obsolete, it will be covered by test_5.
396 formatall > /dev/null
400 scrub_backup_restore 1
401 echo "starting MDTs with OI scrub disabled"
402 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
403 scrub_check_status 3 init
404 scrub_check_flags 4 inconsistent
406 #run_test 3 "Do not trigger OI scrub when MDT mounts if 'noscrub' specified"
410 scrub_backup_restore 1
411 echo "starting MDTs with OI scrub disabled"
412 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
413 scrub_check_flags 4 inconsistent
414 mount_client $MOUNT || error "(5) Fail to start client!"
420 scrub_check_status 7 completed
421 scrub_check_flags 8 ""
424 for n in $(seq $MDSCOUNT); do
425 updated0[$n]=$(scrub_status $n |
426 awk '/^sf_items_updated_prior/ { print $2 }')
429 scrub_check_data2 sanity-scrub.sh 9
433 for n in $(seq $MDSCOUNT); do
434 updated1[$n]=$(scrub_status $n |
435 awk '/^sf_items_updated_prior/ { print $2 }')
436 [ ${updated0[$n]} -eq ${updated1[$n]} ] ||
437 error "(10) NOT auto trigger full scrub as expected"
440 run_test 4a "Auto trigger OI scrub if bad OI mapping was found (1)"
444 scrub_backup_restore 1
445 echo "starting MDTs with OI scrub disabled"
446 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
447 scrub_check_flags 4 inconsistent
448 mount_client $MOUNT || error "(5) Fail to start client!"
451 full_scrub_threshold_rate 10000
455 scrub_check_status 7 completed
456 scrub_check_flags 8 ""
459 for n in $(seq $MDSCOUNT); do
460 updated0[$n]=$(scrub_status $n |
461 awk '/^sf_items_updated_prior/ { print $2 }')
464 scrub_check_data2 sanity-scrub.sh 9
467 scrub_check_status 10 completed
468 scrub_check_flags 11 ""
471 for n in $(seq $MDSCOUNT); do
472 updated1[$n]=$(scrub_status $n |
473 awk '/^sf_items_updated_prior/ { print $2 }')
474 [ ${updated0[$n]} -lt ${updated1[$n]} ] ||
475 error "(12) Auto trigger full scrub unexpectedly"
478 for n in $(seq $MDSCOUNT); do
479 ls -l $DIR/$tdir/mds$n/*.sh > /dev/null ||
480 error "(13) fail to ls"
484 scrub_check_status 14 completed
485 scrub_check_flags 15 ""
487 for n in $(seq $MDSCOUNT); do
488 updated0[$n]=$(scrub_status $n |
489 awk '/^sf_items_updated_prior/ { print $2 }')
490 [ ${updated0[$n]} -gt ${updated1[$n]} ] ||
491 error "(16) Auto trigger full scrub unexpectedly"
494 for n in $(seq $MDSCOUNT); do
495 ls -l $DIR/$tdir/mds$n/d_${tfile}/ || error "(17) fail to ls"
499 for n in $(seq $MDSCOUNT); do
500 updated1[$n]=$(scrub_status $n |
501 awk '/^sf_items_updated_prior/ { print $2 }')
502 [ ${updated0[$n]} -eq ${updated1[$n]} ] ||
503 error "(18) NOT auto trigger full scrub as expected"
506 run_test 4b "Auto trigger OI scrub if bad OI mapping was found (2)"
510 scrub_backup_restore 1
511 echo "starting MDTs with OI scrub disabled"
512 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
513 scrub_check_flags 4 inconsistent
514 mount_client $MOUNT || error "(5) Fail to start client!"
517 full_scrub_threshold_rate 20
521 scrub_check_status 7 completed
522 scrub_check_flags 8 ""
525 for n in $(seq $MDSCOUNT); do
526 updated0[$n]=$(scrub_status $n |
527 awk '/^sf_items_updated_prior/ { print $2 }')
530 scrub_check_data2 sanity-scrub.sh 9
533 scrub_check_status 10 completed
534 scrub_check_flags 11 ""
537 for n in $(seq $MDSCOUNT); do
538 updated1[$n]=$(scrub_status $n |
539 awk '/^sf_items_updated_prior/ { print $2 }')
540 [ ${updated0[$n]} -lt ${updated1[$n]} ] ||
541 error "(12) Auto trigger full scrub unexpectedly"
544 for n in $(seq $MDSCOUNT); do
545 ls -l $DIR/$tdir/mds$n/*.sh > /dev/null ||
546 error "(13) fail to ls"
550 scrub_check_status 14 completed
551 scrub_check_flags 15 ""
553 for n in $(seq $MDSCOUNT); do
554 updated0[$n]=$(scrub_status $n |
555 awk '/^sf_items_updated_prior/ { print $2 }')
556 [ ${updated0[$n]} -gt ${updated1[$n]} ] ||
557 error "(16) Auto trigger full scrub unexpectedly"
560 for n in $(seq $MDSCOUNT); do
561 ls -l $DIR/$tdir/mds$n/${tfile}1 || error "(17) fail to ls"
565 for n in $(seq $MDSCOUNT); do
566 updated1[$n]=$(scrub_status $n |
567 awk '/^sf_items_updated_prior/ { print $2 }')
568 [ ${updated0[$n]} -eq ${updated1[$n]} ] ||
569 error "(18) NOT auto trigger full scrub as expected"
572 run_test 4c "Auto trigger OI scrub if bad OI mapping was found (3)"
575 formatall > /dev/null
579 scrub_backup_restore 1
580 echo "starting MDTs with OI scrub disabled"
581 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
582 scrub_check_status 3 init
583 scrub_check_flags 4 inconsistent
584 mount_client $MOUNT || error "(5) Fail to start client!"
587 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
588 do_nodes $(comma_list $(mdts_nodes)) \
589 $LCTL set_param fail_val=3 fail_loc=0x190
593 umount_client $MOUNT || error "(7) Fail to stop client!"
594 scrub_check_status 8 scanning
596 #define OBD_FAIL_OSD_SCRUB_CRASH 0x191
597 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x191
602 do_nodes $(comma_list $(mdts_nodes)) \
603 $LCTL set_param fail_loc=0 fail_val=0
605 echo "starting MDTs with OI scrub disabled"
606 scrub_start_mds 10 "$MOUNT_OPTS_NOSCRUB"
607 scrub_check_status 11 crashed
610 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
611 do_nodes $(comma_list $(mdts_nodes)) \
612 $LCTL set_param fail_val=3 fail_loc=0x190
614 echo "starting MDTs without disabling OI scrub"
615 scrub_start_mds 13 "$MOUNT_OPTS_SCRUB"
616 scrub_check_status 14 scanning
618 #define OBD_FAIL_OSD_SCRUB_FATAL 0x192
619 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x192
621 scrub_check_status 15 failed
622 mount_client $MOUNT || error "(16) Fail to start client!"
625 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
626 do_nodes $(comma_list $(mdts_nodes)) \
627 $LCTL set_param fail_val=3 fail_loc=0x190
630 for n in $(seq $MDSCOUNT); do
631 stat $DIR/$tdir/mds$n/${tfile}800 ||
632 error "(17) Failed to stat mds$n/${tfile}800"
635 scrub_check_status 18 scanning
637 do_nodes $(comma_list $(mdts_nodes)) \
638 $LCTL set_param fail_loc=0 fail_val=0
640 scrub_check_status 19 completed
641 scrub_check_flags 20 ""
643 run_test 5 "OI scrub state machine"
647 scrub_backup_restore 1
648 echo "starting MDTs with OI scrub disabled"
649 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
650 scrub_check_flags 4 inconsistent
651 mount_client $MOUNT || error "(5) Fail to start client!"
654 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
655 do_nodes $(comma_list $(mdts_nodes)) \
656 $LCTL set_param fail_val=2 fail_loc=0x190
661 # Sleep 5 sec to guarantee at least one object processed by OI scrub
663 # Fail the OI scrub to guarantee there is at least one checkpoint
664 #define OBD_FAIL_OSD_SCRUB_FATAL 0x192
665 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x192
667 scrub_check_status 7 failed
669 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
670 do_nodes $(comma_list $(mdts_nodes)) \
671 $LCTL set_param fail_val=3 fail_loc=0x190
674 for n in $(seq $MDSCOUNT); do
675 # stat will re-trigger OI scrub
676 stat $DIR/$tdir/mds$n/${tfile}800 ||
677 error "(8) Failed to stat mds$n/${tfile}800"
680 umount_client $MOUNT || error "(9) Fail to stop client!"
681 scrub_check_status 10 scanning
683 #define OBD_FAIL_OSD_SCRUB_CRASH 0x191
684 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x191
688 for n in $(seq $MDSCOUNT); do
689 position0[$n]=$(scrub_status $n |
690 awk '/^last_checkpoint_position/ {print $2}')
691 position0[$n]=$((${position0[$n]} + 1))
696 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
697 do_nodes $(comma_list $(mdts_nodes)) \
698 $LCTL set_param fail_val=3 fail_loc=0x190
700 echo "starting MDTs without disabling OI scrub"
701 scrub_start_mds 12 "$MOUNT_OPTS_SCRUB"
703 scrub_check_status 13 scanning
706 for n in $(seq $MDSCOUNT); do
707 position1[$n]=$(scrub_status $n |
708 awk '/^latest_start_position/ {print $2}')
709 if [ ${position0[$n]} -ne ${position1[$n]} ]; then
710 error "(14) Expected position ${position0[$n]}, but" \
711 "got ${position1[$n]}"
715 do_nodes $(comma_list $(mdts_nodes)) \
716 $LCTL set_param fail_loc=0 fail_val=0
718 scrub_check_status 15 completed
719 scrub_check_flags 16 ""
721 run_test 6 "OI scrub resumes from last checkpoint"
725 scrub_backup_restore 1
726 echo "starting MDTs with OI scrub disabled"
727 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
728 scrub_check_flags 4 inconsistent
729 mount_client $MOUNT || error "(5) Fail to start client!"
732 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
733 do_nodes $(comma_list $(mdts_nodes)) \
734 $LCTL set_param fail_val=3 fail_loc=0x190
740 for n in $(seq $MDSCOUNT); do
741 stat $DIR/$tdir/mds$n/${tfile}300 ||
742 error "(7) Failed to stat mds$n/${tfile}300!"
745 scrub_check_status 8 scanning
746 scrub_check_flags 9 inconsistent,auto
748 do_nodes $(comma_list $(mdts_nodes)) \
749 $LCTL set_param fail_loc=0 fail_val=0
751 scrub_check_status 10 completed
754 run_test 7 "System is available during OI scrub scanning"
758 scrub_backup_restore 1
759 echo "starting MDTs with OI scrub disabled"
760 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
761 scrub_check_flags 4 inconsistent
763 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
764 do_nodes $(comma_list $(mdts_nodes)) \
765 $LCTL set_param fail_val=1 fail_loc=0x190
768 scrub_check_status 6 scanning
770 scrub_check_status 8 stopped
772 scrub_check_status 10 scanning
774 do_nodes $(comma_list $(mdts_nodes)) \
775 $LCTL set_param fail_loc=0 fail_val=0
777 scrub_check_status 11 completed
778 scrub_check_flags 12 ""
780 run_test 8 "Control OI scrub manually"
783 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
784 skip "Testing on UP system, the speed may be inaccurate."
789 scrub_backup_restore 1
791 echo "starting MDTs with OI scrub disabled"
792 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
793 scrub_check_flags 4 inconsistent
795 local BASE_SPEED1=100
797 # OI scrub should run with full speed under inconsistent case
798 scrub_start 5 -s $BASE_SPEED1
801 scrub_check_status 6 completed
802 scrub_check_flags 7 ""
803 # OI scrub should run with limited speed under non-inconsistent case
804 scrub_start 8 -s $BASE_SPEED1 -r
807 scrub_check_status 9 scanning
809 # Do NOT ignore that there are 1024 pre-fetched items. And there
810 # may be time error, normally it should be less than 2 seconds.
811 # We allow another 20% schedule error.
812 local PRE_FETCHED=1024
814 # MAX_MARGIN = 1.2 = 12 / 10
815 local MAX_SPEED=$(((PRE_FETCHED + BASE_SPEED1 * \
816 (RUN_TIME1 + TIME_DIFF)) / RUN_TIME1 * 12 / 10))
818 for n in $(seq $MDSCOUNT); do
819 local SPEED=$(scrub_status $n | \
820 awk '/^average_speed/ { print $2 }')
821 [ $SPEED -lt $MAX_SPEED ] ||
822 error "(10) Got speed $SPEED, expected less than" \
827 local BASE_SPEED2=300
829 for n in $(seq $MDSCOUNT); do
830 do_facet mds$n $LCTL set_param -n \
831 mdd.$(facet_svc mds$n).lfsck_speed_limit $BASE_SPEED2
835 # MIN_MARGIN = 0.8 = 8 / 10
836 local MIN_SPEED=$(((PRE_FETCHED + \
837 BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
838 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
839 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
840 # MAX_MARGIN = 1.2 = 12 / 10
841 MAX_SPEED=$(((PRE_FETCHED + \
842 BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
843 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
844 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
845 for n in $(seq $MDSCOUNT); do
846 SPEED=$(scrub_status $n | awk '/^average_speed/ { print $2 }')
847 [ $SPEED -gt $MIN_SPEED ] ||
848 error "(11) Got speed $SPEED, expected more than" \
850 [ $SPEED -lt $MAX_SPEED ] ||
851 error "(12) Got speed $SPEED, expected less than" \
854 do_facet mds$n $LCTL set_param -n \
855 mdd.$(facet_svc mds$n).lfsck_speed_limit 0
858 scrub_check_status 13 completed
860 run_test 9 "OI scrub speed control"
864 scrub_backup_restore 1
865 echo "starting mds$n with OI scrub disabled"
866 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
867 scrub_check_flags 4 inconsistent
868 mount_client $MOUNT || error "(5) Fail to start client!"
871 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
872 do_nodes $(comma_list $(mdts_nodes)) \
873 $LCTL set_param fail_val=1 fail_loc=0x190
877 scrub_check_status 7 scanning
878 umount_client $MOUNT || error "(8) Fail to stop client!"
880 echo "starting MDTs with OI scrub disabled"
881 scrub_start_mds 10 "$MOUNT_OPTS_NOSCRUB"
882 scrub_check_status 11 paused
884 echo "starting MDTs without disabling OI scrub"
885 scrub_start_mds 13 "$MOUNT_OPTS_SCRUB"
886 scrub_check_status 14 scanning
888 do_nodes $(comma_list $(mdts_nodes)) \
889 $LCTL set_param fail_loc=0 fail_val=0
891 scrub_check_status 15 completed
892 scrub_check_flags 16 ""
894 run_test 10a "non-stopped OI scrub should auto restarts after MDS remount (1)"
896 # test_10b is obsolete, it will be coverded by related sanity-lfsck tests.
899 scrub_backup_restore 1
900 echo "starting MDTs with OI scrub disabled"
901 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
902 scrub_check_flags 4 inconsistent
904 #define OBD_FAIL_OSD_SCRUB_DELAY 0x190
905 do_nodes $(comma_list $(mdts_nodes)) \
906 $LCTL set_param fail_val=3 fail_loc=0x190
909 scrub_check_status 6 scanning
911 echo "starting MDTs with OI scrub disabled"
912 scrub_start_mds 8 "$MOUNT_OPTS_NOSCRUB"
913 scrub_check_status 9 paused
915 echo "starting MDTs without disabling OI scrub"
916 scrub_start_mds 11 "$MOUNT_OPTS_SCRUB"
917 scrub_check_status 12 scanning
919 do_nodes $(comma_list $(mdts_nodes)) \
920 $LCTL set_param fail_loc=0 fail_val=0
922 scrub_check_status 13 completed
923 scrub_check_flags 14 ""
925 #run_test 10b "non-stopped OI scrub should auto restarts after MDS remount (2)"
933 for n in $(seq $MDSCOUNT); do
934 $LFS mkdir -i $((n - 1)) $DIR/$tdir/mds$n ||
935 error "(1) Fail to mkdir $DIR/$tdir/mds$n"
937 createmany -o $DIR/$tdir/mds$n/f $CREATED ||
938 error "(2) Fail to create under $tdir/mds$n"
941 # reset OI scrub start point by force
943 scrub_check_status 4 completed
948 # OI scrub should skip the new created objects for the first accessing
949 # notice we're creating a new llog for every OST on every startup
950 # new features can make this even less stable, so we only check
951 # that the number of skipped files is less than 2x the number of files
952 local MAXIMUM=$((CREATED * 2))
953 local MINIMUM=$((CREATED + 1)) # files + directory
954 for n in $(seq $MDSCOUNT); do
955 local SKIPPED=$(scrub_status $n | awk '/^noscrub/ { print $2 }')
956 [ $SKIPPED -ge $MAXIMUM -o $SKIPPED -lt $MINIMUM ] &&
957 error "(5) Expect [ $MINIMUM , $MAXIMUM ) objects" \
958 "skipped on mds$n, but got $SKIPPED"
960 checked0[$n]=$(scrub_status $n | awk '/^checked/ { print $2 }')
963 # reset OI scrub start point by force
965 scrub_check_status 7 completed
967 # OI scrub should skip the new created object only once
968 for n in $(seq $MDSCOUNT); do
969 SKIPPED=$(scrub_status $n | awk '/^noscrub/ { print $2 }')
970 checked1[$n]=$(scrub_status $n | awk '/^checked/ { print $2 }')
972 [ ${checked0[$n]} -ne ${checked1[$n]} -o $SKIPPED -eq 0 ] ||
973 error "(8) Expect 0 objects skipped on mds$n, but" \
977 run_test 11 "OI scrub skips the new created objects only once"
981 $SETSTRIPE -c 1 -i 0 $DIR/$tdir
983 #define OBD_FAIL_OSD_COMPAT_INVALID_ENTRY 0x195
984 do_facet ost1 $LCTL set_param fail_loc=0x195
985 local count=$(precreated_ost_obj_count 0 0)
987 createmany -o $DIR/$tdir/f $((count + 32))
988 umount_client $MOUNT || error "(1) Fail to stop client!"
990 stop ost1 || error "(2) Fail to stop ost1"
992 #define OBD_FAIL_OST_NODESTROY 0x233
993 do_facet ost1 $LCTL set_param fail_loc=0x233
995 start ost1 $(ostdevname 1) $MOUNT_OPTS_NOSCRUB ||
996 error "(3) Fail to start ost1"
998 mount_client $MOUNT || error "(4) Fail to start client!"
1000 ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(5) ls should fail"
1002 $START_SCRUB_ON_OST -r || error "(6) Fail to start OI scrub on OST!"
1004 do_facet ost1 $LCTL set_param fail_loc=0
1005 wait_update_facet ost1 "$LCTL get_param -n \
1006 osd-ldiskfs.$(facet_svc ost1).oi_scrub |
1007 awk '/^status/ { print \\\$2 }'" "completed" 6 ||
1008 error "(7) Expected '$expected' on ost1"
1010 ls -ail $DIR/$tdir > /dev/null || {
1012 error "(8) ls should succeed"
1015 run_test 12 "OI scrub can rebuild invalid /O entries"
1018 check_mount_and_prep
1019 $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1021 #define OBD_FAIL_OSD_COMPAT_NO_ENTRY 0x196
1022 do_facet ost1 $LCTL set_param fail_loc=0x196
1023 local count=$(precreated_ost_obj_count 0 0)
1025 createmany -o $DIR/$tdir/f $((count + 32))
1026 do_facet ost1 $LCTL set_param fail_loc=0
1028 umount_client $MOUNT || error "(1) Fail to stop client!"
1030 stop ost1 || error "(2) Fail to stop ost1"
1032 start ost1 $(ostdevname 1) $MOUNT_OPTS_NOSCRUB ||
1033 error "(3) Fail to start ost1"
1035 mount_client $MOUNT || error "(4) Fail to start client!"
1037 ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(5) ls should fail"
1039 $START_SCRUB_ON_OST -r || error "(6) Fail to start OI scrub on OST!"
1041 wait_update_facet ost1 "$LCTL get_param -n \
1042 osd-ldiskfs.$(facet_svc ost1).oi_scrub |
1043 awk '/^status/ { print \\\$2 }'" "completed" 6 ||
1044 error "(7) Expected '$expected' on ost1"
1046 ls -ail $DIR/$tdir > /dev/null || error "(8) ls should succeed"
1048 run_test 13 "OI scrub can rebuild missed /O entries"
1051 check_mount_and_prep
1052 $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1054 #define OBD_FAIL_OSD_COMPAT_NO_ENTRY 0x196
1055 do_facet ost1 $LCTL set_param fail_loc=0x196
1056 local count=$(precreated_ost_obj_count 0 0)
1058 createmany -o $DIR/$tdir/f $((count + 32))
1059 do_facet ost1 $LCTL set_param fail_loc=0
1061 umount_client $MOUNT || error "(1) Fail to stop client!"
1063 stop ost1 || error "(2) Fail to stop ost1"
1066 run_e2fsck $(facet_host ost1) $(ostdevname 1) "-y" ||
1067 error "(3) Fail to run e2fsck error"
1069 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
1070 error "(4) Fail to start ost1"
1072 mount_client $MOUNT || error "(5) Fail to start client!"
1074 local LF_REPAIRED=$($SHOW_SCRUB_ON_OST |
1075 awk '/^lf_reparied/ { print $2 }')
1076 [ $LF_REPAIRED -gt 0 ] ||
1077 error "(6) Some entry under /lost+found should be repaired"
1079 ls -ail $DIR/$tdir > /dev/null || error "(7) ls should succeed"
1081 run_test 14 "OI scrub can repair objects under lost+found"
1084 # skip test_15 for LU-4182
1085 [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return
1086 local server_version=$(lustre_version_code $SINGLEMDS)
1088 scrub_backup_restore 1
1089 echo "starting MDTs with OI scrub disabled"
1090 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
1091 scrub_check_status 3 init
1092 scrub_check_flags 4 inconsistent
1094 # run under dryrun mode
1095 if [ $server_version -lt $(version_code 2.5.58) ]; then
1096 scrub_start 5 --dryrun on
1098 scrub_start 5 --dryrun
1100 scrub_check_status 6 completed
1101 scrub_check_flags 7 inconsistent
1102 scrub_check_params 8 dryrun
1103 scrub_check_repaired 9 20
1105 # run under dryrun mode again
1106 if [ $server_version -lt $(version_code 2.5.58) ]; then
1107 scrub_start 10 --dryrun on
1109 scrub_start 10 --dryrun
1111 scrub_check_status 11 completed
1112 scrub_check_flags 12 inconsistent
1113 scrub_check_params 13 dryrun
1114 scrub_check_repaired 14 20
1116 # run under normal mode
1118 # Lustre-2.x (x <= 5) used "-n off" to disable dryrun which does not
1119 # work under Lustre-2.y (y >= 6), the test script should be fixed as
1120 # "-noff" or "--dryrun=off" or nothing by default.
1121 if [ $server_version -lt $(version_code 2.5.58) ]; then
1122 scrub_start 15 --dryrun off
1126 scrub_check_status 16 completed
1127 scrub_check_flags 17 ""
1128 scrub_check_params 18 ""
1129 scrub_check_repaired 19 20
1131 # run under normal mode again
1132 if [ $server_version -lt $(version_code 2.5.58) ]; then
1133 scrub_start 20 --dryrun off
1137 scrub_check_status 21 completed
1138 scrub_check_flags 22 ""
1139 scrub_check_params 23 ""
1140 scrub_check_repaired 24 0
1142 run_test 15 "Dryrun mode OI scrub"
1144 # restore MDS/OST size
1145 MDSSIZE=${SAVED_MDSSIZE}
1146 OSTSIZE=${SAVED_OSTSIZE}
1147 OSTCOUNT=${SAVED_OSTCOUNT}
1149 # cleanup the system at last