Whamcloud - gitweb
Merge b_md to HEAD for 0.5.19 release.
[fs/lustre-release.git] / lustre / tests / createmany.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <time.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10
11 int main(int argc, char ** argv)
12 {
13         int i, rc = 0, do_open;
14         char filename[4096];
15         long int start, last, end, count;
16
17         if (argc != 4) {
18                 printf("Usage %s <-o|-m> filenamebase <count|-time>\n",
19                        argv[0]);
20                 return 1;
21         }
22
23         if (strcmp(argv[1], "-o") == 0) {
24                 do_open = 1;
25         } else if (strcmp(argv[1], "-m") == 0) {
26                 do_open = 0;
27         } else {
28                 printf("Usage %s {-o|-m} filenamebase <count|-time>\n",
29                        argv[0]);
30                 return 1;
31         }
32
33         if (strlen(argv[2]) > 4080) {
34                 printf("name too long\n");
35                 return 1;
36         }
37
38         start = last = time(0);
39
40         end = strtol(argv[3], NULL, 0);
41
42         if (end > 0) {
43                 count = end;
44                 end = -1UL >> 1;
45         } else {
46                 end = start - end;
47                 count = -1UL >> 1;
48         }
49
50         for (i = 0; i < count && time(0) < end; i++) {
51                 sprintf(filename, "%s%d", argv[2], i);
52                 if (do_open) {
53                         int fd = open(filename, O_CREAT|O_RDWR, 0644);
54                         if (fd < 0) {
55                                 printf("open(%s) error: %s\n", filename,
56                                        strerror(errno));
57                                 rc = errno;
58                                 break;
59                         }
60                         close(fd);
61                 } else {
62                         rc = mknod(filename, S_IFREG| 0444, 0);
63                         if (rc) {
64                                 printf("mknod(%s) error: %s\n",
65                                        filename, strerror(errno));
66                                 rc = errno;
67                                 break;
68                         }
69                 }
70                 if ((i % 10000) == 0) {
71                         printf(" - created %d (time %ld ; total %ld ; last %ld)\n",
72                                i, time(0), time(0) - start, time(0) - last);
73                         last = time(0);
74                 }
75         }
76         printf("total: %d creates in %ld seconds: %f creates/second\n", i,
77                time(0) - start, ((float)i / (time(0) - start)));
78
79         return rc;
80 }