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>
33 #include <lnet/lnetctl.h>
34 #include <lnet/nidstr.h>
36 #include "lnetconfig/liblnetconfig.h"
38 #define LNET_CONFIGURE true
39 #define LNET_UNCONFIGURE false
41 static int jt_config_lnet(int argc, char **argv);
42 static int jt_unconfig_lnet(int argc, char **argv);
43 static int jt_add_route(int argc, char **argv);
44 static int jt_add_ni(int argc, char **argv);
45 static int jt_set_routing(int argc, char **argv);
46 static int jt_del_route(int argc, char **argv);
47 static int jt_del_ni(int argc, char **argv);
48 static int jt_show_route(int argc, char **argv);
49 static int jt_show_net(int argc, char **argv);
50 static int jt_show_routing(int argc, char **argv);
51 static int jt_show_stats(int argc, char **argv);
52 static int jt_show_peer(int argc, char **argv);
53 static int jt_show_numa(int argc, char **argv);
54 static int jt_set_tiny(int argc, char **argv);
55 static int jt_set_small(int argc, char **argv);
56 static int jt_set_large(int argc, char **argv);
57 static int jt_set_numa(int argc, char **argv);
58 static int jt_add_peer_nid(int argc, char **argv);
59 static int jt_del_peer_nid(int argc, char **argv);
60 /*static int jt_show_peer(int argc, char **argv);*/
61 static int lnetctl_list_commands(int argc, char **argv);
63 command_t lnet_cmds[] = {
64 {"configure", jt_config_lnet, 0, "configure lnet\n"
65 "\t--all: load NI configuration from module parameters\n"},
66 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
70 command_t route_cmds[] = {
71 {"add", jt_add_route, 0, "add a route\n"
72 "\t--net: net name (e.g. tcp0)\n"
73 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
74 "\t--hop: number to final destination (1 < hops < 255)\n"
75 "\t--priority: priority of route (0 - highest prio\n"},
76 {"del", jt_del_route, 0, "delete a route\n"
77 "\t--net: net name (e.g. tcp0)\n"
78 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
79 {"show", jt_show_route, 0, "show routes\n"
80 "\t--net: net name (e.g. tcp0) to filter on\n"
81 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
82 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
83 "\t--priority: priority of route (0 - highest prio to filter on\n"
84 "\t--verbose: display detailed output per route\n"},
88 command_t net_cmds[] = {
89 {"add", jt_add_ni, 0, "add a network\n"
90 "\t--net: net name (e.g. tcp0)\n"
91 "\t--if: physical interface (e.g. eth0)\n"
92 "\t--ip2net: specify networks based on IP address patterns\n"
93 "\t--peer-timeout: time to wait before declaring a peer dead\n"
94 "\t--peer-credits: define the max number of inflight messages\n"
95 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
96 "\t--credits: Network Interface credits\n"
97 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
98 {"del", jt_del_ni, 0, "delete a network\n"
99 "\t--net: net name (e.g. tcp0)\n"
100 "\t--if: physical interface (e.g. eth0)\n"},
101 {"show", jt_show_net, 0, "show networks\n"
102 "\t--net: net name (e.g. tcp0) to filter on\n"
103 "\t--verbose: display detailed output per network\n"},
107 command_t routing_cmds[] = {
108 {"show", jt_show_routing, 0, "show routing information\n"},
112 command_t stats_cmds[] = {
113 {"show", jt_show_stats, 0, "show LNET statistics\n"},
117 command_t numa_cmds[] = {
118 {"show", jt_show_numa, 0, "show NUMA range\n"},
122 command_t set_cmds[] = {
123 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
124 "\tVALUE must be greater than 0\n"},
125 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
126 "\tVALUE must be greater than 0\n"},
127 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
128 "\tVALUE must be greater than 0\n"},
129 {"routing", jt_set_routing, 0, "enable/disable routing\n"
130 "\t0 - disable routing\n"
131 "\t1 - enable routing\n"},
132 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
133 "\tVALUE must be at least 0\n"},
137 command_t peer_cmds[] = {
138 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
139 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
140 "\t NID in the list becomes the Primary NID of a newly created\n"
142 "\t--nid: one or more peer NIDs\n"
143 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
144 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
145 "\t--prim_nid: Primary NID of the peer.\n"
146 "\t--nid: list of NIDs to remove. If none provided,\n"
147 "\t peer is deleted\n"},
148 {"show", jt_show_peer, 0, "show peer information\n"
149 "\t--nid: NID of peer to filter on.\n"
150 "\t--verbose: Include extended statistics\n"},
154 static inline void print_help(const command_t cmds[], const char *cmd_type,
157 const command_t *cmd;
159 for (cmd = cmds; cmd->pc_name; cmd++) {
160 if (pc_name != NULL &&
161 strcmp(cmd->pc_name, pc_name) == 0) {
162 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
165 } else if (pc_name != NULL) {
168 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
172 static int parse_long(const char *number, long int *value)
176 *value = strtol(number, &end, 0);
177 if (end != NULL && *end != 0)
183 static int handle_help(const command_t *cmd_list, const char *cmd,
184 const char *sub_cmd, int argc, char **argv)
191 const char *const short_options = "h";
192 static const struct option long_options[] = {
193 { .name = "help", .has_arg = no_argument, .val = 'h' },
197 while ((opt = getopt_long(argc, argv, short_options,
198 long_options, NULL)) != -1) {
201 print_help(cmd_list, cmd, sub_cmd);
215 static int jt_set_numa(int argc, char **argv)
219 struct cYAML *err_rc = NULL;
221 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
224 rc = parse_long(argv[1], &value);
226 cYAML_build_error(-1, -1, "parser", "set",
227 "cannot parse numa_range value", &err_rc);
228 cYAML_print_tree2file(stderr, err_rc);
229 cYAML_free_tree(err_rc);
233 rc = lustre_lnet_config_numa_range(value, -1, &err_rc);
234 if (rc != LUSTRE_CFG_RC_NO_ERR)
235 cYAML_print_tree2file(stderr, err_rc);
237 cYAML_free_tree(err_rc);
242 static int jt_set_tiny(int argc, char **argv)
246 struct cYAML *err_rc = NULL;
248 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
251 rc = parse_long(argv[1], &value);
253 cYAML_build_error(-1, -1, "parser", "set",
254 "cannot parse tiny_buffers value", &err_rc);
255 cYAML_print_tree2file(stderr, err_rc);
256 cYAML_free_tree(err_rc);
260 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
261 if (rc != LUSTRE_CFG_RC_NO_ERR)
262 cYAML_print_tree2file(stderr, err_rc);
264 cYAML_free_tree(err_rc);
269 static int jt_set_small(int argc, char **argv)
273 struct cYAML *err_rc = NULL;
275 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
278 rc = parse_long(argv[1], &value);
280 cYAML_build_error(-1, -1, "parser", "set",
281 "cannot parse small_buffers value", &err_rc);
282 cYAML_print_tree2file(stderr, err_rc);
283 cYAML_free_tree(err_rc);
287 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
288 if (rc != LUSTRE_CFG_RC_NO_ERR)
289 cYAML_print_tree2file(stderr, err_rc);
291 cYAML_free_tree(err_rc);
296 static int jt_set_large(int argc, char **argv)
300 struct cYAML *err_rc = NULL;
302 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
305 rc = parse_long(argv[1], &value);
307 cYAML_build_error(-1, -1, "parser", "set",
308 "cannot parse large_buffers value", &err_rc);
309 cYAML_print_tree2file(stderr, err_rc);
310 cYAML_free_tree(err_rc);
314 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
315 if (rc != LUSTRE_CFG_RC_NO_ERR)
316 cYAML_print_tree2file(stderr, err_rc);
318 cYAML_free_tree(err_rc);
323 static int jt_set_routing(int argc, char **argv)
326 struct cYAML *err_rc = NULL;
329 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
332 rc = parse_long(argv[1], &value);
333 if (rc != 0 || (value != 0 && value != 1)) {
334 cYAML_build_error(-1, -1, "parser", "set",
335 "cannot parse routing value.\n"
336 "must be 0 for disable or 1 for enable",
338 cYAML_print_tree2file(stderr, err_rc);
339 cYAML_free_tree(err_rc);
343 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
345 if (rc != LUSTRE_CFG_RC_NO_ERR)
346 cYAML_print_tree2file(stderr, err_rc);
348 cYAML_free_tree(err_rc);
353 static int jt_config_lnet(int argc, char **argv)
355 struct cYAML *err_rc = NULL;
356 bool load_mod_params = false;
359 const char *const short_options = "ah";
360 static const struct option long_options[] = {
361 { .name = "all", .has_arg = no_argument, .val = 'a' },
362 { .name = "help", .has_arg = no_argument, .val = 'h' },
366 while ((opt = getopt_long(argc, argv, short_options,
367 long_options, NULL)) != -1) {
370 load_mod_params = true;
373 print_help(lnet_cmds, "lnet", "configure");
380 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
383 if (rc != LUSTRE_CFG_RC_NO_ERR)
384 cYAML_print_tree2file(stderr, err_rc);
386 cYAML_free_tree(err_rc);
391 static int jt_unconfig_lnet(int argc, char **argv)
393 struct cYAML *err_rc = NULL;
396 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
399 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
401 if (rc != LUSTRE_CFG_RC_NO_ERR)
402 cYAML_print_tree2file(stderr, err_rc);
404 cYAML_free_tree(err_rc);
408 static int jt_add_route(int argc, char **argv)
410 char *network = NULL, *gateway = NULL;
411 long int hop = -1, prio = -1;
412 struct cYAML *err_rc = NULL;
415 const char *const short_options = "n:g:c:p:h";
416 static const struct option long_options[] = {
417 { .name = "net", .has_arg = required_argument, .val = 'n' },
418 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
419 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
420 { .name = "priority", .has_arg = required_argument, .val = 'p' },
421 { .name = "help", .has_arg = no_argument, .val = 'h' },
424 while ((opt = getopt_long(argc, argv, short_options,
425 long_options, NULL)) != -1) {
434 rc = parse_long(optarg, &hop);
442 rc = parse_long(optarg, &prio);
450 print_help(route_cmds, "route", "add");
457 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
459 if (rc != LUSTRE_CFG_RC_NO_ERR)
460 cYAML_print_tree2file(stderr, err_rc);
462 cYAML_free_tree(err_rc);
467 static int jt_add_ni(int argc, char **argv)
470 long int pto = -1, pc = -1, pbc = -1, cre = -1;
471 struct cYAML *err_rc = NULL;
472 int rc, opt, cpt_rc = -1;
473 struct lnet_dlc_network_descr nw_descr;
474 struct cfs_expr_list *global_cpts = NULL;
475 struct lnet_ioctl_config_lnd_tunables tunables;
478 memset(&tunables, 0, sizeof(tunables));
479 lustre_lnet_init_nw_descr(&nw_descr);
481 const char *const short_options = "n:i:p:t:c:b:r:s:h";
482 static const struct option long_options[] = {
483 { .name = "net", .has_arg = required_argument, .val = 'n' },
484 { .name = "if", .has_arg = required_argument, .val = 'i' },
485 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
486 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
487 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
488 { .name = "peer-buffer-credits",
489 .has_arg = required_argument, .val = 'b' },
490 { .name = "credits", .has_arg = required_argument, .val = 'r' },
491 { .name = "cpt", .has_arg = required_argument, .val = 's' },
492 { .name = "help", .has_arg = no_argument, .val = 'h' },
495 while ((opt = getopt_long(argc, argv, short_options,
496 long_options, NULL)) != -1) {
499 nw_descr.nw_id = libcfs_str2net(optarg);
502 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
504 cYAML_build_error(-1, -1, "ni", "add",
505 "bad interface list",
514 rc = parse_long(optarg, &pto);
522 rc = parse_long(optarg, &pc);
530 rc = parse_long(optarg, &pbc);
538 rc = parse_long(optarg, &cre);
546 cpt_rc = cfs_expr_list_parse(optarg,
548 UINT_MAX, &global_cpts);
551 print_help(net_cmds, "net", "add");
558 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
559 tunables.lt_cmn.lct_peer_timeout = pto;
560 tunables.lt_cmn.lct_peer_tx_credits = pc;
561 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
562 tunables.lt_cmn.lct_max_tx_credits = cre;
566 rc = lustre_lnet_config_ni(&nw_descr,
567 (cpt_rc == 0) ? global_cpts: NULL,
568 ip2net, (found) ? &tunables : NULL,
571 if (global_cpts != NULL)
572 cfs_expr_list_free(global_cpts);
575 if (rc != LUSTRE_CFG_RC_NO_ERR)
576 cYAML_print_tree2file(stderr, err_rc);
578 cYAML_free_tree(err_rc);
583 static int jt_del_route(int argc, char **argv)
585 char *network = NULL, *gateway = NULL;
586 struct cYAML *err_rc = NULL;
589 const char *const short_options = "n:g:h";
590 static const struct option long_options[] = {
591 { .name = "net", .has_arg = required_argument, .val = 'n' },
592 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
593 { .name = "help", .has_arg = no_argument, .val = 'h' },
596 while ((opt = getopt_long(argc, argv, short_options,
597 long_options, NULL)) != -1) {
606 print_help(route_cmds, "route", "del");
613 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
615 if (rc != LUSTRE_CFG_RC_NO_ERR)
616 cYAML_print_tree2file(stderr, err_rc);
618 cYAML_free_tree(err_rc);
623 static int jt_del_ni(int argc, char **argv)
625 struct cYAML *err_rc = NULL;
627 struct lnet_dlc_network_descr nw_descr;
629 lustre_lnet_init_nw_descr(&nw_descr);
631 const char *const short_options = "n:i:h";
632 static const struct option long_options[] = {
633 { .name = "net", .has_arg = required_argument, .val = 'n' },
634 { .name = "if", .has_arg = required_argument, .val = 'i' },
635 { .name = "help", .has_arg = no_argument, .val = 'h' },
638 while ((opt = getopt_long(argc, argv, short_options,
639 long_options, NULL)) != -1) {
642 nw_descr.nw_id = libcfs_str2net(optarg);
645 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
647 cYAML_build_error(-1, -1, "ni", "add",
648 "bad interface list",
654 print_help(net_cmds, "net", "del");
661 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
664 if (rc != LUSTRE_CFG_RC_NO_ERR)
665 cYAML_print_tree2file(stderr, err_rc);
667 cYAML_free_tree(err_rc);
672 static int jt_show_route(int argc, char **argv)
674 char *network = NULL, *gateway = NULL;
675 long int hop = -1, prio = -1;
676 int detail = 0, rc, opt;
677 struct cYAML *err_rc = NULL, *show_rc = NULL;
679 const char *const short_options = "n:g:h:p:vh";
680 static const struct option long_options[] = {
681 { .name = "net", .has_arg = required_argument, .val = 'n' },
682 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
683 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
684 { .name = "priority", .has_arg = required_argument, .val = 'p' },
685 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
686 { .name = "help", .has_arg = no_argument, .val = 'h' },
689 while ((opt = getopt_long(argc, argv, short_options,
690 long_options, NULL)) != -1) {
699 rc = parse_long(optarg, &hop);
707 rc = parse_long(optarg, &prio);
718 print_help(route_cmds, "route", "show");
725 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
728 if (rc != LUSTRE_CFG_RC_NO_ERR)
729 cYAML_print_tree2file(stderr, err_rc);
731 cYAML_print_tree(show_rc);
733 cYAML_free_tree(err_rc);
734 cYAML_free_tree(show_rc);
739 static int jt_show_net(int argc, char **argv)
741 char *network = NULL;
742 int detail = 0, rc, opt;
743 struct cYAML *err_rc = NULL, *show_rc = NULL;
745 const char *const short_options = "n:vh";
746 static const struct option long_options[] = {
747 { .name = "net", .has_arg = required_argument, .val = 'n' },
748 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
749 { .name = "help", .has_arg = no_argument, .val = 'h' },
752 while ((opt = getopt_long(argc, argv, short_options,
753 long_options, NULL)) != -1) {
762 print_help(net_cmds, "net", "show");
769 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
771 if (rc != LUSTRE_CFG_RC_NO_ERR)
772 cYAML_print_tree2file(stderr, err_rc);
774 cYAML_print_tree(show_rc);
776 cYAML_free_tree(err_rc);
777 cYAML_free_tree(show_rc);
782 static int jt_show_routing(int argc, char **argv)
784 struct cYAML *err_rc = NULL, *show_rc = NULL;
787 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
790 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
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_stats(int argc, char **argv)
806 struct cYAML *show_rc = NULL, *err_rc = NULL;
808 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
811 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
813 if (rc != LUSTRE_CFG_RC_NO_ERR)
814 cYAML_print_tree2file(stderr, err_rc);
816 cYAML_print_tree(show_rc);
818 cYAML_free_tree(err_rc);
819 cYAML_free_tree(show_rc);
824 static int jt_show_numa(int argc, char **argv)
827 struct cYAML *show_rc = NULL, *err_rc = NULL;
829 if (handle_help(numa_cmds, "numa", "show", argc, argv) == 0)
832 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
834 if (rc != LUSTRE_CFG_RC_NO_ERR)
835 cYAML_print_tree2file(stderr, err_rc);
837 cYAML_print_tree(show_rc);
839 cYAML_free_tree(err_rc);
840 cYAML_free_tree(show_rc);
845 static inline int jt_lnet(int argc, char **argv)
851 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
854 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
857 static inline int jt_route(int argc, char **argv)
863 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
866 return Parser_execarg(argc - 1, &argv[1], route_cmds);
869 static inline int jt_net(int argc, char **argv)
875 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
878 return Parser_execarg(argc - 1, &argv[1], net_cmds);
881 static inline int jt_routing(int argc, char **argv)
887 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
890 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
893 static inline int jt_stats(int argc, char **argv)
899 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
902 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
905 static inline int jt_numa(int argc, char **argv)
911 handle_help(numa_cmds, "numa", NULL, argc, argv) == 0)
914 return Parser_execarg(argc - 1, &argv[1], numa_cmds);
917 static inline int jt_peers(int argc, char **argv)
923 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
926 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
929 static inline int jt_set(int argc, char **argv)
935 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
938 return Parser_execarg(argc - 1, &argv[1], set_cmds);
941 static int jt_import(int argc, char **argv)
944 struct cYAML *err_rc = NULL;
945 struct cYAML *show_rc = NULL;
946 int rc = 0, opt, opt_found = 0;
949 const char *const short_options = "adsh";
950 static const struct option long_options[] = {
951 { .name = "add", .has_arg = no_argument, .val = 'a' },
952 { .name = "del", .has_arg = no_argument, .val = 'd' },
953 { .name = "show", .has_arg = no_argument, .val = 's' },
954 { .name = "help", .has_arg = no_argument, .val = 'h' },
957 while ((opt = getopt_long(argc, argv, short_options,
958 long_options, NULL)) != -1) {
967 printf("import FILE\n"
968 "import < FILE : import a file\n"
969 "\t--add: add configuration\n"
970 "\t--del: delete configuration\n"
971 "\t--show: show configuration\n"
972 "\t--help: display this help\n"
973 "If no command option is given then --add"
974 " is assumed by default\n");
981 /* grab the file name if one exists */
982 if (opt_found && argc == 3)
984 else if (!opt_found && argc == 2)
989 rc = lustre_yaml_config(file, &err_rc);
992 rc = lustre_yaml_del(file, &err_rc);
995 rc = lustre_yaml_show(file, &show_rc, &err_rc);
996 cYAML_print_tree(show_rc);
997 cYAML_free_tree(show_rc);
1001 cYAML_print_tree2file(stderr, err_rc);
1003 cYAML_free_tree(err_rc);
1008 static int jt_export(int argc, char **argv)
1010 struct cYAML *show_rc = NULL;
1011 struct cYAML *err_rc = NULL;
1015 const char *const short_options = "h";
1016 static const struct option long_options[] = {
1017 { .name = "help", .has_arg = no_argument, .val = 'h' },
1020 while ((opt = getopt_long(argc, argv, short_options,
1021 long_options, NULL)) != -1) {
1024 printf("export FILE\n"
1025 "export > FILE : export configuration\n"
1026 "\t--help: display this help\n");
1034 f = fopen(argv[1], "w");
1040 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1041 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1042 cYAML_print_tree2file(stderr, err_rc);
1043 cYAML_free_tree(err_rc);
1046 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1048 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1049 cYAML_print_tree2file(stderr, err_rc);
1050 cYAML_free_tree(err_rc);
1053 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1054 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1055 cYAML_print_tree2file(stderr, err_rc);
1056 cYAML_free_tree(err_rc);
1059 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1060 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1061 cYAML_print_tree2file(stderr, err_rc);
1062 cYAML_free_tree(err_rc);
1065 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1066 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1067 cYAML_print_tree2file(stderr, err_rc);
1068 cYAML_free_tree(err_rc);
1071 if (show_rc != NULL) {
1072 cYAML_print_tree2file(f, show_rc);
1073 cYAML_free_tree(show_rc);
1082 static int jt_add_peer_nid(int argc, char **argv)
1084 char *prim_nid = NULL;
1085 char **nids = NULL, **nids2 = NULL;
1087 struct cYAML *err_rc = NULL;
1088 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1089 bool non_mr = false;
1091 const char *const short_options = "k:n:mh";
1092 const struct option long_options[] = {
1093 { "prim_nid", 1, NULL, 'k' },
1094 { "nid", 1, NULL, 'n' },
1095 { "non_mr", 0, NULL, 'm'},
1096 { "help", 0, NULL, 'h' },
1097 { NULL, 0, NULL, 0 },
1100 while ((opt = getopt_long(argc, argv, short_options,
1101 long_options, NULL)) != -1) {
1107 size = lustre_lnet_parse_nids(optarg, nids, size,
1112 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1118 print_help(peer_cmds, "peer", "add");
1125 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1126 !non_mr, -1, &err_rc);
1130 /* free the array of nids */
1131 for (i = 0; i < size; i++)
1136 if (rc != LUSTRE_CFG_RC_NO_ERR)
1137 cYAML_print_tree2file(stderr, err_rc);
1139 cYAML_free_tree(err_rc);
1144 static int jt_del_peer_nid(int argc, char **argv)
1146 char *prim_nid = NULL;
1147 char **nids = NULL, **nids2 = NULL;
1148 struct cYAML *err_rc = NULL;
1149 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1151 const char *const short_options = "k:n:h";
1152 const struct option long_options[] = {
1153 { "prim_nid", 1, NULL, 'k' },
1154 { "nid", 1, NULL, 'n' },
1155 { "help", 0, NULL, 'h' },
1156 { NULL, 0, NULL, 0 },
1159 while ((opt = getopt_long(argc, argv, short_options,
1160 long_options, NULL)) != -1) {
1166 size = lustre_lnet_parse_nids(optarg, nids, size,
1171 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1174 print_help(peer_cmds, "peer", "del");
1181 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1185 for (i = 0; i < size; i++)
1190 if (rc != LUSTRE_CFG_RC_NO_ERR)
1191 cYAML_print_tree2file(stderr, err_rc);
1193 cYAML_free_tree(err_rc);
1198 static int jt_show_peer(int argc, char **argv)
1202 struct cYAML *err_rc = NULL, *show_rc = NULL;
1205 const char *const short_options = "n:vh";
1206 const struct option long_options[] = {
1207 { "nid", 1, NULL, 'n' },
1208 { "verbose", 0, NULL, 'v' },
1209 { "help", 0, NULL, 'h' },
1210 { NULL, 0, NULL, 0 },
1213 while ((opt = getopt_long(argc, argv, short_options,
1214 long_options, NULL)) != -1) {
1223 print_help(peer_cmds, "peer", "show");
1230 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1232 if (rc != LUSTRE_CFG_RC_NO_ERR)
1233 cYAML_print_tree2file(stderr, err_rc);
1235 cYAML_print_tree(show_rc);
1237 cYAML_free_tree(err_rc);
1238 cYAML_free_tree(show_rc);
1243 command_t list[] = {
1244 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1245 {"route", jt_route, 0, "route {add | del | show | help}"},
1246 {"net", jt_net, 0, "net {add | del | show | help}"},
1247 {"routing", jt_routing, 0, "routing {show | help}"},
1248 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1250 {"import", jt_import, 0, "import {--add | --del | --show | "
1251 "--help} FILE.yaml"},
1252 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1253 {"stats", jt_stats, 0, "stats {show | help}"},
1254 {"numa", jt_numa, 0, "numa {show | help}"},
1255 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1256 {"help", Parser_help, 0, "help"},
1257 {"exit", Parser_quit, 0, "quit"},
1258 {"quit", Parser_quit, 0, "quit"},
1259 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
1263 static int lnetctl_list_commands(int argc, char **argv)
1265 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1267 Parser_list_commands(list, buffer, sizeof(buffer), NULL, 0, 4);
1272 int main(int argc, char **argv)
1275 struct cYAML *err_rc = NULL;
1277 rc = lustre_lnet_config_lib_init();
1279 cYAML_build_error(-1, -1, "lnetctl", "startup",
1280 "cannot register LNet device", &err_rc);
1281 cYAML_print_tree2file(stderr, err_rc);
1285 Parser_init("lnetctl > ", list);
1287 rc = Parser_execarg(argc - 1, &argv[1], list);