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.\n"
225 "\t--nid: one or more peer NIDs\n"
226 "\t--non_mr: create this peer as not Multi-Rail capable\n"
227 "\t--ip2nets: specify a range of nids per peer"},
228 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
229 "\t--prim_nid: Primary NID of the peer.\n"
230 "\t--nid: list of NIDs to remove. If none provided,\n"
231 "\t peer is deleted\n"
232 "\t--ip2nets: specify a range of nids per peer"},
233 {"show", jt_show_peer, 0, "show peer information\n"
234 "\t--nid: NID of peer to filter on.\n"
235 "\t--verbose: display detailed output per peer."
236 " Optional argument of '2' outputs more stats\n"},
237 {"list", jt_list_peer, 0, "list all peers\n"},
238 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
239 "\t--nid: Peer NI NID to set the\n"
240 "\t--health: specify health value to set\n"
241 "\t--all: set all peer_nis values to the one specified\n"},
245 static int jt_calc_service_id(int argc, char **argv)
250 rc = lustre_lnet_calc_service_id(&service_id);
251 if (rc != LUSTRE_CFG_RC_NO_ERR)
255 * cYAML currently doesn't support printing hex values.
256 * Therefore just print it locally here
258 printf("service id:\n value: 0x%llx\n", service_id);
263 static inline void print_help(const command_t cmds[], const char *cmd_type,
266 const command_t *cmd;
268 for (cmd = cmds; cmd->pc_name; cmd++) {
269 if (pc_name != NULL &&
270 strcmp(cmd->pc_name, pc_name) == 0) {
271 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
274 } else if (pc_name != NULL) {
277 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
281 static int parse_long(const char *number, long int *value)
288 *value = strtol(number, &end, 0);
289 if (end != NULL && *end != 0)
295 static int check_cmd(const command_t *cmd_list, const char *cmd,
296 const char *sub_cmd, const int min_args,
297 int argc, char **argv)
304 const char *const short_options = "h";
305 static const struct option long_options[] = {
306 { .name = "help", .has_arg = no_argument, .val = 'h' },
310 if (argc < min_args) {
311 print_help(cmd_list, cmd, sub_cmd);
314 } else if (argc > 2) {
318 while ((opt = getopt_long(argc, argv, short_options,
319 long_options, NULL)) != -1) {
322 print_help(cmd_list, cmd, sub_cmd);
337 static int jt_set_max_intf(int argc, char **argv)
341 struct cYAML *err_rc = NULL;
343 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
347 rc = parse_long(argv[1], &value);
349 cYAML_build_error(-1, -1, "parser", "set",
350 "cannot parse max_interfaces value", &err_rc);
351 cYAML_print_tree2file(stderr, err_rc);
352 cYAML_free_tree(err_rc);
356 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
357 if (rc != LUSTRE_CFG_RC_NO_ERR)
358 cYAML_print_tree2file(stderr, err_rc);
360 cYAML_free_tree(err_rc);
365 static int jt_set_numa(int argc, char **argv)
369 struct cYAML *err_rc = NULL;
371 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
375 rc = parse_long(argv[1], &value);
377 cYAML_build_error(-1, -1, "parser", "set",
378 "cannot parse numa_range value", &err_rc);
379 cYAML_print_tree2file(stderr, err_rc);
380 cYAML_free_tree(err_rc);
384 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
385 if (rc != LUSTRE_CFG_RC_NO_ERR)
386 cYAML_print_tree2file(stderr, err_rc);
388 cYAML_free_tree(err_rc);
393 static int jt_set_recov_intrv(int argc, char **argv)
397 struct cYAML *err_rc = NULL;
399 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
403 rc = parse_long(argv[1], &value);
405 cYAML_build_error(-1, -1, "parser", "set",
406 "cannot parse recovery interval value", &err_rc);
407 cYAML_print_tree2file(stderr, err_rc);
408 cYAML_free_tree(err_rc);
412 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
413 if (rc != LUSTRE_CFG_RC_NO_ERR)
414 cYAML_print_tree2file(stderr, err_rc);
416 cYAML_free_tree(err_rc);
421 static int jt_set_rtr_sensitivity(int argc, char **argv)
425 struct cYAML *err_rc = NULL;
427 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
431 rc = parse_long(argv[1], &value);
433 cYAML_build_error(-1, -1, "parser", "set",
434 "cannot parse router sensitivity value", &err_rc);
435 cYAML_print_tree2file(stderr, err_rc);
436 cYAML_free_tree(err_rc);
440 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
441 if (rc != LUSTRE_CFG_RC_NO_ERR)
442 cYAML_print_tree2file(stderr, err_rc);
444 cYAML_free_tree(err_rc);
449 static int jt_set_hsensitivity(int argc, char **argv)
453 struct cYAML *err_rc = NULL;
455 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
459 rc = parse_long(argv[1], &value);
461 cYAML_build_error(-1, -1, "parser", "set",
462 "cannot parse health sensitivity value", &err_rc);
463 cYAML_print_tree2file(stderr, err_rc);
464 cYAML_free_tree(err_rc);
468 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
469 if (rc != LUSTRE_CFG_RC_NO_ERR)
470 cYAML_print_tree2file(stderr, err_rc);
472 cYAML_free_tree(err_rc);
477 static int jt_set_transaction_to(int argc, char **argv)
481 struct cYAML *err_rc = NULL;
483 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
487 rc = parse_long(argv[1], &value);
489 cYAML_build_error(-1, -1, "parser", "set",
490 "cannot parse transaction timeout value", &err_rc);
491 cYAML_print_tree2file(stderr, err_rc);
492 cYAML_free_tree(err_rc);
496 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
497 if (rc != LUSTRE_CFG_RC_NO_ERR)
498 cYAML_print_tree2file(stderr, err_rc);
500 cYAML_free_tree(err_rc);
505 static int jt_set_retry_count(int argc, char **argv)
509 struct cYAML *err_rc = NULL;
511 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
515 rc = parse_long(argv[1], &value);
517 cYAML_build_error(-1, -1, "parser", "set",
518 "cannot parse retry_count value", &err_rc);
519 cYAML_print_tree2file(stderr, err_rc);
520 cYAML_free_tree(err_rc);
524 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
525 if (rc != LUSTRE_CFG_RC_NO_ERR)
526 cYAML_print_tree2file(stderr, err_rc);
528 cYAML_free_tree(err_rc);
533 static int jt_set_discovery(int argc, char **argv)
537 struct cYAML *err_rc = NULL;
539 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
543 rc = parse_long(argv[1], &value);
545 cYAML_build_error(-1, -1, "parser", "set",
546 "cannot parse discovery value", &err_rc);
547 cYAML_print_tree2file(stderr, err_rc);
548 cYAML_free_tree(err_rc);
552 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
553 if (rc != LUSTRE_CFG_RC_NO_ERR)
554 cYAML_print_tree2file(stderr, err_rc);
556 cYAML_free_tree(err_rc);
561 static int jt_set_drop_asym_route(int argc, char **argv)
565 struct cYAML *err_rc = NULL;
567 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
571 rc = parse_long(argv[1], &value);
573 cYAML_build_error(-1, -1, "parser", "set",
574 "cannot parse drop_asym_route value",
576 cYAML_print_tree2file(stderr, err_rc);
577 cYAML_free_tree(err_rc);
581 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
582 if (rc != LUSTRE_CFG_RC_NO_ERR)
583 cYAML_print_tree2file(stderr, err_rc);
585 cYAML_free_tree(err_rc);
590 static int jt_set_tiny(int argc, char **argv)
594 struct cYAML *err_rc = NULL;
596 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
600 rc = parse_long(argv[1], &value);
602 cYAML_build_error(-1, -1, "parser", "set",
603 "cannot parse tiny_buffers value", &err_rc);
604 cYAML_print_tree2file(stderr, err_rc);
605 cYAML_free_tree(err_rc);
609 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
610 if (rc != LUSTRE_CFG_RC_NO_ERR)
611 cYAML_print_tree2file(stderr, err_rc);
613 cYAML_free_tree(err_rc);
618 static int jt_set_small(int argc, char **argv)
622 struct cYAML *err_rc = NULL;
624 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
628 rc = parse_long(argv[1], &value);
630 cYAML_build_error(-1, -1, "parser", "set",
631 "cannot parse small_buffers value", &err_rc);
632 cYAML_print_tree2file(stderr, err_rc);
633 cYAML_free_tree(err_rc);
637 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
638 if (rc != LUSTRE_CFG_RC_NO_ERR)
639 cYAML_print_tree2file(stderr, err_rc);
641 cYAML_free_tree(err_rc);
646 static int jt_set_large(int argc, char **argv)
650 struct cYAML *err_rc = NULL;
652 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
656 rc = parse_long(argv[1], &value);
658 cYAML_build_error(-1, -1, "parser", "set",
659 "cannot parse large_buffers value", &err_rc);
660 cYAML_print_tree2file(stderr, err_rc);
661 cYAML_free_tree(err_rc);
665 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
666 if (rc != LUSTRE_CFG_RC_NO_ERR)
667 cYAML_print_tree2file(stderr, err_rc);
669 cYAML_free_tree(err_rc);
674 static int jt_set_routing(int argc, char **argv)
677 struct cYAML *err_rc = NULL;
680 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
684 rc = parse_long(argv[1], &value);
685 if (rc != 0 || (value != 0 && value != 1)) {
686 cYAML_build_error(-1, -1, "parser", "set",
687 "cannot parse routing value.\n"
688 "must be 0 for disable or 1 for enable",
690 cYAML_print_tree2file(stderr, err_rc);
691 cYAML_free_tree(err_rc);
695 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
697 if (rc != LUSTRE_CFG_RC_NO_ERR)
698 cYAML_print_tree2file(stderr, err_rc);
700 cYAML_free_tree(err_rc);
705 static int jt_config_lnet(int argc, char **argv)
707 struct cYAML *err_rc = NULL;
708 bool load_mod_params = false;
711 const char *const short_options = "a";
712 static const struct option long_options[] = {
713 { .name = "all", .has_arg = no_argument, .val = 'a' },
717 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
721 while ((opt = getopt_long(argc, argv, short_options,
722 long_options, NULL)) != -1) {
725 load_mod_params = true;
732 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
735 if (rc != LUSTRE_CFG_RC_NO_ERR)
736 cYAML_print_tree2file(stderr, err_rc);
738 cYAML_free_tree(err_rc);
743 static int jt_unconfig_lnet(int argc, char **argv)
745 struct cYAML *err_rc = NULL;
748 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
752 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
754 if (rc != LUSTRE_CFG_RC_NO_ERR)
755 cYAML_print_tree2file(stderr, err_rc);
757 cYAML_free_tree(err_rc);
761 static int jt_add_route(int argc, char **argv)
763 char *network = NULL, *gateway = NULL;
764 long int hop = -1, prio = -1, sen = -1;
765 struct cYAML *err_rc = NULL;
768 const char *const short_options = "n:g:c:p:";
769 static const struct option long_options[] = {
770 { .name = "net", .has_arg = required_argument, .val = 'n' },
771 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
772 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
773 { .name = "priority", .has_arg = required_argument, .val = 'p' },
774 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
777 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
781 while ((opt = getopt_long(argc, argv, short_options,
782 long_options, NULL)) != -1) {
791 rc = parse_long(optarg, &hop);
799 rc = parse_long(optarg, &prio);
807 rc = parse_long(optarg, &sen);
816 print_help(route_cmds, "route", "add");
822 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
825 if (rc != LUSTRE_CFG_RC_NO_ERR)
826 cYAML_print_tree2file(stderr, err_rc);
828 cYAML_free_tree(err_rc);
833 static int jt_add_ni(int argc, char **argv)
836 long int pto = -1, pc = -1, pbc = -1, cre = -1;
837 struct cYAML *err_rc = NULL;
838 int rc, opt, cpt_rc = -1;
839 struct lnet_dlc_network_descr nw_descr;
840 struct cfs_expr_list *global_cpts = NULL;
841 struct lnet_ioctl_config_lnd_tunables tunables;
844 memset(&tunables, 0, sizeof(tunables));
845 lustre_lnet_init_nw_descr(&nw_descr);
847 const char *const short_options = "n:i:p:t:c:b:r:s:";
848 static const struct option long_options[] = {
849 { .name = "net", .has_arg = required_argument, .val = 'n' },
850 { .name = "if", .has_arg = required_argument, .val = 'i' },
851 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
852 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
853 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
854 { .name = "peer-buffer-credits",
855 .has_arg = required_argument, .val = 'b' },
856 { .name = "credits", .has_arg = required_argument, .val = 'r' },
857 { .name = "cpt", .has_arg = required_argument, .val = 's' },
860 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
864 while ((opt = getopt_long(argc, argv, short_options,
865 long_options, NULL)) != -1) {
868 nw_descr.nw_id = libcfs_str2net(optarg);
871 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
873 cYAML_build_error(-1, -1, "ni", "add",
874 "bad interface list",
883 rc = parse_long(optarg, &pto);
891 rc = parse_long(optarg, &pc);
899 rc = parse_long(optarg, &pbc);
907 rc = parse_long(optarg, &cre);
915 cpt_rc = cfs_expr_list_parse(optarg,
917 UINT_MAX, &global_cpts);
920 print_help(net_cmds, "net", "add");
926 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
927 tunables.lt_cmn.lct_peer_timeout = pto;
928 tunables.lt_cmn.lct_peer_tx_credits = pc;
929 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
930 tunables.lt_cmn.lct_max_tx_credits = cre;
934 rc = lustre_lnet_config_ni(&nw_descr,
935 (cpt_rc == 0) ? global_cpts: NULL,
936 ip2net, (found) ? &tunables : NULL,
939 if (global_cpts != NULL)
940 cfs_expr_list_free(global_cpts);
943 if (rc != LUSTRE_CFG_RC_NO_ERR)
944 cYAML_print_tree2file(stderr, err_rc);
946 cYAML_free_tree(err_rc);
951 static int jt_del_route(int argc, char **argv)
953 char *network = NULL, *gateway = NULL;
954 struct cYAML *err_rc = NULL;
957 const char *const short_options = "n:g:";
958 static const struct option long_options[] = {
959 { .name = "net", .has_arg = required_argument, .val = 'n' },
960 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
963 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
967 while ((opt = getopt_long(argc, argv, short_options,
968 long_options, NULL)) != -1) {
977 print_help(route_cmds, "route", "del");
983 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
985 if (rc != LUSTRE_CFG_RC_NO_ERR)
986 cYAML_print_tree2file(stderr, err_rc);
988 cYAML_free_tree(err_rc);
993 static int jt_del_ni(int argc, char **argv)
995 struct cYAML *err_rc = NULL;
997 struct lnet_dlc_network_descr nw_descr;
999 lustre_lnet_init_nw_descr(&nw_descr);
1001 const char *const short_options = "n:i:";
1002 static const struct option long_options[] = {
1003 { .name = "net", .has_arg = required_argument, .val = 'n' },
1004 { .name = "if", .has_arg = required_argument, .val = 'i' },
1007 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1011 while ((opt = getopt_long(argc, argv, short_options,
1012 long_options, NULL)) != -1) {
1015 nw_descr.nw_id = libcfs_str2net(optarg);
1018 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1020 cYAML_build_error(-1, -1, "ni", "add",
1021 "bad interface list",
1027 print_help(net_cmds, "net", "del");
1033 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1036 if (rc != LUSTRE_CFG_RC_NO_ERR)
1037 cYAML_print_tree2file(stderr, err_rc);
1039 cYAML_free_tree(err_rc);
1044 static int jt_show_route(int argc, char **argv)
1046 char *network = NULL, *gateway = NULL;
1047 long int hop = -1, prio = -1;
1048 int detail = 0, rc, opt;
1049 struct cYAML *err_rc = NULL, *show_rc = NULL;
1051 const char *const short_options = "n:g:h:p:v";
1052 static const struct option long_options[] = {
1053 { .name = "net", .has_arg = required_argument, .val = 'n' },
1054 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1055 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1056 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1057 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1060 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1064 while ((opt = getopt_long(argc, argv, short_options,
1065 long_options, NULL)) != -1) {
1074 rc = parse_long(optarg, &hop);
1082 rc = parse_long(optarg, &prio);
1093 print_help(route_cmds, "route", "show");
1099 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1100 &show_rc, &err_rc, false);
1102 if (rc != LUSTRE_CFG_RC_NO_ERR)
1103 cYAML_print_tree2file(stderr, err_rc);
1105 cYAML_print_tree(show_rc);
1107 cYAML_free_tree(err_rc);
1108 cYAML_free_tree(show_rc);
1113 static int set_value_helper(int argc, char **argv,
1114 int (*cb)(int, bool, char*, int, struct cYAML**))
1117 long int healthv = -1;
1120 struct cYAML *err_rc = NULL;
1122 const char *const short_options = "t:n:a";
1123 static const struct option long_options[] = {
1124 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1125 { .name = "health", .has_arg = required_argument, .val = 't' },
1126 { .name = "all", .has_arg = no_argument, .val = 'a' },
1129 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1133 while ((opt = getopt_long(argc, argv, short_options,
1134 long_options, NULL)) != -1) {
1140 if (parse_long(optarg, &healthv) != 0)
1151 rc = cb(healthv, all, nid, -1, &err_rc);
1153 if (rc != LUSTRE_CFG_RC_NO_ERR)
1154 cYAML_print_tree2file(stderr, err_rc);
1156 cYAML_free_tree(err_rc);
1161 static int jt_set_ni_value(int argc, char **argv)
1163 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1166 static int jt_set_peer_ni_value(int argc, char **argv)
1168 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1171 static int jt_show_recovery(int argc, char **argv)
1174 struct cYAML *err_rc = NULL, *show_rc = NULL;
1176 const char *const short_options = "lp";
1177 static const struct option long_options[] = {
1178 { .name = "local", .has_arg = no_argument, .val = 'l' },
1179 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1182 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1186 while ((opt = getopt_long(argc, argv, short_options,
1187 long_options, NULL)) != -1) {
1190 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1193 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1200 if (rc != LUSTRE_CFG_RC_NO_ERR)
1201 cYAML_print_tree2file(stderr, err_rc);
1203 cYAML_print_tree(show_rc);
1205 cYAML_free_tree(err_rc);
1206 cYAML_free_tree(show_rc);
1211 static int jt_show_net(int argc, char **argv)
1213 char *network = NULL;
1215 struct cYAML *err_rc = NULL, *show_rc = NULL;
1216 long int detail = 0;
1218 const char *const short_options = "n:v";
1219 static const struct option long_options[] = {
1220 { .name = "net", .has_arg = required_argument, .val = 'n' },
1221 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1224 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1228 while ((opt = getopt_long(argc, argv, short_options,
1229 long_options, NULL)) != -1) {
1235 if ((!optarg) && (argv[optind] != NULL) &&
1236 (argv[optind][0] != '-')) {
1237 if (parse_long(argv[optind++], &detail) != 0)
1244 print_help(net_cmds, "net", "show");
1250 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1253 if (rc != LUSTRE_CFG_RC_NO_ERR)
1254 cYAML_print_tree2file(stderr, err_rc);
1256 cYAML_print_tree(show_rc);
1258 cYAML_free_tree(err_rc);
1259 cYAML_free_tree(show_rc);
1264 static int jt_show_routing(int argc, char **argv)
1266 struct cYAML *err_rc = NULL, *show_rc = NULL;
1269 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1273 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1275 if (rc != LUSTRE_CFG_RC_NO_ERR)
1276 cYAML_print_tree2file(stderr, err_rc);
1278 cYAML_print_tree(show_rc);
1280 cYAML_free_tree(err_rc);
1281 cYAML_free_tree(show_rc);
1286 static int jt_show_stats(int argc, char **argv)
1289 struct cYAML *show_rc = NULL, *err_rc = NULL;
1291 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1295 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1297 if (rc != LUSTRE_CFG_RC_NO_ERR)
1298 cYAML_print_tree2file(stderr, err_rc);
1300 cYAML_print_tree(show_rc);
1302 cYAML_free_tree(err_rc);
1303 cYAML_free_tree(show_rc);
1308 static int jt_show_global(int argc, char **argv)
1311 struct cYAML *show_rc = NULL, *err_rc = NULL;
1313 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1317 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1318 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1319 cYAML_print_tree2file(stderr, err_rc);
1323 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1324 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1325 cYAML_print_tree2file(stderr, err_rc);
1329 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1330 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1331 cYAML_print_tree2file(stderr, err_rc);
1335 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1336 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1337 cYAML_print_tree2file(stderr, err_rc);
1341 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1342 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1343 cYAML_print_tree2file(stderr, err_rc);
1347 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1348 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1349 cYAML_print_tree2file(stderr, err_rc);
1353 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1354 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1355 cYAML_print_tree2file(stderr, err_rc);
1359 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1360 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1361 cYAML_print_tree2file(stderr, err_rc);
1365 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1366 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1367 cYAML_print_tree2file(stderr, err_rc);
1371 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1372 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1373 cYAML_print_tree2file(stderr, err_rc);
1378 cYAML_print_tree(show_rc);
1381 cYAML_free_tree(err_rc);
1382 cYAML_free_tree(show_rc);
1387 static int jt_lnet(int argc, char **argv)
1391 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1395 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1398 static int jt_route(int argc, char **argv)
1402 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1406 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1409 static int jt_net(int argc, char **argv)
1413 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1417 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1420 static int jt_routing(int argc, char **argv)
1424 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1428 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1431 static int jt_stats(int argc, char **argv)
1435 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1439 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1442 static int jt_debug(int argc, char **argv)
1446 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1450 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1453 static int jt_global(int argc, char **argv)
1457 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1461 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1464 static int jt_peers(int argc, char **argv)
1468 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1472 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1475 static int jt_set(int argc, char **argv)
1479 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1483 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1486 static int jt_import(int argc, char **argv)
1489 struct cYAML *err_rc = NULL;
1490 struct cYAML *show_rc = NULL;
1491 int rc = 0, return_rc = 0, opt, opt_found = 0;
1494 const char *const short_options = "adseh";
1495 static const struct option long_options[] = {
1496 { .name = "add", .has_arg = no_argument, .val = 'a' },
1497 { .name = "del", .has_arg = no_argument, .val = 'd' },
1498 { .name = "show", .has_arg = no_argument, .val = 's' },
1499 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1500 { .name = "help", .has_arg = no_argument, .val = 'h' },
1503 while ((opt = getopt_long(argc, argv, short_options,
1504 long_options, NULL)) != -1) {
1518 printf("import FILE\n"
1519 "import < FILE : import a file\n"
1520 "\t--add: add configuration\n"
1521 "\t--del: delete configuration\n"
1522 "\t--show: show configuration\n"
1523 "\t--exec: execute command\n"
1524 "\t--help: display this help\n"
1525 "If no command option is given then --add"
1526 " is assumed by default\n");
1533 /* grab the file name if one exists */
1534 if (opt_found && argc == 3)
1536 else if (!opt_found && argc == 2)
1541 rc = lustre_yaml_config(file, &err_rc);
1542 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1543 cYAML_print_tree(show_rc);
1544 cYAML_free_tree(show_rc);
1547 rc = lustre_yaml_del(file, &err_rc);
1550 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1551 cYAML_print_tree(show_rc);
1552 cYAML_free_tree(show_rc);
1555 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1556 cYAML_print_tree(show_rc);
1557 cYAML_free_tree(show_rc);
1561 if (rc || return_rc) {
1562 cYAML_print_tree2file(stderr, err_rc);
1563 cYAML_free_tree(err_rc);
1569 static int jt_export(int argc, char **argv)
1571 struct cYAML *show_rc = NULL;
1572 struct cYAML *err_rc = NULL;
1576 bool backup = false;
1579 const char *const short_options = "bh";
1580 static const struct option long_options[] = {
1581 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1582 { .name = "help", .has_arg = no_argument, .val = 'h' },
1585 while ((opt = getopt_long(argc, argv, short_options,
1586 long_options, NULL)) != -1) {
1593 printf("export > FILE.yaml : export configuration\n"
1594 "\t--backup: export only what's necessary for reconfig\n"
1595 "\t--help: display this help\n");
1600 if (backup && argc >= 3)
1602 else if (!backup && argc >= 2)
1608 f = fopen(file, "w");
1613 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1614 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1615 cYAML_print_tree2file(stderr, err_rc);
1616 cYAML_free_tree(err_rc);
1620 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1622 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1623 cYAML_print_tree2file(stderr, err_rc);
1624 cYAML_free_tree(err_rc);
1628 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1629 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1630 cYAML_print_tree2file(stderr, err_rc);
1631 cYAML_free_tree(err_rc);
1635 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1636 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1637 cYAML_print_tree2file(stderr, err_rc);
1638 cYAML_free_tree(err_rc);
1642 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1643 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1644 cYAML_print_tree2file(stderr, err_rc);
1645 cYAML_free_tree(err_rc);
1649 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1650 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1651 cYAML_print_tree2file(stderr, err_rc);
1652 cYAML_free_tree(err_rc);
1656 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1657 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1658 cYAML_print_tree2file(stderr, err_rc);
1659 cYAML_free_tree(err_rc);
1663 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1664 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1665 cYAML_print_tree2file(stderr, err_rc);
1666 cYAML_free_tree(err_rc);
1670 if (show_rc != NULL) {
1671 cYAML_print_tree2file(f, show_rc);
1672 cYAML_free_tree(show_rc);
1681 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1683 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1685 char *prim_nid = NULL, *nidstr = NULL;
1686 char err_str[LNET_MAX_STR_LEN] = "Error";
1687 struct cYAML *err_rc = NULL;
1689 const char *const short_opts = "k:mn:";
1690 const struct option long_opts[] = {
1691 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1692 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1693 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1696 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1700 while ((opt = getopt_long(argc, argv, short_opts,
1701 long_opts, NULL)) != -1) {
1710 if (cmd == LNETCTL_DEL_CMD) {
1711 rc = LUSTRE_CFG_RC_BAD_PARAM;
1712 snprintf(err_str, LNET_MAX_STR_LEN,
1713 "Unrecognized option '-%c'", opt);
1719 print_help(peer_cmds, "peer",
1720 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1726 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
1728 if (rc != LUSTRE_CFG_RC_NO_ERR)
1732 cYAML_build_error(rc, -1, "peer",
1733 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1737 if (rc != LUSTRE_CFG_RC_NO_ERR)
1738 cYAML_print_tree2file(stderr, err_rc);
1740 cYAML_free_tree(err_rc);
1745 static int jt_add_peer_nid(int argc, char **argv)
1747 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1750 static int jt_del_peer_nid(int argc, char **argv)
1752 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1755 static int jt_show_peer(int argc, char **argv)
1759 struct cYAML *err_rc = NULL, *show_rc = NULL;
1760 long int detail = 0;
1762 const char *const short_opts = "hn:v::";
1763 const struct option long_opts[] = {
1764 { .name = "help", .has_arg = no_argument, .val = 'h' },
1765 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1766 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1769 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1773 while ((opt = getopt_long(argc, argv, short_opts,
1774 long_opts, NULL)) != -1) {
1780 if ((!optarg) && (argv[optind] != NULL) &&
1781 (argv[optind][0] != '-')) {
1782 if (parse_long(argv[optind++], &detail) != 0)
1789 print_help(peer_cmds, "peer", "show");
1795 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1798 if (rc != LUSTRE_CFG_RC_NO_ERR)
1799 cYAML_print_tree2file(stderr, err_rc);
1801 cYAML_print_tree(show_rc);
1803 cYAML_free_tree(err_rc);
1804 cYAML_free_tree(show_rc);
1809 static int jt_list_peer(int argc, char **argv)
1812 struct cYAML *err_rc = NULL, *list_rc = NULL;
1814 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1818 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1820 if (rc != LUSTRE_CFG_RC_NO_ERR)
1821 cYAML_print_tree2file(stderr, err_rc);
1823 cYAML_print_tree(list_rc);
1825 cYAML_free_tree(err_rc);
1826 cYAML_free_tree(list_rc);
1831 static int jt_ping(int argc, char **argv)
1833 struct cYAML *err_rc = NULL;
1834 struct cYAML *show_rc = NULL;
1838 const char *const short_options = "ht:";
1839 const struct option long_options[] = {
1840 { .name = "help", .has_arg = no_argument, .val = 'h' },
1841 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1844 while ((opt = getopt_long(argc, argv, short_options,
1845 long_options, NULL)) != -1) {
1848 timeout = 1000 * atol(optarg);
1851 printf("ping nid[,nid,...]\n"
1852 "\t --timeout: ping timeout\n"
1853 "\t --help: display this help\n");
1860 for (; optind < argc; optind++)
1861 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1864 cYAML_print_tree(show_rc);
1867 cYAML_print_tree2file(stderr, err_rc);
1869 cYAML_free_tree(err_rc);
1870 cYAML_free_tree(show_rc);
1875 static int jt_discover(int argc, char **argv)
1877 struct cYAML *err_rc = NULL;
1878 struct cYAML *show_rc = NULL;
1882 const char *const short_options = "fh";
1883 const struct option long_options[] = {
1884 { .name = "force", .has_arg = no_argument, .val = 'f' },
1885 { .name = "help", .has_arg = no_argument, .val = 'h' },
1888 while ((opt = getopt_long(argc, argv, short_options,
1889 long_options, NULL)) != -1) {
1895 printf("discover nid[,nid,...]\n"
1896 "\t --force: force discovery\n"
1897 "\t --help: display this help\n");
1904 for (; optind < argc; optind++)
1905 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1909 cYAML_print_tree(show_rc);
1912 cYAML_print_tree2file(stderr, err_rc);
1914 cYAML_free_tree(err_rc);
1915 cYAML_free_tree(show_rc);
1920 static int lnetctl_list_commands(int argc, char **argv)
1922 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1924 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1929 int main(int argc, char **argv)
1932 struct cYAML *err_rc = NULL;
1934 rc = lustre_lnet_config_lib_init();
1936 cYAML_build_error(-1, -1, "lnetctl", "startup",
1937 "cannot register LNet device", &err_rc);
1938 cYAML_print_tree2file(stderr, err_rc);
1942 Parser_init("lnetctl > ", cmd_list);
1944 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);