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_reset_stats(int argc, char **argv);
64 static int jt_add_peer_nid(int argc, char **argv);
65 static int jt_del_peer_nid(int argc, char **argv);
66 static int jt_set_max_intf(int argc, char **argv);
67 static int jt_set_discovery(int argc, char **argv);
68 static int jt_set_drop_asym_route(int argc, char **argv);
69 static int jt_list_peer(int argc, char **argv);
70 static int jt_add_udsp(int argc, char **argv);
71 static int jt_del_udsp(int argc, char **argv);
72 /*static int jt_show_peer(int argc, char **argv);*/
73 static int lnetctl_list_commands(int argc, char **argv);
74 static int jt_import(int argc, char **argv);
75 static int jt_export(int argc, char **argv);
76 static int jt_ping(int argc, char **argv);
77 static int jt_discover(int argc, char **argv);
78 static int jt_lnet(int argc, char **argv);
79 static int jt_route(int argc, char **argv);
80 static int jt_net(int argc, char **argv);
81 static int jt_routing(int argc, char **argv);
82 static int jt_set(int argc, char **argv);
83 static int jt_debug(int argc, char **argv);
84 static int jt_stats(int argc, char **argv);
85 static int jt_global(int argc, char **argv);
86 static int jt_peers(int argc, char **argv);
87 static int jt_set_ni_value(int argc, char **argv);
88 static int jt_set_peer_ni_value(int argc, char **argv);
89 static int jt_calc_service_id(int argc, char **argv);
90 static int jt_set_response_tracking(int argc, char **argv);
91 static int jt_set_recovery_limit(int argc, char **argv);
92 static int jt_udsp(int argc, char **argv);
94 command_t cmd_list[] = {
95 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
96 {"route", jt_route, 0, "route {add | del | show | help}"},
97 {"net", jt_net, 0, "net {add | del | show | set | help}"},
98 {"routing", jt_routing, 0, "routing {show | help}"},
99 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
100 " | routing | numa_range | max_interfaces"
101 " | discovery | drop_asym_route | retry_count"
102 " | transaction_timeout | health_sensitivity"
103 " | recovery_interval | router_sensitivity"
104 " | response_tracking | recovery_limit}"},
105 {"import", jt_import, 0, "import FILE.yaml"},
106 {"export", jt_export, 0, "export FILE.yaml"},
107 {"stats", jt_stats, 0, "stats {show | help}"},
108 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
109 {"global", jt_global, 0, "global {show | help}"},
110 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
111 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
112 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
113 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
114 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
115 {"help", Parser_help, 0, "help"},
116 {"exit", Parser_quit, 0, "quit"},
117 {"quit", Parser_quit, 0, "quit"},
118 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
122 command_t lnet_cmds[] = {
123 {"configure", jt_config_lnet, 0, "configure lnet\n"
124 "\t--all: load NI configuration from module parameters\n"},
125 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
129 command_t route_cmds[] = {
130 {"add", jt_add_route, 0, "add a route\n"
131 "\t--net: net name (e.g. tcp0)\n"
132 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
133 "\t--hop: number to final destination (1 < hops < 255)\n"
134 "\t--priority: priority of route (0 - highest prio\n"
135 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
136 {"del", jt_del_route, 0, "delete a route\n"
137 "\t--net: net name (e.g. tcp0)\n"
138 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
139 {"show", jt_show_route, 0, "show routes\n"
140 "\t--net: net name (e.g. tcp0) to filter on\n"
141 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
142 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
143 "\t--priority: priority of route (0 - highest prio to filter on\n"
144 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
145 "\t--verbose: display detailed output per route\n"},
149 command_t net_cmds[] = {
150 {"add", jt_add_ni, 0, "add a network\n"
151 "\t--net: net name (e.g. tcp0)\n"
152 "\t--if: physical interface (e.g. eth0)\n"
153 "\t--ip2net: specify networks based on IP address patterns\n"
154 "\t--peer-timeout: time to wait before declaring a peer dead\n"
155 "\t--peer-credits: define the max number of inflight messages\n"
156 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
157 "\t--credits: Network Interface credits\n"
158 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
159 "\t--conns-per-peer: number of connections per peer\n"},
160 {"del", jt_del_ni, 0, "delete a network\n"
161 "\t--net: net name (e.g. tcp0)\n"
162 "\t--if: physical interface (e.g. eth0)\n"},
163 {"show", jt_show_net, 0, "show networks\n"
164 "\t--net: net name (e.g. tcp0) to filter on\n"
165 "\t--verbose: display detailed output per network."
166 " Optional argument of '2' outputs more stats\n"},
167 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
168 "\t--nid: NI NID to set the\n"
169 "\t--health: specify health value to set\n"
170 "\t--conns-per-peer: number of connections per peer\n"
171 "\t--all: set all NIs value to the one specified\n"},
175 command_t routing_cmds[] = {
176 {"show", jt_show_routing, 0, "show routing information\n"},
180 command_t stats_cmds[] = {
181 {"show", jt_show_stats, 0, "show LNET statistics\n"},
182 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
186 command_t debug_cmds[] = {
187 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
188 "\t--local : list local recovery queue\n"
189 "\t--peer : list peer recovery queue\n"},
193 command_t global_cmds[] = {
194 {"show", jt_show_global, 0, "show global variables\n"},
198 command_t set_cmds[] = {
199 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
200 "\tVALUE must be greater than 0\n"},
201 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
202 "\tVALUE must be greater than 0\n"},
203 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
204 "\tVALUE must be greater than 0\n"},
205 {"routing", jt_set_routing, 0, "enable/disable routing\n"
206 "\t0 - disable routing\n"
207 "\t1 - enable routing\n"},
208 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
209 "\tVALUE must be at least 0\n"},
210 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
212 "\tValue must be greater than 16\n"},
213 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
214 "\t0 - disable peer discovery\n"
215 "\t1 - enable peer discovery (default)\n"},
216 {"drop_asym_route", jt_set_drop_asym_route, 0,
217 "drop/accept asymmetrical route messages\n"
218 "\t0 - accept asymmetrical route messages (default)\n"
219 "\t1 - drop asymmetrical route messages\n"},
220 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
221 "\t0 - turn of retries\n"
222 "\t>0 - number of retries\n"},
223 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
224 "\t>0 - timeout in seconds\n"},
225 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
226 "\t0 - turn off health evaluation\n"
227 "\t>0 - sensitivity value not more than 1000\n"},
228 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
229 "\t>0 - time in seconds between pings\n"},
230 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
231 "\t100 - router interfaces need to be fully healthy to be used\n"
232 "\t<100 - router interfaces can be used even if not healthy\n"},
233 {"response_tracking", jt_set_response_tracking, 0,
234 "Set the behavior of response tracking\n"
235 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
236 "\t1 - GETs are eligible for response tracking\n"
237 "\t2 - PUTs are eligible for response tracking\n"
238 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
239 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
240 "\t pings and discovery pushes always utilize response tracking\n"},
241 {"recovery_limit", jt_set_recovery_limit, 0,
242 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
243 "\t0 - Recover indefinitely (default)\n"
244 "\t>0 - Recover for the specified number of seconds.\n"},
248 command_t peer_cmds[] = {
249 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
250 "\t--prim_nid: Primary NID of the peer.\n"
251 "\t--nid: one or more peer NIDs\n"
252 "\t--non_mr: create this peer as not Multi-Rail capable\n"
253 "\t--ip2nets: specify a range of nids per peer"},
254 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
255 "\t--prim_nid: Primary NID of the peer.\n"
256 "\t--nid: list of NIDs to remove. If none provided,\n"
257 "\t peer is deleted\n"
258 "\t--ip2nets: specify a range of nids per peer"},
259 {"show", jt_show_peer, 0, "show peer information\n"
260 "\t--nid: NID of peer to filter on.\n"
261 "\t--verbose: display detailed output per peer."
262 " Optional argument of '2' outputs more stats\n"},
263 {"list", jt_list_peer, 0, "list all peers\n"},
264 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
265 "\t--nid: Peer NI NID to set the\n"
266 "\t--health: specify health value to set\n"
267 "\t--all: set all peer_nis values to the one specified\n"},
271 command_t udsp_cmds[] = {
272 {"add", jt_add_udsp, 0, "add a udsp\n"
273 "\t--src: ip2nets syntax specifying the local NID to match\n"
274 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
275 "\t--rte: ip2nets syntax specifying the router NID to match\n"
276 "\t--priority: priority value (0 - highest priority)\n"
277 "\t--idx: index of where to insert the rule.\n"
278 "\t By default, appends to the end of the rule list.\n"},
279 {"del", jt_del_udsp, 0, "delete a udsp\n"
280 "\t--idx: index of the Policy.\n"},
281 {"show", jt_show_udsp, 0, "show udsps\n"
282 "\t --idx: index of the policy to show.\n"},
286 static int jt_calc_service_id(int argc, char **argv)
291 rc = lustre_lnet_calc_service_id(&service_id);
292 if (rc != LUSTRE_CFG_RC_NO_ERR)
296 * cYAML currently doesn't support printing hex values.
297 * Therefore just print it locally here
299 printf("service id:\n value: 0x%jx\n", (uintmax_t)service_id);
304 static inline void print_help(const command_t cmds[], const char *cmd_type,
307 const command_t *cmd;
309 for (cmd = cmds; cmd->pc_name; cmd++) {
310 if (pc_name != NULL &&
311 strcmp(cmd->pc_name, pc_name) == 0) {
312 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
315 } else if (pc_name != NULL) {
318 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
322 static int parse_long(const char *number, long int *value)
329 *value = strtol(number, &end, 0);
330 if (end != NULL && *end != 0)
336 static int check_cmd(const command_t *cmd_list, const char *cmd,
337 const char *sub_cmd, const int min_args,
338 int argc, char **argv)
345 const char *const short_options = "h";
346 static const struct option long_options[] = {
347 { .name = "help", .has_arg = no_argument, .val = 'h' },
351 if (argc < min_args) {
352 print_help(cmd_list, cmd, sub_cmd);
355 } else if (argc > 2) {
359 while ((opt = getopt_long(argc, argv, short_options,
360 long_options, NULL)) != -1) {
363 print_help(cmd_list, cmd, sub_cmd);
378 static int jt_set_response_tracking(int argc, char **argv)
382 struct cYAML *err_rc = NULL;
384 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
388 rc = parse_long(argv[1], &value);
390 cYAML_build_error(-1, -1, "parser", "set",
391 "cannot parse response_tracking value",
393 cYAML_print_tree2file(stderr, err_rc);
394 cYAML_free_tree(err_rc);
398 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
399 if (rc != LUSTRE_CFG_RC_NO_ERR)
400 cYAML_print_tree2file(stderr, err_rc);
402 cYAML_free_tree(err_rc);
407 static int jt_set_recovery_limit(int argc, char **argv)
411 struct cYAML *err_rc = NULL;
413 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
417 rc = parse_long(argv[1], &value);
419 cYAML_build_error(-1, -1, "parser", "set",
420 "cannot parse recovery_limit value",
422 cYAML_print_tree2file(stderr, err_rc);
423 cYAML_free_tree(err_rc);
427 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
428 if (rc != LUSTRE_CFG_RC_NO_ERR)
429 cYAML_print_tree2file(stderr, err_rc);
431 cYAML_free_tree(err_rc);
436 static int jt_set_max_intf(int argc, char **argv)
440 struct cYAML *err_rc = NULL;
442 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
446 rc = parse_long(argv[1], &value);
448 cYAML_build_error(-1, -1, "parser", "set",
449 "cannot parse max_interfaces value", &err_rc);
450 cYAML_print_tree2file(stderr, err_rc);
451 cYAML_free_tree(err_rc);
455 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
456 if (rc != LUSTRE_CFG_RC_NO_ERR)
457 cYAML_print_tree2file(stderr, err_rc);
459 cYAML_free_tree(err_rc);
464 static int jt_set_numa(int argc, char **argv)
468 struct cYAML *err_rc = NULL;
470 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
474 rc = parse_long(argv[1], &value);
476 cYAML_build_error(-1, -1, "parser", "set",
477 "cannot parse numa_range value", &err_rc);
478 cYAML_print_tree2file(stderr, err_rc);
479 cYAML_free_tree(err_rc);
483 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
484 if (rc != LUSTRE_CFG_RC_NO_ERR)
485 cYAML_print_tree2file(stderr, err_rc);
487 cYAML_free_tree(err_rc);
492 static int jt_set_recov_intrv(int argc, char **argv)
496 struct cYAML *err_rc = NULL;
498 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
502 rc = parse_long(argv[1], &value);
504 cYAML_build_error(-1, -1, "parser", "set",
505 "cannot parse recovery interval value", &err_rc);
506 cYAML_print_tree2file(stderr, err_rc);
507 cYAML_free_tree(err_rc);
511 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
512 if (rc != LUSTRE_CFG_RC_NO_ERR)
513 cYAML_print_tree2file(stderr, err_rc);
515 cYAML_free_tree(err_rc);
520 static int jt_set_rtr_sensitivity(int argc, char **argv)
524 struct cYAML *err_rc = NULL;
526 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
530 rc = parse_long(argv[1], &value);
532 cYAML_build_error(-1, -1, "parser", "set",
533 "cannot parse router sensitivity value", &err_rc);
534 cYAML_print_tree2file(stderr, err_rc);
535 cYAML_free_tree(err_rc);
539 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
540 if (rc != LUSTRE_CFG_RC_NO_ERR)
541 cYAML_print_tree2file(stderr, err_rc);
543 cYAML_free_tree(err_rc);
548 static int jt_set_hsensitivity(int argc, char **argv)
552 struct cYAML *err_rc = NULL;
554 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
558 rc = parse_long(argv[1], &value);
560 cYAML_build_error(-1, -1, "parser", "set",
561 "cannot parse health sensitivity value", &err_rc);
562 cYAML_print_tree2file(stderr, err_rc);
563 cYAML_free_tree(err_rc);
567 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
568 if (rc != LUSTRE_CFG_RC_NO_ERR)
569 cYAML_print_tree2file(stderr, err_rc);
571 cYAML_free_tree(err_rc);
576 static int jt_reset_stats(int argc, char **argv)
579 struct cYAML *err_rc = NULL;
581 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
585 rc = lustre_lnet_reset_stats(-1, &err_rc);
586 if (rc != LUSTRE_CFG_RC_NO_ERR)
587 cYAML_print_tree2file(stderr, err_rc);
589 cYAML_free_tree(err_rc);
594 static int jt_set_transaction_to(int argc, char **argv)
598 struct cYAML *err_rc = NULL;
600 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
604 rc = parse_long(argv[1], &value);
606 cYAML_build_error(-1, -1, "parser", "set",
607 "cannot parse transaction timeout value", &err_rc);
608 cYAML_print_tree2file(stderr, err_rc);
609 cYAML_free_tree(err_rc);
613 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
614 if (rc != LUSTRE_CFG_RC_NO_ERR)
615 cYAML_print_tree2file(stderr, err_rc);
617 cYAML_free_tree(err_rc);
622 static int jt_set_retry_count(int argc, char **argv)
626 struct cYAML *err_rc = NULL;
628 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
632 rc = parse_long(argv[1], &value);
634 cYAML_build_error(-1, -1, "parser", "set",
635 "cannot parse retry_count value", &err_rc);
636 cYAML_print_tree2file(stderr, err_rc);
637 cYAML_free_tree(err_rc);
641 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
642 if (rc != LUSTRE_CFG_RC_NO_ERR)
643 cYAML_print_tree2file(stderr, err_rc);
645 cYAML_free_tree(err_rc);
650 static int jt_set_discovery(int argc, char **argv)
654 struct cYAML *err_rc = NULL;
656 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
660 rc = parse_long(argv[1], &value);
662 cYAML_build_error(-1, -1, "parser", "set",
663 "cannot parse discovery value", &err_rc);
664 cYAML_print_tree2file(stderr, err_rc);
665 cYAML_free_tree(err_rc);
669 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
670 if (rc != LUSTRE_CFG_RC_NO_ERR)
671 cYAML_print_tree2file(stderr, err_rc);
673 cYAML_free_tree(err_rc);
678 static int jt_set_drop_asym_route(int argc, char **argv)
682 struct cYAML *err_rc = NULL;
684 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
688 rc = parse_long(argv[1], &value);
690 cYAML_build_error(-1, -1, "parser", "set",
691 "cannot parse drop_asym_route value",
693 cYAML_print_tree2file(stderr, err_rc);
694 cYAML_free_tree(err_rc);
698 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
699 if (rc != LUSTRE_CFG_RC_NO_ERR)
700 cYAML_print_tree2file(stderr, err_rc);
702 cYAML_free_tree(err_rc);
707 static int jt_set_tiny(int argc, char **argv)
711 struct cYAML *err_rc = NULL;
713 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
717 rc = parse_long(argv[1], &value);
719 cYAML_build_error(-1, -1, "parser", "set",
720 "cannot parse tiny_buffers value", &err_rc);
721 cYAML_print_tree2file(stderr, err_rc);
722 cYAML_free_tree(err_rc);
726 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
727 if (rc != LUSTRE_CFG_RC_NO_ERR)
728 cYAML_print_tree2file(stderr, err_rc);
730 cYAML_free_tree(err_rc);
735 static int jt_set_small(int argc, char **argv)
739 struct cYAML *err_rc = NULL;
741 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
745 rc = parse_long(argv[1], &value);
747 cYAML_build_error(-1, -1, "parser", "set",
748 "cannot parse small_buffers value", &err_rc);
749 cYAML_print_tree2file(stderr, err_rc);
750 cYAML_free_tree(err_rc);
754 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
755 if (rc != LUSTRE_CFG_RC_NO_ERR)
756 cYAML_print_tree2file(stderr, err_rc);
758 cYAML_free_tree(err_rc);
763 static int jt_set_large(int argc, char **argv)
767 struct cYAML *err_rc = NULL;
769 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
773 rc = parse_long(argv[1], &value);
775 cYAML_build_error(-1, -1, "parser", "set",
776 "cannot parse large_buffers value", &err_rc);
777 cYAML_print_tree2file(stderr, err_rc);
778 cYAML_free_tree(err_rc);
782 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
783 if (rc != LUSTRE_CFG_RC_NO_ERR)
784 cYAML_print_tree2file(stderr, err_rc);
786 cYAML_free_tree(err_rc);
791 static int jt_set_routing(int argc, char **argv)
794 struct cYAML *err_rc = NULL;
797 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
801 rc = parse_long(argv[1], &value);
802 if (rc != 0 || (value != 0 && value != 1)) {
803 cYAML_build_error(-1, -1, "parser", "set",
804 "cannot parse routing value.\n"
805 "must be 0 for disable or 1 for enable",
807 cYAML_print_tree2file(stderr, err_rc);
808 cYAML_free_tree(err_rc);
812 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
814 if (rc != LUSTRE_CFG_RC_NO_ERR)
815 cYAML_print_tree2file(stderr, err_rc);
817 cYAML_free_tree(err_rc);
822 static int jt_config_lnet(int argc, char **argv)
824 struct cYAML *err_rc = NULL;
825 bool load_mod_params = false;
828 const char *const short_options = "a";
829 static const struct option long_options[] = {
830 { .name = "all", .has_arg = no_argument, .val = 'a' },
834 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
838 while ((opt = getopt_long(argc, argv, short_options,
839 long_options, NULL)) != -1) {
842 load_mod_params = true;
849 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
852 if (rc != LUSTRE_CFG_RC_NO_ERR)
853 cYAML_print_tree2file(stderr, err_rc);
855 cYAML_free_tree(err_rc);
860 static int jt_unconfig_lnet(int argc, char **argv)
862 struct cYAML *err_rc = NULL;
865 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
869 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
871 if (rc != LUSTRE_CFG_RC_NO_ERR)
872 cYAML_print_tree2file(stderr, err_rc);
874 cYAML_free_tree(err_rc);
878 static int jt_add_route(int argc, char **argv)
880 char *network = NULL, *gateway = NULL;
881 long int hop = -1, prio = -1, sen = -1;
882 struct cYAML *err_rc = NULL;
885 const char *const short_options = "n:g:c:p:";
886 static const struct option long_options[] = {
887 { .name = "net", .has_arg = required_argument, .val = 'n' },
888 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
889 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
890 { .name = "priority", .has_arg = required_argument, .val = 'p' },
891 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
894 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
898 while ((opt = getopt_long(argc, argv, short_options,
899 long_options, NULL)) != -1) {
908 rc = parse_long(optarg, &hop);
916 rc = parse_long(optarg, &prio);
924 rc = parse_long(optarg, &sen);
933 print_help(route_cmds, "route", "add");
939 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
942 if (rc != LUSTRE_CFG_RC_NO_ERR)
943 cYAML_print_tree2file(stderr, err_rc);
945 cYAML_free_tree(err_rc);
950 static int jt_add_ni(int argc, char **argv)
953 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1;
954 struct cYAML *err_rc = NULL;
955 int rc, opt, cpt_rc = -1;
956 struct lnet_dlc_network_descr nw_descr;
957 struct cfs_expr_list *global_cpts = NULL;
958 struct lnet_ioctl_config_lnd_tunables tunables;
961 memset(&tunables, 0, sizeof(tunables));
962 lustre_lnet_init_nw_descr(&nw_descr);
964 const char *const short_options = "b:c:i:m:n:p:r:s:t:";
965 static const struct option long_options[] = {
966 { .name = "peer-buffer-credits",
967 .has_arg = required_argument, .val = 'b' },
968 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
969 { .name = "if", .has_arg = required_argument, .val = 'i' },
970 { .name = "conns-per-peer",
971 .has_arg = required_argument, .val = 'm' },
972 { .name = "net", .has_arg = required_argument, .val = 'n' },
973 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
974 { .name = "credits", .has_arg = required_argument, .val = 'r' },
975 { .name = "cpt", .has_arg = required_argument, .val = 's' },
976 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
979 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
983 while ((opt = getopt_long(argc, argv, short_options,
984 long_options, NULL)) != -1) {
987 rc = parse_long(optarg, &pbc);
995 rc = parse_long(optarg, &pc);
1003 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1005 cYAML_build_error(-1, -1, "ni", "add",
1006 "bad interface list",
1012 rc = parse_long(optarg, &cpp);
1021 nw_descr.nw_id = libcfs_str2net(optarg);
1027 rc = parse_long(optarg, &cre);
1035 cpt_rc = cfs_expr_list_parse(optarg,
1037 UINT_MAX, &global_cpts);
1040 rc = parse_long(optarg, &pto);
1048 print_help(net_cmds, "net", "add");
1054 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
1055 tunables.lt_cmn.lct_peer_timeout = pto;
1056 tunables.lt_cmn.lct_peer_tx_credits = pc;
1057 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1058 tunables.lt_cmn.lct_max_tx_credits = cre;
1062 rc = lustre_lnet_config_ni(&nw_descr,
1063 (cpt_rc == 0) ? global_cpts: NULL,
1064 ip2net, (found) ? &tunables : NULL,
1067 if (global_cpts != NULL)
1068 cfs_expr_list_free(global_cpts);
1071 if (rc != LUSTRE_CFG_RC_NO_ERR)
1072 cYAML_print_tree2file(stderr, err_rc);
1074 cYAML_free_tree(err_rc);
1079 static int jt_del_route(int argc, char **argv)
1081 char *network = NULL, *gateway = NULL;
1082 struct cYAML *err_rc = NULL;
1085 const char *const short_options = "n:g:";
1086 static const struct option long_options[] = {
1087 { .name = "net", .has_arg = required_argument, .val = 'n' },
1088 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1091 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1095 while ((opt = getopt_long(argc, argv, short_options,
1096 long_options, NULL)) != -1) {
1105 print_help(route_cmds, "route", "del");
1111 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1113 if (rc != LUSTRE_CFG_RC_NO_ERR)
1114 cYAML_print_tree2file(stderr, err_rc);
1116 cYAML_free_tree(err_rc);
1121 static int jt_del_ni(int argc, char **argv)
1123 struct cYAML *err_rc = NULL;
1125 struct lnet_dlc_network_descr nw_descr;
1127 lustre_lnet_init_nw_descr(&nw_descr);
1129 const char *const short_options = "n:i:";
1130 static const struct option long_options[] = {
1131 { .name = "net", .has_arg = required_argument, .val = 'n' },
1132 { .name = "if", .has_arg = required_argument, .val = 'i' },
1135 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1139 while ((opt = getopt_long(argc, argv, short_options,
1140 long_options, NULL)) != -1) {
1143 nw_descr.nw_id = libcfs_str2net(optarg);
1146 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1148 cYAML_build_error(-1, -1, "ni", "add",
1149 "bad interface list",
1155 print_help(net_cmds, "net", "del");
1161 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1164 if (rc != LUSTRE_CFG_RC_NO_ERR)
1165 cYAML_print_tree2file(stderr, err_rc);
1167 cYAML_free_tree(err_rc);
1172 static int jt_show_route(int argc, char **argv)
1174 char *network = NULL, *gateway = NULL;
1175 long int hop = -1, prio = -1;
1176 int detail = 0, rc, opt;
1177 struct cYAML *err_rc = NULL, *show_rc = NULL;
1179 const char *const short_options = "n:g:h:p:v";
1180 static const struct option long_options[] = {
1181 { .name = "net", .has_arg = required_argument, .val = 'n' },
1182 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1183 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1184 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1185 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1188 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1192 while ((opt = getopt_long(argc, argv, short_options,
1193 long_options, NULL)) != -1) {
1202 rc = parse_long(optarg, &hop);
1210 rc = parse_long(optarg, &prio);
1221 print_help(route_cmds, "route", "show");
1227 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1228 &show_rc, &err_rc, false);
1230 if (rc != LUSTRE_CFG_RC_NO_ERR)
1231 cYAML_print_tree2file(stderr, err_rc);
1233 cYAML_print_tree(show_rc);
1235 cYAML_free_tree(err_rc);
1236 cYAML_free_tree(show_rc);
1241 static int set_value_helper(int argc, char **argv,
1242 int (*cb)(int, bool, char*, int, struct cYAML**))
1245 long int healthv = -1;
1248 struct cYAML *err_rc = NULL;
1250 const char *const short_options = "t:n:a";
1251 static const struct option long_options[] = {
1252 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1253 { .name = "health", .has_arg = required_argument, .val = 't' },
1254 { .name = "all", .has_arg = no_argument, .val = 'a' },
1257 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1261 while ((opt = getopt_long(argc, argv, short_options,
1262 long_options, NULL)) != -1) {
1268 if (parse_long(optarg, &healthv) != 0)
1279 rc = cb(healthv, all, nid, -1, &err_rc);
1281 if (rc != LUSTRE_CFG_RC_NO_ERR)
1282 cYAML_print_tree2file(stderr, err_rc);
1284 cYAML_free_tree(err_rc);
1289 static int jt_set_ni_value(int argc, char **argv)
1292 long int healthv = -1, cpp = -1;
1295 struct cYAML *err_rc = NULL;
1297 const char *const short_options = "a:m:n:t:";
1298 static const struct option long_options[] = {
1299 { .name = "all", .has_arg = no_argument, .val = 'a' },
1300 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
1301 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1302 { .name = "health", .has_arg = required_argument, .val = 't' },
1305 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1309 while ((opt = getopt_long(argc, argv, short_options,
1310 long_options, NULL)) != -1) {
1316 rc = parse_long(optarg, &cpp);
1327 if (parse_long(optarg, &healthv) != 0) {
1339 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
1342 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
1345 if (rc != LUSTRE_CFG_RC_NO_ERR)
1346 cYAML_print_tree2file(stderr, err_rc);
1348 cYAML_free_tree(err_rc);
1353 static int jt_set_peer_ni_value(int argc, char **argv)
1355 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1358 static int jt_show_recovery(int argc, char **argv)
1361 struct cYAML *err_rc = NULL, *show_rc = NULL;
1363 const char *const short_options = "lp";
1364 static const struct option long_options[] = {
1365 { .name = "local", .has_arg = no_argument, .val = 'l' },
1366 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1369 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1373 while ((opt = getopt_long(argc, argv, short_options,
1374 long_options, NULL)) != -1) {
1377 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1380 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1387 if (rc != LUSTRE_CFG_RC_NO_ERR)
1388 cYAML_print_tree2file(stderr, err_rc);
1390 cYAML_print_tree(show_rc);
1392 cYAML_free_tree(err_rc);
1393 cYAML_free_tree(show_rc);
1398 static int jt_show_net(int argc, char **argv)
1400 char *network = NULL;
1402 struct cYAML *err_rc = NULL, *show_rc = NULL;
1403 long int detail = 0;
1405 const char *const short_options = "n:v";
1406 static const struct option long_options[] = {
1407 { .name = "net", .has_arg = required_argument, .val = 'n' },
1408 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1411 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1415 while ((opt = getopt_long(argc, argv, short_options,
1416 long_options, NULL)) != -1) {
1422 if ((!optarg) && (argv[optind] != NULL) &&
1423 (argv[optind][0] != '-')) {
1424 if (parse_long(argv[optind++], &detail) != 0)
1431 print_help(net_cmds, "net", "show");
1437 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1440 if (rc != LUSTRE_CFG_RC_NO_ERR)
1441 cYAML_print_tree2file(stderr, err_rc);
1443 cYAML_print_tree(show_rc);
1445 cYAML_free_tree(err_rc);
1446 cYAML_free_tree(show_rc);
1451 static int jt_show_routing(int argc, char **argv)
1453 struct cYAML *err_rc = NULL, *show_rc = NULL;
1456 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1460 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1462 if (rc != LUSTRE_CFG_RC_NO_ERR)
1463 cYAML_print_tree2file(stderr, err_rc);
1465 cYAML_print_tree(show_rc);
1467 cYAML_free_tree(err_rc);
1468 cYAML_free_tree(show_rc);
1473 static int jt_show_stats(int argc, char **argv)
1476 struct cYAML *show_rc = NULL, *err_rc = NULL;
1478 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1482 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1484 if (rc != LUSTRE_CFG_RC_NO_ERR)
1485 cYAML_print_tree2file(stderr, err_rc);
1487 cYAML_print_tree(show_rc);
1489 cYAML_free_tree(err_rc);
1490 cYAML_free_tree(show_rc);
1495 static int jt_show_udsp(int argc, char **argv)
1499 struct cYAML *err_rc = NULL, *show_rc = NULL;
1501 const char *const short_options = "i:";
1502 static const struct option long_options[] = {
1503 { .name = "idx", .has_arg = required_argument, .val = 'i' },
1507 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
1511 while ((opt = getopt_long(argc, argv, short_options,
1512 long_options, NULL)) != -1) {
1518 print_help(net_cmds, "net", "show");
1524 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
1526 if (rc != LUSTRE_CFG_RC_NO_ERR)
1527 cYAML_print_tree2file(stderr, err_rc);
1529 cYAML_print_tree(show_rc);
1531 cYAML_free_tree(err_rc);
1532 cYAML_free_tree(show_rc);
1537 static int jt_show_global(int argc, char **argv)
1540 struct cYAML *show_rc = NULL, *err_rc = NULL;
1542 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1546 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1547 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1548 cYAML_print_tree2file(stderr, err_rc);
1552 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1553 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1554 cYAML_print_tree2file(stderr, err_rc);
1558 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1559 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1560 cYAML_print_tree2file(stderr, err_rc);
1564 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1565 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1566 cYAML_print_tree2file(stderr, err_rc);
1570 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1571 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1572 cYAML_print_tree2file(stderr, err_rc);
1576 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1577 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1578 cYAML_print_tree2file(stderr, err_rc);
1582 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1583 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1584 cYAML_print_tree2file(stderr, err_rc);
1588 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1589 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1590 cYAML_print_tree2file(stderr, err_rc);
1594 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1595 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1596 cYAML_print_tree2file(stderr, err_rc);
1600 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1601 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1602 cYAML_print_tree2file(stderr, err_rc);
1606 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1607 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1608 cYAML_print_tree2file(stderr, err_rc);
1612 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1613 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1614 cYAML_print_tree2file(stderr, err_rc);
1619 cYAML_print_tree(show_rc);
1622 cYAML_free_tree(err_rc);
1623 cYAML_free_tree(show_rc);
1628 static int jt_lnet(int argc, char **argv)
1632 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1636 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1639 static int jt_route(int argc, char **argv)
1643 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1647 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1650 static int jt_net(int argc, char **argv)
1654 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1658 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1661 static int jt_routing(int argc, char **argv)
1665 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1669 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1672 static int jt_stats(int argc, char **argv)
1676 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1680 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1683 static int jt_debug(int argc, char **argv)
1687 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1691 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1694 static int jt_global(int argc, char **argv)
1698 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1702 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1705 static int jt_peers(int argc, char **argv)
1709 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1713 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1716 static int jt_set(int argc, char **argv)
1720 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1724 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1727 static int jt_udsp(int argc, char **argv)
1731 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1735 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1738 static int jt_import(int argc, char **argv)
1741 struct cYAML *err_rc = NULL;
1742 struct cYAML *show_rc = NULL;
1743 int rc = 0, return_rc = 0, opt, opt_found = 0;
1746 const char *const short_options = "adseh";
1747 static const struct option long_options[] = {
1748 { .name = "add", .has_arg = no_argument, .val = 'a' },
1749 { .name = "del", .has_arg = no_argument, .val = 'd' },
1750 { .name = "show", .has_arg = no_argument, .val = 's' },
1751 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1752 { .name = "help", .has_arg = no_argument, .val = 'h' },
1755 while ((opt = getopt_long(argc, argv, short_options,
1756 long_options, NULL)) != -1) {
1770 printf("import FILE\n"
1771 "import < FILE : import a file\n"
1772 "\t--add: add configuration\n"
1773 "\t--del: delete configuration\n"
1774 "\t--show: show configuration\n"
1775 "\t--exec: execute command\n"
1776 "\t--help: display this help\n"
1777 "If no command option is given then --add"
1778 " is assumed by default\n");
1785 /* grab the file name if one exists */
1786 if (opt_found && argc == 3)
1788 else if (!opt_found && argc == 2)
1793 rc = lustre_yaml_config(file, &err_rc);
1794 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1795 cYAML_print_tree(show_rc);
1796 cYAML_free_tree(show_rc);
1799 rc = lustre_yaml_del(file, &err_rc);
1802 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1803 cYAML_print_tree(show_rc);
1804 cYAML_free_tree(show_rc);
1807 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1808 cYAML_print_tree(show_rc);
1809 cYAML_free_tree(show_rc);
1813 if (rc || return_rc) {
1814 cYAML_print_tree2file(stderr, err_rc);
1815 cYAML_free_tree(err_rc);
1821 static int jt_export(int argc, char **argv)
1823 struct cYAML *show_rc = NULL;
1824 struct cYAML *err_rc = NULL;
1828 bool backup = false;
1831 const char *const short_options = "bh";
1832 static const struct option long_options[] = {
1833 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1834 { .name = "help", .has_arg = no_argument, .val = 'h' },
1837 while ((opt = getopt_long(argc, argv, short_options,
1838 long_options, NULL)) != -1) {
1845 printf("export > FILE.yaml : export configuration\n"
1846 "\t--backup: export only what's necessary for reconfig\n"
1847 "\t--help: display this help\n");
1852 if (backup && argc >= 3)
1854 else if (!backup && argc >= 2)
1860 f = fopen(file, "w");
1865 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1866 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1867 cYAML_print_tree2file(stderr, err_rc);
1868 cYAML_free_tree(err_rc);
1872 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_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_routing(-1, &show_rc, &err_rc, backup);
1881 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1882 cYAML_print_tree2file(stderr, err_rc);
1883 cYAML_free_tree(err_rc);
1887 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1888 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1889 cYAML_print_tree2file(stderr, err_rc);
1890 cYAML_free_tree(err_rc);
1894 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1895 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1896 cYAML_print_tree2file(stderr, err_rc);
1897 cYAML_free_tree(err_rc);
1901 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1902 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1903 cYAML_print_tree2file(stderr, err_rc);
1904 cYAML_free_tree(err_rc);
1908 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1909 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1910 cYAML_print_tree2file(stderr, err_rc);
1911 cYAML_free_tree(err_rc);
1915 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1916 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1917 cYAML_print_tree2file(stderr, err_rc);
1918 cYAML_free_tree(err_rc);
1922 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1923 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1924 cYAML_print_tree2file(stderr, err_rc);
1928 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1929 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1930 cYAML_print_tree2file(stderr, err_rc);
1934 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1935 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1936 cYAML_print_tree2file(stderr, err_rc);
1940 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1941 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1942 cYAML_print_tree2file(stderr, err_rc);
1946 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1947 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1948 cYAML_print_tree2file(stderr, err_rc);
1952 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1953 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1954 cYAML_print_tree2file(stderr, err_rc);
1958 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1959 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1960 cYAML_print_tree2file(stderr, err_rc);
1961 cYAML_free_tree(err_rc);
1965 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1966 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1967 cYAML_print_tree2file(stderr, err_rc);
1968 cYAML_free_tree(err_rc);
1972 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
1973 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1974 cYAML_print_tree2file(stderr, err_rc);
1975 cYAML_free_tree(err_rc);
1979 if (show_rc != NULL) {
1980 cYAML_print_tree2file(f, show_rc);
1981 cYAML_free_tree(show_rc);
1990 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1992 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1994 char *prim_nid = NULL, *nidstr = NULL;
1995 char err_str[LNET_MAX_STR_LEN] = "Error";
1996 struct cYAML *err_rc = NULL;
1998 const char *const short_opts = "k:mn:";
1999 const struct option long_opts[] = {
2000 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2001 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2002 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2005 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2009 while ((opt = getopt_long(argc, argv, short_opts,
2010 long_opts, NULL)) != -1) {
2019 if (cmd == LNETCTL_DEL_CMD) {
2020 rc = LUSTRE_CFG_RC_BAD_PARAM;
2021 snprintf(err_str, LNET_MAX_STR_LEN,
2022 "Unrecognized option '-%c'", opt);
2028 print_help(peer_cmds, "peer",
2029 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2035 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2037 if (rc != LUSTRE_CFG_RC_NO_ERR)
2041 cYAML_build_error(rc, -1, "peer",
2042 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2046 if (rc != LUSTRE_CFG_RC_NO_ERR)
2047 cYAML_print_tree2file(stderr, err_rc);
2049 cYAML_free_tree(err_rc);
2054 static int jt_add_peer_nid(int argc, char **argv)
2056 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2059 static int jt_del_peer_nid(int argc, char **argv)
2061 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2064 static int jt_show_peer(int argc, char **argv)
2068 struct cYAML *err_rc = NULL, *show_rc = NULL;
2069 long int detail = 0;
2071 const char *const short_opts = "hn:v::";
2072 const struct option long_opts[] = {
2073 { .name = "help", .has_arg = no_argument, .val = 'h' },
2074 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2075 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2078 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2082 while ((opt = getopt_long(argc, argv, short_opts,
2083 long_opts, NULL)) != -1) {
2089 if ((!optarg) && (argv[optind] != NULL) &&
2090 (argv[optind][0] != '-')) {
2091 if (parse_long(argv[optind++], &detail) != 0)
2098 print_help(peer_cmds, "peer", "show");
2104 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2107 if (rc != LUSTRE_CFG_RC_NO_ERR)
2108 cYAML_print_tree2file(stderr, err_rc);
2110 cYAML_print_tree(show_rc);
2112 cYAML_free_tree(err_rc);
2113 cYAML_free_tree(show_rc);
2118 static int jt_list_peer(int argc, char **argv)
2121 struct cYAML *err_rc = NULL, *list_rc = NULL;
2123 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2127 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2129 if (rc != LUSTRE_CFG_RC_NO_ERR)
2130 cYAML_print_tree2file(stderr, err_rc);
2132 cYAML_print_tree(list_rc);
2134 cYAML_free_tree(err_rc);
2135 cYAML_free_tree(list_rc);
2140 static int jt_ping(int argc, char **argv)
2142 struct cYAML *err_rc = NULL;
2143 struct cYAML *show_rc = NULL;
2147 const char *const short_options = "ht:";
2148 const struct option long_options[] = {
2149 { .name = "help", .has_arg = no_argument, .val = 'h' },
2150 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2153 while ((opt = getopt_long(argc, argv, short_options,
2154 long_options, NULL)) != -1) {
2157 timeout = 1000 * atol(optarg);
2160 printf("ping nid[,nid,...]\n"
2161 "\t --timeout: ping timeout\n"
2162 "\t --help: display this help\n");
2169 for (; optind < argc; optind++)
2170 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
2173 cYAML_print_tree(show_rc);
2176 cYAML_print_tree2file(stderr, err_rc);
2178 cYAML_free_tree(err_rc);
2179 cYAML_free_tree(show_rc);
2184 static int jt_discover(int argc, char **argv)
2186 struct cYAML *err_rc = NULL;
2187 struct cYAML *show_rc = NULL;
2191 const char *const short_options = "fh";
2192 const struct option long_options[] = {
2193 { .name = "force", .has_arg = no_argument, .val = 'f' },
2194 { .name = "help", .has_arg = no_argument, .val = 'h' },
2197 while ((opt = getopt_long(argc, argv, short_options,
2198 long_options, NULL)) != -1) {
2204 printf("discover nid[,nid,...]\n"
2205 "\t --force: force discovery\n"
2206 "\t --help: display this help\n");
2213 for (; optind < argc; optind++)
2214 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2218 cYAML_print_tree(show_rc);
2221 cYAML_print_tree2file(stderr, err_rc);
2223 cYAML_free_tree(err_rc);
2224 cYAML_free_tree(show_rc);
2229 static int jt_add_udsp(int argc, char **argv)
2231 char *src = NULL, *dst = NULL, *rte = NULL;
2232 struct cYAML *err_rc = NULL;
2233 union lnet_udsp_action udsp_action;
2234 long int idx = -1, priority = -1;
2236 char *action_type = "pref";
2238 const char *const short_options = "s:d:r:p:i:";
2239 static const struct option long_options[] = {
2240 { .name = "src", .has_arg = required_argument, .val = 's' },
2241 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2242 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2243 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2244 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2247 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2251 while ((opt = getopt_long(argc, argv, short_options,
2252 long_options, NULL)) != -1) {
2264 rc = parse_long(optarg, &priority);
2267 action_type = "priority";
2268 udsp_action.udsp_priority = priority;
2271 rc = parse_long(optarg, &idx);
2276 print_help(udsp_cmds, "udsp", "add");
2282 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2285 if (rc != LUSTRE_CFG_RC_NO_ERR)
2286 cYAML_print_tree2file(stderr, err_rc);
2288 cYAML_free_tree(err_rc);
2293 static int jt_del_udsp(int argc, char **argv)
2295 struct cYAML *err_rc = NULL;
2299 const char *const short_options = "i:";
2300 static const struct option long_options[] = {
2301 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2304 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2308 while ((opt = getopt_long(argc, argv, short_options,
2309 long_options, NULL)) != -1) {
2312 rc = parse_long(optarg, &idx);
2317 print_help(udsp_cmds, "udsp", "add");
2323 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2324 if (rc != LUSTRE_CFG_RC_NO_ERR)
2325 cYAML_print_tree2file(stderr, err_rc);
2327 cYAML_free_tree(err_rc);
2332 static int lnetctl_list_commands(int argc, char **argv)
2334 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2336 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2341 int main(int argc, char **argv)
2344 struct cYAML *err_rc = NULL;
2346 rc = lustre_lnet_config_lib_init();
2348 cYAML_build_error(-1, -1, "lnetctl", "startup",
2349 "cannot register LNet device", &err_rc);
2350 cYAML_print_tree2file(stderr, err_rc);
2354 Parser_init("lnetctl > ", cmd_list);
2356 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);