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_hsensitivity(int argc, char **argv);
61 static int jt_add_peer_nid(int argc, char **argv);
62 static int jt_del_peer_nid(int argc, char **argv);
63 static int jt_set_max_intf(int argc, char **argv);
64 static int jt_set_discovery(int argc, char **argv);
65 static int jt_set_drop_asym_route(int argc, char **argv);
66 static int jt_list_peer(int argc, char **argv);
67 /*static int jt_show_peer(int argc, char **argv);*/
68 static int lnetctl_list_commands(int argc, char **argv);
69 static int jt_import(int argc, char **argv);
70 static int jt_export(int argc, char **argv);
71 static int jt_ping(int argc, char **argv);
72 static int jt_discover(int argc, char **argv);
73 static int jt_lnet(int argc, char **argv);
74 static int jt_route(int argc, char **argv);
75 static int jt_net(int argc, char **argv);
76 static int jt_routing(int argc, char **argv);
77 static int jt_set(int argc, char **argv);
78 static int jt_debug(int argc, char **argv);
79 static int jt_stats(int argc, char **argv);
80 static int jt_global(int argc, char **argv);
81 static int jt_peers(int argc, char **argv);
82 static int jt_set_ni_value(int argc, char **argv);
83 static int jt_set_peer_ni_value(int argc, char **argv);
85 command_t cmd_list[] = {
86 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
87 {"route", jt_route, 0, "route {add | del | show | help}"},
88 {"net", jt_net, 0, "net {add | del | show | help}"},
89 {"routing", jt_routing, 0, "routing {show | help}"},
90 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
91 " | routing | numa_range | max_interfaces"
93 {"import", jt_import, 0, "import FILE.yaml"},
94 {"export", jt_export, 0, "export FILE.yaml"},
95 {"stats", jt_stats, 0, "stats {show | help}"},
96 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
97 {"global", jt_global, 0, "global {show | help}"},
98 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
99 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
100 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
101 {"help", Parser_help, 0, "help"},
102 {"exit", Parser_quit, 0, "quit"},
103 {"quit", Parser_quit, 0, "quit"},
104 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
108 command_t lnet_cmds[] = {
109 {"configure", jt_config_lnet, 0, "configure lnet\n"
110 "\t--all: load NI configuration from module parameters\n"},
111 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
115 command_t route_cmds[] = {
116 {"add", jt_add_route, 0, "add a route\n"
117 "\t--net: net name (e.g. tcp0)\n"
118 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
119 "\t--hop: number to final destination (1 < hops < 255)\n"
120 "\t--priority: priority of route (0 - highest prio\n"},
121 {"del", jt_del_route, 0, "delete a route\n"
122 "\t--net: net name (e.g. tcp0)\n"
123 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
124 {"show", jt_show_route, 0, "show routes\n"
125 "\t--net: net name (e.g. tcp0) to filter on\n"
126 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
127 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
128 "\t--priority: priority of route (0 - highest prio to filter on\n"
129 "\t--verbose: display detailed output per route\n"},
133 command_t net_cmds[] = {
134 {"add", jt_add_ni, 0, "add a network\n"
135 "\t--net: net name (e.g. tcp0)\n"
136 "\t--if: physical interface (e.g. eth0)\n"
137 "\t--ip2net: specify networks based on IP address patterns\n"
138 "\t--peer-timeout: time to wait before declaring a peer dead\n"
139 "\t--peer-credits: define the max number of inflight messages\n"
140 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
141 "\t--credits: Network Interface credits\n"
142 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
143 {"del", jt_del_ni, 0, "delete a network\n"
144 "\t--net: net name (e.g. tcp0)\n"
145 "\t--if: physical interface (e.g. eth0)\n"},
146 {"show", jt_show_net, 0, "show networks\n"
147 "\t--net: net name (e.g. tcp0) to filter on\n"
148 "\t--verbose: display detailed output per network."
149 " Optional argument of '2' outputs more stats\n"},
150 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
151 "\t--nid: NI NID to set the\n"
152 "\t--health: specify health value to set\n"
153 "\t--all: set all NIs value to the one specified\n"},
157 command_t routing_cmds[] = {
158 {"show", jt_show_routing, 0, "show routing information\n"},
162 command_t stats_cmds[] = {
163 {"show", jt_show_stats, 0, "show LNET statistics\n"},
167 command_t debug_cmds[] = {
168 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
169 "\t--local : list local recovery queue\n"
170 "\t--peer : list peer recovery queue\n"},
174 command_t global_cmds[] = {
175 {"show", jt_show_global, 0, "show global variables\n"},
179 command_t set_cmds[] = {
180 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
181 "\tVALUE must be greater than 0\n"},
182 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
183 "\tVALUE must be greater than 0\n"},
184 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
185 "\tVALUE must be greater than 0\n"},
186 {"routing", jt_set_routing, 0, "enable/disable routing\n"
187 "\t0 - disable routing\n"
188 "\t1 - enable routing\n"},
189 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
190 "\tVALUE must be at least 0\n"},
191 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
193 "\tValue must be greater than 16\n"},
194 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
195 "\t0 - disable peer discovery\n"
196 "\t1 - enable peer discovery (default)\n"},
197 {"drop_asym_route", jt_set_drop_asym_route, 0,
198 "drop/accept asymmetrical route messages\n"
199 "\t0 - accept asymmetrical route messages (default)\n"
200 "\t1 - drop asymmetrical route messages\n"},
201 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
202 "\t0 - turn of retries\n"
203 "\t>0 - number of retries\n"},
204 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
205 "\t>0 - timeout in seconds\n"},
206 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
207 "\t0 - turn off health evaluation\n"
208 "\t>0 - sensitivity value not more than 1000\n"},
209 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
210 "\t>0 - time in seconds between pings\n"},
214 command_t peer_cmds[] = {
215 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
216 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
217 "\t NID in the list becomes the Primary NID of a newly created\n"
219 "\t--nid: one or more peer NIDs\n"
220 "\t--non_mr: create this peer as not Multi-Rail capable\n"
221 "\t--ip2nets: specify a range of nids per peer"},
222 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
223 "\t--prim_nid: Primary NID of the peer.\n"
224 "\t--nid: list of NIDs to remove. If none provided,\n"
225 "\t peer is deleted\n"
226 "\t--ip2nets: specify a range of nids per peer"},
227 {"show", jt_show_peer, 0, "show peer information\n"
228 "\t--nid: NID of peer to filter on.\n"
229 "\t--verbose: display detailed output per peer."
230 " Optional argument of '2' outputs more stats\n"},
231 {"list", jt_list_peer, 0, "list all peers\n"},
232 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
233 "\t--nid: Peer NI NID to set the\n"
234 "\t--health: specify health value to set\n"
235 "\t--all: set all peer_nis values to the one specified\n"},
239 static inline void print_help(const command_t cmds[], const char *cmd_type,
242 const command_t *cmd;
244 for (cmd = cmds; cmd->pc_name; cmd++) {
245 if (pc_name != NULL &&
246 strcmp(cmd->pc_name, pc_name) == 0) {
247 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
250 } else if (pc_name != NULL) {
253 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
257 static int parse_long(const char *number, long int *value)
264 *value = strtol(number, &end, 0);
265 if (end != NULL && *end != 0)
271 static int check_cmd(const command_t *cmd_list, const char *cmd,
272 const char *sub_cmd, const int min_args,
273 int argc, char **argv)
280 const char *const short_options = "h";
281 static const struct option long_options[] = {
282 { .name = "help", .has_arg = no_argument, .val = 'h' },
286 if (argc < min_args) {
287 print_help(cmd_list, cmd, sub_cmd);
290 } else if (argc > 2) {
294 while ((opt = getopt_long(argc, argv, short_options,
295 long_options, NULL)) != -1) {
298 print_help(cmd_list, cmd, sub_cmd);
313 static int jt_set_max_intf(int argc, char **argv)
317 struct cYAML *err_rc = NULL;
319 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
323 rc = parse_long(argv[1], &value);
325 cYAML_build_error(-1, -1, "parser", "set",
326 "cannot parse max_interfaces value", &err_rc);
327 cYAML_print_tree2file(stderr, err_rc);
328 cYAML_free_tree(err_rc);
332 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
333 if (rc != LUSTRE_CFG_RC_NO_ERR)
334 cYAML_print_tree2file(stderr, err_rc);
336 cYAML_free_tree(err_rc);
341 static int jt_set_numa(int argc, char **argv)
345 struct cYAML *err_rc = NULL;
347 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
351 rc = parse_long(argv[1], &value);
353 cYAML_build_error(-1, -1, "parser", "set",
354 "cannot parse numa_range value", &err_rc);
355 cYAML_print_tree2file(stderr, err_rc);
356 cYAML_free_tree(err_rc);
360 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
361 if (rc != LUSTRE_CFG_RC_NO_ERR)
362 cYAML_print_tree2file(stderr, err_rc);
364 cYAML_free_tree(err_rc);
369 static int jt_set_recov_intrv(int argc, char **argv)
373 struct cYAML *err_rc = NULL;
375 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
379 rc = parse_long(argv[1], &value);
381 cYAML_build_error(-1, -1, "parser", "set",
382 "cannot parse recovery interval value", &err_rc);
383 cYAML_print_tree2file(stderr, err_rc);
384 cYAML_free_tree(err_rc);
388 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
389 if (rc != LUSTRE_CFG_RC_NO_ERR)
390 cYAML_print_tree2file(stderr, err_rc);
392 cYAML_free_tree(err_rc);
397 static int jt_set_hsensitivity(int argc, char **argv)
401 struct cYAML *err_rc = NULL;
403 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
407 rc = parse_long(argv[1], &value);
409 cYAML_build_error(-1, -1, "parser", "set",
410 "cannot parse health sensitivity value", &err_rc);
411 cYAML_print_tree2file(stderr, err_rc);
412 cYAML_free_tree(err_rc);
416 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
417 if (rc != LUSTRE_CFG_RC_NO_ERR)
418 cYAML_print_tree2file(stderr, err_rc);
420 cYAML_free_tree(err_rc);
425 static int jt_set_transaction_to(int argc, char **argv)
429 struct cYAML *err_rc = NULL;
431 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
435 rc = parse_long(argv[1], &value);
437 cYAML_build_error(-1, -1, "parser", "set",
438 "cannot parse transaction timeout value", &err_rc);
439 cYAML_print_tree2file(stderr, err_rc);
440 cYAML_free_tree(err_rc);
444 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
445 if (rc != LUSTRE_CFG_RC_NO_ERR)
446 cYAML_print_tree2file(stderr, err_rc);
448 cYAML_free_tree(err_rc);
453 static int jt_set_retry_count(int argc, char **argv)
457 struct cYAML *err_rc = NULL;
459 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
463 rc = parse_long(argv[1], &value);
465 cYAML_build_error(-1, -1, "parser", "set",
466 "cannot parse retry_count value", &err_rc);
467 cYAML_print_tree2file(stderr, err_rc);
468 cYAML_free_tree(err_rc);
472 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
473 if (rc != LUSTRE_CFG_RC_NO_ERR)
474 cYAML_print_tree2file(stderr, err_rc);
476 cYAML_free_tree(err_rc);
481 static int jt_set_discovery(int argc, char **argv)
485 struct cYAML *err_rc = NULL;
487 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
491 rc = parse_long(argv[1], &value);
493 cYAML_build_error(-1, -1, "parser", "set",
494 "cannot parse discovery value", &err_rc);
495 cYAML_print_tree2file(stderr, err_rc);
496 cYAML_free_tree(err_rc);
500 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
501 if (rc != LUSTRE_CFG_RC_NO_ERR)
502 cYAML_print_tree2file(stderr, err_rc);
504 cYAML_free_tree(err_rc);
509 static int jt_set_drop_asym_route(int argc, char **argv)
513 struct cYAML *err_rc = NULL;
515 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
519 rc = parse_long(argv[1], &value);
521 cYAML_build_error(-1, -1, "parser", "set",
522 "cannot parse drop_asym_route value",
524 cYAML_print_tree2file(stderr, err_rc);
525 cYAML_free_tree(err_rc);
529 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
530 if (rc != LUSTRE_CFG_RC_NO_ERR)
531 cYAML_print_tree2file(stderr, err_rc);
533 cYAML_free_tree(err_rc);
538 static int jt_set_tiny(int argc, char **argv)
542 struct cYAML *err_rc = NULL;
544 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
548 rc = parse_long(argv[1], &value);
550 cYAML_build_error(-1, -1, "parser", "set",
551 "cannot parse tiny_buffers value", &err_rc);
552 cYAML_print_tree2file(stderr, err_rc);
553 cYAML_free_tree(err_rc);
557 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
558 if (rc != LUSTRE_CFG_RC_NO_ERR)
559 cYAML_print_tree2file(stderr, err_rc);
561 cYAML_free_tree(err_rc);
566 static int jt_set_small(int argc, char **argv)
570 struct cYAML *err_rc = NULL;
572 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
576 rc = parse_long(argv[1], &value);
578 cYAML_build_error(-1, -1, "parser", "set",
579 "cannot parse small_buffers value", &err_rc);
580 cYAML_print_tree2file(stderr, err_rc);
581 cYAML_free_tree(err_rc);
585 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
586 if (rc != LUSTRE_CFG_RC_NO_ERR)
587 cYAML_print_tree2file(stderr, err_rc);
589 cYAML_free_tree(err_rc);
594 static int jt_set_large(int argc, char **argv)
598 struct cYAML *err_rc = NULL;
600 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
604 rc = parse_long(argv[1], &value);
606 cYAML_build_error(-1, -1, "parser", "set",
607 "cannot parse large_buffers value", &err_rc);
608 cYAML_print_tree2file(stderr, err_rc);
609 cYAML_free_tree(err_rc);
613 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
614 if (rc != LUSTRE_CFG_RC_NO_ERR)
615 cYAML_print_tree2file(stderr, err_rc);
617 cYAML_free_tree(err_rc);
622 static int jt_set_routing(int argc, char **argv)
625 struct cYAML *err_rc = NULL;
628 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
632 rc = parse_long(argv[1], &value);
633 if (rc != 0 || (value != 0 && value != 1)) {
634 cYAML_build_error(-1, -1, "parser", "set",
635 "cannot parse routing value.\n"
636 "must be 0 for disable or 1 for enable",
638 cYAML_print_tree2file(stderr, err_rc);
639 cYAML_free_tree(err_rc);
643 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
645 if (rc != LUSTRE_CFG_RC_NO_ERR)
646 cYAML_print_tree2file(stderr, err_rc);
648 cYAML_free_tree(err_rc);
653 static int jt_config_lnet(int argc, char **argv)
655 struct cYAML *err_rc = NULL;
656 bool load_mod_params = false;
659 const char *const short_options = "a";
660 static const struct option long_options[] = {
661 { .name = "all", .has_arg = no_argument, .val = 'a' },
665 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
669 while ((opt = getopt_long(argc, argv, short_options,
670 long_options, NULL)) != -1) {
673 load_mod_params = true;
680 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
683 if (rc != LUSTRE_CFG_RC_NO_ERR)
684 cYAML_print_tree2file(stderr, err_rc);
686 cYAML_free_tree(err_rc);
691 static int jt_unconfig_lnet(int argc, char **argv)
693 struct cYAML *err_rc = NULL;
696 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
700 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
702 if (rc != LUSTRE_CFG_RC_NO_ERR)
703 cYAML_print_tree2file(stderr, err_rc);
705 cYAML_free_tree(err_rc);
709 static int jt_add_route(int argc, char **argv)
711 char *network = NULL, *gateway = NULL;
712 long int hop = -1, prio = -1;
713 struct cYAML *err_rc = NULL;
716 const char *const short_options = "n:g:c:p:";
717 static const struct option long_options[] = {
718 { .name = "net", .has_arg = required_argument, .val = 'n' },
719 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
720 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
721 { .name = "priority", .has_arg = required_argument, .val = 'p' },
724 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
728 while ((opt = getopt_long(argc, argv, short_options,
729 long_options, NULL)) != -1) {
738 rc = parse_long(optarg, &hop);
746 rc = parse_long(optarg, &prio);
754 print_help(route_cmds, "route", "add");
760 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
762 if (rc != LUSTRE_CFG_RC_NO_ERR)
763 cYAML_print_tree2file(stderr, err_rc);
765 cYAML_free_tree(err_rc);
770 static int jt_add_ni(int argc, char **argv)
773 long int pto = -1, pc = -1, pbc = -1, cre = -1;
774 struct cYAML *err_rc = NULL;
775 int rc, opt, cpt_rc = -1;
776 struct lnet_dlc_network_descr nw_descr;
777 struct cfs_expr_list *global_cpts = NULL;
778 struct lnet_ioctl_config_lnd_tunables tunables;
781 memset(&tunables, 0, sizeof(tunables));
782 lustre_lnet_init_nw_descr(&nw_descr);
784 const char *const short_options = "n:i:p:t:c:b:r:s:";
785 static const struct option long_options[] = {
786 { .name = "net", .has_arg = required_argument, .val = 'n' },
787 { .name = "if", .has_arg = required_argument, .val = 'i' },
788 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
789 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
790 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
791 { .name = "peer-buffer-credits",
792 .has_arg = required_argument, .val = 'b' },
793 { .name = "credits", .has_arg = required_argument, .val = 'r' },
794 { .name = "cpt", .has_arg = required_argument, .val = 's' },
797 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
801 while ((opt = getopt_long(argc, argv, short_options,
802 long_options, NULL)) != -1) {
805 nw_descr.nw_id = libcfs_str2net(optarg);
808 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
810 cYAML_build_error(-1, -1, "ni", "add",
811 "bad interface list",
820 rc = parse_long(optarg, &pto);
828 rc = parse_long(optarg, &pc);
836 rc = parse_long(optarg, &pbc);
844 rc = parse_long(optarg, &cre);
852 cpt_rc = cfs_expr_list_parse(optarg,
854 UINT_MAX, &global_cpts);
857 print_help(net_cmds, "net", "add");
863 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
864 tunables.lt_cmn.lct_peer_timeout = pto;
865 tunables.lt_cmn.lct_peer_tx_credits = pc;
866 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
867 tunables.lt_cmn.lct_max_tx_credits = cre;
871 rc = lustre_lnet_config_ni(&nw_descr,
872 (cpt_rc == 0) ? global_cpts: NULL,
873 ip2net, (found) ? &tunables : NULL,
876 if (global_cpts != NULL)
877 cfs_expr_list_free(global_cpts);
880 if (rc != LUSTRE_CFG_RC_NO_ERR)
881 cYAML_print_tree2file(stderr, err_rc);
883 cYAML_free_tree(err_rc);
888 static int jt_del_route(int argc, char **argv)
890 char *network = NULL, *gateway = NULL;
891 struct cYAML *err_rc = NULL;
894 const char *const short_options = "n:g:";
895 static const struct option long_options[] = {
896 { .name = "net", .has_arg = required_argument, .val = 'n' },
897 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
900 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
904 while ((opt = getopt_long(argc, argv, short_options,
905 long_options, NULL)) != -1) {
914 print_help(route_cmds, "route", "del");
920 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
922 if (rc != LUSTRE_CFG_RC_NO_ERR)
923 cYAML_print_tree2file(stderr, err_rc);
925 cYAML_free_tree(err_rc);
930 static int jt_del_ni(int argc, char **argv)
932 struct cYAML *err_rc = NULL;
934 struct lnet_dlc_network_descr nw_descr;
936 lustre_lnet_init_nw_descr(&nw_descr);
938 const char *const short_options = "n:i:";
939 static const struct option long_options[] = {
940 { .name = "net", .has_arg = required_argument, .val = 'n' },
941 { .name = "if", .has_arg = required_argument, .val = 'i' },
944 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
948 while ((opt = getopt_long(argc, argv, short_options,
949 long_options, NULL)) != -1) {
952 nw_descr.nw_id = libcfs_str2net(optarg);
955 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
957 cYAML_build_error(-1, -1, "ni", "add",
958 "bad interface list",
964 print_help(net_cmds, "net", "del");
970 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
973 if (rc != LUSTRE_CFG_RC_NO_ERR)
974 cYAML_print_tree2file(stderr, err_rc);
976 cYAML_free_tree(err_rc);
981 static int jt_show_route(int argc, char **argv)
983 char *network = NULL, *gateway = NULL;
984 long int hop = -1, prio = -1;
985 int detail = 0, rc, opt;
986 struct cYAML *err_rc = NULL, *show_rc = NULL;
988 const char *const short_options = "n:g:h:p:v";
989 static const struct option long_options[] = {
990 { .name = "net", .has_arg = required_argument, .val = 'n' },
991 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
992 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
993 { .name = "priority", .has_arg = required_argument, .val = 'p' },
994 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
997 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1001 while ((opt = getopt_long(argc, argv, short_options,
1002 long_options, NULL)) != -1) {
1011 rc = parse_long(optarg, &hop);
1019 rc = parse_long(optarg, &prio);
1030 print_help(route_cmds, "route", "show");
1036 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1037 &show_rc, &err_rc, false);
1039 if (rc != LUSTRE_CFG_RC_NO_ERR)
1040 cYAML_print_tree2file(stderr, err_rc);
1042 cYAML_print_tree(show_rc);
1044 cYAML_free_tree(err_rc);
1045 cYAML_free_tree(show_rc);
1050 static int set_value_helper(int argc, char **argv,
1051 int (*cb)(int, bool, char*, int, struct cYAML**))
1054 long int healthv = -1;
1057 struct cYAML *err_rc = NULL;
1059 const char *const short_options = "t:n:a";
1060 static const struct option long_options[] = {
1061 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1062 { .name = "health", .has_arg = required_argument, .val = 't' },
1063 { .name = "all", .has_arg = no_argument, .val = 'a' },
1066 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1070 while ((opt = getopt_long(argc, argv, short_options,
1071 long_options, NULL)) != -1) {
1077 if (parse_long(optarg, &healthv) != 0)
1088 rc = cb(healthv, all, nid, -1, &err_rc);
1090 if (rc != LUSTRE_CFG_RC_NO_ERR)
1091 cYAML_print_tree2file(stderr, err_rc);
1093 cYAML_free_tree(err_rc);
1098 static int jt_set_ni_value(int argc, char **argv)
1100 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1103 static int jt_set_peer_ni_value(int argc, char **argv)
1105 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1108 static int jt_show_recovery(int argc, char **argv)
1111 struct cYAML *err_rc = NULL, *show_rc = NULL;
1113 const char *const short_options = "lp";
1114 static const struct option long_options[] = {
1115 { .name = "local", .has_arg = no_argument, .val = 'l' },
1116 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1119 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1123 while ((opt = getopt_long(argc, argv, short_options,
1124 long_options, NULL)) != -1) {
1127 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1130 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1137 if (rc != LUSTRE_CFG_RC_NO_ERR)
1138 cYAML_print_tree2file(stderr, err_rc);
1140 cYAML_print_tree(show_rc);
1142 cYAML_free_tree(err_rc);
1143 cYAML_free_tree(show_rc);
1148 static int jt_show_net(int argc, char **argv)
1150 char *network = NULL;
1152 struct cYAML *err_rc = NULL, *show_rc = NULL;
1153 long int detail = 0;
1155 const char *const short_options = "n:v";
1156 static const struct option long_options[] = {
1157 { .name = "net", .has_arg = required_argument, .val = 'n' },
1158 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1161 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1165 while ((opt = getopt_long(argc, argv, short_options,
1166 long_options, NULL)) != -1) {
1172 if ((!optarg) && (argv[optind] != NULL) &&
1173 (argv[optind][0] != '-')) {
1174 if (parse_long(argv[optind++], &detail) != 0)
1181 print_help(net_cmds, "net", "show");
1187 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1190 if (rc != LUSTRE_CFG_RC_NO_ERR)
1191 cYAML_print_tree2file(stderr, err_rc);
1193 cYAML_print_tree(show_rc);
1195 cYAML_free_tree(err_rc);
1196 cYAML_free_tree(show_rc);
1201 static int jt_show_routing(int argc, char **argv)
1203 struct cYAML *err_rc = NULL, *show_rc = NULL;
1206 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1210 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1212 if (rc != LUSTRE_CFG_RC_NO_ERR)
1213 cYAML_print_tree2file(stderr, err_rc);
1215 cYAML_print_tree(show_rc);
1217 cYAML_free_tree(err_rc);
1218 cYAML_free_tree(show_rc);
1223 static int jt_show_stats(int argc, char **argv)
1226 struct cYAML *show_rc = NULL, *err_rc = NULL;
1228 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1232 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1234 if (rc != LUSTRE_CFG_RC_NO_ERR)
1235 cYAML_print_tree2file(stderr, err_rc);
1237 cYAML_print_tree(show_rc);
1239 cYAML_free_tree(err_rc);
1240 cYAML_free_tree(show_rc);
1245 static int jt_show_global(int argc, char **argv)
1248 struct cYAML *show_rc = NULL, *err_rc = NULL;
1250 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1254 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1255 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1256 cYAML_print_tree2file(stderr, err_rc);
1260 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1261 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1262 cYAML_print_tree2file(stderr, err_rc);
1266 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1267 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1268 cYAML_print_tree2file(stderr, err_rc);
1272 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1273 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1274 cYAML_print_tree2file(stderr, err_rc);
1278 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1279 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1280 cYAML_print_tree2file(stderr, err_rc);
1284 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1285 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1286 cYAML_print_tree2file(stderr, err_rc);
1290 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1291 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1292 cYAML_print_tree2file(stderr, err_rc);
1296 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1297 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1298 cYAML_print_tree2file(stderr, err_rc);
1303 cYAML_print_tree(show_rc);
1306 cYAML_free_tree(err_rc);
1307 cYAML_free_tree(show_rc);
1312 static int jt_lnet(int argc, char **argv)
1316 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1320 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1323 static int jt_route(int argc, char **argv)
1327 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1331 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1334 static int jt_net(int argc, char **argv)
1338 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1342 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1345 static int jt_routing(int argc, char **argv)
1349 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1353 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1356 static int jt_stats(int argc, char **argv)
1360 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1364 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1367 static int jt_debug(int argc, char **argv)
1371 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1375 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1378 static int jt_global(int argc, char **argv)
1382 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1386 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1389 static int jt_peers(int argc, char **argv)
1393 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1397 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1400 static int jt_set(int argc, char **argv)
1404 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1408 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1411 static int jt_import(int argc, char **argv)
1414 struct cYAML *err_rc = NULL;
1415 struct cYAML *show_rc = NULL;
1416 int rc = 0, return_rc = 0, opt, opt_found = 0;
1419 const char *const short_options = "adseh";
1420 static const struct option long_options[] = {
1421 { .name = "add", .has_arg = no_argument, .val = 'a' },
1422 { .name = "del", .has_arg = no_argument, .val = 'd' },
1423 { .name = "show", .has_arg = no_argument, .val = 's' },
1424 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1425 { .name = "help", .has_arg = no_argument, .val = 'h' },
1428 while ((opt = getopt_long(argc, argv, short_options,
1429 long_options, NULL)) != -1) {
1443 printf("import FILE\n"
1444 "import < FILE : import a file\n"
1445 "\t--add: add configuration\n"
1446 "\t--del: delete configuration\n"
1447 "\t--show: show configuration\n"
1448 "\t--exec: execute command\n"
1449 "\t--help: display this help\n"
1450 "If no command option is given then --add"
1451 " is assumed by default\n");
1458 /* grab the file name if one exists */
1459 if (opt_found && argc == 3)
1461 else if (!opt_found && argc == 2)
1466 rc = lustre_yaml_config(file, &err_rc);
1467 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1468 cYAML_print_tree(show_rc);
1469 cYAML_free_tree(show_rc);
1472 rc = lustre_yaml_del(file, &err_rc);
1475 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1476 cYAML_print_tree(show_rc);
1477 cYAML_free_tree(show_rc);
1480 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1481 cYAML_print_tree(show_rc);
1482 cYAML_free_tree(show_rc);
1486 if (rc || return_rc) {
1487 cYAML_print_tree2file(stderr, err_rc);
1488 cYAML_free_tree(err_rc);
1494 static int jt_export(int argc, char **argv)
1496 struct cYAML *show_rc = NULL;
1497 struct cYAML *err_rc = NULL;
1501 bool backup = false;
1504 const char *const short_options = "bh";
1505 static const struct option long_options[] = {
1506 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1507 { .name = "help", .has_arg = no_argument, .val = 'h' },
1510 while ((opt = getopt_long(argc, argv, short_options,
1511 long_options, NULL)) != -1) {
1518 printf("export > FILE.yaml : export configuration\n"
1519 "\t--backup: export only what's necessary for reconfig\n"
1520 "\t--help: display this help\n");
1525 if (backup && argc >= 3)
1527 else if (!backup && argc >= 2)
1533 f = fopen(file, "w");
1538 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1539 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1540 cYAML_print_tree2file(stderr, err_rc);
1541 cYAML_free_tree(err_rc);
1545 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1547 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1548 cYAML_print_tree2file(stderr, err_rc);
1549 cYAML_free_tree(err_rc);
1553 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1554 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1555 cYAML_print_tree2file(stderr, err_rc);
1556 cYAML_free_tree(err_rc);
1560 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1561 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1562 cYAML_print_tree2file(stderr, err_rc);
1563 cYAML_free_tree(err_rc);
1567 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1568 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1569 cYAML_print_tree2file(stderr, err_rc);
1570 cYAML_free_tree(err_rc);
1574 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1575 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1576 cYAML_print_tree2file(stderr, err_rc);
1577 cYAML_free_tree(err_rc);
1581 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1582 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1583 cYAML_print_tree2file(stderr, err_rc);
1584 cYAML_free_tree(err_rc);
1588 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1589 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1590 cYAML_print_tree2file(stderr, err_rc);
1591 cYAML_free_tree(err_rc);
1595 if (show_rc != NULL) {
1596 cYAML_print_tree2file(f, show_rc);
1597 cYAML_free_tree(show_rc);
1606 static int jt_add_peer_nid(int argc, char **argv)
1608 char *prim_nid = NULL;
1609 char **nids = NULL, **nids2 = NULL;
1611 struct cYAML *err_rc = NULL;
1612 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1613 bool non_mr = false;
1614 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1616 const char *const short_opts = "k:mn:";
1617 const struct option long_opts[] = {
1618 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1619 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1620 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1621 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1624 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1628 while ((opt = getopt_long(argc, argv, short_opts,
1629 long_opts, NULL)) != -1) {
1632 prim_nid_present = true;
1634 cYAML_build_error(-1, -1, "peer", "add",
1635 "ip2nets can not be specified"
1636 " along side prim_nid parameter.",
1650 if (ip2nets && (nid_list || prim_nid_present)) {
1651 cYAML_build_error(-1, -1, "peer", "add",
1652 "ip2nets can not be specified"
1653 " along side nid or prim_nid"
1654 " parameters", &err_rc);
1658 size = lustre_lnet_parse_nids(optarg, nids, size,
1663 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1669 print_help(peer_cmds, "peer", "add");
1675 for (; optind < argc; optind++) {
1676 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1683 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1684 !non_mr, ip2nets, -1, &err_rc);
1688 /* free the array of nids */
1689 for (i = 0; i < size; i++)
1694 if (rc != LUSTRE_CFG_RC_NO_ERR)
1695 cYAML_print_tree2file(stderr, err_rc);
1697 cYAML_free_tree(err_rc);
1702 static int jt_del_peer_nid(int argc, char **argv)
1704 char *prim_nid = NULL;
1705 char **nids = NULL, **nids2 = NULL;
1706 struct cYAML *err_rc = NULL;
1707 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1708 bool ip2nets = false, nid_list = false, prim_nid_present = false;
1710 const char *const short_opts = "k:n:";
1711 const struct option long_opts[] = {
1712 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1713 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1714 { .name = "ip2nets", .has_arg = required_argument, .val = 'i' },
1717 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1721 while ((opt = getopt_long(argc, argv, short_opts,
1722 long_opts, NULL)) != -1) {
1725 prim_nid_present = true;
1727 cYAML_build_error(-1, -1, "peer", "add",
1728 "ip2nets can not be specified"
1729 " along side prim_nid parameter.",
1743 if (ip2nets && (nid_list || prim_nid_present)) {
1744 cYAML_build_error(-1, -1, "peer", "add",
1745 "ip2nets can not be specified"
1746 " along side nid or prim_nid"
1747 " parameters", &err_rc);
1750 size = lustre_lnet_parse_nids(optarg, nids, size,
1755 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1758 print_help(peer_cmds, "peer", "del");
1764 for (; optind < argc; optind++) {
1765 size = lustre_lnet_parse_nids(argv[optind], nids, size,
1772 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
1776 for (i = 0; i < size; i++)
1781 if (rc != LUSTRE_CFG_RC_NO_ERR)
1782 cYAML_print_tree2file(stderr, err_rc);
1784 cYAML_free_tree(err_rc);
1789 static int jt_show_peer(int argc, char **argv)
1793 struct cYAML *err_rc = NULL, *show_rc = NULL;
1794 long int detail = 0;
1796 const char *const short_opts = "hn:v::";
1797 const struct option long_opts[] = {
1798 { .name = "help", .has_arg = no_argument, .val = 'h' },
1799 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1800 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1803 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1807 while ((opt = getopt_long(argc, argv, short_opts,
1808 long_opts, NULL)) != -1) {
1814 if ((!optarg) && (argv[optind] != NULL) &&
1815 (argv[optind][0] != '-')) {
1816 if (parse_long(argv[optind++], &detail) != 0)
1823 print_help(peer_cmds, "peer", "show");
1829 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1832 if (rc != LUSTRE_CFG_RC_NO_ERR)
1833 cYAML_print_tree2file(stderr, err_rc);
1835 cYAML_print_tree(show_rc);
1837 cYAML_free_tree(err_rc);
1838 cYAML_free_tree(show_rc);
1843 static int jt_list_peer(int argc, char **argv)
1846 struct cYAML *err_rc = NULL, *list_rc = NULL;
1848 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1852 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1854 if (rc != LUSTRE_CFG_RC_NO_ERR)
1855 cYAML_print_tree2file(stderr, err_rc);
1857 cYAML_print_tree(list_rc);
1859 cYAML_free_tree(err_rc);
1860 cYAML_free_tree(list_rc);
1865 static int jt_ping(int argc, char **argv)
1867 struct cYAML *err_rc = NULL;
1868 struct cYAML *show_rc = NULL;
1872 const char *const short_options = "ht:";
1873 const struct option long_options[] = {
1874 { .name = "help", .has_arg = no_argument, .val = 'h' },
1875 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1878 while ((opt = getopt_long(argc, argv, short_options,
1879 long_options, NULL)) != -1) {
1882 timeout = 1000 * atol(optarg);
1885 printf("ping nid[,nid,...]\n"
1886 "\t --timeout: ping timeout\n"
1887 "\t --help: display this help\n");
1894 for (; optind < argc; optind++)
1895 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1898 cYAML_print_tree(show_rc);
1901 cYAML_print_tree2file(stderr, err_rc);
1903 cYAML_free_tree(err_rc);
1904 cYAML_free_tree(show_rc);
1909 static int jt_discover(int argc, char **argv)
1911 struct cYAML *err_rc = NULL;
1912 struct cYAML *show_rc = NULL;
1916 const char *const short_options = "fh";
1917 const struct option long_options[] = {
1918 { .name = "force", .has_arg = no_argument, .val = 'f' },
1919 { .name = "help", .has_arg = no_argument, .val = 'h' },
1922 while ((opt = getopt_long(argc, argv, short_options,
1923 long_options, NULL)) != -1) {
1929 printf("discover nid[,nid,...]\n"
1930 "\t --force: force discovery\n"
1931 "\t --help: display this help\n");
1938 for (; optind < argc; optind++)
1939 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1943 cYAML_print_tree(show_rc);
1946 cYAML_print_tree2file(stderr, err_rc);
1948 cYAML_free_tree(err_rc);
1949 cYAML_free_tree(show_rc);
1954 static int lnetctl_list_commands(int argc, char **argv)
1956 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1958 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1963 int main(int argc, char **argv)
1966 struct cYAML *err_rc = NULL;
1968 rc = lustre_lnet_config_lib_init();
1970 cYAML_build_error(-1, -1, "lnetctl", "startup",
1971 "cannot register LNet device", &err_rc);
1972 cYAML_print_tree2file(stderr, err_rc);
1976 Parser_init("lnetctl > ", cmd_list);
1978 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);