Whamcloud - gitweb
LU-11607 tests: replace lustre_version/fstype - full
[fs/lustre-release.git] / lustre / tests / replay-vbr.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
4
5 set -e
6
7 # bug number:
8 ALWAYS_EXCEPT=" $REPLAY_VBR_EXCEPT"
9
10 SAVE_PWD=$PWD
11 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
12 SETUP=${SETUP:-}
13 CLEANUP=${CLEANUP:-}
14 MOUNT_2=${MOUNT_2:-"yes"}
15 export MULTIOP=${MULTIOP:-multiop}
16 . $LUSTRE/tests/test-framework.sh
17 init_test_env $@
18 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
19 init_logging
20
21 remote_mds_nodsh && log "SKIP: remote MDS with nodsh" && exit 0
22
23 #                                  ~6  (min)"
24 [ "$SLOW" = "no" ] && EXCEPT_SLOW="7"
25
26 build_test_filter
27
28 check_and_setup_lustre
29
30 assert_DIR
31 rm -rf $DIR/[df][0-9]*
32
33 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
34
35 # if there is no CLIENT1 defined, some tests can be ran on localhost
36 CLIENT1=${CLIENT1:-$HOSTNAME}
37 # if CLIENT2 doesn't exist then use CLIENT1 instead
38 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
39 # $CLIENT2 == CLIENT1
40 # Exception is the test which need two separate nodes
41 CLIENT2=${CLIENT2:-$CLIENT1}
42
43 is_mounted $MOUNT2 || error "MOUNT2 is not mounted"
44
45 #
46 # get_version(): Gets the version of an object on servers
47 # Parameter1: Client/Machine Name
48 # Parameter2: File Path
49 # Returns: Objectversion Or -1 if getobjversion fails.
50 #
51 get_version() {
52         local var=${SINGLEMDS}_svc
53         local client=$1
54         local file=$2
55         local fid=$(do_node $client $LFS path2fid $file)
56         local objver=$(do_facet $SINGLEMDS $LCTL --device ${!var} \
57                 getobjversion \\\"$fid\\\")
58
59         [[ -z $objver ]] && objver=-1
60         echo $objver
61 }
62
63 #
64 # chk_get_version(): Wrapper to get_version().
65 # Parameter1: Client/Machine Name
66 # Parameter2: File Path
67 # Returns: Objectversion Or Exit with error in case objver is -1.
68 #
69 chk_get_version() {
70         local objver=$(get_version $1 $2)
71
72         [[ "$objver" == "-1" ]] && error "object version is empty."
73         echo $objver
74 }
75
76
77 #save COS setting
78 cos_param_file=$TMP/rvbr-cos-params
79 save_lustre_params $(get_facets MDS) "mdt.*.commit_on_sharing" > $cos_param_file
80
81 test_0a() {
82         local ver=$(get_version $CLIENT1 $DIR/$tdir/1a)
83
84         [[ "$ver" == "-1" ]] && return 0
85         return 1
86 }
87 run_test 0a "getversion for non existent file shouldn't cause kernel panic"
88
89 test_0b() {
90         local var=${SINGLEMDS}_svc
91         local fid
92         local file=$DIR/$tdir/f
93
94         do_node $CLIENT1 mkdir -p $DIR/$tdir/
95         do_node $CLIENT1 touch $file
96         fid=$(do_node $CLIENT1 $LFS path2fid $file)
97         do_node $CLIENT1 rm -rf $file
98         do_facet $SINGLEMDS $LCTL --device ${!var} getobjversion \\\"$fid\\\" || true
99 }
100 run_test 0b "getversion for non existent fid shouldn't cause kernel panic"
101
102 # test set #1: OPEN
103 test_1a() { # former test_0a
104         local file=$DIR/$tfile
105         local pre
106         local post
107
108         do_node $CLIENT1 mcreate $file
109         pre=$(chk_get_version $CLIENT1 $file)
110         do_node $CLIENT1 openfile -f O_RDWR $file
111         post=$(chk_get_version $CLIENT1 $file)
112         if (($pre != $post)); then
113                 error "version changed unexpectedly: pre $pre, post $post"
114         fi
115 }
116 run_test 1a "open and close do not change versions"
117
118 test_1b() { # former test_0b
119     local var=${SINGLEMDS}_svc
120     zconf_mount $CLIENT2 $MOUNT2
121
122     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
123     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
124     do_node $CLIENT1 mkdir -p -m 755 $MOUNT/$tdir
125
126     replay_barrier $SINGLEMDS
127     do_node $CLIENT2 chmod 777 $MOUNT2/$tdir
128     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT $MOUNT/$tdir/$tfile
129     zconf_umount $CLIENT2 $MOUNT2
130     facet_failover $SINGLEMDS
131
132     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
133     if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
134                 error_and_remount "open succeeded unexpectedly"
135     fi
136 }
137 run_test 1b "open (O_CREAT) checks version of parent"
138
139 test_1c() { # former test_0c
140     local var=${SINGLEMDS}_svc
141     zconf_mount $CLIENT2 $MOUNT2
142
143     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
144     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
145
146     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
147     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tdir/$tfile
148
149     replay_barrier $SINGLEMDS
150     do_node $CLIENT2 chmod 0777 $MOUNT2/$tdir
151     do_node $CLIENT2 chmod 0666 $MOUNT2/$tdir/$tfile
152     rmultiop_start $CLIENT1 $DIR/$tdir/$tfile o_c
153     zconf_umount $CLIENT2 $MOUNT2
154     facet_failover $SINGLEMDS
155
156     client_up $CLIENT1 || error "$CLIENT1 evicted"
157     rmultiop_stop $CLIENT1 || error "close failed"
158 }
159 run_test 1c "open (non O_CREAT) does not checks versions"
160
161 # test set #2: CREAT (not open)
162 # - version of parent is not changed but checked
163 # - pre-version should be -1
164 # - post-version should be valid
165 test_2a() {  # extended former test_0d
166         local pre
167         local post
168
169         # fifo
170         pre=$(chk_get_version $CLIENT1 $DIR)
171         do_node $CLIENT1 mkfifo $DIR/$tfile-fifo
172         post=$(chk_get_version $CLIENT1 $DIR)
173         if (($pre != $post)); then
174                 error "version was changed: pre $pre, post $post"
175         fi
176         # mkdir
177         pre=$(chk_get_version $CLIENT1 $DIR)
178         do_node $CLIENT1 mkdir $DIR/$tfile-dir
179         post=$(chk_get_version $CLIENT1 $DIR)
180         if (($pre != $post)); then
181                 error "version was changed: pre $pre, post $post"
182         fi
183         do_node $CLIENT1 rmdir $DIR/$tfile-dir
184
185         # mknod
186         pre=$(chk_get_version $CLIENT1 $DIR)
187         do_node $CLIENT1 mkfifo $DIR/$tfile-nod
188         post=$(chk_get_version $CLIENT1 $DIR)
189         if (($pre != $post)); then
190                 error "version was changed: pre $pre, post $post"
191         fi
192         # symlink
193         pre=$(chk_get_version $CLIENT1 $DIR)
194         do_node $CLIENT1 mkfifo $DIR/$tfile-symlink
195         post=$(chk_get_version $CLIENT1 $DIR)
196         if (($pre != $post)); then
197                 error "version was changed: pre $pre, post $post"
198         fi
199         # remote directory
200         if [ $MDSCOUNT -ge 2 ]; then
201                 #create remote dir
202                 local MDT_IDX=1
203                 pre=$(chk_get_version $CLIENT1 $DIR)
204                 do_node $CLIENT1 $LFS mkdir -i $MDT_IDX $DIR/$tfile-remote_dir
205                 post=$(chk_get_version $CLIENT1 $DIR)
206                 if (($pre != $post)); then
207                         error "version was changed: pre $pre, post $post"
208                 fi
209         fi
210         do_node $CLIENT1 rm -rf $DIR/$tfile-*
211
212 }
213 run_test 2a "create operations doesn't change version of parent"
214
215 test_2b() { # former test_0e
216     local var=${SINGLEMDS}_svc
217     zconf_mount $CLIENT2 $MOUNT2
218
219     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
220     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
221
222     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
223
224     replay_barrier $SINGLEMDS
225     do_node $CLIENT2 chmod 777 $MOUNT2/$tdir
226     do_node $CLIENT1 mkfifo $DIR/$tdir/$tfile
227     zconf_umount $CLIENT2 $MOUNT2
228     facet_failover $SINGLEMDS
229
230     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
231     if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
232                 error_and_remount "create succeeded unexpectedly"
233     fi
234 }
235 run_test 2b "create checks version of parent"
236
237 test_3a() { # former test_0f
238         local pre
239         local post
240
241         do_node $CLIENT1 mcreate $DIR/$tfile
242         pre=$(chk_get_version $CLIENT1 $DIR)
243         do_node $CLIENT1 rm $DIR/$tfile
244         post=$(chk_get_version $CLIENT1 $DIR)
245         if (($pre != $post)); then
246                 error "version was changed: pre $pre, post $post"
247         fi
248
249         if [ $MDSCOUNT -ge 2 ]; then
250                 #create remote dir
251                 local MDT_IDX=1
252                 do_node $CLIENT1 $LFS mkdir -i $MDT_IDX $DIR/$tfile-remote_dir
253                 pre=$(chk_get_version $CLIENT1 $DIR)
254                 do_node $CLIENT1 rmdir $DIR/$tfile-remote_dir
255                 post=$(chk_get_version $CLIENT1 $DIR)
256                 if (($pre != $post)); then
257                         error "version was changed: pre $pre, post $post"
258                 fi
259         fi
260 }
261 run_test 3a "unlink doesn't change version of parent"
262
263 test_3b() { # former test_0g
264     local var=${SINGLEMDS}_svc
265     zconf_mount $CLIENT2 $MOUNT2
266
267     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
268     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
269
270     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
271     do_node $CLIENT1 mcreate $DIR/$tdir/$tfile
272
273     replay_barrier $SINGLEMDS
274     do_node $CLIENT2 chmod 777 $MOUNT2/$tdir
275     do_node $CLIENT1 rm $DIR/$tdir/$tfile
276     zconf_umount $CLIENT2 $MOUNT2
277     facet_failover $SINGLEMDS
278
279     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
280     if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
281                 error_and_remount "unlink succeeded unexpectedly"
282     fi
283 }
284 run_test 3b "unlink checks version of parent"
285
286 test_4a() { # former test_0h
287         local file=$DIR/$tfile
288         local pre
289         local post
290
291         do_node $CLIENT1 mcreate $file
292         pre=$(chk_get_version $CLIENT1 $file)
293         do_node $CLIENT1 chown $RUNAS_ID:$RUNAS_GID $file
294         post=$(chk_get_version $CLIENT1 $file)
295         if (($pre == $post)); then
296                 error "version not changed: pre $pre, post $post"
297         fi
298 }
299 run_test 4a "setattr of UID changes versions"
300
301 test_4b() { # former test_0i
302         local file=$DIR/$tfile
303         local pre
304         local post
305
306         do_node $CLIENT1 mcreate $file
307         pre=$(chk_get_version $CLIENT1 $file)
308         do_node $CLIENT1 chgrp $RUNAS_GID $file
309         post=$(chk_get_version $CLIENT1 $file)
310         if (($pre == $post)); then
311                 error "version not changed: pre $pre, post $post"
312         fi
313 }
314 run_test 4b "setattr of GID changes versions"
315
316 test_4c() { # former test_0j
317     local file=$DIR/$tfile
318     local var=${SINGLEMDS}_svc
319     zconf_mount $CLIENT2 $MOUNT2
320
321     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
322     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
323
324     do_node $CLIENT1 mcreate $file
325
326     replay_barrier $SINGLEMDS
327     do_node $CLIENT2 chgrp $RUNAS_GID $MOUNT2/$tfile
328     do_node $CLIENT1 chown $RUNAS_ID:$RUNAS_GID $file
329     zconf_umount $CLIENT2 $MOUNT2
330     facet_failover $SINGLEMDS
331
332     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
333     if ! do_node $CLIENT1 $CHECKSTAT -u \\\#$UID $file; then
334                 error_and_remount "setattr of UID succeeded unexpectedly"
335     fi
336 }
337 run_test 4c "setattr of UID checks versions"
338
339 test_4d() { # former test_0k
340     local file=$DIR/$tfile
341     local var=${SINGLEMDS}_svc
342     zconf_mount $CLIENT2 $MOUNT2
343
344     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
345     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
346
347     do_node $CLIENT1 mcreate $file
348
349     replay_barrier $SINGLEMDS
350     do_node $CLIENT2 chown $RUNAS_ID:$RUNAS_GID $MOUNT2/$tfile
351     do_node $CLIENT1 chgrp $RUNAS_GID $file
352     zconf_umount $CLIENT2 $MOUNT2
353     facet_failover $SINGLEMDS
354
355     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
356     if ! do_node $CLIENT1 $CHECKSTAT -g \\\#$UID $file; then
357                 error_and_remount "setattr of GID succeeded unexpectedly"
358     fi
359 }
360 run_test 4d "setattr of GID checks versions"
361
362 test_4e() { # former test_0l
363         local file=$DIR/$tfile
364         local pre
365         local post
366
367         do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
368         pre=$(chk_get_version $CLIENT1 $file)
369         do_node $CLIENT1 chmod 666 $file
370         post=$(chk_get_version $CLIENT1 $file)
371         if (($pre == $post)); then
372                 error "version not changed: pre $pre, post $post"
373         fi
374 }
375 run_test 4e "setattr of permission changes versions"
376
377 test_4f() { # former test_0m
378     local file=$DIR/$tfile
379     local var=${SINGLEMDS}_svc
380     zconf_mount $CLIENT2 $MOUNT2
381
382     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
383     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
384
385     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
386
387     replay_barrier $SINGLEMDS
388     do_node $CLIENT2 chgrp $RUNAS_GID $MOUNT2/$tfile
389     do_node $CLIENT1 chmod 666 $file
390     zconf_umount $CLIENT2 $MOUNT2
391     facet_failover $SINGLEMDS
392
393     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
394     if ! do_node $CLIENT1 $CHECKSTAT -p 0644 $file; then
395                 error_and_remount "setattr of permission succeeded unexpectedly"
396     fi
397 }
398 run_test 4f "setattr of permission checks versions"
399
400 test_4g() { # former test_0n
401         local file=$DIR/$tfile
402         local pre
403         local post
404
405         do_node $CLIENT1 mcreate $file
406         pre=$(chk_get_version $CLIENT1 $file)
407         do_node $CLIENT1 chattr +i $file
408         post=$(chk_get_version $CLIENT1 $file)
409         do_node $CLIENT1 chattr -i $file
410         if (($pre == $post)); then
411                 error "version not changed: pre $pre, post $post"
412         fi
413 }
414 run_test 4g "setattr of flags changes versions"
415
416 checkattr() {
417     local client=$1
418     local attr=$2
419     local file=$3
420     local rc
421
422     if ((${#attr} != 1)); then
423         error "checking multiple attributes not implemented yet"
424     fi
425     do_node $client lsattr $file | cut -d ' ' -f 1 | grep -q $attr
426 }
427
428 test_4h() { # former test_0o
429     local file=$DIR/$tfile
430     local rc
431     local var=${SINGLEMDS}_svc
432     zconf_mount $CLIENT2 $MOUNT2
433
434     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
435     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
436
437     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
438
439     replay_barrier $SINGLEMDS
440     do_node $CLIENT2 chmod 666 $MOUNT2/$tfile
441     do_node $CLIENT1 chattr +i $file
442     zconf_umount $CLIENT2 $MOUNT2
443     facet_failover $SINGLEMDS
444
445     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
446     checkattr $CLIENT1 i $file
447     rc=$?
448     do_node $CLIENT1 chattr -i $file
449     if [ $rc -eq 0 ]; then
450         error "setattr of flags succeeded unexpectedly"
451     fi
452 }
453 run_test 4h "setattr of flags checks versions"
454
455 test_4i() { # former test_0p
456         local file=$DIR/$tfile
457         local pre
458         local post
459         local ad_orig
460         local var=${SINGLEMDS}_svc
461
462         ad_orig=$(do_facet $SINGLEMDS "$LCTL get_param mdd.${!var}.atime_diff")
463         do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.atime_diff=0"
464         do_node $CLIENT1 mcreate $file
465         pre=$(chk_get_version $CLIENT1 $file)
466         do_node $CLIENT1 touch $file
467         post=$(chk_get_version $CLIENT1 $file)
468         #
469         # We don't fail MDS in this test.  atime_diff shall be
470         # restored to its original value.
471         #
472         do_facet $SINGLEMDS "$LCTL set_param $ad_orig"
473         if (($pre != $post)); then
474                 error "version changed unexpectedly: pre $pre, post $post"
475         fi
476 }
477 run_test 4i "setattr of times does not change versions"
478
479 test_4j() { # former test_0q
480         local file=$DIR/$tfile
481         local pre
482         local post
483
484         do_node $CLIENT1 mcreate $file
485         pre=$(chk_get_version $CLIENT1 $file)
486         do_node $CLIENT1 $TRUNCATE $file 1
487         post=$(chk_get_version $CLIENT1 $file)
488         if (($pre != $post)); then
489                 error "version changed unexpectedly: pre $pre, post $post"
490         fi
491 }
492 run_test 4j "setattr of size does not change versions"
493
494 test_4k() { # former test_0r
495     local file=$DIR/$tfile
496     local mtime_pre
497     local mtime_post
498     local mtime
499     local var=${SINGLEMDS}_svc
500     zconf_mount $CLIENT2 $MOUNT2
501
502     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
503     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.atime_diff=0"
504     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
505
506     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $file
507
508     replay_barrier $SINGLEMDS
509     do_node $CLIENT2 chmod 666 $MOUNT2/$tfile
510     do_node $CLIENT1 $TRUNCATE $file 1
511     sleep 1
512     mtime_pre=$(do_node $CLIENT1 stat --format=%Y $file)
513     do_node $CLIENT1 touch $file
514     sleep 1 # avoid stat caching
515     mtime_post=$(do_node $CLIENT1 stat --format=%Y $file)
516     zconf_umount $CLIENT2 $MOUNT2
517     facet_failover $SINGLEMDS
518
519     client_up $CLIENT1 || error "$CLIENT1 evicted"
520     if (($mtime_pre >= $mtime_post)); then
521         error "time not changed: pre $mtime_pre, post $mtime_post"
522     fi
523     if ! do_node $CLIENT1 $CHECKSTAT -s 1 $file; then
524                 error_and_remount "setattr of size failed"
525     fi
526     mtime=$(do_node $CLIENT1 stat --format=%Y $file)
527     if (($mtime != $mtime_post)); then
528         error "setattr of times failed: expected $mtime_post, got $mtime"
529     fi
530 }
531 run_test 4k "setattr of times and size does not check versions"
532
533 test_5a() { # former test_0s
534         local pre
535         local post
536         local tp_pre
537         local tp_post
538
539         do_node $CLIENT1 mcreate $DIR/$tfile
540         do_node $CLIENT1 mkdir -p $DIR/$tdir
541         pre=$(chk_get_version $CLIENT1 $DIR/$tfile)
542         tp_pre=$(chk_get_version $CLIENT1 $DIR/$tdir)
543         do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
544         post=$(chk_get_version $CLIENT1 $DIR/$tfile)
545         tp_post=$(chk_get_version $CLIENT1 $DIR/$tdir)
546         if (($pre == $post)); then
547                 error "version of source not changed: pre $pre, post $post"
548         fi
549         if (($tp_pre != $tp_post)); then
550                 error "version of target parent was changed:"\
551                         "pre $tp_pre, post $tp_post"
552         fi
553 }
554 run_test 5a "link changes versions of source but not target parent"
555
556 test_5b() { # former test_0t
557     local var=${SINGLEMDS}_svc
558     zconf_mount $CLIENT2 $MOUNT2
559
560     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
561     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
562
563     do_node $CLIENT1 mcreate $DIR/$tfile
564     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
565
566     replay_barrier $SINGLEMDS
567     do_node $CLIENT2 chmod 777 $MOUNT2/$tdir
568     do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
569     zconf_umount $CLIENT2 $MOUNT2
570     facet_failover $SINGLEMDS
571
572     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
573     if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
574                 error_and_remount "link should fail"
575     fi
576 }
577 run_test 5b "link checks version of target parent"
578
579 test_5c() { # former test_0u
580     local var=${SINGLEMDS}_svc
581     zconf_mount $CLIENT2 $MOUNT2
582
583     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
584     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
585
586     do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tfile
587     do_node $CLIENT1 mkdir -p $DIR/$tdir
588
589     replay_barrier $SINGLEMDS
590     do_node $CLIENT2 chmod 666 $MOUNT2/$tfile
591     do_node $CLIENT1 link $DIR/$tfile $DIR/$tdir/$tfile
592     zconf_umount $CLIENT2 $MOUNT2
593     facet_failover $SINGLEMDS
594
595     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
596     if ! do_node $CLIENT1 $CHECKSTAT -a $DIR/$tdir/$tfile; then
597                 error_and_remount "link should fail"
598     fi
599 }
600 run_test 5c "link checks version of source"
601
602 test_6a() { # former test_0v
603         local sp_pre
604         local tp_pre
605         local sp_post
606         local tp_post
607
608         do_node $CLIENT1 mcreate $DIR/$tfile
609         do_node $CLIENT1 mkdir -p $DIR/$tdir
610         sp_pre=$(chk_get_version $CLIENT1 $DIR)
611         tp_pre=$(chk_get_version $CLIENT1 $DIR/$tdir)
612         do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
613         sp_post=$(chk_get_version $CLIENT1 $DIR)
614         tp_post=$(chk_get_version $CLIENT1 $DIR/$tdir)
615         if (($sp_pre != $sp_post)); then
616                 error "version of source parent was changed:" \
617                         "pre $sp_pre, post $sp_post"
618         fi
619         if (($tp_pre != $tp_post)); then
620                 error "version of target parent was changed:" \
621                         "pre $tp_pre, post $tp_post"
622         fi
623 }
624 run_test 6a "rename doesn't change versions of source parent and target parent"
625
626 test_6b() { # former test_0w
627         local pre
628         local post
629
630         do_node $CLIENT1 mcreate $DIR/$tfile
631         pre=$(chk_get_version $CLIENT1 $DIR)
632         do_node $CLIENT1 mv $DIR/$tfile $DIR/$tfile-new
633         post=$(chk_get_version $CLIENT1 $DIR)
634         if (($pre != $post)); then
635                 error "version of parent was changed: pre $pre, post $post"
636         fi
637 }
638 run_test 6b "rename within same dir doesn't change version of parent"
639
640 test_6c() { # former test_0x
641     local var=${SINGLEMDS}_svc
642     zconf_mount $CLIENT2 $MOUNT2
643
644     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
645     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
646
647     do_node $CLIENT1 mcreate $DIR/$tfile
648     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
649
650     replay_barrier $SINGLEMDS
651     do_node $CLIENT2 chmod 777 $MOUNT2
652     do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
653     zconf_umount $CLIENT2 $MOUNT2
654     facet_failover $SINGLEMDS
655
656     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
657     if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tfile; then
658                 error_and_remount "rename should fail"
659     fi
660 }
661 run_test 6c "rename checks version of source parent"
662
663 test_6d() { # former test_0y
664     local var=${SINGLEMDS}_svc
665     zconf_mount $CLIENT2 $MOUNT2
666
667     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
668     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
669
670     do_node $CLIENT1 mcreate $DIR/$tfile
671     do_node $CLIENT1 mkdir -p -m 755 $DIR/$tdir
672
673     replay_barrier $SINGLEMDS
674     do_node $CLIENT2 chmod 777 $MOUNT2/$tdir
675     do_node $CLIENT1 mv $DIR/$tfile $DIR/$tdir/$tfile
676     zconf_umount $CLIENT2 $MOUNT2
677     facet_failover $SINGLEMDS
678
679     client_evicted $CLIENT1 || error "$CLIENT1 not evicted"
680     if do_node $CLIENT1 $CHECKSTAT -a $DIR/$tfile; then
681                 error_and_remount "rename should fail"
682     fi
683 }
684 run_test 6d "rename checks version of target parent"
685
686 # pdirops tests, bug 18143
687 cycle=0
688 test_7_cycle() {
689     local first=$1
690     local lost=$2
691     local last=$3
692     local rc=0
693     local var=${SINGLEMDS}_svc
694     zconf_mount $CLIENT2 $MOUNT2
695     cycle=$((cycle + 1))
696     local cname=$TESTNAME.$cycle
697
698     echo "start cycle: $cname"
699     do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
700     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
701
702     do_node $CLIENT1 mkdir -p $DIR/$tdir
703     replay_barrier $SINGLEMDS
704     # first operation
705     echo "$cname first: $first"
706     do_node $CLIENT1 $first || error "$cname: Cannot do first operation"
707     # client2 operations that will be lost
708     echo "$cname lost: $lost"
709     do_node $CLIENT2 $lost || error "$cname: Cannot do 'lost' operations"
710     # second operation
711     echo "$cname last: $last"
712     do_node $CLIENT1 $last || error "$cname: Cannot do last operation"
713     zconf_umount $CLIENT2 $MOUNT2
714     facet_failover $SINGLEMDS
715     # should fail as conflict expected
716     client_evicted $CLIENT1 || rc=1
717
718         wait_recovery_complete $SINGLEMDS
719         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
720
721         rm -rf $DIR/$tdir
722         return $rc
723 }
724
725 test_7a() {
726     first="createmany -o $DIR/$tdir/$tfile- 1"
727     lost="rm $MOUNT2/$tdir/$tfile-0"
728     last="createmany -o $DIR/$tdir/$tfile- 1"
729     test_7_cycle "$first" "$lost" "$last" || error "Test 7a.1 failed"
730
731     first="createmany -o $DIR/$tdir/$tfile- 1"
732     lost="rm $MOUNT2/$tdir/$tfile-0"
733     last="mkdir $DIR/$tdir/$tfile-0"
734     test_7_cycle "$first" "$lost" "$last" || error "Test 7a.2 failed"
735
736     first="mkdir $DIR/$tdir/$tfile-0"
737     lost="mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile-1"
738     last="createmany -o $DIR/$tdir/$tfile- 1"
739     test_7_cycle "$first" "$lost" "$last" || error "Test 7a.3 failed"
740     return 0
741 }
742 run_test 7a "create, {lost}, create"
743
744 test_7b() {
745     first="createmany -o $DIR/$tdir/$tfile- 1"
746     lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
747     last="rm $DIR/$tdir/$tfile-0"
748     test_7_cycle "$first" "$lost" "$last" || error "Test 7b.1 failed"
749
750     first="createmany -o $DIR/$tdir/$tfile- 1"
751     lost="touch $MOUNT2/$tdir/$tfile; mv $MOUNT2/$tdir/$tfile $MOUNT2/$tdir/$tfile-0"
752     last="rm $DIR/$tdir/$tfile-0"
753     test_7_cycle "$first" "$lost" "$last" || error "Test 7b.2 failed"
754
755     first="createmany -o $DIR/$tdir/$tfile- 1"
756     lost="rm $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
757     last="rmdir $DIR/$tdir/$tfile-0"
758     test_7_cycle "$first" "$lost" "$last" || error "Test 7b.3 failed"
759     return 0
760 }
761 run_test 7b "create, {lost}, unlink"
762
763 test_7c() {
764     first="createmany -o $DIR/$tdir/$tfile- 1"
765     lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
766     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
767     test_7_cycle "$first" "$lost" "$last" || error "Test 7c.1 failed"
768
769     first="createmany -o $DIR/$tdir/$tfile- 2"
770     lost="rm $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
771     last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
772     test_7_cycle "$first" "$lost" "$last" || error "Test 7c.2 failed"
773
774     first="createmany -o $DIR/$tdir/$tfile- 1; mkdir $DIR/$tdir/$tfile-1-0"
775     lost="rmdir $MOUNT2/$tdir/$tfile-1-0; createmany -o $MOUNT2/$tdir/$tfile-1- 1"
776     last="mv $DIR/$tdir/$tfile-1-0 $DIR/$tdir/$tfile-0"
777     test_7_cycle "$first" "$lost" "$last" || error "Test 7c.3 failed"
778
779     first="createmany -o $DIR/$tdir/$tfile- 1"
780     lost="mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile"
781     last="mv $DIR/$tdir/$tfile $DIR/$tdir/$tfile-0"
782     test_7_cycle "$first" "$lost" "$last" || error "Test 7c.4 failed"
783     return 0
784 }
785 run_test 7c "create, {lost}, rename"
786
787 test_7d() {
788     first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
789     lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0"
790     last="createmany -o $DIR/$tdir/$tfile- 1"
791     test_7_cycle "$first" "$lost" "$last" && error "Test 7d.1 failed"
792
793     first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
794     lost="mkdir $MOUNT2/$tdir/$tfile-0; rmdir $MOUNT2/$tdir/$tfile-0"
795     last="mkdir $DIR/$tdir/$tfile-0"
796     test_7_cycle "$first" "$lost" "$last" && error "Test 7d.2 failed"
797
798     first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
799     lost="createmany -o $MOUNT2/$tdir/$tfile- 1; mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile-1"
800     last="createmany -o $DIR/$tdir/$tfile- 1"
801     test_7_cycle "$first" "$lost" "$last" && error "Test 7d.3 failed"
802     return 0
803 }
804 run_test 7d "unlink, {lost}, create"
805
806 test_7e() {
807     first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
808     lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0;createmany -o $MOUNT2/$tdir/$tfile- 1"
809     last="rm $DIR/$tdir/$tfile-0"
810     test_7_cycle "$first" "$lost" "$last" || error "Test 7e.1 failed"
811
812     first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
813     lost="mkdir $MOUNT2/$tdir/$tfile-0; rmdir $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
814     last="rmdir $DIR/$tdir/$tfile-0"
815     test_7_cycle "$first" "$lost" "$last" || error "Test 7e.2 failed"
816
817     first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
818     lost="mkdir $MOUNT2/$tdir/$tfile-0"
819     last="rmdir $DIR/$tdir/$tfile-0"
820     test_7_cycle "$first" "$lost" "$last" || error "Test 7e.3 failed"
821
822     first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
823     lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
824     last="rm $DIR/$tdir/$tfile-0"
825     test_7_cycle "$first" "$lost" "$last" || error "Test 7e.4 failed"
826
827     first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
828     lost="mv $MOUNT2/$tdir/$tfile-1 $MOUNT2/$tdir/$tfile-0"
829     last="rm $DIR/$tdir/$tfile-0"
830     test_7_cycle "$first" "$lost" "$last" || error "Test 7e.5 failed"
831     return 0
832 }
833 run_test 7e "unlink, {lost}, unlink"
834
835 test_7f() {
836     first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
837     lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
838     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
839     test_7_cycle "$first" "$lost" "$last" || error "Test 7f.1 failed"
840
841     first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
842     lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
843     last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
844     test_7_cycle "$first" "$lost" "$last" || error "Test 7f.2 failed"
845
846     first="mkdir $DIR/$tdir/$tfile; createmany -o $DIR/$tdir/$tfile- 1; rmdir $DIR/$tdir/$tfile"
847     lost="mkdir $MOUNT2/$tdir/$tfile"
848     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
849     test_7_cycle "$first" "$lost" "$last" || error "Test 7f.3 failed"
850
851     first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
852     lost="mv $MOUNT2/$tdir/$tfile-1 $MOUNT2/$tdir/$tfile-0"
853     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
854     test_7_cycle "$first" "$lost" "$last" || error "Test 7f.4 failed"
855
856     first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
857     lost="mkdir $MOUNT2/$tdir/$tfile-0"
858     last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
859     test_7_cycle "$first" "$lost" "$last" || error "Test 7f.5 failed"
860     return 0
861 }
862 run_test 7f "unlink, {lost}, rename"
863
864 test_7g() {
865         first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
866         lost="mkdir $MOUNT2/$tdir/$tfile-0;rmdir $MOUNT2/$tdir/$tfile-0"
867         last="createmany -o $DIR/$tdir/$tfile- 1"
868         test_7_cycle "$first" "$lost" "$last" && error "Test 7g.1 failed"
869
870         first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
871         lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0"
872         last="mkdir $DIR/$tdir/$tfile-0"
873         test_7_cycle "$first" "$lost" "$last" && error "Test 7g.2 failed"
874
875         first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
876         lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
877         last="link $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
878         if [ "$MDS1_VERSION" -lt $(version_code 2.5.1) ]; then
879                 test_7_cycle "$first" "$lost" "$last" ||
880                         error "Test 7g.3 failed"
881         else #LU-4442 LU-3528
882                 test_7_cycle "$first" "$lost" "$last" &&
883                         error "Test 7g.3 failed"
884         fi
885     return 0
886 }
887 run_test 7g "rename, {lost}, create"
888
889 test_7h() {
890     first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
891     lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
892     last="rm $DIR/$tdir/$tfile-0"
893     test_7_cycle "$first" "$lost" "$last" || error "Test 7h.1 failed"
894
895     first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
896     lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
897     last="rm $DIR/$tdir/$tfile-0"
898     test_7_cycle "$first" "$lost" "$last" || error "Test 7h.2 failed"
899
900     first="createmany -o $DIR/$tdir/$tfile- 1; mkdir  $DIR/$tdir/$tfile; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
901     lost="rm $MOUNT2/$tdir/$tfile/$tfile-0"
902     last="rmdir $DIR/$tdir/$tfile"
903     #test_7_cycle "$first" "$lost" "$last" || error "Test 7h.3 failed"
904     return 0
905 }
906 run_test 7h "rename, {lost}, unlink"
907
908 test_7i() {
909     first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
910     lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
911     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
912     test_7_cycle "$first" "$lost" "$last" || error "Test 7i.1 failed"
913
914     first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
915     lost="mkdir $MOUNT2/$tdir/$tfile-0"
916     last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
917     test_7_cycle "$first" "$lost" "$last" || error "Test 7i.1 failed"
918
919     first="createmany -o $DIR/$tdir/$tfile- 3; mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
920     lost="mv $MOUNT2/$tdir/$tfile-2 $MOUNT2/$tdir/$tfile-0"
921     last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-2"
922     test_7_cycle "$first" "$lost" "$last" || error "Test 7i.3 failed"
923
924     first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
925     lost="rm $MOUNT2/$tdir/$tfile-1"
926     last="mv $DIR/$tdir/$tfile $DIR/$tdir/$tfile-1"
927     test_7_cycle "$first" "$lost" "$last" || error "Test 7i.4 failed"
928     return 0
929 }
930 run_test 7i "rename, {lost}, rename"
931
932 # test set #8: orphan handling bug 15392.
933 # Unlink during recovery creates orphan always just in case some late open may
934 # arrive. These orphans will be removed after recovery anyway.
935 # Tests check that valid create,unlink,create sequence will work in this case
936 # too but not fail on second create due to orphan found.
937
938 test_8a() {
939     local var=${SINGLEMDS}_svc
940     zconf_mount $CLIENT2 $MOUNT2
941
942     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
943
944     do_node $CLIENT1 mcreate $DIR/$tfile
945     do_node $CLIENT1 mkdir $DIR/$tfile-2
946     replay_barrier $SINGLEMDS
947     # missed replay from client2 will lead to recovery by versions
948     do_node $CLIENT2 touch $MOUNT2/$tfile-2/$tfile
949     do_node $CLIENT1 rm $DIR/$tfile || return 1
950     do_node $CLIENT1 touch $DIR/$tfile || return 2
951
952     zconf_umount $CLIENT2 $MOUNT2
953     facet_failover $SINGLEMDS
954     client_up $CLIENT1 || return 6
955
956     do_node $CLIENT1 rm $DIR/$tfile || error "$tfile doesn't exists"
957     return 0
958 }
959 run_test 8a "create | unlink, create shouldn't fail"
960
961 test_8b() {
962     local var=${SINGLEMDS}_svc
963     zconf_mount $CLIENT2 $MOUNT2
964
965     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
966
967     do_node $CLIENT1 touch $DIR/$tfile
968     do_node $CLIENT1 mkdir $DIR/$tfile-2
969     replay_barrier $SINGLEMDS
970     # missed replay from client2 will lead to recovery by versions
971     do_node $CLIENT2 touch $MOUNT2/$tfile-2/$tfile
972     do_node $CLIENT1 rm -f $MOUNT1/$tfile || return 1
973     do_node $CLIENT1 mcreate $MOUNT1/$tfile || return 2
974
975     zconf_umount $CLIENT2 $MOUNT2
976     facet_failover $SINGLEMDS
977     client_up $CLIENT1 || return 6
978
979     do_node $CLIENT1 rm $MOUNT1/$tfile || error "$tfile doesn't exists"
980     return 0
981 }
982 run_test 8b "create | unlink, create shouldn't fail"
983
984 test_8c() {
985     local var=${SINGLEMDS}_svc
986     zconf_mount $CLIENT2 $MOUNT2
987
988     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
989
990     do_node $CLIENT1 touch $DIR/$tfile
991     do_node $CLIENT1 mkdir $DIR/$tfile-2
992     replay_barrier $SINGLEMDS
993     # missed replay from client2 will lead to recovery by versions
994     do_node $CLIENT2 touch $MOUNT2/$tfile-2/$tfile
995     do_node $CLIENT1 rm -f $MOUNT1/$tfile || return 1
996     do_node $CLIENT1 mkdir $MOUNT1/$tfile || return 2
997
998     zconf_umount $CLIENT2 $MOUNT2
999     facet_failover $SINGLEMDS
1000     client_up $CLIENT1 || return 6
1001
1002     do_node $CLIENT1 rmdir $MOUNT1/$tfile || error "$tfile doesn't exists"
1003     return 0
1004 }
1005 run_test 8c "create | unlink, create shouldn't fail"
1006
1007 #
1008 # This test uses three Lustre clients on two hosts.
1009 #
1010 #   Lustre Client 1:    $CLIENT1:$MOUNT     ($DIR)
1011 #   Lustre Client 2:    $CLIENT2:$MOUNT2    ($DIR2)
1012 #   Lustre Client 3:    $CLIENT2:$MOUNT1    ($DIR1)
1013 #
1014 test_10b() { # former test_2b
1015         local pre
1016         local post
1017         local var=${SINGLEMDS}_svc
1018
1019         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && exit 0; }
1020         [ $CLIENTCOUNT -ge 2 ] || \
1021                 { skip "Need two or more clients, have $CLIENTCOUNT" && \
1022                         exit 0; }
1023
1024         do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
1025         do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
1026
1027         zconf_mount $CLIENT1 $MOUNT
1028         zconf_mount $CLIENT2 $MOUNT1
1029         zconf_mount $CLIENT2 $MOUNT2
1030         do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tfile-a
1031         do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tfile-b
1032
1033         #
1034         # Save an MDT transaction number before recovery.
1035         #
1036         do_node $CLIENT1 touch $DIR1/$tfile
1037         pre=$(chk_get_version $CLIENT1 $DIR/$tfile)
1038
1039         #
1040         # Comments on the replay sequence state the expected result
1041         # of each request.
1042         #
1043         #   "R"     Replayed.
1044         #   "U"     Unable to replay.
1045         #   "J"     Rejected.
1046         #
1047         replay_barrier $SINGLEMDS
1048         do_node $CLIENT1 chmod 666 $DIR/$tfile-a            # R
1049         do_node $CLIENT2 chmod 666 $DIR1/$tfile-b           # R
1050         do_node $CLIENT2 chgrp $RUNAS_GID $DIR2/$tfile-a    # U
1051         do_node $CLIENT1 chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile-a      # J
1052         do_node $CLIENT2 $TRUNCATE $DIR2/$tfile-b 1          # U
1053         do_node $CLIENT2 chgrp $RUNAS_GID $DIR1/$tfile-b    # R
1054         do_node $CLIENT1 chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile-b      # R
1055         zconf_umount $CLIENT2 $MOUNT2
1056         facet_failover $SINGLEMDS
1057
1058         client_evicted $CLIENT1 || error "$CLIENT1:$MOUNT not evicted"
1059         client_up $CLIENT2 || error "$CLIENT2:$MOUNT1 evicted"
1060
1061         #
1062         # Check the MDT epoch.  $post must be the first transaction
1063         # number assigned after recovery.
1064         #
1065         do_node $CLIENT2 chmod 666 $DIR1/$tfile
1066         post=$(chk_get_version $CLIENT2 $DIR1/$tfile)
1067         if (($(($pre >> 32)) == $((post >> 32)))); then
1068                 error "epoch not changed: pre $pre, post $post"
1069         fi
1070
1071         if (($(($post & 0x00000000ffffffff)) != 1)); then
1072                 error "transno should restart from one: got $post"
1073         fi
1074
1075         do_node $CLIENT2 stat $DIR1/$tfile-a
1076         do_node $CLIENT2 stat $DIR1/$tfile-b
1077
1078         do_node $CLIENT2 $CHECKSTAT -p 0666 -u \\\#$UID -g \\\#$UID \
1079                 $DIR1/$tfile-a || error "$DIR/$tfile-a: unexpected state"
1080         do_node $CLIENT2 $CHECKSTAT -p 0666 -u \\\#$RUNAS_ID -g \\\#$RUNAS_GID \
1081                 $DIR1/$tfile-b || error "$DIR/$tfile-b: unexpected state"
1082
1083         zconf_umount $CLIENT2 $MOUNT1
1084 }
1085 run_test 10b "3 clients: some, none, and all reqs replayed"
1086
1087 # test set #11: operations in single directory
1088 test_11a() {
1089     local var=${SINGLEMDS}_svc
1090     zconf_mount $CLIENT2 $MOUNT2
1091
1092     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
1093
1094     replay_barrier $SINGLEMDS
1095
1096     do_node $CLIENT1 createmany -o $DIR/$tfile-1- 100 &
1097     PID=$!
1098     do_node $CLIENT2 createmany -o $MOUNT2/$tfile-2- 100
1099     zconf_umount $CLIENT2 $MOUNT2
1100     wait $PID
1101
1102     facet_failover $SINGLEMDS
1103     # recovery shouldn't fail due to missing client 2
1104     client_up $CLIENT1 || return 1
1105     # All files from client1 should have been replayed
1106     do_node $CLIENT1 unlinkmany $DIR/$tfile-1- 100 || return 2
1107
1108     [ -e $DIR/$tdir/$tfile-2-0 ] && error "$tfile-2-0 exists"
1109     return 0
1110 }
1111 run_test 11a "concurrent creates don't affect each other"
1112
1113 test_11b() {
1114     local var=${SINGLEMDS}_svc
1115     zconf_mount $CLIENT2 $MOUNT2
1116
1117     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
1118
1119     do_node $CLIENT2 createmany -o $MOUNT2/$tfile-2- 100
1120
1121     replay_barrier $SINGLEMDS
1122     do_node $CLIENT1 createmany -o $DIR/$tfile-1- 100 &
1123     PID=$!
1124     do_node $CLIENT2 unlinkmany -o $MOUNT2/$tfile-2- 100
1125     zconf_umount $CLIENT2 $MOUNT2
1126     wait $PID
1127
1128     facet_failover $SINGLEMDS
1129     # recovery shouldn't fail due to missing client 2
1130     client_up $CLIENT1 || return 1
1131     # All files from client1 should have been replayed
1132     do_node $CLIENT1 unlinkmany $DIR/$tfile-1- 100 || return 2
1133
1134     [ -e $DIR/$tdir/$tfile-2-0 ] && error "$tfile-2-0 exists"
1135     return 0
1136 }
1137 run_test 11b "concurrent creates and unlinks don't affect each other"
1138
1139 # test set #12: lock replay with VBR, bug 16356
1140 test_12a() { # former test_2a
1141     local var=${SINGLEMDS}_svc
1142     zconf_mount $CLIENT2 $MOUNT2
1143
1144     do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
1145
1146     do_node $CLIENT2 mkdir -p $MOUNT2/$tdir
1147     replay_barrier $SINGLEMDS
1148     do_node $CLIENT2 mcreate $MOUNT2/$tdir/$tfile
1149     do_node $CLIENT1 createmany -o $DIR/$tfile- 25
1150     #client1 read data from client2 which will be lost
1151     do_node $CLIENT1 $CHECKSTAT $DIR/$tdir/$tfile
1152     do_node $CLIENT1 createmany -o $DIR/$tfile-3- 25
1153     zconf_umount $CLIENT2 $MOUNT2
1154
1155     facet_failover $SINGLEMDS
1156     # recovery shouldn't fail due to missing client 2
1157     client_up $CLIENT1 || return 1
1158
1159     # All 50 files should have been replayed
1160     do_node $CLIENT1 unlinkmany $DIR/$tfile- 25 || return 2
1161     do_node $CLIENT1 unlinkmany $DIR/$tfile-3- 25 || return 3
1162     do_node $CLIENT1 $CHECKSTAT $DIR/$tdir/$tfile && return 4
1163
1164     return 0
1165 }
1166 run_test 12a "lost data due to missed REMOTE client during replay"
1167
1168 test_13() { # LU-8826
1169         local var=${SINGLEMDS}_svc
1170
1171         if combined_mgs_mds ; then
1172                 skip "Needs separate MGS to enable IR"
1173                 return 0
1174         fi
1175
1176         do_facet $SINGLEMDS "$LCTL set_param mdd.${!var}.sync_permission=0"
1177         do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
1178
1179         zconf_mount $CLIENT2 $MOUNT2
1180         do_node $CLIENT1 openfile -f O_RDWR:O_CREAT -m 0644 $DIR/$tfile
1181
1182         # set ir_timeout to a reasonable small value
1183         local ir_timeout=$(do_facet mgs $LCTL get_param -n mgs.*.ir_timeout)
1184         do_facet mgs $LCTL set_param mgs.*.ir_timeout=5
1185         # make sure IR functional
1186         sleep 5
1187
1188         replay_barrier $SINGLEMDS
1189         do_node $CLIENT1 chmod 666 $DIR/$tfile
1190         do_node $CLIENT2 chmod 777 $DIR2/$tfile
1191
1192         # make sure client data of $CLIENT2:$MOUNT2 is remained
1193         # define OBD_FAIL_TGT_CLIENT_DEL        0x718
1194         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x718
1195         zconf_umount $CLIENT2 $MOUNT2
1196         # define OBD_FAIL_TGT_SLUGGISH_NET      0x719
1197         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x719
1198         facet_failover $SINGLEMDS
1199
1200         client_up $CLIENT1 || error "$CLIENT1 evicted"
1201
1202         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1203         do_facet mgs $LCTL set_param mgs.*.ir_timeout=$ir_timeout
1204
1205         do_node $CLIENT1 $CHECKSTAT -p 0666 $DIR/$tfile ||
1206                 error "$DIR/$tfile-a: unexpected state"
1207 }
1208 run_test 13 "Shouldn't give up VBR easily on sluggish network"
1209
1210 #restore COS setting
1211 restore_lustre_params < $cos_param_file
1212 rm -f $cos_param_file
1213
1214 [ "$CLIENTS" ] && zconf_mount_clients $CLIENTS $DIR
1215
1216 complete $SECONDS
1217 check_and_cleanup_lustre
1218 exit_status