Whamcloud - gitweb
Add slab patches to chaos patch.
[fs/lustre-release.git] / lustre / tests / testreq.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <signal.h>
29 #include <unistd.h>
30 #include <sys/ioctl.h>
31
32 #define _GNU_SOURCE
33 #include <getopt.h>
34 #undef _GNU_SOURCE
35
36 #include <linux/lustre_mds.h>
37
38 static void usage(char *argv0, int status)
39 {
40         printf(
41 "Usage: %s [OPTION...]\n\
42 \n\
43 --getattr <directory>\n\
44 --setattr <directory>\n\
45 --readpage <directory>\n\
46 --open <directory>\n\
47 --close <directory handle (returned by open)>\n\
48 --create <new name>\n", argv0);
49
50         exit(status);
51 }
52
53 int main(int argc, char **argv)
54 {
55         int fd, rc, c, cmd = 0;
56         unsigned long arg;
57         char *short_opts = "h", *name = argv[0];
58         static struct option long_opts[] = {
59 #define OPT_GETATTR -2
60                 {"getattr", no_argument, NULL, OPT_GETATTR},
61 #define OPT_READPAGE -3
62                 {"readpage", no_argument, NULL, OPT_READPAGE},
63 #define OPT_SETATTR -4
64                 {"setattr", no_argument, NULL, OPT_SETATTR},
65 #define OPT_CREATE -5
66                 {"create", no_argument, NULL, OPT_CREATE},
67 #define OPT_OPEN -6
68                 {"open", no_argument, NULL, OPT_OPEN},
69 #define OPT_CLOSE -7
70                 {"close", required_argument, NULL, OPT_CLOSE},
71 #define OPT_HELP 'h'
72                 {"help", no_argument, NULL, OPT_HELP},
73                 {0}
74         };
75
76         do {
77                 c = getopt_long(argc, argv, short_opts, long_opts, NULL);
78
79                 switch (c) {
80                 case OPT_HELP:
81                         usage(argv[0], 0);
82                         break;
83                 case OPT_GETATTR:
84                         cmd = IOC_REQUEST_GETATTR;
85                         name = "getattr";
86                         arg = 2;
87                         break;
88                 case OPT_SETATTR:
89                         cmd = IOC_REQUEST_SETATTR;
90                         name = "setattr";
91                         arg = 2;
92                         break;
93                 case OPT_READPAGE:
94                         cmd = IOC_REQUEST_READPAGE;
95                         name = "readpage";
96                         arg = 2;
97                         break;
98                 case OPT_CREATE:
99                         cmd = IOC_REQUEST_CREATE;
100                         name ="create";
101                         arg = 2;
102                         break;
103                 case OPT_OPEN:
104                         cmd = IOC_REQUEST_OPEN;
105                         name = "open";
106                         arg = 2;
107                         break;
108                 case OPT_CLOSE:
109                         cmd = IOC_REQUEST_CLOSE;
110                         name = "close";
111                         arg = strtoul(optarg, NULL, 0);
112                         break;
113                 case '?':
114                         usage(argv[0], 1);
115                 }
116         } while (c != -1);
117
118         if (cmd == 0)
119                 usage(argv[0], 1);
120
121         fd = open("/dev/request", O_RDONLY);
122         if (fd == -1) {
123                 fprintf(stderr, "error opening /dev/request: %s\n",
124                         strerror(errno));
125                 exit(1);
126         }
127
128         fprintf(stderr, "Executing %s test (arg=%lu)...\n", name, arg);
129         if (cmd == IOC_REQUEST_OPEN) {
130                 rc = ioctl(fd, cmd, &arg);
131                 printf("%lu\n", arg);
132         } else
133                 rc = ioctl(fd, cmd, arg);
134         fprintf(stderr, "result code: %d\n", rc);
135
136         return 0;
137 }