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 Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_recovery(int argc, char **argv);
52 static int jt_show_global(int argc, char **argv);
53 static int jt_set_tiny(int argc, char **argv);
54 static int jt_set_small(int argc, char **argv);
55 static int jt_set_large(int argc, char **argv);
56 static int jt_set_numa(int argc, char **argv);
57 static int jt_set_retry_count(int argc, char **argv);
58 static int jt_set_transaction_to(int argc, char **argv);
59 static int jt_set_hsensitivity(int argc, char **argv);
60 static int jt_add_peer_nid(int argc, char **argv);
61 static int jt_del_peer_nid(int argc, char **argv);
62 static int jt_set_max_intf(int argc, char **argv);
63 static int jt_set_discovery(int argc, char **argv);
64 static int jt_list_peer(int argc, char **argv);
65 /*static int jt_show_peer(int argc, char **argv);*/
66 static int lnetctl_list_commands(int argc, char **argv);
67 static int jt_import(int argc, char **argv);
68 static int jt_export(int argc, char **argv);
69 static int jt_ping(int argc, char **argv);
70 static int jt_discover(int argc, char **argv);
71 static int jt_lnet(int argc, char **argv);
72 static int jt_route(int argc, char **argv);
73 static int jt_net(int argc, char **argv);
74 static int jt_routing(int argc, char **argv);
75 static int jt_set(int argc, char **argv);
76 static int jt_debug(int argc, char **argv);
77 static int jt_stats(int argc, char **argv);
78 static int jt_global(int argc, char **argv);
79 static int jt_peers(int argc, char **argv);
80 static int jt_set_ni_value(int argc, char **argv);
81 static int jt_set_peer_ni_value(int argc, char **argv);
83 command_t cmd_list[] = {
84 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
85 {"route", jt_route, 0, "route {add | del | show | help}"},
86 {"net", jt_net, 0, "net {add | del | show | help}"},
87 {"routing", jt_routing, 0, "routing {show | help}"},
88 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
89 " | routing | numa_range | max_interfaces"
91 {"import", jt_import, 0, "import FILE.yaml"},
92 {"export", jt_export, 0, "export FILE.yaml"},
93 {"stats", jt_stats, 0, "stats {show | help}"},
94 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
95 {"global", jt_global, 0, "global {show | help}"},
96 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
97 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
98 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
99 {"help", Parser_help, 0, "help"},
100 {"exit", Parser_quit, 0, "quit"},
101 {"quit", Parser_quit, 0, "quit"},
102 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
106 command_t lnet_cmds[] = {
107 {"configure", jt_config_lnet, 0, "configure lnet\n"
108 "\t--all: load NI configuration from module parameters\n"},
109 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
113 command_t route_cmds[] = {
114 {"add", jt_add_route, 0, "add a route\n"
115 "\t--net: net name (e.g. tcp0)\n"
116 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
117 "\t--hop: number to final destination (1 < hops < 255)\n"
118 "\t--priority: priority of route (0 - highest prio\n"},
119 {"del", jt_del_route, 0, "delete a route\n"
120 "\t--net: net name (e.g. tcp0)\n"
121 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
122 {"show", jt_show_route, 0, "show routes\n"
123 "\t--net: net name (e.g. tcp0) to filter on\n"
124 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
125 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
126 "\t--priority: priority of route (0 - highest prio to filter on\n"
127 "\t--verbose: display detailed output per route\n"},
131 command_t net_cmds[] = {
132 {"add", jt_add_ni, 0, "add a network\n"
133 "\t--net: net name (e.g. tcp0)\n"
134 "\t--if: physical interface (e.g. eth0)\n"
135 "\t--ip2net: specify networks based on IP address patterns\n"
136 "\t--peer-timeout: time to wait before declaring a peer dead\n"
137 "\t--peer-credits: define the max number of inflight messages\n"
138 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
139 "\t--credits: Network Interface credits\n"
140 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
141 {"del", jt_del_ni, 0, "delete a network\n"
142 "\t--net: net name (e.g. tcp0)\n"
143 "\t--if: physical interface (e.g. eth0)\n"},
144 {"show", jt_show_net, 0, "show networks\n"
145 "\t--net: net name (e.g. tcp0) to filter on\n"
146 "\t--verbose: display detailed output per network."
147 " Optional argument of '2' outputs more stats\n"},
148 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
149 "\t--nid: NI NID to set the\n"
150 "\t--health: specify health value to set\n"
151 "\t--all: set all NIs value to the one specified\n"},
155 command_t routing_cmds[] = {
156 {"show", jt_show_routing, 0, "show routing information\n"},
160 command_t stats_cmds[] = {
161 {"show", jt_show_stats, 0, "show LNET statistics\n"},
165 command_t debug_cmds[] = {
166 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
167 "\t--local : list local recovery queue\n"
168 "\t--peer : list peer recovery queue\n"},
172 command_t global_cmds[] = {
173 {"show", jt_show_global, 0, "show global variables\n"},
177 command_t set_cmds[] = {
178 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
179 "\tVALUE must be greater than 0\n"},
180 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
181 "\tVALUE must be greater than 0\n"},
182 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
183 "\tVALUE must be greater than 0\n"},
184 {"routing", jt_set_routing, 0, "enable/disable routing\n"
185 "\t0 - disable routing\n"
186 "\t1 - enable routing\n"},
187 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
188 "\tVALUE must be at least 0\n"},
189 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
191 "\tValue must be greater than 16\n"},
192 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
193 "\t0 - disable peer discovery\n"
194 "\t1 - enable peer discovery (default)\n"},
195 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
196 "\t0 - turn of retries\n"
197 "\t>0 - number of retries\n"},
198 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
199 "\t>0 - timeout in seconds\n"},
200 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
201 "\t0 - turn off health evaluation\n"
202 "\t>0 - sensitivity value not more than 1000\n"},
206 command_t peer_cmds[] = {
207 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
208 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
209 "\t NID in the list becomes the Primary NID of a newly created\n"
211 "\t--nid: one or more peer NIDs\n"
212 "\t--non_mr: create this peer as not Multi-Rail capable\n"
213 "\t--ip2nets: specify a range of nids per peer"},
214 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
215 "\t--prim_nid: Primary NID of the peer.\n"
216 "\t--nid: list of NIDs to remove. If none provided,\n"
217 "\t peer is deleted\n"
218 "\t--ip2nets: specify a range of nids per peer"},
219 {"show", jt_show_peer, 0, "show peer information\n"
220 "\t--nid: NID of peer to filter on.\n"
221 "\t--verbose: display detailed output per peer."
222 " Optional argument of '2' outputs more stats\n"},
223 {"list", jt_list_peer, 0, "list all peers\n"},
224 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
225 "\t--nid: Peer NI NID to set the\n"
226 "\t--health: specify health value to set\n"
227 "\t--all: set all peer_nis values to the one specified\n"},
231 static inline void print_help(const command_t cmds[], const char *cmd_type,
234 const command_t *cmd;
236 for (cmd = cmds; cmd->pc_name; cmd++) {
237 if (pc_name != NULL &&
238 strcmp(cmd->pc_name, pc_name) == 0) {
239 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
242 } else if (pc_name != NULL) {
245 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
249 static int parse_long(const char *number, long int *value)
256 *value = strtol(number, &end, 0);
257 if (end != NULL && *end != 0)
263 static int check_cmd(const command_t *cmd_list, const char *cmd,
264 const char *sub_cmd, const int min_args,
265 int argc, char **argv)
272 const char *const short_options = "h";
273 static const struct option long_options[] = {
274 { .name = "help", .has_arg = no_argument, .val = 'h' },
278 if (argc < min_args) {
279 print_help(cmd_list, cmd, sub_cmd);
282 } else if (argc > 2) {
286 while ((opt = getopt_long(argc, argv, short_options,
287 long_options, NULL)) != -1) {
290 print_help(cmd_list, cmd, sub_cmd);
305 static int jt_set_max_intf(int argc, char **argv)
309 struct cYAML *err_rc = NULL;
311 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
315 rc = parse_long(argv[1], &value);
317 cYAML_build_error(-1, -1, "parser", "set",
318 "cannot parse max_interfaces value", &err_rc);
319 cYAML_print_tree2file(stderr, err_rc);
320 cYAML_free_tree(err_rc);
324 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
325 if (rc != LUSTRE_CFG_RC_NO_ERR)
326 cYAML_print_tree2file(stderr, err_rc);
328 cYAML_free_tree(err_rc);
333 static int jt_set_numa(int argc, char **argv)
337 struct cYAML *err_rc = NULL;
339 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
343 rc = parse_long(argv[1], &value);
345 cYAML_build_error(-1, -1, "parser", "set",
346 "cannot parse numa_range value", &err_rc);
347 cYAML_print_tree2file(stderr, err_rc);
348 cYAML_free_tree(err_rc);
352 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
353 if (rc != LUSTRE_CFG_RC_NO_ERR)
354 cYAML_print_tree2file(stderr, err_rc);
356 cYAML_free_tree(err_rc);
361 static int jt_set_hsensitivity(int argc, char **argv)
365 struct cYAML *err_rc = NULL;
367 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
371 rc = parse_long(argv[1], &value);
373 cYAML_build_error(-1, -1, "parser", "set",
374 "cannot parse health sensitivity value", &err_rc);
375 cYAML_print_tree2file(stderr, err_rc);
376 cYAML_free_tree(err_rc);
380 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
381 if (rc != LUSTRE_CFG_RC_NO_ERR)
382 cYAML_print_tree2file(stderr, err_rc);
384 cYAML_free_tree(err_rc);
389 static int jt_set_transaction_to(int argc, char **argv)
393 struct cYAML *err_rc = NULL;
395 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
399 rc = parse_long(argv[1], &value);
401 cYAML_build_error(-1, -1, "parser", "set",
402 "cannot parse transaction timeout value", &err_rc);
403 cYAML_print_tree2file(stderr, err_rc);
404 cYAML_free_tree(err_rc);
408 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
409 if (rc != LUSTRE_CFG_RC_NO_ERR)
410 cYAML_print_tree2file(stderr, err_rc);
412 cYAML_free_tree(err_rc);
417 static int jt_set_retry_count(int argc, char **argv)
421 struct cYAML *err_rc = NULL;
423 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
427 rc = parse_long(argv[1], &value);
429 cYAML_build_error(-1, -1, "parser", "set",
430 "cannot parse retry_count value", &err_rc);
431 cYAML_print_tree2file(stderr, err_rc);
432 cYAML_free_tree(err_rc);
436 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
437 if (rc != LUSTRE_CFG_RC_NO_ERR)
438 cYAML_print_tree2file(stderr, err_rc);
440 cYAML_free_tree(err_rc);
445 static int jt_set_discovery(int argc, char **argv)
449 struct cYAML *err_rc = NULL;
451 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
455 rc = parse_long(argv[1], &value);
457 cYAML_build_error(-1, -1, "parser", "set",
458 "cannot parse discovery value", &err_rc);
459 cYAML_print_tree2file(stderr, err_rc);
460 cYAML_free_tree(err_rc);
464 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
465 if (rc != LUSTRE_CFG_RC_NO_ERR)
466 cYAML_print_tree2file(stderr, err_rc);
468 cYAML_free_tree(err_rc);
473 static int jt_set_tiny(int argc, char **argv)
477 struct cYAML *err_rc = NULL;
479 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
483 rc = parse_long(argv[1], &value);
485 cYAML_build_error(-1, -1, "parser", "set",
486 "cannot parse tiny_buffers value", &err_rc);
487 cYAML_print_tree2file(stderr, err_rc);
488 cYAML_free_tree(err_rc);
492 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
493 if (rc != LUSTRE_CFG_RC_NO_ERR)
494 cYAML_print_tree2file(stderr, err_rc);
496 cYAML_free_tree(err_rc);
501 static int jt_set_small(int argc, char **argv)
505 struct cYAML *err_rc = NULL;
507 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
511 rc = parse_long(argv[1], &value);
513 cYAML_build_error(-1, -1, "parser", "set",
514 "cannot parse small_buffers value", &err_rc);
515 cYAML_print_tree2file(stderr, err_rc);
516 cYAML_free_tree(err_rc);
520 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
521 if (rc != LUSTRE_CFG_RC_NO_ERR)
522 cYAML_print_tree2file(stderr, err_rc);
524 cYAML_free_tree(err_rc);
529 static int jt_set_large(int argc, char **argv)
533 struct cYAML *err_rc = NULL;
535 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
539 rc = parse_long(argv[1], &value);
541 cYAML_build_error(-1, -1, "parser", "set",
542 "cannot parse large_buffers value", &err_rc);
543 cYAML_print_tree2file(stderr, err_rc);
544 cYAML_free_tree(err_rc);
548 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
549 if (rc != LUSTRE_CFG_RC_NO_ERR)
550 cYAML_print_tree2file(stderr, err_rc);
552 cYAML_free_tree(err_rc);
557 static int jt_set_routing(int argc, char **argv)
560 struct cYAML *err_rc = NULL;
563 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
567 rc = parse_long(argv[1], &value);
568 if (rc != 0 || (value != 0 && value != 1)) {
569 cYAML_build_error(-1, -1, "parser", "set",
570 "cannot parse routing value.\n"
571 "must be 0 for disable or 1 for enable",
573 cYAML_print_tree2file(stderr, err_rc);
574 cYAML_free_tree(err_rc);
578 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
580 if (rc != LUSTRE_CFG_RC_NO_ERR)
581 cYAML_print_tree2file(stderr, err_rc);
583 cYAML_free_tree(err_rc);
588 static int jt_config_lnet(int argc, char **argv)
590 struct cYAML *err_rc = NULL;
591 bool load_mod_params = false;
594 const char *const short_options = "a";
595 static const struct option long_options[] = {
596 { .name = "all", .has_arg = no_argument, .val = 'a' },
600 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
604 while ((opt = getopt_long(argc, argv, short_options,
605 long_options, NULL)) != -1) {
608 load_mod_params = true;
615 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
618 if (rc != LUSTRE_CFG_RC_NO_ERR)
619 cYAML_print_tree2file(stderr, err_rc);
621 cYAML_free_tree(err_rc);
626 static int jt_unconfig_lnet(int argc, char **argv)
628 struct cYAML *err_rc = NULL;
631 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
635 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
637 if (rc != LUSTRE_CFG_RC_NO_ERR)
638 cYAML_print_tree2file(stderr, err_rc);
640 cYAML_free_tree(err_rc);
644 static int jt_add_route(int argc, char **argv)
646 char *network = NULL, *gateway = NULL;
647 long int hop = -1, prio = -1;
648 struct cYAML *err_rc = NULL;
651 const char *const short_options = "n:g:c:p:";
652 static const struct option long_options[] = {
653 { .name = "net", .has_arg = required_argument, .val = 'n' },
654 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
655 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
656 { .name = "priority", .has_arg = required_argument, .val = 'p' },
659 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
663 while ((opt = getopt_long(argc, argv, short_options,
664 long_options, NULL)) != -1) {
673 rc = parse_long(optarg, &hop);
681 rc = parse_long(optarg, &prio);
689 print_help(route_cmds, "route", "add");
695 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
697 if (rc != LUSTRE_CFG_RC_NO_ERR)
698 cYAML_print_tree2file(stderr, err_rc);
700 cYAML_free_tree(err_rc);
705 static int jt_add_ni(int argc, char **argv)
708 long int pto = -1, pc = -1, pbc = -1, cre = -1;
709 struct cYAML *err_rc = NULL;
710 int rc, opt, cpt_rc = -1;
711 struct lnet_dlc_network_descr nw_descr;
712 struct cfs_expr_list *global_cpts = NULL;
713 struct lnet_ioctl_config_lnd_tunables tunables;
716 memset(&tunables, 0, sizeof(tunables));
717 lustre_lnet_init_nw_descr(&nw_descr);
719 const char *const short_options = "n:i:p:t:c:b:r:s:";
720 static const struct option long_options[] = {
721 { .name = "net", .has_arg = required_argument, .val = 'n' },
722 { .name = "if", .has_arg = required_argument, .val = 'i' },
723 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
724 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
725 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
726 { .name = "peer-buffer-credits",
727 .has_arg = required_argument, .val = 'b' },
728 { .name = "credits", .has_arg = required_argument, .val = 'r' },
729 { .name = "cpt", .has_arg = required_argument, .val = 's' },
732 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
736 while ((opt = getopt_long(argc, argv, short_options,
737 long_options, NULL)) != -1) {
740 nw_descr.nw_id = libcfs_str2net(optarg);
743 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
745 cYAML_build_error(-1, -1, "ni", "add",
746 "bad interface list",
755 rc = parse_long(optarg, &pto);
763 rc = parse_long(optarg, &pc);
771 rc = parse_long(optarg, &pbc);
779 rc = parse_long(optarg, &cre);
787 cpt_rc = cfs_expr_list_parse(optarg,
789 UINT_MAX, &global_cpts);
792 print_help(net_cmds, "net", "add");
798 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
799 tunables.lt_cmn.lct_peer_timeout = pto;
800 tunables.lt_cmn.lct_peer_tx_credits = pc;
801 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
802 tunables.lt_cmn.lct_max_tx_credits = cre;
806 rc = lustre_lnet_config_ni(&nw_descr,
807 (cpt_rc == 0) ? global_cpts: NULL,
808 ip2net, (found) ? &tunables : NULL,
811 if (global_cpts != NULL)
812 cfs_expr_list_free(global_cpts);
815 if (rc != LUSTRE_CFG_RC_NO_ERR)
816 cYAML_print_tree2file(stderr, err_rc);
818 cYAML_free_tree(err_rc);
823 static int jt_del_route(int argc, char **argv)
825 char *network = NULL, *gateway = NULL;
826 struct cYAML *err_rc = NULL;
829 const char *const short_options = "n:g:";
830 static const struct option long_options[] = {
831 { .name = "net", .has_arg = required_argument, .val = 'n' },
832 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
835 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
839 while ((opt = getopt_long(argc, argv, short_options,
840 long_options, NULL)) != -1) {
849 print_help(route_cmds, "route", "del");
855 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
857 if (rc != LUSTRE_CFG_RC_NO_ERR)
858 cYAML_print_tree2file(stderr, err_rc);
860 cYAML_free_tree(err_rc);
865 static int jt_del_ni(int argc, char **argv)
867 struct cYAML *err_rc = NULL;
869 struct lnet_dlc_network_descr nw_descr;
871 lustre_lnet_init_nw_descr(&nw_descr);
873 const char *const short_options = "n:i:";
874 static const struct option long_options[] = {
875 { .name = "net", .has_arg = required_argument, .val = 'n' },
876 { .name = "if", .has_arg = required_argument, .val = 'i' },
879 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
883 while ((opt = getopt_long(argc, argv, short_options,
884 long_options, NULL)) != -1) {
887 nw_descr.nw_id = libcfs_str2net(optarg);
890 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
892 cYAML_build_error(-1, -1, "ni", "add",
893 "bad interface list",
899 print_help(net_cmds, "net", "del");
905 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
908 if (rc != LUSTRE_CFG_RC_NO_ERR)
909 cYAML_print_tree2file(stderr, err_rc);
911 cYAML_free_tree(err_rc);
916 static int jt_show_route(int argc, char **argv)
918 char *network = NULL, *gateway = NULL;
919 long int hop = -1, prio = -1;
920 int detail = 0, rc, opt;
921 struct cYAML *err_rc = NULL, *show_rc = NULL;
923 const char *const short_options = "n:g:h:p:v";
924 static const struct option long_options[] = {
925 { .name = "net", .has_arg = required_argument, .val = 'n' },
926 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
927 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
928 { .name = "priority", .has_arg = required_argument, .val = 'p' },
929 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
932 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
936 while ((opt = getopt_long(argc, argv, short_options,
937 long_options, NULL)) != -1) {
946 rc = parse_long(optarg, &hop);
954 rc = parse_long(optarg, &prio);
965 print_help(route_cmds, "route", "show");
971 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
972 &show_rc, &err_rc, false);
974 if (rc != LUSTRE_CFG_RC_NO_ERR)
975 cYAML_print_tree2file(stderr, err_rc);
977 cYAML_print_tree(show_rc);
979 cYAML_free_tree(err_rc);
980 cYAML_free_tree(show_rc);
985 static int set_value_helper(int argc, char **argv,
986 int (*cb)(int, bool, char*, int, struct cYAML**))
989 long int healthv = -1;
992 struct cYAML *err_rc = NULL;
994 const char *const short_options = "t:n:a";
995 static const struct option long_options[] = {
996 { .name = "nid", .has_arg = required_argument, .val = 'n' },
997 { .name = "health", .has_arg = required_argument, .val = 't' },
998 { .name = "all", .has_arg = no_argument, .val = 'a' },
1001 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1005 while ((opt = getopt_long(argc, argv, short_options,
1006 long_options, NULL)) != -1) {
1012 if (parse_long(optarg, &healthv) != 0)
1023 rc = cb(healthv, all, nid, -1, &err_rc);
1025 if (rc != LUSTRE_CFG_RC_NO_ERR)
1026 cYAML_print_tree2file(stderr, err_rc);
1028 cYAML_free_tree(err_rc);
1033 static int jt_set_ni_value(int argc, char **argv)
1035 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1038 static int jt_set_peer_ni_value(int argc, char **argv)
1040 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1043 static int jt_show_recovery(int argc, char **argv)
1046 struct cYAML *err_rc = NULL, *show_rc = NULL;
1048 const char *const short_options = "lp";
1049 static const struct option long_options[] = {
1050 { .name = "local", .has_arg = no_argument, .val = 'l' },
1051 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1054 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1058 while ((opt = getopt_long(argc, argv, short_options,
1059 long_options, NULL)) != -1) {
1062 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1065 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1072 if (rc != LUSTRE_CFG_RC_NO_ERR)
1073 cYAML_print_tree2file(stderr, err_rc);
1075 cYAML_print_tree(show_rc);
1077 cYAML_free_tree(err_rc);
1078 cYAML_free_tree(show_rc);
1083 static int jt_show_net(int argc, char **argv)
1085 char *network = NULL;
1087 struct cYAML *err_rc = NULL, *show_rc = NULL;
1088 long int detail = 0;
1090 const char *const short_options = "n:v";
1091 static const struct option long_options[] = {
1092 { .name = "net", .has_arg = required_argument, .val = 'n' },
1093 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1096 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1100 while ((opt = getopt_long(argc, argv, short_options,
1101 long_options, NULL)) != -1) {
1107 if ((!optarg) && (argv[optind] != NULL) &&
1108 (argv[optind][0] != '-')) {
1109 if (parse_long(argv[optind++], &detail) != 0)
1116 print_help(net_cmds, "net", "show");
1122 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1125 if (rc != LUSTRE_CFG_RC_NO_ERR)
1126 cYAML_print_tree2file(stderr, err_rc);
1128 cYAML_print_tree(show_rc);
1130 cYAML_free_tree(err_rc);
1131 cYAML_free_tree(show_rc);
1136 static int jt_show_routing(int argc, char **argv)
1138 struct cYAML *err_rc = NULL, *show_rc = NULL;
1141 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1145 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1147 if (rc != LUSTRE_CFG_RC_NO_ERR)
1148 cYAML_print_tree2file(stderr, err_rc);
1150 cYAML_print_tree(show_rc);
1152 cYAML_free_tree(err_rc);
1153 cYAML_free_tree(show_rc);
1158 static int jt_show_stats(int argc, char **argv)
1161 struct cYAML *show_rc = NULL, *err_rc = NULL;
1163 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1167 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1169 if (rc != LUSTRE_CFG_RC_NO_ERR)
1170 cYAML_print_tree2file(stderr, err_rc);
1172 cYAML_print_tree(show_rc);
1174 cYAML_free_tree(err_rc);
1175 cYAML_free_tree(show_rc);
1180 static int jt_show_global(int argc, char **argv)
1183 struct cYAML *show_rc = NULL, *err_rc = NULL;
1185 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1189 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1190 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1191 cYAML_print_tree2file(stderr, err_rc);
1195 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1196 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1197 cYAML_print_tree2file(stderr, err_rc);
1201 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1202 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1203 cYAML_print_tree2file(stderr, err_rc);
1207 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1208 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1209 cYAML_print_tree2file(stderr, err_rc);
1213 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1214 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1215 cYAML_print_tree2file(stderr, err_rc);
1219 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1220 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1221 cYAML_print_tree2file(stderr, err_rc);
1226 cYAML_print_tree(show_rc);
1229 cYAML_free_tree(err_rc);
1230 cYAML_free_tree(show_rc);
1235 static int jt_lnet(int argc, char **argv)
1239 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1243 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1246 static int jt_route(int argc, char **argv)
1250 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1254 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1257 static int jt_net(int argc, char **argv)
1261 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1265 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1268 static int jt_routing(int argc, char **argv)
1272 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1276 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1279 static int jt_stats(int argc, char **argv)
1283 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1287 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1290 static int jt_debug(int argc, char **argv)
1294 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1298 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1301 static int jt_global(int argc, char **argv)
1305 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1309 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1312 static int jt_peers(int argc, char **argv)
1316 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1320 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1323 static int jt_set(int argc, char **argv)
1327 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1331 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1334 static int jt_import(int argc, char **argv)
1337 struct cYAML *err_rc = NULL;
1338 struct cYAML *show_rc = NULL;
1339 int rc = 0, return_rc = 0, opt, opt_found = 0;
1342 const char *const short_options = "adseh";
1343 static const struct option long_options[] = {
1344 { .name = "add", .has_arg = no_argument, .val = 'a' },
1345 { .name = "del", .has_arg = no_argument, .val = 'd' },
1346 { .name = "show", .has_arg = no_argument, .val = 's' },
1347 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1348 { .name = "help", .has_arg = no_argument, .val = 'h' },
1351 while ((opt = getopt_long(argc, argv, short_options,
1352 long_options, NULL)) != -1) {
1366 printf("import FILE\n"
1367 "import < FILE : import a file\n"
1368 "\t--add: add configuration\n"
1369 "\t--del: delete configuration\n"
1370 "\t--show: show configuration\n"
1371 "\t--exec: execute command\n"
1372 "\t--help: display this help\n"
1373 "If no command option is given then --add"
1374 " is assumed by default\n");
1381 /* grab the file name if one exists */
1382 if (opt_found && argc == 3)
1384 else if (!opt_found && argc == 2)
1389 rc = lustre_yaml_config(file, &err_rc);
1390 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1391 cYAML_print_tree(show_rc);
1392 cYAML_free_tree(show_rc);
1395 rc = lustre_yaml_del(file, &err_rc);
1398 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1399 cYAML_print_tree(show_rc);
1400 cYAML_free_tree(show_rc);
1403 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1404 cYAML_print_tree(show_rc);
1405 cYAML_free_tree(show_rc);
1409 if (rc || return_rc) {
1410 cYAML_print_tree2file(stderr, err_rc);
1411 cYAML_free_tree(err_rc);
1417 static int jt_export(int argc, char **argv)
1419 struct cYAML *show_rc = NULL;
1420 struct cYAML *err_rc = NULL;
1424 bool backup = false;
1427 const char *const short_options = "bh";
1428 static const struct option long_options[] = {
1429 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1430 { .name = "help", .has_arg = no_argument, .val = 'h' },
1433 while ((opt = getopt_long(argc, argv, short_options,
1434 long_options, NULL)) != -1) {
1441 printf("export > FILE.yaml : export configuration\n"
1442 "\t--backup: export only what's necessary for reconfig\n"
1443 "\t--help: display this help\n");
1448 if (backup && argc >= 3)
1450 else if (!backup && argc >= 2)
1456 f = fopen(file, "w");
1461 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1462 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1463 cYAML_print_tree2file(stderr, err_rc);
1464 cYAML_free_tree(err_rc);
1468 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1470 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1471 cYAML_print_tree2file(stderr, err_rc);
1472 cYAML_free_tree(err_rc);
1476 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1477 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1478 cYAML_print_tree2file(stderr, err_rc);
1479 cYAML_free_tree(err_rc);
1483 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1484 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1485 cYAML_print_tree2file(stderr, err_rc);
1486 cYAML_free_tree(err_rc);
1490 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1491 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1492 cYAML_print_tree2file(stderr, err_rc);
1493 cYAML_free_tree(err_rc);
1497 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1498 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1499 cYAML_print_tree2file(stderr, err_rc);
1500 cYAML_free_tree(err_rc);
1504 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1505 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1506 cYAML_print_tree2file(stderr, err_rc);
1507 cYAML_free_tree(err_rc);
1511 if (show_rc != NULL) {
1512 cYAML_print_tree2file(f, show_rc);
1513 cYAML_free_tree(show_rc);
1522 static int jt_add_peer_nid(int argc, char **argv)
1524 char *prim_nid = NULL;
1525 char **nids = NULL, **nids2 = NULL;
1527 struct cYAML *err_rc = NULL;
1528 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1529 bool non_mr = false;
1530 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1532 const char *const short_opts = "k:mn:";
1533 const struct option long_opts[] = {
1534 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1535 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1536 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1537 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1540 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1544 while ((opt = getopt_long(argc, argv, short_opts,
1545 long_opts, NULL)) != -1) {
1548 prim_nid_present = true;
1550 cYAML_build_error(-1, -1, "peer", "add",
1551 "ip2nets can not be specified"
1552 " along side prim_nid parameter.",
1566 if (ip2nets && (nid_list || prim_nid_present)) {
1567 cYAML_build_error(-1, -1, "peer", "add",
1568 "ip2nets can not be specified"
1569 " along side nid or prim_nid"
1570 " parameters", &err_rc);
1574 size = lustre_lnet_parse_nids(optarg, nids, size,
1579 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1585 print_help(peer_cmds, "peer", "add");
1591 for (; optind < argc; optind++) {
1592 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1599 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1600 !non_mr, ip2nets, -1, &err_rc);
1604 /* free the array of nids */
1605 for (i = 0; i < size; i++)
1610 if (rc != LUSTRE_CFG_RC_NO_ERR)
1611 cYAML_print_tree2file(stderr, err_rc);
1613 cYAML_free_tree(err_rc);
1618 static int jt_del_peer_nid(int argc, char **argv)
1620 char *prim_nid = NULL;
1621 char **nids = NULL, **nids2 = NULL;
1622 struct cYAML *err_rc = NULL;
1623 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1624 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1626 const char *const short_opts = "k:n:";
1627 const struct option long_opts[] = {
1628 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1629 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1630 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1633 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1637 while ((opt = getopt_long(argc, argv, short_opts,
1638 long_opts, NULL)) != -1) {
1641 prim_nid_present = true;
1643 cYAML_build_error(-1, -1, "peer", "add",
1644 "ip2nets can not be specified"
1645 " along side prim_nid parameter.",
1659 if (ip2nets && (nid_list || prim_nid_present)) {
1660 cYAML_build_error(-1, -1, "peer", "add",
1661 "ip2nets can not be specified"
1662 " along side nid or prim_nid"
1663 " parameters", &err_rc);
1666 size = lustre_lnet_parse_nids(optarg, nids, size,
1671 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1674 print_help(peer_cmds, "peer", "del");
1680 for (; optind < argc; optind++) {
1681 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1688 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1692 for (i = 0; i < size; i++)
1697 if (rc != LUSTRE_CFG_RC_NO_ERR)
1698 cYAML_print_tree2file(stderr, err_rc);
1700 cYAML_free_tree(err_rc);
1705 static int jt_show_peer(int argc, char **argv)
1709 struct cYAML *err_rc = NULL, *show_rc = NULL;
1710 long int detail = 0;
1712 const char *const short_opts = "hn:v::";
1713 const struct option long_opts[] = {
1714 { .name = "help", .has_arg = no_argument, .val = 'h' },
1715 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1716 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1719 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1723 while ((opt = getopt_long(argc, argv, short_opts,
1724 long_opts, NULL)) != -1) {
1730 if ((!optarg) && (argv[optind] != NULL) &&
1731 (argv[optind][0] != '-')) {
1732 if (parse_long(argv[optind++], &detail) != 0)
1739 print_help(peer_cmds, "peer", "show");
1745 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1748 if (rc != LUSTRE_CFG_RC_NO_ERR)
1749 cYAML_print_tree2file(stderr, err_rc);
1751 cYAML_print_tree(show_rc);
1753 cYAML_free_tree(err_rc);
1754 cYAML_free_tree(show_rc);
1759 static int jt_list_peer(int argc, char **argv)
1762 struct cYAML *err_rc = NULL, *list_rc = NULL;
1764 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1768 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1770 if (rc != LUSTRE_CFG_RC_NO_ERR)
1771 cYAML_print_tree2file(stderr, err_rc);
1773 cYAML_print_tree(list_rc);
1775 cYAML_free_tree(err_rc);
1776 cYAML_free_tree(list_rc);
1781 static int jt_ping(int argc, char **argv)
1783 struct cYAML *err_rc = NULL;
1784 struct cYAML *show_rc = NULL;
1788 const char *const short_options = "ht:";
1789 const struct option long_options[] = {
1790 { .name = "help", .has_arg = no_argument, .val = 'h' },
1791 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1794 while ((opt = getopt_long(argc, argv, short_options,
1795 long_options, NULL)) != -1) {
1798 timeout = 1000 * atol(optarg);
1801 printf("ping nid[,nid,...]\n"
1802 "\t --timeout: ping timeout\n"
1803 "\t --help: display this help\n");
1810 for (; optind < argc; optind++)
1811 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1814 cYAML_print_tree(show_rc);
1817 cYAML_print_tree2file(stderr, err_rc);
1819 cYAML_free_tree(err_rc);
1820 cYAML_free_tree(show_rc);
1825 static int jt_discover(int argc, char **argv)
1827 struct cYAML *err_rc = NULL;
1828 struct cYAML *show_rc = NULL;
1832 const char *const short_options = "fh";
1833 const struct option long_options[] = {
1834 { .name = "force", .has_arg = no_argument, .val = 'f' },
1835 { .name = "help", .has_arg = no_argument, .val = 'h' },
1838 while ((opt = getopt_long(argc, argv, short_options,
1839 long_options, NULL)) != -1) {
1845 printf("discover nid[,nid,...]\n"
1846 "\t --force: force discovery\n"
1847 "\t --help: display this help\n");
1854 for (; optind < argc; optind++)
1855 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1859 cYAML_print_tree(show_rc);
1862 cYAML_print_tree2file(stderr, err_rc);
1864 cYAML_free_tree(err_rc);
1865 cYAML_free_tree(show_rc);
1870 static int lnetctl_list_commands(int argc, char **argv)
1872 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1874 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1879 int main(int argc, char **argv)
1882 struct cYAML *err_rc = NULL;
1884 rc = lustre_lnet_config_lib_init();
1886 cYAML_build_error(-1, -1, "lnetctl", "startup",
1887 "cannot register LNet device", &err_rc);
1888 cYAML_print_tree2file(stderr, err_rc);
1892 Parser_init("lnetctl > ", cmd_list);
1894 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);