4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #ifndef HAVE_USRSPC_RDMA_PS_TCP
59 #define RDMA_PS_TCP 0x0106
62 #define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
63 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
67 * lustre_lnet_ip_range_descr
68 * Describes an IP range.
69 * Each octect is an expression
71 struct lustre_lnet_ip_range_descr {
72 struct list_head ipr_entry;
73 struct list_head ipr_expr;
78 * Describes an ip2nets rule. This can be on a list of rules.
80 struct lustre_lnet_ip2nets {
81 struct lnet_dlc_network_descr ip2nets_net;
82 struct list_head ip2nets_ip_ranges;
85 int open_sysfs_file(const char *path, const char *attr, const int mode)
88 char filename[LNET_MAX_STR_LEN];
90 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
93 snprintf(filename, sizeof(filename), "%s%s",
96 fd = open(filename, mode);
101 static int read_sysfs_file(const char *path, const char *attr,
102 void *val, const size_t size, const int nelem)
105 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
107 fd = open_sysfs_file(path, attr, O_RDONLY);
109 return LUSTRE_CFG_RC_NO_MATCH;
111 if (read(fd, val, size * nelem) == -1)
114 rc = LUSTRE_CFG_RC_NO_ERR;
121 static int write_sysfs_file(const char *path, const char *attr,
122 void *val, const size_t size, const int nelem)
125 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
127 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
129 return LUSTRE_CFG_RC_NO_MATCH;
131 if (write(fd, val, size * nelem) == -1)
134 rc = LUSTRE_CFG_RC_NO_ERR;
143 * frees the memory allocated for an intf descriptor.
145 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
150 if (intf_descr->cpt_expr != NULL)
151 cfs_expr_list_free(intf_descr->cpt_expr);
156 * lustre_lnet_add_ip_range
158 * given a string of the format:
159 * <expr.expr.expr.expr> parse each expr into
160 * a lustre_lnet_ip_range_descr structure and insert on the list.
162 * This function is called from
163 * YAML on each ip-range.
164 * As a result of lnetctl command
165 * When building a NID or P2P selection rules
167 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
169 struct lustre_lnet_ip_range_descr *ip_range;
172 ip_range = calloc(1, sizeof(*ip_range));
173 if (ip_range == NULL)
174 return LUSTRE_CFG_RC_OUT_OF_MEM;
176 INIT_LIST_HEAD(&ip_range->ipr_entry);
177 INIT_LIST_HEAD(&ip_range->ipr_expr);
179 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
180 &ip_range->ipr_expr);
182 return LUSTRE_CFG_RC_BAD_PARAM;
184 list_add_tail(&ip_range->ipr_entry, list);
186 return LUSTRE_CFG_RC_NO_ERR;
189 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
191 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
193 struct lnet_dlc_intf_descr *intf_descr = NULL;
195 char intf_string[LNET_MAX_STR_LEN];
197 if (len >= LNET_MAX_STR_LEN)
198 return LUSTRE_CFG_RC_BAD_PARAM;
200 strncpy(intf_string, intf, len);
201 intf_string[len] = '\0';
203 intf_descr = calloc(1, sizeof(*intf_descr));
204 if (intf_descr == NULL)
205 return LUSTRE_CFG_RC_OUT_OF_MEM;
207 INIT_LIST_HEAD(&intf_descr->intf_on_network);
209 intf_name = intf_string;
210 open_sq_bracket = strchr(intf_string, '[');
211 if (open_sq_bracket != NULL) {
212 close_sq_bracket = strchr(intf_string, ']');
213 if (close_sq_bracket == NULL) {
215 return LUSTRE_CFG_RC_BAD_PARAM;
217 rc = cfs_expr_list_parse(open_sq_bracket,
218 strlen(open_sq_bracket), 0, UINT_MAX,
219 &intf_descr->cpt_expr);
222 return LUSTRE_CFG_RC_BAD_PARAM;
224 strncpy(intf_descr->intf_name, intf_name,
225 open_sq_bracket - intf_name);
226 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
228 strcpy(intf_descr->intf_name, intf_name);
229 intf_descr->cpt_expr = NULL;
232 list_add_tail(&intf_descr->intf_on_network, list);
234 return LUSTRE_CFG_RC_NO_ERR;
237 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
239 if (nw_descr != NULL) {
241 INIT_LIST_HEAD(&nw_descr->network_on_rule);
242 INIT_LIST_HEAD(&nw_descr->nw_intflist);
246 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
247 int max_nids, char *err_str)
249 int rc, num_nids = 0;
250 struct list_head nidlist;
253 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
254 return LUSTRE_CFG_RC_BAD_PARAM;
257 if (strchr(nidstr, '*')) {
258 snprintf(err_str, LNET_MAX_STR_LEN,
259 "asterisk not allowed in nidstring \"%s\"", nidstr);
260 return LUSTRE_CFG_RC_BAD_PARAM;
263 INIT_LIST_HEAD(&nidlist);
264 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
266 snprintf(err_str, LNET_MAX_STR_LEN,
267 "Unable to parse nidlist from: %s\n", nidstr);
268 return LUSTRE_CFG_RC_BAD_PARAM;
271 if (list_empty(&nidlist)) {
272 snprintf(err_str, LNET_MAX_STR_LEN,
273 "\"%s\" does not specify any valid nid lists", nidstr);
274 return LUSTRE_CFG_RC_BAD_PARAM;
277 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
278 cfs_free_nidlist(&nidlist);
280 if (num_nids == -1) {
281 snprintf(err_str, LNET_MAX_STR_LEN,
282 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
284 return LUSTRE_CFG_RC_BAD_PARAM;
288 snprintf(err_str, LNET_MAX_STR_LEN,
289 "Failed to expand nidstr: %s", strerror(num_nids));
290 return LUSTRE_CFG_RC_OUT_OF_MEM;
294 snprintf(err_str, LNET_MAX_STR_LEN,
295 "\"%s\" did not expand to any nids", nidstr);
296 return LUSTRE_CFG_RC_BAD_PARAM;
304 * <intf>[<expr>], <intf>[<expr>],..
306 int lustre_lnet_parse_interfaces(char *intf_str,
307 struct lnet_dlc_network_descr *nw_descr)
312 char *cur = intf_str, *next = NULL;
313 char *end = intf_str + strlen(intf_str);
315 struct lnet_dlc_intf_descr *intf_descr, *tmp;
317 if (nw_descr == NULL)
318 return LUSTRE_CFG_RC_BAD_PARAM;
321 open_square = strchr(cur, '[');
322 if (open_square != NULL) {
323 close_square = strchr(cur, ']');
324 if (close_square == NULL) {
325 rc = LUSTRE_CFG_RC_BAD_PARAM;
329 comma = strchr(cur, ',');
330 if (comma != NULL && comma > close_square) {
332 len = next - close_square;
338 comma = strchr(cur, ',');
348 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
349 if (rc != LUSTRE_CFG_RC_NO_ERR)
355 return LUSTRE_CFG_RC_NO_ERR;
358 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
360 list_del(&intf_descr->intf_on_network);
361 free_intf_descr(intf_descr);
367 int lustre_lnet_config_lib_init(void)
369 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
372 void lustre_lnet_config_lib_uninit(void)
374 unregister_ioc_dev(LNET_DEV_ID);
377 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
378 int seq_no, struct cYAML **err_rc)
380 struct libcfs_ioctl_data data;
383 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
385 LIBCFS_IOC_INIT(data);
387 /* Reverse logic is used here in order not to change
388 * the lctl utility */
389 data.ioc_flags = load_ni_from_mod ? 0 : 1;
391 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
393 rc = l_ioctl(LNET_DEV_ID, opc, &data);
397 "\"LNet %s error: %s\"", (up) ? "configure" :
398 "unconfigure", strerror(errno));
402 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
403 "lnet", err_str, err_rc);
408 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
409 char *err_str, char *cmd_str)
413 rc = l_ioctl(LNET_DEV_ID, cmd, data);
416 snprintf(err_str, LNET_MAX_STR_LEN,
417 "\"%s peer ni operation failed: %s\"",
418 cmd_str, strerror(errno));
424 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
425 int param, int ioc_call, int seq_no,
426 struct cYAML **show_rc, struct cYAML **err_rc)
429 struct lnet_ioctl_ping_data ping;
430 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
431 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
432 struct lnet_process_id id;
433 char err_str[LNET_MAX_STR_LEN] = {0};
434 char *sep, *token, *end;
437 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
442 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
444 data = calloc(1, len);
448 /* create struct cYAML root object */
449 root = cYAML_create_object(NULL, NULL);
453 ping_node = cYAML_create_seq(root, oper);
454 if (ping_node == NULL)
458 src = libcfs_str2nid(src_nidstr);
459 if (src == LNET_NID_ANY) {
460 snprintf(err_str, sizeof(err_str),
461 "\"cannot parse source NID '%s'\"",
463 rc = LUSTRE_CFG_RC_BAD_PARAM;
464 cYAML_build_error(rc, seq_no, MANAGE_CMD,
465 oper, err_str, err_rc);
472 /* tokenise each nid in string ping_nids */
473 token = strtok(ping_nids, ",");
476 item = cYAML_create_seq_item(ping_node);
480 if (first_seq == NULL)
483 /* check if '-' is a part of NID, token */
484 sep = strchr(token, '-');
486 id.pid = LNET_PID_ANY;
487 /* if no net is specified, libcfs_str2nid() will assume tcp */
488 id.nid = libcfs_str2nid(token);
489 if (id.nid == LNET_NID_ANY) {
490 snprintf(err_str, sizeof(err_str),
491 "\"cannot parse NID '%s'\"",
493 rc = LUSTRE_CFG_RC_BAD_PARAM;
494 cYAML_build_error(rc, seq_no, MANAGE_CMD,
495 oper, err_str, err_rc);
499 if (token[0] == 'u' || token[0] == 'U')
500 id.pid = (strtoul(&token[1], &end, 0) |
501 (LNET_PID_USERFLAG));
503 id.pid = strtoul(token, &end, 0);
505 /* assuming '-' is part of hostname */
507 id.pid = LNET_PID_ANY;
508 id.nid = libcfs_str2nid(token);
509 if (id.nid == LNET_NID_ANY) {
510 snprintf(err_str, sizeof(err_str),
511 "\"cannot parse NID '%s'\"",
513 rc = LUSTRE_CFG_RC_BAD_PARAM;
514 cYAML_build_error(rc, seq_no, MANAGE_CMD,
520 id.nid = libcfs_str2nid(sep + 1);
521 if (id.nid == LNET_NID_ANY) {
522 snprintf(err_str, sizeof(err_str),
523 "\"cannot parse NID '%s'\"",
525 rc = LUSTRE_CFG_RC_BAD_PARAM;
526 cYAML_build_error(rc, seq_no, MANAGE_CMD,
533 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
534 ping.ping_hdr.ioc_len = sizeof(ping);
537 ping.op_param = param;
538 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
539 ping.ping_buf = data;
541 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
544 sizeof(err_str), "failed to %s %s: %s\n", oper,
545 id.pid == LNET_PID_ANY ?
546 libcfs_nid2str(id.nid) :
547 libcfs_id2str(id), strerror(errno));
548 rc = LUSTRE_CFG_RC_BAD_PARAM;
549 cYAML_build_error(rc, seq_no, MANAGE_CMD,
550 oper, err_str, err_rc);
554 if (cYAML_create_string(item, "primary nid",
555 libcfs_nid2str(ping.ping_id.nid)) == NULL)
558 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
559 "True" : "False") == NULL)
562 tmp = cYAML_create_seq(item, "peer ni");
566 for (i = 0; i < ping.ping_count; i++) {
567 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
569 peer_ni = cYAML_create_seq_item(tmp);
572 memset(buf, 0, sizeof buf);
573 snprintf(buf, sizeof buf, "nid");
574 if (cYAML_create_string(peer_ni, buf,
575 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
581 } while ((token = strtok(NULL, ",")) != NULL);
584 rc = LUSTRE_CFG_RC_NO_ERR;
589 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
590 cYAML_free_tree(root);
591 } else if (show_rc != NULL && *show_rc != NULL) {
592 struct cYAML *show_node;
593 show_node = cYAML_get_object_item(*show_rc, oper);
594 if (show_node != NULL && cYAML_is_sequence(show_node)) {
595 cYAML_insert_child(show_node, first_seq);
598 } else if (show_node == NULL) {
599 cYAML_insert_sibling((*show_rc)->cy_child,
603 cYAML_free_tree(root);
612 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
613 int seq_no, struct cYAML **show_rc,
614 struct cYAML **err_rc)
618 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
619 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
623 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
624 struct cYAML **show_rc, struct cYAML **err_rc)
628 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
629 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
633 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
634 bool is_mr, __u32 cmd,
635 char *cmd_type, char *err_str)
637 struct lnet_ioctl_peer_cfg data;
640 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
641 /* When adding a peer we first need to create the peer using the
642 * specified (or implied) primary nid. Then we can add
643 * additional nids to this peer using the primary nid as a key
645 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
646 data.prcfg_mr = is_mr;
647 data.prcfg_prim_nid = nidlist[0];
648 data.prcfg_cfg_nid = LNET_NID_ANY;
650 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
656 /* Add or delete any specified NIs associated with the specified
657 * (or implied) primary nid
659 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
660 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
661 data.prcfg_mr = is_mr;
662 data.prcfg_prim_nid = nidlist[0];
663 data.prcfg_cfg_nid = nidlist[nid_idx];
665 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
671 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
672 /* In the delete case we may have been given just the
673 * primary nid of the peer. This tells us to delete the peer
674 * completely (rather than just delete some of its NIs)
676 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
677 data.prcfg_prim_nid = nidlist[0];
678 data.prcfg_cfg_nid = LNET_NID_ANY;
680 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
687 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
688 int cmd, int num_nids, bool is_mr, int seq_no,
689 struct cYAML **err_rc)
691 int rc = LUSTRE_CFG_RC_NO_ERR;
692 char err_str[LNET_MAX_STR_LEN];
693 lnet_nid_t *lnet_nidlist2 = NULL;
694 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
695 IOC_LIBCFS_DEL_PEER_NI;
696 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
699 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
700 if (!lnet_nidlist2) {
701 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
702 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
705 lnet_nidlist2[0] = pnid;
706 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
709 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
710 num_nids, is_mr, ioc_cmd,
716 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
721 replace_sep(char *str, char sep, char newsep)
727 for (i = 0; i < strlen(str); i++) {
728 /* don't replace ',' within [] */
731 else if (str[i] == ']')
733 else if (str[i] == sep && bracket == 0)
738 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
739 int cmd, int seq_no, struct cYAML **err_rc)
742 char err_str[LNET_MAX_STR_LEN] = "Error";
743 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
744 lnet_nid_t pnid = LNET_NID_ANY;
747 rc = LUSTRE_CFG_RC_BAD_PARAM;
748 snprintf(err_str, LNET_MAX_STR_LEN,
749 "--prim_nid must be specified");
753 pnid = libcfs_str2nid(prim_nid);
754 if (pnid == LNET_NID_ANY) {
755 rc = LUSTRE_CFG_RC_BAD_PARAM;
756 snprintf(err_str, LNET_MAX_STR_LEN,
757 "badly formatted primary NID: %s", prim_nid);
764 * if there is no primary nid we need to make the first nid in the
765 * nids list the primary nid
767 replace_sep(nids, ',', ' ');
768 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
769 LNET_MAX_NIDS_PER_PEER, err_str);
776 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
777 cmd, num_nids, is_mr,
781 if (rc != LUSTRE_CFG_RC_NO_ERR)
782 cYAML_build_error(rc, -1, "peer",
783 cmd == LNETCTL_ADD_CMD ? "add" : "del",
789 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
790 int sen, int seq_no, struct cYAML **err_rc,
793 int rc, num_nids, idx;
795 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
796 struct lnet_ioctl_config_data data;
797 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
799 if (nw == NULL || nidstr == NULL) {
800 snprintf(err_str, LNET_MAX_STR_LEN,
801 "\"missing mandatory parameter:'%s'\"",
802 (nw == NULL && nidstr == NULL) ? "network, gateway" :
803 (nw == NULL) ? "network" : "gateway");
804 rc = LUSTRE_CFG_RC_MISSING_PARAM;
808 rnet = libcfs_str2net(nw);
809 if (rnet == LNET_NET_ANY) {
810 snprintf(err_str, LNET_MAX_STR_LEN,
811 "\"cannot parse remote net %s\"", nw);
812 rc = LUSTRE_CFG_RC_BAD_PARAM;
816 replace_sep(nidstr, ',', ' ');
817 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
818 LNET_MAX_NIDS_PER_PEER, err_str);
824 for (idx = 0; idx < num_nids; idx++) {
825 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
827 if (cmd == LNETCTL_ADD_CMD) {
828 data.cfg_config_u.cfg_route.rtr_hop = hops;
829 data.cfg_config_u.cfg_route.rtr_priority = prio;
830 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
833 data.cfg_nid = lnet_nidlist[idx];
835 if (cmd == LNETCTL_ADD_CMD)
836 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
839 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
842 if (rc != 0 && errno != EEXIST &&
843 errno != EHOSTUNREACH) {
845 snprintf(err_str, LNET_MAX_STR_LEN,
846 "route operation failed: %s",
849 } else if (errno == EEXIST) {
851 * continue chugging along if one of the
852 * routes already exists
859 cYAML_build_error(rc, seq_no,
860 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
866 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
867 int sen, int seq_no, struct cYAML **err_rc)
870 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
873 hops = LNET_UNDEFINED_HOPS;
874 } else if (hops < 1 || hops > 255) {
875 snprintf(err_str, LNET_MAX_STR_LEN,
876 "\"invalid hop count %d, must be between 1 and 255\"",
878 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
884 } else if (prio < 0) {
885 snprintf(err_str, LNET_MAX_STR_LEN,
886 "\"invalid priority %d, must be greater than 0\"",
888 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
894 } else if (sen < 1) {
895 snprintf(err_str, LNET_MAX_STR_LEN,
896 "\"invalid health sensitivity %d, must be 1 or greater\"",
898 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
902 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
903 err_rc, LNETCTL_ADD_CMD);
906 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
911 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
912 struct cYAML **err_rc)
914 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
918 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
919 int seq_no, struct cYAML **show_rc,
920 struct cYAML **err_rc, bool backup)
922 struct lnet_ioctl_config_data data;
923 lnet_nid_t gateway_nid;
924 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
926 __u32 net = LNET_NET_ANY;
928 struct cYAML *root = NULL, *route = NULL, *item = NULL;
929 struct cYAML *first_seq = NULL;
930 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
934 net = libcfs_str2net(nw);
935 if (net == LNET_NET_ANY) {
938 "\"cannot parse net '%s'\"", nw);
939 rc = LUSTRE_CFG_RC_BAD_PARAM;
944 /* show all routes without filtering on net */
949 gateway_nid = libcfs_str2nid(gw);
950 if (gateway_nid == LNET_NID_ANY) {
953 "\"cannot parse gateway NID '%s'\"", gw);
954 rc = LUSTRE_CFG_RC_BAD_PARAM;
958 /* show all routes with out filtering on gateway */
959 gateway_nid = LNET_NID_ANY;
961 if ((hops < 1 && hops != -1) || hops > 255) {
964 "\"invalid hop count %d, must be between 0 and 256\"",
966 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
970 /* create struct cYAML root object */
971 root = cYAML_create_object(NULL, NULL);
975 route = cYAML_create_seq(root, "route");
983 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
986 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
992 /* filter on provided data */
993 if (net != LNET_NET_ANY &&
997 if (gateway_nid != LNET_NID_ANY &&
998 gateway_nid != data.cfg_nid)
1002 hops != data.cfg_config_u.cfg_route.rtr_hop)
1006 prio != data.cfg_config_u.cfg_route.rtr_priority)
1009 /* default rc to -1 incase we hit the goto */
1013 item = cYAML_create_seq_item(route);
1017 if (first_seq == NULL)
1020 if (cYAML_create_string(item, "net",
1021 libcfs_net2str(data.cfg_net)) == NULL)
1024 if (cYAML_create_string(item, "gateway",
1025 libcfs_nid2str(data.cfg_nid)) == NULL)
1029 if (cYAML_create_number(item, "hop",
1030 (int) data.cfg_config_u.
1031 cfg_route.rtr_hop) ==
1035 if (cYAML_create_number(item, "priority",
1037 cfg_route.rtr_priority) == NULL)
1040 if (cYAML_create_number(item, "health_sensitivity",
1042 cfg_route.rtr_sensitivity) == NULL)
1045 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1047 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1051 cYAML_create_string(item, "state",
1053 "up" : "down") == NULL)
1057 cYAML_create_string(item, "type",
1059 "multi-hop" : "single-hop") == NULL)
1064 /* print output iff show_rc is not provided */
1065 if (show_rc == NULL)
1066 cYAML_print_tree(root);
1068 if (l_errno != ENOENT) {
1071 "\"cannot get routes: %s\"",
1076 rc = LUSTRE_CFG_RC_NO_ERR;
1078 snprintf(err_str, sizeof(err_str), "\"success\"");
1080 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1081 cYAML_free_tree(root);
1082 } else if (show_rc != NULL && *show_rc != NULL) {
1083 struct cYAML *show_node;
1084 /* find the route node, if one doesn't exist then
1085 * insert one. Otherwise add to the one there
1087 show_node = cYAML_get_object_item(*show_rc, "route");
1088 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1089 cYAML_insert_child(show_node, first_seq);
1092 } else if (show_node == NULL) {
1093 cYAML_insert_sibling((*show_rc)->cy_child,
1097 cYAML_free_tree(root);
1103 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1108 static int socket_intf_query(int request, char *intf,
1114 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1115 return LUSTRE_CFG_RC_BAD_PARAM;
1117 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1119 return LUSTRE_CFG_RC_BAD_PARAM;
1121 strcpy(ifr->ifr_name, intf);
1122 rc = ioctl(sockfd, request, ifr);
1124 rc = LUSTRE_CFG_RC_BAD_PARAM;
1131 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1136 memset(&ifr, 0, sizeof(ifr));
1137 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1139 return LUSTRE_CFG_RC_BAD_PARAM;
1141 if ((ifr.ifr_flags & IFF_UP) == 0)
1142 return LUSTRE_CFG_RC_BAD_PARAM;
1144 memset(&ifr, 0, sizeof(ifr));
1145 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1147 return LUSTRE_CFG_RC_BAD_PARAM;
1149 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1150 *ip = bswap_32(*ip);
1152 return LUSTRE_CFG_RC_NO_ERR;
1155 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1158 unsigned int nic_index;
1160 char *nic_addr_path;
1165 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1167 return LUSTRE_CFG_RC_NO_MATCH;
1169 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1170 nic_addr_path = malloc(size);
1172 return LUSTRE_CFG_RC_OUT_OF_MEM;
1173 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1175 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1176 free(nic_addr_path);
1178 return LUSTRE_CFG_RC_NO_MATCH;
1180 addr = strtol(val, NULL, 16);
1181 if (addr == LONG_MIN || addr == LONG_MAX)
1182 return LUSTRE_CFG_RC_NO_MATCH;
1186 return LUSTRE_CFG_RC_NO_ERR;
1190 * for each interface in the array of interfaces find the IP address of
1191 * that interface, create its nid and add it to an array of NIDs.
1192 * Stop if any of the interfaces is down
1194 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1195 lnet_nid_t **nids, __u32 *nnids,
1196 char *err_str, size_t str_len)
1198 int i = 0, count = 0, rc;
1199 struct lnet_dlc_intf_descr *intf;
1200 char val[LNET_MAX_STR_LEN];
1208 if (nw == NULL || nids == NULL) {
1209 snprintf(err_str, str_len,
1210 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1211 return LUSTRE_CFG_RC_BAD_PARAM;
1214 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1217 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1221 *nids = calloc(count, sizeof(lnet_nid_t));
1222 if (*nids == NULL) {
1223 snprintf(err_str, str_len,
1224 "\"out of memory\"");
1225 return LUSTRE_CFG_RC_OUT_OF_MEM;
1228 * special case the GNI interface since it doesn't have an IP
1229 * address. The assumption is that there can only be one GNI
1230 * interface in the system. No interface name is provided.
1232 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1233 rc = read_sysfs_file(gni_nid_path, "nid", val,
1236 snprintf(err_str, str_len,
1237 "\"cannot read gni nid\"");
1240 gni_num = atoi(val);
1242 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1245 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1246 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1247 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1248 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1249 snprintf(err_str, str_len,
1250 "\"couldn't query kfi intf %s\"",
1252 err_str[str_len - 1] = '\0';
1256 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1262 /* look at the other interfaces */
1263 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1264 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1265 /* handle LNDs with numeric interface name */
1266 num = strtoul(intf->intf_name, &endp, 0);
1267 if (endp == intf->intf_name || *endp != '\0') {
1268 rc = LUSTRE_CFG_RC_BAD_PARAM;
1269 snprintf(err_str, str_len,
1270 "\"couldn't query intf %s\"",
1274 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1277 /* handle LNDs with ip interface name */
1278 rc = lustre_lnet_queryip(intf, &ip);
1279 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1280 snprintf(err_str, str_len,
1281 "\"couldn't query intf %s\"",
1285 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1302 * called repeatedly until a match or no more ip range
1304 * ip_range expression
1305 * interface list with all the interface names.
1306 * all the interfaces in the system.
1308 * try to match the ip_range expr to one of the interfaces' IPs in
1309 * the system. If we hit a patch for an interface. Check if that
1310 * interface name is in the list.
1312 * If there are more than one interface in the list, then make sure
1313 * that the IPs for all of these interfaces match the ip ranges
1316 * for each interface in intf_list
1317 * look up the intf name in ifa
1318 * if not there then no match
1319 * check ip obtained from ifa against a match to any of the
1321 * If no match, then fail
1323 * The result is that all the interfaces have to match.
1325 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1326 struct list_head *intf_list,
1327 struct list_head *ip_ranges)
1331 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1332 struct ifaddrs *ifaddr = ifa;
1333 struct lustre_lnet_ip_range_descr *ip_range;
1337 * if there are no explicit interfaces, and no ip ranges, then
1338 * configure the first tcp interface we encounter.
1340 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1341 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1342 if (ifaddr->ifa_addr == NULL)
1345 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1348 family = ifaddr->ifa_addr->sa_family;
1349 if (family == AF_INET &&
1350 strcmp(ifaddr->ifa_name, "lo") != 0) {
1351 rc = lustre_lnet_add_intf_descr
1352 (intf_list, ifaddr->ifa_name,
1353 strlen(ifaddr->ifa_name));
1355 if (rc != LUSTRE_CFG_RC_NO_ERR)
1358 return LUSTRE_CFG_RC_MATCH;
1361 return LUSTRE_CFG_RC_NO_MATCH;
1365 * First interface which matches an IP pattern will be used
1367 if (list_empty(intf_list)) {
1369 * no interfaces provided in the rule, but an ip range is
1370 * provided, so try and match an interface to the ip
1373 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1374 if (ifaddr->ifa_addr == NULL)
1377 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1380 family = ifaddr->ifa_addr->sa_family;
1381 if (family == AF_INET) {
1382 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1385 list_for_each_entry(ip_range, ip_ranges,
1387 rc = cfs_ip_addr_match(bswap_32(ip),
1388 &ip_range->ipr_expr);
1392 rc = lustre_lnet_add_intf_descr
1393 (intf_list, ifaddr->ifa_name,
1394 strlen(ifaddr->ifa_name));
1396 if (rc != LUSTRE_CFG_RC_NO_ERR)
1402 if (!list_empty(intf_list))
1403 return LUSTRE_CFG_RC_MATCH;
1405 return LUSTRE_CFG_RC_NO_MATCH;
1409 * If an interface is explicitly specified the ip-range might or
1410 * might not be specified. if specified the interface needs to match the
1411 * ip-range. If no ip-range then the interfaces are
1412 * automatically matched if they are all up.
1413 * If > 1 interfaces all the interfaces must match for the NI to
1416 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1417 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1418 if (ifaddr->ifa_addr == NULL)
1421 family = ifaddr->ifa_addr->sa_family;
1422 if (family == AF_INET &&
1423 strcmp(intf_descr->intf_name,
1424 ifaddr->ifa_name) == 0)
1428 if (ifaddr == NULL) {
1429 list_del(&intf_descr->intf_on_network);
1430 free_intf_descr(intf_descr);
1434 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1435 list_del(&intf_descr->intf_on_network);
1436 free_intf_descr(intf_descr);
1440 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1443 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1444 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1450 /* no match for this interface */
1451 list_del(&intf_descr->intf_on_network);
1452 free_intf_descr(intf_descr);
1456 return LUSTRE_CFG_RC_MATCH;
1459 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1460 lnet_nid_t **nids, __u32 *nnids,
1461 char *err_str, size_t str_len)
1463 struct ifaddrs *ifa;
1464 int rc = LUSTRE_CFG_RC_NO_ERR;
1466 rc = getifaddrs(&ifa);
1468 snprintf(err_str, str_len,
1469 "\"failed to get interface addresses: %d\"", -errno);
1473 rc = lustre_lnet_match_ip_to_intf(ifa,
1474 &ip2nets->ip2nets_net.nw_intflist,
1475 &ip2nets->ip2nets_ip_ranges);
1476 if (rc != LUSTRE_CFG_RC_MATCH) {
1477 snprintf(err_str, str_len,
1478 "\"couldn't match ip to existing interfaces\"");
1483 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1485 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1496 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1497 struct lnet_ioctl_config_lnd_tunables *tunables,
1498 struct cfs_expr_list *global_cpts,
1499 lnet_nid_t *nids, char *err_str)
1502 struct lnet_ioctl_config_ni *conf;
1503 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1504 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1507 struct lnet_dlc_intf_descr *intf_descr;
1509 struct cfs_expr_list *cpt_expr;
1511 list_for_each_entry(intf_descr, intf_list,
1513 if (tunables != NULL)
1514 len = sizeof(struct lnet_ioctl_config_ni) +
1515 sizeof(struct lnet_ioctl_config_lnd_tunables);
1517 len = sizeof(struct lnet_ioctl_config_ni);
1519 data = calloc(1, len);
1521 return LUSTRE_CFG_RC_OUT_OF_MEM;
1522 conf = (struct lnet_ioctl_config_ni*) data;
1523 if (tunables != NULL)
1524 tun = (struct lnet_ioctl_config_lnd_tunables*)
1527 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1528 conf->lic_cfg_hdr.ioc_len = len;
1529 conf->lic_nid = nids[i];
1530 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1533 if (intf_descr->cpt_expr != NULL)
1534 cpt_expr = intf_descr->cpt_expr;
1535 else if (global_cpts != NULL)
1536 cpt_expr = global_cpts;
1540 if (cpt_expr != NULL) {
1541 count = cfs_expr_list_values(cpt_expr,
1542 LNET_MAX_SHOW_NUM_CPT,
1545 memcpy(conf->lic_cpts, cpt_array,
1546 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1555 conf->lic_ncpts = count;
1557 if (tunables != NULL)
1558 memcpy(tun, tunables, sizeof(*tunables));
1560 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1565 "\"cannot add network: %s\"", strerror(errno));
1573 return LUSTRE_CFG_RC_NO_ERR;
1577 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1578 struct lnet_ioctl_config_lnd_tunables *tunables,
1579 struct cfs_expr_list *global_cpts,
1580 int seq_no, struct cYAML **err_rc)
1582 lnet_nid_t *nids = NULL;
1585 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1590 "\"incomplete ip2nets information\"");
1591 rc = LUSTRE_CFG_RC_BAD_PARAM;
1596 * call below function to resolve the rules into a list of nids.
1597 * The memory is allocated in that function then freed here when
1598 * it's no longer needed.
1600 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1602 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1605 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1606 snprintf(err_str, sizeof(err_str),
1607 "\"no interfaces match ip2nets rules\"");
1611 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1612 tunables, global_cpts, nids,
1619 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1623 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1624 struct cfs_expr_list *global_cpts,
1626 struct lnet_ioctl_config_lnd_tunables *tunables,
1627 int seq_no, struct cYAML **err_rc)
1630 struct lnet_ioctl_config_ni *conf;
1631 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1632 char buf[LNET_MAX_STR_LEN];
1633 int rc = LUSTRE_CFG_RC_NO_ERR;
1634 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1635 lnet_nid_t *nids = NULL;
1639 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1642 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1643 (list_empty(&nw_descr->nw_intflist) &&
1644 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1647 "\"missing mandatory parameters in NI config: '%s'\"",
1648 (nw_descr == NULL) ? "network , interface" :
1649 (nw_descr->nw_id == 0) ? "network" : "interface");
1650 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1654 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1657 "\"ip2net string too long %d\"",
1658 (int)strlen(ip2net));
1659 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1663 if (ip2net != NULL) {
1664 if (tunables != NULL)
1665 len = sizeof(struct lnet_ioctl_config_ni) +
1666 sizeof(struct lnet_ioctl_config_lnd_tunables);
1668 len = sizeof(struct lnet_ioctl_config_ni);
1669 data = calloc(1, len);
1671 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1674 conf = (struct lnet_ioctl_config_ni*) data;
1675 if (tunables != NULL)
1676 tun = (struct lnet_ioctl_config_lnd_tunables*)
1677 (data + sizeof(*conf));
1679 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1680 conf->lic_cfg_hdr.ioc_len = len;
1681 strncpy(conf->lic_legacy_ip2nets, ip2net,
1684 if (global_cpts != NULL) {
1685 count = cfs_expr_list_values(global_cpts,
1686 LNET_MAX_SHOW_NUM_CPT,
1689 memcpy(conf->lic_cpts, cpt_array,
1690 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1699 conf->lic_ncpts = count;
1701 if (tunables != NULL)
1702 memcpy(tun, tunables, sizeof(*tunables));
1704 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1709 "\"cannot add network: %s\"", strerror(errno));
1716 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1717 rc = LUSTRE_CFG_RC_NO_ERR;
1721 if (nw_descr->nw_id == LNET_NET_ANY) {
1724 "\"cannot parse net '%s'\"",
1725 libcfs_net2str(nw_descr->nw_id));
1726 rc = LUSTRE_CFG_RC_BAD_PARAM;
1731 * special case the GNI since no interface name is expected
1733 if (list_empty(&nw_descr->nw_intflist) &&
1734 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1737 "\"no interface name provided\"");
1738 rc = LUSTRE_CFG_RC_BAD_PARAM;
1742 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1743 err_str, sizeof(err_str));
1745 rc = LUSTRE_CFG_RC_BAD_PARAM;
1749 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1750 tunables, global_cpts, nids,
1754 if (nw_descr != NULL) {
1755 list_for_each_entry_safe(intf_descr, tmp,
1756 &nw_descr->nw_intflist,
1758 list_del(&intf_descr->intf_on_network);
1759 free_intf_descr(intf_descr);
1763 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1774 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1775 int seq_no, struct cYAML **err_rc)
1777 struct lnet_ioctl_config_ni data;
1778 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1779 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1780 lnet_nid_t *nids = NULL;
1782 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1784 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1787 "\"missing mandatory parameter in deleting NI: '%s'\"",
1788 (nw_descr == NULL) ? "network , interface" :
1789 (nw_descr->nw_id == 0) ? "network" : "interface");
1790 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1794 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1795 return LUSTRE_CFG_RC_NO_ERR;
1797 if (nw_descr->nw_id == LNET_NET_ANY) {
1800 "\"cannot parse net '%s'\"",
1801 libcfs_net2str(nw_descr->nw_id));
1802 rc = LUSTRE_CFG_RC_BAD_PARAM;
1806 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1807 err_str, sizeof(err_str));
1809 rc = LUSTRE_CFG_RC_BAD_PARAM;
1814 * no interfaces just the nw_id is specified
1817 nids = calloc(1, sizeof(*nids));
1819 snprintf(err_str, sizeof(err_str),
1820 "\"out of memory\"");
1821 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1824 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1828 for (i = 0; i < nnids; i++) {
1829 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1830 data.lic_nid = nids[i];
1832 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1837 "\"cannot del network: %s\"", strerror(errno));
1841 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1843 list_del(&intf_descr->intf_on_network);
1844 free_intf_descr(intf_descr);
1848 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1857 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1858 enum lnet_health_type type, char *name,
1859 int seq_no, struct cYAML **err_rc)
1861 struct lnet_ioctl_reset_health_cfg data;
1862 int rc = LUSTRE_CFG_RC_NO_ERR;
1863 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1865 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1866 data.rh_type = type;
1868 data.rh_value = value;
1871 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1875 sizeof(err_str), "Can not configure health value: %s",
1879 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1886 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1887 char *name, int seq_no,
1888 struct cYAML **err_rc)
1890 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1891 int rc = LUSTRE_CFG_RC_NO_ERR;
1892 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1894 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1895 data.rcpp_all = all;
1896 data.rcpp_value = value;
1897 data.rcpp_nid = nid;
1899 if (value < 0 || value > 127) {
1900 rc = LUSTRE_CFG_RC_BAD_PARAM;
1901 snprintf(err_str, sizeof(err_str),
1902 "\"Valid values are: 0-127\"");
1905 rc = l_ioctl(LNET_DEV_ID,
1906 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1911 "Can not configure conns_per_peer value: %s",
1915 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1920 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1921 struct cYAML **err_rc)
1925 nid = libcfs_str2nid(ni_nid);
1928 return lustre_lnet_config_healthv(value, all, nid,
1929 LNET_HEALTH_TYPE_LOCAL_NI,
1930 "ni healthv", seq_no, err_rc);
1933 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1934 int seq_no, struct cYAML **err_rc)
1938 nid = libcfs_str2nid(lpni_nid);
1941 return lustre_lnet_config_healthv(value, all, nid,
1942 LNET_HEALTH_TYPE_PEER_NI,
1943 "peer_ni healthv", seq_no, err_rc);
1946 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1947 int seq_no, struct cYAML **err_rc)
1952 nid = libcfs_str2nid(ni_nid);
1955 return lustre_lnet_config_conns_per_peer(value, all, nid,
1956 "ni conns_per_peer",
1961 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1962 struct lnet_ioctl_comm_count *counts)
1964 if (cYAML_create_number(yaml, "put",
1965 counts->ico_put_count)
1968 if (cYAML_create_number(yaml, "get",
1969 counts->ico_get_count)
1972 if (cYAML_create_number(yaml, "reply",
1973 counts->ico_reply_count)
1976 if (cYAML_create_number(yaml, "ack",
1977 counts->ico_ack_count)
1980 if (cYAML_create_number(yaml, "hello",
1981 counts->ico_hello_count)
1988 static struct lnet_ioctl_comm_count *
1989 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1992 return &msg_stats->im_send_stats;
1994 return &msg_stats->im_recv_stats;
1996 return &msg_stats->im_drop_stats;
2002 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2003 struct cYAML *net_node)
2005 char tmp[LNET_MAX_STR_LEN];
2006 struct cYAML *udsp_net;
2007 bool created = false;
2011 /* add the UDSP info */
2012 udsp_net = cYAML_create_object(net_node, "udsp info");
2014 return LUSTRE_CFG_RC_OUT_OF_MEM;
2016 if (!cYAML_create_number(udsp_net, "net priority",
2017 (int) udsp_info->cud_net_priority))
2018 return LUSTRE_CFG_RC_OUT_OF_MEM;
2020 if (!cYAML_create_number(udsp_net, "nid priority",
2021 (int)udsp_info->cud_nid_priority))
2022 return LUSTRE_CFG_RC_OUT_OF_MEM;
2026 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2027 memset(tmp, 0, LNET_MAX_STR_LEN);
2028 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2031 pref = cYAML_create_object(udsp_net,
2032 "Preferred gateway NIDs");
2034 return LUSTRE_CFG_RC_OUT_OF_MEM;
2037 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2038 if (!cYAML_create_string(pref, tmp,
2039 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2040 return LUSTRE_CFG_RC_OUT_OF_MEM;
2043 return LUSTRE_CFG_RC_NO_ERR;
2047 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2048 struct cYAML *nid_node)
2050 char tmp[LNET_MAX_STR_LEN];
2051 struct cYAML *udsp_nid;
2052 bool created = false;
2056 /* add the UDSP info */
2057 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2059 return LUSTRE_CFG_RC_OUT_OF_MEM;
2061 if (!cYAML_create_number(udsp_nid, "net priority",
2062 (int) udsp_info->cud_net_priority))
2063 return LUSTRE_CFG_RC_OUT_OF_MEM;
2065 if (!cYAML_create_number(udsp_nid, "nid priority",
2066 (int) udsp_info->cud_nid_priority))
2067 return LUSTRE_CFG_RC_OUT_OF_MEM;
2070 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2071 memset(tmp, 0, LNET_MAX_STR_LEN);
2072 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2075 pref = cYAML_create_object(udsp_nid,
2076 "Preferred gateway NIDs");
2078 return LUSTRE_CFG_RC_OUT_OF_MEM;
2081 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2082 if (!cYAML_create_string(pref, tmp,
2083 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2084 return LUSTRE_CFG_RC_OUT_OF_MEM;
2089 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2090 memset(tmp, 0, LNET_MAX_STR_LEN);
2091 if (udsp_info->cud_pref_nid[i] == 0)
2094 pref = cYAML_create_object(udsp_nid,
2095 "Preferred source NIDs");
2097 return LUSTRE_CFG_RC_OUT_OF_MEM;
2100 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2101 if (!cYAML_create_string(pref, tmp,
2102 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2103 return LUSTRE_CFG_RC_OUT_OF_MEM;
2106 return LUSTRE_CFG_RC_NO_ERR;
2109 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2110 struct cYAML **show_rc, struct cYAML **err_rc,
2114 struct lnet_ioctl_config_ni *ni_data;
2115 struct lnet_ioctl_config_lnd_tunables *lnd;
2116 struct lnet_ioctl_element_stats *stats;
2117 struct lnet_ioctl_element_msg_stats msg_stats;
2118 struct lnet_ioctl_local_ni_hstats hstats;
2119 struct lnet_ioctl_construct_udsp_info udsp_info;
2120 __u32 net = LNET_NET_ANY;
2121 __u32 prev_net = LNET_NET_ANY;
2122 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2124 struct cYAML *root = NULL, *tunables = NULL,
2125 *net_node = NULL, *interfaces = NULL,
2126 *item = NULL, *first_seq = NULL,
2127 *tmp = NULL, *statistics = NULL,
2129 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2130 char str_buf[str_buf_len];
2132 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2133 bool exist = false, new_net = true;
2135 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2137 buf = calloc(1, buf_size);
2141 ni_data = (struct lnet_ioctl_config_ni *)buf;
2144 net = libcfs_str2net(nw);
2145 if (net == LNET_NET_ANY) {
2148 "\"cannot parse net '%s'\"", nw);
2149 rc = LUSTRE_CFG_RC_BAD_PARAM;
2154 root = cYAML_create_object(NULL, NULL);
2158 net_node = cYAML_create_seq(root, "net");
2159 if (net_node == NULL)
2165 memset(buf, 0, buf_size);
2167 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2169 * set the ioc_len to the proper value since INIT assumes
2172 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2173 ni_data->lic_idx = i;
2175 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2181 rc_net = LNET_NIDNET(ni_data->lic_nid);
2183 /* filter on provided data */
2184 if (net != LNET_NET_ANY &&
2188 /* if we're backing up don't store lo */
2189 if (backup && LNET_NETTYP(rc_net) == LOLND)
2192 /* default rc to -1 in case we hit the goto */
2196 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2197 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2198 (ni_data->lic_bulk + sizeof(*stats));
2200 if (rc_net != prev_net) {
2207 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2211 if (first_seq == NULL)
2214 tmp = cYAML_create_seq(net_node, "local NI(s)");
2220 /* create the tree to be printed. */
2221 item = cYAML_create_seq_item(tmp);
2226 cYAML_create_string(item, "nid",
2227 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2231 cYAML_create_string(item,
2233 (ni_data->lic_status ==
2234 LNET_NI_STATUS_UP) ?
2235 "up" : "down") == NULL)
2238 /* don't add interfaces unless there is at least one
2240 if (strlen(ni_data->lic_ni_intf) > 0) {
2241 interfaces = cYAML_create_object(item, "interfaces");
2242 if (interfaces == NULL)
2245 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2246 if (cYAML_create_string(interfaces, str_buf,
2247 ni_data->lic_ni_intf) == NULL)
2256 goto continue_without_msg_stats;
2258 statistics = cYAML_create_object(item, "statistics");
2259 if (statistics == NULL)
2262 if (cYAML_create_number(statistics, "send_count",
2263 stats->iel_send_count)
2267 if (cYAML_create_number(statistics, "recv_count",
2268 stats->iel_recv_count)
2272 if (cYAML_create_number(statistics, "drop_count",
2273 stats->iel_drop_count)
2278 goto continue_without_udsp_info;
2280 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2281 udsp_info.cud_nid = ni_data->lic_nid;
2282 udsp_info.cud_peer = false;
2283 rc = l_ioctl(LNET_DEV_ID,
2284 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2288 goto continue_without_udsp_info;
2291 rc = create_local_udsp_info(&udsp_info, item);
2297 continue_without_udsp_info:
2299 goto continue_without_msg_stats;
2301 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2302 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2303 msg_stats.im_idx = i;
2305 rc = l_ioctl(LNET_DEV_ID,
2306 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2310 goto continue_without_msg_stats;
2313 for (k = 0; k < 3; k++) {
2314 struct lnet_ioctl_comm_count *counts;
2315 struct cYAML *msg_statistics = NULL;
2317 msg_statistics = cYAML_create_object(item,
2318 (char *)gmsg_stat_names[k]);
2319 if (msg_statistics == NULL)
2322 counts = get_counts(&msg_stats, k);
2326 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2331 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2332 hstats.hlni_nid = ni_data->lic_nid;
2333 /* grab health stats */
2334 rc = l_ioctl(LNET_DEV_ID,
2335 IOC_LIBCFS_GET_LOCAL_HSTATS,
2339 goto continue_without_msg_stats;
2341 yhstats = cYAML_create_object(item, "health stats");
2344 if (cYAML_create_number(yhstats, "fatal_error",
2345 hstats.hlni_fatal_error)
2348 if (cYAML_create_number(yhstats, "health value",
2349 hstats.hlni_health_value)
2352 if (cYAML_create_number(yhstats, "interrupts",
2353 hstats.hlni_local_interrupt)
2356 if (cYAML_create_number(yhstats, "dropped",
2357 hstats.hlni_local_dropped)
2360 if (cYAML_create_number(yhstats, "aborted",
2361 hstats.hlni_local_aborted)
2364 if (cYAML_create_number(yhstats, "no route",
2365 hstats.hlni_local_no_route)
2368 if (cYAML_create_number(yhstats, "timeouts",
2369 hstats.hlni_local_timeout)
2372 if (cYAML_create_number(yhstats, "error",
2373 hstats.hlni_local_error)
2376 if (cYAML_create_number(yhstats, "ping_count",
2377 hstats.hlni_ping_count)
2380 if (cYAML_create_number(yhstats, "next_ping",
2381 hstats.hlni_next_ping)
2385 continue_without_msg_stats:
2386 tunables = cYAML_create_object(item, "tunables");
2390 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2391 if (rc != LUSTRE_CFG_RC_NO_ERR)
2394 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2395 tunables = cYAML_create_object(item,
2397 if (tunables == NULL)
2401 rc = lustre_ni_show_tunables(tunables,
2402 LNET_NETTYP(rc_net),
2404 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2405 rc != LUSTRE_CFG_RC_NO_MATCH)
2409 cYAML_create_number(item, "dev cpt",
2410 ni_data->lic_dev_cpt) == NULL)
2413 /* out put the CPTs in the format: "[x,x,x,...]" */
2415 limit = str_buf + str_buf_len - 3;
2416 pos += scnprintf(pos, limit - pos, "\"[");
2417 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2418 j < ni_data->lic_ncpts &&
2420 pos += scnprintf(pos, limit - pos,
2421 "%d", ni_data->lic_cpts[j]);
2422 if ((j + 1) < ni_data->lic_ncpts)
2423 pos += scnprintf(pos, limit - pos, ",");
2425 snprintf(pos, 3, "]\"");
2427 if (ni_data->lic_ncpts >= 1 &&
2428 cYAML_create_string(item, "CPT",
2434 /* Print out the net information only if show_rc is not provided */
2435 if (show_rc == NULL)
2436 cYAML_print_tree(root);
2438 if (l_errno != ENOENT) {
2441 "\"cannot get networks: %s\"",
2446 rc = LUSTRE_CFG_RC_NO_ERR;
2448 snprintf(err_str, sizeof(err_str), "\"success\"");
2450 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2451 cYAML_free_tree(root);
2452 } else if (show_rc != NULL && *show_rc != NULL) {
2453 struct cYAML *show_node;
2454 /* find the net node, if one doesn't exist
2455 * then insert one. Otherwise add to the one there
2457 show_node = cYAML_get_object_item(*show_rc, "net");
2458 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2459 cYAML_insert_child(show_node, first_seq);
2462 } else if (show_node == NULL) {
2463 cYAML_insert_sibling((*show_rc)->cy_child,
2467 cYAML_free_tree(root);
2473 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2478 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2480 struct lnet_ioctl_config_data data;
2481 int rc = LUSTRE_CFG_RC_NO_ERR;
2482 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2484 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2485 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2487 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2492 "\"cannot %s routing %s\"",
2493 (enable) ? "enable" : "disable", strerror(errno));
2498 cYAML_build_error(rc, seq_no,
2499 (enable) ? ADD_CMD : DEL_CMD,
2500 "routing", err_str, err_rc);
2505 int ioctl_set_value(__u32 val, int ioc, char *name,
2506 int seq_no, struct cYAML **err_rc)
2508 struct lnet_ioctl_set_value data;
2509 int rc = LUSTRE_CFG_RC_NO_ERR;
2510 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2512 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2513 data.sv_value = val;
2515 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2520 "\"cannot configure %s to %d: %s\"", name,
2521 val, strerror(errno));
2524 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2529 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2531 int rc = LUSTRE_CFG_RC_NO_ERR;
2532 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2533 char val[LNET_MAX_STR_LEN];
2535 snprintf(val, sizeof(val), "%d", intrv);
2537 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2538 1, strlen(val) + 1);
2540 snprintf(err_str, sizeof(err_str),
2541 "\"cannot configure recovery interval: %s\"",
2544 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2549 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2551 int rc = LUSTRE_CFG_RC_NO_ERR;
2552 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2553 char val[LNET_MAX_STR_LEN];
2555 snprintf(val, sizeof(val), "%d", sen);
2557 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2558 1, strlen(val) + 1);
2560 snprintf(err_str, sizeof(err_str),
2561 "\"cannot configure router health sensitivity: %s\"",
2564 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2569 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2571 int rc = LUSTRE_CFG_RC_NO_ERR;
2572 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2573 char val[LNET_MAX_STR_LEN];
2575 snprintf(val, sizeof(val), "%d", sen);
2577 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2578 1, strlen(val) + 1);
2580 snprintf(err_str, sizeof(err_str),
2581 "\"cannot configure health sensitivity: %s\"",
2584 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2589 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2591 int rc = LUSTRE_CFG_RC_NO_ERR;
2592 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2593 char val[LNET_MAX_STR_LEN];
2595 snprintf(val, sizeof(val), "%d", timeout);
2597 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2598 1, strlen(val) + 1);
2600 snprintf(err_str, sizeof(err_str),
2601 "\"cannot configure transaction timeout: %s\"",
2604 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2609 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2611 int rc = LUSTRE_CFG_RC_NO_ERR;
2612 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2613 char val[LNET_MAX_STR_LEN];
2615 snprintf(val, sizeof(val), "%d", count);
2617 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2618 1, strlen(val) + 1);
2620 snprintf(err_str, sizeof(err_str),
2621 "\"cannot configure retry count: %s\"",
2624 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2629 int lustre_lnet_config_response_tracking(int val, int seq_no,
2630 struct cYAML **err_rc)
2632 int rc = LUSTRE_CFG_RC_NO_ERR;
2633 char err_str[LNET_MAX_STR_LEN];
2634 char val_str[LNET_MAX_STR_LEN];
2636 if (val < 0 || val > 3) {
2637 rc = LUSTRE_CFG_RC_BAD_PARAM;
2638 snprintf(err_str, sizeof(err_str),
2639 "\"Valid values are: 0, 1, 2, or 3\"");
2641 snprintf(err_str, sizeof(err_str), "\"success\"");
2643 snprintf(val_str, sizeof(val_str), "%d", val);
2645 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2646 val_str, 1, strlen(val_str) + 1);
2648 snprintf(err_str, sizeof(err_str),
2649 "\"cannot configure response tracking: %s\"",
2653 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2659 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2660 struct cYAML **err_rc)
2662 int rc = LUSTRE_CFG_RC_NO_ERR;
2663 char err_str[LNET_MAX_STR_LEN];
2664 char val_str[LNET_MAX_STR_LEN];
2667 rc = LUSTRE_CFG_RC_BAD_PARAM;
2668 snprintf(err_str, sizeof(err_str),
2669 "\"Must be greater than or equal to 0\"");
2671 snprintf(err_str, sizeof(err_str), "\"success\"");
2673 snprintf(val_str, sizeof(val_str), "%d", val);
2675 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2676 val_str, 1, strlen(val_str) + 1);
2678 snprintf(err_str, sizeof(err_str),
2679 "\"cannot configure recovery limit: %s\"",
2683 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2689 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2691 int rc = LUSTRE_CFG_RC_NO_ERR;
2692 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2693 char val[LNET_MAX_STR_LEN];
2695 snprintf(val, sizeof(val), "%d", max);
2697 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2698 1, strlen(val) + 1);
2700 snprintf(err_str, sizeof(err_str),
2701 "\"cannot configure max interfaces: %s\"",
2704 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2709 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2711 int rc = LUSTRE_CFG_RC_NO_ERR;
2712 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2713 char val[LNET_MAX_STR_LEN];
2715 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2717 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2718 1, strlen(val) + 1);
2720 snprintf(err_str, sizeof(err_str),
2721 "\"cannot configure discovery: %s\"",
2724 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2730 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2731 struct cYAML **err_rc)
2733 int rc = LUSTRE_CFG_RC_NO_ERR;
2734 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2735 char val[LNET_MAX_STR_LEN];
2737 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2739 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2740 1, strlen(val) + 1);
2742 snprintf(err_str, sizeof(err_str),
2743 "\"cannot configure drop asym route: %s\"",
2746 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2753 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2755 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2756 "numa_range", seq_no, err_rc);
2759 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2760 struct cYAML **err_rc)
2762 struct lnet_ioctl_config_data data;
2763 int rc = LUSTRE_CFG_RC_NO_ERR;
2764 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2766 /* -1 indicates to ignore changes to this field */
2767 if (tiny < -1 || small < -1 || large < -1) {
2770 "\"tiny, small and large must be >= 0\"");
2771 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2775 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2776 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2777 data.cfg_config_u.cfg_buffers.buf_small = small;
2778 data.cfg_config_u.cfg_buffers.buf_large = large;
2780 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2785 "\"cannot configure buffers: %s\"", strerror(errno));
2790 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2795 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2796 struct cYAML **err_rc)
2798 int rc = LUSTRE_CFG_RC_NO_ERR;
2799 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2800 char interval_str[LNET_MAX_STR_LEN];
2802 if (interval <= 0) {
2803 rc = LUSTRE_CFG_RC_BAD_PARAM;
2804 snprintf(err_str, sizeof(err_str),
2805 "\"must be strictly positive\"");
2808 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2810 rc = write_sysfs_file(modparam_path,
2811 "lnet_max_recovery_ping_interval",
2813 strlen(interval_str) + 1);
2815 snprintf(err_str, sizeof(err_str),
2816 "\"cannot configure maximum recovery ping interval: %s\"",
2820 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2827 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2828 struct cYAML **err_rc, bool backup)
2830 struct lnet_ioctl_config_data *data;
2831 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2832 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2835 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2836 int buf_count[LNET_NRBPOOLS] = {0};
2837 struct cYAML *root = NULL, *pools_node = NULL,
2838 *type_node = NULL, *item = NULL, *cpt = NULL,
2839 *first_seq = NULL, *buffers = NULL;
2841 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2842 char node_name[LNET_MAX_STR_LEN];
2845 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2849 data = (struct lnet_ioctl_config_data *)buf;
2851 root = cYAML_create_object(NULL, NULL);
2856 pools_node = cYAML_create_object(root, "routing");
2858 pools_node = cYAML_create_seq(root, "routing");
2859 if (pools_node == NULL)
2863 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2864 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2865 sizeof(struct lnet_ioctl_pool_cfg);
2866 data->cfg_count = i;
2868 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2876 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2879 goto calculate_buffers;
2881 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2882 item = cYAML_create_seq_item(pools_node);
2886 if (first_seq == NULL)
2889 cpt = cYAML_create_object(item, node_name);
2894 /* create the tree and print */
2895 for (j = 0; j < LNET_NRBPOOLS; j++) {
2897 type_node = cYAML_create_object(cpt, pools[j]);
2898 if (type_node == NULL)
2902 cYAML_create_number(type_node, "npages",
2903 pool_cfg->pl_pools[j].pl_npages)
2907 cYAML_create_number(type_node, "nbuffers",
2908 pool_cfg->pl_pools[j].
2909 pl_nbuffers) == NULL)
2912 cYAML_create_number(type_node, "credits",
2913 pool_cfg->pl_pools[j].
2914 pl_credits) == NULL)
2917 cYAML_create_number(type_node, "mincredits",
2918 pool_cfg->pl_pools[j].
2919 pl_mincredits) == NULL)
2921 /* keep track of the total count for each of the
2922 * tiny, small and large buffers */
2923 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2927 if (pool_cfg != NULL) {
2929 if (cYAML_create_number(pools_node, "enable",
2930 pool_cfg->pl_routing) ==
2934 goto add_buffer_section;
2937 item = cYAML_create_seq_item(pools_node);
2941 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2947 /* create a buffers entry in the show. This is necessary so that
2948 * if the YAML output is used to configure a node, the buffer
2949 * configuration takes hold */
2950 buffers = cYAML_create_object(root, "buffers");
2951 if (buffers == NULL)
2954 for (i = 0; i < LNET_NRBPOOLS; i++) {
2955 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2959 if (show_rc == NULL)
2960 cYAML_print_tree(root);
2962 if (l_errno != ENOENT) {
2965 "\"cannot get routing information: %s\"",
2970 rc = LUSTRE_CFG_RC_NO_ERR;
2972 snprintf(err_str, sizeof(err_str), "\"success\"");
2973 rc = LUSTRE_CFG_RC_NO_ERR;
2977 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2978 cYAML_free_tree(root);
2979 } else if (show_rc != NULL && *show_rc != NULL) {
2980 struct cYAML *routing_node;
2981 /* there should exist only one routing block and one
2982 * buffers block. If there already exists a previous one
2983 * then don't add another */
2984 routing_node = cYAML_get_object_item(*show_rc, "routing");
2985 if (routing_node == NULL) {
2986 cYAML_insert_sibling((*show_rc)->cy_child,
2990 cYAML_free_tree(root);
2996 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3001 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3002 struct cYAML **show_rc, struct cYAML **err_rc,
3006 * TODO: This function is changing in a future patch to accommodate
3007 * PEER_LIST and proper filtering on any nid of the peer
3009 struct lnet_ioctl_peer_cfg peer_info;
3010 struct lnet_peer_ni_credit_info *lpni_cri;
3011 struct lnet_ioctl_element_stats *lpni_stats;
3012 struct lnet_ioctl_element_msg_stats *msg_stats;
3013 struct lnet_ioctl_peer_ni_hstats *hstats;
3014 struct lnet_ioctl_construct_udsp_info udsp_info;
3016 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3021 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3022 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3023 *msg_statistics = NULL, *statistics = NULL,
3025 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3026 struct lnet_process_id *list = NULL;
3031 /* create struct cYAML root object */
3032 root = cYAML_create_object(NULL, NULL);
3036 peer_root = cYAML_create_seq(root, "peer");
3037 if (peer_root == NULL)
3041 size = count * sizeof(struct lnet_process_id);
3042 list = malloc(size);
3048 list[0].nid = libcfs_str2nid(knid);
3052 memset(&peer_info, 0, sizeof(peer_info));
3053 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3054 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3055 peer_info.prcfg_size = size;
3056 peer_info.prcfg_bulk = list;
3059 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3061 count = peer_info.prcfg_count;
3065 if (l_errno != E2BIG) {
3068 "\"cannot get peer list: %s\"",
3074 size = peer_info.prcfg_size;
3075 list = malloc(size);
3084 data = malloc(size);
3090 for (i = 0; i < count; i++) {
3092 memset(&peer_info, 0, sizeof(peer_info));
3093 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3094 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3095 peer_info.prcfg_prim_nid = list[i].nid;
3096 peer_info.prcfg_size = size;
3097 peer_info.prcfg_bulk = data;
3100 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3105 if (l_errno != E2BIG) {
3108 "\"cannot get peer information: %s\"",
3114 size = peer_info.prcfg_size;
3115 data = malloc(size);
3123 peer = cYAML_create_seq_item(peer_root);
3127 if (first_seq == NULL)
3130 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3131 if (cYAML_create_string(peer, "primary nid",
3132 libcfs_nid2str(pnid))
3135 if (cYAML_create_string(peer, "Multi-Rail",
3136 peer_info.prcfg_mr ? "True" : "False")
3140 * print out the state of the peer only if details are
3145 cYAML_create_number(peer, "peer state",
3146 peer_info.prcfg_state)
3151 tmp = cYAML_create_seq(peer, "peer ni");
3156 for (j = 0; j < peer_info.prcfg_count; j++) {
3158 lpni_cri = (void*)nidp + sizeof(nidp);
3159 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3160 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3161 hstats = (void *)msg_stats + sizeof(*msg_stats);
3162 lpni_data = (void *)hstats + sizeof(*hstats);
3164 peer_ni = cYAML_create_seq_item(tmp);
3165 if (peer_ni == NULL)
3168 if (cYAML_create_string(peer_ni, "nid",
3169 libcfs_nid2str(*nidp))
3177 goto continue_without_udsp_info;
3179 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3180 udsp_info.cud_nid = *nidp;
3181 udsp_info.cud_peer = true;
3182 rc = l_ioctl(LNET_DEV_ID,
3183 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3187 goto continue_without_udsp_info;
3190 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3196 continue_without_udsp_info:
3197 if (cYAML_create_string(peer_ni, "state",
3198 lpni_cri->cr_aliveness)
3205 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3206 lpni_cri->cr_ni_peer_tx_credits)
3210 if (cYAML_create_number(peer_ni, "available_tx_credits",
3211 lpni_cri->cr_peer_tx_credits)
3215 if (cYAML_create_number(peer_ni, "min_tx_credits",
3216 lpni_cri->cr_peer_min_tx_credits)
3220 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3221 lpni_cri->cr_peer_tx_qnob)
3225 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3226 lpni_cri->cr_peer_rtr_credits)
3230 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3231 lpni_cri->cr_peer_min_rtr_credits)
3235 if (cYAML_create_number(peer_ni, "refcount",
3236 lpni_cri->cr_refcount) == NULL)
3239 statistics = cYAML_create_object(peer_ni, "statistics");
3240 if (statistics == NULL)
3243 if (cYAML_create_number(statistics, "send_count",
3244 lpni_stats->iel_send_count)
3248 if (cYAML_create_number(statistics, "recv_count",
3249 lpni_stats->iel_recv_count)
3253 if (cYAML_create_number(statistics, "drop_count",
3254 lpni_stats->iel_drop_count)
3261 for (k = 0; k < 3; k++) {
3262 struct lnet_ioctl_comm_count *counts;
3264 msg_statistics = cYAML_create_object(peer_ni,
3265 (char *) gmsg_stat_names[k]);
3266 if (msg_statistics == NULL)
3269 counts = get_counts(msg_stats, k);
3273 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3278 yhstats = cYAML_create_object(peer_ni, "health stats");
3281 if (cYAML_create_number(yhstats, "health value",
3282 hstats->hlpni_health_value)
3285 if (cYAML_create_number(yhstats, "dropped",
3286 hstats->hlpni_remote_dropped)
3289 if (cYAML_create_number(yhstats, "timeout",
3290 hstats->hlpni_remote_timeout)
3293 if (cYAML_create_number(yhstats, "error",
3294 hstats->hlpni_remote_error)
3297 if (cYAML_create_number(yhstats, "network timeout",
3298 hstats->hlpni_network_timeout)
3301 if (cYAML_create_number(yhstats, "ping_count",
3302 hstats->hlpni_ping_count)
3306 if (cYAML_create_number(yhstats, "next_ping",
3307 hstats->hlpni_next_ping)
3314 /* print output iff show_rc is not provided */
3315 if (show_rc == NULL)
3316 cYAML_print_tree(root);
3318 snprintf(err_str, sizeof(err_str), "\"success\"");
3319 rc = LUSTRE_CFG_RC_NO_ERR;
3324 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3325 cYAML_free_tree(root);
3326 } else if (show_rc != NULL && *show_rc != NULL) {
3327 struct cYAML *show_node;
3328 /* find the peer node, if one doesn't exist then
3329 * insert one. Otherwise add to the one there
3331 show_node = cYAML_get_object_item(*show_rc,
3333 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3334 cYAML_insert_child(show_node, first_seq);
3337 } else if (show_node == NULL) {
3338 cYAML_insert_sibling((*show_rc)->cy_child,
3342 cYAML_free_tree(root);
3348 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3354 int lustre_lnet_list_peer(int seq_no,
3355 struct cYAML **show_rc, struct cYAML **err_rc)
3357 struct lnet_ioctl_peer_cfg peer_info;
3358 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3363 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3364 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3365 struct lnet_process_id *list = NULL;
3367 memset(&peer_info, 0, sizeof(peer_info));
3369 /* create struct cYAML root object */
3370 root = cYAML_create_object(NULL, NULL);
3374 list_root = cYAML_create_seq(root, "peer list");
3375 if (list_root == NULL)
3379 size = count * sizeof(struct lnet_process_id);
3380 list = malloc(size);
3386 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3387 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3388 peer_info.prcfg_size = size;
3389 peer_info.prcfg_bulk = list;
3392 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3393 count = peer_info.prcfg_count;
3397 if (l_errno != E2BIG) {
3400 "\"cannot get peer list: %s\"",
3406 size = peer_info.prcfg_size;
3407 list = malloc(size);
3414 /* count is now the actual number of ids in the list. */
3415 for (i = 0; i < count; i++) {
3416 if (cYAML_create_string(list_root, "nid",
3417 libcfs_nid2str(list[i].nid))
3422 /* print output iff show_rc is not provided */
3423 if (show_rc == NULL)
3424 cYAML_print_tree(root);
3426 snprintf(err_str, sizeof(err_str), "\"success\"");
3427 rc = LUSTRE_CFG_RC_NO_ERR;
3432 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3433 cYAML_free_tree(root);
3434 } else if (show_rc != NULL && *show_rc != NULL) {
3435 struct cYAML *show_node;
3436 /* find the peer node, if one doesn't exist then
3437 * insert one. Otherwise add to the one there
3439 show_node = cYAML_get_object_item(*show_rc,
3441 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3442 cYAML_insert_child(show_node, first_seq);
3445 } else if (show_node == NULL) {
3446 cYAML_insert_sibling((*show_rc)->cy_child,
3450 cYAML_free_tree(root);
3456 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3462 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3465 struct cYAML *show_node;
3467 show_node = cYAML_get_object_item(show_rc, "global");
3468 if (show_node != NULL)
3469 cYAML_insert_sibling(show_node->cy_child,
3472 cYAML_insert_sibling(show_rc->cy_child,
3477 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3478 char *name, __u64 value,
3479 struct cYAML **show_rc,
3480 struct cYAML **err_rc, int err)
3482 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3483 struct cYAML *root = NULL, *global = NULL;
3490 root = cYAML_create_object(NULL, NULL);
3494 global = cYAML_create_object(root, "global");
3498 if (cYAML_create_number(global, name,
3502 if (show_rc == NULL)
3503 cYAML_print_tree(root);
3505 snprintf(err_str, err_len, "\"success\"");
3507 rc = LUSTRE_CFG_RC_NO_ERR;
3510 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3511 cYAML_free_tree(root);
3512 } else if (show_rc != NULL && *show_rc != NULL) {
3513 add_to_global(*show_rc, global, root);
3518 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3523 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3524 struct cYAML **show_rc,
3525 struct cYAML **err_rc)
3527 struct lnet_ioctl_set_value data;
3530 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3532 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3534 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3539 "\"cannot get %s: %s\"",
3540 name, strerror(l_errno));
3543 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3544 data.sv_value, show_rc, err_rc, l_errno);
3547 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3548 struct cYAML **err_rc)
3550 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3551 char val[LNET_MAX_STR_LEN];
3552 int intrv = -1, l_errno = 0;
3553 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3555 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3559 snprintf(err_str, sizeof(err_str),
3560 "\"cannot get recovery interval: %d\"", rc);
3565 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3566 "recovery_interval", intrv, show_rc,
3570 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3571 struct cYAML **err_rc)
3573 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3574 char val[LNET_MAX_STR_LEN];
3575 int sen = -1, l_errno = 0;
3576 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3578 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3582 snprintf(err_str, sizeof(err_str),
3583 "\"cannot get health sensitivity: %d\"", rc);
3588 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3589 "health_sensitivity", sen, show_rc,
3593 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3594 struct cYAML **err_rc)
3596 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3597 char val[LNET_MAX_STR_LEN];
3598 int sen = -1, l_errno = 0;
3599 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3601 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3605 snprintf(err_str, sizeof(err_str),
3606 "\"cannot get router sensitivity percentage: %d\"", rc);
3611 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3612 "router_sensitivity", sen, show_rc,
3616 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3617 struct cYAML **err_rc)
3619 char val[LNET_MAX_STR_LEN];
3620 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3627 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3630 snprintf(err_str, sizeof(err_str),
3631 "\"cannot get LND timeout: %d\"", rc);
3632 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3633 "lnd_timeout", lnd_to, show_rc,
3637 fd = open(path.gl_pathv[0], O_RDONLY);
3640 snprintf(err_str, sizeof(err_str),
3641 "\"error opening %s\"", path.gl_pathv[0]);
3645 rc = read(fd, val, sizeof(val));
3652 snprintf(err_str, sizeof(err_str),
3653 "\"error reading %s\"", path.gl_pathv[0]);
3660 cfs_free_param_data(&path);
3662 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3663 "lnd_timeout", lnd_to, show_rc,
3667 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3668 struct cYAML **err_rc)
3670 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3671 char val[LNET_MAX_STR_LEN];
3672 int tto = -1, l_errno = 0;
3673 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3675 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3679 snprintf(err_str, sizeof(err_str),
3680 "\"cannot get transaction timeout: %d\"", rc);
3685 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3686 "transaction_timeout", tto, show_rc,
3690 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3691 struct cYAML **err_rc)
3693 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3694 char val[LNET_MAX_STR_LEN];
3695 int retry_count = -1, l_errno = 0;
3696 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3698 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3702 snprintf(err_str, sizeof(err_str),
3703 "\"cannot get retry count: %d\"", rc);
3705 retry_count = atoi(val);
3708 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3709 "retry_count", retry_count, show_rc,
3713 int lustre_lnet_calc_service_id(__u64 *service_id)
3715 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3716 char val[LNET_MAX_STR_LEN];
3717 int service_port = -1, l_errno = 0;
3719 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3723 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3724 strerror(l_errno), -l_errno);
3727 service_port = atoi(val);
3730 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3732 return LUSTRE_CFG_RC_NO_ERR;
3735 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3738 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3740 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3741 struct lnet_ioctl_config_ni *ni_data;
3742 struct lnet_ioctl_config_lnd_tunables *lnd;
3743 struct lnet_ioctl_element_stats *stats;
3744 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3745 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3746 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3747 int if_cnt = 0, prc;
3748 char syscmdbuf[LNET_MAX_STR_LEN];
3749 char cmdpath[LNET_MAX_STR_LEN];
3750 bool use_custom = false;
3752 buf = calloc(1, buf_size);
3756 ni_data = (struct lnet_ioctl_config_ni *)buf;
3759 ifstr_ptr = ifstr_buf;
3764 memset(buf, 0, buf_size);
3766 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3767 /* set the ioc_len to the proper value since INIT assumes
3770 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3771 ni_data->lic_idx = i;
3773 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3779 rc_net = LNET_NIDNET(ni_data->lic_nid);
3781 /* only need to setup routing for tcp */
3782 if (LNET_NETTYP(rc_net) != SOCKLND)
3785 /* don't add interfaces unless there is at least one
3788 if (strlen(ni_data->lic_ni_intf) > 0) {
3790 strcat(ifstr_ptr, ",");
3791 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3796 if (l_errno != ENOENT) {
3799 "\"cannot get networks: %s\"",
3804 rc = LUSTRE_CFG_RC_NO_ERR;
3807 snprintf(err_str, sizeof(err_str), "\"success\"");
3810 tmp_ptr = getenv("KSOCKLND_CONFIG");
3812 tmp_ptr2 = strrchr(tmp_ptr, '/');
3813 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3814 snprintf(cmdpath, sizeof(cmdpath), "%s",
3821 snprintf(cmdpath, sizeof(cmdpath),
3822 "/usr/sbin/ksocklnd-config");
3824 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3830 "\"snprintf failed : %s\"",
3833 } else if (prc >= LNET_MAX_STR_LEN) {
3834 snprintf(err_str, sizeof(err_str),
3835 "\"ksocklnd-config: argument too long\"");
3837 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3838 cmdpath, ifstr_ptr);
3844 "\"snprintf failed : %s\"",
3850 rc = system(syscmdbuf);
3855 "\"failed to execute ksocklnd-config : %s\"",
3865 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3872 lnet_nid_cpt_hash(lnet_nid_t nid, long int number)
3875 __u64 pair_bits = 0x0001000100010001LLU;
3876 __u64 mask = pair_bits * 0xFF;
3882 pair_sum = (key & mask) + ((key >> 8) & mask);
3883 pair_sum = (pair_sum * pair_bits) >> 48;
3885 return (unsigned int)(pair_sum) % number;
3888 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3890 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3894 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3899 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3903 nid = libcfs_str2nid(nidc);
3904 if (nid == LNET_NID_ANY) {
3905 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3910 return (int)lnet_nid_cpt_hash(nid, ncpts);
3913 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3914 struct cYAML **show_rc, struct cYAML **err_rc)
3916 struct lnet_ioctl_recovery_list nid_list;
3917 struct cYAML *root = NULL, *nids = NULL;
3919 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3921 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3922 nid_list.rlst_type = type;
3924 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3930 if (nid_list.rlst_num_nids == 0)
3933 root = cYAML_create_object(NULL, NULL);
3937 nids = cYAML_create_object(root, name);
3943 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3944 char nidenum[LNET_MAX_STR_LEN];
3945 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3946 if (!cYAML_create_string(nids, nidenum,
3947 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3951 snprintf(err_str, sizeof(err_str), "success\n");
3956 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3957 cYAML_free_tree(root);
3958 } else if (show_rc != NULL && *show_rc != NULL) {
3959 struct cYAML *show_node;
3960 /* find the net node, if one doesn't exist
3961 * then insert one. Otherwise add to the one there
3963 show_node = cYAML_get_object_item(*show_rc, name);
3964 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3965 cYAML_insert_child(show_node, nids);
3968 } else if (show_node == NULL) {
3969 cYAML_insert_sibling((*show_rc)->cy_child,
3973 cYAML_free_tree(root);
3979 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3984 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
3985 struct cYAML **err_rc)
3987 struct libcfs_ioctl_data data;
3989 char err_str[LNET_MAX_STR_LEN] = "Error";
3990 lnet_nid_t pnid = LNET_NID_ANY;
3993 rc = LUSTRE_CFG_RC_BAD_PARAM;
3994 snprintf(err_str, LNET_MAX_STR_LEN,
3995 "--nid must be specified");
3999 pnid = libcfs_str2nid(peer_nid);
4000 if (pnid == LNET_NID_ANY) {
4001 rc = LUSTRE_CFG_RC_BAD_PARAM;
4002 snprintf(err_str, LNET_MAX_STR_LEN,
4003 "badly formatted primary NID: %s", peer_nid);
4007 LIBCFS_IOC_INIT(data);
4008 data.ioc_net = LNET_NIDNET(pnid);
4009 data.ioc_nid = pnid;
4011 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4015 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4021 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4022 struct cYAML **err_rc)
4024 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4025 seq_no, show_rc, err_rc);
4028 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4029 struct cYAML **err_rc)
4031 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4032 seq_no, show_rc, err_rc);
4035 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4036 struct cYAML **err_rc)
4038 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4039 char val[LNET_MAX_STR_LEN];
4040 int rsp_tracking = -1, l_errno = 0;
4041 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4043 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4047 snprintf(err_str, sizeof(err_str),
4048 "\"cannot get lnet_response_tracking value: %d\"", rc);
4050 rsp_tracking = atoi(val);
4053 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4054 "response_tracking", rsp_tracking,
4055 show_rc, err_rc, l_errno);
4058 int lustre_lnet_show_recovery_limit(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 recov_limit = -1, l_errno = 0;
4064 char err_str[LNET_MAX_STR_LEN];
4066 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4068 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4072 snprintf(err_str, sizeof(err_str),
4073 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4075 recov_limit = atoi(val);
4078 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4079 "recovery_limit", recov_limit,
4080 show_rc, err_rc, l_errno);
4083 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4084 struct cYAML **show_rc,
4085 struct cYAML **err_rc)
4087 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4088 char val[LNET_MAX_STR_LEN];
4089 int interval = -1, l_errno = 0;
4090 char err_str[LNET_MAX_STR_LEN];
4092 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4094 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4095 val, 1, sizeof(val));
4098 snprintf(err_str, sizeof(err_str),
4099 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4102 interval = atoi(val);
4105 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4106 "max_recovery_ping_interval", interval,
4107 show_rc, err_rc, l_errno);
4111 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4112 struct cYAML **err_rc)
4114 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4115 char val[LNET_MAX_STR_LEN];
4116 int max_intf = -1, l_errno = 0;
4117 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4119 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4123 snprintf(err_str, sizeof(err_str),
4124 "\"cannot get max interfaces: %d\"", rc);
4126 max_intf = atoi(val);
4129 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4130 "max_interfaces", max_intf, show_rc,
4134 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4135 struct cYAML **err_rc)
4137 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4138 char val[LNET_MAX_STR_LEN];
4139 int discovery = -1, l_errno = 0;
4140 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4142 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4146 snprintf(err_str, sizeof(err_str),
4147 "\"cannot get discovery setting: %d\"", rc);
4150 * The kernel stores a discovery disabled value. User space
4151 * shows whether discovery is enabled. So the value must be
4154 discovery = !atoi(val);
4157 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4158 "discovery", discovery, show_rc,
4162 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4163 struct cYAML **err_rc)
4165 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4166 char val[LNET_MAX_STR_LEN];
4167 int drop_asym_route = -1, l_errno = 0;
4168 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4170 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4174 snprintf(err_str, sizeof(err_str),
4175 "\"cannot get drop asym route setting: %d\"", rc);
4177 drop_asym_route = atoi(val);
4180 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4181 "drop_asym_route", drop_asym_route,
4182 show_rc, err_rc, l_errno);
4185 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4186 struct cYAML **err_rc)
4188 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4189 "numa_range", show_rc, err_rc);
4192 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4193 struct cYAML **err_rc)
4195 struct lnet_ioctl_lnet_stats data;
4196 struct lnet_counters *cntrs;
4199 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4200 struct cYAML *root = NULL, *stats = NULL;
4202 LIBCFS_IOC_INIT_V2(data, st_hdr);
4204 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4209 "\"cannot get lnet statistics: %s\"",
4215 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4217 cntrs = &data.st_cntrs;
4219 root = cYAML_create_object(NULL, NULL);
4223 stats = cYAML_create_object(root, "statistics");
4227 if (!cYAML_create_number(stats, "msgs_alloc",
4228 cntrs->lct_common.lcc_msgs_alloc))
4231 if (!cYAML_create_number(stats, "msgs_max",
4232 cntrs->lct_common.lcc_msgs_max))
4235 if (!cYAML_create_number(stats, "rst_alloc",
4236 cntrs->lct_health.lch_rst_alloc))
4239 if (!cYAML_create_number(stats, "errors",
4240 cntrs->lct_common.lcc_errors))
4243 if (!cYAML_create_number(stats, "send_count",
4244 cntrs->lct_common.lcc_send_count))
4247 if (!cYAML_create_number(stats, "resend_count",
4248 cntrs->lct_health.lch_resend_count))
4251 if (!cYAML_create_number(stats, "response_timeout_count",
4252 cntrs->lct_health.lch_response_timeout_count))
4255 if (!cYAML_create_number(stats, "local_interrupt_count",
4256 cntrs->lct_health.lch_local_interrupt_count))
4259 if (!cYAML_create_number(stats, "local_dropped_count",
4260 cntrs->lct_health.lch_local_dropped_count))
4263 if (!cYAML_create_number(stats, "local_aborted_count",
4264 cntrs->lct_health.lch_local_aborted_count))
4267 if (!cYAML_create_number(stats, "local_no_route_count",
4268 cntrs->lct_health.lch_local_no_route_count))
4271 if (!cYAML_create_number(stats, "local_timeout_count",
4272 cntrs->lct_health.lch_local_timeout_count))
4275 if (!cYAML_create_number(stats, "local_error_count",
4276 cntrs->lct_health.lch_local_error_count))
4279 if (!cYAML_create_number(stats, "remote_dropped_count",
4280 cntrs->lct_health.lch_remote_dropped_count))
4283 if (!cYAML_create_number(stats, "remote_error_count",
4284 cntrs->lct_health.lch_remote_error_count))
4287 if (!cYAML_create_number(stats, "remote_timeout_count",
4288 cntrs->lct_health.lch_remote_timeout_count))
4291 if (!cYAML_create_number(stats, "network_timeout_count",
4292 cntrs->lct_health.lch_network_timeout_count))
4295 if (!cYAML_create_number(stats, "recv_count",
4296 cntrs->lct_common.lcc_recv_count))
4299 if (!cYAML_create_number(stats, "route_count",
4300 cntrs->lct_common.lcc_route_count))
4303 if (!cYAML_create_number(stats, "drop_count",
4304 cntrs->lct_common.lcc_drop_count))
4307 if (!cYAML_create_number(stats, "send_length",
4308 cntrs->lct_common.lcc_send_length))
4311 if (!cYAML_create_number(stats, "recv_length",
4312 cntrs->lct_common.lcc_recv_length))
4315 if (!cYAML_create_number(stats, "route_length",
4316 cntrs->lct_common.lcc_route_length))
4319 if (!cYAML_create_number(stats, "drop_length",
4320 cntrs->lct_common.lcc_drop_length))
4324 cYAML_print_tree(root);
4326 snprintf(err_str, sizeof(err_str), "\"success\"");
4327 rc = LUSTRE_CFG_RC_NO_ERR;
4329 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4330 cYAML_free_tree(root);
4331 } else if (show_rc != NULL && *show_rc != NULL) {
4332 cYAML_insert_sibling((*show_rc)->cy_child,
4339 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4344 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4346 struct libcfs_ioctl_data data;
4347 int rc = LUSTRE_CFG_RC_NO_ERR;
4349 char err_str[LNET_MAX_STR_LEN];
4351 LIBCFS_IOC_INIT(data);
4353 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4358 "\"cannot reset lnet statistics: %s\"",
4362 snprintf(err_str, sizeof(err_str), "\"success\"");
4363 rc = LUSTRE_CFG_RC_NO_ERR;
4366 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4370 typedef int (*cmd_handler_t)(struct cYAML *tree,
4371 struct cYAML **show_rc,
4372 struct cYAML **err_rc);
4374 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4375 struct cYAML **err_rc)
4377 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4379 net = cYAML_get_object_item(tree, "net");
4380 gw = cYAML_get_object_item(tree, "gateway");
4381 hop = cYAML_get_object_item(tree, "hop");
4382 prio = cYAML_get_object_item(tree, "priority");
4383 sen = cYAML_get_object_item(tree, "health_sensitivity");
4384 seq_no = cYAML_get_object_item(tree, "seq_no");
4386 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4387 (gw) ? gw->cy_valuestring : NULL,
4388 (hop) ? hop->cy_valueint : -1,
4389 (prio) ? prio->cy_valueint : -1,
4390 (sen) ? sen->cy_valueint : -1,
4391 (seq_no) ? seq_no->cy_valueint : -1,
4397 * 0: <intf_name>['['<expr>']']
4398 * 1: <intf_name>['['<expr>']']
4400 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4401 struct lnet_dlc_network_descr *nw_descr)
4403 struct cYAML *child = NULL;
4404 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4405 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4407 if (intf_tree == NULL || nw_descr == NULL)
4408 return LUSTRE_CFG_RC_BAD_PARAM;
4410 /* now grab all the interfaces and their cpts */
4411 child = intf_tree->cy_child;
4412 while (child != NULL) {
4413 if (child->cy_valuestring == NULL) {
4414 child = child->cy_next;
4418 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4421 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4422 child->cy_valuestring,
4423 strlen(child->cy_valuestring));
4424 if (rc != LUSTRE_CFG_RC_NO_ERR)
4428 child = child->cy_next;
4432 return LUSTRE_CFG_RC_MISSING_PARAM;
4437 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4439 list_del(&intf_descr->intf_on_network);
4440 free_intf_descr(intf_descr);
4447 yaml_extract_cmn_tunables(struct cYAML *tree,
4448 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4450 struct cYAML *tun, *item;
4452 tun = cYAML_get_object_item(tree, "tunables");
4454 item = cYAML_get_object_item(tun, "peer_timeout");
4456 tunables->lct_peer_timeout = item->cy_valueint;
4458 tunables->lct_peer_timeout = -1;
4459 item = cYAML_get_object_item(tun, "peer_credits");
4461 tunables->lct_peer_tx_credits = item->cy_valueint;
4462 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4464 tunables->lct_peer_rtr_credits = item->cy_valueint;
4465 item = cYAML_get_object_item(tun, "credits");
4467 tunables->lct_max_tx_credits = item->cy_valueint;
4476 yaml_extract_tunables(struct cYAML *tree,
4477 struct lnet_ioctl_config_lnd_tunables *tunables,
4482 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4487 lustre_yaml_extract_lnd_tunables(tree, net_type,
4494 yaml_extract_cpt(struct cYAML *tree,
4495 struct cfs_expr_list **global_cpts)
4500 smp = cYAML_get_object_item(tree, "CPT");
4502 rc = cfs_expr_list_parse(smp->cy_valuestring,
4503 strlen(smp->cy_valuestring),
4504 0, UINT_MAX, global_cpts);
4506 *global_cpts = NULL;
4512 * - net type: <net>[<NUM>]
4514 * - nid: <ip>@<net>[<NUM>]
4517 * 0: <intf_name>['['<expr>']']
4518 * 1: <intf_name>['['<expr>']']
4520 * peer_timeout: <NUM>
4521 * peer_credits: <NUM>
4522 * peer_buffer_credits: <NUM>
4525 * peercredits_hiw: <NUM>
4526 * map_on_demand: <NUM>
4527 * concurrent_sends: <NUM>
4528 * fmr_pool_size: <NUM>
4529 * fmr_flush_trigger: <NUM>
4532 * At least one interface is required. If no interfaces are provided the
4533 * network interface can not be configured.
4535 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4536 struct cYAML **err_rc)
4538 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4540 int num_entries = 0, rc;
4541 struct lnet_dlc_network_descr nw_descr;
4542 struct cfs_expr_list *global_cpts = NULL;
4543 struct lnet_ioctl_config_lnd_tunables tunables;
4546 memset(&tunables, 0, sizeof(tunables));
4548 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4549 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4551 ip2net = cYAML_get_object_item(tree, "ip2net");
4552 net = cYAML_get_object_item(tree, "net type");
4554 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4556 nw_descr.nw_id = LOLND;
4559 * if neither net nor ip2nets are present, then we can not
4560 * configure the network.
4562 if (!net && !ip2net)
4563 return LUSTRE_CFG_RC_MISSING_PARAM;
4565 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4566 if (local_nis == NULL)
4567 return LUSTRE_CFG_RC_MISSING_PARAM;
4569 if (!cYAML_is_sequence(local_nis))
4570 return LUSTRE_CFG_RC_BAD_PARAM;
4572 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4573 intf = cYAML_get_object_item(item, "interfaces");
4576 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4577 if (num_entries <= 0) {
4578 cYAML_build_error(num_entries, -1, "ni", "add",
4579 "bad interface list",
4581 return LUSTRE_CFG_RC_BAD_PARAM;
4585 found = yaml_extract_tunables(tree, &tunables,
4586 LNET_NETTYP(nw_descr.nw_id));
4587 yaml_extract_cpt(tree, &global_cpts);
4588 seq_no = cYAML_get_object_item(tree, "seq_no");
4590 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4591 (ip2net) ? ip2net->cy_valuestring : NULL,
4592 (found) ? &tunables : NULL,
4593 (seq_no) ? seq_no->cy_valueint : -1,
4596 if (global_cpts != NULL)
4597 cfs_expr_list_free(global_cpts);
4604 * - net-spec: <tcp|o2ib|gni>[NUM]
4606 * 0: <intf name>['['<expr>']']
4607 * 1: <intf name>['['<expr>']']
4609 * 0: <expr.expr.expr.expr>
4610 * 1: <expr.expr.expr.expr>
4612 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4613 struct cYAML **show_rc,
4614 struct cYAML **err_rc)
4616 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4618 struct lustre_lnet_ip2nets ip2nets;
4619 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4621 int rc = LUSTRE_CFG_RC_NO_ERR;
4622 struct cfs_expr_list *global_cpts = NULL;
4623 struct cfs_expr_list *el, *el_tmp;
4624 struct lnet_ioctl_config_lnd_tunables tunables;
4625 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4628 memset(&tunables, 0, sizeof(tunables));
4630 /* initialize all lists */
4631 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4632 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4633 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4635 net = cYAML_get_object_item(tree, "net-spec");
4637 return LUSTRE_CFG_RC_BAD_PARAM;
4639 if (net != NULL && net->cy_valuestring == NULL)
4640 return LUSTRE_CFG_RC_BAD_PARAM;
4642 /* assign the network id */
4643 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4644 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4645 return LUSTRE_CFG_RC_BAD_PARAM;
4647 seq_no = cYAML_get_object_item(tree, "seq_no");
4649 intf = cYAML_get_object_item(tree, "interfaces");
4651 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4653 return LUSTRE_CFG_RC_BAD_PARAM;
4656 ip_range = cYAML_get_object_item(tree, "ip-range");
4657 if (ip_range != NULL) {
4658 item = ip_range->cy_child;
4659 while (item != NULL) {
4660 if (item->cy_valuestring == NULL) {
4661 item = item->cy_next;
4665 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4666 item->cy_valuestring);
4668 if (rc != LUSTRE_CFG_RC_NO_ERR)
4671 item = item->cy_next;
4675 found = yaml_extract_tunables(tree, &tunables,
4676 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4677 yaml_extract_cpt(tree, &global_cpts);
4679 rc = lustre_lnet_config_ip2nets(&ip2nets,
4680 (found) ? &tunables : NULL,
4682 (seq_no) ? seq_no->cy_valueint : -1,
4685 if (global_cpts != NULL)
4686 cfs_expr_list_free(global_cpts);
4689 * don't stop because there was no match. Continue processing the
4690 * rest of the rules. If non-match then nothing is configured
4692 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4693 rc = LUSTRE_CFG_RC_NO_ERR;
4695 list_for_each_entry_safe(intf_descr, intf_tmp,
4696 &ip2nets.ip2nets_net.nw_intflist,
4698 list_del(&intf_descr->intf_on_network);
4699 free_intf_descr(intf_descr);
4702 list_for_each_entry_safe(ip_range_descr, tmp,
4703 &ip2nets.ip2nets_ip_ranges,
4705 list_del(&ip_range_descr->ipr_entry);
4706 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4708 list_del(&el->el_link);
4709 cfs_expr_list_free(el);
4711 free(ip_range_descr);
4717 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4718 struct cYAML **err_rc)
4720 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4722 int num_entries, rc;
4723 struct lnet_dlc_network_descr nw_descr;
4725 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4726 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4728 net = cYAML_get_object_item(tree, "net type");
4730 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4732 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4733 if (local_nis == NULL)
4734 return LUSTRE_CFG_RC_MISSING_PARAM;
4736 if (!cYAML_is_sequence(local_nis))
4737 return LUSTRE_CFG_RC_BAD_PARAM;
4739 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4740 intf = cYAML_get_object_item(item, "interfaces");
4743 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4744 if (num_entries <= 0) {
4745 cYAML_build_error(num_entries, -1, "ni", "add",
4746 "bad interface list",
4748 return LUSTRE_CFG_RC_BAD_PARAM;
4752 seq_no = cYAML_get_object_item(tree, "seq_no");
4754 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4755 (seq_no) ? seq_no->cy_valueint : -1,
4761 /* Create a nidstring parseable by the nidstrings library from the nid
4762 * information encoded in the CYAML structure.
4763 * NOTE: Caller must free memory allocated to nidstr
4765 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4766 char *prim_nid, int cmd)
4768 int num_strs = 0, rc;
4769 size_t buf_size, buf_pos, nidstr_len = 0;
4771 struct cYAML *child = NULL, *entry = NULL;
4773 if (cYAML_is_sequence(nids_entry)) {
4774 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4775 entry = cYAML_get_object_item(child, "nid");
4776 /* don't count an empty entry */
4777 if (!entry || !entry->cy_valuestring)
4781 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4782 if (cmd == LNETCTL_DEL_CMD) {
4784 * primary nid is present in the list of
4785 * nids so that means we want to delete
4786 * the entire peer, so no need to go
4787 * further. Just delete the entire peer.
4789 return LUSTRE_CFG_RC_NO_ERR;
4796 * + 1 for the space separating each string, and
4797 * accounts for the terminating null char
4799 nidstr_len += strlen(entry->cy_valuestring) + 1;
4804 if (num_strs == 0 && !prim_nid)
4805 return LUSTRE_CFG_RC_MISSING_PARAM;
4806 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4807 return LUSTRE_CFG_RC_NO_ERR;
4809 buffer = malloc(nidstr_len);
4811 return LUSTRE_CFG_RC_OUT_OF_MEM;
4813 /* now grab all the nids */
4816 buf_size = nidstr_len;
4818 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4819 entry = cYAML_get_object_item(child, "nid");
4820 if (!entry || !entry->cy_valuestring)
4824 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4828 rc = snprintf(buffer + buf_pos, buf_size, " ");
4829 buf_pos += (rc < buf_size) ? rc : buf_size;
4830 buf_size = nidstr_len - buf_pos;
4833 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4834 entry->cy_valuestring);
4835 buf_pos += (rc < buf_size) ? rc : buf_size;
4836 buf_size = nidstr_len - buf_pos;
4841 return LUSTRE_CFG_RC_NO_ERR;
4844 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4845 struct cYAML **err_rc, int cmd)
4847 int rc, num_nids = 0, seqn;
4848 bool mr_value = false;
4849 char *nidstr = NULL, *prim_nidstr;
4850 char err_str[LNET_MAX_STR_LEN];
4851 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4852 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4853 lnet_nid_t pnid = LNET_NID_ANY;
4855 seq_no = cYAML_get_object_item(tree, "seq_no");
4856 seqn = seq_no ? seq_no->cy_valueint : -1;
4858 prim_nid = cYAML_get_object_item(tree, "primary nid");
4859 peer_nis = cYAML_get_object_item(tree, "peer ni");
4861 rc = LUSTRE_CFG_RC_BAD_PARAM;
4862 snprintf(err_str, LNET_MAX_STR_LEN,
4863 "\"primary nid\" must be specified");
4867 prim_nidstr = prim_nid->cy_valuestring;
4869 /* if the provided primary NID is bad, no need to go any further */
4870 pnid = libcfs_str2nid(prim_nidstr);
4871 if (pnid == LNET_NID_ANY) {
4872 rc = LUSTRE_CFG_RC_BAD_PARAM;
4873 snprintf(err_str, LNET_MAX_STR_LEN,
4874 "badly formatted primary NID: %s", prim_nidstr);
4878 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4879 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4880 snprintf(err_str, LNET_MAX_STR_LEN,
4881 "No nids defined in YAML block");
4883 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4884 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4886 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4887 snprintf(err_str, LNET_MAX_STR_LEN,
4888 "Unrecognized error %d", rc);
4894 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4895 LNET_MAX_NIDS_PER_PEER,
4903 if (cmd == LNETCTL_ADD_CMD) {
4904 mr = cYAML_get_object_item(tree, "Multi-Rail");
4906 if (mr && mr->cy_valuestring) {
4907 if (strcmp(mr->cy_valuestring, "False") == 0)
4909 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4910 rc = LUSTRE_CFG_RC_BAD_PARAM;
4911 snprintf(err_str, LNET_MAX_STR_LEN,
4912 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4913 mr->cy_valuestring);
4919 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4920 num_nids, mr_value, seqn,
4927 if (rc != LUSTRE_CFG_RC_NO_ERR)
4928 cYAML_build_error(rc, seqn, "peer",
4929 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4935 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4936 struct cYAML **err_rc)
4938 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4941 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4942 struct cYAML **err_rc)
4944 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4947 static int handle_yaml_config_buffers(struct cYAML *tree,
4948 struct cYAML **show_rc,
4949 struct cYAML **err_rc)
4952 struct cYAML *tiny, *small, *large, *seq_no;
4954 tiny = cYAML_get_object_item(tree, "tiny");
4955 small = cYAML_get_object_item(tree, "small");
4956 large = cYAML_get_object_item(tree, "large");
4957 seq_no = cYAML_get_object_item(tree, "seq_no");
4959 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4960 (small) ? small->cy_valueint : -1,
4961 (large) ? large->cy_valueint : -1,
4962 (seq_no) ? seq_no->cy_valueint : -1,
4968 static int handle_yaml_config_routing(struct cYAML *tree,
4969 struct cYAML **show_rc,
4970 struct cYAML **err_rc)
4972 int rc = LUSTRE_CFG_RC_NO_ERR;
4973 struct cYAML *seq_no, *enable;
4975 seq_no = cYAML_get_object_item(tree, "seq_no");
4976 enable = cYAML_get_object_item(tree, "enable");
4979 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4981 seq_no->cy_valueint : -1,
4988 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4989 struct cYAML **err_rc)
4993 struct cYAML *seq_no;
4995 net = cYAML_get_object_item(tree, "net");
4996 gw = cYAML_get_object_item(tree, "gateway");
4997 seq_no = cYAML_get_object_item(tree, "seq_no");
4999 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5000 (gw) ? gw->cy_valuestring : NULL,
5001 (seq_no) ? seq_no->cy_valueint : -1,
5005 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5006 struct cYAML **err_rc)
5008 struct cYAML *seq_no;
5010 seq_no = cYAML_get_object_item(tree, "seq_no");
5012 return lustre_lnet_enable_routing(0, (seq_no) ?
5013 seq_no->cy_valueint : -1,
5017 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5018 struct cYAML **err_rc)
5024 struct cYAML *detail;
5025 struct cYAML *seq_no;
5027 net = cYAML_get_object_item(tree, "net");
5028 gw = cYAML_get_object_item(tree, "gateway");
5029 hop = cYAML_get_object_item(tree, "hop");
5030 prio = cYAML_get_object_item(tree, "priority");
5031 detail = cYAML_get_object_item(tree, "detail");
5032 seq_no = cYAML_get_object_item(tree, "seq_no");
5034 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5035 (gw) ? gw->cy_valuestring : NULL,
5036 (hop) ? hop->cy_valueint : -1,
5037 (prio) ? prio->cy_valueint : -1,
5038 (detail) ? detail->cy_valueint : 0,
5039 (seq_no) ? seq_no->cy_valueint : -1,
5040 show_rc, err_rc, false);
5043 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5044 struct cYAML **err_rc)
5046 struct cYAML *net, *detail, *seq_no;
5048 net = cYAML_get_object_item(tree, "net type");
5049 detail = cYAML_get_object_item(tree, "detail");
5050 seq_no = cYAML_get_object_item(tree, "seq_no");
5052 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5053 (detail) ? detail->cy_valueint : 0,
5054 (seq_no) ? seq_no->cy_valueint : -1,
5055 show_rc, err_rc, false);
5058 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5059 struct cYAML **err_rc)
5061 struct cYAML *seq_no;
5063 seq_no = cYAML_get_object_item(tree, "seq_no");
5065 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5066 show_rc, err_rc, false);
5069 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5070 struct cYAML **err_rc)
5072 struct cYAML *seq_no, *nid, *detail;
5074 seq_no = cYAML_get_object_item(tree, "seq_no");
5075 detail = cYAML_get_object_item(tree, "detail");
5076 nid = cYAML_get_object_item(tree, "nid");
5078 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5079 (detail) ? detail->cy_valueint : 0,
5080 (seq_no) ? seq_no->cy_valueint : -1,
5081 show_rc, err_rc, false);
5084 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5085 struct cYAML **err_rc)
5087 struct cYAML *seq_no;
5089 seq_no = cYAML_get_object_item(tree, "seq_no");
5091 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5095 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5096 struct cYAML **err_rc)
5098 struct cYAML *seq_no, *range;
5100 seq_no = cYAML_get_object_item(tree, "seq_no");
5101 range = cYAML_get_object_item(tree, "range");
5103 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5104 seq_no ? seq_no->cy_valueint : -1,
5108 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5109 struct cYAML **err_rc)
5111 struct cYAML *seq_no;
5113 seq_no = cYAML_get_object_item(tree, "seq_no");
5115 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5119 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5120 struct cYAML **err_rc)
5122 struct cYAML *seq_no;
5124 seq_no = cYAML_get_object_item(tree, "seq_no");
5126 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5130 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5131 struct cYAML **err_rc)
5133 struct cYAML *seq_no, *idx;
5135 seq_no = cYAML_get_object_item(tree, "seq_no");
5136 idx = cYAML_get_object_item(tree, "idx");
5138 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5139 seq_no ? seq_no->cy_valueint : -1,
5143 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5144 struct cYAML **err_rc)
5146 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5147 union lnet_udsp_action action;
5149 seq_no = cYAML_get_object_item(tree, "seq_no");
5150 src = cYAML_get_object_item(tree, "src");
5151 rte = cYAML_get_object_item(tree, "rte");
5152 dst = cYAML_get_object_item(tree, "dst");
5153 prio = cYAML_get_object_item(tree, "priority");
5154 idx = cYAML_get_object_item(tree, "idx");
5156 action.udsp_priority = prio ? prio->cy_valueint : -1;
5158 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5159 dst ? dst->cy_valuestring : NULL,
5160 rte ? rte->cy_valuestring : NULL,
5161 prio ? "priority" : "",
5163 idx ? idx->cy_valueint : -1,
5164 seq_no ? seq_no->cy_valueint : -1,
5168 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5169 struct cYAML **err_rc)
5171 struct cYAML *seq_no;
5174 seq_no = cYAML_get_object_item(tree, "seq_no");
5175 idx = cYAML_get_object_item(tree, "idx");
5177 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5178 seq_no ? seq_no->cy_valueint : -1,
5182 static int handle_yaml_config_global_settings(struct cYAML *tree,
5183 struct cYAML **show_rc,
5184 struct cYAML **err_rc)
5186 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5187 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5191 seq_no = cYAML_get_object_item(tree, "seq_no");
5192 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5193 if (!max_intf) /* try legacy name */
5194 max_intf = cYAML_get_object_item(tree, "max_intf");
5196 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5197 seq_no ? seq_no->cy_valueint
5201 numa = cYAML_get_object_item(tree, "numa_range");
5203 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5204 seq_no ? seq_no->cy_valueint
5208 discovery = cYAML_get_object_item(tree, "discovery");
5210 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5211 seq_no ? seq_no->cy_valueint
5215 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5216 if (drop_asym_route)
5217 rc = lustre_lnet_config_drop_asym_route(
5218 drop_asym_route->cy_valueint,
5219 seq_no ? seq_no->cy_valueint : -1,
5222 retry = cYAML_get_object_item(tree, "retry_count");
5224 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5225 seq_no ? seq_no->cy_valueint
5229 tto = cYAML_get_object_item(tree, "transaction_timeout");
5231 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5232 seq_no ? seq_no->cy_valueint
5236 sen = cYAML_get_object_item(tree, "health_sensitivity");
5238 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5239 seq_no ? seq_no->cy_valueint
5243 recov = cYAML_get_object_item(tree, "recovery_interval");
5245 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5246 seq_no ? seq_no->cy_valueint
5250 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5252 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5253 seq_no ? seq_no->cy_valueint
5257 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5259 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5260 seq_no ? seq_no->cy_valueint
5264 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5266 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5267 seq_no ? seq_no->cy_valueint
5274 static int handle_yaml_del_global_settings(struct cYAML *tree,
5275 struct cYAML **show_rc,
5276 struct cYAML **err_rc)
5278 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5281 seq_no = cYAML_get_object_item(tree, "seq_no");
5282 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5283 if (!max_intf) /* try legacy name */
5284 max_intf = cYAML_get_object_item(tree, "max_intf");
5286 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5287 seq_no ? seq_no->cy_valueint
5291 numa = cYAML_get_object_item(tree, "numa_range");
5293 rc = lustre_lnet_config_numa_range(0,
5294 seq_no ? seq_no->cy_valueint
5298 /* peer discovery is enabled by default */
5299 discovery = cYAML_get_object_item(tree, "discovery");
5301 rc = lustre_lnet_config_discovery(1,
5302 seq_no ? seq_no->cy_valueint
5306 /* asymmetrical route messages are accepted by default */
5307 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5308 if (drop_asym_route)
5309 rc = lustre_lnet_config_drop_asym_route(
5310 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5315 static int handle_yaml_show_global_settings(struct cYAML *tree,
5316 struct cYAML **show_rc,
5317 struct cYAML **err_rc)
5319 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5320 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5324 seq_no = cYAML_get_object_item(tree, "seq_no");
5325 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5326 if (!max_intf) /* try legacy name */
5327 max_intf = cYAML_get_object_item(tree, "max_intf");
5329 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5333 numa = cYAML_get_object_item(tree, "numa_range");
5335 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5339 discovery = cYAML_get_object_item(tree, "discovery");
5341 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5345 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5346 if (drop_asym_route)
5347 rc = lustre_lnet_show_drop_asym_route(
5348 seq_no ? seq_no->cy_valueint : -1,
5351 retry = cYAML_get_object_item(tree, "retry_count");
5353 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5357 tto = cYAML_get_object_item(tree, "transaction_timeout");
5359 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5363 sen = cYAML_get_object_item(tree, "health_sensitivity");
5365 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5369 recov = cYAML_get_object_item(tree, "recovery_interval");
5371 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5375 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5377 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5381 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5383 rc = lustre_lnet_show_response_tracking(seq_no ?
5384 seq_no->cy_valueint :
5388 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5390 rc = lustre_lnet_show_recovery_limit(seq_no ?
5391 seq_no->cy_valueint :
5398 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5399 struct cYAML **err_rc)
5401 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5403 seq_no = cYAML_get_object_item(tree, "seq_no");
5404 nid = cYAML_get_object_item(tree, "primary nid");
5405 timeout = cYAML_get_object_item(tree, "timeout");
5406 src_nid = cYAML_get_object_item(tree, "source_nid");
5408 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5409 (src_nid) ? src_nid->cy_valuestring : NULL,
5410 (timeout) ? timeout->cy_valueint : 1000,
5411 (seq_no) ? seq_no->cy_valueint : -1,
5415 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5416 struct cYAML **err_rc)
5418 struct cYAML *seq_no, *nid, *force;
5420 seq_no = cYAML_get_object_item(tree, "seq_no");
5421 nid = cYAML_get_object_item(tree, "primary nid");
5422 force = cYAML_get_object_item(tree, "force");
5424 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5425 (force) ? force->cy_valueint : 0,
5426 (seq_no) ? seq_no->cy_valueint : -1,
5430 static int handle_yaml_no_op()
5432 return LUSTRE_CFG_RC_NO_ERR;
5435 struct lookup_cmd_hdlr_tbl {
5440 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5441 { .name = "route", .cb = handle_yaml_config_route },
5442 { .name = "net", .cb = handle_yaml_config_ni },
5443 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5444 { .name = "peer", .cb = handle_yaml_config_peer },
5445 { .name = "routing", .cb = handle_yaml_config_routing },
5446 { .name = "buffers", .cb = handle_yaml_config_buffers },
5447 { .name = "statistics", .cb = handle_yaml_no_op },
5448 { .name = "global", .cb = handle_yaml_config_global_settings},
5449 { .name = "numa", .cb = handle_yaml_config_numa },
5450 { .name = "ping", .cb = handle_yaml_no_op },
5451 { .name = "discover", .cb = handle_yaml_no_op },
5452 { .name = "udsp", .cb = handle_yaml_config_udsp },
5455 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5456 { .name = "route", .cb = handle_yaml_del_route },
5457 { .name = "net", .cb = handle_yaml_del_ni },
5458 { .name = "ip2nets", .cb = handle_yaml_no_op },
5459 { .name = "peer", .cb = handle_yaml_del_peer },
5460 { .name = "routing", .cb = handle_yaml_del_routing },
5461 { .name = "buffers", .cb = handle_yaml_no_op },
5462 { .name = "statistics", .cb = handle_yaml_no_op },
5463 { .name = "global", .cb = handle_yaml_del_global_settings},
5464 { .name = "numa", .cb = handle_yaml_del_numa },
5465 { .name = "ping", .cb = handle_yaml_no_op },
5466 { .name = "discover", .cb = handle_yaml_no_op },
5467 { .name = "udsp", .cb = handle_yaml_del_udsp },
5470 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5471 { .name = "route", .cb = handle_yaml_show_route },
5472 { .name = "net", .cb = handle_yaml_show_net },
5473 { .name = "peer", .cb = handle_yaml_show_peers },
5474 { .name = "ip2nets", .cb = handle_yaml_no_op },
5475 { .name = "routing", .cb = handle_yaml_show_routing },
5476 { .name = "buffers", .cb = handle_yaml_show_routing },
5477 { .name = "statistics", .cb = handle_yaml_show_stats },
5478 { .name = "global", .cb = handle_yaml_show_global_settings},
5479 { .name = "numa", .cb = handle_yaml_show_numa },
5480 { .name = "ping", .cb = handle_yaml_no_op },
5481 { .name = "discover", .cb = handle_yaml_no_op },
5482 { .name = "udsp", .cb = handle_yaml_show_udsp },
5485 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5486 { .name = "route", .cb = handle_yaml_no_op },
5487 { .name = "net", .cb = handle_yaml_no_op },
5488 { .name = "peer", .cb = handle_yaml_no_op },
5489 { .name = "ip2nets", .cb = handle_yaml_no_op },
5490 { .name = "routing", .cb = handle_yaml_no_op },
5491 { .name = "buffers", .cb = handle_yaml_no_op },
5492 { .name = "statistics", .cb = handle_yaml_no_op },
5493 { .name = "global", .cb = handle_yaml_no_op },
5494 { .name = "numa", .cb = handle_yaml_no_op },
5495 { .name = "ping", .cb = handle_yaml_ping },
5496 { .name = "discover", .cb = handle_yaml_discover },
5499 static cmd_handler_t lookup_fn(char *key,
5500 struct lookup_cmd_hdlr_tbl *tbl)
5506 for (i = 0; tbl[i].name != NULL; i++) {
5507 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5514 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5515 struct cYAML **show_rc, struct cYAML **err_rc)
5517 struct cYAML *tree, *item = NULL, *head, *child;
5519 char err_str[LNET_MAX_STR_LEN];
5520 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5522 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5524 return LUSTRE_CFG_RC_BAD_PARAM;
5526 child = tree->cy_child;
5527 while (child != NULL) {
5528 cb = lookup_fn(child->cy_string, table);
5530 snprintf(err_str, sizeof(err_str),
5531 "\"call back for '%s' not found\"",
5533 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5534 "yaml", "helper", err_str, err_rc);
5538 if (cYAML_is_sequence(child)) {
5539 while ((head = cYAML_get_next_seq_item(child, &item))
5541 rc = cb(head, show_rc, err_rc);
5542 if (rc != LUSTRE_CFG_RC_NO_ERR)
5546 rc = cb(child, show_rc, err_rc);
5547 if (rc != LUSTRE_CFG_RC_NO_ERR)
5551 child = child->cy_next;
5555 cYAML_free_tree(tree);
5560 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5562 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5566 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5568 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5572 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5574 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5578 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5580 return lustre_yaml_cb_helper(f, lookup_exec_tbl,