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];
1402 if (nw == NULL || nids == NULL) {
1403 snprintf(err_str, str_len,
1404 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1405 err_str[str_len - 1] = '\0';
1406 return LUSTRE_CFG_RC_BAD_PARAM;
1409 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1412 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1416 *nids = calloc(count, sizeof(lnet_nid_t));
1417 if (*nids == NULL) {
1418 snprintf(err_str, str_len,
1419 "\"out of memory\"");
1420 err_str[str_len - 1] = '\0';
1421 return LUSTRE_CFG_RC_OUT_OF_MEM;
1424 * special case the GNI interface since it doesn't have an IP
1425 * address. The assumption is that there can only be one GNI
1426 * interface in the system. No interface name is provided.
1428 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1429 rc = read_sysfs_file(gni_nid_path, "nid", val,
1432 snprintf(err_str, str_len,
1433 "\"cannot read gni nid\"");
1434 err_str[str_len - 1] = '\0';
1437 gni_num = atoi(val);
1439 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1444 /* look at the other interfaces */
1445 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1446 rc = lustre_lnet_queryip(intf, &ip);
1447 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1448 snprintf(err_str, str_len,
1449 "\"couldn't query intf %s\"", intf->intf_name);
1450 err_str[str_len - 1] = '\0';
1453 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1469 * called repeatedly until a match or no more ip range
1471 * ip_range expression
1472 * interface list with all the interface names.
1473 * all the interfaces in the system.
1475 * try to match the ip_range expr to one of the interfaces' IPs in
1476 * the system. If we hit a patch for an interface. Check if that
1477 * interface name is in the list.
1479 * If there are more than one interface in the list, then make sure
1480 * that the IPs for all of these interfaces match the ip ranges
1483 * for each interface in intf_list
1484 * look up the intf name in ifa
1485 * if not there then no match
1486 * check ip obtained from ifa against a match to any of the
1488 * If no match, then fail
1490 * The result is that all the interfaces have to match.
1492 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1493 struct list_head *intf_list,
1494 struct list_head *ip_ranges)
1498 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1499 struct ifaddrs *ifaddr = ifa;
1500 struct lustre_lnet_ip_range_descr *ip_range;
1504 * if there are no explicit interfaces, and no ip ranges, then
1505 * configure the first tcp interface we encounter.
1507 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1508 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1509 if (ifaddr->ifa_addr == NULL)
1512 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1515 family = ifaddr->ifa_addr->sa_family;
1516 if (family == AF_INET &&
1517 strcmp(ifaddr->ifa_name, "lo") != 0) {
1518 rc = lustre_lnet_add_intf_descr
1519 (intf_list, ifaddr->ifa_name,
1520 strlen(ifaddr->ifa_name));
1522 if (rc != LUSTRE_CFG_RC_NO_ERR)
1525 return LUSTRE_CFG_RC_MATCH;
1528 return LUSTRE_CFG_RC_NO_MATCH;
1532 * First interface which matches an IP pattern will be used
1534 if (list_empty(intf_list)) {
1536 * no interfaces provided in the rule, but an ip range is
1537 * provided, so try and match an interface to the ip
1540 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1541 if (ifaddr->ifa_addr == NULL)
1544 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1547 family = ifaddr->ifa_addr->sa_family;
1548 if (family == AF_INET) {
1549 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1552 list_for_each_entry(ip_range, ip_ranges,
1554 rc = cfs_ip_addr_match(bswap_32(ip),
1555 &ip_range->ipr_expr);
1559 rc = lustre_lnet_add_intf_descr
1560 (intf_list, ifaddr->ifa_name,
1561 strlen(ifaddr->ifa_name));
1563 if (rc != LUSTRE_CFG_RC_NO_ERR)
1569 if (!list_empty(intf_list))
1570 return LUSTRE_CFG_RC_MATCH;
1572 return LUSTRE_CFG_RC_NO_MATCH;
1576 * If an interface is explicitly specified the ip-range might or
1577 * might not be specified. if specified the interface needs to match the
1578 * ip-range. If no ip-range then the interfaces are
1579 * automatically matched if they are all up.
1580 * If > 1 interfaces all the interfaces must match for the NI to
1583 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1584 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1585 if (ifaddr->ifa_addr == NULL)
1588 family = ifaddr->ifa_addr->sa_family;
1589 if (family == AF_INET &&
1590 strcmp(intf_descr->intf_name,
1591 ifaddr->ifa_name) == 0)
1595 if (ifaddr == NULL) {
1596 list_del(&intf_descr->intf_on_network);
1597 free_intf_descr(intf_descr);
1601 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1602 list_del(&intf_descr->intf_on_network);
1603 free_intf_descr(intf_descr);
1607 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1610 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1611 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1617 /* no match for this interface */
1618 list_del(&intf_descr->intf_on_network);
1619 free_intf_descr(intf_descr);
1623 return LUSTRE_CFG_RC_MATCH;
1626 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1627 lnet_nid_t **nids, __u32 *nnids,
1628 char *err_str, size_t str_len)
1630 struct ifaddrs *ifa;
1631 int rc = LUSTRE_CFG_RC_NO_ERR;
1633 rc = getifaddrs(&ifa);
1635 snprintf(err_str, str_len,
1636 "\"failed to get interface addresses: %d\"", -errno);
1637 err_str[str_len - 1] = '\0';
1641 rc = lustre_lnet_match_ip_to_intf(ifa,
1642 &ip2nets->ip2nets_net.nw_intflist,
1643 &ip2nets->ip2nets_ip_ranges);
1644 if (rc != LUSTRE_CFG_RC_MATCH) {
1645 snprintf(err_str, str_len,
1646 "\"couldn't match ip to existing interfaces\"");
1647 err_str[str_len - 1] = '\0';
1652 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1653 err_str, sizeof(err_str));
1654 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1665 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1666 struct lnet_ioctl_config_lnd_tunables *tunables,
1667 struct cfs_expr_list *global_cpts,
1668 lnet_nid_t *nids, char *err_str)
1671 struct lnet_ioctl_config_ni *conf;
1672 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1673 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1676 struct lnet_dlc_intf_descr *intf_descr;
1678 struct cfs_expr_list *cpt_expr;
1680 list_for_each_entry(intf_descr, intf_list,
1682 if (tunables != NULL)
1683 len = sizeof(struct lnet_ioctl_config_ni) +
1684 sizeof(struct lnet_ioctl_config_lnd_tunables);
1686 len = sizeof(struct lnet_ioctl_config_ni);
1688 data = calloc(1, len);
1690 return LUSTRE_CFG_RC_OUT_OF_MEM;
1691 conf = (struct lnet_ioctl_config_ni*) data;
1692 if (tunables != NULL)
1693 tun = (struct lnet_ioctl_config_lnd_tunables*)
1696 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1697 conf->lic_cfg_hdr.ioc_len = len;
1698 conf->lic_nid = nids[i];
1699 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1702 if (intf_descr->cpt_expr != NULL)
1703 cpt_expr = intf_descr->cpt_expr;
1704 else if (global_cpts != NULL)
1705 cpt_expr = global_cpts;
1709 if (cpt_expr != NULL) {
1710 count = cfs_expr_list_values(cpt_expr,
1711 LNET_MAX_SHOW_NUM_CPT,
1714 memcpy(conf->lic_cpts, cpt_array,
1715 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1724 conf->lic_ncpts = count;
1726 if (tunables != NULL)
1727 memcpy(tun, tunables, sizeof(*tunables));
1729 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1734 "\"cannot add network: %s\"", strerror(errno));
1742 return LUSTRE_CFG_RC_NO_ERR;
1746 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1747 struct lnet_ioctl_config_lnd_tunables *tunables,
1748 struct cfs_expr_list *global_cpts,
1749 int seq_no, struct cYAML **err_rc)
1751 lnet_nid_t *nids = NULL;
1754 char err_str[LNET_MAX_STR_LEN];
1756 snprintf(err_str, sizeof(err_str), "\"success\"");
1761 "\"incomplete ip2nets information\"");
1762 rc = LUSTRE_CFG_RC_BAD_PARAM;
1767 * call below function to resolve the rules into a list of nids.
1768 * The memory is allocated in that function then freed here when
1769 * it's no longer needed.
1771 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1773 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1776 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1777 snprintf(err_str, sizeof(err_str),
1778 "\"no interfaces match ip2nets rules\"");
1782 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1783 tunables, global_cpts, nids,
1790 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1794 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1795 struct cfs_expr_list *global_cpts,
1797 struct lnet_ioctl_config_lnd_tunables *tunables,
1798 int seq_no, struct cYAML **err_rc)
1801 struct lnet_ioctl_config_ni *conf;
1802 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1803 char buf[LNET_MAX_STR_LEN];
1804 int rc = LUSTRE_CFG_RC_NO_ERR;
1805 char err_str[LNET_MAX_STR_LEN];
1806 lnet_nid_t *nids = NULL;
1810 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1813 snprintf(err_str, sizeof(err_str), "\"success\"");
1815 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1816 (list_empty(&nw_descr->nw_intflist) &&
1817 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1820 "\"missing mandatory parameters in NI config: '%s'\"",
1821 (nw_descr == NULL) ? "network , interface" :
1822 (nw_descr->nw_id == 0) ? "network" : "interface");
1823 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1827 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1830 "\"ip2net string too long %d\"",
1831 (int)strlen(ip2net));
1832 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1836 if (ip2net != NULL) {
1837 if (tunables != NULL)
1838 len = sizeof(struct lnet_ioctl_config_ni) +
1839 sizeof(struct lnet_ioctl_config_lnd_tunables);
1841 len = sizeof(struct lnet_ioctl_config_ni);
1842 data = calloc(1, len);
1844 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1847 conf = (struct lnet_ioctl_config_ni*) data;
1848 if (tunables != NULL)
1849 tun = (struct lnet_ioctl_config_lnd_tunables*)
1850 (data + sizeof(*conf));
1852 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1853 conf->lic_cfg_hdr.ioc_len = len;
1854 strncpy(conf->lic_legacy_ip2nets, ip2net,
1857 if (global_cpts != NULL) {
1858 count = cfs_expr_list_values(global_cpts,
1859 LNET_MAX_SHOW_NUM_CPT,
1862 memcpy(conf->lic_cpts, cpt_array,
1863 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1872 conf->lic_ncpts = count;
1874 if (tunables != NULL)
1875 memcpy(tun, tunables, sizeof(*tunables));
1877 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1882 "\"cannot add network: %s\"", strerror(errno));
1889 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1890 rc = LUSTRE_CFG_RC_NO_ERR;
1894 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1897 "\"cannot parse net '%s'\"",
1898 libcfs_net2str(nw_descr->nw_id));
1899 rc = LUSTRE_CFG_RC_BAD_PARAM;
1904 * special case the GNI since no interface name is expected
1906 if (list_empty(&nw_descr->nw_intflist) &&
1907 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1910 "\"no interface name provided\"");
1911 rc = LUSTRE_CFG_RC_BAD_PARAM;
1915 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1916 err_str, sizeof(err_str));
1918 rc = LUSTRE_CFG_RC_BAD_PARAM;
1922 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1923 tunables, global_cpts, nids,
1927 if (nw_descr != NULL) {
1928 list_for_each_entry_safe(intf_descr, tmp,
1929 &nw_descr->nw_intflist,
1931 list_del(&intf_descr->intf_on_network);
1932 free_intf_descr(intf_descr);
1936 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1947 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1948 int seq_no, struct cYAML **err_rc)
1950 struct lnet_ioctl_config_ni data;
1951 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1952 char err_str[LNET_MAX_STR_LEN];
1953 lnet_nid_t *nids = NULL;
1955 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1957 snprintf(err_str, sizeof(err_str), "\"success\"");
1959 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1962 "\"missing mandatory parameter in deleting NI: '%s'\"",
1963 (nw_descr == NULL) ? "network , interface" :
1964 (nw_descr->nw_id == 0) ? "network" : "interface");
1965 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1969 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1970 return LUSTRE_CFG_RC_NO_ERR;
1972 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1975 "\"cannot parse net '%s'\"",
1976 libcfs_net2str(nw_descr->nw_id));
1977 rc = LUSTRE_CFG_RC_BAD_PARAM;
1981 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1982 err_str, sizeof(err_str));
1984 rc = LUSTRE_CFG_RC_BAD_PARAM;
1989 * no interfaces just the nw_id is specified
1992 nids = calloc(1, sizeof(*nids));
1994 snprintf(err_str, sizeof(err_str),
1995 "\"out of memory\"");
1996 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1999 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2003 for (i = 0; i < nnids; i++) {
2004 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2005 data.lic_nid = nids[i];
2007 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2012 "\"cannot del network: %s\"", strerror(errno));
2016 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2018 list_del(&intf_descr->intf_on_network);
2019 free_intf_descr(intf_descr);
2023 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2032 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2033 enum lnet_health_type type, char *name,
2034 int seq_no, struct cYAML **err_rc)
2036 struct lnet_ioctl_reset_health_cfg data;
2037 int rc = LUSTRE_CFG_RC_NO_ERR;
2038 char err_str[LNET_MAX_STR_LEN];
2040 snprintf(err_str, sizeof(err_str), "\"success\"");
2042 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2043 data.rh_type = type;
2045 data.rh_value = value;
2048 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2052 sizeof(err_str), "Can not configure health value: %s",
2056 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2061 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2062 struct cYAML **err_rc)
2066 nid = libcfs_str2nid(ni_nid);
2069 return lustre_lnet_config_healthv(value, all, nid,
2070 LNET_HEALTH_TYPE_LOCAL_NI,
2071 "ni healthv", seq_no, err_rc);
2074 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2075 int seq_no, struct cYAML **err_rc)
2079 nid = libcfs_str2nid(lpni_nid);
2082 return lustre_lnet_config_healthv(value, all, nid,
2083 LNET_HEALTH_TYPE_PEER_NI,
2084 "peer_ni healthv", seq_no, err_rc);
2088 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2089 struct lnet_ioctl_comm_count *counts)
2091 if (cYAML_create_number(yaml, "put",
2092 counts->ico_put_count)
2095 if (cYAML_create_number(yaml, "get",
2096 counts->ico_get_count)
2099 if (cYAML_create_number(yaml, "reply",
2100 counts->ico_reply_count)
2103 if (cYAML_create_number(yaml, "ack",
2104 counts->ico_ack_count)
2107 if (cYAML_create_number(yaml, "hello",
2108 counts->ico_hello_count)
2115 static struct lnet_ioctl_comm_count *
2116 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2119 return &msg_stats->im_send_stats;
2121 return &msg_stats->im_recv_stats;
2123 return &msg_stats->im_drop_stats;
2128 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2129 struct cYAML **show_rc, struct cYAML **err_rc,
2133 struct lnet_ioctl_config_ni *ni_data;
2134 struct lnet_ioctl_config_lnd_tunables *lnd;
2135 struct lnet_ioctl_element_stats *stats;
2136 struct lnet_ioctl_element_msg_stats msg_stats;
2137 struct lnet_ioctl_local_ni_hstats hstats;
2138 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2139 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2140 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2142 struct cYAML *root = NULL, *tunables = NULL,
2143 *net_node = NULL, *interfaces = NULL,
2144 *item = NULL, *first_seq = NULL,
2145 *tmp = NULL, *statistics = NULL,
2147 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2148 char str_buf[str_buf_len];
2150 char err_str[LNET_MAX_STR_LEN];
2151 bool exist = false, new_net = true;
2153 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2155 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2157 buf = calloc(1, buf_size);
2161 ni_data = (struct lnet_ioctl_config_ni *)buf;
2164 net = libcfs_str2net(nw);
2165 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2168 "\"cannot parse net '%s'\"", nw);
2169 rc = LUSTRE_CFG_RC_BAD_PARAM;
2174 root = cYAML_create_object(NULL, NULL);
2178 net_node = cYAML_create_seq(root, "net");
2179 if (net_node == NULL)
2186 memset(buf, 0, buf_size);
2188 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2190 * set the ioc_len to the proper value since INIT assumes
2193 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2194 ni_data->lic_idx = i;
2196 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2202 rc_net = LNET_NIDNET(ni_data->lic_nid);
2204 /* filter on provided data */
2205 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2209 /* if we're backing up don't store lo */
2210 if (backup && LNET_NETTYP(rc_net) == LOLND)
2213 /* default rc to -1 in case we hit the goto */
2217 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2218 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2219 (ni_data->lic_bulk + sizeof(*stats));
2221 if (rc_net != prev_net) {
2228 if (!cYAML_create_string(net_node, "net type",
2229 libcfs_net2str(rc_net)))
2232 tmp = cYAML_create_seq(net_node, "local NI(s)");
2238 /* create the tree to be printed. */
2239 item = cYAML_create_seq_item(tmp);
2243 if (first_seq == NULL)
2247 cYAML_create_string(item, "nid",
2248 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2252 cYAML_create_string(item,
2254 (ni_data->lic_status ==
2255 LNET_NI_STATUS_UP) ?
2256 "up" : "down") == NULL)
2259 /* don't add interfaces unless there is at least one
2261 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2262 interfaces = cYAML_create_object(item, "interfaces");
2263 if (interfaces == NULL)
2266 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2267 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2269 sizeof(str_buf), "%d", j);
2270 if (cYAML_create_string(interfaces,
2272 ni_data->lic_ni_intf[j]) ==
2284 goto continue_without_msg_stats;
2286 statistics = cYAML_create_object(item, "statistics");
2287 if (statistics == NULL)
2290 if (cYAML_create_number(statistics, "send_count",
2291 stats->iel_send_count)
2295 if (cYAML_create_number(statistics, "recv_count",
2296 stats->iel_recv_count)
2300 if (cYAML_create_number(statistics, "drop_count",
2301 stats->iel_drop_count)
2306 goto continue_without_msg_stats;
2308 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2309 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2310 msg_stats.im_idx = i;
2312 rc = l_ioctl(LNET_DEV_ID,
2313 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2317 goto continue_without_msg_stats;
2320 for (k = 0; k < 3; k++) {
2321 struct lnet_ioctl_comm_count *counts;
2322 struct cYAML *msg_statistics = NULL;
2324 msg_statistics = cYAML_create_object(item,
2325 (char *)gmsg_stat_names[k]);
2326 if (msg_statistics == NULL)
2329 counts = get_counts(&msg_stats, k);
2333 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2338 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2339 hstats.hlni_nid = ni_data->lic_nid;
2340 /* grab health stats */
2341 rc = l_ioctl(LNET_DEV_ID,
2342 IOC_LIBCFS_GET_LOCAL_HSTATS,
2346 goto continue_without_msg_stats;
2348 yhstats = cYAML_create_object(item, "health stats");
2351 if (cYAML_create_number(yhstats, "health value",
2352 hstats.hlni_health_value)
2355 if (cYAML_create_number(yhstats, "interrupts",
2356 hstats.hlni_local_interrupt)
2359 if (cYAML_create_number(yhstats, "dropped",
2360 hstats.hlni_local_dropped)
2363 if (cYAML_create_number(yhstats, "aborted",
2364 hstats.hlni_local_aborted)
2367 if (cYAML_create_number(yhstats, "no route",
2368 hstats.hlni_local_no_route)
2371 if (cYAML_create_number(yhstats, "timeouts",
2372 hstats.hlni_local_timeout)
2375 if (cYAML_create_number(yhstats, "error",
2376 hstats.hlni_local_error)
2380 continue_without_msg_stats:
2381 tunables = cYAML_create_object(item, "tunables");
2385 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2386 if (rc != LUSTRE_CFG_RC_NO_ERR)
2389 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2391 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2392 rc != LUSTRE_CFG_RC_NO_MATCH)
2395 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2396 tunables = cYAML_create_object(item,
2398 if (tunables == NULL)
2403 cYAML_create_number(item, "dev cpt",
2404 ni_data->lic_dev_cpt) == NULL)
2408 cYAML_create_number(item, "tcp bonding",
2409 ni_data->lic_tcp_bonding)
2413 /* out put the CPTs in the format: "[x,x,x,...]" */
2414 limit = str_buf + str_buf_len - 3;
2415 pos += snprintf(pos, limit - pos, "\"[");
2416 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2417 j < ni_data->lic_ncpts &&
2419 pos += snprintf(pos, limit - pos,
2420 "%d", ni_data->lic_cpts[j]);
2421 if ((j + 1) < ni_data->lic_ncpts)
2422 pos += snprintf(pos, limit - pos, ",");
2424 pos += snprintf(pos, 3, "]\"");
2426 if (ni_data->lic_ncpts >= 1 &&
2427 cYAML_create_string(item, "CPT",
2433 /* Print out the net information only if show_rc is not provided */
2434 if (show_rc == NULL)
2435 cYAML_print_tree(root);
2437 if (l_errno != ENOENT) {
2440 "\"cannot get networks: %s\"",
2445 rc = LUSTRE_CFG_RC_NO_ERR;
2447 snprintf(err_str, sizeof(err_str), "\"success\"");
2449 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2450 cYAML_free_tree(root);
2451 } else if (show_rc != NULL && *show_rc != NULL) {
2452 struct cYAML *show_node;
2453 /* find the net node, if one doesn't exist
2454 * then insert one. Otherwise add to the one there
2456 show_node = cYAML_get_object_item(*show_rc, "net");
2457 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2458 cYAML_insert_child(show_node, first_seq);
2461 } else if (show_node == NULL) {
2462 cYAML_insert_sibling((*show_rc)->cy_child,
2466 cYAML_free_tree(root);
2472 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2477 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2479 struct lnet_ioctl_config_data data;
2480 int rc = LUSTRE_CFG_RC_NO_ERR;
2481 char err_str[LNET_MAX_STR_LEN];
2483 snprintf(err_str, sizeof(err_str), "\"success\"");
2485 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2486 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2488 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2493 "\"cannot %s routing %s\"",
2494 (enable) ? "enable" : "disable", strerror(errno));
2499 cYAML_build_error(rc, seq_no,
2500 (enable) ? ADD_CMD : DEL_CMD,
2501 "routing", err_str, err_rc);
2506 int ioctl_set_value(__u32 val, int ioc, char *name,
2507 int seq_no, struct cYAML **err_rc)
2509 struct lnet_ioctl_set_value data;
2510 int rc = LUSTRE_CFG_RC_NO_ERR;
2511 char err_str[LNET_MAX_STR_LEN];
2513 snprintf(err_str, sizeof(err_str), "\"success\"");
2515 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2516 data.sv_value = val;
2518 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2523 "\"cannot configure %s to %d: %s\"", name,
2524 val, strerror(errno));
2527 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2532 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2534 int rc = LUSTRE_CFG_RC_NO_ERR;
2535 char err_str[LNET_MAX_STR_LEN];
2536 char val[LNET_MAX_STR_LEN];
2538 snprintf(err_str, sizeof(err_str), "\"success\"");
2540 snprintf(val, sizeof(val), "%d", sen);
2542 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2543 1, strlen(val) + 1);
2545 snprintf(err_str, sizeof(err_str),
2546 "\"cannot configure health sensitivity: %s\"",
2549 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2554 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2556 int rc = LUSTRE_CFG_RC_NO_ERR;
2557 char err_str[LNET_MAX_STR_LEN];
2558 char val[LNET_MAX_STR_LEN];
2560 snprintf(err_str, sizeof(err_str), "\"success\"");
2562 snprintf(val, sizeof(val), "%d", timeout);
2564 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2565 1, strlen(val) + 1);
2567 snprintf(err_str, sizeof(err_str),
2568 "\"cannot configure transaction timeout: %s\"",
2571 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2576 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2578 int rc = LUSTRE_CFG_RC_NO_ERR;
2579 char err_str[LNET_MAX_STR_LEN];
2580 char val[LNET_MAX_STR_LEN];
2582 snprintf(err_str, sizeof(err_str), "\"success\"");
2584 snprintf(val, sizeof(val), "%d", count);
2586 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2587 1, strlen(val) + 1);
2589 snprintf(err_str, sizeof(err_str),
2590 "\"cannot configure retry count: %s\"",
2593 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2598 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2600 int rc = LUSTRE_CFG_RC_NO_ERR;
2601 char err_str[LNET_MAX_STR_LEN];
2602 char val[LNET_MAX_STR_LEN];
2604 snprintf(err_str, sizeof(err_str), "\"success\"");
2606 snprintf(val, sizeof(val), "%d", max);
2608 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2609 1, strlen(val) + 1);
2611 snprintf(err_str, sizeof(err_str),
2612 "\"cannot configure max interfaces: %s\"",
2615 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2620 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2622 int rc = LUSTRE_CFG_RC_NO_ERR;
2623 char err_str[LNET_MAX_STR_LEN];
2624 char val[LNET_MAX_STR_LEN];
2626 snprintf(err_str, sizeof(err_str), "\"success\"");
2628 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2630 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2631 1, strlen(val) + 1);
2633 snprintf(err_str, sizeof(err_str),
2634 "\"cannot configure discovery: %s\"",
2637 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2643 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2645 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2646 "numa_range", seq_no, err_rc);
2649 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2650 struct cYAML **err_rc)
2652 struct lnet_ioctl_config_data data;
2653 int rc = LUSTRE_CFG_RC_NO_ERR;
2654 char err_str[LNET_MAX_STR_LEN];
2656 snprintf(err_str, sizeof(err_str), "\"success\"");
2658 /* -1 indicates to ignore changes to this field */
2659 if (tiny < -1 || small < -1 || large < -1) {
2662 "\"tiny, small and large must be >= 0\"");
2663 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2667 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2668 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2669 data.cfg_config_u.cfg_buffers.buf_small = small;
2670 data.cfg_config_u.cfg_buffers.buf_large = large;
2672 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2677 "\"cannot configure buffers: %s\"", strerror(errno));
2682 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2687 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2688 struct cYAML **err_rc, bool backup)
2690 struct lnet_ioctl_config_data *data;
2691 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2692 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2695 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2696 int buf_count[LNET_NRBPOOLS] = {0};
2697 struct cYAML *root = NULL, *pools_node = NULL,
2698 *type_node = NULL, *item = NULL, *cpt = NULL,
2699 *first_seq = NULL, *buffers = NULL;
2701 char err_str[LNET_MAX_STR_LEN];
2702 char node_name[LNET_MAX_STR_LEN];
2705 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2707 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2711 data = (struct lnet_ioctl_config_data *)buf;
2713 root = cYAML_create_object(NULL, NULL);
2718 pools_node = cYAML_create_object(root, "routing");
2720 pools_node = cYAML_create_seq(root, "routing");
2721 if (pools_node == NULL)
2725 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2726 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2727 sizeof(struct lnet_ioctl_pool_cfg);
2728 data->cfg_count = i;
2730 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2738 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2741 goto calculate_buffers;
2743 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2744 item = cYAML_create_seq_item(pools_node);
2748 if (first_seq == NULL)
2751 cpt = cYAML_create_object(item, node_name);
2756 /* create the tree and print */
2757 for (j = 0; j < LNET_NRBPOOLS; j++) {
2759 type_node = cYAML_create_object(cpt, pools[j]);
2760 if (type_node == NULL)
2764 cYAML_create_number(type_node, "npages",
2765 pool_cfg->pl_pools[j].pl_npages)
2769 cYAML_create_number(type_node, "nbuffers",
2770 pool_cfg->pl_pools[j].
2771 pl_nbuffers) == NULL)
2774 cYAML_create_number(type_node, "credits",
2775 pool_cfg->pl_pools[j].
2776 pl_credits) == NULL)
2779 cYAML_create_number(type_node, "mincredits",
2780 pool_cfg->pl_pools[j].
2781 pl_mincredits) == NULL)
2783 /* keep track of the total count for each of the
2784 * tiny, small and large buffers */
2785 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2789 if (pool_cfg != NULL) {
2791 if (cYAML_create_number(pools_node, "enable",
2792 pool_cfg->pl_routing) ==
2796 goto add_buffer_section;
2799 item = cYAML_create_seq_item(pools_node);
2803 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2809 /* create a buffers entry in the show. This is necessary so that
2810 * if the YAML output is used to configure a node, the buffer
2811 * configuration takes hold */
2812 buffers = cYAML_create_object(root, "buffers");
2813 if (buffers == NULL)
2816 for (i = 0; i < LNET_NRBPOOLS; i++) {
2817 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2821 if (show_rc == NULL)
2822 cYAML_print_tree(root);
2824 if (l_errno != ENOENT) {
2827 "\"cannot get routing information: %s\"",
2832 rc = LUSTRE_CFG_RC_NO_ERR;
2834 snprintf(err_str, sizeof(err_str), "\"success\"");
2835 rc = LUSTRE_CFG_RC_NO_ERR;
2839 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2840 cYAML_free_tree(root);
2841 } else if (show_rc != NULL && *show_rc != NULL) {
2842 struct cYAML *routing_node;
2843 /* there should exist only one routing block and one
2844 * buffers block. If there already exists a previous one
2845 * then don't add another */
2846 routing_node = cYAML_get_object_item(*show_rc, "routing");
2847 if (routing_node == NULL) {
2848 cYAML_insert_sibling((*show_rc)->cy_child,
2852 cYAML_free_tree(root);
2858 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2863 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2864 struct cYAML **show_rc, struct cYAML **err_rc,
2868 * TODO: This function is changing in a future patch to accommodate
2869 * PEER_LIST and proper filtering on any nid of the peer
2871 struct lnet_ioctl_peer_cfg peer_info;
2872 struct lnet_peer_ni_credit_info *lpni_cri;
2873 struct lnet_ioctl_element_stats *lpni_stats;
2874 struct lnet_ioctl_element_msg_stats *msg_stats;
2875 struct lnet_ioctl_peer_ni_hstats *hstats;
2877 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2882 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2883 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2884 *msg_statistics = NULL, *statistics = NULL,
2886 char err_str[LNET_MAX_STR_LEN];
2887 struct lnet_process_id *list = NULL;
2892 snprintf(err_str, sizeof(err_str),
2893 "\"out of memory\"");
2895 /* create struct cYAML root object */
2896 root = cYAML_create_object(NULL, NULL);
2900 peer_root = cYAML_create_seq(root, "peer");
2901 if (peer_root == NULL)
2905 size = count * sizeof(struct lnet_process_id);
2906 list = malloc(size);
2912 list[0].nid = libcfs_str2nid(knid);
2916 memset(&peer_info, 0, sizeof(peer_info));
2917 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2918 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2919 peer_info.prcfg_size = size;
2920 peer_info.prcfg_bulk = list;
2923 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2925 count = peer_info.prcfg_count;
2929 if (l_errno != E2BIG) {
2932 "\"cannot get peer list: %s\"",
2938 size = peer_info.prcfg_size;
2939 list = malloc(size);
2948 data = malloc(size);
2954 for (i = 0; i < count; i++) {
2956 memset(&peer_info, 0, sizeof(peer_info));
2957 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2958 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2959 peer_info.prcfg_prim_nid = list[i].nid;
2960 peer_info.prcfg_size = size;
2961 peer_info.prcfg_bulk = data;
2964 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2969 if (l_errno != E2BIG) {
2972 "\"cannot get peer information: %s\"",
2978 size = peer_info.prcfg_size;
2979 data = malloc(size);
2987 peer = cYAML_create_seq_item(peer_root);
2991 if (first_seq == NULL)
2994 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2995 if (cYAML_create_string(peer, "primary nid",
2996 libcfs_nid2str(pnid))
2999 if (cYAML_create_string(peer, "Multi-Rail",
3000 peer_info.prcfg_mr ? "True" : "False")
3004 * print out the state of the peer only if details are
3009 cYAML_create_number(peer, "peer state",
3010 peer_info.prcfg_state)
3015 tmp = cYAML_create_seq(peer, "peer ni");
3020 for (j = 0; j < peer_info.prcfg_count; j++) {
3022 lpni_cri = (void*)nidp + sizeof(nidp);
3023 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3024 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3025 hstats = (void *)msg_stats + sizeof(*msg_stats);
3026 lpni_data = (void *)hstats + sizeof(*hstats);
3028 peer_ni = cYAML_create_seq_item(tmp);
3029 if (peer_ni == NULL)
3032 if (cYAML_create_string(peer_ni, "nid",
3033 libcfs_nid2str(*nidp))
3040 if (cYAML_create_string(peer_ni, "state",
3041 lpni_cri->cr_aliveness)
3048 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3049 lpni_cri->cr_ni_peer_tx_credits)
3053 if (cYAML_create_number(peer_ni, "available_tx_credits",
3054 lpni_cri->cr_peer_tx_credits)
3058 if (cYAML_create_number(peer_ni, "min_tx_credits",
3059 lpni_cri->cr_peer_min_tx_credits)
3063 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3064 lpni_cri->cr_peer_tx_qnob)
3068 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3069 lpni_cri->cr_peer_rtr_credits)
3073 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3074 lpni_cri->cr_peer_min_rtr_credits)
3078 if (cYAML_create_number(peer_ni, "refcount",
3079 lpni_cri->cr_refcount) == NULL)
3082 statistics = cYAML_create_object(peer_ni, "statistics");
3083 if (statistics == NULL)
3086 if (cYAML_create_number(statistics, "send_count",
3087 lpni_stats->iel_send_count)
3091 if (cYAML_create_number(statistics, "recv_count",
3092 lpni_stats->iel_recv_count)
3096 if (cYAML_create_number(statistics, "drop_count",
3097 lpni_stats->iel_drop_count)
3104 for (k = 0; k < 3; k++) {
3105 struct lnet_ioctl_comm_count *counts;
3107 msg_statistics = cYAML_create_object(peer_ni,
3108 (char *) gmsg_stat_names[k]);
3109 if (msg_statistics == NULL)
3112 counts = get_counts(msg_stats, k);
3116 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3121 yhstats = cYAML_create_object(peer_ni, "health stats");
3124 if (cYAML_create_number(yhstats, "health value",
3125 hstats->hlpni_health_value)
3128 if (cYAML_create_number(yhstats, "dropped",
3129 hstats->hlpni_remote_dropped)
3132 if (cYAML_create_number(yhstats, "timeout",
3133 hstats->hlpni_remote_timeout)
3136 if (cYAML_create_number(yhstats, "error",
3137 hstats->hlpni_remote_error)
3140 if (cYAML_create_number(yhstats, "network timeout",
3141 hstats->hlpni_network_timeout)
3147 /* print output iff show_rc is not provided */
3148 if (show_rc == NULL)
3149 cYAML_print_tree(root);
3151 snprintf(err_str, sizeof(err_str), "\"success\"");
3152 rc = LUSTRE_CFG_RC_NO_ERR;
3157 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3158 cYAML_free_tree(root);
3159 } else if (show_rc != NULL && *show_rc != NULL) {
3160 struct cYAML *show_node;
3161 /* find the peer node, if one doesn't exist then
3162 * insert one. Otherwise add to the one there
3164 show_node = cYAML_get_object_item(*show_rc,
3166 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3167 cYAML_insert_child(show_node, first_seq);
3170 } else if (show_node == NULL) {
3171 cYAML_insert_sibling((*show_rc)->cy_child,
3175 cYAML_free_tree(root);
3181 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3187 int lustre_lnet_list_peer(int seq_no,
3188 struct cYAML **show_rc, struct cYAML **err_rc)
3190 struct lnet_ioctl_peer_cfg peer_info;
3191 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3196 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3197 char err_str[LNET_MAX_STR_LEN];
3198 struct lnet_process_id *list = NULL;
3200 snprintf(err_str, sizeof(err_str),
3201 "\"out of memory\"");
3203 memset(&peer_info, 0, sizeof(peer_info));
3205 /* create struct cYAML root object */
3206 root = cYAML_create_object(NULL, NULL);
3210 list_root = cYAML_create_seq(root, "peer list");
3211 if (list_root == NULL)
3215 size = count * sizeof(struct lnet_process_id);
3216 list = malloc(size);
3222 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3223 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3224 peer_info.prcfg_size = size;
3225 peer_info.prcfg_bulk = list;
3228 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3229 count = peer_info.prcfg_count;
3233 if (l_errno != E2BIG) {
3236 "\"cannot get peer list: %s\"",
3242 size = peer_info.prcfg_size;
3243 list = malloc(size);
3250 /* count is now the actual number of ids in the list. */
3251 for (i = 0; i < count; i++) {
3252 if (cYAML_create_string(list_root, "nid",
3253 libcfs_nid2str(list[i].nid))
3258 /* print output iff show_rc is not provided */
3259 if (show_rc == NULL)
3260 cYAML_print_tree(root);
3262 snprintf(err_str, sizeof(err_str), "\"success\"");
3263 rc = LUSTRE_CFG_RC_NO_ERR;
3268 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3269 cYAML_free_tree(root);
3270 } else if (show_rc != NULL && *show_rc != NULL) {
3271 struct cYAML *show_node;
3272 /* find the peer node, if one doesn't exist then
3273 * insert one. Otherwise add to the one there
3275 show_node = cYAML_get_object_item(*show_rc,
3277 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3278 cYAML_insert_child(show_node, first_seq);
3281 } else if (show_node == NULL) {
3282 cYAML_insert_sibling((*show_rc)->cy_child,
3286 cYAML_free_tree(root);
3292 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3298 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3301 struct cYAML *show_node;
3303 show_node = cYAML_get_object_item(show_rc, "global");
3304 if (show_node != NULL)
3305 cYAML_insert_sibling(show_node->cy_child,
3308 cYAML_insert_sibling(show_rc->cy_child,
3313 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3314 char *name, __u32 value,
3315 struct cYAML **show_rc,
3316 struct cYAML **err_rc, int err)
3318 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3319 struct cYAML *root = NULL, *global = NULL;
3326 root = cYAML_create_object(NULL, NULL);
3330 global = cYAML_create_object(root, "global");
3334 if (cYAML_create_number(global, name,
3338 if (show_rc == NULL)
3339 cYAML_print_tree(root);
3341 snprintf(err_str, err_len, "\"success\"");
3343 rc = LUSTRE_CFG_RC_NO_ERR;
3346 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3347 cYAML_free_tree(root);
3348 } else if (show_rc != NULL && *show_rc != NULL) {
3349 add_to_global(*show_rc, global, root);
3354 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3359 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3360 struct cYAML **show_rc,
3361 struct cYAML **err_rc)
3363 struct lnet_ioctl_set_value data;
3366 char err_str[LNET_MAX_STR_LEN];
3368 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3370 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3372 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3377 "\"cannot get %s: %s\"",
3378 name, strerror(l_errno));
3381 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3382 data.sv_value, show_rc, err_rc, l_errno);
3385 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3386 struct cYAML **err_rc)
3388 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3389 char val[LNET_MAX_STR_LEN];
3390 int sen = -1, l_errno = 0;
3391 char err_str[LNET_MAX_STR_LEN];
3393 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3395 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3399 snprintf(err_str, sizeof(err_str),
3400 "\"cannot get health sensitivity: %d\"", rc);
3405 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3406 "health_sensitivity", sen, show_rc,
3410 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3411 struct cYAML **err_rc)
3413 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3414 char val[LNET_MAX_STR_LEN];
3415 int tto = -1, l_errno = 0;
3416 char err_str[LNET_MAX_STR_LEN];
3418 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3420 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3424 snprintf(err_str, sizeof(err_str),
3425 "\"cannot get transaction timeout: %d\"", rc);
3430 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3431 "transaction_timeout", tto, show_rc,
3435 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3436 struct cYAML **err_rc)
3438 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3439 char val[LNET_MAX_STR_LEN];
3440 int retry_count = -1, l_errno = 0;
3441 char err_str[LNET_MAX_STR_LEN];
3443 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3445 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3449 snprintf(err_str, sizeof(err_str),
3450 "\"cannot get retry count: %d\"", rc);
3452 retry_count = atoi(val);
3455 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3456 "retry_count", retry_count, show_rc,
3460 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3461 struct cYAML **show_rc, struct cYAML **err_rc)
3463 struct lnet_ioctl_recovery_list nid_list;
3464 struct cYAML *root = NULL, *nids = NULL;
3466 char err_str[LNET_MAX_STR_LEN];
3468 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3470 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3471 nid_list.rlst_type = type;
3473 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3479 root = cYAML_create_object(NULL, NULL);
3483 nids = cYAML_create_object(root, name);
3489 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3490 char nidenum[LNET_MAX_STR_LEN];
3491 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3492 if (!cYAML_create_string(nids, nidenum,
3493 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3497 snprintf(err_str, sizeof(err_str), "success\n");
3502 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3503 cYAML_free_tree(root);
3504 } else if (show_rc != NULL && *show_rc != NULL) {
3505 struct cYAML *show_node;
3506 /* find the net node, if one doesn't exist
3507 * then insert one. Otherwise add to the one there
3509 show_node = cYAML_get_object_item(*show_rc, name);
3510 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3511 cYAML_insert_child(show_node, nids);
3514 } else if (show_node == NULL) {
3515 cYAML_insert_sibling((*show_rc)->cy_child,
3519 cYAML_free_tree(root);
3525 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3530 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3531 struct cYAML **err_rc)
3533 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3534 seq_no, show_rc, err_rc);
3537 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3538 struct cYAML **err_rc)
3540 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3541 seq_no, show_rc, err_rc);
3544 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3545 struct cYAML **err_rc)
3547 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3548 char val[LNET_MAX_STR_LEN];
3549 int max_intf = -1, l_errno = 0;
3550 char err_str[LNET_MAX_STR_LEN];
3552 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3554 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3558 snprintf(err_str, sizeof(err_str),
3559 "\"cannot get max interfaces: %d\"", rc);
3561 max_intf = atoi(val);
3564 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3565 "max_intf", max_intf, show_rc,
3569 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3570 struct cYAML **err_rc)
3572 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3573 char val[LNET_MAX_STR_LEN];
3574 int discovery = -1, l_errno = 0;
3575 char err_str[LNET_MAX_STR_LEN];
3577 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3579 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3583 snprintf(err_str, sizeof(err_str),
3584 "\"cannot get discovery setting: %d\"", rc);
3587 * The kernel stores a discovery disabled value. User space
3588 * shows whether discovery is enabled. So the value must be
3591 discovery = !atoi(val);
3594 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3595 "discovery", discovery, show_rc,
3599 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3600 struct cYAML **err_rc)
3602 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3603 "numa_range", show_rc, err_rc);
3606 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3607 struct cYAML **err_rc)
3609 struct lnet_ioctl_lnet_stats data;
3610 struct lnet_counters *cntrs;
3613 char err_str[LNET_MAX_STR_LEN];
3614 struct cYAML *root = NULL, *stats = NULL;
3616 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3618 LIBCFS_IOC_INIT_V2(data, st_hdr);
3620 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3625 "\"cannot get lnet statistics: %s\"",
3631 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3633 cntrs = &data.st_cntrs;
3635 root = cYAML_create_object(NULL, NULL);
3639 stats = cYAML_create_object(root, "statistics");
3643 if (!cYAML_create_number(stats, "msgs_alloc",
3644 cntrs->lct_common.lcc_msgs_alloc))
3647 if (!cYAML_create_number(stats, "msgs_max",
3648 cntrs->lct_common.lcc_msgs_max))
3651 if (!cYAML_create_number(stats, "rst_alloc",
3652 cntrs->lct_health.lch_rst_alloc))
3655 if (!cYAML_create_number(stats, "errors",
3656 cntrs->lct_common.lcc_errors))
3659 if (!cYAML_create_number(stats, "send_count",
3660 cntrs->lct_common.lcc_send_count))
3663 if (!cYAML_create_number(stats, "resend_count",
3664 cntrs->lct_health.lch_resend_count))
3667 if (!cYAML_create_number(stats, "response_timeout_count",
3668 cntrs->lct_health.lch_response_timeout_count))
3671 if (!cYAML_create_number(stats, "local_interrupt_count",
3672 cntrs->lct_health.lch_local_interrupt_count))
3675 if (!cYAML_create_number(stats, "local_dropped_count",
3676 cntrs->lct_health.lch_local_dropped_count))
3679 if (!cYAML_create_number(stats, "local_aborted_count",
3680 cntrs->lct_health.lch_local_aborted_count))
3683 if (!cYAML_create_number(stats, "local_no_route_count",
3684 cntrs->lct_health.lch_local_no_route_count))
3687 if (!cYAML_create_number(stats, "local_timeout_count",
3688 cntrs->lct_health.lch_local_timeout_count))
3691 if (!cYAML_create_number(stats, "local_error_count",
3692 cntrs->lct_health.lch_local_error_count))
3695 if (!cYAML_create_number(stats, "remote_dropped_count",
3696 cntrs->lct_health.lch_remote_dropped_count))
3699 if (!cYAML_create_number(stats, "remote_error_count",
3700 cntrs->lct_health.lch_remote_error_count))
3703 if (!cYAML_create_number(stats, "remote_timeout_count",
3704 cntrs->lct_health.lch_remote_timeout_count))
3707 if (!cYAML_create_number(stats, "network_timeout_count",
3708 cntrs->lct_health.lch_network_timeout_count))
3711 if (!cYAML_create_number(stats, "recv_count",
3712 cntrs->lct_common.lcc_recv_count))
3715 if (!cYAML_create_number(stats, "route_count",
3716 cntrs->lct_common.lcc_route_count))
3719 if (!cYAML_create_number(stats, "drop_count",
3720 cntrs->lct_common.lcc_drop_count))
3723 if (!cYAML_create_number(stats, "send_length",
3724 cntrs->lct_common.lcc_send_length))
3727 if (!cYAML_create_number(stats, "recv_length",
3728 cntrs->lct_common.lcc_recv_length))
3731 if (!cYAML_create_number(stats, "route_length",
3732 cntrs->lct_common.lcc_route_length))
3735 if (!cYAML_create_number(stats, "drop_length",
3736 cntrs->lct_common.lcc_drop_length))
3740 cYAML_print_tree(root);
3742 snprintf(err_str, sizeof(err_str), "\"success\"");
3743 rc = LUSTRE_CFG_RC_NO_ERR;
3745 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3746 cYAML_free_tree(root);
3747 } else if (show_rc != NULL && *show_rc != NULL) {
3748 cYAML_insert_sibling((*show_rc)->cy_child,
3755 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3760 typedef int (*cmd_handler_t)(struct cYAML *tree,
3761 struct cYAML **show_rc,
3762 struct cYAML **err_rc);
3764 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3765 struct cYAML **err_rc)
3767 struct cYAML *net, *gw, *hop, *prio, *seq_no;
3769 net = cYAML_get_object_item(tree, "net");
3770 gw = cYAML_get_object_item(tree, "gateway");
3771 hop = cYAML_get_object_item(tree, "hop");
3772 prio = cYAML_get_object_item(tree, "priority");
3773 seq_no = cYAML_get_object_item(tree, "seq_no");
3775 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3776 (gw) ? gw->cy_valuestring : NULL,
3777 (hop) ? hop->cy_valueint : -1,
3778 (prio) ? prio->cy_valueint : -1,
3779 (seq_no) ? seq_no->cy_valueint : -1,
3783 static void yaml_free_string_array(char **array, int num)
3786 char **sub_array = array;
3788 for (i = 0; i < num; i++) {
3789 if (*sub_array != NULL)
3799 * 0: <intf_name>['['<expr>']']
3800 * 1: <intf_name>['['<expr>']']
3802 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3803 struct lnet_dlc_network_descr *nw_descr)
3805 struct cYAML *child = NULL;
3806 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3807 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3809 if (intf_tree == NULL || nw_descr == NULL)
3810 return LUSTRE_CFG_RC_BAD_PARAM;
3812 /* now grab all the interfaces and their cpts */
3813 child = intf_tree->cy_child;
3814 while (child != NULL) {
3815 if (child->cy_valuestring == NULL) {
3816 child = child->cy_next;
3820 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3823 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3824 child->cy_valuestring,
3825 strlen(child->cy_valuestring));
3826 if (rc != LUSTRE_CFG_RC_NO_ERR)
3830 child = child->cy_next;
3834 return LUSTRE_CFG_RC_MISSING_PARAM;
3839 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3841 list_del(&intf_descr->intf_on_network);
3842 free_intf_descr(intf_descr);
3849 yaml_extract_cmn_tunables(struct cYAML *tree,
3850 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3851 struct cfs_expr_list **global_cpts)
3853 struct cYAML *tun, *item, *smp;
3856 tun = cYAML_get_object_item(tree, "tunables");
3858 item = cYAML_get_object_item(tun, "peer_timeout");
3860 tunables->lct_peer_timeout = item->cy_valueint;
3861 item = cYAML_get_object_item(tun, "peer_credits");
3863 tunables->lct_peer_tx_credits = item->cy_valueint;
3864 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3866 tunables->lct_peer_rtr_credits = item->cy_valueint;
3867 item = cYAML_get_object_item(tun, "credits");
3869 tunables->lct_max_tx_credits = item->cy_valueint;
3870 smp = cYAML_get_object_item(tun, "CPT");
3872 rc = cfs_expr_list_parse(smp->cy_valuestring,
3873 strlen(smp->cy_valuestring),
3874 0, UINT_MAX, global_cpts);
3876 *global_cpts = NULL;
3886 yaml_extract_tunables(struct cYAML *tree,
3887 struct lnet_ioctl_config_lnd_tunables *tunables,
3888 struct cfs_expr_list **global_cpts,
3893 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3899 lustre_yaml_extract_lnd_tunables(tree, net_type,
3907 * - net type: <net>[<NUM>]
3909 * - nid: <ip>@<net>[<NUM>]
3912 * 0: <intf_name>['['<expr>']']
3913 * 1: <intf_name>['['<expr>']']
3915 * peer_timeout: <NUM>
3916 * peer_credits: <NUM>
3917 * peer_buffer_credits: <NUM>
3920 * peercredits_hiw: <NUM>
3921 * map_on_demand: <NUM>
3922 * concurrent_sends: <NUM>
3923 * fmr_pool_size: <NUM>
3924 * fmr_flush_trigger: <NUM>
3927 * At least one interface is required. If no interfaces are provided the
3928 * network interface can not be configured.
3930 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3931 struct cYAML **err_rc)
3933 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3935 int num_entries = 0, rc;
3936 struct lnet_dlc_network_descr nw_descr;
3937 struct cfs_expr_list *global_cpts = NULL;
3938 struct lnet_ioctl_config_lnd_tunables tunables;
3941 memset(&tunables, 0, sizeof(tunables));
3943 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3944 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3946 ip2net = cYAML_get_object_item(tree, "ip2net");
3947 net = cYAML_get_object_item(tree, "net type");
3949 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3951 nw_descr.nw_id = LOLND;
3954 * if neither net nor ip2nets are present, then we can not
3955 * configure the network.
3957 if (!net && !ip2net)
3958 return LUSTRE_CFG_RC_MISSING_PARAM;
3960 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3961 if (local_nis == NULL)
3962 return LUSTRE_CFG_RC_MISSING_PARAM;
3964 if (!cYAML_is_sequence(local_nis))
3965 return LUSTRE_CFG_RC_BAD_PARAM;
3967 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3968 intf = cYAML_get_object_item(item, "interfaces");
3971 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3972 if (num_entries <= 0) {
3973 cYAML_build_error(num_entries, -1, "ni", "add",
3974 "bad interface list",
3976 return LUSTRE_CFG_RC_BAD_PARAM;
3980 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3981 LNET_NETTYP(nw_descr.nw_id));
3982 seq_no = cYAML_get_object_item(tree, "seq_no");
3984 rc = lustre_lnet_config_ni(&nw_descr,
3986 (ip2net) ? ip2net->cy_valuestring : NULL,
3987 (found) ? &tunables: NULL,
3988 (seq_no) ? seq_no->cy_valueint : -1,
3991 if (global_cpts != NULL)
3992 cfs_expr_list_free(global_cpts);
3999 * - net-spec: <tcp|o2ib|gni>[NUM]
4001 * 0: <intf name>['['<expr>']']
4002 * 1: <intf name>['['<expr>']']
4004 * 0: <expr.expr.expr.expr>
4005 * 1: <expr.expr.expr.expr>
4007 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4008 struct cYAML **show_rc,
4009 struct cYAML **err_rc)
4011 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4013 struct lustre_lnet_ip2nets ip2nets;
4014 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4016 int rc = LUSTRE_CFG_RC_NO_ERR;
4017 struct cfs_expr_list *global_cpts = NULL;
4018 struct cfs_expr_list *el, *el_tmp;
4019 struct lnet_ioctl_config_lnd_tunables tunables;
4020 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4023 memset(&tunables, 0, sizeof(tunables));
4025 /* initialize all lists */
4026 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4027 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4028 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4030 net = cYAML_get_object_item(tree, "net-spec");
4032 return LUSTRE_CFG_RC_BAD_PARAM;
4034 if (net != NULL && net->cy_valuestring == NULL)
4035 return LUSTRE_CFG_RC_BAD_PARAM;
4037 /* assign the network id */
4038 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4039 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4040 return LUSTRE_CFG_RC_BAD_PARAM;
4042 seq_no = cYAML_get_object_item(tree, "seq_no");
4044 intf = cYAML_get_object_item(tree, "interfaces");
4046 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4048 return LUSTRE_CFG_RC_BAD_PARAM;
4051 ip_range = cYAML_get_object_item(tree, "ip-range");
4052 if (ip_range != NULL) {
4053 item = ip_range->cy_child;
4054 while (item != NULL) {
4055 if (item->cy_valuestring == NULL) {
4056 item = item->cy_next;
4060 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4061 item->cy_valuestring);
4063 if (rc != LUSTRE_CFG_RC_NO_ERR)
4066 item = item->cy_next;
4070 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4071 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4073 rc = lustre_lnet_config_ip2nets(&ip2nets,
4074 (found) ? &tunables : NULL,
4076 (seq_no) ? seq_no->cy_valueint : -1,
4080 * don't stop because there was no match. Continue processing the
4081 * rest of the rules. If non-match then nothing is configured
4083 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4084 rc = LUSTRE_CFG_RC_NO_ERR;
4086 list_for_each_entry_safe(intf_descr, intf_tmp,
4087 &ip2nets.ip2nets_net.nw_intflist,
4089 list_del(&intf_descr->intf_on_network);
4090 free_intf_descr(intf_descr);
4093 list_for_each_entry_safe(ip_range_descr, tmp,
4094 &ip2nets.ip2nets_ip_ranges,
4096 list_del(&ip_range_descr->ipr_entry);
4097 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4099 list_del(&el->el_link);
4100 cfs_expr_list_free(el);
4102 free(ip_range_descr);
4108 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4109 struct cYAML **err_rc)
4111 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4113 int num_entries, rc;
4114 struct lnet_dlc_network_descr nw_descr;
4116 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4117 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4119 net = cYAML_get_object_item(tree, "net type");
4121 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4123 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4124 if (local_nis == NULL)
4125 return LUSTRE_CFG_RC_MISSING_PARAM;
4127 if (!cYAML_is_sequence(local_nis))
4128 return LUSTRE_CFG_RC_BAD_PARAM;
4130 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4131 intf = cYAML_get_object_item(item, "interfaces");
4134 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4135 if (num_entries <= 0) {
4136 cYAML_build_error(num_entries, -1, "ni", "add",
4137 "bad interface list",
4139 return LUSTRE_CFG_RC_BAD_PARAM;
4143 seq_no = cYAML_get_object_item(tree, "seq_no");
4145 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4146 (seq_no) ? seq_no->cy_valueint : -1,
4152 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4153 char *prim_nid, bool del)
4155 struct cYAML *child = NULL, *entry = NULL;
4157 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4159 if (cYAML_is_sequence(nids_entry)) {
4160 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4161 entry = cYAML_get_object_item(child, "nid");
4162 /* don't count an empty entry */
4163 if (!entry || !entry->cy_valuestring)
4167 (strcmp(entry->cy_valuestring, prim_nid)
4170 * primary nid is present in the list of
4171 * nids so that means we want to delete
4172 * the entire peer, so no need to go
4173 * further. Just delete the entire peer.
4183 return LUSTRE_CFG_RC_MISSING_PARAM;
4185 nids = calloc(sizeof(*nids), num);
4187 return LUSTRE_CFG_RC_OUT_OF_MEM;
4189 /* now grab all the nids */
4192 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4193 entry = cYAML_get_object_item(child, "nid");
4194 if (!entry || !entry->cy_valuestring)
4197 nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
4199 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4202 strncpy(nids[num], entry->cy_valuestring,
4203 strlen(entry->cy_valuestring));
4213 yaml_free_string_array(nids, num);
4218 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4219 struct cYAML **err_rc)
4223 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4224 char err_str[LNET_MAX_STR_LEN];
4227 seq_no = cYAML_get_object_item(tree, "seq_no");
4228 prim_nid = cYAML_get_object_item(tree, "primary nid");
4229 mr = cYAML_get_object_item(tree, "Multi-Rail");
4230 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4231 peer_nis = cYAML_get_object_item(tree, "peer ni");
4233 if (ip2nets && (prim_nid || peer_nis)) {
4234 rc = LUSTRE_CFG_RC_BAD_PARAM;
4235 snprintf(err_str, sizeof(err_str),
4236 "ip2nets can not be specified along side prim_nid"
4237 " or peer ni fields");
4238 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4239 ADD_CMD, "peer", err_str, err_rc);
4246 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4248 else if (!strcmp(mr->cy_valuestring, "False"))
4251 rc = LUSTRE_CFG_RC_BAD_PARAM;
4252 snprintf(err_str, sizeof(err_str), "Bad MR value");
4253 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4254 ADD_CMD, "peer", err_str, err_rc);
4259 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4260 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4264 snprintf(err_str, sizeof(err_str),
4265 "error copying nids from YAML block");
4266 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4267 ADD_CMD, "peer", err_str, err_rc);
4271 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4272 nids, num, mr_value,
4273 (ip2nets) ? true : false,
4274 (seq_no) ? seq_no->cy_valueint : -1,
4277 yaml_free_string_array(nids, num);
4281 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4282 struct cYAML **err_rc)
4286 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4287 char err_str[LNET_MAX_STR_LEN];
4289 seq_no = cYAML_get_object_item(tree, "seq_no");
4290 prim_nid = cYAML_get_object_item(tree, "primary nid");
4291 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4292 peer_nis = cYAML_get_object_item(tree, "peer ni");
4294 if (ip2nets && (prim_nid || peer_nis)) {
4295 rc = LUSTRE_CFG_RC_BAD_PARAM;
4296 snprintf(err_str, sizeof(err_str),
4297 "ip2nets can not be specified along side prim_nid"
4298 " or peer ni fields");
4299 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4300 DEL_CMD, "peer", err_str, err_rc);
4304 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4305 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4308 snprintf(err_str, sizeof(err_str),
4309 "error copying nids from YAML block");
4310 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4311 ADD_CMD, "peer", err_str, err_rc);
4315 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4316 nids, num, (ip2nets) ? true : false,
4317 (seq_no) ? seq_no->cy_valueint : -1,
4320 yaml_free_string_array(nids, num);
4324 static int handle_yaml_config_buffers(struct cYAML *tree,
4325 struct cYAML **show_rc,
4326 struct cYAML **err_rc)
4329 struct cYAML *tiny, *small, *large, *seq_no;
4331 tiny = cYAML_get_object_item(tree, "tiny");
4332 small = cYAML_get_object_item(tree, "small");
4333 large = cYAML_get_object_item(tree, "large");
4334 seq_no = cYAML_get_object_item(tree, "seq_no");
4336 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4337 (small) ? small->cy_valueint : -1,
4338 (large) ? large->cy_valueint : -1,
4339 (seq_no) ? seq_no->cy_valueint : -1,
4345 static int handle_yaml_config_routing(struct cYAML *tree,
4346 struct cYAML **show_rc,
4347 struct cYAML **err_rc)
4349 int rc = LUSTRE_CFG_RC_NO_ERR;
4350 struct cYAML *seq_no, *enable;
4352 seq_no = cYAML_get_object_item(tree, "seq_no");
4353 enable = cYAML_get_object_item(tree, "enable");
4356 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4358 seq_no->cy_valueint : -1,
4365 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4366 struct cYAML **err_rc)
4370 struct cYAML *seq_no;
4372 net = cYAML_get_object_item(tree, "net");
4373 gw = cYAML_get_object_item(tree, "gateway");
4374 seq_no = cYAML_get_object_item(tree, "seq_no");
4376 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4377 (gw) ? gw->cy_valuestring : NULL,
4378 (seq_no) ? seq_no->cy_valueint : -1,
4382 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4383 struct cYAML **err_rc)
4385 struct cYAML *seq_no;
4387 seq_no = cYAML_get_object_item(tree, "seq_no");
4389 return lustre_lnet_enable_routing(0, (seq_no) ?
4390 seq_no->cy_valueint : -1,
4394 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4395 struct cYAML **err_rc)
4401 struct cYAML *detail;
4402 struct cYAML *seq_no;
4404 net = cYAML_get_object_item(tree, "net");
4405 gw = cYAML_get_object_item(tree, "gateway");
4406 hop = cYAML_get_object_item(tree, "hop");
4407 prio = cYAML_get_object_item(tree, "priority");
4408 detail = cYAML_get_object_item(tree, "detail");
4409 seq_no = cYAML_get_object_item(tree, "seq_no");
4411 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4412 (gw) ? gw->cy_valuestring : NULL,
4413 (hop) ? hop->cy_valueint : -1,
4414 (prio) ? prio->cy_valueint : -1,
4415 (detail) ? detail->cy_valueint : 0,
4416 (seq_no) ? seq_no->cy_valueint : -1,
4417 show_rc, err_rc, false);
4420 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4421 struct cYAML **err_rc)
4423 struct cYAML *net, *detail, *seq_no;
4425 net = cYAML_get_object_item(tree, "net");
4426 detail = cYAML_get_object_item(tree, "detail");
4427 seq_no = cYAML_get_object_item(tree, "seq_no");
4429 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4430 (detail) ? detail->cy_valueint : 0,
4431 (seq_no) ? seq_no->cy_valueint : -1,
4432 show_rc, err_rc, false);
4435 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4436 struct cYAML **err_rc)
4438 struct cYAML *seq_no;
4440 seq_no = cYAML_get_object_item(tree, "seq_no");
4442 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4443 show_rc, err_rc, false);
4446 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4447 struct cYAML **err_rc)
4449 struct cYAML *seq_no, *nid, *detail;
4451 seq_no = cYAML_get_object_item(tree, "seq_no");
4452 detail = cYAML_get_object_item(tree, "detail");
4453 nid = cYAML_get_object_item(tree, "nid");
4455 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4456 (detail) ? detail->cy_valueint : 0,
4457 (seq_no) ? seq_no->cy_valueint : -1,
4458 show_rc, err_rc, false);
4461 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4462 struct cYAML **err_rc)
4464 struct cYAML *seq_no;
4466 seq_no = cYAML_get_object_item(tree, "seq_no");
4468 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4472 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4473 struct cYAML **err_rc)
4475 struct cYAML *seq_no, *range;
4477 seq_no = cYAML_get_object_item(tree, "seq_no");
4478 range = cYAML_get_object_item(tree, "range");
4480 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4481 seq_no ? seq_no->cy_valueint : -1,
4485 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4486 struct cYAML **err_rc)
4488 struct cYAML *seq_no;
4490 seq_no = cYAML_get_object_item(tree, "seq_no");
4492 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4496 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4497 struct cYAML **err_rc)
4499 struct cYAML *seq_no;
4501 seq_no = cYAML_get_object_item(tree, "seq_no");
4503 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4507 static int handle_yaml_config_global_settings(struct cYAML *tree,
4508 struct cYAML **show_rc,
4509 struct cYAML **err_rc)
4511 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4515 seq_no = cYAML_get_object_item(tree, "seq_no");
4516 max_intf = cYAML_get_object_item(tree, "max_intf");
4518 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4519 seq_no ? seq_no->cy_valueint
4523 numa = cYAML_get_object_item(tree, "numa_range");
4525 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4526 seq_no ? seq_no->cy_valueint
4530 discovery = cYAML_get_object_item(tree, "discovery");
4532 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4533 seq_no ? seq_no->cy_valueint
4537 retry = cYAML_get_object_item(tree, "retry_count");
4539 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4540 seq_no ? seq_no->cy_valueint
4544 tto = cYAML_get_object_item(tree, "transaction_timeout");
4546 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4547 seq_no ? seq_no->cy_valueint
4551 sen = cYAML_get_object_item(tree, "health_sensitivity");
4553 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4554 seq_no ? seq_no->cy_valueint
4561 static int handle_yaml_del_global_settings(struct cYAML *tree,
4562 struct cYAML **show_rc,
4563 struct cYAML **err_rc)
4565 struct cYAML *max_intf, *numa, *discovery, *seq_no;
4568 seq_no = cYAML_get_object_item(tree, "seq_no");
4569 max_intf = cYAML_get_object_item(tree, "max_intf");
4571 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4572 seq_no ? seq_no->cy_valueint
4576 numa = cYAML_get_object_item(tree, "numa_range");
4578 rc = lustre_lnet_config_numa_range(0,
4579 seq_no ? seq_no->cy_valueint
4583 /* peer discovery is enabled by default */
4584 discovery = cYAML_get_object_item(tree, "discovery");
4586 rc = lustre_lnet_config_discovery(1,
4587 seq_no ? seq_no->cy_valueint
4594 static int handle_yaml_show_global_settings(struct cYAML *tree,
4595 struct cYAML **show_rc,
4596 struct cYAML **err_rc)
4598 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4602 seq_no = cYAML_get_object_item(tree, "seq_no");
4603 max_intf = cYAML_get_object_item(tree, "max_intf");
4605 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4609 numa = cYAML_get_object_item(tree, "numa_range");
4611 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4615 discovery = cYAML_get_object_item(tree, "discovery");
4617 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4621 retry = cYAML_get_object_item(tree, "retry_count");
4623 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4627 tto = cYAML_get_object_item(tree, "transaction_timeout");
4629 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4633 sen = cYAML_get_object_item(tree, "health_sensitivity");
4635 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4642 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4643 struct cYAML **err_rc)
4645 struct cYAML *seq_no, *nid, *timeout;
4647 seq_no = cYAML_get_object_item(tree, "seq_no");
4648 nid = cYAML_get_object_item(tree, "primary nid");
4649 timeout = cYAML_get_object_item(tree, "timeout");
4651 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4652 (timeout) ? timeout->cy_valueint : 1000,
4653 (seq_no) ? seq_no->cy_valueint : -1,
4657 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4658 struct cYAML **err_rc)
4660 struct cYAML *seq_no, *nid, *force;
4662 seq_no = cYAML_get_object_item(tree, "seq_no");
4663 nid = cYAML_get_object_item(tree, "primary nid");
4664 force = cYAML_get_object_item(tree, "force");
4666 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4667 (force) ? force->cy_valueint : 0,
4668 (seq_no) ? seq_no->cy_valueint : -1,
4672 static int handle_yaml_no_op()
4674 return LUSTRE_CFG_RC_NO_ERR;
4677 struct lookup_cmd_hdlr_tbl {
4682 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4683 { .name = "route", .cb = handle_yaml_config_route },
4684 { .name = "net", .cb = handle_yaml_config_ni },
4685 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4686 { .name = "peer", .cb = handle_yaml_config_peer },
4687 { .name = "routing", .cb = handle_yaml_config_routing },
4688 { .name = "buffers", .cb = handle_yaml_config_buffers },
4689 { .name = "statistics", .cb = handle_yaml_no_op },
4690 { .name = "global", .cb = handle_yaml_config_global_settings},
4691 { .name = "numa", .cb = handle_yaml_config_numa },
4692 { .name = "ping", .cb = handle_yaml_no_op },
4693 { .name = "discover", .cb = handle_yaml_no_op },
4696 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4697 { .name = "route", .cb = handle_yaml_del_route },
4698 { .name = "net", .cb = handle_yaml_del_ni },
4699 { .name = "ip2nets", .cb = handle_yaml_no_op },
4700 { .name = "peer", .cb = handle_yaml_del_peer },
4701 { .name = "routing", .cb = handle_yaml_del_routing },
4702 { .name = "buffers", .cb = handle_yaml_no_op },
4703 { .name = "statistics", .cb = handle_yaml_no_op },
4704 { .name = "global", .cb = handle_yaml_del_global_settings},
4705 { .name = "numa", .cb = handle_yaml_del_numa },
4706 { .name = "ping", .cb = handle_yaml_no_op },
4707 { .name = "discover", .cb = handle_yaml_no_op },
4710 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4711 { .name = "route", .cb = handle_yaml_show_route },
4712 { .name = "net", .cb = handle_yaml_show_net },
4713 { .name = "peer", .cb = handle_yaml_show_peers },
4714 { .name = "ip2nets", .cb = handle_yaml_no_op },
4715 { .name = "routing", .cb = handle_yaml_show_routing },
4716 { .name = "buffers", .cb = handle_yaml_show_routing },
4717 { .name = "statistics", .cb = handle_yaml_show_stats },
4718 { .name = "global", .cb = handle_yaml_show_global_settings},
4719 { .name = "numa", .cb = handle_yaml_show_numa },
4720 { .name = "ping", .cb = handle_yaml_no_op },
4721 { .name = "discover", .cb = handle_yaml_no_op },
4724 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4725 { .name = "route", .cb = handle_yaml_no_op },
4726 { .name = "net", .cb = handle_yaml_no_op },
4727 { .name = "peer", .cb = handle_yaml_no_op },
4728 { .name = "ip2nets", .cb = handle_yaml_no_op },
4729 { .name = "routing", .cb = handle_yaml_no_op },
4730 { .name = "buffers", .cb = handle_yaml_no_op },
4731 { .name = "statistics", .cb = handle_yaml_no_op },
4732 { .name = "global", .cb = handle_yaml_no_op },
4733 { .name = "numa", .cb = handle_yaml_no_op },
4734 { .name = "ping", .cb = handle_yaml_ping },
4735 { .name = "discover", .cb = handle_yaml_discover },
4738 static cmd_handler_t lookup_fn(char *key,
4739 struct lookup_cmd_hdlr_tbl *tbl)
4745 for (i = 0; tbl[i].name != NULL; i++) {
4746 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4753 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4754 struct cYAML **show_rc, struct cYAML **err_rc)
4756 struct cYAML *tree, *item = NULL, *head, *child;
4758 char err_str[LNET_MAX_STR_LEN];
4759 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4761 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4763 return LUSTRE_CFG_RC_BAD_PARAM;
4765 child = tree->cy_child;
4766 while (child != NULL) {
4767 cb = lookup_fn(child->cy_string, table);
4769 snprintf(err_str, sizeof(err_str),
4770 "\"call back for '%s' not found\"",
4772 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4773 "yaml", "helper", err_str, err_rc);
4777 if (cYAML_is_sequence(child)) {
4778 while ((head = cYAML_get_next_seq_item(child, &item))
4780 rc = cb(head, show_rc, err_rc);
4781 if (rc != LUSTRE_CFG_RC_NO_ERR)
4785 rc = cb(child, show_rc, err_rc);
4786 if (rc != LUSTRE_CFG_RC_NO_ERR)
4790 child = child->cy_next;
4794 cYAML_free_tree(tree);
4799 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4801 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4805 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4807 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4811 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4813 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4817 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4819 return lustre_yaml_cb_helper(f, lookup_exec_tbl,