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 rc = lustre_lnet_config_ni(&nw_descr,
1175 (cpt_rc == 0) ? global_cpts: NULL,
1176 ip2net, (found) ? &tunables : NULL,
1179 if (global_cpts != NULL)
1180 cfs_expr_list_free(global_cpts);
1183 if (rc != LUSTRE_CFG_RC_NO_ERR)
1184 cYAML_print_tree2file(stderr, err_rc);
1186 cYAML_free_tree(err_rc);
1188 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
1190 rc = lustre_lnet_setup_mrrouting(&err_rc);
1192 if (rc != LUSTRE_CFG_RC_NO_ERR)
1193 cYAML_print_tree2file(stderr, err_rc);
1195 cYAML_free_tree(err_rc);
1201 static int jt_del_route(int argc, char **argv)
1203 char *network = NULL, *gateway = NULL;
1204 struct cYAML *err_rc = NULL;
1207 const char *const short_options = "n:g:";
1208 static const struct option long_options[] = {
1209 { .name = "net", .has_arg = required_argument, .val = 'n' },
1210 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1213 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1217 while ((opt = getopt_long(argc, argv, short_options,
1218 long_options, NULL)) != -1) {
1227 print_help(route_cmds, "route", "del");
1233 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1235 if (rc != LUSTRE_CFG_RC_NO_ERR)
1236 cYAML_print_tree2file(stderr, err_rc);
1238 cYAML_free_tree(err_rc);
1243 static int jt_del_ni(int argc, char **argv)
1245 struct cYAML *err_rc = NULL;
1247 struct lnet_dlc_network_descr nw_descr;
1249 lustre_lnet_init_nw_descr(&nw_descr);
1251 const char *const short_options = "n:i:";
1252 static const struct option long_options[] = {
1253 { .name = "net", .has_arg = required_argument, .val = 'n' },
1254 { .name = "if", .has_arg = required_argument, .val = 'i' },
1257 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1261 while ((opt = getopt_long(argc, argv, short_options,
1262 long_options, NULL)) != -1) {
1265 nw_descr.nw_id = libcfs_str2net(optarg);
1268 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1270 cYAML_build_error(-1, -1, "ni", "add",
1271 "bad interface list",
1277 print_help(net_cmds, "net", "del");
1283 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1286 if (rc != LUSTRE_CFG_RC_NO_ERR)
1287 cYAML_print_tree2file(stderr, err_rc);
1289 cYAML_free_tree(err_rc);
1294 static int jt_show_route(int argc, char **argv)
1296 char *network = NULL, *gateway = NULL;
1297 long int hop = -1, prio = -1;
1298 int detail = 0, rc, opt;
1299 struct cYAML *err_rc = NULL, *show_rc = NULL;
1301 const char *const short_options = "n:g:h:p:v";
1302 static const struct option long_options[] = {
1303 { .name = "net", .has_arg = required_argument, .val = 'n' },
1304 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1305 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1306 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1307 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1310 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1314 while ((opt = getopt_long(argc, argv, short_options,
1315 long_options, NULL)) != -1) {
1324 rc = parse_long(optarg, &hop);
1332 rc = parse_long(optarg, &prio);
1343 print_help(route_cmds, "route", "show");
1349 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1350 &show_rc, &err_rc, false);
1352 if (rc != LUSTRE_CFG_RC_NO_ERR)
1353 cYAML_print_tree2file(stderr, err_rc);
1355 cYAML_print_tree(show_rc);
1357 cYAML_free_tree(err_rc);
1358 cYAML_free_tree(show_rc);
1363 static int set_value_helper(int argc, char **argv,
1364 int (*cb)(int, bool, char*, int, struct cYAML**))
1367 long int healthv = -1;
1370 struct cYAML *err_rc = NULL;
1372 const char *const short_options = "t:n:a";
1373 static const struct option long_options[] = {
1374 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1375 { .name = "health", .has_arg = required_argument, .val = 't' },
1376 { .name = "all", .has_arg = no_argument, .val = 'a' },
1379 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1383 while ((opt = getopt_long(argc, argv, short_options,
1384 long_options, NULL)) != -1) {
1390 if (parse_long(optarg, &healthv) != 0)
1401 rc = cb(healthv, all, nid, -1, &err_rc);
1403 if (rc != LUSTRE_CFG_RC_NO_ERR)
1404 cYAML_print_tree2file(stderr, err_rc);
1406 cYAML_free_tree(err_rc);
1411 static int jt_set_ni_value(int argc, char **argv)
1414 long int healthv = -1, cpp = -1;
1417 struct cYAML *err_rc = NULL;
1419 const char *const short_options = "a:m:n:t:";
1420 static const struct option long_options[] = {
1421 { .name = "all", .has_arg = no_argument, .val = 'a' },
1422 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
1423 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1424 { .name = "health", .has_arg = required_argument, .val = 't' },
1427 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1431 while ((opt = getopt_long(argc, argv, short_options,
1432 long_options, NULL)) != -1) {
1438 rc = parse_long(optarg, &cpp);
1449 if (parse_long(optarg, &healthv) != 0) {
1461 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
1464 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
1467 if (rc != LUSTRE_CFG_RC_NO_ERR)
1468 cYAML_print_tree2file(stderr, err_rc);
1470 cYAML_free_tree(err_rc);
1475 static int jt_set_peer_ni_value(int argc, char **argv)
1477 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1480 static int jt_show_recovery(int argc, char **argv)
1483 struct cYAML *err_rc = NULL, *show_rc = NULL;
1485 const char *const short_options = "lp";
1486 static const struct option long_options[] = {
1487 { .name = "local", .has_arg = no_argument, .val = 'l' },
1488 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1491 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1495 while ((opt = getopt_long(argc, argv, short_options,
1496 long_options, NULL)) != -1) {
1499 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1502 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1509 if (rc != LUSTRE_CFG_RC_NO_ERR)
1510 cYAML_print_tree2file(stderr, err_rc);
1512 cYAML_print_tree(show_rc);
1514 cYAML_free_tree(err_rc);
1515 cYAML_free_tree(show_rc);
1520 static int jt_show_net(int argc, char **argv)
1522 char *network = NULL;
1524 struct cYAML *err_rc = NULL, *show_rc = NULL;
1525 long int detail = 0;
1527 const char *const short_options = "n:v";
1528 static const struct option long_options[] = {
1529 { .name = "net", .has_arg = required_argument, .val = 'n' },
1530 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1533 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1537 while ((opt = getopt_long(argc, argv, short_options,
1538 long_options, NULL)) != -1) {
1544 if ((!optarg) && (argv[optind] != NULL) &&
1545 (argv[optind][0] != '-')) {
1546 if (parse_long(argv[optind++], &detail) != 0)
1553 print_help(net_cmds, "net", "show");
1559 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1562 if (rc != LUSTRE_CFG_RC_NO_ERR)
1563 cYAML_print_tree2file(stderr, err_rc);
1565 cYAML_print_tree(show_rc);
1567 cYAML_free_tree(err_rc);
1568 cYAML_free_tree(show_rc);
1573 static int jt_show_routing(int argc, char **argv)
1575 struct cYAML *err_rc = NULL, *show_rc = NULL;
1578 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1582 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1584 if (rc != LUSTRE_CFG_RC_NO_ERR)
1585 cYAML_print_tree2file(stderr, err_rc);
1587 cYAML_print_tree(show_rc);
1589 cYAML_free_tree(err_rc);
1590 cYAML_free_tree(show_rc);
1595 static int jt_show_stats(int argc, char **argv)
1598 struct cYAML *show_rc = NULL, *err_rc = NULL;
1600 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1604 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1606 if (rc != LUSTRE_CFG_RC_NO_ERR)
1607 cYAML_print_tree2file(stderr, err_rc);
1609 cYAML_print_tree(show_rc);
1611 cYAML_free_tree(err_rc);
1612 cYAML_free_tree(show_rc);
1617 static int jt_show_udsp(int argc, char **argv)
1621 struct cYAML *err_rc = NULL, *show_rc = NULL;
1623 const char *const short_options = "i:";
1624 static const struct option long_options[] = {
1625 { .name = "idx", .has_arg = required_argument, .val = 'i' },
1629 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
1633 while ((opt = getopt_long(argc, argv, short_options,
1634 long_options, NULL)) != -1) {
1640 print_help(net_cmds, "net", "show");
1646 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
1648 if (rc != LUSTRE_CFG_RC_NO_ERR)
1649 cYAML_print_tree2file(stderr, err_rc);
1651 cYAML_print_tree(show_rc);
1653 cYAML_free_tree(err_rc);
1654 cYAML_free_tree(show_rc);
1659 static int jt_show_global(int argc, char **argv)
1662 struct cYAML *show_rc = NULL, *err_rc = NULL;
1664 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1668 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1669 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1670 cYAML_print_tree2file(stderr, err_rc);
1674 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1675 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1676 cYAML_print_tree2file(stderr, err_rc);
1680 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1681 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1682 cYAML_print_tree2file(stderr, err_rc);
1686 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1687 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1688 cYAML_print_tree2file(stderr, err_rc);
1692 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1693 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1694 cYAML_print_tree2file(stderr, err_rc);
1698 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1699 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1700 cYAML_print_tree2file(stderr, err_rc);
1704 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1705 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1706 cYAML_print_tree2file(stderr, err_rc);
1710 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1711 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1712 cYAML_print_tree2file(stderr, err_rc);
1716 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1717 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1718 cYAML_print_tree2file(stderr, err_rc);
1722 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1723 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1724 cYAML_print_tree2file(stderr, err_rc);
1728 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1729 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1730 cYAML_print_tree2file(stderr, err_rc);
1734 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1735 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1736 cYAML_print_tree2file(stderr, err_rc);
1740 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
1741 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1742 cYAML_print_tree2file(stderr, err_rc);
1747 cYAML_print_tree(show_rc);
1750 cYAML_free_tree(err_rc);
1751 cYAML_free_tree(show_rc);
1756 static int jt_lnet(int argc, char **argv)
1760 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1764 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1767 static int jt_route(int argc, char **argv)
1771 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1775 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1778 static int jt_net(int argc, char **argv)
1782 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1786 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1789 static int jt_routing(int argc, char **argv)
1793 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1797 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1800 static int jt_stats(int argc, char **argv)
1804 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1808 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1811 static int jt_debug(int argc, char **argv)
1815 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1819 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1822 static int jt_global(int argc, char **argv)
1826 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1830 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1833 static int jt_peers(int argc, char **argv)
1837 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1841 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1844 static int jt_set(int argc, char **argv)
1848 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1852 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1855 static int jt_udsp(int argc, char **argv)
1859 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1863 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1866 static int jt_import(int argc, char **argv)
1869 struct cYAML *err_rc = NULL;
1870 struct cYAML *show_rc = NULL;
1871 int rc = 0, return_rc = 0, opt, opt_found = 0;
1874 const char *const short_options = "adseh";
1875 static const struct option long_options[] = {
1876 { .name = "add", .has_arg = no_argument, .val = 'a' },
1877 { .name = "del", .has_arg = no_argument, .val = 'd' },
1878 { .name = "show", .has_arg = no_argument, .val = 's' },
1879 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1880 { .name = "help", .has_arg = no_argument, .val = 'h' },
1883 while ((opt = getopt_long(argc, argv, short_options,
1884 long_options, NULL)) != -1) {
1898 printf("import FILE\n"
1899 "import < FILE : import a file\n"
1900 "\t--add: add configuration\n"
1901 "\t--del: delete configuration\n"
1902 "\t--show: show configuration\n"
1903 "\t--exec: execute command\n"
1904 "\t--help: display this help\n"
1905 "If no command option is given then --add"
1906 " is assumed by default\n");
1913 /* grab the file name if one exists */
1914 if (opt_found && argc == 3)
1916 else if (!opt_found && argc == 2)
1921 rc = lustre_yaml_config(file, &err_rc);
1922 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1923 cYAML_print_tree(show_rc);
1924 cYAML_free_tree(show_rc);
1927 rc = lustre_yaml_del(file, &err_rc);
1930 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1931 cYAML_print_tree(show_rc);
1932 cYAML_free_tree(show_rc);
1935 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1936 cYAML_print_tree(show_rc);
1937 cYAML_free_tree(show_rc);
1941 if (rc || return_rc) {
1942 cYAML_print_tree2file(stderr, err_rc);
1943 cYAML_free_tree(err_rc);
1949 static int jt_export(int argc, char **argv)
1951 struct cYAML *show_rc = NULL;
1952 struct cYAML *err_rc = NULL;
1956 bool backup = false;
1959 const char *const short_options = "bh";
1960 static const struct option long_options[] = {
1961 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1962 { .name = "help", .has_arg = no_argument, .val = 'h' },
1965 while ((opt = getopt_long(argc, argv, short_options,
1966 long_options, NULL)) != -1) {
1973 printf("export > FILE.yaml : export configuration\n"
1974 "\t--backup: export only what's necessary for reconfig\n"
1975 "\t--help: display this help\n");
1980 if (backup && argc >= 3)
1982 else if (!backup && argc >= 2)
1988 f = fopen(file, "w");
1993 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1994 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1995 cYAML_print_tree2file(stderr, err_rc);
1996 cYAML_free_tree(err_rc);
2000 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
2002 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2003 cYAML_print_tree2file(stderr, err_rc);
2004 cYAML_free_tree(err_rc);
2008 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
2009 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2010 cYAML_print_tree2file(stderr, err_rc);
2011 cYAML_free_tree(err_rc);
2015 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
2016 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2017 cYAML_print_tree2file(stderr, err_rc);
2018 cYAML_free_tree(err_rc);
2022 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2023 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2024 cYAML_print_tree2file(stderr, err_rc);
2025 cYAML_free_tree(err_rc);
2029 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
2030 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2031 cYAML_print_tree2file(stderr, err_rc);
2032 cYAML_free_tree(err_rc);
2036 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
2037 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2038 cYAML_print_tree2file(stderr, err_rc);
2039 cYAML_free_tree(err_rc);
2043 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2044 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2045 cYAML_print_tree2file(stderr, err_rc);
2046 cYAML_free_tree(err_rc);
2050 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2051 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2052 cYAML_print_tree2file(stderr, err_rc);
2056 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2057 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2058 cYAML_print_tree2file(stderr, err_rc);
2062 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
2063 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2064 cYAML_print_tree2file(stderr, err_rc);
2068 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
2069 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2070 cYAML_print_tree2file(stderr, err_rc);
2074 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
2075 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2076 cYAML_print_tree2file(stderr, err_rc);
2080 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
2081 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2082 cYAML_print_tree2file(stderr, err_rc);
2086 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
2087 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2088 cYAML_print_tree2file(stderr, err_rc);
2089 cYAML_free_tree(err_rc);
2093 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2094 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2095 cYAML_print_tree2file(stderr, err_rc);
2096 cYAML_free_tree(err_rc);
2100 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2101 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2102 cYAML_print_tree2file(stderr, err_rc);
2103 cYAML_free_tree(err_rc);
2107 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
2108 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2109 cYAML_print_tree2file(stderr, err_rc);
2110 cYAML_free_tree(err_rc);
2114 if (show_rc != NULL) {
2115 cYAML_print_tree2file(f, show_rc);
2116 cYAML_free_tree(show_rc);
2125 static int jt_peer_nid_common(int argc, char **argv, int cmd)
2127 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
2129 char *prim_nid = NULL, *nidstr = NULL;
2130 char err_str[LNET_MAX_STR_LEN] = "Error";
2131 struct cYAML *err_rc = NULL;
2133 const char *const short_opts = "k:mn:";
2134 const struct option long_opts[] = {
2135 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2136 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2137 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2140 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2144 while ((opt = getopt_long(argc, argv, short_opts,
2145 long_opts, NULL)) != -1) {
2154 if (cmd == LNETCTL_DEL_CMD) {
2155 rc = LUSTRE_CFG_RC_BAD_PARAM;
2156 snprintf(err_str, LNET_MAX_STR_LEN,
2157 "Unrecognized option '-%c'", opt);
2163 print_help(peer_cmds, "peer",
2164 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2170 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2172 if (rc != LUSTRE_CFG_RC_NO_ERR)
2176 cYAML_build_error(rc, -1, "peer",
2177 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2181 if (rc != LUSTRE_CFG_RC_NO_ERR)
2182 cYAML_print_tree2file(stderr, err_rc);
2184 cYAML_free_tree(err_rc);
2189 static int jt_add_peer_nid(int argc, char **argv)
2191 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2194 static int jt_del_peer_nid(int argc, char **argv)
2196 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2199 static int jt_show_peer(int argc, char **argv)
2203 struct cYAML *err_rc = NULL, *show_rc = NULL;
2204 long int detail = 0;
2206 const char *const short_opts = "hn:v::";
2207 const struct option long_opts[] = {
2208 { .name = "help", .has_arg = no_argument, .val = 'h' },
2209 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2210 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2213 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2217 while ((opt = getopt_long(argc, argv, short_opts,
2218 long_opts, NULL)) != -1) {
2224 if ((!optarg) && (argv[optind] != NULL) &&
2225 (argv[optind][0] != '-')) {
2226 if (parse_long(argv[optind++], &detail) != 0)
2233 print_help(peer_cmds, "peer", "show");
2239 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2242 if (rc != LUSTRE_CFG_RC_NO_ERR)
2243 cYAML_print_tree2file(stderr, err_rc);
2245 cYAML_print_tree(show_rc);
2247 cYAML_free_tree(err_rc);
2248 cYAML_free_tree(show_rc);
2253 static int jt_list_peer(int argc, char **argv)
2256 struct cYAML *err_rc = NULL, *list_rc = NULL;
2258 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2262 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2264 if (rc != LUSTRE_CFG_RC_NO_ERR)
2265 cYAML_print_tree2file(stderr, err_rc);
2267 cYAML_print_tree(list_rc);
2269 cYAML_free_tree(err_rc);
2270 cYAML_free_tree(list_rc);
2275 static int jt_ping(int argc, char **argv)
2277 struct cYAML *err_rc = NULL;
2278 struct cYAML *show_rc = NULL;
2281 char *src_nidstr = NULL;
2283 const char *const short_options = "hs:t:";
2284 const struct option long_options[] = {
2285 { .name = "help", .has_arg = no_argument, .val = 'h' },
2286 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2287 { .name = "source", .has_arg = required_argument, .val = 's' },
2290 while ((opt = getopt_long(argc, argv, short_options,
2291 long_options, NULL)) != -1) {
2294 src_nidstr = optarg;
2297 timeout = 1000 * atol(optarg);
2300 printf("ping nid[,nid,...]\n"
2301 "\t --source: source nid\n"
2302 "\t --timeout: ping timeout\n"
2303 "\t --help: display this help\n");
2310 for (; optind < argc; optind++)
2311 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
2315 cYAML_print_tree(show_rc);
2318 cYAML_print_tree2file(stderr, err_rc);
2320 cYAML_free_tree(err_rc);
2321 cYAML_free_tree(show_rc);
2326 static int jt_discover(int argc, char **argv)
2328 struct cYAML *err_rc = NULL;
2329 struct cYAML *show_rc = NULL;
2333 const char *const short_options = "fh";
2334 const struct option long_options[] = {
2335 { .name = "force", .has_arg = no_argument, .val = 'f' },
2336 { .name = "help", .has_arg = no_argument, .val = 'h' },
2339 while ((opt = getopt_long(argc, argv, short_options,
2340 long_options, NULL)) != -1) {
2346 printf("discover nid[,nid,...]\n"
2347 "\t --force: force discovery\n"
2348 "\t --help: display this help\n");
2355 for (; optind < argc; optind++)
2356 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2360 cYAML_print_tree(show_rc);
2363 cYAML_print_tree2file(stderr, err_rc);
2365 cYAML_free_tree(err_rc);
2366 cYAML_free_tree(show_rc);
2371 static int jt_add_udsp(int argc, char **argv)
2373 char *src = NULL, *dst = NULL, *rte = NULL;
2374 struct cYAML *err_rc = NULL;
2375 union lnet_udsp_action udsp_action;
2376 long int idx = -1, priority = -1;
2378 char *action_type = "pref";
2380 const char *const short_options = "s:d:r:p:i:";
2381 static const struct option long_options[] = {
2382 { .name = "src", .has_arg = required_argument, .val = 's' },
2383 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2384 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2385 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2386 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2389 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2393 while ((opt = getopt_long(argc, argv, short_options,
2394 long_options, NULL)) != -1) {
2406 rc = parse_long(optarg, &priority);
2409 action_type = "priority";
2410 udsp_action.udsp_priority = priority;
2413 rc = parse_long(optarg, &idx);
2418 print_help(udsp_cmds, "udsp", "add");
2424 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2427 if (rc != LUSTRE_CFG_RC_NO_ERR)
2428 cYAML_print_tree2file(stderr, err_rc);
2430 cYAML_free_tree(err_rc);
2435 static int jt_del_udsp(int argc, char **argv)
2437 struct cYAML *err_rc = NULL;
2441 const char *const short_options = "i:";
2442 static const struct option long_options[] = {
2443 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2446 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2450 while ((opt = getopt_long(argc, argv, short_options,
2451 long_options, NULL)) != -1) {
2454 rc = parse_long(optarg, &idx);
2459 print_help(udsp_cmds, "udsp", "add");
2465 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2466 if (rc != LUSTRE_CFG_RC_NO_ERR)
2467 cYAML_print_tree2file(stderr, err_rc);
2469 cYAML_free_tree(err_rc);
2474 static int lnetctl_list_commands(int argc, char **argv)
2476 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2478 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2483 int main(int argc, char **argv)
2486 struct cYAML *err_rc = NULL;
2488 rc = lustre_lnet_config_lib_init();
2490 cYAML_build_error(-1, -1, "lnetctl", "startup",
2491 "cannot register LNet device", &err_rc);
2492 cYAML_print_tree2file(stderr, err_rc);
2496 Parser_init("lnetctl > ", cmd_list);
2498 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);