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);
87 static int jt_set_recovery_limit(int argc, char **argv);
89 command_t cmd_list[] = {
90 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
91 {"route", jt_route, 0, "route {add | del | show | help}"},
92 {"net", jt_net, 0, "net {add | del | show | help}"},
93 {"routing", jt_routing, 0, "routing {show | help}"},
94 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
95 " | routing | numa_range | max_interfaces"
96 " | discovery | drop_asym_route | retry_count"
97 " | transaction_timeout | health_sensitivity"
98 " | recovery_interval | router_sensitivity"
99 " | response_tracking | recovery_limit}"},
100 {"import", jt_import, 0, "import FILE.yaml"},
101 {"export", jt_export, 0, "export FILE.yaml"},
102 {"stats", jt_stats, 0, "stats {show | help}"},
103 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
104 {"global", jt_global, 0, "global {show | help}"},
105 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
106 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
107 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
108 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
109 {"help", Parser_help, 0, "help"},
110 {"exit", Parser_quit, 0, "quit"},
111 {"quit", Parser_quit, 0, "quit"},
112 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
116 command_t lnet_cmds[] = {
117 {"configure", jt_config_lnet, 0, "configure lnet\n"
118 "\t--all: load NI configuration from module parameters\n"},
119 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
123 command_t route_cmds[] = {
124 {"add", jt_add_route, 0, "add a route\n"
125 "\t--net: net name (e.g. tcp0)\n"
126 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
127 "\t--hop: number to final destination (1 < hops < 255)\n"
128 "\t--priority: priority of route (0 - highest prio\n"
129 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
130 {"del", jt_del_route, 0, "delete a route\n"
131 "\t--net: net name (e.g. tcp0)\n"
132 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
133 {"show", jt_show_route, 0, "show routes\n"
134 "\t--net: net name (e.g. tcp0) to filter on\n"
135 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
136 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
137 "\t--priority: priority of route (0 - highest prio to filter on\n"
138 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
139 "\t--verbose: display detailed output per route\n"},
143 command_t net_cmds[] = {
144 {"add", jt_add_ni, 0, "add a network\n"
145 "\t--net: net name (e.g. tcp0)\n"
146 "\t--if: physical interface (e.g. eth0)\n"
147 "\t--ip2net: specify networks based on IP address patterns\n"
148 "\t--peer-timeout: time to wait before declaring a peer dead\n"
149 "\t--peer-credits: define the max number of inflight messages\n"
150 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
151 "\t--credits: Network Interface credits\n"
152 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
153 {"del", jt_del_ni, 0, "delete a network\n"
154 "\t--net: net name (e.g. tcp0)\n"
155 "\t--if: physical interface (e.g. eth0)\n"},
156 {"show", jt_show_net, 0, "show networks\n"
157 "\t--net: net name (e.g. tcp0) to filter on\n"
158 "\t--verbose: display detailed output per network."
159 " Optional argument of '2' outputs more stats\n"},
160 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
161 "\t--nid: NI NID to set the\n"
162 "\t--health: specify health value to set\n"
163 "\t--all: set all NIs value to the one specified\n"},
167 command_t routing_cmds[] = {
168 {"show", jt_show_routing, 0, "show routing information\n"},
172 command_t stats_cmds[] = {
173 {"show", jt_show_stats, 0, "show LNET statistics\n"},
177 command_t debug_cmds[] = {
178 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
179 "\t--local : list local recovery queue\n"
180 "\t--peer : list peer recovery queue\n"},
184 command_t global_cmds[] = {
185 {"show", jt_show_global, 0, "show global variables\n"},
189 command_t set_cmds[] = {
190 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
191 "\tVALUE must be greater than 0\n"},
192 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
193 "\tVALUE must be greater than 0\n"},
194 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
195 "\tVALUE must be greater than 0\n"},
196 {"routing", jt_set_routing, 0, "enable/disable routing\n"
197 "\t0 - disable routing\n"
198 "\t1 - enable routing\n"},
199 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
200 "\tVALUE must be at least 0\n"},
201 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
203 "\tValue must be greater than 16\n"},
204 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
205 "\t0 - disable peer discovery\n"
206 "\t1 - enable peer discovery (default)\n"},
207 {"drop_asym_route", jt_set_drop_asym_route, 0,
208 "drop/accept asymmetrical route messages\n"
209 "\t0 - accept asymmetrical route messages (default)\n"
210 "\t1 - drop asymmetrical route messages\n"},
211 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
212 "\t0 - turn of retries\n"
213 "\t>0 - number of retries\n"},
214 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
215 "\t>0 - timeout in seconds\n"},
216 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
217 "\t0 - turn off health evaluation\n"
218 "\t>0 - sensitivity value not more than 1000\n"},
219 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
220 "\t>0 - time in seconds between pings\n"},
221 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
222 "\t100 - router interfaces need to be fully healthy to be used\n"
223 "\t<100 - router interfaces can be used even if not healthy\n"},
224 {"response_tracking", jt_set_response_tracking, 0,
225 "Set the behavior of response tracking\n"
226 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
227 "\t1 - GETs are eligible for response tracking\n"
228 "\t2 - PUTs are eligible for response tracking\n"
229 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
230 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
231 "\t pings and discovery pushes always utilize response tracking\n"},
232 {"recovery_limit", jt_set_recovery_limit, 0,
233 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
234 "\t0 - Recover indefinitely (default)\n"
235 "\t>0 - Recover for the specified number of seconds.\n"},
239 command_t peer_cmds[] = {
240 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
241 "\t--prim_nid: Primary NID of the peer.\n"
242 "\t--nid: one or more peer NIDs\n"
243 "\t--non_mr: create this peer as not Multi-Rail capable\n"
244 "\t--ip2nets: specify a range of nids per peer"},
245 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
246 "\t--prim_nid: Primary NID of the peer.\n"
247 "\t--nid: list of NIDs to remove. If none provided,\n"
248 "\t peer is deleted\n"
249 "\t--ip2nets: specify a range of nids per peer"},
250 {"show", jt_show_peer, 0, "show peer information\n"
251 "\t--nid: NID of peer to filter on.\n"
252 "\t--verbose: display detailed output per peer."
253 " Optional argument of '2' outputs more stats\n"},
254 {"list", jt_list_peer, 0, "list all peers\n"},
255 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
256 "\t--nid: Peer NI NID to set the\n"
257 "\t--health: specify health value to set\n"
258 "\t--all: set all peer_nis values to the one specified\n"},
262 static int jt_calc_service_id(int argc, char **argv)
267 rc = lustre_lnet_calc_service_id(&service_id);
268 if (rc != LUSTRE_CFG_RC_NO_ERR)
272 * cYAML currently doesn't support printing hex values.
273 * Therefore just print it locally here
275 printf("service id:\n value: 0x%jx\n", (uintmax_t)service_id);
280 static inline void print_help(const command_t cmds[], const char *cmd_type,
283 const command_t *cmd;
285 for (cmd = cmds; cmd->pc_name; cmd++) {
286 if (pc_name != NULL &&
287 strcmp(cmd->pc_name, pc_name) == 0) {
288 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
291 } else if (pc_name != NULL) {
294 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
298 static int parse_long(const char *number, long int *value)
305 *value = strtol(number, &end, 0);
306 if (end != NULL && *end != 0)
312 static int check_cmd(const command_t *cmd_list, const char *cmd,
313 const char *sub_cmd, const int min_args,
314 int argc, char **argv)
321 const char *const short_options = "h";
322 static const struct option long_options[] = {
323 { .name = "help", .has_arg = no_argument, .val = 'h' },
327 if (argc < min_args) {
328 print_help(cmd_list, cmd, sub_cmd);
331 } else if (argc > 2) {
335 while ((opt = getopt_long(argc, argv, short_options,
336 long_options, NULL)) != -1) {
339 print_help(cmd_list, cmd, sub_cmd);
354 static int jt_set_response_tracking(int argc, char **argv)
358 struct cYAML *err_rc = NULL;
360 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
364 rc = parse_long(argv[1], &value);
366 cYAML_build_error(-1, -1, "parser", "set",
367 "cannot parse response_tracking value",
369 cYAML_print_tree2file(stderr, err_rc);
370 cYAML_free_tree(err_rc);
374 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
375 if (rc != LUSTRE_CFG_RC_NO_ERR)
376 cYAML_print_tree2file(stderr, err_rc);
378 cYAML_free_tree(err_rc);
383 static int jt_set_recovery_limit(int argc, char **argv)
387 struct cYAML *err_rc = NULL;
389 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
393 rc = parse_long(argv[1], &value);
395 cYAML_build_error(-1, -1, "parser", "set",
396 "cannot parse recovery_limit value",
398 cYAML_print_tree2file(stderr, err_rc);
399 cYAML_free_tree(err_rc);
403 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
404 if (rc != LUSTRE_CFG_RC_NO_ERR)
405 cYAML_print_tree2file(stderr, err_rc);
407 cYAML_free_tree(err_rc);
412 static int jt_set_max_intf(int argc, char **argv)
416 struct cYAML *err_rc = NULL;
418 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
422 rc = parse_long(argv[1], &value);
424 cYAML_build_error(-1, -1, "parser", "set",
425 "cannot parse max_interfaces value", &err_rc);
426 cYAML_print_tree2file(stderr, err_rc);
427 cYAML_free_tree(err_rc);
431 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
432 if (rc != LUSTRE_CFG_RC_NO_ERR)
433 cYAML_print_tree2file(stderr, err_rc);
435 cYAML_free_tree(err_rc);
440 static int jt_set_numa(int argc, char **argv)
444 struct cYAML *err_rc = NULL;
446 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
450 rc = parse_long(argv[1], &value);
452 cYAML_build_error(-1, -1, "parser", "set",
453 "cannot parse numa_range value", &err_rc);
454 cYAML_print_tree2file(stderr, err_rc);
455 cYAML_free_tree(err_rc);
459 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
460 if (rc != LUSTRE_CFG_RC_NO_ERR)
461 cYAML_print_tree2file(stderr, err_rc);
463 cYAML_free_tree(err_rc);
468 static int jt_set_recov_intrv(int argc, char **argv)
472 struct cYAML *err_rc = NULL;
474 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
478 rc = parse_long(argv[1], &value);
480 cYAML_build_error(-1, -1, "parser", "set",
481 "cannot parse recovery interval value", &err_rc);
482 cYAML_print_tree2file(stderr, err_rc);
483 cYAML_free_tree(err_rc);
487 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
488 if (rc != LUSTRE_CFG_RC_NO_ERR)
489 cYAML_print_tree2file(stderr, err_rc);
491 cYAML_free_tree(err_rc);
496 static int jt_set_rtr_sensitivity(int argc, char **argv)
500 struct cYAML *err_rc = NULL;
502 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
506 rc = parse_long(argv[1], &value);
508 cYAML_build_error(-1, -1, "parser", "set",
509 "cannot parse router sensitivity value", &err_rc);
510 cYAML_print_tree2file(stderr, err_rc);
511 cYAML_free_tree(err_rc);
515 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
516 if (rc != LUSTRE_CFG_RC_NO_ERR)
517 cYAML_print_tree2file(stderr, err_rc);
519 cYAML_free_tree(err_rc);
524 static int jt_set_hsensitivity(int argc, char **argv)
528 struct cYAML *err_rc = NULL;
530 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
534 rc = parse_long(argv[1], &value);
536 cYAML_build_error(-1, -1, "parser", "set",
537 "cannot parse health sensitivity value", &err_rc);
538 cYAML_print_tree2file(stderr, err_rc);
539 cYAML_free_tree(err_rc);
543 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
544 if (rc != LUSTRE_CFG_RC_NO_ERR)
545 cYAML_print_tree2file(stderr, err_rc);
547 cYAML_free_tree(err_rc);
552 static int jt_set_transaction_to(int argc, char **argv)
556 struct cYAML *err_rc = NULL;
558 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
562 rc = parse_long(argv[1], &value);
564 cYAML_build_error(-1, -1, "parser", "set",
565 "cannot parse transaction timeout value", &err_rc);
566 cYAML_print_tree2file(stderr, err_rc);
567 cYAML_free_tree(err_rc);
571 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
572 if (rc != LUSTRE_CFG_RC_NO_ERR)
573 cYAML_print_tree2file(stderr, err_rc);
575 cYAML_free_tree(err_rc);
580 static int jt_set_retry_count(int argc, char **argv)
584 struct cYAML *err_rc = NULL;
586 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
590 rc = parse_long(argv[1], &value);
592 cYAML_build_error(-1, -1, "parser", "set",
593 "cannot parse retry_count value", &err_rc);
594 cYAML_print_tree2file(stderr, err_rc);
595 cYAML_free_tree(err_rc);
599 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
600 if (rc != LUSTRE_CFG_RC_NO_ERR)
601 cYAML_print_tree2file(stderr, err_rc);
603 cYAML_free_tree(err_rc);
608 static int jt_set_discovery(int argc, char **argv)
612 struct cYAML *err_rc = NULL;
614 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
618 rc = parse_long(argv[1], &value);
620 cYAML_build_error(-1, -1, "parser", "set",
621 "cannot parse discovery value", &err_rc);
622 cYAML_print_tree2file(stderr, err_rc);
623 cYAML_free_tree(err_rc);
627 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
628 if (rc != LUSTRE_CFG_RC_NO_ERR)
629 cYAML_print_tree2file(stderr, err_rc);
631 cYAML_free_tree(err_rc);
636 static int jt_set_drop_asym_route(int argc, char **argv)
640 struct cYAML *err_rc = NULL;
642 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
646 rc = parse_long(argv[1], &value);
648 cYAML_build_error(-1, -1, "parser", "set",
649 "cannot parse drop_asym_route value",
651 cYAML_print_tree2file(stderr, err_rc);
652 cYAML_free_tree(err_rc);
656 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
657 if (rc != LUSTRE_CFG_RC_NO_ERR)
658 cYAML_print_tree2file(stderr, err_rc);
660 cYAML_free_tree(err_rc);
665 static int jt_set_tiny(int argc, char **argv)
669 struct cYAML *err_rc = NULL;
671 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
675 rc = parse_long(argv[1], &value);
677 cYAML_build_error(-1, -1, "parser", "set",
678 "cannot parse tiny_buffers value", &err_rc);
679 cYAML_print_tree2file(stderr, err_rc);
680 cYAML_free_tree(err_rc);
684 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
685 if (rc != LUSTRE_CFG_RC_NO_ERR)
686 cYAML_print_tree2file(stderr, err_rc);
688 cYAML_free_tree(err_rc);
693 static int jt_set_small(int argc, char **argv)
697 struct cYAML *err_rc = NULL;
699 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
703 rc = parse_long(argv[1], &value);
705 cYAML_build_error(-1, -1, "parser", "set",
706 "cannot parse small_buffers value", &err_rc);
707 cYAML_print_tree2file(stderr, err_rc);
708 cYAML_free_tree(err_rc);
712 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
713 if (rc != LUSTRE_CFG_RC_NO_ERR)
714 cYAML_print_tree2file(stderr, err_rc);
716 cYAML_free_tree(err_rc);
721 static int jt_set_large(int argc, char **argv)
725 struct cYAML *err_rc = NULL;
727 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
731 rc = parse_long(argv[1], &value);
733 cYAML_build_error(-1, -1, "parser", "set",
734 "cannot parse large_buffers value", &err_rc);
735 cYAML_print_tree2file(stderr, err_rc);
736 cYAML_free_tree(err_rc);
740 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
741 if (rc != LUSTRE_CFG_RC_NO_ERR)
742 cYAML_print_tree2file(stderr, err_rc);
744 cYAML_free_tree(err_rc);
749 static int jt_set_routing(int argc, char **argv)
752 struct cYAML *err_rc = NULL;
755 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
759 rc = parse_long(argv[1], &value);
760 if (rc != 0 || (value != 0 && value != 1)) {
761 cYAML_build_error(-1, -1, "parser", "set",
762 "cannot parse routing value.\n"
763 "must be 0 for disable or 1 for enable",
765 cYAML_print_tree2file(stderr, err_rc);
766 cYAML_free_tree(err_rc);
770 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
772 if (rc != LUSTRE_CFG_RC_NO_ERR)
773 cYAML_print_tree2file(stderr, err_rc);
775 cYAML_free_tree(err_rc);
780 static int jt_config_lnet(int argc, char **argv)
782 struct cYAML *err_rc = NULL;
783 bool load_mod_params = false;
786 const char *const short_options = "a";
787 static const struct option long_options[] = {
788 { .name = "all", .has_arg = no_argument, .val = 'a' },
792 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
796 while ((opt = getopt_long(argc, argv, short_options,
797 long_options, NULL)) != -1) {
800 load_mod_params = true;
807 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
810 if (rc != LUSTRE_CFG_RC_NO_ERR)
811 cYAML_print_tree2file(stderr, err_rc);
813 cYAML_free_tree(err_rc);
818 static int jt_unconfig_lnet(int argc, char **argv)
820 struct cYAML *err_rc = NULL;
823 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
827 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
829 if (rc != LUSTRE_CFG_RC_NO_ERR)
830 cYAML_print_tree2file(stderr, err_rc);
832 cYAML_free_tree(err_rc);
836 static int jt_add_route(int argc, char **argv)
838 char *network = NULL, *gateway = NULL;
839 long int hop = -1, prio = -1, sen = -1;
840 struct cYAML *err_rc = NULL;
843 const char *const short_options = "n:g:c:p:";
844 static const struct option long_options[] = {
845 { .name = "net", .has_arg = required_argument, .val = 'n' },
846 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
847 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
848 { .name = "priority", .has_arg = required_argument, .val = 'p' },
849 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
852 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
856 while ((opt = getopt_long(argc, argv, short_options,
857 long_options, NULL)) != -1) {
866 rc = parse_long(optarg, &hop);
874 rc = parse_long(optarg, &prio);
882 rc = parse_long(optarg, &sen);
891 print_help(route_cmds, "route", "add");
897 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
900 if (rc != LUSTRE_CFG_RC_NO_ERR)
901 cYAML_print_tree2file(stderr, err_rc);
903 cYAML_free_tree(err_rc);
908 static int jt_add_ni(int argc, char **argv)
911 long int pto = -1, pc = -1, pbc = -1, cre = -1;
912 struct cYAML *err_rc = NULL;
913 int rc, opt, cpt_rc = -1;
914 struct lnet_dlc_network_descr nw_descr;
915 struct cfs_expr_list *global_cpts = NULL;
916 struct lnet_ioctl_config_lnd_tunables tunables;
919 memset(&tunables, 0, sizeof(tunables));
920 lustre_lnet_init_nw_descr(&nw_descr);
922 const char *const short_options = "n:i:p:t:c:b:r:s:";
923 static const struct option long_options[] = {
924 { .name = "net", .has_arg = required_argument, .val = 'n' },
925 { .name = "if", .has_arg = required_argument, .val = 'i' },
926 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
927 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
928 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
929 { .name = "peer-buffer-credits",
930 .has_arg = required_argument, .val = 'b' },
931 { .name = "credits", .has_arg = required_argument, .val = 'r' },
932 { .name = "cpt", .has_arg = required_argument, .val = 's' },
935 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
939 while ((opt = getopt_long(argc, argv, short_options,
940 long_options, NULL)) != -1) {
943 nw_descr.nw_id = libcfs_str2net(optarg);
946 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
948 cYAML_build_error(-1, -1, "ni", "add",
949 "bad interface list",
958 rc = parse_long(optarg, &pto);
966 rc = parse_long(optarg, &pc);
974 rc = parse_long(optarg, &pbc);
982 rc = parse_long(optarg, &cre);
990 cpt_rc = cfs_expr_list_parse(optarg,
992 UINT_MAX, &global_cpts);
995 print_help(net_cmds, "net", "add");
1001 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
1002 tunables.lt_cmn.lct_peer_timeout = pto;
1003 tunables.lt_cmn.lct_peer_tx_credits = pc;
1004 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1005 tunables.lt_cmn.lct_max_tx_credits = cre;
1009 rc = lustre_lnet_config_ni(&nw_descr,
1010 (cpt_rc == 0) ? global_cpts: NULL,
1011 ip2net, (found) ? &tunables : NULL,
1014 if (global_cpts != NULL)
1015 cfs_expr_list_free(global_cpts);
1018 if (rc != LUSTRE_CFG_RC_NO_ERR)
1019 cYAML_print_tree2file(stderr, err_rc);
1021 cYAML_free_tree(err_rc);
1026 static int jt_del_route(int argc, char **argv)
1028 char *network = NULL, *gateway = NULL;
1029 struct cYAML *err_rc = NULL;
1032 const char *const short_options = "n:g:";
1033 static const struct option long_options[] = {
1034 { .name = "net", .has_arg = required_argument, .val = 'n' },
1035 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1038 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1042 while ((opt = getopt_long(argc, argv, short_options,
1043 long_options, NULL)) != -1) {
1052 print_help(route_cmds, "route", "del");
1058 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1060 if (rc != LUSTRE_CFG_RC_NO_ERR)
1061 cYAML_print_tree2file(stderr, err_rc);
1063 cYAML_free_tree(err_rc);
1068 static int jt_del_ni(int argc, char **argv)
1070 struct cYAML *err_rc = NULL;
1072 struct lnet_dlc_network_descr nw_descr;
1074 lustre_lnet_init_nw_descr(&nw_descr);
1076 const char *const short_options = "n:i:";
1077 static const struct option long_options[] = {
1078 { .name = "net", .has_arg = required_argument, .val = 'n' },
1079 { .name = "if", .has_arg = required_argument, .val = 'i' },
1082 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1086 while ((opt = getopt_long(argc, argv, short_options,
1087 long_options, NULL)) != -1) {
1090 nw_descr.nw_id = libcfs_str2net(optarg);
1093 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1095 cYAML_build_error(-1, -1, "ni", "add",
1096 "bad interface list",
1102 print_help(net_cmds, "net", "del");
1108 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1111 if (rc != LUSTRE_CFG_RC_NO_ERR)
1112 cYAML_print_tree2file(stderr, err_rc);
1114 cYAML_free_tree(err_rc);
1119 static int jt_show_route(int argc, char **argv)
1121 char *network = NULL, *gateway = NULL;
1122 long int hop = -1, prio = -1;
1123 int detail = 0, rc, opt;
1124 struct cYAML *err_rc = NULL, *show_rc = NULL;
1126 const char *const short_options = "n:g:h:p:v";
1127 static const struct option long_options[] = {
1128 { .name = "net", .has_arg = required_argument, .val = 'n' },
1129 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1130 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1131 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1132 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1135 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1139 while ((opt = getopt_long(argc, argv, short_options,
1140 long_options, NULL)) != -1) {
1149 rc = parse_long(optarg, &hop);
1157 rc = parse_long(optarg, &prio);
1168 print_help(route_cmds, "route", "show");
1174 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1175 &show_rc, &err_rc, false);
1177 if (rc != LUSTRE_CFG_RC_NO_ERR)
1178 cYAML_print_tree2file(stderr, err_rc);
1180 cYAML_print_tree(show_rc);
1182 cYAML_free_tree(err_rc);
1183 cYAML_free_tree(show_rc);
1188 static int set_value_helper(int argc, char **argv,
1189 int (*cb)(int, bool, char*, int, struct cYAML**))
1192 long int healthv = -1;
1195 struct cYAML *err_rc = NULL;
1197 const char *const short_options = "t:n:a";
1198 static const struct option long_options[] = {
1199 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1200 { .name = "health", .has_arg = required_argument, .val = 't' },
1201 { .name = "all", .has_arg = no_argument, .val = 'a' },
1204 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1208 while ((opt = getopt_long(argc, argv, short_options,
1209 long_options, NULL)) != -1) {
1215 if (parse_long(optarg, &healthv) != 0)
1226 rc = cb(healthv, all, nid, -1, &err_rc);
1228 if (rc != LUSTRE_CFG_RC_NO_ERR)
1229 cYAML_print_tree2file(stderr, err_rc);
1231 cYAML_free_tree(err_rc);
1236 static int jt_set_ni_value(int argc, char **argv)
1238 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1241 static int jt_set_peer_ni_value(int argc, char **argv)
1243 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1246 static int jt_show_recovery(int argc, char **argv)
1249 struct cYAML *err_rc = NULL, *show_rc = NULL;
1251 const char *const short_options = "lp";
1252 static const struct option long_options[] = {
1253 { .name = "local", .has_arg = no_argument, .val = 'l' },
1254 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1257 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1261 while ((opt = getopt_long(argc, argv, short_options,
1262 long_options, NULL)) != -1) {
1265 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1268 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
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_net(int argc, char **argv)
1288 char *network = NULL;
1290 struct cYAML *err_rc = NULL, *show_rc = NULL;
1291 long int detail = 0;
1293 const char *const short_options = "n:v";
1294 static const struct option long_options[] = {
1295 { .name = "net", .has_arg = required_argument, .val = 'n' },
1296 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1299 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1303 while ((opt = getopt_long(argc, argv, short_options,
1304 long_options, NULL)) != -1) {
1310 if ((!optarg) && (argv[optind] != NULL) &&
1311 (argv[optind][0] != '-')) {
1312 if (parse_long(argv[optind++], &detail) != 0)
1319 print_help(net_cmds, "net", "show");
1325 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1328 if (rc != LUSTRE_CFG_RC_NO_ERR)
1329 cYAML_print_tree2file(stderr, err_rc);
1331 cYAML_print_tree(show_rc);
1333 cYAML_free_tree(err_rc);
1334 cYAML_free_tree(show_rc);
1339 static int jt_show_routing(int argc, char **argv)
1341 struct cYAML *err_rc = NULL, *show_rc = NULL;
1344 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1348 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1350 if (rc != LUSTRE_CFG_RC_NO_ERR)
1351 cYAML_print_tree2file(stderr, err_rc);
1353 cYAML_print_tree(show_rc);
1355 cYAML_free_tree(err_rc);
1356 cYAML_free_tree(show_rc);
1361 static int jt_show_stats(int argc, char **argv)
1364 struct cYAML *show_rc = NULL, *err_rc = NULL;
1366 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1370 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1372 if (rc != LUSTRE_CFG_RC_NO_ERR)
1373 cYAML_print_tree2file(stderr, err_rc);
1375 cYAML_print_tree(show_rc);
1377 cYAML_free_tree(err_rc);
1378 cYAML_free_tree(show_rc);
1383 static int jt_show_global(int argc, char **argv)
1386 struct cYAML *show_rc = NULL, *err_rc = NULL;
1388 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1392 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1393 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1394 cYAML_print_tree2file(stderr, err_rc);
1398 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1399 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1400 cYAML_print_tree2file(stderr, err_rc);
1404 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1405 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1406 cYAML_print_tree2file(stderr, err_rc);
1410 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1411 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1412 cYAML_print_tree2file(stderr, err_rc);
1416 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1417 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1418 cYAML_print_tree2file(stderr, err_rc);
1422 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1423 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1424 cYAML_print_tree2file(stderr, err_rc);
1428 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1429 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1430 cYAML_print_tree2file(stderr, err_rc);
1434 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1435 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1436 cYAML_print_tree2file(stderr, err_rc);
1440 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1441 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1442 cYAML_print_tree2file(stderr, err_rc);
1446 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1447 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1448 cYAML_print_tree2file(stderr, err_rc);
1452 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1453 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1454 cYAML_print_tree2file(stderr, err_rc);
1458 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1459 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1460 cYAML_print_tree2file(stderr, err_rc);
1465 cYAML_print_tree(show_rc);
1468 cYAML_free_tree(err_rc);
1469 cYAML_free_tree(show_rc);
1474 static int jt_lnet(int argc, char **argv)
1478 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1482 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1485 static int jt_route(int argc, char **argv)
1489 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1493 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1496 static int jt_net(int argc, char **argv)
1500 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1504 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1507 static int jt_routing(int argc, char **argv)
1511 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1515 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1518 static int jt_stats(int argc, char **argv)
1522 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1526 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1529 static int jt_debug(int argc, char **argv)
1533 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1537 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1540 static int jt_global(int argc, char **argv)
1544 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1548 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1551 static int jt_peers(int argc, char **argv)
1555 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1559 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1562 static int jt_set(int argc, char **argv)
1566 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1570 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1573 static int jt_import(int argc, char **argv)
1576 struct cYAML *err_rc = NULL;
1577 struct cYAML *show_rc = NULL;
1578 int rc = 0, return_rc = 0, opt, opt_found = 0;
1581 const char *const short_options = "adseh";
1582 static const struct option long_options[] = {
1583 { .name = "add", .has_arg = no_argument, .val = 'a' },
1584 { .name = "del", .has_arg = no_argument, .val = 'd' },
1585 { .name = "show", .has_arg = no_argument, .val = 's' },
1586 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1587 { .name = "help", .has_arg = no_argument, .val = 'h' },
1590 while ((opt = getopt_long(argc, argv, short_options,
1591 long_options, NULL)) != -1) {
1605 printf("import FILE\n"
1606 "import < FILE : import a file\n"
1607 "\t--add: add configuration\n"
1608 "\t--del: delete configuration\n"
1609 "\t--show: show configuration\n"
1610 "\t--exec: execute command\n"
1611 "\t--help: display this help\n"
1612 "If no command option is given then --add"
1613 " is assumed by default\n");
1620 /* grab the file name if one exists */
1621 if (opt_found && argc == 3)
1623 else if (!opt_found && argc == 2)
1628 rc = lustre_yaml_config(file, &err_rc);
1629 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1630 cYAML_print_tree(show_rc);
1631 cYAML_free_tree(show_rc);
1634 rc = lustre_yaml_del(file, &err_rc);
1637 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1638 cYAML_print_tree(show_rc);
1639 cYAML_free_tree(show_rc);
1642 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1643 cYAML_print_tree(show_rc);
1644 cYAML_free_tree(show_rc);
1648 if (rc || return_rc) {
1649 cYAML_print_tree2file(stderr, err_rc);
1650 cYAML_free_tree(err_rc);
1656 static int jt_export(int argc, char **argv)
1658 struct cYAML *show_rc = NULL;
1659 struct cYAML *err_rc = NULL;
1663 bool backup = false;
1666 const char *const short_options = "bh";
1667 static const struct option long_options[] = {
1668 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1669 { .name = "help", .has_arg = no_argument, .val = 'h' },
1672 while ((opt = getopt_long(argc, argv, short_options,
1673 long_options, NULL)) != -1) {
1680 printf("export > FILE.yaml : export configuration\n"
1681 "\t--backup: export only what's necessary for reconfig\n"
1682 "\t--help: display this help\n");
1687 if (backup && argc >= 3)
1689 else if (!backup && argc >= 2)
1695 f = fopen(file, "w");
1700 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
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_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1709 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1710 cYAML_print_tree2file(stderr, err_rc);
1711 cYAML_free_tree(err_rc);
1715 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1716 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1717 cYAML_print_tree2file(stderr, err_rc);
1718 cYAML_free_tree(err_rc);
1722 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1723 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1724 cYAML_print_tree2file(stderr, err_rc);
1725 cYAML_free_tree(err_rc);
1729 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1730 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1731 cYAML_print_tree2file(stderr, err_rc);
1732 cYAML_free_tree(err_rc);
1736 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1737 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1738 cYAML_print_tree2file(stderr, err_rc);
1739 cYAML_free_tree(err_rc);
1743 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1744 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1745 cYAML_print_tree2file(stderr, err_rc);
1746 cYAML_free_tree(err_rc);
1750 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1751 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1752 cYAML_print_tree2file(stderr, err_rc);
1753 cYAML_free_tree(err_rc);
1757 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1758 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1759 cYAML_print_tree2file(stderr, err_rc);
1763 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1764 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1765 cYAML_print_tree2file(stderr, err_rc);
1769 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1770 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1771 cYAML_print_tree2file(stderr, err_rc);
1775 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1776 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1777 cYAML_print_tree2file(stderr, err_rc);
1781 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1782 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1783 cYAML_print_tree2file(stderr, err_rc);
1787 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1788 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1789 cYAML_print_tree2file(stderr, err_rc);
1793 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1794 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1795 cYAML_print_tree2file(stderr, err_rc);
1796 cYAML_free_tree(err_rc);
1800 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1801 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1802 cYAML_print_tree2file(stderr, err_rc);
1803 cYAML_free_tree(err_rc);
1807 if (show_rc != NULL) {
1808 cYAML_print_tree2file(f, show_rc);
1809 cYAML_free_tree(show_rc);
1818 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1820 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1822 char *prim_nid = NULL, *nidstr = NULL;
1823 char err_str[LNET_MAX_STR_LEN] = "Error";
1824 struct cYAML *err_rc = NULL;
1826 const char *const short_opts = "k:mn:";
1827 const struct option long_opts[] = {
1828 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1829 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1830 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1833 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1837 while ((opt = getopt_long(argc, argv, short_opts,
1838 long_opts, NULL)) != -1) {
1847 if (cmd == LNETCTL_DEL_CMD) {
1848 rc = LUSTRE_CFG_RC_BAD_PARAM;
1849 snprintf(err_str, LNET_MAX_STR_LEN,
1850 "Unrecognized option '-%c'", opt);
1856 print_help(peer_cmds, "peer",
1857 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1863 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
1865 if (rc != LUSTRE_CFG_RC_NO_ERR)
1869 cYAML_build_error(rc, -1, "peer",
1870 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1874 if (rc != LUSTRE_CFG_RC_NO_ERR)
1875 cYAML_print_tree2file(stderr, err_rc);
1877 cYAML_free_tree(err_rc);
1882 static int jt_add_peer_nid(int argc, char **argv)
1884 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1887 static int jt_del_peer_nid(int argc, char **argv)
1889 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1892 static int jt_show_peer(int argc, char **argv)
1896 struct cYAML *err_rc = NULL, *show_rc = NULL;
1897 long int detail = 0;
1899 const char *const short_opts = "hn:v::";
1900 const struct option long_opts[] = {
1901 { .name = "help", .has_arg = no_argument, .val = 'h' },
1902 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1903 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1906 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1910 while ((opt = getopt_long(argc, argv, short_opts,
1911 long_opts, NULL)) != -1) {
1917 if ((!optarg) && (argv[optind] != NULL) &&
1918 (argv[optind][0] != '-')) {
1919 if (parse_long(argv[optind++], &detail) != 0)
1926 print_help(peer_cmds, "peer", "show");
1932 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1935 if (rc != LUSTRE_CFG_RC_NO_ERR)
1936 cYAML_print_tree2file(stderr, err_rc);
1938 cYAML_print_tree(show_rc);
1940 cYAML_free_tree(err_rc);
1941 cYAML_free_tree(show_rc);
1946 static int jt_list_peer(int argc, char **argv)
1949 struct cYAML *err_rc = NULL, *list_rc = NULL;
1951 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1955 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1957 if (rc != LUSTRE_CFG_RC_NO_ERR)
1958 cYAML_print_tree2file(stderr, err_rc);
1960 cYAML_print_tree(list_rc);
1962 cYAML_free_tree(err_rc);
1963 cYAML_free_tree(list_rc);
1968 static int jt_ping(int argc, char **argv)
1970 struct cYAML *err_rc = NULL;
1971 struct cYAML *show_rc = NULL;
1975 const char *const short_options = "ht:";
1976 const struct option long_options[] = {
1977 { .name = "help", .has_arg = no_argument, .val = 'h' },
1978 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1981 while ((opt = getopt_long(argc, argv, short_options,
1982 long_options, NULL)) != -1) {
1985 timeout = 1000 * atol(optarg);
1988 printf("ping nid[,nid,...]\n"
1989 "\t --timeout: ping timeout\n"
1990 "\t --help: display this help\n");
1997 for (; optind < argc; optind++)
1998 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
2001 cYAML_print_tree(show_rc);
2004 cYAML_print_tree2file(stderr, err_rc);
2006 cYAML_free_tree(err_rc);
2007 cYAML_free_tree(show_rc);
2012 static int jt_discover(int argc, char **argv)
2014 struct cYAML *err_rc = NULL;
2015 struct cYAML *show_rc = NULL;
2019 const char *const short_options = "fh";
2020 const struct option long_options[] = {
2021 { .name = "force", .has_arg = no_argument, .val = 'f' },
2022 { .name = "help", .has_arg = no_argument, .val = 'h' },
2025 while ((opt = getopt_long(argc, argv, short_options,
2026 long_options, NULL)) != -1) {
2032 printf("discover nid[,nid,...]\n"
2033 "\t --force: force discovery\n"
2034 "\t --help: display this help\n");
2041 for (; optind < argc; optind++)
2042 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2046 cYAML_print_tree(show_rc);
2049 cYAML_print_tree2file(stderr, err_rc);
2051 cYAML_free_tree(err_rc);
2052 cYAML_free_tree(show_rc);
2057 static int lnetctl_list_commands(int argc, char **argv)
2059 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2061 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2066 int main(int argc, char **argv)
2069 struct cYAML *err_rc = NULL;
2071 rc = lustre_lnet_config_lib_init();
2073 cYAML_build_error(-1, -1, "lnetctl", "startup",
2074 "cannot register LNet device", &err_rc);
2075 cYAML_print_tree2file(stderr, err_rc);
2079 Parser_init("lnetctl > ", cmd_list);
2081 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);