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, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include "liblnetconfig.h"
55 #define CONFIG_CMD "configure"
56 #define UNCONFIG_CMD "unconfigure"
59 #define SHOW_CMD "show"
61 #define MANAGE_CMD "manage"
63 #define MAX_NUM_IPS 128
65 #define modparam_path "/sys/module/lnet/parameters/"
66 #define gni_nid_path "/proc/cray_xt/"
68 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
72 * lustre_lnet_ip_range_descr
73 * Describes an IP range.
74 * Each octect is an expression
76 struct lustre_lnet_ip_range_descr {
77 struct list_head ipr_entry;
78 struct list_head ipr_expr;
83 * Describes an ip2nets rule. This can be on a list of rules.
85 struct lustre_lnet_ip2nets {
86 struct lnet_dlc_network_descr ip2nets_net;
87 struct list_head ip2nets_ip_ranges;
90 int open_sysfs_file(const char *path, const char *attr, const int mode)
93 char filename[LNET_MAX_STR_LEN];
95 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
98 snprintf(filename, sizeof(filename), "%s%s",
101 fd = open(filename, mode);
106 static int read_sysfs_file(const char *path, const char *attr,
107 void *val, const size_t size, const int nelem)
110 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
112 fd = open_sysfs_file(path, attr, O_RDONLY);
114 return LUSTRE_CFG_RC_NO_MATCH;
116 if (read(fd, val, size * nelem) == -1)
119 rc = LUSTRE_CFG_RC_NO_ERR;
126 static int write_sysfs_file(const char *path, const char *attr,
127 void *val, const size_t size, const int nelem)
130 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
132 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
134 return LUSTRE_CFG_RC_NO_MATCH;
136 if (write(fd, val, size * nelem) == -1)
139 rc = LUSTRE_CFG_RC_NO_ERR;
148 * frees the memory allocated for an intf descriptor.
150 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
155 if (intf_descr->cpt_expr != NULL)
156 cfs_expr_list_free(intf_descr->cpt_expr);
161 * lustre_lnet_add_ip_range
163 * given a string of the format:
164 * <expr.expr.expr.expr> parse each expr into
165 * a lustre_lnet_ip_range_descr structure and insert on the list.
167 * This function is called from
168 * YAML on each ip-range.
169 * As a result of lnetctl command
170 * When building a NID or P2P selection rules
172 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
174 struct lustre_lnet_ip_range_descr *ip_range;
177 ip_range = calloc(1, sizeof(*ip_range));
178 if (ip_range == NULL)
179 return LUSTRE_CFG_RC_OUT_OF_MEM;
181 INIT_LIST_HEAD(&ip_range->ipr_entry);
182 INIT_LIST_HEAD(&ip_range->ipr_expr);
184 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
185 &ip_range->ipr_expr);
187 return LUSTRE_CFG_RC_BAD_PARAM;
189 list_add_tail(&ip_range->ipr_entry, list);
191 return LUSTRE_CFG_RC_NO_ERR;
194 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
196 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
198 struct lnet_dlc_intf_descr *intf_descr = NULL;
200 char intf_string[LNET_MAX_STR_LEN];
202 if (len >= LNET_MAX_STR_LEN)
203 return LUSTRE_CFG_RC_BAD_PARAM;
205 strncpy(intf_string, intf, len);
206 intf_string[len] = '\0';
208 intf_descr = calloc(1, sizeof(*intf_descr));
209 if (intf_descr == NULL)
210 return LUSTRE_CFG_RC_OUT_OF_MEM;
212 INIT_LIST_HEAD(&intf_descr->intf_on_network);
214 intf_name = intf_string;
215 open_sq_bracket = strchr(intf_string, '[');
216 if (open_sq_bracket != NULL) {
217 close_sq_bracket = strchr(intf_string, ']');
218 if (close_sq_bracket == NULL) {
220 return LUSTRE_CFG_RC_BAD_PARAM;
222 rc = cfs_expr_list_parse(open_sq_bracket,
223 strlen(open_sq_bracket), 0, UINT_MAX,
224 &intf_descr->cpt_expr);
227 return LUSTRE_CFG_RC_BAD_PARAM;
229 strncpy(intf_descr->intf_name, intf_name,
230 open_sq_bracket - intf_name);
231 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
233 strcpy(intf_descr->intf_name, intf_name);
234 intf_descr->cpt_expr = NULL;
237 list_add_tail(&intf_descr->intf_on_network, list);
239 return LUSTRE_CFG_RC_NO_ERR;
242 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
244 if (nw_descr != NULL) {
246 INIT_LIST_HEAD(&nw_descr->network_on_rule);
247 INIT_LIST_HEAD(&nw_descr->nw_intflist);
251 static char *get_next_delimiter_in_nid(char *str, char sep)
255 /* first find the '@' */
256 at = strchr(str, '@');
260 /* now that you found the at find the sep after */
261 comma = strchr(at, sep);
265 int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
267 int bracket = 0, num_str = 0;
268 char *strstart, *chptr;
271 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
272 return LUSTRE_CFG_RC_BAD_PARAM;
275 /* comma-separated nidranges -> space-separated nidranges */
279 if (*chptr == '\0') {
280 out[num_str] = strstart;
287 else if (*chptr == ']')
291 snprintf(err_str, LNET_MAX_STR_LEN,
292 "Mismatched brackets in nidstring \"%s\"",
294 return LUSTRE_CFG_RC_BAD_PARAM;
297 if (bracket == 0 && *chptr == ',') {
298 out[num_str] = strstart;
301 strstart = chptr + 1;
308 snprintf(err_str, LNET_MAX_STR_LEN,
309 "Mismatched brackets in nidstring \"%s\"", nidstr);
310 return LUSTRE_CFG_RC_BAD_PARAM;
316 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
317 int max_nids, char *err_str)
319 int rc, num_nids = 0;
320 struct list_head nidlist;
323 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
324 return LUSTRE_CFG_RC_BAD_PARAM;
327 if (strchr(nidstr, '*')) {
328 snprintf(err_str, LNET_MAX_STR_LEN,
329 "asterisk not allowed in nidstring \"%s\"", nidstr);
330 return LUSTRE_CFG_RC_BAD_PARAM;
333 INIT_LIST_HEAD(&nidlist);
334 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
336 snprintf(err_str, LNET_MAX_STR_LEN,
337 "Unable to parse nidlist from: %s\n", nidstr);
338 return LUSTRE_CFG_RC_BAD_PARAM;
341 if (list_empty(&nidlist)) {
342 snprintf(err_str, LNET_MAX_STR_LEN,
343 "\"%s\" does not specify any valid nid lists", nidstr);
344 return LUSTRE_CFG_RC_BAD_PARAM;
347 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
349 if (num_nids == -1) {
350 snprintf(err_str, LNET_MAX_STR_LEN,
351 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
353 return LUSTRE_CFG_RC_BAD_PARAM;
357 snprintf(err_str, LNET_MAX_STR_LEN,
358 "Failed to expand nidstr: %s", strerror(num_nids));
359 return LUSTRE_CFG_RC_OUT_OF_MEM;
363 snprintf(err_str, LNET_MAX_STR_LEN,
364 "\"%s\" did not expand to any nids", nidstr);
365 return LUSTRE_CFG_RC_BAD_PARAM;
371 int lustre_lnet_parse_nids(char *nids, char **array, int size,
375 char *comma = nids, *cur, *entry;
377 int i, len, start = 0, finish = 0;
379 if (nids == NULL || strlen(nids) == 0)
382 /* count the number or new nids, by counting the number of comma*/
384 comma = get_next_delimiter_in_nid(comma, ',');
394 * if the array is not NULL allocate a large enough array to house
395 * the old and new entries
397 new_array = calloc(sizeof(char*),
398 (size > 0) ? size + num_nids : num_nids);
403 /* parse our the new nids and add them to the tail of the array */
406 start = (size > 0) ? size: 0;
407 finish = (size > 0) ? size + num_nids : num_nids;
408 for (i = start; i < finish; i++) {
409 comma = get_next_delimiter_in_nid(comma, ',');
412 * the length of the string to be parsed out is
413 * from cur to end of string. So it's good enough
416 len = strlen(cur) + 1;
418 /* length of the string is comma - cur */
419 len = (comma - cur) + 1;
421 entry = calloc(1, len);
423 finish = i > 0 ? i - 1: 0;
426 memcpy(entry, cur, len - 1);
428 new_array[i] = entry;
435 /* add the old entries in the array and delete the old array*/
436 for (i = 0; i < size; i++)
437 new_array[i] = array[i];
442 *out_array = new_array;
447 for (i = start; i < finish; i++)
457 * <intf>[<expr>], <intf>[<expr>],..
459 int lustre_lnet_parse_interfaces(char *intf_str,
460 struct lnet_dlc_network_descr *nw_descr)
465 char *cur = intf_str, *next = NULL;
466 char *end = intf_str + strlen(intf_str);
468 struct lnet_dlc_intf_descr *intf_descr, *tmp;
470 if (nw_descr == NULL)
471 return LUSTRE_CFG_RC_BAD_PARAM;
474 open_square = strchr(cur, '[');
475 if (open_square != NULL) {
476 close_square = strchr(cur, ']');
477 if (close_square == NULL) {
478 rc = LUSTRE_CFG_RC_BAD_PARAM;
482 comma = strchr(cur, ',');
483 if (comma != NULL && comma > close_square) {
485 len = next - close_square;
491 comma = strchr(cur, ',');
501 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
502 if (rc != LUSTRE_CFG_RC_NO_ERR)
508 return LUSTRE_CFG_RC_NO_ERR;
511 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
513 list_del(&intf_descr->intf_on_network);
514 free_intf_descr(intf_descr);
520 int lustre_lnet_config_lib_init(void)
522 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
525 void lustre_lnet_config_lib_uninit(void)
527 unregister_ioc_dev(LNET_DEV_ID);
530 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
531 int seq_no, struct cYAML **err_rc)
533 struct libcfs_ioctl_data data;
536 char err_str[LNET_MAX_STR_LEN];
538 snprintf(err_str, sizeof(err_str), "\"Success\"");
540 LIBCFS_IOC_INIT(data);
542 /* Reverse logic is used here in order not to change
543 * the lctl utility */
544 data.ioc_flags = load_ni_from_mod ? 0 : 1;
546 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
548 rc = l_ioctl(LNET_DEV_ID, opc, &data);
552 "\"LNet %s error: %s\"", (up) ? "configure" :
553 "unconfigure", strerror(errno));
557 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
558 "lnet", err_str, err_rc);
563 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
564 char *err_str, char *cmd_str)
568 rc = l_ioctl(LNET_DEV_ID, cmd, data);
571 snprintf(err_str, LNET_MAX_STR_LEN,
572 "\"%s peer ni operation failed: %s\"",
573 cmd_str, strerror(errno));
579 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
580 int seq_no, struct cYAML **show_rc,
581 struct cYAML **err_rc)
584 struct lnet_ioctl_ping_data ping;
585 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
586 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
587 struct lnet_process_id id;
588 char err_str[LNET_MAX_STR_LEN] = {0};
589 char *sep, *token, *end;
592 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
596 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
598 data = calloc(1, len);
602 /* create struct cYAML root object */
603 root = cYAML_create_object(NULL, NULL);
607 ping_node = cYAML_create_seq(root, oper);
608 if (ping_node == NULL)
611 /* tokenise each nid in string ping_nids */
612 token = strtok(ping_nids, ",");
615 item = cYAML_create_seq_item(ping_node);
619 if (first_seq == NULL)
622 /* check if '-' is a part of NID, token */
623 sep = strchr(token, '-');
625 id.pid = LNET_PID_ANY;
626 /* if no net is specified, libcfs_str2nid() will assume tcp */
627 id.nid = libcfs_str2nid(token);
628 if (id.nid == LNET_NID_ANY) {
629 snprintf(err_str, sizeof(err_str),
630 "\"cannot parse NID '%s'\"",
632 rc = LUSTRE_CFG_RC_BAD_PARAM;
633 cYAML_build_error(rc, seq_no, MANAGE_CMD,
634 oper, err_str, err_rc);
638 if (token[0] == 'u' || token[0] == 'U')
639 id.pid = (strtoul(&token[1], &end, 0) |
640 (LNET_PID_USERFLAG));
642 id.pid = strtoul(token, &end, 0);
644 /* assuming '-' is part of hostname */
646 id.pid = LNET_PID_ANY;
647 id.nid = libcfs_str2nid(token);
648 if (id.nid == LNET_NID_ANY) {
649 snprintf(err_str, sizeof(err_str),
650 "\"cannot parse NID '%s'\"",
652 rc = LUSTRE_CFG_RC_BAD_PARAM;
653 cYAML_build_error(rc, seq_no, MANAGE_CMD,
659 id.nid = libcfs_str2nid(sep + 1);
660 if (id.nid == LNET_NID_ANY) {
661 snprintf(err_str, sizeof(err_str),
662 "\"cannot parse NID '%s'\"",
664 rc = LUSTRE_CFG_RC_BAD_PARAM;
665 cYAML_build_error(rc, seq_no, MANAGE_CMD,
672 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
673 ping.ping_hdr.ioc_len = sizeof(ping);
675 ping.op_param = param;
676 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
677 ping.ping_buf = data;
679 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
682 sizeof(err_str), "failed to %s %s: %s\n", oper,
683 id.pid == LNET_PID_ANY ?
684 libcfs_nid2str(id.nid) :
685 libcfs_id2str(id), strerror(errno));
686 rc = LUSTRE_CFG_RC_BAD_PARAM;
687 cYAML_build_error(rc, seq_no, MANAGE_CMD,
688 oper, err_str, err_rc);
692 if (cYAML_create_string(item, "primary nid",
693 libcfs_nid2str(ping.ping_id.nid)) == NULL)
696 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
697 "True" : "False") == NULL)
700 tmp = cYAML_create_seq(item, "peer ni");
704 for (i = 0; i < ping.ping_count; i++) {
705 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
708 peer_ni = cYAML_create_seq_item(tmp);
711 memset(buf, 0, sizeof buf);
712 snprintf(buf, sizeof buf, "nid");
713 if (cYAML_create_string(peer_ni, buf,
714 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
720 } while ((token = strtok(NULL, ",")) != NULL);
723 rc = LUSTRE_CFG_RC_NO_ERR;
728 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
729 cYAML_free_tree(root);
730 } else if (show_rc != NULL && *show_rc != NULL) {
731 struct cYAML *show_node;
732 show_node = cYAML_get_object_item(*show_rc, oper);
733 if (show_node != NULL && cYAML_is_sequence(show_node)) {
734 cYAML_insert_child(show_node, first_seq);
737 } else if (show_node == NULL) {
738 cYAML_insert_sibling((*show_rc)->cy_child,
742 cYAML_free_tree(root);
751 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
752 struct cYAML **show_rc, struct cYAML **err_rc)
756 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
757 seq_no, show_rc, err_rc);
761 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
762 struct cYAML **show_rc, struct cYAML **err_rc)
766 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
767 seq_no, show_rc, err_rc);
771 static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
773 struct lustre_lnet_ip_range_descr *ipr, *tmp;
774 struct cfs_expr_list *el, *el_tmp;
776 list_for_each_entry_safe(ipr, tmp,
777 &ip2nets->ip2nets_ip_ranges,
779 list_del(&ipr->ipr_entry);
780 list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
782 list_del(&el->el_link);
783 cfs_expr_list_free(el);
790 * returns an rc < 0 if there is an error
791 * otherwise it returns the number IPs generated
792 * it also has out params: net - network name
794 static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
795 struct lustre_lnet_ip2nets *ip2nets,
796 __u32 *net, char *err_str)
798 struct lustre_lnet_ip_range_descr *ipr;
800 int ip_idx = MAX_NUM_IPS - 1;
801 int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
803 char ip_range[LNET_MAX_STR_LEN];
805 /* separate the two components of the NID */
807 comp2 = strchr(nidstr, '@');
811 "\"cannot parse NID %s\"", nidstr);
812 err_str[LNET_MAX_STR_LEN - 1] = '\0';
813 rc = LUSTRE_CFG_RC_BAD_PARAM;
817 /* length of the expected ip-range */
818 ip_range_len = comp2 - comp1;
819 if (ip_range_len >= LNET_MAX_STR_LEN) {
822 "\"too long ip_range '%s'\"", nidstr);
823 err_str[LNET_MAX_STR_LEN - 1] = '\0';
824 rc = LUSTRE_CFG_RC_BAD_PARAM;
828 /* move beyond '@' */
832 * if the net component is either o2ib or tcp then we expect
833 * an IP range which could only be a single IP address.
836 *net = libcfs_str2net(comp2);
837 net_type = LNET_NETTYP(*net);
838 /* expression support is for o2iblnd and socklnd only */
839 if (net_type != O2IBLND && net_type != SOCKLND)
840 return LUSTRE_CFG_RC_SKIP;
842 strncpy(ip_range, comp1, ip_range_len);
843 ip_range[ip_range_len] = '\0';
844 ip2nets->ip2nets_net.nw_id = *net;
846 rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
847 if (rc != LUSTRE_CFG_RC_NO_ERR) {
850 "\"cannot parse ip_range '%.100s'\"", ip_range);
851 err_str[LNET_MAX_STR_LEN - 1] = '\0';
852 rc = LUSTRE_CFG_RC_BAD_PARAM;
857 * Generate all the IP Addresses from the parsed range. For sanity
858 * we allow only a max of MAX_NUM_IPS nids to be configured for
861 list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
862 ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
865 if (ip_idx == MAX_NUM_IPS - 1) {
866 snprintf(err_str, LNET_MAX_STR_LEN,
867 "no NIDs provided for configuration");
868 err_str[LNET_MAX_STR_LEN - 1] = '\0';
869 rc = LUSTRE_CFG_RC_NO_MATCH;
871 } else if (ip_idx == -1) {
872 rc = LUSTRE_CFG_RC_LAST_ELEM;
881 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
882 bool is_mr, __u32 cmd,
883 char *cmd_type, char *err_str)
885 struct lnet_ioctl_peer_cfg data;
888 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
889 /* When adding a peer we first need to create the peer using the
890 * specified (or implied) primary nid. Then we can add
891 * additional nids to this peer using the primary nid as a key
893 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
894 data.prcfg_mr = is_mr;
895 data.prcfg_prim_nid = nidlist[0];
896 data.prcfg_cfg_nid = LNET_NID_ANY;
898 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
904 /* Add or delete any specified NIs associated with the specified
905 * (or implied) primary nid
907 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
908 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
909 data.prcfg_mr = is_mr;
910 data.prcfg_prim_nid = nidlist[0];
911 data.prcfg_cfg_nid = nidlist[nid_idx];
913 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
919 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
920 /* In the delete case we may have been given just the
921 * primary nid of the peer. This tells us to delete the peer
922 * completely (rather than just delete some of its NIs)
924 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
925 data.prcfg_prim_nid = nidlist[0];
926 data.prcfg_cfg_nid = LNET_NID_ANY;
928 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
934 static int lustre_lnet_handle_peer_ip2nets(char **nid, int num_nids, bool mr,
935 bool range, __u32 cmd,
936 char *cmd_type, char *err_str)
938 __u32 net = LNET_NIDNET(LNET_NID_ANY);
940 int i, j, rc = LUSTRE_CFG_RC_NO_ERR;
941 __u32 ip_list[MAX_NUM_IPS];
942 struct lustre_lnet_ip2nets ip2nets;
943 struct lnet_ioctl_peer_cfg data;
945 lnet_nid_t prim_nid = LNET_NID_ANY;
947 /* initialize all lists */
948 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
949 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
950 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
952 /* each nid entry is an expression */
953 for (i = 0; i < num_nids; i++) {
954 if (!range && i == 0)
955 prim_nid = libcfs_str2nid(nid[0]);
957 prim_nid = LNET_NID_ANY;
959 rc = lnet_expr2ips(nid[i], ip_list, &ip2nets, &net, err_str);
960 if (rc == LUSTRE_CFG_RC_SKIP)
962 else if (rc == LUSTRE_CFG_RC_LAST_ELEM)
964 else if (rc < LUSTRE_CFG_RC_NO_ERR)
969 for (j = MAX_NUM_IPS - 1; j > ip_idx; j--) {
970 peer_nid = LNET_MKNID(net, ip_list[j]);
971 if (peer_nid == LNET_NID_ANY) {
974 "\"cannot parse NID\"");
975 err_str[LNET_MAX_STR_LEN - 1] = '\0';
976 rc = LUSTRE_CFG_RC_BAD_PARAM;
980 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
983 if (prim_nid == LNET_NID_ANY && j == MAX_NUM_IPS - 1) {
985 peer_nid = LNET_NID_ANY;
988 if (!range && num_nids > 1 && i == 0 &&
989 cmd == IOC_LIBCFS_DEL_PEER_NI)
991 else if (!range && i == 0)
992 peer_nid = LNET_NID_ANY;
994 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
996 data.prcfg_prim_nid = prim_nid;
997 data.prcfg_cfg_nid = peer_nid;
1000 * If prim_nid is not provided then the first nid in the
1001 * list becomes the prim_nid. First time round the loop
1002 * use LNET_NID_ANY for the first parameter, then use
1003 * nid[0] as the key nid after wards
1005 rc = dispatch_peer_ni_cmd(cmd, &data, err_str,
1011 * we just deleted the entire peer using the
1012 * primary_nid. So don't bother iterating through
1013 * the rest of the nids
1015 if (prim_nid != LNET_NID_ANY &&
1016 peer_nid == LNET_NID_ANY &&
1017 cmd == IOC_LIBCFS_DEL_PEER_NI)
1021 lustre_lnet_clean_ip2nets(&ip2nets);
1025 lustre_lnet_clean_ip2nets(&ip2nets);
1029 int lustre_lnet_config_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
1030 int num_nids, bool is_mr, int seq_no,
1031 struct cYAML **err_rc)
1033 int rc = LUSTRE_CFG_RC_NO_ERR;
1034 char err_str[LNET_MAX_STR_LEN];
1035 lnet_nid_t *lnet_nidlist2 = NULL;
1039 pnid = libcfs_str2nid(pnidstr);
1040 if (pnid == LNET_NID_ANY) {
1041 snprintf(err_str, LNET_MAX_STR_LEN,
1042 "bad primary NID: '%s'", pnidstr);
1043 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1049 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
1050 if (!lnet_nidlist2) {
1051 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
1052 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1055 lnet_nidlist2[0] = pnid;
1056 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
1060 rc = lustre_lnet_handle_peer_nidlist((pnidstr) ? lnet_nidlist2 :
1063 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
1067 free(lnet_nidlist2);
1069 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
1073 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
1074 bool mr, bool ip2nets, int seq_no,
1075 struct cYAML **err_rc)
1077 int rc = LUSTRE_CFG_RC_NO_ERR;
1078 char err_str[LNET_MAX_STR_LEN] = {0};
1079 char **nid_array = NULL;
1081 snprintf(err_str, sizeof(err_str), "\"Success\"");
1084 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, mr,
1085 ip2nets, IOC_LIBCFS_ADD_PEER_NI,
1091 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
1092 snprintf(err_str, sizeof(err_str),
1093 "bad primary NID: '%s'",
1095 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1101 nid_array = calloc(sizeof(*nid_array), num_nids);
1103 snprintf(err_str, sizeof(err_str),
1105 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1108 nid_array[0] = pnid;
1109 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
1112 rc = lustre_lnet_handle_peer_ip2nets((pnid) ? nid_array : nid,
1113 num_nids, mr, ip2nets,
1114 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
1123 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
1127 int lustre_lnet_del_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
1128 int num_nids, int seq_no,
1129 struct cYAML **err_rc)
1131 int rc = LUSTRE_CFG_RC_NO_ERR;
1132 char err_str[LNET_MAX_STR_LEN];
1133 lnet_nid_t *lnet_nidlist2 = NULL;
1137 snprintf(err_str, sizeof(err_str),
1138 "\"Primary nid is not provided\"");
1139 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1143 pnid = libcfs_str2nid(pnidstr);
1144 if (pnid == LNET_NID_ANY) {
1145 rc = LUSTRE_CFG_RC_BAD_PARAM;
1146 snprintf(err_str, sizeof(err_str),
1147 "bad key NID: '%s'",
1153 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
1154 if (!lnet_nidlist2) {
1155 snprintf(err_str, sizeof(err_str),
1157 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1160 lnet_nidlist2[0] = pnid;
1161 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
1164 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2, num_nids, false,
1165 IOC_LIBCFS_DEL_PEER_NI, DEL_CMD,
1169 free(lnet_nidlist2);
1171 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
1175 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
1176 bool ip2nets, int seq_no, struct cYAML **err_rc)
1178 int rc = LUSTRE_CFG_RC_NO_ERR;
1179 char err_str[LNET_MAX_STR_LEN] = {0};
1180 char **nid_array = NULL;
1182 snprintf(err_str, sizeof(err_str), "\"Success\"");
1185 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, false,
1186 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
1192 snprintf(err_str, sizeof(err_str),
1193 "\"Primary nid is not provided\"");
1194 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1196 } else if (!ip2nets) {
1197 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
1198 rc = LUSTRE_CFG_RC_BAD_PARAM;
1199 snprintf(err_str, sizeof(err_str),
1200 "bad key NID: '%s'",
1207 nid_array = calloc(sizeof(*nid_array), num_nids);
1209 snprintf(err_str, sizeof(err_str),
1211 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1214 nid_array[0] = pnid;
1215 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
1217 rc = lustre_lnet_handle_peer_ip2nets(nid_array, num_nids, false,
1218 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
1227 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
1231 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
1232 int sen, int seq_no, struct cYAML **err_rc,
1235 int rc, num_nids, num_nidstrs, nid_idx, str_idx;
1237 char err_str[LNET_MAX_STR_LEN];
1238 char *nidstrarray[LNET_MAX_STR_LEN];
1239 struct lnet_ioctl_config_data data;
1240 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
1242 if (nw == NULL || nidstr == NULL) {
1243 snprintf(err_str, LNET_MAX_STR_LEN,
1244 "\"missing mandatory parameter:'%s'\"",
1245 (nw == NULL && nidstr == NULL) ? "network, gateway" :
1246 (nw == NULL) ? "network" : "gateway");
1247 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1251 rnet = libcfs_str2net(nw);
1252 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1253 snprintf(err_str, LNET_MAX_STR_LEN,
1254 "\"cannot parse remote net %s\"", nw);
1255 rc = LUSTRE_CFG_RC_BAD_PARAM;
1259 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
1265 for (str_idx = 0; str_idx < num_nidstrs; str_idx++) {
1266 rc = lustre_lnet_parse_nidstr(nidstrarray[str_idx],
1268 LNET_MAX_NIDS_PER_PEER, err_str);
1274 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1275 data.cfg_net = rnet;
1276 if (cmd == LNETCTL_ADD_CMD) {
1277 data.cfg_config_u.cfg_route.rtr_hop = hops;
1278 data.cfg_config_u.cfg_route.rtr_priority = prio;
1279 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
1282 for (nid_idx = 0; nid_idx < num_nids; nid_idx++) {
1283 data.cfg_nid = lnet_nidlist[nid_idx];
1285 if (cmd == LNETCTL_ADD_CMD)
1286 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
1289 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
1292 if (rc != 0 && errno != EEXIST &&
1293 errno != EHOSTUNREACH) {
1295 snprintf(err_str, LNET_MAX_STR_LEN,
1296 "route operation failed: %s",
1304 cYAML_build_error(rc, seq_no,
1305 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
1311 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
1312 int sen, int seq_no, struct cYAML **err_rc)
1315 char err_str[LNET_MAX_STR_LEN];
1318 hops = LNET_UNDEFINED_HOPS;
1319 } else if (hops < 1 || hops > 255) {
1320 snprintf(err_str, LNET_MAX_STR_LEN,
1321 "\"invalid hop count %d, must be between 1 and 255\"",
1323 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1329 } else if (prio < 0) {
1330 snprintf(err_str, LNET_MAX_STR_LEN,
1331 "\"invalid priority %d, must be greater than 0\"",
1333 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1339 } else if (sen < 1) {
1340 snprintf(err_str, LNET_MAX_STR_LEN,
1341 "\"invalid health sensitivity %d, must be 1 or greater\"",
1343 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1347 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
1348 err_rc, LNETCTL_ADD_CMD);
1350 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1355 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
1356 struct cYAML **err_rc)
1358 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
1362 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1363 int seq_no, struct cYAML **show_rc,
1364 struct cYAML **err_rc, bool backup)
1366 struct lnet_ioctl_config_data data;
1367 lnet_nid_t gateway_nid;
1368 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1370 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1372 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1373 struct cYAML *first_seq = NULL;
1374 char err_str[LNET_MAX_STR_LEN];
1377 snprintf(err_str, sizeof(err_str),
1378 "\"out of memory\"");
1381 net = libcfs_str2net(nw);
1382 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1385 "\"cannot parse net '%s'\"", nw);
1386 rc = LUSTRE_CFG_RC_BAD_PARAM;
1391 /* show all routes without filtering on net */
1392 net = LNET_NIDNET(LNET_NID_ANY);
1396 gateway_nid = libcfs_str2nid(gw);
1397 if (gateway_nid == LNET_NID_ANY) {
1400 "\"cannot parse gateway NID '%s'\"", gw);
1401 rc = LUSTRE_CFG_RC_BAD_PARAM;
1405 /* show all routes with out filtering on gateway */
1406 gateway_nid = LNET_NID_ANY;
1408 if ((hops < 1 && hops != -1) || hops > 255) {
1411 "\"invalid hop count %d, must be between 0 and 256\"",
1413 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1417 /* create struct cYAML root object */
1418 root = cYAML_create_object(NULL, NULL);
1422 route = cYAML_create_seq(root, "route");
1427 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1430 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1436 /* filter on provided data */
1437 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1438 net != data.cfg_net)
1441 if (gateway_nid != LNET_NID_ANY &&
1442 gateway_nid != data.cfg_nid)
1446 hops != data.cfg_config_u.cfg_route.rtr_hop)
1450 prio != data.cfg_config_u.cfg_route.rtr_priority)
1453 /* default rc to -1 incase we hit the goto */
1457 item = cYAML_create_seq_item(route);
1461 if (first_seq == NULL)
1464 if (cYAML_create_string(item, "net",
1465 libcfs_net2str(data.cfg_net)) == NULL)
1468 if (cYAML_create_string(item, "gateway",
1469 libcfs_nid2str(data.cfg_nid)) == NULL)
1473 if (cYAML_create_number(item, "hop",
1474 (int) data.cfg_config_u.
1475 cfg_route.rtr_hop) ==
1479 if (cYAML_create_number(item, "priority",
1481 cfg_route.rtr_priority) == NULL)
1484 if (cYAML_create_number(item, "health_sensitivity",
1486 cfg_route.rtr_sensitivity) == NULL)
1490 cYAML_create_string(item, "state",
1491 data.cfg_config_u.cfg_route.
1493 "up" : "down") == NULL)
1498 /* print output iff show_rc is not provided */
1499 if (show_rc == NULL)
1500 cYAML_print_tree(root);
1502 if (l_errno != ENOENT) {
1505 "\"cannot get routes: %s\"",
1510 rc = LUSTRE_CFG_RC_NO_ERR;
1512 snprintf(err_str, sizeof(err_str), "\"success\"");
1514 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1515 cYAML_free_tree(root);
1516 } else if (show_rc != NULL && *show_rc != NULL) {
1517 struct cYAML *show_node;
1518 /* find the route node, if one doesn't exist then
1519 * insert one. Otherwise add to the one there
1521 show_node = cYAML_get_object_item(*show_rc, "route");
1522 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1523 cYAML_insert_child(show_node, first_seq);
1526 } else if (show_node == NULL) {
1527 cYAML_insert_sibling((*show_rc)->cy_child,
1531 cYAML_free_tree(root);
1537 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1542 static int socket_intf_query(int request, char *intf,
1548 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1549 return LUSTRE_CFG_RC_BAD_PARAM;
1551 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1553 return LUSTRE_CFG_RC_BAD_PARAM;
1555 strcpy(ifr->ifr_name, intf);
1556 rc = ioctl(sockfd, request, ifr);
1558 rc = LUSTRE_CFG_RC_BAD_PARAM;
1565 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1570 memset(&ifr, 0, sizeof(ifr));
1571 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1573 return LUSTRE_CFG_RC_BAD_PARAM;
1575 if ((ifr.ifr_flags & IFF_UP) == 0)
1576 return LUSTRE_CFG_RC_BAD_PARAM;
1578 memset(&ifr, 0, sizeof(ifr));
1579 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1581 return LUSTRE_CFG_RC_BAD_PARAM;
1583 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1584 *ip = bswap_32(*ip);
1586 return LUSTRE_CFG_RC_NO_ERR;
1590 * for each interface in the array of interfaces find the IP address of
1591 * that interface, create its nid and add it to an array of NIDs.
1592 * Stop if any of the interfaces is down
1594 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1595 lnet_nid_t **nids, __u32 *nnids,
1596 char *err_str, size_t str_len)
1598 int i = 0, count = 0, rc;
1599 struct lnet_dlc_intf_descr *intf;
1600 char val[LNET_MAX_STR_LEN];
1607 if (nw == NULL || nids == NULL) {
1608 snprintf(err_str, str_len,
1609 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1610 err_str[str_len - 1] = '\0';
1611 return LUSTRE_CFG_RC_BAD_PARAM;
1614 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1617 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1621 *nids = calloc(count, sizeof(lnet_nid_t));
1622 if (*nids == NULL) {
1623 snprintf(err_str, str_len,
1624 "\"out of memory\"");
1625 err_str[str_len - 1] = '\0';
1626 return LUSTRE_CFG_RC_OUT_OF_MEM;
1629 * special case the GNI interface since it doesn't have an IP
1630 * address. The assumption is that there can only be one GNI
1631 * interface in the system. No interface name is provided.
1633 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1634 rc = read_sysfs_file(gni_nid_path, "nid", val,
1637 snprintf(err_str, str_len,
1638 "\"cannot read gni nid\"");
1639 err_str[str_len - 1] = '\0';
1642 gni_num = atoi(val);
1644 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1649 /* look at the other interfaces */
1650 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1651 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1652 /* handle LNDs with numeric interface name */
1653 num = strtoul(intf->intf_name, &endp, 0);
1654 if (endp == intf->intf_name || *endp != '\0') {
1655 rc = LUSTRE_CFG_RC_BAD_PARAM;
1656 snprintf(err_str, str_len,
1657 "\"couldn't query intf %s\"",
1659 err_str[str_len - 1] = '\0';
1662 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1665 /* handle LNDs with ip interface name */
1666 rc = lustre_lnet_queryip(intf, &ip);
1667 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1668 snprintf(err_str, str_len,
1669 "\"couldn't query intf %s\"",
1671 err_str[str_len - 1] = '\0';
1674 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1691 * called repeatedly until a match or no more ip range
1693 * ip_range expression
1694 * interface list with all the interface names.
1695 * all the interfaces in the system.
1697 * try to match the ip_range expr to one of the interfaces' IPs in
1698 * the system. If we hit a patch for an interface. Check if that
1699 * interface name is in the list.
1701 * If there are more than one interface in the list, then make sure
1702 * that the IPs for all of these interfaces match the ip ranges
1705 * for each interface in intf_list
1706 * look up the intf name in ifa
1707 * if not there then no match
1708 * check ip obtained from ifa against a match to any of the
1710 * If no match, then fail
1712 * The result is that all the interfaces have to match.
1714 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1715 struct list_head *intf_list,
1716 struct list_head *ip_ranges)
1720 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1721 struct ifaddrs *ifaddr = ifa;
1722 struct lustre_lnet_ip_range_descr *ip_range;
1726 * if there are no explicit interfaces, and no ip ranges, then
1727 * configure the first tcp interface we encounter.
1729 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1730 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1731 if (ifaddr->ifa_addr == NULL)
1734 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1737 family = ifaddr->ifa_addr->sa_family;
1738 if (family == AF_INET &&
1739 strcmp(ifaddr->ifa_name, "lo") != 0) {
1740 rc = lustre_lnet_add_intf_descr
1741 (intf_list, ifaddr->ifa_name,
1742 strlen(ifaddr->ifa_name));
1744 if (rc != LUSTRE_CFG_RC_NO_ERR)
1747 return LUSTRE_CFG_RC_MATCH;
1750 return LUSTRE_CFG_RC_NO_MATCH;
1754 * First interface which matches an IP pattern will be used
1756 if (list_empty(intf_list)) {
1758 * no interfaces provided in the rule, but an ip range is
1759 * provided, so try and match an interface to the ip
1762 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1763 if (ifaddr->ifa_addr == NULL)
1766 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1769 family = ifaddr->ifa_addr->sa_family;
1770 if (family == AF_INET) {
1771 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1774 list_for_each_entry(ip_range, ip_ranges,
1776 rc = cfs_ip_addr_match(bswap_32(ip),
1777 &ip_range->ipr_expr);
1781 rc = lustre_lnet_add_intf_descr
1782 (intf_list, ifaddr->ifa_name,
1783 strlen(ifaddr->ifa_name));
1785 if (rc != LUSTRE_CFG_RC_NO_ERR)
1791 if (!list_empty(intf_list))
1792 return LUSTRE_CFG_RC_MATCH;
1794 return LUSTRE_CFG_RC_NO_MATCH;
1798 * If an interface is explicitly specified the ip-range might or
1799 * might not be specified. if specified the interface needs to match the
1800 * ip-range. If no ip-range then the interfaces are
1801 * automatically matched if they are all up.
1802 * If > 1 interfaces all the interfaces must match for the NI to
1805 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1806 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1807 if (ifaddr->ifa_addr == NULL)
1810 family = ifaddr->ifa_addr->sa_family;
1811 if (family == AF_INET &&
1812 strcmp(intf_descr->intf_name,
1813 ifaddr->ifa_name) == 0)
1817 if (ifaddr == NULL) {
1818 list_del(&intf_descr->intf_on_network);
1819 free_intf_descr(intf_descr);
1823 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1824 list_del(&intf_descr->intf_on_network);
1825 free_intf_descr(intf_descr);
1829 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1832 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1833 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1839 /* no match for this interface */
1840 list_del(&intf_descr->intf_on_network);
1841 free_intf_descr(intf_descr);
1845 return LUSTRE_CFG_RC_MATCH;
1848 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1849 lnet_nid_t **nids, __u32 *nnids,
1850 char *err_str, size_t str_len)
1852 struct ifaddrs *ifa;
1853 int rc = LUSTRE_CFG_RC_NO_ERR;
1855 rc = getifaddrs(&ifa);
1857 snprintf(err_str, str_len,
1858 "\"failed to get interface addresses: %d\"", -errno);
1859 err_str[str_len - 1] = '\0';
1863 rc = lustre_lnet_match_ip_to_intf(ifa,
1864 &ip2nets->ip2nets_net.nw_intflist,
1865 &ip2nets->ip2nets_ip_ranges);
1866 if (rc != LUSTRE_CFG_RC_MATCH) {
1867 snprintf(err_str, str_len,
1868 "\"couldn't match ip to existing interfaces\"");
1869 err_str[str_len - 1] = '\0';
1874 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1875 err_str, sizeof(err_str));
1876 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1887 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1888 struct lnet_ioctl_config_lnd_tunables *tunables,
1889 struct cfs_expr_list *global_cpts,
1890 lnet_nid_t *nids, char *err_str)
1893 struct lnet_ioctl_config_ni *conf;
1894 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1895 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1898 struct lnet_dlc_intf_descr *intf_descr;
1900 struct cfs_expr_list *cpt_expr;
1902 list_for_each_entry(intf_descr, intf_list,
1904 if (tunables != NULL)
1905 len = sizeof(struct lnet_ioctl_config_ni) +
1906 sizeof(struct lnet_ioctl_config_lnd_tunables);
1908 len = sizeof(struct lnet_ioctl_config_ni);
1910 data = calloc(1, len);
1912 return LUSTRE_CFG_RC_OUT_OF_MEM;
1913 conf = (struct lnet_ioctl_config_ni*) data;
1914 if (tunables != NULL)
1915 tun = (struct lnet_ioctl_config_lnd_tunables*)
1918 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1919 conf->lic_cfg_hdr.ioc_len = len;
1920 conf->lic_nid = nids[i];
1921 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1924 if (intf_descr->cpt_expr != NULL)
1925 cpt_expr = intf_descr->cpt_expr;
1926 else if (global_cpts != NULL)
1927 cpt_expr = global_cpts;
1931 if (cpt_expr != NULL) {
1932 count = cfs_expr_list_values(cpt_expr,
1933 LNET_MAX_SHOW_NUM_CPT,
1936 memcpy(conf->lic_cpts, cpt_array,
1937 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1946 conf->lic_ncpts = count;
1948 if (tunables != NULL)
1949 memcpy(tun, tunables, sizeof(*tunables));
1951 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1956 "\"cannot add network: %s\"", strerror(errno));
1964 return LUSTRE_CFG_RC_NO_ERR;
1968 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1969 struct lnet_ioctl_config_lnd_tunables *tunables,
1970 struct cfs_expr_list *global_cpts,
1971 int seq_no, struct cYAML **err_rc)
1973 lnet_nid_t *nids = NULL;
1976 char err_str[LNET_MAX_STR_LEN];
1978 snprintf(err_str, sizeof(err_str), "\"success\"");
1983 "\"incomplete ip2nets information\"");
1984 rc = LUSTRE_CFG_RC_BAD_PARAM;
1989 * call below function to resolve the rules into a list of nids.
1990 * The memory is allocated in that function then freed here when
1991 * it's no longer needed.
1993 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1995 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1998 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1999 snprintf(err_str, sizeof(err_str),
2000 "\"no interfaces match ip2nets rules\"");
2004 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
2005 tunables, global_cpts, nids,
2012 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
2016 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
2017 struct cfs_expr_list *global_cpts,
2019 struct lnet_ioctl_config_lnd_tunables *tunables,
2020 int seq_no, struct cYAML **err_rc)
2023 struct lnet_ioctl_config_ni *conf;
2024 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
2025 char buf[LNET_MAX_STR_LEN];
2026 int rc = LUSTRE_CFG_RC_NO_ERR;
2027 char err_str[LNET_MAX_STR_LEN];
2028 lnet_nid_t *nids = NULL;
2032 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2035 snprintf(err_str, sizeof(err_str), "\"success\"");
2037 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
2038 (list_empty(&nw_descr->nw_intflist) &&
2039 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
2042 "\"missing mandatory parameters in NI config: '%s'\"",
2043 (nw_descr == NULL) ? "network , interface" :
2044 (nw_descr->nw_id == 0) ? "network" : "interface");
2045 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2049 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
2052 "\"ip2net string too long %d\"",
2053 (int)strlen(ip2net));
2054 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2058 if (ip2net != NULL) {
2059 if (tunables != NULL)
2060 len = sizeof(struct lnet_ioctl_config_ni) +
2061 sizeof(struct lnet_ioctl_config_lnd_tunables);
2063 len = sizeof(struct lnet_ioctl_config_ni);
2064 data = calloc(1, len);
2066 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2069 conf = (struct lnet_ioctl_config_ni*) data;
2070 if (tunables != NULL)
2071 tun = (struct lnet_ioctl_config_lnd_tunables*)
2072 (data + sizeof(*conf));
2074 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
2075 conf->lic_cfg_hdr.ioc_len = len;
2076 strncpy(conf->lic_legacy_ip2nets, ip2net,
2079 if (global_cpts != NULL) {
2080 count = cfs_expr_list_values(global_cpts,
2081 LNET_MAX_SHOW_NUM_CPT,
2084 memcpy(conf->lic_cpts, cpt_array,
2085 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
2094 conf->lic_ncpts = count;
2096 if (tunables != NULL)
2097 memcpy(tun, tunables, sizeof(*tunables));
2099 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
2104 "\"cannot add network: %s\"", strerror(errno));
2111 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
2112 rc = LUSTRE_CFG_RC_NO_ERR;
2116 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2119 "\"cannot parse net '%s'\"",
2120 libcfs_net2str(nw_descr->nw_id));
2121 rc = LUSTRE_CFG_RC_BAD_PARAM;
2126 * special case the GNI since no interface name is expected
2128 if (list_empty(&nw_descr->nw_intflist) &&
2129 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
2132 "\"no interface name provided\"");
2133 rc = LUSTRE_CFG_RC_BAD_PARAM;
2137 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2138 err_str, sizeof(err_str));
2140 rc = LUSTRE_CFG_RC_BAD_PARAM;
2144 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
2145 tunables, global_cpts, nids,
2149 if (nw_descr != NULL) {
2150 list_for_each_entry_safe(intf_descr, tmp,
2151 &nw_descr->nw_intflist,
2153 list_del(&intf_descr->intf_on_network);
2154 free_intf_descr(intf_descr);
2158 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
2169 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
2170 int seq_no, struct cYAML **err_rc)
2172 struct lnet_ioctl_config_ni data;
2173 int rc = LUSTRE_CFG_RC_NO_ERR, i;
2174 char err_str[LNET_MAX_STR_LEN];
2175 lnet_nid_t *nids = NULL;
2177 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2179 snprintf(err_str, sizeof(err_str), "\"success\"");
2181 if (nw_descr == NULL || nw_descr->nw_id == 0) {
2184 "\"missing mandatory parameter in deleting NI: '%s'\"",
2185 (nw_descr == NULL) ? "network , interface" :
2186 (nw_descr->nw_id == 0) ? "network" : "interface");
2187 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2191 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2192 return LUSTRE_CFG_RC_NO_ERR;
2194 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2197 "\"cannot parse net '%s'\"",
2198 libcfs_net2str(nw_descr->nw_id));
2199 rc = LUSTRE_CFG_RC_BAD_PARAM;
2203 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2204 err_str, sizeof(err_str));
2206 rc = LUSTRE_CFG_RC_BAD_PARAM;
2211 * no interfaces just the nw_id is specified
2214 nids = calloc(1, sizeof(*nids));
2216 snprintf(err_str, sizeof(err_str),
2217 "\"out of memory\"");
2218 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2221 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2225 for (i = 0; i < nnids; i++) {
2226 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2227 data.lic_nid = nids[i];
2229 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2234 "\"cannot del network: %s\"", strerror(errno));
2238 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2240 list_del(&intf_descr->intf_on_network);
2241 free_intf_descr(intf_descr);
2245 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2254 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2255 enum lnet_health_type type, char *name,
2256 int seq_no, struct cYAML **err_rc)
2258 struct lnet_ioctl_reset_health_cfg data;
2259 int rc = LUSTRE_CFG_RC_NO_ERR;
2260 char err_str[LNET_MAX_STR_LEN];
2262 snprintf(err_str, sizeof(err_str), "\"success\"");
2264 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2265 data.rh_type = type;
2267 data.rh_value = value;
2270 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2274 sizeof(err_str), "Can not configure health value: %s",
2278 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2283 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2284 struct cYAML **err_rc)
2288 nid = libcfs_str2nid(ni_nid);
2291 return lustre_lnet_config_healthv(value, all, nid,
2292 LNET_HEALTH_TYPE_LOCAL_NI,
2293 "ni healthv", seq_no, err_rc);
2296 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2297 int seq_no, struct cYAML **err_rc)
2301 nid = libcfs_str2nid(lpni_nid);
2304 return lustre_lnet_config_healthv(value, all, nid,
2305 LNET_HEALTH_TYPE_PEER_NI,
2306 "peer_ni healthv", seq_no, err_rc);
2310 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2311 struct lnet_ioctl_comm_count *counts)
2313 if (cYAML_create_number(yaml, "put",
2314 counts->ico_put_count)
2317 if (cYAML_create_number(yaml, "get",
2318 counts->ico_get_count)
2321 if (cYAML_create_number(yaml, "reply",
2322 counts->ico_reply_count)
2325 if (cYAML_create_number(yaml, "ack",
2326 counts->ico_ack_count)
2329 if (cYAML_create_number(yaml, "hello",
2330 counts->ico_hello_count)
2337 static struct lnet_ioctl_comm_count *
2338 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2341 return &msg_stats->im_send_stats;
2343 return &msg_stats->im_recv_stats;
2345 return &msg_stats->im_drop_stats;
2350 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2351 struct cYAML **show_rc, struct cYAML **err_rc,
2355 struct lnet_ioctl_config_ni *ni_data;
2356 struct lnet_ioctl_config_lnd_tunables *lnd;
2357 struct lnet_ioctl_element_stats *stats;
2358 struct lnet_ioctl_element_msg_stats msg_stats;
2359 struct lnet_ioctl_local_ni_hstats hstats;
2360 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2361 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2362 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2364 struct cYAML *root = NULL, *tunables = NULL,
2365 *net_node = NULL, *interfaces = NULL,
2366 *item = NULL, *first_seq = NULL,
2367 *tmp = NULL, *statistics = NULL,
2369 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2370 char str_buf[str_buf_len];
2372 char err_str[LNET_MAX_STR_LEN];
2373 bool exist = false, new_net = true;
2375 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2377 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2379 buf = calloc(1, buf_size);
2383 ni_data = (struct lnet_ioctl_config_ni *)buf;
2386 net = libcfs_str2net(nw);
2387 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2390 "\"cannot parse net '%s'\"", nw);
2391 rc = LUSTRE_CFG_RC_BAD_PARAM;
2396 root = cYAML_create_object(NULL, NULL);
2400 net_node = cYAML_create_seq(root, "net");
2401 if (net_node == NULL)
2407 memset(buf, 0, buf_size);
2409 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2411 * set the ioc_len to the proper value since INIT assumes
2414 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2415 ni_data->lic_idx = i;
2417 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2423 rc_net = LNET_NIDNET(ni_data->lic_nid);
2425 /* filter on provided data */
2426 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2430 /* if we're backing up don't store lo */
2431 if (backup && LNET_NETTYP(rc_net) == LOLND)
2434 /* default rc to -1 in case we hit the goto */
2438 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2439 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2440 (ni_data->lic_bulk + sizeof(*stats));
2442 if (rc_net != prev_net) {
2449 if (!cYAML_create_string(net_node, "net type",
2450 libcfs_net2str(rc_net)))
2453 tmp = cYAML_create_seq(net_node, "local NI(s)");
2459 /* create the tree to be printed. */
2460 item = cYAML_create_seq_item(tmp);
2464 if (first_seq == NULL)
2468 cYAML_create_string(item, "nid",
2469 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2473 cYAML_create_string(item,
2475 (ni_data->lic_status ==
2476 LNET_NI_STATUS_UP) ?
2477 "up" : "down") == NULL)
2480 /* don't add interfaces unless there is at least one
2482 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2483 interfaces = cYAML_create_object(item, "interfaces");
2484 if (interfaces == NULL)
2487 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2488 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2490 sizeof(str_buf), "%d", j);
2491 if (cYAML_create_string(interfaces,
2493 ni_data->lic_ni_intf[j]) ==
2505 goto continue_without_msg_stats;
2507 statistics = cYAML_create_object(item, "statistics");
2508 if (statistics == NULL)
2511 if (cYAML_create_number(statistics, "send_count",
2512 stats->iel_send_count)
2516 if (cYAML_create_number(statistics, "recv_count",
2517 stats->iel_recv_count)
2521 if (cYAML_create_number(statistics, "drop_count",
2522 stats->iel_drop_count)
2527 goto continue_without_msg_stats;
2529 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2530 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2531 msg_stats.im_idx = i;
2533 rc = l_ioctl(LNET_DEV_ID,
2534 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2538 goto continue_without_msg_stats;
2541 for (k = 0; k < 3; k++) {
2542 struct lnet_ioctl_comm_count *counts;
2543 struct cYAML *msg_statistics = NULL;
2545 msg_statistics = cYAML_create_object(item,
2546 (char *)gmsg_stat_names[k]);
2547 if (msg_statistics == NULL)
2550 counts = get_counts(&msg_stats, k);
2554 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2559 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2560 hstats.hlni_nid = ni_data->lic_nid;
2561 /* grab health stats */
2562 rc = l_ioctl(LNET_DEV_ID,
2563 IOC_LIBCFS_GET_LOCAL_HSTATS,
2567 goto continue_without_msg_stats;
2569 yhstats = cYAML_create_object(item, "health stats");
2572 if (cYAML_create_number(yhstats, "health value",
2573 hstats.hlni_health_value)
2576 if (cYAML_create_number(yhstats, "interrupts",
2577 hstats.hlni_local_interrupt)
2580 if (cYAML_create_number(yhstats, "dropped",
2581 hstats.hlni_local_dropped)
2584 if (cYAML_create_number(yhstats, "aborted",
2585 hstats.hlni_local_aborted)
2588 if (cYAML_create_number(yhstats, "no route",
2589 hstats.hlni_local_no_route)
2592 if (cYAML_create_number(yhstats, "timeouts",
2593 hstats.hlni_local_timeout)
2596 if (cYAML_create_number(yhstats, "error",
2597 hstats.hlni_local_error)
2601 continue_without_msg_stats:
2602 tunables = cYAML_create_object(item, "tunables");
2606 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2607 if (rc != LUSTRE_CFG_RC_NO_ERR)
2610 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2612 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2613 rc != LUSTRE_CFG_RC_NO_MATCH)
2616 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2617 tunables = cYAML_create_object(item,
2619 if (tunables == NULL)
2624 cYAML_create_number(item, "dev cpt",
2625 ni_data->lic_dev_cpt) == NULL)
2629 cYAML_create_number(item, "tcp bonding",
2630 ni_data->lic_tcp_bonding)
2634 /* out put the CPTs in the format: "[x,x,x,...]" */
2636 limit = str_buf + str_buf_len - 3;
2637 pos += scnprintf(pos, limit - pos, "\"[");
2638 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2639 j < ni_data->lic_ncpts &&
2641 pos += scnprintf(pos, limit - pos,
2642 "%d", ni_data->lic_cpts[j]);
2643 if ((j + 1) < ni_data->lic_ncpts)
2644 pos += scnprintf(pos, limit - pos, ",");
2646 snprintf(pos, 3, "]\"");
2648 if (ni_data->lic_ncpts >= 1 &&
2649 cYAML_create_string(item, "CPT",
2655 /* Print out the net information only if show_rc is not provided */
2656 if (show_rc == NULL)
2657 cYAML_print_tree(root);
2659 if (l_errno != ENOENT) {
2662 "\"cannot get networks: %s\"",
2667 rc = LUSTRE_CFG_RC_NO_ERR;
2669 snprintf(err_str, sizeof(err_str), "\"success\"");
2671 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2672 cYAML_free_tree(root);
2673 } else if (show_rc != NULL && *show_rc != NULL) {
2674 struct cYAML *show_node;
2675 /* find the net node, if one doesn't exist
2676 * then insert one. Otherwise add to the one there
2678 show_node = cYAML_get_object_item(*show_rc, "net");
2679 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2680 cYAML_insert_child(show_node, first_seq);
2683 } else if (show_node == NULL) {
2684 cYAML_insert_sibling((*show_rc)->cy_child,
2688 cYAML_free_tree(root);
2694 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2699 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2701 struct lnet_ioctl_config_data data;
2702 int rc = LUSTRE_CFG_RC_NO_ERR;
2703 char err_str[LNET_MAX_STR_LEN];
2705 snprintf(err_str, sizeof(err_str), "\"success\"");
2707 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2708 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2710 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2715 "\"cannot %s routing %s\"",
2716 (enable) ? "enable" : "disable", strerror(errno));
2721 cYAML_build_error(rc, seq_no,
2722 (enable) ? ADD_CMD : DEL_CMD,
2723 "routing", err_str, err_rc);
2728 int ioctl_set_value(__u32 val, int ioc, char *name,
2729 int seq_no, struct cYAML **err_rc)
2731 struct lnet_ioctl_set_value data;
2732 int rc = LUSTRE_CFG_RC_NO_ERR;
2733 char err_str[LNET_MAX_STR_LEN];
2735 snprintf(err_str, sizeof(err_str), "\"success\"");
2737 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2738 data.sv_value = val;
2740 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2745 "\"cannot configure %s to %d: %s\"", name,
2746 val, strerror(errno));
2749 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2754 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2756 int rc = LUSTRE_CFG_RC_NO_ERR;
2757 char err_str[LNET_MAX_STR_LEN];
2758 char val[LNET_MAX_STR_LEN];
2760 snprintf(err_str, sizeof(err_str), "\"success\"");
2762 snprintf(val, sizeof(val), "%d", intrv);
2764 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2765 1, strlen(val) + 1);
2767 snprintf(err_str, sizeof(err_str),
2768 "\"cannot configure recovery interval: %s\"",
2771 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2776 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2778 int rc = LUSTRE_CFG_RC_NO_ERR;
2779 char err_str[LNET_MAX_STR_LEN];
2780 char val[LNET_MAX_STR_LEN];
2782 snprintf(err_str, sizeof(err_str), "\"success\"");
2784 snprintf(val, sizeof(val), "%d", sen);
2786 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2787 1, strlen(val) + 1);
2789 snprintf(err_str, sizeof(err_str),
2790 "\"cannot configure router health sensitivity: %s\"",
2793 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2798 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2800 int rc = LUSTRE_CFG_RC_NO_ERR;
2801 char err_str[LNET_MAX_STR_LEN];
2802 char val[LNET_MAX_STR_LEN];
2804 snprintf(err_str, sizeof(err_str), "\"success\"");
2806 snprintf(val, sizeof(val), "%d", sen);
2808 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2809 1, strlen(val) + 1);
2811 snprintf(err_str, sizeof(err_str),
2812 "\"cannot configure health sensitivity: %s\"",
2815 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2820 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2822 int rc = LUSTRE_CFG_RC_NO_ERR;
2823 char err_str[LNET_MAX_STR_LEN];
2824 char val[LNET_MAX_STR_LEN];
2826 snprintf(err_str, sizeof(err_str), "\"success\"");
2828 snprintf(val, sizeof(val), "%d", timeout);
2830 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2831 1, strlen(val) + 1);
2833 snprintf(err_str, sizeof(err_str),
2834 "\"cannot configure transaction timeout: %s\"",
2837 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2842 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2844 int rc = LUSTRE_CFG_RC_NO_ERR;
2845 char err_str[LNET_MAX_STR_LEN];
2846 char val[LNET_MAX_STR_LEN];
2848 snprintf(err_str, sizeof(err_str), "\"success\"");
2850 snprintf(val, sizeof(val), "%d", count);
2852 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2853 1, strlen(val) + 1);
2855 snprintf(err_str, sizeof(err_str),
2856 "\"cannot configure retry count: %s\"",
2859 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2864 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2866 int rc = LUSTRE_CFG_RC_NO_ERR;
2867 char err_str[LNET_MAX_STR_LEN];
2868 char val[LNET_MAX_STR_LEN];
2870 snprintf(err_str, sizeof(err_str), "\"success\"");
2872 snprintf(val, sizeof(val), "%d", max);
2874 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2875 1, strlen(val) + 1);
2877 snprintf(err_str, sizeof(err_str),
2878 "\"cannot configure max interfaces: %s\"",
2881 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2886 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2888 int rc = LUSTRE_CFG_RC_NO_ERR;
2889 char err_str[LNET_MAX_STR_LEN];
2890 char val[LNET_MAX_STR_LEN];
2892 snprintf(err_str, sizeof(err_str), "\"success\"");
2894 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2896 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2897 1, strlen(val) + 1);
2899 snprintf(err_str, sizeof(err_str),
2900 "\"cannot configure discovery: %s\"",
2903 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2909 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2910 struct cYAML **err_rc)
2912 int rc = LUSTRE_CFG_RC_NO_ERR;
2913 char err_str[LNET_MAX_STR_LEN];
2914 char val[LNET_MAX_STR_LEN];
2916 snprintf(err_str, sizeof(err_str), "\"success\"");
2918 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2920 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2921 1, strlen(val) + 1);
2923 snprintf(err_str, sizeof(err_str),
2924 "\"cannot configure drop asym route: %s\"",
2927 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2934 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2936 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2937 "numa_range", seq_no, err_rc);
2940 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2941 struct cYAML **err_rc)
2943 struct lnet_ioctl_config_data data;
2944 int rc = LUSTRE_CFG_RC_NO_ERR;
2945 char err_str[LNET_MAX_STR_LEN];
2947 snprintf(err_str, sizeof(err_str), "\"success\"");
2949 /* -1 indicates to ignore changes to this field */
2950 if (tiny < -1 || small < -1 || large < -1) {
2953 "\"tiny, small and large must be >= 0\"");
2954 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2958 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2959 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2960 data.cfg_config_u.cfg_buffers.buf_small = small;
2961 data.cfg_config_u.cfg_buffers.buf_large = large;
2963 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2968 "\"cannot configure buffers: %s\"", strerror(errno));
2973 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2978 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2979 struct cYAML **err_rc, bool backup)
2981 struct lnet_ioctl_config_data *data;
2982 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2983 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2986 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2987 int buf_count[LNET_NRBPOOLS] = {0};
2988 struct cYAML *root = NULL, *pools_node = NULL,
2989 *type_node = NULL, *item = NULL, *cpt = NULL,
2990 *first_seq = NULL, *buffers = NULL;
2992 char err_str[LNET_MAX_STR_LEN];
2993 char node_name[LNET_MAX_STR_LEN];
2996 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2998 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
3002 data = (struct lnet_ioctl_config_data *)buf;
3004 root = cYAML_create_object(NULL, NULL);
3009 pools_node = cYAML_create_object(root, "routing");
3011 pools_node = cYAML_create_seq(root, "routing");
3012 if (pools_node == NULL)
3016 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
3017 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
3018 sizeof(struct lnet_ioctl_pool_cfg);
3019 data->cfg_count = i;
3021 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
3029 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
3032 goto calculate_buffers;
3034 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
3035 item = cYAML_create_seq_item(pools_node);
3039 if (first_seq == NULL)
3042 cpt = cYAML_create_object(item, node_name);
3047 /* create the tree and print */
3048 for (j = 0; j < LNET_NRBPOOLS; j++) {
3050 type_node = cYAML_create_object(cpt, pools[j]);
3051 if (type_node == NULL)
3055 cYAML_create_number(type_node, "npages",
3056 pool_cfg->pl_pools[j].pl_npages)
3060 cYAML_create_number(type_node, "nbuffers",
3061 pool_cfg->pl_pools[j].
3062 pl_nbuffers) == NULL)
3065 cYAML_create_number(type_node, "credits",
3066 pool_cfg->pl_pools[j].
3067 pl_credits) == NULL)
3070 cYAML_create_number(type_node, "mincredits",
3071 pool_cfg->pl_pools[j].
3072 pl_mincredits) == NULL)
3074 /* keep track of the total count for each of the
3075 * tiny, small and large buffers */
3076 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
3080 if (pool_cfg != NULL) {
3082 if (cYAML_create_number(pools_node, "enable",
3083 pool_cfg->pl_routing) ==
3087 goto add_buffer_section;
3090 item = cYAML_create_seq_item(pools_node);
3094 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
3100 /* create a buffers entry in the show. This is necessary so that
3101 * if the YAML output is used to configure a node, the buffer
3102 * configuration takes hold */
3103 buffers = cYAML_create_object(root, "buffers");
3104 if (buffers == NULL)
3107 for (i = 0; i < LNET_NRBPOOLS; i++) {
3108 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3112 if (show_rc == NULL)
3113 cYAML_print_tree(root);
3115 if (l_errno != ENOENT) {
3118 "\"cannot get routing information: %s\"",
3123 rc = LUSTRE_CFG_RC_NO_ERR;
3125 snprintf(err_str, sizeof(err_str), "\"success\"");
3126 rc = LUSTRE_CFG_RC_NO_ERR;
3130 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3131 cYAML_free_tree(root);
3132 } else if (show_rc != NULL && *show_rc != NULL) {
3133 struct cYAML *routing_node;
3134 /* there should exist only one routing block and one
3135 * buffers block. If there already exists a previous one
3136 * then don't add another */
3137 routing_node = cYAML_get_object_item(*show_rc, "routing");
3138 if (routing_node == NULL) {
3139 cYAML_insert_sibling((*show_rc)->cy_child,
3143 cYAML_free_tree(root);
3149 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3154 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3155 struct cYAML **show_rc, struct cYAML **err_rc,
3159 * TODO: This function is changing in a future patch to accommodate
3160 * PEER_LIST and proper filtering on any nid of the peer
3162 struct lnet_ioctl_peer_cfg peer_info;
3163 struct lnet_peer_ni_credit_info *lpni_cri;
3164 struct lnet_ioctl_element_stats *lpni_stats;
3165 struct lnet_ioctl_element_msg_stats *msg_stats;
3166 struct lnet_ioctl_peer_ni_hstats *hstats;
3168 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3173 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3174 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3175 *msg_statistics = NULL, *statistics = NULL,
3177 char err_str[LNET_MAX_STR_LEN];
3178 struct lnet_process_id *list = NULL;
3183 snprintf(err_str, sizeof(err_str),
3184 "\"out of memory\"");
3186 /* create struct cYAML root object */
3187 root = cYAML_create_object(NULL, NULL);
3191 peer_root = cYAML_create_seq(root, "peer");
3192 if (peer_root == NULL)
3196 size = count * sizeof(struct lnet_process_id);
3197 list = malloc(size);
3203 list[0].nid = libcfs_str2nid(knid);
3207 memset(&peer_info, 0, sizeof(peer_info));
3208 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3209 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3210 peer_info.prcfg_size = size;
3211 peer_info.prcfg_bulk = list;
3214 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3216 count = peer_info.prcfg_count;
3220 if (l_errno != E2BIG) {
3223 "\"cannot get peer list: %s\"",
3229 size = peer_info.prcfg_size;
3230 list = malloc(size);
3239 data = malloc(size);
3245 for (i = 0; i < count; i++) {
3247 memset(&peer_info, 0, sizeof(peer_info));
3248 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3249 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3250 peer_info.prcfg_prim_nid = list[i].nid;
3251 peer_info.prcfg_size = size;
3252 peer_info.prcfg_bulk = data;
3255 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3260 if (l_errno != E2BIG) {
3263 "\"cannot get peer information: %s\"",
3269 size = peer_info.prcfg_size;
3270 data = malloc(size);
3278 peer = cYAML_create_seq_item(peer_root);
3282 if (first_seq == NULL)
3285 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3286 if (cYAML_create_string(peer, "primary nid",
3287 libcfs_nid2str(pnid))
3290 if (cYAML_create_string(peer, "Multi-Rail",
3291 peer_info.prcfg_mr ? "True" : "False")
3295 * print out the state of the peer only if details are
3300 cYAML_create_number(peer, "peer state",
3301 peer_info.prcfg_state)
3306 tmp = cYAML_create_seq(peer, "peer ni");
3311 for (j = 0; j < peer_info.prcfg_count; j++) {
3313 lpni_cri = (void*)nidp + sizeof(nidp);
3314 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3315 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3316 hstats = (void *)msg_stats + sizeof(*msg_stats);
3317 lpni_data = (void *)hstats + sizeof(*hstats);
3319 peer_ni = cYAML_create_seq_item(tmp);
3320 if (peer_ni == NULL)
3323 if (cYAML_create_string(peer_ni, "nid",
3324 libcfs_nid2str(*nidp))
3331 if (cYAML_create_string(peer_ni, "state",
3332 lpni_cri->cr_aliveness)
3339 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3340 lpni_cri->cr_ni_peer_tx_credits)
3344 if (cYAML_create_number(peer_ni, "available_tx_credits",
3345 lpni_cri->cr_peer_tx_credits)
3349 if (cYAML_create_number(peer_ni, "min_tx_credits",
3350 lpni_cri->cr_peer_min_tx_credits)
3354 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3355 lpni_cri->cr_peer_tx_qnob)
3359 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3360 lpni_cri->cr_peer_rtr_credits)
3364 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3365 lpni_cri->cr_peer_min_rtr_credits)
3369 if (cYAML_create_number(peer_ni, "refcount",
3370 lpni_cri->cr_refcount) == NULL)
3373 statistics = cYAML_create_object(peer_ni, "statistics");
3374 if (statistics == NULL)
3377 if (cYAML_create_number(statistics, "send_count",
3378 lpni_stats->iel_send_count)
3382 if (cYAML_create_number(statistics, "recv_count",
3383 lpni_stats->iel_recv_count)
3387 if (cYAML_create_number(statistics, "drop_count",
3388 lpni_stats->iel_drop_count)
3395 for (k = 0; k < 3; k++) {
3396 struct lnet_ioctl_comm_count *counts;
3398 msg_statistics = cYAML_create_object(peer_ni,
3399 (char *) gmsg_stat_names[k]);
3400 if (msg_statistics == NULL)
3403 counts = get_counts(msg_stats, k);
3407 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3412 yhstats = cYAML_create_object(peer_ni, "health stats");
3415 if (cYAML_create_number(yhstats, "health value",
3416 hstats->hlpni_health_value)
3419 if (cYAML_create_number(yhstats, "dropped",
3420 hstats->hlpni_remote_dropped)
3423 if (cYAML_create_number(yhstats, "timeout",
3424 hstats->hlpni_remote_timeout)
3427 if (cYAML_create_number(yhstats, "error",
3428 hstats->hlpni_remote_error)
3431 if (cYAML_create_number(yhstats, "network timeout",
3432 hstats->hlpni_network_timeout)
3438 /* print output iff show_rc is not provided */
3439 if (show_rc == NULL)
3440 cYAML_print_tree(root);
3442 snprintf(err_str, sizeof(err_str), "\"success\"");
3443 rc = LUSTRE_CFG_RC_NO_ERR;
3448 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3449 cYAML_free_tree(root);
3450 } else if (show_rc != NULL && *show_rc != NULL) {
3451 struct cYAML *show_node;
3452 /* find the peer node, if one doesn't exist then
3453 * insert one. Otherwise add to the one there
3455 show_node = cYAML_get_object_item(*show_rc,
3457 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3458 cYAML_insert_child(show_node, first_seq);
3461 } else if (show_node == NULL) {
3462 cYAML_insert_sibling((*show_rc)->cy_child,
3466 cYAML_free_tree(root);
3472 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3478 int lustre_lnet_list_peer(int seq_no,
3479 struct cYAML **show_rc, struct cYAML **err_rc)
3481 struct lnet_ioctl_peer_cfg peer_info;
3482 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3487 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3488 char err_str[LNET_MAX_STR_LEN];
3489 struct lnet_process_id *list = NULL;
3491 snprintf(err_str, sizeof(err_str),
3492 "\"out of memory\"");
3494 memset(&peer_info, 0, sizeof(peer_info));
3496 /* create struct cYAML root object */
3497 root = cYAML_create_object(NULL, NULL);
3501 list_root = cYAML_create_seq(root, "peer list");
3502 if (list_root == NULL)
3506 size = count * sizeof(struct lnet_process_id);
3507 list = malloc(size);
3513 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3514 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3515 peer_info.prcfg_size = size;
3516 peer_info.prcfg_bulk = list;
3519 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3520 count = peer_info.prcfg_count;
3524 if (l_errno != E2BIG) {
3527 "\"cannot get peer list: %s\"",
3533 size = peer_info.prcfg_size;
3534 list = malloc(size);
3541 /* count is now the actual number of ids in the list. */
3542 for (i = 0; i < count; i++) {
3543 if (cYAML_create_string(list_root, "nid",
3544 libcfs_nid2str(list[i].nid))
3549 /* print output iff show_rc is not provided */
3550 if (show_rc == NULL)
3551 cYAML_print_tree(root);
3553 snprintf(err_str, sizeof(err_str), "\"success\"");
3554 rc = LUSTRE_CFG_RC_NO_ERR;
3559 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3560 cYAML_free_tree(root);
3561 } else if (show_rc != NULL && *show_rc != NULL) {
3562 struct cYAML *show_node;
3563 /* find the peer node, if one doesn't exist then
3564 * insert one. Otherwise add to the one there
3566 show_node = cYAML_get_object_item(*show_rc,
3568 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3569 cYAML_insert_child(show_node, first_seq);
3572 } else if (show_node == NULL) {
3573 cYAML_insert_sibling((*show_rc)->cy_child,
3577 cYAML_free_tree(root);
3583 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3589 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3592 struct cYAML *show_node;
3594 show_node = cYAML_get_object_item(show_rc, "global");
3595 if (show_node != NULL)
3596 cYAML_insert_sibling(show_node->cy_child,
3599 cYAML_insert_sibling(show_rc->cy_child,
3604 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3605 char *name, __u32 value,
3606 struct cYAML **show_rc,
3607 struct cYAML **err_rc, int err)
3609 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3610 struct cYAML *root = NULL, *global = NULL;
3617 root = cYAML_create_object(NULL, NULL);
3621 global = cYAML_create_object(root, "global");
3625 if (cYAML_create_number(global, name,
3629 if (show_rc == NULL)
3630 cYAML_print_tree(root);
3632 snprintf(err_str, err_len, "\"success\"");
3634 rc = LUSTRE_CFG_RC_NO_ERR;
3637 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3638 cYAML_free_tree(root);
3639 } else if (show_rc != NULL && *show_rc != NULL) {
3640 add_to_global(*show_rc, global, root);
3645 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3650 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3651 struct cYAML **show_rc,
3652 struct cYAML **err_rc)
3654 struct lnet_ioctl_set_value data;
3657 char err_str[LNET_MAX_STR_LEN];
3659 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3661 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3663 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3668 "\"cannot get %s: %s\"",
3669 name, strerror(l_errno));
3672 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3673 data.sv_value, show_rc, err_rc, l_errno);
3676 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3677 struct cYAML **err_rc)
3679 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3680 char val[LNET_MAX_STR_LEN];
3681 int intrv = -1, l_errno = 0;
3682 char err_str[LNET_MAX_STR_LEN];
3684 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3686 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3690 snprintf(err_str, sizeof(err_str),
3691 "\"cannot get recovery interval: %d\"", rc);
3696 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3697 "recovery_interval", intrv, show_rc,
3701 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3702 struct cYAML **err_rc)
3704 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3705 char val[LNET_MAX_STR_LEN];
3706 int sen = -1, l_errno = 0;
3707 char err_str[LNET_MAX_STR_LEN];
3709 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3711 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3715 snprintf(err_str, sizeof(err_str),
3716 "\"cannot get health sensitivity: %d\"", rc);
3721 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3722 "health_sensitivity", sen, show_rc,
3726 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3727 struct cYAML **err_rc)
3729 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3730 char val[LNET_MAX_STR_LEN];
3731 int sen = -1, l_errno = 0;
3732 char err_str[LNET_MAX_STR_LEN];
3734 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3736 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3740 snprintf(err_str, sizeof(err_str),
3741 "\"cannot get router sensitivity percentage: %d\"", rc);
3746 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3747 "router_sensitivity", sen, show_rc,
3751 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3752 struct cYAML **err_rc)
3754 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3755 char val[LNET_MAX_STR_LEN];
3756 int tto = -1, l_errno = 0;
3757 char err_str[LNET_MAX_STR_LEN];
3759 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3761 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3765 snprintf(err_str, sizeof(err_str),
3766 "\"cannot get transaction timeout: %d\"", rc);
3771 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3772 "transaction_timeout", tto, show_rc,
3776 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3777 struct cYAML **err_rc)
3779 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3780 char val[LNET_MAX_STR_LEN];
3781 int retry_count = -1, l_errno = 0;
3782 char err_str[LNET_MAX_STR_LEN];
3784 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3786 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3790 snprintf(err_str, sizeof(err_str),
3791 "\"cannot get retry count: %d\"", rc);
3793 retry_count = atoi(val);
3796 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3797 "retry_count", retry_count, show_rc,
3801 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3802 struct cYAML **show_rc, struct cYAML **err_rc)
3804 struct lnet_ioctl_recovery_list nid_list;
3805 struct cYAML *root = NULL, *nids = NULL;
3807 char err_str[LNET_MAX_STR_LEN];
3809 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3811 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3812 nid_list.rlst_type = type;
3814 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3820 if (nid_list.rlst_num_nids == 0)
3823 root = cYAML_create_object(NULL, NULL);
3827 nids = cYAML_create_object(root, name);
3833 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3834 char nidenum[LNET_MAX_STR_LEN];
3835 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3836 if (!cYAML_create_string(nids, nidenum,
3837 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3841 snprintf(err_str, sizeof(err_str), "success\n");
3846 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3847 cYAML_free_tree(root);
3848 } else if (show_rc != NULL && *show_rc != NULL) {
3849 struct cYAML *show_node;
3850 /* find the net node, if one doesn't exist
3851 * then insert one. Otherwise add to the one there
3853 show_node = cYAML_get_object_item(*show_rc, name);
3854 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3855 cYAML_insert_child(show_node, nids);
3858 } else if (show_node == NULL) {
3859 cYAML_insert_sibling((*show_rc)->cy_child,
3863 cYAML_free_tree(root);
3869 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3874 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3875 struct cYAML **err_rc)
3877 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3878 seq_no, show_rc, err_rc);
3881 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3882 struct cYAML **err_rc)
3884 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3885 seq_no, show_rc, err_rc);
3888 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3889 struct cYAML **err_rc)
3891 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3892 char val[LNET_MAX_STR_LEN];
3893 int max_intf = -1, l_errno = 0;
3894 char err_str[LNET_MAX_STR_LEN];
3896 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3898 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3902 snprintf(err_str, sizeof(err_str),
3903 "\"cannot get max interfaces: %d\"", rc);
3905 max_intf = atoi(val);
3908 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3909 "max_intf", max_intf, show_rc,
3913 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3914 struct cYAML **err_rc)
3916 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3917 char val[LNET_MAX_STR_LEN];
3918 int discovery = -1, l_errno = 0;
3919 char err_str[LNET_MAX_STR_LEN];
3921 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3923 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3927 snprintf(err_str, sizeof(err_str),
3928 "\"cannot get discovery setting: %d\"", rc);
3931 * The kernel stores a discovery disabled value. User space
3932 * shows whether discovery is enabled. So the value must be
3935 discovery = !atoi(val);
3938 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3939 "discovery", discovery, show_rc,
3943 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3944 struct cYAML **err_rc)
3946 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3947 char val[LNET_MAX_STR_LEN];
3948 int drop_asym_route = -1, l_errno = 0;
3949 char err_str[LNET_MAX_STR_LEN];
3951 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3953 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3957 snprintf(err_str, sizeof(err_str),
3958 "\"cannot get drop asym route setting: %d\"", rc);
3960 drop_asym_route = atoi(val);
3963 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3964 "drop_asym_route", drop_asym_route,
3965 show_rc, err_rc, l_errno);
3968 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3969 struct cYAML **err_rc)
3971 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3972 "numa_range", show_rc, err_rc);
3975 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3976 struct cYAML **err_rc)
3978 struct lnet_ioctl_lnet_stats data;
3979 struct lnet_counters *cntrs;
3982 char err_str[LNET_MAX_STR_LEN];
3983 struct cYAML *root = NULL, *stats = NULL;
3985 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3987 LIBCFS_IOC_INIT_V2(data, st_hdr);
3989 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3994 "\"cannot get lnet statistics: %s\"",
4000 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4002 cntrs = &data.st_cntrs;
4004 root = cYAML_create_object(NULL, NULL);
4008 stats = cYAML_create_object(root, "statistics");
4012 if (!cYAML_create_number(stats, "msgs_alloc",
4013 cntrs->lct_common.lcc_msgs_alloc))
4016 if (!cYAML_create_number(stats, "msgs_max",
4017 cntrs->lct_common.lcc_msgs_max))
4020 if (!cYAML_create_number(stats, "rst_alloc",
4021 cntrs->lct_health.lch_rst_alloc))
4024 if (!cYAML_create_number(stats, "errors",
4025 cntrs->lct_common.lcc_errors))
4028 if (!cYAML_create_number(stats, "send_count",
4029 cntrs->lct_common.lcc_send_count))
4032 if (!cYAML_create_number(stats, "resend_count",
4033 cntrs->lct_health.lch_resend_count))
4036 if (!cYAML_create_number(stats, "response_timeout_count",
4037 cntrs->lct_health.lch_response_timeout_count))
4040 if (!cYAML_create_number(stats, "local_interrupt_count",
4041 cntrs->lct_health.lch_local_interrupt_count))
4044 if (!cYAML_create_number(stats, "local_dropped_count",
4045 cntrs->lct_health.lch_local_dropped_count))
4048 if (!cYAML_create_number(stats, "local_aborted_count",
4049 cntrs->lct_health.lch_local_aborted_count))
4052 if (!cYAML_create_number(stats, "local_no_route_count",
4053 cntrs->lct_health.lch_local_no_route_count))
4056 if (!cYAML_create_number(stats, "local_timeout_count",
4057 cntrs->lct_health.lch_local_timeout_count))
4060 if (!cYAML_create_number(stats, "local_error_count",
4061 cntrs->lct_health.lch_local_error_count))
4064 if (!cYAML_create_number(stats, "remote_dropped_count",
4065 cntrs->lct_health.lch_remote_dropped_count))
4068 if (!cYAML_create_number(stats, "remote_error_count",
4069 cntrs->lct_health.lch_remote_error_count))
4072 if (!cYAML_create_number(stats, "remote_timeout_count",
4073 cntrs->lct_health.lch_remote_timeout_count))
4076 if (!cYAML_create_number(stats, "network_timeout_count",
4077 cntrs->lct_health.lch_network_timeout_count))
4080 if (!cYAML_create_number(stats, "recv_count",
4081 cntrs->lct_common.lcc_recv_count))
4084 if (!cYAML_create_number(stats, "route_count",
4085 cntrs->lct_common.lcc_route_count))
4088 if (!cYAML_create_number(stats, "drop_count",
4089 cntrs->lct_common.lcc_drop_count))
4092 if (!cYAML_create_number(stats, "send_length",
4093 cntrs->lct_common.lcc_send_length))
4096 if (!cYAML_create_number(stats, "recv_length",
4097 cntrs->lct_common.lcc_recv_length))
4100 if (!cYAML_create_number(stats, "route_length",
4101 cntrs->lct_common.lcc_route_length))
4104 if (!cYAML_create_number(stats, "drop_length",
4105 cntrs->lct_common.lcc_drop_length))
4109 cYAML_print_tree(root);
4111 snprintf(err_str, sizeof(err_str), "\"success\"");
4112 rc = LUSTRE_CFG_RC_NO_ERR;
4114 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4115 cYAML_free_tree(root);
4116 } else if (show_rc != NULL && *show_rc != NULL) {
4117 cYAML_insert_sibling((*show_rc)->cy_child,
4124 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4129 typedef int (*cmd_handler_t)(struct cYAML *tree,
4130 struct cYAML **show_rc,
4131 struct cYAML **err_rc);
4133 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4134 struct cYAML **err_rc)
4136 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4138 net = cYAML_get_object_item(tree, "net");
4139 gw = cYAML_get_object_item(tree, "gateway");
4140 hop = cYAML_get_object_item(tree, "hop");
4141 prio = cYAML_get_object_item(tree, "priority");
4142 sen = cYAML_get_object_item(tree, "health_sensitivity");
4143 seq_no = cYAML_get_object_item(tree, "seq_no");
4145 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4146 (gw) ? gw->cy_valuestring : NULL,
4147 (hop) ? hop->cy_valueint : -1,
4148 (prio) ? prio->cy_valueint : -1,
4149 (sen) ? sen->cy_valueint : -1,
4150 (seq_no) ? seq_no->cy_valueint : -1,
4156 * 0: <intf_name>['['<expr>']']
4157 * 1: <intf_name>['['<expr>']']
4159 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4160 struct lnet_dlc_network_descr *nw_descr)
4162 struct cYAML *child = NULL;
4163 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4164 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4166 if (intf_tree == NULL || nw_descr == NULL)
4167 return LUSTRE_CFG_RC_BAD_PARAM;
4169 /* now grab all the interfaces and their cpts */
4170 child = intf_tree->cy_child;
4171 while (child != NULL) {
4172 if (child->cy_valuestring == NULL) {
4173 child = child->cy_next;
4177 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4180 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4181 child->cy_valuestring,
4182 strlen(child->cy_valuestring));
4183 if (rc != LUSTRE_CFG_RC_NO_ERR)
4187 child = child->cy_next;
4191 return LUSTRE_CFG_RC_MISSING_PARAM;
4196 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4198 list_del(&intf_descr->intf_on_network);
4199 free_intf_descr(intf_descr);
4206 yaml_extract_cmn_tunables(struct cYAML *tree,
4207 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4208 struct cfs_expr_list **global_cpts)
4210 struct cYAML *tun, *item, *smp;
4213 tun = cYAML_get_object_item(tree, "tunables");
4215 item = cYAML_get_object_item(tun, "peer_timeout");
4217 tunables->lct_peer_timeout = item->cy_valueint;
4218 item = cYAML_get_object_item(tun, "peer_credits");
4220 tunables->lct_peer_tx_credits = item->cy_valueint;
4221 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4223 tunables->lct_peer_rtr_credits = item->cy_valueint;
4224 item = cYAML_get_object_item(tun, "credits");
4226 tunables->lct_max_tx_credits = item->cy_valueint;
4227 smp = cYAML_get_object_item(tun, "CPT");
4229 rc = cfs_expr_list_parse(smp->cy_valuestring,
4230 strlen(smp->cy_valuestring),
4231 0, UINT_MAX, global_cpts);
4233 *global_cpts = NULL;
4243 yaml_extract_tunables(struct cYAML *tree,
4244 struct lnet_ioctl_config_lnd_tunables *tunables,
4245 struct cfs_expr_list **global_cpts,
4250 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4256 lustre_yaml_extract_lnd_tunables(tree, net_type,
4264 * - net type: <net>[<NUM>]
4266 * - nid: <ip>@<net>[<NUM>]
4269 * 0: <intf_name>['['<expr>']']
4270 * 1: <intf_name>['['<expr>']']
4272 * peer_timeout: <NUM>
4273 * peer_credits: <NUM>
4274 * peer_buffer_credits: <NUM>
4277 * peercredits_hiw: <NUM>
4278 * map_on_demand: <NUM>
4279 * concurrent_sends: <NUM>
4280 * fmr_pool_size: <NUM>
4281 * fmr_flush_trigger: <NUM>
4284 * At least one interface is required. If no interfaces are provided the
4285 * network interface can not be configured.
4287 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4288 struct cYAML **err_rc)
4290 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4292 int num_entries = 0, rc;
4293 struct lnet_dlc_network_descr nw_descr;
4294 struct cfs_expr_list *global_cpts = NULL;
4295 struct lnet_ioctl_config_lnd_tunables tunables;
4298 memset(&tunables, 0, sizeof(tunables));
4300 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4301 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4303 ip2net = cYAML_get_object_item(tree, "ip2net");
4304 net = cYAML_get_object_item(tree, "net type");
4306 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4308 nw_descr.nw_id = LOLND;
4311 * if neither net nor ip2nets are present, then we can not
4312 * configure the network.
4314 if (!net && !ip2net)
4315 return LUSTRE_CFG_RC_MISSING_PARAM;
4317 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4318 if (local_nis == NULL)
4319 return LUSTRE_CFG_RC_MISSING_PARAM;
4321 if (!cYAML_is_sequence(local_nis))
4322 return LUSTRE_CFG_RC_BAD_PARAM;
4324 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4325 intf = cYAML_get_object_item(item, "interfaces");
4328 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4329 if (num_entries <= 0) {
4330 cYAML_build_error(num_entries, -1, "ni", "add",
4331 "bad interface list",
4333 return LUSTRE_CFG_RC_BAD_PARAM;
4337 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4338 LNET_NETTYP(nw_descr.nw_id));
4339 seq_no = cYAML_get_object_item(tree, "seq_no");
4341 rc = lustre_lnet_config_ni(&nw_descr,
4343 (ip2net) ? ip2net->cy_valuestring : NULL,
4344 (found) ? &tunables: NULL,
4345 (seq_no) ? seq_no->cy_valueint : -1,
4348 if (global_cpts != NULL)
4349 cfs_expr_list_free(global_cpts);
4356 * - net-spec: <tcp|o2ib|gni>[NUM]
4358 * 0: <intf name>['['<expr>']']
4359 * 1: <intf name>['['<expr>']']
4361 * 0: <expr.expr.expr.expr>
4362 * 1: <expr.expr.expr.expr>
4364 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4365 struct cYAML **show_rc,
4366 struct cYAML **err_rc)
4368 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4370 struct lustre_lnet_ip2nets ip2nets;
4371 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4373 int rc = LUSTRE_CFG_RC_NO_ERR;
4374 struct cfs_expr_list *global_cpts = NULL;
4375 struct cfs_expr_list *el, *el_tmp;
4376 struct lnet_ioctl_config_lnd_tunables tunables;
4377 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4380 memset(&tunables, 0, sizeof(tunables));
4382 /* initialize all lists */
4383 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4384 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4385 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4387 net = cYAML_get_object_item(tree, "net-spec");
4389 return LUSTRE_CFG_RC_BAD_PARAM;
4391 if (net != NULL && net->cy_valuestring == NULL)
4392 return LUSTRE_CFG_RC_BAD_PARAM;
4394 /* assign the network id */
4395 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4396 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4397 return LUSTRE_CFG_RC_BAD_PARAM;
4399 seq_no = cYAML_get_object_item(tree, "seq_no");
4401 intf = cYAML_get_object_item(tree, "interfaces");
4403 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4405 return LUSTRE_CFG_RC_BAD_PARAM;
4408 ip_range = cYAML_get_object_item(tree, "ip-range");
4409 if (ip_range != NULL) {
4410 item = ip_range->cy_child;
4411 while (item != NULL) {
4412 if (item->cy_valuestring == NULL) {
4413 item = item->cy_next;
4417 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4418 item->cy_valuestring);
4420 if (rc != LUSTRE_CFG_RC_NO_ERR)
4423 item = item->cy_next;
4427 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4428 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4430 rc = lustre_lnet_config_ip2nets(&ip2nets,
4431 (found) ? &tunables : NULL,
4433 (seq_no) ? seq_no->cy_valueint : -1,
4437 * don't stop because there was no match. Continue processing the
4438 * rest of the rules. If non-match then nothing is configured
4440 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4441 rc = LUSTRE_CFG_RC_NO_ERR;
4443 list_for_each_entry_safe(intf_descr, intf_tmp,
4444 &ip2nets.ip2nets_net.nw_intflist,
4446 list_del(&intf_descr->intf_on_network);
4447 free_intf_descr(intf_descr);
4450 list_for_each_entry_safe(ip_range_descr, tmp,
4451 &ip2nets.ip2nets_ip_ranges,
4453 list_del(&ip_range_descr->ipr_entry);
4454 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4456 list_del(&el->el_link);
4457 cfs_expr_list_free(el);
4459 free(ip_range_descr);
4465 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4466 struct cYAML **err_rc)
4468 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4470 int num_entries, rc;
4471 struct lnet_dlc_network_descr nw_descr;
4473 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4474 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4476 net = cYAML_get_object_item(tree, "net type");
4478 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4480 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4481 if (local_nis == NULL)
4482 return LUSTRE_CFG_RC_MISSING_PARAM;
4484 if (!cYAML_is_sequence(local_nis))
4485 return LUSTRE_CFG_RC_BAD_PARAM;
4487 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4488 intf = cYAML_get_object_item(item, "interfaces");
4491 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4492 if (num_entries <= 0) {
4493 cYAML_build_error(num_entries, -1, "ni", "add",
4494 "bad interface list",
4496 return LUSTRE_CFG_RC_BAD_PARAM;
4500 seq_no = cYAML_get_object_item(tree, "seq_no");
4502 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4503 (seq_no) ? seq_no->cy_valueint : -1,
4509 /* Create a nidstring parseable by the nidstrings library from the nid
4510 * information encoded in the CYAML structure.
4511 * NOTE: Caller must free memory allocated to nidstr
4513 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4514 char *prim_nid, int cmd)
4516 int num_strs = 0, rc;
4517 size_t buf_size, buf_pos, nidstr_len = 0;
4519 struct cYAML *child = NULL, *entry = NULL;
4521 if (cYAML_is_sequence(nids_entry)) {
4522 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4523 entry = cYAML_get_object_item(child, "nid");
4524 /* don't count an empty entry */
4525 if (!entry || !entry->cy_valuestring)
4529 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4530 if (cmd == LNETCTL_DEL_CMD) {
4532 * primary nid is present in the list of
4533 * nids so that means we want to delete
4534 * the entire peer, so no need to go
4535 * further. Just delete the entire peer.
4537 return LUSTRE_CFG_RC_NO_ERR;
4544 * + 1 for the space separating each string, and
4545 * accounts for the terminating null char
4547 nidstr_len += strlen(entry->cy_valuestring) + 1;
4552 if (num_strs == 0 && !prim_nid)
4553 return LUSTRE_CFG_RC_MISSING_PARAM;
4554 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4555 return LUSTRE_CFG_RC_NO_ERR;
4557 buffer = malloc(nidstr_len);
4559 return LUSTRE_CFG_RC_OUT_OF_MEM;
4561 /* now grab all the nids */
4564 buf_size = nidstr_len;
4566 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4567 entry = cYAML_get_object_item(child, "nid");
4568 if (!entry || !entry->cy_valuestring)
4572 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4576 rc = snprintf(buffer + buf_pos, buf_size, " ");
4577 buf_pos += (rc < buf_size) ? rc : buf_size;
4578 buf_size = nidstr_len - buf_pos;
4581 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4582 entry->cy_valuestring);
4583 buf_pos += (rc < buf_size) ? rc : buf_size;
4584 buf_size = nidstr_len - buf_pos;
4589 return LUSTRE_CFG_RC_NO_ERR;
4592 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4593 struct cYAML **err_rc, int cmd)
4595 int rc, num_nids = 0, seqn;
4597 char *nidstr = NULL, *prim_nidstr;
4598 char err_str[LNET_MAX_STR_LEN];
4599 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4600 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4602 seq_no = cYAML_get_object_item(tree, "seq_no");
4603 seqn = seq_no ? seq_no->cy_valueint : -1;
4605 prim_nid = cYAML_get_object_item(tree, "primary nid");
4606 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4608 peer_nis = cYAML_get_object_item(tree, "peer ni");
4609 if (!(prim_nid || peer_nis)) {
4610 rc = LUSTRE_CFG_RC_BAD_PARAM;
4611 snprintf(err_str, LNET_MAX_STR_LEN,
4612 "Neither \"primary nid\" nor \"peer ni\" are defined");
4616 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4617 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4618 snprintf(err_str, LNET_MAX_STR_LEN,
4619 "No nids defined in YAML block");
4621 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4622 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4624 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4625 snprintf(err_str, LNET_MAX_STR_LEN,
4626 "Unrecognized error %d", rc);
4632 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4633 LNET_MAX_NIDS_PER_PEER,
4641 if (cmd == LNETCTL_ADD_CMD) {
4642 mr = cYAML_get_object_item(tree, "Multi-Rail");
4644 if (mr && mr->cy_valuestring) {
4645 if (strcmp(mr->cy_valuestring, "False") == 0)
4647 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4648 rc = LUSTRE_CFG_RC_BAD_PARAM;
4649 snprintf(err_str, LNET_MAX_STR_LEN,
4650 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4651 mr->cy_valuestring);
4656 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4657 num_nids, mr_value, seqn,
4660 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4661 num_nids, seqn, err_rc);
4667 if (rc != LUSTRE_CFG_RC_NO_ERR)
4668 cYAML_build_error(rc, seqn, "peer",
4669 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4675 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4676 struct cYAML **err_rc)
4678 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4681 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4682 struct cYAML **err_rc)
4684 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4687 static int handle_yaml_config_buffers(struct cYAML *tree,
4688 struct cYAML **show_rc,
4689 struct cYAML **err_rc)
4692 struct cYAML *tiny, *small, *large, *seq_no;
4694 tiny = cYAML_get_object_item(tree, "tiny");
4695 small = cYAML_get_object_item(tree, "small");
4696 large = cYAML_get_object_item(tree, "large");
4697 seq_no = cYAML_get_object_item(tree, "seq_no");
4699 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4700 (small) ? small->cy_valueint : -1,
4701 (large) ? large->cy_valueint : -1,
4702 (seq_no) ? seq_no->cy_valueint : -1,
4708 static int handle_yaml_config_routing(struct cYAML *tree,
4709 struct cYAML **show_rc,
4710 struct cYAML **err_rc)
4712 int rc = LUSTRE_CFG_RC_NO_ERR;
4713 struct cYAML *seq_no, *enable;
4715 seq_no = cYAML_get_object_item(tree, "seq_no");
4716 enable = cYAML_get_object_item(tree, "enable");
4719 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4721 seq_no->cy_valueint : -1,
4728 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4729 struct cYAML **err_rc)
4733 struct cYAML *seq_no;
4735 net = cYAML_get_object_item(tree, "net");
4736 gw = cYAML_get_object_item(tree, "gateway");
4737 seq_no = cYAML_get_object_item(tree, "seq_no");
4739 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4740 (gw) ? gw->cy_valuestring : NULL,
4741 (seq_no) ? seq_no->cy_valueint : -1,
4745 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4746 struct cYAML **err_rc)
4748 struct cYAML *seq_no;
4750 seq_no = cYAML_get_object_item(tree, "seq_no");
4752 return lustre_lnet_enable_routing(0, (seq_no) ?
4753 seq_no->cy_valueint : -1,
4757 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4758 struct cYAML **err_rc)
4764 struct cYAML *detail;
4765 struct cYAML *seq_no;
4767 net = cYAML_get_object_item(tree, "net");
4768 gw = cYAML_get_object_item(tree, "gateway");
4769 hop = cYAML_get_object_item(tree, "hop");
4770 prio = cYAML_get_object_item(tree, "priority");
4771 detail = cYAML_get_object_item(tree, "detail");
4772 seq_no = cYAML_get_object_item(tree, "seq_no");
4774 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4775 (gw) ? gw->cy_valuestring : NULL,
4776 (hop) ? hop->cy_valueint : -1,
4777 (prio) ? prio->cy_valueint : -1,
4778 (detail) ? detail->cy_valueint : 0,
4779 (seq_no) ? seq_no->cy_valueint : -1,
4780 show_rc, err_rc, false);
4783 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4784 struct cYAML **err_rc)
4786 struct cYAML *net, *detail, *seq_no;
4788 net = cYAML_get_object_item(tree, "net");
4789 detail = cYAML_get_object_item(tree, "detail");
4790 seq_no = cYAML_get_object_item(tree, "seq_no");
4792 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4793 (detail) ? detail->cy_valueint : 0,
4794 (seq_no) ? seq_no->cy_valueint : -1,
4795 show_rc, err_rc, false);
4798 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4799 struct cYAML **err_rc)
4801 struct cYAML *seq_no;
4803 seq_no = cYAML_get_object_item(tree, "seq_no");
4805 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4806 show_rc, err_rc, false);
4809 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4810 struct cYAML **err_rc)
4812 struct cYAML *seq_no, *nid, *detail;
4814 seq_no = cYAML_get_object_item(tree, "seq_no");
4815 detail = cYAML_get_object_item(tree, "detail");
4816 nid = cYAML_get_object_item(tree, "nid");
4818 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4819 (detail) ? detail->cy_valueint : 0,
4820 (seq_no) ? seq_no->cy_valueint : -1,
4821 show_rc, err_rc, false);
4824 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4825 struct cYAML **err_rc)
4827 struct cYAML *seq_no;
4829 seq_no = cYAML_get_object_item(tree, "seq_no");
4831 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4835 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4836 struct cYAML **err_rc)
4838 struct cYAML *seq_no, *range;
4840 seq_no = cYAML_get_object_item(tree, "seq_no");
4841 range = cYAML_get_object_item(tree, "range");
4843 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4844 seq_no ? seq_no->cy_valueint : -1,
4848 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4849 struct cYAML **err_rc)
4851 struct cYAML *seq_no;
4853 seq_no = cYAML_get_object_item(tree, "seq_no");
4855 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4859 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4860 struct cYAML **err_rc)
4862 struct cYAML *seq_no;
4864 seq_no = cYAML_get_object_item(tree, "seq_no");
4866 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4870 static int handle_yaml_config_global_settings(struct cYAML *tree,
4871 struct cYAML **show_rc,
4872 struct cYAML **err_rc)
4874 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4875 *sen, *recov, *rsen, *drop_asym_route;
4878 seq_no = cYAML_get_object_item(tree, "seq_no");
4879 max_intf = cYAML_get_object_item(tree, "max_intf");
4881 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4882 seq_no ? seq_no->cy_valueint
4886 numa = cYAML_get_object_item(tree, "numa_range");
4888 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4889 seq_no ? seq_no->cy_valueint
4893 discovery = cYAML_get_object_item(tree, "discovery");
4895 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4896 seq_no ? seq_no->cy_valueint
4900 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4901 if (drop_asym_route)
4902 rc = lustre_lnet_config_drop_asym_route(
4903 drop_asym_route->cy_valueint,
4904 seq_no ? seq_no->cy_valueint : -1,
4907 retry = cYAML_get_object_item(tree, "retry_count");
4909 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4910 seq_no ? seq_no->cy_valueint
4914 tto = cYAML_get_object_item(tree, "transaction_timeout");
4916 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4917 seq_no ? seq_no->cy_valueint
4921 sen = cYAML_get_object_item(tree, "health_sensitivity");
4923 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4924 seq_no ? seq_no->cy_valueint
4928 recov = cYAML_get_object_item(tree, "recovery_interval");
4930 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4931 seq_no ? seq_no->cy_valueint
4935 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4937 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4938 seq_no ? seq_no->cy_valueint
4945 static int handle_yaml_del_global_settings(struct cYAML *tree,
4946 struct cYAML **show_rc,
4947 struct cYAML **err_rc)
4949 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4952 seq_no = cYAML_get_object_item(tree, "seq_no");
4953 max_intf = cYAML_get_object_item(tree, "max_intf");
4955 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4956 seq_no ? seq_no->cy_valueint
4960 numa = cYAML_get_object_item(tree, "numa_range");
4962 rc = lustre_lnet_config_numa_range(0,
4963 seq_no ? seq_no->cy_valueint
4967 /* peer discovery is enabled by default */
4968 discovery = cYAML_get_object_item(tree, "discovery");
4970 rc = lustre_lnet_config_discovery(1,
4971 seq_no ? seq_no->cy_valueint
4975 /* asymmetrical route messages are accepted by default */
4976 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4977 if (drop_asym_route)
4978 rc = lustre_lnet_config_drop_asym_route(
4979 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4984 static int handle_yaml_show_global_settings(struct cYAML *tree,
4985 struct cYAML **show_rc,
4986 struct cYAML **err_rc)
4988 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4989 *sen, *recov, *rsen, *drop_asym_route;
4992 seq_no = cYAML_get_object_item(tree, "seq_no");
4993 max_intf = cYAML_get_object_item(tree, "max_intf");
4995 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4999 numa = cYAML_get_object_item(tree, "numa_range");
5001 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5005 discovery = cYAML_get_object_item(tree, "discovery");
5007 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5011 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5012 if (drop_asym_route)
5013 rc = lustre_lnet_show_drop_asym_route(
5014 seq_no ? seq_no->cy_valueint : -1,
5017 retry = cYAML_get_object_item(tree, "retry_count");
5019 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5023 tto = cYAML_get_object_item(tree, "transaction_timeout");
5025 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5029 sen = cYAML_get_object_item(tree, "health_sensitivity");
5031 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5035 recov = cYAML_get_object_item(tree, "recovery_interval");
5037 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5041 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5043 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5050 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5051 struct cYAML **err_rc)
5053 struct cYAML *seq_no, *nid, *timeout;
5055 seq_no = cYAML_get_object_item(tree, "seq_no");
5056 nid = cYAML_get_object_item(tree, "primary nid");
5057 timeout = cYAML_get_object_item(tree, "timeout");
5059 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5060 (timeout) ? timeout->cy_valueint : 1000,
5061 (seq_no) ? seq_no->cy_valueint : -1,
5065 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5066 struct cYAML **err_rc)
5068 struct cYAML *seq_no, *nid, *force;
5070 seq_no = cYAML_get_object_item(tree, "seq_no");
5071 nid = cYAML_get_object_item(tree, "primary nid");
5072 force = cYAML_get_object_item(tree, "force");
5074 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5075 (force) ? force->cy_valueint : 0,
5076 (seq_no) ? seq_no->cy_valueint : -1,
5080 static int handle_yaml_no_op()
5082 return LUSTRE_CFG_RC_NO_ERR;
5085 struct lookup_cmd_hdlr_tbl {
5090 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5091 { .name = "route", .cb = handle_yaml_config_route },
5092 { .name = "net", .cb = handle_yaml_config_ni },
5093 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5094 { .name = "peer", .cb = handle_yaml_config_peer },
5095 { .name = "routing", .cb = handle_yaml_config_routing },
5096 { .name = "buffers", .cb = handle_yaml_config_buffers },
5097 { .name = "statistics", .cb = handle_yaml_no_op },
5098 { .name = "global", .cb = handle_yaml_config_global_settings},
5099 { .name = "numa", .cb = handle_yaml_config_numa },
5100 { .name = "ping", .cb = handle_yaml_no_op },
5101 { .name = "discover", .cb = handle_yaml_no_op },
5104 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5105 { .name = "route", .cb = handle_yaml_del_route },
5106 { .name = "net", .cb = handle_yaml_del_ni },
5107 { .name = "ip2nets", .cb = handle_yaml_no_op },
5108 { .name = "peer", .cb = handle_yaml_del_peer },
5109 { .name = "routing", .cb = handle_yaml_del_routing },
5110 { .name = "buffers", .cb = handle_yaml_no_op },
5111 { .name = "statistics", .cb = handle_yaml_no_op },
5112 { .name = "global", .cb = handle_yaml_del_global_settings},
5113 { .name = "numa", .cb = handle_yaml_del_numa },
5114 { .name = "ping", .cb = handle_yaml_no_op },
5115 { .name = "discover", .cb = handle_yaml_no_op },
5118 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5119 { .name = "route", .cb = handle_yaml_show_route },
5120 { .name = "net", .cb = handle_yaml_show_net },
5121 { .name = "peer", .cb = handle_yaml_show_peers },
5122 { .name = "ip2nets", .cb = handle_yaml_no_op },
5123 { .name = "routing", .cb = handle_yaml_show_routing },
5124 { .name = "buffers", .cb = handle_yaml_show_routing },
5125 { .name = "statistics", .cb = handle_yaml_show_stats },
5126 { .name = "global", .cb = handle_yaml_show_global_settings},
5127 { .name = "numa", .cb = handle_yaml_show_numa },
5128 { .name = "ping", .cb = handle_yaml_no_op },
5129 { .name = "discover", .cb = handle_yaml_no_op },
5132 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5133 { .name = "route", .cb = handle_yaml_no_op },
5134 { .name = "net", .cb = handle_yaml_no_op },
5135 { .name = "peer", .cb = handle_yaml_no_op },
5136 { .name = "ip2nets", .cb = handle_yaml_no_op },
5137 { .name = "routing", .cb = handle_yaml_no_op },
5138 { .name = "buffers", .cb = handle_yaml_no_op },
5139 { .name = "statistics", .cb = handle_yaml_no_op },
5140 { .name = "global", .cb = handle_yaml_no_op },
5141 { .name = "numa", .cb = handle_yaml_no_op },
5142 { .name = "ping", .cb = handle_yaml_ping },
5143 { .name = "discover", .cb = handle_yaml_discover },
5146 static cmd_handler_t lookup_fn(char *key,
5147 struct lookup_cmd_hdlr_tbl *tbl)
5153 for (i = 0; tbl[i].name != NULL; i++) {
5154 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5161 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5162 struct cYAML **show_rc, struct cYAML **err_rc)
5164 struct cYAML *tree, *item = NULL, *head, *child;
5166 char err_str[LNET_MAX_STR_LEN];
5167 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5169 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5171 return LUSTRE_CFG_RC_BAD_PARAM;
5173 child = tree->cy_child;
5174 while (child != NULL) {
5175 cb = lookup_fn(child->cy_string, table);
5177 snprintf(err_str, sizeof(err_str),
5178 "\"call back for '%s' not found\"",
5180 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5181 "yaml", "helper", err_str, err_rc);
5185 if (cYAML_is_sequence(child)) {
5186 while ((head = cYAML_get_next_seq_item(child, &item))
5188 rc = cb(head, show_rc, err_rc);
5189 if (rc != LUSTRE_CFG_RC_NO_ERR)
5193 rc = cb(child, show_rc, err_rc);
5194 if (rc != LUSTRE_CFG_RC_NO_ERR)
5198 child = child->cy_next;
5202 cYAML_free_tree(tree);
5207 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5209 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5213 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5215 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5219 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5221 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5225 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5227 return lustre_yaml_cb_helper(f, lookup_exec_tbl,