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,
121 "Calculate the CPTs associated with NIDs\n"
122 " usage:\n\tlnetctl cpt-of-nid nid[ nid ...]\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_set_recovery_limit(int argc, char **argv)
443 struct cYAML *err_rc = NULL;
445 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
449 rc = parse_long(argv[1], &value);
451 cYAML_build_error(-1, -1, "parser", "set",
452 "cannot parse recovery_limit value",
454 cYAML_print_tree2file(stderr, err_rc);
455 cYAML_free_tree(err_rc);
459 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
460 if (rc != LUSTRE_CFG_RC_NO_ERR)
461 cYAML_print_tree2file(stderr, err_rc);
463 cYAML_free_tree(err_rc);
468 static int jt_set_max_intf(int argc, char **argv)
472 struct cYAML *err_rc = NULL;
474 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
478 rc = parse_long(argv[1], &value);
480 cYAML_build_error(-1, -1, "parser", "set",
481 "cannot parse max_interfaces value", &err_rc);
482 cYAML_print_tree2file(stderr, err_rc);
483 cYAML_free_tree(err_rc);
487 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
488 if (rc != LUSTRE_CFG_RC_NO_ERR)
489 cYAML_print_tree2file(stderr, err_rc);
491 cYAML_free_tree(err_rc);
496 static int jt_set_numa(int argc, char **argv)
500 struct cYAML *err_rc = NULL;
502 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
506 rc = parse_long(argv[1], &value);
508 cYAML_build_error(-1, -1, "parser", "set",
509 "cannot parse numa_range value", &err_rc);
510 cYAML_print_tree2file(stderr, err_rc);
511 cYAML_free_tree(err_rc);
515 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
516 if (rc != LUSTRE_CFG_RC_NO_ERR)
517 cYAML_print_tree2file(stderr, err_rc);
519 cYAML_free_tree(err_rc);
524 static int jt_set_recov_intrv(int argc, char **argv)
528 struct cYAML *err_rc = NULL;
530 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
534 rc = parse_long(argv[1], &value);
536 cYAML_build_error(-1, -1, "parser", "set",
537 "cannot parse recovery interval value", &err_rc);
538 cYAML_print_tree2file(stderr, err_rc);
539 cYAML_free_tree(err_rc);
543 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
544 if (rc != LUSTRE_CFG_RC_NO_ERR)
545 cYAML_print_tree2file(stderr, err_rc);
547 cYAML_free_tree(err_rc);
552 static int jt_set_rtr_sensitivity(int argc, char **argv)
556 struct cYAML *err_rc = NULL;
558 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
562 rc = parse_long(argv[1], &value);
564 cYAML_build_error(-1, -1, "parser", "set",
565 "cannot parse router sensitivity value", &err_rc);
566 cYAML_print_tree2file(stderr, err_rc);
567 cYAML_free_tree(err_rc);
571 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
572 if (rc != LUSTRE_CFG_RC_NO_ERR)
573 cYAML_print_tree2file(stderr, err_rc);
575 cYAML_free_tree(err_rc);
580 static int jt_set_hsensitivity(int argc, char **argv)
584 struct cYAML *err_rc = NULL;
586 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
590 rc = parse_long(argv[1], &value);
592 cYAML_build_error(-1, -1, "parser", "set",
593 "cannot parse health sensitivity value", &err_rc);
594 cYAML_print_tree2file(stderr, err_rc);
595 cYAML_free_tree(err_rc);
599 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
600 if (rc != LUSTRE_CFG_RC_NO_ERR)
601 cYAML_print_tree2file(stderr, err_rc);
603 cYAML_free_tree(err_rc);
608 static int jt_reset_stats(int argc, char **argv)
611 struct cYAML *err_rc = NULL;
613 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
617 rc = lustre_lnet_reset_stats(-1, &err_rc);
618 if (rc != LUSTRE_CFG_RC_NO_ERR)
619 cYAML_print_tree2file(stderr, err_rc);
621 cYAML_free_tree(err_rc);
626 static int jt_set_transaction_to(int argc, char **argv)
630 struct cYAML *err_rc = NULL;
632 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
636 rc = parse_long(argv[1], &value);
638 cYAML_build_error(-1, -1, "parser", "set",
639 "cannot parse transaction timeout value", &err_rc);
640 cYAML_print_tree2file(stderr, err_rc);
641 cYAML_free_tree(err_rc);
645 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
646 if (rc != LUSTRE_CFG_RC_NO_ERR)
647 cYAML_print_tree2file(stderr, err_rc);
649 cYAML_free_tree(err_rc);
654 static int jt_set_retry_count(int argc, char **argv)
658 struct cYAML *err_rc = NULL;
660 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
664 rc = parse_long(argv[1], &value);
666 cYAML_build_error(-1, -1, "parser", "set",
667 "cannot parse retry_count value", &err_rc);
668 cYAML_print_tree2file(stderr, err_rc);
669 cYAML_free_tree(err_rc);
673 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
674 if (rc != LUSTRE_CFG_RC_NO_ERR)
675 cYAML_print_tree2file(stderr, err_rc);
677 cYAML_free_tree(err_rc);
682 static int jt_set_discovery(int argc, char **argv)
686 struct cYAML *err_rc = NULL;
688 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
692 rc = parse_long(argv[1], &value);
694 cYAML_build_error(-1, -1, "parser", "set",
695 "cannot parse discovery value", &err_rc);
696 cYAML_print_tree2file(stderr, err_rc);
697 cYAML_free_tree(err_rc);
701 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
702 if (rc != LUSTRE_CFG_RC_NO_ERR)
703 cYAML_print_tree2file(stderr, err_rc);
705 cYAML_free_tree(err_rc);
710 static int jt_set_drop_asym_route(int argc, char **argv)
714 struct cYAML *err_rc = NULL;
716 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
720 rc = parse_long(argv[1], &value);
722 cYAML_build_error(-1, -1, "parser", "set",
723 "cannot parse drop_asym_route value",
725 cYAML_print_tree2file(stderr, err_rc);
726 cYAML_free_tree(err_rc);
730 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
731 if (rc != LUSTRE_CFG_RC_NO_ERR)
732 cYAML_print_tree2file(stderr, err_rc);
734 cYAML_free_tree(err_rc);
739 static int jt_set_tiny(int argc, char **argv)
743 struct cYAML *err_rc = NULL;
745 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
749 rc = parse_long(argv[1], &value);
751 cYAML_build_error(-1, -1, "parser", "set",
752 "cannot parse tiny_buffers value", &err_rc);
753 cYAML_print_tree2file(stderr, err_rc);
754 cYAML_free_tree(err_rc);
758 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
759 if (rc != LUSTRE_CFG_RC_NO_ERR)
760 cYAML_print_tree2file(stderr, err_rc);
762 cYAML_free_tree(err_rc);
767 static int jt_set_small(int argc, char **argv)
771 struct cYAML *err_rc = NULL;
773 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
777 rc = parse_long(argv[1], &value);
779 cYAML_build_error(-1, -1, "parser", "set",
780 "cannot parse small_buffers value", &err_rc);
781 cYAML_print_tree2file(stderr, err_rc);
782 cYAML_free_tree(err_rc);
786 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
787 if (rc != LUSTRE_CFG_RC_NO_ERR)
788 cYAML_print_tree2file(stderr, err_rc);
790 cYAML_free_tree(err_rc);
795 static int jt_set_large(int argc, char **argv)
799 struct cYAML *err_rc = NULL;
801 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
805 rc = parse_long(argv[1], &value);
807 cYAML_build_error(-1, -1, "parser", "set",
808 "cannot parse large_buffers value", &err_rc);
809 cYAML_print_tree2file(stderr, err_rc);
810 cYAML_free_tree(err_rc);
814 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
815 if (rc != LUSTRE_CFG_RC_NO_ERR)
816 cYAML_print_tree2file(stderr, err_rc);
818 cYAML_free_tree(err_rc);
823 static int jt_set_routing(int argc, char **argv)
826 struct cYAML *err_rc = NULL;
829 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
833 rc = parse_long(argv[1], &value);
834 if (rc != 0 || (value != 0 && value != 1)) {
835 cYAML_build_error(-1, -1, "parser", "set",
836 "cannot parse routing value.\n"
837 "must be 0 for disable or 1 for enable",
839 cYAML_print_tree2file(stderr, err_rc);
840 cYAML_free_tree(err_rc);
844 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
846 if (rc != LUSTRE_CFG_RC_NO_ERR)
847 cYAML_print_tree2file(stderr, err_rc);
849 cYAML_free_tree(err_rc);
854 static int jt_set_max_recovery_ping_interval(int argc, char **argv)
858 struct cYAML *err_rc = NULL;
860 rc = check_cmd(set_cmds, "set", "maximum recovery_interval", 2, argc, argv);
864 rc = parse_long(argv[1], &value);
866 cYAML_build_error(-1, -1, "parser", "set",
867 "cannot parse maximum recovery interval value",
869 cYAML_print_tree2file(stderr, err_rc);
870 cYAML_free_tree(err_rc);
874 rc = lustre_lnet_config_max_recovery_ping_interval(value, -1, &err_rc);
875 if (rc != LUSTRE_CFG_RC_NO_ERR)
876 cYAML_print_tree2file(stderr, err_rc);
878 cYAML_free_tree(err_rc);
883 static void yaml_lnet_print_error(int op, char *cmd, const char *errstr)
885 char errcode[INT_STRING_LEN];
891 snprintf(errcode, sizeof(errcode), "%d", errno);
893 yaml_emitter_initialize(&log);
894 yaml_emitter_set_indent(&log, LNET_DEFAULT_INDENT);
895 yaml_emitter_set_output_file(&log, stderr);
897 yaml_emitter_open(&log);
898 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
899 rc = yaml_emitter_emit(&log, &event);
903 yaml_mapping_start_event_initialize(&event, NULL,
904 (yaml_char_t *)YAML_MAP_TAG,
905 1, YAML_ANY_MAPPING_STYLE);
906 rc = yaml_emitter_emit(&log, &event);
929 yaml_scalar_event_initialize(&event, NULL,
930 (yaml_char_t *)YAML_STR_TAG,
933 YAML_PLAIN_SCALAR_STYLE);
934 rc = yaml_emitter_emit(&log, &event);
938 yaml_sequence_start_event_initialize(&event, NULL,
939 (yaml_char_t *)YAML_SEQ_TAG,
940 1, YAML_ANY_SEQUENCE_STYLE);
941 rc = yaml_emitter_emit(&log, &event);
945 yaml_mapping_start_event_initialize(&event, NULL,
946 (yaml_char_t *)YAML_MAP_TAG,
947 1, YAML_ANY_MAPPING_STYLE);
948 rc = yaml_emitter_emit(&log, &event);
952 yaml_scalar_event_initialize(&event, NULL,
953 (yaml_char_t *)YAML_STR_TAG,
956 1, 0, YAML_PLAIN_SCALAR_STYLE);
957 rc = yaml_emitter_emit(&log, &event);
961 yaml_scalar_event_initialize(&event, NULL,
962 (yaml_char_t *)YAML_STR_TAG,
965 1, 0, YAML_PLAIN_SCALAR_STYLE);
966 rc = yaml_emitter_emit(&log, &event);
970 yaml_scalar_event_initialize(&event, NULL,
971 (yaml_char_t *)YAML_STR_TAG,
972 (yaml_char_t *)"errno",
973 strlen("errno"), 1, 0,
974 YAML_PLAIN_SCALAR_STYLE);
975 rc = yaml_emitter_emit(&log, &event);
979 yaml_scalar_event_initialize(&event, NULL,
980 (yaml_char_t *)YAML_INT_TAG,
981 (yaml_char_t *)errcode,
982 strlen(errcode), 1, 0,
983 YAML_PLAIN_SCALAR_STYLE);
984 rc = yaml_emitter_emit(&log, &event);
989 yaml_scalar_event_initialize(&event, NULL,
990 (yaml_char_t *)YAML_STR_TAG,
991 (yaml_char_t *)"descr",
992 strlen("descr"), 1, 0,
993 YAML_PLAIN_SCALAR_STYLE);
994 rc = yaml_emitter_emit(&log, &event);
998 yaml_scalar_event_initialize(&event, NULL,
999 (yaml_char_t *)YAML_STR_TAG,
1000 (yaml_char_t *)errstr,
1001 strlen(errstr), 1, 0,
1002 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
1003 rc = yaml_emitter_emit(&log, &event);
1007 yaml_mapping_end_event_initialize(&event);
1008 rc = yaml_emitter_emit(&log, &event);
1012 yaml_sequence_end_event_initialize(&event);
1013 rc = yaml_emitter_emit(&log, &event);
1017 yaml_mapping_end_event_initialize(&event);
1018 rc = yaml_emitter_emit(&log, &event);
1022 yaml_document_end_event_initialize(&event, 0);
1023 rc = yaml_emitter_emit(&log, &event);
1027 rc = yaml_emitter_close(&log);
1030 yaml_emitter_log_error(&log, stdout);
1031 yaml_emitter_delete(&log);
1034 static int yaml_lnet_cpt_of_nid_display(yaml_parser_t *reply)
1036 yaml_document_t results;
1037 yaml_emitter_t output;
1040 rc = yaml_parser_load(reply, &results);
1042 yaml_lnet_print_error(NLM_F_DUMP, "cpt-of-nid",
1043 yaml_parser_get_reader_error(reply));
1044 yaml_document_delete(&results);
1048 rc = yaml_emitter_initialize(&output);
1050 yaml_emitter_set_output_file(&output, stdout);
1052 rc = yaml_emitter_dump(&output, &results);
1055 yaml_document_delete(&results);
1057 yaml_emitter_log_error(&output, stderr);
1060 yaml_emitter_delete(&output);
1065 static int yaml_lnet_cpt_of_nid(int start, int end, char **nids)
1067 struct nl_sock *sk = NULL;
1068 yaml_emitter_t request;
1069 yaml_parser_t reply;
1073 /* Create Netlink emitter to send request to kernel */
1074 sk = nl_socket_alloc();
1078 /* Setup parser to receive Netlink packets */
1079 rc = yaml_parser_initialize(&reply);
1085 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1089 /* Create Netlink emitter to send request to kernel */
1090 rc = yaml_emitter_initialize(&request);
1094 rc = yaml_emitter_set_output_netlink(&request, sk, LNET_GENL_NAME,
1096 LNET_CMD_CPT_OF_NID, NLM_F_DUMP);
1100 yaml_emitter_open(&request);
1101 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1102 rc = yaml_emitter_emit(&request, &event);
1106 yaml_mapping_start_event_initialize(&event, NULL,
1107 (yaml_char_t *)YAML_MAP_TAG,
1108 1, YAML_ANY_MAPPING_STYLE);
1109 rc = yaml_emitter_emit(&request, &event);
1113 yaml_scalar_event_initialize(&event, NULL,
1114 (yaml_char_t *)YAML_STR_TAG,
1115 (yaml_char_t *)"cpt-of-nid",
1116 strlen("cpt-of-nid"), 1, 0,
1117 YAML_PLAIN_SCALAR_STYLE);
1118 rc = yaml_emitter_emit(&request, &event);
1122 yaml_mapping_start_event_initialize(&event, NULL,
1123 (yaml_char_t *)YAML_MAP_TAG,
1124 1, YAML_ANY_MAPPING_STYLE);
1125 rc = yaml_emitter_emit(&request, &event);
1129 yaml_scalar_event_initialize(&event, NULL,
1130 (yaml_char_t *)YAML_STR_TAG,
1131 (yaml_char_t *)"nids",
1132 strlen("nids"), 1, 0,
1133 YAML_PLAIN_SCALAR_STYLE);
1134 rc = yaml_emitter_emit(&request, &event);
1138 yaml_sequence_start_event_initialize(&event, NULL,
1139 (yaml_char_t *)YAML_SEQ_TAG,
1140 1, YAML_FLOW_SEQUENCE_STYLE);
1141 rc = yaml_emitter_emit(&request, &event);
1145 for (i = start; i < end; i++) {
1146 yaml_scalar_event_initialize(&event, NULL,
1147 (yaml_char_t *)YAML_STR_TAG,
1148 (yaml_char_t *)nids[i],
1149 strlen(nids[i]), 1, 0,
1150 YAML_PLAIN_SCALAR_STYLE);
1151 rc = yaml_emitter_emit(&request, &event);
1156 yaml_sequence_end_event_initialize(&event);
1157 rc = yaml_emitter_emit(&request, &event);
1161 yaml_mapping_end_event_initialize(&event);
1162 rc = yaml_emitter_emit(&request, &event);
1166 yaml_mapping_end_event_initialize(&event);
1167 rc = yaml_emitter_emit(&request, &event);
1171 yaml_document_end_event_initialize(&event, 0);
1172 rc = yaml_emitter_emit(&request, &event);
1176 rc = yaml_emitter_close(&request);
1179 yaml_emitter_log_error(&request, stderr);
1182 rc = yaml_lnet_cpt_of_nid_display(&reply);
1184 yaml_emitter_delete(&request);
1187 yaml_lnet_print_error(NLM_F_DUMP, "cpt-of-nid",
1188 yaml_parser_get_reader_error(&reply));
1192 yaml_parser_delete(&reply);
1195 return rc == 1 ? 0 : rc;
1198 static int jt_calc_cpt_of_nid(int argc, char **argv)
1201 const char *const short_options = "h";
1202 static const struct option long_options[] = {
1203 { .name = "help", .val = 'h' },
1206 rc = check_cmd(cmd_list, "", "cpt-of-nid", 2, argc, argv);
1210 while ((opt = getopt_long(argc, argv, short_options,
1211 long_options, NULL)) != -1) {
1215 print_help(cmd_list, "", "cpt-of-nid");
1221 rc = yaml_lnet_cpt_of_nid(optind, argc, argv);
1222 if (rc == -EOPNOTSUPP)
1223 printf("Operation not supported\n");
1228 static int jt_config_lnet(int argc, char **argv)
1230 struct cYAML *err_rc = NULL;
1231 bool load_mod_params = false;
1234 const char *const short_options = "a";
1235 static const struct option long_options[] = {
1236 { .name = "all", .has_arg = no_argument, .val = 'a' },
1240 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
1244 while ((opt = getopt_long(argc, argv, short_options,
1245 long_options, NULL)) != -1) {
1248 load_mod_params = true;
1255 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
1258 if (rc != LUSTRE_CFG_RC_NO_ERR)
1259 cYAML_print_tree2file(stderr, err_rc);
1261 cYAML_free_tree(err_rc);
1266 static int jt_unconfig_lnet(int argc, char **argv)
1268 struct cYAML *err_rc = NULL;
1271 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
1275 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
1277 if (rc != LUSTRE_CFG_RC_NO_ERR)
1278 cYAML_print_tree2file(stderr, err_rc);
1280 cYAML_free_tree(err_rc);
1285 static int yaml_lnet_router_gateways(yaml_emitter_t *output, const char *nw,
1286 const char *gw, int hops, int prio,
1289 char num[INT_STRING_LEN];
1293 yaml_mapping_start_event_initialize(&event, NULL,
1294 (yaml_char_t *)YAML_MAP_TAG, 1,
1295 YAML_BLOCK_MAPPING_STYLE);
1296 rc = yaml_emitter_emit(output, &event);
1301 yaml_scalar_event_initialize(&event, NULL,
1302 (yaml_char_t *)YAML_STR_TAG,
1303 (yaml_char_t *)"net",
1304 strlen("net"), 1, 0,
1305 YAML_PLAIN_SCALAR_STYLE);
1306 rc = yaml_emitter_emit(output, &event);
1310 yaml_scalar_event_initialize(&event, NULL,
1311 (yaml_char_t *)YAML_STR_TAG,
1314 YAML_PLAIN_SCALAR_STYLE);
1315 rc = yaml_emitter_emit(output, &event);
1321 yaml_scalar_event_initialize(&event, NULL,
1322 (yaml_char_t *)YAML_STR_TAG,
1323 (yaml_char_t *)"gateway",
1324 strlen("gateway"), 1, 0,
1325 YAML_PLAIN_SCALAR_STYLE);
1326 rc = yaml_emitter_emit(output, &event);
1330 yaml_scalar_event_initialize(&event, NULL,
1331 (yaml_char_t *)YAML_STR_TAG,
1334 YAML_PLAIN_SCALAR_STYLE);
1335 rc = yaml_emitter_emit(output, &event);
1341 yaml_scalar_event_initialize(&event, NULL,
1342 (yaml_char_t *)YAML_STR_TAG,
1343 (yaml_char_t *)"hop",
1344 strlen("hop"), 1, 0,
1345 YAML_PLAIN_SCALAR_STYLE);
1346 rc = yaml_emitter_emit(output, &event);
1350 snprintf(num, sizeof(num), "%d", hops);
1351 yaml_scalar_event_initialize(&event, NULL,
1352 (yaml_char_t *)YAML_INT_TAG,
1355 YAML_PLAIN_SCALAR_STYLE);
1356 rc = yaml_emitter_emit(output, &event);
1362 yaml_scalar_event_initialize(&event, NULL,
1363 (yaml_char_t *)YAML_STR_TAG,
1364 (yaml_char_t *)"priority",
1365 strlen("priority"), 1, 0,
1366 YAML_PLAIN_SCALAR_STYLE);
1367 rc = yaml_emitter_emit(output, &event);
1371 snprintf(num, sizeof(num), "%d", prio);
1372 yaml_scalar_event_initialize(&event, NULL,
1373 (yaml_char_t *)YAML_INT_TAG,
1376 YAML_PLAIN_SCALAR_STYLE);
1377 rc = yaml_emitter_emit(output, &event);
1383 yaml_scalar_event_initialize(&event, NULL,
1384 (yaml_char_t *)YAML_STR_TAG,
1385 (yaml_char_t *)"health_sensitivity",
1386 strlen("health_sensitivity"),
1388 YAML_PLAIN_SCALAR_STYLE);
1389 rc = yaml_emitter_emit(output, &event);
1393 snprintf(num, sizeof(num), "%d", sen);
1394 yaml_scalar_event_initialize(&event, NULL,
1395 (yaml_char_t *)YAML_INT_TAG,
1398 YAML_PLAIN_SCALAR_STYLE);
1399 rc = yaml_emitter_emit(output, &event);
1404 yaml_mapping_end_event_initialize(&event);
1405 rc = yaml_emitter_emit(output, &event);
1410 static int yaml_lnet_route(char *nw, char *gw, int hops, int prio, int sen,
1411 int version, int flags)
1413 struct nid_node head, *entry;
1414 struct nl_sock *sk = NULL;
1415 const char *msg = NULL;
1416 yaml_emitter_t output;
1417 yaml_parser_t reply;
1421 if (!(flags & NLM_F_DUMP) && (!nw || !gw)) {
1422 fprintf(stdout, "missing mandatory parameters:'%s'\n",
1423 (!nw && !gw) ? "net , gateway" :
1424 !nw ? "net" : "gateway");
1428 /* Create Netlink emitter to send request to kernel */
1429 sk = nl_socket_alloc();
1433 /* Setup parser to receive Netlink packets */
1434 rc = yaml_parser_initialize(&reply);
1440 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1442 msg = yaml_parser_get_reader_error(&reply);
1446 /* Create Netlink emitter to send request to kernel */
1447 rc = yaml_emitter_initialize(&output);
1449 msg = "failed to initialize emitter";
1453 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1454 version, LNET_CMD_ROUTES, flags);
1458 yaml_emitter_open(&output);
1459 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1460 rc = yaml_emitter_emit(&output, &event);
1464 yaml_mapping_start_event_initialize(&event, NULL,
1465 (yaml_char_t *)YAML_MAP_TAG,
1466 1, YAML_ANY_MAPPING_STYLE);
1467 rc = yaml_emitter_emit(&output, &event);
1471 yaml_scalar_event_initialize(&event, NULL,
1472 (yaml_char_t *)YAML_STR_TAG,
1473 (yaml_char_t *)"route",
1474 strlen("route"), 1, 0,
1475 YAML_PLAIN_SCALAR_STYLE);
1476 rc = yaml_emitter_emit(&output, &event);
1480 /* NLM_F_DUMP can have no arguments */
1482 NL_INIT_LIST_HEAD(&head.children);
1483 nl_init_list_head(&head.list);
1485 rc = lustre_lnet_parse_nid_range(&head, gw, &msg);
1487 lustre_lnet_free_list(&head);
1488 yaml_emitter_delete(&output);
1495 yaml_sequence_start_event_initialize(&event, NULL,
1496 (yaml_char_t *)YAML_SEQ_TAG,
1498 YAML_BLOCK_SEQUENCE_STYLE);
1499 rc = yaml_emitter_emit(&output, &event);
1503 if (!nl_list_empty(&head.children)) {
1504 nl_list_for_each_entry(entry, &head.children, list) {
1505 const char *nid = entry->nidstr;
1507 rc = yaml_lnet_router_gateways(&output, nw, nid,
1513 rc = yaml_lnet_router_gateways(&output, nw, NULL, hops,
1519 yaml_sequence_end_event_initialize(&event);
1520 rc = yaml_emitter_emit(&output, &event);
1524 yaml_scalar_event_initialize(&event, NULL,
1525 (yaml_char_t *)YAML_STR_TAG,
1528 YAML_PLAIN_SCALAR_STYLE);
1529 rc = yaml_emitter_emit(&output, &event);
1534 yaml_mapping_end_event_initialize(&event);
1535 rc = yaml_emitter_emit(&output, &event);
1539 yaml_document_end_event_initialize(&event, 0);
1540 rc = yaml_emitter_emit(&output, &event);
1544 rc = yaml_emitter_close(&output);
1547 yaml_emitter_log_error(&output, stderr);
1550 yaml_document_t errmsg;
1552 rc = yaml_parser_load(&reply, &errmsg);
1553 if (rc == 1 && (flags & NLM_F_DUMP)) {
1554 yaml_emitter_t debug;
1556 rc = yaml_emitter_initialize(&debug);
1558 yaml_emitter_set_indent(&debug,
1559 LNET_DEFAULT_INDENT);
1560 yaml_emitter_set_output_file(&debug,
1562 rc = yaml_emitter_dump(&debug, &errmsg);
1564 yaml_emitter_delete(&debug);
1566 msg = yaml_parser_get_reader_error(&reply);
1567 /* If we didn't find any routes just be silent */
1568 if (msg && strcmp(msg, "No routes found") == 0)
1571 yaml_document_delete(&errmsg);
1573 yaml_emitter_delete(&output);
1576 yaml_lnet_print_error(flags, "route", msg);
1579 yaml_parser_delete(&reply);
1582 return rc == 1 ? 0 : rc;
1585 static int jt_add_route(int argc, char **argv)
1587 char *network = NULL, *gateway = NULL;
1588 long int hop = -1, prio = -1, sen = -1;
1589 struct cYAML *err_rc = NULL;
1592 const char *const short_options = "n:g:c:p:";
1593 static const struct option long_options[] = {
1594 { .name = "net", .has_arg = required_argument, .val = 'n' },
1595 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1596 { .name = "hop", .has_arg = required_argument, .val = 'c' },
1597 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1598 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1599 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1603 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1607 while ((opt = getopt_long(argc, argv, short_options,
1608 long_options, NULL)) != -1) {
1617 rc = parse_long(optarg, &hop);
1625 rc = parse_long(optarg, &prio);
1633 rc = parse_long(optarg, &sen);
1642 print_help(route_cmds, "route", "add");
1648 rc = yaml_lnet_route(network, gateway, hop, prio, sen,
1649 LNET_GENL_VERSION, NLM_F_CREATE);
1651 if (rc == -EOPNOTSUPP)
1656 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1659 if (rc != LUSTRE_CFG_RC_NO_ERR)
1660 cYAML_print_tree2file(stderr, err_rc);
1662 cYAML_free_tree(err_rc);
1667 static int yaml_add_ni_tunables(yaml_emitter_t *output,
1668 struct lnet_ioctl_config_lnd_tunables *tunables,
1669 struct lnet_dlc_network_descr *nw_descr)
1671 char num[INT_STRING_LEN];
1675 if (tunables->lt_cmn.lct_peer_timeout < 0 &&
1676 tunables->lt_cmn.lct_peer_tx_credits <= 0 &&
1677 tunables->lt_cmn.lct_peer_rtr_credits <= 0 &&
1678 tunables->lt_cmn.lct_max_tx_credits <= 0)
1679 goto skip_general_settings;
1681 yaml_scalar_event_initialize(&event, NULL,
1682 (yaml_char_t *)YAML_STR_TAG,
1683 (yaml_char_t *)"tunables",
1684 strlen("tunables"), 1, 0,
1685 YAML_PLAIN_SCALAR_STYLE);
1686 rc = yaml_emitter_emit(output, &event);
1690 yaml_mapping_start_event_initialize(&event, NULL,
1691 (yaml_char_t *)YAML_MAP_TAG,
1692 1, YAML_ANY_MAPPING_STYLE);
1693 rc = yaml_emitter_emit(output, &event);
1697 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1698 yaml_scalar_event_initialize(&event, NULL,
1699 (yaml_char_t *)YAML_STR_TAG,
1700 (yaml_char_t *)"peer_timeout",
1701 strlen("peer_timeout"), 1, 0,
1702 YAML_PLAIN_SCALAR_STYLE);
1703 rc = yaml_emitter_emit(output, &event);
1707 snprintf(num, sizeof(num), "%u",
1708 tunables->lt_cmn.lct_peer_timeout);
1709 yaml_scalar_event_initialize(&event, NULL,
1710 (yaml_char_t *)YAML_INT_TAG,
1713 YAML_PLAIN_SCALAR_STYLE);
1714 rc = yaml_emitter_emit(output, &event);
1719 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1720 yaml_scalar_event_initialize(&event, NULL,
1721 (yaml_char_t *)YAML_STR_TAG,
1722 (yaml_char_t *)"peer_credits",
1723 strlen("peer_credits"), 1, 0,
1724 YAML_PLAIN_SCALAR_STYLE);
1725 rc = yaml_emitter_emit(output, &event);
1729 snprintf(num, sizeof(num), "%u",
1730 tunables->lt_cmn.lct_peer_tx_credits);
1731 yaml_scalar_event_initialize(&event, NULL,
1732 (yaml_char_t *)YAML_INT_TAG,
1735 YAML_PLAIN_SCALAR_STYLE);
1736 rc = yaml_emitter_emit(output, &event);
1741 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1742 yaml_scalar_event_initialize(&event, NULL,
1743 (yaml_char_t *)YAML_STR_TAG,
1744 (yaml_char_t *)"peer_buffer_credits",
1745 strlen("peer_buffer_credits"), 1, 0,
1746 YAML_PLAIN_SCALAR_STYLE);
1747 rc = yaml_emitter_emit(output, &event);
1751 snprintf(num, sizeof(num), "%u",
1752 tunables->lt_cmn.lct_peer_rtr_credits);
1753 yaml_scalar_event_initialize(&event, NULL,
1754 (yaml_char_t *)YAML_INT_TAG,
1757 YAML_PLAIN_SCALAR_STYLE);
1758 rc = yaml_emitter_emit(output, &event);
1763 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1764 yaml_scalar_event_initialize(&event, NULL,
1765 (yaml_char_t *)YAML_STR_TAG,
1766 (yaml_char_t *)"credits",
1767 strlen("credits"), 1, 0,
1768 YAML_PLAIN_SCALAR_STYLE);
1769 rc = yaml_emitter_emit(output, &event);
1773 snprintf(num, sizeof(num), "%u",
1774 tunables->lt_cmn.lct_max_tx_credits);
1775 yaml_scalar_event_initialize(&event, NULL,
1776 (yaml_char_t *)YAML_INT_TAG,
1779 YAML_PLAIN_SCALAR_STYLE);
1780 rc = yaml_emitter_emit(output, &event);
1785 yaml_mapping_end_event_initialize(&event);
1786 rc = yaml_emitter_emit(output, &event);
1790 skip_general_settings:
1791 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1793 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0 ||
1794 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0] ||
1796 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1797 yaml_scalar_event_initialize(&event, NULL,
1798 (yaml_char_t *)YAML_STR_TAG,
1799 (yaml_char_t *)"lnd tunables",
1800 strlen("lnd tunables"), 1, 0,
1801 YAML_PLAIN_SCALAR_STYLE);
1802 rc = yaml_emitter_emit(output, &event);
1806 yaml_mapping_start_event_initialize(&event, NULL,
1807 (yaml_char_t *)YAML_MAP_TAG,
1808 1, YAML_ANY_MAPPING_STYLE);
1809 rc = yaml_emitter_emit(output, &event);
1813 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1814 yaml_scalar_event_initialize(&event, NULL,
1815 (yaml_char_t *)YAML_STR_TAG,
1816 (yaml_char_t *)"auth_key",
1817 strlen("auth_key"), 1, 0,
1818 YAML_PLAIN_SCALAR_STYLE);
1819 rc = yaml_emitter_emit(output, &event);
1823 snprintf(num, sizeof(num), "%u",
1824 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1826 yaml_scalar_event_initialize(&event, NULL,
1827 (yaml_char_t *)YAML_INT_TAG,
1830 YAML_PLAIN_SCALAR_STYLE);
1831 rc = yaml_emitter_emit(output, &event);
1836 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0]) {
1837 char *tc = &tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0];
1839 yaml_scalar_event_initialize(&event, NULL,
1840 (yaml_char_t *)YAML_STR_TAG,
1841 (yaml_char_t *)"traffic_class",
1842 strlen("traffic_class"), 1, 0,
1843 YAML_PLAIN_SCALAR_STYLE);
1844 rc = yaml_emitter_emit(output, &event);
1848 yaml_scalar_event_initialize(&event, NULL,
1849 (yaml_char_t *)YAML_INT_TAG,
1852 YAML_PLAIN_SCALAR_STYLE);
1854 rc = yaml_emitter_emit(output, &event);
1859 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1860 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1863 yaml_scalar_event_initialize(&event, NULL,
1864 (yaml_char_t *)YAML_STR_TAG,
1865 (yaml_char_t *)"conns_per_peer",
1866 strlen("conns_per_peer"), 1, 0,
1867 YAML_PLAIN_SCALAR_STYLE);
1868 rc = yaml_emitter_emit(output, &event);
1872 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND)
1873 cpp = tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer;
1874 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND)
1875 cpp = tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer;
1876 snprintf(num, sizeof(num), "%u", cpp);
1878 yaml_scalar_event_initialize(&event, NULL,
1879 (yaml_char_t *)YAML_INT_TAG,
1882 YAML_PLAIN_SCALAR_STYLE);
1883 rc = yaml_emitter_emit(output, &event);
1888 yaml_mapping_end_event_initialize(&event);
1889 rc = yaml_emitter_emit(output, &event);
1895 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1896 struct lnet_dlc_network_descr *nw_descr,
1897 struct lnet_ioctl_config_lnd_tunables *tunables,
1898 struct cfs_expr_list *global_cpts,
1899 int version, int flags)
1901 struct lnet_dlc_intf_descr *intf;
1902 struct nl_sock *sk = NULL;
1903 const char *msg = NULL;
1904 yaml_emitter_t output;
1905 yaml_parser_t reply;
1909 if (!(flags & NLM_F_DUMP) && !ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1910 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1911 (!nw_descr) ? "network , interface" :
1912 (nw_descr->nw_id == 0) ? "network" : "interface");
1916 if ((flags == NLM_F_CREATE) && !ip2net && list_empty(&nw_descr->nw_intflist)) {
1917 fprintf(stdout, "creating a local NI needs at least one interface");
1921 /* Create Netlink emitter to send request to kernel */
1922 sk = nl_socket_alloc();
1926 /* Setup parser to receive Netlink packets */
1927 rc = yaml_parser_initialize(&reply);
1933 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1935 msg = yaml_parser_get_reader_error(&reply);
1939 /* Create Netlink emitter to send request to kernel */
1940 rc = yaml_emitter_initialize(&output);
1942 msg = "failed to initialize emitter";
1946 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1947 version, LNET_CMD_NETS, flags);
1951 yaml_emitter_open(&output);
1952 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1953 rc = yaml_emitter_emit(&output, &event);
1957 yaml_mapping_start_event_initialize(&event, NULL,
1958 (yaml_char_t *)YAML_MAP_TAG,
1959 1, YAML_ANY_MAPPING_STYLE);
1960 rc = yaml_emitter_emit(&output, &event);
1964 yaml_scalar_event_initialize(&event, NULL,
1965 (yaml_char_t *)YAML_STR_TAG,
1966 (yaml_char_t *)"net",
1967 strlen("net"), 1, 0,
1968 YAML_PLAIN_SCALAR_STYLE);
1969 rc = yaml_emitter_emit(&output, &event);
1973 if (net_id || ip2net) {
1974 char *key = net_id ? "net type" : "ip2net";
1975 char *value = net_id ? net_id : ip2net;
1977 yaml_sequence_start_event_initialize(&event, NULL,
1978 (yaml_char_t *)YAML_SEQ_TAG,
1979 1, YAML_ANY_SEQUENCE_STYLE);
1980 rc = yaml_emitter_emit(&output, &event);
1984 yaml_mapping_start_event_initialize(&event, NULL,
1985 (yaml_char_t *)YAML_MAP_TAG,
1986 1, YAML_ANY_MAPPING_STYLE);
1987 rc = yaml_emitter_emit(&output, &event);
1991 yaml_scalar_event_initialize(&event, NULL,
1992 (yaml_char_t *)YAML_STR_TAG,
1995 1, 0, YAML_PLAIN_SCALAR_STYLE);
1996 rc = yaml_emitter_emit(&output, &event);
2000 yaml_scalar_event_initialize(&event, NULL,
2001 (yaml_char_t *)YAML_STR_TAG,
2002 (yaml_char_t *)value,
2003 strlen(value), 1, 0,
2004 YAML_PLAIN_SCALAR_STYLE);
2005 rc = yaml_emitter_emit(&output, &event);
2009 yaml_scalar_event_initialize(&event, NULL,
2010 (yaml_char_t *)YAML_STR_TAG,
2013 YAML_PLAIN_SCALAR_STYLE);
2014 rc = yaml_emitter_emit(&output, &event);
2021 if (!nw_descr || list_empty(&nw_descr->nw_intflist))
2024 yaml_scalar_event_initialize(&event, NULL,
2025 (yaml_char_t *)YAML_STR_TAG,
2026 (yaml_char_t *)"local NI(s)",
2027 strlen("local NI(s)"), 1, 0,
2028 YAML_PLAIN_SCALAR_STYLE);
2029 rc = yaml_emitter_emit(&output, &event);
2033 yaml_sequence_start_event_initialize(&event, NULL,
2034 (yaml_char_t *)YAML_SEQ_TAG,
2035 1, YAML_ANY_SEQUENCE_STYLE);
2036 rc = yaml_emitter_emit(&output, &event);
2040 list_for_each_entry(intf, &nw_descr->nw_intflist,
2042 yaml_mapping_start_event_initialize(&event, NULL,
2043 (yaml_char_t *)YAML_MAP_TAG,
2044 1, YAML_ANY_MAPPING_STYLE);
2045 rc = yaml_emitter_emit(&output, &event);
2049 yaml_scalar_event_initialize(&event, NULL,
2050 (yaml_char_t *)YAML_STR_TAG,
2051 (yaml_char_t *)"interfaces",
2052 strlen("interfaces"), 1, 0,
2053 YAML_PLAIN_SCALAR_STYLE);
2054 rc = yaml_emitter_emit(&output, &event);
2058 yaml_mapping_start_event_initialize(&event, NULL,
2059 (yaml_char_t *)YAML_MAP_TAG,
2060 1, YAML_ANY_MAPPING_STYLE);
2061 rc = yaml_emitter_emit(&output, &event);
2065 yaml_scalar_event_initialize(&event, NULL,
2066 (yaml_char_t *)YAML_STR_TAG,
2069 YAML_PLAIN_SCALAR_STYLE);
2070 rc = yaml_emitter_emit(&output, &event);
2074 yaml_scalar_event_initialize(&event, NULL,
2075 (yaml_char_t *)YAML_STR_TAG,
2076 (yaml_char_t *)intf->intf_name,
2077 strlen(intf->intf_name), 1, 0,
2078 YAML_PLAIN_SCALAR_STYLE);
2079 rc = yaml_emitter_emit(&output, &event);
2083 yaml_mapping_end_event_initialize(&event);
2084 rc = yaml_emitter_emit(&output, &event);
2089 rc = yaml_add_ni_tunables(&output, tunables, nw_descr);
2098 yaml_scalar_event_initialize(&event, NULL,
2099 (yaml_char_t *)YAML_STR_TAG,
2100 (yaml_char_t *)"CPT",
2101 strlen("CPT"), 1, 0,
2102 YAML_PLAIN_SCALAR_STYLE);
2103 rc = yaml_emitter_emit(&output, &event);
2107 yaml_sequence_start_event_initialize(&event, NULL,
2108 (yaml_char_t *)YAML_SEQ_TAG,
2110 YAML_FLOW_SEQUENCE_STYLE);
2111 rc = yaml_emitter_emit(&output, &event);
2115 count = cfs_expr_list_values(global_cpts,
2116 LNET_MAX_SHOW_NUM_CPT,
2118 for (i = 0; i < count; i++) {
2119 char core[INT_STRING_LEN];
2121 snprintf(core, sizeof(core), "%u", cpt_array[i]);
2122 yaml_scalar_event_initialize(&event, NULL,
2123 (yaml_char_t *)YAML_STR_TAG,
2124 (yaml_char_t *)core,
2126 YAML_PLAIN_SCALAR_STYLE);
2127 rc = yaml_emitter_emit(&output, &event);
2132 yaml_sequence_end_event_initialize(&event);
2133 rc = yaml_emitter_emit(&output, &event);
2137 cfs_expr_list_free(global_cpts);
2141 yaml_mapping_end_event_initialize(&event);
2142 rc = yaml_emitter_emit(&output, &event);
2147 yaml_sequence_end_event_initialize(&event);
2148 rc = yaml_emitter_emit(&output, &event);
2152 yaml_mapping_end_event_initialize(&event);
2153 rc = yaml_emitter_emit(&output, &event);
2157 yaml_sequence_end_event_initialize(&event);
2158 rc = yaml_emitter_emit(&output, &event);
2162 yaml_mapping_end_event_initialize(&event);
2163 rc = yaml_emitter_emit(&output, &event);
2167 yaml_document_end_event_initialize(&event, 0);
2168 rc = yaml_emitter_emit(&output, &event);
2172 rc = yaml_emitter_close(&output);
2175 yaml_emitter_log_error(&output, stderr);
2178 yaml_document_t errmsg;
2180 rc = yaml_parser_load(&reply, &errmsg);
2181 if (rc == 1 && (flags & NLM_F_DUMP)) {
2182 yaml_emitter_t debug;
2184 rc = yaml_emitter_initialize(&debug);
2186 yaml_emitter_set_indent(&debug,
2187 LNET_DEFAULT_INDENT);
2188 yaml_emitter_set_output_file(&debug, stdout);
2189 rc = yaml_emitter_dump(&debug, &errmsg);
2191 yaml_emitter_delete(&debug);
2193 msg = yaml_parser_get_reader_error(&reply);
2195 yaml_document_delete(&errmsg);
2197 yaml_emitter_delete(&output);
2200 yaml_lnet_print_error(flags, "net", msg);
2203 yaml_parser_delete(&reply);
2206 return rc == 1 ? 0 : rc;
2209 static int jt_add_ni(int argc, char **argv)
2211 char *ip2net = NULL;
2212 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
2213 char *traffic_class = NULL;
2214 struct cYAML *err_rc = NULL;
2215 int rc, opt, cpt_rc = -1;
2216 struct lnet_dlc_network_descr nw_descr;
2217 struct cfs_expr_list *global_cpts = NULL;
2218 struct lnet_ioctl_config_lnd_tunables tunables;
2220 bool skip_mr_route_setup = false;
2221 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:T:";
2222 static const struct option long_options[] = {
2223 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
2224 { .name = "peer-buffer-credits",
2225 .has_arg = required_argument, .val = 'b' },
2226 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
2227 { .name = "if", .has_arg = required_argument, .val = 'i' },
2228 { .name = "skip-mr-route-setup",
2229 .has_arg = no_argument, .val = 'k' },
2230 { .name = "conns-per-peer",
2231 .has_arg = required_argument, .val = 'm' },
2232 { .name = "net", .has_arg = required_argument, .val = 'n' },
2233 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
2234 { .name = "credits", .has_arg = required_argument, .val = 'r' },
2235 { .name = "cpt", .has_arg = required_argument, .val = 's' },
2236 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
2237 { .name = "traffic-class", .has_arg = required_argument, .val = 'T' },
2239 char *net_id = NULL;
2241 memset(&tunables, 0, sizeof(tunables));
2242 lustre_lnet_init_nw_descr(&nw_descr);
2244 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
2248 while ((opt = getopt_long(argc, argv, short_options,
2249 long_options, NULL)) != -1) {
2252 rc = parse_long(optarg, &auth_key);
2260 rc = parse_long(optarg, &pbc);
2268 rc = parse_long(optarg, &pc);
2276 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2278 cYAML_build_error(-1, -1, "ni", "add",
2279 "bad interface list",
2285 skip_mr_route_setup = true;
2288 rc = parse_long(optarg, &cpp);
2297 nw_descr.nw_id = libcfs_str2net(optarg);
2304 rc = parse_long(optarg, &cre);
2312 cpt_rc = cfs_expr_list_parse(optarg,
2314 UINT_MAX, &global_cpts);
2317 rc = parse_long(optarg, &pto);
2325 traffic_class = optarg;
2326 if (strlen(traffic_class) == 0 ||
2327 strlen(traffic_class) >= LNET_MAX_STR_LEN) {
2328 cYAML_build_error(-1, -1, "ni", "add",
2329 "Invalid traffic-class argument",
2331 rc = LUSTRE_CFG_RC_BAD_PARAM;
2336 print_help(net_cmds, "net", "add");
2342 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
2343 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
2347 if (traffic_class && LNET_NETTYP(nw_descr.nw_id) == KFILND &&
2348 strlen(traffic_class) < LNET_MAX_STR_LEN) {
2349 strcpy(&tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0],
2355 if (LNET_NETTYP(nw_descr.nw_id) == SOCKLND && (cpp > -1)) {
2356 tunables.lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
2358 } else if (LNET_NETTYP(nw_descr.nw_id) == O2IBLND && (cpp > -1)) {
2359 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
2363 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
2364 tunables.lt_cmn.lct_peer_timeout = pto;
2365 tunables.lt_cmn.lct_peer_tx_credits = pc;
2366 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
2367 tunables.lt_cmn.lct_max_tx_credits = cre;
2371 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
2372 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
2374 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
2375 found ? &tunables : NULL,
2376 (cpt_rc == 0) ? global_cpts : NULL,
2377 LNET_GENL_VERSION, NLM_F_CREATE);
2379 if (rc == -EOPNOTSUPP)
2381 if (global_cpts != NULL)
2382 cfs_expr_list_free(global_cpts);
2383 if (rc == 0 && !skip_mr_route_setup)
2384 rc = lustre_lnet_setup_mrrouting(&err_rc);
2388 rc = lustre_lnet_config_ni(&nw_descr,
2389 (cpt_rc == 0) ? global_cpts: NULL,
2390 ip2net, (found) ? &tunables : NULL,
2393 if (global_cpts != NULL)
2394 cfs_expr_list_free(global_cpts);
2397 if (rc != LUSTRE_CFG_RC_NO_ERR)
2398 cYAML_print_tree2file(stderr, err_rc);
2400 cYAML_free_tree(err_rc);
2402 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
2404 rc = lustre_lnet_setup_mrrouting(&err_rc);
2406 if (rc != LUSTRE_CFG_RC_NO_ERR)
2407 cYAML_print_tree2file(stderr, err_rc);
2409 cYAML_free_tree(err_rc);
2415 static int jt_del_route(int argc, char **argv)
2417 char *network = NULL, *gateway = NULL;
2418 struct cYAML *err_rc = NULL;
2420 const char *const short_options = "n:g:";
2421 static const struct option long_options[] = {
2422 { .name = "net", .has_arg = required_argument, .val = 'n' },
2423 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2427 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
2431 while ((opt = getopt_long(argc, argv, short_options,
2432 long_options, NULL)) != -1) {
2441 print_help(route_cmds, "route", "del");
2447 rc = yaml_lnet_route(network, gateway, -1, -1, -1, LNET_GENL_VERSION,
2450 if (rc == -EOPNOTSUPP)
2455 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
2457 if (rc != LUSTRE_CFG_RC_NO_ERR)
2458 cYAML_print_tree2file(stderr, err_rc);
2460 cYAML_free_tree(err_rc);
2465 static int jt_del_ni(int argc, char **argv)
2467 struct cYAML *err_rc = NULL;
2469 struct lnet_dlc_network_descr nw_descr;
2470 const char *const short_options = "n:i:";
2471 static const struct option long_options[] = {
2472 { .name = "net", .has_arg = required_argument, .val = 'n' },
2473 { .name = "if", .has_arg = required_argument, .val = 'i' },
2475 char *net_id = NULL;
2477 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
2481 lustre_lnet_init_nw_descr(&nw_descr);
2483 while ((opt = getopt_long(argc, argv, short_options,
2484 long_options, NULL)) != -1) {
2487 nw_descr.nw_id = libcfs_str2net(optarg);
2491 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2493 cYAML_build_error(-1, -1, "ni", "add",
2494 "bad interface list",
2500 print_help(net_cmds, "net", "del");
2506 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, NULL,
2507 LNET_GENL_VERSION, 0);
2509 if (rc != -EOPNOTSUPP)
2513 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
2515 if (rc != LUSTRE_CFG_RC_NO_ERR)
2516 cYAML_print_tree2file(stderr, err_rc);
2518 cYAML_free_tree(err_rc);
2523 static int jt_show_route(int argc, char **argv)
2525 char *network = NULL, *gateway = NULL;
2526 long int hop = -1, prio = -1;
2527 int detail = 0, rc, opt;
2528 struct cYAML *err_rc = NULL, *show_rc = NULL;
2529 const char *const short_options = "c:n:g:p:v";
2530 static const struct option long_options[] = {
2531 { .name = "net", .has_arg = required_argument, .val = 'n' },
2532 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2533 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
2534 { .name = "hop", .has_arg = required_argument, .val = 'c' },
2535 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2536 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
2540 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
2544 while ((opt = getopt_long(argc, argv, short_options,
2545 long_options, NULL)) != -1) {
2554 rc = parse_long(optarg, &hop);
2562 rc = parse_long(optarg, &prio);
2573 print_help(route_cmds, "route", "show");
2579 rc = yaml_lnet_route(network, gateway, hop, prio, -1,
2580 detail, NLM_F_DUMP);
2582 if (rc == -EOPNOTSUPP)
2587 rc = lustre_lnet_show_route(network, gateway, hop, prio,
2589 &show_rc, &err_rc, false);
2591 if (rc != LUSTRE_CFG_RC_NO_ERR)
2592 cYAML_print_tree2file(stderr, err_rc);
2594 cYAML_print_tree(show_rc);
2596 cYAML_free_tree(err_rc);
2597 cYAML_free_tree(show_rc);
2602 static int set_value_helper(int argc, char **argv,
2603 int (*cb)(int, bool, char*, int, int, struct cYAML**))
2606 long int healthv = -1;
2608 long int state = -1;
2610 struct cYAML *err_rc = NULL;
2611 const char *const short_options = "t:n:s:a";
2612 static const struct option long_options[] = {
2613 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2614 { .name = "health", .has_arg = required_argument, .val = 't' },
2615 { .name = "state", .has_arg = required_argument, .val = 's' },
2616 { .name = "all", .has_arg = no_argument, .val = 'a' },
2620 while ((opt = getopt_long(argc, argv, short_options,
2621 long_options, NULL)) != -1) {
2627 if (parse_long(optarg, &healthv) != 0)
2631 if (parse_long(optarg, &state) != 0)
2642 rc = cb(healthv, all, nid, state, -1, &err_rc);
2643 if (rc != LUSTRE_CFG_RC_NO_ERR)
2644 cYAML_print_tree2file(stderr, err_rc);
2646 cYAML_free_tree(err_rc);
2651 static int jt_set_ni_value(int argc, char **argv)
2654 long int healthv = -1, cpp = -1;
2657 struct cYAML *err_rc = NULL;
2659 const char *const short_options = "a:m:n:t:";
2660 static const struct option long_options[] = {
2661 { .name = "all", .has_arg = no_argument, .val = 'a' },
2662 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2663 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2664 { .name = "health", .has_arg = required_argument, .val = 't' },
2667 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2671 while ((opt = getopt_long(argc, argv, short_options,
2672 long_options, NULL)) != -1) {
2678 rc = parse_long(optarg, &cpp);
2689 if (parse_long(optarg, &healthv) != 0) {
2701 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2704 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2707 if (rc != LUSTRE_CFG_RC_NO_ERR)
2708 cYAML_print_tree2file(stderr, err_rc);
2710 cYAML_free_tree(err_rc);
2715 static int yaml_lnet_peer_display(yaml_parser_t *reply, bool list_only)
2717 yaml_emitter_t debug;
2720 rc = yaml_emitter_initialize(&debug);
2724 yaml_emitter_set_indent(&debug, 6);
2725 yaml_emitter_set_output_file(&debug, stdout);
2734 rc = yaml_parser_parse(reply, &event);
2736 goto report_reply_error;
2738 if (event.type != YAML_SCALAR_EVENT)
2741 value = (char *)event.data.scalar.value;
2742 if (strcmp(value, "peer") == 0) {
2743 yaml_event_delete(&event);
2745 yaml_scalar_event_initialize(&event, NULL,
2746 (yaml_char_t *)YAML_STR_TAG,
2747 (yaml_char_t *)"peer list",
2748 strlen("peer list"),
2750 YAML_PLAIN_SCALAR_STYLE);
2751 } else if (strcmp(value, "primary nid") == 0) {
2752 yaml_event_delete(&event);
2754 yaml_scalar_event_initialize(&event, NULL,
2755 (yaml_char_t *)YAML_STR_TAG,
2756 (yaml_char_t *)"nid",
2759 YAML_PLAIN_SCALAR_STYLE);
2760 rc = yaml_emitter_emit(&debug, &event);
2764 /* Now print NID address */
2765 rc = yaml_parser_parse(reply, &event);
2767 goto report_reply_error;
2769 rc = yaml_emitter_emit(&debug, &event);
2774 while (event.type != YAML_MAPPING_END_EVENT) {
2775 rc = yaml_parser_parse(reply, &event);
2777 goto report_reply_error;
2780 /* we can have map end, seq end, map end or
2781 * just map end event. If we see seq end event
2782 * then skip to next mapping end event
2784 rc = yaml_parser_parse(reply, &event);
2786 goto report_reply_error;
2788 if (event.type == YAML_SEQUENCE_END_EVENT) {
2789 yaml_event_delete(&event);
2791 rc = yaml_parser_parse(reply, &event);
2793 goto report_reply_error;
2797 rc = yaml_emitter_emit(&debug, &event);
2801 done = (event.type == YAML_DOCUMENT_END_EVENT);
2804 yaml_document_t errmsg;
2806 rc = yaml_parser_load(reply, &errmsg);
2808 rc = yaml_emitter_dump(&debug, &errmsg);
2809 yaml_document_delete(&errmsg);
2813 yaml_emitter_log_error(&debug, stderr);
2815 yaml_emitter_delete(&debug);
2820 static int yaml_lnet_peer(char *prim_nid, char *nidstr, bool disable_mr,
2821 int health_value, int state, bool list_only,
2822 int version, int flags)
2824 struct nl_sock *sk = NULL;
2825 const char *msg = NULL;
2826 yaml_emitter_t output;
2827 yaml_parser_t reply;
2831 /* Create Netlink emitter to send request to kernel */
2832 sk = nl_socket_alloc();
2836 /* Setup parser to receive Netlink packets */
2837 rc = yaml_parser_initialize(&reply);
2843 rc = yaml_parser_set_input_netlink(&reply, sk, false);
2845 msg = yaml_parser_get_reader_error(&reply);
2849 /* Create Netlink emitter to send request to kernel */
2850 rc = yaml_emitter_initialize(&output);
2852 msg = "failed to initialize emitter";
2856 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
2857 version, LNET_CMD_PEERS, flags);
2861 yaml_emitter_open(&output);
2862 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
2863 rc = yaml_emitter_emit(&output, &event);
2867 yaml_mapping_start_event_initialize(&event, NULL,
2868 (yaml_char_t *)YAML_MAP_TAG,
2869 1, YAML_ANY_MAPPING_STYLE);
2870 rc = yaml_emitter_emit(&output, &event);
2874 yaml_scalar_event_initialize(&event, NULL,
2875 (yaml_char_t *)YAML_STR_TAG,
2876 (yaml_char_t *)"peer",
2877 strlen("peer"), 1, 0,
2878 YAML_PLAIN_SCALAR_STYLE);
2879 rc = yaml_emitter_emit(&output, &event);
2884 yaml_sequence_start_event_initialize(&event, NULL,
2885 (yaml_char_t *)YAML_SEQ_TAG,
2887 YAML_BLOCK_SEQUENCE_STYLE);
2888 rc = yaml_emitter_emit(&output, &event);
2892 yaml_mapping_start_event_initialize(&event, NULL,
2893 (yaml_char_t *)YAML_MAP_TAG,
2895 YAML_BLOCK_MAPPING_STYLE);
2896 rc = yaml_emitter_emit(&output, &event);
2900 yaml_scalar_event_initialize(&event, NULL,
2901 (yaml_char_t *)YAML_STR_TAG,
2902 (yaml_char_t *)"primary nid",
2903 strlen("primary nid"), 1, 0,
2904 YAML_PLAIN_SCALAR_STYLE);
2905 rc = yaml_emitter_emit(&output, &event);
2909 yaml_scalar_event_initialize(&event, NULL,
2910 (yaml_char_t *)YAML_STR_TAG,
2911 (yaml_char_t *)prim_nid,
2912 strlen(prim_nid), 1, 0,
2913 YAML_PLAIN_SCALAR_STYLE);
2914 rc = yaml_emitter_emit(&output, &event);
2919 yaml_scalar_event_initialize(&event, NULL,
2920 (yaml_char_t *)YAML_STR_TAG,
2921 (yaml_char_t *)"Multi-Rail",
2922 strlen("Multi-Rail"), 1, 0,
2923 YAML_PLAIN_SCALAR_STYLE);
2924 rc = yaml_emitter_emit(&output, &event);
2928 yaml_scalar_event_initialize(&event, NULL,
2929 (yaml_char_t *)YAML_BOOL_TAG,
2930 (yaml_char_t *)"False",
2931 strlen("False"), 1, 0,
2932 YAML_PLAIN_SCALAR_STYLE);
2933 rc = yaml_emitter_emit(&output, &event);
2939 char peer_state[INT_STRING_LEN];
2941 yaml_scalar_event_initialize(&event, NULL,
2942 (yaml_char_t *)YAML_STR_TAG,
2943 (yaml_char_t *)"peer state",
2944 strlen("peer state"), 1, 0,
2945 YAML_PLAIN_SCALAR_STYLE);
2946 rc = yaml_emitter_emit(&output, &event);
2950 snprintf(peer_state, sizeof(peer_state), "%d", state);
2951 yaml_scalar_event_initialize(&event, NULL,
2952 (yaml_char_t *)YAML_INT_TAG,
2953 (yaml_char_t *)peer_state,
2954 strlen(peer_state), 1, 0,
2955 YAML_PLAIN_SCALAR_STYLE);
2956 rc = yaml_emitter_emit(&output, &event);
2961 if (!nidstr && health_value == -1)
2964 yaml_scalar_event_initialize(&event, NULL,
2965 (yaml_char_t *)YAML_STR_TAG,
2966 (yaml_char_t *)"peer ni",
2967 strlen("peer ni"), 1, 0,
2968 YAML_PLAIN_SCALAR_STYLE);
2969 rc = yaml_emitter_emit(&output, &event);
2973 yaml_sequence_start_event_initialize(&event, NULL,
2974 (yaml_char_t *)YAML_SEQ_TAG,
2975 1, YAML_BLOCK_SEQUENCE_STYLE);
2976 rc = yaml_emitter_emit(&output, &event);
2981 struct nid_node head, *entry;
2984 /* If we have LNET_ANY_NID and its NLM_F_REPLACE we
2985 * treat it as the all flag case for lnetctl peer set
2987 if (strcmp(nidstr, "<?>") == 0) {
2988 yaml_mapping_start_event_initialize(&event, NULL,
2989 (yaml_char_t *)YAML_MAP_TAG,
2990 1, YAML_BLOCK_MAPPING_STYLE);
2991 rc = yaml_emitter_emit(&output, &event);
2995 yaml_scalar_event_initialize(&event, NULL,
2996 (yaml_char_t *)YAML_STR_TAG,
2997 (yaml_char_t *)"nid",
2998 strlen("nid"), 1, 0,
2999 YAML_PLAIN_SCALAR_STYLE);
3000 rc = yaml_emitter_emit(&output, &event);
3004 yaml_scalar_event_initialize(&event, NULL,
3005 (yaml_char_t *)YAML_STR_TAG,
3006 (yaml_char_t *)nidstr,
3007 strlen(nidstr), 1, 0,
3008 YAML_PLAIN_SCALAR_STYLE);
3009 rc = yaml_emitter_emit(&output, &event);
3013 yaml_mapping_end_event_initialize(&event);
3014 rc = yaml_emitter_emit(&output, &event);
3021 NL_INIT_LIST_HEAD(&head.children);
3022 nl_init_list_head(&head.list);
3023 rc = lustre_lnet_parse_nid_range(&head, nidstr, &msg);
3025 fprintf(stdout, "can't parse nidrange: \"%s\"\n", nidstr);
3026 lustre_lnet_free_list(&head);
3027 yaml_emitter_delete(&output);
3033 if (nl_list_empty(&head.children)) {
3034 lustre_lnet_free_list(&head);
3035 yaml_emitter_delete(&output);
3036 msg = "Unable to parse nidlist: did not expand to any nids";
3041 rc = 1; /* one means its working */
3043 nl_list_for_each_entry(entry, &head.children, list) {
3044 char *nid = entry->nidstr;
3046 if (count++ > LNET_MAX_NIDS_PER_PEER) {
3047 lustre_lnet_free_list(&head);
3048 yaml_emitter_delete(&output);
3049 msg = "Unable to parse nidlist: specifies more NIDs than allowed";
3055 yaml_mapping_start_event_initialize(&event, NULL,
3056 (yaml_char_t *)YAML_MAP_TAG,
3057 1, YAML_BLOCK_MAPPING_STYLE);
3058 rc = yaml_emitter_emit(&output, &event);
3062 yaml_scalar_event_initialize(&event, NULL,
3063 (yaml_char_t *)YAML_STR_TAG,
3064 (yaml_char_t *)"nid",
3065 strlen("nid"), 1, 0,
3066 YAML_PLAIN_SCALAR_STYLE);
3067 rc = yaml_emitter_emit(&output, &event);
3071 yaml_scalar_event_initialize(&event, NULL,
3072 (yaml_char_t *)YAML_STR_TAG,
3075 YAML_PLAIN_SCALAR_STYLE);
3076 rc = yaml_emitter_emit(&output, &event);
3080 yaml_mapping_end_event_initialize(&event);
3081 rc = yaml_emitter_emit(&output, &event);
3085 lustre_lnet_free_list(&head);
3088 if (health_value >= 0) {
3089 char health[INT_STRING_LEN];
3091 /* Create the mapping for 'health stats'. The value field for
3092 * the mapping is not provided so its treated as a empty string.
3094 yaml_mapping_start_event_initialize(&event, NULL,
3095 (yaml_char_t *)YAML_MAP_TAG,
3096 1, YAML_BLOCK_MAPPING_STYLE);
3097 rc = yaml_emitter_emit(&output, &event);
3101 yaml_scalar_event_initialize(&event, NULL,
3102 (yaml_char_t *)YAML_STR_TAG,
3103 (yaml_char_t *)"health stats",
3104 strlen("health stats"), 1, 0,
3105 YAML_PLAIN_SCALAR_STYLE);
3106 rc = yaml_emitter_emit(&output, &event);
3110 /* Setup all mappings for data related to the 'health stats' */
3111 yaml_mapping_start_event_initialize(&event, NULL,
3112 (yaml_char_t *)YAML_MAP_TAG,
3113 1, YAML_BLOCK_MAPPING_STYLE);
3114 rc = yaml_emitter_emit(&output, &event);
3118 yaml_scalar_event_initialize(&event, NULL,
3119 (yaml_char_t *)YAML_STR_TAG,
3120 (yaml_char_t *)"health value",
3121 strlen("health value"), 1, 0,
3122 YAML_PLAIN_SCALAR_STYLE);
3123 rc = yaml_emitter_emit(&output, &event);
3127 snprintf(health, sizeof(health), "%d", health_value);
3128 yaml_scalar_event_initialize(&event, NULL,
3129 (yaml_char_t *)YAML_INT_TAG,
3130 (yaml_char_t *)health,
3131 strlen(health), 1, 0,
3132 YAML_PLAIN_SCALAR_STYLE);
3133 rc = yaml_emitter_emit(&output, &event);
3137 yaml_mapping_end_event_initialize(&event);
3138 rc = yaml_emitter_emit(&output, &event);
3142 yaml_mapping_end_event_initialize(&event);
3143 rc = yaml_emitter_emit(&output, &event);
3148 yaml_sequence_end_event_initialize(&event);
3149 rc = yaml_emitter_emit(&output, &event);
3153 yaml_mapping_end_event_initialize(&event);
3154 rc = yaml_emitter_emit(&output, &event);
3158 yaml_sequence_end_event_initialize(&event);
3159 rc = yaml_emitter_emit(&output, &event);
3163 yaml_scalar_event_initialize(&event, NULL,
3164 (yaml_char_t *)YAML_STR_TAG,
3167 YAML_PLAIN_SCALAR_STYLE);
3168 rc = yaml_emitter_emit(&output, &event);
3173 yaml_mapping_end_event_initialize(&event);
3174 rc = yaml_emitter_emit(&output, &event);
3178 yaml_document_end_event_initialize(&event, 0);
3179 rc = yaml_emitter_emit(&output, &event);
3183 rc = yaml_emitter_close(&output);
3186 yaml_emitter_log_error(&output, stderr);
3189 rc = yaml_lnet_peer_display(&reply, list_only);
3191 msg = yaml_parser_get_reader_error(&reply);
3192 /* If we didn't find any peers just be silent */
3193 if (msg && strcmp(msg, "No peers found") == 0)
3198 yaml_emitter_delete(&output);
3201 yaml_lnet_print_error(flags, "peer", msg);
3204 yaml_parser_delete(&reply);
3207 return rc == 1 ? 0 : rc;
3210 int yaml_lnet_config_peer_ni_healthv(int healthv, bool all, char *lpni_nid,
3211 int state, int seq_no, struct cYAML **err_rc)
3215 rc = yaml_lnet_peer(lpni_nid ? lpni_nid : "<?>", all ? "<?>" : NULL,
3216 false, healthv, state, false, LNET_GENL_VERSION,
3219 if (rc == -EOPNOTSUPP)
3225 rc = lustre_lnet_config_peer_ni_healthv(healthv, all, lpni_nid,
3228 rc = lustre_lnet_set_peer_state(state, lpni_nid, -1, err_rc);
3229 if (rc != LUSTRE_CFG_RC_NO_ERR)
3230 cYAML_print_tree2file(stderr, *err_rc);
3232 cYAML_free_tree(*err_rc);
3237 static int jt_set_peer_ni_value(int argc, char **argv)
3239 int rc = check_cmd(peer_cmds, "peer", "set", 0, argc, argv);
3244 return set_value_helper(argc, argv, yaml_lnet_config_peer_ni_healthv);
3247 static int jt_show_recovery(int argc, char **argv)
3250 struct cYAML *err_rc = NULL, *show_rc = NULL;
3251 const char *const short_options = "lp";
3252 static const struct option long_options[] = {
3253 { .name = "local", .has_arg = no_argument, .val = 'l' },
3254 { .name = "peer", .has_arg = no_argument, .val = 'p' },
3257 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
3261 while ((opt = getopt_long(argc, argv, short_options,
3262 long_options, NULL)) != -1) {
3265 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
3268 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
3275 if (rc != LUSTRE_CFG_RC_NO_ERR)
3276 cYAML_print_tree2file(stderr, err_rc);
3278 cYAML_print_tree(show_rc);
3280 cYAML_free_tree(err_rc);
3281 cYAML_free_tree(show_rc);
3286 static int jt_show_peer_debug_info(int argc, char **argv)
3289 struct cYAML *err_rc = NULL;
3290 char *peer_nid = optarg;
3291 const char *const short_opts = "k";
3292 const struct option long_opts[] = {
3293 { .name = "nid", .has_arg = required_argument, .val = 'k' },
3296 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
3301 while ((opt = getopt_long(argc, argv, short_opts,
3302 long_opts, NULL)) != -1) {
3312 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
3314 if (rc != LUSTRE_CFG_RC_NO_ERR)
3315 cYAML_print_tree2file(stderr, err_rc);
3317 cYAML_free_tree(err_rc);
3322 static int jt_show_net(int argc, char **argv)
3324 char *network = NULL;
3326 struct cYAML *err_rc = NULL, *show_rc = NULL;
3327 long int detail = 0;
3328 const char *const short_options = "n:v";
3329 static const struct option long_options[] = {
3330 { .name = "net", .has_arg = required_argument, .val = 'n' },
3331 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3334 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
3338 while ((opt = getopt_long(argc, argv, short_options,
3339 long_options, NULL)) != -1) {
3345 if ((!optarg) && (argv[optind] != NULL) &&
3346 (argv[optind][0] != '-')) {
3347 if (parse_long(argv[optind++], &detail) != 0)
3354 print_help(net_cmds, "net", "show");
3360 rc = yaml_lnet_config_ni(network, NULL, NULL, NULL, NULL,
3361 detail, NLM_F_DUMP);
3363 if (rc != -EOPNOTSUPP)
3367 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
3370 if (rc != LUSTRE_CFG_RC_NO_ERR)
3371 cYAML_print_tree2file(stderr, err_rc);
3373 cYAML_print_tree(show_rc);
3375 cYAML_free_tree(err_rc);
3376 cYAML_free_tree(show_rc);
3381 static int jt_show_routing(int argc, char **argv)
3383 struct cYAML *err_rc = NULL, *show_rc = NULL;
3386 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
3390 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
3392 if (rc != LUSTRE_CFG_RC_NO_ERR)
3393 cYAML_print_tree2file(stderr, err_rc);
3395 cYAML_print_tree(show_rc);
3397 cYAML_free_tree(err_rc);
3398 cYAML_free_tree(show_rc);
3403 static int jt_show_stats(int argc, char **argv)
3406 struct cYAML *show_rc = NULL, *err_rc = NULL;
3408 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
3412 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
3414 if (rc != LUSTRE_CFG_RC_NO_ERR)
3415 cYAML_print_tree2file(stderr, err_rc);
3417 cYAML_print_tree(show_rc);
3419 cYAML_free_tree(err_rc);
3420 cYAML_free_tree(show_rc);
3425 static int jt_show_udsp(int argc, char **argv)
3429 struct cYAML *err_rc = NULL, *show_rc = NULL;
3431 const char *const short_options = "i:";
3432 static const struct option long_options[] = {
3433 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3437 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
3441 while ((opt = getopt_long(argc, argv, short_options,
3442 long_options, NULL)) != -1) {
3445 rc = parse_long(optarg, &idx);
3446 if (rc != 0 || idx < -1) {
3447 printf("Invalid index \"%s\"\n", optarg);
3452 print_help(net_cmds, "net", "show");
3458 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
3460 if (rc != LUSTRE_CFG_RC_NO_ERR)
3461 cYAML_print_tree2file(stderr, err_rc);
3463 cYAML_print_tree(show_rc);
3465 cYAML_free_tree(err_rc);
3466 cYAML_free_tree(show_rc);
3471 static int jt_show_global(int argc, char **argv)
3474 struct cYAML *show_rc = NULL, *err_rc = NULL;
3476 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
3480 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3481 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3482 cYAML_print_tree2file(stderr, err_rc);
3486 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3487 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3488 cYAML_print_tree2file(stderr, err_rc);
3492 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3493 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3494 cYAML_print_tree2file(stderr, err_rc);
3498 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3499 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3500 cYAML_print_tree2file(stderr, err_rc);
3504 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3505 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3506 cYAML_print_tree2file(stderr, err_rc);
3510 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3511 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3512 cYAML_print_tree2file(stderr, err_rc);
3516 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3517 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3518 cYAML_print_tree2file(stderr, err_rc);
3522 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3523 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3524 cYAML_print_tree2file(stderr, err_rc);
3528 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3529 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3530 cYAML_print_tree2file(stderr, err_rc);
3534 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3535 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3536 cYAML_print_tree2file(stderr, err_rc);
3540 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3541 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3542 cYAML_print_tree2file(stderr, err_rc);
3546 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3547 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3548 cYAML_print_tree2file(stderr, err_rc);
3552 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3553 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3554 cYAML_print_tree2file(stderr, err_rc);
3559 cYAML_print_tree(show_rc);
3562 cYAML_free_tree(err_rc);
3563 cYAML_free_tree(show_rc);
3568 static int jt_lnet(int argc, char **argv)
3572 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
3576 return cfs_parser(argc, argv, lnet_cmds);
3579 static int jt_route(int argc, char **argv)
3583 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
3587 return cfs_parser(argc, argv, route_cmds);
3590 static int jt_net(int argc, char **argv)
3594 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
3598 return cfs_parser(argc, argv, net_cmds);
3601 static int jt_routing(int argc, char **argv)
3605 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
3609 return cfs_parser(argc, argv, routing_cmds);
3612 static int jt_stats(int argc, char **argv)
3616 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
3620 return cfs_parser(argc, argv, stats_cmds);
3623 static int jt_debug(int argc, char **argv)
3627 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
3631 return cfs_parser(argc, argv, debug_cmds);
3634 static int jt_global(int argc, char **argv)
3638 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
3642 return cfs_parser(argc, argv, global_cmds);
3645 static int jt_peers(int argc, char **argv)
3649 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
3653 return cfs_parser(argc, argv, peer_cmds);
3656 static int jt_set(int argc, char **argv)
3660 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
3664 return cfs_parser(argc, argv, set_cmds);
3667 static int jt_udsp(int argc, char **argv)
3671 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
3675 return cfs_parser(argc, argv, udsp_cmds);
3678 static int jt_import(int argc, char **argv)
3681 struct cYAML *err_rc = NULL;
3682 struct cYAML *show_rc = NULL;
3683 int rc = 0, return_rc = 0, opt, opt_found = 0;
3686 const char *const short_options = "adseh";
3687 static const struct option long_options[] = {
3688 { .name = "add", .has_arg = no_argument, .val = 'a' },
3689 { .name = "del", .has_arg = no_argument, .val = 'd' },
3690 { .name = "show", .has_arg = no_argument, .val = 's' },
3691 { .name = "exec", .has_arg = no_argument, .val = 'e' },
3692 { .name = "help", .has_arg = no_argument, .val = 'h' },
3695 while ((opt = getopt_long(argc, argv, short_options,
3696 long_options, NULL)) != -1) {
3710 printf("import FILE\n"
3711 "import < FILE : import a file\n"
3712 "\t--add: add configuration\n"
3713 "\t--del: delete configuration\n"
3714 "\t--show: show configuration\n"
3715 "\t--exec: execute command\n"
3716 "\t--help: display this help\n"
3717 "If no command option is given then --add"
3718 " is assumed by default\n");
3725 /* grab the file name if one exists */
3726 if (opt_found && argc == 3)
3728 else if (!opt_found && argc == 2)
3733 rc = lustre_yaml_config(file, &err_rc);
3734 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3735 cYAML_print_tree(show_rc);
3736 cYAML_free_tree(show_rc);
3739 rc = lustre_yaml_del(file, &err_rc);
3742 rc = lustre_yaml_show(file, &show_rc, &err_rc);
3743 cYAML_print_tree(show_rc);
3744 cYAML_free_tree(show_rc);
3747 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3748 cYAML_print_tree(show_rc);
3749 cYAML_free_tree(show_rc);
3753 if (rc || return_rc) {
3754 cYAML_print_tree2file(stderr, err_rc);
3755 cYAML_free_tree(err_rc);
3761 static int jt_export(int argc, char **argv)
3763 struct cYAML *show_rc = NULL;
3764 struct cYAML *err_rc = NULL;
3768 bool backup = false;
3771 const char *const short_options = "bh";
3772 static const struct option long_options[] = {
3773 { .name = "backup", .has_arg = no_argument, .val = 'b' },
3774 { .name = "help", .has_arg = no_argument, .val = 'h' },
3777 while ((opt = getopt_long(argc, argv, short_options,
3778 long_options, NULL)) != -1) {
3785 printf("export > FILE.yaml : export configuration\n"
3786 "\t--backup: export only what's necessary for reconfig\n"
3787 "\t--help: display this help\n");
3792 if (backup && argc >= 3)
3794 else if (!backup && argc >= 2)
3800 f = fopen(file, "w");
3805 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
3806 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3807 cYAML_print_tree2file(stderr, err_rc);
3808 cYAML_free_tree(err_rc);
3812 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
3814 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3815 cYAML_print_tree2file(stderr, err_rc);
3816 cYAML_free_tree(err_rc);
3820 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
3821 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3822 cYAML_print_tree2file(stderr, err_rc);
3823 cYAML_free_tree(err_rc);
3827 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
3828 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3829 cYAML_print_tree2file(stderr, err_rc);
3830 cYAML_free_tree(err_rc);
3834 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3835 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3836 cYAML_print_tree2file(stderr, err_rc);
3837 cYAML_free_tree(err_rc);
3841 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3842 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3843 cYAML_print_tree2file(stderr, err_rc);
3844 cYAML_free_tree(err_rc);
3848 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3849 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3850 cYAML_print_tree2file(stderr, err_rc);
3851 cYAML_free_tree(err_rc);
3855 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3856 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3857 cYAML_print_tree2file(stderr, err_rc);
3858 cYAML_free_tree(err_rc);
3862 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3863 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3864 cYAML_print_tree2file(stderr, err_rc);
3868 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3869 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3870 cYAML_print_tree2file(stderr, err_rc);
3874 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3875 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3876 cYAML_print_tree2file(stderr, err_rc);
3880 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3881 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3882 cYAML_print_tree2file(stderr, err_rc);
3886 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3887 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3888 cYAML_print_tree2file(stderr, err_rc);
3892 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3893 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3894 cYAML_print_tree2file(stderr, err_rc);
3898 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3899 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3900 cYAML_print_tree2file(stderr, err_rc);
3901 cYAML_free_tree(err_rc);
3905 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3906 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3907 cYAML_print_tree2file(stderr, err_rc);
3908 cYAML_free_tree(err_rc);
3912 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3913 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3914 cYAML_print_tree2file(stderr, err_rc);
3915 cYAML_free_tree(err_rc);
3919 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
3920 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3921 cYAML_print_tree2file(stderr, err_rc);
3922 cYAML_free_tree(err_rc);
3926 if (show_rc != NULL) {
3927 cYAML_print_tree2file(f, show_rc);
3928 cYAML_free_tree(show_rc);
3937 static int jt_peer_nid_common(int argc, char **argv, int cmd)
3939 int flags = cmd == LNETCTL_ADD_CMD ? NLM_F_CREATE : 0;
3940 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
3942 char *prim_nid = NULL, *nidstr = NULL;
3943 char err_str[LNET_MAX_STR_LEN] = "Error";
3944 struct cYAML *err_rc = NULL;
3946 const char *const short_opts = "k:m:n:f:l";
3947 const struct option long_opts[] = {
3948 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
3949 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
3950 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3951 { .name = "force", .has_arg = no_argument, .val = 'f' },
3952 { .name = "lock_prim", .has_arg = no_argument, .val = 'l' },
3955 rc = check_cmd(peer_cmds, "peer",
3956 cmd == LNETCTL_ADD_CMD ? "add" : "del", 2, argc, argv);
3960 while ((opt = getopt_long(argc, argv, short_opts,
3961 long_opts, NULL)) != -1) {
3970 if (cmd == LNETCTL_DEL_CMD) {
3971 rc = LUSTRE_CFG_RC_BAD_PARAM;
3972 snprintf(err_str, LNET_MAX_STR_LEN,
3973 "Unrecognized option '-%c'", opt);
3979 if (cmd == LNETCTL_ADD_CMD) {
3980 rc = LUSTRE_CFG_RC_BAD_PARAM;
3981 snprintf(err_str, LNET_MAX_STR_LEN,
3982 "Unrecognized option '-%c'", opt);
3985 flags |= NLM_F_EXCL;
3988 if (cmd == LNETCTL_DEL_CMD) {
3989 rc = LUSTRE_CFG_RC_BAD_PARAM;
3990 snprintf(err_str, LNET_MAX_STR_LEN,
3991 "Unrecognized option '-%c'", opt);
3994 flags |= NLM_F_EXCL;
3997 print_help(peer_cmds, "peer",
3998 cmd == LNETCTL_ADD_CMD ? "add" : "del");
4004 rc = yaml_lnet_peer(prim_nid, nidstr, !is_mr, -1, -1, false,
4005 LNET_GENL_VERSION, flags);
4007 if (rc == -EOPNOTSUPP)
4012 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
4013 force_lock, -1, &err_rc);
4014 if (rc != LUSTRE_CFG_RC_NO_ERR)
4018 cYAML_build_error(rc, -1, "peer",
4019 cmd == LNETCTL_ADD_CMD ? "add" : "del",
4023 if (rc != LUSTRE_CFG_RC_NO_ERR)
4024 cYAML_print_tree2file(stderr, err_rc);
4026 cYAML_free_tree(err_rc);
4031 static int jt_add_peer_nid(int argc, char **argv)
4033 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
4036 static int jt_del_peer_nid(int argc, char **argv)
4038 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
4041 static int jt_show_peer(int argc, char **argv)
4045 struct cYAML *err_rc = NULL, *show_rc = NULL;
4046 long int detail = 0;
4047 const char *const short_opts = "hn:v::";
4048 const struct option long_opts[] = {
4049 { .name = "help", .has_arg = no_argument, .val = 'h' },
4050 { .name = "nid", .has_arg = required_argument, .val = 'n' },
4051 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
4055 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
4059 while ((opt = getopt_long(argc, argv, short_opts,
4060 long_opts, NULL)) != -1) {
4066 if ((!optarg) && (argv[optind] != NULL) &&
4067 (argv[optind][0] != '-')) {
4068 if (parse_long(argv[optind++], &detail) != 0)
4075 print_help(peer_cmds, "peer", "show");
4081 rc = yaml_lnet_peer(nid, NULL, false, -1, -1, false, detail,
4084 if (rc == -EOPNOTSUPP)
4089 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
4092 if (rc != LUSTRE_CFG_RC_NO_ERR)
4093 cYAML_print_tree2file(stderr, err_rc);
4095 cYAML_print_tree(show_rc);
4097 cYAML_free_tree(err_rc);
4098 cYAML_free_tree(show_rc);
4103 static int jt_list_peer(int argc, char **argv)
4105 struct cYAML *err_rc = NULL, *list_rc = NULL;
4108 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
4112 rc = yaml_lnet_peer(NULL, NULL, false, -1, -1, true, 0, NLM_F_DUMP);
4114 if (rc == -EOPNOTSUPP)
4120 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
4121 if (rc != LUSTRE_CFG_RC_NO_ERR)
4122 cYAML_print_tree2file(stderr, err_rc);
4124 cYAML_print_tree(list_rc);
4126 cYAML_free_tree(err_rc);
4127 cYAML_free_tree(list_rc);
4132 static int yaml_lnet_ping_display(yaml_parser_t *reply)
4134 yaml_emitter_t debug;
4139 rc = yaml_emitter_initialize(&debug);
4141 yaml_emitter_set_output_file(&debug, stdout);
4148 rc = yaml_parser_parse(reply, &event);
4150 goto report_reply_error;
4152 if (event.type != YAML_SCALAR_EVENT) {
4153 rc = yaml_emitter_emit(&debug, &event);
4157 done = (event.type == YAML_DOCUMENT_END_EVENT);
4161 if (strcmp((char *)event.data.scalar.value, "errno") == 0) {
4162 rc = yaml_emitter_emit(&debug, &event);
4166 rc = yaml_parser_parse(reply, &event);
4168 goto report_reply_error;
4170 rc = parse_long((char *)event.data.scalar.value,
4173 goto report_reply_error;
4175 rc = yaml_emitter_emit(&debug, &event);
4180 } else if (error != 0 &&
4181 strcmp((char *)event.data.scalar.value,
4183 rc = yaml_emitter_emit(&debug, &event);
4187 rc = yaml_parser_parse(reply, &event);
4189 goto report_reply_error;
4191 if (strncmp((char *)event.data.scalar.value,
4192 "failed to ", strlen("failed to ")) == 0) {
4195 snprintf(err, sizeof(err), "%s: %s",
4196 (char *)event.data.scalar.value,
4198 yaml_scalar_event_initialize(&event, NULL,
4199 (yaml_char_t *)YAML_STR_TAG,
4202 YAML_PLAIN_SCALAR_STYLE);
4204 rc = yaml_emitter_emit(&debug, &event);
4210 rc = yaml_emitter_emit(&debug, &event);
4217 yaml_emitter_log_error(&debug, stderr);
4219 yaml_emitter_delete(&debug);
4221 return rc2 ? rc2 : rc;
4224 static int yaml_lnet_ping(char *group, int timeout, char *src_nidstr,
4225 int start, int end, char **nids, int flags)
4227 struct nl_sock *sk = NULL;
4228 const char *msg = NULL;
4229 yaml_emitter_t output;
4230 yaml_parser_t reply;
4234 /* Create Netlink emitter to send request to kernel */
4235 sk = nl_socket_alloc();
4239 /* Setup parser to receive Netlink packets */
4240 rc = yaml_parser_initialize(&reply);
4246 rc = yaml_parser_set_input_netlink(&reply, sk, false);
4248 msg = yaml_parser_get_reader_error(&reply);
4252 /* Create Netlink emitter to send request to kernel */
4253 rc = yaml_emitter_initialize(&output);
4255 msg = "failed to initialize emitter";
4259 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
4260 LNET_GENL_VERSION, LNET_CMD_PING,
4265 yaml_emitter_open(&output);
4266 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
4267 rc = yaml_emitter_emit(&output, &event);
4271 yaml_mapping_start_event_initialize(&event, NULL,
4272 (yaml_char_t *)YAML_MAP_TAG,
4273 1, YAML_ANY_MAPPING_STYLE);
4274 rc = yaml_emitter_emit(&output, &event);
4278 yaml_scalar_event_initialize(&event, NULL,
4279 (yaml_char_t *)YAML_STR_TAG,
4280 (yaml_char_t *)group,
4281 strlen(group), 1, 0,
4282 YAML_PLAIN_SCALAR_STYLE);
4283 rc = yaml_emitter_emit(&output, &event);
4287 yaml_mapping_start_event_initialize(&event, NULL,
4288 (yaml_char_t *)YAML_MAP_TAG,
4289 1, YAML_ANY_MAPPING_STYLE);
4290 rc = yaml_emitter_emit(&output, &event);
4294 if (timeout != 1000 || src_nidstr) {
4296 yaml_scalar_event_initialize(&event, NULL,
4297 (yaml_char_t *)YAML_STR_TAG,
4298 (yaml_char_t *)"source",
4299 strlen("source"), 1, 0,
4300 YAML_PLAIN_SCALAR_STYLE);
4301 rc = yaml_emitter_emit(&output, &event);
4305 yaml_scalar_event_initialize(&event, NULL,
4306 (yaml_char_t *)YAML_STR_TAG,
4307 (yaml_char_t *)src_nidstr,
4308 strlen(src_nidstr), 1, 0,
4309 YAML_PLAIN_SCALAR_STYLE);
4310 rc = yaml_emitter_emit(&output, &event);
4315 if (timeout != 1000) {
4318 yaml_scalar_event_initialize(&event, NULL,
4319 (yaml_char_t *)YAML_STR_TAG,
4320 (yaml_char_t *)"timeout",
4321 strlen("timeout"), 1, 0,
4322 YAML_PLAIN_SCALAR_STYLE);
4323 rc = yaml_emitter_emit(&output, &event);
4327 snprintf(time, sizeof(time), "%u", timeout);
4328 yaml_scalar_event_initialize(&event, NULL,
4329 (yaml_char_t *)YAML_INT_TAG,
4330 (yaml_char_t *)time,
4332 YAML_PLAIN_SCALAR_STYLE);
4333 rc = yaml_emitter_emit(&output, &event);
4339 yaml_scalar_event_initialize(&event, NULL,
4340 (yaml_char_t *)YAML_STR_TAG,
4341 (yaml_char_t *)"nids",
4342 strlen("nids"), 1, 0,
4343 YAML_PLAIN_SCALAR_STYLE);
4344 rc = yaml_emitter_emit(&output, &event);
4348 yaml_sequence_start_event_initialize(&event, NULL,
4349 (yaml_char_t *)YAML_SEQ_TAG,
4350 1, YAML_FLOW_SEQUENCE_STYLE);
4351 rc = yaml_emitter_emit(&output, &event);
4355 for (i = start; i < end; i++) {
4356 yaml_scalar_event_initialize(&event, NULL,
4357 (yaml_char_t *)YAML_STR_TAG,
4358 (yaml_char_t *)nids[i],
4359 strlen(nids[i]), 1, 0,
4360 YAML_PLAIN_SCALAR_STYLE);
4361 rc = yaml_emitter_emit(&output, &event);
4366 yaml_sequence_end_event_initialize(&event);
4367 rc = yaml_emitter_emit(&output, &event);
4371 yaml_mapping_end_event_initialize(&event);
4372 rc = yaml_emitter_emit(&output, &event);
4376 yaml_mapping_end_event_initialize(&event);
4377 rc = yaml_emitter_emit(&output, &event);
4381 yaml_document_end_event_initialize(&event, 0);
4382 rc = yaml_emitter_emit(&output, &event);
4386 rc = yaml_emitter_close(&output);
4389 yaml_emitter_log_error(&output, stderr);
4392 rc = yaml_lnet_ping_display(&reply);
4394 msg = yaml_parser_get_reader_error(&reply);
4396 yaml_emitter_delete(&output);
4399 yaml_lnet_print_error(-1, group, msg);
4403 yaml_parser_delete(&reply);
4406 return rc == 1 ? 0 : rc;
4409 static int jt_ping(int argc, char **argv)
4411 struct cYAML *err_rc = NULL;
4412 struct cYAML *show_rc = NULL;
4415 char *src_nidstr = NULL;
4417 const char *const short_options = "hs:t:";
4418 const struct option long_options[] = {
4419 { .name = "help", .has_arg = no_argument, .val = 'h' },
4420 { .name = "timeout", .has_arg = required_argument, .val = 't' },
4421 { .name = "source", .has_arg = required_argument, .val = 's' },
4424 while ((opt = getopt_long(argc, argv, short_options,
4425 long_options, NULL)) != -1) {
4428 src_nidstr = optarg;
4431 timeout = 1000 * atol(optarg);
4434 printf("ping nid[,nid,...]\n"
4435 "\t --source: source nid\n"
4436 "\t --timeout: ping timeout\n"
4437 "\t --help: display this help\n");
4444 for (; optind < argc; optind++)
4445 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
4449 cYAML_print_tree(show_rc);
4452 cYAML_print_tree2file(stderr, err_rc);
4454 cYAML_free_tree(err_rc);
4455 cYAML_free_tree(show_rc);
4460 static int jt_discover(int argc, char **argv)
4462 struct cYAML *err_rc = NULL;
4463 struct cYAML *show_rc = NULL;
4464 int flags = NLM_F_CREATE;
4467 const char *const short_options = "fh";
4468 const struct option long_options[] = {
4469 { .name = "force", .has_arg = no_argument, .val = 'f' },
4470 { .name = "help", .has_arg = no_argument, .val = 'h' },
4474 while ((opt = getopt_long(argc, argv, short_options,
4475 long_options, NULL)) != -1) {
4478 /* BSD treats NLM_F_CREATE | NLM_F_EXCL as an add */
4479 flags |= NLM_F_EXCL;
4483 printf("discover nid[,nid,...]\n"
4484 "\t --force: force discovery\n"
4485 "\t --help: display this help\n");
4492 if (optind == argc) {
4493 printf("Missing nid argument\n");
4497 rc = yaml_lnet_ping("discover", 1000, NULL, optind, argc, argv,
4500 if (rc != -EOPNOTSUPP)
4504 for (; optind < argc; optind++)
4505 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
4509 cYAML_print_tree(show_rc);
4512 cYAML_print_tree2file(stderr, err_rc);
4514 cYAML_free_tree(err_rc);
4515 cYAML_free_tree(show_rc);
4520 static int jt_add_udsp(int argc, char **argv)
4522 char *src = NULL, *dst = NULL, *rte = NULL;
4523 struct cYAML *err_rc = NULL;
4524 union lnet_udsp_action udsp_action;
4525 long int idx = -1, priority = -1;
4527 char *action_type = "pref";
4529 const char *const short_options = "s:d:r:p:i:";
4530 static const struct option long_options[] = {
4531 { .name = "src", .has_arg = required_argument, .val = 's' },
4532 { .name = "dst", .has_arg = required_argument, .val = 'd' },
4533 { .name = "rte", .has_arg = required_argument, .val = 'r' },
4534 { .name = "priority", .has_arg = required_argument, .val = 'p' },
4535 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4538 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
4542 while ((opt = getopt_long(argc, argv, short_options,
4543 long_options, NULL)) != -1) {
4555 rc = parse_long(optarg, &priority);
4556 if (rc != 0 || priority < 0) {
4557 printf("Invalid priority \"%s\"\n", optarg);
4560 action_type = "priority";
4561 udsp_action.udsp_priority = priority;
4564 rc = parse_long(optarg, &idx);
4565 if (rc != 0 || idx < 0) {
4566 printf("Invalid index \"%s\"\n", optarg);
4571 print_help(udsp_cmds, "udsp", "add");
4577 if (!(src || dst || rte)) {
4578 print_help(udsp_cmds, "udsp", "add");
4582 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
4585 if (rc != LUSTRE_CFG_RC_NO_ERR)
4586 cYAML_print_tree2file(stderr, err_rc);
4588 cYAML_free_tree(err_rc);
4593 static int jt_del_udsp(int argc, char **argv)
4595 struct cYAML *err_rc = NULL;
4600 const char *const short_options = "ai:";
4601 static const struct option long_options[] = {
4602 { .name = "all", .has_arg = no_argument, .val = 'a' },
4603 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4606 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
4610 while ((opt = getopt_long(argc, argv, short_options,
4611 long_options, NULL)) != -1) {
4617 rc = parse_long(optarg, &idx);
4618 if (rc != 0 || idx < -1) {
4619 printf("Invalid index \"%s\"\n", optarg);
4624 print_help(udsp_cmds, "udsp", "del");
4630 if (all && idx != -2) {
4631 printf("Cannot combine --all with --idx\n");
4635 } else if (idx == -2) {
4636 printf("Must specify --idx or --all\n");
4640 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
4641 if (rc != LUSTRE_CFG_RC_NO_ERR)
4642 cYAML_print_tree2file(stderr, err_rc);
4644 cYAML_free_tree(err_rc);
4649 int main(int argc, char **argv)
4652 struct cYAML *err_rc = NULL;
4654 rc = lustre_lnet_config_lib_init();
4656 cYAML_build_error(-1, -1, "lnetctl", "startup",
4657 "cannot register LNet device", &err_rc);
4658 cYAML_print_tree2file(stderr, err_rc);
4662 return cfs_parser(argc, argv, cmd_list);