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 jt_import(int argc, char **argv);
75 static int jt_export(int argc, char **argv);
76 static int jt_ping(int argc, char **argv);
77 static int jt_discover(int argc, char **argv);
78 static int jt_lnet(int argc, char **argv);
79 static int jt_route(int argc, char **argv);
80 static int jt_net(int argc, char **argv);
81 static int jt_routing(int argc, char **argv);
82 static int jt_set(int argc, char **argv);
83 static int jt_debug(int argc, char **argv);
84 static int jt_stats(int argc, char **argv);
85 static int jt_global(int argc, char **argv);
86 static int jt_peers(int argc, char **argv);
87 static int jt_set_ni_value(int argc, char **argv);
88 static int jt_set_peer_ni_value(int argc, char **argv);
89 static int jt_calc_service_id(int argc, char **argv);
90 static int jt_set_response_tracking(int argc, char **argv);
91 static int jt_set_recovery_limit(int argc, char **argv);
92 static int jt_udsp(int argc, char **argv);
93 static int jt_setup_mrrouting(int argc, char **argv);
94 static int jt_calc_cpt_of_nid(int argc, char **argv);
95 static int jt_show_peer_debug_info(int argc, char **argv);
97 command_t cmd_list[] = {
98 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
99 {"route", jt_route, 0, "route {add | del | show | help}"},
100 {"net", jt_net, 0, "net {add | del | show | set | help}"},
101 {"routing", jt_routing, 0, "routing {show | help}"},
102 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
103 " | routing | numa_range | max_interfaces"
104 " | discovery | drop_asym_route | retry_count"
105 " | transaction_timeout | health_sensitivity"
106 " | recovery_interval | router_sensitivity"
107 " | response_tracking | recovery_limit}"},
108 {"import", jt_import, 0, "import FILE.yaml"},
109 {"export", jt_export, 0, "export FILE.yaml"},
110 {"stats", jt_stats, 0, "stats {show | help}"},
111 {"debug", jt_debug, 0, "debug {recovery {local | peer} | peer}"},
112 {"global", jt_global, 0, "global {show | help}"},
113 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
114 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
115 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
116 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
117 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
118 {"setup-mrrouting", jt_setup_mrrouting, 0,
119 "setup linux routing tables\n"},
120 {"cpt-of-nid", jt_calc_cpt_of_nid, 0, "Calculate the CPT associated with NID\n"
121 "\t--nid: NID to calculate the CPT of\n"
122 "\t--ncpt: Number of CPTs to consider in the calculation\n"},
126 command_t lnet_cmds[] = {
127 {"configure", jt_config_lnet, 0, "configure lnet\n"
128 "\t--all: load NI configuration from module parameters\n"},
129 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
133 command_t route_cmds[] = {
134 {"add", jt_add_route, 0, "add a route\n"
135 "\t--net: net name (e.g. tcp0)\n"
136 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
137 "\t--hop|hop-count: number to final destination (1 <= hops <= 255)\n"
138 "\t--priority: priority of route (0 - highest prio\n"
139 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
140 {"del", jt_del_route, 0, "delete a route\n"
141 "\t--net: net name (e.g. tcp0)\n"
142 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
143 {"show", jt_show_route, 0, "show routes\n"
144 "\t--net: net name (e.g. tcp0) to filter on\n"
145 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
146 "\t--hop|hop-count: number to final destination (1 <= hops <= 255) to filter on\n"
147 "\t--priority: priority of route (0 - highest prio to filter on\n"
148 "\t--verbose: display detailed output per route\n"},
152 command_t net_cmds[] = {
153 {"add", jt_add_ni, 0, "add a network\n"
154 "\t--net: net name (e.g. tcp0)\n"
155 "\t--if: physical interface (e.g. eth0)\n"
156 "\t--ip2net: specify networks based on IP address patterns\n"
157 "\t--peer-timeout: time to wait before declaring a peer dead\n"
158 "\t--peer-credits: define the max number of inflight messages\n"
159 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
160 "\t--credits: Network Interface credits\n"
161 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
162 "\t--conns-per-peer: number of connections per peer\n"
163 "\t--skip-mr-route-setup: do not add linux route for the ni\n"
164 "\t--auth-key: Network authorization key (kfilnd only)\n"
165 "\t--traffic-class: Traffic class (kfilnd only)\n"},
166 {"del", jt_del_ni, 0, "delete a network\n"
167 "\t--net: net name (e.g. tcp0)\n"
168 "\t--if: physical interface (e.g. eth0)\n"},
169 {"show", jt_show_net, 0, "show networks\n"
170 "\t--net: net name (e.g. tcp0) to filter on\n"
171 "\t--verbose: display detailed output per network."
172 " Optional argument of '2' outputs more stats\n"},
173 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
174 "\t--nid: NI NID to set the\n"
175 "\t--health: specify health value to set\n"
176 "\t--conns-per-peer: number of connections per peer\n"
177 "\t--all: set all NIs value to the one specified\n"},
181 command_t routing_cmds[] = {
182 {"show", jt_show_routing, 0, "show routing information\n"},
186 command_t stats_cmds[] = {
187 {"show", jt_show_stats, 0, "show LNET statistics\n"},
188 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
192 command_t debug_cmds[] = {
193 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
194 "\t--local : list local recovery queue\n"
195 "\t--peer : list peer recovery queue\n"},
196 {"peer", jt_show_peer_debug_info, 0, "show peer debug info\n"
197 "\t--nid: peer's NID\n"},
201 command_t global_cmds[] = {
202 {"show", jt_show_global, 0, "show global variables\n"},
206 command_t set_cmds[] = {
207 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
208 "\tVALUE must be greater than 0\n"},
209 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
210 "\tVALUE must be greater than 0\n"},
211 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
212 "\tVALUE must be greater than 0\n"},
213 {"routing", jt_set_routing, 0, "enable/disable routing\n"
214 "\t0 - disable routing\n"
215 "\t1 - enable routing\n"},
216 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
217 "\tVALUE must be at least 0\n"},
218 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
220 "\tValue must be greater than 16\n"},
221 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
222 "\t0 - disable peer discovery\n"
223 "\t1 - enable peer discovery (default)\n"},
224 {"drop_asym_route", jt_set_drop_asym_route, 0,
225 "drop/accept asymmetrical route messages\n"
226 "\t0 - accept asymmetrical route messages (default)\n"
227 "\t1 - drop asymmetrical route messages\n"},
228 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
229 "\t0 - turn of retries\n"
230 "\t>0 - number of retries\n"},
231 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
232 "\t>0 - timeout in seconds\n"},
233 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
234 "\t0 - turn off health evaluation\n"
235 "\t>0 - sensitivity value not more than 1000\n"},
236 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
237 "\t>0 - time in seconds between pings\n"},
238 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
239 "\t100 - router interfaces need to be fully healthy to be used\n"
240 "\t<100 - router interfaces can be used even if not healthy\n"},
241 {"response_tracking", jt_set_response_tracking, 0,
242 "Set the behavior of response tracking\n"
243 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
244 "\t1 - GETs are eligible for response tracking\n"
245 "\t2 - PUTs are eligible for response tracking\n"
246 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
247 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
248 "\t pings and discovery pushes always utilize response tracking\n"},
249 {"recovery_limit", jt_set_recovery_limit, 0,
250 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
251 "\t0 - Recover indefinitely (default)\n"
252 "\t>0 - Recover for the specified number of seconds.\n"},
253 {"max_recovery_ping_interval", jt_set_max_recovery_ping_interval, 0,
254 "maximum recovery ping interval\n"
255 "\t>0 - maximum recovery ping interval in seconds\n"},
259 command_t peer_cmds[] = {
260 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
261 "\t--prim_nid: Primary NID of the peer.\n"
262 "\t--nid: one or more peer NIDs\n"
263 "\t--non_mr: create this peer as not Multi-Rail capable\n"
264 "\t--ip2nets: specify a range of nids per peer\n"
265 "\t--lock_prim: lock primary nid\n"},
266 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
267 "\t--prim_nid: Primary NID of the peer.\n"
268 "\t--nid: list of NIDs to remove. If none provided,\n"
269 "\t peer is deleted\n"
270 "\t--ip2nets: specify a range of nids per peer\n"
271 "\t--force: force-delete locked primary NID\n"},
272 {"show", jt_show_peer, 0, "show peer information\n"
273 "\t--nid: NID of peer to filter on.\n"
274 "\t--verbose: display detailed output per peer."
275 " Optional argument of '2' outputs more stats\n"},
276 {"list", jt_list_peer, 0, "list all peers\n"},
277 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
278 "\t--nid: Peer NI NID to set the\n"
279 "\t--health: specify health value to set\n"
280 "\t--all: set all peer_nis values to the one specified\n"
281 "\t--state: set peer state (DANGEROUS: for test/debug only)"},
285 command_t udsp_cmds[] = {
286 {"add", jt_add_udsp, 0, "add a udsp\n"
287 "\t--src nid|net: ip2nets syntax specifying the local NID or network to match.\n"
288 "\t--dst nid: ip2nets syntax specifying the remote NID to match.\n"
289 "\t--rte nid: ip2nets syntax specifying the router NID to match.\n"
290 "\t--priority p: Assign priority value p where p >= 0.\n"
291 "\t Note: 0 is the highest priority.\n"
292 "\t--idx n: Insert the rule in the n'th position on the list of rules.\n"
293 "\t By default, rules are appended to the end of the rule list.\n"},
294 {"del", jt_del_udsp, 0, "delete a udsp\n"
295 "\t--all: Delete all rules.\n"
296 "\t--idx n: Delete the rule at index n.\n"},
297 {"show", jt_show_udsp, 0, "show udsps\n"
298 "\t--idx n: Show the rule at at index n.\n"
299 "\t By default, all rules are shown.\n"},
303 static int parse_long(const char *number, long int *value)
310 *value = strtol(number, &end, 0);
311 if (end != NULL && *end != 0)
317 static int jt_setup_mrrouting(int argc, char **argv)
320 struct cYAML *err_rc = NULL;
322 rc = lustre_lnet_setup_mrrouting(&err_rc);
324 if (rc != LUSTRE_CFG_RC_NO_ERR)
325 cYAML_print_tree2file(stderr, err_rc);
327 cYAML_free_tree(err_rc);
332 static inline void print_help(const command_t cmds[], const char *cmd_type,
335 const command_t *cmd;
337 for (cmd = cmds; cmd->pc_name; cmd++) {
338 if (pc_name != NULL &&
339 strcmp(cmd->pc_name, pc_name) == 0) {
340 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
343 } else if (pc_name != NULL) {
346 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
350 static int check_cmd(const command_t *cmd_list, const char *cmd,
351 const char *sub_cmd, const int min_args,
352 int argc, char **argv)
359 const char *const short_options = "h";
360 static const struct option long_options[] = {
361 { .name = "help", .has_arg = no_argument, .val = 'h' },
365 if (argc < min_args) {
366 print_help(cmd_list, cmd, sub_cmd);
369 } else if (argc > 2) {
373 while ((opt = getopt_long(argc, argv, short_options,
374 long_options, NULL)) != -1) {
377 print_help(cmd_list, cmd, sub_cmd);
392 static int jt_set_response_tracking(int argc, char **argv)
396 struct cYAML *err_rc = NULL;
398 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
402 rc = parse_long(argv[1], &value);
404 cYAML_build_error(-1, -1, "parser", "set",
405 "cannot parse response_tracking value",
407 cYAML_print_tree2file(stderr, err_rc);
408 cYAML_free_tree(err_rc);
412 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
413 if (rc != LUSTRE_CFG_RC_NO_ERR)
414 cYAML_print_tree2file(stderr, err_rc);
416 cYAML_free_tree(err_rc);
421 static int jt_calc_service_id(int argc, char **argv)
426 rc = lustre_lnet_calc_service_id(&service_id);
427 if (rc != LUSTRE_CFG_RC_NO_ERR)
430 /* cYAML currently doesn't support printing hex values.
431 * Therefore just print it locally here
433 printf("service_id:\n value: 0x%llx\n",
434 (unsigned long long)(service_id));
439 static int jt_calc_cpt_of_nid(int argc, char **argv)
445 struct cYAML *err_rc = NULL;
446 const char *const short_options = "n:c:h";
447 static const struct option long_options[] = {
448 { .name = "nid", .has_arg = required_argument, .val = 'n' },
449 { .name = "ncpt", .has_arg = required_argument, .val = 'c' },
452 rc = check_cmd(cmd_list, "", "cpt-of-nid", 0, argc, argv);
456 while ((opt = getopt_long(argc, argv, short_options,
457 long_options, NULL)) != -1) {
463 rc = parse_long(optarg, &ncpts);
465 cYAML_build_error(-1, -1, "cpt", "get",
466 "cannot parse input", &err_rc);
467 cYAML_print_tree2file(stderr, err_rc);
468 cYAML_free_tree(err_rc);
473 print_help(cmd_list, "", "cpt-of-nid");
479 cpt = lustre_lnet_calc_cpt_of_nid(nid, ncpts);
483 printf("cpt:\n value: %d\n", cpt);
488 static int jt_set_recovery_limit(int argc, char **argv)
492 struct cYAML *err_rc = NULL;
494 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
498 rc = parse_long(argv[1], &value);
500 cYAML_build_error(-1, -1, "parser", "set",
501 "cannot parse recovery_limit value",
503 cYAML_print_tree2file(stderr, err_rc);
504 cYAML_free_tree(err_rc);
508 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
509 if (rc != LUSTRE_CFG_RC_NO_ERR)
510 cYAML_print_tree2file(stderr, err_rc);
512 cYAML_free_tree(err_rc);
517 static int jt_set_max_intf(int argc, char **argv)
521 struct cYAML *err_rc = NULL;
523 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
527 rc = parse_long(argv[1], &value);
529 cYAML_build_error(-1, -1, "parser", "set",
530 "cannot parse max_interfaces value", &err_rc);
531 cYAML_print_tree2file(stderr, err_rc);
532 cYAML_free_tree(err_rc);
536 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
537 if (rc != LUSTRE_CFG_RC_NO_ERR)
538 cYAML_print_tree2file(stderr, err_rc);
540 cYAML_free_tree(err_rc);
545 static int jt_set_numa(int argc, char **argv)
549 struct cYAML *err_rc = NULL;
551 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
555 rc = parse_long(argv[1], &value);
557 cYAML_build_error(-1, -1, "parser", "set",
558 "cannot parse numa_range value", &err_rc);
559 cYAML_print_tree2file(stderr, err_rc);
560 cYAML_free_tree(err_rc);
564 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
565 if (rc != LUSTRE_CFG_RC_NO_ERR)
566 cYAML_print_tree2file(stderr, err_rc);
568 cYAML_free_tree(err_rc);
573 static int jt_set_recov_intrv(int argc, char **argv)
577 struct cYAML *err_rc = NULL;
579 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
583 rc = parse_long(argv[1], &value);
585 cYAML_build_error(-1, -1, "parser", "set",
586 "cannot parse recovery interval value", &err_rc);
587 cYAML_print_tree2file(stderr, err_rc);
588 cYAML_free_tree(err_rc);
592 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
593 if (rc != LUSTRE_CFG_RC_NO_ERR)
594 cYAML_print_tree2file(stderr, err_rc);
596 cYAML_free_tree(err_rc);
601 static int jt_set_rtr_sensitivity(int argc, char **argv)
605 struct cYAML *err_rc = NULL;
607 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
611 rc = parse_long(argv[1], &value);
613 cYAML_build_error(-1, -1, "parser", "set",
614 "cannot parse router sensitivity value", &err_rc);
615 cYAML_print_tree2file(stderr, err_rc);
616 cYAML_free_tree(err_rc);
620 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
621 if (rc != LUSTRE_CFG_RC_NO_ERR)
622 cYAML_print_tree2file(stderr, err_rc);
624 cYAML_free_tree(err_rc);
629 static int jt_set_hsensitivity(int argc, char **argv)
633 struct cYAML *err_rc = NULL;
635 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
639 rc = parse_long(argv[1], &value);
641 cYAML_build_error(-1, -1, "parser", "set",
642 "cannot parse health sensitivity value", &err_rc);
643 cYAML_print_tree2file(stderr, err_rc);
644 cYAML_free_tree(err_rc);
648 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
649 if (rc != LUSTRE_CFG_RC_NO_ERR)
650 cYAML_print_tree2file(stderr, err_rc);
652 cYAML_free_tree(err_rc);
657 static int jt_reset_stats(int argc, char **argv)
660 struct cYAML *err_rc = NULL;
662 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
666 rc = lustre_lnet_reset_stats(-1, &err_rc);
667 if (rc != LUSTRE_CFG_RC_NO_ERR)
668 cYAML_print_tree2file(stderr, err_rc);
670 cYAML_free_tree(err_rc);
675 static int jt_set_transaction_to(int argc, char **argv)
679 struct cYAML *err_rc = NULL;
681 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
685 rc = parse_long(argv[1], &value);
687 cYAML_build_error(-1, -1, "parser", "set",
688 "cannot parse transaction timeout value", &err_rc);
689 cYAML_print_tree2file(stderr, err_rc);
690 cYAML_free_tree(err_rc);
694 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
695 if (rc != LUSTRE_CFG_RC_NO_ERR)
696 cYAML_print_tree2file(stderr, err_rc);
698 cYAML_free_tree(err_rc);
703 static int jt_set_retry_count(int argc, char **argv)
707 struct cYAML *err_rc = NULL;
709 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
713 rc = parse_long(argv[1], &value);
715 cYAML_build_error(-1, -1, "parser", "set",
716 "cannot parse retry_count value", &err_rc);
717 cYAML_print_tree2file(stderr, err_rc);
718 cYAML_free_tree(err_rc);
722 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
723 if (rc != LUSTRE_CFG_RC_NO_ERR)
724 cYAML_print_tree2file(stderr, err_rc);
726 cYAML_free_tree(err_rc);
731 static int jt_set_discovery(int argc, char **argv)
735 struct cYAML *err_rc = NULL;
737 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
741 rc = parse_long(argv[1], &value);
743 cYAML_build_error(-1, -1, "parser", "set",
744 "cannot parse discovery value", &err_rc);
745 cYAML_print_tree2file(stderr, err_rc);
746 cYAML_free_tree(err_rc);
750 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
751 if (rc != LUSTRE_CFG_RC_NO_ERR)
752 cYAML_print_tree2file(stderr, err_rc);
754 cYAML_free_tree(err_rc);
759 static int jt_set_drop_asym_route(int argc, char **argv)
763 struct cYAML *err_rc = NULL;
765 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
769 rc = parse_long(argv[1], &value);
771 cYAML_build_error(-1, -1, "parser", "set",
772 "cannot parse drop_asym_route value",
774 cYAML_print_tree2file(stderr, err_rc);
775 cYAML_free_tree(err_rc);
779 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
780 if (rc != LUSTRE_CFG_RC_NO_ERR)
781 cYAML_print_tree2file(stderr, err_rc);
783 cYAML_free_tree(err_rc);
788 static int jt_set_tiny(int argc, char **argv)
792 struct cYAML *err_rc = NULL;
794 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
798 rc = parse_long(argv[1], &value);
800 cYAML_build_error(-1, -1, "parser", "set",
801 "cannot parse tiny_buffers value", &err_rc);
802 cYAML_print_tree2file(stderr, err_rc);
803 cYAML_free_tree(err_rc);
807 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
808 if (rc != LUSTRE_CFG_RC_NO_ERR)
809 cYAML_print_tree2file(stderr, err_rc);
811 cYAML_free_tree(err_rc);
816 static int jt_set_small(int argc, char **argv)
820 struct cYAML *err_rc = NULL;
822 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
826 rc = parse_long(argv[1], &value);
828 cYAML_build_error(-1, -1, "parser", "set",
829 "cannot parse small_buffers value", &err_rc);
830 cYAML_print_tree2file(stderr, err_rc);
831 cYAML_free_tree(err_rc);
835 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
836 if (rc != LUSTRE_CFG_RC_NO_ERR)
837 cYAML_print_tree2file(stderr, err_rc);
839 cYAML_free_tree(err_rc);
844 static int jt_set_large(int argc, char **argv)
848 struct cYAML *err_rc = NULL;
850 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
854 rc = parse_long(argv[1], &value);
856 cYAML_build_error(-1, -1, "parser", "set",
857 "cannot parse large_buffers value", &err_rc);
858 cYAML_print_tree2file(stderr, err_rc);
859 cYAML_free_tree(err_rc);
863 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
864 if (rc != LUSTRE_CFG_RC_NO_ERR)
865 cYAML_print_tree2file(stderr, err_rc);
867 cYAML_free_tree(err_rc);
872 static int jt_set_routing(int argc, char **argv)
875 struct cYAML *err_rc = NULL;
878 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
882 rc = parse_long(argv[1], &value);
883 if (rc != 0 || (value != 0 && value != 1)) {
884 cYAML_build_error(-1, -1, "parser", "set",
885 "cannot parse routing value.\n"
886 "must be 0 for disable or 1 for enable",
888 cYAML_print_tree2file(stderr, err_rc);
889 cYAML_free_tree(err_rc);
893 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
895 if (rc != LUSTRE_CFG_RC_NO_ERR)
896 cYAML_print_tree2file(stderr, err_rc);
898 cYAML_free_tree(err_rc);
903 static int jt_set_max_recovery_ping_interval(int argc, char **argv)
907 struct cYAML *err_rc = NULL;
909 rc = check_cmd(set_cmds, "set", "maximum recovery_interval", 2, argc, argv);
913 rc = parse_long(argv[1], &value);
915 cYAML_build_error(-1, -1, "parser", "set",
916 "cannot parse maximum recovery interval value",
918 cYAML_print_tree2file(stderr, err_rc);
919 cYAML_free_tree(err_rc);
923 rc = lustre_lnet_config_max_recovery_ping_interval(value, -1, &err_rc);
924 if (rc != LUSTRE_CFG_RC_NO_ERR)
925 cYAML_print_tree2file(stderr, err_rc);
927 cYAML_free_tree(err_rc);
932 static void yaml_lnet_print_error(int op, char *cmd, const char *errstr)
934 char errcode[INT_STRING_LEN];
940 snprintf(errcode, sizeof(errcode), "%d", errno);
942 yaml_emitter_initialize(&log);
943 yaml_emitter_set_indent(&log, LNET_DEFAULT_INDENT);
944 yaml_emitter_set_output_file(&log, stderr);
946 yaml_emitter_open(&log);
947 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
948 rc = yaml_emitter_emit(&log, &event);
952 yaml_mapping_start_event_initialize(&event, NULL,
953 (yaml_char_t *)YAML_MAP_TAG,
954 1, YAML_ANY_MAPPING_STYLE);
955 rc = yaml_emitter_emit(&log, &event);
975 yaml_scalar_event_initialize(&event, NULL,
976 (yaml_char_t *)YAML_STR_TAG,
979 YAML_PLAIN_SCALAR_STYLE);
980 rc = yaml_emitter_emit(&log, &event);
984 yaml_sequence_start_event_initialize(&event, NULL,
985 (yaml_char_t *)YAML_SEQ_TAG,
986 1, YAML_ANY_SEQUENCE_STYLE);
987 rc = yaml_emitter_emit(&log, &event);
991 yaml_mapping_start_event_initialize(&event, NULL,
992 (yaml_char_t *)YAML_MAP_TAG,
993 1, YAML_ANY_MAPPING_STYLE);
994 rc = yaml_emitter_emit(&log, &event);
998 yaml_scalar_event_initialize(&event, NULL,
999 (yaml_char_t *)YAML_STR_TAG,
1002 1, 0, YAML_PLAIN_SCALAR_STYLE);
1003 rc = yaml_emitter_emit(&log, &event);
1007 yaml_scalar_event_initialize(&event, NULL,
1008 (yaml_char_t *)YAML_STR_TAG,
1011 1, 0, YAML_PLAIN_SCALAR_STYLE);
1012 rc = yaml_emitter_emit(&log, &event);
1016 yaml_scalar_event_initialize(&event, NULL,
1017 (yaml_char_t *)YAML_STR_TAG,
1018 (yaml_char_t *)"errno",
1019 strlen("errno"), 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 *)errcode,
1028 strlen(errcode), 1, 0,
1029 YAML_PLAIN_SCALAR_STYLE);
1030 rc = yaml_emitter_emit(&log, &event);
1035 yaml_scalar_event_initialize(&event, NULL,
1036 (yaml_char_t *)YAML_STR_TAG,
1037 (yaml_char_t *)"descr",
1038 strlen("descr"), 1, 0,
1039 YAML_PLAIN_SCALAR_STYLE);
1040 rc = yaml_emitter_emit(&log, &event);
1044 yaml_scalar_event_initialize(&event, NULL,
1045 (yaml_char_t *)YAML_STR_TAG,
1046 (yaml_char_t *)errstr,
1047 strlen(errstr), 1, 0,
1048 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
1049 rc = yaml_emitter_emit(&log, &event);
1053 yaml_mapping_end_event_initialize(&event);
1054 rc = yaml_emitter_emit(&log, &event);
1058 yaml_sequence_end_event_initialize(&event);
1059 rc = yaml_emitter_emit(&log, &event);
1063 yaml_mapping_end_event_initialize(&event);
1064 rc = yaml_emitter_emit(&log, &event);
1068 yaml_document_end_event_initialize(&event, 0);
1069 rc = yaml_emitter_emit(&log, &event);
1073 rc = yaml_emitter_close(&log);
1076 yaml_emitter_log_error(&log, stdout);
1077 yaml_emitter_delete(&log);
1080 static int jt_config_lnet(int argc, char **argv)
1082 struct cYAML *err_rc = NULL;
1083 bool load_mod_params = false;
1086 const char *const short_options = "a";
1087 static const struct option long_options[] = {
1088 { .name = "all", .has_arg = no_argument, .val = 'a' },
1092 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
1096 while ((opt = getopt_long(argc, argv, short_options,
1097 long_options, NULL)) != -1) {
1100 load_mod_params = true;
1107 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
1110 if (rc != LUSTRE_CFG_RC_NO_ERR)
1111 cYAML_print_tree2file(stderr, err_rc);
1113 cYAML_free_tree(err_rc);
1118 static int jt_unconfig_lnet(int argc, char **argv)
1120 struct cYAML *err_rc = NULL;
1123 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
1127 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
1129 if (rc != LUSTRE_CFG_RC_NO_ERR)
1130 cYAML_print_tree2file(stderr, err_rc);
1132 cYAML_free_tree(err_rc);
1137 static int yaml_lnet_route(char *nw, char *gw, int hops, int prio, int sen,
1138 int version, int flags)
1140 struct nl_sock *sk = NULL;
1141 const char *msg = NULL;
1142 yaml_emitter_t output;
1143 yaml_parser_t reply;
1147 /* Create Netlink emitter to send request to kernel */
1148 sk = nl_socket_alloc();
1152 /* Setup parser to receive Netlink packets */
1153 rc = yaml_parser_initialize(&reply);
1159 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1161 msg = yaml_parser_get_reader_error(&reply);
1165 /* Create Netlink emitter to send request to kernel */
1166 rc = yaml_emitter_initialize(&output);
1168 msg = "failed to initialize emitter";
1172 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1173 version, LNET_CMD_ROUTES, flags);
1177 yaml_emitter_open(&output);
1178 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1179 rc = yaml_emitter_emit(&output, &event);
1183 yaml_mapping_start_event_initialize(&event, NULL,
1184 (yaml_char_t *)YAML_MAP_TAG,
1185 1, YAML_ANY_MAPPING_STYLE);
1186 rc = yaml_emitter_emit(&output, &event);
1190 yaml_scalar_event_initialize(&event, NULL,
1191 (yaml_char_t *)YAML_STR_TAG,
1192 (yaml_char_t *)"route",
1193 strlen("route"), 1, 0,
1194 YAML_PLAIN_SCALAR_STYLE);
1195 rc = yaml_emitter_emit(&output, &event);
1199 if (nw || gw || hops != -1 || prio != -1) {
1200 char num[INT_STRING_LEN];
1202 yaml_sequence_start_event_initialize(&event, NULL,
1203 (yaml_char_t *)YAML_SEQ_TAG,
1205 YAML_BLOCK_SEQUENCE_STYLE);
1206 rc = yaml_emitter_emit(&output, &event);
1211 yaml_mapping_start_event_initialize(&event, NULL,
1212 (yaml_char_t *)YAML_MAP_TAG,
1214 YAML_BLOCK_MAPPING_STYLE);
1215 rc = yaml_emitter_emit(&output, &event);
1219 yaml_scalar_event_initialize(&event, NULL,
1220 (yaml_char_t *)YAML_STR_TAG,
1221 (yaml_char_t *)"net",
1222 strlen("net"), 1, 0,
1223 YAML_PLAIN_SCALAR_STYLE);
1224 rc = yaml_emitter_emit(&output, &event);
1228 yaml_scalar_event_initialize(&event, NULL,
1229 (yaml_char_t *)YAML_STR_TAG,
1232 YAML_PLAIN_SCALAR_STYLE);
1233 rc = yaml_emitter_emit(&output, &event);
1237 yaml_mapping_end_event_initialize(&event);
1238 rc = yaml_emitter_emit(&output, &event);
1244 yaml_mapping_start_event_initialize(&event, NULL,
1245 (yaml_char_t *)YAML_MAP_TAG,
1247 YAML_BLOCK_MAPPING_STYLE);
1248 rc = yaml_emitter_emit(&output, &event);
1252 yaml_scalar_event_initialize(&event, NULL,
1253 (yaml_char_t *)YAML_STR_TAG,
1254 (yaml_char_t *)"gateway",
1255 strlen("gateway"), 1, 0,
1256 YAML_PLAIN_SCALAR_STYLE);
1257 rc = yaml_emitter_emit(&output, &event);
1261 yaml_scalar_event_initialize(&event, NULL,
1262 (yaml_char_t *)YAML_STR_TAG,
1265 YAML_PLAIN_SCALAR_STYLE);
1266 rc = yaml_emitter_emit(&output, &event);
1270 yaml_mapping_end_event_initialize(&event);
1271 rc = yaml_emitter_emit(&output, &event);
1277 yaml_mapping_start_event_initialize(&event, NULL,
1278 (yaml_char_t *)YAML_MAP_TAG,
1280 YAML_BLOCK_MAPPING_STYLE);
1281 rc = yaml_emitter_emit(&output, &event);
1285 yaml_scalar_event_initialize(&event, NULL,
1286 (yaml_char_t *)YAML_STR_TAG,
1287 (yaml_char_t *)"hop",
1288 strlen("hop"), 1, 0,
1289 YAML_PLAIN_SCALAR_STYLE);
1290 rc = yaml_emitter_emit(&output, &event);
1294 snprintf(num, sizeof(num), "%d", hops);
1295 yaml_scalar_event_initialize(&event, NULL,
1296 (yaml_char_t *)YAML_INT_TAG,
1299 YAML_PLAIN_SCALAR_STYLE);
1300 rc = yaml_emitter_emit(&output, &event);
1304 yaml_mapping_end_event_initialize(&event);
1305 rc = yaml_emitter_emit(&output, &event);
1311 yaml_mapping_start_event_initialize(&event, NULL,
1312 (yaml_char_t *)YAML_MAP_TAG,
1314 YAML_BLOCK_MAPPING_STYLE);
1315 rc = yaml_emitter_emit(&output, &event);
1319 yaml_scalar_event_initialize(&event, NULL,
1320 (yaml_char_t *)YAML_STR_TAG,
1321 (yaml_char_t *)"priority",
1322 strlen("priority"), 1, 0,
1323 YAML_PLAIN_SCALAR_STYLE);
1324 rc = yaml_emitter_emit(&output, &event);
1328 snprintf(num, sizeof(num), "%d", prio);
1329 yaml_scalar_event_initialize(&event, NULL,
1330 (yaml_char_t *)YAML_INT_TAG,
1333 YAML_PLAIN_SCALAR_STYLE);
1334 rc = yaml_emitter_emit(&output, &event);
1338 yaml_mapping_end_event_initialize(&event);
1339 rc = yaml_emitter_emit(&output, &event);
1345 yaml_mapping_start_event_initialize(&event, NULL,
1346 (yaml_char_t *)YAML_MAP_TAG,
1348 YAML_BLOCK_MAPPING_STYLE);
1349 rc = yaml_emitter_emit(&output, &event);
1353 yaml_scalar_event_initialize(&event, NULL,
1354 (yaml_char_t *)YAML_STR_TAG,
1355 (yaml_char_t *)"health_sensitivity",
1356 strlen("health_sensitivity"),
1358 YAML_PLAIN_SCALAR_STYLE);
1359 rc = yaml_emitter_emit(&output, &event);
1363 snprintf(num, sizeof(num), "%d", sen);
1364 yaml_scalar_event_initialize(&event, NULL,
1365 (yaml_char_t *)YAML_INT_TAG,
1368 YAML_PLAIN_SCALAR_STYLE);
1369 rc = yaml_emitter_emit(&output, &event);
1373 yaml_mapping_end_event_initialize(&event);
1374 rc = yaml_emitter_emit(&output, &event);
1379 yaml_sequence_end_event_initialize(&event);
1380 rc = yaml_emitter_emit(&output, &event);
1384 yaml_scalar_event_initialize(&event, NULL,
1385 (yaml_char_t *)YAML_STR_TAG,
1388 YAML_PLAIN_SCALAR_STYLE);
1389 rc = yaml_emitter_emit(&output, &event);
1394 yaml_mapping_end_event_initialize(&event);
1395 rc = yaml_emitter_emit(&output, &event);
1399 yaml_document_end_event_initialize(&event, 0);
1400 rc = yaml_emitter_emit(&output, &event);
1404 rc = yaml_emitter_close(&output);
1407 yaml_emitter_log_error(&output, stderr);
1410 yaml_document_t errmsg;
1412 rc = yaml_parser_load(&reply, &errmsg);
1413 if (rc == 1 && flags == NLM_F_DUMP) {
1414 yaml_emitter_t debug;
1416 rc = yaml_emitter_initialize(&debug);
1418 yaml_emitter_set_indent(&debug, 6);
1419 yaml_emitter_set_output_file(&debug,
1421 rc = yaml_emitter_dump(&debug, &errmsg);
1423 yaml_emitter_delete(&debug);
1425 msg = yaml_parser_get_reader_error(&reply);
1426 /* If we didn't find any routes just be silent */
1427 if (msg && strcmp(msg, "No routes found") == 0)
1430 yaml_document_delete(&errmsg);
1432 yaml_emitter_delete(&output);
1435 yaml_lnet_print_error(flags, "route", msg);
1438 yaml_parser_delete(&reply);
1441 return rc == 1 ? 0 : rc;
1444 static int jt_add_route(int argc, char **argv)
1446 char *network = NULL, *gateway = NULL;
1447 long int hop = -1, prio = -1, sen = -1;
1448 struct cYAML *err_rc = NULL;
1451 const char *const short_options = "n:g:c:p:";
1452 static const struct option long_options[] = {
1453 { .name = "net", .has_arg = required_argument, .val = 'n' },
1454 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1455 { .name = "hop", .has_arg = required_argument, .val = 'c' },
1456 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1457 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1458 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1461 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1465 while ((opt = getopt_long(argc, argv, short_options,
1466 long_options, NULL)) != -1) {
1475 rc = parse_long(optarg, &hop);
1483 rc = parse_long(optarg, &prio);
1491 rc = parse_long(optarg, &sen);
1500 print_help(route_cmds, "route", "add");
1506 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1509 if (rc != LUSTRE_CFG_RC_NO_ERR)
1510 cYAML_print_tree2file(stderr, err_rc);
1512 cYAML_free_tree(err_rc);
1517 static int yaml_add_ni_tunables(yaml_emitter_t *output,
1518 struct lnet_ioctl_config_lnd_tunables *tunables,
1519 struct lnet_dlc_network_descr *nw_descr)
1521 char num[INT_STRING_LEN];
1525 if (tunables->lt_cmn.lct_peer_timeout < 0 &&
1526 tunables->lt_cmn.lct_peer_tx_credits <= 0 &&
1527 tunables->lt_cmn.lct_peer_rtr_credits <= 0 &&
1528 tunables->lt_cmn.lct_max_tx_credits <= 0)
1529 goto skip_general_settings;
1531 yaml_scalar_event_initialize(&event, NULL,
1532 (yaml_char_t *)YAML_STR_TAG,
1533 (yaml_char_t *)"tunables",
1534 strlen("tunables"), 1, 0,
1535 YAML_PLAIN_SCALAR_STYLE);
1536 rc = yaml_emitter_emit(output, &event);
1540 yaml_mapping_start_event_initialize(&event, NULL,
1541 (yaml_char_t *)YAML_MAP_TAG,
1542 1, YAML_ANY_MAPPING_STYLE);
1543 rc = yaml_emitter_emit(output, &event);
1547 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1548 yaml_scalar_event_initialize(&event, NULL,
1549 (yaml_char_t *)YAML_STR_TAG,
1550 (yaml_char_t *)"peer_timeout",
1551 strlen("peer_timeout"), 1, 0,
1552 YAML_PLAIN_SCALAR_STYLE);
1553 rc = yaml_emitter_emit(output, &event);
1557 snprintf(num, sizeof(num), "%u",
1558 tunables->lt_cmn.lct_peer_timeout);
1559 yaml_scalar_event_initialize(&event, NULL,
1560 (yaml_char_t *)YAML_INT_TAG,
1563 YAML_PLAIN_SCALAR_STYLE);
1564 rc = yaml_emitter_emit(output, &event);
1569 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1570 yaml_scalar_event_initialize(&event, NULL,
1571 (yaml_char_t *)YAML_STR_TAG,
1572 (yaml_char_t *)"peer_credits",
1573 strlen("peer_credits"), 1, 0,
1574 YAML_PLAIN_SCALAR_STYLE);
1575 rc = yaml_emitter_emit(output, &event);
1579 snprintf(num, sizeof(num), "%u",
1580 tunables->lt_cmn.lct_peer_tx_credits);
1581 yaml_scalar_event_initialize(&event, NULL,
1582 (yaml_char_t *)YAML_INT_TAG,
1585 YAML_PLAIN_SCALAR_STYLE);
1586 rc = yaml_emitter_emit(output, &event);
1591 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1592 yaml_scalar_event_initialize(&event, NULL,
1593 (yaml_char_t *)YAML_STR_TAG,
1594 (yaml_char_t *)"peer_buffer_credits",
1595 strlen("peer_buffer_credits"), 1, 0,
1596 YAML_PLAIN_SCALAR_STYLE);
1597 rc = yaml_emitter_emit(output, &event);
1601 snprintf(num, sizeof(num), "%u",
1602 tunables->lt_cmn.lct_peer_rtr_credits);
1603 yaml_scalar_event_initialize(&event, NULL,
1604 (yaml_char_t *)YAML_INT_TAG,
1607 YAML_PLAIN_SCALAR_STYLE);
1608 rc = yaml_emitter_emit(output, &event);
1613 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1614 yaml_scalar_event_initialize(&event, NULL,
1615 (yaml_char_t *)YAML_STR_TAG,
1616 (yaml_char_t *)"credits",
1617 strlen("credits"), 1, 0,
1618 YAML_PLAIN_SCALAR_STYLE);
1619 rc = yaml_emitter_emit(output, &event);
1623 snprintf(num, sizeof(num), "%u",
1624 tunables->lt_cmn.lct_max_tx_credits);
1625 yaml_scalar_event_initialize(&event, NULL,
1626 (yaml_char_t *)YAML_INT_TAG,
1629 YAML_PLAIN_SCALAR_STYLE);
1630 rc = yaml_emitter_emit(output, &event);
1635 yaml_mapping_end_event_initialize(&event);
1636 rc = yaml_emitter_emit(output, &event);
1640 skip_general_settings:
1641 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1643 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0 ||
1644 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0] ||
1646 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1647 yaml_scalar_event_initialize(&event, NULL,
1648 (yaml_char_t *)YAML_STR_TAG,
1649 (yaml_char_t *)"lnd tunables",
1650 strlen("lnd tunables"), 1, 0,
1651 YAML_PLAIN_SCALAR_STYLE);
1652 rc = yaml_emitter_emit(output, &event);
1656 yaml_mapping_start_event_initialize(&event, NULL,
1657 (yaml_char_t *)YAML_MAP_TAG,
1658 1, YAML_ANY_MAPPING_STYLE);
1659 rc = yaml_emitter_emit(output, &event);
1663 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1664 yaml_scalar_event_initialize(&event, NULL,
1665 (yaml_char_t *)YAML_STR_TAG,
1666 (yaml_char_t *)"auth_key",
1667 strlen("auth_key"), 1, 0,
1668 YAML_PLAIN_SCALAR_STYLE);
1669 rc = yaml_emitter_emit(output, &event);
1673 snprintf(num, sizeof(num), "%u",
1674 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1676 yaml_scalar_event_initialize(&event, NULL,
1677 (yaml_char_t *)YAML_INT_TAG,
1680 YAML_PLAIN_SCALAR_STYLE);
1681 rc = yaml_emitter_emit(output, &event);
1686 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0]) {
1687 char *tc = &tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0];
1689 yaml_scalar_event_initialize(&event, NULL,
1690 (yaml_char_t *)YAML_STR_TAG,
1691 (yaml_char_t *)"traffic_class",
1692 strlen("traffic_class"), 1, 0,
1693 YAML_PLAIN_SCALAR_STYLE);
1694 rc = yaml_emitter_emit(output, &event);
1698 yaml_scalar_event_initialize(&event, NULL,
1699 (yaml_char_t *)YAML_INT_TAG,
1702 YAML_PLAIN_SCALAR_STYLE);
1704 rc = yaml_emitter_emit(output, &event);
1709 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1710 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1713 yaml_scalar_event_initialize(&event, NULL,
1714 (yaml_char_t *)YAML_STR_TAG,
1715 (yaml_char_t *)"conns_per_peer",
1716 strlen("conns_per_peer"), 1, 0,
1717 YAML_PLAIN_SCALAR_STYLE);
1718 rc = yaml_emitter_emit(output, &event);
1722 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND)
1723 cpp = tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer;
1724 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND)
1725 cpp = tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer;
1726 snprintf(num, sizeof(num), "%u", cpp);
1728 yaml_scalar_event_initialize(&event, NULL,
1729 (yaml_char_t *)YAML_INT_TAG,
1732 YAML_PLAIN_SCALAR_STYLE);
1733 rc = yaml_emitter_emit(output, &event);
1738 yaml_mapping_end_event_initialize(&event);
1739 rc = yaml_emitter_emit(output, &event);
1745 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1746 struct lnet_dlc_network_descr *nw_descr,
1747 struct lnet_ioctl_config_lnd_tunables *tunables,
1748 struct cfs_expr_list *global_cpts,
1749 int version, int flags)
1751 struct lnet_dlc_intf_descr *intf;
1752 struct nl_sock *sk = NULL;
1753 const char *msg = NULL;
1754 yaml_emitter_t output;
1755 yaml_parser_t reply;
1759 if (!(flags & NLM_F_DUMP) && !ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1760 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1761 (!nw_descr) ? "network , interface" :
1762 (nw_descr->nw_id == 0) ? "network" : "interface");
1766 if ((flags == NLM_F_CREATE) && !ip2net && list_empty(&nw_descr->nw_intflist)) {
1767 fprintf(stdout, "creating a local NI needs at least one interface");
1771 /* Create Netlink emitter to send request to kernel */
1772 sk = nl_socket_alloc();
1776 /* Setup parser to receive Netlink packets */
1777 rc = yaml_parser_initialize(&reply);
1783 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1785 msg = yaml_parser_get_reader_error(&reply);
1789 /* Create Netlink emitter to send request to kernel */
1790 rc = yaml_emitter_initialize(&output);
1792 msg = "failed to initialize emitter";
1796 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1797 version, LNET_CMD_NETS, flags);
1801 yaml_emitter_open(&output);
1802 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1803 rc = yaml_emitter_emit(&output, &event);
1807 yaml_mapping_start_event_initialize(&event, NULL,
1808 (yaml_char_t *)YAML_MAP_TAG,
1809 1, YAML_ANY_MAPPING_STYLE);
1810 rc = yaml_emitter_emit(&output, &event);
1814 yaml_scalar_event_initialize(&event, NULL,
1815 (yaml_char_t *)YAML_STR_TAG,
1816 (yaml_char_t *)"net",
1817 strlen("net"), 1, 0,
1818 YAML_PLAIN_SCALAR_STYLE);
1819 rc = yaml_emitter_emit(&output, &event);
1823 if (net_id || ip2net) {
1824 char *key = net_id ? "net type" : "ip2net";
1825 char *value = net_id ? net_id : ip2net;
1827 yaml_sequence_start_event_initialize(&event, NULL,
1828 (yaml_char_t *)YAML_SEQ_TAG,
1829 1, YAML_ANY_SEQUENCE_STYLE);
1830 rc = yaml_emitter_emit(&output, &event);
1834 yaml_mapping_start_event_initialize(&event, NULL,
1835 (yaml_char_t *)YAML_MAP_TAG,
1836 1, YAML_ANY_MAPPING_STYLE);
1837 rc = yaml_emitter_emit(&output, &event);
1841 yaml_scalar_event_initialize(&event, NULL,
1842 (yaml_char_t *)YAML_STR_TAG,
1845 1, 0, YAML_PLAIN_SCALAR_STYLE);
1846 rc = yaml_emitter_emit(&output, &event);
1850 yaml_scalar_event_initialize(&event, NULL,
1851 (yaml_char_t *)YAML_STR_TAG,
1852 (yaml_char_t *)value,
1853 strlen(value), 1, 0,
1854 YAML_PLAIN_SCALAR_STYLE);
1855 rc = yaml_emitter_emit(&output, &event);
1859 yaml_scalar_event_initialize(&event, NULL,
1860 (yaml_char_t *)YAML_STR_TAG,
1863 YAML_PLAIN_SCALAR_STYLE);
1864 rc = yaml_emitter_emit(&output, &event);
1871 if (!nw_descr || list_empty(&nw_descr->nw_intflist))
1874 yaml_scalar_event_initialize(&event, NULL,
1875 (yaml_char_t *)YAML_STR_TAG,
1876 (yaml_char_t *)"local NI(s)",
1877 strlen("local NI(s)"), 1, 0,
1878 YAML_PLAIN_SCALAR_STYLE);
1879 rc = yaml_emitter_emit(&output, &event);
1883 yaml_sequence_start_event_initialize(&event, NULL,
1884 (yaml_char_t *)YAML_SEQ_TAG,
1885 1, YAML_ANY_SEQUENCE_STYLE);
1886 rc = yaml_emitter_emit(&output, &event);
1890 list_for_each_entry(intf, &nw_descr->nw_intflist,
1892 yaml_mapping_start_event_initialize(&event, NULL,
1893 (yaml_char_t *)YAML_MAP_TAG,
1894 1, YAML_ANY_MAPPING_STYLE);
1895 rc = yaml_emitter_emit(&output, &event);
1899 yaml_scalar_event_initialize(&event, NULL,
1900 (yaml_char_t *)YAML_STR_TAG,
1901 (yaml_char_t *)"interfaces",
1902 strlen("interfaces"), 1, 0,
1903 YAML_PLAIN_SCALAR_STYLE);
1904 rc = yaml_emitter_emit(&output, &event);
1908 yaml_mapping_start_event_initialize(&event, NULL,
1909 (yaml_char_t *)YAML_MAP_TAG,
1910 1, YAML_ANY_MAPPING_STYLE);
1911 rc = yaml_emitter_emit(&output, &event);
1915 yaml_scalar_event_initialize(&event, NULL,
1916 (yaml_char_t *)YAML_STR_TAG,
1919 YAML_PLAIN_SCALAR_STYLE);
1920 rc = yaml_emitter_emit(&output, &event);
1924 yaml_scalar_event_initialize(&event, NULL,
1925 (yaml_char_t *)YAML_STR_TAG,
1926 (yaml_char_t *)intf->intf_name,
1927 strlen(intf->intf_name), 1, 0,
1928 YAML_PLAIN_SCALAR_STYLE);
1929 rc = yaml_emitter_emit(&output, &event);
1933 yaml_mapping_end_event_initialize(&event);
1934 rc = yaml_emitter_emit(&output, &event);
1939 rc = yaml_add_ni_tunables(&output, tunables, nw_descr);
1948 yaml_scalar_event_initialize(&event, NULL,
1949 (yaml_char_t *)YAML_STR_TAG,
1950 (yaml_char_t *)"CPT",
1951 strlen("CPT"), 1, 0,
1952 YAML_PLAIN_SCALAR_STYLE);
1953 rc = yaml_emitter_emit(&output, &event);
1957 yaml_sequence_start_event_initialize(&event, NULL,
1958 (yaml_char_t *)YAML_SEQ_TAG,
1960 YAML_FLOW_SEQUENCE_STYLE);
1961 rc = yaml_emitter_emit(&output, &event);
1965 count = cfs_expr_list_values(global_cpts,
1966 LNET_MAX_SHOW_NUM_CPT,
1968 for (i = 0; i < count; i++) {
1969 char core[INT_STRING_LEN];
1971 snprintf(core, sizeof(core), "%u", cpt_array[i]);
1972 yaml_scalar_event_initialize(&event, NULL,
1973 (yaml_char_t *)YAML_STR_TAG,
1974 (yaml_char_t *)core,
1976 YAML_PLAIN_SCALAR_STYLE);
1977 rc = yaml_emitter_emit(&output, &event);
1982 yaml_sequence_end_event_initialize(&event);
1983 rc = yaml_emitter_emit(&output, &event);
1987 cfs_expr_list_free(global_cpts);
1991 yaml_mapping_end_event_initialize(&event);
1992 rc = yaml_emitter_emit(&output, &event);
1997 yaml_sequence_end_event_initialize(&event);
1998 rc = yaml_emitter_emit(&output, &event);
2002 yaml_mapping_end_event_initialize(&event);
2003 rc = yaml_emitter_emit(&output, &event);
2007 yaml_sequence_end_event_initialize(&event);
2008 rc = yaml_emitter_emit(&output, &event);
2012 yaml_mapping_end_event_initialize(&event);
2013 rc = yaml_emitter_emit(&output, &event);
2017 yaml_document_end_event_initialize(&event, 0);
2018 rc = yaml_emitter_emit(&output, &event);
2022 rc = yaml_emitter_close(&output);
2025 yaml_emitter_log_error(&output, stderr);
2028 yaml_document_t errmsg;
2030 rc = yaml_parser_load(&reply, &errmsg);
2031 if (rc == 1 && (flags & NLM_F_DUMP)) {
2032 yaml_emitter_t debug;
2034 rc = yaml_emitter_initialize(&debug);
2036 yaml_emitter_set_indent(&debug,
2037 LNET_DEFAULT_INDENT);
2038 yaml_emitter_set_output_file(&debug, stdout);
2039 rc = yaml_emitter_dump(&debug, &errmsg);
2041 yaml_emitter_delete(&debug);
2043 msg = yaml_parser_get_reader_error(&reply);
2045 yaml_document_delete(&errmsg);
2047 yaml_emitter_delete(&output);
2050 yaml_lnet_print_error(flags, "net", msg);
2053 yaml_parser_delete(&reply);
2056 return rc == 1 ? 0 : rc;
2059 static int jt_add_ni(int argc, char **argv)
2061 char *ip2net = NULL;
2062 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
2063 char *traffic_class = NULL;
2064 struct cYAML *err_rc = NULL;
2065 int rc, opt, cpt_rc = -1;
2066 struct lnet_dlc_network_descr nw_descr;
2067 struct cfs_expr_list *global_cpts = NULL;
2068 struct lnet_ioctl_config_lnd_tunables tunables;
2070 bool skip_mr_route_setup = false;
2071 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:T:";
2072 static const struct option long_options[] = {
2073 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
2074 { .name = "peer-buffer-credits",
2075 .has_arg = required_argument, .val = 'b' },
2076 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
2077 { .name = "if", .has_arg = required_argument, .val = 'i' },
2078 { .name = "skip-mr-route-setup",
2079 .has_arg = no_argument, .val = 'k' },
2080 { .name = "conns-per-peer",
2081 .has_arg = required_argument, .val = 'm' },
2082 { .name = "net", .has_arg = required_argument, .val = 'n' },
2083 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
2084 { .name = "credits", .has_arg = required_argument, .val = 'r' },
2085 { .name = "cpt", .has_arg = required_argument, .val = 's' },
2086 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
2087 { .name = "traffic-class", .has_arg = required_argument, .val = 'T' },
2089 char *net_id = NULL;
2091 memset(&tunables, 0, sizeof(tunables));
2092 lustre_lnet_init_nw_descr(&nw_descr);
2094 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
2098 while ((opt = getopt_long(argc, argv, short_options,
2099 long_options, NULL)) != -1) {
2102 rc = parse_long(optarg, &auth_key);
2110 rc = parse_long(optarg, &pbc);
2118 rc = parse_long(optarg, &pc);
2126 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2128 cYAML_build_error(-1, -1, "ni", "add",
2129 "bad interface list",
2135 skip_mr_route_setup = true;
2138 rc = parse_long(optarg, &cpp);
2147 nw_descr.nw_id = libcfs_str2net(optarg);
2154 rc = parse_long(optarg, &cre);
2162 cpt_rc = cfs_expr_list_parse(optarg,
2164 UINT_MAX, &global_cpts);
2167 rc = parse_long(optarg, &pto);
2175 traffic_class = optarg;
2176 if (strlen(traffic_class) == 0 ||
2177 strlen(traffic_class) >= LNET_MAX_STR_LEN) {
2178 cYAML_build_error(-1, -1, "ni", "add",
2179 "Invalid traffic-class argument",
2181 rc = LUSTRE_CFG_RC_BAD_PARAM;
2186 print_help(net_cmds, "net", "add");
2192 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
2193 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
2197 if (traffic_class && LNET_NETTYP(nw_descr.nw_id) == KFILND &&
2198 strlen(traffic_class) < LNET_MAX_STR_LEN) {
2199 strcpy(&tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0],
2205 if (LNET_NETTYP(nw_descr.nw_id) == SOCKLND && (cpp > -1)) {
2206 tunables.lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
2208 } else if (LNET_NETTYP(nw_descr.nw_id) == O2IBLND && (cpp > -1)) {
2209 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
2213 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
2214 tunables.lt_cmn.lct_peer_timeout = pto;
2215 tunables.lt_cmn.lct_peer_tx_credits = pc;
2216 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
2217 tunables.lt_cmn.lct_max_tx_credits = cre;
2221 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
2222 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
2224 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
2225 found ? &tunables : NULL,
2226 (cpt_rc == 0) ? global_cpts : NULL,
2227 LNET_GENL_VERSION, NLM_F_CREATE);
2229 if (rc == -EOPNOTSUPP)
2231 if (global_cpts != NULL)
2232 cfs_expr_list_free(global_cpts);
2233 if (rc == 0 && !skip_mr_route_setup)
2234 rc = lustre_lnet_setup_mrrouting(&err_rc);
2238 rc = lustre_lnet_config_ni(&nw_descr,
2239 (cpt_rc == 0) ? global_cpts: NULL,
2240 ip2net, (found) ? &tunables : NULL,
2243 if (global_cpts != NULL)
2244 cfs_expr_list_free(global_cpts);
2247 if (rc != LUSTRE_CFG_RC_NO_ERR)
2248 cYAML_print_tree2file(stderr, err_rc);
2250 cYAML_free_tree(err_rc);
2252 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
2254 rc = lustre_lnet_setup_mrrouting(&err_rc);
2256 if (rc != LUSTRE_CFG_RC_NO_ERR)
2257 cYAML_print_tree2file(stderr, err_rc);
2259 cYAML_free_tree(err_rc);
2265 static int jt_del_route(int argc, char **argv)
2267 char *network = NULL, *gateway = NULL;
2268 struct cYAML *err_rc = NULL;
2271 const char *const short_options = "n:g:";
2272 static const struct option long_options[] = {
2273 { .name = "net", .has_arg = required_argument, .val = 'n' },
2274 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2277 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
2281 while ((opt = getopt_long(argc, argv, short_options,
2282 long_options, NULL)) != -1) {
2291 print_help(route_cmds, "route", "del");
2297 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
2299 if (rc != LUSTRE_CFG_RC_NO_ERR)
2300 cYAML_print_tree2file(stderr, err_rc);
2302 cYAML_free_tree(err_rc);
2307 static int jt_del_ni(int argc, char **argv)
2309 struct cYAML *err_rc = NULL;
2311 struct lnet_dlc_network_descr nw_descr;
2312 const char *const short_options = "n:i:";
2313 static const struct option long_options[] = {
2314 { .name = "net", .has_arg = required_argument, .val = 'n' },
2315 { .name = "if", .has_arg = required_argument, .val = 'i' },
2317 char *net_id = NULL;
2319 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
2323 lustre_lnet_init_nw_descr(&nw_descr);
2325 while ((opt = getopt_long(argc, argv, short_options,
2326 long_options, NULL)) != -1) {
2329 nw_descr.nw_id = libcfs_str2net(optarg);
2333 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2335 cYAML_build_error(-1, -1, "ni", "add",
2336 "bad interface list",
2342 print_help(net_cmds, "net", "del");
2348 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, NULL,
2349 LNET_GENL_VERSION, 0);
2351 if (rc != -EOPNOTSUPP)
2355 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
2357 if (rc != LUSTRE_CFG_RC_NO_ERR)
2358 cYAML_print_tree2file(stderr, err_rc);
2360 cYAML_free_tree(err_rc);
2365 static int jt_show_route(int argc, char **argv)
2367 char *network = NULL, *gateway = NULL;
2368 long int hop = -1, prio = -1;
2369 int detail = 0, rc, opt;
2370 struct cYAML *err_rc = NULL, *show_rc = NULL;
2371 const char *const short_options = "c:n:g:p:v";
2372 static const struct option long_options[] = {
2373 { .name = "net", .has_arg = required_argument, .val = 'n' },
2374 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2375 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
2376 { .name = "hop", .has_arg = required_argument, .val = 'c' },
2377 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2378 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
2382 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
2386 while ((opt = getopt_long(argc, argv, short_options,
2387 long_options, NULL)) != -1) {
2396 rc = parse_long(optarg, &hop);
2404 rc = parse_long(optarg, &prio);
2415 print_help(route_cmds, "route", "show");
2421 rc = yaml_lnet_route(network, gateway, hop, prio, -1,
2422 detail, NLM_F_DUMP);
2424 if (rc == -EOPNOTSUPP)
2429 rc = lustre_lnet_show_route(network, gateway, hop, prio,
2431 &show_rc, &err_rc, false);
2433 if (rc != LUSTRE_CFG_RC_NO_ERR)
2434 cYAML_print_tree2file(stderr, err_rc);
2436 cYAML_print_tree(show_rc);
2438 cYAML_free_tree(err_rc);
2439 cYAML_free_tree(show_rc);
2444 static int set_value_helper(int argc, char **argv,
2445 int (*cb)(int, bool, char*, int, struct cYAML**))
2448 long int healthv = -1;
2450 long int state = -1;
2452 struct cYAML *err_rc = NULL;
2454 const char *const short_options = "t:n:s:a";
2455 static const struct option long_options[] = {
2456 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2457 { .name = "health", .has_arg = required_argument, .val = 't' },
2458 { .name = "state", .has_arg = required_argument, .val = 's' },
2459 { .name = "all", .has_arg = no_argument, .val = 'a' },
2462 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2466 while ((opt = getopt_long(argc, argv, short_options,
2467 long_options, NULL)) != -1) {
2473 if (parse_long(optarg, &healthv) != 0)
2477 if (parse_long(optarg, &state) != 0)
2489 rc = lustre_lnet_set_peer_state(state, nid, -1, &err_rc);
2491 rc = cb(healthv, all, nid, -1, &err_rc);
2493 if (rc != LUSTRE_CFG_RC_NO_ERR)
2494 cYAML_print_tree2file(stderr, err_rc);
2496 cYAML_free_tree(err_rc);
2501 static int jt_set_ni_value(int argc, char **argv)
2504 long int healthv = -1, cpp = -1;
2507 struct cYAML *err_rc = NULL;
2509 const char *const short_options = "a:m:n:t:";
2510 static const struct option long_options[] = {
2511 { .name = "all", .has_arg = no_argument, .val = 'a' },
2512 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2513 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2514 { .name = "health", .has_arg = required_argument, .val = 't' },
2517 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2521 while ((opt = getopt_long(argc, argv, short_options,
2522 long_options, NULL)) != -1) {
2528 rc = parse_long(optarg, &cpp);
2539 if (parse_long(optarg, &healthv) != 0) {
2551 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2554 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2557 if (rc != LUSTRE_CFG_RC_NO_ERR)
2558 cYAML_print_tree2file(stderr, err_rc);
2560 cYAML_free_tree(err_rc);
2565 static int yaml_lnet_peer_display(yaml_parser_t *reply, bool list_only)
2567 yaml_emitter_t debug;
2570 rc = yaml_emitter_initialize(&debug);
2574 yaml_emitter_set_indent(&debug, 6);
2575 yaml_emitter_set_output_file(&debug, stdout);
2584 rc = yaml_parser_parse(reply, &event);
2586 goto report_reply_error;
2588 if (event.type != YAML_SCALAR_EVENT)
2591 value = (char *)event.data.scalar.value;
2592 if (strcmp(value, "peer") == 0) {
2593 yaml_event_delete(&event);
2595 yaml_scalar_event_initialize(&event, NULL,
2596 (yaml_char_t *)YAML_STR_TAG,
2597 (yaml_char_t *)"peer list",
2598 strlen("peer list"),
2600 YAML_PLAIN_SCALAR_STYLE);
2601 } else if (strcmp(value, "primary nid") == 0) {
2602 yaml_event_delete(&event);
2604 yaml_scalar_event_initialize(&event, NULL,
2605 (yaml_char_t *)YAML_STR_TAG,
2606 (yaml_char_t *)"nid",
2609 YAML_PLAIN_SCALAR_STYLE);
2610 rc = yaml_emitter_emit(&debug, &event);
2614 /* Now print NID address */
2615 rc = yaml_parser_parse(reply, &event);
2617 goto report_reply_error;
2619 rc = yaml_emitter_emit(&debug, &event);
2624 while (event.type != YAML_MAPPING_END_EVENT) {
2625 rc = yaml_parser_parse(reply, &event);
2627 goto report_reply_error;
2630 /* we can have map end, seq end, map end or
2631 * just map end event. If we see seq end event
2632 * then skip to next mapping end event
2634 rc = yaml_parser_parse(reply, &event);
2636 goto report_reply_error;
2638 if (event.type == YAML_SEQUENCE_END_EVENT) {
2639 yaml_event_delete(&event);
2641 rc = yaml_parser_parse(reply, &event);
2643 goto report_reply_error;
2647 rc = yaml_emitter_emit(&debug, &event);
2651 done = (event.type == YAML_DOCUMENT_END_EVENT);
2654 yaml_document_t errmsg;
2656 rc = yaml_parser_load(reply, &errmsg);
2658 rc = yaml_emitter_dump(&debug, &errmsg);
2659 yaml_document_delete(&errmsg);
2663 yaml_emitter_log_error(&debug, stderr);
2665 yaml_emitter_delete(&debug);
2670 static int yaml_lnet_peer(char *prim_nid, char *nidstr, bool disable_mr,
2671 int health_value, int state, bool list_only,
2672 int version, int flags)
2674 struct nl_sock *sk = NULL;
2675 const char *msg = NULL;
2676 yaml_emitter_t output;
2677 yaml_parser_t reply;
2681 /* Create Netlink emitter to send request to kernel */
2682 sk = nl_socket_alloc();
2686 /* Setup parser to receive Netlink packets */
2687 rc = yaml_parser_initialize(&reply);
2693 rc = yaml_parser_set_input_netlink(&reply, sk, false);
2695 msg = yaml_parser_get_reader_error(&reply);
2699 /* Create Netlink emitter to send request to kernel */
2700 rc = yaml_emitter_initialize(&output);
2702 msg = "failed to initialize emitter";
2706 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
2707 version, LNET_CMD_PEERS, flags);
2711 yaml_emitter_open(&output);
2712 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
2713 rc = yaml_emitter_emit(&output, &event);
2717 yaml_mapping_start_event_initialize(&event, NULL,
2718 (yaml_char_t *)YAML_MAP_TAG,
2719 1, YAML_ANY_MAPPING_STYLE);
2720 rc = yaml_emitter_emit(&output, &event);
2724 yaml_scalar_event_initialize(&event, NULL,
2725 (yaml_char_t *)YAML_STR_TAG,
2726 (yaml_char_t *)"peer",
2727 strlen("peer"), 1, 0,
2728 YAML_PLAIN_SCALAR_STYLE);
2729 rc = yaml_emitter_emit(&output, &event);
2734 yaml_sequence_start_event_initialize(&event, NULL,
2735 (yaml_char_t *)YAML_SEQ_TAG,
2737 YAML_BLOCK_SEQUENCE_STYLE);
2738 rc = yaml_emitter_emit(&output, &event);
2742 yaml_mapping_start_event_initialize(&event, NULL,
2743 (yaml_char_t *)YAML_MAP_TAG,
2745 YAML_BLOCK_MAPPING_STYLE);
2746 rc = yaml_emitter_emit(&output, &event);
2750 yaml_scalar_event_initialize(&event, NULL,
2751 (yaml_char_t *)YAML_STR_TAG,
2752 (yaml_char_t *)"primary nid",
2753 strlen("primary nid"), 1, 0,
2754 YAML_PLAIN_SCALAR_STYLE);
2755 rc = yaml_emitter_emit(&output, &event);
2759 yaml_scalar_event_initialize(&event, NULL,
2760 (yaml_char_t *)YAML_STR_TAG,
2761 (yaml_char_t *)prim_nid,
2762 strlen(prim_nid), 1, 0,
2763 YAML_PLAIN_SCALAR_STYLE);
2764 rc = yaml_emitter_emit(&output, &event);
2768 yaml_mapping_end_event_initialize(&event);
2769 rc = yaml_emitter_emit(&output, &event);
2773 yaml_sequence_end_event_initialize(&event);
2774 rc = yaml_emitter_emit(&output, &event);
2778 yaml_scalar_event_initialize(&event, NULL,
2779 (yaml_char_t *)YAML_STR_TAG,
2782 YAML_PLAIN_SCALAR_STYLE);
2783 rc = yaml_emitter_emit(&output, &event);
2788 yaml_mapping_end_event_initialize(&event);
2789 rc = yaml_emitter_emit(&output, &event);
2793 yaml_document_end_event_initialize(&event, 0);
2794 rc = yaml_emitter_emit(&output, &event);
2798 rc = yaml_emitter_close(&output);
2801 yaml_emitter_log_error(&output, stderr);
2804 rc = yaml_lnet_peer_display(&reply, list_only);
2806 msg = yaml_parser_get_reader_error(&reply);
2807 /* If we didn't find any peers just be silent */
2808 if (msg && strcmp(msg, "No peers found") == 0)
2813 yaml_emitter_delete(&output);
2816 yaml_lnet_print_error(flags, "peer", msg);
2819 yaml_parser_delete(&reply);
2822 return rc == 1 ? 0 : rc;
2825 static int jt_set_peer_ni_value(int argc, char **argv)
2827 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
2830 static int jt_show_recovery(int argc, char **argv)
2833 struct cYAML *err_rc = NULL, *show_rc = NULL;
2834 const char *const short_options = "lp";
2835 static const struct option long_options[] = {
2836 { .name = "local", .has_arg = no_argument, .val = 'l' },
2837 { .name = "peer", .has_arg = no_argument, .val = 'p' },
2840 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
2844 while ((opt = getopt_long(argc, argv, short_options,
2845 long_options, NULL)) != -1) {
2848 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
2851 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
2858 if (rc != LUSTRE_CFG_RC_NO_ERR)
2859 cYAML_print_tree2file(stderr, err_rc);
2861 cYAML_print_tree(show_rc);
2863 cYAML_free_tree(err_rc);
2864 cYAML_free_tree(show_rc);
2869 static int jt_show_peer_debug_info(int argc, char **argv)
2872 struct cYAML *err_rc = NULL;
2873 char *peer_nid = optarg;
2874 const char *const short_opts = "k";
2875 const struct option long_opts[] = {
2876 { .name = "nid", .has_arg = required_argument, .val = 'k' },
2879 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
2884 while ((opt = getopt_long(argc, argv, short_opts,
2885 long_opts, NULL)) != -1) {
2895 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
2897 if (rc != LUSTRE_CFG_RC_NO_ERR)
2898 cYAML_print_tree2file(stderr, err_rc);
2900 cYAML_free_tree(err_rc);
2905 static int jt_show_net(int argc, char **argv)
2907 char *network = NULL;
2909 struct cYAML *err_rc = NULL, *show_rc = NULL;
2910 long int detail = 0;
2911 const char *const short_options = "n:v";
2912 static const struct option long_options[] = {
2913 { .name = "net", .has_arg = required_argument, .val = 'n' },
2914 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
2917 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
2921 while ((opt = getopt_long(argc, argv, short_options,
2922 long_options, NULL)) != -1) {
2928 if ((!optarg) && (argv[optind] != NULL) &&
2929 (argv[optind][0] != '-')) {
2930 if (parse_long(argv[optind++], &detail) != 0)
2937 print_help(net_cmds, "net", "show");
2943 rc = yaml_lnet_config_ni(network, NULL, NULL, NULL, NULL,
2944 detail, NLM_F_DUMP);
2946 if (rc != -EOPNOTSUPP)
2950 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
2953 if (rc != LUSTRE_CFG_RC_NO_ERR)
2954 cYAML_print_tree2file(stderr, err_rc);
2956 cYAML_print_tree(show_rc);
2958 cYAML_free_tree(err_rc);
2959 cYAML_free_tree(show_rc);
2964 static int jt_show_routing(int argc, char **argv)
2966 struct cYAML *err_rc = NULL, *show_rc = NULL;
2969 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
2973 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
2975 if (rc != LUSTRE_CFG_RC_NO_ERR)
2976 cYAML_print_tree2file(stderr, err_rc);
2978 cYAML_print_tree(show_rc);
2980 cYAML_free_tree(err_rc);
2981 cYAML_free_tree(show_rc);
2986 static int jt_show_stats(int argc, char **argv)
2989 struct cYAML *show_rc = NULL, *err_rc = NULL;
2991 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
2995 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
2997 if (rc != LUSTRE_CFG_RC_NO_ERR)
2998 cYAML_print_tree2file(stderr, err_rc);
3000 cYAML_print_tree(show_rc);
3002 cYAML_free_tree(err_rc);
3003 cYAML_free_tree(show_rc);
3008 static int jt_show_udsp(int argc, char **argv)
3012 struct cYAML *err_rc = NULL, *show_rc = NULL;
3014 const char *const short_options = "i:";
3015 static const struct option long_options[] = {
3016 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3020 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
3024 while ((opt = getopt_long(argc, argv, short_options,
3025 long_options, NULL)) != -1) {
3028 rc = parse_long(optarg, &idx);
3029 if (rc != 0 || idx < -1) {
3030 printf("Invalid index \"%s\"\n", optarg);
3035 print_help(net_cmds, "net", "show");
3041 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
3043 if (rc != LUSTRE_CFG_RC_NO_ERR)
3044 cYAML_print_tree2file(stderr, err_rc);
3046 cYAML_print_tree(show_rc);
3048 cYAML_free_tree(err_rc);
3049 cYAML_free_tree(show_rc);
3054 static int jt_show_global(int argc, char **argv)
3057 struct cYAML *show_rc = NULL, *err_rc = NULL;
3059 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
3063 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3064 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3065 cYAML_print_tree2file(stderr, err_rc);
3069 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3070 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3071 cYAML_print_tree2file(stderr, err_rc);
3075 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3076 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3077 cYAML_print_tree2file(stderr, err_rc);
3081 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3082 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3083 cYAML_print_tree2file(stderr, err_rc);
3087 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3088 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3089 cYAML_print_tree2file(stderr, err_rc);
3093 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3094 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3095 cYAML_print_tree2file(stderr, err_rc);
3099 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3100 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3101 cYAML_print_tree2file(stderr, err_rc);
3105 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3106 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3107 cYAML_print_tree2file(stderr, err_rc);
3111 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3112 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3113 cYAML_print_tree2file(stderr, err_rc);
3117 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3118 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3119 cYAML_print_tree2file(stderr, err_rc);
3123 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3124 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3125 cYAML_print_tree2file(stderr, err_rc);
3129 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3130 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3131 cYAML_print_tree2file(stderr, err_rc);
3135 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3136 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3137 cYAML_print_tree2file(stderr, err_rc);
3142 cYAML_print_tree(show_rc);
3145 cYAML_free_tree(err_rc);
3146 cYAML_free_tree(show_rc);
3151 static int jt_lnet(int argc, char **argv)
3155 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
3159 return cfs_parser(argc, argv, lnet_cmds);
3162 static int jt_route(int argc, char **argv)
3166 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
3170 return cfs_parser(argc, argv, route_cmds);
3173 static int jt_net(int argc, char **argv)
3177 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
3181 return cfs_parser(argc, argv, net_cmds);
3184 static int jt_routing(int argc, char **argv)
3188 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
3192 return cfs_parser(argc, argv, routing_cmds);
3195 static int jt_stats(int argc, char **argv)
3199 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
3203 return cfs_parser(argc, argv, stats_cmds);
3206 static int jt_debug(int argc, char **argv)
3210 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
3214 return cfs_parser(argc, argv, debug_cmds);
3217 static int jt_global(int argc, char **argv)
3221 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
3225 return cfs_parser(argc, argv, global_cmds);
3228 static int jt_peers(int argc, char **argv)
3232 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
3236 return cfs_parser(argc, argv, peer_cmds);
3239 static int jt_set(int argc, char **argv)
3243 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
3247 return cfs_parser(argc, argv, set_cmds);
3250 static int jt_udsp(int argc, char **argv)
3254 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
3258 return cfs_parser(argc, argv, udsp_cmds);
3261 static int jt_import(int argc, char **argv)
3264 struct cYAML *err_rc = NULL;
3265 struct cYAML *show_rc = NULL;
3266 int rc = 0, return_rc = 0, opt, opt_found = 0;
3269 const char *const short_options = "adseh";
3270 static const struct option long_options[] = {
3271 { .name = "add", .has_arg = no_argument, .val = 'a' },
3272 { .name = "del", .has_arg = no_argument, .val = 'd' },
3273 { .name = "show", .has_arg = no_argument, .val = 's' },
3274 { .name = "exec", .has_arg = no_argument, .val = 'e' },
3275 { .name = "help", .has_arg = no_argument, .val = 'h' },
3278 while ((opt = getopt_long(argc, argv, short_options,
3279 long_options, NULL)) != -1) {
3293 printf("import FILE\n"
3294 "import < FILE : import a file\n"
3295 "\t--add: add configuration\n"
3296 "\t--del: delete configuration\n"
3297 "\t--show: show configuration\n"
3298 "\t--exec: execute command\n"
3299 "\t--help: display this help\n"
3300 "If no command option is given then --add"
3301 " is assumed by default\n");
3308 /* grab the file name if one exists */
3309 if (opt_found && argc == 3)
3311 else if (!opt_found && argc == 2)
3316 rc = lustre_yaml_config(file, &err_rc);
3317 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3318 cYAML_print_tree(show_rc);
3319 cYAML_free_tree(show_rc);
3322 rc = lustre_yaml_del(file, &err_rc);
3325 rc = lustre_yaml_show(file, &show_rc, &err_rc);
3326 cYAML_print_tree(show_rc);
3327 cYAML_free_tree(show_rc);
3330 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3331 cYAML_print_tree(show_rc);
3332 cYAML_free_tree(show_rc);
3336 if (rc || return_rc) {
3337 cYAML_print_tree2file(stderr, err_rc);
3338 cYAML_free_tree(err_rc);
3344 static int jt_export(int argc, char **argv)
3346 struct cYAML *show_rc = NULL;
3347 struct cYAML *err_rc = NULL;
3351 bool backup = false;
3354 const char *const short_options = "bh";
3355 static const struct option long_options[] = {
3356 { .name = "backup", .has_arg = no_argument, .val = 'b' },
3357 { .name = "help", .has_arg = no_argument, .val = 'h' },
3360 while ((opt = getopt_long(argc, argv, short_options,
3361 long_options, NULL)) != -1) {
3368 printf("export > FILE.yaml : export configuration\n"
3369 "\t--backup: export only what's necessary for reconfig\n"
3370 "\t--help: display this help\n");
3375 if (backup && argc >= 3)
3377 else if (!backup && argc >= 2)
3383 f = fopen(file, "w");
3388 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
3389 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3390 cYAML_print_tree2file(stderr, err_rc);
3391 cYAML_free_tree(err_rc);
3395 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
3397 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3398 cYAML_print_tree2file(stderr, err_rc);
3399 cYAML_free_tree(err_rc);
3403 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
3404 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3405 cYAML_print_tree2file(stderr, err_rc);
3406 cYAML_free_tree(err_rc);
3410 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
3411 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3412 cYAML_print_tree2file(stderr, err_rc);
3413 cYAML_free_tree(err_rc);
3417 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3418 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3419 cYAML_print_tree2file(stderr, err_rc);
3420 cYAML_free_tree(err_rc);
3424 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3425 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3426 cYAML_print_tree2file(stderr, err_rc);
3427 cYAML_free_tree(err_rc);
3431 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3432 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3433 cYAML_print_tree2file(stderr, err_rc);
3434 cYAML_free_tree(err_rc);
3438 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3439 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3440 cYAML_print_tree2file(stderr, err_rc);
3441 cYAML_free_tree(err_rc);
3445 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3446 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3447 cYAML_print_tree2file(stderr, err_rc);
3451 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3452 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3453 cYAML_print_tree2file(stderr, err_rc);
3457 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3458 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3459 cYAML_print_tree2file(stderr, err_rc);
3463 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3464 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3465 cYAML_print_tree2file(stderr, err_rc);
3469 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3470 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3471 cYAML_print_tree2file(stderr, err_rc);
3475 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3476 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3477 cYAML_print_tree2file(stderr, err_rc);
3481 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3482 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3483 cYAML_print_tree2file(stderr, err_rc);
3484 cYAML_free_tree(err_rc);
3488 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3489 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3490 cYAML_print_tree2file(stderr, err_rc);
3491 cYAML_free_tree(err_rc);
3495 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3496 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3497 cYAML_print_tree2file(stderr, err_rc);
3498 cYAML_free_tree(err_rc);
3502 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
3503 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3504 cYAML_print_tree2file(stderr, err_rc);
3505 cYAML_free_tree(err_rc);
3509 if (show_rc != NULL) {
3510 cYAML_print_tree2file(f, show_rc);
3511 cYAML_free_tree(show_rc);
3520 static int jt_peer_nid_common(int argc, char **argv, int cmd)
3522 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
3524 char *prim_nid = NULL, *nidstr = NULL;
3525 char err_str[LNET_MAX_STR_LEN] = "Error";
3526 struct cYAML *err_rc = NULL;
3529 const char *const short_opts = "k:m:n:f:l";
3530 const struct option long_opts[] = {
3531 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
3532 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
3533 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3534 { .name = "force", .has_arg = no_argument, .val = 'f' },
3535 { .name = "lock_prim", .has_arg = no_argument, .val = 'l' },
3538 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
3542 while ((opt = getopt_long(argc, argv, short_opts,
3543 long_opts, NULL)) != -1) {
3552 if (cmd == LNETCTL_DEL_CMD) {
3553 rc = LUSTRE_CFG_RC_BAD_PARAM;
3554 snprintf(err_str, LNET_MAX_STR_LEN,
3555 "Unrecognized option '-%c'", opt);
3561 if (cmd == LNETCTL_ADD_CMD) {
3562 rc = LUSTRE_CFG_RC_BAD_PARAM;
3563 snprintf(err_str, LNET_MAX_STR_LEN,
3564 "Unrecognized option '-%c'", opt);
3569 if (cmd == LNETCTL_DEL_CMD) {
3570 rc = LUSTRE_CFG_RC_BAD_PARAM;
3571 snprintf(err_str, LNET_MAX_STR_LEN,
3572 "Unrecognized option '-%c'", opt);
3577 print_help(peer_cmds, "peer",
3578 cmd == LNETCTL_ADD_CMD ? "add" : "del");
3584 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
3585 force_lock, -1, &err_rc);
3586 if (rc != LUSTRE_CFG_RC_NO_ERR)
3590 cYAML_build_error(rc, -1, "peer",
3591 cmd == LNETCTL_ADD_CMD ? "add" : "del",
3595 if (rc != LUSTRE_CFG_RC_NO_ERR)
3596 cYAML_print_tree2file(stderr, err_rc);
3598 cYAML_free_tree(err_rc);
3603 static int jt_add_peer_nid(int argc, char **argv)
3605 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
3608 static int jt_del_peer_nid(int argc, char **argv)
3610 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
3613 static int jt_show_peer(int argc, char **argv)
3617 struct cYAML *err_rc = NULL, *show_rc = NULL;
3618 long int detail = 0;
3619 const char *const short_opts = "hn:v::";
3620 const struct option long_opts[] = {
3621 { .name = "help", .has_arg = no_argument, .val = 'h' },
3622 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3623 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3627 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
3631 while ((opt = getopt_long(argc, argv, short_opts,
3632 long_opts, NULL)) != -1) {
3638 if ((!optarg) && (argv[optind] != NULL) &&
3639 (argv[optind][0] != '-')) {
3640 if (parse_long(argv[optind++], &detail) != 0)
3647 print_help(peer_cmds, "peer", "show");
3653 rc = yaml_lnet_peer(nid, NULL, false, -1, -1, false, detail,
3656 if (rc == -EOPNOTSUPP)
3661 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
3664 if (rc != LUSTRE_CFG_RC_NO_ERR)
3665 cYAML_print_tree2file(stderr, err_rc);
3667 cYAML_print_tree(show_rc);
3669 cYAML_free_tree(err_rc);
3670 cYAML_free_tree(show_rc);
3675 static int jt_list_peer(int argc, char **argv)
3678 struct cYAML *err_rc = NULL, *list_rc = NULL;
3680 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
3684 rc = yaml_lnet_peer(NULL, NULL, false, -1, -1, true, 0, NLM_F_DUMP);
3686 if (rc == -EOPNOTSUPP)
3691 if (rc != LUSTRE_CFG_RC_NO_ERR)
3692 cYAML_print_tree2file(stderr, err_rc);
3694 cYAML_print_tree(list_rc);
3696 cYAML_free_tree(err_rc);
3697 cYAML_free_tree(list_rc);
3702 static int jt_ping(int argc, char **argv)
3704 struct cYAML *err_rc = NULL;
3705 struct cYAML *show_rc = NULL;
3708 char *src_nidstr = NULL;
3710 const char *const short_options = "hs:t:";
3711 const struct option long_options[] = {
3712 { .name = "help", .has_arg = no_argument, .val = 'h' },
3713 { .name = "timeout", .has_arg = required_argument, .val = 't' },
3714 { .name = "source", .has_arg = required_argument, .val = 's' },
3717 while ((opt = getopt_long(argc, argv, short_options,
3718 long_options, NULL)) != -1) {
3721 src_nidstr = optarg;
3724 timeout = 1000 * atol(optarg);
3727 printf("ping nid[,nid,...]\n"
3728 "\t --source: source nid\n"
3729 "\t --timeout: ping timeout\n"
3730 "\t --help: display this help\n");
3737 for (; optind < argc; optind++)
3738 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
3742 cYAML_print_tree(show_rc);
3745 cYAML_print_tree2file(stderr, err_rc);
3747 cYAML_free_tree(err_rc);
3748 cYAML_free_tree(show_rc);
3753 static int jt_discover(int argc, char **argv)
3755 struct cYAML *err_rc = NULL;
3756 struct cYAML *show_rc = NULL;
3760 const char *const short_options = "fh";
3761 const struct option long_options[] = {
3762 { .name = "force", .has_arg = no_argument, .val = 'f' },
3763 { .name = "help", .has_arg = no_argument, .val = 'h' },
3766 while ((opt = getopt_long(argc, argv, short_options,
3767 long_options, NULL)) != -1) {
3773 printf("discover nid[,nid,...]\n"
3774 "\t --force: force discovery\n"
3775 "\t --help: display this help\n");
3782 if (optind == argc) {
3783 printf("Missing nid argument\n");
3787 for (; optind < argc; optind++)
3788 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
3792 cYAML_print_tree(show_rc);
3795 cYAML_print_tree2file(stderr, err_rc);
3797 cYAML_free_tree(err_rc);
3798 cYAML_free_tree(show_rc);
3803 static int jt_add_udsp(int argc, char **argv)
3805 char *src = NULL, *dst = NULL, *rte = NULL;
3806 struct cYAML *err_rc = NULL;
3807 union lnet_udsp_action udsp_action;
3808 long int idx = -1, priority = -1;
3810 char *action_type = "pref";
3812 const char *const short_options = "s:d:r:p:i:";
3813 static const struct option long_options[] = {
3814 { .name = "src", .has_arg = required_argument, .val = 's' },
3815 { .name = "dst", .has_arg = required_argument, .val = 'd' },
3816 { .name = "rte", .has_arg = required_argument, .val = 'r' },
3817 { .name = "priority", .has_arg = required_argument, .val = 'p' },
3818 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3821 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
3825 while ((opt = getopt_long(argc, argv, short_options,
3826 long_options, NULL)) != -1) {
3838 rc = parse_long(optarg, &priority);
3839 if (rc != 0 || priority < 0) {
3840 printf("Invalid priority \"%s\"\n", optarg);
3843 action_type = "priority";
3844 udsp_action.udsp_priority = priority;
3847 rc = parse_long(optarg, &idx);
3848 if (rc != 0 || idx < 0) {
3849 printf("Invalid index \"%s\"\n", optarg);
3854 print_help(udsp_cmds, "udsp", "add");
3860 if (!(src || dst || rte)) {
3861 print_help(udsp_cmds, "udsp", "add");
3865 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
3868 if (rc != LUSTRE_CFG_RC_NO_ERR)
3869 cYAML_print_tree2file(stderr, err_rc);
3871 cYAML_free_tree(err_rc);
3876 static int jt_del_udsp(int argc, char **argv)
3878 struct cYAML *err_rc = NULL;
3883 const char *const short_options = "ai:";
3884 static const struct option long_options[] = {
3885 { .name = "all", .has_arg = no_argument, .val = 'a' },
3886 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3889 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
3893 while ((opt = getopt_long(argc, argv, short_options,
3894 long_options, NULL)) != -1) {
3900 rc = parse_long(optarg, &idx);
3901 if (rc != 0 || idx < -1) {
3902 printf("Invalid index \"%s\"\n", optarg);
3907 print_help(udsp_cmds, "udsp", "del");
3913 if (all && idx != -2) {
3914 printf("Cannot combine --all with --idx\n");
3918 } else if (idx == -2) {
3919 printf("Must specify --idx or --all\n");
3923 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
3924 if (rc != LUSTRE_CFG_RC_NO_ERR)
3925 cYAML_print_tree2file(stderr, err_rc);
3927 cYAML_free_tree(err_rc);
3932 int main(int argc, char **argv)
3935 struct cYAML *err_rc = NULL;
3937 rc = lustre_lnet_config_lib_init();
3939 cYAML_build_error(-1, -1, "lnetctl", "startup",
3940 "cannot register LNet device", &err_rc);
3941 cYAML_print_tree2file(stderr, err_rc);
3945 return cfs_parser(argc, argv, cmd_list);