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.
27 #include <sys/ioctl.h>
29 #include <sys/socket.h>
30 #include <sys/types.h>
38 #include <linux/lustre_lib.h>
39 #include <linux/lustre_idl.h>
40 #include <linux/lustre_dlm.h>
42 #include <libxml/xmlmemory.h>
43 #include <libxml/parser.h>
49 #include <netinet/in.h>
53 #include <asm/page.h> /* needed for PAGE_SIZE - rread*/
56 #include <linux/list.h>
62 static int jt_newdev(int argc, char **argv);
63 static int jt_attach(int argc, char **argv);
64 static int jt_setup(int argc, char **argv);
68 uint64_t conn_addr = -1;
76 #define IOCINIT(data) \
78 memset(&data, 0, sizeof(data)); \
79 data.ioc_version = OBD_IOCTL_VERSION; \
80 data.ioc_addr = conn_addr; \
81 data.ioc_cookie = conn_cookie; \
82 data.ioc_len = sizeof(data); \
84 fprintf(stderr, "No device open, use device\n"); \
90 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
109 0, 0, # struct list_head
115 char * obdo_print(struct obdo *obd)
119 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
120 "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
121 "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
140 static char *cmdname(char *func)
142 static char buf[512];
145 sprintf(buf, "%s-%d", func, thread);
152 int getfd(char *func)
155 fd = open("/dev/obd", O_RDWR);
157 fprintf(stderr, "error: %s: opening /dev/obd: %s\n",
158 cmdname(func), strerror(errno));
164 #define difftime(a, b) \
165 ((double)(a)->tv_sec - (b)->tv_sec + \
166 ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
168 static int be_verbose(int verbose, struct timeval *next_time,
169 int num, int *next_num, int num_total)
176 if (next_time != NULL)
177 gettimeofday(&now, NULL);
179 /* A positive verbosity means to print every X iterations */
181 (next_num == NULL || num >= *next_num || num >= num_total)) {
182 *next_num += verbose;
184 next_time->tv_sec = now.tv_sec - verbose;
185 next_time->tv_usec = now.tv_usec;
190 /* A negative verbosity means to print at most each X seconds */
191 if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0){
192 next_time->tv_sec = now.tv_sec - verbose;
193 next_time->tv_usec = now.tv_usec;
202 static int get_verbose(const char *arg)
206 if (!arg || arg[0] == 'v')
208 else if (arg[0] == 's' || arg[0] == 'q')
211 verbose = (int) strtoul(arg, NULL, 0);
214 printf("Print status every %d seconds\n", -verbose);
215 else if (verbose == 1)
216 printf("Print status every operation\n");
217 else if (verbose > 1)
218 printf("Print status every %d operations\n", verbose);
223 static int do_disconnect(char *func, int verbose)
225 struct obd_ioctl_data data;
232 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
234 fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
235 OBD_IOC_DISCONNECT, strerror(errno));
238 printf("%s: disconnected conn %Lx\n", cmdname(func),
246 extern command_t cmdlist[];
248 static int xml_command(char *cmd, ...) {
256 while (((arg = va_arg(args, char *)) != NULL) && (i < 8)) {
264 for (j = 0; j < i; j++)
265 printf("%s ", cmds[j]);
269 return Parser_execarg(i, cmds, cmdlist);
272 static network_t *xml_network(xmlDocPtr doc, xmlNodePtr root) {
273 xmlNodePtr cur = root->xmlChildrenNode;
276 if ((net = (network_t *)calloc(1, sizeof(network_t))) == NULL) {
277 printf("error: unable to malloc network_t\n");
281 net->type = xmlGetProp(root, "type");
282 if (net->type == NULL) {
283 printf("error: type attrib required (tcp, elan, myrinet)\n");
288 while (cur != NULL) {
289 if (!xmlStrcmp(cur->name, "server"))
290 net->server = xmlNodeGetContent(cur);
292 if (!xmlStrcmp(cur->name, "port"))
293 net->port = atoi(xmlNodeGetContent(cur));
298 if (net->server == NULL) {
299 printf("error: <server> tag required\n");
307 static int xml_mds(xmlDocPtr doc, xmlNodePtr root,
308 char *serv_name, char *serv_uuid) {
309 xmlNodePtr cur = root->xmlChildrenNode;
310 char *fstype = NULL, *device = NULL;
313 printf("--- Setting up MDS ---\n");
314 while (cur != NULL) {
315 if (!xmlStrcmp(cur->name, "fstype"))
316 fstype = xmlNodeGetContent(cur);
318 if (!xmlStrcmp(cur->name, "device"))
319 device = xmlNodeGetContent(cur);
321 /* FIXME: Parse the network bits
322 * if (!xmlStrcmp(cur->name, "network")) {
323 * net = xml_network(doc, cur);
332 if ((fstype == NULL) || (device == NULL)) {
333 printf("error: <fstype> and <device> tags required\n");
337 if ((rc = xml_command("newdev", NULL)) != 0)
340 if ((rc = xml_command("attach","mds",serv_name,serv_uuid,NULL)) != 0)
343 if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
349 static int xml_obd(xmlDocPtr doc, xmlNodePtr root,
350 char *serv_name, char *serv_uuid) {
351 char *obdtype, *format = NULL, *fstype = NULL, *device = NULL;
352 xmlNodePtr cur = root->xmlChildrenNode;
355 obdtype = xmlGetProp(root, "type");
356 printf("--- Setting up OBD ---\n");
358 while (cur != NULL) {
359 if (!xmlStrcmp(cur->name, "fstype"))
360 fstype = xmlNodeGetContent(cur);
362 if (!xmlStrcmp(cur->name, "device"))
363 device = xmlNodeGetContent(cur);
365 if (!xmlStrcmp(cur->name, "autoformat"))
366 format = xmlNodeGetContent(cur);
371 if ((obdtype == NULL) || (fstype == NULL) || (device == NULL)) {
372 printf("error: 'type' attrib and <fstype> "
373 "and <device> tags required\n");
377 /* FIXME: Building and configuring loopback devices should go here
378 * but is currently unsupported. You'll have to use the scripts
379 * for now until support is added, or specify a real device.
382 if ((rc = xml_command("newdev", NULL)) != 0)
385 if ((rc = xml_command("attach", obdtype,
386 serv_name,serv_uuid, NULL)) != 0)
389 if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
395 static int xml_ost(xmlDocPtr doc, xmlNodePtr root,
396 char *serv_name, char *serv_uuid) {
397 char *server_name = NULL, *server_uuid = NULL;
398 char *failover_name = NULL, *failover_uuid = NULL;
399 xmlNodePtr cur = root->xmlChildrenNode;
400 int server_num, failover_num, rc;
402 printf("--- Setting up OST ---\n");
403 while (cur != NULL) {
404 if (!xmlStrcmp(cur->name, "server_id")) {
405 server_num = atoi(xmlGetProp(cur, "num"));
406 server_name = xmlGetProp(cur, "name");
407 server_uuid = xmlGetProp(cur, "uuid");
410 /* FIXME: Properly handle multiple failover servers */
411 if (!xmlStrcmp(cur->name, "failover_id")) {
412 failover_num = atoi(xmlGetProp(cur, "num"));
413 failover_name = xmlGetProp(cur, "name");
414 failover_uuid = xmlGetProp(cur, "uuid");
420 if ((server_name == NULL) || (server_uuid == NULL)) {
421 printf("error: atleast the <server_id> tag is required\n");
425 if ((rc = xml_command("newdev", NULL)) != 0)
428 if ((rc = xml_command("attach","ost",serv_name,serv_uuid,NULL)) != 0)
431 if ((rc = xml_command("setup", server_name, NULL)) != 0)
437 static int xml_osc(xmlDocPtr doc, xmlNodePtr root,
438 char *serv_name, char *serv_uuid) {
439 char *ost_name = NULL, *ost_uuid = NULL;
440 xmlNodePtr cur = root->xmlChildrenNode;
443 printf("--- Setting up OSC ---\n");
444 while (cur != NULL) {
445 if (!xmlStrcmp(cur->name, "service_id")) {
446 ost_num = atoi(xmlGetProp(cur, "num"));
447 ost_name = xmlGetProp(cur, "name");
448 ost_uuid = xmlGetProp(cur, "uuid");
454 if ((ost_name == NULL) || (ost_uuid == NULL)) {
455 printf("error: atleast the <service_id> tag is required\n");
459 if ((rc = xml_command("newdev", NULL)) != 0)
462 if ((rc = xml_command("attach","osc",serv_name,serv_uuid,NULL)) != 0)
465 if ((rc = xml_command("setup", ost_uuid, "localhost", NULL)) != 0)
471 static int xml_mdc(xmlDocPtr doc, xmlNodePtr root,
472 char *serv_name, char *serv_uuid) {
473 char *mds_name = NULL, *mds_uuid = NULL;
474 xmlNodePtr cur = root->xmlChildrenNode;
477 printf("--- Setting up MDC ---\n");
478 while (cur != NULL) {
479 if (!xmlStrcmp(cur->name, "service_id")) {
480 mds_num = atoi(xmlGetProp(cur, "num"));
481 mds_name = xmlGetProp(cur, "name");
482 mds_uuid = xmlGetProp(cur, "uuid");
488 if ((mds_name == NULL) || (mds_uuid == NULL)) {
489 printf("error: atleast the <service_id> tag is required\n");
493 if ((rc = xml_command("newdev", NULL)) != 0)
496 if ((rc = xml_command("attach","mdc",serv_name,serv_uuid,NULL)) != 0)
499 if ((rc = xml_command("setup", mds_uuid, "localhost", NULL)) != 0)
505 static int xml_lov(xmlDocPtr doc, xmlNodePtr root,
506 char *serv_name, char *serv_uuid) {
507 printf("--- Setting up LOV ---\n");
511 static int xml_router(xmlDocPtr doc, xmlNodePtr root,
512 char *serv_name, char *serv_uuid) {
513 printf("--- Setting up ROUTER ---\n");
517 static int xml_ldlm(xmlDocPtr doc, xmlNodePtr root,
518 char *serv_name, char *serv_uuid) {
521 printf("--- Setting up LDLM ---\n");
522 if ((rc = xml_command("newdev", NULL)) != 0)
525 if ((rc = xml_command("attach","ldlm",serv_name,serv_uuid,NULL)) != 0)
528 if ((rc = xml_command("setup", NULL)) != 0)
534 static int xml_service(xmlDocPtr doc, xmlNodePtr root,
535 int serv_num, char *serv_name, char *serv_uuid) {
536 xmlNodePtr cur = root;
539 while (cur != NULL) {
540 name = xmlGetProp(cur, "name");
541 uuid = xmlGetProp(cur, "uuid");
543 if (xmlStrcmp(name, serv_name) ||
544 xmlStrcmp(uuid, serv_uuid)) {
549 if (!xmlStrcmp(cur->name, "mds"))
550 return xml_mds(doc, cur, name, uuid);
551 else if (!xmlStrcmp(cur->name, "obd"))
552 return xml_obd(doc, cur, name, uuid);
553 else if (!xmlStrcmp(cur->name, "ost"))
554 return xml_ost(doc, cur, name, uuid);
555 else if (!xmlStrcmp(cur->name, "osc"))
556 return xml_osc(doc, cur, name, uuid);
557 else if (!xmlStrcmp(cur->name, "mdc"))
558 return xml_mdc(doc, cur, name, uuid);
559 else if (!xmlStrcmp(cur->name, "lov"))
560 return xml_lov(doc, cur, name, uuid);
561 else if (!xmlStrcmp(cur->name, "router"))
562 return xml_router(doc, cur, name, uuid);
563 else if (!xmlStrcmp(cur->name, "ldlm"))
564 return xml_ldlm(doc, cur, name, uuid);
571 printf("error: No XML config branch for name=%s uuid=%s\n",
572 serv_name, serv_uuid);
576 static int xml_profile(xmlDocPtr doc, xmlNodePtr root,
577 int prof_num, char *prof_name, char *prof_uuid) {
578 xmlNodePtr parent, cur = root;
579 char *name, *uuid, *srv_name, *srv_uuid;
582 while (cur != NULL) {
583 name = xmlGetProp(cur, "name");
584 uuid = xmlGetProp(cur, "uuid");
586 if (xmlStrcmp(cur->name, "profile") ||
587 xmlStrcmp(name, prof_name) ||
588 xmlStrcmp(uuid, prof_uuid)) {
593 /* FIXME: Doesn't understand mountpoints yet
594 * xml_mountpoint(doc, root, ...);
597 /* Setup each service in turn
598 * FIXME: Should be sorted by "num" attr, we shouldn't
599 * assume they're in order in the XML document.
602 cur = cur->xmlChildrenNode;
603 while (cur != NULL) {
604 if (!xmlStrcmp(cur->name, "service_id")) {
605 num = atoi(xmlGetProp(cur, "num"));
606 rc = xml_service(doc, root, num,
607 srv_name = xmlGetProp(cur, "name"),
608 srv_uuid = xmlGetProp(cur, "uuid"));
610 printf("error: service config\n");
624 static int xml_node(xmlDocPtr doc, xmlNodePtr root) {
625 xmlNodePtr parent, cur = root;
629 /* Walk the node tags looking for ours */
630 while (cur != NULL) {
631 if (xmlStrcmp(cur->name, "node")) {
636 name = xmlGetProp(cur, "name");
640 uuid = xmlGetProp(cur, "uuid");
644 /* FIXME: Verify our NAME and UUID against /etc/lustre/id
645 * so we're sure we are who we think we are.
648 /* Setup each profile in turn
649 * FIXME: Should be sorted by "num" attr, we shouldn't
650 * assume they're in order in the XML document.
653 cur = cur->xmlChildrenNode;
654 while (cur != NULL) {
655 if (!xmlStrcmp(cur->name, "profile_id")) {
656 num = atoi(xmlGetProp(cur, "num"));
657 rc = xml_profile(doc, root, num,
658 xmlGetProp(cur, "name"),
659 xmlGetProp(cur, "uuid"));
673 static int do_xml(char *func, char *file)
679 doc = xmlParseFile(file);
681 fprintf(stderr, "error: Unable to parse XML\n");
685 cur = xmlDocGetRootElement(doc);
687 fprintf(stderr, "error: Empty XML\n");
692 if (xmlStrcmp(cur->name, (const xmlChar *)"lustre")) {
693 fprintf(stderr, "error: Root node != <lustre>\n");
698 /* FIXME: Validate the XML against the DTD here */
700 /* FIXME: Merge all the text nodes under each branch and
701 * prune empty nodes. Just to make the parsing more
702 * tolerant, the exact location of nested tags isn't
706 rc = xml_node(doc, cur->xmlChildrenNode);
712 static int do_device(char *func, int dev)
714 struct obd_ioctl_data data;
716 memset(&data, 0, sizeof(data));
723 if (obd_ioctl_pack(&data, &buf, max)) {
724 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
728 return ioctl(fd, OBD_IOC_DEVICE , buf);
731 static int jt_device(int argc, char **argv)
733 do_disconnect(argv[0], 1);
736 fprintf(stderr, "usage: %s devno\n", cmdname(argv[0]));
740 rc = do_device(argv[0], strtoul(argv[1], NULL, 0));
743 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
744 strerror(rc = errno));
749 static int jt_connect(int argc, char **argv)
751 struct obd_ioctl_data data;
755 do_disconnect(argv[0], 1);
758 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
762 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
764 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
765 OBD_IOC_CONNECT, strerror(rc = errno));
767 conn_addr = data.ioc_addr;
768 conn_cookie = data.ioc_cookie;
772 static int jt_disconnect(int argc, char **argv)
775 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
782 return do_disconnect(argv[0], 0);
785 static int jt__xml(int argc, char **argv)
788 fprintf(stderr, "usage: %s <xml file> <command [args ...]>\n",
793 return do_xml("xml", argv[1]);
796 static int jt__device(int argc, char **argv)
802 fprintf(stderr, "usage: %s devno <command [args ...]>\n",
807 rc = do_device("device", strtoul(argv[1], NULL, 0));
812 rc = jt_connect(1, arg2);
816 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
818 ret = do_disconnect(argv[0], 0);
825 static int jt__threads(int argc, char **argv)
827 int threads, next_thread;
833 "usage: %s numthreads verbose devno <cmd [args ...]>\n",
838 threads = strtoul(argv[1], NULL, 0);
840 verbose = get_verbose(argv[2]);
842 printf("%s: starting %d threads on device %s running %s\n",
843 argv[0], threads, argv[3], argv[4]);
845 for (i = 1, next_thread = verbose; i <= threads; i++) {
848 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
849 strerror(rc = errno));
851 } else if (rc == 0) {
853 argv[2] = "--device";
854 return jt__device(argc - 2, argv + 2);
855 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
856 printf("%s: thread #%d (PID %d) started\n",
861 if (!thread) { /* parent process */
863 printf("%s: started %d threads\n\n", argv[0], i - 1);
867 for (j = 1; j < i; j++) {
869 int ret = wait(&status);
872 fprintf(stderr, "error: %s: wait - %s\n",
873 argv[0], strerror(errno));
878 * This is a hack. We _should_ be able to use
879 * WIFEXITED(status) to see if there was an
880 * error, but it appears to be broken and it
881 * always returns 1 (OK). See wait(2).
883 int err = WEXITSTATUS(status);
886 "%s: PID %d had rc=%d\n",
897 static int jt_detach(int argc, char **argv)
899 struct obd_ioctl_data data;
904 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
908 if (obd_ioctl_pack(&data, &buf, max)) {
909 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
913 rc = ioctl(fd, OBD_IOC_DETACH , buf);
915 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
921 static int jt_cleanup(int argc, char **argv)
923 struct obd_ioctl_data data;
928 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
932 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
934 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
940 static int jt_newdev(int argc, char **argv)
942 struct obd_ioctl_data data;
950 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
954 rc = ioctl(fd, OBD_IOC_NEWDEV , &data);
956 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
959 printf("Current device set to %d\n", data.ioc_dev);
965 static int jt_list(int argc, char **argv)
968 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
973 memset(buf, 0, sizeof(buf));
974 data->ioc_version = OBD_IOCTL_VERSION;
975 data->ioc_addr = conn_addr;
976 data->ioc_cookie = conn_addr;
977 data->ioc_len = sizeof(buf);
978 data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
981 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
985 rc = ioctl(fd, OBD_IOC_LIST , data);
987 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
990 printf("%s", data->ioc_bulk);
996 static int jt_attach(int argc, char **argv)
998 struct obd_ioctl_data data;
1002 if (argc != 2 && argc != 3 && argc != 4) {
1003 fprintf(stderr, "usage: %s type [name [uuid]]\n",
1008 data.ioc_inllen1 = strlen(argv[1]) + 1;
1009 data.ioc_inlbuf1 = argv[1];
1011 data.ioc_inllen2 = strlen(argv[2]) + 1;
1012 data.ioc_inlbuf2 = argv[2];
1016 data.ioc_inllen3 = strlen(argv[3]) + 1;
1017 data.ioc_inlbuf3 = argv[3];
1020 if (obd_ioctl_pack(&data, &buf, max)) {
1021 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1025 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
1027 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
1028 OBD_IOC_ATTACH, strerror(rc = errno));
1029 else if (argc == 3) {
1031 if (strlen(argv[2]) > 128) {
1032 printf("Name too long to set environment\n");
1035 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
1036 rc = setenv(name, argv[1], 1);
1038 printf("error setting env variable %s\n", name);
1045 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
1047 static int do_name2dev(char *func, char *name)
1049 struct obd_ioctl_data data;
1056 data.ioc_inllen1 = strlen(name) + 1;
1057 data.ioc_inlbuf1 = name;
1059 if (obd_ioctl_pack(&data, &buf, max)) {
1060 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
1063 rc = ioctl(fd, OBD_IOC_NAME2DEV , buf);
1065 fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
1066 name, strerror(rc = errno));
1070 memcpy((char *)(&data), buf, sizeof(data));
1072 return data.ioc_dev + N2D_OFF;
1075 static int jt_name2dev(int argc, char **argv)
1078 fprintf(stderr, "usage: %s name\n", cmdname(argv[0]));
1082 rc = do_name2dev(argv[0], argv[1]);
1083 if (rc >= N2D_OFF) {
1084 int dev = rc - N2D_OFF;
1085 rc = do_device(argv[0], dev);
1087 printf("%d\n", dev);
1092 static int jt_setup(int argc, char **argv)
1094 struct obd_ioctl_data data;
1099 fprintf(stderr, "usage: %s [device] [fstype]\n",
1106 if (argv[1][0] == '$') {
1107 rc = do_name2dev(argv[0], argv[1] + 1);
1108 if (rc >= N2D_OFF) {
1109 printf("%s is device %d\n", argv[1],
1111 data.ioc_dev = rc - N2D_OFF;
1114 data.ioc_dev = strtoul(argv[1], NULL, 0);
1115 data.ioc_inllen1 = strlen(argv[1]) + 1;
1116 data.ioc_inlbuf1 = argv[1];
1119 data.ioc_inllen2 = strlen(argv[2]) + 1;
1120 data.ioc_inlbuf2 = argv[2];
1123 if (obd_ioctl_pack(&data, &buf, max)) {
1124 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1127 rc = ioctl(fd, OBD_IOC_SETUP , buf);
1129 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1130 strerror(rc = errno));
1136 static int jt_create(int argc, char **argv)
1138 struct obd_ioctl_data data;
1139 struct timeval next_time;
1140 int count = 1, next_count;
1145 if (argc < 2 || argc > 4) {
1146 fprintf(stderr, "usage: %s num [mode] [verbose]\n",
1150 count = strtoul(argv[1], NULL, 0);
1153 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
1155 data.ioc_obdo1.o_mode = 0100644;
1156 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
1158 verbose = get_verbose(argv[3]);
1160 printf("%s: %d obdos\n", cmdname(argv[0]), count);
1161 gettimeofday(&next_time, NULL);
1162 next_time.tv_sec -= verbose;
1164 for (i = 1, next_count = verbose; i <= count ; i++) {
1165 rc = ioctl(fd, OBD_IOC_CREATE , &data);
1167 fprintf(stderr, "error: %s: #%d - %s\n",
1168 cmdname(argv[0]), i, strerror(rc = errno));
1171 if (be_verbose(verbose, &next_time, i, &next_count, count))
1172 printf("%s: #%d is object id %Ld\n", cmdname(argv[0]),
1173 i, data.ioc_obdo1.o_id);
1178 static int jt_setattr(int argc, char **argv)
1180 struct obd_ioctl_data data;
1184 fprintf(stderr, "usage: %s id mode\n", cmdname(argv[0]));
1188 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1189 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
1190 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
1192 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
1194 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1195 strerror(rc = errno));
1200 static int jt_destroy(int argc, char **argv)
1202 struct obd_ioctl_data data;
1206 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
1210 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1211 data.ioc_obdo1.o_mode = S_IFREG|0644;
1213 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
1215 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1216 strerror(rc = errno));
1221 static int jt_getattr(int argc, char **argv)
1223 struct obd_ioctl_data data;
1226 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
1231 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1232 /* to help obd filter */
1233 data.ioc_obdo1.o_mode = 0100644;
1234 data.ioc_obdo1.o_valid = 0xffffffff;
1235 printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
1237 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1239 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1240 strerror(rc=errno));
1242 printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
1243 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
1248 static int jt_test_getattr(int argc, char **argv)
1250 struct obd_ioctl_data data;
1251 struct timeval start, next_time;
1252 int i, count, next_count;
1255 if (argc != 2 && argc != 3) {
1256 fprintf(stderr, "usage: %s count [verbose]\n",cmdname(argv[0]));
1261 count = strtoul(argv[1], NULL, 0);
1264 verbose = get_verbose(argv[2]);
1268 data.ioc_obdo1.o_valid = 0xffffffff;
1269 data.ioc_obdo1.o_id = 2;
1270 gettimeofday(&start, NULL);
1271 next_time.tv_sec = start.tv_sec - verbose;
1272 next_time.tv_usec = start.tv_usec;
1273 printf("%s: getting %d attrs (testing only): %s", cmdname(argv[0]),
1274 count, ctime(&start.tv_sec));
1276 for (i = 1, next_count = verbose; i <= count; i++) {
1277 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1279 fprintf(stderr, "error: %s: #%d - %s\n",
1280 cmdname(argv[0]), i, strerror(rc = errno));
1283 if (be_verbose(verbose, &next_time, i,&next_count,count))
1284 printf("%s: got attr #%d\n", cmdname(argv[0]), i);
1292 gettimeofday(&end, NULL);
1294 diff = difftime(&end, &start);
1297 printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
1298 cmdname(argv[0]), i, diff, (double)i / diff,
1299 ctime(&end.tv_sec));
1304 static int jt_test_brw(int argc, char **argv)
1306 struct obd_ioctl_data data;
1307 struct timeval start, next_time;
1309 int pages = 1, obdos = 1, count, next_count;
1310 int verbose = 1, write = 0, rw;
1314 if (argc < 2 || argc > 6) {
1316 "usage: %s count [write [verbose [pages [obdos]]]]\n",
1321 count = strtoul(argv[1], NULL, 0);
1324 if (argv[2][0] == 'w' || argv[2][0] == '1')
1326 else if (argv[2][0] == 'r' || argv[2][0] == '0')
1329 verbose = get_verbose(argv[3]);
1333 pages = strtoul(argv[4], NULL, 0);
1335 obdos = strtoul(argv[5], NULL, 0);
1337 if (obdos != 1 && obdos != 2) {
1338 fprintf(stderr, "error: %s: only 1 or 2 obdos supported\n",
1343 len = pages * PAGE_SIZE;
1345 bulk = calloc(obdos, len);
1347 fprintf(stderr, "error: %s: no memory allocating %dx%d pages\n",
1348 cmdname(argv[0]), obdos, pages);
1352 data.ioc_obdo1.o_id = 2;
1353 data.ioc_count = len;
1354 data.ioc_offset = 0;
1355 data.ioc_plen1 = len;
1356 data.ioc_pbuf1 = bulk;
1358 data.ioc_obdo2.o_id = 3;
1359 data.ioc_plen2 = len;
1360 data.ioc_pbuf2 = bulk + len;
1363 gettimeofday(&start, NULL);
1364 next_time.tv_sec = start.tv_sec - verbose;
1365 next_time.tv_usec = start.tv_usec;
1367 printf("%s: %s %d (%dx%d pages) (testing only): %s",
1368 cmdname(argv[0]), write ? "writing" : "reading",
1369 count, obdos, pages, ctime(&start.tv_sec));
1372 * We will put in the start time (and loop count inside the loop)
1373 * at the beginning of each page so that we will be able to validate
1374 * (at some later time) whether the data actually made it or not.
1376 * XXX we do not currently use any of this memory in OBD_IOC_BRW_*
1377 * just to avoid the overhead of the copy_{to,from}_user. It
1378 * can be fixed if we ever need to send real data around.
1380 for (o = 0, b = bulk; o < obdos; o++)
1381 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1382 memcpy(b, &start, sizeof(start));
1384 rw = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1385 for (i = 1, next_count = verbose; i <= count; i++) {
1387 b = bulk + sizeof(struct timeval);
1388 for (o = 0; o < obdos; o++)
1389 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1390 memcpy(b, &count, sizeof(count));
1393 rc = ioctl(fd, rw, &data);
1395 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1396 cmdname(argv[0]), i, strerror(rc = errno),
1397 write ? "write" : "read");
1399 } else if (be_verbose(verbose, &next_time, i,&next_count,count))
1400 printf("%s: %s number %d\n", cmdname(argv[0]),
1401 write ? "write" : "read", i);
1410 gettimeofday(&end, NULL);
1412 diff = difftime(&end, &start);
1415 printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
1416 cmdname(argv[0]), write ? "wrote" : "read", obdos,
1417 pages, i, diff, (double)obdos * i * pages / diff,
1418 ctime(&end.tv_sec));
1423 static int jt_lov_config(int argc, char **argv)
1425 struct obd_ioctl_data data;
1426 struct lov_desc desc;
1432 Parser_printhelp("lovconfig");
1436 if (strlen(argv[1]) > sizeof(uuid_t) - 1) {
1437 fprintf(stderr, "lov_config: no %dB memory for uuid's\n",
1442 memset(&desc, 0, sizeof(desc));
1443 strcpy(desc.ld_uuid, argv[1]);
1444 desc.ld_default_stripecount = strtoul(argv[2], NULL, 0);
1445 desc.ld_default_stripesize = strtoul(argv[3], NULL, 0);
1446 desc.ld_pattern = strtoul(argv[4], NULL, 0);
1447 desc.ld_tgt_count = argc - 5;
1450 size = sizeof(uuid_t) * desc.ld_tgt_count;
1451 uuidarray = malloc(size);
1453 fprintf(stderr, "lov_config: no %dB memory for uuid's\n",
1457 memset(uuidarray, 0, size);
1458 for (i=5 ; i < argc ; i++) {
1459 char *buf = (char *) (uuidarray + i -5 );
1460 if (strlen(argv[i]) >= sizeof(uuid_t)) {
1461 fprintf(stderr, "lov_config: arg %d (%s) too long\n",
1466 strcpy(buf, argv[i]);
1469 data.ioc_inllen1 = sizeof(desc);
1470 data.ioc_inlbuf1 = (char *)&desc;
1471 data.ioc_inllen2 = size;
1472 data.ioc_inlbuf2 = (char *)uuidarray;
1474 if (obd_ioctl_pack(&data, &buf, max)) {
1475 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1479 rc = ioctl(fd, OBD_IOC_LOV_CONFIG , buf);
1481 fprintf(stderr, "lov_config: error: %s: %s\n",
1482 cmdname(argv[0]),strerror(rc = errno));
1488 static int jt_test_ldlm(int argc, char **argv)
1490 struct obd_ioctl_data data;
1494 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1498 rc = ioctl(fd, IOC_LDLM_TEST, &data);
1500 fprintf(stderr, "error: %s: test failed: %s\n",
1501 cmdname(argv[0]), strerror(rc = errno));
1505 static int jt_newconn(int argc, char **argv)
1507 struct obd_ioctl_data data;
1511 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1515 rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN , &data);
1517 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1518 strerror(rc = errno));
1523 static int jt_quit(int argc, char **argv)
1525 Parser_quit(argc, argv);
1530 command_t cmdlist[] = {
1532 {"--xml", jt__xml, 0, "--xml <xml file> <command [args ...]>"},
1533 {"--device", jt__device, 0, "--device <devno> <command [args ...]>"},
1534 {"--threads", jt__threads, 0,
1535 "--threads <threads> <devno> <command [args ...]>"},
1537 /* Device configuration commands */
1538 {"lovconfig", jt_lov_config, 0, "configure lov data on MDS "
1539 "(usage: lov-uuid stripecount, stripesize, pattern, UUID1, [UUID2, ...])"},
1540 {"list", jt_list, 0, "list the devices (no args)"},
1541 {"newdev", jt_newdev, 0, "set device to a new unused obd (no args)"},
1542 {"device", jt_device, 0, "set current device (args device_no name)"},
1543 {"name2dev", jt_name2dev, 0, "set device by name (args name)"},
1544 {"attach", jt_attach, 0, "name the type of device (args: type data"},
1545 {"setup", jt_setup, 0, "setup device (args: <blkdev> [data]"},
1546 {"detach", jt_detach, 0, "detach the current device (arg: )"},
1547 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
1549 /* Session commands */
1550 {"connect", jt_connect, 0, "connect - get a connection to device"},
1551 {"disconnect", jt_disconnect, 0,
1552 "disconnect - break connection to device"},
1554 /* Session operations */
1555 {"create", jt_create, 0, "create [count [mode [verbose]]]"},
1556 {"destroy", jt_destroy, 0, "destroy <id>"},
1557 {"getattr", jt_getattr, 0, "getattr <id>"},
1558 {"setattr", jt_setattr, 0, "setattr <id> <mode>"},
1559 {"newconn", jt_newconn, 0, "newconn [newuuid]"},
1560 {"test_getattr", jt_test_getattr, 0, "test_getattr <count> [verbose]"},
1561 {"test_brw", jt_test_brw, 0, "test_brw <count> [write [verbose]]"},
1562 {"test_ldlm", jt_test_ldlm, 0, "test lock manager (no args)"},
1564 /* User interface commands */
1565 {"help", Parser_help, 0, "help"},
1566 {"exit", jt_quit, 0, "quit"},
1567 {"quit", jt_quit, 0, "quit"},
1572 static void signal_server(int sig)
1574 if (sig == SIGINT) {
1575 do_disconnect("sigint", 1);
1578 fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
1582 int main(int argc, char **argv)
1584 struct sigaction sigact;
1586 sigact.sa_handler = signal_server;
1587 sigfillset(&sigact.sa_mask);
1588 sigact.sa_flags = SA_RESTART;
1589 sigaction(SIGINT, &sigact, NULL);
1593 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
1595 Parser_init("obdctl > ", cmdlist);
1596 rc = Parser_commands();
1599 do_disconnect(argv[0], 1);