Whamcloud - gitweb
LU-11636 tests: fix test_mkdir() to work with old severs
[fs/lustre-release.git] / lustre / tests / sanity-scrub.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 ALWAYS_EXCEPT="$SANITY_SCRUB_EXCEPT"
11
12 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
16 . $LUSTRE/tests/test-framework.sh
17 init_test_env $@
18 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
19 init_logging
20
21 require_dsh_mds || exit 0
22
23 load_modules
24
25 if ! check_versions; then
26         skip "It is NOT necessary to test scrub under interoperation mode"
27         exit 0
28 fi
29
30 cleanupall
31
32 SAVED_MDSSIZE=${MDSSIZE}
33 SAVED_OSTSIZE=${OSTSIZE}
34 SAVED_OSTCOUNT=${OSTCOUNT}
35
36 # use small MDS + OST size to speed formatting time
37 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
38 # 400M MDT device can guarantee uninitialized groups during the OI scrub
39 MDSSIZE=400000
40 OSTSIZE=200000
41
42 # no need too many OSTs, to reduce the format/start/stop overhead
43 [ $OSTCOUNT -gt 4 ] && OSTCOUNT=4
44
45 # build up a clean test environment.
46 REFORMAT="yes" check_and_setup_lustre
47
48 build_test_filter
49
50 MDT_DEV="${FSNAME}-MDT0000"
51 OST_DEV="${FSNAME}-OST0000"
52 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
53
54 scrub_start() {
55         local error_id=$1
56         local n
57
58         # use "lfsck_start -A" when we no longer need testing interop
59         for n in $(seq $MDSCOUNT); do
60                 do_facet mds$n $LCTL lfsck_start -M $(facet_svc mds$n) \
61                         -t scrub "$@" ||
62                         error "($error_id) Failed to start OI scrub on mds$n"
63         done
64 }
65
66 scrub_stop() {
67         local error_id=$1
68         local n
69
70         # use "lfsck_stop -A" when we no longer need testing interop
71         for n in $(seq $MDSCOUNT); do
72                 do_facet mds$n $LCTL lfsck_stop -M $(facet_svc mds$n) ||
73                         error "($error_id) Failed to stop OI scrub on mds$n"
74         done
75 }
76
77 scrub_status() {
78         local n=$1
79
80         do_facet mds$n $LCTL get_param -n osd-*.$(facet_svc mds$n).oi_scrub
81 }
82
83 START_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_start -M ${MDT_DEV} -t scrub"
84 START_SCRUB_ON_OST="do_facet ost1 $LCTL lfsck_start -M ${OST_DEV} -t scrub"
85 STOP_SCRUB="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
86 SHOW_SCRUB="do_facet $SINGLEMDS \
87                 $LCTL get_param -n osd-*.${MDT_DEV}.oi_scrub"
88 SHOW_SCRUB_ON_OST="do_facet ost1 \
89                 $LCTL get_param -n osd-*.${OST_DEV}.oi_scrub"
90 MOUNT_OPTS_SCRUB="-o user_xattr"
91 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
92
93 scrub_prep() {
94         local nfiles=$1
95         local inject=$2
96         local n
97
98         check_mount_and_prep
99
100         echo "preparing... $(date)"
101         for n in $(seq $MDSCOUNT); do
102                 echo "creating $nfiles files on mds$n"
103                 test_mkdir -i $((n - 1)) -c1 $DIR/$tdir/mds$n ||
104                         error "Failed to create directory mds$n"
105                 cp $LUSTRE/tests/*.sh $DIR/$tdir/mds$n ||
106                         error "Failed to copy files to mds$n"
107                 mkdir -p $DIR/$tdir/mds$n/d_$tfile ||
108                         error "mkdir failed on mds$n"
109                 touch $DIR/$tdir/mds$n/d_$tfile/f1 > \
110                         /dev/null || error "create failed on mds$n"
111                 dd if=/dev/zero of=$DIR/$tdir/mds$n/d_$tfile/f2 bs=1M count=1 ||
112                         error "write failed on mds$n"
113                 if [[ $nfiles -gt 0 ]]; then
114                         createmany -m $DIR/$tdir/mds$n/$tfile $nfiles > \
115                                 /dev/null || error "createmany failed on mds$n"
116                 fi
117         done
118         echo "prepared $(date)."
119
120         [ ! -z $inject ] && [ $inject -eq 2 ] && {
121                 #define OBD_FAIL_OSD_NO_OI_ENTRY        0x198
122                 do_nodes $(comma_list $(mdts_nodes)) \
123                                 $LCTL set_param fail_loc=0x198
124
125                 for n in $(seq $MDSCOUNT); do
126                         cp $LUSTRE/tests/runas $DIR/$tdir/mds$n ||
127                                 error "Fail to copy runas to MDS$n"
128                 done
129
130                 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0
131         }
132
133         [ ! -z $inject ] && [ $inject -eq 1 ] &&
134                 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && {
135                 #define OBD_FAIL_OSD_FID_MAPPING        0x193
136                 do_nodes $(comma_list $(mdts_nodes)) \
137                         $LCTL set_param fail_loc=0x193
138
139                 for n in $(seq $MDSCOUNT); do
140                         chmod 0400 $DIR/$tdir/mds$n/test-framework.sh
141                         chmod 0400 $DIR/$tdir/mds$n/sanity-scrub.sh
142                 done
143
144                 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0
145         }
146
147         cleanup_mount $MOUNT > /dev/null || error "Fail to stop client!"
148
149         # sync local transactions on every MDT
150         do_nodes $(comma_list $(mdts_nodes)) \
151                 "$LCTL set_param -n osd*.*MDT*.force_sync=1"
152
153         # wait for a while to cancel update logs after transactions committed.
154         sleep 3
155
156         # sync again to guarantee all things done.
157         do_nodes $(comma_list $(mdts_nodes)) \
158                 "$LCTL set_param -n osd*.*MDT*.force_sync=1"
159
160         for n in $(seq $MDSCOUNT); do
161                 echo "stop mds$n"
162                 stop mds$n > /dev/null || error "Fail to stop MDS$n!"
163         done
164
165         [ ! -z $inject ] && [ $(facet_fstype $SINGLEMDS) = "ldiskfs" ] && {
166                 if [ $inject -eq 1 ]; then
167                         for n in $(seq $MDSCOUNT); do
168                                 mds_backup_restore mds$n ||
169                                         error "Backup/restore on mds$n failed"
170                         done
171                 elif [ $inject -eq 2 ]; then
172                         scrub_remove_ois 1
173                 fi
174         }
175 }
176
177 scrub_start_mds() {
178         local error_id=$1
179         local opts=$2
180         local n
181
182         for n in $(seq $MDSCOUNT); do
183                 start mds$n $(mdsdevname $n) $opts >/dev/null ||
184                         error "($error_id) Failed to start mds$n"
185         done
186 }
187
188 scrub_stop_mds() {
189         local error_id=$1
190         local n
191
192         for n in $(seq $MDSCOUNT); do
193                 echo "stopping mds$n"
194                 stop mds$n >/dev/null ||
195                         error "($error_id) Failed to stop mds$n"
196         done
197 }
198
199 scrub_check_status() {
200         local error_id=$1
201         local expected=$2
202         local n
203
204         for n in $(seq $MDSCOUNT); do
205                 wait_update_facet mds$n "$LCTL get_param -n \
206                         osd-*.$(facet_svc mds$n).oi_scrub |
207                         awk '/^status/ { print \\\$2 }'" "$expected" 6 ||
208                         error "($error_id) Expected '$expected' on mds$n"
209         done
210 }
211
212 scrub_check_flags() {
213         local error_id=$1
214         local expected=$2
215         local actual
216         local n
217
218         for n in $(seq $MDSCOUNT); do
219                 actual=$(do_facet mds$n $LCTL get_param -n \
220                         osd-*.$(facet_svc mds$n).oi_scrub |
221                         awk '/^flags/ { print $2 }')
222                 if [ "$actual" != "$expected" ]; then
223                         error "($error_id) Expected '$expected' on mds$n, but" \
224                                "got '$actual'"
225                 fi
226         done
227 }
228
229 scrub_check_params() {
230         local error_id=$1
231         local expected=$2
232         local actual
233         local n
234
235         for n in $(seq $MDSCOUNT); do
236                 actual=$(do_facet mds$n $LCTL get_param -n \
237                         osd-*.$(facet_svc mds$n).oi_scrub |
238                         awk '/^param/ { print $2 }')
239                 if [ "$actual" != "$expected" ]; then
240                         error "($error_id) Expected '$expected' on mds$n, but" \
241                                "got '$actual'"
242                 fi
243         done
244 }
245
246 scrub_check_repaired() {
247         local error_id=$1
248         local expected=$2
249         local dryrun=$3
250         local actual
251         local n
252
253         for n in $(seq $MDSCOUNT); do
254                 if [ $dryrun -eq 1 ]; then
255                         actual=$(do_facet mds$n $LCTL get_param -n \
256                                 osd-*.$(facet_svc mds$n).oi_scrub |
257                                 awk '/^inconsistent:/ { print $2 }')
258                 else
259                         actual=$(do_facet mds$n $LCTL get_param -n \
260                                 osd-*.$(facet_svc mds$n).oi_scrub |
261                                 awk '/^updated:/ { print $2 }')
262                 fi
263
264                 if [ $expected -eq 0 -a $actual -ne 0 ]; then
265                         error "($error_id) Expected no repaired on mds$n, but" \
266                                "got '$actual'"
267                 fi
268
269                 if [ $expected -ne 0 -a $actual -lt $expected ]; then
270                         error "($error_id) Expected '$expected' on mds$n, but" \
271                                "got '$actual'"
272                 fi
273         done
274 }
275
276 scrub_check_data() {
277         local error_id=$1
278         local n
279
280         for n in $(seq $MDSCOUNT); do
281                 diff -q $LUSTRE/tests/test-framework.sh \
282                         $DIR/$tdir/mds$n/test-framework.sh ||
283                         error "($error_id) File data check failed"
284         done
285 }
286
287 scrub_check_data2() {
288         local filename=$1
289         local error_id=$2
290         local n
291
292         for n in $(seq $MDSCOUNT); do
293                 diff -q $LUSTRE/tests/$filename \
294                         $DIR/$tdir/mds$n/$filename ||
295                         error "($error_id) File data check failed"
296         done
297 }
298
299 scrub_remove_ois() {
300         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] && return
301
302         local error_id=$1
303         local index=$2
304         local n
305
306         for n in $(seq $MDSCOUNT); do
307                 mds_remove_ois mds$n $index ||
308                         error "($error_id) Failed to remove OI .$index on mds$n"
309         done
310 }
311
312 scrub_enable_auto() {
313         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
314                 osd-*.*.auto_scrub=1
315 }
316
317 full_scrub_ratio() {
318         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] && return
319
320         local ratio=$1
321
322         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
323                 osd-*.*.full_scrub_ratio=$ratio
324 }
325
326 full_scrub_threshold_rate() {
327         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] && return
328
329         local rate=$1
330
331         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
332                 osd-*.*.full_scrub_threshold_rate=$rate
333 }
334
335 scrub_enable_index_backup() {
336         do_nodes $(comma_list $(all_server_nodes)) $LCTL set_param -n \
337                 osd-*.*.index_backup=1
338 }
339
340 scrub_disable_index_backup() {
341         do_nodes $(comma_list $(all_server_nodes)) $LCTL set_param -n \
342                 osd-*.*.index_backup=0
343 }
344
345 test_0() {
346         scrub_prep 0
347         echo "starting MDTs without disabling OI scrub"
348         scrub_start_mds 1 "$MOUNT_OPTS_SCRUB"
349         scrub_check_status 2 init
350         scrub_check_flags 3 ""
351         mount_client $MOUNT || error "(4) Fail to start client!"
352         scrub_check_data 5
353 }
354 run_test 0 "Do not auto trigger OI scrub for non-backup/restore case"
355
356 test_1a() {
357         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
358
359         scrub_prep 0
360         echo "start $SINGLEMDS without disabling OI scrub"
361         scrub_start_mds 1 "$MOUNT_OPTS_SCRUB"
362
363         local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
364         [ -z "$FLAGS" ] || error "(3) Expect empty flags, but got '$FLAGS'"
365
366         mount_client $MOUNT || error "(4) Fail to start client!"
367         #define OBD_FAIL_OSD_FID_MAPPING                        0x193
368         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x193
369         # update .lustre OI mapping
370         touch $MOUNT/.lustre
371         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
372         umount_client $MOUNT || error "(5) Fail to stop client!"
373
374         echo "stop $SINGLEMDS"
375         stop $SINGLEMDS > /dev/null || error "(6) Fail to stop MDS!"
376
377         echo "start $SINGLEMDS with disabling OI scrub"
378         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
379                 error "(7) Fail to start MDS!"
380
381         local FLAGS=$($SHOW_SCRUB | awk '/^flags/ { print $2 }')
382         [ "$FLAGS" == "inconsistent" ] ||
383                 error "(9) Expect 'inconsistent', but got '$FLAGS'"
384 }
385 run_test 1a "Auto trigger initial OI scrub when server mounts"
386
387 test_1b() {
388         scrub_prep 0 2
389         echo "start MDTs without disabling OI scrub"
390         scrub_start_mds 2 "$MOUNT_OPTS_SCRUB"
391         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
392                 scrub_check_status 3 completed
393         mount_client $MOUNT || error "(4) Fail to start client!"
394         scrub_check_data2 runas 5
395         scrub_check_status 6 completed
396 }
397 run_test 1b "Trigger OI scrub when MDT mounts for OI files remove/recreate case"
398
399 test_1c() {
400         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
401                 skip "ldiskfs special test" && return
402
403         local index
404
405         # OI files to be removed:
406         # idx 0: oi.16.0
407         # idx 2: oi.16.{2,4,8,16,32}
408         # idx 3: oi.16.{3,9,27}
409         for index in 0 2 3; do
410                 scrub_prep 0
411                 scrub_remove_ois 1 $index
412                 echo "start MDTs with OI scrub disabled"
413                 scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
414                 scrub_check_flags 3 recreated
415                 scrub_start 4
416                 scrub_check_status 5 completed
417                 scrub_check_flags 6 ""
418         done
419 }
420 run_test 1c "Auto detect kinds of OI file(s) removed/recreated cases"
421
422 test_2() {
423         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
424                 skip "ldiskfs special test" && return
425
426         scrub_prep 0 1
427         echo "starting MDTs without disabling OI scrub"
428         scrub_start_mds 2 "$MOUNT_OPTS_SCRUB"
429         scrub_check_status 3 completed
430         mount_client $MOUNT || error "(4) Fail to start client!"
431         scrub_check_data 5
432 }
433 run_test 2 "Trigger OI scrub when MDT mounts for backup/restore case"
434
435 # test_3 is obsolete, it will be covered by test_5.
436 test_3() {
437         formatall > /dev/null
438         setupall > /dev/null
439
440         scrub_prep 0 1
441         echo "starting MDTs with OI scrub disabled"
442         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
443         scrub_check_status 3 init
444         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
445                 scrub_check_flags 4 recreated,inconsistent
446 }
447 #run_test 3 "Do not trigger OI scrub when MDT mounts if 'noscrub' specified"
448
449 test_4a() {
450         scrub_prep 0 1
451         echo "starting MDTs with OI scrub disabled"
452         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
453         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
454                 scrub_check_flags 4 recreated,inconsistent
455         mount_client $MOUNT || error "(5) Fail to start client!"
456         scrub_enable_auto
457         full_scrub_ratio 0
458         scrub_check_data 6
459         sleep 3
460
461         scrub_check_status 7 completed
462         scrub_check_flags 8 ""
463
464         local -a updated0
465         for n in $(seq $MDSCOUNT); do
466                 updated0[$n]=$(scrub_status $n |
467                                awk '/^prior_updated/ { print $2 }')
468         done
469
470         scrub_check_data2 sanity-scrub.sh 9
471         sleep 3
472
473         local -a updated1
474         for n in $(seq $MDSCOUNT); do
475                 updated1[$n]=$(scrub_status $n |
476                                awk '/^prior_updated/ { print $2 }')
477                 [ ${updated0[$n]} -eq ${updated1[$n]} ] ||
478                         error "(10) NOT auto trigger full scrub as expected"
479         done
480 }
481 run_test 4a "Auto trigger OI scrub if bad OI mapping was found (1)"
482
483 test_4b() {
484         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
485                 skip "ldiskfs special test" && return
486
487         scrub_prep 5 1
488         echo "starting MDTs with OI scrub disabled"
489         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
490         scrub_check_flags 4 recreated,inconsistent
491         mount_client $MOUNT || error "(5) Fail to start client!"
492         scrub_enable_auto
493         full_scrub_ratio 10
494         full_scrub_threshold_rate 10000
495         scrub_check_data 6
496         sleep 3
497
498         scrub_check_status 7 completed
499         scrub_check_flags 8 ""
500
501         local -a updated0
502         for n in $(seq $MDSCOUNT); do
503                 updated0[$n]=$(scrub_status $n |
504                                awk '/^prior_updated/ { print $2 }')
505
506                 echo "OI scrub on MDS$n status for the 1st time:"
507                 do_facet mds$n $LCTL get_param -n \
508                         osd-*.$(facet_svc mds$n).oi_scrub
509         done
510
511         scrub_check_data2 sanity-scrub.sh 9
512         sleep 3
513
514         scrub_check_status 10 completed
515         scrub_check_flags 11 ""
516
517         local -a updated1
518         for n in $(seq $MDSCOUNT); do
519                 updated1[$n]=$(scrub_status $n |
520                                awk '/^prior_updated/ { print $2 }')
521
522                 echo "OI scrub on MDS$n status for the 2nd time:"
523                 do_facet mds$n $LCTL get_param -n \
524                         osd-*.$(facet_svc mds$n).oi_scrub
525
526                 [ ${updated0[$n]} -lt ${updated1[$n]} ] ||
527                         error "(12) Auto trigger full scrub unexpectedly"
528         done
529
530         for n in $(seq $MDSCOUNT); do
531                 ls -l $DIR/$tdir/mds$n/*.sh > /dev/null ||
532                         error "(13) fail to ls"
533         done
534         sleep 3
535
536         scrub_check_status 14 completed
537         scrub_check_flags 15 ""
538
539         for n in $(seq $MDSCOUNT); do
540                 updated0[$n]=$(scrub_status $n |
541                                awk '/^prior_updated/ { print $2 }')
542
543                 echo "OI scrub on MDS$n status for the 3rd time:"
544                 do_facet mds$n $LCTL get_param -n \
545                         osd-*.$(facet_svc mds$n).oi_scrub
546
547                 [ ${updated0[$n]} -gt ${updated1[$n]} ] ||
548                         error "(16) Auto trigger full scrub unexpectedly"
549         done
550
551         for n in $(seq $MDSCOUNT); do
552                 ls -l $DIR/$tdir/mds$n/d_${tfile}/ || error "(17) fail to ls"
553         done
554         sleep 3
555
556         for n in $(seq $MDSCOUNT); do
557                 updated1[$n]=$(scrub_status $n |
558                                awk '/^prior_updated/ { print $2 }')
559                 [ ${updated0[$n]} -eq ${updated1[$n]} ] || {
560                         echo "OI scrub on MDS$n status for the 4th time:"
561                         do_facet mds$n $LCTL get_param -n \
562                                 osd-*.$(facet_svc mds$n).oi_scrub
563
564                         error "(18) NOT auto trigger full scrub as expected"
565                 }
566         done
567 }
568 run_test 4b "Auto trigger OI scrub if bad OI mapping was found (2)"
569
570 test_4c() {
571         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
572                 skip "ldiskfs special test" && return
573
574         scrub_prep 500 1
575         echo "starting MDTs with OI scrub disabled"
576         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
577         scrub_check_flags 4 recreated,inconsistent
578         mount_client $MOUNT || error "(5) Fail to start client!"
579         scrub_enable_auto
580         full_scrub_ratio 2
581         full_scrub_threshold_rate 20
582         scrub_check_data 6
583         sleep 3
584
585         scrub_check_status 7 completed
586         scrub_check_flags 8 ""
587
588         local -a updated0
589         for n in $(seq $MDSCOUNT); do
590                 updated0[$n]=$(scrub_status $n |
591                                awk '/^prior_updated/ { print $2 }')
592
593                 echo "OI scrub on MDS$n status for the 1st time:"
594                 do_facet mds$n $LCTL get_param -n \
595                         osd-*.$(facet_svc mds$n).oi_scrub
596         done
597
598         scrub_check_data2 sanity-scrub.sh 9
599         sleep 3
600
601         scrub_check_status 10 completed
602         scrub_check_flags 11 ""
603
604         local -a updated1
605         for n in $(seq $MDSCOUNT); do
606                 updated1[$n]=$(scrub_status $n |
607                                awk '/^prior_updated/ { print $2 }')
608
609                 echo "OI scrub on MDS$n status for the 2nd time:"
610                 do_facet mds$n $LCTL get_param -n \
611                         osd-*.$(facet_svc mds$n).oi_scrub
612
613                 [ ${updated0[$n]} -lt ${updated1[$n]} ] ||
614                         error "(12) Auto trigger full scrub unexpectedly"
615         done
616
617         for n in $(seq $MDSCOUNT); do
618                 ls -l $DIR/$tdir/mds$n/*.sh > /dev/null ||
619                         error "(13) fail to ls"
620         done
621         sleep 3
622
623         scrub_check_status 14 completed
624         scrub_check_flags 15 ""
625
626         for n in $(seq $MDSCOUNT); do
627                 updated0[$n]=$(scrub_status $n |
628                                awk '/^prior_updated/ { print $2 }')
629
630                 echo "OI scrub on MDS$n status for the 3rd time:"
631                 do_facet mds$n $LCTL get_param -n \
632                         osd-*.$(facet_svc mds$n).oi_scrub
633
634                 [ ${updated0[$n]} -gt ${updated1[$n]} ] ||
635                         error "(16) Auto trigger full scrub unexpectedly"
636         done
637
638         for n in $(seq $MDSCOUNT); do
639                 ls -l $DIR/$tdir/mds$n/${tfile}1 || error "(17) fail to ls"
640         done
641         sleep 3
642
643         for n in $(seq $MDSCOUNT); do
644                 updated1[$n]=$(scrub_status $n |
645                                awk '/^prior_updated/ { print $2 }')
646                 [ ${updated0[$n]} -eq ${updated1[$n]} ] || {
647                         echo "OI scrub on MDS$n status for the 4th time:"
648                         do_facet mds$n $LCTL get_param -n \
649                                 osd-*.$(facet_svc mds$n).oi_scrub
650
651                         error "(18) NOT auto trigger full scrub as expected"
652                 }
653         done
654 }
655 run_test 4c "Auto trigger OI scrub if bad OI mapping was found (3)"
656
657 test_5() {
658         formatall > /dev/null
659         setupall > /dev/null
660
661         scrub_prep 100 1
662         echo "starting MDTs with OI scrub disabled (1)"
663         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
664         scrub_check_status 3 init
665         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
666                 scrub_check_flags 4 recreated,inconsistent
667         mount_client $MOUNT || error "(5) Fail to start client!"
668         scrub_enable_auto
669         full_scrub_ratio 0
670
671         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
672         do_nodes $(comma_list $(mdts_nodes)) \
673                 $LCTL set_param fail_val=3 fail_loc=0x190
674
675         scrub_check_data 6
676         umount_client $MOUNT || error "(7) Fail to stop client!"
677         scrub_check_status 8 scanning
678
679         #define OBD_FAIL_OSD_SCRUB_CRASH         0x191
680         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x191
681
682         sleep 4
683         scrub_stop_mds 9
684
685         do_nodes $(comma_list $(mdts_nodes)) \
686                 $LCTL set_param fail_loc=0 fail_val=0
687
688         echo "starting MDTs with OI scrub disabled (2)"
689         scrub_start_mds 10 "$MOUNT_OPTS_NOSCRUB"
690         scrub_check_status 11 crashed
691         scrub_stop_mds 12
692
693         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
694         do_nodes $(comma_list $(mdts_nodes)) \
695                 $LCTL set_param fail_val=3 fail_loc=0x190
696
697         echo "starting MDTs without disabling OI scrub"
698         scrub_start_mds 13 "$MOUNT_OPTS_SCRUB"
699         scrub_check_status 14 scanning
700
701         #define OBD_FAIL_OSD_SCRUB_FATAL         0x192
702         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x192
703
704         scrub_check_status 15 failed
705         mount_client $MOUNT || error "(16) Fail to start client!"
706
707         full_scrub_ratio 0
708         do_nodes $(comma_list $(mdts_nodes)) \
709                 $LCTL set_param fail_loc=0 fail_val=0
710
711         local n
712         declare -a pids
713
714         for n in $(seq $MDSCOUNT); do
715                 stat $DIR/$tdir/mds$n/sanity-scrub.sh &
716                 pids[$n]=$!
717         done
718
719         for n in $(seq $MDSCOUNT); do
720                 wait ${pids[$n]} ||
721                         error "(18) Fail to stat mds$n/sanity-scrub.sh"
722         done
723
724         scrub_check_status 19 completed
725         scrub_check_flags 20 ""
726 }
727 run_test 5 "OI scrub state machine"
728
729 test_6() {
730         scrub_prep 100 1
731         echo "starting MDTs with OI scrub disabled"
732         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
733         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
734                 scrub_check_flags 4 recreated,inconsistent
735         mount_client $MOUNT || error "(5) Fail to start client!"
736         scrub_enable_auto
737         full_scrub_ratio 0
738
739         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
740         do_nodes $(comma_list $(mdts_nodes)) \
741                 $LCTL set_param fail_val=2 fail_loc=0x190
742
743         scrub_check_data 6
744
745         # Sleep 5 sec to guarantee at least one object processed by OI scrub
746         sleep 5
747         # Fail the OI scrub to guarantee there is at least one checkpoint
748         #define OBD_FAIL_OSD_SCRUB_FATAL         0x192
749         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x192
750
751         scrub_check_status 7 failed
752
753         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
754         do_nodes $(comma_list $(mdts_nodes)) \
755                 $LCTL set_param fail_val=3 fail_loc=0x190
756
757         local n
758         for n in $(seq $MDSCOUNT); do
759                 # stat will re-trigger OI scrub
760                 stat $DIR/$tdir/mds$n/sanity-scrub.sh ||
761                         error "(8) Failed to stat mds$n/sanity-scrub.sh"
762         done
763
764         umount_client $MOUNT || error "(9) Fail to stop client!"
765         scrub_check_status 10 scanning
766
767         #define OBD_FAIL_OSD_SCRUB_CRASH         0x191
768         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x191
769
770         sleep 4
771         local -a position0
772         for n in $(seq $MDSCOUNT); do
773                 position0[$n]=$(scrub_status $n |
774                         awk '/^last_checkpoint_position/ {print $2}')
775                 position0[$n]=$((${position0[$n]} + 1))
776         done
777
778         scrub_stop_mds 11
779
780         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
781         do_nodes $(comma_list $(mdts_nodes)) \
782                 $LCTL set_param fail_val=3 fail_loc=0x190
783
784         echo "starting MDTs without disabling OI scrub"
785         scrub_start_mds 12 "$MOUNT_OPTS_SCRUB"
786
787         scrub_check_status 13 scanning
788
789         local -a position1
790         for n in $(seq $MDSCOUNT); do
791                 position1[$n]=$(scrub_status $n |
792                         awk '/^latest_start_position/ {print $2}')
793                 if [ ${position0[$n]} -ne ${position1[$n]} ]; then
794                         error "(14) Expected position ${position0[$n]}, but" \
795                                 "got ${position1[$n]}"
796                 fi
797         done
798
799         do_nodes $(comma_list $(mdts_nodes)) \
800                 $LCTL set_param fail_loc=0 fail_val=0
801
802         scrub_check_status 15 completed
803         scrub_check_flags 16 ""
804 }
805 run_test 6 "OI scrub resumes from last checkpoint"
806
807 test_7() {
808         scrub_prep 500 1
809         echo "starting MDTs with OI scrub disabled"
810         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
811         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
812                 scrub_check_flags 4 recreated,inconsistent
813         mount_client $MOUNT || error "(5) Fail to start client!"
814         scrub_enable_auto
815         full_scrub_ratio 0
816
817         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
818         do_nodes $(comma_list $(mdts_nodes)) \
819                 $LCTL set_param fail_val=3 fail_loc=0x190
820
821         scrub_check_data 6
822
823         local n
824         for n in $(seq $MDSCOUNT); do
825                 stat $DIR/$tdir/mds$n/${tfile}300 ||
826                         error "(7) Failed to stat mds$n/${tfile}300!"
827         done
828
829         scrub_check_status 8 scanning
830         if [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ]; then
831                 scrub_check_flags 9 inconsistent,auto
832         else
833                 scrub_check_flags 9 recreated,inconsistent,auto
834         fi
835
836         do_nodes $(comma_list $(mdts_nodes)) \
837                 $LCTL set_param fail_loc=0 fail_val=0
838
839         scrub_check_status 10 completed
840         scrub_check_flags ""
841 }
842 run_test 7 "System is available during OI scrub scanning"
843
844 test_8() {
845         scrub_prep 128 1
846         echo "starting MDTs with OI scrub disabled"
847         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
848         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
849                 scrub_check_flags 4 recreated,inconsistent
850
851         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
852         do_nodes $(comma_list $(mdts_nodes)) \
853                 $LCTL set_param fail_val=1 fail_loc=0x190
854
855         scrub_start 5
856         scrub_check_status 6 scanning
857         scrub_stop 7
858         scrub_check_status 8 stopped
859         scrub_start 9
860         scrub_check_status 10 scanning
861
862         do_nodes $(comma_list $(mdts_nodes)) \
863                 $LCTL set_param fail_loc=0 fail_val=0
864
865         scrub_check_status 11 completed
866         scrub_check_flags 12 ""
867 }
868 run_test 8 "Control OI scrub manually"
869
870 test_9() {
871         # Skip scrub speed test for ZFS because of performance unstable
872         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
873                 skip "test scrub speed only on ldiskfs" && return
874
875         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
876                 skip "Testing on UP system, the speed may be inaccurate."
877                 return 0
878         fi
879
880         scrub_prep 6000 1
881
882         echo "starting MDTs with OI scrub disabled"
883         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
884         scrub_check_flags 4 recreated,inconsistent
885
886         local BASE_SPEED1=100
887         local RUN_TIME1=10
888         # OI scrub should run with full speed under inconsistent case
889         scrub_start 5 -s $BASE_SPEED1
890
891         sleep $RUN_TIME1
892         scrub_check_status 6 completed
893         scrub_check_flags 7 ""
894         # OI scrub should run with limited speed under non-inconsistent case
895         scrub_start 8 -s $BASE_SPEED1 -r
896
897         sleep $RUN_TIME1
898         scrub_check_status 9 scanning
899
900         # Do NOT ignore that there are 1024 pre-fetched items. And there
901         # may be time error, normally it should be less than 2 seconds.
902         # We allow another 20% schedule error.
903         local PRE_FETCHED=1024
904         local TIME_DIFF=2
905         # MAX_MARGIN = 1.2 = 12 / 10
906         local MAX_SPEED=$(((PRE_FETCHED + BASE_SPEED1 * \
907                 (RUN_TIME1 + TIME_DIFF)) / RUN_TIME1 * 12 / 10))
908         local n
909         for n in $(seq $MDSCOUNT); do
910                 local SPEED=$(scrub_status $n | \
911                         awk '/^average_speed/ { print $2 }')
912                 [ $SPEED -lt $MAX_SPEED ] ||
913                         error "(10) Got speed $SPEED, expected less than" \
914                                 "$MAX_SPEED"
915         done
916
917         # adjust speed limit
918         local BASE_SPEED2=300
919         local RUN_TIME2=10
920         for n in $(seq $MDSCOUNT); do
921                 do_facet mds$n $LCTL set_param -n \
922                         mdd.$(facet_svc mds$n).lfsck_speed_limit $BASE_SPEED2
923         done
924         sleep $RUN_TIME2
925
926         # MIN_MARGIN = 0.8 = 8 / 10
927         local MIN_SPEED=$(((PRE_FETCHED + \
928                             BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
929                             BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
930                            (RUN_TIME1 + RUN_TIME2) * 8 / 10))
931         # MAX_MARGIN = 1.2 = 12 / 10
932         MAX_SPEED=$(((PRE_FETCHED + \
933                       BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
934                       BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
935                      (RUN_TIME1 + RUN_TIME2) * 12 / 10))
936         for n in $(seq $MDSCOUNT); do
937                 SPEED=$(scrub_status $n | awk '/^average_speed/ { print $2 }')
938                 [ $SPEED -gt $MIN_SPEED ] ||
939                         error "(11) Got speed $SPEED, expected more than" \
940                                 "$MIN_SPEED"
941                 [ $SPEED -lt $MAX_SPEED ] ||
942                         error "(12) Got speed $SPEED, expected less than" \
943                                 "$MAX_SPEED"
944
945                 do_facet mds$n $LCTL set_param -n \
946                                 mdd.$(facet_svc mds$n).lfsck_speed_limit 0
947         done
948
949         scrub_check_status 13 completed
950 }
951 run_test 9 "OI scrub speed control"
952
953 test_10a() {
954         scrub_prep 0 1
955         echo "starting mds$n with OI scrub disabled (1)"
956         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
957         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
958                 scrub_check_flags 4 recreated,inconsistent
959         mount_client $MOUNT || error "(5) Fail to start client!"
960         scrub_enable_auto
961         full_scrub_ratio 0
962
963         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
964         do_nodes $(comma_list $(mdts_nodes)) \
965                 $LCTL set_param fail_val=1 fail_loc=0x190
966
967         scrub_check_data 6
968         scrub_check_status 7 scanning
969         umount_client $MOUNT || error "(8) Fail to stop client!"
970         scrub_stop_mds 9
971         echo "starting MDTs with OI scrub disabled (2)"
972         scrub_start_mds 10 "$MOUNT_OPTS_NOSCRUB"
973         scrub_check_status 11 paused
974         scrub_stop_mds 12
975         echo "starting MDTs without disabling OI scrub"
976         scrub_start_mds 13 "$MOUNT_OPTS_SCRUB"
977         scrub_check_status 14 scanning
978
979         do_nodes $(comma_list $(mdts_nodes)) \
980                 $LCTL set_param fail_loc=0 fail_val=0
981
982         scrub_check_status 15 completed
983         scrub_check_flags 16 ""
984 }
985 run_test 10a "non-stopped OI scrub should auto restarts after MDS remount (1)"
986
987 # test_10b is obsolete, it will be coverded by related sanity-lfsck tests.
988 test_10b() {
989         scrub_prep 0 1
990         echo "starting MDTs with OI scrub disabled"
991         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
992         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
993                 scrub_check_flags 4 recreated,inconsistent
994
995         #define OBD_FAIL_OSD_SCRUB_DELAY         0x190
996         do_nodes $(comma_list $(mdts_nodes)) \
997                 $LCTL set_param fail_val=3 fail_loc=0x190
998
999         scrub_start 5
1000         scrub_check_status 6 scanning
1001         scrub_stop_mds 7
1002         echo "starting MDTs with OI scrub disabled"
1003         scrub_start_mds 8 "$MOUNT_OPTS_NOSCRUB"
1004         scrub_check_status 9 paused
1005         scrub_stop_mds 10
1006         echo "starting MDTs without disabling OI scrub"
1007         scrub_start_mds 11 "$MOUNT_OPTS_SCRUB"
1008         scrub_check_status 12 scanning
1009
1010         do_nodes $(comma_list $(mdts_nodes)) \
1011                 $LCTL set_param fail_loc=0 fail_val=0
1012
1013         scrub_check_status 13 completed
1014         scrub_check_flags 14 ""
1015 }
1016 #run_test 10b "non-stopped OI scrub should auto restarts after MDS remount (2)"
1017
1018 test_11() {
1019         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
1020                 skip "ldiskfs special test" && return
1021
1022         local CREATED=100
1023         local n
1024
1025         check_mount_and_prep
1026
1027         for n in $(seq $MDSCOUNT); do
1028                 test_mkdir -i $((n - 1)) -c1 $DIR/$tdir/mds$n ||
1029                         error "(1) Fail to mkdir $DIR/$tdir/mds$n"
1030
1031                 createmany -o $DIR/$tdir/mds$n/f $CREATED ||
1032                         error "(2) Fail to create under $tdir/mds$n"
1033         done
1034
1035         # reset OI scrub start point by force
1036         scrub_start 3 -r
1037         scrub_check_status 4 completed
1038
1039         declare -a checked0
1040         declare -a checked1
1041
1042         # OI scrub should skip the new created objects for the first accessing
1043         # notice we're creating a new llog for every OST on every startup
1044         # new features can make this even less stable, so we only check that
1045         # the number of skipped files is more than the number or known created
1046         local MINIMUM=$((CREATED + 1)) # files + directory
1047         for n in $(seq $MDSCOUNT); do
1048                 local SKIPPED=$(scrub_status $n | awk '/^noscrub/ { print $2 }')
1049                 [ $SKIPPED -lt $MINIMUM ] &&
1050                         error "(5) Expect at least $MINIMUM objects" \
1051                                 "skipped on mds$n, but got $SKIPPED"
1052
1053                 checked0[$n]=$(scrub_status $n | awk '/^checked/ { print $2 }')
1054         done
1055
1056         # reset OI scrub start point by force
1057         scrub_start 6 -r
1058         scrub_check_status 7 completed
1059
1060         # OI scrub should skip the new created object only once
1061         for n in $(seq $MDSCOUNT); do
1062                 SKIPPED=$(scrub_status $n | awk '/^noscrub/ { print $2 }')
1063                 checked1[$n]=$(scrub_status $n | awk '/^checked/ { print $2 }')
1064
1065                 [ ${checked0[$n]} -ne ${checked1[$n]} -o $SKIPPED -eq 0 ] ||
1066                         error "(8) Expect 0 objects skipped on mds$n, but" \
1067                                 "got $SKIPPED"
1068         done
1069 }
1070 run_test 11 "OI scrub skips the new created objects only once"
1071
1072 test_12() {
1073         check_mount_and_prep
1074         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1075
1076         #define OBD_FAIL_OSD_COMPAT_INVALID_ENTRY               0x195
1077         do_facet ost1 $LCTL set_param fail_loc=0x195
1078         local count=$(precreated_ost_obj_count 0 0)
1079
1080         createmany -o $DIR/$tdir/f $((count + 32))
1081         umount_client $MOUNT || error "(1) Fail to stop client!"
1082
1083         stop ost1 || error "(2) Fail to stop ost1"
1084
1085         #define OBD_FAIL_OST_NODESTROY           0x233
1086         do_facet ost1 $LCTL set_param fail_loc=0x233
1087
1088         start ost1 $(ostdevname 1) $MOUNT_OPTS_NOSCRUB ||
1089                 error "(3) Fail to start ost1"
1090
1091         mount_client $MOUNT || error "(4) Fail to start client!"
1092
1093         ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(5) ls should fail"
1094
1095         $START_SCRUB_ON_OST -r || error "(6) Fail to start OI scrub on OST!"
1096
1097         do_facet ost1 $LCTL set_param fail_loc=0
1098         wait_update_facet ost1 "$LCTL get_param -n \
1099                 osd-*.$(facet_svc ost1).oi_scrub |
1100                 awk '/^status/ { print \\\$2 }'" "completed" 6 ||
1101                 error "(7) Expected '$expected' on ost1"
1102
1103         ls -ail $DIR/$tdir > /dev/null || {
1104                 $SHOW_SCRUB_ON_OST
1105                 error "(8) ls should succeed"
1106         }
1107 }
1108 run_test 12 "OI scrub can rebuild invalid /O entries"
1109
1110 test_13() {
1111         check_mount_and_prep
1112         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1113
1114         #define OBD_FAIL_OSD_COMPAT_NO_ENTRY            0x196
1115         do_facet ost1 $LCTL set_param fail_loc=0x196
1116         local count=$(precreated_ost_obj_count 0 0)
1117
1118         createmany -o $DIR/$tdir/f $((count + 32))
1119         do_facet ost1 $LCTL set_param fail_loc=0
1120
1121         umount_client $MOUNT || error "(1) Fail to stop client!"
1122
1123         stop ost1 || error "(2) Fail to stop ost1"
1124
1125         start ost1 $(ostdevname 1) $MOUNT_OPTS_NOSCRUB ||
1126                 error "(3) Fail to start ost1"
1127
1128         mount_client $MOUNT || error "(4) Fail to start client!"
1129
1130         ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(5) ls should fail"
1131
1132         $START_SCRUB_ON_OST -r || error "(6) Fail to start OI scrub on OST!"
1133
1134         wait_update_facet ost1 "$LCTL get_param -n \
1135                 osd-*.$(facet_svc ost1).oi_scrub |
1136                 awk '/^status/ { print \\\$2 }'" "completed" 6 ||
1137                 error "(7) Expected '$expected' on ost1"
1138
1139         ls -ail $DIR/$tdir > /dev/null || error "(8) ls should succeed"
1140 }
1141 run_test 13 "OI scrub can rebuild missed /O entries"
1142
1143 test_14() {
1144         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
1145                 skip "ldiskfs special test"
1146
1147         check_mount_and_prep
1148         $LFS setstripe -c 1 -i 0 $DIR/$tdir
1149
1150         #define OBD_FAIL_OSD_COMPAT_NO_ENTRY            0x196
1151         do_facet ost1 $LCTL set_param fail_loc=0x196
1152         local count=$(precreated_ost_obj_count 0 0)
1153
1154         createmany -o $DIR/$tdir/f $((count + 1000))
1155         do_facet ost1 $LCTL set_param fail_loc=0
1156
1157         umount_client $MOUNT || error "(1) Fail to stop client!"
1158
1159         stop ost1 || error "(2) Fail to stop ost1"
1160
1161         echo "run e2fsck"
1162         run_e2fsck $(facet_host ost1) $(ostdevname 1) "-y" ||
1163                 error "(3) Fail to run e2fsck error"
1164
1165         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
1166                 error "(4) Fail to start ost1"
1167
1168         mount_client $MOUNT || error "(5) Fail to start client!"
1169
1170         local LF_REPAIRED=$($SHOW_SCRUB_ON_OST |
1171                             awk '/^lf_repa[ir]*ed/ { print $2 }')
1172         [ $LF_REPAIRED -ge 1000 ] ||
1173                 error "(6) Some entry under /lost+found should be repaired"
1174
1175         ls -ail $DIR/$tdir > /dev/null || error "(7) ls should succeed"
1176
1177         stopall
1178
1179         echo "run e2fsck again after LFSCK"
1180         run_e2fsck $(facet_host ost1) $(ostdevname 1) "-y" ||
1181                 error "(8) Fail to run e2fsck error"
1182 }
1183 run_test 14 "OI scrub can repair OST objects under lost+found"
1184
1185 test_15() {
1186         local repaired
1187
1188         formatall > /dev/null
1189         setupall > /dev/null
1190
1191         scrub_prep 20 1
1192         echo "starting MDTs with OI scrub disabled"
1193         scrub_start_mds 2 "$MOUNT_OPTS_NOSCRUB"
1194         scrub_check_status 3 init
1195         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] ||
1196                 scrub_check_flags 4 recreated,inconsistent
1197
1198         # run under dryrun mode
1199         scrub_start 5 --dryrun
1200         scrub_check_status 6 completed
1201         if [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ]; then
1202                 scrub_check_flags 7 inconsistent
1203                 repaired=2
1204         else
1205                 scrub_check_flags 7 recreated,inconsistent
1206                 repaired=20
1207         fi
1208         scrub_check_params 8 dryrun
1209         scrub_check_repaired 9 $repaired 1
1210
1211         # run under dryrun mode again
1212         scrub_start 10 --dryrun
1213         scrub_check_status 11 completed
1214         if [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ]; then
1215                 scrub_check_flags 12 inconsistent
1216         else
1217                 scrub_check_flags 12 recreated,inconsistent
1218         fi
1219         scrub_check_params 13 dryrun
1220         scrub_check_repaired 14 $repaired 1
1221
1222         # run under normal mode
1223         scrub_start 15
1224         scrub_check_status 16 completed
1225         scrub_check_flags 17 ""
1226         scrub_check_params 18 ""
1227         scrub_check_repaired 19 $repaired 0
1228
1229         # run under normal mode again
1230         scrub_start 20
1231         scrub_check_status 21 completed
1232         scrub_check_flags 22 ""
1233         scrub_check_params 23 ""
1234         scrub_check_repaired 24 0 0
1235 }
1236 run_test 15 "Dryrun mode OI scrub"
1237
1238 test_16() {
1239         check_mount_and_prep
1240         scrub_enable_index_backup
1241
1242         #define OBD_FAIL_OSD_INDEX_CRASH        0x199
1243         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x199
1244         scrub_prep 0
1245         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0
1246
1247         echo "starting MDTs without disabling OI scrub"
1248         scrub_start_mds 1 "$MOUNT_OPTS_SCRUB"
1249         mount_client $MOUNT || error "(2) Fail to start client!"
1250         scrub_check_data 3
1251         scrub_disable_index_backup
1252 }
1253 run_test 16 "Initial OI scrub can rebuild crashed index objects"
1254
1255 # restore MDS/OST size
1256 MDSSIZE=${SAVED_MDSSIZE}
1257 OSTSIZE=${SAVED_OSTSIZE}
1258 OSTCOUNT=${SAVED_OSTCOUNT}
1259
1260 # cleanup the system at last
1261 REFORMAT="yes" cleanup_and_setup_lustre
1262
1263 complete $SECONDS
1264 check_and_cleanup_lustre
1265 exit_status