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