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_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
266 int max_nids, char *err_str)
268 int rc, num_nids = 0;
269 struct list_head nidlist;
272 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
273 return LUSTRE_CFG_RC_BAD_PARAM;
276 if (strchr(nidstr, '*')) {
277 snprintf(err_str, LNET_MAX_STR_LEN,
278 "asterisk not allowed in nidstring \"%s\"", nidstr);
279 return LUSTRE_CFG_RC_BAD_PARAM;
282 INIT_LIST_HEAD(&nidlist);
283 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
285 snprintf(err_str, LNET_MAX_STR_LEN,
286 "Unable to parse nidlist from: %s\n", nidstr);
287 return LUSTRE_CFG_RC_BAD_PARAM;
290 if (list_empty(&nidlist)) {
291 snprintf(err_str, LNET_MAX_STR_LEN,
292 "\"%s\" does not specify any valid nid lists", nidstr);
293 return LUSTRE_CFG_RC_BAD_PARAM;
296 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
298 if (num_nids == -1) {
299 snprintf(err_str, LNET_MAX_STR_LEN,
300 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
302 return LUSTRE_CFG_RC_BAD_PARAM;
306 snprintf(err_str, LNET_MAX_STR_LEN,
307 "Failed to expand nidstr: %s", strerror(num_nids));
308 return LUSTRE_CFG_RC_OUT_OF_MEM;
312 snprintf(err_str, LNET_MAX_STR_LEN,
313 "\"%s\" did not expand to any nids", nidstr);
314 return LUSTRE_CFG_RC_BAD_PARAM;
320 int lustre_lnet_parse_nids(char *nids, char **array, int size,
324 char *comma = nids, *cur, *entry;
326 int i, len, start = 0, finish = 0;
328 if (nids == NULL || strlen(nids) == 0)
331 /* count the number or new nids, by counting the number of comma*/
333 comma = get_next_delimiter_in_nid(comma, ',');
343 * if the array is not NULL allocate a large enough array to house
344 * the old and new entries
346 new_array = calloc(sizeof(char*),
347 (size > 0) ? size + num_nids : num_nids);
352 /* parse our the new nids and add them to the tail of the array */
355 start = (size > 0) ? size: 0;
356 finish = (size > 0) ? size + num_nids : num_nids;
357 for (i = start; i < finish; i++) {
358 comma = get_next_delimiter_in_nid(comma, ',');
361 * the length of the string to be parsed out is
362 * from cur to end of string. So it's good enough
365 len = strlen(cur) + 1;
367 /* length of the string is comma - cur */
368 len = (comma - cur) + 1;
370 entry = calloc(1, len);
372 finish = i > 0 ? i - 1: 0;
375 memcpy(entry, cur, len - 1);
377 new_array[i] = entry;
384 /* add the old entries in the array and delete the old array*/
385 for (i = 0; i < size; i++)
386 new_array[i] = array[i];
391 *out_array = new_array;
396 for (i = start; i < finish; i++)
406 * <intf>[<expr>], <intf>[<expr>],..
408 int lustre_lnet_parse_interfaces(char *intf_str,
409 struct lnet_dlc_network_descr *nw_descr)
414 char *cur = intf_str, *next = NULL;
415 char *end = intf_str + strlen(intf_str);
417 struct lnet_dlc_intf_descr *intf_descr, *tmp;
419 if (nw_descr == NULL)
420 return LUSTRE_CFG_RC_BAD_PARAM;
423 open_square = strchr(cur, '[');
424 if (open_square != NULL) {
425 close_square = strchr(cur, ']');
426 if (close_square == NULL) {
427 rc = LUSTRE_CFG_RC_BAD_PARAM;
431 comma = strchr(cur, ',');
432 if (comma != NULL && comma > close_square) {
434 len = next - close_square;
440 comma = strchr(cur, ',');
450 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
451 if (rc != LUSTRE_CFG_RC_NO_ERR)
457 return LUSTRE_CFG_RC_NO_ERR;
460 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
462 list_del(&intf_descr->intf_on_network);
463 free_intf_descr(intf_descr);
469 int lustre_lnet_config_lib_init(void)
471 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
474 void lustre_lnet_config_lib_uninit(void)
476 unregister_ioc_dev(LNET_DEV_ID);
479 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
480 int seq_no, struct cYAML **err_rc)
482 struct libcfs_ioctl_data data;
485 char err_str[LNET_MAX_STR_LEN];
487 snprintf(err_str, sizeof(err_str), "\"Success\"");
489 LIBCFS_IOC_INIT(data);
491 /* Reverse logic is used here in order not to change
492 * the lctl utility */
493 data.ioc_flags = load_ni_from_mod ? 0 : 1;
495 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
497 rc = l_ioctl(LNET_DEV_ID, opc, &data);
501 "\"LNet %s error: %s\"", (up) ? "configure" :
502 "unconfigure", strerror(errno));
506 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
507 "lnet", err_str, err_rc);
512 static int dispatch_peer_ni_cmd(lnet_nid_t pnid, lnet_nid_t nid, __u32 cmd,
513 struct lnet_ioctl_peer_cfg *data,
514 char *err_str, char *cmd_str)
518 data->prcfg_prim_nid = pnid;
519 data->prcfg_cfg_nid = nid;
521 rc = l_ioctl(LNET_DEV_ID, cmd, data);
526 "\"cannot %s peer ni: %s\"",
527 (cmd_str) ? cmd_str : "add", strerror(errno));
528 err_str[LNET_MAX_STR_LEN - 1] = '\0';
534 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
535 int seq_no, struct cYAML **show_rc,
536 struct cYAML **err_rc)
539 struct lnet_ioctl_ping_data ping;
540 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
541 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
542 struct lnet_process_id id;
543 char err_str[LNET_MAX_STR_LEN] = {0};
544 char *sep, *token, *end;
547 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
551 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
553 data = calloc(1, len);
557 /* create struct cYAML root object */
558 root = cYAML_create_object(NULL, NULL);
562 ping_node = cYAML_create_seq(root, oper);
563 if (ping_node == NULL)
566 /* tokenise each nid in string ping_nids */
567 token = strtok(ping_nids, ",");
570 item = cYAML_create_seq_item(ping_node);
574 if (first_seq == NULL)
577 /* check if '-' is a part of NID, token */
578 sep = strchr(token, '-');
580 id.pid = LNET_PID_ANY;
581 /* if no net is specified, libcfs_str2nid() will assume tcp */
582 id.nid = libcfs_str2nid(token);
583 if (id.nid == LNET_NID_ANY) {
584 snprintf(err_str, sizeof(err_str),
585 "\"cannot parse NID '%s'\"",
587 rc = LUSTRE_CFG_RC_BAD_PARAM;
588 cYAML_build_error(rc, seq_no, MANAGE_CMD,
589 oper, err_str, err_rc);
593 if (token[0] == 'u' || token[0] == 'U')
594 id.pid = (strtoul(&token[1], &end, 0) |
595 (LNET_PID_USERFLAG));
597 id.pid = strtoul(token, &end, 0);
599 /* assuming '-' is part of hostname */
601 id.pid = LNET_PID_ANY;
602 id.nid = libcfs_str2nid(token);
603 if (id.nid == LNET_NID_ANY) {
604 snprintf(err_str, sizeof(err_str),
605 "\"cannot parse NID '%s'\"",
607 rc = LUSTRE_CFG_RC_BAD_PARAM;
608 cYAML_build_error(rc, seq_no, MANAGE_CMD,
614 id.nid = libcfs_str2nid(sep + 1);
615 if (id.nid == LNET_NID_ANY) {
616 snprintf(err_str, sizeof(err_str),
617 "\"cannot parse NID '%s'\"",
619 rc = LUSTRE_CFG_RC_BAD_PARAM;
620 cYAML_build_error(rc, seq_no, MANAGE_CMD,
627 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
628 ping.ping_hdr.ioc_len = sizeof(ping);
630 ping.op_param = param;
631 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
632 ping.ping_buf = data;
634 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
637 sizeof(err_str), "failed to %s %s: %s\n", oper,
638 id.pid == LNET_PID_ANY ?
639 libcfs_nid2str(id.nid) :
640 libcfs_id2str(id), strerror(errno));
641 rc = LUSTRE_CFG_RC_BAD_PARAM;
642 cYAML_build_error(rc, seq_no, MANAGE_CMD,
643 oper, err_str, err_rc);
647 if (cYAML_create_string(item, "primary nid",
648 libcfs_nid2str(ping.ping_id.nid)) == NULL)
651 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
652 "True" : "False") == NULL)
655 tmp = cYAML_create_seq(item, "peer ni");
659 for (i = 0; i < ping.ping_count; i++) {
660 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
663 peer_ni = cYAML_create_seq_item(tmp);
666 memset(buf, 0, sizeof buf);
667 snprintf(buf, sizeof buf, "nid");
668 if (cYAML_create_string(peer_ni, buf,
669 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
675 } while ((token = strtok(NULL, ",")) != NULL);
678 rc = LUSTRE_CFG_RC_NO_ERR;
683 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
684 cYAML_free_tree(root);
685 } else if (show_rc != NULL && *show_rc != NULL) {
686 struct cYAML *show_node;
687 show_node = cYAML_get_object_item(*show_rc, oper);
688 if (show_node != NULL && cYAML_is_sequence(show_node)) {
689 cYAML_insert_child(show_node, first_seq);
692 } else if (show_node == NULL) {
693 cYAML_insert_sibling((*show_rc)->cy_child,
697 cYAML_free_tree(root);
706 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
707 struct cYAML **show_rc, struct cYAML **err_rc)
711 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
712 seq_no, show_rc, err_rc);
716 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
717 struct cYAML **show_rc, struct cYAML **err_rc)
721 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
722 seq_no, show_rc, err_rc);
726 static void lustre_lnet_clean_ip2nets(struct lustre_lnet_ip2nets *ip2nets)
728 struct lustre_lnet_ip_range_descr *ipr, *tmp;
729 struct cfs_expr_list *el, *el_tmp;
731 list_for_each_entry_safe(ipr, tmp,
732 &ip2nets->ip2nets_ip_ranges,
734 list_del(&ipr->ipr_entry);
735 list_for_each_entry_safe(el, el_tmp, &ipr->ipr_expr,
737 list_del(&el->el_link);
738 cfs_expr_list_free(el);
745 * returns an rc < 0 if there is an error
746 * otherwise it returns the number IPs generated
747 * it also has out params: net - network name
749 static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
750 struct lustre_lnet_ip2nets *ip2nets,
751 __u32 *net, char *err_str)
753 struct lustre_lnet_ip_range_descr *ipr;
755 int ip_idx = MAX_NUM_IPS - 1;
756 int ip_range_len, rc = LUSTRE_CFG_RC_NO_ERR;
758 char ip_range[LNET_MAX_STR_LEN];
760 /* separate the two components of the NID */
762 comp2 = strchr(nidstr, '@');
766 "\"cannot parse NID %s\"", nidstr);
767 err_str[LNET_MAX_STR_LEN - 1] = '\0';
768 rc = LUSTRE_CFG_RC_BAD_PARAM;
772 /* length of the expected ip-range */
773 ip_range_len = comp2 - comp1;
774 if (ip_range_len >= LNET_MAX_STR_LEN) {
777 "\"too long ip_range '%s'\"", nidstr);
778 err_str[LNET_MAX_STR_LEN - 1] = '\0';
779 rc = LUSTRE_CFG_RC_BAD_PARAM;
783 /* move beyond '@' */
787 * if the net component is either o2ib or tcp then we expect
788 * an IP range which could only be a single IP address.
791 *net = libcfs_str2net(comp2);
792 net_type = LNET_NETTYP(*net);
793 /* expression support is for o2iblnd and socklnd only */
794 if (net_type != O2IBLND && net_type != SOCKLND)
795 return LUSTRE_CFG_RC_SKIP;
797 strncpy(ip_range, comp1, ip_range_len);
798 ip_range[ip_range_len] = '\0';
799 ip2nets->ip2nets_net.nw_id = *net;
801 rc = lustre_lnet_add_ip_range(&ip2nets->ip2nets_ip_ranges, ip_range);
802 if (rc != LUSTRE_CFG_RC_NO_ERR) {
805 "\"cannot parse ip_range '%.100s'\"", ip_range);
806 err_str[LNET_MAX_STR_LEN - 1] = '\0';
807 rc = LUSTRE_CFG_RC_BAD_PARAM;
812 * Generate all the IP Addresses from the parsed range. For sanity
813 * we allow only a max of MAX_NUM_IPS nids to be configured for
816 list_for_each_entry(ipr, &ip2nets->ip2nets_ip_ranges, ipr_entry)
817 ip_idx = cfs_ip_addr_range_gen(ip_list, MAX_NUM_IPS,
820 if (ip_idx == MAX_NUM_IPS - 1) {
821 snprintf(err_str, LNET_MAX_STR_LEN,
822 "no NIDs provided for configuration");
823 err_str[LNET_MAX_STR_LEN - 1] = '\0';
824 rc = LUSTRE_CFG_RC_NO_MATCH;
826 } else if (ip_idx == -1) {
827 rc = LUSTRE_CFG_RC_LAST_ELEM;
836 static int lustre_lnet_handle_peer_ip2nets(char **nid, int num_nids, bool mr,
837 bool range, __u32 cmd,
838 char *cmd_type, char *err_str)
840 __u32 net = LNET_NIDNET(LNET_NID_ANY);
842 int i, j, rc = LUSTRE_CFG_RC_NO_ERR;
843 __u32 ip_list[MAX_NUM_IPS];
844 struct lustre_lnet_ip2nets ip2nets;
845 struct lnet_ioctl_peer_cfg data;
847 lnet_nid_t prim_nid = LNET_NID_ANY;
849 /* initialize all lists */
850 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
851 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
852 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
854 /* each nid entry is an expression */
855 for (i = 0; i < num_nids; i++) {
856 if (!range && i == 0)
857 prim_nid = libcfs_str2nid(nid[0]);
859 prim_nid = LNET_NID_ANY;
861 rc = lnet_expr2ips(nid[i], ip_list, &ip2nets, &net, err_str);
862 if (rc == LUSTRE_CFG_RC_SKIP)
864 else if (rc == LUSTRE_CFG_RC_LAST_ELEM)
866 else if (rc < LUSTRE_CFG_RC_NO_ERR)
871 for (j = MAX_NUM_IPS - 1; j > ip_idx; j--) {
872 peer_nid = LNET_MKNID(net, ip_list[j]);
873 if (peer_nid == LNET_NID_ANY) {
876 "\"cannot parse NID\"");
877 err_str[LNET_MAX_STR_LEN - 1] = '\0';
878 rc = LUSTRE_CFG_RC_BAD_PARAM;
882 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
885 if (prim_nid == LNET_NID_ANY && j == MAX_NUM_IPS - 1) {
887 peer_nid = LNET_NID_ANY;
890 if (!range && num_nids > 1 && i == 0 &&
891 cmd == IOC_LIBCFS_DEL_PEER_NI)
893 else if (!range && i == 0)
894 peer_nid = LNET_NID_ANY;
897 * If prim_nid is not provided then the first nid in the
898 * list becomes the prim_nid. First time round the loop
899 * use LNET_NID_ANY for the first parameter, then use
900 * nid[0] as the key nid after wards
902 rc = dispatch_peer_ni_cmd(prim_nid, peer_nid, cmd,
903 &data, err_str, cmd_type);
908 * we just deleted the entire peer using the
909 * primary_nid. So don't bother iterating through
910 * the rest of the nids
912 if (prim_nid != LNET_NID_ANY &&
913 peer_nid == LNET_NID_ANY &&
914 cmd == IOC_LIBCFS_DEL_PEER_NI)
918 lustre_lnet_clean_ip2nets(&ip2nets);
922 lustre_lnet_clean_ip2nets(&ip2nets);
926 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
927 bool mr, bool ip2nets, int seq_no,
928 struct cYAML **err_rc)
930 int rc = LUSTRE_CFG_RC_NO_ERR;
931 char err_str[LNET_MAX_STR_LEN] = {0};
932 char **nid_array = NULL;
934 snprintf(err_str, sizeof(err_str), "\"Success\"");
937 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, mr,
938 ip2nets, IOC_LIBCFS_ADD_PEER_NI,
944 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
945 snprintf(err_str, sizeof(err_str),
946 "bad primary NID: '%s'",
948 rc = LUSTRE_CFG_RC_MISSING_PARAM;
954 nid_array = calloc(sizeof(*nid_array), num_nids);
956 snprintf(err_str, sizeof(err_str),
958 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
962 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
965 rc = lustre_lnet_handle_peer_ip2nets((pnid) ? nid_array : nid,
966 num_nids, mr, ip2nets,
967 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
976 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
980 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
981 bool ip2nets, int seq_no, struct cYAML **err_rc)
983 int rc = LUSTRE_CFG_RC_NO_ERR;
984 char err_str[LNET_MAX_STR_LEN] = {0};
985 char **nid_array = NULL;
987 snprintf(err_str, sizeof(err_str), "\"Success\"");
990 rc = lustre_lnet_handle_peer_ip2nets(nid, num_nids, false,
991 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
997 snprintf(err_str, sizeof(err_str),
998 "\"Primary nid is not provided\"");
999 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1001 } else if (!ip2nets) {
1002 if (libcfs_str2nid(pnid) == LNET_NID_ANY) {
1003 rc = LUSTRE_CFG_RC_BAD_PARAM;
1004 snprintf(err_str, sizeof(err_str),
1005 "bad key NID: '%s'",
1012 nid_array = calloc(sizeof(*nid_array), num_nids);
1014 snprintf(err_str, sizeof(err_str),
1016 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1019 nid_array[0] = pnid;
1020 memcpy(&nid_array[1], nid, sizeof(*nid) * (num_nids - 1));
1022 rc = lustre_lnet_handle_peer_ip2nets(nid_array, num_nids, false,
1023 ip2nets, IOC_LIBCFS_DEL_PEER_NI,
1032 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
1036 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
1037 int sen, int seq_no, struct cYAML **err_rc)
1039 struct lnet_ioctl_config_data data;
1040 lnet_nid_t gateway_nid;
1041 int rc = LUSTRE_CFG_RC_NO_ERR;
1043 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1044 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1045 char err_str[LNET_MAX_STR_LEN];
1046 __u32 ip_list[MAX_NUM_IPS];
1047 struct lustre_lnet_ip2nets ip2nets;
1049 /* initialize all lists */
1050 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1051 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1052 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1054 snprintf(err_str, sizeof(err_str), "\"Success\"");
1056 if (nw == NULL || gw == NULL) {
1059 "\"missing mandatory parameter in route config:'%s'\"",
1060 (nw == NULL && gw == NULL) ? "network, gateway" :
1061 (nw == NULL) ? "network" : "gateway");
1062 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1066 rnet = libcfs_str2net(nw);
1067 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1070 "\"cannot parse remote net %s\"", nw);
1071 rc = LUSTRE_CFG_RC_BAD_PARAM;
1076 /* hops is undefined */
1077 hops = LNET_UNDEFINED_HOPS;
1078 } else if (hops < 1 || hops > 255) {
1081 "\"invalid hop count %d, must be between 1 and 255\"",
1083 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1089 } else if (prio < 0) {
1092 "\"invalid priority %d, must be greater than 0\"",
1094 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1100 } else if (sen < 1) {
1103 "\"invalid health sensitivity %d, must be 1 or greater\"",
1105 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1109 rc = lnet_expr2ips(gw, ip_list,
1110 &ip2nets, &net, err_str);
1111 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1113 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1118 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1119 data.cfg_net = rnet;
1120 data.cfg_config_u.cfg_route.rtr_hop = hops;
1121 data.cfg_config_u.cfg_route.rtr_priority = prio;
1122 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
1124 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1125 gateway_nid = LNET_MKNID(net, ip_list[i]);
1126 if (gateway_nid == LNET_NID_ANY) {
1129 "\"cannot form gateway NID: %u\"",
1131 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1132 rc = LUSTRE_CFG_RC_BAD_PARAM;
1135 data.cfg_nid = gateway_nid;
1137 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1138 if (rc != 0 && errno != EEXIST && errno != EHOSTUNREACH) {
1142 "\"cannot add route: %s\"", strerror(errno));
1147 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
1152 int lustre_lnet_del_route(char *nw, char *gw,
1153 int seq_no, struct cYAML **err_rc)
1155 struct lnet_ioctl_config_data data;
1156 lnet_nid_t gateway_nid;
1157 int rc = LUSTRE_CFG_RC_NO_ERR;
1158 __u32 rnet = LNET_NIDNET(LNET_NID_ANY);
1159 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1160 char err_str[LNET_MAX_STR_LEN];
1162 __u32 ip_list[MAX_NUM_IPS];
1163 struct lustre_lnet_ip2nets ip2nets;
1165 /* initialize all lists */
1166 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
1167 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
1168 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
1170 snprintf(err_str, sizeof(err_str), "\"Success\"");
1172 if (nw == NULL || gw == NULL) {
1175 "\"missing mandatory parameter in route delete: '%s'\"",
1176 (nw == NULL && gw == NULL) ? "network, gateway" :
1177 (nw == NULL) ? "network" : "gateway");
1178 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1182 rnet = libcfs_str2net(nw);
1183 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
1186 "\"cannot parse remote net '%s'\"", nw);
1187 rc = LUSTRE_CFG_RC_BAD_PARAM;
1191 rc = lnet_expr2ips(gw, ip_list,
1192 &ip2nets, &net, err_str);
1193 if (rc == LUSTRE_CFG_RC_LAST_ELEM)
1195 else if (rc < LUSTRE_CFG_RC_NO_ERR)
1200 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1201 data.cfg_net = rnet;
1203 for (i = MAX_NUM_IPS - 1; i > ip_idx; i--) {
1204 gateway_nid = LNET_MKNID(net, ip_list[i]);
1205 if (gateway_nid == LNET_NID_ANY) {
1208 "\"cannot form gateway NID: %u\"",
1210 err_str[LNET_MAX_STR_LEN - 1] = '\0';
1211 rc = LUSTRE_CFG_RC_BAD_PARAM;
1214 data.cfg_nid = gateway_nid;
1216 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1221 "\"cannot delete route: %s\"", strerror(errno));
1226 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
1231 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
1232 int seq_no, struct cYAML **show_rc,
1233 struct cYAML **err_rc, bool backup)
1235 struct lnet_ioctl_config_data data;
1236 lnet_nid_t gateway_nid;
1237 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1239 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1241 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1242 struct cYAML *first_seq = NULL;
1243 char err_str[LNET_MAX_STR_LEN];
1246 snprintf(err_str, sizeof(err_str),
1247 "\"out of memory\"");
1250 net = libcfs_str2net(nw);
1251 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1254 "\"cannot parse net '%s'\"", nw);
1255 rc = LUSTRE_CFG_RC_BAD_PARAM;
1260 /* show all routes without filtering on net */
1261 net = LNET_NIDNET(LNET_NID_ANY);
1265 gateway_nid = libcfs_str2nid(gw);
1266 if (gateway_nid == LNET_NID_ANY) {
1269 "\"cannot parse gateway NID '%s'\"", gw);
1270 rc = LUSTRE_CFG_RC_BAD_PARAM;
1274 /* show all routes with out filtering on gateway */
1275 gateway_nid = LNET_NID_ANY;
1277 if ((hops < 1 && hops != -1) || hops > 255) {
1280 "\"invalid hop count %d, must be between 0 and 256\"",
1282 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1286 /* create struct cYAML root object */
1287 root = cYAML_create_object(NULL, NULL);
1291 route = cYAML_create_seq(root, "route");
1296 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1299 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1305 /* filter on provided data */
1306 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1307 net != data.cfg_net)
1310 if (gateway_nid != LNET_NID_ANY &&
1311 gateway_nid != data.cfg_nid)
1315 hops != data.cfg_config_u.cfg_route.rtr_hop)
1319 prio != data.cfg_config_u.cfg_route.rtr_priority)
1322 /* default rc to -1 incase we hit the goto */
1326 item = cYAML_create_seq_item(route);
1330 if (first_seq == NULL)
1333 if (cYAML_create_string(item, "net",
1334 libcfs_net2str(data.cfg_net)) == NULL)
1337 if (cYAML_create_string(item, "gateway",
1338 libcfs_nid2str(data.cfg_nid)) == NULL)
1342 if (cYAML_create_number(item, "hop",
1343 (int) data.cfg_config_u.
1344 cfg_route.rtr_hop) ==
1348 if (cYAML_create_number(item, "priority",
1350 cfg_route.rtr_priority) == NULL)
1353 if (cYAML_create_number(item, "health_sensitivity",
1355 cfg_route.rtr_sensitivity) == NULL)
1359 cYAML_create_string(item, "state",
1360 data.cfg_config_u.cfg_route.
1362 "up" : "down") == NULL)
1367 /* print output iff show_rc is not provided */
1368 if (show_rc == NULL)
1369 cYAML_print_tree(root);
1371 if (l_errno != ENOENT) {
1374 "\"cannot get routes: %s\"",
1379 rc = LUSTRE_CFG_RC_NO_ERR;
1381 snprintf(err_str, sizeof(err_str), "\"success\"");
1383 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1384 cYAML_free_tree(root);
1385 } else if (show_rc != NULL && *show_rc != NULL) {
1386 struct cYAML *show_node;
1387 /* find the route node, if one doesn't exist then
1388 * insert one. Otherwise add to the one there
1390 show_node = cYAML_get_object_item(*show_rc, "route");
1391 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1392 cYAML_insert_child(show_node, first_seq);
1395 } else if (show_node == NULL) {
1396 cYAML_insert_sibling((*show_rc)->cy_child,
1400 cYAML_free_tree(root);
1406 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1411 static int socket_intf_query(int request, char *intf,
1417 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1418 return LUSTRE_CFG_RC_BAD_PARAM;
1420 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1422 return LUSTRE_CFG_RC_BAD_PARAM;
1424 strcpy(ifr->ifr_name, intf);
1425 rc = ioctl(sockfd, request, ifr);
1427 rc = LUSTRE_CFG_RC_BAD_PARAM;
1434 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1439 memset(&ifr, 0, sizeof(ifr));
1440 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1442 return LUSTRE_CFG_RC_BAD_PARAM;
1444 if ((ifr.ifr_flags & IFF_UP) == 0)
1445 return LUSTRE_CFG_RC_BAD_PARAM;
1447 memset(&ifr, 0, sizeof(ifr));
1448 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1450 return LUSTRE_CFG_RC_BAD_PARAM;
1452 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1453 *ip = bswap_32(*ip);
1455 return LUSTRE_CFG_RC_NO_ERR;
1459 * for each interface in the array of interfaces find the IP address of
1460 * that interface, create its nid and add it to an array of NIDs.
1461 * Stop if any of the interfaces is down
1463 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1464 lnet_nid_t **nids, __u32 *nnids,
1465 char *err_str, size_t str_len)
1467 int i = 0, count = 0, rc;
1468 struct lnet_dlc_intf_descr *intf;
1469 char val[LNET_MAX_STR_LEN];
1476 if (nw == NULL || nids == NULL) {
1477 snprintf(err_str, str_len,
1478 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1479 err_str[str_len - 1] = '\0';
1480 return LUSTRE_CFG_RC_BAD_PARAM;
1483 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1486 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1490 *nids = calloc(count, sizeof(lnet_nid_t));
1491 if (*nids == NULL) {
1492 snprintf(err_str, str_len,
1493 "\"out of memory\"");
1494 err_str[str_len - 1] = '\0';
1495 return LUSTRE_CFG_RC_OUT_OF_MEM;
1498 * special case the GNI interface since it doesn't have an IP
1499 * address. The assumption is that there can only be one GNI
1500 * interface in the system. No interface name is provided.
1502 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1503 rc = read_sysfs_file(gni_nid_path, "nid", val,
1506 snprintf(err_str, str_len,
1507 "\"cannot read gni nid\"");
1508 err_str[str_len - 1] = '\0';
1511 gni_num = atoi(val);
1513 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1518 /* look at the other interfaces */
1519 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1520 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1521 /* handle LNDs with numeric interface name */
1522 num = strtoul(intf->intf_name, &endp, 0);
1523 if (endp == intf->intf_name || *endp != '\0') {
1524 rc = LUSTRE_CFG_RC_BAD_PARAM;
1525 snprintf(err_str, str_len,
1526 "\"couldn't query intf %s\"",
1528 err_str[str_len - 1] = '\0';
1531 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1534 /* handle LNDs with ip interface name */
1535 rc = lustre_lnet_queryip(intf, &ip);
1536 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1537 snprintf(err_str, str_len,
1538 "\"couldn't query intf %s\"",
1540 err_str[str_len - 1] = '\0';
1543 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1560 * called repeatedly until a match or no more ip range
1562 * ip_range expression
1563 * interface list with all the interface names.
1564 * all the interfaces in the system.
1566 * try to match the ip_range expr to one of the interfaces' IPs in
1567 * the system. If we hit a patch for an interface. Check if that
1568 * interface name is in the list.
1570 * If there are more than one interface in the list, then make sure
1571 * that the IPs for all of these interfaces match the ip ranges
1574 * for each interface in intf_list
1575 * look up the intf name in ifa
1576 * if not there then no match
1577 * check ip obtained from ifa against a match to any of the
1579 * If no match, then fail
1581 * The result is that all the interfaces have to match.
1583 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1584 struct list_head *intf_list,
1585 struct list_head *ip_ranges)
1589 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1590 struct ifaddrs *ifaddr = ifa;
1591 struct lustre_lnet_ip_range_descr *ip_range;
1595 * if there are no explicit interfaces, and no ip ranges, then
1596 * configure the first tcp interface we encounter.
1598 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1599 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1600 if (ifaddr->ifa_addr == NULL)
1603 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1606 family = ifaddr->ifa_addr->sa_family;
1607 if (family == AF_INET &&
1608 strcmp(ifaddr->ifa_name, "lo") != 0) {
1609 rc = lustre_lnet_add_intf_descr
1610 (intf_list, ifaddr->ifa_name,
1611 strlen(ifaddr->ifa_name));
1613 if (rc != LUSTRE_CFG_RC_NO_ERR)
1616 return LUSTRE_CFG_RC_MATCH;
1619 return LUSTRE_CFG_RC_NO_MATCH;
1623 * First interface which matches an IP pattern will be used
1625 if (list_empty(intf_list)) {
1627 * no interfaces provided in the rule, but an ip range is
1628 * provided, so try and match an interface to the ip
1631 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1632 if (ifaddr->ifa_addr == NULL)
1635 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1638 family = ifaddr->ifa_addr->sa_family;
1639 if (family == AF_INET) {
1640 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1643 list_for_each_entry(ip_range, ip_ranges,
1645 rc = cfs_ip_addr_match(bswap_32(ip),
1646 &ip_range->ipr_expr);
1650 rc = lustre_lnet_add_intf_descr
1651 (intf_list, ifaddr->ifa_name,
1652 strlen(ifaddr->ifa_name));
1654 if (rc != LUSTRE_CFG_RC_NO_ERR)
1660 if (!list_empty(intf_list))
1661 return LUSTRE_CFG_RC_MATCH;
1663 return LUSTRE_CFG_RC_NO_MATCH;
1667 * If an interface is explicitly specified the ip-range might or
1668 * might not be specified. if specified the interface needs to match the
1669 * ip-range. If no ip-range then the interfaces are
1670 * automatically matched if they are all up.
1671 * If > 1 interfaces all the interfaces must match for the NI to
1674 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1675 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1676 if (ifaddr->ifa_addr == NULL)
1679 family = ifaddr->ifa_addr->sa_family;
1680 if (family == AF_INET &&
1681 strcmp(intf_descr->intf_name,
1682 ifaddr->ifa_name) == 0)
1686 if (ifaddr == NULL) {
1687 list_del(&intf_descr->intf_on_network);
1688 free_intf_descr(intf_descr);
1692 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1693 list_del(&intf_descr->intf_on_network);
1694 free_intf_descr(intf_descr);
1698 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1701 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1702 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1708 /* no match for this interface */
1709 list_del(&intf_descr->intf_on_network);
1710 free_intf_descr(intf_descr);
1714 return LUSTRE_CFG_RC_MATCH;
1717 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1718 lnet_nid_t **nids, __u32 *nnids,
1719 char *err_str, size_t str_len)
1721 struct ifaddrs *ifa;
1722 int rc = LUSTRE_CFG_RC_NO_ERR;
1724 rc = getifaddrs(&ifa);
1726 snprintf(err_str, str_len,
1727 "\"failed to get interface addresses: %d\"", -errno);
1728 err_str[str_len - 1] = '\0';
1732 rc = lustre_lnet_match_ip_to_intf(ifa,
1733 &ip2nets->ip2nets_net.nw_intflist,
1734 &ip2nets->ip2nets_ip_ranges);
1735 if (rc != LUSTRE_CFG_RC_MATCH) {
1736 snprintf(err_str, str_len,
1737 "\"couldn't match ip to existing interfaces\"");
1738 err_str[str_len - 1] = '\0';
1743 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1744 err_str, sizeof(err_str));
1745 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1756 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1757 struct lnet_ioctl_config_lnd_tunables *tunables,
1758 struct cfs_expr_list *global_cpts,
1759 lnet_nid_t *nids, char *err_str)
1762 struct lnet_ioctl_config_ni *conf;
1763 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1764 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1767 struct lnet_dlc_intf_descr *intf_descr;
1769 struct cfs_expr_list *cpt_expr;
1771 list_for_each_entry(intf_descr, intf_list,
1773 if (tunables != NULL)
1774 len = sizeof(struct lnet_ioctl_config_ni) +
1775 sizeof(struct lnet_ioctl_config_lnd_tunables);
1777 len = sizeof(struct lnet_ioctl_config_ni);
1779 data = calloc(1, len);
1781 return LUSTRE_CFG_RC_OUT_OF_MEM;
1782 conf = (struct lnet_ioctl_config_ni*) data;
1783 if (tunables != NULL)
1784 tun = (struct lnet_ioctl_config_lnd_tunables*)
1787 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1788 conf->lic_cfg_hdr.ioc_len = len;
1789 conf->lic_nid = nids[i];
1790 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1793 if (intf_descr->cpt_expr != NULL)
1794 cpt_expr = intf_descr->cpt_expr;
1795 else if (global_cpts != NULL)
1796 cpt_expr = global_cpts;
1800 if (cpt_expr != NULL) {
1801 count = cfs_expr_list_values(cpt_expr,
1802 LNET_MAX_SHOW_NUM_CPT,
1805 memcpy(conf->lic_cpts, cpt_array,
1806 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1815 conf->lic_ncpts = count;
1817 if (tunables != NULL)
1818 memcpy(tun, tunables, sizeof(*tunables));
1820 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1825 "\"cannot add network: %s\"", strerror(errno));
1833 return LUSTRE_CFG_RC_NO_ERR;
1837 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1838 struct lnet_ioctl_config_lnd_tunables *tunables,
1839 struct cfs_expr_list *global_cpts,
1840 int seq_no, struct cYAML **err_rc)
1842 lnet_nid_t *nids = NULL;
1845 char err_str[LNET_MAX_STR_LEN];
1847 snprintf(err_str, sizeof(err_str), "\"success\"");
1852 "\"incomplete ip2nets information\"");
1853 rc = LUSTRE_CFG_RC_BAD_PARAM;
1858 * call below function to resolve the rules into a list of nids.
1859 * The memory is allocated in that function then freed here when
1860 * it's no longer needed.
1862 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1864 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1867 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1868 snprintf(err_str, sizeof(err_str),
1869 "\"no interfaces match ip2nets rules\"");
1873 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1874 tunables, global_cpts, nids,
1881 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1885 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1886 struct cfs_expr_list *global_cpts,
1888 struct lnet_ioctl_config_lnd_tunables *tunables,
1889 int seq_no, struct cYAML **err_rc)
1892 struct lnet_ioctl_config_ni *conf;
1893 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1894 char buf[LNET_MAX_STR_LEN];
1895 int rc = LUSTRE_CFG_RC_NO_ERR;
1896 char err_str[LNET_MAX_STR_LEN];
1897 lnet_nid_t *nids = NULL;
1901 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1904 snprintf(err_str, sizeof(err_str), "\"success\"");
1906 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1907 (list_empty(&nw_descr->nw_intflist) &&
1908 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1911 "\"missing mandatory parameters in NI config: '%s'\"",
1912 (nw_descr == NULL) ? "network , interface" :
1913 (nw_descr->nw_id == 0) ? "network" : "interface");
1914 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1918 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1921 "\"ip2net string too long %d\"",
1922 (int)strlen(ip2net));
1923 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1927 if (ip2net != NULL) {
1928 if (tunables != NULL)
1929 len = sizeof(struct lnet_ioctl_config_ni) +
1930 sizeof(struct lnet_ioctl_config_lnd_tunables);
1932 len = sizeof(struct lnet_ioctl_config_ni);
1933 data = calloc(1, len);
1935 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1938 conf = (struct lnet_ioctl_config_ni*) data;
1939 if (tunables != NULL)
1940 tun = (struct lnet_ioctl_config_lnd_tunables*)
1941 (data + sizeof(*conf));
1943 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1944 conf->lic_cfg_hdr.ioc_len = len;
1945 strncpy(conf->lic_legacy_ip2nets, ip2net,
1948 if (global_cpts != NULL) {
1949 count = cfs_expr_list_values(global_cpts,
1950 LNET_MAX_SHOW_NUM_CPT,
1953 memcpy(conf->lic_cpts, cpt_array,
1954 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1963 conf->lic_ncpts = count;
1965 if (tunables != NULL)
1966 memcpy(tun, tunables, sizeof(*tunables));
1968 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1973 "\"cannot add network: %s\"", strerror(errno));
1980 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1981 rc = LUSTRE_CFG_RC_NO_ERR;
1985 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1988 "\"cannot parse net '%s'\"",
1989 libcfs_net2str(nw_descr->nw_id));
1990 rc = LUSTRE_CFG_RC_BAD_PARAM;
1995 * special case the GNI since no interface name is expected
1997 if (list_empty(&nw_descr->nw_intflist) &&
1998 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
2001 "\"no interface name provided\"");
2002 rc = LUSTRE_CFG_RC_BAD_PARAM;
2006 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2007 err_str, sizeof(err_str));
2009 rc = LUSTRE_CFG_RC_BAD_PARAM;
2013 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
2014 tunables, global_cpts, nids,
2018 if (nw_descr != NULL) {
2019 list_for_each_entry_safe(intf_descr, tmp,
2020 &nw_descr->nw_intflist,
2022 list_del(&intf_descr->intf_on_network);
2023 free_intf_descr(intf_descr);
2027 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
2038 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
2039 int seq_no, struct cYAML **err_rc)
2041 struct lnet_ioctl_config_ni data;
2042 int rc = LUSTRE_CFG_RC_NO_ERR, i;
2043 char err_str[LNET_MAX_STR_LEN];
2044 lnet_nid_t *nids = NULL;
2046 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2048 snprintf(err_str, sizeof(err_str), "\"success\"");
2050 if (nw_descr == NULL || nw_descr->nw_id == 0) {
2053 "\"missing mandatory parameter in deleting NI: '%s'\"",
2054 (nw_descr == NULL) ? "network , interface" :
2055 (nw_descr->nw_id == 0) ? "network" : "interface");
2056 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2060 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2061 return LUSTRE_CFG_RC_NO_ERR;
2063 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
2066 "\"cannot parse net '%s'\"",
2067 libcfs_net2str(nw_descr->nw_id));
2068 rc = LUSTRE_CFG_RC_BAD_PARAM;
2072 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2073 err_str, sizeof(err_str));
2075 rc = LUSTRE_CFG_RC_BAD_PARAM;
2080 * no interfaces just the nw_id is specified
2083 nids = calloc(1, sizeof(*nids));
2085 snprintf(err_str, sizeof(err_str),
2086 "\"out of memory\"");
2087 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2090 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2094 for (i = 0; i < nnids; i++) {
2095 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2096 data.lic_nid = nids[i];
2098 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2103 "\"cannot del network: %s\"", strerror(errno));
2107 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2109 list_del(&intf_descr->intf_on_network);
2110 free_intf_descr(intf_descr);
2114 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2123 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2124 enum lnet_health_type type, char *name,
2125 int seq_no, struct cYAML **err_rc)
2127 struct lnet_ioctl_reset_health_cfg data;
2128 int rc = LUSTRE_CFG_RC_NO_ERR;
2129 char err_str[LNET_MAX_STR_LEN];
2131 snprintf(err_str, sizeof(err_str), "\"success\"");
2133 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2134 data.rh_type = type;
2136 data.rh_value = value;
2139 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2143 sizeof(err_str), "Can not configure health value: %s",
2147 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2152 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2153 struct cYAML **err_rc)
2157 nid = libcfs_str2nid(ni_nid);
2160 return lustre_lnet_config_healthv(value, all, nid,
2161 LNET_HEALTH_TYPE_LOCAL_NI,
2162 "ni healthv", seq_no, err_rc);
2165 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2166 int seq_no, struct cYAML **err_rc)
2170 nid = libcfs_str2nid(lpni_nid);
2173 return lustre_lnet_config_healthv(value, all, nid,
2174 LNET_HEALTH_TYPE_PEER_NI,
2175 "peer_ni healthv", seq_no, err_rc);
2179 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2180 struct lnet_ioctl_comm_count *counts)
2182 if (cYAML_create_number(yaml, "put",
2183 counts->ico_put_count)
2186 if (cYAML_create_number(yaml, "get",
2187 counts->ico_get_count)
2190 if (cYAML_create_number(yaml, "reply",
2191 counts->ico_reply_count)
2194 if (cYAML_create_number(yaml, "ack",
2195 counts->ico_ack_count)
2198 if (cYAML_create_number(yaml, "hello",
2199 counts->ico_hello_count)
2206 static struct lnet_ioctl_comm_count *
2207 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2210 return &msg_stats->im_send_stats;
2212 return &msg_stats->im_recv_stats;
2214 return &msg_stats->im_drop_stats;
2219 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2220 struct cYAML **show_rc, struct cYAML **err_rc,
2224 struct lnet_ioctl_config_ni *ni_data;
2225 struct lnet_ioctl_config_lnd_tunables *lnd;
2226 struct lnet_ioctl_element_stats *stats;
2227 struct lnet_ioctl_element_msg_stats msg_stats;
2228 struct lnet_ioctl_local_ni_hstats hstats;
2229 __u32 net = LNET_NIDNET(LNET_NID_ANY);
2230 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
2231 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2233 struct cYAML *root = NULL, *tunables = NULL,
2234 *net_node = NULL, *interfaces = NULL,
2235 *item = NULL, *first_seq = NULL,
2236 *tmp = NULL, *statistics = NULL,
2238 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2239 char str_buf[str_buf_len];
2241 char err_str[LNET_MAX_STR_LEN];
2242 bool exist = false, new_net = true;
2244 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2246 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2248 buf = calloc(1, buf_size);
2252 ni_data = (struct lnet_ioctl_config_ni *)buf;
2255 net = libcfs_str2net(nw);
2256 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2259 "\"cannot parse net '%s'\"", nw);
2260 rc = LUSTRE_CFG_RC_BAD_PARAM;
2265 root = cYAML_create_object(NULL, NULL);
2269 net_node = cYAML_create_seq(root, "net");
2270 if (net_node == NULL)
2277 memset(buf, 0, buf_size);
2279 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2281 * set the ioc_len to the proper value since INIT assumes
2284 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2285 ni_data->lic_idx = i;
2287 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2293 rc_net = LNET_NIDNET(ni_data->lic_nid);
2295 /* filter on provided data */
2296 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2300 /* if we're backing up don't store lo */
2301 if (backup && LNET_NETTYP(rc_net) == LOLND)
2304 /* default rc to -1 in case we hit the goto */
2308 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2309 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2310 (ni_data->lic_bulk + sizeof(*stats));
2312 if (rc_net != prev_net) {
2319 if (!cYAML_create_string(net_node, "net type",
2320 libcfs_net2str(rc_net)))
2323 tmp = cYAML_create_seq(net_node, "local NI(s)");
2329 /* create the tree to be printed. */
2330 item = cYAML_create_seq_item(tmp);
2334 if (first_seq == NULL)
2338 cYAML_create_string(item, "nid",
2339 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2343 cYAML_create_string(item,
2345 (ni_data->lic_status ==
2346 LNET_NI_STATUS_UP) ?
2347 "up" : "down") == NULL)
2350 /* don't add interfaces unless there is at least one
2352 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2353 interfaces = cYAML_create_object(item, "interfaces");
2354 if (interfaces == NULL)
2357 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2358 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2360 sizeof(str_buf), "%d", j);
2361 if (cYAML_create_string(interfaces,
2363 ni_data->lic_ni_intf[j]) ==
2375 goto continue_without_msg_stats;
2377 statistics = cYAML_create_object(item, "statistics");
2378 if (statistics == NULL)
2381 if (cYAML_create_number(statistics, "send_count",
2382 stats->iel_send_count)
2386 if (cYAML_create_number(statistics, "recv_count",
2387 stats->iel_recv_count)
2391 if (cYAML_create_number(statistics, "drop_count",
2392 stats->iel_drop_count)
2397 goto continue_without_msg_stats;
2399 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2400 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2401 msg_stats.im_idx = i;
2403 rc = l_ioctl(LNET_DEV_ID,
2404 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2408 goto continue_without_msg_stats;
2411 for (k = 0; k < 3; k++) {
2412 struct lnet_ioctl_comm_count *counts;
2413 struct cYAML *msg_statistics = NULL;
2415 msg_statistics = cYAML_create_object(item,
2416 (char *)gmsg_stat_names[k]);
2417 if (msg_statistics == NULL)
2420 counts = get_counts(&msg_stats, k);
2424 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2429 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2430 hstats.hlni_nid = ni_data->lic_nid;
2431 /* grab health stats */
2432 rc = l_ioctl(LNET_DEV_ID,
2433 IOC_LIBCFS_GET_LOCAL_HSTATS,
2437 goto continue_without_msg_stats;
2439 yhstats = cYAML_create_object(item, "health stats");
2442 if (cYAML_create_number(yhstats, "health value",
2443 hstats.hlni_health_value)
2446 if (cYAML_create_number(yhstats, "interrupts",
2447 hstats.hlni_local_interrupt)
2450 if (cYAML_create_number(yhstats, "dropped",
2451 hstats.hlni_local_dropped)
2454 if (cYAML_create_number(yhstats, "aborted",
2455 hstats.hlni_local_aborted)
2458 if (cYAML_create_number(yhstats, "no route",
2459 hstats.hlni_local_no_route)
2462 if (cYAML_create_number(yhstats, "timeouts",
2463 hstats.hlni_local_timeout)
2466 if (cYAML_create_number(yhstats, "error",
2467 hstats.hlni_local_error)
2471 continue_without_msg_stats:
2472 tunables = cYAML_create_object(item, "tunables");
2476 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2477 if (rc != LUSTRE_CFG_RC_NO_ERR)
2480 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2482 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2483 rc != LUSTRE_CFG_RC_NO_MATCH)
2486 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2487 tunables = cYAML_create_object(item,
2489 if (tunables == NULL)
2494 cYAML_create_number(item, "dev cpt",
2495 ni_data->lic_dev_cpt) == NULL)
2499 cYAML_create_number(item, "tcp bonding",
2500 ni_data->lic_tcp_bonding)
2504 /* out put the CPTs in the format: "[x,x,x,...]" */
2505 limit = str_buf + str_buf_len - 3;
2506 pos += snprintf(pos, limit - pos, "\"[");
2507 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2508 j < ni_data->lic_ncpts &&
2510 pos += snprintf(pos, limit - pos,
2511 "%d", ni_data->lic_cpts[j]);
2512 if ((j + 1) < ni_data->lic_ncpts)
2513 pos += snprintf(pos, limit - pos, ",");
2515 pos += snprintf(pos, 3, "]\"");
2517 if (ni_data->lic_ncpts >= 1 &&
2518 cYAML_create_string(item, "CPT",
2524 /* Print out the net information only if show_rc is not provided */
2525 if (show_rc == NULL)
2526 cYAML_print_tree(root);
2528 if (l_errno != ENOENT) {
2531 "\"cannot get networks: %s\"",
2536 rc = LUSTRE_CFG_RC_NO_ERR;
2538 snprintf(err_str, sizeof(err_str), "\"success\"");
2540 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2541 cYAML_free_tree(root);
2542 } else if (show_rc != NULL && *show_rc != NULL) {
2543 struct cYAML *show_node;
2544 /* find the net node, if one doesn't exist
2545 * then insert one. Otherwise add to the one there
2547 show_node = cYAML_get_object_item(*show_rc, "net");
2548 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2549 cYAML_insert_child(show_node, first_seq);
2552 } else if (show_node == NULL) {
2553 cYAML_insert_sibling((*show_rc)->cy_child,
2557 cYAML_free_tree(root);
2563 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2568 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2570 struct lnet_ioctl_config_data data;
2571 int rc = LUSTRE_CFG_RC_NO_ERR;
2572 char err_str[LNET_MAX_STR_LEN];
2574 snprintf(err_str, sizeof(err_str), "\"success\"");
2576 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2577 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2579 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2584 "\"cannot %s routing %s\"",
2585 (enable) ? "enable" : "disable", strerror(errno));
2590 cYAML_build_error(rc, seq_no,
2591 (enable) ? ADD_CMD : DEL_CMD,
2592 "routing", err_str, err_rc);
2597 int ioctl_set_value(__u32 val, int ioc, char *name,
2598 int seq_no, struct cYAML **err_rc)
2600 struct lnet_ioctl_set_value data;
2601 int rc = LUSTRE_CFG_RC_NO_ERR;
2602 char err_str[LNET_MAX_STR_LEN];
2604 snprintf(err_str, sizeof(err_str), "\"success\"");
2606 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2607 data.sv_value = val;
2609 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2614 "\"cannot configure %s to %d: %s\"", name,
2615 val, strerror(errno));
2618 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2623 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2625 int rc = LUSTRE_CFG_RC_NO_ERR;
2626 char err_str[LNET_MAX_STR_LEN];
2627 char val[LNET_MAX_STR_LEN];
2629 snprintf(err_str, sizeof(err_str), "\"success\"");
2631 snprintf(val, sizeof(val), "%d", intrv);
2633 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2634 1, strlen(val) + 1);
2636 snprintf(err_str, sizeof(err_str),
2637 "\"cannot configure recovery interval: %s\"",
2640 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2645 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2647 int rc = LUSTRE_CFG_RC_NO_ERR;
2648 char err_str[LNET_MAX_STR_LEN];
2649 char val[LNET_MAX_STR_LEN];
2651 snprintf(err_str, sizeof(err_str), "\"success\"");
2653 snprintf(val, sizeof(val), "%d", sen);
2655 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2656 1, strlen(val) + 1);
2658 snprintf(err_str, sizeof(err_str),
2659 "\"cannot configure router health sensitivity: %s\"",
2662 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2667 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2669 int rc = LUSTRE_CFG_RC_NO_ERR;
2670 char err_str[LNET_MAX_STR_LEN];
2671 char val[LNET_MAX_STR_LEN];
2673 snprintf(err_str, sizeof(err_str), "\"success\"");
2675 snprintf(val, sizeof(val), "%d", sen);
2677 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2678 1, strlen(val) + 1);
2680 snprintf(err_str, sizeof(err_str),
2681 "\"cannot configure health sensitivity: %s\"",
2684 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2689 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2691 int rc = LUSTRE_CFG_RC_NO_ERR;
2692 char err_str[LNET_MAX_STR_LEN];
2693 char val[LNET_MAX_STR_LEN];
2695 snprintf(err_str, sizeof(err_str), "\"success\"");
2697 snprintf(val, sizeof(val), "%d", timeout);
2699 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2700 1, strlen(val) + 1);
2702 snprintf(err_str, sizeof(err_str),
2703 "\"cannot configure transaction timeout: %s\"",
2706 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2711 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2713 int rc = LUSTRE_CFG_RC_NO_ERR;
2714 char err_str[LNET_MAX_STR_LEN];
2715 char val[LNET_MAX_STR_LEN];
2717 snprintf(err_str, sizeof(err_str), "\"success\"");
2719 snprintf(val, sizeof(val), "%d", count);
2721 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2722 1, strlen(val) + 1);
2724 snprintf(err_str, sizeof(err_str),
2725 "\"cannot configure retry count: %s\"",
2728 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2733 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2735 int rc = LUSTRE_CFG_RC_NO_ERR;
2736 char err_str[LNET_MAX_STR_LEN];
2737 char val[LNET_MAX_STR_LEN];
2739 snprintf(err_str, sizeof(err_str), "\"success\"");
2741 snprintf(val, sizeof(val), "%d", max);
2743 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2744 1, strlen(val) + 1);
2746 snprintf(err_str, sizeof(err_str),
2747 "\"cannot configure max interfaces: %s\"",
2750 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2755 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2757 int rc = LUSTRE_CFG_RC_NO_ERR;
2758 char err_str[LNET_MAX_STR_LEN];
2759 char val[LNET_MAX_STR_LEN];
2761 snprintf(err_str, sizeof(err_str), "\"success\"");
2763 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2765 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2766 1, strlen(val) + 1);
2768 snprintf(err_str, sizeof(err_str),
2769 "\"cannot configure discovery: %s\"",
2772 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2778 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2779 struct cYAML **err_rc)
2781 int rc = LUSTRE_CFG_RC_NO_ERR;
2782 char err_str[LNET_MAX_STR_LEN];
2783 char val[LNET_MAX_STR_LEN];
2785 snprintf(err_str, sizeof(err_str), "\"success\"");
2787 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2789 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2790 1, strlen(val) + 1);
2792 snprintf(err_str, sizeof(err_str),
2793 "\"cannot configure drop asym route: %s\"",
2796 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2803 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2805 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2806 "numa_range", seq_no, err_rc);
2809 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2810 struct cYAML **err_rc)
2812 struct lnet_ioctl_config_data data;
2813 int rc = LUSTRE_CFG_RC_NO_ERR;
2814 char err_str[LNET_MAX_STR_LEN];
2816 snprintf(err_str, sizeof(err_str), "\"success\"");
2818 /* -1 indicates to ignore changes to this field */
2819 if (tiny < -1 || small < -1 || large < -1) {
2822 "\"tiny, small and large must be >= 0\"");
2823 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2827 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2828 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2829 data.cfg_config_u.cfg_buffers.buf_small = small;
2830 data.cfg_config_u.cfg_buffers.buf_large = large;
2832 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2837 "\"cannot configure buffers: %s\"", strerror(errno));
2842 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2847 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2848 struct cYAML **err_rc, bool backup)
2850 struct lnet_ioctl_config_data *data;
2851 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2852 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2855 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2856 int buf_count[LNET_NRBPOOLS] = {0};
2857 struct cYAML *root = NULL, *pools_node = NULL,
2858 *type_node = NULL, *item = NULL, *cpt = NULL,
2859 *first_seq = NULL, *buffers = NULL;
2861 char err_str[LNET_MAX_STR_LEN];
2862 char node_name[LNET_MAX_STR_LEN];
2865 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2867 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2871 data = (struct lnet_ioctl_config_data *)buf;
2873 root = cYAML_create_object(NULL, NULL);
2878 pools_node = cYAML_create_object(root, "routing");
2880 pools_node = cYAML_create_seq(root, "routing");
2881 if (pools_node == NULL)
2885 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2886 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2887 sizeof(struct lnet_ioctl_pool_cfg);
2888 data->cfg_count = i;
2890 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2898 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2901 goto calculate_buffers;
2903 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2904 item = cYAML_create_seq_item(pools_node);
2908 if (first_seq == NULL)
2911 cpt = cYAML_create_object(item, node_name);
2916 /* create the tree and print */
2917 for (j = 0; j < LNET_NRBPOOLS; j++) {
2919 type_node = cYAML_create_object(cpt, pools[j]);
2920 if (type_node == NULL)
2924 cYAML_create_number(type_node, "npages",
2925 pool_cfg->pl_pools[j].pl_npages)
2929 cYAML_create_number(type_node, "nbuffers",
2930 pool_cfg->pl_pools[j].
2931 pl_nbuffers) == NULL)
2934 cYAML_create_number(type_node, "credits",
2935 pool_cfg->pl_pools[j].
2936 pl_credits) == NULL)
2939 cYAML_create_number(type_node, "mincredits",
2940 pool_cfg->pl_pools[j].
2941 pl_mincredits) == NULL)
2943 /* keep track of the total count for each of the
2944 * tiny, small and large buffers */
2945 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2949 if (pool_cfg != NULL) {
2951 if (cYAML_create_number(pools_node, "enable",
2952 pool_cfg->pl_routing) ==
2956 goto add_buffer_section;
2959 item = cYAML_create_seq_item(pools_node);
2963 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2969 /* create a buffers entry in the show. This is necessary so that
2970 * if the YAML output is used to configure a node, the buffer
2971 * configuration takes hold */
2972 buffers = cYAML_create_object(root, "buffers");
2973 if (buffers == NULL)
2976 for (i = 0; i < LNET_NRBPOOLS; i++) {
2977 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2981 if (show_rc == NULL)
2982 cYAML_print_tree(root);
2984 if (l_errno != ENOENT) {
2987 "\"cannot get routing information: %s\"",
2992 rc = LUSTRE_CFG_RC_NO_ERR;
2994 snprintf(err_str, sizeof(err_str), "\"success\"");
2995 rc = LUSTRE_CFG_RC_NO_ERR;
2999 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3000 cYAML_free_tree(root);
3001 } else if (show_rc != NULL && *show_rc != NULL) {
3002 struct cYAML *routing_node;
3003 /* there should exist only one routing block and one
3004 * buffers block. If there already exists a previous one
3005 * then don't add another */
3006 routing_node = cYAML_get_object_item(*show_rc, "routing");
3007 if (routing_node == NULL) {
3008 cYAML_insert_sibling((*show_rc)->cy_child,
3012 cYAML_free_tree(root);
3018 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3023 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3024 struct cYAML **show_rc, struct cYAML **err_rc,
3028 * TODO: This function is changing in a future patch to accommodate
3029 * PEER_LIST and proper filtering on any nid of the peer
3031 struct lnet_ioctl_peer_cfg peer_info;
3032 struct lnet_peer_ni_credit_info *lpni_cri;
3033 struct lnet_ioctl_element_stats *lpni_stats;
3034 struct lnet_ioctl_element_msg_stats *msg_stats;
3035 struct lnet_ioctl_peer_ni_hstats *hstats;
3037 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3042 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3043 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3044 *msg_statistics = NULL, *statistics = NULL,
3046 char err_str[LNET_MAX_STR_LEN];
3047 struct lnet_process_id *list = NULL;
3052 snprintf(err_str, sizeof(err_str),
3053 "\"out of memory\"");
3055 /* create struct cYAML root object */
3056 root = cYAML_create_object(NULL, NULL);
3060 peer_root = cYAML_create_seq(root, "peer");
3061 if (peer_root == NULL)
3065 size = count * sizeof(struct lnet_process_id);
3066 list = malloc(size);
3072 list[0].nid = libcfs_str2nid(knid);
3076 memset(&peer_info, 0, sizeof(peer_info));
3077 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3078 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3079 peer_info.prcfg_size = size;
3080 peer_info.prcfg_bulk = list;
3083 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3085 count = peer_info.prcfg_count;
3089 if (l_errno != E2BIG) {
3092 "\"cannot get peer list: %s\"",
3098 size = peer_info.prcfg_size;
3099 list = malloc(size);
3108 data = malloc(size);
3114 for (i = 0; i < count; i++) {
3116 memset(&peer_info, 0, sizeof(peer_info));
3117 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3118 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3119 peer_info.prcfg_prim_nid = list[i].nid;
3120 peer_info.prcfg_size = size;
3121 peer_info.prcfg_bulk = data;
3124 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3129 if (l_errno != E2BIG) {
3132 "\"cannot get peer information: %s\"",
3138 size = peer_info.prcfg_size;
3139 data = malloc(size);
3147 peer = cYAML_create_seq_item(peer_root);
3151 if (first_seq == NULL)
3154 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3155 if (cYAML_create_string(peer, "primary nid",
3156 libcfs_nid2str(pnid))
3159 if (cYAML_create_string(peer, "Multi-Rail",
3160 peer_info.prcfg_mr ? "True" : "False")
3164 * print out the state of the peer only if details are
3169 cYAML_create_number(peer, "peer state",
3170 peer_info.prcfg_state)
3175 tmp = cYAML_create_seq(peer, "peer ni");
3180 for (j = 0; j < peer_info.prcfg_count; j++) {
3182 lpni_cri = (void*)nidp + sizeof(nidp);
3183 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3184 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3185 hstats = (void *)msg_stats + sizeof(*msg_stats);
3186 lpni_data = (void *)hstats + sizeof(*hstats);
3188 peer_ni = cYAML_create_seq_item(tmp);
3189 if (peer_ni == NULL)
3192 if (cYAML_create_string(peer_ni, "nid",
3193 libcfs_nid2str(*nidp))
3200 if (cYAML_create_string(peer_ni, "state",
3201 lpni_cri->cr_aliveness)
3208 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3209 lpni_cri->cr_ni_peer_tx_credits)
3213 if (cYAML_create_number(peer_ni, "available_tx_credits",
3214 lpni_cri->cr_peer_tx_credits)
3218 if (cYAML_create_number(peer_ni, "min_tx_credits",
3219 lpni_cri->cr_peer_min_tx_credits)
3223 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3224 lpni_cri->cr_peer_tx_qnob)
3228 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3229 lpni_cri->cr_peer_rtr_credits)
3233 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3234 lpni_cri->cr_peer_min_rtr_credits)
3238 if (cYAML_create_number(peer_ni, "refcount",
3239 lpni_cri->cr_refcount) == NULL)
3242 statistics = cYAML_create_object(peer_ni, "statistics");
3243 if (statistics == NULL)
3246 if (cYAML_create_number(statistics, "send_count",
3247 lpni_stats->iel_send_count)
3251 if (cYAML_create_number(statistics, "recv_count",
3252 lpni_stats->iel_recv_count)
3256 if (cYAML_create_number(statistics, "drop_count",
3257 lpni_stats->iel_drop_count)
3264 for (k = 0; k < 3; k++) {
3265 struct lnet_ioctl_comm_count *counts;
3267 msg_statistics = cYAML_create_object(peer_ni,
3268 (char *) gmsg_stat_names[k]);
3269 if (msg_statistics == NULL)
3272 counts = get_counts(msg_stats, k);
3276 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3281 yhstats = cYAML_create_object(peer_ni, "health stats");
3284 if (cYAML_create_number(yhstats, "health value",
3285 hstats->hlpni_health_value)
3288 if (cYAML_create_number(yhstats, "dropped",
3289 hstats->hlpni_remote_dropped)
3292 if (cYAML_create_number(yhstats, "timeout",
3293 hstats->hlpni_remote_timeout)
3296 if (cYAML_create_number(yhstats, "error",
3297 hstats->hlpni_remote_error)
3300 if (cYAML_create_number(yhstats, "network timeout",
3301 hstats->hlpni_network_timeout)
3307 /* print output iff show_rc is not provided */
3308 if (show_rc == NULL)
3309 cYAML_print_tree(root);
3311 snprintf(err_str, sizeof(err_str), "\"success\"");
3312 rc = LUSTRE_CFG_RC_NO_ERR;
3317 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3318 cYAML_free_tree(root);
3319 } else if (show_rc != NULL && *show_rc != NULL) {
3320 struct cYAML *show_node;
3321 /* find the peer node, if one doesn't exist then
3322 * insert one. Otherwise add to the one there
3324 show_node = cYAML_get_object_item(*show_rc,
3326 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3327 cYAML_insert_child(show_node, first_seq);
3330 } else if (show_node == NULL) {
3331 cYAML_insert_sibling((*show_rc)->cy_child,
3335 cYAML_free_tree(root);
3341 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3347 int lustre_lnet_list_peer(int seq_no,
3348 struct cYAML **show_rc, struct cYAML **err_rc)
3350 struct lnet_ioctl_peer_cfg peer_info;
3351 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3356 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3357 char err_str[LNET_MAX_STR_LEN];
3358 struct lnet_process_id *list = NULL;
3360 snprintf(err_str, sizeof(err_str),
3361 "\"out of memory\"");
3363 memset(&peer_info, 0, sizeof(peer_info));
3365 /* create struct cYAML root object */
3366 root = cYAML_create_object(NULL, NULL);
3370 list_root = cYAML_create_seq(root, "peer list");
3371 if (list_root == NULL)
3375 size = count * sizeof(struct lnet_process_id);
3376 list = malloc(size);
3382 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3383 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3384 peer_info.prcfg_size = size;
3385 peer_info.prcfg_bulk = list;
3388 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3389 count = peer_info.prcfg_count;
3393 if (l_errno != E2BIG) {
3396 "\"cannot get peer list: %s\"",
3402 size = peer_info.prcfg_size;
3403 list = malloc(size);
3410 /* count is now the actual number of ids in the list. */
3411 for (i = 0; i < count; i++) {
3412 if (cYAML_create_string(list_root, "nid",
3413 libcfs_nid2str(list[i].nid))
3418 /* print output iff show_rc is not provided */
3419 if (show_rc == NULL)
3420 cYAML_print_tree(root);
3422 snprintf(err_str, sizeof(err_str), "\"success\"");
3423 rc = LUSTRE_CFG_RC_NO_ERR;
3428 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3429 cYAML_free_tree(root);
3430 } else if (show_rc != NULL && *show_rc != NULL) {
3431 struct cYAML *show_node;
3432 /* find the peer node, if one doesn't exist then
3433 * insert one. Otherwise add to the one there
3435 show_node = cYAML_get_object_item(*show_rc,
3437 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3438 cYAML_insert_child(show_node, first_seq);
3441 } else if (show_node == NULL) {
3442 cYAML_insert_sibling((*show_rc)->cy_child,
3446 cYAML_free_tree(root);
3452 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3458 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3461 struct cYAML *show_node;
3463 show_node = cYAML_get_object_item(show_rc, "global");
3464 if (show_node != NULL)
3465 cYAML_insert_sibling(show_node->cy_child,
3468 cYAML_insert_sibling(show_rc->cy_child,
3473 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3474 char *name, __u32 value,
3475 struct cYAML **show_rc,
3476 struct cYAML **err_rc, int err)
3478 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3479 struct cYAML *root = NULL, *global = NULL;
3486 root = cYAML_create_object(NULL, NULL);
3490 global = cYAML_create_object(root, "global");
3494 if (cYAML_create_number(global, name,
3498 if (show_rc == NULL)
3499 cYAML_print_tree(root);
3501 snprintf(err_str, err_len, "\"success\"");
3503 rc = LUSTRE_CFG_RC_NO_ERR;
3506 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3507 cYAML_free_tree(root);
3508 } else if (show_rc != NULL && *show_rc != NULL) {
3509 add_to_global(*show_rc, global, root);
3514 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3519 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3520 struct cYAML **show_rc,
3521 struct cYAML **err_rc)
3523 struct lnet_ioctl_set_value data;
3526 char err_str[LNET_MAX_STR_LEN];
3528 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3530 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3532 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3537 "\"cannot get %s: %s\"",
3538 name, strerror(l_errno));
3541 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3542 data.sv_value, show_rc, err_rc, l_errno);
3545 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3546 struct cYAML **err_rc)
3548 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3549 char val[LNET_MAX_STR_LEN];
3550 int intrv = -1, l_errno = 0;
3551 char err_str[LNET_MAX_STR_LEN];
3553 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3555 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3559 snprintf(err_str, sizeof(err_str),
3560 "\"cannot get recovery interval: %d\"", rc);
3565 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3566 "recovery_interval", intrv, show_rc,
3570 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3571 struct cYAML **err_rc)
3573 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3574 char val[LNET_MAX_STR_LEN];
3575 int sen = -1, l_errno = 0;
3576 char err_str[LNET_MAX_STR_LEN];
3578 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3580 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3584 snprintf(err_str, sizeof(err_str),
3585 "\"cannot get health sensitivity: %d\"", rc);
3590 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3591 "health_sensitivity", sen, show_rc,
3595 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3596 struct cYAML **err_rc)
3598 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3599 char val[LNET_MAX_STR_LEN];
3600 int sen = -1, l_errno = 0;
3601 char err_str[LNET_MAX_STR_LEN];
3603 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3605 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3609 snprintf(err_str, sizeof(err_str),
3610 "\"cannot get router sensitivity percentage: %d\"", rc);
3615 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3616 "router_sensitivity", sen, show_rc,
3620 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3621 struct cYAML **err_rc)
3623 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3624 char val[LNET_MAX_STR_LEN];
3625 int tto = -1, l_errno = 0;
3626 char err_str[LNET_MAX_STR_LEN];
3628 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3630 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3634 snprintf(err_str, sizeof(err_str),
3635 "\"cannot get transaction timeout: %d\"", rc);
3640 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3641 "transaction_timeout", tto, show_rc,
3645 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3646 struct cYAML **err_rc)
3648 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3649 char val[LNET_MAX_STR_LEN];
3650 int retry_count = -1, l_errno = 0;
3651 char err_str[LNET_MAX_STR_LEN];
3653 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3655 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3659 snprintf(err_str, sizeof(err_str),
3660 "\"cannot get retry count: %d\"", rc);
3662 retry_count = atoi(val);
3665 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3666 "retry_count", retry_count, show_rc,
3670 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3671 struct cYAML **show_rc, struct cYAML **err_rc)
3673 struct lnet_ioctl_recovery_list nid_list;
3674 struct cYAML *root = NULL, *nids = NULL;
3676 char err_str[LNET_MAX_STR_LEN];
3678 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3680 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3681 nid_list.rlst_type = type;
3683 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3689 if (nid_list.rlst_num_nids == 0)
3692 root = cYAML_create_object(NULL, NULL);
3696 nids = cYAML_create_object(root, name);
3702 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3703 char nidenum[LNET_MAX_STR_LEN];
3704 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3705 if (!cYAML_create_string(nids, nidenum,
3706 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3710 snprintf(err_str, sizeof(err_str), "success\n");
3715 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3716 cYAML_free_tree(root);
3717 } else if (show_rc != NULL && *show_rc != NULL) {
3718 struct cYAML *show_node;
3719 /* find the net node, if one doesn't exist
3720 * then insert one. Otherwise add to the one there
3722 show_node = cYAML_get_object_item(*show_rc, name);
3723 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3724 cYAML_insert_child(show_node, nids);
3727 } else if (show_node == NULL) {
3728 cYAML_insert_sibling((*show_rc)->cy_child,
3732 cYAML_free_tree(root);
3738 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3743 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3744 struct cYAML **err_rc)
3746 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3747 seq_no, show_rc, err_rc);
3750 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3751 struct cYAML **err_rc)
3753 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3754 seq_no, show_rc, err_rc);
3757 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3758 struct cYAML **err_rc)
3760 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3761 char val[LNET_MAX_STR_LEN];
3762 int max_intf = -1, l_errno = 0;
3763 char err_str[LNET_MAX_STR_LEN];
3765 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3767 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3771 snprintf(err_str, sizeof(err_str),
3772 "\"cannot get max interfaces: %d\"", rc);
3774 max_intf = atoi(val);
3777 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3778 "max_intf", max_intf, show_rc,
3782 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3783 struct cYAML **err_rc)
3785 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3786 char val[LNET_MAX_STR_LEN];
3787 int discovery = -1, l_errno = 0;
3788 char err_str[LNET_MAX_STR_LEN];
3790 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3792 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3796 snprintf(err_str, sizeof(err_str),
3797 "\"cannot get discovery setting: %d\"", rc);
3800 * The kernel stores a discovery disabled value. User space
3801 * shows whether discovery is enabled. So the value must be
3804 discovery = !atoi(val);
3807 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3808 "discovery", discovery, show_rc,
3812 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3813 struct cYAML **err_rc)
3815 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3816 char val[LNET_MAX_STR_LEN];
3817 int drop_asym_route = -1, l_errno = 0;
3818 char err_str[LNET_MAX_STR_LEN];
3820 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3822 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3826 snprintf(err_str, sizeof(err_str),
3827 "\"cannot get drop asym route setting: %d\"", rc);
3829 drop_asym_route = atoi(val);
3832 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3833 "drop_asym_route", drop_asym_route,
3834 show_rc, err_rc, l_errno);
3837 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3838 struct cYAML **err_rc)
3840 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3841 "numa_range", show_rc, err_rc);
3844 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3845 struct cYAML **err_rc)
3847 struct lnet_ioctl_lnet_stats data;
3848 struct lnet_counters *cntrs;
3851 char err_str[LNET_MAX_STR_LEN];
3852 struct cYAML *root = NULL, *stats = NULL;
3854 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3856 LIBCFS_IOC_INIT_V2(data, st_hdr);
3858 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3863 "\"cannot get lnet statistics: %s\"",
3869 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3871 cntrs = &data.st_cntrs;
3873 root = cYAML_create_object(NULL, NULL);
3877 stats = cYAML_create_object(root, "statistics");
3881 if (!cYAML_create_number(stats, "msgs_alloc",
3882 cntrs->lct_common.lcc_msgs_alloc))
3885 if (!cYAML_create_number(stats, "msgs_max",
3886 cntrs->lct_common.lcc_msgs_max))
3889 if (!cYAML_create_number(stats, "rst_alloc",
3890 cntrs->lct_health.lch_rst_alloc))
3893 if (!cYAML_create_number(stats, "errors",
3894 cntrs->lct_common.lcc_errors))
3897 if (!cYAML_create_number(stats, "send_count",
3898 cntrs->lct_common.lcc_send_count))
3901 if (!cYAML_create_number(stats, "resend_count",
3902 cntrs->lct_health.lch_resend_count))
3905 if (!cYAML_create_number(stats, "response_timeout_count",
3906 cntrs->lct_health.lch_response_timeout_count))
3909 if (!cYAML_create_number(stats, "local_interrupt_count",
3910 cntrs->lct_health.lch_local_interrupt_count))
3913 if (!cYAML_create_number(stats, "local_dropped_count",
3914 cntrs->lct_health.lch_local_dropped_count))
3917 if (!cYAML_create_number(stats, "local_aborted_count",
3918 cntrs->lct_health.lch_local_aborted_count))
3921 if (!cYAML_create_number(stats, "local_no_route_count",
3922 cntrs->lct_health.lch_local_no_route_count))
3925 if (!cYAML_create_number(stats, "local_timeout_count",
3926 cntrs->lct_health.lch_local_timeout_count))
3929 if (!cYAML_create_number(stats, "local_error_count",
3930 cntrs->lct_health.lch_local_error_count))
3933 if (!cYAML_create_number(stats, "remote_dropped_count",
3934 cntrs->lct_health.lch_remote_dropped_count))
3937 if (!cYAML_create_number(stats, "remote_error_count",
3938 cntrs->lct_health.lch_remote_error_count))
3941 if (!cYAML_create_number(stats, "remote_timeout_count",
3942 cntrs->lct_health.lch_remote_timeout_count))
3945 if (!cYAML_create_number(stats, "network_timeout_count",
3946 cntrs->lct_health.lch_network_timeout_count))
3949 if (!cYAML_create_number(stats, "recv_count",
3950 cntrs->lct_common.lcc_recv_count))
3953 if (!cYAML_create_number(stats, "route_count",
3954 cntrs->lct_common.lcc_route_count))
3957 if (!cYAML_create_number(stats, "drop_count",
3958 cntrs->lct_common.lcc_drop_count))
3961 if (!cYAML_create_number(stats, "send_length",
3962 cntrs->lct_common.lcc_send_length))
3965 if (!cYAML_create_number(stats, "recv_length",
3966 cntrs->lct_common.lcc_recv_length))
3969 if (!cYAML_create_number(stats, "route_length",
3970 cntrs->lct_common.lcc_route_length))
3973 if (!cYAML_create_number(stats, "drop_length",
3974 cntrs->lct_common.lcc_drop_length))
3978 cYAML_print_tree(root);
3980 snprintf(err_str, sizeof(err_str), "\"success\"");
3981 rc = LUSTRE_CFG_RC_NO_ERR;
3983 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3984 cYAML_free_tree(root);
3985 } else if (show_rc != NULL && *show_rc != NULL) {
3986 cYAML_insert_sibling((*show_rc)->cy_child,
3993 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3998 typedef int (*cmd_handler_t)(struct cYAML *tree,
3999 struct cYAML **show_rc,
4000 struct cYAML **err_rc);
4002 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4003 struct cYAML **err_rc)
4005 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4007 net = cYAML_get_object_item(tree, "net");
4008 gw = cYAML_get_object_item(tree, "gateway");
4009 hop = cYAML_get_object_item(tree, "hop");
4010 prio = cYAML_get_object_item(tree, "priority");
4011 sen = cYAML_get_object_item(tree, "health_sensitivity");
4012 seq_no = cYAML_get_object_item(tree, "seq_no");
4014 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4015 (gw) ? gw->cy_valuestring : NULL,
4016 (hop) ? hop->cy_valueint : -1,
4017 (prio) ? prio->cy_valueint : -1,
4018 (sen) ? sen->cy_valueint : -1,
4019 (seq_no) ? seq_no->cy_valueint : -1,
4023 static void yaml_free_string_array(char **array, int num)
4026 char **sub_array = array;
4028 for (i = 0; i < num; i++) {
4029 if (*sub_array != NULL)
4039 * 0: <intf_name>['['<expr>']']
4040 * 1: <intf_name>['['<expr>']']
4042 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4043 struct lnet_dlc_network_descr *nw_descr)
4045 struct cYAML *child = NULL;
4046 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4047 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4049 if (intf_tree == NULL || nw_descr == NULL)
4050 return LUSTRE_CFG_RC_BAD_PARAM;
4052 /* now grab all the interfaces and their cpts */
4053 child = intf_tree->cy_child;
4054 while (child != NULL) {
4055 if (child->cy_valuestring == NULL) {
4056 child = child->cy_next;
4060 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4063 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4064 child->cy_valuestring,
4065 strlen(child->cy_valuestring));
4066 if (rc != LUSTRE_CFG_RC_NO_ERR)
4070 child = child->cy_next;
4074 return LUSTRE_CFG_RC_MISSING_PARAM;
4079 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4081 list_del(&intf_descr->intf_on_network);
4082 free_intf_descr(intf_descr);
4089 yaml_extract_cmn_tunables(struct cYAML *tree,
4090 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4091 struct cfs_expr_list **global_cpts)
4093 struct cYAML *tun, *item, *smp;
4096 tun = cYAML_get_object_item(tree, "tunables");
4098 item = cYAML_get_object_item(tun, "peer_timeout");
4100 tunables->lct_peer_timeout = item->cy_valueint;
4101 item = cYAML_get_object_item(tun, "peer_credits");
4103 tunables->lct_peer_tx_credits = item->cy_valueint;
4104 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4106 tunables->lct_peer_rtr_credits = item->cy_valueint;
4107 item = cYAML_get_object_item(tun, "credits");
4109 tunables->lct_max_tx_credits = item->cy_valueint;
4110 smp = cYAML_get_object_item(tun, "CPT");
4112 rc = cfs_expr_list_parse(smp->cy_valuestring,
4113 strlen(smp->cy_valuestring),
4114 0, UINT_MAX, global_cpts);
4116 *global_cpts = NULL;
4126 yaml_extract_tunables(struct cYAML *tree,
4127 struct lnet_ioctl_config_lnd_tunables *tunables,
4128 struct cfs_expr_list **global_cpts,
4133 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4139 lustre_yaml_extract_lnd_tunables(tree, net_type,
4147 * - net type: <net>[<NUM>]
4149 * - nid: <ip>@<net>[<NUM>]
4152 * 0: <intf_name>['['<expr>']']
4153 * 1: <intf_name>['['<expr>']']
4155 * peer_timeout: <NUM>
4156 * peer_credits: <NUM>
4157 * peer_buffer_credits: <NUM>
4160 * peercredits_hiw: <NUM>
4161 * map_on_demand: <NUM>
4162 * concurrent_sends: <NUM>
4163 * fmr_pool_size: <NUM>
4164 * fmr_flush_trigger: <NUM>
4167 * At least one interface is required. If no interfaces are provided the
4168 * network interface can not be configured.
4170 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4171 struct cYAML **err_rc)
4173 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4175 int num_entries = 0, rc;
4176 struct lnet_dlc_network_descr nw_descr;
4177 struct cfs_expr_list *global_cpts = NULL;
4178 struct lnet_ioctl_config_lnd_tunables tunables;
4181 memset(&tunables, 0, sizeof(tunables));
4183 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4184 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4186 ip2net = cYAML_get_object_item(tree, "ip2net");
4187 net = cYAML_get_object_item(tree, "net type");
4189 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4191 nw_descr.nw_id = LOLND;
4194 * if neither net nor ip2nets are present, then we can not
4195 * configure the network.
4197 if (!net && !ip2net)
4198 return LUSTRE_CFG_RC_MISSING_PARAM;
4200 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4201 if (local_nis == NULL)
4202 return LUSTRE_CFG_RC_MISSING_PARAM;
4204 if (!cYAML_is_sequence(local_nis))
4205 return LUSTRE_CFG_RC_BAD_PARAM;
4207 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4208 intf = cYAML_get_object_item(item, "interfaces");
4211 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4212 if (num_entries <= 0) {
4213 cYAML_build_error(num_entries, -1, "ni", "add",
4214 "bad interface list",
4216 return LUSTRE_CFG_RC_BAD_PARAM;
4220 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4221 LNET_NETTYP(nw_descr.nw_id));
4222 seq_no = cYAML_get_object_item(tree, "seq_no");
4224 rc = lustre_lnet_config_ni(&nw_descr,
4226 (ip2net) ? ip2net->cy_valuestring : NULL,
4227 (found) ? &tunables: NULL,
4228 (seq_no) ? seq_no->cy_valueint : -1,
4231 if (global_cpts != NULL)
4232 cfs_expr_list_free(global_cpts);
4239 * - net-spec: <tcp|o2ib|gni>[NUM]
4241 * 0: <intf name>['['<expr>']']
4242 * 1: <intf name>['['<expr>']']
4244 * 0: <expr.expr.expr.expr>
4245 * 1: <expr.expr.expr.expr>
4247 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4248 struct cYAML **show_rc,
4249 struct cYAML **err_rc)
4251 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4253 struct lustre_lnet_ip2nets ip2nets;
4254 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4256 int rc = LUSTRE_CFG_RC_NO_ERR;
4257 struct cfs_expr_list *global_cpts = NULL;
4258 struct cfs_expr_list *el, *el_tmp;
4259 struct lnet_ioctl_config_lnd_tunables tunables;
4260 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4263 memset(&tunables, 0, sizeof(tunables));
4265 /* initialize all lists */
4266 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4267 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4268 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4270 net = cYAML_get_object_item(tree, "net-spec");
4272 return LUSTRE_CFG_RC_BAD_PARAM;
4274 if (net != NULL && net->cy_valuestring == NULL)
4275 return LUSTRE_CFG_RC_BAD_PARAM;
4277 /* assign the network id */
4278 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4279 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4280 return LUSTRE_CFG_RC_BAD_PARAM;
4282 seq_no = cYAML_get_object_item(tree, "seq_no");
4284 intf = cYAML_get_object_item(tree, "interfaces");
4286 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4288 return LUSTRE_CFG_RC_BAD_PARAM;
4291 ip_range = cYAML_get_object_item(tree, "ip-range");
4292 if (ip_range != NULL) {
4293 item = ip_range->cy_child;
4294 while (item != NULL) {
4295 if (item->cy_valuestring == NULL) {
4296 item = item->cy_next;
4300 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4301 item->cy_valuestring);
4303 if (rc != LUSTRE_CFG_RC_NO_ERR)
4306 item = item->cy_next;
4310 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4311 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4313 rc = lustre_lnet_config_ip2nets(&ip2nets,
4314 (found) ? &tunables : NULL,
4316 (seq_no) ? seq_no->cy_valueint : -1,
4320 * don't stop because there was no match. Continue processing the
4321 * rest of the rules. If non-match then nothing is configured
4323 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4324 rc = LUSTRE_CFG_RC_NO_ERR;
4326 list_for_each_entry_safe(intf_descr, intf_tmp,
4327 &ip2nets.ip2nets_net.nw_intflist,
4329 list_del(&intf_descr->intf_on_network);
4330 free_intf_descr(intf_descr);
4333 list_for_each_entry_safe(ip_range_descr, tmp,
4334 &ip2nets.ip2nets_ip_ranges,
4336 list_del(&ip_range_descr->ipr_entry);
4337 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4339 list_del(&el->el_link);
4340 cfs_expr_list_free(el);
4342 free(ip_range_descr);
4348 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4349 struct cYAML **err_rc)
4351 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4353 int num_entries, rc;
4354 struct lnet_dlc_network_descr nw_descr;
4356 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4357 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4359 net = cYAML_get_object_item(tree, "net type");
4361 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4363 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4364 if (local_nis == NULL)
4365 return LUSTRE_CFG_RC_MISSING_PARAM;
4367 if (!cYAML_is_sequence(local_nis))
4368 return LUSTRE_CFG_RC_BAD_PARAM;
4370 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4371 intf = cYAML_get_object_item(item, "interfaces");
4374 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4375 if (num_entries <= 0) {
4376 cYAML_build_error(num_entries, -1, "ni", "add",
4377 "bad interface list",
4379 return LUSTRE_CFG_RC_BAD_PARAM;
4383 seq_no = cYAML_get_object_item(tree, "seq_no");
4385 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4386 (seq_no) ? seq_no->cy_valueint : -1,
4392 static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
4393 char *prim_nid, bool del)
4395 struct cYAML *child = NULL, *entry = NULL;
4397 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4399 if (cYAML_is_sequence(nids_entry)) {
4400 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4401 entry = cYAML_get_object_item(child, "nid");
4402 /* don't count an empty entry */
4403 if (!entry || !entry->cy_valuestring)
4407 (strcmp(entry->cy_valuestring, prim_nid)
4410 * primary nid is present in the list of
4411 * nids so that means we want to delete
4412 * the entire peer, so no need to go
4413 * further. Just delete the entire peer.
4423 return LUSTRE_CFG_RC_MISSING_PARAM;
4425 nids = calloc(sizeof(*nids), num);
4427 return LUSTRE_CFG_RC_OUT_OF_MEM;
4429 /* now grab all the nids */
4432 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4433 entry = cYAML_get_object_item(child, "nid");
4434 if (!entry || !entry->cy_valuestring)
4437 nids[num] = strdup(entry->cy_valuestring);
4439 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4451 yaml_free_string_array(nids, num);
4456 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4457 struct cYAML **err_rc)
4461 struct cYAML *seq_no, *prim_nid, *mr, *ip2nets, *peer_nis;
4462 char err_str[LNET_MAX_STR_LEN];
4465 seq_no = cYAML_get_object_item(tree, "seq_no");
4466 prim_nid = cYAML_get_object_item(tree, "primary nid");
4467 mr = cYAML_get_object_item(tree, "Multi-Rail");
4468 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4469 peer_nis = cYAML_get_object_item(tree, "peer ni");
4471 if (ip2nets && (prim_nid || peer_nis)) {
4472 rc = LUSTRE_CFG_RC_BAD_PARAM;
4473 snprintf(err_str, sizeof(err_str),
4474 "ip2nets can not be specified along side prim_nid"
4475 " or peer ni fields");
4476 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4477 ADD_CMD, "peer", err_str, err_rc);
4484 if (!mr->cy_valuestring || !strcmp(mr->cy_valuestring, "True"))
4486 else if (!strcmp(mr->cy_valuestring, "False"))
4489 rc = LUSTRE_CFG_RC_BAD_PARAM;
4490 snprintf(err_str, sizeof(err_str), "Bad MR value");
4491 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4492 ADD_CMD, "peer", err_str, err_rc);
4497 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis, &nids,
4498 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4502 snprintf(err_str, sizeof(err_str),
4503 "error copying nids from YAML block");
4504 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4505 ADD_CMD, "peer", err_str, err_rc);
4509 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4510 nids, num, mr_value,
4511 (ip2nets) ? true : false,
4512 (seq_no) ? seq_no->cy_valueint : -1,
4515 yaml_free_string_array(nids, num);
4519 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4520 struct cYAML **err_rc)
4524 struct cYAML *seq_no, *prim_nid, *ip2nets, *peer_nis;
4525 char err_str[LNET_MAX_STR_LEN];
4527 seq_no = cYAML_get_object_item(tree, "seq_no");
4528 prim_nid = cYAML_get_object_item(tree, "primary nid");
4529 ip2nets = cYAML_get_object_item(tree, "ip2nets");
4530 peer_nis = cYAML_get_object_item(tree, "peer ni");
4532 if (ip2nets && (prim_nid || peer_nis)) {
4533 rc = LUSTRE_CFG_RC_BAD_PARAM;
4534 snprintf(err_str, sizeof(err_str),
4535 "ip2nets can not be specified along side prim_nid"
4536 " or peer ni fields");
4537 cYAML_build_error(rc, (seq_no) ? seq_no->cy_valueint : -1,
4538 DEL_CMD, "peer", err_str, err_rc);
4542 num = yaml_copy_peer_nids((ip2nets) ? ip2nets : peer_nis , &nids,
4543 (prim_nid) ? prim_nid->cy_valuestring : NULL,
4546 snprintf(err_str, sizeof(err_str),
4547 "error copying nids from YAML block");
4548 cYAML_build_error(num, (seq_no) ? seq_no->cy_valueint : -1,
4549 ADD_CMD, "peer", err_str, err_rc);
4553 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
4554 nids, num, (ip2nets) ? true : false,
4555 (seq_no) ? seq_no->cy_valueint : -1,
4558 yaml_free_string_array(nids, num);
4562 static int handle_yaml_config_buffers(struct cYAML *tree,
4563 struct cYAML **show_rc,
4564 struct cYAML **err_rc)
4567 struct cYAML *tiny, *small, *large, *seq_no;
4569 tiny = cYAML_get_object_item(tree, "tiny");
4570 small = cYAML_get_object_item(tree, "small");
4571 large = cYAML_get_object_item(tree, "large");
4572 seq_no = cYAML_get_object_item(tree, "seq_no");
4574 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4575 (small) ? small->cy_valueint : -1,
4576 (large) ? large->cy_valueint : -1,
4577 (seq_no) ? seq_no->cy_valueint : -1,
4583 static int handle_yaml_config_routing(struct cYAML *tree,
4584 struct cYAML **show_rc,
4585 struct cYAML **err_rc)
4587 int rc = LUSTRE_CFG_RC_NO_ERR;
4588 struct cYAML *seq_no, *enable;
4590 seq_no = cYAML_get_object_item(tree, "seq_no");
4591 enable = cYAML_get_object_item(tree, "enable");
4594 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4596 seq_no->cy_valueint : -1,
4603 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4604 struct cYAML **err_rc)
4608 struct cYAML *seq_no;
4610 net = cYAML_get_object_item(tree, "net");
4611 gw = cYAML_get_object_item(tree, "gateway");
4612 seq_no = cYAML_get_object_item(tree, "seq_no");
4614 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4615 (gw) ? gw->cy_valuestring : NULL,
4616 (seq_no) ? seq_no->cy_valueint : -1,
4620 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4621 struct cYAML **err_rc)
4623 struct cYAML *seq_no;
4625 seq_no = cYAML_get_object_item(tree, "seq_no");
4627 return lustre_lnet_enable_routing(0, (seq_no) ?
4628 seq_no->cy_valueint : -1,
4632 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4633 struct cYAML **err_rc)
4639 struct cYAML *detail;
4640 struct cYAML *seq_no;
4642 net = cYAML_get_object_item(tree, "net");
4643 gw = cYAML_get_object_item(tree, "gateway");
4644 hop = cYAML_get_object_item(tree, "hop");
4645 prio = cYAML_get_object_item(tree, "priority");
4646 detail = cYAML_get_object_item(tree, "detail");
4647 seq_no = cYAML_get_object_item(tree, "seq_no");
4649 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4650 (gw) ? gw->cy_valuestring : NULL,
4651 (hop) ? hop->cy_valueint : -1,
4652 (prio) ? prio->cy_valueint : -1,
4653 (detail) ? detail->cy_valueint : 0,
4654 (seq_no) ? seq_no->cy_valueint : -1,
4655 show_rc, err_rc, false);
4658 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4659 struct cYAML **err_rc)
4661 struct cYAML *net, *detail, *seq_no;
4663 net = cYAML_get_object_item(tree, "net");
4664 detail = cYAML_get_object_item(tree, "detail");
4665 seq_no = cYAML_get_object_item(tree, "seq_no");
4667 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4668 (detail) ? detail->cy_valueint : 0,
4669 (seq_no) ? seq_no->cy_valueint : -1,
4670 show_rc, err_rc, false);
4673 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4674 struct cYAML **err_rc)
4676 struct cYAML *seq_no;
4678 seq_no = cYAML_get_object_item(tree, "seq_no");
4680 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4681 show_rc, err_rc, false);
4684 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4685 struct cYAML **err_rc)
4687 struct cYAML *seq_no, *nid, *detail;
4689 seq_no = cYAML_get_object_item(tree, "seq_no");
4690 detail = cYAML_get_object_item(tree, "detail");
4691 nid = cYAML_get_object_item(tree, "nid");
4693 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4694 (detail) ? detail->cy_valueint : 0,
4695 (seq_no) ? seq_no->cy_valueint : -1,
4696 show_rc, err_rc, false);
4699 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4700 struct cYAML **err_rc)
4702 struct cYAML *seq_no;
4704 seq_no = cYAML_get_object_item(tree, "seq_no");
4706 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4710 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4711 struct cYAML **err_rc)
4713 struct cYAML *seq_no, *range;
4715 seq_no = cYAML_get_object_item(tree, "seq_no");
4716 range = cYAML_get_object_item(tree, "range");
4718 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4719 seq_no ? seq_no->cy_valueint : -1,
4723 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4724 struct cYAML **err_rc)
4726 struct cYAML *seq_no;
4728 seq_no = cYAML_get_object_item(tree, "seq_no");
4730 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4734 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4735 struct cYAML **err_rc)
4737 struct cYAML *seq_no;
4739 seq_no = cYAML_get_object_item(tree, "seq_no");
4741 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4745 static int handle_yaml_config_global_settings(struct cYAML *tree,
4746 struct cYAML **show_rc,
4747 struct cYAML **err_rc)
4749 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4750 *sen, *recov, *rsen, *drop_asym_route;
4753 seq_no = cYAML_get_object_item(tree, "seq_no");
4754 max_intf = cYAML_get_object_item(tree, "max_intf");
4756 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4757 seq_no ? seq_no->cy_valueint
4761 numa = cYAML_get_object_item(tree, "numa_range");
4763 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4764 seq_no ? seq_no->cy_valueint
4768 discovery = cYAML_get_object_item(tree, "discovery");
4770 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4771 seq_no ? seq_no->cy_valueint
4775 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4776 if (drop_asym_route)
4777 rc = lustre_lnet_config_drop_asym_route(
4778 drop_asym_route->cy_valueint,
4779 seq_no ? seq_no->cy_valueint : -1,
4782 retry = cYAML_get_object_item(tree, "retry_count");
4784 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4785 seq_no ? seq_no->cy_valueint
4789 tto = cYAML_get_object_item(tree, "transaction_timeout");
4791 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4792 seq_no ? seq_no->cy_valueint
4796 sen = cYAML_get_object_item(tree, "health_sensitivity");
4798 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4799 seq_no ? seq_no->cy_valueint
4803 recov = cYAML_get_object_item(tree, "recovery_interval");
4805 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4806 seq_no ? seq_no->cy_valueint
4810 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4812 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4813 seq_no ? seq_no->cy_valueint
4820 static int handle_yaml_del_global_settings(struct cYAML *tree,
4821 struct cYAML **show_rc,
4822 struct cYAML **err_rc)
4824 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4827 seq_no = cYAML_get_object_item(tree, "seq_no");
4828 max_intf = cYAML_get_object_item(tree, "max_intf");
4830 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4831 seq_no ? seq_no->cy_valueint
4835 numa = cYAML_get_object_item(tree, "numa_range");
4837 rc = lustre_lnet_config_numa_range(0,
4838 seq_no ? seq_no->cy_valueint
4842 /* peer discovery is enabled by default */
4843 discovery = cYAML_get_object_item(tree, "discovery");
4845 rc = lustre_lnet_config_discovery(1,
4846 seq_no ? seq_no->cy_valueint
4850 /* asymmetrical route messages are accepted by default */
4851 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4852 if (drop_asym_route)
4853 rc = lustre_lnet_config_drop_asym_route(
4854 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4859 static int handle_yaml_show_global_settings(struct cYAML *tree,
4860 struct cYAML **show_rc,
4861 struct cYAML **err_rc)
4863 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4864 *sen, *recov, *rsen, *drop_asym_route;
4867 seq_no = cYAML_get_object_item(tree, "seq_no");
4868 max_intf = cYAML_get_object_item(tree, "max_intf");
4870 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4874 numa = cYAML_get_object_item(tree, "numa_range");
4876 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4880 discovery = cYAML_get_object_item(tree, "discovery");
4882 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4886 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4887 if (drop_asym_route)
4888 rc = lustre_lnet_show_drop_asym_route(
4889 seq_no ? seq_no->cy_valueint : -1,
4892 retry = cYAML_get_object_item(tree, "retry_count");
4894 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4898 tto = cYAML_get_object_item(tree, "transaction_timeout");
4900 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4904 sen = cYAML_get_object_item(tree, "health_sensitivity");
4906 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4910 recov = cYAML_get_object_item(tree, "recovery_interval");
4912 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4916 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4918 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4925 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4926 struct cYAML **err_rc)
4928 struct cYAML *seq_no, *nid, *timeout;
4930 seq_no = cYAML_get_object_item(tree, "seq_no");
4931 nid = cYAML_get_object_item(tree, "primary nid");
4932 timeout = cYAML_get_object_item(tree, "timeout");
4934 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4935 (timeout) ? timeout->cy_valueint : 1000,
4936 (seq_no) ? seq_no->cy_valueint : -1,
4940 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4941 struct cYAML **err_rc)
4943 struct cYAML *seq_no, *nid, *force;
4945 seq_no = cYAML_get_object_item(tree, "seq_no");
4946 nid = cYAML_get_object_item(tree, "primary nid");
4947 force = cYAML_get_object_item(tree, "force");
4949 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4950 (force) ? force->cy_valueint : 0,
4951 (seq_no) ? seq_no->cy_valueint : -1,
4955 static int handle_yaml_no_op()
4957 return LUSTRE_CFG_RC_NO_ERR;
4960 struct lookup_cmd_hdlr_tbl {
4965 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4966 { .name = "route", .cb = handle_yaml_config_route },
4967 { .name = "net", .cb = handle_yaml_config_ni },
4968 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4969 { .name = "peer", .cb = handle_yaml_config_peer },
4970 { .name = "routing", .cb = handle_yaml_config_routing },
4971 { .name = "buffers", .cb = handle_yaml_config_buffers },
4972 { .name = "statistics", .cb = handle_yaml_no_op },
4973 { .name = "global", .cb = handle_yaml_config_global_settings},
4974 { .name = "numa", .cb = handle_yaml_config_numa },
4975 { .name = "ping", .cb = handle_yaml_no_op },
4976 { .name = "discover", .cb = handle_yaml_no_op },
4979 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4980 { .name = "route", .cb = handle_yaml_del_route },
4981 { .name = "net", .cb = handle_yaml_del_ni },
4982 { .name = "ip2nets", .cb = handle_yaml_no_op },
4983 { .name = "peer", .cb = handle_yaml_del_peer },
4984 { .name = "routing", .cb = handle_yaml_del_routing },
4985 { .name = "buffers", .cb = handle_yaml_no_op },
4986 { .name = "statistics", .cb = handle_yaml_no_op },
4987 { .name = "global", .cb = handle_yaml_del_global_settings},
4988 { .name = "numa", .cb = handle_yaml_del_numa },
4989 { .name = "ping", .cb = handle_yaml_no_op },
4990 { .name = "discover", .cb = handle_yaml_no_op },
4993 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4994 { .name = "route", .cb = handle_yaml_show_route },
4995 { .name = "net", .cb = handle_yaml_show_net },
4996 { .name = "peer", .cb = handle_yaml_show_peers },
4997 { .name = "ip2nets", .cb = handle_yaml_no_op },
4998 { .name = "routing", .cb = handle_yaml_show_routing },
4999 { .name = "buffers", .cb = handle_yaml_show_routing },
5000 { .name = "statistics", .cb = handle_yaml_show_stats },
5001 { .name = "global", .cb = handle_yaml_show_global_settings},
5002 { .name = "numa", .cb = handle_yaml_show_numa },
5003 { .name = "ping", .cb = handle_yaml_no_op },
5004 { .name = "discover", .cb = handle_yaml_no_op },
5007 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5008 { .name = "route", .cb = handle_yaml_no_op },
5009 { .name = "net", .cb = handle_yaml_no_op },
5010 { .name = "peer", .cb = handle_yaml_no_op },
5011 { .name = "ip2nets", .cb = handle_yaml_no_op },
5012 { .name = "routing", .cb = handle_yaml_no_op },
5013 { .name = "buffers", .cb = handle_yaml_no_op },
5014 { .name = "statistics", .cb = handle_yaml_no_op },
5015 { .name = "global", .cb = handle_yaml_no_op },
5016 { .name = "numa", .cb = handle_yaml_no_op },
5017 { .name = "ping", .cb = handle_yaml_ping },
5018 { .name = "discover", .cb = handle_yaml_discover },
5021 static cmd_handler_t lookup_fn(char *key,
5022 struct lookup_cmd_hdlr_tbl *tbl)
5028 for (i = 0; tbl[i].name != NULL; i++) {
5029 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5036 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5037 struct cYAML **show_rc, struct cYAML **err_rc)
5039 struct cYAML *tree, *item = NULL, *head, *child;
5041 char err_str[LNET_MAX_STR_LEN];
5042 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5044 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5046 return LUSTRE_CFG_RC_BAD_PARAM;
5048 child = tree->cy_child;
5049 while (child != NULL) {
5050 cb = lookup_fn(child->cy_string, table);
5052 snprintf(err_str, sizeof(err_str),
5053 "\"call back for '%s' not found\"",
5055 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5056 "yaml", "helper", err_str, err_rc);
5060 if (cYAML_is_sequence(child)) {
5061 while ((head = cYAML_get_next_seq_item(child, &item))
5063 rc = cb(head, show_rc, err_rc);
5064 if (rc != LUSTRE_CFG_RC_NO_ERR)
5068 rc = cb(child, show_rc, err_rc);
5069 if (rc != LUSTRE_CFG_RC_NO_ERR)
5073 child = child->cy_next;
5077 cYAML_free_tree(tree);
5082 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5084 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5088 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5090 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5094 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5096 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5100 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5102 return lustre_yaml_cb_helper(f, lookup_exec_tbl,