1716fd348SMartin Matuska /*
2716fd348SMartin Matuska * CDDL HEADER START
3716fd348SMartin Matuska *
4716fd348SMartin Matuska * The contents of this file are subject to the terms of the
5716fd348SMartin Matuska * Common Development and Distribution License (the "License").
6716fd348SMartin Matuska * You may not use this file except in compliance with the License.
7716fd348SMartin Matuska *
8716fd348SMartin Matuska * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0.
10716fd348SMartin Matuska * See the License for the specific language governing permissions
11716fd348SMartin Matuska * and limitations under the License.
12716fd348SMartin Matuska *
13716fd348SMartin Matuska * When distributing Covered Code, include this CDDL HEADER in each
14716fd348SMartin Matuska * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15716fd348SMartin Matuska * If applicable, add the following below this CDDL HEADER, with the
16716fd348SMartin Matuska * fields enclosed by brackets "[]" replaced with your own identifying
17716fd348SMartin Matuska * information: Portions Copyright [yyyy] [name of copyright owner]
18716fd348SMartin Matuska *
19716fd348SMartin Matuska * CDDL HEADER END
20716fd348SMartin Matuska */
21716fd348SMartin Matuska
22716fd348SMartin Matuska /*
23716fd348SMartin Matuska * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24716fd348SMartin Matuska * Use is subject to license terms.
25716fd348SMartin Matuska */
26716fd348SMartin Matuska
27716fd348SMartin Matuska /*
28716fd348SMartin Matuska * Copyright (c) 2012 by Delphix. All rights reserved.
29716fd348SMartin Matuska */
30716fd348SMartin Matuska
31716fd348SMartin Matuska /*
32716fd348SMartin Matuska * Assertion:
33716fd348SMartin Matuska * Create two directory trees in zfs filesystem, and rename
34716fd348SMartin Matuska * directory across the directory structure. ZFS can handle
35716fd348SMartin Matuska * the race situation.
36716fd348SMartin Matuska */
37716fd348SMartin Matuska
38716fd348SMartin Matuska /*
39716fd348SMartin Matuska * Need to create the following directory structures before
40716fd348SMartin Matuska * running this program:
41716fd348SMartin Matuska *
42716fd348SMartin Matuska * mkdir -p 1/2/3/4/5 a/b/c/d/e
43716fd348SMartin Matuska */
44716fd348SMartin Matuska
45716fd348SMartin Matuska
46716fd348SMartin Matuska #include <stdlib.h>
47716fd348SMartin Matuska #include <unistd.h>
48716fd348SMartin Matuska #include <stdio.h>
49716fd348SMartin Matuska
50716fd348SMartin Matuska int
main(void)51716fd348SMartin Matuska main(void)
52716fd348SMartin Matuska {
53716fd348SMartin Matuska int i = 1;
54716fd348SMartin Matuska
55716fd348SMartin Matuska switch (fork()) {
56716fd348SMartin Matuska case -1:
57716fd348SMartin Matuska perror("fork");
58716fd348SMartin Matuska exit(1);
59716fd348SMartin Matuska break;
60716fd348SMartin Matuska
61716fd348SMartin Matuska case 0:
62716fd348SMartin Matuska while (i > 0) {
63716fd348SMartin Matuska int c_count = 0;
64716fd348SMartin Matuska if (rename("a/b/c", "1/2/3/c") == 0)
65716fd348SMartin Matuska c_count++;
66716fd348SMartin Matuska if (rename("1/2/3/c", "a/b/c") == 0)
67716fd348SMartin Matuska c_count++;
68716fd348SMartin Matuska if (c_count)
69716fd348SMartin Matuska (void) fprintf(stderr, "c_count: %d", c_count);
70716fd348SMartin Matuska }
71716fd348SMartin Matuska _exit(0);
72716fd348SMartin Matuska
73716fd348SMartin Matuska default:
74716fd348SMartin Matuska while (i > 0) {
75716fd348SMartin Matuska int p_count = 0;
76716fd348SMartin Matuska if (rename("1", "a/b/c/d/e/1") == 0)
77716fd348SMartin Matuska p_count++;
78716fd348SMartin Matuska if (rename("a/b/c/d/e/1", "1") == 0)
79716fd348SMartin Matuska p_count++;
80716fd348SMartin Matuska if (p_count)
81716fd348SMartin Matuska (void) fprintf(stderr, "p_count: %d", p_count);
82716fd348SMartin Matuska }
83716fd348SMartin Matuska return (0);
84716fd348SMartin Matuska }
85716fd348SMartin Matuska }
86