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,
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);
898 if (rc != LUSTRE_CFG_RC_NO_ERR)
899 cYAML_print_tree2file(stderr, err_rc);
901 cYAML_print_tree(show_rc);
903 cYAML_free_tree(err_rc);
904 cYAML_free_tree(show_rc);
909 static int jt_show_routing(int argc, char **argv)
911 struct cYAML *err_rc = NULL, *show_rc = NULL;
914 rc = check_cmd(routing_cmds, "routing", "show", 0, argc, argv);
918 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
920 if (rc != LUSTRE_CFG_RC_NO_ERR)
921 cYAML_print_tree2file(stderr, err_rc);
923 cYAML_print_tree(show_rc);
925 cYAML_free_tree(err_rc);
926 cYAML_free_tree(show_rc);
931 static int jt_show_stats(int argc, char **argv)
934 struct cYAML *show_rc = NULL, *err_rc = NULL;
936 rc = check_cmd(stats_cmds, "stats", "show", 0, argc, argv);
940 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
942 if (rc != LUSTRE_CFG_RC_NO_ERR)
943 cYAML_print_tree2file(stderr, err_rc);
945 cYAML_print_tree(show_rc);
947 cYAML_free_tree(err_rc);
948 cYAML_free_tree(show_rc);
953 static int jt_show_global(int argc, char **argv)
956 struct cYAML *show_rc = NULL, *err_rc = NULL;
958 rc = check_cmd(global_cmds, "global", "show", 0, argc, argv);
962 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
963 if (rc != LUSTRE_CFG_RC_NO_ERR) {
964 cYAML_print_tree2file(stderr, err_rc);
968 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
969 if (rc != LUSTRE_CFG_RC_NO_ERR) {
970 cYAML_print_tree2file(stderr, err_rc);
974 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
975 if (rc != LUSTRE_CFG_RC_NO_ERR) {
976 cYAML_print_tree2file(stderr, err_rc);
981 cYAML_print_tree(show_rc);
984 cYAML_free_tree(err_rc);
985 cYAML_free_tree(show_rc);
990 static int jt_lnet(int argc, char **argv)
994 rc = check_cmd(lnet_cmds, "lnet", NULL, 2, argc, argv);
998 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
1001 static int jt_route(int argc, char **argv)
1005 rc = check_cmd(route_cmds, "route", NULL, 2, argc, argv);
1009 return Parser_execarg(argc - 1, &argv[1], route_cmds);
1012 static int jt_net(int argc, char **argv)
1016 rc = check_cmd(net_cmds, "net", NULL, 2, argc, argv);
1020 return Parser_execarg(argc - 1, &argv[1], net_cmds);
1023 static int jt_routing(int argc, char **argv)
1027 rc = check_cmd(routing_cmds, "routing", NULL, 2, argc, argv);
1031 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
1034 static int jt_stats(int argc, char **argv)
1038 rc = check_cmd(stats_cmds, "stats", NULL, 2, argc, argv);
1042 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
1045 static int jt_global(int argc, char **argv)
1049 rc = check_cmd(global_cmds, "global", NULL, 2, argc, argv);
1053 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1056 static int jt_peers(int argc, char **argv)
1060 rc = check_cmd(peer_cmds, "peer", NULL, 2, argc, argv);
1064 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1067 static int jt_set(int argc, char **argv)
1071 rc = check_cmd(set_cmds, "set", NULL, 2, argc, argv);
1075 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1078 static int jt_import(int argc, char **argv)
1081 struct cYAML *err_rc = NULL;
1082 struct cYAML *show_rc = NULL;
1083 int rc = 0, return_rc = 0, opt, opt_found = 0;
1086 const char *const short_options = "adseh";
1087 static const struct option long_options[] = {
1088 { .name = "add", .has_arg = no_argument, .val = 'a' },
1089 { .name = "del", .has_arg = no_argument, .val = 'd' },
1090 { .name = "show", .has_arg = no_argument, .val = 's' },
1091 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1092 { .name = "help", .has_arg = no_argument, .val = 'h' },
1095 while ((opt = getopt_long(argc, argv, short_options,
1096 long_options, NULL)) != -1) {
1110 printf("import FILE\n"
1111 "import < FILE : import a file\n"
1112 "\t--add: add configuration\n"
1113 "\t--del: delete configuration\n"
1114 "\t--show: show configuration\n"
1115 "\t--exec: execute command\n"
1116 "\t--help: display this help\n"
1117 "If no command option is given then --add"
1118 " is assumed by default\n");
1125 /* grab the file name if one exists */
1126 if (opt_found && argc == 3)
1128 else if (!opt_found && argc == 2)
1133 rc = lustre_yaml_config(file, &err_rc);
1134 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1135 cYAML_print_tree(show_rc);
1136 cYAML_free_tree(show_rc);
1139 rc = lustre_yaml_del(file, &err_rc);
1142 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1143 cYAML_print_tree(show_rc);
1144 cYAML_free_tree(show_rc);
1147 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1148 cYAML_print_tree(show_rc);
1149 cYAML_free_tree(show_rc);
1153 if (rc || return_rc) {
1154 cYAML_print_tree2file(stderr, err_rc);
1155 cYAML_free_tree(err_rc);
1161 static int jt_export(int argc, char **argv)
1163 struct cYAML *show_rc = NULL;
1164 struct cYAML *err_rc = NULL;
1169 const char *const short_options = "h";
1170 static const struct option long_options[] = {
1171 { .name = "help", .has_arg = no_argument, .val = 'h' },
1174 while ((opt = getopt_long(argc, argv, short_options,
1175 long_options, NULL)) != -1) {
1178 printf("export > FILE.yaml : export configuration\n"
1179 "\t--help: display this help\n");
1187 f = fopen(argv[1], "w");
1193 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc);
1194 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1195 cYAML_print_tree2file(stderr, err_rc);
1196 cYAML_free_tree(err_rc);
1200 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1202 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1203 cYAML_print_tree2file(stderr, err_rc);
1204 cYAML_free_tree(err_rc);
1208 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1209 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1210 cYAML_print_tree2file(stderr, err_rc);
1211 cYAML_free_tree(err_rc);
1215 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc);
1216 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1217 cYAML_print_tree2file(stderr, err_rc);
1218 cYAML_free_tree(err_rc);
1222 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1223 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1224 cYAML_print_tree2file(stderr, err_rc);
1225 cYAML_free_tree(err_rc);
1229 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1230 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1231 cYAML_print_tree2file(stderr, err_rc);
1232 cYAML_free_tree(err_rc);
1236 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1237 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1238 cYAML_print_tree2file(stderr, err_rc);
1239 cYAML_free_tree(err_rc);
1243 if (show_rc != NULL) {
1244 cYAML_print_tree2file(f, show_rc);
1245 cYAML_free_tree(show_rc);
1254 static int jt_add_peer_nid(int argc, char **argv)
1256 char *prim_nid = NULL;
1257 char **nids = NULL, **nids2 = NULL;
1259 struct cYAML *err_rc = NULL;
1260 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1261 bool non_mr = false;
1263 const char *const short_opts = "k:mn:";
1264 const struct option long_opts[] = {
1265 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1266 { .name = "non_mr", .has_arg = no_argument, .val = 'm' },
1267 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1270 rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
1274 while ((opt = getopt_long(argc, argv, short_opts,
1275 long_opts, NULL)) != -1) {
1281 size = lustre_lnet_parse_nids(optarg, nids, size,
1286 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1296 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1297 !non_mr, -1, &err_rc);
1301 /* free the array of nids */
1302 for (i = 0; i < size; i++)
1307 if (rc != LUSTRE_CFG_RC_NO_ERR)
1308 cYAML_print_tree2file(stderr, err_rc);
1310 cYAML_free_tree(err_rc);
1315 static int jt_del_peer_nid(int argc, char **argv)
1317 char *prim_nid = NULL;
1318 char **nids = NULL, **nids2 = NULL;
1319 struct cYAML *err_rc = NULL;
1320 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1322 const char *const short_opts = "k:n:";
1323 const struct option long_opts[] = {
1324 { .name = "prim_nid", .has_arg = required_argument, .val = 'k' },
1325 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1328 rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
1332 while ((opt = getopt_long(argc, argv, short_opts,
1333 long_opts, NULL)) != -1) {
1339 size = lustre_lnet_parse_nids(optarg, nids, size,
1344 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1351 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1355 for (i = 0; i < size; i++)
1360 if (rc != LUSTRE_CFG_RC_NO_ERR)
1361 cYAML_print_tree2file(stderr, err_rc);
1363 cYAML_free_tree(err_rc);
1368 static int jt_show_peer(int argc, char **argv)
1372 struct cYAML *err_rc = NULL, *show_rc = NULL;
1373 long int detail = 0;
1375 const char *const short_opts = "hn:v::";
1376 const struct option long_opts[] = {
1377 { .name = "help", .has_arg = no_argument, .val = 'h' },
1378 { .name = "nid", .has_arg = required_argument, .val = 'n' },
1379 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
1382 rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
1386 while ((opt = getopt_long(argc, argv, short_opts,
1387 long_opts, NULL)) != -1) {
1393 if ((!optarg) && (argv[optind] != NULL) &&
1394 (argv[optind][0] != '-')) {
1395 if (parse_long(argv[optind++], &detail) != 0)
1406 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc);
1408 if (rc != LUSTRE_CFG_RC_NO_ERR)
1409 cYAML_print_tree2file(stderr, err_rc);
1411 cYAML_print_tree(show_rc);
1413 cYAML_free_tree(err_rc);
1414 cYAML_free_tree(show_rc);
1419 static int jt_list_peer(int argc, char **argv)
1422 struct cYAML *err_rc = NULL, *list_rc = NULL;
1424 rc = check_cmd(peer_cmds, "peer", "list", 0, argc, argv);
1428 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1430 if (rc != LUSTRE_CFG_RC_NO_ERR)
1431 cYAML_print_tree2file(stderr, err_rc);
1433 cYAML_print_tree(list_rc);
1435 cYAML_free_tree(err_rc);
1436 cYAML_free_tree(list_rc);
1441 static int jt_ping(int argc, char **argv)
1443 struct cYAML *err_rc = NULL;
1444 struct cYAML *show_rc = NULL;
1448 const char *const short_options = "ht:";
1449 const struct option long_options[] = {
1450 { .name = "help", .has_arg = no_argument, .val = 'h' },
1451 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1454 while ((opt = getopt_long(argc, argv, short_options,
1455 long_options, NULL)) != -1) {
1458 timeout = 1000 * atol(optarg);
1461 printf("ping nid[,nid,...]\n"
1462 "\t --timeout: ping timeout\n"
1463 "\t --help: display this help\n");
1470 for (; optind < argc; optind++)
1471 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1474 cYAML_print_tree(show_rc);
1477 cYAML_print_tree2file(stderr, err_rc);
1479 cYAML_free_tree(err_rc);
1480 cYAML_free_tree(show_rc);
1485 static int jt_discover(int argc, char **argv)
1487 struct cYAML *err_rc = NULL;
1488 struct cYAML *show_rc = NULL;
1492 const char *const short_options = "fh";
1493 const struct option long_options[] = {
1494 { .name = "force", .has_arg = no_argument, .val = 'f' },
1495 { .name = "help", .has_arg = no_argument, .val = 'h' },
1498 while ((opt = getopt_long(argc, argv, short_options,
1499 long_options, NULL)) != -1) {
1505 printf("discover nid[,nid,...]\n"
1506 "\t --force: force discovery\n"
1507 "\t --help: display this help\n");
1514 for (; optind < argc; optind++)
1515 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1519 cYAML_print_tree(show_rc);
1522 cYAML_print_tree2file(stderr, err_rc);
1524 cYAML_free_tree(err_rc);
1525 cYAML_free_tree(show_rc);
1530 static int lnetctl_list_commands(int argc, char **argv)
1532 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1534 Parser_list_commands(cmd_list, buffer, sizeof(buffer), NULL, 0, 4);
1539 int main(int argc, char **argv)
1542 struct cYAML *err_rc = NULL;
1544 rc = lustre_lnet_config_lib_init();
1546 cYAML_build_error(-1, -1, "lnetctl", "startup",
1547 "cannot register LNet device", &err_rc);
1548 cYAML_print_tree2file(stderr, err_rc);
1552 Parser_init("lnetctl > ", cmd_list);
1554 rc = Parser_execarg(argc - 1, &argv[1], cmd_list);