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>
35 #include "cyaml/cyaml.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);*/
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 numa_cmds[] = {
117 {"show", jt_show_numa, 0, "show NUMA range\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"},
136 command_t peer_cmds[] = {
137 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
138 "\t--key_nid: NID to identify peer. If not provided then the first\n"
139 "\t NID in the list becomes the key NID of a newly created\n"
141 "\t--nid: one or more peer NIDs\n"},
142 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
143 "\t--key_nid: NID to identify peer.\n"
144 "\t--nid: list of NIDs to remove. If none provided,\n"
145 "\t peer is deleted\n"},
146 {"show", jt_show_peer, 0, "show peer credits\n"
147 "\t--primary_nid: NID of peer to filter on.\n"},
151 static inline void print_help(const command_t cmds[], const char *cmd_type,
154 const command_t *cmd;
156 for (cmd = cmds; cmd->pc_name; cmd++) {
157 if (pc_name != NULL &&
158 strcmp(cmd->pc_name, pc_name) == 0) {
159 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
162 } else if (pc_name != NULL) {
165 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
169 static int parse_long(const char *number, long int *value)
173 *value = strtol(number, &end, 0);
174 if (end != NULL && *end != 0)
180 static int handle_help(const command_t *cmd_list, const char *cmd,
181 const char *sub_cmd, int argc, char **argv)
188 const char *const short_options = "h";
189 const struct option long_options[] = {
190 { "help", 0, NULL, 'h' },
191 { NULL, 0, NULL, 0 },
194 while ((opt = getopt_long(argc, argv, short_options,
195 long_options, NULL)) != -1) {
198 print_help(cmd_list, cmd, sub_cmd);
212 static int jt_set_numa(int argc, char **argv)
216 struct cYAML *err_rc = NULL;
218 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
221 rc = parse_long(argv[1], &value);
223 cYAML_build_error(-1, -1, "parser", "set",
224 "cannot parse numa_range value", &err_rc);
225 cYAML_print_tree2file(stderr, err_rc);
226 cYAML_free_tree(err_rc);
230 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
231 if (rc != LUSTRE_CFG_RC_NO_ERR)
232 cYAML_print_tree2file(stderr, err_rc);
234 cYAML_free_tree(err_rc);
239 static int jt_set_tiny(int argc, char **argv)
243 struct cYAML *err_rc = NULL;
245 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
248 rc = parse_long(argv[1], &value);
250 cYAML_build_error(-1, -1, "parser", "set",
251 "cannot parse tiny_buffers value", &err_rc);
252 cYAML_print_tree2file(stderr, err_rc);
253 cYAML_free_tree(err_rc);
257 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
258 if (rc != LUSTRE_CFG_RC_NO_ERR)
259 cYAML_print_tree2file(stderr, err_rc);
261 cYAML_free_tree(err_rc);
266 static int jt_set_small(int argc, char **argv)
270 struct cYAML *err_rc = NULL;
272 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
275 rc = parse_long(argv[1], &value);
277 cYAML_build_error(-1, -1, "parser", "set",
278 "cannot parse small_buffers value", &err_rc);
279 cYAML_print_tree2file(stderr, err_rc);
280 cYAML_free_tree(err_rc);
284 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
285 if (rc != LUSTRE_CFG_RC_NO_ERR)
286 cYAML_print_tree2file(stderr, err_rc);
288 cYAML_free_tree(err_rc);
293 static int jt_set_large(int argc, char **argv)
297 struct cYAML *err_rc = NULL;
299 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
302 rc = parse_long(argv[1], &value);
304 cYAML_build_error(-1, -1, "parser", "set",
305 "cannot parse large_buffers value", &err_rc);
306 cYAML_print_tree2file(stderr, err_rc);
307 cYAML_free_tree(err_rc);
311 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
312 if (rc != LUSTRE_CFG_RC_NO_ERR)
313 cYAML_print_tree2file(stderr, err_rc);
315 cYAML_free_tree(err_rc);
320 static int jt_set_routing(int argc, char **argv)
323 struct cYAML *err_rc = NULL;
326 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
329 rc = parse_long(argv[1], &value);
330 if (rc != 0 || (value != 0 && value != 1)) {
331 cYAML_build_error(-1, -1, "parser", "set",
332 "cannot parse routing value.\n"
333 "must be 0 for disable or 1 for enable",
335 cYAML_print_tree2file(stderr, err_rc);
336 cYAML_free_tree(err_rc);
340 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
342 if (rc != LUSTRE_CFG_RC_NO_ERR)
343 cYAML_print_tree2file(stderr, err_rc);
345 cYAML_free_tree(err_rc);
350 static int jt_config_lnet(int argc, char **argv)
352 struct cYAML *err_rc = NULL;
353 bool load_mod_params = false;
356 const char *const short_options = "ah";
357 const struct option long_options[] = {
358 { "all", 0, NULL, 'a' },
359 { "help", 0, NULL, 'h' },
360 { NULL, 0, NULL, 0 },
363 while ((opt = getopt_long(argc, argv, short_options,
364 long_options, NULL)) != -1) {
367 load_mod_params = true;
370 print_help(lnet_cmds, "lnet", "configure");
377 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
380 if (rc != LUSTRE_CFG_RC_NO_ERR)
381 cYAML_print_tree2file(stderr, err_rc);
383 cYAML_free_tree(err_rc);
388 static int jt_unconfig_lnet(int argc, char **argv)
390 struct cYAML *err_rc = NULL;
393 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
396 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
398 if (rc != LUSTRE_CFG_RC_NO_ERR)
399 cYAML_print_tree2file(stderr, err_rc);
401 cYAML_free_tree(err_rc);
405 static int jt_add_route(int argc, char **argv)
407 char *network = NULL, *gateway = NULL;
408 long int hop = -1, prio = -1;
409 struct cYAML *err_rc = NULL;
412 const char *const short_options = "n:g:c:p:h";
413 const struct option long_options[] = {
414 { "net", 1, NULL, 'n' },
415 { "gateway", 1, NULL, 'g' },
416 { "hop-count", 1, NULL, 'c' },
417 { "priority", 1, NULL, 'p' },
418 { "help", 0, NULL, 'h' },
419 { NULL, 0, NULL, 0 },
422 while ((opt = getopt_long(argc, argv, short_options,
423 long_options, NULL)) != -1) {
432 rc = parse_long(optarg, &hop);
440 rc = parse_long(optarg, &prio);
448 print_help(route_cmds, "route", "add");
455 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
457 if (rc != LUSTRE_CFG_RC_NO_ERR)
458 cYAML_print_tree2file(stderr, err_rc);
460 cYAML_free_tree(err_rc);
465 static int jt_add_ni(int argc, char **argv)
468 long int pto = -1, pc = -1, pbc = -1, cre = -1;
469 struct cYAML *err_rc = NULL;
470 int rc, opt, num_global_cpts = 0;
471 struct lnet_dlc_network_descr nw_descr;
472 struct cfs_expr_list *global_cpts = NULL;
473 struct lnet_ioctl_config_lnd_tunables tunables;
476 memset(&tunables, 0, sizeof(tunables));
477 lustre_lnet_init_nw_descr(&nw_descr);
479 const char *const short_options = "n:i:p:t:c:b:r:s:h";
480 const struct option long_options[] = {
481 { "net", 1, NULL, 'n' },
482 { "if", 1, NULL, 'i' },
483 { "ip2net", 1, NULL, 'p' },
484 { "peer-timeout", 1, NULL, 't' },
485 { "peer-credits", 1, NULL, 'c' },
486 { "peer-buffer-credits", 1, NULL, 'b' },
487 { "credits", 1, NULL, 'r' },
488 { "cpt", 1, NULL, 's' },
489 { "help", 0, NULL, 'h' },
490 { NULL, 0, NULL, 0 },
493 while ((opt = getopt_long(argc, argv, short_options,
494 long_options, NULL)) != -1) {
497 nw_descr.nw_id = libcfs_str2net(optarg);
500 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
502 cYAML_build_error(-1, -1, "ni", "add",
503 "bad interface list",
512 rc = parse_long(optarg, &pto);
520 rc = parse_long(optarg, &pc);
528 rc = parse_long(optarg, &pbc);
536 rc = parse_long(optarg, &cre);
545 cfs_expr_list_parse(optarg,
547 0, UINT_MAX, &global_cpts);
550 print_help(net_cmds, "net", "add");
557 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
558 tunables.lt_cmn.lct_peer_timeout = pto;
559 tunables.lt_cmn.lct_peer_tx_credits = pc;
560 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
561 tunables.lt_cmn.lct_max_tx_credits = cre;
565 rc = lustre_lnet_config_ni(&nw_descr,
566 (num_global_cpts > 0) ? global_cpts: NULL,
567 ip2net, (found) ? &tunables : NULL,
570 if (global_cpts != NULL)
571 cfs_expr_list_free(global_cpts);
574 if (rc != LUSTRE_CFG_RC_NO_ERR)
575 cYAML_print_tree2file(stderr, err_rc);
577 cYAML_free_tree(err_rc);
582 static int jt_del_route(int argc, char **argv)
584 char *network = NULL, *gateway = NULL;
585 struct cYAML *err_rc = NULL;
588 const char *const short_options = "n:g:h";
589 const struct option long_options[] = {
590 { "net", 1, NULL, 'n' },
591 { "gateway", 1, NULL, 'g' },
592 { "help", 0, NULL, 'h' },
593 { NULL, 0, NULL, 0 },
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 const struct option long_options[] = {
633 { "net", 1, NULL, 'n' },
634 { "if", 1, NULL, 'i' },
635 { "help", 0, NULL, 'h' },
636 { NULL, 0, NULL, 0 },
639 while ((opt = getopt_long(argc, argv, short_options,
640 long_options, NULL)) != -1) {
643 nw_descr.nw_id = libcfs_str2net(optarg);
646 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
648 cYAML_build_error(-1, -1, "ni", "add",
649 "bad interface list",
655 print_help(net_cmds, "net", "del");
662 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
665 if (rc != LUSTRE_CFG_RC_NO_ERR)
666 cYAML_print_tree2file(stderr, err_rc);
668 cYAML_free_tree(err_rc);
673 static int jt_show_route(int argc, char **argv)
675 char *network = NULL, *gateway = NULL;
676 long int hop = -1, prio = -1;
677 int detail = 0, rc, opt;
678 struct cYAML *err_rc = NULL, *show_rc = NULL;
680 const char *const short_options = "n:g:h:p:vh";
681 const struct option long_options[] = {
682 { "net", 1, NULL, 'n' },
683 { "gateway", 1, NULL, 'g' },
684 { "hop-count", 1, NULL, 'c' },
685 { "priority", 1, NULL, 'p' },
686 { "verbose", 0, NULL, 'v' },
687 { "help", 0, NULL, 'h' },
688 { NULL, 0, NULL, 0 },
691 while ((opt = getopt_long(argc, argv, short_options,
692 long_options, NULL)) != -1) {
701 rc = parse_long(optarg, &hop);
709 rc = parse_long(optarg, &prio);
720 print_help(route_cmds, "route", "show");
727 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
730 if (rc != LUSTRE_CFG_RC_NO_ERR)
731 cYAML_print_tree2file(stderr, err_rc);
733 cYAML_print_tree(show_rc);
735 cYAML_free_tree(err_rc);
736 cYAML_free_tree(show_rc);
741 static int jt_show_net(int argc, char **argv)
743 char *network = NULL;
744 int detail = 0, rc, opt;
745 struct cYAML *err_rc = NULL, *show_rc = NULL;
747 const char *const short_options = "n:vh";
748 const struct option long_options[] = {
749 { "net", 1, NULL, 'n' },
750 { "verbose", 0, NULL, 'v' },
751 { "help", 0, NULL, 'h' },
752 { NULL, 0, NULL, 0 },
755 while ((opt = getopt_long(argc, argv, short_options,
756 long_options, NULL)) != -1) {
765 print_help(net_cmds, "net", "show");
772 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
774 if (rc != LUSTRE_CFG_RC_NO_ERR)
775 cYAML_print_tree2file(stderr, err_rc);
777 cYAML_print_tree(show_rc);
779 cYAML_free_tree(err_rc);
780 cYAML_free_tree(show_rc);
785 static int jt_show_routing(int argc, char **argv)
787 struct cYAML *err_rc = NULL, *show_rc = NULL;
790 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
793 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
795 if (rc != LUSTRE_CFG_RC_NO_ERR)
796 cYAML_print_tree2file(stderr, err_rc);
798 cYAML_print_tree(show_rc);
800 cYAML_free_tree(err_rc);
801 cYAML_free_tree(show_rc);
806 static int jt_show_stats(int argc, char **argv)
809 struct cYAML *show_rc = NULL, *err_rc = NULL;
811 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
814 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
816 if (rc != LUSTRE_CFG_RC_NO_ERR)
817 cYAML_print_tree2file(stderr, err_rc);
819 cYAML_print_tree(show_rc);
821 cYAML_free_tree(err_rc);
822 cYAML_free_tree(show_rc);
827 static int jt_show_numa(int argc, char **argv)
830 struct cYAML *show_rc = NULL, *err_rc = NULL;
832 if (handle_help(numa_cmds, "numa", "show", argc, argv) == 0)
835 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
837 if (rc != LUSTRE_CFG_RC_NO_ERR)
838 cYAML_print_tree2file(stderr, err_rc);
840 cYAML_print_tree(show_rc);
842 cYAML_free_tree(err_rc);
843 cYAML_free_tree(show_rc);
848 static inline int jt_lnet(int argc, char **argv)
854 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
857 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
860 static inline int jt_route(int argc, char **argv)
866 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
869 return Parser_execarg(argc - 1, &argv[1], route_cmds);
872 static inline int jt_net(int argc, char **argv)
878 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
881 return Parser_execarg(argc - 1, &argv[1], net_cmds);
884 static inline int jt_routing(int argc, char **argv)
890 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
893 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
896 static inline int jt_stats(int argc, char **argv)
902 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
905 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
908 static inline int jt_numa(int argc, char **argv)
914 handle_help(numa_cmds, "numa", NULL, argc, argv) == 0)
917 return Parser_execarg(argc - 1, &argv[1], numa_cmds);
920 static inline int jt_peers(int argc, char **argv)
926 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
929 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
932 static inline int jt_set(int argc, char **argv)
938 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
941 return Parser_execarg(argc - 1, &argv[1], set_cmds);
944 static int jt_import(int argc, char **argv)
947 struct cYAML *err_rc = NULL;
948 struct cYAML *show_rc = NULL;
949 int rc = 0, opt, opt_found = 0;
952 const char *const short_options = "adsh";
953 const struct option long_options[] = {
954 { "add", 0, NULL, 'a' },
955 { "del", 0, NULL, 'd' },
956 { "show", 0, NULL, 's' },
957 { "help", 0, NULL, 'h' },
958 { NULL, 0, NULL, 0 },
961 while ((opt = getopt_long(argc, argv, short_options,
962 long_options, NULL)) != -1) {
971 printf("import FILE\n"
972 "import < FILE : import a file\n"
973 "\t--add: add configuration\n"
974 "\t--del: delete configuration\n"
975 "\t--show: show configuration\n"
976 "\t--help: display this help\n"
977 "If no command option is given then --add"
978 " is assumed by default\n");
985 /* grab the file name if one exists */
986 if (opt_found && argc == 3)
988 else if (!opt_found && argc == 2)
993 rc = lustre_yaml_config(file, &err_rc);
996 rc = lustre_yaml_del(file, &err_rc);
999 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1000 cYAML_print_tree(show_rc);
1001 cYAML_free_tree(show_rc);
1005 if (rc != LUSTRE_CFG_RC_NO_ERR)
1006 cYAML_print_tree2file(stderr, err_rc);
1008 cYAML_free_tree(err_rc);
1013 static int jt_export(int argc, char **argv)
1015 struct cYAML *show_rc = NULL;
1016 struct cYAML *err_rc = NULL;
1020 const char *const short_options = "h";
1021 const struct option long_options[] = {
1022 { "help", 0, NULL, 'h' },
1023 { NULL, 0, NULL, 0 },
1026 while ((opt = getopt_long(argc, argv, short_options,
1027 long_options, NULL)) != -1) {
1030 printf("export FILE\n"
1031 "export > FILE : export configuration\n"
1032 "\t--help: display this help\n");
1040 f = fopen(argv[1], "w");
1046 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1047 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1048 cYAML_print_tree2file(stderr, err_rc);
1049 cYAML_free_tree(err_rc);
1052 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_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_routing(-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 if (show_rc != NULL) {
1066 cYAML_print_tree2file(f, show_rc);
1067 cYAML_free_tree(show_rc);
1076 static int jt_add_peer_nid(int argc, char **argv)
1078 char *key_nid = NULL;
1079 char *nid[LNET_MAX_INTERFACES] = {NULL};
1081 struct cYAML *err_rc = NULL;
1083 bool non_mr = false;
1085 const char *const short_options = "k:n:mh";
1086 const struct option long_options[] = {
1087 { "key_nid", 1, NULL, 'k' },
1088 { "nid", 1, NULL, 'n' },
1089 { "non_mr", 1, NULL, 'm'},
1090 { "help", 0, NULL, 'h' },
1091 { NULL, 0, NULL, 0 },
1094 while ((opt = getopt_long(argc, argv, short_options,
1095 long_options, NULL)) != -1) {
1101 if (idx >= LNET_MAX_INTERFACES) {
1102 cYAML_build_error(-1, -1, "peer_ni", "add",
1103 "too many interfaces",
1105 rc = LUSTRE_CFG_RC_BAD_PARAM;
1108 nid[idx] = calloc(strlen(optarg) + 1, 1);
1109 if (nid[idx] == NULL) {
1110 cYAML_build_error(-1, -1, "peer_ni", "add",
1113 rc = LUSTRE_CFG_RC_BAD_PARAM;
1116 strncpy(nid[idx], optarg, strlen(optarg));
1122 print_help(peer_cmds, "peer", "add");
1129 rc = lustre_lnet_config_peer_nid(key_nid, nid, !non_mr, -1, &err_rc);
1133 while (nid[idx] != NULL) {
1138 if (rc != LUSTRE_CFG_RC_NO_ERR)
1139 cYAML_print_tree2file(stderr, err_rc);
1141 cYAML_free_tree(err_rc);
1146 static int jt_del_peer_nid(int argc, char **argv)
1148 char *key_nid = NULL;
1149 char *nid[LNET_MAX_INTERFACES] = {NULL};
1151 struct cYAML *err_rc = NULL;
1154 const char *const short_options = "k:n:h";
1155 const struct option long_options[] = {
1156 { "key_nid", 1, NULL, 'k' },
1157 { "nid", 1, NULL, 'n' },
1158 { "help", 0, NULL, 'h' },
1159 { NULL, 0, NULL, 0 },
1162 while ((opt = getopt_long(argc, argv, short_options,
1163 long_options, NULL)) != -1) {
1169 if (idx >= LNET_MAX_INTERFACES) {
1170 cYAML_build_error(-1, -1, "peer_ni", "del",
1171 "too many interfaces",
1173 rc = LUSTRE_CFG_RC_BAD_PARAM;
1176 nid[idx] = calloc(strlen(optarg) + 1, 1);
1177 if (nid[idx] == NULL) {
1178 cYAML_build_error(-1, -1, "peer_ni", "del",
1181 rc = LUSTRE_CFG_RC_BAD_PARAM;
1184 strncpy(nid[idx], optarg, strlen(optarg));
1188 print_help(peer_cmds, "peer", "del");
1195 rc = lustre_lnet_del_peer_nid(key_nid, nid, -1, &err_rc);
1198 if (rc != LUSTRE_CFG_RC_NO_ERR)
1199 cYAML_print_tree2file(stderr, err_rc);
1201 cYAML_free_tree(err_rc);
1206 static int jt_show_peer(int argc, char **argv)
1208 char *key_nid = NULL;
1210 struct cYAML *err_rc = NULL, *show_rc = NULL;
1212 const char *const short_options = "k:vh";
1213 const struct option long_options[] = {
1214 { "key_nid", 1, NULL, 'k' },
1215 { "help", 0, NULL, 'h' },
1216 { NULL, 0, NULL, 0 },
1219 while ((opt = getopt_long(argc, argv, short_options,
1220 long_options, NULL)) != -1) {
1226 print_help(peer_cmds, "peer", "add");
1233 rc = lustre_lnet_show_peer(key_nid, -1, &show_rc, &err_rc);
1235 if (rc != LUSTRE_CFG_RC_NO_ERR)
1236 cYAML_print_tree2file(stderr, err_rc);
1238 cYAML_print_tree(show_rc);
1240 cYAML_free_tree(err_rc);
1241 cYAML_free_tree(show_rc);
1246 command_t list[] = {
1247 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1248 {"route", jt_route, 0, "route {add | del | show | help}"},
1249 {"net", jt_net, 0, "net {add | del | show | help}"},
1250 {"routing", jt_routing, 0, "routing {show | help}"},
1251 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1253 {"import", jt_import, 0, "import {--add | --del | --show | "
1254 "--help} FILE.yaml"},
1255 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1256 {"stats", jt_stats, 0, "stats {show | help}"},
1257 {"numa", jt_numa, 0, "numa {show | help}"},
1258 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1259 {"help", Parser_help, 0, "help"},
1260 {"exit", Parser_quit, 0, "quit"},
1261 {"quit", Parser_quit, 0, "quit"},
1265 int main(int argc, char **argv)
1268 struct cYAML *err_rc = NULL;
1270 rc = lustre_lnet_config_lib_init();
1272 cYAML_build_error(-1, -1, "lnetctl", "startup",
1273 "cannot register LNet device", &err_rc);
1274 cYAML_print_tree2file(stderr, err_rc);
1278 Parser_init("lnetctl > ", list);
1280 rc = Parser_execarg(argc - 1, &argv[1], list);