1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 * Author: Andreas Dilger <adilger@clusterfs.com>
41 * Author: Robert Read <rread@clusterfs.com>
45 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #include <sys/types.h>
51 #include <sys/param.h>
59 #include <obd.h> /* for struct lov_stripe_md */
60 #include <lustre/lustre_build_version.h>
69 #include <lustre/liblustreapi.h>
71 #ifdef HAVE_ASM_PAGE_H
72 #include <asm/page.h> /* needed for PAGE_SIZE - rread */
75 #include <obd_class.h>
76 #include <lnet/lnetctl.h>
81 #define MAX_STRING_SIZE 128
82 #define DEVICES_LIST "/proc/fs/lustre/devices"
89 #define MAX_THREADS 1024
92 __u64 counters[MAX_THREADS];
93 __u64 offsets[MAX_THREADS];
101 static struct shared_data *shared_data;
102 static __u64 counter_snapshot[2][MAX_THREADS];
103 static int prev_valid;
104 static struct timeval prev_time;
108 const int thread = 0;
109 const int nthreads = 1;
112 #define MAX_IOC_BUFLEN 8192
114 static int cur_device = -1;
117 #define MAX_STRIPES 170
118 struct lov_oinfo lov_oinfos[MAX_STRIPES];
121 struct lov_stripe_md lsm;
122 struct lov_oinfo *ptrs[MAX_STRIPES];
125 static int l2_ioctl(int dev_id, unsigned int opc, void *buf)
127 return l_ioctl(dev_id, opc, buf);
130 int lcfg_ioctl(char * func, int dev_id, struct lustre_cfg *lcfg)
132 struct obd_ioctl_data data;
133 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
136 memset(&data, 0x00, sizeof(data));
137 data.ioc_dev = cur_device;
138 data.ioc_type = LUSTRE_CFG_TYPE;
139 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
141 data.ioc_pbuf1 = (void *)lcfg;
142 memset(buf, 0, sizeof(rawbuf));
143 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
145 fprintf(stderr, "error: %s: invalid ioctl\n",
150 rc = l_ioctl(dev_id, OBD_IOC_PROCESS_CFG, buf);
155 static int do_device(char *func, char *devname);
157 static int get_mgs_device()
160 static int mgs_device = -1;
162 if (mgs_device == -1) {
164 do_disconnect(NULL, 1);
165 rc = do_device("mgsioc", mgs);
168 "This command must be run on the MGS.\n");
172 mgs_device = cur_device;
177 /* Returns -1 on error with errno set */
178 int lcfg_mgs_ioctl(char *func, int dev_id, struct lustre_cfg *lcfg)
180 struct obd_ioctl_data data;
181 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
184 memset(&data, 0x00, sizeof(data));
185 rc = data.ioc_dev = get_mgs_device();
188 data.ioc_type = LUSTRE_CFG_TYPE;
189 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
191 data.ioc_pbuf1 = (void *)lcfg;
192 memset(buf, 0, sizeof(rawbuf));
193 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
195 fprintf(stderr, "error: %s: invalid ioctl\n",
200 rc = l_ioctl(dev_id, OBD_IOC_PARAM, buf);
204 fprintf(stderr, "Make sure cfg_device is set first.\n");
206 fprintf(stderr, "cfg_device should be of the form "
207 "'lustre-MDT0000'\n");
212 char *obdo_print(struct obdo *obd)
216 sprintf(buf, "id: "LPX64"\ngrp: "LPX64"\natime: "LPU64"\nmtime: "LPU64
217 "\nctime: "LPU64"\nsize: "LPU64"\nblocks: "LPU64
218 "\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n"
219 "misc: %x\nnlink: %d,\nvalid "LPX64"\n",
220 obd->o_id, obd->o_gr, obd->o_atime, obd->o_mtime, obd->o_ctime,
221 obd->o_size, obd->o_blocks, obd->o_blksize, obd->o_mode,
222 obd->o_uid, obd->o_gid, obd->o_flags, obd->o_misc,
223 obd->o_nlink, obd->o_valid);
228 #define BAD_VERBOSE (-999999999)
230 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
232 static int do_name2dev(char *func, char *name)
234 struct obd_ioctl_data data;
235 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
238 memset(&data, 0x00, sizeof(data));
239 data.ioc_dev = cur_device;
240 data.ioc_inllen1 = strlen(name) + 1;
241 data.ioc_inlbuf1 = name;
243 memset(buf, 0, sizeof(rawbuf));
244 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
246 fprintf(stderr, "error: %s: invalid ioctl\n",
250 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NAME2DEV, buf);
253 rc = obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
255 fprintf(stderr, "error: %s: invalid reply\n",
260 return data.ioc_dev + N2D_OFF;
264 * resolve a device name to a device number.
265 * supports a number, $name or %uuid.
267 int parse_devname(char *func, char *name)
274 if (isdigit(name[0])) {
275 ret = strtoul(name, NULL, 0);
277 if (name[0] == '$' || name[0] == '%')
279 rc = do_name2dev(func, name);
282 // printf("Name %s is device %d\n", name, ret);
284 fprintf(stderr, "No device found for name %s: %s\n",
292 reset_lsmb (struct lsm_buffer *lsmb)
294 memset (&lsmb->lsm, 0, sizeof (lsmb->lsm));
295 memset(lov_oinfos, 0, sizeof(lov_oinfos));
296 lsmb->lsm.lsm_magic = LOV_MAGIC;
300 parse_lsm (struct lsm_buffer *lsmb, char *string)
302 struct lov_stripe_md *lsm = &lsmb->lsm;
307 * object_id[=size#count[@offset:id]*]
312 lsm->lsm_object_id = strtoull (string, &end, 0);
324 lsm->lsm_stripe_size = strtoul (string, &end, 0);
333 lsm->lsm_stripe_count = strtoul (string, &end, 0);
338 if (*string == 0) /* don't have to specify obj ids */
341 for (i = 0; i < lsm->lsm_stripe_count; i++) {
345 lsm->lsm_oinfo[i]->loi_ost_idx = strtoul(string, &end, 0);
349 lsm->lsm_oinfo[i]->loi_id = strtoull(string, &end, 0);
359 char *jt_cmdname(char *func)
361 static char buf[512];
364 sprintf(buf, "%s-%d", func, thread);
371 #define difftime(a, b) \
372 ((a)->tv_sec - (b)->tv_sec + \
373 ((a)->tv_usec - (b)->tv_usec) / 1000000.0)
375 static int be_verbose(int verbose, struct timeval *next_time,
376 __u64 num, __u64 *next_num, int num_total)
383 if (next_time != NULL)
384 gettimeofday(&now, NULL);
386 /* A positive verbosity means to print every X iterations */
387 if (verbose > 0 && (num >= *next_num || num >= num_total)) {
388 *next_num += verbose;
390 next_time->tv_sec = now.tv_sec - verbose;
391 next_time->tv_usec = now.tv_usec;
396 /* A negative verbosity means to print at most each X seconds */
397 if (verbose < 0 && next_time != NULL &&
398 difftime(&now, next_time) >= 0.0){
399 next_time->tv_sec = now.tv_sec - verbose;
400 next_time->tv_usec = now.tv_usec;
408 static int get_verbose(char *func, const char *arg)
413 if (!arg || arg[0] == 'v')
415 else if (arg[0] == 's' || arg[0] == 'q')
418 verbose = (int)strtoul(arg, &end, 0);
420 fprintf(stderr, "error: %s: bad verbose option '%s'\n",
421 jt_cmdname(func), arg);
427 printf("Print status every %d seconds\n", -verbose);
428 else if (verbose == 1)
429 printf("Print status every operation\n");
430 else if (verbose > 1)
431 printf("Print status every %d operations\n", verbose);
436 int do_disconnect(char *func, int verbose)
438 lcfg_set_devname(NULL);
444 static void shmem_setup(void)
446 /* Create new segment */
447 int shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600);
450 fprintf(stderr, "Can't create shared data: %s\n",
455 /* Attatch to new segment */
456 shared_data = (struct shared_data *)shmat(shmid, NULL, 0);
458 if (shared_data == (struct shared_data *)(-1)) {
459 fprintf(stderr, "Can't attach shared data: %s\n",
465 /* Mark segment as destroyed, so it will disappear when we exit.
466 * Forks will inherit attached segments, so we should be OK.
468 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
469 fprintf(stderr, "Can't destroy shared data: %s\n",
474 static inline void shmem_lock(void)
476 l_mutex_lock(&shared_data->mutex);
479 static inline void shmem_unlock(void)
481 l_mutex_unlock(&shared_data->mutex);
484 static inline void shmem_reset(int total_threads)
486 if (shared_data == NULL)
489 memset(shared_data, 0, sizeof(*shared_data));
490 l_mutex_init(&shared_data->mutex);
491 l_cond_init(&shared_data->cond);
492 memset(counter_snapshot, 0, sizeof(counter_snapshot));
494 shared_data->barrier = total_threads;
497 static inline void shmem_bump(void)
499 static int bumped_running;
501 if (shared_data == NULL || thread <= 0 || thread > MAX_THREADS)
505 shared_data->counters[thread - 1]++;
507 shared_data->running++;
512 static void shmem_snap(int total_threads, int live_threads)
514 struct timeval this_time;
521 if (shared_data == NULL || total_threads > MAX_THREADS)
525 memcpy(counter_snapshot[0], shared_data->counters,
526 total_threads * sizeof(counter_snapshot[0][0]));
527 running = shared_data->running;
530 gettimeofday(&this_time, NULL);
532 for (i = 0; i < total_threads; i++) {
533 long long this_count =
534 counter_snapshot[0][i] - counter_snapshot[1][i];
536 if (this_count != 0) {
542 secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) -
543 (prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
546 secs > 1.0) /* someone screwed with the time? */
547 printf("%d/%d Total: %f/second\n", non_zero, total_threads, total / secs);
549 memcpy(counter_snapshot[1], counter_snapshot[0],
550 total_threads * sizeof(counter_snapshot[0][0]));
551 prev_time = this_time;
553 running == total_threads)
557 static void shmem_stop(void)
559 if (shared_data == NULL)
562 shared_data->stop = 1;
565 static int shmem_running(void)
567 return (shared_data == NULL ||
571 static void shmem_setup(void)
575 static inline void shmem_reset(int total_threads)
579 static inline void shmem_bump(void)
583 static void shmem_lock()
587 static void shmem_unlock()
591 static void shmem_stop(void)
595 static int shmem_running(void)
601 extern command_t cmdlist[];
603 static int do_device(char *func, char *devname)
607 dev = parse_devname(func, devname);
611 lcfg_set_devname(devname);
616 int jt_obd_get_device()
621 int jt_obd_device(int argc, char **argv)
629 printf("current device is %d - %s\n",
630 cur_device, lcfg_get_devname() ? : "not set");
633 rc = do_device("device", argv[1]);
637 int jt_opt_device(int argc, char **argv)
645 rc = do_device("device", argv[1]);
648 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
650 ret = do_disconnect(argv[0], 0);
658 static void parent_sighandler (int sig)
663 int jt_opt_threads(int argc, char **argv)
665 static char cmdstr[128];
668 struct sigaction sigact;
669 struct sigaction saveact1;
670 struct sigaction saveact2;
671 unsigned long threads;
675 int report_count = -1;
682 threads = strtoul(argv[1], &end, 0);
685 report_count = strtoul(end + 1, &end, 0);
687 if (*end || threads > MAX_THREADS) {
688 fprintf(stderr, "error: %s: invalid thread count '%s'\n",
689 jt_cmdname(argv[0]), argv[1]);
693 verbose = get_verbose(argv[0], argv[2]);
694 if (verbose == BAD_VERBOSE)
698 snprintf(cmdstr, sizeof(cmdstr), "%s", argv[4]);
699 for (i = 5; i < argc; i++)
700 snprintf(cmdstr + strlen(cmdstr), sizeof(cmdstr),
703 printf("%s: starting %ld threads on device %s running %s\n",
704 argv[0], threads, argv[3], cmdstr);
707 shmem_reset(threads);
709 sigemptyset(&sigset);
710 sigaddset(&sigset, SIGALRM);
711 sigaddset(&sigset, SIGCHLD);
712 sigprocmask(SIG_BLOCK, &sigset, &saveset);
716 for (i = 1, next_thread = verbose; i <= threads; i++) {
719 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
720 strerror(rc = errno));
722 } else if (rc == 0) {
723 sigprocmask(SIG_SETMASK, &saveset, NULL);
726 argv[2] = "--device";
727 exit(jt_opt_device(argc - 2, argv + 2));
728 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
729 printf("%s: thread #%d (PID %d) started\n",
734 if (!thread) { /* parent process */
735 int live_threads = threads;
737 sigemptyset(&sigset);
738 sigemptyset(&sigact.sa_mask);
739 sigact.sa_handler = parent_sighandler;
742 sigaction(SIGALRM, &sigact, &saveact1);
743 sigaction(SIGCHLD, &sigact, &saveact2);
745 while (live_threads > 0) {
749 if (verbose < 0) /* periodic stats */
755 while (live_threads > 0) {
756 ret = waitpid(0, &status, WNOHANG);
761 fprintf(stderr, "error: %s: wait - %s\n",
762 argv[0], strerror(errno));
768 * This is a hack. We _should_ be able
769 * to use WIFEXITED(status) to see if
770 * there was an error, but it appears
771 * to be broken and it always returns 1
774 int err = WEXITSTATUS(status);
775 if (err || WIFSIGNALED(status))
777 "%s: PID %d had rc=%d\n",
786 /* Show stats while all threads running */
788 shmem_snap(threads, live_threads);
789 if (report_count > 0 && --report_count == 0)
793 sigaction(SIGCHLD, &saveact2, NULL);
794 sigaction(SIGALRM, &saveact1, NULL);
797 sigprocmask(SIG_SETMASK, &saveset, NULL);
802 int jt_opt_threads(int argc, char **argv)
804 fprintf(stderr, "%s not-supported in a single-threaded runtime\n",
805 jt_cmdname(argv[0]));
810 int jt_opt_net(int argc, char **argv)
821 rc = jt_ptl_network (2, arg2);
824 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
829 int jt_obd_no_transno(int argc, char **argv)
831 struct obd_ioctl_data data;
832 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
835 memset(&data, 0x00, sizeof(data));
836 data.ioc_dev = cur_device;
841 memset(buf, 0, sizeof(rawbuf));
842 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
844 fprintf(stderr, "error: %s: invalid ioctl\n",
845 jt_cmdname(argv[0]));
848 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NO_TRANSNO, buf);
850 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
851 strerror(rc = errno));
856 int jt_obd_set_readonly(int argc, char **argv)
858 struct obd_ioctl_data data;
859 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
862 memset(&data, 0x00, sizeof(data));
863 data.ioc_dev = cur_device;
868 memset(buf, 0, sizeof(rawbuf));
869 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
871 fprintf(stderr, "error: %s: invalid ioctl\n",
872 jt_cmdname(argv[0]));
875 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SET_READONLY, buf);
877 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
878 strerror(rc = errno));
883 int jt_obd_abort_recovery(int argc, char **argv)
885 struct obd_ioctl_data data;
886 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
889 memset(&data, 0x00, sizeof(data));
890 data.ioc_dev = cur_device;
895 memset(buf, 0, sizeof(rawbuf));
896 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
898 fprintf(stderr, "error: %s: invalid ioctl\n",
899 jt_cmdname(argv[0]));
902 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_ABORT_RECOVERY, buf);
904 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
905 strerror(rc = errno));
910 int jt_get_version(int argc, char **argv)
913 char rawbuf[MAX_IOC_BUFLEN];
919 rc = llapi_get_version(rawbuf, MAX_IOC_BUFLEN, &version);
921 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
924 printf("Lustre version: %s\n", version);
927 printf("lctl version: %s\n", BUILD_VERSION);
932 * Print an obd device line with the ost_conn_uuid inserted, if the obd
935 static void print_obd_line(char *s)
937 char buf[MAX_STRING_SIZE];
938 char obd_name[MAX_OBD_NAME];
942 if (sscanf(s, " %*d %*s osc %s %*s %*d ", obd_name) == 0)
944 snprintf(buf, sizeof(buf),
945 "/proc/fs/lustre/osc/%s/ost_conn_uuid", obd_name);
946 if ((fp = fopen(buf, "r")) == NULL)
951 if (sscanf(s, " %*d %*s mdc %s %*s %*d ", obd_name) == 0)
953 snprintf(buf, sizeof(buf),
954 "/proc/fs/lustre/mdc/%s/mds_conn_uuid", obd_name);
955 if ((fp = fopen(buf, "r")) == NULL)
959 /* should not ignore fgets(3)'s return value */
960 if (!fgets(buf, sizeof(buf), fp)) {
961 fprintf(stderr, "reading from %s: %s", buf, strerror(errno));
967 /* trim trailing newlines */
968 ptr = strrchr(buf, '\n');
969 if (ptr) *ptr = '\0';
970 ptr = strrchr(s, '\n');
971 if (ptr) *ptr = '\0';
973 printf("%s %s\n", s, buf);
981 /* get device list by ioctl */
982 int jt_obd_list_ioctl(int argc, char **argv)
985 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
986 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
990 /* Just ignore a -t option. Only supported with /proc. */
991 else if (argc == 2 && strcmp(argv[1], "-t") != 0)
994 for (index = 0;; index++) {
995 memset(buf, 0, sizeof(rawbuf));
996 data->ioc_version = OBD_IOCTL_VERSION;
997 data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data));
998 data->ioc_inlbuf1 = buf + size_round(sizeof(*data));
999 data->ioc_len = obd_ioctl_packlen(data);
1000 data->ioc_count = index;
1002 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETDEVICE, buf);
1005 printf("%s\n", (char *)data->ioc_bulk);
1008 if (errno == ENOENT)
1009 /* no device or the last device */
1012 fprintf(stderr, "Error getting device list: %s: "
1013 "check dmesg.\n", strerror(errno));
1018 int jt_obd_list(int argc, char **argv)
1021 char buf[MAX_STRING_SIZE];
1027 else if (argc == 2) {
1028 if (strcmp(argv[1], "-t") == 0)
1034 fp = fopen(DEVICES_LIST, "r");
1036 fprintf(stderr, "error: %s: %s opening "DEVICES_LIST"\n",
1037 jt_cmdname(argv[0]), strerror(rc = errno));
1038 return jt_obd_list_ioctl(argc, argv);
1041 while (fgets(buf, sizeof(buf), fp) != NULL)
1043 print_obd_line(buf);
1051 /* Create one or more objects, arg[4] may describe stripe meta-data. If
1052 * not, defaults assumed. This echo-client instance stashes the stripe
1053 * object ids. Use get_stripe on this node to print full lsm and
1054 * set_stripe on another node to cut/paste between nodes.
1056 /* create <count> [<file_create_mode>] [q|v|# verbosity] [striping] */
1057 int jt_obd_create(int argc, char **argv)
1059 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1060 struct obd_ioctl_data data;
1061 struct timeval next_time;
1062 __u64 count = 1, next_count, base_id = 0;
1063 int verbose = 1, mode = 0100644, rc = 0, i, valid_lsm = 0;
1066 memset(&data, 0x00, sizeof(data));
1067 data.ioc_dev = cur_device;
1068 if (argc < 2 || argc > 5)
1071 count = strtoull(argv[1], &end, 0);
1073 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1074 jt_cmdname(argv[0]), argv[1]);
1079 mode = strtoul(argv[2], &end, 0);
1081 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1082 jt_cmdname(argv[0]), argv[2]);
1085 if (!(mode & S_IFMT))
1090 verbose = get_verbose(argv[0], argv[3]);
1091 if (verbose == BAD_VERBOSE)
1096 reset_lsmb (&lsm_buffer); /* will set default */
1098 rc = parse_lsm (&lsm_buffer, argv[4]);
1100 fprintf(stderr, "error: %s: invalid lsm '%s'\n",
1101 jt_cmdname(argv[0]), argv[4]);
1104 base_id = lsm_buffer.lsm.lsm_object_id;
1108 printf("%s: "LPD64" objects\n", jt_cmdname(argv[0]), count);
1109 gettimeofday(&next_time, NULL);
1110 next_time.tv_sec -= verbose;
1112 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1113 data.ioc_obdo1.o_mode = mode;
1114 data.ioc_obdo1.o_id = base_id;
1115 data.ioc_obdo1.o_uid = 0;
1116 data.ioc_obdo1.o_gid = 0;
1117 data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE |
1118 OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID;
1121 data.ioc_plen1 = sizeof lsm_buffer;
1122 data.ioc_pbuf1 = (char *)&lsm_buffer;
1125 memset(buf, 0, sizeof(rawbuf));
1126 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1128 fprintf(stderr, "error: %s: invalid ioctl\n",
1129 jt_cmdname(argv[0]));
1132 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CREATE, buf);
1133 obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
1136 fprintf(stderr, "error: %s: #%d - %s\n",
1137 jt_cmdname(argv[0]), i, strerror(rc = errno));
1140 if (!(data.ioc_obdo1.o_valid & OBD_MD_FLID)) {
1141 fprintf(stderr,"error: %s: oid not valid #%d:"LPX64"\n",
1142 jt_cmdname(argv[0]), i, data.ioc_obdo1.o_valid);
1147 if (be_verbose(verbose, &next_time, i, &next_count, count))
1148 printf("%s: #%d is object id "LPX64"\n",
1149 jt_cmdname(argv[0]), i, data.ioc_obdo1.o_id);
1154 int jt_obd_setattr(int argc, char **argv)
1156 struct obd_ioctl_data data;
1157 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1161 memset(&data, 0x00, sizeof(data));
1162 data.ioc_dev = cur_device;
1166 data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0);
1168 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1169 jt_cmdname(argv[0]), argv[1]);
1172 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], &end, 0);
1174 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1175 jt_cmdname(argv[0]), argv[2]);
1178 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
1180 memset(buf, 0, sizeof(rawbuf));
1181 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1183 fprintf(stderr, "error: %s: invalid ioctl\n",
1184 jt_cmdname(argv[0]));
1187 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, buf);
1189 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1190 strerror(rc = errno));
1195 int jt_obd_test_setattr(int argc, char **argv)
1197 struct obd_ioctl_data data;
1198 struct timeval start, next_time;
1199 __u64 i, count, next_count;
1200 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1206 if (argc < 2 || argc > 4)
1209 memset(&data, 0x00, sizeof(data));
1210 data.ioc_dev = cur_device;
1211 count = strtoull(argv[1], &end, 0);
1213 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1214 jt_cmdname(argv[0]), argv[1]);
1219 verbose = get_verbose(argv[0], argv[2]);
1220 if (verbose == BAD_VERBOSE)
1225 if (argv[3][0] == 't') {
1226 objid = strtoull(argv[3] + 1, &end, 0);
1228 objid += thread - 1;
1230 objid = strtoull(argv[3], &end, 0);
1232 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1233 jt_cmdname(argv[0]), argv[3]);
1238 gettimeofday(&start, NULL);
1239 next_time.tv_sec = start.tv_sec - verbose;
1240 next_time.tv_usec = start.tv_usec;
1242 printf("%s: setting "LPD64" attrs (objid "LPX64"): %s",
1243 jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec));
1245 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1246 data.ioc_obdo1.o_id = objid;
1247 data.ioc_obdo1.o_mode = S_IFREG;
1248 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
1249 memset(buf, 0x00, sizeof(rawbuf));
1250 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1252 fprintf(stderr, "error: %s: invalid ioctl\n",
1253 jt_cmdname(argv[0]));
1256 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, &data);
1259 fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n",
1260 jt_cmdname(argv[0]), i, errno, strerror(rc = errno));
1264 (verbose, &next_time, i, &next_count, count))
1265 printf("%s: set attr #"LPD64"\n",
1266 jt_cmdname(argv[0]), i);
1274 gettimeofday(&end, NULL);
1276 diff = difftime(&end, &start);
1280 printf("%s: "LPD64" attrs in %.3fs (%.3f attr/s): %s",
1281 jt_cmdname(argv[0]), i, diff, i / diff,
1282 ctime(&end.tv_sec));
1287 int jt_obd_destroy(int argc, char **argv)
1289 struct obd_ioctl_data data;
1290 struct timeval next_time;
1291 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1292 __u64 count = 1, next_count;
1298 memset(&data, 0x00, sizeof(data));
1299 data.ioc_dev = cur_device;
1300 if (argc < 2 || argc > 4)
1303 id = strtoull(argv[1], &end, 0);
1304 if (*end || id == 0 || errno != 0) {
1305 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1306 jt_cmdname(argv[0]), argv[1]);
1310 count = strtoull(argv[2], &end, 0);
1313 "error: %s: invalid iteration count '%s'\n",
1314 jt_cmdname(argv[0]), argv[2]);
1320 verbose = get_verbose(argv[0], argv[3]);
1321 if (verbose == BAD_VERBOSE)
1325 printf("%s: "LPD64" objects\n", jt_cmdname(argv[0]), count);
1326 gettimeofday(&next_time, NULL);
1327 next_time.tv_sec -= verbose;
1329 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++, id++) {
1330 data.ioc_obdo1.o_id = id;
1331 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1332 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1334 memset(buf, 0, sizeof(rawbuf));
1335 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1337 fprintf(stderr, "error: %s: invalid ioctl\n",
1338 jt_cmdname(argv[0]));
1341 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_DESTROY, buf);
1342 obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
1345 fprintf(stderr, "error: %s: objid "LPX64": %s\n",
1346 jt_cmdname(argv[0]), id, strerror(rc = errno));
1350 if (be_verbose(verbose, &next_time, i, &next_count, count))
1351 printf("%s: #%d is object id "LPX64"\n",
1352 jt_cmdname(argv[0]), i, id);
1358 int jt_obd_getattr(int argc, char **argv)
1360 struct obd_ioctl_data data;
1361 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1368 memset(&data, 0x00, sizeof(data));
1369 data.ioc_dev = cur_device;
1370 data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0);
1372 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1373 jt_cmdname(argv[0]), argv[1]);
1376 /* to help obd filter */
1377 data.ioc_obdo1.o_mode = 0100644;
1378 data.ioc_obdo1.o_valid = 0xffffffff;
1379 printf("%s: object id "LPX64"\n", jt_cmdname(argv[0]),data.ioc_obdo1.o_id);
1381 memset(buf, 0, sizeof(rawbuf));
1382 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1384 fprintf(stderr, "error: %s: invalid ioctl\n",
1385 jt_cmdname(argv[0]));
1388 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, buf);
1389 obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
1391 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1392 strerror(rc = errno));
1394 printf("%s: object id "LPX64", mode %o\n", jt_cmdname(argv[0]),
1395 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
1400 int jt_obd_test_getattr(int argc, char **argv)
1402 struct obd_ioctl_data data;
1403 struct timeval start, next_time;
1404 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1405 __u64 i, count, next_count;
1411 if (argc < 2 || argc > 4)
1414 memset(&data, 0x00, sizeof(data));
1415 data.ioc_dev = cur_device;
1416 count = strtoull(argv[1], &end, 0);
1418 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1419 jt_cmdname(argv[0]), argv[1]);
1424 verbose = get_verbose(argv[0], argv[2]);
1425 if (verbose == BAD_VERBOSE)
1430 if (argv[3][0] == 't') {
1431 objid = strtoull(argv[3] + 1, &end, 0);
1433 objid += thread - 1;
1435 objid = strtoull(argv[3], &end, 0);
1437 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1438 jt_cmdname(argv[0]), argv[3]);
1443 gettimeofday(&start, NULL);
1444 next_time.tv_sec = start.tv_sec - verbose;
1445 next_time.tv_usec = start.tv_usec;
1447 printf("%s: getting "LPD64" attrs (objid "LPX64"): %s",
1448 jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec));
1450 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1451 data.ioc_obdo1.o_id = objid;
1452 data.ioc_obdo1.o_mode = S_IFREG;
1453 data.ioc_obdo1.o_valid = 0xffffffff;
1454 memset(buf, 0x00, sizeof(rawbuf));
1455 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1457 fprintf(stderr, "error: %s: invalid ioctl\n",
1458 jt_cmdname(argv[0]));
1461 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data);
1464 fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n",
1465 jt_cmdname(argv[0]), i, errno, strerror(rc = errno));
1469 (verbose, &next_time, i, &next_count, count))
1470 printf("%s: got attr #"LPD64"\n",
1471 jt_cmdname(argv[0]), i);
1479 gettimeofday(&end, NULL);
1481 diff = difftime(&end, &start);
1485 printf("%s: "LPD64" attrs in %.3fs (%.3f attr/s): %s",
1486 jt_cmdname(argv[0]), i, diff, i / diff,
1487 ctime(&end.tv_sec));
1492 /* test_brw <cnt> count
1493 <r|w[r(repeat)x(noverify)]> mode
1494 <q|v|#(print interval)> verbosity
1495 <npages[+offset]> blocksize
1496 <[[<interleave_threads>]t(inc obj by thread#)]obj> object
1497 [p|g<args>] batch */
1498 int jt_obd_test_brw(int argc, char **argv)
1500 struct obd_ioctl_data data;
1501 struct timeval start, next_time;
1502 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1503 __u64 count, next_count, len, stride, thr_offset = 0, objid = 3;
1504 int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1;
1505 int offset_pages = 0;
1507 int repeat_offset = 0;
1508 unsigned long long ull;
1509 int nthr_per_obj = 0;
1514 if (argc < 2 || argc > 7) {
1515 fprintf(stderr, "error: %s: bad number of arguments: %d\n",
1516 jt_cmdname(argv[0]), argc);
1520 count = strtoull(argv[1], &end, 0);
1522 fprintf(stderr, "error: %s: bad iteration count '%s'\n",
1523 jt_cmdname(argv[0]), argv[1]);
1528 if (argv[2][0] == 'w' || argv[2][0] == '1')
1530 /* else it's a read */
1532 if (argv[2][0] != 0)
1533 for (i = 1; argv[2][i] != 0; i++)
1534 switch (argv[2][i]) {
1544 fprintf (stderr, "Can't parse cmd '%s'\n",
1551 verbose = get_verbose(argv[0], argv[3]);
1552 if (verbose == BAD_VERBOSE)
1557 pages = strtoul(argv[4], &end, 0);
1560 offset_pages = strtoul(end + 1, &end, 0);
1563 offset_pages < 0 || offset_pages >= pages) {
1564 fprintf(stderr, "error: %s: bad npages[+offset] parameter '%s'\n",
1565 jt_cmdname(argv[0]), argv[4]);
1572 (n = strtol(argv[5], &end, 0)) > 0 &&
1574 (ull = strtoull(end + 1, &end, 0)) > 0 &&
1578 } else if (thread &&
1579 argv[5][0] == 't') {
1581 objid = strtoull(argv[5] + 1, &end, 0);
1584 objid = strtoull(argv[5], &end, 0);
1587 fprintf(stderr, "error: %s: bad objid '%s'\n",
1588 jt_cmdname(argv[0]), argv[5]);
1593 memset(&data, 0x00, sizeof(data));
1594 data.ioc_dev = cur_device;
1596 /* communicate the 'type' of brw test and batching to echo_client.
1597 * don't start. we'd love to refactor this lctl->echo_client
1599 data.ioc_pbuf1 = (void *)1;
1603 switch(argv[6][0]) {
1604 case 'g': /* plug and unplug */
1605 data.ioc_pbuf1 = (void *)2;
1606 data.ioc_plen1 = strtoull(argv[6] + 1, &end,
1609 case 'p': /* prep and commit */
1610 data.ioc_pbuf1 = (void *)3;
1611 data.ioc_plen1 = strtoull(argv[6] + 1, &end,
1615 fprintf(stderr, "error: %s: batching '%s' "
1616 "needs to specify 'p' or 'g'\n",
1617 jt_cmdname(argv[0]), argv[6]);
1622 fprintf(stderr, "error: %s: bad batching '%s'\n",
1623 jt_cmdname(argv[0]), argv[6]);
1626 data.ioc_plen1 *= getpagesize();
1629 len = pages * getpagesize();
1630 thr_offset = offset_pages * getpagesize();
1636 if (nthr_per_obj != 0) {
1637 /* threads interleave */
1638 obj_idx = (thread - 1)/nthr_per_obj;
1640 stride *= nthr_per_obj;
1642 shared_data->offsets[obj_idx] = stride + thr_offset;
1643 thr_offset += ((thread - 1) % nthr_per_obj) * len;
1645 /* threads disjoint */
1646 thr_offset += (thread - 1) * len;
1649 shared_data->barrier--;
1650 if (shared_data->barrier == 0)
1651 l_cond_broadcast(&shared_data->cond);
1653 l_cond_wait(&shared_data->cond,
1654 &shared_data->mutex);
1660 data.ioc_obdo1.o_id = objid;
1661 data.ioc_obdo1.o_mode = S_IFREG;
1662 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLFLAGS;
1663 data.ioc_obdo1.o_flags = (verify ? OBD_FL_DEBUG_CHECK : 0);
1664 data.ioc_count = len;
1665 data.ioc_offset = (repeat_offset ? 0 : thr_offset);
1667 gettimeofday(&start, NULL);
1668 next_time.tv_sec = start.tv_sec - verbose;
1669 next_time.tv_usec = start.tv_usec;
1672 printf("%s: %s "LPU64"x%d pages (obj "LPX64", off "LPU64"): %s",
1673 jt_cmdname(argv[0]), write ? "writing" : "reading", count,
1674 pages, objid, data.ioc_offset, ctime(&start.tv_sec));
1676 cmd = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1677 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1678 data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS|OBD_MD_FLGRANT);
1679 memset(buf, 0x00, sizeof(rawbuf));
1680 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1682 fprintf(stderr, "error: %s: invalid ioctl\n",
1683 jt_cmdname(argv[0]));
1686 rc = l2_ioctl(OBD_DEV_ID, cmd, buf);
1689 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1690 jt_cmdname(argv[0]), i, strerror(rc = errno),
1691 write ? "write" : "read");
1693 } else if (be_verbose(verbose, &next_time,i, &next_count,count)) {
1695 printf("%s: %s number %d @ "LPD64":"LPU64" for %d\n",
1696 jt_cmdname(argv[0]), write ? "write" : "read", i,
1697 data.ioc_obdo1.o_id, data.ioc_offset,
1698 (int)(pages * getpagesize()));
1702 if (!repeat_offset) {
1704 if (stride == len) {
1705 data.ioc_offset += stride;
1706 } else if (i < count) {
1708 data.ioc_offset = shared_data->offsets[obj_idx];
1709 shared_data->offsets[obj_idx] += len;
1713 data.ioc_offset += len;
1714 obj_idx = 0; /* avoids an unused var warning */
1723 gettimeofday(&end, NULL);
1725 diff = difftime(&end, &start);
1729 printf("%s: %s %dx%d pages in %.3fs (%.3f MB/s): %s",
1730 jt_cmdname(argv[0]), write ? "wrote" : "read",
1732 ((double)i * pages * getpagesize()) /
1734 ctime(&end.tv_sec));
1740 int jt_obd_lov_getconfig(int argc, char **argv)
1742 struct obd_ioctl_data data;
1743 struct lov_desc desc;
1744 struct obd_uuid *uuidarray;
1745 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1750 memset(&data, 0x00, sizeof(data));
1751 data.ioc_dev = cur_device;
1757 fd = open(path, O_RDONLY);
1759 fprintf(stderr, "open \"%s\" failed: %s\n", path,
1764 memset(&desc, 0, sizeof(desc));
1765 obd_str2uuid(&desc.ld_uuid, argv[1]);
1766 desc.ld_tgt_count = ((OBD_MAX_IOCTL_BUFFER-sizeof(data)-sizeof(desc)) /
1767 (sizeof(*uuidarray) + sizeof(*obdgens)));
1770 uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
1772 fprintf(stderr, "error: %s: no memory for %d uuid's\n",
1773 jt_cmdname(argv[0]), desc.ld_tgt_count);
1777 obdgens = calloc(desc.ld_tgt_count, sizeof(*obdgens));
1779 fprintf(stderr, "error: %s: no memory for %d generation #'s\n",
1780 jt_cmdname(argv[0]), desc.ld_tgt_count);
1785 memset(buf, 0x00, sizeof(rawbuf));
1786 data.ioc_inllen1 = sizeof(desc);
1787 data.ioc_inlbuf1 = (char *)&desc;
1788 data.ioc_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
1789 data.ioc_inlbuf2 = (char *)uuidarray;
1790 data.ioc_inllen3 = desc.ld_tgt_count * sizeof(*obdgens);
1791 data.ioc_inlbuf3 = (char *)obdgens;
1793 if (obd_ioctl_pack(&data, &buf, sizeof(rawbuf))) {
1794 fprintf(stderr, "error: %s: invalid ioctl\n",
1795 jt_cmdname(argv[0]));
1799 rc = ioctl(fd, OBD_IOC_LOV_GET_CONFIG, buf);
1800 if (rc == -ENOSPC) {
1805 fprintf(stderr, "error: %s: ioctl error: %s\n",
1806 jt_cmdname(argv[0]), strerror(rc = errno));
1808 struct obd_uuid *uuidp;
1812 if (obd_ioctl_unpack(&data, buf, sizeof(rawbuf))) {
1813 fprintf(stderr, "error: %s: invalid reply\n",
1814 jt_cmdname(argv[0]));
1818 if (desc.ld_default_stripe_count == (__u16)-1)
1819 printf("default_stripe_count: %d\n", -1);
1821 printf("default_stripe_count: %u\n",
1822 desc.ld_default_stripe_count);
1823 printf("default_stripe_size: "LPU64"\n",
1824 desc.ld_default_stripe_size);
1825 printf("default_stripe_offset: "LPU64"\n",
1826 desc.ld_default_stripe_offset);
1827 printf("default_stripe_pattern: %u\n", desc.ld_pattern);
1828 printf("obd_count: %u\n", desc.ld_tgt_count);
1829 printf("OBDS:\tobdidx\t\tobdgen\t\t obduuid\n");
1832 for (i = 0; i < desc.ld_tgt_count; i++, uuidp++, genp++)
1833 printf("\t%6u\t%14u\t\t %s\n", i, *genp, (char *)uuidp);
1844 int jt_obd_ldlm_regress_start(int argc, char **argv)
1847 struct obd_ioctl_data data;
1848 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1849 char argstring[200];
1850 int i, count = sizeof(argstring) - 1;
1852 memset(&data, 0x00, sizeof(data));
1853 data.ioc_dev = cur_device;
1857 argstring[0] = '\0';
1858 for (i = 1; i < argc; i++) {
1859 strncat(argstring, " ", count);
1861 strncat(argstring, argv[i], count);
1862 count -= strlen(argv[i]);
1865 if (strlen(argstring)) {
1866 data.ioc_inlbuf1 = argstring;
1867 data.ioc_inllen1 = strlen(argstring) + 1;
1870 memset(buf, 0, sizeof(rawbuf));
1871 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1873 fprintf(stderr, "error: %s: invalid ioctl\n",
1874 jt_cmdname(argv[0]));
1877 rc = l2_ioctl(OBD_DEV_ID, IOC_LDLM_REGRESS_START, buf);
1879 fprintf(stderr, "error: %s: test failed: %s\n",
1880 jt_cmdname(argv[0]), strerror(rc = errno));
1885 int jt_obd_ldlm_regress_stop(int argc, char **argv)
1888 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1889 struct obd_ioctl_data data;
1891 memset(&data, 0x00, sizeof(data));
1892 data.ioc_dev = cur_device;
1897 memset(buf, 0, sizeof(rawbuf));
1898 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1900 fprintf(stderr, "error: %s: invalid ioctl\n",
1901 jt_cmdname(argv[0]));
1904 rc = l2_ioctl(OBD_DEV_ID, IOC_LDLM_REGRESS_STOP, buf);
1907 fprintf(stderr, "error: %s: test failed: %s\n",
1908 jt_cmdname(argv[0]), strerror(rc = errno));
1912 static int do_activate(int argc, char **argv, int flag)
1914 struct obd_ioctl_data data;
1915 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1918 memset(&data, 0x00, sizeof(data));
1919 data.ioc_dev = cur_device;
1923 /* reuse offset for 'active' */
1924 data.ioc_offset = flag;
1926 memset(buf, 0, sizeof(rawbuf));
1927 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1929 fprintf(stderr, "error: %s: invalid ioctl\n",
1930 jt_cmdname(argv[0]));
1933 rc = l2_ioctl(OBD_DEV_ID, IOC_OSC_SET_ACTIVE, buf);
1935 fprintf(stderr, "error: %s: failed: %s\n",
1936 jt_cmdname(argv[0]), strerror(rc = errno));
1941 int jt_obd_deactivate(int argc, char **argv)
1943 return do_activate(argc, argv, 0);
1946 int jt_obd_activate(int argc, char **argv)
1948 return do_activate(argc, argv, 1);
1951 int jt_obd_recover(int argc, char **argv)
1954 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1955 struct obd_ioctl_data data;
1957 memset(&data, 0x00, sizeof(data));
1958 data.ioc_dev = cur_device;
1963 data.ioc_inllen1 = strlen(argv[1]) + 1;
1964 data.ioc_inlbuf1 = argv[1];
1967 memset(buf, 0, sizeof(rawbuf));
1968 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1970 fprintf(stderr, "error: %s: invalid ioctl\n",
1971 jt_cmdname(argv[0]));
1974 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CLIENT_RECOVER, buf);
1976 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1977 strerror(rc = errno));
1983 int jt_obd_mdc_lookup(int argc, char **argv)
1985 struct obd_ioctl_data data;
1986 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1987 char *parent, *child;
1988 int rc, fd, verbose = 1;
1990 if (argc < 3 || argc > 4)
1996 verbose = get_verbose(argv[0], argv[3]);
1998 memset(&data, 0x00, sizeof(data));
1999 data.ioc_dev = cur_device;
2001 data.ioc_inllen1 = strlen(child) + 1;
2002 data.ioc_inlbuf1 = child;
2004 memset(buf, 0, sizeof(rawbuf));
2005 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2007 fprintf(stderr, "error: %s: invalid ioctl\n",
2008 jt_cmdname(argv[0]));
2012 fd = open(parent, O_RDONLY);
2014 fprintf(stderr, "open \"%s\" failed: %s\n", parent,
2019 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
2021 fprintf(stderr, "error: %s: ioctl error: %s\n",
2022 jt_cmdname(argv[0]), strerror(rc = errno));
2027 rc = obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
2029 fprintf(stderr, "error: %s: invalid reply\n",
2030 jt_cmdname(argv[0]));
2033 printf("%s: mode %o uid %d gid %d\n", child,
2034 data.ioc_obdo1.o_mode, data.ioc_obdo1.o_uid,
2035 data.ioc_obdo1.o_gid);
2041 int jt_cfg_dump_log(int argc, char **argv)
2043 struct obd_ioctl_data data;
2044 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2051 memset(&data, 0x00, sizeof(data));
2052 data.ioc_dev = cur_device;
2053 data.ioc_inllen1 = strlen(argv[1]) + 1;
2054 data.ioc_inlbuf1 = argv[1];
2056 memset(buf, 0, sizeof(rawbuf));
2057 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2059 fprintf(stderr, "error: %s: invalid ioctl\n",
2060 jt_cmdname(argv[0]));
2063 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_DUMP_LOG, buf);
2065 fprintf(stderr, "OBD_IOC_DUMP_LOG failed: %s\n",
2071 int jt_llog_catlist(int argc, char **argv)
2073 struct obd_ioctl_data data;
2074 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2080 memset(&data, 0x00, sizeof(data));
2081 data.ioc_dev = cur_device;
2082 data.ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(data));
2083 memset(buf, 0, sizeof(rawbuf));
2084 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2086 fprintf(stderr, "error: %s: invalid ioctl\n",
2087 jt_cmdname(argv[0]));
2090 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CATLOGLIST, buf);
2092 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2094 fprintf(stderr, "OBD_IOC_CATLOGLIST failed: %s\n",
2100 int jt_llog_info(int argc, char **argv)
2102 struct obd_ioctl_data data;
2103 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2109 memset(&data, 0x00, sizeof(data));
2110 data.ioc_dev = cur_device;
2111 data.ioc_inllen1 = strlen(argv[1]) + 1;
2112 data.ioc_inlbuf1 = argv[1];
2113 data.ioc_inllen2 = sizeof(rawbuf) - size_round(sizeof(data)) -
2114 size_round(data.ioc_inllen1);
2115 memset(buf, 0, sizeof(rawbuf));
2116 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2118 fprintf(stderr, "error: %s: invalid ioctl\n",
2119 jt_cmdname(argv[0]));
2123 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf);
2125 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2127 fprintf(stderr, "OBD_IOC_LLOG_INFO failed: %s\n",
2133 int jt_llog_print(int argc, char **argv)
2135 struct obd_ioctl_data data;
2136 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2139 if (argc != 2 && argc != 4)
2142 memset(&data, 0x00, sizeof(data));
2143 data.ioc_dev = cur_device;
2144 data.ioc_inllen1 = strlen(argv[1]) + 1;
2145 data.ioc_inlbuf1 = argv[1];
2147 data.ioc_inllen2 = strlen(argv[2]) + 1;
2148 data.ioc_inlbuf2 = argv[2];
2149 data.ioc_inllen3 = strlen(argv[3]) + 1;
2150 data.ioc_inlbuf3 = argv[3];
2152 char from[2] = "1", to[3] = "-1";
2153 data.ioc_inllen2 = strlen(from) + 1;
2154 data.ioc_inlbuf2 = from;
2155 data.ioc_inllen3 = strlen(to) + 1;
2156 data.ioc_inlbuf3 = to;
2158 data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) -
2159 size_round(data.ioc_inllen1) -
2160 size_round(data.ioc_inllen2) -
2161 size_round(data.ioc_inllen3);
2162 memset(buf, 0, sizeof(rawbuf));
2163 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2165 fprintf(stderr, "error: %s: invalid ioctl\n",
2166 jt_cmdname(argv[0]));
2170 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_PRINT, buf);
2172 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2174 fprintf(stderr, "OBD_IOC_LLOG_PRINT failed: %s\n",
2180 int jt_llog_cancel(int argc, char **argv)
2182 struct obd_ioctl_data data;
2183 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2189 memset(&data, 0x00, sizeof(data));
2190 data.ioc_dev = cur_device;
2191 data.ioc_inllen1 = strlen(argv[1]) + 1;
2192 data.ioc_inlbuf1 = argv[1];
2193 data.ioc_inllen2 = strlen(argv[2]) + 1;
2194 data.ioc_inlbuf2 = argv[2];
2195 data.ioc_inllen3 = strlen(argv[3]) + 1;
2196 data.ioc_inlbuf3 = argv[3];
2197 memset(buf, 0, sizeof(rawbuf));
2198 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2200 fprintf(stderr, "error: %s: invalid ioctl\n",
2201 jt_cmdname(argv[0]));
2205 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
2207 fprintf(stdout, "index %s be canceled.\n", argv[3]);
2209 fprintf(stderr, "OBD_IOC_LLOG_CANCEL failed: %s\n",
2215 int jt_llog_check(int argc, char **argv)
2217 struct obd_ioctl_data data;
2218 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2221 if (argc != 2 && argc != 4)
2224 memset(&data, 0x00, sizeof(data));
2225 data.ioc_dev = cur_device;
2226 data.ioc_inllen1 = strlen(argv[1]) + 1;
2227 data.ioc_inlbuf1 = argv[1];
2229 data.ioc_inllen2 = strlen(argv[2]) + 1;
2230 data.ioc_inlbuf2 = argv[2];
2231 data.ioc_inllen3 = strlen(argv[3]) + 1;
2232 data.ioc_inlbuf3 = argv[3];
2234 char from[2] = "1", to[3] = "-1";
2235 data.ioc_inllen2 = strlen(from) + 1;
2236 data.ioc_inlbuf2 = from;
2237 data.ioc_inllen3 = strlen(to) + 1;
2238 data.ioc_inlbuf3 = to;
2240 data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) -
2241 size_round(data.ioc_inllen1) -
2242 size_round(data.ioc_inllen2) -
2243 size_round(data.ioc_inllen3);
2244 memset(buf, 0, sizeof(rawbuf));
2245 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2247 fprintf(stderr, "error: %s: invalid ioctl\n",
2248 jt_cmdname(argv[0]));
2252 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf);
2254 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2256 fprintf(stderr, "OBD_IOC_LLOG_CHECK failed: %s\n",
2261 int jt_llog_remove(int argc, char **argv)
2263 struct obd_ioctl_data data;
2264 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2267 if (argc != 3 && argc != 2)
2270 memset(&data, 0x00, sizeof(data));
2271 data.ioc_dev = cur_device;
2272 data.ioc_inllen1 = strlen(argv[1]) + 1;
2273 data.ioc_inlbuf1 = argv[1];
2275 data.ioc_inllen2 = strlen(argv[2]) + 1;
2276 data.ioc_inlbuf2 = argv[2];
2278 memset(buf, 0, sizeof(rawbuf));
2279 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2281 fprintf(stderr, "error: %s: invalid ioctl\n",
2282 jt_cmdname(argv[0]));
2286 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf);
2289 fprintf(stdout, "log %s are removed.\n", argv[2]);
2291 fprintf(stdout, "the log in catalog %s are removed. \n", argv[1]);
2293 fprintf(stderr, "OBD_IOC_LLOG_REMOVE failed: %s\n",
2299 /* attach a regular file to virtual block device.
2302 * 1: error, it always means the command run failed
2305 static int jt_blockdev_run_process(const char *file, char *argv[])
2311 if (pid == 0) { /* child process */
2312 /* don't print error messages */
2314 (void)execvp(file, argv);
2316 } else if (pid > 0) {
2319 rc = waitpid(pid, &status, 0);
2320 if (rc < 0 || !WIFEXITED(status))
2323 return WEXITSTATUS(status);
2329 static int jt_blockdev_find_module(const char *module)
2335 fp = fopen("/proc/modules", "r");
2339 while (fscanf(fp, "%s %*s %*s %*s %*s %*s", modname) == 1) {
2340 if (strcmp(module, modname) == 0) {
2350 static int jt_blockdev_probe_module(const char *module)
2356 if (jt_blockdev_find_module(module) == 1)
2359 /* run modprobe first */
2361 argv[c++] = "/sbin/modprobe";
2363 argv[c++] = (char *)module;
2365 rc = jt_blockdev_run_process("modprobe", argv);
2369 /* cannot find the module in default directory ... */
2370 sprintf(buf, "../llite/%s.ko", module);
2372 argv[c++] = "/sbin/insmod";
2375 rc = jt_blockdev_run_process("insmod", argv);
2379 int jt_blockdev_attach(int argc, char **argv)
2383 char *filename, *devname;
2389 if (jt_blockdev_probe_module("llite_lloop") < 0) {
2390 fprintf(stderr, "error: cannot find module llite_lloop.(k)o\n");
2397 fd = open(filename, O_RDWR);
2399 fprintf(stderr, "file %s can't be opened(%s)\n\n",
2400 filename, strerror(errno));
2404 rc = ioctl(fd, LL_IOC_LLOOP_ATTACH, &dev);
2407 fprintf(stderr, "attach error(%s)\n", strerror(rc));
2411 rc = stat(devname, &st);
2412 if (rc == 0 && (!S_ISBLK(st.st_mode) || st.st_rdev != dev)) {
2414 } else if (rc < 0) {
2415 if (errno == ENOENT &&
2416 !mknod(devname, S_IFBLK|S_IRUSR|S_IWUSR, dev))
2423 fprintf(stderr, "error: the file %s could be attached to block "
2424 "device %X but creating %s failed: %s\n"
2425 "now detaching the block device..",
2426 filename, (int)dev, devname, strerror(rc));
2428 (void)ioctl(fd, LL_IOC_LLOOP_DETACH_BYDEV, dev);
2429 fprintf(stderr, "%s\n", strerror(errno));
2436 int jt_blockdev_detach(int argc, char **argv)
2445 fd = open(filename, O_RDONLY);
2447 fprintf(stderr, "cannot open file %s error %s\n",
2448 filename, strerror(errno));
2452 rc = ioctl(fd, LL_IOC_LLOOP_DETACH, 0);
2455 fprintf(stderr, "detach error(%s)\n", strerror(rc));
2457 (void)unlink(filename);
2464 int jt_blockdev_info(int argc, char **argv)
2474 fd = open(filename, O_RDONLY);
2476 fprintf(stderr, "cannot open file %s error: %s\n",
2477 filename, strerror(errno));
2481 rc = ioctl(fd, LL_IOC_LLOOP_INFO, &ino);
2484 fprintf(stderr, "error: %s\n", strerror(errno));
2487 fprintf(stdout, "lloop device info: ");
2489 fprintf(stdout, "Not attached\n");
2491 fprintf(stdout, "attached to inode "LPU64"\n", ino);
2497 static void signal_server(int sig)
2499 if (sig == SIGINT) {
2500 do_disconnect("sigint", 1);
2503 fprintf(stderr, "%s: got signal %d\n", jt_cmdname("sigint"), sig);
2506 int obd_initialize(int argc, char **argv)
2510 for (i = 0; i < MAX_STRIPES; i++)
2511 lsm_buffer.lsm.lsm_oinfo[i] = lov_oinfos + i;
2514 register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH,
2515 OBD_DEV_MAJOR, OBD_DEV_MINOR);
2520 void obd_finalize(int argc, char **argv)
2522 struct sigaction sigact;
2524 sigact.sa_handler = signal_server;
2525 sigfillset(&sigact.sa_mask);
2526 sigact.sa_flags = SA_RESTART;
2527 sigaction(SIGINT, &sigact, NULL);
2530 do_disconnect(argv[0], 1);
2533 static int check_pool_cmd(enum lcfg_command_type cmd,
2534 char *fsname, char *poolname,
2539 rc = llapi_search_ost(fsname, poolname, ostname);
2540 if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
2541 fprintf(stderr, "Pool %s.%s not found\n",
2547 case LCFG_POOL_NEW: {
2548 LASSERT(ostname == NULL);
2550 fprintf(stderr, "Pool %s.%s already exists\n",
2556 case LCFG_POOL_DEL: {
2557 LASSERT(ostname == NULL);
2559 fprintf(stderr, "Pool %s.%s not empty, "
2560 "please remove all members\n",
2566 case LCFG_POOL_ADD: {
2568 fprintf(stderr, "OST %s is already in pool %s.%s\n",
2569 ostname, fsname, poolname);
2572 rc = llapi_search_ost(fsname, NULL, ostname);
2574 fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
2580 case LCFG_POOL_REM: {
2582 fprintf(stderr, "OST %s not found in pool %s.%s\n",
2583 ostname, fsname, poolname);
2594 /* This check only verifies that the changes have been "pushed out" to
2595 the client successfully. This involves waiting for a config update,
2596 and so may fail because of problems in that code or post-command
2597 network loss. So reporting a warning is appropriate, but not a failure.
2599 static int check_pool_cmd_result(enum lcfg_command_type cmd,
2600 char *fsname, char *poolname,
2607 case LCFG_POOL_NEW: {
2609 rc = llapi_search_ost(fsname, poolname, NULL);
2615 } while ((rc < 0) && (cpt > 0));
2617 fprintf(stderr, "Pool %s.%s created\n",
2621 fprintf(stderr, "Warning, pool %s.%s not found\n",
2626 case LCFG_POOL_DEL: {
2628 rc = llapi_search_ost(fsname, poolname, NULL);
2634 } while ((rc >= 0) && (cpt > 0));
2636 fprintf(stderr, "Pool %s.%s destroyed\n",
2640 fprintf(stderr, "Warning, pool %s.%s still found\n",
2645 case LCFG_POOL_ADD: {
2647 rc = llapi_search_ost(fsname, poolname, ostname);
2653 } while ((rc != 1) && (cpt > 0));
2655 fprintf(stderr, "OST %s added to pool %s.%s\n",
2656 ostname, fsname, poolname);
2659 fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
2660 ostname, fsname, poolname);
2664 case LCFG_POOL_REM: {
2666 rc = llapi_search_ost(fsname, poolname, ostname);
2672 } while ((rc == 1) && (cpt > 0));
2674 fprintf(stderr, "OST %s removed from pool %s.%s\n",
2675 ostname, fsname, poolname);
2678 fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
2679 ostname, fsname, poolname);
2689 static int check_and_complete_ostname(char *fsname, char *ostname)
2692 char real_ostname[MAX_OBD_NAME + 1];
2695 /* if OST name does not start with fsname, we add it */
2696 /* if not check if the fsname is the right one */
2697 ptr = strchr(ostname, '-');
2699 sprintf(real_ostname, "%s-%s", fsname, ostname);
2700 } else if (strncmp(ostname, fsname, strlen(fsname)) != 0) {
2701 fprintf(stderr, "%s does not start with fsname %s\n",
2705 strcpy(real_ostname, ostname);
2707 /* real_ostname is fsname-????? */
2708 ptr = real_ostname + strlen(fsname) + 1;
2709 if (strncmp(ptr, "OST", 3) != 0) {
2710 fprintf(stderr, "%s does not start by %s-OST nor OST\n",
2714 /* real_ostname is fsname-OST????? */
2716 for (i = 0; i < 4; i++) {
2717 if (!isxdigit(*ptr)) {
2719 "ost's index in %s is not an hexa number\n",
2725 /* real_ostname is fsname-OSTXXXX????? */
2726 /* if OST name does not end with _UUID, we add it */
2728 strcat(real_ostname, "_UUID");
2729 } else if (strcmp(ptr, "_UUID") != 0) {
2731 "ostname %s does not end with _UUID\n", ostname);
2734 /* real_ostname is fsname-OSTXXXX_UUID */
2735 strcpy(ostname, real_ostname);
2739 /* returns 0 or -errno */
2740 static int pool_cmd(enum lcfg_command_type cmd,
2741 char *cmdname, char *fullpoolname,
2742 char *fsname, char *poolname, char *ostname)
2745 struct obd_ioctl_data data;
2746 struct lustre_cfg_bufs bufs;
2747 struct lustre_cfg *lcfg;
2748 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2750 rc = check_pool_cmd(cmd, fsname, poolname, ostname);
2752 fprintf(stderr, "Can't verify pool command since there "
2753 "is no local MDT or client, proceeding anyhow...\n");
2757 lustre_cfg_bufs_reset(&bufs, NULL);
2758 lustre_cfg_bufs_set_string(&bufs, 0, cmdname);
2759 lustre_cfg_bufs_set_string(&bufs, 1, fullpoolname);
2760 if (ostname != NULL)
2761 lustre_cfg_bufs_set_string(&bufs, 2, ostname);
2763 lcfg = lustre_cfg_new(cmd, &bufs);
2769 memset(&data, 0x00, sizeof(data));
2770 rc = data.ioc_dev = get_mgs_device();
2774 data.ioc_type = LUSTRE_CFG_TYPE;
2775 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
2776 lcfg->lcfg_buflens);
2777 data.ioc_pbuf1 = (void *)lcfg;
2779 memset(buf, 0, sizeof(rawbuf));
2780 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
2782 fprintf(stderr, "error: %s: invalid ioctl\n",
2783 jt_cmdname(cmdname));
2786 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);
2790 lustre_cfg_free(lcfg);
2795 * this function tranforms a rule [start-end/step] into an array
2796 * of matching numbers
2797 * supported forms are:
2798 * [start] : just this number
2799 * [start-end] : all numbers from start to end
2800 * [start-end/step] : numbers from start to end with increment of step
2801 * on return, format contains a printf format string which can be used
2802 * to generate all the strings
2804 static int get_array_idx(char *rule, char *format, int **array)
2806 char *start, *end, *ptr;
2807 unsigned int lo, hi, step;
2812 start = strchr(rule, '[');
2813 end = strchr(rule, ']');
2814 if ((start == NULL) || (end == NULL)) {
2815 *array = malloc(sizeof(int));
2818 strcpy(format, rule);
2826 /* put in format the printf format (the rule without the range) */
2827 sprintf(format, "%s%%.4x%s", rule, end);
2832 /* loop on , separator */
2834 /* extract the 3 fields */
2835 rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
2842 *array = realloc(*array, array_sz * sizeof(int));
2845 (*array)[array_idx] = lo;
2851 /* do not break to share code with case 3: */
2854 if ((hi < lo) || (step == 0))
2856 array_sz += (hi - lo) / step + 1;
2857 *array = realloc(*array, sizeof(int) * array_sz);
2860 for (i = lo; i <= hi; i+=step, array_idx++)
2861 (*array)[array_idx] = i;
2865 ptr = strchr(start, ',');
2869 } while (ptr != NULL);
2873 static int extract_fsname_poolname(char *arg, char *fsname, char *poolname)
2879 strcpy(fsname, arg);
2880 ptr = strchr(fsname, '.');
2882 fprintf(stderr, ". is missing in %s\n", fsname);
2889 fprintf(stderr, "fsname is empty\n");
2894 len = strlen(ptr + 1);
2896 fprintf(stderr, "poolname is empty\n");
2900 if (len > LOV_MAXPOOLNAME) {
2902 "poolname %s is too long (length is %d max is %d)\n",
2903 ptr + 1, len, LOV_MAXPOOLNAME);
2907 strncpy(poolname, ptr + 1, LOV_MAXPOOLNAME);
2908 poolname[LOV_MAXPOOLNAME] = '\0';
2913 fprintf(stderr, "argument %s must be <fsname>.<poolname>\n", arg);
2917 int jt_pool_cmd(int argc, char **argv)
2919 enum lcfg_command_type cmd;
2920 char fsname[PATH_MAX + 1];
2921 char poolname[LOV_MAXPOOLNAME + 1];
2922 char *ostnames_buf = NULL;
2924 int *array = NULL, array_sz;
2932 case 1: return CMD_HELP;
2934 if (strcmp("pool_new", argv[0]) == 0)
2935 cmd = LCFG_POOL_NEW;
2936 else if (strcmp("pool_destroy", argv[0]) == 0)
2937 cmd = LCFG_POOL_DEL;
2938 else if (strcmp("pool_list", argv[0]) == 0)
2939 return llapi_poollist(argv[1]);
2940 else return CMD_HELP;
2942 rc = extract_fsname_poolname(argv[1], fsname, poolname);
2946 rc = pool_cmd(cmd, argv[0], argv[1], fsname, poolname, NULL);
2950 check_pool_cmd_result(cmd, fsname, poolname, NULL);
2954 char format[2*MAX_OBD_NAME];
2956 if (strcmp("pool_remove", argv[0]) == 0) {
2957 cmd = LCFG_POOL_REM;
2958 } else if (strcmp("pool_add", argv[0]) == 0) {
2959 cmd = LCFG_POOL_ADD;
2964 rc = extract_fsname_poolname(argv[1], fsname, poolname);
2968 for (i = 2; i < argc; i++) {
2971 array_sz = get_array_idx(argv[i], format, &array);
2975 cmds = malloc(array_sz * sizeof(cmds[0]));
2977 ostnames_buf = malloc(array_sz *
2978 (MAX_OBD_NAME + 1));
2985 for (j = 0; j < array_sz; j++) {
2986 char ostname[MAX_OBD_NAME + 1];
2988 snprintf(ostname, MAX_OBD_NAME, format,
2990 ostname[MAX_OBD_NAME] = '\0';
2992 rc = check_and_complete_ostname(fsname,ostname);
3000 if (ostnames_buf != NULL) {
3002 &ostnames_buf[(MAX_OBD_NAME + 1) * j];
3003 strcpy(cmds[j].ostname, ostname);
3005 cmds[j].ostname = NULL;
3007 cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
3010 /* Return an err if any of the add/dels fail */
3014 for (j = 0; j < array_sz; j++) {
3016 char ostname[MAX_OBD_NAME + 1];
3018 if (!cmds[j].ostname) {
3019 snprintf(ostname, MAX_OBD_NAME,
3021 ostname[MAX_OBD_NAME] = '\0';
3022 check_and_complete_ostname(
3028 check_pool_cmd_result(cmd, fsname,
3052 int jt_get_obj_version(int argc, char **argv)
3055 struct obd_ioctl_data data;
3057 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr;
3065 while (*fidstr == '[')
3067 sscanf(fidstr, SFID, RFID(&f));
3069 * fid_is_sane is not suitable here. We rely on
3070 * mds_fid2locked_dentry to report on insane FIDs.
3073 fid.generation = f.f_oid;
3074 fid.f_type = f.f_ver;
3076 memset(&data, 0, sizeof data);
3077 data.ioc_dev = cur_device;
3078 data.ioc_inlbuf1 = (char *) &fid;
3079 data.ioc_inllen1 = sizeof fid;
3080 data.ioc_inlbuf2 = (char *) &version;
3081 data.ioc_inllen2 = sizeof version;
3083 memset(buf, 0, sizeof *buf);
3084 rc = obd_ioctl_pack(&data, &buf, sizeof rawbuf);
3086 fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
3087 jt_cmdname(argv[0]), strerror(-rc));
3091 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GET_OBJ_VERSION, buf);
3093 fprintf(stderr, "error: %s: ioctl: %s\n",
3094 jt_cmdname(argv[0]), strerror(errno));
3098 obd_ioctl_unpack(&data, buf, sizeof rawbuf);
3099 printf(LPX64"\n", version);
3103 void llapi_ping_target(char *obd_type, char *obd_name,
3104 char *obd_uuid, void *args)
3107 struct obd_ioctl_data data;
3108 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3110 memset(&data, 0, sizeof(data));
3111 data.ioc_inlbuf4 = obd_name;
3112 data.ioc_inllen4 = strlen(obd_name) + 1;
3113 data.ioc_dev = OBD_DEV_BY_DEVNAME;
3114 memset(buf, 0, sizeof(rawbuf));
3115 if (obd_ioctl_pack(&data, &buf, sizeof(rawbuf))) {
3116 fprintf(stderr, "error: invalid ioctl\n");
3119 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_PING_TARGET, buf);
3122 if (rc == ENOTCONN || rc == ESHUTDOWN) {
3123 printf("%s: INACTIVE\n", obd_name);
3125 printf("%s: check error: %s\n",
3126 obd_name, strerror(errno));
3128 printf("%s: active\n", obd_name);