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 <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #ifndef HAVE_USRSPC_RDMA_PS_TCP
59 #define RDMA_PS_TCP 0x0106
62 #define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
63 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
67 * lustre_lnet_ip_range_descr
68 * Describes an IP range.
69 * Each octect is an expression
71 struct lustre_lnet_ip_range_descr {
72 struct list_head ipr_entry;
73 struct list_head ipr_expr;
78 * Describes an ip2nets rule. This can be on a list of rules.
80 struct lustre_lnet_ip2nets {
81 struct lnet_dlc_network_descr ip2nets_net;
82 struct list_head ip2nets_ip_ranges;
85 int open_sysfs_file(const char *path, const char *attr, const int mode)
88 char filename[LNET_MAX_STR_LEN];
90 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
93 snprintf(filename, sizeof(filename), "%s%s",
96 fd = open(filename, mode);
101 static int read_sysfs_file(const char *path, const char *attr,
102 void *val, const size_t size, const int nelem)
105 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
107 fd = open_sysfs_file(path, attr, O_RDONLY);
109 return LUSTRE_CFG_RC_NO_MATCH;
111 if (read(fd, val, size * nelem) == -1)
114 rc = LUSTRE_CFG_RC_NO_ERR;
121 static int write_sysfs_file(const char *path, const char *attr,
122 void *val, const size_t size, const int nelem)
125 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
127 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
129 return LUSTRE_CFG_RC_NO_MATCH;
131 if (write(fd, val, size * nelem) == -1)
134 rc = LUSTRE_CFG_RC_NO_ERR;
143 * frees the memory allocated for an intf descriptor.
145 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
150 if (intf_descr->cpt_expr != NULL)
151 cfs_expr_list_free(intf_descr->cpt_expr);
156 * lustre_lnet_add_ip_range
158 * given a string of the format:
159 * <expr.expr.expr.expr> parse each expr into
160 * a lustre_lnet_ip_range_descr structure and insert on the list.
162 * This function is called from
163 * YAML on each ip-range.
164 * As a result of lnetctl command
165 * When building a NID or P2P selection rules
167 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
169 struct lustre_lnet_ip_range_descr *ip_range;
172 ip_range = calloc(1, sizeof(*ip_range));
173 if (ip_range == NULL)
174 return LUSTRE_CFG_RC_OUT_OF_MEM;
176 INIT_LIST_HEAD(&ip_range->ipr_entry);
177 INIT_LIST_HEAD(&ip_range->ipr_expr);
179 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
180 &ip_range->ipr_expr);
182 return LUSTRE_CFG_RC_BAD_PARAM;
184 list_add_tail(&ip_range->ipr_entry, list);
186 return LUSTRE_CFG_RC_NO_ERR;
189 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
191 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
193 struct lnet_dlc_intf_descr *intf_descr = NULL;
195 char intf_string[LNET_MAX_STR_LEN];
197 if (len >= LNET_MAX_STR_LEN)
198 return LUSTRE_CFG_RC_BAD_PARAM;
200 strncpy(intf_string, intf, len);
201 intf_string[len] = '\0';
203 intf_descr = calloc(1, sizeof(*intf_descr));
204 if (intf_descr == NULL)
205 return LUSTRE_CFG_RC_OUT_OF_MEM;
207 INIT_LIST_HEAD(&intf_descr->intf_on_network);
209 intf_name = intf_string;
210 open_sq_bracket = strchr(intf_string, '[');
211 if (open_sq_bracket != NULL) {
212 close_sq_bracket = strchr(intf_string, ']');
213 if (close_sq_bracket == NULL) {
215 return LUSTRE_CFG_RC_BAD_PARAM;
217 rc = cfs_expr_list_parse(open_sq_bracket,
218 strlen(open_sq_bracket), 0, UINT_MAX,
219 &intf_descr->cpt_expr);
222 return LUSTRE_CFG_RC_BAD_PARAM;
224 strncpy(intf_descr->intf_name, intf_name,
225 open_sq_bracket - intf_name);
226 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
228 strcpy(intf_descr->intf_name, intf_name);
229 intf_descr->cpt_expr = NULL;
232 list_add_tail(&intf_descr->intf_on_network, list);
234 return LUSTRE_CFG_RC_NO_ERR;
237 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
239 if (nw_descr != NULL) {
241 INIT_LIST_HEAD(&nw_descr->network_on_rule);
242 INIT_LIST_HEAD(&nw_descr->nw_intflist);
246 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
247 int max_nids, char *err_str)
249 int rc, num_nids = 0;
250 struct list_head nidlist;
253 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
254 return LUSTRE_CFG_RC_BAD_PARAM;
257 if (strchr(nidstr, '*')) {
258 snprintf(err_str, LNET_MAX_STR_LEN,
259 "asterisk not allowed in nidstring \"%s\"", nidstr);
260 return LUSTRE_CFG_RC_BAD_PARAM;
263 INIT_LIST_HEAD(&nidlist);
264 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
266 snprintf(err_str, LNET_MAX_STR_LEN,
267 "Unable to parse nidlist from: %s\n", nidstr);
268 return LUSTRE_CFG_RC_BAD_PARAM;
271 if (list_empty(&nidlist)) {
272 snprintf(err_str, LNET_MAX_STR_LEN,
273 "\"%s\" does not specify any valid nid lists", nidstr);
274 return LUSTRE_CFG_RC_BAD_PARAM;
277 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
278 cfs_free_nidlist(&nidlist);
280 if (num_nids == -1) {
281 snprintf(err_str, LNET_MAX_STR_LEN,
282 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
284 return LUSTRE_CFG_RC_BAD_PARAM;
288 snprintf(err_str, LNET_MAX_STR_LEN,
289 "Failed to expand nidstr: %s", strerror(num_nids));
290 return LUSTRE_CFG_RC_OUT_OF_MEM;
294 snprintf(err_str, LNET_MAX_STR_LEN,
295 "\"%s\" did not expand to any nids", nidstr);
296 return LUSTRE_CFG_RC_BAD_PARAM;
304 * <intf>[<expr>], <intf>[<expr>],..
306 int lustre_lnet_parse_interfaces(char *intf_str,
307 struct lnet_dlc_network_descr *nw_descr)
312 char *cur = intf_str, *next = NULL;
313 char *end = intf_str + strlen(intf_str);
315 struct lnet_dlc_intf_descr *intf_descr, *tmp;
317 if (nw_descr == NULL)
318 return LUSTRE_CFG_RC_BAD_PARAM;
321 open_square = strchr(cur, '[');
322 if (open_square != NULL) {
323 close_square = strchr(cur, ']');
324 if (close_square == NULL) {
325 rc = LUSTRE_CFG_RC_BAD_PARAM;
329 comma = strchr(cur, ',');
330 if (comma != NULL && comma > close_square) {
332 len = next - close_square;
338 comma = strchr(cur, ',');
348 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
349 if (rc != LUSTRE_CFG_RC_NO_ERR)
355 return LUSTRE_CFG_RC_NO_ERR;
358 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
360 list_del(&intf_descr->intf_on_network);
361 free_intf_descr(intf_descr);
367 int lustre_lnet_config_lib_init(void)
369 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
372 void lustre_lnet_config_lib_uninit(void)
374 unregister_ioc_dev(LNET_DEV_ID);
377 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
378 int seq_no, struct cYAML **err_rc)
380 struct libcfs_ioctl_data data;
383 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
385 LIBCFS_IOC_INIT(data);
387 /* Reverse logic is used here in order not to change
388 * the lctl utility */
389 data.ioc_flags = load_ni_from_mod ? 0 : 1;
391 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
393 rc = l_ioctl(LNET_DEV_ID, opc, &data);
397 "\"LNet %s error: %s\"", (up) ? "configure" :
398 "unconfigure", strerror(errno));
402 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
403 "lnet", err_str, err_rc);
408 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
409 char *err_str, char *cmd_str)
413 rc = l_ioctl(LNET_DEV_ID, cmd, data);
416 snprintf(err_str, LNET_MAX_STR_LEN,
417 "\"%s peer ni operation failed: %s\"",
418 cmd_str, strerror(errno));
424 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
425 int param, int ioc_call, int seq_no,
426 struct cYAML **show_rc, struct cYAML **err_rc)
429 struct lnet_ioctl_ping_data ping;
430 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
431 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
432 struct lnet_process_id id;
433 char err_str[LNET_MAX_STR_LEN] = {0};
434 char *sep, *token, *end;
437 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
442 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
444 data = calloc(1, len);
448 /* create struct cYAML root object */
449 root = cYAML_create_object(NULL, NULL);
453 ping_node = cYAML_create_seq(root, oper);
454 if (ping_node == NULL)
458 src = libcfs_str2nid(src_nidstr);
459 if (src == LNET_NID_ANY) {
460 snprintf(err_str, sizeof(err_str),
461 "\"cannot parse source NID '%s'\"",
463 rc = LUSTRE_CFG_RC_BAD_PARAM;
464 cYAML_build_error(rc, seq_no, MANAGE_CMD,
465 oper, err_str, err_rc);
472 /* tokenise each nid in string ping_nids */
473 token = strtok(ping_nids, ",");
476 item = cYAML_create_seq_item(ping_node);
480 if (first_seq == NULL)
483 /* check if '-' is a part of NID, token */
484 sep = strchr(token, '-');
486 id.pid = LNET_PID_ANY;
487 /* if no net is specified, libcfs_str2nid() will assume tcp */
488 id.nid = libcfs_str2nid(token);
489 if (id.nid == LNET_NID_ANY) {
490 snprintf(err_str, sizeof(err_str),
491 "\"cannot parse NID '%s'\"",
493 rc = LUSTRE_CFG_RC_BAD_PARAM;
494 cYAML_build_error(rc, seq_no, MANAGE_CMD,
495 oper, err_str, err_rc);
499 if (token[0] == 'u' || token[0] == 'U')
500 id.pid = (strtoul(&token[1], &end, 0) |
501 (LNET_PID_USERFLAG));
503 id.pid = strtoul(token, &end, 0);
505 /* assuming '-' is part of hostname */
507 id.pid = LNET_PID_ANY;
508 id.nid = libcfs_str2nid(token);
509 if (id.nid == LNET_NID_ANY) {
510 snprintf(err_str, sizeof(err_str),
511 "\"cannot parse NID '%s'\"",
513 rc = LUSTRE_CFG_RC_BAD_PARAM;
514 cYAML_build_error(rc, seq_no, MANAGE_CMD,
520 id.nid = libcfs_str2nid(sep + 1);
521 if (id.nid == LNET_NID_ANY) {
522 snprintf(err_str, sizeof(err_str),
523 "\"cannot parse NID '%s'\"",
525 rc = LUSTRE_CFG_RC_BAD_PARAM;
526 cYAML_build_error(rc, seq_no, MANAGE_CMD,
533 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
534 ping.ping_hdr.ioc_len = sizeof(ping);
537 ping.op_param = param;
538 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
539 ping.ping_buf = data;
541 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
544 sizeof(err_str), "failed to %s %s: %s\n", oper,
545 id.pid == LNET_PID_ANY ?
546 libcfs_nid2str(id.nid) :
547 libcfs_id2str(id), strerror(errno));
548 rc = LUSTRE_CFG_RC_BAD_PARAM;
549 cYAML_build_error(rc, seq_no, MANAGE_CMD,
550 oper, err_str, err_rc);
554 if (cYAML_create_string(item, "primary nid",
555 libcfs_nid2str(ping.ping_id.nid)) == NULL)
558 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
559 "True" : "False") == NULL)
562 tmp = cYAML_create_seq(item, "peer ni");
566 for (i = 0; i < ping.ping_count; i++) {
567 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
569 peer_ni = cYAML_create_seq_item(tmp);
572 memset(buf, 0, sizeof buf);
573 snprintf(buf, sizeof buf, "nid");
574 if (cYAML_create_string(peer_ni, buf,
575 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
581 } while ((token = strtok(NULL, ",")) != NULL);
584 rc = LUSTRE_CFG_RC_NO_ERR;
589 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
590 cYAML_free_tree(root);
591 } else if (show_rc != NULL && *show_rc != NULL) {
592 struct cYAML *show_node;
593 show_node = cYAML_get_object_item(*show_rc, oper);
594 if (show_node != NULL && cYAML_is_sequence(show_node)) {
595 cYAML_insert_child(show_node, first_seq);
598 } else if (show_node == NULL) {
599 cYAML_insert_sibling((*show_rc)->cy_child,
603 cYAML_free_tree(root);
612 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
613 int seq_no, struct cYAML **show_rc,
614 struct cYAML **err_rc)
618 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
619 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
623 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
624 struct cYAML **show_rc, struct cYAML **err_rc)
628 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
629 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
633 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
634 bool is_mr, __u32 cmd,
635 char *cmd_type, char *err_str)
637 struct lnet_ioctl_peer_cfg data;
640 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
641 /* When adding a peer we first need to create the peer using the
642 * specified (or implied) primary nid. Then we can add
643 * additional nids to this peer using the primary nid as a key
645 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
646 data.prcfg_mr = is_mr;
647 data.prcfg_prim_nid = nidlist[0];
648 data.prcfg_cfg_nid = LNET_NID_ANY;
650 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
656 /* Add or delete any specified NIs associated with the specified
657 * (or implied) primary nid
659 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
660 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
661 data.prcfg_mr = is_mr;
662 data.prcfg_prim_nid = nidlist[0];
663 data.prcfg_cfg_nid = nidlist[nid_idx];
665 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
671 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
672 /* In the delete case we may have been given just the
673 * primary nid of the peer. This tells us to delete the peer
674 * completely (rather than just delete some of its NIs)
676 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
677 data.prcfg_prim_nid = nidlist[0];
678 data.prcfg_cfg_nid = LNET_NID_ANY;
680 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
687 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
688 int cmd, int num_nids, bool is_mr, int seq_no,
689 struct cYAML **err_rc)
691 int rc = LUSTRE_CFG_RC_NO_ERR;
692 char err_str[LNET_MAX_STR_LEN];
693 lnet_nid_t *lnet_nidlist2 = NULL;
694 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
695 IOC_LIBCFS_DEL_PEER_NI;
696 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
699 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
700 if (!lnet_nidlist2) {
701 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
702 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
705 lnet_nidlist2[0] = pnid;
706 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
709 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
710 num_nids, is_mr, ioc_cmd,
716 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
721 replace_sep(char *str, char sep, char newsep)
727 for (i = 0; i < strlen(str); i++) {
728 /* don't replace ',' within [] */
731 else if (str[i] == ']')
733 else if (str[i] == sep && bracket == 0)
738 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
739 int cmd, int seq_no, struct cYAML **err_rc)
742 char err_str[LNET_MAX_STR_LEN] = "Error";
743 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
744 lnet_nid_t pnid = LNET_NID_ANY;
747 rc = LUSTRE_CFG_RC_BAD_PARAM;
748 snprintf(err_str, LNET_MAX_STR_LEN,
749 "--prim_nid must be specified");
753 pnid = libcfs_str2nid(prim_nid);
754 if (pnid == LNET_NID_ANY) {
755 rc = LUSTRE_CFG_RC_BAD_PARAM;
756 snprintf(err_str, LNET_MAX_STR_LEN,
757 "badly formatted primary NID: %s", prim_nid);
764 * if there is no primary nid we need to make the first nid in the
765 * nids list the primary nid
767 replace_sep(nids, ',', ' ');
768 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
769 LNET_MAX_NIDS_PER_PEER, err_str);
776 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
777 cmd, num_nids, is_mr,
781 if (rc != LUSTRE_CFG_RC_NO_ERR)
782 cYAML_build_error(rc, -1, "peer",
783 cmd == LNETCTL_ADD_CMD ? "add" : "del",
789 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
790 int sen, int seq_no, struct cYAML **err_rc,
793 int rc, num_nids, idx;
795 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
796 struct lnet_ioctl_config_data data;
797 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
799 if (nw == NULL || nidstr == NULL) {
800 snprintf(err_str, LNET_MAX_STR_LEN,
801 "\"missing mandatory parameter:'%s'\"",
802 (nw == NULL && nidstr == NULL) ? "network, gateway" :
803 (nw == NULL) ? "network" : "gateway");
804 rc = LUSTRE_CFG_RC_MISSING_PARAM;
808 rnet = libcfs_str2net(nw);
809 if (rnet == LNET_NET_ANY) {
810 snprintf(err_str, LNET_MAX_STR_LEN,
811 "\"cannot parse remote net %s\"", nw);
812 rc = LUSTRE_CFG_RC_BAD_PARAM;
816 replace_sep(nidstr, ',', ' ');
817 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
818 LNET_MAX_NIDS_PER_PEER, err_str);
824 for (idx = 0; idx < num_nids; idx++) {
825 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
827 if (cmd == LNETCTL_ADD_CMD) {
828 data.cfg_config_u.cfg_route.rtr_hop = hops;
829 data.cfg_config_u.cfg_route.rtr_priority = prio;
830 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
833 data.cfg_nid = lnet_nidlist[idx];
835 if (cmd == LNETCTL_ADD_CMD)
836 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
839 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
842 if (rc != 0 && errno != EEXIST &&
843 errno != EHOSTUNREACH) {
845 snprintf(err_str, LNET_MAX_STR_LEN,
846 "route operation failed: %s",
849 } else if (errno == EEXIST) {
851 * continue chugging along if one of the
852 * routes already exists
859 cYAML_build_error(rc, seq_no,
860 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
866 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
867 int sen, int seq_no, struct cYAML **err_rc)
870 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
873 hops = LNET_UNDEFINED_HOPS;
874 } else if (hops < 1 || hops > 255) {
875 snprintf(err_str, LNET_MAX_STR_LEN,
876 "\"invalid hop count %d, must be between 1 and 255\"",
878 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
884 } else if (prio < 0) {
885 snprintf(err_str, LNET_MAX_STR_LEN,
886 "\"invalid priority %d, must be greater than 0\"",
888 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
894 } else if (sen < 1) {
895 snprintf(err_str, LNET_MAX_STR_LEN,
896 "\"invalid health sensitivity %d, must be 1 or greater\"",
898 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
902 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
903 err_rc, LNETCTL_ADD_CMD);
906 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
911 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
912 struct cYAML **err_rc)
914 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
918 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
919 int seq_no, struct cYAML **show_rc,
920 struct cYAML **err_rc, bool backup)
922 struct lnet_ioctl_config_data data;
923 lnet_nid_t gateway_nid;
924 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
926 __u32 net = LNET_NET_ANY;
928 struct cYAML *root = NULL, *route = NULL, *item = NULL;
929 struct cYAML *first_seq = NULL;
930 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
934 net = libcfs_str2net(nw);
935 if (net == LNET_NET_ANY) {
938 "\"cannot parse net '%s'\"", nw);
939 rc = LUSTRE_CFG_RC_BAD_PARAM;
944 /* show all routes without filtering on net */
949 gateway_nid = libcfs_str2nid(gw);
950 if (gateway_nid == LNET_NID_ANY) {
953 "\"cannot parse gateway NID '%s'\"", gw);
954 rc = LUSTRE_CFG_RC_BAD_PARAM;
958 /* show all routes with out filtering on gateway */
959 gateway_nid = LNET_NID_ANY;
961 if ((hops < 1 && hops != -1) || hops > 255) {
964 "\"invalid hop count %d, must be between 0 and 256\"",
966 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
970 /* create struct cYAML root object */
971 root = cYAML_create_object(NULL, NULL);
975 route = cYAML_create_seq(root, "route");
983 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
986 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
992 /* filter on provided data */
993 if (net != LNET_NET_ANY &&
997 if (gateway_nid != LNET_NID_ANY &&
998 gateway_nid != data.cfg_nid)
1002 hops != data.cfg_config_u.cfg_route.rtr_hop)
1006 prio != data.cfg_config_u.cfg_route.rtr_priority)
1009 /* default rc to -1 incase we hit the goto */
1013 item = cYAML_create_seq_item(route);
1017 if (first_seq == NULL)
1020 if (cYAML_create_string(item, "net",
1021 libcfs_net2str(data.cfg_net)) == NULL)
1024 if (cYAML_create_string(item, "gateway",
1025 libcfs_nid2str(data.cfg_nid)) == NULL)
1029 if (cYAML_create_number(item, "hop",
1030 (int) data.cfg_config_u.
1031 cfg_route.rtr_hop) ==
1035 if (cYAML_create_number(item, "priority",
1037 cfg_route.rtr_priority) == NULL)
1040 if (cYAML_create_number(item, "health_sensitivity",
1042 cfg_route.rtr_sensitivity) == NULL)
1045 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1047 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1051 cYAML_create_string(item, "state",
1053 "up" : "down") == NULL)
1057 cYAML_create_string(item, "type",
1059 "multi-hop" : "single-hop") == NULL)
1064 /* print output iff show_rc is not provided */
1065 if (show_rc == NULL)
1066 cYAML_print_tree(root);
1068 if (l_errno != ENOENT) {
1071 "\"cannot get routes: %s\"",
1076 rc = LUSTRE_CFG_RC_NO_ERR;
1078 snprintf(err_str, sizeof(err_str), "\"success\"");
1080 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1081 cYAML_free_tree(root);
1082 } else if (show_rc != NULL && *show_rc != NULL) {
1083 struct cYAML *show_node;
1084 /* find the route node, if one doesn't exist then
1085 * insert one. Otherwise add to the one there
1087 show_node = cYAML_get_object_item(*show_rc, "route");
1088 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1089 cYAML_insert_child(show_node, first_seq);
1092 } else if (show_node == NULL) {
1093 cYAML_insert_sibling((*show_rc)->cy_child,
1097 cYAML_free_tree(root);
1103 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1108 static int socket_intf_query(int request, char *intf,
1114 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1115 return LUSTRE_CFG_RC_BAD_PARAM;
1117 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1119 return LUSTRE_CFG_RC_BAD_PARAM;
1121 strcpy(ifr->ifr_name, intf);
1122 rc = ioctl(sockfd, request, ifr);
1124 rc = LUSTRE_CFG_RC_BAD_PARAM;
1131 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1136 memset(&ifr, 0, sizeof(ifr));
1137 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1139 return LUSTRE_CFG_RC_BAD_PARAM;
1141 if ((ifr.ifr_flags & IFF_UP) == 0)
1142 return LUSTRE_CFG_RC_BAD_PARAM;
1144 memset(&ifr, 0, sizeof(ifr));
1145 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1147 return LUSTRE_CFG_RC_BAD_PARAM;
1149 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1150 *ip = bswap_32(*ip);
1152 return LUSTRE_CFG_RC_NO_ERR;
1155 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1158 unsigned int nic_index;
1160 char *nic_addr_path;
1165 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1167 return LUSTRE_CFG_RC_NO_MATCH;
1169 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1170 nic_addr_path = malloc(size);
1172 return LUSTRE_CFG_RC_OUT_OF_MEM;
1173 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1175 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1176 free(nic_addr_path);
1178 return LUSTRE_CFG_RC_NO_MATCH;
1180 addr = strtol(val, NULL, 16);
1181 if (addr == LONG_MIN || addr == LONG_MAX)
1182 return LUSTRE_CFG_RC_NO_MATCH;
1186 return LUSTRE_CFG_RC_NO_ERR;
1190 * for each interface in the array of interfaces find the IP address of
1191 * that interface, create its nid and add it to an array of NIDs.
1192 * Stop if any of the interfaces is down
1194 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1195 lnet_nid_t **nids, __u32 *nnids,
1196 char *err_str, size_t str_len)
1198 int i = 0, count = 0, rc;
1199 struct lnet_dlc_intf_descr *intf;
1200 char val[LNET_MAX_STR_LEN];
1208 if (nw == NULL || nids == NULL) {
1209 snprintf(err_str, str_len,
1210 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1211 return LUSTRE_CFG_RC_BAD_PARAM;
1214 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1217 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1221 *nids = calloc(count, sizeof(lnet_nid_t));
1222 if (*nids == NULL) {
1223 snprintf(err_str, str_len,
1224 "\"out of memory\"");
1225 return LUSTRE_CFG_RC_OUT_OF_MEM;
1228 * special case the GNI interface since it doesn't have an IP
1229 * address. The assumption is that there can only be one GNI
1230 * interface in the system. No interface name is provided.
1232 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1233 rc = read_sysfs_file(gni_nid_path, "nid", val,
1236 snprintf(err_str, str_len,
1237 "\"cannot read gni nid\"");
1240 gni_num = atoi(val);
1242 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1245 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1246 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1247 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1248 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1249 snprintf(err_str, str_len,
1250 "\"couldn't query kfi intf %s\"",
1252 err_str[str_len - 1] = '\0';
1256 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1262 /* look at the other interfaces */
1263 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1264 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1265 /* handle LNDs with numeric interface name */
1266 num = strtoul(intf->intf_name, &endp, 0);
1267 if (endp == intf->intf_name || *endp != '\0') {
1268 rc = LUSTRE_CFG_RC_BAD_PARAM;
1269 snprintf(err_str, str_len,
1270 "\"couldn't query intf %s\"",
1274 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1277 /* handle LNDs with ip interface name */
1278 rc = lustre_lnet_queryip(intf, &ip);
1279 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1280 snprintf(err_str, str_len,
1281 "\"couldn't query intf %s\"",
1285 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1302 * called repeatedly until a match or no more ip range
1304 * ip_range expression
1305 * interface list with all the interface names.
1306 * all the interfaces in the system.
1308 * try to match the ip_range expr to one of the interfaces' IPs in
1309 * the system. If we hit a patch for an interface. Check if that
1310 * interface name is in the list.
1312 * If there are more than one interface in the list, then make sure
1313 * that the IPs for all of these interfaces match the ip ranges
1316 * for each interface in intf_list
1317 * look up the intf name in ifa
1318 * if not there then no match
1319 * check ip obtained from ifa against a match to any of the
1321 * If no match, then fail
1323 * The result is that all the interfaces have to match.
1325 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1326 struct list_head *intf_list,
1327 struct list_head *ip_ranges)
1331 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1332 struct ifaddrs *ifaddr = ifa;
1333 struct lustre_lnet_ip_range_descr *ip_range;
1337 * if there are no explicit interfaces, and no ip ranges, then
1338 * configure the first tcp interface we encounter.
1340 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1341 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1342 if (ifaddr->ifa_addr == NULL)
1345 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1348 family = ifaddr->ifa_addr->sa_family;
1349 if (family == AF_INET &&
1350 strcmp(ifaddr->ifa_name, "lo") != 0) {
1351 rc = lustre_lnet_add_intf_descr
1352 (intf_list, ifaddr->ifa_name,
1353 strlen(ifaddr->ifa_name));
1355 if (rc != LUSTRE_CFG_RC_NO_ERR)
1358 return LUSTRE_CFG_RC_MATCH;
1361 return LUSTRE_CFG_RC_NO_MATCH;
1365 * First interface which matches an IP pattern will be used
1367 if (list_empty(intf_list)) {
1369 * no interfaces provided in the rule, but an ip range is
1370 * provided, so try and match an interface to the ip
1373 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1374 if (ifaddr->ifa_addr == NULL)
1377 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1380 family = ifaddr->ifa_addr->sa_family;
1381 if (family == AF_INET) {
1382 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1385 list_for_each_entry(ip_range, ip_ranges,
1387 rc = cfs_ip_addr_match(bswap_32(ip),
1388 &ip_range->ipr_expr);
1392 rc = lustre_lnet_add_intf_descr
1393 (intf_list, ifaddr->ifa_name,
1394 strlen(ifaddr->ifa_name));
1396 if (rc != LUSTRE_CFG_RC_NO_ERR)
1402 if (!list_empty(intf_list))
1403 return LUSTRE_CFG_RC_MATCH;
1405 return LUSTRE_CFG_RC_NO_MATCH;
1409 * If an interface is explicitly specified the ip-range might or
1410 * might not be specified. if specified the interface needs to match the
1411 * ip-range. If no ip-range then the interfaces are
1412 * automatically matched if they are all up.
1413 * If > 1 interfaces all the interfaces must match for the NI to
1416 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1417 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1418 if (ifaddr->ifa_addr == NULL)
1421 family = ifaddr->ifa_addr->sa_family;
1422 if (family == AF_INET &&
1423 strcmp(intf_descr->intf_name,
1424 ifaddr->ifa_name) == 0)
1428 if (ifaddr == NULL) {
1429 list_del(&intf_descr->intf_on_network);
1430 free_intf_descr(intf_descr);
1434 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1435 list_del(&intf_descr->intf_on_network);
1436 free_intf_descr(intf_descr);
1440 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1443 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1444 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1450 /* no match for this interface */
1451 list_del(&intf_descr->intf_on_network);
1452 free_intf_descr(intf_descr);
1456 return LUSTRE_CFG_RC_MATCH;
1459 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1460 lnet_nid_t **nids, __u32 *nnids,
1461 char *err_str, size_t str_len)
1463 struct ifaddrs *ifa;
1464 int rc = LUSTRE_CFG_RC_NO_ERR;
1466 rc = getifaddrs(&ifa);
1468 snprintf(err_str, str_len,
1469 "\"failed to get interface addresses: %d\"", -errno);
1473 rc = lustre_lnet_match_ip_to_intf(ifa,
1474 &ip2nets->ip2nets_net.nw_intflist,
1475 &ip2nets->ip2nets_ip_ranges);
1476 if (rc != LUSTRE_CFG_RC_MATCH) {
1477 snprintf(err_str, str_len,
1478 "\"couldn't match ip to existing interfaces\"");
1483 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1485 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1496 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1497 struct lnet_ioctl_config_lnd_tunables *tunables,
1498 struct cfs_expr_list *global_cpts,
1499 lnet_nid_t *nids, char *err_str)
1502 struct lnet_ioctl_config_ni *conf;
1503 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1504 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1507 struct lnet_dlc_intf_descr *intf_descr;
1509 struct cfs_expr_list *cpt_expr;
1511 list_for_each_entry(intf_descr, intf_list,
1513 if (tunables != NULL)
1514 len = sizeof(struct lnet_ioctl_config_ni) +
1515 sizeof(struct lnet_ioctl_config_lnd_tunables);
1517 len = sizeof(struct lnet_ioctl_config_ni);
1519 data = calloc(1, len);
1521 return LUSTRE_CFG_RC_OUT_OF_MEM;
1522 conf = (struct lnet_ioctl_config_ni*) data;
1523 if (tunables != NULL)
1524 tun = (struct lnet_ioctl_config_lnd_tunables*)
1527 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1528 conf->lic_cfg_hdr.ioc_len = len;
1529 conf->lic_nid = nids[i];
1530 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1533 if (intf_descr->cpt_expr != NULL)
1534 cpt_expr = intf_descr->cpt_expr;
1535 else if (global_cpts != NULL)
1536 cpt_expr = global_cpts;
1540 if (cpt_expr != NULL) {
1541 count = cfs_expr_list_values(cpt_expr,
1542 LNET_MAX_SHOW_NUM_CPT,
1545 memcpy(conf->lic_cpts, cpt_array,
1546 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1555 conf->lic_ncpts = count;
1557 if (tunables != NULL)
1558 memcpy(tun, tunables, sizeof(*tunables));
1560 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1565 "\"cannot add network: %s\"", strerror(errno));
1573 return LUSTRE_CFG_RC_NO_ERR;
1577 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1578 struct lnet_ioctl_config_lnd_tunables *tunables,
1579 struct cfs_expr_list *global_cpts,
1580 int seq_no, struct cYAML **err_rc)
1582 lnet_nid_t *nids = NULL;
1585 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1590 "\"incomplete ip2nets information\"");
1591 rc = LUSTRE_CFG_RC_BAD_PARAM;
1596 * call below function to resolve the rules into a list of nids.
1597 * The memory is allocated in that function then freed here when
1598 * it's no longer needed.
1600 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1602 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1605 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1606 snprintf(err_str, sizeof(err_str),
1607 "\"no interfaces match ip2nets rules\"");
1611 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1612 tunables, global_cpts, nids,
1619 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1623 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1624 struct cfs_expr_list *global_cpts,
1626 struct lnet_ioctl_config_lnd_tunables *tunables,
1627 long int cpp, int seq_no, struct cYAML **err_rc)
1630 struct lnet_ioctl_config_ni *conf;
1631 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1632 char buf[LNET_MAX_STR_LEN];
1633 int rc = LUSTRE_CFG_RC_NO_ERR;
1634 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1635 lnet_nid_t *nids = NULL;
1639 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1642 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1643 (list_empty(&nw_descr->nw_intflist) &&
1644 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1647 "\"missing mandatory parameters in NI config: '%s'\"",
1648 (nw_descr == NULL) ? "network , interface" :
1649 (nw_descr->nw_id == 0) ? "network" : "interface");
1650 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1654 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1657 "\"ip2net string too long %d\"",
1658 (int)strlen(ip2net));
1659 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1663 if (ip2net != NULL) {
1664 if (tunables != NULL)
1665 len = sizeof(struct lnet_ioctl_config_ni) +
1666 sizeof(struct lnet_ioctl_config_lnd_tunables);
1668 len = sizeof(struct lnet_ioctl_config_ni);
1669 data = calloc(1, len);
1671 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1674 conf = (struct lnet_ioctl_config_ni*) data;
1675 if (tunables != NULL)
1676 tun = (struct lnet_ioctl_config_lnd_tunables*)
1677 (data + sizeof(*conf));
1679 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1680 conf->lic_cfg_hdr.ioc_len = len;
1681 strncpy(conf->lic_legacy_ip2nets, ip2net,
1684 if (global_cpts != NULL) {
1685 count = cfs_expr_list_values(global_cpts,
1686 LNET_MAX_SHOW_NUM_CPT,
1689 memcpy(conf->lic_cpts, cpt_array,
1690 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1699 conf->lic_ncpts = count;
1701 if (tunables != NULL)
1702 memcpy(tun, tunables, sizeof(*tunables));
1704 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1709 "\"cannot add network: %s\"", strerror(errno));
1716 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1717 rc = LUSTRE_CFG_RC_NO_ERR;
1721 if (nw_descr->nw_id == LNET_NET_ANY) {
1724 "\"cannot parse net '%s'\"",
1725 libcfs_net2str(nw_descr->nw_id));
1726 rc = LUSTRE_CFG_RC_BAD_PARAM;
1731 * special case the GNI since no interface name is expected
1733 if (list_empty(&nw_descr->nw_intflist) &&
1734 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1737 "\"no interface name provided\"");
1738 rc = LUSTRE_CFG_RC_BAD_PARAM;
1742 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND && (cpp > -1))
1743 tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
1744 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND && (cpp > -1))
1745 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
1747 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1748 err_str, sizeof(err_str));
1750 rc = LUSTRE_CFG_RC_BAD_PARAM;
1754 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1755 tunables, global_cpts, nids,
1759 if (nw_descr != NULL) {
1760 list_for_each_entry_safe(intf_descr, tmp,
1761 &nw_descr->nw_intflist,
1763 list_del(&intf_descr->intf_on_network);
1764 free_intf_descr(intf_descr);
1768 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1779 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1780 int seq_no, struct cYAML **err_rc)
1782 struct lnet_ioctl_config_ni data;
1783 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1784 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1785 lnet_nid_t *nids = NULL;
1787 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1789 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1792 "\"missing mandatory parameter in deleting NI: '%s'\"",
1793 (nw_descr == NULL) ? "network , interface" :
1794 (nw_descr->nw_id == 0) ? "network" : "interface");
1795 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1799 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1800 return LUSTRE_CFG_RC_NO_ERR;
1802 if (nw_descr->nw_id == LNET_NET_ANY) {
1805 "\"cannot parse net '%s'\"",
1806 libcfs_net2str(nw_descr->nw_id));
1807 rc = LUSTRE_CFG_RC_BAD_PARAM;
1811 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1812 err_str, sizeof(err_str));
1814 rc = LUSTRE_CFG_RC_BAD_PARAM;
1819 * no interfaces just the nw_id is specified
1822 nids = calloc(1, sizeof(*nids));
1824 snprintf(err_str, sizeof(err_str),
1825 "\"out of memory\"");
1826 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1829 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1833 for (i = 0; i < nnids; i++) {
1834 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1835 data.lic_nid = nids[i];
1837 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1842 "\"cannot del network: %s\"", strerror(errno));
1846 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1848 list_del(&intf_descr->intf_on_network);
1849 free_intf_descr(intf_descr);
1853 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1862 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1863 enum lnet_health_type type, char *name,
1864 int seq_no, struct cYAML **err_rc)
1866 struct lnet_ioctl_reset_health_cfg data;
1867 int rc = LUSTRE_CFG_RC_NO_ERR;
1868 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1870 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1871 data.rh_type = type;
1873 data.rh_value = value;
1876 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1880 sizeof(err_str), "Can not configure health value: %s",
1884 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1891 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1892 char *name, int seq_no,
1893 struct cYAML **err_rc)
1895 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1896 int rc = LUSTRE_CFG_RC_NO_ERR;
1897 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1899 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1900 data.rcpp_all = all;
1901 data.rcpp_value = value;
1902 data.rcpp_nid = nid;
1904 if (value < 0 || value > 127) {
1905 rc = LUSTRE_CFG_RC_BAD_PARAM;
1906 snprintf(err_str, sizeof(err_str),
1907 "\"Valid values are: 0-127\"");
1910 rc = l_ioctl(LNET_DEV_ID,
1911 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1916 "Can not configure conns_per_peer value: %s",
1920 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1925 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1926 struct cYAML **err_rc)
1930 nid = libcfs_str2nid(ni_nid);
1933 return lustre_lnet_config_healthv(value, all, nid,
1934 LNET_HEALTH_TYPE_LOCAL_NI,
1935 "ni healthv", seq_no, err_rc);
1938 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1939 int seq_no, struct cYAML **err_rc)
1943 nid = libcfs_str2nid(lpni_nid);
1946 return lustre_lnet_config_healthv(value, all, nid,
1947 LNET_HEALTH_TYPE_PEER_NI,
1948 "peer_ni healthv", seq_no, err_rc);
1951 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1952 int seq_no, struct cYAML **err_rc)
1957 nid = libcfs_str2nid(ni_nid);
1960 return lustre_lnet_config_conns_per_peer(value, all, nid,
1961 "ni conns_per_peer",
1966 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1967 struct lnet_ioctl_comm_count *counts)
1969 if (cYAML_create_number(yaml, "put",
1970 counts->ico_put_count)
1973 if (cYAML_create_number(yaml, "get",
1974 counts->ico_get_count)
1977 if (cYAML_create_number(yaml, "reply",
1978 counts->ico_reply_count)
1981 if (cYAML_create_number(yaml, "ack",
1982 counts->ico_ack_count)
1985 if (cYAML_create_number(yaml, "hello",
1986 counts->ico_hello_count)
1993 static struct lnet_ioctl_comm_count *
1994 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1997 return &msg_stats->im_send_stats;
1999 return &msg_stats->im_recv_stats;
2001 return &msg_stats->im_drop_stats;
2007 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2008 struct cYAML *net_node)
2010 char tmp[LNET_MAX_STR_LEN];
2011 struct cYAML *udsp_net;
2012 bool created = false;
2016 /* add the UDSP info */
2017 udsp_net = cYAML_create_object(net_node, "udsp info");
2019 return LUSTRE_CFG_RC_OUT_OF_MEM;
2021 if (!cYAML_create_number(udsp_net, "net priority",
2022 (int) udsp_info->cud_net_priority))
2023 return LUSTRE_CFG_RC_OUT_OF_MEM;
2025 if (!cYAML_create_number(udsp_net, "nid priority",
2026 (int)udsp_info->cud_nid_priority))
2027 return LUSTRE_CFG_RC_OUT_OF_MEM;
2031 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2032 memset(tmp, 0, LNET_MAX_STR_LEN);
2033 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2036 pref = cYAML_create_object(udsp_net,
2037 "Preferred gateway NIDs");
2039 return LUSTRE_CFG_RC_OUT_OF_MEM;
2042 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2043 if (!cYAML_create_string(pref, tmp,
2044 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2045 return LUSTRE_CFG_RC_OUT_OF_MEM;
2048 return LUSTRE_CFG_RC_NO_ERR;
2052 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2053 struct cYAML *nid_node)
2055 char tmp[LNET_MAX_STR_LEN];
2056 struct cYAML *udsp_nid;
2057 bool created = false;
2061 /* add the UDSP info */
2062 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2064 return LUSTRE_CFG_RC_OUT_OF_MEM;
2066 if (!cYAML_create_number(udsp_nid, "net priority",
2067 (int) udsp_info->cud_net_priority))
2068 return LUSTRE_CFG_RC_OUT_OF_MEM;
2070 if (!cYAML_create_number(udsp_nid, "nid priority",
2071 (int) udsp_info->cud_nid_priority))
2072 return LUSTRE_CFG_RC_OUT_OF_MEM;
2075 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2076 memset(tmp, 0, LNET_MAX_STR_LEN);
2077 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2080 pref = cYAML_create_object(udsp_nid,
2081 "Preferred gateway NIDs");
2083 return LUSTRE_CFG_RC_OUT_OF_MEM;
2086 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2087 if (!cYAML_create_string(pref, tmp,
2088 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2089 return LUSTRE_CFG_RC_OUT_OF_MEM;
2094 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2095 memset(tmp, 0, LNET_MAX_STR_LEN);
2096 if (udsp_info->cud_pref_nid[i] == 0)
2099 pref = cYAML_create_object(udsp_nid,
2100 "Preferred source NIDs");
2102 return LUSTRE_CFG_RC_OUT_OF_MEM;
2105 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2106 if (!cYAML_create_string(pref, tmp,
2107 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2108 return LUSTRE_CFG_RC_OUT_OF_MEM;
2111 return LUSTRE_CFG_RC_NO_ERR;
2114 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2115 struct cYAML **show_rc, struct cYAML **err_rc,
2119 struct lnet_ioctl_config_ni *ni_data;
2120 struct lnet_ioctl_config_lnd_tunables *lnd;
2121 struct lnet_ioctl_element_stats *stats;
2122 struct lnet_ioctl_element_msg_stats msg_stats;
2123 struct lnet_ioctl_local_ni_hstats hstats;
2124 struct lnet_ioctl_construct_udsp_info udsp_info;
2125 __u32 net = LNET_NET_ANY;
2126 __u32 prev_net = LNET_NET_ANY;
2127 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2129 struct cYAML *root = NULL, *tunables = NULL,
2130 *net_node = NULL, *interfaces = NULL,
2131 *item = NULL, *first_seq = NULL,
2132 *tmp = NULL, *statistics = NULL,
2134 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2135 char str_buf[str_buf_len];
2137 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2138 bool exist = false, new_net = true;
2140 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2142 buf = calloc(1, buf_size);
2146 ni_data = (struct lnet_ioctl_config_ni *)buf;
2149 net = libcfs_str2net(nw);
2150 if (net == LNET_NET_ANY) {
2153 "\"cannot parse net '%s'\"", nw);
2154 rc = LUSTRE_CFG_RC_BAD_PARAM;
2159 root = cYAML_create_object(NULL, NULL);
2163 net_node = cYAML_create_seq(root, "net");
2164 if (net_node == NULL)
2170 memset(buf, 0, buf_size);
2172 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2174 * set the ioc_len to the proper value since INIT assumes
2177 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2178 ni_data->lic_idx = i;
2180 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2186 rc_net = LNET_NIDNET(ni_data->lic_nid);
2188 /* filter on provided data */
2189 if (net != LNET_NET_ANY &&
2193 /* if we're backing up don't store lo */
2194 if (backup && LNET_NETTYP(rc_net) == LOLND)
2197 /* default rc to -1 in case we hit the goto */
2201 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2202 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2203 (ni_data->lic_bulk + sizeof(*stats));
2205 if (rc_net != prev_net) {
2212 if (!cYAML_create_string(net_node, "net type",
2213 libcfs_net2str(rc_net)))
2216 tmp = cYAML_create_seq(net_node, "local NI(s)");
2222 /* create the tree to be printed. */
2223 item = cYAML_create_seq_item(tmp);
2227 if (first_seq == NULL)
2231 cYAML_create_string(item, "nid",
2232 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2236 cYAML_create_string(item,
2238 (ni_data->lic_status ==
2239 LNET_NI_STATUS_UP) ?
2240 "up" : "down") == NULL)
2243 /* don't add interfaces unless there is at least one
2245 if (strlen(ni_data->lic_ni_intf) > 0) {
2246 interfaces = cYAML_create_object(item, "interfaces");
2247 if (interfaces == NULL)
2250 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2251 if (cYAML_create_string(interfaces, str_buf,
2252 ni_data->lic_ni_intf) == NULL)
2261 goto continue_without_msg_stats;
2263 statistics = cYAML_create_object(item, "statistics");
2264 if (statistics == NULL)
2267 if (cYAML_create_number(statistics, "send_count",
2268 stats->iel_send_count)
2272 if (cYAML_create_number(statistics, "recv_count",
2273 stats->iel_recv_count)
2277 if (cYAML_create_number(statistics, "drop_count",
2278 stats->iel_drop_count)
2283 goto continue_without_udsp_info;
2285 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2286 udsp_info.cud_nid = ni_data->lic_nid;
2287 udsp_info.cud_peer = false;
2288 rc = l_ioctl(LNET_DEV_ID,
2289 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2293 goto continue_without_udsp_info;
2296 rc = create_local_udsp_info(&udsp_info, item);
2302 continue_without_udsp_info:
2304 goto continue_without_msg_stats;
2306 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2307 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2308 msg_stats.im_idx = i;
2310 rc = l_ioctl(LNET_DEV_ID,
2311 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2315 goto continue_without_msg_stats;
2318 for (k = 0; k < 3; k++) {
2319 struct lnet_ioctl_comm_count *counts;
2320 struct cYAML *msg_statistics = NULL;
2322 msg_statistics = cYAML_create_object(item,
2323 (char *)gmsg_stat_names[k]);
2324 if (msg_statistics == NULL)
2327 counts = get_counts(&msg_stats, k);
2331 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2336 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2337 hstats.hlni_nid = ni_data->lic_nid;
2338 /* grab health stats */
2339 rc = l_ioctl(LNET_DEV_ID,
2340 IOC_LIBCFS_GET_LOCAL_HSTATS,
2344 goto continue_without_msg_stats;
2346 yhstats = cYAML_create_object(item, "health stats");
2349 if (cYAML_create_number(yhstats, "fatal_error",
2350 hstats.hlni_fatal_error)
2353 if (cYAML_create_number(yhstats, "health value",
2354 hstats.hlni_health_value)
2357 if (cYAML_create_number(yhstats, "interrupts",
2358 hstats.hlni_local_interrupt)
2361 if (cYAML_create_number(yhstats, "dropped",
2362 hstats.hlni_local_dropped)
2365 if (cYAML_create_number(yhstats, "aborted",
2366 hstats.hlni_local_aborted)
2369 if (cYAML_create_number(yhstats, "no route",
2370 hstats.hlni_local_no_route)
2373 if (cYAML_create_number(yhstats, "timeouts",
2374 hstats.hlni_local_timeout)
2377 if (cYAML_create_number(yhstats, "error",
2378 hstats.hlni_local_error)
2381 if (cYAML_create_number(yhstats, "ping_count",
2382 hstats.hlni_ping_count)
2385 if (cYAML_create_number(yhstats, "next_ping",
2386 hstats.hlni_next_ping)
2390 continue_without_msg_stats:
2391 tunables = cYAML_create_object(item, "tunables");
2395 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2396 if (rc != LUSTRE_CFG_RC_NO_ERR)
2399 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2400 tunables = cYAML_create_object(item,
2402 if (tunables == NULL)
2406 rc = lustre_ni_show_tunables(tunables,
2407 LNET_NETTYP(rc_net),
2409 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2410 rc != LUSTRE_CFG_RC_NO_MATCH)
2414 cYAML_create_number(item, "dev cpt",
2415 ni_data->lic_dev_cpt) == NULL)
2418 /* out put the CPTs in the format: "[x,x,x,...]" */
2420 limit = str_buf + str_buf_len - 3;
2421 pos += scnprintf(pos, limit - pos, "\"[");
2422 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2423 j < ni_data->lic_ncpts &&
2425 pos += scnprintf(pos, limit - pos,
2426 "%d", ni_data->lic_cpts[j]);
2427 if ((j + 1) < ni_data->lic_ncpts)
2428 pos += scnprintf(pos, limit - pos, ",");
2430 snprintf(pos, 3, "]\"");
2432 if (ni_data->lic_ncpts >= 1 &&
2433 cYAML_create_string(item, "CPT",
2439 /* Print out the net information only if show_rc is not provided */
2440 if (show_rc == NULL)
2441 cYAML_print_tree(root);
2443 if (l_errno != ENOENT) {
2446 "\"cannot get networks: %s\"",
2451 rc = LUSTRE_CFG_RC_NO_ERR;
2453 snprintf(err_str, sizeof(err_str), "\"success\"");
2455 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2456 cYAML_free_tree(root);
2457 } else if (show_rc != NULL && *show_rc != NULL) {
2458 struct cYAML *show_node;
2459 /* find the net node, if one doesn't exist
2460 * then insert one. Otherwise add to the one there
2462 show_node = cYAML_get_object_item(*show_rc, "net");
2463 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2464 cYAML_insert_child(show_node, first_seq);
2467 } else if (show_node == NULL) {
2468 cYAML_insert_sibling((*show_rc)->cy_child,
2472 cYAML_free_tree(root);
2478 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2483 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2485 struct lnet_ioctl_config_data data;
2486 int rc = LUSTRE_CFG_RC_NO_ERR;
2487 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2489 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2490 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2492 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2497 "\"cannot %s routing %s\"",
2498 (enable) ? "enable" : "disable", strerror(errno));
2503 cYAML_build_error(rc, seq_no,
2504 (enable) ? ADD_CMD : DEL_CMD,
2505 "routing", err_str, err_rc);
2510 int ioctl_set_value(__u32 val, int ioc, char *name,
2511 int seq_no, struct cYAML **err_rc)
2513 struct lnet_ioctl_set_value data;
2514 int rc = LUSTRE_CFG_RC_NO_ERR;
2515 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2517 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2518 data.sv_value = val;
2520 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2525 "\"cannot configure %s to %d: %s\"", name,
2526 val, strerror(errno));
2529 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2534 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2536 int rc = LUSTRE_CFG_RC_NO_ERR;
2537 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2538 char val[LNET_MAX_STR_LEN];
2540 snprintf(val, sizeof(val), "%d", intrv);
2542 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2543 1, strlen(val) + 1);
2545 snprintf(err_str, sizeof(err_str),
2546 "\"cannot configure recovery interval: %s\"",
2549 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2554 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2556 int rc = LUSTRE_CFG_RC_NO_ERR;
2557 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2558 char val[LNET_MAX_STR_LEN];
2560 snprintf(val, sizeof(val), "%d", sen);
2562 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2563 1, strlen(val) + 1);
2565 snprintf(err_str, sizeof(err_str),
2566 "\"cannot configure router health sensitivity: %s\"",
2569 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2574 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2576 int rc = LUSTRE_CFG_RC_NO_ERR;
2577 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2578 char val[LNET_MAX_STR_LEN];
2580 snprintf(val, sizeof(val), "%d", sen);
2582 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2583 1, strlen(val) + 1);
2585 snprintf(err_str, sizeof(err_str),
2586 "\"cannot configure health sensitivity: %s\"",
2589 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2594 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2596 int rc = LUSTRE_CFG_RC_NO_ERR;
2597 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2598 char val[LNET_MAX_STR_LEN];
2600 snprintf(val, sizeof(val), "%d", timeout);
2602 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2603 1, strlen(val) + 1);
2605 snprintf(err_str, sizeof(err_str),
2606 "\"cannot configure transaction timeout: %s\"",
2609 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2614 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2616 int rc = LUSTRE_CFG_RC_NO_ERR;
2617 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2618 char val[LNET_MAX_STR_LEN];
2620 snprintf(val, sizeof(val), "%d", count);
2622 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2623 1, strlen(val) + 1);
2625 snprintf(err_str, sizeof(err_str),
2626 "\"cannot configure retry count: %s\"",
2629 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2634 int lustre_lnet_config_response_tracking(int val, int seq_no,
2635 struct cYAML **err_rc)
2637 int rc = LUSTRE_CFG_RC_NO_ERR;
2638 char err_str[LNET_MAX_STR_LEN];
2639 char val_str[LNET_MAX_STR_LEN];
2641 if (val < 0 || val > 3) {
2642 rc = LUSTRE_CFG_RC_BAD_PARAM;
2643 snprintf(err_str, sizeof(err_str),
2644 "\"Valid values are: 0, 1, 2, or 3\"");
2646 snprintf(err_str, sizeof(err_str), "\"success\"");
2648 snprintf(val_str, sizeof(val_str), "%d", val);
2650 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2651 val_str, 1, strlen(val_str) + 1);
2653 snprintf(err_str, sizeof(err_str),
2654 "\"cannot configure response tracking: %s\"",
2658 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2664 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2665 struct cYAML **err_rc)
2667 int rc = LUSTRE_CFG_RC_NO_ERR;
2668 char err_str[LNET_MAX_STR_LEN];
2669 char val_str[LNET_MAX_STR_LEN];
2672 rc = LUSTRE_CFG_RC_BAD_PARAM;
2673 snprintf(err_str, sizeof(err_str),
2674 "\"Must be greater than or equal to 0\"");
2676 snprintf(err_str, sizeof(err_str), "\"success\"");
2678 snprintf(val_str, sizeof(val_str), "%d", val);
2680 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2681 val_str, 1, strlen(val_str) + 1);
2683 snprintf(err_str, sizeof(err_str),
2684 "\"cannot configure recovery limit: %s\"",
2688 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2694 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2696 int rc = LUSTRE_CFG_RC_NO_ERR;
2697 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2698 char val[LNET_MAX_STR_LEN];
2700 snprintf(val, sizeof(val), "%d", max);
2702 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2703 1, strlen(val) + 1);
2705 snprintf(err_str, sizeof(err_str),
2706 "\"cannot configure max interfaces: %s\"",
2709 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2714 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2716 int rc = LUSTRE_CFG_RC_NO_ERR;
2717 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2718 char val[LNET_MAX_STR_LEN];
2720 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2722 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2723 1, strlen(val) + 1);
2725 snprintf(err_str, sizeof(err_str),
2726 "\"cannot configure discovery: %s\"",
2729 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2735 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2736 struct cYAML **err_rc)
2738 int rc = LUSTRE_CFG_RC_NO_ERR;
2739 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2740 char val[LNET_MAX_STR_LEN];
2742 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2744 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2745 1, strlen(val) + 1);
2747 snprintf(err_str, sizeof(err_str),
2748 "\"cannot configure drop asym route: %s\"",
2751 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2758 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2760 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2761 "numa_range", seq_no, err_rc);
2764 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2765 struct cYAML **err_rc)
2767 struct lnet_ioctl_config_data data;
2768 int rc = LUSTRE_CFG_RC_NO_ERR;
2769 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2771 /* -1 indicates to ignore changes to this field */
2772 if (tiny < -1 || small < -1 || large < -1) {
2775 "\"tiny, small and large must be >= 0\"");
2776 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2780 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2781 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2782 data.cfg_config_u.cfg_buffers.buf_small = small;
2783 data.cfg_config_u.cfg_buffers.buf_large = large;
2785 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2790 "\"cannot configure buffers: %s\"", strerror(errno));
2795 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2800 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2801 struct cYAML **err_rc)
2803 int rc = LUSTRE_CFG_RC_NO_ERR;
2804 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2805 char interval_str[LNET_MAX_STR_LEN];
2807 if (interval <= 0) {
2808 rc = LUSTRE_CFG_RC_BAD_PARAM;
2809 snprintf(err_str, sizeof(err_str),
2810 "\"must be strictly positive\"");
2813 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2815 rc = write_sysfs_file(modparam_path,
2816 "lnet_max_recovery_ping_interval",
2818 strlen(interval_str) + 1);
2820 snprintf(err_str, sizeof(err_str),
2821 "\"cannot configure maximum recovery ping interval: %s\"",
2825 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2832 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2833 struct cYAML **err_rc, bool backup)
2835 struct lnet_ioctl_config_data *data;
2836 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2837 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2840 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2841 int buf_count[LNET_NRBPOOLS] = {0};
2842 struct cYAML *root = NULL, *pools_node = NULL,
2843 *type_node = NULL, *item = NULL, *cpt = NULL,
2844 *first_seq = NULL, *buffers = NULL;
2846 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2847 char node_name[LNET_MAX_STR_LEN];
2850 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2854 data = (struct lnet_ioctl_config_data *)buf;
2856 root = cYAML_create_object(NULL, NULL);
2861 pools_node = cYAML_create_object(root, "routing");
2863 pools_node = cYAML_create_seq(root, "routing");
2864 if (pools_node == NULL)
2868 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2869 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2870 sizeof(struct lnet_ioctl_pool_cfg);
2871 data->cfg_count = i;
2873 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2881 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2884 goto calculate_buffers;
2886 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2887 item = cYAML_create_seq_item(pools_node);
2891 if (first_seq == NULL)
2894 cpt = cYAML_create_object(item, node_name);
2899 /* create the tree and print */
2900 for (j = 0; j < LNET_NRBPOOLS; j++) {
2902 type_node = cYAML_create_object(cpt, pools[j]);
2903 if (type_node == NULL)
2907 cYAML_create_number(type_node, "npages",
2908 pool_cfg->pl_pools[j].pl_npages)
2912 cYAML_create_number(type_node, "nbuffers",
2913 pool_cfg->pl_pools[j].
2914 pl_nbuffers) == NULL)
2917 cYAML_create_number(type_node, "credits",
2918 pool_cfg->pl_pools[j].
2919 pl_credits) == NULL)
2922 cYAML_create_number(type_node, "mincredits",
2923 pool_cfg->pl_pools[j].
2924 pl_mincredits) == NULL)
2926 /* keep track of the total count for each of the
2927 * tiny, small and large buffers */
2928 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2932 if (pool_cfg != NULL) {
2934 if (cYAML_create_number(pools_node, "enable",
2935 pool_cfg->pl_routing) ==
2939 goto add_buffer_section;
2942 item = cYAML_create_seq_item(pools_node);
2946 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2952 /* create a buffers entry in the show. This is necessary so that
2953 * if the YAML output is used to configure a node, the buffer
2954 * configuration takes hold */
2955 buffers = cYAML_create_object(root, "buffers");
2956 if (buffers == NULL)
2959 for (i = 0; i < LNET_NRBPOOLS; i++) {
2960 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2964 if (show_rc == NULL)
2965 cYAML_print_tree(root);
2967 if (l_errno != ENOENT) {
2970 "\"cannot get routing information: %s\"",
2975 rc = LUSTRE_CFG_RC_NO_ERR;
2977 snprintf(err_str, sizeof(err_str), "\"success\"");
2978 rc = LUSTRE_CFG_RC_NO_ERR;
2982 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2983 cYAML_free_tree(root);
2984 } else if (show_rc != NULL && *show_rc != NULL) {
2985 struct cYAML *routing_node;
2986 /* there should exist only one routing block and one
2987 * buffers block. If there already exists a previous one
2988 * then don't add another */
2989 routing_node = cYAML_get_object_item(*show_rc, "routing");
2990 if (routing_node == NULL) {
2991 cYAML_insert_sibling((*show_rc)->cy_child,
2995 cYAML_free_tree(root);
3001 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3006 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3007 struct cYAML **show_rc, struct cYAML **err_rc,
3011 * TODO: This function is changing in a future patch to accommodate
3012 * PEER_LIST and proper filtering on any nid of the peer
3014 struct lnet_ioctl_peer_cfg peer_info;
3015 struct lnet_peer_ni_credit_info *lpni_cri;
3016 struct lnet_ioctl_element_stats *lpni_stats;
3017 struct lnet_ioctl_element_msg_stats *msg_stats;
3018 struct lnet_ioctl_peer_ni_hstats *hstats;
3019 struct lnet_ioctl_construct_udsp_info udsp_info;
3021 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3026 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3027 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3028 *msg_statistics = NULL, *statistics = NULL,
3030 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3031 struct lnet_process_id *list = NULL;
3036 /* create struct cYAML root object */
3037 root = cYAML_create_object(NULL, NULL);
3041 peer_root = cYAML_create_seq(root, "peer");
3042 if (peer_root == NULL)
3046 size = count * sizeof(struct lnet_process_id);
3047 list = malloc(size);
3053 list[0].nid = libcfs_str2nid(knid);
3057 memset(&peer_info, 0, sizeof(peer_info));
3058 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3059 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3060 peer_info.prcfg_size = size;
3061 peer_info.prcfg_bulk = list;
3064 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3066 count = peer_info.prcfg_count;
3070 if (l_errno != E2BIG) {
3073 "\"cannot get peer list: %s\"",
3079 size = peer_info.prcfg_size;
3080 list = malloc(size);
3089 data = malloc(size);
3095 for (i = 0; i < count; i++) {
3097 memset(&peer_info, 0, sizeof(peer_info));
3098 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3099 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3100 peer_info.prcfg_prim_nid = list[i].nid;
3101 peer_info.prcfg_size = size;
3102 peer_info.prcfg_bulk = data;
3105 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3110 if (l_errno != E2BIG) {
3113 "\"cannot get peer information: %s\"",
3119 size = peer_info.prcfg_size;
3120 data = malloc(size);
3128 peer = cYAML_create_seq_item(peer_root);
3132 if (first_seq == NULL)
3135 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3136 if (cYAML_create_string(peer, "primary nid",
3137 libcfs_nid2str(pnid))
3140 if (cYAML_create_string(peer, "Multi-Rail",
3141 peer_info.prcfg_mr ? "True" : "False")
3145 * print out the state of the peer only if details are
3150 cYAML_create_number(peer, "peer state",
3151 peer_info.prcfg_state)
3156 tmp = cYAML_create_seq(peer, "peer ni");
3161 for (j = 0; j < peer_info.prcfg_count; j++) {
3163 lpni_cri = (void*)nidp + sizeof(nidp);
3164 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3165 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3166 hstats = (void *)msg_stats + sizeof(*msg_stats);
3167 lpni_data = (void *)hstats + sizeof(*hstats);
3169 peer_ni = cYAML_create_seq_item(tmp);
3170 if (peer_ni == NULL)
3173 if (cYAML_create_string(peer_ni, "nid",
3174 libcfs_nid2str(*nidp))
3182 goto continue_without_udsp_info;
3184 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3185 udsp_info.cud_nid = *nidp;
3186 udsp_info.cud_peer = true;
3187 rc = l_ioctl(LNET_DEV_ID,
3188 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3192 goto continue_without_udsp_info;
3195 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3201 continue_without_udsp_info:
3202 if (cYAML_create_string(peer_ni, "state",
3203 lpni_cri->cr_aliveness)
3210 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3211 lpni_cri->cr_ni_peer_tx_credits)
3215 if (cYAML_create_number(peer_ni, "available_tx_credits",
3216 lpni_cri->cr_peer_tx_credits)
3220 if (cYAML_create_number(peer_ni, "min_tx_credits",
3221 lpni_cri->cr_peer_min_tx_credits)
3225 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3226 lpni_cri->cr_peer_tx_qnob)
3230 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3231 lpni_cri->cr_peer_rtr_credits)
3235 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3236 lpni_cri->cr_peer_min_rtr_credits)
3240 if (cYAML_create_number(peer_ni, "refcount",
3241 lpni_cri->cr_refcount) == NULL)
3244 statistics = cYAML_create_object(peer_ni, "statistics");
3245 if (statistics == NULL)
3248 if (cYAML_create_number(statistics, "send_count",
3249 lpni_stats->iel_send_count)
3253 if (cYAML_create_number(statistics, "recv_count",
3254 lpni_stats->iel_recv_count)
3258 if (cYAML_create_number(statistics, "drop_count",
3259 lpni_stats->iel_drop_count)
3266 for (k = 0; k < 3; k++) {
3267 struct lnet_ioctl_comm_count *counts;
3269 msg_statistics = cYAML_create_object(peer_ni,
3270 (char *) gmsg_stat_names[k]);
3271 if (msg_statistics == NULL)
3274 counts = get_counts(msg_stats, k);
3278 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3283 yhstats = cYAML_create_object(peer_ni, "health stats");
3286 if (cYAML_create_number(yhstats, "health value",
3287 hstats->hlpni_health_value)
3290 if (cYAML_create_number(yhstats, "dropped",
3291 hstats->hlpni_remote_dropped)
3294 if (cYAML_create_number(yhstats, "timeout",
3295 hstats->hlpni_remote_timeout)
3298 if (cYAML_create_number(yhstats, "error",
3299 hstats->hlpni_remote_error)
3302 if (cYAML_create_number(yhstats, "network timeout",
3303 hstats->hlpni_network_timeout)
3306 if (cYAML_create_number(yhstats, "ping_count",
3307 hstats->hlpni_ping_count)
3311 if (cYAML_create_number(yhstats, "next_ping",
3312 hstats->hlpni_next_ping)
3319 /* print output iff show_rc is not provided */
3320 if (show_rc == NULL)
3321 cYAML_print_tree(root);
3323 snprintf(err_str, sizeof(err_str), "\"success\"");
3324 rc = LUSTRE_CFG_RC_NO_ERR;
3329 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3330 cYAML_free_tree(root);
3331 } else if (show_rc != NULL && *show_rc != NULL) {
3332 struct cYAML *show_node;
3333 /* find the peer node, if one doesn't exist then
3334 * insert one. Otherwise add to the one there
3336 show_node = cYAML_get_object_item(*show_rc,
3338 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3339 cYAML_insert_child(show_node, first_seq);
3342 } else if (show_node == NULL) {
3343 cYAML_insert_sibling((*show_rc)->cy_child,
3347 cYAML_free_tree(root);
3353 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3359 int lustre_lnet_list_peer(int seq_no,
3360 struct cYAML **show_rc, struct cYAML **err_rc)
3362 struct lnet_ioctl_peer_cfg peer_info;
3363 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3368 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3369 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3370 struct lnet_process_id *list = NULL;
3372 memset(&peer_info, 0, sizeof(peer_info));
3374 /* create struct cYAML root object */
3375 root = cYAML_create_object(NULL, NULL);
3379 list_root = cYAML_create_seq(root, "peer list");
3380 if (list_root == NULL)
3384 size = count * sizeof(struct lnet_process_id);
3385 list = malloc(size);
3391 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3392 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3393 peer_info.prcfg_size = size;
3394 peer_info.prcfg_bulk = list;
3397 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3398 count = peer_info.prcfg_count;
3402 if (l_errno != E2BIG) {
3405 "\"cannot get peer list: %s\"",
3411 size = peer_info.prcfg_size;
3412 list = malloc(size);
3419 /* count is now the actual number of ids in the list. */
3420 for (i = 0; i < count; i++) {
3421 if (cYAML_create_string(list_root, "nid",
3422 libcfs_nid2str(list[i].nid))
3427 /* print output iff show_rc is not provided */
3428 if (show_rc == NULL)
3429 cYAML_print_tree(root);
3431 snprintf(err_str, sizeof(err_str), "\"success\"");
3432 rc = LUSTRE_CFG_RC_NO_ERR;
3437 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3438 cYAML_free_tree(root);
3439 } else if (show_rc != NULL && *show_rc != NULL) {
3440 struct cYAML *show_node;
3441 /* find the peer node, if one doesn't exist then
3442 * insert one. Otherwise add to the one there
3444 show_node = cYAML_get_object_item(*show_rc,
3446 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3447 cYAML_insert_child(show_node, first_seq);
3450 } else if (show_node == NULL) {
3451 cYAML_insert_sibling((*show_rc)->cy_child,
3455 cYAML_free_tree(root);
3461 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3467 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3470 struct cYAML *show_node;
3472 show_node = cYAML_get_object_item(show_rc, "global");
3473 if (show_node != NULL)
3474 cYAML_insert_sibling(show_node->cy_child,
3477 cYAML_insert_sibling(show_rc->cy_child,
3482 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3483 char *name, __u64 value,
3484 struct cYAML **show_rc,
3485 struct cYAML **err_rc, int err)
3487 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3488 struct cYAML *root = NULL, *global = NULL;
3495 root = cYAML_create_object(NULL, NULL);
3499 global = cYAML_create_object(root, "global");
3503 if (cYAML_create_number(global, name,
3507 if (show_rc == NULL)
3508 cYAML_print_tree(root);
3510 snprintf(err_str, err_len, "\"success\"");
3512 rc = LUSTRE_CFG_RC_NO_ERR;
3515 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3516 cYAML_free_tree(root);
3517 } else if (show_rc != NULL && *show_rc != NULL) {
3518 add_to_global(*show_rc, global, root);
3523 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3528 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3529 struct cYAML **show_rc,
3530 struct cYAML **err_rc)
3532 struct lnet_ioctl_set_value data;
3535 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3537 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3539 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3544 "\"cannot get %s: %s\"",
3545 name, strerror(l_errno));
3548 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3549 data.sv_value, show_rc, err_rc, l_errno);
3552 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3553 struct cYAML **err_rc)
3555 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3556 char val[LNET_MAX_STR_LEN];
3557 int intrv = -1, l_errno = 0;
3558 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3560 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3564 snprintf(err_str, sizeof(err_str),
3565 "\"cannot get recovery interval: %d\"", rc);
3570 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3571 "recovery_interval", intrv, show_rc,
3575 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3576 struct cYAML **err_rc)
3578 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3579 char val[LNET_MAX_STR_LEN];
3580 int sen = -1, l_errno = 0;
3581 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3583 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3587 snprintf(err_str, sizeof(err_str),
3588 "\"cannot get health sensitivity: %d\"", rc);
3593 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3594 "health_sensitivity", sen, show_rc,
3598 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3599 struct cYAML **err_rc)
3601 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3602 char val[LNET_MAX_STR_LEN];
3603 int sen = -1, l_errno = 0;
3604 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3606 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3610 snprintf(err_str, sizeof(err_str),
3611 "\"cannot get router sensitivity percentage: %d\"", rc);
3616 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3617 "router_sensitivity", sen, show_rc,
3621 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3622 struct cYAML **err_rc)
3624 char val[LNET_MAX_STR_LEN];
3625 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3632 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3635 snprintf(err_str, sizeof(err_str),
3636 "\"cannot get LND timeout: %d\"", rc);
3637 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3638 "lnd_timeout", lnd_to, show_rc,
3642 fd = open(path.gl_pathv[0], O_RDONLY);
3645 snprintf(err_str, sizeof(err_str),
3646 "\"error opening %s\"", path.gl_pathv[0]);
3650 rc = read(fd, val, sizeof(val));
3657 snprintf(err_str, sizeof(err_str),
3658 "\"error reading %s\"", path.gl_pathv[0]);
3665 cfs_free_param_data(&path);
3667 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3668 "lnd_timeout", lnd_to, show_rc,
3672 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3673 struct cYAML **err_rc)
3675 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3676 char val[LNET_MAX_STR_LEN];
3677 int tto = -1, l_errno = 0;
3678 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3680 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3684 snprintf(err_str, sizeof(err_str),
3685 "\"cannot get transaction timeout: %d\"", rc);
3690 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3691 "transaction_timeout", tto, show_rc,
3695 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3696 struct cYAML **err_rc)
3698 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3699 char val[LNET_MAX_STR_LEN];
3700 int retry_count = -1, l_errno = 0;
3701 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3703 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3707 snprintf(err_str, sizeof(err_str),
3708 "\"cannot get retry count: %d\"", rc);
3710 retry_count = atoi(val);
3713 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3714 "retry_count", retry_count, show_rc,
3718 int lustre_lnet_calc_service_id(__u64 *service_id)
3720 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3721 char val[LNET_MAX_STR_LEN];
3722 int service_port = -1, l_errno = 0;
3724 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3728 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3729 strerror(l_errno), -l_errno);
3732 service_port = atoi(val);
3735 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3737 return LUSTRE_CFG_RC_NO_ERR;
3740 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3743 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3745 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3746 struct lnet_ioctl_config_ni *ni_data;
3747 struct lnet_ioctl_config_lnd_tunables *lnd;
3748 struct lnet_ioctl_element_stats *stats;
3749 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3750 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3751 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3752 int if_cnt = 0, prc;
3753 char syscmdbuf[LNET_MAX_STR_LEN];
3754 char cmdpath[LNET_MAX_STR_LEN];
3755 bool use_custom = false;
3757 buf = calloc(1, buf_size);
3761 ni_data = (struct lnet_ioctl_config_ni *)buf;
3764 ifstr_ptr = ifstr_buf;
3769 memset(buf, 0, buf_size);
3771 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3772 /* set the ioc_len to the proper value since INIT assumes
3775 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3776 ni_data->lic_idx = i;
3778 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3784 rc_net = LNET_NIDNET(ni_data->lic_nid);
3786 /* only need to setup routing for tcp */
3787 if (LNET_NETTYP(rc_net) != SOCKLND)
3790 /* don't add interfaces unless there is at least one
3793 if (strlen(ni_data->lic_ni_intf) > 0) {
3795 strcat(ifstr_ptr, ",");
3796 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3801 if (l_errno != ENOENT) {
3804 "\"cannot get networks: %s\"",
3809 rc = LUSTRE_CFG_RC_NO_ERR;
3812 snprintf(err_str, sizeof(err_str), "\"success\"");
3815 tmp_ptr = getenv("KSOCKLND_CONFIG");
3817 tmp_ptr2 = strrchr(tmp_ptr, '/');
3818 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3819 snprintf(cmdpath, sizeof(cmdpath), "%s",
3826 snprintf(cmdpath, sizeof(cmdpath),
3827 "/usr/sbin/ksocklnd-config");
3829 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3835 "\"snprintf failed : %s\"",
3838 } else if (prc >= LNET_MAX_STR_LEN) {
3839 snprintf(err_str, sizeof(err_str),
3840 "\"ksocklnd-config: argument too long\"");
3842 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3843 cmdpath, ifstr_ptr);
3849 "\"snprintf failed : %s\"",
3855 rc = system(syscmdbuf);
3860 "\"failed to execute ksocklnd-config : %s\"",
3870 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3877 lnet_nid_cpt_hash(lnet_nid_t nid, long int number)
3880 __u64 pair_bits = 0x0001000100010001LLU;
3881 __u64 mask = pair_bits * 0xFF;
3887 pair_sum = (key & mask) + ((key >> 8) & mask);
3888 pair_sum = (pair_sum * pair_bits) >> 48;
3890 return (unsigned int)(pair_sum) % number;
3893 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3895 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3899 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3904 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3908 nid = libcfs_str2nid(nidc);
3909 if (nid == LNET_NID_ANY) {
3910 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3915 return (int)lnet_nid_cpt_hash(nid, ncpts);
3918 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3919 struct cYAML **show_rc, struct cYAML **err_rc)
3921 struct lnet_ioctl_recovery_list nid_list;
3922 struct cYAML *root = NULL, *nids = NULL;
3924 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3926 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3927 nid_list.rlst_type = type;
3929 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3935 if (nid_list.rlst_num_nids == 0)
3938 root = cYAML_create_object(NULL, NULL);
3942 nids = cYAML_create_object(root, name);
3948 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3949 char nidenum[LNET_MAX_STR_LEN];
3950 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3951 if (!cYAML_create_string(nids, nidenum,
3952 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3956 snprintf(err_str, sizeof(err_str), "success\n");
3961 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3962 cYAML_free_tree(root);
3963 } else if (show_rc != NULL && *show_rc != NULL) {
3964 struct cYAML *show_node;
3965 /* find the net node, if one doesn't exist
3966 * then insert one. Otherwise add to the one there
3968 show_node = cYAML_get_object_item(*show_rc, name);
3969 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3970 cYAML_insert_child(show_node, nids);
3973 } else if (show_node == NULL) {
3974 cYAML_insert_sibling((*show_rc)->cy_child,
3978 cYAML_free_tree(root);
3984 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3989 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3990 struct cYAML **err_rc)
3992 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3993 seq_no, show_rc, err_rc);
3996 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3997 struct cYAML **err_rc)
3999 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4000 seq_no, show_rc, err_rc);
4003 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4004 struct cYAML **err_rc)
4006 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4007 char val[LNET_MAX_STR_LEN];
4008 int rsp_tracking = -1, l_errno = 0;
4009 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4011 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4015 snprintf(err_str, sizeof(err_str),
4016 "\"cannot get lnet_response_tracking value: %d\"", rc);
4018 rsp_tracking = atoi(val);
4021 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4022 "response_tracking", rsp_tracking,
4023 show_rc, err_rc, l_errno);
4026 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4027 struct cYAML **err_rc)
4029 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4030 char val[LNET_MAX_STR_LEN];
4031 int recov_limit = -1, l_errno = 0;
4032 char err_str[LNET_MAX_STR_LEN];
4034 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4036 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4040 snprintf(err_str, sizeof(err_str),
4041 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4043 recov_limit = atoi(val);
4046 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4047 "recovery_limit", recov_limit,
4048 show_rc, err_rc, l_errno);
4051 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4052 struct cYAML **show_rc,
4053 struct cYAML **err_rc)
4055 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4056 char val[LNET_MAX_STR_LEN];
4057 int interval = -1, l_errno = 0;
4058 char err_str[LNET_MAX_STR_LEN];
4060 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4062 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4063 val, 1, sizeof(val));
4066 snprintf(err_str, sizeof(err_str),
4067 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4070 interval = atoi(val);
4073 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4074 "max_recovery_ping_interval", interval,
4075 show_rc, err_rc, l_errno);
4079 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4080 struct cYAML **err_rc)
4082 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4083 char val[LNET_MAX_STR_LEN];
4084 int max_intf = -1, l_errno = 0;
4085 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4087 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4091 snprintf(err_str, sizeof(err_str),
4092 "\"cannot get max interfaces: %d\"", rc);
4094 max_intf = atoi(val);
4097 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4098 "max_interfaces", max_intf, show_rc,
4102 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4103 struct cYAML **err_rc)
4105 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4106 char val[LNET_MAX_STR_LEN];
4107 int discovery = -1, l_errno = 0;
4108 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4110 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4114 snprintf(err_str, sizeof(err_str),
4115 "\"cannot get discovery setting: %d\"", rc);
4118 * The kernel stores a discovery disabled value. User space
4119 * shows whether discovery is enabled. So the value must be
4122 discovery = !atoi(val);
4125 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4126 "discovery", discovery, show_rc,
4130 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4131 struct cYAML **err_rc)
4133 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4134 char val[LNET_MAX_STR_LEN];
4135 int drop_asym_route = -1, l_errno = 0;
4136 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4138 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4142 snprintf(err_str, sizeof(err_str),
4143 "\"cannot get drop asym route setting: %d\"", rc);
4145 drop_asym_route = atoi(val);
4148 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4149 "drop_asym_route", drop_asym_route,
4150 show_rc, err_rc, l_errno);
4153 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4154 struct cYAML **err_rc)
4156 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4157 "numa_range", show_rc, err_rc);
4160 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4161 struct cYAML **err_rc)
4163 struct lnet_ioctl_lnet_stats data;
4164 struct lnet_counters *cntrs;
4167 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4168 struct cYAML *root = NULL, *stats = NULL;
4170 LIBCFS_IOC_INIT_V2(data, st_hdr);
4172 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4177 "\"cannot get lnet statistics: %s\"",
4183 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4185 cntrs = &data.st_cntrs;
4187 root = cYAML_create_object(NULL, NULL);
4191 stats = cYAML_create_object(root, "statistics");
4195 if (!cYAML_create_number(stats, "msgs_alloc",
4196 cntrs->lct_common.lcc_msgs_alloc))
4199 if (!cYAML_create_number(stats, "msgs_max",
4200 cntrs->lct_common.lcc_msgs_max))
4203 if (!cYAML_create_number(stats, "rst_alloc",
4204 cntrs->lct_health.lch_rst_alloc))
4207 if (!cYAML_create_number(stats, "errors",
4208 cntrs->lct_common.lcc_errors))
4211 if (!cYAML_create_number(stats, "send_count",
4212 cntrs->lct_common.lcc_send_count))
4215 if (!cYAML_create_number(stats, "resend_count",
4216 cntrs->lct_health.lch_resend_count))
4219 if (!cYAML_create_number(stats, "response_timeout_count",
4220 cntrs->lct_health.lch_response_timeout_count))
4223 if (!cYAML_create_number(stats, "local_interrupt_count",
4224 cntrs->lct_health.lch_local_interrupt_count))
4227 if (!cYAML_create_number(stats, "local_dropped_count",
4228 cntrs->lct_health.lch_local_dropped_count))
4231 if (!cYAML_create_number(stats, "local_aborted_count",
4232 cntrs->lct_health.lch_local_aborted_count))
4235 if (!cYAML_create_number(stats, "local_no_route_count",
4236 cntrs->lct_health.lch_local_no_route_count))
4239 if (!cYAML_create_number(stats, "local_timeout_count",
4240 cntrs->lct_health.lch_local_timeout_count))
4243 if (!cYAML_create_number(stats, "local_error_count",
4244 cntrs->lct_health.lch_local_error_count))
4247 if (!cYAML_create_number(stats, "remote_dropped_count",
4248 cntrs->lct_health.lch_remote_dropped_count))
4251 if (!cYAML_create_number(stats, "remote_error_count",
4252 cntrs->lct_health.lch_remote_error_count))
4255 if (!cYAML_create_number(stats, "remote_timeout_count",
4256 cntrs->lct_health.lch_remote_timeout_count))
4259 if (!cYAML_create_number(stats, "network_timeout_count",
4260 cntrs->lct_health.lch_network_timeout_count))
4263 if (!cYAML_create_number(stats, "recv_count",
4264 cntrs->lct_common.lcc_recv_count))
4267 if (!cYAML_create_number(stats, "route_count",
4268 cntrs->lct_common.lcc_route_count))
4271 if (!cYAML_create_number(stats, "drop_count",
4272 cntrs->lct_common.lcc_drop_count))
4275 if (!cYAML_create_number(stats, "send_length",
4276 cntrs->lct_common.lcc_send_length))
4279 if (!cYAML_create_number(stats, "recv_length",
4280 cntrs->lct_common.lcc_recv_length))
4283 if (!cYAML_create_number(stats, "route_length",
4284 cntrs->lct_common.lcc_route_length))
4287 if (!cYAML_create_number(stats, "drop_length",
4288 cntrs->lct_common.lcc_drop_length))
4292 cYAML_print_tree(root);
4294 snprintf(err_str, sizeof(err_str), "\"success\"");
4295 rc = LUSTRE_CFG_RC_NO_ERR;
4297 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4298 cYAML_free_tree(root);
4299 } else if (show_rc != NULL && *show_rc != NULL) {
4300 cYAML_insert_sibling((*show_rc)->cy_child,
4307 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4312 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4314 struct libcfs_ioctl_data data;
4315 int rc = LUSTRE_CFG_RC_NO_ERR;
4317 char err_str[LNET_MAX_STR_LEN];
4319 LIBCFS_IOC_INIT(data);
4321 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4326 "\"cannot reset lnet statistics: %s\"",
4330 snprintf(err_str, sizeof(err_str), "\"success\"");
4331 rc = LUSTRE_CFG_RC_NO_ERR;
4334 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4338 typedef int (*cmd_handler_t)(struct cYAML *tree,
4339 struct cYAML **show_rc,
4340 struct cYAML **err_rc);
4342 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4343 struct cYAML **err_rc)
4345 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4347 net = cYAML_get_object_item(tree, "net");
4348 gw = cYAML_get_object_item(tree, "gateway");
4349 hop = cYAML_get_object_item(tree, "hop");
4350 prio = cYAML_get_object_item(tree, "priority");
4351 sen = cYAML_get_object_item(tree, "health_sensitivity");
4352 seq_no = cYAML_get_object_item(tree, "seq_no");
4354 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4355 (gw) ? gw->cy_valuestring : NULL,
4356 (hop) ? hop->cy_valueint : -1,
4357 (prio) ? prio->cy_valueint : -1,
4358 (sen) ? sen->cy_valueint : -1,
4359 (seq_no) ? seq_no->cy_valueint : -1,
4365 * 0: <intf_name>['['<expr>']']
4366 * 1: <intf_name>['['<expr>']']
4368 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4369 struct lnet_dlc_network_descr *nw_descr)
4371 struct cYAML *child = NULL;
4372 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4373 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4375 if (intf_tree == NULL || nw_descr == NULL)
4376 return LUSTRE_CFG_RC_BAD_PARAM;
4378 /* now grab all the interfaces and their cpts */
4379 child = intf_tree->cy_child;
4380 while (child != NULL) {
4381 if (child->cy_valuestring == NULL) {
4382 child = child->cy_next;
4386 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4389 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4390 child->cy_valuestring,
4391 strlen(child->cy_valuestring));
4392 if (rc != LUSTRE_CFG_RC_NO_ERR)
4396 child = child->cy_next;
4400 return LUSTRE_CFG_RC_MISSING_PARAM;
4405 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4407 list_del(&intf_descr->intf_on_network);
4408 free_intf_descr(intf_descr);
4415 yaml_extract_cmn_tunables(struct cYAML *tree,
4416 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4418 struct cYAML *tun, *item;
4420 tun = cYAML_get_object_item(tree, "tunables");
4422 item = cYAML_get_object_item(tun, "peer_timeout");
4424 tunables->lct_peer_timeout = item->cy_valueint;
4426 tunables->lct_peer_timeout = -1;
4427 item = cYAML_get_object_item(tun, "peer_credits");
4429 tunables->lct_peer_tx_credits = item->cy_valueint;
4430 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4432 tunables->lct_peer_rtr_credits = item->cy_valueint;
4433 item = cYAML_get_object_item(tun, "credits");
4435 tunables->lct_max_tx_credits = item->cy_valueint;
4444 yaml_extract_tunables(struct cYAML *tree,
4445 struct lnet_ioctl_config_lnd_tunables *tunables,
4450 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4455 lustre_yaml_extract_lnd_tunables(tree, net_type,
4462 yaml_extract_cpt(struct cYAML *tree,
4463 struct cfs_expr_list **global_cpts)
4468 smp = cYAML_get_object_item(tree, "CPT");
4470 rc = cfs_expr_list_parse(smp->cy_valuestring,
4471 strlen(smp->cy_valuestring),
4472 0, UINT_MAX, global_cpts);
4474 *global_cpts = NULL;
4480 * - net type: <net>[<NUM>]
4482 * - nid: <ip>@<net>[<NUM>]
4485 * 0: <intf_name>['['<expr>']']
4486 * 1: <intf_name>['['<expr>']']
4488 * peer_timeout: <NUM>
4489 * peer_credits: <NUM>
4490 * peer_buffer_credits: <NUM>
4493 * peercredits_hiw: <NUM>
4494 * map_on_demand: <NUM>
4495 * concurrent_sends: <NUM>
4496 * fmr_pool_size: <NUM>
4497 * fmr_flush_trigger: <NUM>
4500 * At least one interface is required. If no interfaces are provided the
4501 * network interface can not be configured.
4503 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4504 struct cYAML **err_rc)
4506 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4508 int num_entries = 0, rc;
4509 struct lnet_dlc_network_descr nw_descr;
4510 struct cfs_expr_list *global_cpts = NULL;
4511 struct lnet_ioctl_config_lnd_tunables tunables;
4514 memset(&tunables, 0, sizeof(tunables));
4516 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4517 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4519 ip2net = cYAML_get_object_item(tree, "ip2net");
4520 net = cYAML_get_object_item(tree, "net type");
4522 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4524 nw_descr.nw_id = LOLND;
4527 * if neither net nor ip2nets are present, then we can not
4528 * configure the network.
4530 if (!net && !ip2net)
4531 return LUSTRE_CFG_RC_MISSING_PARAM;
4533 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4534 if (local_nis == NULL)
4535 return LUSTRE_CFG_RC_MISSING_PARAM;
4537 if (!cYAML_is_sequence(local_nis))
4538 return LUSTRE_CFG_RC_BAD_PARAM;
4540 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4541 intf = cYAML_get_object_item(item, "interfaces");
4544 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4545 if (num_entries <= 0) {
4546 cYAML_build_error(num_entries, -1, "ni", "add",
4547 "bad interface list",
4549 return LUSTRE_CFG_RC_BAD_PARAM;
4553 found = yaml_extract_tunables(tree, &tunables,
4554 LNET_NETTYP(nw_descr.nw_id));
4555 yaml_extract_cpt(tree, &global_cpts);
4556 seq_no = cYAML_get_object_item(tree, "seq_no");
4558 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4559 (ip2net) ? ip2net->cy_valuestring : NULL,
4560 (found) ? &tunables : NULL, -1,
4561 (seq_no) ? seq_no->cy_valueint : -1,
4564 if (global_cpts != NULL)
4565 cfs_expr_list_free(global_cpts);
4572 * - net-spec: <tcp|o2ib|gni>[NUM]
4574 * 0: <intf name>['['<expr>']']
4575 * 1: <intf name>['['<expr>']']
4577 * 0: <expr.expr.expr.expr>
4578 * 1: <expr.expr.expr.expr>
4580 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4581 struct cYAML **show_rc,
4582 struct cYAML **err_rc)
4584 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4586 struct lustre_lnet_ip2nets ip2nets;
4587 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4589 int rc = LUSTRE_CFG_RC_NO_ERR;
4590 struct cfs_expr_list *global_cpts = NULL;
4591 struct cfs_expr_list *el, *el_tmp;
4592 struct lnet_ioctl_config_lnd_tunables tunables;
4593 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4596 memset(&tunables, 0, sizeof(tunables));
4598 /* initialize all lists */
4599 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4600 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4601 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4603 net = cYAML_get_object_item(tree, "net-spec");
4605 return LUSTRE_CFG_RC_BAD_PARAM;
4607 if (net != NULL && net->cy_valuestring == NULL)
4608 return LUSTRE_CFG_RC_BAD_PARAM;
4610 /* assign the network id */
4611 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4612 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4613 return LUSTRE_CFG_RC_BAD_PARAM;
4615 seq_no = cYAML_get_object_item(tree, "seq_no");
4617 intf = cYAML_get_object_item(tree, "interfaces");
4619 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4621 return LUSTRE_CFG_RC_BAD_PARAM;
4624 ip_range = cYAML_get_object_item(tree, "ip-range");
4625 if (ip_range != NULL) {
4626 item = ip_range->cy_child;
4627 while (item != NULL) {
4628 if (item->cy_valuestring == NULL) {
4629 item = item->cy_next;
4633 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4634 item->cy_valuestring);
4636 if (rc != LUSTRE_CFG_RC_NO_ERR)
4639 item = item->cy_next;
4643 found = yaml_extract_tunables(tree, &tunables,
4644 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4645 yaml_extract_cpt(tree, &global_cpts);
4647 rc = lustre_lnet_config_ip2nets(&ip2nets,
4648 (found) ? &tunables : NULL,
4650 (seq_no) ? seq_no->cy_valueint : -1,
4653 if (global_cpts != NULL)
4654 cfs_expr_list_free(global_cpts);
4657 * don't stop because there was no match. Continue processing the
4658 * rest of the rules. If non-match then nothing is configured
4660 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4661 rc = LUSTRE_CFG_RC_NO_ERR;
4663 list_for_each_entry_safe(intf_descr, intf_tmp,
4664 &ip2nets.ip2nets_net.nw_intflist,
4666 list_del(&intf_descr->intf_on_network);
4667 free_intf_descr(intf_descr);
4670 list_for_each_entry_safe(ip_range_descr, tmp,
4671 &ip2nets.ip2nets_ip_ranges,
4673 list_del(&ip_range_descr->ipr_entry);
4674 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4676 list_del(&el->el_link);
4677 cfs_expr_list_free(el);
4679 free(ip_range_descr);
4685 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4686 struct cYAML **err_rc)
4688 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4690 int num_entries, rc;
4691 struct lnet_dlc_network_descr nw_descr;
4693 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4694 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4696 net = cYAML_get_object_item(tree, "net type");
4698 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4700 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4701 if (local_nis == NULL)
4702 return LUSTRE_CFG_RC_MISSING_PARAM;
4704 if (!cYAML_is_sequence(local_nis))
4705 return LUSTRE_CFG_RC_BAD_PARAM;
4707 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4708 intf = cYAML_get_object_item(item, "interfaces");
4711 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4712 if (num_entries <= 0) {
4713 cYAML_build_error(num_entries, -1, "ni", "add",
4714 "bad interface list",
4716 return LUSTRE_CFG_RC_BAD_PARAM;
4720 seq_no = cYAML_get_object_item(tree, "seq_no");
4722 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4723 (seq_no) ? seq_no->cy_valueint : -1,
4729 /* Create a nidstring parseable by the nidstrings library from the nid
4730 * information encoded in the CYAML structure.
4731 * NOTE: Caller must free memory allocated to nidstr
4733 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4734 char *prim_nid, int cmd)
4736 int num_strs = 0, rc;
4737 size_t buf_size, buf_pos, nidstr_len = 0;
4739 struct cYAML *child = NULL, *entry = NULL;
4741 if (cYAML_is_sequence(nids_entry)) {
4742 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4743 entry = cYAML_get_object_item(child, "nid");
4744 /* don't count an empty entry */
4745 if (!entry || !entry->cy_valuestring)
4749 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4750 if (cmd == LNETCTL_DEL_CMD) {
4752 * primary nid is present in the list of
4753 * nids so that means we want to delete
4754 * the entire peer, so no need to go
4755 * further. Just delete the entire peer.
4757 return LUSTRE_CFG_RC_NO_ERR;
4764 * + 1 for the space separating each string, and
4765 * accounts for the terminating null char
4767 nidstr_len += strlen(entry->cy_valuestring) + 1;
4772 if (num_strs == 0 && !prim_nid)
4773 return LUSTRE_CFG_RC_MISSING_PARAM;
4774 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4775 return LUSTRE_CFG_RC_NO_ERR;
4777 buffer = malloc(nidstr_len);
4779 return LUSTRE_CFG_RC_OUT_OF_MEM;
4781 /* now grab all the nids */
4784 buf_size = nidstr_len;
4786 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4787 entry = cYAML_get_object_item(child, "nid");
4788 if (!entry || !entry->cy_valuestring)
4792 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4796 rc = snprintf(buffer + buf_pos, buf_size, " ");
4797 buf_pos += (rc < buf_size) ? rc : buf_size;
4798 buf_size = nidstr_len - buf_pos;
4801 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4802 entry->cy_valuestring);
4803 buf_pos += (rc < buf_size) ? rc : buf_size;
4804 buf_size = nidstr_len - buf_pos;
4809 return LUSTRE_CFG_RC_NO_ERR;
4812 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4813 struct cYAML **err_rc, int cmd)
4815 int rc, num_nids = 0, seqn;
4816 bool mr_value = false;
4817 char *nidstr = NULL, *prim_nidstr;
4818 char err_str[LNET_MAX_STR_LEN];
4819 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4820 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4821 lnet_nid_t pnid = LNET_NID_ANY;
4823 seq_no = cYAML_get_object_item(tree, "seq_no");
4824 seqn = seq_no ? seq_no->cy_valueint : -1;
4826 prim_nid = cYAML_get_object_item(tree, "primary nid");
4827 peer_nis = cYAML_get_object_item(tree, "peer ni");
4829 rc = LUSTRE_CFG_RC_BAD_PARAM;
4830 snprintf(err_str, LNET_MAX_STR_LEN,
4831 "\"primary nid\" must be specified");
4835 prim_nidstr = prim_nid->cy_valuestring;
4837 /* if the provided primary NID is bad, no need to go any further */
4838 pnid = libcfs_str2nid(prim_nidstr);
4839 if (pnid == LNET_NID_ANY) {
4840 rc = LUSTRE_CFG_RC_BAD_PARAM;
4841 snprintf(err_str, LNET_MAX_STR_LEN,
4842 "badly formatted primary NID: %s", prim_nidstr);
4846 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4847 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4848 snprintf(err_str, LNET_MAX_STR_LEN,
4849 "No nids defined in YAML block");
4851 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4852 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4854 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4855 snprintf(err_str, LNET_MAX_STR_LEN,
4856 "Unrecognized error %d", rc);
4862 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4863 LNET_MAX_NIDS_PER_PEER,
4871 if (cmd == LNETCTL_ADD_CMD) {
4872 mr = cYAML_get_object_item(tree, "Multi-Rail");
4874 if (mr && mr->cy_valuestring) {
4875 if (strcmp(mr->cy_valuestring, "False") == 0)
4877 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4878 rc = LUSTRE_CFG_RC_BAD_PARAM;
4879 snprintf(err_str, LNET_MAX_STR_LEN,
4880 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4881 mr->cy_valuestring);
4887 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4888 num_nids, mr_value, seqn,
4895 if (rc != LUSTRE_CFG_RC_NO_ERR)
4896 cYAML_build_error(rc, seqn, "peer",
4897 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4903 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4904 struct cYAML **err_rc)
4906 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4909 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4910 struct cYAML **err_rc)
4912 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4915 static int handle_yaml_config_buffers(struct cYAML *tree,
4916 struct cYAML **show_rc,
4917 struct cYAML **err_rc)
4920 struct cYAML *tiny, *small, *large, *seq_no;
4922 tiny = cYAML_get_object_item(tree, "tiny");
4923 small = cYAML_get_object_item(tree, "small");
4924 large = cYAML_get_object_item(tree, "large");
4925 seq_no = cYAML_get_object_item(tree, "seq_no");
4927 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4928 (small) ? small->cy_valueint : -1,
4929 (large) ? large->cy_valueint : -1,
4930 (seq_no) ? seq_no->cy_valueint : -1,
4936 static int handle_yaml_config_routing(struct cYAML *tree,
4937 struct cYAML **show_rc,
4938 struct cYAML **err_rc)
4940 int rc = LUSTRE_CFG_RC_NO_ERR;
4941 struct cYAML *seq_no, *enable;
4943 seq_no = cYAML_get_object_item(tree, "seq_no");
4944 enable = cYAML_get_object_item(tree, "enable");
4947 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4949 seq_no->cy_valueint : -1,
4956 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4957 struct cYAML **err_rc)
4961 struct cYAML *seq_no;
4963 net = cYAML_get_object_item(tree, "net");
4964 gw = cYAML_get_object_item(tree, "gateway");
4965 seq_no = cYAML_get_object_item(tree, "seq_no");
4967 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4968 (gw) ? gw->cy_valuestring : NULL,
4969 (seq_no) ? seq_no->cy_valueint : -1,
4973 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4974 struct cYAML **err_rc)
4976 struct cYAML *seq_no;
4978 seq_no = cYAML_get_object_item(tree, "seq_no");
4980 return lustre_lnet_enable_routing(0, (seq_no) ?
4981 seq_no->cy_valueint : -1,
4985 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4986 struct cYAML **err_rc)
4992 struct cYAML *detail;
4993 struct cYAML *seq_no;
4995 net = cYAML_get_object_item(tree, "net");
4996 gw = cYAML_get_object_item(tree, "gateway");
4997 hop = cYAML_get_object_item(tree, "hop");
4998 prio = cYAML_get_object_item(tree, "priority");
4999 detail = cYAML_get_object_item(tree, "detail");
5000 seq_no = cYAML_get_object_item(tree, "seq_no");
5002 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5003 (gw) ? gw->cy_valuestring : NULL,
5004 (hop) ? hop->cy_valueint : -1,
5005 (prio) ? prio->cy_valueint : -1,
5006 (detail) ? detail->cy_valueint : 0,
5007 (seq_no) ? seq_no->cy_valueint : -1,
5008 show_rc, err_rc, false);
5011 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5012 struct cYAML **err_rc)
5014 struct cYAML *net, *detail, *seq_no;
5016 net = cYAML_get_object_item(tree, "net");
5017 detail = cYAML_get_object_item(tree, "detail");
5018 seq_no = cYAML_get_object_item(tree, "seq_no");
5020 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5021 (detail) ? detail->cy_valueint : 0,
5022 (seq_no) ? seq_no->cy_valueint : -1,
5023 show_rc, err_rc, false);
5026 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5027 struct cYAML **err_rc)
5029 struct cYAML *seq_no;
5031 seq_no = cYAML_get_object_item(tree, "seq_no");
5033 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5034 show_rc, err_rc, false);
5037 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5038 struct cYAML **err_rc)
5040 struct cYAML *seq_no, *nid, *detail;
5042 seq_no = cYAML_get_object_item(tree, "seq_no");
5043 detail = cYAML_get_object_item(tree, "detail");
5044 nid = cYAML_get_object_item(tree, "nid");
5046 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5047 (detail) ? detail->cy_valueint : 0,
5048 (seq_no) ? seq_no->cy_valueint : -1,
5049 show_rc, err_rc, false);
5052 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5053 struct cYAML **err_rc)
5055 struct cYAML *seq_no;
5057 seq_no = cYAML_get_object_item(tree, "seq_no");
5059 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5063 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5064 struct cYAML **err_rc)
5066 struct cYAML *seq_no, *range;
5068 seq_no = cYAML_get_object_item(tree, "seq_no");
5069 range = cYAML_get_object_item(tree, "range");
5071 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5072 seq_no ? seq_no->cy_valueint : -1,
5076 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5077 struct cYAML **err_rc)
5079 struct cYAML *seq_no;
5081 seq_no = cYAML_get_object_item(tree, "seq_no");
5083 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5087 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5088 struct cYAML **err_rc)
5090 struct cYAML *seq_no;
5092 seq_no = cYAML_get_object_item(tree, "seq_no");
5094 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5098 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5099 struct cYAML **err_rc)
5101 struct cYAML *seq_no, *idx;
5103 seq_no = cYAML_get_object_item(tree, "seq_no");
5104 idx = cYAML_get_object_item(tree, "idx");
5106 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5107 seq_no ? seq_no->cy_valueint : -1,
5111 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5112 struct cYAML **err_rc)
5114 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5115 union lnet_udsp_action action;
5117 seq_no = cYAML_get_object_item(tree, "seq_no");
5118 src = cYAML_get_object_item(tree, "src");
5119 rte = cYAML_get_object_item(tree, "rte");
5120 dst = cYAML_get_object_item(tree, "dst");
5121 prio = cYAML_get_object_item(tree, "priority");
5122 idx = cYAML_get_object_item(tree, "idx");
5124 action.udsp_priority = prio ? prio->cy_valueint : -1;
5126 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5127 dst ? dst->cy_valuestring : NULL,
5128 rte ? rte->cy_valuestring : NULL,
5129 prio ? "priority" : "",
5131 idx ? idx->cy_valueint : -1,
5132 seq_no ? seq_no->cy_valueint : -1,
5136 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5137 struct cYAML **err_rc)
5139 struct cYAML *seq_no;
5142 seq_no = cYAML_get_object_item(tree, "seq_no");
5143 idx = cYAML_get_object_item(tree, "idx");
5145 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5146 seq_no ? seq_no->cy_valueint : -1,
5150 static int handle_yaml_config_global_settings(struct cYAML *tree,
5151 struct cYAML **show_rc,
5152 struct cYAML **err_rc)
5154 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5155 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5159 seq_no = cYAML_get_object_item(tree, "seq_no");
5160 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5161 if (!max_intf) /* try legacy name */
5162 max_intf = cYAML_get_object_item(tree, "max_intf");
5164 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5165 seq_no ? seq_no->cy_valueint
5169 numa = cYAML_get_object_item(tree, "numa_range");
5171 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5172 seq_no ? seq_no->cy_valueint
5176 discovery = cYAML_get_object_item(tree, "discovery");
5178 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5179 seq_no ? seq_no->cy_valueint
5183 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5184 if (drop_asym_route)
5185 rc = lustre_lnet_config_drop_asym_route(
5186 drop_asym_route->cy_valueint,
5187 seq_no ? seq_no->cy_valueint : -1,
5190 retry = cYAML_get_object_item(tree, "retry_count");
5192 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5193 seq_no ? seq_no->cy_valueint
5197 tto = cYAML_get_object_item(tree, "transaction_timeout");
5199 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5200 seq_no ? seq_no->cy_valueint
5204 sen = cYAML_get_object_item(tree, "health_sensitivity");
5206 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5207 seq_no ? seq_no->cy_valueint
5211 recov = cYAML_get_object_item(tree, "recovery_interval");
5213 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5214 seq_no ? seq_no->cy_valueint
5218 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5220 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5221 seq_no ? seq_no->cy_valueint
5225 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5227 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5228 seq_no ? seq_no->cy_valueint
5232 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5234 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5235 seq_no ? seq_no->cy_valueint
5242 static int handle_yaml_del_global_settings(struct cYAML *tree,
5243 struct cYAML **show_rc,
5244 struct cYAML **err_rc)
5246 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5249 seq_no = cYAML_get_object_item(tree, "seq_no");
5250 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5251 if (!max_intf) /* try legacy name */
5252 max_intf = cYAML_get_object_item(tree, "max_intf");
5254 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5255 seq_no ? seq_no->cy_valueint
5259 numa = cYAML_get_object_item(tree, "numa_range");
5261 rc = lustre_lnet_config_numa_range(0,
5262 seq_no ? seq_no->cy_valueint
5266 /* peer discovery is enabled by default */
5267 discovery = cYAML_get_object_item(tree, "discovery");
5269 rc = lustre_lnet_config_discovery(1,
5270 seq_no ? seq_no->cy_valueint
5274 /* asymmetrical route messages are accepted by default */
5275 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5276 if (drop_asym_route)
5277 rc = lustre_lnet_config_drop_asym_route(
5278 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5283 static int handle_yaml_show_global_settings(struct cYAML *tree,
5284 struct cYAML **show_rc,
5285 struct cYAML **err_rc)
5287 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5288 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5292 seq_no = cYAML_get_object_item(tree, "seq_no");
5293 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5294 if (!max_intf) /* try legacy name */
5295 max_intf = cYAML_get_object_item(tree, "max_intf");
5297 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5301 numa = cYAML_get_object_item(tree, "numa_range");
5303 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5307 discovery = cYAML_get_object_item(tree, "discovery");
5309 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5313 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5314 if (drop_asym_route)
5315 rc = lustre_lnet_show_drop_asym_route(
5316 seq_no ? seq_no->cy_valueint : -1,
5319 retry = cYAML_get_object_item(tree, "retry_count");
5321 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5325 tto = cYAML_get_object_item(tree, "transaction_timeout");
5327 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5331 sen = cYAML_get_object_item(tree, "health_sensitivity");
5333 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5337 recov = cYAML_get_object_item(tree, "recovery_interval");
5339 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5343 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5345 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5349 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5351 rc = lustre_lnet_show_response_tracking(seq_no ?
5352 seq_no->cy_valueint :
5356 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5358 rc = lustre_lnet_show_recovery_limit(seq_no ?
5359 seq_no->cy_valueint :
5366 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5367 struct cYAML **err_rc)
5369 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5371 seq_no = cYAML_get_object_item(tree, "seq_no");
5372 nid = cYAML_get_object_item(tree, "primary nid");
5373 timeout = cYAML_get_object_item(tree, "timeout");
5374 src_nid = cYAML_get_object_item(tree, "source_nid");
5376 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5377 (src_nid) ? src_nid->cy_valuestring : NULL,
5378 (timeout) ? timeout->cy_valueint : 1000,
5379 (seq_no) ? seq_no->cy_valueint : -1,
5383 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5384 struct cYAML **err_rc)
5386 struct cYAML *seq_no, *nid, *force;
5388 seq_no = cYAML_get_object_item(tree, "seq_no");
5389 nid = cYAML_get_object_item(tree, "primary nid");
5390 force = cYAML_get_object_item(tree, "force");
5392 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5393 (force) ? force->cy_valueint : 0,
5394 (seq_no) ? seq_no->cy_valueint : -1,
5398 static int handle_yaml_no_op()
5400 return LUSTRE_CFG_RC_NO_ERR;
5403 struct lookup_cmd_hdlr_tbl {
5408 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5409 { .name = "route", .cb = handle_yaml_config_route },
5410 { .name = "net", .cb = handle_yaml_config_ni },
5411 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5412 { .name = "peer", .cb = handle_yaml_config_peer },
5413 { .name = "routing", .cb = handle_yaml_config_routing },
5414 { .name = "buffers", .cb = handle_yaml_config_buffers },
5415 { .name = "statistics", .cb = handle_yaml_no_op },
5416 { .name = "global", .cb = handle_yaml_config_global_settings},
5417 { .name = "numa", .cb = handle_yaml_config_numa },
5418 { .name = "ping", .cb = handle_yaml_no_op },
5419 { .name = "discover", .cb = handle_yaml_no_op },
5420 { .name = "udsp", .cb = handle_yaml_config_udsp },
5423 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5424 { .name = "route", .cb = handle_yaml_del_route },
5425 { .name = "net", .cb = handle_yaml_del_ni },
5426 { .name = "ip2nets", .cb = handle_yaml_no_op },
5427 { .name = "peer", .cb = handle_yaml_del_peer },
5428 { .name = "routing", .cb = handle_yaml_del_routing },
5429 { .name = "buffers", .cb = handle_yaml_no_op },
5430 { .name = "statistics", .cb = handle_yaml_no_op },
5431 { .name = "global", .cb = handle_yaml_del_global_settings},
5432 { .name = "numa", .cb = handle_yaml_del_numa },
5433 { .name = "ping", .cb = handle_yaml_no_op },
5434 { .name = "discover", .cb = handle_yaml_no_op },
5435 { .name = "udsp", .cb = handle_yaml_del_udsp },
5438 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5439 { .name = "route", .cb = handle_yaml_show_route },
5440 { .name = "net", .cb = handle_yaml_show_net },
5441 { .name = "peer", .cb = handle_yaml_show_peers },
5442 { .name = "ip2nets", .cb = handle_yaml_no_op },
5443 { .name = "routing", .cb = handle_yaml_show_routing },
5444 { .name = "buffers", .cb = handle_yaml_show_routing },
5445 { .name = "statistics", .cb = handle_yaml_show_stats },
5446 { .name = "global", .cb = handle_yaml_show_global_settings},
5447 { .name = "numa", .cb = handle_yaml_show_numa },
5448 { .name = "ping", .cb = handle_yaml_no_op },
5449 { .name = "discover", .cb = handle_yaml_no_op },
5450 { .name = "udsp", .cb = handle_yaml_show_udsp },
5453 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5454 { .name = "route", .cb = handle_yaml_no_op },
5455 { .name = "net", .cb = handle_yaml_no_op },
5456 { .name = "peer", .cb = handle_yaml_no_op },
5457 { .name = "ip2nets", .cb = handle_yaml_no_op },
5458 { .name = "routing", .cb = handle_yaml_no_op },
5459 { .name = "buffers", .cb = handle_yaml_no_op },
5460 { .name = "statistics", .cb = handle_yaml_no_op },
5461 { .name = "global", .cb = handle_yaml_no_op },
5462 { .name = "numa", .cb = handle_yaml_no_op },
5463 { .name = "ping", .cb = handle_yaml_ping },
5464 { .name = "discover", .cb = handle_yaml_discover },
5467 static cmd_handler_t lookup_fn(char *key,
5468 struct lookup_cmd_hdlr_tbl *tbl)
5474 for (i = 0; tbl[i].name != NULL; i++) {
5475 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5482 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5483 struct cYAML **show_rc, struct cYAML **err_rc)
5485 struct cYAML *tree, *item = NULL, *head, *child;
5487 char err_str[LNET_MAX_STR_LEN];
5488 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5490 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5492 return LUSTRE_CFG_RC_BAD_PARAM;
5494 child = tree->cy_child;
5495 while (child != NULL) {
5496 cb = lookup_fn(child->cy_string, table);
5498 snprintf(err_str, sizeof(err_str),
5499 "\"call back for '%s' not found\"",
5501 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5502 "yaml", "helper", err_str, err_rc);
5506 if (cYAML_is_sequence(child)) {
5507 while ((head = cYAML_get_next_seq_item(child, &item))
5509 rc = cb(head, show_rc, err_rc);
5510 if (rc != LUSTRE_CFG_RC_NO_ERR)
5514 rc = cb(child, show_rc, err_rc);
5515 if (rc != LUSTRE_CFG_RC_NO_ERR)
5519 child = child->cy_next;
5523 cYAML_free_tree(tree);
5528 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5530 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5534 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5536 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5540 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5542 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5546 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5548 return lustre_yaml_cb_helper(f, lookup_exec_tbl,