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 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
143 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
144 "\t--key_nid: NID to identify peer.\n"
145 "\t--nid: list of NIDs to remove. If none provided,\n"
146 "\t peer is deleted\n"},
147 {"show", jt_show_peer, 0, "show peer credits\n"
148 "\t--primary_nid: NID of peer to filter on.\n"},
152 static inline void print_help(const command_t cmds[], const char *cmd_type,
155 const command_t *cmd;
157 for (cmd = cmds; cmd->pc_name; cmd++) {
158 if (pc_name != NULL &&
159 strcmp(cmd->pc_name, pc_name) == 0) {
160 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
163 } else if (pc_name != NULL) {
166 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
170 static int parse_long(const char *number, long int *value)
174 *value = strtol(number, &end, 0);
175 if (end != NULL && *end != 0)
181 static int handle_help(const command_t *cmd_list, const char *cmd,
182 const char *sub_cmd, int argc, char **argv)
189 const char *const short_options = "h";
190 const struct option long_options[] = {
191 { "help", 0, NULL, 'h' },
192 { NULL, 0, NULL, 0 },
195 while ((opt = getopt_long(argc, argv, short_options,
196 long_options, NULL)) != -1) {
199 print_help(cmd_list, cmd, sub_cmd);
213 static int jt_set_numa(int argc, char **argv)
217 struct cYAML *err_rc = NULL;
219 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
222 rc = parse_long(argv[1], &value);
224 cYAML_build_error(-1, -1, "parser", "set",
225 "cannot parse numa_range value", &err_rc);
226 cYAML_print_tree2file(stderr, err_rc);
227 cYAML_free_tree(err_rc);
231 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
232 if (rc != LUSTRE_CFG_RC_NO_ERR)
233 cYAML_print_tree2file(stderr, err_rc);
235 cYAML_free_tree(err_rc);
240 static int jt_set_tiny(int argc, char **argv)
244 struct cYAML *err_rc = NULL;
246 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
249 rc = parse_long(argv[1], &value);
251 cYAML_build_error(-1, -1, "parser", "set",
252 "cannot parse tiny_buffers value", &err_rc);
253 cYAML_print_tree2file(stderr, err_rc);
254 cYAML_free_tree(err_rc);
258 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
259 if (rc != LUSTRE_CFG_RC_NO_ERR)
260 cYAML_print_tree2file(stderr, err_rc);
262 cYAML_free_tree(err_rc);
267 static int jt_set_small(int argc, char **argv)
271 struct cYAML *err_rc = NULL;
273 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
276 rc = parse_long(argv[1], &value);
278 cYAML_build_error(-1, -1, "parser", "set",
279 "cannot parse small_buffers value", &err_rc);
280 cYAML_print_tree2file(stderr, err_rc);
281 cYAML_free_tree(err_rc);
285 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
286 if (rc != LUSTRE_CFG_RC_NO_ERR)
287 cYAML_print_tree2file(stderr, err_rc);
289 cYAML_free_tree(err_rc);
294 static int jt_set_large(int argc, char **argv)
298 struct cYAML *err_rc = NULL;
300 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
303 rc = parse_long(argv[1], &value);
305 cYAML_build_error(-1, -1, "parser", "set",
306 "cannot parse large_buffers value", &err_rc);
307 cYAML_print_tree2file(stderr, err_rc);
308 cYAML_free_tree(err_rc);
312 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
313 if (rc != LUSTRE_CFG_RC_NO_ERR)
314 cYAML_print_tree2file(stderr, err_rc);
316 cYAML_free_tree(err_rc);
321 static int jt_set_routing(int argc, char **argv)
324 struct cYAML *err_rc = NULL;
327 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
330 rc = parse_long(argv[1], &value);
331 if (rc != 0 || (value != 0 && value != 1)) {
332 cYAML_build_error(-1, -1, "parser", "set",
333 "cannot parse routing value.\n"
334 "must be 0 for disable or 1 for enable",
336 cYAML_print_tree2file(stderr, err_rc);
337 cYAML_free_tree(err_rc);
341 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
343 if (rc != LUSTRE_CFG_RC_NO_ERR)
344 cYAML_print_tree2file(stderr, err_rc);
346 cYAML_free_tree(err_rc);
351 static int jt_config_lnet(int argc, char **argv)
353 struct cYAML *err_rc = NULL;
354 bool load_mod_params = false;
357 const char *const short_options = "ah";
358 const struct option long_options[] = {
359 { "all", 0, NULL, 'a' },
360 { "help", 0, NULL, 'h' },
361 { NULL, 0, NULL, 0 },
364 while ((opt = getopt_long(argc, argv, short_options,
365 long_options, NULL)) != -1) {
368 load_mod_params = true;
371 print_help(lnet_cmds, "lnet", "configure");
378 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
381 if (rc != LUSTRE_CFG_RC_NO_ERR)
382 cYAML_print_tree2file(stderr, err_rc);
384 cYAML_free_tree(err_rc);
389 static int jt_unconfig_lnet(int argc, char **argv)
391 struct cYAML *err_rc = NULL;
394 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
397 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
399 if (rc != LUSTRE_CFG_RC_NO_ERR)
400 cYAML_print_tree2file(stderr, err_rc);
402 cYAML_free_tree(err_rc);
406 static int jt_add_route(int argc, char **argv)
408 char *network = NULL, *gateway = NULL;
409 long int hop = -1, prio = -1;
410 struct cYAML *err_rc = NULL;
413 const char *const short_options = "n:g:c:p:h";
414 const struct option long_options[] = {
415 { "net", 1, NULL, 'n' },
416 { "gateway", 1, NULL, 'g' },
417 { "hop-count", 1, NULL, 'c' },
418 { "priority", 1, NULL, 'p' },
419 { "help", 0, NULL, 'h' },
420 { NULL, 0, NULL, 0 },
423 while ((opt = getopt_long(argc, argv, short_options,
424 long_options, NULL)) != -1) {
433 rc = parse_long(optarg, &hop);
441 rc = parse_long(optarg, &prio);
449 print_help(route_cmds, "route", "add");
456 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
458 if (rc != LUSTRE_CFG_RC_NO_ERR)
459 cYAML_print_tree2file(stderr, err_rc);
461 cYAML_free_tree(err_rc);
466 static int jt_add_ni(int argc, char **argv)
469 long int pto = -1, pc = -1, pbc = -1, cre = -1;
470 struct cYAML *err_rc = NULL;
471 int rc, opt, num_global_cpts = 0;
472 struct lnet_dlc_network_descr nw_descr;
473 struct cfs_expr_list *global_cpts = NULL;
474 struct lnet_ioctl_config_lnd_tunables tunables;
477 memset(&tunables, 0, sizeof(tunables));
478 lustre_lnet_init_nw_descr(&nw_descr);
480 const char *const short_options = "n:i:p:t:c:b:r:s:h";
481 const struct option long_options[] = {
482 { "net", 1, NULL, 'n' },
483 { "if", 1, NULL, 'i' },
484 { "ip2net", 1, NULL, 'p' },
485 { "peer-timeout", 1, NULL, 't' },
486 { "peer-credits", 1, NULL, 'c' },
487 { "peer-buffer-credits", 1, NULL, 'b' },
488 { "credits", 1, NULL, 'r' },
489 { "cpt", 1, NULL, 's' },
490 { "help", 0, NULL, 'h' },
491 { NULL, 0, NULL, 0 },
494 while ((opt = getopt_long(argc, argv, short_options,
495 long_options, NULL)) != -1) {
498 nw_descr.nw_id = libcfs_str2net(optarg);
501 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
503 cYAML_build_error(-1, -1, "ni", "add",
504 "bad interface list",
513 rc = parse_long(optarg, &pto);
521 rc = parse_long(optarg, &pc);
529 rc = parse_long(optarg, &pbc);
537 rc = parse_long(optarg, &cre);
546 cfs_expr_list_parse(optarg,
548 0, 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 (num_global_cpts > 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 const struct option long_options[] = {
591 { "net", 1, NULL, 'n' },
592 { "gateway", 1, NULL, 'g' },
593 { "help", 0, NULL, 'h' },
594 { NULL, 0, NULL, 0 },
597 while ((opt = getopt_long(argc, argv, short_options,
598 long_options, NULL)) != -1) {
607 print_help(route_cmds, "route", "del");
614 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
616 if (rc != LUSTRE_CFG_RC_NO_ERR)
617 cYAML_print_tree2file(stderr, err_rc);
619 cYAML_free_tree(err_rc);
624 static int jt_del_ni(int argc, char **argv)
626 struct cYAML *err_rc = NULL;
628 struct lnet_dlc_network_descr nw_descr;
630 lustre_lnet_init_nw_descr(&nw_descr);
632 const char *const short_options = "n:i:h";
633 const struct option long_options[] = {
634 { "net", 1, NULL, 'n' },
635 { "if", 1, NULL, 'i' },
636 { "help", 0, NULL, 'h' },
637 { NULL, 0, NULL, 0 },
640 while ((opt = getopt_long(argc, argv, short_options,
641 long_options, NULL)) != -1) {
644 nw_descr.nw_id = libcfs_str2net(optarg);
647 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
649 cYAML_build_error(-1, -1, "ni", "add",
650 "bad interface list",
656 print_help(net_cmds, "net", "del");
663 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
666 if (rc != LUSTRE_CFG_RC_NO_ERR)
667 cYAML_print_tree2file(stderr, err_rc);
669 cYAML_free_tree(err_rc);
674 static int jt_show_route(int argc, char **argv)
676 char *network = NULL, *gateway = NULL;
677 long int hop = -1, prio = -1;
678 int detail = 0, rc, opt;
679 struct cYAML *err_rc = NULL, *show_rc = NULL;
681 const char *const short_options = "n:g:h:p:vh";
682 const struct option long_options[] = {
683 { "net", 1, NULL, 'n' },
684 { "gateway", 1, NULL, 'g' },
685 { "hop-count", 1, NULL, 'c' },
686 { "priority", 1, NULL, 'p' },
687 { "verbose", 0, NULL, 'v' },
688 { "help", 0, NULL, 'h' },
689 { NULL, 0, NULL, 0 },
692 while ((opt = getopt_long(argc, argv, short_options,
693 long_options, NULL)) != -1) {
702 rc = parse_long(optarg, &hop);
710 rc = parse_long(optarg, &prio);
721 print_help(route_cmds, "route", "show");
728 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
731 if (rc != LUSTRE_CFG_RC_NO_ERR)
732 cYAML_print_tree2file(stderr, err_rc);
734 cYAML_print_tree(show_rc);
736 cYAML_free_tree(err_rc);
737 cYAML_free_tree(show_rc);
742 static int jt_show_net(int argc, char **argv)
744 char *network = NULL;
745 int detail = 0, rc, opt;
746 struct cYAML *err_rc = NULL, *show_rc = NULL;
748 const char *const short_options = "n:vh";
749 const struct option long_options[] = {
750 { "net", 1, NULL, 'n' },
751 { "verbose", 0, NULL, 'v' },
752 { "help", 0, NULL, 'h' },
753 { NULL, 0, NULL, 0 },
756 while ((opt = getopt_long(argc, argv, short_options,
757 long_options, NULL)) != -1) {
766 print_help(net_cmds, "net", "show");
773 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
775 if (rc != LUSTRE_CFG_RC_NO_ERR)
776 cYAML_print_tree2file(stderr, err_rc);
778 cYAML_print_tree(show_rc);
780 cYAML_free_tree(err_rc);
781 cYAML_free_tree(show_rc);
786 static int jt_show_routing(int argc, char **argv)
788 struct cYAML *err_rc = NULL, *show_rc = NULL;
791 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
794 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
796 if (rc != LUSTRE_CFG_RC_NO_ERR)
797 cYAML_print_tree2file(stderr, err_rc);
799 cYAML_print_tree(show_rc);
801 cYAML_free_tree(err_rc);
802 cYAML_free_tree(show_rc);
807 static int jt_show_stats(int argc, char **argv)
810 struct cYAML *show_rc = NULL, *err_rc = NULL;
812 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
815 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
817 if (rc != LUSTRE_CFG_RC_NO_ERR)
818 cYAML_print_tree2file(stderr, err_rc);
820 cYAML_print_tree(show_rc);
822 cYAML_free_tree(err_rc);
823 cYAML_free_tree(show_rc);
828 static int jt_show_numa(int argc, char **argv)
831 struct cYAML *show_rc = NULL, *err_rc = NULL;
833 if (handle_help(numa_cmds, "numa", "show", argc, argv) == 0)
836 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
838 if (rc != LUSTRE_CFG_RC_NO_ERR)
839 cYAML_print_tree2file(stderr, err_rc);
841 cYAML_print_tree(show_rc);
843 cYAML_free_tree(err_rc);
844 cYAML_free_tree(show_rc);
849 static inline int jt_lnet(int argc, char **argv)
855 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
858 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
861 static inline int jt_route(int argc, char **argv)
867 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
870 return Parser_execarg(argc - 1, &argv[1], route_cmds);
873 static inline int jt_net(int argc, char **argv)
879 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
882 return Parser_execarg(argc - 1, &argv[1], net_cmds);
885 static inline int jt_routing(int argc, char **argv)
891 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
894 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
897 static inline int jt_stats(int argc, char **argv)
903 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
906 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
909 static inline int jt_numa(int argc, char **argv)
915 handle_help(numa_cmds, "numa", NULL, argc, argv) == 0)
918 return Parser_execarg(argc - 1, &argv[1], numa_cmds);
921 static inline int jt_peers(int argc, char **argv)
927 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
930 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
933 static inline int jt_set(int argc, char **argv)
939 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
942 return Parser_execarg(argc - 1, &argv[1], set_cmds);
945 static int jt_import(int argc, char **argv)
948 struct cYAML *err_rc = NULL;
949 struct cYAML *show_rc = NULL;
950 int rc = 0, opt, opt_found = 0;
953 const char *const short_options = "adsh";
954 const struct option long_options[] = {
955 { "add", 0, NULL, 'a' },
956 { "del", 0, NULL, 'd' },
957 { "show", 0, NULL, 's' },
958 { "help", 0, NULL, 'h' },
959 { NULL, 0, NULL, 0 },
962 while ((opt = getopt_long(argc, argv, short_options,
963 long_options, NULL)) != -1) {
972 printf("import FILE\n"
973 "import < FILE : import a file\n"
974 "\t--add: add configuration\n"
975 "\t--del: delete configuration\n"
976 "\t--show: show configuration\n"
977 "\t--help: display this help\n"
978 "If no command option is given then --add"
979 " is assumed by default\n");
986 /* grab the file name if one exists */
987 if (opt_found && argc == 3)
989 else if (!opt_found && argc == 2)
994 rc = lustre_yaml_config(file, &err_rc);
997 rc = lustre_yaml_del(file, &err_rc);
1000 rc = lustre_yaml_show(file, &show_rc, &err_rc);
1001 cYAML_print_tree(show_rc);
1002 cYAML_free_tree(show_rc);
1006 if (rc != LUSTRE_CFG_RC_NO_ERR)
1007 cYAML_print_tree2file(stderr, err_rc);
1009 cYAML_free_tree(err_rc);
1014 static int jt_export(int argc, char **argv)
1016 struct cYAML *show_rc = NULL;
1017 struct cYAML *err_rc = NULL;
1021 const char *const short_options = "h";
1022 const struct option long_options[] = {
1023 { "help", 0, NULL, 'h' },
1024 { NULL, 0, NULL, 0 },
1027 while ((opt = getopt_long(argc, argv, short_options,
1028 long_options, NULL)) != -1) {
1031 printf("export FILE\n"
1032 "export > FILE : export configuration\n"
1033 "\t--help: display this help\n");
1041 f = fopen(argv[1], "w");
1047 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_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_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1055 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1056 cYAML_print_tree2file(stderr, err_rc);
1057 cYAML_free_tree(err_rc);
1060 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1061 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1062 cYAML_print_tree2file(stderr, err_rc);
1063 cYAML_free_tree(err_rc);
1066 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1067 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1068 cYAML_print_tree2file(stderr, err_rc);
1069 cYAML_free_tree(err_rc);
1072 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1073 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1074 cYAML_print_tree2file(stderr, err_rc);
1075 cYAML_free_tree(err_rc);
1078 if (show_rc != NULL) {
1079 cYAML_print_tree2file(f, show_rc);
1080 cYAML_free_tree(show_rc);
1089 static int jt_add_peer_nid(int argc, char **argv)
1091 char *key_nid = NULL;
1092 char **nids = NULL, **nids2 = NULL;
1094 struct cYAML *err_rc = NULL;
1095 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1096 bool non_mr = false;
1098 const char *const short_options = "k:n:mh";
1099 const struct option long_options[] = {
1100 { "key_nid", 1, NULL, 'k' },
1101 { "nid", 1, NULL, 'n' },
1102 { "non_mr", 0, NULL, 'm'},
1103 { "help", 0, NULL, 'h' },
1104 { NULL, 0, NULL, 0 },
1107 while ((opt = getopt_long(argc, argv, short_options,
1108 long_options, NULL)) != -1) {
1114 size = lustre_lnet_parse_nids(optarg, nids, size,
1119 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1125 print_help(peer_cmds, "peer", "add");
1132 rc = lustre_lnet_config_peer_nid(key_nid, nids, size,
1133 !non_mr, -1, &err_rc);
1136 for (i = 0; i < size; i++)
1140 if (rc != LUSTRE_CFG_RC_NO_ERR)
1141 cYAML_print_tree2file(stderr, err_rc);
1143 cYAML_free_tree(err_rc);
1148 static int jt_del_peer_nid(int argc, char **argv)
1150 char *key_nid = NULL;
1151 char **nids = NULL, **nids2 = NULL;
1152 struct cYAML *err_rc = NULL;
1153 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1155 const char *const short_options = "k:n:h";
1156 const struct option long_options[] = {
1157 { "key_nid", 1, NULL, 'k' },
1158 { "nid", 1, NULL, 'n' },
1159 { "help", 0, NULL, 'h' },
1160 { NULL, 0, NULL, 0 },
1163 while ((opt = getopt_long(argc, argv, short_options,
1164 long_options, NULL)) != -1) {
1170 size = lustre_lnet_parse_nids(optarg, nids, size,
1175 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1178 print_help(peer_cmds, "peer", "del");
1185 rc = lustre_lnet_del_peer_nid(key_nid, nids, size, -1, &err_rc);
1188 for (i = 0; i < size; i++)
1192 if (rc != LUSTRE_CFG_RC_NO_ERR)
1193 cYAML_print_tree2file(stderr, err_rc);
1195 cYAML_free_tree(err_rc);
1200 static int jt_show_peer(int argc, char **argv)
1202 char *key_nid = NULL;
1204 struct cYAML *err_rc = NULL, *show_rc = NULL;
1207 const char *const short_options = "k:vh";
1208 const struct option long_options[] = {
1209 { "key_nid", 1, NULL, 'k' },
1210 { "verbose", 0, NULL, 'v' },
1211 { "help", 0, NULL, 'h' },
1212 { NULL, 0, NULL, 0 },
1215 while ((opt = getopt_long(argc, argv, short_options,
1216 long_options, NULL)) != -1) {
1225 print_help(peer_cmds, "peer", "add");
1232 rc = lustre_lnet_show_peer(key_nid, detail, -1, &show_rc, &err_rc);
1234 if (rc != LUSTRE_CFG_RC_NO_ERR)
1235 cYAML_print_tree2file(stderr, err_rc);
1237 cYAML_print_tree(show_rc);
1239 cYAML_free_tree(err_rc);
1240 cYAML_free_tree(show_rc);
1245 command_t list[] = {
1246 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1247 {"route", jt_route, 0, "route {add | del | show | help}"},
1248 {"net", jt_net, 0, "net {add | del | show | help}"},
1249 {"routing", jt_routing, 0, "routing {show | help}"},
1250 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1252 {"import", jt_import, 0, "import {--add | --del | --show | "
1253 "--help} FILE.yaml"},
1254 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1255 {"stats", jt_stats, 0, "stats {show | help}"},
1256 {"numa", jt_numa, 0, "numa {show | help}"},
1257 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1258 {"help", Parser_help, 0, "help"},
1259 {"exit", Parser_quit, 0, "quit"},
1260 {"quit", Parser_quit, 0, "quit"},
1264 int main(int argc, char **argv)
1267 struct cYAML *err_rc = NULL;
1269 rc = lustre_lnet_config_lib_init();
1271 cYAML_build_error(-1, -1, "lnetctl", "startup",
1272 "cannot register LNet device", &err_rc);
1273 cYAML_print_tree2file(stderr, err_rc);
1277 Parser_init("lnetctl > ", list);
1279 rc = Parser_execarg(argc - 1, &argv[1], list);