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 # use small MDS + OST size to speed formatting time
28 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
32 check_and_setup_lustre
35 $LCTL set_param debug=+lfsck > /dev/null || true
37 MDT_DEV="${FSNAME}-MDT0000"
38 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
39 START_NAMESPACE="do_facet $SINGLEMDS \
40 $LCTL lfsck_start -M ${MDT_DEV} -t namespace"
41 STOP_LFSCK="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
42 SHOW_NAMESPACE="do_facet $SINGLEMDS \
43 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace"
44 MOUNT_OPTS_SCRUB="-o user_xattr"
45 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
55 if [ ! -z $igif ]; then
56 #define OBD_FAIL_FID_IGIF 0x1504
57 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
63 echo "preparing... ${nfiles} * ${ndirs} files will be created."
65 cp $LUSTRE/tests/*.sh $DIR/$tdir/
66 for ((i=0; i<${ndirs}; i++)); do
67 mkdir $DIR/$tdir/d${i}
68 touch $DIR/$tdir/f${i}
69 for ((j=0; j<${nfiles}; j++)); do
70 touch $DIR/$tdir/d${i}/f${j}
72 mkdir $DIR/$tdir/e${i}
75 if [ ! -z $igif ]; then
76 touch $DIR/$tdir/dummy
77 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
81 cleanup_mount $MOUNT > /dev/null || error "Fail to stop client!"
82 echo "stop $SINGLEMDS"
83 stop $SINGLEMDS > /dev/null || error "Fail to stop MDS!"
88 echo "start $SINGLEMDS"
89 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
90 error "(1) Fail to start MDS!"
92 #define OBD_FAIL_LFSCK_DELAY1 0x1600
93 do_facet $SINGLEMDS $LCTL set_param fail_val=3
94 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
95 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
97 $SHOW_NAMESPACE || error "Fail to monitor LFSCK (3)"
99 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
100 [ "$STATUS" == "scanning-phase1" ] ||
101 error "(4) Expect 'scanning-phase1', but got '$STATUS'"
103 $STOP_LFSCK || error "(5) Fail to stop LFSCK!"
105 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
106 [ "$STATUS" == "stopped" ] ||
107 error "(6) Expect 'stopped', but got '$STATUS'"
109 $START_NAMESPACE || error "(7) Fail to start LFSCK for namespace!"
111 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
112 [ "$STATUS" == "scanning-phase1" ] ||
113 error "(8) Expect 'scanning-phase1', but got '$STATUS'"
115 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
116 do_facet $SINGLEMDS $LCTL set_param fail_val=0
118 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
119 [ "$STATUS" == "completed" ] ||
120 error "(9) Expect 'completed', but got '$STATUS'"
122 local repaired=$($SHOW_NAMESPACE |
123 awk '/^updated_phase1/ { print $2 }')
124 [ $repaired -eq 0 ] ||
125 error "(10) Expect nothing to be repaired, but got: $repaired"
127 run_test 0 "Control LFSCK manually"
131 echo "start $SINGLEMDS"
132 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
133 error "(1) Fail to start MDS!"
135 mount_client $MOUNT || error "(2) Fail to start client!"
137 #define OBD_FAIL_FID_INDIR 0x1501
138 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1501
139 touch $DIR/$tdir/dummy
141 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
143 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
146 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
147 [ "$STATUS" == "completed" ] ||
148 error "(4) Expect 'completed', but got '$STATUS'"
150 local repaired=$($SHOW_NAMESPACE |
151 awk '/^updated_phase1/ { print $2 }')
152 [ $repaired -eq 1 ] ||
153 error "(5) Fail to repair crashed FID-in-dirent: $repaired"
155 mount_client $MOUNT || error "(6) Fail to start client!"
157 #define OBD_FAIL_FID_LOOKUP 0x1505
158 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
159 ls $DIR/$tdir/ > /dev/null || error "(7) no FID-in-dirent."
161 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
163 run_test 1a "LFSCK can find out and repair crashed FID-in-dirent"
168 echo "start $SINGLEMDS"
169 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
170 error "(1) Fail to start MDS!"
172 mount_client $MOUNT || error "(2) Fail to start client!"
174 #define OBD_FAIL_FID_INLMA 0x1502
175 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1502
176 touch $DIR/$tdir/dummy
178 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
180 #define OBD_FAIL_FID_NOLMA 0x1506
181 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1506
182 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
185 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
186 [ "$STATUS" == "completed" ] ||
187 error "(4) Expect 'completed', but got '$STATUS'"
189 local repaired=$($SHOW_NAMESPACE |
190 awk '/^updated_phase1/ { print $2 }')
191 [ $repaired -eq 1 ] ||
192 error "(5) Fail to repair missed FID-in-LMA: $repaired"
194 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
195 mount_client $MOUNT || error "(6) Fail to start client!"
197 #define OBD_FAIL_FID_LOOKUP 0x1505
198 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
199 stat $DIR/$tdir/dummy > /dev/null || error "(7) no FID-in-LMA."
201 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
203 run_test 1b "LFSCK can find out and repair missed FID-in-LMA"
207 echo "start $SINGLEMDS"
208 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
209 error "(1) Fail to start MDS!"
211 mount_client $MOUNT || error "(2) Fail to start client!"
213 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
214 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
215 touch $DIR/$tdir/dummy
217 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
219 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
222 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
223 [ "$STATUS" == "completed" ] ||
224 error "(4) Expect 'completed', but got '$STATUS'"
226 local repaired=$($SHOW_NAMESPACE |
227 awk '/^updated_phase1/ { print $2 }')
228 [ $repaired -eq 1 ] ||
229 error "(5) Fail to repair crashed linkEA: $repaired"
231 mount_client $MOUNT || error "(6) Fail to start client!"
233 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
234 error "(7) Fail to stat $DIR/$tdir/dummy"
236 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
237 local dummyname=$($LFS fid2path $DIR $dummyfid)
238 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
239 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
241 run_test 2a "LFSCK can find out and repair crashed linkEA entry"
246 echo "start $SINGLEMDS"
247 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
248 error "(1) Fail to start MDS!"
250 mount_client $MOUNT || error "(2) Fail to start client!"
252 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
253 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
254 touch $DIR/$tdir/dummy
256 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
258 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
261 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
262 [ "$STATUS" == "completed" ] ||
263 error "(4) Expect 'completed', but got '$STATUS'"
265 local repaired=$($SHOW_NAMESPACE |
266 awk '/^updated_phase2/ { print $2 }')
267 [ $repaired -eq 1 ] ||
268 error "(5) Fail to repair crashed linkEA: $repaired"
270 mount_client $MOUNT || error "(6) Fail to start client!"
272 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
273 error "(7) Fail to stat $DIR/$tdir/dummy"
275 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
276 local dummyname=$($LFS fid2path $DIR $dummyfid)
277 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
278 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
280 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
285 mds_backup_restore || error "(1) Fail to backup/restore!"
286 echo "start $SINGLEMDS with disabling OI scrub"
287 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
288 error "(2) Fail to start MDS!"
290 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
291 [ "$STATUS" == "init" ] ||
292 error "(3) Expect 'init', but got '$STATUS'"
294 #define OBD_FAIL_LFSCK_DELAY2 0x1601
295 do_facet $SINGLEMDS $LCTL set_param fail_val=1
296 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
297 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
300 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
301 [ "$STATUS" == "scanning-phase1" ] ||
302 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
304 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
305 [ "$FLAGS" == "inconsistent" ] ||
306 error "(6) Expect 'inconsistent', but got '$FLAGS'"
308 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
309 do_facet $SINGLEMDS $LCTL set_param fail_val=0
311 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
312 [ "$STATUS" == "completed" ] ||
313 error "(7) Expect 'completed', but got '$STATUS'"
315 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
316 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
318 local repaired=$($SHOW_NAMESPACE |
319 awk '/^updated_phase1/ { print $2 }')
320 [ $repaired -ge 9 ] ||
321 error "(9) Fail to repair crashed linkEA: $repaired"
323 mount_client $MOUNT || error "(10) Fail to start client!"
325 #define OBD_FAIL_FID_LOOKUP 0x1505
326 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
327 ls $DIR/$tdir/ > /dev/null || error "(11) no FID-in-dirent."
329 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
331 run_test 4 "FID-in-dirent can be rebuilt after MDT file-level backup/restore"
336 mds_backup_restore 1 || error "(1) Fail to backup/restore!"
337 echo "start $SINGLEMDS with disabling OI scrub"
338 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
339 error "(2) Fail to start MDS!"
341 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
342 [ "$STATUS" == "init" ] ||
343 error "(3) Expect 'init', but got '$STATUS'"
345 #define OBD_FAIL_LFSCK_DELAY2 0x1601
346 do_facet $SINGLEMDS $LCTL set_param fail_val=1
347 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
348 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
351 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
352 [ "$STATUS" == "scanning-phase1" ] ||
353 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
355 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
356 [ "$FLAGS" == "inconsistent,upgrade" ] ||
357 error "(6) Expect 'inconsistent,upgrade', but got '$FLAGS'"
359 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
360 do_facet $SINGLEMDS $LCTL set_param fail_val=0
362 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
363 [ "$STATUS" == "completed" ] ||
364 error "(7) Expect 'completed', but got '$STATUS'"
366 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
367 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
369 local repaired=$($SHOW_NAMESPACE |
370 awk '/^updated_phase1/ { print $2 }')
371 [ $repaired -ge 2 ] ||
372 error "(9) Fail to repair crashed linkEA: $repaired"
374 mount_client $MOUNT || error "(10) Fail to start client!"
376 #define OBD_FAIL_FID_LOOKUP 0x1505
377 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
378 stat $DIR/$tdir/dummy > /dev/null || error "(11) no FID-in-LMA."
380 ls $DIR/$tdir/ > /dev/null || error "(12) no FID-in-dirent."
382 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
383 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
384 local dummyname=$($LFS fid2path $DIR $dummyfid)
385 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
386 error "(13) Fail to generate linkEA: $dummyfid $dummyname"
388 run_test 5 "LFSCK can handle IFIG object upgrading"
392 echo "start $SINGLEMDS"
393 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
394 error "(1) Fail to start MDS!"
396 #define OBD_FAIL_LFSCK_DELAY1 0x1600
397 do_facet $SINGLEMDS $LCTL set_param fail_val=1
398 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
399 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
401 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
402 [ "$STATUS" == "scanning-phase1" ] ||
403 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
405 # Sleep 3 sec to guarantee at least one object processed by LFSCK
407 # Fail the LFSCK to guarantee there is at least one checkpoint
408 #define OBD_FAIL_LFSCK_FATAL1 0x1608
409 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001608
411 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
412 [ "$STATUS" == "failed" ] ||
413 error "(4) Expect 'failed', but got '$STATUS'"
415 local POSITION0=$($SHOW_NAMESPACE |
416 awk '/^last_checkpoint_position/ { print $2 }' |
419 #define OBD_FAIL_LFSCK_DELAY1 0x1600
420 do_facet $SINGLEMDS $LCTL set_param fail_val=1
421 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
422 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
424 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
425 [ "$STATUS" == "scanning-phase1" ] ||
426 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
428 local POSITION1=$($SHOW_NAMESPACE |
429 awk '/^latest_start_position/ { print $2 }' |
431 [ $POSITION0 -lt $POSITION1 ] ||
432 error "(7) Expect larger than: $POSITION0, but got $POSITION1"
434 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
435 do_facet $SINGLEMDS $LCTL set_param fail_val=0
437 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
438 [ "$STATUS" == "completed" ] ||
439 error "(8) Expect 'completed', but got '$STATUS'"
441 run_test 6a "LFSCK resumes from last checkpoint (1)"
445 echo "start $SINGLEMDS"
446 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
447 error "(1) Fail to start MDS!"
449 #define OBD_FAIL_LFSCK_DELAY2 0x1601
450 do_facet $SINGLEMDS $LCTL set_param fail_val=1
451 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
452 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
454 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
455 [ "$STATUS" == "scanning-phase1" ] ||
456 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
458 # Sleep 3 sec to guarantee at least one object processed by LFSCK
460 # Fail the LFSCK to guarantee there is at least one checkpoint
461 #define OBD_FAIL_LFSCK_FATAL2 0x1609
462 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
464 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
465 [ "$STATUS" == "failed" ] ||
466 error "(4) Expect 'failed', but got '$STATUS'"
468 local POSITION0=$($SHOW_NAMESPACE |
469 awk '/^last_checkpoint_position/ { print $4 }')
471 #define OBD_FAIL_LFSCK_DELAY2 0x1601
472 do_facet $SINGLEMDS $LCTL set_param fail_val=1
473 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
474 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
476 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
477 [ "$STATUS" == "scanning-phase1" ] ||
478 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
480 local POSITION1=$($SHOW_NAMESPACE |
481 awk '/^latest_start_position/ { print $4 }')
482 if [ $POSITION0 -gt $POSITION1 ]; then
483 [ $POSITION1 -eq 0 -a $POSITINO0 -eq $((POSITION1 + 1)) ] ||
484 error "(7) Expect larger than: $POSITION0, but got $POSITION1"
487 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
488 do_facet $SINGLEMDS $LCTL set_param fail_val=0
490 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
491 [ "$STATUS" == "completed" ] ||
492 error "(8) Expect 'completed', but got '$STATUS'"
494 run_test 6b "LFSCK resumes from last checkpoint (2)"
499 echo "start $SINGLEMDS"
500 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
501 error "(1) Fail to start MDS!"
503 #define OBD_FAIL_LFSCK_DELAY2 0x1601
504 do_facet $SINGLEMDS $LCTL set_param fail_val=1
505 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
506 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
508 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
509 [ "$STATUS" == "scanning-phase1" ] ||
510 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
512 # Sleep 3 sec to guarantee at least one object processed by LFSCK
514 echo "stop $SINGLEMDS"
515 stop $SINGLEMDS > /dev/null || error "(4) Fail to stop MDS!"
517 echo "start $SINGLEMDS"
518 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
519 error "(5) Fail to start MDS!"
521 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
522 [ "$STATUS" == "scanning-phase1" ] ||
523 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
525 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
526 do_facet $SINGLEMDS $LCTL set_param fail_val=0
528 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
529 [ "$STATUS" == "completed" ] ||
530 error "(7) Expect 'completed', but got '$STATUS'"
532 run_test 7a "non-stopped LFSCK should auto restarts after MDS remount (1)"
537 echo "start $SINGLEMDS"
538 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
539 error "(1) Fail to start MDS!"
541 mount_client $MOUNT || error "(2) Fail to start client!"
543 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
544 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
545 for ((i=0; i<10; i++)); do
546 touch $DIR/$tdir/dummy${i}
549 #define OBD_FAIL_LFSCK_DELAY3 0x1602
550 do_facet $SINGLEMDS $LCTL set_param fail_val=1
551 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1602
552 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
555 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
556 [ "$STATUS" == "scanning-phase2" ] ||
557 error "(4) Expect 'scanning-phase2', but got '$STATUS'"
559 echo "stop $SINGLEMDS"
560 stop $SINGLEMDS > /dev/null || error "(5) Fail to stop MDS!"
562 echo "start $SINGLEMDS"
563 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
564 error "(6) Fail to start MDS!"
566 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
567 [ "$STATUS" == "scanning-phase2" ] ||
568 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
570 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
571 do_facet $SINGLEMDS $LCTL set_param fail_val=0
573 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
574 [ "$STATUS" == "completed" ] ||
575 error "(8) Expect 'completed', but got '$STATUS'"
577 run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
582 echo "start $SINGLEMDS"
583 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
584 error "(1) Fail to start MDS!"
586 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
587 [ "$STATUS" == "init" ] ||
588 error "(2) Expect 'init', but got '$STATUS'"
590 mount_client $MOUNT || error "(3) Fail to start client!"
592 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
593 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
594 mkdir $DIR/$tdir/crashed
596 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
597 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
598 for ((i=0; i<5; i++)); do
599 touch $DIR/$tdir/dummy${i}
602 #define OBD_FAIL_LFSCK_DELAY2 0x1601
603 do_facet $SINGLEMDS $LCTL set_param fail_val=2
604 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
605 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
607 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
608 [ "$STATUS" == "scanning-phase1" ] ||
609 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
611 $STOP_LFSCK || error "(6) Fail to stop LFSCK!"
613 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
614 [ "$STATUS" == "stopped" ] ||
615 error "(7) Expect 'stopped', but got '$STATUS'"
617 $START_NAMESPACE || error "(8) Fail to start LFSCK for namespace!"
619 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
620 [ "$STATUS" == "scanning-phase1" ] ||
621 error "(9) Expect 'scanning-phase1', but got '$STATUS'"
623 #define OBD_FAIL_LFSCK_FATAL2 0x1609
624 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
626 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
627 [ "$STATUS" == "failed" ] ||
628 error "(10) Expect 'failed', but got '$STATUS'"
630 #define OBD_FAIL_LFSCK_DELAY1 0x1600
631 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
632 $START_NAMESPACE || error "(11) Fail to start LFSCK for namespace!"
634 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
635 [ "$STATUS" == "scanning-phase1" ] ||
636 error "(12) Expect 'scanning-phase1', but got '$STATUS'"
638 #define OBD_FAIL_LFSCK_CRASH 0x160a
639 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160a
642 echo "stop $SINGLEMDS"
643 stop $SINGLEMDS > /dev/null || error "(13) Fail to stop MDS!"
645 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
646 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
648 echo "start $SINGLEMDS"
649 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
650 error "(14) Fail to start MDS!"
652 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
653 [ "$STATUS" == "crashed" ] ||
654 error "(15) Expect 'crashed', but got '$STATUS'"
656 #define OBD_FAIL_LFSCK_DELAY2 0x1601
657 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
658 $START_NAMESPACE || error "(16) Fail to start LFSCK for namespace!"
660 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
661 [ "$STATUS" == "scanning-phase1" ] ||
662 error "(17) Expect 'scanning-phase1', but got '$STATUS'"
664 echo "stop $SINGLEMDS"
665 stop $SINGLEMDS > /dev/null || error "(18) Fail to stop MDS!"
667 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
668 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
670 echo "start $SINGLEMDS"
671 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
672 error "(19) Fail to start MDS!"
674 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
675 [ "$STATUS" == "paused" ] ||
676 error "(20) Expect 'paused', but got '$STATUS'"
678 #define OBD_FAIL_LFSCK_DELAY3 0x1602
679 do_facet $SINGLEMDS $LCTL set_param fail_val=2
680 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1602
682 $START_NAMESPACE || error "(21) Fail to start LFSCK for namespace!"
684 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
685 [ "$STATUS" == "scanning-phase2" ] ||
686 error "(22) Expect 'scanning-phase2', but got '$STATUS'"
688 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
689 [ "$FLAGS" == "scanned-once,inconsistent" ] ||
690 error "(23) Expect 'scanned-once,inconsistent',but got '$FLAGS'"
692 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
693 do_facet $SINGLEMDS $LCTL set_param fail_val=0
695 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
696 [ "$STATUS" == "completed" ] ||
697 error "(24) Expect 'completed', but got '$STATUS'"
699 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
700 [ -z "$FLAGS" ] || error "(25) Expect empty flags, but got '$FLAGS'"
703 run_test 8 "LFSCK state machine"
706 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
707 skip "Testing on UP system, the speed may be inaccurate."
712 echo "start $SINGLEMDS"
713 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
714 error "(1) Fail to start MDS!"
716 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
717 [ "$STATUS" == "init" ] ||
718 error "(2) Expect 'init', but got '$STATUS'"
720 $START_NAMESPACE -s 100 || error "(3) Fail to start LFSCK!"
723 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
724 [ "$STATUS" == "scanning-phase1" ] ||
725 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
727 local SPEED=$($SHOW_NAMESPACE |
728 awk '/^average_speed_phase1/ { print $2 }')
729 # (100 * (10 + 1)) / 10 = 110
730 [ $SPEED -lt 120 ] ||
731 error "(4) Unexpected speed $SPEED, should not more than 120"
734 do_facet $SINGLEMDS \
735 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 300
738 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
739 # (100 * (10 - 1) + 300 * (10 - 1)) / 20 = 180
740 [ $SPEED -lt 170 ] &&
741 error "(5) Unexpected speed $SPEED, should not less than 170"
743 # (100 * (10 + 1) + 300 * (10 + 1)) / 20 = 220
744 [ $SPEED -lt 230 ] ||
745 error "(6) Unexpected speed $SPEED, should not more than 230"
747 do_facet $SINGLEMDS \
748 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
750 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
751 [ "$STATUS" == "completed" ] ||
752 error "(7) Expect 'completed', but got '$STATUS'"
754 run_test 9a "LFSCK speed control (1)"
757 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
758 skip "Testing on UP system, the speed may be inaccurate."
763 echo "start $SINGLEMDS"
764 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
765 error "(1) Fail to start MDS!"
767 mount_client $MOUNT || error "(2) Fail to start client!"
769 echo "Another preparing... 50 * 50 files (with error) will be created."
770 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
771 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
772 for ((i=0; i<50; i++)); do
773 mkdir -p $DIR/$tdir/d${i}
774 touch $DIR/$tdir/f${i}
775 for ((j=0; j<50; j++)); do
776 touch $DIR/$tdir/d${i}/f${j}
780 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
781 [ "$STATUS" == "init" ] ||
782 error "(3) Expect 'init', but got '$STATUS'"
784 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN 0x160c
785 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160c
786 $START_NAMESPACE || error "(4) Fail to start LFSCK!"
789 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
790 [ "$STATUS" == "stopped" ] ||
791 error "(5) Expect 'stopped', but got '$STATUS'"
793 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
794 $START_NAMESPACE -s 50 || error "(6) Fail to start LFSCK!"
797 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
798 [ "$STATUS" == "scanning-phase2" ] ||
799 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
801 local SPEED=$($SHOW_NAMESPACE |
802 awk '/^average_speed_phase2/ { print $2 }')
803 # (50 * (10 + 1)) / 10 = 55
805 error "(8) Unexpected speed $SPEED, should not more than 60"
808 do_facet $SINGLEMDS \
809 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 150
812 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
813 # (50 * (10 - 1) + 150 * (10 - 1)) / 20 = 90
815 error "(9) Unexpected speed $SPEED, should not less than 85"
817 # (50 * (10 + 1) + 150 * (10 + 1)) / 20 = 110
818 [ $SPEED -lt 115 ] ||
819 error "(10) Unexpected speed $SPEED, should not more than 115"
821 do_facet $SINGLEMDS \
822 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
824 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
825 [ "$STATUS" == "completed" ] ||
826 error "(11) Expect 'completed', but got '$STATUS'"
828 run_test 9b "LFSCK speed control (2)"
833 echo "start $SINGLEMDS"
834 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
835 error "(1) Fail to start MDS!"
837 mount_client $MOUNT || error "(2) Fail to start client!"
839 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
840 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
841 for ((i=0; i<1000; i=$((i+2)))); do
842 mkdir -p $DIR/$tdir/d${i}
843 touch $DIR/$tdir/f${i}
844 for ((j=0; j<5; j++)); do
845 touch $DIR/$tdir/d${i}/f${j}
849 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
850 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
851 for ((i=1; i<1000; i=$((i+2)))); do
852 mkdir -p $DIR/$tdir/d${i}
853 touch $DIR/$tdir/f${i}
854 for ((j=0; j<5; j++)); do
855 touch $DIR/$tdir/d${i}/f${j}
859 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
860 ln $DIR/$tdir/f200 $DIR/$tdir/d200/dummy
863 mount_client $MOUNT || error "(3) Fail to start client!"
865 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
866 [ "$STATUS" == "init" ] ||
867 error "(4) Expect 'init', but got '$STATUS'"
869 $START_NAMESPACE -s 100 || error "(5) Fail to start LFSCK!"
872 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
873 [ "$STATUS" == "scanning-phase1" ] ||
874 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
876 ls -ailR $MOUNT > /dev/null || error "(7) Fail to ls!"
878 touch $DIR/$tdir/d198/a0 || error "(8) Fail to touch!"
880 mkdir $DIR/$tdir/d199/a1 || error "(9) Fail to mkdir!"
882 unlink $DIR/$tdir/f200 || error "(10) Fail to unlink!"
884 rm -rf $DIR/$tdir/d201 || error "(11) Fail to rmdir!"
886 mv $DIR/$tdir/f202 $DIR/$tdir/d203/ || error "(12) Fail to rename!"
888 ln $DIR/$tdir/f204 $DIR/$tdir/d205/a3 || error "(13) Fail to hardlink!"
890 ln -s $DIR/$tdir/d206 $DIR/$tdir/d207/a4 ||
891 error "(14) Fail to softlink!"
893 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
894 [ "$STATUS" == "scanning-phase1" ] ||
895 error "(15) Expect 'scanning-phase1', but got '$STATUS'"
897 do_facet $SINGLEMDS \
898 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
901 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
902 [ "$STATUS" == "completed" ] ||
903 error "(16) Expect 'completed', but got '$STATUS'"
905 run_test 10 "System is available during LFSCK scanning"
907 $LCTL set_param debug=-lfsck > /dev/null || true
909 # restore MDS/OST size
910 MDSSIZE=${SAVED_MDSSIZE}
911 OSTSIZE=${SAVED_OSTSIZE}
913 # cleanup the system at last