4 #include <sys/socket.h>
9 #include <linux/lustre_lib.h>
10 #include <linux/lustre_idl.h>
14 #include <netinet/in.h>
19 #include <linux/list.h>
31 #define IOCINIT(data) do { memset(&data, 0, sizeof(data)); data.ioc_version = OBD_IOCTL_VERSION; data.ioc_conn1 = connid; data.ioc_len = sizeof(data); if (fd < 0) { printf("No device open, use device\n"); return 1;}} while (0)
34 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
53 0, 0, # struct list_head
59 char * obdo_print(struct obdo *obd)
63 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\nsize: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\ngid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
83 static int jt_device(int argc, char **argv)
85 struct obd_ioctl_data data;
88 memset(&data, 0, sizeof(data));
90 fprintf(stderr, "Usage: %s devno\n", argv[0]);
94 data.ioc_dev = atoi(argv[1]);
96 if (obd_ioctl_pack(&data, &buf, max)) {
97 printf("invalid ioctl\n");
102 fd = open("/dev/obd", O_RDWR);
104 printf("Opening /dev/obd: %s\n", strerror(errno));
108 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
110 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
117 static int jt_connect(int argc, char **argv)
119 struct obd_ioctl_data data;
125 fprintf(stderr, "Usage: %s\n", argv[0]);
129 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
131 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
134 connid = data.ioc_conn1;
141 static int jt_disconnect(int argc, char **argv)
143 struct obd_ioctl_data data;
149 fprintf(stderr, "Usage: %s\n", argv[0]);
153 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
155 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
164 static int jt_detach(int argc, char **argv)
166 struct obd_ioctl_data data;
172 fprintf(stderr, "Usage: %s\n", argv[0]);
176 if (obd_ioctl_pack(&data, &buf, max)) {
177 printf("invalid ioctl\n");
181 rc = ioctl(fd, OBD_IOC_DETACH , buf);
183 printf("Detach: %s\n", strerror(errno));
189 static int jt_cleanup(int argc, char **argv)
191 struct obd_ioctl_data data;
197 fprintf(stderr, "Usage: %s\n", argv[0]);
201 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
203 printf("Detach: %s\n", strerror(errno));
209 static int jt_attach(int argc, char **argv)
211 struct obd_ioctl_data data;
216 if ( argc != 2 && argc != 3 ) {
217 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
221 data.ioc_inllen1 = strlen(argv[1]) + 1;
222 data.ioc_inlbuf1 = argv[1];
224 data.ioc_inllen2 = strlen(argv[2]) + 1;
225 data.ioc_inlbuf2 = argv[2];
228 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
229 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
231 if (obd_ioctl_pack(&data, &buf, max)) {
232 printf("invalid ioctl\n");
235 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
236 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
238 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
240 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
246 static int jt_setup(int argc, char **argv)
248 struct obd_ioctl_data data;
253 if ( argc != 2 && argc != 3 ) {
254 fprintf(stderr, "Usage: %s device [fstype]\n", argv[0]);
258 data.ioc_inllen1 = strlen(argv[1]) + 1;
259 data.ioc_inlbuf1 = argv[1];
261 data.ioc_inllen2 = strlen(argv[2]) + 1;
262 data.ioc_inlbuf2 = argv[2];
265 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
266 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
268 if (obd_ioctl_pack(&data, &buf, max)) {
269 printf("invalid ioctl\n");
272 printf("setup len %d addr %p raw %p device %s type %s\n",
273 data.ioc_len, buf, rawbuf,
274 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
276 rc = ioctl(fd, OBD_IOC_SETUP , buf);
278 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
285 static int jt_create(int argc, char **argv)
287 struct obd_ioctl_data data;
295 num = strtoul(argv[1], NULL, 0);
299 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
301 data.ioc_obdo1.o_mode = 0100644;
303 data.ioc_obdo1.o_mode = OBD_MD_FLMODE;
306 silent = strtoul(argv[3], NULL, 0);
309 printf("Creating %d obdos\n", num);
311 for (i = 0 ; i<num ; i++) {
312 rc = ioctl(fd, OBD_IOC_CREATE , &data);
314 printf("Create: %x %s\n", OBD_IOC_CREATE,
318 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
324 {"device", jt_device, 0, "set current device (args device no)"},
325 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
326 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
327 {"detach", jt_detach, 0, "detach the current device (arg: )"},
328 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
329 {"create", jt_create, 0, "create [count [mode [silent]]]"},
330 {"connect", jt_connect, 0, "connect - get a connection to device"},
331 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
332 {"help", Parser_help, 0, "help"},
333 {"exit", Parser_quit, 0, "quit"},
334 {"quit", Parser_quit, 0, "quit"},
338 int main(int argc, char **argv)
342 return Parser_execarg(argc - 1, &argv[1], list);
345 Parser_init("obdctl > ", list);