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>
43 #include <linux/obd.h> /* for struct lov_stripe_md */
44 #include <linux/lustre_build_version.h>
53 #include <asm/page.h> /* needed for PAGE_SIZE - rread */
56 #include <linux/list.h>
59 #include <linux/obd_class.h>
60 #include <portals/ptlctl.h>
69 #define MAX_STRING_SIZE 128
70 #define DEVICES_LIST "/proc/fs/lustre/devices"
72 #define MAX_THREADS 1024
74 __u64 counters[MAX_THREADS];
75 __u64 offsets[MAX_THREADS];
78 pthread_mutex_t mutex;
81 static struct shared_data *shared_data;
82 static __u64 counter_snapshot[2][MAX_THREADS];
83 static int prev_valid;
84 struct timeval prev_time;
86 static int jt_recording;
87 static char rawbuf[8192];
88 static char *buf = rawbuf;
89 static int max = sizeof(rawbuf);
94 static uint32_t cur_device = MAX_OBD_DEVICES;
98 struct lov_stripe_md lsm;
101 static int l2_ioctl(int dev_id, int opc, void *buf)
103 return l_ioctl(dev_id, opc, buf);
106 #define IOC_INIT(data) \
108 memset(&data, 0, sizeof(data)); \
109 data.ioc_dev = cur_device; \
112 #define IOC_PACK(func, data) \
114 memset(buf, 0, sizeof(rawbuf)); \
115 if (obd_ioctl_pack(&data, &buf, max)) { \
116 fprintf(stderr, "error: %s: invalid ioctl\n", \
122 #define IOC_UNPACK(func, data) \
124 if (obd_ioctl_unpack(&data, buf, max)) { \
125 fprintf(stderr, "error: %s: invalid reply\n", \
131 int obd_record(enum cfg_record_type type, int len, void *ptr)
133 struct obd_ioctl_data data;
136 data.ioc_type = type;
137 data.ioc_plen1 = len;
138 data.ioc_pbuf1 = ptr;
139 IOC_PACK("obd_record", data);
141 return l_ioctl(OBD_DEV_ID, OBD_IOC_DORECORD, &data);
144 int lcfg_ioctl(char * func, int dev_id, struct lustre_cfg *lcfg)
147 char lcfg_rawbuf[8192];
148 char * lcfg_buf= lcfg_rawbuf;
149 struct obd_ioctl_data data;
153 memset(lcfg_buf, 0, sizeof(lcfg_rawbuf));
154 if (lustre_cfg_pack(lcfg, &lcfg_buf, sizeof(lcfg_rawbuf), &len)) {
155 fprintf(stderr, "error: %s: invalid ioctl\n",
161 data.ioc_type = LUSTRE_CFG_TYPE;
162 data.ioc_plen1 = len;
163 data.ioc_pbuf1 = lcfg_buf;
164 IOC_PACK(func, data);
167 opc = OBD_IOC_DORECORD;
169 opc = OBD_IOC_PROCESS_CFG;
171 rc = l_ioctl(dev_id, opc, buf);
173 rc = lustre_cfg_unpack(lcfg, lcfg_buf, sizeof(lcfg_rawbuf));
178 char *obdo_print(struct obdo *obd)
182 sprintf(buf, "id: "LPX64"\ngrp: "LPX64"\natime: "LPU64"\nmtime: "LPU64
183 "\nctime: "LPU64"\nsize: "LPU64"\nblocks: "LPU64
184 "\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n"
185 "misc: %x\nnlink: %d,\nvalid "LPX64"\n",
186 obd->o_id, obd->o_gr, obd->o_atime, obd->o_mtime, obd->o_ctime,
187 obd->o_size, obd->o_blocks, obd->o_blksize, obd->o_mode,
188 obd->o_uid, obd->o_gid, obd->o_flags, obd->o_misc,
189 obd->o_nlink, obd->o_valid);
194 #define BAD_VERBOSE (-999999999)
196 #define N2D_OFF 0x100 /* So we can tell between error codes and devices */
198 static int do_name2dev(char *func, char *name)
200 struct obd_ioctl_data data;
205 data.ioc_inllen1 = strlen(name) + 1;
206 data.ioc_inlbuf1 = name;
208 IOC_PACK(func, data);
209 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NAME2DEV, buf);
212 IOC_UNPACK(func, data);
214 return data.ioc_dev + N2D_OFF;
218 * resolve a device name to a device number.
219 * supports a number, $name or %uuid.
221 int parse_devname(char *func, char *name)
228 if (name[0] == '$' || name[0] == '%') {
230 rc = do_name2dev(func, name);
233 printf("Name %s is device %d\n", name, ret);
235 printf("No device found for name %s: %s\n",
239 /* Assume it's a number. This means that bogus strings become
240 * 0. I might care about that some day. */
241 ret = strtoul(name, NULL, 0);
242 //printf("Selected device %d\n", ret);
249 lsm_string (struct lov_stripe_md *lsm)
251 static char buffer[4096];
253 int space = sizeof (buffer);
260 nob = snprintf(p, space, LPX64, lsm->lsm_object_id);
264 if (lsm->lsm_stripe_count != 0) {
265 nob = snprintf (p, space, "=%u#%u",
266 lsm->lsm_stripe_size,
267 lsm->lsm_stripe_count);
271 for (i = 0; i < lsm->lsm_stripe_count; i++) {
272 nob = snprintf (p, space, "@%u:"LPX64,
273 lsm->lsm_oinfo[i].loi_ost_idx,
274 lsm->lsm_oinfo[i].loi_id);
280 if (space == 0) { /* probable overflow */
281 fprintf (stderr, "lsm_string() overflowed buffer\n");
289 reset_lsmb (union lsm_buffer *lsmb)
291 memset (lsmb->space, 0, sizeof (lsmb->space));
292 lsmb->lsm.lsm_magic = LOV_MAGIC;
296 parse_lsm (union lsm_buffer *lsmb, char *string)
298 struct lov_stripe_md *lsm = &lsmb->lsm;
303 * object_id[=size#count[@offset:id]*]
308 lsm->lsm_object_id = strtoull (string, &end, 0);
320 lsm->lsm_stripe_size = strtoul (string, &end, 0);
329 lsm->lsm_stripe_count = strtoul (string, &end, 0);
334 if (*string == 0) /* don't have to specify obj ids */
337 for (i = 0; i < lsm->lsm_stripe_count; i++) {
341 lsm->lsm_oinfo[i].loi_ost_idx = strtoul(string, &end, 0);
345 lsm->lsm_oinfo[i].loi_id = strtoull(string, &end, 0);
355 char *jt_cmdname(char *func)
357 static char buf[512];
360 sprintf(buf, "%s-%d", func, thread);
367 #define difftime(a, b) \
368 ((a)->tv_sec - (b)->tv_sec + \
369 ((a)->tv_usec - (b)->tv_usec) / 1000000.0)
371 static int be_verbose(int verbose, struct timeval *next_time,
372 __u64 num, __u64 *next_num, int num_total)
379 if (next_time != NULL)
380 gettimeofday(&now, NULL);
382 /* A positive verbosity means to print every X iterations */
384 (next_num == NULL || num >= *next_num || num >= num_total)) {
385 *next_num += verbose;
387 next_time->tv_sec = now.tv_sec - verbose;
388 next_time->tv_usec = now.tv_usec;
393 /* A negative verbosity means to print at most each X seconds */
394 if (verbose < 0 && next_time != NULL &&
395 difftime(&now, next_time) >= 0.0){
396 next_time->tv_sec = now.tv_sec - verbose;
397 next_time->tv_usec = now.tv_usec;
406 static int get_verbose(char *func, const char *arg)
411 if (!arg || arg[0] == 'v')
413 else if (arg[0] == 's' || arg[0] == 'q')
416 verbose = (int)strtoul(arg, &end, 0);
418 fprintf(stderr, "error: %s: bad verbose option '%s'\n",
419 jt_cmdname(func), arg);
425 printf("Print status every %d seconds\n", -verbose);
426 else if (verbose == 1)
427 printf("Print status every operation\n");
428 else if (verbose > 1)
429 printf("Print status every %d operations\n", verbose);
434 int do_disconnect(char *func, int verbose)
436 cur_device = MAX_OBD_DEVICES;
440 static void shmem_setup(void)
442 /* Create new segment */
443 int shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600);
446 fprintf(stderr, "Can't create shared data: %s\n",
451 /* Attatch to new segment */
452 shared_data = (struct shared_data *)shmat(shmid, NULL, 0);
454 if (shared_data == (struct shared_data *)(-1)) {
455 fprintf(stderr, "Can't attach shared data: %s\n",
461 /* Mark segment as destroyed, so it will disappear when we exit.
462 * Forks will inherit attached segments, so we should be OK.
464 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
465 fprintf(stderr, "Can't destroy shared data: %s\n",
470 static inline void shmem_reset(int total_threads)
472 if (shared_data == NULL)
475 memset(shared_data, 0, sizeof(*shared_data));
476 pthread_mutex_init(&shared_data->mutex, NULL);
477 pthread_cond_init(&shared_data->cond, NULL);
479 memset(counter_snapshot, 0, sizeof(counter_snapshot));
481 shared_data->barrier = total_threads;
484 static inline void shmem_bump(void)
486 static int bumped_running;
488 if (shared_data == NULL || thread <= 0 || thread > MAX_THREADS)
490 pthread_mutex_lock(&shared_data->mutex);
491 shared_data->counters[thread - 1]++;
493 shared_data->running++;
494 pthread_mutex_unlock(&shared_data->mutex);
498 static void shmem_snap(int total_threads, int live_threads)
500 struct timeval this_time;
507 if (shared_data == NULL || total_threads > MAX_THREADS)
510 pthread_mutex_lock(&shared_data->mutex);
511 memcpy(counter_snapshot[0], shared_data->counters,
512 total_threads * sizeof(counter_snapshot[0][0]));
513 running = shared_data->running;
514 pthread_mutex_unlock(&shared_data->mutex);
516 gettimeofday(&this_time, NULL);
518 for (i = 0; i < total_threads; i++) {
519 long long this_count =
520 counter_snapshot[0][i] - counter_snapshot[1][i];
522 if (this_count != 0) {
528 secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) -
529 (prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
532 live_threads == total_threads &&
533 secs > 0.0) /* someone screwed with the time? */
534 printf("%d/%d Total: %f/second\n", non_zero, total_threads, total / secs);
536 memcpy(counter_snapshot[1], counter_snapshot[0],
537 total_threads * sizeof(counter_snapshot[0][0]));
538 prev_time = this_time;
540 running == total_threads)
544 extern command_t cmdlist[];
546 static int do_device(char *func, char *devname)
548 struct obd_ioctl_data data;
551 memset(&data, 0, sizeof(data));
553 dev = parse_devname(func, devname);
561 int jt_obd_device(int argc, char **argv)
564 do_disconnect(argv[0], 1);
569 rc = do_device(argv[0], argv[1]);
573 int jt_obd_connect(int argc, char **argv)
578 int jt_obd_disconnect(int argc, char **argv)
583 return do_disconnect(argv[0], 0);
586 int jt_opt_device(int argc, char **argv)
594 rc = do_device("device", argv[1]);
597 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
599 ret = do_disconnect(argv[0], 0);
606 static void parent_sighandler (int sig)
611 int jt_opt_threads(int argc, char **argv)
615 struct sigaction sigact;
616 struct sigaction saveact1;
617 struct sigaction saveact2;
618 __u64 threads, next_thread;
627 threads = strtoull(argv[1], &end, 0);
628 if (*end || threads > MAX_THREADS) {
629 fprintf(stderr, "error: %s: invalid thread count '%s'\n",
630 jt_cmdname(argv[0]), argv[1]);
634 verbose = get_verbose(argv[0], argv[2]);
635 if (verbose == BAD_VERBOSE)
639 printf("%s: starting "LPD64" threads on device %s running %s\n",
640 argv[0], threads, argv[3], argv[4]);
642 shmem_reset(threads);
644 sigemptyset(&sigset);
645 sigaddset(&sigset, SIGALRM);
646 sigaddset(&sigset, SIGCHLD);
647 sigprocmask(SIG_BLOCK, &sigset, &saveset);
652 for (i = 1, next_thread = verbose; i <= threads; i++) {
655 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
656 strerror(rc = errno));
658 } else if (rc == 0) {
659 sigprocmask(SIG_SETMASK, &saveset, NULL);
661 argv[2] = "--device";
662 return jt_opt_device(argc - 2, argv + 2);
663 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
664 printf("%s: thread #%d (PID %d) started\n",
669 if (!thread) { /* parent process */
670 int live_threads = threads;
672 sigemptyset(&sigset);
673 sigemptyset(&sigact.sa_mask);
674 sigact.sa_handler = parent_sighandler;
677 sigaction(SIGALRM, &sigact, &saveact1);
678 sigaction(SIGCHLD, &sigact, &saveact2);
680 while (live_threads > 0) {
684 if (verbose < 0) /* periodic stats */
690 while (live_threads > 0) {
691 ret = waitpid(0, &status, WNOHANG);
696 fprintf(stderr, "error: %s: wait - %s\n",
697 argv[0], strerror(errno));
703 * This is a hack. We _should_ be able
704 * to use WIFEXITED(status) to see if
705 * there was an error, but it appears
706 * to be broken and it always returns 1
709 int err = WEXITSTATUS(status);
710 if (err || WIFSIGNALED(status))
712 "%s: PID %d had rc=%d\n",
719 /* Show stats while all threads running */
721 shmem_snap(threads, live_threads);
723 sigaction(SIGCHLD, &saveact2, NULL);
724 sigaction(SIGALRM, &saveact1, NULL);
726 sigprocmask(SIG_SETMASK, &saveset, NULL);
730 int jt_opt_net(int argc, char **argv)
741 rc = jt_ptl_network (2, arg2);
744 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
749 int jt_obd_no_transno(int argc, char **argv)
751 struct obd_ioctl_data data;
759 IOC_PACK(argv[0], data);
760 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NO_TRANSNO, buf);
762 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
763 strerror(rc = errno));
768 int jt_obd_set_readonly(int argc, char **argv)
770 struct obd_ioctl_data data;
778 IOC_PACK(argv[0], data);
779 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SET_READONLY, buf);
781 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
782 strerror(rc = errno));
787 int jt_obd_abort_recovery(int argc, char **argv)
789 struct obd_ioctl_data data;
797 IOC_PACK(argv[0], data);
798 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_ABORT_RECOVERY, buf);
800 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
801 strerror(rc = errno));
805 static int is_number(char *str)
809 if (*str == '-' || *str == '+')
812 if (!strncmp(str, "0x", 2))
819 for (i = 0; i < len; i++)
820 if (!isdigit(str[i]))
825 static int str2ugid(char *str, uint32_t *uid, uint32_t *gid)
831 p = strchr(str, ':');
856 static void ugid2str(char *uidname, char *gidname, uint32_t uid, uint32_t gid)
863 snprintf(uidname, 128, "%s", pwd->pw_name);
865 snprintf(uidname, 128, "%d", uid);
869 snprintf(gidname, 128, "%s", grp->gr_name);
871 snprintf(uidname, 128, "%d", gid);
874 #define SQUASH_IOC_SIZE (4 * 4 + sizeof(ptl_nid_t))
875 int jt_obd_root_squash(int argc, char **argv)
877 struct obd_ioctl_data data;
878 char mybuf[SQUASH_IOC_SIZE];
879 uint32_t *dir, *uid, *gid;
888 memset(mybuf, 0, sizeof(mybuf));
889 dir = (uint32_t *) mybuf;
892 nid = (ptl_nid_t *) (dir + 4);
898 if (str2ugid(argv[1], uid, gid)) {
899 fprintf(stderr, "error: %s: can't parse ugid %s\n",
900 jt_cmdname(argv[0]), argv[1]);
904 if (ptl_parse_nid(nid, argv[2])) {
906 "error: %s: can't parse nid %s\n",
907 jt_cmdname(argv[0]), argv[2]);
914 data.ioc_inllen1= SQUASH_IOC_SIZE;
915 data.ioc_inlbuf1 = mybuf;
917 IOC_PACK(argv[0], data);
918 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_ROOT_SQUASH, buf);
919 IOC_UNPACK(argv[0], data);
921 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
922 strerror(rc = errno));
923 else if (argc == 1) {
924 char uidname[128], gidname[128];
925 char nidstr[256] = {0, };
927 ugid2str(uidname, gidname, *uid, *gid);
928 ptl_nid2str(nidstr, *nid);
929 printf("squash (root:root) => (%s:%s), except nid %s\n",
930 uidname, gidname, nidstr);
936 int jt_get_version(int argc, char **argv)
940 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
945 memset(buf, 0, sizeof(buf));
946 data->ioc_version = OBD_IOCTL_VERSION;
947 data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
948 data->ioc_len = obd_ioctl_packlen(data);
950 rc = l2_ioctl(OBD_DEV_ID, OBD_GET_VERSION, buf);
952 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
953 strerror(rc = errno));
955 printf("Lustre version: %s\n", data->ioc_bulk);
958 printf("lctl version: %s\n", BUILD_VERSION);
962 int jt_obd_list(int argc, char **argv)
965 char buf[MAX_STRING_SIZE];
966 FILE *fp = fopen(DEVICES_LIST, "r");
969 fprintf(stderr, "error: %s: %s could not open file "
971 jt_cmdname(argv[0]), strerror(rc = errno));
978 while (fgets(buf, sizeof(buf), fp) != NULL)
986 /* Get echo client's stripe meta-data for the given object
988 int jt_obd_get_stripe (int argc, char **argv)
990 struct obd_ioctl_data data;
998 id = strtoull (argv[1], &end, 0);
1000 fprintf (stderr, "Error: %s: invalid object id '%s'\n",
1001 jt_cmdname (argv[0]), argv[1]);
1005 memset (&lsm_buffer, 0, sizeof (lsm_buffer));
1008 data.ioc_obdo1.o_id = id;
1009 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1010 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1011 data.ioc_pbuf1 = (char *)&lsm_buffer;
1012 data.ioc_plen1 = sizeof (lsm_buffer);
1014 IOC_PACK(argv[0], data);
1015 rc = l2_ioctl(OBD_DEV_ID, ECHO_IOC_GET_STRIPE, buf);
1016 IOC_UNPACK(argv[0], data);
1019 fprintf (stderr, "Error: %s: rc %d(%s)\n",
1020 jt_cmdname (argv[0]), rc, strerror (errno));
1024 printf ("%s\n", lsm_string (&lsm_buffer.lsm));
1029 /* Set stripe meta-data for 1 or more objects. Object must be new to
1030 * this echo client instance.
1032 int jt_obd_set_stripe (int argc, char **argv)
1034 struct obd_ioctl_data data;
1040 if (argc < 2 || argc > 3)
1043 rc = parse_lsm (&lsm_buffer, argv[1]);
1045 fprintf (stderr, "error: %s: invalid object '%s'\n",
1046 jt_cmdname (argv[0]), argv[1]);
1051 count = strtol (argv[2], &end, 0);
1053 fprintf (stderr, "error: %s: invalid count '%s'\n",
1054 jt_cmdname (argv[0]), argv[1]);
1059 for (i = 0; i < count; i++) {
1061 data.ioc_obdo1.o_id = lsm_buffer.lsm.lsm_object_id + i;
1062 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1063 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1064 data.ioc_pbuf1 = (char *)&lsm_buffer;
1065 data.ioc_plen1 = sizeof (lsm_buffer);
1067 IOC_PACK (argv[0], data);
1068 rc = l2_ioctl (OBD_DEV_ID, ECHO_IOC_SET_STRIPE, buf);
1069 IOC_UNPACK (argv[0], data);
1072 fprintf (stderr, "Error: %s: rc %d(%s)\n",
1073 jt_cmdname (argv[0]), rc, strerror (errno));
1081 /* Clear stripe meta-data info for an object on this echo-client instance
1083 int jt_obd_unset_stripe (int argc, char **argv)
1085 struct obd_ioctl_data data;
1093 id = strtoull (argv[1], &end, 0);
1095 fprintf (stderr, "error: %s: invalid object id '%s'\n",
1096 jt_cmdname (argv[0]), argv[1]);
1101 data.ioc_obdo1.o_id = id;
1102 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1103 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1105 IOC_PACK (argv[0], data);
1106 rc = l2_ioctl (OBD_DEV_ID, ECHO_IOC_SET_STRIPE, buf);
1107 IOC_UNPACK (argv[0], data);
1110 fprintf (stderr, "Error: %s: rc %d(%s)\n",
1111 jt_cmdname (argv[0]), rc, strerror (errno));
1116 /* Create one or more objects, arg[4] may describe stripe meta-data. If
1117 * not, defaults assumed. This echo-client instance stashes the stripe
1118 * object ids. Use get_stripe on this node to print full lsm and
1119 * set_stripe on another node to cut/paste between nodes.
1121 int jt_obd_create(int argc, char **argv)
1123 struct obd_ioctl_data data;
1124 struct timeval next_time;
1125 __u64 count = 1, next_count, base_id = 0;
1126 int verbose = 1, mode = 0100644, rc = 0, i, valid_lsm = 0;
1130 if (argc < 2 || argc > 5)
1133 count = strtoull(argv[1], &end, 0);
1135 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1136 jt_cmdname(argv[0]), argv[1]);
1141 mode = strtoul(argv[2], &end, 0);
1143 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1144 jt_cmdname(argv[0]), argv[2]);
1147 if (!(mode & S_IFMT))
1152 verbose = get_verbose(argv[0], argv[3]);
1153 if (verbose == BAD_VERBOSE)
1158 reset_lsmb (&lsm_buffer); /* will set default */
1160 rc = parse_lsm (&lsm_buffer, argv[4]);
1162 fprintf(stderr, "error: %s: invalid lsm '%s'\n",
1163 jt_cmdname(argv[0]), argv[4]);
1166 base_id = lsm_buffer.lsm.lsm_object_id;
1170 printf("%s: "LPD64" objects\n", jt_cmdname(argv[0]), count);
1171 gettimeofday(&next_time, NULL);
1172 next_time.tv_sec -= verbose;
1174 for (i = 1, next_count = verbose; i <= count; i++) {
1175 data.ioc_obdo1.o_mode = mode;
1176 data.ioc_obdo1.o_id = base_id;
1177 data.ioc_obdo1.o_uid = 0;
1178 data.ioc_obdo1.o_gid = 0;
1179 data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE |
1180 OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID;
1183 data.ioc_plen1 = sizeof lsm_buffer;
1184 data.ioc_pbuf1 = (char *)&lsm_buffer;
1187 IOC_PACK(argv[0], data);
1188 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CREATE, buf);
1189 IOC_UNPACK(argv[0], data);
1192 fprintf(stderr, "error: %s: #%d - %s\n",
1193 jt_cmdname(argv[0]), i, strerror(rc = errno));
1196 if (!(data.ioc_obdo1.o_valid & OBD_MD_FLID)) {
1197 fprintf(stderr, "error: %s: objid not valid #%d:"LPX64"\n",
1198 jt_cmdname(argv[0]), i, data.ioc_obdo1.o_valid);
1203 if (be_verbose(verbose, &next_time, i, &next_count, count))
1204 printf("%s: #%d is object id "LPX64"\n",
1205 jt_cmdname(argv[0]), i, data.ioc_obdo1.o_id);
1210 int jt_obd_setattr(int argc, char **argv)
1212 struct obd_ioctl_data data;
1220 data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0);
1222 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1223 jt_cmdname(argv[0]), argv[1]);
1226 data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], &end, 0);
1228 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1229 jt_cmdname(argv[0]), argv[2]);
1232 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
1234 IOC_PACK(argv[0], data);
1235 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, buf);
1237 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1238 strerror(rc = errno));
1243 int jt_obd_test_setattr(int argc, char **argv)
1245 struct obd_ioctl_data data;
1246 struct timeval start, next_time;
1247 __u64 i, count, next_count;
1253 if (argc < 2 && argc > 4)
1257 count = strtoull(argv[1], &end, 0);
1259 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1260 jt_cmdname(argv[0]), argv[1]);
1265 verbose = get_verbose(argv[0], argv[2]);
1266 if (verbose == BAD_VERBOSE)
1271 if (argv[3][0] == 't') {
1272 objid = strtoull(argv[3] + 1, &end, 0);
1274 objid += thread - 1;
1276 objid = strtoull(argv[3], &end, 0);
1278 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1279 jt_cmdname(argv[0]), argv[3]);
1284 gettimeofday(&start, NULL);
1285 next_time.tv_sec = start.tv_sec - verbose;
1286 next_time.tv_usec = start.tv_usec;
1288 printf("%s: setting "LPD64" attrs (objid "LPX64"): %s",
1289 jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec));
1291 for (i = 1, next_count = verbose; i <= count; i++) {
1292 data.ioc_obdo1.o_id = objid;
1293 data.ioc_obdo1.o_mode = S_IFREG;
1294 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
1295 IOC_PACK(argv[0], data);
1296 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, &data);
1299 fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n",
1300 jt_cmdname(argv[0]), i, errno, strerror(rc = errno));
1304 (verbose, &next_time, i, &next_count, count))
1305 printf("%s: set attr #"LPD64"\n",
1306 jt_cmdname(argv[0]), i);
1314 gettimeofday(&end, NULL);
1316 diff = difftime(&end, &start);
1320 printf("%s: "LPD64" attrs in %.3fs (%.3f attr/s): %s",
1321 jt_cmdname(argv[0]), i, diff, i / diff,
1322 ctime(&end.tv_sec));
1328 int jt_obd_destroy(int argc, char **argv)
1330 struct obd_ioctl_data data;
1331 struct timeval next_time;
1332 __u64 count = 1, next_count;
1339 if (argc < 2 || argc > 4)
1342 id = strtoull(argv[1], &end, 0);
1344 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1345 jt_cmdname(argv[0]), argv[1]);
1349 count = strtoull(argv[2], &end, 0);
1352 "error: %s: invalid iteration count '%s'\n",
1353 jt_cmdname(argv[0]), argv[2]);
1359 verbose = get_verbose(argv[0], argv[3]);
1360 if (verbose == BAD_VERBOSE)
1364 printf("%s: "LPD64" objects\n", jt_cmdname(argv[0]), count);
1365 gettimeofday(&next_time, NULL);
1366 next_time.tv_sec -= verbose;
1368 for (i = 1, next_count = verbose; i <= count; i++, id++) {
1369 data.ioc_obdo1.o_id = id;
1370 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1371 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1373 IOC_PACK(argv[0], data);
1374 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_DESTROY, buf);
1375 IOC_UNPACK(argv[0], data);
1378 fprintf(stderr, "error: %s: objid "LPX64": %s\n",
1379 jt_cmdname(argv[0]), id, strerror(rc = errno));
1383 if (be_verbose(verbose, &next_time, i, &next_count, count))
1384 printf("%s: #%d is object id "LPX64"\n",
1385 jt_cmdname(argv[0]), i, id);
1391 int jt_obd_getattr(int argc, char **argv)
1393 struct obd_ioctl_data data;
1401 data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0);
1403 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1404 jt_cmdname(argv[0]), argv[1]);
1407 /* to help obd filter */
1408 data.ioc_obdo1.o_mode = 0100644;
1409 data.ioc_obdo1.o_valid = (obd_valid)~0ULL;
1410 printf("%s: object id "LPX64"\n", jt_cmdname(argv[0]),data.ioc_obdo1.o_id);
1412 IOC_PACK(argv[0], data);
1413 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, buf);
1414 IOC_UNPACK(argv[0], data);
1416 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1417 strerror(rc = errno));
1419 printf("%s: object id "LPX64", mode %o\n", jt_cmdname(argv[0]),
1420 data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
1425 int jt_obd_test_getattr(int argc, char **argv)
1427 struct obd_ioctl_data data;
1428 struct timeval start, next_time;
1429 __u64 i, count, next_count;
1435 if (argc < 2 || argc > 4)
1439 count = strtoull(argv[1], &end, 0);
1441 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1442 jt_cmdname(argv[0]), argv[1]);
1447 verbose = get_verbose(argv[0], argv[2]);
1448 if (verbose == BAD_VERBOSE)
1453 if (argv[3][0] == 't') {
1454 objid = strtoull(argv[3] + 1, &end, 0);
1456 objid += thread - 1;
1458 objid = strtoull(argv[3], &end, 0);
1460 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1461 jt_cmdname(argv[0]), argv[3]);
1466 gettimeofday(&start, NULL);
1467 next_time.tv_sec = start.tv_sec - verbose;
1468 next_time.tv_usec = start.tv_usec;
1470 printf("%s: getting "LPD64" attrs (objid "LPX64"): %s",
1471 jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec));
1473 for (i = 1, next_count = verbose; i <= count; i++) {
1474 data.ioc_obdo1.o_id = objid;
1475 data.ioc_obdo1.o_mode = S_IFREG;
1476 data.ioc_obdo1.o_valid = (obd_valid)~0ULL;
1477 IOC_PACK(argv[0], data);
1478 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data);
1481 fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n",
1482 jt_cmdname(argv[0]), i, errno, strerror(rc = errno));
1486 (verbose, &next_time, i, &next_count, count))
1487 printf("%s: got attr #"LPD64"\n",
1488 jt_cmdname(argv[0]), i);
1496 gettimeofday(&end, NULL);
1498 diff = difftime(&end, &start);
1502 printf("%s: "LPD64" attrs in %.3fs (%.3f attr/s): %s",
1503 jt_cmdname(argv[0]), i, diff, i / diff,
1504 ctime(&end.tv_sec));
1509 int jt_obd_test_brw(int argc, char **argv)
1511 struct obd_ioctl_data data;
1512 struct timeval start, next_time;
1513 __u64 count, next_count, len, stride, thr_offset = 0, objid = 3;
1514 int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1;
1516 int repeat_offset = 0;
1517 unsigned long long ull;
1518 int nthr_per_obj = 0;
1523 if (argc < 2 || argc > 7) {
1524 fprintf(stderr, "error: %s: bad number of arguments: %d\n",
1525 jt_cmdname(argv[0]), argc);
1529 /* make each thread write to a different offset */
1530 count = strtoull(argv[1], &end, 0);
1533 fprintf(stderr, "error: %s: bad iteration count '%s'\n",
1534 jt_cmdname(argv[0]), argv[1]);
1539 if (argv[2][0] == 'w' || argv[2][0] == '1')
1541 /* else it's a read */
1542 if (argv[2][0] != 0)
1543 for (i = 1; argv[2][i] != 0; i++)
1544 switch (argv[2][i]) {
1554 fprintf (stderr, "Can't parse cmd '%s'\n",
1561 verbose = get_verbose(argv[0], argv[3]);
1562 if (verbose == BAD_VERBOSE)
1567 pages = strtoul(argv[4], &end, 0);
1569 fprintf(stderr, "error: %s: bad page count '%s'\n",
1570 jt_cmdname(argv[0]), argv[4]);
1576 (n = strtol(argv[5], &end, 0)) > 0 &&
1578 (ull = strtoull(end + 1, &end, 0)) > 0 &&
1582 } else if (thread &&
1583 argv[5][0] == 't') {
1585 objid = strtoull(argv[5] + 1, &end, 0);
1588 objid = strtoull(argv[5], &end, 0);
1591 fprintf(stderr, "error: %s: bad objid '%s'\n",
1592 jt_cmdname(argv[0]), argv[5]);
1599 /* communicate the 'type' of brw test and batching to echo_client.
1600 * don't start. we'd love to refactor this lctl->echo_client
1602 data.ioc_pbuf1 = (void *)1;
1606 switch(argv[6][0]) {
1607 case 'g': /* plug and unplug */
1608 data.ioc_pbuf1 = (void *)2;
1609 data.ioc_plen1 = strtoull(argv[6] + 1, &end,
1612 case 'p': /* prep and commit */
1613 data.ioc_pbuf1 = (void *)3;
1614 data.ioc_plen1 = strtoull(argv[6] + 1, &end,
1618 fprintf(stderr, "error: %s: batching '%s' "
1619 "needs to specify 'p' or 'g'\n",
1620 jt_cmdname(argv[0]), argv[6]);
1625 fprintf(stderr, "error: %s: bad batching '%s'\n",
1626 jt_cmdname(argv[0]), argv[6]);
1629 data.ioc_plen1 *= PAGE_SIZE;
1632 len = pages * PAGE_SIZE;
1636 pthread_mutex_lock (&shared_data->mutex);
1637 if (nthr_per_obj != 0) {
1638 /* threads interleave */
1639 obj_idx = (thread - 1)/nthr_per_obj;
1641 stride *= nthr_per_obj;
1642 thr_offset = ((thread - 1) % nthr_per_obj) * len;
1643 if (thr_offset == 0)
1644 shared_data->offsets[obj_idx] = stride;
1646 /* threads disjoint */
1647 thr_offset = (thread - 1) * len;
1650 shared_data->barrier--;
1651 if (shared_data->barrier == 0)
1652 pthread_cond_broadcast(&shared_data->cond);
1654 pthread_cond_wait(&shared_data->cond,
1655 &shared_data->mutex);
1657 pthread_mutex_unlock (&shared_data->mutex);
1661 data.ioc_obdo1.o_id = objid;
1662 data.ioc_obdo1.o_mode = S_IFREG;
1663 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLFLAGS;
1664 data.ioc_obdo1.o_flags = (verify ? OBD_FL_DEBUG_CHECK : 0);
1666 data.ioc_count = len;
1667 data.ioc_offset = (repeat_offset ? 0 : thr_offset);
1669 gettimeofday(&start, NULL);
1670 next_time.tv_sec = start.tv_sec - verbose;
1671 next_time.tv_usec = start.tv_usec;
1674 printf("%s: %s "LPU64"x%d pages (obj "LPX64", off "LPU64"): %s",
1675 jt_cmdname(argv[0]), write ? "writing" : "reading", count,
1676 pages, objid, data.ioc_offset, ctime(&start.tv_sec));
1678 cmd = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
1679 for (i = 1, next_count = verbose; i <= count; i++) {
1680 data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS|OBD_MD_FLGRANT);
1681 IOC_PACK(argv[0], data);
1682 rc = l2_ioctl(OBD_DEV_ID, cmd, buf);
1685 fprintf(stderr, "error: %s: #%d - %s on %s\n",
1686 jt_cmdname(argv[0]), i, strerror(rc = errno),
1687 write ? "write" : "read");
1689 } else if (be_verbose(verbose, &next_time,i, &next_count,count))
1690 printf("%s: %s number %d @ "LPD64":"LPU64" for %d\n",
1691 jt_cmdname(argv[0]), write ? "write" : "read", i,
1692 data.ioc_obdo1.o_id, data.ioc_offset,
1693 (int)(pages * PAGE_SIZE));
1695 if (!repeat_offset) {
1696 if (stride == len) {
1697 data.ioc_offset += stride;
1698 } else if (i < count) {
1699 pthread_mutex_lock (&shared_data->mutex);
1700 data.ioc_offset = shared_data->offsets[obj_idx];
1701 shared_data->offsets[obj_idx] += len;
1702 pthread_mutex_unlock (&shared_data->mutex);
1712 gettimeofday(&end, NULL);
1714 diff = difftime(&end, &start);
1718 printf("%s: %s %dx%d pages in %.3fs (%.3f MB/s): %s",
1719 jt_cmdname(argv[0]), write ? "wrote" : "read",
1721 ((double)i * pages * getpagesize()) /
1723 ctime(&end.tv_sec));
1729 int jt_obd_lov_getconfig(int argc, char **argv)
1731 struct obd_ioctl_data data;
1732 struct lov_desc desc;
1733 struct obd_uuid *uuidarray;
1744 fd = open(path, O_RDONLY);
1746 fprintf(stderr, "open \"%s\" failed: %s\n", path,
1751 memset(&desc, 0, sizeof(desc));
1752 obd_str2uuid(&desc.ld_uuid, argv[1]);
1753 desc.ld_tgt_count = ((OBD_MAX_IOCTL_BUFFER-sizeof(data)-sizeof(desc)) /
1754 (sizeof(*uuidarray) + sizeof(*obdgens)));
1757 uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
1759 fprintf(stderr, "error: %s: no memory for %d uuid's\n",
1760 jt_cmdname(argv[0]), desc.ld_tgt_count);
1764 obdgens = calloc(desc.ld_tgt_count, sizeof(*obdgens));
1766 fprintf(stderr, "error: %s: no memory for %d generation #'s\n",
1767 jt_cmdname(argv[0]), desc.ld_tgt_count);
1772 data.ioc_inllen1 = sizeof(desc);
1773 data.ioc_inlbuf1 = (char *)&desc;
1774 data.ioc_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
1775 data.ioc_inlbuf2 = (char *)uuidarray;
1776 data.ioc_inllen3 = desc.ld_tgt_count * sizeof(*obdgens);
1777 data.ioc_inlbuf3 = (char *)obdgens;
1779 if (obd_ioctl_pack(&data, &buf, max)) {
1780 fprintf(stderr, "error: %s: invalid ioctl\n",
1781 jt_cmdname(argv[0]));
1785 rc = ioctl(fd, OBD_IOC_LOV_GET_CONFIG, buf);
1786 if (rc == -ENOSPC) {
1791 fprintf(stderr, "error: %s: ioctl error: %s\n",
1792 jt_cmdname(argv[0]), strerror(rc = errno));
1794 struct obd_uuid *uuidp;
1798 if (obd_ioctl_unpack(&data, buf, max)) {
1799 fprintf(stderr, "error: %s: invalid reply\n",
1800 jt_cmdname(argv[0]));
1804 printf("default_stripe_count: %u\n",
1805 desc.ld_default_stripe_count);
1806 printf("default_stripe_size: "LPU64"\n",
1807 desc.ld_default_stripe_size);
1808 printf("default_stripe_offset: "LPU64"\n",
1809 desc.ld_default_stripe_offset);
1810 printf("default_stripe_pattern: %u\n", desc.ld_pattern);
1811 printf("obd_count: %u\n", desc.ld_tgt_count);
1812 printf("OBDS:\tobdidx\t\tobdgen\t\t obduuid\n");
1815 for (i = 0; i < desc.ld_tgt_count; i++, uuidp++, genp++)
1816 printf("\t%6u\t%14u\t\t %s\n", i, *genp, (char *)uuidp);
1827 int jt_obd_test_ldlm(int argc, char **argv)
1829 struct obd_ioctl_data data;
1836 IOC_PACK(argv[0], data);
1837 rc = l2_ioctl(OBD_DEV_ID, IOC_LDLM_TEST, buf);
1839 fprintf(stderr, "error: %s: test failed: %s\n",
1840 jt_cmdname(argv[0]), strerror(rc = errno));
1844 int jt_obd_dump_ldlm(int argc, char **argv)
1846 struct obd_ioctl_data data;
1853 IOC_PACK(argv[0], data);
1854 rc = l2_ioctl(OBD_DEV_ID, IOC_LDLM_DUMP, buf);
1856 fprintf(stderr, "error: %s failed: %s\n",
1857 jt_cmdname(argv[0]), strerror(rc = errno));
1861 int jt_obd_ldlm_regress_start(int argc, char **argv)
1864 struct obd_ioctl_data data;
1865 char argstring[200];
1866 int i, count = sizeof(argstring) - 1;
1872 argstring[0] = '\0';
1873 for (i = 1; i < argc; i++) {
1874 strncat(argstring, " ", count);
1876 strncat(argstring, argv[i], count);
1877 count -= strlen(argv[i]);
1880 if (strlen(argstring)) {
1881 data.ioc_inlbuf1 = argstring;
1882 data.ioc_inllen1 = strlen(argstring) + 1;
1885 IOC_PACK(argv[0], data);
1886 rc = l2_ioctl(OBD_DEV_ID, IOC_LDLM_REGRESS_START, buf);
1888 fprintf(stderr, "error: %s: test failed: %s\n",
1889 jt_cmdname(argv[0]), strerror(rc = errno));
1894 int jt_obd_ldlm_regress_stop(int argc, char **argv)
1897 struct obd_ioctl_data data;
1903 IOC_PACK(argv[0], data);
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;
1921 /* reuse offset for 'active' */
1922 data.ioc_offset = flag;
1924 IOC_PACK(argv[0], data);
1925 rc = l2_ioctl(OBD_DEV_ID, IOC_OSC_SET_ACTIVE, buf);
1927 fprintf(stderr, "error: %s: failed: %s\n",
1928 jt_cmdname(argv[0]), strerror(rc = errno));
1933 int jt_obd_deactivate(int argc, char **argv)
1935 return do_activate(argc, argv, 0);
1938 int jt_obd_activate(int argc, char **argv)
1940 return do_activate(argc, argv, 1);
1943 int jt_obd_recover(int argc, char **argv)
1946 struct obd_ioctl_data data;
1953 data.ioc_inllen1 = strlen(argv[1]) + 1;
1954 data.ioc_inlbuf1 = argv[1];
1957 IOC_PACK(argv[0], data);
1958 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CLIENT_RECOVER, buf);
1960 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1961 strerror(rc = errno));
1967 int jt_obd_mdc_lookup(int argc, char **argv)
1969 struct obd_ioctl_data data;
1970 char *parent, *child;
1971 int rc, fd, verbose = 1;
1973 if (argc < 3 || argc > 4)
1979 verbose = get_verbose(argv[0], argv[3]);
1983 data.ioc_inllen1 = strlen(child) + 1;
1984 data.ioc_inlbuf1 = child;
1986 IOC_PACK(argv[0], data);
1988 fd = open(parent, O_RDONLY);
1990 fprintf(stderr, "open \"%s\" failed: %s\n", parent,
1995 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
1997 fprintf(stderr, "error: %s: ioctl error: %s\n",
1998 jt_cmdname(argv[0]), strerror(rc = errno));
2003 IOC_UNPACK(argv[0], data);
2004 printf("%s: mode %o uid %d gid %d\n", child,
2005 data.ioc_obdo1.o_mode, data.ioc_obdo1.o_uid,
2006 data.ioc_obdo1.o_gid);
2012 int jt_obd_finish_gns(int argc, char **argv)
2016 struct obd_ioctl_data data;
2023 fd = open(mtpt, O_RDONLY);
2025 fprintf(stderr, "open \"%s\" failed: %s\n", mtpt,
2031 IOC_PACK(argv[0], data);
2032 rc = ioctl(fd, IOC_MDC_FINISH_GNS, buf);
2034 fprintf(stderr, "error: %s(%s) ioctl error: %s\n",
2035 jt_cmdname(argv[0]), mtpt, strerror(rc = errno));
2042 int jt_obd_close_uuid(int argc, char **argv)
2045 struct obd_ioctl_data data;
2048 fprintf(stderr, "usage: %s <uuid> <net-type>\n", argv[0]);
2052 nal = ptl_name2nal(argv[2]);
2055 fprintf (stderr, "Can't parse NAL %s\n", argv[2]);
2060 data.ioc_inllen1 = strlen(argv[1]) + 1;
2061 data.ioc_inlbuf1 = argv[1];
2064 IOC_PACK(argv[0], data);
2065 rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CLOSE_UUID, buf);
2067 fprintf(stderr, "IOC_PORTAL_CLOSE_UUID failed: %s\n",
2075 int jt_cfg_record(int argc, char **argv)
2077 struct obd_ioctl_data data;
2085 data.ioc_inllen1 = strlen(argv[1]) + 1;
2086 data.ioc_inlbuf1 = argv[1];
2088 IOC_PACK(argv[0], data);
2089 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_RECORD, buf);
2092 ptl_set_cfg_record_cb(obd_record);
2094 fprintf(stderr, "OBD_IOC_RECORD failed: %s\n",
2101 int jt_cfg_parse(int argc, char **argv)
2103 struct obd_ioctl_data data;
2111 data.ioc_inllen1 = strlen(argv[1]) + 1;
2112 data.ioc_inlbuf1 = argv[1];
2114 IOC_PACK(argv[0], data);
2115 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_PARSE, buf);
2117 fprintf(stderr, "OBD_IOC_PARSE failed: %s\n",
2124 int jt_cfg_dump_log(int argc, char **argv)
2126 struct obd_ioctl_data data;
2134 data.ioc_inllen1 = strlen(argv[1]) + 1;
2135 data.ioc_inlbuf1 = argv[1];
2137 IOC_PACK(argv[0], data);
2138 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_DUMP_LOG, buf);
2140 fprintf(stderr, "OBD_IOC_DUMP_LOG failed: %s\n",
2146 int jt_cfg_clear_log(int argc, char **argv)
2148 struct obd_ioctl_data data;
2156 data.ioc_inllen1 = strlen(argv[1]) + 1;
2157 data.ioc_inlbuf1 = argv[1];
2159 IOC_PACK(argv[0], data);
2160 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CLEAR_LOG, buf);
2162 fprintf(stderr, "OBD_IOC_CLEAR_LOG failed: %s\n",
2170 int jt_cfg_endrecord(int argc, char **argv)
2172 struct obd_ioctl_data data;
2180 if (!jt_recording) {
2181 fprintf(stderr, "Not recording, so endrecord doesn't make "
2186 IOC_PACK(argv[0], data);
2187 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_ENDRECORD, buf);
2190 ptl_set_cfg_record_cb(NULL);
2192 fprintf(stderr, "OBD_IOC_ENDRECORD failed: %s\n",
2198 int jt_llog_catlist(int argc, char **argv)
2200 struct obd_ioctl_data data;
2207 data.ioc_inllen1 = max - size_round(sizeof(data));
2208 IOC_PACK(argv[0], data);
2210 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CATLOGLIST, buf);
2212 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2214 fprintf(stderr, "OBD_IOC_CATLOGLIST failed: %s\n",
2220 int jt_llog_info(int argc, char **argv)
2222 struct obd_ioctl_data data;
2229 data.ioc_inllen1 = strlen(argv[1]) + 1;
2230 data.ioc_inlbuf1 = argv[1];
2231 data.ioc_inllen2 = max - size_round(sizeof(data)) -
2232 size_round(data.ioc_inllen1);
2233 IOC_PACK(argv[0], data);
2235 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf);
2237 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2239 fprintf(stderr, "OBD_IOC_LLOG_INFO failed: %s\n",
2245 int jt_llog_print(int argc, char **argv)
2247 struct obd_ioctl_data data;
2250 if (argc != 2 && argc != 4)
2254 data.ioc_inllen1 = strlen(argv[1]) + 1;
2255 data.ioc_inlbuf1 = argv[1];
2257 data.ioc_inllen2 = strlen(argv[2]) + 1;
2258 data.ioc_inlbuf2 = argv[2];
2259 data.ioc_inllen3 = strlen(argv[3]) + 1;
2260 data.ioc_inlbuf3 = argv[3];
2262 char from[2] = "1", to[3] = "-1";
2263 data.ioc_inllen2 = strlen(from) + 1;
2264 data.ioc_inlbuf2 = from;
2265 data.ioc_inllen3 = strlen(to) + 1;
2266 data.ioc_inlbuf3 = to;
2268 data.ioc_inllen4 = max - size_round(sizeof(data)) -
2269 size_round(data.ioc_inllen1) -
2270 size_round(data.ioc_inllen2) -
2271 size_round(data.ioc_inllen3);
2272 IOC_PACK(argv[0], data);
2274 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_PRINT, buf);
2276 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2278 fprintf(stderr, "OBD_IOC_LLOG_PRINT failed: %s\n",
2284 int jt_llog_cancel(int argc, char **argv)
2286 struct obd_ioctl_data data;
2293 data.ioc_inllen1 = strlen(argv[1]) + 1;
2294 data.ioc_inlbuf1 = argv[1];
2295 data.ioc_inllen2 = strlen(argv[2]) + 1;
2296 data.ioc_inlbuf2 = argv[2];
2297 data.ioc_inllen3 = strlen(argv[3]) + 1;
2298 data.ioc_inlbuf3 = argv[3];
2299 IOC_PACK(argv[0], data);
2301 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
2303 fprintf(stdout, "index %s be canceled.\n", argv[3]);
2305 fprintf(stderr, "OBD_IOC_LLOG_CANCEL failed: %s\n",
2311 int jt_llog_check(int argc, char **argv)
2313 struct obd_ioctl_data data;
2316 if (argc != 2 && argc != 4)
2320 data.ioc_inllen1 = strlen(argv[1]) + 1;
2321 data.ioc_inlbuf1 = argv[1];
2323 data.ioc_inllen2 = strlen(argv[2]) + 1;
2324 data.ioc_inlbuf2 = argv[2];
2325 data.ioc_inllen3 = strlen(argv[3]) + 1;
2326 data.ioc_inlbuf3 = argv[3];
2328 char from[2] = "1", to[3] = "-1";
2329 data.ioc_inllen2 = strlen(from) + 1;
2330 data.ioc_inlbuf2 = from;
2331 data.ioc_inllen3 = strlen(to) + 1;
2332 data.ioc_inlbuf3 = to;
2334 data.ioc_inllen4 = max - size_round(sizeof(data)) -
2335 size_round(data.ioc_inllen1) -
2336 size_round(data.ioc_inllen2) -
2337 size_round(data.ioc_inllen3);
2338 IOC_PACK(argv[0], data);
2340 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf);
2342 fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
2344 fprintf(stderr, "OBD_IOC_LLOG_CHECK failed: %s\n",
2349 int jt_llog_remove(int argc, char **argv)
2351 struct obd_ioctl_data data;
2354 if (argc != 3 && argc != 2)
2358 data.ioc_inllen1 = strlen(argv[1]) + 1;
2359 data.ioc_inlbuf1 = argv[1];
2361 data.ioc_inllen2 = strlen(argv[2]) + 1;
2362 data.ioc_inlbuf2 = argv[2];
2364 IOC_PACK(argv[0], data);
2366 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf);
2369 fprintf(stdout, "log %s are removed.\n", argv[2]);
2371 fprintf(stdout, "the log in catalog %s are removed. \n", argv[1]);
2373 fprintf(stderr, "OBD_IOC_LLOG_REMOVE failed: %s\n",
2378 int jt_obd_reint_sync(int argc, char **argv)
2380 struct obd_ioctl_data data;
2386 IOC_PACK(argv[0], data);
2387 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CMOBD_SYNC, buf);
2390 fprintf(stderr, "OBD_IOC_CMOBD_SYNC failed: %s\n",
2397 int jt_obd_cache_on(int argc, char **argv)
2399 struct obd_ioctl_data data;
2405 IOC_PACK(argv[0], data);
2406 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_COBD_CON, buf);
2409 fprintf(stderr, "OBD_IOC_COBD_CON failed: %s\n",
2415 int jt_obd_cache_off(int argc, char **argv)
2417 struct obd_ioctl_data data;
2423 IOC_PACK(argv[0], data);
2424 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_COBD_COFF, buf);
2426 fprintf(stderr, "OBD_IOC_COBD_COFF failed: %s\n",
2431 int jt_obd_snap_add(int argc, char **argv)
2433 struct obd_ioctl_data data;
2440 register_ioc_dev(SMFS_DEV_ID, SMFS_DEV_PATH);
2444 data.ioc_inllen1 = strlen(argv[1]) + 1;
2445 data.ioc_inlbuf1 = argv[1];
2446 data.ioc_inllen2 = strlen(argv[2]) + 2;
2447 data.ioc_inlbuf2 = argv[2];
2449 IOC_PACK(argv[0], data);
2451 rc = l_ioctl(SMFS_DEV_ID, OBD_IOC_SMFS_SNAP_ADD, buf);
2453 unregister_ioc_dev(SMFS_DEV_ID);
2455 fprintf(stderr, "OBD_IOC_SNAP_ADD failed: rc=%s\n",
2461 static void signal_server(int sig)
2463 if (sig == SIGINT) {
2464 do_disconnect("sigint", 1);
2467 fprintf(stderr, "%s: got signal %d\n",
2468 jt_cmdname("sigint"), sig);
2471 int obd_initialize(int argc, char **argv)
2474 register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
2480 void obd_finalize(int argc, char **argv)
2482 struct sigaction sigact;
2484 sigact.sa_handler = signal_server;
2485 sigfillset(&sigact.sa_mask);
2486 sigact.sa_flags = SA_RESTART;
2487 sigaction(SIGINT, &sigact, NULL);
2490 printf("END RECORD\n");
2491 jt_cfg_endrecord(argc, argv);
2494 do_disconnect(argv[0], 1);