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 static const struct option long_options[] = {
192 { .name = "help", .has_arg = no_argument, .val = 'h' },
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_numa_range(value, -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 static const struct option long_options[] = {
360 { .name = "all", .has_arg = no_argument, .val = 'a' },
361 { .name = "help", .has_arg = no_argument, .val = 'h' },
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 static const struct option long_options[] = {
416 { .name = "net", .has_arg = required_argument, .val = 'n' },
417 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
418 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
419 { .name = "priority", .has_arg = required_argument, .val = 'p' },
420 { .name = "help", .has_arg = no_argument, .val = 'h' },
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, cpt_rc = -1;
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 static const struct option long_options[] = {
482 { .name = "net", .has_arg = required_argument, .val = 'n' },
483 { .name = "if", .has_arg = required_argument, .val = 'i' },
484 { .name = "ip2net", .has_arg = required_argument, .val = 'p' },
485 { .name = "peer-timeout", .has_arg = required_argument, .val = 't' },
486 { .name = "peer-credits", .has_arg = required_argument, .val = 'c' },
487 { .name = "peer-buffer-credits",
488 .has_arg = required_argument, .val = 'b' },
489 { .name = "credits", .has_arg = required_argument, .val = 'r' },
490 { .name = "cpt", .has_arg = required_argument, .val = 's' },
491 { .name = "help", .has_arg = no_argument, .val = 'h' },
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);
545 cpt_rc = cfs_expr_list_parse(optarg,
547 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 (cpt_rc == 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 static const struct option long_options[] = {
590 { .name = "net", .has_arg = required_argument, .val = 'n' },
591 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
592 { .name = "help", .has_arg = no_argument, .val = 'h' },
595 while ((opt = getopt_long(argc, argv, short_options,
596 long_options, NULL)) != -1) {
605 print_help(route_cmds, "route", "del");
612 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
614 if (rc != LUSTRE_CFG_RC_NO_ERR)
615 cYAML_print_tree2file(stderr, err_rc);
617 cYAML_free_tree(err_rc);
622 static int jt_del_ni(int argc, char **argv)
624 struct cYAML *err_rc = NULL;
626 struct lnet_dlc_network_descr nw_descr;
628 lustre_lnet_init_nw_descr(&nw_descr);
630 const char *const short_options = "n:i:h";
631 static const struct option long_options[] = {
632 { .name = "net", .has_arg = required_argument, .val = 'n' },
633 { .name = "if", .has_arg = required_argument, .val = 'i' },
634 { .name = "help", .has_arg = no_argument, .val = 'h' },
637 while ((opt = getopt_long(argc, argv, short_options,
638 long_options, NULL)) != -1) {
641 nw_descr.nw_id = libcfs_str2net(optarg);
644 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
646 cYAML_build_error(-1, -1, "ni", "add",
647 "bad interface list",
653 print_help(net_cmds, "net", "del");
660 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
663 if (rc != LUSTRE_CFG_RC_NO_ERR)
664 cYAML_print_tree2file(stderr, err_rc);
666 cYAML_free_tree(err_rc);
671 static int jt_show_route(int argc, char **argv)
673 char *network = NULL, *gateway = NULL;
674 long int hop = -1, prio = -1;
675 int detail = 0, rc, opt;
676 struct cYAML *err_rc = NULL, *show_rc = NULL;
678 const char *const short_options = "n:g:h:p:vh";
679 static const struct option long_options[] = {
680 { .name = "net", .has_arg = required_argument, .val = 'n' },
681 { .name = "gateway", .has_arg = required_argument, .val = 'g' },
682 { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
683 { .name = "priority", .has_arg = required_argument, .val = 'p' },
684 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
685 { .name = "help", .has_arg = no_argument, .val = 'h' },
688 while ((opt = getopt_long(argc, argv, short_options,
689 long_options, NULL)) != -1) {
698 rc = parse_long(optarg, &hop);
706 rc = parse_long(optarg, &prio);
717 print_help(route_cmds, "route", "show");
724 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
727 if (rc != LUSTRE_CFG_RC_NO_ERR)
728 cYAML_print_tree2file(stderr, err_rc);
730 cYAML_print_tree(show_rc);
732 cYAML_free_tree(err_rc);
733 cYAML_free_tree(show_rc);
738 static int jt_show_net(int argc, char **argv)
740 char *network = NULL;
741 int detail = 0, rc, opt;
742 struct cYAML *err_rc = NULL, *show_rc = NULL;
744 const char *const short_options = "n:vh";
745 static const struct option long_options[] = {
746 { .name = "net", .has_arg = required_argument, .val = 'n' },
747 { .name = "verbose", .has_arg = no_argument, .val = 'v' },
748 { .name = "help", .has_arg = no_argument, .val = 'h' },
751 while ((opt = getopt_long(argc, argv, short_options,
752 long_options, NULL)) != -1) {
761 print_help(net_cmds, "net", "show");
768 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
770 if (rc != LUSTRE_CFG_RC_NO_ERR)
771 cYAML_print_tree2file(stderr, err_rc);
773 cYAML_print_tree(show_rc);
775 cYAML_free_tree(err_rc);
776 cYAML_free_tree(show_rc);
781 static int jt_show_routing(int argc, char **argv)
783 struct cYAML *err_rc = NULL, *show_rc = NULL;
786 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
789 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
791 if (rc != LUSTRE_CFG_RC_NO_ERR)
792 cYAML_print_tree2file(stderr, err_rc);
794 cYAML_print_tree(show_rc);
796 cYAML_free_tree(err_rc);
797 cYAML_free_tree(show_rc);
802 static int jt_show_stats(int argc, char **argv)
805 struct cYAML *show_rc = NULL, *err_rc = NULL;
807 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
810 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
812 if (rc != LUSTRE_CFG_RC_NO_ERR)
813 cYAML_print_tree2file(stderr, err_rc);
815 cYAML_print_tree(show_rc);
817 cYAML_free_tree(err_rc);
818 cYAML_free_tree(show_rc);
823 static int jt_show_numa(int argc, char **argv)
826 struct cYAML *show_rc = NULL, *err_rc = NULL;
828 if (handle_help(numa_cmds, "numa", "show", argc, argv) == 0)
831 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
833 if (rc != LUSTRE_CFG_RC_NO_ERR)
834 cYAML_print_tree2file(stderr, err_rc);
836 cYAML_print_tree(show_rc);
838 cYAML_free_tree(err_rc);
839 cYAML_free_tree(show_rc);
844 static inline int jt_lnet(int argc, char **argv)
850 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
853 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
856 static inline int jt_route(int argc, char **argv)
862 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
865 return Parser_execarg(argc - 1, &argv[1], route_cmds);
868 static inline int jt_net(int argc, char **argv)
874 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
877 return Parser_execarg(argc - 1, &argv[1], net_cmds);
880 static inline int jt_routing(int argc, char **argv)
886 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
889 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
892 static inline int jt_stats(int argc, char **argv)
898 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
901 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
904 static inline int jt_numa(int argc, char **argv)
910 handle_help(numa_cmds, "numa", NULL, argc, argv) == 0)
913 return Parser_execarg(argc - 1, &argv[1], numa_cmds);
916 static inline int jt_peers(int argc, char **argv)
922 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
925 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
928 static inline int jt_set(int argc, char **argv)
934 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
937 return Parser_execarg(argc - 1, &argv[1], set_cmds);
940 static int jt_import(int argc, char **argv)
943 struct cYAML *err_rc = NULL;
944 struct cYAML *show_rc = NULL;
945 int rc = 0, opt, opt_found = 0;
948 const char *const short_options = "adsh";
949 static const struct option long_options[] = {
950 { .name = "add", .has_arg = no_argument, .val = 'a' },
951 { .name = "del", .has_arg = no_argument, .val = 'd' },
952 { .name = "show", .has_arg = no_argument, .val = 's' },
953 { .name = "help", .has_arg = no_argument, .val = 'h' },
956 while ((opt = getopt_long(argc, argv, short_options,
957 long_options, NULL)) != -1) {
966 printf("import FILE\n"
967 "import < FILE : import a file\n"
968 "\t--add: add configuration\n"
969 "\t--del: delete configuration\n"
970 "\t--show: show configuration\n"
971 "\t--help: display this help\n"
972 "If no command option is given then --add"
973 " is assumed by default\n");
980 /* grab the file name if one exists */
981 if (opt_found && argc == 3)
983 else if (!opt_found && argc == 2)
988 rc = lustre_yaml_config(file, &err_rc);
991 rc = lustre_yaml_del(file, &err_rc);
994 rc = lustre_yaml_show(file, &show_rc, &err_rc);
995 cYAML_print_tree(show_rc);
996 cYAML_free_tree(show_rc);
1000 cYAML_print_tree2file(stderr, err_rc);
1002 cYAML_free_tree(err_rc);
1007 static int jt_export(int argc, char **argv)
1009 struct cYAML *show_rc = NULL;
1010 struct cYAML *err_rc = NULL;
1014 const char *const short_options = "h";
1015 static const struct option long_options[] = {
1016 { .name = "help", .has_arg = no_argument, .val = 'h' },
1019 while ((opt = getopt_long(argc, argv, short_options,
1020 long_options, NULL)) != -1) {
1023 printf("export FILE\n"
1024 "export > FILE : export configuration\n"
1025 "\t--help: display this help\n");
1033 f = fopen(argv[1], "w");
1039 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
1040 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1041 cYAML_print_tree2file(stderr, err_rc);
1042 cYAML_free_tree(err_rc);
1045 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_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_routing(-1, &show_rc, &err_rc);
1053 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1054 cYAML_print_tree2file(stderr, err_rc);
1055 cYAML_free_tree(err_rc);
1058 rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
1059 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1060 cYAML_print_tree2file(stderr, err_rc);
1061 cYAML_free_tree(err_rc);
1064 rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
1065 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1066 cYAML_print_tree2file(stderr, err_rc);
1067 cYAML_free_tree(err_rc);
1070 if (show_rc != NULL) {
1071 cYAML_print_tree2file(f, show_rc);
1072 cYAML_free_tree(show_rc);
1081 static int jt_add_peer_nid(int argc, char **argv)
1083 char *prim_nid = NULL;
1084 char **nids = NULL, **nids2 = NULL;
1086 struct cYAML *err_rc = NULL;
1087 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
1088 bool non_mr = false;
1090 const char *const short_options = "k:n:mh";
1091 const struct option long_options[] = {
1092 { "prim_nid", 1, NULL, 'k' },
1093 { "nid", 1, NULL, 'n' },
1094 { "non_mr", 0, NULL, 'm'},
1095 { "help", 0, NULL, 'h' },
1096 { NULL, 0, NULL, 0 },
1099 while ((opt = getopt_long(argc, argv, short_options,
1100 long_options, NULL)) != -1) {
1106 size = lustre_lnet_parse_nids(optarg, nids, size,
1111 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1117 print_help(peer_cmds, "peer", "add");
1124 rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
1125 !non_mr, -1, &err_rc);
1128 for (i = 0; i < size; i++)
1132 if (rc != LUSTRE_CFG_RC_NO_ERR)
1133 cYAML_print_tree2file(stderr, err_rc);
1135 cYAML_free_tree(err_rc);
1140 static int jt_del_peer_nid(int argc, char **argv)
1142 char *prim_nid = NULL;
1143 char **nids = NULL, **nids2 = NULL;
1144 struct cYAML *err_rc = NULL;
1145 int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
1147 const char *const short_options = "k:n:h";
1148 const struct option long_options[] = {
1149 { "prim_nid", 1, NULL, 'k' },
1150 { "nid", 1, NULL, 'n' },
1151 { "help", 0, NULL, 'h' },
1152 { NULL, 0, NULL, 0 },
1155 while ((opt = getopt_long(argc, argv, short_options,
1156 long_options, NULL)) != -1) {
1162 size = lustre_lnet_parse_nids(optarg, nids, size,
1167 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1170 print_help(peer_cmds, "peer", "del");
1177 rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
1180 for (i = 0; i < size; i++)
1184 if (rc != LUSTRE_CFG_RC_NO_ERR)
1185 cYAML_print_tree2file(stderr, err_rc);
1187 cYAML_free_tree(err_rc);
1192 static int jt_show_peer(int argc, char **argv)
1196 struct cYAML *err_rc = NULL, *show_rc = NULL;
1199 const char *const short_options = "n:vh";
1200 const struct option long_options[] = {
1201 { "nid", 1, NULL, 'n' },
1202 { "verbose", 0, NULL, 'v' },
1203 { "help", 0, NULL, 'h' },
1204 { NULL, 0, NULL, 0 },
1207 while ((opt = getopt_long(argc, argv, short_options,
1208 long_options, NULL)) != -1) {
1217 print_help(peer_cmds, "peer", "show");
1224 rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
1226 if (rc != LUSTRE_CFG_RC_NO_ERR)
1227 cYAML_print_tree2file(stderr, err_rc);
1229 cYAML_print_tree(show_rc);
1231 cYAML_free_tree(err_rc);
1232 cYAML_free_tree(show_rc);
1237 command_t list[] = {
1238 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1239 {"route", jt_route, 0, "route {add | del | show | help}"},
1240 {"net", jt_net, 0, "net {add | del | show | help}"},
1241 {"routing", jt_routing, 0, "routing {show | help}"},
1242 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1244 {"import", jt_import, 0, "import {--add | --del | --show | "
1245 "--help} FILE.yaml"},
1246 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1247 {"stats", jt_stats, 0, "stats {show | help}"},
1248 {"numa", jt_numa, 0, "numa {show | help}"},
1249 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1250 {"help", Parser_help, 0, "help"},
1251 {"exit", Parser_quit, 0, "quit"},
1252 {"quit", Parser_quit, 0, "quit"},
1256 int main(int argc, char **argv)
1259 struct cYAML *err_rc = NULL;
1261 rc = lustre_lnet_config_lib_init();
1263 cYAML_build_error(-1, -1, "lnetctl", "startup",
1264 "cannot register LNet device", &err_rc);
1265 cYAML_print_tree2file(stderr, err_rc);
1269 Parser_init("lnetctl > ", list);
1271 rc = Parser_execarg(argc - 1, &argv[1], list);