Whamcloud - gitweb
Updated parameters for obdfs_writepage() to use struct *dentry instead of
[fs/lustre-release.git] / lustre / tests / test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <errno.h>
5 #include <sys/ioctl.h>
6 #include <sys/stat.h>
7 #include <asm/statfs.h>
8 #include <unistd.h>
9
10 #define OBD_IOC_CREATE                 _IOR('f', 3, long)
11 #define OBD_IOC_SETUP                  _IOW('f', 4, long)
12 #define OBD_IOC_SYNC                   _IOR('f', 16, long)
13 #define OBD_IOC_DESTROY                _IOW('f', 6, long)
14 #define OBD_IOC_STATFS                _IORW('f', 15, long)
15
16 #define LOOP_DEVICE "/dev/loop0"
17 #define OBD_DEVICE "/dev/obd"
18
19 int main (int argc, char * argv[])
20 {
21         int fd, rc, err = -1;
22         struct stat stat_buf;
23         struct statfs stfs;
24
25
26         if (argc < 2) {
27                 printf("syntax: %s command [argument]\n", argv[0]);
28                 printf("Where command is one of \"setup\", \"create\", \"destroy\", or \"sync\".\n");
29                 exit(1);
30         }
31         if (stat(LOOP_DEVICE, &stat_buf)) {
32                 printf("Couldn't stat(" LOOP_DEVICE ").\n");
33                 exit(1);
34         }
35         printf("Device: %u\n", (unsigned int) stat_buf.st_rdev);
36
37         fd = open (OBD_DEVICE, O_RDONLY);
38         if (fd == -1) {
39                 printf("Couldn't open " OBD_DEVICE ".\n");
40                 exit(1);
41         }
42
43         if (!strcmp(argv[1], "setup")) {
44                 rc = ioctl(fd, OBD_IOC_SETUP, &stat_buf.st_rdev);
45                 fprintf(stderr, "rc = %d, errno = %d\n", rc, errno);
46         } else if (!strcmp(argv[1], "create")) {
47                 int iter, i;
48
49                 if (argc < 3) {
50                         printf("create requires a nonzero argument.\n");
51                         exit(1);
52                 }
53
54                 iter = atoi(argv[2]);
55                 if (iter < 1) {
56                         printf("create requires a nonzero argument.\n");
57                         exit(1);
58                 }
59                 printf("creating %d objects...\n", iter);
60
61                 for (i = 0; i < iter; i++) {
62                         if ((rc = ioctl(fd, OBD_IOC_CREATE, &err))) {
63                                 fprintf(stderr, "Error; aborting.\n");
64                                 break;
65                         }
66                         if ((rc = ioctl(fd, OBD_IOC_DESTROY, &err))) {
67                                 fprintf(stderr, "Error; aborting.\n");
68                                 break;
69                         }
70                 }
71                 fprintf(stderr, "rc = %d, errno = %d, err = %d\n",
72                         rc, errno, err);
73         } else if (!strcmp(argv[1], "sync")) {
74                 rc = ioctl(fd, OBD_IOC_SYNC, &err);
75                 fprintf(stderr, "rc = %d, errno = %d, err = %d\n",
76                         rc, errno, err);
77         } else if (!strcmp(argv[1], "destroy")) {
78                 int ino;
79
80                 if (argc < 3) {
81                         printf("destroy requires a nonzero inode number.\n");
82                         exit(1);
83                 }
84
85                 ino = atoi(argv[2]);
86                 if (ino < 1) {
87                         printf("destroy requires a nonzero inode number.\n");
88                         exit(1);
89                 }
90
91                 rc = ioctl(fd, OBD_IOC_DESTROY, &ino);
92                 fprintf(stderr, "rc = %d, errno = %d\n", rc, errno);
93         } else {
94                 printf("Invalid command, run with no arguments for help.\n");
95         }
96         close(fd);
97
98         return 0;
99 }