4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
33 #include "lnetconfig/cyaml.h"
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_recovery(int argc, char **argv);
52 static int jt_show_global(int argc, char **argv);
53 static int jt_show_udsp(int argc, char **argv);
54 static int jt_set_tiny(int argc, char **argv);
55 static int jt_set_small(int argc, char **argv);
56 static int jt_set_large(int argc, char **argv);
57 static int jt_set_numa(int argc, char **argv);
58 static int jt_set_retry_count(int argc, char **argv);
59 static int jt_set_transaction_to(int argc, char **argv);
60 static int jt_set_recov_intrv(int argc, char **argv);
61 static int jt_set_rtr_sensitivity(int argc, char **argv);
62 static int jt_set_hsensitivity(int argc, char **argv);
63 static int jt_set_max_recovery_ping_interval(int argc, char **argv);
64 static int jt_reset_stats(int argc, char **argv);
65 static int jt_add_peer_nid(int argc, char **argv);
66 static int jt_del_peer_nid(int argc, char **argv);
67 static int jt_set_max_intf(int argc, char **argv);
68 static int jt_set_discovery(int argc, char **argv);
69 static int jt_set_drop_asym_route(int argc, char **argv);
70 static int jt_list_peer(int argc, char **argv);
71 static int jt_add_udsp(int argc, char **argv);
72 static int jt_del_udsp(int argc, char **argv);
73 /*static int jt_show_peer(int argc, char **argv);*/
74 static int lnetctl_list_commands(int argc, char **argv);
75 static int jt_import(int argc, char **argv);
76 static int jt_export(int argc, char **argv);
77 static int jt_ping(int argc, char **argv);
78 static int jt_discover(int argc, char **argv);
79 static int jt_lnet(int argc, char **argv);
80 static int jt_route(int argc, char **argv);
81 static int jt_net(int argc, char **argv);
82 static int jt_routing(int argc, char **argv);
83 static int jt_set(int argc, char **argv);
84 static int jt_debug(int argc, char **argv);
85 static int jt_stats(int argc, char **argv);
86 static int jt_global(int argc, char **argv);
87 static int jt_peers(int argc, char **argv);
88 static int jt_set_ni_value(int argc, char **argv);
89 static int jt_set_peer_ni_value(int argc, char **argv);
90 static int jt_calc_service_id(int argc, char **argv);
91 static int jt_set_response_tracking(int argc, char **argv);
92 static int jt_set_recovery_limit(int argc, char **argv);
93 static int jt_udsp(int argc, char **argv);
94 static int jt_setup_mrrouting(int argc, char **argv);
95 static int jt_calc_cpt_of_nid(int argc, char **argv);
96 static int jt_show_peer_debug_info(int argc, char **argv);
98 command_t cmd_list[] = {
99 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
100 {"route", jt_route, 0, "route {add | del | show | help}"},
101 {"net", jt_net, 0, "net {add | del | show | set | help}"},
102 {"routing", jt_routing, 0, "routing {show | help}"},
103 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
104 " | routing | numa_range | max_interfaces"
105 " | discovery | drop_asym_route | retry_count"
106 " | transaction_timeout | health_sensitivity"
107 " | recovery_interval | router_sensitivity"
108 " | response_tracking | recovery_limit}"},
109 {"import", jt_import, 0, "import FILE.yaml"},
110 {"export", jt_export, 0, "export FILE.yaml"},
111 {"stats", jt_stats, 0, "stats {show | help}"},
112 {"debug", jt_debug, 0, "debug {recovery {local | peer} | peer}"},
113 {"global", jt_global, 0, "global {show | help}"},
114 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
115 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
116 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
117 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
118 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
119 {"setup-mrrouting", jt_setup_mrrouting, 0,
120 "setup linux routing tables\n"},
121 {"cpt-of-nid", jt_calc_cpt_of_nid, 0, "Calculate the CPT associated with NID\n"
122 "\t--nid: NID to calculate the CPT of\n"
123 "\t--ncpt: Number of CPTs to consider in the calculation\n"},
124 {"help", Parser_help, 0, "help"},
125 {"exit", Parser_quit, 0, "quit"},
126 {"quit", Parser_quit, 0, "quit"},
127 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
131 command_t lnet_cmds[] = {
132 {"configure", jt_config_lnet, 0, "configure lnet\n"
133 "\t--all: load NI configuration from module parameters\n"},
134 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
138 command_t route_cmds[] = {
139 {"add", jt_add_route, 0, "add 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 "\t--hop: number to final destination (1 < hops < 255)\n"
143 "\t--priority: priority of route (0 - highest prio\n"
144 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
145 {"del", jt_del_route, 0, "delete a route\n"
146 "\t--net: net name (e.g. tcp0)\n"
147 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
148 {"show", jt_show_route, 0, "show routes\n"
149 "\t--net: net name (e.g. tcp0) to filter on\n"
150 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
151 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
152 "\t--priority: priority of route (0 - highest prio to filter on\n"
153 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
154 "\t--verbose: display detailed output per route\n"},
158 command_t net_cmds[] = {
159 {"add", jt_add_ni, 0, "add a network\n"
160 "\t--net: net name (e.g. tcp0)\n"
161 "\t--if: physical interface (e.g. eth0)\n"
162 "\t--ip2net: specify networks based on IP address patterns\n"
163 "\t--peer-timeout: time to wait before declaring a peer dead\n"
164 "\t--peer-credits: define the max number of inflight messages\n"
165 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
166 "\t--credits: Network Interface credits\n"
167 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
168 "\t--conns-per-peer: number of connections per peer\n"
169 "\t--skip-mr-route-setup: do not add linux route for the ni\n"
170 "\t--auth-key: Network authorization key (kfilnd only)\n"},
171 {"del", jt_del_ni, 0, "delete a network\n"
172 "\t--net: net name (e.g. tcp0)\n"
173 "\t--if: physical interface (e.g. eth0)\n"},
174 {"show", jt_show_net, 0, "show networks\n"
175 "\t--net: net name (e.g. tcp0) to filter on\n"
176 "\t--verbose: display detailed output per network."
177 " Optional argument of '2' outputs more stats\n"},
178 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
179 "\t--nid: NI NID to set the\n"
180 "\t--health: specify health value to set\n"
181 "\t--conns-per-peer: number of connections per peer\n"
182 "\t--all: set all NIs value to the one specified\n"},
186 command_t routing_cmds[] = {
187 {"show", jt_show_routing, 0, "show routing information\n"},
191 command_t stats_cmds[] = {
192 {"show", jt_show_stats, 0, "show LNET statistics\n"},
193 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
197 command_t debug_cmds[] = {
198 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
199 "\t--local : list local recovery queue\n"
200 "\t--peer : list peer recovery queue\n"},
201 {"peer", jt_show_peer_debug_info, 0, "show peer debug info\n"
202 "\t--nid: peer's NID\n"},
206 command_t global_cmds[] = {
207 {"show", jt_show_global, 0, "show global variables\n"},
211 command_t set_cmds[] = {
212 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
213 "\tVALUE must be greater than 0\n"},
214 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
215 "\tVALUE must be greater than 0\n"},
216 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
217 "\tVALUE must be greater than 0\n"},
218 {"routing", jt_set_routing, 0, "enable/disable routing\n"
219 "\t0 - disable routing\n"
220 "\t1 - enable routing\n"},
221 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
222 "\tVALUE must be at least 0\n"},
223 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
225 "\tValue must be greater than 16\n"},
226 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
227 "\t0 - disable peer discovery\n"
228 "\t1 - enable peer discovery (default)\n"},
229 {"drop_asym_route", jt_set_drop_asym_route, 0,
230 "drop/accept asymmetrical route messages\n"
231 "\t0 - accept asymmetrical route messages (default)\n"
232 "\t1 - drop asymmetrical route messages\n"},
233 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
234 "\t0 - turn of retries\n"
235 "\t>0 - number of retries\n"},
236 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
237 "\t>0 - timeout in seconds\n"},
238 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
239 "\t0 - turn off health evaluation\n"
240 "\t>0 - sensitivity value not more than 1000\n"},
241 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
242 "\t>0 - time in seconds between pings\n"},
243 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
244 "\t100 - router interfaces need to be fully healthy to be used\n"
245 "\t<100 - router interfaces can be used even if not healthy\n"},
246 {"response_tracking", jt_set_response_tracking, 0,
247 "Set the behavior of response tracking\n"
248 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
249 "\t1 - GETs are eligible for response tracking\n"
250 "\t2 - PUTs are eligible for response tracking\n"
251 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
252 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
253 "\t pings and discovery pushes always utilize response tracking\n"},
254 {"recovery_limit", jt_set_recovery_limit, 0,
255 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
256 "\t0 - Recover indefinitely (default)\n"
257 "\t>0 - Recover for the specified number of seconds.\n"},
258 {"max_recovery_ping_interval", jt_set_max_recovery_ping_interval, 0,
259 "maximum recovery ping interval\n"
260 "\t>0 - maximum recovery ping interval in seconds\n"},
264 command_t peer_cmds[] = {
265 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
266 "\t--prim_nid: Primary NID of the peer.\n"
267 "\t--nid: one or more peer NIDs\n"
268 "\t--non_mr: create this peer as not Multi-Rail capable\n"
269 "\t--ip2nets: specify a range of nids per peer"},
270 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
271 "\t--prim_nid: Primary NID of the peer.\n"
272 "\t--nid: list of NIDs to remove. If none provided,\n"
273 "\t peer is deleted\n"
274 "\t--ip2nets: specify a range of nids per peer"},
275 {"show", jt_show_peer, 0, "show peer information\n"
276 "\t--nid: NID of peer to filter on.\n"
277 "\t--verbose: display detailed output per peer."
278 " Optional argument of '2' outputs more stats\n"},
279 {"list", jt_list_peer, 0, "list all peers\n"},
280 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
281 "\t--nid: Peer NI NID to set the\n"
282 "\t--health: specify health value to set\n"
283 "\t--all: set all peer_nis values to the one specified\n"},
287 command_t udsp_cmds[] = {
288 {"add", jt_add_udsp, 0, "add a udsp\n"
289 "\t--src: ip2nets syntax specifying the local NID to match\n"
290 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
291 "\t--rte: ip2nets syntax specifying the router NID to match\n"
292 "\t--priority: priority value (0 - highest priority)\n"
293 "\t--idx: index of where to insert the rule.\n"
294 "\t By default, appends to the end of the rule list.\n"},
295 {"del", jt_del_udsp, 0, "delete a udsp\n"
296 "\t--idx: index of the Policy.\n"},
297 {"show", jt_show_udsp, 0, "show udsps\n"
298 "\t --idx: index of the policy to show.\n"},
302 static int parse_long(const char *number, long int *value)
309 *value = strtol(number, &end, 0);
310 if (end != NULL && *end != 0)
316 static int jt_setup_mrrouting(int argc, char **argv)
319 struct cYAML *err_rc = NULL;
321 rc = lustre_lnet_setup_mrrouting(&err_rc);
323 if (rc != LUSTRE_CFG_RC_NO_ERR)
324 cYAML_print_tree2file(stderr, err_rc);
326 cYAML_free_tree(err_rc);
331 static inline void print_help(const command_t cmds[], const char *cmd_type,
334 const command_t *cmd;
336 for (cmd = cmds; cmd->pc_name; cmd++) {
337 if (pc_name != NULL &&
338 strcmp(cmd->pc_name, pc_name) == 0) {
339 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
342 } else if (pc_name != NULL) {
345 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
349 static int check_cmd(const command_t *cmd_list, const char *cmd,
350 const char *sub_cmd, const int min_args,
351 int argc, char **argv)
358 const char *const short_options = "h";
359 static const struct option long_options[] = {
360 { .name = "help", .has_arg = no_argument, .val = 'h' },
364 if (argc < min_args) {
365 print_help(cmd_list, cmd, sub_cmd);
368 } else if (argc > 2) {
372 while ((opt = getopt_long(argc, argv, short_options,
373 long_options, NULL)) != -1) {
376 print_help(cmd_list, cmd, sub_cmd);
391 static int jt_set_response_tracking(int argc, char **argv)
395 struct cYAML *err_rc = NULL;
397 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
401 rc = parse_long(argv[1], &value);
403 cYAML_build_error(-1, -1, "parser", "set",
404 "cannot parse response_tracking value",
406 cYAML_print_tree2file(stderr, err_rc);
407 cYAML_free_tree(err_rc);
411 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
412 if (rc != LUSTRE_CFG_RC_NO_ERR)
413 cYAML_print_tree2file(stderr, err_rc);
415 cYAML_free_tree(err_rc);
420 static int jt_calc_service_id(int argc, char **argv)
425 rc = lustre_lnet_calc_service_id(&service_id);
426 if (rc != LUSTRE_CFG_RC_NO_ERR)
429 /* cYAML currently doesn't support printing hex values.
430 * Therefore just print it locally here
432 printf("service_id:\n value: 0x%llx\n",
433 (unsigned long long)(service_id));
438 static int jt_calc_cpt_of_nid(int argc, char **argv)
444 struct cYAML *err_rc = NULL;
445 const char *const short_options = "n:c:h";
446 static const struct option long_options[] = {
447 { .name = "nid", .has_arg = required_argument, .val = 'n' },
448 { .name = "ncpt", .has_arg = required_argument, .val = 'c' },
451 rc = check_cmd(cmd_list, "", "cpt-of-nid", 0, argc, argv);
455 while ((opt = getopt_long(argc, argv, short_options,
456 long_options, NULL)) != -1) {
462 rc = parse_long(optarg, &ncpts);
464 cYAML_build_error(-1, -1, "cpt", "get",
465 "cannot parse input", &err_rc);
466 cYAML_print_tree2file(stderr, err_rc);
467 cYAML_free_tree(err_rc);
472 print_help(cmd_list, "", "cpt-of-nid");
478 cpt = lustre_lnet_calc_cpt_of_nid(nid, ncpts);
482 printf("cpt:\n value: %d\n", cpt);
487 static int jt_set_recovery_limit(int argc, char **argv)
491 struct cYAML *err_rc = NULL;
493 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
497 rc = parse_long(argv[1], &value);
499 cYAML_build_error(-1, -1, "parser", "set",
500 "cannot parse recovery_limit value",
502 cYAML_print_tree2file(stderr, err_rc);
503 cYAML_free_tree(err_rc);
507 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
508 if (rc != LUSTRE_CFG_RC_NO_ERR)
509 cYAML_print_tree2file(stderr, err_rc);
511 cYAML_free_tree(err_rc);
516 static int jt_set_max_intf(int argc, char **argv)
520 struct cYAML *err_rc = NULL;
522 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
526 rc = parse_long(argv[1], &value);
528 cYAML_build_error(-1, -1, "parser", "set",
529 "cannot parse max_interfaces value", &err_rc);
530 cYAML_print_tree2file(stderr, err_rc);
531 cYAML_free_tree(err_rc);
535 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
536 if (rc != LUSTRE_CFG_RC_NO_ERR)
537 cYAML_print_tree2file(stderr, err_rc);
539 cYAML_free_tree(err_rc);
544 static int jt_set_numa(int argc, char **argv)
548 struct cYAML *err_rc = NULL;
550 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
554 rc = parse_long(argv[1], &value);
556 cYAML_build_error(-1, -1, "parser", "set",
557 "cannot parse numa_range value", &err_rc);
558 cYAML_print_tree2file(stderr, err_rc);
559 cYAML_free_tree(err_rc);
563 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
564 if (rc != LUSTRE_CFG_RC_NO_ERR)
565 cYAML_print_tree2file(stderr, err_rc);
567 cYAML_free_tree(err_rc);
572 static int jt_set_recov_intrv(int argc, char **argv)
576 struct cYAML *err_rc = NULL;
578 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
582 rc = parse_long(argv[1], &value);
584 cYAML_build_error(-1, -1, "parser", "set",
585 "cannot parse recovery interval value", &err_rc);
586 cYAML_print_tree2file(stderr, err_rc);
587 cYAML_free_tree(err_rc);
591 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
592 if (rc != LUSTRE_CFG_RC_NO_ERR)
593 cYAML_print_tree2file(stderr, err_rc);
595 cYAML_free_tree(err_rc);
600 static int jt_set_rtr_sensitivity(int argc, char **argv)
604 struct cYAML *err_rc = NULL;
606 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
610 rc = parse_long(argv[1], &value);
612 cYAML_build_error(-1, -1, "parser", "set",
613 "cannot parse router sensitivity value", &err_rc);
614 cYAML_print_tree2file(stderr, err_rc);
615 cYAML_free_tree(err_rc);
619 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
620 if (rc != LUSTRE_CFG_RC_NO_ERR)
621 cYAML_print_tree2file(stderr, err_rc);
623 cYAML_free_tree(err_rc);
628 static int jt_set_hsensitivity(int argc, char **argv)
632 struct cYAML *err_rc = NULL;
634 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
638 rc = parse_long(argv[1], &value);
640 cYAML_build_error(-1, -1, "parser", "set",
641 "cannot parse health sensitivity value", &err_rc);
642 cYAML_print_tree2file(stderr, err_rc);
643 cYAML_free_tree(err_rc);
647 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
648 if (rc != LUSTRE_CFG_RC_NO_ERR)
649 cYAML_print_tree2file(stderr, err_rc);
651 cYAML_free_tree(err_rc);
656 static int jt_reset_stats(int argc, char **argv)
659 struct cYAML *err_rc = NULL;
661 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
665 rc = lustre_lnet_reset_stats(-1, &err_rc);
666 if (rc != LUSTRE_CFG_RC_NO_ERR)
667 cYAML_print_tree2file(stderr, err_rc);
669 cYAML_free_tree(err_rc);
674 static int jt_set_transaction_to(int argc, char **argv)
678 struct cYAML *err_rc = NULL;
680 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
684 rc = parse_long(argv[1], &value);
686 cYAML_build_error(-1, -1, "parser", "set",
687 "cannot parse transaction timeout value", &err_rc);
688 cYAML_print_tree2file(stderr, err_rc);
689 cYAML_free_tree(err_rc);
693 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
694 if (rc != LUSTRE_CFG_RC_NO_ERR)
695 cYAML_print_tree2file(stderr, err_rc);
697 cYAML_free_tree(err_rc);
702 static int jt_set_retry_count(int argc, char **argv)
706 struct cYAML *err_rc = NULL;
708 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
712 rc = parse_long(argv[1], &value);
714 cYAML_build_error(-1, -1, "parser", "set",
715 "cannot parse retry_count value", &err_rc);
716 cYAML_print_tree2file(stderr, err_rc);
717 cYAML_free_tree(err_rc);
721 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
722 if (rc != LUSTRE_CFG_RC_NO_ERR)
723 cYAML_print_tree2file(stderr, err_rc);
725 cYAML_free_tree(err_rc);
730 static int jt_set_discovery(int argc, char **argv)
734 struct cYAML *err_rc = NULL;
736 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
740 rc = parse_long(argv[1], &value);
742 cYAML_build_error(-1, -1, "parser", "set",
743 "cannot parse discovery value", &err_rc);
744 cYAML_print_tree2file(stderr, err_rc);
745 cYAML_free_tree(err_rc);
749 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
750 if (rc != LUSTRE_CFG_RC_NO_ERR)
751 cYAML_print_tree2file(stderr, err_rc);
753 cYAML_free_tree(err_rc);
758 static int jt_set_drop_asym_route(int argc, char **argv)
762 struct cYAML *err_rc = NULL;
764 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
768 rc = parse_long(argv[1], &value);
770 cYAML_build_error(-1, -1, "parser", "set",
771 "cannot parse drop_asym_route value",
773 cYAML_print_tree2file(stderr, err_rc);
774 cYAML_free_tree(err_rc);
778 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
779 if (rc != LUSTRE_CFG_RC_NO_ERR)
780 cYAML_print_tree2file(stderr, err_rc);
782 cYAML_free_tree(err_rc);
787 static int jt_set_tiny(int argc, char **argv)
791 struct cYAML *err_rc = NULL;
793 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
797 rc = parse_long(argv[1], &value);
799 cYAML_build_error(-1, -1, "parser", "set",
800 "cannot parse tiny_buffers value", &err_rc);
801 cYAML_print_tree2file(stderr, err_rc);
802 cYAML_free_tree(err_rc);
806 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
807 if (rc != LUSTRE_CFG_RC_NO_ERR)
808 cYAML_print_tree2file(stderr, err_rc);
810 cYAML_free_tree(err_rc);
815 static int jt_set_small(int argc, char **argv)
819 struct cYAML *err_rc = NULL;
821 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
825 rc = parse_long(argv[1], &value);
827 cYAML_build_error(-1, -1, "parser", "set",
828 "cannot parse small_buffers value", &err_rc);
829 cYAML_print_tree2file(stderr, err_rc);
830 cYAML_free_tree(err_rc);
834 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
835 if (rc != LUSTRE_CFG_RC_NO_ERR)
836 cYAML_print_tree2file(stderr, err_rc);
838 cYAML_free_tree(err_rc);
843 static int jt_set_large(int argc, char **argv)
847 struct cYAML *err_rc = NULL;
849 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
853 rc = parse_long(argv[1], &value);
855 cYAML_build_error(-1, -1, "parser", "set",
856 "cannot parse large_buffers value", &err_rc);
857 cYAML_print_tree2file(stderr, err_rc);
858 cYAML_free_tree(err_rc);
862 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
863 if (rc != LUSTRE_CFG_RC_NO_ERR)
864 cYAML_print_tree2file(stderr, err_rc);
866 cYAML_free_tree(err_rc);
871 static int jt_set_routing(int argc, char **argv)
874 struct cYAML *err_rc = NULL;
877 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
881 rc = parse_long(argv[1], &value);
882 if (rc != 0 || (value != 0 && value != 1)) {
883 cYAML_build_error(-1, -1, "parser", "set",
884 "cannot parse routing value.\n"
885 "must be 0 for disable or 1 for enable",
887 cYAML_print_tree2file(stderr, err_rc);
888 cYAML_free_tree(err_rc);
892 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
894 if (rc != LUSTRE_CFG_RC_NO_ERR)
895 cYAML_print_tree2file(stderr, err_rc);
897 cYAML_free_tree(err_rc);
902 static int jt_set_max_recovery_ping_interval(int argc, char **argv)
906 struct cYAML *err_rc = NULL;
908 rc = check_cmd(set_cmds, "set", "maximum recovery_interval", 2, argc, argv);
912 rc = parse_long(argv[1], &value);
914 cYAML_build_error(-1, -1, "parser", "set",
915 "cannot parse maximum recovery interval value",
917 cYAML_print_tree2file(stderr, err_rc);
918 cYAML_free_tree(err_rc);
922 rc = lustre_lnet_config_max_recovery_ping_interval(value, -1, &err_rc);
923 if (rc != LUSTRE_CFG_RC_NO_ERR)
924 cYAML_print_tree2file(stderr, err_rc);
926 cYAML_free_tree(err_rc);
931 static void yaml_lnet_print_error(char *flag, char *cmd, const char *errstr)
938 snprintf(errcode, sizeof(errcode), "%d", errno);
940 yaml_emitter_initialize(&log);
941 yaml_emitter_set_output_file(&log, stdout);
943 yaml_emitter_open(&log);
944 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
945 rc = yaml_emitter_emit(&log, &event);
949 yaml_mapping_start_event_initialize(&event, NULL,
950 (yaml_char_t *)YAML_MAP_TAG,
951 1, YAML_ANY_MAPPING_STYLE);
952 rc = yaml_emitter_emit(&log, &event);
956 yaml_scalar_event_initialize(&event, NULL,
957 (yaml_char_t *)YAML_STR_TAG,
960 YAML_PLAIN_SCALAR_STYLE);
961 rc = yaml_emitter_emit(&log, &event);
965 yaml_sequence_start_event_initialize(&event, NULL,
966 (yaml_char_t *)YAML_SEQ_TAG,
967 1, YAML_ANY_SEQUENCE_STYLE);
968 rc = yaml_emitter_emit(&log, &event);
972 yaml_mapping_start_event_initialize(&event, NULL,
973 (yaml_char_t *)YAML_MAP_TAG,
974 1, YAML_ANY_MAPPING_STYLE);
975 rc = yaml_emitter_emit(&log, &event);
979 yaml_scalar_event_initialize(&event, NULL,
980 (yaml_char_t *)YAML_STR_TAG,
983 1, 0, YAML_PLAIN_SCALAR_STYLE);
984 rc = yaml_emitter_emit(&log, &event);
988 yaml_scalar_event_initialize(&event, NULL,
989 (yaml_char_t *)YAML_STR_TAG,
992 1, 0, YAML_PLAIN_SCALAR_STYLE);
993 rc = yaml_emitter_emit(&log, &event);
997 yaml_scalar_event_initialize(&event, NULL,
998 (yaml_char_t *)YAML_STR_TAG,
999 (yaml_char_t *)"errno",
1000 strlen("errno"), 1, 0,
1001 YAML_PLAIN_SCALAR_STYLE);
1002 rc = yaml_emitter_emit(&log, &event);
1006 yaml_scalar_event_initialize(&event, NULL,
1007 (yaml_char_t *)YAML_INT_TAG,
1008 (yaml_char_t *)errcode,
1009 strlen(errcode), 1, 0,
1010 YAML_PLAIN_SCALAR_STYLE);
1011 rc = yaml_emitter_emit(&log, &event);
1016 yaml_scalar_event_initialize(&event, NULL,
1017 (yaml_char_t *)YAML_STR_TAG,
1018 (yaml_char_t *)"descr",
1019 strlen("descr"), 1, 0,
1020 YAML_PLAIN_SCALAR_STYLE);
1021 rc = yaml_emitter_emit(&log, &event);
1025 yaml_scalar_event_initialize(&event, NULL,
1026 (yaml_char_t *)YAML_INT_TAG,
1027 (yaml_char_t *)errstr,
1028 strlen(errstr), 1, 0,
1029 YAML_PLAIN_SCALAR_STYLE);
1030 rc = yaml_emitter_emit(&log, &event);
1034 yaml_mapping_end_event_initialize(&event);
1035 rc = yaml_emitter_emit(&log, &event);
1039 yaml_sequence_end_event_initialize(&event);
1040 rc = yaml_emitter_emit(&log, &event);
1044 yaml_mapping_end_event_initialize(&event);
1045 rc = yaml_emitter_emit(&log, &event);
1049 yaml_document_end_event_initialize(&event, 0);
1050 rc = yaml_emitter_emit(&log, &event);
1054 rc = yaml_emitter_close(&log);
1057 yaml_emitter_log_error(&log, stdout);
1058 yaml_emitter_delete(&log);
1061 static int jt_config_lnet(int argc, char **argv)
1063 struct cYAML *err_rc = NULL;
1064 bool load_mod_params = false;
1067 const char *const short_options = "a";
1068 static const struct option long_options[] = {
1069 { .name = "all", .has_arg = no_argument, .val = 'a' },
1073 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
1077 while ((opt = getopt_long(argc, argv, short_options,
1078 long_options, NULL)) != -1) {
1081 load_mod_params = true;
1088 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
1091 if (rc != LUSTRE_CFG_RC_NO_ERR)
1092 cYAML_print_tree2file(stderr, err_rc);
1094 cYAML_free_tree(err_rc);
1099 static int jt_unconfig_lnet(int argc, char **argv)
1101 struct cYAML *err_rc = NULL;
1104 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
1108 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
1110 if (rc != LUSTRE_CFG_RC_NO_ERR)
1111 cYAML_print_tree2file(stderr, err_rc);
1113 cYAML_free_tree(err_rc);
1117 static int jt_add_route(int argc, char **argv)
1119 char *network = NULL, *gateway = NULL;
1120 long int hop = -1, prio = -1, sen = -1;
1121 struct cYAML *err_rc = NULL;
1124 const char *const short_options = "n:g:c:p:";
1125 static const struct option long_options[] = {
1126 { .name = "net", .has_arg = required_argument, .val = 'n' },
1127 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1128 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1129 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1130 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1133 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1137 while ((opt = getopt_long(argc, argv, short_options,
1138 long_options, NULL)) != -1) {
1147 rc = parse_long(optarg, &hop);
1155 rc = parse_long(optarg, &prio);
1163 rc = parse_long(optarg, &sen);
1172 print_help(route_cmds, "route", "add");
1178 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1181 if (rc != LUSTRE_CFG_RC_NO_ERR)
1182 cYAML_print_tree2file(stderr, err_rc);
1184 cYAML_free_tree(err_rc);
1189 static int yaml_add_ni_tunables(yaml_emitter_t *output,
1190 struct lnet_ioctl_config_lnd_tunables *tunables,
1191 struct lnet_dlc_network_descr *nw_descr)
1197 if (tunables->lt_cmn.lct_peer_timeout < 0 &&
1198 tunables->lt_cmn.lct_peer_tx_credits <= 0 &&
1199 tunables->lt_cmn.lct_peer_rtr_credits <= 0 &&
1200 tunables->lt_cmn.lct_max_tx_credits <= 0)
1201 goto skip_general_settings;
1203 yaml_scalar_event_initialize(&event, NULL,
1204 (yaml_char_t *)YAML_STR_TAG,
1205 (yaml_char_t *)"tunables",
1206 strlen("tunables"), 1, 0,
1207 YAML_PLAIN_SCALAR_STYLE);
1208 rc = yaml_emitter_emit(output, &event);
1212 yaml_mapping_start_event_initialize(&event, NULL,
1213 (yaml_char_t *)YAML_MAP_TAG,
1214 1, YAML_ANY_MAPPING_STYLE);
1215 rc = yaml_emitter_emit(output, &event);
1219 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1220 yaml_scalar_event_initialize(&event, NULL,
1221 (yaml_char_t *)YAML_STR_TAG,
1222 (yaml_char_t *)"peer_timeout",
1223 strlen("peer_timeout"), 1, 0,
1224 YAML_PLAIN_SCALAR_STYLE);
1225 rc = yaml_emitter_emit(output, &event);
1229 snprintf(num, sizeof(num), "%u",
1230 tunables->lt_cmn.lct_peer_timeout);
1231 yaml_scalar_event_initialize(&event, NULL,
1232 (yaml_char_t *)YAML_INT_TAG,
1235 YAML_PLAIN_SCALAR_STYLE);
1236 rc = yaml_emitter_emit(output, &event);
1241 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1242 yaml_scalar_event_initialize(&event, NULL,
1243 (yaml_char_t *)YAML_STR_TAG,
1244 (yaml_char_t *)"peer_credits",
1245 strlen("peer_credits"), 1, 0,
1246 YAML_PLAIN_SCALAR_STYLE);
1247 rc = yaml_emitter_emit(output, &event);
1251 snprintf(num, sizeof(num), "%u",
1252 tunables->lt_cmn.lct_peer_tx_credits);
1253 yaml_scalar_event_initialize(&event, NULL,
1254 (yaml_char_t *)YAML_INT_TAG,
1257 YAML_PLAIN_SCALAR_STYLE);
1258 rc = yaml_emitter_emit(output, &event);
1263 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1264 yaml_scalar_event_initialize(&event, NULL,
1265 (yaml_char_t *)YAML_STR_TAG,
1266 (yaml_char_t *)"peer_buffer_credits",
1267 strlen("peer_buffer_credits"), 1, 0,
1268 YAML_PLAIN_SCALAR_STYLE);
1269 rc = yaml_emitter_emit(output, &event);
1273 snprintf(num, sizeof(num), "%u",
1274 tunables->lt_cmn.lct_peer_rtr_credits);
1275 yaml_scalar_event_initialize(&event, NULL,
1276 (yaml_char_t *)YAML_INT_TAG,
1279 YAML_PLAIN_SCALAR_STYLE);
1280 rc = yaml_emitter_emit(output, &event);
1285 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1286 yaml_scalar_event_initialize(&event, NULL,
1287 (yaml_char_t *)YAML_STR_TAG,
1288 (yaml_char_t *)"credits",
1289 strlen("credits"), 1, 0,
1290 YAML_PLAIN_SCALAR_STYLE);
1291 rc = yaml_emitter_emit(output, &event);
1295 snprintf(num, sizeof(num), "%u",
1296 tunables->lt_cmn.lct_max_tx_credits);
1297 yaml_scalar_event_initialize(&event, NULL,
1298 (yaml_char_t *)YAML_INT_TAG,
1301 YAML_PLAIN_SCALAR_STYLE);
1302 rc = yaml_emitter_emit(output, &event);
1307 yaml_mapping_end_event_initialize(&event);
1308 rc = yaml_emitter_emit(output, &event);
1312 skip_general_settings:
1313 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1315 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0 ||
1317 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1318 yaml_scalar_event_initialize(&event, NULL,
1319 (yaml_char_t *)YAML_STR_TAG,
1320 (yaml_char_t *)"lnd tunables",
1321 strlen("lnd tunables"), 1, 0,
1322 YAML_PLAIN_SCALAR_STYLE);
1323 rc = yaml_emitter_emit(output, &event);
1327 yaml_mapping_start_event_initialize(&event, NULL,
1328 (yaml_char_t *)YAML_MAP_TAG,
1329 1, YAML_ANY_MAPPING_STYLE);
1330 rc = yaml_emitter_emit(output, &event);
1334 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1335 yaml_scalar_event_initialize(&event, NULL,
1336 (yaml_char_t *)YAML_STR_TAG,
1337 (yaml_char_t *)"auth_key",
1338 strlen("auth_key"), 1, 0,
1339 YAML_PLAIN_SCALAR_STYLE);
1340 rc = yaml_emitter_emit(output, &event);
1344 snprintf(num, sizeof(num), "%u",
1345 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1347 yaml_scalar_event_initialize(&event, NULL,
1348 (yaml_char_t *)YAML_INT_TAG,
1351 YAML_PLAIN_SCALAR_STYLE);
1352 rc = yaml_emitter_emit(output, &event);
1357 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1358 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1361 yaml_scalar_event_initialize(&event, NULL,
1362 (yaml_char_t *)YAML_STR_TAG,
1363 (yaml_char_t *)"conns_per_peer",
1364 strlen("conns_per_peer"), 1, 0,
1365 YAML_PLAIN_SCALAR_STYLE);
1366 rc = yaml_emitter_emit(output, &event);
1370 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND)
1371 cpp = tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer;
1372 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND)
1373 cpp = tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer;
1374 snprintf(num, sizeof(num), "%u", cpp);
1376 yaml_scalar_event_initialize(&event, NULL,
1377 (yaml_char_t *)YAML_INT_TAG,
1380 YAML_PLAIN_SCALAR_STYLE);
1381 rc = yaml_emitter_emit(output, &event);
1386 yaml_mapping_end_event_initialize(&event);
1387 rc = yaml_emitter_emit(output, &event);
1393 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1394 struct lnet_dlc_network_descr *nw_descr,
1395 struct lnet_ioctl_config_lnd_tunables *tunables,
1396 struct cfs_expr_list *global_cpts,
1399 struct lnet_dlc_intf_descr *intf;
1400 struct nl_sock *sk = NULL;
1401 yaml_emitter_t output;
1402 yaml_parser_t reply;
1406 if (!ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1407 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1408 (!nw_descr) ? "network , interface" :
1409 (nw_descr->nw_id == 0) ? "network" : "interface");
1413 if ((flags == NLM_F_CREATE) && list_empty(&nw_descr->nw_intflist)) {
1414 fprintf(stdout, "creating a local NI needs at least one interface");
1418 /* Create Netlink emitter to send request to kernel */
1419 sk = nl_socket_alloc();
1423 /* Setup parser to receive Netlink packets */
1424 rc = yaml_parser_initialize(&reply);
1430 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1434 /* Create Netlink emitter to send request to kernel */
1435 rc = yaml_emitter_initialize(&output);
1439 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1440 LNET_GENL_VERSION, LNET_CMD_NETS,
1445 yaml_emitter_open(&output);
1446 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1447 rc = yaml_emitter_emit(&output, &event);
1451 yaml_mapping_start_event_initialize(&event, NULL,
1452 (yaml_char_t *)YAML_MAP_TAG,
1453 1, YAML_ANY_MAPPING_STYLE);
1454 rc = yaml_emitter_emit(&output, &event);
1458 yaml_scalar_event_initialize(&event, NULL,
1459 (yaml_char_t *)YAML_STR_TAG,
1460 (yaml_char_t *)"net",
1461 strlen("net"), 1, 0,
1462 YAML_PLAIN_SCALAR_STYLE);
1463 rc = yaml_emitter_emit(&output, &event);
1467 if (net_id || ip2net) {
1468 char *key = net_id ? "net type" : "ip2net";
1469 char *value = net_id ? net_id : ip2net;
1471 yaml_sequence_start_event_initialize(&event, NULL,
1472 (yaml_char_t *)YAML_SEQ_TAG,
1473 1, YAML_ANY_SEQUENCE_STYLE);
1474 rc = yaml_emitter_emit(&output, &event);
1478 yaml_mapping_start_event_initialize(&event, NULL,
1479 (yaml_char_t *)YAML_MAP_TAG,
1480 1, YAML_ANY_MAPPING_STYLE);
1481 rc = yaml_emitter_emit(&output, &event);
1485 yaml_scalar_event_initialize(&event, NULL,
1486 (yaml_char_t *)YAML_STR_TAG,
1489 1, 0, YAML_PLAIN_SCALAR_STYLE);
1490 rc = yaml_emitter_emit(&output, &event);
1494 yaml_scalar_event_initialize(&event, NULL,
1495 (yaml_char_t *)YAML_STR_TAG,
1496 (yaml_char_t *)value,
1497 strlen(value), 1, 0,
1498 YAML_PLAIN_SCALAR_STYLE);
1499 rc = yaml_emitter_emit(&output, &event);
1503 yaml_scalar_event_initialize(&event, NULL,
1504 (yaml_char_t *)YAML_STR_TAG,
1507 YAML_PLAIN_SCALAR_STYLE);
1508 rc = yaml_emitter_emit(&output, &event);
1515 if (list_empty(&nw_descr->nw_intflist))
1518 yaml_scalar_event_initialize(&event, NULL,
1519 (yaml_char_t *)YAML_STR_TAG,
1520 (yaml_char_t *)"local NI(s)",
1521 strlen("local NI(s)"), 1, 0,
1522 YAML_PLAIN_SCALAR_STYLE);
1523 rc = yaml_emitter_emit(&output, &event);
1527 yaml_sequence_start_event_initialize(&event, NULL,
1528 (yaml_char_t *)YAML_SEQ_TAG,
1529 1, YAML_ANY_SEQUENCE_STYLE);
1530 rc = yaml_emitter_emit(&output, &event);
1534 list_for_each_entry(intf, &nw_descr->nw_intflist,
1536 yaml_mapping_start_event_initialize(&event, NULL,
1537 (yaml_char_t *)YAML_MAP_TAG,
1538 1, YAML_ANY_MAPPING_STYLE);
1539 rc = yaml_emitter_emit(&output, &event);
1543 yaml_scalar_event_initialize(&event, NULL,
1544 (yaml_char_t *)YAML_STR_TAG,
1545 (yaml_char_t *)"interfaces",
1546 strlen("interfaces"), 1, 0,
1547 YAML_PLAIN_SCALAR_STYLE);
1548 rc = yaml_emitter_emit(&output, &event);
1552 yaml_mapping_start_event_initialize(&event, NULL,
1553 (yaml_char_t *)YAML_MAP_TAG,
1554 1, YAML_ANY_MAPPING_STYLE);
1555 rc = yaml_emitter_emit(&output, &event);
1559 yaml_scalar_event_initialize(&event, NULL,
1560 (yaml_char_t *)YAML_STR_TAG,
1563 YAML_PLAIN_SCALAR_STYLE);
1564 rc = yaml_emitter_emit(&output, &event);
1568 yaml_scalar_event_initialize(&event, NULL,
1569 (yaml_char_t *)YAML_STR_TAG,
1570 (yaml_char_t *)intf->intf_name,
1571 strlen(intf->intf_name), 1, 0,
1572 YAML_PLAIN_SCALAR_STYLE);
1573 rc = yaml_emitter_emit(&output, &event);
1577 yaml_mapping_end_event_initialize(&event);
1578 rc = yaml_emitter_emit(&output, &event);
1583 rc = yaml_add_ni_tunables(&output, tunables, nw_descr);
1592 yaml_scalar_event_initialize(&event, NULL,
1593 (yaml_char_t *)YAML_STR_TAG,
1594 (yaml_char_t *)"CPT",
1595 strlen("CPT"), 1, 0,
1596 YAML_PLAIN_SCALAR_STYLE);
1597 rc = yaml_emitter_emit(&output, &event);
1601 yaml_sequence_start_event_initialize(&event, NULL,
1602 (yaml_char_t *)YAML_SEQ_TAG,
1604 YAML_FLOW_SEQUENCE_STYLE);
1605 rc = yaml_emitter_emit(&output, &event);
1609 count = cfs_expr_list_values(global_cpts,
1610 LNET_MAX_SHOW_NUM_CPT,
1612 for (i = 0; i < count; i++) {
1615 snprintf(core, sizeof(core), "%u", cpt_array[i]);
1616 yaml_scalar_event_initialize(&event, NULL,
1617 (yaml_char_t *)YAML_STR_TAG,
1618 (yaml_char_t *)core,
1620 YAML_PLAIN_SCALAR_STYLE);
1621 rc = yaml_emitter_emit(&output, &event);
1626 yaml_sequence_end_event_initialize(&event);
1627 rc = yaml_emitter_emit(&output, &event);
1631 cfs_expr_list_free(global_cpts);
1635 yaml_mapping_end_event_initialize(&event);
1636 rc = yaml_emitter_emit(&output, &event);
1641 yaml_sequence_end_event_initialize(&event);
1642 rc = yaml_emitter_emit(&output, &event);
1646 yaml_mapping_end_event_initialize(&event);
1647 rc = yaml_emitter_emit(&output, &event);
1651 yaml_sequence_end_event_initialize(&event);
1652 rc = yaml_emitter_emit(&output, &event);
1656 yaml_mapping_end_event_initialize(&event);
1657 rc = yaml_emitter_emit(&output, &event);
1661 yaml_document_end_event_initialize(&event, 0);
1662 rc = yaml_emitter_emit(&output, &event);
1666 rc = yaml_emitter_close(&output);
1669 yaml_emitter_log_error(&output, stderr);
1672 yaml_document_t errmsg;
1674 rc = yaml_parser_load(&reply, &errmsg);
1676 yaml_emitter_delete(&output);
1679 yaml_lnet_print_error(flags ? "add" : "del", "net",
1680 yaml_parser_get_reader_error(&reply));
1683 yaml_parser_delete(&reply);
1686 return rc == 1 ? 0 : rc;
1689 static int jt_add_ni(int argc, char **argv)
1691 char *ip2net = NULL;
1692 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
1693 struct cYAML *err_rc = NULL;
1694 int rc, opt, cpt_rc = -1;
1695 struct lnet_dlc_network_descr nw_descr;
1696 struct cfs_expr_list *global_cpts = NULL;
1697 struct lnet_ioctl_config_lnd_tunables tunables;
1699 bool skip_mr_route_setup = false;
1700 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:";
1701 static const struct option long_options[] = {
1702 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
1703 { .name = "peer-buffer-credits",
1704 .has_arg = required_argument, .val = 'b' },
1705 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
1706 { .name = "if", .has_arg = required_argument, .val = 'i' },
1707 { .name = "skip-mr-route-setup",
1708 .has_arg = no_argument, .val = 'k' },
1709 { .name = "conns-per-peer",
1710 .has_arg = required_argument, .val = 'm' },
1711 { .name = "net", .has_arg = required_argument, .val = 'n' },
1712 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
1713 { .name = "credits", .has_arg = required_argument, .val = 'r' },
1714 { .name = "cpt", .has_arg = required_argument, .val = 's' },
1715 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
1717 char *net_id = NULL;
1719 memset(&tunables, 0, sizeof(tunables));
1720 lustre_lnet_init_nw_descr(&nw_descr);
1722 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
1726 while ((opt = getopt_long(argc, argv, short_options,
1727 long_options, NULL)) != -1) {
1730 rc = parse_long(optarg, &auth_key);
1738 rc = parse_long(optarg, &pbc);
1746 rc = parse_long(optarg, &pc);
1754 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1756 cYAML_build_error(-1, -1, "ni", "add",
1757 "bad interface list",
1763 skip_mr_route_setup = true;
1766 rc = parse_long(optarg, &cpp);
1775 nw_descr.nw_id = libcfs_str2net(optarg);
1782 rc = parse_long(optarg, &cre);
1790 cpt_rc = cfs_expr_list_parse(optarg,
1792 UINT_MAX, &global_cpts);
1795 rc = parse_long(optarg, &pto);
1803 print_help(net_cmds, "net", "add");
1809 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
1810 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
1815 if (LNET_NETTYP(nw_descr.nw_id) == SOCKLND && (cpp > -1)) {
1816 tunables.lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
1818 } else if (LNET_NETTYP(nw_descr.nw_id) == O2IBLND && (cpp > -1)) {
1819 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
1823 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
1824 tunables.lt_cmn.lct_peer_timeout = pto;
1825 tunables.lt_cmn.lct_peer_tx_credits = pc;
1826 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1827 tunables.lt_cmn.lct_max_tx_credits = cre;
1831 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
1832 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
1834 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
1835 found ? &tunables : NULL,
1836 (cpt_rc == 0) ? global_cpts : NULL,
1839 if (rc == -EOPNOTSUPP)
1841 if (global_cpts != NULL)
1842 cfs_expr_list_free(global_cpts);
1843 if (rc == 0 && !skip_mr_route_setup)
1844 rc = lustre_lnet_setup_mrrouting(&err_rc);
1848 rc = lustre_lnet_config_ni(&nw_descr,
1849 (cpt_rc == 0) ? global_cpts: NULL,
1850 ip2net, (found) ? &tunables : NULL,
1853 if (global_cpts != NULL)
1854 cfs_expr_list_free(global_cpts);
1857 if (rc != LUSTRE_CFG_RC_NO_ERR)
1858 cYAML_print_tree2file(stderr, err_rc);
1860 cYAML_free_tree(err_rc);
1862 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
1864 rc = lustre_lnet_setup_mrrouting(&err_rc);
1866 if (rc != LUSTRE_CFG_RC_NO_ERR)
1867 cYAML_print_tree2file(stderr, err_rc);
1869 cYAML_free_tree(err_rc);
1875 static int jt_del_route(int argc, char **argv)
1877 char *network = NULL, *gateway = NULL;
1878 struct cYAML *err_rc = NULL;
1881 const char *const short_options = "n:g:";
1882 static const struct option long_options[] = {
1883 { .name = "net", .has_arg = required_argument, .val = 'n' },
1884 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1887 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1891 while ((opt = getopt_long(argc, argv, short_options,
1892 long_options, NULL)) != -1) {
1901 print_help(route_cmds, "route", "del");
1907 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1909 if (rc != LUSTRE_CFG_RC_NO_ERR)
1910 cYAML_print_tree2file(stderr, err_rc);
1912 cYAML_free_tree(err_rc);
1917 static int jt_del_ni(int argc, char **argv)
1919 struct cYAML *err_rc = NULL;
1921 struct lnet_dlc_network_descr nw_descr;
1922 const char *const short_options = "n:i:";
1923 static const struct option long_options[] = {
1924 { .name = "net", .has_arg = required_argument, .val = 'n' },
1925 { .name = "if", .has_arg = required_argument, .val = 'i' },
1927 char *net_id = NULL;
1929 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1933 lustre_lnet_init_nw_descr(&nw_descr);
1935 while ((opt = getopt_long(argc, argv, short_options,
1936 long_options, NULL)) != -1) {
1939 nw_descr.nw_id = libcfs_str2net(optarg);
1943 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1945 cYAML_build_error(-1, -1, "ni", "add",
1946 "bad interface list",
1952 print_help(net_cmds, "net", "del");
1958 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, NULL, 0);
1960 if (rc != -EOPNOTSUPP)
1964 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1966 if (rc != LUSTRE_CFG_RC_NO_ERR)
1967 cYAML_print_tree2file(stderr, err_rc);
1969 cYAML_free_tree(err_rc);
1974 static int jt_show_route(int argc, char **argv)
1976 char *network = NULL, *gateway = NULL;
1977 long int hop = -1, prio = -1;
1978 int detail = 0, rc, opt;
1979 struct cYAML *err_rc = NULL, *show_rc = NULL;
1981 const char *const short_options = "n:g:h:p:v";
1982 static const struct option long_options[] = {
1983 { .name = "net", .has_arg = required_argument, .val = 'n' },
1984 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1985 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1986 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1987 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1990 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1994 while ((opt = getopt_long(argc, argv, short_options,
1995 long_options, NULL)) != -1) {
2004 rc = parse_long(optarg, &hop);
2012 rc = parse_long(optarg, &prio);
2023 print_help(route_cmds, "route", "show");
2029 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
2030 &show_rc, &err_rc, false);
2032 if (rc != LUSTRE_CFG_RC_NO_ERR)
2033 cYAML_print_tree2file(stderr, err_rc);
2035 cYAML_print_tree(show_rc);
2037 cYAML_free_tree(err_rc);
2038 cYAML_free_tree(show_rc);
2043 static int set_value_helper(int argc, char **argv,
2044 int (*cb)(int, bool, char*, int, struct cYAML**))
2047 long int healthv = -1;
2050 struct cYAML *err_rc = NULL;
2052 const char *const short_options = "t:n:a";
2053 static const struct option long_options[] = {
2054 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2055 { .name = "health", .has_arg = required_argument, .val = 't' },
2056 { .name = "all", .has_arg = no_argument, .val = 'a' },
2059 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2063 while ((opt = getopt_long(argc, argv, short_options,
2064 long_options, NULL)) != -1) {
2070 if (parse_long(optarg, &healthv) != 0)
2081 rc = cb(healthv, all, nid, -1, &err_rc);
2083 if (rc != LUSTRE_CFG_RC_NO_ERR)
2084 cYAML_print_tree2file(stderr, err_rc);
2086 cYAML_free_tree(err_rc);
2091 static int jt_set_ni_value(int argc, char **argv)
2094 long int healthv = -1, cpp = -1;
2097 struct cYAML *err_rc = NULL;
2099 const char *const short_options = "a:m:n:t:";
2100 static const struct option long_options[] = {
2101 { .name = "all", .has_arg = no_argument, .val = 'a' },
2102 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2103 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2104 { .name = "health", .has_arg = required_argument, .val = 't' },
2107 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2111 while ((opt = getopt_long(argc, argv, short_options,
2112 long_options, NULL)) != -1) {
2118 rc = parse_long(optarg, &cpp);
2129 if (parse_long(optarg, &healthv) != 0) {
2141 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2144 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2147 if (rc != LUSTRE_CFG_RC_NO_ERR)
2148 cYAML_print_tree2file(stderr, err_rc);
2150 cYAML_free_tree(err_rc);
2155 static int jt_set_peer_ni_value(int argc, char **argv)
2157 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
2160 static int jt_show_recovery(int argc, char **argv)
2163 struct cYAML *err_rc = NULL, *show_rc = NULL;
2164 const char *const short_options = "lp";
2165 static const struct option long_options[] = {
2166 { .name = "local", .has_arg = no_argument, .val = 'l' },
2167 { .name = "peer", .has_arg = no_argument, .val = 'p' },
2170 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
2174 while ((opt = getopt_long(argc, argv, short_options,
2175 long_options, NULL)) != -1) {
2178 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
2181 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
2188 if (rc != LUSTRE_CFG_RC_NO_ERR)
2189 cYAML_print_tree2file(stderr, err_rc);
2191 cYAML_print_tree(show_rc);
2193 cYAML_free_tree(err_rc);
2194 cYAML_free_tree(show_rc);
2199 static int jt_show_peer_debug_info(int argc, char **argv)
2202 struct cYAML *err_rc = NULL;
2203 char *peer_nid = optarg;
2204 const char *const short_opts = "k";
2205 const struct option long_opts[] = {
2206 { .name = "nid", .has_arg = required_argument, .val = 'k' },
2209 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
2214 while ((opt = getopt_long(argc, argv, short_opts,
2215 long_opts, NULL)) != -1) {
2225 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
2227 if (rc != LUSTRE_CFG_RC_NO_ERR)
2228 cYAML_print_tree2file(stderr, err_rc);
2230 cYAML_free_tree(err_rc);
2235 static int jt_show_net(int argc, char **argv)
2237 char *network = NULL;
2239 struct cYAML *err_rc = NULL, *show_rc = NULL;
2240 long int detail = 0;
2242 const char *const short_options = "n:v";
2243 static const struct option long_options[] = {
2244 { .name = "net", .has_arg = required_argument, .val = 'n' },
2245 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2248 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
2252 while ((opt = getopt_long(argc, argv, short_options,
2253 long_options, NULL)) != -1) {
2259 if ((!optarg) && (argv[optind] != NULL) &&
2260 (argv[optind][0] != '-')) {
2261 if (parse_long(argv[optind++], &detail) != 0)
2268 print_help(net_cmds, "net", "show");
2274 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
2277 if (rc != LUSTRE_CFG_RC_NO_ERR)
2278 cYAML_print_tree2file(stderr, err_rc);
2280 cYAML_print_tree(show_rc);
2282 cYAML_free_tree(err_rc);
2283 cYAML_free_tree(show_rc);
2288 static int jt_show_routing(int argc, char **argv)
2290 struct cYAML *err_rc = NULL, *show_rc = NULL;
2293 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
2297 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
2299 if (rc != LUSTRE_CFG_RC_NO_ERR)
2300 cYAML_print_tree2file(stderr, err_rc);
2302 cYAML_print_tree(show_rc);
2304 cYAML_free_tree(err_rc);
2305 cYAML_free_tree(show_rc);
2310 static int jt_show_stats(int argc, char **argv)
2313 struct cYAML *show_rc = NULL, *err_rc = NULL;
2315 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
2319 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
2321 if (rc != LUSTRE_CFG_RC_NO_ERR)
2322 cYAML_print_tree2file(stderr, err_rc);
2324 cYAML_print_tree(show_rc);
2326 cYAML_free_tree(err_rc);
2327 cYAML_free_tree(show_rc);
2332 static int jt_show_udsp(int argc, char **argv)
2336 struct cYAML *err_rc = NULL, *show_rc = NULL;
2338 const char *const short_options = "i:";
2339 static const struct option long_options[] = {
2340 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2344 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
2348 while ((opt = getopt_long(argc, argv, short_options,
2349 long_options, NULL)) != -1) {
2355 print_help(net_cmds, "net", "show");
2361 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
2363 if (rc != LUSTRE_CFG_RC_NO_ERR)
2364 cYAML_print_tree2file(stderr, err_rc);
2366 cYAML_print_tree(show_rc);
2368 cYAML_free_tree(err_rc);
2369 cYAML_free_tree(show_rc);
2374 static int jt_show_global(int argc, char **argv)
2377 struct cYAML *show_rc = NULL, *err_rc = NULL;
2379 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
2383 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2384 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2385 cYAML_print_tree2file(stderr, err_rc);
2389 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
2390 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2391 cYAML_print_tree2file(stderr, err_rc);
2395 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
2396 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2397 cYAML_print_tree2file(stderr, err_rc);
2401 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2402 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2403 cYAML_print_tree2file(stderr, err_rc);
2407 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2408 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2409 cYAML_print_tree2file(stderr, err_rc);
2413 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2414 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2415 cYAML_print_tree2file(stderr, err_rc);
2419 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
2420 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2421 cYAML_print_tree2file(stderr, err_rc);
2425 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
2426 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2427 cYAML_print_tree2file(stderr, err_rc);
2431 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
2432 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2433 cYAML_print_tree2file(stderr, err_rc);
2437 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
2438 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2439 cYAML_print_tree2file(stderr, err_rc);
2443 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
2444 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2445 cYAML_print_tree2file(stderr, err_rc);
2449 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2450 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2451 cYAML_print_tree2file(stderr, err_rc);
2455 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2456 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2457 cYAML_print_tree2file(stderr, err_rc);
2462 cYAML_print_tree(show_rc);
2465 cYAML_free_tree(err_rc);
2466 cYAML_free_tree(show_rc);
2471 static int jt_lnet(int argc, char **argv)
2475 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
2479 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
2482 static int jt_route(int argc, char **argv)
2486 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
2490 return Parser_execarg(argc - 1, &argv[1], route_cmds);
2493 static int jt_net(int argc, char **argv)
2497 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
2501 return Parser_execarg(argc - 1, &argv[1], net_cmds);
2504 static int jt_routing(int argc, char **argv)
2508 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
2512 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
2515 static int jt_stats(int argc, char **argv)
2519 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
2523 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
2526 static int jt_debug(int argc, char **argv)
2530 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
2534 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
2537 static int jt_global(int argc, char **argv)
2541 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
2545 return Parser_execarg(argc - 1, &argv[1], global_cmds);
2548 static int jt_peers(int argc, char **argv)
2552 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
2556 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
2559 static int jt_set(int argc, char **argv)
2563 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
2567 return Parser_execarg(argc - 1, &argv[1], set_cmds);
2570 static int jt_udsp(int argc, char **argv)
2574 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
2578 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
2581 static int jt_import(int argc, char **argv)
2584 struct cYAML *err_rc = NULL;
2585 struct cYAML *show_rc = NULL;
2586 int rc = 0, return_rc = 0, opt, opt_found = 0;
2589 const char *const short_options = "adseh";
2590 static const struct option long_options[] = {
2591 { .name = "add", .has_arg = no_argument, .val = 'a' },
2592 { .name = "del", .has_arg = no_argument, .val = 'd' },
2593 { .name = "show", .has_arg = no_argument, .val = 's' },
2594 { .name = "exec", .has_arg = no_argument, .val = 'e' },
2595 { .name = "help", .has_arg = no_argument, .val = 'h' },
2598 while ((opt = getopt_long(argc, argv, short_options,
2599 long_options, NULL)) != -1) {
2613 printf("import FILE\n"
2614 "import < FILE : import a file\n"
2615 "\t--add: add configuration\n"
2616 "\t--del: delete configuration\n"
2617 "\t--show: show configuration\n"
2618 "\t--exec: execute command\n"
2619 "\t--help: display this help\n"
2620 "If no command option is given then --add"
2621 " is assumed by default\n");
2628 /* grab the file name if one exists */
2629 if (opt_found && argc == 3)
2631 else if (!opt_found && argc == 2)
2636 rc = lustre_yaml_config(file, &err_rc);
2637 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
2638 cYAML_print_tree(show_rc);
2639 cYAML_free_tree(show_rc);
2642 rc = lustre_yaml_del(file, &err_rc);
2645 rc = lustre_yaml_show(file, &show_rc, &err_rc);
2646 cYAML_print_tree(show_rc);
2647 cYAML_free_tree(show_rc);
2650 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
2651 cYAML_print_tree(show_rc);
2652 cYAML_free_tree(show_rc);
2656 if (rc || return_rc) {
2657 cYAML_print_tree2file(stderr, err_rc);
2658 cYAML_free_tree(err_rc);
2664 static int jt_export(int argc, char **argv)
2666 struct cYAML *show_rc = NULL;
2667 struct cYAML *err_rc = NULL;
2671 bool backup = false;
2674 const char *const short_options = "bh";
2675 static const struct option long_options[] = {
2676 { .name = "backup", .has_arg = no_argument, .val = 'b' },
2677 { .name = "help", .has_arg = no_argument, .val = 'h' },
2680 while ((opt = getopt_long(argc, argv, short_options,
2681 long_options, NULL)) != -1) {
2688 printf("export > FILE.yaml : export configuration\n"
2689 "\t--backup: export only what's necessary for reconfig\n"
2690 "\t--help: display this help\n");
2695 if (backup && argc >= 3)
2697 else if (!backup && argc >= 2)
2703 f = fopen(file, "w");
2708 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
2709 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2710 cYAML_print_tree2file(stderr, err_rc);
2711 cYAML_free_tree(err_rc);
2715 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
2717 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2718 cYAML_print_tree2file(stderr, err_rc);
2719 cYAML_free_tree(err_rc);
2723 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
2724 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2725 cYAML_print_tree2file(stderr, err_rc);
2726 cYAML_free_tree(err_rc);
2730 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
2731 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2732 cYAML_print_tree2file(stderr, err_rc);
2733 cYAML_free_tree(err_rc);
2737 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2738 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2739 cYAML_print_tree2file(stderr, err_rc);
2740 cYAML_free_tree(err_rc);
2744 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
2745 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2746 cYAML_print_tree2file(stderr, err_rc);
2747 cYAML_free_tree(err_rc);
2751 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
2752 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2753 cYAML_print_tree2file(stderr, err_rc);
2754 cYAML_free_tree(err_rc);
2758 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2759 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2760 cYAML_print_tree2file(stderr, err_rc);
2761 cYAML_free_tree(err_rc);
2765 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2766 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2767 cYAML_print_tree2file(stderr, err_rc);
2771 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2772 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2773 cYAML_print_tree2file(stderr, err_rc);
2777 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
2778 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2779 cYAML_print_tree2file(stderr, err_rc);
2783 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
2784 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2785 cYAML_print_tree2file(stderr, err_rc);
2789 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
2790 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2791 cYAML_print_tree2file(stderr, err_rc);
2795 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
2796 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2797 cYAML_print_tree2file(stderr, err_rc);
2801 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
2802 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2803 cYAML_print_tree2file(stderr, err_rc);
2804 cYAML_free_tree(err_rc);
2808 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2809 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2810 cYAML_print_tree2file(stderr, err_rc);
2811 cYAML_free_tree(err_rc);
2815 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2816 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2817 cYAML_print_tree2file(stderr, err_rc);
2818 cYAML_free_tree(err_rc);
2822 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
2823 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2824 cYAML_print_tree2file(stderr, err_rc);
2825 cYAML_free_tree(err_rc);
2829 if (show_rc != NULL) {
2830 cYAML_print_tree2file(f, show_rc);
2831 cYAML_free_tree(show_rc);
2840 static int jt_peer_nid_common(int argc, char **argv, int cmd)
2842 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
2844 char *prim_nid = NULL, *nidstr = NULL;
2845 char err_str[LNET_MAX_STR_LEN] = "Error";
2846 struct cYAML *err_rc = NULL;
2848 const char *const short_opts = "k:mn:";
2849 const struct option long_opts[] = {
2850 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2851 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2852 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2855 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2859 while ((opt = getopt_long(argc, argv, short_opts,
2860 long_opts, NULL)) != -1) {
2869 if (cmd == LNETCTL_DEL_CMD) {
2870 rc = LUSTRE_CFG_RC_BAD_PARAM;
2871 snprintf(err_str, LNET_MAX_STR_LEN,
2872 "Unrecognized option '-%c'", opt);
2878 print_help(peer_cmds, "peer",
2879 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2885 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2887 if (rc != LUSTRE_CFG_RC_NO_ERR)
2891 cYAML_build_error(rc, -1, "peer",
2892 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2896 if (rc != LUSTRE_CFG_RC_NO_ERR)
2897 cYAML_print_tree2file(stderr, err_rc);
2899 cYAML_free_tree(err_rc);
2904 static int jt_add_peer_nid(int argc, char **argv)
2906 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2909 static int jt_del_peer_nid(int argc, char **argv)
2911 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2914 static int jt_show_peer(int argc, char **argv)
2918 struct cYAML *err_rc = NULL, *show_rc = NULL;
2919 long int detail = 0;
2921 const char *const short_opts = "hn:v::";
2922 const struct option long_opts[] = {
2923 { .name = "help", .has_arg = no_argument, .val = 'h' },
2924 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2925 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2928 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2932 while ((opt = getopt_long(argc, argv, short_opts,
2933 long_opts, NULL)) != -1) {
2939 if ((!optarg) && (argv[optind] != NULL) &&
2940 (argv[optind][0] != '-')) {
2941 if (parse_long(argv[optind++], &detail) != 0)
2948 print_help(peer_cmds, "peer", "show");
2954 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2957 if (rc != LUSTRE_CFG_RC_NO_ERR)
2958 cYAML_print_tree2file(stderr, err_rc);
2960 cYAML_print_tree(show_rc);
2962 cYAML_free_tree(err_rc);
2963 cYAML_free_tree(show_rc);
2968 static int jt_list_peer(int argc, char **argv)
2971 struct cYAML *err_rc = NULL, *list_rc = NULL;
2973 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2977 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2979 if (rc != LUSTRE_CFG_RC_NO_ERR)
2980 cYAML_print_tree2file(stderr, err_rc);
2982 cYAML_print_tree(list_rc);
2984 cYAML_free_tree(err_rc);
2985 cYAML_free_tree(list_rc);
2990 static int jt_ping(int argc, char **argv)
2992 struct cYAML *err_rc = NULL;
2993 struct cYAML *show_rc = NULL;
2996 char *src_nidstr = NULL;
2998 const char *const short_options = "hs:t:";
2999 const struct option long_options[] = {
3000 { .name = "help", .has_arg = no_argument, .val = 'h' },
3001 { .name = "timeout", .has_arg = required_argument, .val = 't' },
3002 { .name = "source", .has_arg = required_argument, .val = 's' },
3005 while ((opt = getopt_long(argc, argv, short_options,
3006 long_options, NULL)) != -1) {
3009 src_nidstr = optarg;
3012 timeout = 1000 * atol(optarg);
3015 printf("ping nid[,nid,...]\n"
3016 "\t --source: source nid\n"
3017 "\t --timeout: ping timeout\n"
3018 "\t --help: display this help\n");
3025 for (; optind < argc; optind++)
3026 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
3030 cYAML_print_tree(show_rc);
3033 cYAML_print_tree2file(stderr, err_rc);
3035 cYAML_free_tree(err_rc);
3036 cYAML_free_tree(show_rc);
3041 static int jt_discover(int argc, char **argv)
3043 struct cYAML *err_rc = NULL;
3044 struct cYAML *show_rc = NULL;
3048 const char *const short_options = "fh";
3049 const struct option long_options[] = {
3050 { .name = "force", .has_arg = no_argument, .val = 'f' },
3051 { .name = "help", .has_arg = no_argument, .val = 'h' },
3054 while ((opt = getopt_long(argc, argv, short_options,
3055 long_options, NULL)) != -1) {
3061 printf("discover nid[,nid,...]\n"
3062 "\t --force: force discovery\n"
3063 "\t --help: display this help\n");
3070 for (; optind < argc; optind++)
3071 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
3075 cYAML_print_tree(show_rc);
3078 cYAML_print_tree2file(stderr, err_rc);
3080 cYAML_free_tree(err_rc);
3081 cYAML_free_tree(show_rc);
3086 static int jt_add_udsp(int argc, char **argv)
3088 char *src = NULL, *dst = NULL, *rte = NULL;
3089 struct cYAML *err_rc = NULL;
3090 union lnet_udsp_action udsp_action;
3091 long int idx = -1, priority = -1;
3093 char *action_type = "pref";
3095 const char *const short_options = "s:d:r:p:i:";
3096 static const struct option long_options[] = {
3097 { .name = "src", .has_arg = required_argument, .val = 's' },
3098 { .name = "dst", .has_arg = required_argument, .val = 'd' },
3099 { .name = "rte", .has_arg = required_argument, .val = 'r' },
3100 { .name = "priority", .has_arg = required_argument, .val = 'p' },
3101 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3104 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
3108 while ((opt = getopt_long(argc, argv, short_options,
3109 long_options, NULL)) != -1) {
3121 rc = parse_long(optarg, &priority);
3124 action_type = "priority";
3125 udsp_action.udsp_priority = priority;
3128 rc = parse_long(optarg, &idx);
3133 print_help(udsp_cmds, "udsp", "add");
3139 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
3142 if (rc != LUSTRE_CFG_RC_NO_ERR)
3143 cYAML_print_tree2file(stderr, err_rc);
3145 cYAML_free_tree(err_rc);
3150 static int jt_del_udsp(int argc, char **argv)
3152 struct cYAML *err_rc = NULL;
3156 const char *const short_options = "i:";
3157 static const struct option long_options[] = {
3158 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3161 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
3165 while ((opt = getopt_long(argc, argv, short_options,
3166 long_options, NULL)) != -1) {
3169 rc = parse_long(optarg, &idx);
3174 print_help(udsp_cmds, "udsp", "add");
3180 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
3181 if (rc != LUSTRE_CFG_RC_NO_ERR)
3182 cYAML_print_tree2file(stderr, err_rc);
3184 cYAML_free_tree(err_rc);
3189 static int lnetctl_list_commands(int argc, char **argv)
3191 Parser_list_commands(cmd_list, 80, 4);
3196 int main(int argc, char **argv)
3199 struct cYAML *err_rc = NULL;
3201 rc = lustre_lnet_config_lib_init();
3203 cYAML_build_error(-1, -1, "lnetctl", "startup",
3204 "cannot register LNet device", &err_rc);
3205 cYAML_print_tree2file(stderr, err_rc);
3209 Parser_init("lnetctl > ", cmd_list);
3211 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);