4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
33 #include "lnetconfig/cyaml.h"
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_recovery(int argc, char **argv);
52 static int jt_show_global(int argc, char **argv);
53 static int jt_show_udsp(int argc, char **argv);
54 static int jt_set_tiny(int argc, char **argv);
55 static int jt_set_small(int argc, char **argv);
56 static int jt_set_large(int argc, char **argv);
57 static int jt_set_numa(int argc, char **argv);
58 static int jt_set_retry_count(int argc, char **argv);
59 static int jt_set_transaction_to(int argc, char **argv);
60 static int jt_set_recov_intrv(int argc, char **argv);
61 static int jt_set_rtr_sensitivity(int argc, char **argv);
62 static int jt_set_hsensitivity(int argc, char **argv);
63 static int jt_set_max_recovery_ping_interval(int argc, char **argv);
64 static int jt_reset_stats(int argc, char **argv);
65 static int jt_add_peer_nid(int argc, char **argv);
66 static int jt_del_peer_nid(int argc, char **argv);
67 static int jt_set_max_intf(int argc, char **argv);
68 static int jt_set_discovery(int argc, char **argv);
69 static int jt_set_drop_asym_route(int argc, char **argv);
70 static int jt_list_peer(int argc, char **argv);
71 static int jt_add_udsp(int argc, char **argv);
72 static int jt_del_udsp(int argc, char **argv);
73 /*static int jt_show_peer(int argc, char **argv);*/
74 static int jt_import(int argc, char **argv);
75 static int jt_export(int argc, char **argv);
76 static int jt_ping(int argc, char **argv);
77 static int jt_discover(int argc, char **argv);
78 static int jt_lnet(int argc, char **argv);
79 static int jt_route(int argc, char **argv);
80 static int jt_net(int argc, char **argv);
81 static int jt_routing(int argc, char **argv);
82 static int jt_set(int argc, char **argv);
83 static int jt_debug(int argc, char **argv);
84 static int jt_stats(int argc, char **argv);
85 static int jt_global(int argc, char **argv);
86 static int jt_peers(int argc, char **argv);
87 static int jt_set_ni_value(int argc, char **argv);
88 static int jt_set_peer_ni_value(int argc, char **argv);
89 static int jt_calc_service_id(int argc, char **argv);
90 static int jt_set_response_tracking(int argc, char **argv);
91 static int jt_set_recovery_limit(int argc, char **argv);
92 static int jt_udsp(int argc, char **argv);
93 static int jt_setup_mrrouting(int argc, char **argv);
94 static int jt_calc_cpt_of_nid(int argc, char **argv);
95 static int jt_show_peer_debug_info(int argc, char **argv);
97 command_t cmd_list[] = {
98 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
99 {"route", jt_route, 0, "route {add | del | show | help}"},
100 {"net", jt_net, 0, "net {add | del | show | set | help}"},
101 {"routing", jt_routing, 0, "routing {show | help}"},
102 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
103 " | routing | numa_range | max_interfaces"
104 " | discovery | drop_asym_route | retry_count"
105 " | transaction_timeout | health_sensitivity"
106 " | recovery_interval | router_sensitivity"
107 " | response_tracking | recovery_limit}"},
108 {"import", jt_import, 0, "import FILE.yaml"},
109 {"export", jt_export, 0, "export FILE.yaml"},
110 {"stats", jt_stats, 0, "stats {show | help}"},
111 {"debug", jt_debug, 0, "debug {recovery {local | peer} | peer}"},
112 {"global", jt_global, 0, "global {show | help}"},
113 {"peer", jt_peers, 0, "peer {add | del | show | list | set | help}"},
114 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
115 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
116 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
117 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
118 {"setup-mrrouting", jt_setup_mrrouting, 0,
119 "setup linux routing tables\n"},
120 {"cpt-of-nid", jt_calc_cpt_of_nid, 0, "Calculate the CPT associated with NID\n"
121 "\t--nid: NID to calculate the CPT of\n"
122 "\t--ncpt: Number of CPTs to consider in the calculation\n"},
126 command_t lnet_cmds[] = {
127 {"configure", jt_config_lnet, 0, "configure lnet\n"
128 "\t--all: load NI configuration from module parameters\n"},
129 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
133 command_t route_cmds[] = {
134 {"add", jt_add_route, 0, "add a route\n"
135 "\t--net: net name (e.g. tcp0)\n"
136 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
137 "\t--hop|hop-count: number to final destination (1 <= hops <= 255)\n"
138 "\t--priority: priority of route (0 - highest prio\n"
139 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
140 {"del", jt_del_route, 0, "delete a route\n"
141 "\t--net: net name (e.g. tcp0)\n"
142 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
143 {"show", jt_show_route, 0, "show routes\n"
144 "\t--net: net name (e.g. tcp0) to filter on\n"
145 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
146 "\t--hop|hop-count: number to final destination (1 <= hops <= 255) to filter on\n"
147 "\t--priority: priority of route (0 - highest prio to filter on\n"
148 "\t--verbose: display detailed output per route\n"},
152 command_t net_cmds[] = {
153 {"add", jt_add_ni, 0, "add a network\n"
154 "\t--net: net name (e.g. tcp0)\n"
155 "\t--if: physical interface (e.g. eth0)\n"
156 "\t--ip2net: specify networks based on IP address patterns\n"
157 "\t--peer-timeout: time to wait before declaring a peer dead\n"
158 "\t--peer-credits: define the max number of inflight messages\n"
159 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
160 "\t--credits: Network Interface credits\n"
161 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"
162 "\t--conns-per-peer: number of connections per peer\n"
163 "\t--skip-mr-route-setup: do not add linux route for the ni\n"
164 "\t--auth-key: Network authorization key (kfilnd only)\n"
165 "\t--traffic-class: Traffic class (kfilnd only)\n"},
166 {"del", jt_del_ni, 0, "delete a network\n"
167 "\t--net: net name (e.g. tcp0)\n"
168 "\t--if: physical interface (e.g. eth0)\n"},
169 {"show", jt_show_net, 0, "show networks\n"
170 "\t--net: net name (e.g. tcp0) to filter on\n"
171 "\t--verbose: display detailed output per network."
172 " Optional argument of '2' outputs more stats\n"},
173 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
174 "\t--nid: NI NID to set the\n"
175 "\t--health: specify health value to set\n"
176 "\t--conns-per-peer: number of connections per peer\n"
177 "\t--all: set all NIs value to the one specified\n"},
181 command_t routing_cmds[] = {
182 {"show", jt_show_routing, 0, "show routing information\n"},
186 command_t stats_cmds[] = {
187 {"show", jt_show_stats, 0, "show LNET statistics\n"},
188 {"reset", jt_reset_stats, 0, "reset LNET statistics\n"},
192 command_t debug_cmds[] = {
193 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
194 "\t--local : list local recovery queue\n"
195 "\t--peer : list peer recovery queue\n"},
196 {"peer", jt_show_peer_debug_info, 0, "show peer debug info\n"
197 "\t--nid: peer's NID\n"},
201 command_t global_cmds[] = {
202 {"show", jt_show_global, 0, "show global variables\n"},
206 command_t set_cmds[] = {
207 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
208 "\tVALUE must be greater than 0\n"},
209 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
210 "\tVALUE must be greater than 0\n"},
211 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
212 "\tVALUE must be greater than 0\n"},
213 {"routing", jt_set_routing, 0, "enable/disable routing\n"
214 "\t0 - disable routing\n"
215 "\t1 - enable routing\n"},
216 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
217 "\tVALUE must be at least 0\n"},
218 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
220 "\tValue must be greater than 16\n"},
221 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
222 "\t0 - disable peer discovery\n"
223 "\t1 - enable peer discovery (default)\n"},
224 {"drop_asym_route", jt_set_drop_asym_route, 0,
225 "drop/accept asymmetrical route messages\n"
226 "\t0 - accept asymmetrical route messages (default)\n"
227 "\t1 - drop asymmetrical route messages\n"},
228 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
229 "\t0 - turn of retries\n"
230 "\t>0 - number of retries\n"},
231 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
232 "\t>0 - timeout in seconds\n"},
233 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
234 "\t0 - turn off health evaluation\n"
235 "\t>0 - sensitivity value not more than 1000\n"},
236 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
237 "\t>0 - time in seconds between pings\n"},
238 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
239 "\t100 - router interfaces need to be fully healthy to be used\n"
240 "\t<100 - router interfaces can be used even if not healthy\n"},
241 {"response_tracking", jt_set_response_tracking, 0,
242 "Set the behavior of response tracking\n"
243 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
244 "\t1 - GETs are eligible for response tracking\n"
245 "\t2 - PUTs are eligible for response tracking\n"
246 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
247 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
248 "\t pings and discovery pushes always utilize response tracking\n"},
249 {"recovery_limit", jt_set_recovery_limit, 0,
250 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
251 "\t0 - Recover indefinitely (default)\n"
252 "\t>0 - Recover for the specified number of seconds.\n"},
253 {"max_recovery_ping_interval", jt_set_max_recovery_ping_interval, 0,
254 "maximum recovery ping interval\n"
255 "\t>0 - maximum recovery ping interval in seconds\n"},
259 command_t peer_cmds[] = {
260 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
261 "\t--prim_nid: Primary NID of the peer.\n"
262 "\t--nid: one or more peer NIDs\n"
263 "\t--non_mr: create this peer as not Multi-Rail capable\n"
264 "\t--ip2nets: specify a range of nids per peer\n"
265 "\t--lock_prim: lock primary nid\n"},
266 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
267 "\t--prim_nid: Primary NID of the peer.\n"
268 "\t--nid: list of NIDs to remove. If none provided,\n"
269 "\t peer is deleted\n"
270 "\t--ip2nets: specify a range of nids per peer\n"
271 "\t--force: force-delete locked primary NID\n"},
272 {"show", jt_show_peer, 0, "show peer information\n"
273 "\t--nid: NID of peer to filter on.\n"
274 "\t--verbose: display detailed output per peer."
275 " Optional argument of '2' outputs more stats\n"},
276 {"list", jt_list_peer, 0, "list all peers\n"},
277 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
278 "\t--nid: Peer NI NID to set the\n"
279 "\t--health: specify health value to set\n"
280 "\t--all: set all peer_nis values to the one specified\n"
281 "\t--state: set peer state (DANGEROUS: for test/debug only)"},
285 command_t udsp_cmds[] = {
286 {"add", jt_add_udsp, 0, "add a udsp\n"
287 "\t--src nid|net: ip2nets syntax specifying the local NID or network to match.\n"
288 "\t--dst nid: ip2nets syntax specifying the remote NID to match.\n"
289 "\t--rte nid: ip2nets syntax specifying the router NID to match.\n"
290 "\t--priority p: Assign priority value p where p >= 0.\n"
291 "\t Note: 0 is the highest priority.\n"
292 "\t--idx n: Insert the rule in the n'th position on the list of rules.\n"
293 "\t By default, rules are appended to the end of the rule list.\n"},
294 {"del", jt_del_udsp, 0, "delete a udsp\n"
295 "\t--all: Delete all rules.\n"
296 "\t--idx n: Delete the rule at index n.\n"},
297 {"show", jt_show_udsp, 0, "show udsps\n"
298 "\t--idx n: Show the rule at at index n.\n"
299 "\t By default, all rules are shown.\n"},
303 static int parse_long(const char *number, long int *value)
310 *value = strtol(number, &end, 0);
311 if (end != NULL && *end != 0)
317 static int jt_setup_mrrouting(int argc, char **argv)
320 struct cYAML *err_rc = NULL;
322 rc = lustre_lnet_setup_mrrouting(&err_rc);
324 if (rc != LUSTRE_CFG_RC_NO_ERR)
325 cYAML_print_tree2file(stderr, err_rc);
327 cYAML_free_tree(err_rc);
332 static inline void print_help(const command_t cmds[], const char *cmd_type,
335 const command_t *cmd;
337 for (cmd = cmds; cmd->pc_name; cmd++) {
338 if (pc_name != NULL &&
339 strcmp(cmd->pc_name, pc_name) == 0) {
340 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
343 } else if (pc_name != NULL) {
346 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
350 static int check_cmd(const command_t *cmd_list, const char *cmd,
351 const char *sub_cmd, const int min_args,
352 int argc, char **argv)
359 const char *const short_options = "h";
360 static const struct option long_options[] = {
361 { .name = "help", .has_arg = no_argument, .val = 'h' },
365 if (argc < min_args) {
366 print_help(cmd_list, cmd, sub_cmd);
369 } else if (argc > 2) {
373 while ((opt = getopt_long(argc, argv, short_options,
374 long_options, NULL)) != -1) {
377 print_help(cmd_list, cmd, sub_cmd);
392 static int jt_set_response_tracking(int argc, char **argv)
396 struct cYAML *err_rc = NULL;
398 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
402 rc = parse_long(argv[1], &value);
404 cYAML_build_error(-1, -1, "parser", "set",
405 "cannot parse response_tracking value",
407 cYAML_print_tree2file(stderr, err_rc);
408 cYAML_free_tree(err_rc);
412 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
413 if (rc != LUSTRE_CFG_RC_NO_ERR)
414 cYAML_print_tree2file(stderr, err_rc);
416 cYAML_free_tree(err_rc);
421 static int jt_calc_service_id(int argc, char **argv)
426 rc = lustre_lnet_calc_service_id(&service_id);
427 if (rc != LUSTRE_CFG_RC_NO_ERR)
430 /* cYAML currently doesn't support printing hex values.
431 * Therefore just print it locally here
433 printf("service_id:\n value: 0x%llx\n",
434 (unsigned long long)(service_id));
439 static int jt_calc_cpt_of_nid(int argc, char **argv)
445 struct cYAML *err_rc = NULL;
446 const char *const short_options = "n:c:h";
447 static const struct option long_options[] = {
448 { .name = "nid", .has_arg = required_argument, .val = 'n' },
449 { .name = "ncpt", .has_arg = required_argument, .val = 'c' },
452 rc = check_cmd(cmd_list, "", "cpt-of-nid", 0, argc, argv);
456 while ((opt = getopt_long(argc, argv, short_options,
457 long_options, NULL)) != -1) {
463 rc = parse_long(optarg, &ncpts);
465 cYAML_build_error(-1, -1, "cpt", "get",
466 "cannot parse input", &err_rc);
467 cYAML_print_tree2file(stderr, err_rc);
468 cYAML_free_tree(err_rc);
473 print_help(cmd_list, "", "cpt-of-nid");
479 cpt = lustre_lnet_calc_cpt_of_nid(nid, ncpts);
483 printf("cpt:\n value: %d\n", cpt);
488 static int jt_set_recovery_limit(int argc, char **argv)
492 struct cYAML *err_rc = NULL;
494 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
498 rc = parse_long(argv[1], &value);
500 cYAML_build_error(-1, -1, "parser", "set",
501 "cannot parse recovery_limit value",
503 cYAML_print_tree2file(stderr, err_rc);
504 cYAML_free_tree(err_rc);
508 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
509 if (rc != LUSTRE_CFG_RC_NO_ERR)
510 cYAML_print_tree2file(stderr, err_rc);
512 cYAML_free_tree(err_rc);
517 static int jt_set_max_intf(int argc, char **argv)
521 struct cYAML *err_rc = NULL;
523 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
527 rc = parse_long(argv[1], &value);
529 cYAML_build_error(-1, -1, "parser", "set",
530 "cannot parse max_interfaces value", &err_rc);
531 cYAML_print_tree2file(stderr, err_rc);
532 cYAML_free_tree(err_rc);
536 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
537 if (rc != LUSTRE_CFG_RC_NO_ERR)
538 cYAML_print_tree2file(stderr, err_rc);
540 cYAML_free_tree(err_rc);
545 static int jt_set_numa(int argc, char **argv)
549 struct cYAML *err_rc = NULL;
551 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
555 rc = parse_long(argv[1], &value);
557 cYAML_build_error(-1, -1, "parser", "set",
558 "cannot parse numa_range value", &err_rc);
559 cYAML_print_tree2file(stderr, err_rc);
560 cYAML_free_tree(err_rc);
564 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
565 if (rc != LUSTRE_CFG_RC_NO_ERR)
566 cYAML_print_tree2file(stderr, err_rc);
568 cYAML_free_tree(err_rc);
573 static int jt_set_recov_intrv(int argc, char **argv)
577 struct cYAML *err_rc = NULL;
579 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
583 rc = parse_long(argv[1], &value);
585 cYAML_build_error(-1, -1, "parser", "set",
586 "cannot parse recovery interval value", &err_rc);
587 cYAML_print_tree2file(stderr, err_rc);
588 cYAML_free_tree(err_rc);
592 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
593 if (rc != LUSTRE_CFG_RC_NO_ERR)
594 cYAML_print_tree2file(stderr, err_rc);
596 cYAML_free_tree(err_rc);
601 static int jt_set_rtr_sensitivity(int argc, char **argv)
605 struct cYAML *err_rc = NULL;
607 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
611 rc = parse_long(argv[1], &value);
613 cYAML_build_error(-1, -1, "parser", "set",
614 "cannot parse router sensitivity value", &err_rc);
615 cYAML_print_tree2file(stderr, err_rc);
616 cYAML_free_tree(err_rc);
620 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
621 if (rc != LUSTRE_CFG_RC_NO_ERR)
622 cYAML_print_tree2file(stderr, err_rc);
624 cYAML_free_tree(err_rc);
629 static int jt_set_hsensitivity(int argc, char **argv)
633 struct cYAML *err_rc = NULL;
635 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
639 rc = parse_long(argv[1], &value);
641 cYAML_build_error(-1, -1, "parser", "set",
642 "cannot parse health sensitivity value", &err_rc);
643 cYAML_print_tree2file(stderr, err_rc);
644 cYAML_free_tree(err_rc);
648 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
649 if (rc != LUSTRE_CFG_RC_NO_ERR)
650 cYAML_print_tree2file(stderr, err_rc);
652 cYAML_free_tree(err_rc);
657 static int jt_reset_stats(int argc, char **argv)
660 struct cYAML *err_rc = NULL;
662 rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv);
666 rc = lustre_lnet_reset_stats(-1, &err_rc);
667 if (rc != LUSTRE_CFG_RC_NO_ERR)
668 cYAML_print_tree2file(stderr, err_rc);
670 cYAML_free_tree(err_rc);
675 static int jt_set_transaction_to(int argc, char **argv)
679 struct cYAML *err_rc = NULL;
681 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
685 rc = parse_long(argv[1], &value);
687 cYAML_build_error(-1, -1, "parser", "set",
688 "cannot parse transaction timeout value", &err_rc);
689 cYAML_print_tree2file(stderr, err_rc);
690 cYAML_free_tree(err_rc);
694 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
695 if (rc != LUSTRE_CFG_RC_NO_ERR)
696 cYAML_print_tree2file(stderr, err_rc);
698 cYAML_free_tree(err_rc);
703 static int jt_set_retry_count(int argc, char **argv)
707 struct cYAML *err_rc = NULL;
709 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
713 rc = parse_long(argv[1], &value);
715 cYAML_build_error(-1, -1, "parser", "set",
716 "cannot parse retry_count value", &err_rc);
717 cYAML_print_tree2file(stderr, err_rc);
718 cYAML_free_tree(err_rc);
722 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
723 if (rc != LUSTRE_CFG_RC_NO_ERR)
724 cYAML_print_tree2file(stderr, err_rc);
726 cYAML_free_tree(err_rc);
731 static int jt_set_discovery(int argc, char **argv)
735 struct cYAML *err_rc = NULL;
737 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
741 rc = parse_long(argv[1], &value);
743 cYAML_build_error(-1, -1, "parser", "set",
744 "cannot parse discovery value", &err_rc);
745 cYAML_print_tree2file(stderr, err_rc);
746 cYAML_free_tree(err_rc);
750 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
751 if (rc != LUSTRE_CFG_RC_NO_ERR)
752 cYAML_print_tree2file(stderr, err_rc);
754 cYAML_free_tree(err_rc);
759 static int jt_set_drop_asym_route(int argc, char **argv)
763 struct cYAML *err_rc = NULL;
765 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
769 rc = parse_long(argv[1], &value);
771 cYAML_build_error(-1, -1, "parser", "set",
772 "cannot parse drop_asym_route value",
774 cYAML_print_tree2file(stderr, err_rc);
775 cYAML_free_tree(err_rc);
779 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
780 if (rc != LUSTRE_CFG_RC_NO_ERR)
781 cYAML_print_tree2file(stderr, err_rc);
783 cYAML_free_tree(err_rc);
788 static int jt_set_tiny(int argc, char **argv)
792 struct cYAML *err_rc = NULL;
794 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
798 rc = parse_long(argv[1], &value);
800 cYAML_build_error(-1, -1, "parser", "set",
801 "cannot parse tiny_buffers value", &err_rc);
802 cYAML_print_tree2file(stderr, err_rc);
803 cYAML_free_tree(err_rc);
807 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
808 if (rc != LUSTRE_CFG_RC_NO_ERR)
809 cYAML_print_tree2file(stderr, err_rc);
811 cYAML_free_tree(err_rc);
816 static int jt_set_small(int argc, char **argv)
820 struct cYAML *err_rc = NULL;
822 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
826 rc = parse_long(argv[1], &value);
828 cYAML_build_error(-1, -1, "parser", "set",
829 "cannot parse small_buffers value", &err_rc);
830 cYAML_print_tree2file(stderr, err_rc);
831 cYAML_free_tree(err_rc);
835 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
836 if (rc != LUSTRE_CFG_RC_NO_ERR)
837 cYAML_print_tree2file(stderr, err_rc);
839 cYAML_free_tree(err_rc);
844 static int jt_set_large(int argc, char **argv)
848 struct cYAML *err_rc = NULL;
850 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
854 rc = parse_long(argv[1], &value);
856 cYAML_build_error(-1, -1, "parser", "set",
857 "cannot parse large_buffers value", &err_rc);
858 cYAML_print_tree2file(stderr, err_rc);
859 cYAML_free_tree(err_rc);
863 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
864 if (rc != LUSTRE_CFG_RC_NO_ERR)
865 cYAML_print_tree2file(stderr, err_rc);
867 cYAML_free_tree(err_rc);
872 static int jt_set_routing(int argc, char **argv)
875 struct cYAML *err_rc = NULL;
878 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
882 rc = parse_long(argv[1], &value);
883 if (rc != 0 || (value != 0 && value != 1)) {
884 cYAML_build_error(-1, -1, "parser", "set",
885 "cannot parse routing value.\n"
886 "must be 0 for disable or 1 for enable",
888 cYAML_print_tree2file(stderr, err_rc);
889 cYAML_free_tree(err_rc);
893 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
895 if (rc != LUSTRE_CFG_RC_NO_ERR)
896 cYAML_print_tree2file(stderr, err_rc);
898 cYAML_free_tree(err_rc);
903 static int jt_set_max_recovery_ping_interval(int argc, char **argv)
907 struct cYAML *err_rc = NULL;
909 rc = check_cmd(set_cmds, "set", "maximum recovery_interval", 2, argc, argv);
913 rc = parse_long(argv[1], &value);
915 cYAML_build_error(-1, -1, "parser", "set",
916 "cannot parse maximum recovery interval value",
918 cYAML_print_tree2file(stderr, err_rc);
919 cYAML_free_tree(err_rc);
923 rc = lustre_lnet_config_max_recovery_ping_interval(value, -1, &err_rc);
924 if (rc != LUSTRE_CFG_RC_NO_ERR)
925 cYAML_print_tree2file(stderr, err_rc);
927 cYAML_free_tree(err_rc);
932 static void yaml_lnet_print_error(int op, char *cmd, const char *errstr)
934 char errcode[INT_STRING_LEN];
940 snprintf(errcode, sizeof(errcode), "%d", errno);
942 yaml_emitter_initialize(&log);
943 yaml_emitter_set_indent(&log, LNET_DEFAULT_INDENT);
944 yaml_emitter_set_output_file(&log, stderr);
946 yaml_emitter_open(&log);
947 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
948 rc = yaml_emitter_emit(&log, &event);
952 yaml_mapping_start_event_initialize(&event, NULL,
953 (yaml_char_t *)YAML_MAP_TAG,
954 1, YAML_ANY_MAPPING_STYLE);
955 rc = yaml_emitter_emit(&log, &event);
978 yaml_scalar_event_initialize(&event, NULL,
979 (yaml_char_t *)YAML_STR_TAG,
982 YAML_PLAIN_SCALAR_STYLE);
983 rc = yaml_emitter_emit(&log, &event);
987 yaml_sequence_start_event_initialize(&event, NULL,
988 (yaml_char_t *)YAML_SEQ_TAG,
989 1, YAML_ANY_SEQUENCE_STYLE);
990 rc = yaml_emitter_emit(&log, &event);
994 yaml_mapping_start_event_initialize(&event, NULL,
995 (yaml_char_t *)YAML_MAP_TAG,
996 1, YAML_ANY_MAPPING_STYLE);
997 rc = yaml_emitter_emit(&log, &event);
1001 yaml_scalar_event_initialize(&event, NULL,
1002 (yaml_char_t *)YAML_STR_TAG,
1005 1, 0, YAML_PLAIN_SCALAR_STYLE);
1006 rc = yaml_emitter_emit(&log, &event);
1010 yaml_scalar_event_initialize(&event, NULL,
1011 (yaml_char_t *)YAML_STR_TAG,
1014 1, 0, YAML_PLAIN_SCALAR_STYLE);
1015 rc = yaml_emitter_emit(&log, &event);
1019 yaml_scalar_event_initialize(&event, NULL,
1020 (yaml_char_t *)YAML_STR_TAG,
1021 (yaml_char_t *)"errno",
1022 strlen("errno"), 1, 0,
1023 YAML_PLAIN_SCALAR_STYLE);
1024 rc = yaml_emitter_emit(&log, &event);
1028 yaml_scalar_event_initialize(&event, NULL,
1029 (yaml_char_t *)YAML_INT_TAG,
1030 (yaml_char_t *)errcode,
1031 strlen(errcode), 1, 0,
1032 YAML_PLAIN_SCALAR_STYLE);
1033 rc = yaml_emitter_emit(&log, &event);
1038 yaml_scalar_event_initialize(&event, NULL,
1039 (yaml_char_t *)YAML_STR_TAG,
1040 (yaml_char_t *)"descr",
1041 strlen("descr"), 1, 0,
1042 YAML_PLAIN_SCALAR_STYLE);
1043 rc = yaml_emitter_emit(&log, &event);
1047 yaml_scalar_event_initialize(&event, NULL,
1048 (yaml_char_t *)YAML_STR_TAG,
1049 (yaml_char_t *)errstr,
1050 strlen(errstr), 1, 0,
1051 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
1052 rc = yaml_emitter_emit(&log, &event);
1056 yaml_mapping_end_event_initialize(&event);
1057 rc = yaml_emitter_emit(&log, &event);
1061 yaml_sequence_end_event_initialize(&event);
1062 rc = yaml_emitter_emit(&log, &event);
1066 yaml_mapping_end_event_initialize(&event);
1067 rc = yaml_emitter_emit(&log, &event);
1071 yaml_document_end_event_initialize(&event, 0);
1072 rc = yaml_emitter_emit(&log, &event);
1076 rc = yaml_emitter_close(&log);
1079 yaml_emitter_log_error(&log, stdout);
1080 yaml_emitter_delete(&log);
1083 static int jt_config_lnet(int argc, char **argv)
1085 struct cYAML *err_rc = NULL;
1086 bool load_mod_params = false;
1089 const char *const short_options = "a";
1090 static const struct option long_options[] = {
1091 { .name = "all", .has_arg = no_argument, .val = 'a' },
1095 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
1099 while ((opt = getopt_long(argc, argv, short_options,
1100 long_options, NULL)) != -1) {
1103 load_mod_params = true;
1110 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
1113 if (rc != LUSTRE_CFG_RC_NO_ERR)
1114 cYAML_print_tree2file(stderr, err_rc);
1116 cYAML_free_tree(err_rc);
1121 static int jt_unconfig_lnet(int argc, char **argv)
1123 struct cYAML *err_rc = NULL;
1126 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
1130 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
1132 if (rc != LUSTRE_CFG_RC_NO_ERR)
1133 cYAML_print_tree2file(stderr, err_rc);
1135 cYAML_free_tree(err_rc);
1140 static int yaml_lnet_router_gateways(yaml_emitter_t *output, const char *nw,
1141 const char *gw, int hops, int prio,
1144 char num[INT_STRING_LEN];
1148 yaml_mapping_start_event_initialize(&event, NULL,
1149 (yaml_char_t *)YAML_MAP_TAG, 1,
1150 YAML_BLOCK_MAPPING_STYLE);
1151 rc = yaml_emitter_emit(output, &event);
1156 yaml_scalar_event_initialize(&event, NULL,
1157 (yaml_char_t *)YAML_STR_TAG,
1158 (yaml_char_t *)"net",
1159 strlen("net"), 1, 0,
1160 YAML_PLAIN_SCALAR_STYLE);
1161 rc = yaml_emitter_emit(output, &event);
1165 yaml_scalar_event_initialize(&event, NULL,
1166 (yaml_char_t *)YAML_STR_TAG,
1169 YAML_PLAIN_SCALAR_STYLE);
1170 rc = yaml_emitter_emit(output, &event);
1176 yaml_scalar_event_initialize(&event, NULL,
1177 (yaml_char_t *)YAML_STR_TAG,
1178 (yaml_char_t *)"gateway",
1179 strlen("gateway"), 1, 0,
1180 YAML_PLAIN_SCALAR_STYLE);
1181 rc = yaml_emitter_emit(output, &event);
1185 yaml_scalar_event_initialize(&event, NULL,
1186 (yaml_char_t *)YAML_STR_TAG,
1189 YAML_PLAIN_SCALAR_STYLE);
1190 rc = yaml_emitter_emit(output, &event);
1196 yaml_scalar_event_initialize(&event, NULL,
1197 (yaml_char_t *)YAML_STR_TAG,
1198 (yaml_char_t *)"hop",
1199 strlen("hop"), 1, 0,
1200 YAML_PLAIN_SCALAR_STYLE);
1201 rc = yaml_emitter_emit(output, &event);
1205 snprintf(num, sizeof(num), "%d", hops);
1206 yaml_scalar_event_initialize(&event, NULL,
1207 (yaml_char_t *)YAML_INT_TAG,
1210 YAML_PLAIN_SCALAR_STYLE);
1211 rc = yaml_emitter_emit(output, &event);
1217 yaml_scalar_event_initialize(&event, NULL,
1218 (yaml_char_t *)YAML_STR_TAG,
1219 (yaml_char_t *)"priority",
1220 strlen("priority"), 1, 0,
1221 YAML_PLAIN_SCALAR_STYLE);
1222 rc = yaml_emitter_emit(output, &event);
1226 snprintf(num, sizeof(num), "%d", prio);
1227 yaml_scalar_event_initialize(&event, NULL,
1228 (yaml_char_t *)YAML_INT_TAG,
1231 YAML_PLAIN_SCALAR_STYLE);
1232 rc = yaml_emitter_emit(output, &event);
1238 yaml_scalar_event_initialize(&event, NULL,
1239 (yaml_char_t *)YAML_STR_TAG,
1240 (yaml_char_t *)"health_sensitivity",
1241 strlen("health_sensitivity"),
1243 YAML_PLAIN_SCALAR_STYLE);
1244 rc = yaml_emitter_emit(output, &event);
1248 snprintf(num, sizeof(num), "%d", sen);
1249 yaml_scalar_event_initialize(&event, NULL,
1250 (yaml_char_t *)YAML_INT_TAG,
1253 YAML_PLAIN_SCALAR_STYLE);
1254 rc = yaml_emitter_emit(output, &event);
1259 yaml_mapping_end_event_initialize(&event);
1260 rc = yaml_emitter_emit(output, &event);
1265 static int yaml_lnet_route(char *nw, char *gw, int hops, int prio, int sen,
1266 int version, int flags)
1268 struct nid_node head, *entry;
1269 struct nl_sock *sk = NULL;
1270 const char *msg = NULL;
1271 yaml_emitter_t output;
1272 yaml_parser_t reply;
1276 if (!(flags & NLM_F_DUMP) && (!nw || !gw)) {
1277 fprintf(stdout, "missing mandatory parameters:'%s'\n",
1278 (!nw && !gw) ? "net , gateway" :
1279 !nw ? "net" : "gateway");
1283 /* Create Netlink emitter to send request to kernel */
1284 sk = nl_socket_alloc();
1288 /* Setup parser to receive Netlink packets */
1289 rc = yaml_parser_initialize(&reply);
1295 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1297 msg = yaml_parser_get_reader_error(&reply);
1301 /* Create Netlink emitter to send request to kernel */
1302 rc = yaml_emitter_initialize(&output);
1304 msg = "failed to initialize emitter";
1308 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1309 version, LNET_CMD_ROUTES, flags);
1313 yaml_emitter_open(&output);
1314 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1315 rc = yaml_emitter_emit(&output, &event);
1319 yaml_mapping_start_event_initialize(&event, NULL,
1320 (yaml_char_t *)YAML_MAP_TAG,
1321 1, YAML_ANY_MAPPING_STYLE);
1322 rc = yaml_emitter_emit(&output, &event);
1326 yaml_scalar_event_initialize(&event, NULL,
1327 (yaml_char_t *)YAML_STR_TAG,
1328 (yaml_char_t *)"route",
1329 strlen("route"), 1, 0,
1330 YAML_PLAIN_SCALAR_STYLE);
1331 rc = yaml_emitter_emit(&output, &event);
1335 /* NLM_F_DUMP can have no arguments */
1337 NL_INIT_LIST_HEAD(&head.children);
1338 nl_init_list_head(&head.list);
1340 rc = lustre_lnet_parse_nid_range(&head, gw, &msg);
1342 lustre_lnet_free_list(&head);
1343 yaml_emitter_delete(&output);
1350 yaml_sequence_start_event_initialize(&event, NULL,
1351 (yaml_char_t *)YAML_SEQ_TAG,
1353 YAML_BLOCK_SEQUENCE_STYLE);
1354 rc = yaml_emitter_emit(&output, &event);
1358 if (!nl_list_empty(&head.children)) {
1359 nl_list_for_each_entry(entry, &head.children, list) {
1360 const char *nid = entry->nidstr;
1362 rc = yaml_lnet_router_gateways(&output, nw, nid,
1368 rc = yaml_lnet_router_gateways(&output, nw, NULL, hops,
1374 yaml_sequence_end_event_initialize(&event);
1375 rc = yaml_emitter_emit(&output, &event);
1379 yaml_scalar_event_initialize(&event, NULL,
1380 (yaml_char_t *)YAML_STR_TAG,
1383 YAML_PLAIN_SCALAR_STYLE);
1384 rc = yaml_emitter_emit(&output, &event);
1389 yaml_mapping_end_event_initialize(&event);
1390 rc = yaml_emitter_emit(&output, &event);
1394 yaml_document_end_event_initialize(&event, 0);
1395 rc = yaml_emitter_emit(&output, &event);
1399 rc = yaml_emitter_close(&output);
1402 yaml_emitter_log_error(&output, stderr);
1405 yaml_document_t errmsg;
1407 rc = yaml_parser_load(&reply, &errmsg);
1408 if (rc == 1 && (flags & NLM_F_DUMP)) {
1409 yaml_emitter_t debug;
1411 rc = yaml_emitter_initialize(&debug);
1413 yaml_emitter_set_indent(&debug,
1414 LNET_DEFAULT_INDENT);
1415 yaml_emitter_set_output_file(&debug,
1417 rc = yaml_emitter_dump(&debug, &errmsg);
1419 yaml_emitter_delete(&debug);
1421 msg = yaml_parser_get_reader_error(&reply);
1422 /* If we didn't find any routes just be silent */
1423 if (msg && strcmp(msg, "No routes found") == 0)
1426 yaml_document_delete(&errmsg);
1428 yaml_emitter_delete(&output);
1431 yaml_lnet_print_error(flags, "route", msg);
1434 yaml_parser_delete(&reply);
1437 return rc == 1 ? 0 : rc;
1440 static int jt_add_route(int argc, char **argv)
1442 char *network = NULL, *gateway = NULL;
1443 long int hop = -1, prio = -1, sen = -1;
1444 struct cYAML *err_rc = NULL;
1447 const char *const short_options = "n:g:c:p:";
1448 static const struct option long_options[] = {
1449 { .name = "net", .has_arg = required_argument, .val = 'n' },
1450 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1451 { .name = "hop", .has_arg = required_argument, .val = 'c' },
1452 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1453 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1454 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
1458 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
1462 while ((opt = getopt_long(argc, argv, short_options,
1463 long_options, NULL)) != -1) {
1472 rc = parse_long(optarg, &hop);
1480 rc = parse_long(optarg, &prio);
1488 rc = parse_long(optarg, &sen);
1497 print_help(route_cmds, "route", "add");
1503 rc = yaml_lnet_route(network, gateway, hop, prio, sen,
1504 LNET_GENL_VERSION, NLM_F_CREATE);
1506 if (rc == -EOPNOTSUPP)
1511 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
1514 if (rc != LUSTRE_CFG_RC_NO_ERR)
1515 cYAML_print_tree2file(stderr, err_rc);
1517 cYAML_free_tree(err_rc);
1522 static int yaml_add_ni_tunables(yaml_emitter_t *output,
1523 struct lnet_ioctl_config_lnd_tunables *tunables,
1524 struct lnet_dlc_network_descr *nw_descr)
1526 char num[INT_STRING_LEN];
1530 if (tunables->lt_cmn.lct_peer_timeout < 0 &&
1531 tunables->lt_cmn.lct_peer_tx_credits <= 0 &&
1532 tunables->lt_cmn.lct_peer_rtr_credits <= 0 &&
1533 tunables->lt_cmn.lct_max_tx_credits <= 0)
1534 goto skip_general_settings;
1536 yaml_scalar_event_initialize(&event, NULL,
1537 (yaml_char_t *)YAML_STR_TAG,
1538 (yaml_char_t *)"tunables",
1539 strlen("tunables"), 1, 0,
1540 YAML_PLAIN_SCALAR_STYLE);
1541 rc = yaml_emitter_emit(output, &event);
1545 yaml_mapping_start_event_initialize(&event, NULL,
1546 (yaml_char_t *)YAML_MAP_TAG,
1547 1, YAML_ANY_MAPPING_STYLE);
1548 rc = yaml_emitter_emit(output, &event);
1552 if (tunables->lt_cmn.lct_peer_timeout >= 0) {
1553 yaml_scalar_event_initialize(&event, NULL,
1554 (yaml_char_t *)YAML_STR_TAG,
1555 (yaml_char_t *)"peer_timeout",
1556 strlen("peer_timeout"), 1, 0,
1557 YAML_PLAIN_SCALAR_STYLE);
1558 rc = yaml_emitter_emit(output, &event);
1562 snprintf(num, sizeof(num), "%u",
1563 tunables->lt_cmn.lct_peer_timeout);
1564 yaml_scalar_event_initialize(&event, NULL,
1565 (yaml_char_t *)YAML_INT_TAG,
1568 YAML_PLAIN_SCALAR_STYLE);
1569 rc = yaml_emitter_emit(output, &event);
1574 if (tunables->lt_cmn.lct_peer_tx_credits > 0) {
1575 yaml_scalar_event_initialize(&event, NULL,
1576 (yaml_char_t *)YAML_STR_TAG,
1577 (yaml_char_t *)"peer_credits",
1578 strlen("peer_credits"), 1, 0,
1579 YAML_PLAIN_SCALAR_STYLE);
1580 rc = yaml_emitter_emit(output, &event);
1584 snprintf(num, sizeof(num), "%u",
1585 tunables->lt_cmn.lct_peer_tx_credits);
1586 yaml_scalar_event_initialize(&event, NULL,
1587 (yaml_char_t *)YAML_INT_TAG,
1590 YAML_PLAIN_SCALAR_STYLE);
1591 rc = yaml_emitter_emit(output, &event);
1596 if (tunables->lt_cmn.lct_peer_rtr_credits > 0) {
1597 yaml_scalar_event_initialize(&event, NULL,
1598 (yaml_char_t *)YAML_STR_TAG,
1599 (yaml_char_t *)"peer_buffer_credits",
1600 strlen("peer_buffer_credits"), 1, 0,
1601 YAML_PLAIN_SCALAR_STYLE);
1602 rc = yaml_emitter_emit(output, &event);
1606 snprintf(num, sizeof(num), "%u",
1607 tunables->lt_cmn.lct_peer_rtr_credits);
1608 yaml_scalar_event_initialize(&event, NULL,
1609 (yaml_char_t *)YAML_INT_TAG,
1612 YAML_PLAIN_SCALAR_STYLE);
1613 rc = yaml_emitter_emit(output, &event);
1618 if (tunables->lt_cmn.lct_max_tx_credits > 0) {
1619 yaml_scalar_event_initialize(&event, NULL,
1620 (yaml_char_t *)YAML_STR_TAG,
1621 (yaml_char_t *)"credits",
1622 strlen("credits"), 1, 0,
1623 YAML_PLAIN_SCALAR_STYLE);
1624 rc = yaml_emitter_emit(output, &event);
1628 snprintf(num, sizeof(num), "%u",
1629 tunables->lt_cmn.lct_max_tx_credits);
1630 yaml_scalar_event_initialize(&event, NULL,
1631 (yaml_char_t *)YAML_INT_TAG,
1634 YAML_PLAIN_SCALAR_STYLE);
1635 rc = yaml_emitter_emit(output, &event);
1640 yaml_mapping_end_event_initialize(&event);
1641 rc = yaml_emitter_emit(output, &event);
1645 skip_general_settings:
1646 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1648 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0 ||
1649 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0] ||
1651 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1652 yaml_scalar_event_initialize(&event, NULL,
1653 (yaml_char_t *)YAML_STR_TAG,
1654 (yaml_char_t *)"lnd tunables",
1655 strlen("lnd tunables"), 1, 0,
1656 YAML_PLAIN_SCALAR_STYLE);
1657 rc = yaml_emitter_emit(output, &event);
1661 yaml_mapping_start_event_initialize(&event, NULL,
1662 (yaml_char_t *)YAML_MAP_TAG,
1663 1, YAML_ANY_MAPPING_STYLE);
1664 rc = yaml_emitter_emit(output, &event);
1668 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key > 0) {
1669 yaml_scalar_event_initialize(&event, NULL,
1670 (yaml_char_t *)YAML_STR_TAG,
1671 (yaml_char_t *)"auth_key",
1672 strlen("auth_key"), 1, 0,
1673 YAML_PLAIN_SCALAR_STYLE);
1674 rc = yaml_emitter_emit(output, &event);
1678 snprintf(num, sizeof(num), "%u",
1679 tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key);
1681 yaml_scalar_event_initialize(&event, NULL,
1682 (yaml_char_t *)YAML_INT_TAG,
1685 YAML_PLAIN_SCALAR_STYLE);
1686 rc = yaml_emitter_emit(output, &event);
1691 if (tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0]) {
1692 char *tc = &tunables->lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0];
1694 yaml_scalar_event_initialize(&event, NULL,
1695 (yaml_char_t *)YAML_STR_TAG,
1696 (yaml_char_t *)"traffic_class",
1697 strlen("traffic_class"), 1, 0,
1698 YAML_PLAIN_SCALAR_STYLE);
1699 rc = yaml_emitter_emit(output, &event);
1703 yaml_scalar_event_initialize(&event, NULL,
1704 (yaml_char_t *)YAML_INT_TAG,
1707 YAML_PLAIN_SCALAR_STYLE);
1709 rc = yaml_emitter_emit(output, &event);
1714 if (tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer > 0 ||
1715 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer > 0) {
1718 yaml_scalar_event_initialize(&event, NULL,
1719 (yaml_char_t *)YAML_STR_TAG,
1720 (yaml_char_t *)"conns_per_peer",
1721 strlen("conns_per_peer"), 1, 0,
1722 YAML_PLAIN_SCALAR_STYLE);
1723 rc = yaml_emitter_emit(output, &event);
1727 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND)
1728 cpp = tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer;
1729 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND)
1730 cpp = tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer;
1731 snprintf(num, sizeof(num), "%u", cpp);
1733 yaml_scalar_event_initialize(&event, NULL,
1734 (yaml_char_t *)YAML_INT_TAG,
1737 YAML_PLAIN_SCALAR_STYLE);
1738 rc = yaml_emitter_emit(output, &event);
1743 yaml_mapping_end_event_initialize(&event);
1744 rc = yaml_emitter_emit(output, &event);
1750 static int yaml_lnet_config_ni(char *net_id, char *ip2net,
1751 struct lnet_dlc_network_descr *nw_descr,
1752 struct lnet_ioctl_config_lnd_tunables *tunables,
1753 struct cfs_expr_list *global_cpts,
1754 int version, int flags)
1756 struct lnet_dlc_intf_descr *intf;
1757 struct nl_sock *sk = NULL;
1758 const char *msg = NULL;
1759 yaml_emitter_t output;
1760 yaml_parser_t reply;
1764 if (!(flags & NLM_F_DUMP) && !ip2net && (!nw_descr || nw_descr->nw_id == 0)) {
1765 fprintf(stdout, "missing mandatory parameters in NI config: '%s'",
1766 (!nw_descr) ? "network , interface" :
1767 (nw_descr->nw_id == 0) ? "network" : "interface");
1771 if ((flags == NLM_F_CREATE) && !ip2net && list_empty(&nw_descr->nw_intflist)) {
1772 fprintf(stdout, "creating a local NI needs at least one interface");
1776 /* Create Netlink emitter to send request to kernel */
1777 sk = nl_socket_alloc();
1781 /* Setup parser to receive Netlink packets */
1782 rc = yaml_parser_initialize(&reply);
1788 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1790 msg = yaml_parser_get_reader_error(&reply);
1794 /* Create Netlink emitter to send request to kernel */
1795 rc = yaml_emitter_initialize(&output);
1797 msg = "failed to initialize emitter";
1801 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
1802 version, LNET_CMD_NETS, flags);
1806 yaml_emitter_open(&output);
1807 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1808 rc = yaml_emitter_emit(&output, &event);
1812 yaml_mapping_start_event_initialize(&event, NULL,
1813 (yaml_char_t *)YAML_MAP_TAG,
1814 1, YAML_ANY_MAPPING_STYLE);
1815 rc = yaml_emitter_emit(&output, &event);
1819 yaml_scalar_event_initialize(&event, NULL,
1820 (yaml_char_t *)YAML_STR_TAG,
1821 (yaml_char_t *)"net",
1822 strlen("net"), 1, 0,
1823 YAML_PLAIN_SCALAR_STYLE);
1824 rc = yaml_emitter_emit(&output, &event);
1828 if (net_id || ip2net) {
1829 char *key = net_id ? "net type" : "ip2net";
1830 char *value = net_id ? net_id : ip2net;
1832 yaml_sequence_start_event_initialize(&event, NULL,
1833 (yaml_char_t *)YAML_SEQ_TAG,
1834 1, YAML_ANY_SEQUENCE_STYLE);
1835 rc = yaml_emitter_emit(&output, &event);
1839 yaml_mapping_start_event_initialize(&event, NULL,
1840 (yaml_char_t *)YAML_MAP_TAG,
1841 1, YAML_ANY_MAPPING_STYLE);
1842 rc = yaml_emitter_emit(&output, &event);
1846 yaml_scalar_event_initialize(&event, NULL,
1847 (yaml_char_t *)YAML_STR_TAG,
1850 1, 0, YAML_PLAIN_SCALAR_STYLE);
1851 rc = yaml_emitter_emit(&output, &event);
1855 yaml_scalar_event_initialize(&event, NULL,
1856 (yaml_char_t *)YAML_STR_TAG,
1857 (yaml_char_t *)value,
1858 strlen(value), 1, 0,
1859 YAML_PLAIN_SCALAR_STYLE);
1860 rc = yaml_emitter_emit(&output, &event);
1864 yaml_scalar_event_initialize(&event, NULL,
1865 (yaml_char_t *)YAML_STR_TAG,
1868 YAML_PLAIN_SCALAR_STYLE);
1869 rc = yaml_emitter_emit(&output, &event);
1876 if (!nw_descr || list_empty(&nw_descr->nw_intflist))
1879 yaml_scalar_event_initialize(&event, NULL,
1880 (yaml_char_t *)YAML_STR_TAG,
1881 (yaml_char_t *)"local NI(s)",
1882 strlen("local NI(s)"), 1, 0,
1883 YAML_PLAIN_SCALAR_STYLE);
1884 rc = yaml_emitter_emit(&output, &event);
1888 yaml_sequence_start_event_initialize(&event, NULL,
1889 (yaml_char_t *)YAML_SEQ_TAG,
1890 1, YAML_ANY_SEQUENCE_STYLE);
1891 rc = yaml_emitter_emit(&output, &event);
1895 list_for_each_entry(intf, &nw_descr->nw_intflist,
1897 yaml_mapping_start_event_initialize(&event, NULL,
1898 (yaml_char_t *)YAML_MAP_TAG,
1899 1, YAML_ANY_MAPPING_STYLE);
1900 rc = yaml_emitter_emit(&output, &event);
1904 yaml_scalar_event_initialize(&event, NULL,
1905 (yaml_char_t *)YAML_STR_TAG,
1906 (yaml_char_t *)"interfaces",
1907 strlen("interfaces"), 1, 0,
1908 YAML_PLAIN_SCALAR_STYLE);
1909 rc = yaml_emitter_emit(&output, &event);
1913 yaml_mapping_start_event_initialize(&event, NULL,
1914 (yaml_char_t *)YAML_MAP_TAG,
1915 1, YAML_ANY_MAPPING_STYLE);
1916 rc = yaml_emitter_emit(&output, &event);
1920 yaml_scalar_event_initialize(&event, NULL,
1921 (yaml_char_t *)YAML_STR_TAG,
1924 YAML_PLAIN_SCALAR_STYLE);
1925 rc = yaml_emitter_emit(&output, &event);
1929 yaml_scalar_event_initialize(&event, NULL,
1930 (yaml_char_t *)YAML_STR_TAG,
1931 (yaml_char_t *)intf->intf_name,
1932 strlen(intf->intf_name), 1, 0,
1933 YAML_PLAIN_SCALAR_STYLE);
1934 rc = yaml_emitter_emit(&output, &event);
1938 yaml_mapping_end_event_initialize(&event);
1939 rc = yaml_emitter_emit(&output, &event);
1944 rc = yaml_add_ni_tunables(&output, tunables, nw_descr);
1953 yaml_scalar_event_initialize(&event, NULL,
1954 (yaml_char_t *)YAML_STR_TAG,
1955 (yaml_char_t *)"CPT",
1956 strlen("CPT"), 1, 0,
1957 YAML_PLAIN_SCALAR_STYLE);
1958 rc = yaml_emitter_emit(&output, &event);
1962 yaml_sequence_start_event_initialize(&event, NULL,
1963 (yaml_char_t *)YAML_SEQ_TAG,
1965 YAML_FLOW_SEQUENCE_STYLE);
1966 rc = yaml_emitter_emit(&output, &event);
1970 count = cfs_expr_list_values(global_cpts,
1971 LNET_MAX_SHOW_NUM_CPT,
1973 for (i = 0; i < count; i++) {
1974 char core[INT_STRING_LEN];
1976 snprintf(core, sizeof(core), "%u", cpt_array[i]);
1977 yaml_scalar_event_initialize(&event, NULL,
1978 (yaml_char_t *)YAML_STR_TAG,
1979 (yaml_char_t *)core,
1981 YAML_PLAIN_SCALAR_STYLE);
1982 rc = yaml_emitter_emit(&output, &event);
1987 yaml_sequence_end_event_initialize(&event);
1988 rc = yaml_emitter_emit(&output, &event);
1992 cfs_expr_list_free(global_cpts);
1996 yaml_mapping_end_event_initialize(&event);
1997 rc = yaml_emitter_emit(&output, &event);
2002 yaml_sequence_end_event_initialize(&event);
2003 rc = yaml_emitter_emit(&output, &event);
2007 yaml_mapping_end_event_initialize(&event);
2008 rc = yaml_emitter_emit(&output, &event);
2012 yaml_sequence_end_event_initialize(&event);
2013 rc = yaml_emitter_emit(&output, &event);
2017 yaml_mapping_end_event_initialize(&event);
2018 rc = yaml_emitter_emit(&output, &event);
2022 yaml_document_end_event_initialize(&event, 0);
2023 rc = yaml_emitter_emit(&output, &event);
2027 rc = yaml_emitter_close(&output);
2030 yaml_emitter_log_error(&output, stderr);
2033 yaml_document_t errmsg;
2035 rc = yaml_parser_load(&reply, &errmsg);
2036 if (rc == 1 && (flags & NLM_F_DUMP)) {
2037 yaml_emitter_t debug;
2039 rc = yaml_emitter_initialize(&debug);
2041 yaml_emitter_set_indent(&debug,
2042 LNET_DEFAULT_INDENT);
2043 yaml_emitter_set_output_file(&debug, stdout);
2044 rc = yaml_emitter_dump(&debug, &errmsg);
2046 yaml_emitter_delete(&debug);
2048 msg = yaml_parser_get_reader_error(&reply);
2050 yaml_document_delete(&errmsg);
2052 yaml_emitter_delete(&output);
2055 yaml_lnet_print_error(flags, "net", msg);
2058 yaml_parser_delete(&reply);
2061 return rc == 1 ? 0 : rc;
2064 static int jt_add_ni(int argc, char **argv)
2066 char *ip2net = NULL;
2067 long int pto = -1, pc = -1, pbc = -1, cre = -1, cpp = -1, auth_key = -1;
2068 char *traffic_class = NULL;
2069 struct cYAML *err_rc = NULL;
2070 int rc, opt, cpt_rc = -1;
2071 struct lnet_dlc_network_descr nw_descr;
2072 struct cfs_expr_list *global_cpts = NULL;
2073 struct lnet_ioctl_config_lnd_tunables tunables;
2075 bool skip_mr_route_setup = false;
2076 const char *const short_options = "a:b:c:i:k:m:n:p:r:s:t:T:";
2077 static const struct option long_options[] = {
2078 { .name = "auth-key", .has_arg = required_argument, .val = 'a' },
2079 { .name = "peer-buffer-credits",
2080 .has_arg = required_argument, .val = 'b' },
2081 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
2082 { .name = "if", .has_arg = required_argument, .val = 'i' },
2083 { .name = "skip-mr-route-setup",
2084 .has_arg = no_argument, .val = 'k' },
2085 { .name = "conns-per-peer",
2086 .has_arg = required_argument, .val = 'm' },
2087 { .name = "net", .has_arg = required_argument, .val = 'n' },
2088 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
2089 { .name = "credits", .has_arg = required_argument, .val = 'r' },
2090 { .name = "cpt", .has_arg = required_argument, .val = 's' },
2091 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
2092 { .name = "traffic-class", .has_arg = required_argument, .val = 'T' },
2094 char *net_id = NULL;
2096 memset(&tunables, 0, sizeof(tunables));
2097 lustre_lnet_init_nw_descr(&nw_descr);
2099 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
2103 while ((opt = getopt_long(argc, argv, short_options,
2104 long_options, NULL)) != -1) {
2107 rc = parse_long(optarg, &auth_key);
2115 rc = parse_long(optarg, &pbc);
2123 rc = parse_long(optarg, &pc);
2131 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2133 cYAML_build_error(-1, -1, "ni", "add",
2134 "bad interface list",
2140 skip_mr_route_setup = true;
2143 rc = parse_long(optarg, &cpp);
2152 nw_descr.nw_id = libcfs_str2net(optarg);
2159 rc = parse_long(optarg, &cre);
2167 cpt_rc = cfs_expr_list_parse(optarg,
2169 UINT_MAX, &global_cpts);
2172 rc = parse_long(optarg, &pto);
2180 traffic_class = optarg;
2181 if (strlen(traffic_class) == 0 ||
2182 strlen(traffic_class) >= LNET_MAX_STR_LEN) {
2183 cYAML_build_error(-1, -1, "ni", "add",
2184 "Invalid traffic-class argument",
2186 rc = LUSTRE_CFG_RC_BAD_PARAM;
2191 print_help(net_cmds, "net", "add");
2197 if (auth_key > 0 && LNET_NETTYP(nw_descr.nw_id) == KFILND) {
2198 tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_auth_key = auth_key;
2202 if (traffic_class && LNET_NETTYP(nw_descr.nw_id) == KFILND &&
2203 strlen(traffic_class) < LNET_MAX_STR_LEN) {
2204 strcpy(&tunables.lt_tun.lnd_tun_u.lnd_kfi.lnd_traffic_class_str[0],
2210 if (LNET_NETTYP(nw_descr.nw_id) == SOCKLND && (cpp > -1)) {
2211 tunables.lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
2213 } else if (LNET_NETTYP(nw_descr.nw_id) == O2IBLND && (cpp > -1)) {
2214 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
2218 if (pto >= 0 || pc > 0 || pbc > 0 || cre > 0 || cpp > -1) {
2219 tunables.lt_cmn.lct_peer_timeout = pto;
2220 tunables.lt_cmn.lct_peer_tx_credits = pc;
2221 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
2222 tunables.lt_cmn.lct_max_tx_credits = cre;
2226 if (found && LNET_NETTYP(nw_descr.nw_id) == O2IBLND)
2227 tunables.lt_tun.lnd_tun_u.lnd_o2ib.lnd_map_on_demand = UINT_MAX;
2229 rc = yaml_lnet_config_ni(net_id, ip2net, &nw_descr,
2230 found ? &tunables : NULL,
2231 (cpt_rc == 0) ? global_cpts : NULL,
2232 LNET_GENL_VERSION, NLM_F_CREATE);
2234 if (rc == -EOPNOTSUPP)
2236 if (global_cpts != NULL)
2237 cfs_expr_list_free(global_cpts);
2238 if (rc == 0 && !skip_mr_route_setup)
2239 rc = lustre_lnet_setup_mrrouting(&err_rc);
2243 rc = lustre_lnet_config_ni(&nw_descr,
2244 (cpt_rc == 0) ? global_cpts: NULL,
2245 ip2net, (found) ? &tunables : NULL,
2248 if (global_cpts != NULL)
2249 cfs_expr_list_free(global_cpts);
2252 if (rc != LUSTRE_CFG_RC_NO_ERR)
2253 cYAML_print_tree2file(stderr, err_rc);
2255 cYAML_free_tree(err_rc);
2257 if (rc == LUSTRE_CFG_RC_NO_ERR && !skip_mr_route_setup) {
2259 rc = lustre_lnet_setup_mrrouting(&err_rc);
2261 if (rc != LUSTRE_CFG_RC_NO_ERR)
2262 cYAML_print_tree2file(stderr, err_rc);
2264 cYAML_free_tree(err_rc);
2270 static int jt_del_route(int argc, char **argv)
2272 char *network = NULL, *gateway = NULL;
2273 struct cYAML *err_rc = NULL;
2275 const char *const short_options = "n:g:";
2276 static const struct option long_options[] = {
2277 { .name = "net", .has_arg = required_argument, .val = 'n' },
2278 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2282 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
2286 while ((opt = getopt_long(argc, argv, short_options,
2287 long_options, NULL)) != -1) {
2296 print_help(route_cmds, "route", "del");
2302 rc = yaml_lnet_route(network, gateway, -1, -1, -1, LNET_GENL_VERSION,
2305 if (rc == -EOPNOTSUPP)
2310 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
2312 if (rc != LUSTRE_CFG_RC_NO_ERR)
2313 cYAML_print_tree2file(stderr, err_rc);
2315 cYAML_free_tree(err_rc);
2320 static int jt_del_ni(int argc, char **argv)
2322 struct cYAML *err_rc = NULL;
2324 struct lnet_dlc_network_descr nw_descr;
2325 const char *const short_options = "n:i:";
2326 static const struct option long_options[] = {
2327 { .name = "net", .has_arg = required_argument, .val = 'n' },
2328 { .name = "if", .has_arg = required_argument, .val = 'i' },
2330 char *net_id = NULL;
2332 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
2336 lustre_lnet_init_nw_descr(&nw_descr);
2338 while ((opt = getopt_long(argc, argv, short_options,
2339 long_options, NULL)) != -1) {
2342 nw_descr.nw_id = libcfs_str2net(optarg);
2346 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
2348 cYAML_build_error(-1, -1, "ni", "add",
2349 "bad interface list",
2355 print_help(net_cmds, "net", "del");
2361 rc = yaml_lnet_config_ni(net_id, NULL, &nw_descr, NULL, NULL,
2362 LNET_GENL_VERSION, 0);
2364 if (rc != -EOPNOTSUPP)
2368 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
2370 if (rc != LUSTRE_CFG_RC_NO_ERR)
2371 cYAML_print_tree2file(stderr, err_rc);
2373 cYAML_free_tree(err_rc);
2378 static int jt_show_route(int argc, char **argv)
2380 char *network = NULL, *gateway = NULL;
2381 long int hop = -1, prio = -1;
2382 int detail = 0, rc, opt;
2383 struct cYAML *err_rc = NULL, *show_rc = NULL;
2384 const char *const short_options = "c:n:g:p:v";
2385 static const struct option long_options[] = {
2386 { .name = "net", .has_arg = required_argument, .val = 'n' },
2387 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
2388 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
2389 { .name = "hop", .has_arg = required_argument, .val = 'c' },
2390 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2391 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
2395 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
2399 while ((opt = getopt_long(argc, argv, short_options,
2400 long_options, NULL)) != -1) {
2409 rc = parse_long(optarg, &hop);
2417 rc = parse_long(optarg, &prio);
2428 print_help(route_cmds, "route", "show");
2434 rc = yaml_lnet_route(network, gateway, hop, prio, -1,
2435 detail, NLM_F_DUMP);
2437 if (rc == -EOPNOTSUPP)
2442 rc = lustre_lnet_show_route(network, gateway, hop, prio,
2444 &show_rc, &err_rc, false);
2446 if (rc != LUSTRE_CFG_RC_NO_ERR)
2447 cYAML_print_tree2file(stderr, err_rc);
2449 cYAML_print_tree(show_rc);
2451 cYAML_free_tree(err_rc);
2452 cYAML_free_tree(show_rc);
2457 static int set_value_helper(int argc, char **argv,
2458 int (*cb)(int, bool, char*, int, int, struct cYAML**))
2461 long int healthv = -1;
2463 long int state = -1;
2465 struct cYAML *err_rc = NULL;
2466 const char *const short_options = "t:n:s:a";
2467 static const struct option long_options[] = {
2468 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2469 { .name = "health", .has_arg = required_argument, .val = 't' },
2470 { .name = "state", .has_arg = required_argument, .val = 's' },
2471 { .name = "all", .has_arg = no_argument, .val = 'a' },
2475 while ((opt = getopt_long(argc, argv, short_options,
2476 long_options, NULL)) != -1) {
2482 if (parse_long(optarg, &healthv) != 0)
2486 if (parse_long(optarg, &state) != 0)
2497 rc = cb(healthv, all, nid, state, -1, &err_rc);
2498 if (rc != LUSTRE_CFG_RC_NO_ERR)
2499 cYAML_print_tree2file(stderr, err_rc);
2501 cYAML_free_tree(err_rc);
2506 static int jt_set_ni_value(int argc, char **argv)
2509 long int healthv = -1, cpp = -1;
2512 struct cYAML *err_rc = NULL;
2514 const char *const short_options = "a:m:n:t:";
2515 static const struct option long_options[] = {
2516 { .name = "all", .has_arg = no_argument, .val = 'a' },
2517 { .name = "conns-per-peer", .has_arg = required_argument, .val = 'm' },
2518 { .name = "nid", .has_arg = required_argument, .val = 'n' },
2519 { .name = "health", .has_arg = required_argument, .val = 't' },
2522 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
2526 while ((opt = getopt_long(argc, argv, short_options,
2527 long_options, NULL)) != -1) {
2533 rc = parse_long(optarg, &cpp);
2544 if (parse_long(optarg, &healthv) != 0) {
2556 rc = lustre_lnet_config_ni_conns_per_peer(cpp, all, nid,
2559 rc = lustre_lnet_config_ni_healthv(healthv, all, nid,
2562 if (rc != LUSTRE_CFG_RC_NO_ERR)
2563 cYAML_print_tree2file(stderr, err_rc);
2565 cYAML_free_tree(err_rc);
2570 static int yaml_lnet_peer_display(yaml_parser_t *reply, bool list_only)
2572 yaml_emitter_t debug;
2575 rc = yaml_emitter_initialize(&debug);
2579 yaml_emitter_set_indent(&debug, 6);
2580 yaml_emitter_set_output_file(&debug, stdout);
2589 rc = yaml_parser_parse(reply, &event);
2591 goto report_reply_error;
2593 if (event.type != YAML_SCALAR_EVENT)
2596 value = (char *)event.data.scalar.value;
2597 if (strcmp(value, "peer") == 0) {
2598 yaml_event_delete(&event);
2600 yaml_scalar_event_initialize(&event, NULL,
2601 (yaml_char_t *)YAML_STR_TAG,
2602 (yaml_char_t *)"peer list",
2603 strlen("peer list"),
2605 YAML_PLAIN_SCALAR_STYLE);
2606 } else if (strcmp(value, "primary nid") == 0) {
2607 yaml_event_delete(&event);
2609 yaml_scalar_event_initialize(&event, NULL,
2610 (yaml_char_t *)YAML_STR_TAG,
2611 (yaml_char_t *)"nid",
2614 YAML_PLAIN_SCALAR_STYLE);
2615 rc = yaml_emitter_emit(&debug, &event);
2619 /* Now print NID address */
2620 rc = yaml_parser_parse(reply, &event);
2622 goto report_reply_error;
2624 rc = yaml_emitter_emit(&debug, &event);
2629 while (event.type != YAML_MAPPING_END_EVENT) {
2630 rc = yaml_parser_parse(reply, &event);
2632 goto report_reply_error;
2635 /* we can have map end, seq end, map end or
2636 * just map end event. If we see seq end event
2637 * then skip to next mapping end event
2639 rc = yaml_parser_parse(reply, &event);
2641 goto report_reply_error;
2643 if (event.type == YAML_SEQUENCE_END_EVENT) {
2644 yaml_event_delete(&event);
2646 rc = yaml_parser_parse(reply, &event);
2648 goto report_reply_error;
2652 rc = yaml_emitter_emit(&debug, &event);
2656 done = (event.type == YAML_DOCUMENT_END_EVENT);
2659 yaml_document_t errmsg;
2661 rc = yaml_parser_load(reply, &errmsg);
2663 rc = yaml_emitter_dump(&debug, &errmsg);
2664 yaml_document_delete(&errmsg);
2668 yaml_emitter_log_error(&debug, stderr);
2670 yaml_emitter_delete(&debug);
2675 static int yaml_lnet_peer(char *prim_nid, char *nidstr, bool disable_mr,
2676 int health_value, int state, bool list_only,
2677 int version, int flags)
2679 struct nl_sock *sk = NULL;
2680 const char *msg = NULL;
2681 yaml_emitter_t output;
2682 yaml_parser_t reply;
2686 /* Create Netlink emitter to send request to kernel */
2687 sk = nl_socket_alloc();
2691 /* Setup parser to receive Netlink packets */
2692 rc = yaml_parser_initialize(&reply);
2698 rc = yaml_parser_set_input_netlink(&reply, sk, false);
2700 msg = yaml_parser_get_reader_error(&reply);
2704 /* Create Netlink emitter to send request to kernel */
2705 rc = yaml_emitter_initialize(&output);
2707 msg = "failed to initialize emitter";
2711 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
2712 version, LNET_CMD_PEERS, flags);
2716 yaml_emitter_open(&output);
2717 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
2718 rc = yaml_emitter_emit(&output, &event);
2722 yaml_mapping_start_event_initialize(&event, NULL,
2723 (yaml_char_t *)YAML_MAP_TAG,
2724 1, YAML_ANY_MAPPING_STYLE);
2725 rc = yaml_emitter_emit(&output, &event);
2729 yaml_scalar_event_initialize(&event, NULL,
2730 (yaml_char_t *)YAML_STR_TAG,
2731 (yaml_char_t *)"peer",
2732 strlen("peer"), 1, 0,
2733 YAML_PLAIN_SCALAR_STYLE);
2734 rc = yaml_emitter_emit(&output, &event);
2739 yaml_sequence_start_event_initialize(&event, NULL,
2740 (yaml_char_t *)YAML_SEQ_TAG,
2742 YAML_BLOCK_SEQUENCE_STYLE);
2743 rc = yaml_emitter_emit(&output, &event);
2747 yaml_mapping_start_event_initialize(&event, NULL,
2748 (yaml_char_t *)YAML_MAP_TAG,
2750 YAML_BLOCK_MAPPING_STYLE);
2751 rc = yaml_emitter_emit(&output, &event);
2755 yaml_scalar_event_initialize(&event, NULL,
2756 (yaml_char_t *)YAML_STR_TAG,
2757 (yaml_char_t *)"primary nid",
2758 strlen("primary nid"), 1, 0,
2759 YAML_PLAIN_SCALAR_STYLE);
2760 rc = yaml_emitter_emit(&output, &event);
2764 yaml_scalar_event_initialize(&event, NULL,
2765 (yaml_char_t *)YAML_STR_TAG,
2766 (yaml_char_t *)prim_nid,
2767 strlen(prim_nid), 1, 0,
2768 YAML_PLAIN_SCALAR_STYLE);
2769 rc = yaml_emitter_emit(&output, &event);
2774 yaml_scalar_event_initialize(&event, NULL,
2775 (yaml_char_t *)YAML_STR_TAG,
2776 (yaml_char_t *)"Multi-Rail",
2777 strlen("Multi-Rail"), 1, 0,
2778 YAML_PLAIN_SCALAR_STYLE);
2779 rc = yaml_emitter_emit(&output, &event);
2783 yaml_scalar_event_initialize(&event, NULL,
2784 (yaml_char_t *)YAML_BOOL_TAG,
2785 (yaml_char_t *)"False",
2786 strlen("False"), 1, 0,
2787 YAML_PLAIN_SCALAR_STYLE);
2788 rc = yaml_emitter_emit(&output, &event);
2794 char peer_state[INT_STRING_LEN];
2796 yaml_scalar_event_initialize(&event, NULL,
2797 (yaml_char_t *)YAML_STR_TAG,
2798 (yaml_char_t *)"peer state",
2799 strlen("peer state"), 1, 0,
2800 YAML_PLAIN_SCALAR_STYLE);
2801 rc = yaml_emitter_emit(&output, &event);
2805 snprintf(peer_state, sizeof(peer_state), "%d", state);
2806 yaml_scalar_event_initialize(&event, NULL,
2807 (yaml_char_t *)YAML_INT_TAG,
2808 (yaml_char_t *)peer_state,
2809 strlen(peer_state), 1, 0,
2810 YAML_PLAIN_SCALAR_STYLE);
2811 rc = yaml_emitter_emit(&output, &event);
2816 if (!nidstr && health_value == -1)
2819 yaml_scalar_event_initialize(&event, NULL,
2820 (yaml_char_t *)YAML_STR_TAG,
2821 (yaml_char_t *)"peer ni",
2822 strlen("peer ni"), 1, 0,
2823 YAML_PLAIN_SCALAR_STYLE);
2824 rc = yaml_emitter_emit(&output, &event);
2828 yaml_sequence_start_event_initialize(&event, NULL,
2829 (yaml_char_t *)YAML_SEQ_TAG,
2830 1, YAML_BLOCK_SEQUENCE_STYLE);
2831 rc = yaml_emitter_emit(&output, &event);
2836 struct nid_node head, *entry;
2839 /* If we have LNET_ANY_NID and its NLM_F_REPLACE we
2840 * treat it as the all flag case for lnetctl peer set
2842 if (strcmp(nidstr, "<?>") == 0) {
2843 yaml_mapping_start_event_initialize(&event, NULL,
2844 (yaml_char_t *)YAML_MAP_TAG,
2845 1, YAML_BLOCK_MAPPING_STYLE);
2846 rc = yaml_emitter_emit(&output, &event);
2850 yaml_scalar_event_initialize(&event, NULL,
2851 (yaml_char_t *)YAML_STR_TAG,
2852 (yaml_char_t *)"nid",
2853 strlen("nid"), 1, 0,
2854 YAML_PLAIN_SCALAR_STYLE);
2855 rc = yaml_emitter_emit(&output, &event);
2859 yaml_scalar_event_initialize(&event, NULL,
2860 (yaml_char_t *)YAML_STR_TAG,
2861 (yaml_char_t *)nidstr,
2862 strlen(nidstr), 1, 0,
2863 YAML_PLAIN_SCALAR_STYLE);
2864 rc = yaml_emitter_emit(&output, &event);
2868 yaml_mapping_end_event_initialize(&event);
2869 rc = yaml_emitter_emit(&output, &event);
2876 NL_INIT_LIST_HEAD(&head.children);
2877 nl_init_list_head(&head.list);
2878 rc = lustre_lnet_parse_nid_range(&head, nidstr, &msg);
2880 fprintf(stdout, "can't parse nidrange: \"%s\"\n", nidstr);
2881 lustre_lnet_free_list(&head);
2882 yaml_emitter_delete(&output);
2888 if (nl_list_empty(&head.children)) {
2889 lustre_lnet_free_list(&head);
2890 yaml_emitter_delete(&output);
2891 msg = "Unable to parse nidlist: did not expand to any nids";
2896 rc = 1; /* one means its working */
2898 nl_list_for_each_entry(entry, &head.children, list) {
2899 char *nid = entry->nidstr;
2901 if (count++ > LNET_MAX_NIDS_PER_PEER) {
2902 lustre_lnet_free_list(&head);
2903 yaml_emitter_delete(&output);
2904 msg = "Unable to parse nidlist: specifies more NIDs than allowed";
2910 yaml_mapping_start_event_initialize(&event, NULL,
2911 (yaml_char_t *)YAML_MAP_TAG,
2912 1, YAML_BLOCK_MAPPING_STYLE);
2913 rc = yaml_emitter_emit(&output, &event);
2917 yaml_scalar_event_initialize(&event, NULL,
2918 (yaml_char_t *)YAML_STR_TAG,
2919 (yaml_char_t *)"nid",
2920 strlen("nid"), 1, 0,
2921 YAML_PLAIN_SCALAR_STYLE);
2922 rc = yaml_emitter_emit(&output, &event);
2926 yaml_scalar_event_initialize(&event, NULL,
2927 (yaml_char_t *)YAML_STR_TAG,
2930 YAML_PLAIN_SCALAR_STYLE);
2931 rc = yaml_emitter_emit(&output, &event);
2935 yaml_mapping_end_event_initialize(&event);
2936 rc = yaml_emitter_emit(&output, &event);
2940 lustre_lnet_free_list(&head);
2943 if (health_value >= 0) {
2944 char health[INT_STRING_LEN];
2946 /* Create the mapping for 'health stats'. The value field for
2947 * the mapping is not provided so its treated as a empty string.
2949 yaml_mapping_start_event_initialize(&event, NULL,
2950 (yaml_char_t *)YAML_MAP_TAG,
2951 1, YAML_BLOCK_MAPPING_STYLE);
2952 rc = yaml_emitter_emit(&output, &event);
2956 yaml_scalar_event_initialize(&event, NULL,
2957 (yaml_char_t *)YAML_STR_TAG,
2958 (yaml_char_t *)"health stats",
2959 strlen("health stats"), 1, 0,
2960 YAML_PLAIN_SCALAR_STYLE);
2961 rc = yaml_emitter_emit(&output, &event);
2965 /* Setup all mappings for data related to the 'health stats' */
2966 yaml_mapping_start_event_initialize(&event, NULL,
2967 (yaml_char_t *)YAML_MAP_TAG,
2968 1, YAML_BLOCK_MAPPING_STYLE);
2969 rc = yaml_emitter_emit(&output, &event);
2973 yaml_scalar_event_initialize(&event, NULL,
2974 (yaml_char_t *)YAML_STR_TAG,
2975 (yaml_char_t *)"health value",
2976 strlen("health value"), 1, 0,
2977 YAML_PLAIN_SCALAR_STYLE);
2978 rc = yaml_emitter_emit(&output, &event);
2982 snprintf(health, sizeof(health), "%d", health_value);
2983 yaml_scalar_event_initialize(&event, NULL,
2984 (yaml_char_t *)YAML_INT_TAG,
2985 (yaml_char_t *)health,
2986 strlen(health), 1, 0,
2987 YAML_PLAIN_SCALAR_STYLE);
2988 rc = yaml_emitter_emit(&output, &event);
2992 yaml_mapping_end_event_initialize(&event);
2993 rc = yaml_emitter_emit(&output, &event);
2997 yaml_mapping_end_event_initialize(&event);
2998 rc = yaml_emitter_emit(&output, &event);
3003 yaml_sequence_end_event_initialize(&event);
3004 rc = yaml_emitter_emit(&output, &event);
3008 yaml_mapping_end_event_initialize(&event);
3009 rc = yaml_emitter_emit(&output, &event);
3013 yaml_sequence_end_event_initialize(&event);
3014 rc = yaml_emitter_emit(&output, &event);
3018 yaml_scalar_event_initialize(&event, NULL,
3019 (yaml_char_t *)YAML_STR_TAG,
3022 YAML_PLAIN_SCALAR_STYLE);
3023 rc = yaml_emitter_emit(&output, &event);
3028 yaml_mapping_end_event_initialize(&event);
3029 rc = yaml_emitter_emit(&output, &event);
3033 yaml_document_end_event_initialize(&event, 0);
3034 rc = yaml_emitter_emit(&output, &event);
3038 rc = yaml_emitter_close(&output);
3041 yaml_emitter_log_error(&output, stderr);
3044 rc = yaml_lnet_peer_display(&reply, list_only);
3046 msg = yaml_parser_get_reader_error(&reply);
3047 /* If we didn't find any peers just be silent */
3048 if (msg && strcmp(msg, "No peers found") == 0)
3053 yaml_emitter_delete(&output);
3056 yaml_lnet_print_error(flags, "peer", msg);
3059 yaml_parser_delete(&reply);
3062 return rc == 1 ? 0 : rc;
3065 int yaml_lnet_config_peer_ni_healthv(int healthv, bool all, char *lpni_nid,
3066 int state, int seq_no, struct cYAML **err_rc)
3070 rc = yaml_lnet_peer(lpni_nid ? lpni_nid : "<?>", all ? "<?>" : NULL,
3071 false, healthv, state, false, LNET_GENL_VERSION,
3074 if (rc == -EOPNOTSUPP)
3080 rc = lustre_lnet_config_peer_ni_healthv(healthv, all, lpni_nid,
3083 rc = lustre_lnet_set_peer_state(state, lpni_nid, -1, err_rc);
3084 if (rc != LUSTRE_CFG_RC_NO_ERR)
3085 cYAML_print_tree2file(stderr, *err_rc);
3087 cYAML_free_tree(*err_rc);
3092 static int jt_set_peer_ni_value(int argc, char **argv)
3094 int rc = check_cmd(peer_cmds, "peer", "set", 0, argc, argv);
3099 return set_value_helper(argc, argv, yaml_lnet_config_peer_ni_healthv);
3102 static int jt_show_recovery(int argc, char **argv)
3105 struct cYAML *err_rc = NULL, *show_rc = NULL;
3106 const char *const short_options = "lp";
3107 static const struct option long_options[] = {
3108 { .name = "local", .has_arg = no_argument, .val = 'l' },
3109 { .name = "peer", .has_arg = no_argument, .val = 'p' },
3112 rc = check_cmd(debug_cmds, "debug", "recovery", 0, argc, argv);
3116 while ((opt = getopt_long(argc, argv, short_options,
3117 long_options, NULL)) != -1) {
3120 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
3123 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
3130 if (rc != LUSTRE_CFG_RC_NO_ERR)
3131 cYAML_print_tree2file(stderr, err_rc);
3133 cYAML_print_tree(show_rc);
3135 cYAML_free_tree(err_rc);
3136 cYAML_free_tree(show_rc);
3141 static int jt_show_peer_debug_info(int argc, char **argv)
3144 struct cYAML *err_rc = NULL;
3145 char *peer_nid = optarg;
3146 const char *const short_opts = "k";
3147 const struct option long_opts[] = {
3148 { .name = "nid", .has_arg = required_argument, .val = 'k' },
3151 rc = check_cmd(debug_cmds, "debug", "peer", 0, argc, argv);
3156 while ((opt = getopt_long(argc, argv, short_opts,
3157 long_opts, NULL)) != -1) {
3167 rc = lustre_lnet_show_peer_debug_info(peer_nid, -1, &err_rc);
3169 if (rc != LUSTRE_CFG_RC_NO_ERR)
3170 cYAML_print_tree2file(stderr, err_rc);
3172 cYAML_free_tree(err_rc);
3177 static int jt_show_net(int argc, char **argv)
3179 char *network = NULL;
3181 struct cYAML *err_rc = NULL, *show_rc = NULL;
3182 long int detail = 0;
3183 const char *const short_options = "n:v";
3184 static const struct option long_options[] = {
3185 { .name = "net", .has_arg = required_argument, .val = 'n' },
3186 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3189 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
3193 while ((opt = getopt_long(argc, argv, short_options,
3194 long_options, NULL)) != -1) {
3200 if ((!optarg) && (argv[optind] != NULL) &&
3201 (argv[optind][0] != '-')) {
3202 if (parse_long(argv[optind++], &detail) != 0)
3209 print_help(net_cmds, "net", "show");
3215 rc = yaml_lnet_config_ni(network, NULL, NULL, NULL, NULL,
3216 detail, NLM_F_DUMP);
3218 if (rc != -EOPNOTSUPP)
3222 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
3225 if (rc != LUSTRE_CFG_RC_NO_ERR)
3226 cYAML_print_tree2file(stderr, err_rc);
3228 cYAML_print_tree(show_rc);
3230 cYAML_free_tree(err_rc);
3231 cYAML_free_tree(show_rc);
3236 static int jt_show_routing(int argc, char **argv)
3238 struct cYAML *err_rc = NULL, *show_rc = NULL;
3241 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
3245 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
3247 if (rc != LUSTRE_CFG_RC_NO_ERR)
3248 cYAML_print_tree2file(stderr, err_rc);
3250 cYAML_print_tree(show_rc);
3252 cYAML_free_tree(err_rc);
3253 cYAML_free_tree(show_rc);
3258 static int jt_show_stats(int argc, char **argv)
3261 struct cYAML *show_rc = NULL, *err_rc = NULL;
3263 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
3267 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
3269 if (rc != LUSTRE_CFG_RC_NO_ERR)
3270 cYAML_print_tree2file(stderr, err_rc);
3272 cYAML_print_tree(show_rc);
3274 cYAML_free_tree(err_rc);
3275 cYAML_free_tree(show_rc);
3280 static int jt_show_udsp(int argc, char **argv)
3284 struct cYAML *err_rc = NULL, *show_rc = NULL;
3286 const char *const short_options = "i:";
3287 static const struct option long_options[] = {
3288 { .name = "idx", .has_arg = required_argument, .val = 'i' },
3292 rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
3296 while ((opt = getopt_long(argc, argv, short_options,
3297 long_options, NULL)) != -1) {
3300 rc = parse_long(optarg, &idx);
3301 if (rc != 0 || idx < -1) {
3302 printf("Invalid index \"%s\"\n", optarg);
3307 print_help(net_cmds, "net", "show");
3313 rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
3315 if (rc != LUSTRE_CFG_RC_NO_ERR)
3316 cYAML_print_tree2file(stderr, err_rc);
3318 cYAML_print_tree(show_rc);
3320 cYAML_free_tree(err_rc);
3321 cYAML_free_tree(show_rc);
3326 static int jt_show_global(int argc, char **argv)
3329 struct cYAML *show_rc = NULL, *err_rc = NULL;
3331 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
3335 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3336 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3337 cYAML_print_tree2file(stderr, err_rc);
3341 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3342 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3343 cYAML_print_tree2file(stderr, err_rc);
3347 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3348 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3349 cYAML_print_tree2file(stderr, err_rc);
3353 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3354 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3355 cYAML_print_tree2file(stderr, err_rc);
3359 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3360 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3361 cYAML_print_tree2file(stderr, err_rc);
3365 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3366 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3367 cYAML_print_tree2file(stderr, err_rc);
3371 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3372 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3373 cYAML_print_tree2file(stderr, err_rc);
3377 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3378 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3379 cYAML_print_tree2file(stderr, err_rc);
3383 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3384 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3385 cYAML_print_tree2file(stderr, err_rc);
3389 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3390 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3391 cYAML_print_tree2file(stderr, err_rc);
3395 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3396 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3397 cYAML_print_tree2file(stderr, err_rc);
3401 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3402 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3403 cYAML_print_tree2file(stderr, err_rc);
3407 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3408 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3409 cYAML_print_tree2file(stderr, err_rc);
3414 cYAML_print_tree(show_rc);
3417 cYAML_free_tree(err_rc);
3418 cYAML_free_tree(show_rc);
3423 static int jt_lnet(int argc, char **argv)
3427 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
3431 return cfs_parser(argc, argv, lnet_cmds);
3434 static int jt_route(int argc, char **argv)
3438 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
3442 return cfs_parser(argc, argv, route_cmds);
3445 static int jt_net(int argc, char **argv)
3449 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
3453 return cfs_parser(argc, argv, net_cmds);
3456 static int jt_routing(int argc, char **argv)
3460 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
3464 return cfs_parser(argc, argv, routing_cmds);
3467 static int jt_stats(int argc, char **argv)
3471 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
3475 return cfs_parser(argc, argv, stats_cmds);
3478 static int jt_debug(int argc, char **argv)
3482 rc = check_cmd(debug_cmds, "debug", NULL, 2, argc, argv);
3486 return cfs_parser(argc, argv, debug_cmds);
3489 static int jt_global(int argc, char **argv)
3493 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
3497 return cfs_parser(argc, argv, global_cmds);
3500 static int jt_peers(int argc, char **argv)
3504 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
3508 return cfs_parser(argc, argv, peer_cmds);
3511 static int jt_set(int argc, char **argv)
3515 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
3519 return cfs_parser(argc, argv, set_cmds);
3522 static int jt_udsp(int argc, char **argv)
3526 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
3530 return cfs_parser(argc, argv, udsp_cmds);
3533 static int jt_import(int argc, char **argv)
3536 struct cYAML *err_rc = NULL;
3537 struct cYAML *show_rc = NULL;
3538 int rc = 0, return_rc = 0, opt, opt_found = 0;
3541 const char *const short_options = "adseh";
3542 static const struct option long_options[] = {
3543 { .name = "add", .has_arg = no_argument, .val = 'a' },
3544 { .name = "del", .has_arg = no_argument, .val = 'd' },
3545 { .name = "show", .has_arg = no_argument, .val = 's' },
3546 { .name = "exec", .has_arg = no_argument, .val = 'e' },
3547 { .name = "help", .has_arg = no_argument, .val = 'h' },
3550 while ((opt = getopt_long(argc, argv, short_options,
3551 long_options, NULL)) != -1) {
3565 printf("import FILE\n"
3566 "import < FILE : import a file\n"
3567 "\t--add: add configuration\n"
3568 "\t--del: delete configuration\n"
3569 "\t--show: show configuration\n"
3570 "\t--exec: execute command\n"
3571 "\t--help: display this help\n"
3572 "If no command option is given then --add"
3573 " is assumed by default\n");
3580 /* grab the file name if one exists */
3581 if (opt_found && argc == 3)
3583 else if (!opt_found && argc == 2)
3588 rc = lustre_yaml_config(file, &err_rc);
3589 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3590 cYAML_print_tree(show_rc);
3591 cYAML_free_tree(show_rc);
3594 rc = lustre_yaml_del(file, &err_rc);
3597 rc = lustre_yaml_show(file, &show_rc, &err_rc);
3598 cYAML_print_tree(show_rc);
3599 cYAML_free_tree(show_rc);
3602 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
3603 cYAML_print_tree(show_rc);
3604 cYAML_free_tree(show_rc);
3608 if (rc || return_rc) {
3609 cYAML_print_tree2file(stderr, err_rc);
3610 cYAML_free_tree(err_rc);
3616 static int jt_export(int argc, char **argv)
3618 struct cYAML *show_rc = NULL;
3619 struct cYAML *err_rc = NULL;
3623 bool backup = false;
3626 const char *const short_options = "bh";
3627 static const struct option long_options[] = {
3628 { .name = "backup", .has_arg = no_argument, .val = 'b' },
3629 { .name = "help", .has_arg = no_argument, .val = 'h' },
3632 while ((opt = getopt_long(argc, argv, short_options,
3633 long_options, NULL)) != -1) {
3640 printf("export > FILE.yaml : export configuration\n"
3641 "\t--backup: export only what's necessary for reconfig\n"
3642 "\t--help: display this help\n");
3647 if (backup && argc >= 3)
3649 else if (!backup && argc >= 2)
3655 f = fopen(file, "w");
3660 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
3661 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3662 cYAML_print_tree2file(stderr, err_rc);
3663 cYAML_free_tree(err_rc);
3667 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
3669 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3670 cYAML_print_tree2file(stderr, err_rc);
3671 cYAML_free_tree(err_rc);
3675 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
3676 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3677 cYAML_print_tree2file(stderr, err_rc);
3678 cYAML_free_tree(err_rc);
3682 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
3683 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3684 cYAML_print_tree2file(stderr, err_rc);
3685 cYAML_free_tree(err_rc);
3689 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
3690 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3691 cYAML_print_tree2file(stderr, err_rc);
3692 cYAML_free_tree(err_rc);
3696 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
3697 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3698 cYAML_print_tree2file(stderr, err_rc);
3699 cYAML_free_tree(err_rc);
3703 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
3704 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3705 cYAML_print_tree2file(stderr, err_rc);
3706 cYAML_free_tree(err_rc);
3710 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
3711 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3712 cYAML_print_tree2file(stderr, err_rc);
3713 cYAML_free_tree(err_rc);
3717 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
3718 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3719 cYAML_print_tree2file(stderr, err_rc);
3723 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
3724 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3725 cYAML_print_tree2file(stderr, err_rc);
3729 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
3730 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3731 cYAML_print_tree2file(stderr, err_rc);
3735 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
3736 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3737 cYAML_print_tree2file(stderr, err_rc);
3741 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
3742 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3743 cYAML_print_tree2file(stderr, err_rc);
3747 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
3748 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3749 cYAML_print_tree2file(stderr, err_rc);
3753 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
3754 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3755 cYAML_print_tree2file(stderr, err_rc);
3756 cYAML_free_tree(err_rc);
3760 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
3761 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3762 cYAML_print_tree2file(stderr, err_rc);
3763 cYAML_free_tree(err_rc);
3767 rc = lustre_lnet_show_max_recovery_ping_interval(-1, &show_rc, &err_rc);
3768 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3769 cYAML_print_tree2file(stderr, err_rc);
3770 cYAML_free_tree(err_rc);
3774 rc = lustre_lnet_show_udsp(-1, -1, &show_rc, &err_rc);
3775 if (rc != LUSTRE_CFG_RC_NO_ERR) {
3776 cYAML_print_tree2file(stderr, err_rc);
3777 cYAML_free_tree(err_rc);
3781 if (show_rc != NULL) {
3782 cYAML_print_tree2file(f, show_rc);
3783 cYAML_free_tree(show_rc);
3792 static int jt_peer_nid_common(int argc, char **argv, int cmd)
3794 int flags = cmd == LNETCTL_ADD_CMD ? NLM_F_CREATE : 0;
3795 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
3797 char *prim_nid = NULL, *nidstr = NULL;
3798 char err_str[LNET_MAX_STR_LEN] = "Error";
3799 struct cYAML *err_rc = NULL;
3801 const char *const short_opts = "k:m:n:f:l";
3802 const struct option long_opts[] = {
3803 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
3804 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
3805 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3806 { .name = "force", .has_arg = no_argument, .val = 'f' },
3807 { .name = "lock_prim", .has_arg = no_argument, .val = 'l' },
3810 rc = check_cmd(peer_cmds, "peer",
3811 cmd == LNETCTL_ADD_CMD ? "add" : "del", 2, argc, argv);
3815 while ((opt = getopt_long(argc, argv, short_opts,
3816 long_opts, NULL)) != -1) {
3825 if (cmd == LNETCTL_DEL_CMD) {
3826 rc = LUSTRE_CFG_RC_BAD_PARAM;
3827 snprintf(err_str, LNET_MAX_STR_LEN,
3828 "Unrecognized option '-%c'", opt);
3834 if (cmd == LNETCTL_ADD_CMD) {
3835 rc = LUSTRE_CFG_RC_BAD_PARAM;
3836 snprintf(err_str, LNET_MAX_STR_LEN,
3837 "Unrecognized option '-%c'", opt);
3840 flags |= NLM_F_EXCL;
3843 if (cmd == LNETCTL_DEL_CMD) {
3844 rc = LUSTRE_CFG_RC_BAD_PARAM;
3845 snprintf(err_str, LNET_MAX_STR_LEN,
3846 "Unrecognized option '-%c'", opt);
3849 flags |= NLM_F_EXCL;
3852 print_help(peer_cmds, "peer",
3853 cmd == LNETCTL_ADD_CMD ? "add" : "del");
3859 rc = yaml_lnet_peer(prim_nid, nidstr, !is_mr, -1, -1, false,
3860 LNET_GENL_VERSION, flags);
3862 if (rc == -EOPNOTSUPP)
3867 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
3868 force_lock, -1, &err_rc);
3869 if (rc != LUSTRE_CFG_RC_NO_ERR)
3873 cYAML_build_error(rc, -1, "peer",
3874 cmd == LNETCTL_ADD_CMD ? "add" : "del",
3878 if (rc != LUSTRE_CFG_RC_NO_ERR)
3879 cYAML_print_tree2file(stderr, err_rc);
3881 cYAML_free_tree(err_rc);
3886 static int jt_add_peer_nid(int argc, char **argv)
3888 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
3891 static int jt_del_peer_nid(int argc, char **argv)
3893 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
3896 static int jt_show_peer(int argc, char **argv)
3900 struct cYAML *err_rc = NULL, *show_rc = NULL;
3901 long int detail = 0;
3902 const char *const short_opts = "hn:v::";
3903 const struct option long_opts[] = {
3904 { .name = "help", .has_arg = no_argument, .val = 'h' },
3905 { .name = "nid", .has_arg = required_argument, .val = 'n' },
3906 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
3910 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
3914 while ((opt = getopt_long(argc, argv, short_opts,
3915 long_opts, NULL)) != -1) {
3921 if ((!optarg) && (argv[optind] != NULL) &&
3922 (argv[optind][0] != '-')) {
3923 if (parse_long(argv[optind++], &detail) != 0)
3930 print_help(peer_cmds, "peer", "show");
3936 rc = yaml_lnet_peer(nid, NULL, false, -1, -1, false, detail,
3939 if (rc == -EOPNOTSUPP)
3944 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
3947 if (rc != LUSTRE_CFG_RC_NO_ERR)
3948 cYAML_print_tree2file(stderr, err_rc);
3950 cYAML_print_tree(show_rc);
3952 cYAML_free_tree(err_rc);
3953 cYAML_free_tree(show_rc);
3958 static int jt_list_peer(int argc, char **argv)
3961 struct cYAML *err_rc = NULL, *list_rc = NULL;
3963 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
3967 rc = yaml_lnet_peer(NULL, NULL, false, -1, -1, true, 0, NLM_F_DUMP);
3969 if (rc == -EOPNOTSUPP)
3974 if (rc != LUSTRE_CFG_RC_NO_ERR)
3975 cYAML_print_tree2file(stderr, err_rc);
3977 cYAML_print_tree(list_rc);
3979 cYAML_free_tree(err_rc);
3980 cYAML_free_tree(list_rc);
3985 static int yaml_lnet_ping_display(yaml_parser_t *reply)
3987 yaml_emitter_t debug;
3992 rc = yaml_emitter_initialize(&debug);
3994 yaml_emitter_set_output_file(&debug, stdout);
4001 rc = yaml_parser_parse(reply, &event);
4003 goto report_reply_error;
4005 if (event.type != YAML_SCALAR_EVENT) {
4006 rc = yaml_emitter_emit(&debug, &event);
4010 done = (event.type == YAML_DOCUMENT_END_EVENT);
4014 if (strcmp((char *)event.data.scalar.value, "errno") == 0) {
4015 rc = yaml_emitter_emit(&debug, &event);
4019 rc = yaml_parser_parse(reply, &event);
4021 goto report_reply_error;
4023 rc = parse_long((char *)event.data.scalar.value,
4026 goto report_reply_error;
4028 rc = yaml_emitter_emit(&debug, &event);
4033 } else if (error != 0 &&
4034 strcmp((char *)event.data.scalar.value,
4036 rc = yaml_emitter_emit(&debug, &event);
4040 rc = yaml_parser_parse(reply, &event);
4042 goto report_reply_error;
4044 if (strncmp((char *)event.data.scalar.value,
4045 "failed to ", strlen("failed to ")) == 0) {
4048 snprintf(err, sizeof(err), "%s: %s",
4049 (char *)event.data.scalar.value,
4051 yaml_scalar_event_initialize(&event, NULL,
4052 (yaml_char_t *)YAML_STR_TAG,
4055 YAML_PLAIN_SCALAR_STYLE);
4057 rc = yaml_emitter_emit(&debug, &event);
4063 rc = yaml_emitter_emit(&debug, &event);
4070 yaml_emitter_log_error(&debug, stderr);
4072 yaml_emitter_delete(&debug);
4074 return rc2 ? rc2 : rc;
4077 static int yaml_lnet_ping(char *group, int timeout, char *src_nidstr,
4078 int start, int end, char **nids, int flags)
4080 struct nl_sock *sk = NULL;
4081 const char *msg = NULL;
4082 yaml_emitter_t output;
4083 yaml_parser_t reply;
4087 /* Create Netlink emitter to send request to kernel */
4088 sk = nl_socket_alloc();
4092 /* Setup parser to receive Netlink packets */
4093 rc = yaml_parser_initialize(&reply);
4099 rc = yaml_parser_set_input_netlink(&reply, sk, false);
4101 msg = yaml_parser_get_reader_error(&reply);
4105 /* Create Netlink emitter to send request to kernel */
4106 rc = yaml_emitter_initialize(&output);
4108 msg = "failed to initialize emitter";
4112 rc = yaml_emitter_set_output_netlink(&output, sk, LNET_GENL_NAME,
4113 LNET_GENL_VERSION, LNET_CMD_PING,
4118 yaml_emitter_open(&output);
4119 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
4120 rc = yaml_emitter_emit(&output, &event);
4124 yaml_mapping_start_event_initialize(&event, NULL,
4125 (yaml_char_t *)YAML_MAP_TAG,
4126 1, YAML_ANY_MAPPING_STYLE);
4127 rc = yaml_emitter_emit(&output, &event);
4131 yaml_scalar_event_initialize(&event, NULL,
4132 (yaml_char_t *)YAML_STR_TAG,
4133 (yaml_char_t *)group,
4134 strlen(group), 1, 0,
4135 YAML_PLAIN_SCALAR_STYLE);
4136 rc = yaml_emitter_emit(&output, &event);
4140 yaml_mapping_start_event_initialize(&event, NULL,
4141 (yaml_char_t *)YAML_MAP_TAG,
4142 1, YAML_ANY_MAPPING_STYLE);
4143 rc = yaml_emitter_emit(&output, &event);
4147 if (timeout != 1000 || src_nidstr) {
4149 yaml_scalar_event_initialize(&event, NULL,
4150 (yaml_char_t *)YAML_STR_TAG,
4151 (yaml_char_t *)"source",
4152 strlen("source"), 1, 0,
4153 YAML_PLAIN_SCALAR_STYLE);
4154 rc = yaml_emitter_emit(&output, &event);
4158 yaml_scalar_event_initialize(&event, NULL,
4159 (yaml_char_t *)YAML_STR_TAG,
4160 (yaml_char_t *)src_nidstr,
4161 strlen(src_nidstr), 1, 0,
4162 YAML_PLAIN_SCALAR_STYLE);
4163 rc = yaml_emitter_emit(&output, &event);
4168 if (timeout != 1000) {
4171 yaml_scalar_event_initialize(&event, NULL,
4172 (yaml_char_t *)YAML_STR_TAG,
4173 (yaml_char_t *)"timeout",
4174 strlen("timeout"), 1, 0,
4175 YAML_PLAIN_SCALAR_STYLE);
4176 rc = yaml_emitter_emit(&output, &event);
4180 snprintf(time, sizeof(time), "%u", timeout);
4181 yaml_scalar_event_initialize(&event, NULL,
4182 (yaml_char_t *)YAML_INT_TAG,
4183 (yaml_char_t *)time,
4185 YAML_PLAIN_SCALAR_STYLE);
4186 rc = yaml_emitter_emit(&output, &event);
4192 yaml_scalar_event_initialize(&event, NULL,
4193 (yaml_char_t *)YAML_STR_TAG,
4194 (yaml_char_t *)"nids",
4195 strlen("nids"), 1, 0,
4196 YAML_PLAIN_SCALAR_STYLE);
4197 rc = yaml_emitter_emit(&output, &event);
4201 yaml_sequence_start_event_initialize(&event, NULL,
4202 (yaml_char_t *)YAML_SEQ_TAG,
4203 1, YAML_FLOW_SEQUENCE_STYLE);
4204 rc = yaml_emitter_emit(&output, &event);
4208 for (i = start; i < end; i++) {
4209 yaml_scalar_event_initialize(&event, NULL,
4210 (yaml_char_t *)YAML_STR_TAG,
4211 (yaml_char_t *)nids[i],
4212 strlen(nids[i]), 1, 0,
4213 YAML_PLAIN_SCALAR_STYLE);
4214 rc = yaml_emitter_emit(&output, &event);
4219 yaml_sequence_end_event_initialize(&event);
4220 rc = yaml_emitter_emit(&output, &event);
4224 yaml_mapping_end_event_initialize(&event);
4225 rc = yaml_emitter_emit(&output, &event);
4229 yaml_mapping_end_event_initialize(&event);
4230 rc = yaml_emitter_emit(&output, &event);
4234 yaml_document_end_event_initialize(&event, 0);
4235 rc = yaml_emitter_emit(&output, &event);
4239 rc = yaml_emitter_close(&output);
4242 yaml_emitter_log_error(&output, stderr);
4245 rc = yaml_lnet_ping_display(&reply);
4247 msg = yaml_parser_get_reader_error(&reply);
4249 yaml_emitter_delete(&output);
4252 yaml_lnet_print_error(-1, group, msg);
4256 yaml_parser_delete(&reply);
4259 return rc == 1 ? 0 : rc;
4262 static int jt_ping(int argc, char **argv)
4264 struct cYAML *err_rc = NULL;
4265 struct cYAML *show_rc = NULL;
4268 char *src_nidstr = NULL;
4270 const char *const short_options = "hs:t:";
4271 const struct option long_options[] = {
4272 { .name = "help", .has_arg = no_argument, .val = 'h' },
4273 { .name = "timeout", .has_arg = required_argument, .val = 't' },
4274 { .name = "source", .has_arg = required_argument, .val = 's' },
4277 while ((opt = getopt_long(argc, argv, short_options,
4278 long_options, NULL)) != -1) {
4281 src_nidstr = optarg;
4284 timeout = 1000 * atol(optarg);
4287 printf("ping nid[,nid,...]\n"
4288 "\t --source: source nid\n"
4289 "\t --timeout: ping timeout\n"
4290 "\t --help: display this help\n");
4297 for (; optind < argc; optind++)
4298 rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1,
4302 cYAML_print_tree(show_rc);
4305 cYAML_print_tree2file(stderr, err_rc);
4307 cYAML_free_tree(err_rc);
4308 cYAML_free_tree(show_rc);
4313 static int jt_discover(int argc, char **argv)
4315 struct cYAML *err_rc = NULL;
4316 struct cYAML *show_rc = NULL;
4317 int flags = NLM_F_CREATE;
4320 const char *const short_options = "fh";
4321 const struct option long_options[] = {
4322 { .name = "force", .has_arg = no_argument, .val = 'f' },
4323 { .name = "help", .has_arg = no_argument, .val = 'h' },
4327 while ((opt = getopt_long(argc, argv, short_options,
4328 long_options, NULL)) != -1) {
4331 /* BSD treats NLM_F_CREATE | NLM_F_EXCL as an add */
4332 flags |= NLM_F_EXCL;
4336 printf("discover nid[,nid,...]\n"
4337 "\t --force: force discovery\n"
4338 "\t --help: display this help\n");
4345 if (optind == argc) {
4346 printf("Missing nid argument\n");
4350 rc = yaml_lnet_ping("discover", 1000, NULL, optind, argc, argv,
4353 if (rc != -EOPNOTSUPP)
4357 for (; optind < argc; optind++)
4358 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
4362 cYAML_print_tree(show_rc);
4365 cYAML_print_tree2file(stderr, err_rc);
4367 cYAML_free_tree(err_rc);
4368 cYAML_free_tree(show_rc);
4373 static int jt_add_udsp(int argc, char **argv)
4375 char *src = NULL, *dst = NULL, *rte = NULL;
4376 struct cYAML *err_rc = NULL;
4377 union lnet_udsp_action udsp_action;
4378 long int idx = -1, priority = -1;
4380 char *action_type = "pref";
4382 const char *const short_options = "s:d:r:p:i:";
4383 static const struct option long_options[] = {
4384 { .name = "src", .has_arg = required_argument, .val = 's' },
4385 { .name = "dst", .has_arg = required_argument, .val = 'd' },
4386 { .name = "rte", .has_arg = required_argument, .val = 'r' },
4387 { .name = "priority", .has_arg = required_argument, .val = 'p' },
4388 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4391 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
4395 while ((opt = getopt_long(argc, argv, short_options,
4396 long_options, NULL)) != -1) {
4408 rc = parse_long(optarg, &priority);
4409 if (rc != 0 || priority < 0) {
4410 printf("Invalid priority \"%s\"\n", optarg);
4413 action_type = "priority";
4414 udsp_action.udsp_priority = priority;
4417 rc = parse_long(optarg, &idx);
4418 if (rc != 0 || idx < 0) {
4419 printf("Invalid index \"%s\"\n", optarg);
4424 print_help(udsp_cmds, "udsp", "add");
4430 if (!(src || dst || rte)) {
4431 print_help(udsp_cmds, "udsp", "add");
4435 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
4438 if (rc != LUSTRE_CFG_RC_NO_ERR)
4439 cYAML_print_tree2file(stderr, err_rc);
4441 cYAML_free_tree(err_rc);
4446 static int jt_del_udsp(int argc, char **argv)
4448 struct cYAML *err_rc = NULL;
4453 const char *const short_options = "ai:";
4454 static const struct option long_options[] = {
4455 { .name = "all", .has_arg = no_argument, .val = 'a' },
4456 { .name = "idx", .has_arg = required_argument, .val = 'i' },
4459 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
4463 while ((opt = getopt_long(argc, argv, short_options,
4464 long_options, NULL)) != -1) {
4470 rc = parse_long(optarg, &idx);
4471 if (rc != 0 || idx < -1) {
4472 printf("Invalid index \"%s\"\n", optarg);
4477 print_help(udsp_cmds, "udsp", "del");
4483 if (all && idx != -2) {
4484 printf("Cannot combine --all with --idx\n");
4488 } else if (idx == -2) {
4489 printf("Must specify --idx or --all\n");
4493 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
4494 if (rc != LUSTRE_CFG_RC_NO_ERR)
4495 cYAML_print_tree2file(stderr, err_rc);
4497 cYAML_free_tree(err_rc);
4502 int main(int argc, char **argv)
4505 struct cYAML *err_rc = NULL;
4507 rc = lustre_lnet_config_lib_init();
4509 cYAML_build_error(-1, -1, "lnetctl", "startup",
4510 "cannot register LNet device", &err_rc);
4511 cYAML_print_tree2file(stderr, err_rc);
4515 return cfs_parser(argc, argv, cmd_list);