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>
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_global(int argc, char **argv);
52 static int jt_set_tiny(int argc, char **argv);
53 static int jt_set_small(int argc, char **argv);
54 static int jt_set_large(int argc, char **argv);
55 static int jt_set_numa(int argc, char **argv);
56 static int jt_add_peer_nid(int argc, char **argv);
57 static int jt_del_peer_nid(int argc, char **argv);
58 static int jt_set_max_intf(int argc, char **argv);
59 static int jt_set_discovery(int argc, char **argv);
60 static int jt_list_peer(int argc, char **argv);
61 /*static int jt_show_peer(int argc, char **argv);*/
62 static int lnetctl_list_commands(int argc, char **argv);
63 static int jt_import(int argc, char **argv);
64 static int jt_export(int argc, char **argv);
65 static int jt_ping(int argc, char **argv);
66 static int jt_discover(int argc, char **argv);
67 static int jt_lnet(int argc, char **argv);
68 static int jt_route(int argc, char **argv);
69 static int jt_net(int argc, char **argv);
70 static int jt_routing(int argc, char **argv);
71 static int jt_set(int argc, char **argv);
72 static int jt_stats(int argc, char **argv);
73 static int jt_global(int argc, char **argv);
74 static int jt_peers(int argc, char **argv);
77 command_t cmd_list[] = {
78 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
79 {"route", jt_route, 0, "route {add | del | show | help}"},
80 {"net", jt_net, 0, "net {add | del | show | help}"},
81 {"routing", jt_routing, 0, "routing {show | help}"},
82 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
83 " | routing | numa_range | max_interfaces"
85 {"import", jt_import, 0, "import FILE.yaml"},
86 {"export", jt_export, 0, "export FILE.yaml"},
87 {"stats", jt_stats, 0, "stats {show | help}"},
88 {"global", jt_global, 0, "global {show | help}"},
89 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
90 {"ping", jt_ping, 0, "ping nid,[nid,...]"},
91 {"discover", jt_discover, 0, "discover nid[,nid,...]"},
92 {"help", Parser_help, 0, "help"},
93 {"exit", Parser_quit, 0, "quit"},
94 {"quit", Parser_quit, 0, "quit"},
95 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
99 command_t lnet_cmds[] = {
100 {"configure", jt_config_lnet, 0, "configure lnet\n"
101 "\t--all: load NI configuration from module parameters\n"},
102 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
106 command_t route_cmds[] = {
107 {"add", jt_add_route, 0, "add a route\n"
108 "\t--net: net name (e.g. tcp0)\n"
109 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
110 "\t--hop: number to final destination (1 < hops < 255)\n"
111 "\t--priority: priority of route (0 - highest prio\n"},
112 {"del", jt_del_route, 0, "delete a route\n"
113 "\t--net: net name (e.g. tcp0)\n"
114 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
115 {"show", jt_show_route, 0, "show routes\n"
116 "\t--net: net name (e.g. tcp0) to filter on\n"
117 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
118 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
119 "\t--priority: priority of route (0 - highest prio to filter on\n"
120 "\t--verbose: display detailed output per route\n"},
124 command_t net_cmds[] = {
125 {"add", jt_add_ni, 0, "add a network\n"
126 "\t--net: net name (e.g. tcp0)\n"
127 "\t--if: physical interface (e.g. eth0)\n"
128 "\t--ip2net: specify networks based on IP address patterns\n"
129 "\t--peer-timeout: time to wait before declaring a peer dead\n"
130 "\t--peer-credits: define the max number of inflight messages\n"
131 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
132 "\t--credits: Network Interface credits\n"
133 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
134 {"del", jt_del_ni, 0, "delete a network\n"
135 "\t--net: net name (e.g. tcp0)\n"
136 "\t--if: physical interface (e.g. eth0)\n"},
137 {"show", jt_show_net, 0, "show networks\n"
138 "\t--net: net name (e.g. tcp0) to filter on\n"
139 "\t--verbose: display detailed output per network."
140 " Optional argument of '2' outputs more stats\n"},
144 command_t routing_cmds[] = {
145 {"show", jt_show_routing, 0, "show routing information\n"},
149 command_t stats_cmds[] = {
150 {"show", jt_show_stats, 0, "show LNET statistics\n"},
154 command_t global_cmds[] = {
155 {"show", jt_show_global, 0, "show global variables\n"},
159 command_t set_cmds[] = {
160 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
161 "\tVALUE must be greater than 0\n"},
162 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
163 "\tVALUE must be greater than 0\n"},
164 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
165 "\tVALUE must be greater than 0\n"},
166 {"routing", jt_set_routing, 0, "enable/disable routing\n"
167 "\t0 - disable routing\n"
168 "\t1 - enable routing\n"},
169 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
170 "\tVALUE must be at least 0\n"},
171 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
173 "\tValue must be greater than 16\n"},
174 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
175 "\t0 - disable peer discovery\n"
176 "\t1 - enable peer discovery (default)\n"},
180 command_t peer_cmds[] = {
181 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
182 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
183 "\t NID in the list becomes the Primary NID of a newly created\n"
185 "\t--nid: one or more peer NIDs\n"
186 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
187 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
188 "\t--prim_nid: Primary NID of the peer.\n"
189 "\t--nid: list of NIDs to remove. If none provided,\n"
190 "\t peer is deleted\n"},
191 {"show", jt_show_peer, 0, "show peer information\n"
192 "\t--nid: NID of peer to filter on.\n"
193 "\t--verbose: display detailed output per peer."
194 " Optional argument of '2' outputs more stats\n"},
195 {"list", jt_list_peer, 0, "list all peers\n"},
199 static inline void print_help(const command_t cmds[], const char *cmd_type,
202 const command_t *cmd;
204 for (cmd = cmds; cmd->pc_name; cmd++) {
205 if (pc_name != NULL &&
206 strcmp(cmd->pc_name, pc_name) == 0) {
207 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
210 } else if (pc_name != NULL) {
213 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
217 static int parse_long(const char *number, long int *value)
224 *value = strtol(number, &end, 0);
225 if (end != NULL && *end != 0)
231 static int check_cmd(const command_t *cmd_list, const char *cmd,
232 const char *sub_cmd, const int min_args,
233 int argc, char **argv)
240 const char *const short_options = "h";
241 static const struct option long_options[] = {
242 { .name = "help", .has_arg = no_argument, .val = 'h' },
246 if (argc < min_args) {
247 print_help(cmd_list, cmd, sub_cmd);
250 } else if (argc > 2) {
254 while ((opt = getopt_long(argc, argv, short_options,
255 long_options, NULL)) != -1) {
258 print_help(cmd_list, cmd, sub_cmd);
273 static int jt_set_max_intf(int argc, char **argv)
277 struct cYAML *err_rc = NULL;
279 rc = check_cmd(set_cmds, "set", "max_interfaces", 2, argc, argv);
283 rc = parse_long(argv[1], &value);
285 cYAML_build_error(-1, -1, "parser", "set",
286 "cannot parse max_interfaces value", &err_rc);
287 cYAML_print_tree2file(stderr, err_rc);
288 cYAML_free_tree(err_rc);
292 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
293 if (rc != LUSTRE_CFG_RC_NO_ERR)
294 cYAML_print_tree2file(stderr, err_rc);
296 cYAML_free_tree(err_rc);
301 static int jt_set_numa(int argc, char **argv)
305 struct cYAML *err_rc = NULL;
307 rc = check_cmd(set_cmds, "set", "numa_range", 2, argc, argv);
311 rc = parse_long(argv[1], &value);
313 cYAML_build_error(-1, -1, "parser", "set",
314 "cannot parse numa_range value", &err_rc);
315 cYAML_print_tree2file(stderr, err_rc);
316 cYAML_free_tree(err_rc);
320 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
321 if (rc != LUSTRE_CFG_RC_NO_ERR)
322 cYAML_print_tree2file(stderr, err_rc);
324 cYAML_free_tree(err_rc);
329 static int jt_set_discovery(int argc, char **argv)
333 struct cYAML *err_rc = NULL;
335 rc = check_cmd(set_cmds, "set", "discovery", 2, argc, argv);
339 rc = parse_long(argv[1], &value);
341 cYAML_build_error(-1, -1, "parser", "set",
342 "cannot parse discovery value", &err_rc);
343 cYAML_print_tree2file(stderr, err_rc);
344 cYAML_free_tree(err_rc);
348 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
349 if (rc != LUSTRE_CFG_RC_NO_ERR)
350 cYAML_print_tree2file(stderr, err_rc);
352 cYAML_free_tree(err_rc);
357 static int jt_set_tiny(int argc, char **argv)
361 struct cYAML *err_rc = NULL;
363 rc = check_cmd(set_cmds, "set", "tiny_buffers", 2, argc, argv);
367 rc = parse_long(argv[1], &value);
369 cYAML_build_error(-1, -1, "parser", "set",
370 "cannot parse tiny_buffers value", &err_rc);
371 cYAML_print_tree2file(stderr, err_rc);
372 cYAML_free_tree(err_rc);
376 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
377 if (rc != LUSTRE_CFG_RC_NO_ERR)
378 cYAML_print_tree2file(stderr, err_rc);
380 cYAML_free_tree(err_rc);
385 static int jt_set_small(int argc, char **argv)
389 struct cYAML *err_rc = NULL;
391 rc = check_cmd(set_cmds, "set", "small_buffers", 2, argc, argv);
395 rc = parse_long(argv[1], &value);
397 cYAML_build_error(-1, -1, "parser", "set",
398 "cannot parse small_buffers value", &err_rc);
399 cYAML_print_tree2file(stderr, err_rc);
400 cYAML_free_tree(err_rc);
404 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
405 if (rc != LUSTRE_CFG_RC_NO_ERR)
406 cYAML_print_tree2file(stderr, err_rc);
408 cYAML_free_tree(err_rc);
413 static int jt_set_large(int argc, char **argv)
417 struct cYAML *err_rc = NULL;
419 rc = check_cmd(set_cmds, "set", "large_buffers", 2, argc, argv);
423 rc = parse_long(argv[1], &value);
425 cYAML_build_error(-1, -1, "parser", "set",
426 "cannot parse large_buffers value", &err_rc);
427 cYAML_print_tree2file(stderr, err_rc);
428 cYAML_free_tree(err_rc);
432 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
433 if (rc != LUSTRE_CFG_RC_NO_ERR)
434 cYAML_print_tree2file(stderr, err_rc);
436 cYAML_free_tree(err_rc);
441 static int jt_set_routing(int argc, char **argv)
444 struct cYAML *err_rc = NULL;
447 rc = check_cmd(set_cmds, "set", "routing", 2, argc, argv);
451 rc = parse_long(argv[1], &value);
452 if (rc != 0 || (value != 0 && value != 1)) {
453 cYAML_build_error(-1, -1, "parser", "set",
454 "cannot parse routing value.\n"
455 "must be 0 for disable or 1 for enable",
457 cYAML_print_tree2file(stderr, err_rc);
458 cYAML_free_tree(err_rc);
462 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
464 if (rc != LUSTRE_CFG_RC_NO_ERR)
465 cYAML_print_tree2file(stderr, err_rc);
467 cYAML_free_tree(err_rc);
472 static int jt_config_lnet(int argc, char **argv)
474 struct cYAML *err_rc = NULL;
475 bool load_mod_params = false;
478 const char *const short_options = "a";
479 static const struct option long_options[] = {
480 { .name = "all", .has_arg = no_argument, .val = 'a' },
484 rc = check_cmd(lnet_cmds, "lnet", "configure", 0, argc, argv);
488 while ((opt = getopt_long(argc, argv, short_options,
489 long_options, NULL)) != -1) {
492 load_mod_params = true;
499 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
502 if (rc != LUSTRE_CFG_RC_NO_ERR)
503 cYAML_print_tree2file(stderr, err_rc);
505 cYAML_free_tree(err_rc);
510 static int jt_unconfig_lnet(int argc, char **argv)
512 struct cYAML *err_rc = NULL;
515 rc = check_cmd(lnet_cmds, "lnet", "unconfigure", 0, argc, argv);
519 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
521 if (rc != LUSTRE_CFG_RC_NO_ERR)
522 cYAML_print_tree2file(stderr, err_rc);
524 cYAML_free_tree(err_rc);
528 static int jt_add_route(int argc, char **argv)
530 char *network = NULL, *gateway = NULL;
531 long int hop = -1, prio = -1;
532 struct cYAML *err_rc = NULL;
535 const char *const short_options = "n:g:c:p:";
536 static const struct option long_options[] = {
537 { .name = "net", .has_arg = required_argument, .val = 'n' },
538 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
539 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
540 { .name = "priority", .has_arg = required_argument, .val = 'p' },
543 rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
547 while ((opt = getopt_long(argc, argv, short_options,
548 long_options, NULL)) != -1) {
557 rc = parse_long(optarg, &hop);
565 rc = parse_long(optarg, &prio);
577 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
579 if (rc != LUSTRE_CFG_RC_NO_ERR)
580 cYAML_print_tree2file(stderr, err_rc);
582 cYAML_free_tree(err_rc);
587 static int jt_add_ni(int argc, char **argv)
590 long int pto = -1, pc = -1, pbc = -1, cre = -1;
591 struct cYAML *err_rc = NULL;
592 int rc, opt, cpt_rc = -1;
593 struct lnet_dlc_network_descr nw_descr;
594 struct cfs_expr_list *global_cpts = NULL;
595 struct lnet_ioctl_config_lnd_tunables tunables;
598 memset(&tunables, 0, sizeof(tunables));
599 lustre_lnet_init_nw_descr(&nw_descr);
601 const char *const short_options = "n:i:p:t:c:b:r:s:";
602 static const struct option long_options[] = {
603 { .name = "net", .has_arg = required_argument, .val = 'n' },
604 { .name = "if", .has_arg = required_argument, .val = 'i' },
605 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
606 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
607 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
608 { .name = "peer-buffer-credits",
609 .has_arg = required_argument, .val = 'b' },
610 { .name = "credits", .has_arg = required_argument, .val = 'r' },
611 { .name = "cpt", .has_arg = required_argument, .val = 's' },
614 rc = check_cmd(net_cmds, "net", "add", 0, argc, argv);
618 while ((opt = getopt_long(argc, argv, short_options,
619 long_options, NULL)) != -1) {
622 nw_descr.nw_id = libcfs_str2net(optarg);
625 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
627 cYAML_build_error(-1, -1, "ni", "add",
628 "bad interface list",
637 rc = parse_long(optarg, &pto);
645 rc = parse_long(optarg, &pc);
653 rc = parse_long(optarg, &pbc);
661 rc = parse_long(optarg, &cre);
669 cpt_rc = cfs_expr_list_parse(optarg,
671 UINT_MAX, &global_cpts);
678 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
679 tunables.lt_cmn.lct_peer_timeout = pto;
680 tunables.lt_cmn.lct_peer_tx_credits = pc;
681 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
682 tunables.lt_cmn.lct_max_tx_credits = cre;
686 rc = lustre_lnet_config_ni(&nw_descr,
687 (cpt_rc == 0) ? global_cpts: NULL,
688 ip2net, (found) ? &tunables : NULL,
691 if (global_cpts != NULL)
692 cfs_expr_list_free(global_cpts);
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_del_route(int argc, char **argv)
705 char *network = NULL, *gateway = NULL;
706 struct cYAML *err_rc = NULL;
709 const char *const short_options = "n:g:";
710 static const struct option long_options[] = {
711 { .name = "net", .has_arg = required_argument, .val = 'n' },
712 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
715 rc = check_cmd(route_cmds, "route", "del", 0, argc, argv);
719 while ((opt = getopt_long(argc, argv, short_options,
720 long_options, NULL)) != -1) {
733 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
735 if (rc != LUSTRE_CFG_RC_NO_ERR)
736 cYAML_print_tree2file(stderr, err_rc);
738 cYAML_free_tree(err_rc);
743 static int jt_del_ni(int argc, char **argv)
745 struct cYAML *err_rc = NULL;
747 struct lnet_dlc_network_descr nw_descr;
749 lustre_lnet_init_nw_descr(&nw_descr);
751 const char *const short_options = "n:i:";
752 static const struct option long_options[] = {
753 { .name = "net", .has_arg = required_argument, .val = 'n' },
754 { .name = "if", .has_arg = required_argument, .val = 'i' },
757 rc = check_cmd(net_cmds, "net", "del", 0, argc, argv);
761 while ((opt = getopt_long(argc, argv, short_options,
762 long_options, NULL)) != -1) {
765 nw_descr.nw_id = libcfs_str2net(optarg);
768 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
770 cYAML_build_error(-1, -1, "ni", "add",
771 "bad interface list",
781 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
784 if (rc != LUSTRE_CFG_RC_NO_ERR)
785 cYAML_print_tree2file(stderr, err_rc);
787 cYAML_free_tree(err_rc);
792 static int jt_show_route(int argc, char **argv)
794 char *network = NULL, *gateway = NULL;
795 long int hop = -1, prio = -1;
796 int detail = 0, rc, opt;
797 struct cYAML *err_rc = NULL, *show_rc = NULL;
799 const char *const short_options = "n:g:h:p:v";
800 static const struct option long_options[] = {
801 { .name = "net", .has_arg = required_argument, .val = 'n' },
802 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
803 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
804 { .name = "priority", .has_arg = required_argument, .val = 'p' },
805 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
808 rc = check_cmd(route_cmds, "route", "show", 0, argc, argv);
812 while ((opt = getopt_long(argc, argv, short_options,
813 long_options, NULL)) != -1) {
822 rc = parse_long(optarg, &hop);
830 rc = parse_long(optarg, &prio);
845 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
846 &show_rc, &err_rc, false);
848 if (rc != LUSTRE_CFG_RC_NO_ERR)
849 cYAML_print_tree2file(stderr, err_rc);
851 cYAML_print_tree(show_rc);
853 cYAML_free_tree(err_rc);
854 cYAML_free_tree(show_rc);
859 static int jt_show_net(int argc, char **argv)
861 char *network = NULL;
863 struct cYAML *err_rc = NULL, *show_rc = NULL;
866 const char *const short_options = "n:v";
867 static const struct option long_options[] = {
868 { .name = "net", .has_arg = required_argument, .val = 'n' },
869 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
872 rc = check_cmd(net_cmds, "net", "show", 0, argc, argv);
876 while ((opt = getopt_long(argc, argv, short_options,
877 long_options, NULL)) != -1) {
883 if ((!optarg) && (argv[optind] != NULL) &&
884 (argv[optind][0] != '-')) {
885 if (parse_long(argv[optind++], &detail) != 0)
896 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
899 if (rc != LUSTRE_CFG_RC_NO_ERR)
900 cYAML_print_tree2file(stderr, err_rc);
902 cYAML_print_tree(show_rc);
904 cYAML_free_tree(err_rc);
905 cYAML_free_tree(show_rc);
910 static int jt_show_routing(int argc, char **argv)
912 struct cYAML *err_rc = NULL, *show_rc = NULL;
915 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
919 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
921 if (rc != LUSTRE_CFG_RC_NO_ERR)
922 cYAML_print_tree2file(stderr, err_rc);
924 cYAML_print_tree(show_rc);
926 cYAML_free_tree(err_rc);
927 cYAML_free_tree(show_rc);
932 static int jt_show_stats(int argc, char **argv)
935 struct cYAML *show_rc = NULL, *err_rc = NULL;
937 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
941 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
943 if (rc != LUSTRE_CFG_RC_NO_ERR)
944 cYAML_print_tree2file(stderr, err_rc);
946 cYAML_print_tree(show_rc);
948 cYAML_free_tree(err_rc);
949 cYAML_free_tree(show_rc);
954 static int jt_show_global(int argc, char **argv)
957 struct cYAML *show_rc = NULL, *err_rc = NULL;
959 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
963 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
964 if (rc != LUSTRE_CFG_RC_NO_ERR) {
965 cYAML_print_tree2file(stderr, err_rc);
969 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
970 if (rc != LUSTRE_CFG_RC_NO_ERR) {
971 cYAML_print_tree2file(stderr, err_rc);
975 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
976 if (rc != LUSTRE_CFG_RC_NO_ERR) {
977 cYAML_print_tree2file(stderr, err_rc);
982 cYAML_print_tree(show_rc);
985 cYAML_free_tree(err_rc);
986 cYAML_free_tree(show_rc);
991 static int jt_lnet(int argc, char **argv)
995 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
999 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1002 static int jt_route(int argc, char **argv)
1006 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1010 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1013 static int jt_net(int argc, char **argv)
1017 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1021 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1024 static int jt_routing(int argc, char **argv)
1028 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1032 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1035 static int jt_stats(int argc, char **argv)
1039 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1043 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1046 static int jt_global(int argc, char **argv)
1050 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1054 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1057 static int jt_peers(int argc, char **argv)
1061 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1065 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1068 static int jt_set(int argc, char **argv)
1072 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1076 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1079 static int jt_import(int argc, char **argv)
1082 struct cYAML *err_rc = NULL;
1083 struct cYAML *show_rc = NULL;
1084 int rc = 0, return_rc = 0, opt, opt_found = 0;
1087 const char *const short_options = "adseh";
1088 static const struct option long_options[] = {
1089 { .name = "add", .has_arg = no_argument, .val = 'a' },
1090 { .name = "del", .has_arg = no_argument, .val = 'd' },
1091 { .name = "show", .has_arg = no_argument, .val = 's' },
1092 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1093 { .name = "help", .has_arg = no_argument, .val = 'h' },
1096 while ((opt = getopt_long(argc, argv, short_options,
1097 long_options, NULL)) != -1) {
1111 printf("import FILE\n"
1112 "import < FILE : import a file\n"
1113 "\t--add: add configuration\n"
1114 "\t--del: delete configuration\n"
1115 "\t--show: show configuration\n"
1116 "\t--exec: execute command\n"
1117 "\t--help: display this help\n"
1118 "If no command option is given then --add"
1119 " is assumed by default\n");
1126 /* grab the file name if one exists */
1127 if (opt_found && argc == 3)
1129 else if (!opt_found && argc == 2)
1134 rc = lustre_yaml_config(file, &err_rc);
1135 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1136 cYAML_print_tree(show_rc);
1137 cYAML_free_tree(show_rc);
1140 rc = lustre_yaml_del(file, &err_rc);
1143 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1144 cYAML_print_tree(show_rc);
1145 cYAML_free_tree(show_rc);
1148 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1149 cYAML_print_tree(show_rc);
1150 cYAML_free_tree(show_rc);
1154 if (rc || return_rc) {
1155 cYAML_print_tree2file(stderr, err_rc);
1156 cYAML_free_tree(err_rc);
1162 static int jt_export(int argc, char **argv)
1164 struct cYAML *show_rc = NULL;
1165 struct cYAML *err_rc = NULL;
1169 bool backup = false;
1172 const char *const short_options = "bh";
1173 static const struct option long_options[] = {
1174 { .name = "backup", .has_arg = no_argument, .val = 'b' },
1175 { .name = "help", .has_arg = no_argument, .val = 'h' },
1178 while ((opt = getopt_long(argc, argv, short_options,
1179 long_options, NULL)) != -1) {
1186 printf("export > FILE.yaml : export configuration\n"
1187 "\t--help: display this help\n");
1192 if (backup && argc >= 3)
1194 else if (!backup && argc >= 2)
1200 f = fopen(file, "w");
1205 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
1206 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1207 cYAML_print_tree2file(stderr, err_rc);
1208 cYAML_free_tree(err_rc);
1212 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1214 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1215 cYAML_print_tree2file(stderr, err_rc);
1216 cYAML_free_tree(err_rc);
1220 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
1221 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1222 cYAML_print_tree2file(stderr, err_rc);
1223 cYAML_free_tree(err_rc);
1227 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
1228 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1229 cYAML_print_tree2file(stderr, err_rc);
1230 cYAML_free_tree(err_rc);
1234 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1235 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1236 cYAML_print_tree2file(stderr, err_rc);
1237 cYAML_free_tree(err_rc);
1241 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1242 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1243 cYAML_print_tree2file(stderr, err_rc);
1244 cYAML_free_tree(err_rc);
1248 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1249 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1250 cYAML_print_tree2file(stderr, err_rc);
1251 cYAML_free_tree(err_rc);
1255 if (show_rc != NULL) {
1256 cYAML_print_tree2file(f, show_rc);
1257 cYAML_free_tree(show_rc);
1266 static int jt_add_peer_nid(int argc, char **argv)
1268 char *prim_nid = NULL;
1269 char **nids = NULL, **nids2 = NULL;
1271 struct cYAML *err_rc = NULL;
1272 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1273 bool non_mr = false;
1275 const char *const short_opts = "k:mn:";
1276 const struct option long_opts[] = {
1277 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1278 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1279 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1282 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1286 while ((opt = getopt_long(argc, argv, short_opts,
1287 long_opts, NULL)) != -1) {
1293 size = lustre_lnet_parse_nids(optarg, nids, size,
1298 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1308 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1309 !non_mr, -1, &err_rc);
1313 /* free the array of nids */
1314 for (i = 0; i < size; i++)
1319 if (rc != LUSTRE_CFG_RC_NO_ERR)
1320 cYAML_print_tree2file(stderr, err_rc);
1322 cYAML_free_tree(err_rc);
1327 static int jt_del_peer_nid(int argc, char **argv)
1329 char *prim_nid = NULL;
1330 char **nids = NULL, **nids2 = NULL;
1331 struct cYAML *err_rc = NULL;
1332 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1334 const char *const short_opts = "k:n:";
1335 const struct option long_opts[] = {
1336 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1337 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1340 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1344 while ((opt = getopt_long(argc, argv, short_opts,
1345 long_opts, NULL)) != -1) {
1351 size = lustre_lnet_parse_nids(optarg, nids, size,
1356 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1363 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1367 for (i = 0; i < size; i++)
1372 if (rc != LUSTRE_CFG_RC_NO_ERR)
1373 cYAML_print_tree2file(stderr, err_rc);
1375 cYAML_free_tree(err_rc);
1380 static int jt_show_peer(int argc, char **argv)
1384 struct cYAML *err_rc = NULL, *show_rc = NULL;
1385 long int detail = 0;
1387 const char *const short_opts = "hn:v::";
1388 const struct option long_opts[] = {
1389 { .name = "help", .has_arg = no_argument, .val = 'h' },
1390 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1391 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1394 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1398 while ((opt = getopt_long(argc, argv, short_opts,
1399 long_opts, NULL)) != -1) {
1405 if ((!optarg) && (argv[optind] != NULL) &&
1406 (argv[optind][0] != '-')) {
1407 if (parse_long(argv[optind++], &detail) != 0)
1418 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
1421 if (rc != LUSTRE_CFG_RC_NO_ERR)
1422 cYAML_print_tree2file(stderr, err_rc);
1424 cYAML_print_tree(show_rc);
1426 cYAML_free_tree(err_rc);
1427 cYAML_free_tree(show_rc);
1432 static int jt_list_peer(int argc, char **argv)
1435 struct cYAML *err_rc = NULL, *list_rc = NULL;
1437 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1441 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1443 if (rc != LUSTRE_CFG_RC_NO_ERR)
1444 cYAML_print_tree2file(stderr, err_rc);
1446 cYAML_print_tree(list_rc);
1448 cYAML_free_tree(err_rc);
1449 cYAML_free_tree(list_rc);
1454 static int jt_ping(int argc, char **argv)
1456 struct cYAML *err_rc = NULL;
1457 struct cYAML *show_rc = NULL;
1461 const char *const short_options = "ht:";
1462 const struct option long_options[] = {
1463 { .name = "help", .has_arg = no_argument, .val = 'h' },
1464 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1467 while ((opt = getopt_long(argc, argv, short_options,
1468 long_options, NULL)) != -1) {
1471 timeout = 1000 * atol(optarg);
1474 printf("ping nid[,nid,...]\n"
1475 "\t --timeout: ping timeout\n"
1476 "\t --help: display this help\n");
1483 for (; optind < argc; optind++)
1484 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1487 cYAML_print_tree(show_rc);
1490 cYAML_print_tree2file(stderr, err_rc);
1492 cYAML_free_tree(err_rc);
1493 cYAML_free_tree(show_rc);
1498 static int jt_discover(int argc, char **argv)
1500 struct cYAML *err_rc = NULL;
1501 struct cYAML *show_rc = NULL;
1505 const char *const short_options = "fh";
1506 const struct option long_options[] = {
1507 { .name = "force", .has_arg = no_argument, .val = 'f' },
1508 { .name = "help", .has_arg = no_argument, .val = 'h' },
1511 while ((opt = getopt_long(argc, argv, short_options,
1512 long_options, NULL)) != -1) {
1518 printf("discover nid[,nid,...]\n"
1519 "\t --force: force discovery\n"
1520 "\t --help: display this help\n");
1527 for (; optind < argc; optind++)
1528 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1532 cYAML_print_tree(show_rc);
1535 cYAML_print_tree2file(stderr, err_rc);
1537 cYAML_free_tree(err_rc);
1538 cYAML_free_tree(show_rc);
1543 static int lnetctl_list_commands(int argc, char **argv)
1545 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1547 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1552 int main(int argc, char **argv)
1555 struct cYAML *err_rc = NULL;
1557 rc = lustre_lnet_config_lib_init();
1559 cYAML_build_error(-1, -1, "lnetctl", "startup",
1560 "cannot register LNet device", &err_rc);
1561 cYAML_print_tree2file(stderr, err_rc);
1565 Parser_init("lnetctl > ", cmd_list);
1567 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);