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 lustre_lnet_parse_nids(char *nids, char **array, int size,
269 char *comma = nids, *cur, *entry;
271 int i, len, start = 0, finish = 0;
273 if (nids == NULL || strlen(nids) == 0)
276 /* count the number or new nids, by counting the number of comma*/
278 comma = get_next_delimiter_in_nid(comma, ',');
288 * if the array is not NULL allocate a large enough array to house
289 * the old and new entries
291 new_array = calloc(sizeof(char*),
292 (size > 0) ? size + num_nids : num_nids);
297 /* parse our the new nids and add them to the tail of the array */
300 start = (size > 0) ? size: 0;
301 finish = (size > 0) ? size + num_nids : num_nids;
302 for (i = start; i < finish; i++) {
303 comma = get_next_delimiter_in_nid(comma, ',');
306 * the length of the string to be parsed out is
307 * from cur to end of string. So it's good enough
310 len = strlen(cur) + 1;
312 /* length of the string is comma - cur */
313 len = (comma - cur) + 1;
315 entry = calloc(1, len);
317 finish = i > 0 ? i - 1: 0;
320 strncpy(entry, cur, len - 1);
322 new_array[i] = entry;
329 /* add the old entries in the array and delete the old array*/
330 for (i = 0; i < size; i++)
331 new_array[i] = array[i];
336 *out_array = new_array;
341 for (i = start; i < finish; i++)
351 * <intf>[<expr>], <intf>[<expr>],..
353 int lustre_lnet_parse_interfaces(char *intf_str,
354 struct lnet_dlc_network_descr *nw_descr)
359 char *cur = intf_str, *next = NULL;
360 char *end = intf_str + strlen(intf_str);
362 struct lnet_dlc_intf_descr *intf_descr, *tmp;
364 if (nw_descr == NULL)
365 return LUSTRE_CFG_RC_BAD_PARAM;
368 open_square = strchr(cur, '[');
369 if (open_square != NULL) {
370 close_square = strchr(cur, ']');
371 if (close_square == NULL) {
372 rc = LUSTRE_CFG_RC_BAD_PARAM;
376 comma = strchr(cur, ',');
377 if (comma != NULL && comma > close_square) {
379 len = next - close_square;
385 comma = strchr(cur, ',');
395 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
396 if (rc != LUSTRE_CFG_RC_NO_ERR)
402 return LUSTRE_CFG_RC_NO_ERR;
405 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
407 list_del(&intf_descr->intf_on_network);
408 free_intf_descr(intf_descr);
414 int lustre_lnet_config_lib_init(void)
416 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
419 void lustre_lnet_config_lib_uninit(void)
421 unregister_ioc_dev(LNET_DEV_ID);
424 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
425 int seq_no, struct cYAML **err_rc)
427 struct libcfs_ioctl_data data;
430 char err_str[LNET_MAX_STR_LEN];
432 snprintf(err_str, sizeof(err_str), "\"Success\"");
434 LIBCFS_IOC_INIT(data);
436 /* Reverse logic is used here in order not to change
437 * the lctl utility */
438 data.ioc_flags = load_ni_from_mod ? 0 : 1;
440 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
442 rc = l_ioctl(LNET_DEV_ID, opc, &data);
446 "\"LNet %s error: %s\"", (up) ? "configure" :
447 "unconfigure", strerror(errno));
451 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
452 "lnet", err_str, err_rc);
457 static int dispatch_peer_ni_cmd(lnet_nid_t pnid, lnet_nid_t nid, __u32 cmd,
458 struct lnet_ioctl_peer_cfg *data,
459 char *err_str, char *cmd_str)
463 data->prcfg_prim_nid = pnid;
464 data->prcfg_cfg_nid = nid;
466 rc = l_ioctl(LNET_DEV_ID, cmd, data);
471 "\"cannot %s peer ni: %s\"",
472 (cmd_str) ? cmd_str : "add", strerror(errno));
473 err_str[LNET_MAX_STR_LEN - 1] = '\0';
479 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
480 int seq_no, struct cYAML **show_rc,
481 struct cYAML **err_rc)
484 struct lnet_ioctl_ping_data ping;
485 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
486 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
487 struct lnet_process_id id;
488 char err_str[LNET_MAX_STR_LEN] = {0};
489 char *sep, *token, *end;
492 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
496 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
498 data = calloc(1, len);
502 /* create struct cYAML root object */
503 root = cYAML_create_object(NULL, NULL);
507 ping_node = cYAML_create_seq(root, oper);
508 if (ping_node == NULL)
511 /* tokenise each nid in string ping_nids */
512 token = strtok(ping_nids, ",");
515 item = cYAML_create_seq_item(ping_node);
519 if (first_seq == NULL)
522 /* check if '-' is a part of NID, token */
523 sep = strchr(token, '-');
525 id.pid = LNET_PID_ANY;
526 /* if no net is specified, libcfs_str2nid() will assume tcp */
527 id.nid = libcfs_str2nid(token);
528 if (id.nid == LNET_NID_ANY) {
529 snprintf(err_str, sizeof(err_str),
530 "\"cannot parse NID '%s'\"",
532 rc = LUSTRE_CFG_RC_BAD_PARAM;
533 cYAML_build_error(rc, seq_no, MANAGE_CMD,
534 oper, err_str, err_rc);
538 if (token[0] == 'u' || token[0] == 'U')
539 id.pid = (strtoul(&token[1], &end, 0) |
540 (LNET_PID_USERFLAG));
542 id.pid = strtoul(token, &end, 0);
544 /* assuming '-' is part of hostname */
546 id.pid = LNET_PID_ANY;
547 id.nid = libcfs_str2nid(token);
548 if (id.nid == LNET_NID_ANY) {
549 snprintf(err_str, sizeof(err_str),
550 "\"cannot parse NID '%s'\"",
552 rc = LUSTRE_CFG_RC_BAD_PARAM;
553 cYAML_build_error(rc, seq_no, MANAGE_CMD,
559 id.nid = libcfs_str2nid(sep + 1);
560 if (id.nid == LNET_NID_ANY) {
561 snprintf(err_str, sizeof(err_str),
562 "\"cannot parse NID '%s'\"",
564 rc = LUSTRE_CFG_RC_BAD_PARAM;
565 cYAML_build_error(rc, seq_no, MANAGE_CMD,
572 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
573 ping.ping_hdr.ioc_len = sizeof(ping);
575 ping.op_param = param;
576 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
577 ping.ping_buf = data;
579 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
582 sizeof(err_str), "failed to %s %s: %s\n", oper,
583 id.pid == LNET_PID_ANY ?
584 libcfs_nid2str(id.nid) :
585 libcfs_id2str(id), strerror(errno));
586 rc = LUSTRE_CFG_RC_BAD_PARAM;
587 cYAML_build_error(rc, seq_no, MANAGE_CMD,
588 oper, err_str, err_rc);
592 if (cYAML_create_string(item, "primary nid",
593 libcfs_nid2str(ping.ping_id.nid)) == NULL)
596 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
597 "True" : "False") == NULL)
600 tmp = cYAML_create_seq(item, "peer ni");
604 for (i = 0; i < ping.ping_count; i++) {
605 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
608 peer_ni = cYAML_create_seq_item(tmp);
611 memset(buf, 0, sizeof buf);
612 snprintf(buf, sizeof buf, "nid");
613 if (cYAML_create_string(peer_ni, buf,
614 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
620 } while ((token = strtok(NULL, ",")) != NULL);
623 rc = LUSTRE_CFG_RC_NO_ERR;
628 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
629 cYAML_free_tree(root);
630 } else if (show_rc != NULL && *show_rc != NULL) {
631 struct cYAML *show_node;
632 show_node = cYAML_get_object_item(*show_rc, oper);
633 if (show_node != NULL && cYAML_is_sequence(show_node)) {
634 cYAML_insert_child(show_node, first_seq);
637 } else if (show_node == NULL) {
638 cYAML_insert_sibling((*show_rc)->cy_child,
642 cYAML_free_tree(root);
651 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
652 struct cYAML **show_rc, struct cYAML **err_rc)
656 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
657 seq_no, show_rc, err_rc);
661 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
662 struct cYAML **show_rc, struct cYAML **err_rc)
666 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
667 seq_no, show_rc, err_rc);
671 static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
673 struct lustre_lnet_ip_range_descr *ipr, *tmp;
674 struct cfs_expr_list *el, *el_tmp;
676 list_for_each_entry_safe(ipr, tmp,
677 &ip2nets->ip2nets_ip_ranges,
679 list_del(&ipr->ipr_entry);
680 list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
682 list_del(&el->el_link);
683 cfs_expr_list_free(el);
690 * returns an rc < 0 if there is an error
691 * otherwise it returns the number IPs generated
692 * it also has out params: net - network name
694 static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
695 struct lustre_lnet_ip2nets *ip2nets,
696 __u32 *net, char *err_str)
698 struct lustre_lnet_ip_range_descr *ipr;
700 int ip_idx = MAX_NUM_IPS - 1;
701 int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
703 char ip_range[LNET_MAX_STR_LEN];
705 /* separate the two components of the NID */
707 comp2 = strchr(nidstr, '@');
711 "\"cannot parse NID %s\"", nidstr);
712 err_str[LNET_MAX_STR_LEN - 1] = '\0';
713 rc = LUSTRE_CFG_RC_BAD_PARAM;
717 /* length of the expected ip-range */
718 ip_range_len = comp2 - comp1;
719 if (ip_range_len >= LNET_MAX_STR_LEN) {
722 "\"too long ip_range '%s'\"", nidstr);
723 err_str[LNET_MAX_STR_LEN - 1] = '\0';
724 rc = LUSTRE_CFG_RC_BAD_PARAM;
728 /* move beyond '@' */
732 * if the net component is either o2ib or tcp then we expect
733 * an IP range which could only be a single IP address.
736 *net = libcfs_str2net(comp2);
737 net_type = LNET_NETTYP(*net);
738 /* expression support is for o2iblnd and socklnd only */
739 if (net_type != O2IBLND && net_type != SOCKLND)
740 return LUSTRE_CFG_RC_SKIP;
742 strncpy(ip_range, comp1, ip_range_len);
743 ip_range[ip_range_len] = '\0';
744 ip2nets->ip2nets_net.nw_id = *net;
746 rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
747 if (rc != LUSTRE_CFG_RC_NO_ERR) {
750 "\"cannot parse ip_range '%.100s'\"", ip_range);
751 err_str[LNET_MAX_STR_LEN - 1] = '\0';
752 rc = LUSTRE_CFG_RC_BAD_PARAM;
757 * Generate all the IP Addresses from the parsed range. For sanity
758 * we allow only a max of MAX_NUM_IPS nids to be configured for
761 list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
762 ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
765 if (ip_idx == MAX_NUM_IPS - 1) {
766 snprintf(err_str, LNET_MAX_STR_LEN,
767 "no NIDs provided for configuration");
768 err_str[LNET_MAX_STR_LEN - 1] = '\0';
769 rc = LUSTRE_CFG_RC_NO_MATCH;
771 } else if (ip_idx == -1) {
772 rc = LUSTRE_CFG_RC_LAST_ELEM;
781 static int lustre_lnet_handle_peer_ip2nets(char **nid, int num_nids, bool mr,
782 bool range, __u32 cmd,
783 char *cmd_type, char *err_str)
785 __u32 net = LNET_NIDNET(LNET_NID_ANY);
787 int i, j, rc = LUSTRE_CFG_RC_NO_ERR;
788 __u32 ip_list[MAX_NUM_IPS];
789 struct lustre_lnet_ip2nets ip2nets;
790 struct lnet_ioctl_peer_cfg data;
792 lnet_nid_t prim_nid = LNET_NID_ANY;
794 /* initialize all lists */
795 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
796 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
797 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
799 /* each nid entry is an expression */
800 for (i = 0; i < num_nids; i++) {
801 if (!range && i == 0)
802 prim_nid = libcfs_str2nid(nid[0]);
804 prim_nid = LNET_NID_ANY;
806 rc = lnet_expr2ips(nid[i], ip_list, &ip2nets, &net, err_str);
807 if (rc == LUSTRE_CFG_RC_SKIP)
809 else if (rc == LUSTRE_CFG_RC_LAST_ELEM)
811 else if (rc < LUSTRE_CFG_RC_NO_ERR)
816 for (j = MAX_NUM_IPS - 1; j > ip_idx; j--) {
817 peer_nid = LNET_MKNID(net, ip_list[j]);
818 if (peer_nid == LNET_NID_ANY) {
821 "\"cannot parse NID\"");
822 err_str[LNET_MAX_STR_LEN - 1] = '\0';
823 rc = LUSTRE_CFG_RC_BAD_PARAM;
827 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
830 if (prim_nid == LNET_NID_ANY && j == MAX_NUM_IPS - 1) {
832 peer_nid = LNET_NID_ANY;
835 if (!range && num_nids > 1 && i == 0 &&
836 cmd == IOC_LIBCFS_DEL_PEER_NI)
838 else if (!range && i == 0)
839 peer_nid = LNET_NID_ANY;
842 * If prim_nid is not provided then the first nid in the
843 * list becomes the prim_nid. First time round the loop
844 * use LNET_NID_ANY for the first parameter, then use
845 * nid[0] as the key nid after wards
847 rc = dispatch_peer_ni_cmd(prim_nid, peer_nid, cmd,
848 &data, err_str, cmd_type);
853 * we just deleted the entire peer using the
854 * primary_nid. So don't bother iterating through
855 * the rest of the nids
857 if (prim_nid != LNET_NID_ANY &&
858 peer_nid == LNET_NID_ANY &&
859 cmd == IOC_LIBCFS_DEL_PEER_NI)
863 lustre_lnet_clean_ip2nets(&ip2nets);
867 lustre_lnet_clean_ip2nets(&ip2nets);
871 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
872 bool mr, bool ip2nets, int seq_no,
873 struct cYAML **err_rc)
875 int rc = LUSTRE_CFG_RC_NO_ERR;
876 char err_str[LNET_MAX_STR_LEN] = {0};
877 char **nid_array = NULL;
879 snprintf(err_str, sizeof(err_str), "\"Success\"");
882 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, mr,
883 ip2nets, IOC_LIBCFS_ADD_PEER_NI,
889 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
890 snprintf(err_str, sizeof(err_str),
891 "bad primary NID: '%s'",
893 rc = LUSTRE_CFG_RC_MISSING_PARAM;
899 nid_array = calloc(sizeof(*nid_array), num_nids);
901 snprintf(err_str, sizeof(err_str),
903 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
907 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
910 rc = lustre_lnet_handle_peer_ip2nets((pnid) ? nid_array : nid,
911 num_nids, mr, ip2nets,
912 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
921 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
925 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
926 bool ip2nets, int seq_no, struct cYAML **err_rc)
928 int rc = LUSTRE_CFG_RC_NO_ERR;
929 char err_str[LNET_MAX_STR_LEN] = {0};
930 char **nid_array = NULL;
932 snprintf(err_str, sizeof(err_str), "\"Success\"");
935 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, false,
936 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
942 snprintf(err_str, sizeof(err_str),
943 "\"Primary nid is not provided\"");
944 rc = LUSTRE_CFG_RC_MISSING_PARAM;
946 } else if (!ip2nets) {
947 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
948 rc = LUSTRE_CFG_RC_BAD_PARAM;
949 snprintf(err_str, sizeof(err_str),
957 nid_array = calloc(sizeof(*nid_array), num_nids);
959 snprintf(err_str, sizeof(err_str),
961 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
965 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
967 rc = lustre_lnet_handle_peer_ip2nets(nid_array, num_nids, false,
968 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
977 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
981 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
982 int sen, int seq_no, struct cYAML **err_rc)
984 struct lnet_ioctl_config_data data;
985 lnet_nid_t gateway_nid;
986 int rc = LUSTRE_CFG_RC_NO_ERR;
988 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
989 __u32 net = LNET_NIDNET(LNET_NID_ANY);
990 char err_str[LNET_MAX_STR_LEN];
991 __u32 ip_list[MAX_NUM_IPS];
992 struct lustre_lnet_ip2nets ip2nets;
994 /* initialize all lists */
995 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
996 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
997 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
999 snprintf(err_str, sizeof(err_str), "\"Success\"");
1001 if (nw == NULL || gw == NULL) {
1004 "\"missing mandatory parameter in route config:'%s'\"",
1005 (nw == NULL && gw == NULL) ? "network, gateway" :
1006 (nw == NULL) ? "network" : "gateway");
1007 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1011 rnet = libcfs_str2net(nw);
1012 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1015 "\"cannot parse remote net %s\"", nw);
1016 rc = LUSTRE_CFG_RC_BAD_PARAM;
1021 /* hops is undefined */
1022 hops = LNET_UNDEFINED_HOPS;
1023 } else if (hops < 1 || hops > 255) {
1026 "\"invalid hop count %d, must be between 1 and 255\"",
1028 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1034 } else if (prio < 0) {
1037 "\"invalid priority %d, must be greater than 0\"",
1039 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1045 } else if (sen < 1) {
1048 "\"invalid health sensitivity %d, must be 1 or greater\"",
1050 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1054 rc = lnet_expr2ips(gw, ip_list,
1055 &ip2nets, &net, err_str);
1056 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1058 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1063 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1064 data.cfg_net = rnet;
1065 data.cfg_config_u.cfg_route.rtr_hop = hops;
1066 data.cfg_config_u.cfg_route.rtr_priority = prio;
1067 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
1069 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1070 gateway_nid = LNET_MKNID(net, ip_list[i]);
1071 if (gateway_nid == LNET_NID_ANY) {
1074 "\"cannot form gateway NID: %u\"",
1076 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1077 rc = LUSTRE_CFG_RC_BAD_PARAM;
1080 data.cfg_nid = gateway_nid;
1082 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1083 if (rc != 0 && errno != EEXIST && errno != EHOSTUNREACH) {
1087 "\"cannot add route: %s\"", strerror(errno));
1092 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1097 int lustre_lnet_del_route(char *nw, char *gw,
1098 int seq_no, struct cYAML **err_rc)
1100 struct lnet_ioctl_config_data data;
1101 lnet_nid_t gateway_nid;
1102 int rc = LUSTRE_CFG_RC_NO_ERR;
1103 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1104 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1105 char err_str[LNET_MAX_STR_LEN];
1107 __u32 ip_list[MAX_NUM_IPS];
1108 struct lustre_lnet_ip2nets ip2nets;
1110 /* initialize all lists */
1111 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1112 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1113 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1115 snprintf(err_str, sizeof(err_str), "\"Success\"");
1117 if (nw == NULL || gw == NULL) {
1120 "\"missing mandatory parameter in route delete: '%s'\"",
1121 (nw == NULL && gw == NULL) ? "network, gateway" :
1122 (nw == NULL) ? "network" : "gateway");
1123 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1127 rnet = libcfs_str2net(nw);
1128 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1131 "\"cannot parse remote net '%s'\"", nw);
1132 rc = LUSTRE_CFG_RC_BAD_PARAM;
1136 rc = lnet_expr2ips(gw, ip_list,
1137 &ip2nets, &net, err_str);
1138 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1140 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1145 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1146 data.cfg_net = rnet;
1148 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1149 gateway_nid = LNET_MKNID(net, ip_list[i]);
1150 if (gateway_nid == LNET_NID_ANY) {
1153 "\"cannot form gateway NID: %u\"",
1155 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1156 rc = LUSTRE_CFG_RC_BAD_PARAM;
1159 data.cfg_nid = gateway_nid;
1161 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1166 "\"cannot delete route: %s\"", strerror(errno));
1171 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1176 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1177 int seq_no, struct cYAML **show_rc,
1178 struct cYAML **err_rc, bool backup)
1180 struct lnet_ioctl_config_data data;
1181 lnet_nid_t gateway_nid;
1182 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1184 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1186 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1187 struct cYAML *first_seq = NULL;
1188 char err_str[LNET_MAX_STR_LEN];
1191 snprintf(err_str, sizeof(err_str),
1192 "\"out of memory\"");
1195 net = libcfs_str2net(nw);
1196 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1199 "\"cannot parse net '%s'\"", nw);
1200 rc = LUSTRE_CFG_RC_BAD_PARAM;
1205 /* show all routes without filtering on net */
1206 net = LNET_NIDNET(LNET_NID_ANY);
1210 gateway_nid = libcfs_str2nid(gw);
1211 if (gateway_nid == LNET_NID_ANY) {
1214 "\"cannot parse gateway NID '%s'\"", gw);
1215 rc = LUSTRE_CFG_RC_BAD_PARAM;
1219 /* show all routes with out filtering on gateway */
1220 gateway_nid = LNET_NID_ANY;
1222 if ((hops < 1 && hops != -1) || hops > 255) {
1225 "\"invalid hop count %d, must be between 0 and 256\"",
1227 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1231 /* create struct cYAML root object */
1232 root = cYAML_create_object(NULL, NULL);
1236 route = cYAML_create_seq(root, "route");
1241 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1244 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1250 /* filter on provided data */
1251 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1252 net != data.cfg_net)
1255 if (gateway_nid != LNET_NID_ANY &&
1256 gateway_nid != data.cfg_nid)
1260 hops != data.cfg_config_u.cfg_route.rtr_hop)
1264 prio != data.cfg_config_u.cfg_route.rtr_priority)
1267 /* default rc to -1 incase we hit the goto */
1271 item = cYAML_create_seq_item(route);
1275 if (first_seq == NULL)
1278 if (cYAML_create_string(item, "net",
1279 libcfs_net2str(data.cfg_net)) == NULL)
1282 if (cYAML_create_string(item, "gateway",
1283 libcfs_nid2str(data.cfg_nid)) == NULL)
1287 if (cYAML_create_number(item, "hop",
1288 (int) data.cfg_config_u.
1289 cfg_route.rtr_hop) ==
1293 if (cYAML_create_number(item, "priority",
1295 cfg_route.rtr_priority) == NULL)
1298 if (cYAML_create_number(item, "health_sensitivity",
1300 cfg_route.rtr_sensitivity) == NULL)
1304 cYAML_create_string(item, "state",
1305 data.cfg_config_u.cfg_route.
1307 "up" : "down") == NULL)
1312 /* print output iff show_rc is not provided */
1313 if (show_rc == NULL)
1314 cYAML_print_tree(root);
1316 if (l_errno != ENOENT) {
1319 "\"cannot get routes: %s\"",
1324 rc = LUSTRE_CFG_RC_NO_ERR;
1326 snprintf(err_str, sizeof(err_str), "\"success\"");
1328 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1329 cYAML_free_tree(root);
1330 } else if (show_rc != NULL && *show_rc != NULL) {
1331 struct cYAML *show_node;
1332 /* find the route node, if one doesn't exist then
1333 * insert one. Otherwise add to the one there
1335 show_node = cYAML_get_object_item(*show_rc, "route");
1336 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1337 cYAML_insert_child(show_node, first_seq);
1340 } else if (show_node == NULL) {
1341 cYAML_insert_sibling((*show_rc)->cy_child,
1345 cYAML_free_tree(root);
1351 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1356 static int socket_intf_query(int request, char *intf,
1362 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1363 return LUSTRE_CFG_RC_BAD_PARAM;
1365 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1367 return LUSTRE_CFG_RC_BAD_PARAM;
1369 strcpy(ifr->ifr_name, intf);
1370 rc = ioctl(sockfd, request, ifr);
1372 rc = LUSTRE_CFG_RC_BAD_PARAM;
1379 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1384 memset(&ifr, 0, sizeof(ifr));
1385 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1387 return LUSTRE_CFG_RC_BAD_PARAM;
1389 if ((ifr.ifr_flags & IFF_UP) == 0)
1390 return LUSTRE_CFG_RC_BAD_PARAM;
1392 memset(&ifr, 0, sizeof(ifr));
1393 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1395 return LUSTRE_CFG_RC_BAD_PARAM;
1397 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1398 *ip = bswap_32(*ip);
1400 return LUSTRE_CFG_RC_NO_ERR;
1404 * for each interface in the array of interfaces find the IP address of
1405 * that interface, create its nid and add it to an array of NIDs.
1406 * Stop if any of the interfaces is down
1408 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1409 lnet_nid_t **nids, __u32 *nnids,
1410 char *err_str, size_t str_len)
1412 int i = 0, count = 0, rc;
1413 struct lnet_dlc_intf_descr *intf;
1414 char val[LNET_MAX_STR_LEN];
1421 if (nw == NULL || nids == NULL) {
1422 snprintf(err_str, str_len,
1423 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1424 err_str[str_len - 1] = '\0';
1425 return LUSTRE_CFG_RC_BAD_PARAM;
1428 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1431 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1435 *nids = calloc(count, sizeof(lnet_nid_t));
1436 if (*nids == NULL) {
1437 snprintf(err_str, str_len,
1438 "\"out of memory\"");
1439 err_str[str_len - 1] = '\0';
1440 return LUSTRE_CFG_RC_OUT_OF_MEM;
1443 * special case the GNI interface since it doesn't have an IP
1444 * address. The assumption is that there can only be one GNI
1445 * interface in the system. No interface name is provided.
1447 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1448 rc = read_sysfs_file(gni_nid_path, "nid", val,
1451 snprintf(err_str, str_len,
1452 "\"cannot read gni nid\"");
1453 err_str[str_len - 1] = '\0';
1456 gni_num = atoi(val);
1458 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1463 /* look at the other interfaces */
1464 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1465 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1466 /* handle LNDs with numeric interface name */
1467 num = strtoul(intf->intf_name, &endp, 0);
1468 if (endp == intf->intf_name || *endp != '\0') {
1469 rc = LUSTRE_CFG_RC_BAD_PARAM;
1470 snprintf(err_str, str_len,
1471 "\"couldn't query intf %s\"",
1473 err_str[str_len - 1] = '\0';
1476 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1479 /* handle LNDs with ip interface name */
1480 rc = lustre_lnet_queryip(intf, &ip);
1481 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1482 snprintf(err_str, str_len,
1483 "\"couldn't query intf %s\"",
1485 err_str[str_len - 1] = '\0';
1488 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1505 * called repeatedly until a match or no more ip range
1507 * ip_range expression
1508 * interface list with all the interface names.
1509 * all the interfaces in the system.
1511 * try to match the ip_range expr to one of the interfaces' IPs in
1512 * the system. If we hit a patch for an interface. Check if that
1513 * interface name is in the list.
1515 * If there are more than one interface in the list, then make sure
1516 * that the IPs for all of these interfaces match the ip ranges
1519 * for each interface in intf_list
1520 * look up the intf name in ifa
1521 * if not there then no match
1522 * check ip obtained from ifa against a match to any of the
1524 * If no match, then fail
1526 * The result is that all the interfaces have to match.
1528 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1529 struct list_head *intf_list,
1530 struct list_head *ip_ranges)
1534 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1535 struct ifaddrs *ifaddr = ifa;
1536 struct lustre_lnet_ip_range_descr *ip_range;
1540 * if there are no explicit interfaces, and no ip ranges, then
1541 * configure the first tcp interface we encounter.
1543 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1544 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1545 if (ifaddr->ifa_addr == NULL)
1548 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1551 family = ifaddr->ifa_addr->sa_family;
1552 if (family == AF_INET &&
1553 strcmp(ifaddr->ifa_name, "lo") != 0) {
1554 rc = lustre_lnet_add_intf_descr
1555 (intf_list, ifaddr->ifa_name,
1556 strlen(ifaddr->ifa_name));
1558 if (rc != LUSTRE_CFG_RC_NO_ERR)
1561 return LUSTRE_CFG_RC_MATCH;
1564 return LUSTRE_CFG_RC_NO_MATCH;
1568 * First interface which matches an IP pattern will be used
1570 if (list_empty(intf_list)) {
1572 * no interfaces provided in the rule, but an ip range is
1573 * provided, so try and match an interface to the ip
1576 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1577 if (ifaddr->ifa_addr == NULL)
1580 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1583 family = ifaddr->ifa_addr->sa_family;
1584 if (family == AF_INET) {
1585 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1588 list_for_each_entry(ip_range, ip_ranges,
1590 rc = cfs_ip_addr_match(bswap_32(ip),
1591 &ip_range->ipr_expr);
1595 rc = lustre_lnet_add_intf_descr
1596 (intf_list, ifaddr->ifa_name,
1597 strlen(ifaddr->ifa_name));
1599 if (rc != LUSTRE_CFG_RC_NO_ERR)
1605 if (!list_empty(intf_list))
1606 return LUSTRE_CFG_RC_MATCH;
1608 return LUSTRE_CFG_RC_NO_MATCH;
1612 * If an interface is explicitly specified the ip-range might or
1613 * might not be specified. if specified the interface needs to match the
1614 * ip-range. If no ip-range then the interfaces are
1615 * automatically matched if they are all up.
1616 * If > 1 interfaces all the interfaces must match for the NI to
1619 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1620 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1621 if (ifaddr->ifa_addr == NULL)
1624 family = ifaddr->ifa_addr->sa_family;
1625 if (family == AF_INET &&
1626 strcmp(intf_descr->intf_name,
1627 ifaddr->ifa_name) == 0)
1631 if (ifaddr == NULL) {
1632 list_del(&intf_descr->intf_on_network);
1633 free_intf_descr(intf_descr);
1637 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1638 list_del(&intf_descr->intf_on_network);
1639 free_intf_descr(intf_descr);
1643 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1646 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1647 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1653 /* no match for this interface */
1654 list_del(&intf_descr->intf_on_network);
1655 free_intf_descr(intf_descr);
1659 return LUSTRE_CFG_RC_MATCH;
1662 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1663 lnet_nid_t **nids, __u32 *nnids,
1664 char *err_str, size_t str_len)
1666 struct ifaddrs *ifa;
1667 int rc = LUSTRE_CFG_RC_NO_ERR;
1669 rc = getifaddrs(&ifa);
1671 snprintf(err_str, str_len,
1672 "\"failed to get interface addresses: %d\"", -errno);
1673 err_str[str_len - 1] = '\0';
1677 rc = lustre_lnet_match_ip_to_intf(ifa,
1678 &ip2nets->ip2nets_net.nw_intflist,
1679 &ip2nets->ip2nets_ip_ranges);
1680 if (rc != LUSTRE_CFG_RC_MATCH) {
1681 snprintf(err_str, str_len,
1682 "\"couldn't match ip to existing interfaces\"");
1683 err_str[str_len - 1] = '\0';
1688 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1689 err_str, sizeof(err_str));
1690 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1701 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1702 struct lnet_ioctl_config_lnd_tunables *tunables,
1703 struct cfs_expr_list *global_cpts,
1704 lnet_nid_t *nids, char *err_str)
1707 struct lnet_ioctl_config_ni *conf;
1708 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1709 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1712 struct lnet_dlc_intf_descr *intf_descr;
1714 struct cfs_expr_list *cpt_expr;
1716 list_for_each_entry(intf_descr, intf_list,
1718 if (tunables != NULL)
1719 len = sizeof(struct lnet_ioctl_config_ni) +
1720 sizeof(struct lnet_ioctl_config_lnd_tunables);
1722 len = sizeof(struct lnet_ioctl_config_ni);
1724 data = calloc(1, len);
1726 return LUSTRE_CFG_RC_OUT_OF_MEM;
1727 conf = (struct lnet_ioctl_config_ni*) data;
1728 if (tunables != NULL)
1729 tun = (struct lnet_ioctl_config_lnd_tunables*)
1732 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1733 conf->lic_cfg_hdr.ioc_len = len;
1734 conf->lic_nid = nids[i];
1735 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1738 if (intf_descr->cpt_expr != NULL)
1739 cpt_expr = intf_descr->cpt_expr;
1740 else if (global_cpts != NULL)
1741 cpt_expr = global_cpts;
1745 if (cpt_expr != NULL) {
1746 count = cfs_expr_list_values(cpt_expr,
1747 LNET_MAX_SHOW_NUM_CPT,
1750 memcpy(conf->lic_cpts, cpt_array,
1751 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1760 conf->lic_ncpts = count;
1762 if (tunables != NULL)
1763 memcpy(tun, tunables, sizeof(*tunables));
1765 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1770 "\"cannot add network: %s\"", strerror(errno));
1778 return LUSTRE_CFG_RC_NO_ERR;
1782 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1783 struct lnet_ioctl_config_lnd_tunables *tunables,
1784 struct cfs_expr_list *global_cpts,
1785 int seq_no, struct cYAML **err_rc)
1787 lnet_nid_t *nids = NULL;
1790 char err_str[LNET_MAX_STR_LEN];
1792 snprintf(err_str, sizeof(err_str), "\"success\"");
1797 "\"incomplete ip2nets information\"");
1798 rc = LUSTRE_CFG_RC_BAD_PARAM;
1803 * call below function to resolve the rules into a list of nids.
1804 * The memory is allocated in that function then freed here when
1805 * it's no longer needed.
1807 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1809 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1812 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1813 snprintf(err_str, sizeof(err_str),
1814 "\"no interfaces match ip2nets rules\"");
1818 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1819 tunables, global_cpts, nids,
1826 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1830 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1831 struct cfs_expr_list *global_cpts,
1833 struct lnet_ioctl_config_lnd_tunables *tunables,
1834 int seq_no, struct cYAML **err_rc)
1837 struct lnet_ioctl_config_ni *conf;
1838 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1839 char buf[LNET_MAX_STR_LEN];
1840 int rc = LUSTRE_CFG_RC_NO_ERR;
1841 char err_str[LNET_MAX_STR_LEN];
1842 lnet_nid_t *nids = NULL;
1846 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1849 snprintf(err_str, sizeof(err_str), "\"success\"");
1851 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1852 (list_empty(&nw_descr->nw_intflist) &&
1853 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1856 "\"missing mandatory parameters in NI config: '%s'\"",
1857 (nw_descr == NULL) ? "network , interface" :
1858 (nw_descr->nw_id == 0) ? "network" : "interface");
1859 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1863 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1866 "\"ip2net string too long %d\"",
1867 (int)strlen(ip2net));
1868 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1872 if (ip2net != NULL) {
1873 if (tunables != NULL)
1874 len = sizeof(struct lnet_ioctl_config_ni) +
1875 sizeof(struct lnet_ioctl_config_lnd_tunables);
1877 len = sizeof(struct lnet_ioctl_config_ni);
1878 data = calloc(1, len);
1880 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1883 conf = (struct lnet_ioctl_config_ni*) data;
1884 if (tunables != NULL)
1885 tun = (struct lnet_ioctl_config_lnd_tunables*)
1886 (data + sizeof(*conf));
1888 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1889 conf->lic_cfg_hdr.ioc_len = len;
1890 strncpy(conf->lic_legacy_ip2nets, ip2net,
1893 if (global_cpts != NULL) {
1894 count = cfs_expr_list_values(global_cpts,
1895 LNET_MAX_SHOW_NUM_CPT,
1898 memcpy(conf->lic_cpts, cpt_array,
1899 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1908 conf->lic_ncpts = count;
1910 if (tunables != NULL)
1911 memcpy(tun, tunables, sizeof(*tunables));
1913 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1918 "\"cannot add network: %s\"", strerror(errno));
1925 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1926 rc = LUSTRE_CFG_RC_NO_ERR;
1930 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1933 "\"cannot parse net '%s'\"",
1934 libcfs_net2str(nw_descr->nw_id));
1935 rc = LUSTRE_CFG_RC_BAD_PARAM;
1940 * special case the GNI since no interface name is expected
1942 if (list_empty(&nw_descr->nw_intflist) &&
1943 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1946 "\"no interface name provided\"");
1947 rc = LUSTRE_CFG_RC_BAD_PARAM;
1951 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1952 err_str, sizeof(err_str));
1954 rc = LUSTRE_CFG_RC_BAD_PARAM;
1958 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1959 tunables, global_cpts, nids,
1963 if (nw_descr != NULL) {
1964 list_for_each_entry_safe(intf_descr, tmp,
1965 &nw_descr->nw_intflist,
1967 list_del(&intf_descr->intf_on_network);
1968 free_intf_descr(intf_descr);
1972 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1983 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1984 int seq_no, struct cYAML **err_rc)
1986 struct lnet_ioctl_config_ni data;
1987 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1988 char err_str[LNET_MAX_STR_LEN];
1989 lnet_nid_t *nids = NULL;
1991 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1993 snprintf(err_str, sizeof(err_str), "\"success\"");
1995 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1998 "\"missing mandatory parameter in deleting NI: '%s'\"",
1999 (nw_descr == NULL) ? "network , interface" :
2000 (nw_descr->nw_id == 0) ? "network" : "interface");
2001 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2005 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2006 return LUSTRE_CFG_RC_NO_ERR;
2008 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2011 "\"cannot parse net '%s'\"",
2012 libcfs_net2str(nw_descr->nw_id));
2013 rc = LUSTRE_CFG_RC_BAD_PARAM;
2017 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2018 err_str, sizeof(err_str));
2020 rc = LUSTRE_CFG_RC_BAD_PARAM;
2025 * no interfaces just the nw_id is specified
2028 nids = calloc(1, sizeof(*nids));
2030 snprintf(err_str, sizeof(err_str),
2031 "\"out of memory\"");
2032 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2035 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2039 for (i = 0; i < nnids; i++) {
2040 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2041 data.lic_nid = nids[i];
2043 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2048 "\"cannot del network: %s\"", strerror(errno));
2052 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2054 list_del(&intf_descr->intf_on_network);
2055 free_intf_descr(intf_descr);
2059 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2068 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2069 enum lnet_health_type type, char *name,
2070 int seq_no, struct cYAML **err_rc)
2072 struct lnet_ioctl_reset_health_cfg data;
2073 int rc = LUSTRE_CFG_RC_NO_ERR;
2074 char err_str[LNET_MAX_STR_LEN];
2076 snprintf(err_str, sizeof(err_str), "\"success\"");
2078 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2079 data.rh_type = type;
2081 data.rh_value = value;
2084 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2088 sizeof(err_str), "Can not configure health value: %s",
2092 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2097 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2098 struct cYAML **err_rc)
2102 nid = libcfs_str2nid(ni_nid);
2105 return lustre_lnet_config_healthv(value, all, nid,
2106 LNET_HEALTH_TYPE_LOCAL_NI,
2107 "ni healthv", seq_no, err_rc);
2110 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2111 int seq_no, struct cYAML **err_rc)
2115 nid = libcfs_str2nid(lpni_nid);
2118 return lustre_lnet_config_healthv(value, all, nid,
2119 LNET_HEALTH_TYPE_PEER_NI,
2120 "peer_ni healthv", seq_no, err_rc);
2124 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2125 struct lnet_ioctl_comm_count *counts)
2127 if (cYAML_create_number(yaml, "put",
2128 counts->ico_put_count)
2131 if (cYAML_create_number(yaml, "get",
2132 counts->ico_get_count)
2135 if (cYAML_create_number(yaml, "reply",
2136 counts->ico_reply_count)
2139 if (cYAML_create_number(yaml, "ack",
2140 counts->ico_ack_count)
2143 if (cYAML_create_number(yaml, "hello",
2144 counts->ico_hello_count)
2151 static struct lnet_ioctl_comm_count *
2152 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2155 return &msg_stats->im_send_stats;
2157 return &msg_stats->im_recv_stats;
2159 return &msg_stats->im_drop_stats;
2164 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2165 struct cYAML **show_rc, struct cYAML **err_rc,
2169 struct lnet_ioctl_config_ni *ni_data;
2170 struct lnet_ioctl_config_lnd_tunables *lnd;
2171 struct lnet_ioctl_element_stats *stats;
2172 struct lnet_ioctl_element_msg_stats msg_stats;
2173 struct lnet_ioctl_local_ni_hstats hstats;
2174 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2175 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2176 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2178 struct cYAML *root = NULL, *tunables = NULL,
2179 *net_node = NULL, *interfaces = NULL,
2180 *item = NULL, *first_seq = NULL,
2181 *tmp = NULL, *statistics = NULL,
2183 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2184 char str_buf[str_buf_len];
2186 char err_str[LNET_MAX_STR_LEN];
2187 bool exist = false, new_net = true;
2189 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2191 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2193 buf = calloc(1, buf_size);
2197 ni_data = (struct lnet_ioctl_config_ni *)buf;
2200 net = libcfs_str2net(nw);
2201 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2204 "\"cannot parse net '%s'\"", nw);
2205 rc = LUSTRE_CFG_RC_BAD_PARAM;
2210 root = cYAML_create_object(NULL, NULL);
2214 net_node = cYAML_create_seq(root, "net");
2215 if (net_node == NULL)
2222 memset(buf, 0, buf_size);
2224 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2226 * set the ioc_len to the proper value since INIT assumes
2229 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2230 ni_data->lic_idx = i;
2232 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2238 rc_net = LNET_NIDNET(ni_data->lic_nid);
2240 /* filter on provided data */
2241 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2245 /* if we're backing up don't store lo */
2246 if (backup && LNET_NETTYP(rc_net) == LOLND)
2249 /* default rc to -1 in case we hit the goto */
2253 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2254 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2255 (ni_data->lic_bulk + sizeof(*stats));
2257 if (rc_net != prev_net) {
2264 if (!cYAML_create_string(net_node, "net type",
2265 libcfs_net2str(rc_net)))
2268 tmp = cYAML_create_seq(net_node, "local NI(s)");
2274 /* create the tree to be printed. */
2275 item = cYAML_create_seq_item(tmp);
2279 if (first_seq == NULL)
2283 cYAML_create_string(item, "nid",
2284 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2288 cYAML_create_string(item,
2290 (ni_data->lic_status ==
2291 LNET_NI_STATUS_UP) ?
2292 "up" : "down") == NULL)
2295 /* don't add interfaces unless there is at least one
2297 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2298 interfaces = cYAML_create_object(item, "interfaces");
2299 if (interfaces == NULL)
2302 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2303 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2305 sizeof(str_buf), "%d", j);
2306 if (cYAML_create_string(interfaces,
2308 ni_data->lic_ni_intf[j]) ==
2320 goto continue_without_msg_stats;
2322 statistics = cYAML_create_object(item, "statistics");
2323 if (statistics == NULL)
2326 if (cYAML_create_number(statistics, "send_count",
2327 stats->iel_send_count)
2331 if (cYAML_create_number(statistics, "recv_count",
2332 stats->iel_recv_count)
2336 if (cYAML_create_number(statistics, "drop_count",
2337 stats->iel_drop_count)
2342 goto continue_without_msg_stats;
2344 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2345 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2346 msg_stats.im_idx = i;
2348 rc = l_ioctl(LNET_DEV_ID,
2349 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2353 goto continue_without_msg_stats;
2356 for (k = 0; k < 3; k++) {
2357 struct lnet_ioctl_comm_count *counts;
2358 struct cYAML *msg_statistics = NULL;
2360 msg_statistics = cYAML_create_object(item,
2361 (char *)gmsg_stat_names[k]);
2362 if (msg_statistics == NULL)
2365 counts = get_counts(&msg_stats, k);
2369 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2374 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2375 hstats.hlni_nid = ni_data->lic_nid;
2376 /* grab health stats */
2377 rc = l_ioctl(LNET_DEV_ID,
2378 IOC_LIBCFS_GET_LOCAL_HSTATS,
2382 goto continue_without_msg_stats;
2384 yhstats = cYAML_create_object(item, "health stats");
2387 if (cYAML_create_number(yhstats, "health value",
2388 hstats.hlni_health_value)
2391 if (cYAML_create_number(yhstats, "interrupts",
2392 hstats.hlni_local_interrupt)
2395 if (cYAML_create_number(yhstats, "dropped",
2396 hstats.hlni_local_dropped)
2399 if (cYAML_create_number(yhstats, "aborted",
2400 hstats.hlni_local_aborted)
2403 if (cYAML_create_number(yhstats, "no route",
2404 hstats.hlni_local_no_route)
2407 if (cYAML_create_number(yhstats, "timeouts",
2408 hstats.hlni_local_timeout)
2411 if (cYAML_create_number(yhstats, "error",
2412 hstats.hlni_local_error)
2416 continue_without_msg_stats:
2417 tunables = cYAML_create_object(item, "tunables");
2421 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2422 if (rc != LUSTRE_CFG_RC_NO_ERR)
2425 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2427 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2428 rc != LUSTRE_CFG_RC_NO_MATCH)
2431 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2432 tunables = cYAML_create_object(item,
2434 if (tunables == NULL)
2439 cYAML_create_number(item, "dev cpt",
2440 ni_data->lic_dev_cpt) == NULL)
2444 cYAML_create_number(item, "tcp bonding",
2445 ni_data->lic_tcp_bonding)
2449 /* out put the CPTs in the format: "[x,x,x,...]" */
2450 limit = str_buf + str_buf_len - 3;
2451 pos += snprintf(pos, limit - pos, "\"[");
2452 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2453 j < ni_data->lic_ncpts &&
2455 pos += snprintf(pos, limit - pos,
2456 "%d", ni_data->lic_cpts[j]);
2457 if ((j + 1) < ni_data->lic_ncpts)
2458 pos += snprintf(pos, limit - pos, ",");
2460 pos += snprintf(pos, 3, "]\"");
2462 if (ni_data->lic_ncpts >= 1 &&
2463 cYAML_create_string(item, "CPT",
2469 /* Print out the net information only if show_rc is not provided */
2470 if (show_rc == NULL)
2471 cYAML_print_tree(root);
2473 if (l_errno != ENOENT) {
2476 "\"cannot get networks: %s\"",
2481 rc = LUSTRE_CFG_RC_NO_ERR;
2483 snprintf(err_str, sizeof(err_str), "\"success\"");
2485 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2486 cYAML_free_tree(root);
2487 } else if (show_rc != NULL && *show_rc != NULL) {
2488 struct cYAML *show_node;
2489 /* find the net node, if one doesn't exist
2490 * then insert one. Otherwise add to the one there
2492 show_node = cYAML_get_object_item(*show_rc, "net");
2493 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2494 cYAML_insert_child(show_node, first_seq);
2497 } else if (show_node == NULL) {
2498 cYAML_insert_sibling((*show_rc)->cy_child,
2502 cYAML_free_tree(root);
2508 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2513 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2515 struct lnet_ioctl_config_data data;
2516 int rc = LUSTRE_CFG_RC_NO_ERR;
2517 char err_str[LNET_MAX_STR_LEN];
2519 snprintf(err_str, sizeof(err_str), "\"success\"");
2521 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2522 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2524 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2529 "\"cannot %s routing %s\"",
2530 (enable) ? "enable" : "disable", strerror(errno));
2535 cYAML_build_error(rc, seq_no,
2536 (enable) ? ADD_CMD : DEL_CMD,
2537 "routing", err_str, err_rc);
2542 int ioctl_set_value(__u32 val, int ioc, char *name,
2543 int seq_no, struct cYAML **err_rc)
2545 struct lnet_ioctl_set_value data;
2546 int rc = LUSTRE_CFG_RC_NO_ERR;
2547 char err_str[LNET_MAX_STR_LEN];
2549 snprintf(err_str, sizeof(err_str), "\"success\"");
2551 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2552 data.sv_value = val;
2554 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2559 "\"cannot configure %s to %d: %s\"", name,
2560 val, strerror(errno));
2563 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2568 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2570 int rc = LUSTRE_CFG_RC_NO_ERR;
2571 char err_str[LNET_MAX_STR_LEN];
2572 char val[LNET_MAX_STR_LEN];
2574 snprintf(err_str, sizeof(err_str), "\"success\"");
2576 snprintf(val, sizeof(val), "%d", intrv);
2578 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2579 1, strlen(val) + 1);
2581 snprintf(err_str, sizeof(err_str),
2582 "\"cannot configure recovery interval: %s\"",
2585 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2590 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2592 int rc = LUSTRE_CFG_RC_NO_ERR;
2593 char err_str[LNET_MAX_STR_LEN];
2594 char val[LNET_MAX_STR_LEN];
2596 snprintf(err_str, sizeof(err_str), "\"success\"");
2598 snprintf(val, sizeof(val), "%d", sen);
2600 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2601 1, strlen(val) + 1);
2603 snprintf(err_str, sizeof(err_str),
2604 "\"cannot configure router health sensitivity: %s\"",
2607 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2612 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2614 int rc = LUSTRE_CFG_RC_NO_ERR;
2615 char err_str[LNET_MAX_STR_LEN];
2616 char val[LNET_MAX_STR_LEN];
2618 snprintf(err_str, sizeof(err_str), "\"success\"");
2620 snprintf(val, sizeof(val), "%d", sen);
2622 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2623 1, strlen(val) + 1);
2625 snprintf(err_str, sizeof(err_str),
2626 "\"cannot configure health sensitivity: %s\"",
2629 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2634 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2636 int rc = LUSTRE_CFG_RC_NO_ERR;
2637 char err_str[LNET_MAX_STR_LEN];
2638 char val[LNET_MAX_STR_LEN];
2640 snprintf(err_str, sizeof(err_str), "\"success\"");
2642 snprintf(val, sizeof(val), "%d", timeout);
2644 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2645 1, strlen(val) + 1);
2647 snprintf(err_str, sizeof(err_str),
2648 "\"cannot configure transaction timeout: %s\"",
2651 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2656 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2658 int rc = LUSTRE_CFG_RC_NO_ERR;
2659 char err_str[LNET_MAX_STR_LEN];
2660 char val[LNET_MAX_STR_LEN];
2662 snprintf(err_str, sizeof(err_str), "\"success\"");
2664 snprintf(val, sizeof(val), "%d", count);
2666 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2667 1, strlen(val) + 1);
2669 snprintf(err_str, sizeof(err_str),
2670 "\"cannot configure retry count: %s\"",
2673 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2678 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2680 int rc = LUSTRE_CFG_RC_NO_ERR;
2681 char err_str[LNET_MAX_STR_LEN];
2682 char val[LNET_MAX_STR_LEN];
2684 snprintf(err_str, sizeof(err_str), "\"success\"");
2686 snprintf(val, sizeof(val), "%d", max);
2688 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2689 1, strlen(val) + 1);
2691 snprintf(err_str, sizeof(err_str),
2692 "\"cannot configure max interfaces: %s\"",
2695 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2700 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2702 int rc = LUSTRE_CFG_RC_NO_ERR;
2703 char err_str[LNET_MAX_STR_LEN];
2704 char val[LNET_MAX_STR_LEN];
2706 snprintf(err_str, sizeof(err_str), "\"success\"");
2708 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2710 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2711 1, strlen(val) + 1);
2713 snprintf(err_str, sizeof(err_str),
2714 "\"cannot configure discovery: %s\"",
2717 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2723 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2724 struct cYAML **err_rc)
2726 int rc = LUSTRE_CFG_RC_NO_ERR;
2727 char err_str[LNET_MAX_STR_LEN];
2728 char val[LNET_MAX_STR_LEN];
2730 snprintf(err_str, sizeof(err_str), "\"success\"");
2732 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2734 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2735 1, strlen(val) + 1);
2737 snprintf(err_str, sizeof(err_str),
2738 "\"cannot configure drop asym route: %s\"",
2741 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2748 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2750 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2751 "numa_range", seq_no, err_rc);
2754 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2755 struct cYAML **err_rc)
2757 struct lnet_ioctl_config_data data;
2758 int rc = LUSTRE_CFG_RC_NO_ERR;
2759 char err_str[LNET_MAX_STR_LEN];
2761 snprintf(err_str, sizeof(err_str), "\"success\"");
2763 /* -1 indicates to ignore changes to this field */
2764 if (tiny < -1 || small < -1 || large < -1) {
2767 "\"tiny, small and large must be >= 0\"");
2768 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2772 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2773 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2774 data.cfg_config_u.cfg_buffers.buf_small = small;
2775 data.cfg_config_u.cfg_buffers.buf_large = large;
2777 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2782 "\"cannot configure buffers: %s\"", strerror(errno));
2787 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2792 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2793 struct cYAML **err_rc, bool backup)
2795 struct lnet_ioctl_config_data *data;
2796 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2797 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2800 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2801 int buf_count[LNET_NRBPOOLS] = {0};
2802 struct cYAML *root = NULL, *pools_node = NULL,
2803 *type_node = NULL, *item = NULL, *cpt = NULL,
2804 *first_seq = NULL, *buffers = NULL;
2806 char err_str[LNET_MAX_STR_LEN];
2807 char node_name[LNET_MAX_STR_LEN];
2810 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2812 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2816 data = (struct lnet_ioctl_config_data *)buf;
2818 root = cYAML_create_object(NULL, NULL);
2823 pools_node = cYAML_create_object(root, "routing");
2825 pools_node = cYAML_create_seq(root, "routing");
2826 if (pools_node == NULL)
2830 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2831 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2832 sizeof(struct lnet_ioctl_pool_cfg);
2833 data->cfg_count = i;
2835 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2843 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2846 goto calculate_buffers;
2848 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2849 item = cYAML_create_seq_item(pools_node);
2853 if (first_seq == NULL)
2856 cpt = cYAML_create_object(item, node_name);
2861 /* create the tree and print */
2862 for (j = 0; j < LNET_NRBPOOLS; j++) {
2864 type_node = cYAML_create_object(cpt, pools[j]);
2865 if (type_node == NULL)
2869 cYAML_create_number(type_node, "npages",
2870 pool_cfg->pl_pools[j].pl_npages)
2874 cYAML_create_number(type_node, "nbuffers",
2875 pool_cfg->pl_pools[j].
2876 pl_nbuffers) == NULL)
2879 cYAML_create_number(type_node, "credits",
2880 pool_cfg->pl_pools[j].
2881 pl_credits) == NULL)
2884 cYAML_create_number(type_node, "mincredits",
2885 pool_cfg->pl_pools[j].
2886 pl_mincredits) == NULL)
2888 /* keep track of the total count for each of the
2889 * tiny, small and large buffers */
2890 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2894 if (pool_cfg != NULL) {
2896 if (cYAML_create_number(pools_node, "enable",
2897 pool_cfg->pl_routing) ==
2901 goto add_buffer_section;
2904 item = cYAML_create_seq_item(pools_node);
2908 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2914 /* create a buffers entry in the show. This is necessary so that
2915 * if the YAML output is used to configure a node, the buffer
2916 * configuration takes hold */
2917 buffers = cYAML_create_object(root, "buffers");
2918 if (buffers == NULL)
2921 for (i = 0; i < LNET_NRBPOOLS; i++) {
2922 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2926 if (show_rc == NULL)
2927 cYAML_print_tree(root);
2929 if (l_errno != ENOENT) {
2932 "\"cannot get routing information: %s\"",
2937 rc = LUSTRE_CFG_RC_NO_ERR;
2939 snprintf(err_str, sizeof(err_str), "\"success\"");
2940 rc = LUSTRE_CFG_RC_NO_ERR;
2944 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2945 cYAML_free_tree(root);
2946 } else if (show_rc != NULL && *show_rc != NULL) {
2947 struct cYAML *routing_node;
2948 /* there should exist only one routing block and one
2949 * buffers block. If there already exists a previous one
2950 * then don't add another */
2951 routing_node = cYAML_get_object_item(*show_rc, "routing");
2952 if (routing_node == NULL) {
2953 cYAML_insert_sibling((*show_rc)->cy_child,
2957 cYAML_free_tree(root);
2963 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2968 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2969 struct cYAML **show_rc, struct cYAML **err_rc,
2973 * TODO: This function is changing in a future patch to accommodate
2974 * PEER_LIST and proper filtering on any nid of the peer
2976 struct lnet_ioctl_peer_cfg peer_info;
2977 struct lnet_peer_ni_credit_info *lpni_cri;
2978 struct lnet_ioctl_element_stats *lpni_stats;
2979 struct lnet_ioctl_element_msg_stats *msg_stats;
2980 struct lnet_ioctl_peer_ni_hstats *hstats;
2982 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2987 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2988 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2989 *msg_statistics = NULL, *statistics = NULL,
2991 char err_str[LNET_MAX_STR_LEN];
2992 struct lnet_process_id *list = NULL;
2997 snprintf(err_str, sizeof(err_str),
2998 "\"out of memory\"");
3000 /* create struct cYAML root object */
3001 root = cYAML_create_object(NULL, NULL);
3005 peer_root = cYAML_create_seq(root, "peer");
3006 if (peer_root == NULL)
3010 size = count * sizeof(struct lnet_process_id);
3011 list = malloc(size);
3017 list[0].nid = libcfs_str2nid(knid);
3021 memset(&peer_info, 0, sizeof(peer_info));
3022 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3023 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3024 peer_info.prcfg_size = size;
3025 peer_info.prcfg_bulk = list;
3028 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3030 count = peer_info.prcfg_count;
3034 if (l_errno != E2BIG) {
3037 "\"cannot get peer list: %s\"",
3043 size = peer_info.prcfg_size;
3044 list = malloc(size);
3053 data = malloc(size);
3059 for (i = 0; i < count; i++) {
3061 memset(&peer_info, 0, sizeof(peer_info));
3062 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3063 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3064 peer_info.prcfg_prim_nid = list[i].nid;
3065 peer_info.prcfg_size = size;
3066 peer_info.prcfg_bulk = data;
3069 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3074 if (l_errno != E2BIG) {
3077 "\"cannot get peer information: %s\"",
3083 size = peer_info.prcfg_size;
3084 data = malloc(size);
3092 peer = cYAML_create_seq_item(peer_root);
3096 if (first_seq == NULL)
3099 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3100 if (cYAML_create_string(peer, "primary nid",
3101 libcfs_nid2str(pnid))
3104 if (cYAML_create_string(peer, "Multi-Rail",
3105 peer_info.prcfg_mr ? "True" : "False")
3109 * print out the state of the peer only if details are
3114 cYAML_create_number(peer, "peer state",
3115 peer_info.prcfg_state)
3120 tmp = cYAML_create_seq(peer, "peer ni");
3125 for (j = 0; j < peer_info.prcfg_count; j++) {
3127 lpni_cri = (void*)nidp + sizeof(nidp);
3128 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3129 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3130 hstats = (void *)msg_stats + sizeof(*msg_stats);
3131 lpni_data = (void *)hstats + sizeof(*hstats);
3133 peer_ni = cYAML_create_seq_item(tmp);
3134 if (peer_ni == NULL)
3137 if (cYAML_create_string(peer_ni, "nid",
3138 libcfs_nid2str(*nidp))
3145 if (cYAML_create_string(peer_ni, "state",
3146 lpni_cri->cr_aliveness)
3153 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3154 lpni_cri->cr_ni_peer_tx_credits)
3158 if (cYAML_create_number(peer_ni, "available_tx_credits",
3159 lpni_cri->cr_peer_tx_credits)
3163 if (cYAML_create_number(peer_ni, "min_tx_credits",
3164 lpni_cri->cr_peer_min_tx_credits)
3168 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3169 lpni_cri->cr_peer_tx_qnob)
3173 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3174 lpni_cri->cr_peer_rtr_credits)
3178 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3179 lpni_cri->cr_peer_min_rtr_credits)
3183 if (cYAML_create_number(peer_ni, "refcount",
3184 lpni_cri->cr_refcount) == NULL)
3187 statistics = cYAML_create_object(peer_ni, "statistics");
3188 if (statistics == NULL)
3191 if (cYAML_create_number(statistics, "send_count",
3192 lpni_stats->iel_send_count)
3196 if (cYAML_create_number(statistics, "recv_count",
3197 lpni_stats->iel_recv_count)
3201 if (cYAML_create_number(statistics, "drop_count",
3202 lpni_stats->iel_drop_count)
3209 for (k = 0; k < 3; k++) {
3210 struct lnet_ioctl_comm_count *counts;
3212 msg_statistics = cYAML_create_object(peer_ni,
3213 (char *) gmsg_stat_names[k]);
3214 if (msg_statistics == NULL)
3217 counts = get_counts(msg_stats, k);
3221 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3226 yhstats = cYAML_create_object(peer_ni, "health stats");
3229 if (cYAML_create_number(yhstats, "health value",
3230 hstats->hlpni_health_value)
3233 if (cYAML_create_number(yhstats, "dropped",
3234 hstats->hlpni_remote_dropped)
3237 if (cYAML_create_number(yhstats, "timeout",
3238 hstats->hlpni_remote_timeout)
3241 if (cYAML_create_number(yhstats, "error",
3242 hstats->hlpni_remote_error)
3245 if (cYAML_create_number(yhstats, "network timeout",
3246 hstats->hlpni_network_timeout)
3252 /* print output iff show_rc is not provided */
3253 if (show_rc == NULL)
3254 cYAML_print_tree(root);
3256 snprintf(err_str, sizeof(err_str), "\"success\"");
3257 rc = LUSTRE_CFG_RC_NO_ERR;
3262 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3263 cYAML_free_tree(root);
3264 } else if (show_rc != NULL && *show_rc != NULL) {
3265 struct cYAML *show_node;
3266 /* find the peer node, if one doesn't exist then
3267 * insert one. Otherwise add to the one there
3269 show_node = cYAML_get_object_item(*show_rc,
3271 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3272 cYAML_insert_child(show_node, first_seq);
3275 } else if (show_node == NULL) {
3276 cYAML_insert_sibling((*show_rc)->cy_child,
3280 cYAML_free_tree(root);
3286 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3292 int lustre_lnet_list_peer(int seq_no,
3293 struct cYAML **show_rc, struct cYAML **err_rc)
3295 struct lnet_ioctl_peer_cfg peer_info;
3296 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3301 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3302 char err_str[LNET_MAX_STR_LEN];
3303 struct lnet_process_id *list = NULL;
3305 snprintf(err_str, sizeof(err_str),
3306 "\"out of memory\"");
3308 memset(&peer_info, 0, sizeof(peer_info));
3310 /* create struct cYAML root object */
3311 root = cYAML_create_object(NULL, NULL);
3315 list_root = cYAML_create_seq(root, "peer list");
3316 if (list_root == NULL)
3320 size = count * sizeof(struct lnet_process_id);
3321 list = malloc(size);
3327 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3328 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3329 peer_info.prcfg_size = size;
3330 peer_info.prcfg_bulk = list;
3333 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3334 count = peer_info.prcfg_count;
3338 if (l_errno != E2BIG) {
3341 "\"cannot get peer list: %s\"",
3347 size = peer_info.prcfg_size;
3348 list = malloc(size);
3355 /* count is now the actual number of ids in the list. */
3356 for (i = 0; i < count; i++) {
3357 if (cYAML_create_string(list_root, "nid",
3358 libcfs_nid2str(list[i].nid))
3363 /* print output iff show_rc is not provided */
3364 if (show_rc == NULL)
3365 cYAML_print_tree(root);
3367 snprintf(err_str, sizeof(err_str), "\"success\"");
3368 rc = LUSTRE_CFG_RC_NO_ERR;
3373 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3374 cYAML_free_tree(root);
3375 } else if (show_rc != NULL && *show_rc != NULL) {
3376 struct cYAML *show_node;
3377 /* find the peer node, if one doesn't exist then
3378 * insert one. Otherwise add to the one there
3380 show_node = cYAML_get_object_item(*show_rc,
3382 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3383 cYAML_insert_child(show_node, first_seq);
3386 } else if (show_node == NULL) {
3387 cYAML_insert_sibling((*show_rc)->cy_child,
3391 cYAML_free_tree(root);
3397 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3403 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3406 struct cYAML *show_node;
3408 show_node = cYAML_get_object_item(show_rc, "global");
3409 if (show_node != NULL)
3410 cYAML_insert_sibling(show_node->cy_child,
3413 cYAML_insert_sibling(show_rc->cy_child,
3418 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3419 char *name, __u32 value,
3420 struct cYAML **show_rc,
3421 struct cYAML **err_rc, int err)
3423 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3424 struct cYAML *root = NULL, *global = NULL;
3431 root = cYAML_create_object(NULL, NULL);
3435 global = cYAML_create_object(root, "global");
3439 if (cYAML_create_number(global, name,
3443 if (show_rc == NULL)
3444 cYAML_print_tree(root);
3446 snprintf(err_str, err_len, "\"success\"");
3448 rc = LUSTRE_CFG_RC_NO_ERR;
3451 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3452 cYAML_free_tree(root);
3453 } else if (show_rc != NULL && *show_rc != NULL) {
3454 add_to_global(*show_rc, global, root);
3459 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3464 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3465 struct cYAML **show_rc,
3466 struct cYAML **err_rc)
3468 struct lnet_ioctl_set_value data;
3471 char err_str[LNET_MAX_STR_LEN];
3473 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3475 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3477 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3482 "\"cannot get %s: %s\"",
3483 name, strerror(l_errno));
3486 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3487 data.sv_value, show_rc, err_rc, l_errno);
3490 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3491 struct cYAML **err_rc)
3493 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3494 char val[LNET_MAX_STR_LEN];
3495 int intrv = -1, l_errno = 0;
3496 char err_str[LNET_MAX_STR_LEN];
3498 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3500 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3504 snprintf(err_str, sizeof(err_str),
3505 "\"cannot get recovery interval: %d\"", rc);
3510 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3511 "recovery_interval", intrv, show_rc,
3515 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3516 struct cYAML **err_rc)
3518 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3519 char val[LNET_MAX_STR_LEN];
3520 int sen = -1, l_errno = 0;
3521 char err_str[LNET_MAX_STR_LEN];
3523 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3525 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3529 snprintf(err_str, sizeof(err_str),
3530 "\"cannot get health sensitivity: %d\"", rc);
3535 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3536 "health_sensitivity", sen, show_rc,
3540 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3541 struct cYAML **err_rc)
3543 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3544 char val[LNET_MAX_STR_LEN];
3545 int sen = -1, l_errno = 0;
3546 char err_str[LNET_MAX_STR_LEN];
3548 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3550 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3554 snprintf(err_str, sizeof(err_str),
3555 "\"cannot get router sensitivity percentage: %d\"", rc);
3560 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3561 "router_sensitivity", sen, show_rc,
3565 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3566 struct cYAML **err_rc)
3568 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3569 char val[LNET_MAX_STR_LEN];
3570 int tto = -1, l_errno = 0;
3571 char err_str[LNET_MAX_STR_LEN];
3573 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3575 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3579 snprintf(err_str, sizeof(err_str),
3580 "\"cannot get transaction timeout: %d\"", rc);
3585 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3586 "transaction_timeout", tto, show_rc,
3590 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3591 struct cYAML **err_rc)
3593 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3594 char val[LNET_MAX_STR_LEN];
3595 int retry_count = -1, l_errno = 0;
3596 char err_str[LNET_MAX_STR_LEN];
3598 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3600 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3604 snprintf(err_str, sizeof(err_str),
3605 "\"cannot get retry count: %d\"", rc);
3607 retry_count = atoi(val);
3610 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3611 "retry_count", retry_count, show_rc,
3615 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3616 struct cYAML **show_rc, struct cYAML **err_rc)
3618 struct lnet_ioctl_recovery_list nid_list;
3619 struct cYAML *root = NULL, *nids = NULL;
3621 char err_str[LNET_MAX_STR_LEN];
3623 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3625 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3626 nid_list.rlst_type = type;
3628 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3634 if (nid_list.rlst_num_nids == 0)
3637 root = cYAML_create_object(NULL, NULL);
3641 nids = cYAML_create_object(root, name);
3647 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3648 char nidenum[LNET_MAX_STR_LEN];
3649 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3650 if (!cYAML_create_string(nids, nidenum,
3651 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3655 snprintf(err_str, sizeof(err_str), "success\n");
3660 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3661 cYAML_free_tree(root);
3662 } else if (show_rc != NULL && *show_rc != NULL) {
3663 struct cYAML *show_node;
3664 /* find the net node, if one doesn't exist
3665 * then insert one. Otherwise add to the one there
3667 show_node = cYAML_get_object_item(*show_rc, name);
3668 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3669 cYAML_insert_child(show_node, nids);
3672 } else if (show_node == NULL) {
3673 cYAML_insert_sibling((*show_rc)->cy_child,
3677 cYAML_free_tree(root);
3683 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3688 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3689 struct cYAML **err_rc)
3691 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3692 seq_no, show_rc, err_rc);
3695 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3696 struct cYAML **err_rc)
3698 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3699 seq_no, show_rc, err_rc);
3702 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3703 struct cYAML **err_rc)
3705 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3706 char val[LNET_MAX_STR_LEN];
3707 int max_intf = -1, l_errno = 0;
3708 char err_str[LNET_MAX_STR_LEN];
3710 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3712 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3716 snprintf(err_str, sizeof(err_str),
3717 "\"cannot get max interfaces: %d\"", rc);
3719 max_intf = atoi(val);
3722 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3723 "max_intf", max_intf, show_rc,
3727 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3728 struct cYAML **err_rc)
3730 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3731 char val[LNET_MAX_STR_LEN];
3732 int discovery = -1, l_errno = 0;
3733 char err_str[LNET_MAX_STR_LEN];
3735 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3737 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3741 snprintf(err_str, sizeof(err_str),
3742 "\"cannot get discovery setting: %d\"", rc);
3745 * The kernel stores a discovery disabled value. User space
3746 * shows whether discovery is enabled. So the value must be
3749 discovery = !atoi(val);
3752 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3753 "discovery", discovery, show_rc,
3757 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3758 struct cYAML **err_rc)
3760 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3761 char val[LNET_MAX_STR_LEN];
3762 int drop_asym_route = -1, l_errno = 0;
3763 char err_str[LNET_MAX_STR_LEN];
3765 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3767 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3771 snprintf(err_str, sizeof(err_str),
3772 "\"cannot get drop asym route setting: %d\"", rc);
3774 drop_asym_route = atoi(val);
3777 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3778 "drop_asym_route", drop_asym_route,
3779 show_rc, err_rc, l_errno);
3782 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3783 struct cYAML **err_rc)
3785 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3786 "numa_range", show_rc, err_rc);
3789 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3790 struct cYAML **err_rc)
3792 struct lnet_ioctl_lnet_stats data;
3793 struct lnet_counters *cntrs;
3796 char err_str[LNET_MAX_STR_LEN];
3797 struct cYAML *root = NULL, *stats = NULL;
3799 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3801 LIBCFS_IOC_INIT_V2(data, st_hdr);
3803 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3808 "\"cannot get lnet statistics: %s\"",
3814 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3816 cntrs = &data.st_cntrs;
3818 root = cYAML_create_object(NULL, NULL);
3822 stats = cYAML_create_object(root, "statistics");
3826 if (!cYAML_create_number(stats, "msgs_alloc",
3827 cntrs->lct_common.lcc_msgs_alloc))
3830 if (!cYAML_create_number(stats, "msgs_max",
3831 cntrs->lct_common.lcc_msgs_max))
3834 if (!cYAML_create_number(stats, "rst_alloc",
3835 cntrs->lct_health.lch_rst_alloc))
3838 if (!cYAML_create_number(stats, "errors",
3839 cntrs->lct_common.lcc_errors))
3842 if (!cYAML_create_number(stats, "send_count",
3843 cntrs->lct_common.lcc_send_count))
3846 if (!cYAML_create_number(stats, "resend_count",
3847 cntrs->lct_health.lch_resend_count))
3850 if (!cYAML_create_number(stats, "response_timeout_count",
3851 cntrs->lct_health.lch_response_timeout_count))
3854 if (!cYAML_create_number(stats, "local_interrupt_count",
3855 cntrs->lct_health.lch_local_interrupt_count))
3858 if (!cYAML_create_number(stats, "local_dropped_count",
3859 cntrs->lct_health.lch_local_dropped_count))
3862 if (!cYAML_create_number(stats, "local_aborted_count",
3863 cntrs->lct_health.lch_local_aborted_count))
3866 if (!cYAML_create_number(stats, "local_no_route_count",
3867 cntrs->lct_health.lch_local_no_route_count))
3870 if (!cYAML_create_number(stats, "local_timeout_count",
3871 cntrs->lct_health.lch_local_timeout_count))
3874 if (!cYAML_create_number(stats, "local_error_count",
3875 cntrs->lct_health.lch_local_error_count))
3878 if (!cYAML_create_number(stats, "remote_dropped_count",
3879 cntrs->lct_health.lch_remote_dropped_count))
3882 if (!cYAML_create_number(stats, "remote_error_count",
3883 cntrs->lct_health.lch_remote_error_count))
3886 if (!cYAML_create_number(stats, "remote_timeout_count",
3887 cntrs->lct_health.lch_remote_timeout_count))
3890 if (!cYAML_create_number(stats, "network_timeout_count",
3891 cntrs->lct_health.lch_network_timeout_count))
3894 if (!cYAML_create_number(stats, "recv_count",
3895 cntrs->lct_common.lcc_recv_count))
3898 if (!cYAML_create_number(stats, "route_count",
3899 cntrs->lct_common.lcc_route_count))
3902 if (!cYAML_create_number(stats, "drop_count",
3903 cntrs->lct_common.lcc_drop_count))
3906 if (!cYAML_create_number(stats, "send_length",
3907 cntrs->lct_common.lcc_send_length))
3910 if (!cYAML_create_number(stats, "recv_length",
3911 cntrs->lct_common.lcc_recv_length))
3914 if (!cYAML_create_number(stats, "route_length",
3915 cntrs->lct_common.lcc_route_length))
3918 if (!cYAML_create_number(stats, "drop_length",
3919 cntrs->lct_common.lcc_drop_length))
3923 cYAML_print_tree(root);
3925 snprintf(err_str, sizeof(err_str), "\"success\"");
3926 rc = LUSTRE_CFG_RC_NO_ERR;
3928 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3929 cYAML_free_tree(root);
3930 } else if (show_rc != NULL && *show_rc != NULL) {
3931 cYAML_insert_sibling((*show_rc)->cy_child,
3938 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3943 typedef int (*cmd_handler_t)(struct cYAML *tree,
3944 struct cYAML **show_rc,
3945 struct cYAML **err_rc);
3947 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3948 struct cYAML **err_rc)
3950 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3952 net = cYAML_get_object_item(tree, "net");
3953 gw = cYAML_get_object_item(tree, "gateway");
3954 hop = cYAML_get_object_item(tree, "hop");
3955 prio = cYAML_get_object_item(tree, "priority");
3956 sen = cYAML_get_object_item(tree, "health_sensitivity");
3957 seq_no = cYAML_get_object_item(tree, "seq_no");
3959 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3960 (gw) ? gw->cy_valuestring : NULL,
3961 (hop) ? hop->cy_valueint : -1,
3962 (prio) ? prio->cy_valueint : -1,
3963 (sen) ? sen->cy_valueint : -1,
3964 (seq_no) ? seq_no->cy_valueint : -1,
3968 static void yaml_free_string_array(char **array, int num)
3971 char **sub_array = array;
3973 for (i = 0; i < num; i++) {
3974 if (*sub_array != NULL)
3984 * 0: <intf_name>['['<expr>']']
3985 * 1: <intf_name>['['<expr>']']
3987 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3988 struct lnet_dlc_network_descr *nw_descr)
3990 struct cYAML *child = NULL;
3991 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3992 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3994 if (intf_tree == NULL || nw_descr == NULL)
3995 return LUSTRE_CFG_RC_BAD_PARAM;
3997 /* now grab all the interfaces and their cpts */
3998 child = intf_tree->cy_child;
3999 while (child != NULL) {
4000 if (child->cy_valuestring == NULL) {
4001 child = child->cy_next;
4005 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4008 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4009 child->cy_valuestring,
4010 strlen(child->cy_valuestring));
4011 if (rc != LUSTRE_CFG_RC_NO_ERR)
4015 child = child->cy_next;
4019 return LUSTRE_CFG_RC_MISSING_PARAM;
4024 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4026 list_del(&intf_descr->intf_on_network);
4027 free_intf_descr(intf_descr);
4034 yaml_extract_cmn_tunables(struct cYAML *tree,
4035 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4036 struct cfs_expr_list **global_cpts)
4038 struct cYAML *tun, *item, *smp;
4041 tun = cYAML_get_object_item(tree, "tunables");
4043 item = cYAML_get_object_item(tun, "peer_timeout");
4045 tunables->lct_peer_timeout = item->cy_valueint;
4046 item = cYAML_get_object_item(tun, "peer_credits");
4048 tunables->lct_peer_tx_credits = item->cy_valueint;
4049 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4051 tunables->lct_peer_rtr_credits = item->cy_valueint;
4052 item = cYAML_get_object_item(tun, "credits");
4054 tunables->lct_max_tx_credits = item->cy_valueint;
4055 smp = cYAML_get_object_item(tun, "CPT");
4057 rc = cfs_expr_list_parse(smp->cy_valuestring,
4058 strlen(smp->cy_valuestring),
4059 0, UINT_MAX, global_cpts);
4061 *global_cpts = NULL;
4071 yaml_extract_tunables(struct cYAML *tree,
4072 struct lnet_ioctl_config_lnd_tunables *tunables,
4073 struct cfs_expr_list **global_cpts,
4078 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4084 lustre_yaml_extract_lnd_tunables(tree, net_type,
4092 * - net type: <net>[<NUM>]
4094 * - nid: <ip>@<net>[<NUM>]
4097 * 0: <intf_name>['['<expr>']']
4098 * 1: <intf_name>['['<expr>']']
4100 * peer_timeout: <NUM>
4101 * peer_credits: <NUM>
4102 * peer_buffer_credits: <NUM>
4105 * peercredits_hiw: <NUM>
4106 * map_on_demand: <NUM>
4107 * concurrent_sends: <NUM>
4108 * fmr_pool_size: <NUM>
4109 * fmr_flush_trigger: <NUM>
4112 * At least one interface is required. If no interfaces are provided the
4113 * network interface can not be configured.
4115 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4116 struct cYAML **err_rc)
4118 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4120 int num_entries = 0, rc;
4121 struct lnet_dlc_network_descr nw_descr;
4122 struct cfs_expr_list *global_cpts = NULL;
4123 struct lnet_ioctl_config_lnd_tunables tunables;
4126 memset(&tunables, 0, sizeof(tunables));
4128 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4129 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4131 ip2net = cYAML_get_object_item(tree, "ip2net");
4132 net = cYAML_get_object_item(tree, "net type");
4134 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4136 nw_descr.nw_id = LOLND;
4139 * if neither net nor ip2nets are present, then we can not
4140 * configure the network.
4142 if (!net && !ip2net)
4143 return LUSTRE_CFG_RC_MISSING_PARAM;
4145 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4146 if (local_nis == NULL)
4147 return LUSTRE_CFG_RC_MISSING_PARAM;
4149 if (!cYAML_is_sequence(local_nis))
4150 return LUSTRE_CFG_RC_BAD_PARAM;
4152 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4153 intf = cYAML_get_object_item(item, "interfaces");
4156 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4157 if (num_entries <= 0) {
4158 cYAML_build_error(num_entries, -1, "ni", "add",
4159 "bad interface list",
4161 return LUSTRE_CFG_RC_BAD_PARAM;
4165 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4166 LNET_NETTYP(nw_descr.nw_id));
4167 seq_no = cYAML_get_object_item(tree, "seq_no");
4169 rc = lustre_lnet_config_ni(&nw_descr,
4171 (ip2net) ? ip2net->cy_valuestring : NULL,
4172 (found) ? &tunables: NULL,
4173 (seq_no) ? seq_no->cy_valueint : -1,
4176 if (global_cpts != NULL)
4177 cfs_expr_list_free(global_cpts);
4184 * - net-spec: <tcp|o2ib|gni>[NUM]
4186 * 0: <intf name>['['<expr>']']
4187 * 1: <intf name>['['<expr>']']
4189 * 0: <expr.expr.expr.expr>
4190 * 1: <expr.expr.expr.expr>
4192 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4193 struct cYAML **show_rc,
4194 struct cYAML **err_rc)
4196 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4198 struct lustre_lnet_ip2nets ip2nets;
4199 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4201 int rc = LUSTRE_CFG_RC_NO_ERR;
4202 struct cfs_expr_list *global_cpts = NULL;
4203 struct cfs_expr_list *el, *el_tmp;
4204 struct lnet_ioctl_config_lnd_tunables tunables;
4205 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4208 memset(&tunables, 0, sizeof(tunables));
4210 /* initialize all lists */
4211 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4212 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4213 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4215 net = cYAML_get_object_item(tree, "net-spec");
4217 return LUSTRE_CFG_RC_BAD_PARAM;
4219 if (net != NULL && net->cy_valuestring == NULL)
4220 return LUSTRE_CFG_RC_BAD_PARAM;
4222 /* assign the network id */
4223 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4224 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4225 return LUSTRE_CFG_RC_BAD_PARAM;
4227 seq_no = cYAML_get_object_item(tree, "seq_no");
4229 intf = cYAML_get_object_item(tree, "interfaces");
4231 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4233 return LUSTRE_CFG_RC_BAD_PARAM;
4236 ip_range = cYAML_get_object_item(tree, "ip-range");
4237 if (ip_range != NULL) {
4238 item = ip_range->cy_child;
4239 while (item != NULL) {
4240 if (item->cy_valuestring == NULL) {
4241 item = item->cy_next;
4245 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4246 item->cy_valuestring);
4248 if (rc != LUSTRE_CFG_RC_NO_ERR)
4251 item = item->cy_next;
4255 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4256 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4258 rc = lustre_lnet_config_ip2nets(&ip2nets,
4259 (found) ? &tunables : NULL,
4261 (seq_no) ? seq_no->cy_valueint : -1,
4265 * don't stop because there was no match. Continue processing the
4266 * rest of the rules. If non-match then nothing is configured
4268 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4269 rc = LUSTRE_CFG_RC_NO_ERR;
4271 list_for_each_entry_safe(intf_descr, intf_tmp,
4272 &ip2nets.ip2nets_net.nw_intflist,
4274 list_del(&intf_descr->intf_on_network);
4275 free_intf_descr(intf_descr);
4278 list_for_each_entry_safe(ip_range_descr, tmp,
4279 &ip2nets.ip2nets_ip_ranges,
4281 list_del(&ip_range_descr->ipr_entry);
4282 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4284 list_del(&el->el_link);
4285 cfs_expr_list_free(el);
4287 free(ip_range_descr);
4293 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4294 struct cYAML **err_rc)
4296 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4298 int num_entries, rc;
4299 struct lnet_dlc_network_descr nw_descr;
4301 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4302 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4304 net = cYAML_get_object_item(tree, "net type");
4306 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4308 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4309 if (local_nis == NULL)
4310 return LUSTRE_CFG_RC_MISSING_PARAM;
4312 if (!cYAML_is_sequence(local_nis))
4313 return LUSTRE_CFG_RC_BAD_PARAM;
4315 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4316 intf = cYAML_get_object_item(item, "interfaces");
4319 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4320 if (num_entries <= 0) {
4321 cYAML_build_error(num_entries, -1, "ni", "add",
4322 "bad interface list",
4324 return LUSTRE_CFG_RC_BAD_PARAM;
4328 seq_no = cYAML_get_object_item(tree, "seq_no");
4330 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4331 (seq_no) ? seq_no->cy_valueint : -1,
4337 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4338 char *prim_nid, bool del)
4340 struct cYAML *child = NULL, *entry = NULL;
4342 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4344 if (cYAML_is_sequence(nids_entry)) {
4345 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4346 entry = cYAML_get_object_item(child, "nid");
4347 /* don't count an empty entry */
4348 if (!entry || !entry->cy_valuestring)
4352 (strcmp(entry->cy_valuestring, prim_nid)
4355 * primary nid is present in the list of
4356 * nids so that means we want to delete
4357 * the entire peer, so no need to go
4358 * further. Just delete the entire peer.
4368 return LUSTRE_CFG_RC_MISSING_PARAM;
4370 nids = calloc(sizeof(*nids), num);
4372 return LUSTRE_CFG_RC_OUT_OF_MEM;
4374 /* now grab all the nids */
4377 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4378 entry = cYAML_get_object_item(child, "nid");
4379 if (!entry || !entry->cy_valuestring)
4382 nids[num] = strdup(entry->cy_valuestring);
4384 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4396 yaml_free_string_array(nids, num);
4401 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4402 struct cYAML **err_rc)
4406 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4407 char err_str[LNET_MAX_STR_LEN];
4410 seq_no = cYAML_get_object_item(tree, "seq_no");
4411 prim_nid = cYAML_get_object_item(tree, "primary nid");
4412 mr = cYAML_get_object_item(tree, "Multi-Rail");
4413 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4414 peer_nis = cYAML_get_object_item(tree, "peer ni");
4416 if (ip2nets && (prim_nid || peer_nis)) {
4417 rc = LUSTRE_CFG_RC_BAD_PARAM;
4418 snprintf(err_str, sizeof(err_str),
4419 "ip2nets can not be specified along side prim_nid"
4420 " or peer ni fields");
4421 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4422 ADD_CMD, "peer", err_str, err_rc);
4429 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4431 else if (!strcmp(mr->cy_valuestring, "False"))
4434 rc = LUSTRE_CFG_RC_BAD_PARAM;
4435 snprintf(err_str, sizeof(err_str), "Bad MR value");
4436 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4437 ADD_CMD, "peer", err_str, err_rc);
4442 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4443 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4447 snprintf(err_str, sizeof(err_str),
4448 "error copying nids from YAML block");
4449 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4450 ADD_CMD, "peer", err_str, err_rc);
4454 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4455 nids, num, mr_value,
4456 (ip2nets) ? true : false,
4457 (seq_no) ? seq_no->cy_valueint : -1,
4460 yaml_free_string_array(nids, num);
4464 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4465 struct cYAML **err_rc)
4469 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4470 char err_str[LNET_MAX_STR_LEN];
4472 seq_no = cYAML_get_object_item(tree, "seq_no");
4473 prim_nid = cYAML_get_object_item(tree, "primary nid");
4474 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4475 peer_nis = cYAML_get_object_item(tree, "peer ni");
4477 if (ip2nets && (prim_nid || peer_nis)) {
4478 rc = LUSTRE_CFG_RC_BAD_PARAM;
4479 snprintf(err_str, sizeof(err_str),
4480 "ip2nets can not be specified along side prim_nid"
4481 " or peer ni fields");
4482 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4483 DEL_CMD, "peer", err_str, err_rc);
4487 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4488 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4491 snprintf(err_str, sizeof(err_str),
4492 "error copying nids from YAML block");
4493 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4494 ADD_CMD, "peer", err_str, err_rc);
4498 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4499 nids, num, (ip2nets) ? true : false,
4500 (seq_no) ? seq_no->cy_valueint : -1,
4503 yaml_free_string_array(nids, num);
4507 static int handle_yaml_config_buffers(struct cYAML *tree,
4508 struct cYAML **show_rc,
4509 struct cYAML **err_rc)
4512 struct cYAML *tiny, *small, *large, *seq_no;
4514 tiny = cYAML_get_object_item(tree, "tiny");
4515 small = cYAML_get_object_item(tree, "small");
4516 large = cYAML_get_object_item(tree, "large");
4517 seq_no = cYAML_get_object_item(tree, "seq_no");
4519 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4520 (small) ? small->cy_valueint : -1,
4521 (large) ? large->cy_valueint : -1,
4522 (seq_no) ? seq_no->cy_valueint : -1,
4528 static int handle_yaml_config_routing(struct cYAML *tree,
4529 struct cYAML **show_rc,
4530 struct cYAML **err_rc)
4532 int rc = LUSTRE_CFG_RC_NO_ERR;
4533 struct cYAML *seq_no, *enable;
4535 seq_no = cYAML_get_object_item(tree, "seq_no");
4536 enable = cYAML_get_object_item(tree, "enable");
4539 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4541 seq_no->cy_valueint : -1,
4548 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4549 struct cYAML **err_rc)
4553 struct cYAML *seq_no;
4555 net = cYAML_get_object_item(tree, "net");
4556 gw = cYAML_get_object_item(tree, "gateway");
4557 seq_no = cYAML_get_object_item(tree, "seq_no");
4559 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4560 (gw) ? gw->cy_valuestring : NULL,
4561 (seq_no) ? seq_no->cy_valueint : -1,
4565 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4566 struct cYAML **err_rc)
4568 struct cYAML *seq_no;
4570 seq_no = cYAML_get_object_item(tree, "seq_no");
4572 return lustre_lnet_enable_routing(0, (seq_no) ?
4573 seq_no->cy_valueint : -1,
4577 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4578 struct cYAML **err_rc)
4584 struct cYAML *detail;
4585 struct cYAML *seq_no;
4587 net = cYAML_get_object_item(tree, "net");
4588 gw = cYAML_get_object_item(tree, "gateway");
4589 hop = cYAML_get_object_item(tree, "hop");
4590 prio = cYAML_get_object_item(tree, "priority");
4591 detail = cYAML_get_object_item(tree, "detail");
4592 seq_no = cYAML_get_object_item(tree, "seq_no");
4594 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4595 (gw) ? gw->cy_valuestring : NULL,
4596 (hop) ? hop->cy_valueint : -1,
4597 (prio) ? prio->cy_valueint : -1,
4598 (detail) ? detail->cy_valueint : 0,
4599 (seq_no) ? seq_no->cy_valueint : -1,
4600 show_rc, err_rc, false);
4603 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4604 struct cYAML **err_rc)
4606 struct cYAML *net, *detail, *seq_no;
4608 net = cYAML_get_object_item(tree, "net");
4609 detail = cYAML_get_object_item(tree, "detail");
4610 seq_no = cYAML_get_object_item(tree, "seq_no");
4612 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4613 (detail) ? detail->cy_valueint : 0,
4614 (seq_no) ? seq_no->cy_valueint : -1,
4615 show_rc, err_rc, false);
4618 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4619 struct cYAML **err_rc)
4621 struct cYAML *seq_no;
4623 seq_no = cYAML_get_object_item(tree, "seq_no");
4625 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4626 show_rc, err_rc, false);
4629 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4630 struct cYAML **err_rc)
4632 struct cYAML *seq_no, *nid, *detail;
4634 seq_no = cYAML_get_object_item(tree, "seq_no");
4635 detail = cYAML_get_object_item(tree, "detail");
4636 nid = cYAML_get_object_item(tree, "nid");
4638 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4639 (detail) ? detail->cy_valueint : 0,
4640 (seq_no) ? seq_no->cy_valueint : -1,
4641 show_rc, err_rc, false);
4644 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4645 struct cYAML **err_rc)
4647 struct cYAML *seq_no;
4649 seq_no = cYAML_get_object_item(tree, "seq_no");
4651 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4655 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4656 struct cYAML **err_rc)
4658 struct cYAML *seq_no, *range;
4660 seq_no = cYAML_get_object_item(tree, "seq_no");
4661 range = cYAML_get_object_item(tree, "range");
4663 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4664 seq_no ? seq_no->cy_valueint : -1,
4668 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4669 struct cYAML **err_rc)
4671 struct cYAML *seq_no;
4673 seq_no = cYAML_get_object_item(tree, "seq_no");
4675 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4679 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4680 struct cYAML **err_rc)
4682 struct cYAML *seq_no;
4684 seq_no = cYAML_get_object_item(tree, "seq_no");
4686 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4690 static int handle_yaml_config_global_settings(struct cYAML *tree,
4691 struct cYAML **show_rc,
4692 struct cYAML **err_rc)
4694 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4695 *sen, *recov, *rsen, *drop_asym_route;
4698 seq_no = cYAML_get_object_item(tree, "seq_no");
4699 max_intf = cYAML_get_object_item(tree, "max_intf");
4701 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4702 seq_no ? seq_no->cy_valueint
4706 numa = cYAML_get_object_item(tree, "numa_range");
4708 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4709 seq_no ? seq_no->cy_valueint
4713 discovery = cYAML_get_object_item(tree, "discovery");
4715 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4716 seq_no ? seq_no->cy_valueint
4720 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4721 if (drop_asym_route)
4722 rc = lustre_lnet_config_drop_asym_route(
4723 drop_asym_route->cy_valueint,
4724 seq_no ? seq_no->cy_valueint : -1,
4727 retry = cYAML_get_object_item(tree, "retry_count");
4729 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4730 seq_no ? seq_no->cy_valueint
4734 tto = cYAML_get_object_item(tree, "transaction_timeout");
4736 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4737 seq_no ? seq_no->cy_valueint
4741 sen = cYAML_get_object_item(tree, "health_sensitivity");
4743 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4744 seq_no ? seq_no->cy_valueint
4748 recov = cYAML_get_object_item(tree, "recovery_interval");
4750 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4751 seq_no ? seq_no->cy_valueint
4755 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4757 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4758 seq_no ? seq_no->cy_valueint
4765 static int handle_yaml_del_global_settings(struct cYAML *tree,
4766 struct cYAML **show_rc,
4767 struct cYAML **err_rc)
4769 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4772 seq_no = cYAML_get_object_item(tree, "seq_no");
4773 max_intf = cYAML_get_object_item(tree, "max_intf");
4775 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4776 seq_no ? seq_no->cy_valueint
4780 numa = cYAML_get_object_item(tree, "numa_range");
4782 rc = lustre_lnet_config_numa_range(0,
4783 seq_no ? seq_no->cy_valueint
4787 /* peer discovery is enabled by default */
4788 discovery = cYAML_get_object_item(tree, "discovery");
4790 rc = lustre_lnet_config_discovery(1,
4791 seq_no ? seq_no->cy_valueint
4795 /* asymmetrical route messages are accepted by default */
4796 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4797 if (drop_asym_route)
4798 rc = lustre_lnet_config_drop_asym_route(
4799 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4804 static int handle_yaml_show_global_settings(struct cYAML *tree,
4805 struct cYAML **show_rc,
4806 struct cYAML **err_rc)
4808 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4809 *sen, *recov, *rsen, *drop_asym_route;
4812 seq_no = cYAML_get_object_item(tree, "seq_no");
4813 max_intf = cYAML_get_object_item(tree, "max_intf");
4815 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4819 numa = cYAML_get_object_item(tree, "numa_range");
4821 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4825 discovery = cYAML_get_object_item(tree, "discovery");
4827 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4831 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4832 if (drop_asym_route)
4833 rc = lustre_lnet_show_drop_asym_route(
4834 seq_no ? seq_no->cy_valueint : -1,
4837 retry = cYAML_get_object_item(tree, "retry_count");
4839 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4843 tto = cYAML_get_object_item(tree, "transaction_timeout");
4845 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4849 sen = cYAML_get_object_item(tree, "health_sensitivity");
4851 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4855 recov = cYAML_get_object_item(tree, "recovery_interval");
4857 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4861 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4863 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4870 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4871 struct cYAML **err_rc)
4873 struct cYAML *seq_no, *nid, *timeout;
4875 seq_no = cYAML_get_object_item(tree, "seq_no");
4876 nid = cYAML_get_object_item(tree, "primary nid");
4877 timeout = cYAML_get_object_item(tree, "timeout");
4879 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4880 (timeout) ? timeout->cy_valueint : 1000,
4881 (seq_no) ? seq_no->cy_valueint : -1,
4885 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4886 struct cYAML **err_rc)
4888 struct cYAML *seq_no, *nid, *force;
4890 seq_no = cYAML_get_object_item(tree, "seq_no");
4891 nid = cYAML_get_object_item(tree, "primary nid");
4892 force = cYAML_get_object_item(tree, "force");
4894 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4895 (force) ? force->cy_valueint : 0,
4896 (seq_no) ? seq_no->cy_valueint : -1,
4900 static int handle_yaml_no_op()
4902 return LUSTRE_CFG_RC_NO_ERR;
4905 struct lookup_cmd_hdlr_tbl {
4910 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4911 { .name = "route", .cb = handle_yaml_config_route },
4912 { .name = "net", .cb = handle_yaml_config_ni },
4913 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4914 { .name = "peer", .cb = handle_yaml_config_peer },
4915 { .name = "routing", .cb = handle_yaml_config_routing },
4916 { .name = "buffers", .cb = handle_yaml_config_buffers },
4917 { .name = "statistics", .cb = handle_yaml_no_op },
4918 { .name = "global", .cb = handle_yaml_config_global_settings},
4919 { .name = "numa", .cb = handle_yaml_config_numa },
4920 { .name = "ping", .cb = handle_yaml_no_op },
4921 { .name = "discover", .cb = handle_yaml_no_op },
4924 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4925 { .name = "route", .cb = handle_yaml_del_route },
4926 { .name = "net", .cb = handle_yaml_del_ni },
4927 { .name = "ip2nets", .cb = handle_yaml_no_op },
4928 { .name = "peer", .cb = handle_yaml_del_peer },
4929 { .name = "routing", .cb = handle_yaml_del_routing },
4930 { .name = "buffers", .cb = handle_yaml_no_op },
4931 { .name = "statistics", .cb = handle_yaml_no_op },
4932 { .name = "global", .cb = handle_yaml_del_global_settings},
4933 { .name = "numa", .cb = handle_yaml_del_numa },
4934 { .name = "ping", .cb = handle_yaml_no_op },
4935 { .name = "discover", .cb = handle_yaml_no_op },
4938 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4939 { .name = "route", .cb = handle_yaml_show_route },
4940 { .name = "net", .cb = handle_yaml_show_net },
4941 { .name = "peer", .cb = handle_yaml_show_peers },
4942 { .name = "ip2nets", .cb = handle_yaml_no_op },
4943 { .name = "routing", .cb = handle_yaml_show_routing },
4944 { .name = "buffers", .cb = handle_yaml_show_routing },
4945 { .name = "statistics", .cb = handle_yaml_show_stats },
4946 { .name = "global", .cb = handle_yaml_show_global_settings},
4947 { .name = "numa", .cb = handle_yaml_show_numa },
4948 { .name = "ping", .cb = handle_yaml_no_op },
4949 { .name = "discover", .cb = handle_yaml_no_op },
4952 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4953 { .name = "route", .cb = handle_yaml_no_op },
4954 { .name = "net", .cb = handle_yaml_no_op },
4955 { .name = "peer", .cb = handle_yaml_no_op },
4956 { .name = "ip2nets", .cb = handle_yaml_no_op },
4957 { .name = "routing", .cb = handle_yaml_no_op },
4958 { .name = "buffers", .cb = handle_yaml_no_op },
4959 { .name = "statistics", .cb = handle_yaml_no_op },
4960 { .name = "global", .cb = handle_yaml_no_op },
4961 { .name = "numa", .cb = handle_yaml_no_op },
4962 { .name = "ping", .cb = handle_yaml_ping },
4963 { .name = "discover", .cb = handle_yaml_discover },
4966 static cmd_handler_t lookup_fn(char *key,
4967 struct lookup_cmd_hdlr_tbl *tbl)
4973 for (i = 0; tbl[i].name != NULL; i++) {
4974 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4981 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4982 struct cYAML **show_rc, struct cYAML **err_rc)
4984 struct cYAML *tree, *item = NULL, *head, *child;
4986 char err_str[LNET_MAX_STR_LEN];
4987 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4989 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4991 return LUSTRE_CFG_RC_BAD_PARAM;
4993 child = tree->cy_child;
4994 while (child != NULL) {
4995 cb = lookup_fn(child->cy_string, table);
4997 snprintf(err_str, sizeof(err_str),
4998 "\"call back for '%s' not found\"",
5000 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5001 "yaml", "helper", err_str, err_rc);
5005 if (cYAML_is_sequence(child)) {
5006 while ((head = cYAML_get_next_seq_item(child, &item))
5008 rc = cb(head, show_rc, err_rc);
5009 if (rc != LUSTRE_CFG_RC_NO_ERR)
5013 rc = cb(child, show_rc, err_rc);
5014 if (rc != LUSTRE_CFG_RC_NO_ERR)
5018 child = child->cy_next;
5022 cYAML_free_tree(tree);
5027 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5029 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5033 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5035 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5039 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5041 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5045 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5047 return lustre_yaml_cb_helper(f, lookup_exec_tbl,