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);
693 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
695 if (rc != LUSTRE_CFG_RC_NO_ERR)
696 cYAML_print_tree2file(stderr, err_rc);
698 cYAML_free_tree(err_rc);
703 static int jt_add_ni(int argc, char **argv)
706 long int pto = -1, pc = -1, pbc = -1, cre = -1;
707 struct cYAML *err_rc = NULL;
708 int rc, opt, cpt_rc = -1;
709 struct lnet_dlc_network_descr nw_descr;
710 struct cfs_expr_list *global_cpts = NULL;
711 struct lnet_ioctl_config_lnd_tunables tunables;
714 memset(&tunables, 0, sizeof(tunables));
715 lustre_lnet_init_nw_descr(&nw_descr);
717 const char *const short_options = "n:i:p:t:c:b:r:s:";
718 static const struct option long_options[] = {
719 { .name = "net", .has_arg = required_argument, .val = 'n' },
720 { .name = "if", .has_arg = required_argument, .val = 'i' },
721 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
722 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
723 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
724 { .name = "peer-buffer-credits",
725 .has_arg = required_argument, .val = 'b' },
726 { .name = "credits", .has_arg = required_argument, .val = 'r' },
727 { .name = "cpt", .has_arg = required_argument, .val = 's' },
730 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
734 while ((opt = getopt_long(argc, argv, short_options,
735 long_options, NULL)) != -1) {
738 nw_descr.nw_id = libcfs_str2net(optarg);
741 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
743 cYAML_build_error(-1, -1, "ni", "add",
744 "bad interface list",
753 rc = parse_long(optarg, &pto);
761 rc = parse_long(optarg, &pc);
769 rc = parse_long(optarg, &pbc);
777 rc = parse_long(optarg, &cre);
785 cpt_rc = cfs_expr_list_parse(optarg,
787 UINT_MAX, &global_cpts);
794 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
795 tunables.lt_cmn.lct_peer_timeout = pto;
796 tunables.lt_cmn.lct_peer_tx_credits = pc;
797 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
798 tunables.lt_cmn.lct_max_tx_credits = cre;
802 rc = lustre_lnet_config_ni(&nw_descr,
803 (cpt_rc == 0) ? global_cpts: NULL,
804 ip2net, (found) ? &tunables : NULL,
807 if (global_cpts != NULL)
808 cfs_expr_list_free(global_cpts);
811 if (rc != LUSTRE_CFG_RC_NO_ERR)
812 cYAML_print_tree2file(stderr, err_rc);
814 cYAML_free_tree(err_rc);
819 static int jt_del_route(int argc, char **argv)
821 char *network = NULL, *gateway = NULL;
822 struct cYAML *err_rc = NULL;
825 const char *const short_options = "n:g:";
826 static const struct option long_options[] = {
827 { .name = "net", .has_arg = required_argument, .val = 'n' },
828 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
831 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
835 while ((opt = getopt_long(argc, argv, short_options,
836 long_options, NULL)) != -1) {
849 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
851 if (rc != LUSTRE_CFG_RC_NO_ERR)
852 cYAML_print_tree2file(stderr, err_rc);
854 cYAML_free_tree(err_rc);
859 static int jt_del_ni(int argc, char **argv)
861 struct cYAML *err_rc = NULL;
863 struct lnet_dlc_network_descr nw_descr;
865 lustre_lnet_init_nw_descr(&nw_descr);
867 const char *const short_options = "n:i:";
868 static const struct option long_options[] = {
869 { .name = "net", .has_arg = required_argument, .val = 'n' },
870 { .name = "if", .has_arg = required_argument, .val = 'i' },
873 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
877 while ((opt = getopt_long(argc, argv, short_options,
878 long_options, NULL)) != -1) {
881 nw_descr.nw_id = libcfs_str2net(optarg);
884 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
886 cYAML_build_error(-1, -1, "ni", "add",
887 "bad interface list",
897 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
900 if (rc != LUSTRE_CFG_RC_NO_ERR)
901 cYAML_print_tree2file(stderr, err_rc);
903 cYAML_free_tree(err_rc);
908 static int jt_show_route(int argc, char **argv)
910 char *network = NULL, *gateway = NULL;
911 long int hop = -1, prio = -1;
912 int detail = 0, rc, opt;
913 struct cYAML *err_rc = NULL, *show_rc = NULL;
915 const char *const short_options = "n:g:h:p:v";
916 static const struct option long_options[] = {
917 { .name = "net", .has_arg = required_argument, .val = 'n' },
918 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
919 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
920 { .name = "priority", .has_arg = required_argument, .val = 'p' },
921 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
924 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
928 while ((opt = getopt_long(argc, argv, short_options,
929 long_options, NULL)) != -1) {
938 rc = parse_long(optarg, &hop);
946 rc = parse_long(optarg, &prio);
961 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
962 &show_rc, &err_rc, false);
964 if (rc != LUSTRE_CFG_RC_NO_ERR)
965 cYAML_print_tree2file(stderr, err_rc);
967 cYAML_print_tree(show_rc);
969 cYAML_free_tree(err_rc);
970 cYAML_free_tree(show_rc);
975 static int set_value_helper(int argc, char **argv,
976 int (*cb)(int, bool, char*, int, struct cYAML**))
979 long int healthv = -1;
982 struct cYAML *err_rc = NULL;
984 const char *const short_options = "h:n:a";
985 static const struct option long_options[] = {
986 { .name = "nid", .has_arg = required_argument, .val = 'n' },
987 { .name = "health", .has_arg = required_argument, .val = 'h' },
988 { .name = "all", .has_arg = no_argument, .val = 'a' },
991 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
995 while ((opt = getopt_long(argc, argv, short_options,
996 long_options, NULL)) != -1) {
1002 if (parse_long(argv[optind++], &healthv) != 0)
1012 rc = cb(healthv, all, nid, -1, &err_rc);
1014 if (rc != LUSTRE_CFG_RC_NO_ERR)
1015 cYAML_print_tree2file(stderr, err_rc);
1017 cYAML_free_tree(err_rc);
1022 static int jt_set_ni_value(int argc, char **argv)
1024 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1027 static int jt_set_peer_ni_value(int argc, char **argv)
1029 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1032 static int jt_show_recovery(int argc, char **argv)
1035 struct cYAML *err_rc = NULL, *show_rc = NULL;
1037 const char *const short_options = "lp";
1038 static const struct option long_options[] = {
1039 { .name = "local", .has_arg = no_argument, .val = 'l' },
1040 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1043 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1047 while ((opt = getopt_long(argc, argv, short_options,
1048 long_options, NULL)) != -1) {
1051 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1054 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1061 if (rc != LUSTRE_CFG_RC_NO_ERR)
1062 cYAML_print_tree2file(stderr, err_rc);
1064 cYAML_print_tree(show_rc);
1066 cYAML_free_tree(err_rc);
1067 cYAML_free_tree(show_rc);
1072 static int jt_show_net(int argc, char **argv)
1074 char *network = NULL;
1076 struct cYAML *err_rc = NULL, *show_rc = NULL;
1077 long int detail = 0;
1079 const char *const short_options = "n:v";
1080 static const struct option long_options[] = {
1081 { .name = "net", .has_arg = required_argument, .val = 'n' },
1082 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1085 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1089 while ((opt = getopt_long(argc, argv, short_options,
1090 long_options, NULL)) != -1) {
1096 if ((!optarg) && (argv[optind] != NULL) &&
1097 (argv[optind][0] != '-')) {
1098 if (parse_long(argv[optind++], &detail) != 0)
1109 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1112 if (rc != LUSTRE_CFG_RC_NO_ERR)
1113 cYAML_print_tree2file(stderr, err_rc);
1115 cYAML_print_tree(show_rc);
1117 cYAML_free_tree(err_rc);
1118 cYAML_free_tree(show_rc);
1123 static int jt_show_routing(int argc, char **argv)
1125 struct cYAML *err_rc = NULL, *show_rc = NULL;
1128 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1132 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1134 if (rc != LUSTRE_CFG_RC_NO_ERR)
1135 cYAML_print_tree2file(stderr, err_rc);
1137 cYAML_print_tree(show_rc);
1139 cYAML_free_tree(err_rc);
1140 cYAML_free_tree(show_rc);
1145 static int jt_show_stats(int argc, char **argv)
1148 struct cYAML *show_rc = NULL, *err_rc = NULL;
1150 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1154 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1156 if (rc != LUSTRE_CFG_RC_NO_ERR)
1157 cYAML_print_tree2file(stderr, err_rc);
1159 cYAML_print_tree(show_rc);
1161 cYAML_free_tree(err_rc);
1162 cYAML_free_tree(show_rc);
1167 static int jt_show_global(int argc, char **argv)
1170 struct cYAML *show_rc = NULL, *err_rc = NULL;
1172 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1176 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1177 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1178 cYAML_print_tree2file(stderr, err_rc);
1182 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1183 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1184 cYAML_print_tree2file(stderr, err_rc);
1188 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1189 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1190 cYAML_print_tree2file(stderr, err_rc);
1194 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1195 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1196 cYAML_print_tree2file(stderr, err_rc);
1200 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1201 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1202 cYAML_print_tree2file(stderr, err_rc);
1206 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1207 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1208 cYAML_print_tree2file(stderr, err_rc);
1213 cYAML_print_tree(show_rc);
1216 cYAML_free_tree(err_rc);
1217 cYAML_free_tree(show_rc);
1222 static int jt_lnet(int argc, char **argv)
1226 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1230 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1233 static int jt_route(int argc, char **argv)
1237 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1241 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1244 static int jt_net(int argc, char **argv)
1248 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1252 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1255 static int jt_routing(int argc, char **argv)
1259 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1263 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1266 static int jt_stats(int argc, char **argv)
1270 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1274 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1277 static int jt_debug(int argc, char **argv)
1281 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1285 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1288 static int jt_global(int argc, char **argv)
1292 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1296 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1299 static int jt_peers(int argc, char **argv)
1303 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1307 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1310 static int jt_set(int argc, char **argv)
1314 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1318 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1321 static int jt_import(int argc, char **argv)
1324 struct cYAML *err_rc = NULL;
1325 struct cYAML *show_rc = NULL;
1326 int rc = 0, return_rc = 0, opt, opt_found = 0;
1329 const char *const short_options = "adseh";
1330 static const struct option long_options[] = {
1331 { .name = "add", .has_arg = no_argument, .val = 'a' },
1332 { .name = "del", .has_arg = no_argument, .val = 'd' },
1333 { .name = "show", .has_arg = no_argument, .val = 's' },
1334 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1335 { .name = "help", .has_arg = no_argument, .val = 'h' },
1338 while ((opt = getopt_long(argc, argv, short_options,
1339 long_options, NULL)) != -1) {
1353 printf("import FILE\n"
1354 "import < FILE : import a file\n"
1355 "\t--add: add configuration\n"
1356 "\t--del: delete configuration\n"
1357 "\t--show: show configuration\n"
1358 "\t--exec: execute command\n"
1359 "\t--help: display this help\n"
1360 "If no command option is given then --add"
1361 " is assumed by default\n");
1368 /* grab the file name if one exists */
1369 if (opt_found && argc == 3)
1371 else if (!opt_found && argc == 2)
1376 rc = lustre_yaml_config(file, &err_rc);
1377 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1378 cYAML_print_tree(show_rc);
1379 cYAML_free_tree(show_rc);
1382 rc = lustre_yaml_del(file, &err_rc);
1385 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1386 cYAML_print_tree(show_rc);
1387 cYAML_free_tree(show_rc);
1390 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1391 cYAML_print_tree(show_rc);
1392 cYAML_free_tree(show_rc);
1396 if (rc || return_rc) {
1397 cYAML_print_tree2file(stderr, err_rc);
1398 cYAML_free_tree(err_rc);
1404 static int jt_export(int argc, char **argv)
1406 struct cYAML *show_rc = NULL;
1407 struct cYAML *err_rc = NULL;
1411 bool backup = false;
1414 const char *const short_options = "bh";
1415 static const struct option long_options[] = {
1416 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1417 { .name = "help", .has_arg = no_argument, .val = 'h' },
1420 while ((opt = getopt_long(argc, argv, short_options,
1421 long_options, NULL)) != -1) {
1428 printf("export > FILE.yaml : export configuration\n"
1429 "\t--backup: export only what's necessary for reconfig\n"
1430 "\t--help: display this help\n");
1435 if (backup && argc >= 3)
1437 else if (!backup && argc >= 2)
1443 f = fopen(file, "w");
1448 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1449 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1450 cYAML_print_tree2file(stderr, err_rc);
1451 cYAML_free_tree(err_rc);
1455 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1457 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1458 cYAML_print_tree2file(stderr, err_rc);
1459 cYAML_free_tree(err_rc);
1463 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1464 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1465 cYAML_print_tree2file(stderr, err_rc);
1466 cYAML_free_tree(err_rc);
1470 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1471 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1472 cYAML_print_tree2file(stderr, err_rc);
1473 cYAML_free_tree(err_rc);
1477 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1478 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1479 cYAML_print_tree2file(stderr, err_rc);
1480 cYAML_free_tree(err_rc);
1484 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1485 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1486 cYAML_print_tree2file(stderr, err_rc);
1487 cYAML_free_tree(err_rc);
1491 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1492 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1493 cYAML_print_tree2file(stderr, err_rc);
1494 cYAML_free_tree(err_rc);
1498 if (show_rc != NULL) {
1499 cYAML_print_tree2file(f, show_rc);
1500 cYAML_free_tree(show_rc);
1509 static int jt_add_peer_nid(int argc, char **argv)
1511 char *prim_nid = NULL;
1512 char **nids = NULL, **nids2 = NULL;
1514 struct cYAML *err_rc = NULL;
1515 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1516 bool non_mr = false;
1517 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1519 const char *const short_opts = "k:mn:";
1520 const struct option long_opts[] = {
1521 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1522 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1523 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1524 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1527 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1531 while ((opt = getopt_long(argc, argv, short_opts,
1532 long_opts, NULL)) != -1) {
1535 prim_nid_present = true;
1537 cYAML_build_error(-1, -1, "peer", "add",
1538 "ip2nets can not be specified"
1539 " along side prim_nid parameter.",
1553 if (ip2nets && (nid_list || prim_nid_present)) {
1554 cYAML_build_error(-1, -1, "peer", "add",
1555 "ip2nets can not be specified"
1556 " along side nid or prim_nid"
1557 " parameters", &err_rc);
1561 size = lustre_lnet_parse_nids(optarg, nids, size,
1566 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1576 for (; optind < argc; optind++) {
1577 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1584 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1585 !non_mr, ip2nets, -1, &err_rc);
1589 /* free the array of nids */
1590 for (i = 0; i < size; i++)
1595 if (rc != LUSTRE_CFG_RC_NO_ERR)
1596 cYAML_print_tree2file(stderr, err_rc);
1598 cYAML_free_tree(err_rc);
1603 static int jt_del_peer_nid(int argc, char **argv)
1605 char *prim_nid = NULL;
1606 char **nids = NULL, **nids2 = NULL;
1607 struct cYAML *err_rc = NULL;
1608 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1609 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1611 const char *const short_opts = "k:n:";
1612 const struct option long_opts[] = {
1613 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1614 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1615 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1618 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1622 while ((opt = getopt_long(argc, argv, short_opts,
1623 long_opts, NULL)) != -1) {
1626 prim_nid_present = true;
1628 cYAML_build_error(-1, -1, "peer", "add",
1629 "ip2nets can not be specified"
1630 " along side prim_nid parameter.",
1644 if (ip2nets && (nid_list || prim_nid_present)) {
1645 cYAML_build_error(-1, -1, "peer", "add",
1646 "ip2nets can not be specified"
1647 " along side nid or prim_nid"
1648 " parameters", &err_rc);
1651 size = lustre_lnet_parse_nids(optarg, nids, size,
1656 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1663 for (; optind < argc; optind++) {
1664 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1671 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1675 for (i = 0; i < size; i++)
1680 if (rc != LUSTRE_CFG_RC_NO_ERR)
1681 cYAML_print_tree2file(stderr, err_rc);
1683 cYAML_free_tree(err_rc);
1688 static int jt_show_peer(int argc, char **argv)
1692 struct cYAML *err_rc = NULL, *show_rc = NULL;
1693 long int detail = 0;
1695 const char *const short_opts = "hn:v::";
1696 const struct option long_opts[] = {
1697 { .name = "help", .has_arg = no_argument, .val = 'h' },
1698 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1699 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1702 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1706 while ((opt = getopt_long(argc, argv, short_opts,
1707 long_opts, NULL)) != -1) {
1713 if ((!optarg) && (argv[optind] != NULL) &&
1714 (argv[optind][0] != '-')) {
1715 if (parse_long(argv[optind++], &detail) != 0)
1726 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1729 if (rc != LUSTRE_CFG_RC_NO_ERR)
1730 cYAML_print_tree2file(stderr, err_rc);
1732 cYAML_print_tree(show_rc);
1734 cYAML_free_tree(err_rc);
1735 cYAML_free_tree(show_rc);
1740 static int jt_list_peer(int argc, char **argv)
1743 struct cYAML *err_rc = NULL, *list_rc = NULL;
1745 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1749 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1751 if (rc != LUSTRE_CFG_RC_NO_ERR)
1752 cYAML_print_tree2file(stderr, err_rc);
1754 cYAML_print_tree(list_rc);
1756 cYAML_free_tree(err_rc);
1757 cYAML_free_tree(list_rc);
1762 static int jt_ping(int argc, char **argv)
1764 struct cYAML *err_rc = NULL;
1765 struct cYAML *show_rc = NULL;
1769 const char *const short_options = "ht:";
1770 const struct option long_options[] = {
1771 { .name = "help", .has_arg = no_argument, .val = 'h' },
1772 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1775 while ((opt = getopt_long(argc, argv, short_options,
1776 long_options, NULL)) != -1) {
1779 timeout = 1000 * atol(optarg);
1782 printf("ping nid[,nid,...]\n"
1783 "\t --timeout: ping timeout\n"
1784 "\t --help: display this help\n");
1791 for (; optind < argc; optind++)
1792 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1795 cYAML_print_tree(show_rc);
1798 cYAML_print_tree2file(stderr, err_rc);
1800 cYAML_free_tree(err_rc);
1801 cYAML_free_tree(show_rc);
1806 static int jt_discover(int argc, char **argv)
1808 struct cYAML *err_rc = NULL;
1809 struct cYAML *show_rc = NULL;
1813 const char *const short_options = "fh";
1814 const struct option long_options[] = {
1815 { .name = "force", .has_arg = no_argument, .val = 'f' },
1816 { .name = "help", .has_arg = no_argument, .val = 'h' },
1819 while ((opt = getopt_long(argc, argv, short_options,
1820 long_options, NULL)) != -1) {
1826 printf("discover nid[,nid,...]\n"
1827 "\t --force: force discovery\n"
1828 "\t --help: display this help\n");
1835 for (; optind < argc; optind++)
1836 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1840 cYAML_print_tree(show_rc);
1843 cYAML_print_tree2file(stderr, err_rc);
1845 cYAML_free_tree(err_rc);
1846 cYAML_free_tree(show_rc);
1851 static int lnetctl_list_commands(int argc, char **argv)
1853 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1855 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1860 int main(int argc, char **argv)
1863 struct cYAML *err_rc = NULL;
1865 rc = lustre_lnet_config_lib_init();
1867 cYAML_build_error(-1, -1, "lnetctl", "startup",
1868 "cannot register LNet device", &err_rc);
1869 cYAML_print_tree2file(stderr, err_rc);
1873 Parser_init("lnetctl > ", cmd_list);
1875 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);