Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 PTLDEBUG=${PTLDEBUG:--1}
6 LUSTRE=${LUSTRE:-$(dirname $0)/..}
7 . $LUSTRE/tests/test-framework.sh
8 init_test_env "$@"
9 init_logging
10
11 ALWAYS_EXCEPT="$RECOVERY_SMALL_EXCEPT "
12
13 if $SHARED_KEY; then
14         always_except LU-17141 133
15 fi
16
17 build_test_filter
18
19 require_dsh_mds || exit 0
20
21 # Allow us to override the setup if we already have a mounted system by
22 # setting SETUP=" " and CLEANUP=" "
23 SETUP=${SETUP:-""}
24 CLEANUP=${CLEANUP:-""}
25
26 check_and_setup_lustre
27
28 assert_DIR
29 rm -rf $DIR/d[0-9]* $DIR/f.${TESTSUITE}*
30
31 # new sequence needed for MDS < v2_15_61-226-gf00d2467fc
32 if (( $MDS1_VERSION < $(version_code 2.15.61.226) )); then
33         force_new_seq_all
34 fi
35
36 test_1() {
37         local f1="$DIR/$tfile"
38         local f2="$DIR/$tfile.2"
39
40         drop_request "mcreate $f1" ||
41                 error_noexit "create '$f1': drop req"
42
43         drop_reint_reply "mcreate $f2" ||
44                 error_noexit "create '$f2': drop rep"
45
46         drop_request "tchmod 111 $f2" ||
47                 error_noexit "chmod '$f2': drop req"
48
49         drop_reint_reply "tchmod 666 $f2" ||
50                 error_noexit "chmod '$f2': drop rep"
51
52         drop_request "statone $f2" ||
53                 error_noexit "stat '$f2': drop req"
54
55         drop_reply  "statone $f2" ||
56                 error_noexit "stat '$f2': drop rep"
57 }
58 run_test 1 "create, chmod, stat: drop req, drop rep"
59
60 test_4() {
61         local t=$DIR/$tfile
62         do_facet_create_file client $t 10K ||
63                 error_noexit "Create file $t"
64
65         drop_request "cat $t > /dev/null" ||
66                 error_noexit "Open request for $t file"
67
68         drop_reply "cat $t > /dev/null" ||
69                 error_noexit "Open replay for $t file"
70 }
71 run_test 4 "open: drop req, drop rep"
72
73 test_5() {
74         local T=$DIR/$tfile
75         local R="$T-renamed"
76         local RR="$T-renamed-again"
77         do_facet_create_file client $T 10K ||
78                 error_noexit "Create file $T"
79
80         drop_request "mv $T $R" ||
81                 error_noexit "Rename $T"
82
83         drop_reint_reply "mv $R $RR" ||
84                 error_noexit "Failed rename replay on $R"
85
86         do_facet client "checkstat -v $RR" ||
87                 error_noexit "checkstat error on $RR"
88
89         do_facet client "rm $RR" ||
90                 error_noexit "Can't remove file $RR"
91 }
92 run_test 5 "rename: drop req, drop rep"
93
94 test_6() {
95         local T=$DIR/$tfile
96         local LINK1=$DIR/$tfile.link1
97         local LINK2=$DIR/$tfile.link2
98
99         do_facet_create_file client $T 10K || error_noexit "Create file $T"
100         drop_request "link $T $LINK1" || error_noexit "link request for $T"
101         drop_reint_reply "link $T $LINK2" || error_noexit "link reply for $T"
102         drop_request "unlink $LINK1" || error_noexit "unlink request for $T"
103         drop_reint_reply "unlink $LINK2" || error_noexit "unlink reply for $T"
104         do_facet client "rm $T" || error_noexit "Can't remove file $T"
105 }
106 run_test 6 "link, unlink: drop req, drop rep"
107
108 #bug 1423
109 test_8() {
110         drop_reint_reply "touch $DIR/$tfile"    || return 1
111 }
112 run_test 8 "touch: drop rep (bug 1423)"
113
114 #bug 1420
115 test_9() {
116         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
117
118         local t1=${tfile}.1
119         local t2=${tfile}.2
120         do_facet_random_file client $TMP/$tfile 1K ||
121                 error_noexit "Create random file $TMP/$tfile"
122         # make this big, else test 9 doesn't wait for bulk -- bz 5595
123         do_facet_create_file client $TMP/$t1 4M ||
124                 error_noexit "Create file $TMP/$t1"
125         do_facet client "cp $TMP/$t1 $DIR/$t1" ||
126                 error_noexit "Can't copy to $DIR/$t1 file"
127         pause_bulk "cp $TMP/$tfile $DIR/$tfile" ||
128                 error_noexit "Can't pause_bulk copy"
129         do_facet client "cp $TMP/$t1 $DIR/$t2" ||
130                 error_noexit "Can't copy file"
131         do_facet client "sync"
132         do_facet client "rm $DIR/$tfile $DIR/$t2 $DIR/$t1" ||
133                 error_noexit "Can't remove files"
134         do_facet client "rm $TMP/$t1 $TMP/$tfile"
135 }
136 run_test 9 "pause bulk on OST (bug 1420)"
137
138 #bug 1521
139 test_10a() {
140         local before=$(date +%s)
141         local evict
142         local lru_param="ldlm.namespaces.*mdc*.lru_max_age"
143         local old_max_age=($($LCTL get_param -n $lru_param))
144         local old_ratelimit=$($LCTL get_param console_ratelimit)
145
146         $LCTL set_param $lru_param=3900s console_ratelimit=0
147         stack_trap "$LCTL set_param $lru_param=$old_max_age $old_ratelimit"
148
149         do_facet client "stat $DIR > /dev/null"  ||
150                 error "failed to stat $DIR: $?"
151         drop_bl_callback "chmod 0777 $DIR" ||
152                 error "failed to chmod $DIR: $?"
153
154         # let the client reconnect
155         client_reconnect
156         evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
157           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
158         [[ -n "$evict" ]] && (( $evict > $before )) ||
159                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
160                     error "no eviction: $evict before:$before")
161
162         do_facet client checkstat -v -p 0777 $DIR ||
163                 error "client checkstat failed: $?"
164
165         # console messages may be ratelimited on later iterations
166         (( ONLY_REPEAT_ITER == 1 )) || return 0
167
168         # check that the thread watchdog is working properly
169         do_facet mds1 dmesg | tac | sed "/${TESTNAME/_/ }/,$ d" |
170                 grep "[Ss]ervice thread pid .* was inactive" ||
171                 error "no service thread inactive message for ${TESTNAME/_/ }"
172
173         # can't check for "completed" message where it was removed
174         (( $MDS1_VERSION > $(version_code v2_12_50-83-gfc9de679a4) &&
175            $MDS1_VERSION < $(version_code 2.15.62.59) )) ||
176                 do_facet mds1 dmesg | tac | sed "/${TESTNAME/_/ }/,$ d" |
177                         grep "[Ss]ervice thread pid .* completed after" ||
178                 error "no service thread completed  message for ${TESTNAME/_/ }"
179 }
180 run_test 10a "finish request on server after client eviction (bug 1521)"
181
182 test_10b() {
183         local before=$(date +%s)
184         local evict
185
186         [[ "$MDS1_VERSION" -lt $(version_code 2.6.53) ]] &&
187                 skip "Need MDS version at least 2.6.53"
188         do_facet client "stat $DIR > /dev/null"  ||
189                 error "failed to stat $DIR: $?"
190         drop_bl_callback_once "chmod 0777 $DIR" ||
191                 error "failed to chmod $DIR: $?"
192
193         # let the client reconnect
194         client_reconnect
195         evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
196           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
197
198         [ -z "$evict" ] || [[ $evict -le $before ]] ||
199                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
200                     error "eviction happened: $evict before:$before")
201
202         do_facet client checkstat -v -p 0777 $DIR ||
203                 error "client checkstat failed: $?"
204 }
205 run_test 10b "re-send BL AST"
206
207 test_10c() {
208         local before=$(date +%s)
209         local evict
210         local mdccli
211         local mdcpath
212         local conn_uuid
213         local workdir
214         local pid
215         local rc
216
217         workdir="${DIR}/${tdir}"
218         mkdir -p ${workdir} || error "can't create workdir $?"
219         stat ${workdir} > /dev/null ||
220                 error "failed to stat ${workdir}: $?"
221         mdtidx=$($LFS getdirstripe -i ${workdir})
222         mdtname=$($LFS mdts ${workdir} | grep -e "^$mdtidx:" |
223                   awk '{sub("_UUID", "", $2); print $2;}')
224         #assume one client
225         mdccli=$($LCTL dl | grep "${mdtname}-mdc" | awk '{print $4;}')
226         conn_uuid=$($LCTL get_param -n mdc.${mdccli}.conn_uuid)
227         mdcpath="mdc.${mdccli}.import=connection=${conn_uuid}"
228
229         drop_bl_callback_once "chmod 0777 ${workdir}" &
230         pid=$!
231
232         # let chmod blocked
233         sleep 1
234         # force client reconnect
235         $LCTL set_param "${mdcpath}"
236
237         # wait client reconnect
238         client_reconnect
239         wait $pid
240         rc=$?
241         evict=$($LCTL get_param mdc.${mdccli}.state |
242            awk -F"[ [,]" '/EVICTED]$/ { if (t<$4) {t=$4;} } END { print t }')
243
244         [[ $evict -le $before ]] ||
245                 ( $LCTL get_param mdc.$FSNAME-MDT*.state;
246                     error "eviction happened: $EVICT before:$BEFORE" )
247
248         [ $rc -eq 0 ] || error "chmod must finished OK"
249         checkstat -v -p 0777 "${workdir}" ||
250                 error "client checkstat failed: $?"
251 }
252 run_test 10c "re-send BL AST vs reconnect race (LU-5569)"
253
254 test_10d() {
255         local before=$(date +%s)
256         local evict
257
258         [[ "$MDS1_VERSION" -lt $(version_code 2.6.90) ]] &&
259                 skip "Need MDS version at least 2.6.90"
260
261         # sleep 1 is to make sure that BEFORE is not equal to EVICTED below
262         sleep 1
263         rm -f $TMP/$tfile
264         echo -n ", world" | dd of=$TMP/$tfile bs=1c seek=5
265
266         remount_client $MOUNT
267         mount_client $MOUNT2
268
269         cancel_lru_locks osc
270         $LFS setstripe -i 0 -c 1 $DIR1/$tfile
271         echo -n hello | dd of=$DIR1/$tfile bs=5
272
273         stat $DIR2/$tfile >& /dev/null
274         $LCTL set_param fail_err=71
275         drop_bl_callback "echo -n \\\", world\\\" >> $DIR2/$tfile"
276
277         client_reconnect
278
279         cancel_lru_locks osc
280         cmp -l $DIR1/$tfile $DIR2/$tfile || error "file contents differ"
281         cmp -l $DIR1/$tfile $TMP/$tfile || error "wrong content found"
282
283         evict=$(do_facet client $LCTL get_param osc.$FSNAME-OST0000*.state | \
284                 tr -d '\-\[\] ' | \
285           awk -F"[ [,]" '/EVICTED$/ { if (mx<$1) {mx=$1;} } END { print mx }')
286
287         [[ $evict -gt $before ]] ||
288                 (do_facet client $LCTL get_param osc.$FSNAME-OST0000*.state;
289                     error "no eviction: $evict before:$before")
290
291         $LCTL set_param fail_err=0
292         rm $TMP/$tfile
293         umount_client $MOUNT2
294 }
295 run_test 10d "test failed blocking ast"
296
297 test_10e()
298 {
299         [[ "$OST1_VERSION" -le $(version_code 2.8.58) ]] &&
300                 skip "Need OST version at least 2.8.59"
301         [ $CLIENTCOUNT -lt 2 ] && skip "need two clients"
302         [ $(facet_host client) == $(facet_host ost1) ] &&
303                 skip "need ost1 and client on different nodes"
304         local -a clients=(${CLIENTS//,/ })
305         local client1=${clients[0]}
306         local client2=${clients[1]}
307
308         $LFS setstripe -c 1 -i 0 $DIR/$tfile-1 $DIR/$tfile-2
309         $MULTIOP $DIR/$tfile-1 Ow1048576c
310
311 #define OBD_FAIL_LDLM_BL_CALLBACK_NET                   0x305
312         $LCTL set_param fail_loc=0x80000305
313
314 #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
315         do_facet ost1 "$LCTL set_param fail_loc=0x1000030e"
316         # hit OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT twice:
317         # 1. to return ENOTCONN from ldlm_handle_enqueue0
318         # 2. to pause reconnect handling between resend and setting
319         # import to LUSTRE_IMP_FULL state
320         do_facet ost1 "$LCTL set_param fail_val=3"
321
322         # client1 fails ro respond to bl ast
323         do_node $client2 "$MULTIOP $DIR/$tfile-1 Ow1048576c" &
324         MULTIPID=$!
325
326         # ost1 returns error on enqueue, which causes client1 to reconnect
327         do_node $client1 "$MULTIOP $DIR/$tfile-2 Ow1048576c" ||
328                 error "multiop failed"
329         wait $MULTIPID
330
331         do_facet ost1 "$LCTL set_param fail_loc=0"
332         do_facet ost1 "$LCTL set_param fail_val=0"
333 }
334 run_test 10e "re-send BL AST vs reconnect race 2"
335
336 #bug 2460
337 # wake up a thread waiting for completion after eviction
338 test_11(){
339         do_facet client $MULTIOP $DIR/$tfile Ow  ||
340                 { error "multiop write failed: $?"; return 1; }
341         do_facet client $MULTIOP $DIR/$tfile or  ||
342                 { error "multiop read failed: $?"; return 2; }
343
344         cancel_lru_locks osc
345
346         do_facet client $MULTIOP $DIR/$tfile or  ||
347                 { error "multiop read failed: $?"; return 3; }
348         drop_bl_callback_once $MULTIOP $DIR/$tfile Ow ||
349                 echo "evicted as expected"
350
351         do_facet client unlink $DIR/$tfile ||
352                 { error "unlink failed: $?"; return 4; }
353         # allow recovery to complete
354         client_up || client_up || sleep $TIMEOUT
355 }
356 run_test 11 "wake up a thread waiting for completion after eviction (b=2460)"
357
358 #b=2494
359 test_12(){
360         $LCTL mark $MULTIOP $DIR/$tfile OS_c
361         do_facet $SINGLEMDS "lctl set_param fail_loc=0x115"
362         clear_failloc $SINGLEMDS $((TIMEOUT * 2)) &
363         multiop_bg_pause $DIR/$tfile OS_c ||
364                 { error "multiop failed: $?"; return 1; }
365         PID=$!
366 #define OBD_FAIL_MDS_CLOSE_NET           0x115
367         kill -USR1 $PID
368         echo "waiting for multiop $PID"
369         wait $PID || { error "wait for multiop faile: $?"; return 2; }
370         do_facet client unlink $DIR/$tfile ||
371                 { error "client unlink failed: $?"; return 3; }
372         # allow recovery to complete
373         client_up || client_up || sleep $TIMEOUT
374 }
375 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
376
377 # Bug 113, check that readdir lost recv timeout works.
378 test_13() {
379         mkdir_on_mdt0 $DIR/$tdir || { error "mkdir failed: $?"; return 1; }
380         touch $DIR/$tdir/newentry || { error "touch failed: $?"; return 2; }
381 # OBD_FAIL_MDS_READPAGE_NET|CFS_FAIL_ONCE
382         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000104"
383         ls $DIR/$tdir || { error "ls failed: $?"; return 3; }
384         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
385         rm -rf $DIR/$tdir || { error "remove test dir failed: $?"; return 4; }
386 }
387 run_test 13 "mdc_readpage restart test (bug 1138)"
388
389 # Bug 113, check that readdir lost send timeout works.
390 test_14() {
391         mkdir_on_mdt0 $DIR/$tdir
392         touch $DIR/$tdir/newentry
393 # OBD_FAIL_MDS_SENDPAGE|CFS_FAIL_ONCE
394         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000106"
395         ls $DIR/$tdir || return 1
396         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
397 }
398 run_test 14 "mdc_readpage resend test (bug 1138)"
399
400 test_15() {
401         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
402         touch $DIR/$tfile && return 1
403         return 0
404 }
405 run_test 15 "failed open (-ENOMEM)"
406
407 READ_AHEAD=`lctl get_param -n llite.*.max_read_ahead_mb | head -n 1`
408 stop_read_ahead() {
409         lctl set_param -n llite.*.max_read_ahead_mb 0
410 }
411
412 start_read_ahead() {
413         lctl set_param -n llite.*.max_read_ahead_mb $READ_AHEAD
414 }
415
416 test_16() {
417         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
418
419         do_facet_random_file client $TMP/$tfile 100K ||
420                 { error_noexit "Create random file $TMP/$T" ; return 0; }
421         do_facet client "cp $TMP/$tfile $DIR/$tfile" ||
422                 { error_noexit "Copy to $DIR/$tfile file" ; return 0; }
423         sync
424         stop_read_ahead
425
426 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | CFS_FAIL_ONCE
427         do_facet ost1 "lctl set_param fail_loc=0x80000504"
428         cancel_lru_locks osc
429         # OST bulk will time out here, client resends
430         do_facet client "cmp $TMP/$tfile $DIR/$tfile" || return 1
431         do_facet ost1 lctl set_param fail_loc=0
432         # give recovery a chance to finish (shouldn't take long)
433         sleep $TIMEOUT
434         do_facet client "cmp $TMP/$tfile $DIR/$tfile" || return 2
435         start_read_ahead
436         rm -f $TMP/$tfile
437 }
438 run_test 16 "timeout bulk put, don't evict client (2732)"
439
440 test_17a() {
441         local at_max_saved=0
442
443         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
444
445         local SAMPLE_FILE=$TMP/$tfile
446         do_facet_random_file client $SAMPLE_FILE 20K ||
447                 { error_noexit "Create random file $SAMPLE_FILE" ; return 0; }
448
449         # With adaptive timeouts, bulk_get won't expire until
450         # adaptive_timeout_max
451         if at_is_enabled; then
452                 at_max_saved=$(at_max_get ost1)
453                 at_max_set $TIMEOUT ost1
454         fi
455
456         # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | CFS_FAIL_ONCE
457         # OST bulk will time out here, client retries
458         do_facet ost1 lctl set_param fail_loc=0x80000503
459         # need to ensure we send an RPC
460         do_facet client cp $SAMPLE_FILE $DIR/$tfile
461         sync
462
463         # with AT, client will wait adaptive_max*factor+net_latency before
464         # expiring the req, hopefully timeout*2 is enough
465         sleep $(($TIMEOUT*2))
466
467         do_facet ost1 lctl set_param fail_loc=0
468         do_facet client "df $DIR"
469         # expect cmp to succeed, client resent bulk
470         do_facet client "cmp $SAMPLE_FILE $DIR/$tfile" || return 3
471         do_facet client "rm $DIR/$tfile" || return 4
472         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
473         return 0
474 }
475 run_test 17a "timeout bulk get, don't evict client (2732)"
476
477 test_17b() {
478         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
479
480         # get one of the clients from client list
481         local rcli=$(echo $RCLIENTS | cut -d ' ' -f 1)
482         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
483         local ldlm_enqueue_min=$(do_facet ost1 find /sys -name ldlm_enqueue_min)
484         [ -z "$ldlm_enqueue_min" ] &&
485                 skip "missing /sys/.../ldlm_enqueue_min" && return 0
486
487         $LFS setstripe -i 0 -c 1 -S 1048576 $DIR/$tfile ||
488                 error "setstripe failed"
489         $LFS setstripe -i 0 -c 1 -S 1048576 $DIR/${tfile}2 ||
490                 error "setstripe 2 failed"
491
492         save_lustre_params ost1 "at_history" > $p
493         save_lustre_params ost1 "bulk_timeout" >> $p
494         local dev="${FSNAME}-OST0000"
495         save_lustre_params ost1 "obdfilter.$dev.brw_size" >> $p
496         local ldlm_enqueue_min_save=$(do_facet ost1 cat $ldlm_enqueue_min)
497
498         local new_at_history=15
499
500         do_facet ost1 "$LCTL set_param at_history=$new_at_history"
501         do_facet ost1 "$LCTL set_param bulk_timeout=30"
502         do_facet ost1 "echo 30 > /sys/module/ptlrpc/parameters/ldlm_enqueue_min"
503
504         # brw_size is required to be 4m so that bulk transfer timeout
505         # could be simulated with OBD_FAIL_PTLRPC_CLIENT_BULK_CB3
506         local brw_size=$($LCTL get_param -n \
507             osc.$FSNAME-OST0000-osc-[^M]*.import |
508             awk '/max_brw_size/{print $2}')
509         if [ $brw_size -ne 4194304 ]
510         then
511                 save_lustre_params ost1 "obdfilter.$dev.brw_size" >> $p
512                 do_facet ost1 "$LCTL set_param obdfilter.$dev.brw_size=4"
513                 remount_client $MOUNT
514         fi
515
516         # get service estimate expanded
517         #define OBD_FAIL_OST_BRW_PAUSE_PACK              0x224
518         do_facet ost1 "$LCTL set_param fail_loc=0x80000224 fail_val=35"
519         echo "delay rpc servicing by 35 seconds"
520         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=fdatasync
521
522         local estimate
523         estimate=$($LCTL get_param -n osc.$dev-osc-*.timeouts |
524             awk '/portal 6/ {print $5}')
525         echo "service estimates increased to $estimate"
526
527         # let current worst service estimate to get closer to obliteration
528         sleep $((new_at_history / 3))
529
530         # start i/o and simulate bulk transfer loss
531         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3     0x520
532         do_facet ost1 "$LCTL set_param fail_loc=0xa0000520 fail_val=1"
533         dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 conv=fdatasync,notrunc &
534         local writedd=$!
535
536         # start lock conflict handling
537         sleep $((new_at_history / 3))
538         do_node $rcli "dd if=$DIR/$tfile of=/dev/null bs=1M count=1" &
539         local readdd=$!
540
541         # obliterate the worst service estimate
542         sleep $((new_at_history / 3 + 1))
543         dd if=/dev/zero of=$DIR/${tfile}2 bs=1M count=1
544
545         estimate=$($LCTL get_param -n osc.$dev-osc-*.timeouts |
546             awk '/portal 6/ {print $5}')
547         echo "service estimate dropped to $estimate"
548
549         wait $writedd
550         [[ $? == 0 ]] || error "write failed"
551         wait $readdd
552         [[ $? == 0 ]] || error "read failed"
553
554         restore_lustre_params <$p
555         if [ $brw_size -ne 4194304 ]
556         then
557                 remount_client $MOUNT || error "remount_client failed"
558         fi
559         do_facet ost1 "echo $ldlm_enqueue_min_save > $ldlm_enqueue_min"
560 }
561 run_test 17b "timeout bulk get, dont evict client (3582)"
562
563 test_18a() {
564         [ -z ${ost2_svc} ] && skip_env "needs 2 osts" && return 0
565
566         do_facet_create_file client $TMP/$tfile 20K ||
567                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
568
569         do_facet client mkdir -p $DIR/$tdir
570         f=$DIR/$tdir/$tfile
571
572         cancel_lru_locks osc
573         pgcache_empty || return 1
574
575         # 1 stripe on ost2
576         $LFS setstripe -i 1 -c 1 $f
577         stripe_index=$($LFS getstripe -i $f)
578         if [ $stripe_index -ne 1 ]; then
579                 $LFS getstripe $f
580                 error "$f: stripe_index $stripe_index != 1" && return
581         fi
582
583         do_facet client cp $TMP/$tfile $f
584         sync
585         local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
586         $LCTL --device $osc2dev deactivate || return 3
587         # my understanding is that there should be nothing in the page
588         # cache after the client reconnects?
589         rc=0
590         pgcache_empty || rc=2
591         $LCTL --device $osc2dev activate
592         rm -f $f $TMP/$tfile
593         return $rc
594 }
595 run_test 18a "manual ost invalidate clears page cache immediately"
596
597 test_18b() {
598         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
599
600         do_facet_create_file client $TMP/$tfile 20K ||
601                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
602
603         do_facet client mkdir -p $DIR/$tdir
604         f=$DIR/$tdir/$tfile
605
606         cancel_lru_locks osc
607         pgcache_empty || return 1
608
609         $LFS setstripe -i 0 -c 1 $f
610         stripe_index=$($LFS getstripe -i $f)
611         if [ $stripe_index -ne 0 ]; then
612                 $LFS getstripe $f
613                 error "$f: stripe_index $stripe_index != 0" && return
614         fi
615
616         do_facet client cp $TMP/$tfile $f
617         sync
618         ost_evict_client
619         # allow recovery to complete
620         sleep $((TIMEOUT + 2))
621         # my understanding is that there should be nothing in the page
622         # cache after the client reconnects?
623         rc=0
624         pgcache_empty || rc=2
625         rm -f $f $TMP/$tfile
626         return $rc
627 }
628 run_test 18b "eviction and reconnect clears page cache (2766)"
629
630 test_18c() {
631         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
632
633         do_facet_create_file client $TMP/$tfile 20K ||
634                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
635
636         do_facet client mkdir -p $DIR/$tdir
637         f=$DIR/$tdir/$tfile
638
639         cancel_lru_locks osc
640         pgcache_empty || return 1
641
642         $LFS setstripe -i 0 -c 1 $f
643         stripe_index=$($LFS getstripe -i $f)
644         if [ $stripe_index -ne 0 ]; then
645                 $LFS getstripe $f
646                 error "$f: stripe_index $stripe_index != 0" && return
647         fi
648
649         do_facet client cp $TMP/$tfile $f
650         sync
651         ost_evict_client
652
653         # OBD_FAIL_OST_CONNECT_NET2
654         # lost reply to connect request
655         do_facet ost1 lctl set_param fail_loc=0x80000225
656         # force reconnect
657         sleep 1
658         $LFS df $MOUNT > /dev/null 2>&1
659         sleep 2
660         # my understanding is that there should be nothing in the page
661         # cache after the client reconnects?
662         rc=0
663         pgcache_empty || rc=2
664         rm -f $f $TMP/$tfile
665         return $rc
666 }
667 run_test 18c "Dropped connect reply after eviction handing (14755)"
668
669 test_19a() {
670         local before=$(date +%s)
671         local evict
672
673         mount_client $DIR2 || error "failed to mount $DIR2"
674
675         # cancel cached locks from OST to avoid eviction from it
676         cancel_lru_locks osc
677
678         do_facet client "stat $DIR > /dev/null"  ||
679                 error "failed to stat $DIR: $?"
680         drop_ldlm_cancel "chmod 0777 $DIR2" ||
681                 error "failed to chmod $DIR2"
682
683         umount_client $DIR2
684
685         # let the client reconnect
686         client_reconnect
687         evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
688                 awk -F"[ [,]" '/EVICTED ]$/ \
689                         { if (mx<$5) {mx=$5;} } END { print mx }')
690
691         [[ -n "$evict" ]] && (( $evict >= $before )) ||
692                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
693                     error "no eviction: $evict < before: $before")
694 }
695 run_test 19a "test expired_lock_main on mds (2867)"
696
697 test_19b() {
698         local before=$(date +%s)
699         local evict
700
701         mount_client $DIR2 || error "failed to mount $DIR2: $?"
702
703         # cancel cached locks from MDT to avoid eviction from it
704         cancel_lru_locks mdc
705
706         do_facet client $MULTIOP $DIR/$tfile Ow ||
707                 error "failed to run multiop: $?"
708         drop_ldlm_cancel $MULTIOP $DIR2/$tfile Ow ||
709                 error "failed to ldlm_cancel: $?"
710
711         umount_client $DIR2 || error "failed to unmount $DIR2: $?"
712         do_facet client unlink $DIR/$tfile ||
713                 error "failed to unlink $DIR/$tfile: $?"
714
715         # let the client reconnect
716         client_reconnect
717         evict=$(do_facet client $LCTL get_param osc.$FSNAME-OST*.state |
718                 awk -F"[ [,]" '/EVICTED ]$/ \
719                         { if (mx < $5) {mx = $5;} } END { print mx }')
720
721         [[ -n "$evict" ]] && (( $evict >= $before )) ||
722                 (do_facet client $LCTL get_param osc.$FSNAME-OST*.state;
723                     error "no eviction: $evict < before: $before")
724 }
725 run_test 19b "test expired_lock_main on ost (2867)"
726
727 test_19c() {
728         local BEFORE=`date +%s`
729
730         mount_client $DIR2
731         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0
732
733         mkdir -p $DIR1/$tfile
734         stat $DIR1/$tfile
735
736 #define OBD_FAIL_PTLRPC_CANCEL_RESEND 0x516
737         do_facet mds $LCTL set_param fail_loc=0x80000516
738
739         touch $DIR2/$tfile/file1 &
740         PID1=$!
741         # let touch to get blocked on the server
742         sleep 2
743
744         wait $PID1
745         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1
746         umount_client $DIR2
747
748         # let the client reconnect
749         sleep 5
750         EVICT=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
751           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
752
753         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
754 }
755 run_test 19c "check reconnect and lock resend do not trigger expired_lock_main"
756
757 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
758         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
759
760         mkdir -p $DIR/$tdir
761         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
762         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
763         MULTI_PID=$!
764         cancel_lru_locks osc
765 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
766         do_facet ost1 lctl set_param fail_loc=0x80000308
767         kill -USR1 $MULTI_PID
768         wait $MULTI_PID
769         rc=$?
770         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
771 }
772 run_test 20a "ldlm_handle_enqueue error (should return error)"
773
774 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
775         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
776
777         mkdir -p $DIR/$tdir
778         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
779         cancel_lru_locks osc
780 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
781         do_facet ost1 lctl set_param fail_loc=0x80000308
782         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
783                 error "didn't fail open enqueue" || true
784 }
785 run_test 20b "ldlm_handle_enqueue error (should return error)"
786
787 test_21a() {
788         mkdir_on_mdt0 $DIR/$tdir-1
789         mkdir_on_mdt0 $DIR/$tdir-2
790         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
791         close_pid=$!
792
793         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
794         $MULTIOP $DIR/$tdir-2/f Oc &
795         open_pid=$!
796         sleep 1
797         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
798
799         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
800         kill -USR1 $close_pid
801         cancel_lru_locks mdc
802         wait $close_pid || return 1
803         wait $open_pid || return 2
804         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
805
806         $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
807         $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
808
809         rm -rf $DIR/$tdir-*
810 }
811 run_test 21a "drop close request while close and open are both in flight"
812
813 test_21b() {
814         mkdir_on_mdt0 $DIR/$tdir-1
815         mkdir_on_mdt0 $DIR/$tdir-2
816         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
817         close_pid=$!
818
819         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
820         mcreate $DIR/$tdir-2/f &
821         open_pid=$!
822         sleep 1
823         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
824
825         kill -USR1 $close_pid
826         cancel_lru_locks mdc
827         wait $close_pid || return 1
828         wait $open_pid || return 3
829
830         $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
831         $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
832         rm -rf $DIR/$tdir-*
833 }
834 run_test 21b "drop open request while close and open are both in flight"
835
836 test_21c() {
837         mkdir_on_mdt0 $DIR/$tdir-1
838         mkdir_on_mdt0 $DIR/$tdir-2
839         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
840         close_pid=$!
841
842         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
843         mcreate $DIR/$tdir-2/f &
844         open_pid=$!
845         sleep 3
846         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
847
848         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
849         kill -USR1 $close_pid
850         cancel_lru_locks mdc
851         wait $close_pid || return 1
852         wait $open_pid || return 2
853
854         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
855
856         $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
857         $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
858         rm -rf $DIR/$tdir-*
859 }
860 run_test 21c "drop both request while close and open are both in flight"
861
862 test_21d() {
863         mkdir_on_mdt0 $DIR/$tdir-1
864         mkdir_on_mdt0 $DIR/$tdir-2
865         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
866         pid=$!
867
868         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
869         $MULTIOP $DIR/$tdir-2/f Oc &
870         sleep 1
871         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
872
873         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
874         kill -USR1 $pid
875         cancel_lru_locks mdc
876         wait $pid || return 1
877         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
878
879         $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
880         $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
881
882         rm -rf $DIR/$tdir-*
883 }
884 run_test 21d "drop close reply while close and open are both in flight"
885
886 test_21e() {
887         mkdir_on_mdt0 $DIR/$tdir-1
888         mkdir_on_mdt0 $DIR/$tdir-2
889         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
890         pid=$!
891
892         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
893         touch $DIR/$tdir-2/f &
894         sleep 1
895         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
896
897         kill -USR1 $pid
898         cancel_lru_locks mdc
899         wait $pid || return 1
900
901         sleep $TIMEOUT
902         $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
903         $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
904         rm -rf $DIR/$tdir-*
905 }
906 run_test 21e "drop open reply while close and open are both in flight"
907
908 test_21f() {
909         mkdir_on_mdt0 $DIR/$tdir-1
910         mkdir_on_mdt0 $DIR/$tdir-2
911         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
912         pid=$!
913
914         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
915         touch $DIR/$tdir-2/f &
916         sleep 1
917         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
918
919         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
920         kill -USR1 $pid
921         cancel_lru_locks mdc
922         wait $pid || return 1
923         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
924
925         $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
926         $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
927         rm -rf $DIR/$tdir-*
928 }
929 run_test 21f "drop both reply while close and open are both in flight"
930
931 test_21g() {
932         mkdir_on_mdt0 $DIR/$tdir-1
933         mkdir_on_mdt0 $DIR/$tdir-2
934         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
935         pid=$!
936
937         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
938         touch $DIR/$tdir-2/f &
939         sleep 1
940         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
941
942         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
943         kill -USR1 $pid
944         cancel_lru_locks mdc
945         wait $pid || return 1
946         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
947
948         $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
949         $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
950         rm -rf $DIR/$tdir-*
951 }
952 run_test 21g "drop open reply and close request while close and open are both in flight"
953
954 test_21h() {
955         mkdir_on_mdt0 $DIR/$tdir-1
956         mkdir_on_mdt0 $DIR/$tdir-2
957         multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
958         pid=$!
959
960         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
961         touch $DIR/$tdir-2/f &
962         touch_pid=$!
963         sleep 1
964         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
965
966         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
967         cancel_lru_locks mdc
968         kill -USR1 $pid
969         wait $pid || return 1
970         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
971
972         wait $touch_pid || return 2
973
974         $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
975         $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
976         rm -rf $DIR/$tdir-*
977 }
978 run_test 21h "drop open request and close reply while close and open are both in flight"
979
980 # bug 3462 - multiple MDC requests
981 test_22() {
982         f1=$DIR/${tfile}-1
983         f2=$DIR/${tfile}-2
984
985         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
986         $MULTIOP $f2 Oc &
987         close_pid=$!
988
989         sleep 1
990         $MULTIOP $f1 msu || return 1
991
992         cancel_lru_locks mdc
993         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
994
995         wait $close_pid || return 2
996         rm -rf $f2 || return 4
997 }
998 run_test 22 "drop close request and do mknod"
999
1000 test_23() { #b=4561
1001         multiop_bg_pause $DIR/$tfile O_c || return 1
1002         pid=$!
1003         # give a chance for open
1004         sleep 5
1005
1006         # try the close
1007         drop_request "kill -USR1 $pid"
1008
1009         fail $SINGLEMDS
1010         wait $pid || return 1
1011         return 0
1012 }
1013 run_test 23 "client hang when close a file after mds crash"
1014
1015 test_24a() { # bug 11710 details correct fsync() behavior
1016         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1017
1018         mkdir -p $DIR/$tdir
1019         $LFS setstripe -i 0 -c 1 $DIR/$tdir
1020         cancel_lru_locks osc
1021         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
1022         MULTI_PID=$!
1023         ost_evict_client
1024         kill -USR1 $MULTI_PID
1025         wait $MULTI_PID
1026         rc=$?
1027         lctl set_param fail_loc=0x0
1028         client_reconnect
1029         [ $rc -eq 0 ] &&
1030                 error_ignore bz5494 "multiop didn't fail fsync: rc $rc" || true
1031 }
1032 run_test 24a "fsync error (should return error)"
1033
1034 test_24b() {
1035         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1036
1037         dmesg -c > /dev/null
1038         mkdir -p $DIR/$tdir
1039         lfs setstripe $DIR/$tdir -S 0 -i 0 -c 1 ||
1040                 error "$LFS setstripe failed"
1041         cancel_lru_locks osc
1042         multiop_bg_pause $DIR/$tdir/$tfile-1 Ow8192_yc ||
1043                 error "mulitop Ow8192_yc failed"
1044
1045         MULTI_PID1=$!
1046         multiop_bg_pause $DIR/$tdir/$tfile-2 Ow8192_c ||
1047                 error "mulitop Ow8192_c failed"
1048
1049         MULTI_PID2=$!
1050         ost_evict_client
1051
1052         kill -USR1 $MULTI_PID1
1053         wait $MULTI_PID1
1054         rc1=$?
1055         kill -USR1 $MULTI_PID2
1056         wait $MULTI_PID2
1057         rc2=$?
1058         lctl set_param fail_loc=0x0
1059         client_reconnect
1060         [ $rc1 -eq 0 -o $rc2 -eq 0 ] &&
1061         error_ignore bz5494 "multiop didn't fail fsync: $rc1 or close: $rc2" ||
1062                 true
1063
1064         dmesg | grep "dirty page discard:" ||
1065                 error "no discarded dirty page found!"
1066 }
1067 run_test 24b "test dirty page discard due to client eviction"
1068
1069 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
1070 # this test can only run from a client on a separate node.
1071         remote_ost || { skip "local OST" && return 0; }
1072         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1073         remote_mds || { skip "local MDS" && return 0; }
1074
1075         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
1076                 skip "msg and ost1 are at the same node"
1077                 return 0
1078         fi
1079
1080         check_timeout || return 1
1081
1082         # make sure all imports are connected and not IDLE
1083         do_facet client lfs df > /dev/null
1084         # make sure client will not be discarded by server due to LU-14708
1085         $LFS setstripe -c -1 -S 64K $MOUNT/$tfile
1086         dd if=/dev/zero of=$MOUNT/$tfile bs=64K count=$OSTCOUNT oflag=sync ||
1087                 error "dd failed"
1088         sync; sleep 5; sync
1089
1090 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
1091         do_facet client lctl set_param fail_loc=0x505
1092         local before=$(date +%s)
1093         local rc=0
1094
1095         # evictor takes PING_EVICT_TIMEOUT to evict.
1096         # But if there's a race to start the evictor from various obds,
1097         # the loser might have to wait for the next ping.
1098         sleep $((TIMEOUT * 2))
1099         do_facet client lctl set_param fail_loc=0x0
1100         do_facet client lfs df > /dev/null
1101
1102         local oscs=$(lctl dl | awk '/-osc-/ {print $4}')
1103         check_clients_evicted "$before ${oscs[@]}"
1104         check_clients_full 10 "${oscs[@]}"
1105 }
1106 run_test 26a "evict dead exports"
1107
1108 wait_client_evicted () {
1109         local facet=$1
1110         local exports=$2
1111         local timeout=$3
1112         local varsvc=${facet}_svc
1113
1114         wait_update_cond $(facet_active_host $facet) \
1115                 "lctl get_param -n *.${!varsvc}.num_exports | cut -d' ' -f2" \
1116                 "-le" $((exports - 1)) $timeout
1117 }
1118
1119 test_26b() {      # bug 10140 - evict dead exports by pinger
1120         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1121
1122         [[ $(facet_host mgs) != $(facet_host ost1) ]] ||
1123                 skip "msg and ost1 are at the same node"
1124
1125         check_timeout || return 1
1126         clients_up
1127         zconf_mount $HOSTNAME $MOUNT2 ||
1128                 { error "Failed to mount $MOUNT2"; return 2; }
1129         # make sure all imports are connected and not IDLE
1130         do_facet client $LFS df > /dev/null
1131         $LFS setstripe -c -1 $MOUNT/$tfile
1132
1133         local mds_nexp=$(do_facet mds1 \
1134                 lctl get_param -n mdt.${mds1_svc}.num_exports)
1135         local ost_nexp=$(do_facet ost1 \
1136                 lctl get_param -n obdfilter.${ost1_svc}.num_exports)
1137         # must be equal on all the nodes
1138         local INTERVAL=$(do_facet $SINGLEMDS lctl get_param -n ping_interval)
1139         local AT_MAX_SAVED=$(at_max_get mds1)
1140
1141         at_max_set $TIMEOUT mds1
1142         at_max_set $TIMEOUT ost1
1143         stack_trap "at_max_set $AT_MAX_SAVED mds1" EXIT
1144         stack_trap "at_max_set $AT_MAX_SAVED ost1" EXIT
1145
1146         echo "starting with '$ost_nexp' OST and '$mds_nexp' MDS exports"
1147
1148         zconf_umount $HOSTNAME $MOUNT2 -f
1149
1150         # see ptlrpc_export_timeout() for the pinger case; take a bit more the test sake
1151         local TOUT=$((INTERVAL * 2 + (TIMEOUT / 20 + 5 + TIMEOUT) * 3))
1152         TOUT=$((TOUT + (TOUT >> 3)))
1153         echo i $INTERVAL m $AT_MAX_SAVED t $TIMEOUT $TOUT
1154         wait_client_evicted ost1 $ost_nexp $TOUT ||
1155                 error "Client was not evicted by OSS"
1156         wait_client_evicted mds1 $mds_nexp $TOUT ||
1157                 error "Client was not evicted by MDS"
1158 }
1159 run_test 26b "evict dead exports"
1160
1161 test_27() {
1162         mkdir_on_mdt0 $DIR/$tdir
1163         writemany -q -a $DIR/$tdir/$tfile 0 5 &
1164         CLIENT_PID=$!
1165         sleep 1
1166         local save_FAILURE_MODE=$FAILURE_MODE
1167         FAILURE_MODE="SOFT"
1168         facet_failover $SINGLEMDS
1169 #define OBD_FAIL_OSC_SHUTDOWN            0x407
1170         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000407
1171         # need to wait for reconnect
1172         echo waiting for fail_loc
1173         wait_update_facet $SINGLEMDS "lctl get_param -n fail_loc" "-2147482617"
1174         facet_failover $SINGLEMDS
1175         #no crashes allowed!
1176         kill -USR1 $CLIENT_PID
1177         wait $CLIENT_PID
1178         true
1179         FAILURE_MODE=$save_FAILURE_MODE
1180 }
1181 run_test 27 "fail LOV while using OSC's"
1182
1183 test_28() {      # bug 6086 - error adding new clients
1184         do_facet client mcreate $DIR/$tfile       || return 1
1185         drop_bl_callback_once "chmod 0777 $DIR/$tfile" ||
1186                 echo "evicted as expected"
1187         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
1188         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012f"
1189         # fail once (evicted), reconnect fail (fail_loc), ok
1190         client_up || (sleep 10; client_up) || (sleep 10; client_up) || error "reconnect failed"
1191         rm -f $DIR/$tfile
1192         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
1193 }
1194 run_test 28 "handle error adding new clients (bug 6086)"
1195
1196 test_29a() { # bug 22273 - error adding new clients
1197         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
1198         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000711"
1199         # fail abort so client will be new again
1200         fail_abort $SINGLEMDS
1201         client_up || error "reconnect failed"
1202         wait_osc_import_state $SINGLEMDS ost FULL
1203         return 0
1204 }
1205 run_test 29a "error adding new clients doesn't cause LBUG (bug 22273)"
1206
1207 test_29b() { # bug 22273 - error adding new clients
1208         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
1209         do_facet ost1 "lctl set_param fail_loc=0x80000711"
1210         # fail abort so client will be new again
1211         fail_abort ost1
1212         client_up || error "reconnect failed"
1213         return 0
1214 }
1215 run_test 29b "error adding new clients doesn't cause LBUG (bug 22273)"
1216
1217 test_50() {
1218         mkdir -p $DIR/$tdir
1219         # put a load of file creates/writes/deletes
1220         writemany -q $DIR/$tdir/$tfile 0 5 &
1221         CLIENT_PID=$!
1222         echo writemany pid $CLIENT_PID
1223         sleep 10
1224         FAILURE_MODE="SOFT"
1225         fail $SINGLEMDS
1226         # wait for client to reconnect to MDS
1227         sleep 60
1228         fail $SINGLEMDS
1229         sleep 60
1230         fail $SINGLEMDS
1231         # client process should see no problems even though MDS went down
1232         sleep $TIMEOUT
1233         kill -USR1 $CLIENT_PID
1234         wait $CLIENT_PID
1235         rc=$?
1236         echo writemany returned $rc
1237         #these may fail because of eviction due to slow AST response.
1238         [ $rc -eq 0 ] ||
1239                 error_ignore bz13652 "writemany returned rc $rc" || true
1240 }
1241 run_test 50 "failover MDS under load"
1242
1243 test_51() {
1244         #define OBD_FAIL_MDS_SYNC_CAPA_SL                    0x1310
1245         do_facet ost1 lctl set_param fail_loc=0x00001310
1246
1247         mkdir_on_mdt0 $DIR/$tdir
1248         # put a load of file creates/writes/deletes
1249         writemany -q $DIR/$tdir/$tfile 0 5 &
1250         CLIENT_PID=$!
1251         sleep 1
1252         FAILURE_MODE="SOFT"
1253         facet_failover $SINGLEMDS
1254         # failover at various points during recovery
1255         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
1256         echo will failover at $SEQ
1257         for i in $SEQ; do
1258                 #echo failover in $i sec
1259                 log "$TESTNAME: failover in $i sec"
1260                 sleep $i
1261                 facet_failover $SINGLEMDS
1262         done
1263         # client process should see no problems even though MDS went down
1264         # and recovery was interrupted
1265         sleep $TIMEOUT
1266         kill -USR1 $CLIENT_PID
1267         wait $CLIENT_PID
1268         rc=$?
1269         echo writemany returned $rc
1270         [ $rc -eq 0 ] ||
1271                 error_ignore bz13652 "writemany returned rc $rc" || true
1272 }
1273 run_test 51 "failover MDS during recovery"
1274
1275 test_52_guts() {
1276         do_facet client "mkdir -p $DIR/$tdir"
1277         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
1278         CLIENT_PID=$!
1279         echo writemany pid $CLIENT_PID
1280         sleep 10
1281         FAILURE_MODE="SOFT"
1282         fail ost1
1283         rc=0
1284         wait $CLIENT_PID || rc=$?
1285         # active client process should see an EIO for down OST
1286         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
1287         # but timing or failover setup may allow success
1288         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
1289         echo "writemany returned $rc"
1290         return $rc
1291 }
1292
1293 test_52() {
1294         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1295
1296         mkdir -p $DIR/$tdir
1297         test_52_guts
1298         rc=$?
1299         [ $rc -ne 0 ] && { return $rc; }
1300         # wait for client to reconnect to OST
1301         sleep 30
1302         test_52_guts
1303         rc=$?
1304         [ $rc -ne 0 ] && { return $rc; }
1305         sleep 30
1306         test_52_guts
1307         rc=$?
1308         client_reconnect
1309         #return $rc
1310 }
1311 run_test 52 "failover OST under load"
1312
1313 # test of open reconstruct
1314 test_53a() {
1315         touch $DIR/$tfile
1316         drop_mdt_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
1317                 return 2
1318 }
1319 run_test 53a "touch: drop rep"
1320
1321 test_53b() {
1322         touch $DIR/$tfile
1323         sync
1324         drop_mdt_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||
1325                 return 2
1326 }
1327 run_test 53b "touch: drop rep"
1328
1329 test_53c() {
1330         rm -rf $DIR/$tfile
1331         sync
1332         drop_mdt_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||
1333                 return 2
1334 }
1335 run_test 53c "touch: drop rep"
1336
1337 test_54() {
1338         zconf_mount $(hostname) $MOUNT2
1339         touch $DIR/$tfile
1340         touch $DIR2/$tfile.1
1341         sleep 10
1342         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
1343         fail $SINGLEMDS
1344         umount $MOUNT2
1345         ERROR=$(dmesg | egrep "(test 54|went back in time)" | tail -n1 |
1346                 grep "went back in time")
1347         [ x"$ERROR" == x ] || error "back in time occured"
1348 }
1349 run_test 54 "back in time"
1350
1351 # bug 11330 - liblustre application death during I/O locks up OST
1352 test_55() {
1353         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1354
1355         mkdir -p $DIR/$tdir
1356
1357         # This test assumes relatively small max_dirty_mb setting
1358         # which we want to walk away from, so just for it we will
1359         # temporarily lower the value
1360         local max_dirty_mb=$(lctl get_param -n osc.*.max_dirty_mb | head -n 1)
1361         lctl set_param -n osc.*.max_dirty_mb=32
1362         stack_trap "lctl set_param osc.*.max_dirty_mb=$max_dirty_mb" EXIT
1363
1364         # Minimum pass speed is 2MBps
1365         local ddtimeout=64
1366         # LU-2887/LU-3089 - set min pass speed to 500KBps
1367         [ "$ost1_FSTYPE" = zfs ] && ddtimeout=256
1368
1369         # first dd should be finished quickly
1370         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-1
1371         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4 &
1372         DDPID=$!
1373         count=0
1374         echo  "step1: testing ......"
1375         while kill -0 $DDPID 2> /dev/null; do
1376                 let count++
1377                 if [ $count -gt $ddtimeout ]; then
1378                         error "dd should be finished!"
1379                 fi
1380                 sleep 1
1381         done
1382         echo "(dd_pid=$DDPID, time=$count)successful"
1383
1384         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-2
1385         #define OBD_FAIL_OST_DROP_REQ            0x21d
1386         do_facet ost1 lctl set_param fail_loc=0x0000021d
1387         # second dd will be never finished
1388         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4 &
1389         DDPID=$!
1390         count=0
1391         echo  "step2: testing ......"
1392         while [ $count -le $ddtimeout ]; do
1393                 if ! kill -0 $DDPID 2> /dev/null; then
1394                         ls -l $DIR/$tdir
1395                         error "dd shouldn't be finished! (time=$count)"
1396                 fi
1397                 let count++
1398                 sleep 1
1399         done
1400         echo "(dd_pid=$DDPID, time=$count)successful"
1401
1402         #Recover fail_loc and dd will finish soon
1403         do_facet ost1 lctl set_param fail_loc=0
1404         count=0
1405         echo  "step3: testing ......"
1406         while kill -0 $DDPID 2> /dev/null; do
1407                 let count++
1408                 if [ $count -gt $((ddtimeout + 440)) ]; then
1409                         error "dd should be finished!"
1410                 fi
1411                 sleep 1
1412         done
1413         echo "(dd_pid=$DDPID, time=$count)successful"
1414
1415         rm -rf $DIR/$tdir
1416 }
1417 run_test 55 "ost_brw_read/write drops timed-out read/write request"
1418
1419 test_56() { # b=11277
1420 #define OBD_FAIL_MDS_RESEND      0x136
1421         touch $DIR/$tfile
1422         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000136"
1423         stat $DIR/$tfile || error "stat failed"
1424         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1425         rm -f $DIR/$tfile
1426 }
1427 run_test 56 "do not fail on getattr resend"
1428
1429 test_57_helper() {
1430         # no oscs means no client or mdt
1431         while lctl get_param osc.*.* > /dev/null 2>&1; do
1432                 : # loop until proc file is removed
1433         done
1434 }
1435
1436 test_57() { # bug 10866
1437         test_57_helper &
1438         pid=$!
1439         sleep 1
1440 #define OBD_FAIL_LPROC_REMOVE            0xB00
1441         lctl set_param fail_loc=0x80000B00
1442         zconf_umount `hostname` $DIR
1443         lctl set_param fail_loc=0x80000B00
1444         fail_abort $SINGLEMDS
1445         kill -9 $pid
1446         lctl set_param fail_loc=0
1447         mount_client $DIR
1448         do_facet client "df $DIR"
1449         }
1450 run_test 57 "read procfs entries causes kernel crash"
1451
1452 test_58() { # bug 11546
1453 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
1454         touch $DIR/$tfile
1455         ls -la $DIR/$tfile
1456         lctl set_param fail_loc=0x80000801
1457         cp $DIR/$tfile /dev/null &
1458         pid=$!
1459         sleep 1
1460         lctl set_param fail_loc=0
1461         drop_bl_callback_once rm -f $DIR/$tfile
1462         wait $pid
1463         # the first 'df' could tigger the eviction caused by
1464         # 'drop_bl_callback_once', and it's normal case.
1465         # but the next 'df' should return successfully.
1466         do_facet client "df $DIR" || do_facet client "df $DIR"
1467 }
1468 run_test 58 "Eviction in the middle of open RPC reply processing"
1469
1470 test_59() { # bug 10589
1471         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
1472         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
1473 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
1474         lctl set_param fail_loc=0x311
1475         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
1476         [ $? = 0 ] || error "dd write failed"
1477         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
1478         lctl set_param fail_loc=0
1479         sync
1480         zconf_umount `hostname` $MOUNT2 -f
1481         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
1482         [ $? = 0 ] || error "dd read failed"
1483         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
1484         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
1485 }
1486 run_test 59 "Read cancel race on client eviction"
1487
1488 test_60() {
1489         local num_files=${COUNT:-5000}
1490         test_mkdir $DIR/$tdir
1491
1492         # Register (and start) changelog
1493         changelog_register || error "changelog_register failed"
1494
1495         # Generate a large number of changelog entries
1496         createmany -o $DIR/$tdir/$tfile $num_files
1497         sync
1498         sleep 5
1499
1500         # Unlink files in the background
1501         unlinkmany $DIR/$tdir/$tfile $num_files &
1502         local client_pid=$!
1503         sleep 1
1504
1505         # Failover the MDS while unlinks are happening
1506         facet_failover $SINGLEMDS
1507
1508         # Wait for unlinkmany to finish
1509         wait $client_pid
1510
1511         # Check if all the create/unlink events were recorded
1512         # in the changelog
1513         local cl_count=$(changelog_dump | grep -c UNLNK)
1514         echo "$cl_count unlinks in changelog"
1515
1516         changelog_deregister || error "changelog_deregister failed"
1517         if ! changelog_users $SINGLEMDS | grep -q "^cl"; then
1518                 [ $cl_count -eq $num_files ] ||
1519                         error "Recorded $cl_count of $num_files unlinks"
1520                 # Also make sure we can clear large changelogs
1521                 cl_count=$(changelog_dump | wc -l)
1522                 [ $cl_count -le 2 ] ||
1523                         error "Changelog not empty: $cl_count entries"
1524         else # If other users, there may be other unlinks in the log
1525                 [ $cl_count -ge $num_files ] ||
1526                         error "Recorded $cl_count of $num_files unlinks"
1527                 changelog_users $SINGLEMDS
1528                 echo "other changelog users; can't verify clear"
1529         fi
1530 }
1531 run_test 60 "Add Changelog entries during MDS failover"
1532
1533 test_61()
1534 {
1535         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1536         mdtosc=${mdtosc/-MDT*/-MDT\*}
1537         local cflags="osc.$mdtosc.connect_flags"
1538         do_facet $SINGLEMDS "lctl get_param -n $cflags" |grep -q skip_orphan
1539         [ $? -ne 0 ] && skip "don't have skip orphan feature" && return
1540
1541         mkdir_on_mdt0 $DIR/$tdir || error "mkdir dir $DIR/$tdir failed"
1542         # Set the default stripe of $DIR/$tdir to put the files to ost1
1543         $LFS setstripe -c 1 -i 0 $DIR/$tdir
1544
1545         replay_barrier $SINGLEMDS
1546         createmany -o $DIR/$tdir/$tfile-%d 10
1547         local oid=$(do_facet ost1 "lctl get_param -n \
1548                 obdfilter.${ost1_svc}.last_id" | sed -e 's/.*://')
1549
1550         fail_abort $SINGLEMDS
1551
1552         touch $DIR/$tdir/$tfile
1553         local id=$($LFS getstripe $DIR/$tdir/$tfile |
1554                 awk '$1 == 0 { print $2 }')
1555         [ $id -le $oid ] && error "the orphan objid was reused, failed"
1556
1557         # Cleanup
1558         rm -rf $DIR/$tdir
1559 }
1560 run_test 61 "Verify to not reuse orphan objects - bug 17025"
1561
1562 # test_62 as seen it b2_1 please do not reuse test_62
1563 #test_62()
1564 #{
1565 #       zconf_umount `hostname` $DIR
1566 #       #define OBD_FAIL_PTLRPC_DELAY_IMP_FULL   0x516
1567 #       lctl set_param fail_loc=0x516
1568 #       mount_client $DIR
1569 #}
1570 #run_test 62 "Verify connection flags race - bug LU-1716"
1571
1572 test_65() {
1573         mount_client $DIR2
1574
1575         #grant lock1, export2
1576         $LFS setstripe -i -0 $DIR2/$tfile || error "setstripe failed"
1577         $MULTIOP $DIR2/$tfile Ow  || error "multiop failed"
1578
1579 #define OBD_FAIL_LDLM_BL_EVICT            0x31e
1580         do_facet ost $LCTL set_param fail_loc=0x31e
1581         #get waiting lock2, export1
1582         $MULTIOP $DIR/$tfile Ow &
1583         PID1=$!
1584         # let enqueue to get asleep
1585         sleep 2
1586
1587         #get lock2 blocked
1588         $MULTIOP $DIR2/$tfile Ow &
1589         PID2=$!
1590         sleep 2
1591
1592         #evict export1
1593         ost_evict_client
1594
1595         sleep 2
1596         do_facet ost $LCTL set_param fail_loc=0
1597
1598         wait $PID1
1599         wait $PID2
1600
1601         umount_client $DIR2
1602 }
1603 run_test 65 "lock enqueue for destroyed export"
1604
1605 test_66()
1606 {
1607         [[ "$MDS1_VERSION" -ge $(version_code 2.7.51) ]] ||
1608                 skip "Need MDS version at least 2.7.51"
1609
1610         # modify dir so that next revalidate would not obtain UPDATE lock
1611         touch $DIR
1612
1613         # drop 1 reply with UPDATE lock
1614         mcreate $DIR/$tfile || error "mcreate failed: $?"
1615         drop_mdt_ldlm_reply_once "stat $DIR/$tfile" &
1616         sleep 2
1617
1618         # make the re-sent lock to sleep
1619 #define OBD_FAIL_MDS_RESEND              0x136
1620         do_nodes $(osts_nodes) $LCTL set_param fail_loc=0x80000136
1621
1622         #initiate the re-connect & re-send
1623         local mdtname="MDT0000"
1624         local mdccli=$($LCTL dl | grep "${mdtname}-mdc" | awk '{print $4;}')
1625         local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.conn_uuid)
1626         $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}"
1627         sleep 2
1628
1629         #initiate the client eviction while enqueue re-send is in progress
1630         mds_evict_client
1631
1632         client_reconnect
1633         wait
1634 }
1635 run_test 66 "lock enqueue re-send vs client eviction"
1636
1637 test_67()
1638 {
1639 #define OBD_FAIL_PTLRPC_CONNECT_RACE     0x531
1640         $LCTL set_param fail_loc=0x80000531
1641
1642         local mdtname="MDT0000"
1643         local mdccli=$($LCTL dl | grep "${mdtname}-mdc" | awk '{print $4;}')
1644         local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.mds_conn_uuid)
1645         $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}" &
1646         sleep 2
1647
1648         mds_evict_client
1649         sleep 1
1650
1651         client_reconnect
1652         wait
1653 }
1654 run_test 67 "connect vs import invalidate race"
1655
1656 check_cli_ir_state()
1657 {
1658         local NODE=${1:-$HOSTNAME}
1659         local st
1660         st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
1661                             awk '/imperative_recovery:/ { print \\\$2}'")
1662         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1663                 error "Error state $st, must be ENABLED or DISABLED"
1664         echo -n $st
1665 }
1666
1667 check_target_ir_state()
1668 {
1669         local target=${1}
1670         local name=${target}_svc
1671         local recovery_proc=obdfilter.${!name}.recovery_status
1672         local st
1673
1674         while : ; do
1675                 st=$(do_facet $target "$LCTL get_param -n $recovery_proc |
1676                         awk '/status:/{ print \\\$2}'")
1677                 [ x$st = xRECOVERING ] || break
1678         done
1679         st=$(do_facet $target "lctl get_param -n $recovery_proc |
1680                 awk '/IR:/{ print \\\$2}'")
1681         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1682                 error "Error state $st, must be ENABLED or DISABLED"
1683         echo -n $st
1684 }
1685
1686 set_ir_status()
1687 {
1688         do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
1689 }
1690
1691 get_ir_status()
1692 {
1693         local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1694                 awk '/state:/{ print \\\$2 }'")
1695         echo -n ${state/,/}
1696 }
1697
1698 nidtbl_version_mgs()
1699 {
1700         local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1701                 awk '/nidtbl_version:/{ print \\\$2 }'")
1702         echo -n $ver
1703 }
1704
1705 # nidtbl_version_client <mds1|client> [node]
1706 nidtbl_version_client()
1707 {
1708         local cli=$1
1709         local node=${2:-$HOSTNAME}
1710
1711         if [ X$cli = Xclient ]; then
1712                 cli=$FSNAME-client
1713         else
1714                 local obdtype=${cli/%[0-9]*/}
1715                 [ $obdtype != mds ] && error "wrong parameters $cli"
1716
1717                 node=$(facet_active_host $cli)
1718                 local t=${cli}_svc
1719                 cli=${!t}
1720         fi
1721
1722         local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
1723                 awk "/$cli/{print \$6}" |sort -u)
1724
1725         # in case there are multiple mounts on the client node
1726         local arr=($vers)
1727         [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
1728         echo -n $vers
1729 }
1730
1731 nidtbl_versions_match()
1732 {
1733         [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
1734 }
1735
1736 target_instance_match()
1737 {
1738         local srv=$1
1739         local obdtype
1740         local cliname
1741
1742         obdtype=${srv/%[0-9]*/}
1743         case $obdtype in
1744         mds)
1745                 obdname="mdt"
1746                 cliname="mdc"
1747                 ;;
1748         ost)
1749                 obdname="obdfilter"
1750                 cliname="osc"
1751                 ;;
1752         *)
1753                 error "invalid target type" $srv
1754                 return 1
1755                 ;;
1756         esac
1757
1758         local target=${srv}_svc
1759         local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
1760         local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import |
1761                 awk '/instance/{ print $2 }' | head -n1)
1762
1763         return $([ $si -eq $ci ])
1764 }
1765
1766 test_100()
1767 {
1768         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1769                 { skip "MGS without IR support"; return 0; }
1770
1771         # MDT was just restarted in the previous test, make sure everything
1772         # is all set.
1773         local cnt=30
1774         while [ $cnt -gt 0 ]; do
1775                 nidtbl_versions_match && break
1776                 sleep 1
1777                 cnt=$((cnt - 1))
1778         done
1779
1780         # disable IR
1781         set_ir_status disabled
1782
1783         local prev_ver=$(nidtbl_version_client client)
1784
1785         local saved_FAILURE_MODE=$FAILURE_MODE
1786         [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
1787         fail ost1
1788
1789         # valid check
1790         [ $(nidtbl_version_client client) -eq $prev_ver ] ||
1791                 error "version must not change due to IR disabled"
1792         target_instance_match ost1 || error "instance mismatch"
1793
1794         # restore env
1795         set_ir_status full
1796         FAILURE_MODE=$saved_FAILURE_MODE
1797 }
1798 run_test 100 "IR: Make sure normal recovery still works w/o IR"
1799
1800 test_101a()
1801 {
1802         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1803                 skip "MGS without IR support"
1804
1805         set_ir_status full
1806
1807         local ost1_imp=$(get_osc_import_name client ost1)
1808
1809         # disable pinger recovery
1810         lctl set_param -n osc.$ost1_imp.pinger_recov=0
1811         stack_trap "$LCTL set_param -n osc.$ost1_imp.pinger_recov=1" EXIT
1812
1813         fail ost1
1814
1815         target_instance_match ost1 || error "instance mismatch"
1816         nidtbl_versions_match || error "version must match"
1817 }
1818 run_test 101a "IR: Make sure IR works w/o normal recovery"
1819
1820 test_101b()
1821 {
1822         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1823                 skip "MGS without IR support"
1824
1825         set_ir_status full
1826
1827         local ost1_imp=$(get_osc_import_name client ost1)
1828
1829 #define OBD_FAIL_OST_PREPARE_DELAY       0x247
1830         do_facet ost1 "$LCTL set_param fail_loc=0x247"
1831         # disable pinger recovery
1832         $LCTL set_param -n osc.$ost1_imp.pinger_recov=0
1833         stack_trap "$LCTL set_param -n osc.$ost1_imp.pinger_recov=1" EXIT
1834
1835 #OST may return EAGAIN if it is not configured yet
1836         fail ost1
1837 }
1838 run_test 101b "IR: Make sure IR works w/o normal recovery and proceed EAGAIN"
1839
1840 test_102()
1841 {
1842         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1843                 { skip "MGS without IR support"; return 0; }
1844
1845         local clients=${CLIENTS:-$HOSTNAME}
1846         local old_version
1847         local new_version
1848         local mgsdev=mgs
1849
1850         set_ir_status full
1851
1852         # let's have a new nidtbl version
1853         fail ost1
1854
1855         # sleep for a while so that clients can see the failure of ost
1856         # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
1857         # int mgc_request.c:
1858         # define MGC_TIMEOUT_MIN_SECONDS   5
1859         # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
1860         local count=30  # 20 seconds at most
1861         while [ $count -gt 0 ]; do
1862                 nidtbl_versions_match && break
1863                 sleep 1
1864                 count=$((count-1))
1865         done
1866
1867         nidtbl_versions_match || error "nidtbl mismatch"
1868
1869         # get the version #
1870         old_version=$(nidtbl_version_client client)
1871
1872         zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
1873
1874         # restart mgs
1875         combined_mgs_mds && mgsdev=mds1
1876         remount_facet $mgsdev
1877         fail ost1
1878
1879         zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
1880
1881         # check new version
1882         new_version=$(nidtbl_version_client client)
1883         [ $new_version -lt $old_version ] &&
1884                 error "nidtbl version wrong after mgs restarts"
1885         return 0
1886 }
1887 run_test 102 "IR: New client gets updated nidtbl after MGS restart"
1888
1889 test_103()
1890 {
1891         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1892                 { skip "MGS without IR support"; return 0; }
1893
1894         combined_mgs_mds && skip "needs separate mgs and mds" && return 0
1895
1896         # workaround solution to generate config log on the mds
1897         remount_facet mds1
1898
1899         stop mgs
1900         stop mds1
1901
1902         # We need this test because mds is like a client in IR context.
1903         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS ||
1904                 error "MDS should start w/o mgs"
1905
1906         # start mgs and remount mds w/ ir
1907         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
1908         clients_up
1909
1910         # remount client so that fsdb will be created on the MGS
1911         umount_client $MOUNT || error "umount failed"
1912         mount_client $MOUNT || error "mount failed"
1913
1914         # sleep 30 seconds so the MDS has a chance to detect MGS restarting
1915         local count=30
1916         while [ $count -gt 0 ]; do
1917                 [ $(nidtbl_version_client mds1) -ne 0 ] && break
1918                 sleep 1
1919                 count=$((count-1))
1920         done
1921
1922         # after a while, mds should be able to reconnect to mgs and fetch
1923         # up-to-date nidtbl version
1924         nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
1925
1926         # reset everything
1927         set_ir_status full
1928 }
1929 run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
1930
1931 test_104()
1932 {
1933         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1934                 { skip "MGS without IR support"; return 0; }
1935
1936         set_ir_status full
1937
1938         stop ost1
1939         start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
1940                 error "OST1 cannot start"
1941         clients_up
1942
1943         local ir_state=$(check_target_ir_state ost1)
1944
1945         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1946                 error "ir status on ost1 should be DISABLED"
1947 }
1948 run_test 104 "IR: ost can disable IR voluntarily"
1949
1950 test_105()
1951 {
1952         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
1953         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1954                 { skip "MGS without IR support"; return 0; }
1955
1956         set_ir_status full
1957
1958         # get one of the clients from client list
1959         local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
1960
1961         local mount_opts=${MOUNT_OPTS:+$MOUNT_OPTS,}noir
1962         zconf_umount $rcli $MOUNT || error "umount failed"
1963         zconf_mount $rcli $MOUNT $mount_opts || error "mount failed"
1964
1965         # make sure lustre mount at $rcli disabling IR
1966         local ir_state=$(check_cli_ir_state $rcli)
1967         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1968                 error "IR state must be DISABLED at $rcli"
1969
1970         # Since the client just mounted, its last_rcvd entry is not on disk.
1971         # Send an RPC so exp_need_sync forces last_rcvd to commit this export
1972         # so the client can reconnect during OST recovery (LU-924, LU-1582)
1973         $LFS setstripe -i 0 $DIR/$tfile
1974         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=sync
1975
1976         # make sure MGS's state is Partial
1977         [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
1978
1979         fail ost1
1980         # make sure IR on ost1 is DISABLED
1981         local ir_state=$(check_target_ir_state ost1)
1982         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1983                 error "IR status on ost1 should be DISABLED"
1984
1985         # remount with the default MOUNT_OPTS
1986         zconf_umount $rcli $MOUNT || error "umount failed"
1987         zconf_mount $rcli $MOUNT || error "mount failed"
1988
1989         # make sure MGS's state is full
1990         [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
1991
1992         fail ost1
1993         # make sure IR on ost1 is ENABLED
1994         local ir_state=$(check_target_ir_state ost1)
1995         [ $ir_state = "ENABLED" -o $ir_state = "ON" ] ||
1996                 error "IR status on ost1 should be ENABLED"
1997
1998         return 0
1999 }
2000 run_test 105 "IR: NON IR clients support"
2001
2002 cleanup_106() {
2003         trap 0
2004         umount_client $DIR2
2005         debugrestore
2006 }
2007
2008 test_106() { # LU-1789
2009         [[ "$MDS1_VERSION" -ge $(version_code 2.3.50) ]] ||
2010                 skip "Need MDS version at least 2.3.50"
2011
2012 #define OBD_FAIL_MDC_LIGHTWEIGHT         0x805
2013         $LCTL set_param fail_loc=0x805
2014
2015         debugsave
2016         trap cleanup_106 EXIT
2017
2018         # enable lightweight flag on mdc connection
2019         mount_client $DIR2
2020
2021         local MDS_NEXP=$(do_facet $SINGLEMDS \
2022                          lctl get_param -n mdt.${mds1_svc}.num_exports |
2023                          cut -d' ' -f2)
2024         $LCTL set_param fail_loc=0
2025
2026         touch $DIR2/$tfile || error "failed to create empty file"
2027         replay_barrier $SINGLEMDS
2028
2029         $LCTL set_param debug=ha
2030         $LCTL clear
2031         facet_failover $SINGLEMDS
2032
2033         # lightweight goes through LUSTRE_IMP_RECOVER during failover
2034         touch -c $DIR2/$tfile || true
2035         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2036         recovered=$(awk '/MDT0000-mdc-[0-9a-f]*. lwp recover/ { print }' \
2037                     $TMP/lustre-log-$TESTNAME.log)
2038         [ -z "$recovered" ] && error "lightweight client was not recovered"
2039
2040         # and all operations performed by lightweight client should be
2041         # synchronous, so the file created before mds restart should be there
2042         $CHECKSTAT -t file $DIR/$tfile || error "file not present"
2043         rm -f $DIR/$tfile
2044
2045         cleanup_106
2046 }
2047 run_test 106 "lightweight connection support"
2048
2049 test_107 () {
2050         local CLIENT_PID
2051         local close_pid
2052
2053         mkdir_on_mdt0 $DIR/$tdir
2054         # OBD_FAIL_MDS_REINT_NET_REP   0x119
2055         do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2056         multiop $DIR/$tdir D_c &
2057         close_pid=$!
2058         mkdir $DIR/$tdir/dir_106 &
2059         CLIENT_PID=$!
2060         do_facet $SINGLEMDS lctl set_param fail_loc=0
2061         fail $SINGLEMDS
2062
2063         wait $CLIENT_PID || rc=$?
2064         checkstat -t dir $DIR/$tdir/dir_106 || return 1
2065
2066         kill -USR1 $close_pid
2067         wait $close_pid || return 2
2068
2069         return $rc
2070 }
2071 run_test 107 "drop reint reply, then restart MDT"
2072
2073 test_108() {
2074         mkdir -p $DIR/$tdir
2075         $LFS setstripe -c 1 -i 0 $DIR/$tdir
2076
2077         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=256 &
2078         local dd_pid=$!
2079         sleep 0.1
2080
2081         ost_evict_client
2082
2083         wait $dd_pid
2084
2085         client_up || error "reconnect failed"
2086         rm -f $DIR/$tdir/$tfile
2087 }
2088 run_test 108 "client eviction don't crash"
2089
2090 test_110a () {
2091         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2092         local remote_dir=$DIR/$tdir/remote_dir
2093         local mdtidx=1
2094         local num
2095
2096         #prepare for 110 test, which need set striped dir on remote MDT.
2097         for num in $(seq $MDSCOUNT); do
2098                 do_facet mds$num \
2099                         lctl set_param -n mdt.$FSNAME*.enable_remote_dir=1 \
2100                                 2>/dev/null
2101         done
2102
2103         mkdir_on_mdt0 $DIR/$tdir
2104         drop_request "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2105                 error "lfs mkdir failed"
2106         local diridx=$($LFS getstripe -m $remote_dir)
2107         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2108
2109         rm -rf $DIR/$tdir || error "rmdir failed"
2110 }
2111 run_test 110a "create remote directory: drop client req"
2112
2113 test_110b () {
2114         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2115         local remote_dir=$DIR/$tdir/remote_dir
2116         local mdtidx=1
2117
2118         mkdir_on_mdt0 $DIR/$tdir
2119         drop_reint_reply "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2120                 error "lfs mkdir failed"
2121
2122         diridx=$($LFS getstripe -m $remote_dir)
2123         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2124
2125         rm -rf $DIR/$tdir || error "rmdir failed"
2126 }
2127 run_test 110b "create remote directory: drop Master rep"
2128
2129 test_110c () {
2130         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2131         local remote_dir=$DIR/$tdir/remote_dir
2132         local mdtidx=1
2133
2134         mkdir_on_mdt0 $DIR/$tdir
2135         drop_update_reply $mdtidx "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2136                 error "lfs mkdir failed"
2137
2138         diridx=$($LFS getstripe -m $remote_dir)
2139         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2140
2141         rm -rf $DIR/$tdir || error "rmdir failed"
2142 }
2143 run_test 110c "create remote directory: drop update rep on slave MDT"
2144
2145 test_110d () {
2146         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2147         local remote_dir=$DIR/$tdir/remote_dir
2148         local MDTIDX=1
2149
2150         mkdir_on_mdt0 $DIR/$tdir
2151         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
2152
2153         drop_request "rm -rf $remote_dir" || error "rm remote dir failed"
2154
2155         rm -rf $DIR/$tdir || error "rmdir failed"
2156
2157         return 0
2158 }
2159 run_test 110d "remove remote directory: drop client req"
2160
2161 test_110e () {
2162         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2163         local remote_dir=$DIR/$tdir/remote_dir
2164         local MDTIDX=1
2165
2166         mkdir_on_mdt0 $DIR/$tdir
2167         $LFS mkdir -i $MDTIDX -c2 $remote_dir  || error "lfs mkdir failed"
2168         drop_reint_reply "rm -rf $remote_dir" || error "rm remote dir failed"
2169
2170         rm -rf $DIR/$tdir || error "rmdir failed"
2171
2172         return 0
2173 }
2174 run_test 110e "remove remote directory: drop master rep"
2175
2176 test_110f () {
2177         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2178         local remote_dir=$DIR/$tdir/remote_dir
2179         local MDTIDX=1
2180
2181         mkdir_on_mdt0 $DIR/$tdir
2182         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
2183         drop_update_reply $MDTIDX "rm -rf $remote_dir" ||
2184                                         error "rm remote dir failed"
2185
2186         rm -rf $DIR/$tdir || error "rmdir failed"
2187 }
2188 run_test 110f "remove remote directory: drop slave rep"
2189
2190 test_110g () {
2191         [[ "$MDS1_VERSION" -ge $(version_code 2.11.0) ]] ||
2192                 skip "Need MDS version at least 2.11.0"
2193
2194         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2195
2196         mkdir_on_mdt0 $DIR/$tdir
2197         touch $DIR/$tdir/$tfile
2198
2199         # OBD_FAIL_MDS_REINT_NET_REP    0x119
2200         do_facet mds1 $LCTL set_param fail_loc=0x119
2201         $LFS migrate -m 1 $DIR/$tdir &
2202         migrate_pid=$!
2203         sleep 5
2204         do_facet mds1 $LCTL set_param fail_loc=0
2205         wait $migrate_pid
2206
2207         local mdt_index
2208         mdt_index=$($LFS getstripe -m $DIR/$tdir)
2209         [ $mdt_index == 1 ] || error "$tdir is not on MDT1"
2210         mdt_index=$($LFS getstripe -m $DIR/$tdir/$tfile)
2211         [ $mdt_index == 1 ] || error "$tfile is not on MDT1"
2212
2213         rm -rf $DIR/$tdir || error "rmdir failed"
2214 }
2215 run_test 110g "drop reply during migration"
2216
2217 test_110h () {
2218         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2219         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2220                 skip "Need MDS version at least 2.7.56"
2221
2222         local src_dir=$DIR/$tdir/source_dir
2223         local tgt_dir=$DIR/$tdir/target_dir
2224         local MDTIDX=1
2225
2226         mkdir -p $src_dir
2227         $LFS mkdir -i $MDTIDX $tgt_dir
2228
2229         dd if=/etc/hosts of=$src_dir/src_file
2230         touch $tgt_dir/tgt_file
2231         drop_update_reply $MDTIDX \
2232                 "mrename $src_dir/src_file $tgt_dir/tgt_file" ||
2233                 error "mrename failed"
2234
2235         $CHECKSTAT -t file $src_dir/src_file &&
2236                                 error "src_file present after rename"
2237
2238         diff /etc/hosts $tgt_dir/tgt_file ||
2239                         error "file changed after rename"
2240
2241 }
2242 run_test 110h "drop update reply during cross-MDT file rename"
2243
2244 test_110i () {
2245         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2246         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2247                 skip "Need MDS version at least 2.7.56"
2248
2249         local src_dir=$DIR/$tdir/source_dir
2250         local tgt_dir=$DIR/$tdir/target_dir
2251         local MDTIDX=1
2252
2253         mkdir -p $src_dir
2254         $LFS mkdir -i $MDTIDX $tgt_dir
2255
2256         mkdir $src_dir/src_dir
2257         touch $src_dir/src_dir/a
2258         mkdir $tgt_dir/tgt_dir
2259         drop_update_reply $MDTIDX \
2260                 "mrename $src_dir/src_dir $tgt_dir/tgt_dir" ||
2261                 error "mrename failed"
2262
2263         $CHECKSTAT -t dir $src_dir/src_dir &&
2264                         error "src_dir present after rename"
2265
2266         $CHECKSTAT -t dir $tgt_dir/tgt_dir ||
2267                                 error "tgt_dir not present after rename"
2268
2269         $CHECKSTAT -t file $tgt_dir/tgt_dir/a ||
2270                                 error "a not present after rename"
2271 }
2272 run_test 110i "drop update reply during cross-MDT dir rename"
2273
2274 test_110j () {
2275         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2276         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2277                 skip "Need MDS version at least 2.7.56"
2278
2279         local remote_dir=$DIR/$tdir/remote_dir
2280         local local_dir=$DIR/$tdir/local_dir
2281         local MDTIDX=1
2282
2283         mkdir_on_mdt0 $DIR/$tdir
2284         mkdir $DIR/$tdir/local_dir
2285         $LFS mkdir -i $MDTIDX $remote_dir
2286
2287         touch $local_dir/local_file
2288         drop_update_reply $MDTIDX \
2289                 "ln $local_dir/local_file $remote_dir/remote_file" ||
2290                 error "ln failed"
2291
2292         $CHECKSTAT -t file $remote_dir/remote_file ||
2293                                 error "remote not present after ln"
2294 }
2295 run_test 110j "drop update reply during cross-MDT ln"
2296
2297 test_110k() {
2298         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTS"
2299         [[ "$MDS1_VERSION" -ge $(version_code 2.12.55) ]] ||
2300                 skip "Need MDS version at least 2.12.55"
2301
2302         umount $MOUNT
2303         stop mds2 || error "stop mds2 failed"
2304
2305 #define OBD_FAIL_FLD_QUERY_REQ 0x1103
2306         do_facet mds2 lctl set_param fail_loc=0x80001103
2307         local OPTS="$MDS_MOUNT_OPTS -o abort_recovery"
2308         start mds2 $(mdsdevname 2) $OPTS ||
2309                 error "start MDS with abort_recovery should succeed"
2310         do_facet mds2 lctl set_param fail_loc=0
2311
2312         # cleanup
2313         stop mds2 || error "cleanup: stop mds2 failed"
2314         start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS ||
2315                 error "cleanup: start mds2 failed"
2316         zconf_mount $(hostname) $MOUNT || error "cleanup: mount failed"
2317         client_up || error "post-failover df failed"
2318         all_mds_up
2319 }
2320 run_test 110k "FID_QUERY failed during recovery"
2321
2322 test_110m () {
2323         (( $(lustre_version_code $SINGLEMDS) >= $(version_code 2.14.52) )) ||
2324                 skip "Need MDS version at least 2.14.52"
2325         (( $MDSCOUNT >= 2 )) || skip "needs at least 2 MDTs"
2326         local remote_dir=$DIR/$tdir/remote_dir
2327         local mdccli
2328         local uuid
2329         local diridx
2330
2331         mkdir_on_mdt0 $DIR/$tdir
2332
2333 #define OBD_FAIL_PTLRPC_RESEND_RACE 0x0525
2334         do_facet mds1 $LCTL set_param fail_loc=0x80000525
2335         $LFS mkdir -i 1 -c2 $remote_dir &
2336         mkdir_pid=$!
2337         sleep 3
2338         # initiate the re-connect & re-send
2339         mdccli=$(do_facet mds2 $LCTL dl |
2340                 awk '/MDT0000-osp-MDT0001/ {print $4;}')
2341         uuid=$(do_facet mds2 $LCTL get_param -n osp.$mdccli.mdt_conn_uuid)
2342         echo "conn_uuid=$uuid"
2343         do_facet mds2 $LCTL set_param "osp.$mdccli.import=connection=$uuid"
2344
2345         wait $mkdir_pid
2346         (( $? == 0 )) || error "mkdir failed"
2347
2348         diridx=$($LFS getstripe -m $remote_dir)
2349         (( $diridx == 1 )) || error "$diridx != 1"
2350         rm -rf $DIR/$tdir || error "rmdir failed"
2351 }
2352 run_test 110m "update resent vs original RPC race"
2353
2354 # LU-2844 mdt prepare fail should not cause umount oops
2355 test_111 ()
2356 {
2357         [[ "$MDS1_VERSION" -ge $(version_code 2.3.62) ]] ||
2358                 skip "Need MDS version at least 2.3.62"
2359
2360 #define OBD_FAIL_MDS_CHANGELOG_INIT 0x151
2361         do_facet $SINGLEMDS lctl set_param fail_loc=0x151
2362         stop $SINGLEMDS || error "stop MDS failed"
2363         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS &&
2364                 error "start MDS should fail"
2365         do_facet $SINGLEMDS lctl set_param fail_loc=0
2366         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
2367                 error "start MDS failed"
2368 }
2369 run_test 111 "mdd setup fail should not cause umount oops"
2370
2371 # LU-793
2372 test_112a() {
2373         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2374
2375         do_facet_random_file client $TMP/$tfile 100K ||
2376                 error_noexit "Create random file $TMP/$tfile"
2377
2378         pause_bulk "cp $TMP/$tfile $DIR/$tfile" $TIMEOUT ||
2379                 error_noexit "Can't pause_bulk copy"
2380
2381         df $DIR
2382         # expect cmp to succeed, client resent bulk
2383         cmp $TMP/$tfile $DIR/$tfile ||
2384                 error_noexit "Wrong data has been written"
2385         rm $DIR/$tfile ||
2386                 error_noexit "Can't remove file"
2387         rm $TMP/$tfile
2388 }
2389 run_test 112a "bulk resend while orignal request is in progress"
2390
2391 test_115_read() {
2392         local fail1=$1
2393         local fail2=$2
2394
2395         df $DIR
2396         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
2397         cancel_lru_locks osc
2398
2399         # OST_READ       =  3,
2400         $LCTL set_param fail_loc=$fail1 fail_val=3
2401         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1 &
2402         pid=$!
2403         sleep 1
2404
2405         set_nodes_failloc "$(osts_nodes)" $fail2
2406
2407         wait $pid || error "dd failed"
2408         return 0
2409 }
2410
2411 test_115_write() {
2412         local fail1=$1
2413         local fail2=$2
2414         local error=$3
2415         local fail_val2=${4:-0}
2416
2417         df $DIR
2418         touch $DIR/$tfile
2419
2420         # OST_WRITE      =  4,
2421         $LCTL set_param fail_loc=$fail1 fail_val=4
2422         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=dsync &
2423         pid=$!
2424         sleep 1
2425
2426         df $MOUNT
2427         set_nodes_failloc "$(osts_nodes)" $fail2 $fail_val2
2428
2429         wait $pid
2430         rc=$?
2431         [ $error -eq 0 ] && [ $rc -ne 0 ] && error "dd error ($rc)"
2432         [ $error -ne 0 ] && [ $rc -eq 0 ] && error "dd success"
2433         return 0
2434 }
2435
2436 test_115a() {
2437         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2438                 skip "need at least 2.8.50 on OST"
2439
2440         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2441         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2442         test_115_read 0x8000051b 0x8000051a
2443 }
2444 run_test 115a "read: late REQ MDunlink and no bulk"
2445
2446 test_115b() {
2447         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2448                 skip "need at least 2.8.50 on OST"
2449
2450         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2451         #define OBD_FAIL_OST_ENOSPC              0x215
2452
2453         # pass $OSTCOUNT for the fail_loc to be caught
2454         # appropriately by the IO thread
2455         test_115_write 0x8000051b 0x80000215 1 $OSTCOUNT
2456 }
2457 run_test 115b "write: late REQ MDunlink and no bulk"
2458
2459 test_115c() {
2460         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2461                 skip "need at least 2.8.50 on OST"
2462
2463         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2464         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2465         test_115_read 0x8000050f 0x8000051a
2466 }
2467 run_test 115c "read: late Reply MDunlink and no bulk"
2468
2469 test_115d() {
2470         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2471                 skip "need at least 2.8.50 on OST"
2472
2473         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2474         #define OBD_FAIL_OST_ENOSPC              0x215
2475         test_115_write 0x8000050f 0x80000215 0
2476 }
2477 run_test 115d "write: late Reply MDunlink and no bulk"
2478
2479 test_115e() {
2480         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2481                 skip "need at least 2.8.50 on OST"
2482
2483         #define OBD_FAIL_PTLRPC_LONG_BULK_UNLINK 0x510
2484         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2485         test_115_read 0x80000510 0x80000211
2486 }
2487 run_test 115e "read: late Bulk MDunlink and no reply"
2488
2489 test_115f() {
2490         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2491                 skip "need at least 2.8.50 on OST"
2492
2493         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2494         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2495         test_115_read 0x8000051b 0x80000211
2496 }
2497 run_test 115f "read: late REQ MDunlink and no reply"
2498
2499 test_115g() {
2500         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2501                 skip "need at least 2.8.50 on OST"
2502
2503         #define OBD_FAIL_PTLRPC_LONG_BOTH_UNLINK 0x51c
2504         test_115_read 0x8000051c 0
2505 }
2506 run_test 115g "read: late REQ MDunlink and Reply MDunlink"
2507
2508 # parameters: fail_loc CMD RC
2509 test_120_reply() {
2510         local PID
2511         local PID2
2512         local rc=5
2513         local fail
2514
2515         #define OBD_FAIL_LDLM_CP_CB_WAIT2       0x320
2516         #define OBD_FAIL_LDLM_CP_CB_WAIT3       0x321
2517         #define OBD_FAIL_LDLM_CP_CB_WAIT4       0x322
2518         #define OBD_FAIL_LDLM_CP_CB_WAIT5       0x323
2519
2520         echo
2521         echo -n "** FLOCK REPLY vs. EVICTION race, lock $2"
2522         [ "$1" = "CLEANUP" ] &&
2523                 fail=0x80000320 && echo ", $1 cp first"
2524         [ "$1" = "REPLY" ] &&
2525                 fail=0x80000321 && echo ", $1 cp first"
2526         [ "$1" = "DEADLOCK CLEANUP" ] &&
2527                 fail=0x80000322 && echo " DEADLOCK, CLEANUP cp first"
2528         [ "$1" = "DEADLOCK REPLY" ] &&
2529                 fail=0x80000323 && echo " DEADLOCK, REPLY cp first"
2530
2531         if [ x"$2" = x"get" ]; then
2532                 #for TEST lock, take a conflict in advance
2533                 # sleep longer than evictor to not confuse fail_loc: 2+2+4
2534                 echo "** Taking conflict **"
2535                 flocks_test 5 set read sleep 10 $DIR/$tfile &
2536                 PID2=$!
2537
2538                 sleep 2
2539         fi
2540
2541         $LCTL set_param fail_loc=$fail
2542
2543         flocks_test 5 $2 write $DIR/$tfile &
2544         PID=$!
2545
2546         sleep 2
2547         echo "** Evicting and re-connecting client **"
2548         mds_evict_client
2549
2550         client_reconnect
2551
2552         if [ x"$2" = x"get" ]; then
2553                 wait $PID2
2554         fi
2555
2556         wait $PID
2557         rc=$?
2558
2559         # check if the return value is allowed
2560         [ $rc -eq $3 ] && rc=0
2561
2562         $LCTL set_param fail_loc=0
2563         return $rc
2564 }
2565
2566 # a lock is taken, unlock vs. cleanup_resource() race for destroying
2567 # the ORIGINAL lock.
2568 test_120_destroy()
2569 {
2570         local PID
2571
2572         flocks_test 5 set write sleep 4 $DIR/$tfile &
2573         PID=$!
2574         sleep 2
2575
2576         # let unlock to sleep in CP CB
2577         $LCTL set_param fail_loc=$1
2578         sleep 4
2579
2580         # let cleanup to cleep in CP CB
2581         mds_evict_client
2582
2583         client_reconnect
2584
2585         wait $PID
2586         rc=$?
2587
2588         $LCTL set_param fail_loc=0
2589         return $rc
2590 }
2591
2592 test_120() {
2593         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
2594         touch $DIR/$tfile
2595
2596         test_120_reply "CLEANUP" set 5 || error "SET race failed"
2597         test_120_reply "CLEANUP" get 5 || error "GET race failed"
2598         test_120_reply "CLEANUP" unlock 5 || error "UNLOCK race failed"
2599
2600         test_120_reply "REPLY" set 5 || error "SET race failed"
2601         test_120_reply "REPLY" get 5 || error "GET race failed"
2602         test_120_reply "REPLY" unlock 5 || error "UNLOCK race failed"
2603
2604         # DEADLOCK tests
2605         test_120_reply "DEADLOCK CLEANUP" set 5 || error "DEADLOCK race failed"
2606         test_120_reply "DEADLOCK REPLY" set 35 || error "DEADLOCK race failed"
2607
2608         test_120_destroy 0x320 || error "unlock-cleanup race failed"
2609 }
2610 run_test 120 "flock race: completion vs. evict"
2611
2612 test_113() {
2613         local BEFORE=$(date +%s)
2614         local EVICT
2615
2616         # modify dir so that next revalidate would not obtain UPDATE lock
2617         touch $DIR
2618
2619         # drop 1 reply with UPDATE lock,
2620         # resend should not create 2nd lock on server
2621         mcreate $DIR/$tfile || error "mcreate failed: $?"
2622         drop_mdt_ldlm_reply_once "stat $DIR/$tfile" || error "stat failed: $?"
2623
2624         # 2 BL AST will be sent to client, both must find the same lock,
2625         # race them to not get EINVAL for 2nd BL AST
2626         #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
2627         $LCTL set_param fail_loc=0x8000031f
2628
2629         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0 > /dev/null
2630         chmod 0777 $DIR/$tfile || error "chmod failed: $?"
2631         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1 > /dev/null
2632
2633         # let the client reconnect
2634         client_reconnect
2635         EVICT=$($LCTL get_param mdc.$FSNAME-MDT*.state |
2636           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
2637
2638         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
2639 }
2640 run_test 113 "ldlm enqueue dropped reply should not cause deadlocks"
2641
2642 T130_PID=0
2643 test_130_base() {
2644         test_mkdir -p -c1 $DIR/$tdir
2645         local mdts=$(mdts_nodes)
2646
2647         # Prevent interference from layout intent RPCs due to
2648         # asynchronous writeback. These will be tested in 130c below.
2649         do_nodes ${CLIENTS:-$HOSTNAME} sync
2650
2651         # get only LOOKUP lock on $tdir
2652         cancel_lru_locks mdc
2653         ls $DIR/$tdir/$tfile 2>/dev/null
2654
2655         # get getattr by fid on $tdir
2656         #
2657         # we need to race with unlink, unlink must complete before we will
2658         # take a DLM lock, otherwise unlink will wait until getattr will
2659         # complete; but later than getattr starts so that getattr found
2660         # the object
2661 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2662         set_nodes_failloc $mdts 0x80000160
2663         stat $DIR/$tdir &
2664         T130_PID=$!
2665         sleep 2
2666
2667         rm -rf $DIR/$tdir
2668
2669         # drop the reply so that resend happens on an unlinked file.
2670 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2671         set_nodes_failloc $mdts 0x80000157
2672 }
2673
2674 test_130a() {
2675         remote_mds_nodsh && skip "remote MDS with nodsh"
2676         [[ "$MDS1_VERSION" -ge $(version_code 2.7.2) ]] ||
2677                 skip "Need server version newer than 2.7.1"
2678
2679         test_130_base
2680
2681         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2682         return 0
2683 }
2684 run_test 130a "enqueue resend on not existing file"
2685
2686 test_130b() {
2687         remote_mds_nodsh && skip "remote MDS with nodsh"
2688         [[ "$MDS1_VERSION" -ge $(version_code 2.7.2) ]] ||
2689                 skip "Need server version newer than 2.7.1"
2690
2691         test_130_base
2692         # let the reply to be dropped
2693         sleep 10
2694
2695 #define OBD_FAIL_SRV_ENOENT              0x217
2696         set_nodes_failloc "$(mdts_nodes)" 0x80000217
2697
2698         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2699         return 0
2700 }
2701 run_test 130b "enqueue resend on a stale inode"
2702
2703 test_130c() {
2704         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2705         local mdts=$(mdts_nodes)
2706
2707         do_nodes ${CLIENTS:-$HOSTNAME} sync
2708         echo XXX > $DIR/$tfile
2709
2710         cancel_lru_locks mdc
2711
2712         # Trigger writeback on $tfile.
2713         #
2714         # we need to race with unlink, unlink must complete before we will
2715         # take a DLM lock, otherwise unlink will wait until intent will
2716         # complete; but later than intent starts so that intent found
2717         # the object
2718 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2719         set_nodes_failloc $mdts 0x80000160
2720         sync &
2721         T130_PID=$!
2722         sleep 2
2723
2724         rm $DIR/$tfile
2725
2726         # drop the reply so that resend happens on an unlinked file.
2727 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2728         set_nodes_failloc $mdts 0x80000157
2729
2730         # let the reply to be dropped
2731         sleep 10
2732
2733 #define OBD_FAIL_SRV_ENOENT              0x217
2734         set_nodes_failloc $mdts 0x80000217
2735
2736         wait $T130_PID
2737
2738         return 0
2739 }
2740 run_test 130c "layout intent resend on a stale inode"
2741
2742 test_132() {
2743         local before=$(date +%s)
2744         local evict
2745
2746         mount_client $MOUNT2 || error "mount filed"
2747
2748         rm -f $DIR/$tfile
2749         # get a lock on client so that export would reach the stale list
2750         $LFS setstripe -i 0 $DIR/$tfile || error "setstripe failed"
2751         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync ||
2752                 error "dd failed"
2753
2754         #define OBD_FAIL_OST_PAUSE_PUNCH         0x236
2755         do_facet ost1 $LCTL set_param fail_val=120 fail_loc=0x80000236
2756
2757         $TRUNCATE $DIR/$tfile 100 &
2758
2759         sleep 1
2760         dd if=/dev/zero of=$DIR2/$tfile bs=4096 count=1 conv=notrunc ||
2761                 error "dd failed"
2762
2763         wait
2764         umount_client $MOUNT2
2765
2766         evict=$(do_facet client $LCTL get_param \
2767                 osc.$FSNAME-OST0000-osc-*/state |
2768             awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
2769
2770         [ -z "$evict" ] || [[ $evict -le $before ]] ||
2771                 (do_facet client $LCTL get_param \
2772                         osc.$FSNAME-OST0000-osc-*/state;
2773                     error "eviction happened: $evict before:$before")
2774 }
2775 run_test 132 "long punch"
2776
2777 test_131() {
2778         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2779
2780         rm -f $DIR/$tfile
2781         # get a lock on client so that export would reach the stale list
2782         $LFS setstripe -i 0 $DIR/$tfile || error "setstripe failed"
2783         dd if=/dev/zero of=$DIR/$tfile count=1 || error "dd failed"
2784
2785         # another IO under the same lock
2786         #define OBD_FAIL_OSC_DELAY_IO            0x414
2787         $LCTL set_param fail_loc=0x80000414
2788         $LCTL set_param fail_val=4 fail_loc=0x80000414
2789         dd if=/dev/zero of=$DIR/$tfile count=1 conv=notrunc oflag=dsync &
2790         local pid=$!
2791         sleep 1
2792
2793         #define OBD_FAIL_LDLM_BL_EVICT           0x31e
2794         set_nodes_failloc "$(osts_nodes)" 0x8000031e
2795         ost_evict_client
2796         client_reconnect
2797
2798         wait $pid && error "dd succeeded"
2799         return 0
2800 }
2801 run_test 131 "IO vs evict results to IO under staled lock"
2802
2803 test_133() {
2804         local t=$((TIMEOUT * 2))
2805         touch $DIR/$tfile
2806
2807         flock $DIR/$tfile -c "echo bl lock;sleep $t;echo bl flock unlocked" &
2808         sleep 1
2809         multiop_bg_pause $DIR/$tfile O_jc || return 1
2810         PID=$!
2811
2812         #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
2813         do_nodes $(mdts_nodes) $LCTL set_param fail_loc=0x80000157
2814         kill -USR1 $PID
2815         echo "waiting for multiop $PID"
2816         wait $PID || return 2
2817
2818         rm -f $DIR/$tfile
2819
2820         return 0
2821 }
2822 run_test 133 "don't fail on flock resend"
2823
2824 test_134() {
2825         [ $CLIENTCOUNT -lt 2 ] &&
2826                 { skip "Need 2+ clients, have $CLIENTCOUNT" && return; }
2827
2828         mkdir -p $MOUNT/$tdir/1 $MOUNT/$tdir/2 || error "mkdir failed"
2829         touch $MOUNT/$tdir/1/$tfile $MOUNT/$tdir/2/$tfile ||
2830                 error "touch failed"
2831         zconf_umount_clients $CLIENTS $MOUNT
2832         zconf_mount_clients $CLIENTS $MOUNT
2833
2834 #define OBD_FAIL_TGT_REPLY_DATA_RACE    0x722
2835         # assume commit interval is 5
2836         do_facet mds1 "$LCTL set_param fail_loc=0x722 fail_val=5"
2837
2838         local -a clients=(${CLIENTS//,/ })
2839         local client1=${clients[0]}
2840         local client2=${clients[1]}
2841
2842         do_node $client1 rm $MOUNT/$tdir/1/$tfile &
2843         rmpid=$!
2844         do_node $client2 mv $MOUNT/$tdir/2/$tfile $MOUNT/$tdir/2/${tfile}_2 &
2845         mvpid=$!
2846         fail mds1
2847         wait $rmpid || error "rm failed"
2848         wait $mvpid || error "mv failed"
2849         return 0
2850 }
2851 run_test 134 "race between failover and search for reply data free slot"
2852
2853 test_135() {
2854         [ "$MDS1_VERSION" -lt $(version_code 2.12.51) ] &&
2855                 skip "Need MDS version at least 2.12.51"
2856
2857         mkdir -p $DIR/$tdir
2858         $LFS setstripe -E 1M -L mdt $DIR/$tdir
2859         # to have parent dir write lock before open/resend
2860         touch $DIR/$tdir/$tfile
2861         #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
2862         do_nodes $(mdts_nodes) "$LCTL set_param fail_loc=0x80000157"
2863         openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tdir/$tfile ||
2864                 error "Failed to open DOM file"
2865 }
2866 run_test 135 "DOM: open/create resend to return size"
2867
2868 test_136() {
2869         remote_mds_nodsh && skip "remote MDS with nodsh"
2870         [[ "$MDS1_VERSION" -ge $(version_code 2.12.52) ]] ||
2871                 skip "Need MDS version at least 2.12.52"
2872
2873         local mdts=$(comma_list $(mdts_nodes))
2874         local MDT0=$(facet_svc $SINGLEMDS)
2875
2876         local clog=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
2877         [ -n "$clog" ] || error "changelog_register failed"
2878         cl_mask=$(do_facet mds1 $LCTL get_param \
2879                                 mdd.$MDT0.changelog_mask -n)
2880         changelog_chmask "ALL"
2881
2882         # generate some changelog records to accumulate
2883         test_mkdir -i 0 -c 0 $DIR/$tdir || error "mkdir $tdir failed"
2884         createmany -m $DIR/$tdir/$tfile 10000 ||
2885                 error "create $DIR/$tdir/$tfile failed"
2886
2887         local size1=$(do_facet $SINGLEMDS \
2888                       $LCTL get_param -n mdd.$MDT0.changelog_size)
2889         echo "Changelog size $size1"
2890
2891         #define OBD_FAIL_LLOG_PURGE_DELAY                   0x1318
2892         do_nodes $mdts $LCTL set_param fail_loc=0x1318 fail_val=30
2893
2894         # launch changelog_deregister in background on MDS
2895         do_facet mds1 "nohup $LCTL --device $MDT0 changelog_deregister $clog \
2896                         > foo.out 2> foo.err < /dev/null &"
2897         # give time to reach fail_loc
2898         sleep 15
2899
2900         # fail_loc will make MDS sleep in the middle of changelog_deregister
2901         # take this opportunity to abruptly kill MDS
2902         FAILURE_MODE_save=$FAILURE_MODE
2903         FAILURE_MODE=HARD
2904         fail mds1
2905         FAILURE_MODE=$FAILURE_MODE_save
2906
2907         do_nodes $mdts $LCTL set_param fail_loc=0x0 fail_val=0
2908
2909         local size2=$(do_facet $SINGLEMDS \
2910                       $LCTL get_param -n mdd.$MDT0.changelog_size)
2911         echo "Changelog size $size2"
2912         local clog2=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2913                         mdd.$MDT0.changelog_users | grep $clog")
2914         echo "After crash, changelog user $clog2"
2915
2916         [ -n "$clog2" -o $size2 -lt $size1 ] ||
2917                 error "changelog record count unchanged"
2918
2919         do_facet mds1 $LCTL set_param mdd.$MDT0.changelog_mask=\'$cl_mask\' -n
2920 }
2921 run_test 136 "changelog_deregister leaving pending records"
2922
2923 test_137() {
2924         df $DIR
2925         mkdir_on_mdt0 $DIR/$tdir
2926         mkdir $DIR/$tdir/d1
2927         mkdir $DIR/$tdir/d2
2928         dd if=/dev/zero of=$DIR/$tdir/d1/$tfile bs=4096 count=1
2929         dd if=/dev/zero of=$DIR/$tdir/d2/$tfile bs=4096 count=1
2930         cancel_lru_locks osc
2931
2932         #define OBD_FAIL_PTLRPC_RESEND_RACE      0x525
2933         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000525"
2934
2935         # RPC1: any reply is to be delayed to disable last_xid logic
2936         ln $DIR/$tdir/d1/$tfile $DIR/$tdir/d1/f2 &
2937         sleep 1
2938
2939         # RPC2: setattr1 reply is delayed & resent
2940         # original reply comes to client; the resend get asleep
2941         chmod 666 $DIR/$tdir/d2/$tfile
2942
2943         # RPC3: setattr2 on the same file; run ahead of RPC2 resend
2944         chmod 777 $DIR/$tdir/d2/$tfile
2945
2946         # RPC2 resend wakes up
2947         sleep 5
2948         [ $(stat -c "%a" $DIR/$tdir/d2/$tfile) == 777 ] ||
2949                 error "resend got applied"
2950 }
2951 run_test 137 "late resend must be skipped if already applied"
2952
2953 test_138() {
2954         remote_mds_nodsh && skip "remote MDS with nodsh"
2955         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2956         [[ "$MDS1_VERSION" -ge $(version_code 2.12.59) ]] ||
2957                 skip "Need server version newer than 2.12.59"
2958
2959         zconf_umount_clients $CLIENTS $MOUNT
2960
2961 #define OBD_FAIL_TGT_RECOVERY_CONNECT 0x724
2962         #delay a first step of recovey when MDS waiting clients
2963         #and failing to get osp logs
2964         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x724 fail_val=5
2965
2966         facet_failover $SINGLEMDS
2967
2968         #waiting failover and recovery timer
2969         #the valuse is based on target_recovery_overseer() wait_event timeout
2970         sleep 55
2971         stop $SINGLEMDS || error "stop MDS failed"
2972         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
2973         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
2974                 error "start MDS failed"
2975         zconf_mount_clients $CLIENTS $MOUNT
2976 }
2977 run_test 138 "Umount MDT during recovery"
2978
2979 test_139() {
2980         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2981         [ $MDS1_VERSION -lt $(version_code 2.13.50) ] &&
2982                 skip "Need MDS version at least 2.13.50"
2983
2984         stop $SINGLEMDS || error "stop $SINGLEMDS failed"
2985
2986 #define OBD_FAIL_OSP_INVALID_LOGID              0x2106
2987         do_facet $SINGLEMDS $LCTL set_param fail_val=0x68 fail_loc=0x80002106
2988         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
2989                 error "Fail to start $SINGLEMDS"
2990 }
2991 run_test 139 "corrupted catid won't cause crash"
2992
2993 test_140a() {
2994         [ $MDS1_VERSION -lt $(version_code 2.12.58) ] &&
2995                 skip "Need MDS version at least 2.13.50"
2996
2997         slr=$(do_facet mds1 \
2998                 $LCTL get_param -n mdt.$FSNAME-MDT0000.local_recovery)
2999         stack_trap "do_facet mds1 $LCTL set_param \
3000                 mdt.*.local_recovery=$slr" EXIT
3001
3002         # disable recovery for local clients
3003         # so local clients should be marked with no_recovery flag
3004         do_facet mds1 $LCTL set_param mdt.*.local_recovery=0
3005         mount_mds_client
3006
3007         local cnt
3008         cnt=$(do_facet mds1 $LCTL get_param "mdt.*MDT0000.exports.*.export" |
3009                 grep export_flags.*no_recovery | wc -l)
3010         echo "$cnt clients with recovery disabled"
3011         umount_mds_client
3012         [ $cnt -eq 0 ] && error "no clients with recovery disabled"
3013
3014         # enable recovery for local clients
3015         # so no local clients should be marked with no_recovery flag
3016         do_facet mds1 $LCTL set_param mdt.*.local_recovery=1
3017         mount_mds_client
3018
3019         cnt=$(do_facet mds1 $LCTL get_param "mdt.*MDT0000.exports.*.export" |
3020                 grep export_flags.*no_recovery | wc -l)
3021         echo "$cnt clients with recovery disabled"
3022         umount_mds_client
3023         [ $cnt -eq 0 ] || error "$cnt clients with recovery disabled"
3024 }
3025 run_test 140a "local mount is flagged properly"
3026
3027 test_140b() {
3028         [ $MDS1_VERSION -lt $(version_code 2.12.58) ] &&
3029                 skip "Need MDS version at least 2.13.50"
3030
3031         slr=$(do_facet mds1 \
3032                 $LCTL get_param -n mdt.$FSNAME-MDT0000.local_recovery)
3033         stack_trap "do_facet mds1 $LCTL set_param \
3034                 mdt.*.local_recovery=$slr" EXIT
3035
3036         # disable recovery for local clients
3037         do_facet mds1 $LCTL set_param mdt.*.local_recovery=0
3038
3039         mount_mds_client
3040         replay_barrier mds1
3041         umount_mds_client
3042         fail mds1
3043         # Lustre: tfs-MDT0000: Recovery over after 0:03, of 2 clients 2 rec...
3044         local recovery=$(do_facet mds1 dmesg |
3045                          awk '/Recovery over after/ { print $6 }' | tail -1 |
3046                          awk -F: '{ print $1 * 60 + $2 }')
3047         (( recovery < TIMEOUT * 2 + 5 )) ||
3048                 error "recovery took too long $recovery > $((TIMEOUT * 2 + 5))"
3049 }
3050 run_test 140b "local mount is excluded from recovery"
3051
3052 test_141() {
3053         local oldc=0
3054         local newc
3055         local oldgen
3056
3057         [ "$PARALLEL" == "yes" ] && skip "skip parallel run"
3058         combined_mgs_mds || skip "needs combined MGS/MDT"
3059         ( local_mode || from_build_tree ) &&
3060                 skip "cannot run in local mode or from build tree"
3061
3062         # some get_param have a bug to handle dot in param name
3063         oldgen=$(do_facet ost1 $LCTL get_param -n mgc.*.import |
3064                  awk '/generation:/{print $NF}')
3065         do_rpc_nodes $(facet_active_host ost1) cancel_lru_locks MGC
3066         local end=$((SECONDS + 30))
3067         local tmpc=1
3068
3069         while (( oldc == 0 || tmpc != oldc )) && (( SECONDS < end )); do
3070                 tmpc=$oldc
3071                 sleep 1
3072                 oldc=$(do_facet ost1 \
3073                        $LCTL "get_param -n 'ldlm.namespaces.MGC*.lock_count'")
3074         done
3075
3076         fail $SINGLEMDS
3077         wait_mgc_import_state ost1 FULL
3078         wait_update_facet_cond ost1 "$LCTL get_param -n mgc.*.import |
3079                 awk '/generation:/{print}' | cut -d':' -f2" "!=" " $oldgen"
3080         do_rpc_nodes $(facet_active_host ost1) cancel_lru_locks MGC
3081         wait_update_facet ost1 \
3082                 "$LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count'" $oldc ||
3083         {
3084                 newc=$(do_facet ost1 \
3085                        $LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count')
3086                 error "mgc lost locks ($oldc != $newc)"
3087         }
3088 }
3089 run_test 141 "do not lose locks on MGS restart"
3090
3091 test_142() {
3092         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
3093                 skip "Need MDS version at least 2.11.56"
3094
3095         #define OBD_FAIL_MDS_ORPHAN_DELETE      0x165
3096         do_facet mds1 $LCTL set_param fail_loc=0x165
3097         $MULTIOP $DIR/$tfile Ouc || error "multiop failed"
3098
3099         stop mds1
3100         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
3101
3102         wait_update_facet mds1 "pgrep orph_.*-MDD | wc -l" "0" ||
3103                 error "MDD orphan cleanup thread not quit"
3104 }
3105 run_test 142 "orphan name stub can be cleaned up in startup"
3106
3107 test_143() {
3108         (( $MDS1_VERSION >= $(version_code 2.13.0) )) ||
3109                 skip "Need MDS version at least 2.13.0"
3110         [ "$PARALLEL" == "yes" ] && skip "skip parallel run"
3111
3112         local mntpt=$(facet_mntpt $SINGLEMDS)
3113         stop mds1
3114         mount_fstype $SINGLEMDS || error "mount as fstype $SINGLEMDS failed"
3115         do_facet $SINGLEMDS touch $mntpt/PENDING/$tfile
3116         unmount_fstype $SINGLEMDS
3117         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "mds1 start fail"
3118
3119         wait_recovery_complete $SINGLEMDS || error "MDS recovery not done"
3120         wait_update_facet mds1 "pgrep orph_.*-MDD | wc -l" "0" ||
3121                 error "MDD orphan cleanup thread not quit"
3122 }
3123 run_test 143 "orphan cleanup thread shouldn't be blocked even delete failed"
3124
3125 test_144a() {
3126         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
3127                 skip "server does not support overstriping"
3128         (( MDS1_VERSION >= $(version_code 2.15.50.49) )) ||
3129                 skip "Need MDS version at least 2.15.50.49"
3130
3131         local pids=""
3132         local setcount=1000
3133         local mds_timeout
3134         local before
3135         local after
3136         local diff
3137         local mdts=$(mdts_nodes)
3138
3139         large_xattr_enabled || skip_env "ea_inode feature disabled"
3140         test_mkdir -i 0 -c 1 -p $DIR/$tdir
3141         stack_trap "rm -rf $DIR/$tdir" EXIT
3142
3143         mds_timeout=$(do_facet mds1 $LCTL get_param -n timeout)
3144         do_nodes $mdts "$LCTL set_param timeout=300"
3145         stack_trap "do_nodes $mdts $LCTL set_param timeout=$mds_timeout"
3146
3147         $LFS setstripe -i 0 -C $setcount $DIR/$tdir || error "setstripe failed"
3148
3149         for (( i = 0; i < 50; i++)); do
3150                 touch $DIR/$tdir/$tfile_$i &
3151                 pids="$pids $!"
3152         done
3153
3154         fail ost1
3155         sleep 60
3156
3157         for pid in $pids; do
3158                 kill -9 $pid >/dev/null 2>&1
3159         done
3160
3161         before=$SECONDS
3162         fail mds1
3163         after=$SECONDS
3164         # here we measure MDT stop + MDT start time. For error case MDT stop takes
3165         # about obd_timeout-60 (240) seconds. Without error - less than 30s.
3166         # MDT start takes different time depends on a configuration, let's check
3167         # the worst.
3168         diff=$((after - before))
3169         (( $diff < 240 )) || error "MDT failover took $diff seconds"
3170
3171         # failover mds1 back to the primary server
3172         fail mds1
3173 }
3174 run_test 144a "MDT failover should stop precreation threads"
3175
3176 test_144b() {
3177         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
3178                 skip "server does not support overstriping"
3179         (( MDS1_VERSION >= $(version_code 2.15.51.50) )) ||
3180                 skip "Need MDS version at least 2.15.51.50"
3181
3182         local pids=""
3183         local rc=0
3184         local setcount=1000
3185         local mds_timeout
3186         local mdts=$(mdts_nodes)
3187
3188         large_xattr_enabled || skip_env "ea_inode feature disabled"
3189         test_mkdir -i 0 -c 1 -p $DIR/$tdir
3190         stack_trap "rm -rf $DIR/$tdir" EXIT
3191
3192         mds_timeout=$(do_facet mds1 $LCTL get_param -n timeout)
3193         do_nodes $mdts "$LCTL set_param timeout=300"
3194         stack_trap "do_nodes $mdts $LCTL set_param timeout=$mds_timeout"
3195
3196         $LFS setstripe -i 0 -C $setcount $DIR/$tdir || error "setstripe failed"
3197
3198         for (( i = 0; i < 50; i++)); do
3199                 touch $DIR/$tdir/$tfile_$i &
3200                 pids="$pids $!"
3201         done
3202
3203         fail ost1
3204
3205         # 60s is not enought with ZFS which is still significatnly
3206         # slower on some operations like record writing
3207         local stime=60
3208         [[ "$mds1_FSTYPE" != "zfs" ]] || stime=120
3209         sleep $stime
3210
3211         for pid in $pids; do
3212                 ps -p $pid > /dev/null
3213                 (( $? == 0 )) && rc=1
3214                 kill -9 $pid >/dev/null 2>&1
3215         done
3216         echo "rc $rc"
3217         (( $rc == 0 )) || { fail mds1; error "Create thread still running"; }
3218 }
3219 run_test 144b "orphan cleanup shouldn't be blocked for no objects+failover situation"
3220
3221 test_144c() {
3222         [ "$PARALLEL" == "yes" ] && skip "skip parallel run"
3223         remote_mds_nodsh && skip "remote MDS with nodsh"
3224         remote_ost_nodsh && skip "remote OST with nodsh"
3225          (( OST1_VERSION >= $(version_code 2.15.59.53) )) ||
3226                 skip "need OSS >= v2_15_59.53 for reconnect fix"
3227         local rc
3228
3229         #increase a precreation window
3230         mkdir_on_mdt0 $DIR/$tdir
3231         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3232         createmany -o $DIR/$tdir/$tfile 9000
3233
3234         stop mds1
3235 #define OBD_FAIL_OST_DELORPHAN_DELAY     0x254
3236         #delay delorphan request to reconnection 5seconds
3237         do_facet ost1 $LCTL set_param fail_loc=0x0000254 fail_val=5
3238
3239         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "mds1 start fail"
3240
3241         wait_recovery_complete mds1 || error "MDS recovery not done"
3242
3243         sleep 1
3244         #reconnect
3245         do_facet mds1 $LCTL --device $FSNAME-OST0000-osc-MDT0000 recover
3246
3247         do_facet ost1 $LCTL set_param fail_loc=0 fail_val=0
3248
3249         #first and second orphan request delayed for 5seconds
3250         sleep 12
3251
3252         local testid=${TESTNAME//_/ }
3253
3254         do_facet ost1 "dmesg | tac | sed '/$testid/,$ d'" |
3255                 grep "trust the OST"
3256         rc=$?
3257         if (( rc == 0 )); then
3258                 remount_facet mds1
3259                 error "LAST_ID synchronization failed"
3260         else
3261                 return 0
3262         fi
3263 }
3264 run_test 144c "reconnection during orphan cleanup shouldn't lose LAST_ID synchronization"
3265
3266 test_145() {
3267         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
3268         [ $(facet_active_host mds2) = $(facet_active_host mds3) ] &&
3269                 skip "needs mds2 and mds3 on separate nodes"
3270
3271         replay_barrier mds1
3272
3273         touch $DIR/$tfile
3274
3275 #define OBD_FAIL_PTLRPC_DELAY_RECOV      0x507
3276         echo block mds_connect from mds2
3277         do_facet mds2 "$LCTL set_param fail_loc=0x507"
3278
3279 #define OBD_FAIL_OUT_UPDATE_DROP        0x1707
3280         echo block recovery updates from mds3
3281         do_facet mds3 "$LCTL set_param fail_loc=0x1707"
3282
3283         local hard_timeout=\
3284 $(do_facet mds1 $LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_time_hard)
3285
3286         fail mds1 &
3287
3288         local get_soft_timeout_cmd=\
3289 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_time_soft 2>/dev/null"
3290
3291         echo wait until mds1 recovery_time_soft is $hard_timeout
3292         wait_update $(facet_host mds1) "$get_soft_timeout_cmd" \
3293 "$hard_timeout" $hard_timeout
3294
3295         echo unblock mds_connect from mds2
3296         do_facet mds2 "$LCTL set_param fail_loc=0"
3297
3298         echo upblock recovery updates from mds3
3299         do_facet mds3 "$LCTL set_param fail_loc=0"
3300
3301         wait
3302         [ -f $DIR/$tfile ] || error "$DIR/$tfile does not exist"
3303 }
3304 run_test 145 "connect mdtlovs and process update logs after recovery expire"
3305
3306 test_146() {
3307         (( $MDS1_VERSION >= $(version_code 2.15.54.6) )) ||
3308                 skip "Need MDS >= v2_15_54-6-g3c69d46e17 for eviction_count"
3309
3310         local prev_count=$(do_facet $SINGLEMDS \
3311                 $LCTL get_param -n "mdt.${mds1_svc}.eviction_count")
3312
3313         mds_evict_client
3314
3315         client_reconnect
3316
3317         local next_count=$(do_facet $SINGLEMDS \
3318                 $LCTL get_param -n "mdt.${mds1_svc}.eviction_count")
3319
3320         [ "$prev_count" -lt "$next_count" ] ||
3321                 error "wrong eviction count ($prev_count >= $next_count)"
3322 }
3323 run_test 146 "test eviction is counted properly"
3324
3325 test_147() {
3326         local obd_timeout=200
3327         local old=$($LCTL get_param -n timeout)
3328         local f=$DIR/$tfile
3329         local connection_count
3330
3331         $LFS setstripe -i 0 -c 1 $f
3332         stripe_index=$($LFS getstripe -i $f)
3333         if [ $stripe_index -ne 0 ]; then
3334                $LFS getstripe $f
3335                error "$f: stripe_index $stripe_index != 0" && return
3336         fi
3337
3338         $LCTL set_param timeout=$obd_timeout
3339         stack_trap "$LCTL set_param timeout=$old && client_reconnect" EXIT
3340
3341         # OBD_FAIL_OST_CONNECT_NET2
3342         # lost reply to connect request
3343         do_facet ost1 lctl set_param fail_loc=0x00000225 timeout=$obd_timeout
3344         stack_trap "do_facet ost1 $LCTL set_param fail_loc=0 timeout=$old" EXIT
3345
3346
3347         ost_evict_client
3348         # force reconnect
3349         $LFS df $MOUNT > /dev/null 2>&1 &
3350         sleep $((obd_timeout * 3 / 4))
3351
3352         $LCTL get_param osc.$FSNAME-OST0000-osc-*.state
3353         connection_count=$($LCTL get_param osc.$FSNAME-OST0000-osc-*.state |
3354                            tac |  sed "/FULL/,$ d" | grep CONNECTING | wc -l)
3355
3356         echo $connection_count
3357         (($connection_count >= 6)) || error "Client reconnected too slow"
3358 }
3359 run_test 147 "Check client reconnect"
3360
3361 test_148() {
3362         local wce_param="obdfilter.$FSNAME-OST0000.writethrough_cache_enable"
3363         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3364         local amc=$(at_max_get client)
3365         local amo=$(at_max_get ost1)
3366         local timeout
3367
3368         at_max_set 0 client
3369         at_max_set 0 ost1
3370         timeout=$(request_timeout client)
3371
3372         [ "$(facet_fstype ost1)" = "ldiskfs" ] && {
3373                 # save old r/o cache settings
3374                 save_lustre_params ost1 $wce_param > $p
3375
3376                 # disable r/o cache
3377                 do_facet ost1 "$LCTL set_param -n $wce_param=0"
3378         }
3379
3380         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3381         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
3382         cp $DIR/$tfile $TMP/$tfile
3383         #define OBD_FAIL_OST_BRW_PAUSE_BULK2     0x227
3384         do_facet ost1 $LCTL set_param fail_loc=0x80000227
3385         do_facet ost1 $LCTL set_param fail_val=$((timeout+2))
3386         dd if=/dev/urandom of=$DIR/$tfile bs=4096 count=1 conv=notrunc,fdatasync
3387         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=notrunc,fdatasync
3388         sleep 2
3389         cancel_lru_locks osc
3390         cmp -b $DIR/$tfile $TMP/$tfile || error "wrong data"
3391
3392         rm -f $DIR/$tfile $TMP/$tfile
3393
3394         at_max_set $amc client
3395         at_max_set $amo ost1
3396
3397         [ "$(facet_fstype ost1)" = "ldiskfs" ] && {
3398                 # restore initial r/o cache settings
3399                 restore_lustre_params < $p
3400         }
3401
3402         return 0
3403 }
3404 run_test 148 "data corruption through resend"
3405
3406 test_149() {
3407         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
3408
3409         test_mkdir -i 0 -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
3410
3411         # make an orphan striped dir
3412         $MULTIOP $DIR/$tdir D_c &
3413         local PID=$!
3414         sleep 0.3
3415         rmdir $DIR/$tdir || error "can't rmdir"
3416
3417         # stop a slave MDT where one ons stripe is located
3418         stop mds2 -f
3419
3420         # stopping should not cause orphan as another MDT can
3421         # be stopped yet
3422         stop mds1 -f
3423
3424         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "mds1 start fail"
3425         start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "mds1 start fail"
3426
3427         kill -USR1 $PID
3428         wait $PID
3429
3430         clients_up
3431         return 0
3432 }
3433 run_test 149 "skip orphan removal at umount"
3434
3435 test_150() {
3436         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
3437         local lazystatfs
3438         local max
3439
3440         lazystatfs=$($LCTL get_param -n llite.$FSNAME-*.lazystatfs | head -1)
3441         max=$($LCTL get_param -n llite.$FSNAME-*.statahead_max | head -1)
3442
3443         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3444         $LCTL set_param llite.$FSNAME-*.statahead_max=0
3445         stack_trap "$LCTL set_param llite.$FSNAME-*.lazystatfs=$lazystatfs" EXIT
3446         stack_trap "$LCTL set_param llite.$FSNAME-*.statahead_max=$max" EXIT
3447         # stop a slave MDT where one ons stripe is located
3448         stop mds1
3449
3450         stack_trap "start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS && \
3451                 wait_recovery_complete mds1 && clients_up && true" EXIT
3452
3453         df $MOUNT || error "statfs failed"
3454         return 0
3455 }
3456 run_test 150 "statfs when MDT0 offline with lazystatfs option"
3457
3458 test_152() {
3459         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
3460                 skip "server does not support overstriping"
3461
3462         local before
3463         local after
3464         local diff
3465         local saved
3466         local version
3467         local pids_rr=""
3468         local pids_qos=""
3469         local setcount=500
3470
3471         large_xattr_enabled || skip_env "ea_inode feature disabled"
3472         version=$(do_facet mds1 \
3473                   uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
3474         version=$(version_code ${version//\./ })
3475         if (( $version < $(version_code 4.6.0) )); then
3476                 skip "MDS Linux kernel does not support killable semaphore"
3477         fi
3478
3479         test_mkdir -i 0 -c 1 -p $DIR/$tdir
3480         test_mkdir -i 0 -c 1 -p $DIR/$tdir/rr
3481         test_mkdir -i 0 -c 1 -p $DIR/$tdir/qos
3482         stack_trap "rm -rf $DIR/$tdir" EXIT
3483
3484         $LFS setstripe -C $setcount $DIR/$tdir/rr/ || error "setstripe failed"
3485
3486
3487         #define OBD_FAIL_MDS_LOD_CREATE_PAUSE    0x173
3488         #Simulate OST failover and sleep RR allocation under lq_rw_sem
3489         do_facet mds1 $LCTL set_param fail_loc=0x80000173 fail_val=20
3490         before=$(date +%s)
3491         for (( i = 0; i < 2; i++)); do
3492                 touch $DIR/$tdir/rr/$tfile_$i &
3493                 pids_rr="$pids_rr $!"
3494         done
3495         sleep 3
3496
3497         saved=$(do_facet mds1 $LCTL get_param -n lov.*0000*.qos_threshold_rr)
3498         do_facet mds1 $LCTL set_param lov.*.qos_threshold_rr=0
3499         stack_trap "do_facet mds1 $LCTL set_param lov.*.qos_threshold_rr=$saved" EXIT
3500
3501         #create files with QoS algo, killable semaphore sleeps for 2seconds
3502         for (( i = 0; i < 3; i++)); do
3503                 touch $DIR/$tdir/qos/$tfile_$i &
3504                 pids_qos="$pids_qos $!"
3505         done
3506
3507         for pid in $pids_qos; do
3508                 wait $pid
3509         done
3510         after=$(date +%s)
3511
3512         diff=$((after - before))
3513         echo "QoS allocation took $diff seconds"
3514         for pid in $pids_rr; do
3515                wait $pid
3516         done
3517
3518         (( $diff < 20 )) ||
3519         error "QoS allocation slower than RR, killable semaphore doesn't work"
3520 }
3521 run_test 152 "QoS object allocation could be awakened in case of OST failover"
3522
3523 test_153() {
3524         (( MDS1_VERSION >= $(version_code 2.15.54.113) )) ||
3525                 skip "need MDS >= v2_15_54-113-g654d5f3fa4df for reconnect fix"
3526
3527 #define OBD_FAIL_MDS_CONNECT_VS_EVICT   0x174
3528         do_facet mds1 "$LCTL set_param fail_loc=0x174"
3529         # first drop ping reply from MDS and then
3530         # evict on the subsequent reconnect
3531         # (see target_handle_connect)
3532         sleep $((TIMEOUT + 3))
3533         stop mds1
3534         do_facet mds1 "$LCTL set_param fail_loc=0"
3535         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS ||
3536                 error "Fail to start $SINGLEMDS"
3537         wait_recovery_complete mds1 || error "MDS recovery not done"
3538 }
3539 run_test 153 "evict vs reconnect race"
3540
3541 test_154a() {
3542         (( MDS1_VERSION >= $(version_code 2.15.60.2) )) ||
3543                 skip "need MDS >= v2_15_60-2-ge81805244476 for llog fix"
3544         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
3545
3546         stop mds2
3547
3548         local mnt=$(facet_mntpt mds2)
3549
3550         mount_fstype mds2
3551         local ula=($(do_facet mds2 od -t u8 $mnt/update_log | \
3552                 awk '{ if($2 > 0) printf "0x%x:0x%x:0x0 ", $3, $2  }'))
3553         [ ${#ula[@]} -lt 2 ] && error "update_log file corruption"
3554
3555         local catfile=$mnt/update_log_dir/\[${ula[0]}\]
3556
3557         echo replace file $catfile
3558         do_facet mds2 dd if=/dev/urandom of=$catfile count=100 ||
3559                 error "Write file $catfile error"
3560         unmount_fstype mds2
3561
3562         start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "mds2 start fail"
3563
3564         stop mds1
3565         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "mds1 start fail"
3566
3567         echo waiting mds1 recovery....
3568         wait_recovery_complete mds1 20
3569
3570         do_facet mds1 $LCTL get_param mdt.$FSNAME-MDT0000.recovery_status | \
3571                 grep -w COMPLETE || error "Recovery was blocked"
3572 }
3573 run_test 154a "corruption update llog can be skipped"
3574
3575 test_154b() {
3576         (( MDS1_VERSION >= $(version_code 2.15.60.2) )) ||
3577                 skip "need MDS >= v2_15_60-2-ge81805244476 for llog fix"
3578         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
3579
3580         stop mds1
3581
3582         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0"
3583 #define OBD_FAIL_TGT_RECOVERY_CONNECT 0x724
3584         do_facet mds1 $LCTL set_param fail_loc=0x0724 fail_val=5
3585         local OPTS="$MDS_MOUNT_OPTS -o abort_recov"
3586         start mds1 $(mdsdevname 1) $OPTS ||
3587                 error "start MDS with abort_recovery failed"
3588
3589         echo waiting mds1 recovery....
3590         wait_recovery_complete mds1 30
3591         do_facet mds1 $LCTL get_param mdt.$FSNAME-MDT0000.recovery_status | \
3592                 grep -w COMPLETE || error "Recovery was blocked"
3593
3594         mount_client $MOUNT2
3595         umount_client $MOUNT2
3596         remount_client $MOUNT
3597 }
3598 run_test 154b "restore update llog after failed recovery"
3599
3600 test_155() {
3601         (( MDS1_VERSION >= $(version_code 2.15.58.110) )) ||
3602                 skip "need MDS >= v2_15_58-110-g71f8e5d6506f for ptlrpc fix"
3603
3604         local lsoutput1
3605         local lsoutput2
3606
3607         touch $DIR/$tfile
3608         lsoutput1=$(ls -l $DIR)
3609
3610         zconf_umount $HOSTNAME $MOUNT || error "umount failed"
3611         # make sure that last_rcvd update is committed
3612         do_facet mds1 sync
3613         zconf_mount $HOSTNAME $MOUNT || error "mount failed"
3614
3615         replay_barrier_nosync mds1
3616
3617         fail_nodf mds1
3618
3619         lsoutput2=$(ls -l $DIR) || error "ls failed"
3620         [[ $lsoutput1 == $lsoutput2 ]] || error "$lsoutput1 != $lsoutput2"
3621 }
3622 run_test 155 "failover after client remount"
3623
3624 test_156()
3625 {
3626         (( OST1_VERSION >= $(version_code v2_15_60-90-g9df01eee75) )) ||
3627                 skip "Need OST >= 2.15.60.90 for tot_granted miscount fix"
3628
3629         # on failover recovery time hard will be 9 * 5
3630         local saved_timeout=$(do_facet ost1 $LCTL get_param -n timeout)
3631
3632         do_facet mgs $LCTL set_param -P timeout=5 ||
3633                 error "failed to set obd_timeout"
3634         stack_trap "do_facet mgs $LCTL set_param -P timeout=$saved_timeout" \
3635             EXIT
3636
3637         $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "setstripe failed"
3638
3639         # this is to sync last_rcvd, so that the client will have to
3640         # send replay on recovery
3641         $LFS df $MOUNT
3642         do_facet ost1 sync
3643
3644         replay_barrier ost1
3645
3646         $MULTIOP $DIR/$tfile oO_RDWR:O_SYNC:w1048576c || error "multiop failed"
3647
3648         # delay write replay for 45 sec (OBD_RECOVERY_TIME_HARD) to
3649         # get the client evicted as not sending replays
3650
3651 #define OBD_FAIL_PTLRPC_REPLAY_PAUSE     0x536
3652         $LCTL set_param fail_loc=0x80000536 fail_val=45
3653
3654         fail ost1
3655
3656         # check that ost1 evicted the client in recovery
3657         local clients
3658         clients=($(do_facet ost1 \
3659                 $LCTL get_param -n obdfilter.$FSNAME-OST0000.recovery_status |
3660                 awk '/completed_clients/ { print $2 }' | tr '/' '\n'))
3661         [[ $((${clients[0]} + 1)) == ${clients[1]} ]] ||
3662                 error "client not evicted by ost1"
3663
3664         local testid=$(echo $TESTNAME | tr '_' ' ')
3665         do_facet ost1 dmesg | tac | sed "/$testid/,$ d" |
3666                 grep "ofd_obd_disconnect: tot_granted" &&
3667                 error "grant miscount" || true
3668 }
3669 run_test 156 "tot_granted miscount after client eviction"
3670
3671 test_157()
3672 {
3673         (( MDS1_VERSION >= $(version_code 2.15.58.110) )) ||
3674                 skip "need MDS >= v2_15_58-110-g71f8e5d6506f to avoid eviction"
3675
3676         $LFS setstripe -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
3677         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3678         cancel_lru_locks osc
3679
3680 #define OBD_FAIL_LLITE_FAULT_PAUSE                 0x1432
3681         $LCTL set_param fail_loc=0x80001432 fail_val=3
3682         $MULTIOP $DIR/$tfile soO_RDWR:MRUc &
3683         MULTIPID=$!
3684         sleep 1
3685         ost_evict_client
3686         wait $MULTIPID
3687         local rc=$?
3688         (( rc == 0 || rc == 135 )) ||
3689                 error "multiop failed with $rc, not SIGBUS (135)"
3690 }
3691 run_test 157 "eviction during mmaped i/o"
3692
3693 cleanup_158() {
3694         do_facet mds2 $LCTL set_param fail_loc=0
3695         zconf_umount_clients $CLIENTS $MOUNT
3696         mountcli
3697 }
3698
3699 test_158a() {
3700         (( $MDS1_VERSION >= $(version_code 2.15.62) )) ||
3701                 skip "Need MDS version at least 2.15.62 for -EACCES fix"
3702         (( MDSCOUNT > 1 )) || skip "needs >= 2 MDTS"
3703
3704         remount_client $MOUNT
3705         # ensure there is no MOUNT2 on clients
3706         zconf_umount_clients $CLIENTS $MOUNT2 -f
3707
3708         stack_trap cleanup_158 EXIT RETURN
3709
3710         # client import is evicted after failover followed by -EACCES
3711         #define OBD_FAIL_MDS_CONNECT_ACCESS     0x2402
3712         do_facet mds2 $LCTL set_param fail_loc=0x2402
3713         fail_nodf mds2
3714         sleep 5
3715         $LFS df $MOUNT
3716         do_facet mds2 $LCTL set_param fail_loc=0
3717         wait_recovery_complete mds2 || error "MDS recovery not done"
3718         sleep 5
3719
3720         local mdc2=$($LCTL dl | awk '/mdc.*MDT0001-mdc*/ { print $4}')
3721         local active=$($LCTL get_param -n mdc.$mdc2.active)
3722         (( active == 0 )) || error "import status is 'active'"
3723         $LCTL --device $mdc2 activate
3724         active=$($LCTL get_param -n mdc.$mdc2.active)
3725         (( active == 1 )) || error "import status is not 'active'"
3726         status=$($LFS check mdts | grep $mdc2 | grep -c active)
3727         (( status == 1 )) || {
3728                 $LFS check mdts
3729                 error "import is not operational"
3730         }
3731 }
3732 run_test 158a "connect without access right"
3733
3734 test_160() {
3735         (( $MDS1_VERSION >= $(version_code 2.15.62) )) ||
3736                 skip "Need MDS version at least 2.15.62 for group lock destroy fix"
3737
3738         local threads=10
3739         local size=$((1024*100))
3740         local timeout=10
3741         local pids
3742
3743         test_mkdir -i 0 -c 1 $DIR/$tdir
3744         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3745
3746         for ((i = 1; i <= threads; i++)); do
3747                 local file=$DIR/$tdir/file_$i
3748                 #open/group lock/write/unlink/pause/group unlock/close
3749                 $MULTIOP $file OG1234w10240u_g1234c &
3750                 pids[$i]=$!
3751         done
3752         sleep 2
3753
3754         #evict client from MDS, MDS starts to unlink files/destroy objects
3755         mds_evict_client
3756         client_reconnect
3757
3758         wait_update_facet_cond --verbose mds1 \
3759                 "$LCTL get_param -n osp.$FSNAME-OST0000-osc-MDT0000.destroys_in_flight" \
3760                 "-le" "2" $((timeout * 3))
3761         local rc=$?
3762         do_facet mds1 $LCTL get_param osp.$FSNAME-OST0000-osc-MDT0000.error_list
3763         for ((i = 1; i <= threads; i++)); do
3764                 kill -USR1 ${pids[$i]} && wait ${pids[$i]}
3765         done
3766
3767         (( rc == 0 )) || error "destroying OST objects are blocked"
3768
3769         #without group lock, wait and check if all objects are destroyed
3770         sleep $((timeout * 3))
3771         do_facet mds1 $LCTL get_param osp.$FSNAME-OST0000-osc-MDT0000.error_list
3772         local errs=$(do_facet mds1 $LCTL get_param -n osp.$FSNAME-OST0000-osc-MDT0000.error_list | wc -l)
3773         rc=$(do_facet mds1 $LCTL get_param -n osp.$FSNAME-OST0000-osc-MDT0000.destroys_in_flight)
3774
3775         (( $errs == 0 )) || error "error_list not empty"
3776         (( $rc == 0 )) || error "$rc destroys in flight"
3777 }
3778 run_test 160 "MDT destroys are blocked by grouplocks"
3779
3780 test_161() {
3781         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
3782         local ping_interval=$($LCTL get_param -n ping_interval)
3783         local evict_multiplier=$($LCTL get_param -n evict_multiplier)
3784         local pause=$((ping_interval * (evict_multiplier + 2)))
3785
3786         #define OBD_FAIL_OBD_PAUSE_EVICTOR          0x60f
3787         do_facet mds1 $LCTL set_param fail_loc=0x8000060f
3788
3789         $LFS mkdir -i 1 $DIR/$tdir || error "mkdir $tdir"
3790         $LFS mkdir -i 0 $DIR/$tdir/remote || error "mkdir $tdir/remote"
3791
3792         echo sleep $pause seconds
3793         sleep $pause
3794         rmdir $DIR/$tdir/remote || error "rmdir $tdir/remote"
3795 }
3796 run_test 161 "evict osp by ping evictor"
3797
3798 test_162() {
3799         local mntpt=$(facet_mntpt $SINGLEMDS)
3800
3801         test_mkdir -i 0 -c 1 $DIR/$tdir
3802         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3803
3804         local wfile=$DIR/$tdir/$tfile
3805         local rstr="aAdDiPST"
3806
3807         stack_trap "chattr -$rstr $wfile; rm -rf $DIR/$tdir" EXIT
3808
3809         touch $wfile
3810         for ((i = 0; i < ${#rstr[0]}; i++)); do
3811                 local c=${rstr:i:1}
3812
3813                 chattr +$c $wfile || error "Flag [$c] should succeed"
3814         done
3815
3816         local attr1=($(lsattr $wfile))
3817         echo $attr1
3818
3819         [[ -n ${attr1//-/} ]] || error "lsattr failed: $(lsattr $wfile)"
3820
3821         stop mds1
3822         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "mds1 start fail"
3823
3824         wait_recovery_complete $SINGLEMDS || error "MDS recovery not done"
3825
3826         local attr2=($(lsattr $wfile))
3827         echo $attr2
3828         [[ "$attr1" == "$attr2" ]] ||
3829                 error "'$attr1' different with '$attr2'"
3830
3831 }
3832 run_test 162 "File attributes should be persisted after MDS failover"
3833
3834 test_163() {
3835         remote_mds_nodsh && skip "remote MDS with nodsh"
3836         (( "$MDS1_VERSION" >= $(version_code 2.16.54) )) ||
3837                 skip "Need MDS version at least 2.16.54 to skip llog holes"
3838
3839         local mdtidx
3840         local mdtsvc
3841
3842         changelog_register || error "changelog_register failed"
3843         stack_trap changelog_deregister EXIT
3844         test_mkdir -c 0 $DIR/$tdir || error "mkdir $tdir failed"
3845         mdtidx=$(($($LFS getdirstripe -i $DIR/$tdir) + 1))
3846         mdtsvc=$(facet_svc mds$mdtidx)
3847         echo mds$mdtidx $mdtsvc
3848
3849         cl_mask=$(do_facet mds$mdtidx $LCTL get_param mdd.$mdtsvc.changelog_mask -n)
3850         changelog_chmask "ALL"
3851         stack_trap "do_facet mds$mdtidx \
3852                 $LCTL set_param mdd.$mdtsvc.changelog_mask=\'$cl_mask\' -n" EXIT
3853
3854         #define OBD_FAIL_MDS_CHANGELOG_FAIL_WRITE                       0x18f
3855         do_facet mds$mdtidx $LCTL set_param fail_loc=0x18f fail_val=30
3856
3857         # generate some changelog records to create a gap every 31 index
3858         for (( i = 0; i < 10; i++)); do
3859                 createmany -m $DIR/$tdir/$tfile_$i 40 &
3860         done
3861
3862         # Check changelog gap processing without a jump to a next chunk
3863         changelog_dump | awk -F'[ .]' '{if(prev != "" && $2 - prev > 2) \
3864                         {print"Errot between "prev" and "$2; exit 1}prev=$2}' ||
3865                         error "Found a gap"
3866 }
3867 run_test 163 "changelog check for fail write and processing records"
3868
3869 complete_test $SECONDS
3870 check_and_cleanup_lustre
3871 exit_status