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 memcpy(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 (ping.ping_buf[i].nid == LNET_NID_LO_0)
607 peer_ni = cYAML_create_seq_item(tmp);
610 memset(buf, 0, sizeof buf);
611 snprintf(buf, sizeof buf, "nid");
612 if (cYAML_create_string(peer_ni, buf,
613 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
619 } while ((token = strtok(NULL, ",")) != NULL);
622 rc = LUSTRE_CFG_RC_NO_ERR;
627 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
628 cYAML_free_tree(root);
629 } else if (show_rc != NULL && *show_rc != NULL) {
630 struct cYAML *show_node;
631 show_node = cYAML_get_object_item(*show_rc, oper);
632 if (show_node != NULL && cYAML_is_sequence(show_node)) {
633 cYAML_insert_child(show_node, first_seq);
636 } else if (show_node == NULL) {
637 cYAML_insert_sibling((*show_rc)->cy_child,
641 cYAML_free_tree(root);
650 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
651 struct cYAML **show_rc, struct cYAML **err_rc)
655 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
656 seq_no, show_rc, err_rc);
660 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
661 struct cYAML **show_rc, struct cYAML **err_rc)
665 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
666 seq_no, show_rc, err_rc);
670 static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
672 struct lustre_lnet_ip_range_descr *ipr, *tmp;
673 struct cfs_expr_list *el, *el_tmp;
675 list_for_each_entry_safe(ipr, tmp,
676 &ip2nets->ip2nets_ip_ranges,
678 list_del(&ipr->ipr_entry);
679 list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
681 list_del(&el->el_link);
682 cfs_expr_list_free(el);
689 * returns an rc < 0 if there is an error
690 * otherwise it returns the number IPs generated
691 * it also has out params: net - network name
693 static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
694 struct lustre_lnet_ip2nets *ip2nets,
695 __u32 *net, char *err_str)
697 struct lustre_lnet_ip_range_descr *ipr;
699 int ip_idx = MAX_NUM_IPS - 1;
700 int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
702 char ip_range[LNET_MAX_STR_LEN];
704 /* separate the two components of the NID */
706 comp2 = strchr(nidstr, '@');
710 "\"cannot parse NID %s\"", nidstr);
711 err_str[LNET_MAX_STR_LEN - 1] = '\0';
712 rc = LUSTRE_CFG_RC_BAD_PARAM;
716 /* length of the expected ip-range */
717 ip_range_len = comp2 - comp1;
718 if (ip_range_len >= LNET_MAX_STR_LEN) {
721 "\"too long ip_range '%s'\"", nidstr);
722 err_str[LNET_MAX_STR_LEN - 1] = '\0';
723 rc = LUSTRE_CFG_RC_BAD_PARAM;
727 /* move beyond '@' */
731 * if the net component is either o2ib or tcp then we expect
732 * an IP range which could only be a single IP address.
735 *net = libcfs_str2net(comp2);
736 net_type = LNET_NETTYP(*net);
737 /* expression support is for o2iblnd and socklnd only */
738 if (net_type != O2IBLND && net_type != SOCKLND)
739 return LUSTRE_CFG_RC_SKIP;
741 strncpy(ip_range, comp1, ip_range_len);
742 ip_range[ip_range_len] = '\0';
743 ip2nets->ip2nets_net.nw_id = *net;
745 rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
746 if (rc != LUSTRE_CFG_RC_NO_ERR) {
749 "\"cannot parse ip_range '%.100s'\"", ip_range);
750 err_str[LNET_MAX_STR_LEN - 1] = '\0';
751 rc = LUSTRE_CFG_RC_BAD_PARAM;
756 * Generate all the IP Addresses from the parsed range. For sanity
757 * we allow only a max of MAX_NUM_IPS nids to be configured for
760 list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
761 ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
764 if (ip_idx == MAX_NUM_IPS - 1) {
765 snprintf(err_str, LNET_MAX_STR_LEN,
766 "no NIDs provided for configuration");
767 err_str[LNET_MAX_STR_LEN - 1] = '\0';
768 rc = LUSTRE_CFG_RC_NO_MATCH;
770 } else if (ip_idx == -1) {
771 rc = LUSTRE_CFG_RC_LAST_ELEM;
780 static int lustre_lnet_handle_peer_ip2nets(char **nid, int num_nids, bool mr,
781 bool range, __u32 cmd,
782 char *cmd_type, char *err_str)
784 __u32 net = LNET_NIDNET(LNET_NID_ANY);
786 int i, j, rc = LUSTRE_CFG_RC_NO_ERR;
787 __u32 ip_list[MAX_NUM_IPS];
788 struct lustre_lnet_ip2nets ip2nets;
789 struct lnet_ioctl_peer_cfg data;
791 lnet_nid_t prim_nid = LNET_NID_ANY;
793 /* initialize all lists */
794 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
795 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
796 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
798 /* each nid entry is an expression */
799 for (i = 0; i < num_nids; i++) {
800 if (!range && i == 0)
801 prim_nid = libcfs_str2nid(nid[0]);
803 prim_nid = LNET_NID_ANY;
805 rc = lnet_expr2ips(nid[i], ip_list, &ip2nets, &net, err_str);
806 if (rc == LUSTRE_CFG_RC_SKIP)
808 else if (rc == LUSTRE_CFG_RC_LAST_ELEM)
810 else if (rc < LUSTRE_CFG_RC_NO_ERR)
815 for (j = MAX_NUM_IPS - 1; j > ip_idx; j--) {
816 peer_nid = LNET_MKNID(net, ip_list[j]);
817 if (peer_nid == LNET_NID_ANY) {
820 "\"cannot parse NID\"");
821 err_str[LNET_MAX_STR_LEN - 1] = '\0';
822 rc = LUSTRE_CFG_RC_BAD_PARAM;
826 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
829 if (prim_nid == LNET_NID_ANY && j == MAX_NUM_IPS - 1) {
831 peer_nid = LNET_NID_ANY;
834 if (!range && num_nids > 1 && i == 0 &&
835 cmd == IOC_LIBCFS_DEL_PEER_NI)
837 else if (!range && i == 0)
838 peer_nid = LNET_NID_ANY;
841 * If prim_nid is not provided then the first nid in the
842 * list becomes the prim_nid. First time round the loop
843 * use LNET_NID_ANY for the first parameter, then use
844 * nid[0] as the key nid after wards
846 rc = dispatch_peer_ni_cmd(prim_nid, peer_nid, cmd,
847 &data, err_str, cmd_type);
852 * we just deleted the entire peer using the
853 * primary_nid. So don't bother iterating through
854 * the rest of the nids
856 if (prim_nid != LNET_NID_ANY &&
857 peer_nid == LNET_NID_ANY &&
858 cmd == IOC_LIBCFS_DEL_PEER_NI)
862 lustre_lnet_clean_ip2nets(&ip2nets);
866 lustre_lnet_clean_ip2nets(&ip2nets);
870 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
871 bool mr, bool ip2nets, int seq_no,
872 struct cYAML **err_rc)
874 int rc = LUSTRE_CFG_RC_NO_ERR;
875 char err_str[LNET_MAX_STR_LEN] = {0};
876 char **nid_array = NULL;
878 snprintf(err_str, sizeof(err_str), "\"Success\"");
881 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, mr,
882 ip2nets, IOC_LIBCFS_ADD_PEER_NI,
888 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
889 snprintf(err_str, sizeof(err_str),
890 "bad primary NID: '%s'",
892 rc = LUSTRE_CFG_RC_MISSING_PARAM;
898 nid_array = calloc(sizeof(*nid_array), num_nids);
900 snprintf(err_str, sizeof(err_str),
902 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
906 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
909 rc = lustre_lnet_handle_peer_ip2nets((pnid) ? nid_array : nid,
910 num_nids, mr, ip2nets,
911 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
920 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
924 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
925 bool ip2nets, int seq_no, struct cYAML **err_rc)
927 int rc = LUSTRE_CFG_RC_NO_ERR;
928 char err_str[LNET_MAX_STR_LEN] = {0};
929 char **nid_array = NULL;
931 snprintf(err_str, sizeof(err_str), "\"Success\"");
934 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, false,
935 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
941 snprintf(err_str, sizeof(err_str),
942 "\"Primary nid is not provided\"");
943 rc = LUSTRE_CFG_RC_MISSING_PARAM;
945 } else if (!ip2nets) {
946 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
947 rc = LUSTRE_CFG_RC_BAD_PARAM;
948 snprintf(err_str, sizeof(err_str),
956 nid_array = calloc(sizeof(*nid_array), num_nids);
958 snprintf(err_str, sizeof(err_str),
960 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
964 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
966 rc = lustre_lnet_handle_peer_ip2nets(nid_array, num_nids, false,
967 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
976 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
980 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
981 int seq_no, struct cYAML **err_rc)
983 struct lnet_ioctl_config_data data;
984 lnet_nid_t gateway_nid;
985 int rc = LUSTRE_CFG_RC_NO_ERR;
987 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
988 __u32 net = LNET_NIDNET(LNET_NID_ANY);
989 char err_str[LNET_MAX_STR_LEN];
990 __u32 ip_list[MAX_NUM_IPS];
991 struct lustre_lnet_ip2nets ip2nets;
993 /* initialize all lists */
994 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
995 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
996 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
998 snprintf(err_str, sizeof(err_str), "\"Success\"");
1000 if (nw == NULL || gw == NULL) {
1003 "\"missing mandatory parameter in route config:'%s'\"",
1004 (nw == NULL && gw == NULL) ? "network, gateway" :
1005 (nw == NULL) ? "network" : "gateway");
1006 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1010 rnet = libcfs_str2net(nw);
1011 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1014 "\"cannot parse remote net %s\"", nw);
1015 rc = LUSTRE_CFG_RC_BAD_PARAM;
1020 /* hops is undefined */
1021 hops = LNET_UNDEFINED_HOPS;
1022 } else if (hops < 1 || hops > 255) {
1025 "\"invalid hop count %d, must be between 1 and 255\"",
1027 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1033 } else if (prio < 0) {
1036 "\"invalid priority %d, must be greater than 0\"",
1038 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1042 rc = lnet_expr2ips(gw, ip_list,
1043 &ip2nets, &net, err_str);
1044 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1046 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1051 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1052 data.cfg_net = rnet;
1053 data.cfg_config_u.cfg_route.rtr_hop = hops;
1054 data.cfg_config_u.cfg_route.rtr_priority = prio;
1056 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1057 gateway_nid = LNET_MKNID(net, ip_list[i]);
1058 if (gateway_nid == LNET_NID_ANY) {
1061 "\"cannot form gateway NID: %u\"",
1063 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1064 rc = LUSTRE_CFG_RC_BAD_PARAM;
1067 data.cfg_nid = gateway_nid;
1069 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1074 "\"cannot add route: %s\"", strerror(errno));
1079 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1084 int lustre_lnet_del_route(char *nw, char *gw,
1085 int seq_no, struct cYAML **err_rc)
1087 struct lnet_ioctl_config_data data;
1088 lnet_nid_t gateway_nid;
1089 int rc = LUSTRE_CFG_RC_NO_ERR;
1090 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1091 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1092 char err_str[LNET_MAX_STR_LEN];
1094 __u32 ip_list[MAX_NUM_IPS];
1095 struct lustre_lnet_ip2nets ip2nets;
1097 /* initialize all lists */
1098 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1099 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1100 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1102 snprintf(err_str, sizeof(err_str), "\"Success\"");
1104 if (nw == NULL || gw == NULL) {
1107 "\"missing mandatory parameter in route delete: '%s'\"",
1108 (nw == NULL && gw == NULL) ? "network, gateway" :
1109 (nw == NULL) ? "network" : "gateway");
1110 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1114 rnet = libcfs_str2net(nw);
1115 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1118 "\"cannot parse remote net '%s'\"", nw);
1119 rc = LUSTRE_CFG_RC_BAD_PARAM;
1123 rc = lnet_expr2ips(gw, ip_list,
1124 &ip2nets, &net, err_str);
1125 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1127 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1132 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1133 data.cfg_net = rnet;
1135 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1136 gateway_nid = LNET_MKNID(net, ip_list[i]);
1137 if (gateway_nid == LNET_NID_ANY) {
1140 "\"cannot form gateway NID: %u\"",
1142 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1143 rc = LUSTRE_CFG_RC_BAD_PARAM;
1146 data.cfg_nid = gateway_nid;
1148 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1153 "\"cannot delete route: %s\"", strerror(errno));
1158 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1163 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1164 int seq_no, struct cYAML **show_rc,
1165 struct cYAML **err_rc, bool backup)
1167 struct lnet_ioctl_config_data data;
1168 lnet_nid_t gateway_nid;
1169 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1171 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1173 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1174 struct cYAML *first_seq = NULL;
1175 char err_str[LNET_MAX_STR_LEN];
1178 snprintf(err_str, sizeof(err_str),
1179 "\"out of memory\"");
1182 net = libcfs_str2net(nw);
1183 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1186 "\"cannot parse net '%s'\"", nw);
1187 rc = LUSTRE_CFG_RC_BAD_PARAM;
1192 /* show all routes without filtering on net */
1193 net = LNET_NIDNET(LNET_NID_ANY);
1197 gateway_nid = libcfs_str2nid(gw);
1198 if (gateway_nid == LNET_NID_ANY) {
1201 "\"cannot parse gateway NID '%s'\"", gw);
1202 rc = LUSTRE_CFG_RC_BAD_PARAM;
1206 /* show all routes with out filtering on gateway */
1207 gateway_nid = LNET_NID_ANY;
1209 if ((hops < 1 && hops != -1) || hops > 255) {
1212 "\"invalid hop count %d, must be between 0 and 256\"",
1214 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1218 /* create struct cYAML root object */
1219 root = cYAML_create_object(NULL, NULL);
1223 route = cYAML_create_seq(root, "route");
1228 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1231 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1237 /* filter on provided data */
1238 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1239 net != data.cfg_net)
1242 if (gateway_nid != LNET_NID_ANY &&
1243 gateway_nid != data.cfg_nid)
1247 hops != data.cfg_config_u.cfg_route.rtr_hop)
1251 prio != data.cfg_config_u.cfg_route.rtr_priority)
1254 /* default rc to -1 incase we hit the goto */
1258 item = cYAML_create_seq_item(route);
1262 if (first_seq == NULL)
1265 if (cYAML_create_string(item, "net",
1266 libcfs_net2str(data.cfg_net)) == NULL)
1269 if (cYAML_create_string(item, "gateway",
1270 libcfs_nid2str(data.cfg_nid)) == NULL)
1274 if (cYAML_create_number(item, "hop",
1275 (int) data.cfg_config_u.
1276 cfg_route.rtr_hop) ==
1280 if (cYAML_create_number(item, "priority",
1282 cfg_route.rtr_priority) == NULL)
1286 cYAML_create_string(item, "state",
1287 data.cfg_config_u.cfg_route.
1289 "up" : "down") == NULL)
1294 /* print output iff show_rc is not provided */
1295 if (show_rc == NULL)
1296 cYAML_print_tree(root);
1298 if (l_errno != ENOENT) {
1301 "\"cannot get routes: %s\"",
1306 rc = LUSTRE_CFG_RC_NO_ERR;
1308 snprintf(err_str, sizeof(err_str), "\"success\"");
1310 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1311 cYAML_free_tree(root);
1312 } else if (show_rc != NULL && *show_rc != NULL) {
1313 struct cYAML *show_node;
1314 /* find the route node, if one doesn't exist then
1315 * insert one. Otherwise add to the one there
1317 show_node = cYAML_get_object_item(*show_rc, "route");
1318 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1319 cYAML_insert_child(show_node, first_seq);
1322 } else if (show_node == NULL) {
1323 cYAML_insert_sibling((*show_rc)->cy_child,
1327 cYAML_free_tree(root);
1333 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1338 static int socket_intf_query(int request, char *intf,
1344 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1345 return LUSTRE_CFG_RC_BAD_PARAM;
1347 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1349 return LUSTRE_CFG_RC_BAD_PARAM;
1351 strcpy(ifr->ifr_name, intf);
1352 rc = ioctl(sockfd, request, ifr);
1354 rc = LUSTRE_CFG_RC_BAD_PARAM;
1361 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1366 memset(&ifr, 0, sizeof(ifr));
1367 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1369 return LUSTRE_CFG_RC_BAD_PARAM;
1371 if ((ifr.ifr_flags & IFF_UP) == 0)
1372 return LUSTRE_CFG_RC_BAD_PARAM;
1374 memset(&ifr, 0, sizeof(ifr));
1375 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1377 return LUSTRE_CFG_RC_BAD_PARAM;
1379 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1380 *ip = bswap_32(*ip);
1382 return LUSTRE_CFG_RC_NO_ERR;
1386 * for each interface in the array of interfaces find the IP address of
1387 * that interface, create its nid and add it to an array of NIDs.
1388 * Stop if any of the interfaces is down
1390 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1391 lnet_nid_t **nids, __u32 *nnids,
1392 char *err_str, size_t str_len)
1394 int i = 0, count = 0, rc;
1395 struct lnet_dlc_intf_descr *intf;
1396 char val[LNET_MAX_STR_LEN];
1401 if (nw == NULL || nids == NULL) {
1402 snprintf(err_str, str_len,
1403 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1404 err_str[str_len - 1] = '\0';
1405 return LUSTRE_CFG_RC_BAD_PARAM;
1408 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1411 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1415 *nids = calloc(count, sizeof(lnet_nid_t));
1416 if (*nids == NULL) {
1417 snprintf(err_str, str_len,
1418 "\"out of memory\"");
1419 err_str[str_len - 1] = '\0';
1420 return LUSTRE_CFG_RC_OUT_OF_MEM;
1423 * special case the GNI interface since it doesn't have an IP
1424 * address. The assumption is that there can only be one GNI
1425 * interface in the system. No interface name is provided.
1427 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1428 rc = read_sysfs_file(gni_nid_path, "nid", val,
1431 snprintf(err_str, str_len,
1432 "\"cannot read gni nid\"");
1433 err_str[str_len - 1] = '\0';
1436 gni_num = atoi(val);
1438 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1443 /* look at the other interfaces */
1444 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1445 rc = lustre_lnet_queryip(intf, &ip);
1446 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1447 snprintf(err_str, str_len,
1448 "\"couldn't query intf %s\"", intf->intf_name);
1449 err_str[str_len - 1] = '\0';
1452 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1468 * called repeatedly until a match or no more ip range
1470 * ip_range expression
1471 * interface list with all the interface names.
1472 * all the interfaces in the system.
1474 * try to match the ip_range expr to one of the interfaces' IPs in
1475 * the system. If we hit a patch for an interface. Check if that
1476 * interface name is in the list.
1478 * If there are more than one interface in the list, then make sure
1479 * that the IPs for all of these interfaces match the ip ranges
1482 * for each interface in intf_list
1483 * look up the intf name in ifa
1484 * if not there then no match
1485 * check ip obtained from ifa against a match to any of the
1487 * If no match, then fail
1489 * The result is that all the interfaces have to match.
1491 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1492 struct list_head *intf_list,
1493 struct list_head *ip_ranges)
1497 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1498 struct ifaddrs *ifaddr = ifa;
1499 struct lustre_lnet_ip_range_descr *ip_range;
1503 * if there are no explicit interfaces, and no ip ranges, then
1504 * configure the first tcp interface we encounter.
1506 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1507 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1508 if (ifaddr->ifa_addr == NULL)
1511 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1514 family = ifaddr->ifa_addr->sa_family;
1515 if (family == AF_INET &&
1516 strcmp(ifaddr->ifa_name, "lo") != 0) {
1517 rc = lustre_lnet_add_intf_descr
1518 (intf_list, ifaddr->ifa_name,
1519 strlen(ifaddr->ifa_name));
1521 if (rc != LUSTRE_CFG_RC_NO_ERR)
1524 return LUSTRE_CFG_RC_MATCH;
1527 return LUSTRE_CFG_RC_NO_MATCH;
1531 * First interface which matches an IP pattern will be used
1533 if (list_empty(intf_list)) {
1535 * no interfaces provided in the rule, but an ip range is
1536 * provided, so try and match an interface to the ip
1539 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1540 if (ifaddr->ifa_addr == NULL)
1543 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1546 family = ifaddr->ifa_addr->sa_family;
1547 if (family == AF_INET) {
1548 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1551 list_for_each_entry(ip_range, ip_ranges,
1553 rc = cfs_ip_addr_match(bswap_32(ip),
1554 &ip_range->ipr_expr);
1558 rc = lustre_lnet_add_intf_descr
1559 (intf_list, ifaddr->ifa_name,
1560 strlen(ifaddr->ifa_name));
1562 if (rc != LUSTRE_CFG_RC_NO_ERR)
1568 if (!list_empty(intf_list))
1569 return LUSTRE_CFG_RC_MATCH;
1571 return LUSTRE_CFG_RC_NO_MATCH;
1575 * If an interface is explicitly specified the ip-range might or
1576 * might not be specified. if specified the interface needs to match the
1577 * ip-range. If no ip-range then the interfaces are
1578 * automatically matched if they are all up.
1579 * If > 1 interfaces all the interfaces must match for the NI to
1582 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1583 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1584 if (ifaddr->ifa_addr == NULL)
1587 family = ifaddr->ifa_addr->sa_family;
1588 if (family == AF_INET &&
1589 strcmp(intf_descr->intf_name,
1590 ifaddr->ifa_name) == 0)
1594 if (ifaddr == NULL) {
1595 list_del(&intf_descr->intf_on_network);
1596 free_intf_descr(intf_descr);
1600 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1601 list_del(&intf_descr->intf_on_network);
1602 free_intf_descr(intf_descr);
1606 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1609 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1610 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1616 /* no match for this interface */
1617 list_del(&intf_descr->intf_on_network);
1618 free_intf_descr(intf_descr);
1622 return LUSTRE_CFG_RC_MATCH;
1625 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1626 lnet_nid_t **nids, __u32 *nnids,
1627 char *err_str, size_t str_len)
1629 struct ifaddrs *ifa;
1630 int rc = LUSTRE_CFG_RC_NO_ERR;
1632 rc = getifaddrs(&ifa);
1634 snprintf(err_str, str_len,
1635 "\"failed to get interface addresses: %d\"", -errno);
1636 err_str[str_len - 1] = '\0';
1640 rc = lustre_lnet_match_ip_to_intf(ifa,
1641 &ip2nets->ip2nets_net.nw_intflist,
1642 &ip2nets->ip2nets_ip_ranges);
1643 if (rc != LUSTRE_CFG_RC_MATCH) {
1644 snprintf(err_str, str_len,
1645 "\"couldn't match ip to existing interfaces\"");
1646 err_str[str_len - 1] = '\0';
1651 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1652 err_str, sizeof(err_str));
1653 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1664 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1665 struct lnet_ioctl_config_lnd_tunables *tunables,
1666 struct cfs_expr_list *global_cpts,
1667 lnet_nid_t *nids, char *err_str)
1670 struct lnet_ioctl_config_ni *conf;
1671 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1672 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1675 struct lnet_dlc_intf_descr *intf_descr;
1677 struct cfs_expr_list *cpt_expr;
1679 list_for_each_entry(intf_descr, intf_list,
1681 if (tunables != NULL)
1682 len = sizeof(struct lnet_ioctl_config_ni) +
1683 sizeof(struct lnet_ioctl_config_lnd_tunables);
1685 len = sizeof(struct lnet_ioctl_config_ni);
1687 data = calloc(1, len);
1689 return LUSTRE_CFG_RC_OUT_OF_MEM;
1690 conf = (struct lnet_ioctl_config_ni*) data;
1691 if (tunables != NULL)
1692 tun = (struct lnet_ioctl_config_lnd_tunables*)
1695 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1696 conf->lic_cfg_hdr.ioc_len = len;
1697 conf->lic_nid = nids[i];
1698 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1701 if (intf_descr->cpt_expr != NULL)
1702 cpt_expr = intf_descr->cpt_expr;
1703 else if (global_cpts != NULL)
1704 cpt_expr = global_cpts;
1708 if (cpt_expr != NULL) {
1709 count = cfs_expr_list_values(cpt_expr,
1710 LNET_MAX_SHOW_NUM_CPT,
1713 memcpy(conf->lic_cpts, cpt_array,
1714 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1723 conf->lic_ncpts = count;
1725 if (tunables != NULL)
1726 memcpy(tun, tunables, sizeof(*tunables));
1728 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1733 "\"cannot add network: %s\"", strerror(errno));
1741 return LUSTRE_CFG_RC_NO_ERR;
1745 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1746 struct lnet_ioctl_config_lnd_tunables *tunables,
1747 struct cfs_expr_list *global_cpts,
1748 int seq_no, struct cYAML **err_rc)
1750 lnet_nid_t *nids = NULL;
1753 char err_str[LNET_MAX_STR_LEN];
1755 snprintf(err_str, sizeof(err_str), "\"success\"");
1760 "\"incomplete ip2nets information\"");
1761 rc = LUSTRE_CFG_RC_BAD_PARAM;
1766 * call below function to resolve the rules into a list of nids.
1767 * The memory is allocated in that function then freed here when
1768 * it's no longer needed.
1770 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1772 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1775 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1776 snprintf(err_str, sizeof(err_str),
1777 "\"no interfaces match ip2nets rules\"");
1781 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1782 tunables, global_cpts, nids,
1789 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1793 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1794 struct cfs_expr_list *global_cpts,
1796 struct lnet_ioctl_config_lnd_tunables *tunables,
1797 int seq_no, struct cYAML **err_rc)
1800 struct lnet_ioctl_config_ni *conf;
1801 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1802 char buf[LNET_MAX_STR_LEN];
1803 int rc = LUSTRE_CFG_RC_NO_ERR;
1804 char err_str[LNET_MAX_STR_LEN];
1805 lnet_nid_t *nids = NULL;
1809 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1812 snprintf(err_str, sizeof(err_str), "\"success\"");
1814 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1815 (list_empty(&nw_descr->nw_intflist) &&
1816 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1819 "\"missing mandatory parameters in NI config: '%s'\"",
1820 (nw_descr == NULL) ? "network , interface" :
1821 (nw_descr->nw_id == 0) ? "network" : "interface");
1822 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1826 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1829 "\"ip2net string too long %d\"",
1830 (int)strlen(ip2net));
1831 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1835 if (ip2net != NULL) {
1836 if (tunables != NULL)
1837 len = sizeof(struct lnet_ioctl_config_ni) +
1838 sizeof(struct lnet_ioctl_config_lnd_tunables);
1840 len = sizeof(struct lnet_ioctl_config_ni);
1841 data = calloc(1, len);
1843 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1846 conf = (struct lnet_ioctl_config_ni*) data;
1847 if (tunables != NULL)
1848 tun = (struct lnet_ioctl_config_lnd_tunables*)
1849 (data + sizeof(*conf));
1851 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1852 conf->lic_cfg_hdr.ioc_len = len;
1853 strncpy(conf->lic_legacy_ip2nets, ip2net,
1856 if (global_cpts != NULL) {
1857 count = cfs_expr_list_values(global_cpts,
1858 LNET_MAX_SHOW_NUM_CPT,
1861 memcpy(conf->lic_cpts, cpt_array,
1862 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1871 conf->lic_ncpts = count;
1873 if (tunables != NULL)
1874 memcpy(tun, tunables, sizeof(*tunables));
1876 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1881 "\"cannot add network: %s\"", strerror(errno));
1888 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1889 rc = LUSTRE_CFG_RC_NO_ERR;
1893 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1896 "\"cannot parse net '%s'\"",
1897 libcfs_net2str(nw_descr->nw_id));
1898 rc = LUSTRE_CFG_RC_BAD_PARAM;
1903 * special case the GNI since no interface name is expected
1905 if (list_empty(&nw_descr->nw_intflist) &&
1906 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1909 "\"no interface name provided\"");
1910 rc = LUSTRE_CFG_RC_BAD_PARAM;
1914 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1915 err_str, sizeof(err_str));
1917 rc = LUSTRE_CFG_RC_BAD_PARAM;
1921 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1922 tunables, global_cpts, nids,
1926 if (nw_descr != NULL) {
1927 list_for_each_entry_safe(intf_descr, tmp,
1928 &nw_descr->nw_intflist,
1930 list_del(&intf_descr->intf_on_network);
1931 free_intf_descr(intf_descr);
1935 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1946 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1947 int seq_no, struct cYAML **err_rc)
1949 struct lnet_ioctl_config_ni data;
1950 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1951 char err_str[LNET_MAX_STR_LEN];
1952 lnet_nid_t *nids = NULL;
1954 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1956 snprintf(err_str, sizeof(err_str), "\"success\"");
1958 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1961 "\"missing mandatory parameter in deleting NI: '%s'\"",
1962 (nw_descr == NULL) ? "network , interface" :
1963 (nw_descr->nw_id == 0) ? "network" : "interface");
1964 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1968 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1969 return LUSTRE_CFG_RC_NO_ERR;
1971 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1974 "\"cannot parse net '%s'\"",
1975 libcfs_net2str(nw_descr->nw_id));
1976 rc = LUSTRE_CFG_RC_BAD_PARAM;
1980 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1981 err_str, sizeof(err_str));
1983 rc = LUSTRE_CFG_RC_BAD_PARAM;
1988 * no interfaces just the nw_id is specified
1991 nids = calloc(1, sizeof(*nids));
1993 snprintf(err_str, sizeof(err_str),
1994 "\"out of memory\"");
1995 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1998 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2002 for (i = 0; i < nnids; i++) {
2003 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2004 data.lic_nid = nids[i];
2006 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2011 "\"cannot del network: %s\"", strerror(errno));
2015 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2017 list_del(&intf_descr->intf_on_network);
2018 free_intf_descr(intf_descr);
2022 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2031 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2032 enum lnet_health_type type, char *name,
2033 int seq_no, struct cYAML **err_rc)
2035 struct lnet_ioctl_reset_health_cfg data;
2036 int rc = LUSTRE_CFG_RC_NO_ERR;
2037 char err_str[LNET_MAX_STR_LEN];
2039 snprintf(err_str, sizeof(err_str), "\"success\"");
2041 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2042 data.rh_type = type;
2044 data.rh_value = value;
2047 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2051 sizeof(err_str), "Can not configure health value: %s",
2055 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2060 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2061 struct cYAML **err_rc)
2065 nid = libcfs_str2nid(ni_nid);
2068 return lustre_lnet_config_healthv(value, all, nid,
2069 LNET_HEALTH_TYPE_LOCAL_NI,
2070 "ni healthv", seq_no, err_rc);
2073 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2074 int seq_no, struct cYAML **err_rc)
2078 nid = libcfs_str2nid(lpni_nid);
2081 return lustre_lnet_config_healthv(value, all, nid,
2082 LNET_HEALTH_TYPE_PEER_NI,
2083 "peer_ni healthv", seq_no, err_rc);
2087 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2088 struct lnet_ioctl_comm_count *counts)
2090 if (cYAML_create_number(yaml, "put",
2091 counts->ico_put_count)
2094 if (cYAML_create_number(yaml, "get",
2095 counts->ico_get_count)
2098 if (cYAML_create_number(yaml, "reply",
2099 counts->ico_reply_count)
2102 if (cYAML_create_number(yaml, "ack",
2103 counts->ico_ack_count)
2106 if (cYAML_create_number(yaml, "hello",
2107 counts->ico_hello_count)
2114 static struct lnet_ioctl_comm_count *
2115 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2118 return &msg_stats->im_send_stats;
2120 return &msg_stats->im_recv_stats;
2122 return &msg_stats->im_drop_stats;
2127 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2128 struct cYAML **show_rc, struct cYAML **err_rc,
2132 struct lnet_ioctl_config_ni *ni_data;
2133 struct lnet_ioctl_config_lnd_tunables *lnd;
2134 struct lnet_ioctl_element_stats *stats;
2135 struct lnet_ioctl_element_msg_stats msg_stats;
2136 struct lnet_ioctl_local_ni_hstats hstats;
2137 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2138 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2139 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2141 struct cYAML *root = NULL, *tunables = NULL,
2142 *net_node = NULL, *interfaces = NULL,
2143 *item = NULL, *first_seq = NULL,
2144 *tmp = NULL, *statistics = NULL,
2146 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2147 char str_buf[str_buf_len];
2149 char err_str[LNET_MAX_STR_LEN];
2150 bool exist = false, new_net = true;
2152 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2154 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2156 buf = calloc(1, buf_size);
2160 ni_data = (struct lnet_ioctl_config_ni *)buf;
2163 net = libcfs_str2net(nw);
2164 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2167 "\"cannot parse net '%s'\"", nw);
2168 rc = LUSTRE_CFG_RC_BAD_PARAM;
2173 root = cYAML_create_object(NULL, NULL);
2177 net_node = cYAML_create_seq(root, "net");
2178 if (net_node == NULL)
2185 memset(buf, 0, buf_size);
2187 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2189 * set the ioc_len to the proper value since INIT assumes
2192 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2193 ni_data->lic_idx = i;
2195 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2201 rc_net = LNET_NIDNET(ni_data->lic_nid);
2203 /* filter on provided data */
2204 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2208 /* if we're backing up don't store lo */
2209 if (backup && LNET_NETTYP(rc_net) == LOLND)
2212 /* default rc to -1 in case we hit the goto */
2216 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2217 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2218 (ni_data->lic_bulk + sizeof(*stats));
2220 if (rc_net != prev_net) {
2227 if (!cYAML_create_string(net_node, "net type",
2228 libcfs_net2str(rc_net)))
2231 tmp = cYAML_create_seq(net_node, "local NI(s)");
2237 /* create the tree to be printed. */
2238 item = cYAML_create_seq_item(tmp);
2242 if (first_seq == NULL)
2246 cYAML_create_string(item, "nid",
2247 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2251 cYAML_create_string(item,
2253 (ni_data->lic_status ==
2254 LNET_NI_STATUS_UP) ?
2255 "up" : "down") == NULL)
2258 /* don't add interfaces unless there is at least one
2260 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2261 interfaces = cYAML_create_object(item, "interfaces");
2262 if (interfaces == NULL)
2265 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2266 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2268 sizeof(str_buf), "%d", j);
2269 if (cYAML_create_string(interfaces,
2271 ni_data->lic_ni_intf[j]) ==
2283 goto continue_without_msg_stats;
2285 statistics = cYAML_create_object(item, "statistics");
2286 if (statistics == NULL)
2289 if (cYAML_create_number(statistics, "send_count",
2290 stats->iel_send_count)
2294 if (cYAML_create_number(statistics, "recv_count",
2295 stats->iel_recv_count)
2299 if (cYAML_create_number(statistics, "drop_count",
2300 stats->iel_drop_count)
2305 goto continue_without_msg_stats;
2307 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2308 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2309 msg_stats.im_idx = i;
2311 rc = l_ioctl(LNET_DEV_ID,
2312 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2316 goto continue_without_msg_stats;
2319 for (k = 0; k < 3; k++) {
2320 struct lnet_ioctl_comm_count *counts;
2321 struct cYAML *msg_statistics = NULL;
2323 msg_statistics = cYAML_create_object(item,
2324 (char *)gmsg_stat_names[k]);
2325 if (msg_statistics == NULL)
2328 counts = get_counts(&msg_stats, k);
2332 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2337 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2338 hstats.hlni_nid = ni_data->lic_nid;
2339 /* grab health stats */
2340 rc = l_ioctl(LNET_DEV_ID,
2341 IOC_LIBCFS_GET_LOCAL_HSTATS,
2345 goto continue_without_msg_stats;
2347 yhstats = cYAML_create_object(item, "health stats");
2350 if (cYAML_create_number(yhstats, "health value",
2351 hstats.hlni_health_value)
2354 if (cYAML_create_number(yhstats, "interrupts",
2355 hstats.hlni_local_interrupt)
2358 if (cYAML_create_number(yhstats, "dropped",
2359 hstats.hlni_local_dropped)
2362 if (cYAML_create_number(yhstats, "aborted",
2363 hstats.hlni_local_aborted)
2366 if (cYAML_create_number(yhstats, "no route",
2367 hstats.hlni_local_no_route)
2370 if (cYAML_create_number(yhstats, "timeouts",
2371 hstats.hlni_local_timeout)
2374 if (cYAML_create_number(yhstats, "error",
2375 hstats.hlni_local_error)
2379 continue_without_msg_stats:
2380 tunables = cYAML_create_object(item, "tunables");
2384 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2385 if (rc != LUSTRE_CFG_RC_NO_ERR)
2388 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2390 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2391 rc != LUSTRE_CFG_RC_NO_MATCH)
2394 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2395 tunables = cYAML_create_object(item,
2397 if (tunables == NULL)
2402 cYAML_create_number(item, "dev cpt",
2403 ni_data->lic_dev_cpt) == NULL)
2407 cYAML_create_number(item, "tcp bonding",
2408 ni_data->lic_tcp_bonding)
2412 /* out put the CPTs in the format: "[x,x,x,...]" */
2413 limit = str_buf + str_buf_len - 3;
2414 pos += snprintf(pos, limit - pos, "\"[");
2415 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2416 j < ni_data->lic_ncpts &&
2418 pos += snprintf(pos, limit - pos,
2419 "%d", ni_data->lic_cpts[j]);
2420 if ((j + 1) < ni_data->lic_ncpts)
2421 pos += snprintf(pos, limit - pos, ",");
2423 pos += snprintf(pos, 3, "]\"");
2425 if (ni_data->lic_ncpts >= 1 &&
2426 cYAML_create_string(item, "CPT",
2432 /* Print out the net information only if show_rc is not provided */
2433 if (show_rc == NULL)
2434 cYAML_print_tree(root);
2436 if (l_errno != ENOENT) {
2439 "\"cannot get networks: %s\"",
2444 rc = LUSTRE_CFG_RC_NO_ERR;
2446 snprintf(err_str, sizeof(err_str), "\"success\"");
2448 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2449 cYAML_free_tree(root);
2450 } else if (show_rc != NULL && *show_rc != NULL) {
2451 struct cYAML *show_node;
2452 /* find the net node, if one doesn't exist
2453 * then insert one. Otherwise add to the one there
2455 show_node = cYAML_get_object_item(*show_rc, "net");
2456 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2457 cYAML_insert_child(show_node, first_seq);
2460 } else if (show_node == NULL) {
2461 cYAML_insert_sibling((*show_rc)->cy_child,
2465 cYAML_free_tree(root);
2471 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2476 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2478 struct lnet_ioctl_config_data data;
2479 int rc = LUSTRE_CFG_RC_NO_ERR;
2480 char err_str[LNET_MAX_STR_LEN];
2482 snprintf(err_str, sizeof(err_str), "\"success\"");
2484 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2485 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2487 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2492 "\"cannot %s routing %s\"",
2493 (enable) ? "enable" : "disable", strerror(errno));
2498 cYAML_build_error(rc, seq_no,
2499 (enable) ? ADD_CMD : DEL_CMD,
2500 "routing", err_str, err_rc);
2505 int ioctl_set_value(__u32 val, int ioc, char *name,
2506 int seq_no, struct cYAML **err_rc)
2508 struct lnet_ioctl_set_value data;
2509 int rc = LUSTRE_CFG_RC_NO_ERR;
2510 char err_str[LNET_MAX_STR_LEN];
2512 snprintf(err_str, sizeof(err_str), "\"success\"");
2514 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2515 data.sv_value = val;
2517 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2522 "\"cannot configure %s to %d: %s\"", name,
2523 val, strerror(errno));
2526 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2531 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2533 int rc = LUSTRE_CFG_RC_NO_ERR;
2534 char err_str[LNET_MAX_STR_LEN];
2535 char val[LNET_MAX_STR_LEN];
2537 snprintf(err_str, sizeof(err_str), "\"success\"");
2539 snprintf(val, sizeof(val), "%d", intrv);
2541 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2542 1, strlen(val) + 1);
2544 snprintf(err_str, sizeof(err_str),
2545 "\"cannot configure recovery interval: %s\"",
2548 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2553 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2555 int rc = LUSTRE_CFG_RC_NO_ERR;
2556 char err_str[LNET_MAX_STR_LEN];
2557 char val[LNET_MAX_STR_LEN];
2559 snprintf(err_str, sizeof(err_str), "\"success\"");
2561 snprintf(val, sizeof(val), "%d", sen);
2563 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2564 1, strlen(val) + 1);
2566 snprintf(err_str, sizeof(err_str),
2567 "\"cannot configure health sensitivity: %s\"",
2570 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2575 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2577 int rc = LUSTRE_CFG_RC_NO_ERR;
2578 char err_str[LNET_MAX_STR_LEN];
2579 char val[LNET_MAX_STR_LEN];
2581 snprintf(err_str, sizeof(err_str), "\"success\"");
2583 snprintf(val, sizeof(val), "%d", timeout);
2585 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2586 1, strlen(val) + 1);
2588 snprintf(err_str, sizeof(err_str),
2589 "\"cannot configure transaction timeout: %s\"",
2592 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2597 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2599 int rc = LUSTRE_CFG_RC_NO_ERR;
2600 char err_str[LNET_MAX_STR_LEN];
2601 char val[LNET_MAX_STR_LEN];
2603 snprintf(err_str, sizeof(err_str), "\"success\"");
2605 snprintf(val, sizeof(val), "%d", count);
2607 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2608 1, strlen(val) + 1);
2610 snprintf(err_str, sizeof(err_str),
2611 "\"cannot configure retry count: %s\"",
2614 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2619 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2621 int rc = LUSTRE_CFG_RC_NO_ERR;
2622 char err_str[LNET_MAX_STR_LEN];
2623 char val[LNET_MAX_STR_LEN];
2625 snprintf(err_str, sizeof(err_str), "\"success\"");
2627 snprintf(val, sizeof(val), "%d", max);
2629 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2630 1, strlen(val) + 1);
2632 snprintf(err_str, sizeof(err_str),
2633 "\"cannot configure max interfaces: %s\"",
2636 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2641 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2643 int rc = LUSTRE_CFG_RC_NO_ERR;
2644 char err_str[LNET_MAX_STR_LEN];
2645 char val[LNET_MAX_STR_LEN];
2647 snprintf(err_str, sizeof(err_str), "\"success\"");
2649 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2651 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2652 1, strlen(val) + 1);
2654 snprintf(err_str, sizeof(err_str),
2655 "\"cannot configure discovery: %s\"",
2658 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2664 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2665 struct cYAML **err_rc)
2667 int rc = LUSTRE_CFG_RC_NO_ERR;
2668 char err_str[LNET_MAX_STR_LEN];
2669 char val[LNET_MAX_STR_LEN];
2671 snprintf(err_str, sizeof(err_str), "\"success\"");
2673 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2675 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2676 1, strlen(val) + 1);
2678 snprintf(err_str, sizeof(err_str),
2679 "\"cannot configure drop asym route: %s\"",
2682 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2689 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2691 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2692 "numa_range", seq_no, err_rc);
2695 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2696 struct cYAML **err_rc)
2698 struct lnet_ioctl_config_data data;
2699 int rc = LUSTRE_CFG_RC_NO_ERR;
2700 char err_str[LNET_MAX_STR_LEN];
2702 snprintf(err_str, sizeof(err_str), "\"success\"");
2704 /* -1 indicates to ignore changes to this field */
2705 if (tiny < -1 || small < -1 || large < -1) {
2708 "\"tiny, small and large must be >= 0\"");
2709 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2713 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2714 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2715 data.cfg_config_u.cfg_buffers.buf_small = small;
2716 data.cfg_config_u.cfg_buffers.buf_large = large;
2718 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2723 "\"cannot configure buffers: %s\"", strerror(errno));
2728 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2733 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2734 struct cYAML **err_rc, bool backup)
2736 struct lnet_ioctl_config_data *data;
2737 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2738 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2741 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2742 int buf_count[LNET_NRBPOOLS] = {0};
2743 struct cYAML *root = NULL, *pools_node = NULL,
2744 *type_node = NULL, *item = NULL, *cpt = NULL,
2745 *first_seq = NULL, *buffers = NULL;
2747 char err_str[LNET_MAX_STR_LEN];
2748 char node_name[LNET_MAX_STR_LEN];
2751 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2753 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2757 data = (struct lnet_ioctl_config_data *)buf;
2759 root = cYAML_create_object(NULL, NULL);
2764 pools_node = cYAML_create_object(root, "routing");
2766 pools_node = cYAML_create_seq(root, "routing");
2767 if (pools_node == NULL)
2771 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2772 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2773 sizeof(struct lnet_ioctl_pool_cfg);
2774 data->cfg_count = i;
2776 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2784 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2787 goto calculate_buffers;
2789 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2790 item = cYAML_create_seq_item(pools_node);
2794 if (first_seq == NULL)
2797 cpt = cYAML_create_object(item, node_name);
2802 /* create the tree and print */
2803 for (j = 0; j < LNET_NRBPOOLS; j++) {
2805 type_node = cYAML_create_object(cpt, pools[j]);
2806 if (type_node == NULL)
2810 cYAML_create_number(type_node, "npages",
2811 pool_cfg->pl_pools[j].pl_npages)
2815 cYAML_create_number(type_node, "nbuffers",
2816 pool_cfg->pl_pools[j].
2817 pl_nbuffers) == NULL)
2820 cYAML_create_number(type_node, "credits",
2821 pool_cfg->pl_pools[j].
2822 pl_credits) == NULL)
2825 cYAML_create_number(type_node, "mincredits",
2826 pool_cfg->pl_pools[j].
2827 pl_mincredits) == NULL)
2829 /* keep track of the total count for each of the
2830 * tiny, small and large buffers */
2831 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2835 if (pool_cfg != NULL) {
2837 if (cYAML_create_number(pools_node, "enable",
2838 pool_cfg->pl_routing) ==
2842 goto add_buffer_section;
2845 item = cYAML_create_seq_item(pools_node);
2849 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2855 /* create a buffers entry in the show. This is necessary so that
2856 * if the YAML output is used to configure a node, the buffer
2857 * configuration takes hold */
2858 buffers = cYAML_create_object(root, "buffers");
2859 if (buffers == NULL)
2862 for (i = 0; i < LNET_NRBPOOLS; i++) {
2863 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2867 if (show_rc == NULL)
2868 cYAML_print_tree(root);
2870 if (l_errno != ENOENT) {
2873 "\"cannot get routing information: %s\"",
2878 rc = LUSTRE_CFG_RC_NO_ERR;
2880 snprintf(err_str, sizeof(err_str), "\"success\"");
2881 rc = LUSTRE_CFG_RC_NO_ERR;
2885 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2886 cYAML_free_tree(root);
2887 } else if (show_rc != NULL && *show_rc != NULL) {
2888 struct cYAML *routing_node;
2889 /* there should exist only one routing block and one
2890 * buffers block. If there already exists a previous one
2891 * then don't add another */
2892 routing_node = cYAML_get_object_item(*show_rc, "routing");
2893 if (routing_node == NULL) {
2894 cYAML_insert_sibling((*show_rc)->cy_child,
2898 cYAML_free_tree(root);
2904 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2909 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2910 struct cYAML **show_rc, struct cYAML **err_rc,
2914 * TODO: This function is changing in a future patch to accommodate
2915 * PEER_LIST and proper filtering on any nid of the peer
2917 struct lnet_ioctl_peer_cfg peer_info;
2918 struct lnet_peer_ni_credit_info *lpni_cri;
2919 struct lnet_ioctl_element_stats *lpni_stats;
2920 struct lnet_ioctl_element_msg_stats *msg_stats;
2921 struct lnet_ioctl_peer_ni_hstats *hstats;
2923 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2928 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2929 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2930 *msg_statistics = NULL, *statistics = NULL,
2932 char err_str[LNET_MAX_STR_LEN];
2933 struct lnet_process_id *list = NULL;
2938 snprintf(err_str, sizeof(err_str),
2939 "\"out of memory\"");
2941 /* create struct cYAML root object */
2942 root = cYAML_create_object(NULL, NULL);
2946 peer_root = cYAML_create_seq(root, "peer");
2947 if (peer_root == NULL)
2951 size = count * sizeof(struct lnet_process_id);
2952 list = malloc(size);
2958 list[0].nid = libcfs_str2nid(knid);
2962 memset(&peer_info, 0, sizeof(peer_info));
2963 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2964 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2965 peer_info.prcfg_size = size;
2966 peer_info.prcfg_bulk = list;
2969 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2971 count = peer_info.prcfg_count;
2975 if (l_errno != E2BIG) {
2978 "\"cannot get peer list: %s\"",
2984 size = peer_info.prcfg_size;
2985 list = malloc(size);
2994 data = malloc(size);
3000 for (i = 0; i < count; i++) {
3002 memset(&peer_info, 0, sizeof(peer_info));
3003 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3004 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3005 peer_info.prcfg_prim_nid = list[i].nid;
3006 peer_info.prcfg_size = size;
3007 peer_info.prcfg_bulk = data;
3010 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3015 if (l_errno != E2BIG) {
3018 "\"cannot get peer information: %s\"",
3024 size = peer_info.prcfg_size;
3025 data = malloc(size);
3033 peer = cYAML_create_seq_item(peer_root);
3037 if (first_seq == NULL)
3040 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3041 if (cYAML_create_string(peer, "primary nid",
3042 libcfs_nid2str(pnid))
3045 if (cYAML_create_string(peer, "Multi-Rail",
3046 peer_info.prcfg_mr ? "True" : "False")
3050 * print out the state of the peer only if details are
3055 cYAML_create_number(peer, "peer state",
3056 peer_info.prcfg_state)
3061 tmp = cYAML_create_seq(peer, "peer ni");
3066 for (j = 0; j < peer_info.prcfg_count; j++) {
3068 lpni_cri = (void*)nidp + sizeof(nidp);
3069 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3070 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3071 hstats = (void *)msg_stats + sizeof(*msg_stats);
3072 lpni_data = (void *)hstats + sizeof(*hstats);
3074 peer_ni = cYAML_create_seq_item(tmp);
3075 if (peer_ni == NULL)
3078 if (cYAML_create_string(peer_ni, "nid",
3079 libcfs_nid2str(*nidp))
3086 if (cYAML_create_string(peer_ni, "state",
3087 lpni_cri->cr_aliveness)
3094 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3095 lpni_cri->cr_ni_peer_tx_credits)
3099 if (cYAML_create_number(peer_ni, "available_tx_credits",
3100 lpni_cri->cr_peer_tx_credits)
3104 if (cYAML_create_number(peer_ni, "min_tx_credits",
3105 lpni_cri->cr_peer_min_tx_credits)
3109 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3110 lpni_cri->cr_peer_tx_qnob)
3114 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3115 lpni_cri->cr_peer_rtr_credits)
3119 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3120 lpni_cri->cr_peer_min_rtr_credits)
3124 if (cYAML_create_number(peer_ni, "refcount",
3125 lpni_cri->cr_refcount) == NULL)
3128 statistics = cYAML_create_object(peer_ni, "statistics");
3129 if (statistics == NULL)
3132 if (cYAML_create_number(statistics, "send_count",
3133 lpni_stats->iel_send_count)
3137 if (cYAML_create_number(statistics, "recv_count",
3138 lpni_stats->iel_recv_count)
3142 if (cYAML_create_number(statistics, "drop_count",
3143 lpni_stats->iel_drop_count)
3150 for (k = 0; k < 3; k++) {
3151 struct lnet_ioctl_comm_count *counts;
3153 msg_statistics = cYAML_create_object(peer_ni,
3154 (char *) gmsg_stat_names[k]);
3155 if (msg_statistics == NULL)
3158 counts = get_counts(msg_stats, k);
3162 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3167 yhstats = cYAML_create_object(peer_ni, "health stats");
3170 if (cYAML_create_number(yhstats, "health value",
3171 hstats->hlpni_health_value)
3174 if (cYAML_create_number(yhstats, "dropped",
3175 hstats->hlpni_remote_dropped)
3178 if (cYAML_create_number(yhstats, "timeout",
3179 hstats->hlpni_remote_timeout)
3182 if (cYAML_create_number(yhstats, "error",
3183 hstats->hlpni_remote_error)
3186 if (cYAML_create_number(yhstats, "network timeout",
3187 hstats->hlpni_network_timeout)
3193 /* print output iff show_rc is not provided */
3194 if (show_rc == NULL)
3195 cYAML_print_tree(root);
3197 snprintf(err_str, sizeof(err_str), "\"success\"");
3198 rc = LUSTRE_CFG_RC_NO_ERR;
3203 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3204 cYAML_free_tree(root);
3205 } else if (show_rc != NULL && *show_rc != NULL) {
3206 struct cYAML *show_node;
3207 /* find the peer node, if one doesn't exist then
3208 * insert one. Otherwise add to the one there
3210 show_node = cYAML_get_object_item(*show_rc,
3212 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3213 cYAML_insert_child(show_node, first_seq);
3216 } else if (show_node == NULL) {
3217 cYAML_insert_sibling((*show_rc)->cy_child,
3221 cYAML_free_tree(root);
3227 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3233 int lustre_lnet_list_peer(int seq_no,
3234 struct cYAML **show_rc, struct cYAML **err_rc)
3236 struct lnet_ioctl_peer_cfg peer_info;
3237 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3242 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3243 char err_str[LNET_MAX_STR_LEN];
3244 struct lnet_process_id *list = NULL;
3246 snprintf(err_str, sizeof(err_str),
3247 "\"out of memory\"");
3249 memset(&peer_info, 0, sizeof(peer_info));
3251 /* create struct cYAML root object */
3252 root = cYAML_create_object(NULL, NULL);
3256 list_root = cYAML_create_seq(root, "peer list");
3257 if (list_root == NULL)
3261 size = count * sizeof(struct lnet_process_id);
3262 list = malloc(size);
3268 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3269 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3270 peer_info.prcfg_size = size;
3271 peer_info.prcfg_bulk = list;
3274 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3275 count = peer_info.prcfg_count;
3279 if (l_errno != E2BIG) {
3282 "\"cannot get peer list: %s\"",
3288 size = peer_info.prcfg_size;
3289 list = malloc(size);
3296 /* count is now the actual number of ids in the list. */
3297 for (i = 0; i < count; i++) {
3298 if (cYAML_create_string(list_root, "nid",
3299 libcfs_nid2str(list[i].nid))
3304 /* print output iff show_rc is not provided */
3305 if (show_rc == NULL)
3306 cYAML_print_tree(root);
3308 snprintf(err_str, sizeof(err_str), "\"success\"");
3309 rc = LUSTRE_CFG_RC_NO_ERR;
3314 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3315 cYAML_free_tree(root);
3316 } else if (show_rc != NULL && *show_rc != NULL) {
3317 struct cYAML *show_node;
3318 /* find the peer node, if one doesn't exist then
3319 * insert one. Otherwise add to the one there
3321 show_node = cYAML_get_object_item(*show_rc,
3323 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3324 cYAML_insert_child(show_node, first_seq);
3327 } else if (show_node == NULL) {
3328 cYAML_insert_sibling((*show_rc)->cy_child,
3332 cYAML_free_tree(root);
3338 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3344 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3347 struct cYAML *show_node;
3349 show_node = cYAML_get_object_item(show_rc, "global");
3350 if (show_node != NULL)
3351 cYAML_insert_sibling(show_node->cy_child,
3354 cYAML_insert_sibling(show_rc->cy_child,
3359 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3360 char *name, __u32 value,
3361 struct cYAML **show_rc,
3362 struct cYAML **err_rc, int err)
3364 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3365 struct cYAML *root = NULL, *global = NULL;
3372 root = cYAML_create_object(NULL, NULL);
3376 global = cYAML_create_object(root, "global");
3380 if (cYAML_create_number(global, name,
3384 if (show_rc == NULL)
3385 cYAML_print_tree(root);
3387 snprintf(err_str, err_len, "\"success\"");
3389 rc = LUSTRE_CFG_RC_NO_ERR;
3392 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3393 cYAML_free_tree(root);
3394 } else if (show_rc != NULL && *show_rc != NULL) {
3395 add_to_global(*show_rc, global, root);
3400 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3405 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3406 struct cYAML **show_rc,
3407 struct cYAML **err_rc)
3409 struct lnet_ioctl_set_value data;
3412 char err_str[LNET_MAX_STR_LEN];
3414 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3416 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3418 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3423 "\"cannot get %s: %s\"",
3424 name, strerror(l_errno));
3427 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3428 data.sv_value, show_rc, err_rc, l_errno);
3431 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3432 struct cYAML **err_rc)
3434 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3435 char val[LNET_MAX_STR_LEN];
3436 int intrv = -1, l_errno = 0;
3437 char err_str[LNET_MAX_STR_LEN];
3439 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3441 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3445 snprintf(err_str, sizeof(err_str),
3446 "\"cannot get recovery interval: %d\"", rc);
3451 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3452 "recovery_interval", intrv, show_rc,
3456 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3457 struct cYAML **err_rc)
3459 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3460 char val[LNET_MAX_STR_LEN];
3461 int sen = -1, l_errno = 0;
3462 char err_str[LNET_MAX_STR_LEN];
3464 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3466 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3470 snprintf(err_str, sizeof(err_str),
3471 "\"cannot get health sensitivity: %d\"", rc);
3476 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3477 "health_sensitivity", sen, show_rc,
3481 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3482 struct cYAML **err_rc)
3484 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3485 char val[LNET_MAX_STR_LEN];
3486 int tto = -1, l_errno = 0;
3487 char err_str[LNET_MAX_STR_LEN];
3489 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3491 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3495 snprintf(err_str, sizeof(err_str),
3496 "\"cannot get transaction timeout: %d\"", rc);
3501 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3502 "transaction_timeout", tto, show_rc,
3506 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3507 struct cYAML **err_rc)
3509 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3510 char val[LNET_MAX_STR_LEN];
3511 int retry_count = -1, l_errno = 0;
3512 char err_str[LNET_MAX_STR_LEN];
3514 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3516 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3520 snprintf(err_str, sizeof(err_str),
3521 "\"cannot get retry count: %d\"", rc);
3523 retry_count = atoi(val);
3526 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3527 "retry_count", retry_count, show_rc,
3531 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3532 struct cYAML **show_rc, struct cYAML **err_rc)
3534 struct lnet_ioctl_recovery_list nid_list;
3535 struct cYAML *root = NULL, *nids = NULL;
3537 char err_str[LNET_MAX_STR_LEN];
3539 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3541 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3542 nid_list.rlst_type = type;
3544 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3550 if (nid_list.rlst_num_nids == 0)
3553 root = cYAML_create_object(NULL, NULL);
3557 nids = cYAML_create_object(root, name);
3563 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3564 char nidenum[LNET_MAX_STR_LEN];
3565 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3566 if (!cYAML_create_string(nids, nidenum,
3567 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3571 snprintf(err_str, sizeof(err_str), "success\n");
3576 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3577 cYAML_free_tree(root);
3578 } else if (show_rc != NULL && *show_rc != NULL) {
3579 struct cYAML *show_node;
3580 /* find the net node, if one doesn't exist
3581 * then insert one. Otherwise add to the one there
3583 show_node = cYAML_get_object_item(*show_rc, name);
3584 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3585 cYAML_insert_child(show_node, nids);
3588 } else if (show_node == NULL) {
3589 cYAML_insert_sibling((*show_rc)->cy_child,
3593 cYAML_free_tree(root);
3599 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3604 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3605 struct cYAML **err_rc)
3607 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3608 seq_no, show_rc, err_rc);
3611 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3612 struct cYAML **err_rc)
3614 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3615 seq_no, show_rc, err_rc);
3618 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3619 struct cYAML **err_rc)
3621 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3622 char val[LNET_MAX_STR_LEN];
3623 int max_intf = -1, l_errno = 0;
3624 char err_str[LNET_MAX_STR_LEN];
3626 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3628 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3632 snprintf(err_str, sizeof(err_str),
3633 "\"cannot get max interfaces: %d\"", rc);
3635 max_intf = atoi(val);
3638 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3639 "max_intf", max_intf, show_rc,
3643 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3644 struct cYAML **err_rc)
3646 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3647 char val[LNET_MAX_STR_LEN];
3648 int discovery = -1, l_errno = 0;
3649 char err_str[LNET_MAX_STR_LEN];
3651 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3653 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3657 snprintf(err_str, sizeof(err_str),
3658 "\"cannot get discovery setting: %d\"", rc);
3661 * The kernel stores a discovery disabled value. User space
3662 * shows whether discovery is enabled. So the value must be
3665 discovery = !atoi(val);
3668 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3669 "discovery", discovery, show_rc,
3673 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3674 struct cYAML **err_rc)
3676 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3677 char val[LNET_MAX_STR_LEN];
3678 int drop_asym_route = -1, l_errno = 0;
3679 char err_str[LNET_MAX_STR_LEN];
3681 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3683 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3687 snprintf(err_str, sizeof(err_str),
3688 "\"cannot get drop asym route setting: %d\"", rc);
3690 drop_asym_route = atoi(val);
3693 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3694 "drop_asym_route", drop_asym_route,
3695 show_rc, err_rc, l_errno);
3698 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3699 struct cYAML **err_rc)
3701 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3702 "numa_range", show_rc, err_rc);
3705 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3706 struct cYAML **err_rc)
3708 struct lnet_ioctl_lnet_stats data;
3709 struct lnet_counters *cntrs;
3712 char err_str[LNET_MAX_STR_LEN];
3713 struct cYAML *root = NULL, *stats = NULL;
3715 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3717 LIBCFS_IOC_INIT_V2(data, st_hdr);
3719 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3724 "\"cannot get lnet statistics: %s\"",
3730 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3732 cntrs = &data.st_cntrs;
3734 root = cYAML_create_object(NULL, NULL);
3738 stats = cYAML_create_object(root, "statistics");
3742 if (!cYAML_create_number(stats, "msgs_alloc",
3743 cntrs->lct_common.lcc_msgs_alloc))
3746 if (!cYAML_create_number(stats, "msgs_max",
3747 cntrs->lct_common.lcc_msgs_max))
3750 if (!cYAML_create_number(stats, "rst_alloc",
3751 cntrs->lct_health.lch_rst_alloc))
3754 if (!cYAML_create_number(stats, "errors",
3755 cntrs->lct_common.lcc_errors))
3758 if (!cYAML_create_number(stats, "send_count",
3759 cntrs->lct_common.lcc_send_count))
3762 if (!cYAML_create_number(stats, "resend_count",
3763 cntrs->lct_health.lch_resend_count))
3766 if (!cYAML_create_number(stats, "response_timeout_count",
3767 cntrs->lct_health.lch_response_timeout_count))
3770 if (!cYAML_create_number(stats, "local_interrupt_count",
3771 cntrs->lct_health.lch_local_interrupt_count))
3774 if (!cYAML_create_number(stats, "local_dropped_count",
3775 cntrs->lct_health.lch_local_dropped_count))
3778 if (!cYAML_create_number(stats, "local_aborted_count",
3779 cntrs->lct_health.lch_local_aborted_count))
3782 if (!cYAML_create_number(stats, "local_no_route_count",
3783 cntrs->lct_health.lch_local_no_route_count))
3786 if (!cYAML_create_number(stats, "local_timeout_count",
3787 cntrs->lct_health.lch_local_timeout_count))
3790 if (!cYAML_create_number(stats, "local_error_count",
3791 cntrs->lct_health.lch_local_error_count))
3794 if (!cYAML_create_number(stats, "remote_dropped_count",
3795 cntrs->lct_health.lch_remote_dropped_count))
3798 if (!cYAML_create_number(stats, "remote_error_count",
3799 cntrs->lct_health.lch_remote_error_count))
3802 if (!cYAML_create_number(stats, "remote_timeout_count",
3803 cntrs->lct_health.lch_remote_timeout_count))
3806 if (!cYAML_create_number(stats, "network_timeout_count",
3807 cntrs->lct_health.lch_network_timeout_count))
3810 if (!cYAML_create_number(stats, "recv_count",
3811 cntrs->lct_common.lcc_recv_count))
3814 if (!cYAML_create_number(stats, "route_count",
3815 cntrs->lct_common.lcc_route_count))
3818 if (!cYAML_create_number(stats, "drop_count",
3819 cntrs->lct_common.lcc_drop_count))
3822 if (!cYAML_create_number(stats, "send_length",
3823 cntrs->lct_common.lcc_send_length))
3826 if (!cYAML_create_number(stats, "recv_length",
3827 cntrs->lct_common.lcc_recv_length))
3830 if (!cYAML_create_number(stats, "route_length",
3831 cntrs->lct_common.lcc_route_length))
3834 if (!cYAML_create_number(stats, "drop_length",
3835 cntrs->lct_common.lcc_drop_length))
3839 cYAML_print_tree(root);
3841 snprintf(err_str, sizeof(err_str), "\"success\"");
3842 rc = LUSTRE_CFG_RC_NO_ERR;
3844 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3845 cYAML_free_tree(root);
3846 } else if (show_rc != NULL && *show_rc != NULL) {
3847 cYAML_insert_sibling((*show_rc)->cy_child,
3854 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3859 typedef int (*cmd_handler_t)(struct cYAML *tree,
3860 struct cYAML **show_rc,
3861 struct cYAML **err_rc);
3863 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3864 struct cYAML **err_rc)
3866 struct cYAML *net, *gw, *hop, *prio, *seq_no;
3868 net = cYAML_get_object_item(tree, "net");
3869 gw = cYAML_get_object_item(tree, "gateway");
3870 hop = cYAML_get_object_item(tree, "hop");
3871 prio = cYAML_get_object_item(tree, "priority");
3872 seq_no = cYAML_get_object_item(tree, "seq_no");
3874 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3875 (gw) ? gw->cy_valuestring : NULL,
3876 (hop) ? hop->cy_valueint : -1,
3877 (prio) ? prio->cy_valueint : -1,
3878 (seq_no) ? seq_no->cy_valueint : -1,
3882 static void yaml_free_string_array(char **array, int num)
3885 char **sub_array = array;
3887 for (i = 0; i < num; i++) {
3888 if (*sub_array != NULL)
3898 * 0: <intf_name>['['<expr>']']
3899 * 1: <intf_name>['['<expr>']']
3901 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3902 struct lnet_dlc_network_descr *nw_descr)
3904 struct cYAML *child = NULL;
3905 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3906 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3908 if (intf_tree == NULL || nw_descr == NULL)
3909 return LUSTRE_CFG_RC_BAD_PARAM;
3911 /* now grab all the interfaces and their cpts */
3912 child = intf_tree->cy_child;
3913 while (child != NULL) {
3914 if (child->cy_valuestring == NULL) {
3915 child = child->cy_next;
3919 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3922 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3923 child->cy_valuestring,
3924 strlen(child->cy_valuestring));
3925 if (rc != LUSTRE_CFG_RC_NO_ERR)
3929 child = child->cy_next;
3933 return LUSTRE_CFG_RC_MISSING_PARAM;
3938 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3940 list_del(&intf_descr->intf_on_network);
3941 free_intf_descr(intf_descr);
3948 yaml_extract_cmn_tunables(struct cYAML *tree,
3949 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3950 struct cfs_expr_list **global_cpts)
3952 struct cYAML *tun, *item, *smp;
3955 tun = cYAML_get_object_item(tree, "tunables");
3957 item = cYAML_get_object_item(tun, "peer_timeout");
3959 tunables->lct_peer_timeout = item->cy_valueint;
3960 item = cYAML_get_object_item(tun, "peer_credits");
3962 tunables->lct_peer_tx_credits = item->cy_valueint;
3963 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3965 tunables->lct_peer_rtr_credits = item->cy_valueint;
3966 item = cYAML_get_object_item(tun, "credits");
3968 tunables->lct_max_tx_credits = item->cy_valueint;
3969 smp = cYAML_get_object_item(tun, "CPT");
3971 rc = cfs_expr_list_parse(smp->cy_valuestring,
3972 strlen(smp->cy_valuestring),
3973 0, UINT_MAX, global_cpts);
3975 *global_cpts = NULL;
3985 yaml_extract_tunables(struct cYAML *tree,
3986 struct lnet_ioctl_config_lnd_tunables *tunables,
3987 struct cfs_expr_list **global_cpts,
3992 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3998 lustre_yaml_extract_lnd_tunables(tree, net_type,
4006 * - net type: <net>[<NUM>]
4008 * - nid: <ip>@<net>[<NUM>]
4011 * 0: <intf_name>['['<expr>']']
4012 * 1: <intf_name>['['<expr>']']
4014 * peer_timeout: <NUM>
4015 * peer_credits: <NUM>
4016 * peer_buffer_credits: <NUM>
4019 * peercredits_hiw: <NUM>
4020 * map_on_demand: <NUM>
4021 * concurrent_sends: <NUM>
4022 * fmr_pool_size: <NUM>
4023 * fmr_flush_trigger: <NUM>
4026 * At least one interface is required. If no interfaces are provided the
4027 * network interface can not be configured.
4029 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4030 struct cYAML **err_rc)
4032 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4034 int num_entries = 0, rc;
4035 struct lnet_dlc_network_descr nw_descr;
4036 struct cfs_expr_list *global_cpts = NULL;
4037 struct lnet_ioctl_config_lnd_tunables tunables;
4040 memset(&tunables, 0, sizeof(tunables));
4042 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4043 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4045 ip2net = cYAML_get_object_item(tree, "ip2net");
4046 net = cYAML_get_object_item(tree, "net type");
4048 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4050 nw_descr.nw_id = LOLND;
4053 * if neither net nor ip2nets are present, then we can not
4054 * configure the network.
4056 if (!net && !ip2net)
4057 return LUSTRE_CFG_RC_MISSING_PARAM;
4059 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4060 if (local_nis == NULL)
4061 return LUSTRE_CFG_RC_MISSING_PARAM;
4063 if (!cYAML_is_sequence(local_nis))
4064 return LUSTRE_CFG_RC_BAD_PARAM;
4066 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4067 intf = cYAML_get_object_item(item, "interfaces");
4070 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4071 if (num_entries <= 0) {
4072 cYAML_build_error(num_entries, -1, "ni", "add",
4073 "bad interface list",
4075 return LUSTRE_CFG_RC_BAD_PARAM;
4079 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4080 LNET_NETTYP(nw_descr.nw_id));
4081 seq_no = cYAML_get_object_item(tree, "seq_no");
4083 rc = lustre_lnet_config_ni(&nw_descr,
4085 (ip2net) ? ip2net->cy_valuestring : NULL,
4086 (found) ? &tunables: NULL,
4087 (seq_no) ? seq_no->cy_valueint : -1,
4090 if (global_cpts != NULL)
4091 cfs_expr_list_free(global_cpts);
4098 * - net-spec: <tcp|o2ib|gni>[NUM]
4100 * 0: <intf name>['['<expr>']']
4101 * 1: <intf name>['['<expr>']']
4103 * 0: <expr.expr.expr.expr>
4104 * 1: <expr.expr.expr.expr>
4106 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4107 struct cYAML **show_rc,
4108 struct cYAML **err_rc)
4110 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4112 struct lustre_lnet_ip2nets ip2nets;
4113 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4115 int rc = LUSTRE_CFG_RC_NO_ERR;
4116 struct cfs_expr_list *global_cpts = NULL;
4117 struct cfs_expr_list *el, *el_tmp;
4118 struct lnet_ioctl_config_lnd_tunables tunables;
4119 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4122 memset(&tunables, 0, sizeof(tunables));
4124 /* initialize all lists */
4125 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4126 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4127 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4129 net = cYAML_get_object_item(tree, "net-spec");
4131 return LUSTRE_CFG_RC_BAD_PARAM;
4133 if (net != NULL && net->cy_valuestring == NULL)
4134 return LUSTRE_CFG_RC_BAD_PARAM;
4136 /* assign the network id */
4137 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4138 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4139 return LUSTRE_CFG_RC_BAD_PARAM;
4141 seq_no = cYAML_get_object_item(tree, "seq_no");
4143 intf = cYAML_get_object_item(tree, "interfaces");
4145 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4147 return LUSTRE_CFG_RC_BAD_PARAM;
4150 ip_range = cYAML_get_object_item(tree, "ip-range");
4151 if (ip_range != NULL) {
4152 item = ip_range->cy_child;
4153 while (item != NULL) {
4154 if (item->cy_valuestring == NULL) {
4155 item = item->cy_next;
4159 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4160 item->cy_valuestring);
4162 if (rc != LUSTRE_CFG_RC_NO_ERR)
4165 item = item->cy_next;
4169 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4170 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4172 rc = lustre_lnet_config_ip2nets(&ip2nets,
4173 (found) ? &tunables : NULL,
4175 (seq_no) ? seq_no->cy_valueint : -1,
4179 * don't stop because there was no match. Continue processing the
4180 * rest of the rules. If non-match then nothing is configured
4182 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4183 rc = LUSTRE_CFG_RC_NO_ERR;
4185 list_for_each_entry_safe(intf_descr, intf_tmp,
4186 &ip2nets.ip2nets_net.nw_intflist,
4188 list_del(&intf_descr->intf_on_network);
4189 free_intf_descr(intf_descr);
4192 list_for_each_entry_safe(ip_range_descr, tmp,
4193 &ip2nets.ip2nets_ip_ranges,
4195 list_del(&ip_range_descr->ipr_entry);
4196 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4198 list_del(&el->el_link);
4199 cfs_expr_list_free(el);
4201 free(ip_range_descr);
4207 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4208 struct cYAML **err_rc)
4210 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4212 int num_entries, rc;
4213 struct lnet_dlc_network_descr nw_descr;
4215 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4216 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4218 net = cYAML_get_object_item(tree, "net type");
4220 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4222 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4223 if (local_nis == NULL)
4224 return LUSTRE_CFG_RC_MISSING_PARAM;
4226 if (!cYAML_is_sequence(local_nis))
4227 return LUSTRE_CFG_RC_BAD_PARAM;
4229 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4230 intf = cYAML_get_object_item(item, "interfaces");
4233 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4234 if (num_entries <= 0) {
4235 cYAML_build_error(num_entries, -1, "ni", "add",
4236 "bad interface list",
4238 return LUSTRE_CFG_RC_BAD_PARAM;
4242 seq_no = cYAML_get_object_item(tree, "seq_no");
4244 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4245 (seq_no) ? seq_no->cy_valueint : -1,
4251 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4252 char *prim_nid, bool del)
4254 struct cYAML *child = NULL, *entry = NULL;
4256 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4258 if (cYAML_is_sequence(nids_entry)) {
4259 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4260 entry = cYAML_get_object_item(child, "nid");
4261 /* don't count an empty entry */
4262 if (!entry || !entry->cy_valuestring)
4266 (strcmp(entry->cy_valuestring, prim_nid)
4269 * primary nid is present in the list of
4270 * nids so that means we want to delete
4271 * the entire peer, so no need to go
4272 * further. Just delete the entire peer.
4282 return LUSTRE_CFG_RC_MISSING_PARAM;
4284 nids = calloc(sizeof(*nids), num);
4286 return LUSTRE_CFG_RC_OUT_OF_MEM;
4288 /* now grab all the nids */
4291 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4292 entry = cYAML_get_object_item(child, "nid");
4293 if (!entry || !entry->cy_valuestring)
4296 nids[num] = strdup(entry->cy_valuestring);
4298 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4310 yaml_free_string_array(nids, num);
4315 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4316 struct cYAML **err_rc)
4320 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4321 char err_str[LNET_MAX_STR_LEN];
4324 seq_no = cYAML_get_object_item(tree, "seq_no");
4325 prim_nid = cYAML_get_object_item(tree, "primary nid");
4326 mr = cYAML_get_object_item(tree, "Multi-Rail");
4327 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4328 peer_nis = cYAML_get_object_item(tree, "peer ni");
4330 if (ip2nets && (prim_nid || peer_nis)) {
4331 rc = LUSTRE_CFG_RC_BAD_PARAM;
4332 snprintf(err_str, sizeof(err_str),
4333 "ip2nets can not be specified along side prim_nid"
4334 " or peer ni fields");
4335 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4336 ADD_CMD, "peer", err_str, err_rc);
4343 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4345 else if (!strcmp(mr->cy_valuestring, "False"))
4348 rc = LUSTRE_CFG_RC_BAD_PARAM;
4349 snprintf(err_str, sizeof(err_str), "Bad MR value");
4350 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4351 ADD_CMD, "peer", err_str, err_rc);
4356 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4357 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4361 snprintf(err_str, sizeof(err_str),
4362 "error copying nids from YAML block");
4363 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4364 ADD_CMD, "peer", err_str, err_rc);
4368 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4369 nids, num, mr_value,
4370 (ip2nets) ? true : false,
4371 (seq_no) ? seq_no->cy_valueint : -1,
4374 yaml_free_string_array(nids, num);
4378 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4379 struct cYAML **err_rc)
4383 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4384 char err_str[LNET_MAX_STR_LEN];
4386 seq_no = cYAML_get_object_item(tree, "seq_no");
4387 prim_nid = cYAML_get_object_item(tree, "primary nid");
4388 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4389 peer_nis = cYAML_get_object_item(tree, "peer ni");
4391 if (ip2nets && (prim_nid || peer_nis)) {
4392 rc = LUSTRE_CFG_RC_BAD_PARAM;
4393 snprintf(err_str, sizeof(err_str),
4394 "ip2nets can not be specified along side prim_nid"
4395 " or peer ni fields");
4396 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4397 DEL_CMD, "peer", err_str, err_rc);
4401 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4402 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4405 snprintf(err_str, sizeof(err_str),
4406 "error copying nids from YAML block");
4407 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4408 ADD_CMD, "peer", err_str, err_rc);
4412 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4413 nids, num, (ip2nets) ? true : false,
4414 (seq_no) ? seq_no->cy_valueint : -1,
4417 yaml_free_string_array(nids, num);
4421 static int handle_yaml_config_buffers(struct cYAML *tree,
4422 struct cYAML **show_rc,
4423 struct cYAML **err_rc)
4426 struct cYAML *tiny, *small, *large, *seq_no;
4428 tiny = cYAML_get_object_item(tree, "tiny");
4429 small = cYAML_get_object_item(tree, "small");
4430 large = cYAML_get_object_item(tree, "large");
4431 seq_no = cYAML_get_object_item(tree, "seq_no");
4433 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4434 (small) ? small->cy_valueint : -1,
4435 (large) ? large->cy_valueint : -1,
4436 (seq_no) ? seq_no->cy_valueint : -1,
4442 static int handle_yaml_config_routing(struct cYAML *tree,
4443 struct cYAML **show_rc,
4444 struct cYAML **err_rc)
4446 int rc = LUSTRE_CFG_RC_NO_ERR;
4447 struct cYAML *seq_no, *enable;
4449 seq_no = cYAML_get_object_item(tree, "seq_no");
4450 enable = cYAML_get_object_item(tree, "enable");
4453 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4455 seq_no->cy_valueint : -1,
4462 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4463 struct cYAML **err_rc)
4467 struct cYAML *seq_no;
4469 net = cYAML_get_object_item(tree, "net");
4470 gw = cYAML_get_object_item(tree, "gateway");
4471 seq_no = cYAML_get_object_item(tree, "seq_no");
4473 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4474 (gw) ? gw->cy_valuestring : NULL,
4475 (seq_no) ? seq_no->cy_valueint : -1,
4479 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4480 struct cYAML **err_rc)
4482 struct cYAML *seq_no;
4484 seq_no = cYAML_get_object_item(tree, "seq_no");
4486 return lustre_lnet_enable_routing(0, (seq_no) ?
4487 seq_no->cy_valueint : -1,
4491 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4492 struct cYAML **err_rc)
4498 struct cYAML *detail;
4499 struct cYAML *seq_no;
4501 net = cYAML_get_object_item(tree, "net");
4502 gw = cYAML_get_object_item(tree, "gateway");
4503 hop = cYAML_get_object_item(tree, "hop");
4504 prio = cYAML_get_object_item(tree, "priority");
4505 detail = cYAML_get_object_item(tree, "detail");
4506 seq_no = cYAML_get_object_item(tree, "seq_no");
4508 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4509 (gw) ? gw->cy_valuestring : NULL,
4510 (hop) ? hop->cy_valueint : -1,
4511 (prio) ? prio->cy_valueint : -1,
4512 (detail) ? detail->cy_valueint : 0,
4513 (seq_no) ? seq_no->cy_valueint : -1,
4514 show_rc, err_rc, false);
4517 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4518 struct cYAML **err_rc)
4520 struct cYAML *net, *detail, *seq_no;
4522 net = cYAML_get_object_item(tree, "net");
4523 detail = cYAML_get_object_item(tree, "detail");
4524 seq_no = cYAML_get_object_item(tree, "seq_no");
4526 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4527 (detail) ? detail->cy_valueint : 0,
4528 (seq_no) ? seq_no->cy_valueint : -1,
4529 show_rc, err_rc, false);
4532 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4533 struct cYAML **err_rc)
4535 struct cYAML *seq_no;
4537 seq_no = cYAML_get_object_item(tree, "seq_no");
4539 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4540 show_rc, err_rc, false);
4543 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4544 struct cYAML **err_rc)
4546 struct cYAML *seq_no, *nid, *detail;
4548 seq_no = cYAML_get_object_item(tree, "seq_no");
4549 detail = cYAML_get_object_item(tree, "detail");
4550 nid = cYAML_get_object_item(tree, "nid");
4552 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4553 (detail) ? detail->cy_valueint : 0,
4554 (seq_no) ? seq_no->cy_valueint : -1,
4555 show_rc, err_rc, false);
4558 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4559 struct cYAML **err_rc)
4561 struct cYAML *seq_no;
4563 seq_no = cYAML_get_object_item(tree, "seq_no");
4565 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4569 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4570 struct cYAML **err_rc)
4572 struct cYAML *seq_no, *range;
4574 seq_no = cYAML_get_object_item(tree, "seq_no");
4575 range = cYAML_get_object_item(tree, "range");
4577 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4578 seq_no ? seq_no->cy_valueint : -1,
4582 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4583 struct cYAML **err_rc)
4585 struct cYAML *seq_no;
4587 seq_no = cYAML_get_object_item(tree, "seq_no");
4589 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4593 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4594 struct cYAML **err_rc)
4596 struct cYAML *seq_no;
4598 seq_no = cYAML_get_object_item(tree, "seq_no");
4600 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4604 static int handle_yaml_config_global_settings(struct cYAML *tree,
4605 struct cYAML **show_rc,
4606 struct cYAML **err_rc)
4608 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4609 *sen, *recov, *drop_asym_route;
4612 seq_no = cYAML_get_object_item(tree, "seq_no");
4613 max_intf = cYAML_get_object_item(tree, "max_intf");
4615 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4616 seq_no ? seq_no->cy_valueint
4620 numa = cYAML_get_object_item(tree, "numa_range");
4622 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4623 seq_no ? seq_no->cy_valueint
4627 discovery = cYAML_get_object_item(tree, "discovery");
4629 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4630 seq_no ? seq_no->cy_valueint
4634 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4635 if (drop_asym_route)
4636 rc = lustre_lnet_config_drop_asym_route(
4637 drop_asym_route->cy_valueint,
4638 seq_no ? seq_no->cy_valueint : -1,
4641 retry = cYAML_get_object_item(tree, "retry_count");
4643 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4644 seq_no ? seq_no->cy_valueint
4648 tto = cYAML_get_object_item(tree, "transaction_timeout");
4650 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4651 seq_no ? seq_no->cy_valueint
4655 sen = cYAML_get_object_item(tree, "health_sensitivity");
4657 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4658 seq_no ? seq_no->cy_valueint
4662 recov = cYAML_get_object_item(tree, "recovery_interval");
4664 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4665 seq_no ? seq_no->cy_valueint
4672 static int handle_yaml_del_global_settings(struct cYAML *tree,
4673 struct cYAML **show_rc,
4674 struct cYAML **err_rc)
4676 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4679 seq_no = cYAML_get_object_item(tree, "seq_no");
4680 max_intf = cYAML_get_object_item(tree, "max_intf");
4682 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4683 seq_no ? seq_no->cy_valueint
4687 numa = cYAML_get_object_item(tree, "numa_range");
4689 rc = lustre_lnet_config_numa_range(0,
4690 seq_no ? seq_no->cy_valueint
4694 /* peer discovery is enabled by default */
4695 discovery = cYAML_get_object_item(tree, "discovery");
4697 rc = lustre_lnet_config_discovery(1,
4698 seq_no ? seq_no->cy_valueint
4702 /* asymmetrical route messages are accepted by default */
4703 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4704 if (drop_asym_route)
4705 rc = lustre_lnet_config_drop_asym_route(
4706 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4711 static int handle_yaml_show_global_settings(struct cYAML *tree,
4712 struct cYAML **show_rc,
4713 struct cYAML **err_rc)
4715 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4716 *sen, *recov, *drop_asym_route;
4719 seq_no = cYAML_get_object_item(tree, "seq_no");
4720 max_intf = cYAML_get_object_item(tree, "max_intf");
4722 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4726 numa = cYAML_get_object_item(tree, "numa_range");
4728 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4732 discovery = cYAML_get_object_item(tree, "discovery");
4734 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4738 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4739 if (drop_asym_route)
4740 rc = lustre_lnet_show_drop_asym_route(
4741 seq_no ? seq_no->cy_valueint : -1,
4744 retry = cYAML_get_object_item(tree, "retry_count");
4746 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4750 tto = cYAML_get_object_item(tree, "transaction_timeout");
4752 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4756 sen = cYAML_get_object_item(tree, "health_sensitivity");
4758 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4762 recov = cYAML_get_object_item(tree, "recovery_interval");
4764 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4771 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4772 struct cYAML **err_rc)
4774 struct cYAML *seq_no, *nid, *timeout;
4776 seq_no = cYAML_get_object_item(tree, "seq_no");
4777 nid = cYAML_get_object_item(tree, "primary nid");
4778 timeout = cYAML_get_object_item(tree, "timeout");
4780 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4781 (timeout) ? timeout->cy_valueint : 1000,
4782 (seq_no) ? seq_no->cy_valueint : -1,
4786 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4787 struct cYAML **err_rc)
4789 struct cYAML *seq_no, *nid, *force;
4791 seq_no = cYAML_get_object_item(tree, "seq_no");
4792 nid = cYAML_get_object_item(tree, "primary nid");
4793 force = cYAML_get_object_item(tree, "force");
4795 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4796 (force) ? force->cy_valueint : 0,
4797 (seq_no) ? seq_no->cy_valueint : -1,
4801 static int handle_yaml_no_op()
4803 return LUSTRE_CFG_RC_NO_ERR;
4806 struct lookup_cmd_hdlr_tbl {
4811 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4812 { .name = "route", .cb = handle_yaml_config_route },
4813 { .name = "net", .cb = handle_yaml_config_ni },
4814 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4815 { .name = "peer", .cb = handle_yaml_config_peer },
4816 { .name = "routing", .cb = handle_yaml_config_routing },
4817 { .name = "buffers", .cb = handle_yaml_config_buffers },
4818 { .name = "statistics", .cb = handle_yaml_no_op },
4819 { .name = "global", .cb = handle_yaml_config_global_settings},
4820 { .name = "numa", .cb = handle_yaml_config_numa },
4821 { .name = "ping", .cb = handle_yaml_no_op },
4822 { .name = "discover", .cb = handle_yaml_no_op },
4825 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4826 { .name = "route", .cb = handle_yaml_del_route },
4827 { .name = "net", .cb = handle_yaml_del_ni },
4828 { .name = "ip2nets", .cb = handle_yaml_no_op },
4829 { .name = "peer", .cb = handle_yaml_del_peer },
4830 { .name = "routing", .cb = handle_yaml_del_routing },
4831 { .name = "buffers", .cb = handle_yaml_no_op },
4832 { .name = "statistics", .cb = handle_yaml_no_op },
4833 { .name = "global", .cb = handle_yaml_del_global_settings},
4834 { .name = "numa", .cb = handle_yaml_del_numa },
4835 { .name = "ping", .cb = handle_yaml_no_op },
4836 { .name = "discover", .cb = handle_yaml_no_op },
4839 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4840 { .name = "route", .cb = handle_yaml_show_route },
4841 { .name = "net", .cb = handle_yaml_show_net },
4842 { .name = "peer", .cb = handle_yaml_show_peers },
4843 { .name = "ip2nets", .cb = handle_yaml_no_op },
4844 { .name = "routing", .cb = handle_yaml_show_routing },
4845 { .name = "buffers", .cb = handle_yaml_show_routing },
4846 { .name = "statistics", .cb = handle_yaml_show_stats },
4847 { .name = "global", .cb = handle_yaml_show_global_settings},
4848 { .name = "numa", .cb = handle_yaml_show_numa },
4849 { .name = "ping", .cb = handle_yaml_no_op },
4850 { .name = "discover", .cb = handle_yaml_no_op },
4853 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4854 { .name = "route", .cb = handle_yaml_no_op },
4855 { .name = "net", .cb = handle_yaml_no_op },
4856 { .name = "peer", .cb = handle_yaml_no_op },
4857 { .name = "ip2nets", .cb = handle_yaml_no_op },
4858 { .name = "routing", .cb = handle_yaml_no_op },
4859 { .name = "buffers", .cb = handle_yaml_no_op },
4860 { .name = "statistics", .cb = handle_yaml_no_op },
4861 { .name = "global", .cb = handle_yaml_no_op },
4862 { .name = "numa", .cb = handle_yaml_no_op },
4863 { .name = "ping", .cb = handle_yaml_ping },
4864 { .name = "discover", .cb = handle_yaml_discover },
4867 static cmd_handler_t lookup_fn(char *key,
4868 struct lookup_cmd_hdlr_tbl *tbl)
4874 for (i = 0; tbl[i].name != NULL; i++) {
4875 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4882 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4883 struct cYAML **show_rc, struct cYAML **err_rc)
4885 struct cYAML *tree, *item = NULL, *head, *child;
4887 char err_str[LNET_MAX_STR_LEN];
4888 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4890 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4892 return LUSTRE_CFG_RC_BAD_PARAM;
4894 child = tree->cy_child;
4895 while (child != NULL) {
4896 cb = lookup_fn(child->cy_string, table);
4898 snprintf(err_str, sizeof(err_str),
4899 "\"call back for '%s' not found\"",
4901 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4902 "yaml", "helper", err_str, err_rc);
4906 if (cYAML_is_sequence(child)) {
4907 while ((head = cYAML_get_next_seq_item(child, &item))
4909 rc = cb(head, show_rc, err_rc);
4910 if (rc != LUSTRE_CFG_RC_NO_ERR)
4914 rc = cb(child, show_rc, err_rc);
4915 if (rc != LUSTRE_CFG_RC_NO_ERR)
4919 child = child->cy_next;
4923 cYAML_free_tree(tree);
4928 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4930 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4934 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4936 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4940 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4942 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4946 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4948 return lustre_yaml_cb_helper(f, lookup_exec_tbl,