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 require_dsh_mds || exit 0
22 MCREATE=${MCREATE:-mcreate}
23 SAVED_MDSSIZE=${MDSSIZE}
24 SAVED_OSTSIZE=${OSTSIZE}
25 SAVED_OSTCOUNT=${OSTCOUNT}
26 # use small MDS + OST size to speed formatting time
27 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
30 # no need too much OSTs, to reduce the format/start/stop overhead
31 [ $OSTCOUNT -gt 4 ] && OSTCOUNT=4
33 # build up a clean test environment.
37 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.60) ]] &&
38 skip "Need MDS version at least 2.3.60" && check_and_cleanup_lustre &&
41 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.4.90) ]] &&
42 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 2c"
44 [[ $(lustre_version_code ost1) -lt $(version_code 2.5.55) ]] &&
45 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 12 13 14 15 16 17 18 19"
49 $LCTL set_param debug=+lfsck > /dev/null || true
51 MDT_DEV="${FSNAME}-MDT0000"
52 OST_DEV="${FSNAME}-OST0000"
53 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
54 START_NAMESPACE="do_facet $SINGLEMDS \
55 $LCTL lfsck_start -M ${MDT_DEV} -t namespace"
56 START_LAYOUT="do_facet $SINGLEMDS \
57 $LCTL lfsck_start -M ${MDT_DEV} -t layout"
58 START_LAYOUT_ON_OST="do_facet ost1 $LCTL lfsck_start -M ${OST_DEV} -t layout"
59 STOP_LFSCK="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
60 SHOW_NAMESPACE="do_facet $SINGLEMDS \
61 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace"
62 SHOW_LAYOUT="do_facet $SINGLEMDS \
63 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_layout"
64 SHOW_LAYOUT_ON_OST="do_facet ost1 \
65 $LCTL get_param -n obdfilter.${OST_DEV}.lfsck_layout"
66 MOUNT_OPTS_SCRUB="-o user_xattr"
67 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
76 echo "preparing... $nfiles * $ndirs files will be created $(date)."
77 if [ ! -z $igif ]; then
78 #define OBD_FAIL_FID_IGIF 0x1504
79 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
82 cp $LUSTRE/tests/*.sh $DIR/$tdir/
83 if [ $ndirs -gt 0 ]; then
84 createmany -d $DIR/$tdir/d $ndirs
85 createmany -m $DIR/$tdir/f $ndirs
86 if [ $nfiles -gt 0 ]; then
87 for ((i = 0; i < $ndirs; i++)); do
88 createmany -m $DIR/$tdir/d${i}/f $nfiles > \
89 /dev/null || error "createmany $nfiles"
92 createmany -d $DIR/$tdir/e $ndirs
95 if [ ! -z $igif ]; then
96 touch $DIR/$tdir/dummy
97 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
100 echo "prepared $(date)."
106 #define OBD_FAIL_LFSCK_DELAY1 0x1600
107 do_facet $SINGLEMDS $LCTL set_param fail_val=3 fail_loc=0x1600
108 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
110 $SHOW_NAMESPACE || error "Fail to monitor LFSCK (3)"
112 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
113 [ "$STATUS" == "scanning-phase1" ] ||
114 error "(4) Expect 'scanning-phase1', but got '$STATUS'"
116 $STOP_LFSCK || error "(5) Fail to stop LFSCK!"
118 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
119 [ "$STATUS" == "stopped" ] ||
120 error "(6) Expect 'stopped', but got '$STATUS'"
122 $START_NAMESPACE || error "(7) Fail to start LFSCK for namespace!"
124 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
125 [ "$STATUS" == "scanning-phase1" ] ||
126 error "(8) Expect 'scanning-phase1', but got '$STATUS'"
128 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
129 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
130 mdd.${MDT_DEV}.lfsck_namespace |
131 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
133 error "(9) unexpected status"
136 local repaired=$($SHOW_NAMESPACE |
137 awk '/^updated_phase1/ { print $2 }')
138 [ $repaired -eq 0 ] ||
139 error "(10) Expect nothing to be repaired, but got: $repaired"
141 local scanned1=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
142 $START_NAMESPACE -r || error "(11) Fail to reset LFSCK!"
143 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
144 mdd.${MDT_DEV}.lfsck_namespace |
145 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
147 error "(12) unexpected status"
150 local scanned2=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
151 [ $((scanned1 + 1)) -eq $scanned2 ] ||
152 error "(13) Expect success $((scanned1 + 1)), but got $scanned2"
154 echo "stopall, should NOT crash LU-3649"
155 stopall || error "(14) Fail to stopall"
157 run_test 0 "Control LFSCK manually"
160 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
161 skip "OI Scrub not implemented for ZFS" && return
165 #define OBD_FAIL_FID_INDIR 0x1501
166 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1501
167 touch $DIR/$tdir/dummy
169 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
171 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
172 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
173 mdd.${MDT_DEV}.lfsck_namespace |
174 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
176 error "(4) unexpected status"
179 local repaired=$($SHOW_NAMESPACE |
180 awk '/^dirent_repaired/ { print $2 }')
181 # for interop with old server
182 [ -z "$repaired" ] &&
183 repaired=$($SHOW_NAMESPACE |
184 awk '/^updated_phase1/ { print $2 }')
186 [ $repaired -eq 1 ] ||
187 error "(5) Fail to repair crashed FID-in-dirent: $repaired"
189 mount_client $MOUNT || error "(6) Fail to start client!"
191 #define OBD_FAIL_FID_LOOKUP 0x1505
192 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
193 ls $DIR/$tdir/ > /dev/null || error "(7) no FID-in-dirent."
195 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
197 run_test 1a "LFSCK can find out and repair crashed FID-in-dirent"
201 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
202 skip "OI Scrub not implemented for ZFS" && return
206 #define OBD_FAIL_FID_INLMA 0x1502
207 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1502
208 touch $DIR/$tdir/dummy
210 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
212 #define OBD_FAIL_FID_NOLMA 0x1506
213 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1506
214 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
215 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
216 mdd.${MDT_DEV}.lfsck_namespace |
217 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
219 error "(4) unexpected status"
222 local repaired=$($SHOW_NAMESPACE |
223 awk '/^dirent_repaired/ { print $2 }')
224 # for interop with old server
225 [ -z "$repaired" ] &&
226 repaired=$($SHOW_NAMESPACE |
227 awk '/^updated_phase1/ { print $2 }')
229 [ $repaired -eq 1 ] ||
230 error "(5) Fail to repair missed FID-in-LMA: $repaired"
232 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
233 mount_client $MOUNT || error "(6) Fail to start client!"
235 #define OBD_FAIL_FID_LOOKUP 0x1505
236 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
237 stat $DIR/$tdir/dummy > /dev/null || error "(7) no FID-in-LMA."
239 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
241 run_test 1b "LFSCK can find out and repair missed FID-in-LMA"
246 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
247 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
248 touch $DIR/$tdir/dummy
250 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
252 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
253 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
254 mdd.${MDT_DEV}.lfsck_namespace |
255 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
257 error "(4) unexpected status"
260 local repaired=$($SHOW_NAMESPACE |
261 awk '/^linkea_repaired/ { print $2 }')
262 # for interop with old server
263 [ -z "$repaired" ] &&
264 repaired=$($SHOW_NAMESPACE |
265 awk '/^updated_phase1/ { 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 2a "LFSCK can find out and repair crashed linkEA entry"
286 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
287 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
288 touch $DIR/$tdir/dummy
290 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
292 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
293 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
294 mdd.${MDT_DEV}.lfsck_namespace |
295 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
297 error "(4) unexpected status"
300 local repaired=$($SHOW_NAMESPACE |
301 awk '/^updated_phase2/ { print $2 }')
302 [ $repaired -eq 1 ] ||
303 error "(5) Fail to repair crashed linkEA: $repaired"
305 mount_client $MOUNT || error "(6) Fail to start client!"
307 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
308 error "(7) Fail to stat $DIR/$tdir/dummy"
310 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
311 local dummyname=$($LFS fid2path $DIR $dummyfid)
312 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
313 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
315 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
321 #define OBD_FAIL_LFSCK_LINKEA_MORE2 0x1605
322 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1605
323 touch $DIR/$tdir/dummy
325 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
327 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
328 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
329 mdd.${MDT_DEV}.lfsck_namespace |
330 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
332 error "(4) unexpected status"
335 local repaired=$($SHOW_NAMESPACE |
336 awk '/^updated_phase2/ { print $2 }')
337 [ $repaired -eq 1 ] ||
338 error "(5) Fail to repair crashed linkEA: $repaired"
340 mount_client $MOUNT || error "(6) Fail to start client!"
342 stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
343 error "(7) Fail to stat $DIR/$tdir/dummy"
345 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
346 local dummyname=$($LFS fid2path $DIR $dummyfid)
347 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
348 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
350 run_test 2c "LFSCK can find out and remove repeated linkEA entry"
354 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
355 skip "OI Scrub not implemented for ZFS" && return
358 cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
359 stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
361 mds_backup_restore $SINGLEMDS || error "(1) Fail to backup/restore!"
362 echo "start $SINGLEMDS with disabling OI scrub"
363 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
364 error "(2) Fail to start MDS!"
366 #define OBD_FAIL_LFSCK_DELAY2 0x1601
367 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
368 $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
369 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
370 mdd.${MDT_DEV}.lfsck_namespace |
371 awk '/^flags/ { print \\\$2 }'" "inconsistent" 6 || {
373 error "(5) unexpected status"
376 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
377 [ "$STATUS" == "scanning-phase1" ] ||
378 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
380 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
381 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
382 mdd.${MDT_DEV}.lfsck_namespace |
383 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
385 error "(7) unexpected status"
388 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
389 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
391 local repaired=$($SHOW_NAMESPACE |
392 awk '/^dirent_repaired/ { print $2 }')
393 # for interop with old server
394 [ -z "$repaired" ] &&
395 repaired=$($SHOW_NAMESPACE |
396 awk '/^updated_phase1/ { print $2 }')
398 [ $repaired -ge 9 ] ||
399 error "(9) Fail to re-generate FID-in-dirent: $repaired"
401 mount_client $MOUNT || error "(10) Fail to start client!"
403 #define OBD_FAIL_FID_LOOKUP 0x1505
404 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
405 ls $DIR/$tdir/ > /dev/null || error "(11) no FID-in-dirent."
406 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
408 run_test 4 "FID-in-dirent can be rebuilt after MDT file-level backup/restore"
412 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
413 skip "OI Scrub not implemented for ZFS" && return
416 cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
417 stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
419 mds_backup_restore $SINGLEMDS 1 || error "(1) Fail to backup/restore!"
420 echo "start $SINGLEMDS with disabling OI scrub"
421 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
422 error "(2) Fail to start MDS!"
424 #define OBD_FAIL_LFSCK_DELAY2 0x1601
425 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
426 $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
427 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
428 mdd.${MDT_DEV}.lfsck_namespace |
429 awk '/^flags/ { print \\\$2 }'" "inconsistent,upgrade" 6 || {
431 error "(5) unexpected status"
434 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
435 [ "$STATUS" == "scanning-phase1" ] ||
436 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
438 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
439 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
440 mdd.${MDT_DEV}.lfsck_namespace |
441 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
443 error "(7) unexpected status"
446 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
447 [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
449 local repaired=$($SHOW_NAMESPACE |
450 awk '/^dirent_repaired/ { print $2 }')
451 # for interop with old server
452 [ -z "$repaired" ] &&
453 repaired=$($SHOW_NAMESPACE |
454 awk '/^updated_phase1/ { print $2 }')
456 [ $repaired -ge 2 ] ||
457 error "(9) Fail to generate FID-in-dirent for IGIF: $repaired"
459 mount_client $MOUNT || error "(10) Fail to start client!"
461 #define OBD_FAIL_FID_LOOKUP 0x1505
462 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
463 stat $DIR/$tdir/dummy > /dev/null || error "(11) no FID-in-LMA."
465 ls $DIR/$tdir/ > /dev/null || error "(12) no FID-in-dirent."
467 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
468 local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
469 local dummyname=$($LFS fid2path $DIR $dummyfid)
470 [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
471 error "(13) Fail to generate linkEA: $dummyfid $dummyname"
473 run_test 5 "LFSCK can handle IGIF object upgrading"
478 #define OBD_FAIL_LFSCK_DELAY1 0x1600
479 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
480 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
482 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
483 [ "$STATUS" == "scanning-phase1" ] ||
484 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
486 # Sleep 3 sec to guarantee at least one object processed by LFSCK
488 # Fail the LFSCK to guarantee there is at least one checkpoint
489 #define OBD_FAIL_LFSCK_FATAL1 0x1608
490 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001608
491 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
492 mdd.${MDT_DEV}.lfsck_namespace |
493 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
495 error "(4) unexpected status"
498 local POS0=$($SHOW_NAMESPACE |
499 awk '/^last_checkpoint_position/ { print $2 }' |
502 #define OBD_FAIL_LFSCK_DELAY1 0x1600
503 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
504 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
506 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
507 [ "$STATUS" == "scanning-phase1" ] ||
508 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
510 local POS1=$($SHOW_NAMESPACE |
511 awk '/^latest_start_position/ { print $2 }' |
513 [ $POS0 -lt $POS1 ] ||
514 error "(7) Expect larger than: $POS0, but got $POS1"
516 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
517 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
518 mdd.${MDT_DEV}.lfsck_namespace |
519 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
521 error "(8) unexpected status"
524 run_test 6a "LFSCK resumes from last checkpoint (1)"
529 #define OBD_FAIL_LFSCK_DELAY2 0x1601
530 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
531 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
533 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
534 [ "$STATUS" == "scanning-phase1" ] ||
535 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
537 # Sleep 5 sec to guarantee that we are in the directory scanning
539 # Fail the LFSCK to guarantee there is at least one checkpoint
540 #define OBD_FAIL_LFSCK_FATAL2 0x1609
541 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
542 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
543 mdd.${MDT_DEV}.lfsck_namespace |
544 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
546 error "(4) unexpected status"
549 local O_POS0=$($SHOW_NAMESPACE |
550 awk '/^last_checkpoint_position/ { print $2 }' |
553 local D_POS0=$($SHOW_NAMESPACE |
554 awk '/^last_checkpoint_position/ { print $4 }')
556 #define OBD_FAIL_LFSCK_DELAY2 0x1601
557 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
558 $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
560 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
561 [ "$STATUS" == "scanning-phase1" ] ||
562 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
564 local O_POS1=$($SHOW_NAMESPACE |
565 awk '/^latest_start_position/ { print $2 }' |
567 local D_POS1=$($SHOW_NAMESPACE |
568 awk '/^latest_start_position/ { print $4 }')
570 if [ "$D_POS0" == "N/A" -o "$D_POS1" == "N/A" ]; then
571 [ $O_POS0 -lt $O_POS1 ] ||
572 error "(7.1) $O_POS1 is not larger than $O_POS0"
574 [ $D_POS0 -lt $D_POS1 ] ||
575 error "(7.2) $D_POS1 is not larger than $D_POS0"
578 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
579 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
580 mdd.${MDT_DEV}.lfsck_namespace |
581 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
583 error "(8) unexpected status"
586 run_test 6b "LFSCK resumes from last checkpoint (2)"
593 #define OBD_FAIL_LFSCK_DELAY2 0x1601
594 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
595 $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
597 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
598 [ "$STATUS" == "scanning-phase1" ] ||
599 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
601 # Sleep 3 sec to guarantee at least one object processed by LFSCK
603 echo "stop $SINGLEMDS"
604 stop $SINGLEMDS > /dev/null || error "(4) Fail to stop MDS!"
606 echo "start $SINGLEMDS"
607 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
608 error "(5) Fail to start MDS!"
610 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
611 [ "$STATUS" == "scanning-phase1" ] ||
612 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
614 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
615 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
616 mdd.${MDT_DEV}.lfsck_namespace |
617 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
619 error "(7) unexpected status"
622 run_test 7a "non-stopped LFSCK should auto restarts after MDS remount (1)"
628 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
629 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
630 for ((i = 0; i < 20; i++)); do
631 touch $DIR/$tdir/dummy${i}
634 #define OBD_FAIL_LFSCK_DELAY3 0x1602
635 do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1602
636 $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
637 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
638 mdd.${MDT_DEV}.lfsck_namespace |
639 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
641 error "(4) unexpected status"
644 echo "stop $SINGLEMDS"
645 stop $SINGLEMDS > /dev/null || error "(5) Fail to stop MDS!"
647 echo "start $SINGLEMDS"
648 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
649 error "(6) Fail to start MDS!"
651 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
652 [ "$STATUS" == "scanning-phase2" ] ||
653 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
655 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
656 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
657 mdd.${MDT_DEV}.lfsck_namespace |
658 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
660 error "(8) unexpected status"
663 run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
668 formatall > /dev/null
674 local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
675 [ "$STATUS" == "init" ] ||
676 error "(2) Expect 'init', but got '$STATUS'"
678 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
679 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
680 mkdir $DIR/$tdir/crashed
682 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
683 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
684 for ((i = 0; i < 5; i++)); do
685 touch $DIR/$tdir/dummy${i}
688 umount_client $MOUNT || error "(3) Fail to stop client!"
690 #define OBD_FAIL_LFSCK_DELAY2 0x1601
691 do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1601
692 $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
694 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
695 [ "$STATUS" == "scanning-phase1" ] ||
696 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
698 $STOP_LFSCK || error "(6) Fail to stop LFSCK!"
700 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
701 [ "$STATUS" == "stopped" ] ||
702 error "(7) Expect 'stopped', but got '$STATUS'"
704 $START_NAMESPACE || error "(8) Fail to start LFSCK for namespace!"
706 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
707 [ "$STATUS" == "scanning-phase1" ] ||
708 error "(9) Expect 'scanning-phase1', but got '$STATUS'"
710 #define OBD_FAIL_LFSCK_FATAL2 0x1609
711 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
712 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
713 mdd.${MDT_DEV}.lfsck_namespace |
714 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
716 error "(10) unexpected status"
719 #define OBD_FAIL_LFSCK_DELAY1 0x1600
720 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
721 $START_NAMESPACE || error "(11) Fail to start LFSCK for namespace!"
723 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
724 [ "$STATUS" == "scanning-phase1" ] ||
725 error "(12) Expect 'scanning-phase1', but got '$STATUS'"
727 #define OBD_FAIL_LFSCK_CRASH 0x160a
728 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160a
731 echo "stop $SINGLEMDS"
732 stop $SINGLEMDS > /dev/null || error "(13) Fail to stop MDS!"
734 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
735 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
737 echo "start $SINGLEMDS"
738 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
739 error "(14) Fail to start MDS!"
741 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
742 [ "$STATUS" == "crashed" ] ||
743 error "(15) Expect 'crashed', but got '$STATUS'"
745 #define OBD_FAIL_LFSCK_DELAY2 0x1601
746 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
747 $START_NAMESPACE || error "(16) Fail to start LFSCK for namespace!"
749 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
750 [ "$STATUS" == "scanning-phase1" ] ||
751 error "(17) Expect 'scanning-phase1', but got '$STATUS'"
753 echo "stop $SINGLEMDS"
754 stop $SINGLEMDS > /dev/null || error "(18) Fail to stop MDS!"
756 #define OBD_FAIL_LFSCK_NO_AUTO 0x160b
757 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
759 echo "start $SINGLEMDS"
760 start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
761 error "(19) Fail to start MDS!"
763 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
764 [ "$STATUS" == "paused" ] ||
765 error "(20) Expect 'paused', but got '$STATUS'"
767 #define OBD_FAIL_LFSCK_DELAY3 0x1602
768 do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1602
770 $START_NAMESPACE || error "(21) Fail to start LFSCK for namespace!"
771 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
772 mdd.${MDT_DEV}.lfsck_namespace |
773 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
775 error "(22) unexpected status"
778 local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
779 [ "$FLAGS" == "scanned-once,inconsistent" ] ||
780 error "(23) Expect 'scanned-once,inconsistent',but got '$FLAGS'"
782 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
783 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
784 mdd.${MDT_DEV}.lfsck_namespace |
785 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
787 error "(24) unexpected status"
790 FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
791 [ -z "$FLAGS" ] || error "(25) Expect empty flags, but got '$FLAGS'"
793 run_test 8 "LFSCK state machine"
796 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
797 skip "Testing on UP system, the speed may be inaccurate."
803 local BASE_SPEED1=100
805 $START_NAMESPACE -r -s $BASE_SPEED1 || error "(3) Fail to start LFSCK!"
808 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
809 [ "$STATUS" == "scanning-phase1" ] ||
810 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
812 local SPEED=$($SHOW_NAMESPACE |
813 awk '/^average_speed_phase1/ { print $2 }')
815 # There may be time error, normally it should be less than 2 seconds.
816 # We allow another 20% schedule error.
818 # MAX_MARGIN = 1.2 = 12 / 10
819 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
820 RUN_TIME1 * 12 / 10))
821 [ $SPEED -lt $MAX_SPEED ] ||
822 error "(4) Got speed $SPEED, expected less than $MAX_SPEED"
825 local BASE_SPEED2=300
827 do_facet $SINGLEMDS \
828 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
831 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
832 # MIN_MARGIN = 0.8 = 8 / 10
833 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
834 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
835 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
836 # Account for slow ZFS performance - LU-4934
837 [ $SPEED -gt $MIN_SPEED ] || [ $(facet_fstype $SINGLEMDS) -eq zfs ] ||
838 error "(5) Got speed $SPEED, expected more than $MIN_SPEED"
840 # MAX_MARGIN = 1.2 = 12 / 10
841 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
842 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
843 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
844 [ $SPEED -lt $MAX_SPEED ] ||
845 error "(6) Got speed $SPEED, expected less than $MAX_SPEED"
847 do_facet $SINGLEMDS \
848 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
850 wait_update_facet $SINGLEMDS \
851 "$LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace|\
852 awk '/^status/ { print \\\$2 }'" "completed" 30 ||
853 error "(7) Failed to get expected 'completed'"
855 run_test 9a "LFSCK speed control (1)"
858 if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
859 skip "Testing on UP system, the speed may be inaccurate."
865 echo "Preparing another 50 * 50 files (with error) at $(date)."
866 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
867 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
868 createmany -d $DIR/$tdir/d 50
869 createmany -m $DIR/$tdir/f 50
870 for ((i = 0; i < 50; i++)); do
871 createmany -m $DIR/$tdir/d${i}/f 50 > /dev/null
874 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN 0x160c
875 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160c
876 $START_NAMESPACE -r || error "(4) Fail to start LFSCK!"
877 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
878 mdd.${MDT_DEV}.lfsck_namespace |
879 awk '/^status/ { print \\\$2 }'" "stopped" 10 || {
881 error "(5) unexpected status"
884 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
885 echo "Prepared at $(date)."
889 $START_NAMESPACE -s $BASE_SPEED1 || error "(6) Fail to start LFSCK!"
892 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
893 [ "$STATUS" == "scanning-phase2" ] ||
894 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
896 local SPEED=$($SHOW_NAMESPACE |
897 awk '/^average_speed_phase2/ { print $2 }')
898 # There may be time error, normally it should be less than 2 seconds.
899 # We allow another 20% schedule error.
901 # MAX_MARGIN = 1.2 = 12 / 10
902 local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
903 RUN_TIME1 * 12 / 10))
904 [ $SPEED -lt $MAX_SPEED ] ||
905 error "(8) Got speed $SPEED, expected less than $MAX_SPEED"
908 local BASE_SPEED2=150
910 do_facet $SINGLEMDS \
911 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
914 SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
915 # MIN_MARGIN = 0.8 = 8 / 10
916 local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
917 BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
918 (RUN_TIME1 + RUN_TIME2) * 8 / 10))
919 [ $SPEED -gt $MIN_SPEED ] ||[ $(facet_fstype $SINGLEMDS) -eq zfs ] ||
920 error "(9) Got speed $SPEED, expected more than $MIN_SPEED"
922 # MAX_MARGIN = 1.2 = 12 / 10
923 MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
924 BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
925 (RUN_TIME1 + RUN_TIME2) * 12 / 10))
926 [ $SPEED -lt $MAX_SPEED ] ||
927 error "(10) Got speed $SPEED, expected less than $MAX_SPEED"
929 do_facet $SINGLEMDS \
930 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
931 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
932 mdd.${MDT_DEV}.lfsck_namespace |
933 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
935 error "(11) unexpected status"
938 run_test 9b "LFSCK speed control (2)"
942 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
943 skip "lookup(..)/linkea on ZFS issue" && return
947 echo "Preparing more files with error at $(date)."
948 #define OBD_FAIL_LFSCK_LINKEA_CRASH 0x1603
949 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
951 for ((i = 0; i < 1000; i = $((i+2)))); do
952 mkdir -p $DIR/$tdir/d${i}
953 touch $DIR/$tdir/f${i}
954 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
957 #define OBD_FAIL_LFSCK_LINKEA_MORE 0x1604
958 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
960 for ((i = 1; i < 1000; i = $((i+2)))); do
961 mkdir -p $DIR/$tdir/d${i}
962 touch $DIR/$tdir/f${i}
963 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
966 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
967 echo "Prepared at $(date)."
969 ln $DIR/$tdir/f200 $DIR/$tdir/d200/dummy
972 mount_client $MOUNT || error "(3) Fail to start client!"
974 $START_NAMESPACE -r -s 100 || error "(5) Fail to start LFSCK!"
977 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
978 [ "$STATUS" == "scanning-phase1" ] ||
979 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
981 ls -ailR $MOUNT > /dev/null || error "(7) Fail to ls!"
983 touch $DIR/$tdir/d198/a0 || error "(8) Fail to touch!"
985 mkdir $DIR/$tdir/d199/a1 || error "(9) Fail to mkdir!"
987 unlink $DIR/$tdir/f200 || error "(10) Fail to unlink!"
989 rm -rf $DIR/$tdir/d201 || error "(11) Fail to rmdir!"
991 mv $DIR/$tdir/f202 $DIR/$tdir/d203/ || error "(12) Fail to rename!"
993 ln $DIR/$tdir/f204 $DIR/$tdir/d205/a3 || error "(13) Fail to hardlink!"
995 ln -s $DIR/$tdir/d206 $DIR/$tdir/d207/a4 ||
996 error "(14) Fail to softlink!"
998 STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
999 [ "$STATUS" == "scanning-phase1" ] ||
1000 error "(15) Expect 'scanning-phase1', but got '$STATUS'"
1002 do_facet $SINGLEMDS \
1003 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
1004 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1005 mdd.${MDT_DEV}.lfsck_namespace |
1006 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1008 error "(16) unexpected status"
1011 run_test 10 "System is available during LFSCK scanning"
1014 ost_remove_lastid() {
1017 local rcmd="do_facet ost${ost}"
1019 echo "remove LAST_ID on ost${ost}: idx=${idx}"
1021 # step 1: local mount
1022 mount_fstype ost${ost} || return 1
1023 # step 2: remove the specified LAST_ID
1024 ${rcmd} rm -fv $(facet_mntpt ost${ost})/O/${idx}/{LAST_ID,d0/0}
1026 unmount_fstype ost${ost} || return 2
1030 check_mount_and_prep
1031 $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1032 createmany -o $DIR/$tdir/f 64 || error "(0) Fail to create 64 files."
1037 ost_remove_lastid 1 0 || error "(1) Fail to remove LAST_ID"
1039 start ost1 $(ostdevname 1) $MOUNT_OPTS_NOSCRUB > /dev/null ||
1040 error "(2) Fail to start ost1"
1042 #define OBD_FAIL_LFSCK_DELAY4 0x160e
1043 do_facet ost1 $LCTL set_param fail_val=3 fail_loc=0x160e
1045 echo "trigger LFSCK for layout on ost1 to rebuild the LAST_ID(s)"
1046 $START_LAYOUT_ON_OST -r || error "(4) Fail to start LFSCK on OST!"
1048 wait_update_facet ost1 "$LCTL get_param -n \
1049 obdfilter.${OST_DEV}.lfsck_layout |
1050 awk '/^flags/ { print \\\$2 }'" "crashed_lastid" 60 || {
1052 error "(5) unexpected status"
1055 do_facet ost1 $LCTL set_param fail_val=0 fail_loc=0
1057 wait_update_facet ost1 "$LCTL get_param -n \
1058 obdfilter.${OST_DEV}.lfsck_layout |
1059 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1061 error "(6) unexpected status"
1064 echo "the LAST_ID(s) should have been rebuilt"
1065 FLAGS=$($SHOW_LAYOUT_ON_OST | awk '/^flags/ { print $2 }')
1066 [ -z "$FLAGS" ] || error "(7) Expect empty flags, but got '$FLAGS'"
1068 run_test 11a "LFSCK can rebuild lost last_id"
1071 check_mount_and_prep
1072 $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1074 echo "set fail_loc=0x160d to skip the updating LAST_ID on-disk"
1075 #define OBD_FAIL_LFSCK_SKIP_LASTID 0x160d
1076 do_facet ost1 $LCTL set_param fail_loc=0x160d
1077 createmany -o $DIR/$tdir/f 64
1078 local lastid1=$(do_facet ost1 "lctl get_param -n \
1079 obdfilter.${ost1_svc}.last_id" | grep 0x100000000 |
1080 awk -F: '{ print $2 }')
1082 umount_client $MOUNT
1083 stop ost1 || error "(1) Fail to stop ost1"
1085 #define OBD_FAIL_OST_ENOSPC 0x215
1086 do_facet ost1 $LCTL set_param fail_loc=0x215
1088 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
1089 error "(2) Fail to start ost1"
1091 for ((i = 0; i < 60; i++)); do
1092 lastid2=$(do_facet ost1 "lctl get_param -n \
1093 obdfilter.${ost1_svc}.last_id" | grep 0x100000000 |
1094 awk -F: '{ print $2 }')
1095 [ ! -z $lastid2 ] && break;
1099 echo "the on-disk LAST_ID should be smaller than the expected one"
1100 [ $lastid1 -gt $lastid2 ] ||
1101 error "(4) expect lastid1 [ $lastid1 ] > lastid2 [ $lastid2 ]"
1103 echo "trigger LFSCK for layout on ost1 to rebuild the on-disk LAST_ID"
1104 $START_LAYOUT_ON_OST -r || error "(5) Fail to start LFSCK on OST!"
1106 wait_update_facet ost1 "$LCTL get_param -n \
1107 obdfilter.${OST_DEV}.lfsck_layout |
1108 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1110 error "(6) unexpected status"
1113 stop ost1 || error "(7) Fail to stop ost1"
1115 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
1116 error "(8) Fail to start ost1"
1118 echo "the on-disk LAST_ID should have been rebuilt"
1119 wait_update_facet ost1 "$LCTL get_param -n \
1120 obdfilter.${ost1_svc}.last_id | grep 0x100000000 |
1121 awk -F: '{ print \\\$2 }'" "$lastid1" 60 || {
1122 $LCTL get_param -n obdfilter.${ost1_svc}.last_id
1123 error "(9) expect lastid1 0x100000000:$lastid1"
1126 do_facet ost1 $LCTL set_param fail_loc=0
1127 stopall || error "(10) Fail to stopall"
1129 run_test 11b "LFSCK can rebuild crashed last_id"
1132 [ $MDSCOUNT -lt 2 ] &&
1133 skip "We need at least 2 MDSes for test_12" && exit 0
1135 check_mount_and_prep
1136 for k in $(seq $MDSCOUNT); do
1137 $LFS mkdir -i $((k - 1)) $DIR/$tdir/${k}
1138 createmany -o $DIR/$tdir/${k}/f 100 ||
1139 error "(0) Fail to create 100 files."
1142 echo "Start namespace LFSCK on all targets by single command (-s 1)."
1143 do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \
1144 -s 1 -r || error "(2) Fail to start LFSCK on all devices!"
1146 echo "All the LFSCK targets should be in 'scanning-phase1' status."
1147 for k in $(seq $MDSCOUNT); do
1148 local STATUS=$(do_facet mds${k} $LCTL get_param -n \
1149 mdd.$(facet_svc mds${k}).lfsck_namespace |
1150 awk '/^status/ { print $2 }')
1151 [ "$STATUS" == "scanning-phase1" ] ||
1152 error "(3) MDS${k} Expect 'scanning-phase1', but got '$STATUS'"
1155 echo "Stop namespace LFSCK on all targets by single lctl command."
1156 do_facet mds1 $LCTL lfsck_stop -M ${FSNAME}-MDT0000 -A ||
1157 error "(4) Fail to stop LFSCK on all devices!"
1159 echo "All the LFSCK targets should be in 'stopped' status."
1160 for k in $(seq $MDSCOUNT); do
1161 local STATUS=$(do_facet mds${k} $LCTL get_param -n \
1162 mdd.$(facet_svc mds${k}).lfsck_namespace |
1163 awk '/^status/ { print $2 }')
1164 [ "$STATUS" == "stopped" ] ||
1165 error "(5) MDS${k} Expect 'stopped', but got '$STATUS'"
1168 echo "Re-start namespace LFSCK on all targets by single command (-s 0)."
1169 do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \
1170 -s 0 -r || error "(6) Fail to start LFSCK on all devices!"
1172 echo "All the LFSCK targets should be in 'completed' status."
1173 for k in $(seq $MDSCOUNT); do
1174 wait_update_facet mds${k} "$LCTL get_param -n \
1175 mdd.$(facet_svc mds${k}).lfsck_namespace |
1176 awk '/^status/ { print \\\$2 }'" "completed" 8 ||
1177 error "(7) MDS${k} is not the expected 'completed'"
1180 echo "Start layout LFSCK on all targets by single command (-s 1)."
1181 do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \
1182 -s 1 -r || error "(8) Fail to start LFSCK on all devices!"
1184 echo "All the LFSCK targets should be in 'scanning-phase1' status."
1185 for k in $(seq $MDSCOUNT); do
1186 local STATUS=$(do_facet mds${k} $LCTL get_param -n \
1187 mdd.$(facet_svc mds${k}).lfsck_layout |
1188 awk '/^status/ { print $2 }')
1189 [ "$STATUS" == "scanning-phase1" ] ||
1190 error "(9) MDS${k} Expect 'scanning-phase1', but got '$STATUS'"
1193 echo "Stop layout LFSCK on all targets by single lctl command."
1194 do_facet mds1 $LCTL lfsck_stop -M ${FSNAME}-MDT0000 -A ||
1195 error "(10) Fail to stop LFSCK on all devices!"
1197 echo "All the LFSCK targets should be in 'stopped' status."
1198 for k in $(seq $MDSCOUNT); do
1199 local STATUS=$(do_facet mds${k} $LCTL get_param -n \
1200 mdd.$(facet_svc mds${k}).lfsck_layout |
1201 awk '/^status/ { print $2 }')
1202 [ "$STATUS" == "stopped" ] ||
1203 error "(11) MDS${k} Expect 'stopped', but got '$STATUS'"
1206 for k in $(seq $OSTCOUNT); do
1207 local STATUS=$(do_facet ost${k} $LCTL get_param -n \
1208 obdfilter.$(facet_svc ost${k}).lfsck_layout |
1209 awk '/^status/ { print $2 }')
1210 [ "$STATUS" == "stopped" ] ||
1211 error "(12) OST${k} Expect 'stopped', but got '$STATUS'"
1214 echo "Re-start layout LFSCK on all targets by single command (-s 0)."
1215 do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \
1216 -s 0 -r || error "(13) Fail to start LFSCK on all devices!"
1218 echo "All the LFSCK targets should be in 'completed' status."
1219 for k in $(seq $MDSCOUNT); do
1220 # The LFSCK status query internal is 30 seconds. For the case
1221 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1222 # time to guarantee the status sync up.
1223 wait_update_facet mds${k} "$LCTL get_param -n \
1224 mdd.$(facet_svc mds${k}).lfsck_layout |
1225 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1226 error "(14) MDS${k} is not the expected 'completed'"
1229 run_test 12 "single command to trigger LFSCK on all devices"
1233 echo "The lmm_oi in layout EA should be consistent with the MDT-object"
1234 echo "FID; otherwise, the LFSCK should re-generate the lmm_oi from the"
1235 echo "MDT-object FID."
1238 check_mount_and_prep
1240 echo "Inject failure stub to simulate bad lmm_oi"
1241 #define OBD_FAIL_LFSCK_BAD_LMMOI 0x160f
1242 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160f
1243 createmany -o $DIR/$tdir/f 32
1244 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1246 echo "Trigger layout LFSCK to find out the bad lmm_oi and fix them"
1247 $START_LAYOUT -r || error "(1) Fail to start LFSCK for layout!"
1249 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1250 mdd.${MDT_DEV}.lfsck_layout |
1251 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1253 error "(2) unexpected status"
1256 local repaired=$($SHOW_LAYOUT |
1257 awk '/^repaired_others/ { print $2 }')
1258 [ $repaired -eq 32 ] ||
1259 error "(3) Fail to repair crashed lmm_oi: $repaired"
1261 run_test 13 "LFSCK can repair crashed lmm_oi"
1265 echo "The OST-object referenced by the MDT-object should be there;"
1266 echo "otherwise, the LFSCK should re-create the missed OST-object."
1269 check_mount_and_prep
1270 $LFS setstripe -c 1 -i 0 $DIR/$tdir
1272 local count=$(precreated_ost_obj_count 0 0)
1274 echo "Inject failure stub to simulate dangling referenced MDT-object"
1275 #define OBD_FAIL_LFSCK_DANGLING 0x1610
1276 do_facet ost1 $LCTL set_param fail_loc=0x1610
1277 createmany -o $DIR/$tdir/f $((count + 32))
1278 do_facet ost1 $LCTL set_param fail_loc=0
1280 # exhaust other pre-created dangling cases
1281 count=$(precreated_ost_obj_count 0 0)
1282 createmany -o $DIR/$tdir/a $count ||
1283 error "(0) Fail to create $count files."
1285 echo "'ls' should fail because of dangling referenced MDT-object"
1286 ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(1) ls should fail."
1288 echo "Trigger layout LFSCK to find out dangling reference"
1289 $START_LAYOUT -r || error "(2) Fail to start LFSCK for layout!"
1291 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1292 mdd.${MDT_DEV}.lfsck_layout |
1293 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1295 error "(3) unexpected status"
1298 local repaired=$($SHOW_LAYOUT |
1299 awk '/^repaired_dangling/ { print $2 }')
1300 [ $repaired -ge 32 ] ||
1301 error "(4) Fail to repair dangling reference: $repaired"
1303 echo "'ls' should fail because it will not repair dangling by default"
1304 ls -ail $DIR/$tdir > /dev/null 2>&1 && error "(5) ls should fail."
1306 echo "Trigger layout LFSCK to repair dangling reference"
1307 $START_LAYOUT -r -c || error "(6) Fail to start LFSCK for layout!"
1309 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1310 mdd.${MDT_DEV}.lfsck_layout |
1311 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1313 error "(7) unexpected status"
1316 repaired=$($SHOW_LAYOUT |
1317 awk '/^repaired_dangling/ { print $2 }')
1318 [ $repaired -ge 32 ] ||
1319 error "(8) Fail to repair dangling reference: $repaired"
1321 echo "'ls' should success after layout LFSCK repairing"
1322 ls -ail $DIR/$tdir > /dev/null || error "(9) ls should success."
1324 run_test 14 "LFSCK can repair MDT-object with dangling reference"
1328 echo "If the OST-object referenced by the MDT-object back points"
1329 echo "to some non-exist MDT-object, then the LFSCK should repair"
1330 echo "the OST-object to back point to the right MDT-object."
1333 check_mount_and_prep
1334 $LFS setstripe -c 1 -i 0 $DIR/$tdir
1336 echo "Inject failure stub to make the OST-object to back point to"
1337 echo "non-exist MDT-object."
1338 #define OBD_FAIL_LFSCK_UNMATCHED_PAIR1 0x1611
1340 do_facet ost1 $LCTL set_param fail_loc=0x1611
1341 dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=1
1342 cancel_lru_locks osc
1343 do_facet ost1 $LCTL set_param fail_loc=0
1345 echo "Trigger layout LFSCK to find out unmatched pairs and fix them"
1346 $START_LAYOUT -r || error "(1) Fail to start LFSCK for layout!"
1348 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1349 mdd.${MDT_DEV}.lfsck_layout |
1350 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1352 error "(2) unexpected status"
1355 local repaired=$($SHOW_LAYOUT |
1356 awk '/^repaired_unmatched_pair/ { print $2 }')
1357 [ $repaired -eq 1 ] ||
1358 error "(3) Fail to repair unmatched pair: $repaired"
1360 run_test 15a "LFSCK can repair unmatched MDT-object/OST-object pairs (1)"
1364 echo "If the OST-object referenced by the MDT-object back points"
1365 echo "to other MDT-object that doesn't recognize the OST-object,"
1366 echo "then the LFSCK should repair it to back point to the right"
1367 echo "MDT-object (the first one)."
1370 check_mount_and_prep
1371 $LFS setstripe -c 1 -i 0 $DIR/$tdir
1372 dd if=/dev/zero of=$DIR/$tdir/guard bs=1M count=1
1373 cancel_lru_locks osc
1375 echo "Inject failure stub to make the OST-object to back point to"
1376 echo "other MDT-object"
1378 #define OBD_FAIL_LFSCK_UNMATCHED_PAIR2 0x1612
1379 do_facet ost1 $LCTL set_param fail_loc=0x1612
1380 dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=1
1381 cancel_lru_locks osc
1382 do_facet ost1 $LCTL set_param fail_loc=0
1384 echo "Trigger layout LFSCK to find out unmatched pairs and fix them"
1385 $START_LAYOUT -r || error "(1) Fail to start LFSCK for layout!"
1387 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1388 mdd.${MDT_DEV}.lfsck_layout |
1389 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1391 error "(2) unexpected status"
1394 local repaired=$($SHOW_LAYOUT |
1395 awk '/^repaired_unmatched_pair/ { print $2 }')
1396 [ $repaired -eq 1 ] ||
1397 error "(3) Fail to repair unmatched pair: $repaired"
1399 run_test 15b "LFSCK can repair unmatched MDT-object/OST-object pairs (2)"
1403 echo "If the OST-object's owner information does not match the owner"
1404 echo "information stored in the MDT-object, then the LFSCK trust the"
1405 echo "MDT-object and update the OST-object's owner information."
1408 check_mount_and_prep
1409 $LFS setstripe -c 1 -i 0 $DIR/$tdir
1410 dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=1
1411 cancel_lru_locks osc
1413 echo "Inject failure stub to skip OST-object owner changing"
1414 #define OBD_FAIL_LFSCK_BAD_OWNER 0x1613
1415 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1613
1416 chown 1.1 $DIR/$tdir/f0
1417 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1419 echo "Trigger layout LFSCK to find out inconsistent OST-object owner"
1422 $START_LAYOUT -r || error "(1) Fail to start LFSCK for layout!"
1424 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1425 mdd.${MDT_DEV}.lfsck_layout |
1426 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1428 error "(2) unexpected status"
1431 local repaired=$($SHOW_LAYOUT |
1432 awk '/^repaired_inconsistent_owner/ { print $2 }')
1433 [ $repaired -eq 1 ] ||
1434 error "(3) Fail to repair inconsistent owner: $repaired"
1436 run_test 16 "LFSCK can repair inconsistent MDT-object/OST-object owner"
1440 echo "If more than one MDT-objects reference the same OST-object,"
1441 echo "and the OST-object only recognizes one MDT-object, then the"
1442 echo "LFSCK should create new OST-objects for such non-recognized"
1446 check_mount_and_prep
1447 $LFS setstripe -c 1 -i 0 $DIR/$tdir
1449 echo "Inject failure stub to make two MDT-objects to refernce"
1450 echo "the OST-object"
1452 #define OBD_FAIL_LFSCK_MULTIPLE_REF 0x1614
1453 do_facet $SINGLEMDS $LCTL set_param fail_val=0 fail_loc=0x1614
1455 dd if=/dev/zero of=$DIR/$tdir/guard bs=1M count=1
1456 cancel_lru_locks osc
1458 createmany -o $DIR/$tdir/f 1
1460 do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
1462 cancel_lru_locks mdc
1463 cancel_lru_locks osc
1465 echo "$DIR/$tdir/f0 and $DIR/$tdir/guard use the same OST-objects"
1466 local size=$(ls -l $DIR/$tdir/f0 | awk '{ print $5 }')
1467 [ $size -eq 1048576 ] ||
1468 error "(1) f0 (wrong) size should be 1048576, but got $size"
1470 echo "Trigger layout LFSCK to find out multiple refenced MDT-objects"
1473 $START_LAYOUT -r || error "(2) Fail to start LFSCK for layout!"
1475 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1476 mdd.${MDT_DEV}.lfsck_layout |
1477 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
1479 error "(3) unexpected status"
1482 local repaired=$($SHOW_LAYOUT |
1483 awk '/^repaired_multiple_referenced/ { print $2 }')
1484 [ $repaired -eq 1 ] ||
1485 error "(4) Fail to repair multiple references: $repaired"
1487 echo "$DIR/$tdir/f0 and $DIR/$tdir/guard should use diff OST-objects"
1488 dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=2 ||
1489 error "(5) Fail to write f0."
1490 size=$(ls -l $DIR/$tdir/guard | awk '{ print $5 }')
1491 [ $size -eq 1048576 ] ||
1492 error "(6) guard size should be 1048576, but got $size"
1494 run_test 17 "LFSCK can repair multiple references"
1498 echo "The target MDT-object is there, but related stripe information"
1499 echo "is lost or partly lost. The LFSCK should regenerate the missed"
1500 echo "layout EA entries."
1503 check_mount_and_prep
1504 $LFS mkdir -i 0 $DIR/$tdir/a1
1505 $LFS setstripe -c 1 -i 0 -s 1M $DIR/$tdir/a1
1506 dd if=/dev/zero of=$DIR/$tdir/a1/f1 bs=1M count=2
1508 local saved_size=$(ls -il $DIR/$tdir/a1/f1 | awk '{ print $6 }')
1510 $LFS path2fid $DIR/$tdir/a1/f1
1511 $LFS getstripe $DIR/$tdir/a1/f1
1513 if [ $MDSCOUNT -ge 2 ]; then
1514 $LFS mkdir -i 1 $DIR/$tdir/a2
1515 $LFS setstripe -c 2 -i 1 -s 1M $DIR/$tdir/a2
1516 dd if=/dev/zero of=$DIR/$tdir/a2/f2 bs=1M count=2
1517 $LFS path2fid $DIR/$tdir/a2/f2
1518 $LFS getstripe $DIR/$tdir/a2/f2
1521 cancel_lru_locks osc
1523 echo "Inject failure, to make the MDT-object lost its layout EA"
1524 #define OBD_FAIL_LFSCK_LOST_STRIPE 0x1615
1525 do_facet mds1 $LCTL set_param fail_loc=0x1615
1526 chown 1.1 $DIR/$tdir/a1/f1
1528 if [ $MDSCOUNT -ge 2 ]; then
1529 do_facet mds2 $LCTL set_param fail_loc=0x1615
1530 chown 1.1 $DIR/$tdir/a2/f2
1536 do_facet mds1 $LCTL set_param fail_loc=0
1537 if [ $MDSCOUNT -ge 2 ]; then
1538 do_facet mds2 $LCTL set_param fail_loc=0
1541 cancel_lru_locks mdc
1542 cancel_lru_locks osc
1544 echo "The file size should be incorrect since layout EA is lost"
1545 local cur_size=$(ls -il $DIR/$tdir/a1/f1 | awk '{ print $6 }')
1546 [ "$cur_size" != "$saved_size" ] ||
1547 error "(1) Expect incorrect file1 size"
1549 if [ $MDSCOUNT -ge 2 ]; then
1550 cur_size=$(ls -il $DIR/$tdir/a2/f2 | awk '{ print $6 }')
1551 [ "$cur_size" != "$saved_size" ] ||
1552 error "(2) Expect incorrect file2 size"
1555 echo "Trigger layout LFSCK on all devices to find out orphan OST-object"
1556 $START_LAYOUT -r -o || error "(3) Fail to start LFSCK for layout!"
1558 for k in $(seq $MDSCOUNT); do
1559 # The LFSCK status query internal is 30 seconds. For the case
1560 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1561 # time to guarantee the status sync up.
1562 wait_update_facet mds${k} "$LCTL get_param -n \
1563 mdd.$(facet_svc mds${k}).lfsck_layout |
1564 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1565 error "(4) MDS${k} is not the expected 'completed'"
1568 for k in $(seq $OSTCOUNT); do
1569 local cur_status=$(do_facet ost${k} $LCTL get_param -n \
1570 obdfilter.$(facet_svc ost${k}).lfsck_layout |
1571 awk '/^status/ { print $2 }')
1572 [ "$cur_status" == "completed" ] ||
1573 error "(5) OST${k} Expect 'completed', but got '$cur_status'"
1576 local repaired=$(do_facet mds1 $LCTL get_param -n \
1577 mdd.$(facet_svc mds1).lfsck_layout |
1578 awk '/^repaired_orphan/ { print $2 }')
1579 [ $repaired -eq 1 ] ||
1580 error "(6.1) Expect 1 fixed on mds1, but got: $repaired"
1582 if [ $MDSCOUNT -ge 2 ]; then
1583 repaired=$(do_facet mds2 $LCTL get_param -n \
1584 mdd.$(facet_svc mds2).lfsck_layout |
1585 awk '/^repaired_orphan/ { print $2 }')
1586 [ $repaired -eq 2 ] ||
1587 error "(6.2) Expect 2 fixed on mds2, but got: $repaired"
1590 $LFS path2fid $DIR/$tdir/a1/f1
1591 $LFS getstripe $DIR/$tdir/a1/f1
1593 if [ $MDSCOUNT -ge 2 ]; then
1594 $LFS path2fid $DIR/$tdir/a2/f2
1595 $LFS getstripe $DIR/$tdir/a2/f2
1598 echo "The file size should be correct after layout LFSCK scanning"
1599 cur_size=$(ls -il $DIR/$tdir/a1/f1 | awk '{ print $6 }')
1600 [ "$cur_size" == "$saved_size" ] ||
1601 error "(7) Expect file1 size $saved_size, but got $cur_size"
1603 if [ $MDSCOUNT -ge 2 ]; then
1604 cur_size=$(ls -il $DIR/$tdir/a2/f2 | awk '{ print $6 }')
1605 [ "$cur_size" == "$saved_size" ] ||
1606 error "(8) Expect file2 size $saved_size, but got $cur_size"
1609 run_test 18a "Find out orphan OST-object and repair it (1)"
1613 echo "The target MDT-object is lost. The LFSCK should re-create the"
1614 echo "MDT-object under .lustre/lost+found/MDTxxxx. The admin should"
1615 echo "can move it back to normal namespace manually."
1618 check_mount_and_prep
1619 $LFS mkdir -i 0 $DIR/$tdir/a1
1620 $LFS setstripe -c 1 -i 0 -s 1M $DIR/$tdir/a1
1621 dd if=/dev/zero of=$DIR/$tdir/a1/f1 bs=1M count=2
1622 local saved_size=$(ls -il $DIR/$tdir/a1/f1 | awk '{ print $6 }')
1623 local fid1=$($LFS path2fid $DIR/$tdir/a1/f1)
1625 $LFS getstripe $DIR/$tdir/a1/f1
1627 if [ $MDSCOUNT -ge 2 ]; then
1628 $LFS mkdir -i 1 $DIR/$tdir/a2
1629 $LFS setstripe -c 2 -i 1 -s 1M $DIR/$tdir/a2
1630 dd if=/dev/zero of=$DIR/$tdir/a2/f2 bs=1M count=2
1631 fid2=$($LFS path2fid $DIR/$tdir/a2/f2)
1633 $LFS getstripe $DIR/$tdir/a2/f2
1636 cancel_lru_locks osc
1638 echo "Inject failure, to simulate the case of missing the MDT-object"
1639 #define OBD_FAIL_LFSCK_LOST_MDTOBJ 0x1616
1640 do_facet mds1 $LCTL set_param fail_loc=0x1616
1641 rm -f $DIR/$tdir/a1/f1
1643 if [ $MDSCOUNT -ge 2 ]; then
1644 do_facet mds2 $LCTL set_param fail_loc=0x1616
1645 rm -f $DIR/$tdir/a2/f2
1651 do_facet mds1 $LCTL set_param fail_loc=0
1652 if [ $MDSCOUNT -ge 2 ]; then
1653 do_facet mds2 $LCTL set_param fail_loc=0
1656 cancel_lru_locks mdc
1657 cancel_lru_locks osc
1659 echo "Trigger layout LFSCK on all devices to find out orphan OST-object"
1660 $START_LAYOUT -r -o || error "(1) Fail to start LFSCK for layout!"
1662 for k in $(seq $MDSCOUNT); do
1663 # The LFSCK status query internal is 30 seconds. For the case
1664 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1665 # time to guarantee the status sync up.
1666 wait_update_facet mds${k} "$LCTL get_param -n \
1667 mdd.$(facet_svc mds${k}).lfsck_layout |
1668 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1669 error "(2) MDS${k} is not the expected 'completed'"
1672 for k in $(seq $OSTCOUNT); do
1673 local cur_status=$(do_facet ost${k} $LCTL get_param -n \
1674 obdfilter.$(facet_svc ost${k}).lfsck_layout |
1675 awk '/^status/ { print $2 }')
1676 [ "$cur_status" == "completed" ] ||
1677 error "(3) OST${k} Expect 'completed', but got '$cur_status'"
1680 local repaired=$(do_facet mds1 $LCTL get_param -n \
1681 mdd.$(facet_svc mds1).lfsck_layout |
1682 awk '/^repaired_orphan/ { print $2 }')
1683 [ $repaired -eq 1 ] ||
1684 error "(4.1) Expect 1 fixed on mds1, but got: $repaired"
1686 if [ $MDSCOUNT -ge 2 ]; then
1687 repaired=$(do_facet mds2 $LCTL get_param -n \
1688 mdd.$(facet_svc mds2).lfsck_layout |
1689 awk '/^repaired_orphan/ { print $2 }')
1690 [ $repaired -eq 2 ] ||
1691 error "(4.2) Expect 2 fixed on mds2, but got: $repaired"
1694 echo "Move the files from ./lustre/lost+found/MDTxxxx to namespace"
1695 mv $MOUNT/.lustre/lost+found/MDT0000/R-${fid1} $DIR/$tdir/a1/f1 ||
1696 error "(5) Fail to move $MOUNT/.lustre/lost+found/MDT0000/R-${fid1}"
1698 if [ $MDSCOUNT -ge 2 ]; then
1699 local name=$MOUNT/.lustre/lost+found/MDT0001/R-${fid2}
1700 mv $name $DIR/$tdir/a2/f2 || error "(6) Fail to move $name"
1703 $LFS path2fid $DIR/$tdir/a1/f1
1704 $LFS getstripe $DIR/$tdir/a1/f1
1706 if [ $MDSCOUNT -ge 2 ]; then
1707 $LFS path2fid $DIR/$tdir/a2/f2
1708 $LFS getstripe $DIR/$tdir/a2/f2
1711 echo "The file size should be correct after layout LFSCK scanning"
1712 local cur_size=$(ls -il $DIR/$tdir/a1/f1 | awk '{ print $6 }')
1713 [ "$cur_size" == "$saved_size" ] ||
1714 error "(7) Expect file1 size $saved_size, but got $cur_size"
1716 if [ $MDSCOUNT -ge 2 ]; then
1717 cur_size=$(ls -il $DIR/$tdir/a2/f2 | awk '{ print $6 }')
1718 [ "$cur_size" == "$saved_size" ] ||
1719 error "(8) Expect file2 size $saved_size, but got $cur_size"
1722 run_test 18b "Find out orphan OST-object and repair it (2)"
1726 echo "The target MDT-object is lost, and the OST-object FID is missing."
1727 echo "The LFSCK should re-create the MDT-object with new FID under the "
1728 echo "directory .lustre/lost+found/MDTxxxx."
1731 check_mount_and_prep
1732 $LFS mkdir -i 0 $DIR/$tdir/a1
1733 $LFS setstripe -c 1 -i 0 -s 1M $DIR/$tdir/a1
1735 echo "Inject failure, to simulate the case of missing parent FID"
1736 #define OBD_FAIL_LFSCK_NOPFID 0x1617
1737 do_facet ost1 $LCTL set_param fail_loc=0x1617
1739 dd if=/dev/zero of=$DIR/$tdir/a1/f1 bs=1M count=2
1740 $LFS getstripe $DIR/$tdir/a1/f1
1742 if [ $MDSCOUNT -ge 2 ]; then
1743 $LFS mkdir -i 1 $DIR/$tdir/a2
1744 $LFS setstripe -c 2 -i 1 -s 1M $DIR/$tdir/a2
1745 do_facet ost2 $LCTL set_param fail_loc=0x1617
1746 dd if=/dev/zero of=$DIR/$tdir/a2/f2 bs=1M count=2
1747 $LFS getstripe $DIR/$tdir/a2/f2
1750 cancel_lru_locks osc
1752 echo "Inject failure, to simulate the case of missing the MDT-object"
1753 #define OBD_FAIL_LFSCK_LOST_MDTOBJ 0x1616
1754 do_facet mds1 $LCTL set_param fail_loc=0x1616
1755 rm -f $DIR/$tdir/a1/f1
1757 if [ $MDSCOUNT -ge 2 ]; then
1758 do_facet mds2 $LCTL set_param fail_loc=0x1616
1759 rm -f $DIR/$tdir/a2/f2
1765 do_facet mds1 $LCTL set_param fail_loc=0
1766 if [ $MDSCOUNT -ge 2 ]; then
1767 do_facet mds2 $LCTL set_param fail_loc=0
1770 cancel_lru_locks mdc
1771 cancel_lru_locks osc
1773 echo "Trigger layout LFSCK on all devices to find out orphan OST-object"
1774 $START_LAYOUT -r -o || error "(1) Fail to start LFSCK for layout!"
1776 for k in $(seq $MDSCOUNT); do
1777 # The LFSCK status query internal is 30 seconds. For the case
1778 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1779 # time to guarantee the status sync up.
1780 wait_update_facet mds${k} "$LCTL get_param -n \
1781 mdd.$(facet_svc mds${k}).lfsck_layout |
1782 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1783 error "(2) MDS${k} is not the expected 'completed'"
1786 for k in $(seq $OSTCOUNT); do
1787 local cur_status=$(do_facet ost${k} $LCTL get_param -n \
1788 obdfilter.$(facet_svc ost${k}).lfsck_layout |
1789 awk '/^status/ { print $2 }')
1790 [ "$cur_status" == "completed" ] ||
1791 error "(3) OST${k} Expect 'completed', but got '$cur_status'"
1794 if [ $MDSCOUNT -ge 2 ]; then
1800 local repaired=$(do_facet mds1 $LCTL get_param -n \
1801 mdd.$(facet_svc mds1).lfsck_layout |
1802 awk '/^repaired_orphan/ { print $2 }')
1803 [ $repaired -eq $expected ] ||
1804 error "(4) Expect $expected fixed on mds1, but got: $repaired"
1806 if [ $MDSCOUNT -ge 2 ]; then
1807 repaired=$(do_facet mds2 $LCTL get_param -n \
1808 mdd.$(facet_svc mds2).lfsck_layout |
1809 awk '/^repaired_orphan/ { print $2 }')
1810 [ $repaired -eq 0 ] ||
1811 error "(5) Expect 0 fixed on mds2, but got: $repaired"
1814 echo "There should be some stub under .lustre/lost+found/MDT0001/"
1815 ls -ail $MOUNT/.lustre/lost+found/MDT0001/N-* &&
1816 error "(6) .lustre/lost+found/MDT0001/ should be empty"
1818 echo "There should be some stub under .lustre/lost+found/MDT0000/"
1819 ls -ail $MOUNT/.lustre/lost+found/MDT0000/N-* ||
1820 error "(7) .lustre/lost+found/MDT0000/ should not be empty"
1822 run_test 18c "Find out orphan OST-object and repair it (3)"
1826 echo "The target MDT-object layout EA slot is occpuied by some new"
1827 echo "created OST-object when repair dangling reference case. Such"
1828 echo "conflict OST-object has never been modified. Then when found"
1829 echo "the orphan OST-object, LFSCK will replace it with the orphan"
1833 check_mount_and_prep
1835 $LFS setstripe -c 1 -i 0 -s 1M $DIR/$tdir/a1
1836 echo "guard" > $DIR/$tdir/a1/f1
1837 echo "foo" > $DIR/$tdir/a1/f2
1838 local saved_size=$(ls -il $DIR/$tdir/a1/f2 | awk '{ print $6 }')
1839 $LFS path2fid $DIR/$tdir/a1/f1
1840 $LFS getstripe $DIR/$tdir/a1/f1
1841 $LFS path2fid $DIR/$tdir/a1/f2
1842 $LFS getstripe $DIR/$tdir/a1/f2
1843 cancel_lru_locks osc
1845 echo "Inject failure to make $DIR/$tdir/a1/f1 and $DIR/$tdir/a1/f2"
1846 echo "to reference the same OST-object (which is f1's OST-obejct)."
1847 echo "Then drop $DIR/$tdir/a1/f1 and its OST-object, so f2 becomes"
1848 echo "dangling reference case, but f2's old OST-object is there."
1851 #define OBD_FAIL_LFSCK_CHANGE_STRIPE 0x1618
1852 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1618
1853 chown 1.1 $DIR/$tdir/a1/f2
1854 rm -f $DIR/$tdir/a1/f1
1857 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1859 echo "stopall to cleanup object cache"
1862 setupall > /dev/null
1864 echo "The file size should be incorrect since dangling referenced"
1865 local cur_size=$(ls -il $DIR/$tdir/a1/f2 | awk '{ print $6 }')
1866 [ "$cur_size" != "$saved_size" ] ||
1867 error "(1) Expect incorrect file2 size"
1869 #define OBD_FAIL_LFSCK_DELAY3 0x1602
1870 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x1602
1872 echo "Trigger layout LFSCK on all devices to find out orphan OST-object"
1873 $START_LAYOUT -r -o -c || error "(2) Fail to start LFSCK for layout!"
1875 wait_update_facet mds1 "$LCTL get_param -n \
1876 mdd.$(facet_svc mds1).lfsck_layout |
1877 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 ||
1878 error "(3.0) MDS1 is not the expected 'scanning-phase2'"
1880 # LU-3469: before osp_sync() is enabled, wait for a while to guarantee
1881 # that former async repair operations have been executed on the OST(s).
1885 do_facet $SINGLEMDS $LCTL set_param fail_val=0 fail_loc=0
1887 for k in $(seq $MDSCOUNT); do
1888 # The LFSCK status query internal is 30 seconds. For the case
1889 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1890 # time to guarantee the status sync up.
1891 wait_update_facet mds${k} "$LCTL get_param -n \
1892 mdd.$(facet_svc mds${k}).lfsck_layout |
1893 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1894 error "(3) MDS${k} is not the expected 'completed'"
1897 for k in $(seq $OSTCOUNT); do
1898 local cur_status=$(do_facet ost${k} $LCTL get_param -n \
1899 obdfilter.$(facet_svc ost${k}).lfsck_layout |
1900 awk '/^status/ { print $2 }')
1901 [ "$cur_status" == "completed" ] ||
1902 error "(4) OST${k} Expect 'completed', but got '$cur_status'"
1905 local repaired=$(do_facet $SINGLEMDS $LCTL get_param -n \
1906 mdd.$(facet_svc $SINGLEMDS).lfsck_layout |
1907 awk '/^repaired_orphan/ { print $2 }')
1908 [ $repaired -eq 1 ] ||
1909 error "(5) Expect 1 orphan has been fixed, but got: $repaired"
1911 echo "The file size should be correct after layout LFSCK scanning"
1912 cur_size=$(ls -il $DIR/$tdir/a1/f2 | awk '{ print $6 }')
1913 [ "$cur_size" == "$saved_size" ] ||
1914 error "(6) Expect file2 size $saved_size, but got $cur_size"
1916 echo "The LFSCK should find back the original data."
1917 cat $DIR/$tdir/a1/f2
1918 $LFS path2fid $DIR/$tdir/a1/f2
1919 $LFS getstripe $DIR/$tdir/a1/f2
1921 run_test 18d "Find out orphan OST-object and repair it (4)"
1925 echo "The target MDT-object layout EA slot is occpuied by some new"
1926 echo "created OST-object when repair dangling reference case. Such"
1927 echo "conflict OST-object has been modified by others. To keep the"
1928 echo "new data, the LFSCK will create a new file to refernece this"
1929 echo "old orphan OST-object."
1932 check_mount_and_prep
1934 $LFS setstripe -c 1 -i 0 -s 1M $DIR/$tdir/a1
1935 echo "guard" > $DIR/$tdir/a1/f1
1936 echo "foo" > $DIR/$tdir/a1/f2
1937 local saved_size=$(ls -il $DIR/$tdir/a1/f2 | awk '{ print $6 }')
1938 $LFS path2fid $DIR/$tdir/a1/f1
1939 $LFS getstripe $DIR/$tdir/a1/f1
1940 $LFS path2fid $DIR/$tdir/a1/f2
1941 $LFS getstripe $DIR/$tdir/a1/f2
1942 cancel_lru_locks osc
1944 echo "Inject failure to make $DIR/$tdir/a1/f1 and $DIR/$tdir/a1/f2"
1945 echo "to reference the same OST-object (which is f1's OST-obejct)."
1946 echo "Then drop $DIR/$tdir/a1/f1 and its OST-object, so f2 becomes"
1947 echo "dangling reference case, but f2's old OST-object is there."
1950 #define OBD_FAIL_LFSCK_CHANGE_STRIPE 0x1618
1951 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1618
1952 chown 1.1 $DIR/$tdir/a1/f2
1953 rm -f $DIR/$tdir/a1/f1
1956 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1958 echo "stopall to cleanup object cache"
1961 setupall > /dev/null
1963 echo "The file size should be incorrect since dangling referenced"
1964 local cur_size=$(ls -il $DIR/$tdir/a1/f2 | awk '{ print $6 }')
1965 [ "$cur_size" != "$saved_size" ] ||
1966 error "(1) Expect incorrect file2 size"
1968 #define OBD_FAIL_LFSCK_DELAY3 0x1602
1969 do_facet $SINGLEMDS $LCTL set_param fail_val=10 fail_loc=0x1602
1971 echo "Trigger layout LFSCK on all devices to find out orphan OST-object"
1972 $START_LAYOUT -r -o -c || error "(2) Fail to start LFSCK for layout!"
1974 wait_update_facet mds1 "$LCTL get_param -n \
1975 mdd.$(facet_svc mds1).lfsck_layout |
1976 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 ||
1977 error "(3) MDS1 is not the expected 'scanning-phase2'"
1979 # to guarantee all updates are synced.
1983 echo "Write new data to f2 to modify the new created OST-object."
1984 echo "dummy" >> $DIR/$tdir/a1/f2
1986 do_facet $SINGLEMDS $LCTL set_param fail_val=0 fail_loc=0
1988 for k in $(seq $MDSCOUNT); do
1989 # The LFSCK status query internal is 30 seconds. For the case
1990 # of some LFSCK_NOTIFY RPCs failure/lost, we will wait enough
1991 # time to guarantee the status sync up.
1992 wait_update_facet mds${k} "$LCTL get_param -n \
1993 mdd.$(facet_svc mds${k}).lfsck_layout |
1994 awk '/^status/ { print \\\$2 }'" "completed" 32 ||
1995 error "(4) MDS${k} is not the expected 'completed'"
1998 for k in $(seq $OSTCOUNT); do
1999 local cur_status=$(do_facet ost${k} $LCTL get_param -n \
2000 obdfilter.$(facet_svc ost${k}).lfsck_layout |
2001 awk '/^status/ { print $2 }')
2002 [ "$cur_status" == "completed" ] ||
2003 error "(5) OST${k} Expect 'completed', but got '$cur_status'"
2006 local repaired=$(do_facet $SINGLEMDS $LCTL get_param -n \
2007 mdd.$(facet_svc $SINGLEMDS).lfsck_layout |
2008 awk '/^repaired_orphan/ { print $2 }')
2009 [ $repaired -eq 1 ] ||
2010 error "(6) Expect 1 orphan has been fixed, but got: $repaired"
2012 echo "There should be stub file under .lustre/lost+found/MDT0000/"
2013 local cname=$(ls $MOUNT/.lustre/lost+found/MDT0000/C-*)
2015 error "(7) .lustre/lost+found/MDT0000/ should not be empty"
2017 echo "The stub file should keep the original f2 data"
2018 cur_size=$(ls -il $cname | awk '{ print $6 }')
2019 [ "$cur_size" == "$saved_size" ] ||
2020 error "(8) Expect file2 size $saved_size, but got $cur_size"
2023 $LFS path2fid $cname
2024 $LFS getstripe $cname
2026 echo "The f2 should contains new data."
2027 cat $DIR/$tdir/a1/f2
2028 $LFS path2fid $DIR/$tdir/a1/f2
2029 $LFS getstripe $DIR/$tdir/a1/f2
2031 run_test 18e "Find out orphan OST-object and repair it (5)"
2034 check_mount_and_prep
2035 $LFS setstripe -c 1 -i 0 $DIR/$tdir
2037 echo "foo" > $DIR/$tdir/a0
2038 echo "guard" > $DIR/$tdir/a1
2039 cancel_lru_locks osc
2041 echo "Inject failure, then client will offer wrong parent FID when read"
2042 do_facet ost1 $LCTL set_param -n \
2043 obdfilter.${FSNAME}-OST0000.lfsck_verify_pfid 1
2044 #define OBD_FAIL_LFSCK_INVALID_PFID 0x1619
2045 $LCTL set_param fail_loc=0x1619
2047 echo "Read RPC with wrong parent FID should be denied"
2048 cat $DIR/$tdir/a0 && error "(3) Read should be denied!"
2049 $LCTL set_param fail_loc=0
2051 run_test 19a "OST-object inconsistency self detect"
2054 check_mount_and_prep
2055 $LFS setstripe -c 1 -i 0 $DIR/$tdir
2057 echo "Inject failure stub to make the OST-object to back point to"
2058 echo "non-exist MDT-object"
2060 #define OBD_FAIL_LFSCK_UNMATCHED_PAIR1 0x1611
2061 do_facet ost1 $LCTL set_param fail_loc=0x1611
2062 echo "foo" > $DIR/$tdir/f0
2063 cancel_lru_locks osc
2064 do_facet ost1 $LCTL set_param fail_loc=0
2066 echo "Nothing should be fixed since self detect and repair is disabled"
2067 local repaired=$(do_facet ost1 $LCTL get_param -n \
2068 obdfilter.${FSNAME}-OST0000.lfsck_verify_pfid |
2069 awk '/^repaired/ { print $2 }')
2070 [ $repaired -eq 0 ] ||
2071 error "(1) Expected 0 repaired, but got $repaired"
2073 echo "Read RPC with right parent FID should be accepted,"
2074 echo "and cause parent FID on OST to be fixed"
2076 do_facet ost1 $LCTL set_param -n \
2077 obdfilter.${FSNAME}-OST0000.lfsck_verify_pfid 1
2078 cat $DIR/$tdir/f0 || error "(2) Read should not be denied!"
2080 repaired=$(do_facet ost1 $LCTL get_param -n \
2081 obdfilter.${FSNAME}-OST0000.lfsck_verify_pfid |
2082 awk '/^repaired/ { print $2 }')
2083 [ $repaired -eq 1 ] ||
2084 error "(3) Expected 1 repaired, but got $repaired"
2086 run_test 19b "OST-object inconsistency self repair"
2088 $LCTL set_param debug=-lfsck > /dev/null || true
2090 # restore MDS/OST size
2091 MDSSIZE=${SAVED_MDSSIZE}
2092 OSTSIZE=${SAVED_OSTSIZE}
2093 OSTCOUNT=${SAVED_OSTCOUNT}
2095 # cleanup the system at last