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