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