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_show_udsp(int argc, char **argv);
54 static int jt_set_tiny(int argc, char **argv);
55 static int jt_set_small(int argc, char **argv);
56 static int jt_set_large(int argc, char **argv);
57 static int jt_set_numa(int argc, char **argv);
58 static int jt_set_retry_count(int argc, char **argv);
59 static int jt_set_transaction_to(int argc, char **argv);
60 static int jt_set_recov_intrv(int argc, char **argv);
61 static int jt_set_rtr_sensitivity(int argc, char **argv);
62 static int jt_set_hsensitivity(int argc, char **argv);
63 static int jt_set_max_recovery_ping_interval(int argc, char **argv);
64 static int jt_reset_stats(int argc, char **argv);
65 static int jt_add_peer_nid(int argc, char **argv);
66 static int jt_del_peer_nid(int argc, char **argv);
67 static int jt_set_max_intf(int argc, char **argv);
68 static int jt_set_discovery(int argc, char **argv);
69 static int jt_set_drop_asym_route(int argc, char **argv);
70 static int jt_list_peer(int argc, char **argv);
71 static int jt_add_udsp(int argc, char **argv);
72 static int jt_del_udsp(int argc, char **argv);
73 /*static int jt_show_peer(int argc, char **argv);*/
74 static int lnetctl_list_commands(int argc, char **argv);
75 static int jt_import(int argc, char **argv);
76 static int jt_export(int argc, char **argv);
77 static int jt_ping(int argc, char **argv);
78 static int jt_discover(int argc, char **argv);
79 static int jt_lnet(int argc, char **argv);
80 static int jt_route(int argc, char **argv);
81 static int jt_net(int argc, char **argv);
82 static int jt_routing(int argc, char **argv);
83 static int jt_set(int argc, char **argv);
84 static int jt_debug(int argc, char **argv);
85 static int jt_stats(int argc, char **argv);
86 static int jt_global(int argc, char **argv);
87 static int jt_peers(int argc, char **argv);
88 static int jt_set_ni_value(int argc, char **argv);
89 static int jt_set_peer_ni_value(int argc, char **argv);
90 static int jt_calc_service_id(int argc, char **argv);
91 static int jt_set_response_tracking(int argc, char **argv);
92 static int jt_set_recovery_limit(int argc, char **argv);
93 static int jt_udsp(int argc, char **argv);
94 static int jt_setup_mrrouting(int argc, char **argv);
95 static int jt_calc_cpt_of_nid(int argc, char **argv);
97 command_t cmd_list[] = {
98 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
99 {"route", jt_route, 0, "route {add | del | show | help}"},
100 {"net", jt_net, 0, "net {add | del | show | set | help}"},
101 {"routing", jt_routing, 0, "routing {show | help}"},
102 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
103 " | routing | numa_range | max_interfaces"
104 " | discovery | drop_asym_route | retry_count"
105 " | transaction_timeout | health_sensitivity"
106 " | recovery_interval | router_sensitivity"
107 " | response_tracking | recovery_limit}"},
108 {"import", jt_import, 0, "import FILE.yaml"},
109 {"export", jt_export, 0, "export FILE.yaml"},
110 {"stats", jt_stats, 0, "stats {show | help}"},
111 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
112 {"global", jt_global, 0, "global {show | help}"},
113 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
114 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
115 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
116 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
117 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
118 {"setup-mrrouting", jt_setup_mrrouting, 0,
119 "setup linux routing tables\n"},
120 {"cpt-of-nid", jt_calc_cpt_of_nid, 0, "Calculate the CPT associated with NID\n"
121 "\t--nid: NID to calculate the CPT of\n"
122 "\t--ncpt: Number of CPTs to consider in the calculation\n"},
123 {"help", Parser_help, 0, "help"},
124 {"exit", Parser_quit, 0, "quit"},
125 {"quit", Parser_quit, 0, "quit"},
126 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
130 command_t lnet_cmds[] = {
131 {"configure", jt_config_lnet, 0, "configure lnet\n"
132 "\t--all: load NI configuration from module parameters\n"},
133 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
137 command_t route_cmds[] = {
138 {"add", jt_add_route, 0, "add a route\n"
139 "\t--net: net name (e.g. tcp0)\n"
140 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
141 "\t--hop: number to final destination (1 < hops < 255)\n"
142 "\t--priority: priority of route (0 - highest prio\n"
143 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
144 {"del", jt_del_route, 0, "delete a route\n"
145 "\t--net: net name (e.g. tcp0)\n"
146 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
147 {"show", jt_show_route, 0, "show routes\n"
148 "\t--net: net name (e.g. tcp0) to filter on\n"
149 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
150 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
151 "\t--priority: priority of route (0 - highest prio to filter on\n"
152 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
153 "\t--verbose: display detailed output per route\n"},
157 command_t net_cmds[] = {
158 {"add", jt_add_ni, 0, "add a network\n"
159 "\t--net: net name (e.g. tcp0)\n"
160 "\t--if: physical interface (e.g. eth0)\n"
161 "\t--ip2net: specify networks based on IP address patterns\n"
162 "\t--peer-timeout: time to wait before declaring a peer dead\n"
163 "\t--peer-credits: define the max number of inflight messages\n"
164 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
165 "\t--credits: Network Interface credits\n"
166 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
167 "\t--conns-per-peer: number of connections per peer\n"
168 "\t--skip-mr-route-setup: do not add linux route for the ni\n"},
169 {"del", jt_del_ni, 0, "delete a network\n"
170 "\t--net: net name (e.g. tcp0)\n"
171 "\t--if: physical interface (e.g. eth0)\n"},
172 {"show", jt_show_net, 0, "show networks\n"
173 "\t--net: net name (e.g. tcp0) to filter on\n"
174 "\t--verbose: display detailed output per network."
175 " Optional argument of '2' outputs more stats\n"},
176 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
177 "\t--nid: NI NID to set the\n"
178 "\t--health: specify health value to set\n"
179 "\t--conns-per-peer: number of connections per peer\n"
180 "\t--all: set all NIs value to the one specified\n"},
184 command_t routing_cmds[] = {
185 {"show", jt_show_routing, 0, "show routing information\n"},
189 command_t stats_cmds[] = {
190 {"show", jt_show_stats, 0, "show LNET statistics\n"},
191 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
195 command_t debug_cmds[] = {
196 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
197 "\t--local : list local recovery queue\n"
198 "\t--peer : list peer recovery queue\n"},
202 command_t global_cmds[] = {
203 {"show", jt_show_global, 0, "show global variables\n"},
207 command_t set_cmds[] = {
208 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
209 "\tVALUE must be greater than 0\n"},
210 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
211 "\tVALUE must be greater than 0\n"},
212 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
213 "\tVALUE must be greater than 0\n"},
214 {"routing", jt_set_routing, 0, "enable/disable routing\n"
215 "\t0 - disable routing\n"
216 "\t1 - enable routing\n"},
217 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
218 "\tVALUE must be at least 0\n"},
219 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
221 "\tValue must be greater than 16\n"},
222 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
223 "\t0 - disable peer discovery\n"
224 "\t1 - enable peer discovery (default)\n"},
225 {"drop_asym_route", jt_set_drop_asym_route, 0,
226 "drop/accept asymmetrical route messages\n"
227 "\t0 - accept asymmetrical route messages (default)\n"
228 "\t1 - drop asymmetrical route messages\n"},
229 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
230 "\t0 - turn of retries\n"
231 "\t>0 - number of retries\n"},
232 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
233 "\t>0 - timeout in seconds\n"},
234 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
235 "\t0 - turn off health evaluation\n"
236 "\t>0 - sensitivity value not more than 1000\n"},
237 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
238 "\t>0 - time in seconds between pings\n"},
239 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
240 "\t100 - router interfaces need to be fully healthy to be used\n"
241 "\t<100 - router interfaces can be used even if not healthy\n"},
242 {"response_tracking", jt_set_response_tracking, 0,
243 "Set the behavior of response tracking\n"
244 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
245 "\t1 - GETs are eligible for response tracking\n"
246 "\t2 - PUTs are eligible for response tracking\n"
247 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
248 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
249 "\t pings and discovery pushes always utilize response tracking\n"},
250 {"recovery_limit", jt_set_recovery_limit, 0,
251 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
252 "\t0 - Recover indefinitely (default)\n"
253 "\t>0 - Recover for the specified number of seconds.\n"},
254 {"max_recovery_ping_interval", jt_set_max_recovery_ping_interval, 0,
255 "maximum recovery ping interval\n"
256 "\t>0 - maximum recovery ping interval in seconds\n"},
260 command_t peer_cmds[] = {
261 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
262 "\t--prim_nid: Primary NID of the peer.\n"
263 "\t--nid: one or more peer NIDs\n"
264 "\t--non_mr: create this peer as not Multi-Rail capable\n"
265 "\t--ip2nets: specify a range of nids per peer"},
266 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
267 "\t--prim_nid: Primary NID of the peer.\n"
268 "\t--nid: list of NIDs to remove. If none provided,\n"
269 "\t peer is deleted\n"
270 "\t--ip2nets: specify a range of nids per peer"},
271 {"show", jt_show_peer, 0, "show peer information\n"
272 "\t--nid: NID of peer to filter on.\n"
273 "\t--verbose: display detailed output per peer."
274 " Optional argument of '2' outputs more stats\n"},
275 {"list", jt_list_peer, 0, "list all peers\n"},
276 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
277 "\t--nid: Peer NI NID to set the\n"
278 "\t--health: specify health value to set\n"
279 "\t--all: set all peer_nis values to the one specified\n"},
283 command_t udsp_cmds[] = {
284 {"add", jt_add_udsp, 0, "add a udsp\n"
285 "\t--src: ip2nets syntax specifying the local NID to match\n"
286 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
287 "\t--rte: ip2nets syntax specifying the router NID to match\n"
288 "\t--priority: priority value (0 - highest priority)\n"
289 "\t--idx: index of where to insert the rule.\n"
290 "\t By default, appends to the end of the rule list.\n"},
291 {"del", jt_del_udsp, 0, "delete a udsp\n"
292 "\t--idx: index of the Policy.\n"},
293 {"show", jt_show_udsp, 0, "show udsps\n"
294 "\t --idx: index of the policy to show.\n"},
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 jt_setup_mrrouting(int argc, char **argv)
315 struct cYAML *err_rc = NULL;
317 rc = lustre_lnet_setup_mrrouting(&err_rc);
319 if (rc != LUSTRE_CFG_RC_NO_ERR)
320 cYAML_print_tree2file(stderr, err_rc);
322 cYAML_free_tree(err_rc);
327 static inline void print_help(const command_t cmds[], const char *cmd_type,
330 const command_t *cmd;
332 for (cmd = cmds; cmd->pc_name; cmd++) {
333 if (pc_name != NULL &&
334 strcmp(cmd->pc_name, pc_name) == 0) {
335 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
338 } else if (pc_name != NULL) {
341 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
345 static int check_cmd(const command_t *cmd_list, const char *cmd,
346 const char *sub_cmd, const int min_args,
347 int argc, char **argv)
354 const char *const short_options = "h";
355 static const struct option long_options[] = {
356 { .name = "help", .has_arg = no_argument, .val = 'h' },
360 if (argc < min_args) {
361 print_help(cmd_list, cmd, sub_cmd);
364 } else if (argc > 2) {
368 while ((opt = getopt_long(argc, argv, short_options,
369 long_options, NULL)) != -1) {
372 print_help(cmd_list, cmd, sub_cmd);
387 static int jt_set_response_tracking(int argc, char **argv)
391 struct cYAML *err_rc = NULL;
393 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
397 rc = parse_long(argv[1], &value);
399 cYAML_build_error(-1, -1, "parser", "set",
400 "cannot parse response_tracking value",
402 cYAML_print_tree2file(stderr, err_rc);
403 cYAML_free_tree(err_rc);
407 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
408 if (rc != LUSTRE_CFG_RC_NO_ERR)
409 cYAML_print_tree2file(stderr, err_rc);
411 cYAML_free_tree(err_rc);
416 static int jt_calc_service_id(int argc, char **argv)
421 rc = lustre_lnet_calc_service_id(&service_id);
422 if (rc != LUSTRE_CFG_RC_NO_ERR)
425 /* cYAML currently doesn't support printing hex values.
426 * Therefore just print it locally here
428 printf("service_id:\n value: 0x%llx\n",
429 (unsigned long long)(service_id));
434 static int jt_calc_cpt_of_nid(int argc, char **argv)
440 struct cYAML *err_rc = NULL;
441 const char *const short_options = "n:c:h";
442 static const struct option long_options[] = {
443 { .name = "nid", .has_arg = required_argument, .val = 'n' },
444 { .name = "ncpt", .has_arg = required_argument, .val = 'c' },
447 rc = check_cmd(cmd_list, "", "cpt-of-nid", 0, argc, argv);
451 while ((opt = getopt_long(argc, argv, short_options,
452 long_options, NULL)) != -1) {
458 rc = parse_long(optarg, &ncpts);
460 cYAML_build_error(-1, -1, "cpt", "get",
461 "cannot parse input", &err_rc);
462 cYAML_print_tree2file(stderr, err_rc);
463 cYAML_free_tree(err_rc);
468 print_help(cmd_list, "", "cpt-of-nid");
474 cpt = lustre_lnet_calc_cpt_of_nid(nid, ncpts);
478 printf("cpt:\n value: %d\n", cpt);
483 static int jt_set_recovery_limit(int argc, char **argv)
487 struct cYAML *err_rc = NULL;
489 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
493 rc = parse_long(argv[1], &value);
495 cYAML_build_error(-1, -1, "parser", "set",
496 "cannot parse recovery_limit value",
498 cYAML_print_tree2file(stderr, err_rc);
499 cYAML_free_tree(err_rc);
503 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
504 if (rc != LUSTRE_CFG_RC_NO_ERR)
505 cYAML_print_tree2file(stderr, err_rc);
507 cYAML_free_tree(err_rc);
512 static int jt_set_max_intf(int argc, char **argv)
516 struct cYAML *err_rc = NULL;
518 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
522 rc = parse_long(argv[1], &value);
524 cYAML_build_error(-1, -1, "parser", "set",
525 "cannot parse max_interfaces value", &err_rc);
526 cYAML_print_tree2file(stderr, err_rc);
527 cYAML_free_tree(err_rc);
531 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
532 if (rc != LUSTRE_CFG_RC_NO_ERR)
533 cYAML_print_tree2file(stderr, err_rc);
535 cYAML_free_tree(err_rc);
540 static int jt_set_numa(int argc, char **argv)
544 struct cYAML *err_rc = NULL;
546 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
550 rc = parse_long(argv[1], &value);
552 cYAML_build_error(-1, -1, "parser", "set",
553 "cannot parse numa_range value", &err_rc);
554 cYAML_print_tree2file(stderr, err_rc);
555 cYAML_free_tree(err_rc);
559 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
560 if (rc != LUSTRE_CFG_RC_NO_ERR)
561 cYAML_print_tree2file(stderr, err_rc);
563 cYAML_free_tree(err_rc);
568 static int jt_set_recov_intrv(int argc, char **argv)
572 struct cYAML *err_rc = NULL;
574 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
578 rc = parse_long(argv[1], &value);
580 cYAML_build_error(-1, -1, "parser", "set",
581 "cannot parse recovery interval value", &err_rc);
582 cYAML_print_tree2file(stderr, err_rc);
583 cYAML_free_tree(err_rc);
587 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
588 if (rc != LUSTRE_CFG_RC_NO_ERR)
589 cYAML_print_tree2file(stderr, err_rc);
591 cYAML_free_tree(err_rc);
596 static int jt_set_rtr_sensitivity(int argc, char **argv)
600 struct cYAML *err_rc = NULL;
602 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
606 rc = parse_long(argv[1], &value);
608 cYAML_build_error(-1, -1, "parser", "set",
609 "cannot parse router sensitivity value", &err_rc);
610 cYAML_print_tree2file(stderr, err_rc);
611 cYAML_free_tree(err_rc);
615 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
616 if (rc != LUSTRE_CFG_RC_NO_ERR)
617 cYAML_print_tree2file(stderr, err_rc);
619 cYAML_free_tree(err_rc);
624 static int jt_set_hsensitivity(int argc, char **argv)
628 struct cYAML *err_rc = NULL;
630 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
634 rc = parse_long(argv[1], &value);
636 cYAML_build_error(-1, -1, "parser", "set",
637 "cannot parse health sensitivity value", &err_rc);
638 cYAML_print_tree2file(stderr, err_rc);
639 cYAML_free_tree(err_rc);
643 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
644 if (rc != LUSTRE_CFG_RC_NO_ERR)
645 cYAML_print_tree2file(stderr, err_rc);
647 cYAML_free_tree(err_rc);
652 static int jt_reset_stats(int argc, char **argv)
655 struct cYAML *err_rc = NULL;
657 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
661 rc = lustre_lnet_reset_stats(-1, &err_rc);
662 if (rc != LUSTRE_CFG_RC_NO_ERR)
663 cYAML_print_tree2file(stderr, err_rc);
665 cYAML_free_tree(err_rc);
670 static int jt_set_transaction_to(int argc, char **argv)
674 struct cYAML *err_rc = NULL;
676 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
680 rc = parse_long(argv[1], &value);
682 cYAML_build_error(-1, -1, "parser", "set",
683 "cannot parse transaction timeout value", &err_rc);
684 cYAML_print_tree2file(stderr, err_rc);
685 cYAML_free_tree(err_rc);
689 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
690 if (rc != LUSTRE_CFG_RC_NO_ERR)
691 cYAML_print_tree2file(stderr, err_rc);
693 cYAML_free_tree(err_rc);
698 static int jt_set_retry_count(int argc, char **argv)
702 struct cYAML *err_rc = NULL;
704 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
708 rc = parse_long(argv[1], &value);
710 cYAML_build_error(-1, -1, "parser", "set",
711 "cannot parse retry_count value", &err_rc);
712 cYAML_print_tree2file(stderr, err_rc);
713 cYAML_free_tree(err_rc);
717 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
718 if (rc != LUSTRE_CFG_RC_NO_ERR)
719 cYAML_print_tree2file(stderr, err_rc);
721 cYAML_free_tree(err_rc);
726 static int jt_set_discovery(int argc, char **argv)
730 struct cYAML *err_rc = NULL;
732 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
736 rc = parse_long(argv[1], &value);
738 cYAML_build_error(-1, -1, "parser", "set",
739 "cannot parse discovery value", &err_rc);
740 cYAML_print_tree2file(stderr, err_rc);
741 cYAML_free_tree(err_rc);
745 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
746 if (rc != LUSTRE_CFG_RC_NO_ERR)
747 cYAML_print_tree2file(stderr, err_rc);
749 cYAML_free_tree(err_rc);
754 static int jt_set_drop_asym_route(int argc, char **argv)
758 struct cYAML *err_rc = NULL;
760 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
764 rc = parse_long(argv[1], &value);
766 cYAML_build_error(-1, -1, "parser", "set",
767 "cannot parse drop_asym_route value",
769 cYAML_print_tree2file(stderr, err_rc);
770 cYAML_free_tree(err_rc);
774 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
775 if (rc != LUSTRE_CFG_RC_NO_ERR)
776 cYAML_print_tree2file(stderr, err_rc);
778 cYAML_free_tree(err_rc);
783 static int jt_set_tiny(int argc, char **argv)
787 struct cYAML *err_rc = NULL;
789 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
793 rc = parse_long(argv[1], &value);
795 cYAML_build_error(-1, -1, "parser", "set",
796 "cannot parse tiny_buffers value", &err_rc);
797 cYAML_print_tree2file(stderr, err_rc);
798 cYAML_free_tree(err_rc);
802 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
803 if (rc != LUSTRE_CFG_RC_NO_ERR)
804 cYAML_print_tree2file(stderr, err_rc);
806 cYAML_free_tree(err_rc);
811 static int jt_set_small(int argc, char **argv)
815 struct cYAML *err_rc = NULL;
817 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
821 rc = parse_long(argv[1], &value);
823 cYAML_build_error(-1, -1, "parser", "set",
824 "cannot parse small_buffers value", &err_rc);
825 cYAML_print_tree2file(stderr, err_rc);
826 cYAML_free_tree(err_rc);
830 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
831 if (rc != LUSTRE_CFG_RC_NO_ERR)
832 cYAML_print_tree2file(stderr, err_rc);
834 cYAML_free_tree(err_rc);
839 static int jt_set_large(int argc, char **argv)
843 struct cYAML *err_rc = NULL;
845 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
849 rc = parse_long(argv[1], &value);
851 cYAML_build_error(-1, -1, "parser", "set",
852 "cannot parse large_buffers value", &err_rc);
853 cYAML_print_tree2file(stderr, err_rc);
854 cYAML_free_tree(err_rc);
858 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
859 if (rc != LUSTRE_CFG_RC_NO_ERR)
860 cYAML_print_tree2file(stderr, err_rc);
862 cYAML_free_tree(err_rc);
867 static int jt_set_routing(int argc, char **argv)
870 struct cYAML *err_rc = NULL;
873 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
877 rc = parse_long(argv[1], &value);
878 if (rc != 0 || (value != 0 && value != 1)) {
879 cYAML_build_error(-1, -1, "parser", "set",
880 "cannot parse routing value.\n"
881 "must be 0 for disable or 1 for enable",
883 cYAML_print_tree2file(stderr, err_rc);
884 cYAML_free_tree(err_rc);
888 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
890 if (rc != LUSTRE_CFG_RC_NO_ERR)
891 cYAML_print_tree2file(stderr, err_rc);
893 cYAML_free_tree(err_rc);
898 static int jt_set_max_recovery_ping_interval(int argc, char **argv)
902 struct cYAML *err_rc = NULL;
904 rc = check_cmd(set_cmds, "set", "maximum recovery_interval", 2, argc, argv);
908 rc = parse_long(argv[1], &value);
910 cYAML_build_error(-1, -1, "parser", "set",
911 "cannot parse maximum recovery interval value",
913 cYAML_print_tree2file(stderr, err_rc);
914 cYAML_free_tree(err_rc);
918 rc = lustre_lnet_config_max_recovery_ping_interval(value, -1, &err_rc);
919 if (rc != LUSTRE_CFG_RC_NO_ERR)
920 cYAML_print_tree2file(stderr, err_rc);
922 cYAML_free_tree(err_rc);
928 static int jt_config_lnet(int argc, char **argv)
930 struct cYAML *err_rc = NULL;
931 bool load_mod_params = false;
934 const char *const short_options = "a";
935 static const struct option long_options[] = {
936 { .name = "all", .has_arg = no_argument, .val = 'a' },
940 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
944 while ((opt = getopt_long(argc, argv, short_options,
945 long_options, NULL)) != -1) {
948 load_mod_params = true;
955 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
958 if (rc != LUSTRE_CFG_RC_NO_ERR)
959 cYAML_print_tree2file(stderr, err_rc);
961 cYAML_free_tree(err_rc);
966 static int jt_unconfig_lnet(int argc, char **argv)
968 struct cYAML *err_rc = NULL;
971 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
975 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
977 if (rc != LUSTRE_CFG_RC_NO_ERR)
978 cYAML_print_tree2file(stderr, err_rc);
980 cYAML_free_tree(err_rc);
984 static int jt_add_route(int argc, char **argv)
986 char *network = NULL, *gateway = NULL;
987 long int hop = -1, prio = -1, sen = -1;
988 struct cYAML *err_rc = NULL;
991 const char *const short_options = "n:g:c:p:";
992 static const struct option long_options[] = {
993 { .name = "net", .has_arg = required_argument, .val = 'n' },
994 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
995 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
996 { .name = "priority", .has_arg = required_argument, .val = 'p' },
997 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1000 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1004 while ((opt = getopt_long(argc, argv, short_options,
1005 long_options, NULL)) != -1) {
1014 rc = parse_long(optarg, &hop);
1022 rc = parse_long(optarg, &prio);
1030 rc = parse_long(optarg, &sen);
1039 print_help(route_cmds, "route", "add");
1045 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1048 if (rc != LUSTRE_CFG_RC_NO_ERR)
1049 cYAML_print_tree2file(stderr, err_rc);
1051 cYAML_free_tree(err_rc);
1056 static int jt_add_ni(int argc, char **argv)
1058 char *ip2net = NULL;
1059 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1;
1060 struct cYAML *err_rc = NULL;
1061 int rc, opt, cpt_rc = -1;
1062 struct lnet_dlc_network_descr nw_descr;
1063 struct cfs_expr_list *global_cpts = NULL;
1064 struct lnet_ioctl_config_lnd_tunables tunables;
1066 bool skip_mr_route_setup = false;
1068 memset(&tunables, 0, sizeof(tunables));
1069 lustre_lnet_init_nw_descr(&nw_descr);
1071 const char *const short_options = "b:c:i:k:m:n:p:r:s:t:";
1072 static const struct option long_options[] = {
1073 { .name = "peer-buffer-credits",
1074 .has_arg = required_argument, .val = 'b' },
1075 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
1076 { .name = "if", .has_arg = required_argument, .val = 'i' },
1077 { .name = "skip-mr-route-setup",
1078 .has_arg = no_argument, .val = 'k' },
1079 { .name = "conns-per-peer",
1080 .has_arg = required_argument, .val = 'm' },
1081 { .name = "net", .has_arg = required_argument, .val = 'n' },
1082 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
1083 { .name = "credits", .has_arg = required_argument, .val = 'r' },
1084 { .name = "cpt", .has_arg = required_argument, .val = 's' },
1085 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
1088 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
1092 while ((opt = getopt_long(argc, argv, short_options,
1093 long_options, NULL)) != -1) {
1096 rc = parse_long(optarg, &pbc);
1104 rc = parse_long(optarg, &pc);
1112 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1114 cYAML_build_error(-1, -1, "ni", "add",
1115 "bad interface list",
1121 skip_mr_route_setup = true;
1124 rc = parse_long(optarg, &cpp);
1133 nw_descr.nw_id = libcfs_str2net(optarg);
1139 rc = parse_long(optarg, &cre);
1147 cpt_rc = cfs_expr_list_parse(optarg,
1149 UINT_MAX, &global_cpts);
1152 rc = parse_long(optarg, &pto);
1160 print_help(net_cmds, "net", "add");
1166 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
1167 tunables.lt_cmn.lct_peer_timeout = pto;
1168 tunables.lt_cmn.lct_peer_tx_credits = pc;
1169 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1170 tunables.lt_cmn.lct_max_tx_credits = cre;
1174 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
1175 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
1177 rc = lustre_lnet_config_ni(&nw_descr,
1178 (cpt_rc == 0) ? global_cpts: NULL,
1179 ip2net, (found) ? &tunables : NULL,
1182 if (global_cpts != NULL)
1183 cfs_expr_list_free(global_cpts);
1186 if (rc != LUSTRE_CFG_RC_NO_ERR)
1187 cYAML_print_tree2file(stderr, err_rc);
1189 cYAML_free_tree(err_rc);
1191 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
1193 rc = lustre_lnet_setup_mrrouting(&err_rc);
1195 if (rc != LUSTRE_CFG_RC_NO_ERR)
1196 cYAML_print_tree2file(stderr, err_rc);
1198 cYAML_free_tree(err_rc);
1204 static int jt_del_route(int argc, char **argv)
1206 char *network = NULL, *gateway = NULL;
1207 struct cYAML *err_rc = NULL;
1210 const char *const short_options = "n:g:";
1211 static const struct option long_options[] = {
1212 { .name = "net", .has_arg = required_argument, .val = 'n' },
1213 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1216 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1220 while ((opt = getopt_long(argc, argv, short_options,
1221 long_options, NULL)) != -1) {
1230 print_help(route_cmds, "route", "del");
1236 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1238 if (rc != LUSTRE_CFG_RC_NO_ERR)
1239 cYAML_print_tree2file(stderr, err_rc);
1241 cYAML_free_tree(err_rc);
1246 static int jt_del_ni(int argc, char **argv)
1248 struct cYAML *err_rc = NULL;
1250 struct lnet_dlc_network_descr nw_descr;
1252 lustre_lnet_init_nw_descr(&nw_descr);
1254 const char *const short_options = "n:i:";
1255 static const struct option long_options[] = {
1256 { .name = "net", .has_arg = required_argument, .val = 'n' },
1257 { .name = "if", .has_arg = required_argument, .val = 'i' },
1260 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1264 while ((opt = getopt_long(argc, argv, short_options,
1265 long_options, NULL)) != -1) {
1268 nw_descr.nw_id = libcfs_str2net(optarg);
1271 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1273 cYAML_build_error(-1, -1, "ni", "add",
1274 "bad interface list",
1280 print_help(net_cmds, "net", "del");
1286 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1289 if (rc != LUSTRE_CFG_RC_NO_ERR)
1290 cYAML_print_tree2file(stderr, err_rc);
1292 cYAML_free_tree(err_rc);
1297 static int jt_show_route(int argc, char **argv)
1299 char *network = NULL, *gateway = NULL;
1300 long int hop = -1, prio = -1;
1301 int detail = 0, rc, opt;
1302 struct cYAML *err_rc = NULL, *show_rc = NULL;
1304 const char *const short_options = "n:g:h:p:v";
1305 static const struct option long_options[] = {
1306 { .name = "net", .has_arg = required_argument, .val = 'n' },
1307 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1308 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1309 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1310 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1313 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1317 while ((opt = getopt_long(argc, argv, short_options,
1318 long_options, NULL)) != -1) {
1327 rc = parse_long(optarg, &hop);
1335 rc = parse_long(optarg, &prio);
1346 print_help(route_cmds, "route", "show");
1352 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1353 &show_rc, &err_rc, false);
1355 if (rc != LUSTRE_CFG_RC_NO_ERR)
1356 cYAML_print_tree2file(stderr, err_rc);
1358 cYAML_print_tree(show_rc);
1360 cYAML_free_tree(err_rc);
1361 cYAML_free_tree(show_rc);
1366 static int set_value_helper(int argc, char **argv,
1367 int (*cb)(int, bool, char*, int, struct cYAML**))
1370 long int healthv = -1;
1373 struct cYAML *err_rc = NULL;
1375 const char *const short_options = "t:n:a";
1376 static const struct option long_options[] = {
1377 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1378 { .name = "health", .has_arg = required_argument, .val = 't' },
1379 { .name = "all", .has_arg = no_argument, .val = 'a' },
1382 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1386 while ((opt = getopt_long(argc, argv, short_options,
1387 long_options, NULL)) != -1) {
1393 if (parse_long(optarg, &healthv) != 0)
1404 rc = cb(healthv, all, nid, -1, &err_rc);
1406 if (rc != LUSTRE_CFG_RC_NO_ERR)
1407 cYAML_print_tree2file(stderr, err_rc);
1409 cYAML_free_tree(err_rc);
1414 static int jt_set_ni_value(int argc, char **argv)
1417 long int healthv = -1, cpp = -1;
1420 struct cYAML *err_rc = NULL;
1422 const char *const short_options = "a:m:n:t:";
1423 static const struct option long_options[] = {
1424 { .name = "all", .has_arg = no_argument, .val = 'a' },
1425 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
1426 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1427 { .name = "health", .has_arg = required_argument, .val = 't' },
1430 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1434 while ((opt = getopt_long(argc, argv, short_options,
1435 long_options, NULL)) != -1) {
1441 rc = parse_long(optarg, &cpp);
1452 if (parse_long(optarg, &healthv) != 0) {
1464 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
1467 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
1470 if (rc != LUSTRE_CFG_RC_NO_ERR)
1471 cYAML_print_tree2file(stderr, err_rc);
1473 cYAML_free_tree(err_rc);
1478 static int jt_set_peer_ni_value(int argc, char **argv)
1480 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1483 static int jt_show_recovery(int argc, char **argv)
1486 struct cYAML *err_rc = NULL, *show_rc = NULL;
1488 const char *const short_options = "lp";
1489 static const struct option long_options[] = {
1490 { .name = "local", .has_arg = no_argument, .val = 'l' },
1491 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1494 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1498 while ((opt = getopt_long(argc, argv, short_options,
1499 long_options, NULL)) != -1) {
1502 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1505 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1512 if (rc != LUSTRE_CFG_RC_NO_ERR)
1513 cYAML_print_tree2file(stderr, err_rc);
1515 cYAML_print_tree(show_rc);
1517 cYAML_free_tree(err_rc);
1518 cYAML_free_tree(show_rc);
1523 static int jt_show_net(int argc, char **argv)
1525 char *network = NULL;
1527 struct cYAML *err_rc = NULL, *show_rc = NULL;
1528 long int detail = 0;
1530 const char *const short_options = "n:v";
1531 static const struct option long_options[] = {
1532 { .name = "net", .has_arg = required_argument, .val = 'n' },
1533 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1536 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1540 while ((opt = getopt_long(argc, argv, short_options,
1541 long_options, NULL)) != -1) {
1547 if ((!optarg) && (argv[optind] != NULL) &&
1548 (argv[optind][0] != '-')) {
1549 if (parse_long(argv[optind++], &detail) != 0)
1556 print_help(net_cmds, "net", "show");
1562 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1565 if (rc != LUSTRE_CFG_RC_NO_ERR)
1566 cYAML_print_tree2file(stderr, err_rc);
1568 cYAML_print_tree(show_rc);
1570 cYAML_free_tree(err_rc);
1571 cYAML_free_tree(show_rc);
1576 static int jt_show_routing(int argc, char **argv)
1578 struct cYAML *err_rc = NULL, *show_rc = NULL;
1581 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1585 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1587 if (rc != LUSTRE_CFG_RC_NO_ERR)
1588 cYAML_print_tree2file(stderr, err_rc);
1590 cYAML_print_tree(show_rc);
1592 cYAML_free_tree(err_rc);
1593 cYAML_free_tree(show_rc);
1598 static int jt_show_stats(int argc, char **argv)
1601 struct cYAML *show_rc = NULL, *err_rc = NULL;
1603 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1607 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1609 if (rc != LUSTRE_CFG_RC_NO_ERR)
1610 cYAML_print_tree2file(stderr, err_rc);
1612 cYAML_print_tree(show_rc);
1614 cYAML_free_tree(err_rc);
1615 cYAML_free_tree(show_rc);
1620 static int jt_show_udsp(int argc, char **argv)
1624 struct cYAML *err_rc = NULL, *show_rc = NULL;
1626 const char *const short_options = "i:";
1627 static const struct option long_options[] = {
1628 { .name = "idx", .has_arg = required_argument, .val = 'i' },
1632 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
1636 while ((opt = getopt_long(argc, argv, short_options,
1637 long_options, NULL)) != -1) {
1643 print_help(net_cmds, "net", "show");
1649 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
1651 if (rc != LUSTRE_CFG_RC_NO_ERR)
1652 cYAML_print_tree2file(stderr, err_rc);
1654 cYAML_print_tree(show_rc);
1656 cYAML_free_tree(err_rc);
1657 cYAML_free_tree(show_rc);
1662 static int jt_show_global(int argc, char **argv)
1665 struct cYAML *show_rc = NULL, *err_rc = NULL;
1667 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1671 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1672 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1673 cYAML_print_tree2file(stderr, err_rc);
1677 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1678 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1679 cYAML_print_tree2file(stderr, err_rc);
1683 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1684 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1685 cYAML_print_tree2file(stderr, err_rc);
1689 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1690 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1691 cYAML_print_tree2file(stderr, err_rc);
1695 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1696 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1697 cYAML_print_tree2file(stderr, err_rc);
1701 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1702 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1703 cYAML_print_tree2file(stderr, err_rc);
1707 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1708 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1709 cYAML_print_tree2file(stderr, err_rc);
1713 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1714 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1715 cYAML_print_tree2file(stderr, err_rc);
1719 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1720 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1721 cYAML_print_tree2file(stderr, err_rc);
1725 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1726 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1727 cYAML_print_tree2file(stderr, err_rc);
1731 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1732 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1733 cYAML_print_tree2file(stderr, err_rc);
1737 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1738 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1739 cYAML_print_tree2file(stderr, err_rc);
1743 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
1744 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1745 cYAML_print_tree2file(stderr, err_rc);
1750 cYAML_print_tree(show_rc);
1753 cYAML_free_tree(err_rc);
1754 cYAML_free_tree(show_rc);
1759 static int jt_lnet(int argc, char **argv)
1763 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1767 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1770 static int jt_route(int argc, char **argv)
1774 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1778 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1781 static int jt_net(int argc, char **argv)
1785 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1789 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1792 static int jt_routing(int argc, char **argv)
1796 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1800 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1803 static int jt_stats(int argc, char **argv)
1807 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1811 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1814 static int jt_debug(int argc, char **argv)
1818 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1822 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1825 static int jt_global(int argc, char **argv)
1829 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1833 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1836 static int jt_peers(int argc, char **argv)
1840 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1844 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1847 static int jt_set(int argc, char **argv)
1851 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1855 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1858 static int jt_udsp(int argc, char **argv)
1862 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1866 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1869 static int jt_import(int argc, char **argv)
1872 struct cYAML *err_rc = NULL;
1873 struct cYAML *show_rc = NULL;
1874 int rc = 0, return_rc = 0, opt, opt_found = 0;
1877 const char *const short_options = "adseh";
1878 static const struct option long_options[] = {
1879 { .name = "add", .has_arg = no_argument, .val = 'a' },
1880 { .name = "del", .has_arg = no_argument, .val = 'd' },
1881 { .name = "show", .has_arg = no_argument, .val = 's' },
1882 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1883 { .name = "help", .has_arg = no_argument, .val = 'h' },
1886 while ((opt = getopt_long(argc, argv, short_options,
1887 long_options, NULL)) != -1) {
1901 printf("import FILE\n"
1902 "import < FILE : import a file\n"
1903 "\t--add: add configuration\n"
1904 "\t--del: delete configuration\n"
1905 "\t--show: show configuration\n"
1906 "\t--exec: execute command\n"
1907 "\t--help: display this help\n"
1908 "If no command option is given then --add"
1909 " is assumed by default\n");
1916 /* grab the file name if one exists */
1917 if (opt_found && argc == 3)
1919 else if (!opt_found && argc == 2)
1924 rc = lustre_yaml_config(file, &err_rc);
1925 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1926 cYAML_print_tree(show_rc);
1927 cYAML_free_tree(show_rc);
1930 rc = lustre_yaml_del(file, &err_rc);
1933 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1934 cYAML_print_tree(show_rc);
1935 cYAML_free_tree(show_rc);
1938 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1939 cYAML_print_tree(show_rc);
1940 cYAML_free_tree(show_rc);
1944 if (rc || return_rc) {
1945 cYAML_print_tree2file(stderr, err_rc);
1946 cYAML_free_tree(err_rc);
1952 static int jt_export(int argc, char **argv)
1954 struct cYAML *show_rc = NULL;
1955 struct cYAML *err_rc = NULL;
1959 bool backup = false;
1962 const char *const short_options = "bh";
1963 static const struct option long_options[] = {
1964 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1965 { .name = "help", .has_arg = no_argument, .val = 'h' },
1968 while ((opt = getopt_long(argc, argv, short_options,
1969 long_options, NULL)) != -1) {
1976 printf("export > FILE.yaml : export configuration\n"
1977 "\t--backup: export only what's necessary for reconfig\n"
1978 "\t--help: display this help\n");
1983 if (backup && argc >= 3)
1985 else if (!backup && argc >= 2)
1991 f = fopen(file, "w");
1996 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1997 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1998 cYAML_print_tree2file(stderr, err_rc);
1999 cYAML_free_tree(err_rc);
2003 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
2005 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2006 cYAML_print_tree2file(stderr, err_rc);
2007 cYAML_free_tree(err_rc);
2011 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
2012 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2013 cYAML_print_tree2file(stderr, err_rc);
2014 cYAML_free_tree(err_rc);
2018 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
2019 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2020 cYAML_print_tree2file(stderr, err_rc);
2021 cYAML_free_tree(err_rc);
2025 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2026 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2027 cYAML_print_tree2file(stderr, err_rc);
2028 cYAML_free_tree(err_rc);
2032 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
2033 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2034 cYAML_print_tree2file(stderr, err_rc);
2035 cYAML_free_tree(err_rc);
2039 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
2040 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2041 cYAML_print_tree2file(stderr, err_rc);
2042 cYAML_free_tree(err_rc);
2046 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2047 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2048 cYAML_print_tree2file(stderr, err_rc);
2049 cYAML_free_tree(err_rc);
2053 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2054 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2055 cYAML_print_tree2file(stderr, err_rc);
2059 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2060 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2061 cYAML_print_tree2file(stderr, err_rc);
2065 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
2066 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2067 cYAML_print_tree2file(stderr, err_rc);
2071 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
2072 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2073 cYAML_print_tree2file(stderr, err_rc);
2077 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
2078 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2079 cYAML_print_tree2file(stderr, err_rc);
2083 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
2084 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2085 cYAML_print_tree2file(stderr, err_rc);
2089 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
2090 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2091 cYAML_print_tree2file(stderr, err_rc);
2092 cYAML_free_tree(err_rc);
2096 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2097 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2098 cYAML_print_tree2file(stderr, err_rc);
2099 cYAML_free_tree(err_rc);
2103 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2104 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2105 cYAML_print_tree2file(stderr, err_rc);
2106 cYAML_free_tree(err_rc);
2110 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
2111 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2112 cYAML_print_tree2file(stderr, err_rc);
2113 cYAML_free_tree(err_rc);
2117 if (show_rc != NULL) {
2118 cYAML_print_tree2file(f, show_rc);
2119 cYAML_free_tree(show_rc);
2128 static int jt_peer_nid_common(int argc, char **argv, int cmd)
2130 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
2132 char *prim_nid = NULL, *nidstr = NULL;
2133 char err_str[LNET_MAX_STR_LEN] = "Error";
2134 struct cYAML *err_rc = NULL;
2136 const char *const short_opts = "k:mn:";
2137 const struct option long_opts[] = {
2138 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2139 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2140 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2143 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2147 while ((opt = getopt_long(argc, argv, short_opts,
2148 long_opts, NULL)) != -1) {
2157 if (cmd == LNETCTL_DEL_CMD) {
2158 rc = LUSTRE_CFG_RC_BAD_PARAM;
2159 snprintf(err_str, LNET_MAX_STR_LEN,
2160 "Unrecognized option '-%c'", opt);
2166 print_help(peer_cmds, "peer",
2167 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2173 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2175 if (rc != LUSTRE_CFG_RC_NO_ERR)
2179 cYAML_build_error(rc, -1, "peer",
2180 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2184 if (rc != LUSTRE_CFG_RC_NO_ERR)
2185 cYAML_print_tree2file(stderr, err_rc);
2187 cYAML_free_tree(err_rc);
2192 static int jt_add_peer_nid(int argc, char **argv)
2194 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2197 static int jt_del_peer_nid(int argc, char **argv)
2199 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2202 static int jt_show_peer(int argc, char **argv)
2206 struct cYAML *err_rc = NULL, *show_rc = NULL;
2207 long int detail = 0;
2209 const char *const short_opts = "hn:v::";
2210 const struct option long_opts[] = {
2211 { .name = "help", .has_arg = no_argument, .val = 'h' },
2212 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2213 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2216 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2220 while ((opt = getopt_long(argc, argv, short_opts,
2221 long_opts, NULL)) != -1) {
2227 if ((!optarg) && (argv[optind] != NULL) &&
2228 (argv[optind][0] != '-')) {
2229 if (parse_long(argv[optind++], &detail) != 0)
2236 print_help(peer_cmds, "peer", "show");
2242 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2245 if (rc != LUSTRE_CFG_RC_NO_ERR)
2246 cYAML_print_tree2file(stderr, err_rc);
2248 cYAML_print_tree(show_rc);
2250 cYAML_free_tree(err_rc);
2251 cYAML_free_tree(show_rc);
2256 static int jt_list_peer(int argc, char **argv)
2259 struct cYAML *err_rc = NULL, *list_rc = NULL;
2261 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2265 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2267 if (rc != LUSTRE_CFG_RC_NO_ERR)
2268 cYAML_print_tree2file(stderr, err_rc);
2270 cYAML_print_tree(list_rc);
2272 cYAML_free_tree(err_rc);
2273 cYAML_free_tree(list_rc);
2278 static int jt_ping(int argc, char **argv)
2280 struct cYAML *err_rc = NULL;
2281 struct cYAML *show_rc = NULL;
2284 char *src_nidstr = NULL;
2286 const char *const short_options = "hs:t:";
2287 const struct option long_options[] = {
2288 { .name = "help", .has_arg = no_argument, .val = 'h' },
2289 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2290 { .name = "source", .has_arg = required_argument, .val = 's' },
2293 while ((opt = getopt_long(argc, argv, short_options,
2294 long_options, NULL)) != -1) {
2297 src_nidstr = optarg;
2300 timeout = 1000 * atol(optarg);
2303 printf("ping nid[,nid,...]\n"
2304 "\t --source: source nid\n"
2305 "\t --timeout: ping timeout\n"
2306 "\t --help: display this help\n");
2313 for (; optind < argc; optind++)
2314 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
2318 cYAML_print_tree(show_rc);
2321 cYAML_print_tree2file(stderr, err_rc);
2323 cYAML_free_tree(err_rc);
2324 cYAML_free_tree(show_rc);
2329 static int jt_discover(int argc, char **argv)
2331 struct cYAML *err_rc = NULL;
2332 struct cYAML *show_rc = NULL;
2336 const char *const short_options = "fh";
2337 const struct option long_options[] = {
2338 { .name = "force", .has_arg = no_argument, .val = 'f' },
2339 { .name = "help", .has_arg = no_argument, .val = 'h' },
2342 while ((opt = getopt_long(argc, argv, short_options,
2343 long_options, NULL)) != -1) {
2349 printf("discover nid[,nid,...]\n"
2350 "\t --force: force discovery\n"
2351 "\t --help: display this help\n");
2358 for (; optind < argc; optind++)
2359 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2363 cYAML_print_tree(show_rc);
2366 cYAML_print_tree2file(stderr, err_rc);
2368 cYAML_free_tree(err_rc);
2369 cYAML_free_tree(show_rc);
2374 static int jt_add_udsp(int argc, char **argv)
2376 char *src = NULL, *dst = NULL, *rte = NULL;
2377 struct cYAML *err_rc = NULL;
2378 union lnet_udsp_action udsp_action;
2379 long int idx = -1, priority = -1;
2381 char *action_type = "pref";
2383 const char *const short_options = "s:d:r:p:i:";
2384 static const struct option long_options[] = {
2385 { .name = "src", .has_arg = required_argument, .val = 's' },
2386 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2387 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2388 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2389 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2392 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2396 while ((opt = getopt_long(argc, argv, short_options,
2397 long_options, NULL)) != -1) {
2409 rc = parse_long(optarg, &priority);
2412 action_type = "priority";
2413 udsp_action.udsp_priority = priority;
2416 rc = parse_long(optarg, &idx);
2421 print_help(udsp_cmds, "udsp", "add");
2427 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2430 if (rc != LUSTRE_CFG_RC_NO_ERR)
2431 cYAML_print_tree2file(stderr, err_rc);
2433 cYAML_free_tree(err_rc);
2438 static int jt_del_udsp(int argc, char **argv)
2440 struct cYAML *err_rc = NULL;
2444 const char *const short_options = "i:";
2445 static const struct option long_options[] = {
2446 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2449 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2453 while ((opt = getopt_long(argc, argv, short_options,
2454 long_options, NULL)) != -1) {
2457 rc = parse_long(optarg, &idx);
2462 print_help(udsp_cmds, "udsp", "add");
2468 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2469 if (rc != LUSTRE_CFG_RC_NO_ERR)
2470 cYAML_print_tree2file(stderr, err_rc);
2472 cYAML_free_tree(err_rc);
2477 static int lnetctl_list_commands(int argc, char **argv)
2479 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2481 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2486 int main(int argc, char **argv)
2489 struct cYAML *err_rc = NULL;
2491 rc = lustre_lnet_config_lib_init();
2493 cYAML_build_error(-1, -1, "lnetctl", "startup",
2494 "cannot register LNet device", &err_rc);
2495 cYAML_print_tree2file(stderr, err_rc);
2499 Parser_init("lnetctl > ", cmd_list);
2501 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);