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(lnet_nid_t pnid, lnet_nid_t nid, __u32 cmd,
564 struct lnet_ioctl_peer_cfg *data,
565 char *err_str, char *cmd_str)
569 data->prcfg_prim_nid = pnid;
570 data->prcfg_cfg_nid = nid;
572 rc = l_ioctl(LNET_DEV_ID, cmd, data);
577 "\"cannot %s peer ni: %s\"",
578 (cmd_str) ? cmd_str : "add", strerror(errno));
579 err_str[LNET_MAX_STR_LEN - 1] = '\0';
585 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
586 int seq_no, struct cYAML **show_rc,
587 struct cYAML **err_rc)
590 struct lnet_ioctl_ping_data ping;
591 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
592 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
593 struct lnet_process_id id;
594 char err_str[LNET_MAX_STR_LEN] = {0};
595 char *sep, *token, *end;
598 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
602 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
604 data = calloc(1, len);
608 /* create struct cYAML root object */
609 root = cYAML_create_object(NULL, NULL);
613 ping_node = cYAML_create_seq(root, oper);
614 if (ping_node == NULL)
617 /* tokenise each nid in string ping_nids */
618 token = strtok(ping_nids, ",");
621 item = cYAML_create_seq_item(ping_node);
625 if (first_seq == NULL)
628 /* check if '-' is a part of NID, token */
629 sep = strchr(token, '-');
631 id.pid = LNET_PID_ANY;
632 /* if no net is specified, libcfs_str2nid() will assume tcp */
633 id.nid = libcfs_str2nid(token);
634 if (id.nid == LNET_NID_ANY) {
635 snprintf(err_str, sizeof(err_str),
636 "\"cannot parse NID '%s'\"",
638 rc = LUSTRE_CFG_RC_BAD_PARAM;
639 cYAML_build_error(rc, seq_no, MANAGE_CMD,
640 oper, err_str, err_rc);
644 if (token[0] == 'u' || token[0] == 'U')
645 id.pid = (strtoul(&token[1], &end, 0) |
646 (LNET_PID_USERFLAG));
648 id.pid = strtoul(token, &end, 0);
650 /* assuming '-' is part of hostname */
652 id.pid = LNET_PID_ANY;
653 id.nid = libcfs_str2nid(token);
654 if (id.nid == LNET_NID_ANY) {
655 snprintf(err_str, sizeof(err_str),
656 "\"cannot parse NID '%s'\"",
658 rc = LUSTRE_CFG_RC_BAD_PARAM;
659 cYAML_build_error(rc, seq_no, MANAGE_CMD,
665 id.nid = libcfs_str2nid(sep + 1);
666 if (id.nid == LNET_NID_ANY) {
667 snprintf(err_str, sizeof(err_str),
668 "\"cannot parse NID '%s'\"",
670 rc = LUSTRE_CFG_RC_BAD_PARAM;
671 cYAML_build_error(rc, seq_no, MANAGE_CMD,
678 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
679 ping.ping_hdr.ioc_len = sizeof(ping);
681 ping.op_param = param;
682 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
683 ping.ping_buf = data;
685 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
688 sizeof(err_str), "failed to %s %s: %s\n", oper,
689 id.pid == LNET_PID_ANY ?
690 libcfs_nid2str(id.nid) :
691 libcfs_id2str(id), strerror(errno));
692 rc = LUSTRE_CFG_RC_BAD_PARAM;
693 cYAML_build_error(rc, seq_no, MANAGE_CMD,
694 oper, err_str, err_rc);
698 if (cYAML_create_string(item, "primary nid",
699 libcfs_nid2str(ping.ping_id.nid)) == NULL)
702 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
703 "True" : "False") == NULL)
706 tmp = cYAML_create_seq(item, "peer ni");
710 for (i = 0; i < ping.ping_count; i++) {
711 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
714 peer_ni = cYAML_create_seq_item(tmp);
717 memset(buf, 0, sizeof buf);
718 snprintf(buf, sizeof buf, "nid");
719 if (cYAML_create_string(peer_ni, buf,
720 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
726 } while ((token = strtok(NULL, ",")) != NULL);
729 rc = LUSTRE_CFG_RC_NO_ERR;
734 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
735 cYAML_free_tree(root);
736 } else if (show_rc != NULL && *show_rc != NULL) {
737 struct cYAML *show_node;
738 show_node = cYAML_get_object_item(*show_rc, oper);
739 if (show_node != NULL && cYAML_is_sequence(show_node)) {
740 cYAML_insert_child(show_node, first_seq);
743 } else if (show_node == NULL) {
744 cYAML_insert_sibling((*show_rc)->cy_child,
748 cYAML_free_tree(root);
757 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
758 struct cYAML **show_rc, struct cYAML **err_rc)
762 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
763 seq_no, show_rc, err_rc);
767 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
768 struct cYAML **show_rc, struct cYAML **err_rc)
772 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
773 seq_no, show_rc, err_rc);
777 static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
779 struct lustre_lnet_ip_range_descr *ipr, *tmp;
780 struct cfs_expr_list *el, *el_tmp;
782 list_for_each_entry_safe(ipr, tmp,
783 &ip2nets->ip2nets_ip_ranges,
785 list_del(&ipr->ipr_entry);
786 list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
788 list_del(&el->el_link);
789 cfs_expr_list_free(el);
796 * returns an rc < 0 if there is an error
797 * otherwise it returns the number IPs generated
798 * it also has out params: net - network name
800 static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
801 struct lustre_lnet_ip2nets *ip2nets,
802 __u32 *net, char *err_str)
804 struct lustre_lnet_ip_range_descr *ipr;
806 int ip_idx = MAX_NUM_IPS - 1;
807 int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
809 char ip_range[LNET_MAX_STR_LEN];
811 /* separate the two components of the NID */
813 comp2 = strchr(nidstr, '@');
817 "\"cannot parse NID %s\"", nidstr);
818 err_str[LNET_MAX_STR_LEN - 1] = '\0';
819 rc = LUSTRE_CFG_RC_BAD_PARAM;
823 /* length of the expected ip-range */
824 ip_range_len = comp2 - comp1;
825 if (ip_range_len >= LNET_MAX_STR_LEN) {
828 "\"too long ip_range '%s'\"", nidstr);
829 err_str[LNET_MAX_STR_LEN - 1] = '\0';
830 rc = LUSTRE_CFG_RC_BAD_PARAM;
834 /* move beyond '@' */
838 * if the net component is either o2ib or tcp then we expect
839 * an IP range which could only be a single IP address.
842 *net = libcfs_str2net(comp2);
843 net_type = LNET_NETTYP(*net);
844 /* expression support is for o2iblnd and socklnd only */
845 if (net_type != O2IBLND && net_type != SOCKLND)
846 return LUSTRE_CFG_RC_SKIP;
848 strncpy(ip_range, comp1, ip_range_len);
849 ip_range[ip_range_len] = '\0';
850 ip2nets->ip2nets_net.nw_id = *net;
852 rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
853 if (rc != LUSTRE_CFG_RC_NO_ERR) {
856 "\"cannot parse ip_range '%.100s'\"", ip_range);
857 err_str[LNET_MAX_STR_LEN - 1] = '\0';
858 rc = LUSTRE_CFG_RC_BAD_PARAM;
863 * Generate all the IP Addresses from the parsed range. For sanity
864 * we allow only a max of MAX_NUM_IPS nids to be configured for
867 list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
868 ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
871 if (ip_idx == MAX_NUM_IPS - 1) {
872 snprintf(err_str, LNET_MAX_STR_LEN,
873 "no NIDs provided for configuration");
874 err_str[LNET_MAX_STR_LEN - 1] = '\0';
875 rc = LUSTRE_CFG_RC_NO_MATCH;
877 } else if (ip_idx == -1) {
878 rc = LUSTRE_CFG_RC_LAST_ELEM;
887 static int lustre_lnet_handle_peer_ip2nets(char **nid, int num_nids, bool mr,
888 bool range, __u32 cmd,
889 char *cmd_type, char *err_str)
891 __u32 net = LNET_NIDNET(LNET_NID_ANY);
893 int i, j, rc = LUSTRE_CFG_RC_NO_ERR;
894 __u32 ip_list[MAX_NUM_IPS];
895 struct lustre_lnet_ip2nets ip2nets;
896 struct lnet_ioctl_peer_cfg data;
898 lnet_nid_t prim_nid = LNET_NID_ANY;
900 /* initialize all lists */
901 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
902 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
903 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
905 /* each nid entry is an expression */
906 for (i = 0; i < num_nids; i++) {
907 if (!range && i == 0)
908 prim_nid = libcfs_str2nid(nid[0]);
910 prim_nid = LNET_NID_ANY;
912 rc = lnet_expr2ips(nid[i], ip_list, &ip2nets, &net, err_str);
913 if (rc == LUSTRE_CFG_RC_SKIP)
915 else if (rc == LUSTRE_CFG_RC_LAST_ELEM)
917 else if (rc < LUSTRE_CFG_RC_NO_ERR)
922 for (j = MAX_NUM_IPS - 1; j > ip_idx; j--) {
923 peer_nid = LNET_MKNID(net, ip_list[j]);
924 if (peer_nid == LNET_NID_ANY) {
927 "\"cannot parse NID\"");
928 err_str[LNET_MAX_STR_LEN - 1] = '\0';
929 rc = LUSTRE_CFG_RC_BAD_PARAM;
933 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
936 if (prim_nid == LNET_NID_ANY && j == MAX_NUM_IPS - 1) {
938 peer_nid = LNET_NID_ANY;
941 if (!range && num_nids > 1 && i == 0 &&
942 cmd == IOC_LIBCFS_DEL_PEER_NI)
944 else if (!range && i == 0)
945 peer_nid = LNET_NID_ANY;
948 * If prim_nid is not provided then the first nid in the
949 * list becomes the prim_nid. First time round the loop
950 * use LNET_NID_ANY for the first parameter, then use
951 * nid[0] as the key nid after wards
953 rc = dispatch_peer_ni_cmd(prim_nid, peer_nid, cmd,
954 &data, err_str, cmd_type);
959 * we just deleted the entire peer using the
960 * primary_nid. So don't bother iterating through
961 * the rest of the nids
963 if (prim_nid != LNET_NID_ANY &&
964 peer_nid == LNET_NID_ANY &&
965 cmd == IOC_LIBCFS_DEL_PEER_NI)
969 lustre_lnet_clean_ip2nets(&ip2nets);
973 lustre_lnet_clean_ip2nets(&ip2nets);
977 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
978 bool mr, bool ip2nets, int seq_no,
979 struct cYAML **err_rc)
981 int rc = LUSTRE_CFG_RC_NO_ERR;
982 char err_str[LNET_MAX_STR_LEN] = {0};
983 char **nid_array = NULL;
985 snprintf(err_str, sizeof(err_str), "\"Success\"");
988 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, mr,
989 ip2nets, IOC_LIBCFS_ADD_PEER_NI,
995 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
996 snprintf(err_str, sizeof(err_str),
997 "bad primary NID: '%s'",
999 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1005 nid_array = calloc(sizeof(*nid_array), num_nids);
1007 snprintf(err_str, sizeof(err_str),
1009 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1012 nid_array[0] = pnid;
1013 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
1016 rc = lustre_lnet_handle_peer_ip2nets((pnid) ? nid_array : nid,
1017 num_nids, mr, ip2nets,
1018 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
1027 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
1031 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
1032 bool ip2nets, int seq_no, struct cYAML **err_rc)
1034 int rc = LUSTRE_CFG_RC_NO_ERR;
1035 char err_str[LNET_MAX_STR_LEN] = {0};
1036 char **nid_array = NULL;
1038 snprintf(err_str, sizeof(err_str), "\"Success\"");
1041 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, false,
1042 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
1048 snprintf(err_str, sizeof(err_str),
1049 "\"Primary nid is not provided\"");
1050 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1052 } else if (!ip2nets) {
1053 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
1054 rc = LUSTRE_CFG_RC_BAD_PARAM;
1055 snprintf(err_str, sizeof(err_str),
1056 "bad key NID: '%s'",
1063 nid_array = calloc(sizeof(*nid_array), num_nids);
1065 snprintf(err_str, sizeof(err_str),
1067 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1070 nid_array[0] = pnid;
1071 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
1073 rc = lustre_lnet_handle_peer_ip2nets(nid_array, num_nids, false,
1074 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
1083 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
1087 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
1088 int sen, int seq_no, struct cYAML **err_rc)
1090 struct lnet_ioctl_config_data data;
1091 lnet_nid_t gateway_nid;
1092 int rc = LUSTRE_CFG_RC_NO_ERR;
1094 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1095 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1096 char err_str[LNET_MAX_STR_LEN];
1097 __u32 ip_list[MAX_NUM_IPS];
1098 struct lustre_lnet_ip2nets ip2nets;
1100 /* initialize all lists */
1101 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1102 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1103 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1105 snprintf(err_str, sizeof(err_str), "\"Success\"");
1107 if (nw == NULL || gw == NULL) {
1110 "\"missing mandatory parameter in route config:'%s'\"",
1111 (nw == NULL && gw == NULL) ? "network, gateway" :
1112 (nw == NULL) ? "network" : "gateway");
1113 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1117 rnet = libcfs_str2net(nw);
1118 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1121 "\"cannot parse remote net %s\"", nw);
1122 rc = LUSTRE_CFG_RC_BAD_PARAM;
1127 /* hops is undefined */
1128 hops = LNET_UNDEFINED_HOPS;
1129 } else if (hops < 1 || hops > 255) {
1132 "\"invalid hop count %d, must be between 1 and 255\"",
1134 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1140 } else if (prio < 0) {
1143 "\"invalid priority %d, must be greater than 0\"",
1145 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1151 } else if (sen < 1) {
1154 "\"invalid health sensitivity %d, must be 1 or greater\"",
1156 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1160 rc = lnet_expr2ips(gw, ip_list,
1161 &ip2nets, &net, err_str);
1162 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1164 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1169 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1170 data.cfg_net = rnet;
1171 data.cfg_config_u.cfg_route.rtr_hop = hops;
1172 data.cfg_config_u.cfg_route.rtr_priority = prio;
1173 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
1175 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1176 gateway_nid = LNET_MKNID(net, ip_list[i]);
1177 if (gateway_nid == LNET_NID_ANY) {
1180 "\"cannot form gateway NID: %u\"",
1182 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1183 rc = LUSTRE_CFG_RC_BAD_PARAM;
1186 data.cfg_nid = gateway_nid;
1188 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1189 if (rc != 0 && errno != EEXIST && errno != EHOSTUNREACH) {
1193 "\"cannot add route: %s\"", strerror(errno));
1198 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1203 int lustre_lnet_del_route(char *nw, char *gw,
1204 int seq_no, struct cYAML **err_rc)
1206 struct lnet_ioctl_config_data data;
1207 lnet_nid_t gateway_nid;
1208 int rc = LUSTRE_CFG_RC_NO_ERR;
1209 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1210 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1211 char err_str[LNET_MAX_STR_LEN];
1213 __u32 ip_list[MAX_NUM_IPS];
1214 struct lustre_lnet_ip2nets ip2nets;
1216 /* initialize all lists */
1217 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1218 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1219 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1221 snprintf(err_str, sizeof(err_str), "\"Success\"");
1223 if (nw == NULL || gw == NULL) {
1226 "\"missing mandatory parameter in route delete: '%s'\"",
1227 (nw == NULL && gw == NULL) ? "network, gateway" :
1228 (nw == NULL) ? "network" : "gateway");
1229 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1233 rnet = libcfs_str2net(nw);
1234 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1237 "\"cannot parse remote net '%s'\"", nw);
1238 rc = LUSTRE_CFG_RC_BAD_PARAM;
1242 rc = lnet_expr2ips(gw, ip_list,
1243 &ip2nets, &net, err_str);
1244 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1246 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1251 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1252 data.cfg_net = rnet;
1254 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1255 gateway_nid = LNET_MKNID(net, ip_list[i]);
1256 if (gateway_nid == LNET_NID_ANY) {
1259 "\"cannot form gateway NID: %u\"",
1261 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1262 rc = LUSTRE_CFG_RC_BAD_PARAM;
1265 data.cfg_nid = gateway_nid;
1267 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1272 "\"cannot delete route: %s\"", strerror(errno));
1277 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1282 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1283 int seq_no, struct cYAML **show_rc,
1284 struct cYAML **err_rc, bool backup)
1286 struct lnet_ioctl_config_data data;
1287 lnet_nid_t gateway_nid;
1288 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1290 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1292 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1293 struct cYAML *first_seq = NULL;
1294 char err_str[LNET_MAX_STR_LEN];
1297 snprintf(err_str, sizeof(err_str),
1298 "\"out of memory\"");
1301 net = libcfs_str2net(nw);
1302 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1305 "\"cannot parse net '%s'\"", nw);
1306 rc = LUSTRE_CFG_RC_BAD_PARAM;
1311 /* show all routes without filtering on net */
1312 net = LNET_NIDNET(LNET_NID_ANY);
1316 gateway_nid = libcfs_str2nid(gw);
1317 if (gateway_nid == LNET_NID_ANY) {
1320 "\"cannot parse gateway NID '%s'\"", gw);
1321 rc = LUSTRE_CFG_RC_BAD_PARAM;
1325 /* show all routes with out filtering on gateway */
1326 gateway_nid = LNET_NID_ANY;
1328 if ((hops < 1 && hops != -1) || hops > 255) {
1331 "\"invalid hop count %d, must be between 0 and 256\"",
1333 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1337 /* create struct cYAML root object */
1338 root = cYAML_create_object(NULL, NULL);
1342 route = cYAML_create_seq(root, "route");
1347 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1350 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1356 /* filter on provided data */
1357 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1358 net != data.cfg_net)
1361 if (gateway_nid != LNET_NID_ANY &&
1362 gateway_nid != data.cfg_nid)
1366 hops != data.cfg_config_u.cfg_route.rtr_hop)
1370 prio != data.cfg_config_u.cfg_route.rtr_priority)
1373 /* default rc to -1 incase we hit the goto */
1377 item = cYAML_create_seq_item(route);
1381 if (first_seq == NULL)
1384 if (cYAML_create_string(item, "net",
1385 libcfs_net2str(data.cfg_net)) == NULL)
1388 if (cYAML_create_string(item, "gateway",
1389 libcfs_nid2str(data.cfg_nid)) == NULL)
1393 if (cYAML_create_number(item, "hop",
1394 (int) data.cfg_config_u.
1395 cfg_route.rtr_hop) ==
1399 if (cYAML_create_number(item, "priority",
1401 cfg_route.rtr_priority) == NULL)
1404 if (cYAML_create_number(item, "health_sensitivity",
1406 cfg_route.rtr_sensitivity) == NULL)
1410 cYAML_create_string(item, "state",
1411 data.cfg_config_u.cfg_route.
1413 "up" : "down") == NULL)
1418 /* print output iff show_rc is not provided */
1419 if (show_rc == NULL)
1420 cYAML_print_tree(root);
1422 if (l_errno != ENOENT) {
1425 "\"cannot get routes: %s\"",
1430 rc = LUSTRE_CFG_RC_NO_ERR;
1432 snprintf(err_str, sizeof(err_str), "\"success\"");
1434 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1435 cYAML_free_tree(root);
1436 } else if (show_rc != NULL && *show_rc != NULL) {
1437 struct cYAML *show_node;
1438 /* find the route node, if one doesn't exist then
1439 * insert one. Otherwise add to the one there
1441 show_node = cYAML_get_object_item(*show_rc, "route");
1442 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1443 cYAML_insert_child(show_node, first_seq);
1446 } else if (show_node == NULL) {
1447 cYAML_insert_sibling((*show_rc)->cy_child,
1451 cYAML_free_tree(root);
1457 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1462 static int socket_intf_query(int request, char *intf,
1468 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1469 return LUSTRE_CFG_RC_BAD_PARAM;
1471 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1473 return LUSTRE_CFG_RC_BAD_PARAM;
1475 strcpy(ifr->ifr_name, intf);
1476 rc = ioctl(sockfd, request, ifr);
1478 rc = LUSTRE_CFG_RC_BAD_PARAM;
1485 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1490 memset(&ifr, 0, sizeof(ifr));
1491 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1493 return LUSTRE_CFG_RC_BAD_PARAM;
1495 if ((ifr.ifr_flags & IFF_UP) == 0)
1496 return LUSTRE_CFG_RC_BAD_PARAM;
1498 memset(&ifr, 0, sizeof(ifr));
1499 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1501 return LUSTRE_CFG_RC_BAD_PARAM;
1503 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1504 *ip = bswap_32(*ip);
1506 return LUSTRE_CFG_RC_NO_ERR;
1510 * for each interface in the array of interfaces find the IP address of
1511 * that interface, create its nid and add it to an array of NIDs.
1512 * Stop if any of the interfaces is down
1514 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1515 lnet_nid_t **nids, __u32 *nnids,
1516 char *err_str, size_t str_len)
1518 int i = 0, count = 0, rc;
1519 struct lnet_dlc_intf_descr *intf;
1520 char val[LNET_MAX_STR_LEN];
1527 if (nw == NULL || nids == NULL) {
1528 snprintf(err_str, str_len,
1529 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1530 err_str[str_len - 1] = '\0';
1531 return LUSTRE_CFG_RC_BAD_PARAM;
1534 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1537 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1541 *nids = calloc(count, sizeof(lnet_nid_t));
1542 if (*nids == NULL) {
1543 snprintf(err_str, str_len,
1544 "\"out of memory\"");
1545 err_str[str_len - 1] = '\0';
1546 return LUSTRE_CFG_RC_OUT_OF_MEM;
1549 * special case the GNI interface since it doesn't have an IP
1550 * address. The assumption is that there can only be one GNI
1551 * interface in the system. No interface name is provided.
1553 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1554 rc = read_sysfs_file(gni_nid_path, "nid", val,
1557 snprintf(err_str, str_len,
1558 "\"cannot read gni nid\"");
1559 err_str[str_len - 1] = '\0';
1562 gni_num = atoi(val);
1564 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1569 /* look at the other interfaces */
1570 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1571 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1572 /* handle LNDs with numeric interface name */
1573 num = strtoul(intf->intf_name, &endp, 0);
1574 if (endp == intf->intf_name || *endp != '\0') {
1575 rc = LUSTRE_CFG_RC_BAD_PARAM;
1576 snprintf(err_str, str_len,
1577 "\"couldn't query intf %s\"",
1579 err_str[str_len - 1] = '\0';
1582 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1585 /* handle LNDs with ip interface name */
1586 rc = lustre_lnet_queryip(intf, &ip);
1587 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1588 snprintf(err_str, str_len,
1589 "\"couldn't query intf %s\"",
1591 err_str[str_len - 1] = '\0';
1594 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1611 * called repeatedly until a match or no more ip range
1613 * ip_range expression
1614 * interface list with all the interface names.
1615 * all the interfaces in the system.
1617 * try to match the ip_range expr to one of the interfaces' IPs in
1618 * the system. If we hit a patch for an interface. Check if that
1619 * interface name is in the list.
1621 * If there are more than one interface in the list, then make sure
1622 * that the IPs for all of these interfaces match the ip ranges
1625 * for each interface in intf_list
1626 * look up the intf name in ifa
1627 * if not there then no match
1628 * check ip obtained from ifa against a match to any of the
1630 * If no match, then fail
1632 * The result is that all the interfaces have to match.
1634 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1635 struct list_head *intf_list,
1636 struct list_head *ip_ranges)
1640 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1641 struct ifaddrs *ifaddr = ifa;
1642 struct lustre_lnet_ip_range_descr *ip_range;
1646 * if there are no explicit interfaces, and no ip ranges, then
1647 * configure the first tcp interface we encounter.
1649 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1650 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1651 if (ifaddr->ifa_addr == NULL)
1654 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1657 family = ifaddr->ifa_addr->sa_family;
1658 if (family == AF_INET &&
1659 strcmp(ifaddr->ifa_name, "lo") != 0) {
1660 rc = lustre_lnet_add_intf_descr
1661 (intf_list, ifaddr->ifa_name,
1662 strlen(ifaddr->ifa_name));
1664 if (rc != LUSTRE_CFG_RC_NO_ERR)
1667 return LUSTRE_CFG_RC_MATCH;
1670 return LUSTRE_CFG_RC_NO_MATCH;
1674 * First interface which matches an IP pattern will be used
1676 if (list_empty(intf_list)) {
1678 * no interfaces provided in the rule, but an ip range is
1679 * provided, so try and match an interface to the ip
1682 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1683 if (ifaddr->ifa_addr == NULL)
1686 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1689 family = ifaddr->ifa_addr->sa_family;
1690 if (family == AF_INET) {
1691 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1694 list_for_each_entry(ip_range, ip_ranges,
1696 rc = cfs_ip_addr_match(bswap_32(ip),
1697 &ip_range->ipr_expr);
1701 rc = lustre_lnet_add_intf_descr
1702 (intf_list, ifaddr->ifa_name,
1703 strlen(ifaddr->ifa_name));
1705 if (rc != LUSTRE_CFG_RC_NO_ERR)
1711 if (!list_empty(intf_list))
1712 return LUSTRE_CFG_RC_MATCH;
1714 return LUSTRE_CFG_RC_NO_MATCH;
1718 * If an interface is explicitly specified the ip-range might or
1719 * might not be specified. if specified the interface needs to match the
1720 * ip-range. If no ip-range then the interfaces are
1721 * automatically matched if they are all up.
1722 * If > 1 interfaces all the interfaces must match for the NI to
1725 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1726 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1727 if (ifaddr->ifa_addr == NULL)
1730 family = ifaddr->ifa_addr->sa_family;
1731 if (family == AF_INET &&
1732 strcmp(intf_descr->intf_name,
1733 ifaddr->ifa_name) == 0)
1737 if (ifaddr == NULL) {
1738 list_del(&intf_descr->intf_on_network);
1739 free_intf_descr(intf_descr);
1743 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1744 list_del(&intf_descr->intf_on_network);
1745 free_intf_descr(intf_descr);
1749 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1752 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1753 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1759 /* no match for this interface */
1760 list_del(&intf_descr->intf_on_network);
1761 free_intf_descr(intf_descr);
1765 return LUSTRE_CFG_RC_MATCH;
1768 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1769 lnet_nid_t **nids, __u32 *nnids,
1770 char *err_str, size_t str_len)
1772 struct ifaddrs *ifa;
1773 int rc = LUSTRE_CFG_RC_NO_ERR;
1775 rc = getifaddrs(&ifa);
1777 snprintf(err_str, str_len,
1778 "\"failed to get interface addresses: %d\"", -errno);
1779 err_str[str_len - 1] = '\0';
1783 rc = lustre_lnet_match_ip_to_intf(ifa,
1784 &ip2nets->ip2nets_net.nw_intflist,
1785 &ip2nets->ip2nets_ip_ranges);
1786 if (rc != LUSTRE_CFG_RC_MATCH) {
1787 snprintf(err_str, str_len,
1788 "\"couldn't match ip to existing interfaces\"");
1789 err_str[str_len - 1] = '\0';
1794 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1795 err_str, sizeof(err_str));
1796 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1807 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1808 struct lnet_ioctl_config_lnd_tunables *tunables,
1809 struct cfs_expr_list *global_cpts,
1810 lnet_nid_t *nids, char *err_str)
1813 struct lnet_ioctl_config_ni *conf;
1814 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1815 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1818 struct lnet_dlc_intf_descr *intf_descr;
1820 struct cfs_expr_list *cpt_expr;
1822 list_for_each_entry(intf_descr, intf_list,
1824 if (tunables != NULL)
1825 len = sizeof(struct lnet_ioctl_config_ni) +
1826 sizeof(struct lnet_ioctl_config_lnd_tunables);
1828 len = sizeof(struct lnet_ioctl_config_ni);
1830 data = calloc(1, len);
1832 return LUSTRE_CFG_RC_OUT_OF_MEM;
1833 conf = (struct lnet_ioctl_config_ni*) data;
1834 if (tunables != NULL)
1835 tun = (struct lnet_ioctl_config_lnd_tunables*)
1838 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1839 conf->lic_cfg_hdr.ioc_len = len;
1840 conf->lic_nid = nids[i];
1841 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1844 if (intf_descr->cpt_expr != NULL)
1845 cpt_expr = intf_descr->cpt_expr;
1846 else if (global_cpts != NULL)
1847 cpt_expr = global_cpts;
1851 if (cpt_expr != NULL) {
1852 count = cfs_expr_list_values(cpt_expr,
1853 LNET_MAX_SHOW_NUM_CPT,
1856 memcpy(conf->lic_cpts, cpt_array,
1857 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1866 conf->lic_ncpts = count;
1868 if (tunables != NULL)
1869 memcpy(tun, tunables, sizeof(*tunables));
1871 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1876 "\"cannot add network: %s\"", strerror(errno));
1884 return LUSTRE_CFG_RC_NO_ERR;
1888 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1889 struct lnet_ioctl_config_lnd_tunables *tunables,
1890 struct cfs_expr_list *global_cpts,
1891 int seq_no, struct cYAML **err_rc)
1893 lnet_nid_t *nids = NULL;
1896 char err_str[LNET_MAX_STR_LEN];
1898 snprintf(err_str, sizeof(err_str), "\"success\"");
1903 "\"incomplete ip2nets information\"");
1904 rc = LUSTRE_CFG_RC_BAD_PARAM;
1909 * call below function to resolve the rules into a list of nids.
1910 * The memory is allocated in that function then freed here when
1911 * it's no longer needed.
1913 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1915 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1918 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1919 snprintf(err_str, sizeof(err_str),
1920 "\"no interfaces match ip2nets rules\"");
1924 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1925 tunables, global_cpts, nids,
1932 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1936 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1937 struct cfs_expr_list *global_cpts,
1939 struct lnet_ioctl_config_lnd_tunables *tunables,
1940 int seq_no, struct cYAML **err_rc)
1943 struct lnet_ioctl_config_ni *conf;
1944 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1945 char buf[LNET_MAX_STR_LEN];
1946 int rc = LUSTRE_CFG_RC_NO_ERR;
1947 char err_str[LNET_MAX_STR_LEN];
1948 lnet_nid_t *nids = NULL;
1952 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1955 snprintf(err_str, sizeof(err_str), "\"success\"");
1957 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1958 (list_empty(&nw_descr->nw_intflist) &&
1959 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1962 "\"missing mandatory parameters in NI config: '%s'\"",
1963 (nw_descr == NULL) ? "network , interface" :
1964 (nw_descr->nw_id == 0) ? "network" : "interface");
1965 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1969 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1972 "\"ip2net string too long %d\"",
1973 (int)strlen(ip2net));
1974 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1978 if (ip2net != NULL) {
1979 if (tunables != NULL)
1980 len = sizeof(struct lnet_ioctl_config_ni) +
1981 sizeof(struct lnet_ioctl_config_lnd_tunables);
1983 len = sizeof(struct lnet_ioctl_config_ni);
1984 data = calloc(1, len);
1986 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1989 conf = (struct lnet_ioctl_config_ni*) data;
1990 if (tunables != NULL)
1991 tun = (struct lnet_ioctl_config_lnd_tunables*)
1992 (data + sizeof(*conf));
1994 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1995 conf->lic_cfg_hdr.ioc_len = len;
1996 strncpy(conf->lic_legacy_ip2nets, ip2net,
1999 if (global_cpts != NULL) {
2000 count = cfs_expr_list_values(global_cpts,
2001 LNET_MAX_SHOW_NUM_CPT,
2004 memcpy(conf->lic_cpts, cpt_array,
2005 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
2014 conf->lic_ncpts = count;
2016 if (tunables != NULL)
2017 memcpy(tun, tunables, sizeof(*tunables));
2019 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
2024 "\"cannot add network: %s\"", strerror(errno));
2031 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
2032 rc = LUSTRE_CFG_RC_NO_ERR;
2036 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2039 "\"cannot parse net '%s'\"",
2040 libcfs_net2str(nw_descr->nw_id));
2041 rc = LUSTRE_CFG_RC_BAD_PARAM;
2046 * special case the GNI since no interface name is expected
2048 if (list_empty(&nw_descr->nw_intflist) &&
2049 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
2052 "\"no interface name provided\"");
2053 rc = LUSTRE_CFG_RC_BAD_PARAM;
2057 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2058 err_str, sizeof(err_str));
2060 rc = LUSTRE_CFG_RC_BAD_PARAM;
2064 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
2065 tunables, global_cpts, nids,
2069 if (nw_descr != NULL) {
2070 list_for_each_entry_safe(intf_descr, tmp,
2071 &nw_descr->nw_intflist,
2073 list_del(&intf_descr->intf_on_network);
2074 free_intf_descr(intf_descr);
2078 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
2089 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
2090 int seq_no, struct cYAML **err_rc)
2092 struct lnet_ioctl_config_ni data;
2093 int rc = LUSTRE_CFG_RC_NO_ERR, i;
2094 char err_str[LNET_MAX_STR_LEN];
2095 lnet_nid_t *nids = NULL;
2097 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2099 snprintf(err_str, sizeof(err_str), "\"success\"");
2101 if (nw_descr == NULL || nw_descr->nw_id == 0) {
2104 "\"missing mandatory parameter in deleting NI: '%s'\"",
2105 (nw_descr == NULL) ? "network , interface" :
2106 (nw_descr->nw_id == 0) ? "network" : "interface");
2107 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2111 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2112 return LUSTRE_CFG_RC_NO_ERR;
2114 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2117 "\"cannot parse net '%s'\"",
2118 libcfs_net2str(nw_descr->nw_id));
2119 rc = LUSTRE_CFG_RC_BAD_PARAM;
2123 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2124 err_str, sizeof(err_str));
2126 rc = LUSTRE_CFG_RC_BAD_PARAM;
2131 * no interfaces just the nw_id is specified
2134 nids = calloc(1, sizeof(*nids));
2136 snprintf(err_str, sizeof(err_str),
2137 "\"out of memory\"");
2138 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2141 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2145 for (i = 0; i < nnids; i++) {
2146 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2147 data.lic_nid = nids[i];
2149 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2154 "\"cannot del network: %s\"", strerror(errno));
2158 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2160 list_del(&intf_descr->intf_on_network);
2161 free_intf_descr(intf_descr);
2165 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2174 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2175 enum lnet_health_type type, char *name,
2176 int seq_no, struct cYAML **err_rc)
2178 struct lnet_ioctl_reset_health_cfg data;
2179 int rc = LUSTRE_CFG_RC_NO_ERR;
2180 char err_str[LNET_MAX_STR_LEN];
2182 snprintf(err_str, sizeof(err_str), "\"success\"");
2184 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2185 data.rh_type = type;
2187 data.rh_value = value;
2190 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2194 sizeof(err_str), "Can not configure health value: %s",
2198 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2203 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2204 struct cYAML **err_rc)
2208 nid = libcfs_str2nid(ni_nid);
2211 return lustre_lnet_config_healthv(value, all, nid,
2212 LNET_HEALTH_TYPE_LOCAL_NI,
2213 "ni healthv", seq_no, err_rc);
2216 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2217 int seq_no, struct cYAML **err_rc)
2221 nid = libcfs_str2nid(lpni_nid);
2224 return lustre_lnet_config_healthv(value, all, nid,
2225 LNET_HEALTH_TYPE_PEER_NI,
2226 "peer_ni healthv", seq_no, err_rc);
2230 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2231 struct lnet_ioctl_comm_count *counts)
2233 if (cYAML_create_number(yaml, "put",
2234 counts->ico_put_count)
2237 if (cYAML_create_number(yaml, "get",
2238 counts->ico_get_count)
2241 if (cYAML_create_number(yaml, "reply",
2242 counts->ico_reply_count)
2245 if (cYAML_create_number(yaml, "ack",
2246 counts->ico_ack_count)
2249 if (cYAML_create_number(yaml, "hello",
2250 counts->ico_hello_count)
2257 static struct lnet_ioctl_comm_count *
2258 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2261 return &msg_stats->im_send_stats;
2263 return &msg_stats->im_recv_stats;
2265 return &msg_stats->im_drop_stats;
2270 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2271 struct cYAML **show_rc, struct cYAML **err_rc,
2275 struct lnet_ioctl_config_ni *ni_data;
2276 struct lnet_ioctl_config_lnd_tunables *lnd;
2277 struct lnet_ioctl_element_stats *stats;
2278 struct lnet_ioctl_element_msg_stats msg_stats;
2279 struct lnet_ioctl_local_ni_hstats hstats;
2280 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2281 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2282 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2284 struct cYAML *root = NULL, *tunables = NULL,
2285 *net_node = NULL, *interfaces = NULL,
2286 *item = NULL, *first_seq = NULL,
2287 *tmp = NULL, *statistics = NULL,
2289 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2290 char str_buf[str_buf_len];
2292 char err_str[LNET_MAX_STR_LEN];
2293 bool exist = false, new_net = true;
2295 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2297 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2299 buf = calloc(1, buf_size);
2303 ni_data = (struct lnet_ioctl_config_ni *)buf;
2306 net = libcfs_str2net(nw);
2307 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2310 "\"cannot parse net '%s'\"", nw);
2311 rc = LUSTRE_CFG_RC_BAD_PARAM;
2316 root = cYAML_create_object(NULL, NULL);
2320 net_node = cYAML_create_seq(root, "net");
2321 if (net_node == NULL)
2327 memset(buf, 0, buf_size);
2329 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2331 * set the ioc_len to the proper value since INIT assumes
2334 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2335 ni_data->lic_idx = i;
2337 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2343 rc_net = LNET_NIDNET(ni_data->lic_nid);
2345 /* filter on provided data */
2346 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2350 /* if we're backing up don't store lo */
2351 if (backup && LNET_NETTYP(rc_net) == LOLND)
2354 /* default rc to -1 in case we hit the goto */
2358 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2359 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2360 (ni_data->lic_bulk + sizeof(*stats));
2362 if (rc_net != prev_net) {
2369 if (!cYAML_create_string(net_node, "net type",
2370 libcfs_net2str(rc_net)))
2373 tmp = cYAML_create_seq(net_node, "local NI(s)");
2379 /* create the tree to be printed. */
2380 item = cYAML_create_seq_item(tmp);
2384 if (first_seq == NULL)
2388 cYAML_create_string(item, "nid",
2389 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2393 cYAML_create_string(item,
2395 (ni_data->lic_status ==
2396 LNET_NI_STATUS_UP) ?
2397 "up" : "down") == NULL)
2400 /* don't add interfaces unless there is at least one
2402 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2403 interfaces = cYAML_create_object(item, "interfaces");
2404 if (interfaces == NULL)
2407 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2408 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2410 sizeof(str_buf), "%d", j);
2411 if (cYAML_create_string(interfaces,
2413 ni_data->lic_ni_intf[j]) ==
2425 goto continue_without_msg_stats;
2427 statistics = cYAML_create_object(item, "statistics");
2428 if (statistics == NULL)
2431 if (cYAML_create_number(statistics, "send_count",
2432 stats->iel_send_count)
2436 if (cYAML_create_number(statistics, "recv_count",
2437 stats->iel_recv_count)
2441 if (cYAML_create_number(statistics, "drop_count",
2442 stats->iel_drop_count)
2447 goto continue_without_msg_stats;
2449 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2450 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2451 msg_stats.im_idx = i;
2453 rc = l_ioctl(LNET_DEV_ID,
2454 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2458 goto continue_without_msg_stats;
2461 for (k = 0; k < 3; k++) {
2462 struct lnet_ioctl_comm_count *counts;
2463 struct cYAML *msg_statistics = NULL;
2465 msg_statistics = cYAML_create_object(item,
2466 (char *)gmsg_stat_names[k]);
2467 if (msg_statistics == NULL)
2470 counts = get_counts(&msg_stats, k);
2474 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2479 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2480 hstats.hlni_nid = ni_data->lic_nid;
2481 /* grab health stats */
2482 rc = l_ioctl(LNET_DEV_ID,
2483 IOC_LIBCFS_GET_LOCAL_HSTATS,
2487 goto continue_without_msg_stats;
2489 yhstats = cYAML_create_object(item, "health stats");
2492 if (cYAML_create_number(yhstats, "health value",
2493 hstats.hlni_health_value)
2496 if (cYAML_create_number(yhstats, "interrupts",
2497 hstats.hlni_local_interrupt)
2500 if (cYAML_create_number(yhstats, "dropped",
2501 hstats.hlni_local_dropped)
2504 if (cYAML_create_number(yhstats, "aborted",
2505 hstats.hlni_local_aborted)
2508 if (cYAML_create_number(yhstats, "no route",
2509 hstats.hlni_local_no_route)
2512 if (cYAML_create_number(yhstats, "timeouts",
2513 hstats.hlni_local_timeout)
2516 if (cYAML_create_number(yhstats, "error",
2517 hstats.hlni_local_error)
2521 continue_without_msg_stats:
2522 tunables = cYAML_create_object(item, "tunables");
2526 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2527 if (rc != LUSTRE_CFG_RC_NO_ERR)
2530 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2532 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2533 rc != LUSTRE_CFG_RC_NO_MATCH)
2536 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2537 tunables = cYAML_create_object(item,
2539 if (tunables == NULL)
2544 cYAML_create_number(item, "dev cpt",
2545 ni_data->lic_dev_cpt) == NULL)
2549 cYAML_create_number(item, "tcp bonding",
2550 ni_data->lic_tcp_bonding)
2554 /* out put the CPTs in the format: "[x,x,x,...]" */
2556 limit = str_buf + str_buf_len - 3;
2557 pos += scnprintf(pos, limit - pos, "\"[");
2558 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2559 j < ni_data->lic_ncpts &&
2561 pos += scnprintf(pos, limit - pos,
2562 "%d", ni_data->lic_cpts[j]);
2563 if ((j + 1) < ni_data->lic_ncpts)
2564 pos += scnprintf(pos, limit - pos, ",");
2566 snprintf(pos, 3, "]\"");
2568 if (ni_data->lic_ncpts >= 1 &&
2569 cYAML_create_string(item, "CPT",
2575 /* Print out the net information only if show_rc is not provided */
2576 if (show_rc == NULL)
2577 cYAML_print_tree(root);
2579 if (l_errno != ENOENT) {
2582 "\"cannot get networks: %s\"",
2587 rc = LUSTRE_CFG_RC_NO_ERR;
2589 snprintf(err_str, sizeof(err_str), "\"success\"");
2591 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2592 cYAML_free_tree(root);
2593 } else if (show_rc != NULL && *show_rc != NULL) {
2594 struct cYAML *show_node;
2595 /* find the net node, if one doesn't exist
2596 * then insert one. Otherwise add to the one there
2598 show_node = cYAML_get_object_item(*show_rc, "net");
2599 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2600 cYAML_insert_child(show_node, first_seq);
2603 } else if (show_node == NULL) {
2604 cYAML_insert_sibling((*show_rc)->cy_child,
2608 cYAML_free_tree(root);
2614 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2619 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2621 struct lnet_ioctl_config_data data;
2622 int rc = LUSTRE_CFG_RC_NO_ERR;
2623 char err_str[LNET_MAX_STR_LEN];
2625 snprintf(err_str, sizeof(err_str), "\"success\"");
2627 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2628 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2630 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2635 "\"cannot %s routing %s\"",
2636 (enable) ? "enable" : "disable", strerror(errno));
2641 cYAML_build_error(rc, seq_no,
2642 (enable) ? ADD_CMD : DEL_CMD,
2643 "routing", err_str, err_rc);
2648 int ioctl_set_value(__u32 val, int ioc, char *name,
2649 int seq_no, struct cYAML **err_rc)
2651 struct lnet_ioctl_set_value data;
2652 int rc = LUSTRE_CFG_RC_NO_ERR;
2653 char err_str[LNET_MAX_STR_LEN];
2655 snprintf(err_str, sizeof(err_str), "\"success\"");
2657 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2658 data.sv_value = val;
2660 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2665 "\"cannot configure %s to %d: %s\"", name,
2666 val, strerror(errno));
2669 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2674 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2676 int rc = LUSTRE_CFG_RC_NO_ERR;
2677 char err_str[LNET_MAX_STR_LEN];
2678 char val[LNET_MAX_STR_LEN];
2680 snprintf(err_str, sizeof(err_str), "\"success\"");
2682 snprintf(val, sizeof(val), "%d", intrv);
2684 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2685 1, strlen(val) + 1);
2687 snprintf(err_str, sizeof(err_str),
2688 "\"cannot configure recovery interval: %s\"",
2691 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2696 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2698 int rc = LUSTRE_CFG_RC_NO_ERR;
2699 char err_str[LNET_MAX_STR_LEN];
2700 char val[LNET_MAX_STR_LEN];
2702 snprintf(err_str, sizeof(err_str), "\"success\"");
2704 snprintf(val, sizeof(val), "%d", sen);
2706 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2707 1, strlen(val) + 1);
2709 snprintf(err_str, sizeof(err_str),
2710 "\"cannot configure router health sensitivity: %s\"",
2713 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2718 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2720 int rc = LUSTRE_CFG_RC_NO_ERR;
2721 char err_str[LNET_MAX_STR_LEN];
2722 char val[LNET_MAX_STR_LEN];
2724 snprintf(err_str, sizeof(err_str), "\"success\"");
2726 snprintf(val, sizeof(val), "%d", sen);
2728 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2729 1, strlen(val) + 1);
2731 snprintf(err_str, sizeof(err_str),
2732 "\"cannot configure health sensitivity: %s\"",
2735 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2740 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2742 int rc = LUSTRE_CFG_RC_NO_ERR;
2743 char err_str[LNET_MAX_STR_LEN];
2744 char val[LNET_MAX_STR_LEN];
2746 snprintf(err_str, sizeof(err_str), "\"success\"");
2748 snprintf(val, sizeof(val), "%d", timeout);
2750 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2751 1, strlen(val) + 1);
2753 snprintf(err_str, sizeof(err_str),
2754 "\"cannot configure transaction timeout: %s\"",
2757 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2762 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2764 int rc = LUSTRE_CFG_RC_NO_ERR;
2765 char err_str[LNET_MAX_STR_LEN];
2766 char val[LNET_MAX_STR_LEN];
2768 snprintf(err_str, sizeof(err_str), "\"success\"");
2770 snprintf(val, sizeof(val), "%d", count);
2772 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2773 1, strlen(val) + 1);
2775 snprintf(err_str, sizeof(err_str),
2776 "\"cannot configure retry count: %s\"",
2779 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2784 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2786 int rc = LUSTRE_CFG_RC_NO_ERR;
2787 char err_str[LNET_MAX_STR_LEN];
2788 char val[LNET_MAX_STR_LEN];
2790 snprintf(err_str, sizeof(err_str), "\"success\"");
2792 snprintf(val, sizeof(val), "%d", max);
2794 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2795 1, strlen(val) + 1);
2797 snprintf(err_str, sizeof(err_str),
2798 "\"cannot configure max interfaces: %s\"",
2801 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2806 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2808 int rc = LUSTRE_CFG_RC_NO_ERR;
2809 char err_str[LNET_MAX_STR_LEN];
2810 char val[LNET_MAX_STR_LEN];
2812 snprintf(err_str, sizeof(err_str), "\"success\"");
2814 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2816 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2817 1, strlen(val) + 1);
2819 snprintf(err_str, sizeof(err_str),
2820 "\"cannot configure discovery: %s\"",
2823 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2829 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2830 struct cYAML **err_rc)
2832 int rc = LUSTRE_CFG_RC_NO_ERR;
2833 char err_str[LNET_MAX_STR_LEN];
2834 char val[LNET_MAX_STR_LEN];
2836 snprintf(err_str, sizeof(err_str), "\"success\"");
2838 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2840 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2841 1, strlen(val) + 1);
2843 snprintf(err_str, sizeof(err_str),
2844 "\"cannot configure drop asym route: %s\"",
2847 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2854 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2856 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2857 "numa_range", seq_no, err_rc);
2860 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2861 struct cYAML **err_rc)
2863 struct lnet_ioctl_config_data data;
2864 int rc = LUSTRE_CFG_RC_NO_ERR;
2865 char err_str[LNET_MAX_STR_LEN];
2867 snprintf(err_str, sizeof(err_str), "\"success\"");
2869 /* -1 indicates to ignore changes to this field */
2870 if (tiny < -1 || small < -1 || large < -1) {
2873 "\"tiny, small and large must be >= 0\"");
2874 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2878 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2879 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2880 data.cfg_config_u.cfg_buffers.buf_small = small;
2881 data.cfg_config_u.cfg_buffers.buf_large = large;
2883 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2888 "\"cannot configure buffers: %s\"", strerror(errno));
2893 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2898 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2899 struct cYAML **err_rc, bool backup)
2901 struct lnet_ioctl_config_data *data;
2902 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2903 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2906 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2907 int buf_count[LNET_NRBPOOLS] = {0};
2908 struct cYAML *root = NULL, *pools_node = NULL,
2909 *type_node = NULL, *item = NULL, *cpt = NULL,
2910 *first_seq = NULL, *buffers = NULL;
2912 char err_str[LNET_MAX_STR_LEN];
2913 char node_name[LNET_MAX_STR_LEN];
2916 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2918 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2922 data = (struct lnet_ioctl_config_data *)buf;
2924 root = cYAML_create_object(NULL, NULL);
2929 pools_node = cYAML_create_object(root, "routing");
2931 pools_node = cYAML_create_seq(root, "routing");
2932 if (pools_node == NULL)
2936 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2937 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2938 sizeof(struct lnet_ioctl_pool_cfg);
2939 data->cfg_count = i;
2941 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2949 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2952 goto calculate_buffers;
2954 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2955 item = cYAML_create_seq_item(pools_node);
2959 if (first_seq == NULL)
2962 cpt = cYAML_create_object(item, node_name);
2967 /* create the tree and print */
2968 for (j = 0; j < LNET_NRBPOOLS; j++) {
2970 type_node = cYAML_create_object(cpt, pools[j]);
2971 if (type_node == NULL)
2975 cYAML_create_number(type_node, "npages",
2976 pool_cfg->pl_pools[j].pl_npages)
2980 cYAML_create_number(type_node, "nbuffers",
2981 pool_cfg->pl_pools[j].
2982 pl_nbuffers) == NULL)
2985 cYAML_create_number(type_node, "credits",
2986 pool_cfg->pl_pools[j].
2987 pl_credits) == NULL)
2990 cYAML_create_number(type_node, "mincredits",
2991 pool_cfg->pl_pools[j].
2992 pl_mincredits) == NULL)
2994 /* keep track of the total count for each of the
2995 * tiny, small and large buffers */
2996 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
3000 if (pool_cfg != NULL) {
3002 if (cYAML_create_number(pools_node, "enable",
3003 pool_cfg->pl_routing) ==
3007 goto add_buffer_section;
3010 item = cYAML_create_seq_item(pools_node);
3014 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
3020 /* create a buffers entry in the show. This is necessary so that
3021 * if the YAML output is used to configure a node, the buffer
3022 * configuration takes hold */
3023 buffers = cYAML_create_object(root, "buffers");
3024 if (buffers == NULL)
3027 for (i = 0; i < LNET_NRBPOOLS; i++) {
3028 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3032 if (show_rc == NULL)
3033 cYAML_print_tree(root);
3035 if (l_errno != ENOENT) {
3038 "\"cannot get routing information: %s\"",
3043 rc = LUSTRE_CFG_RC_NO_ERR;
3045 snprintf(err_str, sizeof(err_str), "\"success\"");
3046 rc = LUSTRE_CFG_RC_NO_ERR;
3050 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3051 cYAML_free_tree(root);
3052 } else if (show_rc != NULL && *show_rc != NULL) {
3053 struct cYAML *routing_node;
3054 /* there should exist only one routing block and one
3055 * buffers block. If there already exists a previous one
3056 * then don't add another */
3057 routing_node = cYAML_get_object_item(*show_rc, "routing");
3058 if (routing_node == NULL) {
3059 cYAML_insert_sibling((*show_rc)->cy_child,
3063 cYAML_free_tree(root);
3069 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3074 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3075 struct cYAML **show_rc, struct cYAML **err_rc,
3079 * TODO: This function is changing in a future patch to accommodate
3080 * PEER_LIST and proper filtering on any nid of the peer
3082 struct lnet_ioctl_peer_cfg peer_info;
3083 struct lnet_peer_ni_credit_info *lpni_cri;
3084 struct lnet_ioctl_element_stats *lpni_stats;
3085 struct lnet_ioctl_element_msg_stats *msg_stats;
3086 struct lnet_ioctl_peer_ni_hstats *hstats;
3088 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3093 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3094 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3095 *msg_statistics = NULL, *statistics = NULL,
3097 char err_str[LNET_MAX_STR_LEN];
3098 struct lnet_process_id *list = NULL;
3103 snprintf(err_str, sizeof(err_str),
3104 "\"out of memory\"");
3106 /* create struct cYAML root object */
3107 root = cYAML_create_object(NULL, NULL);
3111 peer_root = cYAML_create_seq(root, "peer");
3112 if (peer_root == NULL)
3116 size = count * sizeof(struct lnet_process_id);
3117 list = malloc(size);
3123 list[0].nid = libcfs_str2nid(knid);
3127 memset(&peer_info, 0, sizeof(peer_info));
3128 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3129 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3130 peer_info.prcfg_size = size;
3131 peer_info.prcfg_bulk = list;
3134 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3136 count = peer_info.prcfg_count;
3140 if (l_errno != E2BIG) {
3143 "\"cannot get peer list: %s\"",
3149 size = peer_info.prcfg_size;
3150 list = malloc(size);
3159 data = malloc(size);
3165 for (i = 0; i < count; i++) {
3167 memset(&peer_info, 0, sizeof(peer_info));
3168 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3169 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3170 peer_info.prcfg_prim_nid = list[i].nid;
3171 peer_info.prcfg_size = size;
3172 peer_info.prcfg_bulk = data;
3175 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3180 if (l_errno != E2BIG) {
3183 "\"cannot get peer information: %s\"",
3189 size = peer_info.prcfg_size;
3190 data = malloc(size);
3198 peer = cYAML_create_seq_item(peer_root);
3202 if (first_seq == NULL)
3205 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3206 if (cYAML_create_string(peer, "primary nid",
3207 libcfs_nid2str(pnid))
3210 if (cYAML_create_string(peer, "Multi-Rail",
3211 peer_info.prcfg_mr ? "True" : "False")
3215 * print out the state of the peer only if details are
3220 cYAML_create_number(peer, "peer state",
3221 peer_info.prcfg_state)
3226 tmp = cYAML_create_seq(peer, "peer ni");
3231 for (j = 0; j < peer_info.prcfg_count; j++) {
3233 lpni_cri = (void*)nidp + sizeof(nidp);
3234 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3235 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3236 hstats = (void *)msg_stats + sizeof(*msg_stats);
3237 lpni_data = (void *)hstats + sizeof(*hstats);
3239 peer_ni = cYAML_create_seq_item(tmp);
3240 if (peer_ni == NULL)
3243 if (cYAML_create_string(peer_ni, "nid",
3244 libcfs_nid2str(*nidp))
3251 if (cYAML_create_string(peer_ni, "state",
3252 lpni_cri->cr_aliveness)
3259 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3260 lpni_cri->cr_ni_peer_tx_credits)
3264 if (cYAML_create_number(peer_ni, "available_tx_credits",
3265 lpni_cri->cr_peer_tx_credits)
3269 if (cYAML_create_number(peer_ni, "min_tx_credits",
3270 lpni_cri->cr_peer_min_tx_credits)
3274 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3275 lpni_cri->cr_peer_tx_qnob)
3279 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3280 lpni_cri->cr_peer_rtr_credits)
3284 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3285 lpni_cri->cr_peer_min_rtr_credits)
3289 if (cYAML_create_number(peer_ni, "refcount",
3290 lpni_cri->cr_refcount) == NULL)
3293 statistics = cYAML_create_object(peer_ni, "statistics");
3294 if (statistics == NULL)
3297 if (cYAML_create_number(statistics, "send_count",
3298 lpni_stats->iel_send_count)
3302 if (cYAML_create_number(statistics, "recv_count",
3303 lpni_stats->iel_recv_count)
3307 if (cYAML_create_number(statistics, "drop_count",
3308 lpni_stats->iel_drop_count)
3315 for (k = 0; k < 3; k++) {
3316 struct lnet_ioctl_comm_count *counts;
3318 msg_statistics = cYAML_create_object(peer_ni,
3319 (char *) gmsg_stat_names[k]);
3320 if (msg_statistics == NULL)
3323 counts = get_counts(msg_stats, k);
3327 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3332 yhstats = cYAML_create_object(peer_ni, "health stats");
3335 if (cYAML_create_number(yhstats, "health value",
3336 hstats->hlpni_health_value)
3339 if (cYAML_create_number(yhstats, "dropped",
3340 hstats->hlpni_remote_dropped)
3343 if (cYAML_create_number(yhstats, "timeout",
3344 hstats->hlpni_remote_timeout)
3347 if (cYAML_create_number(yhstats, "error",
3348 hstats->hlpni_remote_error)
3351 if (cYAML_create_number(yhstats, "network timeout",
3352 hstats->hlpni_network_timeout)
3358 /* print output iff show_rc is not provided */
3359 if (show_rc == NULL)
3360 cYAML_print_tree(root);
3362 snprintf(err_str, sizeof(err_str), "\"success\"");
3363 rc = LUSTRE_CFG_RC_NO_ERR;
3368 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3369 cYAML_free_tree(root);
3370 } else if (show_rc != NULL && *show_rc != NULL) {
3371 struct cYAML *show_node;
3372 /* find the peer node, if one doesn't exist then
3373 * insert one. Otherwise add to the one there
3375 show_node = cYAML_get_object_item(*show_rc,
3377 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3378 cYAML_insert_child(show_node, first_seq);
3381 } else if (show_node == NULL) {
3382 cYAML_insert_sibling((*show_rc)->cy_child,
3386 cYAML_free_tree(root);
3392 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3398 int lustre_lnet_list_peer(int seq_no,
3399 struct cYAML **show_rc, struct cYAML **err_rc)
3401 struct lnet_ioctl_peer_cfg peer_info;
3402 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3407 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3408 char err_str[LNET_MAX_STR_LEN];
3409 struct lnet_process_id *list = NULL;
3411 snprintf(err_str, sizeof(err_str),
3412 "\"out of memory\"");
3414 memset(&peer_info, 0, sizeof(peer_info));
3416 /* create struct cYAML root object */
3417 root = cYAML_create_object(NULL, NULL);
3421 list_root = cYAML_create_seq(root, "peer list");
3422 if (list_root == NULL)
3426 size = count * sizeof(struct lnet_process_id);
3427 list = malloc(size);
3433 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3434 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3435 peer_info.prcfg_size = size;
3436 peer_info.prcfg_bulk = list;
3439 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3440 count = peer_info.prcfg_count;
3444 if (l_errno != E2BIG) {
3447 "\"cannot get peer list: %s\"",
3453 size = peer_info.prcfg_size;
3454 list = malloc(size);
3461 /* count is now the actual number of ids in the list. */
3462 for (i = 0; i < count; i++) {
3463 if (cYAML_create_string(list_root, "nid",
3464 libcfs_nid2str(list[i].nid))
3469 /* print output iff show_rc is not provided */
3470 if (show_rc == NULL)
3471 cYAML_print_tree(root);
3473 snprintf(err_str, sizeof(err_str), "\"success\"");
3474 rc = LUSTRE_CFG_RC_NO_ERR;
3479 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3480 cYAML_free_tree(root);
3481 } else if (show_rc != NULL && *show_rc != NULL) {
3482 struct cYAML *show_node;
3483 /* find the peer node, if one doesn't exist then
3484 * insert one. Otherwise add to the one there
3486 show_node = cYAML_get_object_item(*show_rc,
3488 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3489 cYAML_insert_child(show_node, first_seq);
3492 } else if (show_node == NULL) {
3493 cYAML_insert_sibling((*show_rc)->cy_child,
3497 cYAML_free_tree(root);
3503 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3509 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3512 struct cYAML *show_node;
3514 show_node = cYAML_get_object_item(show_rc, "global");
3515 if (show_node != NULL)
3516 cYAML_insert_sibling(show_node->cy_child,
3519 cYAML_insert_sibling(show_rc->cy_child,
3524 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3525 char *name, __u32 value,
3526 struct cYAML **show_rc,
3527 struct cYAML **err_rc, int err)
3529 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3530 struct cYAML *root = NULL, *global = NULL;
3537 root = cYAML_create_object(NULL, NULL);
3541 global = cYAML_create_object(root, "global");
3545 if (cYAML_create_number(global, name,
3549 if (show_rc == NULL)
3550 cYAML_print_tree(root);
3552 snprintf(err_str, err_len, "\"success\"");
3554 rc = LUSTRE_CFG_RC_NO_ERR;
3557 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3558 cYAML_free_tree(root);
3559 } else if (show_rc != NULL && *show_rc != NULL) {
3560 add_to_global(*show_rc, global, root);
3565 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3570 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3571 struct cYAML **show_rc,
3572 struct cYAML **err_rc)
3574 struct lnet_ioctl_set_value data;
3577 char err_str[LNET_MAX_STR_LEN];
3579 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3581 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3583 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3588 "\"cannot get %s: %s\"",
3589 name, strerror(l_errno));
3592 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3593 data.sv_value, show_rc, err_rc, l_errno);
3596 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3597 struct cYAML **err_rc)
3599 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3600 char val[LNET_MAX_STR_LEN];
3601 int intrv = -1, l_errno = 0;
3602 char err_str[LNET_MAX_STR_LEN];
3604 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3606 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3610 snprintf(err_str, sizeof(err_str),
3611 "\"cannot get recovery interval: %d\"", rc);
3616 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3617 "recovery_interval", intrv, show_rc,
3621 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3622 struct cYAML **err_rc)
3624 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3625 char val[LNET_MAX_STR_LEN];
3626 int sen = -1, l_errno = 0;
3627 char err_str[LNET_MAX_STR_LEN];
3629 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3631 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3635 snprintf(err_str, sizeof(err_str),
3636 "\"cannot get health sensitivity: %d\"", rc);
3641 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3642 "health_sensitivity", sen, show_rc,
3646 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3647 struct cYAML **err_rc)
3649 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3650 char val[LNET_MAX_STR_LEN];
3651 int sen = -1, l_errno = 0;
3652 char err_str[LNET_MAX_STR_LEN];
3654 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3656 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3660 snprintf(err_str, sizeof(err_str),
3661 "\"cannot get router sensitivity percentage: %d\"", rc);
3666 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3667 "router_sensitivity", sen, show_rc,
3671 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3672 struct cYAML **err_rc)
3674 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3675 char val[LNET_MAX_STR_LEN];
3676 int tto = -1, l_errno = 0;
3677 char err_str[LNET_MAX_STR_LEN];
3679 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3681 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3685 snprintf(err_str, sizeof(err_str),
3686 "\"cannot get transaction timeout: %d\"", rc);
3691 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3692 "transaction_timeout", tto, show_rc,
3696 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3697 struct cYAML **err_rc)
3699 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3700 char val[LNET_MAX_STR_LEN];
3701 int retry_count = -1, l_errno = 0;
3702 char err_str[LNET_MAX_STR_LEN];
3704 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3706 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3710 snprintf(err_str, sizeof(err_str),
3711 "\"cannot get retry count: %d\"", rc);
3713 retry_count = atoi(val);
3716 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3717 "retry_count", retry_count, show_rc,
3721 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3722 struct cYAML **show_rc, struct cYAML **err_rc)
3724 struct lnet_ioctl_recovery_list nid_list;
3725 struct cYAML *root = NULL, *nids = NULL;
3727 char err_str[LNET_MAX_STR_LEN];
3729 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3731 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3732 nid_list.rlst_type = type;
3734 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3740 if (nid_list.rlst_num_nids == 0)
3743 root = cYAML_create_object(NULL, NULL);
3747 nids = cYAML_create_object(root, name);
3753 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3754 char nidenum[LNET_MAX_STR_LEN];
3755 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3756 if (!cYAML_create_string(nids, nidenum,
3757 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3761 snprintf(err_str, sizeof(err_str), "success\n");
3766 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3767 cYAML_free_tree(root);
3768 } else if (show_rc != NULL && *show_rc != NULL) {
3769 struct cYAML *show_node;
3770 /* find the net node, if one doesn't exist
3771 * then insert one. Otherwise add to the one there
3773 show_node = cYAML_get_object_item(*show_rc, name);
3774 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3775 cYAML_insert_child(show_node, nids);
3778 } else if (show_node == NULL) {
3779 cYAML_insert_sibling((*show_rc)->cy_child,
3783 cYAML_free_tree(root);
3789 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3794 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3795 struct cYAML **err_rc)
3797 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3798 seq_no, show_rc, err_rc);
3801 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3802 struct cYAML **err_rc)
3804 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3805 seq_no, show_rc, err_rc);
3808 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3809 struct cYAML **err_rc)
3811 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3812 char val[LNET_MAX_STR_LEN];
3813 int max_intf = -1, l_errno = 0;
3814 char err_str[LNET_MAX_STR_LEN];
3816 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3818 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3822 snprintf(err_str, sizeof(err_str),
3823 "\"cannot get max interfaces: %d\"", rc);
3825 max_intf = atoi(val);
3828 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3829 "max_intf", max_intf, show_rc,
3833 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3834 struct cYAML **err_rc)
3836 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3837 char val[LNET_MAX_STR_LEN];
3838 int discovery = -1, l_errno = 0;
3839 char err_str[LNET_MAX_STR_LEN];
3841 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3843 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3847 snprintf(err_str, sizeof(err_str),
3848 "\"cannot get discovery setting: %d\"", rc);
3851 * The kernel stores a discovery disabled value. User space
3852 * shows whether discovery is enabled. So the value must be
3855 discovery = !atoi(val);
3858 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3859 "discovery", discovery, show_rc,
3863 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3864 struct cYAML **err_rc)
3866 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3867 char val[LNET_MAX_STR_LEN];
3868 int drop_asym_route = -1, l_errno = 0;
3869 char err_str[LNET_MAX_STR_LEN];
3871 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3873 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3877 snprintf(err_str, sizeof(err_str),
3878 "\"cannot get drop asym route setting: %d\"", rc);
3880 drop_asym_route = atoi(val);
3883 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3884 "drop_asym_route", drop_asym_route,
3885 show_rc, err_rc, l_errno);
3888 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3889 struct cYAML **err_rc)
3891 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3892 "numa_range", show_rc, err_rc);
3895 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3896 struct cYAML **err_rc)
3898 struct lnet_ioctl_lnet_stats data;
3899 struct lnet_counters *cntrs;
3902 char err_str[LNET_MAX_STR_LEN];
3903 struct cYAML *root = NULL, *stats = NULL;
3905 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3907 LIBCFS_IOC_INIT_V2(data, st_hdr);
3909 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3914 "\"cannot get lnet statistics: %s\"",
3920 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3922 cntrs = &data.st_cntrs;
3924 root = cYAML_create_object(NULL, NULL);
3928 stats = cYAML_create_object(root, "statistics");
3932 if (!cYAML_create_number(stats, "msgs_alloc",
3933 cntrs->lct_common.lcc_msgs_alloc))
3936 if (!cYAML_create_number(stats, "msgs_max",
3937 cntrs->lct_common.lcc_msgs_max))
3940 if (!cYAML_create_number(stats, "rst_alloc",
3941 cntrs->lct_health.lch_rst_alloc))
3944 if (!cYAML_create_number(stats, "errors",
3945 cntrs->lct_common.lcc_errors))
3948 if (!cYAML_create_number(stats, "send_count",
3949 cntrs->lct_common.lcc_send_count))
3952 if (!cYAML_create_number(stats, "resend_count",
3953 cntrs->lct_health.lch_resend_count))
3956 if (!cYAML_create_number(stats, "response_timeout_count",
3957 cntrs->lct_health.lch_response_timeout_count))
3960 if (!cYAML_create_number(stats, "local_interrupt_count",
3961 cntrs->lct_health.lch_local_interrupt_count))
3964 if (!cYAML_create_number(stats, "local_dropped_count",
3965 cntrs->lct_health.lch_local_dropped_count))
3968 if (!cYAML_create_number(stats, "local_aborted_count",
3969 cntrs->lct_health.lch_local_aborted_count))
3972 if (!cYAML_create_number(stats, "local_no_route_count",
3973 cntrs->lct_health.lch_local_no_route_count))
3976 if (!cYAML_create_number(stats, "local_timeout_count",
3977 cntrs->lct_health.lch_local_timeout_count))
3980 if (!cYAML_create_number(stats, "local_error_count",
3981 cntrs->lct_health.lch_local_error_count))
3984 if (!cYAML_create_number(stats, "remote_dropped_count",
3985 cntrs->lct_health.lch_remote_dropped_count))
3988 if (!cYAML_create_number(stats, "remote_error_count",
3989 cntrs->lct_health.lch_remote_error_count))
3992 if (!cYAML_create_number(stats, "remote_timeout_count",
3993 cntrs->lct_health.lch_remote_timeout_count))
3996 if (!cYAML_create_number(stats, "network_timeout_count",
3997 cntrs->lct_health.lch_network_timeout_count))
4000 if (!cYAML_create_number(stats, "recv_count",
4001 cntrs->lct_common.lcc_recv_count))
4004 if (!cYAML_create_number(stats, "route_count",
4005 cntrs->lct_common.lcc_route_count))
4008 if (!cYAML_create_number(stats, "drop_count",
4009 cntrs->lct_common.lcc_drop_count))
4012 if (!cYAML_create_number(stats, "send_length",
4013 cntrs->lct_common.lcc_send_length))
4016 if (!cYAML_create_number(stats, "recv_length",
4017 cntrs->lct_common.lcc_recv_length))
4020 if (!cYAML_create_number(stats, "route_length",
4021 cntrs->lct_common.lcc_route_length))
4024 if (!cYAML_create_number(stats, "drop_length",
4025 cntrs->lct_common.lcc_drop_length))
4029 cYAML_print_tree(root);
4031 snprintf(err_str, sizeof(err_str), "\"success\"");
4032 rc = LUSTRE_CFG_RC_NO_ERR;
4034 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4035 cYAML_free_tree(root);
4036 } else if (show_rc != NULL && *show_rc != NULL) {
4037 cYAML_insert_sibling((*show_rc)->cy_child,
4044 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4049 typedef int (*cmd_handler_t)(struct cYAML *tree,
4050 struct cYAML **show_rc,
4051 struct cYAML **err_rc);
4053 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4054 struct cYAML **err_rc)
4056 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4058 net = cYAML_get_object_item(tree, "net");
4059 gw = cYAML_get_object_item(tree, "gateway");
4060 hop = cYAML_get_object_item(tree, "hop");
4061 prio = cYAML_get_object_item(tree, "priority");
4062 sen = cYAML_get_object_item(tree, "health_sensitivity");
4063 seq_no = cYAML_get_object_item(tree, "seq_no");
4065 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4066 (gw) ? gw->cy_valuestring : NULL,
4067 (hop) ? hop->cy_valueint : -1,
4068 (prio) ? prio->cy_valueint : -1,
4069 (sen) ? sen->cy_valueint : -1,
4070 (seq_no) ? seq_no->cy_valueint : -1,
4074 static void yaml_free_string_array(char **array, int num)
4077 char **sub_array = array;
4079 for (i = 0; i < num; i++) {
4080 if (*sub_array != NULL)
4090 * 0: <intf_name>['['<expr>']']
4091 * 1: <intf_name>['['<expr>']']
4093 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4094 struct lnet_dlc_network_descr *nw_descr)
4096 struct cYAML *child = NULL;
4097 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4098 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4100 if (intf_tree == NULL || nw_descr == NULL)
4101 return LUSTRE_CFG_RC_BAD_PARAM;
4103 /* now grab all the interfaces and their cpts */
4104 child = intf_tree->cy_child;
4105 while (child != NULL) {
4106 if (child->cy_valuestring == NULL) {
4107 child = child->cy_next;
4111 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4114 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4115 child->cy_valuestring,
4116 strlen(child->cy_valuestring));
4117 if (rc != LUSTRE_CFG_RC_NO_ERR)
4121 child = child->cy_next;
4125 return LUSTRE_CFG_RC_MISSING_PARAM;
4130 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4132 list_del(&intf_descr->intf_on_network);
4133 free_intf_descr(intf_descr);
4140 yaml_extract_cmn_tunables(struct cYAML *tree,
4141 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4142 struct cfs_expr_list **global_cpts)
4144 struct cYAML *tun, *item, *smp;
4147 tun = cYAML_get_object_item(tree, "tunables");
4149 item = cYAML_get_object_item(tun, "peer_timeout");
4151 tunables->lct_peer_timeout = item->cy_valueint;
4152 item = cYAML_get_object_item(tun, "peer_credits");
4154 tunables->lct_peer_tx_credits = item->cy_valueint;
4155 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4157 tunables->lct_peer_rtr_credits = item->cy_valueint;
4158 item = cYAML_get_object_item(tun, "credits");
4160 tunables->lct_max_tx_credits = item->cy_valueint;
4161 smp = cYAML_get_object_item(tun, "CPT");
4163 rc = cfs_expr_list_parse(smp->cy_valuestring,
4164 strlen(smp->cy_valuestring),
4165 0, UINT_MAX, global_cpts);
4167 *global_cpts = NULL;
4177 yaml_extract_tunables(struct cYAML *tree,
4178 struct lnet_ioctl_config_lnd_tunables *tunables,
4179 struct cfs_expr_list **global_cpts,
4184 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4190 lustre_yaml_extract_lnd_tunables(tree, net_type,
4198 * - net type: <net>[<NUM>]
4200 * - nid: <ip>@<net>[<NUM>]
4203 * 0: <intf_name>['['<expr>']']
4204 * 1: <intf_name>['['<expr>']']
4206 * peer_timeout: <NUM>
4207 * peer_credits: <NUM>
4208 * peer_buffer_credits: <NUM>
4211 * peercredits_hiw: <NUM>
4212 * map_on_demand: <NUM>
4213 * concurrent_sends: <NUM>
4214 * fmr_pool_size: <NUM>
4215 * fmr_flush_trigger: <NUM>
4218 * At least one interface is required. If no interfaces are provided the
4219 * network interface can not be configured.
4221 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4222 struct cYAML **err_rc)
4224 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4226 int num_entries = 0, rc;
4227 struct lnet_dlc_network_descr nw_descr;
4228 struct cfs_expr_list *global_cpts = NULL;
4229 struct lnet_ioctl_config_lnd_tunables tunables;
4232 memset(&tunables, 0, sizeof(tunables));
4234 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4235 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4237 ip2net = cYAML_get_object_item(tree, "ip2net");
4238 net = cYAML_get_object_item(tree, "net type");
4240 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4242 nw_descr.nw_id = LOLND;
4245 * if neither net nor ip2nets are present, then we can not
4246 * configure the network.
4248 if (!net && !ip2net)
4249 return LUSTRE_CFG_RC_MISSING_PARAM;
4251 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4252 if (local_nis == NULL)
4253 return LUSTRE_CFG_RC_MISSING_PARAM;
4255 if (!cYAML_is_sequence(local_nis))
4256 return LUSTRE_CFG_RC_BAD_PARAM;
4258 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4259 intf = cYAML_get_object_item(item, "interfaces");
4262 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4263 if (num_entries <= 0) {
4264 cYAML_build_error(num_entries, -1, "ni", "add",
4265 "bad interface list",
4267 return LUSTRE_CFG_RC_BAD_PARAM;
4271 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4272 LNET_NETTYP(nw_descr.nw_id));
4273 seq_no = cYAML_get_object_item(tree, "seq_no");
4275 rc = lustre_lnet_config_ni(&nw_descr,
4277 (ip2net) ? ip2net->cy_valuestring : NULL,
4278 (found) ? &tunables: NULL,
4279 (seq_no) ? seq_no->cy_valueint : -1,
4282 if (global_cpts != NULL)
4283 cfs_expr_list_free(global_cpts);
4290 * - net-spec: <tcp|o2ib|gni>[NUM]
4292 * 0: <intf name>['['<expr>']']
4293 * 1: <intf name>['['<expr>']']
4295 * 0: <expr.expr.expr.expr>
4296 * 1: <expr.expr.expr.expr>
4298 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4299 struct cYAML **show_rc,
4300 struct cYAML **err_rc)
4302 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4304 struct lustre_lnet_ip2nets ip2nets;
4305 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4307 int rc = LUSTRE_CFG_RC_NO_ERR;
4308 struct cfs_expr_list *global_cpts = NULL;
4309 struct cfs_expr_list *el, *el_tmp;
4310 struct lnet_ioctl_config_lnd_tunables tunables;
4311 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4314 memset(&tunables, 0, sizeof(tunables));
4316 /* initialize all lists */
4317 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4318 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4319 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4321 net = cYAML_get_object_item(tree, "net-spec");
4323 return LUSTRE_CFG_RC_BAD_PARAM;
4325 if (net != NULL && net->cy_valuestring == NULL)
4326 return LUSTRE_CFG_RC_BAD_PARAM;
4328 /* assign the network id */
4329 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4330 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4331 return LUSTRE_CFG_RC_BAD_PARAM;
4333 seq_no = cYAML_get_object_item(tree, "seq_no");
4335 intf = cYAML_get_object_item(tree, "interfaces");
4337 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4339 return LUSTRE_CFG_RC_BAD_PARAM;
4342 ip_range = cYAML_get_object_item(tree, "ip-range");
4343 if (ip_range != NULL) {
4344 item = ip_range->cy_child;
4345 while (item != NULL) {
4346 if (item->cy_valuestring == NULL) {
4347 item = item->cy_next;
4351 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4352 item->cy_valuestring);
4354 if (rc != LUSTRE_CFG_RC_NO_ERR)
4357 item = item->cy_next;
4361 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4362 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4364 rc = lustre_lnet_config_ip2nets(&ip2nets,
4365 (found) ? &tunables : NULL,
4367 (seq_no) ? seq_no->cy_valueint : -1,
4371 * don't stop because there was no match. Continue processing the
4372 * rest of the rules. If non-match then nothing is configured
4374 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4375 rc = LUSTRE_CFG_RC_NO_ERR;
4377 list_for_each_entry_safe(intf_descr, intf_tmp,
4378 &ip2nets.ip2nets_net.nw_intflist,
4380 list_del(&intf_descr->intf_on_network);
4381 free_intf_descr(intf_descr);
4384 list_for_each_entry_safe(ip_range_descr, tmp,
4385 &ip2nets.ip2nets_ip_ranges,
4387 list_del(&ip_range_descr->ipr_entry);
4388 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4390 list_del(&el->el_link);
4391 cfs_expr_list_free(el);
4393 free(ip_range_descr);
4399 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4400 struct cYAML **err_rc)
4402 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4404 int num_entries, rc;
4405 struct lnet_dlc_network_descr nw_descr;
4407 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4408 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4410 net = cYAML_get_object_item(tree, "net type");
4412 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4414 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4415 if (local_nis == NULL)
4416 return LUSTRE_CFG_RC_MISSING_PARAM;
4418 if (!cYAML_is_sequence(local_nis))
4419 return LUSTRE_CFG_RC_BAD_PARAM;
4421 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4422 intf = cYAML_get_object_item(item, "interfaces");
4425 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4426 if (num_entries <= 0) {
4427 cYAML_build_error(num_entries, -1, "ni", "add",
4428 "bad interface list",
4430 return LUSTRE_CFG_RC_BAD_PARAM;
4434 seq_no = cYAML_get_object_item(tree, "seq_no");
4436 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4437 (seq_no) ? seq_no->cy_valueint : -1,
4443 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4444 char *prim_nid, bool del)
4446 struct cYAML *child = NULL, *entry = NULL;
4448 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4450 if (cYAML_is_sequence(nids_entry)) {
4451 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4452 entry = cYAML_get_object_item(child, "nid");
4453 /* don't count an empty entry */
4454 if (!entry || !entry->cy_valuestring)
4458 (strcmp(entry->cy_valuestring, prim_nid)
4461 * primary nid is present in the list of
4462 * nids so that means we want to delete
4463 * the entire peer, so no need to go
4464 * further. Just delete the entire peer.
4474 return LUSTRE_CFG_RC_MISSING_PARAM;
4476 nids = calloc(sizeof(*nids), num);
4478 return LUSTRE_CFG_RC_OUT_OF_MEM;
4480 /* now grab all the nids */
4483 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4484 entry = cYAML_get_object_item(child, "nid");
4485 if (!entry || !entry->cy_valuestring)
4488 nids[num] = strdup(entry->cy_valuestring);
4490 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4502 yaml_free_string_array(nids, num);
4507 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4508 struct cYAML **err_rc)
4512 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4513 char err_str[LNET_MAX_STR_LEN];
4516 seq_no = cYAML_get_object_item(tree, "seq_no");
4517 prim_nid = cYAML_get_object_item(tree, "primary nid");
4518 mr = cYAML_get_object_item(tree, "Multi-Rail");
4519 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4520 peer_nis = cYAML_get_object_item(tree, "peer ni");
4522 if (ip2nets && (prim_nid || peer_nis)) {
4523 rc = LUSTRE_CFG_RC_BAD_PARAM;
4524 snprintf(err_str, sizeof(err_str),
4525 "ip2nets can not be specified along side prim_nid"
4526 " or peer ni fields");
4527 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4528 ADD_CMD, "peer", err_str, err_rc);
4535 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4537 else if (!strcmp(mr->cy_valuestring, "False"))
4540 rc = LUSTRE_CFG_RC_BAD_PARAM;
4541 snprintf(err_str, sizeof(err_str), "Bad MR value");
4542 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4543 ADD_CMD, "peer", err_str, err_rc);
4548 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4549 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4553 snprintf(err_str, sizeof(err_str),
4554 "error copying nids from YAML block");
4555 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4556 ADD_CMD, "peer", err_str, err_rc);
4560 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4561 nids, num, mr_value,
4562 (ip2nets) ? true : false,
4563 (seq_no) ? seq_no->cy_valueint : -1,
4566 yaml_free_string_array(nids, num);
4570 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4571 struct cYAML **err_rc)
4575 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4576 char err_str[LNET_MAX_STR_LEN];
4578 seq_no = cYAML_get_object_item(tree, "seq_no");
4579 prim_nid = cYAML_get_object_item(tree, "primary nid");
4580 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4581 peer_nis = cYAML_get_object_item(tree, "peer ni");
4583 if (ip2nets && (prim_nid || peer_nis)) {
4584 rc = LUSTRE_CFG_RC_BAD_PARAM;
4585 snprintf(err_str, sizeof(err_str),
4586 "ip2nets can not be specified along side prim_nid"
4587 " or peer ni fields");
4588 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4589 DEL_CMD, "peer", err_str, err_rc);
4593 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4594 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4597 snprintf(err_str, sizeof(err_str),
4598 "error copying nids from YAML block");
4599 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4600 ADD_CMD, "peer", err_str, err_rc);
4604 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4605 nids, num, (ip2nets) ? true : false,
4606 (seq_no) ? seq_no->cy_valueint : -1,
4609 yaml_free_string_array(nids, num);
4613 static int handle_yaml_config_buffers(struct cYAML *tree,
4614 struct cYAML **show_rc,
4615 struct cYAML **err_rc)
4618 struct cYAML *tiny, *small, *large, *seq_no;
4620 tiny = cYAML_get_object_item(tree, "tiny");
4621 small = cYAML_get_object_item(tree, "small");
4622 large = cYAML_get_object_item(tree, "large");
4623 seq_no = cYAML_get_object_item(tree, "seq_no");
4625 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4626 (small) ? small->cy_valueint : -1,
4627 (large) ? large->cy_valueint : -1,
4628 (seq_no) ? seq_no->cy_valueint : -1,
4634 static int handle_yaml_config_routing(struct cYAML *tree,
4635 struct cYAML **show_rc,
4636 struct cYAML **err_rc)
4638 int rc = LUSTRE_CFG_RC_NO_ERR;
4639 struct cYAML *seq_no, *enable;
4641 seq_no = cYAML_get_object_item(tree, "seq_no");
4642 enable = cYAML_get_object_item(tree, "enable");
4645 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4647 seq_no->cy_valueint : -1,
4654 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4655 struct cYAML **err_rc)
4659 struct cYAML *seq_no;
4661 net = cYAML_get_object_item(tree, "net");
4662 gw = cYAML_get_object_item(tree, "gateway");
4663 seq_no = cYAML_get_object_item(tree, "seq_no");
4665 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4666 (gw) ? gw->cy_valuestring : NULL,
4667 (seq_no) ? seq_no->cy_valueint : -1,
4671 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4672 struct cYAML **err_rc)
4674 struct cYAML *seq_no;
4676 seq_no = cYAML_get_object_item(tree, "seq_no");
4678 return lustre_lnet_enable_routing(0, (seq_no) ?
4679 seq_no->cy_valueint : -1,
4683 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4684 struct cYAML **err_rc)
4690 struct cYAML *detail;
4691 struct cYAML *seq_no;
4693 net = cYAML_get_object_item(tree, "net");
4694 gw = cYAML_get_object_item(tree, "gateway");
4695 hop = cYAML_get_object_item(tree, "hop");
4696 prio = cYAML_get_object_item(tree, "priority");
4697 detail = cYAML_get_object_item(tree, "detail");
4698 seq_no = cYAML_get_object_item(tree, "seq_no");
4700 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4701 (gw) ? gw->cy_valuestring : NULL,
4702 (hop) ? hop->cy_valueint : -1,
4703 (prio) ? prio->cy_valueint : -1,
4704 (detail) ? detail->cy_valueint : 0,
4705 (seq_no) ? seq_no->cy_valueint : -1,
4706 show_rc, err_rc, false);
4709 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4710 struct cYAML **err_rc)
4712 struct cYAML *net, *detail, *seq_no;
4714 net = cYAML_get_object_item(tree, "net");
4715 detail = cYAML_get_object_item(tree, "detail");
4716 seq_no = cYAML_get_object_item(tree, "seq_no");
4718 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4719 (detail) ? detail->cy_valueint : 0,
4720 (seq_no) ? seq_no->cy_valueint : -1,
4721 show_rc, err_rc, false);
4724 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4725 struct cYAML **err_rc)
4727 struct cYAML *seq_no;
4729 seq_no = cYAML_get_object_item(tree, "seq_no");
4731 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4732 show_rc, err_rc, false);
4735 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4736 struct cYAML **err_rc)
4738 struct cYAML *seq_no, *nid, *detail;
4740 seq_no = cYAML_get_object_item(tree, "seq_no");
4741 detail = cYAML_get_object_item(tree, "detail");
4742 nid = cYAML_get_object_item(tree, "nid");
4744 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4745 (detail) ? detail->cy_valueint : 0,
4746 (seq_no) ? seq_no->cy_valueint : -1,
4747 show_rc, err_rc, false);
4750 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4751 struct cYAML **err_rc)
4753 struct cYAML *seq_no;
4755 seq_no = cYAML_get_object_item(tree, "seq_no");
4757 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4761 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4762 struct cYAML **err_rc)
4764 struct cYAML *seq_no, *range;
4766 seq_no = cYAML_get_object_item(tree, "seq_no");
4767 range = cYAML_get_object_item(tree, "range");
4769 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4770 seq_no ? seq_no->cy_valueint : -1,
4774 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4775 struct cYAML **err_rc)
4777 struct cYAML *seq_no;
4779 seq_no = cYAML_get_object_item(tree, "seq_no");
4781 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4785 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4786 struct cYAML **err_rc)
4788 struct cYAML *seq_no;
4790 seq_no = cYAML_get_object_item(tree, "seq_no");
4792 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4796 static int handle_yaml_config_global_settings(struct cYAML *tree,
4797 struct cYAML **show_rc,
4798 struct cYAML **err_rc)
4800 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4801 *sen, *recov, *rsen, *drop_asym_route;
4804 seq_no = cYAML_get_object_item(tree, "seq_no");
4805 max_intf = cYAML_get_object_item(tree, "max_intf");
4807 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4808 seq_no ? seq_no->cy_valueint
4812 numa = cYAML_get_object_item(tree, "numa_range");
4814 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4815 seq_no ? seq_no->cy_valueint
4819 discovery = cYAML_get_object_item(tree, "discovery");
4821 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4822 seq_no ? seq_no->cy_valueint
4826 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4827 if (drop_asym_route)
4828 rc = lustre_lnet_config_drop_asym_route(
4829 drop_asym_route->cy_valueint,
4830 seq_no ? seq_no->cy_valueint : -1,
4833 retry = cYAML_get_object_item(tree, "retry_count");
4835 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4836 seq_no ? seq_no->cy_valueint
4840 tto = cYAML_get_object_item(tree, "transaction_timeout");
4842 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4843 seq_no ? seq_no->cy_valueint
4847 sen = cYAML_get_object_item(tree, "health_sensitivity");
4849 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4850 seq_no ? seq_no->cy_valueint
4854 recov = cYAML_get_object_item(tree, "recovery_interval");
4856 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4857 seq_no ? seq_no->cy_valueint
4861 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4863 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4864 seq_no ? seq_no->cy_valueint
4871 static int handle_yaml_del_global_settings(struct cYAML *tree,
4872 struct cYAML **show_rc,
4873 struct cYAML **err_rc)
4875 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4878 seq_no = cYAML_get_object_item(tree, "seq_no");
4879 max_intf = cYAML_get_object_item(tree, "max_intf");
4881 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4882 seq_no ? seq_no->cy_valueint
4886 numa = cYAML_get_object_item(tree, "numa_range");
4888 rc = lustre_lnet_config_numa_range(0,
4889 seq_no ? seq_no->cy_valueint
4893 /* peer discovery is enabled by default */
4894 discovery = cYAML_get_object_item(tree, "discovery");
4896 rc = lustre_lnet_config_discovery(1,
4897 seq_no ? seq_no->cy_valueint
4901 /* asymmetrical route messages are accepted by default */
4902 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4903 if (drop_asym_route)
4904 rc = lustre_lnet_config_drop_asym_route(
4905 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4910 static int handle_yaml_show_global_settings(struct cYAML *tree,
4911 struct cYAML **show_rc,
4912 struct cYAML **err_rc)
4914 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4915 *sen, *recov, *rsen, *drop_asym_route;
4918 seq_no = cYAML_get_object_item(tree, "seq_no");
4919 max_intf = cYAML_get_object_item(tree, "max_intf");
4921 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4925 numa = cYAML_get_object_item(tree, "numa_range");
4927 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4931 discovery = cYAML_get_object_item(tree, "discovery");
4933 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4937 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4938 if (drop_asym_route)
4939 rc = lustre_lnet_show_drop_asym_route(
4940 seq_no ? seq_no->cy_valueint : -1,
4943 retry = cYAML_get_object_item(tree, "retry_count");
4945 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4949 tto = cYAML_get_object_item(tree, "transaction_timeout");
4951 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4955 sen = cYAML_get_object_item(tree, "health_sensitivity");
4957 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4961 recov = cYAML_get_object_item(tree, "recovery_interval");
4963 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4967 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4969 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4976 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4977 struct cYAML **err_rc)
4979 struct cYAML *seq_no, *nid, *timeout;
4981 seq_no = cYAML_get_object_item(tree, "seq_no");
4982 nid = cYAML_get_object_item(tree, "primary nid");
4983 timeout = cYAML_get_object_item(tree, "timeout");
4985 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4986 (timeout) ? timeout->cy_valueint : 1000,
4987 (seq_no) ? seq_no->cy_valueint : -1,
4991 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4992 struct cYAML **err_rc)
4994 struct cYAML *seq_no, *nid, *force;
4996 seq_no = cYAML_get_object_item(tree, "seq_no");
4997 nid = cYAML_get_object_item(tree, "primary nid");
4998 force = cYAML_get_object_item(tree, "force");
5000 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5001 (force) ? force->cy_valueint : 0,
5002 (seq_no) ? seq_no->cy_valueint : -1,
5006 static int handle_yaml_no_op()
5008 return LUSTRE_CFG_RC_NO_ERR;
5011 struct lookup_cmd_hdlr_tbl {
5016 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5017 { .name = "route", .cb = handle_yaml_config_route },
5018 { .name = "net", .cb = handle_yaml_config_ni },
5019 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5020 { .name = "peer", .cb = handle_yaml_config_peer },
5021 { .name = "routing", .cb = handle_yaml_config_routing },
5022 { .name = "buffers", .cb = handle_yaml_config_buffers },
5023 { .name = "statistics", .cb = handle_yaml_no_op },
5024 { .name = "global", .cb = handle_yaml_config_global_settings},
5025 { .name = "numa", .cb = handle_yaml_config_numa },
5026 { .name = "ping", .cb = handle_yaml_no_op },
5027 { .name = "discover", .cb = handle_yaml_no_op },
5030 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5031 { .name = "route", .cb = handle_yaml_del_route },
5032 { .name = "net", .cb = handle_yaml_del_ni },
5033 { .name = "ip2nets", .cb = handle_yaml_no_op },
5034 { .name = "peer", .cb = handle_yaml_del_peer },
5035 { .name = "routing", .cb = handle_yaml_del_routing },
5036 { .name = "buffers", .cb = handle_yaml_no_op },
5037 { .name = "statistics", .cb = handle_yaml_no_op },
5038 { .name = "global", .cb = handle_yaml_del_global_settings},
5039 { .name = "numa", .cb = handle_yaml_del_numa },
5040 { .name = "ping", .cb = handle_yaml_no_op },
5041 { .name = "discover", .cb = handle_yaml_no_op },
5044 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5045 { .name = "route", .cb = handle_yaml_show_route },
5046 { .name = "net", .cb = handle_yaml_show_net },
5047 { .name = "peer", .cb = handle_yaml_show_peers },
5048 { .name = "ip2nets", .cb = handle_yaml_no_op },
5049 { .name = "routing", .cb = handle_yaml_show_routing },
5050 { .name = "buffers", .cb = handle_yaml_show_routing },
5051 { .name = "statistics", .cb = handle_yaml_show_stats },
5052 { .name = "global", .cb = handle_yaml_show_global_settings},
5053 { .name = "numa", .cb = handle_yaml_show_numa },
5054 { .name = "ping", .cb = handle_yaml_no_op },
5055 { .name = "discover", .cb = handle_yaml_no_op },
5058 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5059 { .name = "route", .cb = handle_yaml_no_op },
5060 { .name = "net", .cb = handle_yaml_no_op },
5061 { .name = "peer", .cb = handle_yaml_no_op },
5062 { .name = "ip2nets", .cb = handle_yaml_no_op },
5063 { .name = "routing", .cb = handle_yaml_no_op },
5064 { .name = "buffers", .cb = handle_yaml_no_op },
5065 { .name = "statistics", .cb = handle_yaml_no_op },
5066 { .name = "global", .cb = handle_yaml_no_op },
5067 { .name = "numa", .cb = handle_yaml_no_op },
5068 { .name = "ping", .cb = handle_yaml_ping },
5069 { .name = "discover", .cb = handle_yaml_discover },
5072 static cmd_handler_t lookup_fn(char *key,
5073 struct lookup_cmd_hdlr_tbl *tbl)
5079 for (i = 0; tbl[i].name != NULL; i++) {
5080 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5087 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5088 struct cYAML **show_rc, struct cYAML **err_rc)
5090 struct cYAML *tree, *item = NULL, *head, *child;
5092 char err_str[LNET_MAX_STR_LEN];
5093 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5095 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5097 return LUSTRE_CFG_RC_BAD_PARAM;
5099 child = tree->cy_child;
5100 while (child != NULL) {
5101 cb = lookup_fn(child->cy_string, table);
5103 snprintf(err_str, sizeof(err_str),
5104 "\"call back for '%s' not found\"",
5106 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5107 "yaml", "helper", err_str, err_rc);
5111 if (cYAML_is_sequence(child)) {
5112 while ((head = cYAML_get_next_seq_item(child, &item))
5114 rc = cb(head, show_rc, err_rc);
5115 if (rc != LUSTRE_CFG_RC_NO_ERR)
5119 rc = cb(child, show_rc, err_rc);
5120 if (rc != LUSTRE_CFG_RC_NO_ERR)
5124 child = child->cy_next;
5128 cYAML_free_tree(tree);
5133 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5135 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5139 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5141 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5145 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5147 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5151 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5153 return lustre_yaml_cb_helper(f, lookup_exec_tbl,