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_add_peer_nid(int argc, char **argv);
64 static int jt_del_peer_nid(int argc, char **argv);
65 static int jt_set_max_intf(int argc, char **argv);
66 static int jt_set_discovery(int argc, char **argv);
67 static int jt_set_drop_asym_route(int argc, char **argv);
68 static int jt_list_peer(int argc, char **argv);
69 static int jt_add_udsp(int argc, char **argv);
70 static int jt_del_udsp(int argc, char **argv);
71 /*static int jt_show_peer(int argc, char **argv);*/
72 static int lnetctl_list_commands(int argc, char **argv);
73 static int jt_import(int argc, char **argv);
74 static int jt_export(int argc, char **argv);
75 static int jt_ping(int argc, char **argv);
76 static int jt_discover(int argc, char **argv);
77 static int jt_lnet(int argc, char **argv);
78 static int jt_route(int argc, char **argv);
79 static int jt_net(int argc, char **argv);
80 static int jt_routing(int argc, char **argv);
81 static int jt_set(int argc, char **argv);
82 static int jt_debug(int argc, char **argv);
83 static int jt_stats(int argc, char **argv);
84 static int jt_global(int argc, char **argv);
85 static int jt_peers(int argc, char **argv);
86 static int jt_set_ni_value(int argc, char **argv);
87 static int jt_set_peer_ni_value(int argc, char **argv);
88 static int jt_calc_service_id(int argc, char **argv);
89 static int jt_set_response_tracking(int argc, char **argv);
90 static int jt_set_recovery_limit(int argc, char **argv);
91 static int jt_udsp(int argc, char **argv);
93 command_t cmd_list[] = {
94 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
95 {"route", jt_route, 0, "route {add | del | show | help}"},
96 {"net", jt_net, 0, "net {add | del | show | help}"},
97 {"routing", jt_routing, 0, "routing {show | help}"},
98 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
99 " | routing | numa_range | max_interfaces"
100 " | discovery | drop_asym_route | retry_count"
101 " | transaction_timeout | health_sensitivity"
102 " | recovery_interval | router_sensitivity"
103 " | response_tracking | recovery_limit}"},
104 {"import", jt_import, 0, "import FILE.yaml"},
105 {"export", jt_export, 0, "export FILE.yaml"},
106 {"stats", jt_stats, 0, "stats {show | help}"},
107 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
108 {"global", jt_global, 0, "global {show | help}"},
109 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
110 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
111 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
112 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
113 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
114 {"help", Parser_help, 0, "help"},
115 {"exit", Parser_quit, 0, "quit"},
116 {"quit", Parser_quit, 0, "quit"},
117 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
121 command_t lnet_cmds[] = {
122 {"configure", jt_config_lnet, 0, "configure lnet\n"
123 "\t--all: load NI configuration from module parameters\n"},
124 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
128 command_t route_cmds[] = {
129 {"add", jt_add_route, 0, "add a route\n"
130 "\t--net: net name (e.g. tcp0)\n"
131 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
132 "\t--hop: number to final destination (1 < hops < 255)\n"
133 "\t--priority: priority of route (0 - highest prio\n"
134 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
135 {"del", jt_del_route, 0, "delete a route\n"
136 "\t--net: net name (e.g. tcp0)\n"
137 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
138 {"show", jt_show_route, 0, "show routes\n"
139 "\t--net: net name (e.g. tcp0) to filter on\n"
140 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
141 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
142 "\t--priority: priority of route (0 - highest prio to filter on\n"
143 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
144 "\t--verbose: display detailed output per route\n"},
148 command_t net_cmds[] = {
149 {"add", jt_add_ni, 0, "add a network\n"
150 "\t--net: net name (e.g. tcp0)\n"
151 "\t--if: physical interface (e.g. eth0)\n"
152 "\t--ip2net: specify networks based on IP address patterns\n"
153 "\t--peer-timeout: time to wait before declaring a peer dead\n"
154 "\t--peer-credits: define the max number of inflight messages\n"
155 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
156 "\t--credits: Network Interface credits\n"
157 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
158 {"del", jt_del_ni, 0, "delete a network\n"
159 "\t--net: net name (e.g. tcp0)\n"
160 "\t--if: physical interface (e.g. eth0)\n"},
161 {"show", jt_show_net, 0, "show networks\n"
162 "\t--net: net name (e.g. tcp0) to filter on\n"
163 "\t--verbose: display detailed output per network."
164 " Optional argument of '2' outputs more stats\n"},
165 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
166 "\t--nid: NI NID to set the\n"
167 "\t--health: specify health value to set\n"
168 "\t--all: set all NIs value to the one specified\n"},
172 command_t routing_cmds[] = {
173 {"show", jt_show_routing, 0, "show routing information\n"},
177 command_t stats_cmds[] = {
178 {"show", jt_show_stats, 0, "show LNET statistics\n"},
182 command_t debug_cmds[] = {
183 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
184 "\t--local : list local recovery queue\n"
185 "\t--peer : list peer recovery queue\n"},
189 command_t global_cmds[] = {
190 {"show", jt_show_global, 0, "show global variables\n"},
194 command_t set_cmds[] = {
195 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
196 "\tVALUE must be greater than 0\n"},
197 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
198 "\tVALUE must be greater than 0\n"},
199 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
200 "\tVALUE must be greater than 0\n"},
201 {"routing", jt_set_routing, 0, "enable/disable routing\n"
202 "\t0 - disable routing\n"
203 "\t1 - enable routing\n"},
204 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
205 "\tVALUE must be at least 0\n"},
206 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
208 "\tValue must be greater than 16\n"},
209 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
210 "\t0 - disable peer discovery\n"
211 "\t1 - enable peer discovery (default)\n"},
212 {"drop_asym_route", jt_set_drop_asym_route, 0,
213 "drop/accept asymmetrical route messages\n"
214 "\t0 - accept asymmetrical route messages (default)\n"
215 "\t1 - drop asymmetrical route messages\n"},
216 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
217 "\t0 - turn of retries\n"
218 "\t>0 - number of retries\n"},
219 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
220 "\t>0 - timeout in seconds\n"},
221 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
222 "\t0 - turn off health evaluation\n"
223 "\t>0 - sensitivity value not more than 1000\n"},
224 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
225 "\t>0 - time in seconds between pings\n"},
226 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
227 "\t100 - router interfaces need to be fully healthy to be used\n"
228 "\t<100 - router interfaces can be used even if not healthy\n"},
229 {"response_tracking", jt_set_response_tracking, 0,
230 "Set the behavior of response tracking\n"
231 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
232 "\t1 - GETs are eligible for response tracking\n"
233 "\t2 - PUTs are eligible for response tracking\n"
234 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
235 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
236 "\t pings and discovery pushes always utilize response tracking\n"},
237 {"recovery_limit", jt_set_recovery_limit, 0,
238 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
239 "\t0 - Recover indefinitely (default)\n"
240 "\t>0 - Recover for the specified number of seconds.\n"},
244 command_t peer_cmds[] = {
245 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
246 "\t--prim_nid: Primary NID of the peer.\n"
247 "\t--nid: one or more peer NIDs\n"
248 "\t--non_mr: create this peer as not Multi-Rail capable\n"
249 "\t--ip2nets: specify a range of nids per peer"},
250 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
251 "\t--prim_nid: Primary NID of the peer.\n"
252 "\t--nid: list of NIDs to remove. If none provided,\n"
253 "\t peer is deleted\n"
254 "\t--ip2nets: specify a range of nids per peer"},
255 {"show", jt_show_peer, 0, "show peer information\n"
256 "\t--nid: NID of peer to filter on.\n"
257 "\t--verbose: display detailed output per peer."
258 " Optional argument of '2' outputs more stats\n"},
259 {"list", jt_list_peer, 0, "list all peers\n"},
260 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
261 "\t--nid: Peer NI NID to set the\n"
262 "\t--health: specify health value to set\n"
263 "\t--all: set all peer_nis values to the one specified\n"},
267 command_t udsp_cmds[] = {
268 {"add", jt_add_udsp, 0, "add a udsp\n"
269 "\t--src: ip2nets syntax specifying the local NID to match\n"
270 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
271 "\t--rte: ip2nets syntax specifying the router NID to match\n"
272 "\t--priority: priority value (0 - highest priority)\n"
273 "\t--idx: index of where to insert the rule.\n"
274 "\t By default, appends to the end of the rule list.\n"},
275 {"del", jt_del_udsp, 0, "delete a udsp\n"
276 "\t--idx: index of the Policy.\n"},
277 {"show", jt_show_udsp, 0, "show udsps\n"
278 "\t --idx: index of the policy to show.\n"},
282 static int jt_calc_service_id(int argc, char **argv)
287 rc = lustre_lnet_calc_service_id(&service_id);
288 if (rc != LUSTRE_CFG_RC_NO_ERR)
292 * cYAML currently doesn't support printing hex values.
293 * Therefore just print it locally here
295 printf("service id:\n value: 0x%jx\n", (uintmax_t)service_id);
300 static inline void print_help(const command_t cmds[], const char *cmd_type,
303 const command_t *cmd;
305 for (cmd = cmds; cmd->pc_name; cmd++) {
306 if (pc_name != NULL &&
307 strcmp(cmd->pc_name, pc_name) == 0) {
308 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
311 } else if (pc_name != NULL) {
314 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
318 static int parse_long(const char *number, long int *value)
325 *value = strtol(number, &end, 0);
326 if (end != NULL && *end != 0)
332 static int check_cmd(const command_t *cmd_list, const char *cmd,
333 const char *sub_cmd, const int min_args,
334 int argc, char **argv)
341 const char *const short_options = "h";
342 static const struct option long_options[] = {
343 { .name = "help", .has_arg = no_argument, .val = 'h' },
347 if (argc < min_args) {
348 print_help(cmd_list, cmd, sub_cmd);
351 } else if (argc > 2) {
355 while ((opt = getopt_long(argc, argv, short_options,
356 long_options, NULL)) != -1) {
359 print_help(cmd_list, cmd, sub_cmd);
374 static int jt_set_response_tracking(int argc, char **argv)
378 struct cYAML *err_rc = NULL;
380 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
384 rc = parse_long(argv[1], &value);
386 cYAML_build_error(-1, -1, "parser", "set",
387 "cannot parse response_tracking value",
389 cYAML_print_tree2file(stderr, err_rc);
390 cYAML_free_tree(err_rc);
394 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
395 if (rc != LUSTRE_CFG_RC_NO_ERR)
396 cYAML_print_tree2file(stderr, err_rc);
398 cYAML_free_tree(err_rc);
403 static int jt_set_recovery_limit(int argc, char **argv)
407 struct cYAML *err_rc = NULL;
409 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
413 rc = parse_long(argv[1], &value);
415 cYAML_build_error(-1, -1, "parser", "set",
416 "cannot parse recovery_limit value",
418 cYAML_print_tree2file(stderr, err_rc);
419 cYAML_free_tree(err_rc);
423 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
424 if (rc != LUSTRE_CFG_RC_NO_ERR)
425 cYAML_print_tree2file(stderr, err_rc);
427 cYAML_free_tree(err_rc);
432 static int jt_set_max_intf(int argc, char **argv)
436 struct cYAML *err_rc = NULL;
438 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
442 rc = parse_long(argv[1], &value);
444 cYAML_build_error(-1, -1, "parser", "set",
445 "cannot parse max_interfaces value", &err_rc);
446 cYAML_print_tree2file(stderr, err_rc);
447 cYAML_free_tree(err_rc);
451 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
452 if (rc != LUSTRE_CFG_RC_NO_ERR)
453 cYAML_print_tree2file(stderr, err_rc);
455 cYAML_free_tree(err_rc);
460 static int jt_set_numa(int argc, char **argv)
464 struct cYAML *err_rc = NULL;
466 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
470 rc = parse_long(argv[1], &value);
472 cYAML_build_error(-1, -1, "parser", "set",
473 "cannot parse numa_range value", &err_rc);
474 cYAML_print_tree2file(stderr, err_rc);
475 cYAML_free_tree(err_rc);
479 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
480 if (rc != LUSTRE_CFG_RC_NO_ERR)
481 cYAML_print_tree2file(stderr, err_rc);
483 cYAML_free_tree(err_rc);
488 static int jt_set_recov_intrv(int argc, char **argv)
492 struct cYAML *err_rc = NULL;
494 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
498 rc = parse_long(argv[1], &value);
500 cYAML_build_error(-1, -1, "parser", "set",
501 "cannot parse recovery interval value", &err_rc);
502 cYAML_print_tree2file(stderr, err_rc);
503 cYAML_free_tree(err_rc);
507 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
508 if (rc != LUSTRE_CFG_RC_NO_ERR)
509 cYAML_print_tree2file(stderr, err_rc);
511 cYAML_free_tree(err_rc);
516 static int jt_set_rtr_sensitivity(int argc, char **argv)
520 struct cYAML *err_rc = NULL;
522 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
526 rc = parse_long(argv[1], &value);
528 cYAML_build_error(-1, -1, "parser", "set",
529 "cannot parse router sensitivity value", &err_rc);
530 cYAML_print_tree2file(stderr, err_rc);
531 cYAML_free_tree(err_rc);
535 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
536 if (rc != LUSTRE_CFG_RC_NO_ERR)
537 cYAML_print_tree2file(stderr, err_rc);
539 cYAML_free_tree(err_rc);
544 static int jt_set_hsensitivity(int argc, char **argv)
548 struct cYAML *err_rc = NULL;
550 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
554 rc = parse_long(argv[1], &value);
556 cYAML_build_error(-1, -1, "parser", "set",
557 "cannot parse health sensitivity value", &err_rc);
558 cYAML_print_tree2file(stderr, err_rc);
559 cYAML_free_tree(err_rc);
563 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
564 if (rc != LUSTRE_CFG_RC_NO_ERR)
565 cYAML_print_tree2file(stderr, err_rc);
567 cYAML_free_tree(err_rc);
572 static int jt_set_transaction_to(int argc, char **argv)
576 struct cYAML *err_rc = NULL;
578 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
582 rc = parse_long(argv[1], &value);
584 cYAML_build_error(-1, -1, "parser", "set",
585 "cannot parse transaction timeout value", &err_rc);
586 cYAML_print_tree2file(stderr, err_rc);
587 cYAML_free_tree(err_rc);
591 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
592 if (rc != LUSTRE_CFG_RC_NO_ERR)
593 cYAML_print_tree2file(stderr, err_rc);
595 cYAML_free_tree(err_rc);
600 static int jt_set_retry_count(int argc, char **argv)
604 struct cYAML *err_rc = NULL;
606 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
610 rc = parse_long(argv[1], &value);
612 cYAML_build_error(-1, -1, "parser", "set",
613 "cannot parse retry_count value", &err_rc);
614 cYAML_print_tree2file(stderr, err_rc);
615 cYAML_free_tree(err_rc);
619 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
620 if (rc != LUSTRE_CFG_RC_NO_ERR)
621 cYAML_print_tree2file(stderr, err_rc);
623 cYAML_free_tree(err_rc);
628 static int jt_set_discovery(int argc, char **argv)
632 struct cYAML *err_rc = NULL;
634 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
638 rc = parse_long(argv[1], &value);
640 cYAML_build_error(-1, -1, "parser", "set",
641 "cannot parse discovery value", &err_rc);
642 cYAML_print_tree2file(stderr, err_rc);
643 cYAML_free_tree(err_rc);
647 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
648 if (rc != LUSTRE_CFG_RC_NO_ERR)
649 cYAML_print_tree2file(stderr, err_rc);
651 cYAML_free_tree(err_rc);
656 static int jt_set_drop_asym_route(int argc, char **argv)
660 struct cYAML *err_rc = NULL;
662 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
666 rc = parse_long(argv[1], &value);
668 cYAML_build_error(-1, -1, "parser", "set",
669 "cannot parse drop_asym_route value",
671 cYAML_print_tree2file(stderr, err_rc);
672 cYAML_free_tree(err_rc);
676 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
677 if (rc != LUSTRE_CFG_RC_NO_ERR)
678 cYAML_print_tree2file(stderr, err_rc);
680 cYAML_free_tree(err_rc);
685 static int jt_set_tiny(int argc, char **argv)
689 struct cYAML *err_rc = NULL;
691 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
695 rc = parse_long(argv[1], &value);
697 cYAML_build_error(-1, -1, "parser", "set",
698 "cannot parse tiny_buffers value", &err_rc);
699 cYAML_print_tree2file(stderr, err_rc);
700 cYAML_free_tree(err_rc);
704 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
705 if (rc != LUSTRE_CFG_RC_NO_ERR)
706 cYAML_print_tree2file(stderr, err_rc);
708 cYAML_free_tree(err_rc);
713 static int jt_set_small(int argc, char **argv)
717 struct cYAML *err_rc = NULL;
719 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
723 rc = parse_long(argv[1], &value);
725 cYAML_build_error(-1, -1, "parser", "set",
726 "cannot parse small_buffers value", &err_rc);
727 cYAML_print_tree2file(stderr, err_rc);
728 cYAML_free_tree(err_rc);
732 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
733 if (rc != LUSTRE_CFG_RC_NO_ERR)
734 cYAML_print_tree2file(stderr, err_rc);
736 cYAML_free_tree(err_rc);
741 static int jt_set_large(int argc, char **argv)
745 struct cYAML *err_rc = NULL;
747 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
751 rc = parse_long(argv[1], &value);
753 cYAML_build_error(-1, -1, "parser", "set",
754 "cannot parse large_buffers value", &err_rc);
755 cYAML_print_tree2file(stderr, err_rc);
756 cYAML_free_tree(err_rc);
760 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
761 if (rc != LUSTRE_CFG_RC_NO_ERR)
762 cYAML_print_tree2file(stderr, err_rc);
764 cYAML_free_tree(err_rc);
769 static int jt_set_routing(int argc, char **argv)
772 struct cYAML *err_rc = NULL;
775 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
779 rc = parse_long(argv[1], &value);
780 if (rc != 0 || (value != 0 && value != 1)) {
781 cYAML_build_error(-1, -1, "parser", "set",
782 "cannot parse routing value.\n"
783 "must be 0 for disable or 1 for enable",
785 cYAML_print_tree2file(stderr, err_rc);
786 cYAML_free_tree(err_rc);
790 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
792 if (rc != LUSTRE_CFG_RC_NO_ERR)
793 cYAML_print_tree2file(stderr, err_rc);
795 cYAML_free_tree(err_rc);
800 static int jt_config_lnet(int argc, char **argv)
802 struct cYAML *err_rc = NULL;
803 bool load_mod_params = false;
806 const char *const short_options = "a";
807 static const struct option long_options[] = {
808 { .name = "all", .has_arg = no_argument, .val = 'a' },
812 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
816 while ((opt = getopt_long(argc, argv, short_options,
817 long_options, NULL)) != -1) {
820 load_mod_params = true;
827 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
830 if (rc != LUSTRE_CFG_RC_NO_ERR)
831 cYAML_print_tree2file(stderr, err_rc);
833 cYAML_free_tree(err_rc);
838 static int jt_unconfig_lnet(int argc, char **argv)
840 struct cYAML *err_rc = NULL;
843 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
847 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
849 if (rc != LUSTRE_CFG_RC_NO_ERR)
850 cYAML_print_tree2file(stderr, err_rc);
852 cYAML_free_tree(err_rc);
856 static int jt_add_route(int argc, char **argv)
858 char *network = NULL, *gateway = NULL;
859 long int hop = -1, prio = -1, sen = -1;
860 struct cYAML *err_rc = NULL;
863 const char *const short_options = "n:g:c:p:";
864 static const struct option long_options[] = {
865 { .name = "net", .has_arg = required_argument, .val = 'n' },
866 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
867 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
868 { .name = "priority", .has_arg = required_argument, .val = 'p' },
869 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
872 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
876 while ((opt = getopt_long(argc, argv, short_options,
877 long_options, NULL)) != -1) {
886 rc = parse_long(optarg, &hop);
894 rc = parse_long(optarg, &prio);
902 rc = parse_long(optarg, &sen);
911 print_help(route_cmds, "route", "add");
917 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
920 if (rc != LUSTRE_CFG_RC_NO_ERR)
921 cYAML_print_tree2file(stderr, err_rc);
923 cYAML_free_tree(err_rc);
928 static int jt_add_ni(int argc, char **argv)
931 long int pto = -1, pc = -1, pbc = -1, cre = -1;
932 struct cYAML *err_rc = NULL;
933 int rc, opt, cpt_rc = -1;
934 struct lnet_dlc_network_descr nw_descr;
935 struct cfs_expr_list *global_cpts = NULL;
936 struct lnet_ioctl_config_lnd_tunables tunables;
939 memset(&tunables, 0, sizeof(tunables));
940 lustre_lnet_init_nw_descr(&nw_descr);
942 const char *const short_options = "n:i:p:t:c:b:r:s:";
943 static const struct option long_options[] = {
944 { .name = "net", .has_arg = required_argument, .val = 'n' },
945 { .name = "if", .has_arg = required_argument, .val = 'i' },
946 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
947 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
948 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
949 { .name = "peer-buffer-credits",
950 .has_arg = required_argument, .val = 'b' },
951 { .name = "credits", .has_arg = required_argument, .val = 'r' },
952 { .name = "cpt", .has_arg = required_argument, .val = 's' },
955 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
959 while ((opt = getopt_long(argc, argv, short_options,
960 long_options, NULL)) != -1) {
963 nw_descr.nw_id = libcfs_str2net(optarg);
966 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
968 cYAML_build_error(-1, -1, "ni", "add",
969 "bad interface list",
978 rc = parse_long(optarg, &pto);
986 rc = parse_long(optarg, &pc);
994 rc = parse_long(optarg, &pbc);
1002 rc = parse_long(optarg, &cre);
1010 cpt_rc = cfs_expr_list_parse(optarg,
1012 UINT_MAX, &global_cpts);
1015 print_help(net_cmds, "net", "add");
1021 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
1022 tunables.lt_cmn.lct_peer_timeout = pto;
1023 tunables.lt_cmn.lct_peer_tx_credits = pc;
1024 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1025 tunables.lt_cmn.lct_max_tx_credits = cre;
1029 rc = lustre_lnet_config_ni(&nw_descr,
1030 (cpt_rc == 0) ? global_cpts: NULL,
1031 ip2net, (found) ? &tunables : NULL,
1034 if (global_cpts != NULL)
1035 cfs_expr_list_free(global_cpts);
1038 if (rc != LUSTRE_CFG_RC_NO_ERR)
1039 cYAML_print_tree2file(stderr, err_rc);
1041 cYAML_free_tree(err_rc);
1046 static int jt_del_route(int argc, char **argv)
1048 char *network = NULL, *gateway = NULL;
1049 struct cYAML *err_rc = NULL;
1052 const char *const short_options = "n:g:";
1053 static const struct option long_options[] = {
1054 { .name = "net", .has_arg = required_argument, .val = 'n' },
1055 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1058 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1062 while ((opt = getopt_long(argc, argv, short_options,
1063 long_options, NULL)) != -1) {
1072 print_help(route_cmds, "route", "del");
1078 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1080 if (rc != LUSTRE_CFG_RC_NO_ERR)
1081 cYAML_print_tree2file(stderr, err_rc);
1083 cYAML_free_tree(err_rc);
1088 static int jt_del_ni(int argc, char **argv)
1090 struct cYAML *err_rc = NULL;
1092 struct lnet_dlc_network_descr nw_descr;
1094 lustre_lnet_init_nw_descr(&nw_descr);
1096 const char *const short_options = "n:i:";
1097 static const struct option long_options[] = {
1098 { .name = "net", .has_arg = required_argument, .val = 'n' },
1099 { .name = "if", .has_arg = required_argument, .val = 'i' },
1102 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1106 while ((opt = getopt_long(argc, argv, short_options,
1107 long_options, NULL)) != -1) {
1110 nw_descr.nw_id = libcfs_str2net(optarg);
1113 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1115 cYAML_build_error(-1, -1, "ni", "add",
1116 "bad interface list",
1122 print_help(net_cmds, "net", "del");
1128 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1131 if (rc != LUSTRE_CFG_RC_NO_ERR)
1132 cYAML_print_tree2file(stderr, err_rc);
1134 cYAML_free_tree(err_rc);
1139 static int jt_show_route(int argc, char **argv)
1141 char *network = NULL, *gateway = NULL;
1142 long int hop = -1, prio = -1;
1143 int detail = 0, rc, opt;
1144 struct cYAML *err_rc = NULL, *show_rc = NULL;
1146 const char *const short_options = "n:g:h:p:v";
1147 static const struct option long_options[] = {
1148 { .name = "net", .has_arg = required_argument, .val = 'n' },
1149 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1150 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1151 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1152 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1155 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1159 while ((opt = getopt_long(argc, argv, short_options,
1160 long_options, NULL)) != -1) {
1169 rc = parse_long(optarg, &hop);
1177 rc = parse_long(optarg, &prio);
1188 print_help(route_cmds, "route", "show");
1194 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1195 &show_rc, &err_rc, false);
1197 if (rc != LUSTRE_CFG_RC_NO_ERR)
1198 cYAML_print_tree2file(stderr, err_rc);
1200 cYAML_print_tree(show_rc);
1202 cYAML_free_tree(err_rc);
1203 cYAML_free_tree(show_rc);
1208 static int set_value_helper(int argc, char **argv,
1209 int (*cb)(int, bool, char*, int, struct cYAML**))
1212 long int healthv = -1;
1215 struct cYAML *err_rc = NULL;
1217 const char *const short_options = "t:n:a";
1218 static const struct option long_options[] = {
1219 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1220 { .name = "health", .has_arg = required_argument, .val = 't' },
1221 { .name = "all", .has_arg = no_argument, .val = 'a' },
1224 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1228 while ((opt = getopt_long(argc, argv, short_options,
1229 long_options, NULL)) != -1) {
1235 if (parse_long(optarg, &healthv) != 0)
1246 rc = cb(healthv, all, nid, -1, &err_rc);
1248 if (rc != LUSTRE_CFG_RC_NO_ERR)
1249 cYAML_print_tree2file(stderr, err_rc);
1251 cYAML_free_tree(err_rc);
1256 static int jt_set_ni_value(int argc, char **argv)
1258 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1261 static int jt_set_peer_ni_value(int argc, char **argv)
1263 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1266 static int jt_show_recovery(int argc, char **argv)
1269 struct cYAML *err_rc = NULL, *show_rc = NULL;
1271 const char *const short_options = "lp";
1272 static const struct option long_options[] = {
1273 { .name = "local", .has_arg = no_argument, .val = 'l' },
1274 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1277 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1281 while ((opt = getopt_long(argc, argv, short_options,
1282 long_options, NULL)) != -1) {
1285 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1288 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1295 if (rc != LUSTRE_CFG_RC_NO_ERR)
1296 cYAML_print_tree2file(stderr, err_rc);
1298 cYAML_print_tree(show_rc);
1300 cYAML_free_tree(err_rc);
1301 cYAML_free_tree(show_rc);
1306 static int jt_show_net(int argc, char **argv)
1308 char *network = NULL;
1310 struct cYAML *err_rc = NULL, *show_rc = NULL;
1311 long int detail = 0;
1313 const char *const short_options = "n:v";
1314 static const struct option long_options[] = {
1315 { .name = "net", .has_arg = required_argument, .val = 'n' },
1316 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1319 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1323 while ((opt = getopt_long(argc, argv, short_options,
1324 long_options, NULL)) != -1) {
1330 if ((!optarg) && (argv[optind] != NULL) &&
1331 (argv[optind][0] != '-')) {
1332 if (parse_long(argv[optind++], &detail) != 0)
1339 print_help(net_cmds, "net", "show");
1345 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1348 if (rc != LUSTRE_CFG_RC_NO_ERR)
1349 cYAML_print_tree2file(stderr, err_rc);
1351 cYAML_print_tree(show_rc);
1353 cYAML_free_tree(err_rc);
1354 cYAML_free_tree(show_rc);
1359 static int jt_show_routing(int argc, char **argv)
1361 struct cYAML *err_rc = NULL, *show_rc = NULL;
1364 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1368 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1370 if (rc != LUSTRE_CFG_RC_NO_ERR)
1371 cYAML_print_tree2file(stderr, err_rc);
1373 cYAML_print_tree(show_rc);
1375 cYAML_free_tree(err_rc);
1376 cYAML_free_tree(show_rc);
1381 static int jt_show_stats(int argc, char **argv)
1384 struct cYAML *show_rc = NULL, *err_rc = NULL;
1386 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1390 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1392 if (rc != LUSTRE_CFG_RC_NO_ERR)
1393 cYAML_print_tree2file(stderr, err_rc);
1395 cYAML_print_tree(show_rc);
1397 cYAML_free_tree(err_rc);
1398 cYAML_free_tree(show_rc);
1403 static int jt_show_udsp(int argc, char **argv)
1407 struct cYAML *err_rc = NULL, *show_rc = NULL;
1409 const char *const short_options = "i:";
1410 static const struct option long_options[] = {
1411 { .name = "idx", .has_arg = required_argument, .val = 'i' },
1415 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
1419 while ((opt = getopt_long(argc, argv, short_options,
1420 long_options, NULL)) != -1) {
1426 print_help(net_cmds, "net", "show");
1432 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
1434 if (rc != LUSTRE_CFG_RC_NO_ERR)
1435 cYAML_print_tree2file(stderr, err_rc);
1437 cYAML_print_tree(show_rc);
1439 cYAML_free_tree(err_rc);
1440 cYAML_free_tree(show_rc);
1445 static int jt_show_global(int argc, char **argv)
1448 struct cYAML *show_rc = NULL, *err_rc = NULL;
1450 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1454 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1455 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1456 cYAML_print_tree2file(stderr, err_rc);
1460 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1461 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1462 cYAML_print_tree2file(stderr, err_rc);
1466 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1467 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1468 cYAML_print_tree2file(stderr, err_rc);
1472 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1473 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1474 cYAML_print_tree2file(stderr, err_rc);
1478 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1479 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1480 cYAML_print_tree2file(stderr, err_rc);
1484 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1485 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1486 cYAML_print_tree2file(stderr, err_rc);
1490 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1491 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1492 cYAML_print_tree2file(stderr, err_rc);
1496 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1497 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1498 cYAML_print_tree2file(stderr, err_rc);
1502 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1503 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1504 cYAML_print_tree2file(stderr, err_rc);
1508 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1509 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1510 cYAML_print_tree2file(stderr, err_rc);
1514 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1515 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1516 cYAML_print_tree2file(stderr, err_rc);
1520 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1521 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1522 cYAML_print_tree2file(stderr, err_rc);
1527 cYAML_print_tree(show_rc);
1530 cYAML_free_tree(err_rc);
1531 cYAML_free_tree(show_rc);
1536 static int jt_lnet(int argc, char **argv)
1540 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1544 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1547 static int jt_route(int argc, char **argv)
1551 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1555 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1558 static int jt_net(int argc, char **argv)
1562 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1566 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1569 static int jt_routing(int argc, char **argv)
1573 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1577 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1580 static int jt_stats(int argc, char **argv)
1584 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1588 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1591 static int jt_debug(int argc, char **argv)
1595 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1599 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1602 static int jt_global(int argc, char **argv)
1606 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1610 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1613 static int jt_peers(int argc, char **argv)
1617 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1621 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1624 static int jt_set(int argc, char **argv)
1628 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1632 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1635 static int jt_udsp(int argc, char **argv)
1639 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1643 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1646 static int jt_import(int argc, char **argv)
1649 struct cYAML *err_rc = NULL;
1650 struct cYAML *show_rc = NULL;
1651 int rc = 0, return_rc = 0, opt, opt_found = 0;
1654 const char *const short_options = "adseh";
1655 static const struct option long_options[] = {
1656 { .name = "add", .has_arg = no_argument, .val = 'a' },
1657 { .name = "del", .has_arg = no_argument, .val = 'd' },
1658 { .name = "show", .has_arg = no_argument, .val = 's' },
1659 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1660 { .name = "help", .has_arg = no_argument, .val = 'h' },
1663 while ((opt = getopt_long(argc, argv, short_options,
1664 long_options, NULL)) != -1) {
1678 printf("import FILE\n"
1679 "import < FILE : import a file\n"
1680 "\t--add: add configuration\n"
1681 "\t--del: delete configuration\n"
1682 "\t--show: show configuration\n"
1683 "\t--exec: execute command\n"
1684 "\t--help: display this help\n"
1685 "If no command option is given then --add"
1686 " is assumed by default\n");
1693 /* grab the file name if one exists */
1694 if (opt_found && argc == 3)
1696 else if (!opt_found && argc == 2)
1701 rc = lustre_yaml_config(file, &err_rc);
1702 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1703 cYAML_print_tree(show_rc);
1704 cYAML_free_tree(show_rc);
1707 rc = lustre_yaml_del(file, &err_rc);
1710 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1711 cYAML_print_tree(show_rc);
1712 cYAML_free_tree(show_rc);
1715 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1716 cYAML_print_tree(show_rc);
1717 cYAML_free_tree(show_rc);
1721 if (rc || return_rc) {
1722 cYAML_print_tree2file(stderr, err_rc);
1723 cYAML_free_tree(err_rc);
1729 static int jt_export(int argc, char **argv)
1731 struct cYAML *show_rc = NULL;
1732 struct cYAML *err_rc = NULL;
1736 bool backup = false;
1739 const char *const short_options = "bh";
1740 static const struct option long_options[] = {
1741 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1742 { .name = "help", .has_arg = no_argument, .val = 'h' },
1745 while ((opt = getopt_long(argc, argv, short_options,
1746 long_options, NULL)) != -1) {
1753 printf("export > FILE.yaml : export configuration\n"
1754 "\t--backup: export only what's necessary for reconfig\n"
1755 "\t--help: display this help\n");
1760 if (backup && argc >= 3)
1762 else if (!backup && argc >= 2)
1768 f = fopen(file, "w");
1773 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1774 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1775 cYAML_print_tree2file(stderr, err_rc);
1776 cYAML_free_tree(err_rc);
1780 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1782 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1783 cYAML_print_tree2file(stderr, err_rc);
1784 cYAML_free_tree(err_rc);
1788 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1789 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1790 cYAML_print_tree2file(stderr, err_rc);
1791 cYAML_free_tree(err_rc);
1795 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1796 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1797 cYAML_print_tree2file(stderr, err_rc);
1798 cYAML_free_tree(err_rc);
1802 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1803 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1804 cYAML_print_tree2file(stderr, err_rc);
1805 cYAML_free_tree(err_rc);
1809 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1810 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1811 cYAML_print_tree2file(stderr, err_rc);
1812 cYAML_free_tree(err_rc);
1816 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1817 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1818 cYAML_print_tree2file(stderr, err_rc);
1819 cYAML_free_tree(err_rc);
1823 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1824 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1825 cYAML_print_tree2file(stderr, err_rc);
1826 cYAML_free_tree(err_rc);
1830 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1831 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1832 cYAML_print_tree2file(stderr, err_rc);
1836 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1837 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1838 cYAML_print_tree2file(stderr, err_rc);
1842 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1843 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1844 cYAML_print_tree2file(stderr, err_rc);
1848 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1849 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1850 cYAML_print_tree2file(stderr, err_rc);
1854 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1855 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1856 cYAML_print_tree2file(stderr, err_rc);
1860 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1861 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1862 cYAML_print_tree2file(stderr, err_rc);
1866 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1867 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1868 cYAML_print_tree2file(stderr, err_rc);
1869 cYAML_free_tree(err_rc);
1873 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1874 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1875 cYAML_print_tree2file(stderr, err_rc);
1876 cYAML_free_tree(err_rc);
1880 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
1881 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1882 cYAML_print_tree2file(stderr, err_rc);
1883 cYAML_free_tree(err_rc);
1887 if (show_rc != NULL) {
1888 cYAML_print_tree2file(f, show_rc);
1889 cYAML_free_tree(show_rc);
1898 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1900 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1902 char *prim_nid = NULL, *nidstr = NULL;
1903 char err_str[LNET_MAX_STR_LEN] = "Error";
1904 struct cYAML *err_rc = NULL;
1906 const char *const short_opts = "k:mn:";
1907 const struct option long_opts[] = {
1908 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1909 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1910 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1913 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1917 while ((opt = getopt_long(argc, argv, short_opts,
1918 long_opts, NULL)) != -1) {
1927 if (cmd == LNETCTL_DEL_CMD) {
1928 rc = LUSTRE_CFG_RC_BAD_PARAM;
1929 snprintf(err_str, LNET_MAX_STR_LEN,
1930 "Unrecognized option '-%c'", opt);
1936 print_help(peer_cmds, "peer",
1937 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1943 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
1945 if (rc != LUSTRE_CFG_RC_NO_ERR)
1949 cYAML_build_error(rc, -1, "peer",
1950 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1954 if (rc != LUSTRE_CFG_RC_NO_ERR)
1955 cYAML_print_tree2file(stderr, err_rc);
1957 cYAML_free_tree(err_rc);
1962 static int jt_add_peer_nid(int argc, char **argv)
1964 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1967 static int jt_del_peer_nid(int argc, char **argv)
1969 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1972 static int jt_show_peer(int argc, char **argv)
1976 struct cYAML *err_rc = NULL, *show_rc = NULL;
1977 long int detail = 0;
1979 const char *const short_opts = "hn:v::";
1980 const struct option long_opts[] = {
1981 { .name = "help", .has_arg = no_argument, .val = 'h' },
1982 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1983 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1986 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1990 while ((opt = getopt_long(argc, argv, short_opts,
1991 long_opts, NULL)) != -1) {
1997 if ((!optarg) && (argv[optind] != NULL) &&
1998 (argv[optind][0] != '-')) {
1999 if (parse_long(argv[optind++], &detail) != 0)
2006 print_help(peer_cmds, "peer", "show");
2012 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2015 if (rc != LUSTRE_CFG_RC_NO_ERR)
2016 cYAML_print_tree2file(stderr, err_rc);
2018 cYAML_print_tree(show_rc);
2020 cYAML_free_tree(err_rc);
2021 cYAML_free_tree(show_rc);
2026 static int jt_list_peer(int argc, char **argv)
2029 struct cYAML *err_rc = NULL, *list_rc = NULL;
2031 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2035 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2037 if (rc != LUSTRE_CFG_RC_NO_ERR)
2038 cYAML_print_tree2file(stderr, err_rc);
2040 cYAML_print_tree(list_rc);
2042 cYAML_free_tree(err_rc);
2043 cYAML_free_tree(list_rc);
2048 static int jt_ping(int argc, char **argv)
2050 struct cYAML *err_rc = NULL;
2051 struct cYAML *show_rc = NULL;
2055 const char *const short_options = "ht:";
2056 const struct option long_options[] = {
2057 { .name = "help", .has_arg = no_argument, .val = 'h' },
2058 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2061 while ((opt = getopt_long(argc, argv, short_options,
2062 long_options, NULL)) != -1) {
2065 timeout = 1000 * atol(optarg);
2068 printf("ping nid[,nid,...]\n"
2069 "\t --timeout: ping timeout\n"
2070 "\t --help: display this help\n");
2077 for (; optind < argc; optind++)
2078 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
2081 cYAML_print_tree(show_rc);
2084 cYAML_print_tree2file(stderr, err_rc);
2086 cYAML_free_tree(err_rc);
2087 cYAML_free_tree(show_rc);
2092 static int jt_discover(int argc, char **argv)
2094 struct cYAML *err_rc = NULL;
2095 struct cYAML *show_rc = NULL;
2099 const char *const short_options = "fh";
2100 const struct option long_options[] = {
2101 { .name = "force", .has_arg = no_argument, .val = 'f' },
2102 { .name = "help", .has_arg = no_argument, .val = 'h' },
2105 while ((opt = getopt_long(argc, argv, short_options,
2106 long_options, NULL)) != -1) {
2112 printf("discover nid[,nid,...]\n"
2113 "\t --force: force discovery\n"
2114 "\t --help: display this help\n");
2121 for (; optind < argc; optind++)
2122 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2126 cYAML_print_tree(show_rc);
2129 cYAML_print_tree2file(stderr, err_rc);
2131 cYAML_free_tree(err_rc);
2132 cYAML_free_tree(show_rc);
2137 static int jt_add_udsp(int argc, char **argv)
2139 char *src = NULL, *dst = NULL, *rte = NULL;
2140 struct cYAML *err_rc = NULL;
2141 union lnet_udsp_action udsp_action;
2142 long int idx = -1, priority = -1;
2144 char *action_type = "pref";
2146 const char *const short_options = "s:d:r:p:i:";
2147 static const struct option long_options[] = {
2148 { .name = "src", .has_arg = required_argument, .val = 's' },
2149 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2150 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2151 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2152 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2155 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2159 while ((opt = getopt_long(argc, argv, short_options,
2160 long_options, NULL)) != -1) {
2172 rc = parse_long(optarg, &priority);
2175 action_type = "priority";
2176 udsp_action.udsp_priority = priority;
2179 rc = parse_long(optarg, &idx);
2184 print_help(udsp_cmds, "udsp", "add");
2190 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2193 if (rc != LUSTRE_CFG_RC_NO_ERR)
2194 cYAML_print_tree2file(stderr, err_rc);
2196 cYAML_free_tree(err_rc);
2201 static int jt_del_udsp(int argc, char **argv)
2203 struct cYAML *err_rc = NULL;
2207 const char *const short_options = "i:";
2208 static const struct option long_options[] = {
2209 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2212 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2216 while ((opt = getopt_long(argc, argv, short_options,
2217 long_options, NULL)) != -1) {
2220 rc = parse_long(optarg, &idx);
2225 print_help(udsp_cmds, "udsp", "add");
2231 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2232 if (rc != LUSTRE_CFG_RC_NO_ERR)
2233 cYAML_print_tree2file(stderr, err_rc);
2235 cYAML_free_tree(err_rc);
2240 static int lnetctl_list_commands(int argc, char **argv)
2242 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2244 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2249 int main(int argc, char **argv)
2252 struct cYAML *err_rc = NULL;
2254 rc = lustre_lnet_config_lib_init();
2256 cYAML_build_error(-1, -1, "lnetctl", "startup",
2257 "cannot register LNet device", &err_rc);
2258 cYAML_print_tree2file(stderr, err_rc);
2262 Parser_init("lnetctl > ", cmd_list);
2264 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);