Whamcloud - gitweb
LU-9494 test: Improve message for skipping tests
[fs/lustre-release.git] / lustre / tests / lfsck-performance.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 ALWAYS_EXCEPT="$LFSCK_PERFORMANCE_EXCEPT"
7 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
14 init_logging
15
16 require_dsh_mds || exit 0
17 require_dsh_ost || exit 0
18
19 [ "$SLOW" = "no" ] &&
20         skip "skip lfsck performance test under non-SLOW mode" && exit 0
21
22 NTHREADS=${NTHREADS:-0}
23 UNIT=${UNIT:-8192}
24 MINCOUNT=${MINCOUNT:-4096}
25 MAXCOUNT=${MAXCOUNT:-8192}
26 MINCOUNT_REPAIR=${MINCOUNT_REPAIR:-4096}
27 MAXCOUNT_REPAIR=${MAXCOUNT_REPAIR:-8192}
28 BASE_COUNT=${BASE_COUNT:-8192}
29 FACTOR=${FACTOR:-2}
30 INCFACTOR=${INCFACTOR:-25} #percent
31 MINSUBDIR=${MINSUBDIR:-1}
32 MAXSUBDIR=${MAXSUBDIR:-2}
33 TOTSUBDIR=${TOTSUBDIR:-2}
34 WTIME=${WTIME:-86400}
35
36 RCMD="do_facet ${SINGLEMDS}"
37 RLCTL="${RCMD} ${LCTL}"
38 MDT_DEV="${FSNAME}-MDT0000"
39 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
40 START_NAMESPACE="${RLCTL} lfsck_start -M ${MDT_DEV} -t namespace"
41 STOP_LFSCK="${RLCTL} lfsck_stop -M ${MDT_DEV} -A"
42 SHOW_NAMESPACE="${RLCTL} get_param -n mdd.${MDT_DEV}.lfsck_namespace"
43 MNTOPTS_NOSCRUB="-o user_xattr,noscrub"
44 remote_mds && ECHOCMD=${RCMD} || ECHOCMD="eval"
45
46 if [ ${NTHREADS} -eq 0 ]; then
47         CPUCORE=$(${RCMD} cat /proc/cpuinfo | grep "processor.*:" | wc -l)
48         NTHREADS=$((CPUCORE * 2))
49 fi
50
51 lfsck_attach() {
52         ${RCMD} "modprobe obdecho"
53
54         ${ECHOCMD} "${LCTL} <<-EOF
55                 attach echo_client lfsck-MDT0000 lfsck-MDT0000_UUID
56                 setup ${MDT_DEV} mdd
57         EOF"
58 }
59
60 lfsck_detach() {
61         ${ECHOCMD} "${LCTL} <<-EOF
62                 device lfsck-MDT0000
63                 cleanup
64                 detach
65         EOF"
66 }
67
68 lfsck_create() {
69         local echodev=$(${RLCTL} dl | grep echo_client|awk '{print $1}')
70         local j
71
72         ${ECHOCMD} "${LCTL} <<-EOF
73                 cfg_device ${echodev}
74                 test_mkdir ${tdir}
75         EOF"
76
77         for ((j = 1; j < ${threads}; j++)); do
78                 ${ECHOCMD} "${LCTL} <<-EOF
79                         cfg_device ${echodev}
80                         test_mkdir ${tdir}${j}
81                 EOF"
82         done
83
84         ${ECHOCMD} "${LCTL} <<-EOF
85                 cfg_device ${echodev}
86                 --threads ${threads} 0 ${echodev} test_create \
87                 -d ${tdir} -D ${threads} -b ${lbase} -c 0 -n ${usize}
88         EOF"
89 }
90
91 lfsck_cleanup() {
92         do_rpc_nodes $(facet_active_host $SINGLEMDS) unload_modules
93         formatall
94 }
95
96 lfsck_create_nfiles() {
97         local total=$1
98         local lbase=$2
99         local threads=$3
100         local linkea=$4
101         local ldir="/test-${lbase}"
102         local cycle=0
103         local count=${UNIT}
104
105         while true; do
106                 [ ${count} -eq 0 -o  ${count} -gt ${total} ] && count=${total}
107                 local usize=$((count / NTHREADS))
108                 [ ${usize} -eq 0 ] && break
109                 local tdir=${ldir}-${cycle}-
110
111                 echo "[cycle: ${cycle}] [threads: ${threads}]"\
112                      "[files: ${count}] [basedir: ${tdir}]"
113                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB ||
114                         error "Fail to start MDS!"
115                 #define OBD_FAIL_FID_IGIF       0x1504
116                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x1504
117
118                 lfsck_attach
119                 lfsck_create
120                 lfsck_detach
121
122                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x0
123                 stop ${SINGLEMDS} || error "Fail to stop MDS!"
124
125                 total=$((total - usize * NTHREADS))
126                 [ ${total} -eq 0 ] && break
127                 lbase=$((lbase + usize))
128                 cycle=$((cycle + 1))
129         done
130 }
131
132 build_test_filter
133
134 test_0() {
135         local BCOUNT=0
136         local i
137
138         stopall
139         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
140         format_mdt $(facet_number $SINGLEMDS)
141
142         for ((i = $MINCOUNT; i <= $MAXCOUNT; i = $((i * FACTOR)))); do
143                 local nfiles=$((i - BCOUNT))
144
145                 echo "+++ start to create for ${i} files set at: $(date) +++"
146                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
147                         error "Fail to create files!"
148                 echo "+++ end to create for ${i} files set at: $(date) +++"
149
150                 BCOUNT=${i}
151                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
152                         error "Fail to start MDS!"
153
154                 echo "start lfsck_namespace for ${i} files set at: $(date)"
155                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
156
157                 while true; do
158                         local STATUS=$($SHOW_NAMESPACE |
159                                         awk '/^status/ { print $2 }')
160                         [ "$STATUS" == "completed" ] && break
161                         sleep 3 # check status every 3 seconds
162                 done
163
164                 echo "end lfsck_namespace for ${i} files set at: $(date)"
165                 SPEED=$($SHOW_NAMESPACE |
166                         awk '/^average_speed_phase1/ { print $2 }')
167                 echo "lfsck_namespace speed is ${SPEED}/sec"
168                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
169         done
170 }
171 run_test 0 "lfsck namespace performance (routine case) without load"
172
173 test_1() {
174         [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
175                 skip "not implemented for ZFS" && return
176
177         local BCOUNT=0
178         local i
179
180         stopall
181         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
182         format_mdt $(facet_number $SINGLEMDS)
183
184         for ((i = $MINCOUNT_REPAIR; i <= $MAXCOUNT_REPAIR;
185               i = $((i * FACTOR)))); do
186                 local nfiles=$((i - BCOUNT))
187
188                 echo "+++ start to create for ${i} files set at: $(date) +++"
189                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
190                         error "Fail to create files!"
191                 echo "+++ end to create for ${i} files set at: $(date) +++"
192
193                 BCOUNT=${i}
194                 local stime=$(date +%s)
195                 echo "backup/restore ${i} files start at: $(date)"
196                 mds_backup_restore $SINGLEMDS || error "Fail to backup/restore!"
197                 echo "backup/restore ${i} files end at: $(date)"
198                 local etime=$(date +%s)
199                 local delta=$((etime - stime))
200                 [ $delta -gt 0 ] || delta=1
201                 echo "backup/restore ${i} files used ${delta} seconds"
202                 echo "backup/restore speed is $((i / delta))/sec"
203
204                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
205                         error "Fail to start MDS!"
206
207                 echo "start lfsck_namespace for ${i} files set at: $(date)"
208                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
209
210                 while true; do
211                         local STATUS=$($SHOW_NAMESPACE |
212                                         awk '/^status/ { print $2 }')
213                         [ "$STATUS" == "completed" ] && break
214                         sleep 3 # check status every 3 seconds
215                 done
216
217                 echo "end lfsck_namespace for ${i} files set at: $(date)"
218                 local SPEED=$($SHOW_NAMESPACE |
219                               awk '/^average_speed_phase1/ { print $2 }')
220                 echo "lfsck_namespace speed is ${SPEED}/sec"
221                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
222         done
223 }
224 run_test 1 "lfsck namespace performance (backup/restore) without load"
225
226 test_2() {
227         local i
228
229         for ((i = $MINCOUNT_REPAIR; i <= $MAXCOUNT_REPAIR;
230               i = $((i * FACTOR)))); do
231                 stopall
232                 do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
233                 format_mdt $(facet_number $SINGLEMDS)
234
235                 echo "+++ start to create for ${i} files set at: $(date) +++"
236                 lfsck_create_nfiles ${i} 0 ${NTHREADS} 1 ||
237                         error "Fail to create files!"
238                 echo "+++ end to create for ${i} files set at: $(date) +++"
239
240                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
241                         error "Fail to start MDS!"
242
243                 echo "start lfsck_namespace for ${i} files set at: $(date)"
244                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
245
246                 while true; do
247                         local STATUS=$($SHOW_NAMESPACE |
248                                         awk '/^status/ { print $2 }')
249                         [ "$STATUS" == "completed" ] && break
250                         sleep 3 # check status every 3 seconds
251                 done
252
253                 echo "end lfsck_namespace for ${i} files set at: $(date)"
254                 local SPEED=$($SHOW_NAMESPACE |
255                               awk '/^average_speed_phase1/ { print $2 }')
256                 echo "lfsck_namespace speed is ${SPEED}/sec"
257                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
258         done
259 }
260 run_test 2 "lfsck namespace performance (upgrade from 1.8) without load"
261
262 test_3() {
263         [ $INCFACTOR -gt 25 ] && INCFACTOR=25
264
265         local inc_count=$((BASE_COUNT * INCFACTOR / 100))
266         local BCOUNT=0
267         local i
268
269         stopall
270         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
271         format_mdt $(facet_number $SINGLEMDS)
272
273         for ((i = $inc_count; i <= $BASE_COUNT; i = $((i + inc_count)))); do
274                 local nfiles=$((i - BCOUNT))
275
276                 echo "+++ start to create for ${i} files set at: $(date) +++"
277                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
278                         error "Fail to create files!"
279                 echo "+++ end to create for ${i} files set at: $(date) +++"
280                 BCOUNT=${i}
281         done
282
283         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
284                 error "Fail to start MDS!"
285
286         echo "start lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
287         $START_NAMESPACE || error "Fail to start lfsck_namespace!"
288
289         while true; do
290                 local STATUS=$($SHOW_NAMESPACE |
291                                 awk '/^status/ { print $2 }')
292                 [ "$STATUS" == "completed" ] && break
293                 sleep 3 # check status every 3 seconds
294         done
295
296         echo "end lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
297         local FULL_SPEED=$($SHOW_NAMESPACE |
298                       awk '/^average_speed_phase1/ { print $2 }')
299         echo "lfsck_namespace full_speed is ${FULL_SPEED}/sec"
300         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
301         local inc_speed=$((FULL_SPEED * INCFACTOR / 100))
302         local j
303
304         for ((j = $inc_speed; j < $FULL_SPEED; j = $((j + inc_speed)))); do
305                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
306                         error "Fail to start MDS!"
307
308                 $STOP_LFSCK > /dev/null 2>&1
309                 echo "start lfsck_namespace with speed ${j} at: $(date)"
310                 $START_NAMESPACE --reset -s ${j} ||
311                         error "Fail to start lfsck_namespace with speed ${j}!"
312                 # lfsck_namespace will be paused when MDS stop,
313                 # and will be restarted automatically when mount up again.
314                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
315
316                 local nfiles=$(((i - BCOUNT) / 2))
317
318                 echo "+++ start to create for ${i} files set at: $(date) +++"
319                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
320                         error "Fail to create files!"
321                 echo "+++ end to create for ${i} files set at: $(date) +++"
322                 BCOUNT=${i}
323                 i=$((i + inc_count))
324         done
325
326         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
327                 error "Fail to start MDS!"
328
329         $STOP_LFSCK /dev/null 2>&1
330         echo "start lfsck_namespace with full speed at: $(date)"
331         $START_NAMESPACE --reset -s 0 ||
332                 error "Fail to start lfsck_namespace with full speed!"
333         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
334
335         local nfiles=$(((i - BCOUNT) / 2))
336
337         echo "+++ start to create for ${i} files set at: $(date) +++"
338         lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
339                 error "Fail to create files!"
340         echo "+++ end to create for ${i} files set at: $(date) +++"
341 }
342 run_test 3 "lfsck namespace impact on create performance"
343
344 show_layout() {
345         local idx=$1
346
347         do_facet mds${idx} \
348                 "$LCTL get_param -n mdd.$(facet_svc mds${idx}).lfsck_layout"
349 }
350
351 layout_test_one() {
352         echo "***** Start layout LFSCK on all devices at: $(date) *****"
353         $RLCTL lfsck_start -M ${MDT_DEV} -t layout -A -r || return 21
354
355         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
356                 mdd.${MDT_DEV}.lfsck_layout |
357                 awk '/^status/ { print \\\$2 }'" "completed" $WTIME || {
358                 show_layout 1
359                 return 22
360         }
361         echo "***** End layout LFSCK on all devices at: $(date) *****"
362
363         for n in $(seq $MDSCOUNT); do
364                 show_layout ${n}
365
366                 local SPEED=$(show_layout ${n} |
367                               awk '/^average_speed_phase1/ { print $2 }')
368                 echo
369                 echo "lfsck_layout speed on MDS_${n} is $SPEED objs/sec"
370                 echo
371         done
372 }
373
374 layout_gen_one() {
375         local idx1=$1
376         local idx2=$2
377         local mntpt="/mnt/lustre_lfsck_${idx1}_${idx2}"
378         local basedir="$mntpt/$tdir/$idx1/$idx2"
379
380         mkdir -p $mntpt || {
381                 error_noexit "(11) Fail to mkdir $mntpt"
382                 return 11
383         }
384
385         mount_client $mntpt || {
386                 error_noexit "(12) Fail to mount $mntpt"
387                 return 12
388         }
389
390         mkdir $basedir || {
391                 umount_client $mntpt
392                 error_noexit "(13) Fail to mkdir $basedir"
393                 return 13
394         }
395
396         echo "&&&&& Start create $UNIT files under $basedir at: $(date) &&&&&"
397         createmany -o ${basedir}/f $UNIT || {
398                 umount_client $mntpt
399                 error_noexit "(14) Fail to gen $UNIT files under $basedir"
400                 return 14
401         }
402         echo "&&&&& End create $UNIT files under $basedir at: $(date) &&&&&"
403
404         umount_client $mntpt
405 }
406
407 layout_gen_set() {
408         local cnt=$1
409
410         echo "##### Start generate test set for subdirs=$cnt at: $(date) #####"
411         for ((k = 0; k < $MDSCOUNT; k++)); do
412                 $LFS mkdir -i ${k} $LFSCKDIR/${k} || return 10
413
414                 for ((l = 1; l <= $cnt; l++)); do
415                         layout_gen_one ${k} ${l} &
416                 done
417         done
418
419         wait
420         echo "##### End generate test set for subdirs=$cnt at: $(date) #####"
421 }
422
423 t4_test() {
424         local saved_mdscount=$MDSCOUNT
425         local saved_ostcount=$OSTCOUNT
426
427         echo "stopall"
428         stopall > /dev/null || error "(1) Fail to stopall"
429
430         LFSCKDIR="$DIR/$tdir"
431         MDSCOUNT=1
432         for ((i = 1; i <= $saved_ostcount; i = $((i * 2)))); do
433                 OSTCOUNT=${i}
434
435                 echo "+++++ Start cycle ostcount=$OSTCOUNT at: $(date) +++++"
436                 echo
437
438                 for ((j = $MINSUBDIR; j <= $MAXSUBDIR; j = $((j * FACTOR)))); do
439                         echo "formatall"
440                         formatall > /dev/null ||
441                                 error "(2) Fail to formatall, subdirs=${j}"
442
443                         echo "setupall"
444                         setupall > /dev/null ||
445                                 error "(3) Fail to setupall, subdirs=${j}"
446
447                         mkdir $LFSCKDIR ||
448                                 error "(4) mkdir $LFSCKDIR, subdirs=${j}"
449
450                         $LFS setstripe -c ${OSTCOUNT} -i 0 $LFSCKDIR ||
451                                 error "(5) setstripe on $LFSCKDIR, subdirs=${j}"
452
453                         local RC=0
454                         layout_gen_set ${j} || RC=$?
455                         [ $RC -eq 0 ] ||
456                                 error "(6) generate set $RC, subdirs=${j}"
457
458                         RC=0
459                         layout_test_one || RC=$?
460                         [ $RC -eq 0 ] ||
461                                 error "(7) LFSCK failed with $RC, subdirs=${j}"
462                 done
463
464                 echo "stopall"
465                 stopall > /dev/null || error "(8) Fail to stopall, subdirs=${j}"
466
467                 echo
468                 echo "----- Stop cycle ostcount=$OSTCOUNT at: $(date) -----"
469         done
470
471         MDSCOUNT=$saved_mdscount
472         OSTCOUNT=$saved_ostcount
473 }
474
475 test_4a() {
476         t4_test
477 }
478 run_test 4a "Single MDS lfsck layout performance (routine case) without load"
479
480 test_4b() {
481         echo "Inject failure stub to simulate dangling reference"
482         #define OBD_FAIL_LFSCK_DANGLING 0x1610
483         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0x1610
484
485         t4_test
486 }
487 run_test 4b "Single MDS lfsck layout performance (repairing case) without load"
488
489 t5_test() {
490         local saved_mdscount=$MDSCOUNT
491
492         echo "stopall"
493         stopall > /dev/null || error "(1) Fail to stopall"
494
495         LFSCKDIR="$DIR/$tdir"
496         for ((i = 1; i <= $saved_mdscount; i++)); do
497                 MDSCOUNT=${i}
498
499                 echo "+++++ Start cycle mdscount=$MDSCOUNT at: $(date) +++++"
500                 echo
501
502                 for ((j = $MINSUBDIR; j <= $MAXSUBDIR; j = $((j * FACTOR)))); do
503                         echo "formatall"
504                         formatall > /dev/null ||
505                                 error "(2) Fail to formatall, subdirs=${j}"
506
507                         echo "setupall"
508                         setupall > /dev/null ||
509                                 error "(3) Fail to setupall, subdirs=${j}"
510
511                         mkdir $LFSCKDIR ||
512                                 error "(4) mkdir $LFSCKDIR, subdirs=${j}"
513
514                         $LFS setstripe -c ${OSTCOUNT} -i 0 $LFSCKDIR ||
515                                 error "(5) setstripe on $LFSCKDIR, subdirs=${j}"
516
517                         local RC=0
518                         layout_gen_set ${j} || RC=$?
519                         [ $RC -eq 0 ] ||
520                                 error "(6) generate set $RC, subdirs=${j}"
521
522                         RC=0
523                         layout_test_one || RC=$?
524                         [ $RC -eq 0 ] ||
525                                 error "(7) LFSCK failed with $RC, subdirs=${j}"
526                 done
527
528                 echo "stopall"
529                 stopall > /dev/null || error "(8) Fail to stopall"
530
531                 echo
532                 echo "----- Stop cycle mdscount=$MDSCOUNT at: $(date) -----"
533         done
534
535         MDSCOUNT=$saved_mdscount
536 }
537
538 test_5a() {
539         t5_test
540 }
541 run_test 5a "lfsck layout performance (routine case) without load for DNE"
542
543 test_5b() {
544         echo "Inject failure stub to simulate dangling reference"
545         #define OBD_FAIL_LFSCK_DANGLING 0x1610
546         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0x1610
547
548         t5_test
549 }
550 run_test 5b "lfsck layout performance (repairing case) without load for DNE"
551
552 lfsck_fast_create() {
553         local total=$1
554         local lbase=$2
555         local threads=$3
556         local ldir="/test-${lbase}"
557         local cycle=0
558         local count=$UNIT
559
560         while true; do
561                 [ $count -eq 0 -o  $count -gt ${total} ] && count=$total
562                 local usize=$((count / NTHREADS))
563                 [ ${usize} -eq 0 ] && break
564                 local tdir=${ldir}-${cycle}-
565
566                 echo "[cycle: $cycle] [threads: $threads]"\
567                      "[files: $count] [basedir: $tdir]"
568
569                 lfsck_create
570
571                 total=$((total - usize * NTHREADS))
572                 [ $total -eq 0 ] && break
573                 lbase=$((lbase + usize))
574                 cycle=$((cycle + 1))
575         done
576 }
577
578 lfsck_detach_error() {
579         lfsck_detach
580         error "$@"
581 }
582
583 test_6() {
584         [ $INCFACTOR -gt 25 ] && INCFACTOR=25
585
586         echo "stopall"
587         stopall > /dev/null || error "(1) Fail to stopall"
588
589         local saved_mdscount=$MDSCOUNT
590
591         LFSCKDIR="$DIR/$tdir"
592         MDSCOUNT=1
593         echo "formatall"
594         formatall > /dev/null || error "(2) Fail to formatall"
595
596         echo "setupall"
597         setupall > /dev/null || error "(3) Fail to setupall"
598
599         mkdir $LFSCKDIR || error "(4) Fail to mkdir $LFSCKDIR"
600
601         $LFS setstripe -c ${OSTCOUNT} -i 0 $LFSCKDIR ||
602                 error "(5) Fail to setstripe on $LFSCKDIR"
603
604         local RC=0
605         layout_gen_set $TOTSUBDIR || RC=$?
606         [ $RC -eq 0 ] ||
607                 error "(6) Fail to generate set $RC, subdirs=$TOTSUBDIR"
608
609         echo
610         echo "***** Start layout LFSCK on single MDS at: $(date) *****"
611         $RLCTL lfsck_start -M ${MDT_DEV} -t layout -r ||
612                 error "(7) Fail to start layout LFSCK"
613
614         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
615                 mdd.${MDT_DEV}.lfsck_layout |
616                 awk '/^status/ { print \\\$2 }'" "completed" $WTIME || {
617                 show_layout 1
618                 error "(8) layout LFSCK cannot finished in time"
619         }
620         echo "***** End layout LFSCK on single MDS at: $(date) *****"
621
622         local SPEED=$(show_layout 1 |
623                       awk '/^average_speed_phase1/ { print $2 }')
624         echo "lfsck_layout full_speed is $SPEED objs/sec"
625
626         local inc_count=$((BASE_COUNT * INCFACTOR / 100))
627         local nfiles=$((inc_count / 2))
628
629         lfsck_attach
630         for ((m = 0, n = $INCFACTOR; n < 100;
631               m = $((m + inc_count)), n = $((n + INCFACTOR)))); do
632                 local sl=$((SPEED * n / 100))
633
634                 $STOP_LFSCK > /dev/null 2>&1
635                 echo
636                 echo "start lfsck_layout with speed ${sl} at: $(date)"
637                 $RLCTL lfsck_start -M ${MDT_DEV} -t layout -r -s ${sl} ||
638                         lfsck_detach_error \
639                         "(9) Fail to start lfsck_layout with speed ${sl}"
640
641                 echo "&&&&& Start create files set from ${m} at: $(date) &&&&&"
642                 lfsck_fast_create $nfiles ${m} $NTHREADS ||
643                         lfsck_detach_error "(10) Fail to create files"
644                 echo "&&&&& End create files set from ${m} at: $(date) &&&&&"
645         done
646
647         $STOP_LFSCK > /dev/null 2>&1
648         echo
649         echo "start lfsck_layout with full speed at: $(date)"
650         $RLCTL lfsck_start -M ${MDT_DEV} -t layout -r -s 0 ||
651                 lfsck_detach_error \
652                 "(11) Fail to start lfsck_layout with full speed"
653
654         echo "&&&&& start to create files set from ${m} at: $(date) &&&&&"
655         lfsck_fast_create $nfiles ${m} $NTHREADS ||
656                 lfsck_detach_error "(12) Fail to create files"
657         echo "&&&&& end to create files set from ${m} at: $(date) &&&&&"
658
659         m=$((m + inc_count))
660         $STOP_LFSCK > /dev/null 2>&1
661         echo
662         echo "create without lfsck_layout run back-ground"
663         echo "&&&&& start to create files set from ${m} at: $(date) &&&&&"
664         lfsck_fast_create $nfiles ${m} $NTHREADS ||
665                 lfsck_detach_error "(13) Fail to create files"
666         echo "&&&&& end to create files set from ${m} at: $(date) &&&&&"
667
668         lfsck_detach
669         echo
670         echo "stopall"
671         stopall > /dev/null || error "(14) Fail to stopall"
672
673         MDSCOUNT=$saved_mdscount
674 }
675 run_test 6 "lfsck layout impact on create performance"
676
677 show_namespace() {
678         local idx=$1
679
680         do_facet mds${idx} \
681                 "$LCTL get_param -n mdd.$(facet_svc mds${idx}).lfsck_namespace"
682 }
683
684 namespace_test_one() {
685         echo "***** Start namespace LFSCK on all devices at: $(date) *****"
686         $RLCTL lfsck_start -M ${MDT_DEV} -t namespace -A -r || return 21
687
688         for n in $(seq $MDSCOUNT); do
689                 wait_update_facet mds${n} "$LCTL get_param -n \
690                         mdd.$(facet_svc mds${n}).lfsck_namespace |
691                         awk '/^status/ { print \\\$2 }'" "completed" $WTIME || {
692                         show_namespace ${n}
693                         return 22
694                 }
695         done
696         echo "***** End namespace LFSCK on all devices at: $(date) *****"
697
698         for n in $(seq $MDSCOUNT); do
699                 show_namespace ${n}
700
701                 local SPEED=$(show_namespace ${n} |
702                               awk '/^average_speed_total/ { print $2 }')
703                 echo
704                 echo "lfsck_namespace speed on MDS_${n} is $SPEED objs/sec"
705                 echo
706         done
707 }
708
709 namespace_gen_one() {
710         local idx1=$1
711         local idx2=$2
712         local idx3=$(((idx1 + 1) % MDSCOUNT))
713         local base_mntpt="/mnt/lustre_lfsck_${idx1}"
714         local show_dir="$LFSCKDIR/${idx1}/${idx2}"
715         local work_dir="${base_mntpt}_0/$tdir/${idx1}/${idx2}"
716
717         mkdir $show_dir || return 20
718
719         local count=$((UNIT * 78 / 100)) # 78% regular files
720         local sub_count=$((count / NTHREADS))
721         echo "Creating $count regular files under $show_dir at: $(date)"
722         for ((m = 0; m < $NTHREADS; m++)); do
723                 local sub_dir="${base_mntpt}_${m}/$tdir/${idx1}/${idx2}"
724
725                 createmany -o ${sub_dir}/f_${m}_ $sub_count > /dev/null &
726         done
727
728         wait || {
729                 error_noexit "(21) Fail to gen regular files under $show_dir"
730                 return 21
731         }
732
733         count=$((UNIT * 3 / 100)) # 3% local sub-dirs
734         echo "Creating $count local sub-dirs under $show_dir at: $(date)"
735         createmany -d $work_dir/d_l_ $count > /dev/null || {
736                 error_noexit "(22) Fail to gen local sub-dir under $show_dir"
737                 return 22
738         }
739
740         # 3% * 5 = 15% regular files under local sub-dirs
741         echo "Creating 5 regular files under each local sub-dir at: $(date)"
742         for ((m = 0; m < $count; m++)); do
743                 createmany -o $work_dir/d_l_${m}/f_l_ 5 > /dev/null || {
744                         error_noexit \
745                         "(23) Fail to gen regular under $work_dir/d_l_${m}"
746                         return 23
747                 }
748         done
749
750         count=$((UNIT * 4 / 1000)) # 0.4% multiple hard-links
751         echo "Creating $count multiple hard-links under $show_dir at: $(date)"
752         for ((m = 0; m < $count; m++)); do
753                 ln $work_dir/f_0_${m} $work_dir/f_m_${m} || {
754                         error_noexit \
755                         "(24) Fail to hardlink to $work_dir/f_0_${m}"
756                         return 24
757                 }
758         done
759
760         count=$((UNIT * 3 / 1000)) # 0.3% remote sub-dirs
761         echo "Creating $count remote sub-dirs under $show_dir, and 4 regular" \
762                 "files under each remote sub-dir at: $(date)"
763         for ((m = 0; m < $count; m++)); do
764                 $LFS mkdir -i ${idx3} $work_dir/d_r_${m} || {
765                         error_noexit \
766                         "(25) Fail to remote mkdir $work_dir/d_r_${m}"
767                         return 25
768                 }
769
770                 # 0.3% * 4 = 1.2% regular files under remote sub-dirs
771                 createmany -o $work_dir/d_r_${m}/f_r_ 4 > /dev/null || {
772                         error_noexit \
773                         "(26) Fail to gen regular under $work_dir/d_r_${m}"
774                         return 26
775                 }
776         done
777
778         # 0.3% 2-striped sub-dirs + 0.6% shards of the 2-striped sub-dirs
779         count=$((UNIT * 3 / 1000))
780         echo "Creating $count 2-striped sub-dirs under $show_dir," \
781                 "and 4 regular files under each striped sub-dir at: $(date)"
782         for ((m = 0; m < $count; m++)); do
783                 $LFS setdirstripe -i ${idx1} -c 2 -t all_char \
784                         $work_dir/d_s_${m} || {
785                         error_noexit \
786                         "(27) Fail to make striped-dir $work_dir/d_s_${m}"
787                         return 27
788                 }
789
790                 # 0.3% * 4 = 1.2% regular files under striped sub-dirs
791                 createmany -o $work_dir/d_s_${m}/f_s_ 4 > /dev/null || {
792                         error_noexit \
793                         "(28) Fail to gen regular under $work_dir/d_s_${m}"
794                         return 28
795                 }
796         done
797 }
798
799 namespace_gen_mdt() {
800         local mdt_idx=$1
801         local dir_cnt=$2
802         local base_mntpt="/mnt/lustre_lfsck_${mdt_idx}"
803
804         $LFS mkdir -i ${mdt_idx} $LFSCKDIR/${mdt_idx} || return 10
805
806         for ((m = 0; m < $NTHREADS; m++)); do
807                 local mntpt="${base_mntpt}_${m}"
808
809                 mkdir -p $mntpt || {
810                         umount ${base_mntpt}_*
811                         error_noexit "(11) Fail to mkdir $mntpt"
812                         return 11
813                 }
814
815                 mount_client $mntpt || {
816                         umount ${base_mntpt}_*
817                         error_noexit "(12) Fail to mount $mntpt"
818                         return 12
819                 }
820         done
821
822         for ((l = 0; l < $dir_cnt; l++)); do
823                 namespace_gen_one ${mdt_idx} ${l}
824         done
825
826         umount ${base_mntpt}_*
827 }
828
829 namespace_gen_set() {
830
831         local cnt=$1
832
833         echo "##### Start generate test set for subdirs=$cnt at: $(date) #####"
834         for ((k = 0; k < $MDSCOUNT; k++)); do
835                 namespace_gen_mdt ${k} ${cnt} &
836         done
837         wait
838         echo "##### End generate test set for subdirs=$cnt at: $(date) #####"
839 }
840
841 t7_test() {
842         local local_loc=$1
843         local saved_mdscount=$MDSCOUNT
844
845         [ $MDSCOUNT -le 8 ] ||
846                 error "Too much MDT, test data set on each MDT may be unbalance"
847
848         echo "stopall"
849         stopall > /dev/null || error "(1) Fail to stopall"
850
851         LFSCKDIR="$DIR/$tdir"
852         for ((i = 2; i <= $saved_mdscount; i = $((i + 2)))); do
853                 MDSCOUNT=${i}
854
855                 echo "+++++ Start cycle mdscount=$MDSCOUNT at: $(date) +++++"
856                 echo
857
858                 for ((j = $MINSUBDIR; j <= $MAXSUBDIR;
859                       j = $((j + MINSUBDIR)))); do
860                         echo "formatall"
861                         formatall > /dev/null ||
862                                 error "(2) Fail to formatall, subdirs=${j}"
863
864                         echo "setupall"
865                         setupall > /dev/null ||
866                                 error "(3) Fail to setupall, subdirs=${j}"
867
868                         mkdir $LFSCKDIR ||
869                                 error "(4) mkdir $LFSCKDIR, subdirs=${j}"
870
871                         $LFS setstripe -c 1 -i -1 $LFSCKDIR ||
872                                 error "(5) Fail to setstripe on $LFSCKDIR"
873
874                         do_nodes $(comma_list $(mdts_nodes)) \
875                                 $LCTL set_param fail_loc=$local_loc
876
877                         local RC=0
878                         namespace_gen_set ${j} || RC=$?
879                         [ $RC -eq 0 ] ||
880                                 error "(6) generate set $RC, subdirs=${j}"
881
882                         RC=0
883                         namespace_test_one || RC=$?
884                         [ $RC -eq 0 ] ||
885                                 error "(7) LFSCK failed with $RC, subdirs=${j}"
886
887                         do_nodes $(comma_list $(mdts_nodes)) \
888                                 $LCTL set_param fail_loc=0
889                 done
890
891                 echo "stopall"
892                 stopall > /dev/null || error "(8) Fail to stopall"
893
894                 echo
895                 echo "----- Stop cycle mdscount=$MDSCOUNT at: $(date) -----"
896         done
897
898         MDSCOUNT=$saved_mdscount
899 }
900
901 test_7a() {
902         t7_test 0
903 }
904 run_test 7a "namespace LFSCK performance (routine check) without load for DNE"
905
906 test_7b() {
907         echo "Inject failure stub to simulate the case of lost linkEA"
908         #define OBD_FAIL_LFSCK_NO_LINKEA        0x161d
909         t7_test 0x161d
910 }
911 run_test 7b "namespace LFSCK performance (repairing lost linkEA) for DNE"
912
913 test_7c() {
914         echo "Inject failure stub to simulate the case of bad FID-in-dirent"
915         #define OBD_FAIL_FID_INDIR      0x1501
916         t7_test 0x1501
917 }
918 run_test 7c "namespace LFSCK performance (repairing bad FID-in-dirent) for DNE"
919
920 test_8() {
921         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
922
923         [ $INCFACTOR -gt 25 ] && INCFACTOR=25
924
925         echo "stopall"
926         stopall > /dev/null || error "(1) Fail to stopall"
927
928         local saved_mdscount=$MDSCOUNT
929
930         LFSCKDIR="$DIR/$tdir"
931         MDSCOUNT=2
932         echo "formatall"
933         formatall > /dev/null || error "(2) Fail to formatall"
934
935         echo "setupall"
936         setupall > /dev/null || error "(3) Fail to setupall"
937
938         mkdir $LFSCKDIR || error "(4) Fail to mkdir $LFSCKDIR"
939
940         $LFS setstripe -c 1 -i 0 $LFSCKDIR ||
941                 error "(5) Fail to setstripe on $LFSCKDIR"
942
943         local RC=0
944         namespace_gen_set $TOTSUBDIR || RC=$?
945         [ $RC -eq 0 ] ||
946                 error "(6) Fail to generate set $RC, subdirs=$TOTSUBDIR"
947
948         echo
949         echo "***** Start namespace LFSCK at: $(date) *****"
950         $RLCTL lfsck_start -M ${MDT_DEV} -t namespace -A -r ||
951                 error "(7) Fail to start namespace LFSCK"
952
953         for n in $(seq $MDSCOUNT); do
954                 wait_update_facet mds${n} "$LCTL get_param -n \
955                         mdd.$(facet_svc mds${n}).lfsck_namespace |
956                         awk '/^status/ { print \\\$2 }'" "completed" $WTIME || {
957                         show_namespace ${n}
958                         error "(8) namespace LFSCK cannot finished in time"
959                 }
960         done
961         echo "***** End namespace LFSCK at: $(date) *****"
962
963         local SPEED=$(show_namespace 1 |
964                       awk '/^average_speed_phase1/ { print $2 }')
965         echo "lfsck_namespace full_speed is $SPEED objs/sec"
966         echo
967
968         local inc_count=$((BASE_COUNT * INCFACTOR / 100))
969         local nfiles=$((inc_count / 2))
970         local m=0
971
972         lfsck_attach
973
974         local stime=$(date +%s)
975         lfsck_fast_create $nfiles ${m} $NTHREADS ||
976                 lfsck_detach_error "(9) Fail to create files"
977         local etime=$(date +%s)
978         echo "created $nfiles without lfsck_namespace run back-ground used" \
979                 "$((etime - stime)) seconds"
980         echo
981
982         for ((m = nfiles, n = $INCFACTOR; n < 100;
983               m = $((m + inc_count)), n = $((n + INCFACTOR)))); do
984                 local sl=$((SPEED * n / 100))
985
986                 $STOP_LFSCK > /dev/null 2>&1
987                 echo "start lfsck_namespace with speed ${sl} at: $(date)"
988                 $RLCTL lfsck_start -M ${MDT_DEV} -t namespace -A -r -s ${sl} ||
989                         lfsck_detach_error \
990                         "(10) Fail to start lfsck_namespace with speed ${sl}"
991
992                 stime=$(date +%s)
993                 lfsck_fast_create $nfiles ${m} $NTHREADS ||
994                         lfsck_detach_error "(11) Fail to create files"
995                 etime=$(date +%s)
996                 echo "created $nfiles with namespace LFSCK run with the" \
997                         "speed limit of ${n}% of full speed used" \
998                         "$((etime - stime)) seconds"
999                 echo
1000         done
1001
1002         $STOP_LFSCK > /dev/null 2>&1
1003         echo "start lfsck_namespace with full speed at: $(date)"
1004         $RLCTL lfsck_start -M ${MDT_DEV} -t namespace -A -r -s 0 ||
1005                 lfsck_detach_error \
1006                 "(12) Fail to start lfsck_namespace with full speed"
1007
1008         stime=$(date +%s)
1009         lfsck_fast_create $nfiles ${m} $NTHREADS ||
1010                 lfsck_detach_error "(13) Fail to create files"
1011         etime=$(date +%s)
1012         echo "created $nfiles with namespace LFSCK run with full speed used" \
1013                 "$((etime - stime)) seconds"
1014         echo
1015
1016         $STOP_LFSCK > /dev/null 2>&1
1017
1018         lfsck_detach
1019
1020         echo "stopall"
1021         stopall > /dev/null || error "(14) Fail to stopall"
1022
1023         MDSCOUNT=$saved_mdscount
1024 }
1025 run_test 8 "lfsck namespace impact on create performance"
1026
1027 # cleanup the system at last
1028 lfsck_cleanup
1029 complete $SECONDS
1030 exit_status