3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 ALWAYS_EXCEPT="$SANITY_LFSCK_EXCEPT"
11 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
15 . $LUSTRE/tests/test-framework.sh
17 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
20 [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
21 skip "test LFSCK only for ldiskfs" && exit 0
22 require_dsh_mds || exit 0
24 MCREATE=${MCREATE:-mcreate}
25 SAVED_MDSSIZE=${MDSSIZE}
26 SAVED_OSTSIZE=${OSTSIZE}
27 SAVED_OSTCOUNT=${OSTCOUNT}
28 # use small MDS + OST size to speed formatting time
29 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
32 # no need too much OSTs, to reduce the format/start/stop overhead
33 [ $OSTCOUNT -gt 4 ] && OSTCOUNT=4
35 # build up a clean test environment.
39 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.60) ]] &&
40 skip "Need MDS version at least 2.3.60" && check_and_cleanup_lustre &&
43 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.4.90) ]] &&
44 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 2c"
48 $LCTL set_param debug=+lfsck > /dev/null || true
50 MDT_DEV="${FSNAME}-MDT0000"
51 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
52 START_NAMESPACE="do_facet $SINGLEMDS \
53 $LCTL lfsck_start -M ${MDT_DEV} -t namespace"
54 STOP_LFSCK="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
55 SHOW_NAMESPACE="do_facet $SINGLEMDS \
56 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace"
57 MOUNT_OPTS_SCRUB="-o user_xattr"
58 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
67 echo "preparing... $nfiles * $ndirs files will be created $(date)."
68 if [ ! -z $igif ]; then
69 #define OBD_FAIL_FID_IGIF 0x1504
70 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
73 cp $LUSTRE/tests/*.sh $DIR/$tdir/
74 if [ $ndirs -gt 0 ]; then
75 createmany -d $DIR/$tdir/d $ndirs
76 createmany -m $DIR/$tdir/f $ndirs
77 if [ $nfiles -gt 0 ]; then
78 for ((i = 0; i < $ndirs; i++)); do
79 createmany -m $DIR/$tdir/d${i}/f $nfiles > \
80 /dev/null || error "createmany $nfiles"
83 createmany -d $DIR/$tdir/e $ndirs
86 if [ ! -z $igif ]; then
87 touch $DIR/$tdir/dummy
88 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
91 echo "prepared $(date)."
97 #define OBD_FAIL_LFSCK_DELAY1 0x1600
98 do_facet $SINGLEMDS $LCTL set_param fail_val=3 fail_loc=0x1600
99 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
101 $SHOW_NAMESPACE || error "Fail to monitor LFSCK (3)"
103 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
104 [ "$STATUS" == "scanning-phase1" ] ||
105 error "(4) Expect 'scanning-phase1', but got '$STATUS'"
107 $STOP_LFSCK || error "(5) Fail to stop LFSCK!"
109 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
110 [ "$STATUS" == "stopped" ] ||
111 error "(6) Expect 'stopped', but got '$STATUS'"
113 $START_NAMESPACE || error "(7) Fail to start LFSCK for namespace!"
115 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
116 [ "$STATUS" == "scanning-phase1" ] ||
117 error "(8) Expect 'scanning-phase1', but got '$STATUS'"
119 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
120 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
121 mdd.${MDT_DEV}.lfsck_namespace |
122 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
124 error "(9) unexpected status"
127 local repaired=$($SHOW_NAMESPACE |
128 awk '/^updated_phase1/ { print $2 }')
129 [ $repaired -eq 0 ] ||
130 error "(10) Expect nothing to be repaired, but got: $repaired"
132 local scanned1=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
133 $START_NAMESPACE -r || error "(11) Fail to reset LFSCK!"
134 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
135 mdd.${MDT_DEV}.lfsck_namespace |
136 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
138 error "(12) unexpected status"
141 local scanned2=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
142 [ $((scanned1 + 1)) -eq $scanned2 ] ||
143 error "(13) Expect success $((scanned1 + 1)), but got $scanned2"
145 echo "stopall, should NOT crash LU-3649"
146 stopall || error "(14) Fail to stopall"
148 run_test 0 "Control LFSCK manually"
153 #define OBD_FAIL_FID_INDIR 0x1501
154 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1501
155 touch $DIR/$tdir/dummy
157 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
159 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
160 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
161 mdd.${MDT_DEV}.lfsck_namespace |
162 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
164 error "(4) unexpected status"
167 local repaired=$($SHOW_NAMESPACE |
168 awk '/^updated_phase1/ { print $2 }')
169 [ $repaired -eq 1 ] ||
170 error "(5) Fail to repair crashed FID-in-dirent: $repaired"
172 mount_client $MOUNT || error "(6) Fail to start client!"
174 #define OBD_FAIL_FID_LOOKUP 0x1505
175 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
176 ls $DIR/$tdir/ > /dev/null || error "(7) no FID-in-dirent."
178 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
180 run_test 1a "LFSCK can find out and repair crashed FID-in-dirent"
186 #define OBD_FAIL_FID_INLMA 0x1502
187 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1502
188 touch $DIR/$tdir/dummy
190 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
192 #define OBD_FAIL_FID_NOLMA 0x1506
193 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1506
194 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
195 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
196 mdd.${MDT_DEV}.lfsck_namespace |
197 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
199 error "(4) unexpected status"
202 local repaired=$($SHOW_NAMESPACE |
203 awk '/^updated_phase1/ { print $2 }')
204 [ $repaired -eq 1 ] ||
205 error "(5) Fail to repair missed FID-in-LMA: $repaired"
207 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
208 mount_client $MOUNT || error "(6) Fail to start client!"
210 #define OBD_FAIL_FID_LOOKUP 0x1505
211 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
212 stat $DIR/$tdir/dummy > /dev/null || error "(7) no FID-in-LMA."
214 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
216 run_test 1b "LFSCK can find out and repair missed FID-in-LMA"
221 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
222 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
223 touch $DIR/$tdir/dummy
225 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
227 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
228 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
229 mdd.${MDT_DEV}.lfsck_namespace |
230 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
232 error "(4) unexpected status"
235 local repaired=$($SHOW_NAMESPACE |
236 awk '/^updated_phase1/ { print $2 }')
237 [ $repaired -eq 1 ] ||
238 error "(5) Fail to repair crashed linkEA: $repaired"
240 mount_client $MOUNT || error "(6) Fail to start client!"
242 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
243 error "(7) Fail to stat $DIR/$tdir/dummy"
245 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
246 local dummyname=$($LFS fid2path $DIR $dummyfid)
247 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
248 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
250 run_test 2a "LFSCK can find out and repair crashed linkEA entry"
256 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
257 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
258 touch $DIR/$tdir/dummy
260 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
262 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
263 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
264 mdd.${MDT_DEV}.lfsck_namespace |
265 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
267 error "(4) unexpected status"
270 local repaired=$($SHOW_NAMESPACE |
271 awk '/^updated_phase2/ { print $2 }')
272 [ $repaired -eq 1 ] ||
273 error "(5) Fail to repair crashed linkEA: $repaired"
275 mount_client $MOUNT || error "(6) Fail to start client!"
277 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
278 error "(7) Fail to stat $DIR/$tdir/dummy"
280 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
281 local dummyname=$($LFS fid2path $DIR $dummyfid)
282 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
283 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
285 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
291 #define OBD_FAIL_LFSCK_LINKEA_MORE2 0x1605
292 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1605
293 touch $DIR/$tdir/dummy
295 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
297 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
298 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
299 mdd.${MDT_DEV}.lfsck_namespace |
300 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
302 error "(4) unexpected status"
305 local repaired=$($SHOW_NAMESPACE |
306 awk '/^updated_phase2/ { print $2 }')
307 [ $repaired -eq 1 ] ||
308 error "(5) Fail to repair crashed linkEA: $repaired"
310 mount_client $MOUNT || error "(6) Fail to start client!"
312 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
313 error "(7) Fail to stat $DIR/$tdir/dummy"
315 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
316 local dummyname=$($LFS fid2path $DIR $dummyfid)
317 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
318 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
320 run_test 2c "LFSCK can find out and remove repeated linkEA entry"
325 cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
326 stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
328 mds_backup_restore $SINGLEMDS || error "(1) Fail to backup/restore!"
329 echo "start $SINGLEMDS with disabling OI scrub"
330 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
331 error "(2) Fail to start MDS!"
333 #define OBD_FAIL_LFSCK_DELAY2 0x1601
334 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
335 $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
336 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
337 mdd.${MDT_DEV}.lfsck_namespace |
338 awk '/^flags/ { print \\\$2 }'" "inconsistent" 6 || {
340 error "(5) unexpected status"
343 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
344 [ "$STATUS" == "scanning-phase1" ] ||
345 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
347 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
348 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
349 mdd.${MDT_DEV}.lfsck_namespace |
350 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
352 error "(7) unexpected status"
355 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
356 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
358 local repaired=$($SHOW_NAMESPACE |
359 awk '/^updated_phase1/ { print $2 }')
360 [ $repaired -ge 9 ] ||
361 error "(9) Fail to repair crashed linkEA: $repaired"
363 mount_client $MOUNT || error "(10) Fail to start client!"
365 #define OBD_FAIL_FID_LOOKUP 0x1505
366 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
367 ls $DIR/$tdir/ > /dev/null || error "(11) no FID-in-dirent."
369 local count=$(ls -al $DIR/$tdir | wc -l)
370 [ $count -gt 9 ] || error "(12) namespace LFSCK failed"
372 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
374 run_test 4 "FID-in-dirent can be rebuilt after MDT file-level backup/restore"
379 cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
380 stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
382 mds_backup_restore $SINGLEMDS 1 || error "(1) Fail to backup/restore!"
383 echo "start $SINGLEMDS with disabling OI scrub"
384 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
385 error "(2) Fail to start MDS!"
387 #define OBD_FAIL_LFSCK_DELAY2 0x1601
388 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
389 $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
390 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
391 mdd.${MDT_DEV}.lfsck_namespace |
392 awk '/^flags/ { print \\\$2 }'" "inconsistent,upgrade" 6 || {
394 error "(5) unexpected status"
397 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
398 [ "$STATUS" == "scanning-phase1" ] ||
399 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
401 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
402 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
403 mdd.${MDT_DEV}.lfsck_namespace |
404 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
406 error "(7) unexpected status"
409 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
410 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
412 local repaired=$($SHOW_NAMESPACE |
413 awk '/^updated_phase1/ { print $2 }')
414 [ $repaired -ge 2 ] ||
415 error "(9) Fail to repair crashed linkEA: $repaired"
417 mount_client $MOUNT || error "(10) Fail to start client!"
419 #define OBD_FAIL_FID_LOOKUP 0x1505
420 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
421 stat $DIR/$tdir/dummy > /dev/null || error "(11) no FID-in-LMA."
423 ls $DIR/$tdir/ > /dev/null || error "(12) no FID-in-dirent."
425 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
426 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
427 local dummyname=$($LFS fid2path $DIR $dummyfid)
428 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
429 error "(13) Fail to generate linkEA: $dummyfid $dummyname"
431 run_test 5 "LFSCK can handle IGIF object upgrading"
436 #define OBD_FAIL_LFSCK_DELAY1 0x1600
437 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
438 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
440 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
441 [ "$STATUS" == "scanning-phase1" ] ||
442 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
444 # Sleep 3 sec to guarantee at least one object processed by LFSCK
446 # Fail the LFSCK to guarantee there is at least one checkpoint
447 #define OBD_FAIL_LFSCK_FATAL1 0x1608
448 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001608
449 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
450 mdd.${MDT_DEV}.lfsck_namespace |
451 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
453 error "(4) unexpected status"
456 local POS0=$($SHOW_NAMESPACE |
457 awk '/^last_checkpoint_position/ { print $2 }' |
460 #define OBD_FAIL_LFSCK_DELAY1 0x1600
461 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
462 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
464 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
465 [ "$STATUS" == "scanning-phase1" ] ||
466 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
468 local POS1=$($SHOW_NAMESPACE |
469 awk '/^latest_start_position/ { print $2 }' |
471 [ $POS0 -lt $POS1 ] ||
472 error "(7) Expect larger than: $POS0, but got $POS1"
474 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
475 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
476 mdd.${MDT_DEV}.lfsck_namespace |
477 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
479 error "(8) unexpected status"
482 run_test 6a "LFSCK resumes from last checkpoint (1)"
487 #define OBD_FAIL_LFSCK_DELAY2 0x1601
488 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
489 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
491 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
492 [ "$STATUS" == "scanning-phase1" ] ||
493 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
495 # Sleep 5 sec to guarantee that we are in the directory scanning
497 # Fail the LFSCK to guarantee there is at least one checkpoint
498 #define OBD_FAIL_LFSCK_FATAL2 0x1609
499 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
500 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
501 mdd.${MDT_DEV}.lfsck_namespace |
502 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
504 error "(4) unexpected status"
507 local O_POS0=$($SHOW_NAMESPACE |
508 awk '/^last_checkpoint_position/ { print $2 }' |
511 local D_POS0=$($SHOW_NAMESPACE |
512 awk '/^last_checkpoint_position/ { print $4 }')
514 #define OBD_FAIL_LFSCK_DELAY2 0x1601
515 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
516 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
518 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
519 [ "$STATUS" == "scanning-phase1" ] ||
520 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
522 local O_POS1=$($SHOW_NAMESPACE |
523 awk '/^latest_start_position/ { print $2 }' |
525 local D_POS1=$($SHOW_NAMESPACE |
526 awk '/^latest_start_position/ { print $4 }')
528 if [ "$D_POS0" == "N/A" -o "$D_POS1" == "N/A" ]; then
529 [ $O_POS0 -lt $O_POS1 ] ||
530 error "(7.1) $O_POS1 is not larger than $O_POS0"
532 [ $D_POS0 -lt $D_POS1 ] ||
533 error "(7.2) $D_POS1 is not larger than $D_POS0"
536 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
537 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
538 mdd.${MDT_DEV}.lfsck_namespace |
539 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
541 error "(8) unexpected status"
544 run_test 6b "LFSCK resumes from last checkpoint (2)"
551 #define OBD_FAIL_LFSCK_DELAY2 0x1601
552 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
553 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
555 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
556 [ "$STATUS" == "scanning-phase1" ] ||
557 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
559 # Sleep 3 sec to guarantee at least one object processed by LFSCK
561 echo "stop $SINGLEMDS"
562 stop $SINGLEMDS > /dev/null || error "(4) Fail to stop MDS!"
564 echo "start $SINGLEMDS"
565 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
566 error "(5) Fail to start MDS!"
568 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
569 [ "$STATUS" == "scanning-phase1" ] ||
570 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
572 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
573 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
574 mdd.${MDT_DEV}.lfsck_namespace |
575 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
577 error "(7) unexpected status"
580 run_test 7a "non-stopped LFSCK should auto restarts after MDS remount (1)"
586 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
587 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
588 for ((i = 0; i < 20; i++)); do
589 touch $DIR/$tdir/dummy${i}
592 #define OBD_FAIL_LFSCK_DELAY3 0x1602
593 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1602
594 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
595 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
596 mdd.${MDT_DEV}.lfsck_namespace |
597 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
599 error "(4) unexpected status"
602 echo "stop $SINGLEMDS"
603 stop $SINGLEMDS > /dev/null || error "(5) Fail to stop MDS!"
605 echo "start $SINGLEMDS"
606 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
607 error "(6) Fail to start MDS!"
609 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
610 [ "$STATUS" == "scanning-phase2" ] ||
611 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
613 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
614 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
615 mdd.${MDT_DEV}.lfsck_namespace |
616 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
618 error "(8) unexpected status"
621 run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
626 formatall > /dev/null
632 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
633 [ "$STATUS" == "init" ] ||
634 error "(2) Expect 'init', but got '$STATUS'"
636 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
637 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
638 mkdir $DIR/$tdir/crashed
640 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
641 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
642 for ((i = 0; i < 5; i++)); do
643 touch $DIR/$tdir/dummy${i}
646 umount_client $MOUNT || error "(3) Fail to stop client!"
648 #define OBD_FAIL_LFSCK_DELAY2 0x1601
649 do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1601
650 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
652 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
653 [ "$STATUS" == "scanning-phase1" ] ||
654 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
656 $STOP_LFSCK || error "(6) Fail to stop LFSCK!"
658 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
659 [ "$STATUS" == "stopped" ] ||
660 error "(7) Expect 'stopped', but got '$STATUS'"
662 $START_NAMESPACE || error "(8) Fail to start LFSCK for namespace!"
664 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
665 [ "$STATUS" == "scanning-phase1" ] ||
666 error "(9) Expect 'scanning-phase1', but got '$STATUS'"
668 #define OBD_FAIL_LFSCK_FATAL2 0x1609
669 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
670 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
671 mdd.${MDT_DEV}.lfsck_namespace |
672 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
674 error "(10) unexpected status"
677 #define OBD_FAIL_LFSCK_DELAY1 0x1600
678 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
679 $START_NAMESPACE || error "(11) Fail to start LFSCK for namespace!"
681 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
682 [ "$STATUS" == "scanning-phase1" ] ||
683 error "(12) Expect 'scanning-phase1', but got '$STATUS'"
685 #define OBD_FAIL_LFSCK_CRASH 0x160a
686 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160a
689 echo "stop $SINGLEMDS"
690 stop $SINGLEMDS > /dev/null || error "(13) Fail to stop MDS!"
692 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
693 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
695 echo "start $SINGLEMDS"
696 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
697 error "(14) Fail to start MDS!"
699 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
700 [ "$STATUS" == "crashed" ] ||
701 error "(15) Expect 'crashed', but got '$STATUS'"
703 #define OBD_FAIL_LFSCK_DELAY2 0x1601
704 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
705 $START_NAMESPACE || error "(16) Fail to start LFSCK for namespace!"
707 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
708 [ "$STATUS" == "scanning-phase1" ] ||
709 error "(17) Expect 'scanning-phase1', but got '$STATUS'"
711 echo "stop $SINGLEMDS"
712 stop $SINGLEMDS > /dev/null || error "(18) Fail to stop MDS!"
714 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
715 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
717 echo "start $SINGLEMDS"
718 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
719 error "(19) Fail to start MDS!"
721 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
722 [ "$STATUS" == "paused" ] ||
723 error "(20) Expect 'paused', but got '$STATUS'"
725 #define OBD_FAIL_LFSCK_DELAY3 0x1602
726 do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1602
728 $START_NAMESPACE || error "(21) Fail to start LFSCK for namespace!"
729 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
730 mdd.${MDT_DEV}.lfsck_namespace |
731 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
733 error "(22) unexpected status"
736 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
737 [ "$FLAGS" == "scanned-once,inconsistent" ] ||
738 error "(23) Expect 'scanned-once,inconsistent',but got '$FLAGS'"
740 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
741 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
742 mdd.${MDT_DEV}.lfsck_namespace |
743 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
745 error "(24) unexpected status"
748 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
749 [ -z "$FLAGS" ] || error "(25) Expect empty flags, but got '$FLAGS'"
751 run_test 8 "LFSCK state machine"
754 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
755 skip "Testing on UP system, the speed may be inaccurate."
761 local BASE_SPEED1=100
763 $START_NAMESPACE -r -s $BASE_SPEED1 || error "(3) Fail to start LFSCK!"
766 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
767 [ "$STATUS" == "scanning-phase1" ] ||
768 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
770 local SPEED=$($SHOW_NAMESPACE |
771 awk '/^average_speed_phase1/ { print $2 }')
773 # There may be time error, normally it should be less than 2 seconds.
774 # We allow another 20% schedule error.
776 # MAX_MARGIN = 1.2 = 12 / 10
777 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
778 RUN_TIME1 * 12 / 10))
779 [ $SPEED -lt $MAX_SPEED ] ||
780 error "(4) Got speed $SPEED, expected less than $MAX_SPEED"
783 local BASE_SPEED2=300
785 do_facet $SINGLEMDS \
786 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
789 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
790 # MIN_MARGIN = 0.8 = 8 / 10
791 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
792 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
793 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
794 [ $SPEED -gt $MIN_SPEED ] ||
795 error "(5) Got speed $SPEED, expected more than $MIN_SPEED"
797 # MAX_MARGIN = 1.2 = 12 / 10
798 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
799 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
800 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
801 [ $SPEED -lt $MAX_SPEED ] ||
802 error "(6) Got speed $SPEED, expected less than $MAX_SPEED"
804 do_facet $SINGLEMDS \
805 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
807 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
808 [ "$STATUS" == "completed" ] ||
809 error "(7) Expect 'completed', but got '$STATUS'"
811 run_test 9a "LFSCK speed control (1)"
814 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
815 skip "Testing on UP system, the speed may be inaccurate."
821 echo "Preparing another 50 * 50 files (with error) at $(date)."
822 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
823 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
824 createmany -d $DIR/$tdir/d 50
825 createmany -m $DIR/$tdir/f 50
826 for ((i = 0; i < 50; i++)); do
827 createmany -m $DIR/$tdir/d${i}/f 50 > /dev/null
830 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN 0x160c
831 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160c
832 $START_NAMESPACE -r || error "(4) Fail to start LFSCK!"
833 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
834 mdd.${MDT_DEV}.lfsck_namespace |
835 awk '/^status/ { print \\\$2 }'" "stopped" 10 || {
837 error "(5) unexpected status"
840 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
841 echo "Prepared at $(date)."
845 $START_NAMESPACE -s $BASE_SPEED1 || error "(6) Fail to start LFSCK!"
848 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
849 [ "$STATUS" == "scanning-phase2" ] ||
850 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
852 local SPEED=$($SHOW_NAMESPACE |
853 awk '/^average_speed_phase2/ { print $2 }')
854 # There may be time error, normally it should be less than 2 seconds.
855 # We allow another 20% schedule error.
857 # MAX_MARGIN = 1.2 = 12 / 10
858 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
859 RUN_TIME1 * 12 / 10))
860 [ $SPEED -lt $MAX_SPEED ] ||
861 error "(8) Got speed $SPEED, expected less than $MAX_SPEED"
864 local BASE_SPEED2=150
866 do_facet $SINGLEMDS \
867 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
870 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
871 # MIN_MARGIN = 0.8 = 8 / 10
872 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
873 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
874 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
875 [ $SPEED -gt $MIN_SPEED ] ||
876 error "(9) Got speed $SPEED, expected more than $MIN_SPEED"
878 # MAX_MARGIN = 1.2 = 12 / 10
879 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
880 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
881 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
882 [ $SPEED -lt $MAX_SPEED ] ||
883 error "(10) Got speed $SPEED, expected less than $MAX_SPEED"
885 do_facet $SINGLEMDS \
886 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
887 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
888 mdd.${MDT_DEV}.lfsck_namespace |
889 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
891 error "(11) unexpected status"
894 run_test 9b "LFSCK speed control (2)"
900 echo "Preparing more files with error at $(date)."
901 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
902 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
904 for ((i = 0; i < 1000; i = $((i+2)))); do
905 mkdir -p $DIR/$tdir/d${i}
906 touch $DIR/$tdir/f${i}
907 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
910 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
911 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
913 for ((i = 1; i < 1000; i = $((i+2)))); do
914 mkdir -p $DIR/$tdir/d${i}
915 touch $DIR/$tdir/f${i}
916 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
919 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
920 echo "Prepared at $(date)."
922 ln $DIR/$tdir/f200 $DIR/$tdir/d200/dummy
925 mount_client $MOUNT || error "(3) Fail to start client!"
927 $START_NAMESPACE -r -s 100 || error "(5) Fail to start LFSCK!"
930 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
931 [ "$STATUS" == "scanning-phase1" ] ||
932 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
934 ls -ailR $MOUNT > /dev/null || error "(7) Fail to ls!"
936 touch $DIR/$tdir/d198/a0 || error "(8) Fail to touch!"
938 mkdir $DIR/$tdir/d199/a1 || error "(9) Fail to mkdir!"
940 unlink $DIR/$tdir/f200 || error "(10) Fail to unlink!"
942 rm -rf $DIR/$tdir/d201 || error "(11) Fail to rmdir!"
944 mv $DIR/$tdir/f202 $DIR/$tdir/d203/ || error "(12) Fail to rename!"
946 ln $DIR/$tdir/f204 $DIR/$tdir/d205/a3 || error "(13) Fail to hardlink!"
948 ln -s $DIR/$tdir/d206 $DIR/$tdir/d207/a4 ||
949 error "(14) Fail to softlink!"
951 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
952 [ "$STATUS" == "scanning-phase1" ] ||
953 error "(15) Expect 'scanning-phase1', but got '$STATUS'"
955 do_facet $SINGLEMDS \
956 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
957 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
958 mdd.${MDT_DEV}.lfsck_namespace |
959 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
961 error "(16) unexpected status"
964 run_test 10 "System is available during LFSCK scanning"
966 $LCTL set_param debug=-lfsck > /dev/null || true
968 # restore MDS/OST size
969 MDSSIZE=${SAVED_MDSSIZE}
970 OSTSIZE=${SAVED_OSTSIZE}
971 OSTCOUNT=${SAVED_OSTCOUNT}
973 # cleanup the system at last