4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_global(int argc, char **argv);
52 static int jt_set_tiny(int argc, char **argv);
53 static int jt_set_small(int argc, char **argv);
54 static int jt_set_large(int argc, char **argv);
55 static int jt_set_numa(int argc, char **argv);
56 static int jt_set_retry_count(int argc, char **argv);
57 static int jt_set_transaction_to(int argc, char **argv);
58 static int jt_add_peer_nid(int argc, char **argv);
59 static int jt_del_peer_nid(int argc, char **argv);
60 static int jt_set_max_intf(int argc, char **argv);
61 static int jt_set_discovery(int argc, char **argv);
62 static int jt_list_peer(int argc, char **argv);
63 /*static int jt_show_peer(int argc, char **argv);*/
64 static int lnetctl_list_commands(int argc, char **argv);
65 static int jt_import(int argc, char **argv);
66 static int jt_export(int argc, char **argv);
67 static int jt_ping(int argc, char **argv);
68 static int jt_discover(int argc, char **argv);
69 static int jt_lnet(int argc, char **argv);
70 static int jt_route(int argc, char **argv);
71 static int jt_net(int argc, char **argv);
72 static int jt_routing(int argc, char **argv);
73 static int jt_set(int argc, char **argv);
74 static int jt_stats(int argc, char **argv);
75 static int jt_global(int argc, char **argv);
76 static int jt_peers(int argc, char **argv);
79 command_t cmd_list[] = {
80 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
81 {"route", jt_route, 0, "route {add | del | show | help}"},
82 {"net", jt_net, 0, "net {add | del | show | help}"},
83 {"routing", jt_routing, 0, "routing {show | help}"},
84 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
85 " | routing | numa_range | max_interfaces"
87 {"import", jt_import, 0, "import FILE.yaml"},
88 {"export", jt_export, 0, "export FILE.yaml"},
89 {"stats", jt_stats, 0, "stats {show | help}"},
90 {"global", jt_global, 0, "global {show | help}"},
91 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
92 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
93 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
94 {"help", Parser_help, 0, "help"},
95 {"exit", Parser_quit, 0, "quit"},
96 {"quit", Parser_quit, 0, "quit"},
97 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
101 command_t lnet_cmds[] = {
102 {"configure", jt_config_lnet, 0, "configure lnet\n"
103 "\t--all: load NI configuration from module parameters\n"},
104 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
108 command_t route_cmds[] = {
109 {"add", jt_add_route, 0, "add a route\n"
110 "\t--net: net name (e.g. tcp0)\n"
111 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
112 "\t--hop: number to final destination (1 < hops < 255)\n"
113 "\t--priority: priority of route (0 - highest prio\n"},
114 {"del", jt_del_route, 0, "delete a route\n"
115 "\t--net: net name (e.g. tcp0)\n"
116 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
117 {"show", jt_show_route, 0, "show routes\n"
118 "\t--net: net name (e.g. tcp0) to filter on\n"
119 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
120 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
121 "\t--priority: priority of route (0 - highest prio to filter on\n"
122 "\t--verbose: display detailed output per route\n"},
126 command_t net_cmds[] = {
127 {"add", jt_add_ni, 0, "add a network\n"
128 "\t--net: net name (e.g. tcp0)\n"
129 "\t--if: physical interface (e.g. eth0)\n"
130 "\t--ip2net: specify networks based on IP address patterns\n"
131 "\t--peer-timeout: time to wait before declaring a peer dead\n"
132 "\t--peer-credits: define the max number of inflight messages\n"
133 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
134 "\t--credits: Network Interface credits\n"
135 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
136 {"del", jt_del_ni, 0, "delete a network\n"
137 "\t--net: net name (e.g. tcp0)\n"
138 "\t--if: physical interface (e.g. eth0)\n"},
139 {"show", jt_show_net, 0, "show networks\n"
140 "\t--net: net name (e.g. tcp0) to filter on\n"
141 "\t--verbose: display detailed output per network."
142 " Optional argument of '2' outputs more stats\n"},
146 command_t routing_cmds[] = {
147 {"show", jt_show_routing, 0, "show routing information\n"},
151 command_t stats_cmds[] = {
152 {"show", jt_show_stats, 0, "show LNET statistics\n"},
156 command_t global_cmds[] = {
157 {"show", jt_show_global, 0, "show global variables\n"},
161 command_t set_cmds[] = {
162 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
163 "\tVALUE must be greater than 0\n"},
164 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
165 "\tVALUE must be greater than 0\n"},
166 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
167 "\tVALUE must be greater than 0\n"},
168 {"routing", jt_set_routing, 0, "enable/disable routing\n"
169 "\t0 - disable routing\n"
170 "\t1 - enable routing\n"},
171 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
172 "\tVALUE must be at least 0\n"},
173 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
175 "\tValue must be greater than 16\n"},
176 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
177 "\t0 - disable peer discovery\n"
178 "\t1 - enable peer discovery (default)\n"},
179 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
180 "\t0 - turn of retries\n"
181 "\t>0 - number of retries\n"},
182 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
183 "\t>0 - timeout in seconds\n"},
187 command_t peer_cmds[] = {
188 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
189 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
190 "\t NID in the list becomes the Primary NID of a newly created\n"
192 "\t--nid: one or more peer NIDs\n"
193 "\t--non_mr: create this peer as not Multi-Rail capable\n"
194 "\t--ip2nets: specify a range of nids per peer"},
195 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
196 "\t--prim_nid: Primary NID of the peer.\n"
197 "\t--nid: list of NIDs to remove. If none provided,\n"
198 "\t peer is deleted\n"
199 "\t--ip2nets: specify a range of nids per peer"},
200 {"show", jt_show_peer, 0, "show peer information\n"
201 "\t--nid: NID of peer to filter on.\n"
202 "\t--verbose: display detailed output per peer."
203 " Optional argument of '2' outputs more stats\n"},
204 {"list", jt_list_peer, 0, "list all peers\n"},
208 static inline void print_help(const command_t cmds[], const char *cmd_type,
211 const command_t *cmd;
213 for (cmd = cmds; cmd->pc_name; cmd++) {
214 if (pc_name != NULL &&
215 strcmp(cmd->pc_name, pc_name) == 0) {
216 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
219 } else if (pc_name != NULL) {
222 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
226 static int parse_long(const char *number, long int *value)
233 *value = strtol(number, &end, 0);
234 if (end != NULL && *end != 0)
240 static int check_cmd(const command_t *cmd_list, const char *cmd,
241 const char *sub_cmd, const int min_args,
242 int argc, char **argv)
249 const char *const short_options = "h";
250 static const struct option long_options[] = {
251 { .name = "help", .has_arg = no_argument, .val = 'h' },
255 if (argc < min_args) {
256 print_help(cmd_list, cmd, sub_cmd);
259 } else if (argc > 2) {
263 while ((opt = getopt_long(argc, argv, short_options,
264 long_options, NULL)) != -1) {
267 print_help(cmd_list, cmd, sub_cmd);
282 static int jt_set_max_intf(int argc, char **argv)
286 struct cYAML *err_rc = NULL;
288 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
292 rc = parse_long(argv[1], &value);
294 cYAML_build_error(-1, -1, "parser", "set",
295 "cannot parse max_interfaces value", &err_rc);
296 cYAML_print_tree2file(stderr, err_rc);
297 cYAML_free_tree(err_rc);
301 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
302 if (rc != LUSTRE_CFG_RC_NO_ERR)
303 cYAML_print_tree2file(stderr, err_rc);
305 cYAML_free_tree(err_rc);
310 static int jt_set_numa(int argc, char **argv)
314 struct cYAML *err_rc = NULL;
316 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
320 rc = parse_long(argv[1], &value);
322 cYAML_build_error(-1, -1, "parser", "set",
323 "cannot parse numa_range value", &err_rc);
324 cYAML_print_tree2file(stderr, err_rc);
325 cYAML_free_tree(err_rc);
329 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
330 if (rc != LUSTRE_CFG_RC_NO_ERR)
331 cYAML_print_tree2file(stderr, err_rc);
333 cYAML_free_tree(err_rc);
338 static int jt_set_transaction_to(int argc, char **argv)
342 struct cYAML *err_rc = NULL;
344 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
348 rc = parse_long(argv[1], &value);
350 cYAML_build_error(-1, -1, "parser", "set",
351 "cannot parse transaction timeout value", &err_rc);
352 cYAML_print_tree2file(stderr, err_rc);
353 cYAML_free_tree(err_rc);
357 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
358 if (rc != LUSTRE_CFG_RC_NO_ERR)
359 cYAML_print_tree2file(stderr, err_rc);
361 cYAML_free_tree(err_rc);
366 static int jt_set_retry_count(int argc, char **argv)
370 struct cYAML *err_rc = NULL;
372 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
376 rc = parse_long(argv[1], &value);
378 cYAML_build_error(-1, -1, "parser", "set",
379 "cannot parse retry_count value", &err_rc);
380 cYAML_print_tree2file(stderr, err_rc);
381 cYAML_free_tree(err_rc);
385 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
386 if (rc != LUSTRE_CFG_RC_NO_ERR)
387 cYAML_print_tree2file(stderr, err_rc);
389 cYAML_free_tree(err_rc);
394 static int jt_set_discovery(int argc, char **argv)
398 struct cYAML *err_rc = NULL;
400 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
404 rc = parse_long(argv[1], &value);
406 cYAML_build_error(-1, -1, "parser", "set",
407 "cannot parse discovery value", &err_rc);
408 cYAML_print_tree2file(stderr, err_rc);
409 cYAML_free_tree(err_rc);
413 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
414 if (rc != LUSTRE_CFG_RC_NO_ERR)
415 cYAML_print_tree2file(stderr, err_rc);
417 cYAML_free_tree(err_rc);
422 static int jt_set_tiny(int argc, char **argv)
426 struct cYAML *err_rc = NULL;
428 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
432 rc = parse_long(argv[1], &value);
434 cYAML_build_error(-1, -1, "parser", "set",
435 "cannot parse tiny_buffers value", &err_rc);
436 cYAML_print_tree2file(stderr, err_rc);
437 cYAML_free_tree(err_rc);
441 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
442 if (rc != LUSTRE_CFG_RC_NO_ERR)
443 cYAML_print_tree2file(stderr, err_rc);
445 cYAML_free_tree(err_rc);
450 static int jt_set_small(int argc, char **argv)
454 struct cYAML *err_rc = NULL;
456 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
460 rc = parse_long(argv[1], &value);
462 cYAML_build_error(-1, -1, "parser", "set",
463 "cannot parse small_buffers value", &err_rc);
464 cYAML_print_tree2file(stderr, err_rc);
465 cYAML_free_tree(err_rc);
469 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
470 if (rc != LUSTRE_CFG_RC_NO_ERR)
471 cYAML_print_tree2file(stderr, err_rc);
473 cYAML_free_tree(err_rc);
478 static int jt_set_large(int argc, char **argv)
482 struct cYAML *err_rc = NULL;
484 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
488 rc = parse_long(argv[1], &value);
490 cYAML_build_error(-1, -1, "parser", "set",
491 "cannot parse large_buffers value", &err_rc);
492 cYAML_print_tree2file(stderr, err_rc);
493 cYAML_free_tree(err_rc);
497 rc = lustre_lnet_config_buffers(-1, -1, 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_set_routing(int argc, char **argv)
509 struct cYAML *err_rc = NULL;
512 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
516 rc = parse_long(argv[1], &value);
517 if (rc != 0 || (value != 0 && value != 1)) {
518 cYAML_build_error(-1, -1, "parser", "set",
519 "cannot parse routing value.\n"
520 "must be 0 for disable or 1 for enable",
522 cYAML_print_tree2file(stderr, err_rc);
523 cYAML_free_tree(err_rc);
527 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
529 if (rc != LUSTRE_CFG_RC_NO_ERR)
530 cYAML_print_tree2file(stderr, err_rc);
532 cYAML_free_tree(err_rc);
537 static int jt_config_lnet(int argc, char **argv)
539 struct cYAML *err_rc = NULL;
540 bool load_mod_params = false;
543 const char *const short_options = "a";
544 static const struct option long_options[] = {
545 { .name = "all", .has_arg = no_argument, .val = 'a' },
549 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
553 while ((opt = getopt_long(argc, argv, short_options,
554 long_options, NULL)) != -1) {
557 load_mod_params = true;
564 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
567 if (rc != LUSTRE_CFG_RC_NO_ERR)
568 cYAML_print_tree2file(stderr, err_rc);
570 cYAML_free_tree(err_rc);
575 static int jt_unconfig_lnet(int argc, char **argv)
577 struct cYAML *err_rc = NULL;
580 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
584 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
586 if (rc != LUSTRE_CFG_RC_NO_ERR)
587 cYAML_print_tree2file(stderr, err_rc);
589 cYAML_free_tree(err_rc);
593 static int jt_add_route(int argc, char **argv)
595 char *network = NULL, *gateway = NULL;
596 long int hop = -1, prio = -1;
597 struct cYAML *err_rc = NULL;
600 const char *const short_options = "n:g:c:p:";
601 static const struct option long_options[] = {
602 { .name = "net", .has_arg = required_argument, .val = 'n' },
603 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
604 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
605 { .name = "priority", .has_arg = required_argument, .val = 'p' },
608 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
612 while ((opt = getopt_long(argc, argv, short_options,
613 long_options, NULL)) != -1) {
622 rc = parse_long(optarg, &hop);
630 rc = parse_long(optarg, &prio);
642 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
644 if (rc != LUSTRE_CFG_RC_NO_ERR)
645 cYAML_print_tree2file(stderr, err_rc);
647 cYAML_free_tree(err_rc);
652 static int jt_add_ni(int argc, char **argv)
655 long int pto = -1, pc = -1, pbc = -1, cre = -1;
656 struct cYAML *err_rc = NULL;
657 int rc, opt, cpt_rc = -1;
658 struct lnet_dlc_network_descr nw_descr;
659 struct cfs_expr_list *global_cpts = NULL;
660 struct lnet_ioctl_config_lnd_tunables tunables;
663 memset(&tunables, 0, sizeof(tunables));
664 lustre_lnet_init_nw_descr(&nw_descr);
666 const char *const short_options = "n:i:p:t:c:b:r:s:";
667 static const struct option long_options[] = {
668 { .name = "net", .has_arg = required_argument, .val = 'n' },
669 { .name = "if", .has_arg = required_argument, .val = 'i' },
670 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
671 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
672 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
673 { .name = "peer-buffer-credits",
674 .has_arg = required_argument, .val = 'b' },
675 { .name = "credits", .has_arg = required_argument, .val = 'r' },
676 { .name = "cpt", .has_arg = required_argument, .val = 's' },
679 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
683 while ((opt = getopt_long(argc, argv, short_options,
684 long_options, NULL)) != -1) {
687 nw_descr.nw_id = libcfs_str2net(optarg);
690 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
692 cYAML_build_error(-1, -1, "ni", "add",
693 "bad interface list",
702 rc = parse_long(optarg, &pto);
710 rc = parse_long(optarg, &pc);
718 rc = parse_long(optarg, &pbc);
726 rc = parse_long(optarg, &cre);
734 cpt_rc = cfs_expr_list_parse(optarg,
736 UINT_MAX, &global_cpts);
743 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
744 tunables.lt_cmn.lct_peer_timeout = pto;
745 tunables.lt_cmn.lct_peer_tx_credits = pc;
746 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
747 tunables.lt_cmn.lct_max_tx_credits = cre;
751 rc = lustre_lnet_config_ni(&nw_descr,
752 (cpt_rc == 0) ? global_cpts: NULL,
753 ip2net, (found) ? &tunables : NULL,
756 if (global_cpts != NULL)
757 cfs_expr_list_free(global_cpts);
760 if (rc != LUSTRE_CFG_RC_NO_ERR)
761 cYAML_print_tree2file(stderr, err_rc);
763 cYAML_free_tree(err_rc);
768 static int jt_del_route(int argc, char **argv)
770 char *network = NULL, *gateway = NULL;
771 struct cYAML *err_rc = NULL;
774 const char *const short_options = "n:g:";
775 static const struct option long_options[] = {
776 { .name = "net", .has_arg = required_argument, .val = 'n' },
777 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
780 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
784 while ((opt = getopt_long(argc, argv, short_options,
785 long_options, NULL)) != -1) {
798 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
800 if (rc != LUSTRE_CFG_RC_NO_ERR)
801 cYAML_print_tree2file(stderr, err_rc);
803 cYAML_free_tree(err_rc);
808 static int jt_del_ni(int argc, char **argv)
810 struct cYAML *err_rc = NULL;
812 struct lnet_dlc_network_descr nw_descr;
814 lustre_lnet_init_nw_descr(&nw_descr);
816 const char *const short_options = "n:i:";
817 static const struct option long_options[] = {
818 { .name = "net", .has_arg = required_argument, .val = 'n' },
819 { .name = "if", .has_arg = required_argument, .val = 'i' },
822 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
826 while ((opt = getopt_long(argc, argv, short_options,
827 long_options, NULL)) != -1) {
830 nw_descr.nw_id = libcfs_str2net(optarg);
833 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
835 cYAML_build_error(-1, -1, "ni", "add",
836 "bad interface list",
846 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
849 if (rc != LUSTRE_CFG_RC_NO_ERR)
850 cYAML_print_tree2file(stderr, err_rc);
852 cYAML_free_tree(err_rc);
857 static int jt_show_route(int argc, char **argv)
859 char *network = NULL, *gateway = NULL;
860 long int hop = -1, prio = -1;
861 int detail = 0, rc, opt;
862 struct cYAML *err_rc = NULL, *show_rc = NULL;
864 const char *const short_options = "n:g:h:p:v";
865 static const struct option long_options[] = {
866 { .name = "net", .has_arg = required_argument, .val = 'n' },
867 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
868 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
869 { .name = "priority", .has_arg = required_argument, .val = 'p' },
870 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
873 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
877 while ((opt = getopt_long(argc, argv, short_options,
878 long_options, NULL)) != -1) {
887 rc = parse_long(optarg, &hop);
895 rc = parse_long(optarg, &prio);
910 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
911 &show_rc, &err_rc, false);
913 if (rc != LUSTRE_CFG_RC_NO_ERR)
914 cYAML_print_tree2file(stderr, err_rc);
916 cYAML_print_tree(show_rc);
918 cYAML_free_tree(err_rc);
919 cYAML_free_tree(show_rc);
924 static int jt_show_net(int argc, char **argv)
926 char *network = NULL;
928 struct cYAML *err_rc = NULL, *show_rc = NULL;
931 const char *const short_options = "n:v";
932 static const struct option long_options[] = {
933 { .name = "net", .has_arg = required_argument, .val = 'n' },
934 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
937 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
941 while ((opt = getopt_long(argc, argv, short_options,
942 long_options, NULL)) != -1) {
948 if ((!optarg) && (argv[optind] != NULL) &&
949 (argv[optind][0] != '-')) {
950 if (parse_long(argv[optind++], &detail) != 0)
961 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
964 if (rc != LUSTRE_CFG_RC_NO_ERR)
965 cYAML_print_tree2file(stderr, err_rc);
967 cYAML_print_tree(show_rc);
969 cYAML_free_tree(err_rc);
970 cYAML_free_tree(show_rc);
975 static int jt_show_routing(int argc, char **argv)
977 struct cYAML *err_rc = NULL, *show_rc = NULL;
980 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
984 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
986 if (rc != LUSTRE_CFG_RC_NO_ERR)
987 cYAML_print_tree2file(stderr, err_rc);
989 cYAML_print_tree(show_rc);
991 cYAML_free_tree(err_rc);
992 cYAML_free_tree(show_rc);
997 static int jt_show_stats(int argc, char **argv)
1000 struct cYAML *show_rc = NULL, *err_rc = NULL;
1002 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1006 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1008 if (rc != LUSTRE_CFG_RC_NO_ERR)
1009 cYAML_print_tree2file(stderr, err_rc);
1011 cYAML_print_tree(show_rc);
1013 cYAML_free_tree(err_rc);
1014 cYAML_free_tree(show_rc);
1019 static int jt_show_global(int argc, char **argv)
1022 struct cYAML *show_rc = NULL, *err_rc = NULL;
1024 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1028 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1029 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1030 cYAML_print_tree2file(stderr, err_rc);
1034 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1035 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1036 cYAML_print_tree2file(stderr, err_rc);
1040 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1041 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1042 cYAML_print_tree2file(stderr, err_rc);
1046 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1047 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1048 cYAML_print_tree2file(stderr, err_rc);
1052 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1053 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1054 cYAML_print_tree2file(stderr, err_rc);
1059 cYAML_print_tree(show_rc);
1062 cYAML_free_tree(err_rc);
1063 cYAML_free_tree(show_rc);
1068 static int jt_lnet(int argc, char **argv)
1072 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1076 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1079 static int jt_route(int argc, char **argv)
1083 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1087 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1090 static int jt_net(int argc, char **argv)
1094 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1098 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1101 static int jt_routing(int argc, char **argv)
1105 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1109 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1112 static int jt_stats(int argc, char **argv)
1116 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1120 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1123 static int jt_global(int argc, char **argv)
1127 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1131 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1134 static int jt_peers(int argc, char **argv)
1138 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1142 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1145 static int jt_set(int argc, char **argv)
1149 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1153 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1156 static int jt_import(int argc, char **argv)
1159 struct cYAML *err_rc = NULL;
1160 struct cYAML *show_rc = NULL;
1161 int rc = 0, return_rc = 0, opt, opt_found = 0;
1164 const char *const short_options = "adseh";
1165 static const struct option long_options[] = {
1166 { .name = "add", .has_arg = no_argument, .val = 'a' },
1167 { .name = "del", .has_arg = no_argument, .val = 'd' },
1168 { .name = "show", .has_arg = no_argument, .val = 's' },
1169 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1170 { .name = "help", .has_arg = no_argument, .val = 'h' },
1173 while ((opt = getopt_long(argc, argv, short_options,
1174 long_options, NULL)) != -1) {
1188 printf("import FILE\n"
1189 "import < FILE : import a file\n"
1190 "\t--add: add configuration\n"
1191 "\t--del: delete configuration\n"
1192 "\t--show: show configuration\n"
1193 "\t--exec: execute command\n"
1194 "\t--help: display this help\n"
1195 "If no command option is given then --add"
1196 " is assumed by default\n");
1203 /* grab the file name if one exists */
1204 if (opt_found && argc == 3)
1206 else if (!opt_found && argc == 2)
1211 rc = lustre_yaml_config(file, &err_rc);
1212 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1213 cYAML_print_tree(show_rc);
1214 cYAML_free_tree(show_rc);
1217 rc = lustre_yaml_del(file, &err_rc);
1220 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1221 cYAML_print_tree(show_rc);
1222 cYAML_free_tree(show_rc);
1225 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1226 cYAML_print_tree(show_rc);
1227 cYAML_free_tree(show_rc);
1231 if (rc || return_rc) {
1232 cYAML_print_tree2file(stderr, err_rc);
1233 cYAML_free_tree(err_rc);
1239 static int jt_export(int argc, char **argv)
1241 struct cYAML *show_rc = NULL;
1242 struct cYAML *err_rc = NULL;
1246 bool backup = false;
1249 const char *const short_options = "bh";
1250 static const struct option long_options[] = {
1251 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1252 { .name = "help", .has_arg = no_argument, .val = 'h' },
1255 while ((opt = getopt_long(argc, argv, short_options,
1256 long_options, NULL)) != -1) {
1263 printf("export > FILE.yaml : export configuration\n"
1264 "\t--backup: export only what's necessary for reconfig\n"
1265 "\t--help: display this help\n");
1270 if (backup && argc >= 3)
1272 else if (!backup && argc >= 2)
1278 f = fopen(file, "w");
1283 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1284 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1285 cYAML_print_tree2file(stderr, err_rc);
1286 cYAML_free_tree(err_rc);
1290 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1292 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1293 cYAML_print_tree2file(stderr, err_rc);
1294 cYAML_free_tree(err_rc);
1298 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1299 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1300 cYAML_print_tree2file(stderr, err_rc);
1301 cYAML_free_tree(err_rc);
1305 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1306 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1307 cYAML_print_tree2file(stderr, err_rc);
1308 cYAML_free_tree(err_rc);
1312 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1313 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1314 cYAML_print_tree2file(stderr, err_rc);
1315 cYAML_free_tree(err_rc);
1319 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1320 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1321 cYAML_print_tree2file(stderr, err_rc);
1322 cYAML_free_tree(err_rc);
1326 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1327 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1328 cYAML_print_tree2file(stderr, err_rc);
1329 cYAML_free_tree(err_rc);
1333 if (show_rc != NULL) {
1334 cYAML_print_tree2file(f, show_rc);
1335 cYAML_free_tree(show_rc);
1344 static int jt_add_peer_nid(int argc, char **argv)
1346 char *prim_nid = NULL;
1347 char **nids = NULL, **nids2 = NULL;
1349 struct cYAML *err_rc = NULL;
1350 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1351 bool non_mr = false;
1352 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1354 const char *const short_opts = "k:mn:";
1355 const struct option long_opts[] = {
1356 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1357 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1358 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1359 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1362 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1366 while ((opt = getopt_long(argc, argv, short_opts,
1367 long_opts, NULL)) != -1) {
1370 prim_nid_present = true;
1372 cYAML_build_error(-1, -1, "peer", "add",
1373 "ip2nets can not be specified"
1374 " along side prim_nid parameter.",
1388 if (ip2nets && (nid_list || prim_nid_present)) {
1389 cYAML_build_error(-1, -1, "peer", "add",
1390 "ip2nets can not be specified"
1391 " along side nid or prim_nid"
1392 " parameters", &err_rc);
1396 size = lustre_lnet_parse_nids(optarg, nids, size,
1401 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1411 for (; optind < argc; optind++) {
1412 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1419 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1420 !non_mr, ip2nets, -1, &err_rc);
1424 /* free the array of nids */
1425 for (i = 0; i < size; i++)
1430 if (rc != LUSTRE_CFG_RC_NO_ERR)
1431 cYAML_print_tree2file(stderr, err_rc);
1433 cYAML_free_tree(err_rc);
1438 static int jt_del_peer_nid(int argc, char **argv)
1440 char *prim_nid = NULL;
1441 char **nids = NULL, **nids2 = NULL;
1442 struct cYAML *err_rc = NULL;
1443 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1444 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1446 const char *const short_opts = "k:n:";
1447 const struct option long_opts[] = {
1448 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1449 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1450 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1453 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1457 while ((opt = getopt_long(argc, argv, short_opts,
1458 long_opts, NULL)) != -1) {
1461 prim_nid_present = true;
1463 cYAML_build_error(-1, -1, "peer", "add",
1464 "ip2nets can not be specified"
1465 " along side prim_nid parameter.",
1479 if (ip2nets && (nid_list || prim_nid_present)) {
1480 cYAML_build_error(-1, -1, "peer", "add",
1481 "ip2nets can not be specified"
1482 " along side nid or prim_nid"
1483 " parameters", &err_rc);
1486 size = lustre_lnet_parse_nids(optarg, nids, size,
1491 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1498 for (; optind < argc; optind++) {
1499 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1506 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1510 for (i = 0; i < size; i++)
1515 if (rc != LUSTRE_CFG_RC_NO_ERR)
1516 cYAML_print_tree2file(stderr, err_rc);
1518 cYAML_free_tree(err_rc);
1523 static int jt_show_peer(int argc, char **argv)
1527 struct cYAML *err_rc = NULL, *show_rc = NULL;
1528 long int detail = 0;
1530 const char *const short_opts = "hn:v::";
1531 const struct option long_opts[] = {
1532 { .name = "help", .has_arg = no_argument, .val = 'h' },
1533 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1534 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1537 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1541 while ((opt = getopt_long(argc, argv, short_opts,
1542 long_opts, NULL)) != -1) {
1548 if ((!optarg) && (argv[optind] != NULL) &&
1549 (argv[optind][0] != '-')) {
1550 if (parse_long(argv[optind++], &detail) != 0)
1561 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1564 if (rc != LUSTRE_CFG_RC_NO_ERR)
1565 cYAML_print_tree2file(stderr, err_rc);
1567 cYAML_print_tree(show_rc);
1569 cYAML_free_tree(err_rc);
1570 cYAML_free_tree(show_rc);
1575 static int jt_list_peer(int argc, char **argv)
1578 struct cYAML *err_rc = NULL, *list_rc = NULL;
1580 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1584 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1586 if (rc != LUSTRE_CFG_RC_NO_ERR)
1587 cYAML_print_tree2file(stderr, err_rc);
1589 cYAML_print_tree(list_rc);
1591 cYAML_free_tree(err_rc);
1592 cYAML_free_tree(list_rc);
1597 static int jt_ping(int argc, char **argv)
1599 struct cYAML *err_rc = NULL;
1600 struct cYAML *show_rc = NULL;
1604 const char *const short_options = "ht:";
1605 const struct option long_options[] = {
1606 { .name = "help", .has_arg = no_argument, .val = 'h' },
1607 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1610 while ((opt = getopt_long(argc, argv, short_options,
1611 long_options, NULL)) != -1) {
1614 timeout = 1000 * atol(optarg);
1617 printf("ping nid[,nid,...]\n"
1618 "\t --timeout: ping timeout\n"
1619 "\t --help: display this help\n");
1626 for (; optind < argc; optind++)
1627 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1630 cYAML_print_tree(show_rc);
1633 cYAML_print_tree2file(stderr, err_rc);
1635 cYAML_free_tree(err_rc);
1636 cYAML_free_tree(show_rc);
1641 static int jt_discover(int argc, char **argv)
1643 struct cYAML *err_rc = NULL;
1644 struct cYAML *show_rc = NULL;
1648 const char *const short_options = "fh";
1649 const struct option long_options[] = {
1650 { .name = "force", .has_arg = no_argument, .val = 'f' },
1651 { .name = "help", .has_arg = no_argument, .val = 'h' },
1654 while ((opt = getopt_long(argc, argv, short_options,
1655 long_options, NULL)) != -1) {
1661 printf("discover nid[,nid,...]\n"
1662 "\t --force: force discovery\n"
1663 "\t --help: display this help\n");
1670 for (; optind < argc; optind++)
1671 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1675 cYAML_print_tree(show_rc);
1678 cYAML_print_tree2file(stderr, err_rc);
1680 cYAML_free_tree(err_rc);
1681 cYAML_free_tree(show_rc);
1686 static int lnetctl_list_commands(int argc, char **argv)
1688 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1690 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1695 int main(int argc, char **argv)
1698 struct cYAML *err_rc = NULL;
1700 rc = lustre_lnet_config_lib_init();
1702 cYAML_build_error(-1, -1, "lnetctl", "startup",
1703 "cannot register LNet device", &err_rc);
1704 cYAML_print_tree2file(stderr, err_rc);
1708 Parser_init("lnetctl > ", cmd_list);
1710 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);