Whamcloud - gitweb
Modified ChangeLog entry.
[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 <liblustre.h>
37 #include <lustre_mds.h>
38
39 static void usage(char *argv0, int status)
40 {
41         printf(
42 "Usage: %s [OPTION...]\n\
43 \n\
44 --getattr <directory>\n\
45 --setattr <directory>\n\
46 --readpage <directory>\n\
47 --open <directory>\n\
48 --close <directory handle (returned by open)>\n\
49 --create <new name>\n", argv0);
50
51         exit(status);
52 }
53
54 int main(int argc, char **argv)
55 {
56         int fd = 0;
57         int rc = 0;
58         int c  = 0;
59         long cmd = 0;
60         unsigned long arg;
61         char *short_opts = "h", *name = argv[0];
62         static struct option long_opts[] = {
63 #define OPT_GETATTR -2
64                 {"getattr", no_argument, NULL, OPT_GETATTR},
65 #define OPT_READPAGE -3
66                 {"readpage", no_argument, NULL, OPT_READPAGE},
67 #define OPT_SETATTR -4
68                 {"setattr", no_argument, NULL, OPT_SETATTR},
69 #define OPT_CREATE -5
70                 {"create", no_argument, NULL, OPT_CREATE},
71 #define OPT_OPEN -6
72                 {"open", no_argument, NULL, OPT_OPEN},
73 #define OPT_CLOSE -7
74                 {"close", required_argument, NULL, OPT_CLOSE},
75 #define OPT_HELP 'h'
76                 {"help", no_argument, NULL, OPT_HELP},
77                 {0}
78         };
79
80         do {
81                 c = getopt_long(argc, argv, short_opts, long_opts, NULL);
82
83                 switch (c) {
84                 case OPT_HELP:
85                         usage(argv[0], 0);
86                         break;
87                 case OPT_GETATTR:
88                         cmd = IOC_REQUEST_GETATTR;
89                         name = "getattr";
90                         arg = 2;
91                         break;
92                 case OPT_SETATTR:
93                         cmd = IOC_REQUEST_SETATTR;
94                         name = "setattr";
95                         arg = 2;
96                         break;
97                 case OPT_READPAGE:
98                         cmd = IOC_REQUEST_READPAGE;
99                         name = "readpage";
100                         arg = 2;
101                         break;
102                 case OPT_CREATE:
103                         cmd = IOC_REQUEST_CREATE;
104                         name ="create";
105                         arg = 2;
106                         break;
107                 case OPT_OPEN:
108                         cmd = IOC_REQUEST_OPEN;
109                         name = "open";
110                         arg = 2;
111                         break;
112                 case OPT_CLOSE:
113                         cmd = IOC_REQUEST_CLOSE;
114                         name = "close";
115                         arg = strtoul(optarg, NULL, 0);
116                         break;
117                 case '?':
118                         usage(argv[0], 1);
119                 }
120         } while (c != -1);
121
122         if (cmd == 0)
123                 usage(argv[0], 1);
124
125         fd = open("/dev/request", O_RDONLY);
126         if (fd == -1) {
127                 fprintf(stderr, "error opening /dev/request: %s\n",
128                         strerror(errno));
129                 exit(1);
130         }
131
132         fprintf(stderr, "Executing %s test (arg=%lu)...\n", name, arg);
133         if (cmd == IOC_REQUEST_OPEN) {
134                 rc = ioctl(fd, cmd, &arg);
135                 printf("%lu\n", arg);
136         } else
137                 rc = ioctl(fd, cmd, arg);
138         fprintf(stderr, "result code: %d\n", rc);
139
140         return 0;
141 }