1 // SPDX-License-Identifier: LGPL-2.0
4 * Copyright (c) 2014, 2017, Intel Corporation.
8 * This file is part of Lustre, http://www.lustre.org/
11 * 1. APIs that take the actual parameters expanded. This is for other
12 * entities that would like to link against the library and call the APIs
13 * directly without having to form an intermediate representation.
14 * 2. APIs that take a YAML file and parses out the information there and
15 * calls the APIs mentioned in 1
17 * Author: Amir Shehata <amir.shehata@intel.com>
29 #include <sys/ioctl.h>
31 #include <libcfs/util/ioctl.h>
32 #include <libcfs/util/hash.h>
33 #include <linux/lnet/lnetctl.h>
35 #include <sys/types.h>
39 #include <rdma/rdma_user_cm.h>
40 #include "liblnetconfig.h"
42 #include <libcfs/util/param.h>
44 #ifndef HAVE_USRSPC_RDMA_PS_TCP
45 #define RDMA_PS_TCP 0x0106
48 #define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
49 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
53 * lustre_lnet_ip_range_descr
54 * Describes an IP range.
55 * Each octect is an expression
57 struct lustre_lnet_ip_range_descr {
58 struct list_head ipr_entry;
59 struct list_head ipr_expr;
64 * Describes an ip2nets rule. This can be on a list of rules.
66 struct lustre_lnet_ip2nets {
67 struct lnet_dlc_network_descr ip2nets_net;
68 struct list_head ip2nets_ip_ranges;
71 static int open_sysfs_file(const char *path, const char *attr, const int mode)
74 char filename[LNET_MAX_STR_LEN];
75 size_t size = sizeof(filename);
78 namelen = snprintf(filename, size, "%s%s", path, attr);
80 filename[size - 1] = '\0';
82 fd = open(filename, mode);
87 static int read_sysfs_file(const char *path, const char *attr,
88 void *val, const size_t size, const int nelem)
91 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
93 fd = open_sysfs_file(path, attr, O_RDONLY);
95 return LUSTRE_CFG_RC_NO_MATCH;
97 if (read(fd, val, size * nelem) == -1)
100 rc = LUSTRE_CFG_RC_NO_ERR;
107 static int write_sysfs_file(const char *path, const char *attr,
108 void *val, const size_t size, const int nelem)
111 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
113 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
115 return LUSTRE_CFG_RC_NO_MATCH;
117 if (write(fd, val, size * nelem) == -1)
120 rc = LUSTRE_CFG_RC_NO_ERR;
129 * frees the memory allocated for an intf descriptor.
131 static void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
136 if (intf_descr->cpt_expr != NULL)
137 cfs_expr_list_free(intf_descr->cpt_expr);
142 * lustre_lnet_add_ip_range
144 * given a string of the format:
145 * <expr.expr.expr.expr> parse each expr into
146 * a lustre_lnet_ip_range_descr structure and insert on the list.
148 * This function is called from
149 * YAML on each ip-range.
150 * As a result of lnetctl command
151 * When building a NID or P2P selection rules
153 static int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
155 struct lustre_lnet_ip_range_descr *ip_range;
158 ip_range = calloc(1, sizeof(*ip_range));
159 if (ip_range == NULL)
160 return LUSTRE_CFG_RC_OUT_OF_MEM;
162 INIT_LIST_HEAD(&ip_range->ipr_entry);
163 INIT_LIST_HEAD(&ip_range->ipr_expr);
165 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
166 &ip_range->ipr_expr);
168 return LUSTRE_CFG_RC_BAD_PARAM;
170 list_add_tail(&ip_range->ipr_entry, list);
172 return LUSTRE_CFG_RC_NO_ERR;
175 static int lustre_lnet_add_intf_descr(struct list_head *list, char *intf,
178 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
180 struct lnet_dlc_intf_descr *intf_descr = NULL;
182 char intf_string[LNET_MAX_STR_LEN];
184 if (len >= LNET_MAX_STR_LEN)
185 return LUSTRE_CFG_RC_BAD_PARAM;
187 strncpy(intf_string, intf, len);
188 intf_string[len] = '\0';
190 intf_descr = calloc(1, sizeof(*intf_descr));
191 if (intf_descr == NULL)
192 return LUSTRE_CFG_RC_OUT_OF_MEM;
194 INIT_LIST_HEAD(&intf_descr->intf_on_network);
196 intf_name = intf_string;
197 open_sq_bracket = strchr(intf_string, '[');
198 if (open_sq_bracket != NULL) {
199 close_sq_bracket = strchr(intf_string, ']');
200 if (close_sq_bracket == NULL) {
202 return LUSTRE_CFG_RC_BAD_PARAM;
204 rc = cfs_expr_list_parse(open_sq_bracket,
205 strlen(open_sq_bracket), 0, UINT_MAX,
206 &intf_descr->cpt_expr);
209 return LUSTRE_CFG_RC_BAD_PARAM;
211 strncpy(intf_descr->intf_name, intf_name,
212 open_sq_bracket - intf_name);
213 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
215 strcpy(intf_descr->intf_name, intf_name);
216 intf_descr->cpt_expr = NULL;
219 list_add_tail(&intf_descr->intf_on_network, list);
221 return LUSTRE_CFG_RC_NO_ERR;
224 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
226 if (nw_descr != NULL) {
228 INIT_LIST_HEAD(&nw_descr->network_on_rule);
229 INIT_LIST_HEAD(&nw_descr->nw_intflist);
233 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
234 int max_nids, char *err_str)
236 int rc, num_nids = 0;
237 struct list_head nidlist;
240 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
241 return LUSTRE_CFG_RC_BAD_PARAM;
244 if (strchr(nidstr, '*')) {
245 snprintf(err_str, LNET_MAX_STR_LEN,
246 "asterisk not allowed in nidstring \"%s\"", nidstr);
247 return LUSTRE_CFG_RC_BAD_PARAM;
250 INIT_LIST_HEAD(&nidlist);
251 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
253 snprintf(err_str, LNET_MAX_STR_LEN,
254 "Unable to parse nidlist from: %s\n", nidstr);
255 return LUSTRE_CFG_RC_BAD_PARAM;
258 if (list_empty(&nidlist)) {
259 snprintf(err_str, LNET_MAX_STR_LEN,
260 "\"%s\" does not specify any valid nid lists", nidstr);
261 return LUSTRE_CFG_RC_BAD_PARAM;
264 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
265 cfs_free_nidlist(&nidlist);
267 if (num_nids == -1) {
268 snprintf(err_str, LNET_MAX_STR_LEN,
269 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
271 return LUSTRE_CFG_RC_BAD_PARAM;
275 snprintf(err_str, LNET_MAX_STR_LEN,
276 "Failed to expand nidstr: %s", strerror(num_nids));
277 return LUSTRE_CFG_RC_OUT_OF_MEM;
281 snprintf(err_str, LNET_MAX_STR_LEN,
282 "\"%s\" did not expand to any nids", nidstr);
283 return LUSTRE_CFG_RC_BAD_PARAM;
291 * <intf>[<expr>], <intf>[<expr>],..
293 int lustre_lnet_parse_interfaces(char *intf_str,
294 struct lnet_dlc_network_descr *nw_descr)
299 char *cur = intf_str, *next = NULL;
300 char *end = intf_str + strlen(intf_str);
302 struct lnet_dlc_intf_descr *intf_descr, *tmp;
304 if (nw_descr == NULL)
305 return LUSTRE_CFG_RC_BAD_PARAM;
310 open_square = strchr(cur, '[');
311 if (open_square != NULL) {
312 close_square = strchr(cur, ']');
313 if (close_square == NULL) {
314 rc = LUSTRE_CFG_RC_BAD_PARAM;
318 comma = strchr(cur, ',');
319 if (comma != NULL && comma > close_square) {
321 len = next - close_square;
327 comma = strchr(cur, ',');
337 /* Extract net id if its a NID string */
338 net = strchr(cur, '@');
340 nw_descr->nw_id = libcfs_str2net(net + 1);
341 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
342 if (rc != LUSTRE_CFG_RC_NO_ERR)
348 return LUSTRE_CFG_RC_NO_ERR;
351 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
353 list_del(&intf_descr->intf_on_network);
354 free_intf_descr(intf_descr);
360 int lustre_lnet_config_lib_init(void)
362 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
365 void lustre_lnet_config_lib_uninit(void)
367 unregister_ioc_dev(LNET_DEV_ID);
370 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
371 int seq_no, struct cYAML **err_rc)
373 struct libcfs_ioctl_data data;
376 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
378 LIBCFS_IOC_INIT(data);
380 /* Reverse logic is used here in order not to change
381 * the lctl utility */
382 data.ioc_flags = load_ni_from_mod ? 0 : 1;
384 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
386 rc = l_ioctl(LNET_DEV_ID, opc, &data);
390 "\"LNet %s error: %s\"", (up) ? "configure" :
391 "unconfigure", strerror(errno));
395 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
396 "lnet", err_str, err_rc);
401 int yaml_lnet_configure(int flags, const char **msg)
403 char *err = "lnet configure: ";
404 yaml_parser_t setup, reply;
405 char *config = "net:\n";
406 yaml_document_t results;
407 yaml_emitter_t request;
411 /* Initialize configuration parser */
412 rc = yaml_parser_initialize(&setup);
414 yaml_parser_log_error(&setup, stderr, err);
415 yaml_parser_delete(&setup);
419 yaml_parser_set_input_string(&setup, (unsigned char *)config,
421 rc = yaml_parser_load(&setup, &results);
423 yaml_parser_log_error(&setup, stderr, err);
424 yaml_parser_delete(&setup);
427 yaml_parser_delete(&setup);
429 /* Create Netlink emitter to send request to kernel */
430 sk = nl_socket_alloc();
432 yaml_document_delete(&results);
436 /* Setup parser to recieve Netlink packets */
437 rc = yaml_parser_initialize(&reply);
439 yaml_document_delete(&results);
444 rc = yaml_parser_set_input_netlink(&reply, sk, false);
448 yaml_emitter_initialize(&request);
449 rc = yaml_emitter_set_output_netlink(&request, sk, LNET_GENL_NAME,
451 LNET_CMD_CONFIGURE, flags);
452 if (rc == 1) /* 1 is success */
453 rc = yaml_emitter_dump(&request, &results);
455 yaml_emitter_log_error(&request, stderr);
458 yaml_document_t errmsg;
460 rc = yaml_parser_load(&reply, &errmsg);
462 yaml_emitter_delete(&request);
465 *msg = yaml_parser_get_reader_error(&reply);
469 yaml_parser_delete(&reply);
470 yaml_document_delete(&results);
473 return rc == 1 ? 0 : rc;
476 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
477 char *err_str, char *cmd_str)
481 rc = l_ioctl(LNET_DEV_ID, cmd, data);
484 snprintf(err_str, LNET_MAX_STR_LEN,
485 "\"%s peer ni operation failed: %s\"",
486 cmd_str, strerror(errno));
492 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
493 int param, int ioc_call, int seq_no,
494 struct cYAML **show_rc, struct cYAML **err_rc)
497 struct lnet_ioctl_ping_data ping;
498 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
499 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
500 struct lnet_process_id id;
501 char err_str[LNET_MAX_STR_LEN] = {0};
502 char *sep, *token, *end;
505 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
510 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
512 data = calloc(1, len);
516 /* create struct cYAML root object */
517 root = cYAML_create_object(NULL, NULL);
521 ping_node = cYAML_create_seq(root, oper);
522 if (ping_node == NULL)
526 src = libcfs_str2nid(src_nidstr);
527 if (src == LNET_NID_ANY) {
528 snprintf(err_str, sizeof(err_str),
529 "\"cannot parse source NID '%s'\"",
531 rc = LUSTRE_CFG_RC_BAD_PARAM;
532 cYAML_build_error(rc, seq_no, MANAGE_CMD,
533 oper, err_str, err_rc);
540 /* tokenise each nid in string ping_nids */
541 token = strtok(ping_nids, ",");
544 item = cYAML_create_seq_item(ping_node);
548 if (first_seq == NULL)
551 /* check if '-' is a part of NID, token */
552 sep = strchr(token, '-');
554 id.pid = LNET_PID_ANY;
555 /* if no net is specified, libcfs_str2nid() will assume tcp */
556 id.nid = libcfs_str2nid(token);
557 if (id.nid == LNET_NID_ANY) {
558 snprintf(err_str, sizeof(err_str),
559 "\"cannot parse NID '%s'\"",
561 rc = LUSTRE_CFG_RC_BAD_PARAM;
562 cYAML_build_error(rc, seq_no, MANAGE_CMD,
563 oper, err_str, err_rc);
567 if (token[0] == 'u' || token[0] == 'U')
568 id.pid = (strtoul(&token[1], &end, 0) |
569 (LNET_PID_USERFLAG));
571 id.pid = strtoul(token, &end, 0);
573 /* assuming '-' is part of hostname */
575 id.pid = LNET_PID_ANY;
576 id.nid = libcfs_str2nid(token);
577 if (id.nid == LNET_NID_ANY) {
578 snprintf(err_str, sizeof(err_str),
579 "\"cannot parse NID '%s'\"",
581 rc = LUSTRE_CFG_RC_BAD_PARAM;
582 cYAML_build_error(rc, seq_no, MANAGE_CMD,
588 id.nid = libcfs_str2nid(sep + 1);
589 if (id.nid == LNET_NID_ANY) {
590 snprintf(err_str, sizeof(err_str),
591 "\"cannot parse NID '%s'\"",
593 rc = LUSTRE_CFG_RC_BAD_PARAM;
594 cYAML_build_error(rc, seq_no, MANAGE_CMD,
601 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
602 ping.ping_hdr.ioc_len = sizeof(ping);
605 ping.op_param = param;
606 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
607 ping.ping_buf = data;
609 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
612 sizeof(err_str), "failed to %s %s: %s\n", oper,
613 id.pid == LNET_PID_ANY ?
614 libcfs_nid2str(id.nid) :
615 libcfs_id2str(id), strerror(errno));
616 rc = LUSTRE_CFG_RC_BAD_PARAM;
617 cYAML_build_error(rc, seq_no, MANAGE_CMD,
618 oper, err_str, err_rc);
622 if (cYAML_create_string(item, "primary nid",
623 libcfs_nid2str(ping.ping_id.nid)) == NULL)
626 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
627 "True" : "False") == NULL)
630 tmp = cYAML_create_seq(item, "peer ni");
634 for (i = 0; i < ping.ping_count; i++) {
635 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
637 peer_ni = cYAML_create_seq_item(tmp);
640 memset(buf, 0, sizeof buf);
641 snprintf(buf, sizeof buf, "nid");
642 if (cYAML_create_string(peer_ni, buf,
643 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
649 } while ((token = strtok(NULL, ",")) != NULL);
652 rc = LUSTRE_CFG_RC_NO_ERR;
657 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
658 cYAML_free_tree(root);
659 } else if (show_rc != NULL && *show_rc != NULL) {
660 struct cYAML *show_node;
661 show_node = cYAML_get_object_item(*show_rc, oper);
662 if (show_node != NULL && cYAML_is_sequence(show_node)) {
663 cYAML_insert_child(show_node, first_seq);
666 } else if (show_node == NULL) {
667 cYAML_insert_sibling((*show_rc)->cy_child,
671 cYAML_free_tree(root);
680 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
681 int seq_no, struct cYAML **show_rc,
682 struct cYAML **err_rc)
686 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
687 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
691 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
692 struct cYAML **show_rc, struct cYAML **err_rc)
696 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
697 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
701 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
702 bool is_mr, int option, __u32 cmd,
703 char *cmd_type, char *err_str)
705 struct lnet_ioctl_peer_cfg data;
708 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
709 /* When adding a peer we first need to create the peer using the
710 * specified (or implied) primary nid. Then we can add
711 * additional nids to this peer using the primary nid as a key
713 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
714 data.prcfg_mr = is_mr;
715 data.prcfg_prim_nid = nidlist[0];
716 data.prcfg_cfg_nid = LNET_NID_ANY;
717 data.prcfg_count = option;
719 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
725 /* Add or delete any specified NIs associated with the specified
726 * (or implied) primary nid
728 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
729 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
730 data.prcfg_mr = is_mr;
731 data.prcfg_prim_nid = nidlist[0];
732 data.prcfg_cfg_nid = nidlist[nid_idx];
733 data.prcfg_count = option;
735 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
741 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
742 /* In the delete case we may have been given just the
743 * primary nid of the peer. This tells us to delete the peer
744 * completely (rather than just delete some of its NIs)
746 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
747 data.prcfg_prim_nid = nidlist[0];
748 data.prcfg_cfg_nid = LNET_NID_ANY;
749 data.prcfg_count = option;
751 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
758 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
759 int cmd, int num_nids, bool is_mr, int option,
760 int seq_no, struct cYAML **err_rc)
762 int rc = LUSTRE_CFG_RC_NO_ERR;
763 char err_str[LNET_MAX_STR_LEN];
764 lnet_nid_t *lnet_nidlist2 = NULL;
765 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
766 IOC_LIBCFS_DEL_PEER_NI;
767 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
770 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
771 if (!lnet_nidlist2) {
772 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
773 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
776 lnet_nidlist2[0] = pnid;
777 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
780 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
781 num_nids, is_mr, option,
782 ioc_cmd, cmd_str, err_str);
787 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
792 replace_sep(char *str, char sep, char newsep)
798 for (i = 0; i < strlen(str); i++) {
799 /* don't replace ',' within [] */
802 else if (str[i] == ']')
804 else if (str[i] == sep && bracket == 0)
809 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr, int cmd,
810 int option, int seq_no, struct cYAML **err_rc)
813 char err_str[LNET_MAX_STR_LEN] = "Error";
814 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
815 lnet_nid_t pnid = LNET_NID_ANY;
818 rc = LUSTRE_CFG_RC_BAD_PARAM;
819 snprintf(err_str, LNET_MAX_STR_LEN,
820 "--prim_nid must be specified");
824 pnid = libcfs_str2nid(prim_nid);
825 if (pnid == LNET_NID_ANY) {
826 rc = LUSTRE_CFG_RC_BAD_PARAM;
827 snprintf(err_str, LNET_MAX_STR_LEN,
828 "badly formatted primary NID: %s", prim_nid);
835 * if there is no primary nid we need to make the first nid in the
836 * nids list the primary nid
838 replace_sep(nids, ',', ' ');
839 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
840 LNET_MAX_NIDS_PER_PEER, err_str);
847 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
848 cmd, num_nids, is_mr,
852 if (rc != LUSTRE_CFG_RC_NO_ERR)
853 cYAML_build_error(rc, -1, "peer",
854 cmd == LNETCTL_ADD_CMD ? "add" : "del",
860 static int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
861 int sen, int seq_no, struct cYAML **err_rc,
864 int rc, num_nids, idx;
866 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
867 struct lnet_ioctl_config_data data;
868 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
870 if (nw == NULL || nidstr == NULL) {
871 snprintf(err_str, LNET_MAX_STR_LEN,
872 "\"missing mandatory parameter:'%s'\"",
873 (nw == NULL && nidstr == NULL) ? "network, gateway" :
874 (nw == NULL) ? "network" : "gateway");
875 rc = LUSTRE_CFG_RC_MISSING_PARAM;
879 rnet = libcfs_str2net(nw);
880 if (rnet == LNET_NET_ANY) {
881 snprintf(err_str, LNET_MAX_STR_LEN,
882 "\"cannot parse remote net %s\"", nw);
883 rc = LUSTRE_CFG_RC_BAD_PARAM;
887 replace_sep(nidstr, ',', ' ');
888 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
889 LNET_MAX_NIDS_PER_PEER, err_str);
895 for (idx = 0; idx < num_nids; idx++) {
896 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
898 if (cmd == LNETCTL_ADD_CMD) {
899 data.cfg_config_u.cfg_route.rtr_hop = hops;
900 data.cfg_config_u.cfg_route.rtr_priority = prio;
901 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
904 data.cfg_nid = lnet_nidlist[idx];
906 if (cmd == LNETCTL_ADD_CMD)
907 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
910 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
913 if (rc != 0 && errno != EEXIST &&
914 errno != EHOSTUNREACH) {
916 snprintf(err_str, LNET_MAX_STR_LEN,
917 "route operation failed: %s",
920 } else if (errno == EEXIST) {
922 * continue chugging along if one of the
923 * routes already exists
930 cYAML_build_error(rc, seq_no,
931 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
937 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
938 int sen, int seq_no, struct cYAML **err_rc)
941 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
944 hops = LNET_UNDEFINED_HOPS;
945 } else if (hops < 1 || hops > 255) {
946 snprintf(err_str, LNET_MAX_STR_LEN,
947 "\"invalid hop count %d, must be between 1 and 255\"",
949 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
955 } else if (prio < 0) {
956 snprintf(err_str, LNET_MAX_STR_LEN,
957 "\"invalid priority %d, must be greater than 0\"",
959 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
965 } else if (sen < 1) {
966 snprintf(err_str, LNET_MAX_STR_LEN,
967 "\"invalid health sensitivity %d, must be 1 or greater\"",
969 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
973 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
974 err_rc, LNETCTL_ADD_CMD);
977 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
982 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
983 struct cYAML **err_rc)
985 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
989 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
990 int seq_no, struct cYAML **show_rc,
991 struct cYAML **err_rc, bool backup)
993 struct lnet_ioctl_config_data data;
994 lnet_nid_t gateway_nid;
995 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
997 __u32 net = LNET_NET_ANY;
999 struct cYAML *root = NULL, *route = NULL, *item = NULL;
1000 struct cYAML *first_seq = NULL;
1001 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
1005 net = libcfs_str2net(nw);
1006 if (net == LNET_NET_ANY) {
1009 "\"cannot parse net '%s'\"", nw);
1010 rc = LUSTRE_CFG_RC_BAD_PARAM;
1015 /* show all routes without filtering on net */
1020 gateway_nid = libcfs_str2nid(gw);
1021 if (gateway_nid == LNET_NID_ANY) {
1024 "\"cannot parse gateway NID '%s'\"", gw);
1025 rc = LUSTRE_CFG_RC_BAD_PARAM;
1029 /* show all routes with out filtering on gateway */
1030 gateway_nid = LNET_NID_ANY;
1032 if ((hops < 1 && hops != -1) || hops > 255) {
1035 "\"invalid hop count %d, must be between 0 and 256\"",
1037 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1041 /* create struct cYAML root object */
1042 root = cYAML_create_object(NULL, NULL);
1046 route = cYAML_create_seq(root, "route");
1054 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1057 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1063 /* filter on provided data */
1064 if (net != LNET_NET_ANY &&
1065 net != data.cfg_net)
1068 if (gateway_nid != LNET_NID_ANY &&
1069 gateway_nid != data.cfg_nid)
1073 hops != data.cfg_config_u.cfg_route.rtr_hop)
1077 prio != data.cfg_config_u.cfg_route.rtr_priority)
1080 /* default rc to -1 incase we hit the goto */
1084 item = cYAML_create_seq_item(route);
1088 if (first_seq == NULL)
1091 if (cYAML_create_string(item, "net",
1092 libcfs_net2str(data.cfg_net)) == NULL)
1095 if (cYAML_create_string(item, "gateway",
1096 libcfs_nid2str(data.cfg_nid)) == NULL)
1100 if (cYAML_create_number(item, "hop",
1101 (int) data.cfg_config_u.
1102 cfg_route.rtr_hop) ==
1106 if (cYAML_create_number(item, "priority",
1108 cfg_route.rtr_priority) == NULL)
1111 if (cYAML_create_number(item, "health_sensitivity",
1113 cfg_route.rtr_sensitivity) == NULL)
1116 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1118 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1122 cYAML_create_string(item, "state",
1124 "up" : "down") == NULL)
1128 cYAML_create_string(item, "type",
1130 "multi-hop" : "single-hop") == NULL)
1135 /* print output iff show_rc is not provided */
1136 if (show_rc == NULL)
1137 cYAML_print_tree(root);
1139 if (l_errno != ENOENT) {
1142 "\"cannot get routes: %s\"",
1147 rc = LUSTRE_CFG_RC_NO_ERR;
1149 snprintf(err_str, sizeof(err_str), "\"success\"");
1151 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1152 cYAML_free_tree(root);
1153 } else if (show_rc != NULL && *show_rc != NULL) {
1154 struct cYAML *show_node;
1155 /* find the route node, if one doesn't exist then
1156 * insert one. Otherwise add to the one there
1158 show_node = cYAML_get_object_item(*show_rc, "route");
1159 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1160 cYAML_insert_child(show_node, first_seq);
1163 } else if (show_node == NULL) {
1164 cYAML_insert_sibling((*show_rc)->cy_child,
1168 cYAML_free_tree(root);
1174 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1179 static int socket_intf_query(int request, char *intf,
1185 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1186 return LUSTRE_CFG_RC_BAD_PARAM;
1188 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1190 return LUSTRE_CFG_RC_BAD_PARAM;
1192 strcpy(ifr->ifr_name, intf);
1193 rc = ioctl(sockfd, request, ifr);
1195 rc = LUSTRE_CFG_RC_BAD_PARAM;
1202 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1207 memset(&ifr, 0, sizeof(ifr));
1208 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1210 return LUSTRE_CFG_RC_BAD_PARAM;
1212 if ((ifr.ifr_flags & IFF_UP) == 0)
1213 return LUSTRE_CFG_RC_BAD_PARAM;
1215 memset(&ifr, 0, sizeof(ifr));
1216 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1218 return LUSTRE_CFG_RC_BAD_PARAM;
1220 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1221 *ip = bswap_32(*ip);
1223 return LUSTRE_CFG_RC_NO_ERR;
1226 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1229 unsigned int nic_index;
1231 char *nic_addr_path;
1236 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1238 return LUSTRE_CFG_RC_NO_MATCH;
1240 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1241 nic_addr_path = malloc(size);
1243 return LUSTRE_CFG_RC_OUT_OF_MEM;
1244 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1246 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1247 free(nic_addr_path);
1249 return LUSTRE_CFG_RC_NO_MATCH;
1251 addr = strtol(val, NULL, 16);
1252 if (addr == LONG_MIN || addr == LONG_MAX)
1253 return LUSTRE_CFG_RC_NO_MATCH;
1257 return LUSTRE_CFG_RC_NO_ERR;
1261 * for each interface in the array of interfaces find the IP address of
1262 * that interface, create its nid and add it to an array of NIDs.
1263 * Stop if any of the interfaces is down
1265 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1266 lnet_nid_t **nids, __u32 *nnids,
1267 char *err_str, size_t str_len)
1269 int i = 0, count = 0, rc;
1270 struct lnet_dlc_intf_descr *intf;
1271 char val[LNET_MAX_STR_LEN];
1279 if (nw == NULL || nids == NULL) {
1280 snprintf(err_str, str_len,
1281 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1282 return LUSTRE_CFG_RC_BAD_PARAM;
1285 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1288 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1292 *nids = calloc(count, sizeof(lnet_nid_t));
1293 if (*nids == NULL) {
1294 snprintf(err_str, str_len,
1295 "\"out of memory\"");
1296 return LUSTRE_CFG_RC_OUT_OF_MEM;
1299 * special case the GNI interface since it doesn't have an IP
1300 * address. The assumption is that there can only be one GNI
1301 * interface in the system. No interface name is provided.
1303 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1304 rc = read_sysfs_file(gni_nid_path, "nid", val,
1307 snprintf(err_str, str_len,
1308 "\"cannot read gni nid\"");
1311 gni_num = atoi(val);
1313 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1316 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1317 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1318 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1319 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1320 snprintf(err_str, str_len,
1321 "\"couldn't query kfi intf %s\"",
1323 err_str[str_len - 1] = '\0';
1327 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1333 /* look at the other interfaces */
1334 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1335 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1336 /* handle LNDs with numeric interface name */
1337 num = strtoul(intf->intf_name, &endp, 0);
1338 if (endp == intf->intf_name || *endp != '\0') {
1339 rc = LUSTRE_CFG_RC_BAD_PARAM;
1340 snprintf(err_str, str_len,
1341 "\"couldn't query intf %s\"",
1345 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1348 /* handle LNDs with ip interface name */
1349 rc = lustre_lnet_queryip(intf, &ip);
1350 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1351 snprintf(err_str, str_len,
1352 "\"couldn't query intf %s\"",
1356 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1373 * called repeatedly until a match or no more ip range
1375 * ip_range expression
1376 * interface list with all the interface names.
1377 * all the interfaces in the system.
1379 * try to match the ip_range expr to one of the interfaces' IPs in
1380 * the system. If we hit a patch for an interface. Check if that
1381 * interface name is in the list.
1383 * If there are more than one interface in the list, then make sure
1384 * that the IPs for all of these interfaces match the ip ranges
1387 * for each interface in intf_list
1388 * look up the intf name in ifa
1389 * if not there then no match
1390 * check ip obtained from ifa against a match to any of the
1392 * If no match, then fail
1394 * The result is that all the interfaces have to match.
1396 static int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1397 struct list_head *intf_list,
1398 struct list_head *ip_ranges)
1402 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1403 struct ifaddrs *ifaddr = ifa;
1404 struct lustre_lnet_ip_range_descr *ip_range;
1408 * if there are no explicit interfaces, and no ip ranges, then
1409 * configure the first tcp interface we encounter.
1411 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1412 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1413 if (ifaddr->ifa_addr == NULL)
1416 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1419 family = ifaddr->ifa_addr->sa_family;
1420 if (family == AF_INET &&
1421 strcmp(ifaddr->ifa_name, "lo") != 0) {
1422 rc = lustre_lnet_add_intf_descr
1423 (intf_list, ifaddr->ifa_name,
1424 strlen(ifaddr->ifa_name));
1426 if (rc != LUSTRE_CFG_RC_NO_ERR)
1429 return LUSTRE_CFG_RC_MATCH;
1432 return LUSTRE_CFG_RC_NO_MATCH;
1436 * First interface which matches an IP pattern will be used
1438 if (list_empty(intf_list)) {
1440 * no interfaces provided in the rule, but an ip range is
1441 * provided, so try and match an interface to the ip
1444 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1445 if (ifaddr->ifa_addr == NULL)
1448 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1451 family = ifaddr->ifa_addr->sa_family;
1452 if (family == AF_INET) {
1453 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1456 list_for_each_entry(ip_range, ip_ranges,
1458 rc = cfs_ip_addr_match(bswap_32(ip),
1459 &ip_range->ipr_expr);
1463 rc = lustre_lnet_add_intf_descr
1464 (intf_list, ifaddr->ifa_name,
1465 strlen(ifaddr->ifa_name));
1467 if (rc != LUSTRE_CFG_RC_NO_ERR)
1473 if (!list_empty(intf_list))
1474 return LUSTRE_CFG_RC_MATCH;
1476 return LUSTRE_CFG_RC_NO_MATCH;
1480 * If an interface is explicitly specified the ip-range might or
1481 * might not be specified. if specified the interface needs to match the
1482 * ip-range. If no ip-range then the interfaces are
1483 * automatically matched if they are all up.
1484 * If > 1 interfaces all the interfaces must match for the NI to
1487 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1488 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1489 if (ifaddr->ifa_addr == NULL)
1492 family = ifaddr->ifa_addr->sa_family;
1493 if (family == AF_INET &&
1494 strcmp(intf_descr->intf_name,
1495 ifaddr->ifa_name) == 0)
1499 if (ifaddr == NULL) {
1500 list_del(&intf_descr->intf_on_network);
1501 free_intf_descr(intf_descr);
1505 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1506 list_del(&intf_descr->intf_on_network);
1507 free_intf_descr(intf_descr);
1511 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1514 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1515 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1521 /* no match for this interface */
1522 list_del(&intf_descr->intf_on_network);
1523 free_intf_descr(intf_descr);
1527 return LUSTRE_CFG_RC_MATCH;
1530 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1531 lnet_nid_t **nids, __u32 *nnids,
1532 char *err_str, size_t str_len)
1534 struct ifaddrs *ifa;
1535 int rc = LUSTRE_CFG_RC_NO_ERR;
1537 rc = getifaddrs(&ifa);
1539 snprintf(err_str, str_len,
1540 "\"failed to get interface addresses: %d\"", -errno);
1544 rc = lustre_lnet_match_ip_to_intf(ifa,
1545 &ip2nets->ip2nets_net.nw_intflist,
1546 &ip2nets->ip2nets_ip_ranges);
1547 if (rc != LUSTRE_CFG_RC_MATCH) {
1548 snprintf(err_str, str_len,
1549 "\"couldn't match ip to existing interfaces\"");
1554 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1556 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1566 void lustre_lnet_free_list(struct nid_node *head)
1568 struct nid_node *entry, *tmp;
1570 nl_list_for_each_entry_safe(entry, tmp, &head->children, list) {
1571 nl_list_del(&entry->list);
1576 static int unroll_nid_range_scan(struct nid_node *list, const char *nid,
1577 char *tmp, char *tmp2, char *nidstr,
1578 const char **errmsg)
1580 unsigned int first = 0, last = 0, off = 0, inc = 1;
1581 bool slash = false, hyphen = false;
1582 char num[INT_STRING_LEN] = "";
1583 char *range = tmp + 1;
1587 if (!tmp && !tmp2) {
1588 *errmsg = "Unable to parse nidlist: [] are missing";
1592 if ((tmp && !tmp2) || (!tmp && tmp2)) {
1593 *errmsg = "Unable to parse nidlist: incomplete bracket set";
1598 *errmsg = "Unable to parse nidlist: improper bracket ordering";
1602 if (strchr(nid, ':'))
1605 while (range < tmp2) {
1606 if (isxdigit(*range)) {
1607 if (off > INT_STRING_LEN)
1609 num[off++] = *range++;
1610 } else if (*range == ':') {
1611 /* skip ':' for IPv6 and IB GUID */
1613 } else if (*range == '-') {
1615 if (!isxdigit(*range)) {
1616 *errmsg = "Unable to parse nidlist: range needs number after -";
1620 first = strtoul(num, NULL, base);
1621 memset(num, 0, sizeof(num));
1624 } else if (*range == '/') {
1626 if (!isdigit(*range)) {
1627 *errmsg = "Unable to parse nidlist: range needs number after /";
1631 /* Don't lose last number. This should be the very last item */
1633 last = strtoul(num, NULL, base);
1634 memset(num, 0, sizeof(num));
1638 } else if (*range == ',') {
1639 char *end = strchr(nidstr, ',');
1640 int count = strlen(tmp2 + 1);
1641 struct nid_node *item;
1642 int len = tmp - nid;
1645 if (!isxdigit(*range)) {
1646 *errmsg = "Unable to parse nidlist: range needs number after ,";
1650 /* If hyphen is true then we have the foramt '[first - last],' format.
1651 * The other format is just x, y, z, ... format.
1655 inc = strtoul(num, NULL, base);
1657 last = strtoul(num, NULL, base);
1660 *errmsg = "Unable to parse nidlist: range is wrong order";
1664 while (last >= first) {
1665 char hdr[LNET_MAX_STR_LEN], *next;
1667 snprintf(hdr, sizeof(hdr), "%.*s%d%.*s",
1668 len, nid, first, count,
1670 next = strchr(hdr, '[');
1671 if (next && strchr(next, ']')) {
1672 rc = unroll_nid_range_scan(list, hdr, next,
1678 item = calloc(1, sizeof(struct nid_node));
1680 *errmsg = "Unable to parse nidlist: allocation failed";
1683 snprintf(item->nidstr, sizeof(item->nidstr),
1684 "%s@%s", hdr, nidstr);
1685 nl_init_list_head(&item->list);
1686 nl_list_add_tail(&item->list, &list->children);
1690 /* reset slash / hyphen handing */
1695 int end_len = end ? end - nidstr : strlen(nidstr);
1697 item = calloc(1, sizeof(struct nid_node));
1699 *errmsg = "Unable to parse nidlist: allocation failed";
1702 snprintf(item->nidstr, sizeof(item->nidstr),
1703 "%.*s%s%.*s@%.*s", len, nid, num,
1704 count, tmp2 + 1, end_len, nidstr);
1705 nl_init_list_head(&item->list);
1706 nl_list_add_tail(&item->list, &list->children);
1709 memset(num, 0, sizeof(num));
1712 *errmsg = "Unable to parse nidlist: invalid character in range";
1719 inc = strtoul(num, NULL, base);
1721 last = strtoul(num, NULL, base);
1722 memset(num, 0, sizeof(num));
1728 /* This is the last set of [ first - last ]. We reach this point because
1729 * the above loop reached the end of the range and no ',' was found so
1730 * the final set of number range wasn't processed. Do that handling here.
1732 if (first || last) {
1733 char *next = tmp2 + 1;
1734 int len = strlen(nid);
1737 *errmsg = "Unable to parse nidlist: range is wrong order";
1741 if (strchr(nid, '['))
1742 len = strchr(nid, '[') - nid;
1744 tmp = strchr(tmp2, '[');
1746 tmp2 = strchr(tmp, ']');
1748 while (last >= first) {
1749 char str[LNET_MAX_STR_LEN];
1751 snprintf(str, sizeof(str), "%.*s%u%.*s",
1752 len, nid, first, (int)(tmp - next), next);
1754 rc = unroll_nid_range_scan(list, str, tmp, tmp2,
1759 char *end = strchr(nidstr, ',');
1760 int count = end ? end - nidstr : strlen(nidstr);
1761 struct nid_node *item;
1763 item = calloc(1, sizeof(struct nid_node));
1765 *errmsg = "Unable to parse nidlist: allocation failed";
1768 snprintf(item->nidstr, sizeof(item->nidstr),
1769 "%s@%.*s", str, count, nidstr);
1770 nl_init_list_head(&item->list);
1771 nl_list_add_tail(&item->list, &list->children);
1780 int lustre_lnet_parse_nid_range(struct nid_node *head, char *nidstr,
1781 const char **errmsg)
1787 *errmsg = "supplied nidstr is NULL";
1791 if (strchr(nidstr, '*')) {
1792 *errmsg = "asterisk not allowed in nidstring";
1796 if (strstr(nidstr, "<?>")) {
1797 *errmsg = "Unable to parse nidlist: LNET_ANY_NID is unsupported";
1801 if (strchr(nidstr, '@') == NULL) {
1802 *errmsg = "Unable to parse nidlist: no valid NIDs in string";
1806 while ((nid = strsep(&nidstr, "@")) != NULL) {
1807 char *tmp = NULL, *tmp2 = NULL, *end = NULL;
1809 tmp = strchr(nid, '[');
1810 tmp2 = strchr(nid, ']');
1812 if (!tmp && !tmp2) {
1813 char *end = strchr(nidstr, ',');
1814 struct nid_node *item;
1817 item = calloc(1, sizeof(struct nid_node));
1819 *errmsg = "Unable to parse nidlist: allocation failed";
1824 count = end ? end - nidstr : strlen(nidstr);
1825 snprintf(item->nidstr, sizeof(item->nidstr),
1826 "%s@%.*s", nid, count, nidstr);
1827 nl_init_list_head(&item->list);
1828 nl_list_add_tail(&item->list, &head->children);
1830 rc = unroll_nid_range_scan(head, nid, tmp, tmp2,
1837 end = strchr(nidstr, ',');
1849 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1850 struct lnet_ioctl_config_lnd_tunables *tunables,
1851 struct cfs_expr_list *global_cpts,
1852 lnet_nid_t *nids, char *err_str)
1855 struct lnet_ioctl_config_ni *conf;
1856 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1857 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1860 struct lnet_dlc_intf_descr *intf_descr;
1862 struct cfs_expr_list *cpt_expr;
1864 list_for_each_entry(intf_descr, intf_list,
1866 if (tunables != NULL)
1867 len = sizeof(struct lnet_ioctl_config_ni) +
1868 sizeof(struct lnet_ioctl_config_lnd_tunables);
1870 len = sizeof(struct lnet_ioctl_config_ni);
1872 data = calloc(1, len);
1874 return LUSTRE_CFG_RC_OUT_OF_MEM;
1875 conf = (struct lnet_ioctl_config_ni*) data;
1876 if (tunables != NULL)
1877 tun = (struct lnet_ioctl_config_lnd_tunables*)
1880 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1881 conf->lic_cfg_hdr.ioc_len = len;
1882 conf->lic_nid = nids[i];
1883 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1886 if (intf_descr->cpt_expr != NULL)
1887 cpt_expr = intf_descr->cpt_expr;
1888 else if (global_cpts != NULL)
1889 cpt_expr = global_cpts;
1893 if (cpt_expr != NULL) {
1894 count = cfs_expr_list_values(cpt_expr,
1895 LNET_MAX_SHOW_NUM_CPT,
1898 memcpy(conf->lic_cpts, cpt_array,
1899 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1908 conf->lic_ncpts = count;
1910 if (tunables != NULL)
1911 memcpy(tun, tunables, sizeof(*tunables));
1913 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1918 "\"cannot add network: %s\"", strerror(errno));
1926 return LUSTRE_CFG_RC_NO_ERR;
1930 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1931 struct lnet_ioctl_config_lnd_tunables *tunables,
1932 struct cfs_expr_list *global_cpts,
1933 int seq_no, struct cYAML **err_rc)
1935 lnet_nid_t *nids = NULL;
1938 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1943 "\"incomplete ip2nets information\"");
1944 rc = LUSTRE_CFG_RC_BAD_PARAM;
1949 * call below function to resolve the rules into a list of nids.
1950 * The memory is allocated in that function then freed here when
1951 * it's no longer needed.
1953 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1955 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1958 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1959 snprintf(err_str, sizeof(err_str),
1960 "\"no interfaces match ip2nets rules\"");
1964 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1965 tunables, global_cpts, nids,
1972 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1976 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1977 struct cfs_expr_list *global_cpts,
1979 struct lnet_ioctl_config_lnd_tunables *tunables,
1980 int seq_no, struct cYAML **err_rc)
1983 struct lnet_ioctl_config_ni *conf;
1984 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1985 char buf[LNET_MAX_STR_LEN];
1986 int rc = LUSTRE_CFG_RC_NO_ERR;
1987 char err_str[LNET_MAX_STR_LEN * 2] = "\"success\"";
1988 lnet_nid_t *nids = NULL;
1992 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1995 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1996 (list_empty(&nw_descr->nw_intflist) &&
1997 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
2000 "\"missing mandatory parameters in NI config: '%s'\"",
2001 (nw_descr == NULL) ? "network , interface" :
2002 (nw_descr->nw_id == 0) ? "network" : "interface");
2003 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2007 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
2010 "\"ip2net string too long %d\"",
2011 (int)strlen(ip2net));
2012 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2016 if (ip2net != NULL) {
2017 if (tunables != NULL)
2018 len = sizeof(struct lnet_ioctl_config_ni) +
2019 sizeof(struct lnet_ioctl_config_lnd_tunables);
2021 len = sizeof(struct lnet_ioctl_config_ni);
2022 data = calloc(1, len);
2024 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2027 conf = (struct lnet_ioctl_config_ni*) data;
2028 if (tunables != NULL)
2029 tun = (struct lnet_ioctl_config_lnd_tunables*)
2030 (data + sizeof(*conf));
2032 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
2033 conf->lic_cfg_hdr.ioc_len = len;
2034 strncpy(conf->lic_legacy_ip2nets, ip2net,
2037 if (global_cpts != NULL) {
2038 count = cfs_expr_list_values(global_cpts,
2039 LNET_MAX_SHOW_NUM_CPT,
2042 memcpy(conf->lic_cpts, cpt_array,
2043 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
2052 conf->lic_ncpts = count;
2054 if (tunables != NULL)
2055 memcpy(tun, tunables, sizeof(*tunables));
2057 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
2062 "\"cannot add network: %s\"", strerror(errno));
2069 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
2070 rc = LUSTRE_CFG_RC_NO_ERR;
2074 if (nw_descr->nw_id == LNET_NET_ANY) {
2077 "\"cannot parse net '%s'\"",
2078 libcfs_net2str(nw_descr->nw_id));
2079 rc = LUSTRE_CFG_RC_BAD_PARAM;
2084 * special case the GNI since no interface name is expected
2086 if (list_empty(&nw_descr->nw_intflist) &&
2087 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
2090 "\"no interface name provided\"");
2091 rc = LUSTRE_CFG_RC_BAD_PARAM;
2095 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2096 err_str, sizeof(err_str));
2098 rc = LUSTRE_CFG_RC_BAD_PARAM;
2102 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
2103 tunables, global_cpts, nids,
2107 if (nw_descr != NULL) {
2108 list_for_each_entry_safe(intf_descr, tmp,
2109 &nw_descr->nw_intflist,
2111 list_del(&intf_descr->intf_on_network);
2112 free_intf_descr(intf_descr);
2116 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
2127 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
2128 int seq_no, struct cYAML **err_rc)
2130 struct lnet_ioctl_config_ni data;
2131 int rc = LUSTRE_CFG_RC_NO_ERR, i;
2132 char err_str[LNET_MAX_STR_LEN * 2] = "\"success\"";
2133 lnet_nid_t *nids = NULL;
2135 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2137 if (nw_descr == NULL || nw_descr->nw_id == 0) {
2140 "\"missing mandatory parameter in deleting NI: '%s'\"",
2141 (nw_descr == NULL) ? "network , interface" :
2142 (nw_descr->nw_id == 0) ? "network" : "interface");
2143 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2147 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
2148 return LUSTRE_CFG_RC_NO_ERR;
2150 if (nw_descr->nw_id == LNET_NET_ANY) {
2153 "\"cannot parse net '%s'\"",
2154 libcfs_net2str(nw_descr->nw_id));
2155 rc = LUSTRE_CFG_RC_BAD_PARAM;
2159 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
2160 err_str, sizeof(err_str));
2162 rc = LUSTRE_CFG_RC_BAD_PARAM;
2167 * no interfaces just the nw_id is specified
2170 nids = calloc(1, sizeof(*nids));
2172 snprintf(err_str, sizeof(err_str),
2173 "\"out of memory\"");
2174 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2177 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
2181 for (i = 0; i < nnids; i++) {
2182 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
2183 data.lic_nid = nids[i];
2185 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
2190 "\"cannot del network: %s\"", strerror(errno));
2194 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2196 list_del(&intf_descr->intf_on_network);
2197 free_intf_descr(intf_descr);
2201 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
2210 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
2211 enum lnet_health_type type, char *name,
2212 int seq_no, struct cYAML **err_rc)
2214 struct lnet_ioctl_reset_health_cfg data;
2215 int rc = LUSTRE_CFG_RC_NO_ERR;
2216 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2218 LIBCFS_IOC_INIT_V2(data, rh_hdr);
2219 data.rh_type = type;
2221 data.rh_value = value;
2224 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
2228 sizeof(err_str), "Can not configure health value: %s",
2232 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2238 lustre_lnet_config_peer(int state, lnet_nid_t nid, char *name,
2239 int seq_no, struct cYAML **err_rc)
2241 struct lnet_ioctl_peer_cfg data;
2242 int rc = LUSTRE_CFG_RC_NO_ERR;
2243 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2245 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
2246 data.prcfg_state = state;
2247 data.prcfg_prim_nid = nid;
2248 data.prcfg_cfg_nid = LNET_NID_ANY;
2250 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_PEER, &data);
2254 sizeof(err_str), "Can not set peer property: %s",
2258 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2264 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
2265 char *name, int seq_no,
2266 struct cYAML **err_rc)
2268 struct lnet_ioctl_reset_conns_per_peer_cfg data;
2269 int rc = LUSTRE_CFG_RC_NO_ERR;
2270 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2272 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
2273 data.rcpp_all = all;
2274 data.rcpp_value = value;
2275 data.rcpp_nid = nid;
2277 if (value < 0 || value > 127) {
2278 rc = LUSTRE_CFG_RC_BAD_PARAM;
2279 snprintf(err_str, sizeof(err_str),
2280 "\"Valid values are: 0-127\"");
2283 rc = l_ioctl(LNET_DEV_ID,
2284 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
2289 "Can not configure conns_per_peer value: %s",
2293 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2298 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
2299 struct cYAML **err_rc)
2303 nid = libcfs_str2nid(ni_nid);
2306 return lustre_lnet_config_healthv(value, all, nid,
2307 LNET_HEALTH_TYPE_LOCAL_NI,
2308 "ni healthv", seq_no, err_rc);
2311 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
2312 int seq_no, struct cYAML **err_rc)
2316 nid = libcfs_str2nid(lpni_nid);
2319 return lustre_lnet_config_healthv(value, all, nid,
2320 LNET_HEALTH_TYPE_PEER_NI,
2321 "peer_ni healthv", seq_no, err_rc);
2324 int lustre_lnet_set_peer_state(int state, char *lpni_nid, int seq_no,
2325 struct cYAML **err_rc)
2330 nid = libcfs_str2nid(lpni_nid);
2333 return lustre_lnet_config_peer(state, nid, "peer state", seq_no,
2337 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
2338 int seq_no, struct cYAML **err_rc)
2343 nid = libcfs_str2nid(ni_nid);
2346 return lustre_lnet_config_conns_per_peer(value, all, nid,
2347 "ni conns_per_peer",
2352 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2353 struct lnet_ioctl_comm_count *counts)
2355 if (cYAML_create_number(yaml, "put",
2356 counts->ico_put_count)
2359 if (cYAML_create_number(yaml, "get",
2360 counts->ico_get_count)
2363 if (cYAML_create_number(yaml, "reply",
2364 counts->ico_reply_count)
2367 if (cYAML_create_number(yaml, "ack",
2368 counts->ico_ack_count)
2371 if (cYAML_create_number(yaml, "hello",
2372 counts->ico_hello_count)
2379 static struct lnet_ioctl_comm_count *
2380 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2383 return &msg_stats->im_send_stats;
2385 return &msg_stats->im_recv_stats;
2387 return &msg_stats->im_drop_stats;
2393 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2394 struct cYAML *net_node)
2396 char tmp[LNET_MAX_STR_LEN];
2397 struct cYAML *udsp_net;
2398 bool created = false;
2402 /* add the UDSP info */
2403 udsp_net = cYAML_create_object(net_node, "udsp info");
2405 return LUSTRE_CFG_RC_OUT_OF_MEM;
2407 if (!cYAML_create_number(udsp_net, "net priority",
2408 (int) udsp_info->cud_net_priority))
2409 return LUSTRE_CFG_RC_OUT_OF_MEM;
2411 if (!cYAML_create_number(udsp_net, "nid priority",
2412 (int)udsp_info->cud_nid_priority))
2413 return LUSTRE_CFG_RC_OUT_OF_MEM;
2417 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2418 memset(tmp, 0, LNET_MAX_STR_LEN);
2419 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2422 pref = cYAML_create_object(udsp_net,
2423 "Preferred gateway NIDs");
2425 return LUSTRE_CFG_RC_OUT_OF_MEM;
2428 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2429 if (!cYAML_create_string(pref, tmp,
2430 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2431 return LUSTRE_CFG_RC_OUT_OF_MEM;
2434 return LUSTRE_CFG_RC_NO_ERR;
2438 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2439 struct cYAML *nid_node)
2441 char tmp[LNET_MAX_STR_LEN];
2442 struct cYAML *udsp_nid;
2443 bool created = false;
2447 /* add the UDSP info */
2448 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2450 return LUSTRE_CFG_RC_OUT_OF_MEM;
2452 if (!cYAML_create_number(udsp_nid, "net priority",
2453 (int) udsp_info->cud_net_priority))
2454 return LUSTRE_CFG_RC_OUT_OF_MEM;
2456 if (!cYAML_create_number(udsp_nid, "nid priority",
2457 (int) udsp_info->cud_nid_priority))
2458 return LUSTRE_CFG_RC_OUT_OF_MEM;
2461 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2462 memset(tmp, 0, LNET_MAX_STR_LEN);
2463 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2466 pref = cYAML_create_object(udsp_nid,
2467 "Preferred gateway NIDs");
2469 return LUSTRE_CFG_RC_OUT_OF_MEM;
2472 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2473 if (!cYAML_create_string(pref, tmp,
2474 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2475 return LUSTRE_CFG_RC_OUT_OF_MEM;
2480 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2481 memset(tmp, 0, LNET_MAX_STR_LEN);
2482 if (udsp_info->cud_pref_nid[i] == 0)
2485 pref = cYAML_create_object(udsp_nid,
2486 "Preferred source NIDs");
2488 return LUSTRE_CFG_RC_OUT_OF_MEM;
2491 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2492 if (!cYAML_create_string(pref, tmp,
2493 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2494 return LUSTRE_CFG_RC_OUT_OF_MEM;
2497 return LUSTRE_CFG_RC_NO_ERR;
2500 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2501 struct cYAML **show_rc, struct cYAML **err_rc,
2505 struct lnet_ioctl_config_ni *ni_data;
2506 struct lnet_ioctl_config_lnd_tunables *lnd;
2507 struct lnet_ioctl_element_stats *stats;
2508 struct lnet_ioctl_element_msg_stats msg_stats;
2509 struct lnet_ioctl_local_ni_hstats hstats;
2510 struct lnet_ioctl_construct_udsp_info udsp_info;
2511 __u32 net = LNET_NET_ANY;
2512 __u32 prev_net = LNET_NET_ANY;
2513 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2515 struct cYAML *root = NULL, *tunables = NULL,
2516 *net_node = NULL, *interfaces = NULL,
2517 *item = NULL, *first_seq = NULL,
2518 *tmp = NULL, *statistics = NULL,
2520 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2521 char str_buf[str_buf_len];
2523 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2524 bool exist = false, new_net = true;
2526 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2528 buf = calloc(1, buf_size);
2532 ni_data = (struct lnet_ioctl_config_ni *)buf;
2535 net = libcfs_str2net(nw);
2536 if (net == LNET_NET_ANY) {
2539 "\"cannot parse net '%s'\"", nw);
2540 rc = LUSTRE_CFG_RC_BAD_PARAM;
2545 root = cYAML_create_object(NULL, NULL);
2549 net_node = cYAML_create_seq(root, "net");
2550 if (net_node == NULL)
2556 memset(buf, 0, buf_size);
2558 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2560 * set the ioc_len to the proper value since INIT assumes
2563 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2564 ni_data->lic_idx = i;
2566 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2572 rc_net = LNET_NIDNET(ni_data->lic_nid);
2574 /* filter on provided data */
2575 if (net != LNET_NET_ANY &&
2579 /* if we're backing up don't store lo */
2580 if (backup && LNET_NETTYP(rc_net) == LOLND)
2583 /* default rc to -1 in case we hit the goto */
2587 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2588 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2589 (ni_data->lic_bulk + sizeof(*stats));
2591 if (rc_net != prev_net) {
2598 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2602 if (first_seq == NULL)
2605 tmp = cYAML_create_seq(net_node, "local NI(s)");
2611 /* create the tree to be printed. */
2612 item = cYAML_create_seq_item(tmp);
2617 cYAML_create_string(item, "nid",
2618 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2622 cYAML_create_string(item,
2624 (ni_data->lic_status ==
2625 LNET_NI_STATUS_UP) ?
2626 "up" : "down") == NULL)
2629 /* don't add interfaces unless there is at least one
2631 if (strlen(ni_data->lic_ni_intf) > 0) {
2632 interfaces = cYAML_create_object(item, "interfaces");
2633 if (interfaces == NULL)
2636 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2637 if (cYAML_create_string(interfaces, str_buf,
2638 ni_data->lic_ni_intf) == NULL)
2647 goto continue_without_msg_stats;
2649 statistics = cYAML_create_object(item, "statistics");
2650 if (statistics == NULL)
2653 if (cYAML_create_number(statistics, "send_count",
2654 stats->iel_send_count)
2658 if (cYAML_create_number(statistics, "recv_count",
2659 stats->iel_recv_count)
2663 if (cYAML_create_number(statistics, "drop_count",
2664 stats->iel_drop_count)
2669 goto continue_without_udsp_info;
2671 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2672 udsp_info.cud_nid = ni_data->lic_nid;
2673 udsp_info.cud_peer = false;
2674 rc = l_ioctl(LNET_DEV_ID,
2675 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2679 goto continue_without_udsp_info;
2682 rc = create_local_udsp_info(&udsp_info, item);
2688 continue_without_udsp_info:
2690 goto continue_without_msg_stats;
2692 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2693 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2694 msg_stats.im_idx = i;
2696 rc = l_ioctl(LNET_DEV_ID,
2697 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2701 goto continue_without_msg_stats;
2704 for (k = 0; k < 3; k++) {
2705 struct lnet_ioctl_comm_count *counts;
2706 struct cYAML *msg_statistics = NULL;
2708 msg_statistics = cYAML_create_object(item,
2709 (char *)gmsg_stat_names[k]);
2710 if (msg_statistics == NULL)
2713 counts = get_counts(&msg_stats, k);
2717 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2722 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2723 hstats.hlni_nid = ni_data->lic_nid;
2724 /* grab health stats */
2725 rc = l_ioctl(LNET_DEV_ID,
2726 IOC_LIBCFS_GET_LOCAL_HSTATS,
2730 goto continue_without_msg_stats;
2732 yhstats = cYAML_create_object(item, "health stats");
2735 if (cYAML_create_number(yhstats, "fatal_error",
2736 hstats.hlni_fatal_error)
2739 if (cYAML_create_number(yhstats, "health value",
2740 hstats.hlni_health_value)
2743 if (cYAML_create_number(yhstats, "interrupts",
2744 hstats.hlni_local_interrupt)
2747 if (cYAML_create_number(yhstats, "dropped",
2748 hstats.hlni_local_dropped)
2751 if (cYAML_create_number(yhstats, "aborted",
2752 hstats.hlni_local_aborted)
2755 if (cYAML_create_number(yhstats, "no route",
2756 hstats.hlni_local_no_route)
2759 if (cYAML_create_number(yhstats, "timeouts",
2760 hstats.hlni_local_timeout)
2763 if (cYAML_create_number(yhstats, "error",
2764 hstats.hlni_local_error)
2767 if (cYAML_create_number(yhstats, "ping_count",
2768 hstats.hlni_ping_count)
2771 if (cYAML_create_number(yhstats, "next_ping",
2772 hstats.hlni_next_ping)
2776 continue_without_msg_stats:
2777 tunables = cYAML_create_object(item, "tunables");
2781 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2782 if (rc != LUSTRE_CFG_RC_NO_ERR)
2785 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2786 tunables = cYAML_create_object(item,
2788 if (tunables == NULL)
2792 rc = lustre_ni_show_tunables(tunables,
2793 LNET_NETTYP(rc_net),
2794 &lnd->lt_tun, backup);
2795 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2796 rc != LUSTRE_CFG_RC_NO_MATCH)
2800 cYAML_create_number(item, "dev cpt",
2801 ni_data->lic_dev_cpt) == NULL)
2804 /* out put the CPTs in the format: "[x,x,x,...]" */
2806 limit = str_buf + str_buf_len - 3;
2807 pos += scnprintf(pos, limit - pos, "\"[");
2808 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2809 j < ni_data->lic_ncpts &&
2811 pos += scnprintf(pos, limit - pos,
2812 "%d", ni_data->lic_cpts[j]);
2813 if ((j + 1) < ni_data->lic_ncpts)
2814 pos += scnprintf(pos, limit - pos, ",");
2816 snprintf(pos, 3, "]\"");
2818 if (ni_data->lic_ncpts >= 1 &&
2819 cYAML_create_string(item, "CPT",
2825 /* Print out the net information only if show_rc is not provided */
2826 if (show_rc == NULL)
2827 cYAML_print_tree(root);
2829 if (l_errno != ENOENT) {
2832 "\"cannot get networks: %s\"",
2837 rc = LUSTRE_CFG_RC_NO_ERR;
2839 snprintf(err_str, sizeof(err_str), "\"success\"");
2841 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2842 cYAML_free_tree(root);
2843 } else if (show_rc != NULL && *show_rc != NULL) {
2844 struct cYAML *show_node;
2845 /* find the net node, if one doesn't exist
2846 * then insert one. Otherwise add to the one there
2848 show_node = cYAML_get_object_item(*show_rc, "net");
2849 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2850 cYAML_insert_child(show_node, first_seq);
2853 } else if (show_node == NULL) {
2854 cYAML_insert_sibling((*show_rc)->cy_child,
2858 cYAML_free_tree(root);
2864 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2869 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2871 struct lnet_ioctl_config_data data;
2872 int rc = LUSTRE_CFG_RC_NO_ERR;
2873 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2875 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2876 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2878 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2883 "\"cannot %s routing %s\"",
2884 (enable) ? "enable" : "disable", strerror(errno));
2889 cYAML_build_error(rc, seq_no,
2890 (enable) ? ADD_CMD : DEL_CMD,
2891 "routing", err_str, err_rc);
2896 static int ioctl_set_value(__u32 val, int ioc, char *name,
2897 int seq_no, struct cYAML **err_rc)
2899 struct lnet_ioctl_set_value data;
2900 int rc = LUSTRE_CFG_RC_NO_ERR;
2901 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2903 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2904 data.sv_value = val;
2906 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2911 "\"cannot configure %s to %d: %s\"", name,
2912 val, strerror(errno));
2915 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2920 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2922 int rc = LUSTRE_CFG_RC_NO_ERR;
2923 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2924 char val[LNET_MAX_STR_LEN];
2926 snprintf(val, sizeof(val), "%d", intrv);
2928 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2929 1, strlen(val) + 1);
2931 snprintf(err_str, sizeof(err_str),
2932 "\"cannot configure recovery interval: %s\"",
2935 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2940 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2942 int rc = LUSTRE_CFG_RC_NO_ERR;
2943 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2944 char val[LNET_MAX_STR_LEN];
2946 snprintf(val, sizeof(val), "%d", sen);
2948 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2949 1, strlen(val) + 1);
2951 snprintf(err_str, sizeof(err_str),
2952 "\"cannot configure router health sensitivity: %s\"",
2955 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2960 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2962 int rc = LUSTRE_CFG_RC_NO_ERR;
2963 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2964 char val[LNET_MAX_STR_LEN];
2966 snprintf(val, sizeof(val), "%d", sen);
2968 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2969 1, strlen(val) + 1);
2971 snprintf(err_str, sizeof(err_str),
2972 "\"cannot configure health sensitivity: %s\"",
2975 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2980 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2982 int rc = LUSTRE_CFG_RC_NO_ERR;
2983 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2984 char val[LNET_MAX_STR_LEN];
2986 snprintf(val, sizeof(val), "%d", timeout);
2988 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2989 1, strlen(val) + 1);
2991 snprintf(err_str, sizeof(err_str),
2992 "\"cannot configure transaction timeout: %s\"",
2995 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
3000 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
3002 int rc = LUSTRE_CFG_RC_NO_ERR;
3003 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3004 char val[LNET_MAX_STR_LEN];
3006 snprintf(val, sizeof(val), "%d", count);
3008 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
3009 1, strlen(val) + 1);
3011 snprintf(err_str, sizeof(err_str),
3012 "\"cannot configure retry count: %s\"",
3015 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
3020 int lustre_lnet_config_response_tracking(int val, int seq_no,
3021 struct cYAML **err_rc)
3023 int rc = LUSTRE_CFG_RC_NO_ERR;
3024 char err_str[LNET_MAX_STR_LEN];
3025 char val_str[LNET_MAX_STR_LEN];
3027 if (val < 0 || val > 3) {
3028 rc = LUSTRE_CFG_RC_BAD_PARAM;
3029 snprintf(err_str, sizeof(err_str),
3030 "\"Valid values are: 0, 1, 2, or 3\"");
3032 snprintf(err_str, sizeof(err_str), "\"success\"");
3034 snprintf(val_str, sizeof(val_str), "%d", val);
3036 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
3037 val_str, 1, strlen(val_str) + 1);
3039 snprintf(err_str, sizeof(err_str),
3040 "\"cannot configure response tracking: %s\"",
3044 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
3050 int lustre_lnet_config_recovery_limit(int val, int seq_no,
3051 struct cYAML **err_rc)
3053 int rc = LUSTRE_CFG_RC_NO_ERR;
3054 char err_str[LNET_MAX_STR_LEN];
3055 char val_str[LNET_MAX_STR_LEN];
3058 rc = LUSTRE_CFG_RC_BAD_PARAM;
3059 snprintf(err_str, sizeof(err_str),
3060 "\"Must be greater than or equal to 0\"");
3062 snprintf(err_str, sizeof(err_str), "\"success\"");
3064 snprintf(val_str, sizeof(val_str), "%d", val);
3066 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
3067 val_str, 1, strlen(val_str) + 1);
3069 snprintf(err_str, sizeof(err_str),
3070 "\"cannot configure recovery limit: %s\"",
3074 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
3080 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
3082 int rc = LUSTRE_CFG_RC_NO_ERR;
3083 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3084 char val[LNET_MAX_STR_LEN];
3086 snprintf(val, sizeof(val), "%d", max);
3088 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3089 1, strlen(val) + 1);
3091 snprintf(err_str, sizeof(err_str),
3092 "\"cannot configure max interfaces: %s\"",
3095 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
3100 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
3102 int rc = LUSTRE_CFG_RC_NO_ERR;
3103 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3104 char val[LNET_MAX_STR_LEN];
3106 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
3108 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3109 1, strlen(val) + 1);
3111 snprintf(err_str, sizeof(err_str),
3112 "\"cannot configure discovery: %s\"",
3115 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
3121 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
3122 struct cYAML **err_rc)
3124 int rc = LUSTRE_CFG_RC_NO_ERR;
3125 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3126 char val[LNET_MAX_STR_LEN];
3128 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
3130 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3131 1, strlen(val) + 1);
3133 snprintf(err_str, sizeof(err_str),
3134 "\"cannot configure drop asym route: %s\"",
3137 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
3144 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
3146 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
3147 "numa_range", seq_no, err_rc);
3150 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
3151 struct cYAML **err_rc)
3153 struct lnet_ioctl_config_data data;
3154 int rc = LUSTRE_CFG_RC_NO_ERR;
3155 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3157 /* -1 indicates to ignore changes to this field */
3158 if (tiny < -1 || small < -1 || large < -1) {
3161 "\"tiny, small and large must be >= 0\"");
3162 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
3166 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
3167 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
3168 data.cfg_config_u.cfg_buffers.buf_small = small;
3169 data.cfg_config_u.cfg_buffers.buf_large = large;
3171 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
3176 "\"cannot configure buffers: %s\"", strerror(errno));
3181 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
3186 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
3187 struct cYAML **err_rc)
3189 int rc = LUSTRE_CFG_RC_NO_ERR;
3190 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
3191 char interval_str[LNET_MAX_STR_LEN];
3193 if (interval <= 0) {
3194 rc = LUSTRE_CFG_RC_BAD_PARAM;
3195 snprintf(err_str, sizeof(err_str),
3196 "\"must be strictly positive\"");
3199 snprintf(interval_str, sizeof(interval_str), "%d", interval);
3201 rc = write_sysfs_file(modparam_path,
3202 "lnet_max_recovery_ping_interval",
3204 strlen(interval_str) + 1);
3206 snprintf(err_str, sizeof(err_str),
3207 "\"cannot configure maximum recovery ping interval: %s\"",
3211 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
3218 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
3219 struct cYAML **err_rc, bool backup)
3221 struct lnet_ioctl_config_data *data;
3222 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
3223 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3226 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
3227 int buf_count[LNET_NRBPOOLS] = {0};
3228 struct cYAML *root = NULL, *pools_node = NULL,
3229 *type_node = NULL, *item = NULL, *cpt = NULL,
3230 *first_seq = NULL, *buffers = NULL;
3232 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3233 char node_name[LNET_MAX_STR_LEN];
3236 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
3240 data = (struct lnet_ioctl_config_data *)buf;
3242 root = cYAML_create_object(NULL, NULL);
3247 pools_node = cYAML_create_object(root, "routing");
3249 pools_node = cYAML_create_seq(root, "routing");
3250 if (pools_node == NULL)
3254 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
3255 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
3256 sizeof(struct lnet_ioctl_pool_cfg);
3257 data->cfg_count = i;
3259 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
3267 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
3270 goto calculate_buffers;
3272 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
3273 item = cYAML_create_seq_item(pools_node);
3277 if (first_seq == NULL)
3280 cpt = cYAML_create_object(item, node_name);
3285 /* create the tree and print */
3286 for (j = 0; j < LNET_NRBPOOLS; j++) {
3288 type_node = cYAML_create_object(cpt, pools[j]);
3289 if (type_node == NULL)
3293 cYAML_create_number(type_node, "npages",
3294 pool_cfg->pl_pools[j].pl_npages)
3298 cYAML_create_number(type_node, "nbuffers",
3299 pool_cfg->pl_pools[j].
3300 pl_nbuffers) == NULL)
3303 cYAML_create_number(type_node, "credits",
3304 pool_cfg->pl_pools[j].
3305 pl_credits) == NULL)
3308 cYAML_create_number(type_node, "mincredits",
3309 pool_cfg->pl_pools[j].
3310 pl_mincredits) == NULL)
3312 /* keep track of the total count for each of the
3313 * tiny, small and large buffers */
3314 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
3318 if (pool_cfg != NULL) {
3320 if (cYAML_create_number(pools_node, "enable",
3321 pool_cfg->pl_routing) ==
3325 goto add_buffer_section;
3328 item = cYAML_create_seq_item(pools_node);
3332 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
3338 /* create a buffers entry in the show. This is necessary so that
3339 * if the YAML output is used to configure a node, the buffer
3340 * configuration takes hold */
3341 buffers = cYAML_create_object(root, "buffers");
3342 if (buffers == NULL)
3345 for (i = 0; i < LNET_NRBPOOLS; i++) {
3346 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3350 if (show_rc == NULL)
3351 cYAML_print_tree(root);
3353 if (l_errno != ENOENT) {
3356 "\"cannot get routing information: %s\"",
3361 rc = LUSTRE_CFG_RC_NO_ERR;
3363 snprintf(err_str, sizeof(err_str), "\"success\"");
3364 rc = LUSTRE_CFG_RC_NO_ERR;
3368 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3369 cYAML_free_tree(root);
3370 } else if (show_rc != NULL && *show_rc != NULL) {
3371 struct cYAML *routing_node;
3372 /* there should exist only one routing block and one
3373 * buffers block. If there already exists a previous one
3374 * then don't add another */
3375 routing_node = cYAML_get_object_item(*show_rc, "routing");
3376 if (routing_node == NULL) {
3377 cYAML_insert_sibling((*show_rc)->cy_child,
3381 cYAML_free_tree(root);
3387 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3392 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3393 struct cYAML **show_rc, struct cYAML **err_rc,
3397 * TODO: This function is changing in a future patch to accommodate
3398 * PEER_LIST and proper filtering on any nid of the peer
3400 struct lnet_ioctl_peer_cfg peer_info;
3401 struct lnet_peer_ni_credit_info *lpni_cri;
3402 struct lnet_ioctl_element_stats *lpni_stats;
3403 struct lnet_ioctl_element_msg_stats *msg_stats;
3404 struct lnet_ioctl_peer_ni_hstats *hstats;
3405 struct lnet_ioctl_construct_udsp_info udsp_info;
3407 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3412 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3413 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3414 *msg_statistics = NULL, *statistics = NULL,
3416 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3417 struct lnet_process_id *list = NULL;
3422 /* create struct cYAML root object */
3423 root = cYAML_create_object(NULL, NULL);
3427 peer_root = cYAML_create_seq(root, "peer");
3428 if (peer_root == NULL)
3432 size = count * sizeof(struct lnet_process_id);
3433 list = malloc(size);
3439 list[0].nid = libcfs_str2nid(knid);
3443 memset(&peer_info, 0, sizeof(peer_info));
3444 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3445 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3446 peer_info.prcfg_size = size;
3447 peer_info.prcfg_bulk = list;
3450 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3452 count = peer_info.prcfg_count;
3456 if (l_errno != E2BIG) {
3459 "\"cannot get peer list: %s\"",
3465 size = peer_info.prcfg_size;
3466 list = malloc(size);
3475 data = malloc(size);
3481 for (i = 0; i < count; i++) {
3483 memset(&peer_info, 0, sizeof(peer_info));
3484 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3485 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3486 peer_info.prcfg_prim_nid = list[i].nid;
3487 peer_info.prcfg_size = size;
3488 peer_info.prcfg_bulk = data;
3491 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3496 if (l_errno != E2BIG) {
3499 "\"cannot get peer information: %s\"",
3505 size = peer_info.prcfg_size;
3506 data = malloc(size);
3514 peer = cYAML_create_seq_item(peer_root);
3518 if (first_seq == NULL)
3521 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3522 if (cYAML_create_string(peer, "primary nid",
3523 libcfs_nid2str(pnid))
3526 if (cYAML_create_string(peer, "Multi-Rail",
3527 peer_info.prcfg_mr ? "True" : "False")
3531 * print out the state of the peer only if details are
3536 cYAML_create_number(peer, "peer state",
3537 peer_info.prcfg_state)
3542 tmp = cYAML_create_seq(peer, "peer ni");
3547 for (j = 0; j < peer_info.prcfg_count; j++) {
3549 lpni_cri = (void*)nidp + sizeof(nidp);
3550 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3551 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3552 hstats = (void *)msg_stats + sizeof(*msg_stats);
3553 lpni_data = (void *)hstats + sizeof(*hstats);
3555 peer_ni = cYAML_create_seq_item(tmp);
3556 if (peer_ni == NULL)
3559 if (cYAML_create_string(peer_ni, "nid",
3560 libcfs_nid2str(*nidp))
3568 goto continue_without_udsp_info;
3570 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3571 udsp_info.cud_nid = *nidp;
3572 udsp_info.cud_peer = true;
3573 rc = l_ioctl(LNET_DEV_ID,
3574 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3578 goto continue_without_udsp_info;
3581 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3587 continue_without_udsp_info:
3588 if (cYAML_create_string(peer_ni, "state",
3589 lpni_cri->cr_aliveness)
3596 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3597 lpni_cri->cr_ni_peer_tx_credits)
3601 if (cYAML_create_number(peer_ni, "available_tx_credits",
3602 lpni_cri->cr_peer_tx_credits)
3606 if (cYAML_create_number(peer_ni, "min_tx_credits",
3607 lpni_cri->cr_peer_min_tx_credits)
3611 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3612 lpni_cri->cr_peer_tx_qnob)
3616 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3617 lpni_cri->cr_peer_rtr_credits)
3621 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3622 lpni_cri->cr_peer_min_rtr_credits)
3626 if (cYAML_create_number(peer_ni, "refcount",
3627 lpni_cri->cr_refcount) == NULL)
3630 statistics = cYAML_create_object(peer_ni, "statistics");
3631 if (statistics == NULL)
3634 if (cYAML_create_number(statistics, "send_count",
3635 lpni_stats->iel_send_count)
3639 if (cYAML_create_number(statistics, "recv_count",
3640 lpni_stats->iel_recv_count)
3644 if (cYAML_create_number(statistics, "drop_count",
3645 lpni_stats->iel_drop_count)
3652 for (k = 0; k < 3; k++) {
3653 struct lnet_ioctl_comm_count *counts;
3655 msg_statistics = cYAML_create_object(peer_ni,
3656 (char *) gmsg_stat_names[k]);
3657 if (msg_statistics == NULL)
3660 counts = get_counts(msg_stats, k);
3664 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3669 yhstats = cYAML_create_object(peer_ni, "health stats");
3672 if (cYAML_create_number(yhstats, "health value",
3673 hstats->hlpni_health_value)
3676 if (cYAML_create_number(yhstats, "dropped",
3677 hstats->hlpni_remote_dropped)
3680 if (cYAML_create_number(yhstats, "timeout",
3681 hstats->hlpni_remote_timeout)
3684 if (cYAML_create_number(yhstats, "error",
3685 hstats->hlpni_remote_error)
3688 if (cYAML_create_number(yhstats, "network timeout",
3689 hstats->hlpni_network_timeout)
3692 if (cYAML_create_number(yhstats, "ping_count",
3693 hstats->hlpni_ping_count)
3697 if (cYAML_create_number(yhstats, "next_ping",
3698 hstats->hlpni_next_ping)
3705 /* print output iff show_rc is not provided */
3706 if (show_rc == NULL)
3707 cYAML_print_tree(root);
3709 snprintf(err_str, sizeof(err_str), "\"success\"");
3710 rc = LUSTRE_CFG_RC_NO_ERR;
3715 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3716 cYAML_free_tree(root);
3717 } else if (show_rc != NULL && *show_rc != NULL) {
3718 struct cYAML *show_node;
3719 /* find the peer node, if one doesn't exist then
3720 * insert one. Otherwise add to the one there
3722 show_node = cYAML_get_object_item(*show_rc,
3724 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3725 cYAML_insert_child(show_node, first_seq);
3728 } else if (show_node == NULL) {
3729 cYAML_insert_sibling((*show_rc)->cy_child,
3733 cYAML_free_tree(root);
3739 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3745 int lustre_lnet_list_peer(int seq_no,
3746 struct cYAML **show_rc, struct cYAML **err_rc)
3748 struct lnet_ioctl_peer_cfg peer_info;
3749 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3754 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3755 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3756 struct lnet_process_id *list = NULL;
3758 memset(&peer_info, 0, sizeof(peer_info));
3760 /* create struct cYAML root object */
3761 root = cYAML_create_object(NULL, NULL);
3765 list_root = cYAML_create_seq(root, "peer list");
3766 if (list_root == NULL)
3770 size = count * sizeof(struct lnet_process_id);
3771 list = malloc(size);
3777 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3778 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3779 peer_info.prcfg_size = size;
3780 peer_info.prcfg_bulk = list;
3783 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3784 count = peer_info.prcfg_count;
3788 if (l_errno != E2BIG) {
3791 "\"cannot get peer list: %s\"",
3797 size = peer_info.prcfg_size;
3798 list = malloc(size);
3805 /* count is now the actual number of ids in the list. */
3806 for (i = 0; i < count; i++) {
3807 if (cYAML_create_string(list_root, "nid",
3808 libcfs_nid2str(list[i].nid))
3813 /* print output iff show_rc is not provided */
3814 if (show_rc == NULL)
3815 cYAML_print_tree(root);
3817 snprintf(err_str, sizeof(err_str), "\"success\"");
3818 rc = LUSTRE_CFG_RC_NO_ERR;
3823 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3824 cYAML_free_tree(root);
3825 } else if (show_rc != NULL && *show_rc != NULL) {
3826 struct cYAML *show_node;
3827 /* find the peer node, if one doesn't exist then
3828 * insert one. Otherwise add to the one there
3830 show_node = cYAML_get_object_item(*show_rc,
3832 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3833 cYAML_insert_child(show_node, first_seq);
3836 } else if (show_node == NULL) {
3837 cYAML_insert_sibling((*show_rc)->cy_child,
3841 cYAML_free_tree(root);
3847 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3853 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3856 struct cYAML *show_node;
3858 show_node = cYAML_get_object_item(show_rc, "global");
3859 if (show_node != NULL)
3860 cYAML_insert_sibling(show_node->cy_child,
3863 cYAML_insert_sibling(show_rc->cy_child,
3868 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3869 char *name, __u64 value,
3870 struct cYAML **show_rc,
3871 struct cYAML **err_rc, int err)
3873 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3874 struct cYAML *root = NULL, *global = NULL;
3881 root = cYAML_create_object(NULL, NULL);
3885 global = cYAML_create_object(root, "global");
3889 if (cYAML_create_number(global, name,
3893 if (show_rc == NULL)
3894 cYAML_print_tree(root);
3896 snprintf(err_str, err_len, "\"success\"");
3898 rc = LUSTRE_CFG_RC_NO_ERR;
3901 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3902 cYAML_free_tree(root);
3903 } else if (show_rc != NULL && *show_rc != NULL) {
3904 add_to_global(*show_rc, global, root);
3909 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3914 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3915 struct cYAML **show_rc,
3916 struct cYAML **err_rc)
3918 struct lnet_ioctl_set_value data;
3921 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3923 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3925 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3930 "\"cannot get %s: %s\"",
3931 name, strerror(l_errno));
3934 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3935 data.sv_value, show_rc, err_rc, l_errno);
3938 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3939 struct cYAML **err_rc)
3941 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3942 char val[LNET_MAX_STR_LEN];
3943 int intrv = -1, l_errno = 0;
3944 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3946 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3950 snprintf(err_str, sizeof(err_str),
3951 "\"cannot get recovery interval: %d\"", rc);
3956 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3957 "recovery_interval", intrv, show_rc,
3961 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3962 struct cYAML **err_rc)
3964 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3965 char val[LNET_MAX_STR_LEN];
3966 int sen = -1, l_errno = 0;
3967 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3969 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3973 snprintf(err_str, sizeof(err_str),
3974 "\"cannot get health sensitivity: %d\"", rc);
3979 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3980 "health_sensitivity", sen, show_rc,
3984 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3985 struct cYAML **err_rc)
3987 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3988 char val[LNET_MAX_STR_LEN];
3989 int sen = -1, l_errno = 0;
3990 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3992 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3996 snprintf(err_str, sizeof(err_str),
3997 "\"cannot get router sensitivity percentage: %d\"", rc);
4002 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4003 "router_sensitivity", sen, show_rc,
4007 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
4008 struct cYAML **err_rc)
4010 char val[LNET_MAX_STR_LEN];
4011 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4018 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
4021 snprintf(err_str, sizeof(err_str),
4022 "\"cannot get LND timeout: %d\"", rc);
4023 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4024 "lnd_timeout", lnd_to, show_rc,
4028 fd = open(path.gl_pathv[0], O_RDONLY);
4031 snprintf(err_str, sizeof(err_str),
4032 "\"error opening %s\"", path.gl_pathv[0]);
4036 rc = read(fd, val, sizeof(val));
4043 snprintf(err_str, sizeof(err_str),
4044 "\"error reading %s\"", path.gl_pathv[0]);
4051 cfs_free_param_data(&path);
4053 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4054 "lnd_timeout", lnd_to, show_rc,
4058 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
4059 struct cYAML **err_rc)
4061 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4062 char val[LNET_MAX_STR_LEN];
4063 int tto = -1, l_errno = 0;
4064 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4066 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
4070 snprintf(err_str, sizeof(err_str),
4071 "\"cannot get transaction timeout: %d\"", rc);
4076 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4077 "transaction_timeout", tto, show_rc,
4081 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
4082 struct cYAML **err_rc)
4084 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4085 char val[LNET_MAX_STR_LEN];
4086 int retry_count = -1, l_errno = 0;
4087 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4089 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
4093 snprintf(err_str, sizeof(err_str),
4094 "\"cannot get retry count: %d\"", rc);
4096 retry_count = atoi(val);
4099 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4100 "retry_count", retry_count, show_rc,
4104 int lustre_lnet_calc_service_id(__u64 *service_id)
4106 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4107 char val[LNET_MAX_STR_LEN];
4108 int service_port = -1, l_errno = 0;
4110 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
4114 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
4115 strerror(l_errno), -l_errno);
4118 service_port = atoi(val);
4121 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
4123 return LUSTRE_CFG_RC_NO_ERR;
4126 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
4129 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
4131 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4132 struct lnet_ioctl_config_ni *ni_data;
4133 struct lnet_ioctl_config_lnd_tunables *lnd;
4134 struct lnet_ioctl_element_stats *stats;
4135 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
4136 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
4137 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
4138 int if_cnt = 0, prc;
4139 char syscmdbuf[LNET_MAX_STR_LEN];
4140 char cmdpath[LNET_MAX_STR_LEN];
4141 bool use_custom = false;
4143 buf = calloc(1, buf_size);
4147 ni_data = (struct lnet_ioctl_config_ni *)buf;
4150 ifstr_ptr = ifstr_buf;
4155 memset(buf, 0, buf_size);
4157 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
4158 /* set the ioc_len to the proper value since INIT assumes
4161 ni_data->lic_cfg_hdr.ioc_len = buf_size;
4162 ni_data->lic_idx = i;
4164 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
4170 rc_net = LNET_NIDNET(ni_data->lic_nid);
4172 /* only need to setup routing for tcp */
4173 if (LNET_NETTYP(rc_net) != SOCKLND)
4176 /* don't add interfaces unless there is at least one
4179 if (strlen(ni_data->lic_ni_intf) > 0) {
4181 strcat(ifstr_ptr, ",");
4182 strcat(ifstr_ptr, ni_data->lic_ni_intf);
4187 if (l_errno != ENOENT) {
4190 "\"cannot get networks: %s\"",
4195 rc = LUSTRE_CFG_RC_NO_ERR;
4198 snprintf(err_str, sizeof(err_str), "\"success\"");
4201 tmp_ptr = getenv("KSOCKLND_CONFIG");
4203 tmp_ptr2 = strrchr(tmp_ptr, '/');
4204 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
4205 snprintf(cmdpath, sizeof(cmdpath), "%s",
4212 snprintf(cmdpath, sizeof(cmdpath),
4213 "/usr/sbin/ksocklnd-config");
4215 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
4221 "\"snprintf failed : %s\"",
4224 } else if (prc >= LNET_MAX_STR_LEN) {
4225 snprintf(err_str, sizeof(err_str),
4226 "\"ksocklnd-config: argument too long\"");
4228 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
4229 cmdpath, ifstr_ptr);
4235 "\"snprintf failed : %s\"",
4241 rc = system(syscmdbuf);
4246 "\"failed to execute ksocklnd-config : %s\"",
4256 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
4262 static int show_recovery_queue(enum lnet_health_type type, char *name,
4263 int seq_no, struct cYAML **show_rc,
4264 struct cYAML **err_rc)
4266 struct lnet_ioctl_recovery_list nid_list;
4267 struct cYAML *root = NULL, *nids = NULL;
4269 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
4271 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
4272 nid_list.rlst_type = type;
4274 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
4280 if (nid_list.rlst_num_nids == 0)
4283 root = cYAML_create_object(NULL, NULL);
4287 nids = cYAML_create_object(root, name);
4293 for (i = 0; i < nid_list.rlst_num_nids; i++) {
4294 char nidenum[LNET_MAX_STR_LEN];
4295 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
4296 if (!cYAML_create_string(nids, nidenum,
4297 libcfs_nid2str(nid_list.rlst_nid_array[i])))
4301 snprintf(err_str, sizeof(err_str), "success\n");
4306 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4307 cYAML_free_tree(root);
4308 } else if (show_rc != NULL && *show_rc != NULL) {
4309 struct cYAML *show_node;
4310 /* find the net node, if one doesn't exist
4311 * then insert one. Otherwise add to the one there
4313 show_node = cYAML_get_object_item(*show_rc, name);
4314 if (show_node != NULL && cYAML_is_sequence(show_node)) {
4315 cYAML_insert_child(show_node, nids);
4318 } else if (show_node == NULL) {
4319 cYAML_insert_sibling((*show_rc)->cy_child,
4323 cYAML_free_tree(root);
4329 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
4334 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
4335 struct cYAML **err_rc)
4337 struct libcfs_ioctl_data data;
4339 char err_str[LNET_MAX_STR_LEN] = "Error";
4340 lnet_nid_t pnid = LNET_NID_ANY;
4343 rc = LUSTRE_CFG_RC_BAD_PARAM;
4344 snprintf(err_str, LNET_MAX_STR_LEN,
4345 "--nid must be specified");
4349 pnid = libcfs_str2nid(peer_nid);
4350 if (pnid == LNET_NID_ANY) {
4351 rc = LUSTRE_CFG_RC_BAD_PARAM;
4352 snprintf(err_str, LNET_MAX_STR_LEN,
4353 "badly formatted primary NID: %s", peer_nid);
4357 LIBCFS_IOC_INIT(data);
4358 data.ioc_net = LNET_NIDNET(pnid);
4359 data.ioc_nid = pnid;
4361 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4365 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4371 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4372 struct cYAML **err_rc)
4374 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4375 seq_no, show_rc, err_rc);
4378 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4379 struct cYAML **err_rc)
4381 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4382 seq_no, show_rc, err_rc);
4385 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4386 struct cYAML **err_rc)
4388 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4389 char val[LNET_MAX_STR_LEN];
4390 int rsp_tracking = -1, l_errno = 0;
4391 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4393 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4397 snprintf(err_str, sizeof(err_str),
4398 "\"cannot get lnet_response_tracking value: %d\"", rc);
4400 rsp_tracking = atoi(val);
4403 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4404 "response_tracking", rsp_tracking,
4405 show_rc, err_rc, l_errno);
4408 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4409 struct cYAML **err_rc)
4411 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4412 char val[LNET_MAX_STR_LEN];
4413 int recov_limit = -1, l_errno = 0;
4414 char err_str[LNET_MAX_STR_LEN];
4416 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4418 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4422 snprintf(err_str, sizeof(err_str),
4423 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4425 recov_limit = atoi(val);
4428 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4429 "recovery_limit", recov_limit,
4430 show_rc, err_rc, l_errno);
4433 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4434 struct cYAML **show_rc,
4435 struct cYAML **err_rc)
4437 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4438 char val[LNET_MAX_STR_LEN];
4439 int interval = -1, l_errno = 0;
4440 char err_str[LNET_MAX_STR_LEN];
4442 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4444 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4445 val, 1, sizeof(val));
4448 snprintf(err_str, sizeof(err_str),
4449 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4452 interval = atoi(val);
4455 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4456 "max_recovery_ping_interval", interval,
4457 show_rc, err_rc, l_errno);
4461 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4462 struct cYAML **err_rc)
4464 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4465 char val[LNET_MAX_STR_LEN];
4466 int max_intf = -1, l_errno = 0;
4467 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4469 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4473 snprintf(err_str, sizeof(err_str),
4474 "\"cannot get max interfaces: %d\"", rc);
4476 max_intf = atoi(val);
4479 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4480 "max_interfaces", max_intf, show_rc,
4484 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4485 struct cYAML **err_rc)
4487 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4488 char val[LNET_MAX_STR_LEN];
4489 int discovery = -1, l_errno = 0;
4490 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4492 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4496 snprintf(err_str, sizeof(err_str),
4497 "\"cannot get discovery setting: %d\"", rc);
4500 * The kernel stores a discovery disabled value. User space
4501 * shows whether discovery is enabled. So the value must be
4504 discovery = !atoi(val);
4507 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4508 "discovery", discovery, show_rc,
4512 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4513 struct cYAML **err_rc)
4515 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4516 char val[LNET_MAX_STR_LEN];
4517 int drop_asym_route = -1, l_errno = 0;
4518 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4520 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4524 snprintf(err_str, sizeof(err_str),
4525 "\"cannot get drop asym route setting: %d\"", rc);
4527 drop_asym_route = atoi(val);
4530 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4531 "drop_asym_route", drop_asym_route,
4532 show_rc, err_rc, l_errno);
4535 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4536 struct cYAML **err_rc)
4538 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4539 "numa_range", show_rc, err_rc);
4542 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4543 struct cYAML **err_rc)
4545 struct lnet_ioctl_lnet_stats data;
4546 struct lnet_counters *cntrs;
4548 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4549 struct cYAML *root = NULL, *stats = NULL;
4551 LIBCFS_IOC_INIT_V2(data, st_hdr);
4553 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4557 "\"cannot get lnet statistics: %s\"",
4562 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4564 cntrs = &data.st_cntrs;
4566 root = cYAML_create_object(NULL, NULL);
4570 stats = cYAML_create_object(root, "statistics");
4574 if (!cYAML_create_number(stats, "msgs_alloc",
4575 cntrs->lct_common.lcc_msgs_alloc))
4578 if (!cYAML_create_number(stats, "msgs_max",
4579 cntrs->lct_common.lcc_msgs_max))
4582 if (!cYAML_create_number(stats, "rst_alloc",
4583 cntrs->lct_health.lch_rst_alloc))
4586 if (!cYAML_create_number(stats, "errors",
4587 cntrs->lct_common.lcc_errors))
4590 if (!cYAML_create_number(stats, "send_count",
4591 cntrs->lct_common.lcc_send_count))
4594 if (!cYAML_create_number(stats, "resend_count",
4595 cntrs->lct_health.lch_resend_count))
4598 if (!cYAML_create_number(stats, "response_timeout_count",
4599 cntrs->lct_health.lch_response_timeout_count))
4602 if (!cYAML_create_number(stats, "local_interrupt_count",
4603 cntrs->lct_health.lch_local_interrupt_count))
4606 if (!cYAML_create_number(stats, "local_dropped_count",
4607 cntrs->lct_health.lch_local_dropped_count))
4610 if (!cYAML_create_number(stats, "local_aborted_count",
4611 cntrs->lct_health.lch_local_aborted_count))
4614 if (!cYAML_create_number(stats, "local_no_route_count",
4615 cntrs->lct_health.lch_local_no_route_count))
4618 if (!cYAML_create_number(stats, "local_timeout_count",
4619 cntrs->lct_health.lch_local_timeout_count))
4622 if (!cYAML_create_number(stats, "local_error_count",
4623 cntrs->lct_health.lch_local_error_count))
4626 if (!cYAML_create_number(stats, "remote_dropped_count",
4627 cntrs->lct_health.lch_remote_dropped_count))
4630 if (!cYAML_create_number(stats, "remote_error_count",
4631 cntrs->lct_health.lch_remote_error_count))
4634 if (!cYAML_create_number(stats, "remote_timeout_count",
4635 cntrs->lct_health.lch_remote_timeout_count))
4638 if (!cYAML_create_number(stats, "network_timeout_count",
4639 cntrs->lct_health.lch_network_timeout_count))
4642 if (!cYAML_create_number(stats, "recv_count",
4643 cntrs->lct_common.lcc_recv_count))
4646 if (!cYAML_create_number(stats, "route_count",
4647 cntrs->lct_common.lcc_route_count))
4650 if (!cYAML_create_number(stats, "drop_count",
4651 cntrs->lct_common.lcc_drop_count))
4654 if (!cYAML_create_number(stats, "send_length",
4655 cntrs->lct_common.lcc_send_length))
4658 if (!cYAML_create_number(stats, "recv_length",
4659 cntrs->lct_common.lcc_recv_length))
4662 if (!cYAML_create_number(stats, "route_length",
4663 cntrs->lct_common.lcc_route_length))
4666 if (!cYAML_create_number(stats, "drop_length",
4667 cntrs->lct_common.lcc_drop_length))
4671 cYAML_print_tree(root);
4673 snprintf(err_str, sizeof(err_str), "\"success\"");
4674 rc = LUSTRE_CFG_RC_NO_ERR;
4676 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4677 cYAML_free_tree(root);
4678 } else if (show_rc != NULL && *show_rc != NULL) {
4679 cYAML_insert_sibling((*show_rc)->cy_child,
4686 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4691 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4693 struct libcfs_ioctl_data data;
4694 int rc = LUSTRE_CFG_RC_NO_ERR;
4696 char err_str[LNET_MAX_STR_LEN];
4698 LIBCFS_IOC_INIT(data);
4700 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4705 "\"cannot reset lnet statistics: %s\"",
4709 snprintf(err_str, sizeof(err_str), "\"success\"");
4710 rc = LUSTRE_CFG_RC_NO_ERR;
4713 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4717 typedef int (*cmd_handler_t)(struct cYAML *tree,
4718 struct cYAML **show_rc,
4719 struct cYAML **err_rc);
4721 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4722 struct cYAML **err_rc)
4724 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4726 net = cYAML_get_object_item(tree, "net");
4727 gw = cYAML_get_object_item(tree, "gateway");
4728 hop = cYAML_get_object_item(tree, "hop");
4729 prio = cYAML_get_object_item(tree, "priority");
4730 sen = cYAML_get_object_item(tree, "health_sensitivity");
4731 seq_no = cYAML_get_object_item(tree, "seq_no");
4733 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4734 (gw) ? gw->cy_valuestring : NULL,
4735 (hop) ? hop->cy_valueint : -1,
4736 (prio) ? prio->cy_valueint : -1,
4737 (sen) ? sen->cy_valueint : -1,
4738 (seq_no) ? seq_no->cy_valueint : -1,
4744 * 0: <intf_name>['['<expr>']']
4745 * 1: <intf_name>['['<expr>']']
4747 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4748 struct lnet_dlc_network_descr *nw_descr)
4750 struct cYAML *child = NULL;
4751 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4752 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4754 if (intf_tree == NULL || nw_descr == NULL)
4755 return LUSTRE_CFG_RC_BAD_PARAM;
4757 /* now grab all the interfaces and their cpts */
4758 child = intf_tree->cy_child;
4759 while (child != NULL) {
4760 if (child->cy_valuestring == NULL) {
4761 child = child->cy_next;
4765 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4768 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4769 child->cy_valuestring,
4770 strlen(child->cy_valuestring));
4771 if (rc != LUSTRE_CFG_RC_NO_ERR)
4775 child = child->cy_next;
4779 return LUSTRE_CFG_RC_MISSING_PARAM;
4784 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4786 list_del(&intf_descr->intf_on_network);
4787 free_intf_descr(intf_descr);
4794 yaml_extract_cmn_tunables(struct cYAML *tree,
4795 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4797 struct cYAML *tun, *item;
4799 tun = cYAML_get_object_item(tree, "tunables");
4801 item = cYAML_get_object_item(tun, "peer_timeout");
4803 tunables->lct_peer_timeout = item->cy_valueint;
4805 tunables->lct_peer_timeout = -1;
4806 item = cYAML_get_object_item(tun, "peer_credits");
4808 tunables->lct_peer_tx_credits = item->cy_valueint;
4809 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4811 tunables->lct_peer_rtr_credits = item->cy_valueint;
4812 item = cYAML_get_object_item(tun, "credits");
4814 tunables->lct_max_tx_credits = item->cy_valueint;
4823 yaml_extract_tunables(struct cYAML *tree,
4824 struct lnet_ioctl_config_lnd_tunables *tunables,
4829 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4834 lustre_yaml_extract_lnd_tunables(tree, net_type,
4841 yaml_extract_cpt(struct cYAML *tree,
4842 struct cfs_expr_list **global_cpts)
4847 smp = cYAML_get_object_item(tree, "CPT");
4849 rc = cfs_expr_list_parse(smp->cy_valuestring,
4850 strlen(smp->cy_valuestring),
4851 0, UINT_MAX, global_cpts);
4853 *global_cpts = NULL;
4859 * - net type: <net>[<NUM>]
4861 * - nid: <ip>@<net>[<NUM>]
4864 * 0: <intf_name>['['<expr>']']
4865 * 1: <intf_name>['['<expr>']']
4867 * peer_timeout: <NUM>
4868 * peer_credits: <NUM>
4869 * peer_buffer_credits: <NUM>
4872 * peercredits_hiw: <NUM>
4873 * map_on_demand: <NUM>
4874 * concurrent_sends: <NUM>
4875 * fmr_pool_size: <NUM>
4876 * fmr_flush_trigger: <NUM>
4879 * At least one interface is required. If no interfaces are provided the
4880 * network interface can not be configured.
4882 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4883 struct cYAML **err_rc)
4885 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4887 int num_entries = 0, rc;
4888 struct lnet_dlc_network_descr nw_descr;
4889 struct cfs_expr_list *global_cpts = NULL;
4890 struct lnet_ioctl_config_lnd_tunables tunables;
4893 memset(&tunables, 0, sizeof(tunables));
4894 /* Use LND defaults */
4895 tunables.lt_cmn.lct_peer_timeout = -1;
4896 tunables.lt_cmn.lct_peer_tx_credits = -1;
4897 tunables.lt_cmn.lct_peer_rtr_credits = -1;
4898 tunables.lt_cmn.lct_max_tx_credits = -1;
4900 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4901 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4903 ip2net = cYAML_get_object_item(tree, "ip2net");
4904 net = cYAML_get_object_item(tree, "net type");
4906 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4908 nw_descr.nw_id = LOLND;
4911 * if neither net nor ip2nets are present, then we can not
4912 * configure the network.
4914 if (!net && !ip2net)
4915 return LUSTRE_CFG_RC_MISSING_PARAM;
4917 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4918 if (local_nis == NULL)
4919 return LUSTRE_CFG_RC_MISSING_PARAM;
4921 if (!cYAML_is_sequence(local_nis))
4922 return LUSTRE_CFG_RC_BAD_PARAM;
4924 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4925 intf = cYAML_get_object_item(item, "interfaces");
4928 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4929 if (num_entries <= 0) {
4930 cYAML_build_error(num_entries, -1, "ni", "add",
4931 "bad interface list",
4933 return LUSTRE_CFG_RC_BAD_PARAM;
4937 found = yaml_extract_tunables(tree, &tunables,
4938 LNET_NETTYP(nw_descr.nw_id));
4939 yaml_extract_cpt(tree, &global_cpts);
4940 seq_no = cYAML_get_object_item(tree, "seq_no");
4942 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4943 (ip2net) ? ip2net->cy_valuestring : NULL,
4944 (found) ? &tunables : NULL,
4945 (seq_no) ? seq_no->cy_valueint : -1,
4948 if (global_cpts != NULL)
4949 cfs_expr_list_free(global_cpts);
4956 * - net-spec: <tcp|o2ib|gni>[NUM]
4958 * 0: <intf name>['['<expr>']']
4959 * 1: <intf name>['['<expr>']']
4961 * 0: <expr.expr.expr.expr>
4962 * 1: <expr.expr.expr.expr>
4964 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4965 struct cYAML **show_rc,
4966 struct cYAML **err_rc)
4968 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4970 struct lustre_lnet_ip2nets ip2nets;
4971 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4973 int rc = LUSTRE_CFG_RC_NO_ERR;
4974 struct cfs_expr_list *global_cpts = NULL;
4975 struct cfs_expr_list *el, *el_tmp;
4976 struct lnet_ioctl_config_lnd_tunables tunables;
4977 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4980 memset(&tunables, 0, sizeof(tunables));
4982 /* initialize all lists */
4983 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4984 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4985 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4987 net = cYAML_get_object_item(tree, "net-spec");
4989 return LUSTRE_CFG_RC_BAD_PARAM;
4991 if (net != NULL && net->cy_valuestring == NULL)
4992 return LUSTRE_CFG_RC_BAD_PARAM;
4994 /* assign the network id */
4995 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4996 if (ip2nets.ip2nets_net.nw_id == LNET_NET_ANY)
4997 return LUSTRE_CFG_RC_BAD_PARAM;
4999 seq_no = cYAML_get_object_item(tree, "seq_no");
5001 intf = cYAML_get_object_item(tree, "interfaces");
5003 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
5005 return LUSTRE_CFG_RC_BAD_PARAM;
5008 ip_range = cYAML_get_object_item(tree, "ip-range");
5009 if (ip_range != NULL) {
5010 item = ip_range->cy_child;
5011 while (item != NULL) {
5012 if (item->cy_valuestring == NULL) {
5013 item = item->cy_next;
5017 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
5018 item->cy_valuestring);
5020 if (rc != LUSTRE_CFG_RC_NO_ERR)
5023 item = item->cy_next;
5027 found = yaml_extract_tunables(tree, &tunables,
5028 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
5029 yaml_extract_cpt(tree, &global_cpts);
5031 rc = lustre_lnet_config_ip2nets(&ip2nets,
5032 (found) ? &tunables : NULL,
5034 (seq_no) ? seq_no->cy_valueint : -1,
5037 if (global_cpts != NULL)
5038 cfs_expr_list_free(global_cpts);
5041 * don't stop because there was no match. Continue processing the
5042 * rest of the rules. If non-match then nothing is configured
5044 if (rc == LUSTRE_CFG_RC_NO_MATCH)
5045 rc = LUSTRE_CFG_RC_NO_ERR;
5047 list_for_each_entry_safe(intf_descr, intf_tmp,
5048 &ip2nets.ip2nets_net.nw_intflist,
5050 list_del(&intf_descr->intf_on_network);
5051 free_intf_descr(intf_descr);
5054 list_for_each_entry_safe(ip_range_descr, tmp,
5055 &ip2nets.ip2nets_ip_ranges,
5057 list_del(&ip_range_descr->ipr_entry);
5058 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
5060 list_del(&el->el_link);
5061 cfs_expr_list_free(el);
5063 free(ip_range_descr);
5069 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
5070 struct cYAML **err_rc)
5072 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
5074 int num_entries, rc;
5075 struct lnet_dlc_network_descr nw_descr;
5077 INIT_LIST_HEAD(&nw_descr.network_on_rule);
5078 INIT_LIST_HEAD(&nw_descr.nw_intflist);
5080 net = cYAML_get_object_item(tree, "net type");
5082 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
5084 local_nis = cYAML_get_object_item(tree, "local NI(s)");
5085 if (local_nis == NULL)
5086 return LUSTRE_CFG_RC_MISSING_PARAM;
5088 if (!cYAML_is_sequence(local_nis))
5089 return LUSTRE_CFG_RC_BAD_PARAM;
5091 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
5092 intf = cYAML_get_object_item(item, "interfaces");
5095 num_entries = yaml_copy_intf_info(intf, &nw_descr);
5096 if (num_entries <= 0) {
5097 cYAML_build_error(num_entries, -1, "ni", "add",
5098 "bad interface list",
5100 return LUSTRE_CFG_RC_BAD_PARAM;
5104 seq_no = cYAML_get_object_item(tree, "seq_no");
5106 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
5107 (seq_no) ? seq_no->cy_valueint : -1,
5113 /* Create a nidstring parseable by the nidstrings library from the nid
5114 * information encoded in the CYAML structure.
5115 * NOTE: Caller must free memory allocated to nidstr
5117 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
5118 char *prim_nid, int cmd)
5120 int num_strs = 0, rc;
5121 size_t buf_size, buf_pos, nidstr_len = 0;
5123 struct cYAML *child = NULL, *entry = NULL;
5125 if (cYAML_is_sequence(nids_entry)) {
5126 while (cYAML_get_next_seq_item(nids_entry, &child)) {
5127 entry = cYAML_get_object_item(child, "nid");
5128 /* don't count an empty entry */
5129 if (!entry || !entry->cy_valuestring)
5133 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
5134 if (cmd == LNETCTL_DEL_CMD) {
5136 * primary nid is present in the list of
5137 * nids so that means we want to delete
5138 * the entire peer, so no need to go
5139 * further. Just delete the entire peer.
5141 return LUSTRE_CFG_RC_NO_ERR;
5148 * + 1 for the space separating each string, and
5149 * accounts for the terminating null char
5151 nidstr_len += strlen(entry->cy_valuestring) + 1;
5156 if (num_strs == 0 && !prim_nid)
5157 return LUSTRE_CFG_RC_MISSING_PARAM;
5158 else if (num_strs == 0) /* Only the primary nid was given to add/del */
5159 return LUSTRE_CFG_RC_NO_ERR;
5161 buffer = malloc(nidstr_len);
5163 return LUSTRE_CFG_RC_OUT_OF_MEM;
5165 /* now grab all the nids */
5168 buf_size = nidstr_len;
5170 while (cYAML_get_next_seq_item(nids_entry, &child)) {
5171 entry = cYAML_get_object_item(child, "nid");
5172 if (!entry || !entry->cy_valuestring)
5176 (strcmp(entry->cy_valuestring, prim_nid) == 0))
5180 rc = snprintf(buffer + buf_pos, buf_size, " ");
5181 buf_pos += (rc < buf_size) ? rc : buf_size;
5182 buf_size = nidstr_len - buf_pos;
5185 rc = snprintf(buffer + buf_pos, buf_size, "%s",
5186 entry->cy_valuestring);
5187 buf_pos += (rc < buf_size) ? rc : buf_size;
5188 buf_size = nidstr_len - buf_pos;
5193 return LUSTRE_CFG_RC_NO_ERR;
5196 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
5197 struct cYAML **err_rc, int cmd)
5199 int rc, num_nids = 0, seqn;
5200 bool mr_value = false;
5201 char *nidstr = NULL, *prim_nidstr;
5202 char err_str[LNET_MAX_STR_LEN];
5203 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
5204 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
5205 lnet_nid_t pnid = LNET_NID_ANY;
5208 seq_no = cYAML_get_object_item(tree, "seq_no");
5209 seqn = seq_no ? seq_no->cy_valueint : -1;
5211 prim_nid = cYAML_get_object_item(tree, "primary nid");
5212 peer_nis = cYAML_get_object_item(tree, "peer ni");
5214 rc = LUSTRE_CFG_RC_BAD_PARAM;
5215 snprintf(err_str, LNET_MAX_STR_LEN,
5216 "\"primary nid\" must be specified");
5220 prim_nidstr = prim_nid->cy_valuestring;
5222 /* if the provided primary NID is bad, no need to go any further */
5223 pnid = libcfs_str2nid(prim_nidstr);
5224 if (pnid == LNET_NID_ANY) {
5225 rc = LUSTRE_CFG_RC_BAD_PARAM;
5226 snprintf(err_str, LNET_MAX_STR_LEN,
5227 "badly formatted primary NID: %s", prim_nidstr);
5231 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
5232 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
5233 snprintf(err_str, LNET_MAX_STR_LEN,
5234 "No nids defined in YAML block");
5236 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
5237 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
5239 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
5240 snprintf(err_str, LNET_MAX_STR_LEN,
5241 "Unrecognized error %d", rc);
5247 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
5248 LNET_MAX_NIDS_PER_PEER,
5256 if (cmd == LNETCTL_ADD_CMD) {
5257 mr = cYAML_get_object_item(tree, "Multi-Rail");
5259 if (mr && mr->cy_valuestring) {
5260 if (strcmp(mr->cy_valuestring, "False") == 0)
5262 else if (strcmp(mr->cy_valuestring, "True") != 0) {
5263 rc = LUSTRE_CFG_RC_BAD_PARAM;
5264 snprintf(err_str, LNET_MAX_STR_LEN,
5265 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
5266 mr->cy_valuestring);
5272 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
5273 num_nids, mr_value, force,
5280 if (rc != LUSTRE_CFG_RC_NO_ERR)
5281 cYAML_build_error(rc, seqn, "peer",
5282 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
5288 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
5289 struct cYAML **err_rc)
5291 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
5294 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
5295 struct cYAML **err_rc)
5297 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
5300 static int handle_yaml_config_buffers(struct cYAML *tree,
5301 struct cYAML **show_rc,
5302 struct cYAML **err_rc)
5305 struct cYAML *tiny, *small, *large, *seq_no;
5307 tiny = cYAML_get_object_item(tree, "tiny");
5308 small = cYAML_get_object_item(tree, "small");
5309 large = cYAML_get_object_item(tree, "large");
5310 seq_no = cYAML_get_object_item(tree, "seq_no");
5312 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
5313 (small) ? small->cy_valueint : -1,
5314 (large) ? large->cy_valueint : -1,
5315 (seq_no) ? seq_no->cy_valueint : -1,
5321 static int handle_yaml_config_routing(struct cYAML *tree,
5322 struct cYAML **show_rc,
5323 struct cYAML **err_rc)
5325 int rc = LUSTRE_CFG_RC_NO_ERR;
5326 struct cYAML *seq_no, *enable;
5328 seq_no = cYAML_get_object_item(tree, "seq_no");
5329 enable = cYAML_get_object_item(tree, "enable");
5332 rc = lustre_lnet_enable_routing(enable->cy_valueint,
5334 seq_no->cy_valueint : -1,
5341 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
5342 struct cYAML **err_rc)
5346 struct cYAML *seq_no;
5348 net = cYAML_get_object_item(tree, "net");
5349 gw = cYAML_get_object_item(tree, "gateway");
5350 seq_no = cYAML_get_object_item(tree, "seq_no");
5352 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5353 (gw) ? gw->cy_valuestring : NULL,
5354 (seq_no) ? seq_no->cy_valueint : -1,
5358 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5359 struct cYAML **err_rc)
5361 struct cYAML *seq_no;
5363 seq_no = cYAML_get_object_item(tree, "seq_no");
5365 return lustre_lnet_enable_routing(0, (seq_no) ?
5366 seq_no->cy_valueint : -1,
5370 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5371 struct cYAML **err_rc)
5377 struct cYAML *detail;
5378 struct cYAML *seq_no;
5380 net = cYAML_get_object_item(tree, "net");
5381 gw = cYAML_get_object_item(tree, "gateway");
5382 hop = cYAML_get_object_item(tree, "hop");
5383 prio = cYAML_get_object_item(tree, "priority");
5384 detail = cYAML_get_object_item(tree, "detail");
5385 seq_no = cYAML_get_object_item(tree, "seq_no");
5387 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5388 (gw) ? gw->cy_valuestring : NULL,
5389 (hop) ? hop->cy_valueint : -1,
5390 (prio) ? prio->cy_valueint : -1,
5391 (detail) ? detail->cy_valueint : 0,
5392 (seq_no) ? seq_no->cy_valueint : -1,
5393 show_rc, err_rc, false);
5396 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5397 struct cYAML **err_rc)
5399 struct cYAML *net, *detail, *seq_no;
5401 net = cYAML_get_object_item(tree, "net type");
5402 detail = cYAML_get_object_item(tree, "detail");
5403 seq_no = cYAML_get_object_item(tree, "seq_no");
5405 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5406 (detail) ? detail->cy_valueint : 0,
5407 (seq_no) ? seq_no->cy_valueint : -1,
5408 show_rc, err_rc, false);
5411 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5412 struct cYAML **err_rc)
5414 struct cYAML *seq_no;
5416 seq_no = cYAML_get_object_item(tree, "seq_no");
5418 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5419 show_rc, err_rc, false);
5422 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5423 struct cYAML **err_rc)
5425 struct cYAML *seq_no, *nid, *detail;
5427 seq_no = cYAML_get_object_item(tree, "seq_no");
5428 detail = cYAML_get_object_item(tree, "detail");
5429 nid = cYAML_get_object_item(tree, "nid");
5431 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5432 (detail) ? detail->cy_valueint : 0,
5433 (seq_no) ? seq_no->cy_valueint : -1,
5434 show_rc, err_rc, false);
5437 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5438 struct cYAML **err_rc)
5440 struct cYAML *seq_no;
5442 seq_no = cYAML_get_object_item(tree, "seq_no");
5444 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5448 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5449 struct cYAML **err_rc)
5451 struct cYAML *seq_no, *range;
5453 seq_no = cYAML_get_object_item(tree, "seq_no");
5454 range = cYAML_get_object_item(tree, "range");
5456 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5457 seq_no ? seq_no->cy_valueint : -1,
5461 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5462 struct cYAML **err_rc)
5464 struct cYAML *seq_no;
5466 seq_no = cYAML_get_object_item(tree, "seq_no");
5468 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5472 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5473 struct cYAML **err_rc)
5475 struct cYAML *seq_no;
5477 seq_no = cYAML_get_object_item(tree, "seq_no");
5479 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5483 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5484 struct cYAML **err_rc)
5486 struct cYAML *seq_no, *idx;
5488 seq_no = cYAML_get_object_item(tree, "seq_no");
5489 idx = cYAML_get_object_item(tree, "idx");
5491 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5492 seq_no ? seq_no->cy_valueint : -1,
5496 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5497 struct cYAML **err_rc)
5499 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5500 union lnet_udsp_action action;
5502 seq_no = cYAML_get_object_item(tree, "seq_no");
5503 src = cYAML_get_object_item(tree, "src");
5504 rte = cYAML_get_object_item(tree, "rte");
5505 dst = cYAML_get_object_item(tree, "dst");
5506 prio = cYAML_get_object_item(tree, "priority");
5507 idx = cYAML_get_object_item(tree, "idx");
5509 action.udsp_priority = prio ? prio->cy_valueint : -1;
5511 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5512 dst ? dst->cy_valuestring : NULL,
5513 rte ? rte->cy_valuestring : NULL,
5514 prio ? "priority" : "",
5516 idx ? idx->cy_valueint : -1,
5517 seq_no ? seq_no->cy_valueint : -1,
5521 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5522 struct cYAML **err_rc)
5524 struct cYAML *seq_no;
5527 seq_no = cYAML_get_object_item(tree, "seq_no");
5528 idx = cYAML_get_object_item(tree, "idx");
5530 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5531 seq_no ? seq_no->cy_valueint : -1,
5535 static int handle_yaml_config_global_settings(struct cYAML *tree,
5536 struct cYAML **show_rc,
5537 struct cYAML **err_rc)
5539 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5540 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5544 seq_no = cYAML_get_object_item(tree, "seq_no");
5545 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5546 if (!max_intf) /* try legacy name */
5547 max_intf = cYAML_get_object_item(tree, "max_intf");
5549 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5550 seq_no ? seq_no->cy_valueint
5554 numa = cYAML_get_object_item(tree, "numa_range");
5556 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5557 seq_no ? seq_no->cy_valueint
5561 discovery = cYAML_get_object_item(tree, "discovery");
5563 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5564 seq_no ? seq_no->cy_valueint
5568 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5569 if (drop_asym_route)
5570 rc = lustre_lnet_config_drop_asym_route(
5571 drop_asym_route->cy_valueint,
5572 seq_no ? seq_no->cy_valueint : -1,
5575 retry = cYAML_get_object_item(tree, "retry_count");
5577 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5578 seq_no ? seq_no->cy_valueint
5582 tto = cYAML_get_object_item(tree, "transaction_timeout");
5584 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5585 seq_no ? seq_no->cy_valueint
5589 sen = cYAML_get_object_item(tree, "health_sensitivity");
5591 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5592 seq_no ? seq_no->cy_valueint
5596 recov = cYAML_get_object_item(tree, "recovery_interval");
5598 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5599 seq_no ? seq_no->cy_valueint
5603 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5605 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5606 seq_no ? seq_no->cy_valueint
5610 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5612 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5613 seq_no ? seq_no->cy_valueint
5617 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5619 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5620 seq_no ? seq_no->cy_valueint
5627 static int handle_yaml_del_global_settings(struct cYAML *tree,
5628 struct cYAML **show_rc,
5629 struct cYAML **err_rc)
5631 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5634 seq_no = cYAML_get_object_item(tree, "seq_no");
5635 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5636 if (!max_intf) /* try legacy name */
5637 max_intf = cYAML_get_object_item(tree, "max_intf");
5639 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5640 seq_no ? seq_no->cy_valueint
5644 numa = cYAML_get_object_item(tree, "numa_range");
5646 rc = lustre_lnet_config_numa_range(0,
5647 seq_no ? seq_no->cy_valueint
5651 /* peer discovery is enabled by default */
5652 discovery = cYAML_get_object_item(tree, "discovery");
5654 rc = lustre_lnet_config_discovery(1,
5655 seq_no ? seq_no->cy_valueint
5659 /* asymmetrical route messages are accepted by default */
5660 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5661 if (drop_asym_route)
5662 rc = lustre_lnet_config_drop_asym_route(
5663 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5668 static int handle_yaml_show_global_settings(struct cYAML *tree,
5669 struct cYAML **show_rc,
5670 struct cYAML **err_rc)
5672 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5673 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5677 seq_no = cYAML_get_object_item(tree, "seq_no");
5678 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5679 if (!max_intf) /* try legacy name */
5680 max_intf = cYAML_get_object_item(tree, "max_intf");
5682 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5686 numa = cYAML_get_object_item(tree, "numa_range");
5688 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5692 discovery = cYAML_get_object_item(tree, "discovery");
5694 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5698 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5699 if (drop_asym_route)
5700 rc = lustre_lnet_show_drop_asym_route(
5701 seq_no ? seq_no->cy_valueint : -1,
5704 retry = cYAML_get_object_item(tree, "retry_count");
5706 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5710 tto = cYAML_get_object_item(tree, "transaction_timeout");
5712 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5716 sen = cYAML_get_object_item(tree, "health_sensitivity");
5718 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5722 recov = cYAML_get_object_item(tree, "recovery_interval");
5724 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5728 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5730 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5734 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5736 rc = lustre_lnet_show_response_tracking(seq_no ?
5737 seq_no->cy_valueint :
5741 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5743 rc = lustre_lnet_show_recovery_limit(seq_no ?
5744 seq_no->cy_valueint :
5751 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5752 struct cYAML **err_rc)
5754 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5756 seq_no = cYAML_get_object_item(tree, "seq_no");
5757 nid = cYAML_get_object_item(tree, "primary nid");
5758 timeout = cYAML_get_object_item(tree, "timeout");
5759 src_nid = cYAML_get_object_item(tree, "source_nid");
5761 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5762 (src_nid) ? src_nid->cy_valuestring : NULL,
5763 (timeout) ? timeout->cy_valueint : 1000,
5764 (seq_no) ? seq_no->cy_valueint : -1,
5768 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5769 struct cYAML **err_rc)
5771 struct cYAML *seq_no, *nid, *force;
5773 seq_no = cYAML_get_object_item(tree, "seq_no");
5774 nid = cYAML_get_object_item(tree, "primary nid");
5775 force = cYAML_get_object_item(tree, "force");
5777 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5778 (force) ? force->cy_valueint : 0,
5779 (seq_no) ? seq_no->cy_valueint : -1,
5783 static int handle_yaml_no_op()
5785 return LUSTRE_CFG_RC_NO_ERR;
5788 struct lookup_cmd_hdlr_tbl {
5793 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5794 { .name = "route", .cb = handle_yaml_config_route },
5795 { .name = "net", .cb = handle_yaml_config_ni },
5796 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5797 { .name = "peer", .cb = handle_yaml_config_peer },
5798 { .name = "routing", .cb = handle_yaml_config_routing },
5799 { .name = "buffers", .cb = handle_yaml_config_buffers },
5800 { .name = "statistics", .cb = handle_yaml_no_op },
5801 { .name = "global", .cb = handle_yaml_config_global_settings},
5802 { .name = "numa", .cb = handle_yaml_config_numa },
5803 { .name = "ping", .cb = handle_yaml_no_op },
5804 { .name = "discover", .cb = handle_yaml_no_op },
5805 { .name = "udsp", .cb = handle_yaml_config_udsp },
5808 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5809 { .name = "route", .cb = handle_yaml_del_route },
5810 { .name = "net", .cb = handle_yaml_del_ni },
5811 { .name = "ip2nets", .cb = handle_yaml_no_op },
5812 { .name = "peer", .cb = handle_yaml_del_peer },
5813 { .name = "routing", .cb = handle_yaml_del_routing },
5814 { .name = "buffers", .cb = handle_yaml_no_op },
5815 { .name = "statistics", .cb = handle_yaml_no_op },
5816 { .name = "global", .cb = handle_yaml_del_global_settings},
5817 { .name = "numa", .cb = handle_yaml_del_numa },
5818 { .name = "ping", .cb = handle_yaml_no_op },
5819 { .name = "discover", .cb = handle_yaml_no_op },
5820 { .name = "udsp", .cb = handle_yaml_del_udsp },
5823 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5824 { .name = "route", .cb = handle_yaml_show_route },
5825 { .name = "net", .cb = handle_yaml_show_net },
5826 { .name = "peer", .cb = handle_yaml_show_peers },
5827 { .name = "ip2nets", .cb = handle_yaml_no_op },
5828 { .name = "routing", .cb = handle_yaml_show_routing },
5829 { .name = "buffers", .cb = handle_yaml_show_routing },
5830 { .name = "statistics", .cb = handle_yaml_show_stats },
5831 { .name = "global", .cb = handle_yaml_show_global_settings},
5832 { .name = "numa", .cb = handle_yaml_show_numa },
5833 { .name = "ping", .cb = handle_yaml_no_op },
5834 { .name = "discover", .cb = handle_yaml_no_op },
5835 { .name = "udsp", .cb = handle_yaml_show_udsp },
5838 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5839 { .name = "route", .cb = handle_yaml_no_op },
5840 { .name = "net", .cb = handle_yaml_no_op },
5841 { .name = "peer", .cb = handle_yaml_no_op },
5842 { .name = "ip2nets", .cb = handle_yaml_no_op },
5843 { .name = "routing", .cb = handle_yaml_no_op },
5844 { .name = "buffers", .cb = handle_yaml_no_op },
5845 { .name = "statistics", .cb = handle_yaml_no_op },
5846 { .name = "global", .cb = handle_yaml_no_op },
5847 { .name = "numa", .cb = handle_yaml_no_op },
5848 { .name = "ping", .cb = handle_yaml_ping },
5849 { .name = "discover", .cb = handle_yaml_discover },
5852 static cmd_handler_t lookup_fn(char *key,
5853 struct lookup_cmd_hdlr_tbl *tbl)
5859 for (i = 0; tbl[i].name != NULL; i++) {
5860 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5867 static int lustre_yaml_cb_helper(char *f, int len,
5868 struct lookup_cmd_hdlr_tbl *table,
5869 struct cYAML **show_rc, struct cYAML **err_rc)
5871 struct cYAML *tree, *item = NULL, *head, *child;
5873 char err_str[LNET_MAX_STR_LEN];
5874 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5876 tree = cYAML_build_tree(NULL, f, len, err_rc, false);
5878 return LUSTRE_CFG_RC_BAD_PARAM;
5880 child = tree->cy_child;
5881 while (child != NULL) {
5882 cb = lookup_fn(child->cy_string, table);
5884 snprintf(err_str, sizeof(err_str),
5885 "\"call back for '%s' not found\"",
5887 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5888 "yaml", "helper", err_str, err_rc);
5892 if (cYAML_is_sequence(child)) {
5893 while ((head = cYAML_get_next_seq_item(child, &item))
5895 rc = cb(head, show_rc, err_rc);
5896 if (rc != LUSTRE_CFG_RC_NO_ERR)
5900 rc = cb(child, show_rc, err_rc);
5901 if (rc != LUSTRE_CFG_RC_NO_ERR)
5905 child = child->cy_next;
5909 cYAML_free_tree(tree);
5914 int lustre_yaml_config(char *f, int len, struct cYAML **err_rc)
5916 return lustre_yaml_cb_helper(f, len, lookup_config_tbl,
5920 int lustre_yaml_del(char *f, int len, struct cYAML **err_rc)
5922 return lustre_yaml_cb_helper(f, len, lookup_del_tbl,
5926 int lustre_yaml_show(char *f, int len, struct cYAML **show_rc,
5927 struct cYAML **err_rc)
5929 return lustre_yaml_cb_helper(f, len, lookup_show_tbl,
5933 int lustre_yaml_exec(char *f, int len, struct cYAML **show_rc,
5934 struct cYAML **err_rc)
5936 return lustre_yaml_cb_helper(f, len, lookup_exec_tbl,