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;
2699 /* default end of indexes is max indexes in a llog bitmap */
2701 end = LLOG_MIN_CHUNK_SIZE * 8 - 1;
2703 data.ioc_dev = cur_device;
2704 data.ioc_inlbuf1 = logname;
2705 data.ioc_inllen1 = strlen(logname) + 1;
2708 * Estimate about 128 characters per configuration record. Not all
2709 * records will be printed in any case, so they should easily fit. If
2710 * not, the kernel will return -EOVERFLOW and ask for fewer records.
2712 * We don't want to request records from the kernel one-at-a-time, as
2713 * it restarts the config llog iteration from the beginning, so we
2714 * fetch multiple records from the kernel per call and split locally.
2716 for (rec = start; rec < end; rec += inc) {
2717 char *record = ((struct obd_ioctl_data *)buf)->ioc_bulk;
2718 __u32 *is_llog_eof = &((struct obd_ioctl_data *)buf)->ioc_u32_2;
2721 snprintf(startbuf, sizeof(startbuf), "%lu", rec);
2722 snprintf(endbuf, sizeof(endbuf), "%lu",
2723 end < rec + inc - 1 ? end : rec + inc - 1);
2725 data.ioc_u32_1 = raw ? 1 : 0;
2726 /* start and end record numbers are passed as ASCII digits */
2727 data.ioc_inlbuf2 = startbuf;
2728 data.ioc_inllen2 = strlen(startbuf) + 1;
2729 data.ioc_inlbuf3 = endbuf;
2730 data.ioc_inllen3 = strlen(endbuf) + 1;
2732 data.ioc_inllen4 = sizeof(rawbuf) -
2733 __ALIGN_KERNEL(sizeof(data), 8) -
2734 __ALIGN_KERNEL(data.ioc_inllen1, 8) -
2735 __ALIGN_KERNEL(data.ioc_inllen2, 8) -
2736 __ALIGN_KERNEL(data.ioc_inllen3, 8);
2737 memset(buf, 0, sizeof(rawbuf));
2738 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
2740 fprintf(stderr, "%s: invalid ioctl data\n", logname);
2744 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_PRINT, buf);
2745 if (rc == -EOVERFLOW && inc > 2) {
2750 fprintf(stderr, "%s: OBD_IOC_LLOG_PRINT failed: %s\n",
2751 logname, strerror(errno));
2756 /* record was not modified -> all indexes are skipped */
2757 if (strcmp(record, logname) != 0)
2758 rc = llog_process_records(record_cb, record, private,
2763 /* end of llog file ? */
2772 static int llog_parse_catalog_options(int *argc, char ***argv, char **catalog,
2773 long *start, long *end, int *raw)
2775 const struct option long_opts[] = {
2776 /* the --catalog option is not required, just for consistency */
2777 { .val = 'c', .name = "catalog", .has_arg = required_argument },
2778 { .val = 'e', .name = "end", .has_arg = required_argument },
2779 { .val = 'h', .name = "help", .has_arg = no_argument },
2780 { .val = 'r', .name = "raw", .has_arg = no_argument },
2781 { .val = 's', .name = "start", .has_arg = required_argument },
2783 char *cmd = (*argv)[0];
2787 if (!catalog || !start || !end)
2790 /* now process command line arguments*/
2791 while ((c = getopt_long(*argc, *argv, "c:e:hrs:",
2792 long_opts, NULL)) != -1) {
2798 *end = strtol(optarg, &endp, 0);
2799 if (*endp != '\0') {
2800 fprintf(stderr, "%s: bad end value '%s'\n",
2811 *start = strtol(optarg, &endp, 0);
2812 if (*endp != '\0') {
2813 fprintf(stderr, "%s: bad start value '%s'\n",
2827 * support old optional positional parameters only if they were
2828 * not already specified with named arguments: logname [start [end]]
2833 "%s: logname is set, unknown argument '%s'\n",
2837 *catalog = (*argv)[0];
2842 if (*catalog == NULL) {
2843 fprintf(stderr, "%s: no logname specified\n", cmd);
2850 "%s: --start is set, unknown argument '%s'\n",
2855 *start = strtol((*argv)[0], &endp, 0);
2856 if (*endp != '\0') {
2857 fprintf(stderr, "%s: bad start value '%s'\n",
2867 "%s: --end is set, unknown argument '%s'\n",
2872 *end = strtol((*argv)[0], &endp, 0);
2873 if (*endp != '\0') {
2874 fprintf(stderr, "%s: bad end value '%s'\n",
2882 fprintf(stderr, "%s: unknown argument '%s'\n", cmd, (*argv)[0]);
2886 if (*end != -1 && *end < *start) {
2887 fprintf(stderr, "%s: end '%lu' less than than start '%lu'\n",
2895 int jt_llog_print(int argc, char **argv)
2897 char *catalog = NULL;
2898 long start = 1, end = -1;
2902 rc = llog_parse_catalog_options(&argc, &argv, &catalog, &start, &end,
2907 if (llog_default_device(LLOG_DFLT_MGS_SET))
2908 return CMD_INCOMPLETE;
2910 rc = jt_llog_print_iter(catalog, start, end, jt_llog_print_cb,
2911 NULL, false, !!raw);
2913 llog_default_device(LLOG_DFLT_DEV_RESET);
2919 * Parse catalog, log ID, and optionally a log index with either optional
2920 * arguments or positional arguments. Only the initial catalog argument
2921 * may be positional with other optional arguments.
2923 * The positional arguments option should eventually be phased out.
2925 static int llog_parse_catalog_log_idx(int *argc, char ***argv, const char *opts,
2926 struct obd_ioctl_data *data)
2928 const struct option long_opts[] = {
2929 /* the --catalog option is not required, just for consistency */
2930 { .val = 'c', .name = "catalog", .has_arg = required_argument },
2931 { .val = 'h', .name = "help", .has_arg = no_argument },
2932 { .val = 'i', .name = "log_idx", .has_arg = required_argument },
2933 { .val = 'l', .name = "log_id", .has_arg = required_argument },
2938 if (!data || *argc <= 1)
2941 data->ioc_dev = cur_device;
2943 /* now process command line arguments*/
2944 while ((c = getopt_long(*argc, *argv, opts, long_opts, NULL)) != -1) {
2947 data->ioc_inllen1 = strlen(optarg) + 1;
2948 data->ioc_inlbuf1 = optarg;
2951 data->ioc_inllen3 = strlen(optarg) + 1;
2952 data->ioc_inlbuf3 = optarg;
2954 case 'l': /* The log_id option isn't currently needed for
2955 * cancel as mdt_iocontrol() handles IOC_LLOG_CANCEL,
2956 * but we may as well keep it for now.
2958 data->ioc_inllen2 = strlen(optarg) + 1;
2959 data->ioc_inlbuf2 = optarg;
2970 /* Allow catalog to be specified as first option without --catalog */
2971 if (!data->ioc_inlbuf1 && *argc > 0) {
2972 data->ioc_inlbuf1 = (*argv)[0];
2973 data->ioc_inllen1 = strlen((*argv)[0]) + 1;
2981 int jt_llog_cancel(int argc, char **argv)
2983 struct obd_ioctl_data data = { 0 };
2984 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
2985 char *cmd = argv[0];
2988 /* Manage default device */
2989 if (llog_default_device(LLOG_DFLT_MGS_SET))
2990 return CMD_INCOMPLETE;
2992 /* Parse catalog file (in inlbuf1) and named parameters */
2993 rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hi:l:", &data);
2996 * Handle old positional parameters if not using named parameters,
2997 * either "<catalog> <log_idx>" or "<catalog> <log_id> <log_idx>".
2998 * It was "inlbuf3 = log_idx", and "inlbuf2 = log_id" (ignored by
2999 * config log cancel), and shows why I hate positional parameters.
3002 data.ioc_inllen3 = strlen(argv[0]) + 1;
3003 data.ioc_inlbuf3 = argv[0];
3004 } else if (argc == 2) {
3005 data.ioc_inllen2 = strlen(argv[0]) + 1;
3006 data.ioc_inlbuf2 = argv[0];
3007 data.ioc_inllen3 = strlen(argv[1]) + 1;
3008 data.ioc_inlbuf3 = argv[1];
3011 if (!data.ioc_inlbuf1 || !data.ioc_inlbuf3) {
3012 /* missing mandatory parameters */
3017 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3019 fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n",
3020 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3024 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
3026 fprintf(stderr, "%s: cancel catalog '%s:%s' failed: %s\n",
3027 jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf3,
3031 llog_default_device(LLOG_DFLT_DEV_RESET);
3035 int jt_llog_check(int argc, char **argv)
3037 struct obd_ioctl_data data = { 0 };
3038 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3039 char *catalog = NULL;
3040 char startbuf[16], endbuf[16];
3041 long start = 1, end = -1;
3042 char *cmd = argv[0];
3045 rc = llog_parse_catalog_options(&argc, &argv, &catalog, &start,
3050 if (llog_default_device(LLOG_DFLT_MGS_SET))
3051 return CMD_INCOMPLETE;
3056 data.ioc_dev = cur_device;
3057 data.ioc_inllen1 = strlen(catalog) + 1;
3058 data.ioc_inlbuf1 = catalog;
3060 snprintf(startbuf, sizeof(startbuf), "%lu", start);
3061 snprintf(endbuf, sizeof(endbuf), "%lu", end);
3062 /* start and end record numbers are passed as ASCII digits */
3063 data.ioc_inllen2 = strlen(startbuf) + 1;
3064 data.ioc_inlbuf2 = startbuf;
3065 data.ioc_inllen3 = strlen(endbuf) + 1;
3066 data.ioc_inlbuf3 = endbuf;
3068 data.ioc_inllen4 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
3069 __ALIGN_KERNEL(data.ioc_inllen1, 8) -
3070 __ALIGN_KERNEL(data.ioc_inllen2, 8) -
3071 __ALIGN_KERNEL(data.ioc_inllen3, 8);
3072 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3074 fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n",
3075 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3079 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf);
3081 fprintf(stdout, "%s", ((struct obd_ioctl_data *)buf)->ioc_bulk);
3083 fprintf(stderr, "%s: OBD_IOC_LLOG_CHECK failed: %s\n",
3084 jt_cmdname(cmd), strerror(errno));
3086 llog_default_device(LLOG_DFLT_DEV_RESET);
3090 int jt_llog_remove(int argc, char **argv)
3092 struct obd_ioctl_data data = { 0 };
3093 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3094 char *cmd = argv[0];
3097 if (llog_default_device(LLOG_DFLT_MGS_SET))
3098 return CMD_INCOMPLETE;
3100 rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hl:", &data);
3105 if (data.ioc_inlbuf2) {
3107 "%s: --log_id is set, unknown argument '%s'\n",
3108 jt_cmdname(cmd), argv[0]);
3113 data.ioc_inllen2 = strlen(argv[0]) + 1;
3114 data.ioc_inlbuf2 = argv[0];
3117 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3119 fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n",
3120 jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc));
3124 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf);
3126 fprintf(stderr, "%s: cancel catalog '%s:%s' failed: %s\n",
3127 jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf2,
3131 llog_default_device(LLOG_DFLT_DEV_RESET);
3135 static void signal_server(int sig)
3137 if (sig == SIGINT) {
3138 do_disconnect("sigint", 1);
3141 fprintf(stderr, "%s: got signal %d\n", jt_cmdname("sigint"),
3146 int obd_initialize(int argc, char **argv)
3148 if (shmem_setup() != 0)
3151 register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
3156 void obd_finalize(int argc, char **argv)
3158 struct sigaction sigact;
3160 /* sigact initialization */
3161 sigact.sa_handler = signal_server;
3162 sigfillset(&sigact.sa_mask);
3163 sigact.sa_flags = SA_RESTART;
3164 /* coverity[uninit_use_in_call] */
3165 sigaction(SIGINT, &sigact, NULL);
3168 do_disconnect(argv[0], 1);
3172 * Get the index of the last llog record
3174 * logid: [0x3:0xa:0x0]:0
3179 * \param logname[in] pointer to config log name
3181 * \retval > 0 on success
3184 static long llog_last_index(char *logname)
3186 struct obd_ioctl_data data = { 0 };
3187 char rawbuf[MAX_IOC_BUFLEN] = "", *buf = rawbuf;
3191 data.ioc_dev = cur_device;
3192 data.ioc_inllen1 = strlen(logname) + 1;
3193 data.ioc_inlbuf1 = logname;
3194 data.ioc_inllen2 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
3195 __ALIGN_KERNEL(data.ioc_inllen1, 8);
3196 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3198 fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n",
3199 __func__, logname, strerror(-rc));
3203 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf);
3205 last_index = strstr(((struct obd_ioctl_data *)buf)->ioc_bulk,
3207 return strtol(last_index + 11, NULL, 10);
3215 static char *get_llog_event_name(__u32 cmd)
3217 #ifdef HAVE_SERVER_SUPPORT
3218 struct lcfg_type_data *data;
3220 data = lcfg_cmd2data(cmd);
3222 return data->ltd_name;
3227 static char *get_event_filter(__u32 cmd)
3230 char *filter = NULL;
3233 event_name = get_llog_event_name(cmd);
3235 /* 9 bytes for "event: , " */
3236 len = 9 + strlen(event_name);
3237 filter = malloc(len + 1);
3240 memset(filter, 0, len + 1);
3241 snprintf(filter, len, "event: %s, ", event_name);
3249 * Callback to search ostname in llog
3250 * - { index: 23, event: attach, device: lustre-OST0000-osc, type: osc,
3251 * UUID: lustre-clilov_UUID }
3252 * - { index: 24, event: setup, device: lustre-OST0000-osc,
3253 * UUID: lustre-OST0000_UUID, node: 192.168.0.120@tcp }
3254 * - { index: 25, event: add_osc, device: lustre-clilov,
3255 * ost: lustre-OST0000_UUID, index: 0, gen: 1 }
3257 * \param record[in] pointer to llog record
3258 * \param data[in] pointer to ostname
3260 * \retval 1 if ostname is found
3261 * 0 if ostname is not found
3262 * -ENOENT if ostname is deleted
3264 static int llog_search_ost_cb(const char *record, void *data)
3266 char *ostname = data;
3267 char ost_filter[MAX_STRING_SIZE] = {'\0'};
3268 char *add_osc, *del_osc, *setup, *cleanup;
3270 add_osc = get_event_filter(LCFG_LOV_ADD_OBD);
3271 del_osc = get_event_filter(LCFG_LOV_DEL_OBD);
3272 setup = get_event_filter(LCFG_SETUP);
3273 cleanup = get_event_filter(LCFG_CLEANUP);
3274 if (!add_osc || !del_osc || !setup || !cleanup)
3277 if (ostname && ostname[0])
3278 snprintf(ost_filter, sizeof(ost_filter), " %s,", ostname);
3280 if (strstr(record, ost_filter)) {
3281 if (strstr(record, add_osc) || strstr(record, setup))
3283 if (strstr(record, del_osc) || strstr(record, cleanup))
3296 * Search ost in llog
3298 * \param logname[in] pointer to config log name
3299 * \param last_index[in] the index of the last llog record
3300 * \param ostname[in] pointer to ost name
3302 * \retval 1 if ostname is found
3303 * 0 if ostname is not found
3305 static int llog_search_ost(char *logname, long last_index, char *ostname)
3307 long start, end, inc = MAX_IOC_BUFLEN / 128;
3310 for (end = last_index; end > 1; end -= inc) {
3311 start = end - inc > 0 ? end - inc : 1;
3312 rc = jt_llog_print_iter(logname, start, end, llog_search_ost_cb,
3313 ostname, true, false);
3318 return (rc == 1 ? 1 : 0);
3321 struct llog_del_ost_priv {
3329 * Callback to search and delete ostname in llog
3331 * \param record[in] pointer to llog record
3332 * \param data[in] pointer to ostname
3334 * \retval 1 if ostname is found and entry deleted
3335 * 0 if ostname is not found
3338 static int llog_del_ost_cb(const char *record, void *data)
3340 char ost_filter[MAX_STRING_SIZE] = {'\0'};
3341 char log_idxstr[MAX_STRING_SIZE] = {'\0'};
3342 long int log_idx = 0;
3343 struct llog_del_ost_priv *priv = data;
3344 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3345 struct obd_ioctl_data ioc_data = { 0 };
3348 if (priv->ostname && priv->ostname[0])
3349 snprintf(ost_filter, sizeof(ost_filter), " %s", priv->ostname);
3351 if (!strstr(record, ost_filter))
3354 rc = sscanf(record, "- { index: %ld", &log_idx);
3356 fprintf(stderr, "error: record without index:\n%s\n",
3360 snprintf(log_idxstr, sizeof(log_idxstr), "%ld", log_idx);
3362 ioc_data.ioc_dev = cur_device;
3363 ioc_data.ioc_inllen1 = strlen(priv->logname) + 1;
3364 ioc_data.ioc_inlbuf1 = priv->logname;
3365 ioc_data.ioc_inllen3 = strlen(log_idxstr) + 1;
3366 ioc_data.ioc_inlbuf3 = log_idxstr;
3368 rc = llapi_ioctl_pack(&ioc_data, &buf, sizeof(rawbuf));
3370 fprintf(stderr, "ioctl_pack for catalog '%s' failed: %s\n",
3371 ioc_data.ioc_inlbuf1, strerror(-rc));
3376 fprintf(stdout, "[DRY RUN] cancel catalog '%s:%s':\"%s\"\n",
3377 ioc_data.ioc_inlbuf1, ioc_data.ioc_inlbuf3, record);
3379 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf);
3381 fprintf(stderr, "cancel catalog '%s:%s' failed: %s\n",
3382 ioc_data.ioc_inlbuf1, ioc_data.ioc_inlbuf3,
3385 fprintf(stdout, "cancel catalog %s log_idx %ld: done\n",
3386 priv->logname, log_idx);
3394 * Search and delete ost in llog
3396 * \param logname[in] pointer to config log name
3397 * \param last_index[in] the index of the last llog record
3398 * \param ostname[in] pointer to ost name
3399 * \param dryrun[in] dry run?
3401 * \retval 1 if ostname is found and deleted
3402 * 0 if ostname is not found
3404 static int llog_del_ost(char *logname, long last_index, char *ostname,
3407 long start, end, inc = MAX_IOC_BUFLEN / 128;
3409 struct llog_del_ost_priv priv = { logname, ostname, false, dryrun };
3411 for (end = last_index; end > 1; end -= inc) {
3412 start = end - inc > 0 ? end - inc : 1;
3413 rc = jt_llog_print_iter(logname, start, end, llog_del_ost_cb,
3414 &priv, true, false);
3420 fprintf(stdout, "del_ost: cancelled %d catalog entries\n",
3423 fprintf(stdout, "del_ost: no catalog entry deleted\n");
3428 struct llog_pool_data {
3429 char lpd_fsname[LUSTRE_MAXFSNAME + 1];
3430 char lpd_poolname[LOV_MAXPOOLNAME + 1];
3431 char lpd_ostname[MAX_OBD_NAME + 1];
3432 enum lcfg_command_type lpd_cmd_type;
3433 bool lpd_pool_exists;
3438 * Called for each formatted line in the config log (within range).
3440 * - { index: 74, event: new_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
3441 * - { index: 77, event: add_pool, device: tfs-clilov, fsname: tfs, pool: tmp,
3442 * ost: tfs-OST0000_UUID }
3443 * - { index: 224, event: remove_pool, device: tfs-clilov, fsname: tfs,
3444 * pool: tmp, ost: tfs-OST0003_UUID }
3445 * - { index: 227, event: del_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
3447 * \param record[in] pointer to llog record
3448 * \param data[in] pointer to llog_pool_data
3450 * \retval 1 if pool or OST is found
3451 * 0 if pool or OST is not found
3452 * -ENOENT if pool or OST is removed
3454 static int llog_search_pool_cb(const char *record, void *data)
3456 struct llog_pool_data *lpd = data;
3457 char pool_filter[MAX_STRING_SIZE] = "";
3458 char *new_pool, *del_pool, *add_pool, *rem_pool;
3460 int fs_pool_len = 0, rc = 0;
3462 new_pool = get_event_filter(LCFG_POOL_NEW);
3463 del_pool = get_event_filter(LCFG_POOL_DEL);
3464 add_pool = get_event_filter(LCFG_POOL_ADD);
3465 rem_pool = get_event_filter(LCFG_POOL_REM);
3466 if (!new_pool || !del_pool || !add_pool || !rem_pool) {
3471 fs_pool_len = 16 + strlen(lpd->lpd_fsname) + strlen(lpd->lpd_poolname);
3472 snprintf(pool_filter, fs_pool_len + 1, "fsname: %s, pool: %s",
3473 lpd->lpd_fsname, lpd->lpd_poolname);
3475 /* search poolname */
3476 found = strstr(record, pool_filter);
3478 (found[fs_pool_len] == ' ' || found[fs_pool_len] == ',')) {
3479 if (strstr(record, new_pool)) {
3480 lpd->lpd_pool_exists = true;
3484 if (strstr(record, del_pool)) {
3485 lpd->lpd_pool_exists = false;
3490 if (lpd->lpd_cmd_type == LCFG_POOL_NEW ||
3491 lpd->lpd_cmd_type == LCFG_POOL_DEL) {
3492 /* In function mgs_pool_cmd(), a pool's pool_new/add
3493 * record will be marked as "SKIP" if its pool_destroy/
3494 * remove record is logged later. That means the "SKIP"
3495 * record won't be printed here and thus lpd_ost_num
3496 * doesn't need to be decreased as well.
3498 if (strstr(record, add_pool))
3500 } else if (lpd->lpd_ostname[0] != '\0') {
3501 if (strstr(record, lpd->lpd_ostname)) {
3502 lpd->lpd_pool_exists = true;
3503 if (strstr(record, add_pool)) {
3504 lpd->lpd_ost_num = 1;
3508 if (strstr(record, rem_pool)) {
3509 lpd->lpd_ost_num = 0;
3529 /* Search pool and its ost in llog
3531 * \param logname[in] pointer to config log name
3532 * \param last_index[in] the index of the last llog record
3533 * \param fsname[in] pointer to filesystem name
3534 * \param poolname[in] pointer pool name
3535 * \param ostname[in] pointer to OST name(OSTnnnn-UUID)
3536 * \param cmd[in] pool command type
3538 * \retval < 0 on error
3539 * 0 if pool is empty or OST is not found
3540 * 1 if pool is not empty or OST is found
3542 static int llog_search_pool(char *logname, long last_index, char *fsname,
3543 char *poolname, char *ostname,
3544 enum lcfg_command_type cmd)
3546 struct llog_pool_data lpd;
3547 long start, end, inc = MAX_IOC_BUFLEN / 128;
3550 memset(&lpd, 0, sizeof(lpd));
3551 lpd.lpd_cmd_type = cmd;
3552 lpd.lpd_pool_exists = false;
3553 lpd.lpd_ost_num = 0;
3554 strncpy(lpd.lpd_fsname, fsname, sizeof(lpd.lpd_fsname) - 1);
3555 if (poolname && poolname[0])
3556 strncpy(lpd.lpd_poolname, poolname,
3557 sizeof(lpd.lpd_poolname) - 1);
3558 if (ostname && ostname[0])
3559 strncpy(lpd.lpd_ostname, ostname, sizeof(lpd.lpd_ostname) - 1);
3561 for (end = last_index; end > 1; end -= inc) {
3562 start = end - inc > 0 ? end - inc : 1;
3563 rc = jt_llog_print_iter(logname, start, end,
3564 llog_search_pool_cb, &lpd, true, false);
3566 if (rc == 1 && lpd.lpd_pool_exists)
3567 rc = lpd.lpd_ost_num ? 1 : 0;
3568 else if (rc == -ENOENT && lpd.lpd_pool_exists &&
3580 static bool combined_mgs_mds(char *fsname)
3585 rc = cfs_get_param_paths(&path, "mdt/%s-MDT0000", fsname);
3587 cfs_free_param_data(&path);
3589 if (get_mgs_device() > 0 && !rc)
3596 * if pool is NULL, search ostname in target_obd
3597 * if pool is not NULL:
3598 * - if pool not found returns errno < 0
3599 * - if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty
3600 * - if ostname is not NULL, returns 1 if OST is in pool and 0 if not
3602 int lctl_search_ost(char *fsname, char *poolname, char *ostname,
3603 enum lcfg_command_type cmd)
3605 char logname[MAX_OBD_NAME] = {'\0'};
3608 if (fsname && fsname[0] == '\0')
3613 if (combined_mgs_mds(fsname))
3614 return llapi_search_ost(fsname, poolname, ostname);
3616 /* fetch the last_index of llog record */
3617 snprintf(logname, sizeof(logname), "%s-client", fsname);
3618 last_index = llog_last_index(logname);
3622 /* if pool is NULL, search ostname in target_obd */
3623 if (!poolname && ostname)
3624 return llog_search_ost(logname, last_index, ostname);
3626 return llog_search_pool(logname, last_index, fsname, poolname,
3630 static int check_pool_cmd(enum lcfg_command_type cmd, char *fsname,
3631 char *poolname, char *ostname)
3635 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3636 if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
3637 fprintf(stderr, "Pool %s.%s not found\n",
3643 case LCFG_POOL_NEW: {
3648 fprintf(stderr, "Pool %s.%s already exists\n",
3654 case LCFG_POOL_DEL: {
3660 "Pool %s.%s not empty, please remove all members\n",
3666 case LCFG_POOL_ADD: {
3668 fprintf(stderr, "OST %s is already in pool %s.%s\n",
3669 ostname, fsname, poolname);
3672 rc = lctl_search_ost(fsname, NULL, ostname, cmd);
3674 fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
3680 case LCFG_POOL_REM: {
3682 fprintf(stderr, "OST %s not found in pool %s.%s\n",
3683 ostname, fsname, poolname);
3695 * This check only verifies that the changes have been "pushed out" to
3696 * the client successfully. This involves waiting for a config update,
3697 * and so may fail because of problems in that code or post-command
3698 * network loss. So reporting a warning is appropriate, but not a failure.
3700 static int check_pool_cmd_result(enum lcfg_command_type cmd, char *fsname,
3701 char *poolname, char *ostname)
3707 case LCFG_POOL_NEW: {
3709 rc = lctl_search_ost(fsname, poolname, NULL, cmd);
3715 } while ((rc < 0) && (cpt > 0));
3717 fprintf(stderr, "Pool %s.%s created\n",
3722 fprintf(stderr, "Warning, pool %s.%s not found\n", fsname,
3726 case LCFG_POOL_DEL: {
3728 rc = lctl_search_ost(fsname, poolname, NULL, cmd);
3734 } while ((rc >= 0) && (cpt > 0));
3736 fprintf(stderr, "Pool %s.%s destroyed\n",
3741 fprintf(stderr, "Warning, pool %s.%s still found\n", fsname,
3745 case LCFG_POOL_ADD: {
3747 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3753 } while ((rc != 1) && (cpt > 0));
3755 fprintf(stderr, "OST %s added to pool %s.%s\n",
3756 ostname, fsname, poolname);
3759 fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
3760 ostname, fsname, poolname);
3763 case LCFG_POOL_REM: {
3765 rc = lctl_search_ost(fsname, poolname, ostname, cmd);
3771 } while ((rc == 1) && (cpt > 0));
3773 fprintf(stderr, "OST %s removed from pool %s.%s\n",
3774 ostname, fsname, poolname);
3777 fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
3778 ostname, fsname, poolname);
3787 static int check_and_complete_ostname(char *fsname, char *ostname)
3790 char real_ostname[MAX_OBD_NAME + 1];
3793 /* if OST name does not start with fsname, we add it */
3794 /* if not check if the fsname is the right one */
3795 ptr = strchr(ostname, '-');
3797 sprintf(real_ostname, "%s-%s", fsname, ostname);
3798 } else if (strncmp(ostname, fsname, strlen(fsname)) != 0) {
3799 fprintf(stderr, "%s does not start with fsname %s\n",
3803 if (strlen(ostname) > sizeof(real_ostname) - 1)
3806 strncpy(real_ostname, ostname, sizeof(real_ostname));
3809 /* real_ostname is fsname-????? */
3810 ptr = real_ostname + strlen(fsname) + 1;
3811 if (strncmp(ptr, "OST", 3) != 0) {
3812 fprintf(stderr, "%s does not start by %s-OST nor OST\n",
3816 /* real_ostname is fsname-OST????? */
3818 for (i = 0; i < 4; i++) {
3819 if (!isxdigit(*ptr)) {
3821 "ost's index in %s is not an hexa number\n",
3827 /* real_ostname is fsname-OSTXXXX????? */
3828 /* if OST name does not end with _UUID, we add it */
3830 strcat(real_ostname, "_UUID");
3831 } else if (strcmp(ptr, "_UUID") != 0) {
3833 "ostname %s does not end with _UUID\n", ostname);
3836 /* real_ostname is fsname-OSTXXXX_UUID */
3837 strcpy(ostname, real_ostname);
3841 /* returns 0 or -errno */
3842 static int pool_cmd(enum lcfg_command_type cmd, char *cmdname,
3843 char *fullpoolname, char *fsname, char *poolname,
3847 struct obd_ioctl_data data;
3848 struct lustre_cfg_bufs bufs;
3849 struct lustre_cfg *lcfg;
3850 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3852 rc = check_pool_cmd(cmd, fsname, poolname, ostname);
3855 "Can't verify pool command since there is no local MDT or client, proceeding anyhow...\n");
3859 lustre_cfg_bufs_reset(&bufs, NULL);
3860 lustre_cfg_bufs_set_string(&bufs, 0, cmdname);
3861 lustre_cfg_bufs_set_string(&bufs, 1, fullpoolname);
3863 lustre_cfg_bufs_set_string(&bufs, 2, ostname);
3865 lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
3868 lustre_cfg_init(lcfg, cmd, &bufs);
3870 memset(&data, 0, sizeof(data));
3871 rc = data.ioc_dev = get_mgs_device();
3875 data.ioc_type = LUSTRE_CFG_TYPE;
3876 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
3877 lcfg->lcfg_buflens);
3878 data.ioc_pbuf1 = (void *)lcfg;
3880 memset(buf, 0, sizeof(rawbuf));
3881 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3883 fprintf(stderr, "error: %s: invalid ioctl\n",
3884 jt_cmdname(cmdname));
3888 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);
3895 "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",
3896 jt_cmdname(cmdname), LOV_MAXPOOLNAME, LUSTRE_MAXFSNAME);
3900 "error: %s can contain only alphanumeric characters, underscores, and dashes besides the required '.'\n",
3901 jt_cmdname(cmdname));
3909 int jt_del_ost(int argc, char **argv)
3911 char *fsname = NULL, *ptr, *logname;
3912 char mdtpattern[16], clipattern[16];
3913 char ostname[MAX_OBD_NAME + 1];
3916 int rc, start = 0, dryrun = 0;
3919 static struct option long_opts[] = {
3920 { .val = 'h', .name = "help", .has_arg = no_argument },
3921 { .val = 'n', .name = "dryrun", .has_arg = no_argument },
3922 { .val = 't', .name = "target", .has_arg = required_argument },
3925 while ((c = getopt_long(argc, argv, "hnt:", long_opts, NULL)) != -1) {
3928 fsname = strdup(optarg);
3943 if (llog_default_device(LLOG_DFLT_MGS_SET)) {
3944 rc = CMD_INCOMPLETE;
3948 ptr = strstr(fsname, "-OST");
3955 fprintf(stdout, "del_ost: dry run for target %s\n", fsname);
3958 rc = sscanf(ptr, "OST%04x", &index);
3964 if (strlen(ptr) > sizeof(ostname) - 1) {
3969 snprintf(mdtpattern, sizeof(mdtpattern), "%s-MDT", fsname);
3970 snprintf(clipattern, sizeof(clipattern), "%s-client", fsname);
3971 snprintf(ostname, sizeof(ostname), "%s-%s", fsname, ptr);
3974 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
3977 start = llog_catlist_next(start, rawbuf, sizeof(rawbuf));
3980 begin = ((struct obd_ioctl_data *)buf)->ioc_bulk;
3981 if (strlen(begin) == 0)
3984 while ((end = strchr(begin, '\n'))) {
3986 logname = strstr(begin, "config_log: ");
3988 if (logname && (strstr(logname, mdtpattern) ||
3989 strstr(logname, clipattern))) {
3992 fprintf(stdout, "config_log: %s\n", logname);
3994 last_index = llog_last_index(logname);
3995 if (last_index < 0) {
3997 "error with catalog %s: %s\n",
3998 logname, strerror(-last_index));
4002 rc = llog_del_ost(logname, last_index, ostname,
4012 llog_default_device(LLOG_DFLT_DEV_RESET);
4018 #ifdef HAVE_SERVER_SUPPORT
4020 * Format and send the ioctl to the MGS.
4022 * \param cmd IOCTL to send
4023 * \param ret_data void pointer to return anything from
4025 * \param num_args number of arguments to pack into the
4027 * \param argv[] variable number of string arguments
4029 * \retval 0 on success
4031 static int nodemap_cmd(enum lcfg_command_type cmd, void *ret_data,
4032 unsigned int ret_size, ...)
4037 struct lustre_cfg_bufs bufs;
4038 struct obd_ioctl_data data;
4039 struct lustre_cfg *lcfg;
4040 char rawbuf[MAX_IOC_BUFLEN];
4044 lustre_cfg_bufs_reset(&bufs, NULL);
4046 va_start(ap, ret_size);
4047 arg = va_arg(ap, char *);
4049 lustre_cfg_bufs_set_string(&bufs, i, arg);
4051 arg = va_arg(ap, char *);
4055 lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
4058 lustre_cfg_init(lcfg, cmd, &bufs);
4060 memset(&data, 0, sizeof(data));
4061 rc = data.ioc_dev = get_mgs_device();
4065 data.ioc_type = LUSTRE_CFG_TYPE;
4066 data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
4067 lcfg->lcfg_buflens);
4068 data.ioc_pbuf1 = (void *)lcfg;
4070 memset(buf, 0, sizeof(rawbuf));
4071 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
4074 "error: invalid ioctl request: %08x errno: %d: %s\n",
4075 cmd, errno, strerror(-rc));
4079 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_NODEMAP, buf);
4082 "error: invalid ioctl: %08x errno: %d: %s\n",
4083 cmd, errno, strerror(errno));
4088 rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
4092 if (ret_size > data.ioc_plen1)
4093 ret_size = data.ioc_plen1;
4095 memcpy(ret_data, data.ioc_pbuf1, ret_size);
4104 * activate nodemap functions
4106 * \param argc number of args
4107 * \param argv[] variable string arguments
4109 * argv[0] 1 for activate or 0 for deactivate
4111 * \retval 0 on success
4113 int jt_nodemap_activate(int argc, char **argv)
4117 rc = nodemap_cmd(LCFG_NODEMAP_ACTIVATE, NULL, 0, argv[0], argv[1],
4131 * \param argc number of args
4132 * \param argv[] variable string arguments
4134 * argv[0] nodemap name
4136 * \retval 0 on success
4138 int jt_nodemap_add(int argc, char **argv)
4142 rc = llapi_nodemap_exists(argv[1]);
4144 fprintf(stderr, "error: %s existing nodemap name\n", argv[1]);
4148 rc = nodemap_cmd(LCFG_NODEMAP_ADD, NULL, 0, argv[0], argv[1], NULL);
4161 * \param argc number of args
4162 * \param argv[] variable string arguments
4164 * argv[0] nodemap name
4166 * \retval 0 on success
4168 int jt_nodemap_del(int argc, char **argv)
4172 rc = llapi_nodemap_exists(argv[1]);
4174 fprintf(stderr, "error: %s not existing nodemap name\n",
4178 rc = nodemap_cmd(LCFG_NODEMAP_DEL, NULL, 0, argv[0], argv[1], NULL);
4189 * test a nid for nodemap membership
4191 * \param argc number of args
4192 * \param argv[] variable string arguments
4194 * argv[0] properly formatted nid
4196 * \retval 0 on success
4198 int jt_nodemap_test_nid(int argc, char **argv)
4200 char rawbuf[MAX_IOC_BUFLEN];
4203 rc = nodemap_cmd(LCFG_NODEMAP_TEST_NID, &rawbuf, sizeof(rawbuf),
4204 argv[0], argv[1], NULL);
4206 printf("%s\n", (char *)rawbuf);
4212 * test a nodemap id pair for mapping
4214 * \param argc number of args
4215 * \param argv[[] variable string arguments
4217 * \retval 0 on success
4219 * The argv array should contain the nodemap name, the id
4220 * to checking the mapping on, and the id type (UID or GID)
4223 int jt_nodemap_test_id(int argc, char **argv)
4225 char rawbuf[MAX_IOC_BUFLEN];
4226 char *nidstr = NULL;
4228 char *typestr = NULL;
4232 static struct option long_opts[] = {
4233 { .val = 'i', .name = "id", .has_arg = required_argument },
4234 { .val = 'n', .name = "nid", .has_arg = required_argument },
4235 { .val = 't', .name = "idtype",
4236 .has_arg = required_argument },
4239 while ((c = getopt_long(argc, argv, "n:t:i:",
4240 long_opts, NULL)) != -1) {
4254 if (!nidstr || !typestr || !idstr) {
4256 "usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>\n");
4260 rc = nodemap_cmd(LCFG_NODEMAP_TEST_ID, &rawbuf, sizeof(rawbuf),
4261 argv[0], nidstr, typestr, idstr, NULL);
4263 printf("%s\n", (char *)rawbuf);
4271 * \param nodemap_range --range string
4272 * \param nid_range nid range string, min_nid:max_nid
4274 * \retval 0 on success
4276 static int parse_nid_range(char *nodemap_range, char *nid_range, int range_len)
4278 char min_nid[LNET_NIDSTR_SIZE + 1];
4279 char max_nid[LNET_NIDSTR_SIZE + 1];
4280 struct list_head nidlist;
4283 INIT_LIST_HEAD(&nidlist);
4285 if (cfs_parse_nidlist(nodemap_range, strlen(nodemap_range),
4288 "error: nodemap_xxx_range: can't parse nid range: %s\n",
4293 rc = cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
4298 "error: nodemap_xxx_range: nid range uses currently unsupported features\n");
4299 else if (rc == -ERANGE)
4301 "error: nodemap_xxx_range: nodemap ranges must be contiguous\n");
4306 snprintf(nid_range, range_len, "%s:%s", min_nid, max_nid);
4312 * add an nid range to a nodemap
4314 * \param argc number of args
4315 * \param argv[] variable string arguments
4317 * --name nodemap name
4318 * --range properly formatted nid range
4320 * \retval 0 on success, -errno on error
4322 int jt_nodemap_add_range(int argc, char **argv)
4324 char *nodemap_name = NULL;
4325 char *nodemap_range = NULL;
4326 char nid_range[2 * LNET_NIDSTR_SIZE + 2];
4330 static struct option long_opts[] = {
4331 { .val = 'n', .name = "name", .has_arg = required_argument },
4332 { .val = 'r', .name = "range", .has_arg = required_argument },
4335 while ((c = getopt_long(argc, argv, "n:r:",
4336 long_opts, NULL)) != -1) {
4339 nodemap_name = optarg;
4342 nodemap_range = optarg;
4347 if (!nodemap_name || !nodemap_range) {
4349 "usage: nodemap_add_range --name <name> --range <range>\n");
4353 rc = parse_nid_range(nodemap_range, nid_range, sizeof(nid_range));
4357 rc = nodemap_cmd(LCFG_NODEMAP_ADD_RANGE, NULL, 0, argv[0],
4358 nodemap_name, nid_range, NULL);
4361 "error: %s: cannot add range '%s' to nodemap '%s': %s\n",
4362 jt_cmdname(argv[0]), nodemap_range, nodemap_name,
4370 * delete an nid range to a nodemap
4372 * \param argc number of args
4373 * \param argv[] variable string arguments
4375 * --name nodemap name
4376 * --range properly formatted nid range
4378 * \retval 0 on success
4380 int jt_nodemap_del_range(int argc, char **argv)
4382 char *nodemap_name = NULL;
4383 char *nodemap_range = NULL;
4384 char nid_range[2 * LNET_NIDSTR_SIZE + 2];
4388 static struct option long_opts[] = {
4389 { .val = 'n', .name = "name", .has_arg = required_argument },
4390 { .val = 'r', .name = "range", .has_arg = required_argument },
4393 while ((c = getopt_long(argc, argv, "n:r:",
4394 long_opts, NULL)) != -1) {
4397 nodemap_name = optarg;
4400 nodemap_range = optarg;
4405 if (!nodemap_name || !nodemap_range) {
4407 "usage: nodemap_del_range --name <name> --range <range>\n");
4411 rc = parse_nid_range(nodemap_range, nid_range, sizeof(nid_range));
4416 rc = nodemap_cmd(LCFG_NODEMAP_DEL_RANGE, NULL, 0, argv[0],
4417 nodemap_name, nid_range, NULL);
4421 "error: %s: cannot delete range '%s' to nodemap '%s': rc = %d\n",
4422 jt_cmdname(argv[0]), nodemap_range, nodemap_name, rc);
4429 * set a fileset on a nodemap
4431 * \param argc number of args
4432 * \param argv[] variable string arguments
4434 * --name nodemap name
4435 * --fileset fileset name
4437 * \retval 0 on success
4439 int jt_nodemap_set_fileset(int argc, char **argv)
4441 char *nodemap_name = NULL;
4442 char *fileset_name = NULL;
4446 static struct option long_opts[] = {
4447 { .val = 'f', .name = "fileset", .has_arg = required_argument },
4448 { .val = 'n', .name = "name", .has_arg = required_argument },
4451 while ((c = getopt_long(argc, argv, "n:f:",
4452 long_opts, NULL)) != -1) {
4455 nodemap_name = optarg;
4458 fileset_name = optarg;
4463 if (!nodemap_name || !fileset_name) {
4465 "usage: nodemap_set_fileset --name <name> --fileset <fileset>\n");
4469 rc = nodemap_cmd(LCFG_NODEMAP_SET_FILESET, NULL, 0, argv[0],
4470 nodemap_name, fileset_name, NULL);
4474 "error: %s: cannot set fileset '%s' on nodemap '%s': rc = %d\n",
4475 jt_cmdname(argv[0]), fileset_name, nodemap_name, rc);
4482 * set SELinux policy info on a nodemap
4484 * \param argc number of args
4485 * \param argv[] variable string arguments
4487 * --name nodemap name
4488 * --sepol SELinux policy info
4490 * \retval 0 on success
4492 int jt_nodemap_set_sepol(int argc, char **argv)
4494 char *nodemap_name = NULL;
4499 static struct option long_options[] = {
4502 .has_arg = required_argument,
4507 .has_arg = required_argument,
4515 while ((c = getopt_long(argc, argv, "n:s:",
4516 long_options, NULL)) != -1) {
4519 nodemap_name = optarg;
4527 if (!nodemap_name || !sepol) {
4529 "usage: nodemap_set_sepol --name <name> --sepol <sepol>\n");
4533 rc = nodemap_cmd(LCFG_NODEMAP_SET_SEPOL, NULL, 0, argv[0],
4534 nodemap_name, sepol, NULL);
4538 "error: %s: cannot set sepol '%s' on nodemap '%s': rc = %d\n",
4539 jt_cmdname(argv[0]), sepol, nodemap_name, rc);
4546 * modify a nodemap's behavior
4548 * \param argc number of args
4549 * \param argv[] variable string arguments
4551 * --name nodemap name
4552 * --property nodemap property to change
4553 * admin, trusted, squash_uid, squash_gid)
4554 * --value value to set property
4556 * \retval 0 on success
4558 int jt_nodemap_modify(int argc, char **argv)
4562 enum lcfg_command_type cmd = 0;
4563 char *nodemap_name = NULL;
4567 static struct option long_opts[] = {
4568 { .val = 'n', .name = "name", .has_arg = required_argument },
4569 { .val = 'p', .name = "property", .has_arg = required_argument },
4570 { .val = 'v', .name = "value", .has_arg = required_argument },
4573 while ((c = getopt_long(argc, argv, "n:p:v:",
4574 long_opts, NULL)) != -1) {
4577 nodemap_name = optarg;
4588 if (!nodemap_name || !param || !value) {
4590 "usage: nodemap_modify --name <nodemap_name> --property <property_name> --value <value>\n");
4592 "valid properties: admin trusted map_mode squash_uid squash_gid squash_projid deny_unknown audit_mode forbid_encryption readonly_mount\n");
4596 if (strcmp("admin", param) == 0) {
4597 cmd = LCFG_NODEMAP_ADMIN;
4598 } else if (strcmp("trusted", param) == 0) {
4599 cmd = LCFG_NODEMAP_TRUSTED;
4600 } else if (strcmp("deny_unknown", param) == 0) {
4601 cmd = LCFG_NODEMAP_DENY_UNKNOWN;
4602 } else if (strcmp("squash_uid", param) == 0) {
4603 cmd = LCFG_NODEMAP_SQUASH_UID;
4604 } else if (strcmp("squash_gid", param) == 0) {
4605 cmd = LCFG_NODEMAP_SQUASH_GID;
4606 } else if (strcmp("squash_projid", param) == 0) {
4607 cmd = LCFG_NODEMAP_SQUASH_PROJID;
4608 } else if (strcmp("map_mode", param) == 0) {
4609 cmd = LCFG_NODEMAP_MAP_MODE;
4610 } else if (strcmp("audit_mode", param) == 0) {
4611 cmd = LCFG_NODEMAP_AUDIT_MODE;
4612 } else if (strcmp("forbid_encryption", param) == 0) {
4613 cmd = LCFG_NODEMAP_FORBID_ENCRYPT;
4614 } else if (strcmp("readonly_mount", param) == 0) {
4615 cmd = LCFG_NODEMAP_READONLY_MOUNT;
4618 "error: %s: nodemap_modify invalid subcommand: %s\n",
4619 jt_cmdname(argv[0]), param);
4623 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, param,
4628 "error: %s: cannot modify nodemap '%s' to param '%s': value '%s': rc = %d\n",
4629 jt_cmdname(argv[0]), nodemap_name, param, value, rc);
4635 int jt_nodemap_add_idmap(int argc, char **argv)
4638 enum lcfg_command_type cmd = 0;
4639 char *nodemap_name = NULL;
4641 char *idtype = NULL;
4644 static struct option long_opts[] = {
4645 { .val = 'i', .name = "idtype", .has_arg = required_argument },
4646 { .val = 'm', .name = "idmap", .has_arg = required_argument },
4647 { .val = 'n', .name = "name", .has_arg = required_argument },
4650 while ((c = getopt_long(argc, argv, "n:m:i:",
4651 long_opts, NULL)) != -1) {
4654 nodemap_name = optarg;
4665 if (!nodemap_name || !idmap || !idtype) {
4667 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4672 if (strcmp("uid", idtype) == 0) {
4673 cmd = LCFG_NODEMAP_ADD_UIDMAP;
4674 } else if (strcmp("gid", idtype) == 0) {
4675 cmd = LCFG_NODEMAP_ADD_GIDMAP;
4676 } else if (strcmp("projid", idtype) == 0) {
4677 cmd = LCFG_NODEMAP_ADD_PROJIDMAP;
4680 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4685 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
4689 "cannot add %smap '%s' to nodemap '%s': rc = %d\n",
4690 idtype, idmap, nodemap_name, rc);
4696 int jt_nodemap_del_idmap(int argc, char **argv)
4699 enum lcfg_command_type cmd = 0;
4700 char *nodemap_name = NULL;
4702 char *idtype = NULL;
4705 static struct option long_opts[] = {
4706 { .val = 'i', .name = "idtype", .has_arg = required_argument },
4707 { .val = 'm', .name = "idmap", .has_arg = required_argument },
4708 { .val = 'n', .name = "name", .has_arg = required_argument },
4711 while ((c = getopt_long(argc, argv, "n:m:i:",
4712 long_opts, NULL)) != -1) {
4715 nodemap_name = optarg;
4726 if (!nodemap_name || !idmap || !idtype) {
4728 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4733 if (strcmp("uid", idtype) == 0) {
4734 cmd = LCFG_NODEMAP_DEL_UIDMAP;
4735 } else if (strcmp("gid", idtype) == 0) {
4736 cmd = LCFG_NODEMAP_DEL_GIDMAP;
4737 } else if (strcmp("projid", idtype) == 0) {
4738 cmd = LCFG_NODEMAP_DEL_PROJIDMAP;
4741 "usage: %s --name <name> --idtype [uid | gid | projid] --idmap <client id>:<filesystem id>\n",
4746 rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
4750 "cannot delete %smap '%s' from nodemap '%s': rc = %d\n",
4751 idtype, idmap, nodemap_name, rc);
4756 #else /* !HAVE_SERVER_SUPPORT */
4757 int jt_nodemap_activate(int argc, char **argv)
4759 fprintf(stderr, "error: %s: invalid ioctl\n",
4760 jt_cmdname(argv[0]));
4764 int jt_nodemap_add(int argc, char **argv)
4766 fprintf(stderr, "error: %s: invalid ioctl\n",
4767 jt_cmdname(argv[0]));
4771 int jt_nodemap_del(int argc, char **argv)
4773 fprintf(stderr, "error: %s: invalid ioctl\n",
4774 jt_cmdname(argv[0]));
4778 int jt_nodemap_modify(int argc, char **argv)
4780 fprintf(stderr, "error: %s: invalid ioctl\n",
4781 jt_cmdname(argv[0]));
4785 int jt_nodemap_add_range(int argc, char **argv)
4787 fprintf(stderr, "error: %s: invalid ioctl\n",
4788 jt_cmdname(argv[0]));
4792 int jt_nodemap_test_nid(int argc, char **argv)
4794 fprintf(stderr, "error: %s: invalid ioctl\n",
4795 jt_cmdname(argv[0]));
4799 int jt_nodemap_del_range(int argc, char **argv)
4801 fprintf(stderr, "error: %s: invalid ioctl\n",
4802 jt_cmdname(argv[0]));
4806 int jt_nodemap_add_idmap(int argc, char **argv)
4808 fprintf(stderr, "error: %s: invalid ioctl\n",
4809 jt_cmdname(argv[0]));
4813 int jt_nodemap_del_idmap(int argc, char **argv)
4815 fprintf(stderr, "error: %s: invalid ioctl\n",
4816 jt_cmdname(argv[0]));
4820 int jt_nodemap_test_id(int argc, char **argv)
4822 fprintf(stderr, "error: %s: invalid ioctl\n",
4823 jt_cmdname(argv[0]));
4827 int jt_nodemap_set_fileset(int argc, char **argv)
4829 fprintf(stderr, "error: %s: invalid ioctl\n",
4830 jt_cmdname(argv[0]));
4834 int jt_nodemap_set_sepol(int argc, char **argv)
4836 fprintf(stderr, "error: %s: invalid ioctl\n",
4837 jt_cmdname(argv[0]));
4841 int jt_nodemap_info(int argc, char **argv)
4843 fprintf(stderr, "error: %s: invalid ioctl\n",
4844 jt_cmdname(argv[0]));
4847 #endif /* HAVE_SERVER_SUPPORT */
4850 * this function tranforms a rule [start-end/step] into an array
4851 * of matching numbers
4852 * supported forms are:
4853 * [start] : just this number
4854 * [start-end] : all numbers from start to end
4855 * [start-end/step] : numbers from start to end with increment of step
4856 * on return, format contains a printf format string which can be used
4857 * to generate all the strings
4859 static int get_array_idx(char *rule, char *format, int **array)
4861 char *start, *end, *ptr;
4862 unsigned int lo, hi, step;
4867 start = strchr(rule, '[');
4868 end = strchr(rule, ']');
4869 if ((!start) || (!end)) {
4870 *array = malloc(sizeof(int));
4873 strcpy(format, rule);
4881 /* put in format the printf format (the rule without the range) */
4882 sprintf(format, "%s%%.4x%s", rule, end);
4887 /* loop on , separator */
4889 /* extract the 3 fields */
4890 rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
4898 tmp = realloc(*array, array_sz * sizeof(int));
4902 (*array)[array_idx] = lo;
4908 /* do not break to share code with case 3: */
4913 if ((hi < lo) || (step == 0))
4915 array_sz += (hi - lo) / step + 1;
4916 tmp = realloc(*array, array_sz * sizeof(int));
4920 for (i = lo; i <= hi; i += step, array_idx++)
4921 (*array)[array_idx] = i;
4925 ptr = strchr(start, ',');
4939 struct llog_pool_name {
4940 char lpn_name[UUID_MAX];
4941 struct list_head lpn_list;
4944 struct llog_pool_list_data {
4945 char lpld_fsname[LUSTRE_MAXFSNAME + 1];
4946 char lpld_poolname[LOV_MAXPOOLNAME + 1];
4948 struct list_head lpld_list_head;
4952 * Callback to list pool information in llog
4953 * - { index: 74, event: new_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
4954 * - { index: 77, event: add_pool, device: tfs-clilov, fsname: tfs, pool: tmp,
4955 * ost: tfs-OST0000_UUID }
4956 * - { index: 224, event: remove_pool, device: tfs-clilov, fsname: tfs,
4957 * pool: tmp, ost: tfs-OST0003_UUID }
4958 * - { index: 227, event: del_pool, device: tfs-clilov, fsname: tfs, pool: tmp }
4960 * \param record[in] pointer to llog record
4961 * \param data[in] pointer to struct llog_pool_list_data
4963 * \retval 0 on success
4966 static int llog_poollist_cb(const char *record, void *data)
4968 struct llog_pool_list_data *lpld = data;
4969 char pool_filter[MAX_STRING_SIZE] = "";
4970 char *new_record, *del_record, *del_pool, *found;
4972 int filter_len, rc = 0;
4974 filter_len = snprintf(pool_filter, sizeof(pool_filter), " fsname: %s,",
4976 if (lpld->lpld_poolname[0] == '\0') {
4977 new_record = get_event_filter(LCFG_POOL_NEW);
4978 del_record = get_event_filter(LCFG_POOL_DEL);
4979 strncpy(type, " pool: ", sizeof(type));
4981 filter_len += snprintf(pool_filter + filter_len,
4982 sizeof(pool_filter) - filter_len,
4983 " pool: %s", lpld->lpld_poolname);
4984 new_record = get_event_filter(LCFG_POOL_ADD);
4985 del_record = get_event_filter(LCFG_POOL_REM);
4986 strncpy(type, " ost: ", sizeof(type));
4988 del_pool = get_event_filter(LCFG_POOL_DEL);
4990 if (!new_record || !del_record || !del_pool) {
4995 found = strstr(record, pool_filter);
4997 (found[filter_len] == ' ' || found[filter_len] == ',')) {
4998 struct llog_pool_name *tmp = NULL;
4999 struct list_head *head = &lpld->lpld_list_head;
5001 int name_len, type_len = strlen(type);
5003 lpld->lpld_exists = true;
5004 if (strstr(record, new_record)) {
5005 name = strstr(record, type);
5006 /* 2 bytes for " }" */
5007 name_len = strlen(name) - type_len - 2;
5008 if (name_len <= 0 || name_len > sizeof(tmp->lpn_name))
5010 tmp = malloc(sizeof(struct llog_pool_name));
5015 memset(tmp, 0, sizeof(struct llog_pool_name));
5016 strncpy(tmp->lpn_name, name + type_len, name_len);
5017 list_add_tail(&tmp->lpn_list, &lpld->lpld_list_head);
5018 } else if (strstr(record, del_record)) {
5019 name = strstr(record, type);
5020 name_len = strlen(name) - type_len - 2;
5021 list_for_each_entry(tmp, head, lpn_list) {
5022 if (strncmp(tmp->lpn_name, name + type_len,
5024 tmp->lpn_name[name_len] == '\0') {
5025 list_del(&tmp->lpn_list);
5031 /* verify if the specified pool still exists */
5032 if (lpld->lpld_poolname[0] && strstr(record, del_pool))
5033 lpld->lpld_exists = false;
5047 * List pool information by config log
5049 * \param fsname[in] pointer to filesystem name
5050 * \param poolname[in] pointer to pool name
5052 * \retval 0 on success
5055 int llog_poollist(char *fsname, char *poolname)
5057 char logname[MAX_OBD_NAME] = {'\0'};
5058 struct llog_pool_list_data lpld;
5059 struct llog_pool_name *tmp;
5060 struct list_head *head;
5063 if (fsname && fsname[0] == '\0')
5068 memset(&lpld, 0, sizeof(lpld));
5069 INIT_LIST_HEAD(&lpld.lpld_list_head);
5070 lpld.lpld_exists = false;
5071 strncpy(lpld.lpld_fsname, fsname, sizeof(lpld.lpld_fsname) - 1);
5072 if (poolname && poolname[0])
5073 strncpy(lpld.lpld_poolname, poolname,
5074 sizeof(lpld.lpld_poolname) - 1);
5075 snprintf(logname, sizeof(logname), "%s-client", fsname);
5076 rc = jt_llog_print_iter(logname, 0, -1, llog_poollist_cb, &lpld, false,
5079 if (poolname && poolname[0])
5080 printf("Pool: %s.%s\n", fsname, poolname);
5082 printf("Pools from %s:\n", fsname);
5084 head = &lpld.lpld_list_head;
5085 if (poolname && poolname[0] && !lpld.lpld_exists && list_empty(head))
5088 list_for_each_entry(tmp, head, lpn_list) {
5089 if (poolname && poolname[0])
5090 printf("%s\n", tmp->lpn_name);
5092 printf("%s.%s\n", fsname, tmp->lpn_name);
5093 list_del(&tmp->lpn_list);
5100 static bool get_pools_path(char *fsname)
5105 rc = cfs_get_param_paths(&path, "lov/%s-*/pools", fsname);
5107 cfs_free_param_data(&path);
5112 static int extract_fsname_poolname(char **argv, char *fsname,
5115 char *cmd = argv[0], *param = argv[1];
5119 snprintf(fsname, PATH_MAX + 1, "%s", param);
5120 ptr = strchr(fsname, '.');
5122 if (strcmp(cmd, "pool_list") == 0) {
5126 fprintf(stderr, ". is missing in %s\n", fsname);
5131 if ((ptr - fsname) == 0) {
5132 fprintf(stderr, "fsname is empty\n");
5140 if (ptr[0] == '\0') {
5141 fprintf(stderr, "poolname is empty\n");
5146 strncpy(poolname, ptr, LOV_MAXPOOLNAME);
5147 poolname[LOV_MAXPOOLNAME] = '\0';
5149 if (lov_pool_is_reserved(poolname)) {
5150 fprintf(stderr, "poolname cannot be '%s'\n", poolname);
5157 fprintf(stderr, "argument %s must be <fsname>.<poolname>\n", param);
5161 int jt_pool_cmd(int argc, char **argv)
5163 enum lcfg_command_type cmd;
5164 char fsname[PATH_MAX + 1];
5165 char poolname[LOV_MAXPOOLNAME + 1];
5166 char *ostnames_buf = NULL;
5168 int *array = NULL, array_sz;
5176 case 1: return CMD_HELP;
5178 rc = extract_fsname_poolname(argv, fsname, poolname);
5182 if (strcmp("pool_new", argv[0]) == 0) {
5183 cmd = LCFG_POOL_NEW;
5184 } else if (strcmp("pool_destroy", argv[0]) == 0) {
5185 cmd = LCFG_POOL_DEL;
5186 } else if (strcmp("pool_list", argv[0]) == 0) {
5187 if (get_pools_path(fsname))
5188 return llapi_poollist(argv[1]);
5189 if (get_mgs_device() > 0)
5190 return llog_poollist(fsname, poolname);
5192 "Cannot run pool_list command since there is no local MGS/MDT or client\n");
5198 rc = pool_cmd(cmd, argv[0], argv[1], fsname, poolname, NULL);
5202 check_pool_cmd_result(cmd, fsname, poolname, NULL);
5206 char format[2 * MAX_OBD_NAME];
5208 if (strcmp("pool_remove", argv[0]) == 0)
5209 cmd = LCFG_POOL_REM;
5210 else if (strcmp("pool_add", argv[0]) == 0)
5211 cmd = LCFG_POOL_ADD;
5215 rc = extract_fsname_poolname(argv, fsname, poolname);
5219 for (i = 2; i < argc; i++) {
5222 array_sz = get_array_idx(argv[i], format, &array);
5226 cmds = malloc(array_sz * sizeof(cmds[0]));
5228 ostnames_buf = malloc(array_sz *
5229 (MAX_OBD_NAME + 1));
5236 for (j = 0; j < array_sz; j++) {
5237 char ostname[MAX_OBD_NAME + 1];
5240 snprintf(ostname, MAX_OBD_NAME, format,
5242 ostname[MAX_OBD_NAME] = '\0';
5244 rc2 = check_and_complete_ostname(fsname,
5256 &ostnames_buf[(MAX_OBD_NAME + 1) * j];
5257 strcpy(cmds[j].ostname, ostname);
5259 cmds[j].ostname = NULL;
5261 cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
5264 /* Return an err if any of the add/dels fail */
5268 for (j = 0; j < array_sz; j++) {
5270 char ostname[MAX_OBD_NAME + 1];
5272 if (!cmds[j].ostname) {
5273 snprintf(ostname, MAX_OBD_NAME,
5275 ostname[MAX_OBD_NAME] = '\0';
5276 check_and_complete_ostname(
5282 check_pool_cmd_result(cmd, fsname,
5307 #ifdef HAVE_SERVER_SUPPORT
5308 static const char *barrier_status2name(enum barrier_status status)
5313 case BS_FREEZING_P1:
5314 return "freezing_p1";
5315 case BS_FREEZING_P2:
5316 return "freezing_p2";
5334 int jt_barrier_freeze(int argc, char **argv)
5336 struct obd_ioctl_data data;
5337 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5338 struct barrier_ctl bc;
5341 if (argc < 2 || argc > 3)
5344 memset(&data, 0, sizeof(data));
5345 rc = data.ioc_dev = get_mgs_device();
5349 memset(&bc, 0, sizeof(bc));
5350 bc.bc_version = BARRIER_VERSION_V1;
5351 bc.bc_cmd = BC_FREEZE;
5353 bc.bc_timeout = atoi(argv[2]);
5354 if (bc.bc_timeout == 0)
5355 bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
5357 if (strlen(argv[1]) > 8) {
5359 "%s: fsname name %s is too long. It should not exceed 8.\n",
5364 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5365 data.ioc_inlbuf1 = (char *)&bc;
5366 data.ioc_inllen1 = sizeof(bc);
5367 memset(buf, 0, sizeof(rawbuf));
5368 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5370 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5374 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5376 fprintf(stderr, "Fail to freeze barrier for %s: %s\n",
5377 argv[1], strerror(errno));
5382 int jt_barrier_thaw(int argc, char **argv)
5384 struct obd_ioctl_data data;
5385 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5386 struct barrier_ctl bc;
5392 memset(&data, 0, sizeof(data));
5393 rc = data.ioc_dev = get_mgs_device();
5397 memset(&bc, 0, sizeof(bc));
5398 bc.bc_version = BARRIER_VERSION_V1;
5399 bc.bc_cmd = BC_THAW;
5401 if (strlen(argv[1]) > 8) {
5403 "fsname name %s is too long. It should not exceed 8.\n",
5408 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5409 data.ioc_inlbuf1 = (char *)&bc;
5410 data.ioc_inllen1 = sizeof(bc);
5411 memset(buf, 0, sizeof(rawbuf));
5412 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5414 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5418 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5420 fprintf(stderr, "Fail to thaw barrier for %s: %s\n",
5421 argv[1], strerror(errno));
5426 int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc)
5428 struct obd_ioctl_data data;
5429 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5432 memset(&data, 0, sizeof(data));
5433 rc = data.ioc_dev = get_mgs_device();
5437 memset(bc, 0, sizeof(*bc));
5438 bc->bc_version = BARRIER_VERSION_V1;
5439 bc->bc_cmd = BC_STAT;
5440 strncpy(bc->bc_name, fsname, sizeof(bc->bc_name) - 1);
5441 data.ioc_inlbuf1 = (char *)bc;
5442 data.ioc_inllen1 = sizeof(*bc);
5443 memset(buf, 0, sizeof(rawbuf));
5444 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5446 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5450 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5452 fprintf(stderr, "Fail to query barrier for %s: %s\n",
5453 fsname, strerror(errno));
5455 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5460 int jt_barrier_stat(int argc, char **argv)
5462 struct barrier_ctl bc;
5463 static struct option long_opt_barrier_stat[] = {
5467 .has_arg = no_argument,
5471 .has_arg = no_argument,
5482 bool timeout = false;
5484 while ((opt = getopt_long(argc, argv, "st", long_opt_barrier_stat,
5501 name = argv[optind];
5502 if (strlen(name) > 8) {
5504 "fsname name %s is too long. It should not exceed 8.\n",
5509 rc = __jt_barrier_stat(name, &bc);
5511 if (state && !timeout)
5512 printf("%s\n", barrier_status2name(bc.bc_status));
5513 else if (timeout && !state)
5515 (bc.bc_status == BS_FREEZING_P1 ||
5516 bc.bc_status == BS_FREEZING_P2 ||
5517 bc.bc_status == BS_FROZEN) ?
5520 printf("state: %s\ntimeout: %d seconds\n",
5521 barrier_status2name(bc.bc_status),
5522 (bc.bc_status == BS_FREEZING_P1 ||
5523 bc.bc_status == BS_FREEZING_P2 ||
5524 bc.bc_status == BS_FROZEN) ?
5531 int jt_barrier_rescan(int argc, char **argv)
5533 struct obd_ioctl_data data;
5534 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
5535 struct barrier_ctl bc;
5538 if (argc < 2 || argc > 3)
5541 memset(&data, 0, sizeof(data));
5542 rc = data.ioc_dev = get_mgs_device();
5546 memset(&bc, 0, sizeof(bc));
5547 bc.bc_version = BARRIER_VERSION_V1;
5548 bc.bc_cmd = BC_RESCAN;
5550 bc.bc_timeout = atoi(argv[2]);
5551 if (bc.bc_timeout == 0)
5552 bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
5554 if (strlen(argv[1]) > 8) {
5556 "fsname name %s is too long. It should not exceed 8.\n",
5561 strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name));
5562 data.ioc_inlbuf1 = (char *)&bc;
5563 data.ioc_inllen1 = sizeof(bc);
5564 memset(buf, 0, sizeof(rawbuf));
5565 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5567 fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc);
5571 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
5573 fprintf(stderr, "Fail to rescan barrier bitmap for %s: %s\n",
5574 argv[1], strerror(errno));
5576 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5577 printf("%u of %u MDT(s) in the filesystem %s are inactive\n",
5578 bc.bc_absence, bc.bc_total, argv[1]);
5583 #endif /* HAVE_SERVER_SUPPORT */
5585 int jt_get_obj_version(int argc, char **argv)
5588 struct obd_ioctl_data data;
5589 __u64 version, id = ULLONG_MAX, group = ULLONG_MAX;
5590 char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr;
5593 while ((c = getopt(argc, argv, "i:g:")) != -1) {
5596 id = strtoull(optarg, NULL, 0);
5599 group = strtoull(optarg, NULL, 0);
5607 fidstr = *(argv + optind);
5609 if (!(id != ULLONG_MAX && group != ULLONG_MAX && argc == 0) &&
5610 !(id == ULLONG_MAX && group == ULLONG_MAX && argc == 1))
5613 memset(&data, 0, sizeof(data));
5614 data.ioc_dev = cur_device;
5616 rc = llapi_fid_parse(fidstr, &fid, NULL);
5618 fprintf(stderr, "%s: error parsing FID '%s': %s\n",
5619 jt_cmdname(argv[0]), fidstr, strerror(-rc));
5623 data.ioc_inlbuf1 = (char *)&fid;
5624 data.ioc_inllen1 = sizeof(fid);
5626 data.ioc_inlbuf3 = (char *)&id;
5627 data.ioc_inllen3 = sizeof(id);
5628 data.ioc_inlbuf4 = (char *)&group;
5629 data.ioc_inllen4 = sizeof(group);
5631 data.ioc_inlbuf2 = (char *)&version;
5632 data.ioc_inllen2 = sizeof(version);
5634 memset(buf, 0, sizeof(*buf));
5635 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5637 fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
5638 jt_cmdname(argv[0]), strerror(-rc));
5642 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GET_OBJ_VERSION, buf);
5644 fprintf(stderr, "error: %s: ioctl: %s\n",
5645 jt_cmdname(argv[0]), strerror(errno));
5649 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5650 printf("%#jx\n", (uintmax_t)version);
5655 #ifdef HAVE_SERVER_SUPPORT
5656 int jt_changelog_register(int argc, char **argv)
5658 struct option long_opts[] = {
5659 { .val = 'h', .name = "help", .has_arg = no_argument },
5660 { .val = 'm', .name = "mask", .has_arg = required_argument },
5661 { .val = 'n', .name = "nameonly", .has_arg = no_argument },
5662 { .val = 'u', .name = "user", .has_arg = required_argument },
5664 struct obd_ioctl_data data = { 0 };
5665 char rawbuf[MAX_IOC_BUFLEN] = "";
5667 char *device = lcfg_get_devname();
5668 char *username = NULL, *usermask = NULL;
5669 bool print_name_only = false;
5673 if (cur_device < 0 || !device)
5676 while ((c = getopt_long(argc, argv, "hm:nu:", long_opts, NULL)) != -1) {
5679 usermask = strdup(optarg);
5682 "error: %s: %s: cannot copy '%s'\n",
5683 jt_cmdname(argv[0]), strerror(errno),
5689 print_name_only = true;
5692 username = strdup(optarg);
5695 "error: %s: %s: cannot copy '%s'\n",
5696 jt_cmdname(argv[0]), strerror(errno),
5709 data.ioc_dev = cur_device;
5711 data.ioc_inlbuf1 = username;
5712 data.ioc_inllen1 = strlen(username) + 1;
5716 data.ioc_inlbuf2 = usermask;
5717 data.ioc_inllen2 = strlen(usermask) + 1;
5720 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5722 fprintf(stderr, "error: %s: cannot pack ioctl: %s\n",
5723 jt_cmdname(argv[0]), strerror(-rc));
5726 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CHANGELOG_REG, buf);
5729 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
5730 rc == -EEXIST ? "User exists" : strerror(-rc));
5734 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5736 if (data.ioc_u32_1 == 0) {
5737 fprintf(stderr, "received invalid userid!\n");
5742 if (print_name_only)
5743 printf("%s%u%s%s\n", CHANGELOG_USER_PREFIX, data.ioc_u32_1,
5744 username ? "-" : "", username ? : "");
5746 printf("%s: Registered changelog userid '%s%u%s%s'\n",
5747 device, CHANGELOG_USER_PREFIX, data.ioc_u32_1,
5748 username ? "-" : "", username ? : "");
5755 int jt_changelog_deregister(int argc, char **argv)
5757 struct option long_opts[] = {
5758 { .val = 'h', .name = "help", .has_arg = no_argument },
5759 { .val = 'u', .name = "user", .has_arg = required_argument },
5761 struct obd_ioctl_data data = { 0 };
5762 char rawbuf[MAX_IOC_BUFLEN] = "";
5764 char *device = lcfg_get_devname();
5765 char *username = NULL;
5769 if (cur_device < 0 || !device)
5772 while ((c = getopt_long(argc, argv, "hu:", long_opts, NULL)) != -1) {
5775 username = strdup(optarg);
5778 "error: %s: %s: cannot copy '%s'\n",
5779 jt_cmdname(argv[0]), strerror(errno),
5791 if (1 == optind && argc > 1) {
5792 /* first check if pure ID was passed */
5793 id = atoi(argv[optind]);
5794 /* nameless cl<ID> format or cl<ID>-... format, only ID matters */
5796 sscanf(argv[optind], CHANGELOG_USER_PREFIX"%d", &id);
5798 /* no valid ID was parsed */
5802 "error: %s: expect <ID> or cl<ID>[-name] got '%s'\n",
5803 strerror(-rc), argv[optind]);
5809 if (optind < argc || argc == 1)
5812 data.ioc_dev = cur_device;
5813 data.ioc_u32_1 = id;
5815 data.ioc_inlbuf1 = username;
5816 data.ioc_inllen1 = strlen(username) + 1;
5819 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
5821 fprintf(stderr, "error: %s: invalid ioctl\n",
5822 jt_cmdname(argv[0]));
5826 rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CHANGELOG_DEREG, buf);
5829 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
5830 rc == -ENOENT ? "User not found" : strerror(-rc));
5834 llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
5835 printf("%s: Deregistered changelog user #%u\n", device, data.ioc_u32_1);
5839 #else /* !HAVE_SERVER_SUPPORT */
5840 int jt_changelog_register(int argc, char **argv)
5842 fprintf(stderr, "error: %s: invalid ioctl\n",
5843 jt_cmdname(argv[0]));
5847 int jt_changelog_deregister(int argc, char **argv)
5849 fprintf(stderr, "error: %s: invalid ioctl\n",
5850 jt_cmdname(argv[0]));
5853 #endif /* HAVE_SERVER_SUPPORT */
5855 int jt_pcc_add(int argc, char **argv)
5857 struct option long_opts[] = {
5858 { .val = 'p', .name = "param", .has_arg = required_argument },
5860 const char *mntpath;
5861 const char *pccpath;
5867 while ((rc = getopt_long(argc, argv, "p:", long_opts, NULL)) != -1) {
5878 fprintf(stderr, "%s: must specify the config param for PCC\n",
5879 jt_cmdname(argv[0]));
5883 if (optind + 2 != argc) {
5885 "%s: must specify mount path and PCC path %d:%d\n",
5886 jt_cmdname(argv[0]), optind, argc);
5890 mntpath = argv[optind++];
5891 pccpath = argv[optind];
5893 snprintf(cmd, PATH_MAX, "add %s %s", pccpath, param);
5894 rc = llapi_pccdev_set(mntpath, cmd);
5896 fprintf(stderr, "%s: failed to run '%s' on %s\n",
5897 jt_cmdname(argv[0]), cmd, mntpath);
5902 int jt_pcc_del(int argc, char **argv)
5904 const char *mntpath;
5905 const char *pccpath;
5911 fprintf(stderr, "%s: require 3 arguments\n",
5912 jt_cmdname(argv[0]));
5916 mntpath = argv[optind++];
5917 pccpath = argv[optind++];
5919 snprintf(cmd, PATH_MAX, "del %s", pccpath);
5920 rc = llapi_pccdev_set(mntpath, cmd);
5922 fprintf(stderr, "%s: failed to run '%s' on %s\n",
5923 jt_cmdname(argv[0]), cmd, mntpath);
5928 int jt_pcc_clear(int argc, char **argv)
5930 const char *mntpath;
5935 fprintf(stderr, "%s: require 2 arguments\n",
5936 jt_cmdname(argv[0]));
5940 mntpath = argv[optind];
5941 rc = llapi_pccdev_set(mntpath, "clear");
5943 fprintf(stderr, "%s: failed to run 'clear' on %s\n",
5944 jt_cmdname(argv[0]), mntpath);
5949 int jt_pcc_list(int argc, char **argv)
5951 const char *mntpath;
5956 fprintf(stderr, "%s: require 2 arguments\n",
5957 jt_cmdname(argv[0]));
5961 mntpath = argv[optind];
5962 rc = llapi_pccdev_get(mntpath);
5964 fprintf(stderr, "%s: failed to run 'pcc list' on %s\n",
5965 jt_cmdname(argv[0]), mntpath);