* [TESTCASE] orphan link/unlink race test
@ 2008-07-24 19:40 Josef Bacik
0 siblings, 0 replies; only message in thread
From: Josef Bacik @ 2008-07-24 19:40 UTC (permalink / raw)
To: linux-btrfs
Hello,
This is for whoever is doing the QA suite (not it!), it tests the orphan code to
make sure two threads unlinking/linking a file doesn't blow up. A successfull
run of this should result in no output at all. Thanks,
Josef
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
static int link_thread()
{
int i, ret;
for (i = 0; i < 1000; i++) {
int fd;
ret = link("foo", "bar");
if (ret) {
if (errno == ENOENT)
continue;
fprintf(stderr, "FAILED: could not link foo to bar: "
"%d\n", errno);
break;
}
fd = open("bar", O_RDWR);
if (fd < 0) {
fprintf(stderr, "FAILED: could not open bar: %d\n",
errno);
break;
}
ret = unlink("bar");
if (ret) {
fprintf(stderr, "FAILED: could not unlink bar: %d\n",
errno);
break;
}
ret = fsync(fd);
if (ret) {
fprintf(stderr, "FAILED: could not fsync bar: %d\n",
errno);
break;
}
ret = close(fd);
if (ret) {
fprintf(stderr, "FAILED: could not close bar: %d\n",
errno);
break;
}
}
}
static void unlink_thread()
{
int fd, i, ret;
for (i = 0; i < 1000; i++) {
fd = open("foo", O_CREAT | O_RDWR, 0666);
if (fd < 0) {
fprintf(stderr, "FAILED: could not create foo: %d\n",
errno);
break;
}
ret = fsync(fd);
if (ret) {
fprintf(stderr, "FAILED: could not fsync foo after "
"create: %d\n", errno);
break;
}
ret = unlink("foo");
if (ret) {
fprintf(stderr, "FAILED: could not unlink foo: %d\n",
errno);
break;
}
ret = fsync(fd);
if (ret) {
fprintf(stderr, "FAILED: could not fsync foo after "
"unlink: %d\n", errno);
break;
}
ret = close(fd);
if (ret) {
fprintf(stderr, "FAILED: could not close foo: %d\n",
errno);
break;
}
}
}
int main(int argc, char **argv)
{
pid_t child;
int ret;
child = fork();
if (!child) {
link_thread();
} else if (child > 0) {
int status;
unlink_thread();
ret = waitpid(child, &status, 0);
} else {
fprintf(stderr, "Error forking child: %d\n", errno);
}
return 0;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-07-24 19:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-24 19:40 [TESTCASE] orphan link/unlink race test Josef Bacik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox