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>
33 #include <linux/lustre_lib.h>
34 #include <linux/lustre_idl.h>
38 #include <netinet/in.h>
41 #include <linux/module.h>
44 #include <linux/list.h>
56 #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)
59 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
78 0, 0, # struct list_head
84 char * obdo_print(struct obdo *obd)
88 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",
107 static int jt_device(int argc, char **argv)
109 struct obd_ioctl_data data;
112 memset(&data, 0, sizeof(data));
114 fprintf(stderr, "Usage: %s devno\n", argv[0]);
118 data.ioc_dev = atoi(argv[1]);
120 if (obd_ioctl_pack(&data, &buf, max)) {
121 printf("invalid ioctl\n");
126 fd = open("/dev/obd", O_RDWR);
128 printf("Opening /dev/obd: %s\n", strerror(errno));
132 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
134 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
141 static int jt_connect(int argc, char **argv)
143 struct obd_ioctl_data data;
149 fprintf(stderr, "Usage: %s\n", argv[0]);
153 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
155 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
158 connid = data.ioc_conn1;
163 static int jt_disconnect(int argc, char **argv)
165 struct obd_ioctl_data data;
171 fprintf(stderr, "Usage: %s\n", argv[0]);
175 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
177 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
186 static int jt_detach(int argc, char **argv)
188 struct obd_ioctl_data data;
194 fprintf(stderr, "Usage: %s\n", argv[0]);
198 if (obd_ioctl_pack(&data, &buf, max)) {
199 printf("invalid ioctl\n");
203 rc = ioctl(fd, OBD_IOC_DETACH , buf);
205 printf("Detach: %s\n", strerror(errno));
211 static int jt_cleanup(int argc, char **argv)
213 struct obd_ioctl_data data;
219 fprintf(stderr, "Usage: %s\n", argv[0]);
223 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
225 printf("Detach: %s\n", strerror(errno));
231 static int jt_attach(int argc, char **argv)
233 struct obd_ioctl_data data;
238 if ( argc != 2 && argc != 3 ) {
239 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
243 data.ioc_inllen1 = strlen(argv[1]) + 1;
244 data.ioc_inlbuf1 = argv[1];
246 data.ioc_inllen2 = strlen(argv[2]) + 1;
247 data.ioc_inlbuf2 = argv[2];
250 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
251 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
253 if (obd_ioctl_pack(&data, &buf, max)) {
254 printf("invalid ioctl\n");
257 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
258 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
260 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
262 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
268 static int jt_setup(int argc, char **argv)
270 struct obd_ioctl_data data;
276 fprintf(stderr, "Usage: %s [device] [fstype]\n", argv[0]);
281 data.ioc_inllen1 = strlen(argv[1]) + 1;
282 data.ioc_inlbuf1 = argv[1];
283 data.ioc_dev = strtoul(argv[1], NULL, 0);
288 data.ioc_inllen2 = strlen(argv[2]) + 1;
289 data.ioc_inlbuf2 = argv[2];
292 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
293 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
295 if (obd_ioctl_pack(&data, &buf, max)) {
296 printf("invalid ioctl\n");
299 printf("setup len %d addr %p raw %p device %s type %s\n",
300 data.ioc_len, buf, rawbuf,
301 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
303 rc = ioctl(fd, OBD_IOC_SETUP , buf);
305 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
312 static int jt_create(int argc, char **argv)
314 struct obd_ioctl_data data;
322 num = strtoul(argv[1], NULL, 0);
324 printf("usage %s num [mode] [silent]\n", argv[0]);
328 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
330 data.ioc_obdo1.o_mode = 0100644;
332 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
335 silent = strtoul(argv[3], NULL, 0);
338 printf("Creating %d obdos\n", num);
340 for (i = 0 ; i<num ; i++) {
341 rc = ioctl(fd, OBD_IOC_CREATE , &data);
343 printf("Create: %x %s\n", OBD_IOC_CREATE,
347 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
352 static int jt_setattr(int argc, char **argv)
354 struct obd_ioctl_data data;
359 printf("usage: %s id mode\n", argv[0]);
363 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
364 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
365 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
367 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
369 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
374 static int jt_destroy(int argc, char **argv)
376 struct obd_ioctl_data data;
381 printf("usage %s id\n", argv[0]);
384 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
386 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
388 printf("setattr: %x %s\n", OBD_IOC_DESTROY, strerror(errno));
393 static int jt_getattr(int argc, char **argv)
395 struct obd_ioctl_data data;
400 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
401 data.ioc_obdo1.o_valid = 0xffffffff;
402 printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
404 printf("usage %s id\n", argv[0]);
408 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
410 printf("Error: %s\n", strerror(rc));
412 printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
413 data.ioc_obdo1.o_mode);
418 static int jt_modules(int argc, char **argv)
420 char *modules[] = {"portals", "ksocknal", "obdclass", "ptlrpc",
421 "obdext2", "ost", "osc", "mds", "mdc", "llight",
423 char *paths[] = {"portals/linux/oslib", "portals/linux/socknal",
424 "obd/class", "obd/rpc", "obd/ext2obd", "obd/ost",
425 "obd/osc", "obd/mds", "obd/mdc", "obd/llight", NULL};
427 char *kernel = "linux";
435 printf("%s [path] [kernel]\n", argv[0]);
439 printf("symbol-file\nsymbol-file %s\nb panic\nb stop\n", kernel);
441 for (i = 0; modules[i] != NULL; i++) {
442 struct module_info info;
445 int query_module(const char *name, int which, void *buf,
446 size_t bufsize, size_t *ret);
448 rc = query_module(modules[i], QM_INFO, &info, sizeof(info),
452 printf("query_module(%s) failed: %s\n",
453 modules[i], strerror(errno));
455 printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
456 paths[i], modules[i],
457 info.addr + sizeof(struct module));
465 {"device", jt_device, 0, "set current device (args device no)"},
466 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
467 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
468 {"detach", jt_detach, 0, "detach the current device (arg: )"},
469 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
470 {"create", jt_create, 0, "create [count [mode [silent]]]"},
471 {"destroy", jt_destroy, 0, "destroy id"},
472 {"getattr", jt_getattr, 0, "getattr id"},
473 {"setattr", jt_setattr, 0, "setattr id mode"},
474 {"connect", jt_connect, 0, "connect - get a connection to device"},
475 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
476 {"modules", jt_modules, 0, "provide gdb-friendly module info (arg: <path>)"},
477 {"help", Parser_help, 0, "help"},
478 {"exit", Parser_quit, 0, "quit"},
479 {"quit", Parser_quit, 0, "quit"},
483 int main(int argc, char **argv)
487 return Parser_execarg(argc - 1, &argv[1], list);
490 Parser_init("obdctl > ", list);