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_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);
63 static int jt_import(int argc, char **argv);
64 static int jt_export(int argc, char **argv);
65 static int jt_ping(int argc, char **argv);
66 static int jt_discover(int argc, char **argv);
67 static int jt_lnet(int argc, char **argv);
68 static int jt_route(int argc, char **argv);
69 static int jt_net(int argc, char **argv);
70 static int jt_routing(int argc, char **argv);
71 static int jt_set(int argc, char **argv);
72 static int jt_stats(int argc, char **argv);
73 static int jt_global(int argc, char **argv);
74 static int jt_peers(int argc, char **argv);
77 command_t cmd_list[] = {
78 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
79 {"route", jt_route, 0, "route {add | del | show | help}"},
80 {"net", jt_net, 0, "net {add | del | show | help}"},
81 {"routing", jt_routing, 0, "routing {show | help}"},
82 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
83 " | routing | numa_range | max_interfaces"
85 {"import", jt_import, 0, "import FILE.yaml"},
86 {"export", jt_export, 0, "export FILE.yaml"},
87 {"stats", jt_stats, 0, "stats {show | help}"},
88 {"global", jt_global, 0, "global {show | help}"},
89 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
90 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
91 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
92 {"help", Parser_help, 0, "help"},
93 {"exit", Parser_quit, 0, "quit"},
94 {"quit", Parser_quit, 0, "quit"},
95 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
99 command_t lnet_cmds[] = {
100 {"configure", jt_config_lnet, 0, "configure lnet\n"
101 "\t--all: load NI configuration from module parameters\n"},
102 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
106 command_t route_cmds[] = {
107 {"add", jt_add_route, 0, "add a route\n"
108 "\t--net: net name (e.g. tcp0)\n"
109 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
110 "\t--hop: number to final destination (1 < hops < 255)\n"
111 "\t--priority: priority of route (0 - highest prio\n"},
112 {"del", jt_del_route, 0, "delete a route\n"
113 "\t--net: net name (e.g. tcp0)\n"
114 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
115 {"show", jt_show_route, 0, "show routes\n"
116 "\t--net: net name (e.g. tcp0) to filter on\n"
117 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
118 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
119 "\t--priority: priority of route (0 - highest prio to filter on\n"
120 "\t--verbose: display detailed output per route\n"},
124 command_t net_cmds[] = {
125 {"add", jt_add_ni, 0, "add a network\n"
126 "\t--net: net name (e.g. tcp0)\n"
127 "\t--if: physical interface (e.g. eth0)\n"
128 "\t--ip2net: specify networks based on IP address patterns\n"
129 "\t--peer-timeout: time to wait before declaring a peer dead\n"
130 "\t--peer-credits: define the max number of inflight messages\n"
131 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
132 "\t--credits: Network Interface credits\n"
133 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
134 {"del", jt_del_ni, 0, "delete a network\n"
135 "\t--net: net name (e.g. tcp0)\n"
136 "\t--if: physical interface (e.g. eth0)\n"},
137 {"show", jt_show_net, 0, "show networks\n"
138 "\t--net: net name (e.g. tcp0) to filter on\n"
139 "\t--verbose: display detailed output per network."
140 " Optional argument of '2' outputs more stats\n"},
144 command_t routing_cmds[] = {
145 {"show", jt_show_routing, 0, "show routing information\n"},
149 command_t stats_cmds[] = {
150 {"show", jt_show_stats, 0, "show LNET statistics\n"},
154 command_t global_cmds[] = {
155 {"show", jt_show_global, 0, "show global variables\n"},
159 command_t set_cmds[] = {
160 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
161 "\tVALUE must be greater than 0\n"},
162 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
163 "\tVALUE must be greater than 0\n"},
164 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
165 "\tVALUE must be greater than 0\n"},
166 {"routing", jt_set_routing, 0, "enable/disable routing\n"
167 "\t0 - disable routing\n"
168 "\t1 - enable routing\n"},
169 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
170 "\tVALUE must be at least 0\n"},
171 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
173 "\tValue must be greater than 16\n"},
174 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
175 "\t0 - disable peer discovery\n"
176 "\t1 - enable peer discovery (default)\n"},
180 command_t peer_cmds[] = {
181 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
182 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
183 "\t NID in the list becomes the Primary NID of a newly created\n"
185 "\t--nid: one or more peer NIDs\n"
186 "\t--non_mr: create this peer as not Multi-Rail capable\n"
187 "\t--ip2nets: specify a range of nids per peer"},
188 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
189 "\t--prim_nid: Primary NID of the peer.\n"
190 "\t--nid: list of NIDs to remove. If none provided,\n"
191 "\t peer is deleted\n"
192 "\t--ip2nets: specify a range of nids per peer"},
193 {"show", jt_show_peer, 0, "show peer information\n"
194 "\t--nid: NID of peer to filter on.\n"
195 "\t--verbose: display detailed output per peer."
196 " Optional argument of '2' outputs more stats\n"},
197 {"list", jt_list_peer, 0, "list all peers\n"},
201 static inline void print_help(const command_t cmds[], const char *cmd_type,
204 const command_t *cmd;
206 for (cmd = cmds; cmd->pc_name; cmd++) {
207 if (pc_name != NULL &&
208 strcmp(cmd->pc_name, pc_name) == 0) {
209 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
212 } else if (pc_name != NULL) {
215 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
219 static int parse_long(const char *number, long int *value)
226 *value = strtol(number, &end, 0);
227 if (end != NULL && *end != 0)
233 static int check_cmd(const command_t *cmd_list, const char *cmd,
234 const char *sub_cmd, const int min_args,
235 int argc, char **argv)
242 const char *const short_options = "h";
243 static const struct option long_options[] = {
244 { .name = "help", .has_arg = no_argument, .val = 'h' },
248 if (argc < min_args) {
249 print_help(cmd_list, cmd, sub_cmd);
252 } else if (argc > 2) {
256 while ((opt = getopt_long(argc, argv, short_options,
257 long_options, NULL)) != -1) {
260 print_help(cmd_list, cmd, sub_cmd);
275 static int jt_set_max_intf(int argc, char **argv)
279 struct cYAML *err_rc = NULL;
281 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
285 rc = parse_long(argv[1], &value);
287 cYAML_build_error(-1, -1, "parser", "set",
288 "cannot parse max_interfaces value", &err_rc);
289 cYAML_print_tree2file(stderr, err_rc);
290 cYAML_free_tree(err_rc);
294 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
295 if (rc != LUSTRE_CFG_RC_NO_ERR)
296 cYAML_print_tree2file(stderr, err_rc);
298 cYAML_free_tree(err_rc);
303 static int jt_set_numa(int argc, char **argv)
307 struct cYAML *err_rc = NULL;
309 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
313 rc = parse_long(argv[1], &value);
315 cYAML_build_error(-1, -1, "parser", "set",
316 "cannot parse numa_range value", &err_rc);
317 cYAML_print_tree2file(stderr, err_rc);
318 cYAML_free_tree(err_rc);
322 rc = lustre_lnet_config_numa_range(value, -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_discovery(int argc, char **argv)
335 struct cYAML *err_rc = NULL;
337 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
341 rc = parse_long(argv[1], &value);
343 cYAML_build_error(-1, -1, "parser", "set",
344 "cannot parse discovery value", &err_rc);
345 cYAML_print_tree2file(stderr, err_rc);
346 cYAML_free_tree(err_rc);
350 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
351 if (rc != LUSTRE_CFG_RC_NO_ERR)
352 cYAML_print_tree2file(stderr, err_rc);
354 cYAML_free_tree(err_rc);
359 static int jt_set_tiny(int argc, char **argv)
363 struct cYAML *err_rc = NULL;
365 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
369 rc = parse_long(argv[1], &value);
371 cYAML_build_error(-1, -1, "parser", "set",
372 "cannot parse tiny_buffers value", &err_rc);
373 cYAML_print_tree2file(stderr, err_rc);
374 cYAML_free_tree(err_rc);
378 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
379 if (rc != LUSTRE_CFG_RC_NO_ERR)
380 cYAML_print_tree2file(stderr, err_rc);
382 cYAML_free_tree(err_rc);
387 static int jt_set_small(int argc, char **argv)
391 struct cYAML *err_rc = NULL;
393 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
397 rc = parse_long(argv[1], &value);
399 cYAML_build_error(-1, -1, "parser", "set",
400 "cannot parse small_buffers value", &err_rc);
401 cYAML_print_tree2file(stderr, err_rc);
402 cYAML_free_tree(err_rc);
406 rc = lustre_lnet_config_buffers(-1, value, -1, -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_set_large(int argc, char **argv)
419 struct cYAML *err_rc = NULL;
421 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
425 rc = parse_long(argv[1], &value);
427 cYAML_build_error(-1, -1, "parser", "set",
428 "cannot parse large_buffers value", &err_rc);
429 cYAML_print_tree2file(stderr, err_rc);
430 cYAML_free_tree(err_rc);
434 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
435 if (rc != LUSTRE_CFG_RC_NO_ERR)
436 cYAML_print_tree2file(stderr, err_rc);
438 cYAML_free_tree(err_rc);
443 static int jt_set_routing(int argc, char **argv)
446 struct cYAML *err_rc = NULL;
449 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
453 rc = parse_long(argv[1], &value);
454 if (rc != 0 || (value != 0 && value != 1)) {
455 cYAML_build_error(-1, -1, "parser", "set",
456 "cannot parse routing value.\n"
457 "must be 0 for disable or 1 for enable",
459 cYAML_print_tree2file(stderr, err_rc);
460 cYAML_free_tree(err_rc);
464 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
466 if (rc != LUSTRE_CFG_RC_NO_ERR)
467 cYAML_print_tree2file(stderr, err_rc);
469 cYAML_free_tree(err_rc);
474 static int jt_config_lnet(int argc, char **argv)
476 struct cYAML *err_rc = NULL;
477 bool load_mod_params = false;
480 const char *const short_options = "a";
481 static const struct option long_options[] = {
482 { .name = "all", .has_arg = no_argument, .val = 'a' },
486 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
490 while ((opt = getopt_long(argc, argv, short_options,
491 long_options, NULL)) != -1) {
494 load_mod_params = true;
501 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
504 if (rc != LUSTRE_CFG_RC_NO_ERR)
505 cYAML_print_tree2file(stderr, err_rc);
507 cYAML_free_tree(err_rc);
512 static int jt_unconfig_lnet(int argc, char **argv)
514 struct cYAML *err_rc = NULL;
517 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
521 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
523 if (rc != LUSTRE_CFG_RC_NO_ERR)
524 cYAML_print_tree2file(stderr, err_rc);
526 cYAML_free_tree(err_rc);
530 static int jt_add_route(int argc, char **argv)
532 char *network = NULL, *gateway = NULL;
533 long int hop = -1, prio = -1;
534 struct cYAML *err_rc = NULL;
537 const char *const short_options = "n:g:c:p:";
538 static const struct option long_options[] = {
539 { .name = "net", .has_arg = required_argument, .val = 'n' },
540 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
541 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
542 { .name = "priority", .has_arg = required_argument, .val = 'p' },
545 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
549 while ((opt = getopt_long(argc, argv, short_options,
550 long_options, NULL)) != -1) {
559 rc = parse_long(optarg, &hop);
567 rc = parse_long(optarg, &prio);
579 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
581 if (rc != LUSTRE_CFG_RC_NO_ERR)
582 cYAML_print_tree2file(stderr, err_rc);
584 cYAML_free_tree(err_rc);
589 static int jt_add_ni(int argc, char **argv)
592 long int pto = -1, pc = -1, pbc = -1, cre = -1;
593 struct cYAML *err_rc = NULL;
594 int rc, opt, cpt_rc = -1;
595 struct lnet_dlc_network_descr nw_descr;
596 struct cfs_expr_list *global_cpts = NULL;
597 struct lnet_ioctl_config_lnd_tunables tunables;
600 memset(&tunables, 0, sizeof(tunables));
601 lustre_lnet_init_nw_descr(&nw_descr);
603 const char *const short_options = "n:i:p:t:c:b:r:s:";
604 static const struct option long_options[] = {
605 { .name = "net", .has_arg = required_argument, .val = 'n' },
606 { .name = "if", .has_arg = required_argument, .val = 'i' },
607 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
608 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
609 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
610 { .name = "peer-buffer-credits",
611 .has_arg = required_argument, .val = 'b' },
612 { .name = "credits", .has_arg = required_argument, .val = 'r' },
613 { .name = "cpt", .has_arg = required_argument, .val = 's' },
616 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
620 while ((opt = getopt_long(argc, argv, short_options,
621 long_options, NULL)) != -1) {
624 nw_descr.nw_id = libcfs_str2net(optarg);
627 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
629 cYAML_build_error(-1, -1, "ni", "add",
630 "bad interface list",
639 rc = parse_long(optarg, &pto);
647 rc = parse_long(optarg, &pc);
655 rc = parse_long(optarg, &pbc);
663 rc = parse_long(optarg, &cre);
671 cpt_rc = cfs_expr_list_parse(optarg,
673 UINT_MAX, &global_cpts);
680 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
681 tunables.lt_cmn.lct_peer_timeout = pto;
682 tunables.lt_cmn.lct_peer_tx_credits = pc;
683 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
684 tunables.lt_cmn.lct_max_tx_credits = cre;
688 rc = lustre_lnet_config_ni(&nw_descr,
689 (cpt_rc == 0) ? global_cpts: NULL,
690 ip2net, (found) ? &tunables : NULL,
693 if (global_cpts != NULL)
694 cfs_expr_list_free(global_cpts);
697 if (rc != LUSTRE_CFG_RC_NO_ERR)
698 cYAML_print_tree2file(stderr, err_rc);
700 cYAML_free_tree(err_rc);
705 static int jt_del_route(int argc, char **argv)
707 char *network = NULL, *gateway = NULL;
708 struct cYAML *err_rc = NULL;
711 const char *const short_options = "n:g:";
712 static const struct option long_options[] = {
713 { .name = "net", .has_arg = required_argument, .val = 'n' },
714 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
717 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
721 while ((opt = getopt_long(argc, argv, short_options,
722 long_options, NULL)) != -1) {
735 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
737 if (rc != LUSTRE_CFG_RC_NO_ERR)
738 cYAML_print_tree2file(stderr, err_rc);
740 cYAML_free_tree(err_rc);
745 static int jt_del_ni(int argc, char **argv)
747 struct cYAML *err_rc = NULL;
749 struct lnet_dlc_network_descr nw_descr;
751 lustre_lnet_init_nw_descr(&nw_descr);
753 const char *const short_options = "n:i:";
754 static const struct option long_options[] = {
755 { .name = "net", .has_arg = required_argument, .val = 'n' },
756 { .name = "if", .has_arg = required_argument, .val = 'i' },
759 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
763 while ((opt = getopt_long(argc, argv, short_options,
764 long_options, NULL)) != -1) {
767 nw_descr.nw_id = libcfs_str2net(optarg);
770 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
772 cYAML_build_error(-1, -1, "ni", "add",
773 "bad interface list",
783 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
786 if (rc != LUSTRE_CFG_RC_NO_ERR)
787 cYAML_print_tree2file(stderr, err_rc);
789 cYAML_free_tree(err_rc);
794 static int jt_show_route(int argc, char **argv)
796 char *network = NULL, *gateway = NULL;
797 long int hop = -1, prio = -1;
798 int detail = 0, rc, opt;
799 struct cYAML *err_rc = NULL, *show_rc = NULL;
801 const char *const short_options = "n:g:h:p:v";
802 static const struct option long_options[] = {
803 { .name = "net", .has_arg = required_argument, .val = 'n' },
804 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
805 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
806 { .name = "priority", .has_arg = required_argument, .val = 'p' },
807 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
810 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
814 while ((opt = getopt_long(argc, argv, short_options,
815 long_options, NULL)) != -1) {
824 rc = parse_long(optarg, &hop);
832 rc = parse_long(optarg, &prio);
847 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
848 &show_rc, &err_rc, false);
850 if (rc != LUSTRE_CFG_RC_NO_ERR)
851 cYAML_print_tree2file(stderr, err_rc);
853 cYAML_print_tree(show_rc);
855 cYAML_free_tree(err_rc);
856 cYAML_free_tree(show_rc);
861 static int jt_show_net(int argc, char **argv)
863 char *network = NULL;
865 struct cYAML *err_rc = NULL, *show_rc = NULL;
868 const char *const short_options = "n:v";
869 static const struct option long_options[] = {
870 { .name = "net", .has_arg = required_argument, .val = 'n' },
871 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
874 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
878 while ((opt = getopt_long(argc, argv, short_options,
879 long_options, NULL)) != -1) {
885 if ((!optarg) && (argv[optind] != NULL) &&
886 (argv[optind][0] != '-')) {
887 if (parse_long(argv[optind++], &detail) != 0)
898 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
901 if (rc != LUSTRE_CFG_RC_NO_ERR)
902 cYAML_print_tree2file(stderr, err_rc);
904 cYAML_print_tree(show_rc);
906 cYAML_free_tree(err_rc);
907 cYAML_free_tree(show_rc);
912 static int jt_show_routing(int argc, char **argv)
914 struct cYAML *err_rc = NULL, *show_rc = NULL;
917 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
921 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
923 if (rc != LUSTRE_CFG_RC_NO_ERR)
924 cYAML_print_tree2file(stderr, err_rc);
926 cYAML_print_tree(show_rc);
928 cYAML_free_tree(err_rc);
929 cYAML_free_tree(show_rc);
934 static int jt_show_stats(int argc, char **argv)
937 struct cYAML *show_rc = NULL, *err_rc = NULL;
939 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
943 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
945 if (rc != LUSTRE_CFG_RC_NO_ERR)
946 cYAML_print_tree2file(stderr, err_rc);
948 cYAML_print_tree(show_rc);
950 cYAML_free_tree(err_rc);
951 cYAML_free_tree(show_rc);
956 static int jt_show_global(int argc, char **argv)
959 struct cYAML *show_rc = NULL, *err_rc = NULL;
961 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
965 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
966 if (rc != LUSTRE_CFG_RC_NO_ERR) {
967 cYAML_print_tree2file(stderr, err_rc);
971 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
972 if (rc != LUSTRE_CFG_RC_NO_ERR) {
973 cYAML_print_tree2file(stderr, err_rc);
977 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
978 if (rc != LUSTRE_CFG_RC_NO_ERR) {
979 cYAML_print_tree2file(stderr, err_rc);
984 cYAML_print_tree(show_rc);
987 cYAML_free_tree(err_rc);
988 cYAML_free_tree(show_rc);
993 static int jt_lnet(int argc, char **argv)
997 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1001 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1004 static int jt_route(int argc, char **argv)
1008 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1012 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1015 static int jt_net(int argc, char **argv)
1019 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1023 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1026 static int jt_routing(int argc, char **argv)
1030 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1034 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1037 static int jt_stats(int argc, char **argv)
1041 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1045 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1048 static int jt_global(int argc, char **argv)
1052 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1056 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1059 static int jt_peers(int argc, char **argv)
1063 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1067 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1070 static int jt_set(int argc, char **argv)
1074 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1078 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1081 static int jt_import(int argc, char **argv)
1084 struct cYAML *err_rc = NULL;
1085 struct cYAML *show_rc = NULL;
1086 int rc = 0, return_rc = 0, opt, opt_found = 0;
1089 const char *const short_options = "adseh";
1090 static const struct option long_options[] = {
1091 { .name = "add", .has_arg = no_argument, .val = 'a' },
1092 { .name = "del", .has_arg = no_argument, .val = 'd' },
1093 { .name = "show", .has_arg = no_argument, .val = 's' },
1094 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1095 { .name = "help", .has_arg = no_argument, .val = 'h' },
1098 while ((opt = getopt_long(argc, argv, short_options,
1099 long_options, NULL)) != -1) {
1113 printf("import FILE\n"
1114 "import < FILE : import a file\n"
1115 "\t--add: add configuration\n"
1116 "\t--del: delete configuration\n"
1117 "\t--show: show configuration\n"
1118 "\t--exec: execute command\n"
1119 "\t--help: display this help\n"
1120 "If no command option is given then --add"
1121 " is assumed by default\n");
1128 /* grab the file name if one exists */
1129 if (opt_found && argc == 3)
1131 else if (!opt_found && argc == 2)
1136 rc = lustre_yaml_config(file, &err_rc);
1137 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1138 cYAML_print_tree(show_rc);
1139 cYAML_free_tree(show_rc);
1142 rc = lustre_yaml_del(file, &err_rc);
1145 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1146 cYAML_print_tree(show_rc);
1147 cYAML_free_tree(show_rc);
1150 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1151 cYAML_print_tree(show_rc);
1152 cYAML_free_tree(show_rc);
1156 if (rc || return_rc) {
1157 cYAML_print_tree2file(stderr, err_rc);
1158 cYAML_free_tree(err_rc);
1164 static int jt_export(int argc, char **argv)
1166 struct cYAML *show_rc = NULL;
1167 struct cYAML *err_rc = NULL;
1171 bool backup = false;
1174 const char *const short_options = "bh";
1175 static const struct option long_options[] = {
1176 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1177 { .name = "help", .has_arg = no_argument, .val = 'h' },
1180 while ((opt = getopt_long(argc, argv, short_options,
1181 long_options, NULL)) != -1) {
1188 printf("export > FILE.yaml : export configuration\n"
1189 "\t--backup: export only what's necessary for reconfig\n"
1190 "\t--help: display this help\n");
1195 if (backup && argc >= 3)
1197 else if (!backup && argc >= 2)
1203 f = fopen(file, "w");
1208 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1209 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1210 cYAML_print_tree2file(stderr, err_rc);
1211 cYAML_free_tree(err_rc);
1215 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1217 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1218 cYAML_print_tree2file(stderr, err_rc);
1219 cYAML_free_tree(err_rc);
1223 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1224 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1225 cYAML_print_tree2file(stderr, err_rc);
1226 cYAML_free_tree(err_rc);
1230 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1231 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1232 cYAML_print_tree2file(stderr, err_rc);
1233 cYAML_free_tree(err_rc);
1237 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1238 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1239 cYAML_print_tree2file(stderr, err_rc);
1240 cYAML_free_tree(err_rc);
1244 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1245 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1246 cYAML_print_tree2file(stderr, err_rc);
1247 cYAML_free_tree(err_rc);
1251 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1252 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1253 cYAML_print_tree2file(stderr, err_rc);
1254 cYAML_free_tree(err_rc);
1258 if (show_rc != NULL) {
1259 cYAML_print_tree2file(f, show_rc);
1260 cYAML_free_tree(show_rc);
1269 static int jt_add_peer_nid(int argc, char **argv)
1271 char *prim_nid = NULL;
1272 char **nids = NULL, **nids2 = NULL;
1274 struct cYAML *err_rc = NULL;
1275 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1276 bool non_mr = false;
1277 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1279 const char *const short_opts = "k:mn:";
1280 const struct option long_opts[] = {
1281 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1282 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1283 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1284 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1287 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1291 while ((opt = getopt_long(argc, argv, short_opts,
1292 long_opts, NULL)) != -1) {
1295 prim_nid_present = true;
1297 cYAML_build_error(-1, -1, "peer", "add",
1298 "ip2nets can not be specified"
1299 " along side prim_nid parameter.",
1313 if (ip2nets && (nid_list || prim_nid_present)) {
1314 cYAML_build_error(-1, -1, "peer", "add",
1315 "ip2nets can not be specified"
1316 " along side nid or prim_nid"
1317 " parameters", &err_rc);
1321 size = lustre_lnet_parse_nids(optarg, nids, size,
1326 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1336 for (; optind < argc; optind++) {
1337 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1344 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1345 !non_mr, ip2nets, -1, &err_rc);
1349 /* free the array of nids */
1350 for (i = 0; i < size; i++)
1355 if (rc != LUSTRE_CFG_RC_NO_ERR)
1356 cYAML_print_tree2file(stderr, err_rc);
1358 cYAML_free_tree(err_rc);
1363 static int jt_del_peer_nid(int argc, char **argv)
1365 char *prim_nid = NULL;
1366 char **nids = NULL, **nids2 = NULL;
1367 struct cYAML *err_rc = NULL;
1368 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1369 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1371 const char *const short_opts = "k:n:";
1372 const struct option long_opts[] = {
1373 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1374 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1375 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1378 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1382 while ((opt = getopt_long(argc, argv, short_opts,
1383 long_opts, NULL)) != -1) {
1386 prim_nid_present = true;
1388 cYAML_build_error(-1, -1, "peer", "add",
1389 "ip2nets can not be specified"
1390 " along side prim_nid parameter.",
1404 if (ip2nets && (nid_list || prim_nid_present)) {
1405 cYAML_build_error(-1, -1, "peer", "add",
1406 "ip2nets can not be specified"
1407 " along side nid or prim_nid"
1408 " parameters", &err_rc);
1411 size = lustre_lnet_parse_nids(optarg, nids, size,
1416 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1423 for (; optind < argc; optind++) {
1424 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1431 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1435 for (i = 0; i < size; i++)
1440 if (rc != LUSTRE_CFG_RC_NO_ERR)
1441 cYAML_print_tree2file(stderr, err_rc);
1443 cYAML_free_tree(err_rc);
1448 static int jt_show_peer(int argc, char **argv)
1452 struct cYAML *err_rc = NULL, *show_rc = NULL;
1453 long int detail = 0;
1455 const char *const short_opts = "hn:v::";
1456 const struct option long_opts[] = {
1457 { .name = "help", .has_arg = no_argument, .val = 'h' },
1458 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1459 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1462 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1466 while ((opt = getopt_long(argc, argv, short_opts,
1467 long_opts, NULL)) != -1) {
1473 if ((!optarg) && (argv[optind] != NULL) &&
1474 (argv[optind][0] != '-')) {
1475 if (parse_long(argv[optind++], &detail) != 0)
1486 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1489 if (rc != LUSTRE_CFG_RC_NO_ERR)
1490 cYAML_print_tree2file(stderr, err_rc);
1492 cYAML_print_tree(show_rc);
1494 cYAML_free_tree(err_rc);
1495 cYAML_free_tree(show_rc);
1500 static int jt_list_peer(int argc, char **argv)
1503 struct cYAML *err_rc = NULL, *list_rc = NULL;
1505 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1509 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1511 if (rc != LUSTRE_CFG_RC_NO_ERR)
1512 cYAML_print_tree2file(stderr, err_rc);
1514 cYAML_print_tree(list_rc);
1516 cYAML_free_tree(err_rc);
1517 cYAML_free_tree(list_rc);
1522 static int jt_ping(int argc, char **argv)
1524 struct cYAML *err_rc = NULL;
1525 struct cYAML *show_rc = NULL;
1529 const char *const short_options = "ht:";
1530 const struct option long_options[] = {
1531 { .name = "help", .has_arg = no_argument, .val = 'h' },
1532 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1535 while ((opt = getopt_long(argc, argv, short_options,
1536 long_options, NULL)) != -1) {
1539 timeout = 1000 * atol(optarg);
1542 printf("ping nid[,nid,...]\n"
1543 "\t --timeout: ping timeout\n"
1544 "\t --help: display this help\n");
1551 for (; optind < argc; optind++)
1552 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1555 cYAML_print_tree(show_rc);
1558 cYAML_print_tree2file(stderr, err_rc);
1560 cYAML_free_tree(err_rc);
1561 cYAML_free_tree(show_rc);
1566 static int jt_discover(int argc, char **argv)
1568 struct cYAML *err_rc = NULL;
1569 struct cYAML *show_rc = NULL;
1573 const char *const short_options = "fh";
1574 const struct option long_options[] = {
1575 { .name = "force", .has_arg = no_argument, .val = 'f' },
1576 { .name = "help", .has_arg = no_argument, .val = 'h' },
1579 while ((opt = getopt_long(argc, argv, short_options,
1580 long_options, NULL)) != -1) {
1586 printf("discover nid[,nid,...]\n"
1587 "\t --force: force discovery\n"
1588 "\t --help: display this help\n");
1595 for (; optind < argc; optind++)
1596 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1600 cYAML_print_tree(show_rc);
1603 cYAML_print_tree2file(stderr, err_rc);
1605 cYAML_free_tree(err_rc);
1606 cYAML_free_tree(show_rc);
1611 static int lnetctl_list_commands(int argc, char **argv)
1613 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1615 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1620 int main(int argc, char **argv)
1623 struct cYAML *err_rc = NULL;
1625 rc = lustre_lnet_config_lib_init();
1627 cYAML_build_error(-1, -1, "lnetctl", "startup",
1628 "cannot register LNet device", &err_rc);
1629 cYAML_print_tree2file(stderr, err_rc);
1633 Parser_init("lnetctl > ", cmd_list);
1635 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);