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_recovery(int argc, char **argv);
52 static int jt_show_global(int argc, char **argv);
53 static int jt_set_tiny(int argc, char **argv);
54 static int jt_set_small(int argc, char **argv);
55 static int jt_set_large(int argc, char **argv);
56 static int jt_set_numa(int argc, char **argv);
57 static int jt_set_retry_count(int argc, char **argv);
58 static int jt_set_transaction_to(int argc, char **argv);
59 static int jt_set_recov_intrv(int argc, char **argv);
60 static int jt_set_rtr_sensitivity(int argc, char **argv);
61 static int jt_set_hsensitivity(int argc, char **argv);
62 static int jt_add_peer_nid(int argc, char **argv);
63 static int jt_del_peer_nid(int argc, char **argv);
64 static int jt_set_max_intf(int argc, char **argv);
65 static int jt_set_discovery(int argc, char **argv);
66 static int jt_set_drop_asym_route(int argc, char **argv);
67 static int jt_list_peer(int argc, char **argv);
68 /*static int jt_show_peer(int argc, char **argv);*/
69 static int lnetctl_list_commands(int argc, char **argv);
70 static int jt_import(int argc, char **argv);
71 static int jt_export(int argc, char **argv);
72 static int jt_ping(int argc, char **argv);
73 static int jt_discover(int argc, char **argv);
74 static int jt_lnet(int argc, char **argv);
75 static int jt_route(int argc, char **argv);
76 static int jt_net(int argc, char **argv);
77 static int jt_routing(int argc, char **argv);
78 static int jt_set(int argc, char **argv);
79 static int jt_debug(int argc, char **argv);
80 static int jt_stats(int argc, char **argv);
81 static int jt_global(int argc, char **argv);
82 static int jt_peers(int argc, char **argv);
83 static int jt_set_ni_value(int argc, char **argv);
84 static int jt_set_peer_ni_value(int argc, char **argv);
86 command_t cmd_list[] = {
87 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
88 {"route", jt_route, 0, "route {add | del | show | help}"},
89 {"net", jt_net, 0, "net {add | del | show | help}"},
90 {"routing", jt_routing, 0, "routing {show | help}"},
91 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
92 " | routing | numa_range | max_interfaces"
94 {"import", jt_import, 0, "import FILE.yaml"},
95 {"export", jt_export, 0, "export FILE.yaml"},
96 {"stats", jt_stats, 0, "stats {show | help}"},
97 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
98 {"global", jt_global, 0, "global {show | help}"},
99 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
100 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
101 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
102 {"help", Parser_help, 0, "help"},
103 {"exit", Parser_quit, 0, "quit"},
104 {"quit", Parser_quit, 0, "quit"},
105 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
109 command_t lnet_cmds[] = {
110 {"configure", jt_config_lnet, 0, "configure lnet\n"
111 "\t--all: load NI configuration from module parameters\n"},
112 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
116 command_t route_cmds[] = {
117 {"add", jt_add_route, 0, "add a route\n"
118 "\t--net: net name (e.g. tcp0)\n"
119 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
120 "\t--hop: number to final destination (1 < hops < 255)\n"
121 "\t--priority: priority of route (0 - highest prio\n"
122 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
123 {"del", jt_del_route, 0, "delete a route\n"
124 "\t--net: net name (e.g. tcp0)\n"
125 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
126 {"show", jt_show_route, 0, "show routes\n"
127 "\t--net: net name (e.g. tcp0) to filter on\n"
128 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
129 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
130 "\t--priority: priority of route (0 - highest prio to filter on\n"
131 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
132 "\t--verbose: display detailed output per route\n"},
136 command_t net_cmds[] = {
137 {"add", jt_add_ni, 0, "add a network\n"
138 "\t--net: net name (e.g. tcp0)\n"
139 "\t--if: physical interface (e.g. eth0)\n"
140 "\t--ip2net: specify networks based on IP address patterns\n"
141 "\t--peer-timeout: time to wait before declaring a peer dead\n"
142 "\t--peer-credits: define the max number of inflight messages\n"
143 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
144 "\t--credits: Network Interface credits\n"
145 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
146 {"del", jt_del_ni, 0, "delete a network\n"
147 "\t--net: net name (e.g. tcp0)\n"
148 "\t--if: physical interface (e.g. eth0)\n"},
149 {"show", jt_show_net, 0, "show networks\n"
150 "\t--net: net name (e.g. tcp0) to filter on\n"
151 "\t--verbose: display detailed output per network."
152 " Optional argument of '2' outputs more stats\n"},
153 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
154 "\t--nid: NI NID to set the\n"
155 "\t--health: specify health value to set\n"
156 "\t--all: set all NIs value to the one specified\n"},
160 command_t routing_cmds[] = {
161 {"show", jt_show_routing, 0, "show routing information\n"},
165 command_t stats_cmds[] = {
166 {"show", jt_show_stats, 0, "show LNET statistics\n"},
170 command_t debug_cmds[] = {
171 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
172 "\t--local : list local recovery queue\n"
173 "\t--peer : list peer recovery queue\n"},
177 command_t global_cmds[] = {
178 {"show", jt_show_global, 0, "show global variables\n"},
182 command_t set_cmds[] = {
183 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
184 "\tVALUE must be greater than 0\n"},
185 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
186 "\tVALUE must be greater than 0\n"},
187 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
188 "\tVALUE must be greater than 0\n"},
189 {"routing", jt_set_routing, 0, "enable/disable routing\n"
190 "\t0 - disable routing\n"
191 "\t1 - enable routing\n"},
192 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
193 "\tVALUE must be at least 0\n"},
194 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
196 "\tValue must be greater than 16\n"},
197 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
198 "\t0 - disable peer discovery\n"
199 "\t1 - enable peer discovery (default)\n"},
200 {"drop_asym_route", jt_set_drop_asym_route, 0,
201 "drop/accept asymmetrical route messages\n"
202 "\t0 - accept asymmetrical route messages (default)\n"
203 "\t1 - drop asymmetrical route messages\n"},
204 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
205 "\t0 - turn of retries\n"
206 "\t>0 - number of retries\n"},
207 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
208 "\t>0 - timeout in seconds\n"},
209 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
210 "\t0 - turn off health evaluation\n"
211 "\t>0 - sensitivity value not more than 1000\n"},
212 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
213 "\t>0 - time in seconds between pings\n"},
214 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
215 "\t100 - router interfaces need to be fully healthy to be used\n"
216 "\t<100 - router interfaces can be used even if not healthy\n"},
220 command_t peer_cmds[] = {
221 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
222 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
223 "\t NID in the list becomes the Primary NID of a newly created\n"
225 "\t--nid: one or more peer NIDs\n"
226 "\t--non_mr: create this peer as not Multi-Rail capable\n"
227 "\t--ip2nets: specify a range of nids per peer"},
228 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
229 "\t--prim_nid: Primary NID of the peer.\n"
230 "\t--nid: list of NIDs to remove. If none provided,\n"
231 "\t peer is deleted\n"
232 "\t--ip2nets: specify a range of nids per peer"},
233 {"show", jt_show_peer, 0, "show peer information\n"
234 "\t--nid: NID of peer to filter on.\n"
235 "\t--verbose: display detailed output per peer."
236 " Optional argument of '2' outputs more stats\n"},
237 {"list", jt_list_peer, 0, "list all peers\n"},
238 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
239 "\t--nid: Peer NI NID to set the\n"
240 "\t--health: specify health value to set\n"
241 "\t--all: set all peer_nis values to the one specified\n"},
245 static inline void print_help(const command_t cmds[], const char *cmd_type,
248 const command_t *cmd;
250 for (cmd = cmds; cmd->pc_name; cmd++) {
251 if (pc_name != NULL &&
252 strcmp(cmd->pc_name, pc_name) == 0) {
253 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
256 } else if (pc_name != NULL) {
259 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
263 static int parse_long(const char *number, long int *value)
270 *value = strtol(number, &end, 0);
271 if (end != NULL && *end != 0)
277 static int check_cmd(const command_t *cmd_list, const char *cmd,
278 const char *sub_cmd, const int min_args,
279 int argc, char **argv)
286 const char *const short_options = "h";
287 static const struct option long_options[] = {
288 { .name = "help", .has_arg = no_argument, .val = 'h' },
292 if (argc < min_args) {
293 print_help(cmd_list, cmd, sub_cmd);
296 } else if (argc > 2) {
300 while ((opt = getopt_long(argc, argv, short_options,
301 long_options, NULL)) != -1) {
304 print_help(cmd_list, cmd, sub_cmd);
319 static int jt_set_max_intf(int argc, char **argv)
323 struct cYAML *err_rc = NULL;
325 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
329 rc = parse_long(argv[1], &value);
331 cYAML_build_error(-1, -1, "parser", "set",
332 "cannot parse max_interfaces value", &err_rc);
333 cYAML_print_tree2file(stderr, err_rc);
334 cYAML_free_tree(err_rc);
338 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
339 if (rc != LUSTRE_CFG_RC_NO_ERR)
340 cYAML_print_tree2file(stderr, err_rc);
342 cYAML_free_tree(err_rc);
347 static int jt_set_numa(int argc, char **argv)
351 struct cYAML *err_rc = NULL;
353 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
357 rc = parse_long(argv[1], &value);
359 cYAML_build_error(-1, -1, "parser", "set",
360 "cannot parse numa_range value", &err_rc);
361 cYAML_print_tree2file(stderr, err_rc);
362 cYAML_free_tree(err_rc);
366 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
367 if (rc != LUSTRE_CFG_RC_NO_ERR)
368 cYAML_print_tree2file(stderr, err_rc);
370 cYAML_free_tree(err_rc);
375 static int jt_set_recov_intrv(int argc, char **argv)
379 struct cYAML *err_rc = NULL;
381 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
385 rc = parse_long(argv[1], &value);
387 cYAML_build_error(-1, -1, "parser", "set",
388 "cannot parse recovery interval value", &err_rc);
389 cYAML_print_tree2file(stderr, err_rc);
390 cYAML_free_tree(err_rc);
394 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
395 if (rc != LUSTRE_CFG_RC_NO_ERR)
396 cYAML_print_tree2file(stderr, err_rc);
398 cYAML_free_tree(err_rc);
403 static int jt_set_rtr_sensitivity(int argc, char **argv)
407 struct cYAML *err_rc = NULL;
409 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
413 rc = parse_long(argv[1], &value);
415 cYAML_build_error(-1, -1, "parser", "set",
416 "cannot parse router sensitivity value", &err_rc);
417 cYAML_print_tree2file(stderr, err_rc);
418 cYAML_free_tree(err_rc);
422 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
423 if (rc != LUSTRE_CFG_RC_NO_ERR)
424 cYAML_print_tree2file(stderr, err_rc);
426 cYAML_free_tree(err_rc);
431 static int jt_set_hsensitivity(int argc, char **argv)
435 struct cYAML *err_rc = NULL;
437 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
441 rc = parse_long(argv[1], &value);
443 cYAML_build_error(-1, -1, "parser", "set",
444 "cannot parse health sensitivity value", &err_rc);
445 cYAML_print_tree2file(stderr, err_rc);
446 cYAML_free_tree(err_rc);
450 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
451 if (rc != LUSTRE_CFG_RC_NO_ERR)
452 cYAML_print_tree2file(stderr, err_rc);
454 cYAML_free_tree(err_rc);
459 static int jt_set_transaction_to(int argc, char **argv)
463 struct cYAML *err_rc = NULL;
465 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
469 rc = parse_long(argv[1], &value);
471 cYAML_build_error(-1, -1, "parser", "set",
472 "cannot parse transaction timeout value", &err_rc);
473 cYAML_print_tree2file(stderr, err_rc);
474 cYAML_free_tree(err_rc);
478 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
479 if (rc != LUSTRE_CFG_RC_NO_ERR)
480 cYAML_print_tree2file(stderr, err_rc);
482 cYAML_free_tree(err_rc);
487 static int jt_set_retry_count(int argc, char **argv)
491 struct cYAML *err_rc = NULL;
493 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
497 rc = parse_long(argv[1], &value);
499 cYAML_build_error(-1, -1, "parser", "set",
500 "cannot parse retry_count value", &err_rc);
501 cYAML_print_tree2file(stderr, err_rc);
502 cYAML_free_tree(err_rc);
506 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
507 if (rc != LUSTRE_CFG_RC_NO_ERR)
508 cYAML_print_tree2file(stderr, err_rc);
510 cYAML_free_tree(err_rc);
515 static int jt_set_discovery(int argc, char **argv)
519 struct cYAML *err_rc = NULL;
521 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
525 rc = parse_long(argv[1], &value);
527 cYAML_build_error(-1, -1, "parser", "set",
528 "cannot parse discovery value", &err_rc);
529 cYAML_print_tree2file(stderr, err_rc);
530 cYAML_free_tree(err_rc);
534 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
535 if (rc != LUSTRE_CFG_RC_NO_ERR)
536 cYAML_print_tree2file(stderr, err_rc);
538 cYAML_free_tree(err_rc);
543 static int jt_set_drop_asym_route(int argc, char **argv)
547 struct cYAML *err_rc = NULL;
549 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
553 rc = parse_long(argv[1], &value);
555 cYAML_build_error(-1, -1, "parser", "set",
556 "cannot parse drop_asym_route value",
558 cYAML_print_tree2file(stderr, err_rc);
559 cYAML_free_tree(err_rc);
563 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
564 if (rc != LUSTRE_CFG_RC_NO_ERR)
565 cYAML_print_tree2file(stderr, err_rc);
567 cYAML_free_tree(err_rc);
572 static int jt_set_tiny(int argc, char **argv)
576 struct cYAML *err_rc = NULL;
578 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
582 rc = parse_long(argv[1], &value);
584 cYAML_build_error(-1, -1, "parser", "set",
585 "cannot parse tiny_buffers value", &err_rc);
586 cYAML_print_tree2file(stderr, err_rc);
587 cYAML_free_tree(err_rc);
591 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
592 if (rc != LUSTRE_CFG_RC_NO_ERR)
593 cYAML_print_tree2file(stderr, err_rc);
595 cYAML_free_tree(err_rc);
600 static int jt_set_small(int argc, char **argv)
604 struct cYAML *err_rc = NULL;
606 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
610 rc = parse_long(argv[1], &value);
612 cYAML_build_error(-1, -1, "parser", "set",
613 "cannot parse small_buffers value", &err_rc);
614 cYAML_print_tree2file(stderr, err_rc);
615 cYAML_free_tree(err_rc);
619 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
620 if (rc != LUSTRE_CFG_RC_NO_ERR)
621 cYAML_print_tree2file(stderr, err_rc);
623 cYAML_free_tree(err_rc);
628 static int jt_set_large(int argc, char **argv)
632 struct cYAML *err_rc = NULL;
634 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
638 rc = parse_long(argv[1], &value);
640 cYAML_build_error(-1, -1, "parser", "set",
641 "cannot parse large_buffers value", &err_rc);
642 cYAML_print_tree2file(stderr, err_rc);
643 cYAML_free_tree(err_rc);
647 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
648 if (rc != LUSTRE_CFG_RC_NO_ERR)
649 cYAML_print_tree2file(stderr, err_rc);
651 cYAML_free_tree(err_rc);
656 static int jt_set_routing(int argc, char **argv)
659 struct cYAML *err_rc = NULL;
662 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
666 rc = parse_long(argv[1], &value);
667 if (rc != 0 || (value != 0 && value != 1)) {
668 cYAML_build_error(-1, -1, "parser", "set",
669 "cannot parse routing value.\n"
670 "must be 0 for disable or 1 for enable",
672 cYAML_print_tree2file(stderr, err_rc);
673 cYAML_free_tree(err_rc);
677 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
679 if (rc != LUSTRE_CFG_RC_NO_ERR)
680 cYAML_print_tree2file(stderr, err_rc);
682 cYAML_free_tree(err_rc);
687 static int jt_config_lnet(int argc, char **argv)
689 struct cYAML *err_rc = NULL;
690 bool load_mod_params = false;
693 const char *const short_options = "a";
694 static const struct option long_options[] = {
695 { .name = "all", .has_arg = no_argument, .val = 'a' },
699 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
703 while ((opt = getopt_long(argc, argv, short_options,
704 long_options, NULL)) != -1) {
707 load_mod_params = true;
714 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
717 if (rc != LUSTRE_CFG_RC_NO_ERR)
718 cYAML_print_tree2file(stderr, err_rc);
720 cYAML_free_tree(err_rc);
725 static int jt_unconfig_lnet(int argc, char **argv)
727 struct cYAML *err_rc = NULL;
730 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
734 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
736 if (rc != LUSTRE_CFG_RC_NO_ERR)
737 cYAML_print_tree2file(stderr, err_rc);
739 cYAML_free_tree(err_rc);
743 static int jt_add_route(int argc, char **argv)
745 char *network = NULL, *gateway = NULL;
746 long int hop = -1, prio = -1, sen = -1;
747 struct cYAML *err_rc = NULL;
750 const char *const short_options = "n:g:c:p:";
751 static const struct option long_options[] = {
752 { .name = "net", .has_arg = required_argument, .val = 'n' },
753 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
754 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
755 { .name = "priority", .has_arg = required_argument, .val = 'p' },
756 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
759 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
763 while ((opt = getopt_long(argc, argv, short_options,
764 long_options, NULL)) != -1) {
773 rc = parse_long(optarg, &hop);
781 rc = parse_long(optarg, &prio);
789 rc = parse_long(optarg, &sen);
798 print_help(route_cmds, "route", "add");
804 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
807 if (rc != LUSTRE_CFG_RC_NO_ERR)
808 cYAML_print_tree2file(stderr, err_rc);
810 cYAML_free_tree(err_rc);
815 static int jt_add_ni(int argc, char **argv)
818 long int pto = -1, pc = -1, pbc = -1, cre = -1;
819 struct cYAML *err_rc = NULL;
820 int rc, opt, cpt_rc = -1;
821 struct lnet_dlc_network_descr nw_descr;
822 struct cfs_expr_list *global_cpts = NULL;
823 struct lnet_ioctl_config_lnd_tunables tunables;
826 memset(&tunables, 0, sizeof(tunables));
827 lustre_lnet_init_nw_descr(&nw_descr);
829 const char *const short_options = "n:i:p:t:c:b:r:s:";
830 static const struct option long_options[] = {
831 { .name = "net", .has_arg = required_argument, .val = 'n' },
832 { .name = "if", .has_arg = required_argument, .val = 'i' },
833 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
834 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
835 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
836 { .name = "peer-buffer-credits",
837 .has_arg = required_argument, .val = 'b' },
838 { .name = "credits", .has_arg = required_argument, .val = 'r' },
839 { .name = "cpt", .has_arg = required_argument, .val = 's' },
842 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
846 while ((opt = getopt_long(argc, argv, short_options,
847 long_options, NULL)) != -1) {
850 nw_descr.nw_id = libcfs_str2net(optarg);
853 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
855 cYAML_build_error(-1, -1, "ni", "add",
856 "bad interface list",
865 rc = parse_long(optarg, &pto);
873 rc = parse_long(optarg, &pc);
881 rc = parse_long(optarg, &pbc);
889 rc = parse_long(optarg, &cre);
897 cpt_rc = cfs_expr_list_parse(optarg,
899 UINT_MAX, &global_cpts);
902 print_help(net_cmds, "net", "add");
908 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
909 tunables.lt_cmn.lct_peer_timeout = pto;
910 tunables.lt_cmn.lct_peer_tx_credits = pc;
911 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
912 tunables.lt_cmn.lct_max_tx_credits = cre;
916 rc = lustre_lnet_config_ni(&nw_descr,
917 (cpt_rc == 0) ? global_cpts: NULL,
918 ip2net, (found) ? &tunables : NULL,
921 if (global_cpts != NULL)
922 cfs_expr_list_free(global_cpts);
925 if (rc != LUSTRE_CFG_RC_NO_ERR)
926 cYAML_print_tree2file(stderr, err_rc);
928 cYAML_free_tree(err_rc);
933 static int jt_del_route(int argc, char **argv)
935 char *network = NULL, *gateway = NULL;
936 struct cYAML *err_rc = NULL;
939 const char *const short_options = "n:g:";
940 static const struct option long_options[] = {
941 { .name = "net", .has_arg = required_argument, .val = 'n' },
942 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
945 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
949 while ((opt = getopt_long(argc, argv, short_options,
950 long_options, NULL)) != -1) {
959 print_help(route_cmds, "route", "del");
965 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
967 if (rc != LUSTRE_CFG_RC_NO_ERR)
968 cYAML_print_tree2file(stderr, err_rc);
970 cYAML_free_tree(err_rc);
975 static int jt_del_ni(int argc, char **argv)
977 struct cYAML *err_rc = NULL;
979 struct lnet_dlc_network_descr nw_descr;
981 lustre_lnet_init_nw_descr(&nw_descr);
983 const char *const short_options = "n:i:";
984 static const struct option long_options[] = {
985 { .name = "net", .has_arg = required_argument, .val = 'n' },
986 { .name = "if", .has_arg = required_argument, .val = 'i' },
989 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
993 while ((opt = getopt_long(argc, argv, short_options,
994 long_options, NULL)) != -1) {
997 nw_descr.nw_id = libcfs_str2net(optarg);
1000 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1002 cYAML_build_error(-1, -1, "ni", "add",
1003 "bad interface list",
1009 print_help(net_cmds, "net", "del");
1015 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1018 if (rc != LUSTRE_CFG_RC_NO_ERR)
1019 cYAML_print_tree2file(stderr, err_rc);
1021 cYAML_free_tree(err_rc);
1026 static int jt_show_route(int argc, char **argv)
1028 char *network = NULL, *gateway = NULL;
1029 long int hop = -1, prio = -1;
1030 int detail = 0, rc, opt;
1031 struct cYAML *err_rc = NULL, *show_rc = NULL;
1033 const char *const short_options = "n:g:h:p:v";
1034 static const struct option long_options[] = {
1035 { .name = "net", .has_arg = required_argument, .val = 'n' },
1036 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1037 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1038 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1039 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1042 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1046 while ((opt = getopt_long(argc, argv, short_options,
1047 long_options, NULL)) != -1) {
1056 rc = parse_long(optarg, &hop);
1064 rc = parse_long(optarg, &prio);
1075 print_help(route_cmds, "route", "show");
1081 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1082 &show_rc, &err_rc, false);
1084 if (rc != LUSTRE_CFG_RC_NO_ERR)
1085 cYAML_print_tree2file(stderr, err_rc);
1087 cYAML_print_tree(show_rc);
1089 cYAML_free_tree(err_rc);
1090 cYAML_free_tree(show_rc);
1095 static int set_value_helper(int argc, char **argv,
1096 int (*cb)(int, bool, char*, int, struct cYAML**))
1099 long int healthv = -1;
1102 struct cYAML *err_rc = NULL;
1104 const char *const short_options = "t:n:a";
1105 static const struct option long_options[] = {
1106 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1107 { .name = "health", .has_arg = required_argument, .val = 't' },
1108 { .name = "all", .has_arg = no_argument, .val = 'a' },
1111 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1115 while ((opt = getopt_long(argc, argv, short_options,
1116 long_options, NULL)) != -1) {
1122 if (parse_long(optarg, &healthv) != 0)
1133 rc = cb(healthv, all, nid, -1, &err_rc);
1135 if (rc != LUSTRE_CFG_RC_NO_ERR)
1136 cYAML_print_tree2file(stderr, err_rc);
1138 cYAML_free_tree(err_rc);
1143 static int jt_set_ni_value(int argc, char **argv)
1145 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1148 static int jt_set_peer_ni_value(int argc, char **argv)
1150 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1153 static int jt_show_recovery(int argc, char **argv)
1156 struct cYAML *err_rc = NULL, *show_rc = NULL;
1158 const char *const short_options = "lp";
1159 static const struct option long_options[] = {
1160 { .name = "local", .has_arg = no_argument, .val = 'l' },
1161 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1164 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1168 while ((opt = getopt_long(argc, argv, short_options,
1169 long_options, NULL)) != -1) {
1172 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1175 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1182 if (rc != LUSTRE_CFG_RC_NO_ERR)
1183 cYAML_print_tree2file(stderr, err_rc);
1185 cYAML_print_tree(show_rc);
1187 cYAML_free_tree(err_rc);
1188 cYAML_free_tree(show_rc);
1193 static int jt_show_net(int argc, char **argv)
1195 char *network = NULL;
1197 struct cYAML *err_rc = NULL, *show_rc = NULL;
1198 long int detail = 0;
1200 const char *const short_options = "n:v";
1201 static const struct option long_options[] = {
1202 { .name = "net", .has_arg = required_argument, .val = 'n' },
1203 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1206 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1210 while ((opt = getopt_long(argc, argv, short_options,
1211 long_options, NULL)) != -1) {
1217 if ((!optarg) && (argv[optind] != NULL) &&
1218 (argv[optind][0] != '-')) {
1219 if (parse_long(argv[optind++], &detail) != 0)
1226 print_help(net_cmds, "net", "show");
1232 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1235 if (rc != LUSTRE_CFG_RC_NO_ERR)
1236 cYAML_print_tree2file(stderr, err_rc);
1238 cYAML_print_tree(show_rc);
1240 cYAML_free_tree(err_rc);
1241 cYAML_free_tree(show_rc);
1246 static int jt_show_routing(int argc, char **argv)
1248 struct cYAML *err_rc = NULL, *show_rc = NULL;
1251 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1255 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1257 if (rc != LUSTRE_CFG_RC_NO_ERR)
1258 cYAML_print_tree2file(stderr, err_rc);
1260 cYAML_print_tree(show_rc);
1262 cYAML_free_tree(err_rc);
1263 cYAML_free_tree(show_rc);
1268 static int jt_show_stats(int argc, char **argv)
1271 struct cYAML *show_rc = NULL, *err_rc = NULL;
1273 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1277 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1279 if (rc != LUSTRE_CFG_RC_NO_ERR)
1280 cYAML_print_tree2file(stderr, err_rc);
1282 cYAML_print_tree(show_rc);
1284 cYAML_free_tree(err_rc);
1285 cYAML_free_tree(show_rc);
1290 static int jt_show_global(int argc, char **argv)
1293 struct cYAML *show_rc = NULL, *err_rc = NULL;
1295 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1299 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1300 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1301 cYAML_print_tree2file(stderr, err_rc);
1305 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1306 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1307 cYAML_print_tree2file(stderr, err_rc);
1311 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1312 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1313 cYAML_print_tree2file(stderr, err_rc);
1317 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1318 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1319 cYAML_print_tree2file(stderr, err_rc);
1323 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1324 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1325 cYAML_print_tree2file(stderr, err_rc);
1329 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1330 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1331 cYAML_print_tree2file(stderr, err_rc);
1335 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1336 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1337 cYAML_print_tree2file(stderr, err_rc);
1341 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1342 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1343 cYAML_print_tree2file(stderr, err_rc);
1347 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1348 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1349 cYAML_print_tree2file(stderr, err_rc);
1354 cYAML_print_tree(show_rc);
1357 cYAML_free_tree(err_rc);
1358 cYAML_free_tree(show_rc);
1363 static int jt_lnet(int argc, char **argv)
1367 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1371 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1374 static int jt_route(int argc, char **argv)
1378 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1382 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1385 static int jt_net(int argc, char **argv)
1389 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1393 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1396 static int jt_routing(int argc, char **argv)
1400 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1404 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1407 static int jt_stats(int argc, char **argv)
1411 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1415 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1418 static int jt_debug(int argc, char **argv)
1422 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1426 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1429 static int jt_global(int argc, char **argv)
1433 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1437 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1440 static int jt_peers(int argc, char **argv)
1444 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1448 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1451 static int jt_set(int argc, char **argv)
1455 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1459 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1462 static int jt_import(int argc, char **argv)
1465 struct cYAML *err_rc = NULL;
1466 struct cYAML *show_rc = NULL;
1467 int rc = 0, return_rc = 0, opt, opt_found = 0;
1470 const char *const short_options = "adseh";
1471 static const struct option long_options[] = {
1472 { .name = "add", .has_arg = no_argument, .val = 'a' },
1473 { .name = "del", .has_arg = no_argument, .val = 'd' },
1474 { .name = "show", .has_arg = no_argument, .val = 's' },
1475 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1476 { .name = "help", .has_arg = no_argument, .val = 'h' },
1479 while ((opt = getopt_long(argc, argv, short_options,
1480 long_options, NULL)) != -1) {
1494 printf("import FILE\n"
1495 "import < FILE : import a file\n"
1496 "\t--add: add configuration\n"
1497 "\t--del: delete configuration\n"
1498 "\t--show: show configuration\n"
1499 "\t--exec: execute command\n"
1500 "\t--help: display this help\n"
1501 "If no command option is given then --add"
1502 " is assumed by default\n");
1509 /* grab the file name if one exists */
1510 if (opt_found && argc == 3)
1512 else if (!opt_found && argc == 2)
1517 rc = lustre_yaml_config(file, &err_rc);
1518 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1519 cYAML_print_tree(show_rc);
1520 cYAML_free_tree(show_rc);
1523 rc = lustre_yaml_del(file, &err_rc);
1526 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1527 cYAML_print_tree(show_rc);
1528 cYAML_free_tree(show_rc);
1531 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1532 cYAML_print_tree(show_rc);
1533 cYAML_free_tree(show_rc);
1537 if (rc || return_rc) {
1538 cYAML_print_tree2file(stderr, err_rc);
1539 cYAML_free_tree(err_rc);
1545 static int jt_export(int argc, char **argv)
1547 struct cYAML *show_rc = NULL;
1548 struct cYAML *err_rc = NULL;
1552 bool backup = false;
1555 const char *const short_options = "bh";
1556 static const struct option long_options[] = {
1557 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1558 { .name = "help", .has_arg = no_argument, .val = 'h' },
1561 while ((opt = getopt_long(argc, argv, short_options,
1562 long_options, NULL)) != -1) {
1569 printf("export > FILE.yaml : export configuration\n"
1570 "\t--backup: export only what's necessary for reconfig\n"
1571 "\t--help: display this help\n");
1576 if (backup && argc >= 3)
1578 else if (!backup && argc >= 2)
1584 f = fopen(file, "w");
1589 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1590 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1591 cYAML_print_tree2file(stderr, err_rc);
1592 cYAML_free_tree(err_rc);
1596 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1598 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1599 cYAML_print_tree2file(stderr, err_rc);
1600 cYAML_free_tree(err_rc);
1604 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1605 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1606 cYAML_print_tree2file(stderr, err_rc);
1607 cYAML_free_tree(err_rc);
1611 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1612 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1613 cYAML_print_tree2file(stderr, err_rc);
1614 cYAML_free_tree(err_rc);
1618 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1619 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1620 cYAML_print_tree2file(stderr, err_rc);
1621 cYAML_free_tree(err_rc);
1625 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1626 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1627 cYAML_print_tree2file(stderr, err_rc);
1628 cYAML_free_tree(err_rc);
1632 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1633 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1634 cYAML_print_tree2file(stderr, err_rc);
1635 cYAML_free_tree(err_rc);
1639 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1640 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1641 cYAML_print_tree2file(stderr, err_rc);
1642 cYAML_free_tree(err_rc);
1646 if (show_rc != NULL) {
1647 cYAML_print_tree2file(f, show_rc);
1648 cYAML_free_tree(show_rc);
1657 static int jt_add_peer_nid(int argc, char **argv)
1659 char *prim_nid = NULL;
1660 char **nids = NULL, **nids2 = NULL;
1662 struct cYAML *err_rc = NULL;
1663 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1664 bool non_mr = false;
1665 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1667 const char *const short_opts = "k:mn:";
1668 const struct option long_opts[] = {
1669 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1670 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1671 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1672 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1675 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1679 while ((opt = getopt_long(argc, argv, short_opts,
1680 long_opts, NULL)) != -1) {
1683 prim_nid_present = true;
1685 cYAML_build_error(-1, -1, "peer", "add",
1686 "ip2nets can not be specified"
1687 " along side prim_nid parameter.",
1701 if (ip2nets && (nid_list || prim_nid_present)) {
1702 cYAML_build_error(-1, -1, "peer", "add",
1703 "ip2nets can not be specified"
1704 " along side nid or prim_nid"
1705 " parameters", &err_rc);
1709 size = lustre_lnet_parse_nids(optarg, nids, size,
1714 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1720 print_help(peer_cmds, "peer", "add");
1726 for (; optind < argc; optind++) {
1727 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1734 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1735 !non_mr, ip2nets, -1, &err_rc);
1739 /* free the array of nids */
1740 for (i = 0; i < size; i++)
1745 if (rc != LUSTRE_CFG_RC_NO_ERR)
1746 cYAML_print_tree2file(stderr, err_rc);
1748 cYAML_free_tree(err_rc);
1753 static int jt_del_peer_nid(int argc, char **argv)
1755 char *prim_nid = NULL;
1756 char **nids = NULL, **nids2 = NULL;
1757 struct cYAML *err_rc = NULL;
1758 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1759 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1761 const char *const short_opts = "k:n:";
1762 const struct option long_opts[] = {
1763 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1764 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1765 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1768 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1772 while ((opt = getopt_long(argc, argv, short_opts,
1773 long_opts, NULL)) != -1) {
1776 prim_nid_present = true;
1778 cYAML_build_error(-1, -1, "peer", "add",
1779 "ip2nets can not be specified"
1780 " along side prim_nid parameter.",
1794 if (ip2nets && (nid_list || prim_nid_present)) {
1795 cYAML_build_error(-1, -1, "peer", "add",
1796 "ip2nets can not be specified"
1797 " along side nid or prim_nid"
1798 " parameters", &err_rc);
1801 size = lustre_lnet_parse_nids(optarg, nids, size,
1806 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1809 print_help(peer_cmds, "peer", "del");
1815 for (; optind < argc; optind++) {
1816 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1823 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1827 for (i = 0; i < size; i++)
1832 if (rc != LUSTRE_CFG_RC_NO_ERR)
1833 cYAML_print_tree2file(stderr, err_rc);
1835 cYAML_free_tree(err_rc);
1840 static int jt_show_peer(int argc, char **argv)
1844 struct cYAML *err_rc = NULL, *show_rc = NULL;
1845 long int detail = 0;
1847 const char *const short_opts = "hn:v::";
1848 const struct option long_opts[] = {
1849 { .name = "help", .has_arg = no_argument, .val = 'h' },
1850 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1851 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1854 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1858 while ((opt = getopt_long(argc, argv, short_opts,
1859 long_opts, NULL)) != -1) {
1865 if ((!optarg) && (argv[optind] != NULL) &&
1866 (argv[optind][0] != '-')) {
1867 if (parse_long(argv[optind++], &detail) != 0)
1874 print_help(peer_cmds, "peer", "show");
1880 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1883 if (rc != LUSTRE_CFG_RC_NO_ERR)
1884 cYAML_print_tree2file(stderr, err_rc);
1886 cYAML_print_tree(show_rc);
1888 cYAML_free_tree(err_rc);
1889 cYAML_free_tree(show_rc);
1894 static int jt_list_peer(int argc, char **argv)
1897 struct cYAML *err_rc = NULL, *list_rc = NULL;
1899 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1903 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1905 if (rc != LUSTRE_CFG_RC_NO_ERR)
1906 cYAML_print_tree2file(stderr, err_rc);
1908 cYAML_print_tree(list_rc);
1910 cYAML_free_tree(err_rc);
1911 cYAML_free_tree(list_rc);
1916 static int jt_ping(int argc, char **argv)
1918 struct cYAML *err_rc = NULL;
1919 struct cYAML *show_rc = NULL;
1923 const char *const short_options = "ht:";
1924 const struct option long_options[] = {
1925 { .name = "help", .has_arg = no_argument, .val = 'h' },
1926 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1929 while ((opt = getopt_long(argc, argv, short_options,
1930 long_options, NULL)) != -1) {
1933 timeout = 1000 * atol(optarg);
1936 printf("ping nid[,nid,...]\n"
1937 "\t --timeout: ping timeout\n"
1938 "\t --help: display this help\n");
1945 for (; optind < argc; optind++)
1946 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1949 cYAML_print_tree(show_rc);
1952 cYAML_print_tree2file(stderr, err_rc);
1954 cYAML_free_tree(err_rc);
1955 cYAML_free_tree(show_rc);
1960 static int jt_discover(int argc, char **argv)
1962 struct cYAML *err_rc = NULL;
1963 struct cYAML *show_rc = NULL;
1967 const char *const short_options = "fh";
1968 const struct option long_options[] = {
1969 { .name = "force", .has_arg = no_argument, .val = 'f' },
1970 { .name = "help", .has_arg = no_argument, .val = 'h' },
1973 while ((opt = getopt_long(argc, argv, short_options,
1974 long_options, NULL)) != -1) {
1980 printf("discover nid[,nid,...]\n"
1981 "\t --force: force discovery\n"
1982 "\t --help: display this help\n");
1989 for (; optind < argc; optind++)
1990 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1994 cYAML_print_tree(show_rc);
1997 cYAML_print_tree2file(stderr, err_rc);
1999 cYAML_free_tree(err_rc);
2000 cYAML_free_tree(show_rc);
2005 static int lnetctl_list_commands(int argc, char **argv)
2007 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2009 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2014 int main(int argc, char **argv)
2017 struct cYAML *err_rc = NULL;
2019 rc = lustre_lnet_config_lib_init();
2021 cYAML_build_error(-1, -1, "lnetctl", "startup",
2022 "cannot register LNet device", &err_rc);
2023 cYAML_print_tree2file(stderr, err_rc);
2027 Parser_init("lnetctl > ", cmd_list);
2029 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);