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>
7 * Author: Andreas Dilger <adilger@clusterfs.com>
8 * Author: Robert Read <rread@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <sys/ioctl.h>
31 #include <sys/socket.h>
32 #include <sys/types.h>
40 #include <linux/lustre_lib.h>
41 #include <linux/lustre_idl.h>
42 #include <linux/lustre_dlm.h>
48 #include <netinet/in.h>
52 #include <asm/page.h> /* needed for PAGE_SIZE - rread */
55 #include <linux/list.h>
67 # define MAX_SHMEM_COUNT 1024
68 static long long *shared_counters;
69 static long long counter_snapshot[2][MAX_SHMEM_COUNT];
70 struct timeval prev_time;
74 uint64_t conn_addr = -1;
82 static int getfd(char *func);
83 static char *cmdname(char *func);
85 #define IOCINIT(data) \
87 memset(&data, 0, sizeof(data)); \
88 data.ioc_version = OBD_IOCTL_VERSION; \
89 data.ioc_addr = conn_addr; \
90 data.ioc_cookie = conn_cookie; \
91 data.ioc_len = sizeof(data); \
93 fprintf(stderr, "No device open, use device\n"); \
98 char *obdo_print(struct obdo *obd)
102 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
103 "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
104 "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
116 obd->o_flags, obd->o_obdflags, obd->o_nlink, obd->o_valid);
121 #define BAD_VERBOSE (-999999999)
123 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
125 static int do_name2dev(char *func, char *name)
127 struct obd_ioctl_data data;
135 data.ioc_inllen1 = strlen(name) + 1;
136 data.ioc_inlbuf1 = name;
138 if (obd_ioctl_pack(&data, &buf, max)) {
139 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
142 rc = ioctl(fd, OBD_IOC_NAME2DEV, buf);
144 fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
145 name, strerror(rc = errno));
149 memcpy((char *)(&data), buf, sizeof(data));
151 return data.ioc_dev + N2D_OFF;
155 * resolve a device name to a device number.
156 * supports a number or name.
157 * FIXME: support UUID
159 static int parse_devname(char *func, char *name)
166 if (name[0] == '$') {
167 rc = do_name2dev(func, name + 1);
170 printf("%s is device %d\n", name, ret);
172 fprintf(stderr, "error: %s: %s: %s\n", cmdname(func),
173 name, "device not found");
176 ret = strtoul(name, NULL, 0);
181 static char *cmdname(char *func)
183 static char buf[512];
186 sprintf(buf, "%s-%d", func, thread);
193 static int getfd(char *func)
196 fd = open("/dev/obd", O_RDWR);
198 fprintf(stderr, "error: %s: opening /dev/obd: %s\n"
199 "hint: lustre kernel modules may not be loaded.\n",
200 cmdname(func), strerror(errno));
206 #define difftime(a, b) \
207 ((double)(a)->tv_sec - (b)->tv_sec + \
208 ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
210 static int be_verbose(int verbose, struct timeval *next_time,
211 int num, int *next_num, int num_total)
218 if (next_time != NULL)
219 gettimeofday(&now, NULL);
221 /* A positive verbosity means to print every X iterations */
223 (next_num == NULL || num >= *next_num || num >= num_total)) {
224 *next_num += verbose;
226 next_time->tv_sec = now.tv_sec - verbose;
227 next_time->tv_usec = now.tv_usec;
232 /* A negative verbosity means to print at most each X seconds */
233 if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0){
234 next_time->tv_sec = now.tv_sec - verbose;
235 next_time->tv_usec = now.tv_usec;
244 static int get_verbose(char *func, const char *arg)
249 if (!arg || arg[0] == 'v')
251 else if (arg[0] == 's' || arg[0] == 'q')
254 verbose = (int)strtoul(arg, &end, 0);
256 fprintf(stderr, "error: %s: bad verbose option '%s'\n",
263 printf("Print status every %d seconds\n", -verbose);
264 else if (verbose == 1)
265 printf("Print status every operation\n");
266 else if (verbose > 1)
267 printf("Print status every %d operations\n", verbose);
272 int do_disconnect(char *func, int verbose)
275 struct obd_ioctl_data data;
282 rc = ioctl(fd, OBD_IOC_DISCONNECT, &data);
284 fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
285 OBD_IOC_DISCONNECT, strerror(errno));
288 printf("%s: disconnected conn %Lx\n", cmdname(func),
297 static void shmem_setup(void)
299 int shmid = shmget(IPC_PRIVATE, sizeof(counter_snapshot[0]), 0600);
302 fprintf(stderr, "Can't create shared memory counters: %s\n",
307 shared_counters = (long long *)shmat(shmid, NULL, 0);
309 if (shared_counters == (long long *)(-1)) {
310 fprintf(stderr, "Can't attach shared memory counters: %s\n",
312 shared_counters = NULL;
317 static inline void shmem_reset(void)
319 if (shared_counters == NULL)
322 memset(shared_counters, 0, sizeof(counter_snapshot[0]));
323 memset(counter_snapshot, 0, sizeof(counter_snapshot));
324 gettimeofday(&prev_time, NULL);
327 static inline void shmem_bump(void)
329 if (shared_counters == NULL || thread <= 0 || thread > MAX_SHMEM_COUNT)
332 shared_counters[thread - 1]++;
335 static void shmem_snap(int n)
337 struct timeval this_time;
343 if (shared_counters == NULL || n > MAX_SHMEM_COUNT)
346 memcpy(counter_snapshot[1], counter_snapshot[0],
347 n * sizeof(counter_snapshot[0][0]));
348 memcpy(counter_snapshot[0], shared_counters,
349 n * sizeof(counter_snapshot[0][0]));
350 gettimeofday(&this_time, NULL);
352 for (i = 0; i < n; i++) {
353 long long this_count =
354 counter_snapshot[0][i] - counter_snapshot[1][i];
356 if (this_count != 0) {
362 secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) -
363 (prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
365 printf("%d/%d Total: %f/second\n", non_zero, n, total / secs);
367 prev_time = this_time;
370 #define SHMEM_SETUP() shmem_setup()
371 #define SHMEM_RESET() shmem_reset()
372 #define SHMEM_BUMP() shmem_bump()
373 #define SHMEM_SNAP(n) shmem_snap(n)
375 #define SHMEM_SETUP()
376 #define SHMEM_RESET()
378 #define SHMEM_SNAP(n)
381 extern command_t cmdlist[];
383 static int do_device(char *func, int dev)
385 struct obd_ioctl_data data;
387 memset(&data, 0, sizeof(data));
394 if (obd_ioctl_pack(&data, &buf, max)) {
395 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
399 return ioctl(fd, OBD_IOC_DEVICE, buf);
402 int jt_obd_device(int argc, char **argv)
405 do_disconnect(argv[0], 1);
410 dev = parse_devname(argv[0], argv[1]);
414 rc = do_device(argv[0], dev);
416 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
417 strerror(rc = errno));
422 int jt_obd_connect(int argc, char **argv)
424 struct obd_ioctl_data data;
429 do_disconnect(argv[0], 1);
431 #warning TODO: implement timeout per lctl usage for probe
435 rc = ioctl(fd, OBD_IOC_CONNECT, &data);
437 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
438 OBD_IOC_CONNECT, strerror(rc = errno));
440 conn_addr = data.ioc_addr;
441 conn_cookie = data.ioc_cookie;
446 int jt_obd_disconnect(int argc, char **argv)
454 return do_disconnect(argv[0], 0);
457 int jt_opt_device(int argc, char **argv)
466 rc = do_device("device", parse_devname(argv[0], argv[1]));
471 rc = jt_obd_connect(1, arg2);
475 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
477 ret = do_disconnect(argv[0], 0);
484 int jt_opt_threads(int argc, char **argv)
486 int threads, next_thread;
495 threads = strtoul(argv[1], &end, 0);
497 fprintf(stderr, "error: %s: invalid page count '%s'\n",
498 cmdname(argv[0]), argv[1]);
502 verbose = get_verbose(argv[0], argv[2]);
503 if (verbose == BAD_VERBOSE)
507 printf("%s: starting %d threads on device %s running %s\n",
508 argv[0], threads, argv[3], argv[4]);
512 for (i = 1, next_thread = verbose; i <= threads; i++) {
515 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
516 strerror(rc = errno));
518 } else if (rc == 0) {
520 argv[2] = "--device";
521 return jt_opt_device(argc - 2, argv + 2);
522 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
523 printf("%s: thread #%d (PID %d) started\n",
528 if (!thread) { /* parent process */
529 int live_threads = threads;
531 while (live_threads > 0) {
535 ret = waitpid(0, &status, verbose < 0 ? WNOHANG : 0);
546 fprintf(stderr, "error: %s: wait - %s\n",
547 argv[0], strerror(errno));
552 * This is a hack. We _should_ be able to use
553 * WIFEXITED(status) to see if there was an
554 * error, but it appears to be broken and it
555 * always returns 1 (OK). See wait(2).
557 int err = WEXITSTATUS(status);
558 if (err || WIFSIGNALED(status))
560 "%s: PID %d had rc=%d\n",
573 int jt_obd_detach(int argc, char **argv)
575 struct obd_ioctl_data data;
583 if (obd_ioctl_pack(&data, &buf, max)) {
584 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
588 rc = ioctl(fd, OBD_IOC_DETACH, buf);
590 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
591 strerror(rc = errno));
596 int jt_obd_cleanup(int argc, char **argv)
598 struct obd_ioctl_data data;
606 rc = ioctl(fd, OBD_IOC_CLEANUP, &data);
608 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
609 strerror(rc = errno));
614 int jt_obd_newdev(int argc, char **argv)
617 struct obd_ioctl_data data;
627 rc = ioctl(fd, OBD_IOC_NEWDEV, &data);
629 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
630 strerror(rc = errno));
632 printf("Current device set to %d\n", data.ioc_dev);
638 int jt_obd_list(int argc, char **argv)
642 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
647 memset(buf, 0, sizeof(buf));
648 data->ioc_version = OBD_IOCTL_VERSION;
649 data->ioc_addr = conn_addr;
650 data->ioc_cookie = conn_addr;
651 data->ioc_len = sizeof(buf);
652 data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
657 rc = ioctl(fd, OBD_IOC_LIST, data);
659 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
660 strerror(rc = errno));
662 printf("%s", data->ioc_bulk);
668 int jt_obd_attach(int argc, char **argv)
670 struct obd_ioctl_data data;
675 if (argc != 2 && argc != 3 && argc != 4)
678 data.ioc_inllen1 = strlen(argv[1]) + 1;
679 data.ioc_inlbuf1 = argv[1];
681 data.ioc_inllen2 = strlen(argv[2]) + 1;
682 data.ioc_inlbuf2 = argv[2];
686 data.ioc_inllen3 = strlen(argv[3]) + 1;
687 data.ioc_inlbuf3 = argv[3];
690 if (obd_ioctl_pack(&data, &buf, max)) {
691 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
695 rc = ioctl(fd, OBD_IOC_ATTACH, buf);
697 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
698 OBD_IOC_ATTACH, strerror(rc = errno));
699 else if (argc == 3) {
701 if (strlen(argv[2]) > 128) {
702 printf("Name too long to set environment\n");
705 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
706 rc = setenv(name, argv[1], 1);
708 printf("error setting env variable %s\n", name);
715 int jt_obd_name2dev(int argc, char **argv)
722 rc = do_name2dev(argv[0], argv[1]);
724 int dev = rc - N2D_OFF;
725 rc = do_device(argv[0], dev);
732 int jt_obd_setup(int argc, char **argv)
734 struct obd_ioctl_data data;
744 data.ioc_dev = parse_devname(argv[0], argv[1]);
745 if (data.ioc_dev < 0)
747 data.ioc_inllen1 = strlen(argv[1]) + 1;
748 data.ioc_inlbuf1 = argv[1];
751 data.ioc_inllen2 = strlen(argv[2]) + 1;
752 data.ioc_inlbuf2 = argv[2];
755 if (obd_ioctl_pack(&data, &buf, max)) {
756 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
759 rc = ioctl(fd, OBD_IOC_SETUP, buf);
761 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
762 strerror(rc = errno));
768 int jt_obd_create(int argc, char **argv)
770 struct obd_ioctl_data data;
771 struct timeval next_time;
772 int count = 1, next_count;
778 if (argc < 2 || argc > 4)
781 count = strtoul(argv[1], &end, 0);
783 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
784 cmdname(argv[0]), argv[1]);
789 data.ioc_obdo1.o_mode = strtoul(argv[2], &end, 0);
791 fprintf(stderr, "error: %s: invalid mode '%s'\n",
792 cmdname(argv[0]), argv[2]);
796 data.ioc_obdo1.o_mode = 0100644;
797 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
800 verbose = get_verbose(argv[0], argv[3]);
801 if (verbose == BAD_VERBOSE)
805 printf("%s: %d objects\n", cmdname(argv[0]), count);
806 gettimeofday(&next_time, NULL);
807 next_time.tv_sec -= verbose;
809 for (i = 1, next_count = verbose; i <= count; i++) {
810 rc = ioctl(fd, OBD_IOC_CREATE, &data);
813 fprintf(stderr, "error: %s: #%d - %s\n",
814 cmdname(argv[0]), i, strerror(rc = errno));
817 if (be_verbose(verbose, &next_time, i, &next_count, count))
818 printf("%s: #%d is object id %Ld\n", cmdname(argv[0]),
819 i, data.ioc_obdo1.o_id);
824 int jt_obd_setattr(int argc, char **argv)
826 struct obd_ioctl_data data;
834 data.ioc_obdo1.o_id = strtoul(argv[1], &end, 0);
836 fprintf(stderr, "error: %s: invalid objid '%s'\n",
837 cmdname(argv[0]), argv[1]);
840 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], &end, 0);
842 fprintf(stderr, "error: %s: invalid mode '%s'\n",
843 cmdname(argv[0]), argv[2]);
846 data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
848 rc = ioctl(fd, OBD_IOC_SETATTR, &data);
850 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
851 strerror(rc = errno));
856 int jt_obd_destroy(int argc, char **argv)
858 struct obd_ioctl_data data;
866 data.ioc_obdo1.o_id = strtoul(argv[1], &end, 0);
868 fprintf(stderr, "error: %s: invalid objid '%s'\n",
869 cmdname(argv[0]), argv[1]);
872 data.ioc_obdo1.o_mode = S_IFREG | 0644;
874 rc = ioctl(fd, OBD_IOC_DESTROY, &data);
876 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
877 strerror(rc = errno));
882 int jt_obd_getattr(int argc, char **argv)
884 struct obd_ioctl_data data;
892 data.ioc_obdo1.o_id = strtoul(argv[1], &end, 0);
894 fprintf(stderr, "error: %s: invalid objid '%s'\n",
895 cmdname(argv[0]), argv[1]);
898 /* to help obd filter */
899 data.ioc_obdo1.o_mode = 0100644;
900 data.ioc_obdo1.o_valid = 0xffffffff;
901 printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
903 rc = ioctl(fd, OBD_IOC_GETATTR, &data);
905 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
906 strerror(rc = errno));
908 printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
909 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
914 int jt_obd_test_getattr(int argc, char **argv)
916 struct obd_ioctl_data data;
917 struct timeval start, next_time;
918 int i, count, next_count;
923 if (argc != 2 && argc != 3)
927 count = strtoul(argv[1], &end, 0);
929 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
930 cmdname(argv[0]), argv[1]);
935 verbose = get_verbose(argv[0], argv[2]);
936 if (verbose == BAD_VERBOSE)
941 data.ioc_obdo1.o_valid = 0xffffffff;
942 data.ioc_obdo1.o_id = 2;
943 gettimeofday(&start, NULL);
944 next_time.tv_sec = start.tv_sec - verbose;
945 next_time.tv_usec = start.tv_usec;
947 printf("%s: getting %d attrs (testing only): %s",
948 cmdname(argv[0]), count, ctime(&start.tv_sec));
950 for (i = 1, next_count = verbose; i <= count; i++) {
951 rc = ioctl(fd, OBD_IOC_GETATTR, &data);
954 fprintf(stderr, "error: %s: #%d - %s\n",
955 cmdname(argv[0]), i, strerror(rc = errno));
959 (verbose, &next_time, i, &next_count, count))
960 printf("%s: got attr #%d\n", cmdname(argv[0]),
969 gettimeofday(&end, NULL);
971 diff = difftime(&end, &start);
975 printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
976 cmdname(argv[0]), i, diff, (double)i / diff,
982 int jt_obd_test_brw(int argc, char **argv)
984 struct obd_ioctl_data data;
985 struct timeval start, next_time;
986 int pages = 1, objid = 3, count, next_count;
987 int verbose = 1, write = 0, rw;
994 if (argc < 2 || argc > 6) {
995 fprintf(stderr, "error: %s: bad number of arguments: %d\n",
996 cmdname(argv[0]), argc);
1000 count = strtoul(argv[1], &end, 0);
1002 fprintf(stderr, "error: %s: bad iteration count '%s'\n",
1003 cmdname(argv[0]), argv[1]);
1008 if (argv[2][0] == 'w' || argv[2][0] == '1')
1010 else if (argv[2][0] == 'r' || argv[2][0] == '0')
1013 verbose = get_verbose(argv[0], argv[3]);
1014 if (verbose == BAD_VERBOSE)
1019 pages = strtoul(argv[4], &end, 0);
1021 fprintf(stderr, "error: %s: bad page count '%s'\n",
1022 cmdname(argv[0]), argv[4]);
1027 objid = strtoul(argv[5], &end, 0);
1029 fprintf(stderr, "error: %s: bad objid '%s'\n",
1030 cmdname(argv[0]), argv[5]);
1035 len = pages * PAGE_SIZE;
1038 data.ioc_obdo1.o_id = objid;
1039 data.ioc_count = len;
1040 data.ioc_offset = 0;
1042 gettimeofday(&start, NULL);
1043 next_time.tv_sec = start.tv_sec - verbose;
1044 next_time.tv_usec = start.tv_usec;
1047 printf("%s: %s %dx%d pages (testing only): %s",
1048 cmdname(argv[0]), write ? "writing" : "reading",
1049 count, pages, ctime(&start.tv_sec));
1051 rw = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1052 for (i = 1, next_count = verbose, offset = 0; i <= count; i++) {
1053 rc = ioctl(fd, rw, &data);
1056 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1057 cmdname(argv[0]), i, strerror(rc = errno),
1058 write ? "write" : "read");
1060 } else if (be_verbose
1061 (verbose, &next_time, i, &next_count, count))
1062 printf("%s: %s number %d\n", cmdname(argv[0]),
1063 write ? "write" : "read", i);
1065 data.ioc_offset += len;
1072 gettimeofday(&end, NULL);
1074 diff = difftime(&end, &start);
1078 printf("%s: %s %dx%d pages in %.4gs (%.4g pg/s): %s",
1079 cmdname(argv[0]), write ? "wrote" : "read",
1080 i, pages, diff, (double)i * pages / diff,
1081 ctime(&end.tv_sec));
1086 int jt_obd_lov_config(int argc, char **argv)
1088 struct obd_ioctl_data data;
1089 struct lov_desc desc;
1099 if (strlen(argv[1]) > sizeof(*uuidarray) - 1) {
1100 fprintf(stderr, "error: %s: no %dB memory for uuid's\n",
1101 cmdname(argv[0]), strlen(argv[1]));
1105 memset(&desc, 0, sizeof(desc));
1106 strncpy(desc.ld_uuid, argv[1], sizeof(*uuidarray) - 1);
1107 desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
1109 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
1110 cmdname(argv[0]), argv[2]);
1113 desc.ld_default_stripe_size = strtoul(argv[3], &end, 0);
1115 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
1116 cmdname(argv[0]), argv[3]);
1119 if (desc.ld_default_stripe_size < 4096) {
1120 fprintf(stderr, "error: %s: stripe size %ld too small\n",
1121 cmdname(argv[0]), (long)desc.ld_default_stripe_size);
1124 desc.ld_default_stripe_offset = (__u64) strtoul(argv[4], &end, 0);
1126 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
1127 cmdname(argv[0]), argv[4]);
1130 desc.ld_pattern = strtoul(argv[5], &end, 0);
1132 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
1133 cmdname(argv[0]), argv[5]);
1136 desc.ld_tgt_count = argc - 6;
1138 size = desc.ld_tgt_count * sizeof(*uuidarray);
1139 uuidarray = malloc(size);
1141 fprintf(stderr, "error: %s: no %dB memory for uuid's\n",
1142 cmdname(argv[0]), size);
1145 memset(uuidarray, 0, size);
1146 for (i = 6; i < argc; i++) {
1147 char *buf = (char *)(uuidarray + i - 6);
1148 if (strlen(argv[i]) >= sizeof(*uuidarray)) {
1149 fprintf(stderr, "error: %s: arg %d (%s) too long\n",
1150 cmdname(argv[0]), i, argv[i]);
1154 strcpy(buf, argv[i]);
1157 data.ioc_inllen1 = sizeof(desc);
1158 data.ioc_inlbuf1 = (char *)&desc;
1159 data.ioc_inllen2 = size;
1160 data.ioc_inlbuf2 = (char *)uuidarray;
1162 if (obd_ioctl_pack(&data, &buf, max)) {
1163 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1167 rc = ioctl(fd, OBD_IOC_LOV_CONFIG, buf);
1169 fprintf(stderr, "lov_config: error: %s: %s\n",
1170 cmdname(argv[0]), strerror(rc = errno));
1175 int jt_obd_test_ldlm(int argc, char **argv)
1177 struct obd_ioctl_data data;
1184 rc = ioctl(fd, IOC_LDLM_TEST, &data);
1186 fprintf(stderr, "error: %s: test failed: %s\n",
1187 cmdname(argv[0]), strerror(rc = errno));
1191 int jt_obd_dump_ldlm(int argc, char **argv)
1193 struct obd_ioctl_data data;
1200 rc = ioctl(fd, IOC_LDLM_DUMP, &data);
1202 fprintf(stderr, "error: %s failed: %s\n",
1203 cmdname(argv[0]), strerror(rc = errno));
1207 int jt_obd_ldlm_regress_start(int argc, char **argv)
1210 struct obd_ioctl_data data;
1211 char argstring[200];
1212 int i, count = sizeof(argstring) - 1;
1218 argstring[0] = '\0';
1219 for (i = 1; i < argc; i++) {
1220 strncat(argstring, " ", count);
1222 strncat(argstring, argv[i], count);
1223 count -= strlen(argv[i]);
1226 if (strlen(argstring)) {
1227 data.ioc_inlbuf1 = argstring;
1228 data.ioc_inllen1 = strlen(argstring) + 1;
1231 if (obd_ioctl_pack(&data, &buf, max)) {
1232 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
1236 rc = ioctl(fd, IOC_LDLM_REGRESS_START, buf);
1239 fprintf(stderr, "error: %s: test failed: %s\n",
1240 cmdname(argv[0]), strerror(rc = errno));
1245 int jt_obd_ldlm_regress_stop(int argc, char **argv)
1248 struct obd_ioctl_data data;
1254 rc = ioctl(fd, IOC_LDLM_REGRESS_STOP, &data);
1257 fprintf(stderr, "error: %s: test failed: %s\n",
1258 cmdname(argv[0]), strerror(rc = errno));
1262 int jt_obd_newconn(int argc, char **argv)
1265 struct obd_ioctl_data data;
1271 rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN, &data);
1273 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
1274 strerror(rc = errno));
1279 static void signal_server(int sig)
1281 if (sig == SIGINT) {
1282 do_disconnect("sigint", 1);
1285 fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
1288 int obd_initialize(int argc, char **argv)
1295 void obd_cleanup(int argc, char **argv)
1297 struct sigaction sigact;
1299 sigact.sa_handler = signal_server;
1300 sigfillset(&sigact.sa_mask);
1301 sigact.sa_flags = SA_RESTART;
1302 sigaction(SIGINT, &sigact, NULL);
1304 do_disconnect(argv[0], 1);