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 "\"cannot parse ip_range '%s'\"", ip_range);
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 '%s'\"", 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 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;
1043 rc = lnet_expr2ips(gw, ip_list,
1044 &ip2nets, &net, err_str);
1045 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1047 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1052 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1053 data.cfg_net = rnet;
1054 data.cfg_config_u.cfg_route.rtr_hop = hops;
1055 data.cfg_config_u.cfg_route.rtr_priority = prio;
1057 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1058 gateway_nid = LNET_MKNID(net, ip_list[i]);
1059 if (gateway_nid == LNET_NID_ANY) {
1062 "\"cannot form gateway NID: %u\"",
1064 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1065 rc = LUSTRE_CFG_RC_BAD_PARAM;
1068 data.cfg_nid = gateway_nid;
1070 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1075 "\"cannot add route: %s\"", strerror(errno));
1080 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1085 int lustre_lnet_del_route(char *nw, char *gw,
1086 int seq_no, struct cYAML **err_rc)
1088 struct lnet_ioctl_config_data data;
1089 lnet_nid_t gateway_nid;
1090 int rc = LUSTRE_CFG_RC_NO_ERR;
1091 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1092 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1093 char err_str[LNET_MAX_STR_LEN];
1095 __u32 ip_list[MAX_NUM_IPS];
1096 struct lustre_lnet_ip2nets ip2nets;
1098 /* initialize all lists */
1099 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1100 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1101 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1103 snprintf(err_str, sizeof(err_str), "\"Success\"");
1105 if (nw == NULL || gw == NULL) {
1108 "\"missing mandatory parameter in route delete: '%s'\"",
1109 (nw == NULL && gw == NULL) ? "network, gateway" :
1110 (nw == NULL) ? "network" : "gateway");
1111 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1115 rnet = libcfs_str2net(nw);
1116 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1119 "\"cannot parse remote net '%s'\"", nw);
1120 rc = LUSTRE_CFG_RC_BAD_PARAM;
1124 rc = lnet_expr2ips(gw, ip_list,
1125 &ip2nets, &net, err_str);
1126 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1128 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1133 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1134 data.cfg_net = rnet;
1136 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1137 gateway_nid = LNET_MKNID(net, ip_list[i]);
1138 if (gateway_nid == LNET_NID_ANY) {
1141 "\"cannot form gateway NID: %u\"",
1143 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1144 rc = LUSTRE_CFG_RC_BAD_PARAM;
1147 data.cfg_nid = gateway_nid;
1149 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1154 "\"cannot delete route: %s\"", strerror(errno));
1159 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1164 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1165 int seq_no, struct cYAML **show_rc,
1166 struct cYAML **err_rc, bool backup)
1168 struct lnet_ioctl_config_data data;
1169 lnet_nid_t gateway_nid;
1170 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1172 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1174 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1175 struct cYAML *first_seq = NULL;
1176 char err_str[LNET_MAX_STR_LEN];
1179 snprintf(err_str, sizeof(err_str),
1180 "\"out of memory\"");
1183 net = libcfs_str2net(nw);
1184 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1187 "\"cannot parse net '%s'\"", nw);
1188 rc = LUSTRE_CFG_RC_BAD_PARAM;
1193 /* show all routes without filtering on net */
1194 net = LNET_NIDNET(LNET_NID_ANY);
1198 gateway_nid = libcfs_str2nid(gw);
1199 if (gateway_nid == LNET_NID_ANY) {
1202 "\"cannot parse gateway NID '%s'\"", gw);
1203 rc = LUSTRE_CFG_RC_BAD_PARAM;
1207 /* show all routes with out filtering on gateway */
1208 gateway_nid = LNET_NID_ANY;
1210 if ((hops < 1 && hops != -1) || hops > 255) {
1213 "\"invalid hop count %d, must be between 0 and 256\"",
1215 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1219 /* create struct cYAML root object */
1220 root = cYAML_create_object(NULL, NULL);
1224 route = cYAML_create_seq(root, "route");
1229 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1232 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1238 /* filter on provided data */
1239 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1240 net != data.cfg_net)
1243 if (gateway_nid != LNET_NID_ANY &&
1244 gateway_nid != data.cfg_nid)
1248 hops != data.cfg_config_u.cfg_route.rtr_hop)
1252 prio != data.cfg_config_u.cfg_route.rtr_priority)
1255 /* default rc to -1 incase we hit the goto */
1259 item = cYAML_create_seq_item(route);
1263 if (first_seq == NULL)
1266 if (cYAML_create_string(item, "net",
1267 libcfs_net2str(data.cfg_net)) == NULL)
1270 if (cYAML_create_string(item, "gateway",
1271 libcfs_nid2str(data.cfg_nid)) == NULL)
1275 if (cYAML_create_number(item, "hop",
1276 (int) data.cfg_config_u.
1277 cfg_route.rtr_hop) ==
1281 if (cYAML_create_number(item, "priority",
1283 cfg_route.rtr_priority) == NULL)
1287 cYAML_create_string(item, "state",
1288 data.cfg_config_u.cfg_route.
1290 "up" : "down") == NULL)
1295 /* print output iff show_rc is not provided */
1296 if (show_rc == NULL)
1297 cYAML_print_tree(root);
1299 if (l_errno != ENOENT) {
1302 "\"cannot get routes: %s\"",
1307 rc = LUSTRE_CFG_RC_NO_ERR;
1309 snprintf(err_str, sizeof(err_str), "\"success\"");
1311 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1312 cYAML_free_tree(root);
1313 } else if (show_rc != NULL && *show_rc != NULL) {
1314 struct cYAML *show_node;
1315 /* find the route node, if one doesn't exist then
1316 * insert one. Otherwise add to the one there
1318 show_node = cYAML_get_object_item(*show_rc, "route");
1319 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1320 cYAML_insert_child(show_node, first_seq);
1323 } else if (show_node == NULL) {
1324 cYAML_insert_sibling((*show_rc)->cy_child,
1328 cYAML_free_tree(root);
1334 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1339 static int socket_intf_query(int request, char *intf,
1345 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1346 return LUSTRE_CFG_RC_BAD_PARAM;
1348 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1350 return LUSTRE_CFG_RC_BAD_PARAM;
1352 strcpy(ifr->ifr_name, intf);
1353 rc = ioctl(sockfd, request, ifr);
1355 rc = LUSTRE_CFG_RC_BAD_PARAM;
1362 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1367 memset(&ifr, 0, sizeof(ifr));
1368 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1370 return LUSTRE_CFG_RC_BAD_PARAM;
1372 if ((ifr.ifr_flags & IFF_UP) == 0)
1373 return LUSTRE_CFG_RC_BAD_PARAM;
1375 memset(&ifr, 0, sizeof(ifr));
1376 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1378 return LUSTRE_CFG_RC_BAD_PARAM;
1380 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1381 *ip = bswap_32(*ip);
1383 return LUSTRE_CFG_RC_NO_ERR;
1387 * for each interface in the array of interfaces find the IP address of
1388 * that interface, create its nid and add it to an array of NIDs.
1389 * Stop if any of the interfaces is down
1391 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1392 lnet_nid_t **nids, __u32 *nnids,
1393 char *err_str, size_t str_len)
1395 int i = 0, count = 0, rc;
1396 struct lnet_dlc_intf_descr *intf;
1397 char val[LNET_MAX_STR_LEN];
1404 if (nw == NULL || nids == NULL) {
1405 snprintf(err_str, str_len,
1406 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1407 err_str[str_len - 1] = '\0';
1408 return LUSTRE_CFG_RC_BAD_PARAM;
1411 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1414 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1418 *nids = calloc(count, sizeof(lnet_nid_t));
1419 if (*nids == NULL) {
1420 snprintf(err_str, str_len,
1421 "\"out of memory\"");
1422 err_str[str_len - 1] = '\0';
1423 return LUSTRE_CFG_RC_OUT_OF_MEM;
1426 * special case the GNI interface since it doesn't have an IP
1427 * address. The assumption is that there can only be one GNI
1428 * interface in the system. No interface name is provided.
1430 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1431 rc = read_sysfs_file(gni_nid_path, "nid", val,
1434 snprintf(err_str, str_len,
1435 "\"cannot read gni nid\"");
1436 err_str[str_len - 1] = '\0';
1439 gni_num = atoi(val);
1441 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1446 /* look at the other interfaces */
1447 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1448 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1449 /* handle LNDs with numeric interface name */
1450 num = strtoul(intf->intf_name, &endp, 0);
1451 if (endp == intf->intf_name || *endp != '\0') {
1452 rc = LUSTRE_CFG_RC_BAD_PARAM;
1453 snprintf(err_str, str_len,
1454 "\"couldn't query intf %s\"",
1456 err_str[str_len - 1] = '\0';
1459 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1462 /* handle LNDs with ip interface name */
1463 rc = lustre_lnet_queryip(intf, &ip);
1464 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1465 snprintf(err_str, str_len,
1466 "\"couldn't query intf %s\"",
1468 err_str[str_len - 1] = '\0';
1471 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1488 * called repeatedly until a match or no more ip range
1490 * ip_range expression
1491 * interface list with all the interface names.
1492 * all the interfaces in the system.
1494 * try to match the ip_range expr to one of the interfaces' IPs in
1495 * the system. If we hit a patch for an interface. Check if that
1496 * interface name is in the list.
1498 * If there are more than one interface in the list, then make sure
1499 * that the IPs for all of these interfaces match the ip ranges
1502 * for each interface in intf_list
1503 * look up the intf name in ifa
1504 * if not there then no match
1505 * check ip obtained from ifa against a match to any of the
1507 * If no match, then fail
1509 * The result is that all the interfaces have to match.
1511 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1512 struct list_head *intf_list,
1513 struct list_head *ip_ranges)
1517 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1518 struct ifaddrs *ifaddr = ifa;
1519 struct lustre_lnet_ip_range_descr *ip_range;
1523 * if there are no explicit interfaces, and no ip ranges, then
1524 * configure the first tcp interface we encounter.
1526 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1527 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1528 if (ifaddr->ifa_addr == NULL)
1531 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1534 family = ifaddr->ifa_addr->sa_family;
1535 if (family == AF_INET &&
1536 strcmp(ifaddr->ifa_name, "lo") != 0) {
1537 rc = lustre_lnet_add_intf_descr
1538 (intf_list, ifaddr->ifa_name,
1539 strlen(ifaddr->ifa_name));
1541 if (rc != LUSTRE_CFG_RC_NO_ERR)
1544 return LUSTRE_CFG_RC_MATCH;
1547 return LUSTRE_CFG_RC_NO_MATCH;
1551 * First interface which matches an IP pattern will be used
1553 if (list_empty(intf_list)) {
1555 * no interfaces provided in the rule, but an ip range is
1556 * provided, so try and match an interface to the ip
1559 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1560 if (ifaddr->ifa_addr == NULL)
1563 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1566 family = ifaddr->ifa_addr->sa_family;
1567 if (family == AF_INET) {
1568 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1571 list_for_each_entry(ip_range, ip_ranges,
1573 rc = cfs_ip_addr_match(bswap_32(ip),
1574 &ip_range->ipr_expr);
1578 rc = lustre_lnet_add_intf_descr
1579 (intf_list, ifaddr->ifa_name,
1580 strlen(ifaddr->ifa_name));
1582 if (rc != LUSTRE_CFG_RC_NO_ERR)
1588 if (!list_empty(intf_list))
1589 return LUSTRE_CFG_RC_MATCH;
1591 return LUSTRE_CFG_RC_NO_MATCH;
1595 * If an interface is explicitly specified the ip-range might or
1596 * might not be specified. if specified the interface needs to match the
1597 * ip-range. If no ip-range then the interfaces are
1598 * automatically matched if they are all up.
1599 * If > 1 interfaces all the interfaces must match for the NI to
1602 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1603 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1604 if (ifaddr->ifa_addr == NULL)
1607 family = ifaddr->ifa_addr->sa_family;
1608 if (family == AF_INET &&
1609 strcmp(intf_descr->intf_name,
1610 ifaddr->ifa_name) == 0)
1614 if (ifaddr == NULL) {
1615 list_del(&intf_descr->intf_on_network);
1616 free_intf_descr(intf_descr);
1620 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1621 list_del(&intf_descr->intf_on_network);
1622 free_intf_descr(intf_descr);
1626 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1629 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1630 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1636 /* no match for this interface */
1637 list_del(&intf_descr->intf_on_network);
1638 free_intf_descr(intf_descr);
1642 return LUSTRE_CFG_RC_MATCH;
1645 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1646 lnet_nid_t **nids, __u32 *nnids,
1647 char *err_str, size_t str_len)
1649 struct ifaddrs *ifa;
1650 int rc = LUSTRE_CFG_RC_NO_ERR;
1652 rc = getifaddrs(&ifa);
1654 snprintf(err_str, str_len,
1655 "\"failed to get interface addresses: %d\"", -errno);
1656 err_str[str_len - 1] = '\0';
1660 rc = lustre_lnet_match_ip_to_intf(ifa,
1661 &ip2nets->ip2nets_net.nw_intflist,
1662 &ip2nets->ip2nets_ip_ranges);
1663 if (rc != LUSTRE_CFG_RC_MATCH) {
1664 snprintf(err_str, str_len,
1665 "\"couldn't match ip to existing interfaces\"");
1666 err_str[str_len - 1] = '\0';
1671 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1672 err_str, sizeof(err_str));
1673 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1684 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1685 struct lnet_ioctl_config_lnd_tunables *tunables,
1686 struct cfs_expr_list *global_cpts,
1687 lnet_nid_t *nids, char *err_str)
1690 struct lnet_ioctl_config_ni *conf;
1691 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1692 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1695 struct lnet_dlc_intf_descr *intf_descr;
1697 struct cfs_expr_list *cpt_expr;
1699 list_for_each_entry(intf_descr, intf_list,
1701 if (tunables != NULL)
1702 len = sizeof(struct lnet_ioctl_config_ni) +
1703 sizeof(struct lnet_ioctl_config_lnd_tunables);
1705 len = sizeof(struct lnet_ioctl_config_ni);
1707 data = calloc(1, len);
1709 return LUSTRE_CFG_RC_OUT_OF_MEM;
1710 conf = (struct lnet_ioctl_config_ni*) data;
1711 if (tunables != NULL)
1712 tun = (struct lnet_ioctl_config_lnd_tunables*)
1715 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1716 conf->lic_cfg_hdr.ioc_len = len;
1717 conf->lic_nid = nids[i];
1718 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1721 if (intf_descr->cpt_expr != NULL)
1722 cpt_expr = intf_descr->cpt_expr;
1723 else if (global_cpts != NULL)
1724 cpt_expr = global_cpts;
1728 if (cpt_expr != NULL) {
1729 count = cfs_expr_list_values(cpt_expr,
1730 LNET_MAX_SHOW_NUM_CPT,
1733 memcpy(conf->lic_cpts, cpt_array,
1734 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1743 conf->lic_ncpts = count;
1745 if (tunables != NULL)
1746 memcpy(tun, tunables, sizeof(*tunables));
1748 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1753 "\"cannot add network: %s\"", strerror(errno));
1761 return LUSTRE_CFG_RC_NO_ERR;
1765 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1766 struct lnet_ioctl_config_lnd_tunables *tunables,
1767 struct cfs_expr_list *global_cpts,
1768 int seq_no, struct cYAML **err_rc)
1770 lnet_nid_t *nids = NULL;
1773 char err_str[LNET_MAX_STR_LEN];
1775 snprintf(err_str, sizeof(err_str), "\"success\"");
1780 "\"incomplete ip2nets information\"");
1781 rc = LUSTRE_CFG_RC_BAD_PARAM;
1786 * call below function to resolve the rules into a list of nids.
1787 * The memory is allocated in that function then freed here when
1788 * it's no longer needed.
1790 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1792 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1795 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1796 snprintf(err_str, sizeof(err_str),
1797 "\"no interfaces match ip2nets rules\"");
1801 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1802 tunables, global_cpts, nids,
1809 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1813 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1814 struct cfs_expr_list *global_cpts,
1816 struct lnet_ioctl_config_lnd_tunables *tunables,
1817 int seq_no, struct cYAML **err_rc)
1820 struct lnet_ioctl_config_ni *conf;
1821 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1822 char buf[LNET_MAX_STR_LEN];
1823 int rc = LUSTRE_CFG_RC_NO_ERR;
1824 char err_str[LNET_MAX_STR_LEN];
1825 lnet_nid_t *nids = NULL;
1829 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1832 snprintf(err_str, sizeof(err_str), "\"success\"");
1834 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1835 (list_empty(&nw_descr->nw_intflist) &&
1836 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1839 "\"missing mandatory parameters in NI config: '%s'\"",
1840 (nw_descr == NULL) ? "network , interface" :
1841 (nw_descr->nw_id == 0) ? "network" : "interface");
1842 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1846 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1849 "\"ip2net string too long %d\"",
1850 (int)strlen(ip2net));
1851 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1855 if (ip2net != NULL) {
1856 if (tunables != NULL)
1857 len = sizeof(struct lnet_ioctl_config_ni) +
1858 sizeof(struct lnet_ioctl_config_lnd_tunables);
1860 len = sizeof(struct lnet_ioctl_config_ni);
1861 data = calloc(1, len);
1863 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1866 conf = (struct lnet_ioctl_config_ni*) data;
1867 if (tunables != NULL)
1868 tun = (struct lnet_ioctl_config_lnd_tunables*)
1869 (data + sizeof(*conf));
1871 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1872 conf->lic_cfg_hdr.ioc_len = len;
1873 strncpy(conf->lic_legacy_ip2nets, ip2net,
1876 if (global_cpts != NULL) {
1877 count = cfs_expr_list_values(global_cpts,
1878 LNET_MAX_SHOW_NUM_CPT,
1881 memcpy(conf->lic_cpts, cpt_array,
1882 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1891 conf->lic_ncpts = count;
1893 if (tunables != NULL)
1894 memcpy(tun, tunables, sizeof(*tunables));
1896 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1901 "\"cannot add network: %s\"", strerror(errno));
1908 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1909 rc = LUSTRE_CFG_RC_NO_ERR;
1913 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1916 "\"cannot parse net '%s'\"",
1917 libcfs_net2str(nw_descr->nw_id));
1918 rc = LUSTRE_CFG_RC_BAD_PARAM;
1923 * special case the GNI since no interface name is expected
1925 if (list_empty(&nw_descr->nw_intflist) &&
1926 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1929 "\"no interface name provided\"");
1930 rc = LUSTRE_CFG_RC_BAD_PARAM;
1934 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1935 err_str, sizeof(err_str));
1937 rc = LUSTRE_CFG_RC_BAD_PARAM;
1941 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1942 tunables, global_cpts, nids,
1946 if (nw_descr != NULL) {
1947 list_for_each_entry_safe(intf_descr, tmp,
1948 &nw_descr->nw_intflist,
1950 list_del(&intf_descr->intf_on_network);
1951 free_intf_descr(intf_descr);
1955 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1966 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1967 int seq_no, struct cYAML **err_rc)
1969 struct lnet_ioctl_config_ni data;
1970 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1971 char err_str[LNET_MAX_STR_LEN];
1972 lnet_nid_t *nids = NULL;
1974 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1976 snprintf(err_str, sizeof(err_str), "\"success\"");
1978 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1981 "\"missing mandatory parameter in deleting NI: '%s'\"",
1982 (nw_descr == NULL) ? "network , interface" :
1983 (nw_descr->nw_id == 0) ? "network" : "interface");
1984 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1988 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1989 return LUSTRE_CFG_RC_NO_ERR;
1991 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1994 "\"cannot parse net '%s'\"",
1995 libcfs_net2str(nw_descr->nw_id));
1996 rc = LUSTRE_CFG_RC_BAD_PARAM;
2000 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2001 err_str, sizeof(err_str));
2003 rc = LUSTRE_CFG_RC_BAD_PARAM;
2008 * no interfaces just the nw_id is specified
2011 nids = calloc(1, sizeof(*nids));
2013 snprintf(err_str, sizeof(err_str),
2014 "\"out of memory\"");
2015 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2018 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2022 for (i = 0; i < nnids; i++) {
2023 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2024 data.lic_nid = nids[i];
2026 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2031 "\"cannot del network: %s\"", strerror(errno));
2035 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2037 list_del(&intf_descr->intf_on_network);
2038 free_intf_descr(intf_descr);
2042 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2051 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2052 enum lnet_health_type type, char *name,
2053 int seq_no, struct cYAML **err_rc)
2055 struct lnet_ioctl_reset_health_cfg data;
2056 int rc = LUSTRE_CFG_RC_NO_ERR;
2057 char err_str[LNET_MAX_STR_LEN];
2059 snprintf(err_str, sizeof(err_str), "\"success\"");
2061 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2062 data.rh_type = type;
2064 data.rh_value = value;
2067 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2071 sizeof(err_str), "Can not configure health value: %s",
2075 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2080 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2081 struct cYAML **err_rc)
2085 nid = libcfs_str2nid(ni_nid);
2088 return lustre_lnet_config_healthv(value, all, nid,
2089 LNET_HEALTH_TYPE_LOCAL_NI,
2090 "ni healthv", seq_no, err_rc);
2093 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2094 int seq_no, struct cYAML **err_rc)
2098 nid = libcfs_str2nid(lpni_nid);
2101 return lustre_lnet_config_healthv(value, all, nid,
2102 LNET_HEALTH_TYPE_PEER_NI,
2103 "peer_ni healthv", seq_no, err_rc);
2107 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2108 struct lnet_ioctl_comm_count *counts)
2110 if (cYAML_create_number(yaml, "put",
2111 counts->ico_put_count)
2114 if (cYAML_create_number(yaml, "get",
2115 counts->ico_get_count)
2118 if (cYAML_create_number(yaml, "reply",
2119 counts->ico_reply_count)
2122 if (cYAML_create_number(yaml, "ack",
2123 counts->ico_ack_count)
2126 if (cYAML_create_number(yaml, "hello",
2127 counts->ico_hello_count)
2134 static struct lnet_ioctl_comm_count *
2135 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2138 return &msg_stats->im_send_stats;
2140 return &msg_stats->im_recv_stats;
2142 return &msg_stats->im_drop_stats;
2147 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2148 struct cYAML **show_rc, struct cYAML **err_rc,
2152 struct lnet_ioctl_config_ni *ni_data;
2153 struct lnet_ioctl_config_lnd_tunables *lnd;
2154 struct lnet_ioctl_element_stats *stats;
2155 struct lnet_ioctl_element_msg_stats msg_stats;
2156 struct lnet_ioctl_local_ni_hstats hstats;
2157 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2158 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2159 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2161 struct cYAML *root = NULL, *tunables = NULL,
2162 *net_node = NULL, *interfaces = NULL,
2163 *item = NULL, *first_seq = NULL,
2164 *tmp = NULL, *statistics = NULL,
2166 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2167 char str_buf[str_buf_len];
2169 char err_str[LNET_MAX_STR_LEN];
2170 bool exist = false, new_net = true;
2172 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2174 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2176 buf = calloc(1, buf_size);
2180 ni_data = (struct lnet_ioctl_config_ni *)buf;
2183 net = libcfs_str2net(nw);
2184 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2187 "\"cannot parse net '%s'\"", nw);
2188 rc = LUSTRE_CFG_RC_BAD_PARAM;
2193 root = cYAML_create_object(NULL, NULL);
2197 net_node = cYAML_create_seq(root, "net");
2198 if (net_node == NULL)
2205 memset(buf, 0, buf_size);
2207 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2209 * set the ioc_len to the proper value since INIT assumes
2212 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2213 ni_data->lic_idx = i;
2215 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2221 rc_net = LNET_NIDNET(ni_data->lic_nid);
2223 /* filter on provided data */
2224 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2228 /* if we're backing up don't store lo */
2229 if (backup && LNET_NETTYP(rc_net) == LOLND)
2232 /* default rc to -1 in case we hit the goto */
2236 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2237 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2238 (ni_data->lic_bulk + sizeof(*stats));
2240 if (rc_net != prev_net) {
2247 if (!cYAML_create_string(net_node, "net type",
2248 libcfs_net2str(rc_net)))
2251 tmp = cYAML_create_seq(net_node, "local NI(s)");
2257 /* create the tree to be printed. */
2258 item = cYAML_create_seq_item(tmp);
2262 if (first_seq == NULL)
2266 cYAML_create_string(item, "nid",
2267 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2271 cYAML_create_string(item,
2273 (ni_data->lic_status ==
2274 LNET_NI_STATUS_UP) ?
2275 "up" : "down") == NULL)
2278 /* don't add interfaces unless there is at least one
2280 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2281 interfaces = cYAML_create_object(item, "interfaces");
2282 if (interfaces == NULL)
2285 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2286 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2288 sizeof(str_buf), "%d", j);
2289 if (cYAML_create_string(interfaces,
2291 ni_data->lic_ni_intf[j]) ==
2303 goto continue_without_msg_stats;
2305 statistics = cYAML_create_object(item, "statistics");
2306 if (statistics == NULL)
2309 if (cYAML_create_number(statistics, "send_count",
2310 stats->iel_send_count)
2314 if (cYAML_create_number(statistics, "recv_count",
2315 stats->iel_recv_count)
2319 if (cYAML_create_number(statistics, "drop_count",
2320 stats->iel_drop_count)
2325 goto continue_without_msg_stats;
2327 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2328 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2329 msg_stats.im_idx = i;
2331 rc = l_ioctl(LNET_DEV_ID,
2332 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2336 goto continue_without_msg_stats;
2339 for (k = 0; k < 3; k++) {
2340 struct lnet_ioctl_comm_count *counts;
2341 struct cYAML *msg_statistics = NULL;
2343 msg_statistics = cYAML_create_object(item,
2344 (char *)gmsg_stat_names[k]);
2345 if (msg_statistics == NULL)
2348 counts = get_counts(&msg_stats, k);
2352 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2357 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2358 hstats.hlni_nid = ni_data->lic_nid;
2359 /* grab health stats */
2360 rc = l_ioctl(LNET_DEV_ID,
2361 IOC_LIBCFS_GET_LOCAL_HSTATS,
2365 goto continue_without_msg_stats;
2367 yhstats = cYAML_create_object(item, "health stats");
2370 if (cYAML_create_number(yhstats, "health value",
2371 hstats.hlni_health_value)
2374 if (cYAML_create_number(yhstats, "interrupts",
2375 hstats.hlni_local_interrupt)
2378 if (cYAML_create_number(yhstats, "dropped",
2379 hstats.hlni_local_dropped)
2382 if (cYAML_create_number(yhstats, "aborted",
2383 hstats.hlni_local_aborted)
2386 if (cYAML_create_number(yhstats, "no route",
2387 hstats.hlni_local_no_route)
2390 if (cYAML_create_number(yhstats, "timeouts",
2391 hstats.hlni_local_timeout)
2394 if (cYAML_create_number(yhstats, "error",
2395 hstats.hlni_local_error)
2399 continue_without_msg_stats:
2400 tunables = cYAML_create_object(item, "tunables");
2404 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2405 if (rc != LUSTRE_CFG_RC_NO_ERR)
2408 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2410 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2411 rc != LUSTRE_CFG_RC_NO_MATCH)
2414 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2415 tunables = cYAML_create_object(item,
2417 if (tunables == NULL)
2422 cYAML_create_number(item, "dev cpt",
2423 ni_data->lic_dev_cpt) == NULL)
2427 cYAML_create_number(item, "tcp bonding",
2428 ni_data->lic_tcp_bonding)
2432 /* out put the CPTs in the format: "[x,x,x,...]" */
2433 limit = str_buf + str_buf_len - 3;
2434 pos += snprintf(pos, limit - pos, "\"[");
2435 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2436 j < ni_data->lic_ncpts &&
2438 pos += snprintf(pos, limit - pos,
2439 "%d", ni_data->lic_cpts[j]);
2440 if ((j + 1) < ni_data->lic_ncpts)
2441 pos += snprintf(pos, limit - pos, ",");
2443 pos += snprintf(pos, 3, "]\"");
2445 if (ni_data->lic_ncpts >= 1 &&
2446 cYAML_create_string(item, "CPT",
2452 /* Print out the net information only if show_rc is not provided */
2453 if (show_rc == NULL)
2454 cYAML_print_tree(root);
2456 if (l_errno != ENOENT) {
2459 "\"cannot get networks: %s\"",
2464 rc = LUSTRE_CFG_RC_NO_ERR;
2466 snprintf(err_str, sizeof(err_str), "\"success\"");
2468 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2469 cYAML_free_tree(root);
2470 } else if (show_rc != NULL && *show_rc != NULL) {
2471 struct cYAML *show_node;
2472 /* find the net node, if one doesn't exist
2473 * then insert one. Otherwise add to the one there
2475 show_node = cYAML_get_object_item(*show_rc, "net");
2476 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2477 cYAML_insert_child(show_node, first_seq);
2480 } else if (show_node == NULL) {
2481 cYAML_insert_sibling((*show_rc)->cy_child,
2485 cYAML_free_tree(root);
2491 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2496 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2498 struct lnet_ioctl_config_data data;
2499 int rc = LUSTRE_CFG_RC_NO_ERR;
2500 char err_str[LNET_MAX_STR_LEN];
2502 snprintf(err_str, sizeof(err_str), "\"success\"");
2504 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2505 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2507 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2512 "\"cannot %s routing %s\"",
2513 (enable) ? "enable" : "disable", strerror(errno));
2518 cYAML_build_error(rc, seq_no,
2519 (enable) ? ADD_CMD : DEL_CMD,
2520 "routing", err_str, err_rc);
2525 int ioctl_set_value(__u32 val, int ioc, char *name,
2526 int seq_no, struct cYAML **err_rc)
2528 struct lnet_ioctl_set_value data;
2529 int rc = LUSTRE_CFG_RC_NO_ERR;
2530 char err_str[LNET_MAX_STR_LEN];
2532 snprintf(err_str, sizeof(err_str), "\"success\"");
2534 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2535 data.sv_value = val;
2537 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2542 "\"cannot configure %s to %d: %s\"", name,
2543 val, strerror(errno));
2546 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2551 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2553 int rc = LUSTRE_CFG_RC_NO_ERR;
2554 char err_str[LNET_MAX_STR_LEN];
2555 char val[LNET_MAX_STR_LEN];
2557 snprintf(err_str, sizeof(err_str), "\"success\"");
2559 snprintf(val, sizeof(val), "%d", intrv);
2561 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2562 1, strlen(val) + 1);
2564 snprintf(err_str, sizeof(err_str),
2565 "\"cannot configure recovery interval: %s\"",
2568 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2573 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2575 int rc = LUSTRE_CFG_RC_NO_ERR;
2576 char err_str[LNET_MAX_STR_LEN];
2577 char val[LNET_MAX_STR_LEN];
2579 snprintf(err_str, sizeof(err_str), "\"success\"");
2581 snprintf(val, sizeof(val), "%d", sen);
2583 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2584 1, strlen(val) + 1);
2586 snprintf(err_str, sizeof(err_str),
2587 "\"cannot configure health sensitivity: %s\"",
2590 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2595 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2597 int rc = LUSTRE_CFG_RC_NO_ERR;
2598 char err_str[LNET_MAX_STR_LEN];
2599 char val[LNET_MAX_STR_LEN];
2601 snprintf(err_str, sizeof(err_str), "\"success\"");
2603 snprintf(val, sizeof(val), "%d", timeout);
2605 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2606 1, strlen(val) + 1);
2608 snprintf(err_str, sizeof(err_str),
2609 "\"cannot configure transaction timeout: %s\"",
2612 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2617 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2619 int rc = LUSTRE_CFG_RC_NO_ERR;
2620 char err_str[LNET_MAX_STR_LEN];
2621 char val[LNET_MAX_STR_LEN];
2623 snprintf(err_str, sizeof(err_str), "\"success\"");
2625 snprintf(val, sizeof(val), "%d", count);
2627 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2628 1, strlen(val) + 1);
2630 snprintf(err_str, sizeof(err_str),
2631 "\"cannot configure retry count: %s\"",
2634 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2639 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2641 int rc = LUSTRE_CFG_RC_NO_ERR;
2642 char err_str[LNET_MAX_STR_LEN];
2643 char val[LNET_MAX_STR_LEN];
2645 snprintf(err_str, sizeof(err_str), "\"success\"");
2647 snprintf(val, sizeof(val), "%d", max);
2649 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2650 1, strlen(val) + 1);
2652 snprintf(err_str, sizeof(err_str),
2653 "\"cannot configure max interfaces: %s\"",
2656 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2661 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2663 int rc = LUSTRE_CFG_RC_NO_ERR;
2664 char err_str[LNET_MAX_STR_LEN];
2665 char val[LNET_MAX_STR_LEN];
2667 snprintf(err_str, sizeof(err_str), "\"success\"");
2669 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2671 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2672 1, strlen(val) + 1);
2674 snprintf(err_str, sizeof(err_str),
2675 "\"cannot configure discovery: %s\"",
2678 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2684 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2685 struct cYAML **err_rc)
2687 int rc = LUSTRE_CFG_RC_NO_ERR;
2688 char err_str[LNET_MAX_STR_LEN];
2689 char val[LNET_MAX_STR_LEN];
2691 snprintf(err_str, sizeof(err_str), "\"success\"");
2693 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2695 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2696 1, strlen(val) + 1);
2698 snprintf(err_str, sizeof(err_str),
2699 "\"cannot configure drop asym route: %s\"",
2702 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2709 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2711 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2712 "numa_range", seq_no, err_rc);
2715 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2716 struct cYAML **err_rc)
2718 struct lnet_ioctl_config_data data;
2719 int rc = LUSTRE_CFG_RC_NO_ERR;
2720 char err_str[LNET_MAX_STR_LEN];
2722 snprintf(err_str, sizeof(err_str), "\"success\"");
2724 /* -1 indicates to ignore changes to this field */
2725 if (tiny < -1 || small < -1 || large < -1) {
2728 "\"tiny, small and large must be >= 0\"");
2729 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2733 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2734 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2735 data.cfg_config_u.cfg_buffers.buf_small = small;
2736 data.cfg_config_u.cfg_buffers.buf_large = large;
2738 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2743 "\"cannot configure buffers: %s\"", strerror(errno));
2748 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2753 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2754 struct cYAML **err_rc, bool backup)
2756 struct lnet_ioctl_config_data *data;
2757 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2758 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2761 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2762 int buf_count[LNET_NRBPOOLS] = {0};
2763 struct cYAML *root = NULL, *pools_node = NULL,
2764 *type_node = NULL, *item = NULL, *cpt = NULL,
2765 *first_seq = NULL, *buffers = NULL;
2767 char err_str[LNET_MAX_STR_LEN];
2768 char node_name[LNET_MAX_STR_LEN];
2771 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2773 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2777 data = (struct lnet_ioctl_config_data *)buf;
2779 root = cYAML_create_object(NULL, NULL);
2784 pools_node = cYAML_create_object(root, "routing");
2786 pools_node = cYAML_create_seq(root, "routing");
2787 if (pools_node == NULL)
2791 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2792 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2793 sizeof(struct lnet_ioctl_pool_cfg);
2794 data->cfg_count = i;
2796 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2804 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2807 goto calculate_buffers;
2809 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2810 item = cYAML_create_seq_item(pools_node);
2814 if (first_seq == NULL)
2817 cpt = cYAML_create_object(item, node_name);
2822 /* create the tree and print */
2823 for (j = 0; j < LNET_NRBPOOLS; j++) {
2825 type_node = cYAML_create_object(cpt, pools[j]);
2826 if (type_node == NULL)
2830 cYAML_create_number(type_node, "npages",
2831 pool_cfg->pl_pools[j].pl_npages)
2835 cYAML_create_number(type_node, "nbuffers",
2836 pool_cfg->pl_pools[j].
2837 pl_nbuffers) == NULL)
2840 cYAML_create_number(type_node, "credits",
2841 pool_cfg->pl_pools[j].
2842 pl_credits) == NULL)
2845 cYAML_create_number(type_node, "mincredits",
2846 pool_cfg->pl_pools[j].
2847 pl_mincredits) == NULL)
2849 /* keep track of the total count for each of the
2850 * tiny, small and large buffers */
2851 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2855 if (pool_cfg != NULL) {
2857 if (cYAML_create_number(pools_node, "enable",
2858 pool_cfg->pl_routing) ==
2862 goto add_buffer_section;
2865 item = cYAML_create_seq_item(pools_node);
2869 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2875 /* create a buffers entry in the show. This is necessary so that
2876 * if the YAML output is used to configure a node, the buffer
2877 * configuration takes hold */
2878 buffers = cYAML_create_object(root, "buffers");
2879 if (buffers == NULL)
2882 for (i = 0; i < LNET_NRBPOOLS; i++) {
2883 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2887 if (show_rc == NULL)
2888 cYAML_print_tree(root);
2890 if (l_errno != ENOENT) {
2893 "\"cannot get routing information: %s\"",
2898 rc = LUSTRE_CFG_RC_NO_ERR;
2900 snprintf(err_str, sizeof(err_str), "\"success\"");
2901 rc = LUSTRE_CFG_RC_NO_ERR;
2905 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2906 cYAML_free_tree(root);
2907 } else if (show_rc != NULL && *show_rc != NULL) {
2908 struct cYAML *routing_node;
2909 /* there should exist only one routing block and one
2910 * buffers block. If there already exists a previous one
2911 * then don't add another */
2912 routing_node = cYAML_get_object_item(*show_rc, "routing");
2913 if (routing_node == NULL) {
2914 cYAML_insert_sibling((*show_rc)->cy_child,
2918 cYAML_free_tree(root);
2924 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2929 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2930 struct cYAML **show_rc, struct cYAML **err_rc,
2934 * TODO: This function is changing in a future patch to accommodate
2935 * PEER_LIST and proper filtering on any nid of the peer
2937 struct lnet_ioctl_peer_cfg peer_info;
2938 struct lnet_peer_ni_credit_info *lpni_cri;
2939 struct lnet_ioctl_element_stats *lpni_stats;
2940 struct lnet_ioctl_element_msg_stats *msg_stats;
2941 struct lnet_ioctl_peer_ni_hstats *hstats;
2943 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2948 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2949 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2950 *msg_statistics = NULL, *statistics = NULL,
2952 char err_str[LNET_MAX_STR_LEN];
2953 struct lnet_process_id *list = NULL;
2958 snprintf(err_str, sizeof(err_str),
2959 "\"out of memory\"");
2961 /* create struct cYAML root object */
2962 root = cYAML_create_object(NULL, NULL);
2966 peer_root = cYAML_create_seq(root, "peer");
2967 if (peer_root == NULL)
2971 size = count * sizeof(struct lnet_process_id);
2972 list = malloc(size);
2978 list[0].nid = libcfs_str2nid(knid);
2982 memset(&peer_info, 0, sizeof(peer_info));
2983 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2984 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2985 peer_info.prcfg_size = size;
2986 peer_info.prcfg_bulk = list;
2989 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2991 count = peer_info.prcfg_count;
2995 if (l_errno != E2BIG) {
2998 "\"cannot get peer list: %s\"",
3004 size = peer_info.prcfg_size;
3005 list = malloc(size);
3014 data = malloc(size);
3020 for (i = 0; i < count; i++) {
3022 memset(&peer_info, 0, sizeof(peer_info));
3023 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3024 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3025 peer_info.prcfg_prim_nid = list[i].nid;
3026 peer_info.prcfg_size = size;
3027 peer_info.prcfg_bulk = data;
3030 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3035 if (l_errno != E2BIG) {
3038 "\"cannot get peer information: %s\"",
3044 size = peer_info.prcfg_size;
3045 data = malloc(size);
3053 peer = cYAML_create_seq_item(peer_root);
3057 if (first_seq == NULL)
3060 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3061 if (cYAML_create_string(peer, "primary nid",
3062 libcfs_nid2str(pnid))
3065 if (cYAML_create_string(peer, "Multi-Rail",
3066 peer_info.prcfg_mr ? "True" : "False")
3070 * print out the state of the peer only if details are
3075 cYAML_create_number(peer, "peer state",
3076 peer_info.prcfg_state)
3081 tmp = cYAML_create_seq(peer, "peer ni");
3086 for (j = 0; j < peer_info.prcfg_count; j++) {
3088 lpni_cri = (void*)nidp + sizeof(nidp);
3089 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3090 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3091 hstats = (void *)msg_stats + sizeof(*msg_stats);
3092 lpni_data = (void *)hstats + sizeof(*hstats);
3094 peer_ni = cYAML_create_seq_item(tmp);
3095 if (peer_ni == NULL)
3098 if (cYAML_create_string(peer_ni, "nid",
3099 libcfs_nid2str(*nidp))
3106 if (cYAML_create_string(peer_ni, "state",
3107 lpni_cri->cr_aliveness)
3114 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3115 lpni_cri->cr_ni_peer_tx_credits)
3119 if (cYAML_create_number(peer_ni, "available_tx_credits",
3120 lpni_cri->cr_peer_tx_credits)
3124 if (cYAML_create_number(peer_ni, "min_tx_credits",
3125 lpni_cri->cr_peer_min_tx_credits)
3129 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3130 lpni_cri->cr_peer_tx_qnob)
3134 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3135 lpni_cri->cr_peer_rtr_credits)
3139 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3140 lpni_cri->cr_peer_min_rtr_credits)
3144 if (cYAML_create_number(peer_ni, "refcount",
3145 lpni_cri->cr_refcount) == NULL)
3148 statistics = cYAML_create_object(peer_ni, "statistics");
3149 if (statistics == NULL)
3152 if (cYAML_create_number(statistics, "send_count",
3153 lpni_stats->iel_send_count)
3157 if (cYAML_create_number(statistics, "recv_count",
3158 lpni_stats->iel_recv_count)
3162 if (cYAML_create_number(statistics, "drop_count",
3163 lpni_stats->iel_drop_count)
3170 for (k = 0; k < 3; k++) {
3171 struct lnet_ioctl_comm_count *counts;
3173 msg_statistics = cYAML_create_object(peer_ni,
3174 (char *) gmsg_stat_names[k]);
3175 if (msg_statistics == NULL)
3178 counts = get_counts(msg_stats, k);
3182 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3187 yhstats = cYAML_create_object(peer_ni, "health stats");
3190 if (cYAML_create_number(yhstats, "health value",
3191 hstats->hlpni_health_value)
3194 if (cYAML_create_number(yhstats, "dropped",
3195 hstats->hlpni_remote_dropped)
3198 if (cYAML_create_number(yhstats, "timeout",
3199 hstats->hlpni_remote_timeout)
3202 if (cYAML_create_number(yhstats, "error",
3203 hstats->hlpni_remote_error)
3206 if (cYAML_create_number(yhstats, "network timeout",
3207 hstats->hlpni_network_timeout)
3213 /* print output iff show_rc is not provided */
3214 if (show_rc == NULL)
3215 cYAML_print_tree(root);
3217 snprintf(err_str, sizeof(err_str), "\"success\"");
3218 rc = LUSTRE_CFG_RC_NO_ERR;
3223 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3224 cYAML_free_tree(root);
3225 } else if (show_rc != NULL && *show_rc != NULL) {
3226 struct cYAML *show_node;
3227 /* find the peer node, if one doesn't exist then
3228 * insert one. Otherwise add to the one there
3230 show_node = cYAML_get_object_item(*show_rc,
3232 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3233 cYAML_insert_child(show_node, first_seq);
3236 } else if (show_node == NULL) {
3237 cYAML_insert_sibling((*show_rc)->cy_child,
3241 cYAML_free_tree(root);
3247 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3253 int lustre_lnet_list_peer(int seq_no,
3254 struct cYAML **show_rc, struct cYAML **err_rc)
3256 struct lnet_ioctl_peer_cfg peer_info;
3257 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3262 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3263 char err_str[LNET_MAX_STR_LEN];
3264 struct lnet_process_id *list = NULL;
3266 snprintf(err_str, sizeof(err_str),
3267 "\"out of memory\"");
3269 memset(&peer_info, 0, sizeof(peer_info));
3271 /* create struct cYAML root object */
3272 root = cYAML_create_object(NULL, NULL);
3276 list_root = cYAML_create_seq(root, "peer list");
3277 if (list_root == NULL)
3281 size = count * sizeof(struct lnet_process_id);
3282 list = malloc(size);
3288 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3289 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3290 peer_info.prcfg_size = size;
3291 peer_info.prcfg_bulk = list;
3294 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3295 count = peer_info.prcfg_count;
3299 if (l_errno != E2BIG) {
3302 "\"cannot get peer list: %s\"",
3308 size = peer_info.prcfg_size;
3309 list = malloc(size);
3316 /* count is now the actual number of ids in the list. */
3317 for (i = 0; i < count; i++) {
3318 if (cYAML_create_string(list_root, "nid",
3319 libcfs_nid2str(list[i].nid))
3324 /* print output iff show_rc is not provided */
3325 if (show_rc == NULL)
3326 cYAML_print_tree(root);
3328 snprintf(err_str, sizeof(err_str), "\"success\"");
3329 rc = LUSTRE_CFG_RC_NO_ERR;
3334 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3335 cYAML_free_tree(root);
3336 } else if (show_rc != NULL && *show_rc != NULL) {
3337 struct cYAML *show_node;
3338 /* find the peer node, if one doesn't exist then
3339 * insert one. Otherwise add to the one there
3341 show_node = cYAML_get_object_item(*show_rc,
3343 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3344 cYAML_insert_child(show_node, first_seq);
3347 } else if (show_node == NULL) {
3348 cYAML_insert_sibling((*show_rc)->cy_child,
3352 cYAML_free_tree(root);
3358 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3364 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3367 struct cYAML *show_node;
3369 show_node = cYAML_get_object_item(show_rc, "global");
3370 if (show_node != NULL)
3371 cYAML_insert_sibling(show_node->cy_child,
3374 cYAML_insert_sibling(show_rc->cy_child,
3379 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3380 char *name, __u32 value,
3381 struct cYAML **show_rc,
3382 struct cYAML **err_rc, int err)
3384 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3385 struct cYAML *root = NULL, *global = NULL;
3392 root = cYAML_create_object(NULL, NULL);
3396 global = cYAML_create_object(root, "global");
3400 if (cYAML_create_number(global, name,
3404 if (show_rc == NULL)
3405 cYAML_print_tree(root);
3407 snprintf(err_str, err_len, "\"success\"");
3409 rc = LUSTRE_CFG_RC_NO_ERR;
3412 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3413 cYAML_free_tree(root);
3414 } else if (show_rc != NULL && *show_rc != NULL) {
3415 add_to_global(*show_rc, global, root);
3420 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3425 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3426 struct cYAML **show_rc,
3427 struct cYAML **err_rc)
3429 struct lnet_ioctl_set_value data;
3432 char err_str[LNET_MAX_STR_LEN];
3434 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3436 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3438 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3443 "\"cannot get %s: %s\"",
3444 name, strerror(l_errno));
3447 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3448 data.sv_value, show_rc, err_rc, l_errno);
3451 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3452 struct cYAML **err_rc)
3454 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3455 char val[LNET_MAX_STR_LEN];
3456 int intrv = -1, l_errno = 0;
3457 char err_str[LNET_MAX_STR_LEN];
3459 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3461 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3465 snprintf(err_str, sizeof(err_str),
3466 "\"cannot get recovery interval: %d\"", rc);
3471 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3472 "recovery_interval", intrv, show_rc,
3476 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3477 struct cYAML **err_rc)
3479 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3480 char val[LNET_MAX_STR_LEN];
3481 int sen = -1, l_errno = 0;
3482 char err_str[LNET_MAX_STR_LEN];
3484 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3486 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3490 snprintf(err_str, sizeof(err_str),
3491 "\"cannot get health sensitivity: %d\"", rc);
3496 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3497 "health_sensitivity", sen, show_rc,
3501 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3502 struct cYAML **err_rc)
3504 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3505 char val[LNET_MAX_STR_LEN];
3506 int tto = -1, l_errno = 0;
3507 char err_str[LNET_MAX_STR_LEN];
3509 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3511 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3515 snprintf(err_str, sizeof(err_str),
3516 "\"cannot get transaction timeout: %d\"", rc);
3521 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3522 "transaction_timeout", tto, show_rc,
3526 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3527 struct cYAML **err_rc)
3529 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3530 char val[LNET_MAX_STR_LEN];
3531 int retry_count = -1, l_errno = 0;
3532 char err_str[LNET_MAX_STR_LEN];
3534 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3536 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3540 snprintf(err_str, sizeof(err_str),
3541 "\"cannot get retry count: %d\"", rc);
3543 retry_count = atoi(val);
3546 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3547 "retry_count", retry_count, show_rc,
3551 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3552 struct cYAML **show_rc, struct cYAML **err_rc)
3554 struct lnet_ioctl_recovery_list nid_list;
3555 struct cYAML *root = NULL, *nids = NULL;
3557 char err_str[LNET_MAX_STR_LEN];
3559 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3561 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3562 nid_list.rlst_type = type;
3564 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3570 if (nid_list.rlst_num_nids == 0)
3573 root = cYAML_create_object(NULL, NULL);
3577 nids = cYAML_create_object(root, name);
3583 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3584 char nidenum[LNET_MAX_STR_LEN];
3585 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3586 if (!cYAML_create_string(nids, nidenum,
3587 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3591 snprintf(err_str, sizeof(err_str), "success\n");
3596 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3597 cYAML_free_tree(root);
3598 } else if (show_rc != NULL && *show_rc != NULL) {
3599 struct cYAML *show_node;
3600 /* find the net node, if one doesn't exist
3601 * then insert one. Otherwise add to the one there
3603 show_node = cYAML_get_object_item(*show_rc, name);
3604 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3605 cYAML_insert_child(show_node, nids);
3608 } else if (show_node == NULL) {
3609 cYAML_insert_sibling((*show_rc)->cy_child,
3613 cYAML_free_tree(root);
3619 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3624 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3625 struct cYAML **err_rc)
3627 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3628 seq_no, show_rc, err_rc);
3631 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3632 struct cYAML **err_rc)
3634 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3635 seq_no, show_rc, err_rc);
3638 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3639 struct cYAML **err_rc)
3641 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3642 char val[LNET_MAX_STR_LEN];
3643 int max_intf = -1, l_errno = 0;
3644 char err_str[LNET_MAX_STR_LEN];
3646 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3648 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3652 snprintf(err_str, sizeof(err_str),
3653 "\"cannot get max interfaces: %d\"", rc);
3655 max_intf = atoi(val);
3658 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3659 "max_intf", max_intf, show_rc,
3663 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3664 struct cYAML **err_rc)
3666 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3667 char val[LNET_MAX_STR_LEN];
3668 int discovery = -1, l_errno = 0;
3669 char err_str[LNET_MAX_STR_LEN];
3671 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3673 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3677 snprintf(err_str, sizeof(err_str),
3678 "\"cannot get discovery setting: %d\"", rc);
3681 * The kernel stores a discovery disabled value. User space
3682 * shows whether discovery is enabled. So the value must be
3685 discovery = !atoi(val);
3688 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3689 "discovery", discovery, show_rc,
3693 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3694 struct cYAML **err_rc)
3696 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3697 char val[LNET_MAX_STR_LEN];
3698 int drop_asym_route = -1, l_errno = 0;
3699 char err_str[LNET_MAX_STR_LEN];
3701 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3703 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3707 snprintf(err_str, sizeof(err_str),
3708 "\"cannot get drop asym route setting: %d\"", rc);
3710 drop_asym_route = atoi(val);
3713 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3714 "drop_asym_route", drop_asym_route,
3715 show_rc, err_rc, l_errno);
3718 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3719 struct cYAML **err_rc)
3721 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3722 "numa_range", show_rc, err_rc);
3725 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3726 struct cYAML **err_rc)
3728 struct lnet_ioctl_lnet_stats data;
3729 struct lnet_counters *cntrs;
3732 char err_str[LNET_MAX_STR_LEN];
3733 struct cYAML *root = NULL, *stats = NULL;
3735 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3737 LIBCFS_IOC_INIT_V2(data, st_hdr);
3739 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3744 "\"cannot get lnet statistics: %s\"",
3750 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3752 cntrs = &data.st_cntrs;
3754 root = cYAML_create_object(NULL, NULL);
3758 stats = cYAML_create_object(root, "statistics");
3762 if (!cYAML_create_number(stats, "msgs_alloc",
3763 cntrs->lct_common.lcc_msgs_alloc))
3766 if (!cYAML_create_number(stats, "msgs_max",
3767 cntrs->lct_common.lcc_msgs_max))
3770 if (!cYAML_create_number(stats, "rst_alloc",
3771 cntrs->lct_health.lch_rst_alloc))
3774 if (!cYAML_create_number(stats, "errors",
3775 cntrs->lct_common.lcc_errors))
3778 if (!cYAML_create_number(stats, "send_count",
3779 cntrs->lct_common.lcc_send_count))
3782 if (!cYAML_create_number(stats, "resend_count",
3783 cntrs->lct_health.lch_resend_count))
3786 if (!cYAML_create_number(stats, "response_timeout_count",
3787 cntrs->lct_health.lch_response_timeout_count))
3790 if (!cYAML_create_number(stats, "local_interrupt_count",
3791 cntrs->lct_health.lch_local_interrupt_count))
3794 if (!cYAML_create_number(stats, "local_dropped_count",
3795 cntrs->lct_health.lch_local_dropped_count))
3798 if (!cYAML_create_number(stats, "local_aborted_count",
3799 cntrs->lct_health.lch_local_aborted_count))
3802 if (!cYAML_create_number(stats, "local_no_route_count",
3803 cntrs->lct_health.lch_local_no_route_count))
3806 if (!cYAML_create_number(stats, "local_timeout_count",
3807 cntrs->lct_health.lch_local_timeout_count))
3810 if (!cYAML_create_number(stats, "local_error_count",
3811 cntrs->lct_health.lch_local_error_count))
3814 if (!cYAML_create_number(stats, "remote_dropped_count",
3815 cntrs->lct_health.lch_remote_dropped_count))
3818 if (!cYAML_create_number(stats, "remote_error_count",
3819 cntrs->lct_health.lch_remote_error_count))
3822 if (!cYAML_create_number(stats, "remote_timeout_count",
3823 cntrs->lct_health.lch_remote_timeout_count))
3826 if (!cYAML_create_number(stats, "network_timeout_count",
3827 cntrs->lct_health.lch_network_timeout_count))
3830 if (!cYAML_create_number(stats, "recv_count",
3831 cntrs->lct_common.lcc_recv_count))
3834 if (!cYAML_create_number(stats, "route_count",
3835 cntrs->lct_common.lcc_route_count))
3838 if (!cYAML_create_number(stats, "drop_count",
3839 cntrs->lct_common.lcc_drop_count))
3842 if (!cYAML_create_number(stats, "send_length",
3843 cntrs->lct_common.lcc_send_length))
3846 if (!cYAML_create_number(stats, "recv_length",
3847 cntrs->lct_common.lcc_recv_length))
3850 if (!cYAML_create_number(stats, "route_length",
3851 cntrs->lct_common.lcc_route_length))
3854 if (!cYAML_create_number(stats, "drop_length",
3855 cntrs->lct_common.lcc_drop_length))
3859 cYAML_print_tree(root);
3861 snprintf(err_str, sizeof(err_str), "\"success\"");
3862 rc = LUSTRE_CFG_RC_NO_ERR;
3864 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3865 cYAML_free_tree(root);
3866 } else if (show_rc != NULL && *show_rc != NULL) {
3867 cYAML_insert_sibling((*show_rc)->cy_child,
3874 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3879 typedef int (*cmd_handler_t)(struct cYAML *tree,
3880 struct cYAML **show_rc,
3881 struct cYAML **err_rc);
3883 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3884 struct cYAML **err_rc)
3886 struct cYAML *net, *gw, *hop, *prio, *seq_no;
3888 net = cYAML_get_object_item(tree, "net");
3889 gw = cYAML_get_object_item(tree, "gateway");
3890 hop = cYAML_get_object_item(tree, "hop");
3891 prio = cYAML_get_object_item(tree, "priority");
3892 seq_no = cYAML_get_object_item(tree, "seq_no");
3894 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3895 (gw) ? gw->cy_valuestring : NULL,
3896 (hop) ? hop->cy_valueint : -1,
3897 (prio) ? prio->cy_valueint : -1,
3898 (seq_no) ? seq_no->cy_valueint : -1,
3902 static void yaml_free_string_array(char **array, int num)
3905 char **sub_array = array;
3907 for (i = 0; i < num; i++) {
3908 if (*sub_array != NULL)
3918 * 0: <intf_name>['['<expr>']']
3919 * 1: <intf_name>['['<expr>']']
3921 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3922 struct lnet_dlc_network_descr *nw_descr)
3924 struct cYAML *child = NULL;
3925 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3926 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3928 if (intf_tree == NULL || nw_descr == NULL)
3929 return LUSTRE_CFG_RC_BAD_PARAM;
3931 /* now grab all the interfaces and their cpts */
3932 child = intf_tree->cy_child;
3933 while (child != NULL) {
3934 if (child->cy_valuestring == NULL) {
3935 child = child->cy_next;
3939 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3942 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3943 child->cy_valuestring,
3944 strlen(child->cy_valuestring));
3945 if (rc != LUSTRE_CFG_RC_NO_ERR)
3949 child = child->cy_next;
3953 return LUSTRE_CFG_RC_MISSING_PARAM;
3958 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3960 list_del(&intf_descr->intf_on_network);
3961 free_intf_descr(intf_descr);
3968 yaml_extract_cmn_tunables(struct cYAML *tree,
3969 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3970 struct cfs_expr_list **global_cpts)
3972 struct cYAML *tun, *item, *smp;
3975 tun = cYAML_get_object_item(tree, "tunables");
3977 item = cYAML_get_object_item(tun, "peer_timeout");
3979 tunables->lct_peer_timeout = item->cy_valueint;
3980 item = cYAML_get_object_item(tun, "peer_credits");
3982 tunables->lct_peer_tx_credits = item->cy_valueint;
3983 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3985 tunables->lct_peer_rtr_credits = item->cy_valueint;
3986 item = cYAML_get_object_item(tun, "credits");
3988 tunables->lct_max_tx_credits = item->cy_valueint;
3989 smp = cYAML_get_object_item(tun, "CPT");
3991 rc = cfs_expr_list_parse(smp->cy_valuestring,
3992 strlen(smp->cy_valuestring),
3993 0, UINT_MAX, global_cpts);
3995 *global_cpts = NULL;
4005 yaml_extract_tunables(struct cYAML *tree,
4006 struct lnet_ioctl_config_lnd_tunables *tunables,
4007 struct cfs_expr_list **global_cpts,
4012 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4018 lustre_yaml_extract_lnd_tunables(tree, net_type,
4026 * - net type: <net>[<NUM>]
4028 * - nid: <ip>@<net>[<NUM>]
4031 * 0: <intf_name>['['<expr>']']
4032 * 1: <intf_name>['['<expr>']']
4034 * peer_timeout: <NUM>
4035 * peer_credits: <NUM>
4036 * peer_buffer_credits: <NUM>
4039 * peercredits_hiw: <NUM>
4040 * map_on_demand: <NUM>
4041 * concurrent_sends: <NUM>
4042 * fmr_pool_size: <NUM>
4043 * fmr_flush_trigger: <NUM>
4046 * At least one interface is required. If no interfaces are provided the
4047 * network interface can not be configured.
4049 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4050 struct cYAML **err_rc)
4052 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4054 int num_entries = 0, rc;
4055 struct lnet_dlc_network_descr nw_descr;
4056 struct cfs_expr_list *global_cpts = NULL;
4057 struct lnet_ioctl_config_lnd_tunables tunables;
4060 memset(&tunables, 0, sizeof(tunables));
4062 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4063 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4065 ip2net = cYAML_get_object_item(tree, "ip2net");
4066 net = cYAML_get_object_item(tree, "net type");
4068 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4070 nw_descr.nw_id = LOLND;
4073 * if neither net nor ip2nets are present, then we can not
4074 * configure the network.
4076 if (!net && !ip2net)
4077 return LUSTRE_CFG_RC_MISSING_PARAM;
4079 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4080 if (local_nis == NULL)
4081 return LUSTRE_CFG_RC_MISSING_PARAM;
4083 if (!cYAML_is_sequence(local_nis))
4084 return LUSTRE_CFG_RC_BAD_PARAM;
4086 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4087 intf = cYAML_get_object_item(item, "interfaces");
4090 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4091 if (num_entries <= 0) {
4092 cYAML_build_error(num_entries, -1, "ni", "add",
4093 "bad interface list",
4095 return LUSTRE_CFG_RC_BAD_PARAM;
4099 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4100 LNET_NETTYP(nw_descr.nw_id));
4101 seq_no = cYAML_get_object_item(tree, "seq_no");
4103 rc = lustre_lnet_config_ni(&nw_descr,
4105 (ip2net) ? ip2net->cy_valuestring : NULL,
4106 (found) ? &tunables: NULL,
4107 (seq_no) ? seq_no->cy_valueint : -1,
4110 if (global_cpts != NULL)
4111 cfs_expr_list_free(global_cpts);
4118 * - net-spec: <tcp|o2ib|gni>[NUM]
4120 * 0: <intf name>['['<expr>']']
4121 * 1: <intf name>['['<expr>']']
4123 * 0: <expr.expr.expr.expr>
4124 * 1: <expr.expr.expr.expr>
4126 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4127 struct cYAML **show_rc,
4128 struct cYAML **err_rc)
4130 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4132 struct lustre_lnet_ip2nets ip2nets;
4133 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4135 int rc = LUSTRE_CFG_RC_NO_ERR;
4136 struct cfs_expr_list *global_cpts = NULL;
4137 struct cfs_expr_list *el, *el_tmp;
4138 struct lnet_ioctl_config_lnd_tunables tunables;
4139 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4142 memset(&tunables, 0, sizeof(tunables));
4144 /* initialize all lists */
4145 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4146 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4147 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4149 net = cYAML_get_object_item(tree, "net-spec");
4151 return LUSTRE_CFG_RC_BAD_PARAM;
4153 if (net != NULL && net->cy_valuestring == NULL)
4154 return LUSTRE_CFG_RC_BAD_PARAM;
4156 /* assign the network id */
4157 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4158 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4159 return LUSTRE_CFG_RC_BAD_PARAM;
4161 seq_no = cYAML_get_object_item(tree, "seq_no");
4163 intf = cYAML_get_object_item(tree, "interfaces");
4165 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4167 return LUSTRE_CFG_RC_BAD_PARAM;
4170 ip_range = cYAML_get_object_item(tree, "ip-range");
4171 if (ip_range != NULL) {
4172 item = ip_range->cy_child;
4173 while (item != NULL) {
4174 if (item->cy_valuestring == NULL) {
4175 item = item->cy_next;
4179 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4180 item->cy_valuestring);
4182 if (rc != LUSTRE_CFG_RC_NO_ERR)
4185 item = item->cy_next;
4189 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4190 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4192 rc = lustre_lnet_config_ip2nets(&ip2nets,
4193 (found) ? &tunables : NULL,
4195 (seq_no) ? seq_no->cy_valueint : -1,
4199 * don't stop because there was no match. Continue processing the
4200 * rest of the rules. If non-match then nothing is configured
4202 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4203 rc = LUSTRE_CFG_RC_NO_ERR;
4205 list_for_each_entry_safe(intf_descr, intf_tmp,
4206 &ip2nets.ip2nets_net.nw_intflist,
4208 list_del(&intf_descr->intf_on_network);
4209 free_intf_descr(intf_descr);
4212 list_for_each_entry_safe(ip_range_descr, tmp,
4213 &ip2nets.ip2nets_ip_ranges,
4215 list_del(&ip_range_descr->ipr_entry);
4216 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4218 list_del(&el->el_link);
4219 cfs_expr_list_free(el);
4221 free(ip_range_descr);
4227 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4228 struct cYAML **err_rc)
4230 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4232 int num_entries, rc;
4233 struct lnet_dlc_network_descr nw_descr;
4235 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4236 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4238 net = cYAML_get_object_item(tree, "net type");
4240 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4242 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4243 if (local_nis == NULL)
4244 return LUSTRE_CFG_RC_MISSING_PARAM;
4246 if (!cYAML_is_sequence(local_nis))
4247 return LUSTRE_CFG_RC_BAD_PARAM;
4249 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4250 intf = cYAML_get_object_item(item, "interfaces");
4253 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4254 if (num_entries <= 0) {
4255 cYAML_build_error(num_entries, -1, "ni", "add",
4256 "bad interface list",
4258 return LUSTRE_CFG_RC_BAD_PARAM;
4262 seq_no = cYAML_get_object_item(tree, "seq_no");
4264 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4265 (seq_no) ? seq_no->cy_valueint : -1,
4271 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4272 char *prim_nid, bool del)
4274 struct cYAML *child = NULL, *entry = NULL;
4276 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4278 if (cYAML_is_sequence(nids_entry)) {
4279 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4280 entry = cYAML_get_object_item(child, "nid");
4281 /* don't count an empty entry */
4282 if (!entry || !entry->cy_valuestring)
4286 (strcmp(entry->cy_valuestring, prim_nid)
4289 * primary nid is present in the list of
4290 * nids so that means we want to delete
4291 * the entire peer, so no need to go
4292 * further. Just delete the entire peer.
4302 return LUSTRE_CFG_RC_MISSING_PARAM;
4304 nids = calloc(sizeof(*nids), num);
4306 return LUSTRE_CFG_RC_OUT_OF_MEM;
4308 /* now grab all the nids */
4311 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4312 entry = cYAML_get_object_item(child, "nid");
4313 if (!entry || !entry->cy_valuestring)
4316 nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
4318 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4321 strncpy(nids[num], entry->cy_valuestring,
4322 strlen(entry->cy_valuestring));
4332 yaml_free_string_array(nids, num);
4337 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4338 struct cYAML **err_rc)
4342 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4343 char err_str[LNET_MAX_STR_LEN];
4346 seq_no = cYAML_get_object_item(tree, "seq_no");
4347 prim_nid = cYAML_get_object_item(tree, "primary nid");
4348 mr = cYAML_get_object_item(tree, "Multi-Rail");
4349 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4350 peer_nis = cYAML_get_object_item(tree, "peer ni");
4352 if (ip2nets && (prim_nid || peer_nis)) {
4353 rc = LUSTRE_CFG_RC_BAD_PARAM;
4354 snprintf(err_str, sizeof(err_str),
4355 "ip2nets can not be specified along side prim_nid"
4356 " or peer ni fields");
4357 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4358 ADD_CMD, "peer", err_str, err_rc);
4365 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4367 else if (!strcmp(mr->cy_valuestring, "False"))
4370 rc = LUSTRE_CFG_RC_BAD_PARAM;
4371 snprintf(err_str, sizeof(err_str), "Bad MR value");
4372 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4373 ADD_CMD, "peer", err_str, err_rc);
4378 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4379 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4383 snprintf(err_str, sizeof(err_str),
4384 "error copying nids from YAML block");
4385 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4386 ADD_CMD, "peer", err_str, err_rc);
4390 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4391 nids, num, mr_value,
4392 (ip2nets) ? true : false,
4393 (seq_no) ? seq_no->cy_valueint : -1,
4396 yaml_free_string_array(nids, num);
4400 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4401 struct cYAML **err_rc)
4405 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4406 char err_str[LNET_MAX_STR_LEN];
4408 seq_no = cYAML_get_object_item(tree, "seq_no");
4409 prim_nid = cYAML_get_object_item(tree, "primary nid");
4410 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4411 peer_nis = cYAML_get_object_item(tree, "peer ni");
4413 if (ip2nets && (prim_nid || peer_nis)) {
4414 rc = LUSTRE_CFG_RC_BAD_PARAM;
4415 snprintf(err_str, sizeof(err_str),
4416 "ip2nets can not be specified along side prim_nid"
4417 " or peer ni fields");
4418 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4419 DEL_CMD, "peer", err_str, err_rc);
4423 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4424 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4427 snprintf(err_str, sizeof(err_str),
4428 "error copying nids from YAML block");
4429 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4430 ADD_CMD, "peer", err_str, err_rc);
4434 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4435 nids, num, (ip2nets) ? true : false,
4436 (seq_no) ? seq_no->cy_valueint : -1,
4439 yaml_free_string_array(nids, num);
4443 static int handle_yaml_config_buffers(struct cYAML *tree,
4444 struct cYAML **show_rc,
4445 struct cYAML **err_rc)
4448 struct cYAML *tiny, *small, *large, *seq_no;
4450 tiny = cYAML_get_object_item(tree, "tiny");
4451 small = cYAML_get_object_item(tree, "small");
4452 large = cYAML_get_object_item(tree, "large");
4453 seq_no = cYAML_get_object_item(tree, "seq_no");
4455 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4456 (small) ? small->cy_valueint : -1,
4457 (large) ? large->cy_valueint : -1,
4458 (seq_no) ? seq_no->cy_valueint : -1,
4464 static int handle_yaml_config_routing(struct cYAML *tree,
4465 struct cYAML **show_rc,
4466 struct cYAML **err_rc)
4468 int rc = LUSTRE_CFG_RC_NO_ERR;
4469 struct cYAML *seq_no, *enable;
4471 seq_no = cYAML_get_object_item(tree, "seq_no");
4472 enable = cYAML_get_object_item(tree, "enable");
4475 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4477 seq_no->cy_valueint : -1,
4484 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4485 struct cYAML **err_rc)
4489 struct cYAML *seq_no;
4491 net = cYAML_get_object_item(tree, "net");
4492 gw = cYAML_get_object_item(tree, "gateway");
4493 seq_no = cYAML_get_object_item(tree, "seq_no");
4495 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4496 (gw) ? gw->cy_valuestring : NULL,
4497 (seq_no) ? seq_no->cy_valueint : -1,
4501 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4502 struct cYAML **err_rc)
4504 struct cYAML *seq_no;
4506 seq_no = cYAML_get_object_item(tree, "seq_no");
4508 return lustre_lnet_enable_routing(0, (seq_no) ?
4509 seq_no->cy_valueint : -1,
4513 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4514 struct cYAML **err_rc)
4520 struct cYAML *detail;
4521 struct cYAML *seq_no;
4523 net = cYAML_get_object_item(tree, "net");
4524 gw = cYAML_get_object_item(tree, "gateway");
4525 hop = cYAML_get_object_item(tree, "hop");
4526 prio = cYAML_get_object_item(tree, "priority");
4527 detail = cYAML_get_object_item(tree, "detail");
4528 seq_no = cYAML_get_object_item(tree, "seq_no");
4530 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4531 (gw) ? gw->cy_valuestring : NULL,
4532 (hop) ? hop->cy_valueint : -1,
4533 (prio) ? prio->cy_valueint : -1,
4534 (detail) ? detail->cy_valueint : 0,
4535 (seq_no) ? seq_no->cy_valueint : -1,
4536 show_rc, err_rc, false);
4539 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4540 struct cYAML **err_rc)
4542 struct cYAML *net, *detail, *seq_no;
4544 net = cYAML_get_object_item(tree, "net");
4545 detail = cYAML_get_object_item(tree, "detail");
4546 seq_no = cYAML_get_object_item(tree, "seq_no");
4548 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4549 (detail) ? detail->cy_valueint : 0,
4550 (seq_no) ? seq_no->cy_valueint : -1,
4551 show_rc, err_rc, false);
4554 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4555 struct cYAML **err_rc)
4557 struct cYAML *seq_no;
4559 seq_no = cYAML_get_object_item(tree, "seq_no");
4561 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4562 show_rc, err_rc, false);
4565 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4566 struct cYAML **err_rc)
4568 struct cYAML *seq_no, *nid, *detail;
4570 seq_no = cYAML_get_object_item(tree, "seq_no");
4571 detail = cYAML_get_object_item(tree, "detail");
4572 nid = cYAML_get_object_item(tree, "nid");
4574 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4575 (detail) ? detail->cy_valueint : 0,
4576 (seq_no) ? seq_no->cy_valueint : -1,
4577 show_rc, err_rc, false);
4580 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4581 struct cYAML **err_rc)
4583 struct cYAML *seq_no;
4585 seq_no = cYAML_get_object_item(tree, "seq_no");
4587 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4591 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4592 struct cYAML **err_rc)
4594 struct cYAML *seq_no, *range;
4596 seq_no = cYAML_get_object_item(tree, "seq_no");
4597 range = cYAML_get_object_item(tree, "range");
4599 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4600 seq_no ? seq_no->cy_valueint : -1,
4604 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4605 struct cYAML **err_rc)
4607 struct cYAML *seq_no;
4609 seq_no = cYAML_get_object_item(tree, "seq_no");
4611 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4615 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4616 struct cYAML **err_rc)
4618 struct cYAML *seq_no;
4620 seq_no = cYAML_get_object_item(tree, "seq_no");
4622 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4626 static int handle_yaml_config_global_settings(struct cYAML *tree,
4627 struct cYAML **show_rc,
4628 struct cYAML **err_rc)
4630 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4631 *sen, *recov, *drop_asym_route;
4634 seq_no = cYAML_get_object_item(tree, "seq_no");
4635 max_intf = cYAML_get_object_item(tree, "max_intf");
4637 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4638 seq_no ? seq_no->cy_valueint
4642 numa = cYAML_get_object_item(tree, "numa_range");
4644 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4645 seq_no ? seq_no->cy_valueint
4649 discovery = cYAML_get_object_item(tree, "discovery");
4651 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4652 seq_no ? seq_no->cy_valueint
4656 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4657 if (drop_asym_route)
4658 rc = lustre_lnet_config_drop_asym_route(
4659 drop_asym_route->cy_valueint,
4660 seq_no ? seq_no->cy_valueint : -1,
4663 retry = cYAML_get_object_item(tree, "retry_count");
4665 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4666 seq_no ? seq_no->cy_valueint
4670 tto = cYAML_get_object_item(tree, "transaction_timeout");
4672 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4673 seq_no ? seq_no->cy_valueint
4677 sen = cYAML_get_object_item(tree, "health_sensitivity");
4679 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4680 seq_no ? seq_no->cy_valueint
4684 recov = cYAML_get_object_item(tree, "recovery_interval");
4686 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4687 seq_no ? seq_no->cy_valueint
4694 static int handle_yaml_del_global_settings(struct cYAML *tree,
4695 struct cYAML **show_rc,
4696 struct cYAML **err_rc)
4698 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4701 seq_no = cYAML_get_object_item(tree, "seq_no");
4702 max_intf = cYAML_get_object_item(tree, "max_intf");
4704 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4705 seq_no ? seq_no->cy_valueint
4709 numa = cYAML_get_object_item(tree, "numa_range");
4711 rc = lustre_lnet_config_numa_range(0,
4712 seq_no ? seq_no->cy_valueint
4716 /* peer discovery is enabled by default */
4717 discovery = cYAML_get_object_item(tree, "discovery");
4719 rc = lustre_lnet_config_discovery(1,
4720 seq_no ? seq_no->cy_valueint
4724 /* asymmetrical route messages are accepted by default */
4725 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4726 if (drop_asym_route)
4727 rc = lustre_lnet_config_drop_asym_route(
4728 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4733 static int handle_yaml_show_global_settings(struct cYAML *tree,
4734 struct cYAML **show_rc,
4735 struct cYAML **err_rc)
4737 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4738 *sen, *recov, *drop_asym_route;
4741 seq_no = cYAML_get_object_item(tree, "seq_no");
4742 max_intf = cYAML_get_object_item(tree, "max_intf");
4744 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4748 numa = cYAML_get_object_item(tree, "numa_range");
4750 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4754 discovery = cYAML_get_object_item(tree, "discovery");
4756 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4760 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4761 if (drop_asym_route)
4762 rc = lustre_lnet_show_drop_asym_route(
4763 seq_no ? seq_no->cy_valueint : -1,
4766 retry = cYAML_get_object_item(tree, "retry_count");
4768 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4772 tto = cYAML_get_object_item(tree, "transaction_timeout");
4774 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4778 sen = cYAML_get_object_item(tree, "health_sensitivity");
4780 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4784 recov = cYAML_get_object_item(tree, "recovery_interval");
4786 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4793 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4794 struct cYAML **err_rc)
4796 struct cYAML *seq_no, *nid, *timeout;
4798 seq_no = cYAML_get_object_item(tree, "seq_no");
4799 nid = cYAML_get_object_item(tree, "primary nid");
4800 timeout = cYAML_get_object_item(tree, "timeout");
4802 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4803 (timeout) ? timeout->cy_valueint : 1000,
4804 (seq_no) ? seq_no->cy_valueint : -1,
4808 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4809 struct cYAML **err_rc)
4811 struct cYAML *seq_no, *nid, *force;
4813 seq_no = cYAML_get_object_item(tree, "seq_no");
4814 nid = cYAML_get_object_item(tree, "primary nid");
4815 force = cYAML_get_object_item(tree, "force");
4817 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4818 (force) ? force->cy_valueint : 0,
4819 (seq_no) ? seq_no->cy_valueint : -1,
4823 static int handle_yaml_no_op()
4825 return LUSTRE_CFG_RC_NO_ERR;
4828 struct lookup_cmd_hdlr_tbl {
4833 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4834 { .name = "route", .cb = handle_yaml_config_route },
4835 { .name = "net", .cb = handle_yaml_config_ni },
4836 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4837 { .name = "peer", .cb = handle_yaml_config_peer },
4838 { .name = "routing", .cb = handle_yaml_config_routing },
4839 { .name = "buffers", .cb = handle_yaml_config_buffers },
4840 { .name = "statistics", .cb = handle_yaml_no_op },
4841 { .name = "global", .cb = handle_yaml_config_global_settings},
4842 { .name = "numa", .cb = handle_yaml_config_numa },
4843 { .name = "ping", .cb = handle_yaml_no_op },
4844 { .name = "discover", .cb = handle_yaml_no_op },
4847 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4848 { .name = "route", .cb = handle_yaml_del_route },
4849 { .name = "net", .cb = handle_yaml_del_ni },
4850 { .name = "ip2nets", .cb = handle_yaml_no_op },
4851 { .name = "peer", .cb = handle_yaml_del_peer },
4852 { .name = "routing", .cb = handle_yaml_del_routing },
4853 { .name = "buffers", .cb = handle_yaml_no_op },
4854 { .name = "statistics", .cb = handle_yaml_no_op },
4855 { .name = "global", .cb = handle_yaml_del_global_settings},
4856 { .name = "numa", .cb = handle_yaml_del_numa },
4857 { .name = "ping", .cb = handle_yaml_no_op },
4858 { .name = "discover", .cb = handle_yaml_no_op },
4861 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4862 { .name = "route", .cb = handle_yaml_show_route },
4863 { .name = "net", .cb = handle_yaml_show_net },
4864 { .name = "peer", .cb = handle_yaml_show_peers },
4865 { .name = "ip2nets", .cb = handle_yaml_no_op },
4866 { .name = "routing", .cb = handle_yaml_show_routing },
4867 { .name = "buffers", .cb = handle_yaml_show_routing },
4868 { .name = "statistics", .cb = handle_yaml_show_stats },
4869 { .name = "global", .cb = handle_yaml_show_global_settings},
4870 { .name = "numa", .cb = handle_yaml_show_numa },
4871 { .name = "ping", .cb = handle_yaml_no_op },
4872 { .name = "discover", .cb = handle_yaml_no_op },
4875 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4876 { .name = "route", .cb = handle_yaml_no_op },
4877 { .name = "net", .cb = handle_yaml_no_op },
4878 { .name = "peer", .cb = handle_yaml_no_op },
4879 { .name = "ip2nets", .cb = handle_yaml_no_op },
4880 { .name = "routing", .cb = handle_yaml_no_op },
4881 { .name = "buffers", .cb = handle_yaml_no_op },
4882 { .name = "statistics", .cb = handle_yaml_no_op },
4883 { .name = "global", .cb = handle_yaml_no_op },
4884 { .name = "numa", .cb = handle_yaml_no_op },
4885 { .name = "ping", .cb = handle_yaml_ping },
4886 { .name = "discover", .cb = handle_yaml_discover },
4889 static cmd_handler_t lookup_fn(char *key,
4890 struct lookup_cmd_hdlr_tbl *tbl)
4896 for (i = 0; tbl[i].name != NULL; i++) {
4897 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4904 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4905 struct cYAML **show_rc, struct cYAML **err_rc)
4907 struct cYAML *tree, *item = NULL, *head, *child;
4909 char err_str[LNET_MAX_STR_LEN];
4910 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4912 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4914 return LUSTRE_CFG_RC_BAD_PARAM;
4916 child = tree->cy_child;
4917 while (child != NULL) {
4918 cb = lookup_fn(child->cy_string, table);
4920 snprintf(err_str, sizeof(err_str),
4921 "\"call back for '%s' not found\"",
4923 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4924 "yaml", "helper", err_str, err_rc);
4928 if (cYAML_is_sequence(child)) {
4929 while ((head = cYAML_get_next_seq_item(child, &item))
4931 rc = cb(head, show_rc, err_rc);
4932 if (rc != LUSTRE_CFG_RC_NO_ERR)
4936 rc = cb(child, show_rc, err_rc);
4937 if (rc != LUSTRE_CFG_RC_NO_ERR)
4941 child = child->cy_next;
4945 cYAML_free_tree(tree);
4950 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4952 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4956 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4958 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4962 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4964 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4968 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4970 return lustre_yaml_cb_helper(f, lookup_exec_tbl,