Whamcloud - gitweb
LU-6000 tests: avoid test failure on b2_4 server
[fs/lustre-release.git] / lustre / tests / sanity-lfsck.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 ALWAYS_EXCEPT="$SANITY_LFSCK_EXCEPT"
11 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
15 . $LUSTRE/tests/test-framework.sh
16 init_test_env $@
17 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
18 init_logging
19
20 [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
21         skip "test LFSCK only for ldiskfs" && exit 0
22 require_dsh_mds || exit 0
23
24 MCREATE=${MCREATE:-mcreate}
25 SAVED_MDSSIZE=${MDSSIZE}
26 SAVED_OSTSIZE=${OSTSIZE}
27 SAVED_OSTCOUNT=${OSTCOUNT}
28 # use small MDS + OST size to speed formatting time
29 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
30 MDSSIZE=100000
31 OSTSIZE=100000
32 # no need too much OSTs, to reduce the format/start/stop overhead
33 [ $OSTCOUNT -gt 4 ] && OSTCOUNT=4
34
35 # build up a clean test environment.
36 formatall
37 setupall
38
39 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.60) ]] &&
40         skip "Need MDS version at least 2.3.60" && check_and_cleanup_lustre &&
41         exit 0
42
43 [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.4.90) ]] &&
44         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 2c"
45
46 build_test_filter
47
48 $LCTL set_param debug=+lfsck > /dev/null || true
49
50 MDT_DEV="${FSNAME}-MDT0000"
51 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
52 START_NAMESPACE="do_facet $SINGLEMDS \
53                 $LCTL lfsck_start -M ${MDT_DEV} -t namespace"
54 STOP_LFSCK="do_facet $SINGLEMDS $LCTL lfsck_stop -M ${MDT_DEV}"
55 SHOW_NAMESPACE="do_facet $SINGLEMDS \
56                 $LCTL get_param -n mdd.${MDT_DEV}.lfsck_namespace"
57 MOUNT_OPTS_SCRUB="-o user_xattr"
58 MOUNT_OPTS_NOSCRUB="-o user_xattr,noscrub"
59
60 lfsck_prep() {
61         local ndirs=$1
62         local nfiles=$2
63         local igif=$3
64
65         check_mount_and_prep
66
67         echo "preparing... $nfiles * $ndirs files will be created $(date)."
68         if [ ! -z $igif ]; then
69                 #define OBD_FAIL_FID_IGIF       0x1504
70                 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1504
71         fi
72
73         cp $LUSTRE/tests/*.sh $DIR/$tdir/
74         if [ $ndirs -gt 0 ]; then
75                 createmany -d $DIR/$tdir/d $ndirs
76                 createmany -m $DIR/$tdir/f $ndirs
77                 if [ $nfiles -gt 0 ]; then
78                         for ((i = 0; i < $ndirs; i++)); do
79                                 createmany -m $DIR/$tdir/d${i}/f $nfiles > \
80                                         /dev/null || error "createmany $nfiles"
81                         done
82                 fi
83                 createmany -d $DIR/$tdir/e $ndirs
84         fi
85
86         if [ ! -z $igif ]; then
87                 touch $DIR/$tdir/dummy
88                 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
89         fi
90
91         echo "prepared $(date)."
92 }
93
94 test_0() {
95         lfsck_prep 3 3
96
97         #define OBD_FAIL_LFSCK_DELAY1           0x1600
98         do_facet $SINGLEMDS $LCTL set_param fail_val=3 fail_loc=0x1600
99         $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
100
101         $SHOW_NAMESPACE || error "Fail to monitor LFSCK (3)"
102
103         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
104         [ "$STATUS" == "scanning-phase1" ] ||
105                 error "(4) Expect 'scanning-phase1', but got '$STATUS'"
106
107         $STOP_LFSCK || error "(5) Fail to stop LFSCK!"
108
109         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
110         [ "$STATUS" == "stopped" ] ||
111                 error "(6) Expect 'stopped', but got '$STATUS'"
112
113         $START_NAMESPACE || error "(7) Fail to start LFSCK for namespace!"
114
115         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
116         [ "$STATUS" == "scanning-phase1" ] ||
117                 error "(8) Expect 'scanning-phase1', but got '$STATUS'"
118
119         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
120         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
121                 mdd.${MDT_DEV}.lfsck_namespace |
122                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
123                 $SHOW_NAMESPACE
124                 error "(9) unexpected status"
125         }
126
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"
131
132         local scanned1=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
133         $START_NAMESPACE -r || error "(11) Fail to reset LFSCK!"
134         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
135                 mdd.${MDT_DEV}.lfsck_namespace |
136                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
137                 $SHOW_NAMESPACE
138                 error "(12) unexpected status"
139         }
140
141         local scanned2=$($SHOW_NAMESPACE | awk '/^success_count/ { print $2 }')
142         [ $((scanned1 + 1)) -eq $scanned2 ] ||
143                 error "(13) Expect success $((scanned1 + 1)), but got $scanned2"
144
145         echo "stopall, should NOT crash LU-3649"
146         stopall || error "(14) Fail to stopall"
147 }
148 run_test 0 "Control LFSCK manually"
149
150 test_1a() {
151         lfsck_prep 1 1
152
153         #define OBD_FAIL_FID_INDIR      0x1501
154         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1501
155         touch $DIR/$tdir/dummy
156
157         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
158         umount_client $MOUNT
159         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
160         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
161                 mdd.${MDT_DEV}.lfsck_namespace |
162                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
163                 $SHOW_NAMESPACE
164                 error "(4) unexpected status"
165         }
166
167         local repaired=$($SHOW_NAMESPACE |
168                          awk '/^updated_phase1/ { print $2 }')
169         [ $repaired -eq 1 ] ||
170                 error "(5) Fail to repair crashed FID-in-dirent: $repaired"
171
172         mount_client $MOUNT || error "(6) Fail to start client!"
173
174         #define OBD_FAIL_FID_LOOKUP     0x1505
175         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
176         ls $DIR/$tdir/ > /dev/null || error "(7) no FID-in-dirent."
177
178         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
179         cancel_lru_locks mdc
180 }
181 run_test 1a "LFSCK can find out and repair crashed FID-in-dirent"
182
183 test_1b()
184 {
185         lfsck_prep 1 1
186
187         #define OBD_FAIL_FID_INLMA      0x1502
188         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1502
189         touch $DIR/$tdir/dummy
190
191         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
192         umount_client $MOUNT
193         #define OBD_FAIL_FID_NOLMA      0x1506
194         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1506
195         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
196         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
197                 mdd.${MDT_DEV}.lfsck_namespace |
198                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
199                 $SHOW_NAMESPACE
200                 error "(4) unexpected status"
201         }
202
203         local repaired=$($SHOW_NAMESPACE |
204                          awk '/^updated_phase1/ { print $2 }')
205         [ $repaired -eq 1 ] ||
206                 error "(5) Fail to repair missed FID-in-LMA: $repaired"
207
208         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
209         mount_client $MOUNT || error "(6) Fail to start client!"
210
211         #define OBD_FAIL_FID_LOOKUP     0x1505
212         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
213         stat $DIR/$tdir/dummy > /dev/null || error "(7) no FID-in-LMA."
214
215         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
216         cancel_lru_locks mdc
217 }
218 run_test 1b "LFSCK can find out and repair missed FID-in-LMA"
219
220 test_2a() {
221         lfsck_prep 1 1
222
223         #define OBD_FAIL_LFSCK_LINKEA_CRASH     0x1603
224         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
225         touch $DIR/$tdir/dummy
226
227         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
228         umount_client $MOUNT
229         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
230         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
231                 mdd.${MDT_DEV}.lfsck_namespace |
232                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
233                 $SHOW_NAMESPACE
234                 error "(4) unexpected status"
235         }
236
237         local repaired=$($SHOW_NAMESPACE |
238                          awk '/^updated_phase1/ { print $2 }')
239         [ $repaired -eq 1 ] ||
240                 error "(5) Fail to repair crashed linkEA: $repaired"
241
242         mount_client $MOUNT || error "(6) Fail to start client!"
243
244         stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
245                 error "(7) Fail to stat $DIR/$tdir/dummy"
246
247         local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
248         local dummyname=$($LFS fid2path $DIR $dummyfid)
249         [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
250                 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
251 }
252 run_test 2a "LFSCK can find out and repair crashed linkEA entry"
253
254 test_2b()
255 {
256         lfsck_prep 1 1
257
258         #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
259         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
260         touch $DIR/$tdir/dummy
261
262         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
263         umount_client $MOUNT
264         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
265         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
266                 mdd.${MDT_DEV}.lfsck_namespace |
267                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
268                 $SHOW_NAMESPACE
269                 error "(4) unexpected status"
270         }
271
272         local repaired=$($SHOW_NAMESPACE |
273                          awk '/^updated_phase2/ { print $2 }')
274         [ $repaired -eq 1 ] ||
275                 error "(5) Fail to repair crashed linkEA: $repaired"
276
277         mount_client $MOUNT || error "(6) Fail to start client!"
278
279         stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
280                 error "(7) Fail to stat $DIR/$tdir/dummy"
281
282         local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
283         local dummyname=$($LFS fid2path $DIR $dummyfid)
284         [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
285                 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
286 }
287 run_test 2b "LFSCK can find out and remove invalid linkEA entry"
288
289 test_2c()
290 {
291         lfsck_prep 1 1
292
293         #define OBD_FAIL_LFSCK_LINKEA_MORE2     0x1605
294         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1605
295         touch $DIR/$tdir/dummy
296
297         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
298         umount_client $MOUNT
299         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
300         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
301                 mdd.${MDT_DEV}.lfsck_namespace |
302                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
303                 $SHOW_NAMESPACE
304                 error "(4) unexpected status"
305         }
306
307         local repaired=$($SHOW_NAMESPACE |
308                          awk '/^updated_phase2/ { print $2 }')
309         [ $repaired -eq 1 ] ||
310                 error "(5) Fail to repair crashed linkEA: $repaired"
311
312         mount_client $MOUNT || error "(6) Fail to start client!"
313
314         stat $DIR/$tdir/dummy | grep "Links: 1" > /dev/null ||
315                 error "(7) Fail to stat $DIR/$tdir/dummy"
316
317         local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
318         local dummyname=$($LFS fid2path $DIR $dummyfid)
319         [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
320                 error "(8) Fail to repair linkEA: $dummyfid $dummyname"
321 }
322 run_test 2c "LFSCK can find out and remove repeated linkEA entry"
323
324 test_4()
325 {
326         lfsck_prep 3 3
327         cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
328         stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
329
330         mds_backup_restore $SINGLEMDS || error "(1) Fail to backup/restore!"
331         echo "start $SINGLEMDS with disabling OI scrub"
332         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
333                 error "(2) Fail to start MDS!"
334
335         #define OBD_FAIL_LFSCK_DELAY2           0x1601
336         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
337         $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
338         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
339                 mdd.${MDT_DEV}.lfsck_namespace |
340                 awk '/^flags/ { print \\\$2 }'" "inconsistent" 6 || {
341                 $SHOW_NAMESPACE
342                 error "(5) unexpected status"
343         }
344
345         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
346         [ "$STATUS" == "scanning-phase1" ] ||
347                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
348
349         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
350         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
351                 mdd.${MDT_DEV}.lfsck_namespace |
352                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
353                 $SHOW_NAMESPACE
354                 error "(7) unexpected status"
355         }
356
357         FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
358         [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
359
360         local repaired=$($SHOW_NAMESPACE |
361                          awk '/^updated_phase1/ { print $2 }')
362         [ $repaired -ge 9 ] ||
363                 error "(9) Fail to repair crashed linkEA: $repaired"
364
365         mount_client $MOUNT || error "(10) Fail to start client!"
366
367         #define OBD_FAIL_FID_LOOKUP     0x1505
368         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
369         ls $DIR/$tdir/ > /dev/null || error "(11) no FID-in-dirent."
370
371         local server_version=$(lustre_version_code $SINGLEMDS)
372         if [[ $server_version -ge $(version_code 2.5.58) ]] ||
373            [[ $server_version -ge $(version_code 2.5.4) &&
374               $server_version -lt $(version_code 2.5.11) ]]; then
375                 local count=$(ls -al $DIR/$tdir | wc -l)
376                 [ $count -gt 9 ] || error "(12) namespace LFSCK failed"
377         fi
378
379         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
380         cancel_lru_locks mdc
381 }
382 run_test 4 "FID-in-dirent can be rebuilt after MDT file-level backup/restore"
383
384 test_5()
385 {
386         lfsck_prep 1 1 1
387         cleanup_mount $MOUNT || error "(0.1) Fail to stop client!"
388         stop $SINGLEMDS > /dev/null || error "(0.2) Fail to stop MDS!"
389
390         mds_backup_restore $SINGLEMDS 1 || error "(1) Fail to backup/restore!"
391         echo "start $SINGLEMDS with disabling OI scrub"
392         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_NOSCRUB > /dev/null ||
393                 error "(2) Fail to start MDS!"
394
395         #define OBD_FAIL_LFSCK_DELAY2           0x1601
396         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
397         $START_NAMESPACE -r || error "(4) Fail to start LFSCK for namespace!"
398         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
399                 mdd.${MDT_DEV}.lfsck_namespace |
400                 awk '/^flags/ { print \\\$2 }'" "inconsistent,upgrade" 6 || {
401                 $SHOW_NAMESPACE
402                 error "(5) unexpected status"
403         }
404
405         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
406         [ "$STATUS" == "scanning-phase1" ] ||
407                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
408
409         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
410         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
411                 mdd.${MDT_DEV}.lfsck_namespace |
412                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
413                 $SHOW_NAMESPACE
414                 error "(7) unexpected status"
415         }
416
417         FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
418         [ -z "$FLAGS" ] || error "(8) Expect empty flags, but got '$FLAGS'"
419
420         local repaired=$($SHOW_NAMESPACE |
421                          awk '/^updated_phase1/ { print $2 }')
422         [ $repaired -ge 2 ] ||
423                 error "(9) Fail to repair crashed linkEA: $repaired"
424
425         mount_client $MOUNT || error "(10) Fail to start client!"
426
427         #define OBD_FAIL_FID_LOOKUP     0x1505
428         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1505
429         stat $DIR/$tdir/dummy > /dev/null || error "(11) no FID-in-LMA."
430
431         ls $DIR/$tdir/ > /dev/null || error "(12) no FID-in-dirent."
432
433         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
434         cancel_lru_locks mdc
435         local dummyfid=$($LFS path2fid $DIR/$tdir/dummy)
436         local dummyname=$($LFS fid2path $DIR $dummyfid)
437         [ "$dummyname" == "$DIR/$tdir/dummy" ] ||
438                 error "(13) Fail to generate linkEA: $dummyfid $dummyname"
439 }
440 run_test 5 "LFSCK can handle IGIF object upgrading"
441
442 test_6a() {
443         lfsck_prep 5 5
444
445         #define OBD_FAIL_LFSCK_DELAY1           0x1600
446         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
447         $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
448
449         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
450         [ "$STATUS" == "scanning-phase1" ] ||
451                 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
452
453         # Sleep 3 sec to guarantee at least one object processed by LFSCK
454         sleep 3
455         # Fail the LFSCK to guarantee there is at least one checkpoint
456         #define OBD_FAIL_LFSCK_FATAL1           0x1608
457         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001608
458         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
459                 mdd.${MDT_DEV}.lfsck_namespace |
460                 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
461                 $SHOW_NAMESPACE
462                 error "(4) unexpected status"
463         }
464
465         local POS0=$($SHOW_NAMESPACE |
466                      awk '/^last_checkpoint_position/ { print $2 }' |
467                      tr -d ',')
468
469         #define OBD_FAIL_LFSCK_DELAY1           0x1600
470         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1600
471         $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
472
473         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
474         [ "$STATUS" == "scanning-phase1" ] ||
475                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
476
477         local POS1=$($SHOW_NAMESPACE |
478                      awk '/^latest_start_position/ { print $2 }' |
479                      tr -d ',')
480         [ $POS0 -lt $POS1 ] ||
481                 error "(7) Expect larger than: $POS0, but got $POS1"
482
483         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
484         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
485                 mdd.${MDT_DEV}.lfsck_namespace |
486                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
487                 $SHOW_NAMESPACE
488                 error "(8) unexpected status"
489         }
490 }
491 run_test 6a "LFSCK resumes from last checkpoint (1)"
492
493 test_6b() {
494         lfsck_prep 5 5
495
496         #define OBD_FAIL_LFSCK_DELAY2           0x1601
497         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
498         $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
499
500         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
501         [ "$STATUS" == "scanning-phase1" ] ||
502                 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
503
504         # Sleep 5 sec to guarantee that we are in the directory scanning
505         sleep 5
506         # Fail the LFSCK to guarantee there is at least one checkpoint
507         #define OBD_FAIL_LFSCK_FATAL2           0x1609
508         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
509         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
510                 mdd.${MDT_DEV}.lfsck_namespace |
511                 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
512                 $SHOW_NAMESPACE
513                 error "(4) unexpected status"
514         }
515
516         local O_POS0=$($SHOW_NAMESPACE |
517                        awk '/^last_checkpoint_position/ { print $2 }' |
518                        tr -d ',')
519
520         local D_POS0=$($SHOW_NAMESPACE |
521                        awk '/^last_checkpoint_position/ { print $4 }')
522
523         #define OBD_FAIL_LFSCK_DELAY2           0x1601
524         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
525         $START_NAMESPACE || error "(5) Fail to start LFSCK for namespace!"
526
527         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
528         [ "$STATUS" == "scanning-phase1" ] ||
529                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
530
531         local O_POS1=$($SHOW_NAMESPACE |
532                        awk '/^latest_start_position/ { print $2 }' |
533                        tr -d ',')
534         local D_POS1=$($SHOW_NAMESPACE |
535                        awk '/^latest_start_position/ { print $4 }')
536
537         if [ "$D_POS0" == "N/A" -o "$D_POS1" == "N/A" ]; then
538                 [ $O_POS0 -lt $O_POS1 ] ||
539                         error "(7.1) $O_POS1 is not larger than $O_POS0"
540         else
541                 [ $D_POS0 -lt $D_POS1 ] ||
542                         error "(7.2) $D_POS1 is not larger than $D_POS0"
543         fi
544
545         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
546         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
547                 mdd.${MDT_DEV}.lfsck_namespace |
548                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
549                 $SHOW_NAMESPACE
550                 error "(8) unexpected status"
551         }
552 }
553 run_test 6b "LFSCK resumes from last checkpoint (2)"
554
555 test_7a()
556 {
557         lfsck_prep 5 5
558         umount_client $MOUNT
559
560         #define OBD_FAIL_LFSCK_DELAY2           0x1601
561         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1601
562         $START_NAMESPACE -r || error "(2) Fail to start LFSCK for namespace!"
563
564         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
565         [ "$STATUS" == "scanning-phase1" ] ||
566                 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
567
568         # Sleep 3 sec to guarantee at least one object processed by LFSCK
569         sleep 3
570         echo "stop $SINGLEMDS"
571         stop $SINGLEMDS > /dev/null || error "(4) Fail to stop MDS!"
572
573         echo "start $SINGLEMDS"
574         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
575                 error "(5) Fail to start MDS!"
576
577         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
578         [ "$STATUS" == "scanning-phase1" ] ||
579                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
580
581         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
582         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
583                 mdd.${MDT_DEV}.lfsck_namespace |
584                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
585                 $SHOW_NAMESPACE
586                 error "(7) unexpected status"
587         }
588 }
589 run_test 7a "non-stopped LFSCK should auto restarts after MDS remount (1)"
590
591 test_7b()
592 {
593         lfsck_prep 2 2
594
595         #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
596         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
597         for ((i = 0; i < 20; i++)); do
598                 touch $DIR/$tdir/dummy${i}
599         done
600
601         #define OBD_FAIL_LFSCK_DELAY3           0x1602
602         do_facet $SINGLEMDS $LCTL set_param fail_val=1 fail_loc=0x1602
603         $START_NAMESPACE -r || error "(3) Fail to start LFSCK for namespace!"
604         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
605                 mdd.${MDT_DEV}.lfsck_namespace |
606                 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
607                 $SHOW_NAMESPACE
608                 error "(4) unexpected status"
609         }
610
611         echo "stop $SINGLEMDS"
612         stop $SINGLEMDS > /dev/null || error "(5) Fail to stop MDS!"
613
614         echo "start $SINGLEMDS"
615         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
616                 error "(6) Fail to start MDS!"
617
618         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
619         [ "$STATUS" == "scanning-phase2" ] ||
620                 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
621
622         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
623         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
624                 mdd.${MDT_DEV}.lfsck_namespace |
625                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
626                 $SHOW_NAMESPACE
627                 error "(8) unexpected status"
628         }
629 }
630 run_test 7b "non-stopped LFSCK should auto restarts after MDS remount (2)"
631
632 test_8()
633 {
634         echo "formatall"
635         formatall > /dev/null
636         echo "setupall"
637         setupall > /dev/null
638
639         lfsck_prep 20 20
640
641         local STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
642         [ "$STATUS" == "init" ] ||
643                 error "(2) Expect 'init', but got '$STATUS'"
644
645         #define OBD_FAIL_LFSCK_LINKEA_CRASH     0x1603
646         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
647         mkdir $DIR/$tdir/crashed
648
649         #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
650         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
651         for ((i = 0; i < 5; i++)); do
652                 touch $DIR/$tdir/dummy${i}
653         done
654
655         umount_client $MOUNT || error "(3) Fail to stop client!"
656
657         #define OBD_FAIL_LFSCK_DELAY2           0x1601
658         do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1601
659         $START_NAMESPACE || error "(4) Fail to start LFSCK for namespace!"
660
661         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
662         [ "$STATUS" == "scanning-phase1" ] ||
663                 error "(5) Expect 'scanning-phase1', but got '$STATUS'"
664
665         $STOP_LFSCK || error "(6) Fail to stop LFSCK!"
666
667         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
668         [ "$STATUS" == "stopped" ] ||
669                 error "(7) Expect 'stopped', but got '$STATUS'"
670
671         $START_NAMESPACE || error "(8) Fail to start LFSCK for namespace!"
672
673         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
674         [ "$STATUS" == "scanning-phase1" ] ||
675                 error "(9) Expect 'scanning-phase1', but got '$STATUS'"
676
677         #define OBD_FAIL_LFSCK_FATAL2           0x1609
678         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80001609
679         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
680                 mdd.${MDT_DEV}.lfsck_namespace |
681                 awk '/^status/ { print \\\$2 }'" "failed" 6 || {
682                 $SHOW_NAMESPACE
683                 error "(10) unexpected status"
684         }
685
686         #define OBD_FAIL_LFSCK_DELAY1           0x1600
687         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1600
688         $START_NAMESPACE || error "(11) Fail to start LFSCK for namespace!"
689
690         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
691         [ "$STATUS" == "scanning-phase1" ] ||
692                 error "(12) Expect 'scanning-phase1', but got '$STATUS'"
693
694         #define OBD_FAIL_LFSCK_CRASH            0x160a
695         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160a
696         sleep 5
697
698         echo "stop $SINGLEMDS"
699         stop $SINGLEMDS > /dev/null || error "(13) Fail to stop MDS!"
700
701         #define OBD_FAIL_LFSCK_NO_AUTO          0x160b
702         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
703
704         echo "start $SINGLEMDS"
705         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
706                 error "(14) Fail to start MDS!"
707
708         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
709         [ "$STATUS" == "crashed" ] ||
710                 error "(15) Expect 'crashed', but got '$STATUS'"
711
712         #define OBD_FAIL_LFSCK_DELAY2           0x1601
713         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1601
714         $START_NAMESPACE || error "(16) Fail to start LFSCK for namespace!"
715
716         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
717         [ "$STATUS" == "scanning-phase1" ] ||
718                 error "(17) Expect 'scanning-phase1', but got '$STATUS'"
719
720         echo "stop $SINGLEMDS"
721         stop $SINGLEMDS > /dev/null || error "(18) Fail to stop MDS!"
722
723         #define OBD_FAIL_LFSCK_NO_AUTO          0x160b
724         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160b
725
726         echo "start $SINGLEMDS"
727         start $SINGLEMDS $MDT_DEVNAME $MOUNT_OPTS_SCRUB > /dev/null ||
728                 error "(19) Fail to start MDS!"
729
730         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
731         [ "$STATUS" == "paused" ] ||
732                 error "(20) Expect 'paused', but got '$STATUS'"
733
734         #define OBD_FAIL_LFSCK_DELAY3           0x1602
735         do_facet $SINGLEMDS $LCTL set_param fail_val=2 fail_loc=0x1602
736
737         $START_NAMESPACE || error "(21) Fail to start LFSCK for namespace!"
738         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
739                 mdd.${MDT_DEV}.lfsck_namespace |
740                 awk '/^status/ { print \\\$2 }'" "scanning-phase2" 6 || {
741                 $SHOW_NAMESPACE
742                 error "(22) unexpected status"
743         }
744
745         local FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
746         [ "$FLAGS" == "scanned-once,inconsistent" ] ||
747                 error "(23) Expect 'scanned-once,inconsistent',but got '$FLAGS'"
748
749         do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
750         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
751                 mdd.${MDT_DEV}.lfsck_namespace |
752                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
753                 $SHOW_NAMESPACE
754                 error "(24) unexpected status"
755         }
756
757         FLAGS=$($SHOW_NAMESPACE | awk '/^flags/ { print $2 }')
758         [ -z "$FLAGS" ] || error "(25) Expect empty flags, but got '$FLAGS'"
759 }
760 run_test 8 "LFSCK state machine"
761
762 test_9a() {
763         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
764                 skip "Testing on UP system, the speed may be inaccurate."
765                 return 0
766         fi
767
768         lfsck_prep 70 70
769
770         local BASE_SPEED1=100
771         local RUN_TIME1=10
772         $START_NAMESPACE -r -s $BASE_SPEED1 || error "(3) Fail to start LFSCK!"
773
774         sleep $RUN_TIME1
775         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
776         [ "$STATUS" == "scanning-phase1" ] ||
777                 error "(3) Expect 'scanning-phase1', but got '$STATUS'"
778
779         local SPEED=$($SHOW_NAMESPACE |
780                       awk '/^average_speed_phase1/ { print $2 }')
781
782         # There may be time error, normally it should be less than 2 seconds.
783         # We allow another 20% schedule error.
784         local TIME_DIFF=2
785         # MAX_MARGIN = 1.2 = 12 / 10
786         local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
787                            RUN_TIME1 * 12 / 10))
788         [ $SPEED -lt $MAX_SPEED ] ||
789                 error "(4) Got speed $SPEED, expected less than $MAX_SPEED"
790
791         # adjust speed limit
792         local BASE_SPEED2=300
793         local RUN_TIME2=10
794         do_facet $SINGLEMDS \
795                 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
796         sleep $RUN_TIME2
797
798         SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase1/ { print $2 }')
799         # MIN_MARGIN = 0.8 = 8 / 10
800         local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
801                             BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
802                            (RUN_TIME1 + RUN_TIME2) * 8 / 10))
803         [ $SPEED -gt $MIN_SPEED ] ||
804                 error "(5) Got speed $SPEED, expected more than $MIN_SPEED"
805
806         # MAX_MARGIN = 1.2 = 12 / 10
807         MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
808                       BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
809                      (RUN_TIME1 + RUN_TIME2) * 12 / 10))
810         [ $SPEED -lt $MAX_SPEED ] ||
811                 error "(6) Got speed $SPEED, expected less than $MAX_SPEED"
812
813         do_facet $SINGLEMDS \
814                 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
815         sleep 5
816         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
817         [ "$STATUS" == "completed" ] ||
818                 error "(7) Expect 'completed', but got '$STATUS'"
819 }
820 run_test 9a "LFSCK speed control (1)"
821
822 test_9b() {
823         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
824                 skip "Testing on UP system, the speed may be inaccurate."
825                 return 0
826         fi
827
828         lfsck_prep 0 0
829
830         echo "Preparing another 50 * 50 files (with error) at $(date)."
831         #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
832         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
833         createmany -d $DIR/$tdir/d 50
834         createmany -m $DIR/$tdir/f 50
835         for ((i = 0; i < 50; i++)); do
836                 createmany -m $DIR/$tdir/d${i}/f 50 > /dev/null
837         done
838
839         #define OBD_FAIL_LFSCK_NO_DOUBLESCAN    0x160c
840         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x160c
841         $START_NAMESPACE -r || error "(4) Fail to start LFSCK!"
842         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
843                 mdd.${MDT_DEV}.lfsck_namespace |
844                 awk '/^status/ { print \\\$2 }'" "stopped" 10 || {
845                 $SHOW_NAMESPACE
846                 error "(5) unexpected status"
847         }
848
849         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
850         echo "Prepared at $(date)."
851
852         local BASE_SPEED1=50
853         local RUN_TIME1=10
854         $START_NAMESPACE -s $BASE_SPEED1 || error "(6) Fail to start LFSCK!"
855
856         sleep $RUN_TIME1
857         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
858         [ "$STATUS" == "scanning-phase2" ] ||
859                 error "(7) Expect 'scanning-phase2', but got '$STATUS'"
860
861         local SPEED=$($SHOW_NAMESPACE |
862                       awk '/^average_speed_phase2/ { print $2 }')
863         # There may be time error, normally it should be less than 2 seconds.
864         # We allow another 20% schedule error.
865         local TIME_DIFF=2
866         # MAX_MARGIN = 1.2 = 12 / 10
867         local MAX_SPEED=$((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) / \
868                           RUN_TIME1 * 12 / 10))
869         [ $SPEED -lt $MAX_SPEED ] ||
870                 error "(8) Got speed $SPEED, expected less than $MAX_SPEED"
871
872         # adjust speed limit
873         local BASE_SPEED2=150
874         local RUN_TIME2=10
875         do_facet $SINGLEMDS \
876                 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit $BASE_SPEED2
877         sleep $RUN_TIME2
878
879         SPEED=$($SHOW_NAMESPACE | awk '/^average_speed_phase2/ { print $2 }')
880         # MIN_MARGIN = 0.8 = 8 / 10
881         local MIN_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 - TIME_DIFF) + \
882                             BASE_SPEED2 * (RUN_TIME2 - TIME_DIFF)) / \
883                            (RUN_TIME1 + RUN_TIME2) * 8 / 10))
884         [ $SPEED -gt $MIN_SPEED ] ||
885                 error "(9) Got speed $SPEED, expected more than $MIN_SPEED"
886
887         # MAX_MARGIN = 1.2 = 12 / 10
888         MAX_SPEED=$(((BASE_SPEED1 * (RUN_TIME1 + TIME_DIFF) + \
889                       BASE_SPEED2 * (RUN_TIME2 + TIME_DIFF)) / \
890                      (RUN_TIME1 + RUN_TIME2) * 12 / 10))
891         [ $SPEED -lt $MAX_SPEED ] ||
892                 error "(10) Got speed $SPEED, expected less than $MAX_SPEED"
893
894         do_facet $SINGLEMDS \
895                 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
896         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
897                 mdd.${MDT_DEV}.lfsck_namespace |
898                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
899                 $SHOW_NAMESPACE
900                 error "(11) unexpected status"
901         }
902 }
903 run_test 9b "LFSCK speed control (2)"
904
905 test_10()
906 {
907         lfsck_prep 1 1
908
909         echo "Preparing more files with error at $(date)."
910         #define OBD_FAIL_LFSCK_LINKEA_CRASH     0x1603
911         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1603
912
913         for ((i = 0; i < 1000; i = $((i+2)))); do
914                 mkdir -p $DIR/$tdir/d${i}
915                 touch $DIR/$tdir/f${i}
916                 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
917         done
918
919         #define OBD_FAIL_LFSCK_LINKEA_MORE      0x1604
920         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1604
921
922         for ((i = 1; i < 1000; i = $((i+2)))); do
923                 mkdir -p $DIR/$tdir/d${i}
924                 touch $DIR/$tdir/f${i}
925                 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
926         done
927
928         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
929         echo "Prepared at $(date)."
930
931         ln $DIR/$tdir/f200 $DIR/$tdir/d200/dummy
932
933         umount_client $MOUNT
934         mount_client $MOUNT || error "(3) Fail to start client!"
935
936         $START_NAMESPACE -r -s 100 || error "(5) Fail to start LFSCK!"
937
938         sleep 10
939         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
940         [ "$STATUS" == "scanning-phase1" ] ||
941                 error "(6) Expect 'scanning-phase1', but got '$STATUS'"
942
943         ls -ailR $MOUNT > /dev/null || error "(7) Fail to ls!"
944
945         touch $DIR/$tdir/d198/a0 || error "(8) Fail to touch!"
946
947         mkdir $DIR/$tdir/d199/a1 || error "(9) Fail to mkdir!"
948
949         unlink $DIR/$tdir/f200 || error "(10) Fail to unlink!"
950
951         rm -rf $DIR/$tdir/d201 || error "(11) Fail to rmdir!"
952
953         mv $DIR/$tdir/f202 $DIR/$tdir/d203/ || error "(12) Fail to rename!"
954
955         ln $DIR/$tdir/f204 $DIR/$tdir/d205/a3 || error "(13) Fail to hardlink!"
956
957         ln -s $DIR/$tdir/d206 $DIR/$tdir/d207/a4 ||
958                 error "(14) Fail to softlink!"
959
960         STATUS=$($SHOW_NAMESPACE | awk '/^status/ { print $2 }')
961         [ "$STATUS" == "scanning-phase1" ] ||
962                 error "(15) Expect 'scanning-phase1', but got '$STATUS'"
963
964         do_facet $SINGLEMDS \
965                 $LCTL set_param -n mdd.${MDT_DEV}.lfsck_speed_limit 0
966         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
967                 mdd.${MDT_DEV}.lfsck_namespace |
968                 awk '/^status/ { print \\\$2 }'" "completed" 6 || {
969                 $SHOW_NAMESPACE
970                 error "(16) unexpected status"
971         }
972 }
973 run_test 10 "System is available during LFSCK scanning"
974
975 test_20a() {
976         local server_version=$(lustre_version_code $SINGLEMDS)
977
978         [[ $server_version -ge $(version_code 2.5.60) ]] ||
979         [[ $server_version -ge $(version_code 2.5.3) &&
980            $server_version -lt $(version_code 2.5.11) ]] ||
981                 { skip "Need MDS version 2.5.4+ or 2.5.60+"; return; }
982
983         [ $OSTCOUNT -lt 2 ] &&
984                 skip "The test needs at least 2 OSTs" && return
985
986         echo "#####"
987         echo "For old client, even though it cannot access the file with"
988         echo "LOV EA hole, it should not cause the system crash."
989         echo "#####"
990
991         lfsck_prep 0 0
992
993         $LFS mkdir -i 0 $DIR/$tdir/a1
994         if [ $OSTCOUNT -gt 2 ]; then
995                 $LFS setstripe -c 3 -i 0 -s 1M $DIR/$tdir/a1
996                 bcount=513
997         else
998                 $LFS setstripe -c 2 -i 0 -s 1M $DIR/$tdir/a1
999                 bcount=257
1000         fi
1001
1002         # 256 blocks on the stripe0.
1003         # 1 block on the stripe1 for 2 OSTs case.
1004         # 256 blocks on the stripe1 for other cases.
1005         # 1 block on the stripe2 if OSTs > 2
1006         dd if=/dev/zero of=$DIR/$tdir/a1/f0 bs=4096 count=$bcount
1007
1008         local fid0=$($LFS path2fid $DIR/$tdir/a1/f0)
1009
1010         echo ${fid0}
1011         $LFS getstripe $DIR/$tdir/a1/f0
1012
1013         cancel_lru_locks osc
1014
1015         echo "Inject failure..."
1016         echo "To make a LOV EA hole..."
1017         #define OBD_FAIL_MAKE_LOVEA_HOLE        0x1406
1018         do_facet mds1 $LCTL set_param fail_loc=0x1406
1019         chown 1.1 $DIR/$tdir/a1/f0
1020
1021         umount_client $MOUNT
1022         sync
1023         sleep 2
1024         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
1025
1026         mount_client $MOUNT || error "Fail to start client!"
1027
1028         $LFS getstripe $DIR/$tdir/a1/f0
1029         dd if=$DIR/$tdir/a1/f0 of=/dev/null
1030         return 0 # not crash
1031 }
1032 run_test 20a "Don't crash client while access with LOV EA hole"
1033
1034 $LCTL set_param debug=-lfsck > /dev/null || true
1035
1036 # restore MDS/OST size
1037 MDSSIZE=${SAVED_MDSSIZE}
1038 OSTSIZE=${SAVED_OSTSIZE}
1039 OSTCOUNT=${SAVED_OSTCOUNT}
1040
1041 # cleanup the system at last
1042 formatall
1043
1044 complete $SECONDS
1045 exit_status