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_set_tiny(int argc, char **argv);
54 static int jt_set_small(int argc, char **argv);
55 static int jt_set_large(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);*/
60 command_t lnet_cmds[] = {
61 {"configure", jt_config_lnet, 0, "configure lnet\n"
62 "\t--all: load NI configuration from module parameters\n"},
63 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
67 command_t route_cmds[] = {
68 {"add", jt_add_route, 0, "add a route\n"
69 "\t--net: net name (e.g. tcp0)\n"
70 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
71 "\t--hop: number to final destination (1 < hops < 255)\n"
72 "\t--priority: priority of route (0 - highest prio\n"},
73 {"del", jt_del_route, 0, "delete a route\n"
74 "\t--net: net name (e.g. tcp0)\n"
75 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
76 {"show", jt_show_route, 0, "show routes\n"
77 "\t--net: net name (e.g. tcp0) to filter on\n"
78 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
79 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
80 "\t--priority: priority of route (0 - highest prio to filter on\n"
81 "\t--verbose: display detailed output per route\n"},
85 command_t net_cmds[] = {
86 {"add", jt_add_ni, 0, "add a network\n"
87 "\t--net: net name (e.g. tcp0)\n"
88 "\t--if: physical interface (e.g. eth0)\n"
89 "\t--ip2net: specify networks based on IP address patterns\n"
90 "\t--peer-timeout: time to wait before declaring a peer dead\n"
91 "\t--peer-credits: define the max number of inflight messages\n"
92 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
93 "\t--credits: Network Interface credits\n"
94 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
95 {"del", jt_del_ni, 0, "delete a network\n"
96 "\t--net: net name (e.g. tcp0)\n"
97 "\t--if: physical interface (e.g. eth0)\n"},
98 {"show", jt_show_net, 0, "show networks\n"
99 "\t--net: net name (e.g. tcp0) to filter on\n"
100 "\t--verbose: display detailed output per network\n"},
104 command_t routing_cmds[] = {
105 {"show", jt_show_routing, 0, "show routing information\n"},
109 command_t stats_cmds[] = {
110 {"show", jt_show_stats, 0, "show LNET statistics\n"},
114 command_t set_cmds[] = {
115 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
116 "\tVALUE must be greater than 0\n"},
117 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
118 "\tVALUE must be greater than 0\n"},
119 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
120 "\tVALUE must be greater than 0\n"},
121 {"routing", jt_set_routing, 0, "enable/disable routing\n"
122 "\t0 - disable routing\n"
123 "\t1 - enable routing\n"},
127 command_t peer_cmds[] = {
128 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
129 "\t--key_nid: NID to identify peer. If not provided then the first\n"
130 "\t NID in the list becomes the key NID of a newly created\n"
132 "\t--nid: one or more peer NIDs\n"},
133 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
134 "\t--key_nid: NID to identify peer.\n"
135 "\t--nid: list of NIDs to remove. If none provided,\n"
136 "\t peer is deleted\n"},
137 {"show", jt_show_peer, 0, "show peer credits\n"
138 "\t--primary_nid: NID of peer to filter on.\n"},
142 static inline void print_help(const command_t cmds[], const char *cmd_type,
145 const command_t *cmd;
147 for (cmd = cmds; cmd->pc_name; cmd++) {
148 if (pc_name != NULL &&
149 strcmp(cmd->pc_name, pc_name) == 0) {
150 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
153 } else if (pc_name != NULL) {
156 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
160 static int parse_long(const char *number, long int *value)
164 *value = strtol(number, &end, 0);
165 if (end != NULL && *end != 0)
171 static int handle_help(const command_t *cmd_list, const char *cmd,
172 const char *sub_cmd, int argc, char **argv)
179 const char *const short_options = "h";
180 const struct option long_options[] = {
181 { "help", 0, NULL, 'h' },
182 { NULL, 0, NULL, 0 },
185 while ((opt = getopt_long(argc, argv, short_options,
186 long_options, NULL)) != -1) {
189 print_help(cmd_list, cmd, sub_cmd);
203 static int jt_set_tiny(int argc, char **argv)
207 struct cYAML *err_rc = NULL;
209 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
212 rc = parse_long(argv[1], &value);
214 cYAML_build_error(-1, -1, "parser", "set",
215 "cannot parse tiny_buffers value", &err_rc);
216 cYAML_print_tree2file(stderr, err_rc);
217 cYAML_free_tree(err_rc);
221 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
222 if (rc != LUSTRE_CFG_RC_NO_ERR)
223 cYAML_print_tree2file(stderr, err_rc);
225 cYAML_free_tree(err_rc);
230 static int jt_set_small(int argc, char **argv)
234 struct cYAML *err_rc = NULL;
236 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
239 rc = parse_long(argv[1], &value);
241 cYAML_build_error(-1, -1, "parser", "set",
242 "cannot parse small_buffers value", &err_rc);
243 cYAML_print_tree2file(stderr, err_rc);
244 cYAML_free_tree(err_rc);
248 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
249 if (rc != LUSTRE_CFG_RC_NO_ERR)
250 cYAML_print_tree2file(stderr, err_rc);
252 cYAML_free_tree(err_rc);
257 static int jt_set_large(int argc, char **argv)
261 struct cYAML *err_rc = NULL;
263 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
266 rc = parse_long(argv[1], &value);
268 cYAML_build_error(-1, -1, "parser", "set",
269 "cannot parse large_buffers value", &err_rc);
270 cYAML_print_tree2file(stderr, err_rc);
271 cYAML_free_tree(err_rc);
275 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
276 if (rc != LUSTRE_CFG_RC_NO_ERR)
277 cYAML_print_tree2file(stderr, err_rc);
279 cYAML_free_tree(err_rc);
284 static int jt_set_routing(int argc, char **argv)
287 struct cYAML *err_rc = NULL;
290 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
293 rc = parse_long(argv[1], &value);
294 if (rc != 0 || (value != 0 && value != 1)) {
295 cYAML_build_error(-1, -1, "parser", "set",
296 "cannot parse routing value.\n"
297 "must be 0 for disable or 1 for enable",
299 cYAML_print_tree2file(stderr, err_rc);
300 cYAML_free_tree(err_rc);
304 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
306 if (rc != LUSTRE_CFG_RC_NO_ERR)
307 cYAML_print_tree2file(stderr, err_rc);
309 cYAML_free_tree(err_rc);
314 static int jt_config_lnet(int argc, char **argv)
316 struct cYAML *err_rc = NULL;
317 bool load_mod_params = false;
320 const char *const short_options = "ah";
321 const struct option long_options[] = {
322 { "all", 0, NULL, 'a' },
323 { "help", 0, NULL, 'h' },
324 { NULL, 0, NULL, 0 },
327 while ((opt = getopt_long(argc, argv, short_options,
328 long_options, NULL)) != -1) {
331 load_mod_params = true;
334 print_help(lnet_cmds, "lnet", "configure");
341 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
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_unconfig_lnet(int argc, char **argv)
354 struct cYAML *err_rc = NULL;
357 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
360 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
362 if (rc != LUSTRE_CFG_RC_NO_ERR)
363 cYAML_print_tree2file(stderr, err_rc);
365 cYAML_free_tree(err_rc);
369 static int jt_add_route(int argc, char **argv)
371 char *network = NULL, *gateway = NULL;
372 long int hop = -1, prio = -1;
373 struct cYAML *err_rc = NULL;
376 const char *const short_options = "n:g:c:p:h";
377 const struct option long_options[] = {
378 { "net", 1, NULL, 'n' },
379 { "gateway", 1, NULL, 'g' },
380 { "hop-count", 1, NULL, 'c' },
381 { "priority", 1, NULL, 'p' },
382 { "help", 0, NULL, 'h' },
383 { NULL, 0, NULL, 0 },
386 while ((opt = getopt_long(argc, argv, short_options,
387 long_options, NULL)) != -1) {
396 rc = parse_long(optarg, &hop);
404 rc = parse_long(optarg, &prio);
412 print_help(route_cmds, "route", "add");
419 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
421 if (rc != LUSTRE_CFG_RC_NO_ERR)
422 cYAML_print_tree2file(stderr, err_rc);
424 cYAML_free_tree(err_rc);
429 static int jt_add_ni(int argc, char **argv)
432 long int pto = -1, pc = -1, pbc = -1, cre = -1;
433 struct cYAML *err_rc = NULL;
434 int rc, opt, num_global_cpts = 0;
435 struct lnet_dlc_network_descr nw_descr;
436 struct cfs_expr_list *global_cpts = NULL;
437 struct lnet_ioctl_config_lnd_tunables tunables;
440 memset(&tunables, 0, sizeof(tunables));
441 lustre_lnet_init_nw_descr(&nw_descr);
443 const char *const short_options = "n:i:p:t:c:b:r:s:h";
444 const struct option long_options[] = {
445 { "net", 1, NULL, 'n' },
446 { "if", 1, NULL, 'i' },
447 { "ip2net", 1, NULL, 'p' },
448 { "peer-timeout", 1, NULL, 't' },
449 { "peer-credits", 1, NULL, 'c' },
450 { "peer-buffer-credits", 1, NULL, 'b' },
451 { "credits", 1, NULL, 'r' },
452 { "cpt", 1, NULL, 's' },
453 { "help", 0, NULL, 'h' },
454 { NULL, 0, NULL, 0 },
457 while ((opt = getopt_long(argc, argv, short_options,
458 long_options, NULL)) != -1) {
461 nw_descr.nw_id = libcfs_str2net(optarg);
464 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
466 cYAML_build_error(-1, -1, "ni", "add",
467 "bad interface list",
476 rc = parse_long(optarg, &pto);
484 rc = parse_long(optarg, &pc);
492 rc = parse_long(optarg, &pbc);
500 rc = parse_long(optarg, &cre);
509 cfs_expr_list_parse(optarg,
511 0, UINT_MAX, &global_cpts);
514 print_help(net_cmds, "net", "add");
521 if (pto > 0 || pc > 0 || pbc > 0 || cre > 0) {
522 tunables.lt_cmn.lct_peer_timeout = pto;
523 tunables.lt_cmn.lct_peer_tx_credits = pc;
524 tunables.lt_cmn.lct_peer_rtr_credits = pbc;
525 tunables.lt_cmn.lct_max_tx_credits = cre;
529 rc = lustre_lnet_config_ni(&nw_descr,
530 (num_global_cpts > 0) ? global_cpts: NULL,
531 ip2net, (found) ? &tunables : NULL,
534 if (global_cpts != NULL)
535 cfs_expr_list_free(global_cpts);
538 if (rc != LUSTRE_CFG_RC_NO_ERR)
539 cYAML_print_tree2file(stderr, err_rc);
541 cYAML_free_tree(err_rc);
546 static int jt_del_route(int argc, char **argv)
548 char *network = NULL, *gateway = NULL;
549 struct cYAML *err_rc = NULL;
552 const char *const short_options = "n:g:h";
553 const struct option long_options[] = {
554 { "net", 1, NULL, 'n' },
555 { "gateway", 1, NULL, 'g' },
556 { "help", 0, NULL, 'h' },
557 { NULL, 0, NULL, 0 },
560 while ((opt = getopt_long(argc, argv, short_options,
561 long_options, NULL)) != -1) {
570 print_help(route_cmds, "route", "del");
577 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
579 if (rc != LUSTRE_CFG_RC_NO_ERR)
580 cYAML_print_tree2file(stderr, err_rc);
582 cYAML_free_tree(err_rc);
587 static int jt_del_ni(int argc, char **argv)
589 struct cYAML *err_rc = NULL;
591 struct lnet_dlc_network_descr nw_descr;
593 lustre_lnet_init_nw_descr(&nw_descr);
595 const char *const short_options = "n:i:h";
596 const struct option long_options[] = {
597 { "net", 1, NULL, 'n' },
598 { "if", 1, NULL, 'i' },
599 { "help", 0, NULL, 'h' },
600 { NULL, 0, NULL, 0 },
603 while ((opt = getopt_long(argc, argv, short_options,
604 long_options, NULL)) != -1) {
607 nw_descr.nw_id = libcfs_str2net(optarg);
610 rc = lustre_lnet_parse_interfaces(optarg, &nw_descr);
612 cYAML_build_error(-1, -1, "ni", "add",
613 "bad interface list",
619 print_help(net_cmds, "net", "del");
626 rc = lustre_lnet_del_ni(&nw_descr, -1, &err_rc);
629 if (rc != LUSTRE_CFG_RC_NO_ERR)
630 cYAML_print_tree2file(stderr, err_rc);
632 cYAML_free_tree(err_rc);
637 static int jt_show_route(int argc, char **argv)
639 char *network = NULL, *gateway = NULL;
640 long int hop = -1, prio = -1;
641 int detail = 0, rc, opt;
642 struct cYAML *err_rc = NULL, *show_rc = NULL;
644 const char *const short_options = "n:g:h:p:vh";
645 const struct option long_options[] = {
646 { "net", 1, NULL, 'n' },
647 { "gateway", 1, NULL, 'g' },
648 { "hop-count", 1, NULL, 'c' },
649 { "priority", 1, NULL, 'p' },
650 { "verbose", 0, NULL, 'v' },
651 { "help", 0, NULL, 'h' },
652 { NULL, 0, NULL, 0 },
655 while ((opt = getopt_long(argc, argv, short_options,
656 long_options, NULL)) != -1) {
665 rc = parse_long(optarg, &hop);
673 rc = parse_long(optarg, &prio);
684 print_help(route_cmds, "route", "show");
691 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
694 if (rc != LUSTRE_CFG_RC_NO_ERR)
695 cYAML_print_tree2file(stderr, err_rc);
697 cYAML_print_tree(show_rc);
699 cYAML_free_tree(err_rc);
700 cYAML_free_tree(show_rc);
705 static int jt_show_net(int argc, char **argv)
707 char *network = NULL;
708 int detail = 0, rc, opt;
709 struct cYAML *err_rc = NULL, *show_rc = NULL;
711 const char *const short_options = "n:vh";
712 const struct option long_options[] = {
713 { "net", 1, NULL, 'n' },
714 { "verbose", 0, NULL, 'v' },
715 { "help", 0, NULL, 'h' },
716 { NULL, 0, NULL, 0 },
719 while ((opt = getopt_long(argc, argv, short_options,
720 long_options, NULL)) != -1) {
729 print_help(net_cmds, "net", "show");
736 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
738 if (rc != LUSTRE_CFG_RC_NO_ERR)
739 cYAML_print_tree2file(stderr, err_rc);
741 cYAML_print_tree(show_rc);
743 cYAML_free_tree(err_rc);
744 cYAML_free_tree(show_rc);
749 static int jt_show_routing(int argc, char **argv)
751 struct cYAML *err_rc = NULL, *show_rc = NULL;
754 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
757 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
759 if (rc != LUSTRE_CFG_RC_NO_ERR)
760 cYAML_print_tree2file(stderr, err_rc);
762 cYAML_print_tree(show_rc);
764 cYAML_free_tree(err_rc);
765 cYAML_free_tree(show_rc);
770 static int jt_show_stats(int argc, char **argv)
773 struct cYAML *show_rc = NULL, *err_rc = NULL;
775 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
778 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
780 if (rc != LUSTRE_CFG_RC_NO_ERR)
781 cYAML_print_tree2file(stderr, err_rc);
783 cYAML_print_tree(show_rc);
785 cYAML_free_tree(err_rc);
786 cYAML_free_tree(show_rc);
791 static inline int jt_lnet(int argc, char **argv)
797 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
800 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
803 static inline int jt_route(int argc, char **argv)
809 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
812 return Parser_execarg(argc - 1, &argv[1], route_cmds);
815 static inline int jt_net(int argc, char **argv)
821 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
824 return Parser_execarg(argc - 1, &argv[1], net_cmds);
827 static inline int jt_routing(int argc, char **argv)
833 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
836 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
839 static inline int jt_stats(int argc, char **argv)
845 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
848 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
851 static inline int jt_peers(int argc, char **argv)
857 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
860 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
863 static inline int jt_set(int argc, char **argv)
869 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
872 return Parser_execarg(argc - 1, &argv[1], set_cmds);
875 static int jt_import(int argc, char **argv)
878 struct cYAML *err_rc = NULL;
879 struct cYAML *show_rc = NULL;
880 int rc = 0, opt, opt_found = 0;
883 const char *const short_options = "adsh";
884 const struct option long_options[] = {
885 { "add", 0, NULL, 'a' },
886 { "del", 0, NULL, 'd' },
887 { "show", 0, NULL, 's' },
888 { "help", 0, NULL, 'h' },
889 { NULL, 0, NULL, 0 },
892 while ((opt = getopt_long(argc, argv, short_options,
893 long_options, NULL)) != -1) {
902 printf("import FILE\n"
903 "import < FILE : import a file\n"
904 "\t--add: add configuration\n"
905 "\t--del: delete configuration\n"
906 "\t--show: show configuration\n"
907 "\t--help: display this help\n"
908 "If no command option is given then --add"
909 " is assumed by default\n");
916 /* grab the file name if one exists */
917 if (opt_found && argc == 3)
919 else if (!opt_found && argc == 2)
924 rc = lustre_yaml_config(file, &err_rc);
927 rc = lustre_yaml_del(file, &err_rc);
930 rc = lustre_yaml_show(file, &show_rc, &err_rc);
931 cYAML_print_tree(show_rc);
932 cYAML_free_tree(show_rc);
936 if (rc != LUSTRE_CFG_RC_NO_ERR)
937 cYAML_print_tree2file(stderr, err_rc);
939 cYAML_free_tree(err_rc);
944 static int jt_export(int argc, char **argv)
946 struct cYAML *show_rc = NULL;
947 struct cYAML *err_rc = NULL;
951 const char *const short_options = "h";
952 const struct option long_options[] = {
953 { "help", 0, NULL, 'h' },
954 { NULL, 0, NULL, 0 },
957 while ((opt = getopt_long(argc, argv, short_options,
958 long_options, NULL)) != -1) {
961 printf("export FILE\n"
962 "export > FILE : export configuration\n"
963 "\t--help: display this help\n");
971 f = fopen(argv[1], "w");
977 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
978 if (rc != LUSTRE_CFG_RC_NO_ERR) {
979 cYAML_print_tree2file(stderr, err_rc);
980 cYAML_free_tree(err_rc);
983 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
985 if (rc != LUSTRE_CFG_RC_NO_ERR) {
986 cYAML_print_tree2file(stderr, err_rc);
987 cYAML_free_tree(err_rc);
990 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
991 if (rc != LUSTRE_CFG_RC_NO_ERR) {
992 cYAML_print_tree2file(stderr, err_rc);
993 cYAML_free_tree(err_rc);
996 if (show_rc != NULL) {
997 cYAML_print_tree2file(f, show_rc);
998 cYAML_free_tree(show_rc);
1007 static int jt_add_peer_nid(int argc, char **argv)
1009 char *key_nid = NULL;
1010 char *nid[LNET_MAX_INTERFACES] = {NULL};
1012 struct cYAML *err_rc = NULL;
1015 const char *const short_options = "k:n:h";
1016 const struct option long_options[] = {
1017 { "key_nid", 1, NULL, 'k' },
1018 { "nid", 1, NULL, 'n' },
1019 { "help", 0, NULL, 'h' },
1020 { NULL, 0, NULL, 0 },
1023 while ((opt = getopt_long(argc, argv, short_options,
1024 long_options, NULL)) != -1) {
1030 if (idx >= LNET_MAX_INTERFACES) {
1031 cYAML_build_error(-1, -1, "peer_ni", "add",
1032 "too many interfaces",
1034 rc = LUSTRE_CFG_RC_BAD_PARAM;
1037 nid[idx] = calloc(strlen(optarg) + 1, 1);
1038 if (nid[idx] == NULL) {
1039 cYAML_build_error(-1, -1, "peer_ni", "add",
1042 rc = LUSTRE_CFG_RC_BAD_PARAM;
1045 strncpy(nid[idx], optarg, strlen(optarg));
1049 print_help(peer_cmds, "peer", "add");
1056 rc = lustre_lnet_config_peer_nid(key_nid, nid, -1, &err_rc);
1060 while (nid[idx] != NULL) {
1065 if (rc != LUSTRE_CFG_RC_NO_ERR)
1066 cYAML_print_tree2file(stderr, err_rc);
1068 cYAML_free_tree(err_rc);
1073 static int jt_del_peer_nid(int argc, char **argv)
1075 char *key_nid = NULL;
1076 char *nid[LNET_MAX_INTERFACES] = {NULL};
1078 struct cYAML *err_rc = NULL;
1081 const char *const short_options = "k:n:h";
1082 const struct option long_options[] = {
1083 { "key_nid", 1, NULL, 'k' },
1084 { "nid", 1, NULL, 'n' },
1085 { "help", 0, NULL, 'h' },
1086 { NULL, 0, NULL, 0 },
1089 while ((opt = getopt_long(argc, argv, short_options,
1090 long_options, NULL)) != -1) {
1096 if (idx >= LNET_MAX_INTERFACES) {
1097 cYAML_build_error(-1, -1, "peer_ni", "del",
1098 "too many interfaces",
1100 rc = LUSTRE_CFG_RC_BAD_PARAM;
1103 nid[idx] = calloc(strlen(optarg) + 1, 1);
1104 if (nid[idx] == NULL) {
1105 cYAML_build_error(-1, -1, "peer_ni", "del",
1108 rc = LUSTRE_CFG_RC_BAD_PARAM;
1111 strncpy(nid[idx], optarg, strlen(optarg));
1115 print_help(peer_cmds, "peer", "del");
1122 rc = lustre_lnet_del_peer_nid(key_nid, nid, -1, &err_rc);
1125 if (rc != LUSTRE_CFG_RC_NO_ERR)
1126 cYAML_print_tree2file(stderr, err_rc);
1128 cYAML_free_tree(err_rc);
1133 static int jt_show_peer(int argc, char **argv)
1135 char *key_nid = NULL;
1137 struct cYAML *err_rc = NULL, *show_rc = NULL;
1139 const char *const short_options = "k:vh";
1140 const struct option long_options[] = {
1141 { "key_nid", 1, NULL, 'k' },
1142 { "help", 0, NULL, 'h' },
1143 { NULL, 0, NULL, 0 },
1146 while ((opt = getopt_long(argc, argv, short_options,
1147 long_options, NULL)) != -1) {
1153 print_help(peer_cmds, "peer", "add");
1160 rc = lustre_lnet_show_peer(key_nid, -1, &show_rc, &err_rc);
1162 if (rc != LUSTRE_CFG_RC_NO_ERR)
1163 cYAML_print_tree2file(stderr, err_rc);
1165 cYAML_print_tree(show_rc);
1167 cYAML_free_tree(err_rc);
1168 cYAML_free_tree(show_rc);
1173 command_t list[] = {
1174 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1175 {"route", jt_route, 0, "route {add | del | show | help}"},
1176 {"net", jt_net, 0, "net {add | del | show | help}"},
1177 {"routing", jt_routing, 0, "routing {show | help}"},
1178 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1180 {"import", jt_import, 0, "import {--add | --del | --show | "
1181 "--help} FILE.yaml"},
1182 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1183 {"stats", jt_stats, 0, "stats {show | help}"},
1184 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1185 {"help", Parser_help, 0, "help"},
1186 {"exit", Parser_quit, 0, "quit"},
1187 {"quit", Parser_quit, 0, "quit"},
1191 int main(int argc, char **argv)
1194 struct cYAML *err_rc = NULL;
1196 rc = lustre_lnet_config_lib_init();
1198 cYAML_build_error(-1, -1, "lnetctl", "startup",
1199 "cannot register LNet device", &err_rc);
1200 cYAML_print_tree2file(stderr, err_rc);
1204 Parser_init("lnetctl > ", list);
1206 rc = Parser_execarg(argc - 1, &argv[1], list);