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_set_tiny(int argc, char **argv);
54 static int jt_set_small(int argc, char **argv);
55 static int jt_set_large(int argc, char **argv);
56 static int jt_set_numa(int argc, char **argv);
57 static int jt_set_retry_count(int argc, char **argv);
58 static int jt_set_transaction_to(int argc, char **argv);
59 static int jt_set_recov_intrv(int argc, char **argv);
60 static int jt_set_rtr_sensitivity(int argc, char **argv);
61 static int jt_set_hsensitivity(int argc, char **argv);
62 static int jt_add_peer_nid(int argc, char **argv);
63 static int jt_del_peer_nid(int argc, char **argv);
64 static int jt_set_max_intf(int argc, char **argv);
65 static int jt_set_discovery(int argc, char **argv);
66 static int jt_set_drop_asym_route(int argc, char **argv);
67 static int jt_list_peer(int argc, char **argv);
68 static int jt_add_udsp(int argc, char **argv);
69 static int jt_del_udsp(int argc, char **argv);
70 /*static int jt_show_peer(int argc, char **argv);*/
71 static int lnetctl_list_commands(int argc, char **argv);
72 static int jt_import(int argc, char **argv);
73 static int jt_export(int argc, char **argv);
74 static int jt_ping(int argc, char **argv);
75 static int jt_discover(int argc, char **argv);
76 static int jt_lnet(int argc, char **argv);
77 static int jt_route(int argc, char **argv);
78 static int jt_net(int argc, char **argv);
79 static int jt_routing(int argc, char **argv);
80 static int jt_set(int argc, char **argv);
81 static int jt_debug(int argc, char **argv);
82 static int jt_stats(int argc, char **argv);
83 static int jt_global(int argc, char **argv);
84 static int jt_peers(int argc, char **argv);
85 static int jt_set_ni_value(int argc, char **argv);
86 static int jt_set_peer_ni_value(int argc, char **argv);
87 static int jt_calc_service_id(int argc, char **argv);
88 static int jt_set_response_tracking(int argc, char **argv);
89 static int jt_set_recovery_limit(int argc, char **argv);
90 static int jt_udsp(int argc, char **argv);
92 command_t cmd_list[] = {
93 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
94 {"route", jt_route, 0, "route {add | del | show | help}"},
95 {"net", jt_net, 0, "net {add | del | show | help}"},
96 {"routing", jt_routing, 0, "routing {show | help}"},
97 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
98 " | routing | numa_range | max_interfaces"
99 " | discovery | drop_asym_route | retry_count"
100 " | transaction_timeout | health_sensitivity"
101 " | recovery_interval | router_sensitivity"
102 " | response_tracking | recovery_limit}"},
103 {"import", jt_import, 0, "import FILE.yaml"},
104 {"export", jt_export, 0, "export FILE.yaml"},
105 {"stats", jt_stats, 0, "stats {show | help}"},
106 {"debug", jt_debug, 0, "debug recovery {local | peer}"},
107 {"global", jt_global, 0, "global {show | help}"},
108 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
109 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
110 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
111 {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
112 {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
113 {"help", Parser_help, 0, "help"},
114 {"exit", Parser_quit, 0, "quit"},
115 {"quit", Parser_quit, 0, "quit"},
116 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
120 command_t lnet_cmds[] = {
121 {"configure", jt_config_lnet, 0, "configure lnet\n"
122 "\t--all: load NI configuration from module parameters\n"},
123 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
127 command_t route_cmds[] = {
128 {"add", jt_add_route, 0, "add a route\n"
129 "\t--net: net name (e.g. tcp0)\n"
130 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
131 "\t--hop: number to final destination (1 < hops < 255)\n"
132 "\t--priority: priority of route (0 - highest prio\n"
133 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
134 {"del", jt_del_route, 0, "delete 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 {"show", jt_show_route, 0, "show routes\n"
138 "\t--net: net name (e.g. tcp0) to filter on\n"
139 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
140 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
141 "\t--priority: priority of route (0 - highest prio to filter on\n"
142 "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
143 "\t--verbose: display detailed output per route\n"},
147 command_t net_cmds[] = {
148 {"add", jt_add_ni, 0, "add a network\n"
149 "\t--net: net name (e.g. tcp0)\n"
150 "\t--if: physical interface (e.g. eth0)\n"
151 "\t--ip2net: specify networks based on IP address patterns\n"
152 "\t--peer-timeout: time to wait before declaring a peer dead\n"
153 "\t--peer-credits: define the max number of inflight messages\n"
154 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
155 "\t--credits: Network Interface credits\n"
156 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
157 {"del", jt_del_ni, 0, "delete a network\n"
158 "\t--net: net name (e.g. tcp0)\n"
159 "\t--if: physical interface (e.g. eth0)\n"},
160 {"show", jt_show_net, 0, "show networks\n"
161 "\t--net: net name (e.g. tcp0) to filter on\n"
162 "\t--verbose: display detailed output per network."
163 " Optional argument of '2' outputs more stats\n"},
164 {"set", jt_set_ni_value, 0, "set local NI specific parameter\n"
165 "\t--nid: NI NID to set the\n"
166 "\t--health: specify health value to set\n"
167 "\t--all: set all NIs value to the one specified\n"},
171 command_t routing_cmds[] = {
172 {"show", jt_show_routing, 0, "show routing information\n"},
176 command_t stats_cmds[] = {
177 {"show", jt_show_stats, 0, "show LNET statistics\n"},
181 command_t debug_cmds[] = {
182 {"recovery", jt_show_recovery, 0, "list recovery queues\n"
183 "\t--local : list local recovery queue\n"
184 "\t--peer : list peer recovery queue\n"},
188 command_t global_cmds[] = {
189 {"show", jt_show_global, 0, "show global variables\n"},
193 command_t set_cmds[] = {
194 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
195 "\tVALUE must be greater than 0\n"},
196 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
197 "\tVALUE must be greater than 0\n"},
198 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
199 "\tVALUE must be greater than 0\n"},
200 {"routing", jt_set_routing, 0, "enable/disable routing\n"
201 "\t0 - disable routing\n"
202 "\t1 - enable routing\n"},
203 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
204 "\tVALUE must be at least 0\n"},
205 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
207 "\tValue must be greater than 16\n"},
208 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
209 "\t0 - disable peer discovery\n"
210 "\t1 - enable peer discovery (default)\n"},
211 {"drop_asym_route", jt_set_drop_asym_route, 0,
212 "drop/accept asymmetrical route messages\n"
213 "\t0 - accept asymmetrical route messages (default)\n"
214 "\t1 - drop asymmetrical route messages\n"},
215 {"retry_count", jt_set_retry_count, 0, "number of retries\n"
216 "\t0 - turn of retries\n"
217 "\t>0 - number of retries\n"},
218 {"transaction_timeout", jt_set_transaction_to, 0, "Message/Response timeout\n"
219 "\t>0 - timeout in seconds\n"},
220 {"health_sensitivity", jt_set_hsensitivity, 0, "sensitivity to failure\n"
221 "\t0 - turn off health evaluation\n"
222 "\t>0 - sensitivity value not more than 1000\n"},
223 {"recovery_interval", jt_set_recov_intrv, 0, "interval to ping in seconds (at least 1)\n"
224 "\t>0 - time in seconds between pings\n"},
225 {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
226 "\t100 - router interfaces need to be fully healthy to be used\n"
227 "\t<100 - router interfaces can be used even if not healthy\n"},
228 {"response_tracking", jt_set_response_tracking, 0,
229 "Set the behavior of response tracking\n"
230 "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
231 "\t1 - GETs are eligible for response tracking\n"
232 "\t2 - PUTs are eligible for response tracking\n"
233 "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
234 "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
235 "\t pings and discovery pushes always utilize response tracking\n"},
236 {"recovery_limit", jt_set_recovery_limit, 0,
237 "Set how long LNet will attempt to recover unhealthy interfaces.\n"
238 "\t0 - Recover indefinitely (default)\n"
239 "\t>0 - Recover for the specified number of seconds.\n"},
243 command_t peer_cmds[] = {
244 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
245 "\t--prim_nid: Primary NID of the peer.\n"
246 "\t--nid: one or more peer NIDs\n"
247 "\t--non_mr: create this peer as not Multi-Rail capable\n"
248 "\t--ip2nets: specify a range of nids per peer"},
249 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
250 "\t--prim_nid: Primary NID of the peer.\n"
251 "\t--nid: list of NIDs to remove. If none provided,\n"
252 "\t peer is deleted\n"
253 "\t--ip2nets: specify a range of nids per peer"},
254 {"show", jt_show_peer, 0, "show peer information\n"
255 "\t--nid: NID of peer to filter on.\n"
256 "\t--verbose: display detailed output per peer."
257 " Optional argument of '2' outputs more stats\n"},
258 {"list", jt_list_peer, 0, "list all peers\n"},
259 {"set", jt_set_peer_ni_value, 0, "set peer ni specific parameter\n"
260 "\t--nid: Peer NI NID to set the\n"
261 "\t--health: specify health value to set\n"
262 "\t--all: set all peer_nis values to the one specified\n"},
266 command_t udsp_cmds[] = {
267 {"add", jt_add_udsp, 0, "add a udsp\n"
268 "\t--src: ip2nets syntax specifying the local NID to match\n"
269 "\t--dst: ip2nets syntax specifying the remote NID to match\n"
270 "\t--rte: ip2nets syntax specifying the router NID to match\n"
271 "\t--priority: priority value (0 - highest priority)\n"
272 "\t--idx: index of where to insert the rule.\n"
273 "\t By default, appends to the end of the rule list.\n"},
274 {"del", jt_del_udsp, 0, "delete a udsp\n"
275 "\t--idx: index of the Policy.\n"},
279 static int jt_calc_service_id(int argc, char **argv)
284 rc = lustre_lnet_calc_service_id(&service_id);
285 if (rc != LUSTRE_CFG_RC_NO_ERR)
289 * cYAML currently doesn't support printing hex values.
290 * Therefore just print it locally here
292 printf("service id:\n value: 0x%llx\n", service_id);
297 static inline void print_help(const command_t cmds[], const char *cmd_type,
300 const command_t *cmd;
302 for (cmd = cmds; cmd->pc_name; cmd++) {
303 if (pc_name != NULL &&
304 strcmp(cmd->pc_name, pc_name) == 0) {
305 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
308 } else if (pc_name != NULL) {
311 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
315 static int parse_long(const char *number, long int *value)
322 *value = strtol(number, &end, 0);
323 if (end != NULL && *end != 0)
329 static int check_cmd(const command_t *cmd_list, const char *cmd,
330 const char *sub_cmd, const int min_args,
331 int argc, char **argv)
338 const char *const short_options = "h";
339 static const struct option long_options[] = {
340 { .name = "help", .has_arg = no_argument, .val = 'h' },
344 if (argc < min_args) {
345 print_help(cmd_list, cmd, sub_cmd);
348 } else if (argc > 2) {
352 while ((opt = getopt_long(argc, argv, short_options,
353 long_options, NULL)) != -1) {
356 print_help(cmd_list, cmd, sub_cmd);
371 static int jt_set_response_tracking(int argc, char **argv)
375 struct cYAML *err_rc = NULL;
377 rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
381 rc = parse_long(argv[1], &value);
383 cYAML_build_error(-1, -1, "parser", "set",
384 "cannot parse response_tracking value",
386 cYAML_print_tree2file(stderr, err_rc);
387 cYAML_free_tree(err_rc);
391 rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
392 if (rc != LUSTRE_CFG_RC_NO_ERR)
393 cYAML_print_tree2file(stderr, err_rc);
395 cYAML_free_tree(err_rc);
400 static int jt_set_recovery_limit(int argc, char **argv)
404 struct cYAML *err_rc = NULL;
406 rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
410 rc = parse_long(argv[1], &value);
412 cYAML_build_error(-1, -1, "parser", "set",
413 "cannot parse recovery_limit value",
415 cYAML_print_tree2file(stderr, err_rc);
416 cYAML_free_tree(err_rc);
420 rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
421 if (rc != LUSTRE_CFG_RC_NO_ERR)
422 cYAML_print_tree2file(stderr, err_rc);
424 cYAML_free_tree(err_rc);
429 static int jt_set_max_intf(int argc, char **argv)
433 struct cYAML *err_rc = NULL;
435 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
439 rc = parse_long(argv[1], &value);
441 cYAML_build_error(-1, -1, "parser", "set",
442 "cannot parse max_interfaces value", &err_rc);
443 cYAML_print_tree2file(stderr, err_rc);
444 cYAML_free_tree(err_rc);
448 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
449 if (rc != LUSTRE_CFG_RC_NO_ERR)
450 cYAML_print_tree2file(stderr, err_rc);
452 cYAML_free_tree(err_rc);
457 static int jt_set_numa(int argc, char **argv)
461 struct cYAML *err_rc = NULL;
463 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
467 rc = parse_long(argv[1], &value);
469 cYAML_build_error(-1, -1, "parser", "set",
470 "cannot parse numa_range value", &err_rc);
471 cYAML_print_tree2file(stderr, err_rc);
472 cYAML_free_tree(err_rc);
476 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
477 if (rc != LUSTRE_CFG_RC_NO_ERR)
478 cYAML_print_tree2file(stderr, err_rc);
480 cYAML_free_tree(err_rc);
485 static int jt_set_recov_intrv(int argc, char **argv)
489 struct cYAML *err_rc = NULL;
491 rc = check_cmd(set_cmds, "set", "recovery_interval", 2, argc, argv);
495 rc = parse_long(argv[1], &value);
497 cYAML_build_error(-1, -1, "parser", "set",
498 "cannot parse recovery interval value", &err_rc);
499 cYAML_print_tree2file(stderr, err_rc);
500 cYAML_free_tree(err_rc);
504 rc = lustre_lnet_config_recov_intrv(value, -1, &err_rc);
505 if (rc != LUSTRE_CFG_RC_NO_ERR)
506 cYAML_print_tree2file(stderr, err_rc);
508 cYAML_free_tree(err_rc);
513 static int jt_set_rtr_sensitivity(int argc, char **argv)
517 struct cYAML *err_rc = NULL;
519 rc = check_cmd(set_cmds, "set", "router_sensitivity", 2, argc, argv);
523 rc = parse_long(argv[1], &value);
525 cYAML_build_error(-1, -1, "parser", "set",
526 "cannot parse router sensitivity value", &err_rc);
527 cYAML_print_tree2file(stderr, err_rc);
528 cYAML_free_tree(err_rc);
532 rc = lustre_lnet_config_rtr_sensitivity(value, -1, &err_rc);
533 if (rc != LUSTRE_CFG_RC_NO_ERR)
534 cYAML_print_tree2file(stderr, err_rc);
536 cYAML_free_tree(err_rc);
541 static int jt_set_hsensitivity(int argc, char **argv)
545 struct cYAML *err_rc = NULL;
547 rc = check_cmd(set_cmds, "set", "health_sensitivity", 2, argc, argv);
551 rc = parse_long(argv[1], &value);
553 cYAML_build_error(-1, -1, "parser", "set",
554 "cannot parse health sensitivity value", &err_rc);
555 cYAML_print_tree2file(stderr, err_rc);
556 cYAML_free_tree(err_rc);
560 rc = lustre_lnet_config_hsensitivity(value, -1, &err_rc);
561 if (rc != LUSTRE_CFG_RC_NO_ERR)
562 cYAML_print_tree2file(stderr, err_rc);
564 cYAML_free_tree(err_rc);
569 static int jt_set_transaction_to(int argc, char **argv)
573 struct cYAML *err_rc = NULL;
575 rc = check_cmd(set_cmds, "set", "transaction_timeout", 2, argc, argv);
579 rc = parse_long(argv[1], &value);
581 cYAML_build_error(-1, -1, "parser", "set",
582 "cannot parse transaction timeout value", &err_rc);
583 cYAML_print_tree2file(stderr, err_rc);
584 cYAML_free_tree(err_rc);
588 rc = lustre_lnet_config_transaction_to(value, -1, &err_rc);
589 if (rc != LUSTRE_CFG_RC_NO_ERR)
590 cYAML_print_tree2file(stderr, err_rc);
592 cYAML_free_tree(err_rc);
597 static int jt_set_retry_count(int argc, char **argv)
601 struct cYAML *err_rc = NULL;
603 rc = check_cmd(set_cmds, "set", "retry_count", 2, argc, argv);
607 rc = parse_long(argv[1], &value);
609 cYAML_build_error(-1, -1, "parser", "set",
610 "cannot parse retry_count value", &err_rc);
611 cYAML_print_tree2file(stderr, err_rc);
612 cYAML_free_tree(err_rc);
616 rc = lustre_lnet_config_retry_count(value, -1, &err_rc);
617 if (rc != LUSTRE_CFG_RC_NO_ERR)
618 cYAML_print_tree2file(stderr, err_rc);
620 cYAML_free_tree(err_rc);
625 static int jt_set_discovery(int argc, char **argv)
629 struct cYAML *err_rc = NULL;
631 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
635 rc = parse_long(argv[1], &value);
637 cYAML_build_error(-1, -1, "parser", "set",
638 "cannot parse discovery value", &err_rc);
639 cYAML_print_tree2file(stderr, err_rc);
640 cYAML_free_tree(err_rc);
644 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
645 if (rc != LUSTRE_CFG_RC_NO_ERR)
646 cYAML_print_tree2file(stderr, err_rc);
648 cYAML_free_tree(err_rc);
653 static int jt_set_drop_asym_route(int argc, char **argv)
657 struct cYAML *err_rc = NULL;
659 rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
663 rc = parse_long(argv[1], &value);
665 cYAML_build_error(-1, -1, "parser", "set",
666 "cannot parse drop_asym_route value",
668 cYAML_print_tree2file(stderr, err_rc);
669 cYAML_free_tree(err_rc);
673 rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
674 if (rc != LUSTRE_CFG_RC_NO_ERR)
675 cYAML_print_tree2file(stderr, err_rc);
677 cYAML_free_tree(err_rc);
682 static int jt_set_tiny(int argc, char **argv)
686 struct cYAML *err_rc = NULL;
688 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
692 rc = parse_long(argv[1], &value);
694 cYAML_build_error(-1, -1, "parser", "set",
695 "cannot parse tiny_buffers value", &err_rc);
696 cYAML_print_tree2file(stderr, err_rc);
697 cYAML_free_tree(err_rc);
701 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
702 if (rc != LUSTRE_CFG_RC_NO_ERR)
703 cYAML_print_tree2file(stderr, err_rc);
705 cYAML_free_tree(err_rc);
710 static int jt_set_small(int argc, char **argv)
714 struct cYAML *err_rc = NULL;
716 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
720 rc = parse_long(argv[1], &value);
722 cYAML_build_error(-1, -1, "parser", "set",
723 "cannot parse small_buffers value", &err_rc);
724 cYAML_print_tree2file(stderr, err_rc);
725 cYAML_free_tree(err_rc);
729 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
730 if (rc != LUSTRE_CFG_RC_NO_ERR)
731 cYAML_print_tree2file(stderr, err_rc);
733 cYAML_free_tree(err_rc);
738 static int jt_set_large(int argc, char **argv)
742 struct cYAML *err_rc = NULL;
744 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
748 rc = parse_long(argv[1], &value);
750 cYAML_build_error(-1, -1, "parser", "set",
751 "cannot parse large_buffers value", &err_rc);
752 cYAML_print_tree2file(stderr, err_rc);
753 cYAML_free_tree(err_rc);
757 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
758 if (rc != LUSTRE_CFG_RC_NO_ERR)
759 cYAML_print_tree2file(stderr, err_rc);
761 cYAML_free_tree(err_rc);
766 static int jt_set_routing(int argc, char **argv)
769 struct cYAML *err_rc = NULL;
772 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
776 rc = parse_long(argv[1], &value);
777 if (rc != 0 || (value != 0 && value != 1)) {
778 cYAML_build_error(-1, -1, "parser", "set",
779 "cannot parse routing value.\n"
780 "must be 0 for disable or 1 for enable",
782 cYAML_print_tree2file(stderr, err_rc);
783 cYAML_free_tree(err_rc);
787 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
789 if (rc != LUSTRE_CFG_RC_NO_ERR)
790 cYAML_print_tree2file(stderr, err_rc);
792 cYAML_free_tree(err_rc);
797 static int jt_config_lnet(int argc, char **argv)
799 struct cYAML *err_rc = NULL;
800 bool load_mod_params = false;
803 const char *const short_options = "a";
804 static const struct option long_options[] = {
805 { .name = "all", .has_arg = no_argument, .val = 'a' },
809 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
813 while ((opt = getopt_long(argc, argv, short_options,
814 long_options, NULL)) != -1) {
817 load_mod_params = true;
824 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
827 if (rc != LUSTRE_CFG_RC_NO_ERR)
828 cYAML_print_tree2file(stderr, err_rc);
830 cYAML_free_tree(err_rc);
835 static int jt_unconfig_lnet(int argc, char **argv)
837 struct cYAML *err_rc = NULL;
840 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
844 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
846 if (rc != LUSTRE_CFG_RC_NO_ERR)
847 cYAML_print_tree2file(stderr, err_rc);
849 cYAML_free_tree(err_rc);
853 static int jt_add_route(int argc, char **argv)
855 char *network = NULL, *gateway = NULL;
856 long int hop = -1, prio = -1, sen = -1;
857 struct cYAML *err_rc = NULL;
860 const char *const short_options = "n:g:c:p:";
861 static const struct option long_options[] = {
862 { .name = "net", .has_arg = required_argument, .val = 'n' },
863 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
864 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
865 { .name = "priority", .has_arg = required_argument, .val = 'p' },
866 { .name = "health_sensitivity", .has_arg = required_argument, .val = 's' },
869 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
873 while ((opt = getopt_long(argc, argv, short_options,
874 long_options, NULL)) != -1) {
883 rc = parse_long(optarg, &hop);
891 rc = parse_long(optarg, &prio);
899 rc = parse_long(optarg, &sen);
908 print_help(route_cmds, "route", "add");
914 rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
917 if (rc != LUSTRE_CFG_RC_NO_ERR)
918 cYAML_print_tree2file(stderr, err_rc);
920 cYAML_free_tree(err_rc);
925 static int jt_add_ni(int argc, char **argv)
928 long int pto = -1, pc = -1, pbc = -1, cre = -1;
929 struct cYAML *err_rc = NULL;
930 int rc, opt, cpt_rc = -1;
931 struct lnet_dlc_network_descr nw_descr;
932 struct cfs_expr_list *global_cpts = NULL;
933 struct lnet_ioctl_config_lnd_tunables tunables;
936 memset(&tunables, 0, sizeof(tunables));
937 lustre_lnet_init_nw_descr(&nw_descr);
939 const char *const short_options = "n:i:p:t:c:b:r:s:";
940 static const struct option long_options[] = {
941 { .name = "net", .has_arg = required_argument, .val = 'n' },
942 { .name = "if", .has_arg = required_argument, .val = 'i' },
943 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
944 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
945 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
946 { .name = "peer-buffer-credits",
947 .has_arg = required_argument, .val = 'b' },
948 { .name = "credits", .has_arg = required_argument, .val = 'r' },
949 { .name = "cpt", .has_arg = required_argument, .val = 's' },
952 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
956 while ((opt = getopt_long(argc, argv, short_options,
957 long_options, NULL)) != -1) {
960 nw_descr.nw_id = libcfs_str2net(optarg);
963 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
965 cYAML_build_error(-1, -1, "ni", "add",
966 "bad interface list",
975 rc = parse_long(optarg, &pto);
983 rc = parse_long(optarg, &pc);
991 rc = parse_long(optarg, &pbc);
999 rc = parse_long(optarg, &cre);
1007 cpt_rc = cfs_expr_list_parse(optarg,
1009 UINT_MAX, &global_cpts);
1012 print_help(net_cmds, "net", "add");
1018 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
1019 tunables.lt_cmn.lct_peer_timeout = pto;
1020 tunables.lt_cmn.lct_peer_tx_credits = pc;
1021 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
1022 tunables.lt_cmn.lct_max_tx_credits = cre;
1026 rc = lustre_lnet_config_ni(&nw_descr,
1027 (cpt_rc == 0) ? global_cpts: NULL,
1028 ip2net, (found) ? &tunables : NULL,
1031 if (global_cpts != NULL)
1032 cfs_expr_list_free(global_cpts);
1035 if (rc != LUSTRE_CFG_RC_NO_ERR)
1036 cYAML_print_tree2file(stderr, err_rc);
1038 cYAML_free_tree(err_rc);
1043 static int jt_del_route(int argc, char **argv)
1045 char *network = NULL, *gateway = NULL;
1046 struct cYAML *err_rc = NULL;
1049 const char *const short_options = "n:g:";
1050 static const struct option long_options[] = {
1051 { .name = "net", .has_arg = required_argument, .val = 'n' },
1052 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1055 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
1059 while ((opt = getopt_long(argc, argv, short_options,
1060 long_options, NULL)) != -1) {
1069 print_help(route_cmds, "route", "del");
1075 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
1077 if (rc != LUSTRE_CFG_RC_NO_ERR)
1078 cYAML_print_tree2file(stderr, err_rc);
1080 cYAML_free_tree(err_rc);
1085 static int jt_del_ni(int argc, char **argv)
1087 struct cYAML *err_rc = NULL;
1089 struct lnet_dlc_network_descr nw_descr;
1091 lustre_lnet_init_nw_descr(&nw_descr);
1093 const char *const short_options = "n:i:";
1094 static const struct option long_options[] = {
1095 { .name = "net", .has_arg = required_argument, .val = 'n' },
1096 { .name = "if", .has_arg = required_argument, .val = 'i' },
1099 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
1103 while ((opt = getopt_long(argc, argv, short_options,
1104 long_options, NULL)) != -1) {
1107 nw_descr.nw_id = libcfs_str2net(optarg);
1110 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
1112 cYAML_build_error(-1, -1, "ni", "add",
1113 "bad interface list",
1119 print_help(net_cmds, "net", "del");
1125 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
1128 if (rc != LUSTRE_CFG_RC_NO_ERR)
1129 cYAML_print_tree2file(stderr, err_rc);
1131 cYAML_free_tree(err_rc);
1136 static int jt_show_route(int argc, char **argv)
1138 char *network = NULL, *gateway = NULL;
1139 long int hop = -1, prio = -1;
1140 int detail = 0, rc, opt;
1141 struct cYAML *err_rc = NULL, *show_rc = NULL;
1143 const char *const short_options = "n:g:h:p:v";
1144 static const struct option long_options[] = {
1145 { .name = "net", .has_arg = required_argument, .val = 'n' },
1146 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
1147 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
1148 { .name = "priority", .has_arg = required_argument, .val = 'p' },
1149 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
1152 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
1156 while ((opt = getopt_long(argc, argv, short_options,
1157 long_options, NULL)) != -1) {
1166 rc = parse_long(optarg, &hop);
1174 rc = parse_long(optarg, &prio);
1185 print_help(route_cmds, "route", "show");
1191 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
1192 &show_rc, &err_rc, false);
1194 if (rc != LUSTRE_CFG_RC_NO_ERR)
1195 cYAML_print_tree2file(stderr, err_rc);
1197 cYAML_print_tree(show_rc);
1199 cYAML_free_tree(err_rc);
1200 cYAML_free_tree(show_rc);
1205 static int set_value_helper(int argc, char **argv,
1206 int (*cb)(int, bool, char*, int, struct cYAML**))
1209 long int healthv = -1;
1212 struct cYAML *err_rc = NULL;
1214 const char *const short_options = "t:n:a";
1215 static const struct option long_options[] = {
1216 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1217 { .name = "health", .has_arg = required_argument, .val = 't' },
1218 { .name = "all", .has_arg = no_argument, .val = 'a' },
1221 rc = check_cmd(net_cmds, "net", "set", 0, argc, argv);
1225 while ((opt = getopt_long(argc, argv, short_options,
1226 long_options, NULL)) != -1) {
1232 if (parse_long(optarg, &healthv) != 0)
1243 rc = cb(healthv, all, nid, -1, &err_rc);
1245 if (rc != LUSTRE_CFG_RC_NO_ERR)
1246 cYAML_print_tree2file(stderr, err_rc);
1248 cYAML_free_tree(err_rc);
1253 static int jt_set_ni_value(int argc, char **argv)
1255 return set_value_helper(argc, argv, lustre_lnet_config_ni_healthv);
1258 static int jt_set_peer_ni_value(int argc, char **argv)
1260 return set_value_helper(argc, argv, lustre_lnet_config_peer_ni_healthv);
1263 static int jt_show_recovery(int argc, char **argv)
1266 struct cYAML *err_rc = NULL, *show_rc = NULL;
1268 const char *const short_options = "lp";
1269 static const struct option long_options[] = {
1270 { .name = "local", .has_arg = no_argument, .val = 'l' },
1271 { .name = "peer", .has_arg = no_argument, .val = 'p' },
1274 rc = check_cmd(debug_cmds, "recovery", NULL, 0, argc, argv);
1278 while ((opt = getopt_long(argc, argv, short_options,
1279 long_options, NULL)) != -1) {
1282 rc = lustre_lnet_show_local_ni_recovq(-1, &show_rc, &err_rc);
1285 rc = lustre_lnet_show_peer_ni_recovq(-1, &show_rc, &err_rc);
1292 if (rc != LUSTRE_CFG_RC_NO_ERR)
1293 cYAML_print_tree2file(stderr, err_rc);
1295 cYAML_print_tree(show_rc);
1297 cYAML_free_tree(err_rc);
1298 cYAML_free_tree(show_rc);
1303 static int jt_show_net(int argc, char **argv)
1305 char *network = NULL;
1307 struct cYAML *err_rc = NULL, *show_rc = NULL;
1308 long int detail = 0;
1310 const char *const short_options = "n:v";
1311 static const struct option long_options[] = {
1312 { .name = "net", .has_arg = required_argument, .val = 'n' },
1313 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1316 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
1320 while ((opt = getopt_long(argc, argv, short_options,
1321 long_options, NULL)) != -1) {
1327 if ((!optarg) && (argv[optind] != NULL) &&
1328 (argv[optind][0] != '-')) {
1329 if (parse_long(argv[optind++], &detail) != 0)
1336 print_help(net_cmds, "net", "show");
1342 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
1345 if (rc != LUSTRE_CFG_RC_NO_ERR)
1346 cYAML_print_tree2file(stderr, err_rc);
1348 cYAML_print_tree(show_rc);
1350 cYAML_free_tree(err_rc);
1351 cYAML_free_tree(show_rc);
1356 static int jt_show_routing(int argc, char **argv)
1358 struct cYAML *err_rc = NULL, *show_rc = NULL;
1361 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
1365 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
1367 if (rc != LUSTRE_CFG_RC_NO_ERR)
1368 cYAML_print_tree2file(stderr, err_rc);
1370 cYAML_print_tree(show_rc);
1372 cYAML_free_tree(err_rc);
1373 cYAML_free_tree(show_rc);
1378 static int jt_show_stats(int argc, char **argv)
1381 struct cYAML *show_rc = NULL, *err_rc = NULL;
1383 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
1387 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
1389 if (rc != LUSTRE_CFG_RC_NO_ERR)
1390 cYAML_print_tree2file(stderr, err_rc);
1392 cYAML_print_tree(show_rc);
1394 cYAML_free_tree(err_rc);
1395 cYAML_free_tree(show_rc);
1400 static int jt_show_global(int argc, char **argv)
1403 struct cYAML *show_rc = NULL, *err_rc = NULL;
1405 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
1409 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1410 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1411 cYAML_print_tree2file(stderr, err_rc);
1415 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1416 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1417 cYAML_print_tree2file(stderr, err_rc);
1421 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1422 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1423 cYAML_print_tree2file(stderr, err_rc);
1427 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1428 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1429 cYAML_print_tree2file(stderr, err_rc);
1433 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1434 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1435 cYAML_print_tree2file(stderr, err_rc);
1439 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1440 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1441 cYAML_print_tree2file(stderr, err_rc);
1445 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1446 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1447 cYAML_print_tree2file(stderr, err_rc);
1451 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1452 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1453 cYAML_print_tree2file(stderr, err_rc);
1457 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1458 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1459 cYAML_print_tree2file(stderr, err_rc);
1463 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1464 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1465 cYAML_print_tree2file(stderr, err_rc);
1469 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1470 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1471 cYAML_print_tree2file(stderr, err_rc);
1475 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1476 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1477 cYAML_print_tree2file(stderr, err_rc);
1482 cYAML_print_tree(show_rc);
1485 cYAML_free_tree(err_rc);
1486 cYAML_free_tree(show_rc);
1491 static int jt_lnet(int argc, char **argv)
1495 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
1499 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1502 static int jt_route(int argc, char **argv)
1506 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1510 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1513 static int jt_net(int argc, char **argv)
1517 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1521 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1524 static int jt_routing(int argc, char **argv)
1528 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1532 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1535 static int jt_stats(int argc, char **argv)
1539 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1543 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1546 static int jt_debug(int argc, char **argv)
1550 rc = check_cmd(debug_cmds, "recovery", NULL, 2, argc, argv);
1554 return Parser_execarg(argc - 1, &argv[1], debug_cmds);
1557 static int jt_global(int argc, char **argv)
1561 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1565 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1568 static int jt_peers(int argc, char **argv)
1572 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1576 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1579 static int jt_set(int argc, char **argv)
1583 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1587 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1590 static int jt_udsp(int argc, char **argv)
1594 rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
1598 return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
1601 static int jt_import(int argc, char **argv)
1604 struct cYAML *err_rc = NULL;
1605 struct cYAML *show_rc = NULL;
1606 int rc = 0, return_rc = 0, opt, opt_found = 0;
1609 const char *const short_options = "adseh";
1610 static const struct option long_options[] = {
1611 { .name = "add", .has_arg = no_argument, .val = 'a' },
1612 { .name = "del", .has_arg = no_argument, .val = 'd' },
1613 { .name = "show", .has_arg = no_argument, .val = 's' },
1614 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1615 { .name = "help", .has_arg = no_argument, .val = 'h' },
1618 while ((opt = getopt_long(argc, argv, short_options,
1619 long_options, NULL)) != -1) {
1633 printf("import FILE\n"
1634 "import < FILE : import a file\n"
1635 "\t--add: add configuration\n"
1636 "\t--del: delete configuration\n"
1637 "\t--show: show configuration\n"
1638 "\t--exec: execute command\n"
1639 "\t--help: display this help\n"
1640 "If no command option is given then --add"
1641 " is assumed by default\n");
1648 /* grab the file name if one exists */
1649 if (opt_found && argc == 3)
1651 else if (!opt_found && argc == 2)
1656 rc = lustre_yaml_config(file, &err_rc);
1657 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1658 cYAML_print_tree(show_rc);
1659 cYAML_free_tree(show_rc);
1662 rc = lustre_yaml_del(file, &err_rc);
1665 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1666 cYAML_print_tree(show_rc);
1667 cYAML_free_tree(show_rc);
1670 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1671 cYAML_print_tree(show_rc);
1672 cYAML_free_tree(show_rc);
1676 if (rc || return_rc) {
1677 cYAML_print_tree2file(stderr, err_rc);
1678 cYAML_free_tree(err_rc);
1684 static int jt_export(int argc, char **argv)
1686 struct cYAML *show_rc = NULL;
1687 struct cYAML *err_rc = NULL;
1691 bool backup = false;
1694 const char *const short_options = "bh";
1695 static const struct option long_options[] = {
1696 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1697 { .name = "help", .has_arg = no_argument, .val = 'h' },
1700 while ((opt = getopt_long(argc, argv, short_options,
1701 long_options, NULL)) != -1) {
1708 printf("export > FILE.yaml : export configuration\n"
1709 "\t--backup: export only what's necessary for reconfig\n"
1710 "\t--help: display this help\n");
1715 if (backup && argc >= 3)
1717 else if (!backup && argc >= 2)
1723 f = fopen(file, "w");
1728 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1729 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1730 cYAML_print_tree2file(stderr, err_rc);
1731 cYAML_free_tree(err_rc);
1735 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1737 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1738 cYAML_print_tree2file(stderr, err_rc);
1739 cYAML_free_tree(err_rc);
1743 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1744 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1745 cYAML_print_tree2file(stderr, err_rc);
1746 cYAML_free_tree(err_rc);
1750 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1751 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1752 cYAML_print_tree2file(stderr, err_rc);
1753 cYAML_free_tree(err_rc);
1757 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1758 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1759 cYAML_print_tree2file(stderr, err_rc);
1760 cYAML_free_tree(err_rc);
1764 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1765 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1766 cYAML_print_tree2file(stderr, err_rc);
1767 cYAML_free_tree(err_rc);
1771 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1772 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1773 cYAML_print_tree2file(stderr, err_rc);
1774 cYAML_free_tree(err_rc);
1778 rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
1779 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1780 cYAML_print_tree2file(stderr, err_rc);
1781 cYAML_free_tree(err_rc);
1785 rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
1786 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1787 cYAML_print_tree2file(stderr, err_rc);
1791 rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
1792 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1793 cYAML_print_tree2file(stderr, err_rc);
1797 rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
1798 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1799 cYAML_print_tree2file(stderr, err_rc);
1803 rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
1804 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1805 cYAML_print_tree2file(stderr, err_rc);
1809 rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
1810 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1811 cYAML_print_tree2file(stderr, err_rc);
1815 rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
1816 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1817 cYAML_print_tree2file(stderr, err_rc);
1821 rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
1822 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1823 cYAML_print_tree2file(stderr, err_rc);
1824 cYAML_free_tree(err_rc);
1828 rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
1829 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1830 cYAML_print_tree2file(stderr, err_rc);
1831 cYAML_free_tree(err_rc);
1835 if (show_rc != NULL) {
1836 cYAML_print_tree2file(f, show_rc);
1837 cYAML_free_tree(show_rc);
1846 static int jt_peer_nid_common(int argc, char **argv, int cmd)
1848 int rc = LUSTRE_CFG_RC_NO_ERR, opt;
1850 char *prim_nid = NULL, *nidstr = NULL;
1851 char err_str[LNET_MAX_STR_LEN] = "Error";
1852 struct cYAML *err_rc = NULL;
1854 const char *const short_opts = "k:mn:";
1855 const struct option long_opts[] = {
1856 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1857 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1858 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1861 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1865 while ((opt = getopt_long(argc, argv, short_opts,
1866 long_opts, NULL)) != -1) {
1875 if (cmd == LNETCTL_DEL_CMD) {
1876 rc = LUSTRE_CFG_RC_BAD_PARAM;
1877 snprintf(err_str, LNET_MAX_STR_LEN,
1878 "Unrecognized option '-%c'", opt);
1884 print_help(peer_cmds, "peer",
1885 cmd == LNETCTL_ADD_CMD ? "add" : "del");
1891 rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
1893 if (rc != LUSTRE_CFG_RC_NO_ERR)
1897 cYAML_build_error(rc, -1, "peer",
1898 cmd == LNETCTL_ADD_CMD ? "add" : "del",
1902 if (rc != LUSTRE_CFG_RC_NO_ERR)
1903 cYAML_print_tree2file(stderr, err_rc);
1905 cYAML_free_tree(err_rc);
1910 static int jt_add_peer_nid(int argc, char **argv)
1912 return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
1915 static int jt_del_peer_nid(int argc, char **argv)
1917 return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
1920 static int jt_show_peer(int argc, char **argv)
1924 struct cYAML *err_rc = NULL, *show_rc = NULL;
1925 long int detail = 0;
1927 const char *const short_opts = "hn:v::";
1928 const struct option long_opts[] = {
1929 { .name = "help", .has_arg = no_argument, .val = 'h' },
1930 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1931 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1934 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1938 while ((opt = getopt_long(argc, argv, short_opts,
1939 long_opts, NULL)) != -1) {
1945 if ((!optarg) && (argv[optind] != NULL) &&
1946 (argv[optind][0] != '-')) {
1947 if (parse_long(argv[optind++], &detail) != 0)
1954 print_help(peer_cmds, "peer", "show");
1960 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1963 if (rc != LUSTRE_CFG_RC_NO_ERR)
1964 cYAML_print_tree2file(stderr, err_rc);
1966 cYAML_print_tree(show_rc);
1968 cYAML_free_tree(err_rc);
1969 cYAML_free_tree(show_rc);
1974 static int jt_list_peer(int argc, char **argv)
1977 struct cYAML *err_rc = NULL, *list_rc = NULL;
1979 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1983 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1985 if (rc != LUSTRE_CFG_RC_NO_ERR)
1986 cYAML_print_tree2file(stderr, err_rc);
1988 cYAML_print_tree(list_rc);
1990 cYAML_free_tree(err_rc);
1991 cYAML_free_tree(list_rc);
1996 static int jt_ping(int argc, char **argv)
1998 struct cYAML *err_rc = NULL;
1999 struct cYAML *show_rc = NULL;
2003 const char *const short_options = "ht:";
2004 const struct option long_options[] = {
2005 { .name = "help", .has_arg = no_argument, .val = 'h' },
2006 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2009 while ((opt = getopt_long(argc, argv, short_options,
2010 long_options, NULL)) != -1) {
2013 timeout = 1000 * atol(optarg);
2016 printf("ping nid[,nid,...]\n"
2017 "\t --timeout: ping timeout\n"
2018 "\t --help: display this help\n");
2025 for (; optind < argc; optind++)
2026 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
2029 cYAML_print_tree(show_rc);
2032 cYAML_print_tree2file(stderr, err_rc);
2034 cYAML_free_tree(err_rc);
2035 cYAML_free_tree(show_rc);
2040 static int jt_discover(int argc, char **argv)
2042 struct cYAML *err_rc = NULL;
2043 struct cYAML *show_rc = NULL;
2047 const char *const short_options = "fh";
2048 const struct option long_options[] = {
2049 { .name = "force", .has_arg = no_argument, .val = 'f' },
2050 { .name = "help", .has_arg = no_argument, .val = 'h' },
2053 while ((opt = getopt_long(argc, argv, short_options,
2054 long_options, NULL)) != -1) {
2060 printf("discover nid[,nid,...]\n"
2061 "\t --force: force discovery\n"
2062 "\t --help: display this help\n");
2069 for (; optind < argc; optind++)
2070 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
2074 cYAML_print_tree(show_rc);
2077 cYAML_print_tree2file(stderr, err_rc);
2079 cYAML_free_tree(err_rc);
2080 cYAML_free_tree(show_rc);
2085 static int jt_add_udsp(int argc, char **argv)
2087 char *src = NULL, *dst = NULL, *rte = NULL;
2088 struct cYAML *err_rc = NULL;
2089 union lnet_udsp_action udsp_action;
2090 long int idx = -1, priority = -1;
2092 char *action_type = "pref";
2094 const char *const short_options = "s:d:r:p:i:";
2095 static const struct option long_options[] = {
2096 { .name = "src", .has_arg = required_argument, .val = 's' },
2097 { .name = "dst", .has_arg = required_argument, .val = 'd' },
2098 { .name = "rte", .has_arg = required_argument, .val = 'r' },
2099 { .name = "priority", .has_arg = required_argument, .val = 'p' },
2100 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2103 rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
2107 while ((opt = getopt_long(argc, argv, short_options,
2108 long_options, NULL)) != -1) {
2120 rc = parse_long(optarg, &priority);
2123 action_type = "priority";
2124 udsp_action.udsp_priority = priority;
2127 rc = parse_long(optarg, &idx);
2132 print_help(udsp_cmds, "udsp", "add");
2138 rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
2141 if (rc != LUSTRE_CFG_RC_NO_ERR)
2142 cYAML_print_tree2file(stderr, err_rc);
2144 cYAML_free_tree(err_rc);
2149 static int jt_del_udsp(int argc, char **argv)
2151 struct cYAML *err_rc = NULL;
2155 const char *const short_options = "i:";
2156 static const struct option long_options[] = {
2157 { .name = "idx", .has_arg = required_argument, .val = 'i' },
2160 rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
2164 while ((opt = getopt_long(argc, argv, short_options,
2165 long_options, NULL)) != -1) {
2168 rc = parse_long(optarg, &idx);
2173 print_help(udsp_cmds, "udsp", "add");
2179 rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
2180 if (rc != LUSTRE_CFG_RC_NO_ERR)
2181 cYAML_print_tree2file(stderr, err_rc);
2183 cYAML_free_tree(err_rc);
2188 static int lnetctl_list_commands(int argc, char **argv)
2190 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
2192 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
2197 int main(int argc, char **argv)
2200 struct cYAML *err_rc = NULL;
2202 rc = lustre_lnet_config_lib_init();
2204 cYAML_build_error(-1, -1, "lnetctl", "startup",
2205 "cannot register LNet device", &err_rc);
2206 cYAML_print_tree2file(stderr, err_rc);
2210 Parser_init("lnetctl > ", cmd_list);
2212 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);