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_config_route(char *nw, char *gw, int hops, int prio,
1232 int sen, int seq_no, struct cYAML **err_rc)
1234 struct lnet_ioctl_config_data data;
1235 lnet_nid_t gateway_nid;
1236 int rc = LUSTRE_CFG_RC_NO_ERR;
1238 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1239 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1240 char err_str[LNET_MAX_STR_LEN];
1241 __u32 ip_list[MAX_NUM_IPS];
1242 struct lustre_lnet_ip2nets ip2nets;
1244 /* initialize all lists */
1245 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1246 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1247 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1249 snprintf(err_str, sizeof(err_str), "\"Success\"");
1251 if (nw == NULL || gw == NULL) {
1254 "\"missing mandatory parameter in route config:'%s'\"",
1255 (nw == NULL && gw == NULL) ? "network, gateway" :
1256 (nw == NULL) ? "network" : "gateway");
1257 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1261 rnet = libcfs_str2net(nw);
1262 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1265 "\"cannot parse remote net %s\"", nw);
1266 rc = LUSTRE_CFG_RC_BAD_PARAM;
1271 /* hops is undefined */
1272 hops = LNET_UNDEFINED_HOPS;
1273 } else if (hops < 1 || hops > 255) {
1276 "\"invalid hop count %d, must be between 1 and 255\"",
1278 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1284 } else if (prio < 0) {
1287 "\"invalid priority %d, must be greater than 0\"",
1289 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1295 } else if (sen < 1) {
1298 "\"invalid health sensitivity %d, must be 1 or greater\"",
1300 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1304 rc = lnet_expr2ips(gw, ip_list,
1305 &ip2nets, &net, err_str);
1306 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1308 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1313 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1314 data.cfg_net = rnet;
1315 data.cfg_config_u.cfg_route.rtr_hop = hops;
1316 data.cfg_config_u.cfg_route.rtr_priority = prio;
1317 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
1319 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1320 gateway_nid = LNET_MKNID(net, ip_list[i]);
1321 if (gateway_nid == LNET_NID_ANY) {
1324 "\"cannot form gateway NID: %u\"",
1326 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1327 rc = LUSTRE_CFG_RC_BAD_PARAM;
1330 data.cfg_nid = gateway_nid;
1332 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1333 if (rc != 0 && errno != EEXIST && errno != EHOSTUNREACH) {
1337 "\"cannot add route: %s\"", strerror(errno));
1342 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1347 int lustre_lnet_del_route(char *nw, char *gw,
1348 int seq_no, struct cYAML **err_rc)
1350 struct lnet_ioctl_config_data data;
1351 lnet_nid_t gateway_nid;
1352 int rc = LUSTRE_CFG_RC_NO_ERR;
1353 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1354 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1355 char err_str[LNET_MAX_STR_LEN];
1357 __u32 ip_list[MAX_NUM_IPS];
1358 struct lustre_lnet_ip2nets ip2nets;
1360 /* initialize all lists */
1361 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1362 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1363 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1365 snprintf(err_str, sizeof(err_str), "\"Success\"");
1367 if (nw == NULL || gw == NULL) {
1370 "\"missing mandatory parameter in route delete: '%s'\"",
1371 (nw == NULL && gw == NULL) ? "network, gateway" :
1372 (nw == NULL) ? "network" : "gateway");
1373 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1377 rnet = libcfs_str2net(nw);
1378 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1381 "\"cannot parse remote net '%s'\"", nw);
1382 rc = LUSTRE_CFG_RC_BAD_PARAM;
1386 rc = lnet_expr2ips(gw, ip_list,
1387 &ip2nets, &net, err_str);
1388 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1390 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1395 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1396 data.cfg_net = rnet;
1398 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1399 gateway_nid = LNET_MKNID(net, ip_list[i]);
1400 if (gateway_nid == LNET_NID_ANY) {
1403 "\"cannot form gateway NID: %u\"",
1405 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1406 rc = LUSTRE_CFG_RC_BAD_PARAM;
1409 data.cfg_nid = gateway_nid;
1411 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1416 "\"cannot delete route: %s\"", strerror(errno));
1421 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1426 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1427 int seq_no, struct cYAML **show_rc,
1428 struct cYAML **err_rc, bool backup)
1430 struct lnet_ioctl_config_data data;
1431 lnet_nid_t gateway_nid;
1432 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1434 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1436 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1437 struct cYAML *first_seq = NULL;
1438 char err_str[LNET_MAX_STR_LEN];
1441 snprintf(err_str, sizeof(err_str),
1442 "\"out of memory\"");
1445 net = libcfs_str2net(nw);
1446 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1449 "\"cannot parse net '%s'\"", nw);
1450 rc = LUSTRE_CFG_RC_BAD_PARAM;
1455 /* show all routes without filtering on net */
1456 net = LNET_NIDNET(LNET_NID_ANY);
1460 gateway_nid = libcfs_str2nid(gw);
1461 if (gateway_nid == LNET_NID_ANY) {
1464 "\"cannot parse gateway NID '%s'\"", gw);
1465 rc = LUSTRE_CFG_RC_BAD_PARAM;
1469 /* show all routes with out filtering on gateway */
1470 gateway_nid = LNET_NID_ANY;
1472 if ((hops < 1 && hops != -1) || hops > 255) {
1475 "\"invalid hop count %d, must be between 0 and 256\"",
1477 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1481 /* create struct cYAML root object */
1482 root = cYAML_create_object(NULL, NULL);
1486 route = cYAML_create_seq(root, "route");
1491 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1494 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1500 /* filter on provided data */
1501 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1502 net != data.cfg_net)
1505 if (gateway_nid != LNET_NID_ANY &&
1506 gateway_nid != data.cfg_nid)
1510 hops != data.cfg_config_u.cfg_route.rtr_hop)
1514 prio != data.cfg_config_u.cfg_route.rtr_priority)
1517 /* default rc to -1 incase we hit the goto */
1521 item = cYAML_create_seq_item(route);
1525 if (first_seq == NULL)
1528 if (cYAML_create_string(item, "net",
1529 libcfs_net2str(data.cfg_net)) == NULL)
1532 if (cYAML_create_string(item, "gateway",
1533 libcfs_nid2str(data.cfg_nid)) == NULL)
1537 if (cYAML_create_number(item, "hop",
1538 (int) data.cfg_config_u.
1539 cfg_route.rtr_hop) ==
1543 if (cYAML_create_number(item, "priority",
1545 cfg_route.rtr_priority) == NULL)
1548 if (cYAML_create_number(item, "health_sensitivity",
1550 cfg_route.rtr_sensitivity) == NULL)
1554 cYAML_create_string(item, "state",
1555 data.cfg_config_u.cfg_route.
1557 "up" : "down") == NULL)
1562 /* print output iff show_rc is not provided */
1563 if (show_rc == NULL)
1564 cYAML_print_tree(root);
1566 if (l_errno != ENOENT) {
1569 "\"cannot get routes: %s\"",
1574 rc = LUSTRE_CFG_RC_NO_ERR;
1576 snprintf(err_str, sizeof(err_str), "\"success\"");
1578 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1579 cYAML_free_tree(root);
1580 } else if (show_rc != NULL && *show_rc != NULL) {
1581 struct cYAML *show_node;
1582 /* find the route node, if one doesn't exist then
1583 * insert one. Otherwise add to the one there
1585 show_node = cYAML_get_object_item(*show_rc, "route");
1586 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1587 cYAML_insert_child(show_node, first_seq);
1590 } else if (show_node == NULL) {
1591 cYAML_insert_sibling((*show_rc)->cy_child,
1595 cYAML_free_tree(root);
1601 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1606 static int socket_intf_query(int request, char *intf,
1612 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1613 return LUSTRE_CFG_RC_BAD_PARAM;
1615 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1617 return LUSTRE_CFG_RC_BAD_PARAM;
1619 strcpy(ifr->ifr_name, intf);
1620 rc = ioctl(sockfd, request, ifr);
1622 rc = LUSTRE_CFG_RC_BAD_PARAM;
1629 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1634 memset(&ifr, 0, sizeof(ifr));
1635 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1637 return LUSTRE_CFG_RC_BAD_PARAM;
1639 if ((ifr.ifr_flags & IFF_UP) == 0)
1640 return LUSTRE_CFG_RC_BAD_PARAM;
1642 memset(&ifr, 0, sizeof(ifr));
1643 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1645 return LUSTRE_CFG_RC_BAD_PARAM;
1647 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1648 *ip = bswap_32(*ip);
1650 return LUSTRE_CFG_RC_NO_ERR;
1654 * for each interface in the array of interfaces find the IP address of
1655 * that interface, create its nid and add it to an array of NIDs.
1656 * Stop if any of the interfaces is down
1658 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1659 lnet_nid_t **nids, __u32 *nnids,
1660 char *err_str, size_t str_len)
1662 int i = 0, count = 0, rc;
1663 struct lnet_dlc_intf_descr *intf;
1664 char val[LNET_MAX_STR_LEN];
1671 if (nw == NULL || nids == NULL) {
1672 snprintf(err_str, str_len,
1673 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1674 err_str[str_len - 1] = '\0';
1675 return LUSTRE_CFG_RC_BAD_PARAM;
1678 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1681 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1685 *nids = calloc(count, sizeof(lnet_nid_t));
1686 if (*nids == NULL) {
1687 snprintf(err_str, str_len,
1688 "\"out of memory\"");
1689 err_str[str_len - 1] = '\0';
1690 return LUSTRE_CFG_RC_OUT_OF_MEM;
1693 * special case the GNI interface since it doesn't have an IP
1694 * address. The assumption is that there can only be one GNI
1695 * interface in the system. No interface name is provided.
1697 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1698 rc = read_sysfs_file(gni_nid_path, "nid", val,
1701 snprintf(err_str, str_len,
1702 "\"cannot read gni nid\"");
1703 err_str[str_len - 1] = '\0';
1706 gni_num = atoi(val);
1708 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1713 /* look at the other interfaces */
1714 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1715 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1716 /* handle LNDs with numeric interface name */
1717 num = strtoul(intf->intf_name, &endp, 0);
1718 if (endp == intf->intf_name || *endp != '\0') {
1719 rc = LUSTRE_CFG_RC_BAD_PARAM;
1720 snprintf(err_str, str_len,
1721 "\"couldn't query intf %s\"",
1723 err_str[str_len - 1] = '\0';
1726 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1729 /* handle LNDs with ip interface name */
1730 rc = lustre_lnet_queryip(intf, &ip);
1731 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1732 snprintf(err_str, str_len,
1733 "\"couldn't query intf %s\"",
1735 err_str[str_len - 1] = '\0';
1738 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1755 * called repeatedly until a match or no more ip range
1757 * ip_range expression
1758 * interface list with all the interface names.
1759 * all the interfaces in the system.
1761 * try to match the ip_range expr to one of the interfaces' IPs in
1762 * the system. If we hit a patch for an interface. Check if that
1763 * interface name is in the list.
1765 * If there are more than one interface in the list, then make sure
1766 * that the IPs for all of these interfaces match the ip ranges
1769 * for each interface in intf_list
1770 * look up the intf name in ifa
1771 * if not there then no match
1772 * check ip obtained from ifa against a match to any of the
1774 * If no match, then fail
1776 * The result is that all the interfaces have to match.
1778 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1779 struct list_head *intf_list,
1780 struct list_head *ip_ranges)
1784 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1785 struct ifaddrs *ifaddr = ifa;
1786 struct lustre_lnet_ip_range_descr *ip_range;
1790 * if there are no explicit interfaces, and no ip ranges, then
1791 * configure the first tcp interface we encounter.
1793 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1794 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1795 if (ifaddr->ifa_addr == NULL)
1798 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1801 family = ifaddr->ifa_addr->sa_family;
1802 if (family == AF_INET &&
1803 strcmp(ifaddr->ifa_name, "lo") != 0) {
1804 rc = lustre_lnet_add_intf_descr
1805 (intf_list, ifaddr->ifa_name,
1806 strlen(ifaddr->ifa_name));
1808 if (rc != LUSTRE_CFG_RC_NO_ERR)
1811 return LUSTRE_CFG_RC_MATCH;
1814 return LUSTRE_CFG_RC_NO_MATCH;
1818 * First interface which matches an IP pattern will be used
1820 if (list_empty(intf_list)) {
1822 * no interfaces provided in the rule, but an ip range is
1823 * provided, so try and match an interface to the ip
1826 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1827 if (ifaddr->ifa_addr == NULL)
1830 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1833 family = ifaddr->ifa_addr->sa_family;
1834 if (family == AF_INET) {
1835 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1838 list_for_each_entry(ip_range, ip_ranges,
1840 rc = cfs_ip_addr_match(bswap_32(ip),
1841 &ip_range->ipr_expr);
1845 rc = lustre_lnet_add_intf_descr
1846 (intf_list, ifaddr->ifa_name,
1847 strlen(ifaddr->ifa_name));
1849 if (rc != LUSTRE_CFG_RC_NO_ERR)
1855 if (!list_empty(intf_list))
1856 return LUSTRE_CFG_RC_MATCH;
1858 return LUSTRE_CFG_RC_NO_MATCH;
1862 * If an interface is explicitly specified the ip-range might or
1863 * might not be specified. if specified the interface needs to match the
1864 * ip-range. If no ip-range then the interfaces are
1865 * automatically matched if they are all up.
1866 * If > 1 interfaces all the interfaces must match for the NI to
1869 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1870 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1871 if (ifaddr->ifa_addr == NULL)
1874 family = ifaddr->ifa_addr->sa_family;
1875 if (family == AF_INET &&
1876 strcmp(intf_descr->intf_name,
1877 ifaddr->ifa_name) == 0)
1881 if (ifaddr == NULL) {
1882 list_del(&intf_descr->intf_on_network);
1883 free_intf_descr(intf_descr);
1887 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1888 list_del(&intf_descr->intf_on_network);
1889 free_intf_descr(intf_descr);
1893 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1896 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1897 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1903 /* no match for this interface */
1904 list_del(&intf_descr->intf_on_network);
1905 free_intf_descr(intf_descr);
1909 return LUSTRE_CFG_RC_MATCH;
1912 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1913 lnet_nid_t **nids, __u32 *nnids,
1914 char *err_str, size_t str_len)
1916 struct ifaddrs *ifa;
1917 int rc = LUSTRE_CFG_RC_NO_ERR;
1919 rc = getifaddrs(&ifa);
1921 snprintf(err_str, str_len,
1922 "\"failed to get interface addresses: %d\"", -errno);
1923 err_str[str_len - 1] = '\0';
1927 rc = lustre_lnet_match_ip_to_intf(ifa,
1928 &ip2nets->ip2nets_net.nw_intflist,
1929 &ip2nets->ip2nets_ip_ranges);
1930 if (rc != LUSTRE_CFG_RC_MATCH) {
1931 snprintf(err_str, str_len,
1932 "\"couldn't match ip to existing interfaces\"");
1933 err_str[str_len - 1] = '\0';
1938 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1939 err_str, sizeof(err_str));
1940 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1951 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1952 struct lnet_ioctl_config_lnd_tunables *tunables,
1953 struct cfs_expr_list *global_cpts,
1954 lnet_nid_t *nids, char *err_str)
1957 struct lnet_ioctl_config_ni *conf;
1958 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1959 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1962 struct lnet_dlc_intf_descr *intf_descr;
1964 struct cfs_expr_list *cpt_expr;
1966 list_for_each_entry(intf_descr, intf_list,
1968 if (tunables != NULL)
1969 len = sizeof(struct lnet_ioctl_config_ni) +
1970 sizeof(struct lnet_ioctl_config_lnd_tunables);
1972 len = sizeof(struct lnet_ioctl_config_ni);
1974 data = calloc(1, len);
1976 return LUSTRE_CFG_RC_OUT_OF_MEM;
1977 conf = (struct lnet_ioctl_config_ni*) data;
1978 if (tunables != NULL)
1979 tun = (struct lnet_ioctl_config_lnd_tunables*)
1982 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1983 conf->lic_cfg_hdr.ioc_len = len;
1984 conf->lic_nid = nids[i];
1985 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1988 if (intf_descr->cpt_expr != NULL)
1989 cpt_expr = intf_descr->cpt_expr;
1990 else if (global_cpts != NULL)
1991 cpt_expr = global_cpts;
1995 if (cpt_expr != NULL) {
1996 count = cfs_expr_list_values(cpt_expr,
1997 LNET_MAX_SHOW_NUM_CPT,
2000 memcpy(conf->lic_cpts, cpt_array,
2001 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
2010 conf->lic_ncpts = count;
2012 if (tunables != NULL)
2013 memcpy(tun, tunables, sizeof(*tunables));
2015 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
2020 "\"cannot add network: %s\"", strerror(errno));
2028 return LUSTRE_CFG_RC_NO_ERR;
2032 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
2033 struct lnet_ioctl_config_lnd_tunables *tunables,
2034 struct cfs_expr_list *global_cpts,
2035 int seq_no, struct cYAML **err_rc)
2037 lnet_nid_t *nids = NULL;
2040 char err_str[LNET_MAX_STR_LEN];
2042 snprintf(err_str, sizeof(err_str), "\"success\"");
2047 "\"incomplete ip2nets information\"");
2048 rc = LUSTRE_CFG_RC_BAD_PARAM;
2053 * call below function to resolve the rules into a list of nids.
2054 * The memory is allocated in that function then freed here when
2055 * it's no longer needed.
2057 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
2059 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
2062 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
2063 snprintf(err_str, sizeof(err_str),
2064 "\"no interfaces match ip2nets rules\"");
2068 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
2069 tunables, global_cpts, nids,
2076 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
2080 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
2081 struct cfs_expr_list *global_cpts,
2083 struct lnet_ioctl_config_lnd_tunables *tunables,
2084 int seq_no, struct cYAML **err_rc)
2087 struct lnet_ioctl_config_ni *conf;
2088 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
2089 char buf[LNET_MAX_STR_LEN];
2090 int rc = LUSTRE_CFG_RC_NO_ERR;
2091 char err_str[LNET_MAX_STR_LEN];
2092 lnet_nid_t *nids = NULL;
2096 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2099 snprintf(err_str, sizeof(err_str), "\"success\"");
2101 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
2102 (list_empty(&nw_descr->nw_intflist) &&
2103 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
2106 "\"missing mandatory parameters in NI config: '%s'\"",
2107 (nw_descr == NULL) ? "network , interface" :
2108 (nw_descr->nw_id == 0) ? "network" : "interface");
2109 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2113 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
2116 "\"ip2net string too long %d\"",
2117 (int)strlen(ip2net));
2118 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2122 if (ip2net != NULL) {
2123 if (tunables != NULL)
2124 len = sizeof(struct lnet_ioctl_config_ni) +
2125 sizeof(struct lnet_ioctl_config_lnd_tunables);
2127 len = sizeof(struct lnet_ioctl_config_ni);
2128 data = calloc(1, len);
2130 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2133 conf = (struct lnet_ioctl_config_ni*) data;
2134 if (tunables != NULL)
2135 tun = (struct lnet_ioctl_config_lnd_tunables*)
2136 (data + sizeof(*conf));
2138 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
2139 conf->lic_cfg_hdr.ioc_len = len;
2140 strncpy(conf->lic_legacy_ip2nets, ip2net,
2143 if (global_cpts != NULL) {
2144 count = cfs_expr_list_values(global_cpts,
2145 LNET_MAX_SHOW_NUM_CPT,
2148 memcpy(conf->lic_cpts, cpt_array,
2149 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
2158 conf->lic_ncpts = count;
2160 if (tunables != NULL)
2161 memcpy(tun, tunables, sizeof(*tunables));
2163 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
2168 "\"cannot add network: %s\"", strerror(errno));
2175 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
2176 rc = LUSTRE_CFG_RC_NO_ERR;
2180 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2183 "\"cannot parse net '%s'\"",
2184 libcfs_net2str(nw_descr->nw_id));
2185 rc = LUSTRE_CFG_RC_BAD_PARAM;
2190 * special case the GNI since no interface name is expected
2192 if (list_empty(&nw_descr->nw_intflist) &&
2193 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
2196 "\"no interface name provided\"");
2197 rc = LUSTRE_CFG_RC_BAD_PARAM;
2201 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2202 err_str, sizeof(err_str));
2204 rc = LUSTRE_CFG_RC_BAD_PARAM;
2208 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
2209 tunables, global_cpts, nids,
2213 if (nw_descr != NULL) {
2214 list_for_each_entry_safe(intf_descr, tmp,
2215 &nw_descr->nw_intflist,
2217 list_del(&intf_descr->intf_on_network);
2218 free_intf_descr(intf_descr);
2222 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
2233 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
2234 int seq_no, struct cYAML **err_rc)
2236 struct lnet_ioctl_config_ni data;
2237 int rc = LUSTRE_CFG_RC_NO_ERR, i;
2238 char err_str[LNET_MAX_STR_LEN];
2239 lnet_nid_t *nids = NULL;
2241 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2243 snprintf(err_str, sizeof(err_str), "\"success\"");
2245 if (nw_descr == NULL || nw_descr->nw_id == 0) {
2248 "\"missing mandatory parameter in deleting NI: '%s'\"",
2249 (nw_descr == NULL) ? "network , interface" :
2250 (nw_descr->nw_id == 0) ? "network" : "interface");
2251 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2255 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2256 return LUSTRE_CFG_RC_NO_ERR;
2258 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2261 "\"cannot parse net '%s'\"",
2262 libcfs_net2str(nw_descr->nw_id));
2263 rc = LUSTRE_CFG_RC_BAD_PARAM;
2267 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2268 err_str, sizeof(err_str));
2270 rc = LUSTRE_CFG_RC_BAD_PARAM;
2275 * no interfaces just the nw_id is specified
2278 nids = calloc(1, sizeof(*nids));
2280 snprintf(err_str, sizeof(err_str),
2281 "\"out of memory\"");
2282 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2285 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2289 for (i = 0; i < nnids; i++) {
2290 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2291 data.lic_nid = nids[i];
2293 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2298 "\"cannot del network: %s\"", strerror(errno));
2302 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2304 list_del(&intf_descr->intf_on_network);
2305 free_intf_descr(intf_descr);
2309 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2318 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2319 enum lnet_health_type type, char *name,
2320 int seq_no, struct cYAML **err_rc)
2322 struct lnet_ioctl_reset_health_cfg data;
2323 int rc = LUSTRE_CFG_RC_NO_ERR;
2324 char err_str[LNET_MAX_STR_LEN];
2326 snprintf(err_str, sizeof(err_str), "\"success\"");
2328 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2329 data.rh_type = type;
2331 data.rh_value = value;
2334 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2338 sizeof(err_str), "Can not configure health value: %s",
2342 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2347 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2348 struct cYAML **err_rc)
2352 nid = libcfs_str2nid(ni_nid);
2355 return lustre_lnet_config_healthv(value, all, nid,
2356 LNET_HEALTH_TYPE_LOCAL_NI,
2357 "ni healthv", seq_no, err_rc);
2360 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2361 int seq_no, struct cYAML **err_rc)
2365 nid = libcfs_str2nid(lpni_nid);
2368 return lustre_lnet_config_healthv(value, all, nid,
2369 LNET_HEALTH_TYPE_PEER_NI,
2370 "peer_ni healthv", seq_no, err_rc);
2374 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2375 struct lnet_ioctl_comm_count *counts)
2377 if (cYAML_create_number(yaml, "put",
2378 counts->ico_put_count)
2381 if (cYAML_create_number(yaml, "get",
2382 counts->ico_get_count)
2385 if (cYAML_create_number(yaml, "reply",
2386 counts->ico_reply_count)
2389 if (cYAML_create_number(yaml, "ack",
2390 counts->ico_ack_count)
2393 if (cYAML_create_number(yaml, "hello",
2394 counts->ico_hello_count)
2401 static struct lnet_ioctl_comm_count *
2402 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2405 return &msg_stats->im_send_stats;
2407 return &msg_stats->im_recv_stats;
2409 return &msg_stats->im_drop_stats;
2414 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2415 struct cYAML **show_rc, struct cYAML **err_rc,
2419 struct lnet_ioctl_config_ni *ni_data;
2420 struct lnet_ioctl_config_lnd_tunables *lnd;
2421 struct lnet_ioctl_element_stats *stats;
2422 struct lnet_ioctl_element_msg_stats msg_stats;
2423 struct lnet_ioctl_local_ni_hstats hstats;
2424 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2425 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2426 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2428 struct cYAML *root = NULL, *tunables = NULL,
2429 *net_node = NULL, *interfaces = NULL,
2430 *item = NULL, *first_seq = NULL,
2431 *tmp = NULL, *statistics = NULL,
2433 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2434 char str_buf[str_buf_len];
2436 char err_str[LNET_MAX_STR_LEN];
2437 bool exist = false, new_net = true;
2439 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2441 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2443 buf = calloc(1, buf_size);
2447 ni_data = (struct lnet_ioctl_config_ni *)buf;
2450 net = libcfs_str2net(nw);
2451 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2454 "\"cannot parse net '%s'\"", nw);
2455 rc = LUSTRE_CFG_RC_BAD_PARAM;
2460 root = cYAML_create_object(NULL, NULL);
2464 net_node = cYAML_create_seq(root, "net");
2465 if (net_node == NULL)
2471 memset(buf, 0, buf_size);
2473 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2475 * set the ioc_len to the proper value since INIT assumes
2478 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2479 ni_data->lic_idx = i;
2481 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2487 rc_net = LNET_NIDNET(ni_data->lic_nid);
2489 /* filter on provided data */
2490 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2494 /* if we're backing up don't store lo */
2495 if (backup && LNET_NETTYP(rc_net) == LOLND)
2498 /* default rc to -1 in case we hit the goto */
2502 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2503 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2504 (ni_data->lic_bulk + sizeof(*stats));
2506 if (rc_net != prev_net) {
2513 if (!cYAML_create_string(net_node, "net type",
2514 libcfs_net2str(rc_net)))
2517 tmp = cYAML_create_seq(net_node, "local NI(s)");
2523 /* create the tree to be printed. */
2524 item = cYAML_create_seq_item(tmp);
2528 if (first_seq == NULL)
2532 cYAML_create_string(item, "nid",
2533 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2537 cYAML_create_string(item,
2539 (ni_data->lic_status ==
2540 LNET_NI_STATUS_UP) ?
2541 "up" : "down") == NULL)
2544 /* don't add interfaces unless there is at least one
2546 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2547 interfaces = cYAML_create_object(item, "interfaces");
2548 if (interfaces == NULL)
2551 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2552 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2554 sizeof(str_buf), "%d", j);
2555 if (cYAML_create_string(interfaces,
2557 ni_data->lic_ni_intf[j]) ==
2569 goto continue_without_msg_stats;
2571 statistics = cYAML_create_object(item, "statistics");
2572 if (statistics == NULL)
2575 if (cYAML_create_number(statistics, "send_count",
2576 stats->iel_send_count)
2580 if (cYAML_create_number(statistics, "recv_count",
2581 stats->iel_recv_count)
2585 if (cYAML_create_number(statistics, "drop_count",
2586 stats->iel_drop_count)
2591 goto continue_without_msg_stats;
2593 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2594 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2595 msg_stats.im_idx = i;
2597 rc = l_ioctl(LNET_DEV_ID,
2598 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2602 goto continue_without_msg_stats;
2605 for (k = 0; k < 3; k++) {
2606 struct lnet_ioctl_comm_count *counts;
2607 struct cYAML *msg_statistics = NULL;
2609 msg_statistics = cYAML_create_object(item,
2610 (char *)gmsg_stat_names[k]);
2611 if (msg_statistics == NULL)
2614 counts = get_counts(&msg_stats, k);
2618 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2623 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2624 hstats.hlni_nid = ni_data->lic_nid;
2625 /* grab health stats */
2626 rc = l_ioctl(LNET_DEV_ID,
2627 IOC_LIBCFS_GET_LOCAL_HSTATS,
2631 goto continue_without_msg_stats;
2633 yhstats = cYAML_create_object(item, "health stats");
2636 if (cYAML_create_number(yhstats, "health value",
2637 hstats.hlni_health_value)
2640 if (cYAML_create_number(yhstats, "interrupts",
2641 hstats.hlni_local_interrupt)
2644 if (cYAML_create_number(yhstats, "dropped",
2645 hstats.hlni_local_dropped)
2648 if (cYAML_create_number(yhstats, "aborted",
2649 hstats.hlni_local_aborted)
2652 if (cYAML_create_number(yhstats, "no route",
2653 hstats.hlni_local_no_route)
2656 if (cYAML_create_number(yhstats, "timeouts",
2657 hstats.hlni_local_timeout)
2660 if (cYAML_create_number(yhstats, "error",
2661 hstats.hlni_local_error)
2665 continue_without_msg_stats:
2666 tunables = cYAML_create_object(item, "tunables");
2670 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2671 if (rc != LUSTRE_CFG_RC_NO_ERR)
2674 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2676 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2677 rc != LUSTRE_CFG_RC_NO_MATCH)
2680 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2681 tunables = cYAML_create_object(item,
2683 if (tunables == NULL)
2688 cYAML_create_number(item, "dev cpt",
2689 ni_data->lic_dev_cpt) == NULL)
2693 cYAML_create_number(item, "tcp bonding",
2694 ni_data->lic_tcp_bonding)
2698 /* out put the CPTs in the format: "[x,x,x,...]" */
2700 limit = str_buf + str_buf_len - 3;
2701 pos += scnprintf(pos, limit - pos, "\"[");
2702 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2703 j < ni_data->lic_ncpts &&
2705 pos += scnprintf(pos, limit - pos,
2706 "%d", ni_data->lic_cpts[j]);
2707 if ((j + 1) < ni_data->lic_ncpts)
2708 pos += scnprintf(pos, limit - pos, ",");
2710 snprintf(pos, 3, "]\"");
2712 if (ni_data->lic_ncpts >= 1 &&
2713 cYAML_create_string(item, "CPT",
2719 /* Print out the net information only if show_rc is not provided */
2720 if (show_rc == NULL)
2721 cYAML_print_tree(root);
2723 if (l_errno != ENOENT) {
2726 "\"cannot get networks: %s\"",
2731 rc = LUSTRE_CFG_RC_NO_ERR;
2733 snprintf(err_str, sizeof(err_str), "\"success\"");
2735 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2736 cYAML_free_tree(root);
2737 } else if (show_rc != NULL && *show_rc != NULL) {
2738 struct cYAML *show_node;
2739 /* find the net node, if one doesn't exist
2740 * then insert one. Otherwise add to the one there
2742 show_node = cYAML_get_object_item(*show_rc, "net");
2743 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2744 cYAML_insert_child(show_node, first_seq);
2747 } else if (show_node == NULL) {
2748 cYAML_insert_sibling((*show_rc)->cy_child,
2752 cYAML_free_tree(root);
2758 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2763 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2765 struct lnet_ioctl_config_data data;
2766 int rc = LUSTRE_CFG_RC_NO_ERR;
2767 char err_str[LNET_MAX_STR_LEN];
2769 snprintf(err_str, sizeof(err_str), "\"success\"");
2771 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2772 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2774 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2779 "\"cannot %s routing %s\"",
2780 (enable) ? "enable" : "disable", strerror(errno));
2785 cYAML_build_error(rc, seq_no,
2786 (enable) ? ADD_CMD : DEL_CMD,
2787 "routing", err_str, err_rc);
2792 int ioctl_set_value(__u32 val, int ioc, char *name,
2793 int seq_no, struct cYAML **err_rc)
2795 struct lnet_ioctl_set_value data;
2796 int rc = LUSTRE_CFG_RC_NO_ERR;
2797 char err_str[LNET_MAX_STR_LEN];
2799 snprintf(err_str, sizeof(err_str), "\"success\"");
2801 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2802 data.sv_value = val;
2804 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2809 "\"cannot configure %s to %d: %s\"", name,
2810 val, strerror(errno));
2813 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2818 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2820 int rc = LUSTRE_CFG_RC_NO_ERR;
2821 char err_str[LNET_MAX_STR_LEN];
2822 char val[LNET_MAX_STR_LEN];
2824 snprintf(err_str, sizeof(err_str), "\"success\"");
2826 snprintf(val, sizeof(val), "%d", intrv);
2828 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2829 1, strlen(val) + 1);
2831 snprintf(err_str, sizeof(err_str),
2832 "\"cannot configure recovery interval: %s\"",
2835 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2840 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2842 int rc = LUSTRE_CFG_RC_NO_ERR;
2843 char err_str[LNET_MAX_STR_LEN];
2844 char val[LNET_MAX_STR_LEN];
2846 snprintf(err_str, sizeof(err_str), "\"success\"");
2848 snprintf(val, sizeof(val), "%d", sen);
2850 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2851 1, strlen(val) + 1);
2853 snprintf(err_str, sizeof(err_str),
2854 "\"cannot configure router health sensitivity: %s\"",
2857 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2862 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2864 int rc = LUSTRE_CFG_RC_NO_ERR;
2865 char err_str[LNET_MAX_STR_LEN];
2866 char val[LNET_MAX_STR_LEN];
2868 snprintf(err_str, sizeof(err_str), "\"success\"");
2870 snprintf(val, sizeof(val), "%d", sen);
2872 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2873 1, strlen(val) + 1);
2875 snprintf(err_str, sizeof(err_str),
2876 "\"cannot configure health sensitivity: %s\"",
2879 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2884 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2886 int rc = LUSTRE_CFG_RC_NO_ERR;
2887 char err_str[LNET_MAX_STR_LEN];
2888 char val[LNET_MAX_STR_LEN];
2890 snprintf(err_str, sizeof(err_str), "\"success\"");
2892 snprintf(val, sizeof(val), "%d", timeout);
2894 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2895 1, strlen(val) + 1);
2897 snprintf(err_str, sizeof(err_str),
2898 "\"cannot configure transaction timeout: %s\"",
2901 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2906 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2908 int rc = LUSTRE_CFG_RC_NO_ERR;
2909 char err_str[LNET_MAX_STR_LEN];
2910 char val[LNET_MAX_STR_LEN];
2912 snprintf(err_str, sizeof(err_str), "\"success\"");
2914 snprintf(val, sizeof(val), "%d", count);
2916 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2917 1, strlen(val) + 1);
2919 snprintf(err_str, sizeof(err_str),
2920 "\"cannot configure retry count: %s\"",
2923 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2928 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2930 int rc = LUSTRE_CFG_RC_NO_ERR;
2931 char err_str[LNET_MAX_STR_LEN];
2932 char val[LNET_MAX_STR_LEN];
2934 snprintf(err_str, sizeof(err_str), "\"success\"");
2936 snprintf(val, sizeof(val), "%d", max);
2938 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2939 1, strlen(val) + 1);
2941 snprintf(err_str, sizeof(err_str),
2942 "\"cannot configure max interfaces: %s\"",
2945 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2950 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2952 int rc = LUSTRE_CFG_RC_NO_ERR;
2953 char err_str[LNET_MAX_STR_LEN];
2954 char val[LNET_MAX_STR_LEN];
2956 snprintf(err_str, sizeof(err_str), "\"success\"");
2958 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2960 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2961 1, strlen(val) + 1);
2963 snprintf(err_str, sizeof(err_str),
2964 "\"cannot configure discovery: %s\"",
2967 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2973 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2974 struct cYAML **err_rc)
2976 int rc = LUSTRE_CFG_RC_NO_ERR;
2977 char err_str[LNET_MAX_STR_LEN];
2978 char val[LNET_MAX_STR_LEN];
2980 snprintf(err_str, sizeof(err_str), "\"success\"");
2982 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2984 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2985 1, strlen(val) + 1);
2987 snprintf(err_str, sizeof(err_str),
2988 "\"cannot configure drop asym route: %s\"",
2991 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2998 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
3000 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
3001 "numa_range", seq_no, err_rc);
3004 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
3005 struct cYAML **err_rc)
3007 struct lnet_ioctl_config_data data;
3008 int rc = LUSTRE_CFG_RC_NO_ERR;
3009 char err_str[LNET_MAX_STR_LEN];
3011 snprintf(err_str, sizeof(err_str), "\"success\"");
3013 /* -1 indicates to ignore changes to this field */
3014 if (tiny < -1 || small < -1 || large < -1) {
3017 "\"tiny, small and large must be >= 0\"");
3018 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
3022 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
3023 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
3024 data.cfg_config_u.cfg_buffers.buf_small = small;
3025 data.cfg_config_u.cfg_buffers.buf_large = large;
3027 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
3032 "\"cannot configure buffers: %s\"", strerror(errno));
3037 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
3042 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
3043 struct cYAML **err_rc, bool backup)
3045 struct lnet_ioctl_config_data *data;
3046 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
3047 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3050 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
3051 int buf_count[LNET_NRBPOOLS] = {0};
3052 struct cYAML *root = NULL, *pools_node = NULL,
3053 *type_node = NULL, *item = NULL, *cpt = NULL,
3054 *first_seq = NULL, *buffers = NULL;
3056 char err_str[LNET_MAX_STR_LEN];
3057 char node_name[LNET_MAX_STR_LEN];
3060 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3062 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
3066 data = (struct lnet_ioctl_config_data *)buf;
3068 root = cYAML_create_object(NULL, NULL);
3073 pools_node = cYAML_create_object(root, "routing");
3075 pools_node = cYAML_create_seq(root, "routing");
3076 if (pools_node == NULL)
3080 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
3081 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
3082 sizeof(struct lnet_ioctl_pool_cfg);
3083 data->cfg_count = i;
3085 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
3093 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
3096 goto calculate_buffers;
3098 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
3099 item = cYAML_create_seq_item(pools_node);
3103 if (first_seq == NULL)
3106 cpt = cYAML_create_object(item, node_name);
3111 /* create the tree and print */
3112 for (j = 0; j < LNET_NRBPOOLS; j++) {
3114 type_node = cYAML_create_object(cpt, pools[j]);
3115 if (type_node == NULL)
3119 cYAML_create_number(type_node, "npages",
3120 pool_cfg->pl_pools[j].pl_npages)
3124 cYAML_create_number(type_node, "nbuffers",
3125 pool_cfg->pl_pools[j].
3126 pl_nbuffers) == NULL)
3129 cYAML_create_number(type_node, "credits",
3130 pool_cfg->pl_pools[j].
3131 pl_credits) == NULL)
3134 cYAML_create_number(type_node, "mincredits",
3135 pool_cfg->pl_pools[j].
3136 pl_mincredits) == NULL)
3138 /* keep track of the total count for each of the
3139 * tiny, small and large buffers */
3140 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
3144 if (pool_cfg != NULL) {
3146 if (cYAML_create_number(pools_node, "enable",
3147 pool_cfg->pl_routing) ==
3151 goto add_buffer_section;
3154 item = cYAML_create_seq_item(pools_node);
3158 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
3164 /* create a buffers entry in the show. This is necessary so that
3165 * if the YAML output is used to configure a node, the buffer
3166 * configuration takes hold */
3167 buffers = cYAML_create_object(root, "buffers");
3168 if (buffers == NULL)
3171 for (i = 0; i < LNET_NRBPOOLS; i++) {
3172 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3176 if (show_rc == NULL)
3177 cYAML_print_tree(root);
3179 if (l_errno != ENOENT) {
3182 "\"cannot get routing information: %s\"",
3187 rc = LUSTRE_CFG_RC_NO_ERR;
3189 snprintf(err_str, sizeof(err_str), "\"success\"");
3190 rc = LUSTRE_CFG_RC_NO_ERR;
3194 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3195 cYAML_free_tree(root);
3196 } else if (show_rc != NULL && *show_rc != NULL) {
3197 struct cYAML *routing_node;
3198 /* there should exist only one routing block and one
3199 * buffers block. If there already exists a previous one
3200 * then don't add another */
3201 routing_node = cYAML_get_object_item(*show_rc, "routing");
3202 if (routing_node == NULL) {
3203 cYAML_insert_sibling((*show_rc)->cy_child,
3207 cYAML_free_tree(root);
3213 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3218 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3219 struct cYAML **show_rc, struct cYAML **err_rc,
3223 * TODO: This function is changing in a future patch to accommodate
3224 * PEER_LIST and proper filtering on any nid of the peer
3226 struct lnet_ioctl_peer_cfg peer_info;
3227 struct lnet_peer_ni_credit_info *lpni_cri;
3228 struct lnet_ioctl_element_stats *lpni_stats;
3229 struct lnet_ioctl_element_msg_stats *msg_stats;
3230 struct lnet_ioctl_peer_ni_hstats *hstats;
3232 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3237 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3238 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3239 *msg_statistics = NULL, *statistics = NULL,
3241 char err_str[LNET_MAX_STR_LEN];
3242 struct lnet_process_id *list = NULL;
3247 snprintf(err_str, sizeof(err_str),
3248 "\"out of memory\"");
3250 /* create struct cYAML root object */
3251 root = cYAML_create_object(NULL, NULL);
3255 peer_root = cYAML_create_seq(root, "peer");
3256 if (peer_root == NULL)
3260 size = count * sizeof(struct lnet_process_id);
3261 list = malloc(size);
3267 list[0].nid = libcfs_str2nid(knid);
3271 memset(&peer_info, 0, sizeof(peer_info));
3272 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3273 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3274 peer_info.prcfg_size = size;
3275 peer_info.prcfg_bulk = list;
3278 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3280 count = peer_info.prcfg_count;
3284 if (l_errno != E2BIG) {
3287 "\"cannot get peer list: %s\"",
3293 size = peer_info.prcfg_size;
3294 list = malloc(size);
3303 data = malloc(size);
3309 for (i = 0; i < count; i++) {
3311 memset(&peer_info, 0, sizeof(peer_info));
3312 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3313 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3314 peer_info.prcfg_prim_nid = list[i].nid;
3315 peer_info.prcfg_size = size;
3316 peer_info.prcfg_bulk = data;
3319 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3324 if (l_errno != E2BIG) {
3327 "\"cannot get peer information: %s\"",
3333 size = peer_info.prcfg_size;
3334 data = malloc(size);
3342 peer = cYAML_create_seq_item(peer_root);
3346 if (first_seq == NULL)
3349 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3350 if (cYAML_create_string(peer, "primary nid",
3351 libcfs_nid2str(pnid))
3354 if (cYAML_create_string(peer, "Multi-Rail",
3355 peer_info.prcfg_mr ? "True" : "False")
3359 * print out the state of the peer only if details are
3364 cYAML_create_number(peer, "peer state",
3365 peer_info.prcfg_state)
3370 tmp = cYAML_create_seq(peer, "peer ni");
3375 for (j = 0; j < peer_info.prcfg_count; j++) {
3377 lpni_cri = (void*)nidp + sizeof(nidp);
3378 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3379 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3380 hstats = (void *)msg_stats + sizeof(*msg_stats);
3381 lpni_data = (void *)hstats + sizeof(*hstats);
3383 peer_ni = cYAML_create_seq_item(tmp);
3384 if (peer_ni == NULL)
3387 if (cYAML_create_string(peer_ni, "nid",
3388 libcfs_nid2str(*nidp))
3395 if (cYAML_create_string(peer_ni, "state",
3396 lpni_cri->cr_aliveness)
3403 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3404 lpni_cri->cr_ni_peer_tx_credits)
3408 if (cYAML_create_number(peer_ni, "available_tx_credits",
3409 lpni_cri->cr_peer_tx_credits)
3413 if (cYAML_create_number(peer_ni, "min_tx_credits",
3414 lpni_cri->cr_peer_min_tx_credits)
3418 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3419 lpni_cri->cr_peer_tx_qnob)
3423 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3424 lpni_cri->cr_peer_rtr_credits)
3428 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3429 lpni_cri->cr_peer_min_rtr_credits)
3433 if (cYAML_create_number(peer_ni, "refcount",
3434 lpni_cri->cr_refcount) == NULL)
3437 statistics = cYAML_create_object(peer_ni, "statistics");
3438 if (statistics == NULL)
3441 if (cYAML_create_number(statistics, "send_count",
3442 lpni_stats->iel_send_count)
3446 if (cYAML_create_number(statistics, "recv_count",
3447 lpni_stats->iel_recv_count)
3451 if (cYAML_create_number(statistics, "drop_count",
3452 lpni_stats->iel_drop_count)
3459 for (k = 0; k < 3; k++) {
3460 struct lnet_ioctl_comm_count *counts;
3462 msg_statistics = cYAML_create_object(peer_ni,
3463 (char *) gmsg_stat_names[k]);
3464 if (msg_statistics == NULL)
3467 counts = get_counts(msg_stats, k);
3471 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3476 yhstats = cYAML_create_object(peer_ni, "health stats");
3479 if (cYAML_create_number(yhstats, "health value",
3480 hstats->hlpni_health_value)
3483 if (cYAML_create_number(yhstats, "dropped",
3484 hstats->hlpni_remote_dropped)
3487 if (cYAML_create_number(yhstats, "timeout",
3488 hstats->hlpni_remote_timeout)
3491 if (cYAML_create_number(yhstats, "error",
3492 hstats->hlpni_remote_error)
3495 if (cYAML_create_number(yhstats, "network timeout",
3496 hstats->hlpni_network_timeout)
3502 /* print output iff show_rc is not provided */
3503 if (show_rc == NULL)
3504 cYAML_print_tree(root);
3506 snprintf(err_str, sizeof(err_str), "\"success\"");
3507 rc = LUSTRE_CFG_RC_NO_ERR;
3512 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3513 cYAML_free_tree(root);
3514 } else if (show_rc != NULL && *show_rc != NULL) {
3515 struct cYAML *show_node;
3516 /* find the peer node, if one doesn't exist then
3517 * insert one. Otherwise add to the one there
3519 show_node = cYAML_get_object_item(*show_rc,
3521 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3522 cYAML_insert_child(show_node, first_seq);
3525 } else if (show_node == NULL) {
3526 cYAML_insert_sibling((*show_rc)->cy_child,
3530 cYAML_free_tree(root);
3536 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3542 int lustre_lnet_list_peer(int seq_no,
3543 struct cYAML **show_rc, struct cYAML **err_rc)
3545 struct lnet_ioctl_peer_cfg peer_info;
3546 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3551 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3552 char err_str[LNET_MAX_STR_LEN];
3553 struct lnet_process_id *list = NULL;
3555 snprintf(err_str, sizeof(err_str),
3556 "\"out of memory\"");
3558 memset(&peer_info, 0, sizeof(peer_info));
3560 /* create struct cYAML root object */
3561 root = cYAML_create_object(NULL, NULL);
3565 list_root = cYAML_create_seq(root, "peer list");
3566 if (list_root == NULL)
3570 size = count * sizeof(struct lnet_process_id);
3571 list = malloc(size);
3577 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3578 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3579 peer_info.prcfg_size = size;
3580 peer_info.prcfg_bulk = list;
3583 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3584 count = peer_info.prcfg_count;
3588 if (l_errno != E2BIG) {
3591 "\"cannot get peer list: %s\"",
3597 size = peer_info.prcfg_size;
3598 list = malloc(size);
3605 /* count is now the actual number of ids in the list. */
3606 for (i = 0; i < count; i++) {
3607 if (cYAML_create_string(list_root, "nid",
3608 libcfs_nid2str(list[i].nid))
3613 /* print output iff show_rc is not provided */
3614 if (show_rc == NULL)
3615 cYAML_print_tree(root);
3617 snprintf(err_str, sizeof(err_str), "\"success\"");
3618 rc = LUSTRE_CFG_RC_NO_ERR;
3623 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3624 cYAML_free_tree(root);
3625 } else if (show_rc != NULL && *show_rc != NULL) {
3626 struct cYAML *show_node;
3627 /* find the peer node, if one doesn't exist then
3628 * insert one. Otherwise add to the one there
3630 show_node = cYAML_get_object_item(*show_rc,
3632 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3633 cYAML_insert_child(show_node, first_seq);
3636 } else if (show_node == NULL) {
3637 cYAML_insert_sibling((*show_rc)->cy_child,
3641 cYAML_free_tree(root);
3647 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3653 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3656 struct cYAML *show_node;
3658 show_node = cYAML_get_object_item(show_rc, "global");
3659 if (show_node != NULL)
3660 cYAML_insert_sibling(show_node->cy_child,
3663 cYAML_insert_sibling(show_rc->cy_child,
3668 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3669 char *name, __u32 value,
3670 struct cYAML **show_rc,
3671 struct cYAML **err_rc, int err)
3673 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3674 struct cYAML *root = NULL, *global = NULL;
3681 root = cYAML_create_object(NULL, NULL);
3685 global = cYAML_create_object(root, "global");
3689 if (cYAML_create_number(global, name,
3693 if (show_rc == NULL)
3694 cYAML_print_tree(root);
3696 snprintf(err_str, err_len, "\"success\"");
3698 rc = LUSTRE_CFG_RC_NO_ERR;
3701 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3702 cYAML_free_tree(root);
3703 } else if (show_rc != NULL && *show_rc != NULL) {
3704 add_to_global(*show_rc, global, root);
3709 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3714 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3715 struct cYAML **show_rc,
3716 struct cYAML **err_rc)
3718 struct lnet_ioctl_set_value data;
3721 char err_str[LNET_MAX_STR_LEN];
3723 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3725 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3727 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3732 "\"cannot get %s: %s\"",
3733 name, strerror(l_errno));
3736 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3737 data.sv_value, show_rc, err_rc, l_errno);
3740 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3741 struct cYAML **err_rc)
3743 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3744 char val[LNET_MAX_STR_LEN];
3745 int intrv = -1, l_errno = 0;
3746 char err_str[LNET_MAX_STR_LEN];
3748 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3750 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3754 snprintf(err_str, sizeof(err_str),
3755 "\"cannot get recovery interval: %d\"", rc);
3760 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3761 "recovery_interval", intrv, show_rc,
3765 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3766 struct cYAML **err_rc)
3768 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3769 char val[LNET_MAX_STR_LEN];
3770 int sen = -1, l_errno = 0;
3771 char err_str[LNET_MAX_STR_LEN];
3773 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3775 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3779 snprintf(err_str, sizeof(err_str),
3780 "\"cannot get health sensitivity: %d\"", rc);
3785 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3786 "health_sensitivity", sen, show_rc,
3790 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3791 struct cYAML **err_rc)
3793 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3794 char val[LNET_MAX_STR_LEN];
3795 int sen = -1, l_errno = 0;
3796 char err_str[LNET_MAX_STR_LEN];
3798 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3800 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3804 snprintf(err_str, sizeof(err_str),
3805 "\"cannot get router sensitivity percentage: %d\"", rc);
3810 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3811 "router_sensitivity", sen, show_rc,
3815 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3816 struct cYAML **err_rc)
3818 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3819 char val[LNET_MAX_STR_LEN];
3820 int tto = -1, l_errno = 0;
3821 char err_str[LNET_MAX_STR_LEN];
3823 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3825 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3829 snprintf(err_str, sizeof(err_str),
3830 "\"cannot get transaction timeout: %d\"", rc);
3835 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3836 "transaction_timeout", tto, show_rc,
3840 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3841 struct cYAML **err_rc)
3843 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3844 char val[LNET_MAX_STR_LEN];
3845 int retry_count = -1, l_errno = 0;
3846 char err_str[LNET_MAX_STR_LEN];
3848 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3850 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3854 snprintf(err_str, sizeof(err_str),
3855 "\"cannot get retry count: %d\"", rc);
3857 retry_count = atoi(val);
3860 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3861 "retry_count", retry_count, show_rc,
3865 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3866 struct cYAML **show_rc, struct cYAML **err_rc)
3868 struct lnet_ioctl_recovery_list nid_list;
3869 struct cYAML *root = NULL, *nids = NULL;
3871 char err_str[LNET_MAX_STR_LEN];
3873 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3875 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3876 nid_list.rlst_type = type;
3878 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3884 if (nid_list.rlst_num_nids == 0)
3887 root = cYAML_create_object(NULL, NULL);
3891 nids = cYAML_create_object(root, name);
3897 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3898 char nidenum[LNET_MAX_STR_LEN];
3899 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3900 if (!cYAML_create_string(nids, nidenum,
3901 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3905 snprintf(err_str, sizeof(err_str), "success\n");
3910 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3911 cYAML_free_tree(root);
3912 } else if (show_rc != NULL && *show_rc != NULL) {
3913 struct cYAML *show_node;
3914 /* find the net node, if one doesn't exist
3915 * then insert one. Otherwise add to the one there
3917 show_node = cYAML_get_object_item(*show_rc, name);
3918 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3919 cYAML_insert_child(show_node, nids);
3922 } else if (show_node == NULL) {
3923 cYAML_insert_sibling((*show_rc)->cy_child,
3927 cYAML_free_tree(root);
3933 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3938 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3939 struct cYAML **err_rc)
3941 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3942 seq_no, show_rc, err_rc);
3945 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3946 struct cYAML **err_rc)
3948 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3949 seq_no, show_rc, err_rc);
3952 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3953 struct cYAML **err_rc)
3955 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3956 char val[LNET_MAX_STR_LEN];
3957 int max_intf = -1, l_errno = 0;
3958 char err_str[LNET_MAX_STR_LEN];
3960 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3962 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3966 snprintf(err_str, sizeof(err_str),
3967 "\"cannot get max interfaces: %d\"", rc);
3969 max_intf = atoi(val);
3972 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3973 "max_intf", max_intf, show_rc,
3977 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3978 struct cYAML **err_rc)
3980 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3981 char val[LNET_MAX_STR_LEN];
3982 int discovery = -1, l_errno = 0;
3983 char err_str[LNET_MAX_STR_LEN];
3985 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3987 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3991 snprintf(err_str, sizeof(err_str),
3992 "\"cannot get discovery setting: %d\"", rc);
3995 * The kernel stores a discovery disabled value. User space
3996 * shows whether discovery is enabled. So the value must be
3999 discovery = !atoi(val);
4002 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4003 "discovery", discovery, show_rc,
4007 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4008 struct cYAML **err_rc)
4010 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4011 char val[LNET_MAX_STR_LEN];
4012 int drop_asym_route = -1, l_errno = 0;
4013 char err_str[LNET_MAX_STR_LEN];
4015 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4017 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4021 snprintf(err_str, sizeof(err_str),
4022 "\"cannot get drop asym route setting: %d\"", rc);
4024 drop_asym_route = atoi(val);
4027 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4028 "drop_asym_route", drop_asym_route,
4029 show_rc, err_rc, l_errno);
4032 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4033 struct cYAML **err_rc)
4035 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4036 "numa_range", show_rc, err_rc);
4039 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4040 struct cYAML **err_rc)
4042 struct lnet_ioctl_lnet_stats data;
4043 struct lnet_counters *cntrs;
4046 char err_str[LNET_MAX_STR_LEN];
4047 struct cYAML *root = NULL, *stats = NULL;
4049 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4051 LIBCFS_IOC_INIT_V2(data, st_hdr);
4053 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4058 "\"cannot get lnet statistics: %s\"",
4064 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4066 cntrs = &data.st_cntrs;
4068 root = cYAML_create_object(NULL, NULL);
4072 stats = cYAML_create_object(root, "statistics");
4076 if (!cYAML_create_number(stats, "msgs_alloc",
4077 cntrs->lct_common.lcc_msgs_alloc))
4080 if (!cYAML_create_number(stats, "msgs_max",
4081 cntrs->lct_common.lcc_msgs_max))
4084 if (!cYAML_create_number(stats, "rst_alloc",
4085 cntrs->lct_health.lch_rst_alloc))
4088 if (!cYAML_create_number(stats, "errors",
4089 cntrs->lct_common.lcc_errors))
4092 if (!cYAML_create_number(stats, "send_count",
4093 cntrs->lct_common.lcc_send_count))
4096 if (!cYAML_create_number(stats, "resend_count",
4097 cntrs->lct_health.lch_resend_count))
4100 if (!cYAML_create_number(stats, "response_timeout_count",
4101 cntrs->lct_health.lch_response_timeout_count))
4104 if (!cYAML_create_number(stats, "local_interrupt_count",
4105 cntrs->lct_health.lch_local_interrupt_count))
4108 if (!cYAML_create_number(stats, "local_dropped_count",
4109 cntrs->lct_health.lch_local_dropped_count))
4112 if (!cYAML_create_number(stats, "local_aborted_count",
4113 cntrs->lct_health.lch_local_aborted_count))
4116 if (!cYAML_create_number(stats, "local_no_route_count",
4117 cntrs->lct_health.lch_local_no_route_count))
4120 if (!cYAML_create_number(stats, "local_timeout_count",
4121 cntrs->lct_health.lch_local_timeout_count))
4124 if (!cYAML_create_number(stats, "local_error_count",
4125 cntrs->lct_health.lch_local_error_count))
4128 if (!cYAML_create_number(stats, "remote_dropped_count",
4129 cntrs->lct_health.lch_remote_dropped_count))
4132 if (!cYAML_create_number(stats, "remote_error_count",
4133 cntrs->lct_health.lch_remote_error_count))
4136 if (!cYAML_create_number(stats, "remote_timeout_count",
4137 cntrs->lct_health.lch_remote_timeout_count))
4140 if (!cYAML_create_number(stats, "network_timeout_count",
4141 cntrs->lct_health.lch_network_timeout_count))
4144 if (!cYAML_create_number(stats, "recv_count",
4145 cntrs->lct_common.lcc_recv_count))
4148 if (!cYAML_create_number(stats, "route_count",
4149 cntrs->lct_common.lcc_route_count))
4152 if (!cYAML_create_number(stats, "drop_count",
4153 cntrs->lct_common.lcc_drop_count))
4156 if (!cYAML_create_number(stats, "send_length",
4157 cntrs->lct_common.lcc_send_length))
4160 if (!cYAML_create_number(stats, "recv_length",
4161 cntrs->lct_common.lcc_recv_length))
4164 if (!cYAML_create_number(stats, "route_length",
4165 cntrs->lct_common.lcc_route_length))
4168 if (!cYAML_create_number(stats, "drop_length",
4169 cntrs->lct_common.lcc_drop_length))
4173 cYAML_print_tree(root);
4175 snprintf(err_str, sizeof(err_str), "\"success\"");
4176 rc = LUSTRE_CFG_RC_NO_ERR;
4178 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4179 cYAML_free_tree(root);
4180 } else if (show_rc != NULL && *show_rc != NULL) {
4181 cYAML_insert_sibling((*show_rc)->cy_child,
4188 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4193 typedef int (*cmd_handler_t)(struct cYAML *tree,
4194 struct cYAML **show_rc,
4195 struct cYAML **err_rc);
4197 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4198 struct cYAML **err_rc)
4200 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4202 net = cYAML_get_object_item(tree, "net");
4203 gw = cYAML_get_object_item(tree, "gateway");
4204 hop = cYAML_get_object_item(tree, "hop");
4205 prio = cYAML_get_object_item(tree, "priority");
4206 sen = cYAML_get_object_item(tree, "health_sensitivity");
4207 seq_no = cYAML_get_object_item(tree, "seq_no");
4209 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4210 (gw) ? gw->cy_valuestring : NULL,
4211 (hop) ? hop->cy_valueint : -1,
4212 (prio) ? prio->cy_valueint : -1,
4213 (sen) ? sen->cy_valueint : -1,
4214 (seq_no) ? seq_no->cy_valueint : -1,
4220 * 0: <intf_name>['['<expr>']']
4221 * 1: <intf_name>['['<expr>']']
4223 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4224 struct lnet_dlc_network_descr *nw_descr)
4226 struct cYAML *child = NULL;
4227 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4228 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4230 if (intf_tree == NULL || nw_descr == NULL)
4231 return LUSTRE_CFG_RC_BAD_PARAM;
4233 /* now grab all the interfaces and their cpts */
4234 child = intf_tree->cy_child;
4235 while (child != NULL) {
4236 if (child->cy_valuestring == NULL) {
4237 child = child->cy_next;
4241 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4244 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4245 child->cy_valuestring,
4246 strlen(child->cy_valuestring));
4247 if (rc != LUSTRE_CFG_RC_NO_ERR)
4251 child = child->cy_next;
4255 return LUSTRE_CFG_RC_MISSING_PARAM;
4260 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4262 list_del(&intf_descr->intf_on_network);
4263 free_intf_descr(intf_descr);
4270 yaml_extract_cmn_tunables(struct cYAML *tree,
4271 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4272 struct cfs_expr_list **global_cpts)
4274 struct cYAML *tun, *item, *smp;
4277 tun = cYAML_get_object_item(tree, "tunables");
4279 item = cYAML_get_object_item(tun, "peer_timeout");
4281 tunables->lct_peer_timeout = item->cy_valueint;
4282 item = cYAML_get_object_item(tun, "peer_credits");
4284 tunables->lct_peer_tx_credits = item->cy_valueint;
4285 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4287 tunables->lct_peer_rtr_credits = item->cy_valueint;
4288 item = cYAML_get_object_item(tun, "credits");
4290 tunables->lct_max_tx_credits = item->cy_valueint;
4291 smp = cYAML_get_object_item(tun, "CPT");
4293 rc = cfs_expr_list_parse(smp->cy_valuestring,
4294 strlen(smp->cy_valuestring),
4295 0, UINT_MAX, global_cpts);
4297 *global_cpts = NULL;
4307 yaml_extract_tunables(struct cYAML *tree,
4308 struct lnet_ioctl_config_lnd_tunables *tunables,
4309 struct cfs_expr_list **global_cpts,
4314 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4320 lustre_yaml_extract_lnd_tunables(tree, net_type,
4328 * - net type: <net>[<NUM>]
4330 * - nid: <ip>@<net>[<NUM>]
4333 * 0: <intf_name>['['<expr>']']
4334 * 1: <intf_name>['['<expr>']']
4336 * peer_timeout: <NUM>
4337 * peer_credits: <NUM>
4338 * peer_buffer_credits: <NUM>
4341 * peercredits_hiw: <NUM>
4342 * map_on_demand: <NUM>
4343 * concurrent_sends: <NUM>
4344 * fmr_pool_size: <NUM>
4345 * fmr_flush_trigger: <NUM>
4348 * At least one interface is required. If no interfaces are provided the
4349 * network interface can not be configured.
4351 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4352 struct cYAML **err_rc)
4354 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4356 int num_entries = 0, rc;
4357 struct lnet_dlc_network_descr nw_descr;
4358 struct cfs_expr_list *global_cpts = NULL;
4359 struct lnet_ioctl_config_lnd_tunables tunables;
4362 memset(&tunables, 0, sizeof(tunables));
4364 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4365 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4367 ip2net = cYAML_get_object_item(tree, "ip2net");
4368 net = cYAML_get_object_item(tree, "net type");
4370 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4372 nw_descr.nw_id = LOLND;
4375 * if neither net nor ip2nets are present, then we can not
4376 * configure the network.
4378 if (!net && !ip2net)
4379 return LUSTRE_CFG_RC_MISSING_PARAM;
4381 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4382 if (local_nis == NULL)
4383 return LUSTRE_CFG_RC_MISSING_PARAM;
4385 if (!cYAML_is_sequence(local_nis))
4386 return LUSTRE_CFG_RC_BAD_PARAM;
4388 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4389 intf = cYAML_get_object_item(item, "interfaces");
4392 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4393 if (num_entries <= 0) {
4394 cYAML_build_error(num_entries, -1, "ni", "add",
4395 "bad interface list",
4397 return LUSTRE_CFG_RC_BAD_PARAM;
4401 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4402 LNET_NETTYP(nw_descr.nw_id));
4403 seq_no = cYAML_get_object_item(tree, "seq_no");
4405 rc = lustre_lnet_config_ni(&nw_descr,
4407 (ip2net) ? ip2net->cy_valuestring : NULL,
4408 (found) ? &tunables: NULL,
4409 (seq_no) ? seq_no->cy_valueint : -1,
4412 if (global_cpts != NULL)
4413 cfs_expr_list_free(global_cpts);
4420 * - net-spec: <tcp|o2ib|gni>[NUM]
4422 * 0: <intf name>['['<expr>']']
4423 * 1: <intf name>['['<expr>']']
4425 * 0: <expr.expr.expr.expr>
4426 * 1: <expr.expr.expr.expr>
4428 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4429 struct cYAML **show_rc,
4430 struct cYAML **err_rc)
4432 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4434 struct lustre_lnet_ip2nets ip2nets;
4435 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4437 int rc = LUSTRE_CFG_RC_NO_ERR;
4438 struct cfs_expr_list *global_cpts = NULL;
4439 struct cfs_expr_list *el, *el_tmp;
4440 struct lnet_ioctl_config_lnd_tunables tunables;
4441 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4444 memset(&tunables, 0, sizeof(tunables));
4446 /* initialize all lists */
4447 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4448 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4449 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4451 net = cYAML_get_object_item(tree, "net-spec");
4453 return LUSTRE_CFG_RC_BAD_PARAM;
4455 if (net != NULL && net->cy_valuestring == NULL)
4456 return LUSTRE_CFG_RC_BAD_PARAM;
4458 /* assign the network id */
4459 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4460 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4461 return LUSTRE_CFG_RC_BAD_PARAM;
4463 seq_no = cYAML_get_object_item(tree, "seq_no");
4465 intf = cYAML_get_object_item(tree, "interfaces");
4467 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4469 return LUSTRE_CFG_RC_BAD_PARAM;
4472 ip_range = cYAML_get_object_item(tree, "ip-range");
4473 if (ip_range != NULL) {
4474 item = ip_range->cy_child;
4475 while (item != NULL) {
4476 if (item->cy_valuestring == NULL) {
4477 item = item->cy_next;
4481 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4482 item->cy_valuestring);
4484 if (rc != LUSTRE_CFG_RC_NO_ERR)
4487 item = item->cy_next;
4491 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4492 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4494 rc = lustre_lnet_config_ip2nets(&ip2nets,
4495 (found) ? &tunables : NULL,
4497 (seq_no) ? seq_no->cy_valueint : -1,
4501 * don't stop because there was no match. Continue processing the
4502 * rest of the rules. If non-match then nothing is configured
4504 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4505 rc = LUSTRE_CFG_RC_NO_ERR;
4507 list_for_each_entry_safe(intf_descr, intf_tmp,
4508 &ip2nets.ip2nets_net.nw_intflist,
4510 list_del(&intf_descr->intf_on_network);
4511 free_intf_descr(intf_descr);
4514 list_for_each_entry_safe(ip_range_descr, tmp,
4515 &ip2nets.ip2nets_ip_ranges,
4517 list_del(&ip_range_descr->ipr_entry);
4518 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4520 list_del(&el->el_link);
4521 cfs_expr_list_free(el);
4523 free(ip_range_descr);
4529 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4530 struct cYAML **err_rc)
4532 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4534 int num_entries, rc;
4535 struct lnet_dlc_network_descr nw_descr;
4537 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4538 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4540 net = cYAML_get_object_item(tree, "net type");
4542 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4544 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4545 if (local_nis == NULL)
4546 return LUSTRE_CFG_RC_MISSING_PARAM;
4548 if (!cYAML_is_sequence(local_nis))
4549 return LUSTRE_CFG_RC_BAD_PARAM;
4551 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4552 intf = cYAML_get_object_item(item, "interfaces");
4555 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4556 if (num_entries <= 0) {
4557 cYAML_build_error(num_entries, -1, "ni", "add",
4558 "bad interface list",
4560 return LUSTRE_CFG_RC_BAD_PARAM;
4564 seq_no = cYAML_get_object_item(tree, "seq_no");
4566 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4567 (seq_no) ? seq_no->cy_valueint : -1,
4573 /* Create a nidstring parseable by the nidstrings library from the nid
4574 * information encoded in the CYAML structure.
4575 * NOTE: Caller must free memory allocated to nidstr
4577 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4578 char *prim_nid, int cmd)
4580 int num_strs = 0, rc;
4581 size_t buf_size, buf_pos, nidstr_len = 0;
4583 struct cYAML *child = NULL, *entry = NULL;
4585 if (cYAML_is_sequence(nids_entry)) {
4586 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4587 entry = cYAML_get_object_item(child, "nid");
4588 /* don't count an empty entry */
4589 if (!entry || !entry->cy_valuestring)
4593 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4594 if (cmd == LNETCTL_DEL_CMD) {
4596 * primary nid is present in the list of
4597 * nids so that means we want to delete
4598 * the entire peer, so no need to go
4599 * further. Just delete the entire peer.
4601 return LUSTRE_CFG_RC_NO_ERR;
4608 * + 1 for the space separating each string, and
4609 * accounts for the terminating null char
4611 nidstr_len += strlen(entry->cy_valuestring) + 1;
4616 if (num_strs == 0 && !prim_nid)
4617 return LUSTRE_CFG_RC_MISSING_PARAM;
4618 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4619 return LUSTRE_CFG_RC_NO_ERR;
4621 buffer = malloc(nidstr_len);
4623 return LUSTRE_CFG_RC_OUT_OF_MEM;
4625 /* now grab all the nids */
4628 buf_size = nidstr_len;
4630 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4631 entry = cYAML_get_object_item(child, "nid");
4632 if (!entry || !entry->cy_valuestring)
4636 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4640 rc = snprintf(buffer + buf_pos, buf_size, " ");
4641 buf_pos += (rc < buf_size) ? rc : buf_size;
4642 buf_size = nidstr_len - buf_pos;
4645 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4646 entry->cy_valuestring);
4647 buf_pos += (rc < buf_size) ? rc : buf_size;
4648 buf_size = nidstr_len - buf_pos;
4653 return LUSTRE_CFG_RC_NO_ERR;
4656 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4657 struct cYAML **err_rc, int cmd)
4659 int rc, num_nids = 0, seqn;
4661 char *nidstr = NULL, *prim_nidstr;
4662 char err_str[LNET_MAX_STR_LEN];
4663 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4664 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4666 seq_no = cYAML_get_object_item(tree, "seq_no");
4667 seqn = seq_no ? seq_no->cy_valueint : -1;
4669 prim_nid = cYAML_get_object_item(tree, "primary nid");
4670 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4672 peer_nis = cYAML_get_object_item(tree, "peer ni");
4673 if (!(prim_nid || peer_nis)) {
4674 rc = LUSTRE_CFG_RC_BAD_PARAM;
4675 snprintf(err_str, LNET_MAX_STR_LEN,
4676 "Neither \"primary nid\" nor \"peer ni\" are defined");
4680 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4681 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4682 snprintf(err_str, LNET_MAX_STR_LEN,
4683 "No nids defined in YAML block");
4685 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4686 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4688 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4689 snprintf(err_str, LNET_MAX_STR_LEN,
4690 "Unrecognized error %d", rc);
4696 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4697 LNET_MAX_NIDS_PER_PEER,
4705 if (cmd == LNETCTL_ADD_CMD) {
4706 mr = cYAML_get_object_item(tree, "Multi-Rail");
4708 if (mr && mr->cy_valuestring) {
4709 if (strcmp(mr->cy_valuestring, "False") == 0)
4711 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4712 rc = LUSTRE_CFG_RC_BAD_PARAM;
4713 snprintf(err_str, LNET_MAX_STR_LEN,
4714 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4715 mr->cy_valuestring);
4720 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4721 num_nids, mr_value, seqn,
4724 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4725 num_nids, seqn, err_rc);
4731 if (rc != LUSTRE_CFG_RC_NO_ERR)
4732 cYAML_build_error(rc, seqn, "peer",
4733 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4739 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4740 struct cYAML **err_rc)
4742 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4745 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4746 struct cYAML **err_rc)
4748 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4751 static int handle_yaml_config_buffers(struct cYAML *tree,
4752 struct cYAML **show_rc,
4753 struct cYAML **err_rc)
4756 struct cYAML *tiny, *small, *large, *seq_no;
4758 tiny = cYAML_get_object_item(tree, "tiny");
4759 small = cYAML_get_object_item(tree, "small");
4760 large = cYAML_get_object_item(tree, "large");
4761 seq_no = cYAML_get_object_item(tree, "seq_no");
4763 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4764 (small) ? small->cy_valueint : -1,
4765 (large) ? large->cy_valueint : -1,
4766 (seq_no) ? seq_no->cy_valueint : -1,
4772 static int handle_yaml_config_routing(struct cYAML *tree,
4773 struct cYAML **show_rc,
4774 struct cYAML **err_rc)
4776 int rc = LUSTRE_CFG_RC_NO_ERR;
4777 struct cYAML *seq_no, *enable;
4779 seq_no = cYAML_get_object_item(tree, "seq_no");
4780 enable = cYAML_get_object_item(tree, "enable");
4783 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4785 seq_no->cy_valueint : -1,
4792 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4793 struct cYAML **err_rc)
4797 struct cYAML *seq_no;
4799 net = cYAML_get_object_item(tree, "net");
4800 gw = cYAML_get_object_item(tree, "gateway");
4801 seq_no = cYAML_get_object_item(tree, "seq_no");
4803 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4804 (gw) ? gw->cy_valuestring : NULL,
4805 (seq_no) ? seq_no->cy_valueint : -1,
4809 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4810 struct cYAML **err_rc)
4812 struct cYAML *seq_no;
4814 seq_no = cYAML_get_object_item(tree, "seq_no");
4816 return lustre_lnet_enable_routing(0, (seq_no) ?
4817 seq_no->cy_valueint : -1,
4821 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4822 struct cYAML **err_rc)
4828 struct cYAML *detail;
4829 struct cYAML *seq_no;
4831 net = cYAML_get_object_item(tree, "net");
4832 gw = cYAML_get_object_item(tree, "gateway");
4833 hop = cYAML_get_object_item(tree, "hop");
4834 prio = cYAML_get_object_item(tree, "priority");
4835 detail = cYAML_get_object_item(tree, "detail");
4836 seq_no = cYAML_get_object_item(tree, "seq_no");
4838 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4839 (gw) ? gw->cy_valuestring : NULL,
4840 (hop) ? hop->cy_valueint : -1,
4841 (prio) ? prio->cy_valueint : -1,
4842 (detail) ? detail->cy_valueint : 0,
4843 (seq_no) ? seq_no->cy_valueint : -1,
4844 show_rc, err_rc, false);
4847 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4848 struct cYAML **err_rc)
4850 struct cYAML *net, *detail, *seq_no;
4852 net = cYAML_get_object_item(tree, "net");
4853 detail = cYAML_get_object_item(tree, "detail");
4854 seq_no = cYAML_get_object_item(tree, "seq_no");
4856 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4857 (detail) ? detail->cy_valueint : 0,
4858 (seq_no) ? seq_no->cy_valueint : -1,
4859 show_rc, err_rc, false);
4862 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4863 struct cYAML **err_rc)
4865 struct cYAML *seq_no;
4867 seq_no = cYAML_get_object_item(tree, "seq_no");
4869 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4870 show_rc, err_rc, false);
4873 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4874 struct cYAML **err_rc)
4876 struct cYAML *seq_no, *nid, *detail;
4878 seq_no = cYAML_get_object_item(tree, "seq_no");
4879 detail = cYAML_get_object_item(tree, "detail");
4880 nid = cYAML_get_object_item(tree, "nid");
4882 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4883 (detail) ? detail->cy_valueint : 0,
4884 (seq_no) ? seq_no->cy_valueint : -1,
4885 show_rc, err_rc, false);
4888 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4889 struct cYAML **err_rc)
4891 struct cYAML *seq_no;
4893 seq_no = cYAML_get_object_item(tree, "seq_no");
4895 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4899 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4900 struct cYAML **err_rc)
4902 struct cYAML *seq_no, *range;
4904 seq_no = cYAML_get_object_item(tree, "seq_no");
4905 range = cYAML_get_object_item(tree, "range");
4907 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4908 seq_no ? seq_no->cy_valueint : -1,
4912 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4913 struct cYAML **err_rc)
4915 struct cYAML *seq_no;
4917 seq_no = cYAML_get_object_item(tree, "seq_no");
4919 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4923 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4924 struct cYAML **err_rc)
4926 struct cYAML *seq_no;
4928 seq_no = cYAML_get_object_item(tree, "seq_no");
4930 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4934 static int handle_yaml_config_global_settings(struct cYAML *tree,
4935 struct cYAML **show_rc,
4936 struct cYAML **err_rc)
4938 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4939 *sen, *recov, *rsen, *drop_asym_route;
4942 seq_no = cYAML_get_object_item(tree, "seq_no");
4943 max_intf = cYAML_get_object_item(tree, "max_intf");
4945 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4946 seq_no ? seq_no->cy_valueint
4950 numa = cYAML_get_object_item(tree, "numa_range");
4952 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4953 seq_no ? seq_no->cy_valueint
4957 discovery = cYAML_get_object_item(tree, "discovery");
4959 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4960 seq_no ? seq_no->cy_valueint
4964 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4965 if (drop_asym_route)
4966 rc = lustre_lnet_config_drop_asym_route(
4967 drop_asym_route->cy_valueint,
4968 seq_no ? seq_no->cy_valueint : -1,
4971 retry = cYAML_get_object_item(tree, "retry_count");
4973 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4974 seq_no ? seq_no->cy_valueint
4978 tto = cYAML_get_object_item(tree, "transaction_timeout");
4980 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4981 seq_no ? seq_no->cy_valueint
4985 sen = cYAML_get_object_item(tree, "health_sensitivity");
4987 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4988 seq_no ? seq_no->cy_valueint
4992 recov = cYAML_get_object_item(tree, "recovery_interval");
4994 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4995 seq_no ? seq_no->cy_valueint
4999 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5001 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5002 seq_no ? seq_no->cy_valueint
5009 static int handle_yaml_del_global_settings(struct cYAML *tree,
5010 struct cYAML **show_rc,
5011 struct cYAML **err_rc)
5013 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5016 seq_no = cYAML_get_object_item(tree, "seq_no");
5017 max_intf = cYAML_get_object_item(tree, "max_intf");
5019 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5020 seq_no ? seq_no->cy_valueint
5024 numa = cYAML_get_object_item(tree, "numa_range");
5026 rc = lustre_lnet_config_numa_range(0,
5027 seq_no ? seq_no->cy_valueint
5031 /* peer discovery is enabled by default */
5032 discovery = cYAML_get_object_item(tree, "discovery");
5034 rc = lustre_lnet_config_discovery(1,
5035 seq_no ? seq_no->cy_valueint
5039 /* asymmetrical route messages are accepted by default */
5040 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5041 if (drop_asym_route)
5042 rc = lustre_lnet_config_drop_asym_route(
5043 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5048 static int handle_yaml_show_global_settings(struct cYAML *tree,
5049 struct cYAML **show_rc,
5050 struct cYAML **err_rc)
5052 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5053 *sen, *recov, *rsen, *drop_asym_route;
5056 seq_no = cYAML_get_object_item(tree, "seq_no");
5057 max_intf = cYAML_get_object_item(tree, "max_intf");
5059 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5063 numa = cYAML_get_object_item(tree, "numa_range");
5065 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5069 discovery = cYAML_get_object_item(tree, "discovery");
5071 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5075 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5076 if (drop_asym_route)
5077 rc = lustre_lnet_show_drop_asym_route(
5078 seq_no ? seq_no->cy_valueint : -1,
5081 retry = cYAML_get_object_item(tree, "retry_count");
5083 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5087 tto = cYAML_get_object_item(tree, "transaction_timeout");
5089 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5093 sen = cYAML_get_object_item(tree, "health_sensitivity");
5095 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5099 recov = cYAML_get_object_item(tree, "recovery_interval");
5101 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5105 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5107 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5114 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5115 struct cYAML **err_rc)
5117 struct cYAML *seq_no, *nid, *timeout;
5119 seq_no = cYAML_get_object_item(tree, "seq_no");
5120 nid = cYAML_get_object_item(tree, "primary nid");
5121 timeout = cYAML_get_object_item(tree, "timeout");
5123 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5124 (timeout) ? timeout->cy_valueint : 1000,
5125 (seq_no) ? seq_no->cy_valueint : -1,
5129 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5130 struct cYAML **err_rc)
5132 struct cYAML *seq_no, *nid, *force;
5134 seq_no = cYAML_get_object_item(tree, "seq_no");
5135 nid = cYAML_get_object_item(tree, "primary nid");
5136 force = cYAML_get_object_item(tree, "force");
5138 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5139 (force) ? force->cy_valueint : 0,
5140 (seq_no) ? seq_no->cy_valueint : -1,
5144 static int handle_yaml_no_op()
5146 return LUSTRE_CFG_RC_NO_ERR;
5149 struct lookup_cmd_hdlr_tbl {
5154 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5155 { .name = "route", .cb = handle_yaml_config_route },
5156 { .name = "net", .cb = handle_yaml_config_ni },
5157 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5158 { .name = "peer", .cb = handle_yaml_config_peer },
5159 { .name = "routing", .cb = handle_yaml_config_routing },
5160 { .name = "buffers", .cb = handle_yaml_config_buffers },
5161 { .name = "statistics", .cb = handle_yaml_no_op },
5162 { .name = "global", .cb = handle_yaml_config_global_settings},
5163 { .name = "numa", .cb = handle_yaml_config_numa },
5164 { .name = "ping", .cb = handle_yaml_no_op },
5165 { .name = "discover", .cb = handle_yaml_no_op },
5168 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5169 { .name = "route", .cb = handle_yaml_del_route },
5170 { .name = "net", .cb = handle_yaml_del_ni },
5171 { .name = "ip2nets", .cb = handle_yaml_no_op },
5172 { .name = "peer", .cb = handle_yaml_del_peer },
5173 { .name = "routing", .cb = handle_yaml_del_routing },
5174 { .name = "buffers", .cb = handle_yaml_no_op },
5175 { .name = "statistics", .cb = handle_yaml_no_op },
5176 { .name = "global", .cb = handle_yaml_del_global_settings},
5177 { .name = "numa", .cb = handle_yaml_del_numa },
5178 { .name = "ping", .cb = handle_yaml_no_op },
5179 { .name = "discover", .cb = handle_yaml_no_op },
5182 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5183 { .name = "route", .cb = handle_yaml_show_route },
5184 { .name = "net", .cb = handle_yaml_show_net },
5185 { .name = "peer", .cb = handle_yaml_show_peers },
5186 { .name = "ip2nets", .cb = handle_yaml_no_op },
5187 { .name = "routing", .cb = handle_yaml_show_routing },
5188 { .name = "buffers", .cb = handle_yaml_show_routing },
5189 { .name = "statistics", .cb = handle_yaml_show_stats },
5190 { .name = "global", .cb = handle_yaml_show_global_settings},
5191 { .name = "numa", .cb = handle_yaml_show_numa },
5192 { .name = "ping", .cb = handle_yaml_no_op },
5193 { .name = "discover", .cb = handle_yaml_no_op },
5196 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5197 { .name = "route", .cb = handle_yaml_no_op },
5198 { .name = "net", .cb = handle_yaml_no_op },
5199 { .name = "peer", .cb = handle_yaml_no_op },
5200 { .name = "ip2nets", .cb = handle_yaml_no_op },
5201 { .name = "routing", .cb = handle_yaml_no_op },
5202 { .name = "buffers", .cb = handle_yaml_no_op },
5203 { .name = "statistics", .cb = handle_yaml_no_op },
5204 { .name = "global", .cb = handle_yaml_no_op },
5205 { .name = "numa", .cb = handle_yaml_no_op },
5206 { .name = "ping", .cb = handle_yaml_ping },
5207 { .name = "discover", .cb = handle_yaml_discover },
5210 static cmd_handler_t lookup_fn(char *key,
5211 struct lookup_cmd_hdlr_tbl *tbl)
5217 for (i = 0; tbl[i].name != NULL; i++) {
5218 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5225 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5226 struct cYAML **show_rc, struct cYAML **err_rc)
5228 struct cYAML *tree, *item = NULL, *head, *child;
5230 char err_str[LNET_MAX_STR_LEN];
5231 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5233 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5235 return LUSTRE_CFG_RC_BAD_PARAM;
5237 child = tree->cy_child;
5238 while (child != NULL) {
5239 cb = lookup_fn(child->cy_string, table);
5241 snprintf(err_str, sizeof(err_str),
5242 "\"call back for '%s' not found\"",
5244 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5245 "yaml", "helper", err_str, err_rc);
5249 if (cYAML_is_sequence(child)) {
5250 while ((head = cYAML_get_next_seq_item(child, &item))
5252 rc = cb(head, show_rc, err_rc);
5253 if (rc != LUSTRE_CFG_RC_NO_ERR)
5257 rc = cb(child, show_rc, err_rc);
5258 if (rc != LUSTRE_CFG_RC_NO_ERR)
5262 child = child->cy_next;
5266 cYAML_free_tree(tree);
5271 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5273 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5277 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5279 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5283 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5285 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5289 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5291 return lustre_yaml_cb_helper(f, lookup_exec_tbl,