Fix readonly check for vdev user properties
[zfs.git] / tests / zfs-tests / cmd / dir_rd_update.c
blobc0d283105a925f062920531ebcf508ef0cfbad69
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Assertion:
30 * A read operation and directory update operation performed
31 * concurrently on the same directory can lead to deadlock
32 * on a UFS logging file system, but not on a ZFS file system.
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <errno.h>
38 #include <fcntl.h>
39 #include <string.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #define TMP_DIR /tmp
45 static char dirpath[256];
47 int
48 main(int argc, char **argv)
50 const char *cp1 = "";
51 int i = 0;
52 int ret = 0;
53 int testdd = 0;
54 pid_t pid;
55 static const int op_num = 5;
57 if (argc == 1) {
58 (void) printf("Usage: %s <mount point>\n", argv[0]);
59 exit(-1);
61 for (i = 0; i < 256; i++) {
62 dirpath[i] = 0;
65 cp1 = argv[1];
66 if (strlen(cp1) >= (sizeof (dirpath) - strlen("/TMP_DIR"))) {
67 (void) printf("The string length of mount point is "
68 "too large\n");
69 exit(-1);
71 (void) snprintf(dirpath, sizeof (dirpath), "%s/TMP_DIR", cp1);
73 ret = mkdir(dirpath, 0777);
74 if (ret != 0) {
75 if (errno != EEXIST) {
76 (void) printf("%s: mkdir(<%s>, 0777) failed: errno "
77 "(decimal)=%d\n", argv[0], dirpath, errno);
78 exit(-1);
81 testdd = open(dirpath, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC);
82 if (testdd < 0) {
83 (void) printf("%s: open(<%s>, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC)"
84 " failed: errno (decimal)=%d\n", argv[0], dirpath, errno);
85 exit(-1);
86 } else {
87 (void) close(testdd);
89 pid = fork();
90 if (pid > 0) {
91 int fd = open(dirpath, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC);
92 char buf[16];
93 int rdret;
94 int j = 0;
96 if (fd < 0) {
97 (void) printf("%s: open <%s> again failed:"
98 " errno = %d\n", argv[0], dirpath, errno);
99 exit(-1);
102 while (j < op_num) {
103 (void) sleep(1);
104 rdret = read(fd, buf, 16);
105 if (rdret == -1) {
106 (void) printf("readdir failed");
108 j++;
110 (void) close(fd);
111 } else if (pid == 0) {
112 int fd = open(dirpath, O_RDONLY);
113 int chownret;
114 int k = 0;
116 if (fd < 0) {
117 (void) printf("%s: open(<%s>, O_RDONLY) again failed:"
118 " errno (decimal)=%d\n", argv[0], dirpath, errno);
119 exit(-1);
122 while (k < op_num) {
123 (void) sleep(1);
124 chownret = fchown(fd, 0, 0);
125 if (chownret == -1) {
126 (void) printf("chown failed");
129 k++;
131 (void) close(fd);
134 return (0);