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) 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)
60 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
79 0, 0, # struct list_head
85 char * obdo_print(struct obdo *obd)
89 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",
108 static int jt_device(int argc, char **argv)
110 struct obd_ioctl_data data;
113 memset(&data, 0, sizeof(data));
115 fprintf(stderr, "Usage: %s devno\n", argv[0]);
119 data.ioc_dev = atoi(argv[1]);
121 if (obd_ioctl_pack(&data, &buf, max)) {
122 printf("invalid ioctl\n");
127 fd = open("/dev/obd", O_RDWR);
129 printf("Opening /dev/obd: %s\n", strerror(errno));
133 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
135 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
142 static int do_disconnect()
144 struct obd_ioctl_data data;
151 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
153 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
161 static int jt_connect(int argc, char **argv)
163 struct obd_ioctl_data data;
171 fprintf(stderr, "Usage: %s\n", argv[0]);
175 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
177 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
180 connid = data.ioc_conn1;
185 static int jt_disconnect(int argc, char **argv)
187 struct obd_ioctl_data data;
193 fprintf(stderr, "Usage: %s\n", argv[0]);
197 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
199 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
208 static int jt_detach(int argc, char **argv)
210 struct obd_ioctl_data data;
216 fprintf(stderr, "Usage: %s\n", argv[0]);
220 if (obd_ioctl_pack(&data, &buf, max)) {
221 printf("invalid ioctl\n");
225 rc = ioctl(fd, OBD_IOC_DETACH , buf);
227 printf("Detach: %s\n", strerror(errno));
233 static int jt_cleanup(int argc, char **argv)
235 struct obd_ioctl_data data;
241 fprintf(stderr, "Usage: %s\n", argv[0]);
245 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
247 printf("Detach: %s\n", strerror(errno));
253 static int jt_attach(int argc, char **argv)
255 struct obd_ioctl_data data;
260 if ( argc != 2 && argc != 3 ) {
261 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
265 data.ioc_inllen1 = strlen(argv[1]) + 1;
266 data.ioc_inlbuf1 = argv[1];
268 data.ioc_inllen2 = strlen(argv[2]) + 1;
269 data.ioc_inlbuf2 = argv[2];
272 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
273 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
275 if (obd_ioctl_pack(&data, &buf, max)) {
276 printf("invalid ioctl\n");
279 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
280 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
282 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
284 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
290 static int jt_setup(int argc, char **argv)
292 struct obd_ioctl_data data;
298 fprintf(stderr, "Usage: %s [device] [fstype]\n", argv[0]);
303 data.ioc_inllen1 = strlen(argv[1]) + 1;
304 data.ioc_inlbuf1 = argv[1];
305 data.ioc_dev = strtoul(argv[1], NULL, 0);
310 data.ioc_inllen2 = strlen(argv[2]) + 1;
311 data.ioc_inlbuf2 = argv[2];
314 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
315 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
317 if (obd_ioctl_pack(&data, &buf, max)) {
318 printf("invalid ioctl\n");
321 printf("setup len %d addr %p raw %p device %s type %s\n",
322 data.ioc_len, buf, rawbuf,
323 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
325 rc = ioctl(fd, OBD_IOC_SETUP , buf);
327 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
334 static int jt_create(int argc, char **argv)
336 struct obd_ioctl_data data;
344 num = strtoul(argv[1], NULL, 0);
346 printf("usage %s num [mode] [silent]\n", argv[0]);
350 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
352 data.ioc_obdo1.o_mode = 0100644;
354 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
357 silent = strtoul(argv[3], NULL, 0);
360 printf("Creating %d obdos\n", num);
362 for (i = 0 ; i<num ; i++) {
363 rc = ioctl(fd, OBD_IOC_CREATE , &data);
365 printf("Create: %x %s\n", OBD_IOC_CREATE,
369 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
374 static int jt_setattr(int argc, char **argv)
376 struct obd_ioctl_data data;
381 printf("usage: %s id mode\n", argv[0]);
385 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
386 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
387 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
389 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
391 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
396 static int jt_destroy(int argc, char **argv)
398 struct obd_ioctl_data data;
403 printf("usage %s id\n", argv[0]);
406 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
408 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
410 printf("setattr: %x %s\n", OBD_IOC_DESTROY, strerror(errno));
415 static int jt_multi_getattr(int argc, char **argv)
417 struct obd_ioctl_data data;
423 count = strtoul(argv[1], NULL, 0);
424 data.ioc_obdo1.o_valid = 0xffffffff;
425 data.ioc_obdo1.o_id = 2;
426 printf("getting %d attrs (testing only)\n", count);
428 printf("usage %s id\n", argv[0]);
432 for (i = 0 ; i < count; i++) {
433 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
435 printf("Error: %s on i=%d\n", strerror(rc), i);
438 printf("attr number %d\n", i);
444 static int jt_getattr(int argc, char **argv)
446 struct obd_ioctl_data data;
451 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
452 data.ioc_obdo1.o_valid = 0xffffffff;
453 printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
455 printf("usage %s id\n", argv[0]);
459 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
461 printf("Error: %s\n", strerror(rc));
463 printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
464 data.ioc_obdo1.o_mode);
470 {"device", jt_device, 0, "set current device (args device no)"},
471 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
472 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
473 {"detach", jt_detach, 0, "detach the current device (arg: )"},
474 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
475 {"create", jt_create, 0, "create [count [mode [silent]]]"},
476 {"destroy", jt_destroy, 0, "destroy id"},
477 {"test_getattr", jt_multi_getattr, 0, "test_getattr count [silent]"},
478 {"getattr", jt_getattr, 0, "getattr id"},
479 {"setattr", jt_setattr, 0, "setattr id mode"},
480 {"connect", jt_connect, 0, "connect - get a connection to device"},
481 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
482 {"help", Parser_help, 0, "help"},
483 {"exit", Parser_quit, 0, "quit"},
484 {"quit", Parser_quit, 0, "quit"},
489 static void signal_server(int sig)
492 printf("Disconnecting existing connection");
497 int main(int argc, char **argv)
499 struct sigaction sigact;
500 sigact.sa_handler = signal_server;
501 sigfillset(&sigact.sa_mask);
502 sigact.sa_flags = SA_RESTART;
503 sigaction(SIGINT, &sigact, NULL);
506 return Parser_execarg(argc - 1, &argv[1], list);
509 Parser_init("obdctl > ", list);