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