1 /* $NetBSD: t_renamerace.c,v 1.32 2014/07/29 09:15:48 gson Exp $ */
4 * Modified for rump and atf from a program supplied
5 * by Nicolas Joly in kern/40948
10 #include <sys/utsname.h>
21 #include <rump/rump.h>
22 #include <rump/rump_syscalls.h>
24 /* Bump the size of the test file system image to a larger value.
26 * These tests cause a lot of churn in the file system by creating and
27 * deleting files/directories in quick succession. A faster CPU will cause
28 * more churn because the tests are capped by a run time period in seconds,
29 * not number of operations.
31 * This is all fine except for LFS, because the lfs_cleanerd cannot keep up
32 * with the churn and thus causes the test to fail on fast machines. Hence
33 * the reason for this hack. */
34 #define FSTEST_IMGSIZE (50000 * 512)
36 #include "../common/h_fsmacros.h"
37 #include "../../h_macros.h"
39 static volatile int quittingtime
;
47 rump_pub_lwproc_newlwp(wrkpid
);
49 while (!quittingtime
) {
50 fd
= rump_sys_open("rename.test1",
51 O_WRONLY
|O_CREAT
|O_TRUNC
, 0666);
52 if (fd
== -1 && errno
!= EEXIST
)
53 atf_tc_fail_errno("create");
54 rump_sys_unlink("rename.test1");
65 rump_pub_lwproc_newlwp(wrkpid
);
67 while (!quittingtime
) {
68 if (rump_sys_mkdir("rename.test1", 0777) == -1)
69 atf_tc_fail_errno("mkdir");
70 rump_sys_rmdir("rename.test1");
80 rump_pub_lwproc_newlwp(wrkpid
);
82 while (!quittingtime
) {
83 rump_sys_rename("rename.test1", "rename.test2");
91 renamerace(const atf_tc_t
*tc
, const char *mp
)
93 pthread_t pt1
[NWRK
], pt2
[NWRK
];
97 * Sysvbfs supports only 8 inodes so this test would exhaust
98 * the inode table and creating files would fail with ENOSPC.
100 if (FSTYPE_SYSVBFS(tc
))
101 atf_tc_skip("filesystem has not enough inodes");
102 if (FSTYPE_RUMPFS(tc
))
103 atf_tc_skip("rename not supported by file system");
105 atf_tc_expect_fail("PR kern/49046");
107 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG
));
108 RL(wrkpid
= rump_sys_getpid());
110 RL(rump_sys_chdir(mp
));
111 for (i
= 0; i
< NWRK
; i
++)
112 pthread_create(&pt1
[i
], NULL
, w1
, NULL
);
114 for (i
= 0; i
< NWRK
; i
++)
115 pthread_create(&pt2
[i
], NULL
, w2
, NULL
);
120 for (i
= 0; i
< NWRK
; i
++)
121 pthread_join(pt1
[i
], NULL
);
122 for (i
= 0; i
< NWRK
; i
++)
123 pthread_join(pt2
[i
], NULL
);
124 RL(rump_sys_chdir("/"));
127 atf_tc_fail("race did not trigger this time");
129 if (FSTYPE_MSDOS(tc
)) {
130 atf_tc_expect_fail("PR kern/44661");
132 * XXX: race does not trigger every time at least
135 if (msdosfs_fstest_unmount(tc
, mp
, 0) != 0) {
136 rump_pub_vfs_mount_print(mp
, 1);
137 atf_tc_fail_errno("unmount failed");
139 atf_tc_fail("race did not trigger this time");
144 renamerace_dirs(const atf_tc_t
*tc
, const char *mp
)
148 if (FSTYPE_SYSVBFS(tc
))
149 atf_tc_skip("directories not supported by file system");
151 if (FSTYPE_RUMPFS(tc
))
152 atf_tc_skip("rename not supported by file system");
154 /* XXX: msdosfs also sometimes hangs */
155 if (FSTYPE_MSDOS(tc
))
156 atf_tc_expect_signal(-1, "PR kern/43626");
158 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG
));
159 RL(wrkpid
= rump_sys_getpid());
161 RL(rump_sys_chdir(mp
));
162 pthread_create(&pt1
, NULL
, w1_dirs
, NULL
);
163 pthread_create(&pt2
, NULL
, w2
, NULL
);
168 pthread_join(pt1
, NULL
);
169 pthread_join(pt2
, NULL
);
170 RL(rump_sys_chdir("/"));
173 * Doesn't always trigger when run on a slow backend
174 * (i.e. not on tmpfs/mfs). So do the usual kludge.
176 if (FSTYPE_MSDOS(tc
))
180 ATF_TC_FSAPPLY(renamerace
, "rename(2) race with file unlinked mid-operation");
181 ATF_TC_FSAPPLY(renamerace_dirs
, "rename(2) race with directories");
186 ATF_TP_FSAPPLY(renamerace
); /* PR kern/41128 */
187 ATF_TP_FSAPPLY(renamerace_dirs
);
189 return atf_no_error();