4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_global(int argc, char **argv);
52 static int jt_set_tiny(int argc, char **argv);
53 static int jt_set_small(int argc, char **argv);
54 static int jt_set_large(int argc, char **argv);
55 static int jt_set_numa(int argc, char **argv);
56 static int jt_set_retry_count(int argc, char **argv);
57 static int jt_set_transaction_to(int argc, char **argv);
58 static int jt_set_hsensitivity(int argc, char **argv);
59 static int jt_add_peer_nid(int argc, char **argv);
60 static int jt_del_peer_nid(int argc, char **argv);
61 static int jt_set_max_intf(int argc, char **argv);
62 static int jt_set_discovery(int argc, char **argv);
63 static int jt_list_peer(int argc, char **argv);
64 /*static int jt_show_peer(int argc, char **argv);*/
65 static int lnetctl_list_commands(int argc, char **argv);
66 static int jt_import(int argc, char **argv);
67 static int jt_export(int argc, char **argv);
68 static int jt_ping(int argc, char **argv);
69 static int jt_discover(int argc, char **argv);
70 static int jt_lnet(int argc, char **argv);
71 static int jt_route(int argc, char **argv);
72 static int jt_net(int argc, char **argv);
73 static int jt_routing(int argc, char **argv);
74 static int jt_set(int argc, char **argv);
75 static int jt_stats(int argc, char **argv);
76 static int jt_global(int argc, char **argv);
77 static int jt_peers(int argc, char **argv);
80 command_t cmd_list[] = {
81 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
82 {"route", jt_route, 0, "route {add | del | show | help}"},
83 {"net", jt_net, 0, "net {add | del | show | help}"},
84 {"routing", jt_routing, 0, "routing {show | help}"},
85 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
86 " | routing | numa_range | max_interfaces"
88 {"import", jt_import, 0, "import FILE.yaml"},
89 {"export", jt_export, 0, "export FILE.yaml"},
90 {"stats", jt_stats, 0, "stats {show | help}"},
91 {"global", jt_global, 0, "global {show | help}"},
92 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
93 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
94 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
95 {"help", Parser_help, 0, "help"},
96 {"exit", Parser_quit, 0, "quit"},
97 {"quit", Parser_quit, 0, "quit"},
98 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
102 command_t lnet_cmds[] = {
103 {"configure", jt_config_lnet, 0, "configure lnet\n"
104 "\t--all: load NI configuration from module parameters\n"},
105 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
109 command_t route_cmds[] = {
110 {"add", jt_add_route, 0, "add a route\n"
111 "\t--net: net name (e.g. tcp0)\n"
112 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
113 "\t--hop: number to final destination (1 < hops < 255)\n"
114 "\t--priority: priority of route (0 - highest prio\n"},
115 {"del", jt_del_route, 0, "delete a route\n"
116 "\t--net: net name (e.g. tcp0)\n"
117 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
118 {"show", jt_show_route, 0, "show routes\n"
119 "\t--net: net name (e.g. tcp0) to filter on\n"
120 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
121 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
122 "\t--priority: priority of route (0 - highest prio to filter on\n"
123 "\t--verbose: display detailed output per route\n"},
127 command_t net_cmds[] = {
128 {"add", jt_add_ni, 0, "add a network\n"
129 "\t--net: net name (e.g. tcp0)\n"
130 "\t--if: physical interface (e.g. eth0)\n"
131 "\t--ip2net: specify networks based on IP address patterns\n"
132 "\t--peer-timeout: time to wait before declaring a peer dead\n"
133 "\t--peer-credits: define the max number of inflight messages\n"
134 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
135 "\t--credits: Network Interface credits\n"
136 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
137 {"del", jt_del_ni, 0, "delete a network\n"
138 "\t--net: net name (e.g. tcp0)\n"
139 "\t--if: physical interface (e.g. eth0)\n"},
140 {"show", jt_show_net, 0, "show networks\n"
141 "\t--net: net name (e.g. tcp0) to filter on\n"
142 "\t--verbose: display detailed output per network."
143 " Optional argument of '2' outputs more stats\n"},
147 command_t routing_cmds[] = {
148 {"show", jt_show_routing, 0, "show routing information\n"},
152 command_t stats_cmds[] = {
153 {"show", jt_show_stats, 0, "show LNET statistics\n"},
157 command_t global_cmds[] = {
158 {"show", jt_show_global, 0, "show global variables\n"},
162 command_t set_cmds[] = {
163 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
164 "\tVALUE must be greater than 0\n"},
165 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
166 "\tVALUE must be greater than 0\n"},
167 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
168 "\tVALUE must be greater than 0\n"},
169 {"routing", jt_set_routing, 0, "enable/disable routing\n"
170 "\t0 - disable routing\n"
171 "\t1 - enable routing\n"},
172 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
173 "\tVALUE must be at least 0\n"},
174 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
176 "\tValue must be greater than 16\n"},
177 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
178 "\t0 - disable peer discovery\n"
179 "\t1 - enable peer discovery (default)\n"},
180 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
181 "\t0 - turn of retries\n"
182 "\t>0 - number of retries\n"},
183 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
184 "\t>0 - timeout in seconds\n"},
185 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
186 "\t0 - turn off health evaluation\n"
187 "\t>0 - sensitivity value not more than 1000\n"},
191 command_t peer_cmds[] = {
192 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
193 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
194 "\t NID in the list becomes the Primary NID of a newly created\n"
196 "\t--nid: one or more peer NIDs\n"
197 "\t--non_mr: create this peer as not Multi-Rail capable\n"
198 "\t--ip2nets: specify a range of nids per peer"},
199 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
200 "\t--prim_nid: Primary NID of the peer.\n"
201 "\t--nid: list of NIDs to remove. If none provided,\n"
202 "\t peer is deleted\n"
203 "\t--ip2nets: specify a range of nids per peer"},
204 {"show", jt_show_peer, 0, "show peer information\n"
205 "\t--nid: NID of peer to filter on.\n"
206 "\t--verbose: display detailed output per peer."
207 " Optional argument of '2' outputs more stats\n"},
208 {"list", jt_list_peer, 0, "list all peers\n"},
212 static inline void print_help(const command_t cmds[], const char *cmd_type,
215 const command_t *cmd;
217 for (cmd = cmds; cmd->pc_name; cmd++) {
218 if (pc_name != NULL &&
219 strcmp(cmd->pc_name, pc_name) == 0) {
220 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
223 } else if (pc_name != NULL) {
226 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
230 static int parse_long(const char *number, long int *value)
237 *value = strtol(number, &end, 0);
238 if (end != NULL && *end != 0)
244 static int check_cmd(const command_t *cmd_list, const char *cmd,
245 const char *sub_cmd, const int min_args,
246 int argc, char **argv)
253 const char *const short_options = "h";
254 static const struct option long_options[] = {
255 { .name = "help", .has_arg = no_argument, .val = 'h' },
259 if (argc < min_args) {
260 print_help(cmd_list, cmd, sub_cmd);
263 } else if (argc > 2) {
267 while ((opt = getopt_long(argc, argv, short_options,
268 long_options, NULL)) != -1) {
271 print_help(cmd_list, cmd, sub_cmd);
286 static int jt_set_max_intf(int argc, char **argv)
290 struct cYAML *err_rc = NULL;
292 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
296 rc = parse_long(argv[1], &value);
298 cYAML_build_error(-1, -1, "parser", "set",
299 "cannot parse max_interfaces value", &err_rc);
300 cYAML_print_tree2file(stderr, err_rc);
301 cYAML_free_tree(err_rc);
305 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
306 if (rc != LUSTRE_CFG_RC_NO_ERR)
307 cYAML_print_tree2file(stderr, err_rc);
309 cYAML_free_tree(err_rc);
314 static int jt_set_numa(int argc, char **argv)
318 struct cYAML *err_rc = NULL;
320 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
324 rc = parse_long(argv[1], &value);
326 cYAML_build_error(-1, -1, "parser", "set",
327 "cannot parse numa_range value", &err_rc);
328 cYAML_print_tree2file(stderr, err_rc);
329 cYAML_free_tree(err_rc);
333 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
334 if (rc != LUSTRE_CFG_RC_NO_ERR)
335 cYAML_print_tree2file(stderr, err_rc);
337 cYAML_free_tree(err_rc);
342 static int jt_set_hsensitivity(int argc, char **argv)
346 struct cYAML *err_rc = NULL;
348 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
352 rc = parse_long(argv[1], &value);
354 cYAML_build_error(-1, -1, "parser", "set",
355 "cannot parse health sensitivity value", &err_rc);
356 cYAML_print_tree2file(stderr, err_rc);
357 cYAML_free_tree(err_rc);
361 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
362 if (rc != LUSTRE_CFG_RC_NO_ERR)
363 cYAML_print_tree2file(stderr, err_rc);
365 cYAML_free_tree(err_rc);
370 static int jt_set_transaction_to(int argc, char **argv)
374 struct cYAML *err_rc = NULL;
376 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
380 rc = parse_long(argv[1], &value);
382 cYAML_build_error(-1, -1, "parser", "set",
383 "cannot parse transaction timeout value", &err_rc);
384 cYAML_print_tree2file(stderr, err_rc);
385 cYAML_free_tree(err_rc);
389 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
390 if (rc != LUSTRE_CFG_RC_NO_ERR)
391 cYAML_print_tree2file(stderr, err_rc);
393 cYAML_free_tree(err_rc);
398 static int jt_set_retry_count(int argc, char **argv)
402 struct cYAML *err_rc = NULL;
404 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
408 rc = parse_long(argv[1], &value);
410 cYAML_build_error(-1, -1, "parser", "set",
411 "cannot parse retry_count value", &err_rc);
412 cYAML_print_tree2file(stderr, err_rc);
413 cYAML_free_tree(err_rc);
417 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
418 if (rc != LUSTRE_CFG_RC_NO_ERR)
419 cYAML_print_tree2file(stderr, err_rc);
421 cYAML_free_tree(err_rc);
426 static int jt_set_discovery(int argc, char **argv)
430 struct cYAML *err_rc = NULL;
432 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
436 rc = parse_long(argv[1], &value);
438 cYAML_build_error(-1, -1, "parser", "set",
439 "cannot parse discovery value", &err_rc);
440 cYAML_print_tree2file(stderr, err_rc);
441 cYAML_free_tree(err_rc);
445 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
446 if (rc != LUSTRE_CFG_RC_NO_ERR)
447 cYAML_print_tree2file(stderr, err_rc);
449 cYAML_free_tree(err_rc);
454 static int jt_set_tiny(int argc, char **argv)
458 struct cYAML *err_rc = NULL;
460 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
464 rc = parse_long(argv[1], &value);
466 cYAML_build_error(-1, -1, "parser", "set",
467 "cannot parse tiny_buffers value", &err_rc);
468 cYAML_print_tree2file(stderr, err_rc);
469 cYAML_free_tree(err_rc);
473 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
474 if (rc != LUSTRE_CFG_RC_NO_ERR)
475 cYAML_print_tree2file(stderr, err_rc);
477 cYAML_free_tree(err_rc);
482 static int jt_set_small(int argc, char **argv)
486 struct cYAML *err_rc = NULL;
488 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
492 rc = parse_long(argv[1], &value);
494 cYAML_build_error(-1, -1, "parser", "set",
495 "cannot parse small_buffers value", &err_rc);
496 cYAML_print_tree2file(stderr, err_rc);
497 cYAML_free_tree(err_rc);
501 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
502 if (rc != LUSTRE_CFG_RC_NO_ERR)
503 cYAML_print_tree2file(stderr, err_rc);
505 cYAML_free_tree(err_rc);
510 static int jt_set_large(int argc, char **argv)
514 struct cYAML *err_rc = NULL;
516 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
520 rc = parse_long(argv[1], &value);
522 cYAML_build_error(-1, -1, "parser", "set",
523 "cannot parse large_buffers value", &err_rc);
524 cYAML_print_tree2file(stderr, err_rc);
525 cYAML_free_tree(err_rc);
529 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
530 if (rc != LUSTRE_CFG_RC_NO_ERR)
531 cYAML_print_tree2file(stderr, err_rc);
533 cYAML_free_tree(err_rc);
538 static int jt_set_routing(int argc, char **argv)
541 struct cYAML *err_rc = NULL;
544 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
548 rc = parse_long(argv[1], &value);
549 if (rc != 0 || (value != 0 && value != 1)) {
550 cYAML_build_error(-1, -1, "parser", "set",
551 "cannot parse routing value.\n"
552 "must be 0 for disable or 1 for enable",
554 cYAML_print_tree2file(stderr, err_rc);
555 cYAML_free_tree(err_rc);
559 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
561 if (rc != LUSTRE_CFG_RC_NO_ERR)
562 cYAML_print_tree2file(stderr, err_rc);
564 cYAML_free_tree(err_rc);
569 static int jt_config_lnet(int argc, char **argv)
571 struct cYAML *err_rc = NULL;
572 bool load_mod_params = false;
575 const char *const short_options = "a";
576 static const struct option long_options[] = {
577 { .name = "all", .has_arg = no_argument, .val = 'a' },
581 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
585 while ((opt = getopt_long(argc, argv, short_options,
586 long_options, NULL)) != -1) {
589 load_mod_params = true;
596 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
599 if (rc != LUSTRE_CFG_RC_NO_ERR)
600 cYAML_print_tree2file(stderr, err_rc);
602 cYAML_free_tree(err_rc);
607 static int jt_unconfig_lnet(int argc, char **argv)
609 struct cYAML *err_rc = NULL;
612 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
616 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
618 if (rc != LUSTRE_CFG_RC_NO_ERR)
619 cYAML_print_tree2file(stderr, err_rc);
621 cYAML_free_tree(err_rc);
625 static int jt_add_route(int argc, char **argv)
627 char *network = NULL, *gateway = NULL;
628 long int hop = -1, prio = -1;
629 struct cYAML *err_rc = NULL;
632 const char *const short_options = "n:g:c:p:";
633 static const struct option long_options[] = {
634 { .name = "net", .has_arg = required_argument, .val = 'n' },
635 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
636 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
637 { .name = "priority", .has_arg = required_argument, .val = 'p' },
640 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
644 while ((opt = getopt_long(argc, argv, short_options,
645 long_options, NULL)) != -1) {
654 rc = parse_long(optarg, &hop);
662 rc = parse_long(optarg, &prio);
674 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
676 if (rc != LUSTRE_CFG_RC_NO_ERR)
677 cYAML_print_tree2file(stderr, err_rc);
679 cYAML_free_tree(err_rc);
684 static int jt_add_ni(int argc, char **argv)
687 long int pto = -1, pc = -1, pbc = -1, cre = -1;
688 struct cYAML *err_rc = NULL;
689 int rc, opt, cpt_rc = -1;
690 struct lnet_dlc_network_descr nw_descr;
691 struct cfs_expr_list *global_cpts = NULL;
692 struct lnet_ioctl_config_lnd_tunables tunables;
695 memset(&tunables, 0, sizeof(tunables));
696 lustre_lnet_init_nw_descr(&nw_descr);
698 const char *const short_options = "n:i:p:t:c:b:r:s:";
699 static const struct option long_options[] = {
700 { .name = "net", .has_arg = required_argument, .val = 'n' },
701 { .name = "if", .has_arg = required_argument, .val = 'i' },
702 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
703 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
704 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
705 { .name = "peer-buffer-credits",
706 .has_arg = required_argument, .val = 'b' },
707 { .name = "credits", .has_arg = required_argument, .val = 'r' },
708 { .name = "cpt", .has_arg = required_argument, .val = 's' },
711 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
715 while ((opt = getopt_long(argc, argv, short_options,
716 long_options, NULL)) != -1) {
719 nw_descr.nw_id = libcfs_str2net(optarg);
722 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
724 cYAML_build_error(-1, -1, "ni", "add",
725 "bad interface list",
734 rc = parse_long(optarg, &pto);
742 rc = parse_long(optarg, &pc);
750 rc = parse_long(optarg, &pbc);
758 rc = parse_long(optarg, &cre);
766 cpt_rc = cfs_expr_list_parse(optarg,
768 UINT_MAX, &global_cpts);
775 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
776 tunables.lt_cmn.lct_peer_timeout = pto;
777 tunables.lt_cmn.lct_peer_tx_credits = pc;
778 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
779 tunables.lt_cmn.lct_max_tx_credits = cre;
783 rc = lustre_lnet_config_ni(&nw_descr,
784 (cpt_rc == 0) ? global_cpts: NULL,
785 ip2net, (found) ? &tunables : NULL,
788 if (global_cpts != NULL)
789 cfs_expr_list_free(global_cpts);
792 if (rc != LUSTRE_CFG_RC_NO_ERR)
793 cYAML_print_tree2file(stderr, err_rc);
795 cYAML_free_tree(err_rc);
800 static int jt_del_route(int argc, char **argv)
802 char *network = NULL, *gateway = NULL;
803 struct cYAML *err_rc = NULL;
806 const char *const short_options = "n:g:";
807 static const struct option long_options[] = {
808 { .name = "net", .has_arg = required_argument, .val = 'n' },
809 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
812 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
816 while ((opt = getopt_long(argc, argv, short_options,
817 long_options, NULL)) != -1) {
830 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
832 if (rc != LUSTRE_CFG_RC_NO_ERR)
833 cYAML_print_tree2file(stderr, err_rc);
835 cYAML_free_tree(err_rc);
840 static int jt_del_ni(int argc, char **argv)
842 struct cYAML *err_rc = NULL;
844 struct lnet_dlc_network_descr nw_descr;
846 lustre_lnet_init_nw_descr(&nw_descr);
848 const char *const short_options = "n:i:";
849 static const struct option long_options[] = {
850 { .name = "net", .has_arg = required_argument, .val = 'n' },
851 { .name = "if", .has_arg = required_argument, .val = 'i' },
854 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
858 while ((opt = getopt_long(argc, argv, short_options,
859 long_options, NULL)) != -1) {
862 nw_descr.nw_id = libcfs_str2net(optarg);
865 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
867 cYAML_build_error(-1, -1, "ni", "add",
868 "bad interface list",
878 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
881 if (rc != LUSTRE_CFG_RC_NO_ERR)
882 cYAML_print_tree2file(stderr, err_rc);
884 cYAML_free_tree(err_rc);
889 static int jt_show_route(int argc, char **argv)
891 char *network = NULL, *gateway = NULL;
892 long int hop = -1, prio = -1;
893 int detail = 0, rc, opt;
894 struct cYAML *err_rc = NULL, *show_rc = NULL;
896 const char *const short_options = "n:g:h:p:v";
897 static const struct option long_options[] = {
898 { .name = "net", .has_arg = required_argument, .val = 'n' },
899 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
900 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
901 { .name = "priority", .has_arg = required_argument, .val = 'p' },
902 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
905 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
909 while ((opt = getopt_long(argc, argv, short_options,
910 long_options, NULL)) != -1) {
919 rc = parse_long(optarg, &hop);
927 rc = parse_long(optarg, &prio);
942 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
943 &show_rc, &err_rc, false);
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_net(int argc, char **argv)
958 char *network = NULL;
960 struct cYAML *err_rc = NULL, *show_rc = NULL;
963 const char *const short_options = "n:v";
964 static const struct option long_options[] = {
965 { .name = "net", .has_arg = required_argument, .val = 'n' },
966 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
969 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
973 while ((opt = getopt_long(argc, argv, short_options,
974 long_options, NULL)) != -1) {
980 if ((!optarg) && (argv[optind] != NULL) &&
981 (argv[optind][0] != '-')) {
982 if (parse_long(argv[optind++], &detail) != 0)
993 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
996 if (rc != LUSTRE_CFG_RC_NO_ERR)
997 cYAML_print_tree2file(stderr, err_rc);
999 cYAML_print_tree(show_rc);
1001 cYAML_free_tree(err_rc);
1002 cYAML_free_tree(show_rc);
1007 static int jt_show_routing(int argc, char **argv)
1009 struct cYAML *err_rc = NULL, *show_rc = NULL;
1012 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1016 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1018 if (rc != LUSTRE_CFG_RC_NO_ERR)
1019 cYAML_print_tree2file(stderr, err_rc);
1021 cYAML_print_tree(show_rc);
1023 cYAML_free_tree(err_rc);
1024 cYAML_free_tree(show_rc);
1029 static int jt_show_stats(int argc, char **argv)
1032 struct cYAML *show_rc = NULL, *err_rc = NULL;
1034 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1038 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1040 if (rc != LUSTRE_CFG_RC_NO_ERR)
1041 cYAML_print_tree2file(stderr, err_rc);
1043 cYAML_print_tree(show_rc);
1045 cYAML_free_tree(err_rc);
1046 cYAML_free_tree(show_rc);
1051 static int jt_show_global(int argc, char **argv)
1054 struct cYAML *show_rc = NULL, *err_rc = NULL;
1056 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1060 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1061 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1062 cYAML_print_tree2file(stderr, err_rc);
1066 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1067 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1068 cYAML_print_tree2file(stderr, err_rc);
1072 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1073 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1074 cYAML_print_tree2file(stderr, err_rc);
1078 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1079 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1080 cYAML_print_tree2file(stderr, err_rc);
1084 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1085 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1086 cYAML_print_tree2file(stderr, err_rc);
1090 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1091 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1092 cYAML_print_tree2file(stderr, err_rc);
1097 cYAML_print_tree(show_rc);
1100 cYAML_free_tree(err_rc);
1101 cYAML_free_tree(show_rc);
1106 static int jt_lnet(int argc, char **argv)
1110 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1114 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1117 static int jt_route(int argc, char **argv)
1121 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1125 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1128 static int jt_net(int argc, char **argv)
1132 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1136 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1139 static int jt_routing(int argc, char **argv)
1143 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1147 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1150 static int jt_stats(int argc, char **argv)
1154 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1158 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1161 static int jt_global(int argc, char **argv)
1165 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1169 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1172 static int jt_peers(int argc, char **argv)
1176 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1180 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1183 static int jt_set(int argc, char **argv)
1187 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1191 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1194 static int jt_import(int argc, char **argv)
1197 struct cYAML *err_rc = NULL;
1198 struct cYAML *show_rc = NULL;
1199 int rc = 0, return_rc = 0, opt, opt_found = 0;
1202 const char *const short_options = "adseh";
1203 static const struct option long_options[] = {
1204 { .name = "add", .has_arg = no_argument, .val = 'a' },
1205 { .name = "del", .has_arg = no_argument, .val = 'd' },
1206 { .name = "show", .has_arg = no_argument, .val = 's' },
1207 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1208 { .name = "help", .has_arg = no_argument, .val = 'h' },
1211 while ((opt = getopt_long(argc, argv, short_options,
1212 long_options, NULL)) != -1) {
1226 printf("import FILE\n"
1227 "import < FILE : import a file\n"
1228 "\t--add: add configuration\n"
1229 "\t--del: delete configuration\n"
1230 "\t--show: show configuration\n"
1231 "\t--exec: execute command\n"
1232 "\t--help: display this help\n"
1233 "If no command option is given then --add"
1234 " is assumed by default\n");
1241 /* grab the file name if one exists */
1242 if (opt_found && argc == 3)
1244 else if (!opt_found && argc == 2)
1249 rc = lustre_yaml_config(file, &err_rc);
1250 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1251 cYAML_print_tree(show_rc);
1252 cYAML_free_tree(show_rc);
1255 rc = lustre_yaml_del(file, &err_rc);
1258 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1259 cYAML_print_tree(show_rc);
1260 cYAML_free_tree(show_rc);
1263 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1264 cYAML_print_tree(show_rc);
1265 cYAML_free_tree(show_rc);
1269 if (rc || return_rc) {
1270 cYAML_print_tree2file(stderr, err_rc);
1271 cYAML_free_tree(err_rc);
1277 static int jt_export(int argc, char **argv)
1279 struct cYAML *show_rc = NULL;
1280 struct cYAML *err_rc = NULL;
1284 bool backup = false;
1287 const char *const short_options = "bh";
1288 static const struct option long_options[] = {
1289 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1290 { .name = "help", .has_arg = no_argument, .val = 'h' },
1293 while ((opt = getopt_long(argc, argv, short_options,
1294 long_options, NULL)) != -1) {
1301 printf("export > FILE.yaml : export configuration\n"
1302 "\t--backup: export only what's necessary for reconfig\n"
1303 "\t--help: display this help\n");
1308 if (backup && argc >= 3)
1310 else if (!backup && argc >= 2)
1316 f = fopen(file, "w");
1321 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1322 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1323 cYAML_print_tree2file(stderr, err_rc);
1324 cYAML_free_tree(err_rc);
1328 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1330 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1331 cYAML_print_tree2file(stderr, err_rc);
1332 cYAML_free_tree(err_rc);
1336 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1337 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1338 cYAML_print_tree2file(stderr, err_rc);
1339 cYAML_free_tree(err_rc);
1343 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1344 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1345 cYAML_print_tree2file(stderr, err_rc);
1346 cYAML_free_tree(err_rc);
1350 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1351 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1352 cYAML_print_tree2file(stderr, err_rc);
1353 cYAML_free_tree(err_rc);
1357 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1358 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1359 cYAML_print_tree2file(stderr, err_rc);
1360 cYAML_free_tree(err_rc);
1364 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1365 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1366 cYAML_print_tree2file(stderr, err_rc);
1367 cYAML_free_tree(err_rc);
1371 if (show_rc != NULL) {
1372 cYAML_print_tree2file(f, show_rc);
1373 cYAML_free_tree(show_rc);
1382 static int jt_add_peer_nid(int argc, char **argv)
1384 char *prim_nid = NULL;
1385 char **nids = NULL, **nids2 = NULL;
1387 struct cYAML *err_rc = NULL;
1388 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1389 bool non_mr = false;
1390 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1392 const char *const short_opts = "k:mn:";
1393 const struct option long_opts[] = {
1394 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1395 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1396 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1397 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1400 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1404 while ((opt = getopt_long(argc, argv, short_opts,
1405 long_opts, NULL)) != -1) {
1408 prim_nid_present = true;
1410 cYAML_build_error(-1, -1, "peer", "add",
1411 "ip2nets can not be specified"
1412 " along side prim_nid parameter.",
1426 if (ip2nets && (nid_list || prim_nid_present)) {
1427 cYAML_build_error(-1, -1, "peer", "add",
1428 "ip2nets can not be specified"
1429 " along side nid or prim_nid"
1430 " parameters", &err_rc);
1434 size = lustre_lnet_parse_nids(optarg, nids, size,
1439 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1449 for (; optind < argc; optind++) {
1450 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1457 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1458 !non_mr, ip2nets, -1, &err_rc);
1462 /* free the array of nids */
1463 for (i = 0; i < size; i++)
1468 if (rc != LUSTRE_CFG_RC_NO_ERR)
1469 cYAML_print_tree2file(stderr, err_rc);
1471 cYAML_free_tree(err_rc);
1476 static int jt_del_peer_nid(int argc, char **argv)
1478 char *prim_nid = NULL;
1479 char **nids = NULL, **nids2 = NULL;
1480 struct cYAML *err_rc = NULL;
1481 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1482 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1484 const char *const short_opts = "k:n:";
1485 const struct option long_opts[] = {
1486 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1487 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1488 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1491 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1495 while ((opt = getopt_long(argc, argv, short_opts,
1496 long_opts, NULL)) != -1) {
1499 prim_nid_present = true;
1501 cYAML_build_error(-1, -1, "peer", "add",
1502 "ip2nets can not be specified"
1503 " along side prim_nid parameter.",
1517 if (ip2nets && (nid_list || prim_nid_present)) {
1518 cYAML_build_error(-1, -1, "peer", "add",
1519 "ip2nets can not be specified"
1520 " along side nid or prim_nid"
1521 " parameters", &err_rc);
1524 size = lustre_lnet_parse_nids(optarg, nids, size,
1529 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1536 for (; optind < argc; optind++) {
1537 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1544 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1548 for (i = 0; i < size; i++)
1553 if (rc != LUSTRE_CFG_RC_NO_ERR)
1554 cYAML_print_tree2file(stderr, err_rc);
1556 cYAML_free_tree(err_rc);
1561 static int jt_show_peer(int argc, char **argv)
1565 struct cYAML *err_rc = NULL, *show_rc = NULL;
1566 long int detail = 0;
1568 const char *const short_opts = "hn:v::";
1569 const struct option long_opts[] = {
1570 { .name = "help", .has_arg = no_argument, .val = 'h' },
1571 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1572 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1575 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1579 while ((opt = getopt_long(argc, argv, short_opts,
1580 long_opts, NULL)) != -1) {
1586 if ((!optarg) && (argv[optind] != NULL) &&
1587 (argv[optind][0] != '-')) {
1588 if (parse_long(argv[optind++], &detail) != 0)
1599 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1602 if (rc != LUSTRE_CFG_RC_NO_ERR)
1603 cYAML_print_tree2file(stderr, err_rc);
1605 cYAML_print_tree(show_rc);
1607 cYAML_free_tree(err_rc);
1608 cYAML_free_tree(show_rc);
1613 static int jt_list_peer(int argc, char **argv)
1616 struct cYAML *err_rc = NULL, *list_rc = NULL;
1618 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1622 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1624 if (rc != LUSTRE_CFG_RC_NO_ERR)
1625 cYAML_print_tree2file(stderr, err_rc);
1627 cYAML_print_tree(list_rc);
1629 cYAML_free_tree(err_rc);
1630 cYAML_free_tree(list_rc);
1635 static int jt_ping(int argc, char **argv)
1637 struct cYAML *err_rc = NULL;
1638 struct cYAML *show_rc = NULL;
1642 const char *const short_options = "ht:";
1643 const struct option long_options[] = {
1644 { .name = "help", .has_arg = no_argument, .val = 'h' },
1645 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1648 while ((opt = getopt_long(argc, argv, short_options,
1649 long_options, NULL)) != -1) {
1652 timeout = 1000 * atol(optarg);
1655 printf("ping nid[,nid,...]\n"
1656 "\t --timeout: ping timeout\n"
1657 "\t --help: display this help\n");
1664 for (; optind < argc; optind++)
1665 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1668 cYAML_print_tree(show_rc);
1671 cYAML_print_tree2file(stderr, err_rc);
1673 cYAML_free_tree(err_rc);
1674 cYAML_free_tree(show_rc);
1679 static int jt_discover(int argc, char **argv)
1681 struct cYAML *err_rc = NULL;
1682 struct cYAML *show_rc = NULL;
1686 const char *const short_options = "fh";
1687 const struct option long_options[] = {
1688 { .name = "force", .has_arg = no_argument, .val = 'f' },
1689 { .name = "help", .has_arg = no_argument, .val = 'h' },
1692 while ((opt = getopt_long(argc, argv, short_options,
1693 long_options, NULL)) != -1) {
1699 printf("discover nid[,nid,...]\n"
1700 "\t --force: force discovery\n"
1701 "\t --help: display this help\n");
1708 for (; optind < argc; optind++)
1709 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1713 cYAML_print_tree(show_rc);
1716 cYAML_print_tree2file(stderr, err_rc);
1718 cYAML_free_tree(err_rc);
1719 cYAML_free_tree(show_rc);
1724 static int lnetctl_list_commands(int argc, char **argv)
1726 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1728 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1733 int main(int argc, char **argv)
1736 struct cYAML *err_rc = NULL;
1738 rc = lustre_lnet_config_lib_init();
1740 cYAML_build_error(-1, -1, "lnetctl", "startup",
1741 "cannot register LNet device", &err_rc);
1742 cYAML_print_tree2file(stderr, err_rc);
1746 Parser_init("lnetctl > ", cmd_list);
1748 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);