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