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, 2016, 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_add_peer_nid(int argc, char **argv);
57 static int jt_del_peer_nid(int argc, char **argv);
58 static int jt_set_max_intf(int argc, char **argv);
59 static int jt_set_discovery(int argc, char **argv);
60 static int jt_list_peer(int argc, char **argv);
61 /*static int jt_show_peer(int argc, char **argv);*/
62 static int lnetctl_list_commands(int argc, char **argv);
64 command_t lnet_cmds[] = {
65 {"configure", jt_config_lnet, 0, "configure lnet\n"
66 "\t--all: load NI configuration from module parameters\n"},
67 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
71 command_t route_cmds[] = {
72 {"add", jt_add_route, 0, "add a route\n"
73 "\t--net: net name (e.g. tcp0)\n"
74 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
75 "\t--hop: number to final destination (1 < hops < 255)\n"
76 "\t--priority: priority of route (0 - highest prio\n"},
77 {"del", jt_del_route, 0, "delete a route\n"
78 "\t--net: net name (e.g. tcp0)\n"
79 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
80 {"show", jt_show_route, 0, "show routes\n"
81 "\t--net: net name (e.g. tcp0) to filter on\n"
82 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
83 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
84 "\t--priority: priority of route (0 - highest prio to filter on\n"
85 "\t--verbose: display detailed output per route\n"},
89 command_t net_cmds[] = {
90 {"add", jt_add_ni, 0, "add a network\n"
91 "\t--net: net name (e.g. tcp0)\n"
92 "\t--if: physical interface (e.g. eth0)\n"
93 "\t--ip2net: specify networks based on IP address patterns\n"
94 "\t--peer-timeout: time to wait before declaring a peer dead\n"
95 "\t--peer-credits: define the max number of inflight messages\n"
96 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
97 "\t--credits: Network Interface credits\n"
98 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
99 {"del", jt_del_ni, 0, "delete a network\n"
100 "\t--net: net name (e.g. tcp0)\n"
101 "\t--if: physical interface (e.g. eth0)\n"},
102 {"show", jt_show_net, 0, "show networks\n"
103 "\t--net: net name (e.g. tcp0) to filter on\n"
104 "\t--verbose: display detailed output per network\n"},
108 command_t routing_cmds[] = {
109 {"show", jt_show_routing, 0, "show routing information\n"},
113 command_t stats_cmds[] = {
114 {"show", jt_show_stats, 0, "show LNET statistics\n"},
118 command_t global_cmds[] = {
119 {"show", jt_show_global, 0, "show global variables\n"},
123 command_t set_cmds[] = {
124 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
125 "\tVALUE must be greater than 0\n"},
126 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
127 "\tVALUE must be greater than 0\n"},
128 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
129 "\tVALUE must be greater than 0\n"},
130 {"routing", jt_set_routing, 0, "enable/disable routing\n"
131 "\t0 - disable routing\n"
132 "\t1 - enable routing\n"},
133 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
134 "\tVALUE must be at least 0\n"},
135 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
137 "\tValue must be greater than 16\n"},
138 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
139 "\t0 - disable peer discovery\n"
140 "\t1 - enable peer discovery (default)\n"},
144 command_t peer_cmds[] = {
145 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
146 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
147 "\t NID in the list becomes the Primary NID of a newly created\n"
149 "\t--nid: one or more peer NIDs\n"
150 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
151 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
152 "\t--prim_nid: Primary NID of the peer.\n"
153 "\t--nid: list of NIDs to remove. If none provided,\n"
154 "\t peer is deleted\n"},
155 {"show", jt_show_peer, 0, "show peer information\n"
156 "\t--nid: NID of peer to filter on.\n"
157 "\t--verbose: Include extended statistics\n"},
158 {"list", jt_list_peer, 0, "list all peers\n"},
162 static inline void print_help(const command_t cmds[], const char *cmd_type,
165 const command_t *cmd;
167 for (cmd = cmds; cmd->pc_name; cmd++) {
168 if (pc_name != NULL &&
169 strcmp(cmd->pc_name, pc_name) == 0) {
170 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
173 } else if (pc_name != NULL) {
176 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
180 static int parse_long(const char *number, long int *value)
184 *value = strtol(number, &end, 0);
185 if (end != NULL && *end != 0)
191 static int handle_help(const command_t *cmd_list, const char *cmd,
192 const char *sub_cmd, int argc, char **argv)
199 const char *const short_options = "h";
200 static const struct option long_options[] = {
201 { .name = "help", .has_arg = no_argument, .val = 'h' },
205 while ((opt = getopt_long(argc, argv, short_options,
206 long_options, NULL)) != -1) {
209 print_help(cmd_list, cmd, sub_cmd);
223 static int jt_set_max_intf(int argc, char **argv)
227 struct cYAML *err_rc = NULL;
229 if (handle_help(set_cmds, "set", "max_interfaces", argc, argv) == 0)
232 rc = parse_long(argv[1], &value);
234 cYAML_build_error(-1, -1, "parser", "set",
235 "cannot parse max_interfaces value", &err_rc);
236 cYAML_print_tree2file(stderr, err_rc);
237 cYAML_free_tree(err_rc);
241 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
242 if (rc != LUSTRE_CFG_RC_NO_ERR)
243 cYAML_print_tree2file(stderr, err_rc);
245 cYAML_free_tree(err_rc);
250 static int jt_set_numa(int argc, char **argv)
254 struct cYAML *err_rc = NULL;
256 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
259 rc = parse_long(argv[1], &value);
261 cYAML_build_error(-1, -1, "parser", "set",
262 "cannot parse numa_range value", &err_rc);
263 cYAML_print_tree2file(stderr, err_rc);
264 cYAML_free_tree(err_rc);
268 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
269 if (rc != LUSTRE_CFG_RC_NO_ERR)
270 cYAML_print_tree2file(stderr, err_rc);
272 cYAML_free_tree(err_rc);
277 static int jt_set_discovery(int argc, char **argv)
281 struct cYAML *err_rc = NULL;
283 if (handle_help(set_cmds, "set", "discovery", argc, argv) == 0)
286 rc = parse_long(argv[1], &value);
288 cYAML_build_error(-1, -1, "parser", "set",
289 "cannot parse discovery value", &err_rc);
290 cYAML_print_tree2file(stderr, err_rc);
291 cYAML_free_tree(err_rc);
295 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
296 if (rc != LUSTRE_CFG_RC_NO_ERR)
297 cYAML_print_tree2file(stderr, err_rc);
299 cYAML_free_tree(err_rc);
304 static int jt_set_tiny(int argc, char **argv)
308 struct cYAML *err_rc = NULL;
310 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
313 rc = parse_long(argv[1], &value);
315 cYAML_build_error(-1, -1, "parser", "set",
316 "cannot parse tiny_buffers value", &err_rc);
317 cYAML_print_tree2file(stderr, err_rc);
318 cYAML_free_tree(err_rc);
322 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
323 if (rc != LUSTRE_CFG_RC_NO_ERR)
324 cYAML_print_tree2file(stderr, err_rc);
326 cYAML_free_tree(err_rc);
331 static int jt_set_small(int argc, char **argv)
335 struct cYAML *err_rc = NULL;
337 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
340 rc = parse_long(argv[1], &value);
342 cYAML_build_error(-1, -1, "parser", "set",
343 "cannot parse small_buffers value", &err_rc);
344 cYAML_print_tree2file(stderr, err_rc);
345 cYAML_free_tree(err_rc);
349 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
350 if (rc != LUSTRE_CFG_RC_NO_ERR)
351 cYAML_print_tree2file(stderr, err_rc);
353 cYAML_free_tree(err_rc);
358 static int jt_set_large(int argc, char **argv)
362 struct cYAML *err_rc = NULL;
364 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
367 rc = parse_long(argv[1], &value);
369 cYAML_build_error(-1, -1, "parser", "set",
370 "cannot parse large_buffers value", &err_rc);
371 cYAML_print_tree2file(stderr, err_rc);
372 cYAML_free_tree(err_rc);
376 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
377 if (rc != LUSTRE_CFG_RC_NO_ERR)
378 cYAML_print_tree2file(stderr, err_rc);
380 cYAML_free_tree(err_rc);
385 static int jt_set_routing(int argc, char **argv)
388 struct cYAML *err_rc = NULL;
391 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
394 rc = parse_long(argv[1], &value);
395 if (rc != 0 || (value != 0 && value != 1)) {
396 cYAML_build_error(-1, -1, "parser", "set",
397 "cannot parse routing value.\n"
398 "must be 0 for disable or 1 for enable",
400 cYAML_print_tree2file(stderr, err_rc);
401 cYAML_free_tree(err_rc);
405 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
407 if (rc != LUSTRE_CFG_RC_NO_ERR)
408 cYAML_print_tree2file(stderr, err_rc);
410 cYAML_free_tree(err_rc);
415 static int jt_config_lnet(int argc, char **argv)
417 struct cYAML *err_rc = NULL;
418 bool load_mod_params = false;
421 const char *const short_options = "ah";
422 static const struct option long_options[] = {
423 { .name = "all", .has_arg = no_argument, .val = 'a' },
424 { .name = "help", .has_arg = no_argument, .val = 'h' },
428 while ((opt = getopt_long(argc, argv, short_options,
429 long_options, NULL)) != -1) {
432 load_mod_params = true;
435 print_help(lnet_cmds, "lnet", "configure");
442 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
445 if (rc != LUSTRE_CFG_RC_NO_ERR)
446 cYAML_print_tree2file(stderr, err_rc);
448 cYAML_free_tree(err_rc);
453 static int jt_unconfig_lnet(int argc, char **argv)
455 struct cYAML *err_rc = NULL;
458 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
461 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
463 if (rc != LUSTRE_CFG_RC_NO_ERR)
464 cYAML_print_tree2file(stderr, err_rc);
466 cYAML_free_tree(err_rc);
470 static int jt_add_route(int argc, char **argv)
472 char *network = NULL, *gateway = NULL;
473 long int hop = -1, prio = -1;
474 struct cYAML *err_rc = NULL;
477 const char *const short_options = "n:g:c:p:h";
478 static const struct option long_options[] = {
479 { .name = "net", .has_arg = required_argument, .val = 'n' },
480 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
481 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
482 { .name = "priority", .has_arg = required_argument, .val = 'p' },
483 { .name = "help", .has_arg = no_argument, .val = 'h' },
486 while ((opt = getopt_long(argc, argv, short_options,
487 long_options, NULL)) != -1) {
496 rc = parse_long(optarg, &hop);
504 rc = parse_long(optarg, &prio);
512 print_help(route_cmds, "route", "add");
519 rc = lustre_lnet_config_route(network, gateway, hop, prio, -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_add_ni(int argc, char **argv)
532 long int pto = -1, pc = -1, pbc = -1, cre = -1;
533 struct cYAML *err_rc = NULL;
534 int rc, opt, cpt_rc = -1;
535 struct lnet_dlc_network_descr nw_descr;
536 struct cfs_expr_list *global_cpts = NULL;
537 struct lnet_ioctl_config_lnd_tunables tunables;
540 memset(&tunables, 0, sizeof(tunables));
541 lustre_lnet_init_nw_descr(&nw_descr);
543 const char *const short_options = "n:i:p:t:c:b:r:s:h";
544 static const struct option long_options[] = {
545 { .name = "net", .has_arg = required_argument, .val = 'n' },
546 { .name = "if", .has_arg = required_argument, .val = 'i' },
547 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
548 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
549 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
550 { .name = "peer-buffer-credits",
551 .has_arg = required_argument, .val = 'b' },
552 { .name = "credits", .has_arg = required_argument, .val = 'r' },
553 { .name = "cpt", .has_arg = required_argument, .val = 's' },
554 { .name = "help", .has_arg = no_argument, .val = 'h' },
557 while ((opt = getopt_long(argc, argv, short_options,
558 long_options, NULL)) != -1) {
561 nw_descr.nw_id = libcfs_str2net(optarg);
564 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
566 cYAML_build_error(-1, -1, "ni", "add",
567 "bad interface list",
576 rc = parse_long(optarg, &pto);
584 rc = parse_long(optarg, &pc);
592 rc = parse_long(optarg, &pbc);
600 rc = parse_long(optarg, &cre);
608 cpt_rc = cfs_expr_list_parse(optarg,
610 UINT_MAX, &global_cpts);
613 print_help(net_cmds, "net", "add");
620 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
621 tunables.lt_cmn.lct_peer_timeout = pto;
622 tunables.lt_cmn.lct_peer_tx_credits = pc;
623 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
624 tunables.lt_cmn.lct_max_tx_credits = cre;
628 rc = lustre_lnet_config_ni(&nw_descr,
629 (cpt_rc == 0) ? global_cpts: NULL,
630 ip2net, (found) ? &tunables : NULL,
633 if (global_cpts != NULL)
634 cfs_expr_list_free(global_cpts);
637 if (rc != LUSTRE_CFG_RC_NO_ERR)
638 cYAML_print_tree2file(stderr, err_rc);
640 cYAML_free_tree(err_rc);
645 static int jt_del_route(int argc, char **argv)
647 char *network = NULL, *gateway = NULL;
648 struct cYAML *err_rc = NULL;
651 const char *const short_options = "n:g:h";
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 = "help", .has_arg = no_argument, .val = 'h' },
658 while ((opt = getopt_long(argc, argv, short_options,
659 long_options, NULL)) != -1) {
668 print_help(route_cmds, "route", "del");
675 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
677 if (rc != LUSTRE_CFG_RC_NO_ERR)
678 cYAML_print_tree2file(stderr, err_rc);
680 cYAML_free_tree(err_rc);
685 static int jt_del_ni(int argc, char **argv)
687 struct cYAML *err_rc = NULL;
689 struct lnet_dlc_network_descr nw_descr;
691 lustre_lnet_init_nw_descr(&nw_descr);
693 const char *const short_options = "n:i:h";
694 static const struct option long_options[] = {
695 { .name = "net", .has_arg = required_argument, .val = 'n' },
696 { .name = "if", .has_arg = required_argument, .val = 'i' },
697 { .name = "help", .has_arg = no_argument, .val = 'h' },
700 while ((opt = getopt_long(argc, argv, short_options,
701 long_options, NULL)) != -1) {
704 nw_descr.nw_id = libcfs_str2net(optarg);
707 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
709 cYAML_build_error(-1, -1, "ni", "add",
710 "bad interface list",
716 print_help(net_cmds, "net", "del");
723 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
726 if (rc != LUSTRE_CFG_RC_NO_ERR)
727 cYAML_print_tree2file(stderr, err_rc);
729 cYAML_free_tree(err_rc);
734 static int jt_show_route(int argc, char **argv)
736 char *network = NULL, *gateway = NULL;
737 long int hop = -1, prio = -1;
738 int detail = 0, rc, opt;
739 struct cYAML *err_rc = NULL, *show_rc = NULL;
741 const char *const short_options = "n:g:h:p:vh";
742 static const struct option long_options[] = {
743 { .name = "net", .has_arg = required_argument, .val = 'n' },
744 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
745 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
746 { .name = "priority", .has_arg = required_argument, .val = 'p' },
747 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
748 { .name = "help", .has_arg = no_argument, .val = 'h' },
751 while ((opt = getopt_long(argc, argv, short_options,
752 long_options, NULL)) != -1) {
761 rc = parse_long(optarg, &hop);
769 rc = parse_long(optarg, &prio);
780 print_help(route_cmds, "route", "show");
787 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
790 if (rc != LUSTRE_CFG_RC_NO_ERR)
791 cYAML_print_tree2file(stderr, err_rc);
793 cYAML_print_tree(show_rc);
795 cYAML_free_tree(err_rc);
796 cYAML_free_tree(show_rc);
801 static int jt_show_net(int argc, char **argv)
803 char *network = NULL;
804 int detail = 0, rc, opt;
805 struct cYAML *err_rc = NULL, *show_rc = NULL;
807 const char *const short_options = "n:vh";
808 static const struct option long_options[] = {
809 { .name = "net", .has_arg = required_argument, .val = 'n' },
810 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
811 { .name = "help", .has_arg = no_argument, .val = 'h' },
814 while ((opt = getopt_long(argc, argv, short_options,
815 long_options, NULL)) != -1) {
824 print_help(net_cmds, "net", "show");
831 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
833 if (rc != LUSTRE_CFG_RC_NO_ERR)
834 cYAML_print_tree2file(stderr, err_rc);
836 cYAML_print_tree(show_rc);
838 cYAML_free_tree(err_rc);
839 cYAML_free_tree(show_rc);
844 static int jt_show_routing(int argc, char **argv)
846 struct cYAML *err_rc = NULL, *show_rc = NULL;
849 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
852 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
854 if (rc != LUSTRE_CFG_RC_NO_ERR)
855 cYAML_print_tree2file(stderr, err_rc);
857 cYAML_print_tree(show_rc);
859 cYAML_free_tree(err_rc);
860 cYAML_free_tree(show_rc);
865 static int jt_show_stats(int argc, char **argv)
868 struct cYAML *show_rc = NULL, *err_rc = NULL;
870 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
873 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
875 if (rc != LUSTRE_CFG_RC_NO_ERR)
876 cYAML_print_tree2file(stderr, err_rc);
878 cYAML_print_tree(show_rc);
880 cYAML_free_tree(err_rc);
881 cYAML_free_tree(show_rc);
886 static int jt_show_global(int argc, char **argv)
889 struct cYAML *show_rc = NULL, *err_rc = NULL;
891 if (handle_help(global_cmds, "global", "show", argc, argv) == 0)
894 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
895 if (rc != LUSTRE_CFG_RC_NO_ERR) {
896 cYAML_print_tree2file(stderr, err_rc);
900 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
901 if (rc != LUSTRE_CFG_RC_NO_ERR) {
902 cYAML_print_tree2file(stderr, err_rc);
906 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
907 if (rc != LUSTRE_CFG_RC_NO_ERR) {
908 cYAML_print_tree2file(stderr, err_rc);
913 cYAML_print_tree(show_rc);
916 cYAML_free_tree(err_rc);
917 cYAML_free_tree(show_rc);
922 static inline int jt_lnet(int argc, char **argv)
928 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
931 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
934 static inline int jt_route(int argc, char **argv)
940 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
943 return Parser_execarg(argc - 1, &argv[1], route_cmds);
946 static inline int jt_net(int argc, char **argv)
952 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
955 return Parser_execarg(argc - 1, &argv[1], net_cmds);
958 static inline int jt_routing(int argc, char **argv)
964 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
967 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
970 static inline int jt_stats(int argc, char **argv)
976 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
979 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
982 static inline int jt_global(int argc, char **argv)
988 handle_help(global_cmds, "global", NULL, argc, argv) == 0)
991 return Parser_execarg(argc - 1, &argv[1], global_cmds);
994 static inline int jt_peers(int argc, char **argv)
1000 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
1003 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1006 static inline int jt_set(int argc, char **argv)
1012 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
1015 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1018 static int jt_import(int argc, char **argv)
1021 struct cYAML *err_rc = NULL;
1022 struct cYAML *show_rc = NULL;
1023 int rc = 0, opt, opt_found = 0;
1026 const char *const short_options = "adsh";
1027 static const struct option long_options[] = {
1028 { .name = "add", .has_arg = no_argument, .val = 'a' },
1029 { .name = "del", .has_arg = no_argument, .val = 'd' },
1030 { .name = "show", .has_arg = no_argument, .val = 's' },
1031 { .name = "help", .has_arg = no_argument, .val = 'h' },
1034 while ((opt = getopt_long(argc, argv, short_options,
1035 long_options, NULL)) != -1) {
1044 printf("import FILE\n"
1045 "import < FILE : import a file\n"
1046 "\t--add: add configuration\n"
1047 "\t--del: delete configuration\n"
1048 "\t--show: show configuration\n"
1049 "\t--help: display this help\n"
1050 "If no command option is given then --add"
1051 " is assumed by default\n");
1058 /* grab the file name if one exists */
1059 if (opt_found && argc == 3)
1061 else if (!opt_found && argc == 2)
1066 rc = lustre_yaml_config(file, &err_rc);
1069 rc = lustre_yaml_del(file, &err_rc);
1072 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1073 cYAML_print_tree(show_rc);
1074 cYAML_free_tree(show_rc);
1078 cYAML_print_tree2file(stderr, err_rc);
1080 cYAML_free_tree(err_rc);
1085 static int jt_export(int argc, char **argv)
1087 struct cYAML *show_rc = NULL;
1088 struct cYAML *err_rc = NULL;
1092 const char *const short_options = "h";
1093 static const struct option long_options[] = {
1094 { .name = "help", .has_arg = no_argument, .val = 'h' },
1097 while ((opt = getopt_long(argc, argv, short_options,
1098 long_options, NULL)) != -1) {
1101 printf("export FILE\n"
1102 "export > FILE : export configuration\n"
1103 "\t--help: display this help\n");
1111 f = fopen(argv[1], "w");
1117 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1118 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1119 cYAML_print_tree2file(stderr, err_rc);
1120 cYAML_free_tree(err_rc);
1123 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1125 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1126 cYAML_print_tree2file(stderr, err_rc);
1127 cYAML_free_tree(err_rc);
1130 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1131 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1132 cYAML_print_tree2file(stderr, err_rc);
1133 cYAML_free_tree(err_rc);
1136 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1137 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1138 cYAML_print_tree2file(stderr, err_rc);
1139 cYAML_free_tree(err_rc);
1142 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1143 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1144 cYAML_print_tree2file(stderr, err_rc);
1145 cYAML_free_tree(err_rc);
1148 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1149 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1150 cYAML_print_tree2file(stderr, err_rc);
1151 cYAML_free_tree(err_rc);
1154 if (show_rc != NULL) {
1155 cYAML_print_tree2file(f, show_rc);
1156 cYAML_free_tree(show_rc);
1165 static int jt_add_peer_nid(int argc, char **argv)
1167 char *prim_nid = NULL;
1168 char **nids = NULL, **nids2 = NULL;
1170 struct cYAML *err_rc = NULL;
1171 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1172 bool non_mr = false;
1174 const char *const short_options = "k:n:mh";
1175 const struct option long_options[] = {
1176 { "prim_nid", 1, NULL, 'k' },
1177 { "nid", 1, NULL, 'n' },
1178 { "non_mr", 0, NULL, 'm'},
1179 { "help", 0, NULL, 'h' },
1180 { NULL, 0, NULL, 0 },
1183 while ((opt = getopt_long(argc, argv, short_options,
1184 long_options, NULL)) != -1) {
1190 size = lustre_lnet_parse_nids(optarg, nids, size,
1195 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1201 print_help(peer_cmds, "peer", "add");
1208 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1209 !non_mr, -1, &err_rc);
1213 /* free the array of nids */
1214 for (i = 0; i < size; i++)
1219 if (rc != LUSTRE_CFG_RC_NO_ERR)
1220 cYAML_print_tree2file(stderr, err_rc);
1222 cYAML_free_tree(err_rc);
1227 static int jt_del_peer_nid(int argc, char **argv)
1229 char *prim_nid = NULL;
1230 char **nids = NULL, **nids2 = NULL;
1231 struct cYAML *err_rc = NULL;
1232 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1234 const char *const short_options = "k:n:h";
1235 const struct option long_options[] = {
1236 { "prim_nid", 1, NULL, 'k' },
1237 { "nid", 1, NULL, 'n' },
1238 { "help", 0, NULL, 'h' },
1239 { NULL, 0, NULL, 0 },
1242 while ((opt = getopt_long(argc, argv, short_options,
1243 long_options, NULL)) != -1) {
1249 size = lustre_lnet_parse_nids(optarg, nids, size,
1254 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1257 print_help(peer_cmds, "peer", "show");
1264 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1268 for (i = 0; i < size; i++)
1273 if (rc != LUSTRE_CFG_RC_NO_ERR)
1274 cYAML_print_tree2file(stderr, err_rc);
1276 cYAML_free_tree(err_rc);
1281 static int jt_show_peer(int argc, char **argv)
1285 struct cYAML *err_rc = NULL, *show_rc = NULL;
1288 const char *const short_options = "n:vh";
1289 const struct option long_options[] = {
1290 { "nid", 1, NULL, 'n' },
1291 { "verbose", 0, NULL, 'v' },
1292 { "help", 0, NULL, 'h' },
1293 { NULL, 0, NULL, 0 },
1296 while ((opt = getopt_long(argc, argv, short_options,
1297 long_options, NULL)) != -1) {
1306 print_help(peer_cmds, "peer", "show");
1313 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1315 if (rc != LUSTRE_CFG_RC_NO_ERR)
1316 cYAML_print_tree2file(stderr, err_rc);
1318 cYAML_print_tree(show_rc);
1320 cYAML_free_tree(err_rc);
1321 cYAML_free_tree(show_rc);
1326 static int jt_list_peer(int argc, char **argv)
1329 struct cYAML *err_rc = NULL, *list_rc = NULL;
1331 const char *const short_options = "h";
1332 const struct option long_options[] = {
1333 { "help", 0, NULL, 'h' },
1334 { NULL, 0, NULL, 0 },
1337 while ((opt = getopt_long(argc, argv, short_options,
1338 long_options, NULL)) != -1) {
1341 print_help(peer_cmds, "peer", "list");
1348 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1350 if (rc != LUSTRE_CFG_RC_NO_ERR)
1351 cYAML_print_tree2file(stderr, err_rc);
1353 cYAML_print_tree(list_rc);
1355 cYAML_free_tree(err_rc);
1356 cYAML_free_tree(list_rc);
1361 command_t list[] = {
1362 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1363 {"route", jt_route, 0, "route {add | del | show | help}"},
1364 {"net", jt_net, 0, "net {add | del | show | help}"},
1365 {"routing", jt_routing, 0, "routing {show | help}"},
1366 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1367 " | routing | numa_range | max_interfaces"
1369 {"import", jt_import, 0, "import {--add | --del | --show | "
1370 "--help} FILE.yaml"},
1371 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1372 {"stats", jt_stats, 0, "stats {show | help}"},
1373 {"global", jt_global, 0, "global {show | help}"},
1374 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1375 {"help", Parser_help, 0, "help"},
1376 {"exit", Parser_quit, 0, "quit"},
1377 {"quit", Parser_quit, 0, "quit"},
1378 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
1382 static int lnetctl_list_commands(int argc, char **argv)
1384 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1386 Parser_list_commands(list, buffer, sizeof(buffer), NULL, 0, 4);
1391 int main(int argc, char **argv)
1394 struct cYAML *err_rc = NULL;
1396 rc = lustre_lnet_config_lib_init();
1398 cYAML_build_error(-1, -1, "lnetctl", "startup",
1399 "cannot register LNet device", &err_rc);
1400 cYAML_print_tree2file(stderr, err_rc);
1404 Parser_init("lnetctl > ", list);
1406 rc = Parser_execarg(argc - 1, &argv[1], list);