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);
86 static int jt_set_response_tracking(int argc, char **argv);
88 command_t cmd_list[] = {
89 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
90 {"route", jt_route, 0, "route {add | del | show | help}"},
91 {"net", jt_net, 0, "net {add | del | show | help}"},
92 {"routing", jt_routing, 0, "routing {show | help}"},
93 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
94 " | routing | numa_range | max_interfaces"
96 {"import", jt_import, 0, "import FILE.yaml"},
97 {"export", jt_export, 0, "export FILE.yaml"},
98 {"stats", jt_stats, 0, "stats {show | help}"},
99 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
100 {"global", jt_global, 0, "global {show | help}"},
101 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
102 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
103 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
104 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
105 {"help", Parser_help, 0, "help"},
106 {"exit", Parser_quit, 0, "quit"},
107 {"quit", Parser_quit, 0, "quit"},
108 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
112 command_t lnet_cmds[] = {
113 {"configure", jt_config_lnet, 0, "configure lnet\n"
114 "\t--all: load NI configuration from module parameters\n"},
115 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
119 command_t route_cmds[] = {
120 {"add", jt_add_route, 0, "add a route\n"
121 "\t--net: net name (e.g. tcp0)\n"
122 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
123 "\t--hop: number to final destination (1 < hops < 255)\n"
124 "\t--priority: priority of route (0 - highest prio\n"
125 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
126 {"del", jt_del_route, 0, "delete a route\n"
127 "\t--net: net name (e.g. tcp0)\n"
128 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
129 {"show", jt_show_route, 0, "show routes\n"
130 "\t--net: net name (e.g. tcp0) to filter on\n"
131 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
132 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
133 "\t--priority: priority of route (0 - highest prio to filter on\n"
134 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
135 "\t--verbose: display detailed output per route\n"},
139 command_t net_cmds[] = {
140 {"add", jt_add_ni, 0, "add a network\n"
141 "\t--net: net name (e.g. tcp0)\n"
142 "\t--if: physical interface (e.g. eth0)\n"
143 "\t--ip2net: specify networks based on IP address patterns\n"
144 "\t--peer-timeout: time to wait before declaring a peer dead\n"
145 "\t--peer-credits: define the max number of inflight messages\n"
146 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
147 "\t--credits: Network Interface credits\n"
148 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
149 {"del", jt_del_ni, 0, "delete a network\n"
150 "\t--net: net name (e.g. tcp0)\n"
151 "\t--if: physical interface (e.g. eth0)\n"},
152 {"show", jt_show_net, 0, "show networks\n"
153 "\t--net: net name (e.g. tcp0) to filter on\n"
154 "\t--verbose: display detailed output per network."
155 " Optional argument of '2' outputs more stats\n"},
156 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
157 "\t--nid: NI NID to set the\n"
158 "\t--health: specify health value to set\n"
159 "\t--all: set all NIs value to the one specified\n"},
163 command_t routing_cmds[] = {
164 {"show", jt_show_routing, 0, "show routing information\n"},
168 command_t stats_cmds[] = {
169 {"show", jt_show_stats, 0, "show LNET statistics\n"},
173 command_t debug_cmds[] = {
174 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
175 "\t--local : list local recovery queue\n"
176 "\t--peer : list peer recovery queue\n"},
180 command_t global_cmds[] = {
181 {"show", jt_show_global, 0, "show global variables\n"},
185 command_t set_cmds[] = {
186 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
187 "\tVALUE must be greater than 0\n"},
188 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
189 "\tVALUE must be greater than 0\n"},
190 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
191 "\tVALUE must be greater than 0\n"},
192 {"routing", jt_set_routing, 0, "enable/disable routing\n"
193 "\t0 - disable routing\n"
194 "\t1 - enable routing\n"},
195 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
196 "\tVALUE must be at least 0\n"},
197 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
199 "\tValue must be greater than 16\n"},
200 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
201 "\t0 - disable peer discovery\n"
202 "\t1 - enable peer discovery (default)\n"},
203 {"drop_asym_route", jt_set_drop_asym_route, 0,
204 "drop/accept asymmetrical route messages\n"
205 "\t0 - accept asymmetrical route messages (default)\n"
206 "\t1 - drop asymmetrical route messages\n"},
207 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
208 "\t0 - turn of retries\n"
209 "\t>0 - number of retries\n"},
210 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
211 "\t>0 - timeout in seconds\n"},
212 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
213 "\t0 - turn off health evaluation\n"
214 "\t>0 - sensitivity value not more than 1000\n"},
215 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
216 "\t>0 - time in seconds between pings\n"},
217 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
218 "\t100 - router interfaces need to be fully healthy to be used\n"
219 "\t<100 - router interfaces can be used even if not healthy\n"},
220 {"response_tracking", jt_set_response_tracking, 0,
221 "Set the behavior of response tracking\n"
222 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
223 "\t1 - GETs are eligible for response tracking\n"
224 "\t2 - PUTs are eligible for response tracking\n"
225 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
226 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
227 "\t pings and discovery pushes always utilize response tracking\n"},
231 command_t peer_cmds[] = {
232 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
233 "\t--prim_nid: Primary NID of the peer.\n"
234 "\t--nid: one or more peer NIDs\n"
235 "\t--non_mr: create this peer as not Multi-Rail capable\n"
236 "\t--ip2nets: specify a range of nids per peer"},
237 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
238 "\t--prim_nid: Primary NID of the peer.\n"
239 "\t--nid: list of NIDs to remove. If none provided,\n"
240 "\t peer is deleted\n"
241 "\t--ip2nets: specify a range of nids per peer"},
242 {"show", jt_show_peer, 0, "show peer information\n"
243 "\t--nid: NID of peer to filter on.\n"
244 "\t--verbose: display detailed output per peer."
245 " Optional argument of '2' outputs more stats\n"},
246 {"list", jt_list_peer, 0, "list all peers\n"},
247 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
248 "\t--nid: Peer NI NID to set the\n"
249 "\t--health: specify health value to set\n"
250 "\t--all: set all peer_nis values to the one specified\n"},
254 static int jt_calc_service_id(int argc, char **argv)
259 rc = lustre_lnet_calc_service_id(&service_id);
260 if (rc != LUSTRE_CFG_RC_NO_ERR)
264 * cYAML currently doesn't support printing hex values.
265 * Therefore just print it locally here
267 printf("service id:\n value: 0x%llx\n", service_id);
272 static inline void print_help(const command_t cmds[], const char *cmd_type,
275 const command_t *cmd;
277 for (cmd = cmds; cmd->pc_name; cmd++) {
278 if (pc_name != NULL &&
279 strcmp(cmd->pc_name, pc_name) == 0) {
280 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
283 } else if (pc_name != NULL) {
286 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
290 static int parse_long(const char *number, long int *value)
297 *value = strtol(number, &end, 0);
298 if (end != NULL && *end != 0)
304 static int check_cmd(const command_t *cmd_list, const char *cmd,
305 const char *sub_cmd, const int min_args,
306 int argc, char **argv)
313 const char *const short_options = "h";
314 static const struct option long_options[] = {
315 { .name = "help", .has_arg = no_argument, .val = 'h' },
319 if (argc < min_args) {
320 print_help(cmd_list, cmd, sub_cmd);
323 } else if (argc > 2) {
327 while ((opt = getopt_long(argc, argv, short_options,
328 long_options, NULL)) != -1) {
331 print_help(cmd_list, cmd, sub_cmd);
346 static int jt_set_response_tracking(int argc, char **argv)
350 struct cYAML *err_rc = NULL;
352 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
356 rc = parse_long(argv[1], &value);
358 cYAML_build_error(-1, -1, "parser", "set",
359 "cannot parse response_tracking value",
361 cYAML_print_tree2file(stderr, err_rc);
362 cYAML_free_tree(err_rc);
366 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
367 if (rc != LUSTRE_CFG_RC_NO_ERR)
368 cYAML_print_tree2file(stderr, err_rc);
370 cYAML_free_tree(err_rc);
375 static int jt_set_max_intf(int argc, char **argv)
379 struct cYAML *err_rc = NULL;
381 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
385 rc = parse_long(argv[1], &value);
387 cYAML_build_error(-1, -1, "parser", "set",
388 "cannot parse max_interfaces value", &err_rc);
389 cYAML_print_tree2file(stderr, err_rc);
390 cYAML_free_tree(err_rc);
394 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
395 if (rc != LUSTRE_CFG_RC_NO_ERR)
396 cYAML_print_tree2file(stderr, err_rc);
398 cYAML_free_tree(err_rc);
403 static int jt_set_numa(int argc, char **argv)
407 struct cYAML *err_rc = NULL;
409 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
413 rc = parse_long(argv[1], &value);
415 cYAML_build_error(-1, -1, "parser", "set",
416 "cannot parse numa_range value", &err_rc);
417 cYAML_print_tree2file(stderr, err_rc);
418 cYAML_free_tree(err_rc);
422 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
423 if (rc != LUSTRE_CFG_RC_NO_ERR)
424 cYAML_print_tree2file(stderr, err_rc);
426 cYAML_free_tree(err_rc);
431 static int jt_set_recov_intrv(int argc, char **argv)
435 struct cYAML *err_rc = NULL;
437 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
441 rc = parse_long(argv[1], &value);
443 cYAML_build_error(-1, -1, "parser", "set",
444 "cannot parse recovery interval value", &err_rc);
445 cYAML_print_tree2file(stderr, err_rc);
446 cYAML_free_tree(err_rc);
450 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
451 if (rc != LUSTRE_CFG_RC_NO_ERR)
452 cYAML_print_tree2file(stderr, err_rc);
454 cYAML_free_tree(err_rc);
459 static int jt_set_rtr_sensitivity(int argc, char **argv)
463 struct cYAML *err_rc = NULL;
465 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
469 rc = parse_long(argv[1], &value);
471 cYAML_build_error(-1, -1, "parser", "set",
472 "cannot parse router sensitivity value", &err_rc);
473 cYAML_print_tree2file(stderr, err_rc);
474 cYAML_free_tree(err_rc);
478 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
479 if (rc != LUSTRE_CFG_RC_NO_ERR)
480 cYAML_print_tree2file(stderr, err_rc);
482 cYAML_free_tree(err_rc);
487 static int jt_set_hsensitivity(int argc, char **argv)
491 struct cYAML *err_rc = NULL;
493 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
497 rc = parse_long(argv[1], &value);
499 cYAML_build_error(-1, -1, "parser", "set",
500 "cannot parse health sensitivity value", &err_rc);
501 cYAML_print_tree2file(stderr, err_rc);
502 cYAML_free_tree(err_rc);
506 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
507 if (rc != LUSTRE_CFG_RC_NO_ERR)
508 cYAML_print_tree2file(stderr, err_rc);
510 cYAML_free_tree(err_rc);
515 static int jt_set_transaction_to(int argc, char **argv)
519 struct cYAML *err_rc = NULL;
521 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
525 rc = parse_long(argv[1], &value);
527 cYAML_build_error(-1, -1, "parser", "set",
528 "cannot parse transaction timeout value", &err_rc);
529 cYAML_print_tree2file(stderr, err_rc);
530 cYAML_free_tree(err_rc);
534 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
535 if (rc != LUSTRE_CFG_RC_NO_ERR)
536 cYAML_print_tree2file(stderr, err_rc);
538 cYAML_free_tree(err_rc);
543 static int jt_set_retry_count(int argc, char **argv)
547 struct cYAML *err_rc = NULL;
549 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
553 rc = parse_long(argv[1], &value);
555 cYAML_build_error(-1, -1, "parser", "set",
556 "cannot parse retry_count value", &err_rc);
557 cYAML_print_tree2file(stderr, err_rc);
558 cYAML_free_tree(err_rc);
562 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
563 if (rc != LUSTRE_CFG_RC_NO_ERR)
564 cYAML_print_tree2file(stderr, err_rc);
566 cYAML_free_tree(err_rc);
571 static int jt_set_discovery(int argc, char **argv)
575 struct cYAML *err_rc = NULL;
577 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
581 rc = parse_long(argv[1], &value);
583 cYAML_build_error(-1, -1, "parser", "set",
584 "cannot parse discovery value", &err_rc);
585 cYAML_print_tree2file(stderr, err_rc);
586 cYAML_free_tree(err_rc);
590 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
591 if (rc != LUSTRE_CFG_RC_NO_ERR)
592 cYAML_print_tree2file(stderr, err_rc);
594 cYAML_free_tree(err_rc);
599 static int jt_set_drop_asym_route(int argc, char **argv)
603 struct cYAML *err_rc = NULL;
605 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
609 rc = parse_long(argv[1], &value);
611 cYAML_build_error(-1, -1, "parser", "set",
612 "cannot parse drop_asym_route value",
614 cYAML_print_tree2file(stderr, err_rc);
615 cYAML_free_tree(err_rc);
619 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
620 if (rc != LUSTRE_CFG_RC_NO_ERR)
621 cYAML_print_tree2file(stderr, err_rc);
623 cYAML_free_tree(err_rc);
628 static int jt_set_tiny(int argc, char **argv)
632 struct cYAML *err_rc = NULL;
634 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
638 rc = parse_long(argv[1], &value);
640 cYAML_build_error(-1, -1, "parser", "set",
641 "cannot parse tiny_buffers value", &err_rc);
642 cYAML_print_tree2file(stderr, err_rc);
643 cYAML_free_tree(err_rc);
647 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
648 if (rc != LUSTRE_CFG_RC_NO_ERR)
649 cYAML_print_tree2file(stderr, err_rc);
651 cYAML_free_tree(err_rc);
656 static int jt_set_small(int argc, char **argv)
660 struct cYAML *err_rc = NULL;
662 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
666 rc = parse_long(argv[1], &value);
668 cYAML_build_error(-1, -1, "parser", "set",
669 "cannot parse small_buffers value", &err_rc);
670 cYAML_print_tree2file(stderr, err_rc);
671 cYAML_free_tree(err_rc);
675 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
676 if (rc != LUSTRE_CFG_RC_NO_ERR)
677 cYAML_print_tree2file(stderr, err_rc);
679 cYAML_free_tree(err_rc);
684 static int jt_set_large(int argc, char **argv)
688 struct cYAML *err_rc = NULL;
690 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
694 rc = parse_long(argv[1], &value);
696 cYAML_build_error(-1, -1, "parser", "set",
697 "cannot parse large_buffers value", &err_rc);
698 cYAML_print_tree2file(stderr, err_rc);
699 cYAML_free_tree(err_rc);
703 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
704 if (rc != LUSTRE_CFG_RC_NO_ERR)
705 cYAML_print_tree2file(stderr, err_rc);
707 cYAML_free_tree(err_rc);
712 static int jt_set_routing(int argc, char **argv)
715 struct cYAML *err_rc = NULL;
718 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
722 rc = parse_long(argv[1], &value);
723 if (rc != 0 || (value != 0 && value != 1)) {
724 cYAML_build_error(-1, -1, "parser", "set",
725 "cannot parse routing value.\n"
726 "must be 0 for disable or 1 for enable",
728 cYAML_print_tree2file(stderr, err_rc);
729 cYAML_free_tree(err_rc);
733 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
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_config_lnet(int argc, char **argv)
745 struct cYAML *err_rc = NULL;
746 bool load_mod_params = false;
749 const char *const short_options = "a";
750 static const struct option long_options[] = {
751 { .name = "all", .has_arg = no_argument, .val = 'a' },
755 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
759 while ((opt = getopt_long(argc, argv, short_options,
760 long_options, NULL)) != -1) {
763 load_mod_params = true;
770 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
773 if (rc != LUSTRE_CFG_RC_NO_ERR)
774 cYAML_print_tree2file(stderr, err_rc);
776 cYAML_free_tree(err_rc);
781 static int jt_unconfig_lnet(int argc, char **argv)
783 struct cYAML *err_rc = NULL;
786 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
790 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
792 if (rc != LUSTRE_CFG_RC_NO_ERR)
793 cYAML_print_tree2file(stderr, err_rc);
795 cYAML_free_tree(err_rc);
799 static int jt_add_route(int argc, char **argv)
801 char *network = NULL, *gateway = NULL;
802 long int hop = -1, prio = -1, sen = -1;
803 struct cYAML *err_rc = NULL;
806 const char *const short_options = "n:g:c:p:";
807 static const struct option long_options[] = {
808 { .name = "net", .has_arg = required_argument, .val = 'n' },
809 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
810 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
811 { .name = "priority", .has_arg = required_argument, .val = 'p' },
812 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
815 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
819 while ((opt = getopt_long(argc, argv, short_options,
820 long_options, NULL)) != -1) {
829 rc = parse_long(optarg, &hop);
837 rc = parse_long(optarg, &prio);
845 rc = parse_long(optarg, &sen);
854 print_help(route_cmds, "route", "add");
860 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
863 if (rc != LUSTRE_CFG_RC_NO_ERR)
864 cYAML_print_tree2file(stderr, err_rc);
866 cYAML_free_tree(err_rc);
871 static int jt_add_ni(int argc, char **argv)
874 long int pto = -1, pc = -1, pbc = -1, cre = -1;
875 struct cYAML *err_rc = NULL;
876 int rc, opt, cpt_rc = -1;
877 struct lnet_dlc_network_descr nw_descr;
878 struct cfs_expr_list *global_cpts = NULL;
879 struct lnet_ioctl_config_lnd_tunables tunables;
882 memset(&tunables, 0, sizeof(tunables));
883 lustre_lnet_init_nw_descr(&nw_descr);
885 const char *const short_options = "n:i:p:t:c:b:r:s:";
886 static const struct option long_options[] = {
887 { .name = "net", .has_arg = required_argument, .val = 'n' },
888 { .name = "if", .has_arg = required_argument, .val = 'i' },
889 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
890 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
891 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
892 { .name = "peer-buffer-credits",
893 .has_arg = required_argument, .val = 'b' },
894 { .name = "credits", .has_arg = required_argument, .val = 'r' },
895 { .name = "cpt", .has_arg = required_argument, .val = 's' },
898 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
902 while ((opt = getopt_long(argc, argv, short_options,
903 long_options, NULL)) != -1) {
906 nw_descr.nw_id = libcfs_str2net(optarg);
909 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
911 cYAML_build_error(-1, -1, "ni", "add",
912 "bad interface list",
921 rc = parse_long(optarg, &pto);
929 rc = parse_long(optarg, &pc);
937 rc = parse_long(optarg, &pbc);
945 rc = parse_long(optarg, &cre);
953 cpt_rc = cfs_expr_list_parse(optarg,
955 UINT_MAX, &global_cpts);
958 print_help(net_cmds, "net", "add");
964 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
965 tunables.lt_cmn.lct_peer_timeout = pto;
966 tunables.lt_cmn.lct_peer_tx_credits = pc;
967 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
968 tunables.lt_cmn.lct_max_tx_credits = cre;
972 rc = lustre_lnet_config_ni(&nw_descr,
973 (cpt_rc == 0) ? global_cpts: NULL,
974 ip2net, (found) ? &tunables : NULL,
977 if (global_cpts != NULL)
978 cfs_expr_list_free(global_cpts);
981 if (rc != LUSTRE_CFG_RC_NO_ERR)
982 cYAML_print_tree2file(stderr, err_rc);
984 cYAML_free_tree(err_rc);
989 static int jt_del_route(int argc, char **argv)
991 char *network = NULL, *gateway = NULL;
992 struct cYAML *err_rc = NULL;
995 const char *const short_options = "n:g:";
996 static const struct option long_options[] = {
997 { .name = "net", .has_arg = required_argument, .val = 'n' },
998 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1001 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1005 while ((opt = getopt_long(argc, argv, short_options,
1006 long_options, NULL)) != -1) {
1015 print_help(route_cmds, "route", "del");
1021 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1023 if (rc != LUSTRE_CFG_RC_NO_ERR)
1024 cYAML_print_tree2file(stderr, err_rc);
1026 cYAML_free_tree(err_rc);
1031 static int jt_del_ni(int argc, char **argv)
1033 struct cYAML *err_rc = NULL;
1035 struct lnet_dlc_network_descr nw_descr;
1037 lustre_lnet_init_nw_descr(&nw_descr);
1039 const char *const short_options = "n:i:";
1040 static const struct option long_options[] = {
1041 { .name = "net", .has_arg = required_argument, .val = 'n' },
1042 { .name = "if", .has_arg = required_argument, .val = 'i' },
1045 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1049 while ((opt = getopt_long(argc, argv, short_options,
1050 long_options, NULL)) != -1) {
1053 nw_descr.nw_id = libcfs_str2net(optarg);
1056 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1058 cYAML_build_error(-1, -1, "ni", "add",
1059 "bad interface list",
1065 print_help(net_cmds, "net", "del");
1071 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1074 if (rc != LUSTRE_CFG_RC_NO_ERR)
1075 cYAML_print_tree2file(stderr, err_rc);
1077 cYAML_free_tree(err_rc);
1082 static int jt_show_route(int argc, char **argv)
1084 char *network = NULL, *gateway = NULL;
1085 long int hop = -1, prio = -1;
1086 int detail = 0, rc, opt;
1087 struct cYAML *err_rc = NULL, *show_rc = NULL;
1089 const char *const short_options = "n:g:h:p:v";
1090 static const struct option long_options[] = {
1091 { .name = "net", .has_arg = required_argument, .val = 'n' },
1092 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1093 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1094 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1095 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1098 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1102 while ((opt = getopt_long(argc, argv, short_options,
1103 long_options, NULL)) != -1) {
1112 rc = parse_long(optarg, &hop);
1120 rc = parse_long(optarg, &prio);
1131 print_help(route_cmds, "route", "show");
1137 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1138 &show_rc, &err_rc, false);
1140 if (rc != LUSTRE_CFG_RC_NO_ERR)
1141 cYAML_print_tree2file(stderr, err_rc);
1143 cYAML_print_tree(show_rc);
1145 cYAML_free_tree(err_rc);
1146 cYAML_free_tree(show_rc);
1151 static int set_value_helper(int argc, char **argv,
1152 int (*cb)(int, bool, char*, int, struct cYAML**))
1155 long int healthv = -1;
1158 struct cYAML *err_rc = NULL;
1160 const char *const short_options = "t:n:a";
1161 static const struct option long_options[] = {
1162 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1163 { .name = "health", .has_arg = required_argument, .val = 't' },
1164 { .name = "all", .has_arg = no_argument, .val = 'a' },
1167 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1171 while ((opt = getopt_long(argc, argv, short_options,
1172 long_options, NULL)) != -1) {
1178 if (parse_long(optarg, &healthv) != 0)
1189 rc = cb(healthv, all, nid, -1, &err_rc);
1191 if (rc != LUSTRE_CFG_RC_NO_ERR)
1192 cYAML_print_tree2file(stderr, err_rc);
1194 cYAML_free_tree(err_rc);
1199 static int jt_set_ni_value(int argc, char **argv)
1201 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1204 static int jt_set_peer_ni_value(int argc, char **argv)
1206 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1209 static int jt_show_recovery(int argc, char **argv)
1212 struct cYAML *err_rc = NULL, *show_rc = NULL;
1214 const char *const short_options = "lp";
1215 static const struct option long_options[] = {
1216 { .name = "local", .has_arg = no_argument, .val = 'l' },
1217 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1220 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1224 while ((opt = getopt_long(argc, argv, short_options,
1225 long_options, NULL)) != -1) {
1228 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1231 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1238 if (rc != LUSTRE_CFG_RC_NO_ERR)
1239 cYAML_print_tree2file(stderr, err_rc);
1241 cYAML_print_tree(show_rc);
1243 cYAML_free_tree(err_rc);
1244 cYAML_free_tree(show_rc);
1249 static int jt_show_net(int argc, char **argv)
1251 char *network = NULL;
1253 struct cYAML *err_rc = NULL, *show_rc = NULL;
1254 long int detail = 0;
1256 const char *const short_options = "n:v";
1257 static const struct option long_options[] = {
1258 { .name = "net", .has_arg = required_argument, .val = 'n' },
1259 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1262 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1266 while ((opt = getopt_long(argc, argv, short_options,
1267 long_options, NULL)) != -1) {
1273 if ((!optarg) && (argv[optind] != NULL) &&
1274 (argv[optind][0] != '-')) {
1275 if (parse_long(argv[optind++], &detail) != 0)
1282 print_help(net_cmds, "net", "show");
1288 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1291 if (rc != LUSTRE_CFG_RC_NO_ERR)
1292 cYAML_print_tree2file(stderr, err_rc);
1294 cYAML_print_tree(show_rc);
1296 cYAML_free_tree(err_rc);
1297 cYAML_free_tree(show_rc);
1302 static int jt_show_routing(int argc, char **argv)
1304 struct cYAML *err_rc = NULL, *show_rc = NULL;
1307 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1311 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1313 if (rc != LUSTRE_CFG_RC_NO_ERR)
1314 cYAML_print_tree2file(stderr, err_rc);
1316 cYAML_print_tree(show_rc);
1318 cYAML_free_tree(err_rc);
1319 cYAML_free_tree(show_rc);
1324 static int jt_show_stats(int argc, char **argv)
1327 struct cYAML *show_rc = NULL, *err_rc = NULL;
1329 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1333 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1335 if (rc != LUSTRE_CFG_RC_NO_ERR)
1336 cYAML_print_tree2file(stderr, err_rc);
1338 cYAML_print_tree(show_rc);
1340 cYAML_free_tree(err_rc);
1341 cYAML_free_tree(show_rc);
1346 static int jt_show_global(int argc, char **argv)
1349 struct cYAML *show_rc = NULL, *err_rc = NULL;
1351 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1355 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1356 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1357 cYAML_print_tree2file(stderr, err_rc);
1361 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1362 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1363 cYAML_print_tree2file(stderr, err_rc);
1367 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1368 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1369 cYAML_print_tree2file(stderr, err_rc);
1373 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1374 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1375 cYAML_print_tree2file(stderr, err_rc);
1379 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1380 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1381 cYAML_print_tree2file(stderr, err_rc);
1385 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1386 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1387 cYAML_print_tree2file(stderr, err_rc);
1391 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1392 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1393 cYAML_print_tree2file(stderr, err_rc);
1397 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1398 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1399 cYAML_print_tree2file(stderr, err_rc);
1403 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1404 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1405 cYAML_print_tree2file(stderr, err_rc);
1409 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1410 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1411 cYAML_print_tree2file(stderr, err_rc);
1415 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1416 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1417 cYAML_print_tree2file(stderr, err_rc);
1422 cYAML_print_tree(show_rc);
1425 cYAML_free_tree(err_rc);
1426 cYAML_free_tree(show_rc);
1431 static int jt_lnet(int argc, char **argv)
1435 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1439 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1442 static int jt_route(int argc, char **argv)
1446 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1450 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1453 static int jt_net(int argc, char **argv)
1457 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1461 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1464 static int jt_routing(int argc, char **argv)
1468 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1472 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1475 static int jt_stats(int argc, char **argv)
1479 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1483 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1486 static int jt_debug(int argc, char **argv)
1490 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1494 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1497 static int jt_global(int argc, char **argv)
1501 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1505 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1508 static int jt_peers(int argc, char **argv)
1512 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1516 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1519 static int jt_set(int argc, char **argv)
1523 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1527 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1530 static int jt_import(int argc, char **argv)
1533 struct cYAML *err_rc = NULL;
1534 struct cYAML *show_rc = NULL;
1535 int rc = 0, return_rc = 0, opt, opt_found = 0;
1538 const char *const short_options = "adseh";
1539 static const struct option long_options[] = {
1540 { .name = "add", .has_arg = no_argument, .val = 'a' },
1541 { .name = "del", .has_arg = no_argument, .val = 'd' },
1542 { .name = "show", .has_arg = no_argument, .val = 's' },
1543 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1544 { .name = "help", .has_arg = no_argument, .val = 'h' },
1547 while ((opt = getopt_long(argc, argv, short_options,
1548 long_options, NULL)) != -1) {
1562 printf("import FILE\n"
1563 "import < FILE : import a file\n"
1564 "\t--add: add configuration\n"
1565 "\t--del: delete configuration\n"
1566 "\t--show: show configuration\n"
1567 "\t--exec: execute command\n"
1568 "\t--help: display this help\n"
1569 "If no command option is given then --add"
1570 " is assumed by default\n");
1577 /* grab the file name if one exists */
1578 if (opt_found && argc == 3)
1580 else if (!opt_found && argc == 2)
1585 rc = lustre_yaml_config(file, &err_rc);
1586 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1587 cYAML_print_tree(show_rc);
1588 cYAML_free_tree(show_rc);
1591 rc = lustre_yaml_del(file, &err_rc);
1594 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1595 cYAML_print_tree(show_rc);
1596 cYAML_free_tree(show_rc);
1599 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1600 cYAML_print_tree(show_rc);
1601 cYAML_free_tree(show_rc);
1605 if (rc || return_rc) {
1606 cYAML_print_tree2file(stderr, err_rc);
1607 cYAML_free_tree(err_rc);
1613 static int jt_export(int argc, char **argv)
1615 struct cYAML *show_rc = NULL;
1616 struct cYAML *err_rc = NULL;
1620 bool backup = false;
1623 const char *const short_options = "bh";
1624 static const struct option long_options[] = {
1625 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1626 { .name = "help", .has_arg = no_argument, .val = 'h' },
1629 while ((opt = getopt_long(argc, argv, short_options,
1630 long_options, NULL)) != -1) {
1637 printf("export > FILE.yaml : export configuration\n"
1638 "\t--backup: export only what's necessary for reconfig\n"
1639 "\t--help: display this help\n");
1644 if (backup && argc >= 3)
1646 else if (!backup && argc >= 2)
1652 f = fopen(file, "w");
1657 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1658 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1659 cYAML_print_tree2file(stderr, err_rc);
1660 cYAML_free_tree(err_rc);
1664 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1666 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1667 cYAML_print_tree2file(stderr, err_rc);
1668 cYAML_free_tree(err_rc);
1672 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1673 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1674 cYAML_print_tree2file(stderr, err_rc);
1675 cYAML_free_tree(err_rc);
1679 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1680 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1681 cYAML_print_tree2file(stderr, err_rc);
1682 cYAML_free_tree(err_rc);
1686 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1687 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1688 cYAML_print_tree2file(stderr, err_rc);
1689 cYAML_free_tree(err_rc);
1693 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1694 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1695 cYAML_print_tree2file(stderr, err_rc);
1696 cYAML_free_tree(err_rc);
1700 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1701 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1702 cYAML_print_tree2file(stderr, err_rc);
1703 cYAML_free_tree(err_rc);
1707 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1708 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1709 cYAML_print_tree2file(stderr, err_rc);
1710 cYAML_free_tree(err_rc);
1714 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1715 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1716 cYAML_print_tree2file(stderr, err_rc);
1717 cYAML_free_tree(err_rc);
1721 if (show_rc != NULL) {
1722 cYAML_print_tree2file(f, show_rc);
1723 cYAML_free_tree(show_rc);
1732 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1734 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1736 char *prim_nid = NULL, *nidstr = NULL;
1737 char err_str[LNET_MAX_STR_LEN] = "Error";
1738 struct cYAML *err_rc = NULL;
1740 const char *const short_opts = "k:mn:";
1741 const struct option long_opts[] = {
1742 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1743 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1744 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1747 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1751 while ((opt = getopt_long(argc, argv, short_opts,
1752 long_opts, NULL)) != -1) {
1761 if (cmd == LNETCTL_DEL_CMD) {
1762 rc = LUSTRE_CFG_RC_BAD_PARAM;
1763 snprintf(err_str, LNET_MAX_STR_LEN,
1764 "Unrecognized option '-%c'", opt);
1770 print_help(peer_cmds, "peer",
1771 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1777 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
1779 if (rc != LUSTRE_CFG_RC_NO_ERR)
1783 cYAML_build_error(rc, -1, "peer",
1784 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1788 if (rc != LUSTRE_CFG_RC_NO_ERR)
1789 cYAML_print_tree2file(stderr, err_rc);
1791 cYAML_free_tree(err_rc);
1796 static int jt_add_peer_nid(int argc, char **argv)
1798 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1801 static int jt_del_peer_nid(int argc, char **argv)
1803 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1806 static int jt_show_peer(int argc, char **argv)
1810 struct cYAML *err_rc = NULL, *show_rc = NULL;
1811 long int detail = 0;
1813 const char *const short_opts = "hn:v::";
1814 const struct option long_opts[] = {
1815 { .name = "help", .has_arg = no_argument, .val = 'h' },
1816 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1817 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1820 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1824 while ((opt = getopt_long(argc, argv, short_opts,
1825 long_opts, NULL)) != -1) {
1831 if ((!optarg) && (argv[optind] != NULL) &&
1832 (argv[optind][0] != '-')) {
1833 if (parse_long(argv[optind++], &detail) != 0)
1840 print_help(peer_cmds, "peer", "show");
1846 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1849 if (rc != LUSTRE_CFG_RC_NO_ERR)
1850 cYAML_print_tree2file(stderr, err_rc);
1852 cYAML_print_tree(show_rc);
1854 cYAML_free_tree(err_rc);
1855 cYAML_free_tree(show_rc);
1860 static int jt_list_peer(int argc, char **argv)
1863 struct cYAML *err_rc = NULL, *list_rc = NULL;
1865 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1869 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1871 if (rc != LUSTRE_CFG_RC_NO_ERR)
1872 cYAML_print_tree2file(stderr, err_rc);
1874 cYAML_print_tree(list_rc);
1876 cYAML_free_tree(err_rc);
1877 cYAML_free_tree(list_rc);
1882 static int jt_ping(int argc, char **argv)
1884 struct cYAML *err_rc = NULL;
1885 struct cYAML *show_rc = NULL;
1889 const char *const short_options = "ht:";
1890 const struct option long_options[] = {
1891 { .name = "help", .has_arg = no_argument, .val = 'h' },
1892 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1895 while ((opt = getopt_long(argc, argv, short_options,
1896 long_options, NULL)) != -1) {
1899 timeout = 1000 * atol(optarg);
1902 printf("ping nid[,nid,...]\n"
1903 "\t --timeout: ping timeout\n"
1904 "\t --help: display this help\n");
1911 for (; optind < argc; optind++)
1912 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1915 cYAML_print_tree(show_rc);
1918 cYAML_print_tree2file(stderr, err_rc);
1920 cYAML_free_tree(err_rc);
1921 cYAML_free_tree(show_rc);
1926 static int jt_discover(int argc, char **argv)
1928 struct cYAML *err_rc = NULL;
1929 struct cYAML *show_rc = NULL;
1933 const char *const short_options = "fh";
1934 const struct option long_options[] = {
1935 { .name = "force", .has_arg = no_argument, .val = 'f' },
1936 { .name = "help", .has_arg = no_argument, .val = 'h' },
1939 while ((opt = getopt_long(argc, argv, short_options,
1940 long_options, NULL)) != -1) {
1946 printf("discover nid[,nid,...]\n"
1947 "\t --force: force discovery\n"
1948 "\t --help: display this help\n");
1955 for (; optind < argc; optind++)
1956 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1960 cYAML_print_tree(show_rc);
1963 cYAML_print_tree2file(stderr, err_rc);
1965 cYAML_free_tree(err_rc);
1966 cYAML_free_tree(show_rc);
1971 static int lnetctl_list_commands(int argc, char **argv)
1973 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1975 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1980 int main(int argc, char **argv)
1983 struct cYAML *err_rc = NULL;
1985 rc = lustre_lnet_config_lib_init();
1987 cYAML_build_error(-1, -1, "lnetctl", "startup",
1988 "cannot register LNet device", &err_rc);
1989 cYAML_print_tree2file(stderr, err_rc);
1993 Parser_init("lnetctl > ", cmd_list);
1995 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);