1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <sys/ioctl.h>
28 #include <sys/socket.h>
29 #include <sys/types.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
39 #include <netinet/in.h>
42 #include <linux/module.h>
45 #include <linux/list.h>
57 #define IOCINIT(data) \
59 memset(&data, 0, sizeof(data)); \
60 data.ioc_version = OBD_IOCTL_VERSION; \
61 data.ioc_conn1 = connid; \
62 data.ioc_len = sizeof(data); \
64 fprintf(stderr, "No device open, use device\n"); \
70 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
89 0, 0, # struct list_head
95 char * obdo_print(struct obdo *obd)
99 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",
118 static int jt_device(int argc, char **argv)
120 struct obd_ioctl_data data;
123 memset(&data, 0, sizeof(data));
125 fprintf(stderr, "Usage: %s devno\n", argv[0]);
129 data.ioc_dev = atoi(argv[1]);
131 if (obd_ioctl_pack(&data, &buf, max)) {
132 printf("invalid ioctl\n");
137 fd = open("/dev/obd", O_RDWR);
139 printf("Opening /dev/obd: %s\n", strerror(errno));
143 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
145 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
152 static int do_disconnect()
154 struct obd_ioctl_data data;
162 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
164 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
172 static int jt_connect(int argc, char **argv)
174 struct obd_ioctl_data data;
182 fprintf(stderr, "Usage: %s\n", argv[0]);
186 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
188 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
191 connid = data.ioc_conn1;
196 static int jt_disconnect(int argc, char **argv)
198 struct obd_ioctl_data data;
204 fprintf(stderr, "Usage: %s\n", argv[0]);
208 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
210 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
219 static int jt_detach(int argc, char **argv)
221 struct obd_ioctl_data data;
227 fprintf(stderr, "Usage: %s\n", argv[0]);
231 if (obd_ioctl_pack(&data, &buf, max)) {
232 printf("invalid ioctl\n");
236 rc = ioctl(fd, OBD_IOC_DETACH , buf);
238 printf("Detach: %s\n", strerror(errno));
244 static int jt_cleanup(int argc, char **argv)
246 struct obd_ioctl_data data;
252 fprintf(stderr, "Usage: %s\n", argv[0]);
256 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
258 printf("Detach: %s\n", strerror(errno));
264 static int jt_attach(int argc, char **argv)
266 struct obd_ioctl_data data;
271 if ( argc != 2 && argc != 3 ) {
272 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
276 data.ioc_inllen1 = strlen(argv[1]) + 1;
277 data.ioc_inlbuf1 = argv[1];
279 data.ioc_inllen2 = strlen(argv[2]) + 1;
280 data.ioc_inlbuf2 = argv[2];
283 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
284 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
286 if (obd_ioctl_pack(&data, &buf, max)) {
287 printf("invalid ioctl\n");
290 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
291 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
293 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
295 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
301 static int jt_setup(int argc, char **argv)
303 struct obd_ioctl_data data;
309 fprintf(stderr, "Usage: %s [device] [fstype]\n", argv[0]);
314 data.ioc_inllen1 = strlen(argv[1]) + 1;
315 data.ioc_inlbuf1 = argv[1];
316 data.ioc_dev = strtoul(argv[1], NULL, 0);
321 data.ioc_inllen2 = strlen(argv[2]) + 1;
322 data.ioc_inlbuf2 = argv[2];
325 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
326 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
328 if (obd_ioctl_pack(&data, &buf, max)) {
329 printf("invalid ioctl\n");
332 printf("setup len %d addr %p raw %p device %s type %s\n",
333 data.ioc_len, buf, rawbuf,
334 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
336 rc = ioctl(fd, OBD_IOC_SETUP , buf);
338 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
345 static int jt_create(int argc, char **argv)
347 struct obd_ioctl_data data;
355 num = strtoul(argv[1], NULL, 0);
357 printf("usage %s num [mode] [silent]\n", argv[0]);
361 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
363 data.ioc_obdo1.o_mode = 0100644;
365 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
368 silent = strtoul(argv[3], NULL, 0);
371 printf("Creating %d obdos\n", num);
373 for (i = 0 ; i<num ; i++) {
374 rc = ioctl(fd, OBD_IOC_CREATE , &data);
376 printf("Create: %x %s\n", OBD_IOC_CREATE,
380 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
385 static int jt_setattr(int argc, char **argv)
387 struct obd_ioctl_data data;
392 printf("usage: %s id mode\n", argv[0]);
396 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
397 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
398 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
400 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
402 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
407 static int jt_destroy(int argc, char **argv)
409 struct obd_ioctl_data data;
414 printf("usage %s id\n", argv[0]);
417 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
419 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
421 printf("setattr: %x %s\n", OBD_IOC_DESTROY, strerror(errno));
426 static int jt_multi_getattr(int argc, char **argv)
428 struct obd_ioctl_data data;
434 count = strtoul(argv[1], NULL, 0);
435 data.ioc_obdo1.o_valid = 0xffffffff;
436 data.ioc_obdo1.o_id = 2;
437 printf("getting %d attrs (testing only)\n", count);
439 printf("usage %s id\n", argv[0]);
443 for (i = 0 ; i < count; i++) {
444 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
446 printf("Error: %s on i=%d\n", strerror(rc), i);
449 printf("attr number %d\n", i);
455 static int jt_getattr(int argc, char **argv)
457 struct obd_ioctl_data data;
462 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
463 data.ioc_obdo1.o_valid = 0xffffffff;
464 printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
466 printf("usage %s id\n", argv[0]);
470 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
472 printf("Error: %s\n", strerror(rc));
474 printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
475 data.ioc_obdo1.o_mode);
481 {"device", jt_device, 0, "set current device (args device no)"},
482 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
483 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
484 {"detach", jt_detach, 0, "detach the current device (arg: )"},
485 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
486 {"create", jt_create, 0, "create [count [mode [silent]]]"},
487 {"destroy", jt_destroy, 0, "destroy id"},
488 {"test_getattr", jt_multi_getattr, 0, "test_getattr count [silent]"},
489 {"getattr", jt_getattr, 0, "getattr id"},
490 {"setattr", jt_setattr, 0, "setattr id mode"},
491 {"connect", jt_connect, 0, "connect - get a connection to device"},
492 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
493 {"help", Parser_help, 0, "help"},
494 {"exit", Parser_quit, 0, "quit"},
495 {"quit", Parser_quit, 0, "quit"},
500 static void signal_server(int sig)
503 fprintf(stderr,"\nDisconnecting any existing connections...\n");
509 int main(int argc, char **argv)
511 struct sigaction sigact;
512 sigact.sa_handler = signal_server;
513 sigfillset(&sigact.sa_mask);
514 sigact.sa_flags = SA_RESTART;
515 sigaction(SIGINT, &sigact, NULL);
518 return Parser_execarg(argc - 1, &argv[1], list);
521 Parser_init("obdctl > ", list);