4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
33 * Author: Peter J. Braam <braam@clusterfs.com>
34 * Author: Phil Schwan <phil@clusterfs.com>
35 * Author: Andreas Dilger <adilger@clusterfs.com>
36 * Author: Robert Read <rread@clusterfs.com>
39 #include <sys/ioctl.h>
40 #include <sys/socket.h>
43 #include <sys/types.h>
61 #include "lustreapi_internal.h"
62 #include <libcfs/util/list.h>
63 #include <libcfs/util/ioctl.h>
64 #include <libcfs/util/param.h>
65 #include <libcfs/util/parser.h>
66 #include <libcfs/util/string.h>
68 #include <linux/lnet/nidstr.h>
69 #include <linux/lnet/lnetctl.h>
70 #ifdef HAVE_SERVER_SUPPPORT
71 #include <linux/lustre/lustre_barrier_user.h>
72 #include <linux/lustre/lustre_disk.h>
74 #include <linux/lustre/lustre_cfg.h>
75 #include <linux/lustre/lustre_ioctl.h>
76 #include <linux/lustre/lustre_ostid.h>
77 #include <linux/lustre/lustre_param.h>
78 #include <linux/lustre/lustre_ver.h>
80 #include <lustre/lustreapi.h>
82 #define MAX_STRING_SIZE 128
89 #define MAX_THREADS 4096
90 #define MAX_BASE_ID 0xffffffff
91 #define NIDSTRING_LENGTH 64
93 pthread_mutex_t mutex;
97 __u64 counters[MAX_THREADS];
98 __u64 offsets[MAX_THREADS];
102 struct timeval start_time;
103 struct timeval end_time;
107 static struct shared_data *shared_data;
108 static __u64 counter_snapshot[2][MAX_THREADS];
109 static int prev_valid;
110 static struct timeval prev_time;
115 const int nthreads = 1;
118 static int cur_device = -1;
120 int lcfg_ioctl(char *func, int dev_id, struct lustre_cfg *lcfg)
122 struct obd_ioctl_data data;
123 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
126 memset(&data, 0, sizeof(data));
127 data.ioc_dev = cur_device;
128 data.ioc_type = LUSTRE_CFG_TYPE;
129 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
131 data.ioc_pbuf1 = (void *)lcfg;
132 memset(buf, 0, sizeof(rawbuf));
133 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
135 fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(func));
139 rc = l_ioctl(dev_id, OBD_IOC_PROCESS_CFG, buf);
144 static int do_device(char *func, char *devname);
146 static int get_mgs_device(void)
149 static int mgs_device = -1;
151 if (mgs_device == -1) {
154 do_disconnect(NULL, 1);
155 rc = do_device("mgsioc", mgs);
158 "This command must be run on the MGS.\n");
162 mgs_device = cur_device;
167 /* Returns -1 on error with errno set */
168 int lcfg_mgs_ioctl(char *func, int dev_id, struct lustre_cfg *lcfg)
170 struct obd_ioctl_data data;
171 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
174 memset(&data, 0, sizeof(data));
175 rc = data.ioc_dev = get_mgs_device();
178 data.ioc_type = LUSTRE_CFG_TYPE;
179 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
181 data.ioc_pbuf1 = (void *)lcfg;
182 memset(buf, 0, sizeof(rawbuf));
183 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
185 fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(func));
189 rc = l_ioctl(dev_id, OBD_IOC_PARAM, buf);
191 if (rc && errno == ENOSYS)
192 fprintf(stderr, "Make sure cfg_device is set first.\n");
197 char *obdo_print(struct obdo *obd)
201 snprintf(buf, sizeof(buf), "id: %#jx\ngrp: %#jx\natime: %ju\n"
202 "mtime: %ju\nctime: %ju\nsize: %ju\nblocks: %ju"
203 "\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n"
204 "misc: %x\nnlink: %d,\nvalid %#jx\n",
205 (uintmax_t)ostid_id(&obd->o_oi),
206 (uintmax_t)ostid_seq(&obd->o_oi),
207 (uintmax_t)obd->o_atime, (uintmax_t)obd->o_mtime,
208 (uintmax_t)obd->o_ctime, (uintmax_t)obd->o_size,
209 (uintmax_t)obd->o_blocks, obd->o_blksize, obd->o_mode,
210 obd->o_uid, obd->o_gid, obd->o_flags, obd->o_misc,
211 obd->o_nlink, (uintmax_t)obd->o_valid);
215 #define BAD_VERBOSE (-999999999)
217 char *jt_cmdname(char *func)
219 static char buf[512];
222 sprintf(buf, "%s-%d", func, thread);
229 #define difftime(a, b) \
230 ((a)->tv_sec - (b)->tv_sec + \
231 ((a)->tv_usec - (b)->tv_usec) / 1000000.0)
233 static int be_verbose(int verbose, struct timeval *next_time,
234 __u64 num, __u64 *next_num, int num_total)
242 gettimeofday(&now, NULL);
244 /* A positive verbosity means to print every X iterations */
245 if (verbose > 0 && (num >= *next_num || num >= num_total)) {
246 *next_num += verbose;
248 next_time->tv_sec = now.tv_sec - verbose;
249 next_time->tv_usec = now.tv_usec;
254 /* A negative verbosity means to print at most each X seconds */
255 if (verbose < 0 && next_time && difftime(&now, next_time) >= 0.0) {
256 next_time->tv_sec = now.tv_sec - verbose;
257 next_time->tv_usec = now.tv_usec;
265 static int get_verbose(char *func, const char *arg)
270 if (!arg || arg[0] == 'v') {
272 } else if (arg[0] == 's' || arg[0] == 'q') {
275 verbose = (int)strtoul(arg, &end, 0);
277 fprintf(stderr, "error: %s: bad verbose option '%s'\n",
278 jt_cmdname(func), arg);
284 printf("Print status every %d seconds\n", -verbose);
285 else if (verbose == 1)
286 printf("Print status every operation\n");
287 else if (verbose > 1)
288 printf("Print status every %d operations\n", verbose);
293 int do_disconnect(char *func, int verbose)
295 lcfg_set_devname(NULL);
301 static int shmem_setup(void)
303 pthread_mutexattr_t mattr;
304 pthread_condattr_t cattr;
308 /* Create new segment */
309 shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600);
311 fprintf(stderr, "Can't create shared data: %s\n",
316 /* Attatch to new segment */
317 shared_data = (struct shared_data *)shmat(shmid, NULL, 0);
319 if (shared_data == (struct shared_data *)(-1)) {
320 fprintf(stderr, "Can't attach shared data: %s\n",
327 * Mark segment as destroyed, so it will disappear when we exit.
328 * Forks will inherit attached segments, so we should be OK.
330 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
331 fprintf(stderr, "Can't destroy shared data: %s\n",
336 pthread_mutexattr_init(&mattr);
337 pthread_condattr_init(&cattr);
339 rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
341 fprintf(stderr, "Can't set shared mutex attr\n");
345 rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
347 fprintf(stderr, "Can't set shared cond attr\n");
351 pthread_mutex_init(&shared_data->mutex, &mattr);
352 pthread_cond_init(&shared_data->cond, &cattr);
354 pthread_mutexattr_destroy(&mattr);
355 pthread_condattr_destroy(&cattr);
360 static inline void shmem_lock(void)
362 pthread_mutex_lock(&shared_data->mutex);
365 static inline void shmem_unlock(void)
367 pthread_mutex_unlock(&shared_data->mutex);
370 static inline void shmem_wait(void)
372 pthread_cond_wait(&shared_data->cond, &shared_data->mutex);
375 static inline void shmem_wakeup_all(void)
377 pthread_cond_broadcast(&shared_data->cond);
380 static inline void shmem_reset(int total_threads)
385 memset(&shared_data->body, 0, sizeof(shared_data->body));
386 memset(counter_snapshot, 0, sizeof(counter_snapshot));
388 shared_data->stopping = 0;
389 shared_data->body.start_barrier = total_threads;
390 shared_data->body.stop_barrier = total_threads;
393 static inline void shmem_bump(__u32 counter)
395 static bool running_not_bumped = true;
397 if (!shared_data || thread <= 0 || thread > MAX_THREADS)
401 shared_data->body.counters[thread - 1] += counter;
402 if (running_not_bumped) {
403 shared_data->body.thr_running++;
404 running_not_bumped = false;
409 static void shmem_total(int total_threads)
415 if (!shared_data || total_threads > MAX_THREADS)
419 for (i = 0; i < total_threads; i++)
420 total += shared_data->body.counters[i];
422 secs = difftime(&shared_data->body.end_time,
423 &shared_data->body.start_time);
426 printf("Total: total %ju threads %d sec %f %f/second\n",
427 (uintmax_t)total, total_threads, secs, total / secs);
430 static void shmem_snap(int total_threads, int live_threads)
432 struct timeval this_time;
439 if (!shared_data || total_threads > MAX_THREADS)
443 memcpy(counter_snapshot[0], shared_data->body.counters,
444 total_threads * sizeof(counter_snapshot[0][0]));
445 running = shared_data->body.thr_running;
448 gettimeofday(&this_time, NULL);
450 for (i = 0; i < total_threads; i++) {
451 long long this_count =
452 counter_snapshot[0][i] - counter_snapshot[1][i];
454 if (this_count != 0) {
460 secs = difftime(&this_time, &prev_time);
461 if (prev_valid && secs > 1.0) { /* someone screwed with the time? */
462 printf("%d/%d Total: %f/second\n", non_zero, total_threads,
465 memcpy(counter_snapshot[1], counter_snapshot[0],
466 total_threads * sizeof(counter_snapshot[0][0]));
467 prev_time = this_time;
469 if (!prev_valid && running == total_threads) {
471 /* drop counters when all threads were started */
472 memcpy(counter_snapshot[1], counter_snapshot[0],
473 total_threads * sizeof(counter_snapshot[0][0]));
474 prev_time = this_time;
478 static void shmem_stop(void)
483 shared_data->stopping = 1;
486 static void shmem_cleanup(void)
493 pthread_mutex_destroy(&shared_data->mutex);
494 pthread_cond_destroy(&shared_data->cond);
497 static int shmem_running(void)
499 return (!shared_data || !shared_data->stopping);
502 static void shmem_end_time_locked(void)
504 shared_data->body.stop_barrier--;
505 if (shared_data->body.stop_barrier == 0)
506 gettimeofday(&shared_data->body.end_time, NULL);
509 static void shmem_start_time_locked(void)
511 shared_data->body.start_barrier--;
512 if (shared_data->body.start_barrier == 0) {
514 gettimeofday(&shared_data->body.start_time, NULL);
521 static int shmem_setup(void)
526 static inline void shmem_reset(int total_threads)
530 static inline void shmem_bump(__u32 counters)
534 static void shmem_lock(void)
538 static void shmem_unlock(void)
542 static void shmem_cleanup(void)
546 static int shmem_running(void)
552 extern command_t cmdlist[];
554 static int do_device(char *func, char *devname)
558 dev = parse_devname(func, devname, cur_device);
562 lcfg_set_devname(devname);
567 int jt_obd_get_device(void)
572 int jt_obd_device(int argc, char **argv)
580 printf("current device is %d - %s\n",
581 cur_device, lcfg_get_devname() ? : "not set");
584 rc = do_device("device", argv[1]);
588 int jt_opt_device(int argc, char **argv)
596 rc = do_device("device", argv[1]);
599 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
601 ret = do_disconnect(argv[0], 0);
609 static void parent_sighandler(int sig)
613 int jt_opt_threads(int argc, char **argv)
615 static char cmdstr[129];
618 struct sigaction sigact;
619 struct sigaction saveact1;
620 struct sigaction saveact2;
621 unsigned long threads;
625 int report_count = -1;
632 threads = strtoul(argv[1], &end, 0);
635 report_count = strtoul(end + 1, &end, 0);
637 if (*end || threads > MAX_THREADS) {
638 fprintf(stderr, "error: %s: invalid thread count '%s'\n",
639 jt_cmdname(argv[0]), argv[1]);
643 verbose = get_verbose(argv[0], argv[2]);
644 if (verbose == BAD_VERBOSE)
648 snprintf(cmdstr, sizeof(cmdstr), "%s", argv[4]);
649 for (i = 5; i < argc; i++)
650 snprintf(cmdstr + strlen(cmdstr),
651 sizeof(cmdstr) - strlen(cmdstr),
654 printf("%s: starting %ld threads on device %s running %s\n",
655 argv[0], threads, argv[3], cmdstr);
658 shmem_reset(threads);
660 sigemptyset(&sigset);
661 sigaddset(&sigset, SIGALRM);
662 sigaddset(&sigset, SIGCHLD);
663 sigprocmask(SIG_BLOCK, &sigset, &saveset);
667 for (i = 1, next_thread = verbose; i <= threads; i++) {
670 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
671 strerror(rc = errno));
673 } else if (rc == 0) {
674 sigprocmask(SIG_SETMASK, &saveset, NULL);
677 argv[2] = "--device";
678 exit(jt_opt_device(argc - 2, argv + 2));
679 } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
680 printf("%s: thread #%d (PID %d) started\n",
685 if (!thread) { /* parent process */
686 int live_threads = threads;
688 sigemptyset(&sigset);
689 sigemptyset(&sigact.sa_mask);
690 sigact.sa_handler = parent_sighandler;
693 sigaction(SIGALRM, &sigact, &saveact1);
694 sigaction(SIGCHLD, &sigact, &saveact2);
696 while (live_threads > 0) {
700 if (verbose < 0) /* periodic stats */
706 while (live_threads > 0) {
707 ret = waitpid(0, &status, WNOHANG);
713 "error: %s: wait - %s\n",
714 argv[0], strerror(errno));
720 * This is a hack. We _should_ be able
721 * to use WIFEXITED(status) to see if
722 * there was an error, but it appears
723 * to be broken and it always returns 1
726 int err = WEXITSTATUS(status);
728 if (err || WIFSIGNALED(status))
730 "%s: PID %d had rc=%d\n",
739 /* Show stats while all threads running */
741 shmem_snap(threads, live_threads);
742 if (report_count > 0 && --report_count == 0)
746 sigaction(SIGCHLD, &saveact2, NULL);
747 sigaction(SIGALRM, &saveact1, NULL);
750 shmem_total(threads);
751 sigprocmask(SIG_SETMASK, &saveset, NULL);
756 int jt_opt_threads(int argc, char **argv)
758 fprintf(stderr, "%s not-supported in a single-threaded runtime\n",
759 jt_cmdname(argv[0]));
764 int jt_opt_net(int argc, char **argv)
775 rc = jt_ptl_network(2, arg2);
778 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
783 #ifdef HAVE_SERVER_SUPPORT
785 * Place this here so we can build tools that work with
786 * older Lustre versions
788 #ifndef OBD_IOC_NO_TRANSNO
789 #define OBD_IOC_NO_TRANSNO _IOW('f', 140, OBD_IOC_DATA_TYPE)
792 int jt_obd_no_transno(int argc, char **argv)
794 struct obd_ioctl_data data;
795 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
804 memset(buf, 0, sizeof(rawbuf));
806 rc = cfs_get_param_paths(&path, "no_transno");
810 fd = open(path.gl_pathv[0], O_WRONLY);
812 cfs_free_param_data(&path);
816 snprintf(rawbuf, sizeof(rawbuf), "%d", cur_device);
818 count = write(fd, rawbuf, strlen(rawbuf));
822 cfs_free_param_data(&path);
830 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
831 memset(&data, 0, sizeof(data));
832 data.ioc_dev = cur_device;
834 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
836 fprintf(stderr, "error: %s: invalid ioctl\n",
837 jt_cmdname(argv[0]));
840 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_NO_TRANSNO, buf);
842 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
843 strerror(rc = errno));
848 int jt_obd_set_readonly(int argc, char **argv)
850 struct obd_ioctl_data data;
851 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
854 memset(&data, 0, sizeof(data));
855 data.ioc_dev = cur_device;
860 memset(buf, 0, sizeof(rawbuf));
861 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
863 fprintf(stderr, "error: %s: invalid ioctl\n",
864 jt_cmdname(argv[0]));
867 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_SET_READONLY, buf);
869 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
870 strerror(rc = errno));
875 static int obd_abort_recovery(char *cmd, enum obd_abort_recovery_flags flags)
877 struct obd_ioctl_data data = {
878 .ioc_dev = cur_device,
881 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
884 memset(buf, 0, sizeof(rawbuf));
885 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
887 fprintf(stderr, "error: %s: invalid ioctl\n",
891 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_ABORT_RECOVERY, buf);
893 fprintf(stderr, "error: %s: %s\n", jt_cmdname(cmd),
894 strerror(rc = errno));
899 int jt_obd_abort_recovery(int argc, char **argv)
904 return obd_abort_recovery(argv[0], OBD_FLG_ABORT_RECOV_OST);
907 int jt_obd_abort_recovery_mdt(int argc, char **argv)
912 return obd_abort_recovery(argv[0], OBD_FLG_ABORT_RECOV_MDT);
914 #else /* ! HAVE_SERVER_SUPPROT */
915 int jt_obd_no_transno(int argc, char **argv)
920 fprintf(stderr, "error: %s: invalid ioctl\n",
921 jt_cmdname(argv[0]));
925 int jt_obd_set_readonly(int argc, char **argv)
930 fprintf(stderr, "error: %s: invalid ioctl\n",
931 jt_cmdname(argv[0]));
935 int jt_obd_abort_recovery(int argc, char **argv)
940 fprintf(stderr, "error: %s: invalid ioctl\n",
941 jt_cmdname(argv[0]));
945 int jt_obd_abort_recovery_mdt(int argc, char **argv)
950 fprintf(stderr, "error: %s: invalid ioctl\n",
951 jt_cmdname(argv[0]));
954 #endif /* HAVE_SERVER_SUPPORT */
956 int jt_get_version(int argc, char **argv)
964 rc = llapi_get_version_string(version, sizeof(version));
966 printf("Lustre version: %s\n", LUSTRE_VERSION_STRING);
968 printf("Lustre version: %s\n", version);
973 struct jt_fid_space {
979 int jt_obd_alloc_fids(struct jt_fid_space *space, struct lu_fid *fid,
984 if (space->jt_seq == 0 || space->jt_id == space->jt_width) {
985 struct obd_ioctl_data data;
986 char rawbuf[MAX_IOC_BUFLEN];
991 memset(&data, 0, sizeof(data));
992 data.ioc_dev = cur_device;
994 data.ioc_pbuf1 = (char *)&seqnr;
995 data.ioc_plen1 = sizeof(seqnr);
997 data.ioc_pbuf2 = (char *)&max_count;
998 data.ioc_plen2 = sizeof(max_count);
1000 memset(buf, 0, sizeof(rawbuf));
1001 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1003 fprintf(stderr, "error: invalid ioctl rc = %d\n", rc);
1007 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_ECHO_ALLOC_SEQ, buf);
1009 fprintf(stderr, "ioctl error: rc = %d\n", rc);
1013 space->jt_seq = *(__u64 *)data.ioc_pbuf1;
1014 space->jt_width = *(int *)data.ioc_pbuf2;
1017 fid->f_seq = space->jt_seq;
1018 fid->f_oid = space->jt_id;
1021 space->jt_id = space->jt_id + *count;
1022 if (space->jt_id > space->jt_width)
1023 space->jt_id = space->jt_width;
1025 *count = space->jt_id - fid->f_oid;
1029 #define MD_STEP_COUNT 1000
1030 int jt_obd_md_common(int argc, char **argv, int cmd)
1032 struct obd_ioctl_data data;
1033 struct timeval start;
1034 struct timeval end_time;
1035 char rawbuf[MAX_IOC_BUFLEN];
1040 char *parent_basedir = NULL;
1042 int parent_base_id = 0;
1043 int parent_count = 1;
1044 __u64 child_base_id = -1;
1045 int stripe_count = 0;
1046 int stripe_index = -1;
1052 __u64 total_count = 0;
1054 struct jt_fid_space fid_space = {0};
1056 struct option long_opts[] = {
1057 { .val = 'b', .name = "child_base_id",
1058 .has_arg = required_argument },
1059 { .val = 'c', .name = "stripe_count",
1060 .has_arg = required_argument },
1061 { .val = 'd', .name = "parent_basedir",
1062 .has_arg = required_argument },
1063 { .val = 'D', .name = "parent_dircount",
1064 .has_arg = required_argument },
1065 { .val = 'i', .name = "stripe_index", .has_arg = required_argument },
1066 { .val = 'm', .name = "mode", .has_arg = required_argument },
1067 { .val = 'n', .name = "count", .has_arg = required_argument },
1068 { .val = 't', .name = "time", .has_arg = required_argument },
1069 { .val = 'v', .name = "version", .has_arg = no_argument },
1072 while ((c = getopt_long(argc, argv, "b:c:d:D:m:n:t:v",
1073 long_opts, NULL)) >= 0) {
1076 child_base_id = strtoull(optarg, &end, 0);
1079 "error: %s: bad child_base_id '%s'\n",
1080 jt_cmdname(argv[0]), optarg);
1085 stripe_count = strtoul(optarg, &end, 0);
1088 "error: %s: bad stripe count '%s'\n",
1089 jt_cmdname(argv[0]), optarg);
1094 parent_basedir = optarg;
1097 parent_count = strtoul(optarg, &end, 0);
1100 "error: %s: bad parent count '%s'\n",
1101 jt_cmdname(argv[0]), optarg);
1106 stripe_index = strtoul(optarg, &end, 0);
1109 "error: %s: bad stripe index '%s'\n",
1110 jt_cmdname(argv[0]), optarg);
1115 mode = strtoul(optarg, &end, 0);
1117 fprintf(stderr, "error: %s: bad mode '%s'\n",
1118 jt_cmdname(argv[0]), optarg);
1123 total_count = strtoul(optarg, &end, 0);
1124 if (*end || total_count == 0) {
1125 fprintf(stderr, "%s: bad child count '%s'\n",
1126 jt_cmdname(argv[0]), optarg);
1131 seconds = strtoull(optarg, &end, 0);
1133 fprintf(stderr, "error: %s: seconds '%s'\n",
1134 jt_cmdname(argv[0]), optarg);
1143 "error: %s: option '%s' unrecognized\n",
1144 argv[0], argv[optind - 1]);
1149 memset(&data, 0, sizeof(data));
1150 data.ioc_dev = cur_device;
1151 if (child_base_id == -1) {
1154 name = argv[optind];
1157 if (optind < argc) {
1159 "child_base_id and name can not specified at the same time\n");
1164 if (stripe_count == 0 && stripe_index != -1) {
1166 "If stripe_count is 0, stripe_index can not be specified\n");
1170 if (total_count == 0 && seconds == 0) {
1171 fprintf(stderr, "count or seconds needs to be indicated\n");
1175 if (parent_count <= 0) {
1176 fprintf(stderr, "parent count must < 0\n");
1183 /* threads interleave */
1184 if (parent_base_id != -1)
1185 parent_base_id += (thread - 1) % parent_count;
1187 if (child_base_id != -1)
1188 child_base_id += (thread - 1) *
1189 (MAX_BASE_ID / nthreads);
1191 shmem_start_time_locked();
1196 * If parent directory is not specified, try to get the directory
1199 if (!parent_basedir) {
1204 "parent_basedir or name must be indicated!\n");
1207 /*Get directory and name from name*/
1208 last_lash = strrchr(name, '/');
1209 if (!last_lash || name[0] != '/') {
1210 fprintf(stderr, "Can not locate %s\n", name);
1214 if (last_lash == name) {
1215 sprintf(dirname, "%s", "/");
1218 int namelen = (unsigned long)last_lash -
1219 (unsigned long)name + 1;
1220 snprintf(dirname, namelen, "%s", name);
1221 name = last_lash + 1;
1224 data.ioc_pbuf1 = dirname;
1225 data.ioc_plen1 = strlen(dirname);
1227 data.ioc_pbuf2 = name;
1228 data.ioc_plen2 = strlen(name);
1231 data.ioc_pbuf2 = name;
1232 data.ioc_plen2 = strlen(name);
1234 if (parent_base_id > 0)
1235 sprintf(dirname, "%s%d", parent_basedir,
1238 sprintf(dirname, "%s", parent_basedir);
1239 data.ioc_pbuf1 = dirname;
1240 data.ioc_plen1 = strlen(dirname);
1243 if (cmd == ECHO_MD_MKDIR || cmd == ECHO_MD_RMDIR)
1244 create_mode = S_IFDIR;
1246 create_mode = S_IFREG;
1248 data.ioc_obdo1.o_mode = mode | S_IFDIR;
1249 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE |
1250 OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
1251 data.ioc_command = cmd;
1253 gettimeofday(&start, NULL);
1254 while (shmem_running()) {
1255 struct lu_fid fid = { 0 };
1257 if (child_base_id != -1)
1258 data.ioc_obdo2.o_oi.oi.oi_id = child_base_id;
1259 data.ioc_obdo2.o_mode = mode | create_mode;
1260 data.ioc_obdo2.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE |
1261 OBD_MD_FLMODE | OBD_MD_FLFLAGS |
1263 data.ioc_obdo2.o_misc = stripe_count;
1264 data.ioc_obdo2.o_stripe_idx = stripe_index;
1266 if (total_count > 0) {
1267 if ((total_count - count) > MD_STEP_COUNT)
1268 data.ioc_count = MD_STEP_COUNT;
1270 data.ioc_count = total_count - count;
1272 data.ioc_count = MD_STEP_COUNT;
1275 if (cmd == ECHO_MD_CREATE || cmd == ECHO_MD_MKDIR) {
1276 /*Allocate fids for the create */
1277 rc = jt_obd_alloc_fids(&fid_space, &fid,
1280 fprintf(stderr, "Allocate fids error %d.\n",
1284 data.ioc_obdo1.o_oi.oi_fid = fid;
1287 child_base_id += data.ioc_count;
1288 count += data.ioc_count;
1290 memset(buf, 0, sizeof(rawbuf));
1291 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1293 fprintf(stderr, "error: %s: invalid ioctl %d\n",
1294 jt_cmdname(argv[0]), rc);
1298 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_ECHO_MD, buf);
1300 fprintf(stderr, "error: %s: %s\n",
1301 jt_cmdname(argv[0]), strerror(rc = errno));
1304 shmem_bump(data.ioc_count);
1306 gettimeofday(&end_time, NULL);
1307 diff = difftime(&end_time, &start);
1308 if (seconds > 0 && (__u64)diff > seconds)
1311 if (count >= total_count && total_count > 0)
1315 if (count > 0 && version) {
1316 gettimeofday(&end_time, NULL);
1317 diff = difftime(&end_time, &start);
1318 printf("%s: %d in %.3fs (%.3f /s): %s",
1319 jt_cmdname(argv[0]), count, diff,
1320 (double)count / diff, ctime(&end_time.tv_sec));
1326 shmem_end_time_locked();
1333 int jt_obd_test_create(int argc, char **argv)
1335 return jt_obd_md_common(argc, argv, ECHO_MD_CREATE);
1338 int jt_obd_test_mkdir(int argc, char **argv)
1340 return jt_obd_md_common(argc, argv, ECHO_MD_MKDIR);
1343 int jt_obd_test_destroy(int argc, char **argv)
1345 return jt_obd_md_common(argc, argv, ECHO_MD_DESTROY);
1348 int jt_obd_test_rmdir(int argc, char **argv)
1350 return jt_obd_md_common(argc, argv, ECHO_MD_RMDIR);
1353 int jt_obd_test_lookup(int argc, char **argv)
1355 return jt_obd_md_common(argc, argv, ECHO_MD_LOOKUP);
1358 int jt_obd_test_setxattr(int argc, char **argv)
1360 return jt_obd_md_common(argc, argv, ECHO_MD_SETATTR);
1363 int jt_obd_test_md_getattr(int argc, char **argv)
1365 return jt_obd_md_common(argc, argv, ECHO_MD_GETATTR);
1368 int jt_obd_create(int argc, char **argv)
1370 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1371 struct obd_ioctl_data data;
1372 struct timeval next_time;
1373 __u64 count = 1, next_count, base_id = 1;
1374 int verbose = 1, mode = 0100644, rc = 0, i;
1377 memset(&data, 0, sizeof(data));
1378 data.ioc_dev = cur_device;
1379 if (argc < 2 || argc > 4)
1382 count = strtoull(argv[1], &end, 0);
1384 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1385 jt_cmdname(argv[0]), argv[1]);
1390 mode = strtoul(argv[2], &end, 0);
1392 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1393 jt_cmdname(argv[0]), argv[2]);
1396 if (!(mode & S_IFMT))
1401 verbose = get_verbose(argv[0], argv[3]);
1402 if (verbose == BAD_VERBOSE)
1406 printf("%s: %jd objects\n", jt_cmdname(argv[0]), (uintmax_t)count);
1407 gettimeofday(&next_time, NULL);
1408 next_time.tv_sec -= verbose;
1410 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
1411 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1413 * base_id is 1 so we don't need to worry about it being
1414 * greater than OBIF_MAX_OID
1416 data.ioc_obdo1.o_oi.oi_fid.f_oid = base_id;
1417 data.ioc_obdo1.o_mode = mode;
1418 data.ioc_obdo1.o_uid = 0;
1419 data.ioc_obdo1.o_gid = 0;
1420 data.ioc_obdo1.o_projid = 0;
1421 data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE |
1422 OBD_MD_FLID | OBD_MD_FLUID |
1423 OBD_MD_FLGID | OBD_MD_FLGROUP |
1426 memset(buf, 0, sizeof(rawbuf));
1427 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1429 fprintf(stderr, "error: %s: invalid ioctl\n",
1430 jt_cmdname(argv[0]));
1433 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CREATE, buf);
1434 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
1437 fprintf(stderr, "error: %s: #%d - %s\n",
1438 jt_cmdname(argv[0]), i, strerror(rc = errno));
1441 if (!(data.ioc_obdo1.o_valid & OBD_MD_FLID)) {
1442 fprintf(stderr, "error: %s: oid not valid #%d:%#jx\n",
1443 jt_cmdname(argv[0]), i,
1444 (uintmax_t)data.ioc_obdo1.o_valid);
1449 if (be_verbose(verbose, &next_time, i, &next_count, count))
1450 printf("%s: #%d is object id %#jx\n",
1451 jt_cmdname(argv[0]), i,
1452 (uintmax_t)ostid_id(&data.ioc_obdo1.o_oi));
1458 int jt_obd_setattr(int argc, char **argv)
1460 struct obd_ioctl_data data;
1461 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1467 memset(&data, 0, sizeof(data));
1468 data.ioc_dev = cur_device;
1472 objid = strtoull(argv[1], &end, 0);
1474 fprintf(stderr, "error: %s: objid '%s' is not a number\n",
1475 jt_cmdname(argv[0]), argv[1]);
1479 if (objid >= OBIF_MAX_OID) {
1480 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1481 jt_cmdname(argv[0]), argv[1]);
1485 mode = strtoul(argv[2], &end, 0);
1487 fprintf(stderr, "error: %s: invalid mode '%s'\n",
1488 jt_cmdname(argv[0]), argv[2]);
1492 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
1493 data.ioc_obdo1.o_mode = S_IFREG | mode;
1494 data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
1495 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
1497 memset(buf, 0, sizeof(rawbuf));
1498 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1500 fprintf(stderr, "error: %s: invalid ioctl\n",
1501 jt_cmdname(argv[0]));
1504 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, buf);
1506 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1507 strerror(rc = errno));
1512 int jt_obd_test_setattr(int argc, char **argv)
1514 struct obd_ioctl_data data;
1515 struct timeval start, next_time;
1516 __u64 i, count, next_count;
1517 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1523 if (argc < 2 || argc > 4)
1526 memset(&data, 0, sizeof(data));
1527 data.ioc_dev = cur_device;
1528 count = strtoull(argv[1], &end, 0);
1530 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1531 jt_cmdname(argv[0]), argv[1]);
1536 verbose = get_verbose(argv[0], argv[2]);
1537 if (verbose == BAD_VERBOSE)
1542 if (argv[3][0] == 't') {
1543 objid = strtoull(argv[3] + 1, &end, 0);
1545 objid += thread - 1;
1547 objid = strtoull(argv[3], &end, 0);
1550 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1551 jt_cmdname(argv[0]), argv[3]);
1556 gettimeofday(&start, NULL);
1557 next_time.tv_sec = start.tv_sec - verbose;
1558 next_time.tv_usec = start.tv_usec;
1560 printf("%s: setting %jd attrs (objid %#jx): %s",
1561 jt_cmdname(argv[0]), (uintmax_t)count,
1562 (uintmax_t)objid, ctime(&start.tv_sec));
1564 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
1565 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1566 if (objid >= OBIF_MAX_OID) {
1567 fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
1568 jt_cmdname(argv[0]), (unsigned long long)objid);
1572 data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
1573 data.ioc_obdo1.o_mode = S_IFREG;
1574 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE |
1576 memset(buf, 0, sizeof(rawbuf));
1577 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1579 fprintf(stderr, "error: %s: invalid ioctl\n",
1580 jt_cmdname(argv[0]));
1583 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, &data);
1586 fprintf(stderr, "error: %s: #%jd - %d:%s\n",
1587 jt_cmdname(argv[0]), (uintmax_t)i,
1588 errno, strerror(rc = errno));
1591 if (be_verbose(verbose, &next_time, i, &next_count, count))
1592 printf("%s: set attr #%jd\n",
1593 jt_cmdname(argv[0]), (uintmax_t)i);
1600 gettimeofday(&end, NULL);
1602 diff = difftime(&end, &start);
1606 printf("%s: %jd attrs in %.3fs (%.3f attr/s): %s",
1607 jt_cmdname(argv[0]), (uintmax_t)i, diff,
1608 i / diff, ctime(&end.tv_sec));
1613 int jt_obd_destroy(int argc, char **argv)
1615 struct obd_ioctl_data data;
1616 struct timeval next_time;
1617 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1618 __u64 count = 1, next_count;
1624 memset(&data, 0, sizeof(data));
1625 data.ioc_dev = cur_device;
1626 if (argc < 2 || argc > 4)
1630 id = strtoull(argv[1], &end, 0);
1631 if (*end || id == 0 || errno != 0) {
1632 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1633 jt_cmdname(argv[0]), argv[1]);
1637 count = strtoull(argv[2], &end, 0);
1640 "error: %s: invalid iteration count '%s'\n",
1641 jt_cmdname(argv[0]), argv[2]);
1647 verbose = get_verbose(argv[0], argv[3]);
1648 if (verbose == BAD_VERBOSE)
1652 printf("%s: %jd objects\n", jt_cmdname(argv[0]), (uintmax_t)count);
1653 gettimeofday(&next_time, NULL);
1654 next_time.tv_sec -= verbose;
1656 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
1657 for (i = 1, next_count = verbose; i <= count && shmem_running();
1659 if (id >= OBIF_MAX_OID) {
1660 fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
1661 jt_cmdname(argv[0]), (unsigned long long)id);
1665 data.ioc_obdo1.o_oi.oi_fid.f_oid = id;
1666 data.ioc_obdo1.o_mode = S_IFREG | 0644;
1667 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
1669 memset(buf, 0, sizeof(rawbuf));
1670 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1672 fprintf(stderr, "error: %s: invalid ioctl\n",
1673 jt_cmdname(argv[0]));
1676 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_DESTROY, buf);
1677 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
1680 fprintf(stderr, "error: %s: objid %#jx: %s\n",
1681 jt_cmdname(argv[0]), (uintmax_t)id,
1682 strerror(rc = errno));
1686 if (be_verbose(verbose, &next_time, i, &next_count, count))
1687 printf("%s: #%d is object id %#jx\n",
1688 jt_cmdname(argv[0]), i, (uintmax_t)id);
1694 static int jt_str_to_ost_id(const char *str, struct ost_id *oi)
1699 oid = strtoull(str, &end, 0);
1701 /* If str is a single number then assume old echo
1703 if (oid >= OBIF_MAX_OID)
1706 ostid_set_seq_echo(oi);
1707 oi->oi_fid.f_oid = oid;
1711 return llapi_fid_parse(str, &oi->oi_fid, NULL);
1714 int jt_obd_getattr(int argc, char **argv)
1716 struct obd_ioctl_data data;
1718 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1724 memset(&data, 0, sizeof(data));
1725 data.ioc_dev = cur_device;
1726 oa = &data.ioc_obdo1;
1728 rc = jt_str_to_ost_id(argv[1], &oa->o_oi);
1730 fprintf(stderr, "error: %s: invalid objid of FID '%s'\n",
1731 jt_cmdname(argv[0]), argv[1]);
1735 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1737 memset(buf, 0, sizeof(rawbuf));
1738 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1740 fprintf(stderr, "error: %s: invalid ioctl\n",
1741 jt_cmdname(argv[0]));
1744 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, buf);
1745 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
1747 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
1748 strerror(rc = errno));
1752 #define OP4(bits, name, format, value) \
1754 if ((oa->o_valid & (bits)) == (bits)) \
1755 printf("%s: "format"\n", (name), value); \
1758 #define OPM(bits, member, format) \
1759 OP4(bits, #member, format, (uintmax_t)(oa->o_ ## member))
1761 #define OPO(bits, member) OPM(bits, member, "%#jo")
1762 #define OPU(bits, member) OPM(bits, member, "%ju")
1763 #define OPX(bits, member) OPM(bits, member, "%#jx")
1766 OPX(OBD_MD_FLID | OBD_MD_FLGROUP, oi.oi.oi_id);
1767 OPX(OBD_MD_FLID | OBD_MD_FLGROUP, oi.oi.oi_seq);
1768 OP4(OBD_MD_FLID | OBD_MD_FLGROUP, "oi.oi_fid", DFID, PFID(&oa->o_oi.oi_fid));
1769 OPU(OBD_MD_FLATIME, atime);
1770 OPU(OBD_MD_FLMTIME, mtime);
1771 OPU(OBD_MD_FLCTIME, ctime);
1772 OPU(OBD_MD_FLSIZE, size);
1773 OPU(OBD_MD_FLBLOCKS, blocks);
1774 OPU(OBD_MD_FLBLKSZ, blksize);
1775 OPO(OBD_MD_FLMODE | OBD_MD_FLTYPE, mode);
1776 OPU(OBD_MD_FLUID, uid);
1777 OPU(OBD_MD_FLGID, gid);
1778 OPU(OBD_MD_FLFLAGS, flags);
1779 OPU(OBD_MD_FLNLINK, nlink);
1780 OPX(OBD_MD_FLPARENT | OBD_MD_FLFID, parent_seq);
1781 OPX(OBD_MD_FLPARENT | OBD_MD_FLFID, parent_oid);
1782 OPX(OBD_MD_FLPARENT | OBD_MD_FLFID, parent_ver);
1783 OPU(OBD_MD_LAYOUT_VERSION, layout_version);
1784 OPU(OBD_MD_FLGRANT, grant);
1785 OPU(OBD_MD_FLPROJID, projid);
1786 OPU(OBD_MD_FLDATAVERSION, data_version);
1796 int jt_obd_test_getattr(int argc, char **argv)
1798 struct obd_ioctl_data data;
1799 struct timeval start, next_time;
1800 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1801 __u64 i, count, next_count;
1807 if (argc < 2 || argc > 4)
1810 memset(&data, 0, sizeof(data));
1811 data.ioc_dev = cur_device;
1812 count = strtoull(argv[1], &end, 0);
1814 fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
1815 jt_cmdname(argv[0]), argv[1]);
1820 verbose = get_verbose(argv[0], argv[2]);
1821 if (verbose == BAD_VERBOSE)
1826 if (argv[3][0] == 't') {
1827 objid = strtoull(argv[3] + 1, &end, 0);
1829 objid += thread - 1;
1831 objid = strtoull(argv[3], &end, 0);
1834 fprintf(stderr, "error: %s: invalid objid '%s'\n",
1835 jt_cmdname(argv[0]), argv[3]);
1840 gettimeofday(&start, NULL);
1841 next_time.tv_sec = start.tv_sec - verbose;
1842 next_time.tv_usec = start.tv_usec;
1844 printf("%s: getting %jd attrs (objid %#jx): %s",
1845 jt_cmdname(argv[0]), (uintmax_t)count,
1846 (uintmax_t)objid, ctime(&start.tv_sec));
1848 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
1849 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
1850 if (objid >= OBIF_MAX_OID) {
1851 fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
1852 jt_cmdname(argv[0]), (unsigned long long)objid);
1856 data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
1857 data.ioc_obdo1.o_mode = S_IFREG;
1858 data.ioc_obdo1.o_valid = 0xffffffff;
1859 memset(buf, 0, sizeof(rawbuf));
1860 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1862 fprintf(stderr, "error: %s: invalid ioctl\n",
1863 jt_cmdname(argv[0]));
1866 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data);
1869 fprintf(stderr, "error: %s: #%jd - %d:%s\n",
1870 jt_cmdname(argv[0]), (uintmax_t)i,
1871 errno, strerror(rc = errno));
1874 if (be_verbose(verbose, &next_time, i, &next_count, count))
1875 printf("%s: got attr #%jd\n",
1876 jt_cmdname(argv[0]), (uintmax_t)i);
1883 gettimeofday(&end, NULL);
1885 diff = difftime(&end, &start);
1889 printf("%s: %jd attrs in %.3fs (%.3f attr/s): %s",
1890 jt_cmdname(argv[0]), (uintmax_t)i, diff,
1891 i / diff, ctime(&end.tv_sec));
1898 * test_brw <cnt> count
1899 * <r|w[r(repeat)x(noverify)]> mode
1900 * <q|v|#(print interval)> verbosity
1901 * <npages[+offset]> blocksize
1902 * <[[<interleave_threads>]t(inc obj by thread#)]obj> object
1905 int jt_obd_test_brw(int argc, char **argv)
1907 struct obd_ioctl_data data;
1908 struct timeval start, next_time;
1909 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
1910 __u64 count, next_count, len, stride, thr_offset = 0, objid = 3;
1911 int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1;
1912 int offset_pages = 0;
1914 int repeat_offset = 0;
1915 unsigned long long ull;
1916 int nthr_per_obj = 0;
1921 if (argc < 2 || argc > 7) {
1922 fprintf(stderr, "error: %s: bad number of arguments: %d\n",
1923 jt_cmdname(argv[0]), argc);
1927 count = strtoull(argv[1], &end, 0);
1929 fprintf(stderr, "error: %s: bad iteration count '%s'\n",
1930 jt_cmdname(argv[0]), argv[1]);
1935 if (argv[2][0] == 'w' || argv[2][0] == '1')
1937 /* else it's a read */
1939 if (argv[2][0] != 0)
1940 for (i = 1; argv[2][i] != 0; i++)
1941 switch (argv[2][i]) {
1952 "Can't parse cmd '%s'\n",
1959 verbose = get_verbose(argv[0], argv[3]);
1960 if (verbose == BAD_VERBOSE)
1965 pages = strtoul(argv[4], &end, 0);
1968 offset_pages = strtoul(end + 1, &end, 0);
1970 if (*end != 0 || offset_pages < 0 || offset_pages >= pages) {
1971 fprintf(stderr, "error: %s: bad npages[+offset] parameter '%s'\n",
1972 jt_cmdname(argv[0]), argv[4]);
1978 if (thread && (n = strtol(argv[5], &end, 0)) > 0 &&
1979 *end == 't' && (ull = strtoull(end + 1, &end, 0)) > 0 &&
1983 } else if (thread && argv[5][0] == 't') {
1985 objid = strtoull(argv[5] + 1, &end, 0);
1988 objid = strtoull(argv[5], &end, 0);
1991 fprintf(stderr, "error: %s: bad objid '%s'\n",
1992 jt_cmdname(argv[0]), argv[5]);
1997 memset(&data, 0, sizeof(data));
1998 data.ioc_dev = cur_device;
2001 * communicate the 'type' of brw test and batching to echo_client.
2002 * don't start. we'd love to refactor this lctl->echo_client
2005 data.ioc_pbuf1 = (void *)1;
2009 switch (argv[6][0]) {
2010 case 'g': /* plug and unplug */
2011 data.ioc_pbuf1 = (void *)2;
2012 data.ioc_plen1 = strtoull(argv[6] + 1, &end, 0);
2014 case 'p': /* prep and commit */
2015 data.ioc_pbuf1 = (void *)3;
2016 data.ioc_plen1 = strtoull(argv[6] + 1, &end, 0);
2020 "error: %s: batching '%s' needs to specify 'p' or 'g'\n",
2021 jt_cmdname(argv[0]), argv[6]);
2026 fprintf(stderr, "error: %s: bad batching '%s'\n",
2027 jt_cmdname(argv[0]), argv[6]);
2030 data.ioc_plen1 *= getpagesize();
2033 len = pages * getpagesize();
2034 thr_offset = offset_pages * getpagesize();
2040 if (nthr_per_obj != 0) {
2041 /* threads interleave */
2042 obj_idx = (thread - 1) / nthr_per_obj;
2044 stride *= nthr_per_obj;
2045 if ((thread - 1) % nthr_per_obj == 0) {
2046 shared_data->body.offsets[obj_idx] =
2047 stride + thr_offset;
2049 thr_offset += ((thread - 1) % nthr_per_obj) * len;
2051 /* threads disjoint */
2052 thr_offset += (thread - 1) * len;
2055 shmem_start_time_locked();
2060 ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
2061 if (objid >= OBIF_MAX_OID) {
2062 fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
2063 jt_cmdname(argv[0]), (unsigned long long)objid);
2067 data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
2068 data.ioc_obdo1.o_mode = S_IFREG;
2069 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE |
2070 OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
2071 data.ioc_obdo1.o_flags = (verify ? OBD_FL_DEBUG_CHECK : 0);
2072 data.ioc_count = len;
2073 data.ioc_offset = (repeat_offset ? 0 : thr_offset);
2075 gettimeofday(&start, NULL);
2076 next_time.tv_sec = start.tv_sec - verbose;
2077 next_time.tv_usec = start.tv_usec;
2080 printf("%s: %s %jux%d pages (obj %#jx, off %ju): %s",
2081 jt_cmdname(argv[0]), write ? "writing" : "reading",
2082 (uintmax_t)count, pages, (uintmax_t)objid,
2083 (uintmax_t)data.ioc_offset, ctime(&start.tv_sec));
2085 cmd = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
2086 for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
2087 data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
2088 memset(buf, 0, sizeof(rawbuf));
2089 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2091 fprintf(stderr, "error: %s: invalid ioctl\n",
2092 jt_cmdname(argv[0]));
2095 rc = l_ioctl(OBD_DEV_ID, cmd, buf);
2098 fprintf(stderr, "error: %s: #%d - %s on %s\n",
2099 jt_cmdname(argv[0]), i, strerror(rc = errno),
2100 write ? "write" : "read");
2102 } else if (be_verbose(verbose, &next_time, i,
2103 &next_count, count)) {
2105 printf("%s: %s number %d @ %jd:%ju for %d\n",
2106 jt_cmdname(argv[0]), write ? "write" : "read", i,
2107 (uintmax_t)ostid_id(&data.ioc_obdo1.o_oi),
2108 (uintmax_t)data.ioc_offset,
2109 (int)(pages * getpagesize()));
2113 if (!repeat_offset) {
2115 if (stride == len) {
2116 data.ioc_offset += stride;
2117 } else if (i < count) {
2120 shared_data->body.offsets[obj_idx];
2121 shared_data->body.offsets[obj_idx] += len;
2125 data.ioc_offset += len;
2126 obj_idx = 0; /* avoids an unused var warning */
2135 gettimeofday(&end, NULL);
2137 diff = difftime(&end, &start);
2141 printf("%s: %s %dx%d pages in %.3fs (%.3f MB/s): %s",
2142 jt_cmdname(argv[0]), write ? "wrote" : "read",
2144 ((double)i * pages * getpagesize()) /
2145 (diff * 1048576.0), ctime(&end.tv_sec));
2151 shmem_end_time_locked();
2158 static int do_activate(int argc, char **argv, int flag)
2160 struct obd_ioctl_data data;
2161 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2164 memset(&data, 0, sizeof(data));
2165 data.ioc_dev = cur_device;
2169 /* reuse offset for 'active' */
2170 data.ioc_offset = flag;
2172 memset(buf, 0, sizeof(rawbuf));
2173 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2175 fprintf(stderr, "error: %s: invalid ioctl\n",
2176 jt_cmdname(argv[0]));
2179 rc = l_ioctl(OBD_DEV_ID, IOC_OSC_SET_ACTIVE, buf);
2181 fprintf(stderr, "error: %s: failed: %s\n",
2182 jt_cmdname(argv[0]), strerror(rc = errno));
2188 * Replace nids for given device.
2189 * lctl replace_nids <devicename> <nid1>[,nid2,nid3]
2190 * Command should be started on MGS server.
2191 * Only MGS server should be started (command execution
2192 * returns error in another cases). Command mount
2193 * -t lustre <MDT partition> -o nosvc <mount point>
2194 * can be used for that.
2196 * llogs for MDTs and clients are processed. All
2197 * records copied as is except add_uuid and setup. This records
2198 * are skipped and recorded with new nids and uuid.
2200 * \see mgs_replace_nids
2201 * \see mgs_replace_log
2202 * \see mgs_replace_nids_handler
2204 int jt_replace_nids(int argc, char **argv)
2207 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2208 struct obd_ioctl_data data;
2210 memset(&data, 0, sizeof(data));
2211 data.ioc_dev = get_mgs_device();
2215 data.ioc_inllen1 = strlen(argv[1]) + 1;
2216 data.ioc_inlbuf1 = argv[1];
2218 data.ioc_inllen2 = strlen(argv[2]) + 1;
2219 data.ioc_inlbuf2 = argv[2];
2220 memset(buf, 0, sizeof(rawbuf));
2221 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2223 fprintf(stderr, "error: %s: invalid ioctl\n",
2224 jt_cmdname(argv[0]));
2228 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_REPLACE_NIDS, buf);
2230 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
2231 strerror(rc = errno));
2237 int jt_obd_deactivate(int argc, char **argv)
2239 return do_activate(argc, argv, 0);
2242 int jt_obd_activate(int argc, char **argv)
2244 return do_activate(argc, argv, 1);
2247 int jt_obd_recover(int argc, char **argv)
2249 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2250 struct obd_ioctl_data data;
2253 memset(&data, 0, sizeof(data));
2254 data.ioc_dev = cur_device;
2259 data.ioc_inllen1 = strlen(argv[1]) + 1;
2260 data.ioc_inlbuf1 = argv[1];
2263 memset(buf, 0, sizeof(rawbuf));
2264 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2266 fprintf(stderr, "error: %s: invalid ioctl\n",
2267 jt_cmdname(argv[0]));
2270 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CLIENT_RECOVER, buf);
2272 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
2273 strerror(rc = errno));
2279 int jt_obd_mdc_lookup(int argc, char **argv)
2281 struct obd_ioctl_data data;
2282 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2283 char *parent, *child;
2284 int rc, fd, verbose = 1;
2286 if (argc < 3 || argc > 4)
2292 verbose = get_verbose(argv[0], argv[3]);
2294 memset(&data, 0, sizeof(data));
2295 data.ioc_dev = cur_device;
2297 data.ioc_inllen1 = strlen(child) + 1;
2298 data.ioc_inlbuf1 = child;
2300 memset(buf, 0, sizeof(rawbuf));
2301 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2303 fprintf(stderr, "error: %s: invalid ioctl\n",
2304 jt_cmdname(argv[0]));
2308 fd = open(parent, O_RDONLY);
2310 fprintf(stderr, "open \"%s\" failed: %s\n", parent,
2315 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
2317 fprintf(stderr, "error: %s: ioctl error: %s\n",
2318 jt_cmdname(argv[0]), strerror(rc = errno));
2323 rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
2325 fprintf(stderr, "error: %s: invalid reply\n",
2326 jt_cmdname(argv[0]));
2329 printf("%s: mode %o uid %d gid %d\n",
2330 child, data.ioc_obdo1.o_mode, data.ioc_obdo1.o_uid,
2331 data.ioc_obdo1.o_gid);
2337 #ifdef HAVE_SERVER_SUPPORT
2339 * Clear config logs for given device or filesystem.
2340 * lctl clear_conf <devicename|fsname>
2341 * Command has to be run on MGS node having MGS device mounted with -o
2344 * Configuration logs for filesystem or one particular log is
2345 * processed. New log is created, original log is read, its records
2346 * marked SKIP do not get copied to new log. Others are copied as-is.
2347 * Original file is renamed to log.${time}.bak.
2349 * \see mgs_clear_configs
2350 * \see mgs_replace_log
2351 * \see mgs_clear_config_handler
2353 int jt_lcfg_clear(int argc, char **argv)
2356 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2357 struct obd_ioctl_data data;
2359 memset(&data, 0, sizeof(data));
2360 data.ioc_dev = get_mgs_device();
2364 data.ioc_inllen1 = strlen(argv[1]) + 1;
2365 data.ioc_inlbuf1 = argv[1];
2367 memset(buf, 0, sizeof(rawbuf));
2368 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2370 fprintf(stderr, "error: %s: invalid ioctl\n",
2371 jt_cmdname(argv[0]));
2375 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CLEAR_CONFIGS, buf);
2377 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
2378 strerror(rc = errno));
2384 int jt_lcfg_fork(int argc, char **argv)
2386 struct obd_ioctl_data data;
2387 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2393 memset(&data, 0, sizeof(data));
2394 data.ioc_dev = get_mgs_device();
2395 data.ioc_inllen1 = strlen(argv[1]) + 1;
2396 data.ioc_inlbuf1 = argv[1];
2397 data.ioc_inllen2 = strlen(argv[2]) + 1;
2398 data.ioc_inlbuf2 = argv[2];
2400 memset(buf, 0, sizeof(rawbuf));
2401 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2403 fprintf(stderr, "error: %s: invalid ioctl\n",
2404 jt_cmdname(argv[0]));
2408 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LCFG_FORK, buf);
2410 fprintf(stderr, "error: %s: OBD_IOC_LCFG_FORK failed: %s\n",
2411 jt_cmdname(argv[0]), strerror(errno));
2416 int jt_lcfg_erase(int argc, char **argv)
2418 struct obd_ioctl_data data;
2419 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2423 if (strncmp(argv[2], "-q", strlen("-q")) != 0 &&
2424 strncmp(argv[2], "--quiet", strlen("--quiet")) != 0)
2426 } else if (argc != 2) {
2430 memset(&data, 0, sizeof(data));
2431 data.ioc_dev = get_mgs_device();
2432 data.ioc_inllen1 = strlen(argv[1]) + 1;
2433 data.ioc_inlbuf1 = argv[1];
2435 memset(buf, 0, sizeof(rawbuf));
2436 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2438 fprintf(stderr, "error: %s: invalid ioctl\n",
2439 jt_cmdname(argv[0]));
2443 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LCFG_ERASE, buf);
2445 fprintf(stderr, "error: %s: OBD_IOC_LCFG_ERASE failed: %s\n",
2446 jt_cmdname(argv[0]), strerror(errno));
2450 #else /* !HAVE_SERVER_SUPPORT */
2451 int jt_lcfg_clear(int argc, char **argv)
2456 fprintf(stderr, "error: %s: invalid ioctl\n",
2457 jt_cmdname(argv[0]));
2461 int jt_lcfg_fork(int argc, char **argv)
2466 fprintf(stderr, "error: %s: invalid ioctl\n",
2467 jt_cmdname(argv[0]));
2471 int jt_lcfg_erase(int argc, char **argv)
2476 fprintf(stderr, "error: %s: invalid ioctl\n",
2477 jt_cmdname(argv[0]));
2480 #endif /* HAVE_SERVER_SUPPORT */
2482 enum llog_default_dev_op {
2483 LLOG_DFLT_MGS_SET = 0,
2487 static int llog_default_device(enum llog_default_dev_op op)
2490 static int dflt_dev = -1;
2492 if (op == LLOG_DFLT_MGS_SET && (cur_device == -1)) {
2493 char mgs[] = "$MGS";
2495 rc = do_device("llog_default_device", mgs);
2496 dflt_dev = cur_device;
2498 } else if (op == LLOG_DFLT_DEV_RESET && (dflt_dev != -1)) {
2499 do_disconnect(NULL, 1);
2506 static int llog_catlist_next(int index, char *buf, size_t buflen)
2508 struct obd_ioctl_data data;
2511 memset(&data, 0, sizeof(data));
2512 data.ioc_dev = cur_device;
2513 data.ioc_inllen1 = buflen - __ALIGN_KERNEL(sizeof(data), 8);
2514 data.ioc_count = index;
2515 memset(buf, 0, buflen);
2516 rc = llapi_ioctl_pack(&data, &buf, buflen);
2518 fprintf(stderr, "error: invalid llapi_ioctl_pack: %s\n",
2522 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CATLOGLIST, buf);
2524 fprintf(stderr, "OBD_IOC_CATLOGLIST failed: %s\n",
2528 return ((struct obd_ioctl_data *)buf)->ioc_count;
2531 int jt_llog_catlist(int argc, char **argv)
2533 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2540 if (llog_default_device(LLOG_DFLT_MGS_SET))
2541 return CMD_INCOMPLETE;
2544 start = llog_catlist_next(start, rawbuf, sizeof(rawbuf));
2547 tmp = ((struct obd_ioctl_data *)buf)->ioc_bulk;
2548 if (strlen(tmp) > 0)
2549 fprintf(stdout, "%s", tmp);
2554 llog_default_device(LLOG_DFLT_DEV_RESET);
2559 int jt_llog_info(int argc, char **argv)
2561 const struct option long_opts[] = {
2562 /* Allow optional "--catalog" for compatibility with llog commands. */
2563 { .val = 'c', .name = "catalog", .has_arg = required_argument },
2564 { .val = 'h', .name = "help", .has_arg = no_argument },
2566 struct obd_ioctl_data data = { 0 };
2567 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
2568 char *cmd = argv[0];
2569 char *catalog = NULL;
2572 while ((c = getopt_long(argc, argv, "c:h", long_opts, NULL)) != -1) {
2584 /* support "logname" positional parameter */
2588 "%s: catalog is set, unknown argument '%s'\n",
2593 } else if (!catalog || argc > 1) {
2597 /* Manage default device */
2598 if (llog_default_device(LLOG_DFLT_MGS_SET))
2599 return CMD_INCOMPLETE;
2601 data.ioc_dev = cur_device;
2602 data.ioc_inllen1 = strlen(catalog) + 1;
2603 data.ioc_inlbuf1 = catalog;
2604 data.ioc_inllen2 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
2605 __ALIGN_KERNEL(data.ioc_inllen1, 8);
2606 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2608 fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n",
2609 jt_cmdname(cmd), catalog, strerror(-rc));
2613 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf);
2615 fprintf(stdout, "%s", ((struct obd_ioctl_data *)buf)->ioc_bulk);
2617 fprintf(stderr, "%s: OBD_IOC_LLOG_INFO failed: %s\n",
2618 jt_cmdname(cmd), strerror(errno));
2621 llog_default_device(LLOG_DFLT_DEV_RESET);
2626 int jt_llog_print_cb(const char *record, void *private)
2628 printf("%s\n", record);
2634 llog_process_records(int (record_cb)(const char *record, void *private),
2635 const char *record, void *private, bool reverse)
2643 ptr = strchr(record, '\n');
2646 rc = record_cb(record, private);
2651 } while (ptr && *(ptr + 1));
2653 tmp = (char *)record;
2655 ptr = strrchr(record, '\n');
2660 while ((ptr = strrchr(record, '\n'))) {
2663 rc = record_cb(tmp, private);
2667 rc = record_cb(record, private);
2676 * Iterate over llog records, typically YAML-formatted configuration logs
2678 * \param logname[in] name of llog file or FID
2679 * \param start[in] first record to process
2680 * \param end[in] last record to process (inclusive)
2681 * \param cb[in] callback for records. Return -ve error, or +ve abort.
2682 * \param private[in,out] private data passed to the \a record_cb function
2683 * \param reverse[in] print the llog records from the beginning or the end
2685 * \retval 0 on success
2686 * others handled by the caller
2688 int jt_llog_print_iter(char *logname, long start, long end,
2689 int (record_cb)(const char *record, void *private),
2690 void *private, bool reverse, bool raw)
2692 struct obd_ioctl_data data = { 0 };
2693 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
2694 char startbuf[16], endbuf[16];
2695 static long inc = sizeof(rawbuf) / 128;
2702 data.ioc_dev = cur_device;
2703 data.ioc_inlbuf1 = logname;
2704 data.ioc_inllen1 = strlen(logname) + 1;
2707 * Estimate about 128 characters per configuration record. Not all
2708 * records will be printed in any case, so they should easily fit. If
2709 * not, the kernel will return -EOVERFLOW and ask for fewer records.
2711 * We don't want to request records from the kernel one-at-a-time, as
2712 * it restarts the config llog iteration from the beginning, so we
2713 * fetch multiple records from the kernel per call and split locally.
2715 for (rec = start; rec < end; rec += inc) {
2716 char *record = ((struct obd_ioctl_data *)buf)->ioc_bulk;
2719 snprintf(startbuf, sizeof(startbuf), "%lu", rec);
2720 snprintf(endbuf, sizeof(endbuf), "%lu",
2721 end < rec + inc - 1 ? end : rec + inc - 1);
2723 data.ioc_u32_1 = raw ? 1 : 0;
2724 /* start and end record numbers are passed as ASCII digits */
2725 data.ioc_inlbuf2 = startbuf;
2726 data.ioc_inllen2 = strlen(startbuf) + 1;
2727 data.ioc_inlbuf3 = endbuf;
2728 data.ioc_inllen3 = strlen(endbuf) + 1;
2730 data.ioc_inllen4 = sizeof(rawbuf) -
2731 __ALIGN_KERNEL(sizeof(data), 8) -
2732 __ALIGN_KERNEL(data.ioc_inllen1, 8) -
2733 __ALIGN_KERNEL(data.ioc_inllen2, 8) -
2734 __ALIGN_KERNEL(data.ioc_inllen3, 8);
2735 memset(buf, 0, sizeof(rawbuf));
2736 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2738 fprintf(stderr, "%s: invalid ioctl data\n", logname);
2742 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_PRINT, buf);
2743 if (rc == -EOVERFLOW && inc > 2) {
2748 fprintf(stderr, "%s: OBD_IOC_LLOG_PRINT failed: %s\n",
2749 logname, strerror(errno));
2754 /* There is no "end of list" marker, record was not modified */
2755 if (strcmp(record, logname) == 0)
2758 rc = llog_process_records(record_cb, record, private, reverse);
2767 static int llog_parse_catalog_options(int *argc, char ***argv, char **catalog,
2768 long *start, long *end, int *raw)
2770 const struct option long_opts[] = {
2771 /* the --catalog option is not required, just for consistency */
2772 { .val = 'c', .name = "catalog", .has_arg = required_argument },
2773 { .val = 'e', .name = "end", .has_arg = required_argument },
2774 { .val = 'h', .name = "help", .has_arg = no_argument },
2775 { .val = 'r', .name = "raw", .has_arg = no_argument },
2776 { .val = 's', .name = "start", .has_arg = required_argument },
2778 char *cmd = (*argv)[0];
2782 if (!catalog || !start || !end)
2785 /* now process command line arguments*/
2786 while ((c = getopt_long(*argc, *argv, "c:e:hrs:",
2787 long_opts, NULL)) != -1) {
2793 *end = strtol(optarg, &endp, 0);
2794 if (*endp != '\0') {
2795 fprintf(stderr, "%s: bad end value '%s'\n",
2806 *start = strtol(optarg, &endp, 0);
2807 if (*endp != '\0') {
2808 fprintf(stderr, "%s: bad start value '%s'\n",
2822 * support old optional positional parameters only if they were
2823 * not already specified with named arguments: logname [start [end]]
2828 "%s: logname is set, unknown argument '%s'\n",
2832 *catalog = (*argv)[0];
2837 if (*catalog == NULL) {
2838 fprintf(stderr, "%s: no logname specified\n", cmd);
2845 "%s: --start is set, unknown argument '%s'\n",
2850 *start = strtol((*argv)[0], &endp, 0);
2851 if (*endp != '\0') {
2852 fprintf(stderr, "%s: bad start value '%s'\n",
2862 "%s: --end is set, unknown argument '%s'\n",
2867 *end = strtol((*argv)[0], &endp, 0);
2868 if (*endp != '\0') {
2869 fprintf(stderr, "%s: bad end value '%s'\n",
2877 fprintf(stderr, "%s: unknown argument '%s'\n", cmd, (*argv)[0]);
2881 if (*end != -1 && *end < *start) {
2882 fprintf(stderr, "%s: end '%lu' less than than start '%lu'\n",
2890 int jt_llog_print(int argc, char **argv)
2892 char *catalog = NULL;
2893 long start = 1, end = -1;
2897 rc = llog_parse_catalog_options(&argc, &argv, &catalog, &start, &end,
2902 if (llog_default_device(LLOG_DFLT_MGS_SET))
2903 return CMD_INCOMPLETE;
2905 rc = jt_llog_print_iter(catalog, start, end, jt_llog_print_cb,
2906 NULL, false, !!raw);
2908 llog_default_device(LLOG_DFLT_DEV_RESET);
2914 * Parse catalog, log ID, and optionally a log index with either optional
2915 * arguments or positional arguments. Only the initial catalog argument
2916 * may be positional with other optional arguments.
2918 * The positional arguments option should eventually be phased out.
2920 static int llog_parse_catalog_log_idx(int *argc, char ***argv, const char *opts,
2921 struct obd_ioctl_data *data)
2923 const struct option long_opts[] = {
2924 /* the --catalog option is not required, just for consistency */
2925 { .val = 'c', .name = "catalog", .has_arg = required_argument },
2926 { .val = 'h', .name = "help", .has_arg = no_argument },
2927 { .val = 'i', .name = "log_idx", .has_arg = required_argument },
2928 { .val = 'l', .name = "log_id", .has_arg = required_argument },
2933 if (!data || *argc <= 1)
2936 data->ioc_dev = cur_device;
2938 /* now process command line arguments*/
2939 while ((c = getopt_long(*argc, *argv, opts, long_opts, NULL)) != -1) {
2942 data->ioc_inllen1 = strlen(optarg) + 1;
2943 data->ioc_inlbuf1 = optarg;
2946 data->ioc_inllen3 = strlen(optarg) + 1;
2947 data->ioc_inlbuf3 = optarg;
2949 case 'l': /* The log_id option isn't currently needed for
2950 * cancel as mdt_iocontrol() handles IOC_LLOG_CANCEL,
2951 * but we may as well keep it for now.
2953 data->ioc_inllen2 = strlen(optarg) + 1;
2954 data->ioc_inlbuf2 = optarg;
2965 /* Allow catalog to be specified as first option without --catalog */
2966 if (!data->ioc_inlbuf1 && *argc > 0) {
2967 data->ioc_inlbuf1 = (*argv)[0];
2968 data->ioc_inllen1 = strlen((*argv)[0]) + 1;
2976 int jt_llog_cancel(int argc, char **argv)
2978 struct obd_ioctl_data data = { 0 };
2979 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
2980 char *cmd = argv[0];
2983 /* Manage default device */
2984 if (llog_default_device(LLOG_DFLT_MGS_SET))
2985 return CMD_INCOMPLETE;
2987 /* Parse catalog file (in inlbuf1) and named parameters */
2988 rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hi:l:", &data);
2991 * Handle old positional parameters if not using named parameters,
2992 * either "<catalog> <log_idx>" or "<catalog> <log_id> <log_idx>".
2993 * It was "inlbuf3 = log_idx", and "inlbuf2 = log_id" (ignored by
2994 * config log cancel), and shows why I hate positional parameters.
2997 data.ioc_inllen3 = strlen(argv[0]) + 1;
2998 data.ioc_inlbuf3 = argv[0];
2999 } else if (argc == 2) {
3000 data.ioc_inllen2 = strlen(argv[0]) + 1;
3001 data.ioc_inlbuf2 = argv[0];
3002 data.ioc_inllen3 = strlen(argv[1]) + 1;
3003 data.ioc_inlbuf3 = argv[1];
3006 if (!data.ioc_inlbuf1 || !data.ioc_inlbuf3) {
3007 /* missing mandatory parameters */
3012 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3014 fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n",
3015 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3019 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
3021 fprintf(stderr, "%s: cancel catalog '%s:%s' failed: %s\n",
3022 jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf3,
3026 llog_default_device(LLOG_DFLT_DEV_RESET);
3030 int jt_llog_check(int argc, char **argv)
3032 struct obd_ioctl_data data = { 0 };
3033 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3034 char *catalog = NULL;
3035 char startbuf[16], endbuf[16];
3036 long start = 1, end = -1;
3037 char *cmd = argv[0];
3040 rc = llog_parse_catalog_options(&argc, &argv, &catalog, &start,
3045 if (llog_default_device(LLOG_DFLT_MGS_SET))
3046 return CMD_INCOMPLETE;
3051 data.ioc_dev = cur_device;
3052 data.ioc_inllen1 = strlen(catalog) + 1;
3053 data.ioc_inlbuf1 = catalog;
3055 snprintf(startbuf, sizeof(startbuf), "%lu", start);
3056 snprintf(endbuf, sizeof(endbuf), "%lu", end);
3057 /* start and end record numbers are passed as ASCII digits */
3058 data.ioc_inllen2 = strlen(startbuf) + 1;
3059 data.ioc_inlbuf2 = startbuf;
3060 data.ioc_inllen3 = strlen(endbuf) + 1;
3061 data.ioc_inlbuf3 = endbuf;
3063 data.ioc_inllen4 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
3064 __ALIGN_KERNEL(data.ioc_inllen1, 8) -
3065 __ALIGN_KERNEL(data.ioc_inllen2, 8) -
3066 __ALIGN_KERNEL(data.ioc_inllen3, 8);
3067 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3069 fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n",
3070 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3074 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf);
3076 fprintf(stdout, "%s", ((struct obd_ioctl_data *)buf)->ioc_bulk);
3078 fprintf(stderr, "%s: OBD_IOC_LLOG_CHECK failed: %s\n",
3079 jt_cmdname(cmd), strerror(errno));
3081 llog_default_device(LLOG_DFLT_DEV_RESET);
3085 int jt_llog_remove(int argc, char **argv)
3087 struct obd_ioctl_data data = { 0 };
3088 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3089 char *cmd = argv[0];
3092 if (llog_default_device(LLOG_DFLT_MGS_SET))
3093 return CMD_INCOMPLETE;
3095 rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hl:", &data);
3100 if (data.ioc_inlbuf2) {
3102 "%s: --log_id is set, unknown argument '%s'\n",
3103 jt_cmdname(cmd), argv[0]);
3108 data.ioc_inllen2 = strlen(argv[0]) + 1;
3109 data.ioc_inlbuf2 = argv[0];
3112 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3114 fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n",
3115 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3119 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf);
3121 fprintf(stderr, "%s: cancel catalog '%s:%s' failed: %s\n",
3122 jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf2,
3126 llog_default_device(LLOG_DFLT_DEV_RESET);
3130 static void signal_server(int sig)
3132 if (sig == SIGINT) {
3133 do_disconnect("sigint", 1);
3136 fprintf(stderr, "%s: got signal %d\n", jt_cmdname("sigint"),
3141 int obd_initialize(int argc, char **argv)
3143 if (shmem_setup() != 0)
3146 register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
3151 void obd_finalize(int argc, char **argv)
3153 struct sigaction sigact;
3155 /* sigact initialization */
3156 sigact.sa_handler = signal_server;
3157 sigfillset(&sigact.sa_mask);
3158 sigact.sa_flags = SA_RESTART;
3159 /* coverity[uninit_use_in_call] */
3160 sigaction(SIGINT, &sigact, NULL);
3163 do_disconnect(argv[0], 1);
3167 * Get the index of the last llog record
3169 * logid: [0x3:0xa:0x0]:0
3174 * \param logname[in] pointer to config log name
3176 * \retval > 0 on success
3179 static long llog_last_index(char *logname)
3181 struct obd_ioctl_data data = { 0 };
3182 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3186 data.ioc_dev = cur_device;
3187 data.ioc_inllen1 = strlen(logname) + 1;
3188 data.ioc_inlbuf1 = logname;
3189 data.ioc_inllen2 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
3190 __ALIGN_KERNEL(data.ioc_inllen1, 8);
3191 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3193 fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n",
3194 __func__, logname, strerror(-rc));
3198 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf);
3200 last_index = strstr(((struct obd_ioctl_data *)buf)->ioc_bulk,
3202 return strtol(last_index + 11, NULL, 10);
3210 static char *get_llog_event_name(__u32 cmd)
3212 #ifdef HAVE_SERVER_SUPPORT
3213 struct lcfg_type_data *data;
3215 data = lcfg_cmd2data(cmd);
3217 return data->ltd_name;
3222 static char *get_event_filter(__u32 cmd)
3225 char *filter = NULL;
3228 event_name = get_llog_event_name(cmd);
3230 /* 9 bytes for "event: , " */
3231 len = 9 + strlen(event_name);
3232 filter = malloc(len + 1);
3235 memset(filter, 0, len + 1);
3236 snprintf(filter, len, "event: %s, ", event_name);
3244 * Callback to search ostname in llog
3245 * - { index: 23, event: attach, device: lustre-OST0000-osc, type: osc,
3246 * UUID: lustre-clilov_UUID }
3247 * - { index: 24, event: setup, device: lustre-OST0000-osc,
3248 * UUID: lustre-OST0000_UUID, node: 192.168.0.120@tcp }
3249 * - { index: 25, event: add_osc, device: lustre-clilov,
3250 * ost: lustre-OST0000_UUID, index: 0, gen: 1 }
3252 * \param record[in] pointer to llog record
3253 * \param data[in] pointer to ostname
3255 * \retval 1 if ostname is found
3256 * 0 if ostname is not found
3257 * -ENOENT if ostname is deleted
3259 static int llog_search_ost_cb(const char *record, void *data)
3261 char *ostname = data;
3262 char ost_filter[MAX_STRING_SIZE] = {'\0'};
3263 char *add_osc, *del_osc, *setup, *cleanup;
3265 add_osc = get_event_filter(LCFG_LOV_ADD_OBD);
3266 del_osc = get_event_filter(LCFG_LOV_DEL_OBD);
3267 setup = get_event_filter(LCFG_SETUP);
3268 cleanup = get_event_filter(LCFG_CLEANUP);
3269 if (!add_osc || !del_osc || !setup || !cleanup)
3272 if (ostname && ostname[0])
3273 snprintf(ost_filter, sizeof(ost_filter), " %s,", ostname);
3275 if (strstr(record, ost_filter)) {
3276 if (strstr(record, add_osc) || strstr(record, setup))
3278 if (strstr(record, del_osc) || strstr(record, cleanup))
3291 * Search ost in llog
3293 * \param logname[in] pointer to config log name
3294 * \param last_index[in] the index of the last llog record
3295 * \param ostname[in] pointer to ost name
3297 * \retval 1 if ostname is found
3298 * 0 if ostname is not found
3300 static int llog_search_ost(char *logname, long last_index, char *ostname)
3302 long start, end, inc = MAX_IOC_BUFLEN / 128;
3305 for (end = last_index; end > 1; end -= inc) {
3306 start = end - inc > 0 ? end - inc : 1;
3307 rc = jt_llog_print_iter(logname, start, end, llog_search_ost_cb,
3308 ostname, true, false);
3313 return (rc == 1 ? 1 : 0);
3316 struct llog_del_ost_priv {
3324 * Callback to search and delete ostname in llog
3326 * \param record[in] pointer to llog record
3327 * \param data[in] pointer to ostname
3329 * \retval 1 if ostname is found and entry deleted
3330 * 0 if ostname is not found
3333 static int llog_del_ost_cb(const char *record, void *data)
3335 char ost_filter[MAX_STRING_SIZE] = {'\0'};
3336 char log_idxstr[MAX_STRING_SIZE] = {'\0'};
3337 long int log_idx = 0;
3338 struct llog_del_ost_priv *priv = data;
3339 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3340 struct obd_ioctl_data ioc_data = { 0 };
3343 if (priv->ostname && priv->ostname[0])
3344 snprintf(ost_filter, sizeof(ost_filter), " %s", priv->ostname);
3346 if (!strstr(record, ost_filter))
3349 rc = sscanf(record, "- { index: %ld", &log_idx);
3351 fprintf(stderr, "error: record without index:\n%s\n",
3355 snprintf(log_idxstr, sizeof(log_idxstr), "%ld", log_idx);
3357 ioc_data.ioc_dev = cur_device;
3358 ioc_data.ioc_inllen1 = strlen(priv->logname) + 1;
3359 ioc_data.ioc_inlbuf1 = priv->logname;
3360 ioc_data.ioc_inllen3 = strlen(log_idxstr) + 1;
3361 ioc_data.ioc_inlbuf3 = log_idxstr;
3363 rc = llapi_ioctl_pack(&ioc_data, &buf, sizeof(rawbuf));
3365 fprintf(stderr, "ioctl_pack for catalog '%s' failed: %s\n",
3366 ioc_data.ioc_inlbuf1, strerror(-rc));
3371 fprintf(stdout, "[DRY RUN] cancel catalog '%s:%s':\"%s\"\n",
3372 ioc_data.ioc_inlbuf1, ioc_data.ioc_inlbuf3, record);
3374 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
3376 fprintf(stderr, "cancel catalog '%s:%s' failed: %s\n",
3377 ioc_data.ioc_inlbuf1, ioc_data.ioc_inlbuf3,
3380 fprintf(stdout, "cancel catalog %s log_idx %ld: done\n",
3381 priv->logname, log_idx);
3389 * Search and delete ost in llog
3391 * \param logname[in] pointer to config log name
3392 * \param last_index[in] the index of the last llog record
3393 * \param ostname[in] pointer to ost name
3394 * \param dryrun[in] dry run?
3396 * \retval 1 if ostname is found and deleted
3397 * 0 if ostname is not found
3399 static int llog_del_ost(char *logname, long last_index, char *ostname,
3402 long start, end, inc = MAX_IOC_BUFLEN / 128;
3404 struct llog_del_ost_priv priv = { logname, ostname, false, dryrun };
3406 for (end = last_index; end > 1; end -= inc) {
3407 start = end - inc > 0 ? end - inc : 1;
3408 rc = jt_llog_print_iter(logname, start, end, llog_del_ost_cb,
3409 &priv, true, false);
3415 fprintf(stdout, "del_ost: cancelled %d catalog entries\n",
3418 fprintf(stdout, "del_ost: no catalog entry deleted\n");
3423 struct llog_pool_data {
3424 char lpd_fsname[LUSTRE_MAXFSNAME + 1];
3425 char lpd_poolname[LOV_MAXPOOLNAME + 1];
3426 char lpd_ostname[MAX_OBD_NAME + 1];
3427 enum lcfg_command_type lpd_cmd_type;
3428 bool lpd_pool_exists;
3433 * Called for each formatted line in the config log (within range).
3435 * - { index: 74, event: new_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
3436 * - { index: 77, event: add_pool, device: tfs-clilov, fsname: tfs, pool: tmp,
3437 * ost: tfs-OST0000_UUID }
3438 * - { index: 224, event: remove_pool, device: tfs-clilov, fsname: tfs,
3439 * pool: tmp, ost: tfs-OST0003_UUID }
3440 * - { index: 227, event: del_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
3442 * \param record[in] pointer to llog record
3443 * \param data[in] pointer to llog_pool_data
3445 * \retval 1 if pool or OST is found
3446 * 0 if pool or OST is not found
3447 * -ENOENT if pool or OST is removed
3449 static int llog_search_pool_cb(const char *record, void *data)
3451 struct llog_pool_data *lpd = data;
3452 char pool_filter[MAX_STRING_SIZE] = "";
3453 char *new_pool, *del_pool, *add_pool, *rem_pool;
3455 int fs_pool_len = 0, rc = 0;
3457 new_pool = get_event_filter(LCFG_POOL_NEW);
3458 del_pool = get_event_filter(LCFG_POOL_DEL);
3459 add_pool = get_event_filter(LCFG_POOL_ADD);
3460 rem_pool = get_event_filter(LCFG_POOL_REM);
3461 if (!new_pool || !del_pool || !add_pool || !rem_pool) {
3466 fs_pool_len = 16 + strlen(lpd->lpd_fsname) + strlen(lpd->lpd_poolname);
3467 snprintf(pool_filter, fs_pool_len + 1, "fsname: %s, pool: %s",
3468 lpd->lpd_fsname, lpd->lpd_poolname);
3470 /* search poolname */
3471 found = strstr(record, pool_filter);
3473 (found[fs_pool_len] == ' ' || found[fs_pool_len] == ',')) {
3474 if (strstr(record, new_pool)) {
3475 lpd->lpd_pool_exists = true;
3479 if (strstr(record, del_pool)) {
3480 lpd->lpd_pool_exists = false;
3485 if (lpd->lpd_cmd_type == LCFG_POOL_NEW ||
3486 lpd->lpd_cmd_type == LCFG_POOL_DEL) {
3487 /* In function mgs_pool_cmd(), a pool's pool_new/add
3488 * record will be marked as "SKIP" if its pool_destroy/
3489 * remove record is logged later. That means the "SKIP"
3490 * record won't be printed here and thus lpd_ost_num
3491 * doesn't need to be decreased as well.
3493 if (strstr(record, add_pool))
3495 } else if (lpd->lpd_ostname && lpd->lpd_ostname[0]) {
3496 if (strstr(record, lpd->lpd_ostname)) {
3497 lpd->lpd_pool_exists = true;
3498 if (strstr(record, add_pool)) {
3499 lpd->lpd_ost_num = 1;
3503 if (strstr(record, rem_pool)) {
3504 lpd->lpd_ost_num = 0;
3524 /* Search pool and its ost in llog
3526 * \param logname[in] pointer to config log name
3527 * \param last_index[in] the index of the last llog record
3528 * \param fsname[in] pointer to filesystem name
3529 * \param poolname[in] pointer pool name
3530 * \param ostname[in] pointer to OST name(OSTnnnn-UUID)
3531 * \param cmd[in] pool command type
3533 * \retval < 0 on error
3534 * 0 if pool is empty or OST is not found
3535 * 1 if pool is not empty or OST is found
3537 static int llog_search_pool(char *logname, long last_index, char *fsname,
3538 char *poolname, char *ostname,
3539 enum lcfg_command_type cmd)
3541 struct llog_pool_data lpd;
3542 long start, end, inc = MAX_IOC_BUFLEN / 128;
3545 memset(&lpd, 0, sizeof(lpd));
3546 lpd.lpd_cmd_type = cmd;
3547 lpd.lpd_pool_exists = false;
3548 lpd.lpd_ost_num = 0;
3549 strncpy(lpd.lpd_fsname, fsname, sizeof(lpd.lpd_fsname) - 1);
3550 if (poolname && poolname[0])
3551 strncpy(lpd.lpd_poolname, poolname,
3552 sizeof(lpd.lpd_poolname) - 1);
3553 if (ostname && ostname[0])
3554 strncpy(lpd.lpd_ostname, ostname, sizeof(lpd.lpd_ostname) - 1);
3556 for (end = last_index; end > 1; end -= inc) {
3557 start = end - inc > 0 ? end - inc : 1;
3558 rc = jt_llog_print_iter(logname, start, end,
3559 llog_search_pool_cb, &lpd, true, false);
3561 if (rc == 1 && lpd.lpd_pool_exists)
3562 rc = lpd.lpd_ost_num ? 1 : 0;
3563 else if (rc == -ENOENT && lpd.lpd_pool_exists &&
3575 static bool combined_mgs_mds(char *fsname)
3580 rc = cfs_get_param_paths(&path, "mdt/%s-MDT0000", fsname);
3582 cfs_free_param_data(&path);
3584 if (get_mgs_device() > 0 && !rc)
3591 * if pool is NULL, search ostname in target_obd
3592 * if pool is not NULL:
3593 * - if pool not found returns errno < 0
3594 * - if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty
3595 * - if ostname is not NULL, returns 1 if OST is in pool and 0 if not
3597 int lctl_search_ost(char *fsname, char *poolname, char *ostname,
3598 enum lcfg_command_type cmd)
3600 char logname[MAX_OBD_NAME] = {'\0'};
3603 if (fsname && fsname[0] == '\0')
3608 if (combined_mgs_mds(fsname))
3609 return llapi_search_ost(fsname, poolname, ostname);
3611 /* fetch the last_index of llog record */
3612 snprintf(logname, sizeof(logname), "%s-client", fsname);
3613 last_index = llog_last_index(logname);
3617 /* if pool is NULL, search ostname in target_obd */
3618 if (!poolname && ostname)
3619 return llog_search_ost(logname, last_index, ostname);
3621 return llog_search_pool(logname, last_index, fsname, poolname,
3625 static int check_pool_cmd(enum lcfg_command_type cmd, char *fsname,
3626 char *poolname, char *ostname)
3630 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3631 if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
3632 fprintf(stderr, "Pool %s.%s not found\n",
3638 case LCFG_POOL_NEW: {
3643 fprintf(stderr, "Pool %s.%s already exists\n",
3649 case LCFG_POOL_DEL: {
3655 "Pool %s.%s not empty, please remove all members\n",
3661 case LCFG_POOL_ADD: {
3663 fprintf(stderr, "OST %s is already in pool %s.%s\n",
3664 ostname, fsname, poolname);
3667 rc = lctl_search_ost(fsname, NULL, ostname, cmd);
3669 fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
3675 case LCFG_POOL_REM: {
3677 fprintf(stderr, "OST %s not found in pool %s.%s\n",
3678 ostname, fsname, poolname);
3690 * This check only verifies that the changes have been "pushed out" to
3691 * the client successfully. This involves waiting for a config update,
3692 * and so may fail because of problems in that code or post-command
3693 * network loss. So reporting a warning is appropriate, but not a failure.
3695 static int check_pool_cmd_result(enum lcfg_command_type cmd, char *fsname,
3696 char *poolname, char *ostname)
3702 case LCFG_POOL_NEW: {
3704 rc = lctl_search_ost(fsname, poolname, NULL, cmd);
3710 } while ((rc < 0) && (cpt > 0));
3712 fprintf(stderr, "Pool %s.%s created\n",
3717 fprintf(stderr, "Warning, pool %s.%s not found\n", fsname,
3721 case LCFG_POOL_DEL: {
3723 rc = lctl_search_ost(fsname, poolname, NULL, cmd);
3729 } while ((rc >= 0) && (cpt > 0));
3731 fprintf(stderr, "Pool %s.%s destroyed\n",
3736 fprintf(stderr, "Warning, pool %s.%s still found\n", fsname,
3740 case LCFG_POOL_ADD: {
3742 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3748 } while ((rc != 1) && (cpt > 0));
3750 fprintf(stderr, "OST %s added to pool %s.%s\n",
3751 ostname, fsname, poolname);
3754 fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
3755 ostname, fsname, poolname);
3758 case LCFG_POOL_REM: {
3760 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3766 } while ((rc == 1) && (cpt > 0));
3768 fprintf(stderr, "OST %s removed from pool %s.%s\n",
3769 ostname, fsname, poolname);
3772 fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
3773 ostname, fsname, poolname);
3782 static int check_and_complete_ostname(char *fsname, char *ostname)
3785 char real_ostname[MAX_OBD_NAME + 1];
3788 /* if OST name does not start with fsname, we add it */
3789 /* if not check if the fsname is the right one */
3790 ptr = strchr(ostname, '-');
3792 sprintf(real_ostname, "%s-%s", fsname, ostname);
3793 } else if (strncmp(ostname, fsname, strlen(fsname)) != 0) {
3794 fprintf(stderr, "%s does not start with fsname %s\n",
3798 if (strlen(ostname) > sizeof(real_ostname) - 1)
3801 strncpy(real_ostname, ostname, sizeof(real_ostname));
3804 /* real_ostname is fsname-????? */
3805 ptr = real_ostname + strlen(fsname) + 1;
3806 if (strncmp(ptr, "OST", 3) != 0) {
3807 fprintf(stderr, "%s does not start by %s-OST nor OST\n",
3811 /* real_ostname is fsname-OST????? */
3813 for (i = 0; i < 4; i++) {
3814 if (!isxdigit(*ptr)) {
3816 "ost's index in %s is not an hexa number\n",
3822 /* real_ostname is fsname-OSTXXXX????? */
3823 /* if OST name does not end with _UUID, we add it */
3825 strcat(real_ostname, "_UUID");
3826 } else if (strcmp(ptr, "_UUID") != 0) {
3828 "ostname %s does not end with _UUID\n", ostname);
3831 /* real_ostname is fsname-OSTXXXX_UUID */
3832 strcpy(ostname, real_ostname);
3836 /* returns 0 or -errno */
3837 static int pool_cmd(enum lcfg_command_type cmd, char *cmdname,
3838 char *fullpoolname, char *fsname, char *poolname,
3842 struct obd_ioctl_data data;
3843 struct lustre_cfg_bufs bufs;
3844 struct lustre_cfg *lcfg;
3845 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3847 rc = check_pool_cmd(cmd, fsname, poolname, ostname);
3850 "Can't verify pool command since there is no local MDT or client, proceeding anyhow...\n");
3854 lustre_cfg_bufs_reset(&bufs, NULL);
3855 lustre_cfg_bufs_set_string(&bufs, 0, cmdname);
3856 lustre_cfg_bufs_set_string(&bufs, 1, fullpoolname);
3858 lustre_cfg_bufs_set_string(&bufs, 2, ostname);
3860 lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
3863 lustre_cfg_init(lcfg, cmd, &bufs);
3865 memset(&data, 0, sizeof(data));
3866 rc = data.ioc_dev = get_mgs_device();
3870 data.ioc_type = LUSTRE_CFG_TYPE;
3871 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
3872 lcfg->lcfg_buflens);
3873 data.ioc_pbuf1 = (void *)lcfg;
3875 memset(buf, 0, sizeof(rawbuf));
3876 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3878 fprintf(stderr, "error: %s: invalid ioctl\n",
3879 jt_cmdname(cmdname));
3883 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);
3890 "error: %s: either the pool or file system name is too long (max pool name len is %d and file system name is %d)\n",
3891 jt_cmdname(cmdname), LOV_MAXPOOLNAME, LUSTRE_MAXFSNAME);
3895 "error: %s can contain only alphanumeric characters, underscores, and dashes besides the required '.'\n",
3896 jt_cmdname(cmdname));
3904 int jt_del_ost(int argc, char **argv)
3906 char *fsname = NULL, *ptr, *logname;
3907 char mdtpattern[16], clipattern[16];
3908 char ostname[MAX_OBD_NAME + 1];
3911 int rc, start = 0, dryrun = 0;
3914 static struct option long_opts[] = {
3915 { .val = 'h', .name = "help", .has_arg = no_argument },
3916 { .val = 'n', .name = "dryrun", .has_arg = no_argument },
3917 { .val = 't', .name = "target", .has_arg = required_argument },
3920 while ((c = getopt_long(argc, argv, "hnt:", long_opts, NULL)) != -1) {
3923 fsname = strdup(optarg);
3938 if (llog_default_device(LLOG_DFLT_MGS_SET)) {
3939 rc = CMD_INCOMPLETE;
3943 ptr = strstr(fsname, "-OST");
3950 fprintf(stdout, "del_ost: dry run for target %s\n", fsname);
3953 rc = sscanf(ptr, "OST%04x", &index);
3959 if (strlen(ptr) > sizeof(ostname) - 1) {
3964 snprintf(mdtpattern, sizeof(mdtpattern), "%s-MDT", fsname);
3965 snprintf(clipattern, sizeof(clipattern), "%s-client", fsname);
3966 snprintf(ostname, sizeof(ostname), "%s-%s", fsname, ptr);
3969 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3972 start = llog_catlist_next(start, rawbuf, sizeof(rawbuf));
3975 begin = ((struct obd_ioctl_data *)buf)->ioc_bulk;
3976 if (strlen(begin) == 0)
3979 while ((end = strchr(begin, '\n'))) {
3981 logname = strstr(begin, "config_log: ");
3983 if (logname && (strstr(logname, mdtpattern) ||
3984 strstr(logname, clipattern))) {
3987 fprintf(stdout, "config_log: %s\n", logname);
3989 last_index = llog_last_index(logname);
3990 if (last_index < 0) {
3992 "error with catalog %s: %s\n",
3993 logname, strerror(-last_index));
3997 rc = llog_del_ost(logname, last_index, ostname,
4007 llog_default_device(LLOG_DFLT_DEV_RESET);
4013 #ifdef HAVE_SERVER_SUPPORT
4015 * Format and send the ioctl to the MGS.
4017 * \param cmd IOCTL to send
4018 * \param ret_data void pointer to return anything from
4020 * \param num_args number of arguments to pack into the
4022 * \param argv[] variable number of string arguments
4024 * \retval 0 on success
4026 static int nodemap_cmd(enum lcfg_command_type cmd, void *ret_data,
4027 unsigned int ret_size, ...)
4032 struct lustre_cfg_bufs bufs;
4033 struct obd_ioctl_data data;
4034 struct lustre_cfg *lcfg;
4035 char rawbuf[MAX_IOC_BUFLEN];
4039 lustre_cfg_bufs_reset(&bufs, NULL);
4041 va_start(ap, ret_size);
4042 arg = va_arg(ap, char *);
4044 lustre_cfg_bufs_set_string(&bufs, i, arg);
4046 arg = va_arg(ap, char *);
4050 lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
4053 lustre_cfg_init(lcfg, cmd, &bufs);
4055 memset(&data, 0, sizeof(data));
4056 rc = data.ioc_dev = get_mgs_device();
4060 data.ioc_type = LUSTRE_CFG_TYPE;
4061 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
4062 lcfg->lcfg_buflens);
4063 data.ioc_pbuf1 = (void *)lcfg;
4065 memset(buf, 0, sizeof(rawbuf));
4066 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
4069 "error: invalid ioctl request: %08x errno: %d: %s\n",
4070 cmd, errno, strerror(-rc));
4074 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_NODEMAP, buf);
4077 "error: invalid ioctl: %08x errno: %d: %s\n",
4078 cmd, errno, strerror(errno));
4083 rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
4087 if (ret_size > data.ioc_plen1)
4088 ret_size = data.ioc_plen1;
4090 memcpy(ret_data, data.ioc_pbuf1, ret_size);
4099 * activate nodemap functions
4101 * \param argc number of args
4102 * \param argv[] variable string arguments
4104 * argv[0] 1 for activate or 0 for deactivate
4106 * \retval 0 on success
4108 int jt_nodemap_activate(int argc, char **argv)
4112 rc = nodemap_cmd(LCFG_NODEMAP_ACTIVATE, NULL, 0, argv[0], argv[1],
4126 * \param argc number of args
4127 * \param argv[] variable string arguments
4129 * argv[0] nodemap name
4131 * \retval 0 on success
4133 int jt_nodemap_add(int argc, char **argv)
4137 rc = llapi_nodemap_exists(argv[1]);
4139 fprintf(stderr, "error: %s existing nodemap name\n", argv[1]);
4143 rc = nodemap_cmd(LCFG_NODEMAP_ADD, NULL, 0, argv[0], argv[1], NULL);
4156 * \param argc number of args
4157 * \param argv[] variable string arguments
4159 * argv[0] nodemap name
4161 * \retval 0 on success
4163 int jt_nodemap_del(int argc, char **argv)
4167 rc = llapi_nodemap_exists(argv[1]);
4169 fprintf(stderr, "error: %s not existing nodemap name\n",
4173 rc = nodemap_cmd(LCFG_NODEMAP_DEL, NULL, 0, argv[0], argv[1], NULL);
4184 * test a nid for nodemap membership
4186 * \param argc number of args
4187 * \param argv[] variable string arguments
4189 * argv[0] properly formatted nid
4191 * \retval 0 on success
4193 int jt_nodemap_test_nid(int argc, char **argv)
4195 char rawbuf[MAX_IOC_BUFLEN];
4198 rc = nodemap_cmd(LCFG_NODEMAP_TEST_NID, &rawbuf, sizeof(rawbuf),
4199 argv[0], argv[1], NULL);
4201 printf("%s\n", (char *)rawbuf);
4207 * test a nodemap id pair for mapping
4209 * \param argc number of args
4210 * \param argv[[] variable string arguments
4212 * \retval 0 on success
4214 * The argv array should contain the nodemap name, the id
4215 * to checking the mapping on, and the id type (UID or GID)
4218 int jt_nodemap_test_id(int argc, char **argv)
4220 char rawbuf[MAX_IOC_BUFLEN];
4221 char *nidstr = NULL;
4223 char *typestr = NULL;
4227 static struct option long_opts[] = {
4228 { .val = 'i', .name = "id", .has_arg = required_argument },
4229 { .val = 'n', .name = "nid", .has_arg = required_argument },
4230 { .val = 't', .name = "idtype",
4231 .has_arg = required_argument },
4234 while ((c = getopt_long(argc, argv, "n:t:i:",
4235 long_opts, NULL)) != -1) {
4249 if (!nidstr || !typestr || !idstr) {
4251 "usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>\n");
4255 rc = nodemap_cmd(LCFG_NODEMAP_TEST_ID, &rawbuf, sizeof(rawbuf),
4256 argv[0], nidstr, typestr, idstr, NULL);
4258 printf("%s\n", (char *)rawbuf);
4266 * \param nodemap_range --range string
4267 * \param nid_range nid range string, min_nid:max_nid
4269 * \retval 0 on success
4271 static int parse_nid_range(char *nodemap_range, char *nid_range, int range_len)
4273 char min_nid[LNET_NIDSTR_SIZE + 1];
4274 char max_nid[LNET_NIDSTR_SIZE + 1];
4275 struct list_head nidlist;
4278 INIT_LIST_HEAD(&nidlist);
4280 if (cfs_parse_nidlist(nodemap_range, strlen(nodemap_range),
4283 "error: nodemap_xxx_range: can't parse nid range: %s\n",
4288 rc = cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
4293 "error: nodemap_xxx_range: nid range uses currently unsupported features\n");
4294 else if (rc == -ERANGE)
4296 "error: nodemap_xxx_range: nodemap ranges must be contiguous\n");
4301 snprintf(nid_range, range_len, "%s:%s", min_nid, max_nid);
4307 * add an nid range to a nodemap
4309 * \param argc number of args
4310 * \param argv[] variable string arguments
4312 * --name nodemap name
4313 * --range properly formatted nid range
4315 * \retval 0 on success, -errno on error
4317 int jt_nodemap_add_range(int argc, char **argv)
4319 char *nodemap_name = NULL;
4320 char *nodemap_range = NULL;
4321 char nid_range[2 * LNET_NIDSTR_SIZE + 2];
4325 static struct option long_opts[] = {
4326 { .val = 'n', .name = "name", .has_arg = required_argument },
4327 { .val = 'r', .name = "range", .has_arg = required_argument },
4330 while ((c = getopt_long(argc, argv, "n:r:",
4331 long_opts, NULL)) != -1) {
4334 nodemap_name = optarg;
4337 nodemap_range = optarg;
4342 if (!nodemap_name || !nodemap_range) {
4344 "usage: nodemap_add_range --name <name> --range <range>\n");
4348 rc = parse_nid_range(nodemap_range, nid_range, sizeof(nid_range));
4352 rc = nodemap_cmd(LCFG_NODEMAP_ADD_RANGE, NULL, 0, argv[0],
4353 nodemap_name, nid_range, NULL);
4356 "error: %s: cannot add range '%s' to nodemap '%s': %s\n",
4357 jt_cmdname(argv[0]), nodemap_range, nodemap_name,
4365 * delete an nid range to a nodemap
4367 * \param argc number of args
4368 * \param argv[] variable string arguments
4370 * --name nodemap name
4371 * --range properly formatted nid range
4373 * \retval 0 on success
4375 int jt_nodemap_del_range(int argc, char **argv)
4377 char *nodemap_name = NULL;
4378 char *nodemap_range = NULL;
4379 char nid_range[2 * LNET_NIDSTR_SIZE + 2];
4383 static struct option long_opts[] = {
4384 { .val = 'n', .name = "name", .has_arg = required_argument },
4385 { .val = 'r', .name = "range", .has_arg = required_argument },
4388 while ((c = getopt_long(argc, argv, "n:r:",
4389 long_opts, NULL)) != -1) {
4392 nodemap_name = optarg;
4395 nodemap_range = optarg;
4400 if (!nodemap_name || !nodemap_range) {
4402 "usage: nodemap_del_range --name <name> --range <range>\n");
4406 rc = parse_nid_range(nodemap_range, nid_range, sizeof(nid_range));
4411 rc = nodemap_cmd(LCFG_NODEMAP_DEL_RANGE, NULL, 0, argv[0],
4412 nodemap_name, nid_range, NULL);
4416 "error: %s: cannot delete range '%s' to nodemap '%s': rc = %d\n",
4417 jt_cmdname(argv[0]), nodemap_range, nodemap_name, rc);
4424 * set a fileset on a nodemap
4426 * \param argc number of args
4427 * \param argv[] variable string arguments
4429 * --name nodemap name
4430 * --fileset fileset name
4432 * \retval 0 on success
4434 int jt_nodemap_set_fileset(int argc, char **argv)
4436 char *nodemap_name = NULL;
4437 char *fileset_name = NULL;
4441 static struct option long_opts[] = {
4442 { .val = 'f', .name = "fileset", .has_arg = required_argument },
4443 { .val = 'n', .name = "name", .has_arg = required_argument },
4446 while ((c = getopt_long(argc, argv, "n:f:",
4447 long_opts, NULL)) != -1) {
4450 nodemap_name = optarg;
4453 fileset_name = optarg;
4458 if (!nodemap_name || !fileset_name) {
4460 "usage: nodemap_set_fileset --name <name> --fileset <fileset>\n");
4464 rc = nodemap_cmd(LCFG_NODEMAP_SET_FILESET, NULL, 0, argv[0],
4465 nodemap_name, fileset_name, NULL);
4469 "error: %s: cannot set fileset '%s' on nodemap '%s': rc = %d\n",
4470 jt_cmdname(argv[0]), fileset_name, nodemap_name, rc);
4477 * set SELinux policy info on a nodemap
4479 * \param argc number of args
4480 * \param argv[] variable string arguments
4482 * --name nodemap name
4483 * --sepol SELinux policy info
4485 * \retval 0 on success
4487 int jt_nodemap_set_sepol(int argc, char **argv)
4489 char *nodemap_name = NULL;
4494 static struct option long_options[] = {
4497 .has_arg = required_argument,
4502 .has_arg = required_argument,
4510 while ((c = getopt_long(argc, argv, "n:s:",
4511 long_options, NULL)) != -1) {
4514 nodemap_name = optarg;
4522 if (!nodemap_name || !sepol) {
4524 "usage: nodemap_set_sepol --name <name> --sepol <sepol>\n");
4528 rc = nodemap_cmd(LCFG_NODEMAP_SET_SEPOL, NULL, 0, argv[0],
4529 nodemap_name, sepol, NULL);
4533 "error: %s: cannot set sepol '%s' on nodemap '%s': rc = %d\n",
4534 jt_cmdname(argv[0]), sepol, nodemap_name, rc);
4541 * modify a nodemap's behavior
4543 * \param argc number of args
4544 * \param argv[] variable string arguments
4546 * --name nodemap name
4547 * --property nodemap property to change
4548 * admin, trusted, squash_uid, squash_gid)
4549 * --value value to set property
4551 * \retval 0 on success
4553 int jt_nodemap_modify(int argc, char **argv)
4557 enum lcfg_command_type cmd = 0;
4558 char *nodemap_name = NULL;
4562 static struct option long_opts[] = {
4563 { .val = 'n', .name = "name", .has_arg = required_argument },
4564 { .val = 'p', .name = "property", .has_arg = required_argument },
4565 { .val = 'v', .name = "value", .has_arg = required_argument },
4568 while ((c = getopt_long(argc, argv, "n:p:v:",
4569 long_opts, NULL)) != -1) {
4572 nodemap_name = optarg;
4583 if (!nodemap_name || !param || !value) {
4585 "usage: nodemap_modify --name <nodemap_name> --property <property_name> --value <value>\n");
4587 "valid properties: admin trusted map_mode squash_uid squash_gid squash_projid deny_unknown audit_mode forbid_encryption readonly_mount\n");
4591 if (strcmp("admin", param) == 0) {
4592 cmd = LCFG_NODEMAP_ADMIN;
4593 } else if (strcmp("trusted", param) == 0) {
4594 cmd = LCFG_NODEMAP_TRUSTED;
4595 } else if (strcmp("deny_unknown", param) == 0) {
4596 cmd = LCFG_NODEMAP_DENY_UNKNOWN;
4597 } else if (strcmp("squash_uid", param) == 0) {
4598 cmd = LCFG_NODEMAP_SQUASH_UID;
4599 } else if (strcmp("squash_gid", param) == 0) {
4600 cmd = LCFG_NODEMAP_SQUASH_GID;
4601 } else if (strcmp("squash_projid", param) == 0) {
4602 cmd = LCFG_NODEMAP_SQUASH_PROJID;
4603 } else if (strcmp("map_mode", param) == 0) {
4604 cmd = LCFG_NODEMAP_MAP_MODE;
4605 } else if (strcmp("audit_mode", param) == 0) {
4606 cmd = LCFG_NODEMAP_AUDIT_MODE;
4607 } else if (strcmp("forbid_encryption", param) == 0) {
4608 cmd = LCFG_NODEMAP_FORBID_ENCRYPT;
4609 } else if (strcmp("readonly_mount", param) == 0) {
4610 cmd = LCFG_NODEMAP_READONLY_MOUNT;
4613 "error: %s: nodemap_modify invalid subcommand: %s\n",
4614 jt_cmdname(argv[0]), param);
4618 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, param,
4623 "error: %s: cannot modify nodemap '%s' to param '%s': value '%s': rc = %d\n",
4624 jt_cmdname(argv[0]), nodemap_name, param, value, rc);
4630 int jt_nodemap_add_idmap(int argc, char **argv)
4633 enum lcfg_command_type cmd = 0;
4634 char *nodemap_name = NULL;
4636 char *idtype = NULL;
4639 static struct option long_opts[] = {
4640 { .val = 'i', .name = "idtype", .has_arg = required_argument },
4641 { .val = 'm', .name = "idmap", .has_arg = required_argument },
4642 { .val = 'n', .name = "name", .has_arg = required_argument },
4645 while ((c = getopt_long(argc, argv, "n:m:i:",
4646 long_opts, NULL)) != -1) {
4649 nodemap_name = optarg;
4660 if (!nodemap_name || !idmap || !idtype) {
4662 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4667 if (strcmp("uid", idtype) == 0) {
4668 cmd = LCFG_NODEMAP_ADD_UIDMAP;
4669 } else if (strcmp("gid", idtype) == 0) {
4670 cmd = LCFG_NODEMAP_ADD_GIDMAP;
4671 } else if (strcmp("projid", idtype) == 0) {
4672 cmd = LCFG_NODEMAP_ADD_PROJIDMAP;
4675 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4680 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
4684 "cannot add %smap '%s' to nodemap '%s': rc = %d\n",
4685 idtype, idmap, nodemap_name, rc);
4691 int jt_nodemap_del_idmap(int argc, char **argv)
4694 enum lcfg_command_type cmd = 0;
4695 char *nodemap_name = NULL;
4697 char *idtype = NULL;
4700 static struct option long_opts[] = {
4701 { .val = 'i', .name = "idtype", .has_arg = required_argument },
4702 { .val = 'm', .name = "idmap", .has_arg = required_argument },
4703 { .val = 'n', .name = "name", .has_arg = required_argument },
4706 while ((c = getopt_long(argc, argv, "n:m:i:",
4707 long_opts, NULL)) != -1) {
4710 nodemap_name = optarg;
4721 if (!nodemap_name || !idmap || !idtype) {
4723 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4728 if (strcmp("uid", idtype) == 0) {
4729 cmd = LCFG_NODEMAP_DEL_UIDMAP;
4730 } else if (strcmp("gid", idtype) == 0) {
4731 cmd = LCFG_NODEMAP_DEL_GIDMAP;
4732 } else if (strcmp("projid", idtype) == 0) {
4733 cmd = LCFG_NODEMAP_DEL_PROJIDMAP;
4736 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4741 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
4745 "cannot delete %smap '%s' from nodemap '%s': rc = %d\n",
4746 idtype, idmap, nodemap_name, rc);
4751 #else /* !HAVE_SERVER_SUPPORT */
4752 int jt_nodemap_activate(int argc, char **argv)
4754 fprintf(stderr, "error: %s: invalid ioctl\n",
4755 jt_cmdname(argv[0]));
4759 int jt_nodemap_add(int argc, char **argv)
4761 fprintf(stderr, "error: %s: invalid ioctl\n",
4762 jt_cmdname(argv[0]));
4766 int jt_nodemap_del(int argc, char **argv)
4768 fprintf(stderr, "error: %s: invalid ioctl\n",
4769 jt_cmdname(argv[0]));
4773 int jt_nodemap_modify(int argc, char **argv)
4775 fprintf(stderr, "error: %s: invalid ioctl\n",
4776 jt_cmdname(argv[0]));
4780 int jt_nodemap_add_range(int argc, char **argv)
4782 fprintf(stderr, "error: %s: invalid ioctl\n",
4783 jt_cmdname(argv[0]));
4787 int jt_nodemap_test_nid(int argc, char **argv)
4789 fprintf(stderr, "error: %s: invalid ioctl\n",
4790 jt_cmdname(argv[0]));
4794 int jt_nodemap_del_range(int argc, char **argv)
4796 fprintf(stderr, "error: %s: invalid ioctl\n",
4797 jt_cmdname(argv[0]));
4801 int jt_nodemap_add_idmap(int argc, char **argv)
4803 fprintf(stderr, "error: %s: invalid ioctl\n",
4804 jt_cmdname(argv[0]));
4808 int jt_nodemap_del_idmap(int argc, char **argv)
4810 fprintf(stderr, "error: %s: invalid ioctl\n",
4811 jt_cmdname(argv[0]));
4815 int jt_nodemap_test_id(int argc, char **argv)
4817 fprintf(stderr, "error: %s: invalid ioctl\n",
4818 jt_cmdname(argv[0]));
4822 int jt_nodemap_set_fileset(int argc, char **argv)
4824 fprintf(stderr, "error: %s: invalid ioctl\n",
4825 jt_cmdname(argv[0]));
4829 int jt_nodemap_set_sepol(int argc, char **argv)
4831 fprintf(stderr, "error: %s: invalid ioctl\n",
4832 jt_cmdname(argv[0]));
4836 int jt_nodemap_info(int argc, char **argv)
4838 fprintf(stderr, "error: %s: invalid ioctl\n",
4839 jt_cmdname(argv[0]));
4842 #endif /* HAVE_SERVER_SUPPORT */
4845 * this function tranforms a rule [start-end/step] into an array
4846 * of matching numbers
4847 * supported forms are:
4848 * [start] : just this number
4849 * [start-end] : all numbers from start to end
4850 * [start-end/step] : numbers from start to end with increment of step
4851 * on return, format contains a printf format string which can be used
4852 * to generate all the strings
4854 static int get_array_idx(char *rule, char *format, int **array)
4856 char *start, *end, *ptr;
4857 unsigned int lo, hi, step;
4862 start = strchr(rule, '[');
4863 end = strchr(rule, ']');
4864 if ((!start) || (!end)) {
4865 *array = malloc(sizeof(int));
4868 strcpy(format, rule);
4876 /* put in format the printf format (the rule without the range) */
4877 sprintf(format, "%s%%.4x%s", rule, end);
4882 /* loop on , separator */
4884 /* extract the 3 fields */
4885 rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
4893 tmp = realloc(*array, array_sz * sizeof(int));
4897 (*array)[array_idx] = lo;
4903 /* do not break to share code with case 3: */
4908 if ((hi < lo) || (step == 0))
4910 array_sz += (hi - lo) / step + 1;
4911 tmp = realloc(*array, array_sz * sizeof(int));
4915 for (i = lo; i <= hi; i += step, array_idx++)
4916 (*array)[array_idx] = i;
4920 ptr = strchr(start, ',');
4934 struct llog_pool_name {
4935 char lpn_name[UUID_MAX];
4936 struct list_head lpn_list;
4939 struct llog_pool_list_data {
4940 char lpld_fsname[LUSTRE_MAXFSNAME + 1];
4941 char lpld_poolname[LOV_MAXPOOLNAME + 1];
4943 struct list_head lpld_list_head;
4947 * Callback to list pool information in llog
4948 * - { index: 74, event: new_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
4949 * - { index: 77, event: add_pool, device: tfs-clilov, fsname: tfs, pool: tmp,
4950 * ost: tfs-OST0000_UUID }
4951 * - { index: 224, event: remove_pool, device: tfs-clilov, fsname: tfs,
4952 * pool: tmp, ost: tfs-OST0003_UUID }
4953 * - { index: 227, event: del_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
4955 * \param record[in] pointer to llog record
4956 * \param data[in] pointer to struct llog_pool_list_data
4958 * \retval 0 on success
4961 static int llog_poollist_cb(const char *record, void *data)
4963 struct llog_pool_list_data *lpld = data;
4964 char pool_filter[MAX_STRING_SIZE] = "";
4965 char *new_record, *del_record, *del_pool, *found;
4967 int filter_len, rc = 0;
4969 filter_len = snprintf(pool_filter, sizeof(pool_filter), " fsname: %s,",
4971 if (lpld->lpld_poolname[0] == '\0') {
4972 new_record = get_event_filter(LCFG_POOL_NEW);
4973 del_record = get_event_filter(LCFG_POOL_DEL);
4974 strncpy(type, " pool: ", sizeof(type));
4976 filter_len += snprintf(pool_filter + filter_len,
4977 sizeof(pool_filter) - filter_len,
4978 " pool: %s", lpld->lpld_poolname);
4979 new_record = get_event_filter(LCFG_POOL_ADD);
4980 del_record = get_event_filter(LCFG_POOL_REM);
4981 strncpy(type, " ost: ", sizeof(type));
4983 del_pool = get_event_filter(LCFG_POOL_DEL);
4985 if (!new_record || !del_record || !del_pool) {
4990 found = strstr(record, pool_filter);
4992 (found[filter_len] == ' ' || found[filter_len] == ',')) {
4993 struct llog_pool_name *tmp = NULL;
4994 struct list_head *head = &lpld->lpld_list_head;
4996 int name_len, type_len = strlen(type);
4998 lpld->lpld_exists = true;
4999 if (strstr(record, new_record)) {
5000 name = strstr(record, type);
5001 /* 2 bytes for " }" */
5002 name_len = strlen(name) - type_len - 2;
5003 if (name_len <= 0 || name_len > sizeof(tmp->lpn_name))
5005 tmp = malloc(sizeof(struct llog_pool_name));
5010 memset(tmp, 0, sizeof(struct llog_pool_name));
5011 strncpy(tmp->lpn_name, name + type_len, name_len);
5012 list_add_tail(&tmp->lpn_list, &lpld->lpld_list_head);
5013 } else if (strstr(record, del_record)) {
5014 name = strstr(record, type);
5015 name_len = strlen(name) - type_len - 2;
5016 list_for_each_entry(tmp, head, lpn_list) {
5017 if (strncmp(tmp->lpn_name, name + type_len,
5019 tmp->lpn_name[name_len] == '\0') {
5020 list_del(&tmp->lpn_list);
5026 /* verify if the specified pool still exists */
5027 if (lpld->lpld_poolname[0] && strstr(record, del_pool))
5028 lpld->lpld_exists = false;
5042 * List pool information by config log
5044 * \param fsname[in] pointer to filesystem name
5045 * \param poolname[in] pointer to pool name
5047 * \retval 0 on success
5050 int llog_poollist(char *fsname, char *poolname)
5052 char logname[MAX_OBD_NAME] = {'\0'};
5053 struct llog_pool_list_data lpld;
5054 struct llog_pool_name *tmp;
5055 struct list_head *head;
5058 if (fsname && fsname[0] == '\0')
5063 memset(&lpld, 0, sizeof(lpld));
5064 INIT_LIST_HEAD(&lpld.lpld_list_head);
5065 lpld.lpld_exists = false;
5066 strncpy(lpld.lpld_fsname, fsname, sizeof(lpld.lpld_fsname) - 1);
5067 if (poolname && poolname[0])
5068 strncpy(lpld.lpld_poolname, poolname,
5069 sizeof(lpld.lpld_poolname) - 1);
5070 snprintf(logname, sizeof(logname), "%s-client", fsname);
5071 rc = jt_llog_print_iter(logname, 0, -1, llog_poollist_cb, &lpld, false,
5074 if (poolname && poolname[0])
5075 printf("Pool: %s.%s\n", fsname, poolname);
5077 printf("Pools from %s:\n", fsname);
5079 head = &lpld.lpld_list_head;
5080 if (poolname && poolname[0] && !lpld.lpld_exists && list_empty(head))
5083 list_for_each_entry(tmp, head, lpn_list) {
5084 if (poolname && poolname[0])
5085 printf("%s\n", tmp->lpn_name);
5087 printf("%s.%s\n", fsname, tmp->lpn_name);
5088 list_del(&tmp->lpn_list);
5095 static bool get_pools_path(char *fsname)
5100 rc = cfs_get_param_paths(&path, "lov/%s-*/pools", fsname);
5102 cfs_free_param_data(&path);
5107 static int extract_fsname_poolname(char **argv, char *fsname,
5110 char *cmd = argv[0], *param = argv[1];
5114 snprintf(fsname, PATH_MAX + 1, "%s", param);
5115 ptr = strchr(fsname, '.');
5117 if (strcmp(cmd, "pool_list") == 0) {
5121 fprintf(stderr, ". is missing in %s\n", fsname);
5126 if ((ptr - fsname) == 0) {
5127 fprintf(stderr, "fsname is empty\n");
5135 if (strlen(ptr) == 0) {
5136 fprintf(stderr, "poolname is empty\n");
5141 strncpy(poolname, ptr, LOV_MAXPOOLNAME);
5142 poolname[LOV_MAXPOOLNAME] = '\0';
5144 if (strncmp(poolname, "none", LOV_MAXPOOLNAME) == 0) {
5145 fprintf(stderr, "poolname cannot be 'none'\n");
5152 fprintf(stderr, "argument %s must be <fsname>.<poolname>\n", param);
5156 int jt_pool_cmd(int argc, char **argv)
5158 enum lcfg_command_type cmd;
5159 char fsname[PATH_MAX + 1];
5160 char poolname[LOV_MAXPOOLNAME + 1];
5161 char *ostnames_buf = NULL;
5163 int *array = NULL, array_sz;
5171 case 1: return CMD_HELP;
5173 rc = extract_fsname_poolname(argv, fsname, poolname);
5177 if (strcmp("pool_new", argv[0]) == 0) {
5178 cmd = LCFG_POOL_NEW;
5179 } else if (strcmp("pool_destroy", argv[0]) == 0) {
5180 cmd = LCFG_POOL_DEL;
5181 } else if (strcmp("pool_list", argv[0]) == 0) {
5182 if (get_pools_path(fsname))
5183 return llapi_poollist(argv[1]);
5184 if (get_mgs_device() > 0)
5185 return llog_poollist(fsname, poolname);
5187 "Cannot run pool_list command since there is no local MGS/MDT or client\n");
5193 rc = pool_cmd(cmd, argv[0], argv[1], fsname, poolname, NULL);
5197 check_pool_cmd_result(cmd, fsname, poolname, NULL);
5201 char format[2 * MAX_OBD_NAME];
5203 if (strcmp("pool_remove", argv[0]) == 0)
5204 cmd = LCFG_POOL_REM;
5205 else if (strcmp("pool_add", argv[0]) == 0)
5206 cmd = LCFG_POOL_ADD;
5210 rc = extract_fsname_poolname(argv, fsname, poolname);
5214 for (i = 2; i < argc; i++) {
5217 array_sz = get_array_idx(argv[i], format, &array);
5221 cmds = malloc(array_sz * sizeof(cmds[0]));
5223 ostnames_buf = malloc(array_sz *
5224 (MAX_OBD_NAME + 1));
5231 for (j = 0; j < array_sz; j++) {
5232 char ostname[MAX_OBD_NAME + 1];
5235 snprintf(ostname, MAX_OBD_NAME, format,
5237 ostname[MAX_OBD_NAME] = '\0';
5239 rc2 = check_and_complete_ostname(fsname,
5251 &ostnames_buf[(MAX_OBD_NAME + 1) * j];
5252 strcpy(cmds[j].ostname, ostname);
5254 cmds[j].ostname = NULL;
5256 cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
5259 /* Return an err if any of the add/dels fail */
5263 for (j = 0; j < array_sz; j++) {
5265 char ostname[MAX_OBD_NAME + 1];
5267 if (!cmds[j].ostname) {
5268 snprintf(ostname, MAX_OBD_NAME,
5270 ostname[MAX_OBD_NAME] = '\0';
5271 check_and_complete_ostname(
5277 check_pool_cmd_result(cmd, fsname,
5302 #ifdef HAVE_SERVER_SUPPORT
5303 static const char *barrier_status2name(enum barrier_status status)
5308 case BS_FREEZING_P1:
5309 return "freezing_p1";
5310 case BS_FREEZING_P2:
5311 return "freezing_p2";
5329 int jt_barrier_freeze(int argc, char **argv)
5331 struct obd_ioctl_data data;
5332 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5333 struct barrier_ctl bc;
5336 if (argc < 2 || argc > 3)
5339 memset(&data, 0, sizeof(data));
5340 rc = data.ioc_dev = get_mgs_device();
5344 memset(&bc, 0, sizeof(bc));
5345 bc.bc_version = BARRIER_VERSION_V1;
5346 bc.bc_cmd = BC_FREEZE;
5348 bc.bc_timeout = atoi(argv[2]);
5349 if (bc.bc_timeout == 0)
5350 bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
5352 if (strlen(argv[1]) > 8) {
5354 "%s: fsname name %s is too long. It should not exceed 8.\n",
5359 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5360 data.ioc_inlbuf1 = (char *)&bc;
5361 data.ioc_inllen1 = sizeof(bc);
5362 memset(buf, 0, sizeof(rawbuf));
5363 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5365 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5369 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5371 fprintf(stderr, "Fail to freeze barrier for %s: %s\n",
5372 argv[1], strerror(errno));
5377 int jt_barrier_thaw(int argc, char **argv)
5379 struct obd_ioctl_data data;
5380 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5381 struct barrier_ctl bc;
5387 memset(&data, 0, sizeof(data));
5388 rc = data.ioc_dev = get_mgs_device();
5392 memset(&bc, 0, sizeof(bc));
5393 bc.bc_version = BARRIER_VERSION_V1;
5394 bc.bc_cmd = BC_THAW;
5396 if (strlen(argv[1]) > 8) {
5398 "fsname name %s is too long. It should not exceed 8.\n",
5403 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5404 data.ioc_inlbuf1 = (char *)&bc;
5405 data.ioc_inllen1 = sizeof(bc);
5406 memset(buf, 0, sizeof(rawbuf));
5407 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5409 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5413 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5415 fprintf(stderr, "Fail to thaw barrier for %s: %s\n",
5416 argv[1], strerror(errno));
5421 int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc)
5423 struct obd_ioctl_data data;
5424 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5427 memset(&data, 0, sizeof(data));
5428 rc = data.ioc_dev = get_mgs_device();
5432 memset(bc, 0, sizeof(*bc));
5433 bc->bc_version = BARRIER_VERSION_V1;
5434 bc->bc_cmd = BC_STAT;
5435 strncpy(bc->bc_name, fsname, sizeof(bc->bc_name) - 1);
5436 data.ioc_inlbuf1 = (char *)bc;
5437 data.ioc_inllen1 = sizeof(*bc);
5438 memset(buf, 0, sizeof(rawbuf));
5439 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5441 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5445 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5447 fprintf(stderr, "Fail to query barrier for %s: %s\n",
5448 fsname, strerror(errno));
5450 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5455 int jt_barrier_stat(int argc, char **argv)
5457 struct barrier_ctl bc;
5458 static struct option long_opt_barrier_stat[] = {
5462 .has_arg = no_argument,
5466 .has_arg = no_argument,
5477 bool timeout = false;
5479 while ((opt = getopt_long(argc, argv, "st", long_opt_barrier_stat,
5496 name = argv[optind];
5497 if (strlen(name) > 8) {
5499 "fsname name %s is too long. It should not exceed 8.\n",
5504 rc = __jt_barrier_stat(name, &bc);
5506 if (state && !timeout)
5507 printf("%s\n", barrier_status2name(bc.bc_status));
5508 else if (timeout && !state)
5510 (bc.bc_status == BS_FREEZING_P1 ||
5511 bc.bc_status == BS_FREEZING_P2 ||
5512 bc.bc_status == BS_FROZEN) ?
5515 printf("state: %s\ntimeout: %d seconds\n",
5516 barrier_status2name(bc.bc_status),
5517 (bc.bc_status == BS_FREEZING_P1 ||
5518 bc.bc_status == BS_FREEZING_P2 ||
5519 bc.bc_status == BS_FROZEN) ?
5526 int jt_barrier_rescan(int argc, char **argv)
5528 struct obd_ioctl_data data;
5529 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5530 struct barrier_ctl bc;
5533 if (argc < 2 || argc > 3)
5536 memset(&data, 0, sizeof(data));
5537 rc = data.ioc_dev = get_mgs_device();
5541 memset(&bc, 0, sizeof(bc));
5542 bc.bc_version = BARRIER_VERSION_V1;
5543 bc.bc_cmd = BC_RESCAN;
5545 bc.bc_timeout = atoi(argv[2]);
5546 if (bc.bc_timeout == 0)
5547 bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
5549 if (strlen(argv[1]) > 8) {
5551 "fsname name %s is too long. It should not exceed 8.\n",
5556 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5557 data.ioc_inlbuf1 = (char *)&bc;
5558 data.ioc_inllen1 = sizeof(bc);
5559 memset(buf, 0, sizeof(rawbuf));
5560 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5562 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5566 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5568 fprintf(stderr, "Fail to rescan barrier bitmap for %s: %s\n",
5569 argv[1], strerror(errno));
5571 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5572 printf("%u of %u MDT(s) in the filesystem %s are inactive\n",
5573 bc.bc_absence, bc.bc_total, argv[1]);
5578 #endif /* HAVE_SERVER_SUPPORT */
5580 int jt_get_obj_version(int argc, char **argv)
5583 struct obd_ioctl_data data;
5584 __u64 version, id = ULLONG_MAX, group = ULLONG_MAX;
5585 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr;
5588 while ((c = getopt(argc, argv, "i:g:")) != -1) {
5591 id = strtoull(optarg, NULL, 0);
5594 group = strtoull(optarg, NULL, 0);
5602 fidstr = *(argv + optind);
5604 if (!(id != ULLONG_MAX && group != ULLONG_MAX && argc == 0) &&
5605 !(id == ULLONG_MAX && group == ULLONG_MAX && argc == 1))
5608 memset(&data, 0, sizeof(data));
5609 data.ioc_dev = cur_device;
5611 rc = llapi_fid_parse(fidstr, &fid, NULL);
5613 fprintf(stderr, "%s: error parsing FID '%s': %s\n",
5614 jt_cmdname(argv[0]), fidstr, strerror(-rc));
5618 data.ioc_inlbuf1 = (char *)&fid;
5619 data.ioc_inllen1 = sizeof(fid);
5621 data.ioc_inlbuf3 = (char *)&id;
5622 data.ioc_inllen3 = sizeof(id);
5623 data.ioc_inlbuf4 = (char *)&group;
5624 data.ioc_inllen4 = sizeof(group);
5626 data.ioc_inlbuf2 = (char *)&version;
5627 data.ioc_inllen2 = sizeof(version);
5629 memset(buf, 0, sizeof(*buf));
5630 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5632 fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
5633 jt_cmdname(argv[0]), strerror(-rc));
5637 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GET_OBJ_VERSION, buf);
5639 fprintf(stderr, "error: %s: ioctl: %s\n",
5640 jt_cmdname(argv[0]), strerror(errno));
5644 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5645 printf("%#jx\n", (uintmax_t)version);
5650 #ifdef HAVE_SERVER_SUPPORT
5651 int jt_changelog_register(int argc, char **argv)
5653 struct option long_opts[] = {
5654 { .val = 'h', .name = "help", .has_arg = no_argument },
5655 { .val = 'm', .name = "mask", .has_arg = required_argument },
5656 { .val = 'n', .name = "nameonly", .has_arg = no_argument },
5657 { .val = 'u', .name = "user", .has_arg = required_argument },
5659 struct obd_ioctl_data data = { 0 };
5660 char rawbuf[MAX_IOC_BUFLEN] = "";
5662 char *device = lcfg_get_devname();
5663 char *username = NULL, *usermask = NULL;
5664 bool print_name_only = false;
5668 if (cur_device < 0 || !device)
5671 while ((c = getopt_long(argc, argv, "hm:nu:", long_opts, NULL)) != -1) {
5674 usermask = strdup(optarg);
5677 "error: %s: %s: cannot copy '%s'\n",
5678 jt_cmdname(argv[0]), strerror(errno),
5684 print_name_only = true;
5687 username = strdup(optarg);
5690 "error: %s: %s: cannot copy '%s'\n",
5691 jt_cmdname(argv[0]), strerror(errno),
5704 data.ioc_dev = cur_device;
5706 data.ioc_inlbuf1 = username;
5707 data.ioc_inllen1 = strlen(username) + 1;
5711 data.ioc_inlbuf2 = usermask;
5712 data.ioc_inllen2 = strlen(usermask) + 1;
5715 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5717 fprintf(stderr, "error: %s: cannot pack ioctl: %s\n",
5718 jt_cmdname(argv[0]), strerror(-rc));
5721 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CHANGELOG_REG, buf);
5724 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
5725 rc == -EEXIST ? "User exists" : strerror(-rc));
5729 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5731 if (data.ioc_u32_1 == 0) {
5732 fprintf(stderr, "received invalid userid!\n");
5737 if (print_name_only)
5738 printf("%s%u%s%s\n", CHANGELOG_USER_PREFIX, data.ioc_u32_1,
5739 username ? "-" : "", username ? : "");
5741 printf("%s: Registered changelog userid '%s%u%s%s'\n",
5742 device, CHANGELOG_USER_PREFIX, data.ioc_u32_1,
5743 username ? "-" : "", username ? : "");
5750 int jt_changelog_deregister(int argc, char **argv)
5752 struct option long_opts[] = {
5753 { .val = 'h', .name = "help", .has_arg = no_argument },
5754 { .val = 'u', .name = "user", .has_arg = required_argument },
5756 struct obd_ioctl_data data = { 0 };
5757 char rawbuf[MAX_IOC_BUFLEN] = "";
5759 char *device = lcfg_get_devname();
5760 char *username = NULL;
5764 if (cur_device < 0 || !device)
5767 while ((c = getopt_long(argc, argv, "hu:", long_opts, NULL)) != -1) {
5770 username = strdup(optarg);
5773 "error: %s: %s: cannot copy '%s'\n",
5774 jt_cmdname(argv[0]), strerror(errno),
5786 if (1 == optind && argc > 1) {
5787 /* first check if pure ID was passed */
5788 id = atoi(argv[optind]);
5789 /* nameless cl<ID> format or cl<ID>-... format, only ID matters */
5791 sscanf(argv[optind], CHANGELOG_USER_PREFIX"%d", &id);
5793 /* no valid ID was parsed */
5797 "error: %s: expect <ID> or cl<ID>[-name] got '%s'\n",
5798 strerror(-rc), argv[optind]);
5804 if (optind < argc || argc == 1)
5807 data.ioc_dev = cur_device;
5808 data.ioc_u32_1 = id;
5810 data.ioc_inlbuf1 = username;
5811 data.ioc_inllen1 = strlen(username) + 1;
5814 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5816 fprintf(stderr, "error: %s: invalid ioctl\n",
5817 jt_cmdname(argv[0]));
5821 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CHANGELOG_DEREG, buf);
5824 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
5825 rc == -ENOENT ? "User not found" : strerror(-rc));
5829 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5830 printf("%s: Deregistered changelog user #%u\n", device, data.ioc_u32_1);
5834 #else /* !HAVE_SERVER_SUPPORT */
5835 int jt_changelog_register(int argc, char **argv)
5837 fprintf(stderr, "error: %s: invalid ioctl\n",
5838 jt_cmdname(argv[0]));
5842 int jt_changelog_deregister(int argc, char **argv)
5844 fprintf(stderr, "error: %s: invalid ioctl\n",
5845 jt_cmdname(argv[0]));
5848 #endif /* HAVE_SERVER_SUPPORT */
5850 int jt_pcc_add(int argc, char **argv)
5852 struct option long_opts[] = {
5853 { .val = 'p', .name = "param", .has_arg = required_argument },
5855 const char *mntpath;
5856 const char *pccpath;
5862 while ((rc = getopt_long(argc, argv, "p:", long_opts, NULL)) != -1) {
5873 fprintf(stderr, "%s: must specify the config param for PCC\n",
5874 jt_cmdname(argv[0]));
5878 if (optind + 2 != argc) {
5880 "%s: must specify mount path and PCC path %d:%d\n",
5881 jt_cmdname(argv[0]), optind, argc);
5885 mntpath = argv[optind++];
5886 pccpath = argv[optind];
5888 snprintf(cmd, PATH_MAX, "add %s %s", pccpath, param);
5889 rc = llapi_pccdev_set(mntpath, cmd);
5891 fprintf(stderr, "%s: failed to run '%s' on %s\n",
5892 jt_cmdname(argv[0]), cmd, mntpath);
5897 int jt_pcc_del(int argc, char **argv)
5899 const char *mntpath;
5900 const char *pccpath;
5906 fprintf(stderr, "%s: require 3 arguments\n",
5907 jt_cmdname(argv[0]));
5911 mntpath = argv[optind++];
5912 pccpath = argv[optind++];
5914 snprintf(cmd, PATH_MAX, "del %s", pccpath);
5915 rc = llapi_pccdev_set(mntpath, cmd);
5917 fprintf(stderr, "%s: failed to run '%s' on %s\n",
5918 jt_cmdname(argv[0]), cmd, mntpath);
5923 int jt_pcc_clear(int argc, char **argv)
5925 const char *mntpath;
5930 fprintf(stderr, "%s: require 2 arguments\n",
5931 jt_cmdname(argv[0]));
5935 mntpath = argv[optind];
5936 rc = llapi_pccdev_set(mntpath, "clear");
5938 fprintf(stderr, "%s: failed to run 'clear' on %s\n",
5939 jt_cmdname(argv[0]), mntpath);
5944 int jt_pcc_list(int argc, char **argv)
5946 const char *mntpath;
5951 fprintf(stderr, "%s: require 2 arguments\n",
5952 jt_cmdname(argv[0]));
5956 mntpath = argv[optind];
5957 rc = llapi_pccdev_get(mntpath);
5959 fprintf(stderr, "%s: failed to run 'pcc list' on %s\n",
5960 jt_cmdname(argv[0]), mntpath);