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>
43 #include <linux/list.h>
55 #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)
58 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
77 0, 0, # struct list_head
83 char * obdo_print(struct obdo *obd)
87 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",
106 static int jt_device(int argc, char **argv)
108 struct obd_ioctl_data data;
111 memset(&data, 0, sizeof(data));
113 fprintf(stderr, "Usage: %s devno\n", argv[0]);
117 data.ioc_dev = atoi(argv[1]);
119 if (obd_ioctl_pack(&data, &buf, max)) {
120 printf("invalid ioctl\n");
125 fd = open("/dev/obd", O_RDWR);
127 printf("Opening /dev/obd: %s\n", strerror(errno));
131 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
133 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
140 static int jt_connect(int argc, char **argv)
142 struct obd_ioctl_data data;
148 fprintf(stderr, "Usage: %s\n", argv[0]);
152 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
154 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
157 connid = data.ioc_conn1;
162 static int jt_disconnect(int argc, char **argv)
164 struct obd_ioctl_data data;
170 fprintf(stderr, "Usage: %s\n", argv[0]);
174 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
176 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
185 static int jt_detach(int argc, char **argv)
187 struct obd_ioctl_data data;
193 fprintf(stderr, "Usage: %s\n", argv[0]);
197 if (obd_ioctl_pack(&data, &buf, max)) {
198 printf("invalid ioctl\n");
202 rc = ioctl(fd, OBD_IOC_DETACH , buf);
204 printf("Detach: %s\n", strerror(errno));
210 static int jt_cleanup(int argc, char **argv)
212 struct obd_ioctl_data data;
218 fprintf(stderr, "Usage: %s\n", argv[0]);
222 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
224 printf("Detach: %s\n", strerror(errno));
230 static int jt_attach(int argc, char **argv)
232 struct obd_ioctl_data data;
237 if ( argc != 2 && argc != 3 ) {
238 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
242 data.ioc_inllen1 = strlen(argv[1]) + 1;
243 data.ioc_inlbuf1 = argv[1];
245 data.ioc_inllen2 = strlen(argv[2]) + 1;
246 data.ioc_inlbuf2 = argv[2];
249 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
250 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
252 if (obd_ioctl_pack(&data, &buf, max)) {
253 printf("invalid ioctl\n");
256 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
257 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
259 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
261 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
267 static int jt_setup(int argc, char **argv)
269 struct obd_ioctl_data data;
275 fprintf(stderr, "Usage: %s [device] [fstype]\n", argv[0]);
280 data.ioc_inllen1 = strlen(argv[1]) + 1;
281 data.ioc_inlbuf1 = argv[1];
282 data.ioc_dev = strtoul(argv[1], NULL, 0);
287 data.ioc_inllen2 = strlen(argv[2]) + 1;
288 data.ioc_inlbuf2 = argv[2];
291 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
292 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
294 if (obd_ioctl_pack(&data, &buf, max)) {
295 printf("invalid ioctl\n");
298 printf("setup len %d addr %p raw %p device %s type %s\n",
299 data.ioc_len, buf, rawbuf,
300 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
302 rc = ioctl(fd, OBD_IOC_SETUP , buf);
304 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
311 static int jt_create(int argc, char **argv)
313 struct obd_ioctl_data data;
321 num = strtoul(argv[1], NULL, 0);
323 printf("usage %s num [mode] [silent]\n", argv[0]);
327 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
329 data.ioc_obdo1.o_mode = 0100644;
331 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
334 silent = strtoul(argv[3], NULL, 0);
337 printf("Creating %d obdos\n", num);
339 for (i = 0 ; i<num ; i++) {
340 rc = ioctl(fd, OBD_IOC_CREATE , &data);
342 printf("Create: %x %s\n", OBD_IOC_CREATE,
346 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
351 static int jt_setattr(int argc, char **argv)
353 struct obd_ioctl_data data;
358 printf("usage: %s id mode\n", argv[0]);
362 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
363 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
364 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
366 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
368 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
373 static int jt_destroy(int argc, char **argv)
375 struct obd_ioctl_data data;
380 printf("usage %s id\n", argv[0]);
383 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
385 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
387 printf("setattr: %x %s\n", OBD_IOC_DESTROY, strerror(errno));
392 static int jt_multi_getattr(int argc, char **argv)
394 struct obd_ioctl_data data;
400 count = strtoul(argv[1], NULL, 0);
401 data.ioc_obdo1.o_valid = 0xffffffff;
402 data.ioc_obdo1.o_id = 2;
403 printf("getting %d attrs (testing only)\n", count);
405 printf("usage %s id\n", argv[0]);
409 for (i = 0 ; i < count; i++) {
410 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
412 printf("Error: %s on i=%d\n", strerror(rc), i);
415 printf("attr number %d\n", i);
421 static int jt_getattr(int argc, char **argv)
423 struct obd_ioctl_data data;
428 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
429 data.ioc_obdo1.o_valid = 0xffffffff;
430 printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
432 printf("usage %s id\n", argv[0]);
436 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
438 printf("Error: %s\n", strerror(rc));
440 printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
441 data.ioc_obdo1.o_mode);
447 {"device", jt_device, 0, "set current device (args device no)"},
448 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
449 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
450 {"detach", jt_detach, 0, "detach the current device (arg: )"},
451 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
452 {"create", jt_create, 0, "create [count [mode [silent]]]"},
453 {"destroy", jt_destroy, 0, "destroy id"},
454 {"test_getattr", jt_multi_getattr, 0, "test_getattr count [silent]"},
455 {"getattr", jt_getattr, 0, "getattr id"},
456 {"setattr", jt_setattr, 0, "setattr id mode"},
457 {"connect", jt_connect, 0, "connect - get a connection to device"},
458 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
459 {"help", Parser_help, 0, "help"},
460 {"exit", Parser_quit, 0, "quit"},
461 {"quit", Parser_quit, 0, "quit"},
465 int main(int argc, char **argv)
469 return Parser_execarg(argc - 1, &argv[1], list);
472 Parser_init("obdctl > ", list);