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>
30 #include <libcfs/util/ioctl.h>
31 #include <libcfs/util/parser.h>
32 #include <lnet/lnetctl.h>
33 #include "cyaml/cyaml.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_net(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_net(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_set_tiny(int argc, char **argv);
52 static int jt_set_small(int argc, char **argv);
53 static int jt_set_large(int argc, char **argv);
54 static int jt_add_peer_nid(int argc, char **argv);
55 static int jt_del_peer_nid(int argc, char **argv);
56 /*static int jt_show_peer(int argc, char **argv);*/
58 command_t lnet_cmds[] = {
59 {"configure", jt_config_lnet, 0, "configure lnet\n"
60 "\t--all: load NI configuration from module parameters\n"},
61 {"unconfigure", jt_unconfig_lnet, 0, "unconfigure lnet\n"},
65 command_t route_cmds[] = {
66 {"add", jt_add_route, 0, "add a route\n"
67 "\t--net: net name (e.g. tcp0)\n"
68 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
69 "\t--hop: number to final destination (1 < hops < 255)\n"
70 "\t--priority: priority of route (0 - highest prio\n"},
71 {"del", jt_del_route, 0, "delete a route\n"
72 "\t--net: net name (e.g. tcp0)\n"
73 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
74 {"show", jt_show_route, 0, "show routes\n"
75 "\t--net: net name (e.g. tcp0) to filter on\n"
76 "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
77 "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
78 "\t--priority: priority of route (0 - highest prio to filter on\n"
79 "\t--verbose: display detailed output per route\n"},
83 command_t net_cmds[] = {
84 {"add", jt_add_net, 0, "add a network\n"
85 "\t--net: net name (e.g. tcp0)\n"
86 "\t--if: physical interface (e.g. eth0)\n"
87 "\t--ip2net: specify networks based on IP address patterns\n"
88 "\t--peer-timeout: time to wait before declaring a peer dead\n"
89 "\t--peer-credits: define the max number of inflight messages\n"
90 "\t--peer-buffer-credits: the number of buffer credits per peer\n"
91 "\t--credits: Network Interface credits\n"
92 "\t--cpt: CPU Partitions configured net uses (e.g. [0,1]\n"},
93 {"del", jt_del_net, 0, "delete a network\n"
94 "\t--net: net name (e.g. tcp0)\n"},
95 {"show", jt_show_net, 0, "show networks\n"
96 "\t--net: net name (e.g. tcp0) to filter on\n"
97 "\t--verbose: display detailed output per network\n"},
101 command_t routing_cmds[] = {
102 {"show", jt_show_routing, 0, "show routing information\n"},
106 command_t stats_cmds[] = {
107 {"show", jt_show_stats, 0, "show LNET statistics\n"},
111 command_t set_cmds[] = {
112 {"tiny_buffers", jt_set_tiny, 0, "set tiny routing buffers\n"
113 "\tVALUE must be greater than 0\n"},
114 {"small_buffers", jt_set_small, 0, "set small routing buffers\n"
115 "\tVALUE must be greater than 0\n"},
116 {"large_buffers", jt_set_large, 0, "set large routing buffers\n"
117 "\tVALUE must be greater than 0\n"},
118 {"routing", jt_set_routing, 0, "enable/disable routing\n"
119 "\t0 - disable routing\n"
120 "\t1 - enable routing\n"},
124 command_t peer_cmds[] = {
125 {"add", jt_add_peer_nid, 0, "add a peer NID\n"
126 "\t--key_nid: NID to identify peer. If not provided then the first\n"
127 "\t NID in the list becomes the key NID of a newly created\n"
129 "\t--nid: one or more peer NIDs\n"},
130 {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
131 "\t--key_nid: NID to identify peer.\n"
132 "\t--nid: list of NIDs to remove. If none provided,\n"
133 "\t peer is deleted\n"},
134 {"show", jt_show_peer, 0, "show peer credits\n"
135 "\t--primary_nid: NID of peer to filter on.\n"},
139 static inline void print_help(const command_t cmds[], const char *cmd_type,
142 const command_t *cmd;
144 for (cmd = cmds; cmd->pc_name; cmd++) {
145 if (pc_name != NULL &&
146 strcmp(cmd->pc_name, pc_name) == 0) {
147 printf("%s %s: %s\n", cmd_type, cmd->pc_name,
150 } else if (pc_name != NULL) {
153 printf("%s %s: %s\n", cmd_type, cmd->pc_name, cmd->pc_help);
157 static int parse_long(const char *number, long int *value)
161 *value = strtol(number, &end, 0);
162 if (end != NULL && *end != 0)
168 static int handle_help(const command_t *cmd_list, const char *cmd,
169 const char *sub_cmd, int argc, char **argv)
176 const char *const short_options = "h";
177 const struct option long_options[] = {
178 { "help", 0, NULL, 'h' },
179 { NULL, 0, NULL, 0 },
182 while ((opt = getopt_long(argc, argv, short_options,
183 long_options, NULL)) != -1) {
186 print_help(cmd_list, cmd, sub_cmd);
200 static int jt_set_tiny(int argc, char **argv)
204 struct cYAML *err_rc = NULL;
206 if (handle_help(set_cmds, "set", "tiny_buffers", argc, argv) == 0)
209 rc = parse_long(argv[1], &value);
211 cYAML_build_error(-1, -1, "parser", "set",
212 "cannot parse tiny_buffers value", &err_rc);
213 cYAML_print_tree2file(stderr, err_rc);
214 cYAML_free_tree(err_rc);
218 rc = lustre_lnet_config_buffers(value, -1, -1, -1, &err_rc);
219 if (rc != LUSTRE_CFG_RC_NO_ERR)
220 cYAML_print_tree2file(stderr, err_rc);
222 cYAML_free_tree(err_rc);
227 static int jt_set_small(int argc, char **argv)
231 struct cYAML *err_rc = NULL;
233 if (handle_help(set_cmds, "set", "small_buffers", argc, argv) == 0)
236 rc = parse_long(argv[1], &value);
238 cYAML_build_error(-1, -1, "parser", "set",
239 "cannot parse small_buffers value", &err_rc);
240 cYAML_print_tree2file(stderr, err_rc);
241 cYAML_free_tree(err_rc);
245 rc = lustre_lnet_config_buffers(-1, value, -1, -1, &err_rc);
246 if (rc != LUSTRE_CFG_RC_NO_ERR)
247 cYAML_print_tree2file(stderr, err_rc);
249 cYAML_free_tree(err_rc);
254 static int jt_set_large(int argc, char **argv)
258 struct cYAML *err_rc = NULL;
260 if (handle_help(set_cmds, "set", "large_buffers", argc, argv) == 0)
263 rc = parse_long(argv[1], &value);
265 cYAML_build_error(-1, -1, "parser", "set",
266 "cannot parse large_buffers value", &err_rc);
267 cYAML_print_tree2file(stderr, err_rc);
268 cYAML_free_tree(err_rc);
272 rc = lustre_lnet_config_buffers(-1, -1, value, -1, &err_rc);
273 if (rc != LUSTRE_CFG_RC_NO_ERR)
274 cYAML_print_tree2file(stderr, err_rc);
276 cYAML_free_tree(err_rc);
281 static int jt_set_routing(int argc, char **argv)
284 struct cYAML *err_rc = NULL;
287 if (handle_help(set_cmds, "set", "routing", argc, argv) == 0)
290 rc = parse_long(argv[1], &value);
291 if (rc != 0 || (value != 0 && value != 1)) {
292 cYAML_build_error(-1, -1, "parser", "set",
293 "cannot parse routing value.\n"
294 "must be 0 for disable or 1 for enable",
296 cYAML_print_tree2file(stderr, err_rc);
297 cYAML_free_tree(err_rc);
301 rc = lustre_lnet_enable_routing(value, -1, &err_rc);
303 if (rc != LUSTRE_CFG_RC_NO_ERR)
304 cYAML_print_tree2file(stderr, err_rc);
306 cYAML_free_tree(err_rc);
311 static int jt_config_lnet(int argc, char **argv)
313 struct cYAML *err_rc = NULL;
314 bool load_mod_params = false;
317 const char *const short_options = "ah";
318 const struct option long_options[] = {
319 { "all", 0, NULL, 'a' },
320 { "help", 0, NULL, 'h' },
321 { NULL, 0, NULL, 0 },
324 while ((opt = getopt_long(argc, argv, short_options,
325 long_options, NULL)) != -1) {
328 load_mod_params = true;
331 print_help(lnet_cmds, "lnet", "configure");
338 rc = lustre_lnet_config_ni_system(LNET_CONFIGURE, load_mod_params,
341 if (rc != LUSTRE_CFG_RC_NO_ERR)
342 cYAML_print_tree2file(stderr, err_rc);
344 cYAML_free_tree(err_rc);
349 static int jt_unconfig_lnet(int argc, char **argv)
351 struct cYAML *err_rc = NULL;
354 if (handle_help(lnet_cmds, "lnet", "unconfigure", argc, argv) == 0)
357 rc = lustre_lnet_config_ni_system(LNET_UNCONFIGURE, 0, -1, &err_rc);
359 if (rc != LUSTRE_CFG_RC_NO_ERR)
360 cYAML_print_tree2file(stderr, err_rc);
362 cYAML_free_tree(err_rc);
366 static int jt_add_route(int argc, char **argv)
368 char *network = NULL, *gateway = NULL;
369 long int hop = -1, prio = -1;
370 struct cYAML *err_rc = NULL;
373 const char *const short_options = "n:g:c:p:h";
374 const struct option long_options[] = {
375 { "net", 1, NULL, 'n' },
376 { "gateway", 1, NULL, 'g' },
377 { "hop-count", 1, NULL, 'c' },
378 { "priority", 1, NULL, 'p' },
379 { "help", 0, NULL, 'h' },
380 { NULL, 0, NULL, 0 },
383 while ((opt = getopt_long(argc, argv, short_options,
384 long_options, NULL)) != -1) {
393 rc = parse_long(optarg, &hop);
401 rc = parse_long(optarg, &prio);
409 print_help(route_cmds, "route", "add");
416 rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
418 if (rc != LUSTRE_CFG_RC_NO_ERR)
419 cYAML_print_tree2file(stderr, err_rc);
421 cYAML_free_tree(err_rc);
426 static int jt_add_net(int argc, char **argv)
428 char *network = NULL, *intf = NULL, *ip2net = NULL, *cpt = NULL;
429 long int pto = -1, pc = -1, pbc = -1, cre = -1;
430 struct cYAML *err_rc = NULL;
433 const char *const short_options = "n:i:p:t:c:b:r:s:h";
434 const struct option long_options[] = {
435 { "net", 1, NULL, 'n' },
436 { "if", 1, NULL, 'i' },
437 { "ip2net", 1, NULL, 'p' },
438 { "peer-timeout", 1, NULL, 't' },
439 { "peer-credits", 1, NULL, 'c' },
440 { "peer-buffer-credits", 1, NULL, 'b' },
441 { "credits", 1, NULL, 'r' },
442 { "cpt", 1, NULL, 's' },
443 { "help", 0, NULL, 'h' },
444 { NULL, 0, NULL, 0 },
447 while ((opt = getopt_long(argc, argv, short_options,
448 long_options, NULL)) != -1) {
460 rc = parse_long(optarg, &pto);
468 rc = parse_long(optarg, &pc);
476 rc = parse_long(optarg, &pbc);
484 rc = parse_long(optarg, &cre);
495 print_help(net_cmds, "net", "add");
502 rc = lustre_lnet_config_net(network, intf, ip2net, pto, pc, pbc,
503 cre, cpt, -1, NULL, &err_rc);
505 if (rc != LUSTRE_CFG_RC_NO_ERR)
506 cYAML_print_tree2file(stderr, err_rc);
508 cYAML_free_tree(err_rc);
513 static int jt_del_route(int argc, char **argv)
515 char *network = NULL, *gateway = NULL;
516 struct cYAML *err_rc = NULL;
519 const char *const short_options = "n:g:h";
520 const struct option long_options[] = {
521 { "net", 1, NULL, 'n' },
522 { "gateway", 1, NULL, 'g' },
523 { "help", 0, NULL, 'h' },
524 { NULL, 0, NULL, 0 },
527 while ((opt = getopt_long(argc, argv, short_options,
528 long_options, NULL)) != -1) {
537 print_help(route_cmds, "route", "del");
544 rc = lustre_lnet_del_route(network, gateway, -1, &err_rc);
546 if (rc != LUSTRE_CFG_RC_NO_ERR)
547 cYAML_print_tree2file(stderr, err_rc);
549 cYAML_free_tree(err_rc);
554 static int jt_del_net(int argc, char **argv)
556 char *network = NULL;
557 struct cYAML *err_rc = NULL;
560 const char *const short_options = "n:h";
561 const struct option long_options[] = {
562 { "net", 1, NULL, 'n' },
563 { "help", 0, NULL, 'h' },
564 { NULL, 0, NULL, 0 },
567 while ((opt = getopt_long(argc, argv, short_options,
568 long_options, NULL)) != -1) {
574 print_help(net_cmds, "net", "del");
581 rc = lustre_lnet_del_net(network, -1, &err_rc);
583 if (rc != LUSTRE_CFG_RC_NO_ERR)
584 cYAML_print_tree2file(stderr, err_rc);
586 cYAML_free_tree(err_rc);
591 static int jt_show_route(int argc, char **argv)
593 char *network = NULL, *gateway = NULL;
594 long int hop = -1, prio = -1;
595 int detail = 0, rc, opt;
596 struct cYAML *err_rc = NULL, *show_rc = NULL;
598 const char *const short_options = "n:g:h:p:vh";
599 const struct option long_options[] = {
600 { "net", 1, NULL, 'n' },
601 { "gateway", 1, NULL, 'g' },
602 { "hop-count", 1, NULL, 'c' },
603 { "priority", 1, NULL, 'p' },
604 { "verbose", 0, NULL, 'v' },
605 { "help", 0, NULL, 'h' },
606 { NULL, 0, NULL, 0 },
609 while ((opt = getopt_long(argc, argv, short_options,
610 long_options, NULL)) != -1) {
619 rc = parse_long(optarg, &hop);
627 rc = parse_long(optarg, &prio);
638 print_help(route_cmds, "route", "show");
645 rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
648 if (rc != LUSTRE_CFG_RC_NO_ERR)
649 cYAML_print_tree2file(stderr, err_rc);
651 cYAML_print_tree(show_rc);
653 cYAML_free_tree(err_rc);
654 cYAML_free_tree(show_rc);
659 static int jt_show_net(int argc, char **argv)
661 char *network = NULL;
662 int detail = 0, rc, opt;
663 struct cYAML *err_rc = NULL, *show_rc = NULL;
665 const char *const short_options = "n:vh";
666 const struct option long_options[] = {
667 { "net", 1, NULL, 'n' },
668 { "verbose", 0, NULL, 'v' },
669 { "help", 0, NULL, 'h' },
670 { NULL, 0, NULL, 0 },
673 while ((opt = getopt_long(argc, argv, short_options,
674 long_options, NULL)) != -1) {
683 print_help(net_cmds, "net", "show");
690 rc = lustre_lnet_show_net(network, detail, -1, &show_rc, &err_rc);
692 if (rc != LUSTRE_CFG_RC_NO_ERR)
693 cYAML_print_tree2file(stderr, err_rc);
695 cYAML_print_tree(show_rc);
697 cYAML_free_tree(err_rc);
698 cYAML_free_tree(show_rc);
703 static int jt_show_routing(int argc, char **argv)
705 struct cYAML *err_rc = NULL, *show_rc = NULL;
708 if (handle_help(routing_cmds, "routing", "show", argc, argv) == 0)
711 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
713 if (rc != LUSTRE_CFG_RC_NO_ERR)
714 cYAML_print_tree2file(stderr, err_rc);
716 cYAML_print_tree(show_rc);
718 cYAML_free_tree(err_rc);
719 cYAML_free_tree(show_rc);
724 static int jt_show_stats(int argc, char **argv)
727 struct cYAML *show_rc = NULL, *err_rc = NULL;
729 if (handle_help(stats_cmds, "stats", "show", argc, argv) == 0)
732 rc = lustre_lnet_show_stats(-1, &show_rc, &err_rc);
734 if (rc != LUSTRE_CFG_RC_NO_ERR)
735 cYAML_print_tree2file(stderr, err_rc);
737 cYAML_print_tree(show_rc);
739 cYAML_free_tree(err_rc);
740 cYAML_free_tree(show_rc);
745 static inline int jt_lnet(int argc, char **argv)
751 handle_help(lnet_cmds, "lnet", NULL, argc, argv) == 0)
754 return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
757 static inline int jt_route(int argc, char **argv)
763 handle_help(route_cmds, "route", NULL, argc, argv) == 0)
766 return Parser_execarg(argc - 1, &argv[1], route_cmds);
769 static inline int jt_net(int argc, char **argv)
775 handle_help(net_cmds, "net", NULL, argc, argv) == 0)
778 return Parser_execarg(argc - 1, &argv[1], net_cmds);
781 static inline int jt_routing(int argc, char **argv)
787 handle_help(routing_cmds, "routing", NULL, argc, argv) == 0)
790 return Parser_execarg(argc - 1, &argv[1], routing_cmds);
793 static inline int jt_stats(int argc, char **argv)
799 handle_help(stats_cmds, "stats", NULL, argc, argv) == 0)
802 return Parser_execarg(argc - 1, &argv[1], stats_cmds);
805 static inline int jt_peers(int argc, char **argv)
811 handle_help(peer_cmds, "peer", NULL, argc, argv) == 0)
814 return Parser_execarg(argc - 1, &argv[1], peer_cmds);
817 static inline int jt_set(int argc, char **argv)
823 handle_help(set_cmds, "set", NULL, argc, argv) == 0)
826 return Parser_execarg(argc - 1, &argv[1], set_cmds);
829 static int jt_import(int argc, char **argv)
832 struct cYAML *err_rc = NULL;
833 struct cYAML *show_rc = NULL;
834 int rc = 0, opt, opt_found = 0;
837 const char *const short_options = "adsh";
838 const struct option long_options[] = {
839 { "add", 0, NULL, 'a' },
840 { "del", 0, NULL, 'd' },
841 { "show", 0, NULL, 's' },
842 { "help", 0, NULL, 'h' },
843 { NULL, 0, NULL, 0 },
846 while ((opt = getopt_long(argc, argv, short_options,
847 long_options, NULL)) != -1) {
856 printf("import FILE\n"
857 "import < FILE : import a file\n"
858 "\t--add: add configuration\n"
859 "\t--del: delete configuration\n"
860 "\t--show: show configuration\n"
861 "\t--help: display this help\n"
862 "If no command option is given then --add"
863 " is assumed by default\n");
870 /* grab the file name if one exists */
871 if (opt_found && argc == 3)
873 else if (!opt_found && argc == 2)
878 rc = lustre_yaml_config(file, &err_rc);
881 rc = lustre_yaml_del(file, &err_rc);
884 rc = lustre_yaml_show(file, &show_rc, &err_rc);
885 cYAML_print_tree(show_rc);
886 cYAML_free_tree(show_rc);
890 if (rc != LUSTRE_CFG_RC_NO_ERR)
891 cYAML_print_tree2file(stderr, err_rc);
893 cYAML_free_tree(err_rc);
898 static int jt_export(int argc, char **argv)
900 struct cYAML *show_rc = NULL;
901 struct cYAML *err_rc = NULL;
905 const char *const short_options = "h";
906 const struct option long_options[] = {
907 { "help", 0, NULL, 'h' },
908 { NULL, 0, NULL, 0 },
911 while ((opt = getopt_long(argc, argv, short_options,
912 long_options, NULL)) != -1) {
915 printf("export FILE\n"
916 "export > FILE : export configuration\n"
917 "\t--help: display this help\n");
925 f = fopen(argv[1], "w");
931 rc = lustre_lnet_show_net(NULL, 1, -1, &show_rc, &err_rc);
932 if (rc != LUSTRE_CFG_RC_NO_ERR) {
933 cYAML_print_tree2file(stderr, err_rc);
934 cYAML_free_tree(err_rc);
937 rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
939 if (rc != LUSTRE_CFG_RC_NO_ERR) {
940 cYAML_print_tree2file(stderr, err_rc);
941 cYAML_free_tree(err_rc);
944 rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
945 if (rc != LUSTRE_CFG_RC_NO_ERR) {
946 cYAML_print_tree2file(stderr, err_rc);
947 cYAML_free_tree(err_rc);
950 if (show_rc != NULL) {
951 cYAML_print_tree2file(f, show_rc);
952 cYAML_free_tree(show_rc);
961 static int jt_add_peer_nid(int argc, char **argv)
963 char *key_nid = NULL;
964 char *nid[LNET_MAX_INTERFACES] = {NULL};
966 struct cYAML *err_rc = NULL;
969 const char *const short_options = "k:n:h";
970 const struct option long_options[] = {
971 { "key_nid", 1, NULL, 'k' },
972 { "nid", 1, NULL, 'n' },
973 { "help", 0, NULL, 'h' },
974 { NULL, 0, NULL, 0 },
977 while ((opt = getopt_long(argc, argv, short_options,
978 long_options, NULL)) != -1) {
984 if (idx >= LNET_MAX_INTERFACES) {
985 cYAML_build_error(-1, -1, "peer_ni", "add",
986 "too many interfaces",
988 rc = LUSTRE_CFG_RC_BAD_PARAM;
991 nid[idx] = calloc(strlen(optarg) + 1, 1);
992 if (nid[idx] == NULL) {
993 cYAML_build_error(-1, -1, "peer_ni", "add",
996 rc = LUSTRE_CFG_RC_BAD_PARAM;
999 strncpy(nid[idx], optarg, strlen(optarg));
1003 print_help(peer_cmds, "peer", "add");
1010 rc = lustre_lnet_config_peer_nid(key_nid, nid, -1, &err_rc);
1014 while (nid[idx] != NULL) {
1019 if (rc != LUSTRE_CFG_RC_NO_ERR)
1020 cYAML_print_tree2file(stderr, err_rc);
1022 cYAML_free_tree(err_rc);
1027 static int jt_del_peer_nid(int argc, char **argv)
1029 char *key_nid = NULL;
1030 char *nid[LNET_MAX_INTERFACES] = {NULL};
1032 struct cYAML *err_rc = NULL;
1035 const char *const short_options = "k:n:h";
1036 const struct option long_options[] = {
1037 { "key_nid", 1, NULL, 'k' },
1038 { "nid", 1, NULL, 'n' },
1039 { "help", 0, NULL, 'h' },
1040 { NULL, 0, NULL, 0 },
1043 while ((opt = getopt_long(argc, argv, short_options,
1044 long_options, NULL)) != -1) {
1050 if (idx >= LNET_MAX_INTERFACES) {
1051 cYAML_build_error(-1, -1, "peer_ni", "del",
1052 "too many interfaces",
1054 rc = LUSTRE_CFG_RC_BAD_PARAM;
1057 nid[idx] = calloc(strlen(optarg) + 1, 1);
1058 if (nid[idx] == NULL) {
1059 cYAML_build_error(-1, -1, "peer_ni", "del",
1062 rc = LUSTRE_CFG_RC_BAD_PARAM;
1065 strncpy(nid[idx], optarg, strlen(optarg));
1069 print_help(peer_cmds, "peer", "del");
1076 rc = lustre_lnet_del_peer_nid(key_nid, nid, -1, &err_rc);
1079 if (rc != LUSTRE_CFG_RC_NO_ERR)
1080 cYAML_print_tree2file(stderr, err_rc);
1082 cYAML_free_tree(err_rc);
1087 static int jt_show_peer(int argc, char **argv)
1089 char *key_nid = NULL;
1091 struct cYAML *err_rc = NULL, *show_rc = NULL;
1093 const char *const short_options = "k:vh";
1094 const struct option long_options[] = {
1095 { "key_nid", 1, NULL, 'k' },
1096 { "help", 0, NULL, 'h' },
1097 { NULL, 0, NULL, 0 },
1100 while ((opt = getopt_long(argc, argv, short_options,
1101 long_options, NULL)) != -1) {
1107 print_help(peer_cmds, "peer", "add");
1114 rc = lustre_lnet_show_peer(key_nid, -1, &show_rc, &err_rc);
1116 if (rc != LUSTRE_CFG_RC_NO_ERR)
1117 cYAML_print_tree2file(stderr, err_rc);
1119 cYAML_print_tree(show_rc);
1121 cYAML_free_tree(err_rc);
1122 cYAML_free_tree(show_rc);
1127 command_t list[] = {
1128 {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
1129 {"route", jt_route, 0, "route {add | del | show | help}"},
1130 {"net", jt_net, 0, "net {add | del | show | help}"},
1131 {"routing", jt_routing, 0, "routing {show | help}"},
1132 {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
1134 {"import", jt_import, 0, "import {--add | --del | --show | "
1135 "--help} FILE.yaml"},
1136 {"export", jt_export, 0, "export {--help} FILE.yaml"},
1137 {"stats", jt_stats, 0, "stats {show | help}"},
1138 {"peer", jt_peers, 0, "peer {add | del | show | help}"},
1139 {"help", Parser_help, 0, "help"},
1140 {"exit", Parser_quit, 0, "quit"},
1141 {"quit", Parser_quit, 0, "quit"},
1145 int main(int argc, char **argv)
1148 struct cYAML *err_rc = NULL;
1150 rc = lustre_lnet_config_lib_init();
1152 cYAML_build_error(-1, -1, "lnetctl", "startup",
1153 "cannot register LNet device", &err_rc);
1154 cYAML_print_tree2file(stderr, err_rc);
1158 Parser_init("lnetctl > ", list);
1160 rc = Parser_execarg(argc - 1, &argv[1], list);