Whamcloud - gitweb
LU-14739 quota: nodemap squashed root cannot bypass quota
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(dirname $0)/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 init_logging
9
10 # bug number for skipped test:
11 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 # bug number for SLOW test:
15 # time in minutes:                 40 min"
16 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
17
18 build_test_filter
19
20 # While we do not use OSTCOUNT=1 setup anymore,
21 # ost1failover_HOST is used
22 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
23 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
24
25 require_dsh_ost || exit 0
26
27 check_and_setup_lustre
28 assert_DIR
29 rm -rf $DIR/[df][0-9]*
30
31 TDIR=$DIR/d0.${TESTSUITE}
32 mkdir_on_mdt0 $TDIR
33 $LFS setstripe $TDIR -i 0 -c 1
34 $LFS getstripe $TDIR
35
36 test_0a() {
37         zconf_umount $(hostname) $MOUNT -f
38         # needs to run during initial client->OST connection
39         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
40         do_facet ost1 "lctl set_param fail_loc=0x80000211"
41         zconf_mount $(hostname) $MOUNT && $LFS df $MOUNT || error "mount fail"
42 }
43 run_test 0a "target handle mismatch (bug 5317)"
44
45 test_0b() {
46         fail ost1
47         cp /etc/profile  $TDIR/$tfile
48         sync
49         diff /etc/profile $TDIR/$tfile
50         rm -f $TDIR/$tfile
51 }
52 run_test 0b "empty replay"
53
54 test_1() {
55         date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
56         fail ost1
57         $CHECKSTAT -t file $TDIR/$tfile || error "check for file failed"
58         rm -f $TDIR/$tfile
59 }
60 run_test 1 "touch"
61
62 test_2() {
63         for i in $(seq 10); do
64                 echo "tag-$i" > $TDIR/$tfile-$i ||
65                         error "create $TDIR/$tfile-$i failed"
66         done
67         fail ost1
68         for i in $(seq 10); do
69                 grep -q "tag-$i" $TDIR/$tfile-$i ||
70                         error "grep $TDIR/$tfile-$i failed"
71         done
72         rm -f $TDIR/$tfile-*
73 }
74 run_test 2 "|x| 10 open(O_CREAT)s"
75
76 test_3() {
77         verify=$ROOT/tmp/verify-$$
78         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
79         ddpid=$!
80         sync &
81         fail ost1
82         wait $ddpid || error "wait for dd failed"
83         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
84         rm -f $verify $TDIR/$tfile
85 }
86 run_test 3 "Fail OST during write, with verification"
87
88 test_4() {
89         verify=$ROOT/tmp/verify-$$
90         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
91         # invalidate cache, so that we're reading over the wire
92         cancel_lru_locks osc
93         cmp $verify $TDIR/$tfile &
94         cmppid=$!
95         fail ost1
96         wait $cmppid || error "wait on cmp failed"
97         rm -f $verify $TDIR/$tfile
98 }
99 run_test 4 "Fail OST during read, with verification"
100
101 iozone_bg () {
102     local args=$@
103
104     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
105     mkfifo $tmppipe
106
107     echo "+ iozone $args"
108     iozone $args > $tmppipe &
109
110     local pid=$!
111
112     echo "tmppipe=$tmppipe"
113     echo iozone pid=$pid
114
115     # iozone exit code is 0 even if iozone is not completed
116     # need to check iozone output  on "complete"
117     local iozonelog=$TMP/${TESTSUITE}.iozone.log
118     rm -f $iozonelog
119     cat $tmppipe | while read line ; do
120         echo "$line"
121         echo "$line" >>$iozonelog
122     done;
123
124     local rc=0
125     wait $pid
126     rc=$?
127     if ! $(tail -1 $iozonelog | grep -q complete); then
128         echo iozone failed!
129         rc=1
130     fi
131     rm -f $tmppipe
132     rm -f $iozonelog
133     return $rc
134 }
135
136 test_5() {
137         if [ -z "$(which iozone 2> /dev/null)" ]; then
138                 skip_env "iozone missing"
139                 return 0
140         fi
141
142         # striping is -c 1, get min of available
143         local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail |
144                 sort -n | head -n1)
145         local size=$(( minavail * 3/4 ))
146         local GB=1048576  # 1048576KB == 1GB
147
148         if (( size > GB )); then
149                 size=$GB
150         fi
151         # no random I/O (-i 2) as it's very slow with ZFS
152         local iozone_opts="-i 0 -i 1 -+d -r 4 -s $size -f $TDIR/$tfile"
153
154         iozone_bg $iozone_opts &
155         local pid=$!
156
157         echo iozone bg pid=$pid
158
159         sleep 8
160         fail ost1
161         local rc=0
162         wait $pid || error "wait on iozone failed"
163         rc=$?
164         log "iozone rc=$rc"
165         rm -f $TDIR/$tfile
166         wait_delete_completed_mds
167         [ $rc -eq 0 ] || error "iozone failed"
168         return $rc
169 }
170 run_test 5 "Fail OST during iozone"
171
172 kbytesfree() {
173    calc_osc_kbytes kbytesfree
174 }
175
176 test_6() {
177         remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
178
179         local f=$TDIR/$tfile
180         sync && sleep 5 && sync  # wait for delete thread
181
182         # wait till space is returned, following
183         # (( $before > $after_dd)) test counting on that
184         wait_mds_ost_sync || error "first wait_mds_ost_sync failed"
185         wait_destroy_complete || error "first wait_destroy_complete failed"
186         sync_all_data
187
188         local before=$(kbytesfree)
189         dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd failed"
190         $LFS getstripe $f || error "$LFS getstripe $f failed"
191         local stripe_index=$(lfs getstripe -i $f)
192
193         sync
194         sleep 2 # ensure we have a fresh statfs
195         sync
196
197         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
198         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
199
200         wait_mds_ost_sync || error "second wait_mds_ost_sync failed"
201
202         # retry till statfs returns useful results
203         local after_dd=$(kbytesfree)
204         local i=0
205         while (( $before <= $after_dd && $i < 20 )); do
206                 sync
207                 sleep 1
208                 let ++i
209                 after_dd=$(kbytesfree)
210         done
211
212         log "before_free: $before after_dd_free: $after_dd took $i seconds"
213         (( $before > $after_dd )) ||
214                 error "free grew after dd: before:$before after_dd:$after_dd"
215
216         rm -f $f
217         fail ost$((stripe_index + 1))
218         wait_recovery_complete ost$((stripe_index + 1)) ||
219                 error "OST$((stripe_index + 1)) recovery not completed"
220         $CHECKSTAT -t file $f && return 2 || true
221         sync
222         # let the delete happen
223         wait_mds_ost_sync || error "third wait_mds_ost_sync failed"
224         wait_delete_completed || error "second wait_delete_completed failed"
225         local after=$(kbytesfree)
226         log "free_before: $before free_after: $after"
227         (( $before <= $after + $(fs_log_size) )) ||
228                 error "$before > $after + logsize $(fs_log_size)"
229 }
230 run_test 6 "Fail OST before obd_destroy"
231
232 test_7() {
233         local f=$TDIR/$tfile
234         sync && sleep 5 && sync # wait for delete thread
235
236         # wait till space is returned, following
237         # (( $before > $after_dd)) test counting on that
238         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
239         wait_destroy_complete || error "wait_destroy_complete failed"
240
241         local before=$(kbytesfree)
242         dd if=/dev/urandom bs=4096 count=1280 of=$f ||
243                 error "dd to file failed: $?"
244
245         sync
246         local after_dd=$(kbytesfree)
247         local i=0
248         while (( $before <= $after_dd && $i < 10 )); do
249                 sync
250                 sleep 1
251                 let ++i
252                 after_dd=$(kbytesfree)
253         done
254
255         log "before: $before after_dd: $after_dd took $i seconds"
256         (( $before > $after_dd )) ||
257                 error "space grew after dd: before:$before after_dd:$after_dd"
258         replay_barrier ost1
259         rm -f $f
260         fail ost1
261         wait_recovery_complete ost1 || error "OST recovery not done"
262         $CHECKSTAT -t file $f && return 2 || true
263         sync
264         # let the delete happen
265         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
266         wait_delete_completed || error "wait_delete_completed failed"
267         local after=$(kbytesfree)
268         log "before: $before after: $after"
269         (( $before <= $after + $(fs_log_size) )) ||
270                  error "$before > $after + logsize $(fs_log_size)"
271 }
272 run_test 7 "Fail OST before obd_destroy"
273
274 test_8a() {
275         [[ "$MDS1_VERSION" -ge $(version_code 2.3.0) ]] ||
276                 skip "Need MDS version at least 2.3.0"
277         verify=$ROOT/tmp/verify-$$
278         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
279                 error "Create verify file failed"
280         #define OBD_FAIL_OST_DQACQ_NET 0x230
281         do_facet ost1 "lctl set_param fail_loc=0x230"
282         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
283         ddpid=$!
284         sleep $TIMEOUT  # wait for the io to become redo io
285         if ! ps -p $ddpid  > /dev/null 2>&1; then
286                 error "redo io finished incorrectly"
287         fi
288         do_facet ost1 "lctl set_param fail_loc=0"
289         wait $ddpid || true
290         cancel_lru_locks osc
291         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
292         rm -f $verify $TDIR/$tfile
293         message=$(dmesg | grep "redo for recoverable error -115")
294         [ -z "$message" ] || error "redo error messages found in dmesg"
295 }
296 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
297
298 test_8b() {
299         [[ "$MDS1_VERSION" -ge $(version_code 2.3.0) ]] ||
300                 skip "Need MDS version at least 2.3.0"
301         verify=$ROOT/tmp/verify-$$
302         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
303                 error "Create verify file failed"
304         #define OBD_FAIL_OST_DQACQ_NET 0x230
305         do_facet ost1 "lctl set_param fail_loc=0x230"
306         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
307         ddpid=$!
308         sleep $TIMEOUT  # wait for the io to become redo io
309         fail ost1
310         do_facet ost1 "lctl set_param fail_loc=0"
311         wait $ddpid || error "dd did not complete"
312         cancel_lru_locks osc
313         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
314         rm -f $verify $TDIR/$tfile
315 }
316 run_test 8b "Verify redo io: redo io should success after recovery"
317
318 test_8c() {
319         [[ "$MDS1_VERSION" -ge $(version_code 2.3.0) ]] ||
320                 skip "Need MDS version at least 2.3.0"
321         verify=$ROOT/tmp/verify-$$
322         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
323                 error "Create verify file failed"
324         #define OBD_FAIL_OST_DQACQ_NET 0x230
325         do_facet ost1 "lctl set_param fail_loc=0x230"
326         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
327         ddpid=$!
328         sleep $TIMEOUT  # wait for the io to become redo io
329         ost_evict_client
330         # allow recovery to complete
331         sleep $((TIMEOUT + 2))
332         do_facet ost1 "lctl set_param fail_loc=0"
333         wait $ddpid
334         cancel_lru_locks osc
335         cmp $verify $TDIR/$tfile && error "compare files should fail"
336         rm -f $verify $TDIR/$tfile
337 }
338 run_test 8c "Verify redo io: redo io should fail after eviction"
339
340 test_8d() {
341         [[ "$MDS1_VERSION" -ge $(version_code 2.3.0) ]] ||
342                 skip "Need MDS version at least 2.3.0"
343         #define OBD_FAIL_MDS_DQACQ_NET 0x187
344         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
345         # test the non-intent create path
346         mcreate $TDIR/$tfile &
347         cpid=$!
348         sleep $TIMEOUT
349         if ! ps -p $cpid  > /dev/null 2>&1; then
350                 error "mknod finished incorrectly"
351         fi
352         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
353         wait $cpid || error "mcreate did not complete"
354         stat $TDIR/$tfile || error "mknod failed"
355
356         rm $TDIR/$tfile
357
358         #define OBD_FAIL_MDS_DQACQ_NET 0x187
359         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
360         # test the intent create path
361         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
362         cpid=$!
363         sleep $TIMEOUT
364         if ! ps -p $cpid > /dev/null 2>&1; then
365                 error "open finished incorrectly"
366         fi
367         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
368         wait $cpid || error "openfile failed"
369         stat $TDIR/$tfile || error "open failed"
370 }
371 run_test 8d "Verify redo creation on -EINPROGRESS"
372
373 test_8e() {
374         [[ "$MDS1_VERSION" -ge $(version_code 2.3.0) ]] ||
375                 skip "Need MDS version at least 2.3.0"
376         sleep 1 # ensure we have a fresh statfs
377         #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
378         do_facet ost1 "lctl set_param fail_loc=0x231"
379         $LFS df $MOUNT &
380         dfpid=$!
381         sleep $TIMEOUT
382         if ! ps -p $dfpid  > /dev/null 2>&1; then
383                 do_facet ost1 "lctl set_param fail_loc=0"
384                 error "df shouldn't have completed!"
385         fi
386 }
387 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
388
389 test_9() {
390         [ "$OST1_VERSION" -ge $(version_code 2.6.54) ] ||
391                 skip "Need OST version at least 2.6.54"
392         $LFS setstripe -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
393
394         # LU-1573 - Add duplicate write to generate grants
395         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
396                 error "First write failed"
397         replay_barrier ost1
398         # do IO
399         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
400                 error "failed to write"
401         # failover, replay and resend replayed waiting request
402         #define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
403         do_facet ost1 $LCTL set_param fail_loc=0x00000714
404         do_facet ost1 $LCTL set_param fail_val=$TIMEOUT
405         fail ost1
406         do_facet ost1 $LCTL set_param fail_loc=0
407         do_facet ost1 "dmesg | tail -n 100" |
408                 sed -n '/no req deadline/,$ p' | grep -qi 'Already past' &&
409                 return 1
410         return 0
411 }
412 run_test 9 "Verify that no req deadline happened during recovery"
413
414 test_10() {
415         rm -f $TDIR/$tfile
416
417         dd if=/dev/zero of=$TDIR/$tfile count=10 || error "dd failed"
418
419         #define OBD_FAIL_OSC_DELAY_IO            0x414
420         $LCTL set_param fail_val=60 fail_loc=0x414
421         cancel_lru_locks OST0000-osc &
422         sleep 2
423         facet_failover ost1 || error "failover: $?"
424
425         #define OBD_FAIL_LDLM_GRANT_CHECK        0x32a
426         $LCTL set_param fail_loc=0x32a
427         stat $TDIR/$tfile
428
429         wait
430 }
431 run_test 10 "conflicting PW & PR locks on a client"
432
433 test_12() {
434         [ $FAILURE_MODE != "HARD" ] &&
435                 skip "Test needs FAILURE_MODE HARD" && return 0
436         remote_ost || { skip "need remote OST" && return 0; }
437
438         local tmp=$TMP/$tdir
439         local dir=$DIR/$tdir
440         declare -a pids
441
442
443         mkdir -p $tmp || error "can't create $tmp"
444         mkdir -p $dir || error "can't create $dir"
445
446         $LFS setstripe -c 1 -i 0 $dir
447
448         for i in `seq 1 10`; do mkdir $dir/d$i; done
449
450         #define OBD_FAIL_OST_DELAY_TRANS        0x245
451         do_facet ost1 "$LCTL set_param fail_loc=0x245" ||
452                 error "can't set fail_loc"
453
454         for i in `seq 1 10`;
455         do
456                 createmany -o $dir/d$i/$(openssl rand -base64 12) 500 &
457                 pids+=($!)
458         done
459         echo "Waiting createmany pids"
460         wait ${pids[@]}
461
462         ls -lR $dir > $tmp/ls_r_out 2>&1&
463         local ls_pid=$!
464
465         facet_failover ost1
466
467         echo "starting wait for ls -l"
468         wait $ls_pid
469         grep "?\|No such file or directory" $tmp/ls_r_out &&
470                 error "Found file without object on OST"
471         rm -rf $tmp
472         rm -rf $dir
473 }
474 run_test 12 "check stat after OST failover"
475
476 complete $SECONDS
477 check_and_cleanup_lustre
478 exit_status