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