Whamcloud - gitweb
Add O_LARGEFILE and O_DIRECT to openclose test so we can eventually stress
[fs/lustre-release.git] / lustre / tests / openclose.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <string.h>
9
10 int main(int argc, char *argv[])
11 {
12         char *filename;
13         unsigned long count, i;
14         int fd;
15
16         if (argc != 3) {
17                 fprintf(stderr, "usage: %s <filename> <iterations>\n", argv[0]);
18                 exit(1);
19         }
20
21         filename = argv[1];
22         count = strtoul(argv[2], NULL, 0);
23
24         fd = open(filename, O_RDWR|O_CREAT, 0644);
25         if (fd < 0) {
26                 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
27                         strerror(errno));
28                 exit(1);
29         }
30         if (close(fd) < 0) {
31                 fprintf(stderr, "close(): %s\n", strerror(errno));
32                 exit(1);
33         }
34
35         for (i = 0; i < count; i++) {
36                 fd = open(filename, O_RDONLY|O_LARGEFILE|O_DIRECT);
37                 if (fd < 0) {
38                         fprintf(stderr, "open(%s, O_RDONLY): %s\n", filename,
39                                 strerror(errno));
40                         exit(1);
41                 }
42                 if (close(fd) < 0) {
43                         fprintf(stderr, "close(): %s\n", strerror(errno));
44                         exit(1);
45                 }
46         }
47         if (unlink(filename) < 0) {
48                 fprintf(stderr, "unlink(%s): %s\n", filename, strerror(errno));
49                 exit(1);
50         }
51         printf("Done.\n");
52         return 0;
53 }