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_show_peer(int argc, char **argv);*/
60 static int lnetctl_list_commands(int argc, char **argv);
62 command_t lnet_cmds[] = {
63 {"configure", jt_config_lnet, 0, "configure lnet\n"
64 "\t--all: load NI configuration from module parameters\n"},
65 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
69 command_t route_cmds[] = {
70 {"add", jt_add_route, 0, "add a route\n"
71 "\t--net: net name (e.g. tcp0)\n"
72 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
73 "\t--hop: number to final destination (1 < hops < 255)\n"
74 "\t--priority: priority of route (0 - highest prio\n"},
75 {"del", jt_del_route, 0, "delete a route\n"
76 "\t--net: net name (e.g. tcp0)\n"
77 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
78 {"show", jt_show_route, 0, "show routes\n"
79 "\t--net: net name (e.g. tcp0) to filter on\n"
80 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
81 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
82 "\t--priority: priority of route (0 - highest prio to filter on\n"
83 "\t--verbose: display detailed output per route\n"},
87 command_t net_cmds[] = {
88 {"add", jt_add_ni, 0, "add a network\n"
89 "\t--net: net name (e.g. tcp0)\n"
90 "\t--if: physical interface (e.g. eth0)\n"
91 "\t--ip2net: specify networks based on IP address patterns\n"
92 "\t--peer-timeout: time to wait before declaring a peer dead\n"
93 "\t--peer-credits: define the max number of inflight messages\n"
94 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
95 "\t--credits: Network Interface credits\n"
96 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
97 {"del", jt_del_ni, 0, "delete a network\n"
98 "\t--net: net name (e.g. tcp0)\n"
99 "\t--if: physical interface (e.g. eth0)\n"},
100 {"show", jt_show_net, 0, "show networks\n"
101 "\t--net: net name (e.g. tcp0) to filter on\n"
102 "\t--verbose: display detailed output per network\n"},
106 command_t routing_cmds[] = {
107 {"show", jt_show_routing, 0, "show routing information\n"},
111 command_t stats_cmds[] = {
112 {"show", jt_show_stats, 0, "show LNET statistics\n"},
116 command_t global_cmds[] = {
117 {"show", jt_show_global, 0, "show global variables\n"},
121 command_t set_cmds[] = {
122 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
123 "\tVALUE must be greater than 0\n"},
124 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
125 "\tVALUE must be greater than 0\n"},
126 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
127 "\tVALUE must be greater than 0\n"},
128 {"routing", jt_set_routing, 0, "enable/disable routing\n"
129 "\t0 - disable routing\n"
130 "\t1 - enable routing\n"},
131 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
132 "\tVALUE must be at least 0\n"},
133 {"max_interfaces", jt_set_max_intf, 0, "set the default value for "
135 "\tValue must be greater than 16\n"},
139 command_t peer_cmds[] = {
140 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
141 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
142 "\t NID in the list becomes the Primary NID of a newly created\n"
144 "\t--nid: one or more peer NIDs\n"
145 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
146 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
147 "\t--prim_nid: Primary NID of the peer.\n"
148 "\t--nid: list of NIDs to remove. If none provided,\n"
149 "\t peer is deleted\n"},
150 {"show", jt_show_peer, 0, "show peer information\n"
151 "\t--nid: NID of peer to filter on.\n"
152 "\t--verbose: Include extended statistics\n"},
156 static inline void print_help(const command_t cmds[], const char *cmd_type,
159 const command_t *cmd;
161 for (cmd = cmds; cmd->pc_name; cmd++) {
162 if (pc_name != NULL &&
163 strcmp(cmd->pc_name, pc_name) == 0) {
164 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
167 } else if (pc_name != NULL) {
170 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
174 static int parse_long(const char *number, long int *value)
178 *value = strtol(number, &end, 0);
179 if (end != NULL && *end != 0)
185 static int handle_help(const command_t *cmd_list, const char *cmd,
186 const char *sub_cmd, int argc, char **argv)
193 const char *const short_options = "h";
194 static const struct option long_options[] = {
195 { .name = "help", .has_arg = no_argument, .val = 'h' },
199 while ((opt = getopt_long(argc, argv, short_options,
200 long_options, NULL)) != -1) {
203 print_help(cmd_list, cmd, sub_cmd);
217 static int jt_set_max_intf(int argc, char **argv)
221 struct cYAML *err_rc = NULL;
223 if (handle_help(set_cmds, "set", "max_interfaces", argc, argv) == 0)
226 rc = parse_long(argv[1], &value);
228 cYAML_build_error(-1, -1, "parser", "set",
229 "cannot parse max_interfaces value", &err_rc);
230 cYAML_print_tree2file(stderr, err_rc);
231 cYAML_free_tree(err_rc);
235 rc = lustre_lnet_config_max_intf(value, -1, &err_rc);
236 if (rc != LUSTRE_CFG_RC_NO_ERR)
237 cYAML_print_tree2file(stderr, err_rc);
239 cYAML_free_tree(err_rc);
244 static int jt_set_numa(int argc, char **argv)
248 struct cYAML *err_rc = NULL;
250 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
253 rc = parse_long(argv[1], &value);
255 cYAML_build_error(-1, -1, "parser", "set",
256 "cannot parse numa_range value", &err_rc);
257 cYAML_print_tree2file(stderr, err_rc);
258 cYAML_free_tree(err_rc);
262 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
263 if (rc != LUSTRE_CFG_RC_NO_ERR)
264 cYAML_print_tree2file(stderr, err_rc);
266 cYAML_free_tree(err_rc);
271 static int jt_set_tiny(int argc, char **argv)
275 struct cYAML *err_rc = NULL;
277 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
280 rc = parse_long(argv[1], &value);
282 cYAML_build_error(-1, -1, "parser", "set",
283 "cannot parse tiny_buffers value", &err_rc);
284 cYAML_print_tree2file(stderr, err_rc);
285 cYAML_free_tree(err_rc);
289 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
290 if (rc != LUSTRE_CFG_RC_NO_ERR)
291 cYAML_print_tree2file(stderr, err_rc);
293 cYAML_free_tree(err_rc);
298 static int jt_set_small(int argc, char **argv)
302 struct cYAML *err_rc = NULL;
304 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
307 rc = parse_long(argv[1], &value);
309 cYAML_build_error(-1, -1, "parser", "set",
310 "cannot parse small_buffers value", &err_rc);
311 cYAML_print_tree2file(stderr, err_rc);
312 cYAML_free_tree(err_rc);
316 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
317 if (rc != LUSTRE_CFG_RC_NO_ERR)
318 cYAML_print_tree2file(stderr, err_rc);
320 cYAML_free_tree(err_rc);
325 static int jt_set_large(int argc, char **argv)
329 struct cYAML *err_rc = NULL;
331 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
334 rc = parse_long(argv[1], &value);
336 cYAML_build_error(-1, -1, "parser", "set",
337 "cannot parse large_buffers value", &err_rc);
338 cYAML_print_tree2file(stderr, err_rc);
339 cYAML_free_tree(err_rc);
343 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
344 if (rc != LUSTRE_CFG_RC_NO_ERR)
345 cYAML_print_tree2file(stderr, err_rc);
347 cYAML_free_tree(err_rc);
352 static int jt_set_routing(int argc, char **argv)
355 struct cYAML *err_rc = NULL;
358 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
361 rc = parse_long(argv[1], &value);
362 if (rc != 0 || (value != 0 && value != 1)) {
363 cYAML_build_error(-1, -1, "parser", "set",
364 "cannot parse routing value.\n"
365 "must be 0 for disable or 1 for enable",
367 cYAML_print_tree2file(stderr, err_rc);
368 cYAML_free_tree(err_rc);
372 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
374 if (rc != LUSTRE_CFG_RC_NO_ERR)
375 cYAML_print_tree2file(stderr, err_rc);
377 cYAML_free_tree(err_rc);
382 static int jt_config_lnet(int argc, char **argv)
384 struct cYAML *err_rc = NULL;
385 bool load_mod_params = false;
388 const char *const short_options = "ah";
389 static const struct option long_options[] = {
390 { .name = "all", .has_arg = no_argument, .val = 'a' },
391 { .name = "help", .has_arg = no_argument, .val = 'h' },
395 while ((opt = getopt_long(argc, argv, short_options,
396 long_options, NULL)) != -1) {
399 load_mod_params = true;
402 print_help(lnet_cmds, "lnet", "configure");
409 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
412 if (rc != LUSTRE_CFG_RC_NO_ERR)
413 cYAML_print_tree2file(stderr, err_rc);
415 cYAML_free_tree(err_rc);
420 static int jt_unconfig_lnet(int argc, char **argv)
422 struct cYAML *err_rc = NULL;
425 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
428 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
430 if (rc != LUSTRE_CFG_RC_NO_ERR)
431 cYAML_print_tree2file(stderr, err_rc);
433 cYAML_free_tree(err_rc);
437 static int jt_add_route(int argc, char **argv)
439 char *network = NULL, *gateway = NULL;
440 long int hop = -1, prio = -1;
441 struct cYAML *err_rc = NULL;
444 const char *const short_options = "n:g:c:p:h";
445 static const struct option long_options[] = {
446 { .name = "net", .has_arg = required_argument, .val = 'n' },
447 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
448 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
449 { .name = "priority", .has_arg = required_argument, .val = 'p' },
450 { .name = "help", .has_arg = no_argument, .val = 'h' },
453 while ((opt = getopt_long(argc, argv, short_options,
454 long_options, NULL)) != -1) {
463 rc = parse_long(optarg, &hop);
471 rc = parse_long(optarg, &prio);
479 print_help(route_cmds, "route", "add");
486 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
488 if (rc != LUSTRE_CFG_RC_NO_ERR)
489 cYAML_print_tree2file(stderr, err_rc);
491 cYAML_free_tree(err_rc);
496 static int jt_add_ni(int argc, char **argv)
499 long int pto = -1, pc = -1, pbc = -1, cre = -1;
500 struct cYAML *err_rc = NULL;
501 int rc, opt, cpt_rc = -1;
502 struct lnet_dlc_network_descr nw_descr;
503 struct cfs_expr_list *global_cpts = NULL;
504 struct lnet_ioctl_config_lnd_tunables tunables;
507 memset(&tunables, 0, sizeof(tunables));
508 lustre_lnet_init_nw_descr(&nw_descr);
510 const char *const short_options = "n:i:p:t:c:b:r:s:h";
511 static const struct option long_options[] = {
512 { .name = "net", .has_arg = required_argument, .val = 'n' },
513 { .name = "if", .has_arg = required_argument, .val = 'i' },
514 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
515 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
516 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
517 { .name = "peer-buffer-credits",
518 .has_arg = required_argument, .val = 'b' },
519 { .name = "credits", .has_arg = required_argument, .val = 'r' },
520 { .name = "cpt", .has_arg = required_argument, .val = 's' },
521 { .name = "help", .has_arg = no_argument, .val = 'h' },
524 while ((opt = getopt_long(argc, argv, short_options,
525 long_options, NULL)) != -1) {
528 nw_descr.nw_id = libcfs_str2net(optarg);
531 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
533 cYAML_build_error(-1, -1, "ni", "add",
534 "bad interface list",
543 rc = parse_long(optarg, &pto);
551 rc = parse_long(optarg, &pc);
559 rc = parse_long(optarg, &pbc);
567 rc = parse_long(optarg, &cre);
575 cpt_rc = cfs_expr_list_parse(optarg,
577 UINT_MAX, &global_cpts);
580 print_help(net_cmds, "net", "add");
587 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
588 tunables.lt_cmn.lct_peer_timeout = pto;
589 tunables.lt_cmn.lct_peer_tx_credits = pc;
590 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
591 tunables.lt_cmn.lct_max_tx_credits = cre;
595 rc = lustre_lnet_config_ni(&nw_descr,
596 (cpt_rc == 0) ? global_cpts: NULL,
597 ip2net, (found) ? &tunables : NULL,
600 if (global_cpts != NULL)
601 cfs_expr_list_free(global_cpts);
604 if (rc != LUSTRE_CFG_RC_NO_ERR)
605 cYAML_print_tree2file(stderr, err_rc);
607 cYAML_free_tree(err_rc);
612 static int jt_del_route(int argc, char **argv)
614 char *network = NULL, *gateway = NULL;
615 struct cYAML *err_rc = NULL;
618 const char *const short_options = "n:g:h";
619 static const struct option long_options[] = {
620 { .name = "net", .has_arg = required_argument, .val = 'n' },
621 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
622 { .name = "help", .has_arg = no_argument, .val = 'h' },
625 while ((opt = getopt_long(argc, argv, short_options,
626 long_options, NULL)) != -1) {
635 print_help(route_cmds, "route", "del");
642 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
644 if (rc != LUSTRE_CFG_RC_NO_ERR)
645 cYAML_print_tree2file(stderr, err_rc);
647 cYAML_free_tree(err_rc);
652 static int jt_del_ni(int argc, char **argv)
654 struct cYAML *err_rc = NULL;
656 struct lnet_dlc_network_descr nw_descr;
658 lustre_lnet_init_nw_descr(&nw_descr);
660 const char *const short_options = "n:i:h";
661 static const struct option long_options[] = {
662 { .name = "net", .has_arg = required_argument, .val = 'n' },
663 { .name = "if", .has_arg = required_argument, .val = 'i' },
664 { .name = "help", .has_arg = no_argument, .val = 'h' },
667 while ((opt = getopt_long(argc, argv, short_options,
668 long_options, NULL)) != -1) {
671 nw_descr.nw_id = libcfs_str2net(optarg);
674 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
676 cYAML_build_error(-1, -1, "ni", "add",
677 "bad interface list",
683 print_help(net_cmds, "net", "del");
690 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
693 if (rc != LUSTRE_CFG_RC_NO_ERR)
694 cYAML_print_tree2file(stderr, err_rc);
696 cYAML_free_tree(err_rc);
701 static int jt_show_route(int argc, char **argv)
703 char *network = NULL, *gateway = NULL;
704 long int hop = -1, prio = -1;
705 int detail = 0, rc, opt;
706 struct cYAML *err_rc = NULL, *show_rc = NULL;
708 const char *const short_options = "n:g:h:p:vh";
709 static const struct option long_options[] = {
710 { .name = "net", .has_arg = required_argument, .val = 'n' },
711 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
712 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
713 { .name = "priority", .has_arg = required_argument, .val = 'p' },
714 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
715 { .name = "help", .has_arg = no_argument, .val = 'h' },
718 while ((opt = getopt_long(argc, argv, short_options,
719 long_options, NULL)) != -1) {
728 rc = parse_long(optarg, &hop);
736 rc = parse_long(optarg, &prio);
747 print_help(route_cmds, "route", "show");
754 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
757 if (rc != LUSTRE_CFG_RC_NO_ERR)
758 cYAML_print_tree2file(stderr, err_rc);
760 cYAML_print_tree(show_rc);
762 cYAML_free_tree(err_rc);
763 cYAML_free_tree(show_rc);
768 static int jt_show_net(int argc, char **argv)
770 char *network = NULL;
771 int detail = 0, rc, opt;
772 struct cYAML *err_rc = NULL, *show_rc = NULL;
774 const char *const short_options = "n:vh";
775 static const struct option long_options[] = {
776 { .name = "net", .has_arg = required_argument, .val = 'n' },
777 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
778 { .name = "help", .has_arg = no_argument, .val = 'h' },
781 while ((opt = getopt_long(argc, argv, short_options,
782 long_options, NULL)) != -1) {
791 print_help(net_cmds, "net", "show");
798 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
800 if (rc != LUSTRE_CFG_RC_NO_ERR)
801 cYAML_print_tree2file(stderr, err_rc);
803 cYAML_print_tree(show_rc);
805 cYAML_free_tree(err_rc);
806 cYAML_free_tree(show_rc);
811 static int jt_show_routing(int argc, char **argv)
813 struct cYAML *err_rc = NULL, *show_rc = NULL;
816 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
819 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
821 if (rc != LUSTRE_CFG_RC_NO_ERR)
822 cYAML_print_tree2file(stderr, err_rc);
824 cYAML_print_tree(show_rc);
826 cYAML_free_tree(err_rc);
827 cYAML_free_tree(show_rc);
832 static int jt_show_stats(int argc, char **argv)
835 struct cYAML *show_rc = NULL, *err_rc = NULL;
837 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
840 rc = lustre_lnet_show_stats(-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_global(int argc, char **argv)
856 struct cYAML *show_rc = NULL, *err_rc = NULL;
858 if (handle_help(global_cmds, "global", "show", argc, argv) == 0)
861 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
862 if (rc != LUSTRE_CFG_RC_NO_ERR) {
863 cYAML_print_tree2file(stderr, err_rc);
867 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
868 if (rc != LUSTRE_CFG_RC_NO_ERR) {
869 cYAML_print_tree2file(stderr, err_rc);
874 cYAML_print_tree(show_rc);
877 cYAML_free_tree(err_rc);
878 cYAML_free_tree(show_rc);
883 static inline int jt_lnet(int argc, char **argv)
889 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
892 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
895 static inline int jt_route(int argc, char **argv)
901 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
904 return Parser_execarg(argc - 1, &argv[1], route_cmds);
907 static inline int jt_net(int argc, char **argv)
913 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
916 return Parser_execarg(argc - 1, &argv[1], net_cmds);
919 static inline int jt_routing(int argc, char **argv)
925 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
928 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
931 static inline int jt_stats(int argc, char **argv)
937 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
940 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
943 static inline int jt_global(int argc, char **argv)
949 handle_help(global_cmds, "global", NULL, argc, argv) == 0)
952 return Parser_execarg(argc - 1, &argv[1], global_cmds);
955 static inline int jt_peers(int argc, char **argv)
961 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
964 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
967 static inline int jt_set(int argc, char **argv)
973 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
976 return Parser_execarg(argc - 1, &argv[1], set_cmds);
979 static int jt_import(int argc, char **argv)
982 struct cYAML *err_rc = NULL;
983 struct cYAML *show_rc = NULL;
984 int rc = 0, opt, opt_found = 0;
987 const char *const short_options = "adsh";
988 static const struct option long_options[] = {
989 { .name = "add", .has_arg = no_argument, .val = 'a' },
990 { .name = "del", .has_arg = no_argument, .val = 'd' },
991 { .name = "show", .has_arg = no_argument, .val = 's' },
992 { .name = "help", .has_arg = no_argument, .val = 'h' },
995 while ((opt = getopt_long(argc, argv, short_options,
996 long_options, NULL)) != -1) {
1005 printf("import FILE\n"
1006 "import < FILE : import a file\n"
1007 "\t--add: add configuration\n"
1008 "\t--del: delete configuration\n"
1009 "\t--show: show configuration\n"
1010 "\t--help: display this help\n"
1011 "If no command option is given then --add"
1012 " is assumed by default\n");
1019 /* grab the file name if one exists */
1020 if (opt_found && argc == 3)
1022 else if (!opt_found && argc == 2)
1027 rc = lustre_yaml_config(file, &err_rc);
1030 rc = lustre_yaml_del(file, &err_rc);
1033 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1034 cYAML_print_tree(show_rc);
1035 cYAML_free_tree(show_rc);
1039 cYAML_print_tree2file(stderr, err_rc);
1041 cYAML_free_tree(err_rc);
1046 static int jt_export(int argc, char **argv)
1048 struct cYAML *show_rc = NULL;
1049 struct cYAML *err_rc = NULL;
1053 const char *const short_options = "h";
1054 static const struct option long_options[] = {
1055 { .name = "help", .has_arg = no_argument, .val = 'h' },
1058 while ((opt = getopt_long(argc, argv, short_options,
1059 long_options, NULL)) != -1) {
1062 printf("export FILE\n"
1063 "export > FILE : export configuration\n"
1064 "\t--help: display this help\n");
1072 f = fopen(argv[1], "w");
1078 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1079 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1080 cYAML_print_tree2file(stderr, err_rc);
1081 cYAML_free_tree(err_rc);
1084 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1086 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1087 cYAML_print_tree2file(stderr, err_rc);
1088 cYAML_free_tree(err_rc);
1091 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1092 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1093 cYAML_print_tree2file(stderr, err_rc);
1094 cYAML_free_tree(err_rc);
1097 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1098 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1099 cYAML_print_tree2file(stderr, err_rc);
1100 cYAML_free_tree(err_rc);
1103 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1104 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1105 cYAML_print_tree2file(stderr, err_rc);
1106 cYAML_free_tree(err_rc);
1109 rc = lustre_lnet_show_max_intf(-1, &show_rc, &err_rc);
1110 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1111 cYAML_print_tree2file(stderr, err_rc);
1112 cYAML_free_tree(err_rc);
1115 if (show_rc != NULL) {
1116 cYAML_print_tree2file(f, show_rc);
1117 cYAML_free_tree(show_rc);
1126 static int jt_add_peer_nid(int argc, char **argv)
1128 char *prim_nid = NULL;
1129 char **nids = NULL, **nids2 = NULL;
1131 struct cYAML *err_rc = NULL;
1132 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1133 bool non_mr = false;
1135 const char *const short_options = "k:n:mh";
1136 const struct option long_options[] = {
1137 { "prim_nid", 1, NULL, 'k' },
1138 { "nid", 1, NULL, 'n' },
1139 { "non_mr", 0, NULL, 'm'},
1140 { "help", 0, NULL, 'h' },
1141 { NULL, 0, NULL, 0 },
1144 while ((opt = getopt_long(argc, argv, short_options,
1145 long_options, NULL)) != -1) {
1151 size = lustre_lnet_parse_nids(optarg, nids, size,
1156 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1162 print_help(peer_cmds, "peer", "add");
1169 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1170 !non_mr, -1, &err_rc);
1174 /* free the array of nids */
1175 for (i = 0; i < size; i++)
1180 if (rc != LUSTRE_CFG_RC_NO_ERR)
1181 cYAML_print_tree2file(stderr, err_rc);
1183 cYAML_free_tree(err_rc);
1188 static int jt_del_peer_nid(int argc, char **argv)
1190 char *prim_nid = NULL;
1191 char **nids = NULL, **nids2 = NULL;
1192 struct cYAML *err_rc = NULL;
1193 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1195 const char *const short_options = "k:n:h";
1196 const struct option long_options[] = {
1197 { "prim_nid", 1, NULL, 'k' },
1198 { "nid", 1, NULL, 'n' },
1199 { "help", 0, NULL, 'h' },
1200 { NULL, 0, NULL, 0 },
1203 while ((opt = getopt_long(argc, argv, short_options,
1204 long_options, NULL)) != -1) {
1210 size = lustre_lnet_parse_nids(optarg, nids, size,
1215 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1218 print_help(peer_cmds, "peer", "del");
1225 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1229 for (i = 0; i < size; i++)
1234 if (rc != LUSTRE_CFG_RC_NO_ERR)
1235 cYAML_print_tree2file(stderr, err_rc);
1237 cYAML_free_tree(err_rc);
1242 static int jt_show_peer(int argc, char **argv)
1246 struct cYAML *err_rc = NULL, *show_rc = NULL;
1249 const char *const short_options = "n:vh";
1250 const struct option long_options[] = {
1251 { "nid", 1, NULL, 'n' },
1252 { "verbose", 0, NULL, 'v' },
1253 { "help", 0, NULL, 'h' },
1254 { NULL, 0, NULL, 0 },
1257 while ((opt = getopt_long(argc, argv, short_options,
1258 long_options, NULL)) != -1) {
1267 print_help(peer_cmds, "peer", "show");
1274 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1276 if (rc != LUSTRE_CFG_RC_NO_ERR)
1277 cYAML_print_tree2file(stderr, err_rc);
1279 cYAML_print_tree(show_rc);
1281 cYAML_free_tree(err_rc);
1282 cYAML_free_tree(show_rc);
1287 command_t list[] = {
1288 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1289 {"route", jt_route, 0, "route {add | del | show | help}"},
1290 {"net", jt_net, 0, "net {add | del | show | help}"},
1291 {"routing", jt_routing, 0, "routing {show | help}"},
1292 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1293 " | routing | numa_range | max_interfaces}"},
1294 {"import", jt_import, 0, "import {--add | --del | --show | "
1295 "--help} FILE.yaml"},
1296 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1297 {"stats", jt_stats, 0, "stats {show | help}"},
1298 {"global", jt_global, 0, "global {show | help}"},
1299 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1300 {"help", Parser_help, 0, "help"},
1301 {"exit", Parser_quit, 0, "quit"},
1302 {"quit", Parser_quit, 0, "quit"},
1303 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
1307 static int lnetctl_list_commands(int argc, char **argv)
1309 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1311 Parser_list_commands(list, buffer, sizeof(buffer), NULL, 0, 4);
1316 int main(int argc, char **argv)
1319 struct cYAML *err_rc = NULL;
1321 rc = lustre_lnet_config_lib_init();
1323 cYAML_build_error(-1, -1, "lnetctl", "startup",
1324 "cannot register LNet device", &err_rc);
1325 cYAML_print_tree2file(stderr, err_rc);
1329 Parser_init("lnetctl > ", list);
1331 rc = Parser_execarg(argc - 1, &argv[1], list);