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--prim_nid: Primary NID of the peer. If not provided then the first\n"
139 "\t NID in the list becomes the Primary 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--prim_nid: Primary NID of the 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 information\n"
148 "\t--nid: NID of peer to filter on.\n"
149 "\t--verbose: Include extended statistics\n"},
153 static inline void print_help(const command_t cmds[], const char *cmd_type,
156 const command_t *cmd;
158 for (cmd = cmds; cmd->pc_name; cmd++) {
159 if (pc_name != NULL &&
160 strcmp(cmd->pc_name, pc_name) == 0) {
161 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
164 } else if (pc_name != NULL) {
167 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
171 static int parse_long(const char *number, long int *value)
175 *value = strtol(number, &end, 0);
176 if (end != NULL && *end != 0)
182 static int handle_help(const command_t *cmd_list, const char *cmd,
183 const char *sub_cmd, int argc, char **argv)
190 const char *const short_options = "h";
191 const struct option long_options[] = {
192 { "help", 0, NULL, 'h' },
193 { NULL, 0, NULL, 0 },
196 while ((opt = getopt_long(argc, argv, short_options,
197 long_options, NULL)) != -1) {
200 print_help(cmd_list, cmd, sub_cmd);
214 static int jt_set_numa(int argc, char **argv)
218 struct cYAML *err_rc = NULL;
220 if (handle_help(set_cmds, "set", "numa_range", argc, argv) == 0)
223 rc = parse_long(argv[1], &value);
225 cYAML_build_error(-1, -1, "parser", "set",
226 "cannot parse numa_range value", &err_rc);
227 cYAML_print_tree2file(stderr, err_rc);
228 cYAML_free_tree(err_rc);
232 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
233 if (rc != LUSTRE_CFG_RC_NO_ERR)
234 cYAML_print_tree2file(stderr, err_rc);
236 cYAML_free_tree(err_rc);
241 static int jt_set_tiny(int argc, char **argv)
245 struct cYAML *err_rc = NULL;
247 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
250 rc = parse_long(argv[1], &value);
252 cYAML_build_error(-1, -1, "parser", "set",
253 "cannot parse tiny_buffers value", &err_rc);
254 cYAML_print_tree2file(stderr, err_rc);
255 cYAML_free_tree(err_rc);
259 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
260 if (rc != LUSTRE_CFG_RC_NO_ERR)
261 cYAML_print_tree2file(stderr, err_rc);
263 cYAML_free_tree(err_rc);
268 static int jt_set_small(int argc, char **argv)
272 struct cYAML *err_rc = NULL;
274 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
277 rc = parse_long(argv[1], &value);
279 cYAML_build_error(-1, -1, "parser", "set",
280 "cannot parse small_buffers value", &err_rc);
281 cYAML_print_tree2file(stderr, err_rc);
282 cYAML_free_tree(err_rc);
286 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
287 if (rc != LUSTRE_CFG_RC_NO_ERR)
288 cYAML_print_tree2file(stderr, err_rc);
290 cYAML_free_tree(err_rc);
295 static int jt_set_large(int argc, char **argv)
299 struct cYAML *err_rc = NULL;
301 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
304 rc = parse_long(argv[1], &value);
306 cYAML_build_error(-1, -1, "parser", "set",
307 "cannot parse large_buffers value", &err_rc);
308 cYAML_print_tree2file(stderr, err_rc);
309 cYAML_free_tree(err_rc);
313 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
314 if (rc != LUSTRE_CFG_RC_NO_ERR)
315 cYAML_print_tree2file(stderr, err_rc);
317 cYAML_free_tree(err_rc);
322 static int jt_set_routing(int argc, char **argv)
325 struct cYAML *err_rc = NULL;
328 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
331 rc = parse_long(argv[1], &value);
332 if (rc != 0 || (value != 0 && value != 1)) {
333 cYAML_build_error(-1, -1, "parser", "set",
334 "cannot parse routing value.\n"
335 "must be 0 for disable or 1 for enable",
337 cYAML_print_tree2file(stderr, err_rc);
338 cYAML_free_tree(err_rc);
342 rc = lustre_lnet_enable_routing(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_config_lnet(int argc, char **argv)
354 struct cYAML *err_rc = NULL;
355 bool load_mod_params = false;
358 const char *const short_options = "ah";
359 const struct option long_options[] = {
360 { "all", 0, NULL, 'a' },
361 { "help", 0, NULL, 'h' },
362 { NULL, 0, NULL, 0 },
365 while ((opt = getopt_long(argc, argv, short_options,
366 long_options, NULL)) != -1) {
369 load_mod_params = true;
372 print_help(lnet_cmds, "lnet", "configure");
379 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
382 if (rc != LUSTRE_CFG_RC_NO_ERR)
383 cYAML_print_tree2file(stderr, err_rc);
385 cYAML_free_tree(err_rc);
390 static int jt_unconfig_lnet(int argc, char **argv)
392 struct cYAML *err_rc = NULL;
395 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
398 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
400 if (rc != LUSTRE_CFG_RC_NO_ERR)
401 cYAML_print_tree2file(stderr, err_rc);
403 cYAML_free_tree(err_rc);
407 static int jt_add_route(int argc, char **argv)
409 char *network = NULL, *gateway = NULL;
410 long int hop = -1, prio = -1;
411 struct cYAML *err_rc = NULL;
414 const char *const short_options = "n:g:c:p:h";
415 const struct option long_options[] = {
416 { "net", 1, NULL, 'n' },
417 { "gateway", 1, NULL, 'g' },
418 { "hop-count", 1, NULL, 'c' },
419 { "priority", 1, NULL, 'p' },
420 { "help", 0, NULL, 'h' },
421 { NULL, 0, NULL, 0 },
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 const struct option long_options[] = {
483 { "net", 1, NULL, 'n' },
484 { "if", 1, NULL, 'i' },
485 { "ip2net", 1, NULL, 'p' },
486 { "peer-timeout", 1, NULL, 't' },
487 { "peer-credits", 1, NULL, 'c' },
488 { "peer-buffer-credits", 1, NULL, 'b' },
489 { "credits", 1, NULL, 'r' },
490 { "cpt", 1, NULL, 's' },
491 { "help", 0, NULL, 'h' },
492 { NULL, 0, NULL, 0 },
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 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 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 rc = lustre_lnet_show_peer(NULL, 1, -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 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1072 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1073 cYAML_print_tree2file(stderr, err_rc);
1074 cYAML_free_tree(err_rc);
1077 if (show_rc != NULL) {
1078 cYAML_print_tree2file(f, show_rc);
1079 cYAML_free_tree(show_rc);
1088 static int jt_add_peer_nid(int argc, char **argv)
1090 char *prim_nid = NULL;
1091 char **nids = NULL, **nids2 = NULL;
1093 struct cYAML *err_rc = NULL;
1094 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1095 bool non_mr = false;
1097 const char *const short_options = "k:n:mh";
1098 const struct option long_options[] = {
1099 { "prim_nid", 1, NULL, 'k' },
1100 { "nid", 1, NULL, 'n' },
1101 { "non_mr", 0, NULL, 'm'},
1102 { "help", 0, NULL, 'h' },
1103 { NULL, 0, NULL, 0 },
1106 while ((opt = getopt_long(argc, argv, short_options,
1107 long_options, NULL)) != -1) {
1113 size = lustre_lnet_parse_nids(optarg, nids, size,
1118 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1124 print_help(peer_cmds, "peer", "add");
1131 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1132 !non_mr, -1, &err_rc);
1135 for (i = 0; i < size; i++)
1139 if (rc != LUSTRE_CFG_RC_NO_ERR)
1140 cYAML_print_tree2file(stderr, err_rc);
1142 cYAML_free_tree(err_rc);
1147 static int jt_del_peer_nid(int argc, char **argv)
1149 char *prim_nid = NULL;
1150 char **nids = NULL, **nids2 = NULL;
1151 struct cYAML *err_rc = NULL;
1152 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1154 const char *const short_options = "k:n:h";
1155 const struct option long_options[] = {
1156 { "prim_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 size = lustre_lnet_parse_nids(optarg, nids, size,
1174 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1177 print_help(peer_cmds, "peer", "del");
1184 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1187 for (i = 0; i < size; i++)
1191 if (rc != LUSTRE_CFG_RC_NO_ERR)
1192 cYAML_print_tree2file(stderr, err_rc);
1194 cYAML_free_tree(err_rc);
1199 static int jt_show_peer(int argc, char **argv)
1203 struct cYAML *err_rc = NULL, *show_rc = NULL;
1206 const char *const short_options = "n:vh";
1207 const struct option long_options[] = {
1208 { "nid", 1, NULL, 'n' },
1209 { "verbose", 0, NULL, 'v' },
1210 { "help", 0, NULL, 'h' },
1211 { NULL, 0, NULL, 0 },
1214 while ((opt = getopt_long(argc, argv, short_options,
1215 long_options, NULL)) != -1) {
1224 print_help(peer_cmds, "peer", "show");
1231 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1233 if (rc != LUSTRE_CFG_RC_NO_ERR)
1234 cYAML_print_tree2file(stderr, err_rc);
1236 cYAML_print_tree(show_rc);
1238 cYAML_free_tree(err_rc);
1239 cYAML_free_tree(show_rc);
1244 command_t list[] = {
1245 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1246 {"route", jt_route, 0, "route {add | del | show | help}"},
1247 {"net", jt_net, 0, "net {add | del | show | help}"},
1248 {"routing", jt_routing, 0, "routing {show | help}"},
1249 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1251 {"import", jt_import, 0, "import {--add | --del | --show | "
1252 "--help} FILE.yaml"},
1253 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1254 {"stats", jt_stats, 0, "stats {show | help}"},
1255 {"numa", jt_numa, 0, "numa {show | help}"},
1256 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1257 {"help", Parser_help, 0, "help"},
1258 {"exit", Parser_quit, 0, "quit"},
1259 {"quit", Parser_quit, 0, "quit"},
1263 int main(int argc, char **argv)
1266 struct cYAML *err_rc = NULL;
1268 rc = lustre_lnet_config_lib_init();
1270 cYAML_build_error(-1, -1, "lnetctl", "startup",
1271 "cannot register LNet device", &err_rc);
1272 cYAML_print_tree2file(stderr, err_rc);
1276 Parser_init("lnetctl > ", list);
1278 rc = Parser_execarg(argc - 1, &argv[1], list);