Whamcloud - gitweb
LU-1538 tests: delete test files from /tmp after use
[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 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
17         skip "lfsck performance only for ldiskfs" && exit 0
18
19 require_dsh_mds || exit 0
20
21 [ "$SLOW" = "no" ] &&
22         skip "skip lfsck performance test under non-SLOW mode" && exit 0
23
24 NTHREADS=${NTHREADS:-0}
25 UNIT=${UNIT:-1048576}
26 MINCOUNT=${MINCOUNT:-8192}
27 MAXCOUNT=${MAXCOUNT:-32768}
28 MINCOUNT_REPAIR=${MINCOUNT_REPAIR:-8192}
29 MAXCOUNT_REPAIR=${MAXCOUNT_REPAIR:-32768}
30 BASE_COUNT=${BASE_COUNT:-1048576}
31 FACTOR=${FACTOR:-2}
32 INCFACTOR=${INCFACTOR:-25} #percent
33
34 RCMD="do_facet ${SINGLEMDS}"
35 RLCTL="${RCMD} ${LCTL}"
36 MDT_DEV="${FSNAME}-MDT0000"
37 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
38 START_NAMESPACE="${RLCTL} lfsck_start -M ${MDT_DEV} -t namespace"
39 STOP_LFSCK="${RLCTL} lfsck_stop -M ${MDT_DEV}"
40 SHOW_NAMESPACE="${RLCTL} get_param -n mdd.${MDT_DEV}.lfsck_namespace"
41 MNTOPTS_NOSCRUB="-o user_xattr,noscrub"
42 remote_mds && ECHOCMD=${RCMD} || ECHOCMD="eval"
43
44 if [ ${NTHREADS} -eq 0 ]; then
45         CPUCORE=$(${RCMD} cat /proc/cpuinfo | grep "processor.*:" | wc -l)
46         NTHREADS=$((CPUCORE * 2))
47 fi
48
49 lfsck_attach() {
50         ${ECHOCMD} "${LCTL} <<-EOF
51                 attach echo_client lfsck-MDT0000 lfsck-MDT0000_UUID
52                 setup ${MDT_DEV} mdd
53         EOF"
54 }
55
56 lfsck_detach() {
57         ${ECHOCMD} "${LCTL} <<-EOF
58                 device lfsck-MDT0000
59                 cleanup
60                 detach
61         EOF"
62 }
63
64 lfsck_create() {
65         local echodev=$(${RLCTL} dl | grep echo_client|awk '{print $1}')
66         local j
67
68         ${ECHOCMD} "${LCTL} <<-EOF
69                 cfg_device ${echodev}
70                 test_mkdir ${tdir}
71         EOF"
72
73         for ((j=1; j<${threads}; j++)); do
74                 ${ECHOCMD} "${LCTL} <<-EOF
75                         cfg_device ${echodev}
76                         test_mkdir ${tdir}${j}
77                 EOF"
78         done
79
80         ${ECHOCMD} "${LCTL} <<-EOF
81                 cfg_device ${echodev}
82                 --threads ${threads} 0 ${echodev} test_create \
83                 -d ${tdir} -D ${threads} -b ${lbase} -c 0 -n ${usize}
84         EOF"
85 }
86
87 lfsck_cleanup() {
88         do_rpc_nodes $(facet_active_host $SINGLEMDS) unload_modules
89         formatall
90 }
91
92 lfsck_create_nfiles() {
93         local total=$1
94         local lbase=$2
95         local threads=$3
96         local linkea=$4
97         local ldir="/test-${lbase}"
98         local cycle=0
99         local count=${UNIT}
100
101         while true; do
102                 [ ${count} -eq 0 -o  ${count} -gt ${total} ] && count=${total}
103                 local usize=$((count / NTHREADS))
104                 [ ${usize} -eq 0 ] && break
105                 local tdir=${ldir}-${cycle}-
106
107                 echo "[cycle: ${cycle}] [threads: ${threads}]"\
108                      "[files: ${count}] [basedir: ${tdir}]"
109                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB ||
110                         error "Fail to start MDS!"
111                 #define OBD_FAIL_FID_IGIF       0x1504
112                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x1504
113
114                 lfsck_attach
115                 lfsck_create
116                 lfsck_detach
117
118                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x0
119                 stop ${SINGLEMDS} || error "Fail to stop MDS!"
120
121                 total=$((total - usize * NTHREADS))
122                 [ ${total} -eq 0 ] && break
123                 lbase=$((lbase + usize))
124                 cycle=$((cycle + 1))
125         done
126 }
127
128 build_test_filter
129
130 test_0() {
131         local BCOUNT=0
132         local i
133
134         stopall
135         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
136         reformat_external_journal
137         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
138                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
139                 error "Fail to reformat the MDS!"
140
141         for ((i=$MINCOUNT; i<=$MAXCOUNT; i=$((i * FACTOR)))); do
142                 local nfiles=$((i - BCOUNT))
143
144                 echo "+++ start to create for ${i} files set at: $(date) +++"
145                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
146                         error "Fail to create files!"
147                 echo "+++ end to create for ${i} files set at: $(date) +++"
148
149                 BCOUNT=${i}
150                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
151                         error "Fail to start MDS!"
152
153                 echo "start lfsck_namespace for ${i} files set at: $(date)"
154                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
155
156                 while true; do
157                         local STATUS=$($SHOW_NAMESPACE |
158                                         awk '/^status/ { print $2 }')
159                         [ "$STATUS" == "completed" ] && break
160                         sleep 3 # check status every 3 seconds
161                 done
162
163                 echo "end lfsck_namespace for ${i} files set at: $(date)"
164                 SPEED=$($SHOW_NAMESPACE |
165                         awk '/^average_speed_phase1/ { print $2 }')
166                 echo "lfsck_namespace speed is ${SPEED}/sec"
167                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
168         done
169 }
170 run_test 0 "lfsck performance test (routine case) without load"
171
172 test_1() {
173         local BCOUNT=0
174         local i
175
176         stopall
177         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
178         reformat_external_journal
179         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
180                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
181                 error "Fail to reformat the MDS!"
182
183         for ((i=$MINCOUNT_REPAIR; i<=$MAXCOUNT_REPAIR; i=$((i * FACTOR)))); do
184                 local nfiles=$((i - BCOUNT))
185
186                 echo "+++ start to create for ${i} files set at: $(date) +++"
187                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
188                         error "Fail to create files!"
189                 echo "+++ end to create for ${i} files set at: $(date) +++"
190
191                 BCOUNT=${i}
192                 local stime=$(date +%s)
193                 echo "backup/restore ${i} files start at: $(date)"
194                 mds_backup_restore $SINGLEMDS || error "Fail to backup/restore!"
195                 echo "backup/restore ${i} files end at: $(date)"
196                 local etime=$(date +%s)
197                 local delta=$((etime - stime))
198                 [ $delta -gt 0 ] || delta=1
199                 echo "backup/restore ${i} files used ${delta} seconds"
200                 echo "backup/restore speed is $((i / delta))/sec"
201
202                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
203                         error "Fail to start MDS!"
204
205                 echo "start lfsck_namespace for ${i} files set at: $(date)"
206                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
207
208                 while true; do
209                         local STATUS=$($SHOW_NAMESPACE |
210                                         awk '/^status/ { print $2 }')
211                         [ "$STATUS" == "completed" ] && break
212                         sleep 3 # check status every 3 seconds
213                 done
214
215                 echo "end lfsck_namespace for ${i} files set at: $(date)"
216                 local SPEED=$($SHOW_NAMESPACE |
217                               awk '/^average_speed_phase1/ { print $2 }')
218                 echo "lfsck_namespace speed is ${SPEED}/sec"
219                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
220         done
221 }
222 run_test 1 "lfsck performance test (backup/restore) without load"
223
224 test_2() {
225         local i
226
227         for ((i=$MINCOUNT_REPAIR; i<=$MAXCOUNT_REPAIR; i=$((i * FACTOR)))); do
228                 stopall
229                 do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
230                 reformat_external_journal
231                 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) \
232                         --backfstype ldiskfs --reformat ${MDT_DEVNAME} \
233                         $(mdsvdevname 1) > /dev/null ||
234                         error "Fail to reformat the MDS!"
235
236                 echo "+++ start to create for ${i} files set at: $(date) +++"
237                 lfsck_create_nfiles ${i} 0 ${NTHREADS} 1 ||
238                         error "Fail to create files!"
239                 echo "+++ end to create for ${i} files set at: $(date) +++"
240
241                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
242                         error "Fail to start MDS!"
243
244                 echo "start lfsck_namespace for ${i} files set at: $(date)"
245                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
246
247                 while true; do
248                         local STATUS=$($SHOW_NAMESPACE |
249                                         awk '/^status/ { print $2 }')
250                         [ "$STATUS" == "completed" ] && break
251                         sleep 3 # check status every 3 seconds
252                 done
253
254                 echo "end lfsck_namespace for ${i} files set at: $(date)"
255                 local SPEED=$($SHOW_NAMESPACE |
256                               awk '/^average_speed_phase1/ { print $2 }')
257                 echo "lfsck_namespace speed is ${SPEED}/sec"
258                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
259         done
260 }
261 run_test 2 "lfsck performance test (simulate upgrade from 1.8) without load"
262
263 test_3() {
264         [ $MDSSIZE -lt 4000000 ] &&
265                 skip "MDT device is too small, expect at last 4GB" && exit 0
266
267         [ $BASE_COUNT -lt 1048576 ] && BASE_COUNT=1048576
268         [ $INCFACTOR -gt 25 ] && INCFACTOR=25
269
270         local inc_count=$((BASE_COUNT * INCFACTOR / 100))
271         local BCOUNT=0
272         local i
273
274         stopall
275         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
276         reformat_external_journal
277         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
278                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
279                 error "Fail to reformat the MDS!"
280
281         for ((i=$inc_count; i<=$BASE_COUNT; i=$((i + inc_count)))); do
282                 local nfiles=$((i - BCOUNT))
283
284                 echo "+++ start to create for ${i} files set at: $(date) +++"
285                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
286                         error "Fail to create files!"
287                 echo "+++ end to create for ${i} files set at: $(date) +++"
288                 BCOUNT=${i}
289         done
290
291         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
292                 error "Fail to start MDS!"
293
294         echo "start lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
295         $START_NAMESPACE || error "Fail to start lfsck_namespace!"
296
297         while true; do
298                 local STATUS=$($SHOW_NAMESPACE |
299                                 awk '/^status/ { print $2 }')
300                 [ "$STATUS" == "completed" ] && break
301                 sleep 3 # check status every 3 seconds
302         done
303
304         echo "end lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
305         local FULL_SPEED=$($SHOW_NAMESPACE |
306                       awk '/^average_speed_phase1/ { print $2 }')
307         echo "lfsck_namespace full_speed is ${FULL_SPEED}/sec"
308         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
309         local inc_speed=$((FULL_SPEED * INCFACTOR / 100))
310         local j
311
312         for ((j=$inc_speed; j<$FULL_SPEED; j=$((j + inc_speed)))); do
313                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
314                         error "Fail to start MDS!"
315
316                 $STOP_LFSCK > /dev/null 2>&1
317                 echo "start lfsck_namespace with speed ${j} at: $(date)"
318                 $START_NAMESPACE --reset -s ${j} ||
319                         error "Fail to start lfsck_namespace with speed ${j}!"
320                 # lfsck_namespace will be paused when MDS stop,
321                 # and will be restarted automatically when mount up again.
322                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
323
324                 local nfiles=$(((i - BCOUNT) / 2))
325
326                 echo "+++ start to create for ${i} files set at: $(date) +++"
327                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
328                         error "Fail to create files!"
329                 echo "+++ end to create for ${i} files set at: $(date) +++"
330                 BCOUNT=${i}
331                 i=$((i + inc_count))
332         done
333
334         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
335                 error "Fail to start MDS!"
336
337         $STOP_LFSCK /dev/null 2>&1
338         echo "start lfsck_namespace with full speed at: $(date)"
339         $START_NAMESPACE --reset -s 0 ||
340                 error "Fail to start lfsck_namespace with full speed!"
341         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
342
343         local nfiles=$(((i - BCOUNT) / 2))
344
345         echo "+++ start to create for ${i} files set at: $(date) +++"
346         lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
347                 error "Fail to create files!"
348         echo "+++ end to create for ${i} files set at: $(date) +++"
349 }
350 run_test 3 "lfsck performance test (routine case) without load"
351
352 # cleanup the system at last
353 lfsck_cleanup
354 complete $SECONDS
355 exit_status