+ rm -rf $DIR/$tdir
+ return $rc
+}
+
+test_7a() {
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="rm $MOUNT2/$tdir/$tfile-0"
+ last="createmany -o $DIR/$tdir/$tfile- 1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7a.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="rm $MOUNT2/$tdir/$tfile-0"
+ last="mkdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7a.2 failed"
+
+ first="mkdir $DIR/$tdir/$tfile-0"
+ lost="mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile-1"
+ last="createmany -o $DIR/$tdir/$tfile- 1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7a.3 failed"
+ return 0
+}
+run_test 7a "create, {lost}, create"
+
+test_7b() {
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7b.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="touch $MOUNT2/$tdir/$tfile; mv $MOUNT2/$tdir/$tfile $MOUNT2/$tdir/$tfile-0"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7b.2 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="rm $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
+ last="rmdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7b.3 failed"
+ return 0
+}
+run_test 7b "create, {lost}, unlink"
+
+test_7c() {
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7c.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2"
+ lost="rm $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
+ last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7c.2 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; mkdir $DIR/$tdir/$tfile-1-0"
+ lost="rmdir $MOUNT2/$tdir/$tfile-1-0; createmany -o $MOUNT2/$tdir/$tfile-1- 1"
+ last="mv $DIR/$tdir/$tfile-1-0 $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7c.3 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1"
+ lost="mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile"
+ last="mv $DIR/$tdir/$tfile $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7c.4 failed"
+ return 0
+}
+run_test 7c "create, {lost}, rename"
+
+test_7d() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0"
+ last="createmany -o $DIR/$tdir/$tfile- 1"
+ test_7_cycle "$first" "$lost" "$last" && error "Test 7d.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0; rmdir $MOUNT2/$tdir/$tfile-0"
+ last="mkdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" && error "Test 7d.2 failed"
+
+ first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1; mv $MOUNT2/$tdir/$tfile-0 $MOUNT2/$tdir/$tfile-1"
+ last="createmany -o $DIR/$tdir/$tfile- 1"
+ test_7_cycle "$first" "$lost" "$last" && error "Test 7d.3 failed"
+ return 0
+}
+run_test 7d "unlink, {lost}, create"
+
+test_7e() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0;createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7e.1 failed"
+
+ first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0; rmdir $MOUNT2/$tdir/$tfile-0; mkdir $MOUNT2/$tdir/$tfile-0"
+ last="rmdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7e.2 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0"
+ last="rmdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7e.3 failed"
+
+ first="mkdir $DIR/$tdir/$tfile-0; rmdir $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7e.4 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
+ lost="mv $MOUNT2/$tdir/$tfile-1 $MOUNT2/$tdir/$tfile-0"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7e.5 failed"
+ return 0
+}
+run_test 7e "unlink, {lost}, unlink"
+
+test_7f() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; rm $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7f.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7f.2 failed"
+
+ first="mkdir $DIR/$tdir/$tfile; createmany -o $DIR/$tdir/$tfile- 1; rmdir $DIR/$tdir/$tfile"
+ lost="mkdir $MOUNT2/$tdir/$tfile"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7f.3 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
+ lost="mv $MOUNT2/$tdir/$tfile-1 $MOUNT2/$tdir/$tfile-0"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7f.4 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; rm $DIR/$tdir/$tfile-0"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0"
+ last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7f.5 failed"
+ return 0
+}
+run_test 7f "unlink, {lost}, rename"
+
+test_7g() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0;rmdir $MOUNT2/$tdir/$tfile-0"
+ last="createmany -o $DIR/$tdir/$tfile- 1"
+ test_7_cycle "$first" "$lost" "$last" && error "Test 7g.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1; rm $MOUNT2/$tdir/$tfile-0"
+ last="mkdir $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" && error "Test 7g.2 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="link $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7g.3 failed"
+ return 0
+}
+run_test 7g "rename, {lost}, create"
+
+test_7h() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7h.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ lost="rm $MOUNT2/$tdir/$tfile-0; createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="rm $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7h.2 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; mkdir $DIR/$tdir/$tfile; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
+ lost="rm $MOUNT2/$tdir/$tfile/$tfile-0"
+ last="rmdir $DIR/$tdir/$tfile"
+ #test_7_cycle "$first" "$lost" "$last" || error "Test 7h.3 failed"
+ return 0
+}
+run_test 7h "rename, {lost}, unlink"
+
+test_7i() {
+ first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ lost="createmany -o $MOUNT2/$tdir/$tfile- 1"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7i.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 1; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-1"
+ lost="mkdir $MOUNT2/$tdir/$tfile-0"
+ last="mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7i.1 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 3; mv $DIR/$tdir/$tfile-1 $DIR/$tdir/$tfile-0"
+ lost="mv $MOUNT2/$tdir/$tfile-2 $MOUNT2/$tdir/$tfile-0"
+ last="mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile-2"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7i.3 failed"
+
+ first="createmany -o $DIR/$tdir/$tfile- 2; mv $DIR/$tdir/$tfile-0 $DIR/$tdir/$tfile"
+ lost="rm $MOUNT2/$tdir/$tfile-1"
+ last="mv $DIR/$tdir/$tfile $DIR/$tdir/$tfile-1"
+ test_7_cycle "$first" "$lost" "$last" || error "Test 7i.4 failed"
+ return 0
+}
+run_test 7i "rename, {lost}, rename"
+
+# test set #8: orphan handling bug 15392.
+# Unlink during recovery creates orphan always just in case some late open may
+# arrive. These orphans will be removed after recovery anyway.
+# Tests check that valid create,unlink,create sequence will work in this case
+# too but not fail on second create due to orphan found.
+
+test_8a() {
+ local var=${SINGLEMDS}_svc
+ zconf_mount $CLIENT2 $MOUNT2
+
+ do_facet $SINGLEMDS "$LCTL set_param mdt.${!var}.commit_on_sharing=0"
+
+ do_node $CLIENT1 mcreate $DIR/$tfile
+ do_node $CLIENT1 mkdir $DIR/$tfile-2
+ replay_barrier $SINGLEMDS
+ # missed replay from client2 will lead to recovery by versions
+ do_node $CLIENT2 touch $MOUNT2/$tfile-2/$tfile
+ do_node $CLIENT1 rm $DIR/$tfile || return 1
+ do_node $CLIENT1 touch $DIR/$tfile || return 2
+
+ zconf_umount $CLIENT2 $MOUNT2
+ facet_failover $SINGLEMDS
+ client_up $CLIENT1 || return 6