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, 2016, 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);
64 command_t lnet_cmds[] = {
65 {"configure", jt_config_lnet, 0, "configure lnet\n"
66 "\t--all: load NI configuration from module parameters\n"},
67 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
71 command_t route_cmds[] = {
72 {"add", jt_add_route, 0, "add a route\n"
73 "\t--net: net name (e.g. tcp0)\n"
74 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
75 "\t--hop: number to final destination (1 < hops < 255)\n"
76 "\t--priority: priority of route (0 - highest prio\n"},
77 {"del", jt_del_route, 0, "delete a route\n"
78 "\t--net: net name (e.g. tcp0)\n"
79 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
80 {"show", jt_show_route, 0, "show routes\n"
81 "\t--net: net name (e.g. tcp0) to filter on\n"
82 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
83 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
84 "\t--priority: priority of route (0 - highest prio to filter on\n"
85 "\t--verbose: display detailed output per route\n"},
89 command_t net_cmds[] = {
90 {"add", jt_add_ni, 0, "add a network\n"
91 "\t--net: net name (e.g. tcp0)\n"
92 "\t--if: physical interface (e.g. eth0)\n"
93 "\t--ip2net: specify networks based on IP address patterns\n"
94 "\t--peer-timeout: time to wait before declaring a peer dead\n"
95 "\t--peer-credits: define the max number of inflight messages\n"
96 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
97 "\t--credits: Network Interface credits\n"
98 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
99 {"del", jt_del_ni, 0, "delete a network\n"
100 "\t--net: net name (e.g. tcp0)\n"
101 "\t--if: physical interface (e.g. eth0)\n"},
102 {"show", jt_show_net, 0, "show networks\n"
103 "\t--net: net name (e.g. tcp0) to filter on\n"
104 "\t--verbose: display detailed output per network."
105 "optional argument of 2 outputs more stats\n"},
109 command_t routing_cmds[] = {
110 {"show", jt_show_routing, 0, "show routing information\n"},
114 command_t stats_cmds[] = {
115 {"show", jt_show_stats, 0, "show LNET statistics\n"},
119 command_t global_cmds[] = {
120 {"show", jt_show_global, 0, "show global variables\n"},
124 command_t set_cmds[] = {
125 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
126 "\tVALUE must be greater than 0\n"},
127 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
128 "\tVALUE must be greater than 0\n"},
129 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
130 "\tVALUE must be greater than 0\n"},
131 {"routing", jt_set_routing, 0, "enable/disable routing\n"
132 "\t0 - disable routing\n"
133 "\t1 - enable routing\n"},
134 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
135 "\tVALUE must be at least 0\n"},
136 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
138 "\tValue must be greater than 16\n"},
139 {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
140 "\t0 - disable peer discovery\n"
141 "\t1 - enable peer discovery (default)\n"},
145 command_t peer_cmds[] = {
146 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
147 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
148 "\t NID in the list becomes the Primary NID of a newly created\n"
150 "\t--nid: one or more peer NIDs\n"
151 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
152 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
153 "\t--prim_nid: Primary NID of the peer.\n"
154 "\t--nid: list of NIDs to remove. If none provided,\n"
155 "\t peer is deleted\n"},
156 {"show", jt_show_peer, 0, "show peer information\n"
157 "\t--nid: NID of peer to filter on.\n"
158 "\t--verbose: display detailed output per peer."
159 "optional argument of 2 outputs more stats\n"},
160 {"list", jt_list_peer, 0, "list all peers\n"},
164 static inline void print_help(const command_t cmds[], const char *cmd_type,
167 const command_t *cmd;
169 for (cmd = cmds; cmd->pc_name; cmd++) {
170 if (pc_name != NULL &&
171 strcmp(cmd->pc_name, pc_name) == 0) {
172 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
175 } else if (pc_name != NULL) {
178 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
182 static int parse_long(const char *number, long int *value)
186 *value = strtol(number, &end, 0);
187 if (end != NULL && *end != 0)
193 static int handle_help(const command_t *cmd_list, const char *cmd,
194 const char *sub_cmd, int argc, char **argv)
201 const char *const short_options = "h";
202 static const struct option long_options[] = {
203 { .name = "help", .has_arg = no_argument, .val = 'h' },
207 while ((opt = getopt_long(argc, argv, short_options,
208 long_options, NULL)) != -1) {
211 print_help(cmd_list, cmd, sub_cmd);
225 static int jt_set_max_intf(int argc, char **argv)
229 struct cYAML *err_rc = NULL;
231 if (handle_help(set_cmds, "set", "max_interfaces", argc, argv) == 0)
234 rc = parse_long(argv[1], &value);
236 cYAML_build_error(-1, -1, "parser", "set",
237 "cannot parse max_interfaces value", &err_rc);
238 cYAML_print_tree2file(stderr, err_rc);
239 cYAML_free_tree(err_rc);
243 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
244 if (rc != LUSTRE_CFG_RC_NO_ERR)
245 cYAML_print_tree2file(stderr, err_rc);
247 cYAML_free_tree(err_rc);
252 static int jt_set_numa(int argc, char **argv)
256 struct cYAML *err_rc = NULL;
258 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
261 rc = parse_long(argv[1], &value);
263 cYAML_build_error(-1, -1, "parser", "set",
264 "cannot parse numa_range value", &err_rc);
265 cYAML_print_tree2file(stderr, err_rc);
266 cYAML_free_tree(err_rc);
270 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
271 if (rc != LUSTRE_CFG_RC_NO_ERR)
272 cYAML_print_tree2file(stderr, err_rc);
274 cYAML_free_tree(err_rc);
279 static int jt_set_discovery(int argc, char **argv)
283 struct cYAML *err_rc = NULL;
285 if (handle_help(set_cmds, "set", "discovery", argc, argv) == 0)
288 rc = parse_long(argv[1], &value);
290 cYAML_build_error(-1, -1, "parser", "set",
291 "cannot parse discovery value", &err_rc);
292 cYAML_print_tree2file(stderr, err_rc);
293 cYAML_free_tree(err_rc);
297 rc = lustre_lnet_config_discovery(value, -1, &err_rc);
298 if (rc != LUSTRE_CFG_RC_NO_ERR)
299 cYAML_print_tree2file(stderr, err_rc);
301 cYAML_free_tree(err_rc);
306 static int jt_set_tiny(int argc, char **argv)
310 struct cYAML *err_rc = NULL;
312 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
315 rc = parse_long(argv[1], &value);
317 cYAML_build_error(-1, -1, "parser", "set",
318 "cannot parse tiny_buffers value", &err_rc);
319 cYAML_print_tree2file(stderr, err_rc);
320 cYAML_free_tree(err_rc);
324 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
325 if (rc != LUSTRE_CFG_RC_NO_ERR)
326 cYAML_print_tree2file(stderr, err_rc);
328 cYAML_free_tree(err_rc);
333 static int jt_set_small(int argc, char **argv)
337 struct cYAML *err_rc = NULL;
339 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
342 rc = parse_long(argv[1], &value);
344 cYAML_build_error(-1, -1, "parser", "set",
345 "cannot parse small_buffers value", &err_rc);
346 cYAML_print_tree2file(stderr, err_rc);
347 cYAML_free_tree(err_rc);
351 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
352 if (rc != LUSTRE_CFG_RC_NO_ERR)
353 cYAML_print_tree2file(stderr, err_rc);
355 cYAML_free_tree(err_rc);
360 static int jt_set_large(int argc, char **argv)
364 struct cYAML *err_rc = NULL;
366 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
369 rc = parse_long(argv[1], &value);
371 cYAML_build_error(-1, -1, "parser", "set",
372 "cannot parse large_buffers value", &err_rc);
373 cYAML_print_tree2file(stderr, err_rc);
374 cYAML_free_tree(err_rc);
378 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
379 if (rc != LUSTRE_CFG_RC_NO_ERR)
380 cYAML_print_tree2file(stderr, err_rc);
382 cYAML_free_tree(err_rc);
387 static int jt_set_routing(int argc, char **argv)
390 struct cYAML *err_rc = NULL;
393 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
396 rc = parse_long(argv[1], &value);
397 if (rc != 0 || (value != 0 && value != 1)) {
398 cYAML_build_error(-1, -1, "parser", "set",
399 "cannot parse routing value.\n"
400 "must be 0 for disable or 1 for enable",
402 cYAML_print_tree2file(stderr, err_rc);
403 cYAML_free_tree(err_rc);
407 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
409 if (rc != LUSTRE_CFG_RC_NO_ERR)
410 cYAML_print_tree2file(stderr, err_rc);
412 cYAML_free_tree(err_rc);
417 static int jt_config_lnet(int argc, char **argv)
419 struct cYAML *err_rc = NULL;
420 bool load_mod_params = false;
423 const char *const short_options = "ah";
424 static const struct option long_options[] = {
425 { .name = "all", .has_arg = no_argument, .val = 'a' },
426 { .name = "help", .has_arg = no_argument, .val = 'h' },
430 while ((opt = getopt_long(argc, argv, short_options,
431 long_options, NULL)) != -1) {
434 load_mod_params = true;
437 print_help(lnet_cmds, "lnet", "configure");
444 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
447 if (rc != LUSTRE_CFG_RC_NO_ERR)
448 cYAML_print_tree2file(stderr, err_rc);
450 cYAML_free_tree(err_rc);
455 static int jt_unconfig_lnet(int argc, char **argv)
457 struct cYAML *err_rc = NULL;
460 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
463 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
465 if (rc != LUSTRE_CFG_RC_NO_ERR)
466 cYAML_print_tree2file(stderr, err_rc);
468 cYAML_free_tree(err_rc);
472 static int jt_add_route(int argc, char **argv)
474 char *network = NULL, *gateway = NULL;
475 long int hop = -1, prio = -1;
476 struct cYAML *err_rc = NULL;
479 const char *const short_options = "n:g:c:p:h";
480 static const struct option long_options[] = {
481 { .name = "net", .has_arg = required_argument, .val = 'n' },
482 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
483 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
484 { .name = "priority", .has_arg = required_argument, .val = 'p' },
485 { .name = "help", .has_arg = no_argument, .val = 'h' },
488 while ((opt = getopt_long(argc, argv, short_options,
489 long_options, NULL)) != -1) {
498 rc = parse_long(optarg, &hop);
506 rc = parse_long(optarg, &prio);
514 print_help(route_cmds, "route", "add");
521 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
523 if (rc != LUSTRE_CFG_RC_NO_ERR)
524 cYAML_print_tree2file(stderr, err_rc);
526 cYAML_free_tree(err_rc);
531 static int jt_add_ni(int argc, char **argv)
534 long int pto = -1, pc = -1, pbc = -1, cre = -1;
535 struct cYAML *err_rc = NULL;
536 int rc, opt, cpt_rc = -1;
537 struct lnet_dlc_network_descr nw_descr;
538 struct cfs_expr_list *global_cpts = NULL;
539 struct lnet_ioctl_config_lnd_tunables tunables;
542 memset(&tunables, 0, sizeof(tunables));
543 lustre_lnet_init_nw_descr(&nw_descr);
545 const char *const short_options = "n:i:p:t:c:b:r:s:h";
546 static const struct option long_options[] = {
547 { .name = "net", .has_arg = required_argument, .val = 'n' },
548 { .name = "if", .has_arg = required_argument, .val = 'i' },
549 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
550 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
551 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
552 { .name = "peer-buffer-credits",
553 .has_arg = required_argument, .val = 'b' },
554 { .name = "credits", .has_arg = required_argument, .val = 'r' },
555 { .name = "cpt", .has_arg = required_argument, .val = 's' },
556 { .name = "help", .has_arg = no_argument, .val = 'h' },
559 while ((opt = getopt_long(argc, argv, short_options,
560 long_options, NULL)) != -1) {
563 nw_descr.nw_id = libcfs_str2net(optarg);
566 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
568 cYAML_build_error(-1, -1, "ni", "add",
569 "bad interface list",
578 rc = parse_long(optarg, &pto);
586 rc = parse_long(optarg, &pc);
594 rc = parse_long(optarg, &pbc);
602 rc = parse_long(optarg, &cre);
610 cpt_rc = cfs_expr_list_parse(optarg,
612 UINT_MAX, &global_cpts);
615 print_help(net_cmds, "net", "add");
622 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
623 tunables.lt_cmn.lct_peer_timeout = pto;
624 tunables.lt_cmn.lct_peer_tx_credits = pc;
625 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
626 tunables.lt_cmn.lct_max_tx_credits = cre;
630 rc = lustre_lnet_config_ni(&nw_descr,
631 (cpt_rc == 0) ? global_cpts: NULL,
632 ip2net, (found) ? &tunables : NULL,
635 if (global_cpts != NULL)
636 cfs_expr_list_free(global_cpts);
639 if (rc != LUSTRE_CFG_RC_NO_ERR)
640 cYAML_print_tree2file(stderr, err_rc);
642 cYAML_free_tree(err_rc);
647 static int jt_del_route(int argc, char **argv)
649 char *network = NULL, *gateway = NULL;
650 struct cYAML *err_rc = NULL;
653 const char *const short_options = "n:g:h";
654 static const struct option long_options[] = {
655 { .name = "net", .has_arg = required_argument, .val = 'n' },
656 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
657 { .name = "help", .has_arg = no_argument, .val = 'h' },
660 while ((opt = getopt_long(argc, argv, short_options,
661 long_options, NULL)) != -1) {
670 print_help(route_cmds, "route", "del");
677 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
679 if (rc != LUSTRE_CFG_RC_NO_ERR)
680 cYAML_print_tree2file(stderr, err_rc);
682 cYAML_free_tree(err_rc);
687 static int jt_del_ni(int argc, char **argv)
689 struct cYAML *err_rc = NULL;
691 struct lnet_dlc_network_descr nw_descr;
693 lustre_lnet_init_nw_descr(&nw_descr);
695 const char *const short_options = "n:i:h";
696 static const struct option long_options[] = {
697 { .name = "net", .has_arg = required_argument, .val = 'n' },
698 { .name = "if", .has_arg = required_argument, .val = 'i' },
699 { .name = "help", .has_arg = no_argument, .val = 'h' },
702 while ((opt = getopt_long(argc, argv, short_options,
703 long_options, NULL)) != -1) {
706 nw_descr.nw_id = libcfs_str2net(optarg);
709 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
711 cYAML_build_error(-1, -1, "ni", "add",
712 "bad interface list",
718 print_help(net_cmds, "net", "del");
725 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
728 if (rc != LUSTRE_CFG_RC_NO_ERR)
729 cYAML_print_tree2file(stderr, err_rc);
731 cYAML_free_tree(err_rc);
736 static int jt_show_route(int argc, char **argv)
738 char *network = NULL, *gateway = NULL;
739 long int hop = -1, prio = -1;
740 int detail = 0, rc, opt;
741 struct cYAML *err_rc = NULL, *show_rc = NULL;
743 const char *const short_options = "n:g:h:p:vh";
744 static const struct option long_options[] = {
745 { .name = "net", .has_arg = required_argument, .val = 'n' },
746 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
747 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
748 { .name = "priority", .has_arg = required_argument, .val = 'p' },
749 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
750 { .name = "help", .has_arg = no_argument, .val = 'h' },
753 while ((opt = getopt_long(argc, argv, short_options,
754 long_options, NULL)) != -1) {
763 rc = parse_long(optarg, &hop);
771 rc = parse_long(optarg, &prio);
782 print_help(route_cmds, "route", "show");
789 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
792 if (rc != LUSTRE_CFG_RC_NO_ERR)
793 cYAML_print_tree2file(stderr, err_rc);
795 cYAML_print_tree(show_rc);
797 cYAML_free_tree(err_rc);
798 cYAML_free_tree(show_rc);
803 static int jt_show_net(int argc, char **argv)
805 char *network = NULL;
807 struct cYAML *err_rc = NULL, *show_rc = NULL;
810 const char *const short_options = "n:vh";
811 static const struct option long_options[] = {
812 { .name = "net", .has_arg = required_argument, .val = 'n' },
813 { .name = "verbose", .has_arg = optional_argument, .val = 'v' },
814 { .name = "help", .has_arg = no_argument, .val = 'h' },
817 while ((opt = getopt_long(argc, argv, short_options,
818 long_options, NULL)) != -1) {
824 if ((!optarg) && (argv[optind] != NULL) &&
825 (argv[optind][0] != '-')) {
826 if (parse_long(argv[optind++], &detail) != 0)
833 print_help(net_cmds, "net", "show");
840 rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc);
842 if (rc != LUSTRE_CFG_RC_NO_ERR)
843 cYAML_print_tree2file(stderr, err_rc);
845 cYAML_print_tree(show_rc);
847 cYAML_free_tree(err_rc);
848 cYAML_free_tree(show_rc);
853 static int jt_show_routing(int argc, char **argv)
855 struct cYAML *err_rc = NULL, *show_rc = NULL;
858 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
861 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
863 if (rc != LUSTRE_CFG_RC_NO_ERR)
864 cYAML_print_tree2file(stderr, err_rc);
866 cYAML_print_tree(show_rc);
868 cYAML_free_tree(err_rc);
869 cYAML_free_tree(show_rc);
874 static int jt_show_stats(int argc, char **argv)
877 struct cYAML *show_rc = NULL, *err_rc = NULL;
879 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
882 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
884 if (rc != LUSTRE_CFG_RC_NO_ERR)
885 cYAML_print_tree2file(stderr, err_rc);
887 cYAML_print_tree(show_rc);
889 cYAML_free_tree(err_rc);
890 cYAML_free_tree(show_rc);
895 static int jt_show_global(int argc, char **argv)
898 struct cYAML *show_rc = NULL, *err_rc = NULL;
900 if (handle_help(global_cmds, "global", "show", argc, argv) == 0)
903 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
904 if (rc != LUSTRE_CFG_RC_NO_ERR) {
905 cYAML_print_tree2file(stderr, err_rc);
909 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
910 if (rc != LUSTRE_CFG_RC_NO_ERR) {
911 cYAML_print_tree2file(stderr, err_rc);
915 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
916 if (rc != LUSTRE_CFG_RC_NO_ERR) {
917 cYAML_print_tree2file(stderr, err_rc);
922 cYAML_print_tree(show_rc);
925 cYAML_free_tree(err_rc);
926 cYAML_free_tree(show_rc);
931 static inline int jt_lnet(int argc, char **argv)
937 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
940 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
943 static inline int jt_route(int argc, char **argv)
949 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
952 return Parser_execarg(argc - 1, &argv[1], route_cmds);
955 static inline int jt_net(int argc, char **argv)
961 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
964 return Parser_execarg(argc - 1, &argv[1], net_cmds);
967 static inline int jt_routing(int argc, char **argv)
973 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
976 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
979 static inline int jt_stats(int argc, char **argv)
985 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
988 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
991 static inline int jt_global(int argc, char **argv)
997 handle_help(global_cmds, "global", NULL, argc, argv) == 0)
1000 return Parser_execarg(argc - 1, &argv[1], global_cmds);
1003 static inline int jt_peers(int argc, char **argv)
1009 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
1012 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
1015 static inline int jt_set(int argc, char **argv)
1021 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
1024 return Parser_execarg(argc - 1, &argv[1], set_cmds);
1027 static int jt_import(int argc, char **argv)
1030 struct cYAML *err_rc = NULL;
1031 struct cYAML *show_rc = NULL;
1032 int rc = 0, return_rc = 0, opt, opt_found = 0;
1035 const char *const short_options = "adsh";
1036 static const struct option long_options[] = {
1037 { .name = "add", .has_arg = no_argument, .val = 'a' },
1038 { .name = "del", .has_arg = no_argument, .val = 'd' },
1039 { .name = "show", .has_arg = no_argument, .val = 's' },
1040 { .name = "exec", .has_arg = no_argument, .val = 'e' },
1041 { .name = "help", .has_arg = no_argument, .val = 'h' },
1044 while ((opt = getopt_long(argc, argv, short_options,
1045 long_options, NULL)) != -1) {
1059 printf("import FILE\n"
1060 "import < FILE : import a file\n"
1061 "\t--add: add configuration\n"
1062 "\t--del: delete configuration\n"
1063 "\t--show: show configuration\n"
1064 "\t--exec: execute command\n"
1065 "\t--help: display this help\n"
1066 "If no command option is given then --add"
1067 " is assumed by default\n");
1074 /* grab the file name if one exists */
1075 if (opt_found && argc == 3)
1077 else if (!opt_found && argc == 2)
1082 rc = lustre_yaml_config(file, &err_rc);
1083 return_rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1084 cYAML_print_tree(show_rc);
1085 cYAML_free_tree(show_rc);
1088 rc = lustre_yaml_del(file, &err_rc);
1091 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1092 cYAML_print_tree(show_rc);
1093 cYAML_free_tree(show_rc);
1096 rc = lustre_yaml_exec(file, &show_rc, &err_rc);
1097 cYAML_print_tree(show_rc);
1098 cYAML_free_tree(show_rc);
1102 if (rc || return_rc) {
1103 cYAML_print_tree2file(stderr, err_rc);
1104 cYAML_free_tree(err_rc);
1110 static int jt_export(int argc, char **argv)
1112 struct cYAML *show_rc = NULL;
1113 struct cYAML *err_rc = NULL;
1117 const char *const short_options = "h";
1118 static const struct option long_options[] = {
1119 { .name = "help", .has_arg = no_argument, .val = 'h' },
1122 while ((opt = getopt_long(argc, argv, short_options,
1123 long_options, NULL)) != -1) {
1126 printf("export FILE\n"
1127 "export > FILE : export configuration\n"
1128 "\t--help: display this help\n");
1136 f = fopen(argv[1], "w");
1142 rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc);
1143 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1144 cYAML_print_tree2file(stderr, err_rc);
1145 cYAML_free_tree(err_rc);
1149 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1151 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1152 cYAML_print_tree2file(stderr, err_rc);
1153 cYAML_free_tree(err_rc);
1157 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1158 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1159 cYAML_print_tree2file(stderr, err_rc);
1160 cYAML_free_tree(err_rc);
1164 rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc);
1165 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1166 cYAML_print_tree2file(stderr, err_rc);
1167 cYAML_free_tree(err_rc);
1171 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1172 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1173 cYAML_print_tree2file(stderr, err_rc);
1174 cYAML_free_tree(err_rc);
1178 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1179 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1180 cYAML_print_tree2file(stderr, err_rc);
1181 cYAML_free_tree(err_rc);
1185 rc = lustre_lnet_show_discovery(-1, &show_rc, &err_rc);
1186 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1187 cYAML_print_tree2file(stderr, err_rc);
1188 cYAML_free_tree(err_rc);
1192 if (show_rc != NULL) {
1193 cYAML_print_tree2file(f, show_rc);
1194 cYAML_free_tree(show_rc);
1203 static int jt_add_peer_nid(int argc, char **argv)
1205 char *prim_nid = NULL;
1206 char **nids = NULL, **nids2 = NULL;
1208 struct cYAML *err_rc = NULL;
1209 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1210 bool non_mr = false;
1212 const char *const short_options = "k:n:mh";
1213 const struct option long_options[] = {
1214 { "prim_nid", 1, NULL, 'k' },
1215 { "nid", 1, NULL, 'n' },
1216 { "non_mr", 0, NULL, 'm'},
1217 { "help", 0, NULL, 'h' },
1218 { NULL, 0, NULL, 0 },
1221 while ((opt = getopt_long(argc, argv, short_options,
1222 long_options, NULL)) != -1) {
1228 size = lustre_lnet_parse_nids(optarg, nids, size,
1233 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1239 print_help(peer_cmds, "peer", "add");
1246 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1247 !non_mr, -1, &err_rc);
1251 /* free the array of nids */
1252 for (i = 0; i < size; i++)
1257 if (rc != LUSTRE_CFG_RC_NO_ERR)
1258 cYAML_print_tree2file(stderr, err_rc);
1260 cYAML_free_tree(err_rc);
1265 static int jt_del_peer_nid(int argc, char **argv)
1267 char *prim_nid = NULL;
1268 char **nids = NULL, **nids2 = NULL;
1269 struct cYAML *err_rc = NULL;
1270 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1272 const char *const short_options = "k:n:h";
1273 const struct option long_options[] = {
1274 { "prim_nid", 1, NULL, 'k' },
1275 { "nid", 1, NULL, 'n' },
1276 { "help", 0, NULL, 'h' },
1277 { NULL, 0, NULL, 0 },
1280 while ((opt = getopt_long(argc, argv, short_options,
1281 long_options, NULL)) != -1) {
1287 size = lustre_lnet_parse_nids(optarg, nids, size,
1292 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1295 print_help(peer_cmds, "peer", "show");
1302 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1306 for (i = 0; i < size; i++)
1311 if (rc != LUSTRE_CFG_RC_NO_ERR)
1312 cYAML_print_tree2file(stderr, err_rc);
1314 cYAML_free_tree(err_rc);
1319 static int jt_show_peer(int argc, char **argv)
1323 struct cYAML *err_rc = NULL, *show_rc = NULL;
1324 long int detail = 0;
1326 const char *const short_options = "n:v::h";
1327 const struct option long_options[] = {
1328 { "nid", 1, NULL, 'n' },
1329 { "verbose", 2, NULL, 'v' },
1330 { "help", 0, NULL, 'h' },
1331 { NULL, 0, NULL, 0 },
1334 while ((opt = getopt_long(argc, argv, short_options,
1335 long_options, NULL)) != -1) {
1341 if ((!optarg) && (argv[optind] != NULL) &&
1342 (argv[optind][0] != '-')) {
1343 if (parse_long(argv[optind++], &detail) != 0)
1350 print_help(peer_cmds, "peer", "show");
1357 rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc);
1359 if (rc != LUSTRE_CFG_RC_NO_ERR)
1360 cYAML_print_tree2file(stderr, err_rc);
1362 cYAML_print_tree(show_rc);
1364 cYAML_free_tree(err_rc);
1365 cYAML_free_tree(show_rc);
1370 static int jt_list_peer(int argc, char **argv)
1373 struct cYAML *err_rc = NULL, *list_rc = NULL;
1375 const char *const short_options = "h";
1376 const struct option long_options[] = {
1377 { "help", 0, NULL, 'h' },
1378 { NULL, 0, NULL, 0 },
1381 while ((opt = getopt_long(argc, argv, short_options,
1382 long_options, NULL)) != -1) {
1385 print_help(peer_cmds, "peer", "list");
1392 rc = lustre_lnet_list_peer(-1, &list_rc, &err_rc);
1394 if (rc != LUSTRE_CFG_RC_NO_ERR)
1395 cYAML_print_tree2file(stderr, err_rc);
1397 cYAML_print_tree(list_rc);
1399 cYAML_free_tree(err_rc);
1400 cYAML_free_tree(list_rc);
1405 static int jt_ping(int argc, char **argv)
1407 struct cYAML *err_rc = NULL;
1408 struct cYAML *show_rc = NULL;
1412 const char *const short_options = "t:h";
1413 const struct option long_options[] = {
1414 { "timeout", 1, NULL, 't' },
1415 { "help", 0, NULL, 'h' },
1416 { NULL, 0, NULL, 0 },
1419 while ((opt = getopt_long(argc, argv, short_options,
1420 long_options, NULL)) != -1) {
1423 timeout = 1000 * atol(optarg);
1426 printf("ping: <nid1> <nid2> .. <nidN> (e.g. 10.2.2.2@tcp)\n"
1427 "\t--timeout: timeout(secs)\n"
1428 "\t--help: display this help\n");
1438 for (; optind < argc; optind++)
1439 rc = lustre_lnet_ping_nid(argv[optind], timeout, -1, &show_rc, &err_rc);
1442 cYAML_print_tree(show_rc);
1445 cYAML_print_tree2file(stderr, err_rc);
1447 cYAML_free_tree(err_rc);
1448 cYAML_free_tree(show_rc);
1453 static int jt_discover(int argc, char **argv)
1455 struct cYAML *err_rc = NULL;
1456 struct cYAML *show_rc = NULL;
1460 const char *const short_options = "fh";
1461 const struct option long_options[] = {
1462 { "force", 0, NULL, 'f' },
1463 { "help", 0, NULL, 'h' },
1464 { NULL, 0, NULL, 0 },
1467 while ((opt = getopt_long(argc, argv, short_options,
1468 long_options, NULL)) != -1) {
1474 printf("discover: nid1 nid2 .. nidN (e.g. 10.2.2.2@tcp)\n"
1476 "\t--help: display this help\n");
1486 for (; optind < argc; optind++)
1487 rc = lustre_lnet_discover_nid(argv[optind], force, -1, &show_rc,
1491 cYAML_print_tree(show_rc);
1494 cYAML_print_tree2file(stderr, err_rc);
1496 cYAML_free_tree(err_rc);
1497 cYAML_free_tree(show_rc);
1502 command_t list[] = {
1503 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1504 {"route", jt_route, 0, "route {add | del | show | help}"},
1505 {"net", jt_net, 0, "net {add | del | show | help}"},
1506 {"routing", jt_routing, 0, "routing {show | help}"},
1507 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1508 " | routing | numa_range | max_interfaces"
1510 {"import", jt_import, 0, "import {--add | --del | --show | "
1511 "--exec | --help} FILE.yaml"},
1512 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1513 {"stats", jt_stats, 0, "stats {show | help}"},
1514 {"global", jt_global, 0, "global {show | help}"},
1515 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1516 {"ping", jt_ping, 0, "ping {--help}"},
1517 {"discover", jt_discover, 0, "discover {--help}"},
1518 {"help", Parser_help, 0, "help"},
1519 {"exit", Parser_quit, 0, "quit"},
1520 {"quit", Parser_quit, 0, "quit"},
1521 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
1525 static int lnetctl_list_commands(int argc, char **argv)
1527 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1529 Parser_list_commands(list, buffer, sizeof(buffer), NULL, 0, 4);
1534 int main(int argc, char **argv)
1537 struct cYAML *err_rc = NULL;
1539 rc = lustre_lnet_config_lib_init();
1541 cYAML_build_error(-1, -1, "lnetctl", "startup",
1542 "cannot register LNet device", &err_rc);
1543 cYAML_print_tree2file(stderr, err_rc);
1547 Parser_init("lnetctl > ", list);
1549 rc = Parser_execarg(argc - 1, &argv[1], list);