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_router_gateways(yaml_emitter_t *output, const char *nw,
1138 const char *gw, int hops, int prio,
1141 char num[INT_STRING_LEN];
1145 yaml_mapping_start_event_initialize(&event, NULL,
1146 (yaml_char_t *)YAML_MAP_TAG, 1,
1147 YAML_BLOCK_MAPPING_STYLE);
1148 rc = yaml_emitter_emit(output, &event);
1153 yaml_scalar_event_initialize(&event, NULL,
1154 (yaml_char_t *)YAML_STR_TAG,
1155 (yaml_char_t *)"net",
1156 strlen("net"), 1, 0,
1157 YAML_PLAIN_SCALAR_STYLE);
1158 rc = yaml_emitter_emit(output, &event);
1162 yaml_scalar_event_initialize(&event, NULL,
1163 (yaml_char_t *)YAML_STR_TAG,
1166 YAML_PLAIN_SCALAR_STYLE);
1167 rc = yaml_emitter_emit(output, &event);
1173 yaml_scalar_event_initialize(&event, NULL,
1174 (yaml_char_t *)YAML_STR_TAG,
1175 (yaml_char_t *)"gateway",
1176 strlen("gateway"), 1, 0,
1177 YAML_PLAIN_SCALAR_STYLE);
1178 rc = yaml_emitter_emit(output, &event);
1182 yaml_scalar_event_initialize(&event, NULL,
1183 (yaml_char_t *)YAML_STR_TAG,
1186 YAML_PLAIN_SCALAR_STYLE);
1187 rc = yaml_emitter_emit(output, &event);
1193 yaml_scalar_event_initialize(&event, NULL,
1194 (yaml_char_t *)YAML_STR_TAG,
1195 (yaml_char_t *)"hop",
1196 strlen("hop"), 1, 0,
1197 YAML_PLAIN_SCALAR_STYLE);
1198 rc = yaml_emitter_emit(output, &event);
1202 snprintf(num, sizeof(num), "%d", hops);
1203 yaml_scalar_event_initialize(&event, NULL,
1204 (yaml_char_t *)YAML_INT_TAG,
1207 YAML_PLAIN_SCALAR_STYLE);
1208 rc = yaml_emitter_emit(output, &event);
1214 yaml_scalar_event_initialize(&event, NULL,
1215 (yaml_char_t *)YAML_STR_TAG,
1216 (yaml_char_t *)"priority",
1217 strlen("priority"), 1, 0,
1218 YAML_PLAIN_SCALAR_STYLE);
1219 rc = yaml_emitter_emit(output, &event);
1223 snprintf(num, sizeof(num), "%d", prio);
1224 yaml_scalar_event_initialize(&event, NULL,
1225 (yaml_char_t *)YAML_INT_TAG,
1228 YAML_PLAIN_SCALAR_STYLE);
1229 rc = yaml_emitter_emit(output, &event);
1235 yaml_scalar_event_initialize(&event, NULL,
1236 (yaml_char_t *)YAML_STR_TAG,
1237 (yaml_char_t *)"health_sensitivity",
1238 strlen("health_sensitivity"),
1240 YAML_PLAIN_SCALAR_STYLE);
1241 rc = yaml_emitter_emit(output, &event);
1245 snprintf(num, sizeof(num), "%d", sen);
1246 yaml_scalar_event_initialize(&event, NULL,
1247 (yaml_char_t *)YAML_INT_TAG,
1250 YAML_PLAIN_SCALAR_STYLE);
1251 rc = yaml_emitter_emit(output, &event);
1256 yaml_mapping_end_event_initialize(&event);
1257 rc = yaml_emitter_emit(output, &event);
1262 static int yaml_lnet_route(char *nw, char *gw, int hops, int prio, int sen,
1263 int version, int flags)
1265 struct nid_node head, *entry;
1266 struct nl_sock *sk = NULL;
1267 const char *msg = NULL;
1268 yaml_emitter_t output;
1269 yaml_parser_t reply;
1273 if (!(flags & NLM_F_DUMP) && (!nw || !gw)) {
1274 fprintf(stdout, "missing mandatory parameters:'%s'\n",
1275 (!nw && !gw) ? "net , gateway" :
1276 !nw ? "net" : "gateway");
1280 /* Create Netlink emitter to send request to kernel */
1281 sk = nl_socket_alloc();
1285 /* Setup parser to receive Netlink packets */
1286 rc = yaml_parser_initialize(&reply);
1292 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1294 msg = yaml_parser_get_reader_error(&reply);
1298 /* Create Netlink emitter to send request to kernel */
1299 rc = yaml_emitter_initialize(&output);
1301 msg = "failed to initialize emitter";
1305 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1306 version, LNET_CMD_ROUTES, flags);
1310 yaml_emitter_open(&output);
1311 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
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 yaml_scalar_event_initialize(&event, NULL,
1324 (yaml_char_t *)YAML_STR_TAG,
1325 (yaml_char_t *)"route",
1326 strlen("route"), 1, 0,
1327 YAML_PLAIN_SCALAR_STYLE);
1328 rc = yaml_emitter_emit(&output, &event);
1332 /* NLM_F_DUMP can have no arguments */
1334 NL_INIT_LIST_HEAD(&head.children);
1335 nl_init_list_head(&head.list);
1337 rc = lustre_lnet_parse_nid_range(&head, gw, &msg);
1339 lustre_lnet_free_list(&head);
1340 yaml_emitter_delete(&output);
1347 yaml_sequence_start_event_initialize(&event, NULL,
1348 (yaml_char_t *)YAML_SEQ_TAG,
1350 YAML_BLOCK_SEQUENCE_STYLE);
1351 rc = yaml_emitter_emit(&output, &event);
1355 if (!nl_list_empty(&head.children)) {
1356 nl_list_for_each_entry(entry, &head.children, list) {
1357 const char *nid = entry->nidstr;
1359 rc = yaml_lnet_router_gateways(&output, nw, nid,
1365 rc = yaml_lnet_router_gateways(&output, nw, NULL, hops,
1371 yaml_sequence_end_event_initialize(&event);
1372 rc = yaml_emitter_emit(&output, &event);
1376 yaml_scalar_event_initialize(&event, NULL,
1377 (yaml_char_t *)YAML_STR_TAG,
1380 YAML_PLAIN_SCALAR_STYLE);
1381 rc = yaml_emitter_emit(&output, &event);
1386 yaml_mapping_end_event_initialize(&event);
1387 rc = yaml_emitter_emit(&output, &event);
1391 yaml_document_end_event_initialize(&event, 0);
1392 rc = yaml_emitter_emit(&output, &event);
1396 rc = yaml_emitter_close(&output);
1399 yaml_emitter_log_error(&output, stderr);
1402 yaml_document_t errmsg;
1404 rc = yaml_parser_load(&reply, &errmsg);
1405 if (rc == 1 && (flags & NLM_F_DUMP)) {
1406 yaml_emitter_t debug;
1408 rc = yaml_emitter_initialize(&debug);
1410 yaml_emitter_set_indent(&debug,
1411 LNET_DEFAULT_INDENT);
1412 yaml_emitter_set_output_file(&debug,
1414 rc = yaml_emitter_dump(&debug, &errmsg);
1416 yaml_emitter_delete(&debug);
1418 msg = yaml_parser_get_reader_error(&reply);
1419 /* If we didn't find any routes just be silent */
1420 if (msg && strcmp(msg, "No routes found") == 0)
1423 yaml_document_delete(&errmsg);
1425 yaml_emitter_delete(&output);
1428 yaml_lnet_print_error(flags, "route", msg);
1431 yaml_parser_delete(&reply);
1434 return rc == 1 ? 0 : rc;
1437 static int jt_add_route(int argc, char **argv)
1439 char *network = NULL, *gateway = NULL;
1440 long int hop = -1, prio = -1, sen = -1;
1441 struct cYAML *err_rc = NULL;
1444 const char *const short_options = "n:g:c:p:";
1445 static const struct option long_options[] = {
1446 { .name = "net", .has_arg = required_argument, .val = 'n' },
1447 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1448 { .name = "hop", .has_arg = required_argument, .val = 'c' },
1449 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1450 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1451 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1455 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1459 while ((opt = getopt_long(argc, argv, short_options,
1460 long_options, NULL)) != -1) {
1469 rc = parse_long(optarg, &hop);
1477 rc = parse_long(optarg, &prio);
1485 rc = parse_long(optarg, &sen);
1494 print_help(route_cmds, "route", "add");
1500 rc = yaml_lnet_route(network, gateway, hop, prio, sen,
1501 LNET_GENL_VERSION, NLM_F_CREATE);
1503 if (rc == -EOPNOTSUPP)
1508 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1511 if (rc != LUSTRE_CFG_RC_NO_ERR)
1512 cYAML_print_tree2file(stderr, err_rc);
1514 cYAML_free_tree(err_rc);
1519 static int yaml_add_ni_tunables(yaml_emitter_t *output,
1520 struct lnet_ioctl_config_lnd_tunables *tunables,
1521 struct lnet_dlc_network_descr *nw_descr)
1523 char num[INT_STRING_LEN];
1527 if (tunables->lt_cmn.lct_peer_timeout < 0 &&
1528 tunables->lt_cmn.lct_peer_tx_credits <= 0 &&
1529 tunables->lt_cmn.lct_peer_rtr_credits <= 0 &&
1530 tunables->lt_cmn.lct_max_tx_credits <= 0)
1531 goto skip_general_settings;
1533 yaml_scalar_event_initialize(&event, NULL,
1534 (yaml_char_t *)YAML_STR_TAG,
1535 (yaml_char_t *)"tunables",
1536 strlen("tunables"), 1, 0,
1537 YAML_PLAIN_SCALAR_STYLE);
1538 rc = yaml_emitter_emit(output, &event);
1542 yaml_mapping_start_event_initialize(&event, NULL,
1543 (yaml_char_t *)YAML_MAP_TAG,
1544 1, YAML_ANY_MAPPING_STYLE);
1545 rc = yaml_emitter_emit(output, &event);
1549 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1550 yaml_scalar_event_initialize(&event, NULL,
1551 (yaml_char_t *)YAML_STR_TAG,
1552 (yaml_char_t *)"peer_timeout",
1553 strlen("peer_timeout"), 1, 0,
1554 YAML_PLAIN_SCALAR_STYLE);
1555 rc = yaml_emitter_emit(output, &event);
1559 snprintf(num, sizeof(num), "%u",
1560 tunables->lt_cmn.lct_peer_timeout);
1561 yaml_scalar_event_initialize(&event, NULL,
1562 (yaml_char_t *)YAML_INT_TAG,
1565 YAML_PLAIN_SCALAR_STYLE);
1566 rc = yaml_emitter_emit(output, &event);
1571 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1572 yaml_scalar_event_initialize(&event, NULL,
1573 (yaml_char_t *)YAML_STR_TAG,
1574 (yaml_char_t *)"peer_credits",
1575 strlen("peer_credits"), 1, 0,
1576 YAML_PLAIN_SCALAR_STYLE);
1577 rc = yaml_emitter_emit(output, &event);
1581 snprintf(num, sizeof(num), "%u",
1582 tunables->lt_cmn.lct_peer_tx_credits);
1583 yaml_scalar_event_initialize(&event, NULL,
1584 (yaml_char_t *)YAML_INT_TAG,
1587 YAML_PLAIN_SCALAR_STYLE);
1588 rc = yaml_emitter_emit(output, &event);
1593 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1594 yaml_scalar_event_initialize(&event, NULL,
1595 (yaml_char_t *)YAML_STR_TAG,
1596 (yaml_char_t *)"peer_buffer_credits",
1597 strlen("peer_buffer_credits"), 1, 0,
1598 YAML_PLAIN_SCALAR_STYLE);
1599 rc = yaml_emitter_emit(output, &event);
1603 snprintf(num, sizeof(num), "%u",
1604 tunables->lt_cmn.lct_peer_rtr_credits);
1605 yaml_scalar_event_initialize(&event, NULL,
1606 (yaml_char_t *)YAML_INT_TAG,
1609 YAML_PLAIN_SCALAR_STYLE);
1610 rc = yaml_emitter_emit(output, &event);
1615 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1616 yaml_scalar_event_initialize(&event, NULL,
1617 (yaml_char_t *)YAML_STR_TAG,
1618 (yaml_char_t *)"credits",
1619 strlen("credits"), 1, 0,
1620 YAML_PLAIN_SCALAR_STYLE);
1621 rc = yaml_emitter_emit(output, &event);
1625 snprintf(num, sizeof(num), "%u",
1626 tunables->lt_cmn.lct_max_tx_credits);
1627 yaml_scalar_event_initialize(&event, NULL,
1628 (yaml_char_t *)YAML_INT_TAG,
1631 YAML_PLAIN_SCALAR_STYLE);
1632 rc = yaml_emitter_emit(output, &event);
1637 yaml_mapping_end_event_initialize(&event);
1638 rc = yaml_emitter_emit(output, &event);
1642 skip_general_settings:
1643 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1645 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0 ||
1646 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0] ||
1648 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1649 yaml_scalar_event_initialize(&event, NULL,
1650 (yaml_char_t *)YAML_STR_TAG,
1651 (yaml_char_t *)"lnd tunables",
1652 strlen("lnd tunables"), 1, 0,
1653 YAML_PLAIN_SCALAR_STYLE);
1654 rc = yaml_emitter_emit(output, &event);
1658 yaml_mapping_start_event_initialize(&event, NULL,
1659 (yaml_char_t *)YAML_MAP_TAG,
1660 1, YAML_ANY_MAPPING_STYLE);
1661 rc = yaml_emitter_emit(output, &event);
1665 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1666 yaml_scalar_event_initialize(&event, NULL,
1667 (yaml_char_t *)YAML_STR_TAG,
1668 (yaml_char_t *)"auth_key",
1669 strlen("auth_key"), 1, 0,
1670 YAML_PLAIN_SCALAR_STYLE);
1671 rc = yaml_emitter_emit(output, &event);
1675 snprintf(num, sizeof(num), "%u",
1676 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1678 yaml_scalar_event_initialize(&event, NULL,
1679 (yaml_char_t *)YAML_INT_TAG,
1682 YAML_PLAIN_SCALAR_STYLE);
1683 rc = yaml_emitter_emit(output, &event);
1688 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0]) {
1689 char *tc = &tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0];
1691 yaml_scalar_event_initialize(&event, NULL,
1692 (yaml_char_t *)YAML_STR_TAG,
1693 (yaml_char_t *)"traffic_class",
1694 strlen("traffic_class"), 1, 0,
1695 YAML_PLAIN_SCALAR_STYLE);
1696 rc = yaml_emitter_emit(output, &event);
1700 yaml_scalar_event_initialize(&event, NULL,
1701 (yaml_char_t *)YAML_INT_TAG,
1704 YAML_PLAIN_SCALAR_STYLE);
1706 rc = yaml_emitter_emit(output, &event);
1711 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1712 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1715 yaml_scalar_event_initialize(&event, NULL,
1716 (yaml_char_t *)YAML_STR_TAG,
1717 (yaml_char_t *)"conns_per_peer",
1718 strlen("conns_per_peer"), 1, 0,
1719 YAML_PLAIN_SCALAR_STYLE);
1720 rc = yaml_emitter_emit(output, &event);
1724 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND)
1725 cpp = tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer;
1726 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND)
1727 cpp = tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer;
1728 snprintf(num, sizeof(num), "%u", cpp);
1730 yaml_scalar_event_initialize(&event, NULL,
1731 (yaml_char_t *)YAML_INT_TAG,
1734 YAML_PLAIN_SCALAR_STYLE);
1735 rc = yaml_emitter_emit(output, &event);
1740 yaml_mapping_end_event_initialize(&event);
1741 rc = yaml_emitter_emit(output, &event);
1747 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1748 struct lnet_dlc_network_descr *nw_descr,
1749 struct lnet_ioctl_config_lnd_tunables *tunables,
1750 struct cfs_expr_list *global_cpts,
1751 int version, int flags)
1753 struct lnet_dlc_intf_descr *intf;
1754 struct nl_sock *sk = NULL;
1755 const char *msg = NULL;
1756 yaml_emitter_t output;
1757 yaml_parser_t reply;
1761 if (!(flags & NLM_F_DUMP) && !ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1762 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1763 (!nw_descr) ? "network , interface" :
1764 (nw_descr->nw_id == 0) ? "network" : "interface");
1768 if ((flags == NLM_F_CREATE) && !ip2net && list_empty(&nw_descr->nw_intflist)) {
1769 fprintf(stdout, "creating a local NI needs at least one interface");
1773 /* Create Netlink emitter to send request to kernel */
1774 sk = nl_socket_alloc();
1778 /* Setup parser to receive Netlink packets */
1779 rc = yaml_parser_initialize(&reply);
1785 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1787 msg = yaml_parser_get_reader_error(&reply);
1791 /* Create Netlink emitter to send request to kernel */
1792 rc = yaml_emitter_initialize(&output);
1794 msg = "failed to initialize emitter";
1798 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1799 version, LNET_CMD_NETS, flags);
1803 yaml_emitter_open(&output);
1804 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1805 rc = yaml_emitter_emit(&output, &event);
1809 yaml_mapping_start_event_initialize(&event, NULL,
1810 (yaml_char_t *)YAML_MAP_TAG,
1811 1, YAML_ANY_MAPPING_STYLE);
1812 rc = yaml_emitter_emit(&output, &event);
1816 yaml_scalar_event_initialize(&event, NULL,
1817 (yaml_char_t *)YAML_STR_TAG,
1818 (yaml_char_t *)"net",
1819 strlen("net"), 1, 0,
1820 YAML_PLAIN_SCALAR_STYLE);
1821 rc = yaml_emitter_emit(&output, &event);
1825 if (net_id || ip2net) {
1826 char *key = net_id ? "net type" : "ip2net";
1827 char *value = net_id ? net_id : ip2net;
1829 yaml_sequence_start_event_initialize(&event, NULL,
1830 (yaml_char_t *)YAML_SEQ_TAG,
1831 1, YAML_ANY_SEQUENCE_STYLE);
1832 rc = yaml_emitter_emit(&output, &event);
1836 yaml_mapping_start_event_initialize(&event, NULL,
1837 (yaml_char_t *)YAML_MAP_TAG,
1838 1, YAML_ANY_MAPPING_STYLE);
1839 rc = yaml_emitter_emit(&output, &event);
1843 yaml_scalar_event_initialize(&event, NULL,
1844 (yaml_char_t *)YAML_STR_TAG,
1847 1, 0, YAML_PLAIN_SCALAR_STYLE);
1848 rc = yaml_emitter_emit(&output, &event);
1852 yaml_scalar_event_initialize(&event, NULL,
1853 (yaml_char_t *)YAML_STR_TAG,
1854 (yaml_char_t *)value,
1855 strlen(value), 1, 0,
1856 YAML_PLAIN_SCALAR_STYLE);
1857 rc = yaml_emitter_emit(&output, &event);
1861 yaml_scalar_event_initialize(&event, NULL,
1862 (yaml_char_t *)YAML_STR_TAG,
1865 YAML_PLAIN_SCALAR_STYLE);
1866 rc = yaml_emitter_emit(&output, &event);
1873 if (!nw_descr || list_empty(&nw_descr->nw_intflist))
1876 yaml_scalar_event_initialize(&event, NULL,
1877 (yaml_char_t *)YAML_STR_TAG,
1878 (yaml_char_t *)"local NI(s)",
1879 strlen("local NI(s)"), 1, 0,
1880 YAML_PLAIN_SCALAR_STYLE);
1881 rc = yaml_emitter_emit(&output, &event);
1885 yaml_sequence_start_event_initialize(&event, NULL,
1886 (yaml_char_t *)YAML_SEQ_TAG,
1887 1, YAML_ANY_SEQUENCE_STYLE);
1888 rc = yaml_emitter_emit(&output, &event);
1892 list_for_each_entry(intf, &nw_descr->nw_intflist,
1894 yaml_mapping_start_event_initialize(&event, NULL,
1895 (yaml_char_t *)YAML_MAP_TAG,
1896 1, YAML_ANY_MAPPING_STYLE);
1897 rc = yaml_emitter_emit(&output, &event);
1901 yaml_scalar_event_initialize(&event, NULL,
1902 (yaml_char_t *)YAML_STR_TAG,
1903 (yaml_char_t *)"interfaces",
1904 strlen("interfaces"), 1, 0,
1905 YAML_PLAIN_SCALAR_STYLE);
1906 rc = yaml_emitter_emit(&output, &event);
1910 yaml_mapping_start_event_initialize(&event, NULL,
1911 (yaml_char_t *)YAML_MAP_TAG,
1912 1, YAML_ANY_MAPPING_STYLE);
1913 rc = yaml_emitter_emit(&output, &event);
1917 yaml_scalar_event_initialize(&event, NULL,
1918 (yaml_char_t *)YAML_STR_TAG,
1921 YAML_PLAIN_SCALAR_STYLE);
1922 rc = yaml_emitter_emit(&output, &event);
1926 yaml_scalar_event_initialize(&event, NULL,
1927 (yaml_char_t *)YAML_STR_TAG,
1928 (yaml_char_t *)intf->intf_name,
1929 strlen(intf->intf_name), 1, 0,
1930 YAML_PLAIN_SCALAR_STYLE);
1931 rc = yaml_emitter_emit(&output, &event);
1935 yaml_mapping_end_event_initialize(&event);
1936 rc = yaml_emitter_emit(&output, &event);
1941 rc = yaml_add_ni_tunables(&output, tunables, nw_descr);
1950 yaml_scalar_event_initialize(&event, NULL,
1951 (yaml_char_t *)YAML_STR_TAG,
1952 (yaml_char_t *)"CPT",
1953 strlen("CPT"), 1, 0,
1954 YAML_PLAIN_SCALAR_STYLE);
1955 rc = yaml_emitter_emit(&output, &event);
1959 yaml_sequence_start_event_initialize(&event, NULL,
1960 (yaml_char_t *)YAML_SEQ_TAG,
1962 YAML_FLOW_SEQUENCE_STYLE);
1963 rc = yaml_emitter_emit(&output, &event);
1967 count = cfs_expr_list_values(global_cpts,
1968 LNET_MAX_SHOW_NUM_CPT,
1970 for (i = 0; i < count; i++) {
1971 char core[INT_STRING_LEN];
1973 snprintf(core, sizeof(core), "%u", cpt_array[i]);
1974 yaml_scalar_event_initialize(&event, NULL,
1975 (yaml_char_t *)YAML_STR_TAG,
1976 (yaml_char_t *)core,
1978 YAML_PLAIN_SCALAR_STYLE);
1979 rc = yaml_emitter_emit(&output, &event);
1984 yaml_sequence_end_event_initialize(&event);
1985 rc = yaml_emitter_emit(&output, &event);
1989 cfs_expr_list_free(global_cpts);
1993 yaml_mapping_end_event_initialize(&event);
1994 rc = yaml_emitter_emit(&output, &event);
1999 yaml_sequence_end_event_initialize(&event);
2000 rc = yaml_emitter_emit(&output, &event);
2004 yaml_mapping_end_event_initialize(&event);
2005 rc = yaml_emitter_emit(&output, &event);
2009 yaml_sequence_end_event_initialize(&event);
2010 rc = yaml_emitter_emit(&output, &event);
2014 yaml_mapping_end_event_initialize(&event);
2015 rc = yaml_emitter_emit(&output, &event);
2019 yaml_document_end_event_initialize(&event, 0);
2020 rc = yaml_emitter_emit(&output, &event);
2024 rc = yaml_emitter_close(&output);
2027 yaml_emitter_log_error(&output, stderr);
2030 yaml_document_t errmsg;
2032 rc = yaml_parser_load(&reply, &errmsg);
2033 if (rc == 1 && (flags & NLM_F_DUMP)) {
2034 yaml_emitter_t debug;
2036 rc = yaml_emitter_initialize(&debug);
2038 yaml_emitter_set_indent(&debug,
2039 LNET_DEFAULT_INDENT);
2040 yaml_emitter_set_output_file(&debug, stdout);
2041 rc = yaml_emitter_dump(&debug, &errmsg);
2043 yaml_emitter_delete(&debug);
2045 msg = yaml_parser_get_reader_error(&reply);
2047 yaml_document_delete(&errmsg);
2049 yaml_emitter_delete(&output);
2052 yaml_lnet_print_error(flags, "net", msg);
2055 yaml_parser_delete(&reply);
2058 return rc == 1 ? 0 : rc;
2061 static int jt_add_ni(int argc, char **argv)
2063 char *ip2net = NULL;
2064 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
2065 char *traffic_class = NULL;
2066 struct cYAML *err_rc = NULL;
2067 int rc, opt, cpt_rc = -1;
2068 struct lnet_dlc_network_descr nw_descr;
2069 struct cfs_expr_list *global_cpts = NULL;
2070 struct lnet_ioctl_config_lnd_tunables tunables;
2072 bool skip_mr_route_setup = false;
2073 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:T:";
2074 static const struct option long_options[] = {
2075 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
2076 { .name = "peer-buffer-credits",
2077 .has_arg = required_argument, .val = 'b' },
2078 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
2079 { .name = "if", .has_arg = required_argument, .val = 'i' },
2080 { .name = "skip-mr-route-setup",
2081 .has_arg = no_argument, .val = 'k' },
2082 { .name = "conns-per-peer",
2083 .has_arg = required_argument, .val = 'm' },
2084 { .name = "net", .has_arg = required_argument, .val = 'n' },
2085 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
2086 { .name = "credits", .has_arg = required_argument, .val = 'r' },
2087 { .name = "cpt", .has_arg = required_argument, .val = 's' },
2088 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
2089 { .name = "traffic-class", .has_arg = required_argument, .val = 'T' },
2091 char *net_id = NULL;
2093 memset(&tunables, 0, sizeof(tunables));
2094 lustre_lnet_init_nw_descr(&nw_descr);
2096 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
2100 while ((opt = getopt_long(argc, argv, short_options,
2101 long_options, NULL)) != -1) {
2104 rc = parse_long(optarg, &auth_key);
2112 rc = parse_long(optarg, &pbc);
2120 rc = parse_long(optarg, &pc);
2128 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2130 cYAML_build_error(-1, -1, "ni", "add",
2131 "bad interface list",
2137 skip_mr_route_setup = true;
2140 rc = parse_long(optarg, &cpp);
2149 nw_descr.nw_id = libcfs_str2net(optarg);
2156 rc = parse_long(optarg, &cre);
2164 cpt_rc = cfs_expr_list_parse(optarg,
2166 UINT_MAX, &global_cpts);
2169 rc = parse_long(optarg, &pto);
2177 traffic_class = optarg;
2178 if (strlen(traffic_class) == 0 ||
2179 strlen(traffic_class) >= LNET_MAX_STR_LEN) {
2180 cYAML_build_error(-1, -1, "ni", "add",
2181 "Invalid traffic-class argument",
2183 rc = LUSTRE_CFG_RC_BAD_PARAM;
2188 print_help(net_cmds, "net", "add");
2194 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
2195 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
2199 if (traffic_class && LNET_NETTYP(nw_descr.nw_id) == KFILND &&
2200 strlen(traffic_class) < LNET_MAX_STR_LEN) {
2201 strcpy(&tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0],
2207 if (LNET_NETTYP(nw_descr.nw_id) == SOCKLND && (cpp > -1)) {
2208 tunables.lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
2210 } else if (LNET_NETTYP(nw_descr.nw_id) == O2IBLND && (cpp > -1)) {
2211 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
2215 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
2216 tunables.lt_cmn.lct_peer_timeout = pto;
2217 tunables.lt_cmn.lct_peer_tx_credits = pc;
2218 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
2219 tunables.lt_cmn.lct_max_tx_credits = cre;
2223 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
2224 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
2226 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
2227 found ? &tunables : NULL,
2228 (cpt_rc == 0) ? global_cpts : NULL,
2229 LNET_GENL_VERSION, NLM_F_CREATE);
2231 if (rc == -EOPNOTSUPP)
2233 if (global_cpts != NULL)
2234 cfs_expr_list_free(global_cpts);
2235 if (rc == 0 && !skip_mr_route_setup)
2236 rc = lustre_lnet_setup_mrrouting(&err_rc);
2240 rc = lustre_lnet_config_ni(&nw_descr,
2241 (cpt_rc == 0) ? global_cpts: NULL,
2242 ip2net, (found) ? &tunables : NULL,
2245 if (global_cpts != NULL)
2246 cfs_expr_list_free(global_cpts);
2249 if (rc != LUSTRE_CFG_RC_NO_ERR)
2250 cYAML_print_tree2file(stderr, err_rc);
2252 cYAML_free_tree(err_rc);
2254 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
2256 rc = lustre_lnet_setup_mrrouting(&err_rc);
2258 if (rc != LUSTRE_CFG_RC_NO_ERR)
2259 cYAML_print_tree2file(stderr, err_rc);
2261 cYAML_free_tree(err_rc);
2267 static int jt_del_route(int argc, char **argv)
2269 char *network = NULL, *gateway = NULL;
2270 struct cYAML *err_rc = NULL;
2272 const char *const short_options = "n:g:";
2273 static const struct option long_options[] = {
2274 { .name = "net", .has_arg = required_argument, .val = 'n' },
2275 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2279 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
2283 while ((opt = getopt_long(argc, argv, short_options,
2284 long_options, NULL)) != -1) {
2293 print_help(route_cmds, "route", "del");
2299 rc = yaml_lnet_route(network, gateway, -1, -1, -1, LNET_GENL_VERSION,
2302 if (rc == -EOPNOTSUPP)
2307 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
2309 if (rc != LUSTRE_CFG_RC_NO_ERR)
2310 cYAML_print_tree2file(stderr, err_rc);
2312 cYAML_free_tree(err_rc);
2317 static int jt_del_ni(int argc, char **argv)
2319 struct cYAML *err_rc = NULL;
2321 struct lnet_dlc_network_descr nw_descr;
2322 const char *const short_options = "n:i:";
2323 static const struct option long_options[] = {
2324 { .name = "net", .has_arg = required_argument, .val = 'n' },
2325 { .name = "if", .has_arg = required_argument, .val = 'i' },
2327 char *net_id = NULL;
2329 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
2333 lustre_lnet_init_nw_descr(&nw_descr);
2335 while ((opt = getopt_long(argc, argv, short_options,
2336 long_options, NULL)) != -1) {
2339 nw_descr.nw_id = libcfs_str2net(optarg);
2343 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2345 cYAML_build_error(-1, -1, "ni", "add",
2346 "bad interface list",
2352 print_help(net_cmds, "net", "del");
2358 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, NULL,
2359 LNET_GENL_VERSION, 0);
2361 if (rc != -EOPNOTSUPP)
2365 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
2367 if (rc != LUSTRE_CFG_RC_NO_ERR)
2368 cYAML_print_tree2file(stderr, err_rc);
2370 cYAML_free_tree(err_rc);
2375 static int jt_show_route(int argc, char **argv)
2377 char *network = NULL, *gateway = NULL;
2378 long int hop = -1, prio = -1;
2379 int detail = 0, rc, opt;
2380 struct cYAML *err_rc = NULL, *show_rc = NULL;
2381 const char *const short_options = "c:n:g:p:v";
2382 static const struct option long_options[] = {
2383 { .name = "net", .has_arg = required_argument, .val = 'n' },
2384 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2385 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
2386 { .name = "hop", .has_arg = required_argument, .val = 'c' },
2387 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2388 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
2392 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
2396 while ((opt = getopt_long(argc, argv, short_options,
2397 long_options, NULL)) != -1) {
2406 rc = parse_long(optarg, &hop);
2414 rc = parse_long(optarg, &prio);
2425 print_help(route_cmds, "route", "show");
2431 rc = yaml_lnet_route(network, gateway, hop, prio, -1,
2432 detail, NLM_F_DUMP);
2434 if (rc == -EOPNOTSUPP)
2439 rc = lustre_lnet_show_route(network, gateway, hop, prio,
2441 &show_rc, &err_rc, false);
2443 if (rc != LUSTRE_CFG_RC_NO_ERR)
2444 cYAML_print_tree2file(stderr, err_rc);
2446 cYAML_print_tree(show_rc);
2448 cYAML_free_tree(err_rc);
2449 cYAML_free_tree(show_rc);
2454 static int set_value_helper(int argc, char **argv,
2455 int (*cb)(int, bool, char*, int, int, struct cYAML**))
2458 long int healthv = -1;
2460 long int state = -1;
2462 struct cYAML *err_rc = NULL;
2463 const char *const short_options = "t:n:s:a";
2464 static const struct option long_options[] = {
2465 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2466 { .name = "health", .has_arg = required_argument, .val = 't' },
2467 { .name = "state", .has_arg = required_argument, .val = 's' },
2468 { .name = "all", .has_arg = no_argument, .val = 'a' },
2472 while ((opt = getopt_long(argc, argv, short_options,
2473 long_options, NULL)) != -1) {
2479 if (parse_long(optarg, &healthv) != 0)
2483 if (parse_long(optarg, &state) != 0)
2494 rc = cb(healthv, all, nid, state, -1, &err_rc);
2495 if (rc != LUSTRE_CFG_RC_NO_ERR)
2496 cYAML_print_tree2file(stderr, err_rc);
2498 cYAML_free_tree(err_rc);
2503 static int jt_set_ni_value(int argc, char **argv)
2506 long int healthv = -1, cpp = -1;
2509 struct cYAML *err_rc = NULL;
2511 const char *const short_options = "a:m:n:t:";
2512 static const struct option long_options[] = {
2513 { .name = "all", .has_arg = no_argument, .val = 'a' },
2514 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2515 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2516 { .name = "health", .has_arg = required_argument, .val = 't' },
2519 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2523 while ((opt = getopt_long(argc, argv, short_options,
2524 long_options, NULL)) != -1) {
2530 rc = parse_long(optarg, &cpp);
2541 if (parse_long(optarg, &healthv) != 0) {
2553 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2556 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2559 if (rc != LUSTRE_CFG_RC_NO_ERR)
2560 cYAML_print_tree2file(stderr, err_rc);
2562 cYAML_free_tree(err_rc);
2567 static int yaml_lnet_peer_display(yaml_parser_t *reply, bool list_only)
2569 yaml_emitter_t debug;
2572 rc = yaml_emitter_initialize(&debug);
2576 yaml_emitter_set_indent(&debug, 6);
2577 yaml_emitter_set_output_file(&debug, stdout);
2586 rc = yaml_parser_parse(reply, &event);
2588 goto report_reply_error;
2590 if (event.type != YAML_SCALAR_EVENT)
2593 value = (char *)event.data.scalar.value;
2594 if (strcmp(value, "peer") == 0) {
2595 yaml_event_delete(&event);
2597 yaml_scalar_event_initialize(&event, NULL,
2598 (yaml_char_t *)YAML_STR_TAG,
2599 (yaml_char_t *)"peer list",
2600 strlen("peer list"),
2602 YAML_PLAIN_SCALAR_STYLE);
2603 } else if (strcmp(value, "primary nid") == 0) {
2604 yaml_event_delete(&event);
2606 yaml_scalar_event_initialize(&event, NULL,
2607 (yaml_char_t *)YAML_STR_TAG,
2608 (yaml_char_t *)"nid",
2611 YAML_PLAIN_SCALAR_STYLE);
2612 rc = yaml_emitter_emit(&debug, &event);
2616 /* Now print NID address */
2617 rc = yaml_parser_parse(reply, &event);
2619 goto report_reply_error;
2621 rc = yaml_emitter_emit(&debug, &event);
2626 while (event.type != YAML_MAPPING_END_EVENT) {
2627 rc = yaml_parser_parse(reply, &event);
2629 goto report_reply_error;
2632 /* we can have map end, seq end, map end or
2633 * just map end event. If we see seq end event
2634 * then skip to next mapping end event
2636 rc = yaml_parser_parse(reply, &event);
2638 goto report_reply_error;
2640 if (event.type == YAML_SEQUENCE_END_EVENT) {
2641 yaml_event_delete(&event);
2643 rc = yaml_parser_parse(reply, &event);
2645 goto report_reply_error;
2649 rc = yaml_emitter_emit(&debug, &event);
2653 done = (event.type == YAML_DOCUMENT_END_EVENT);
2656 yaml_document_t errmsg;
2658 rc = yaml_parser_load(reply, &errmsg);
2660 rc = yaml_emitter_dump(&debug, &errmsg);
2661 yaml_document_delete(&errmsg);
2665 yaml_emitter_log_error(&debug, stderr);
2667 yaml_emitter_delete(&debug);
2672 static int yaml_lnet_peer(char *prim_nid, char *nidstr, bool disable_mr,
2673 int health_value, int state, bool list_only,
2674 int version, int flags)
2676 struct nl_sock *sk = NULL;
2677 const char *msg = NULL;
2678 yaml_emitter_t output;
2679 yaml_parser_t reply;
2683 /* Create Netlink emitter to send request to kernel */
2684 sk = nl_socket_alloc();
2688 /* Setup parser to receive Netlink packets */
2689 rc = yaml_parser_initialize(&reply);
2695 rc = yaml_parser_set_input_netlink(&reply, sk, false);
2697 msg = yaml_parser_get_reader_error(&reply);
2701 /* Create Netlink emitter to send request to kernel */
2702 rc = yaml_emitter_initialize(&output);
2704 msg = "failed to initialize emitter";
2708 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
2709 version, LNET_CMD_PEERS, flags);
2713 yaml_emitter_open(&output);
2714 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
2715 rc = yaml_emitter_emit(&output, &event);
2719 yaml_mapping_start_event_initialize(&event, NULL,
2720 (yaml_char_t *)YAML_MAP_TAG,
2721 1, YAML_ANY_MAPPING_STYLE);
2722 rc = yaml_emitter_emit(&output, &event);
2726 yaml_scalar_event_initialize(&event, NULL,
2727 (yaml_char_t *)YAML_STR_TAG,
2728 (yaml_char_t *)"peer",
2729 strlen("peer"), 1, 0,
2730 YAML_PLAIN_SCALAR_STYLE);
2731 rc = yaml_emitter_emit(&output, &event);
2736 yaml_sequence_start_event_initialize(&event, NULL,
2737 (yaml_char_t *)YAML_SEQ_TAG,
2739 YAML_BLOCK_SEQUENCE_STYLE);
2740 rc = yaml_emitter_emit(&output, &event);
2744 yaml_mapping_start_event_initialize(&event, NULL,
2745 (yaml_char_t *)YAML_MAP_TAG,
2747 YAML_BLOCK_MAPPING_STYLE);
2748 rc = yaml_emitter_emit(&output, &event);
2752 yaml_scalar_event_initialize(&event, NULL,
2753 (yaml_char_t *)YAML_STR_TAG,
2754 (yaml_char_t *)"primary nid",
2755 strlen("primary nid"), 1, 0,
2756 YAML_PLAIN_SCALAR_STYLE);
2757 rc = yaml_emitter_emit(&output, &event);
2761 yaml_scalar_event_initialize(&event, NULL,
2762 (yaml_char_t *)YAML_STR_TAG,
2763 (yaml_char_t *)prim_nid,
2764 strlen(prim_nid), 1, 0,
2765 YAML_PLAIN_SCALAR_STYLE);
2766 rc = yaml_emitter_emit(&output, &event);
2771 yaml_scalar_event_initialize(&event, NULL,
2772 (yaml_char_t *)YAML_STR_TAG,
2773 (yaml_char_t *)"Multi-Rail",
2774 strlen("Multi-Rail"), 1, 0,
2775 YAML_PLAIN_SCALAR_STYLE);
2776 rc = yaml_emitter_emit(&output, &event);
2780 yaml_scalar_event_initialize(&event, NULL,
2781 (yaml_char_t *)YAML_BOOL_TAG,
2782 (yaml_char_t *)"False",
2783 strlen("False"), 1, 0,
2784 YAML_PLAIN_SCALAR_STYLE);
2785 rc = yaml_emitter_emit(&output, &event);
2791 char peer_state[INT_STRING_LEN];
2793 yaml_scalar_event_initialize(&event, NULL,
2794 (yaml_char_t *)YAML_STR_TAG,
2795 (yaml_char_t *)"peer state",
2796 strlen("peer state"), 1, 0,
2797 YAML_PLAIN_SCALAR_STYLE);
2798 rc = yaml_emitter_emit(&output, &event);
2802 snprintf(peer_state, sizeof(peer_state), "%d", state);
2803 yaml_scalar_event_initialize(&event, NULL,
2804 (yaml_char_t *)YAML_INT_TAG,
2805 (yaml_char_t *)peer_state,
2806 strlen(peer_state), 1, 0,
2807 YAML_PLAIN_SCALAR_STYLE);
2808 rc = yaml_emitter_emit(&output, &event);
2813 if (!nidstr && health_value == -1)
2816 yaml_scalar_event_initialize(&event, NULL,
2817 (yaml_char_t *)YAML_STR_TAG,
2818 (yaml_char_t *)"peer ni",
2819 strlen("peer ni"), 1, 0,
2820 YAML_PLAIN_SCALAR_STYLE);
2821 rc = yaml_emitter_emit(&output, &event);
2825 yaml_sequence_start_event_initialize(&event, NULL,
2826 (yaml_char_t *)YAML_SEQ_TAG,
2827 1, YAML_BLOCK_SEQUENCE_STYLE);
2828 rc = yaml_emitter_emit(&output, &event);
2833 struct nid_node head, *entry;
2836 /* If we have LNET_ANY_NID and its NLM_F_REPLACE we
2837 * treat it as the all flag case for lnetctl peer set
2839 if (strcmp(nidstr, "<?>") == 0) {
2840 yaml_mapping_start_event_initialize(&event, NULL,
2841 (yaml_char_t *)YAML_MAP_TAG,
2842 1, YAML_BLOCK_MAPPING_STYLE);
2843 rc = yaml_emitter_emit(&output, &event);
2847 yaml_scalar_event_initialize(&event, NULL,
2848 (yaml_char_t *)YAML_STR_TAG,
2849 (yaml_char_t *)"nid",
2850 strlen("nid"), 1, 0,
2851 YAML_PLAIN_SCALAR_STYLE);
2852 rc = yaml_emitter_emit(&output, &event);
2856 yaml_scalar_event_initialize(&event, NULL,
2857 (yaml_char_t *)YAML_STR_TAG,
2858 (yaml_char_t *)nidstr,
2859 strlen(nidstr), 1, 0,
2860 YAML_PLAIN_SCALAR_STYLE);
2861 rc = yaml_emitter_emit(&output, &event);
2865 yaml_mapping_end_event_initialize(&event);
2866 rc = yaml_emitter_emit(&output, &event);
2873 NL_INIT_LIST_HEAD(&head.children);
2874 nl_init_list_head(&head.list);
2875 rc = lustre_lnet_parse_nid_range(&head, nidstr, &msg);
2877 fprintf(stdout, "can't parse nidrange: \"%s\"\n", nidstr);
2878 lustre_lnet_free_list(&head);
2879 yaml_emitter_delete(&output);
2885 if (nl_list_empty(&head.children)) {
2886 lustre_lnet_free_list(&head);
2887 yaml_emitter_delete(&output);
2888 msg = "Unable to parse nidlist: did not expand to any nids";
2893 rc = 1; /* one means its working */
2895 nl_list_for_each_entry(entry, &head.children, list) {
2896 char *nid = entry->nidstr;
2898 if (count++ > LNET_MAX_NIDS_PER_PEER) {
2899 lustre_lnet_free_list(&head);
2900 yaml_emitter_delete(&output);
2901 msg = "Unable to parse nidlist: specifies more NIDs than allowed";
2907 yaml_mapping_start_event_initialize(&event, NULL,
2908 (yaml_char_t *)YAML_MAP_TAG,
2909 1, YAML_BLOCK_MAPPING_STYLE);
2910 rc = yaml_emitter_emit(&output, &event);
2914 yaml_scalar_event_initialize(&event, NULL,
2915 (yaml_char_t *)YAML_STR_TAG,
2916 (yaml_char_t *)"nid",
2917 strlen("nid"), 1, 0,
2918 YAML_PLAIN_SCALAR_STYLE);
2919 rc = yaml_emitter_emit(&output, &event);
2923 yaml_scalar_event_initialize(&event, NULL,
2924 (yaml_char_t *)YAML_STR_TAG,
2927 YAML_PLAIN_SCALAR_STYLE);
2928 rc = yaml_emitter_emit(&output, &event);
2932 yaml_mapping_end_event_initialize(&event);
2933 rc = yaml_emitter_emit(&output, &event);
2937 lustre_lnet_free_list(&head);
2940 if (health_value >= 0) {
2941 char health[INT_STRING_LEN];
2943 /* Create the mapping for 'health stats'. The value field for
2944 * the mapping is not provided so its treated as a empty string.
2946 yaml_mapping_start_event_initialize(&event, NULL,
2947 (yaml_char_t *)YAML_MAP_TAG,
2948 1, YAML_BLOCK_MAPPING_STYLE);
2949 rc = yaml_emitter_emit(&output, &event);
2953 yaml_scalar_event_initialize(&event, NULL,
2954 (yaml_char_t *)YAML_STR_TAG,
2955 (yaml_char_t *)"health stats",
2956 strlen("health stats"), 1, 0,
2957 YAML_PLAIN_SCALAR_STYLE);
2958 rc = yaml_emitter_emit(&output, &event);
2962 /* Setup all mappings for data related to the 'health stats' */
2963 yaml_mapping_start_event_initialize(&event, NULL,
2964 (yaml_char_t *)YAML_MAP_TAG,
2965 1, YAML_BLOCK_MAPPING_STYLE);
2966 rc = yaml_emitter_emit(&output, &event);
2970 yaml_scalar_event_initialize(&event, NULL,
2971 (yaml_char_t *)YAML_STR_TAG,
2972 (yaml_char_t *)"health value",
2973 strlen("health value"), 1, 0,
2974 YAML_PLAIN_SCALAR_STYLE);
2975 rc = yaml_emitter_emit(&output, &event);
2979 snprintf(health, sizeof(health), "%d", health_value);
2980 yaml_scalar_event_initialize(&event, NULL,
2981 (yaml_char_t *)YAML_INT_TAG,
2982 (yaml_char_t *)health,
2983 strlen(health), 1, 0,
2984 YAML_PLAIN_SCALAR_STYLE);
2985 rc = yaml_emitter_emit(&output, &event);
2989 yaml_mapping_end_event_initialize(&event);
2990 rc = yaml_emitter_emit(&output, &event);
2994 yaml_mapping_end_event_initialize(&event);
2995 rc = yaml_emitter_emit(&output, &event);
3000 yaml_sequence_end_event_initialize(&event);
3001 rc = yaml_emitter_emit(&output, &event);
3005 yaml_mapping_end_event_initialize(&event);
3006 rc = yaml_emitter_emit(&output, &event);
3010 yaml_sequence_end_event_initialize(&event);
3011 rc = yaml_emitter_emit(&output, &event);
3015 yaml_scalar_event_initialize(&event, NULL,
3016 (yaml_char_t *)YAML_STR_TAG,
3019 YAML_PLAIN_SCALAR_STYLE);
3020 rc = yaml_emitter_emit(&output, &event);
3025 yaml_mapping_end_event_initialize(&event);
3026 rc = yaml_emitter_emit(&output, &event);
3030 yaml_document_end_event_initialize(&event, 0);
3031 rc = yaml_emitter_emit(&output, &event);
3035 rc = yaml_emitter_close(&output);
3038 yaml_emitter_log_error(&output, stderr);
3041 rc = yaml_lnet_peer_display(&reply, list_only);
3043 msg = yaml_parser_get_reader_error(&reply);
3044 /* If we didn't find any peers just be silent */
3045 if (msg && strcmp(msg, "No peers found") == 0)
3050 yaml_emitter_delete(&output);
3053 yaml_lnet_print_error(flags, "peer", msg);
3056 yaml_parser_delete(&reply);
3059 return rc == 1 ? 0 : rc;
3062 int yaml_lnet_config_peer_ni_healthv(int healthv, bool all, char *lpni_nid,
3063 int state, int seq_no, struct cYAML **err_rc)
3067 rc = yaml_lnet_peer(lpni_nid ? lpni_nid : "<?>", all ? "<?>" : NULL,
3068 false, healthv, state, false, LNET_GENL_VERSION,
3071 if (rc == -EOPNOTSUPP)
3077 rc = lustre_lnet_config_peer_ni_healthv(healthv, all, lpni_nid,
3080 rc = lustre_lnet_set_peer_state(state, lpni_nid, -1, err_rc);
3081 if (rc != LUSTRE_CFG_RC_NO_ERR)
3082 cYAML_print_tree2file(stderr, *err_rc);
3084 cYAML_free_tree(*err_rc);
3089 static int jt_set_peer_ni_value(int argc, char **argv)
3091 int rc = check_cmd(peer_cmds, "peer", "set", 0, argc, argv);
3096 return set_value_helper(argc, argv, yaml_lnet_config_peer_ni_healthv);
3099 static int jt_show_recovery(int argc, char **argv)
3102 struct cYAML *err_rc = NULL, *show_rc = NULL;
3103 const char *const short_options = "lp";
3104 static const struct option long_options[] = {
3105 { .name = "local", .has_arg = no_argument, .val = 'l' },
3106 { .name = "peer", .has_arg = no_argument, .val = 'p' },
3109 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
3113 while ((opt = getopt_long(argc, argv, short_options,
3114 long_options, NULL)) != -1) {
3117 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
3120 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
3127 if (rc != LUSTRE_CFG_RC_NO_ERR)
3128 cYAML_print_tree2file(stderr, err_rc);
3130 cYAML_print_tree(show_rc);
3132 cYAML_free_tree(err_rc);
3133 cYAML_free_tree(show_rc);
3138 static int jt_show_peer_debug_info(int argc, char **argv)
3141 struct cYAML *err_rc = NULL;
3142 char *peer_nid = optarg;
3143 const char *const short_opts = "k";
3144 const struct option long_opts[] = {
3145 { .name = "nid", .has_arg = required_argument, .val = 'k' },
3148 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
3153 while ((opt = getopt_long(argc, argv, short_opts,
3154 long_opts, NULL)) != -1) {
3164 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
3166 if (rc != LUSTRE_CFG_RC_NO_ERR)
3167 cYAML_print_tree2file(stderr, err_rc);
3169 cYAML_free_tree(err_rc);
3174 static int jt_show_net(int argc, char **argv)
3176 char *network = NULL;
3178 struct cYAML *err_rc = NULL, *show_rc = NULL;
3179 long int detail = 0;
3180 const char *const short_options = "n:v";
3181 static const struct option long_options[] = {
3182 { .name = "net", .has_arg = required_argument, .val = 'n' },
3183 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3186 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
3190 while ((opt = getopt_long(argc, argv, short_options,
3191 long_options, NULL)) != -1) {
3197 if ((!optarg) && (argv[optind] != NULL) &&
3198 (argv[optind][0] != '-')) {
3199 if (parse_long(argv[optind++], &detail) != 0)
3206 print_help(net_cmds, "net", "show");
3212 rc = yaml_lnet_config_ni(network, NULL, NULL, NULL, NULL,
3213 detail, NLM_F_DUMP);
3215 if (rc != -EOPNOTSUPP)
3219 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
3222 if (rc != LUSTRE_CFG_RC_NO_ERR)
3223 cYAML_print_tree2file(stderr, err_rc);
3225 cYAML_print_tree(show_rc);
3227 cYAML_free_tree(err_rc);
3228 cYAML_free_tree(show_rc);
3233 static int jt_show_routing(int argc, char **argv)
3235 struct cYAML *err_rc = NULL, *show_rc = NULL;
3238 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
3242 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
3244 if (rc != LUSTRE_CFG_RC_NO_ERR)
3245 cYAML_print_tree2file(stderr, err_rc);
3247 cYAML_print_tree(show_rc);
3249 cYAML_free_tree(err_rc);
3250 cYAML_free_tree(show_rc);
3255 static int jt_show_stats(int argc, char **argv)
3258 struct cYAML *show_rc = NULL, *err_rc = NULL;
3260 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
3264 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
3266 if (rc != LUSTRE_CFG_RC_NO_ERR)
3267 cYAML_print_tree2file(stderr, err_rc);
3269 cYAML_print_tree(show_rc);
3271 cYAML_free_tree(err_rc);
3272 cYAML_free_tree(show_rc);
3277 static int jt_show_udsp(int argc, char **argv)
3281 struct cYAML *err_rc = NULL, *show_rc = NULL;
3283 const char *const short_options = "i:";
3284 static const struct option long_options[] = {
3285 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3289 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
3293 while ((opt = getopt_long(argc, argv, short_options,
3294 long_options, NULL)) != -1) {
3297 rc = parse_long(optarg, &idx);
3298 if (rc != 0 || idx < -1) {
3299 printf("Invalid index \"%s\"\n", optarg);
3304 print_help(net_cmds, "net", "show");
3310 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
3312 if (rc != LUSTRE_CFG_RC_NO_ERR)
3313 cYAML_print_tree2file(stderr, err_rc);
3315 cYAML_print_tree(show_rc);
3317 cYAML_free_tree(err_rc);
3318 cYAML_free_tree(show_rc);
3323 static int jt_show_global(int argc, char **argv)
3326 struct cYAML *show_rc = NULL, *err_rc = NULL;
3328 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
3332 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3333 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3334 cYAML_print_tree2file(stderr, err_rc);
3338 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3339 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3340 cYAML_print_tree2file(stderr, err_rc);
3344 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3345 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3346 cYAML_print_tree2file(stderr, err_rc);
3350 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3351 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3352 cYAML_print_tree2file(stderr, err_rc);
3356 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3357 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3358 cYAML_print_tree2file(stderr, err_rc);
3362 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3363 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3364 cYAML_print_tree2file(stderr, err_rc);
3368 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3369 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3370 cYAML_print_tree2file(stderr, err_rc);
3374 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3375 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3376 cYAML_print_tree2file(stderr, err_rc);
3380 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3381 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3382 cYAML_print_tree2file(stderr, err_rc);
3386 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3387 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3388 cYAML_print_tree2file(stderr, err_rc);
3392 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3393 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3394 cYAML_print_tree2file(stderr, err_rc);
3398 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3399 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3400 cYAML_print_tree2file(stderr, err_rc);
3404 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3405 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3406 cYAML_print_tree2file(stderr, err_rc);
3411 cYAML_print_tree(show_rc);
3414 cYAML_free_tree(err_rc);
3415 cYAML_free_tree(show_rc);
3420 static int jt_lnet(int argc, char **argv)
3424 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
3428 return cfs_parser(argc, argv, lnet_cmds);
3431 static int jt_route(int argc, char **argv)
3435 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
3439 return cfs_parser(argc, argv, route_cmds);
3442 static int jt_net(int argc, char **argv)
3446 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
3450 return cfs_parser(argc, argv, net_cmds);
3453 static int jt_routing(int argc, char **argv)
3457 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
3461 return cfs_parser(argc, argv, routing_cmds);
3464 static int jt_stats(int argc, char **argv)
3468 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
3472 return cfs_parser(argc, argv, stats_cmds);
3475 static int jt_debug(int argc, char **argv)
3479 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
3483 return cfs_parser(argc, argv, debug_cmds);
3486 static int jt_global(int argc, char **argv)
3490 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
3494 return cfs_parser(argc, argv, global_cmds);
3497 static int jt_peers(int argc, char **argv)
3501 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
3505 return cfs_parser(argc, argv, peer_cmds);
3508 static int jt_set(int argc, char **argv)
3512 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
3516 return cfs_parser(argc, argv, set_cmds);
3519 static int jt_udsp(int argc, char **argv)
3523 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
3527 return cfs_parser(argc, argv, udsp_cmds);
3530 static int jt_import(int argc, char **argv)
3533 struct cYAML *err_rc = NULL;
3534 struct cYAML *show_rc = NULL;
3535 int rc = 0, return_rc = 0, opt, opt_found = 0;
3538 const char *const short_options = "adseh";
3539 static const struct option long_options[] = {
3540 { .name = "add", .has_arg = no_argument, .val = 'a' },
3541 { .name = "del", .has_arg = no_argument, .val = 'd' },
3542 { .name = "show", .has_arg = no_argument, .val = 's' },
3543 { .name = "exec", .has_arg = no_argument, .val = 'e' },
3544 { .name = "help", .has_arg = no_argument, .val = 'h' },
3547 while ((opt = getopt_long(argc, argv, short_options,
3548 long_options, NULL)) != -1) {
3562 printf("import FILE\n"
3563 "import < FILE : import a file\n"
3564 "\t--add: add configuration\n"
3565 "\t--del: delete configuration\n"
3566 "\t--show: show configuration\n"
3567 "\t--exec: execute command\n"
3568 "\t--help: display this help\n"
3569 "If no command option is given then --add"
3570 " is assumed by default\n");
3577 /* grab the file name if one exists */
3578 if (opt_found && argc == 3)
3580 else if (!opt_found && argc == 2)
3585 rc = lustre_yaml_config(file, &err_rc);
3586 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3587 cYAML_print_tree(show_rc);
3588 cYAML_free_tree(show_rc);
3591 rc = lustre_yaml_del(file, &err_rc);
3594 rc = lustre_yaml_show(file, &show_rc, &err_rc);
3595 cYAML_print_tree(show_rc);
3596 cYAML_free_tree(show_rc);
3599 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3600 cYAML_print_tree(show_rc);
3601 cYAML_free_tree(show_rc);
3605 if (rc || return_rc) {
3606 cYAML_print_tree2file(stderr, err_rc);
3607 cYAML_free_tree(err_rc);
3613 static int jt_export(int argc, char **argv)
3615 struct cYAML *show_rc = NULL;
3616 struct cYAML *err_rc = NULL;
3620 bool backup = false;
3623 const char *const short_options = "bh";
3624 static const struct option long_options[] = {
3625 { .name = "backup", .has_arg = no_argument, .val = 'b' },
3626 { .name = "help", .has_arg = no_argument, .val = 'h' },
3629 while ((opt = getopt_long(argc, argv, short_options,
3630 long_options, NULL)) != -1) {
3637 printf("export > FILE.yaml : export configuration\n"
3638 "\t--backup: export only what's necessary for reconfig\n"
3639 "\t--help: display this help\n");
3644 if (backup && argc >= 3)
3646 else if (!backup && argc >= 2)
3652 f = fopen(file, "w");
3657 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
3658 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3659 cYAML_print_tree2file(stderr, err_rc);
3660 cYAML_free_tree(err_rc);
3664 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
3666 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3667 cYAML_print_tree2file(stderr, err_rc);
3668 cYAML_free_tree(err_rc);
3672 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
3673 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3674 cYAML_print_tree2file(stderr, err_rc);
3675 cYAML_free_tree(err_rc);
3679 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
3680 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3681 cYAML_print_tree2file(stderr, err_rc);
3682 cYAML_free_tree(err_rc);
3686 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3687 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3688 cYAML_print_tree2file(stderr, err_rc);
3689 cYAML_free_tree(err_rc);
3693 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3694 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3695 cYAML_print_tree2file(stderr, err_rc);
3696 cYAML_free_tree(err_rc);
3700 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3701 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3702 cYAML_print_tree2file(stderr, err_rc);
3703 cYAML_free_tree(err_rc);
3707 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3708 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3709 cYAML_print_tree2file(stderr, err_rc);
3710 cYAML_free_tree(err_rc);
3714 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3715 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3716 cYAML_print_tree2file(stderr, err_rc);
3720 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3721 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3722 cYAML_print_tree2file(stderr, err_rc);
3726 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3727 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3728 cYAML_print_tree2file(stderr, err_rc);
3732 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3733 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3734 cYAML_print_tree2file(stderr, err_rc);
3738 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3739 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3740 cYAML_print_tree2file(stderr, err_rc);
3744 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3745 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3746 cYAML_print_tree2file(stderr, err_rc);
3750 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3751 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3752 cYAML_print_tree2file(stderr, err_rc);
3753 cYAML_free_tree(err_rc);
3757 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3758 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3759 cYAML_print_tree2file(stderr, err_rc);
3760 cYAML_free_tree(err_rc);
3764 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3765 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3766 cYAML_print_tree2file(stderr, err_rc);
3767 cYAML_free_tree(err_rc);
3771 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
3772 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3773 cYAML_print_tree2file(stderr, err_rc);
3774 cYAML_free_tree(err_rc);
3778 if (show_rc != NULL) {
3779 cYAML_print_tree2file(f, show_rc);
3780 cYAML_free_tree(show_rc);
3789 static int jt_peer_nid_common(int argc, char **argv, int cmd)
3791 int flags = cmd == LNETCTL_ADD_CMD ? NLM_F_CREATE : 0;
3792 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
3794 char *prim_nid = NULL, *nidstr = NULL;
3795 char err_str[LNET_MAX_STR_LEN] = "Error";
3796 struct cYAML *err_rc = NULL;
3798 const char *const short_opts = "k:m:n:f:l";
3799 const struct option long_opts[] = {
3800 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
3801 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
3802 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3803 { .name = "force", .has_arg = no_argument, .val = 'f' },
3804 { .name = "lock_prim", .has_arg = no_argument, .val = 'l' },
3807 rc = check_cmd(peer_cmds, "peer",
3808 cmd == LNETCTL_ADD_CMD ? "add" : "del", 2, argc, argv);
3812 while ((opt = getopt_long(argc, argv, short_opts,
3813 long_opts, NULL)) != -1) {
3822 if (cmd == LNETCTL_DEL_CMD) {
3823 rc = LUSTRE_CFG_RC_BAD_PARAM;
3824 snprintf(err_str, LNET_MAX_STR_LEN,
3825 "Unrecognized option '-%c'", opt);
3831 if (cmd == LNETCTL_ADD_CMD) {
3832 rc = LUSTRE_CFG_RC_BAD_PARAM;
3833 snprintf(err_str, LNET_MAX_STR_LEN,
3834 "Unrecognized option '-%c'", opt);
3837 flags |= NLM_F_EXCL;
3840 if (cmd == LNETCTL_DEL_CMD) {
3841 rc = LUSTRE_CFG_RC_BAD_PARAM;
3842 snprintf(err_str, LNET_MAX_STR_LEN,
3843 "Unrecognized option '-%c'", opt);
3846 flags |= NLM_F_EXCL;
3849 print_help(peer_cmds, "peer",
3850 cmd == LNETCTL_ADD_CMD ? "add" : "del");
3856 rc = yaml_lnet_peer(prim_nid, nidstr, !is_mr, -1, -1, false,
3857 LNET_GENL_VERSION, flags);
3859 if (rc == -EOPNOTSUPP)
3864 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
3865 force_lock, -1, &err_rc);
3866 if (rc != LUSTRE_CFG_RC_NO_ERR)
3870 cYAML_build_error(rc, -1, "peer",
3871 cmd == LNETCTL_ADD_CMD ? "add" : "del",
3875 if (rc != LUSTRE_CFG_RC_NO_ERR)
3876 cYAML_print_tree2file(stderr, err_rc);
3878 cYAML_free_tree(err_rc);
3883 static int jt_add_peer_nid(int argc, char **argv)
3885 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
3888 static int jt_del_peer_nid(int argc, char **argv)
3890 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
3893 static int jt_show_peer(int argc, char **argv)
3897 struct cYAML *err_rc = NULL, *show_rc = NULL;
3898 long int detail = 0;
3899 const char *const short_opts = "hn:v::";
3900 const struct option long_opts[] = {
3901 { .name = "help", .has_arg = no_argument, .val = 'h' },
3902 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3903 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3907 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
3911 while ((opt = getopt_long(argc, argv, short_opts,
3912 long_opts, NULL)) != -1) {
3918 if ((!optarg) && (argv[optind] != NULL) &&
3919 (argv[optind][0] != '-')) {
3920 if (parse_long(argv[optind++], &detail) != 0)
3927 print_help(peer_cmds, "peer", "show");
3933 rc = yaml_lnet_peer(nid, NULL, false, -1, -1, false, detail,
3936 if (rc == -EOPNOTSUPP)
3941 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
3944 if (rc != LUSTRE_CFG_RC_NO_ERR)
3945 cYAML_print_tree2file(stderr, err_rc);
3947 cYAML_print_tree(show_rc);
3949 cYAML_free_tree(err_rc);
3950 cYAML_free_tree(show_rc);
3955 static int jt_list_peer(int argc, char **argv)
3958 struct cYAML *err_rc = NULL, *list_rc = NULL;
3960 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
3964 rc = yaml_lnet_peer(NULL, NULL, false, -1, -1, true, 0, NLM_F_DUMP);
3966 if (rc == -EOPNOTSUPP)
3971 if (rc != LUSTRE_CFG_RC_NO_ERR)
3972 cYAML_print_tree2file(stderr, err_rc);
3974 cYAML_print_tree(list_rc);
3976 cYAML_free_tree(err_rc);
3977 cYAML_free_tree(list_rc);
3982 static int jt_ping(int argc, char **argv)
3984 struct cYAML *err_rc = NULL;
3985 struct cYAML *show_rc = NULL;
3988 char *src_nidstr = NULL;
3990 const char *const short_options = "hs:t:";
3991 const struct option long_options[] = {
3992 { .name = "help", .has_arg = no_argument, .val = 'h' },
3993 { .name = "timeout", .has_arg = required_argument, .val = 't' },
3994 { .name = "source", .has_arg = required_argument, .val = 's' },
3997 while ((opt = getopt_long(argc, argv, short_options,
3998 long_options, NULL)) != -1) {
4001 src_nidstr = optarg;
4004 timeout = 1000 * atol(optarg);
4007 printf("ping nid[,nid,...]\n"
4008 "\t --source: source nid\n"
4009 "\t --timeout: ping timeout\n"
4010 "\t --help: display this help\n");
4017 for (; optind < argc; optind++)
4018 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
4022 cYAML_print_tree(show_rc);
4025 cYAML_print_tree2file(stderr, err_rc);
4027 cYAML_free_tree(err_rc);
4028 cYAML_free_tree(show_rc);
4033 static int jt_discover(int argc, char **argv)
4035 struct cYAML *err_rc = NULL;
4036 struct cYAML *show_rc = NULL;
4040 const char *const short_options = "fh";
4041 const struct option long_options[] = {
4042 { .name = "force", .has_arg = no_argument, .val = 'f' },
4043 { .name = "help", .has_arg = no_argument, .val = 'h' },
4046 while ((opt = getopt_long(argc, argv, short_options,
4047 long_options, NULL)) != -1) {
4053 printf("discover nid[,nid,...]\n"
4054 "\t --force: force discovery\n"
4055 "\t --help: display this help\n");
4062 if (optind == argc) {
4063 printf("Missing nid argument\n");
4067 for (; optind < argc; optind++)
4068 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
4072 cYAML_print_tree(show_rc);
4075 cYAML_print_tree2file(stderr, err_rc);
4077 cYAML_free_tree(err_rc);
4078 cYAML_free_tree(show_rc);
4083 static int jt_add_udsp(int argc, char **argv)
4085 char *src = NULL, *dst = NULL, *rte = NULL;
4086 struct cYAML *err_rc = NULL;
4087 union lnet_udsp_action udsp_action;
4088 long int idx = -1, priority = -1;
4090 char *action_type = "pref";
4092 const char *const short_options = "s:d:r:p:i:";
4093 static const struct option long_options[] = {
4094 { .name = "src", .has_arg = required_argument, .val = 's' },
4095 { .name = "dst", .has_arg = required_argument, .val = 'd' },
4096 { .name = "rte", .has_arg = required_argument, .val = 'r' },
4097 { .name = "priority", .has_arg = required_argument, .val = 'p' },
4098 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4101 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
4105 while ((opt = getopt_long(argc, argv, short_options,
4106 long_options, NULL)) != -1) {
4118 rc = parse_long(optarg, &priority);
4119 if (rc != 0 || priority < 0) {
4120 printf("Invalid priority \"%s\"\n", optarg);
4123 action_type = "priority";
4124 udsp_action.udsp_priority = priority;
4127 rc = parse_long(optarg, &idx);
4128 if (rc != 0 || idx < 0) {
4129 printf("Invalid index \"%s\"\n", optarg);
4134 print_help(udsp_cmds, "udsp", "add");
4140 if (!(src || dst || rte)) {
4141 print_help(udsp_cmds, "udsp", "add");
4145 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
4148 if (rc != LUSTRE_CFG_RC_NO_ERR)
4149 cYAML_print_tree2file(stderr, err_rc);
4151 cYAML_free_tree(err_rc);
4156 static int jt_del_udsp(int argc, char **argv)
4158 struct cYAML *err_rc = NULL;
4163 const char *const short_options = "ai:";
4164 static const struct option long_options[] = {
4165 { .name = "all", .has_arg = no_argument, .val = 'a' },
4166 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4169 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
4173 while ((opt = getopt_long(argc, argv, short_options,
4174 long_options, NULL)) != -1) {
4180 rc = parse_long(optarg, &idx);
4181 if (rc != 0 || idx < -1) {
4182 printf("Invalid index \"%s\"\n", optarg);
4187 print_help(udsp_cmds, "udsp", "del");
4193 if (all && idx != -2) {
4194 printf("Cannot combine --all with --idx\n");
4198 } else if (idx == -2) {
4199 printf("Must specify --idx or --all\n");
4203 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
4204 if (rc != LUSTRE_CFG_RC_NO_ERR)
4205 cYAML_print_tree2file(stderr, err_rc);
4207 cYAML_free_tree(err_rc);
4212 int main(int argc, char **argv)
4215 struct cYAML *err_rc = NULL;
4217 rc = lustre_lnet_config_lib_init();
4219 cYAML_build_error(-1, -1, "lnetctl", "startup",
4220 "cannot register LNet device", &err_rc);
4221 cYAML_print_tree2file(stderr, err_rc);
4225 return cfs_parser(argc, argv, cmd_list);