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_global(int argc, char **argv);
52 static int jt_set_tiny(int argc, char **argv);
53 static int jt_set_small(int argc, char **argv);
54 static int jt_set_large(int argc, char **argv);
55 static int jt_set_numa(int argc, char **argv);
56 static int jt_set_retry_count(int argc, char **argv);
57 static int jt_set_transaction_to(int argc, char **argv);
58 static int jt_set_hsensitivity(int argc, char **argv);
59 static int jt_add_peer_nid(int argc, char **argv);
60 static int jt_del_peer_nid(int argc, char **argv);
61 static int jt_set_max_intf(int argc, char **argv);
62 static int jt_set_discovery(int argc, char **argv);
63 static int jt_list_peer(int argc, char **argv);
64 /*static int jt_show_peer(int argc, char **argv);*/
65 static int lnetctl_list_commands(int argc, char **argv);
66 static int jt_import(int argc, char **argv);
67 static int jt_export(int argc, char **argv);
68 static int jt_ping(int argc, char **argv);
69 static int jt_discover(int argc, char **argv);
70 static int jt_lnet(int argc, char **argv);
71 static int jt_route(int argc, char **argv);
72 static int jt_net(int argc, char **argv);
73 static int jt_routing(int argc, char **argv);
74 static int jt_set(int argc, char **argv);
75 static int jt_stats(int argc, char **argv);
76 static int jt_global(int argc, char **argv);
77 static int jt_peers(int argc, char **argv);
78 static int jt_set_ni_value(int argc, char **argv);
79 static int jt_set_peer_ni_value(int argc, char **argv);
81 command_t cmd_list[] = {
82 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
83 {"route", jt_route, 0, "route {add | del | show | help}"},
84 {"net", jt_net, 0, "net {add | del | show | help}"},
85 {"routing", jt_routing, 0, "routing {show | help}"},
86 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
87 " | routing | numa_range | max_interfaces"
89 {"import", jt_import, 0, "import FILE.yaml"},
90 {"export", jt_export, 0, "export FILE.yaml"},
91 {"stats", jt_stats, 0, "stats {show | help}"},
92 {"global", jt_global, 0, "global {show | help}"},
93 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
94 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
95 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
96 {"help", Parser_help, 0, "help"},
97 {"exit", Parser_quit, 0, "quit"},
98 {"quit", Parser_quit, 0, "quit"},
99 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
103 command_t lnet_cmds[] = {
104 {"configure", jt_config_lnet, 0, "configure lnet\n"
105 "\t--all: load NI configuration from module parameters\n"},
106 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
110 command_t route_cmds[] = {
111 {"add", jt_add_route, 0, "add a route\n"
112 "\t--net: net name (e.g. tcp0)\n"
113 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
114 "\t--hop: number to final destination (1 < hops < 255)\n"
115 "\t--priority: priority of route (0 - highest prio\n"},
116 {"del", jt_del_route, 0, "delete a route\n"
117 "\t--net: net name (e.g. tcp0)\n"
118 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
119 {"show", jt_show_route, 0, "show routes\n"
120 "\t--net: net name (e.g. tcp0) to filter on\n"
121 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
122 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
123 "\t--priority: priority of route (0 - highest prio to filter on\n"
124 "\t--verbose: display detailed output per route\n"},
128 command_t net_cmds[] = {
129 {"add", jt_add_ni, 0, "add a network\n"
130 "\t--net: net name (e.g. tcp0)\n"
131 "\t--if: physical interface (e.g. eth0)\n"
132 "\t--ip2net: specify networks based on IP address patterns\n"
133 "\t--peer-timeout: time to wait before declaring a peer dead\n"
134 "\t--peer-credits: define the max number of inflight messages\n"
135 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
136 "\t--credits: Network Interface credits\n"
137 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
138 {"del", jt_del_ni, 0, "delete a network\n"
139 "\t--net: net name (e.g. tcp0)\n"
140 "\t--if: physical interface (e.g. eth0)\n"},
141 {"show", jt_show_net, 0, "show networks\n"
142 "\t--net: net name (e.g. tcp0) to filter on\n"
143 "\t--verbose: display detailed output per network."
144 " Optional argument of '2' outputs more stats\n"},
145 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
146 "\t--nid: NI NID to set the\n"
147 "\t--health: specify health value to set\n"
148 "\t--all: set all NIs value to the one specified\n"},
152 command_t routing_cmds[] = {
153 {"show", jt_show_routing, 0, "show routing information\n"},
157 command_t stats_cmds[] = {
158 {"show", jt_show_stats, 0, "show LNET statistics\n"},
162 command_t global_cmds[] = {
163 {"show", jt_show_global, 0, "show global variables\n"},
167 command_t set_cmds[] = {
168 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
169 "\tVALUE must be greater than 0\n"},
170 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
171 "\tVALUE must be greater than 0\n"},
172 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
173 "\tVALUE must be greater than 0\n"},
174 {"routing", jt_set_routing, 0, "enable/disable routing\n"
175 "\t0 - disable routing\n"
176 "\t1 - enable routing\n"},
177 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
178 "\tVALUE must be at least 0\n"},
179 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
181 "\tValue must be greater than 16\n"},
182 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
183 "\t0 - disable peer discovery\n"
184 "\t1 - enable peer discovery (default)\n"},
185 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
186 "\t0 - turn of retries\n"
187 "\t>0 - number of retries\n"},
188 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
189 "\t>0 - timeout in seconds\n"},
190 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
191 "\t0 - turn off health evaluation\n"
192 "\t>0 - sensitivity value not more than 1000\n"},
196 command_t peer_cmds[] = {
197 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
198 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
199 "\t NID in the list becomes the Primary NID of a newly created\n"
201 "\t--nid: one or more peer NIDs\n"
202 "\t--non_mr: create this peer as not Multi-Rail capable\n"
203 "\t--ip2nets: specify a range of nids per peer"},
204 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
205 "\t--prim_nid: Primary NID of the peer.\n"
206 "\t--nid: list of NIDs to remove. If none provided,\n"
207 "\t peer is deleted\n"
208 "\t--ip2nets: specify a range of nids per peer"},
209 {"show", jt_show_peer, 0, "show peer information\n"
210 "\t--nid: NID of peer to filter on.\n"
211 "\t--verbose: display detailed output per peer."
212 " Optional argument of '2' outputs more stats\n"},
213 {"list", jt_list_peer, 0, "list all peers\n"},
214 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
215 "\t--nid: Peer NI NID to set the\n"
216 "\t--health: specify health value to set\n"
217 "\t--all: set all peer_nis values to the one specified\n"},
221 static inline void print_help(const command_t cmds[], const char *cmd_type,
224 const command_t *cmd;
226 for (cmd = cmds; cmd->pc_name; cmd++) {
227 if (pc_name != NULL &&
228 strcmp(cmd->pc_name, pc_name) == 0) {
229 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
232 } else if (pc_name != NULL) {
235 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
239 static int parse_long(const char *number, long int *value)
246 *value = strtol(number, &end, 0);
247 if (end != NULL && *end != 0)
253 static int check_cmd(const command_t *cmd_list, const char *cmd,
254 const char *sub_cmd, const int min_args,
255 int argc, char **argv)
262 const char *const short_options = "h";
263 static const struct option long_options[] = {
264 { .name = "help", .has_arg = no_argument, .val = 'h' },
268 if (argc < min_args) {
269 print_help(cmd_list, cmd, sub_cmd);
272 } else if (argc > 2) {
276 while ((opt = getopt_long(argc, argv, short_options,
277 long_options, NULL)) != -1) {
280 print_help(cmd_list, cmd, sub_cmd);
295 static int jt_set_max_intf(int argc, char **argv)
299 struct cYAML *err_rc = NULL;
301 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
305 rc = parse_long(argv[1], &value);
307 cYAML_build_error(-1, -1, "parser", "set",
308 "cannot parse max_interfaces value", &err_rc);
309 cYAML_print_tree2file(stderr, err_rc);
310 cYAML_free_tree(err_rc);
314 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
315 if (rc != LUSTRE_CFG_RC_NO_ERR)
316 cYAML_print_tree2file(stderr, err_rc);
318 cYAML_free_tree(err_rc);
323 static int jt_set_numa(int argc, char **argv)
327 struct cYAML *err_rc = NULL;
329 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
333 rc = parse_long(argv[1], &value);
335 cYAML_build_error(-1, -1, "parser", "set",
336 "cannot parse numa_range value", &err_rc);
337 cYAML_print_tree2file(stderr, err_rc);
338 cYAML_free_tree(err_rc);
342 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
343 if (rc != LUSTRE_CFG_RC_NO_ERR)
344 cYAML_print_tree2file(stderr, err_rc);
346 cYAML_free_tree(err_rc);
351 static int jt_set_hsensitivity(int argc, char **argv)
355 struct cYAML *err_rc = NULL;
357 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
361 rc = parse_long(argv[1], &value);
363 cYAML_build_error(-1, -1, "parser", "set",
364 "cannot parse health sensitivity value", &err_rc);
365 cYAML_print_tree2file(stderr, err_rc);
366 cYAML_free_tree(err_rc);
370 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
371 if (rc != LUSTRE_CFG_RC_NO_ERR)
372 cYAML_print_tree2file(stderr, err_rc);
374 cYAML_free_tree(err_rc);
379 static int jt_set_transaction_to(int argc, char **argv)
383 struct cYAML *err_rc = NULL;
385 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
389 rc = parse_long(argv[1], &value);
391 cYAML_build_error(-1, -1, "parser", "set",
392 "cannot parse transaction timeout value", &err_rc);
393 cYAML_print_tree2file(stderr, err_rc);
394 cYAML_free_tree(err_rc);
398 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
399 if (rc != LUSTRE_CFG_RC_NO_ERR)
400 cYAML_print_tree2file(stderr, err_rc);
402 cYAML_free_tree(err_rc);
407 static int jt_set_retry_count(int argc, char **argv)
411 struct cYAML *err_rc = NULL;
413 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
417 rc = parse_long(argv[1], &value);
419 cYAML_build_error(-1, -1, "parser", "set",
420 "cannot parse retry_count value", &err_rc);
421 cYAML_print_tree2file(stderr, err_rc);
422 cYAML_free_tree(err_rc);
426 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
427 if (rc != LUSTRE_CFG_RC_NO_ERR)
428 cYAML_print_tree2file(stderr, err_rc);
430 cYAML_free_tree(err_rc);
435 static int jt_set_discovery(int argc, char **argv)
439 struct cYAML *err_rc = NULL;
441 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
445 rc = parse_long(argv[1], &value);
447 cYAML_build_error(-1, -1, "parser", "set",
448 "cannot parse discovery value", &err_rc);
449 cYAML_print_tree2file(stderr, err_rc);
450 cYAML_free_tree(err_rc);
454 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
455 if (rc != LUSTRE_CFG_RC_NO_ERR)
456 cYAML_print_tree2file(stderr, err_rc);
458 cYAML_free_tree(err_rc);
463 static int jt_set_tiny(int argc, char **argv)
467 struct cYAML *err_rc = NULL;
469 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
473 rc = parse_long(argv[1], &value);
475 cYAML_build_error(-1, -1, "parser", "set",
476 "cannot parse tiny_buffers value", &err_rc);
477 cYAML_print_tree2file(stderr, err_rc);
478 cYAML_free_tree(err_rc);
482 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
483 if (rc != LUSTRE_CFG_RC_NO_ERR)
484 cYAML_print_tree2file(stderr, err_rc);
486 cYAML_free_tree(err_rc);
491 static int jt_set_small(int argc, char **argv)
495 struct cYAML *err_rc = NULL;
497 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
501 rc = parse_long(argv[1], &value);
503 cYAML_build_error(-1, -1, "parser", "set",
504 "cannot parse small_buffers value", &err_rc);
505 cYAML_print_tree2file(stderr, err_rc);
506 cYAML_free_tree(err_rc);
510 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
511 if (rc != LUSTRE_CFG_RC_NO_ERR)
512 cYAML_print_tree2file(stderr, err_rc);
514 cYAML_free_tree(err_rc);
519 static int jt_set_large(int argc, char **argv)
523 struct cYAML *err_rc = NULL;
525 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
529 rc = parse_long(argv[1], &value);
531 cYAML_build_error(-1, -1, "parser", "set",
532 "cannot parse large_buffers value", &err_rc);
533 cYAML_print_tree2file(stderr, err_rc);
534 cYAML_free_tree(err_rc);
538 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
539 if (rc != LUSTRE_CFG_RC_NO_ERR)
540 cYAML_print_tree2file(stderr, err_rc);
542 cYAML_free_tree(err_rc);
547 static int jt_set_routing(int argc, char **argv)
550 struct cYAML *err_rc = NULL;
553 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
557 rc = parse_long(argv[1], &value);
558 if (rc != 0 || (value != 0 && value != 1)) {
559 cYAML_build_error(-1, -1, "parser", "set",
560 "cannot parse routing value.\n"
561 "must be 0 for disable or 1 for enable",
563 cYAML_print_tree2file(stderr, err_rc);
564 cYAML_free_tree(err_rc);
568 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
570 if (rc != LUSTRE_CFG_RC_NO_ERR)
571 cYAML_print_tree2file(stderr, err_rc);
573 cYAML_free_tree(err_rc);
578 static int jt_config_lnet(int argc, char **argv)
580 struct cYAML *err_rc = NULL;
581 bool load_mod_params = false;
584 const char *const short_options = "a";
585 static const struct option long_options[] = {
586 { .name = "all", .has_arg = no_argument, .val = 'a' },
590 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
594 while ((opt = getopt_long(argc, argv, short_options,
595 long_options, NULL)) != -1) {
598 load_mod_params = true;
605 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
608 if (rc != LUSTRE_CFG_RC_NO_ERR)
609 cYAML_print_tree2file(stderr, err_rc);
611 cYAML_free_tree(err_rc);
616 static int jt_unconfig_lnet(int argc, char **argv)
618 struct cYAML *err_rc = NULL;
621 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
625 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
627 if (rc != LUSTRE_CFG_RC_NO_ERR)
628 cYAML_print_tree2file(stderr, err_rc);
630 cYAML_free_tree(err_rc);
634 static int jt_add_route(int argc, char **argv)
636 char *network = NULL, *gateway = NULL;
637 long int hop = -1, prio = -1;
638 struct cYAML *err_rc = NULL;
641 const char *const short_options = "n:g:c:p:";
642 static const struct option long_options[] = {
643 { .name = "net", .has_arg = required_argument, .val = 'n' },
644 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
645 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
646 { .name = "priority", .has_arg = required_argument, .val = 'p' },
649 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
653 while ((opt = getopt_long(argc, argv, short_options,
654 long_options, NULL)) != -1) {
663 rc = parse_long(optarg, &hop);
671 rc = parse_long(optarg, &prio);
683 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
685 if (rc != LUSTRE_CFG_RC_NO_ERR)
686 cYAML_print_tree2file(stderr, err_rc);
688 cYAML_free_tree(err_rc);
693 static int jt_add_ni(int argc, char **argv)
696 long int pto = -1, pc = -1, pbc = -1, cre = -1;
697 struct cYAML *err_rc = NULL;
698 int rc, opt, cpt_rc = -1;
699 struct lnet_dlc_network_descr nw_descr;
700 struct cfs_expr_list *global_cpts = NULL;
701 struct lnet_ioctl_config_lnd_tunables tunables;
704 memset(&tunables, 0, sizeof(tunables));
705 lustre_lnet_init_nw_descr(&nw_descr);
707 const char *const short_options = "n:i:p:t:c:b:r:s:";
708 static const struct option long_options[] = {
709 { .name = "net", .has_arg = required_argument, .val = 'n' },
710 { .name = "if", .has_arg = required_argument, .val = 'i' },
711 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
712 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
713 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
714 { .name = "peer-buffer-credits",
715 .has_arg = required_argument, .val = 'b' },
716 { .name = "credits", .has_arg = required_argument, .val = 'r' },
717 { .name = "cpt", .has_arg = required_argument, .val = 's' },
720 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
724 while ((opt = getopt_long(argc, argv, short_options,
725 long_options, NULL)) != -1) {
728 nw_descr.nw_id = libcfs_str2net(optarg);
731 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
733 cYAML_build_error(-1, -1, "ni", "add",
734 "bad interface list",
743 rc = parse_long(optarg, &pto);
751 rc = parse_long(optarg, &pc);
759 rc = parse_long(optarg, &pbc);
767 rc = parse_long(optarg, &cre);
775 cpt_rc = cfs_expr_list_parse(optarg,
777 UINT_MAX, &global_cpts);
784 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
785 tunables.lt_cmn.lct_peer_timeout = pto;
786 tunables.lt_cmn.lct_peer_tx_credits = pc;
787 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
788 tunables.lt_cmn.lct_max_tx_credits = cre;
792 rc = lustre_lnet_config_ni(&nw_descr,
793 (cpt_rc == 0) ? global_cpts: NULL,
794 ip2net, (found) ? &tunables : NULL,
797 if (global_cpts != NULL)
798 cfs_expr_list_free(global_cpts);
801 if (rc != LUSTRE_CFG_RC_NO_ERR)
802 cYAML_print_tree2file(stderr, err_rc);
804 cYAML_free_tree(err_rc);
809 static int jt_del_route(int argc, char **argv)
811 char *network = NULL, *gateway = NULL;
812 struct cYAML *err_rc = NULL;
815 const char *const short_options = "n:g:";
816 static const struct option long_options[] = {
817 { .name = "net", .has_arg = required_argument, .val = 'n' },
818 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
821 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
825 while ((opt = getopt_long(argc, argv, short_options,
826 long_options, NULL)) != -1) {
839 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
841 if (rc != LUSTRE_CFG_RC_NO_ERR)
842 cYAML_print_tree2file(stderr, err_rc);
844 cYAML_free_tree(err_rc);
849 static int jt_del_ni(int argc, char **argv)
851 struct cYAML *err_rc = NULL;
853 struct lnet_dlc_network_descr nw_descr;
855 lustre_lnet_init_nw_descr(&nw_descr);
857 const char *const short_options = "n:i:";
858 static const struct option long_options[] = {
859 { .name = "net", .has_arg = required_argument, .val = 'n' },
860 { .name = "if", .has_arg = required_argument, .val = 'i' },
863 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
867 while ((opt = getopt_long(argc, argv, short_options,
868 long_options, NULL)) != -1) {
871 nw_descr.nw_id = libcfs_str2net(optarg);
874 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
876 cYAML_build_error(-1, -1, "ni", "add",
877 "bad interface list",
887 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
890 if (rc != LUSTRE_CFG_RC_NO_ERR)
891 cYAML_print_tree2file(stderr, err_rc);
893 cYAML_free_tree(err_rc);
898 static int jt_show_route(int argc, char **argv)
900 char *network = NULL, *gateway = NULL;
901 long int hop = -1, prio = -1;
902 int detail = 0, rc, opt;
903 struct cYAML *err_rc = NULL, *show_rc = NULL;
905 const char *const short_options = "n:g:h:p:v";
906 static const struct option long_options[] = {
907 { .name = "net", .has_arg = required_argument, .val = 'n' },
908 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
909 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
910 { .name = "priority", .has_arg = required_argument, .val = 'p' },
911 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
914 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
918 while ((opt = getopt_long(argc, argv, short_options,
919 long_options, NULL)) != -1) {
928 rc = parse_long(optarg, &hop);
936 rc = parse_long(optarg, &prio);
951 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
952 &show_rc, &err_rc, false);
954 if (rc != LUSTRE_CFG_RC_NO_ERR)
955 cYAML_print_tree2file(stderr, err_rc);
957 cYAML_print_tree(show_rc);
959 cYAML_free_tree(err_rc);
960 cYAML_free_tree(show_rc);
965 static int set_value_helper(int argc, char **argv,
966 int (*cb)(int, bool, char*, int, struct cYAML**))
969 long int healthv = -1;
972 struct cYAML *err_rc = NULL;
974 const char *const short_options = "h:n:a";
975 static const struct option long_options[] = {
976 { .name = "nid", .has_arg = required_argument, .val = 'n' },
977 { .name = "health", .has_arg = required_argument, .val = 'h' },
978 { .name = "all", .has_arg = no_argument, .val = 'a' },
981 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
985 while ((opt = getopt_long(argc, argv, short_options,
986 long_options, NULL)) != -1) {
992 if (parse_long(argv[optind++], &healthv) != 0)
1002 rc = cb(healthv, all, nid, -1, &err_rc);
1004 if (rc != LUSTRE_CFG_RC_NO_ERR)
1005 cYAML_print_tree2file(stderr, err_rc);
1007 cYAML_free_tree(err_rc);
1012 static int jt_set_ni_value(int argc, char **argv)
1014 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1017 static int jt_set_peer_ni_value(int argc, char **argv)
1019 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1022 static int jt_show_net(int argc, char **argv)
1024 char *network = NULL;
1026 struct cYAML *err_rc = NULL, *show_rc = NULL;
1027 long int detail = 0;
1029 const char *const short_options = "n:v";
1030 static const struct option long_options[] = {
1031 { .name = "net", .has_arg = required_argument, .val = 'n' },
1032 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1035 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1039 while ((opt = getopt_long(argc, argv, short_options,
1040 long_options, NULL)) != -1) {
1046 if ((!optarg) && (argv[optind] != NULL) &&
1047 (argv[optind][0] != '-')) {
1048 if (parse_long(argv[optind++], &detail) != 0)
1059 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1062 if (rc != LUSTRE_CFG_RC_NO_ERR)
1063 cYAML_print_tree2file(stderr, err_rc);
1065 cYAML_print_tree(show_rc);
1067 cYAML_free_tree(err_rc);
1068 cYAML_free_tree(show_rc);
1073 static int jt_show_routing(int argc, char **argv)
1075 struct cYAML *err_rc = NULL, *show_rc = NULL;
1078 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1082 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1084 if (rc != LUSTRE_CFG_RC_NO_ERR)
1085 cYAML_print_tree2file(stderr, err_rc);
1087 cYAML_print_tree(show_rc);
1089 cYAML_free_tree(err_rc);
1090 cYAML_free_tree(show_rc);
1095 static int jt_show_stats(int argc, char **argv)
1098 struct cYAML *show_rc = NULL, *err_rc = NULL;
1100 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1104 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1106 if (rc != LUSTRE_CFG_RC_NO_ERR)
1107 cYAML_print_tree2file(stderr, err_rc);
1109 cYAML_print_tree(show_rc);
1111 cYAML_free_tree(err_rc);
1112 cYAML_free_tree(show_rc);
1117 static int jt_show_global(int argc, char **argv)
1120 struct cYAML *show_rc = NULL, *err_rc = NULL;
1122 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1126 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1127 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1128 cYAML_print_tree2file(stderr, err_rc);
1132 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1133 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1134 cYAML_print_tree2file(stderr, err_rc);
1138 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1139 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1140 cYAML_print_tree2file(stderr, err_rc);
1144 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1145 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1146 cYAML_print_tree2file(stderr, err_rc);
1150 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1151 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1152 cYAML_print_tree2file(stderr, err_rc);
1156 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1157 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1158 cYAML_print_tree2file(stderr, err_rc);
1163 cYAML_print_tree(show_rc);
1166 cYAML_free_tree(err_rc);
1167 cYAML_free_tree(show_rc);
1172 static int jt_lnet(int argc, char **argv)
1176 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1180 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1183 static int jt_route(int argc, char **argv)
1187 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1191 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1194 static int jt_net(int argc, char **argv)
1198 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1202 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1205 static int jt_routing(int argc, char **argv)
1209 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1213 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1216 static int jt_stats(int argc, char **argv)
1220 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1224 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1227 static int jt_global(int argc, char **argv)
1231 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1235 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1238 static int jt_peers(int argc, char **argv)
1242 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1246 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1249 static int jt_set(int argc, char **argv)
1253 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1257 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1260 static int jt_import(int argc, char **argv)
1263 struct cYAML *err_rc = NULL;
1264 struct cYAML *show_rc = NULL;
1265 int rc = 0, return_rc = 0, opt, opt_found = 0;
1268 const char *const short_options = "adseh";
1269 static const struct option long_options[] = {
1270 { .name = "add", .has_arg = no_argument, .val = 'a' },
1271 { .name = "del", .has_arg = no_argument, .val = 'd' },
1272 { .name = "show", .has_arg = no_argument, .val = 's' },
1273 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1274 { .name = "help", .has_arg = no_argument, .val = 'h' },
1277 while ((opt = getopt_long(argc, argv, short_options,
1278 long_options, NULL)) != -1) {
1292 printf("import FILE\n"
1293 "import < FILE : import a file\n"
1294 "\t--add: add configuration\n"
1295 "\t--del: delete configuration\n"
1296 "\t--show: show configuration\n"
1297 "\t--exec: execute command\n"
1298 "\t--help: display this help\n"
1299 "If no command option is given then --add"
1300 " is assumed by default\n");
1307 /* grab the file name if one exists */
1308 if (opt_found && argc == 3)
1310 else if (!opt_found && argc == 2)
1315 rc = lustre_yaml_config(file, &err_rc);
1316 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1317 cYAML_print_tree(show_rc);
1318 cYAML_free_tree(show_rc);
1321 rc = lustre_yaml_del(file, &err_rc);
1324 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1325 cYAML_print_tree(show_rc);
1326 cYAML_free_tree(show_rc);
1329 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1330 cYAML_print_tree(show_rc);
1331 cYAML_free_tree(show_rc);
1335 if (rc || return_rc) {
1336 cYAML_print_tree2file(stderr, err_rc);
1337 cYAML_free_tree(err_rc);
1343 static int jt_export(int argc, char **argv)
1345 struct cYAML *show_rc = NULL;
1346 struct cYAML *err_rc = NULL;
1350 bool backup = false;
1353 const char *const short_options = "bh";
1354 static const struct option long_options[] = {
1355 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1356 { .name = "help", .has_arg = no_argument, .val = 'h' },
1359 while ((opt = getopt_long(argc, argv, short_options,
1360 long_options, NULL)) != -1) {
1367 printf("export > FILE.yaml : export configuration\n"
1368 "\t--backup: export only what's necessary for reconfig\n"
1369 "\t--help: display this help\n");
1374 if (backup && argc >= 3)
1376 else if (!backup && argc >= 2)
1382 f = fopen(file, "w");
1387 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1388 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1389 cYAML_print_tree2file(stderr, err_rc);
1390 cYAML_free_tree(err_rc);
1394 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1396 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1397 cYAML_print_tree2file(stderr, err_rc);
1398 cYAML_free_tree(err_rc);
1402 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1403 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1404 cYAML_print_tree2file(stderr, err_rc);
1405 cYAML_free_tree(err_rc);
1409 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1410 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1411 cYAML_print_tree2file(stderr, err_rc);
1412 cYAML_free_tree(err_rc);
1416 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1417 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1418 cYAML_print_tree2file(stderr, err_rc);
1419 cYAML_free_tree(err_rc);
1423 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1424 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1425 cYAML_print_tree2file(stderr, err_rc);
1426 cYAML_free_tree(err_rc);
1430 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1431 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1432 cYAML_print_tree2file(stderr, err_rc);
1433 cYAML_free_tree(err_rc);
1437 if (show_rc != NULL) {
1438 cYAML_print_tree2file(f, show_rc);
1439 cYAML_free_tree(show_rc);
1448 static int jt_add_peer_nid(int argc, char **argv)
1450 char *prim_nid = NULL;
1451 char **nids = NULL, **nids2 = NULL;
1453 struct cYAML *err_rc = NULL;
1454 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1455 bool non_mr = false;
1456 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1458 const char *const short_opts = "k:mn:";
1459 const struct option long_opts[] = {
1460 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1461 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1462 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1463 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1466 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1470 while ((opt = getopt_long(argc, argv, short_opts,
1471 long_opts, NULL)) != -1) {
1474 prim_nid_present = true;
1476 cYAML_build_error(-1, -1, "peer", "add",
1477 "ip2nets can not be specified"
1478 " along side prim_nid parameter.",
1492 if (ip2nets && (nid_list || prim_nid_present)) {
1493 cYAML_build_error(-1, -1, "peer", "add",
1494 "ip2nets can not be specified"
1495 " along side nid or prim_nid"
1496 " parameters", &err_rc);
1500 size = lustre_lnet_parse_nids(optarg, nids, size,
1505 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1515 for (; optind < argc; optind++) {
1516 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1523 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1524 !non_mr, ip2nets, -1, &err_rc);
1528 /* free the array of nids */
1529 for (i = 0; i < size; i++)
1534 if (rc != LUSTRE_CFG_RC_NO_ERR)
1535 cYAML_print_tree2file(stderr, err_rc);
1537 cYAML_free_tree(err_rc);
1542 static int jt_del_peer_nid(int argc, char **argv)
1544 char *prim_nid = NULL;
1545 char **nids = NULL, **nids2 = NULL;
1546 struct cYAML *err_rc = NULL;
1547 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1548 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1550 const char *const short_opts = "k:n:";
1551 const struct option long_opts[] = {
1552 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1553 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1554 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1557 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1561 while ((opt = getopt_long(argc, argv, short_opts,
1562 long_opts, NULL)) != -1) {
1565 prim_nid_present = true;
1567 cYAML_build_error(-1, -1, "peer", "add",
1568 "ip2nets can not be specified"
1569 " along side prim_nid parameter.",
1583 if (ip2nets && (nid_list || prim_nid_present)) {
1584 cYAML_build_error(-1, -1, "peer", "add",
1585 "ip2nets can not be specified"
1586 " along side nid or prim_nid"
1587 " parameters", &err_rc);
1590 size = lustre_lnet_parse_nids(optarg, nids, size,
1595 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1602 for (; optind < argc; optind++) {
1603 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1610 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1614 for (i = 0; i < size; i++)
1619 if (rc != LUSTRE_CFG_RC_NO_ERR)
1620 cYAML_print_tree2file(stderr, err_rc);
1622 cYAML_free_tree(err_rc);
1627 static int jt_show_peer(int argc, char **argv)
1631 struct cYAML *err_rc = NULL, *show_rc = NULL;
1632 long int detail = 0;
1634 const char *const short_opts = "hn:v::";
1635 const struct option long_opts[] = {
1636 { .name = "help", .has_arg = no_argument, .val = 'h' },
1637 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1638 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1641 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1645 while ((opt = getopt_long(argc, argv, short_opts,
1646 long_opts, NULL)) != -1) {
1652 if ((!optarg) && (argv[optind] != NULL) &&
1653 (argv[optind][0] != '-')) {
1654 if (parse_long(argv[optind++], &detail) != 0)
1665 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1668 if (rc != LUSTRE_CFG_RC_NO_ERR)
1669 cYAML_print_tree2file(stderr, err_rc);
1671 cYAML_print_tree(show_rc);
1673 cYAML_free_tree(err_rc);
1674 cYAML_free_tree(show_rc);
1679 static int jt_list_peer(int argc, char **argv)
1682 struct cYAML *err_rc = NULL, *list_rc = NULL;
1684 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1688 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1690 if (rc != LUSTRE_CFG_RC_NO_ERR)
1691 cYAML_print_tree2file(stderr, err_rc);
1693 cYAML_print_tree(list_rc);
1695 cYAML_free_tree(err_rc);
1696 cYAML_free_tree(list_rc);
1701 static int jt_ping(int argc, char **argv)
1703 struct cYAML *err_rc = NULL;
1704 struct cYAML *show_rc = NULL;
1708 const char *const short_options = "ht:";
1709 const struct option long_options[] = {
1710 { .name = "help", .has_arg = no_argument, .val = 'h' },
1711 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1714 while ((opt = getopt_long(argc, argv, short_options,
1715 long_options, NULL)) != -1) {
1718 timeout = 1000 * atol(optarg);
1721 printf("ping nid[,nid,...]\n"
1722 "\t --timeout: ping timeout\n"
1723 "\t --help: display this help\n");
1730 for (; optind < argc; optind++)
1731 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1734 cYAML_print_tree(show_rc);
1737 cYAML_print_tree2file(stderr, err_rc);
1739 cYAML_free_tree(err_rc);
1740 cYAML_free_tree(show_rc);
1745 static int jt_discover(int argc, char **argv)
1747 struct cYAML *err_rc = NULL;
1748 struct cYAML *show_rc = NULL;
1752 const char *const short_options = "fh";
1753 const struct option long_options[] = {
1754 { .name = "force", .has_arg = no_argument, .val = 'f' },
1755 { .name = "help", .has_arg = no_argument, .val = 'h' },
1758 while ((opt = getopt_long(argc, argv, short_options,
1759 long_options, NULL)) != -1) {
1765 printf("discover nid[,nid,...]\n"
1766 "\t --force: force discovery\n"
1767 "\t --help: display this help\n");
1774 for (; optind < argc; optind++)
1775 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1779 cYAML_print_tree(show_rc);
1782 cYAML_print_tree2file(stderr, err_rc);
1784 cYAML_free_tree(err_rc);
1785 cYAML_free_tree(show_rc);
1790 static int lnetctl_list_commands(int argc, char **argv)
1792 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1794 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1799 int main(int argc, char **argv)
1802 struct cYAML *err_rc = NULL;
1804 rc = lustre_lnet_config_lib_init();
1806 cYAML_build_error(-1, -1, "lnetctl", "startup",
1807 "cannot register LNet device", &err_rc);
1808 cYAML_print_tree2file(stderr, err_rc);
1812 Parser_init("lnetctl > ", cmd_list);
1814 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);