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>
33 #include "lnetconfig/cyaml.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);
85 static int jt_calc_service_id(int argc, char **argv);
87 command_t cmd_list[] = {
88 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
89 {"route", jt_route, 0, "route {add | del | show | help}"},
90 {"net", jt_net, 0, "net {add | del | show | help}"},
91 {"routing", jt_routing, 0, "routing {show | help}"},
92 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
93 " | routing | numa_range | max_interfaces"
95 {"import", jt_import, 0, "import FILE.yaml"},
96 {"export", jt_export, 0, "export FILE.yaml"},
97 {"stats", jt_stats, 0, "stats {show | help}"},
98 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
99 {"global", jt_global, 0, "global {show | help}"},
100 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
101 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
102 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
103 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
104 {"help", Parser_help, 0, "help"},
105 {"exit", Parser_quit, 0, "quit"},
106 {"quit", Parser_quit, 0, "quit"},
107 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
111 command_t lnet_cmds[] = {
112 {"configure", jt_config_lnet, 0, "configure lnet\n"
113 "\t--all: load NI configuration from module parameters\n"},
114 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
118 command_t route_cmds[] = {
119 {"add", jt_add_route, 0, "add a route\n"
120 "\t--net: net name (e.g. tcp0)\n"
121 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
122 "\t--hop: number to final destination (1 < hops < 255)\n"
123 "\t--priority: priority of route (0 - highest prio\n"
124 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
125 {"del", jt_del_route, 0, "delete a route\n"
126 "\t--net: net name (e.g. tcp0)\n"
127 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
128 {"show", jt_show_route, 0, "show routes\n"
129 "\t--net: net name (e.g. tcp0) to filter on\n"
130 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
131 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
132 "\t--priority: priority of route (0 - highest prio to filter on\n"
133 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
134 "\t--verbose: display detailed output per route\n"},
138 command_t net_cmds[] = {
139 {"add", jt_add_ni, 0, "add a network\n"
140 "\t--net: net name (e.g. tcp0)\n"
141 "\t--if: physical interface (e.g. eth0)\n"
142 "\t--ip2net: specify networks based on IP address patterns\n"
143 "\t--peer-timeout: time to wait before declaring a peer dead\n"
144 "\t--peer-credits: define the max number of inflight messages\n"
145 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
146 "\t--credits: Network Interface credits\n"
147 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
148 {"del", jt_del_ni, 0, "delete a network\n"
149 "\t--net: net name (e.g. tcp0)\n"
150 "\t--if: physical interface (e.g. eth0)\n"},
151 {"show", jt_show_net, 0, "show networks\n"
152 "\t--net: net name (e.g. tcp0) to filter on\n"
153 "\t--verbose: display detailed output per network."
154 " Optional argument of '2' outputs more stats\n"},
155 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
156 "\t--nid: NI NID to set the\n"
157 "\t--health: specify health value to set\n"
158 "\t--all: set all NIs value to the one specified\n"},
162 command_t routing_cmds[] = {
163 {"show", jt_show_routing, 0, "show routing information\n"},
167 command_t stats_cmds[] = {
168 {"show", jt_show_stats, 0, "show LNET statistics\n"},
172 command_t debug_cmds[] = {
173 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
174 "\t--local : list local recovery queue\n"
175 "\t--peer : list peer recovery queue\n"},
179 command_t global_cmds[] = {
180 {"show", jt_show_global, 0, "show global variables\n"},
184 command_t set_cmds[] = {
185 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
186 "\tVALUE must be greater than 0\n"},
187 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
188 "\tVALUE must be greater than 0\n"},
189 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
190 "\tVALUE must be greater than 0\n"},
191 {"routing", jt_set_routing, 0, "enable/disable routing\n"
192 "\t0 - disable routing\n"
193 "\t1 - enable routing\n"},
194 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
195 "\tVALUE must be at least 0\n"},
196 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
198 "\tValue must be greater than 16\n"},
199 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
200 "\t0 - disable peer discovery\n"
201 "\t1 - enable peer discovery (default)\n"},
202 {"drop_asym_route", jt_set_drop_asym_route, 0,
203 "drop/accept asymmetrical route messages\n"
204 "\t0 - accept asymmetrical route messages (default)\n"
205 "\t1 - drop asymmetrical route messages\n"},
206 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
207 "\t0 - turn of retries\n"
208 "\t>0 - number of retries\n"},
209 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
210 "\t>0 - timeout in seconds\n"},
211 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
212 "\t0 - turn off health evaluation\n"
213 "\t>0 - sensitivity value not more than 1000\n"},
214 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
215 "\t>0 - time in seconds between pings\n"},
216 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
217 "\t100 - router interfaces need to be fully healthy to be used\n"
218 "\t<100 - router interfaces can be used even if not healthy\n"},
222 command_t peer_cmds[] = {
223 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
224 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
225 "\t NID in the list becomes the Primary NID of a newly created\n"
227 "\t--nid: one or more peer NIDs\n"
228 "\t--non_mr: create this peer as not Multi-Rail capable\n"
229 "\t--ip2nets: specify a range of nids per peer"},
230 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
231 "\t--prim_nid: Primary NID of the peer.\n"
232 "\t--nid: list of NIDs to remove. If none provided,\n"
233 "\t peer is deleted\n"
234 "\t--ip2nets: specify a range of nids per peer"},
235 {"show", jt_show_peer, 0, "show peer information\n"
236 "\t--nid: NID of peer to filter on.\n"
237 "\t--verbose: display detailed output per peer."
238 " Optional argument of '2' outputs more stats\n"},
239 {"list", jt_list_peer, 0, "list all peers\n"},
240 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
241 "\t--nid: Peer NI NID to set the\n"
242 "\t--health: specify health value to set\n"
243 "\t--all: set all peer_nis values to the one specified\n"},
247 static int jt_calc_service_id(int argc, char **argv)
252 rc = lustre_lnet_calc_service_id(&service_id);
253 if (rc != LUSTRE_CFG_RC_NO_ERR)
257 * cYAML currently doesn't support printing hex values.
258 * Therefore just print it locally here
260 printf("service id:\n value: 0x%llx\n", service_id);
265 static inline void print_help(const command_t cmds[], const char *cmd_type,
268 const command_t *cmd;
270 for (cmd = cmds; cmd->pc_name; cmd++) {
271 if (pc_name != NULL &&
272 strcmp(cmd->pc_name, pc_name) == 0) {
273 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
276 } else if (pc_name != NULL) {
279 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
283 static int parse_long(const char *number, long int *value)
290 *value = strtol(number, &end, 0);
291 if (end != NULL && *end != 0)
297 static int check_cmd(const command_t *cmd_list, const char *cmd,
298 const char *sub_cmd, const int min_args,
299 int argc, char **argv)
306 const char *const short_options = "h";
307 static const struct option long_options[] = {
308 { .name = "help", .has_arg = no_argument, .val = 'h' },
312 if (argc < min_args) {
313 print_help(cmd_list, cmd, sub_cmd);
316 } else if (argc > 2) {
320 while ((opt = getopt_long(argc, argv, short_options,
321 long_options, NULL)) != -1) {
324 print_help(cmd_list, cmd, sub_cmd);
339 static int jt_set_max_intf(int argc, char **argv)
343 struct cYAML *err_rc = NULL;
345 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
349 rc = parse_long(argv[1], &value);
351 cYAML_build_error(-1, -1, "parser", "set",
352 "cannot parse max_interfaces value", &err_rc);
353 cYAML_print_tree2file(stderr, err_rc);
354 cYAML_free_tree(err_rc);
358 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
359 if (rc != LUSTRE_CFG_RC_NO_ERR)
360 cYAML_print_tree2file(stderr, err_rc);
362 cYAML_free_tree(err_rc);
367 static int jt_set_numa(int argc, char **argv)
371 struct cYAML *err_rc = NULL;
373 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
377 rc = parse_long(argv[1], &value);
379 cYAML_build_error(-1, -1, "parser", "set",
380 "cannot parse numa_range value", &err_rc);
381 cYAML_print_tree2file(stderr, err_rc);
382 cYAML_free_tree(err_rc);
386 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
387 if (rc != LUSTRE_CFG_RC_NO_ERR)
388 cYAML_print_tree2file(stderr, err_rc);
390 cYAML_free_tree(err_rc);
395 static int jt_set_recov_intrv(int argc, char **argv)
399 struct cYAML *err_rc = NULL;
401 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
405 rc = parse_long(argv[1], &value);
407 cYAML_build_error(-1, -1, "parser", "set",
408 "cannot parse recovery interval value", &err_rc);
409 cYAML_print_tree2file(stderr, err_rc);
410 cYAML_free_tree(err_rc);
414 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
415 if (rc != LUSTRE_CFG_RC_NO_ERR)
416 cYAML_print_tree2file(stderr, err_rc);
418 cYAML_free_tree(err_rc);
423 static int jt_set_rtr_sensitivity(int argc, char **argv)
427 struct cYAML *err_rc = NULL;
429 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
433 rc = parse_long(argv[1], &value);
435 cYAML_build_error(-1, -1, "parser", "set",
436 "cannot parse router sensitivity value", &err_rc);
437 cYAML_print_tree2file(stderr, err_rc);
438 cYAML_free_tree(err_rc);
442 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
443 if (rc != LUSTRE_CFG_RC_NO_ERR)
444 cYAML_print_tree2file(stderr, err_rc);
446 cYAML_free_tree(err_rc);
451 static int jt_set_hsensitivity(int argc, char **argv)
455 struct cYAML *err_rc = NULL;
457 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
461 rc = parse_long(argv[1], &value);
463 cYAML_build_error(-1, -1, "parser", "set",
464 "cannot parse health sensitivity value", &err_rc);
465 cYAML_print_tree2file(stderr, err_rc);
466 cYAML_free_tree(err_rc);
470 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
471 if (rc != LUSTRE_CFG_RC_NO_ERR)
472 cYAML_print_tree2file(stderr, err_rc);
474 cYAML_free_tree(err_rc);
479 static int jt_set_transaction_to(int argc, char **argv)
483 struct cYAML *err_rc = NULL;
485 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
489 rc = parse_long(argv[1], &value);
491 cYAML_build_error(-1, -1, "parser", "set",
492 "cannot parse transaction timeout value", &err_rc);
493 cYAML_print_tree2file(stderr, err_rc);
494 cYAML_free_tree(err_rc);
498 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
499 if (rc != LUSTRE_CFG_RC_NO_ERR)
500 cYAML_print_tree2file(stderr, err_rc);
502 cYAML_free_tree(err_rc);
507 static int jt_set_retry_count(int argc, char **argv)
511 struct cYAML *err_rc = NULL;
513 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
517 rc = parse_long(argv[1], &value);
519 cYAML_build_error(-1, -1, "parser", "set",
520 "cannot parse retry_count value", &err_rc);
521 cYAML_print_tree2file(stderr, err_rc);
522 cYAML_free_tree(err_rc);
526 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
527 if (rc != LUSTRE_CFG_RC_NO_ERR)
528 cYAML_print_tree2file(stderr, err_rc);
530 cYAML_free_tree(err_rc);
535 static int jt_set_discovery(int argc, char **argv)
539 struct cYAML *err_rc = NULL;
541 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
545 rc = parse_long(argv[1], &value);
547 cYAML_build_error(-1, -1, "parser", "set",
548 "cannot parse discovery value", &err_rc);
549 cYAML_print_tree2file(stderr, err_rc);
550 cYAML_free_tree(err_rc);
554 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
555 if (rc != LUSTRE_CFG_RC_NO_ERR)
556 cYAML_print_tree2file(stderr, err_rc);
558 cYAML_free_tree(err_rc);
563 static int jt_set_drop_asym_route(int argc, char **argv)
567 struct cYAML *err_rc = NULL;
569 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
573 rc = parse_long(argv[1], &value);
575 cYAML_build_error(-1, -1, "parser", "set",
576 "cannot parse drop_asym_route value",
578 cYAML_print_tree2file(stderr, err_rc);
579 cYAML_free_tree(err_rc);
583 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
584 if (rc != LUSTRE_CFG_RC_NO_ERR)
585 cYAML_print_tree2file(stderr, err_rc);
587 cYAML_free_tree(err_rc);
592 static int jt_set_tiny(int argc, char **argv)
596 struct cYAML *err_rc = NULL;
598 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
602 rc = parse_long(argv[1], &value);
604 cYAML_build_error(-1, -1, "parser", "set",
605 "cannot parse tiny_buffers value", &err_rc);
606 cYAML_print_tree2file(stderr, err_rc);
607 cYAML_free_tree(err_rc);
611 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
612 if (rc != LUSTRE_CFG_RC_NO_ERR)
613 cYAML_print_tree2file(stderr, err_rc);
615 cYAML_free_tree(err_rc);
620 static int jt_set_small(int argc, char **argv)
624 struct cYAML *err_rc = NULL;
626 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
630 rc = parse_long(argv[1], &value);
632 cYAML_build_error(-1, -1, "parser", "set",
633 "cannot parse small_buffers value", &err_rc);
634 cYAML_print_tree2file(stderr, err_rc);
635 cYAML_free_tree(err_rc);
639 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
640 if (rc != LUSTRE_CFG_RC_NO_ERR)
641 cYAML_print_tree2file(stderr, err_rc);
643 cYAML_free_tree(err_rc);
648 static int jt_set_large(int argc, char **argv)
652 struct cYAML *err_rc = NULL;
654 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
658 rc = parse_long(argv[1], &value);
660 cYAML_build_error(-1, -1, "parser", "set",
661 "cannot parse large_buffers value", &err_rc);
662 cYAML_print_tree2file(stderr, err_rc);
663 cYAML_free_tree(err_rc);
667 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
668 if (rc != LUSTRE_CFG_RC_NO_ERR)
669 cYAML_print_tree2file(stderr, err_rc);
671 cYAML_free_tree(err_rc);
676 static int jt_set_routing(int argc, char **argv)
679 struct cYAML *err_rc = NULL;
682 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
686 rc = parse_long(argv[1], &value);
687 if (rc != 0 || (value != 0 && value != 1)) {
688 cYAML_build_error(-1, -1, "parser", "set",
689 "cannot parse routing value.\n"
690 "must be 0 for disable or 1 for enable",
692 cYAML_print_tree2file(stderr, err_rc);
693 cYAML_free_tree(err_rc);
697 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
699 if (rc != LUSTRE_CFG_RC_NO_ERR)
700 cYAML_print_tree2file(stderr, err_rc);
702 cYAML_free_tree(err_rc);
707 static int jt_config_lnet(int argc, char **argv)
709 struct cYAML *err_rc = NULL;
710 bool load_mod_params = false;
713 const char *const short_options = "a";
714 static const struct option long_options[] = {
715 { .name = "all", .has_arg = no_argument, .val = 'a' },
719 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
723 while ((opt = getopt_long(argc, argv, short_options,
724 long_options, NULL)) != -1) {
727 load_mod_params = true;
734 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
737 if (rc != LUSTRE_CFG_RC_NO_ERR)
738 cYAML_print_tree2file(stderr, err_rc);
740 cYAML_free_tree(err_rc);
745 static int jt_unconfig_lnet(int argc, char **argv)
747 struct cYAML *err_rc = NULL;
750 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
754 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
756 if (rc != LUSTRE_CFG_RC_NO_ERR)
757 cYAML_print_tree2file(stderr, err_rc);
759 cYAML_free_tree(err_rc);
763 static int jt_add_route(int argc, char **argv)
765 char *network = NULL, *gateway = NULL;
766 long int hop = -1, prio = -1, sen = -1;
767 struct cYAML *err_rc = NULL;
770 const char *const short_options = "n:g:c:p:";
771 static const struct option long_options[] = {
772 { .name = "net", .has_arg = required_argument, .val = 'n' },
773 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
774 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
775 { .name = "priority", .has_arg = required_argument, .val = 'p' },
776 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
779 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
783 while ((opt = getopt_long(argc, argv, short_options,
784 long_options, NULL)) != -1) {
793 rc = parse_long(optarg, &hop);
801 rc = parse_long(optarg, &prio);
809 rc = parse_long(optarg, &sen);
818 print_help(route_cmds, "route", "add");
824 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
827 if (rc != LUSTRE_CFG_RC_NO_ERR)
828 cYAML_print_tree2file(stderr, err_rc);
830 cYAML_free_tree(err_rc);
835 static int jt_add_ni(int argc, char **argv)
838 long int pto = -1, pc = -1, pbc = -1, cre = -1;
839 struct cYAML *err_rc = NULL;
840 int rc, opt, cpt_rc = -1;
841 struct lnet_dlc_network_descr nw_descr;
842 struct cfs_expr_list *global_cpts = NULL;
843 struct lnet_ioctl_config_lnd_tunables tunables;
846 memset(&tunables, 0, sizeof(tunables));
847 lustre_lnet_init_nw_descr(&nw_descr);
849 const char *const short_options = "n:i:p:t:c:b:r:s:";
850 static const struct option long_options[] = {
851 { .name = "net", .has_arg = required_argument, .val = 'n' },
852 { .name = "if", .has_arg = required_argument, .val = 'i' },
853 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
854 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
855 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
856 { .name = "peer-buffer-credits",
857 .has_arg = required_argument, .val = 'b' },
858 { .name = "credits", .has_arg = required_argument, .val = 'r' },
859 { .name = "cpt", .has_arg = required_argument, .val = 's' },
862 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
866 while ((opt = getopt_long(argc, argv, short_options,
867 long_options, NULL)) != -1) {
870 nw_descr.nw_id = libcfs_str2net(optarg);
873 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
875 cYAML_build_error(-1, -1, "ni", "add",
876 "bad interface list",
885 rc = parse_long(optarg, &pto);
893 rc = parse_long(optarg, &pc);
901 rc = parse_long(optarg, &pbc);
909 rc = parse_long(optarg, &cre);
917 cpt_rc = cfs_expr_list_parse(optarg,
919 UINT_MAX, &global_cpts);
922 print_help(net_cmds, "net", "add");
928 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
929 tunables.lt_cmn.lct_peer_timeout = pto;
930 tunables.lt_cmn.lct_peer_tx_credits = pc;
931 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
932 tunables.lt_cmn.lct_max_tx_credits = cre;
936 rc = lustre_lnet_config_ni(&nw_descr,
937 (cpt_rc == 0) ? global_cpts: NULL,
938 ip2net, (found) ? &tunables : NULL,
941 if (global_cpts != NULL)
942 cfs_expr_list_free(global_cpts);
945 if (rc != LUSTRE_CFG_RC_NO_ERR)
946 cYAML_print_tree2file(stderr, err_rc);
948 cYAML_free_tree(err_rc);
953 static int jt_del_route(int argc, char **argv)
955 char *network = NULL, *gateway = NULL;
956 struct cYAML *err_rc = NULL;
959 const char *const short_options = "n:g:";
960 static const struct option long_options[] = {
961 { .name = "net", .has_arg = required_argument, .val = 'n' },
962 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
965 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
969 while ((opt = getopt_long(argc, argv, short_options,
970 long_options, NULL)) != -1) {
979 print_help(route_cmds, "route", "del");
985 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
987 if (rc != LUSTRE_CFG_RC_NO_ERR)
988 cYAML_print_tree2file(stderr, err_rc);
990 cYAML_free_tree(err_rc);
995 static int jt_del_ni(int argc, char **argv)
997 struct cYAML *err_rc = NULL;
999 struct lnet_dlc_network_descr nw_descr;
1001 lustre_lnet_init_nw_descr(&nw_descr);
1003 const char *const short_options = "n:i:";
1004 static const struct option long_options[] = {
1005 { .name = "net", .has_arg = required_argument, .val = 'n' },
1006 { .name = "if", .has_arg = required_argument, .val = 'i' },
1009 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1013 while ((opt = getopt_long(argc, argv, short_options,
1014 long_options, NULL)) != -1) {
1017 nw_descr.nw_id = libcfs_str2net(optarg);
1020 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1022 cYAML_build_error(-1, -1, "ni", "add",
1023 "bad interface list",
1029 print_help(net_cmds, "net", "del");
1035 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1038 if (rc != LUSTRE_CFG_RC_NO_ERR)
1039 cYAML_print_tree2file(stderr, err_rc);
1041 cYAML_free_tree(err_rc);
1046 static int jt_show_route(int argc, char **argv)
1048 char *network = NULL, *gateway = NULL;
1049 long int hop = -1, prio = -1;
1050 int detail = 0, rc, opt;
1051 struct cYAML *err_rc = NULL, *show_rc = NULL;
1053 const char *const short_options = "n:g:h:p:v";
1054 static const struct option long_options[] = {
1055 { .name = "net", .has_arg = required_argument, .val = 'n' },
1056 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1057 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1058 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1059 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1062 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1066 while ((opt = getopt_long(argc, argv, short_options,
1067 long_options, NULL)) != -1) {
1076 rc = parse_long(optarg, &hop);
1084 rc = parse_long(optarg, &prio);
1095 print_help(route_cmds, "route", "show");
1101 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1102 &show_rc, &err_rc, false);
1104 if (rc != LUSTRE_CFG_RC_NO_ERR)
1105 cYAML_print_tree2file(stderr, err_rc);
1107 cYAML_print_tree(show_rc);
1109 cYAML_free_tree(err_rc);
1110 cYAML_free_tree(show_rc);
1115 static int set_value_helper(int argc, char **argv,
1116 int (*cb)(int, bool, char*, int, struct cYAML**))
1119 long int healthv = -1;
1122 struct cYAML *err_rc = NULL;
1124 const char *const short_options = "t:n:a";
1125 static const struct option long_options[] = {
1126 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1127 { .name = "health", .has_arg = required_argument, .val = 't' },
1128 { .name = "all", .has_arg = no_argument, .val = 'a' },
1131 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1135 while ((opt = getopt_long(argc, argv, short_options,
1136 long_options, NULL)) != -1) {
1142 if (parse_long(optarg, &healthv) != 0)
1153 rc = cb(healthv, all, nid, -1, &err_rc);
1155 if (rc != LUSTRE_CFG_RC_NO_ERR)
1156 cYAML_print_tree2file(stderr, err_rc);
1158 cYAML_free_tree(err_rc);
1163 static int jt_set_ni_value(int argc, char **argv)
1165 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1168 static int jt_set_peer_ni_value(int argc, char **argv)
1170 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1173 static int jt_show_recovery(int argc, char **argv)
1176 struct cYAML *err_rc = NULL, *show_rc = NULL;
1178 const char *const short_options = "lp";
1179 static const struct option long_options[] = {
1180 { .name = "local", .has_arg = no_argument, .val = 'l' },
1181 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1184 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1188 while ((opt = getopt_long(argc, argv, short_options,
1189 long_options, NULL)) != -1) {
1192 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1195 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1202 if (rc != LUSTRE_CFG_RC_NO_ERR)
1203 cYAML_print_tree2file(stderr, err_rc);
1205 cYAML_print_tree(show_rc);
1207 cYAML_free_tree(err_rc);
1208 cYAML_free_tree(show_rc);
1213 static int jt_show_net(int argc, char **argv)
1215 char *network = NULL;
1217 struct cYAML *err_rc = NULL, *show_rc = NULL;
1218 long int detail = 0;
1220 const char *const short_options = "n:v";
1221 static const struct option long_options[] = {
1222 { .name = "net", .has_arg = required_argument, .val = 'n' },
1223 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1226 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1230 while ((opt = getopt_long(argc, argv, short_options,
1231 long_options, NULL)) != -1) {
1237 if ((!optarg) && (argv[optind] != NULL) &&
1238 (argv[optind][0] != '-')) {
1239 if (parse_long(argv[optind++], &detail) != 0)
1246 print_help(net_cmds, "net", "show");
1252 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1255 if (rc != LUSTRE_CFG_RC_NO_ERR)
1256 cYAML_print_tree2file(stderr, err_rc);
1258 cYAML_print_tree(show_rc);
1260 cYAML_free_tree(err_rc);
1261 cYAML_free_tree(show_rc);
1266 static int jt_show_routing(int argc, char **argv)
1268 struct cYAML *err_rc = NULL, *show_rc = NULL;
1271 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1275 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1277 if (rc != LUSTRE_CFG_RC_NO_ERR)
1278 cYAML_print_tree2file(stderr, err_rc);
1280 cYAML_print_tree(show_rc);
1282 cYAML_free_tree(err_rc);
1283 cYAML_free_tree(show_rc);
1288 static int jt_show_stats(int argc, char **argv)
1291 struct cYAML *show_rc = NULL, *err_rc = NULL;
1293 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1297 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1299 if (rc != LUSTRE_CFG_RC_NO_ERR)
1300 cYAML_print_tree2file(stderr, err_rc);
1302 cYAML_print_tree(show_rc);
1304 cYAML_free_tree(err_rc);
1305 cYAML_free_tree(show_rc);
1310 static int jt_show_global(int argc, char **argv)
1313 struct cYAML *show_rc = NULL, *err_rc = NULL;
1315 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1319 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1320 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1321 cYAML_print_tree2file(stderr, err_rc);
1325 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1326 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1327 cYAML_print_tree2file(stderr, err_rc);
1331 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1332 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1333 cYAML_print_tree2file(stderr, err_rc);
1337 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1338 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1339 cYAML_print_tree2file(stderr, err_rc);
1343 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1344 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1345 cYAML_print_tree2file(stderr, err_rc);
1349 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1350 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1351 cYAML_print_tree2file(stderr, err_rc);
1355 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1356 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1357 cYAML_print_tree2file(stderr, err_rc);
1361 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1362 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1363 cYAML_print_tree2file(stderr, err_rc);
1367 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1368 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1369 cYAML_print_tree2file(stderr, err_rc);
1374 cYAML_print_tree(show_rc);
1377 cYAML_free_tree(err_rc);
1378 cYAML_free_tree(show_rc);
1383 static int jt_lnet(int argc, char **argv)
1387 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1391 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1394 static int jt_route(int argc, char **argv)
1398 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1402 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1405 static int jt_net(int argc, char **argv)
1409 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1413 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1416 static int jt_routing(int argc, char **argv)
1420 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1424 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1427 static int jt_stats(int argc, char **argv)
1431 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1435 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1438 static int jt_debug(int argc, char **argv)
1442 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1446 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1449 static int jt_global(int argc, char **argv)
1453 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1457 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1460 static int jt_peers(int argc, char **argv)
1464 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1468 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1471 static int jt_set(int argc, char **argv)
1475 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1479 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1482 static int jt_import(int argc, char **argv)
1485 struct cYAML *err_rc = NULL;
1486 struct cYAML *show_rc = NULL;
1487 int rc = 0, return_rc = 0, opt, opt_found = 0;
1490 const char *const short_options = "adseh";
1491 static const struct option long_options[] = {
1492 { .name = "add", .has_arg = no_argument, .val = 'a' },
1493 { .name = "del", .has_arg = no_argument, .val = 'd' },
1494 { .name = "show", .has_arg = no_argument, .val = 's' },
1495 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1496 { .name = "help", .has_arg = no_argument, .val = 'h' },
1499 while ((opt = getopt_long(argc, argv, short_options,
1500 long_options, NULL)) != -1) {
1514 printf("import FILE\n"
1515 "import < FILE : import a file\n"
1516 "\t--add: add configuration\n"
1517 "\t--del: delete configuration\n"
1518 "\t--show: show configuration\n"
1519 "\t--exec: execute command\n"
1520 "\t--help: display this help\n"
1521 "If no command option is given then --add"
1522 " is assumed by default\n");
1529 /* grab the file name if one exists */
1530 if (opt_found && argc == 3)
1532 else if (!opt_found && argc == 2)
1537 rc = lustre_yaml_config(file, &err_rc);
1538 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1539 cYAML_print_tree(show_rc);
1540 cYAML_free_tree(show_rc);
1543 rc = lustre_yaml_del(file, &err_rc);
1546 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1547 cYAML_print_tree(show_rc);
1548 cYAML_free_tree(show_rc);
1551 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1552 cYAML_print_tree(show_rc);
1553 cYAML_free_tree(show_rc);
1557 if (rc || return_rc) {
1558 cYAML_print_tree2file(stderr, err_rc);
1559 cYAML_free_tree(err_rc);
1565 static int jt_export(int argc, char **argv)
1567 struct cYAML *show_rc = NULL;
1568 struct cYAML *err_rc = NULL;
1572 bool backup = false;
1575 const char *const short_options = "bh";
1576 static const struct option long_options[] = {
1577 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1578 { .name = "help", .has_arg = no_argument, .val = 'h' },
1581 while ((opt = getopt_long(argc, argv, short_options,
1582 long_options, NULL)) != -1) {
1589 printf("export > FILE.yaml : export configuration\n"
1590 "\t--backup: export only what's necessary for reconfig\n"
1591 "\t--help: display this help\n");
1596 if (backup && argc >= 3)
1598 else if (!backup && argc >= 2)
1604 f = fopen(file, "w");
1609 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1610 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1611 cYAML_print_tree2file(stderr, err_rc);
1612 cYAML_free_tree(err_rc);
1616 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1618 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1619 cYAML_print_tree2file(stderr, err_rc);
1620 cYAML_free_tree(err_rc);
1624 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1625 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1626 cYAML_print_tree2file(stderr, err_rc);
1627 cYAML_free_tree(err_rc);
1631 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1632 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1633 cYAML_print_tree2file(stderr, err_rc);
1634 cYAML_free_tree(err_rc);
1638 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1639 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1640 cYAML_print_tree2file(stderr, err_rc);
1641 cYAML_free_tree(err_rc);
1645 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1646 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1647 cYAML_print_tree2file(stderr, err_rc);
1648 cYAML_free_tree(err_rc);
1652 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1653 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1654 cYAML_print_tree2file(stderr, err_rc);
1655 cYAML_free_tree(err_rc);
1659 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1660 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1661 cYAML_print_tree2file(stderr, err_rc);
1662 cYAML_free_tree(err_rc);
1666 if (show_rc != NULL) {
1667 cYAML_print_tree2file(f, show_rc);
1668 cYAML_free_tree(show_rc);
1677 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1679 int rc = LUSTRE_CFG_RC_NO_ERR, opt, num_nids, num_nidstrs, i;
1681 char *prim_nid = NULL, *nidstr = NULL;
1682 char err_str[LNET_MAX_STR_LEN] = "Error";
1683 char *nidstrarray[LNET_MAX_STR_LEN];
1684 struct cYAML *err_rc = NULL;
1685 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
1687 const char *const short_opts = "k:mn:";
1688 const struct option long_opts[] = {
1689 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1690 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1691 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1694 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1698 while ((opt = getopt_long(argc, argv, short_opts,
1699 long_opts, NULL)) != -1) {
1708 if (cmd == LNETCTL_DEL_CMD) {
1709 rc = LUSTRE_CFG_RC_BAD_PARAM;
1710 snprintf(err_str, LNET_MAX_STR_LEN,
1711 "Unrecognized option '-%c'", opt);
1717 print_help(peer_cmds, "peer",
1718 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1724 if (!(nidstr || prim_nid)) {
1725 rc = LUSTRE_CFG_RC_BAD_PARAM;
1726 snprintf(err_str, LNET_MAX_STR_LEN,
1727 "--prim_nid or --nid (or both) must be specified");
1732 /* We were only provided a primary nid */
1734 if (cmd == LNETCTL_ADD_CMD)
1735 rc = lustre_lnet_config_peer_nidlist(prim_nid,
1740 rc = lustre_lnet_del_peer_nidlist(prim_nid,
1748 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
1754 for (i = 0; i < num_nidstrs; i++) {
1755 rc = lustre_lnet_parse_nidstr(nidstrarray[i], lnet_nidlist,
1756 LNET_MAX_NIDS_PER_PEER, err_str);
1762 if (cmd == LNETCTL_ADD_CMD)
1763 rc = lustre_lnet_config_peer_nidlist(prim_nid,
1768 rc = lustre_lnet_del_peer_nidlist(prim_nid,
1775 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1776 cYAML_build_error(rc, -1, "peer",
1777 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1779 cYAML_print_tree2file(stderr, err_rc);
1782 cYAML_free_tree(err_rc);
1787 static int jt_add_peer_nid(int argc, char **argv)
1789 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1792 static int jt_del_peer_nid(int argc, char **argv)
1794 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1797 static int jt_show_peer(int argc, char **argv)
1801 struct cYAML *err_rc = NULL, *show_rc = NULL;
1802 long int detail = 0;
1804 const char *const short_opts = "hn:v::";
1805 const struct option long_opts[] = {
1806 { .name = "help", .has_arg = no_argument, .val = 'h' },
1807 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1808 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1811 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1815 while ((opt = getopt_long(argc, argv, short_opts,
1816 long_opts, NULL)) != -1) {
1822 if ((!optarg) && (argv[optind] != NULL) &&
1823 (argv[optind][0] != '-')) {
1824 if (parse_long(argv[optind++], &detail) != 0)
1831 print_help(peer_cmds, "peer", "show");
1837 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1840 if (rc != LUSTRE_CFG_RC_NO_ERR)
1841 cYAML_print_tree2file(stderr, err_rc);
1843 cYAML_print_tree(show_rc);
1845 cYAML_free_tree(err_rc);
1846 cYAML_free_tree(show_rc);
1851 static int jt_list_peer(int argc, char **argv)
1854 struct cYAML *err_rc = NULL, *list_rc = NULL;
1856 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1860 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1862 if (rc != LUSTRE_CFG_RC_NO_ERR)
1863 cYAML_print_tree2file(stderr, err_rc);
1865 cYAML_print_tree(list_rc);
1867 cYAML_free_tree(err_rc);
1868 cYAML_free_tree(list_rc);
1873 static int jt_ping(int argc, char **argv)
1875 struct cYAML *err_rc = NULL;
1876 struct cYAML *show_rc = NULL;
1880 const char *const short_options = "ht:";
1881 const struct option long_options[] = {
1882 { .name = "help", .has_arg = no_argument, .val = 'h' },
1883 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1886 while ((opt = getopt_long(argc, argv, short_options,
1887 long_options, NULL)) != -1) {
1890 timeout = 1000 * atol(optarg);
1893 printf("ping nid[,nid,...]\n"
1894 "\t --timeout: ping timeout\n"
1895 "\t --help: display this help\n");
1902 for (; optind < argc; optind++)
1903 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1906 cYAML_print_tree(show_rc);
1909 cYAML_print_tree2file(stderr, err_rc);
1911 cYAML_free_tree(err_rc);
1912 cYAML_free_tree(show_rc);
1917 static int jt_discover(int argc, char **argv)
1919 struct cYAML *err_rc = NULL;
1920 struct cYAML *show_rc = NULL;
1924 const char *const short_options = "fh";
1925 const struct option long_options[] = {
1926 { .name = "force", .has_arg = no_argument, .val = 'f' },
1927 { .name = "help", .has_arg = no_argument, .val = 'h' },
1930 while ((opt = getopt_long(argc, argv, short_options,
1931 long_options, NULL)) != -1) {
1937 printf("discover nid[,nid,...]\n"
1938 "\t --force: force discovery\n"
1939 "\t --help: display this help\n");
1946 for (; optind < argc; optind++)
1947 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1951 cYAML_print_tree(show_rc);
1954 cYAML_print_tree2file(stderr, err_rc);
1956 cYAML_free_tree(err_rc);
1957 cYAML_free_tree(show_rc);
1962 static int lnetctl_list_commands(int argc, char **argv)
1964 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1966 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1971 int main(int argc, char **argv)
1974 struct cYAML *err_rc = NULL;
1976 rc = lustre_lnet_config_lib_init();
1978 cYAML_build_error(-1, -1, "lnetctl", "startup",
1979 "cannot register LNet device", &err_rc);
1980 cYAML_print_tree2file(stderr, err_rc);
1984 Parser_init("lnetctl > ", cmd_list);
1986 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);