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