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 {"del", jt_del_route, 0, "delete a route\n"
123 "\t--net: net name (e.g. tcp0)\n"
124 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
125 {"show", jt_show_route, 0, "show routes\n"
126 "\t--net: net name (e.g. tcp0) to filter on\n"
127 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
128 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
129 "\t--priority: priority of route (0 - highest prio to filter on\n"
130 "\t--verbose: display detailed output per route\n"},
134 command_t net_cmds[] = {
135 {"add", jt_add_ni, 0, "add a network\n"
136 "\t--net: net name (e.g. tcp0)\n"
137 "\t--if: physical interface (e.g. eth0)\n"
138 "\t--ip2net: specify networks based on IP address patterns\n"
139 "\t--peer-timeout: time to wait before declaring a peer dead\n"
140 "\t--peer-credits: define the max number of inflight messages\n"
141 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
142 "\t--credits: Network Interface credits\n"
143 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
144 {"del", jt_del_ni, 0, "delete a network\n"
145 "\t--net: net name (e.g. tcp0)\n"
146 "\t--if: physical interface (e.g. eth0)\n"},
147 {"show", jt_show_net, 0, "show networks\n"
148 "\t--net: net name (e.g. tcp0) to filter on\n"
149 "\t--verbose: display detailed output per network."
150 " Optional argument of '2' outputs more stats\n"},
151 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
152 "\t--nid: NI NID to set the\n"
153 "\t--health: specify health value to set\n"
154 "\t--all: set all NIs value to the one specified\n"},
158 command_t routing_cmds[] = {
159 {"show", jt_show_routing, 0, "show routing information\n"},
163 command_t stats_cmds[] = {
164 {"show", jt_show_stats, 0, "show LNET statistics\n"},
168 command_t debug_cmds[] = {
169 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
170 "\t--local : list local recovery queue\n"
171 "\t--peer : list peer recovery queue\n"},
175 command_t global_cmds[] = {
176 {"show", jt_show_global, 0, "show global variables\n"},
180 command_t set_cmds[] = {
181 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
182 "\tVALUE must be greater than 0\n"},
183 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
184 "\tVALUE must be greater than 0\n"},
185 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
186 "\tVALUE must be greater than 0\n"},
187 {"routing", jt_set_routing, 0, "enable/disable routing\n"
188 "\t0 - disable routing\n"
189 "\t1 - enable routing\n"},
190 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
191 "\tVALUE must be at least 0\n"},
192 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
194 "\tValue must be greater than 16\n"},
195 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
196 "\t0 - disable peer discovery\n"
197 "\t1 - enable peer discovery (default)\n"},
198 {"drop_asym_route", jt_set_drop_asym_route, 0,
199 "drop/accept asymmetrical route messages\n"
200 "\t0 - accept asymmetrical route messages (default)\n"
201 "\t1 - drop asymmetrical route messages\n"},
202 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
203 "\t0 - turn of retries\n"
204 "\t>0 - number of retries\n"},
205 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
206 "\t>0 - timeout in seconds\n"},
207 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
208 "\t0 - turn off health evaluation\n"
209 "\t>0 - sensitivity value not more than 1000\n"},
210 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
211 "\t>0 - time in seconds between pings\n"},
212 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
213 "\t100 - router interfaces need to be fully healthy to be used\n"
214 "\t<100 - router interfaces can be used even if not healthy\n"},
218 command_t peer_cmds[] = {
219 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
220 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
221 "\t NID in the list becomes the Primary NID of a newly created\n"
223 "\t--nid: one or more peer NIDs\n"
224 "\t--non_mr: create this peer as not Multi-Rail capable\n"
225 "\t--ip2nets: specify a range of nids per peer"},
226 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
227 "\t--prim_nid: Primary NID of the peer.\n"
228 "\t--nid: list of NIDs to remove. If none provided,\n"
229 "\t peer is deleted\n"
230 "\t--ip2nets: specify a range of nids per peer"},
231 {"show", jt_show_peer, 0, "show peer information\n"
232 "\t--nid: NID of peer to filter on.\n"
233 "\t--verbose: display detailed output per peer."
234 " Optional argument of '2' outputs more stats\n"},
235 {"list", jt_list_peer, 0, "list all peers\n"},
236 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
237 "\t--nid: Peer NI NID to set the\n"
238 "\t--health: specify health value to set\n"
239 "\t--all: set all peer_nis values to the one specified\n"},
243 static inline void print_help(const command_t cmds[], const char *cmd_type,
246 const command_t *cmd;
248 for (cmd = cmds; cmd->pc_name; cmd++) {
249 if (pc_name != NULL &&
250 strcmp(cmd->pc_name, pc_name) == 0) {
251 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
254 } else if (pc_name != NULL) {
257 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
261 static int parse_long(const char *number, long int *value)
268 *value = strtol(number, &end, 0);
269 if (end != NULL && *end != 0)
275 static int check_cmd(const command_t *cmd_list, const char *cmd,
276 const char *sub_cmd, const int min_args,
277 int argc, char **argv)
284 const char *const short_options = "h";
285 static const struct option long_options[] = {
286 { .name = "help", .has_arg = no_argument, .val = 'h' },
290 if (argc < min_args) {
291 print_help(cmd_list, cmd, sub_cmd);
294 } else if (argc > 2) {
298 while ((opt = getopt_long(argc, argv, short_options,
299 long_options, NULL)) != -1) {
302 print_help(cmd_list, cmd, sub_cmd);
317 static int jt_set_max_intf(int argc, char **argv)
321 struct cYAML *err_rc = NULL;
323 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
327 rc = parse_long(argv[1], &value);
329 cYAML_build_error(-1, -1, "parser", "set",
330 "cannot parse max_interfaces value", &err_rc);
331 cYAML_print_tree2file(stderr, err_rc);
332 cYAML_free_tree(err_rc);
336 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
337 if (rc != LUSTRE_CFG_RC_NO_ERR)
338 cYAML_print_tree2file(stderr, err_rc);
340 cYAML_free_tree(err_rc);
345 static int jt_set_numa(int argc, char **argv)
349 struct cYAML *err_rc = NULL;
351 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
355 rc = parse_long(argv[1], &value);
357 cYAML_build_error(-1, -1, "parser", "set",
358 "cannot parse numa_range value", &err_rc);
359 cYAML_print_tree2file(stderr, err_rc);
360 cYAML_free_tree(err_rc);
364 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
365 if (rc != LUSTRE_CFG_RC_NO_ERR)
366 cYAML_print_tree2file(stderr, err_rc);
368 cYAML_free_tree(err_rc);
373 static int jt_set_recov_intrv(int argc, char **argv)
377 struct cYAML *err_rc = NULL;
379 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
383 rc = parse_long(argv[1], &value);
385 cYAML_build_error(-1, -1, "parser", "set",
386 "cannot parse recovery interval value", &err_rc);
387 cYAML_print_tree2file(stderr, err_rc);
388 cYAML_free_tree(err_rc);
392 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
393 if (rc != LUSTRE_CFG_RC_NO_ERR)
394 cYAML_print_tree2file(stderr, err_rc);
396 cYAML_free_tree(err_rc);
401 static int jt_set_rtr_sensitivity(int argc, char **argv)
405 struct cYAML *err_rc = NULL;
407 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
411 rc = parse_long(argv[1], &value);
413 cYAML_build_error(-1, -1, "parser", "set",
414 "cannot parse router sensitivity value", &err_rc);
415 cYAML_print_tree2file(stderr, err_rc);
416 cYAML_free_tree(err_rc);
420 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
421 if (rc != LUSTRE_CFG_RC_NO_ERR)
422 cYAML_print_tree2file(stderr, err_rc);
424 cYAML_free_tree(err_rc);
429 static int jt_set_hsensitivity(int argc, char **argv)
433 struct cYAML *err_rc = NULL;
435 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
439 rc = parse_long(argv[1], &value);
441 cYAML_build_error(-1, -1, "parser", "set",
442 "cannot parse health sensitivity value", &err_rc);
443 cYAML_print_tree2file(stderr, err_rc);
444 cYAML_free_tree(err_rc);
448 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
449 if (rc != LUSTRE_CFG_RC_NO_ERR)
450 cYAML_print_tree2file(stderr, err_rc);
452 cYAML_free_tree(err_rc);
457 static int jt_set_transaction_to(int argc, char **argv)
461 struct cYAML *err_rc = NULL;
463 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
467 rc = parse_long(argv[1], &value);
469 cYAML_build_error(-1, -1, "parser", "set",
470 "cannot parse transaction timeout value", &err_rc);
471 cYAML_print_tree2file(stderr, err_rc);
472 cYAML_free_tree(err_rc);
476 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
477 if (rc != LUSTRE_CFG_RC_NO_ERR)
478 cYAML_print_tree2file(stderr, err_rc);
480 cYAML_free_tree(err_rc);
485 static int jt_set_retry_count(int argc, char **argv)
489 struct cYAML *err_rc = NULL;
491 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
495 rc = parse_long(argv[1], &value);
497 cYAML_build_error(-1, -1, "parser", "set",
498 "cannot parse retry_count value", &err_rc);
499 cYAML_print_tree2file(stderr, err_rc);
500 cYAML_free_tree(err_rc);
504 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
505 if (rc != LUSTRE_CFG_RC_NO_ERR)
506 cYAML_print_tree2file(stderr, err_rc);
508 cYAML_free_tree(err_rc);
513 static int jt_set_discovery(int argc, char **argv)
517 struct cYAML *err_rc = NULL;
519 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
523 rc = parse_long(argv[1], &value);
525 cYAML_build_error(-1, -1, "parser", "set",
526 "cannot parse discovery value", &err_rc);
527 cYAML_print_tree2file(stderr, err_rc);
528 cYAML_free_tree(err_rc);
532 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
533 if (rc != LUSTRE_CFG_RC_NO_ERR)
534 cYAML_print_tree2file(stderr, err_rc);
536 cYAML_free_tree(err_rc);
541 static int jt_set_drop_asym_route(int argc, char **argv)
545 struct cYAML *err_rc = NULL;
547 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
551 rc = parse_long(argv[1], &value);
553 cYAML_build_error(-1, -1, "parser", "set",
554 "cannot parse drop_asym_route value",
556 cYAML_print_tree2file(stderr, err_rc);
557 cYAML_free_tree(err_rc);
561 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
562 if (rc != LUSTRE_CFG_RC_NO_ERR)
563 cYAML_print_tree2file(stderr, err_rc);
565 cYAML_free_tree(err_rc);
570 static int jt_set_tiny(int argc, char **argv)
574 struct cYAML *err_rc = NULL;
576 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
580 rc = parse_long(argv[1], &value);
582 cYAML_build_error(-1, -1, "parser", "set",
583 "cannot parse tiny_buffers value", &err_rc);
584 cYAML_print_tree2file(stderr, err_rc);
585 cYAML_free_tree(err_rc);
589 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
590 if (rc != LUSTRE_CFG_RC_NO_ERR)
591 cYAML_print_tree2file(stderr, err_rc);
593 cYAML_free_tree(err_rc);
598 static int jt_set_small(int argc, char **argv)
602 struct cYAML *err_rc = NULL;
604 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
608 rc = parse_long(argv[1], &value);
610 cYAML_build_error(-1, -1, "parser", "set",
611 "cannot parse small_buffers value", &err_rc);
612 cYAML_print_tree2file(stderr, err_rc);
613 cYAML_free_tree(err_rc);
617 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
618 if (rc != LUSTRE_CFG_RC_NO_ERR)
619 cYAML_print_tree2file(stderr, err_rc);
621 cYAML_free_tree(err_rc);
626 static int jt_set_large(int argc, char **argv)
630 struct cYAML *err_rc = NULL;
632 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
636 rc = parse_long(argv[1], &value);
638 cYAML_build_error(-1, -1, "parser", "set",
639 "cannot parse large_buffers value", &err_rc);
640 cYAML_print_tree2file(stderr, err_rc);
641 cYAML_free_tree(err_rc);
645 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
646 if (rc != LUSTRE_CFG_RC_NO_ERR)
647 cYAML_print_tree2file(stderr, err_rc);
649 cYAML_free_tree(err_rc);
654 static int jt_set_routing(int argc, char **argv)
657 struct cYAML *err_rc = NULL;
660 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
664 rc = parse_long(argv[1], &value);
665 if (rc != 0 || (value != 0 && value != 1)) {
666 cYAML_build_error(-1, -1, "parser", "set",
667 "cannot parse routing value.\n"
668 "must be 0 for disable or 1 for enable",
670 cYAML_print_tree2file(stderr, err_rc);
671 cYAML_free_tree(err_rc);
675 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
677 if (rc != LUSTRE_CFG_RC_NO_ERR)
678 cYAML_print_tree2file(stderr, err_rc);
680 cYAML_free_tree(err_rc);
685 static int jt_config_lnet(int argc, char **argv)
687 struct cYAML *err_rc = NULL;
688 bool load_mod_params = false;
691 const char *const short_options = "a";
692 static const struct option long_options[] = {
693 { .name = "all", .has_arg = no_argument, .val = 'a' },
697 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
701 while ((opt = getopt_long(argc, argv, short_options,
702 long_options, NULL)) != -1) {
705 load_mod_params = true;
712 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
715 if (rc != LUSTRE_CFG_RC_NO_ERR)
716 cYAML_print_tree2file(stderr, err_rc);
718 cYAML_free_tree(err_rc);
723 static int jt_unconfig_lnet(int argc, char **argv)
725 struct cYAML *err_rc = NULL;
728 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
732 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
734 if (rc != LUSTRE_CFG_RC_NO_ERR)
735 cYAML_print_tree2file(stderr, err_rc);
737 cYAML_free_tree(err_rc);
741 static int jt_add_route(int argc, char **argv)
743 char *network = NULL, *gateway = NULL;
744 long int hop = -1, prio = -1;
745 struct cYAML *err_rc = NULL;
748 const char *const short_options = "n:g:c:p:";
749 static const struct option long_options[] = {
750 { .name = "net", .has_arg = required_argument, .val = 'n' },
751 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
752 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
753 { .name = "priority", .has_arg = required_argument, .val = 'p' },
756 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
760 while ((opt = getopt_long(argc, argv, short_options,
761 long_options, NULL)) != -1) {
770 rc = parse_long(optarg, &hop);
778 rc = parse_long(optarg, &prio);
786 print_help(route_cmds, "route", "add");
792 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
794 if (rc != LUSTRE_CFG_RC_NO_ERR)
795 cYAML_print_tree2file(stderr, err_rc);
797 cYAML_free_tree(err_rc);
802 static int jt_add_ni(int argc, char **argv)
805 long int pto = -1, pc = -1, pbc = -1, cre = -1;
806 struct cYAML *err_rc = NULL;
807 int rc, opt, cpt_rc = -1;
808 struct lnet_dlc_network_descr nw_descr;
809 struct cfs_expr_list *global_cpts = NULL;
810 struct lnet_ioctl_config_lnd_tunables tunables;
813 memset(&tunables, 0, sizeof(tunables));
814 lustre_lnet_init_nw_descr(&nw_descr);
816 const char *const short_options = "n:i:p:t:c:b:r:s:";
817 static const struct option long_options[] = {
818 { .name = "net", .has_arg = required_argument, .val = 'n' },
819 { .name = "if", .has_arg = required_argument, .val = 'i' },
820 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
821 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
822 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
823 { .name = "peer-buffer-credits",
824 .has_arg = required_argument, .val = 'b' },
825 { .name = "credits", .has_arg = required_argument, .val = 'r' },
826 { .name = "cpt", .has_arg = required_argument, .val = 's' },
829 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
833 while ((opt = getopt_long(argc, argv, short_options,
834 long_options, NULL)) != -1) {
837 nw_descr.nw_id = libcfs_str2net(optarg);
840 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
842 cYAML_build_error(-1, -1, "ni", "add",
843 "bad interface list",
852 rc = parse_long(optarg, &pto);
860 rc = parse_long(optarg, &pc);
868 rc = parse_long(optarg, &pbc);
876 rc = parse_long(optarg, &cre);
884 cpt_rc = cfs_expr_list_parse(optarg,
886 UINT_MAX, &global_cpts);
889 print_help(net_cmds, "net", "add");
895 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
896 tunables.lt_cmn.lct_peer_timeout = pto;
897 tunables.lt_cmn.lct_peer_tx_credits = pc;
898 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
899 tunables.lt_cmn.lct_max_tx_credits = cre;
903 rc = lustre_lnet_config_ni(&nw_descr,
904 (cpt_rc == 0) ? global_cpts: NULL,
905 ip2net, (found) ? &tunables : NULL,
908 if (global_cpts != NULL)
909 cfs_expr_list_free(global_cpts);
912 if (rc != LUSTRE_CFG_RC_NO_ERR)
913 cYAML_print_tree2file(stderr, err_rc);
915 cYAML_free_tree(err_rc);
920 static int jt_del_route(int argc, char **argv)
922 char *network = NULL, *gateway = NULL;
923 struct cYAML *err_rc = NULL;
926 const char *const short_options = "n:g:";
927 static const struct option long_options[] = {
928 { .name = "net", .has_arg = required_argument, .val = 'n' },
929 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
932 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
936 while ((opt = getopt_long(argc, argv, short_options,
937 long_options, NULL)) != -1) {
946 print_help(route_cmds, "route", "del");
952 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
954 if (rc != LUSTRE_CFG_RC_NO_ERR)
955 cYAML_print_tree2file(stderr, err_rc);
957 cYAML_free_tree(err_rc);
962 static int jt_del_ni(int argc, char **argv)
964 struct cYAML *err_rc = NULL;
966 struct lnet_dlc_network_descr nw_descr;
968 lustre_lnet_init_nw_descr(&nw_descr);
970 const char *const short_options = "n:i:";
971 static const struct option long_options[] = {
972 { .name = "net", .has_arg = required_argument, .val = 'n' },
973 { .name = "if", .has_arg = required_argument, .val = 'i' },
976 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
980 while ((opt = getopt_long(argc, argv, short_options,
981 long_options, NULL)) != -1) {
984 nw_descr.nw_id = libcfs_str2net(optarg);
987 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
989 cYAML_build_error(-1, -1, "ni", "add",
990 "bad interface list",
996 print_help(net_cmds, "net", "del");
1002 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1005 if (rc != LUSTRE_CFG_RC_NO_ERR)
1006 cYAML_print_tree2file(stderr, err_rc);
1008 cYAML_free_tree(err_rc);
1013 static int jt_show_route(int argc, char **argv)
1015 char *network = NULL, *gateway = NULL;
1016 long int hop = -1, prio = -1;
1017 int detail = 0, rc, opt;
1018 struct cYAML *err_rc = NULL, *show_rc = NULL;
1020 const char *const short_options = "n:g:h:p:v";
1021 static const struct option long_options[] = {
1022 { .name = "net", .has_arg = required_argument, .val = 'n' },
1023 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1024 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1025 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1026 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1029 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1033 while ((opt = getopt_long(argc, argv, short_options,
1034 long_options, NULL)) != -1) {
1043 rc = parse_long(optarg, &hop);
1051 rc = parse_long(optarg, &prio);
1062 print_help(route_cmds, "route", "show");
1068 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1069 &show_rc, &err_rc, false);
1071 if (rc != LUSTRE_CFG_RC_NO_ERR)
1072 cYAML_print_tree2file(stderr, err_rc);
1074 cYAML_print_tree(show_rc);
1076 cYAML_free_tree(err_rc);
1077 cYAML_free_tree(show_rc);
1082 static int set_value_helper(int argc, char **argv,
1083 int (*cb)(int, bool, char*, int, struct cYAML**))
1086 long int healthv = -1;
1089 struct cYAML *err_rc = NULL;
1091 const char *const short_options = "t:n:a";
1092 static const struct option long_options[] = {
1093 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1094 { .name = "health", .has_arg = required_argument, .val = 't' },
1095 { .name = "all", .has_arg = no_argument, .val = 'a' },
1098 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1102 while ((opt = getopt_long(argc, argv, short_options,
1103 long_options, NULL)) != -1) {
1109 if (parse_long(optarg, &healthv) != 0)
1120 rc = cb(healthv, all, nid, -1, &err_rc);
1122 if (rc != LUSTRE_CFG_RC_NO_ERR)
1123 cYAML_print_tree2file(stderr, err_rc);
1125 cYAML_free_tree(err_rc);
1130 static int jt_set_ni_value(int argc, char **argv)
1132 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1135 static int jt_set_peer_ni_value(int argc, char **argv)
1137 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1140 static int jt_show_recovery(int argc, char **argv)
1143 struct cYAML *err_rc = NULL, *show_rc = NULL;
1145 const char *const short_options = "lp";
1146 static const struct option long_options[] = {
1147 { .name = "local", .has_arg = no_argument, .val = 'l' },
1148 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1151 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1155 while ((opt = getopt_long(argc, argv, short_options,
1156 long_options, NULL)) != -1) {
1159 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1162 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1169 if (rc != LUSTRE_CFG_RC_NO_ERR)
1170 cYAML_print_tree2file(stderr, err_rc);
1172 cYAML_print_tree(show_rc);
1174 cYAML_free_tree(err_rc);
1175 cYAML_free_tree(show_rc);
1180 static int jt_show_net(int argc, char **argv)
1182 char *network = NULL;
1184 struct cYAML *err_rc = NULL, *show_rc = NULL;
1185 long int detail = 0;
1187 const char *const short_options = "n:v";
1188 static const struct option long_options[] = {
1189 { .name = "net", .has_arg = required_argument, .val = 'n' },
1190 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1193 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1197 while ((opt = getopt_long(argc, argv, short_options,
1198 long_options, NULL)) != -1) {
1204 if ((!optarg) && (argv[optind] != NULL) &&
1205 (argv[optind][0] != '-')) {
1206 if (parse_long(argv[optind++], &detail) != 0)
1213 print_help(net_cmds, "net", "show");
1219 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1222 if (rc != LUSTRE_CFG_RC_NO_ERR)
1223 cYAML_print_tree2file(stderr, err_rc);
1225 cYAML_print_tree(show_rc);
1227 cYAML_free_tree(err_rc);
1228 cYAML_free_tree(show_rc);
1233 static int jt_show_routing(int argc, char **argv)
1235 struct cYAML *err_rc = NULL, *show_rc = NULL;
1238 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1242 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1244 if (rc != LUSTRE_CFG_RC_NO_ERR)
1245 cYAML_print_tree2file(stderr, err_rc);
1247 cYAML_print_tree(show_rc);
1249 cYAML_free_tree(err_rc);
1250 cYAML_free_tree(show_rc);
1255 static int jt_show_stats(int argc, char **argv)
1258 struct cYAML *show_rc = NULL, *err_rc = NULL;
1260 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1264 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1266 if (rc != LUSTRE_CFG_RC_NO_ERR)
1267 cYAML_print_tree2file(stderr, err_rc);
1269 cYAML_print_tree(show_rc);
1271 cYAML_free_tree(err_rc);
1272 cYAML_free_tree(show_rc);
1277 static int jt_show_global(int argc, char **argv)
1280 struct cYAML *show_rc = NULL, *err_rc = NULL;
1282 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1286 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1287 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1288 cYAML_print_tree2file(stderr, err_rc);
1292 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1293 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1294 cYAML_print_tree2file(stderr, err_rc);
1298 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1299 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1300 cYAML_print_tree2file(stderr, err_rc);
1304 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1305 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1306 cYAML_print_tree2file(stderr, err_rc);
1310 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1311 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1312 cYAML_print_tree2file(stderr, err_rc);
1316 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1317 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1318 cYAML_print_tree2file(stderr, err_rc);
1322 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1323 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1324 cYAML_print_tree2file(stderr, err_rc);
1328 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1329 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1330 cYAML_print_tree2file(stderr, err_rc);
1334 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1335 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1336 cYAML_print_tree2file(stderr, err_rc);
1341 cYAML_print_tree(show_rc);
1344 cYAML_free_tree(err_rc);
1345 cYAML_free_tree(show_rc);
1350 static int jt_lnet(int argc, char **argv)
1354 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1358 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1361 static int jt_route(int argc, char **argv)
1365 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1369 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1372 static int jt_net(int argc, char **argv)
1376 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1380 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1383 static int jt_routing(int argc, char **argv)
1387 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1391 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1394 static int jt_stats(int argc, char **argv)
1398 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1402 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1405 static int jt_debug(int argc, char **argv)
1409 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1413 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1416 static int jt_global(int argc, char **argv)
1420 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1424 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1427 static int jt_peers(int argc, char **argv)
1431 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1435 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1438 static int jt_set(int argc, char **argv)
1442 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1446 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1449 static int jt_import(int argc, char **argv)
1452 struct cYAML *err_rc = NULL;
1453 struct cYAML *show_rc = NULL;
1454 int rc = 0, return_rc = 0, opt, opt_found = 0;
1457 const char *const short_options = "adseh";
1458 static const struct option long_options[] = {
1459 { .name = "add", .has_arg = no_argument, .val = 'a' },
1460 { .name = "del", .has_arg = no_argument, .val = 'd' },
1461 { .name = "show", .has_arg = no_argument, .val = 's' },
1462 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1463 { .name = "help", .has_arg = no_argument, .val = 'h' },
1466 while ((opt = getopt_long(argc, argv, short_options,
1467 long_options, NULL)) != -1) {
1481 printf("import FILE\n"
1482 "import < FILE : import a file\n"
1483 "\t--add: add configuration\n"
1484 "\t--del: delete configuration\n"
1485 "\t--show: show configuration\n"
1486 "\t--exec: execute command\n"
1487 "\t--help: display this help\n"
1488 "If no command option is given then --add"
1489 " is assumed by default\n");
1496 /* grab the file name if one exists */
1497 if (opt_found && argc == 3)
1499 else if (!opt_found && argc == 2)
1504 rc = lustre_yaml_config(file, &err_rc);
1505 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1506 cYAML_print_tree(show_rc);
1507 cYAML_free_tree(show_rc);
1510 rc = lustre_yaml_del(file, &err_rc);
1513 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1514 cYAML_print_tree(show_rc);
1515 cYAML_free_tree(show_rc);
1518 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1519 cYAML_print_tree(show_rc);
1520 cYAML_free_tree(show_rc);
1524 if (rc || return_rc) {
1525 cYAML_print_tree2file(stderr, err_rc);
1526 cYAML_free_tree(err_rc);
1532 static int jt_export(int argc, char **argv)
1534 struct cYAML *show_rc = NULL;
1535 struct cYAML *err_rc = NULL;
1539 bool backup = false;
1542 const char *const short_options = "bh";
1543 static const struct option long_options[] = {
1544 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1545 { .name = "help", .has_arg = no_argument, .val = 'h' },
1548 while ((opt = getopt_long(argc, argv, short_options,
1549 long_options, NULL)) != -1) {
1556 printf("export > FILE.yaml : export configuration\n"
1557 "\t--backup: export only what's necessary for reconfig\n"
1558 "\t--help: display this help\n");
1563 if (backup && argc >= 3)
1565 else if (!backup && argc >= 2)
1571 f = fopen(file, "w");
1576 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1577 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1578 cYAML_print_tree2file(stderr, err_rc);
1579 cYAML_free_tree(err_rc);
1583 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1585 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1586 cYAML_print_tree2file(stderr, err_rc);
1587 cYAML_free_tree(err_rc);
1591 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1592 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1593 cYAML_print_tree2file(stderr, err_rc);
1594 cYAML_free_tree(err_rc);
1598 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1599 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1600 cYAML_print_tree2file(stderr, err_rc);
1601 cYAML_free_tree(err_rc);
1605 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1606 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1607 cYAML_print_tree2file(stderr, err_rc);
1608 cYAML_free_tree(err_rc);
1612 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1613 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1614 cYAML_print_tree2file(stderr, err_rc);
1615 cYAML_free_tree(err_rc);
1619 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1620 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1621 cYAML_print_tree2file(stderr, err_rc);
1622 cYAML_free_tree(err_rc);
1626 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1627 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1628 cYAML_print_tree2file(stderr, err_rc);
1629 cYAML_free_tree(err_rc);
1633 if (show_rc != NULL) {
1634 cYAML_print_tree2file(f, show_rc);
1635 cYAML_free_tree(show_rc);
1644 static int jt_add_peer_nid(int argc, char **argv)
1646 char *prim_nid = NULL;
1647 char **nids = NULL, **nids2 = NULL;
1649 struct cYAML *err_rc = NULL;
1650 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1651 bool non_mr = false;
1652 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1654 const char *const short_opts = "k:mn:";
1655 const struct option long_opts[] = {
1656 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1657 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1658 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1659 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1662 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1666 while ((opt = getopt_long(argc, argv, short_opts,
1667 long_opts, NULL)) != -1) {
1670 prim_nid_present = true;
1672 cYAML_build_error(-1, -1, "peer", "add",
1673 "ip2nets can not be specified"
1674 " along side prim_nid parameter.",
1688 if (ip2nets && (nid_list || prim_nid_present)) {
1689 cYAML_build_error(-1, -1, "peer", "add",
1690 "ip2nets can not be specified"
1691 " along side nid or prim_nid"
1692 " parameters", &err_rc);
1696 size = lustre_lnet_parse_nids(optarg, nids, size,
1701 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1707 print_help(peer_cmds, "peer", "add");
1713 for (; optind < argc; optind++) {
1714 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1721 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1722 !non_mr, ip2nets, -1, &err_rc);
1726 /* free the array of nids */
1727 for (i = 0; i < size; i++)
1732 if (rc != LUSTRE_CFG_RC_NO_ERR)
1733 cYAML_print_tree2file(stderr, err_rc);
1735 cYAML_free_tree(err_rc);
1740 static int jt_del_peer_nid(int argc, char **argv)
1742 char *prim_nid = NULL;
1743 char **nids = NULL, **nids2 = NULL;
1744 struct cYAML *err_rc = NULL;
1745 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1746 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1748 const char *const short_opts = "k:n:";
1749 const struct option long_opts[] = {
1750 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1751 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1752 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1755 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1759 while ((opt = getopt_long(argc, argv, short_opts,
1760 long_opts, NULL)) != -1) {
1763 prim_nid_present = true;
1765 cYAML_build_error(-1, -1, "peer", "add",
1766 "ip2nets can not be specified"
1767 " along side prim_nid parameter.",
1781 if (ip2nets && (nid_list || prim_nid_present)) {
1782 cYAML_build_error(-1, -1, "peer", "add",
1783 "ip2nets can not be specified"
1784 " along side nid or prim_nid"
1785 " parameters", &err_rc);
1788 size = lustre_lnet_parse_nids(optarg, nids, size,
1793 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1796 print_help(peer_cmds, "peer", "del");
1802 for (; optind < argc; optind++) {
1803 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1810 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1814 for (i = 0; i < size; i++)
1819 if (rc != LUSTRE_CFG_RC_NO_ERR)
1820 cYAML_print_tree2file(stderr, err_rc);
1822 cYAML_free_tree(err_rc);
1827 static int jt_show_peer(int argc, char **argv)
1831 struct cYAML *err_rc = NULL, *show_rc = NULL;
1832 long int detail = 0;
1834 const char *const short_opts = "hn:v::";
1835 const struct option long_opts[] = {
1836 { .name = "help", .has_arg = no_argument, .val = 'h' },
1837 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1838 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1841 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1845 while ((opt = getopt_long(argc, argv, short_opts,
1846 long_opts, NULL)) != -1) {
1852 if ((!optarg) && (argv[optind] != NULL) &&
1853 (argv[optind][0] != '-')) {
1854 if (parse_long(argv[optind++], &detail) != 0)
1861 print_help(peer_cmds, "peer", "show");
1867 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1870 if (rc != LUSTRE_CFG_RC_NO_ERR)
1871 cYAML_print_tree2file(stderr, err_rc);
1873 cYAML_print_tree(show_rc);
1875 cYAML_free_tree(err_rc);
1876 cYAML_free_tree(show_rc);
1881 static int jt_list_peer(int argc, char **argv)
1884 struct cYAML *err_rc = NULL, *list_rc = NULL;
1886 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1890 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1892 if (rc != LUSTRE_CFG_RC_NO_ERR)
1893 cYAML_print_tree2file(stderr, err_rc);
1895 cYAML_print_tree(list_rc);
1897 cYAML_free_tree(err_rc);
1898 cYAML_free_tree(list_rc);
1903 static int jt_ping(int argc, char **argv)
1905 struct cYAML *err_rc = NULL;
1906 struct cYAML *show_rc = NULL;
1910 const char *const short_options = "ht:";
1911 const struct option long_options[] = {
1912 { .name = "help", .has_arg = no_argument, .val = 'h' },
1913 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1916 while ((opt = getopt_long(argc, argv, short_options,
1917 long_options, NULL)) != -1) {
1920 timeout = 1000 * atol(optarg);
1923 printf("ping nid[,nid,...]\n"
1924 "\t --timeout: ping timeout\n"
1925 "\t --help: display this help\n");
1932 for (; optind < argc; optind++)
1933 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1936 cYAML_print_tree(show_rc);
1939 cYAML_print_tree2file(stderr, err_rc);
1941 cYAML_free_tree(err_rc);
1942 cYAML_free_tree(show_rc);
1947 static int jt_discover(int argc, char **argv)
1949 struct cYAML *err_rc = NULL;
1950 struct cYAML *show_rc = NULL;
1954 const char *const short_options = "fh";
1955 const struct option long_options[] = {
1956 { .name = "force", .has_arg = no_argument, .val = 'f' },
1957 { .name = "help", .has_arg = no_argument, .val = 'h' },
1960 while ((opt = getopt_long(argc, argv, short_options,
1961 long_options, NULL)) != -1) {
1967 printf("discover nid[,nid,...]\n"
1968 "\t --force: force discovery\n"
1969 "\t --help: display this help\n");
1976 for (; optind < argc; optind++)
1977 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1981 cYAML_print_tree(show_rc);
1984 cYAML_print_tree2file(stderr, err_rc);
1986 cYAML_free_tree(err_rc);
1987 cYAML_free_tree(show_rc);
1992 static int lnetctl_list_commands(int argc, char **argv)
1994 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1996 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2001 int main(int argc, char **argv)
2004 struct cYAML *err_rc = NULL;
2006 rc = lustre_lnet_config_lib_init();
2008 cYAML_build_error(-1, -1, "lnetctl", "startup",
2009 "cannot register LNet device", &err_rc);
2010 cYAML_print_tree2file(stderr, err_rc);
2014 Parser_init("lnetctl > ", cmd_list);
2016 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);