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_add_peer_nid(int argc, char **argv);
58 static int jt_del_peer_nid(int argc, char **argv);
59 static int jt_set_max_intf(int argc, char **argv);
60 static int jt_set_discovery(int argc, char **argv);
61 static int jt_list_peer(int argc, char **argv);
62 /*static int jt_show_peer(int argc, char **argv);*/
63 static int lnetctl_list_commands(int argc, char **argv);
64 static int jt_import(int argc, char **argv);
65 static int jt_export(int argc, char **argv);
66 static int jt_ping(int argc, char **argv);
67 static int jt_discover(int argc, char **argv);
68 static int jt_lnet(int argc, char **argv);
69 static int jt_route(int argc, char **argv);
70 static int jt_net(int argc, char **argv);
71 static int jt_routing(int argc, char **argv);
72 static int jt_set(int argc, char **argv);
73 static int jt_stats(int argc, char **argv);
74 static int jt_global(int argc, char **argv);
75 static int jt_peers(int argc, char **argv);
78 command_t cmd_list[] = {
79 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
80 {"route", jt_route, 0, "route {add | del | show | help}"},
81 {"net", jt_net, 0, "net {add | del | show | help}"},
82 {"routing", jt_routing, 0, "routing {show | help}"},
83 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
84 " | routing | numa_range | max_interfaces"
86 {"import", jt_import, 0, "import FILE.yaml"},
87 {"export", jt_export, 0, "export FILE.yaml"},
88 {"stats", jt_stats, 0, "stats {show | help}"},
89 {"global", jt_global, 0, "global {show | help}"},
90 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
91 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
92 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
93 {"help", Parser_help, 0, "help"},
94 {"exit", Parser_quit, 0, "quit"},
95 {"quit", Parser_quit, 0, "quit"},
96 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
100 command_t lnet_cmds[] = {
101 {"configure", jt_config_lnet, 0, "configure lnet\n"
102 "\t--all: load NI configuration from module parameters\n"},
103 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
107 command_t route_cmds[] = {
108 {"add", jt_add_route, 0, "add a route\n"
109 "\t--net: net name (e.g. tcp0)\n"
110 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
111 "\t--hop: number to final destination (1 < hops < 255)\n"
112 "\t--priority: priority of route (0 - highest prio\n"},
113 {"del", jt_del_route, 0, "delete a route\n"
114 "\t--net: net name (e.g. tcp0)\n"
115 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
116 {"show", jt_show_route, 0, "show routes\n"
117 "\t--net: net name (e.g. tcp0) to filter on\n"
118 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
119 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
120 "\t--priority: priority of route (0 - highest prio to filter on\n"
121 "\t--verbose: display detailed output per route\n"},
125 command_t net_cmds[] = {
126 {"add", jt_add_ni, 0, "add a network\n"
127 "\t--net: net name (e.g. tcp0)\n"
128 "\t--if: physical interface (e.g. eth0)\n"
129 "\t--ip2net: specify networks based on IP address patterns\n"
130 "\t--peer-timeout: time to wait before declaring a peer dead\n"
131 "\t--peer-credits: define the max number of inflight messages\n"
132 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
133 "\t--credits: Network Interface credits\n"
134 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
135 {"del", jt_del_ni, 0, "delete a network\n"
136 "\t--net: net name (e.g. tcp0)\n"
137 "\t--if: physical interface (e.g. eth0)\n"},
138 {"show", jt_show_net, 0, "show networks\n"
139 "\t--net: net name (e.g. tcp0) to filter on\n"
140 "\t--verbose: display detailed output per network."
141 " Optional argument of '2' outputs more stats\n"},
145 command_t routing_cmds[] = {
146 {"show", jt_show_routing, 0, "show routing information\n"},
150 command_t stats_cmds[] = {
151 {"show", jt_show_stats, 0, "show LNET statistics\n"},
155 command_t global_cmds[] = {
156 {"show", jt_show_global, 0, "show global variables\n"},
160 command_t set_cmds[] = {
161 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
162 "\tVALUE must be greater than 0\n"},
163 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
164 "\tVALUE must be greater than 0\n"},
165 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
166 "\tVALUE must be greater than 0\n"},
167 {"routing", jt_set_routing, 0, "enable/disable routing\n"
168 "\t0 - disable routing\n"
169 "\t1 - enable routing\n"},
170 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
171 "\tVALUE must be at least 0\n"},
172 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
174 "\tValue must be greater than 16\n"},
175 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
176 "\t0 - disable peer discovery\n"
177 "\t1 - enable peer discovery (default)\n"},
178 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
179 "\t0 - turn of retries\n"
180 "\t>0 - number of retries\n"},
184 command_t peer_cmds[] = {
185 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
186 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
187 "\t NID in the list becomes the Primary NID of a newly created\n"
189 "\t--nid: one or more peer NIDs\n"
190 "\t--non_mr: create this peer as not Multi-Rail capable\n"
191 "\t--ip2nets: specify a range of nids per peer"},
192 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
193 "\t--prim_nid: Primary NID of the peer.\n"
194 "\t--nid: list of NIDs to remove. If none provided,\n"
195 "\t peer is deleted\n"
196 "\t--ip2nets: specify a range of nids per peer"},
197 {"show", jt_show_peer, 0, "show peer information\n"
198 "\t--nid: NID of peer to filter on.\n"
199 "\t--verbose: display detailed output per peer."
200 " Optional argument of '2' outputs more stats\n"},
201 {"list", jt_list_peer, 0, "list all peers\n"},
205 static inline void print_help(const command_t cmds[], const char *cmd_type,
208 const command_t *cmd;
210 for (cmd = cmds; cmd->pc_name; cmd++) {
211 if (pc_name != NULL &&
212 strcmp(cmd->pc_name, pc_name) == 0) {
213 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
216 } else if (pc_name != NULL) {
219 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
223 static int parse_long(const char *number, long int *value)
230 *value = strtol(number, &end, 0);
231 if (end != NULL && *end != 0)
237 static int check_cmd(const command_t *cmd_list, const char *cmd,
238 const char *sub_cmd, const int min_args,
239 int argc, char **argv)
246 const char *const short_options = "h";
247 static const struct option long_options[] = {
248 { .name = "help", .has_arg = no_argument, .val = 'h' },
252 if (argc < min_args) {
253 print_help(cmd_list, cmd, sub_cmd);
256 } else if (argc > 2) {
260 while ((opt = getopt_long(argc, argv, short_options,
261 long_options, NULL)) != -1) {
264 print_help(cmd_list, cmd, sub_cmd);
279 static int jt_set_max_intf(int argc, char **argv)
283 struct cYAML *err_rc = NULL;
285 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
289 rc = parse_long(argv[1], &value);
291 cYAML_build_error(-1, -1, "parser", "set",
292 "cannot parse max_interfaces value", &err_rc);
293 cYAML_print_tree2file(stderr, err_rc);
294 cYAML_free_tree(err_rc);
298 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
299 if (rc != LUSTRE_CFG_RC_NO_ERR)
300 cYAML_print_tree2file(stderr, err_rc);
302 cYAML_free_tree(err_rc);
307 static int jt_set_numa(int argc, char **argv)
311 struct cYAML *err_rc = NULL;
313 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
317 rc = parse_long(argv[1], &value);
319 cYAML_build_error(-1, -1, "parser", "set",
320 "cannot parse numa_range value", &err_rc);
321 cYAML_print_tree2file(stderr, err_rc);
322 cYAML_free_tree(err_rc);
326 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
327 if (rc != LUSTRE_CFG_RC_NO_ERR)
328 cYAML_print_tree2file(stderr, err_rc);
330 cYAML_free_tree(err_rc);
335 static int jt_set_retry_count(int argc, char **argv)
339 struct cYAML *err_rc = NULL;
341 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
345 rc = parse_long(argv[1], &value);
347 cYAML_build_error(-1, -1, "parser", "set",
348 "cannot parse retry_count value", &err_rc);
349 cYAML_print_tree2file(stderr, err_rc);
350 cYAML_free_tree(err_rc);
354 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
355 if (rc != LUSTRE_CFG_RC_NO_ERR)
356 cYAML_print_tree2file(stderr, err_rc);
358 cYAML_free_tree(err_rc);
363 static int jt_set_discovery(int argc, char **argv)
367 struct cYAML *err_rc = NULL;
369 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
373 rc = parse_long(argv[1], &value);
375 cYAML_build_error(-1, -1, "parser", "set",
376 "cannot parse discovery value", &err_rc);
377 cYAML_print_tree2file(stderr, err_rc);
378 cYAML_free_tree(err_rc);
382 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
383 if (rc != LUSTRE_CFG_RC_NO_ERR)
384 cYAML_print_tree2file(stderr, err_rc);
386 cYAML_free_tree(err_rc);
391 static int jt_set_tiny(int argc, char **argv)
395 struct cYAML *err_rc = NULL;
397 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
401 rc = parse_long(argv[1], &value);
403 cYAML_build_error(-1, -1, "parser", "set",
404 "cannot parse tiny_buffers value", &err_rc);
405 cYAML_print_tree2file(stderr, err_rc);
406 cYAML_free_tree(err_rc);
410 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
411 if (rc != LUSTRE_CFG_RC_NO_ERR)
412 cYAML_print_tree2file(stderr, err_rc);
414 cYAML_free_tree(err_rc);
419 static int jt_set_small(int argc, char **argv)
423 struct cYAML *err_rc = NULL;
425 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
429 rc = parse_long(argv[1], &value);
431 cYAML_build_error(-1, -1, "parser", "set",
432 "cannot parse small_buffers value", &err_rc);
433 cYAML_print_tree2file(stderr, err_rc);
434 cYAML_free_tree(err_rc);
438 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
439 if (rc != LUSTRE_CFG_RC_NO_ERR)
440 cYAML_print_tree2file(stderr, err_rc);
442 cYAML_free_tree(err_rc);
447 static int jt_set_large(int argc, char **argv)
451 struct cYAML *err_rc = NULL;
453 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
457 rc = parse_long(argv[1], &value);
459 cYAML_build_error(-1, -1, "parser", "set",
460 "cannot parse large_buffers value", &err_rc);
461 cYAML_print_tree2file(stderr, err_rc);
462 cYAML_free_tree(err_rc);
466 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
467 if (rc != LUSTRE_CFG_RC_NO_ERR)
468 cYAML_print_tree2file(stderr, err_rc);
470 cYAML_free_tree(err_rc);
475 static int jt_set_routing(int argc, char **argv)
478 struct cYAML *err_rc = NULL;
481 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
485 rc = parse_long(argv[1], &value);
486 if (rc != 0 || (value != 0 && value != 1)) {
487 cYAML_build_error(-1, -1, "parser", "set",
488 "cannot parse routing value.\n"
489 "must be 0 for disable or 1 for enable",
491 cYAML_print_tree2file(stderr, err_rc);
492 cYAML_free_tree(err_rc);
496 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
498 if (rc != LUSTRE_CFG_RC_NO_ERR)
499 cYAML_print_tree2file(stderr, err_rc);
501 cYAML_free_tree(err_rc);
506 static int jt_config_lnet(int argc, char **argv)
508 struct cYAML *err_rc = NULL;
509 bool load_mod_params = false;
512 const char *const short_options = "a";
513 static const struct option long_options[] = {
514 { .name = "all", .has_arg = no_argument, .val = 'a' },
518 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
522 while ((opt = getopt_long(argc, argv, short_options,
523 long_options, NULL)) != -1) {
526 load_mod_params = true;
533 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
536 if (rc != LUSTRE_CFG_RC_NO_ERR)
537 cYAML_print_tree2file(stderr, err_rc);
539 cYAML_free_tree(err_rc);
544 static int jt_unconfig_lnet(int argc, char **argv)
546 struct cYAML *err_rc = NULL;
549 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
553 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
555 if (rc != LUSTRE_CFG_RC_NO_ERR)
556 cYAML_print_tree2file(stderr, err_rc);
558 cYAML_free_tree(err_rc);
562 static int jt_add_route(int argc, char **argv)
564 char *network = NULL, *gateway = NULL;
565 long int hop = -1, prio = -1;
566 struct cYAML *err_rc = NULL;
569 const char *const short_options = "n:g:c:p:";
570 static const struct option long_options[] = {
571 { .name = "net", .has_arg = required_argument, .val = 'n' },
572 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
573 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
574 { .name = "priority", .has_arg = required_argument, .val = 'p' },
577 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
581 while ((opt = getopt_long(argc, argv, short_options,
582 long_options, NULL)) != -1) {
591 rc = parse_long(optarg, &hop);
599 rc = parse_long(optarg, &prio);
611 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
613 if (rc != LUSTRE_CFG_RC_NO_ERR)
614 cYAML_print_tree2file(stderr, err_rc);
616 cYAML_free_tree(err_rc);
621 static int jt_add_ni(int argc, char **argv)
624 long int pto = -1, pc = -1, pbc = -1, cre = -1;
625 struct cYAML *err_rc = NULL;
626 int rc, opt, cpt_rc = -1;
627 struct lnet_dlc_network_descr nw_descr;
628 struct cfs_expr_list *global_cpts = NULL;
629 struct lnet_ioctl_config_lnd_tunables tunables;
632 memset(&tunables, 0, sizeof(tunables));
633 lustre_lnet_init_nw_descr(&nw_descr);
635 const char *const short_options = "n:i:p:t:c:b:r:s:";
636 static const struct option long_options[] = {
637 { .name = "net", .has_arg = required_argument, .val = 'n' },
638 { .name = "if", .has_arg = required_argument, .val = 'i' },
639 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
640 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
641 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
642 { .name = "peer-buffer-credits",
643 .has_arg = required_argument, .val = 'b' },
644 { .name = "credits", .has_arg = required_argument, .val = 'r' },
645 { .name = "cpt", .has_arg = required_argument, .val = 's' },
648 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
652 while ((opt = getopt_long(argc, argv, short_options,
653 long_options, NULL)) != -1) {
656 nw_descr.nw_id = libcfs_str2net(optarg);
659 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
661 cYAML_build_error(-1, -1, "ni", "add",
662 "bad interface list",
671 rc = parse_long(optarg, &pto);
679 rc = parse_long(optarg, &pc);
687 rc = parse_long(optarg, &pbc);
695 rc = parse_long(optarg, &cre);
703 cpt_rc = cfs_expr_list_parse(optarg,
705 UINT_MAX, &global_cpts);
712 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
713 tunables.lt_cmn.lct_peer_timeout = pto;
714 tunables.lt_cmn.lct_peer_tx_credits = pc;
715 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
716 tunables.lt_cmn.lct_max_tx_credits = cre;
720 rc = lustre_lnet_config_ni(&nw_descr,
721 (cpt_rc == 0) ? global_cpts: NULL,
722 ip2net, (found) ? &tunables : NULL,
725 if (global_cpts != NULL)
726 cfs_expr_list_free(global_cpts);
729 if (rc != LUSTRE_CFG_RC_NO_ERR)
730 cYAML_print_tree2file(stderr, err_rc);
732 cYAML_free_tree(err_rc);
737 static int jt_del_route(int argc, char **argv)
739 char *network = NULL, *gateway = NULL;
740 struct cYAML *err_rc = NULL;
743 const char *const short_options = "n:g:";
744 static const struct option long_options[] = {
745 { .name = "net", .has_arg = required_argument, .val = 'n' },
746 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
749 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
753 while ((opt = getopt_long(argc, argv, short_options,
754 long_options, NULL)) != -1) {
767 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
769 if (rc != LUSTRE_CFG_RC_NO_ERR)
770 cYAML_print_tree2file(stderr, err_rc);
772 cYAML_free_tree(err_rc);
777 static int jt_del_ni(int argc, char **argv)
779 struct cYAML *err_rc = NULL;
781 struct lnet_dlc_network_descr nw_descr;
783 lustre_lnet_init_nw_descr(&nw_descr);
785 const char *const short_options = "n:i:";
786 static const struct option long_options[] = {
787 { .name = "net", .has_arg = required_argument, .val = 'n' },
788 { .name = "if", .has_arg = required_argument, .val = 'i' },
791 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
795 while ((opt = getopt_long(argc, argv, short_options,
796 long_options, NULL)) != -1) {
799 nw_descr.nw_id = libcfs_str2net(optarg);
802 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
804 cYAML_build_error(-1, -1, "ni", "add",
805 "bad interface list",
815 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
818 if (rc != LUSTRE_CFG_RC_NO_ERR)
819 cYAML_print_tree2file(stderr, err_rc);
821 cYAML_free_tree(err_rc);
826 static int jt_show_route(int argc, char **argv)
828 char *network = NULL, *gateway = NULL;
829 long int hop = -1, prio = -1;
830 int detail = 0, rc, opt;
831 struct cYAML *err_rc = NULL, *show_rc = NULL;
833 const char *const short_options = "n:g:h:p:v";
834 static const struct option long_options[] = {
835 { .name = "net", .has_arg = required_argument, .val = 'n' },
836 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
837 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
838 { .name = "priority", .has_arg = required_argument, .val = 'p' },
839 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
842 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
846 while ((opt = getopt_long(argc, argv, short_options,
847 long_options, NULL)) != -1) {
856 rc = parse_long(optarg, &hop);
864 rc = parse_long(optarg, &prio);
879 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
880 &show_rc, &err_rc, false);
882 if (rc != LUSTRE_CFG_RC_NO_ERR)
883 cYAML_print_tree2file(stderr, err_rc);
885 cYAML_print_tree(show_rc);
887 cYAML_free_tree(err_rc);
888 cYAML_free_tree(show_rc);
893 static int jt_show_net(int argc, char **argv)
895 char *network = NULL;
897 struct cYAML *err_rc = NULL, *show_rc = NULL;
900 const char *const short_options = "n:v";
901 static const struct option long_options[] = {
902 { .name = "net", .has_arg = required_argument, .val = 'n' },
903 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
906 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
910 while ((opt = getopt_long(argc, argv, short_options,
911 long_options, NULL)) != -1) {
917 if ((!optarg) && (argv[optind] != NULL) &&
918 (argv[optind][0] != '-')) {
919 if (parse_long(argv[optind++], &detail) != 0)
930 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
933 if (rc != LUSTRE_CFG_RC_NO_ERR)
934 cYAML_print_tree2file(stderr, err_rc);
936 cYAML_print_tree(show_rc);
938 cYAML_free_tree(err_rc);
939 cYAML_free_tree(show_rc);
944 static int jt_show_routing(int argc, char **argv)
946 struct cYAML *err_rc = NULL, *show_rc = NULL;
949 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
953 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
955 if (rc != LUSTRE_CFG_RC_NO_ERR)
956 cYAML_print_tree2file(stderr, err_rc);
958 cYAML_print_tree(show_rc);
960 cYAML_free_tree(err_rc);
961 cYAML_free_tree(show_rc);
966 static int jt_show_stats(int argc, char **argv)
969 struct cYAML *show_rc = NULL, *err_rc = NULL;
971 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
975 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
977 if (rc != LUSTRE_CFG_RC_NO_ERR)
978 cYAML_print_tree2file(stderr, err_rc);
980 cYAML_print_tree(show_rc);
982 cYAML_free_tree(err_rc);
983 cYAML_free_tree(show_rc);
988 static int jt_show_global(int argc, char **argv)
991 struct cYAML *show_rc = NULL, *err_rc = NULL;
993 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
997 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
998 if (rc != LUSTRE_CFG_RC_NO_ERR) {
999 cYAML_print_tree2file(stderr, err_rc);
1003 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1004 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1005 cYAML_print_tree2file(stderr, err_rc);
1009 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1010 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1011 cYAML_print_tree2file(stderr, err_rc);
1015 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1016 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1017 cYAML_print_tree2file(stderr, err_rc);
1022 cYAML_print_tree(show_rc);
1025 cYAML_free_tree(err_rc);
1026 cYAML_free_tree(show_rc);
1031 static int jt_lnet(int argc, char **argv)
1035 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1039 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1042 static int jt_route(int argc, char **argv)
1046 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1050 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1053 static int jt_net(int argc, char **argv)
1057 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1061 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1064 static int jt_routing(int argc, char **argv)
1068 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1072 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1075 static int jt_stats(int argc, char **argv)
1079 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1083 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1086 static int jt_global(int argc, char **argv)
1090 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1094 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1097 static int jt_peers(int argc, char **argv)
1101 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1105 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1108 static int jt_set(int argc, char **argv)
1112 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1116 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1119 static int jt_import(int argc, char **argv)
1122 struct cYAML *err_rc = NULL;
1123 struct cYAML *show_rc = NULL;
1124 int rc = 0, return_rc = 0, opt, opt_found = 0;
1127 const char *const short_options = "adseh";
1128 static const struct option long_options[] = {
1129 { .name = "add", .has_arg = no_argument, .val = 'a' },
1130 { .name = "del", .has_arg = no_argument, .val = 'd' },
1131 { .name = "show", .has_arg = no_argument, .val = 's' },
1132 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1133 { .name = "help", .has_arg = no_argument, .val = 'h' },
1136 while ((opt = getopt_long(argc, argv, short_options,
1137 long_options, NULL)) != -1) {
1151 printf("import FILE\n"
1152 "import < FILE : import a file\n"
1153 "\t--add: add configuration\n"
1154 "\t--del: delete configuration\n"
1155 "\t--show: show configuration\n"
1156 "\t--exec: execute command\n"
1157 "\t--help: display this help\n"
1158 "If no command option is given then --add"
1159 " is assumed by default\n");
1166 /* grab the file name if one exists */
1167 if (opt_found && argc == 3)
1169 else if (!opt_found && argc == 2)
1174 rc = lustre_yaml_config(file, &err_rc);
1175 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1176 cYAML_print_tree(show_rc);
1177 cYAML_free_tree(show_rc);
1180 rc = lustre_yaml_del(file, &err_rc);
1183 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1184 cYAML_print_tree(show_rc);
1185 cYAML_free_tree(show_rc);
1188 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1189 cYAML_print_tree(show_rc);
1190 cYAML_free_tree(show_rc);
1194 if (rc || return_rc) {
1195 cYAML_print_tree2file(stderr, err_rc);
1196 cYAML_free_tree(err_rc);
1202 static int jt_export(int argc, char **argv)
1204 struct cYAML *show_rc = NULL;
1205 struct cYAML *err_rc = NULL;
1209 bool backup = false;
1212 const char *const short_options = "bh";
1213 static const struct option long_options[] = {
1214 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1215 { .name = "help", .has_arg = no_argument, .val = 'h' },
1218 while ((opt = getopt_long(argc, argv, short_options,
1219 long_options, NULL)) != -1) {
1226 printf("export > FILE.yaml : export configuration\n"
1227 "\t--backup: export only what's necessary for reconfig\n"
1228 "\t--help: display this help\n");
1233 if (backup && argc >= 3)
1235 else if (!backup && argc >= 2)
1241 f = fopen(file, "w");
1246 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1247 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1248 cYAML_print_tree2file(stderr, err_rc);
1249 cYAML_free_tree(err_rc);
1253 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1255 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1256 cYAML_print_tree2file(stderr, err_rc);
1257 cYAML_free_tree(err_rc);
1261 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1262 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1263 cYAML_print_tree2file(stderr, err_rc);
1264 cYAML_free_tree(err_rc);
1268 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1269 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1270 cYAML_print_tree2file(stderr, err_rc);
1271 cYAML_free_tree(err_rc);
1275 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1276 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1277 cYAML_print_tree2file(stderr, err_rc);
1278 cYAML_free_tree(err_rc);
1282 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1283 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1284 cYAML_print_tree2file(stderr, err_rc);
1285 cYAML_free_tree(err_rc);
1289 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1290 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1291 cYAML_print_tree2file(stderr, err_rc);
1292 cYAML_free_tree(err_rc);
1296 if (show_rc != NULL) {
1297 cYAML_print_tree2file(f, show_rc);
1298 cYAML_free_tree(show_rc);
1307 static int jt_add_peer_nid(int argc, char **argv)
1309 char *prim_nid = NULL;
1310 char **nids = NULL, **nids2 = NULL;
1312 struct cYAML *err_rc = NULL;
1313 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1314 bool non_mr = false;
1315 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1317 const char *const short_opts = "k:mn:";
1318 const struct option long_opts[] = {
1319 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1320 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1321 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1322 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1325 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1329 while ((opt = getopt_long(argc, argv, short_opts,
1330 long_opts, NULL)) != -1) {
1333 prim_nid_present = true;
1335 cYAML_build_error(-1, -1, "peer", "add",
1336 "ip2nets can not be specified"
1337 " along side prim_nid parameter.",
1351 if (ip2nets && (nid_list || prim_nid_present)) {
1352 cYAML_build_error(-1, -1, "peer", "add",
1353 "ip2nets can not be specified"
1354 " along side nid or prim_nid"
1355 " parameters", &err_rc);
1359 size = lustre_lnet_parse_nids(optarg, nids, size,
1364 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1374 for (; optind < argc; optind++) {
1375 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1382 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1383 !non_mr, ip2nets, -1, &err_rc);
1387 /* free the array of nids */
1388 for (i = 0; i < size; i++)
1393 if (rc != LUSTRE_CFG_RC_NO_ERR)
1394 cYAML_print_tree2file(stderr, err_rc);
1396 cYAML_free_tree(err_rc);
1401 static int jt_del_peer_nid(int argc, char **argv)
1403 char *prim_nid = NULL;
1404 char **nids = NULL, **nids2 = NULL;
1405 struct cYAML *err_rc = NULL;
1406 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1407 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1409 const char *const short_opts = "k:n:";
1410 const struct option long_opts[] = {
1411 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1412 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1413 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1416 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1420 while ((opt = getopt_long(argc, argv, short_opts,
1421 long_opts, NULL)) != -1) {
1424 prim_nid_present = true;
1426 cYAML_build_error(-1, -1, "peer", "add",
1427 "ip2nets can not be specified"
1428 " along side prim_nid parameter.",
1442 if (ip2nets && (nid_list || prim_nid_present)) {
1443 cYAML_build_error(-1, -1, "peer", "add",
1444 "ip2nets can not be specified"
1445 " along side nid or prim_nid"
1446 " parameters", &err_rc);
1449 size = lustre_lnet_parse_nids(optarg, nids, size,
1454 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1461 for (; optind < argc; optind++) {
1462 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1469 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1473 for (i = 0; i < size; i++)
1478 if (rc != LUSTRE_CFG_RC_NO_ERR)
1479 cYAML_print_tree2file(stderr, err_rc);
1481 cYAML_free_tree(err_rc);
1486 static int jt_show_peer(int argc, char **argv)
1490 struct cYAML *err_rc = NULL, *show_rc = NULL;
1491 long int detail = 0;
1493 const char *const short_opts = "hn:v::";
1494 const struct option long_opts[] = {
1495 { .name = "help", .has_arg = no_argument, .val = 'h' },
1496 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1497 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1500 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1504 while ((opt = getopt_long(argc, argv, short_opts,
1505 long_opts, NULL)) != -1) {
1511 if ((!optarg) && (argv[optind] != NULL) &&
1512 (argv[optind][0] != '-')) {
1513 if (parse_long(argv[optind++], &detail) != 0)
1524 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1527 if (rc != LUSTRE_CFG_RC_NO_ERR)
1528 cYAML_print_tree2file(stderr, err_rc);
1530 cYAML_print_tree(show_rc);
1532 cYAML_free_tree(err_rc);
1533 cYAML_free_tree(show_rc);
1538 static int jt_list_peer(int argc, char **argv)
1541 struct cYAML *err_rc = NULL, *list_rc = NULL;
1543 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1547 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1549 if (rc != LUSTRE_CFG_RC_NO_ERR)
1550 cYAML_print_tree2file(stderr, err_rc);
1552 cYAML_print_tree(list_rc);
1554 cYAML_free_tree(err_rc);
1555 cYAML_free_tree(list_rc);
1560 static int jt_ping(int argc, char **argv)
1562 struct cYAML *err_rc = NULL;
1563 struct cYAML *show_rc = NULL;
1567 const char *const short_options = "ht:";
1568 const struct option long_options[] = {
1569 { .name = "help", .has_arg = no_argument, .val = 'h' },
1570 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1573 while ((opt = getopt_long(argc, argv, short_options,
1574 long_options, NULL)) != -1) {
1577 timeout = 1000 * atol(optarg);
1580 printf("ping nid[,nid,...]\n"
1581 "\t --timeout: ping timeout\n"
1582 "\t --help: display this help\n");
1589 for (; optind < argc; optind++)
1590 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1593 cYAML_print_tree(show_rc);
1596 cYAML_print_tree2file(stderr, err_rc);
1598 cYAML_free_tree(err_rc);
1599 cYAML_free_tree(show_rc);
1604 static int jt_discover(int argc, char **argv)
1606 struct cYAML *err_rc = NULL;
1607 struct cYAML *show_rc = NULL;
1611 const char *const short_options = "fh";
1612 const struct option long_options[] = {
1613 { .name = "force", .has_arg = no_argument, .val = 'f' },
1614 { .name = "help", .has_arg = no_argument, .val = 'h' },
1617 while ((opt = getopt_long(argc, argv, short_options,
1618 long_options, NULL)) != -1) {
1624 printf("discover nid[,nid,...]\n"
1625 "\t --force: force discovery\n"
1626 "\t --help: display this help\n");
1633 for (; optind < argc; optind++)
1634 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1638 cYAML_print_tree(show_rc);
1641 cYAML_print_tree2file(stderr, err_rc);
1643 cYAML_free_tree(err_rc);
1644 cYAML_free_tree(show_rc);
1649 static int lnetctl_list_commands(int argc, char **argv)
1651 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1653 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1658 int main(int argc, char **argv)
1661 struct cYAML *err_rc = NULL;
1663 rc = lustre_lnet_config_lib_init();
1665 cYAML_build_error(-1, -1, "lnetctl", "startup",
1666 "cannot register LNet device", &err_rc);
1667 cYAML_print_tree2file(stderr, err_rc);
1671 Parser_init("lnetctl > ", cmd_list);
1673 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);