4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2016, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/parser.h>
34 #include "lnetconfig/liblnetconfig.h"
36 #define LNET_CONFIGURE true
37 #define LNET_UNCONFIGURE false
39 static int jt_config_lnet(int argc, char **argv);
40 static int jt_unconfig_lnet(int argc, char **argv);
41 static int jt_add_route(int argc, char **argv);
42 static int jt_add_ni(int argc, char **argv);
43 static int jt_set_routing(int argc, char **argv);
44 static int jt_del_route(int argc, char **argv);
45 static int jt_del_ni(int argc, char **argv);
46 static int jt_show_route(int argc, char **argv);
47 static int jt_show_net(int argc, char **argv);
48 static int jt_show_routing(int argc, char **argv);
49 static int jt_show_stats(int argc, char **argv);
50 static int jt_show_peer(int argc, char **argv);
51 static int jt_show_numa(int argc, char **argv);
52 static int jt_set_tiny(int argc, char **argv);
53 static int jt_set_small(int argc, char **argv);
54 static int jt_set_large(int argc, char **argv);
55 static int jt_set_numa(int argc, char **argv);
56 static int jt_add_peer_nid(int argc, char **argv);
57 static int jt_del_peer_nid(int argc, char **argv);
58 /*static int jt_show_peer(int argc, char **argv);*/
59 static int lnetctl_list_commands(int argc, char **argv);
61 command_t lnet_cmds[] = {
62 {"configure", jt_config_lnet, 0, "configure lnet\n"
63 "\t--all: load NI configuration from module parameters\n"},
64 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
68 command_t route_cmds[] = {
69 {"add", jt_add_route, 0, "add a route\n"
70 "\t--net: net name (e.g. tcp0)\n"
71 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
72 "\t--hop: number to final destination (1 < hops < 255)\n"
73 "\t--priority: priority of route (0 - highest prio\n"},
74 {"del", jt_del_route, 0, "delete a route\n"
75 "\t--net: net name (e.g. tcp0)\n"
76 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
77 {"show", jt_show_route, 0, "show routes\n"
78 "\t--net: net name (e.g. tcp0) to filter on\n"
79 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
80 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
81 "\t--priority: priority of route (0 - highest prio to filter on\n"
82 "\t--verbose: display detailed output per route\n"},
86 command_t net_cmds[] = {
87 {"add", jt_add_ni, 0, "add a network\n"
88 "\t--net: net name (e.g. tcp0)\n"
89 "\t--if: physical interface (e.g. eth0)\n"
90 "\t--ip2net: specify networks based on IP address patterns\n"
91 "\t--peer-timeout: time to wait before declaring a peer dead\n"
92 "\t--peer-credits: define the max number of inflight messages\n"
93 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
94 "\t--credits: Network Interface credits\n"
95 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
96 {"del", jt_del_ni, 0, "delete a network\n"
97 "\t--net: net name (e.g. tcp0)\n"
98 "\t--if: physical interface (e.g. eth0)\n"},
99 {"show", jt_show_net, 0, "show networks\n"
100 "\t--net: net name (e.g. tcp0) to filter on\n"
101 "\t--verbose: display detailed output per network\n"},
105 command_t routing_cmds[] = {
106 {"show", jt_show_routing, 0, "show routing information\n"},
110 command_t stats_cmds[] = {
111 {"show", jt_show_stats, 0, "show LNET statistics\n"},
115 command_t numa_cmds[] = {
116 {"show", jt_show_numa, 0, "show NUMA range\n"},
120 command_t set_cmds[] = {
121 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
122 "\tVALUE must be greater than 0\n"},
123 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
124 "\tVALUE must be greater than 0\n"},
125 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
126 "\tVALUE must be greater than 0\n"},
127 {"routing", jt_set_routing, 0, "enable/disable routing\n"
128 "\t0 - disable routing\n"
129 "\t1 - enable routing\n"},
130 {"numa_range", jt_set_numa, 0, "set NUMA range for NI selection\n"
131 "\tVALUE must be at least 0\n"},
135 command_t peer_cmds[] = {
136 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
137 "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
138 "\t NID in the list becomes the Primary NID of a newly created\n"
140 "\t--nid: one or more peer NIDs\n"
141 "\t--non_mr: create this peer as not Multi-Rail capable\n"},
142 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
143 "\t--prim_nid: Primary NID of the 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 information\n"
147 "\t--nid: NID of peer to filter on.\n"
148 "\t--verbose: Include extended statistics\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 static const struct option long_options[] = {
191 { .name = "help", .has_arg = no_argument, .val = 'h' },
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_numa_range(value, -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 static const struct option long_options[] = {
359 { .name = "all", .has_arg = no_argument, .val = 'a' },
360 { .name = "help", .has_arg = no_argument, .val = 'h' },
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 static const struct option long_options[] = {
415 { .name = "net", .has_arg = required_argument, .val = 'n' },
416 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
417 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
418 { .name = "priority", .has_arg = required_argument, .val = 'p' },
419 { .name = "help", .has_arg = no_argument, .val = 'h' },
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, cpt_rc = -1;
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 static const struct option long_options[] = {
481 { .name = "net", .has_arg = required_argument, .val = 'n' },
482 { .name = "if", .has_arg = required_argument, .val = 'i' },
483 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
484 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
485 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
486 { .name = "peer-buffer-credits",
487 .has_arg = required_argument, .val = 'b' },
488 { .name = "credits", .has_arg = required_argument, .val = 'r' },
489 { .name = "cpt", .has_arg = required_argument, .val = 's' },
490 { .name = "help", .has_arg = no_argument, .val = 'h' },
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);
544 cpt_rc = cfs_expr_list_parse(optarg,
546 UINT_MAX, &global_cpts);
549 print_help(net_cmds, "net", "add");
556 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
557 tunables.lt_cmn.lct_peer_timeout = pto;
558 tunables.lt_cmn.lct_peer_tx_credits = pc;
559 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
560 tunables.lt_cmn.lct_max_tx_credits = cre;
564 rc = lustre_lnet_config_ni(&nw_descr,
565 (cpt_rc == 0) ? global_cpts: NULL,
566 ip2net, (found) ? &tunables : NULL,
569 if (global_cpts != NULL)
570 cfs_expr_list_free(global_cpts);
573 if (rc != LUSTRE_CFG_RC_NO_ERR)
574 cYAML_print_tree2file(stderr, err_rc);
576 cYAML_free_tree(err_rc);
581 static int jt_del_route(int argc, char **argv)
583 char *network = NULL, *gateway = NULL;
584 struct cYAML *err_rc = NULL;
587 const char *const short_options = "n:g:h";
588 static const struct option long_options[] = {
589 { .name = "net", .has_arg = required_argument, .val = 'n' },
590 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
591 { .name = "help", .has_arg = no_argument, .val = 'h' },
594 while ((opt = getopt_long(argc, argv, short_options,
595 long_options, NULL)) != -1) {
604 print_help(route_cmds, "route", "del");
611 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
613 if (rc != LUSTRE_CFG_RC_NO_ERR)
614 cYAML_print_tree2file(stderr, err_rc);
616 cYAML_free_tree(err_rc);
621 static int jt_del_ni(int argc, char **argv)
623 struct cYAML *err_rc = NULL;
625 struct lnet_dlc_network_descr nw_descr;
627 lustre_lnet_init_nw_descr(&nw_descr);
629 const char *const short_options = "n:i:h";
630 static const struct option long_options[] = {
631 { .name = "net", .has_arg = required_argument, .val = 'n' },
632 { .name = "if", .has_arg = required_argument, .val = 'i' },
633 { .name = "help", .has_arg = no_argument, .val = 'h' },
636 while ((opt = getopt_long(argc, argv, short_options,
637 long_options, NULL)) != -1) {
640 nw_descr.nw_id = libcfs_str2net(optarg);
643 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
645 cYAML_build_error(-1, -1, "ni", "add",
646 "bad interface list",
652 print_help(net_cmds, "net", "del");
659 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
662 if (rc != LUSTRE_CFG_RC_NO_ERR)
663 cYAML_print_tree2file(stderr, err_rc);
665 cYAML_free_tree(err_rc);
670 static int jt_show_route(int argc, char **argv)
672 char *network = NULL, *gateway = NULL;
673 long int hop = -1, prio = -1;
674 int detail = 0, rc, opt;
675 struct cYAML *err_rc = NULL, *show_rc = NULL;
677 const char *const short_options = "n:g:h:p:vh";
678 static const struct option long_options[] = {
679 { .name = "net", .has_arg = required_argument, .val = 'n' },
680 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
681 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
682 { .name = "priority", .has_arg = required_argument, .val = 'p' },
683 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
684 { .name = "help", .has_arg = no_argument, .val = 'h' },
687 while ((opt = getopt_long(argc, argv, short_options,
688 long_options, NULL)) != -1) {
697 rc = parse_long(optarg, &hop);
705 rc = parse_long(optarg, &prio);
716 print_help(route_cmds, "route", "show");
723 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
726 if (rc != LUSTRE_CFG_RC_NO_ERR)
727 cYAML_print_tree2file(stderr, err_rc);
729 cYAML_print_tree(show_rc);
731 cYAML_free_tree(err_rc);
732 cYAML_free_tree(show_rc);
737 static int jt_show_net(int argc, char **argv)
739 char *network = NULL;
740 int detail = 0, rc, opt;
741 struct cYAML *err_rc = NULL, *show_rc = NULL;
743 const char *const short_options = "n:vh";
744 static const struct option long_options[] = {
745 { .name = "net", .has_arg = required_argument, .val = 'n' },
746 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
747 { .name = "help", .has_arg = no_argument, .val = 'h' },
750 while ((opt = getopt_long(argc, argv, short_options,
751 long_options, NULL)) != -1) {
760 print_help(net_cmds, "net", "show");
767 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
769 if (rc != LUSTRE_CFG_RC_NO_ERR)
770 cYAML_print_tree2file(stderr, err_rc);
772 cYAML_print_tree(show_rc);
774 cYAML_free_tree(err_rc);
775 cYAML_free_tree(show_rc);
780 static int jt_show_routing(int argc, char **argv)
782 struct cYAML *err_rc = NULL, *show_rc = NULL;
785 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
788 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
790 if (rc != LUSTRE_CFG_RC_NO_ERR)
791 cYAML_print_tree2file(stderr, err_rc);
793 cYAML_print_tree(show_rc);
795 cYAML_free_tree(err_rc);
796 cYAML_free_tree(show_rc);
801 static int jt_show_stats(int argc, char **argv)
804 struct cYAML *show_rc = NULL, *err_rc = NULL;
806 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
809 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
811 if (rc != LUSTRE_CFG_RC_NO_ERR)
812 cYAML_print_tree2file(stderr, err_rc);
814 cYAML_print_tree(show_rc);
816 cYAML_free_tree(err_rc);
817 cYAML_free_tree(show_rc);
822 static int jt_show_numa(int argc, char **argv)
825 struct cYAML *show_rc = NULL, *err_rc = NULL;
827 if (handle_help(numa_cmds, "numa", "show", argc, argv) == 0)
830 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
832 if (rc != LUSTRE_CFG_RC_NO_ERR)
833 cYAML_print_tree2file(stderr, err_rc);
835 cYAML_print_tree(show_rc);
837 cYAML_free_tree(err_rc);
838 cYAML_free_tree(show_rc);
843 static inline int jt_lnet(int argc, char **argv)
849 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
852 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
855 static inline int jt_route(int argc, char **argv)
861 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
864 return Parser_execarg(argc - 1, &argv[1], route_cmds);
867 static inline int jt_net(int argc, char **argv)
873 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
876 return Parser_execarg(argc - 1, &argv[1], net_cmds);
879 static inline int jt_routing(int argc, char **argv)
885 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
888 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
891 static inline int jt_stats(int argc, char **argv)
897 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
900 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
903 static inline int jt_numa(int argc, char **argv)
909 handle_help(numa_cmds, "numa", NULL, argc, argv) == 0)
912 return Parser_execarg(argc - 1, &argv[1], numa_cmds);
915 static inline int jt_peers(int argc, char **argv)
921 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
924 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
927 static inline int jt_set(int argc, char **argv)
933 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
936 return Parser_execarg(argc - 1, &argv[1], set_cmds);
939 static int jt_import(int argc, char **argv)
942 struct cYAML *err_rc = NULL;
943 struct cYAML *show_rc = NULL;
944 int rc = 0, opt, opt_found = 0;
947 const char *const short_options = "adsh";
948 static const struct option long_options[] = {
949 { .name = "add", .has_arg = no_argument, .val = 'a' },
950 { .name = "del", .has_arg = no_argument, .val = 'd' },
951 { .name = "show", .has_arg = no_argument, .val = 's' },
952 { .name = "help", .has_arg = no_argument, .val = 'h' },
955 while ((opt = getopt_long(argc, argv, short_options,
956 long_options, NULL)) != -1) {
965 printf("import FILE\n"
966 "import < FILE : import a file\n"
967 "\t--add: add configuration\n"
968 "\t--del: delete configuration\n"
969 "\t--show: show configuration\n"
970 "\t--help: display this help\n"
971 "If no command option is given then --add"
972 " is assumed by default\n");
979 /* grab the file name if one exists */
980 if (opt_found && argc == 3)
982 else if (!opt_found && argc == 2)
987 rc = lustre_yaml_config(file, &err_rc);
990 rc = lustre_yaml_del(file, &err_rc);
993 rc = lustre_yaml_show(file, &show_rc, &err_rc);
994 cYAML_print_tree(show_rc);
995 cYAML_free_tree(show_rc);
999 cYAML_print_tree2file(stderr, err_rc);
1001 cYAML_free_tree(err_rc);
1006 static int jt_export(int argc, char **argv)
1008 struct cYAML *show_rc = NULL;
1009 struct cYAML *err_rc = NULL;
1013 const char *const short_options = "h";
1014 static const struct option long_options[] = {
1015 { .name = "help", .has_arg = no_argument, .val = 'h' },
1018 while ((opt = getopt_long(argc, argv, short_options,
1019 long_options, NULL)) != -1) {
1022 printf("export FILE\n"
1023 "export > FILE : export configuration\n"
1024 "\t--help: display this help\n");
1032 f = fopen(argv[1], "w");
1038 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1039 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1040 cYAML_print_tree2file(stderr, err_rc);
1041 cYAML_free_tree(err_rc);
1044 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
1046 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1047 cYAML_print_tree2file(stderr, err_rc);
1048 cYAML_free_tree(err_rc);
1051 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
1052 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1053 cYAML_print_tree2file(stderr, err_rc);
1054 cYAML_free_tree(err_rc);
1057 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1058 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1059 cYAML_print_tree2file(stderr, err_rc);
1060 cYAML_free_tree(err_rc);
1063 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1064 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1065 cYAML_print_tree2file(stderr, err_rc);
1066 cYAML_free_tree(err_rc);
1069 if (show_rc != NULL) {
1070 cYAML_print_tree2file(f, show_rc);
1071 cYAML_free_tree(show_rc);
1080 static int jt_add_peer_nid(int argc, char **argv)
1082 char *prim_nid = NULL;
1083 char **nids = NULL, **nids2 = NULL;
1085 struct cYAML *err_rc = NULL;
1086 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1087 bool non_mr = false;
1089 const char *const short_options = "k:n:mh";
1090 const struct option long_options[] = {
1091 { "prim_nid", 1, NULL, 'k' },
1092 { "nid", 1, NULL, 'n' },
1093 { "non_mr", 0, NULL, 'm'},
1094 { "help", 0, NULL, 'h' },
1095 { NULL, 0, NULL, 0 },
1098 while ((opt = getopt_long(argc, argv, short_options,
1099 long_options, NULL)) != -1) {
1105 size = lustre_lnet_parse_nids(optarg, nids, size,
1110 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1116 print_help(peer_cmds, "peer", "add");
1123 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1124 !non_mr, -1, &err_rc);
1128 /* free the array of nids */
1129 for (i = 0; i < size; i++)
1134 if (rc != LUSTRE_CFG_RC_NO_ERR)
1135 cYAML_print_tree2file(stderr, err_rc);
1137 cYAML_free_tree(err_rc);
1142 static int jt_del_peer_nid(int argc, char **argv)
1144 char *prim_nid = NULL;
1145 char **nids = NULL, **nids2 = NULL;
1146 struct cYAML *err_rc = NULL;
1147 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1149 const char *const short_options = "k:n:h";
1150 const struct option long_options[] = {
1151 { "prim_nid", 1, NULL, 'k' },
1152 { "nid", 1, NULL, 'n' },
1153 { "help", 0, NULL, 'h' },
1154 { NULL, 0, NULL, 0 },
1157 while ((opt = getopt_long(argc, argv, short_options,
1158 long_options, NULL)) != -1) {
1164 size = lustre_lnet_parse_nids(optarg, nids, size,
1169 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1172 print_help(peer_cmds, "peer", "del");
1179 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1183 for (i = 0; i < size; i++)
1188 if (rc != LUSTRE_CFG_RC_NO_ERR)
1189 cYAML_print_tree2file(stderr, err_rc);
1191 cYAML_free_tree(err_rc);
1196 static int jt_show_peer(int argc, char **argv)
1200 struct cYAML *err_rc = NULL, *show_rc = NULL;
1203 const char *const short_options = "n:vh";
1204 const struct option long_options[] = {
1205 { "nid", 1, NULL, 'n' },
1206 { "verbose", 0, NULL, 'v' },
1207 { "help", 0, NULL, 'h' },
1208 { NULL, 0, NULL, 0 },
1211 while ((opt = getopt_long(argc, argv, short_options,
1212 long_options, NULL)) != -1) {
1221 print_help(peer_cmds, "peer", "show");
1228 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1230 if (rc != LUSTRE_CFG_RC_NO_ERR)
1231 cYAML_print_tree2file(stderr, err_rc);
1233 cYAML_print_tree(show_rc);
1235 cYAML_free_tree(err_rc);
1236 cYAML_free_tree(show_rc);
1241 command_t list[] = {
1242 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1243 {"route", jt_route, 0, "route {add | del | show | help}"},
1244 {"net", jt_net, 0, "net {add | del | show | help}"},
1245 {"routing", jt_routing, 0, "routing {show | help}"},
1246 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1248 {"import", jt_import, 0, "import {--add | --del | --show | "
1249 "--help} FILE.yaml"},
1250 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1251 {"stats", jt_stats, 0, "stats {show | help}"},
1252 {"numa", jt_numa, 0, "numa {show | help}"},
1253 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1254 {"help", Parser_help, 0, "help"},
1255 {"exit", Parser_quit, 0, "quit"},
1256 {"quit", Parser_quit, 0, "quit"},
1257 {"--list-commands", lnetctl_list_commands, 0, "list commands"},
1261 static int lnetctl_list_commands(int argc, char **argv)
1263 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
1265 Parser_list_commands(list, buffer, sizeof(buffer), NULL, 0, 4);
1270 int main(int argc, char **argv)
1273 struct cYAML *err_rc = NULL;
1275 rc = lustre_lnet_config_lib_init();
1277 cYAML_build_error(-1, -1, "lnetctl", "startup",
1278 "cannot register LNet device", &err_rc);
1279 cYAML_print_tree2file(stderr, err_rc);
1283 Parser_init("lnetctl > ", list);
1285 rc = Parser_execarg(argc - 1, &argv[1], list);