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,
1197 yaml_scalar_event_initialize(&event, NULL,
1198 (yaml_char_t *)YAML_STR_TAG,
1199 (yaml_char_t *)"tunables",
1200 strlen("tunables"), 1, 0,
1201 YAML_PLAIN_SCALAR_STYLE);
1202 rc = yaml_emitter_emit(output, &event);
1206 yaml_mapping_start_event_initialize(&event, NULL,
1207 (yaml_char_t *)YAML_MAP_TAG,
1208 1, YAML_ANY_MAPPING_STYLE);
1209 rc = yaml_emitter_emit(output, &event);
1213 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1214 yaml_scalar_event_initialize(&event, NULL,
1215 (yaml_char_t *)YAML_STR_TAG,
1216 (yaml_char_t *)"peer_timeout",
1217 strlen("peer_timeout"), 1, 0,
1218 YAML_PLAIN_SCALAR_STYLE);
1219 rc = yaml_emitter_emit(output, &event);
1223 snprintf(num, sizeof(num), "%u",
1224 tunables->lt_cmn.lct_peer_timeout);
1225 yaml_scalar_event_initialize(&event, NULL,
1226 (yaml_char_t *)YAML_INT_TAG,
1229 YAML_PLAIN_SCALAR_STYLE);
1230 rc = yaml_emitter_emit(output, &event);
1235 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1236 yaml_scalar_event_initialize(&event, NULL,
1237 (yaml_char_t *)YAML_STR_TAG,
1238 (yaml_char_t *)"peer_credits",
1239 strlen("peer_credits"), 1, 0,
1240 YAML_PLAIN_SCALAR_STYLE);
1241 rc = yaml_emitter_emit(output, &event);
1245 snprintf(num, sizeof(num), "%u",
1246 tunables->lt_cmn.lct_peer_tx_credits);
1247 yaml_scalar_event_initialize(&event, NULL,
1248 (yaml_char_t *)YAML_INT_TAG,
1251 YAML_PLAIN_SCALAR_STYLE);
1252 rc = yaml_emitter_emit(output, &event);
1257 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1258 yaml_scalar_event_initialize(&event, NULL,
1259 (yaml_char_t *)YAML_STR_TAG,
1260 (yaml_char_t *)"peer_buffer_credits",
1261 strlen("peer_buffer_credits"), 1, 0,
1262 YAML_PLAIN_SCALAR_STYLE);
1263 rc = yaml_emitter_emit(output, &event);
1267 snprintf(num, sizeof(num), "%u",
1268 tunables->lt_cmn.lct_peer_rtr_credits);
1269 yaml_scalar_event_initialize(&event, NULL,
1270 (yaml_char_t *)YAML_INT_TAG,
1273 YAML_PLAIN_SCALAR_STYLE);
1274 rc = yaml_emitter_emit(output, &event);
1279 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1280 yaml_scalar_event_initialize(&event, NULL,
1281 (yaml_char_t *)YAML_STR_TAG,
1282 (yaml_char_t *)"credits",
1283 strlen("credits"), 1, 0,
1284 YAML_PLAIN_SCALAR_STYLE);
1285 rc = yaml_emitter_emit(output, &event);
1289 snprintf(num, sizeof(num), "%u",
1290 tunables->lt_cmn.lct_max_tx_credits);
1291 yaml_scalar_event_initialize(&event, NULL,
1292 (yaml_char_t *)YAML_INT_TAG,
1295 YAML_PLAIN_SCALAR_STYLE);
1296 rc = yaml_emitter_emit(output, &event);
1301 yaml_mapping_end_event_initialize(&event);
1302 rc = yaml_emitter_emit(output, &event);
1306 if (cpp > 0 || tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1307 yaml_scalar_event_initialize(&event, NULL,
1308 (yaml_char_t *)YAML_STR_TAG,
1309 (yaml_char_t *)"lnd tunables",
1310 strlen("lnd tunables"), 1, 0,
1311 YAML_PLAIN_SCALAR_STYLE);
1312 rc = yaml_emitter_emit(output, &event);
1316 yaml_mapping_start_event_initialize(&event, NULL,
1317 (yaml_char_t *)YAML_MAP_TAG,
1318 1, YAML_ANY_MAPPING_STYLE);
1319 rc = yaml_emitter_emit(output, &event);
1323 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1324 yaml_scalar_event_initialize(&event, NULL,
1325 (yaml_char_t *)YAML_STR_TAG,
1326 (yaml_char_t *)"auth_key",
1327 strlen("auth_key"), 1, 0,
1328 YAML_PLAIN_SCALAR_STYLE);
1329 rc = yaml_emitter_emit(output, &event);
1333 snprintf(num, sizeof(num), "%u",
1334 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1336 yaml_scalar_event_initialize(&event, NULL,
1337 (yaml_char_t *)YAML_STR_TAG,
1338 (yaml_char_t *)"conns_per_peer",
1339 strlen("conns_per_peer"), 1, 0,
1340 YAML_PLAIN_SCALAR_STYLE);
1341 rc = yaml_emitter_emit(output, &event);
1345 snprintf(num, sizeof(num), "%u", cpp);
1348 yaml_scalar_event_initialize(&event, NULL,
1349 (yaml_char_t *)YAML_INT_TAG,
1352 YAML_PLAIN_SCALAR_STYLE);
1353 rc = yaml_emitter_emit(output, &event);
1357 yaml_mapping_end_event_initialize(&event);
1358 rc = yaml_emitter_emit(output, &event);
1366 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1367 struct lnet_dlc_network_descr *nw_descr,
1368 struct lnet_ioctl_config_lnd_tunables *tunables,
1369 int cpp, struct cfs_expr_list *global_cpts,
1372 struct lnet_dlc_intf_descr *intf;
1373 struct nl_sock *sk = NULL;
1374 yaml_emitter_t output;
1375 yaml_parser_t reply;
1379 if (!ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1380 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1381 (!nw_descr) ? "network , interface" :
1382 (nw_descr->nw_id == 0) ? "network" : "interface");
1386 if ((flags == NLM_F_CREATE) && list_empty(&nw_descr->nw_intflist)) {
1387 fprintf(stdout, "creating a local NI needs at least one interface");
1391 /* Create Netlink emitter to send request to kernel */
1392 sk = nl_socket_alloc();
1396 /* Setup parser to receive Netlink packets */
1397 rc = yaml_parser_initialize(&reply);
1403 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1407 /* Create Netlink emitter to send request to kernel */
1408 rc = yaml_emitter_initialize(&output);
1412 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1413 LNET_GENL_VERSION, LNET_CMD_NETS,
1418 yaml_emitter_open(&output);
1419 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1420 rc = yaml_emitter_emit(&output, &event);
1424 yaml_mapping_start_event_initialize(&event, NULL,
1425 (yaml_char_t *)YAML_MAP_TAG,
1426 1, YAML_ANY_MAPPING_STYLE);
1427 rc = yaml_emitter_emit(&output, &event);
1431 yaml_scalar_event_initialize(&event, NULL,
1432 (yaml_char_t *)YAML_STR_TAG,
1433 (yaml_char_t *)"net",
1434 strlen("net"), 1, 0,
1435 YAML_PLAIN_SCALAR_STYLE);
1436 rc = yaml_emitter_emit(&output, &event);
1440 if (net_id || ip2net) {
1441 char *key = net_id ? "net type" : "ip2net";
1442 char *value = net_id ? net_id : ip2net;
1444 yaml_sequence_start_event_initialize(&event, NULL,
1445 (yaml_char_t *)YAML_SEQ_TAG,
1446 1, YAML_ANY_SEQUENCE_STYLE);
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,
1462 1, 0, YAML_PLAIN_SCALAR_STYLE);
1463 rc = yaml_emitter_emit(&output, &event);
1467 yaml_scalar_event_initialize(&event, NULL,
1468 (yaml_char_t *)YAML_STR_TAG,
1469 (yaml_char_t *)value,
1470 strlen(value), 1, 0,
1471 YAML_PLAIN_SCALAR_STYLE);
1472 rc = yaml_emitter_emit(&output, &event);
1476 yaml_scalar_event_initialize(&event, NULL,
1477 (yaml_char_t *)YAML_STR_TAG,
1480 YAML_PLAIN_SCALAR_STYLE);
1481 rc = yaml_emitter_emit(&output, &event);
1488 if (list_empty(&nw_descr->nw_intflist))
1491 yaml_scalar_event_initialize(&event, NULL,
1492 (yaml_char_t *)YAML_STR_TAG,
1493 (yaml_char_t *)"local NI(s)",
1494 strlen("local NI(s)"), 1, 0,
1495 YAML_PLAIN_SCALAR_STYLE);
1496 rc = yaml_emitter_emit(&output, &event);
1500 yaml_sequence_start_event_initialize(&event, NULL,
1501 (yaml_char_t *)YAML_SEQ_TAG,
1502 1, YAML_ANY_SEQUENCE_STYLE);
1503 rc = yaml_emitter_emit(&output, &event);
1507 list_for_each_entry(intf, &nw_descr->nw_intflist,
1509 yaml_mapping_start_event_initialize(&event, NULL,
1510 (yaml_char_t *)YAML_MAP_TAG,
1511 1, YAML_ANY_MAPPING_STYLE);
1512 rc = yaml_emitter_emit(&output, &event);
1516 yaml_scalar_event_initialize(&event, NULL,
1517 (yaml_char_t *)YAML_STR_TAG,
1518 (yaml_char_t *)"interfaces",
1519 strlen("interfaces"), 1, 0,
1520 YAML_PLAIN_SCALAR_STYLE);
1521 rc = yaml_emitter_emit(&output, &event);
1525 yaml_mapping_start_event_initialize(&event, NULL,
1526 (yaml_char_t *)YAML_MAP_TAG,
1527 1, YAML_ANY_MAPPING_STYLE);
1528 rc = yaml_emitter_emit(&output, &event);
1532 yaml_scalar_event_initialize(&event, NULL,
1533 (yaml_char_t *)YAML_STR_TAG,
1536 YAML_PLAIN_SCALAR_STYLE);
1537 rc = yaml_emitter_emit(&output, &event);
1541 yaml_scalar_event_initialize(&event, NULL,
1542 (yaml_char_t *)YAML_STR_TAG,
1543 (yaml_char_t *)intf->intf_name,
1544 strlen(intf->intf_name), 1, 0,
1545 YAML_PLAIN_SCALAR_STYLE);
1546 rc = yaml_emitter_emit(&output, &event);
1550 yaml_mapping_end_event_initialize(&event);
1551 rc = yaml_emitter_emit(&output, &event);
1556 rc = yaml_add_ni_tunables(&output, tunables, cpp);
1565 yaml_scalar_event_initialize(&event, NULL,
1566 (yaml_char_t *)YAML_STR_TAG,
1567 (yaml_char_t *)"CPT",
1568 strlen("CPT"), 1, 0,
1569 YAML_PLAIN_SCALAR_STYLE);
1570 rc = yaml_emitter_emit(&output, &event);
1574 yaml_sequence_start_event_initialize(&event, NULL,
1575 (yaml_char_t *)YAML_SEQ_TAG,
1577 YAML_FLOW_SEQUENCE_STYLE);
1578 rc = yaml_emitter_emit(&output, &event);
1582 count = cfs_expr_list_values(global_cpts,
1583 LNET_MAX_SHOW_NUM_CPT,
1585 for (i = 0; i < count; i++) {
1588 snprintf(core, sizeof(core), "%u", cpt_array[i]);
1589 yaml_scalar_event_initialize(&event, NULL,
1590 (yaml_char_t *)YAML_STR_TAG,
1591 (yaml_char_t *)core,
1593 YAML_PLAIN_SCALAR_STYLE);
1594 rc = yaml_emitter_emit(&output, &event);
1599 yaml_sequence_end_event_initialize(&event);
1600 rc = yaml_emitter_emit(&output, &event);
1604 cfs_expr_list_free(global_cpts);
1608 yaml_mapping_end_event_initialize(&event);
1609 rc = yaml_emitter_emit(&output, &event);
1614 yaml_sequence_end_event_initialize(&event);
1615 rc = yaml_emitter_emit(&output, &event);
1619 yaml_mapping_end_event_initialize(&event);
1620 rc = yaml_emitter_emit(&output, &event);
1624 yaml_sequence_end_event_initialize(&event);
1625 rc = yaml_emitter_emit(&output, &event);
1629 yaml_mapping_end_event_initialize(&event);
1630 rc = yaml_emitter_emit(&output, &event);
1634 yaml_document_end_event_initialize(&event, 0);
1635 rc = yaml_emitter_emit(&output, &event);
1639 rc = yaml_emitter_close(&output);
1642 yaml_emitter_log_error(&output, stderr);
1645 yaml_document_t errmsg;
1647 rc = yaml_parser_load(&reply, &errmsg);
1649 yaml_emitter_delete(&output);
1652 yaml_lnet_print_error(flags ? "add" : "del", "net",
1653 yaml_parser_get_reader_error(&reply));
1656 yaml_parser_delete(&reply);
1659 return rc == 1 ? 0 : rc;
1662 static int jt_add_ni(int argc, char **argv)
1664 char *ip2net = NULL;
1665 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
1666 struct cYAML *err_rc = NULL;
1667 int rc, opt, cpt_rc = -1;
1668 struct lnet_dlc_network_descr nw_descr;
1669 struct cfs_expr_list *global_cpts = NULL;
1670 struct lnet_ioctl_config_lnd_tunables tunables;
1672 bool skip_mr_route_setup = false;
1673 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:";
1674 static const struct option long_options[] = {
1675 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
1676 { .name = "peer-buffer-credits",
1677 .has_arg = required_argument, .val = 'b' },
1678 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
1679 { .name = "if", .has_arg = required_argument, .val = 'i' },
1680 { .name = "skip-mr-route-setup",
1681 .has_arg = no_argument, .val = 'k' },
1682 { .name = "conns-per-peer",
1683 .has_arg = required_argument, .val = 'm' },
1684 { .name = "net", .has_arg = required_argument, .val = 'n' },
1685 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
1686 { .name = "credits", .has_arg = required_argument, .val = 'r' },
1687 { .name = "cpt", .has_arg = required_argument, .val = 's' },
1688 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
1690 char *net_id = NULL;
1692 memset(&tunables, 0, sizeof(tunables));
1693 lustre_lnet_init_nw_descr(&nw_descr);
1695 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
1699 while ((opt = getopt_long(argc, argv, short_options,
1700 long_options, NULL)) != -1) {
1703 rc = parse_long(optarg, &auth_key);
1711 rc = parse_long(optarg, &pbc);
1719 rc = parse_long(optarg, &pc);
1727 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1729 cYAML_build_error(-1, -1, "ni", "add",
1730 "bad interface list",
1736 skip_mr_route_setup = true;
1739 rc = parse_long(optarg, &cpp);
1748 nw_descr.nw_id = libcfs_str2net(optarg);
1755 rc = parse_long(optarg, &cre);
1763 cpt_rc = cfs_expr_list_parse(optarg,
1765 UINT_MAX, &global_cpts);
1768 rc = parse_long(optarg, &pto);
1776 print_help(net_cmds, "net", "add");
1782 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
1783 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
1787 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
1788 tunables.lt_cmn.lct_peer_timeout = pto;
1789 tunables.lt_cmn.lct_peer_tx_credits = pc;
1790 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1791 tunables.lt_cmn.lct_max_tx_credits = cre;
1795 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
1796 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
1798 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
1799 found ? &tunables : NULL, cpp,
1800 (cpt_rc == 0) ? global_cpts : NULL,
1803 if (rc == -EOPNOTSUPP)
1805 if (global_cpts != NULL)
1806 cfs_expr_list_free(global_cpts);
1807 if (rc == 0 && !skip_mr_route_setup)
1808 rc = lustre_lnet_setup_mrrouting(&err_rc);
1812 rc = lustre_lnet_config_ni(&nw_descr,
1813 (cpt_rc == 0) ? global_cpts: NULL,
1814 ip2net, (found) ? &tunables : NULL,
1817 if (global_cpts != NULL)
1818 cfs_expr_list_free(global_cpts);
1821 if (rc != LUSTRE_CFG_RC_NO_ERR)
1822 cYAML_print_tree2file(stderr, err_rc);
1824 cYAML_free_tree(err_rc);
1826 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
1828 rc = lustre_lnet_setup_mrrouting(&err_rc);
1830 if (rc != LUSTRE_CFG_RC_NO_ERR)
1831 cYAML_print_tree2file(stderr, err_rc);
1833 cYAML_free_tree(err_rc);
1839 static int jt_del_route(int argc, char **argv)
1841 char *network = NULL, *gateway = NULL;
1842 struct cYAML *err_rc = NULL;
1845 const char *const short_options = "n:g:";
1846 static const struct option long_options[] = {
1847 { .name = "net", .has_arg = required_argument, .val = 'n' },
1848 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1851 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1855 while ((opt = getopt_long(argc, argv, short_options,
1856 long_options, NULL)) != -1) {
1865 print_help(route_cmds, "route", "del");
1871 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1873 if (rc != LUSTRE_CFG_RC_NO_ERR)
1874 cYAML_print_tree2file(stderr, err_rc);
1876 cYAML_free_tree(err_rc);
1881 static int jt_del_ni(int argc, char **argv)
1883 struct cYAML *err_rc = NULL;
1885 struct lnet_dlc_network_descr nw_descr;
1886 const char *const short_options = "n:i:";
1887 static const struct option long_options[] = {
1888 { .name = "net", .has_arg = required_argument, .val = 'n' },
1889 { .name = "if", .has_arg = required_argument, .val = 'i' },
1891 char *net_id = NULL;
1893 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1897 lustre_lnet_init_nw_descr(&nw_descr);
1899 while ((opt = getopt_long(argc, argv, short_options,
1900 long_options, NULL)) != -1) {
1903 nw_descr.nw_id = libcfs_str2net(optarg);
1907 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1909 cYAML_build_error(-1, -1, "ni", "add",
1910 "bad interface list",
1916 print_help(net_cmds, "net", "del");
1922 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, -1, NULL, 0);
1924 if (rc != -EOPNOTSUPP)
1928 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1930 if (rc != LUSTRE_CFG_RC_NO_ERR)
1931 cYAML_print_tree2file(stderr, err_rc);
1933 cYAML_free_tree(err_rc);
1938 static int jt_show_route(int argc, char **argv)
1940 char *network = NULL, *gateway = NULL;
1941 long int hop = -1, prio = -1;
1942 int detail = 0, rc, opt;
1943 struct cYAML *err_rc = NULL, *show_rc = NULL;
1945 const char *const short_options = "n:g:h:p:v";
1946 static const struct option long_options[] = {
1947 { .name = "net", .has_arg = required_argument, .val = 'n' },
1948 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1949 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1950 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1951 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1954 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1958 while ((opt = getopt_long(argc, argv, short_options,
1959 long_options, NULL)) != -1) {
1968 rc = parse_long(optarg, &hop);
1976 rc = parse_long(optarg, &prio);
1987 print_help(route_cmds, "route", "show");
1993 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1994 &show_rc, &err_rc, false);
1996 if (rc != LUSTRE_CFG_RC_NO_ERR)
1997 cYAML_print_tree2file(stderr, err_rc);
1999 cYAML_print_tree(show_rc);
2001 cYAML_free_tree(err_rc);
2002 cYAML_free_tree(show_rc);
2007 static int set_value_helper(int argc, char **argv,
2008 int (*cb)(int, bool, char*, int, struct cYAML**))
2011 long int healthv = -1;
2014 struct cYAML *err_rc = NULL;
2016 const char *const short_options = "t:n:a";
2017 static const struct option long_options[] = {
2018 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2019 { .name = "health", .has_arg = required_argument, .val = 't' },
2020 { .name = "all", .has_arg = no_argument, .val = 'a' },
2023 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2027 while ((opt = getopt_long(argc, argv, short_options,
2028 long_options, NULL)) != -1) {
2034 if (parse_long(optarg, &healthv) != 0)
2045 rc = cb(healthv, all, nid, -1, &err_rc);
2047 if (rc != LUSTRE_CFG_RC_NO_ERR)
2048 cYAML_print_tree2file(stderr, err_rc);
2050 cYAML_free_tree(err_rc);
2055 static int jt_set_ni_value(int argc, char **argv)
2058 long int healthv = -1, cpp = -1;
2061 struct cYAML *err_rc = NULL;
2063 const char *const short_options = "a:m:n:t:";
2064 static const struct option long_options[] = {
2065 { .name = "all", .has_arg = no_argument, .val = 'a' },
2066 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2067 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2068 { .name = "health", .has_arg = required_argument, .val = 't' },
2071 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2075 while ((opt = getopt_long(argc, argv, short_options,
2076 long_options, NULL)) != -1) {
2082 rc = parse_long(optarg, &cpp);
2093 if (parse_long(optarg, &healthv) != 0) {
2105 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2108 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2111 if (rc != LUSTRE_CFG_RC_NO_ERR)
2112 cYAML_print_tree2file(stderr, err_rc);
2114 cYAML_free_tree(err_rc);
2119 static int jt_set_peer_ni_value(int argc, char **argv)
2121 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
2124 static int jt_show_recovery(int argc, char **argv)
2127 struct cYAML *err_rc = NULL, *show_rc = NULL;
2128 const char *const short_options = "lp";
2129 static const struct option long_options[] = {
2130 { .name = "local", .has_arg = no_argument, .val = 'l' },
2131 { .name = "peer", .has_arg = no_argument, .val = 'p' },
2134 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
2138 while ((opt = getopt_long(argc, argv, short_options,
2139 long_options, NULL)) != -1) {
2142 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
2145 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
2152 if (rc != LUSTRE_CFG_RC_NO_ERR)
2153 cYAML_print_tree2file(stderr, err_rc);
2155 cYAML_print_tree(show_rc);
2157 cYAML_free_tree(err_rc);
2158 cYAML_free_tree(show_rc);
2163 static int jt_show_peer_debug_info(int argc, char **argv)
2166 struct cYAML *err_rc = NULL;
2167 char *peer_nid = optarg;
2168 const char *const short_opts = "k";
2169 const struct option long_opts[] = {
2170 { .name = "nid", .has_arg = required_argument, .val = 'k' },
2173 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
2178 while ((opt = getopt_long(argc, argv, short_opts,
2179 long_opts, NULL)) != -1) {
2189 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
2191 if (rc != LUSTRE_CFG_RC_NO_ERR)
2192 cYAML_print_tree2file(stderr, err_rc);
2194 cYAML_free_tree(err_rc);
2199 static int jt_show_net(int argc, char **argv)
2201 char *network = NULL;
2203 struct cYAML *err_rc = NULL, *show_rc = NULL;
2204 long int detail = 0;
2206 const char *const short_options = "n:v";
2207 static const struct option long_options[] = {
2208 { .name = "net", .has_arg = required_argument, .val = 'n' },
2209 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2212 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
2216 while ((opt = getopt_long(argc, argv, short_options,
2217 long_options, NULL)) != -1) {
2223 if ((!optarg) && (argv[optind] != NULL) &&
2224 (argv[optind][0] != '-')) {
2225 if (parse_long(argv[optind++], &detail) != 0)
2232 print_help(net_cmds, "net", "show");
2238 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
2241 if (rc != LUSTRE_CFG_RC_NO_ERR)
2242 cYAML_print_tree2file(stderr, err_rc);
2244 cYAML_print_tree(show_rc);
2246 cYAML_free_tree(err_rc);
2247 cYAML_free_tree(show_rc);
2252 static int jt_show_routing(int argc, char **argv)
2254 struct cYAML *err_rc = NULL, *show_rc = NULL;
2257 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
2261 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
2263 if (rc != LUSTRE_CFG_RC_NO_ERR)
2264 cYAML_print_tree2file(stderr, err_rc);
2266 cYAML_print_tree(show_rc);
2268 cYAML_free_tree(err_rc);
2269 cYAML_free_tree(show_rc);
2274 static int jt_show_stats(int argc, char **argv)
2277 struct cYAML *show_rc = NULL, *err_rc = NULL;
2279 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
2283 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
2285 if (rc != LUSTRE_CFG_RC_NO_ERR)
2286 cYAML_print_tree2file(stderr, err_rc);
2288 cYAML_print_tree(show_rc);
2290 cYAML_free_tree(err_rc);
2291 cYAML_free_tree(show_rc);
2296 static int jt_show_udsp(int argc, char **argv)
2300 struct cYAML *err_rc = NULL, *show_rc = NULL;
2302 const char *const short_options = "i:";
2303 static const struct option long_options[] = {
2304 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2308 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
2312 while ((opt = getopt_long(argc, argv, short_options,
2313 long_options, NULL)) != -1) {
2319 print_help(net_cmds, "net", "show");
2325 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
2327 if (rc != LUSTRE_CFG_RC_NO_ERR)
2328 cYAML_print_tree2file(stderr, err_rc);
2330 cYAML_print_tree(show_rc);
2332 cYAML_free_tree(err_rc);
2333 cYAML_free_tree(show_rc);
2338 static int jt_show_global(int argc, char **argv)
2341 struct cYAML *show_rc = NULL, *err_rc = NULL;
2343 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
2347 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2348 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2349 cYAML_print_tree2file(stderr, err_rc);
2353 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
2354 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2355 cYAML_print_tree2file(stderr, err_rc);
2359 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
2360 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2361 cYAML_print_tree2file(stderr, err_rc);
2365 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2366 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2367 cYAML_print_tree2file(stderr, err_rc);
2371 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2372 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2373 cYAML_print_tree2file(stderr, err_rc);
2377 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2378 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2379 cYAML_print_tree2file(stderr, err_rc);
2383 rc = lustre_lnet_show_hsensitivity(-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_recov_intrv(-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_rtr_sensitivity(-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_lnd_timeout(-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_response_tracking(-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_recovery_limit(-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_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2420 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2421 cYAML_print_tree2file(stderr, err_rc);
2426 cYAML_print_tree(show_rc);
2429 cYAML_free_tree(err_rc);
2430 cYAML_free_tree(show_rc);
2435 static int jt_lnet(int argc, char **argv)
2439 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
2443 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
2446 static int jt_route(int argc, char **argv)
2450 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
2454 return Parser_execarg(argc - 1, &argv[1], route_cmds);
2457 static int jt_net(int argc, char **argv)
2461 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
2465 return Parser_execarg(argc - 1, &argv[1], net_cmds);
2468 static int jt_routing(int argc, char **argv)
2472 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
2476 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
2479 static int jt_stats(int argc, char **argv)
2483 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
2487 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
2490 static int jt_debug(int argc, char **argv)
2494 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
2498 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
2501 static int jt_global(int argc, char **argv)
2505 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
2509 return Parser_execarg(argc - 1, &argv[1], global_cmds);
2512 static int jt_peers(int argc, char **argv)
2516 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
2520 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
2523 static int jt_set(int argc, char **argv)
2527 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
2531 return Parser_execarg(argc - 1, &argv[1], set_cmds);
2534 static int jt_udsp(int argc, char **argv)
2538 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
2542 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
2545 static int jt_import(int argc, char **argv)
2548 struct cYAML *err_rc = NULL;
2549 struct cYAML *show_rc = NULL;
2550 int rc = 0, return_rc = 0, opt, opt_found = 0;
2553 const char *const short_options = "adseh";
2554 static const struct option long_options[] = {
2555 { .name = "add", .has_arg = no_argument, .val = 'a' },
2556 { .name = "del", .has_arg = no_argument, .val = 'd' },
2557 { .name = "show", .has_arg = no_argument, .val = 's' },
2558 { .name = "exec", .has_arg = no_argument, .val = 'e' },
2559 { .name = "help", .has_arg = no_argument, .val = 'h' },
2562 while ((opt = getopt_long(argc, argv, short_options,
2563 long_options, NULL)) != -1) {
2577 printf("import FILE\n"
2578 "import < FILE : import a file\n"
2579 "\t--add: add configuration\n"
2580 "\t--del: delete configuration\n"
2581 "\t--show: show configuration\n"
2582 "\t--exec: execute command\n"
2583 "\t--help: display this help\n"
2584 "If no command option is given then --add"
2585 " is assumed by default\n");
2592 /* grab the file name if one exists */
2593 if (opt_found && argc == 3)
2595 else if (!opt_found && argc == 2)
2600 rc = lustre_yaml_config(file, &err_rc);
2601 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
2602 cYAML_print_tree(show_rc);
2603 cYAML_free_tree(show_rc);
2606 rc = lustre_yaml_del(file, &err_rc);
2609 rc = lustre_yaml_show(file, &show_rc, &err_rc);
2610 cYAML_print_tree(show_rc);
2611 cYAML_free_tree(show_rc);
2614 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
2615 cYAML_print_tree(show_rc);
2616 cYAML_free_tree(show_rc);
2620 if (rc || return_rc) {
2621 cYAML_print_tree2file(stderr, err_rc);
2622 cYAML_free_tree(err_rc);
2628 static int jt_export(int argc, char **argv)
2630 struct cYAML *show_rc = NULL;
2631 struct cYAML *err_rc = NULL;
2635 bool backup = false;
2638 const char *const short_options = "bh";
2639 static const struct option long_options[] = {
2640 { .name = "backup", .has_arg = no_argument, .val = 'b' },
2641 { .name = "help", .has_arg = no_argument, .val = 'h' },
2644 while ((opt = getopt_long(argc, argv, short_options,
2645 long_options, NULL)) != -1) {
2652 printf("export > FILE.yaml : export configuration\n"
2653 "\t--backup: export only what's necessary for reconfig\n"
2654 "\t--help: display this help\n");
2659 if (backup && argc >= 3)
2661 else if (!backup && argc >= 2)
2667 f = fopen(file, "w");
2672 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
2673 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2674 cYAML_print_tree2file(stderr, err_rc);
2675 cYAML_free_tree(err_rc);
2679 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
2681 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2682 cYAML_print_tree2file(stderr, err_rc);
2683 cYAML_free_tree(err_rc);
2687 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
2688 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2689 cYAML_print_tree2file(stderr, err_rc);
2690 cYAML_free_tree(err_rc);
2694 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
2695 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2696 cYAML_print_tree2file(stderr, err_rc);
2697 cYAML_free_tree(err_rc);
2701 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
2702 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2703 cYAML_print_tree2file(stderr, err_rc);
2704 cYAML_free_tree(err_rc);
2708 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
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_discovery(-1, &show_rc, &err_rc);
2716 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2717 cYAML_print_tree2file(stderr, err_rc);
2718 cYAML_free_tree(err_rc);
2722 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
2723 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2724 cYAML_print_tree2file(stderr, err_rc);
2725 cYAML_free_tree(err_rc);
2729 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
2730 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2731 cYAML_print_tree2file(stderr, err_rc);
2735 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
2736 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2737 cYAML_print_tree2file(stderr, err_rc);
2741 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
2742 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2743 cYAML_print_tree2file(stderr, err_rc);
2747 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
2748 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2749 cYAML_print_tree2file(stderr, err_rc);
2753 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
2754 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2755 cYAML_print_tree2file(stderr, err_rc);
2759 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
2760 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2761 cYAML_print_tree2file(stderr, err_rc);
2765 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
2766 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2767 cYAML_print_tree2file(stderr, err_rc);
2768 cYAML_free_tree(err_rc);
2772 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
2773 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2774 cYAML_print_tree2file(stderr, err_rc);
2775 cYAML_free_tree(err_rc);
2779 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
2780 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2781 cYAML_print_tree2file(stderr, err_rc);
2782 cYAML_free_tree(err_rc);
2786 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
2787 if (rc != LUSTRE_CFG_RC_NO_ERR) {
2788 cYAML_print_tree2file(stderr, err_rc);
2789 cYAML_free_tree(err_rc);
2793 if (show_rc != NULL) {
2794 cYAML_print_tree2file(f, show_rc);
2795 cYAML_free_tree(show_rc);
2804 static int jt_peer_nid_common(int argc, char **argv, int cmd)
2806 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
2808 char *prim_nid = NULL, *nidstr = NULL;
2809 char err_str[LNET_MAX_STR_LEN] = "Error";
2810 struct cYAML *err_rc = NULL;
2812 const char *const short_opts = "k:mn:";
2813 const struct option long_opts[] = {
2814 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
2815 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
2816 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2819 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
2823 while ((opt = getopt_long(argc, argv, short_opts,
2824 long_opts, NULL)) != -1) {
2833 if (cmd == LNETCTL_DEL_CMD) {
2834 rc = LUSTRE_CFG_RC_BAD_PARAM;
2835 snprintf(err_str, LNET_MAX_STR_LEN,
2836 "Unrecognized option '-%c'", opt);
2842 print_help(peer_cmds, "peer",
2843 cmd == LNETCTL_ADD_CMD ? "add" : "del");
2849 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
2851 if (rc != LUSTRE_CFG_RC_NO_ERR)
2855 cYAML_build_error(rc, -1, "peer",
2856 cmd == LNETCTL_ADD_CMD ? "add" : "del",
2860 if (rc != LUSTRE_CFG_RC_NO_ERR)
2861 cYAML_print_tree2file(stderr, err_rc);
2863 cYAML_free_tree(err_rc);
2868 static int jt_add_peer_nid(int argc, char **argv)
2870 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
2873 static int jt_del_peer_nid(int argc, char **argv)
2875 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
2878 static int jt_show_peer(int argc, char **argv)
2882 struct cYAML *err_rc = NULL, *show_rc = NULL;
2883 long int detail = 0;
2885 const char *const short_opts = "hn:v::";
2886 const struct option long_opts[] = {
2887 { .name = "help", .has_arg = no_argument, .val = 'h' },
2888 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2889 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2892 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
2896 while ((opt = getopt_long(argc, argv, short_opts,
2897 long_opts, NULL)) != -1) {
2903 if ((!optarg) && (argv[optind] != NULL) &&
2904 (argv[optind][0] != '-')) {
2905 if (parse_long(argv[optind++], &detail) != 0)
2912 print_help(peer_cmds, "peer", "show");
2918 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
2921 if (rc != LUSTRE_CFG_RC_NO_ERR)
2922 cYAML_print_tree2file(stderr, err_rc);
2924 cYAML_print_tree(show_rc);
2926 cYAML_free_tree(err_rc);
2927 cYAML_free_tree(show_rc);
2932 static int jt_list_peer(int argc, char **argv)
2935 struct cYAML *err_rc = NULL, *list_rc = NULL;
2937 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
2941 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
2943 if (rc != LUSTRE_CFG_RC_NO_ERR)
2944 cYAML_print_tree2file(stderr, err_rc);
2946 cYAML_print_tree(list_rc);
2948 cYAML_free_tree(err_rc);
2949 cYAML_free_tree(list_rc);
2954 static int jt_ping(int argc, char **argv)
2956 struct cYAML *err_rc = NULL;
2957 struct cYAML *show_rc = NULL;
2960 char *src_nidstr = NULL;
2962 const char *const short_options = "hs:t:";
2963 const struct option long_options[] = {
2964 { .name = "help", .has_arg = no_argument, .val = 'h' },
2965 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2966 { .name = "source", .has_arg = required_argument, .val = 's' },
2969 while ((opt = getopt_long(argc, argv, short_options,
2970 long_options, NULL)) != -1) {
2973 src_nidstr = optarg;
2976 timeout = 1000 * atol(optarg);
2979 printf("ping nid[,nid,...]\n"
2980 "\t --source: source nid\n"
2981 "\t --timeout: ping timeout\n"
2982 "\t --help: display this help\n");
2989 for (; optind < argc; optind++)
2990 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
2994 cYAML_print_tree(show_rc);
2997 cYAML_print_tree2file(stderr, err_rc);
2999 cYAML_free_tree(err_rc);
3000 cYAML_free_tree(show_rc);
3005 static int jt_discover(int argc, char **argv)
3007 struct cYAML *err_rc = NULL;
3008 struct cYAML *show_rc = NULL;
3012 const char *const short_options = "fh";
3013 const struct option long_options[] = {
3014 { .name = "force", .has_arg = no_argument, .val = 'f' },
3015 { .name = "help", .has_arg = no_argument, .val = 'h' },
3018 while ((opt = getopt_long(argc, argv, short_options,
3019 long_options, NULL)) != -1) {
3025 printf("discover nid[,nid,...]\n"
3026 "\t --force: force discovery\n"
3027 "\t --help: display this help\n");
3034 for (; optind < argc; optind++)
3035 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
3039 cYAML_print_tree(show_rc);
3042 cYAML_print_tree2file(stderr, err_rc);
3044 cYAML_free_tree(err_rc);
3045 cYAML_free_tree(show_rc);
3050 static int jt_add_udsp(int argc, char **argv)
3052 char *src = NULL, *dst = NULL, *rte = NULL;
3053 struct cYAML *err_rc = NULL;
3054 union lnet_udsp_action udsp_action;
3055 long int idx = -1, priority = -1;
3057 char *action_type = "pref";
3059 const char *const short_options = "s:d:r:p:i:";
3060 static const struct option long_options[] = {
3061 { .name = "src", .has_arg = required_argument, .val = 's' },
3062 { .name = "dst", .has_arg = required_argument, .val = 'd' },
3063 { .name = "rte", .has_arg = required_argument, .val = 'r' },
3064 { .name = "priority", .has_arg = required_argument, .val = 'p' },
3065 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3068 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
3072 while ((opt = getopt_long(argc, argv, short_options,
3073 long_options, NULL)) != -1) {
3085 rc = parse_long(optarg, &priority);
3088 action_type = "priority";
3089 udsp_action.udsp_priority = priority;
3092 rc = parse_long(optarg, &idx);
3097 print_help(udsp_cmds, "udsp", "add");
3103 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
3106 if (rc != LUSTRE_CFG_RC_NO_ERR)
3107 cYAML_print_tree2file(stderr, err_rc);
3109 cYAML_free_tree(err_rc);
3114 static int jt_del_udsp(int argc, char **argv)
3116 struct cYAML *err_rc = NULL;
3120 const char *const short_options = "i:";
3121 static const struct option long_options[] = {
3122 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3125 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
3129 while ((opt = getopt_long(argc, argv, short_options,
3130 long_options, NULL)) != -1) {
3133 rc = parse_long(optarg, &idx);
3138 print_help(udsp_cmds, "udsp", "add");
3144 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
3145 if (rc != LUSTRE_CFG_RC_NO_ERR)
3146 cYAML_print_tree2file(stderr, err_rc);
3148 cYAML_free_tree(err_rc);
3153 static int lnetctl_list_commands(int argc, char **argv)
3155 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
3157 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
3162 int main(int argc, char **argv)
3165 struct cYAML *err_rc = NULL;
3167 rc = lustre_lnet_config_lib_init();
3169 cYAML_build_error(-1, -1, "lnetctl", "startup",
3170 "cannot register LNet device", &err_rc);
3171 cYAML_print_tree2file(stderr, err_rc);
3175 Parser_init("lnetctl > ", cmd_list);
3177 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);