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>
37 #include <linux/lustre_lib.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_dlm.h>
41 #include <libxml/xmlmemory.h>
42 #include <libxml/parser.h>
48 #include <netinet/in.h>
53 #include <linux/list.h>
59 static int jt_newdev(int argc, char **argv);
60 static int jt_attach(int argc, char **argv);
61 static int jt_setup(int argc, char **argv);
72 #define IOCINIT(data) \
74 memset(&data, 0, sizeof(data)); \
75 data.ioc_version = OBD_IOCTL_VERSION; \
76 data.ioc_conn1 = connid; \
77 data.ioc_len = sizeof(data); \
79 fprintf(stderr, "No device open, use device\n"); \
85 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
104 0, 0, # struct list_head
110 char * obdo_print(struct obdo *obd)
114 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
115 "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
116 "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
135 static char *cmdname(char *func)
137 static char buf[512];
140 sprintf(buf, "%s-%d", func, thread);
147 int getfd(char *func)
150 fd = open("/dev/obd", O_RDWR);
152 fprintf(stderr, "error: %s: opening /dev/obd: %s\n",
153 cmdname(func), strerror(errno));
160 #define difftime(a, b) \
161 ((double)(a)->tv_sec - (b)->tv_sec + \
162 ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
165 #define difftime(a, b) (((a)->tv_sec - (b)->tv_sec) + \
166 (((a)->tv_usec - (b)->tv_usec) / 1000000))
169 static int be_verbose(int verbose, struct timeval *next_time,
170 int num, int *next_num, int num_total)
177 if (next_time != NULL)
178 gettimeofday(&now, NULL);
180 /* A positive verbosity means to print every X iterations */
182 (next_num == NULL || num >= *next_num || num >= num_total)) {
183 *next_num += verbose;
185 next_time->tv_sec = now.tv_sec - verbose;
186 next_time->tv_usec = now.tv_usec;
191 /* A negative verbosity means to print at most each X seconds */
192 if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0){
193 next_time->tv_sec = now.tv_sec - verbose;
194 next_time->tv_usec = now.tv_usec;
203 static int get_verbose(const char *arg)
207 if (!arg || arg[0] == 'v')
209 else if (arg[0] == 's' || arg[0] == 'q')
212 verbose = (int) strtoul(arg, NULL, 0);
215 printf("Print status every %d seconds\n", -verbose);
216 else if (verbose == 1)
217 printf("Print status every operation\n");
218 else if (verbose > 1)
219 printf("Print status every %d operations\n", verbose);
224 static int do_disconnect(char *func, int verbose)
226 struct obd_ioctl_data data;
233 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
235 fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
236 OBD_IOC_DISCONNECT, strerror(errno));
239 printf("%s: disconnected connid %d\n", cmdname(func),
247 extern command_t cmdlist[];
249 /* Given a XML document and the root of a mds branch do the setup */
250 static int xml_mds(xmlDocPtr doc, xmlNodePtr root,
251 char *serv_id, char *serv_uuid) {
252 xmlNodePtr cur = root->xmlChildrenNode;
253 char *fstype = NULL, *device = NULL;
254 char *newdev[1] = { "newdev" };
255 char *attach[3] = { "attach", "mds", "MDSDEV" };
256 char *setup[3] = { "setup", NULL, NULL };
259 while (cur != NULL) {
260 if (!xmlStrcmp(cur->name, "fstype"))
261 fstype = cur->content;
263 if (!xmlStrcmp(cur->name, "device"))
264 device = cur->content;
267 if ((fstype == NULL) || (device == NULL))
270 /* Invoke commands as if passed interactively */
271 rc = jt_newdev(1, newdev);
275 rc = jt_attach(3, attach);
281 rc = jt_setup(3, setup);
288 /* Given a XML document and the root of a obd branch do the setup */
289 static int xml_obd(xmlDocPtr doc, xmlNodePtr root,
290 char *serv_id, char *serv_uuid) {
291 /* FIXME: Fill in the guts... */
295 /* Given a XML document and the root of a ost branch do the setup */
296 static int xml_ost(xmlDocPtr doc, xmlNodePtr root,
297 char *serv_id, char *serv_uuid) {
298 /* FIXME: Fill in the guts... */
302 /* Given a XML document and the root of a osc branch do the setup */
303 static int xml_osc(xmlDocPtr doc, xmlNodePtr root,
304 char *serv_id, char *serv_uuid) {
305 xmlNodePtr cur = root->xmlChildrenNode;
306 char *type = NULL, *address = NULL;
307 char *newdev[1] = { "newdev" };
308 char *attach[3] = { "attach", "osc", "OSCDEV" };
309 char *setup[2] = { "setup", "-1" };
312 while (cur != NULL) {
313 if (!xmlStrcmp(cur->name, "network")) {
314 type = xmlGetProp(cur, "type");
318 address = xmlGetProp(cur, "address");
322 /* FIXME: Do the portals setup here as well? */
328 /* Invoke commands as if passed interactively */
329 rc = jt_newdev(1, newdev);
333 rc = jt_attach(2, attach);
337 rc = jt_setup(1, setup);
344 /* Given a XML document and the root of a lov branch do the setup */
345 static int xml_lov(xmlDocPtr doc, xmlNodePtr root,
346 char *serv_id, char *serv_uuid) {
347 /* FIXME: Fill in the guts... */
351 /* Given a XML document and the root of a router branch do the setup */
352 static int xml_router(xmlDocPtr doc, xmlNodePtr root,
353 char *serv_id, char *serv_uuid) {
354 /* FIXME: Fill in the guts... */
358 /* Given a XML document and service id/uuid setup the service */
359 static int xml_service(xmlDocPtr doc, xmlNodePtr root,
360 int serv_num, char *serv_id, char *serv_uuid) {
361 xmlNodePtr cur = root;
364 while (cur != NULL) {
365 id = xmlGetProp(cur, "id");
366 uuid = xmlGetProp(cur, "uuid");
368 if (xmlStrcmp(id, serv_id) ||
369 xmlStrcmp(uuid, serv_uuid)) {
374 if (!xmlStrcmp(cur->name, "mds"))
375 rc = xml_mds(doc, cur, serv_id, serv_uuid);
376 else if (!xmlStrcmp(cur->name, "obd"))
377 rc = xml_obd(doc, cur, serv_id, serv_uuid);
378 else if (!xmlStrcmp(cur->name, "ost"))
379 rc = xml_ost(doc, cur, serv_id, serv_uuid);
380 else if (!xmlStrcmp(cur->name, "osc"))
381 rc = xml_osc(doc, cur, serv_id, serv_uuid);
382 else if (!xmlStrcmp(cur->name, "lov"))
383 rc = xml_lov(doc, cur, serv_id, serv_uuid);
384 else if (!xmlStrcmp(cur->name, "router"))
385 rc = xml_router(doc, cur, serv_id, serv_uuid);
395 /* Given a XML document and profile id/uuid setup the profile */
396 static int xml_profile(xmlDocPtr doc, xmlNodePtr root,
397 int prof_num, char *prof_id, char *prof_uuid) {
398 xmlNodePtr parent, cur = root;
402 while (cur != NULL) {
403 id = xmlGetProp(cur, "id");
404 uuid = xmlGetProp(cur, "uuid");
406 if (xmlStrcmp(cur->name, "profile") ||
407 xmlStrcmp(id, prof_id) ||
408 xmlStrcmp(uuid, prof_uuid)) {
413 /* FIXME: Doesn't understand mountpoints yet
414 * xml_mountpoint(doc, root, ...);
417 /* Setup each service in turn
418 * FIXME: Should be sorted by "num" attr, we shouldn't
419 * assume they're in order in the XML document.
422 cur = cur->xmlChildrenNode;
423 while (cur != NULL) {
424 if (!xmlStrcmp(cur->name, "service_id")) {
425 num = atoi(xmlGetProp(cur, "num"));
426 rc = xml_service(doc, root, num,
427 xmlGetProp(cur, "id"),
428 xmlGetProp(cur, "uuid"));
442 static int xml_node(xmlDocPtr doc, xmlNodePtr root) {
443 xmlNodePtr parent, cur = root;
447 /* Walk the node tags looking for ours */
448 while (cur != NULL) {
449 if (xmlStrcmp(cur->name, "node")) {
454 id = xmlGetProp(cur, "id");
458 uuid = xmlGetProp(cur, "uuid");
462 /* FIXME: Verify our ID and UUID against /etc/lustre/id
463 * so we're sure we are who we think we are.
466 /* Setup each profile in turn
467 * FIXME: Should be sorted by "num" attr, we shouldn't
468 * assume they're in order in the XML document.
471 cur = cur->xmlChildrenNode;
472 while (cur != NULL) {
473 if (!xmlStrcmp(cur->name, "profile_id")) {
474 num = atoi(xmlGetProp(cur, "num"));
475 rc = xml_profile(doc, root, num,
476 xmlGetProp(cur, "id"),
477 xmlGetProp(cur, "uuid"));
491 static int do_xml(char *func, char *file)
497 doc = xmlParseFile(file);
499 fprintf(stderr, "error: Unable to parse XML\n");
503 cur = xmlDocGetRootElement(doc);
505 fprintf(stderr, "error: Empty XML\n");
510 if (xmlStrcmp(cur->name, (const xmlChar *)"lustre")) {
511 fprintf(stderr, "error: Root node != <lustre>\n");
516 /* FIXME: Validate the XML against the DTD here */
518 /* FIXME: Merge all the text nodes under each branch and
519 * prune empty nodes. Just to make the parsing more
523 rc = xml_node(doc, cur->xmlChildrenNode);
529 static int do_device(char *func, int dev)
531 struct obd_ioctl_data data;
533 memset(&data, 0, sizeof(data));
540 if (obd_ioctl_pack(&data, &buf, max)) {
541 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
545 return ioctl(fd, OBD_IOC_DEVICE , buf);
548 static int jt_device(int argc, char **argv)
550 do_disconnect(argv[0], 1);
553 fprintf(stderr, "usage: %s devno\n", cmdname(argv[0]));
557 rc = do_device(argv[0], strtoul(argv[1], NULL, 0));
560 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
561 strerror(rc = errno));
566 static int jt_connect(int argc, char **argv)
568 struct obd_ioctl_data data;
572 do_disconnect(argv[0], 1);
575 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
579 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
581 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
582 OBD_IOC_CONNECT, strerror(rc = errno));
584 connid = data.ioc_conn1;
589 static int jt_disconnect(int argc, char **argv)
592 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
596 return do_disconnect(argv[0], 0);
599 static int jt__xml(int argc, char **argv)
602 fprintf(stderr, "usage: %s <xml file> <command [args ...]>\n",
607 return do_xml("xml", argv[1]);
610 static int jt__device(int argc, char **argv)
616 fprintf(stderr, "usage: %s devno <command [args ...]>\n",
621 rc = do_device("device", strtoul(argv[1], NULL, 0));
626 rc = jt_connect(1, arg2);
630 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
632 ret = do_disconnect(argv[0], 0);
639 static int jt__threads(int argc, char **argv)
641 int threads, next_thread;
647 "usage: %s numthreads verbose devno <cmd [args ...]>\n",
652 threads = strtoul(argv[1], NULL, 0);
654 verbose = get_verbose(argv[2]);
656 printf("%s: starting %d threads on device %s running %s\n",
657 argv[0], threads, argv[3], argv[4]);
659 for (i = 1, next_thread = verbose; i <= threads; i++) {
662 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
663 strerror(rc = errno));
665 } else if (rc == 0) {
667 argv[2] = "--device";
668 return jt__device(argc - 2, argv + 2);
669 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
670 printf("%s: thread #%d (PID %d) started\n",
675 if (!thread) { /* parent process */
677 printf("%s: started %d threads\n\n", argv[0], i - 1);
681 for (j = 1; j < i; j++) {
683 int ret = wait(&status);
686 fprintf(stderr, "error: %s: wait - %s\n",
687 argv[0], strerror(errno));
692 * This is a hack. We _should_ be able to use
693 * WIFEXITED(status) to see if there was an
694 * error, but it appears to be broken and it
695 * always returns 1 (OK). See wait(2).
697 int err = WEXITSTATUS(status);
700 "%s: PID %d had rc=%d\n",
711 static int jt_detach(int argc, char **argv)
713 struct obd_ioctl_data data;
718 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
722 if (obd_ioctl_pack(&data, &buf, max)) {
723 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
727 rc = ioctl(fd, OBD_IOC_DETACH , buf);
729 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
735 static int jt_cleanup(int argc, char **argv)
737 struct obd_ioctl_data data;
742 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
746 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
748 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
754 static int jt_newdev(int argc, char **argv)
756 struct obd_ioctl_data data;
764 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
768 rc = ioctl(fd, OBD_IOC_NEWDEV , &data);
770 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
773 printf("Current device set to %d\n", data.ioc_dev);
779 static int jt_attach(int argc, char **argv)
781 struct obd_ioctl_data data;
785 if (argc != 2 && argc != 3) {
786 fprintf(stderr, "usage: %s type [name [uuid]]\n",
791 data.ioc_inllen1 = strlen(argv[1]) + 1;
792 data.ioc_inlbuf1 = argv[1];
794 data.ioc_inllen2 = strlen(argv[2]) + 1;
795 data.ioc_inlbuf2 = argv[2];
798 if (obd_ioctl_pack(&data, &buf, max)) {
799 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
803 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
805 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
806 OBD_IOC_ATTACH, strerror(rc = errno));
807 else if (argc == 3) {
809 if (strlen(argv[2]) > 128) {
810 printf("Name too long to set environment\n");
813 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
814 rc = setenv(name, argv[1], 1);
816 printf("error setting env variable %s\n", name);
823 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
825 static int do_name2dev(char *func, char *name)
827 struct obd_ioctl_data data;
834 data.ioc_inllen1 = strlen(name) + 1;
835 data.ioc_inlbuf1 = name;
837 if (obd_ioctl_pack(&data, &buf, max)) {
838 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
841 rc = ioctl(fd, OBD_IOC_NAME2DEV , buf);
843 fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
844 name, strerror(rc = errno));
848 memcpy((char *)(&data), buf, sizeof(data));
850 return data.ioc_dev + N2D_OFF;
853 static int jt_name2dev(int argc, char **argv)
856 fprintf(stderr, "usage: %s name\n", cmdname(argv[0]));
860 rc = do_name2dev(argv[0], argv[1]);
862 int dev = rc - N2D_OFF;
863 rc = do_device(argv[0], dev);
870 static int jt_setup(int argc, char **argv)
872 struct obd_ioctl_data data;
877 fprintf(stderr, "usage: %s [device] [fstype]\n",
884 if (argv[1][0] == '$') {
885 rc = do_name2dev(argv[0], argv[1] + 1);
887 printf("%s is device %d\n", argv[1],
889 data.ioc_dev = rc - N2D_OFF;
892 data.ioc_dev = strtoul(argv[1], NULL, 0);
893 data.ioc_inllen1 = strlen(argv[1]) + 1;
894 data.ioc_inlbuf1 = argv[1];
897 data.ioc_inllen2 = strlen(argv[2]) + 1;
898 data.ioc_inlbuf2 = argv[2];
901 if (obd_ioctl_pack(&data, &buf, max)) {
902 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
905 rc = ioctl(fd, OBD_IOC_SETUP , buf);
907 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
908 strerror(rc = errno));
914 static int jt_create(int argc, char **argv)
916 struct obd_ioctl_data data;
917 struct timeval next_time;
918 int count = 1, next_count;
923 if (argc < 2 || argc > 4) {
924 fprintf(stderr, "usage: %s num [mode] [verbose]\n",
928 count = strtoul(argv[1], NULL, 0);
931 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
933 data.ioc_obdo1.o_mode = 0100644;
934 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
936 verbose = get_verbose(argv[3]);
938 printf("%s: %d obdos\n", cmdname(argv[0]), count);
939 gettimeofday(&next_time, NULL);
940 next_time.tv_sec -= verbose;
942 for (i = 1, next_count = verbose; i <= count ; i++) {
943 rc = ioctl(fd, OBD_IOC_CREATE , &data);
945 fprintf(stderr, "error: %s: #%d - %s\n",
946 cmdname(argv[0]), i, strerror(rc = errno));
949 if (be_verbose(verbose, &next_time, i, &next_count, count))
950 printf("%s: #%d is object id %Ld\n", cmdname(argv[0]),
951 i, data.ioc_obdo1.o_id);
956 static int jt_setattr(int argc, char **argv)
958 struct obd_ioctl_data data;
962 fprintf(stderr, "usage: %s id mode\n", cmdname(argv[0]));
966 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
967 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
968 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
970 rc = ioctl(fd, OBD_IOC_SETATTR , &data);
972 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
973 strerror(rc = errno));
978 static int jt_destroy(int argc, char **argv)
980 struct obd_ioctl_data data;
984 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
988 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
989 data.ioc_obdo1.o_mode = S_IFREG|0644;
991 rc = ioctl(fd, OBD_IOC_DESTROY , &data);
993 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
994 strerror(rc = errno));
999 static int jt_getattr(int argc, char **argv)
1001 struct obd_ioctl_data data;
1004 fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
1009 data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
1010 /* to help obd filter */
1011 data.ioc_obdo1.o_mode = 0100644;
1012 data.ioc_obdo1.o_valid = 0xffffffff;
1013 printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
1015 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1017 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1018 strerror(rc=errno));
1020 printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
1021 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
1026 static int jt_test_getattr(int argc, char **argv)
1028 struct obd_ioctl_data data;
1029 struct timeval start, next_time;
1030 int i, count, next_count;
1033 if (argc != 2 && argc != 3) {
1034 fprintf(stderr, "usage: %s count [verbose]\n",cmdname(argv[0]));
1039 count = strtoul(argv[1], NULL, 0);
1042 verbose = get_verbose(argv[2]);
1046 data.ioc_obdo1.o_valid = 0xffffffff;
1047 data.ioc_obdo1.o_id = 2;
1048 gettimeofday(&start, NULL);
1049 next_time.tv_sec = start.tv_sec - verbose;
1050 next_time.tv_usec = start.tv_usec;
1051 printf("%s: getting %d attrs (testing only): %s", cmdname(argv[0]),
1052 count, ctime(&start.tv_sec));
1054 for (i = 1, next_count = verbose; i <= count; i++) {
1055 rc = ioctl(fd, OBD_IOC_GETATTR , &data);
1057 fprintf(stderr, "error: %s: #%d - %s\n",
1058 cmdname(argv[0]), i, strerror(rc = errno));
1061 if (be_verbose(verbose, &next_time, i,&next_count,count))
1062 printf("%s: got attr #%d\n", cmdname(argv[0]), i);
1070 gettimeofday(&end, NULL);
1072 diff = difftime(&end, &start);
1075 printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
1076 cmdname(argv[0]), i, diff, (double)i / diff,
1077 ctime(&end.tv_sec));
1082 static int jt_test_brw(int argc, char **argv)
1084 struct obd_ioctl_data data;
1085 struct timeval start, next_time;
1087 int pages = 1, obdos = 1, count, next_count;
1088 int verbose = 1, write = 0, rw;
1092 if (argc < 2 || argc > 6) {
1094 "usage: %s count [write [verbose [pages [obdos]]]]\n",
1099 count = strtoul(argv[1], NULL, 0);
1102 if (argv[2][0] == 'w' || argv[2][0] == '1')
1104 else if (argv[2][0] == 'r' || argv[2][0] == '0')
1107 verbose = get_verbose(argv[3]);
1111 pages = strtoul(argv[4], NULL, 0);
1113 obdos = strtoul(argv[5], NULL, 0);
1115 if (obdos != 1 && obdos != 2) {
1116 fprintf(stderr, "error: %s: only 1 or 2 obdos supported\n",
1121 len = pages * PAGE_SIZE;
1123 bulk = calloc(obdos, len);
1125 fprintf(stderr, "error: %s: no memory allocating %dx%d pages\n",
1126 cmdname(argv[0]), obdos, pages);
1130 data.ioc_conn2 = connid;
1131 data.ioc_obdo1.o_id = 2;
1132 data.ioc_count = len;
1133 data.ioc_offset = 0;
1134 data.ioc_plen1 = len;
1135 data.ioc_pbuf1 = bulk;
1137 data.ioc_obdo2.o_id = 3;
1138 data.ioc_plen2 = len;
1139 data.ioc_pbuf2 = bulk + len;
1142 gettimeofday(&start, NULL);
1143 next_time.tv_sec = start.tv_sec - verbose;
1144 next_time.tv_usec = start.tv_usec;
1146 printf("%s: %s %d (%dx%d pages) (testing only): %s",
1147 cmdname(argv[0]), write ? "writing" : "reading",
1148 count, obdos, pages, ctime(&start.tv_sec));
1151 * We will put in the start time (and loop count inside the loop)
1152 * at the beginning of each page so that we will be able to validate
1153 * (at some later time) whether the data actually made it or not.
1155 * XXX we do not currently use any of this memory in OBD_IOC_BRW_*
1156 * just to avoid the overhead of the copy_{to,from}_user. It
1157 * can be fixed if we ever need to send real data around.
1159 for (o = 0, b = bulk; o < obdos; o++)
1160 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1161 memcpy(b, &start, sizeof(start));
1163 rw = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1164 for (i = 1, next_count = verbose; i <= count; i++) {
1166 b = bulk + sizeof(struct timeval);
1167 for (o = 0; o < obdos; o++)
1168 for (p = 0; p < pages; p++, b += PAGE_SIZE)
1169 memcpy(b, &count, sizeof(count));
1172 rc = ioctl(fd, rw, &data);
1174 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1175 cmdname(argv[0]), i, strerror(rc = errno),
1176 write ? "write" : "read");
1178 } else if (be_verbose(verbose, &next_time, i,&next_count,count))
1179 printf("%s: %s number %d\n", cmdname(argv[0]),
1180 write ? "write" : "read", i);
1189 gettimeofday(&end, NULL);
1191 diff = difftime(&end, &start);
1194 printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
1195 cmdname(argv[0]), write ? "wrote" : "read", obdos,
1196 pages, i, diff, (double)obdos * i * pages / diff,
1197 ctime(&end.tv_sec));
1202 static int jt_test_ldlm(int argc, char **argv)
1204 struct obd_ioctl_data data;
1208 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1212 rc = ioctl(fd, IOC_LDLM_TEST, &data);
1214 fprintf(stderr, "error: %s: test failed: %s\n",
1215 cmdname(argv[0]), strerror(rc = errno));
1219 static int jt_newconn(int argc, char **argv)
1221 struct obd_ioctl_data data;
1225 fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
1229 rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN , &data);
1231 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1232 strerror(rc = errno));
1237 static int jt_quit(int argc, char **argv)
1239 Parser_quit(argc, argv);
1244 command_t cmdlist[] = {
1246 {"--xml", jt__xml, 0, "--xml <xml file> <command [args ...]>"},
1247 {"--device", jt__device, 0, "--device <devno> <command [args ...]>"},
1248 {"--threads", jt__threads, 0,
1249 "--threads <threads> <devno> <command [args ...]>"},
1251 /* Device configuration commands */
1252 {"newdev", jt_newdev, 0, "set device to a new unused obd (no args)"},
1253 {"device", jt_device, 0, "set current device (args device_no name)"},
1254 {"name2dev", jt_name2dev, 0, "set device by name (args name)"},
1255 {"attach", jt_attach, 0, "name the type of device (args: type data"},
1256 {"setup", jt_setup, 0, "setup device (args: <blkdev> [data]"},
1257 {"detach", jt_detach, 0, "detach the current device (arg: )"},
1258 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
1260 /* Session commands */
1261 {"connect", jt_connect, 0, "connect - get a connection to device"},
1262 {"disconnect", jt_disconnect, 0,
1263 "disconnect - break connection to device"},
1265 /* Session operations */
1266 {"create", jt_create, 0, "create [count [mode [verbose]]]"},
1267 {"destroy", jt_destroy, 0, "destroy <id>"},
1268 {"getattr", jt_getattr, 0, "getattr <id>"},
1269 {"setattr", jt_setattr, 0, "setattr <id> <mode>"},
1270 {"newconn", jt_newconn, 0, "newconn [newuuid]"},
1271 {"test_getattr", jt_test_getattr, 0, "test_getattr <count> [verbose]"},
1272 {"test_brw", jt_test_brw, 0, "test_brw <count> [write [verbose]]"},
1273 {"test_ldlm", jt_test_ldlm, 0, "test lock manager (no args)"},
1275 /* User interface commands */
1276 {"help", Parser_help, 0, "help"},
1277 {"exit", jt_quit, 0, "quit"},
1278 {"quit", jt_quit, 0, "quit"},
1283 static void signal_server(int sig)
1285 if (sig == SIGINT) {
1286 do_disconnect("sigint", 1);
1289 fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
1293 int main(int argc, char **argv)
1295 struct sigaction sigact;
1297 sigact.sa_handler = signal_server;
1298 sigfillset(&sigact.sa_mask);
1299 sigact.sa_flags = SA_RESTART;
1300 sigaction(SIGINT, &sigact, NULL);
1304 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
1306 Parser_init("obdctl > ", cmdlist);
1307 rc = Parser_commands();
1310 do_disconnect(argv[0], 1);