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, int option, __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;
649 data.prcfg_count = option;
651 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
657 /* Add or delete any specified NIs associated with the specified
658 * (or implied) primary nid
660 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
661 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
662 data.prcfg_mr = is_mr;
663 data.prcfg_prim_nid = nidlist[0];
664 data.prcfg_cfg_nid = nidlist[nid_idx];
665 data.prcfg_count = option;
667 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
673 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
674 /* In the delete case we may have been given just the
675 * primary nid of the peer. This tells us to delete the peer
676 * completely (rather than just delete some of its NIs)
678 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
679 data.prcfg_prim_nid = nidlist[0];
680 data.prcfg_cfg_nid = LNET_NID_ANY;
681 data.prcfg_count = option;
683 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
690 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
691 int cmd, int num_nids, bool is_mr, int option,
692 int seq_no, struct cYAML **err_rc)
694 int rc = LUSTRE_CFG_RC_NO_ERR;
695 char err_str[LNET_MAX_STR_LEN];
696 lnet_nid_t *lnet_nidlist2 = NULL;
697 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
698 IOC_LIBCFS_DEL_PEER_NI;
699 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
702 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
703 if (!lnet_nidlist2) {
704 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
705 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
708 lnet_nidlist2[0] = pnid;
709 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
712 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
713 num_nids, is_mr, option,
714 ioc_cmd, cmd_str, err_str);
719 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
724 replace_sep(char *str, char sep, char newsep)
730 for (i = 0; i < strlen(str); i++) {
731 /* don't replace ',' within [] */
734 else if (str[i] == ']')
736 else if (str[i] == sep && bracket == 0)
741 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr, int cmd,
742 int option, int seq_no, struct cYAML **err_rc)
745 char err_str[LNET_MAX_STR_LEN] = "Error";
746 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
747 lnet_nid_t pnid = LNET_NID_ANY;
750 rc = LUSTRE_CFG_RC_BAD_PARAM;
751 snprintf(err_str, LNET_MAX_STR_LEN,
752 "--prim_nid must be specified");
756 pnid = libcfs_str2nid(prim_nid);
757 if (pnid == LNET_NID_ANY) {
758 rc = LUSTRE_CFG_RC_BAD_PARAM;
759 snprintf(err_str, LNET_MAX_STR_LEN,
760 "badly formatted primary NID: %s", prim_nid);
767 * if there is no primary nid we need to make the first nid in the
768 * nids list the primary nid
770 replace_sep(nids, ',', ' ');
771 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
772 LNET_MAX_NIDS_PER_PEER, err_str);
779 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
780 cmd, num_nids, is_mr,
784 if (rc != LUSTRE_CFG_RC_NO_ERR)
785 cYAML_build_error(rc, -1, "peer",
786 cmd == LNETCTL_ADD_CMD ? "add" : "del",
792 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
793 int sen, int seq_no, struct cYAML **err_rc,
796 int rc, num_nids, idx;
798 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
799 struct lnet_ioctl_config_data data;
800 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
802 if (nw == NULL || nidstr == NULL) {
803 snprintf(err_str, LNET_MAX_STR_LEN,
804 "\"missing mandatory parameter:'%s'\"",
805 (nw == NULL && nidstr == NULL) ? "network, gateway" :
806 (nw == NULL) ? "network" : "gateway");
807 rc = LUSTRE_CFG_RC_MISSING_PARAM;
811 rnet = libcfs_str2net(nw);
812 if (rnet == LNET_NET_ANY) {
813 snprintf(err_str, LNET_MAX_STR_LEN,
814 "\"cannot parse remote net %s\"", nw);
815 rc = LUSTRE_CFG_RC_BAD_PARAM;
819 replace_sep(nidstr, ',', ' ');
820 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
821 LNET_MAX_NIDS_PER_PEER, err_str);
827 for (idx = 0; idx < num_nids; idx++) {
828 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
830 if (cmd == LNETCTL_ADD_CMD) {
831 data.cfg_config_u.cfg_route.rtr_hop = hops;
832 data.cfg_config_u.cfg_route.rtr_priority = prio;
833 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
836 data.cfg_nid = lnet_nidlist[idx];
838 if (cmd == LNETCTL_ADD_CMD)
839 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
842 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
845 if (rc != 0 && errno != EEXIST &&
846 errno != EHOSTUNREACH) {
848 snprintf(err_str, LNET_MAX_STR_LEN,
849 "route operation failed: %s",
852 } else if (errno == EEXIST) {
854 * continue chugging along if one of the
855 * routes already exists
862 cYAML_build_error(rc, seq_no,
863 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
869 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
870 int sen, int seq_no, struct cYAML **err_rc)
873 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
876 hops = LNET_UNDEFINED_HOPS;
877 } else if (hops < 1 || hops > 255) {
878 snprintf(err_str, LNET_MAX_STR_LEN,
879 "\"invalid hop count %d, must be between 1 and 255\"",
881 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
887 } else if (prio < 0) {
888 snprintf(err_str, LNET_MAX_STR_LEN,
889 "\"invalid priority %d, must be greater than 0\"",
891 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
897 } else if (sen < 1) {
898 snprintf(err_str, LNET_MAX_STR_LEN,
899 "\"invalid health sensitivity %d, must be 1 or greater\"",
901 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
905 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
906 err_rc, LNETCTL_ADD_CMD);
909 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
914 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
915 struct cYAML **err_rc)
917 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
921 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
922 int seq_no, struct cYAML **show_rc,
923 struct cYAML **err_rc, bool backup)
925 struct lnet_ioctl_config_data data;
926 lnet_nid_t gateway_nid;
927 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
929 __u32 net = LNET_NET_ANY;
931 struct cYAML *root = NULL, *route = NULL, *item = NULL;
932 struct cYAML *first_seq = NULL;
933 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
937 net = libcfs_str2net(nw);
938 if (net == LNET_NET_ANY) {
941 "\"cannot parse net '%s'\"", nw);
942 rc = LUSTRE_CFG_RC_BAD_PARAM;
947 /* show all routes without filtering on net */
952 gateway_nid = libcfs_str2nid(gw);
953 if (gateway_nid == LNET_NID_ANY) {
956 "\"cannot parse gateway NID '%s'\"", gw);
957 rc = LUSTRE_CFG_RC_BAD_PARAM;
961 /* show all routes with out filtering on gateway */
962 gateway_nid = LNET_NID_ANY;
964 if ((hops < 1 && hops != -1) || hops > 255) {
967 "\"invalid hop count %d, must be between 0 and 256\"",
969 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
973 /* create struct cYAML root object */
974 root = cYAML_create_object(NULL, NULL);
978 route = cYAML_create_seq(root, "route");
986 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
989 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
995 /* filter on provided data */
996 if (net != LNET_NET_ANY &&
1000 if (gateway_nid != LNET_NID_ANY &&
1001 gateway_nid != data.cfg_nid)
1005 hops != data.cfg_config_u.cfg_route.rtr_hop)
1009 prio != data.cfg_config_u.cfg_route.rtr_priority)
1012 /* default rc to -1 incase we hit the goto */
1016 item = cYAML_create_seq_item(route);
1020 if (first_seq == NULL)
1023 if (cYAML_create_string(item, "net",
1024 libcfs_net2str(data.cfg_net)) == NULL)
1027 if (cYAML_create_string(item, "gateway",
1028 libcfs_nid2str(data.cfg_nid)) == NULL)
1032 if (cYAML_create_number(item, "hop",
1033 (int) data.cfg_config_u.
1034 cfg_route.rtr_hop) ==
1038 if (cYAML_create_number(item, "priority",
1040 cfg_route.rtr_priority) == NULL)
1043 if (cYAML_create_number(item, "health_sensitivity",
1045 cfg_route.rtr_sensitivity) == NULL)
1048 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1050 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1054 cYAML_create_string(item, "state",
1056 "up" : "down") == NULL)
1060 cYAML_create_string(item, "type",
1062 "multi-hop" : "single-hop") == NULL)
1067 /* print output iff show_rc is not provided */
1068 if (show_rc == NULL)
1069 cYAML_print_tree(root);
1071 if (l_errno != ENOENT) {
1074 "\"cannot get routes: %s\"",
1079 rc = LUSTRE_CFG_RC_NO_ERR;
1081 snprintf(err_str, sizeof(err_str), "\"success\"");
1083 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1084 cYAML_free_tree(root);
1085 } else if (show_rc != NULL && *show_rc != NULL) {
1086 struct cYAML *show_node;
1087 /* find the route node, if one doesn't exist then
1088 * insert one. Otherwise add to the one there
1090 show_node = cYAML_get_object_item(*show_rc, "route");
1091 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1092 cYAML_insert_child(show_node, first_seq);
1095 } else if (show_node == NULL) {
1096 cYAML_insert_sibling((*show_rc)->cy_child,
1100 cYAML_free_tree(root);
1106 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1111 static int socket_intf_query(int request, char *intf,
1117 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1118 return LUSTRE_CFG_RC_BAD_PARAM;
1120 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1122 return LUSTRE_CFG_RC_BAD_PARAM;
1124 strcpy(ifr->ifr_name, intf);
1125 rc = ioctl(sockfd, request, ifr);
1127 rc = LUSTRE_CFG_RC_BAD_PARAM;
1134 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1139 memset(&ifr, 0, sizeof(ifr));
1140 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1142 return LUSTRE_CFG_RC_BAD_PARAM;
1144 if ((ifr.ifr_flags & IFF_UP) == 0)
1145 return LUSTRE_CFG_RC_BAD_PARAM;
1147 memset(&ifr, 0, sizeof(ifr));
1148 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1150 return LUSTRE_CFG_RC_BAD_PARAM;
1152 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1153 *ip = bswap_32(*ip);
1155 return LUSTRE_CFG_RC_NO_ERR;
1158 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1161 unsigned int nic_index;
1163 char *nic_addr_path;
1168 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1170 return LUSTRE_CFG_RC_NO_MATCH;
1172 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1173 nic_addr_path = malloc(size);
1175 return LUSTRE_CFG_RC_OUT_OF_MEM;
1176 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1178 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1179 free(nic_addr_path);
1181 return LUSTRE_CFG_RC_NO_MATCH;
1183 addr = strtol(val, NULL, 16);
1184 if (addr == LONG_MIN || addr == LONG_MAX)
1185 return LUSTRE_CFG_RC_NO_MATCH;
1189 return LUSTRE_CFG_RC_NO_ERR;
1193 * for each interface in the array of interfaces find the IP address of
1194 * that interface, create its nid and add it to an array of NIDs.
1195 * Stop if any of the interfaces is down
1197 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1198 lnet_nid_t **nids, __u32 *nnids,
1199 char *err_str, size_t str_len)
1201 int i = 0, count = 0, rc;
1202 struct lnet_dlc_intf_descr *intf;
1203 char val[LNET_MAX_STR_LEN];
1211 if (nw == NULL || nids == NULL) {
1212 snprintf(err_str, str_len,
1213 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1214 return LUSTRE_CFG_RC_BAD_PARAM;
1217 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1220 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1224 *nids = calloc(count, sizeof(lnet_nid_t));
1225 if (*nids == NULL) {
1226 snprintf(err_str, str_len,
1227 "\"out of memory\"");
1228 return LUSTRE_CFG_RC_OUT_OF_MEM;
1231 * special case the GNI interface since it doesn't have an IP
1232 * address. The assumption is that there can only be one GNI
1233 * interface in the system. No interface name is provided.
1235 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1236 rc = read_sysfs_file(gni_nid_path, "nid", val,
1239 snprintf(err_str, str_len,
1240 "\"cannot read gni nid\"");
1243 gni_num = atoi(val);
1245 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1248 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1249 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1250 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1251 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1252 snprintf(err_str, str_len,
1253 "\"couldn't query kfi intf %s\"",
1255 err_str[str_len - 1] = '\0';
1259 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1265 /* look at the other interfaces */
1266 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1267 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1268 /* handle LNDs with numeric interface name */
1269 num = strtoul(intf->intf_name, &endp, 0);
1270 if (endp == intf->intf_name || *endp != '\0') {
1271 rc = LUSTRE_CFG_RC_BAD_PARAM;
1272 snprintf(err_str, str_len,
1273 "\"couldn't query intf %s\"",
1277 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1280 /* handle LNDs with ip interface name */
1281 rc = lustre_lnet_queryip(intf, &ip);
1282 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1283 snprintf(err_str, str_len,
1284 "\"couldn't query intf %s\"",
1288 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1305 * called repeatedly until a match or no more ip range
1307 * ip_range expression
1308 * interface list with all the interface names.
1309 * all the interfaces in the system.
1311 * try to match the ip_range expr to one of the interfaces' IPs in
1312 * the system. If we hit a patch for an interface. Check if that
1313 * interface name is in the list.
1315 * If there are more than one interface in the list, then make sure
1316 * that the IPs for all of these interfaces match the ip ranges
1319 * for each interface in intf_list
1320 * look up the intf name in ifa
1321 * if not there then no match
1322 * check ip obtained from ifa against a match to any of the
1324 * If no match, then fail
1326 * The result is that all the interfaces have to match.
1328 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1329 struct list_head *intf_list,
1330 struct list_head *ip_ranges)
1334 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1335 struct ifaddrs *ifaddr = ifa;
1336 struct lustre_lnet_ip_range_descr *ip_range;
1340 * if there are no explicit interfaces, and no ip ranges, then
1341 * configure the first tcp interface we encounter.
1343 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1344 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1345 if (ifaddr->ifa_addr == NULL)
1348 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1351 family = ifaddr->ifa_addr->sa_family;
1352 if (family == AF_INET &&
1353 strcmp(ifaddr->ifa_name, "lo") != 0) {
1354 rc = lustre_lnet_add_intf_descr
1355 (intf_list, ifaddr->ifa_name,
1356 strlen(ifaddr->ifa_name));
1358 if (rc != LUSTRE_CFG_RC_NO_ERR)
1361 return LUSTRE_CFG_RC_MATCH;
1364 return LUSTRE_CFG_RC_NO_MATCH;
1368 * First interface which matches an IP pattern will be used
1370 if (list_empty(intf_list)) {
1372 * no interfaces provided in the rule, but an ip range is
1373 * provided, so try and match an interface to the ip
1376 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1377 if (ifaddr->ifa_addr == NULL)
1380 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1383 family = ifaddr->ifa_addr->sa_family;
1384 if (family == AF_INET) {
1385 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1388 list_for_each_entry(ip_range, ip_ranges,
1390 rc = cfs_ip_addr_match(bswap_32(ip),
1391 &ip_range->ipr_expr);
1395 rc = lustre_lnet_add_intf_descr
1396 (intf_list, ifaddr->ifa_name,
1397 strlen(ifaddr->ifa_name));
1399 if (rc != LUSTRE_CFG_RC_NO_ERR)
1405 if (!list_empty(intf_list))
1406 return LUSTRE_CFG_RC_MATCH;
1408 return LUSTRE_CFG_RC_NO_MATCH;
1412 * If an interface is explicitly specified the ip-range might or
1413 * might not be specified. if specified the interface needs to match the
1414 * ip-range. If no ip-range then the interfaces are
1415 * automatically matched if they are all up.
1416 * If > 1 interfaces all the interfaces must match for the NI to
1419 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1420 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1421 if (ifaddr->ifa_addr == NULL)
1424 family = ifaddr->ifa_addr->sa_family;
1425 if (family == AF_INET &&
1426 strcmp(intf_descr->intf_name,
1427 ifaddr->ifa_name) == 0)
1431 if (ifaddr == NULL) {
1432 list_del(&intf_descr->intf_on_network);
1433 free_intf_descr(intf_descr);
1437 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1438 list_del(&intf_descr->intf_on_network);
1439 free_intf_descr(intf_descr);
1443 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1446 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1447 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1453 /* no match for this interface */
1454 list_del(&intf_descr->intf_on_network);
1455 free_intf_descr(intf_descr);
1459 return LUSTRE_CFG_RC_MATCH;
1462 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1463 lnet_nid_t **nids, __u32 *nnids,
1464 char *err_str, size_t str_len)
1466 struct ifaddrs *ifa;
1467 int rc = LUSTRE_CFG_RC_NO_ERR;
1469 rc = getifaddrs(&ifa);
1471 snprintf(err_str, str_len,
1472 "\"failed to get interface addresses: %d\"", -errno);
1476 rc = lustre_lnet_match_ip_to_intf(ifa,
1477 &ip2nets->ip2nets_net.nw_intflist,
1478 &ip2nets->ip2nets_ip_ranges);
1479 if (rc != LUSTRE_CFG_RC_MATCH) {
1480 snprintf(err_str, str_len,
1481 "\"couldn't match ip to existing interfaces\"");
1486 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1488 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1499 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1500 struct lnet_ioctl_config_lnd_tunables *tunables,
1501 struct cfs_expr_list *global_cpts,
1502 lnet_nid_t *nids, char *err_str)
1505 struct lnet_ioctl_config_ni *conf;
1506 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1507 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1510 struct lnet_dlc_intf_descr *intf_descr;
1512 struct cfs_expr_list *cpt_expr;
1514 list_for_each_entry(intf_descr, intf_list,
1516 if (tunables != NULL)
1517 len = sizeof(struct lnet_ioctl_config_ni) +
1518 sizeof(struct lnet_ioctl_config_lnd_tunables);
1520 len = sizeof(struct lnet_ioctl_config_ni);
1522 data = calloc(1, len);
1524 return LUSTRE_CFG_RC_OUT_OF_MEM;
1525 conf = (struct lnet_ioctl_config_ni*) data;
1526 if (tunables != NULL)
1527 tun = (struct lnet_ioctl_config_lnd_tunables*)
1530 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1531 conf->lic_cfg_hdr.ioc_len = len;
1532 conf->lic_nid = nids[i];
1533 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1536 if (intf_descr->cpt_expr != NULL)
1537 cpt_expr = intf_descr->cpt_expr;
1538 else if (global_cpts != NULL)
1539 cpt_expr = global_cpts;
1543 if (cpt_expr != NULL) {
1544 count = cfs_expr_list_values(cpt_expr,
1545 LNET_MAX_SHOW_NUM_CPT,
1548 memcpy(conf->lic_cpts, cpt_array,
1549 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1558 conf->lic_ncpts = count;
1560 if (tunables != NULL)
1561 memcpy(tun, tunables, sizeof(*tunables));
1563 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1568 "\"cannot add network: %s\"", strerror(errno));
1576 return LUSTRE_CFG_RC_NO_ERR;
1580 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1581 struct lnet_ioctl_config_lnd_tunables *tunables,
1582 struct cfs_expr_list *global_cpts,
1583 int seq_no, struct cYAML **err_rc)
1585 lnet_nid_t *nids = NULL;
1588 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1593 "\"incomplete ip2nets information\"");
1594 rc = LUSTRE_CFG_RC_BAD_PARAM;
1599 * call below function to resolve the rules into a list of nids.
1600 * The memory is allocated in that function then freed here when
1601 * it's no longer needed.
1603 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1605 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1608 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1609 snprintf(err_str, sizeof(err_str),
1610 "\"no interfaces match ip2nets rules\"");
1614 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1615 tunables, global_cpts, nids,
1622 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1626 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1627 struct cfs_expr_list *global_cpts,
1629 struct lnet_ioctl_config_lnd_tunables *tunables,
1630 int seq_no, struct cYAML **err_rc)
1633 struct lnet_ioctl_config_ni *conf;
1634 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1635 char buf[LNET_MAX_STR_LEN];
1636 int rc = LUSTRE_CFG_RC_NO_ERR;
1637 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1638 lnet_nid_t *nids = NULL;
1642 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1645 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1646 (list_empty(&nw_descr->nw_intflist) &&
1647 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1650 "\"missing mandatory parameters in NI config: '%s'\"",
1651 (nw_descr == NULL) ? "network , interface" :
1652 (nw_descr->nw_id == 0) ? "network" : "interface");
1653 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1657 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1660 "\"ip2net string too long %d\"",
1661 (int)strlen(ip2net));
1662 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1666 if (ip2net != NULL) {
1667 if (tunables != NULL)
1668 len = sizeof(struct lnet_ioctl_config_ni) +
1669 sizeof(struct lnet_ioctl_config_lnd_tunables);
1671 len = sizeof(struct lnet_ioctl_config_ni);
1672 data = calloc(1, len);
1674 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1677 conf = (struct lnet_ioctl_config_ni*) data;
1678 if (tunables != NULL)
1679 tun = (struct lnet_ioctl_config_lnd_tunables*)
1680 (data + sizeof(*conf));
1682 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1683 conf->lic_cfg_hdr.ioc_len = len;
1684 strncpy(conf->lic_legacy_ip2nets, ip2net,
1687 if (global_cpts != NULL) {
1688 count = cfs_expr_list_values(global_cpts,
1689 LNET_MAX_SHOW_NUM_CPT,
1692 memcpy(conf->lic_cpts, cpt_array,
1693 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1702 conf->lic_ncpts = count;
1704 if (tunables != NULL)
1705 memcpy(tun, tunables, sizeof(*tunables));
1707 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1712 "\"cannot add network: %s\"", strerror(errno));
1719 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1720 rc = LUSTRE_CFG_RC_NO_ERR;
1724 if (nw_descr->nw_id == LNET_NET_ANY) {
1727 "\"cannot parse net '%s'\"",
1728 libcfs_net2str(nw_descr->nw_id));
1729 rc = LUSTRE_CFG_RC_BAD_PARAM;
1734 * special case the GNI since no interface name is expected
1736 if (list_empty(&nw_descr->nw_intflist) &&
1737 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1740 "\"no interface name provided\"");
1741 rc = LUSTRE_CFG_RC_BAD_PARAM;
1745 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1746 err_str, sizeof(err_str));
1748 rc = LUSTRE_CFG_RC_BAD_PARAM;
1752 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1753 tunables, global_cpts, nids,
1757 if (nw_descr != NULL) {
1758 list_for_each_entry_safe(intf_descr, tmp,
1759 &nw_descr->nw_intflist,
1761 list_del(&intf_descr->intf_on_network);
1762 free_intf_descr(intf_descr);
1766 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1777 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1778 int seq_no, struct cYAML **err_rc)
1780 struct lnet_ioctl_config_ni data;
1781 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1782 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1783 lnet_nid_t *nids = NULL;
1785 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1787 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1790 "\"missing mandatory parameter in deleting NI: '%s'\"",
1791 (nw_descr == NULL) ? "network , interface" :
1792 (nw_descr->nw_id == 0) ? "network" : "interface");
1793 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1797 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1798 return LUSTRE_CFG_RC_NO_ERR;
1800 if (nw_descr->nw_id == LNET_NET_ANY) {
1803 "\"cannot parse net '%s'\"",
1804 libcfs_net2str(nw_descr->nw_id));
1805 rc = LUSTRE_CFG_RC_BAD_PARAM;
1809 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1810 err_str, sizeof(err_str));
1812 rc = LUSTRE_CFG_RC_BAD_PARAM;
1817 * no interfaces just the nw_id is specified
1820 nids = calloc(1, sizeof(*nids));
1822 snprintf(err_str, sizeof(err_str),
1823 "\"out of memory\"");
1824 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1827 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1831 for (i = 0; i < nnids; i++) {
1832 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1833 data.lic_nid = nids[i];
1835 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1840 "\"cannot del network: %s\"", strerror(errno));
1844 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1846 list_del(&intf_descr->intf_on_network);
1847 free_intf_descr(intf_descr);
1851 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1860 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1861 enum lnet_health_type type, char *name,
1862 int seq_no, struct cYAML **err_rc)
1864 struct lnet_ioctl_reset_health_cfg data;
1865 int rc = LUSTRE_CFG_RC_NO_ERR;
1866 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1868 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1869 data.rh_type = type;
1871 data.rh_value = value;
1874 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1878 sizeof(err_str), "Can not configure health value: %s",
1882 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1889 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1890 char *name, int seq_no,
1891 struct cYAML **err_rc)
1893 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1894 int rc = LUSTRE_CFG_RC_NO_ERR;
1895 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1897 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1898 data.rcpp_all = all;
1899 data.rcpp_value = value;
1900 data.rcpp_nid = nid;
1902 if (value < 0 || value > 127) {
1903 rc = LUSTRE_CFG_RC_BAD_PARAM;
1904 snprintf(err_str, sizeof(err_str),
1905 "\"Valid values are: 0-127\"");
1908 rc = l_ioctl(LNET_DEV_ID,
1909 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1914 "Can not configure conns_per_peer value: %s",
1918 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1923 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1924 struct cYAML **err_rc)
1928 nid = libcfs_str2nid(ni_nid);
1931 return lustre_lnet_config_healthv(value, all, nid,
1932 LNET_HEALTH_TYPE_LOCAL_NI,
1933 "ni healthv", seq_no, err_rc);
1936 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1937 int seq_no, struct cYAML **err_rc)
1941 nid = libcfs_str2nid(lpni_nid);
1944 return lustre_lnet_config_healthv(value, all, nid,
1945 LNET_HEALTH_TYPE_PEER_NI,
1946 "peer_ni healthv", seq_no, err_rc);
1949 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1950 int seq_no, struct cYAML **err_rc)
1955 nid = libcfs_str2nid(ni_nid);
1958 return lustre_lnet_config_conns_per_peer(value, all, nid,
1959 "ni conns_per_peer",
1964 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1965 struct lnet_ioctl_comm_count *counts)
1967 if (cYAML_create_number(yaml, "put",
1968 counts->ico_put_count)
1971 if (cYAML_create_number(yaml, "get",
1972 counts->ico_get_count)
1975 if (cYAML_create_number(yaml, "reply",
1976 counts->ico_reply_count)
1979 if (cYAML_create_number(yaml, "ack",
1980 counts->ico_ack_count)
1983 if (cYAML_create_number(yaml, "hello",
1984 counts->ico_hello_count)
1991 static struct lnet_ioctl_comm_count *
1992 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1995 return &msg_stats->im_send_stats;
1997 return &msg_stats->im_recv_stats;
1999 return &msg_stats->im_drop_stats;
2005 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2006 struct cYAML *net_node)
2008 char tmp[LNET_MAX_STR_LEN];
2009 struct cYAML *udsp_net;
2010 bool created = false;
2014 /* add the UDSP info */
2015 udsp_net = cYAML_create_object(net_node, "udsp info");
2017 return LUSTRE_CFG_RC_OUT_OF_MEM;
2019 if (!cYAML_create_number(udsp_net, "net priority",
2020 (int) udsp_info->cud_net_priority))
2021 return LUSTRE_CFG_RC_OUT_OF_MEM;
2023 if (!cYAML_create_number(udsp_net, "nid priority",
2024 (int)udsp_info->cud_nid_priority))
2025 return LUSTRE_CFG_RC_OUT_OF_MEM;
2029 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2030 memset(tmp, 0, LNET_MAX_STR_LEN);
2031 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2034 pref = cYAML_create_object(udsp_net,
2035 "Preferred gateway NIDs");
2037 return LUSTRE_CFG_RC_OUT_OF_MEM;
2040 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2041 if (!cYAML_create_string(pref, tmp,
2042 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2043 return LUSTRE_CFG_RC_OUT_OF_MEM;
2046 return LUSTRE_CFG_RC_NO_ERR;
2050 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2051 struct cYAML *nid_node)
2053 char tmp[LNET_MAX_STR_LEN];
2054 struct cYAML *udsp_nid;
2055 bool created = false;
2059 /* add the UDSP info */
2060 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2062 return LUSTRE_CFG_RC_OUT_OF_MEM;
2064 if (!cYAML_create_number(udsp_nid, "net priority",
2065 (int) udsp_info->cud_net_priority))
2066 return LUSTRE_CFG_RC_OUT_OF_MEM;
2068 if (!cYAML_create_number(udsp_nid, "nid priority",
2069 (int) udsp_info->cud_nid_priority))
2070 return LUSTRE_CFG_RC_OUT_OF_MEM;
2073 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2074 memset(tmp, 0, LNET_MAX_STR_LEN);
2075 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2078 pref = cYAML_create_object(udsp_nid,
2079 "Preferred gateway NIDs");
2081 return LUSTRE_CFG_RC_OUT_OF_MEM;
2084 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2085 if (!cYAML_create_string(pref, tmp,
2086 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2087 return LUSTRE_CFG_RC_OUT_OF_MEM;
2092 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2093 memset(tmp, 0, LNET_MAX_STR_LEN);
2094 if (udsp_info->cud_pref_nid[i] == 0)
2097 pref = cYAML_create_object(udsp_nid,
2098 "Preferred source NIDs");
2100 return LUSTRE_CFG_RC_OUT_OF_MEM;
2103 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2104 if (!cYAML_create_string(pref, tmp,
2105 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2106 return LUSTRE_CFG_RC_OUT_OF_MEM;
2109 return LUSTRE_CFG_RC_NO_ERR;
2112 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2113 struct cYAML **show_rc, struct cYAML **err_rc,
2117 struct lnet_ioctl_config_ni *ni_data;
2118 struct lnet_ioctl_config_lnd_tunables *lnd;
2119 struct lnet_ioctl_element_stats *stats;
2120 struct lnet_ioctl_element_msg_stats msg_stats;
2121 struct lnet_ioctl_local_ni_hstats hstats;
2122 struct lnet_ioctl_construct_udsp_info udsp_info;
2123 __u32 net = LNET_NET_ANY;
2124 __u32 prev_net = LNET_NET_ANY;
2125 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2127 struct cYAML *root = NULL, *tunables = NULL,
2128 *net_node = NULL, *interfaces = NULL,
2129 *item = NULL, *first_seq = NULL,
2130 *tmp = NULL, *statistics = NULL,
2132 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2133 char str_buf[str_buf_len];
2135 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2136 bool exist = false, new_net = true;
2138 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2140 buf = calloc(1, buf_size);
2144 ni_data = (struct lnet_ioctl_config_ni *)buf;
2147 net = libcfs_str2net(nw);
2148 if (net == LNET_NET_ANY) {
2151 "\"cannot parse net '%s'\"", nw);
2152 rc = LUSTRE_CFG_RC_BAD_PARAM;
2157 root = cYAML_create_object(NULL, NULL);
2161 net_node = cYAML_create_seq(root, "net");
2162 if (net_node == NULL)
2168 memset(buf, 0, buf_size);
2170 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2172 * set the ioc_len to the proper value since INIT assumes
2175 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2176 ni_data->lic_idx = i;
2178 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2184 rc_net = LNET_NIDNET(ni_data->lic_nid);
2186 /* filter on provided data */
2187 if (net != LNET_NET_ANY &&
2191 /* if we're backing up don't store lo */
2192 if (backup && LNET_NETTYP(rc_net) == LOLND)
2195 /* default rc to -1 in case we hit the goto */
2199 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2200 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2201 (ni_data->lic_bulk + sizeof(*stats));
2203 if (rc_net != prev_net) {
2210 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2214 if (first_seq == NULL)
2217 tmp = cYAML_create_seq(net_node, "local NI(s)");
2223 /* create the tree to be printed. */
2224 item = cYAML_create_seq_item(tmp);
2229 cYAML_create_string(item, "nid",
2230 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2234 cYAML_create_string(item,
2236 (ni_data->lic_status ==
2237 LNET_NI_STATUS_UP) ?
2238 "up" : "down") == NULL)
2241 /* don't add interfaces unless there is at least one
2243 if (strlen(ni_data->lic_ni_intf) > 0) {
2244 interfaces = cYAML_create_object(item, "interfaces");
2245 if (interfaces == NULL)
2248 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2249 if (cYAML_create_string(interfaces, str_buf,
2250 ni_data->lic_ni_intf) == NULL)
2259 goto continue_without_msg_stats;
2261 statistics = cYAML_create_object(item, "statistics");
2262 if (statistics == NULL)
2265 if (cYAML_create_number(statistics, "send_count",
2266 stats->iel_send_count)
2270 if (cYAML_create_number(statistics, "recv_count",
2271 stats->iel_recv_count)
2275 if (cYAML_create_number(statistics, "drop_count",
2276 stats->iel_drop_count)
2281 goto continue_without_udsp_info;
2283 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2284 udsp_info.cud_nid = ni_data->lic_nid;
2285 udsp_info.cud_peer = false;
2286 rc = l_ioctl(LNET_DEV_ID,
2287 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2291 goto continue_without_udsp_info;
2294 rc = create_local_udsp_info(&udsp_info, item);
2300 continue_without_udsp_info:
2302 goto continue_without_msg_stats;
2304 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2305 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2306 msg_stats.im_idx = i;
2308 rc = l_ioctl(LNET_DEV_ID,
2309 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2313 goto continue_without_msg_stats;
2316 for (k = 0; k < 3; k++) {
2317 struct lnet_ioctl_comm_count *counts;
2318 struct cYAML *msg_statistics = NULL;
2320 msg_statistics = cYAML_create_object(item,
2321 (char *)gmsg_stat_names[k]);
2322 if (msg_statistics == NULL)
2325 counts = get_counts(&msg_stats, k);
2329 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2334 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2335 hstats.hlni_nid = ni_data->lic_nid;
2336 /* grab health stats */
2337 rc = l_ioctl(LNET_DEV_ID,
2338 IOC_LIBCFS_GET_LOCAL_HSTATS,
2342 goto continue_without_msg_stats;
2344 yhstats = cYAML_create_object(item, "health stats");
2347 if (cYAML_create_number(yhstats, "fatal_error",
2348 hstats.hlni_fatal_error)
2351 if (cYAML_create_number(yhstats, "health value",
2352 hstats.hlni_health_value)
2355 if (cYAML_create_number(yhstats, "interrupts",
2356 hstats.hlni_local_interrupt)
2359 if (cYAML_create_number(yhstats, "dropped",
2360 hstats.hlni_local_dropped)
2363 if (cYAML_create_number(yhstats, "aborted",
2364 hstats.hlni_local_aborted)
2367 if (cYAML_create_number(yhstats, "no route",
2368 hstats.hlni_local_no_route)
2371 if (cYAML_create_number(yhstats, "timeouts",
2372 hstats.hlni_local_timeout)
2375 if (cYAML_create_number(yhstats, "error",
2376 hstats.hlni_local_error)
2379 if (cYAML_create_number(yhstats, "ping_count",
2380 hstats.hlni_ping_count)
2383 if (cYAML_create_number(yhstats, "next_ping",
2384 hstats.hlni_next_ping)
2388 continue_without_msg_stats:
2389 tunables = cYAML_create_object(item, "tunables");
2393 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2394 if (rc != LUSTRE_CFG_RC_NO_ERR)
2397 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2398 tunables = cYAML_create_object(item,
2400 if (tunables == NULL)
2404 rc = lustre_ni_show_tunables(tunables,
2405 LNET_NETTYP(rc_net),
2406 &lnd->lt_tun, backup);
2407 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2408 rc != LUSTRE_CFG_RC_NO_MATCH)
2412 cYAML_create_number(item, "dev cpt",
2413 ni_data->lic_dev_cpt) == NULL)
2416 /* out put the CPTs in the format: "[x,x,x,...]" */
2418 limit = str_buf + str_buf_len - 3;
2419 pos += scnprintf(pos, limit - pos, "\"[");
2420 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2421 j < ni_data->lic_ncpts &&
2423 pos += scnprintf(pos, limit - pos,
2424 "%d", ni_data->lic_cpts[j]);
2425 if ((j + 1) < ni_data->lic_ncpts)
2426 pos += scnprintf(pos, limit - pos, ",");
2428 snprintf(pos, 3, "]\"");
2430 if (ni_data->lic_ncpts >= 1 &&
2431 cYAML_create_string(item, "CPT",
2437 /* Print out the net information only if show_rc is not provided */
2438 if (show_rc == NULL)
2439 cYAML_print_tree(root);
2441 if (l_errno != ENOENT) {
2444 "\"cannot get networks: %s\"",
2449 rc = LUSTRE_CFG_RC_NO_ERR;
2451 snprintf(err_str, sizeof(err_str), "\"success\"");
2453 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2454 cYAML_free_tree(root);
2455 } else if (show_rc != NULL && *show_rc != NULL) {
2456 struct cYAML *show_node;
2457 /* find the net node, if one doesn't exist
2458 * then insert one. Otherwise add to the one there
2460 show_node = cYAML_get_object_item(*show_rc, "net");
2461 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2462 cYAML_insert_child(show_node, first_seq);
2465 } else if (show_node == NULL) {
2466 cYAML_insert_sibling((*show_rc)->cy_child,
2470 cYAML_free_tree(root);
2476 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2481 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2483 struct lnet_ioctl_config_data data;
2484 int rc = LUSTRE_CFG_RC_NO_ERR;
2485 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2487 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2488 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2490 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2495 "\"cannot %s routing %s\"",
2496 (enable) ? "enable" : "disable", strerror(errno));
2501 cYAML_build_error(rc, seq_no,
2502 (enable) ? ADD_CMD : DEL_CMD,
2503 "routing", err_str, err_rc);
2508 int ioctl_set_value(__u32 val, int ioc, char *name,
2509 int seq_no, struct cYAML **err_rc)
2511 struct lnet_ioctl_set_value data;
2512 int rc = LUSTRE_CFG_RC_NO_ERR;
2513 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2515 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2516 data.sv_value = val;
2518 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2523 "\"cannot configure %s to %d: %s\"", name,
2524 val, strerror(errno));
2527 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2532 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2534 int rc = LUSTRE_CFG_RC_NO_ERR;
2535 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2536 char val[LNET_MAX_STR_LEN];
2538 snprintf(val, sizeof(val), "%d", intrv);
2540 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2541 1, strlen(val) + 1);
2543 snprintf(err_str, sizeof(err_str),
2544 "\"cannot configure recovery interval: %s\"",
2547 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2552 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2554 int rc = LUSTRE_CFG_RC_NO_ERR;
2555 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2556 char val[LNET_MAX_STR_LEN];
2558 snprintf(val, sizeof(val), "%d", sen);
2560 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2561 1, strlen(val) + 1);
2563 snprintf(err_str, sizeof(err_str),
2564 "\"cannot configure router health sensitivity: %s\"",
2567 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2572 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2574 int rc = LUSTRE_CFG_RC_NO_ERR;
2575 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2576 char val[LNET_MAX_STR_LEN];
2578 snprintf(val, sizeof(val), "%d", sen);
2580 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2581 1, strlen(val) + 1);
2583 snprintf(err_str, sizeof(err_str),
2584 "\"cannot configure health sensitivity: %s\"",
2587 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2592 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2594 int rc = LUSTRE_CFG_RC_NO_ERR;
2595 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2596 char val[LNET_MAX_STR_LEN];
2598 snprintf(val, sizeof(val), "%d", timeout);
2600 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2601 1, strlen(val) + 1);
2603 snprintf(err_str, sizeof(err_str),
2604 "\"cannot configure transaction timeout: %s\"",
2607 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2612 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2614 int rc = LUSTRE_CFG_RC_NO_ERR;
2615 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2616 char val[LNET_MAX_STR_LEN];
2618 snprintf(val, sizeof(val), "%d", count);
2620 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2621 1, strlen(val) + 1);
2623 snprintf(err_str, sizeof(err_str),
2624 "\"cannot configure retry count: %s\"",
2627 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2632 int lustre_lnet_config_response_tracking(int val, int seq_no,
2633 struct cYAML **err_rc)
2635 int rc = LUSTRE_CFG_RC_NO_ERR;
2636 char err_str[LNET_MAX_STR_LEN];
2637 char val_str[LNET_MAX_STR_LEN];
2639 if (val < 0 || val > 3) {
2640 rc = LUSTRE_CFG_RC_BAD_PARAM;
2641 snprintf(err_str, sizeof(err_str),
2642 "\"Valid values are: 0, 1, 2, or 3\"");
2644 snprintf(err_str, sizeof(err_str), "\"success\"");
2646 snprintf(val_str, sizeof(val_str), "%d", val);
2648 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2649 val_str, 1, strlen(val_str) + 1);
2651 snprintf(err_str, sizeof(err_str),
2652 "\"cannot configure response tracking: %s\"",
2656 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2662 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2663 struct cYAML **err_rc)
2665 int rc = LUSTRE_CFG_RC_NO_ERR;
2666 char err_str[LNET_MAX_STR_LEN];
2667 char val_str[LNET_MAX_STR_LEN];
2670 rc = LUSTRE_CFG_RC_BAD_PARAM;
2671 snprintf(err_str, sizeof(err_str),
2672 "\"Must be greater than or equal to 0\"");
2674 snprintf(err_str, sizeof(err_str), "\"success\"");
2676 snprintf(val_str, sizeof(val_str), "%d", val);
2678 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2679 val_str, 1, strlen(val_str) + 1);
2681 snprintf(err_str, sizeof(err_str),
2682 "\"cannot configure recovery limit: %s\"",
2686 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2692 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2694 int rc = LUSTRE_CFG_RC_NO_ERR;
2695 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2696 char val[LNET_MAX_STR_LEN];
2698 snprintf(val, sizeof(val), "%d", max);
2700 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2701 1, strlen(val) + 1);
2703 snprintf(err_str, sizeof(err_str),
2704 "\"cannot configure max interfaces: %s\"",
2707 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2712 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2714 int rc = LUSTRE_CFG_RC_NO_ERR;
2715 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2716 char val[LNET_MAX_STR_LEN];
2718 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2720 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2721 1, strlen(val) + 1);
2723 snprintf(err_str, sizeof(err_str),
2724 "\"cannot configure discovery: %s\"",
2727 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2733 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2734 struct cYAML **err_rc)
2736 int rc = LUSTRE_CFG_RC_NO_ERR;
2737 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2738 char val[LNET_MAX_STR_LEN];
2740 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2742 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2743 1, strlen(val) + 1);
2745 snprintf(err_str, sizeof(err_str),
2746 "\"cannot configure drop asym route: %s\"",
2749 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2756 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2758 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2759 "numa_range", seq_no, err_rc);
2762 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2763 struct cYAML **err_rc)
2765 struct lnet_ioctl_config_data data;
2766 int rc = LUSTRE_CFG_RC_NO_ERR;
2767 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2769 /* -1 indicates to ignore changes to this field */
2770 if (tiny < -1 || small < -1 || large < -1) {
2773 "\"tiny, small and large must be >= 0\"");
2774 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2778 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2779 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2780 data.cfg_config_u.cfg_buffers.buf_small = small;
2781 data.cfg_config_u.cfg_buffers.buf_large = large;
2783 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2788 "\"cannot configure buffers: %s\"", strerror(errno));
2793 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2798 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2799 struct cYAML **err_rc)
2801 int rc = LUSTRE_CFG_RC_NO_ERR;
2802 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2803 char interval_str[LNET_MAX_STR_LEN];
2805 if (interval <= 0) {
2806 rc = LUSTRE_CFG_RC_BAD_PARAM;
2807 snprintf(err_str, sizeof(err_str),
2808 "\"must be strictly positive\"");
2811 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2813 rc = write_sysfs_file(modparam_path,
2814 "lnet_max_recovery_ping_interval",
2816 strlen(interval_str) + 1);
2818 snprintf(err_str, sizeof(err_str),
2819 "\"cannot configure maximum recovery ping interval: %s\"",
2823 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2830 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2831 struct cYAML **err_rc, bool backup)
2833 struct lnet_ioctl_config_data *data;
2834 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2835 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2838 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2839 int buf_count[LNET_NRBPOOLS] = {0};
2840 struct cYAML *root = NULL, *pools_node = NULL,
2841 *type_node = NULL, *item = NULL, *cpt = NULL,
2842 *first_seq = NULL, *buffers = NULL;
2844 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2845 char node_name[LNET_MAX_STR_LEN];
2848 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2852 data = (struct lnet_ioctl_config_data *)buf;
2854 root = cYAML_create_object(NULL, NULL);
2859 pools_node = cYAML_create_object(root, "routing");
2861 pools_node = cYAML_create_seq(root, "routing");
2862 if (pools_node == NULL)
2866 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2867 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2868 sizeof(struct lnet_ioctl_pool_cfg);
2869 data->cfg_count = i;
2871 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2879 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2882 goto calculate_buffers;
2884 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2885 item = cYAML_create_seq_item(pools_node);
2889 if (first_seq == NULL)
2892 cpt = cYAML_create_object(item, node_name);
2897 /* create the tree and print */
2898 for (j = 0; j < LNET_NRBPOOLS; j++) {
2900 type_node = cYAML_create_object(cpt, pools[j]);
2901 if (type_node == NULL)
2905 cYAML_create_number(type_node, "npages",
2906 pool_cfg->pl_pools[j].pl_npages)
2910 cYAML_create_number(type_node, "nbuffers",
2911 pool_cfg->pl_pools[j].
2912 pl_nbuffers) == NULL)
2915 cYAML_create_number(type_node, "credits",
2916 pool_cfg->pl_pools[j].
2917 pl_credits) == NULL)
2920 cYAML_create_number(type_node, "mincredits",
2921 pool_cfg->pl_pools[j].
2922 pl_mincredits) == NULL)
2924 /* keep track of the total count for each of the
2925 * tiny, small and large buffers */
2926 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2930 if (pool_cfg != NULL) {
2932 if (cYAML_create_number(pools_node, "enable",
2933 pool_cfg->pl_routing) ==
2937 goto add_buffer_section;
2940 item = cYAML_create_seq_item(pools_node);
2944 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2950 /* create a buffers entry in the show. This is necessary so that
2951 * if the YAML output is used to configure a node, the buffer
2952 * configuration takes hold */
2953 buffers = cYAML_create_object(root, "buffers");
2954 if (buffers == NULL)
2957 for (i = 0; i < LNET_NRBPOOLS; i++) {
2958 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2962 if (show_rc == NULL)
2963 cYAML_print_tree(root);
2965 if (l_errno != ENOENT) {
2968 "\"cannot get routing information: %s\"",
2973 rc = LUSTRE_CFG_RC_NO_ERR;
2975 snprintf(err_str, sizeof(err_str), "\"success\"");
2976 rc = LUSTRE_CFG_RC_NO_ERR;
2980 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2981 cYAML_free_tree(root);
2982 } else if (show_rc != NULL && *show_rc != NULL) {
2983 struct cYAML *routing_node;
2984 /* there should exist only one routing block and one
2985 * buffers block. If there already exists a previous one
2986 * then don't add another */
2987 routing_node = cYAML_get_object_item(*show_rc, "routing");
2988 if (routing_node == NULL) {
2989 cYAML_insert_sibling((*show_rc)->cy_child,
2993 cYAML_free_tree(root);
2999 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3004 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3005 struct cYAML **show_rc, struct cYAML **err_rc,
3009 * TODO: This function is changing in a future patch to accommodate
3010 * PEER_LIST and proper filtering on any nid of the peer
3012 struct lnet_ioctl_peer_cfg peer_info;
3013 struct lnet_peer_ni_credit_info *lpni_cri;
3014 struct lnet_ioctl_element_stats *lpni_stats;
3015 struct lnet_ioctl_element_msg_stats *msg_stats;
3016 struct lnet_ioctl_peer_ni_hstats *hstats;
3017 struct lnet_ioctl_construct_udsp_info udsp_info;
3019 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3024 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3025 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3026 *msg_statistics = NULL, *statistics = NULL,
3028 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3029 struct lnet_process_id *list = NULL;
3034 /* create struct cYAML root object */
3035 root = cYAML_create_object(NULL, NULL);
3039 peer_root = cYAML_create_seq(root, "peer");
3040 if (peer_root == NULL)
3044 size = count * sizeof(struct lnet_process_id);
3045 list = malloc(size);
3051 list[0].nid = libcfs_str2nid(knid);
3055 memset(&peer_info, 0, sizeof(peer_info));
3056 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3057 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3058 peer_info.prcfg_size = size;
3059 peer_info.prcfg_bulk = list;
3062 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3064 count = peer_info.prcfg_count;
3068 if (l_errno != E2BIG) {
3071 "\"cannot get peer list: %s\"",
3077 size = peer_info.prcfg_size;
3078 list = malloc(size);
3087 data = malloc(size);
3093 for (i = 0; i < count; i++) {
3095 memset(&peer_info, 0, sizeof(peer_info));
3096 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3097 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3098 peer_info.prcfg_prim_nid = list[i].nid;
3099 peer_info.prcfg_size = size;
3100 peer_info.prcfg_bulk = data;
3103 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3108 if (l_errno != E2BIG) {
3111 "\"cannot get peer information: %s\"",
3117 size = peer_info.prcfg_size;
3118 data = malloc(size);
3126 peer = cYAML_create_seq_item(peer_root);
3130 if (first_seq == NULL)
3133 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3134 if (cYAML_create_string(peer, "primary nid",
3135 libcfs_nid2str(pnid))
3138 if (cYAML_create_string(peer, "Multi-Rail",
3139 peer_info.prcfg_mr ? "True" : "False")
3143 * print out the state of the peer only if details are
3148 cYAML_create_number(peer, "peer state",
3149 peer_info.prcfg_state)
3154 tmp = cYAML_create_seq(peer, "peer ni");
3159 for (j = 0; j < peer_info.prcfg_count; j++) {
3161 lpni_cri = (void*)nidp + sizeof(nidp);
3162 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3163 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3164 hstats = (void *)msg_stats + sizeof(*msg_stats);
3165 lpni_data = (void *)hstats + sizeof(*hstats);
3167 peer_ni = cYAML_create_seq_item(tmp);
3168 if (peer_ni == NULL)
3171 if (cYAML_create_string(peer_ni, "nid",
3172 libcfs_nid2str(*nidp))
3180 goto continue_without_udsp_info;
3182 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3183 udsp_info.cud_nid = *nidp;
3184 udsp_info.cud_peer = true;
3185 rc = l_ioctl(LNET_DEV_ID,
3186 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3190 goto continue_without_udsp_info;
3193 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3199 continue_without_udsp_info:
3200 if (cYAML_create_string(peer_ni, "state",
3201 lpni_cri->cr_aliveness)
3208 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3209 lpni_cri->cr_ni_peer_tx_credits)
3213 if (cYAML_create_number(peer_ni, "available_tx_credits",
3214 lpni_cri->cr_peer_tx_credits)
3218 if (cYAML_create_number(peer_ni, "min_tx_credits",
3219 lpni_cri->cr_peer_min_tx_credits)
3223 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3224 lpni_cri->cr_peer_tx_qnob)
3228 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3229 lpni_cri->cr_peer_rtr_credits)
3233 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3234 lpni_cri->cr_peer_min_rtr_credits)
3238 if (cYAML_create_number(peer_ni, "refcount",
3239 lpni_cri->cr_refcount) == NULL)
3242 statistics = cYAML_create_object(peer_ni, "statistics");
3243 if (statistics == NULL)
3246 if (cYAML_create_number(statistics, "send_count",
3247 lpni_stats->iel_send_count)
3251 if (cYAML_create_number(statistics, "recv_count",
3252 lpni_stats->iel_recv_count)
3256 if (cYAML_create_number(statistics, "drop_count",
3257 lpni_stats->iel_drop_count)
3264 for (k = 0; k < 3; k++) {
3265 struct lnet_ioctl_comm_count *counts;
3267 msg_statistics = cYAML_create_object(peer_ni,
3268 (char *) gmsg_stat_names[k]);
3269 if (msg_statistics == NULL)
3272 counts = get_counts(msg_stats, k);
3276 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3281 yhstats = cYAML_create_object(peer_ni, "health stats");
3284 if (cYAML_create_number(yhstats, "health value",
3285 hstats->hlpni_health_value)
3288 if (cYAML_create_number(yhstats, "dropped",
3289 hstats->hlpni_remote_dropped)
3292 if (cYAML_create_number(yhstats, "timeout",
3293 hstats->hlpni_remote_timeout)
3296 if (cYAML_create_number(yhstats, "error",
3297 hstats->hlpni_remote_error)
3300 if (cYAML_create_number(yhstats, "network timeout",
3301 hstats->hlpni_network_timeout)
3304 if (cYAML_create_number(yhstats, "ping_count",
3305 hstats->hlpni_ping_count)
3309 if (cYAML_create_number(yhstats, "next_ping",
3310 hstats->hlpni_next_ping)
3317 /* print output iff show_rc is not provided */
3318 if (show_rc == NULL)
3319 cYAML_print_tree(root);
3321 snprintf(err_str, sizeof(err_str), "\"success\"");
3322 rc = LUSTRE_CFG_RC_NO_ERR;
3327 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3328 cYAML_free_tree(root);
3329 } else if (show_rc != NULL && *show_rc != NULL) {
3330 struct cYAML *show_node;
3331 /* find the peer node, if one doesn't exist then
3332 * insert one. Otherwise add to the one there
3334 show_node = cYAML_get_object_item(*show_rc,
3336 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3337 cYAML_insert_child(show_node, first_seq);
3340 } else if (show_node == NULL) {
3341 cYAML_insert_sibling((*show_rc)->cy_child,
3345 cYAML_free_tree(root);
3351 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3357 int lustre_lnet_list_peer(int seq_no,
3358 struct cYAML **show_rc, struct cYAML **err_rc)
3360 struct lnet_ioctl_peer_cfg peer_info;
3361 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3366 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3367 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3368 struct lnet_process_id *list = NULL;
3370 memset(&peer_info, 0, sizeof(peer_info));
3372 /* create struct cYAML root object */
3373 root = cYAML_create_object(NULL, NULL);
3377 list_root = cYAML_create_seq(root, "peer list");
3378 if (list_root == NULL)
3382 size = count * sizeof(struct lnet_process_id);
3383 list = malloc(size);
3389 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3390 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3391 peer_info.prcfg_size = size;
3392 peer_info.prcfg_bulk = list;
3395 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3396 count = peer_info.prcfg_count;
3400 if (l_errno != E2BIG) {
3403 "\"cannot get peer list: %s\"",
3409 size = peer_info.prcfg_size;
3410 list = malloc(size);
3417 /* count is now the actual number of ids in the list. */
3418 for (i = 0; i < count; i++) {
3419 if (cYAML_create_string(list_root, "nid",
3420 libcfs_nid2str(list[i].nid))
3425 /* print output iff show_rc is not provided */
3426 if (show_rc == NULL)
3427 cYAML_print_tree(root);
3429 snprintf(err_str, sizeof(err_str), "\"success\"");
3430 rc = LUSTRE_CFG_RC_NO_ERR;
3435 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3436 cYAML_free_tree(root);
3437 } else if (show_rc != NULL && *show_rc != NULL) {
3438 struct cYAML *show_node;
3439 /* find the peer node, if one doesn't exist then
3440 * insert one. Otherwise add to the one there
3442 show_node = cYAML_get_object_item(*show_rc,
3444 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3445 cYAML_insert_child(show_node, first_seq);
3448 } else if (show_node == NULL) {
3449 cYAML_insert_sibling((*show_rc)->cy_child,
3453 cYAML_free_tree(root);
3459 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3465 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3468 struct cYAML *show_node;
3470 show_node = cYAML_get_object_item(show_rc, "global");
3471 if (show_node != NULL)
3472 cYAML_insert_sibling(show_node->cy_child,
3475 cYAML_insert_sibling(show_rc->cy_child,
3480 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3481 char *name, __u64 value,
3482 struct cYAML **show_rc,
3483 struct cYAML **err_rc, int err)
3485 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3486 struct cYAML *root = NULL, *global = NULL;
3493 root = cYAML_create_object(NULL, NULL);
3497 global = cYAML_create_object(root, "global");
3501 if (cYAML_create_number(global, name,
3505 if (show_rc == NULL)
3506 cYAML_print_tree(root);
3508 snprintf(err_str, err_len, "\"success\"");
3510 rc = LUSTRE_CFG_RC_NO_ERR;
3513 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3514 cYAML_free_tree(root);
3515 } else if (show_rc != NULL && *show_rc != NULL) {
3516 add_to_global(*show_rc, global, root);
3521 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3526 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3527 struct cYAML **show_rc,
3528 struct cYAML **err_rc)
3530 struct lnet_ioctl_set_value data;
3533 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3535 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3537 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3542 "\"cannot get %s: %s\"",
3543 name, strerror(l_errno));
3546 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3547 data.sv_value, show_rc, err_rc, l_errno);
3550 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3551 struct cYAML **err_rc)
3553 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3554 char val[LNET_MAX_STR_LEN];
3555 int intrv = -1, l_errno = 0;
3556 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3558 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3562 snprintf(err_str, sizeof(err_str),
3563 "\"cannot get recovery interval: %d\"", rc);
3568 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3569 "recovery_interval", intrv, show_rc,
3573 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3574 struct cYAML **err_rc)
3576 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3577 char val[LNET_MAX_STR_LEN];
3578 int sen = -1, l_errno = 0;
3579 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3581 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3585 snprintf(err_str, sizeof(err_str),
3586 "\"cannot get health sensitivity: %d\"", rc);
3591 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3592 "health_sensitivity", sen, show_rc,
3596 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3597 struct cYAML **err_rc)
3599 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3600 char val[LNET_MAX_STR_LEN];
3601 int sen = -1, l_errno = 0;
3602 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3604 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3608 snprintf(err_str, sizeof(err_str),
3609 "\"cannot get router sensitivity percentage: %d\"", rc);
3614 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3615 "router_sensitivity", sen, show_rc,
3619 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3620 struct cYAML **err_rc)
3622 char val[LNET_MAX_STR_LEN];
3623 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3630 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3633 snprintf(err_str, sizeof(err_str),
3634 "\"cannot get LND timeout: %d\"", rc);
3635 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3636 "lnd_timeout", lnd_to, show_rc,
3640 fd = open(path.gl_pathv[0], O_RDONLY);
3643 snprintf(err_str, sizeof(err_str),
3644 "\"error opening %s\"", path.gl_pathv[0]);
3648 rc = read(fd, val, sizeof(val));
3655 snprintf(err_str, sizeof(err_str),
3656 "\"error reading %s\"", path.gl_pathv[0]);
3663 cfs_free_param_data(&path);
3665 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3666 "lnd_timeout", lnd_to, show_rc,
3670 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3671 struct cYAML **err_rc)
3673 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3674 char val[LNET_MAX_STR_LEN];
3675 int tto = -1, l_errno = 0;
3676 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3678 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3682 snprintf(err_str, sizeof(err_str),
3683 "\"cannot get transaction timeout: %d\"", rc);
3688 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3689 "transaction_timeout", tto, show_rc,
3693 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3694 struct cYAML **err_rc)
3696 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3697 char val[LNET_MAX_STR_LEN];
3698 int retry_count = -1, l_errno = 0;
3699 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3701 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3705 snprintf(err_str, sizeof(err_str),
3706 "\"cannot get retry count: %d\"", rc);
3708 retry_count = atoi(val);
3711 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3712 "retry_count", retry_count, show_rc,
3716 int lustre_lnet_calc_service_id(__u64 *service_id)
3718 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3719 char val[LNET_MAX_STR_LEN];
3720 int service_port = -1, l_errno = 0;
3722 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3726 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3727 strerror(l_errno), -l_errno);
3730 service_port = atoi(val);
3733 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3735 return LUSTRE_CFG_RC_NO_ERR;
3738 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3741 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3743 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3744 struct lnet_ioctl_config_ni *ni_data;
3745 struct lnet_ioctl_config_lnd_tunables *lnd;
3746 struct lnet_ioctl_element_stats *stats;
3747 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3748 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3749 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3750 int if_cnt = 0, prc;
3751 char syscmdbuf[LNET_MAX_STR_LEN];
3752 char cmdpath[LNET_MAX_STR_LEN];
3753 bool use_custom = false;
3755 buf = calloc(1, buf_size);
3759 ni_data = (struct lnet_ioctl_config_ni *)buf;
3762 ifstr_ptr = ifstr_buf;
3767 memset(buf, 0, buf_size);
3769 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3770 /* set the ioc_len to the proper value since INIT assumes
3773 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3774 ni_data->lic_idx = i;
3776 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3782 rc_net = LNET_NIDNET(ni_data->lic_nid);
3784 /* only need to setup routing for tcp */
3785 if (LNET_NETTYP(rc_net) != SOCKLND)
3788 /* don't add interfaces unless there is at least one
3791 if (strlen(ni_data->lic_ni_intf) > 0) {
3793 strcat(ifstr_ptr, ",");
3794 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3799 if (l_errno != ENOENT) {
3802 "\"cannot get networks: %s\"",
3807 rc = LUSTRE_CFG_RC_NO_ERR;
3810 snprintf(err_str, sizeof(err_str), "\"success\"");
3813 tmp_ptr = getenv("KSOCKLND_CONFIG");
3815 tmp_ptr2 = strrchr(tmp_ptr, '/');
3816 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3817 snprintf(cmdpath, sizeof(cmdpath), "%s",
3824 snprintf(cmdpath, sizeof(cmdpath),
3825 "/usr/sbin/ksocklnd-config");
3827 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3833 "\"snprintf failed : %s\"",
3836 } else if (prc >= LNET_MAX_STR_LEN) {
3837 snprintf(err_str, sizeof(err_str),
3838 "\"ksocklnd-config: argument too long\"");
3840 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3841 cmdpath, ifstr_ptr);
3847 "\"snprintf failed : %s\"",
3853 rc = system(syscmdbuf);
3858 "\"failed to execute ksocklnd-config : %s\"",
3868 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3875 lnet_nid_cpt_hash(lnet_nid_t nid, long int number)
3878 __u64 pair_bits = 0x0001000100010001LLU;
3879 __u64 mask = pair_bits * 0xFF;
3885 pair_sum = (key & mask) + ((key >> 8) & mask);
3886 pair_sum = (pair_sum * pair_bits) >> 48;
3888 return (unsigned int)(pair_sum) % number;
3891 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3893 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3897 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3902 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3906 nid = libcfs_str2nid(nidc);
3907 if (nid == LNET_NID_ANY) {
3908 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3913 return (int)lnet_nid_cpt_hash(nid, ncpts);
3916 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3917 struct cYAML **show_rc, struct cYAML **err_rc)
3919 struct lnet_ioctl_recovery_list nid_list;
3920 struct cYAML *root = NULL, *nids = NULL;
3922 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3924 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3925 nid_list.rlst_type = type;
3927 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3933 if (nid_list.rlst_num_nids == 0)
3936 root = cYAML_create_object(NULL, NULL);
3940 nids = cYAML_create_object(root, name);
3946 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3947 char nidenum[LNET_MAX_STR_LEN];
3948 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3949 if (!cYAML_create_string(nids, nidenum,
3950 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3954 snprintf(err_str, sizeof(err_str), "success\n");
3959 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3960 cYAML_free_tree(root);
3961 } else if (show_rc != NULL && *show_rc != NULL) {
3962 struct cYAML *show_node;
3963 /* find the net node, if one doesn't exist
3964 * then insert one. Otherwise add to the one there
3966 show_node = cYAML_get_object_item(*show_rc, name);
3967 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3968 cYAML_insert_child(show_node, nids);
3971 } else if (show_node == NULL) {
3972 cYAML_insert_sibling((*show_rc)->cy_child,
3976 cYAML_free_tree(root);
3982 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3987 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
3988 struct cYAML **err_rc)
3990 struct libcfs_ioctl_data data;
3992 char err_str[LNET_MAX_STR_LEN] = "Error";
3993 lnet_nid_t pnid = LNET_NID_ANY;
3996 rc = LUSTRE_CFG_RC_BAD_PARAM;
3997 snprintf(err_str, LNET_MAX_STR_LEN,
3998 "--nid must be specified");
4002 pnid = libcfs_str2nid(peer_nid);
4003 if (pnid == LNET_NID_ANY) {
4004 rc = LUSTRE_CFG_RC_BAD_PARAM;
4005 snprintf(err_str, LNET_MAX_STR_LEN,
4006 "badly formatted primary NID: %s", peer_nid);
4010 LIBCFS_IOC_INIT(data);
4011 data.ioc_net = LNET_NIDNET(pnid);
4012 data.ioc_nid = pnid;
4014 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4018 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4024 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4025 struct cYAML **err_rc)
4027 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4028 seq_no, show_rc, err_rc);
4031 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4032 struct cYAML **err_rc)
4034 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4035 seq_no, show_rc, err_rc);
4038 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4039 struct cYAML **err_rc)
4041 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4042 char val[LNET_MAX_STR_LEN];
4043 int rsp_tracking = -1, l_errno = 0;
4044 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4046 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4050 snprintf(err_str, sizeof(err_str),
4051 "\"cannot get lnet_response_tracking value: %d\"", rc);
4053 rsp_tracking = atoi(val);
4056 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4057 "response_tracking", rsp_tracking,
4058 show_rc, err_rc, l_errno);
4061 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4062 struct cYAML **err_rc)
4064 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4065 char val[LNET_MAX_STR_LEN];
4066 int recov_limit = -1, l_errno = 0;
4067 char err_str[LNET_MAX_STR_LEN];
4069 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4071 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4075 snprintf(err_str, sizeof(err_str),
4076 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4078 recov_limit = atoi(val);
4081 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4082 "recovery_limit", recov_limit,
4083 show_rc, err_rc, l_errno);
4086 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4087 struct cYAML **show_rc,
4088 struct cYAML **err_rc)
4090 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4091 char val[LNET_MAX_STR_LEN];
4092 int interval = -1, l_errno = 0;
4093 char err_str[LNET_MAX_STR_LEN];
4095 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4097 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4098 val, 1, sizeof(val));
4101 snprintf(err_str, sizeof(err_str),
4102 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4105 interval = atoi(val);
4108 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4109 "max_recovery_ping_interval", interval,
4110 show_rc, err_rc, l_errno);
4114 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4115 struct cYAML **err_rc)
4117 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4118 char val[LNET_MAX_STR_LEN];
4119 int max_intf = -1, l_errno = 0;
4120 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4122 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4126 snprintf(err_str, sizeof(err_str),
4127 "\"cannot get max interfaces: %d\"", rc);
4129 max_intf = atoi(val);
4132 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4133 "max_interfaces", max_intf, show_rc,
4137 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4138 struct cYAML **err_rc)
4140 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4141 char val[LNET_MAX_STR_LEN];
4142 int discovery = -1, l_errno = 0;
4143 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4145 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4149 snprintf(err_str, sizeof(err_str),
4150 "\"cannot get discovery setting: %d\"", rc);
4153 * The kernel stores a discovery disabled value. User space
4154 * shows whether discovery is enabled. So the value must be
4157 discovery = !atoi(val);
4160 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4161 "discovery", discovery, show_rc,
4165 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4166 struct cYAML **err_rc)
4168 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4169 char val[LNET_MAX_STR_LEN];
4170 int drop_asym_route = -1, l_errno = 0;
4171 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4173 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4177 snprintf(err_str, sizeof(err_str),
4178 "\"cannot get drop asym route setting: %d\"", rc);
4180 drop_asym_route = atoi(val);
4183 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4184 "drop_asym_route", drop_asym_route,
4185 show_rc, err_rc, l_errno);
4188 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4189 struct cYAML **err_rc)
4191 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4192 "numa_range", show_rc, err_rc);
4195 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4196 struct cYAML **err_rc)
4198 struct lnet_ioctl_lnet_stats data;
4199 struct lnet_counters *cntrs;
4202 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4203 struct cYAML *root = NULL, *stats = NULL;
4205 LIBCFS_IOC_INIT_V2(data, st_hdr);
4207 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4212 "\"cannot get lnet statistics: %s\"",
4218 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4220 cntrs = &data.st_cntrs;
4222 root = cYAML_create_object(NULL, NULL);
4226 stats = cYAML_create_object(root, "statistics");
4230 if (!cYAML_create_number(stats, "msgs_alloc",
4231 cntrs->lct_common.lcc_msgs_alloc))
4234 if (!cYAML_create_number(stats, "msgs_max",
4235 cntrs->lct_common.lcc_msgs_max))
4238 if (!cYAML_create_number(stats, "rst_alloc",
4239 cntrs->lct_health.lch_rst_alloc))
4242 if (!cYAML_create_number(stats, "errors",
4243 cntrs->lct_common.lcc_errors))
4246 if (!cYAML_create_number(stats, "send_count",
4247 cntrs->lct_common.lcc_send_count))
4250 if (!cYAML_create_number(stats, "resend_count",
4251 cntrs->lct_health.lch_resend_count))
4254 if (!cYAML_create_number(stats, "response_timeout_count",
4255 cntrs->lct_health.lch_response_timeout_count))
4258 if (!cYAML_create_number(stats, "local_interrupt_count",
4259 cntrs->lct_health.lch_local_interrupt_count))
4262 if (!cYAML_create_number(stats, "local_dropped_count",
4263 cntrs->lct_health.lch_local_dropped_count))
4266 if (!cYAML_create_number(stats, "local_aborted_count",
4267 cntrs->lct_health.lch_local_aborted_count))
4270 if (!cYAML_create_number(stats, "local_no_route_count",
4271 cntrs->lct_health.lch_local_no_route_count))
4274 if (!cYAML_create_number(stats, "local_timeout_count",
4275 cntrs->lct_health.lch_local_timeout_count))
4278 if (!cYAML_create_number(stats, "local_error_count",
4279 cntrs->lct_health.lch_local_error_count))
4282 if (!cYAML_create_number(stats, "remote_dropped_count",
4283 cntrs->lct_health.lch_remote_dropped_count))
4286 if (!cYAML_create_number(stats, "remote_error_count",
4287 cntrs->lct_health.lch_remote_error_count))
4290 if (!cYAML_create_number(stats, "remote_timeout_count",
4291 cntrs->lct_health.lch_remote_timeout_count))
4294 if (!cYAML_create_number(stats, "network_timeout_count",
4295 cntrs->lct_health.lch_network_timeout_count))
4298 if (!cYAML_create_number(stats, "recv_count",
4299 cntrs->lct_common.lcc_recv_count))
4302 if (!cYAML_create_number(stats, "route_count",
4303 cntrs->lct_common.lcc_route_count))
4306 if (!cYAML_create_number(stats, "drop_count",
4307 cntrs->lct_common.lcc_drop_count))
4310 if (!cYAML_create_number(stats, "send_length",
4311 cntrs->lct_common.lcc_send_length))
4314 if (!cYAML_create_number(stats, "recv_length",
4315 cntrs->lct_common.lcc_recv_length))
4318 if (!cYAML_create_number(stats, "route_length",
4319 cntrs->lct_common.lcc_route_length))
4322 if (!cYAML_create_number(stats, "drop_length",
4323 cntrs->lct_common.lcc_drop_length))
4327 cYAML_print_tree(root);
4329 snprintf(err_str, sizeof(err_str), "\"success\"");
4330 rc = LUSTRE_CFG_RC_NO_ERR;
4332 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4333 cYAML_free_tree(root);
4334 } else if (show_rc != NULL && *show_rc != NULL) {
4335 cYAML_insert_sibling((*show_rc)->cy_child,
4342 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4347 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4349 struct libcfs_ioctl_data data;
4350 int rc = LUSTRE_CFG_RC_NO_ERR;
4352 char err_str[LNET_MAX_STR_LEN];
4354 LIBCFS_IOC_INIT(data);
4356 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4361 "\"cannot reset lnet statistics: %s\"",
4365 snprintf(err_str, sizeof(err_str), "\"success\"");
4366 rc = LUSTRE_CFG_RC_NO_ERR;
4369 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4373 typedef int (*cmd_handler_t)(struct cYAML *tree,
4374 struct cYAML **show_rc,
4375 struct cYAML **err_rc);
4377 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4378 struct cYAML **err_rc)
4380 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4382 net = cYAML_get_object_item(tree, "net");
4383 gw = cYAML_get_object_item(tree, "gateway");
4384 hop = cYAML_get_object_item(tree, "hop");
4385 prio = cYAML_get_object_item(tree, "priority");
4386 sen = cYAML_get_object_item(tree, "health_sensitivity");
4387 seq_no = cYAML_get_object_item(tree, "seq_no");
4389 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4390 (gw) ? gw->cy_valuestring : NULL,
4391 (hop) ? hop->cy_valueint : -1,
4392 (prio) ? prio->cy_valueint : -1,
4393 (sen) ? sen->cy_valueint : -1,
4394 (seq_no) ? seq_no->cy_valueint : -1,
4400 * 0: <intf_name>['['<expr>']']
4401 * 1: <intf_name>['['<expr>']']
4403 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4404 struct lnet_dlc_network_descr *nw_descr)
4406 struct cYAML *child = NULL;
4407 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4408 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4410 if (intf_tree == NULL || nw_descr == NULL)
4411 return LUSTRE_CFG_RC_BAD_PARAM;
4413 /* now grab all the interfaces and their cpts */
4414 child = intf_tree->cy_child;
4415 while (child != NULL) {
4416 if (child->cy_valuestring == NULL) {
4417 child = child->cy_next;
4421 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4424 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4425 child->cy_valuestring,
4426 strlen(child->cy_valuestring));
4427 if (rc != LUSTRE_CFG_RC_NO_ERR)
4431 child = child->cy_next;
4435 return LUSTRE_CFG_RC_MISSING_PARAM;
4440 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4442 list_del(&intf_descr->intf_on_network);
4443 free_intf_descr(intf_descr);
4450 yaml_extract_cmn_tunables(struct cYAML *tree,
4451 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4453 struct cYAML *tun, *item;
4455 tun = cYAML_get_object_item(tree, "tunables");
4457 item = cYAML_get_object_item(tun, "peer_timeout");
4459 tunables->lct_peer_timeout = item->cy_valueint;
4461 tunables->lct_peer_timeout = -1;
4462 item = cYAML_get_object_item(tun, "peer_credits");
4464 tunables->lct_peer_tx_credits = item->cy_valueint;
4465 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4467 tunables->lct_peer_rtr_credits = item->cy_valueint;
4468 item = cYAML_get_object_item(tun, "credits");
4470 tunables->lct_max_tx_credits = item->cy_valueint;
4479 yaml_extract_tunables(struct cYAML *tree,
4480 struct lnet_ioctl_config_lnd_tunables *tunables,
4485 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4490 lustre_yaml_extract_lnd_tunables(tree, net_type,
4497 yaml_extract_cpt(struct cYAML *tree,
4498 struct cfs_expr_list **global_cpts)
4503 smp = cYAML_get_object_item(tree, "CPT");
4505 rc = cfs_expr_list_parse(smp->cy_valuestring,
4506 strlen(smp->cy_valuestring),
4507 0, UINT_MAX, global_cpts);
4509 *global_cpts = NULL;
4515 * - net type: <net>[<NUM>]
4517 * - nid: <ip>@<net>[<NUM>]
4520 * 0: <intf_name>['['<expr>']']
4521 * 1: <intf_name>['['<expr>']']
4523 * peer_timeout: <NUM>
4524 * peer_credits: <NUM>
4525 * peer_buffer_credits: <NUM>
4528 * peercredits_hiw: <NUM>
4529 * map_on_demand: <NUM>
4530 * concurrent_sends: <NUM>
4531 * fmr_pool_size: <NUM>
4532 * fmr_flush_trigger: <NUM>
4535 * At least one interface is required. If no interfaces are provided the
4536 * network interface can not be configured.
4538 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4539 struct cYAML **err_rc)
4541 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4543 int num_entries = 0, rc;
4544 struct lnet_dlc_network_descr nw_descr;
4545 struct cfs_expr_list *global_cpts = NULL;
4546 struct lnet_ioctl_config_lnd_tunables tunables;
4549 memset(&tunables, 0, sizeof(tunables));
4550 /* Use LND defaults */
4551 tunables.lt_cmn.lct_peer_timeout = -1;
4552 tunables.lt_cmn.lct_peer_tx_credits = -1;
4553 tunables.lt_cmn.lct_peer_rtr_credits = -1;
4554 tunables.lt_cmn.lct_max_tx_credits = -1;
4556 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4557 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4559 ip2net = cYAML_get_object_item(tree, "ip2net");
4560 net = cYAML_get_object_item(tree, "net type");
4562 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4564 nw_descr.nw_id = LOLND;
4567 * if neither net nor ip2nets are present, then we can not
4568 * configure the network.
4570 if (!net && !ip2net)
4571 return LUSTRE_CFG_RC_MISSING_PARAM;
4573 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4574 if (local_nis == NULL)
4575 return LUSTRE_CFG_RC_MISSING_PARAM;
4577 if (!cYAML_is_sequence(local_nis))
4578 return LUSTRE_CFG_RC_BAD_PARAM;
4580 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4581 intf = cYAML_get_object_item(item, "interfaces");
4584 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4585 if (num_entries <= 0) {
4586 cYAML_build_error(num_entries, -1, "ni", "add",
4587 "bad interface list",
4589 return LUSTRE_CFG_RC_BAD_PARAM;
4593 found = yaml_extract_tunables(tree, &tunables,
4594 LNET_NETTYP(nw_descr.nw_id));
4595 yaml_extract_cpt(tree, &global_cpts);
4596 seq_no = cYAML_get_object_item(tree, "seq_no");
4598 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4599 (ip2net) ? ip2net->cy_valuestring : NULL,
4600 (found) ? &tunables : NULL,
4601 (seq_no) ? seq_no->cy_valueint : -1,
4604 if (global_cpts != NULL)
4605 cfs_expr_list_free(global_cpts);
4612 * - net-spec: <tcp|o2ib|gni>[NUM]
4614 * 0: <intf name>['['<expr>']']
4615 * 1: <intf name>['['<expr>']']
4617 * 0: <expr.expr.expr.expr>
4618 * 1: <expr.expr.expr.expr>
4620 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4621 struct cYAML **show_rc,
4622 struct cYAML **err_rc)
4624 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4626 struct lustre_lnet_ip2nets ip2nets;
4627 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4629 int rc = LUSTRE_CFG_RC_NO_ERR;
4630 struct cfs_expr_list *global_cpts = NULL;
4631 struct cfs_expr_list *el, *el_tmp;
4632 struct lnet_ioctl_config_lnd_tunables tunables;
4633 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4636 memset(&tunables, 0, sizeof(tunables));
4638 /* initialize all lists */
4639 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4640 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4641 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4643 net = cYAML_get_object_item(tree, "net-spec");
4645 return LUSTRE_CFG_RC_BAD_PARAM;
4647 if (net != NULL && net->cy_valuestring == NULL)
4648 return LUSTRE_CFG_RC_BAD_PARAM;
4650 /* assign the network id */
4651 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4652 if (ip2nets.ip2nets_net.nw_id == LNET_NET_ANY)
4653 return LUSTRE_CFG_RC_BAD_PARAM;
4655 seq_no = cYAML_get_object_item(tree, "seq_no");
4657 intf = cYAML_get_object_item(tree, "interfaces");
4659 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4661 return LUSTRE_CFG_RC_BAD_PARAM;
4664 ip_range = cYAML_get_object_item(tree, "ip-range");
4665 if (ip_range != NULL) {
4666 item = ip_range->cy_child;
4667 while (item != NULL) {
4668 if (item->cy_valuestring == NULL) {
4669 item = item->cy_next;
4673 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4674 item->cy_valuestring);
4676 if (rc != LUSTRE_CFG_RC_NO_ERR)
4679 item = item->cy_next;
4683 found = yaml_extract_tunables(tree, &tunables,
4684 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4685 yaml_extract_cpt(tree, &global_cpts);
4687 rc = lustre_lnet_config_ip2nets(&ip2nets,
4688 (found) ? &tunables : NULL,
4690 (seq_no) ? seq_no->cy_valueint : -1,
4693 if (global_cpts != NULL)
4694 cfs_expr_list_free(global_cpts);
4697 * don't stop because there was no match. Continue processing the
4698 * rest of the rules. If non-match then nothing is configured
4700 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4701 rc = LUSTRE_CFG_RC_NO_ERR;
4703 list_for_each_entry_safe(intf_descr, intf_tmp,
4704 &ip2nets.ip2nets_net.nw_intflist,
4706 list_del(&intf_descr->intf_on_network);
4707 free_intf_descr(intf_descr);
4710 list_for_each_entry_safe(ip_range_descr, tmp,
4711 &ip2nets.ip2nets_ip_ranges,
4713 list_del(&ip_range_descr->ipr_entry);
4714 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4716 list_del(&el->el_link);
4717 cfs_expr_list_free(el);
4719 free(ip_range_descr);
4725 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4726 struct cYAML **err_rc)
4728 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4730 int num_entries, rc;
4731 struct lnet_dlc_network_descr nw_descr;
4733 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4734 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4736 net = cYAML_get_object_item(tree, "net type");
4738 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4740 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4741 if (local_nis == NULL)
4742 return LUSTRE_CFG_RC_MISSING_PARAM;
4744 if (!cYAML_is_sequence(local_nis))
4745 return LUSTRE_CFG_RC_BAD_PARAM;
4747 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4748 intf = cYAML_get_object_item(item, "interfaces");
4751 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4752 if (num_entries <= 0) {
4753 cYAML_build_error(num_entries, -1, "ni", "add",
4754 "bad interface list",
4756 return LUSTRE_CFG_RC_BAD_PARAM;
4760 seq_no = cYAML_get_object_item(tree, "seq_no");
4762 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4763 (seq_no) ? seq_no->cy_valueint : -1,
4769 /* Create a nidstring parseable by the nidstrings library from the nid
4770 * information encoded in the CYAML structure.
4771 * NOTE: Caller must free memory allocated to nidstr
4773 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4774 char *prim_nid, int cmd)
4776 int num_strs = 0, rc;
4777 size_t buf_size, buf_pos, nidstr_len = 0;
4779 struct cYAML *child = NULL, *entry = NULL;
4781 if (cYAML_is_sequence(nids_entry)) {
4782 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4783 entry = cYAML_get_object_item(child, "nid");
4784 /* don't count an empty entry */
4785 if (!entry || !entry->cy_valuestring)
4789 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4790 if (cmd == LNETCTL_DEL_CMD) {
4792 * primary nid is present in the list of
4793 * nids so that means we want to delete
4794 * the entire peer, so no need to go
4795 * further. Just delete the entire peer.
4797 return LUSTRE_CFG_RC_NO_ERR;
4804 * + 1 for the space separating each string, and
4805 * accounts for the terminating null char
4807 nidstr_len += strlen(entry->cy_valuestring) + 1;
4812 if (num_strs == 0 && !prim_nid)
4813 return LUSTRE_CFG_RC_MISSING_PARAM;
4814 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4815 return LUSTRE_CFG_RC_NO_ERR;
4817 buffer = malloc(nidstr_len);
4819 return LUSTRE_CFG_RC_OUT_OF_MEM;
4821 /* now grab all the nids */
4824 buf_size = nidstr_len;
4826 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4827 entry = cYAML_get_object_item(child, "nid");
4828 if (!entry || !entry->cy_valuestring)
4832 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4836 rc = snprintf(buffer + buf_pos, buf_size, " ");
4837 buf_pos += (rc < buf_size) ? rc : buf_size;
4838 buf_size = nidstr_len - buf_pos;
4841 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4842 entry->cy_valuestring);
4843 buf_pos += (rc < buf_size) ? rc : buf_size;
4844 buf_size = nidstr_len - buf_pos;
4849 return LUSTRE_CFG_RC_NO_ERR;
4852 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4853 struct cYAML **err_rc, int cmd)
4855 int rc, num_nids = 0, seqn;
4856 bool mr_value = false;
4857 char *nidstr = NULL, *prim_nidstr;
4858 char err_str[LNET_MAX_STR_LEN];
4859 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4860 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4861 lnet_nid_t pnid = LNET_NID_ANY;
4864 seq_no = cYAML_get_object_item(tree, "seq_no");
4865 seqn = seq_no ? seq_no->cy_valueint : -1;
4867 prim_nid = cYAML_get_object_item(tree, "primary nid");
4868 peer_nis = cYAML_get_object_item(tree, "peer ni");
4870 rc = LUSTRE_CFG_RC_BAD_PARAM;
4871 snprintf(err_str, LNET_MAX_STR_LEN,
4872 "\"primary nid\" must be specified");
4876 prim_nidstr = prim_nid->cy_valuestring;
4878 /* if the provided primary NID is bad, no need to go any further */
4879 pnid = libcfs_str2nid(prim_nidstr);
4880 if (pnid == LNET_NID_ANY) {
4881 rc = LUSTRE_CFG_RC_BAD_PARAM;
4882 snprintf(err_str, LNET_MAX_STR_LEN,
4883 "badly formatted primary NID: %s", prim_nidstr);
4887 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4888 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4889 snprintf(err_str, LNET_MAX_STR_LEN,
4890 "No nids defined in YAML block");
4892 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4893 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4895 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4896 snprintf(err_str, LNET_MAX_STR_LEN,
4897 "Unrecognized error %d", rc);
4903 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4904 LNET_MAX_NIDS_PER_PEER,
4912 if (cmd == LNETCTL_ADD_CMD) {
4913 mr = cYAML_get_object_item(tree, "Multi-Rail");
4915 if (mr && mr->cy_valuestring) {
4916 if (strcmp(mr->cy_valuestring, "False") == 0)
4918 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4919 rc = LUSTRE_CFG_RC_BAD_PARAM;
4920 snprintf(err_str, LNET_MAX_STR_LEN,
4921 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4922 mr->cy_valuestring);
4928 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4929 num_nids, mr_value, force,
4936 if (rc != LUSTRE_CFG_RC_NO_ERR)
4937 cYAML_build_error(rc, seqn, "peer",
4938 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4944 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4945 struct cYAML **err_rc)
4947 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4950 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4951 struct cYAML **err_rc)
4953 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4956 static int handle_yaml_config_buffers(struct cYAML *tree,
4957 struct cYAML **show_rc,
4958 struct cYAML **err_rc)
4961 struct cYAML *tiny, *small, *large, *seq_no;
4963 tiny = cYAML_get_object_item(tree, "tiny");
4964 small = cYAML_get_object_item(tree, "small");
4965 large = cYAML_get_object_item(tree, "large");
4966 seq_no = cYAML_get_object_item(tree, "seq_no");
4968 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4969 (small) ? small->cy_valueint : -1,
4970 (large) ? large->cy_valueint : -1,
4971 (seq_no) ? seq_no->cy_valueint : -1,
4977 static int handle_yaml_config_routing(struct cYAML *tree,
4978 struct cYAML **show_rc,
4979 struct cYAML **err_rc)
4981 int rc = LUSTRE_CFG_RC_NO_ERR;
4982 struct cYAML *seq_no, *enable;
4984 seq_no = cYAML_get_object_item(tree, "seq_no");
4985 enable = cYAML_get_object_item(tree, "enable");
4988 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4990 seq_no->cy_valueint : -1,
4997 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4998 struct cYAML **err_rc)
5002 struct cYAML *seq_no;
5004 net = cYAML_get_object_item(tree, "net");
5005 gw = cYAML_get_object_item(tree, "gateway");
5006 seq_no = cYAML_get_object_item(tree, "seq_no");
5008 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5009 (gw) ? gw->cy_valuestring : NULL,
5010 (seq_no) ? seq_no->cy_valueint : -1,
5014 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5015 struct cYAML **err_rc)
5017 struct cYAML *seq_no;
5019 seq_no = cYAML_get_object_item(tree, "seq_no");
5021 return lustre_lnet_enable_routing(0, (seq_no) ?
5022 seq_no->cy_valueint : -1,
5026 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5027 struct cYAML **err_rc)
5033 struct cYAML *detail;
5034 struct cYAML *seq_no;
5036 net = cYAML_get_object_item(tree, "net");
5037 gw = cYAML_get_object_item(tree, "gateway");
5038 hop = cYAML_get_object_item(tree, "hop");
5039 prio = cYAML_get_object_item(tree, "priority");
5040 detail = cYAML_get_object_item(tree, "detail");
5041 seq_no = cYAML_get_object_item(tree, "seq_no");
5043 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5044 (gw) ? gw->cy_valuestring : NULL,
5045 (hop) ? hop->cy_valueint : -1,
5046 (prio) ? prio->cy_valueint : -1,
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_net(struct cYAML *tree, struct cYAML **show_rc,
5053 struct cYAML **err_rc)
5055 struct cYAML *net, *detail, *seq_no;
5057 net = cYAML_get_object_item(tree, "net type");
5058 detail = cYAML_get_object_item(tree, "detail");
5059 seq_no = cYAML_get_object_item(tree, "seq_no");
5061 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5062 (detail) ? detail->cy_valueint : 0,
5063 (seq_no) ? seq_no->cy_valueint : -1,
5064 show_rc, err_rc, false);
5067 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5068 struct cYAML **err_rc)
5070 struct cYAML *seq_no;
5072 seq_no = cYAML_get_object_item(tree, "seq_no");
5074 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5075 show_rc, err_rc, false);
5078 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5079 struct cYAML **err_rc)
5081 struct cYAML *seq_no, *nid, *detail;
5083 seq_no = cYAML_get_object_item(tree, "seq_no");
5084 detail = cYAML_get_object_item(tree, "detail");
5085 nid = cYAML_get_object_item(tree, "nid");
5087 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5088 (detail) ? detail->cy_valueint : 0,
5089 (seq_no) ? seq_no->cy_valueint : -1,
5090 show_rc, err_rc, false);
5093 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5094 struct cYAML **err_rc)
5096 struct cYAML *seq_no;
5098 seq_no = cYAML_get_object_item(tree, "seq_no");
5100 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5104 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5105 struct cYAML **err_rc)
5107 struct cYAML *seq_no, *range;
5109 seq_no = cYAML_get_object_item(tree, "seq_no");
5110 range = cYAML_get_object_item(tree, "range");
5112 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5113 seq_no ? seq_no->cy_valueint : -1,
5117 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5118 struct cYAML **err_rc)
5120 struct cYAML *seq_no;
5122 seq_no = cYAML_get_object_item(tree, "seq_no");
5124 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5128 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5129 struct cYAML **err_rc)
5131 struct cYAML *seq_no;
5133 seq_no = cYAML_get_object_item(tree, "seq_no");
5135 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5139 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5140 struct cYAML **err_rc)
5142 struct cYAML *seq_no, *idx;
5144 seq_no = cYAML_get_object_item(tree, "seq_no");
5145 idx = cYAML_get_object_item(tree, "idx");
5147 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5148 seq_no ? seq_no->cy_valueint : -1,
5152 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5153 struct cYAML **err_rc)
5155 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5156 union lnet_udsp_action action;
5158 seq_no = cYAML_get_object_item(tree, "seq_no");
5159 src = cYAML_get_object_item(tree, "src");
5160 rte = cYAML_get_object_item(tree, "rte");
5161 dst = cYAML_get_object_item(tree, "dst");
5162 prio = cYAML_get_object_item(tree, "priority");
5163 idx = cYAML_get_object_item(tree, "idx");
5165 action.udsp_priority = prio ? prio->cy_valueint : -1;
5167 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5168 dst ? dst->cy_valuestring : NULL,
5169 rte ? rte->cy_valuestring : NULL,
5170 prio ? "priority" : "",
5172 idx ? idx->cy_valueint : -1,
5173 seq_no ? seq_no->cy_valueint : -1,
5177 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5178 struct cYAML **err_rc)
5180 struct cYAML *seq_no;
5183 seq_no = cYAML_get_object_item(tree, "seq_no");
5184 idx = cYAML_get_object_item(tree, "idx");
5186 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5187 seq_no ? seq_no->cy_valueint : -1,
5191 static int handle_yaml_config_global_settings(struct cYAML *tree,
5192 struct cYAML **show_rc,
5193 struct cYAML **err_rc)
5195 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5196 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5200 seq_no = cYAML_get_object_item(tree, "seq_no");
5201 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5202 if (!max_intf) /* try legacy name */
5203 max_intf = cYAML_get_object_item(tree, "max_intf");
5205 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5206 seq_no ? seq_no->cy_valueint
5210 numa = cYAML_get_object_item(tree, "numa_range");
5212 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5213 seq_no ? seq_no->cy_valueint
5217 discovery = cYAML_get_object_item(tree, "discovery");
5219 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5220 seq_no ? seq_no->cy_valueint
5224 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5225 if (drop_asym_route)
5226 rc = lustre_lnet_config_drop_asym_route(
5227 drop_asym_route->cy_valueint,
5228 seq_no ? seq_no->cy_valueint : -1,
5231 retry = cYAML_get_object_item(tree, "retry_count");
5233 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5234 seq_no ? seq_no->cy_valueint
5238 tto = cYAML_get_object_item(tree, "transaction_timeout");
5240 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5241 seq_no ? seq_no->cy_valueint
5245 sen = cYAML_get_object_item(tree, "health_sensitivity");
5247 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5248 seq_no ? seq_no->cy_valueint
5252 recov = cYAML_get_object_item(tree, "recovery_interval");
5254 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5255 seq_no ? seq_no->cy_valueint
5259 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5261 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5262 seq_no ? seq_no->cy_valueint
5266 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5268 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5269 seq_no ? seq_no->cy_valueint
5273 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5275 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5276 seq_no ? seq_no->cy_valueint
5283 static int handle_yaml_del_global_settings(struct cYAML *tree,
5284 struct cYAML **show_rc,
5285 struct cYAML **err_rc)
5287 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5290 seq_no = cYAML_get_object_item(tree, "seq_no");
5291 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5292 if (!max_intf) /* try legacy name */
5293 max_intf = cYAML_get_object_item(tree, "max_intf");
5295 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5296 seq_no ? seq_no->cy_valueint
5300 numa = cYAML_get_object_item(tree, "numa_range");
5302 rc = lustre_lnet_config_numa_range(0,
5303 seq_no ? seq_no->cy_valueint
5307 /* peer discovery is enabled by default */
5308 discovery = cYAML_get_object_item(tree, "discovery");
5310 rc = lustre_lnet_config_discovery(1,
5311 seq_no ? seq_no->cy_valueint
5315 /* asymmetrical route messages are accepted by default */
5316 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5317 if (drop_asym_route)
5318 rc = lustre_lnet_config_drop_asym_route(
5319 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5324 static int handle_yaml_show_global_settings(struct cYAML *tree,
5325 struct cYAML **show_rc,
5326 struct cYAML **err_rc)
5328 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5329 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5333 seq_no = cYAML_get_object_item(tree, "seq_no");
5334 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5335 if (!max_intf) /* try legacy name */
5336 max_intf = cYAML_get_object_item(tree, "max_intf");
5338 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5342 numa = cYAML_get_object_item(tree, "numa_range");
5344 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5348 discovery = cYAML_get_object_item(tree, "discovery");
5350 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5354 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5355 if (drop_asym_route)
5356 rc = lustre_lnet_show_drop_asym_route(
5357 seq_no ? seq_no->cy_valueint : -1,
5360 retry = cYAML_get_object_item(tree, "retry_count");
5362 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5366 tto = cYAML_get_object_item(tree, "transaction_timeout");
5368 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5372 sen = cYAML_get_object_item(tree, "health_sensitivity");
5374 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5378 recov = cYAML_get_object_item(tree, "recovery_interval");
5380 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5384 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5386 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5390 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5392 rc = lustre_lnet_show_response_tracking(seq_no ?
5393 seq_no->cy_valueint :
5397 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5399 rc = lustre_lnet_show_recovery_limit(seq_no ?
5400 seq_no->cy_valueint :
5407 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5408 struct cYAML **err_rc)
5410 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5412 seq_no = cYAML_get_object_item(tree, "seq_no");
5413 nid = cYAML_get_object_item(tree, "primary nid");
5414 timeout = cYAML_get_object_item(tree, "timeout");
5415 src_nid = cYAML_get_object_item(tree, "source_nid");
5417 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5418 (src_nid) ? src_nid->cy_valuestring : NULL,
5419 (timeout) ? timeout->cy_valueint : 1000,
5420 (seq_no) ? seq_no->cy_valueint : -1,
5424 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5425 struct cYAML **err_rc)
5427 struct cYAML *seq_no, *nid, *force;
5429 seq_no = cYAML_get_object_item(tree, "seq_no");
5430 nid = cYAML_get_object_item(tree, "primary nid");
5431 force = cYAML_get_object_item(tree, "force");
5433 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5434 (force) ? force->cy_valueint : 0,
5435 (seq_no) ? seq_no->cy_valueint : -1,
5439 static int handle_yaml_no_op()
5441 return LUSTRE_CFG_RC_NO_ERR;
5444 struct lookup_cmd_hdlr_tbl {
5449 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5450 { .name = "route", .cb = handle_yaml_config_route },
5451 { .name = "net", .cb = handle_yaml_config_ni },
5452 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5453 { .name = "peer", .cb = handle_yaml_config_peer },
5454 { .name = "routing", .cb = handle_yaml_config_routing },
5455 { .name = "buffers", .cb = handle_yaml_config_buffers },
5456 { .name = "statistics", .cb = handle_yaml_no_op },
5457 { .name = "global", .cb = handle_yaml_config_global_settings},
5458 { .name = "numa", .cb = handle_yaml_config_numa },
5459 { .name = "ping", .cb = handle_yaml_no_op },
5460 { .name = "discover", .cb = handle_yaml_no_op },
5461 { .name = "udsp", .cb = handle_yaml_config_udsp },
5464 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5465 { .name = "route", .cb = handle_yaml_del_route },
5466 { .name = "net", .cb = handle_yaml_del_ni },
5467 { .name = "ip2nets", .cb = handle_yaml_no_op },
5468 { .name = "peer", .cb = handle_yaml_del_peer },
5469 { .name = "routing", .cb = handle_yaml_del_routing },
5470 { .name = "buffers", .cb = handle_yaml_no_op },
5471 { .name = "statistics", .cb = handle_yaml_no_op },
5472 { .name = "global", .cb = handle_yaml_del_global_settings},
5473 { .name = "numa", .cb = handle_yaml_del_numa },
5474 { .name = "ping", .cb = handle_yaml_no_op },
5475 { .name = "discover", .cb = handle_yaml_no_op },
5476 { .name = "udsp", .cb = handle_yaml_del_udsp },
5479 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5480 { .name = "route", .cb = handle_yaml_show_route },
5481 { .name = "net", .cb = handle_yaml_show_net },
5482 { .name = "peer", .cb = handle_yaml_show_peers },
5483 { .name = "ip2nets", .cb = handle_yaml_no_op },
5484 { .name = "routing", .cb = handle_yaml_show_routing },
5485 { .name = "buffers", .cb = handle_yaml_show_routing },
5486 { .name = "statistics", .cb = handle_yaml_show_stats },
5487 { .name = "global", .cb = handle_yaml_show_global_settings},
5488 { .name = "numa", .cb = handle_yaml_show_numa },
5489 { .name = "ping", .cb = handle_yaml_no_op },
5490 { .name = "discover", .cb = handle_yaml_no_op },
5491 { .name = "udsp", .cb = handle_yaml_show_udsp },
5494 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5495 { .name = "route", .cb = handle_yaml_no_op },
5496 { .name = "net", .cb = handle_yaml_no_op },
5497 { .name = "peer", .cb = handle_yaml_no_op },
5498 { .name = "ip2nets", .cb = handle_yaml_no_op },
5499 { .name = "routing", .cb = handle_yaml_no_op },
5500 { .name = "buffers", .cb = handle_yaml_no_op },
5501 { .name = "statistics", .cb = handle_yaml_no_op },
5502 { .name = "global", .cb = handle_yaml_no_op },
5503 { .name = "numa", .cb = handle_yaml_no_op },
5504 { .name = "ping", .cb = handle_yaml_ping },
5505 { .name = "discover", .cb = handle_yaml_discover },
5508 static cmd_handler_t lookup_fn(char *key,
5509 struct lookup_cmd_hdlr_tbl *tbl)
5515 for (i = 0; tbl[i].name != NULL; i++) {
5516 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5523 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5524 struct cYAML **show_rc, struct cYAML **err_rc)
5526 struct cYAML *tree, *item = NULL, *head, *child;
5528 char err_str[LNET_MAX_STR_LEN];
5529 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5531 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5533 return LUSTRE_CFG_RC_BAD_PARAM;
5535 child = tree->cy_child;
5536 while (child != NULL) {
5537 cb = lookup_fn(child->cy_string, table);
5539 snprintf(err_str, sizeof(err_str),
5540 "\"call back for '%s' not found\"",
5542 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5543 "yaml", "helper", err_str, err_rc);
5547 if (cYAML_is_sequence(child)) {
5548 while ((head = cYAML_get_next_seq_item(child, &item))
5550 rc = cb(head, show_rc, err_rc);
5551 if (rc != LUSTRE_CFG_RC_NO_ERR)
5555 rc = cb(child, show_rc, err_rc);
5556 if (rc != LUSTRE_CFG_RC_NO_ERR)
5560 child = child->cy_next;
5564 cYAML_free_tree(tree);
5569 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5571 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5575 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5577 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5581 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5583 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5587 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5589 return lustre_yaml_cb_helper(f, lookup_exec_tbl,