Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / tests / unlinkmany.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 void usage(char *prog)
12 {
13         printf("usage: %s filenamefmt count\n", prog);
14         printf("       %s filenamefmt start count\n", prog);
15 }
16
17 int main(int argc, char ** argv)
18 {
19         int i, rc = 0;
20         char format[4096], *fmt;
21         char filename[4096];
22         long start, last;
23         long begin = 0, count;
24
25         if (argc < 3 || argc > 4) {
26                 usage(argv[0]);
27                 return 1;
28         }
29
30         if (strlen(argv[1]) > 4080) {
31                 printf("name too long\n");
32                 return 1;
33         }
34
35         start = last = time(0);
36
37         if (argc == 3) {
38                 count = strtol(argv[2], NULL, 0);
39                 if (count < 1) {
40                         printf("count must be at least one\n");
41                         return 1;
42                 }
43         } else {
44                 begin = strtol(argv[2], NULL, 0);
45                 count = strtol(argv[3], NULL, 0);
46         }
47
48         if (strchr(argv[1], '%')) {
49                 fmt = argv[1];
50         } else {
51                 sprintf(format, "%s%%d", argv[1]);
52                 fmt = format;
53         }
54         for (i = 0; i < count; i++, begin++) {
55                 sprintf(filename, fmt, begin);
56                 rc = unlink(filename);
57                 if (rc) {
58                         printf("unlink(%s) error: %s\n",
59                                filename, strerror(errno));
60                         rc = errno;
61                         break;
62                 }
63                 if ((i % 10000) == 0) {
64                         printf(" - unlinked %d (time %ld ; total %ld ; last "
65                                "%ld)\n", i, time(0), time(0) - start,
66                                time(0) - last);
67                         last = time(0);
68                 }
69         }
70         printf("total: %d unlinks in %ld seconds: %f unlinks/second\n", i,
71                time(0) - start, ((float)i / (time(0) - start)));
72
73         return rc;
74 }