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];
260 data.ioc_dev = strtoul(argv[1], NULL, 0);
262 data.ioc_inllen2 = strlen(argv[2]) + 1;
263 data.ioc_inlbuf2 = argv[2];
266 printf("setup len %d addr %p device %s type %s\n", data.ioc_len, buf,
267 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
269 if (obd_ioctl_pack(&data, &buf, max)) {
270 printf("invalid ioctl\n");
273 printf("setup len %d addr %p raw %p device %s type %s\n",
274 data.ioc_len, buf, rawbuf,
275 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
277 rc = ioctl(fd, OBD_IOC_SETUP , buf);
279 printf("setup: %x %s\n", OBD_IOC_SETUP, strerror(errno));
286 static int jt_create(int argc, char **argv)
288 struct obd_ioctl_data data;
296 num = strtoul(argv[1], NULL, 0);
298 printf("usage %s num [mode] [silent]\n", argv[0]);
302 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
304 data.ioc_obdo1.o_mode = 0100644;
306 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
309 silent = strtoul(argv[3], NULL, 0);
312 printf("Creating %d obdos\n", num);
314 for (i = 0 ; i<num ; i++) {
315 rc = ioctl(fd, OBD_IOC_CREATE , &data);
317 printf("Create: %x %s\n", OBD_IOC_CREATE,
321 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
326 static int jt_setattr(int argc, char **argv)
328 struct obd_ioctl_data data;
333 printf("usage %s id mode\n", argv[0]);
336 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
337 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
338 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
340 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
342 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
347 static int jt_destroy(int argc, char **argv)
349 struct obd_ioctl_data data;
354 printf("usage %s id\n", argv[0]);
357 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
359 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
361 printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno));
366 static int jt_getattr(int argc, char **argv)
368 struct obd_ioctl_data data;
373 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
374 data.ioc_obdo1.o_valid = 0xffffffff;
375 printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
377 printf("usage %s id\n", argv[0]);
381 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
383 printf("Error: %s\n", strerror(rc));
385 printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
386 data.ioc_obdo1.o_mode);
392 {"device", jt_device, 0, "set current device (args device no)"},
393 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
394 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
395 {"detach", jt_detach, 0, "detach the current device (arg: )"},
396 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
397 {"create", jt_create, 0, "create [count [mode [silent]]]"},
398 {"destroy", jt_destroy, 0, "destroy id"},
399 {"getattr", jt_getattr, 0, "getattr id"},
400 {"setattr", jt_setattr, 0, "setattr id mode"},
401 {"connect", jt_connect, 0, "connect - get a connection to device"},
402 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
403 {"help", Parser_help, 0, "help"},
404 {"exit", Parser_quit, 0, "quit"},
405 {"quit", Parser_quit, 0, "quit"},
409 int main(int argc, char **argv)
413 return Parser_execarg(argc - 1, &argv[1], list);
416 Parser_init("obdctl > ", list);