X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Fopenclose.c;h=22c859c2956618f6cc6ddf1c5350b294c92dbcb5;hb=a64f43dfeb7b30b5f94cee813f57845c76feeeac;hp=4fbae4771ce62bbcc47182a36be353924cb96975;hpb=62da08490f917a5a739e9e81977f5290d52670da;p=fs%2Flustre-release.git diff --git a/lustre/tests/openclose.c b/lustre/tests/openclose.c index 4fbae47..22c859c 100644 --- a/lustre/tests/openclose.c +++ b/lustre/tests/openclose.c @@ -1,3 +1,10 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + */ + +/* for O_DIRECT */ +#define _GNU_SOURCE + #include #include #include @@ -7,29 +14,31 @@ #include #include #include +#include +#include #ifndef O_DIRECT -#define O_DIRECT 040000 /* direct disk access hint */ +#define O_DIRECT 0 #endif int main(int argc, char *argv[]) { char filename[1024]; unsigned long count, i; - int thread = 0; - int threads = 0; - int rc; - int fd; + int thread = 0; + int threads = 0; + int rc = 0; + int fd, ioctl_flags = 0; if (argc < 3 || argc > 4) { fprintf(stderr, "usage: %s [threads]\n", - argv[0]); + argv[0]); exit(1); } count = strtoul(argv[2], NULL, 0); - if (argc == 4) - threads = strtoul(argv[3], NULL, 0); + if (argc == 4) + threads = strtoul(argv[3], NULL, 0); for (i = 1; i <= threads; i++) { rc = fork(); @@ -47,7 +56,7 @@ int main(int argc, char *argv[]) rc = 0; } - if (threads && thread == 0) { /* parent process */ + if (threads && thread == 0) { /* parent process */ int live_threads = threads; while (live_threads > 0) { @@ -55,15 +64,14 @@ int main(int argc, char *argv[]) pid_t ret; ret = waitpid(0, &status, 0); - if (ret == 0) { + if (ret == 0) continue; - } if (ret < 0) { - fprintf(stderr, "error: %s: wait - %s\n", - argv[0], strerror(errno)); if (!rc) rc = errno; + fprintf(stderr, "error: %s: wait - %s\n", + argv[0], strerror(rc)); } else { /* * This is a hack. We _should_ be able to use @@ -78,53 +86,58 @@ int main(int argc, char *argv[]) argv[0], ret, err); if (!rc) rc = err; - - live_threads--; } + live_threads--; } - } else { - if (threads) - sprintf(filename, "%s-%d", argv[1], thread); - else - strcpy(filename, argv[1]); + } else { + if (threads) + sprintf(filename, "%s-%d", argv[1], thread); + else + strcpy(filename, argv[1]); - fd = open(filename, O_RDWR|O_CREAT, 0644); - if (fd < 0) { - fprintf(stderr, "open(%s, O_CREAT): %s\n", filename, - strerror(errno)); - exit(errno); - } - if (close(fd) < 0) { - fprintf(stderr, "close(): %s\n", strerror(errno)); - rc = errno; - goto unlink; - } + fd = open(filename, O_RDWR|O_CREAT, 0644); + if (fd < 0) { + rc = errno; + fprintf(stderr, "open(%s, O_CREAT): %s\n", filename, + strerror(rc)); + exit(rc); + } + if (close(fd) < 0) { + rc = errno; + fprintf(stderr, "close(): %s\n", strerror(rc)); + goto unlink; + } - for (i = 0; i < count; i++) { - fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT); - if (fd < 0) { - fprintf(stderr, "open(%s, O_RDWR): %s\n", - filename, strerror(errno)); - rc = errno; - break; - } - if (close(fd) < 0) { - fprintf(stderr, "close(): %s\n", - strerror(errno)); - rc = errno; - break; - } - } - unlink: - if (unlink(filename) < 0) { - fprintf(stderr, "unlink(%s): %s\n", filename, - strerror(errno)); - rc = errno; - } - if (threads) - printf("Thread %d done: rc = %d\n", thread, rc); - else - printf("Done: rc = %d\n", rc); - } + for (i = 0; i < count; i++) { + fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT); + if (fd < 0) { + rc = errno; + fprintf(stderr, "open(%s, O_RDWR): %s\n", + filename, strerror(rc)); + break; + } + if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 && + errno != ENOTTY) { + rc = errno; + fprintf(stderr, "ioctl(): %s\n", strerror(rc)); + break; + } + if (close(fd) < 0) { + rc = errno; + fprintf(stderr, "close(): %s\n", strerror(rc)); + break; + } + } + unlink: + if (unlink(filename) < 0) { + rc = errno; + fprintf(stderr, "unlink(%s): %s\n", filename, + strerror(rc)); + } + if (threads) + printf("Thread %d done: rc = %d\n", thread, rc); + else + printf("Done: rc = %d\n", rc); + } return rc; }