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
34 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.60) ]] &&
35 skip "Need MDS version at least 2.3.60" && check_and_cleanup_lustre &&
40 $LCTL set_param debug=+lfsck > /dev/null || true
42 MDT_DEV="${FSNAME}-MDT0000"
43 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
44 START_NAMESPACE="do_facet $SINGLEMDS \
45 $LCTL lfsck_start -M ${MDT_DEV} -t namespace"
46 STOP_LFSCK="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
47 SHOW_NAMESPACE="do_facet $SINGLEMDS \
48 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace"
49 MOUNT_OPTS_SCRUB="-o user_xattr"
50 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
63 if [ ! -z $igif ]; then
64 #define OBD_FAIL_FID_IGIF 0x1504
65 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
68 echo "preparing... ${nfiles} * ${ndirs} files will be created."
70 cp $LUSTRE/tests/*.sh $DIR/
71 for ((i = 0; i < ${ndirs}; i++)); do
72 mkdir $DIR/$tdir/d${i}
73 touch $DIR/$tdir/f${i}
74 for ((j = 0; j < ${nfiles}; j++)); do
75 touch $DIR/$tdir/d${i}/f${j}
77 mkdir $DIR/$tdir/e${i}
80 if [ ! -z $igif ]; then
81 touch $DIR/$tdir/dummy
82 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
86 cleanup_mount $MOUNT > /dev/null || error "Fail to stop client!"
87 echo "stop $SINGLEMDS"
88 stop $SINGLEMDS > /dev/null || error "Fail to stop MDS!"
93 echo "start $SINGLEMDS"
94 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
95 error "(1) Fail to start MDS!"
97 #define OBD_FAIL_LFSCK_DELAY1 0x1600
98 do_facet $SINGLEMDS $LCTL set_param fail_val=3
99 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
100 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
102 $SHOW_NAMESPACE || error "Fail to monitor LFSCK (3)"
104 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
105 [ "$STATUS" == "scanning-phase1" ] ||
106 error "(4) Expect 'scanning-phase1', but got '$STATUS'"
108 $STOP_LFSCK || error "(5) Fail to stop LFSCK!"
110 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
111 [ "$STATUS" == "stopped" ] ||
112 error "(6) Expect 'stopped', but got '$STATUS'"
114 $START_NAMESPACE || error "(7) Fail to start LFSCK for namespace!"
116 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
117 [ "$STATUS" == "scanning-phase1" ] ||
118 error "(8) Expect 'scanning-phase1', but got '$STATUS'"
120 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
121 do_facet $SINGLEMDS $LCTL set_param fail_val=0
123 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
124 [ "$STATUS" == "completed" ] ||
125 error "(9) Expect 'completed', but got '$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!"
136 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
137 [ "$STATUS" == "completed" ] ||
138 error "(12) Expect 'completed', but got '$STATUS'"
140 local scanned2=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
141 [ $((scanned1 + 1)) -eq $scanned2 ] ||
142 error "(13) Expect success $((scanned1 + 1)), but got $scanned2"
144 echo "stopall, should NOT crash LU-3649"
147 run_test 0 "Control LFSCK manually"
151 echo "start $SINGLEMDS"
152 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
153 error "(1) Fail to start MDS!"
155 mount_client $MOUNT || error "(2) Fail to start client!"
157 #define OBD_FAIL_FID_INDIR 0x1501
158 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1501
159 touch $DIR/$tdir/dummy
161 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
163 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
166 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
167 [ "$STATUS" == "completed" ] ||
168 error "(4) Expect 'completed', but got '$STATUS'"
170 local repaired=$($SHOW_NAMESPACE |
171 awk '/^updated_phase1/ { print $2 }')
172 [ $repaired -eq 1 ] ||
173 error "(5) Fail to repair crashed FID-in-dirent: $repaired"
175 mount_client $MOUNT || error "(6) Fail to start client!"
177 #define OBD_FAIL_FID_LOOKUP 0x1505
178 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
179 ls $DIR/$tdir/ > /dev/null || error "(7) no FID-in-dirent."
181 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
183 run_test 1a "LFSCK can find out and repair crashed FID-in-dirent"
188 echo "start $SINGLEMDS"
189 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
190 error "(1) Fail to start MDS!"
192 mount_client $MOUNT || error "(2) Fail to start client!"
194 #define OBD_FAIL_FID_INLMA 0x1502
195 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1502
196 touch $DIR/$tdir/dummy
198 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
200 #define OBD_FAIL_FID_NOLMA 0x1506
201 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1506
202 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
205 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
206 [ "$STATUS" == "completed" ] ||
207 error "(4) Expect 'completed', but got '$STATUS'"
209 local repaired=$($SHOW_NAMESPACE |
210 awk '/^updated_phase1/ { print $2 }')
211 [ $repaired -eq 1 ] ||
212 error "(5) Fail to repair missed FID-in-LMA: $repaired"
214 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
215 mount_client $MOUNT || error "(6) Fail to start client!"
217 #define OBD_FAIL_FID_LOOKUP 0x1505
218 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
219 stat $DIR/$tdir/dummy > /dev/null || error "(7) no FID-in-LMA."
221 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
223 run_test 1b "LFSCK can find out and repair missed FID-in-LMA"
227 echo "start $SINGLEMDS"
228 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
229 error "(1) Fail to start MDS!"
231 mount_client $MOUNT || error "(2) Fail to start client!"
233 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
234 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
235 touch $DIR/$tdir/dummy
237 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
239 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
242 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
243 [ "$STATUS" == "completed" ] ||
244 error "(4) Expect 'completed', but got '$STATUS'"
246 local repaired=$($SHOW_NAMESPACE |
247 awk '/^updated_phase1/ { print $2 }')
248 [ $repaired -eq 1 ] ||
249 error "(5) Fail to repair crashed linkEA: $repaired"
251 mount_client $MOUNT || error "(6) Fail to start client!"
253 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
254 error "(7) Fail to stat $DIR/$tdir/dummy"
256 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
257 local dummyname=$($LFS fid2path $DIR $dummyfid)
258 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
259 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
261 run_test 2a "LFSCK can find out and repair crashed linkEA entry"
266 echo "start $SINGLEMDS"
267 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
268 error "(1) Fail to start MDS!"
270 mount_client $MOUNT || error "(2) Fail to start client!"
272 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
273 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
274 touch $DIR/$tdir/dummy
276 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
278 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
281 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
282 [ "$STATUS" == "completed" ] ||
283 error "(4) Expect 'completed', but got '$STATUS'"
285 local repaired=$($SHOW_NAMESPACE |
286 awk '/^updated_phase2/ { print $2 }')
287 [ $repaired -eq 1 ] ||
288 error "(5) Fail to repair crashed linkEA: $repaired"
290 mount_client $MOUNT || error "(6) Fail to start client!"
292 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
293 error "(7) Fail to stat $DIR/$tdir/dummy"
295 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
296 local dummyname=$($LFS fid2path $DIR $dummyfid)
297 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
298 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
300 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
305 echo "start $SINGLEMDS"
306 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
307 error "(1) Fail to start MDS!"
309 mount_client $MOUNT || error "(2) Fail to start client!"
311 #define OBD_FAIL_LFSCK_LINKEA_MORE2 0x1605
312 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1605
313 touch $DIR/$tdir/dummy
315 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
317 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
320 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
321 [ "$STATUS" == "completed" ] ||
322 error "(4) Expect 'completed', but got '$STATUS'"
324 local repaired=$($SHOW_NAMESPACE |
325 awk '/^updated_phase2/ { print $2 }')
326 [ $repaired -eq 1 ] ||
327 error "(5) Fail to repair crashed linkEA: $repaired"
329 mount_client $MOUNT || error "(6) Fail to start client!"
331 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
332 error "(7) Fail to stat $DIR/$tdir/dummy"
334 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
335 local dummyname=$($LFS fid2path $DIR $dummyfid)
336 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
337 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
339 run_test 2c "LFSCK can find out and remove repeated linkEA entry"
344 mds_backup_restore || error "(1) Fail to backup/restore!"
345 echo "start $SINGLEMDS with disabling OI scrub"
346 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
347 error "(2) Fail to start MDS!"
349 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
350 [ "$STATUS" == "init" ] ||
351 error "(3) Expect 'init', but got '$STATUS'"
353 #define OBD_FAIL_LFSCK_DELAY2 0x1601
354 do_facet $SINGLEMDS $LCTL set_param fail_val=1
355 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
356 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
359 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
360 [ "$STATUS" == "scanning-phase1" ] ||
361 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
363 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
364 [ "$FLAGS" == "inconsistent" ] ||
365 error "(6) Expect 'inconsistent', but got '$FLAGS'"
367 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
368 do_facet $SINGLEMDS $LCTL set_param fail_val=0
370 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
371 [ "$STATUS" == "completed" ] ||
372 error "(7) Expect 'completed', but got '$STATUS'"
374 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
375 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
377 local repaired=$($SHOW_NAMESPACE |
378 awk '/^updated_phase1/ { print $2 }')
379 [ $repaired -ge 9 ] ||
380 error "(9) Fail to repair crashed linkEA: $repaired"
382 mount_client $MOUNT || error "(10) Fail to start client!"
384 #define OBD_FAIL_FID_LOOKUP 0x1505
385 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
386 ls $DIR/$tdir/ > /dev/null || error "(11) no FID-in-dirent."
388 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
390 run_test 4 "FID-in-dirent can be rebuilt after MDT file-level backup/restore"
395 mds_backup_restore 1 || error "(1) Fail to backup/restore!"
396 echo "start $SINGLEMDS with disabling OI scrub"
397 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
398 error "(2) Fail to start MDS!"
400 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
401 [ "$STATUS" == "init" ] ||
402 error "(3) Expect 'init', but got '$STATUS'"
404 #define OBD_FAIL_LFSCK_DELAY2 0x1601
405 do_facet $SINGLEMDS $LCTL set_param fail_val=1
406 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
407 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
410 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
411 [ "$STATUS" == "scanning-phase1" ] ||
412 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
414 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
415 [ "$FLAGS" == "inconsistent,upgrade" ] ||
416 error "(6) Expect 'inconsistent,upgrade', but got '$FLAGS'"
418 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
419 do_facet $SINGLEMDS $LCTL set_param fail_val=0
421 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
422 [ "$STATUS" == "completed" ] ||
423 error "(7) Expect 'completed', but got '$STATUS'"
425 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
426 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
428 local repaired=$($SHOW_NAMESPACE |
429 awk '/^updated_phase1/ { print $2 }')
430 [ $repaired -ge 2 ] ||
431 error "(9) Fail to repair crashed linkEA: $repaired"
433 mount_client $MOUNT || error "(10) Fail to start client!"
435 #define OBD_FAIL_FID_LOOKUP 0x1505
436 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
437 stat $DIR/$tdir/dummy > /dev/null || error "(11) no FID-in-LMA."
439 ls $DIR/$tdir/ > /dev/null || error "(12) no FID-in-dirent."
441 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
442 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
443 local dummyname=$($LFS fid2path $DIR $dummyfid)
444 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
445 error "(13) Fail to generate linkEA: $dummyfid $dummyname"
447 run_test 5 "LFSCK can handle IFIG object upgrading"
451 echo "start $SINGLEMDS"
452 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
453 error "(1) Fail to start MDS!"
455 #define OBD_FAIL_LFSCK_DELAY1 0x1600
456 do_facet $SINGLEMDS $LCTL set_param fail_val=1
457 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
458 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
460 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
461 [ "$STATUS" == "scanning-phase1" ] ||
462 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
464 # Sleep 3 sec to guarantee at least one object processed by LFSCK
466 # Fail the LFSCK to guarantee there is at least one checkpoint
467 #define OBD_FAIL_LFSCK_FATAL1 0x1608
468 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001608
470 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
471 [ "$STATUS" == "failed" ] ||
472 error "(4) Expect 'failed', but got '$STATUS'"
474 local POSITION0=$($SHOW_NAMESPACE |
475 awk '/^last_checkpoint_position/ { print $2 }' |
478 #define OBD_FAIL_LFSCK_DELAY1 0x1600
479 do_facet $SINGLEMDS $LCTL set_param fail_val=1
480 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
481 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
483 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
484 [ "$STATUS" == "scanning-phase1" ] ||
485 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
487 local POSITION1=$($SHOW_NAMESPACE |
488 awk '/^latest_start_position/ { print $2 }' |
490 [ $POSITION0 -lt $POSITION1 ] ||
491 error "(7) Expect larger than: $POSITION0, but got $POSITION1"
493 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
494 do_facet $SINGLEMDS $LCTL set_param fail_val=0
496 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
497 [ "$STATUS" == "completed" ] ||
498 error "(8) Expect 'completed', but got '$STATUS'"
500 run_test 6a "LFSCK resumes from last checkpoint (1)"
504 echo "start $SINGLEMDS"
505 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
506 error "(1) Fail to start MDS!"
508 #define OBD_FAIL_LFSCK_DELAY2 0x1601
509 do_facet $SINGLEMDS $LCTL set_param fail_val=1
510 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
511 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
513 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
514 [ "$STATUS" == "scanning-phase1" ] ||
515 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
517 # Sleep 3 sec to guarantee at least one object processed by LFSCK
519 # Fail the LFSCK to guarantee there is at least one checkpoint
520 #define OBD_FAIL_LFSCK_FATAL2 0x1609
521 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
523 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
524 [ "$STATUS" == "failed" ] ||
525 error "(4) Expect 'failed', but got '$STATUS'"
527 local POSITION0=$($SHOW_NAMESPACE |
528 awk '/^last_checkpoint_position/ { print $4 }')
530 #define OBD_FAIL_LFSCK_DELAY2 0x1601
531 do_facet $SINGLEMDS $LCTL set_param fail_val=1
532 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
533 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
535 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
536 [ "$STATUS" == "scanning-phase1" ] ||
537 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
539 local POSITION1=$($SHOW_NAMESPACE |
540 awk '/^latest_start_position/ { print $4 }')
541 if [ $POSITION0 -gt $POSITION1 ]; then
542 [ $POSITION1 -eq 0 -a $POSITION0 -eq $((POSITION1 + 1)) ] ||
543 error "(7) Expect larger than: $POSITION0, but got $POSITION1"
546 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
547 do_facet $SINGLEMDS $LCTL set_param fail_val=0
549 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
550 [ "$STATUS" == "completed" ] ||
551 error "(8) Expect 'completed', but got '$STATUS'"
553 run_test 6b "LFSCK resumes from last checkpoint (2)"
558 echo "start $SINGLEMDS"
559 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
560 error "(1) Fail to start MDS!"
562 #define OBD_FAIL_LFSCK_DELAY2 0x1601
563 do_facet $SINGLEMDS $LCTL set_param fail_val=1
564 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
565 $START_NAMESPACE || error "(2) Fail to start LFSCK for namespace!"
567 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
568 [ "$STATUS" == "scanning-phase1" ] ||
569 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
571 # Sleep 3 sec to guarantee at least one object processed by LFSCK
573 echo "stop $SINGLEMDS"
574 stop $SINGLEMDS > /dev/null || error "(4) Fail to stop MDS!"
576 echo "start $SINGLEMDS"
577 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
578 error "(5) Fail to start MDS!"
580 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
581 [ "$STATUS" == "scanning-phase1" ] ||
582 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
584 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
585 do_facet $SINGLEMDS $LCTL set_param fail_val=0
587 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
588 [ "$STATUS" == "completed" ] ||
589 error "(7) Expect 'completed', but got '$STATUS'"
591 run_test 7a "non-stopped LFSCK should auto restarts after MDS remount (1)"
596 echo "start $SINGLEMDS"
597 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
598 error "(1) Fail to start MDS!"
600 mount_client $MOUNT || error "(2) Fail to start client!"
602 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
603 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
604 for ((i = 0; i < 20; i++)); do
605 touch $DIR/$tdir/dummy${i}
608 #define OBD_FAIL_LFSCK_DELAY3 0x1602
609 do_facet $SINGLEMDS $LCTL set_param fail_val=1
610 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1602
611 $START_NAMESPACE || error "(3) Fail to start LFSCK for namespace!"
614 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
615 [ "$STATUS" == "scanning-phase2" ] ||
616 error "(4) Expect 'scanning-phase2', but got '$STATUS'"
618 echo "stop $SINGLEMDS"
619 stop $SINGLEMDS > /dev/null || error "(5) Fail to stop MDS!"
621 echo "start $SINGLEMDS"
622 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
623 error "(6) Fail to start MDS!"
625 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
626 [ "$STATUS" == "scanning-phase2" ] ||
627 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
629 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
630 do_facet $SINGLEMDS $LCTL set_param fail_val=0
632 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
633 [ "$STATUS" == "completed" ] ||
634 error "(8) Expect 'completed', but got '$STATUS'"
636 run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
641 echo "start $SINGLEMDS"
642 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
643 error "(1) Fail to start MDS!"
645 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
646 [ "$STATUS" == "init" ] ||
647 error "(2) Expect 'init', but got '$STATUS'"
649 mount_client $MOUNT || error "(3) Fail to start client!"
651 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
652 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
653 mkdir $DIR/$tdir/crashed
655 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
656 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
657 for ((i = 0; i < 5; i++)); do
658 touch $DIR/$tdir/dummy${i}
661 #define OBD_FAIL_LFSCK_DELAY2 0x1601
662 do_facet $SINGLEMDS $LCTL set_param fail_val=2
663 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
664 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
666 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
667 [ "$STATUS" == "scanning-phase1" ] ||
668 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
670 $STOP_LFSCK || error "(6) Fail to stop LFSCK!"
672 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
673 [ "$STATUS" == "stopped" ] ||
674 error "(7) Expect 'stopped', but got '$STATUS'"
676 $START_NAMESPACE || error "(8) Fail to start LFSCK for namespace!"
678 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
679 [ "$STATUS" == "scanning-phase1" ] ||
680 error "(9) Expect 'scanning-phase1', but got '$STATUS'"
682 #define OBD_FAIL_LFSCK_FATAL2 0x1609
683 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
685 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
686 [ "$STATUS" == "failed" ] ||
687 error "(10) Expect 'failed', but got '$STATUS'"
689 #define OBD_FAIL_LFSCK_DELAY1 0x1600
690 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
691 $START_NAMESPACE || error "(11) Fail to start LFSCK for namespace!"
693 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
694 [ "$STATUS" == "scanning-phase1" ] ||
695 error "(12) Expect 'scanning-phase1', but got '$STATUS'"
697 #define OBD_FAIL_LFSCK_CRASH 0x160a
698 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160a
701 echo "stop $SINGLEMDS"
702 stop $SINGLEMDS > /dev/null || error "(13) Fail to stop MDS!"
704 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
705 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
707 echo "start $SINGLEMDS"
708 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
709 error "(14) Fail to start MDS!"
711 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
712 [ "$STATUS" == "crashed" ] ||
713 error "(15) Expect 'crashed', but got '$STATUS'"
715 #define OBD_FAIL_LFSCK_DELAY2 0x1601
716 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
717 $START_NAMESPACE || error "(16) Fail to start LFSCK for namespace!"
719 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
720 [ "$STATUS" == "scanning-phase1" ] ||
721 error "(17) Expect 'scanning-phase1', but got '$STATUS'"
723 echo "stop $SINGLEMDS"
724 stop $SINGLEMDS > /dev/null || error "(18) Fail to stop MDS!"
726 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
727 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
729 echo "start $SINGLEMDS"
730 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
731 error "(19) Fail to start MDS!"
733 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
734 [ "$STATUS" == "paused" ] ||
735 error "(20) Expect 'paused', but got '$STATUS'"
737 #define OBD_FAIL_LFSCK_DELAY3 0x1602
738 do_facet $SINGLEMDS $LCTL set_param fail_val=2
739 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1602
741 $START_NAMESPACE || error "(21) Fail to start LFSCK for namespace!"
743 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
744 [ "$STATUS" == "scanning-phase2" ] ||
745 error "(22) Expect 'scanning-phase2', but got '$STATUS'"
747 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
748 [ "$FLAGS" == "scanned-once,inconsistent" ] ||
749 error "(23) Expect 'scanned-once,inconsistent',but got '$FLAGS'"
751 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
752 do_facet $SINGLEMDS $LCTL set_param fail_val=0
754 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
755 [ "$STATUS" == "completed" ] ||
756 error "(24) Expect 'completed', but got '$STATUS'"
758 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
759 [ -z "$FLAGS" ] || error "(25) Expect empty flags, but got '$FLAGS'"
762 run_test 8 "LFSCK state machine"
765 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
766 skip "Testing on UP system, the speed may be inaccurate."
771 echo "start $SINGLEMDS"
772 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
773 error "(1) Fail to start MDS!"
775 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
776 [ "$STATUS" == "init" ] ||
777 error "(2) Expect 'init', but got '$STATUS'"
779 local BASE_SPEED1=100
781 $START_NAMESPACE -s $BASE_SPEED1 || error "(3) Fail to start LFSCK!"
784 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
785 [ "$STATUS" == "scanning-phase1" ] ||
786 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
788 local SPEED=$($SHOW_NAMESPACE |
789 awk '/^average_speed_phase1/ { print $2 }')
791 # There may be time error, normally it should be less than 2 seconds.
792 # We allow another 20% schedule error.
794 # MAX_MARGIN = 1.2 = 12 / 10
795 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
796 RUN_TIME1 * 12 / 10))
797 [ $SPEED -lt $MAX_SPEED ] ||
798 error "(4) Got speed $SPEED, expected less than $MAX_SPEED"
801 local BASE_SPEED2=300
803 do_facet $SINGLEMDS \
804 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
807 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
808 # MIN_MARGIN = 0.8 = 8 / 10
809 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
810 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
811 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
812 [ $SPEED -gt $MIN_SPEED ] ||
813 error "(5) Got speed $SPEED, expected more than $MIN_SPEED"
815 # MAX_MARGIN = 1.2 = 12 / 10
816 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
817 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
818 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
819 [ $SPEED -lt $MAX_SPEED ] ||
820 error "(6) Got speed $SPEED, expected less than $MAX_SPEED"
822 do_facet $SINGLEMDS \
823 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
825 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
826 [ "$STATUS" == "completed" ] ||
827 error "(7) Expect 'completed', but got '$STATUS'"
829 run_test 9a "LFSCK speed control (1)"
832 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
833 skip "Testing on UP system, the speed may be inaccurate."
838 echo "start $SINGLEMDS"
839 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
840 error "(1) Fail to start MDS!"
842 mount_client $MOUNT || error "(2) Fail to start client!"
844 echo "Another preparing... 50 * 50 files (with error) will be created."
845 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
846 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
847 for ((i = 0; i < 50; i++)); do
848 mkdir -p $DIR/$tdir/d${i}
849 touch $DIR/$tdir/f${i}
850 for ((j = 0; j < 50; j++)); do
851 touch $DIR/$tdir/d${i}/f${j}
855 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
856 [ "$STATUS" == "init" ] ||
857 error "(3) Expect 'init', but got '$STATUS'"
859 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN 0x160c
860 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160c
861 $START_NAMESPACE || error "(4) Fail to start LFSCK!"
864 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
865 [ "$STATUS" == "stopped" ] ||
866 error "(5) Expect 'stopped', but got '$STATUS'"
868 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
872 $START_NAMESPACE -s $BASE_SPEED1 || error "(6) Fail to start LFSCK!"
875 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
876 [ "$STATUS" == "scanning-phase2" ] ||
877 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
879 local SPEED=$($SHOW_NAMESPACE |
880 awk '/^average_speed_phase2/ { print $2 }')
881 # There may be time error, normally it should be less than 2 seconds.
882 # We allow another 20% schedule error.
884 # MAX_MARGIN = 1.2 = 12 / 10
885 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
886 RUN_TIME1 * 12 / 10))
887 [ $SPEED -lt $MAX_SPEED ] ||
888 error "(8) Got speed $SPEED, expected less than $MAX_SPEED"
891 local BASE_SPEED2=150
893 do_facet $SINGLEMDS \
894 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
897 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
898 # MIN_MARGIN = 0.8 = 8 / 10
899 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
900 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
901 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
902 [ $SPEED -gt $MIN_SPEED ] ||
903 error "(9) Got speed $SPEED, expected more than $MIN_SPEED"
905 # MAX_MARGIN = 1.2 = 12 / 10
906 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
907 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
908 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
909 [ $SPEED -lt $MAX_SPEED ] ||
910 error "(10) Got speed $SPEED, expected less than $MAX_SPEED"
912 do_facet $SINGLEMDS \
913 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
915 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
916 [ "$STATUS" == "completed" ] ||
917 error "(11) Expect 'completed', but got '$STATUS'"
919 run_test 9b "LFSCK speed control (2)"
924 echo "start $SINGLEMDS"
925 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
926 error "(1) Fail to start MDS!"
928 mount_client $MOUNT || error "(2) Fail to start client!"
930 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
931 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
932 for ((i = 0; i < 1000; i = $((i+2)))); do
933 mkdir -p $DIR/$tdir/d${i}
934 touch $DIR/$tdir/f${i}
935 for ((j = 0; j < 5; j++)); do
936 touch $DIR/$tdir/d${i}/f${j}
940 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
941 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
942 for ((i = 1; i < 1000; i = $((i+2)))); do
943 mkdir -p $DIR/$tdir/d${i}
944 touch $DIR/$tdir/f${i}
945 for ((j = 0; j < 5; j++)); do
946 touch $DIR/$tdir/d${i}/f${j}
950 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
951 ln $DIR/$tdir/f200 $DIR/$tdir/d200/dummy
954 mount_client $MOUNT || error "(3) Fail to start client!"
956 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
957 [ "$STATUS" == "init" ] ||
958 error "(4) Expect 'init', but got '$STATUS'"
960 $START_NAMESPACE -s 100 || error "(5) Fail to start LFSCK!"
963 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
964 [ "$STATUS" == "scanning-phase1" ] ||
965 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
967 ls -ailR $MOUNT > /dev/null || error "(7) Fail to ls!"
969 touch $DIR/$tdir/d198/a0 || error "(8) Fail to touch!"
971 mkdir $DIR/$tdir/d199/a1 || error "(9) Fail to mkdir!"
973 unlink $DIR/$tdir/f200 || error "(10) Fail to unlink!"
975 rm -rf $DIR/$tdir/d201 || error "(11) Fail to rmdir!"
977 mv $DIR/$tdir/f202 $DIR/$tdir/d203/ || error "(12) Fail to rename!"
979 ln $DIR/$tdir/f204 $DIR/$tdir/d205/a3 || error "(13) Fail to hardlink!"
981 ln -s $DIR/$tdir/d206 $DIR/$tdir/d207/a4 ||
982 error "(14) Fail to softlink!"
984 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
985 [ "$STATUS" == "scanning-phase1" ] ||
986 error "(15) Expect 'scanning-phase1', but got '$STATUS'"
988 do_facet $SINGLEMDS \
989 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
992 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
993 [ "$STATUS" == "completed" ] ||
994 error "(16) Expect 'completed', but got '$STATUS'"
996 run_test 10 "System is available during LFSCK scanning"
998 $LCTL set_param debug=-lfsck > /dev/null || true
1000 # restore MDS/OST size
1001 MDSSIZE=${SAVED_MDSSIZE}
1002 OSTSIZE=${SAVED_OSTSIZE}
1004 # cleanup the system at last