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>
54 #include <linux/list.h>
60 static int jt_newdev(int argc, char **argv);
61 static int jt_attach(int argc, char **argv);
62 static int jt_setup(int argc, char **argv);
73 #define IOCINIT(data) \
75 memset(&data, 0, sizeof(data)); \
76 data.ioc_version = OBD_IOCTL_VERSION; \
77 data.ioc_conn1 = connid; \
78 data.ioc_len = sizeof(data); \
80 fprintf(stderr, "No device open, use device\n"); \
86 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
105 0, 0, # struct list_head
111 char * obdo_print(struct obdo *obd)
115 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
116 "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
117 "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
136 static char *cmdname(char *func)
138 static char buf[512];
141 sprintf(buf, "%s-%d", func, thread);
148 int getfd(char *func)
151 fd = open("/dev/obd", O_RDWR);
153 fprintf(stderr, "error: %s: opening /dev/obd: %s\n",
154 cmdname(func), strerror(errno));
161 #define difftime(a, b) \
162 ((double)(a)->tv_sec - (b)->tv_sec + \
163 ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
166 #define difftime(a, b) (((a)->tv_sec - (b)->tv_sec) + \
167 (((a)->tv_usec - (b)->tv_usec) / 1000000))
170 static int be_verbose(int verbose, struct timeval *next_time,
171 int num, int *next_num, int num_total)
178 if (next_time != NULL)
179 gettimeofday(&now, NULL);
181 /* A positive verbosity means to print every X iterations */
183 (next_num == NULL || num >= *next_num || num >= num_total)) {
184 *next_num += verbose;
186 next_time->tv_sec = now.tv_sec - verbose;
187 next_time->tv_usec = now.tv_usec;
192 /* A negative verbosity means to print at most each X seconds */
193 if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0){
194 next_time->tv_sec = now.tv_sec - verbose;
195 next_time->tv_usec = now.tv_usec;
204 static int get_verbose(const char *arg)
208 if (!arg || arg[0] == 'v')
210 else if (arg[0] == 's' || arg[0] == 'q')
213 verbose = (int) strtoul(arg, NULL, 0);
216 printf("Print status every %d seconds\n", -verbose);
217 else if (verbose == 1)
218 printf("Print status every operation\n");
219 else if (verbose > 1)
220 printf("Print status every %d operations\n", verbose);
225 static int do_disconnect(char *func, int verbose)
227 struct obd_ioctl_data data;
234 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
236 fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
237 OBD_IOC_DISCONNECT, strerror(errno));
240 printf("%s: disconnected connid %d\n", cmdname(func),
248 extern command_t cmdlist[];
250 static int xml_command(char *cmd, ...) {
258 while (((arg = va_arg(args, char *)) != NULL) && (i < 8)) {
266 for (j = 0; j < i; j++)
267 printf("%s ", cmds[j]);
271 return Parser_execarg(i, cmds, cmdlist);
274 static network_t *xml_network(xmlDocPtr doc, xmlNodePtr root) {
275 xmlNodePtr cur = root->xmlChildrenNode;
278 if ((net = (network_t *)calloc(1, sizeof(network_t))) == NULL) {
279 printf("error: unable to malloc network_t\n");
283 net->type = xmlGetProp(root, "type");
284 if (net->type == NULL) {
285 printf("error: type attrib required (tcp, elan, myrinet)\n");
290 while (cur != NULL) {
291 if (!xmlStrcmp(cur->name, "server"))
292 net->server = xmlNodeGetContent(cur);
294 if (!xmlStrcmp(cur->name, "port"))
295 net->port = atoi(xmlNodeGetContent(cur));
300 if (net->server == NULL) {
301 printf("error: <server> tag required\n");
309 static int xml_mds(xmlDocPtr doc, xmlNodePtr root,
310 char *serv_id, char *serv_uuid) {
311 xmlNodePtr cur = root->xmlChildrenNode;
312 char *fstype = NULL, *device = NULL;
315 printf("--- Setting up MDS ---\n");
316 while (cur != NULL) {
317 if (!xmlStrcmp(cur->name, "fstype"))
318 fstype = xmlNodeGetContent(cur);
320 if (!xmlStrcmp(cur->name, "device"))
321 device = xmlNodeGetContent(cur);
326 if ((fstype == NULL) || (device == NULL)) {
327 printf("error: <fstype> and <device> tags required\n");
331 if ((rc = xml_command("newdev", NULL)) != 0)
334 if ((rc = xml_command("attach", "mds", "MDSDEV", NULL)) != 0)
337 if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
343 static int xml_obd(xmlDocPtr doc, xmlNodePtr root,
344 char *serv_id, char *serv_uuid) {
345 xmlNodePtr cur = root->xmlChildrenNode;
346 char *obdtype, *format = NULL, *fstype = NULL, *device = NULL;
349 obdtype = xmlGetProp(root, "type");
350 printf("--- Setting up OBD ---\n");
352 while (cur != NULL) {
353 if (!xmlStrcmp(cur->name, "fstype"))
354 fstype = xmlNodeGetContent(cur);
356 if (!xmlStrcmp(cur->name, "device"))
357 device = xmlNodeGetContent(cur);
359 if (!xmlStrcmp(cur->name, "autoformat"))
360 format = xmlNodeGetContent(cur);
365 if ((obdtype == NULL) || (fstype == NULL) || (device == NULL)) {
366 printf("error: 'type' attrib and <fstype> and <device> tags required\n");
370 /* FIXME: Building and configuring loopback devices should go here
371 * but is currently unsupported. You'll have to use the scripts
372 * for now until support is added, or specify a real device.
375 if ((rc = xml_command("newdev", NULL)) != 0)
378 if ((rc = xml_command("attach", obdtype, "OBDDEV", NULL)) != 0)
381 if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
387 static int xml_ost(xmlDocPtr doc, xmlNodePtr root,
388 char *serv_id, char *serv_uuid) {
391 printf("--- Setting up OST ---\n");
392 if ((rc = xml_command("newdev", NULL)) != 0)
395 if ((rc = xml_command("attach", "ost", "OSTDEV", NULL)) != 0)
398 if ((rc = xml_command("setup", "$OBDDEV", NULL)) != 0)
404 static int xml_osc(xmlDocPtr doc, xmlNodePtr root,
405 char *serv_id, char *serv_uuid) {
406 xmlNodePtr cur = root->xmlChildrenNode;
407 network_t *net = NULL;
410 printf("--- Setting up OSC ---\n");
411 while (cur != NULL) {
412 if (!xmlStrcmp(cur->name, "network")) {
413 net = xml_network(doc, cur);
421 printf("error: <network> tag required\n");
425 if ((rc = xml_command("newdev", NULL)) != 0) {
430 if ((rc = xml_command("attach", "osc", "OSCDEV", NULL)) != 0) {
435 if ((rc = xml_command("setup", "OSTDEV", net->server, NULL)) != 0) {
445 static int xml_mdc(xmlDocPtr doc, xmlNodePtr root,
446 char *serv_id, char *serv_uuid) {
447 xmlNodePtr cur = root->xmlChildrenNode;
448 network_t *net = NULL;
451 printf("--- Setting up MDC ---\n");
452 while (cur != NULL) {
453 if (!xmlStrcmp(cur->name, "network")) {
454 net = xml_network(doc, cur);
462 printf("error: <network> tag required\n");
466 if ((rc = xml_command("newdev", NULL)) != 0) {
471 if ((rc = xml_command("attach", "mdc", "MDCDEV", NULL)) != 0) {
476 if ((rc = xml_command("setup", "MDSDEV", net->server, NULL)) != 0) {
486 static int xml_lov(xmlDocPtr doc, xmlNodePtr root,
487 char *serv_id, char *serv_uuid) {
488 printf("--- Setting up LOV ---\n");
492 static int xml_router(xmlDocPtr doc, xmlNodePtr root,
493 char *serv_id, char *serv_uuid) {
494 printf("--- Setting up ROUTER ---\n");
498 static int xml_ldlm(xmlDocPtr doc, xmlNodePtr root,
499 char *serv_id, char *serv_uuid) {
502 printf("--- Setting up LDLM ---\n");
503 if ((rc = xml_command("newdev", NULL)) != 0)
506 if ((rc = xml_command("attach", "ldlm", "LDLMDEV", NULL)) != 0)
509 if ((rc = xml_command("setup", NULL)) != 0)
515 static int xml_service(xmlDocPtr doc, xmlNodePtr root,
516 int serv_num, char *serv_id, char *serv_uuid) {
517 xmlNodePtr cur = root;
520 while (cur != NULL) {
521 id = xmlGetProp(cur, "id");
522 uuid = xmlGetProp(cur, "uuid");
524 if (xmlStrcmp(id, serv_id) ||
525 xmlStrcmp(uuid, serv_uuid)) {
530 if (!xmlStrcmp(cur->name, "mds"))
531 return xml_mds(doc, cur, serv_id, serv_uuid);
532 else if (!xmlStrcmp(cur->name, "obd"))
533 return xml_obd(doc, cur, serv_id, serv_uuid);
534 else if (!xmlStrcmp(cur->name, "ost"))
535 return xml_ost(doc, cur, serv_id, serv_uuid);
536 else if (!xmlStrcmp(cur->name, "osc"))
537 return xml_osc(doc, cur, serv_id, serv_uuid);
538 else if (!xmlStrcmp(cur->name, "mdc"))
539 return xml_mdc(doc, cur, serv_id, serv_uuid);
540 else if (!xmlStrcmp(cur->name, "lov"))
541 return xml_lov(doc, cur, serv_id, serv_uuid);
542 else if (!xmlStrcmp(cur->name, "router"))
543 return xml_router(doc, cur, serv_id, serv_uuid);
544 else if (!xmlStrcmp(cur->name, "ldlm"))
545 return xml_ldlm(doc, cur, serv_id, serv_uuid);
552 printf("error: No XML config branch for id=%s uuid=%s\n",
557 static int xml_profile(xmlDocPtr doc, xmlNodePtr root,
558 int prof_num, char *prof_id, char *prof_uuid) {
559 xmlNodePtr parent, cur = root;
560 char *id, *uuid, *srv_id, *srv_uuid;
563 while (cur != NULL) {
564 id = xmlGetProp(cur, "id");
565 uuid = xmlGetProp(cur, "uuid");
567 if (xmlStrcmp(cur->name, "profile") ||
568 xmlStrcmp(id, prof_id) ||
569 xmlStrcmp(uuid, prof_uuid)) {
574 /* FIXME: Doesn't understand mountpoints yet
575 * xml_mountpoint(doc, root, ...);
578 /* Setup each service in turn
579 * FIXME: Should be sorted by "num" attr, we shouldn't
580 * assume they're in order in the XML document.
583 cur = cur->xmlChildrenNode;
584 while (cur != NULL) {
585 if (!xmlStrcmp(cur->name, "service_id")) {
586 num = atoi(xmlGetProp(cur, "num"));
587 rc = xml_service(doc, root, num,
588 srv_id = xmlGetProp(cur, "id"),
589 srv_uuid = xmlGetProp(cur, "uuid"));
591 printf("error: service config\n");
605 static int xml_node(xmlDocPtr doc, xmlNodePtr root) {
606 xmlNodePtr parent, cur = root;
610 /* Walk the node tags looking for ours */
611 while (cur != NULL) {
612 if (xmlStrcmp(cur->name, "node")) {
617 id = xmlGetProp(cur, "id");
621 uuid = xmlGetProp(cur, "uuid");
625 /* FIXME: Verify our ID and UUID against /etc/lustre/id
626 * so we're sure we are who we think we are.
629 /* Setup each profile in turn
630 * FIXME: Should be sorted by "num" attr, we shouldn't
631 * assume they're in order in the XML document.
634 cur = cur->xmlChildrenNode;
635 while (cur != NULL) {
636 if (!xmlStrcmp(cur->name, "profile_id")) {
637 num = atoi(xmlGetProp(cur, "num"));
638 rc = xml_profile(doc, root, num,
639 xmlGetProp(cur, "id"),
640 xmlGetProp(cur, "uuid"));
654 static int do_xml(char *func, char *file)
660 doc = xmlParseFile(file);
662 fprintf(stderr, "error: Unable to parse XML\n");
666 cur = xmlDocGetRootElement(doc);
668 fprintf(stderr, "error: Empty XML\n");
673 if (xmlStrcmp(cur->name, (const xmlChar *)"lustre")) {
674 fprintf(stderr, "error: Root node != <lustre>\n");
679 /* FIXME: Validate the XML against the DTD here */
681 /* FIXME: Merge all the text nodes under each branch and
682 * prune empty nodes. Just to make the parsing more
683 * tolerant, the exact location of nested tags isn't
687 rc = xml_node(doc, cur->xmlChildrenNode);
693 static int do_device(char *func, int dev)
695 struct obd_ioctl_data data;
697 memset(&data, 0, sizeof(data));
704 if (obd_ioctl_pack(&data, &buf, max)) {
705 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
709 return ioctl(fd, OBD_IOC_DEVICE , buf);
712 static int jt_device(int argc, char **argv)
714 do_disconnect(argv[0], 1);
717 fprintf(stderr, "usage: %s devno\n", cmdname(argv[0]));
721 rc = do_device(argv[0], strtoul(argv[1], NULL, 0));
724 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
725 strerror(rc = errno));
730 static int jt_connect(int argc, char **argv)
732 struct obd_ioctl_data data;
736 do_disconnect(argv[0], 1);
739 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
743 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
745 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
746 OBD_IOC_CONNECT, strerror(rc = errno));
748 connid = data.ioc_conn1;
753 static int jt_disconnect(int argc, char **argv)
756 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
760 return do_disconnect(argv[0], 0);
763 static int jt__xml(int argc, char **argv)
766 fprintf(stderr, "usage: %s <xml file> <command [args ...]>\n",
771 return do_xml("xml", argv[1]);
774 static int jt__device(int argc, char **argv)
780 fprintf(stderr, "usage: %s devno <command [args ...]>\n",
785 rc = do_device("device", strtoul(argv[1], NULL, 0));
790 rc = jt_connect(1, arg2);
794 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
796 ret = do_disconnect(argv[0], 0);
803 static int jt__threads(int argc, char **argv)
805 int threads, next_thread;
811 "usage: %s numthreads verbose devno <cmd [args ...]>\n",
816 threads = strtoul(argv[1], NULL, 0);
818 verbose = get_verbose(argv[2]);
820 printf("%s: starting %d threads on device %s running %s\n",
821 argv[0], threads, argv[3], argv[4]);
823 for (i = 1, next_thread = verbose; i <= threads; i++) {
826 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
827 strerror(rc = errno));
829 } else if (rc == 0) {
831 argv[2] = "--device";
832 return jt__device(argc - 2, argv + 2);
833 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
834 printf("%s: thread #%d (PID %d) started\n",
839 if (!thread) { /* parent process */
841 printf("%s: started %d threads\n\n", argv[0], i - 1);
845 for (j = 1; j < i; j++) {
847 int ret = wait(&status);
850 fprintf(stderr, "error: %s: wait - %s\n",
851 argv[0], strerror(errno));
856 * This is a hack. We _should_ be able to use
857 * WIFEXITED(status) to see if there was an
858 * error, but it appears to be broken and it
859 * always returns 1 (OK). See wait(2).
861 int err = WEXITSTATUS(status);
864 "%s: PID %d had rc=%d\n",
875 static int jt_detach(int argc, char **argv)
877 struct obd_ioctl_data data;
882 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
886 if (obd_ioctl_pack(&data, &buf, max)) {
887 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
891 rc = ioctl(fd, OBD_IOC_DETACH , buf);
893 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
899 static int jt_cleanup(int argc, char **argv)
901 struct obd_ioctl_data data;
906 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
910 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
912 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
918 static int jt_newdev(int argc, char **argv)
920 struct obd_ioctl_data data;
928 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
932 rc = ioctl(fd, OBD_IOC_NEWDEV , &data);
934 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
937 printf("Current device set to %d\n", data.ioc_dev);
943 static int jt_attach(int argc, char **argv)
945 struct obd_ioctl_data data;
949 if (argc != 2 && argc != 3) {
950 fprintf(stderr, "usage: %s type [name [uuid]]\n",
955 data.ioc_inllen1 = strlen(argv[1]) + 1;
956 data.ioc_inlbuf1 = argv[1];
958 data.ioc_inllen2 = strlen(argv[2]) + 1;
959 data.ioc_inlbuf2 = argv[2];
962 if (obd_ioctl_pack(&data, &buf, max)) {
963 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
967 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
969 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
970 OBD_IOC_ATTACH, strerror(rc = errno));
971 else if (argc == 3) {
973 if (strlen(argv[2]) > 128) {
974 printf("Name too long to set environment\n");
977 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
978 rc = setenv(name, argv[1], 1);
980 printf("error setting env variable %s\n", name);
987 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
989 static int do_name2dev(char *func, char *name)
991 struct obd_ioctl_data data;
998 data.ioc_inllen1 = strlen(name) + 1;
999 data.ioc_inlbuf1 = name;
1001 if (obd_ioctl_pack(&data, &buf, max)) {
1002 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
1005 rc = ioctl(fd, OBD_IOC_NAME2DEV , buf);
1007 fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
1008 name, strerror(rc = errno));
1012 memcpy((char *)(&data), buf, sizeof(data));
1014 return data.ioc_dev + N2D_OFF;
1017 static int jt_name2dev(int argc, char **argv)
1020 fprintf(stderr, "usage: %s name\n", cmdname(argv[0]));
1024 rc = do_name2dev(argv[0], argv[1]);
1025 if (rc >= N2D_OFF) {
1026 int dev = rc - N2D_OFF;
1027 rc = do_device(argv[0], dev);
1029 printf("%d\n", dev);
1034 static int jt_setup(int argc, char **argv)
1036 struct obd_ioctl_data data;
1041 fprintf(stderr, "usage: %s [device] [fstype]\n",
1048 if (argv[1][0] == '$') {
1049 rc = do_name2dev(argv[0], argv[1] + 1);
1050 if (rc >= N2D_OFF) {
1051 printf("%s is device %d\n", argv[1],
1053 data.ioc_dev = rc - N2D_OFF;
1056 data.ioc_dev = strtoul(argv[1], NULL, 0);
1057 data.ioc_inllen1 = strlen(argv[1]) + 1;
1058 data.ioc_inlbuf1 = argv[1];
1061 data.ioc_inllen2 = strlen(argv[2]) + 1;
1062 data.ioc_inlbuf2 = argv[2];
1065 if (obd_ioctl_pack(&data, &buf, max)) {
1066 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1069 rc = ioctl(fd, OBD_IOC_SETUP , buf);
1071 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1072 strerror(rc = errno));
1078 static int jt_create(int argc, char **argv)
1080 struct obd_ioctl_data data;
1081 struct timeval next_time;
1082 int count = 1, next_count;
1087 if (argc < 2 || argc > 4) {
1088 fprintf(stderr, "usage: %s num [mode] [verbose]\n",
1092 count = strtoul(argv[1], NULL, 0);
1095 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
1097 data.ioc_obdo1.o_mode = 0100644;
1098 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
1100 verbose = get_verbose(argv[3]);
1102 printf("%s: %d obdos\n", cmdname(argv[0]), count);
1103 gettimeofday(&next_time, NULL);
1104 next_time.tv_sec -= verbose;
1106 for (i = 1, next_count = verbose; i <= count ; i++) {
1107 rc = ioctl(fd, OBD_IOC_CREATE , &data);
1109 fprintf(stderr, "error: %s: #%d - %s\n",
1110 cmdname(argv[0]), i, strerror(rc = errno));
1113 if (be_verbose(verbose, &next_time, i, &next_count, count))
1114 printf("%s: #%d is object id %Ld\n", cmdname(argv[0]),
1115 i, data.ioc_obdo1.o_id);
1120 static int jt_setattr(int argc, char **argv)
1122 struct obd_ioctl_data data;
1126 fprintf(stderr, "usage: %s id mode\n", cmdname(argv[0]));
1130 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1131 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
1132 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
1134 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
1136 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1137 strerror(rc = errno));
1142 static int jt_destroy(int argc, char **argv)
1144 struct obd_ioctl_data data;
1148 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
1152 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1153 data.ioc_obdo1.o_mode = S_IFREG|0644;
1155 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
1157 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1158 strerror(rc = errno));
1163 static int jt_getattr(int argc, char **argv)
1165 struct obd_ioctl_data data;
1168 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
1173 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1174 /* to help obd filter */
1175 data.ioc_obdo1.o_mode = 0100644;
1176 data.ioc_obdo1.o_valid = 0xffffffff;
1177 printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
1179 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1181 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1182 strerror(rc=errno));
1184 printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
1185 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
1190 static int jt_test_getattr(int argc, char **argv)
1192 struct obd_ioctl_data data;
1193 struct timeval start, next_time;
1194 int i, count, next_count;
1197 if (argc != 2 && argc != 3) {
1198 fprintf(stderr, "usage: %s count [verbose]\n",cmdname(argv[0]));
1203 count = strtoul(argv[1], NULL, 0);
1206 verbose = get_verbose(argv[2]);
1210 data.ioc_obdo1.o_valid = 0xffffffff;
1211 data.ioc_obdo1.o_id = 2;
1212 gettimeofday(&start, NULL);
1213 next_time.tv_sec = start.tv_sec - verbose;
1214 next_time.tv_usec = start.tv_usec;
1215 printf("%s: getting %d attrs (testing only): %s", cmdname(argv[0]),
1216 count, ctime(&start.tv_sec));
1218 for (i = 1, next_count = verbose; i <= count; i++) {
1219 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1221 fprintf(stderr, "error: %s: #%d - %s\n",
1222 cmdname(argv[0]), i, strerror(rc = errno));
1225 if (be_verbose(verbose, &next_time, i,&next_count,count))
1226 printf("%s: got attr #%d\n", cmdname(argv[0]), i);
1234 gettimeofday(&end, NULL);
1236 diff = difftime(&end, &start);
1239 printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
1240 cmdname(argv[0]), i, diff, (double)i / diff,
1241 ctime(&end.tv_sec));
1246 static int jt_test_brw(int argc, char **argv)
1248 struct obd_ioctl_data data;
1249 struct timeval start, next_time;
1251 int pages = 1, obdos = 1, count, next_count;
1252 int verbose = 1, write = 0, rw;
1256 if (argc < 2 || argc > 6) {
1258 "usage: %s count [write [verbose [pages [obdos]]]]\n",
1263 count = strtoul(argv[1], NULL, 0);
1266 if (argv[2][0] == 'w' || argv[2][0] == '1')
1268 else if (argv[2][0] == 'r' || argv[2][0] == '0')
1271 verbose = get_verbose(argv[3]);
1275 pages = strtoul(argv[4], NULL, 0);
1277 obdos = strtoul(argv[5], NULL, 0);
1279 if (obdos != 1 && obdos != 2) {
1280 fprintf(stderr, "error: %s: only 1 or 2 obdos supported\n",
1285 len = pages * PAGE_SIZE;
1287 bulk = calloc(obdos, len);
1289 fprintf(stderr, "error: %s: no memory allocating %dx%d pages\n",
1290 cmdname(argv[0]), obdos, pages);
1294 data.ioc_conn2 = connid;
1295 data.ioc_obdo1.o_id = 2;
1296 data.ioc_count = len;
1297 data.ioc_offset = 0;
1298 data.ioc_plen1 = len;
1299 data.ioc_pbuf1 = bulk;
1301 data.ioc_obdo2.o_id = 3;
1302 data.ioc_plen2 = len;
1303 data.ioc_pbuf2 = bulk + len;
1306 gettimeofday(&start, NULL);
1307 next_time.tv_sec = start.tv_sec - verbose;
1308 next_time.tv_usec = start.tv_usec;
1310 printf("%s: %s %d (%dx%d pages) (testing only): %s",
1311 cmdname(argv[0]), write ? "writing" : "reading",
1312 count, obdos, pages, ctime(&start.tv_sec));
1315 * We will put in the start time (and loop count inside the loop)
1316 * at the beginning of each page so that we will be able to validate
1317 * (at some later time) whether the data actually made it or not.
1319 * XXX we do not currently use any of this memory in OBD_IOC_BRW_*
1320 * just to avoid the overhead of the copy_{to,from}_user. It
1321 * can be fixed if we ever need to send real data around.
1323 for (o = 0, b = bulk; o < obdos; o++)
1324 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1325 memcpy(b, &start, sizeof(start));
1327 rw = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1328 for (i = 1, next_count = verbose; i <= count; i++) {
1330 b = bulk + sizeof(struct timeval);
1331 for (o = 0; o < obdos; o++)
1332 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1333 memcpy(b, &count, sizeof(count));
1336 rc = ioctl(fd, rw, &data);
1338 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1339 cmdname(argv[0]), i, strerror(rc = errno),
1340 write ? "write" : "read");
1342 } else if (be_verbose(verbose, &next_time, i,&next_count,count))
1343 printf("%s: %s number %d\n", cmdname(argv[0]),
1344 write ? "write" : "read", i);
1353 gettimeofday(&end, NULL);
1355 diff = difftime(&end, &start);
1358 printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
1359 cmdname(argv[0]), write ? "wrote" : "read", obdos,
1360 pages, i, diff, (double)obdos * i * pages / diff,
1361 ctime(&end.tv_sec));
1366 static int jt_test_ldlm(int argc, char **argv)
1368 struct obd_ioctl_data data;
1372 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1376 rc = ioctl(fd, IOC_LDLM_TEST, &data);
1378 fprintf(stderr, "error: %s: test failed: %s\n",
1379 cmdname(argv[0]), strerror(rc = errno));
1383 static int jt_newconn(int argc, char **argv)
1385 struct obd_ioctl_data data;
1389 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1393 rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN , &data);
1395 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1396 strerror(rc = errno));
1401 static int jt_quit(int argc, char **argv)
1403 Parser_quit(argc, argv);
1408 command_t cmdlist[] = {
1410 {"--xml", jt__xml, 0, "--xml <xml file> <command [args ...]>"},
1411 {"--device", jt__device, 0, "--device <devno> <command [args ...]>"},
1412 {"--threads", jt__threads, 0,
1413 "--threads <threads> <devno> <command [args ...]>"},
1415 /* Device configuration commands */
1416 {"newdev", jt_newdev, 0, "set device to a new unused obd (no args)"},
1417 {"device", jt_device, 0, "set current device (args device_no name)"},
1418 {"name2dev", jt_name2dev, 0, "set device by name (args name)"},
1419 {"attach", jt_attach, 0, "name the type of device (args: type data"},
1420 {"setup", jt_setup, 0, "setup device (args: <blkdev> [data]"},
1421 {"detach", jt_detach, 0, "detach the current device (arg: )"},
1422 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
1424 /* Session commands */
1425 {"connect", jt_connect, 0, "connect - get a connection to device"},
1426 {"disconnect", jt_disconnect, 0,
1427 "disconnect - break connection to device"},
1429 /* Session operations */
1430 {"create", jt_create, 0, "create [count [mode [verbose]]]"},
1431 {"destroy", jt_destroy, 0, "destroy <id>"},
1432 {"getattr", jt_getattr, 0, "getattr <id>"},
1433 {"setattr", jt_setattr, 0, "setattr <id> <mode>"},
1434 {"newconn", jt_newconn, 0, "newconn [newuuid]"},
1435 {"test_getattr", jt_test_getattr, 0, "test_getattr <count> [verbose]"},
1436 {"test_brw", jt_test_brw, 0, "test_brw <count> [write [verbose]]"},
1437 {"test_ldlm", jt_test_ldlm, 0, "test lock manager (no args)"},
1439 /* User interface commands */
1440 {"help", Parser_help, 0, "help"},
1441 {"exit", jt_quit, 0, "quit"},
1442 {"quit", jt_quit, 0, "quit"},
1447 static void signal_server(int sig)
1449 if (sig == SIGINT) {
1450 do_disconnect("sigint", 1);
1453 fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
1457 int main(int argc, char **argv)
1459 struct sigaction sigact;
1461 sigact.sa_handler = signal_server;
1462 sigfillset(&sigact.sa_mask);
1463 sigact.sa_flags = SA_RESTART;
1464 sigaction(SIGINT, &sigact, NULL);
1468 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
1470 Parser_init("obdctl > ", cmdlist);
1471 rc = Parser_commands();
1474 do_disconnect(argv[0], 1);