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);
93 static int jt_setup_mrrouting(int argc, char **argv);
95 command_t cmd_list[] = {
96 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
97 {"route", jt_route, 0, "route {add | del | show | help}"},
98 {"net", jt_net, 0, "net {add | del | show | set | help}"},
99 {"routing", jt_routing, 0, "routing {show | help}"},
100 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
101 " | routing | numa_range | max_interfaces"
102 " | discovery | drop_asym_route | retry_count"
103 " | transaction_timeout | health_sensitivity"
104 " | recovery_interval | router_sensitivity"
105 " | response_tracking | recovery_limit}"},
106 {"import", jt_import, 0, "import FILE.yaml"},
107 {"export", jt_export, 0, "export FILE.yaml"},
108 {"stats", jt_stats, 0, "stats {show | help}"},
109 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
110 {"global", jt_global, 0, "global {show | help}"},
111 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
112 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
113 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
114 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
115 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
116 {"setup-mrrouting", jt_setup_mrrouting, 0,
117 "setup linux routing tables\n"},
118 {"help", Parser_help, 0, "help"},
119 {"exit", Parser_quit, 0, "quit"},
120 {"quit", Parser_quit, 0, "quit"},
121 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
125 command_t lnet_cmds[] = {
126 {"configure", jt_config_lnet, 0, "configure lnet\n"
127 "\t--all: load NI configuration from module parameters\n"},
128 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
132 command_t route_cmds[] = {
133 {"add", jt_add_route, 0, "add a route\n"
134 "\t--net: net name (e.g. tcp0)\n"
135 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
136 "\t--hop: number to final destination (1 < hops < 255)\n"
137 "\t--priority: priority of route (0 - highest prio\n"
138 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
139 {"del", jt_del_route, 0, "delete a route\n"
140 "\t--net: net name (e.g. tcp0)\n"
141 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
142 {"show", jt_show_route, 0, "show routes\n"
143 "\t--net: net name (e.g. tcp0) to filter on\n"
144 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
145 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
146 "\t--priority: priority of route (0 - highest prio to filter on\n"
147 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
148 "\t--verbose: display detailed output per route\n"},
152 command_t net_cmds[] = {
153 {"add", jt_add_ni, 0, "add a network\n"
154 "\t--net: net name (e.g. tcp0)\n"
155 "\t--if: physical interface (e.g. eth0)\n"
156 "\t--ip2net: specify networks based on IP address patterns\n"
157 "\t--peer-timeout: time to wait before declaring a peer dead\n"
158 "\t--peer-credits: define the max number of inflight messages\n"
159 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
160 "\t--credits: Network Interface credits\n"
161 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
162 "\t--conns-per-peer: number of connections per peer\n"
163 "\t--skip-mr-route-setup: do not add linux route for the ni\n"},
164 {"del", jt_del_ni, 0, "delete a network\n"
165 "\t--net: net name (e.g. tcp0)\n"
166 "\t--if: physical interface (e.g. eth0)\n"},
167 {"show", jt_show_net, 0, "show networks\n"
168 "\t--net: net name (e.g. tcp0) to filter on\n"
169 "\t--verbose: display detailed output per network."
170 " Optional argument of '2' outputs more stats\n"},
171 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
172 "\t--nid: NI NID to set the\n"
173 "\t--health: specify health value to set\n"
174 "\t--conns-per-peer: number of connections per peer\n"
175 "\t--all: set all NIs value to the one specified\n"},
179 command_t routing_cmds[] = {
180 {"show", jt_show_routing, 0, "show routing information\n"},
184 command_t stats_cmds[] = {
185 {"show", jt_show_stats, 0, "show LNET statistics\n"},
186 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
190 command_t debug_cmds[] = {
191 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
192 "\t--local : list local recovery queue\n"
193 "\t--peer : list peer recovery queue\n"},
197 command_t global_cmds[] = {
198 {"show", jt_show_global, 0, "show global variables\n"},
202 command_t set_cmds[] = {
203 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
204 "\tVALUE must be greater than 0\n"},
205 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
206 "\tVALUE must be greater than 0\n"},
207 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
208 "\tVALUE must be greater than 0\n"},
209 {"routing", jt_set_routing, 0, "enable/disable routing\n"
210 "\t0 - disable routing\n"
211 "\t1 - enable routing\n"},
212 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
213 "\tVALUE must be at least 0\n"},
214 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
216 "\tValue must be greater than 16\n"},
217 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
218 "\t0 - disable peer discovery\n"
219 "\t1 - enable peer discovery (default)\n"},
220 {"drop_asym_route", jt_set_drop_asym_route, 0,
221 "drop/accept asymmetrical route messages\n"
222 "\t0 - accept asymmetrical route messages (default)\n"
223 "\t1 - drop asymmetrical route messages\n"},
224 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
225 "\t0 - turn of retries\n"
226 "\t>0 - number of retries\n"},
227 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
228 "\t>0 - timeout in seconds\n"},
229 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
230 "\t0 - turn off health evaluation\n"
231 "\t>0 - sensitivity value not more than 1000\n"},
232 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
233 "\t>0 - time in seconds between pings\n"},
234 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
235 "\t100 - router interfaces need to be fully healthy to be used\n"
236 "\t<100 - router interfaces can be used even if not healthy\n"},
237 {"response_tracking", jt_set_response_tracking, 0,
238 "Set the behavior of response tracking\n"
239 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
240 "\t1 - GETs are eligible for response tracking\n"
241 "\t2 - PUTs are eligible for response tracking\n"
242 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
243 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
244 "\t pings and discovery pushes always utilize response tracking\n"},
245 {"recovery_limit", jt_set_recovery_limit, 0,
246 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
247 "\t0 - Recover indefinitely (default)\n"
248 "\t>0 - Recover for the specified number of seconds.\n"},
252 command_t peer_cmds[] = {
253 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
254 "\t--prim_nid: Primary NID of the peer.\n"
255 "\t--nid: one or more peer NIDs\n"
256 "\t--non_mr: create this peer as not Multi-Rail capable\n"
257 "\t--ip2nets: specify a range of nids per peer"},
258 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
259 "\t--prim_nid: Primary NID of the peer.\n"
260 "\t--nid: list of NIDs to remove. If none provided,\n"
261 "\t peer is deleted\n"
262 "\t--ip2nets: specify a range of nids per peer"},
263 {"show", jt_show_peer, 0, "show peer information\n"
264 "\t--nid: NID of peer to filter on.\n"
265 "\t--verbose: display detailed output per peer."
266 " Optional argument of '2' outputs more stats\n"},
267 {"list", jt_list_peer, 0, "list all peers\n"},
268 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
269 "\t--nid: Peer NI NID to set the\n"
270 "\t--health: specify health value to set\n"
271 "\t--all: set all peer_nis values to the one specified\n"},
275 command_t udsp_cmds[] = {
276 {"add", jt_add_udsp, 0, "add a udsp\n"
277 "\t--src: ip2nets syntax specifying the local NID to match\n"
278 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
279 "\t--rte: ip2nets syntax specifying the router NID to match\n"
280 "\t--priority: priority value (0 - highest priority)\n"
281 "\t--idx: index of where to insert the rule.\n"
282 "\t By default, appends to the end of the rule list.\n"},
283 {"del", jt_del_udsp, 0, "delete a udsp\n"
284 "\t--idx: index of the Policy.\n"},
285 {"show", jt_show_udsp, 0, "show udsps\n"
286 "\t --idx: index of the policy to show.\n"},
290 static int jt_calc_service_id(int argc, char **argv)
295 rc = lustre_lnet_calc_service_id(&service_id);
296 if (rc != LUSTRE_CFG_RC_NO_ERR)
300 * cYAML currently doesn't support printing hex values.
301 * Therefore just print it locally here
303 printf("service id:\n value: 0x%jx\n", (uintmax_t)service_id);
308 static int jt_setup_mrrouting(int argc, char **argv)
311 struct cYAML *err_rc = NULL;
313 rc = lustre_lnet_setup_mrrouting(&err_rc);
315 if (rc != LUSTRE_CFG_RC_NO_ERR)
316 cYAML_print_tree2file(stderr, err_rc);
318 cYAML_free_tree(err_rc);
323 static inline void print_help(const command_t cmds[], const char *cmd_type,
326 const command_t *cmd;
328 for (cmd = cmds; cmd->pc_name; cmd++) {
329 if (pc_name != NULL &&
330 strcmp(cmd->pc_name, pc_name) == 0) {
331 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
334 } else if (pc_name != NULL) {
337 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
341 static int parse_long(const char *number, long int *value)
348 *value = strtol(number, &end, 0);
349 if (end != NULL && *end != 0)
355 static int check_cmd(const command_t *cmd_list, const char *cmd,
356 const char *sub_cmd, const int min_args,
357 int argc, char **argv)
364 const char *const short_options = "h";
365 static const struct option long_options[] = {
366 { .name = "help", .has_arg = no_argument, .val = 'h' },
370 if (argc < min_args) {
371 print_help(cmd_list, cmd, sub_cmd);
374 } else if (argc > 2) {
378 while ((opt = getopt_long(argc, argv, short_options,
379 long_options, NULL)) != -1) {
382 print_help(cmd_list, cmd, sub_cmd);
397 static int jt_set_response_tracking(int argc, char **argv)
401 struct cYAML *err_rc = NULL;
403 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
407 rc = parse_long(argv[1], &value);
409 cYAML_build_error(-1, -1, "parser", "set",
410 "cannot parse response_tracking value",
412 cYAML_print_tree2file(stderr, err_rc);
413 cYAML_free_tree(err_rc);
417 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
418 if (rc != LUSTRE_CFG_RC_NO_ERR)
419 cYAML_print_tree2file(stderr, err_rc);
421 cYAML_free_tree(err_rc);
426 static int jt_set_recovery_limit(int argc, char **argv)
430 struct cYAML *err_rc = NULL;
432 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
436 rc = parse_long(argv[1], &value);
438 cYAML_build_error(-1, -1, "parser", "set",
439 "cannot parse recovery_limit value",
441 cYAML_print_tree2file(stderr, err_rc);
442 cYAML_free_tree(err_rc);
446 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
447 if (rc != LUSTRE_CFG_RC_NO_ERR)
448 cYAML_print_tree2file(stderr, err_rc);
450 cYAML_free_tree(err_rc);
455 static int jt_set_max_intf(int argc, char **argv)
459 struct cYAML *err_rc = NULL;
461 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
465 rc = parse_long(argv[1], &value);
467 cYAML_build_error(-1, -1, "parser", "set",
468 "cannot parse max_interfaces value", &err_rc);
469 cYAML_print_tree2file(stderr, err_rc);
470 cYAML_free_tree(err_rc);
474 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
475 if (rc != LUSTRE_CFG_RC_NO_ERR)
476 cYAML_print_tree2file(stderr, err_rc);
478 cYAML_free_tree(err_rc);
483 static int jt_set_numa(int argc, char **argv)
487 struct cYAML *err_rc = NULL;
489 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
493 rc = parse_long(argv[1], &value);
495 cYAML_build_error(-1, -1, "parser", "set",
496 "cannot parse numa_range value", &err_rc);
497 cYAML_print_tree2file(stderr, err_rc);
498 cYAML_free_tree(err_rc);
502 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
503 if (rc != LUSTRE_CFG_RC_NO_ERR)
504 cYAML_print_tree2file(stderr, err_rc);
506 cYAML_free_tree(err_rc);
511 static int jt_set_recov_intrv(int argc, char **argv)
515 struct cYAML *err_rc = NULL;
517 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
521 rc = parse_long(argv[1], &value);
523 cYAML_build_error(-1, -1, "parser", "set",
524 "cannot parse recovery interval value", &err_rc);
525 cYAML_print_tree2file(stderr, err_rc);
526 cYAML_free_tree(err_rc);
530 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
531 if (rc != LUSTRE_CFG_RC_NO_ERR)
532 cYAML_print_tree2file(stderr, err_rc);
534 cYAML_free_tree(err_rc);
539 static int jt_set_rtr_sensitivity(int argc, char **argv)
543 struct cYAML *err_rc = NULL;
545 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
549 rc = parse_long(argv[1], &value);
551 cYAML_build_error(-1, -1, "parser", "set",
552 "cannot parse router sensitivity value", &err_rc);
553 cYAML_print_tree2file(stderr, err_rc);
554 cYAML_free_tree(err_rc);
558 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
559 if (rc != LUSTRE_CFG_RC_NO_ERR)
560 cYAML_print_tree2file(stderr, err_rc);
562 cYAML_free_tree(err_rc);
567 static int jt_set_hsensitivity(int argc, char **argv)
571 struct cYAML *err_rc = NULL;
573 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
577 rc = parse_long(argv[1], &value);
579 cYAML_build_error(-1, -1, "parser", "set",
580 "cannot parse health sensitivity value", &err_rc);
581 cYAML_print_tree2file(stderr, err_rc);
582 cYAML_free_tree(err_rc);
586 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
587 if (rc != LUSTRE_CFG_RC_NO_ERR)
588 cYAML_print_tree2file(stderr, err_rc);
590 cYAML_free_tree(err_rc);
595 static int jt_reset_stats(int argc, char **argv)
598 struct cYAML *err_rc = NULL;
600 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
604 rc = lustre_lnet_reset_stats(-1, &err_rc);
605 if (rc != LUSTRE_CFG_RC_NO_ERR)
606 cYAML_print_tree2file(stderr, err_rc);
608 cYAML_free_tree(err_rc);
613 static int jt_set_transaction_to(int argc, char **argv)
617 struct cYAML *err_rc = NULL;
619 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
623 rc = parse_long(argv[1], &value);
625 cYAML_build_error(-1, -1, "parser", "set",
626 "cannot parse transaction timeout value", &err_rc);
627 cYAML_print_tree2file(stderr, err_rc);
628 cYAML_free_tree(err_rc);
632 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
633 if (rc != LUSTRE_CFG_RC_NO_ERR)
634 cYAML_print_tree2file(stderr, err_rc);
636 cYAML_free_tree(err_rc);
641 static int jt_set_retry_count(int argc, char **argv)
645 struct cYAML *err_rc = NULL;
647 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
651 rc = parse_long(argv[1], &value);
653 cYAML_build_error(-1, -1, "parser", "set",
654 "cannot parse retry_count value", &err_rc);
655 cYAML_print_tree2file(stderr, err_rc);
656 cYAML_free_tree(err_rc);
660 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
661 if (rc != LUSTRE_CFG_RC_NO_ERR)
662 cYAML_print_tree2file(stderr, err_rc);
664 cYAML_free_tree(err_rc);
669 static int jt_set_discovery(int argc, char **argv)
673 struct cYAML *err_rc = NULL;
675 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
679 rc = parse_long(argv[1], &value);
681 cYAML_build_error(-1, -1, "parser", "set",
682 "cannot parse discovery value", &err_rc);
683 cYAML_print_tree2file(stderr, err_rc);
684 cYAML_free_tree(err_rc);
688 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
689 if (rc != LUSTRE_CFG_RC_NO_ERR)
690 cYAML_print_tree2file(stderr, err_rc);
692 cYAML_free_tree(err_rc);
697 static int jt_set_drop_asym_route(int argc, char **argv)
701 struct cYAML *err_rc = NULL;
703 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
707 rc = parse_long(argv[1], &value);
709 cYAML_build_error(-1, -1, "parser", "set",
710 "cannot parse drop_asym_route value",
712 cYAML_print_tree2file(stderr, err_rc);
713 cYAML_free_tree(err_rc);
717 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
718 if (rc != LUSTRE_CFG_RC_NO_ERR)
719 cYAML_print_tree2file(stderr, err_rc);
721 cYAML_free_tree(err_rc);
726 static int jt_set_tiny(int argc, char **argv)
730 struct cYAML *err_rc = NULL;
732 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
736 rc = parse_long(argv[1], &value);
738 cYAML_build_error(-1, -1, "parser", "set",
739 "cannot parse tiny_buffers value", &err_rc);
740 cYAML_print_tree2file(stderr, err_rc);
741 cYAML_free_tree(err_rc);
745 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
746 if (rc != LUSTRE_CFG_RC_NO_ERR)
747 cYAML_print_tree2file(stderr, err_rc);
749 cYAML_free_tree(err_rc);
754 static int jt_set_small(int argc, char **argv)
758 struct cYAML *err_rc = NULL;
760 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
764 rc = parse_long(argv[1], &value);
766 cYAML_build_error(-1, -1, "parser", "set",
767 "cannot parse small_buffers value", &err_rc);
768 cYAML_print_tree2file(stderr, err_rc);
769 cYAML_free_tree(err_rc);
773 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
774 if (rc != LUSTRE_CFG_RC_NO_ERR)
775 cYAML_print_tree2file(stderr, err_rc);
777 cYAML_free_tree(err_rc);
782 static int jt_set_large(int argc, char **argv)
786 struct cYAML *err_rc = NULL;
788 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
792 rc = parse_long(argv[1], &value);
794 cYAML_build_error(-1, -1, "parser", "set",
795 "cannot parse large_buffers value", &err_rc);
796 cYAML_print_tree2file(stderr, err_rc);
797 cYAML_free_tree(err_rc);
801 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
802 if (rc != LUSTRE_CFG_RC_NO_ERR)
803 cYAML_print_tree2file(stderr, err_rc);
805 cYAML_free_tree(err_rc);
810 static int jt_set_routing(int argc, char **argv)
813 struct cYAML *err_rc = NULL;
816 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
820 rc = parse_long(argv[1], &value);
821 if (rc != 0 || (value != 0 && value != 1)) {
822 cYAML_build_error(-1, -1, "parser", "set",
823 "cannot parse routing value.\n"
824 "must be 0 for disable or 1 for enable",
826 cYAML_print_tree2file(stderr, err_rc);
827 cYAML_free_tree(err_rc);
831 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
833 if (rc != LUSTRE_CFG_RC_NO_ERR)
834 cYAML_print_tree2file(stderr, err_rc);
836 cYAML_free_tree(err_rc);
841 static int jt_config_lnet(int argc, char **argv)
843 struct cYAML *err_rc = NULL;
844 bool load_mod_params = false;
847 const char *const short_options = "a";
848 static const struct option long_options[] = {
849 { .name = "all", .has_arg = no_argument, .val = 'a' },
853 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
857 while ((opt = getopt_long(argc, argv, short_options,
858 long_options, NULL)) != -1) {
861 load_mod_params = true;
868 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
871 if (rc != LUSTRE_CFG_RC_NO_ERR)
872 cYAML_print_tree2file(stderr, err_rc);
874 cYAML_free_tree(err_rc);
879 static int jt_unconfig_lnet(int argc, char **argv)
881 struct cYAML *err_rc = NULL;
884 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
888 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
890 if (rc != LUSTRE_CFG_RC_NO_ERR)
891 cYAML_print_tree2file(stderr, err_rc);
893 cYAML_free_tree(err_rc);
897 static int jt_add_route(int argc, char **argv)
899 char *network = NULL, *gateway = NULL;
900 long int hop = -1, prio = -1, sen = -1;
901 struct cYAML *err_rc = NULL;
904 const char *const short_options = "n:g:c:p:";
905 static const struct option long_options[] = {
906 { .name = "net", .has_arg = required_argument, .val = 'n' },
907 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
908 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
909 { .name = "priority", .has_arg = required_argument, .val = 'p' },
910 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
913 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
917 while ((opt = getopt_long(argc, argv, short_options,
918 long_options, NULL)) != -1) {
927 rc = parse_long(optarg, &hop);
935 rc = parse_long(optarg, &prio);
943 rc = parse_long(optarg, &sen);
952 print_help(route_cmds, "route", "add");
958 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
961 if (rc != LUSTRE_CFG_RC_NO_ERR)
962 cYAML_print_tree2file(stderr, err_rc);
964 cYAML_free_tree(err_rc);
969 static int jt_add_ni(int argc, char **argv)
972 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1;
973 struct cYAML *err_rc = NULL;
974 int rc, opt, cpt_rc = -1;
975 struct lnet_dlc_network_descr nw_descr;
976 struct cfs_expr_list *global_cpts = NULL;
977 struct lnet_ioctl_config_lnd_tunables tunables;
979 bool skip_mr_route_setup = false;
981 memset(&tunables, 0, sizeof(tunables));
982 lustre_lnet_init_nw_descr(&nw_descr);
984 const char *const short_options = "b:c:i:k:m:n:p:r:s:t:";
985 static const struct option long_options[] = {
986 { .name = "peer-buffer-credits",
987 .has_arg = required_argument, .val = 'b' },
988 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
989 { .name = "if", .has_arg = required_argument, .val = 'i' },
990 { .name = "skip-mr-route-setup",
991 .has_arg = no_argument, .val = 'k' },
992 { .name = "conns-per-peer",
993 .has_arg = required_argument, .val = 'm' },
994 { .name = "net", .has_arg = required_argument, .val = 'n' },
995 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
996 { .name = "credits", .has_arg = required_argument, .val = 'r' },
997 { .name = "cpt", .has_arg = required_argument, .val = 's' },
998 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
1001 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
1005 while ((opt = getopt_long(argc, argv, short_options,
1006 long_options, NULL)) != -1) {
1009 rc = parse_long(optarg, &pbc);
1017 rc = parse_long(optarg, &pc);
1025 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1027 cYAML_build_error(-1, -1, "ni", "add",
1028 "bad interface list",
1034 skip_mr_route_setup = true;
1037 rc = parse_long(optarg, &cpp);
1046 nw_descr.nw_id = libcfs_str2net(optarg);
1052 rc = parse_long(optarg, &cre);
1060 cpt_rc = cfs_expr_list_parse(optarg,
1062 UINT_MAX, &global_cpts);
1065 rc = parse_long(optarg, &pto);
1073 print_help(net_cmds, "net", "add");
1079 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
1080 tunables.lt_cmn.lct_peer_timeout = pto;
1081 tunables.lt_cmn.lct_peer_tx_credits = pc;
1082 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1083 tunables.lt_cmn.lct_max_tx_credits = cre;
1087 rc = lustre_lnet_config_ni(&nw_descr,
1088 (cpt_rc == 0) ? global_cpts: NULL,
1089 ip2net, (found) ? &tunables : NULL,
1092 if (global_cpts != NULL)
1093 cfs_expr_list_free(global_cpts);
1096 if (rc != LUSTRE_CFG_RC_NO_ERR)
1097 cYAML_print_tree2file(stderr, err_rc);
1099 cYAML_free_tree(err_rc);
1101 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
1103 rc = lustre_lnet_setup_mrrouting(&err_rc);
1105 if (rc != LUSTRE_CFG_RC_NO_ERR)
1106 cYAML_print_tree2file(stderr, err_rc);
1108 cYAML_free_tree(err_rc);
1114 static int jt_del_route(int argc, char **argv)
1116 char *network = NULL, *gateway = NULL;
1117 struct cYAML *err_rc = NULL;
1120 const char *const short_options = "n:g:";
1121 static const struct option long_options[] = {
1122 { .name = "net", .has_arg = required_argument, .val = 'n' },
1123 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1126 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1130 while ((opt = getopt_long(argc, argv, short_options,
1131 long_options, NULL)) != -1) {
1140 print_help(route_cmds, "route", "del");
1146 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1148 if (rc != LUSTRE_CFG_RC_NO_ERR)
1149 cYAML_print_tree2file(stderr, err_rc);
1151 cYAML_free_tree(err_rc);
1156 static int jt_del_ni(int argc, char **argv)
1158 struct cYAML *err_rc = NULL;
1160 struct lnet_dlc_network_descr nw_descr;
1162 lustre_lnet_init_nw_descr(&nw_descr);
1164 const char *const short_options = "n:i:";
1165 static const struct option long_options[] = {
1166 { .name = "net", .has_arg = required_argument, .val = 'n' },
1167 { .name = "if", .has_arg = required_argument, .val = 'i' },
1170 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1174 while ((opt = getopt_long(argc, argv, short_options,
1175 long_options, NULL)) != -1) {
1178 nw_descr.nw_id = libcfs_str2net(optarg);
1181 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1183 cYAML_build_error(-1, -1, "ni", "add",
1184 "bad interface list",
1190 print_help(net_cmds, "net", "del");
1196 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1199 if (rc != LUSTRE_CFG_RC_NO_ERR)
1200 cYAML_print_tree2file(stderr, err_rc);
1202 cYAML_free_tree(err_rc);
1207 static int jt_show_route(int argc, char **argv)
1209 char *network = NULL, *gateway = NULL;
1210 long int hop = -1, prio = -1;
1211 int detail = 0, rc, opt;
1212 struct cYAML *err_rc = NULL, *show_rc = NULL;
1214 const char *const short_options = "n:g:h:p:v";
1215 static const struct option long_options[] = {
1216 { .name = "net", .has_arg = required_argument, .val = 'n' },
1217 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1218 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1219 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1220 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1223 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1227 while ((opt = getopt_long(argc, argv, short_options,
1228 long_options, NULL)) != -1) {
1237 rc = parse_long(optarg, &hop);
1245 rc = parse_long(optarg, &prio);
1256 print_help(route_cmds, "route", "show");
1262 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1263 &show_rc, &err_rc, false);
1265 if (rc != LUSTRE_CFG_RC_NO_ERR)
1266 cYAML_print_tree2file(stderr, err_rc);
1268 cYAML_print_tree(show_rc);
1270 cYAML_free_tree(err_rc);
1271 cYAML_free_tree(show_rc);
1276 static int set_value_helper(int argc, char **argv,
1277 int (*cb)(int, bool, char*, int, struct cYAML**))
1280 long int healthv = -1;
1283 struct cYAML *err_rc = NULL;
1285 const char *const short_options = "t:n:a";
1286 static const struct option long_options[] = {
1287 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1288 { .name = "health", .has_arg = required_argument, .val = 't' },
1289 { .name = "all", .has_arg = no_argument, .val = 'a' },
1292 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1296 while ((opt = getopt_long(argc, argv, short_options,
1297 long_options, NULL)) != -1) {
1303 if (parse_long(optarg, &healthv) != 0)
1314 rc = cb(healthv, all, nid, -1, &err_rc);
1316 if (rc != LUSTRE_CFG_RC_NO_ERR)
1317 cYAML_print_tree2file(stderr, err_rc);
1319 cYAML_free_tree(err_rc);
1324 static int jt_set_ni_value(int argc, char **argv)
1327 long int healthv = -1, cpp = -1;
1330 struct cYAML *err_rc = NULL;
1332 const char *const short_options = "a:m:n:t:";
1333 static const struct option long_options[] = {
1334 { .name = "all", .has_arg = no_argument, .val = 'a' },
1335 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
1336 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1337 { .name = "health", .has_arg = required_argument, .val = 't' },
1340 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1344 while ((opt = getopt_long(argc, argv, short_options,
1345 long_options, NULL)) != -1) {
1351 rc = parse_long(optarg, &cpp);
1362 if (parse_long(optarg, &healthv) != 0) {
1374 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
1377 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
1380 if (rc != LUSTRE_CFG_RC_NO_ERR)
1381 cYAML_print_tree2file(stderr, err_rc);
1383 cYAML_free_tree(err_rc);
1388 static int jt_set_peer_ni_value(int argc, char **argv)
1390 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1393 static int jt_show_recovery(int argc, char **argv)
1396 struct cYAML *err_rc = NULL, *show_rc = NULL;
1398 const char *const short_options = "lp";
1399 static const struct option long_options[] = {
1400 { .name = "local", .has_arg = no_argument, .val = 'l' },
1401 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1404 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1408 while ((opt = getopt_long(argc, argv, short_options,
1409 long_options, NULL)) != -1) {
1412 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1415 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1422 if (rc != LUSTRE_CFG_RC_NO_ERR)
1423 cYAML_print_tree2file(stderr, err_rc);
1425 cYAML_print_tree(show_rc);
1427 cYAML_free_tree(err_rc);
1428 cYAML_free_tree(show_rc);
1433 static int jt_show_net(int argc, char **argv)
1435 char *network = NULL;
1437 struct cYAML *err_rc = NULL, *show_rc = NULL;
1438 long int detail = 0;
1440 const char *const short_options = "n:v";
1441 static const struct option long_options[] = {
1442 { .name = "net", .has_arg = required_argument, .val = 'n' },
1443 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1446 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1450 while ((opt = getopt_long(argc, argv, short_options,
1451 long_options, NULL)) != -1) {
1457 if ((!optarg) && (argv[optind] != NULL) &&
1458 (argv[optind][0] != '-')) {
1459 if (parse_long(argv[optind++], &detail) != 0)
1466 print_help(net_cmds, "net", "show");
1472 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1475 if (rc != LUSTRE_CFG_RC_NO_ERR)
1476 cYAML_print_tree2file(stderr, err_rc);
1478 cYAML_print_tree(show_rc);
1480 cYAML_free_tree(err_rc);
1481 cYAML_free_tree(show_rc);
1486 static int jt_show_routing(int argc, char **argv)
1488 struct cYAML *err_rc = NULL, *show_rc = NULL;
1491 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1495 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1497 if (rc != LUSTRE_CFG_RC_NO_ERR)
1498 cYAML_print_tree2file(stderr, err_rc);
1500 cYAML_print_tree(show_rc);
1502 cYAML_free_tree(err_rc);
1503 cYAML_free_tree(show_rc);
1508 static int jt_show_stats(int argc, char **argv)
1511 struct cYAML *show_rc = NULL, *err_rc = NULL;
1513 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1517 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1519 if (rc != LUSTRE_CFG_RC_NO_ERR)
1520 cYAML_print_tree2file(stderr, err_rc);
1522 cYAML_print_tree(show_rc);
1524 cYAML_free_tree(err_rc);
1525 cYAML_free_tree(show_rc);
1530 static int jt_show_udsp(int argc, char **argv)
1534 struct cYAML *err_rc = NULL, *show_rc = NULL;
1536 const char *const short_options = "i:";
1537 static const struct option long_options[] = {
1538 { .name = "idx", .has_arg = required_argument, .val = 'i' },
1542 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
1546 while ((opt = getopt_long(argc, argv, short_options,
1547 long_options, NULL)) != -1) {
1553 print_help(net_cmds, "net", "show");
1559 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
1561 if (rc != LUSTRE_CFG_RC_NO_ERR)
1562 cYAML_print_tree2file(stderr, err_rc);
1564 cYAML_print_tree(show_rc);
1566 cYAML_free_tree(err_rc);
1567 cYAML_free_tree(show_rc);
1572 static int jt_show_global(int argc, char **argv)
1575 struct cYAML *show_rc = NULL, *err_rc = NULL;
1577 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1581 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1582 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1583 cYAML_print_tree2file(stderr, err_rc);
1587 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1588 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1589 cYAML_print_tree2file(stderr, err_rc);
1593 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1594 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1595 cYAML_print_tree2file(stderr, err_rc);
1599 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1600 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1601 cYAML_print_tree2file(stderr, err_rc);
1605 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1606 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1607 cYAML_print_tree2file(stderr, err_rc);
1611 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1612 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1613 cYAML_print_tree2file(stderr, err_rc);
1617 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1618 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1619 cYAML_print_tree2file(stderr, err_rc);
1623 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1624 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1625 cYAML_print_tree2file(stderr, err_rc);
1629 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1630 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1631 cYAML_print_tree2file(stderr, err_rc);
1635 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1636 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1637 cYAML_print_tree2file(stderr, err_rc);
1641 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1642 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1643 cYAML_print_tree2file(stderr, err_rc);
1647 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1648 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1649 cYAML_print_tree2file(stderr, err_rc);
1654 cYAML_print_tree(show_rc);
1657 cYAML_free_tree(err_rc);
1658 cYAML_free_tree(show_rc);
1663 static int jt_lnet(int argc, char **argv)
1667 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1671 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1674 static int jt_route(int argc, char **argv)
1678 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1682 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1685 static int jt_net(int argc, char **argv)
1689 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1693 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1696 static int jt_routing(int argc, char **argv)
1700 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1704 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1707 static int jt_stats(int argc, char **argv)
1711 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1715 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1718 static int jt_debug(int argc, char **argv)
1722 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1726 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1729 static int jt_global(int argc, char **argv)
1733 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1737 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1740 static int jt_peers(int argc, char **argv)
1744 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1748 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1751 static int jt_set(int argc, char **argv)
1755 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1759 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1762 static int jt_udsp(int argc, char **argv)
1766 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1770 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1773 static int jt_import(int argc, char **argv)
1776 struct cYAML *err_rc = NULL;
1777 struct cYAML *show_rc = NULL;
1778 int rc = 0, return_rc = 0, opt, opt_found = 0;
1781 const char *const short_options = "adseh";
1782 static const struct option long_options[] = {
1783 { .name = "add", .has_arg = no_argument, .val = 'a' },
1784 { .name = "del", .has_arg = no_argument, .val = 'd' },
1785 { .name = "show", .has_arg = no_argument, .val = 's' },
1786 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1787 { .name = "help", .has_arg = no_argument, .val = 'h' },
1790 while ((opt = getopt_long(argc, argv, short_options,
1791 long_options, NULL)) != -1) {
1805 printf("import FILE\n"
1806 "import < FILE : import a file\n"
1807 "\t--add: add configuration\n"
1808 "\t--del: delete configuration\n"
1809 "\t--show: show configuration\n"
1810 "\t--exec: execute command\n"
1811 "\t--help: display this help\n"
1812 "If no command option is given then --add"
1813 " is assumed by default\n");
1820 /* grab the file name if one exists */
1821 if (opt_found && argc == 3)
1823 else if (!opt_found && argc == 2)
1828 rc = lustre_yaml_config(file, &err_rc);
1829 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1830 cYAML_print_tree(show_rc);
1831 cYAML_free_tree(show_rc);
1834 rc = lustre_yaml_del(file, &err_rc);
1837 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1838 cYAML_print_tree(show_rc);
1839 cYAML_free_tree(show_rc);
1842 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1843 cYAML_print_tree(show_rc);
1844 cYAML_free_tree(show_rc);
1848 if (rc || return_rc) {
1849 cYAML_print_tree2file(stderr, err_rc);
1850 cYAML_free_tree(err_rc);
1856 static int jt_export(int argc, char **argv)
1858 struct cYAML *show_rc = NULL;
1859 struct cYAML *err_rc = NULL;
1863 bool backup = false;
1866 const char *const short_options = "bh";
1867 static const struct option long_options[] = {
1868 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1869 { .name = "help", .has_arg = no_argument, .val = 'h' },
1872 while ((opt = getopt_long(argc, argv, short_options,
1873 long_options, NULL)) != -1) {
1880 printf("export > FILE.yaml : export configuration\n"
1881 "\t--backup: export only what's necessary for reconfig\n"
1882 "\t--help: display this help\n");
1887 if (backup && argc >= 3)
1889 else if (!backup && argc >= 2)
1895 f = fopen(file, "w");
1900 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1901 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1902 cYAML_print_tree2file(stderr, err_rc);
1903 cYAML_free_tree(err_rc);
1907 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_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_routing(-1, &show_rc, &err_rc, backup);
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_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1923 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1924 cYAML_print_tree2file(stderr, err_rc);
1925 cYAML_free_tree(err_rc);
1929 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1930 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1931 cYAML_print_tree2file(stderr, err_rc);
1932 cYAML_free_tree(err_rc);
1936 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1937 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1938 cYAML_print_tree2file(stderr, err_rc);
1939 cYAML_free_tree(err_rc);
1943 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1944 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1945 cYAML_print_tree2file(stderr, err_rc);
1946 cYAML_free_tree(err_rc);
1950 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1951 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1952 cYAML_print_tree2file(stderr, err_rc);
1953 cYAML_free_tree(err_rc);
1957 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1958 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1959 cYAML_print_tree2file(stderr, err_rc);
1963 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1964 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1965 cYAML_print_tree2file(stderr, err_rc);
1969 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1970 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1971 cYAML_print_tree2file(stderr, err_rc);
1975 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1976 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1977 cYAML_print_tree2file(stderr, err_rc);
1981 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1982 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1983 cYAML_print_tree2file(stderr, err_rc);
1987 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1988 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1989 cYAML_print_tree2file(stderr, err_rc);
1993 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1994 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1995 cYAML_print_tree2file(stderr, err_rc);
1996 cYAML_free_tree(err_rc);
2000 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2001 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2002 cYAML_print_tree2file(stderr, err_rc);
2003 cYAML_free_tree(err_rc);
2007 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
2008 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2009 cYAML_print_tree2file(stderr, err_rc);
2010 cYAML_free_tree(err_rc);
2014 if (show_rc != NULL) {
2015 cYAML_print_tree2file(f, show_rc);
2016 cYAML_free_tree(show_rc);
2025 static int jt_peer_nid_common(int argc, char **argv, int cmd)
2027 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
2029 char *prim_nid = NULL, *nidstr = NULL;
2030 char err_str[LNET_MAX_STR_LEN] = "Error";
2031 struct cYAML *err_rc = NULL;
2033 const char *const short_opts = "k:mn:";
2034 const struct option long_opts[] = {
2035 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2036 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2037 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2040 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2044 while ((opt = getopt_long(argc, argv, short_opts,
2045 long_opts, NULL)) != -1) {
2054 if (cmd == LNETCTL_DEL_CMD) {
2055 rc = LUSTRE_CFG_RC_BAD_PARAM;
2056 snprintf(err_str, LNET_MAX_STR_LEN,
2057 "Unrecognized option '-%c'", opt);
2063 print_help(peer_cmds, "peer",
2064 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2070 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2072 if (rc != LUSTRE_CFG_RC_NO_ERR)
2076 cYAML_build_error(rc, -1, "peer",
2077 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2081 if (rc != LUSTRE_CFG_RC_NO_ERR)
2082 cYAML_print_tree2file(stderr, err_rc);
2084 cYAML_free_tree(err_rc);
2089 static int jt_add_peer_nid(int argc, char **argv)
2091 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2094 static int jt_del_peer_nid(int argc, char **argv)
2096 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2099 static int jt_show_peer(int argc, char **argv)
2103 struct cYAML *err_rc = NULL, *show_rc = NULL;
2104 long int detail = 0;
2106 const char *const short_opts = "hn:v::";
2107 const struct option long_opts[] = {
2108 { .name = "help", .has_arg = no_argument, .val = 'h' },
2109 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2110 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2113 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2117 while ((opt = getopt_long(argc, argv, short_opts,
2118 long_opts, NULL)) != -1) {
2124 if ((!optarg) && (argv[optind] != NULL) &&
2125 (argv[optind][0] != '-')) {
2126 if (parse_long(argv[optind++], &detail) != 0)
2133 print_help(peer_cmds, "peer", "show");
2139 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2142 if (rc != LUSTRE_CFG_RC_NO_ERR)
2143 cYAML_print_tree2file(stderr, err_rc);
2145 cYAML_print_tree(show_rc);
2147 cYAML_free_tree(err_rc);
2148 cYAML_free_tree(show_rc);
2153 static int jt_list_peer(int argc, char **argv)
2156 struct cYAML *err_rc = NULL, *list_rc = NULL;
2158 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2162 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2164 if (rc != LUSTRE_CFG_RC_NO_ERR)
2165 cYAML_print_tree2file(stderr, err_rc);
2167 cYAML_print_tree(list_rc);
2169 cYAML_free_tree(err_rc);
2170 cYAML_free_tree(list_rc);
2175 static int jt_ping(int argc, char **argv)
2177 struct cYAML *err_rc = NULL;
2178 struct cYAML *show_rc = NULL;
2181 char *src_nidstr = NULL;
2183 const char *const short_options = "hs:t:";
2184 const struct option long_options[] = {
2185 { .name = "help", .has_arg = no_argument, .val = 'h' },
2186 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2187 { .name = "source", .has_arg = required_argument, .val = 's' },
2190 while ((opt = getopt_long(argc, argv, short_options,
2191 long_options, NULL)) != -1) {
2194 src_nidstr = optarg;
2197 timeout = 1000 * atol(optarg);
2200 printf("ping nid[,nid,...]\n"
2201 "\t --source: source nid\n"
2202 "\t --timeout: ping timeout\n"
2203 "\t --help: display this help\n");
2210 for (; optind < argc; optind++)
2211 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
2215 cYAML_print_tree(show_rc);
2218 cYAML_print_tree2file(stderr, err_rc);
2220 cYAML_free_tree(err_rc);
2221 cYAML_free_tree(show_rc);
2226 static int jt_discover(int argc, char **argv)
2228 struct cYAML *err_rc = NULL;
2229 struct cYAML *show_rc = NULL;
2233 const char *const short_options = "fh";
2234 const struct option long_options[] = {
2235 { .name = "force", .has_arg = no_argument, .val = 'f' },
2236 { .name = "help", .has_arg = no_argument, .val = 'h' },
2239 while ((opt = getopt_long(argc, argv, short_options,
2240 long_options, NULL)) != -1) {
2246 printf("discover nid[,nid,...]\n"
2247 "\t --force: force discovery\n"
2248 "\t --help: display this help\n");
2255 for (; optind < argc; optind++)
2256 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2260 cYAML_print_tree(show_rc);
2263 cYAML_print_tree2file(stderr, err_rc);
2265 cYAML_free_tree(err_rc);
2266 cYAML_free_tree(show_rc);
2271 static int jt_add_udsp(int argc, char **argv)
2273 char *src = NULL, *dst = NULL, *rte = NULL;
2274 struct cYAML *err_rc = NULL;
2275 union lnet_udsp_action udsp_action;
2276 long int idx = -1, priority = -1;
2278 char *action_type = "pref";
2280 const char *const short_options = "s:d:r:p:i:";
2281 static const struct option long_options[] = {
2282 { .name = "src", .has_arg = required_argument, .val = 's' },
2283 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2284 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2285 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2286 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2289 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2293 while ((opt = getopt_long(argc, argv, short_options,
2294 long_options, NULL)) != -1) {
2306 rc = parse_long(optarg, &priority);
2309 action_type = "priority";
2310 udsp_action.udsp_priority = priority;
2313 rc = parse_long(optarg, &idx);
2318 print_help(udsp_cmds, "udsp", "add");
2324 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2327 if (rc != LUSTRE_CFG_RC_NO_ERR)
2328 cYAML_print_tree2file(stderr, err_rc);
2330 cYAML_free_tree(err_rc);
2335 static int jt_del_udsp(int argc, char **argv)
2337 struct cYAML *err_rc = NULL;
2341 const char *const short_options = "i:";
2342 static const struct option long_options[] = {
2343 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2346 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2350 while ((opt = getopt_long(argc, argv, short_options,
2351 long_options, NULL)) != -1) {
2354 rc = parse_long(optarg, &idx);
2359 print_help(udsp_cmds, "udsp", "add");
2365 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2366 if (rc != LUSTRE_CFG_RC_NO_ERR)
2367 cYAML_print_tree2file(stderr, err_rc);
2369 cYAML_free_tree(err_rc);
2374 static int lnetctl_list_commands(int argc, char **argv)
2376 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2378 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2383 int main(int argc, char **argv)
2386 struct cYAML *err_rc = NULL;
2388 rc = lustre_lnet_config_lib_init();
2390 cYAML_build_error(-1, -1, "lnetctl", "startup",
2391 "cannot register LNet device", &err_rc);
2392 cYAML_print_tree2file(stderr, err_rc);
2396 Parser_init("lnetctl > ", cmd_list);
2398 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);