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 <libcfs/util/hash.h>
48 #include <linux/lnet/lnetctl.h>
50 #include <sys/types.h>
54 #include <rdma/rdma_user_cm.h>
55 #include "liblnetconfig.h"
57 #include <libcfs/util/param.h>
59 #ifndef HAVE_USRSPC_RDMA_PS_TCP
60 #define RDMA_PS_TCP 0x0106
63 #define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
64 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
68 * lustre_lnet_ip_range_descr
69 * Describes an IP range.
70 * Each octect is an expression
72 struct lustre_lnet_ip_range_descr {
73 struct list_head ipr_entry;
74 struct list_head ipr_expr;
79 * Describes an ip2nets rule. This can be on a list of rules.
81 struct lustre_lnet_ip2nets {
82 struct lnet_dlc_network_descr ip2nets_net;
83 struct list_head ip2nets_ip_ranges;
86 static int open_sysfs_file(const char *path, const char *attr, const int mode)
89 char filename[LNET_MAX_STR_LEN];
90 size_t size = sizeof(filename);
93 namelen = snprintf(filename, size, "%s%s", path, attr);
95 filename[size - 1] = '\0';
97 fd = open(filename, mode);
102 static int read_sysfs_file(const char *path, const char *attr,
103 void *val, const size_t size, const int nelem)
106 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
108 fd = open_sysfs_file(path, attr, O_RDONLY);
110 return LUSTRE_CFG_RC_NO_MATCH;
112 if (read(fd, val, size * nelem) == -1)
115 rc = LUSTRE_CFG_RC_NO_ERR;
122 static int write_sysfs_file(const char *path, const char *attr,
123 void *val, const size_t size, const int nelem)
126 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
128 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
130 return LUSTRE_CFG_RC_NO_MATCH;
132 if (write(fd, val, size * nelem) == -1)
135 rc = LUSTRE_CFG_RC_NO_ERR;
144 * frees the memory allocated for an intf descriptor.
146 static void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
151 if (intf_descr->cpt_expr != NULL)
152 cfs_expr_list_free(intf_descr->cpt_expr);
157 * lustre_lnet_add_ip_range
159 * given a string of the format:
160 * <expr.expr.expr.expr> parse each expr into
161 * a lustre_lnet_ip_range_descr structure and insert on the list.
163 * This function is called from
164 * YAML on each ip-range.
165 * As a result of lnetctl command
166 * When building a NID or P2P selection rules
168 static int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
170 struct lustre_lnet_ip_range_descr *ip_range;
173 ip_range = calloc(1, sizeof(*ip_range));
174 if (ip_range == NULL)
175 return LUSTRE_CFG_RC_OUT_OF_MEM;
177 INIT_LIST_HEAD(&ip_range->ipr_entry);
178 INIT_LIST_HEAD(&ip_range->ipr_expr);
180 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
181 &ip_range->ipr_expr);
183 return LUSTRE_CFG_RC_BAD_PARAM;
185 list_add_tail(&ip_range->ipr_entry, list);
187 return LUSTRE_CFG_RC_NO_ERR;
190 static int lustre_lnet_add_intf_descr(struct list_head *list, char *intf,
193 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
195 struct lnet_dlc_intf_descr *intf_descr = NULL;
197 char intf_string[LNET_MAX_STR_LEN];
199 if (len >= LNET_MAX_STR_LEN)
200 return LUSTRE_CFG_RC_BAD_PARAM;
202 strncpy(intf_string, intf, len);
203 intf_string[len] = '\0';
205 intf_descr = calloc(1, sizeof(*intf_descr));
206 if (intf_descr == NULL)
207 return LUSTRE_CFG_RC_OUT_OF_MEM;
209 INIT_LIST_HEAD(&intf_descr->intf_on_network);
211 intf_name = intf_string;
212 open_sq_bracket = strchr(intf_string, '[');
213 if (open_sq_bracket != NULL) {
214 close_sq_bracket = strchr(intf_string, ']');
215 if (close_sq_bracket == NULL) {
217 return LUSTRE_CFG_RC_BAD_PARAM;
219 rc = cfs_expr_list_parse(open_sq_bracket,
220 strlen(open_sq_bracket), 0, UINT_MAX,
221 &intf_descr->cpt_expr);
224 return LUSTRE_CFG_RC_BAD_PARAM;
226 strncpy(intf_descr->intf_name, intf_name,
227 open_sq_bracket - intf_name);
228 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
230 strcpy(intf_descr->intf_name, intf_name);
231 intf_descr->cpt_expr = NULL;
234 list_add_tail(&intf_descr->intf_on_network, list);
236 return LUSTRE_CFG_RC_NO_ERR;
239 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
241 if (nw_descr != NULL) {
243 INIT_LIST_HEAD(&nw_descr->network_on_rule);
244 INIT_LIST_HEAD(&nw_descr->nw_intflist);
248 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
249 int max_nids, char *err_str)
251 int rc, num_nids = 0;
252 struct list_head nidlist;
255 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
256 return LUSTRE_CFG_RC_BAD_PARAM;
259 if (strchr(nidstr, '*')) {
260 snprintf(err_str, LNET_MAX_STR_LEN,
261 "asterisk not allowed in nidstring \"%s\"", nidstr);
262 return LUSTRE_CFG_RC_BAD_PARAM;
265 INIT_LIST_HEAD(&nidlist);
266 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
268 snprintf(err_str, LNET_MAX_STR_LEN,
269 "Unable to parse nidlist from: %s\n", nidstr);
270 return LUSTRE_CFG_RC_BAD_PARAM;
273 if (list_empty(&nidlist)) {
274 snprintf(err_str, LNET_MAX_STR_LEN,
275 "\"%s\" does not specify any valid nid lists", nidstr);
276 return LUSTRE_CFG_RC_BAD_PARAM;
279 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
280 cfs_free_nidlist(&nidlist);
282 if (num_nids == -1) {
283 snprintf(err_str, LNET_MAX_STR_LEN,
284 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
286 return LUSTRE_CFG_RC_BAD_PARAM;
290 snprintf(err_str, LNET_MAX_STR_LEN,
291 "Failed to expand nidstr: %s", strerror(num_nids));
292 return LUSTRE_CFG_RC_OUT_OF_MEM;
296 snprintf(err_str, LNET_MAX_STR_LEN,
297 "\"%s\" did not expand to any nids", nidstr);
298 return LUSTRE_CFG_RC_BAD_PARAM;
306 * <intf>[<expr>], <intf>[<expr>],..
308 int lustre_lnet_parse_interfaces(char *intf_str,
309 struct lnet_dlc_network_descr *nw_descr)
314 char *cur = intf_str, *next = NULL;
315 char *end = intf_str + strlen(intf_str);
317 struct lnet_dlc_intf_descr *intf_descr, *tmp;
319 if (nw_descr == NULL)
320 return LUSTRE_CFG_RC_BAD_PARAM;
323 open_square = strchr(cur, '[');
324 if (open_square != NULL) {
325 close_square = strchr(cur, ']');
326 if (close_square == NULL) {
327 rc = LUSTRE_CFG_RC_BAD_PARAM;
331 comma = strchr(cur, ',');
332 if (comma != NULL && comma > close_square) {
334 len = next - close_square;
340 comma = strchr(cur, ',');
350 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
351 if (rc != LUSTRE_CFG_RC_NO_ERR)
357 return LUSTRE_CFG_RC_NO_ERR;
360 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
362 list_del(&intf_descr->intf_on_network);
363 free_intf_descr(intf_descr);
369 int lustre_lnet_config_lib_init(void)
371 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
374 void lustre_lnet_config_lib_uninit(void)
376 unregister_ioc_dev(LNET_DEV_ID);
379 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
380 int seq_no, struct cYAML **err_rc)
382 struct libcfs_ioctl_data data;
385 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
387 LIBCFS_IOC_INIT(data);
389 /* Reverse logic is used here in order not to change
390 * the lctl utility */
391 data.ioc_flags = load_ni_from_mod ? 0 : 1;
393 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
395 rc = l_ioctl(LNET_DEV_ID, opc, &data);
399 "\"LNet %s error: %s\"", (up) ? "configure" :
400 "unconfigure", strerror(errno));
404 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
405 "lnet", err_str, err_rc);
410 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
411 char *err_str, char *cmd_str)
415 rc = l_ioctl(LNET_DEV_ID, cmd, data);
418 snprintf(err_str, LNET_MAX_STR_LEN,
419 "\"%s peer ni operation failed: %s\"",
420 cmd_str, strerror(errno));
426 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
427 int param, int ioc_call, int seq_no,
428 struct cYAML **show_rc, struct cYAML **err_rc)
431 struct lnet_ioctl_ping_data ping;
432 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
433 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
434 struct lnet_process_id id;
435 char err_str[LNET_MAX_STR_LEN] = {0};
436 char *sep, *token, *end;
439 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
444 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
446 data = calloc(1, len);
450 /* create struct cYAML root object */
451 root = cYAML_create_object(NULL, NULL);
455 ping_node = cYAML_create_seq(root, oper);
456 if (ping_node == NULL)
460 src = libcfs_str2nid(src_nidstr);
461 if (src == LNET_NID_ANY) {
462 snprintf(err_str, sizeof(err_str),
463 "\"cannot parse source NID '%s'\"",
465 rc = LUSTRE_CFG_RC_BAD_PARAM;
466 cYAML_build_error(rc, seq_no, MANAGE_CMD,
467 oper, err_str, err_rc);
474 /* tokenise each nid in string ping_nids */
475 token = strtok(ping_nids, ",");
478 item = cYAML_create_seq_item(ping_node);
482 if (first_seq == NULL)
485 /* check if '-' is a part of NID, token */
486 sep = strchr(token, '-');
488 id.pid = LNET_PID_ANY;
489 /* if no net is specified, libcfs_str2nid() will assume tcp */
490 id.nid = libcfs_str2nid(token);
491 if (id.nid == LNET_NID_ANY) {
492 snprintf(err_str, sizeof(err_str),
493 "\"cannot parse NID '%s'\"",
495 rc = LUSTRE_CFG_RC_BAD_PARAM;
496 cYAML_build_error(rc, seq_no, MANAGE_CMD,
497 oper, err_str, err_rc);
501 if (token[0] == 'u' || token[0] == 'U')
502 id.pid = (strtoul(&token[1], &end, 0) |
503 (LNET_PID_USERFLAG));
505 id.pid = strtoul(token, &end, 0);
507 /* assuming '-' is part of hostname */
509 id.pid = LNET_PID_ANY;
510 id.nid = libcfs_str2nid(token);
511 if (id.nid == LNET_NID_ANY) {
512 snprintf(err_str, sizeof(err_str),
513 "\"cannot parse NID '%s'\"",
515 rc = LUSTRE_CFG_RC_BAD_PARAM;
516 cYAML_build_error(rc, seq_no, MANAGE_CMD,
522 id.nid = libcfs_str2nid(sep + 1);
523 if (id.nid == LNET_NID_ANY) {
524 snprintf(err_str, sizeof(err_str),
525 "\"cannot parse NID '%s'\"",
527 rc = LUSTRE_CFG_RC_BAD_PARAM;
528 cYAML_build_error(rc, seq_no, MANAGE_CMD,
535 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
536 ping.ping_hdr.ioc_len = sizeof(ping);
539 ping.op_param = param;
540 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
541 ping.ping_buf = data;
543 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
546 sizeof(err_str), "failed to %s %s: %s\n", oper,
547 id.pid == LNET_PID_ANY ?
548 libcfs_nid2str(id.nid) :
549 libcfs_id2str(id), strerror(errno));
550 rc = LUSTRE_CFG_RC_BAD_PARAM;
551 cYAML_build_error(rc, seq_no, MANAGE_CMD,
552 oper, err_str, err_rc);
556 if (cYAML_create_string(item, "primary nid",
557 libcfs_nid2str(ping.ping_id.nid)) == NULL)
560 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
561 "True" : "False") == NULL)
564 tmp = cYAML_create_seq(item, "peer ni");
568 for (i = 0; i < ping.ping_count; i++) {
569 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
571 peer_ni = cYAML_create_seq_item(tmp);
574 memset(buf, 0, sizeof buf);
575 snprintf(buf, sizeof buf, "nid");
576 if (cYAML_create_string(peer_ni, buf,
577 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
583 } while ((token = strtok(NULL, ",")) != NULL);
586 rc = LUSTRE_CFG_RC_NO_ERR;
591 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
592 cYAML_free_tree(root);
593 } else if (show_rc != NULL && *show_rc != NULL) {
594 struct cYAML *show_node;
595 show_node = cYAML_get_object_item(*show_rc, oper);
596 if (show_node != NULL && cYAML_is_sequence(show_node)) {
597 cYAML_insert_child(show_node, first_seq);
600 } else if (show_node == NULL) {
601 cYAML_insert_sibling((*show_rc)->cy_child,
605 cYAML_free_tree(root);
614 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
615 int seq_no, struct cYAML **show_rc,
616 struct cYAML **err_rc)
620 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
621 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
625 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
626 struct cYAML **show_rc, struct cYAML **err_rc)
630 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
631 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
635 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
636 bool is_mr, int option, __u32 cmd,
637 char *cmd_type, char *err_str)
639 struct lnet_ioctl_peer_cfg data;
642 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
643 /* When adding a peer we first need to create the peer using the
644 * specified (or implied) primary nid. Then we can add
645 * additional nids to this peer using the primary nid as a key
647 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
648 data.prcfg_mr = is_mr;
649 data.prcfg_prim_nid = nidlist[0];
650 data.prcfg_cfg_nid = LNET_NID_ANY;
651 data.prcfg_count = option;
653 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
659 /* Add or delete any specified NIs associated with the specified
660 * (or implied) primary nid
662 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
663 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
664 data.prcfg_mr = is_mr;
665 data.prcfg_prim_nid = nidlist[0];
666 data.prcfg_cfg_nid = nidlist[nid_idx];
667 data.prcfg_count = option;
669 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
675 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
676 /* In the delete case we may have been given just the
677 * primary nid of the peer. This tells us to delete the peer
678 * completely (rather than just delete some of its NIs)
680 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
681 data.prcfg_prim_nid = nidlist[0];
682 data.prcfg_cfg_nid = LNET_NID_ANY;
683 data.prcfg_count = option;
685 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
692 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
693 int cmd, int num_nids, bool is_mr, int option,
694 int seq_no, struct cYAML **err_rc)
696 int rc = LUSTRE_CFG_RC_NO_ERR;
697 char err_str[LNET_MAX_STR_LEN];
698 lnet_nid_t *lnet_nidlist2 = NULL;
699 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
700 IOC_LIBCFS_DEL_PEER_NI;
701 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
704 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
705 if (!lnet_nidlist2) {
706 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
707 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
710 lnet_nidlist2[0] = pnid;
711 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
714 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
715 num_nids, is_mr, option,
716 ioc_cmd, cmd_str, err_str);
721 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
726 replace_sep(char *str, char sep, char newsep)
732 for (i = 0; i < strlen(str); i++) {
733 /* don't replace ',' within [] */
736 else if (str[i] == ']')
738 else if (str[i] == sep && bracket == 0)
743 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr, int cmd,
744 int option, int seq_no, struct cYAML **err_rc)
747 char err_str[LNET_MAX_STR_LEN] = "Error";
748 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
749 lnet_nid_t pnid = LNET_NID_ANY;
752 rc = LUSTRE_CFG_RC_BAD_PARAM;
753 snprintf(err_str, LNET_MAX_STR_LEN,
754 "--prim_nid must be specified");
758 pnid = libcfs_str2nid(prim_nid);
759 if (pnid == LNET_NID_ANY) {
760 rc = LUSTRE_CFG_RC_BAD_PARAM;
761 snprintf(err_str, LNET_MAX_STR_LEN,
762 "badly formatted primary NID: %s", prim_nid);
769 * if there is no primary nid we need to make the first nid in the
770 * nids list the primary nid
772 replace_sep(nids, ',', ' ');
773 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
774 LNET_MAX_NIDS_PER_PEER, err_str);
781 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
782 cmd, num_nids, is_mr,
786 if (rc != LUSTRE_CFG_RC_NO_ERR)
787 cYAML_build_error(rc, -1, "peer",
788 cmd == LNETCTL_ADD_CMD ? "add" : "del",
794 static int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
795 int sen, int seq_no, struct cYAML **err_rc,
798 int rc, num_nids, idx;
800 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
801 struct lnet_ioctl_config_data data;
802 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
804 if (nw == NULL || nidstr == NULL) {
805 snprintf(err_str, LNET_MAX_STR_LEN,
806 "\"missing mandatory parameter:'%s'\"",
807 (nw == NULL && nidstr == NULL) ? "network, gateway" :
808 (nw == NULL) ? "network" : "gateway");
809 rc = LUSTRE_CFG_RC_MISSING_PARAM;
813 rnet = libcfs_str2net(nw);
814 if (rnet == LNET_NET_ANY) {
815 snprintf(err_str, LNET_MAX_STR_LEN,
816 "\"cannot parse remote net %s\"", nw);
817 rc = LUSTRE_CFG_RC_BAD_PARAM;
821 replace_sep(nidstr, ',', ' ');
822 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
823 LNET_MAX_NIDS_PER_PEER, err_str);
829 for (idx = 0; idx < num_nids; idx++) {
830 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
832 if (cmd == LNETCTL_ADD_CMD) {
833 data.cfg_config_u.cfg_route.rtr_hop = hops;
834 data.cfg_config_u.cfg_route.rtr_priority = prio;
835 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
838 data.cfg_nid = lnet_nidlist[idx];
840 if (cmd == LNETCTL_ADD_CMD)
841 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
844 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
847 if (rc != 0 && errno != EEXIST &&
848 errno != EHOSTUNREACH) {
850 snprintf(err_str, LNET_MAX_STR_LEN,
851 "route operation failed: %s",
854 } else if (errno == EEXIST) {
856 * continue chugging along if one of the
857 * routes already exists
864 cYAML_build_error(rc, seq_no,
865 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
871 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
872 int sen, int seq_no, struct cYAML **err_rc)
875 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
878 hops = LNET_UNDEFINED_HOPS;
879 } else if (hops < 1 || hops > 255) {
880 snprintf(err_str, LNET_MAX_STR_LEN,
881 "\"invalid hop count %d, must be between 1 and 255\"",
883 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
889 } else if (prio < 0) {
890 snprintf(err_str, LNET_MAX_STR_LEN,
891 "\"invalid priority %d, must be greater than 0\"",
893 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
899 } else if (sen < 1) {
900 snprintf(err_str, LNET_MAX_STR_LEN,
901 "\"invalid health sensitivity %d, must be 1 or greater\"",
903 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
907 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
908 err_rc, LNETCTL_ADD_CMD);
911 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
916 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
917 struct cYAML **err_rc)
919 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
923 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
924 int seq_no, struct cYAML **show_rc,
925 struct cYAML **err_rc, bool backup)
927 struct lnet_ioctl_config_data data;
928 lnet_nid_t gateway_nid;
929 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
931 __u32 net = LNET_NET_ANY;
933 struct cYAML *root = NULL, *route = NULL, *item = NULL;
934 struct cYAML *first_seq = NULL;
935 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
939 net = libcfs_str2net(nw);
940 if (net == LNET_NET_ANY) {
943 "\"cannot parse net '%s'\"", nw);
944 rc = LUSTRE_CFG_RC_BAD_PARAM;
949 /* show all routes without filtering on net */
954 gateway_nid = libcfs_str2nid(gw);
955 if (gateway_nid == LNET_NID_ANY) {
958 "\"cannot parse gateway NID '%s'\"", gw);
959 rc = LUSTRE_CFG_RC_BAD_PARAM;
963 /* show all routes with out filtering on gateway */
964 gateway_nid = LNET_NID_ANY;
966 if ((hops < 1 && hops != -1) || hops > 255) {
969 "\"invalid hop count %d, must be between 0 and 256\"",
971 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
975 /* create struct cYAML root object */
976 root = cYAML_create_object(NULL, NULL);
980 route = cYAML_create_seq(root, "route");
988 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
991 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
997 /* filter on provided data */
998 if (net != LNET_NET_ANY &&
1002 if (gateway_nid != LNET_NID_ANY &&
1003 gateway_nid != data.cfg_nid)
1007 hops != data.cfg_config_u.cfg_route.rtr_hop)
1011 prio != data.cfg_config_u.cfg_route.rtr_priority)
1014 /* default rc to -1 incase we hit the goto */
1018 item = cYAML_create_seq_item(route);
1022 if (first_seq == NULL)
1025 if (cYAML_create_string(item, "net",
1026 libcfs_net2str(data.cfg_net)) == NULL)
1029 if (cYAML_create_string(item, "gateway",
1030 libcfs_nid2str(data.cfg_nid)) == NULL)
1034 if (cYAML_create_number(item, "hop",
1035 (int) data.cfg_config_u.
1036 cfg_route.rtr_hop) ==
1040 if (cYAML_create_number(item, "priority",
1042 cfg_route.rtr_priority) == NULL)
1045 if (cYAML_create_number(item, "health_sensitivity",
1047 cfg_route.rtr_sensitivity) == NULL)
1050 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1052 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1056 cYAML_create_string(item, "state",
1058 "up" : "down") == NULL)
1062 cYAML_create_string(item, "type",
1064 "multi-hop" : "single-hop") == NULL)
1069 /* print output iff show_rc is not provided */
1070 if (show_rc == NULL)
1071 cYAML_print_tree(root);
1073 if (l_errno != ENOENT) {
1076 "\"cannot get routes: %s\"",
1081 rc = LUSTRE_CFG_RC_NO_ERR;
1083 snprintf(err_str, sizeof(err_str), "\"success\"");
1085 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1086 cYAML_free_tree(root);
1087 } else if (show_rc != NULL && *show_rc != NULL) {
1088 struct cYAML *show_node;
1089 /* find the route node, if one doesn't exist then
1090 * insert one. Otherwise add to the one there
1092 show_node = cYAML_get_object_item(*show_rc, "route");
1093 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1094 cYAML_insert_child(show_node, first_seq);
1097 } else if (show_node == NULL) {
1098 cYAML_insert_sibling((*show_rc)->cy_child,
1102 cYAML_free_tree(root);
1108 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1113 static int socket_intf_query(int request, char *intf,
1119 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1120 return LUSTRE_CFG_RC_BAD_PARAM;
1122 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1124 return LUSTRE_CFG_RC_BAD_PARAM;
1126 strcpy(ifr->ifr_name, intf);
1127 rc = ioctl(sockfd, request, ifr);
1129 rc = LUSTRE_CFG_RC_BAD_PARAM;
1136 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1141 memset(&ifr, 0, sizeof(ifr));
1142 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1144 return LUSTRE_CFG_RC_BAD_PARAM;
1146 if ((ifr.ifr_flags & IFF_UP) == 0)
1147 return LUSTRE_CFG_RC_BAD_PARAM;
1149 memset(&ifr, 0, sizeof(ifr));
1150 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1152 return LUSTRE_CFG_RC_BAD_PARAM;
1154 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1155 *ip = bswap_32(*ip);
1157 return LUSTRE_CFG_RC_NO_ERR;
1160 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1163 unsigned int nic_index;
1165 char *nic_addr_path;
1170 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1172 return LUSTRE_CFG_RC_NO_MATCH;
1174 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1175 nic_addr_path = malloc(size);
1177 return LUSTRE_CFG_RC_OUT_OF_MEM;
1178 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1180 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1181 free(nic_addr_path);
1183 return LUSTRE_CFG_RC_NO_MATCH;
1185 addr = strtol(val, NULL, 16);
1186 if (addr == LONG_MIN || addr == LONG_MAX)
1187 return LUSTRE_CFG_RC_NO_MATCH;
1191 return LUSTRE_CFG_RC_NO_ERR;
1195 * for each interface in the array of interfaces find the IP address of
1196 * that interface, create its nid and add it to an array of NIDs.
1197 * Stop if any of the interfaces is down
1199 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1200 lnet_nid_t **nids, __u32 *nnids,
1201 char *err_str, size_t str_len)
1203 int i = 0, count = 0, rc;
1204 struct lnet_dlc_intf_descr *intf;
1205 char val[LNET_MAX_STR_LEN];
1213 if (nw == NULL || nids == NULL) {
1214 snprintf(err_str, str_len,
1215 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1216 return LUSTRE_CFG_RC_BAD_PARAM;
1219 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1222 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1226 *nids = calloc(count, sizeof(lnet_nid_t));
1227 if (*nids == NULL) {
1228 snprintf(err_str, str_len,
1229 "\"out of memory\"");
1230 return LUSTRE_CFG_RC_OUT_OF_MEM;
1233 * special case the GNI interface since it doesn't have an IP
1234 * address. The assumption is that there can only be one GNI
1235 * interface in the system. No interface name is provided.
1237 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1238 rc = read_sysfs_file(gni_nid_path, "nid", val,
1241 snprintf(err_str, str_len,
1242 "\"cannot read gni nid\"");
1245 gni_num = atoi(val);
1247 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1250 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1251 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1252 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1253 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1254 snprintf(err_str, str_len,
1255 "\"couldn't query kfi intf %s\"",
1257 err_str[str_len - 1] = '\0';
1261 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1267 /* look at the other interfaces */
1268 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1269 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1270 /* handle LNDs with numeric interface name */
1271 num = strtoul(intf->intf_name, &endp, 0);
1272 if (endp == intf->intf_name || *endp != '\0') {
1273 rc = LUSTRE_CFG_RC_BAD_PARAM;
1274 snprintf(err_str, str_len,
1275 "\"couldn't query intf %s\"",
1279 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1282 /* handle LNDs with ip interface name */
1283 rc = lustre_lnet_queryip(intf, &ip);
1284 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1285 snprintf(err_str, str_len,
1286 "\"couldn't query intf %s\"",
1290 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1307 * called repeatedly until a match or no more ip range
1309 * ip_range expression
1310 * interface list with all the interface names.
1311 * all the interfaces in the system.
1313 * try to match the ip_range expr to one of the interfaces' IPs in
1314 * the system. If we hit a patch for an interface. Check if that
1315 * interface name is in the list.
1317 * If there are more than one interface in the list, then make sure
1318 * that the IPs for all of these interfaces match the ip ranges
1321 * for each interface in intf_list
1322 * look up the intf name in ifa
1323 * if not there then no match
1324 * check ip obtained from ifa against a match to any of the
1326 * If no match, then fail
1328 * The result is that all the interfaces have to match.
1330 static int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1331 struct list_head *intf_list,
1332 struct list_head *ip_ranges)
1336 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1337 struct ifaddrs *ifaddr = ifa;
1338 struct lustre_lnet_ip_range_descr *ip_range;
1342 * if there are no explicit interfaces, and no ip ranges, then
1343 * configure the first tcp interface we encounter.
1345 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1346 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1347 if (ifaddr->ifa_addr == NULL)
1350 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1353 family = ifaddr->ifa_addr->sa_family;
1354 if (family == AF_INET &&
1355 strcmp(ifaddr->ifa_name, "lo") != 0) {
1356 rc = lustre_lnet_add_intf_descr
1357 (intf_list, ifaddr->ifa_name,
1358 strlen(ifaddr->ifa_name));
1360 if (rc != LUSTRE_CFG_RC_NO_ERR)
1363 return LUSTRE_CFG_RC_MATCH;
1366 return LUSTRE_CFG_RC_NO_MATCH;
1370 * First interface which matches an IP pattern will be used
1372 if (list_empty(intf_list)) {
1374 * no interfaces provided in the rule, but an ip range is
1375 * provided, so try and match an interface to the ip
1378 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1379 if (ifaddr->ifa_addr == NULL)
1382 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1385 family = ifaddr->ifa_addr->sa_family;
1386 if (family == AF_INET) {
1387 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1390 list_for_each_entry(ip_range, ip_ranges,
1392 rc = cfs_ip_addr_match(bswap_32(ip),
1393 &ip_range->ipr_expr);
1397 rc = lustre_lnet_add_intf_descr
1398 (intf_list, ifaddr->ifa_name,
1399 strlen(ifaddr->ifa_name));
1401 if (rc != LUSTRE_CFG_RC_NO_ERR)
1407 if (!list_empty(intf_list))
1408 return LUSTRE_CFG_RC_MATCH;
1410 return LUSTRE_CFG_RC_NO_MATCH;
1414 * If an interface is explicitly specified the ip-range might or
1415 * might not be specified. if specified the interface needs to match the
1416 * ip-range. If no ip-range then the interfaces are
1417 * automatically matched if they are all up.
1418 * If > 1 interfaces all the interfaces must match for the NI to
1421 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1422 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1423 if (ifaddr->ifa_addr == NULL)
1426 family = ifaddr->ifa_addr->sa_family;
1427 if (family == AF_INET &&
1428 strcmp(intf_descr->intf_name,
1429 ifaddr->ifa_name) == 0)
1433 if (ifaddr == NULL) {
1434 list_del(&intf_descr->intf_on_network);
1435 free_intf_descr(intf_descr);
1439 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1440 list_del(&intf_descr->intf_on_network);
1441 free_intf_descr(intf_descr);
1445 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1448 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1449 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1455 /* no match for this interface */
1456 list_del(&intf_descr->intf_on_network);
1457 free_intf_descr(intf_descr);
1461 return LUSTRE_CFG_RC_MATCH;
1464 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1465 lnet_nid_t **nids, __u32 *nnids,
1466 char *err_str, size_t str_len)
1468 struct ifaddrs *ifa;
1469 int rc = LUSTRE_CFG_RC_NO_ERR;
1471 rc = getifaddrs(&ifa);
1473 snprintf(err_str, str_len,
1474 "\"failed to get interface addresses: %d\"", -errno);
1478 rc = lustre_lnet_match_ip_to_intf(ifa,
1479 &ip2nets->ip2nets_net.nw_intflist,
1480 &ip2nets->ip2nets_ip_ranges);
1481 if (rc != LUSTRE_CFG_RC_MATCH) {
1482 snprintf(err_str, str_len,
1483 "\"couldn't match ip to existing interfaces\"");
1488 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1490 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1501 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1502 struct lnet_ioctl_config_lnd_tunables *tunables,
1503 struct cfs_expr_list *global_cpts,
1504 lnet_nid_t *nids, char *err_str)
1507 struct lnet_ioctl_config_ni *conf;
1508 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1509 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1512 struct lnet_dlc_intf_descr *intf_descr;
1514 struct cfs_expr_list *cpt_expr;
1516 list_for_each_entry(intf_descr, intf_list,
1518 if (tunables != NULL)
1519 len = sizeof(struct lnet_ioctl_config_ni) +
1520 sizeof(struct lnet_ioctl_config_lnd_tunables);
1522 len = sizeof(struct lnet_ioctl_config_ni);
1524 data = calloc(1, len);
1526 return LUSTRE_CFG_RC_OUT_OF_MEM;
1527 conf = (struct lnet_ioctl_config_ni*) data;
1528 if (tunables != NULL)
1529 tun = (struct lnet_ioctl_config_lnd_tunables*)
1532 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1533 conf->lic_cfg_hdr.ioc_len = len;
1534 conf->lic_nid = nids[i];
1535 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1538 if (intf_descr->cpt_expr != NULL)
1539 cpt_expr = intf_descr->cpt_expr;
1540 else if (global_cpts != NULL)
1541 cpt_expr = global_cpts;
1545 if (cpt_expr != NULL) {
1546 count = cfs_expr_list_values(cpt_expr,
1547 LNET_MAX_SHOW_NUM_CPT,
1550 memcpy(conf->lic_cpts, cpt_array,
1551 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1560 conf->lic_ncpts = count;
1562 if (tunables != NULL)
1563 memcpy(tun, tunables, sizeof(*tunables));
1565 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1570 "\"cannot add network: %s\"", strerror(errno));
1578 return LUSTRE_CFG_RC_NO_ERR;
1582 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1583 struct lnet_ioctl_config_lnd_tunables *tunables,
1584 struct cfs_expr_list *global_cpts,
1585 int seq_no, struct cYAML **err_rc)
1587 lnet_nid_t *nids = NULL;
1590 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1595 "\"incomplete ip2nets information\"");
1596 rc = LUSTRE_CFG_RC_BAD_PARAM;
1601 * call below function to resolve the rules into a list of nids.
1602 * The memory is allocated in that function then freed here when
1603 * it's no longer needed.
1605 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1607 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1610 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1611 snprintf(err_str, sizeof(err_str),
1612 "\"no interfaces match ip2nets rules\"");
1616 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1617 tunables, global_cpts, nids,
1624 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1628 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1629 struct cfs_expr_list *global_cpts,
1631 struct lnet_ioctl_config_lnd_tunables *tunables,
1632 int seq_no, struct cYAML **err_rc)
1635 struct lnet_ioctl_config_ni *conf;
1636 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1637 char buf[LNET_MAX_STR_LEN];
1638 int rc = LUSTRE_CFG_RC_NO_ERR;
1639 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1640 lnet_nid_t *nids = NULL;
1644 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1647 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1648 (list_empty(&nw_descr->nw_intflist) &&
1649 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1652 "\"missing mandatory parameters in NI config: '%s'\"",
1653 (nw_descr == NULL) ? "network , interface" :
1654 (nw_descr->nw_id == 0) ? "network" : "interface");
1655 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1659 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1662 "\"ip2net string too long %d\"",
1663 (int)strlen(ip2net));
1664 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1668 if (ip2net != NULL) {
1669 if (tunables != NULL)
1670 len = sizeof(struct lnet_ioctl_config_ni) +
1671 sizeof(struct lnet_ioctl_config_lnd_tunables);
1673 len = sizeof(struct lnet_ioctl_config_ni);
1674 data = calloc(1, len);
1676 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1679 conf = (struct lnet_ioctl_config_ni*) data;
1680 if (tunables != NULL)
1681 tun = (struct lnet_ioctl_config_lnd_tunables*)
1682 (data + sizeof(*conf));
1684 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1685 conf->lic_cfg_hdr.ioc_len = len;
1686 strncpy(conf->lic_legacy_ip2nets, ip2net,
1689 if (global_cpts != NULL) {
1690 count = cfs_expr_list_values(global_cpts,
1691 LNET_MAX_SHOW_NUM_CPT,
1694 memcpy(conf->lic_cpts, cpt_array,
1695 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1704 conf->lic_ncpts = count;
1706 if (tunables != NULL)
1707 memcpy(tun, tunables, sizeof(*tunables));
1709 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1714 "\"cannot add network: %s\"", strerror(errno));
1721 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1722 rc = LUSTRE_CFG_RC_NO_ERR;
1726 if (nw_descr->nw_id == LNET_NET_ANY) {
1729 "\"cannot parse net '%s'\"",
1730 libcfs_net2str(nw_descr->nw_id));
1731 rc = LUSTRE_CFG_RC_BAD_PARAM;
1736 * special case the GNI since no interface name is expected
1738 if (list_empty(&nw_descr->nw_intflist) &&
1739 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1742 "\"no interface name provided\"");
1743 rc = LUSTRE_CFG_RC_BAD_PARAM;
1747 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1748 err_str, sizeof(err_str));
1750 rc = LUSTRE_CFG_RC_BAD_PARAM;
1754 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1755 tunables, global_cpts, nids,
1759 if (nw_descr != NULL) {
1760 list_for_each_entry_safe(intf_descr, tmp,
1761 &nw_descr->nw_intflist,
1763 list_del(&intf_descr->intf_on_network);
1764 free_intf_descr(intf_descr);
1768 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1779 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1780 int seq_no, struct cYAML **err_rc)
1782 struct lnet_ioctl_config_ni data;
1783 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1784 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1785 lnet_nid_t *nids = NULL;
1787 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1789 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1792 "\"missing mandatory parameter in deleting NI: '%s'\"",
1793 (nw_descr == NULL) ? "network , interface" :
1794 (nw_descr->nw_id == 0) ? "network" : "interface");
1795 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1799 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1800 return LUSTRE_CFG_RC_NO_ERR;
1802 if (nw_descr->nw_id == LNET_NET_ANY) {
1805 "\"cannot parse net '%s'\"",
1806 libcfs_net2str(nw_descr->nw_id));
1807 rc = LUSTRE_CFG_RC_BAD_PARAM;
1811 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1812 err_str, sizeof(err_str));
1814 rc = LUSTRE_CFG_RC_BAD_PARAM;
1819 * no interfaces just the nw_id is specified
1822 nids = calloc(1, sizeof(*nids));
1824 snprintf(err_str, sizeof(err_str),
1825 "\"out of memory\"");
1826 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1829 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1833 for (i = 0; i < nnids; i++) {
1834 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1835 data.lic_nid = nids[i];
1837 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1842 "\"cannot del network: %s\"", strerror(errno));
1846 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1848 list_del(&intf_descr->intf_on_network);
1849 free_intf_descr(intf_descr);
1853 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1862 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1863 enum lnet_health_type type, char *name,
1864 int seq_no, struct cYAML **err_rc)
1866 struct lnet_ioctl_reset_health_cfg data;
1867 int rc = LUSTRE_CFG_RC_NO_ERR;
1868 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1870 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1871 data.rh_type = type;
1873 data.rh_value = value;
1876 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1880 sizeof(err_str), "Can not configure health value: %s",
1884 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1890 lustre_lnet_config_peer(int state, lnet_nid_t nid, char *name,
1891 int seq_no, struct cYAML **err_rc)
1893 struct lnet_ioctl_peer_cfg data;
1894 int rc = LUSTRE_CFG_RC_NO_ERR;
1895 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1897 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
1898 data.prcfg_state = state;
1899 data.prcfg_prim_nid = nid;
1900 data.prcfg_cfg_nid = LNET_NID_ANY;
1902 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_PEER, &data);
1906 sizeof(err_str), "Can not set peer property: %s",
1910 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1916 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1917 char *name, int seq_no,
1918 struct cYAML **err_rc)
1920 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1921 int rc = LUSTRE_CFG_RC_NO_ERR;
1922 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1924 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1925 data.rcpp_all = all;
1926 data.rcpp_value = value;
1927 data.rcpp_nid = nid;
1929 if (value < 0 || value > 127) {
1930 rc = LUSTRE_CFG_RC_BAD_PARAM;
1931 snprintf(err_str, sizeof(err_str),
1932 "\"Valid values are: 0-127\"");
1935 rc = l_ioctl(LNET_DEV_ID,
1936 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1941 "Can not configure conns_per_peer value: %s",
1945 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1950 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1951 struct cYAML **err_rc)
1955 nid = libcfs_str2nid(ni_nid);
1958 return lustre_lnet_config_healthv(value, all, nid,
1959 LNET_HEALTH_TYPE_LOCAL_NI,
1960 "ni healthv", seq_no, err_rc);
1963 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1964 int seq_no, struct cYAML **err_rc)
1968 nid = libcfs_str2nid(lpni_nid);
1971 return lustre_lnet_config_healthv(value, all, nid,
1972 LNET_HEALTH_TYPE_PEER_NI,
1973 "peer_ni healthv", seq_no, err_rc);
1976 int lustre_lnet_set_peer_state(int state, char *lpni_nid, int seq_no,
1977 struct cYAML **err_rc)
1982 nid = libcfs_str2nid(lpni_nid);
1985 return lustre_lnet_config_peer(state, nid, "peer state", seq_no,
1989 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1990 int seq_no, struct cYAML **err_rc)
1995 nid = libcfs_str2nid(ni_nid);
1998 return lustre_lnet_config_conns_per_peer(value, all, nid,
1999 "ni conns_per_peer",
2004 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2005 struct lnet_ioctl_comm_count *counts)
2007 if (cYAML_create_number(yaml, "put",
2008 counts->ico_put_count)
2011 if (cYAML_create_number(yaml, "get",
2012 counts->ico_get_count)
2015 if (cYAML_create_number(yaml, "reply",
2016 counts->ico_reply_count)
2019 if (cYAML_create_number(yaml, "ack",
2020 counts->ico_ack_count)
2023 if (cYAML_create_number(yaml, "hello",
2024 counts->ico_hello_count)
2031 static struct lnet_ioctl_comm_count *
2032 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2035 return &msg_stats->im_send_stats;
2037 return &msg_stats->im_recv_stats;
2039 return &msg_stats->im_drop_stats;
2045 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2046 struct cYAML *net_node)
2048 char tmp[LNET_MAX_STR_LEN];
2049 struct cYAML *udsp_net;
2050 bool created = false;
2054 /* add the UDSP info */
2055 udsp_net = cYAML_create_object(net_node, "udsp info");
2057 return LUSTRE_CFG_RC_OUT_OF_MEM;
2059 if (!cYAML_create_number(udsp_net, "net priority",
2060 (int) udsp_info->cud_net_priority))
2061 return LUSTRE_CFG_RC_OUT_OF_MEM;
2063 if (!cYAML_create_number(udsp_net, "nid priority",
2064 (int)udsp_info->cud_nid_priority))
2065 return LUSTRE_CFG_RC_OUT_OF_MEM;
2069 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2070 memset(tmp, 0, LNET_MAX_STR_LEN);
2071 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2074 pref = cYAML_create_object(udsp_net,
2075 "Preferred gateway NIDs");
2077 return LUSTRE_CFG_RC_OUT_OF_MEM;
2080 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2081 if (!cYAML_create_string(pref, tmp,
2082 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2083 return LUSTRE_CFG_RC_OUT_OF_MEM;
2086 return LUSTRE_CFG_RC_NO_ERR;
2090 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2091 struct cYAML *nid_node)
2093 char tmp[LNET_MAX_STR_LEN];
2094 struct cYAML *udsp_nid;
2095 bool created = false;
2099 /* add the UDSP info */
2100 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2102 return LUSTRE_CFG_RC_OUT_OF_MEM;
2104 if (!cYAML_create_number(udsp_nid, "net priority",
2105 (int) udsp_info->cud_net_priority))
2106 return LUSTRE_CFG_RC_OUT_OF_MEM;
2108 if (!cYAML_create_number(udsp_nid, "nid priority",
2109 (int) udsp_info->cud_nid_priority))
2110 return LUSTRE_CFG_RC_OUT_OF_MEM;
2113 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2114 memset(tmp, 0, LNET_MAX_STR_LEN);
2115 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2118 pref = cYAML_create_object(udsp_nid,
2119 "Preferred gateway NIDs");
2121 return LUSTRE_CFG_RC_OUT_OF_MEM;
2124 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2125 if (!cYAML_create_string(pref, tmp,
2126 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2127 return LUSTRE_CFG_RC_OUT_OF_MEM;
2132 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2133 memset(tmp, 0, LNET_MAX_STR_LEN);
2134 if (udsp_info->cud_pref_nid[i] == 0)
2137 pref = cYAML_create_object(udsp_nid,
2138 "Preferred source NIDs");
2140 return LUSTRE_CFG_RC_OUT_OF_MEM;
2143 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2144 if (!cYAML_create_string(pref, tmp,
2145 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2146 return LUSTRE_CFG_RC_OUT_OF_MEM;
2149 return LUSTRE_CFG_RC_NO_ERR;
2152 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2153 struct cYAML **show_rc, struct cYAML **err_rc,
2157 struct lnet_ioctl_config_ni *ni_data;
2158 struct lnet_ioctl_config_lnd_tunables *lnd;
2159 struct lnet_ioctl_element_stats *stats;
2160 struct lnet_ioctl_element_msg_stats msg_stats;
2161 struct lnet_ioctl_local_ni_hstats hstats;
2162 struct lnet_ioctl_construct_udsp_info udsp_info;
2163 __u32 net = LNET_NET_ANY;
2164 __u32 prev_net = LNET_NET_ANY;
2165 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2167 struct cYAML *root = NULL, *tunables = NULL,
2168 *net_node = NULL, *interfaces = NULL,
2169 *item = NULL, *first_seq = NULL,
2170 *tmp = NULL, *statistics = NULL,
2172 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2173 char str_buf[str_buf_len];
2175 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2176 bool exist = false, new_net = true;
2178 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2180 buf = calloc(1, buf_size);
2184 ni_data = (struct lnet_ioctl_config_ni *)buf;
2187 net = libcfs_str2net(nw);
2188 if (net == LNET_NET_ANY) {
2191 "\"cannot parse net '%s'\"", nw);
2192 rc = LUSTRE_CFG_RC_BAD_PARAM;
2197 root = cYAML_create_object(NULL, NULL);
2201 net_node = cYAML_create_seq(root, "net");
2202 if (net_node == NULL)
2208 memset(buf, 0, buf_size);
2210 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2212 * set the ioc_len to the proper value since INIT assumes
2215 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2216 ni_data->lic_idx = i;
2218 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2224 rc_net = LNET_NIDNET(ni_data->lic_nid);
2226 /* filter on provided data */
2227 if (net != LNET_NET_ANY &&
2231 /* if we're backing up don't store lo */
2232 if (backup && LNET_NETTYP(rc_net) == LOLND)
2235 /* default rc to -1 in case we hit the goto */
2239 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2240 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2241 (ni_data->lic_bulk + sizeof(*stats));
2243 if (rc_net != prev_net) {
2250 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2254 if (first_seq == NULL)
2257 tmp = cYAML_create_seq(net_node, "local NI(s)");
2263 /* create the tree to be printed. */
2264 item = cYAML_create_seq_item(tmp);
2269 cYAML_create_string(item, "nid",
2270 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2274 cYAML_create_string(item,
2276 (ni_data->lic_status ==
2277 LNET_NI_STATUS_UP) ?
2278 "up" : "down") == NULL)
2281 /* don't add interfaces unless there is at least one
2283 if (strlen(ni_data->lic_ni_intf) > 0) {
2284 interfaces = cYAML_create_object(item, "interfaces");
2285 if (interfaces == NULL)
2288 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2289 if (cYAML_create_string(interfaces, str_buf,
2290 ni_data->lic_ni_intf) == NULL)
2299 goto continue_without_msg_stats;
2301 statistics = cYAML_create_object(item, "statistics");
2302 if (statistics == NULL)
2305 if (cYAML_create_number(statistics, "send_count",
2306 stats->iel_send_count)
2310 if (cYAML_create_number(statistics, "recv_count",
2311 stats->iel_recv_count)
2315 if (cYAML_create_number(statistics, "drop_count",
2316 stats->iel_drop_count)
2321 goto continue_without_udsp_info;
2323 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2324 udsp_info.cud_nid = ni_data->lic_nid;
2325 udsp_info.cud_peer = false;
2326 rc = l_ioctl(LNET_DEV_ID,
2327 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2331 goto continue_without_udsp_info;
2334 rc = create_local_udsp_info(&udsp_info, item);
2340 continue_without_udsp_info:
2342 goto continue_without_msg_stats;
2344 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2345 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2346 msg_stats.im_idx = i;
2348 rc = l_ioctl(LNET_DEV_ID,
2349 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2353 goto continue_without_msg_stats;
2356 for (k = 0; k < 3; k++) {
2357 struct lnet_ioctl_comm_count *counts;
2358 struct cYAML *msg_statistics = NULL;
2360 msg_statistics = cYAML_create_object(item,
2361 (char *)gmsg_stat_names[k]);
2362 if (msg_statistics == NULL)
2365 counts = get_counts(&msg_stats, k);
2369 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2374 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2375 hstats.hlni_nid = ni_data->lic_nid;
2376 /* grab health stats */
2377 rc = l_ioctl(LNET_DEV_ID,
2378 IOC_LIBCFS_GET_LOCAL_HSTATS,
2382 goto continue_without_msg_stats;
2384 yhstats = cYAML_create_object(item, "health stats");
2387 if (cYAML_create_number(yhstats, "fatal_error",
2388 hstats.hlni_fatal_error)
2391 if (cYAML_create_number(yhstats, "health value",
2392 hstats.hlni_health_value)
2395 if (cYAML_create_number(yhstats, "interrupts",
2396 hstats.hlni_local_interrupt)
2399 if (cYAML_create_number(yhstats, "dropped",
2400 hstats.hlni_local_dropped)
2403 if (cYAML_create_number(yhstats, "aborted",
2404 hstats.hlni_local_aborted)
2407 if (cYAML_create_number(yhstats, "no route",
2408 hstats.hlni_local_no_route)
2411 if (cYAML_create_number(yhstats, "timeouts",
2412 hstats.hlni_local_timeout)
2415 if (cYAML_create_number(yhstats, "error",
2416 hstats.hlni_local_error)
2419 if (cYAML_create_number(yhstats, "ping_count",
2420 hstats.hlni_ping_count)
2423 if (cYAML_create_number(yhstats, "next_ping",
2424 hstats.hlni_next_ping)
2428 continue_without_msg_stats:
2429 tunables = cYAML_create_object(item, "tunables");
2433 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2434 if (rc != LUSTRE_CFG_RC_NO_ERR)
2437 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2438 tunables = cYAML_create_object(item,
2440 if (tunables == NULL)
2444 rc = lustre_ni_show_tunables(tunables,
2445 LNET_NETTYP(rc_net),
2446 &lnd->lt_tun, backup);
2447 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2448 rc != LUSTRE_CFG_RC_NO_MATCH)
2452 cYAML_create_number(item, "dev cpt",
2453 ni_data->lic_dev_cpt) == NULL)
2456 /* out put the CPTs in the format: "[x,x,x,...]" */
2458 limit = str_buf + str_buf_len - 3;
2459 pos += scnprintf(pos, limit - pos, "\"[");
2460 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2461 j < ni_data->lic_ncpts &&
2463 pos += scnprintf(pos, limit - pos,
2464 "%d", ni_data->lic_cpts[j]);
2465 if ((j + 1) < ni_data->lic_ncpts)
2466 pos += scnprintf(pos, limit - pos, ",");
2468 snprintf(pos, 3, "]\"");
2470 if (ni_data->lic_ncpts >= 1 &&
2471 cYAML_create_string(item, "CPT",
2477 /* Print out the net information only if show_rc is not provided */
2478 if (show_rc == NULL)
2479 cYAML_print_tree(root);
2481 if (l_errno != ENOENT) {
2484 "\"cannot get networks: %s\"",
2489 rc = LUSTRE_CFG_RC_NO_ERR;
2491 snprintf(err_str, sizeof(err_str), "\"success\"");
2493 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2494 cYAML_free_tree(root);
2495 } else if (show_rc != NULL && *show_rc != NULL) {
2496 struct cYAML *show_node;
2497 /* find the net node, if one doesn't exist
2498 * then insert one. Otherwise add to the one there
2500 show_node = cYAML_get_object_item(*show_rc, "net");
2501 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2502 cYAML_insert_child(show_node, first_seq);
2505 } else if (show_node == NULL) {
2506 cYAML_insert_sibling((*show_rc)->cy_child,
2510 cYAML_free_tree(root);
2516 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2521 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2523 struct lnet_ioctl_config_data data;
2524 int rc = LUSTRE_CFG_RC_NO_ERR;
2525 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2527 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2528 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2530 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2535 "\"cannot %s routing %s\"",
2536 (enable) ? "enable" : "disable", strerror(errno));
2541 cYAML_build_error(rc, seq_no,
2542 (enable) ? ADD_CMD : DEL_CMD,
2543 "routing", err_str, err_rc);
2548 static int ioctl_set_value(__u32 val, int ioc, char *name,
2549 int seq_no, struct cYAML **err_rc)
2551 struct lnet_ioctl_set_value data;
2552 int rc = LUSTRE_CFG_RC_NO_ERR;
2553 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2555 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2556 data.sv_value = val;
2558 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2563 "\"cannot configure %s to %d: %s\"", name,
2564 val, strerror(errno));
2567 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2572 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2574 int rc = LUSTRE_CFG_RC_NO_ERR;
2575 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2576 char val[LNET_MAX_STR_LEN];
2578 snprintf(val, sizeof(val), "%d", intrv);
2580 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2581 1, strlen(val) + 1);
2583 snprintf(err_str, sizeof(err_str),
2584 "\"cannot configure recovery interval: %s\"",
2587 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2592 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2594 int rc = LUSTRE_CFG_RC_NO_ERR;
2595 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2596 char val[LNET_MAX_STR_LEN];
2598 snprintf(val, sizeof(val), "%d", sen);
2600 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2601 1, strlen(val) + 1);
2603 snprintf(err_str, sizeof(err_str),
2604 "\"cannot configure router health sensitivity: %s\"",
2607 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2612 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2614 int rc = LUSTRE_CFG_RC_NO_ERR;
2615 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2616 char val[LNET_MAX_STR_LEN];
2618 snprintf(val, sizeof(val), "%d", sen);
2620 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2621 1, strlen(val) + 1);
2623 snprintf(err_str, sizeof(err_str),
2624 "\"cannot configure health sensitivity: %s\"",
2627 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2632 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2634 int rc = LUSTRE_CFG_RC_NO_ERR;
2635 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2636 char val[LNET_MAX_STR_LEN];
2638 snprintf(val, sizeof(val), "%d", timeout);
2640 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2641 1, strlen(val) + 1);
2643 snprintf(err_str, sizeof(err_str),
2644 "\"cannot configure transaction timeout: %s\"",
2647 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2652 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2654 int rc = LUSTRE_CFG_RC_NO_ERR;
2655 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2656 char val[LNET_MAX_STR_LEN];
2658 snprintf(val, sizeof(val), "%d", count);
2660 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2661 1, strlen(val) + 1);
2663 snprintf(err_str, sizeof(err_str),
2664 "\"cannot configure retry count: %s\"",
2667 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2672 int lustre_lnet_config_response_tracking(int val, int seq_no,
2673 struct cYAML **err_rc)
2675 int rc = LUSTRE_CFG_RC_NO_ERR;
2676 char err_str[LNET_MAX_STR_LEN];
2677 char val_str[LNET_MAX_STR_LEN];
2679 if (val < 0 || val > 3) {
2680 rc = LUSTRE_CFG_RC_BAD_PARAM;
2681 snprintf(err_str, sizeof(err_str),
2682 "\"Valid values are: 0, 1, 2, or 3\"");
2684 snprintf(err_str, sizeof(err_str), "\"success\"");
2686 snprintf(val_str, sizeof(val_str), "%d", val);
2688 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2689 val_str, 1, strlen(val_str) + 1);
2691 snprintf(err_str, sizeof(err_str),
2692 "\"cannot configure response tracking: %s\"",
2696 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2702 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2703 struct cYAML **err_rc)
2705 int rc = LUSTRE_CFG_RC_NO_ERR;
2706 char err_str[LNET_MAX_STR_LEN];
2707 char val_str[LNET_MAX_STR_LEN];
2710 rc = LUSTRE_CFG_RC_BAD_PARAM;
2711 snprintf(err_str, sizeof(err_str),
2712 "\"Must be greater than or equal to 0\"");
2714 snprintf(err_str, sizeof(err_str), "\"success\"");
2716 snprintf(val_str, sizeof(val_str), "%d", val);
2718 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2719 val_str, 1, strlen(val_str) + 1);
2721 snprintf(err_str, sizeof(err_str),
2722 "\"cannot configure recovery limit: %s\"",
2726 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2732 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2734 int rc = LUSTRE_CFG_RC_NO_ERR;
2735 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2736 char val[LNET_MAX_STR_LEN];
2738 snprintf(val, sizeof(val), "%d", max);
2740 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2741 1, strlen(val) + 1);
2743 snprintf(err_str, sizeof(err_str),
2744 "\"cannot configure max interfaces: %s\"",
2747 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2752 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2754 int rc = LUSTRE_CFG_RC_NO_ERR;
2755 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2756 char val[LNET_MAX_STR_LEN];
2758 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2760 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2761 1, strlen(val) + 1);
2763 snprintf(err_str, sizeof(err_str),
2764 "\"cannot configure discovery: %s\"",
2767 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2773 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2774 struct cYAML **err_rc)
2776 int rc = LUSTRE_CFG_RC_NO_ERR;
2777 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2778 char val[LNET_MAX_STR_LEN];
2780 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2782 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2783 1, strlen(val) + 1);
2785 snprintf(err_str, sizeof(err_str),
2786 "\"cannot configure drop asym route: %s\"",
2789 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2796 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2798 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2799 "numa_range", seq_no, err_rc);
2802 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2803 struct cYAML **err_rc)
2805 struct lnet_ioctl_config_data data;
2806 int rc = LUSTRE_CFG_RC_NO_ERR;
2807 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2809 /* -1 indicates to ignore changes to this field */
2810 if (tiny < -1 || small < -1 || large < -1) {
2813 "\"tiny, small and large must be >= 0\"");
2814 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2818 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2819 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2820 data.cfg_config_u.cfg_buffers.buf_small = small;
2821 data.cfg_config_u.cfg_buffers.buf_large = large;
2823 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2828 "\"cannot configure buffers: %s\"", strerror(errno));
2833 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2838 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2839 struct cYAML **err_rc)
2841 int rc = LUSTRE_CFG_RC_NO_ERR;
2842 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2843 char interval_str[LNET_MAX_STR_LEN];
2845 if (interval <= 0) {
2846 rc = LUSTRE_CFG_RC_BAD_PARAM;
2847 snprintf(err_str, sizeof(err_str),
2848 "\"must be strictly positive\"");
2851 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2853 rc = write_sysfs_file(modparam_path,
2854 "lnet_max_recovery_ping_interval",
2856 strlen(interval_str) + 1);
2858 snprintf(err_str, sizeof(err_str),
2859 "\"cannot configure maximum recovery ping interval: %s\"",
2863 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2870 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2871 struct cYAML **err_rc, bool backup)
2873 struct lnet_ioctl_config_data *data;
2874 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2875 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2878 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2879 int buf_count[LNET_NRBPOOLS] = {0};
2880 struct cYAML *root = NULL, *pools_node = NULL,
2881 *type_node = NULL, *item = NULL, *cpt = NULL,
2882 *first_seq = NULL, *buffers = NULL;
2884 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2885 char node_name[LNET_MAX_STR_LEN];
2888 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2892 data = (struct lnet_ioctl_config_data *)buf;
2894 root = cYAML_create_object(NULL, NULL);
2899 pools_node = cYAML_create_object(root, "routing");
2901 pools_node = cYAML_create_seq(root, "routing");
2902 if (pools_node == NULL)
2906 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2907 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2908 sizeof(struct lnet_ioctl_pool_cfg);
2909 data->cfg_count = i;
2911 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2919 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2922 goto calculate_buffers;
2924 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2925 item = cYAML_create_seq_item(pools_node);
2929 if (first_seq == NULL)
2932 cpt = cYAML_create_object(item, node_name);
2937 /* create the tree and print */
2938 for (j = 0; j < LNET_NRBPOOLS; j++) {
2940 type_node = cYAML_create_object(cpt, pools[j]);
2941 if (type_node == NULL)
2945 cYAML_create_number(type_node, "npages",
2946 pool_cfg->pl_pools[j].pl_npages)
2950 cYAML_create_number(type_node, "nbuffers",
2951 pool_cfg->pl_pools[j].
2952 pl_nbuffers) == NULL)
2955 cYAML_create_number(type_node, "credits",
2956 pool_cfg->pl_pools[j].
2957 pl_credits) == NULL)
2960 cYAML_create_number(type_node, "mincredits",
2961 pool_cfg->pl_pools[j].
2962 pl_mincredits) == NULL)
2964 /* keep track of the total count for each of the
2965 * tiny, small and large buffers */
2966 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2970 if (pool_cfg != NULL) {
2972 if (cYAML_create_number(pools_node, "enable",
2973 pool_cfg->pl_routing) ==
2977 goto add_buffer_section;
2980 item = cYAML_create_seq_item(pools_node);
2984 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2990 /* create a buffers entry in the show. This is necessary so that
2991 * if the YAML output is used to configure a node, the buffer
2992 * configuration takes hold */
2993 buffers = cYAML_create_object(root, "buffers");
2994 if (buffers == NULL)
2997 for (i = 0; i < LNET_NRBPOOLS; i++) {
2998 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3002 if (show_rc == NULL)
3003 cYAML_print_tree(root);
3005 if (l_errno != ENOENT) {
3008 "\"cannot get routing information: %s\"",
3013 rc = LUSTRE_CFG_RC_NO_ERR;
3015 snprintf(err_str, sizeof(err_str), "\"success\"");
3016 rc = LUSTRE_CFG_RC_NO_ERR;
3020 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3021 cYAML_free_tree(root);
3022 } else if (show_rc != NULL && *show_rc != NULL) {
3023 struct cYAML *routing_node;
3024 /* there should exist only one routing block and one
3025 * buffers block. If there already exists a previous one
3026 * then don't add another */
3027 routing_node = cYAML_get_object_item(*show_rc, "routing");
3028 if (routing_node == NULL) {
3029 cYAML_insert_sibling((*show_rc)->cy_child,
3033 cYAML_free_tree(root);
3039 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3044 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3045 struct cYAML **show_rc, struct cYAML **err_rc,
3049 * TODO: This function is changing in a future patch to accommodate
3050 * PEER_LIST and proper filtering on any nid of the peer
3052 struct lnet_ioctl_peer_cfg peer_info;
3053 struct lnet_peer_ni_credit_info *lpni_cri;
3054 struct lnet_ioctl_element_stats *lpni_stats;
3055 struct lnet_ioctl_element_msg_stats *msg_stats;
3056 struct lnet_ioctl_peer_ni_hstats *hstats;
3057 struct lnet_ioctl_construct_udsp_info udsp_info;
3059 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3064 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3065 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3066 *msg_statistics = NULL, *statistics = NULL,
3068 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3069 struct lnet_process_id *list = NULL;
3074 /* create struct cYAML root object */
3075 root = cYAML_create_object(NULL, NULL);
3079 peer_root = cYAML_create_seq(root, "peer");
3080 if (peer_root == NULL)
3084 size = count * sizeof(struct lnet_process_id);
3085 list = malloc(size);
3091 list[0].nid = libcfs_str2nid(knid);
3095 memset(&peer_info, 0, sizeof(peer_info));
3096 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3097 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3098 peer_info.prcfg_size = size;
3099 peer_info.prcfg_bulk = list;
3102 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3104 count = peer_info.prcfg_count;
3108 if (l_errno != E2BIG) {
3111 "\"cannot get peer list: %s\"",
3117 size = peer_info.prcfg_size;
3118 list = malloc(size);
3127 data = malloc(size);
3133 for (i = 0; i < count; i++) {
3135 memset(&peer_info, 0, sizeof(peer_info));
3136 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3137 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3138 peer_info.prcfg_prim_nid = list[i].nid;
3139 peer_info.prcfg_size = size;
3140 peer_info.prcfg_bulk = data;
3143 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3148 if (l_errno != E2BIG) {
3151 "\"cannot get peer information: %s\"",
3157 size = peer_info.prcfg_size;
3158 data = malloc(size);
3166 peer = cYAML_create_seq_item(peer_root);
3170 if (first_seq == NULL)
3173 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3174 if (cYAML_create_string(peer, "primary nid",
3175 libcfs_nid2str(pnid))
3178 if (cYAML_create_string(peer, "Multi-Rail",
3179 peer_info.prcfg_mr ? "True" : "False")
3183 * print out the state of the peer only if details are
3188 cYAML_create_number(peer, "peer state",
3189 peer_info.prcfg_state)
3194 tmp = cYAML_create_seq(peer, "peer ni");
3199 for (j = 0; j < peer_info.prcfg_count; j++) {
3201 lpni_cri = (void*)nidp + sizeof(nidp);
3202 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3203 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3204 hstats = (void *)msg_stats + sizeof(*msg_stats);
3205 lpni_data = (void *)hstats + sizeof(*hstats);
3207 peer_ni = cYAML_create_seq_item(tmp);
3208 if (peer_ni == NULL)
3211 if (cYAML_create_string(peer_ni, "nid",
3212 libcfs_nid2str(*nidp))
3220 goto continue_without_udsp_info;
3222 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3223 udsp_info.cud_nid = *nidp;
3224 udsp_info.cud_peer = true;
3225 rc = l_ioctl(LNET_DEV_ID,
3226 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3230 goto continue_without_udsp_info;
3233 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3239 continue_without_udsp_info:
3240 if (cYAML_create_string(peer_ni, "state",
3241 lpni_cri->cr_aliveness)
3248 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3249 lpni_cri->cr_ni_peer_tx_credits)
3253 if (cYAML_create_number(peer_ni, "available_tx_credits",
3254 lpni_cri->cr_peer_tx_credits)
3258 if (cYAML_create_number(peer_ni, "min_tx_credits",
3259 lpni_cri->cr_peer_min_tx_credits)
3263 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3264 lpni_cri->cr_peer_tx_qnob)
3268 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3269 lpni_cri->cr_peer_rtr_credits)
3273 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3274 lpni_cri->cr_peer_min_rtr_credits)
3278 if (cYAML_create_number(peer_ni, "refcount",
3279 lpni_cri->cr_refcount) == NULL)
3282 statistics = cYAML_create_object(peer_ni, "statistics");
3283 if (statistics == NULL)
3286 if (cYAML_create_number(statistics, "send_count",
3287 lpni_stats->iel_send_count)
3291 if (cYAML_create_number(statistics, "recv_count",
3292 lpni_stats->iel_recv_count)
3296 if (cYAML_create_number(statistics, "drop_count",
3297 lpni_stats->iel_drop_count)
3304 for (k = 0; k < 3; k++) {
3305 struct lnet_ioctl_comm_count *counts;
3307 msg_statistics = cYAML_create_object(peer_ni,
3308 (char *) gmsg_stat_names[k]);
3309 if (msg_statistics == NULL)
3312 counts = get_counts(msg_stats, k);
3316 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3321 yhstats = cYAML_create_object(peer_ni, "health stats");
3324 if (cYAML_create_number(yhstats, "health value",
3325 hstats->hlpni_health_value)
3328 if (cYAML_create_number(yhstats, "dropped",
3329 hstats->hlpni_remote_dropped)
3332 if (cYAML_create_number(yhstats, "timeout",
3333 hstats->hlpni_remote_timeout)
3336 if (cYAML_create_number(yhstats, "error",
3337 hstats->hlpni_remote_error)
3340 if (cYAML_create_number(yhstats, "network timeout",
3341 hstats->hlpni_network_timeout)
3344 if (cYAML_create_number(yhstats, "ping_count",
3345 hstats->hlpni_ping_count)
3349 if (cYAML_create_number(yhstats, "next_ping",
3350 hstats->hlpni_next_ping)
3357 /* print output iff show_rc is not provided */
3358 if (show_rc == NULL)
3359 cYAML_print_tree(root);
3361 snprintf(err_str, sizeof(err_str), "\"success\"");
3362 rc = LUSTRE_CFG_RC_NO_ERR;
3367 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3368 cYAML_free_tree(root);
3369 } else if (show_rc != NULL && *show_rc != NULL) {
3370 struct cYAML *show_node;
3371 /* find the peer node, if one doesn't exist then
3372 * insert one. Otherwise add to the one there
3374 show_node = cYAML_get_object_item(*show_rc,
3376 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3377 cYAML_insert_child(show_node, first_seq);
3380 } else if (show_node == NULL) {
3381 cYAML_insert_sibling((*show_rc)->cy_child,
3385 cYAML_free_tree(root);
3391 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3397 int lustre_lnet_list_peer(int seq_no,
3398 struct cYAML **show_rc, struct cYAML **err_rc)
3400 struct lnet_ioctl_peer_cfg peer_info;
3401 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3406 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3407 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3408 struct lnet_process_id *list = NULL;
3410 memset(&peer_info, 0, sizeof(peer_info));
3412 /* create struct cYAML root object */
3413 root = cYAML_create_object(NULL, NULL);
3417 list_root = cYAML_create_seq(root, "peer list");
3418 if (list_root == NULL)
3422 size = count * sizeof(struct lnet_process_id);
3423 list = malloc(size);
3429 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3430 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3431 peer_info.prcfg_size = size;
3432 peer_info.prcfg_bulk = list;
3435 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3436 count = peer_info.prcfg_count;
3440 if (l_errno != E2BIG) {
3443 "\"cannot get peer list: %s\"",
3449 size = peer_info.prcfg_size;
3450 list = malloc(size);
3457 /* count is now the actual number of ids in the list. */
3458 for (i = 0; i < count; i++) {
3459 if (cYAML_create_string(list_root, "nid",
3460 libcfs_nid2str(list[i].nid))
3465 /* print output iff show_rc is not provided */
3466 if (show_rc == NULL)
3467 cYAML_print_tree(root);
3469 snprintf(err_str, sizeof(err_str), "\"success\"");
3470 rc = LUSTRE_CFG_RC_NO_ERR;
3475 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3476 cYAML_free_tree(root);
3477 } else if (show_rc != NULL && *show_rc != NULL) {
3478 struct cYAML *show_node;
3479 /* find the peer node, if one doesn't exist then
3480 * insert one. Otherwise add to the one there
3482 show_node = cYAML_get_object_item(*show_rc,
3484 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3485 cYAML_insert_child(show_node, first_seq);
3488 } else if (show_node == NULL) {
3489 cYAML_insert_sibling((*show_rc)->cy_child,
3493 cYAML_free_tree(root);
3499 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3505 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3508 struct cYAML *show_node;
3510 show_node = cYAML_get_object_item(show_rc, "global");
3511 if (show_node != NULL)
3512 cYAML_insert_sibling(show_node->cy_child,
3515 cYAML_insert_sibling(show_rc->cy_child,
3520 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3521 char *name, __u64 value,
3522 struct cYAML **show_rc,
3523 struct cYAML **err_rc, int err)
3525 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3526 struct cYAML *root = NULL, *global = NULL;
3533 root = cYAML_create_object(NULL, NULL);
3537 global = cYAML_create_object(root, "global");
3541 if (cYAML_create_number(global, name,
3545 if (show_rc == NULL)
3546 cYAML_print_tree(root);
3548 snprintf(err_str, err_len, "\"success\"");
3550 rc = LUSTRE_CFG_RC_NO_ERR;
3553 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3554 cYAML_free_tree(root);
3555 } else if (show_rc != NULL && *show_rc != NULL) {
3556 add_to_global(*show_rc, global, root);
3561 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3566 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3567 struct cYAML **show_rc,
3568 struct cYAML **err_rc)
3570 struct lnet_ioctl_set_value data;
3573 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3575 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3577 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3582 "\"cannot get %s: %s\"",
3583 name, strerror(l_errno));
3586 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3587 data.sv_value, show_rc, err_rc, l_errno);
3590 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3591 struct cYAML **err_rc)
3593 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3594 char val[LNET_MAX_STR_LEN];
3595 int intrv = -1, l_errno = 0;
3596 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3598 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3602 snprintf(err_str, sizeof(err_str),
3603 "\"cannot get recovery interval: %d\"", rc);
3608 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3609 "recovery_interval", intrv, show_rc,
3613 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3614 struct cYAML **err_rc)
3616 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3617 char val[LNET_MAX_STR_LEN];
3618 int sen = -1, l_errno = 0;
3619 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3621 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3625 snprintf(err_str, sizeof(err_str),
3626 "\"cannot get health sensitivity: %d\"", rc);
3631 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3632 "health_sensitivity", sen, show_rc,
3636 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3637 struct cYAML **err_rc)
3639 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3640 char val[LNET_MAX_STR_LEN];
3641 int sen = -1, l_errno = 0;
3642 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3644 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3648 snprintf(err_str, sizeof(err_str),
3649 "\"cannot get router sensitivity percentage: %d\"", rc);
3654 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3655 "router_sensitivity", sen, show_rc,
3659 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3660 struct cYAML **err_rc)
3662 char val[LNET_MAX_STR_LEN];
3663 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3670 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3673 snprintf(err_str, sizeof(err_str),
3674 "\"cannot get LND timeout: %d\"", rc);
3675 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3676 "lnd_timeout", lnd_to, show_rc,
3680 fd = open(path.gl_pathv[0], O_RDONLY);
3683 snprintf(err_str, sizeof(err_str),
3684 "\"error opening %s\"", path.gl_pathv[0]);
3688 rc = read(fd, val, sizeof(val));
3695 snprintf(err_str, sizeof(err_str),
3696 "\"error reading %s\"", path.gl_pathv[0]);
3703 cfs_free_param_data(&path);
3705 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3706 "lnd_timeout", lnd_to, show_rc,
3710 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3711 struct cYAML **err_rc)
3713 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3714 char val[LNET_MAX_STR_LEN];
3715 int tto = -1, l_errno = 0;
3716 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3718 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3722 snprintf(err_str, sizeof(err_str),
3723 "\"cannot get transaction timeout: %d\"", rc);
3728 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3729 "transaction_timeout", tto, show_rc,
3733 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3734 struct cYAML **err_rc)
3736 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3737 char val[LNET_MAX_STR_LEN];
3738 int retry_count = -1, l_errno = 0;
3739 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3741 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3745 snprintf(err_str, sizeof(err_str),
3746 "\"cannot get retry count: %d\"", rc);
3748 retry_count = atoi(val);
3751 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3752 "retry_count", retry_count, show_rc,
3756 int lustre_lnet_calc_service_id(__u64 *service_id)
3758 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3759 char val[LNET_MAX_STR_LEN];
3760 int service_port = -1, l_errno = 0;
3762 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3766 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3767 strerror(l_errno), -l_errno);
3770 service_port = atoi(val);
3773 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3775 return LUSTRE_CFG_RC_NO_ERR;
3778 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3781 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3783 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3784 struct lnet_ioctl_config_ni *ni_data;
3785 struct lnet_ioctl_config_lnd_tunables *lnd;
3786 struct lnet_ioctl_element_stats *stats;
3787 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3788 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3789 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3790 int if_cnt = 0, prc;
3791 char syscmdbuf[LNET_MAX_STR_LEN];
3792 char cmdpath[LNET_MAX_STR_LEN];
3793 bool use_custom = false;
3795 buf = calloc(1, buf_size);
3799 ni_data = (struct lnet_ioctl_config_ni *)buf;
3802 ifstr_ptr = ifstr_buf;
3807 memset(buf, 0, buf_size);
3809 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3810 /* set the ioc_len to the proper value since INIT assumes
3813 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3814 ni_data->lic_idx = i;
3816 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3822 rc_net = LNET_NIDNET(ni_data->lic_nid);
3824 /* only need to setup routing for tcp */
3825 if (LNET_NETTYP(rc_net) != SOCKLND)
3828 /* don't add interfaces unless there is at least one
3831 if (strlen(ni_data->lic_ni_intf) > 0) {
3833 strcat(ifstr_ptr, ",");
3834 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3839 if (l_errno != ENOENT) {
3842 "\"cannot get networks: %s\"",
3847 rc = LUSTRE_CFG_RC_NO_ERR;
3850 snprintf(err_str, sizeof(err_str), "\"success\"");
3853 tmp_ptr = getenv("KSOCKLND_CONFIG");
3855 tmp_ptr2 = strrchr(tmp_ptr, '/');
3856 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3857 snprintf(cmdpath, sizeof(cmdpath), "%s",
3864 snprintf(cmdpath, sizeof(cmdpath),
3865 "/usr/sbin/ksocklnd-config");
3867 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3873 "\"snprintf failed : %s\"",
3876 } else if (prc >= LNET_MAX_STR_LEN) {
3877 snprintf(err_str, sizeof(err_str),
3878 "\"ksocklnd-config: argument too long\"");
3880 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3881 cmdpath, ifstr_ptr);
3887 "\"snprintf failed : %s\"",
3893 rc = system(syscmdbuf);
3898 "\"failed to execute ksocklnd-config : %s\"",
3908 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3915 lnet_nid_cpt_hash(lnet_nid_t nid, long int number, unsigned int cpt_bits)
3918 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
3924 if (lnd == KFILND || lnd == GNILND) {
3925 cpt = hash_long(key, cpt_bits);
3927 /* NB: The number of CPTs needn't be a power of 2 */
3929 cpt = (key + cpt + (cpt >> 1)) % number;
3931 __u64 pair_bits = 0x0001000100010001LLU;
3932 __u64 mask = pair_bits * 0xFF;
3934 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
3935 * (number of CPTs) to match nid to a CPT.
3937 pair_sum = (key & mask) + ((key >> 8) & mask);
3938 pair_sum = (pair_sum * pair_bits) >> 48;
3939 cpt = (unsigned int)(pair_sum) % number;
3945 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3947 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3949 unsigned int cpt_bits;
3952 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3957 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3962 fprintf(stderr, "error:\n msg: \"number of CPTs must be >= 1\"\n");
3967 while ((1 << cpt_bits) < ncpts)
3970 nid = libcfs_str2nid(nidc);
3971 if (nid == LNET_NID_ANY) {
3972 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3977 return (int)lnet_nid_cpt_hash(nid, ncpts, cpt_bits);
3980 static int show_recovery_queue(enum lnet_health_type type, char *name,
3981 int seq_no, struct cYAML **show_rc,
3982 struct cYAML **err_rc)
3984 struct lnet_ioctl_recovery_list nid_list;
3985 struct cYAML *root = NULL, *nids = NULL;
3987 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3989 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3990 nid_list.rlst_type = type;
3992 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3998 if (nid_list.rlst_num_nids == 0)
4001 root = cYAML_create_object(NULL, NULL);
4005 nids = cYAML_create_object(root, name);
4011 for (i = 0; i < nid_list.rlst_num_nids; i++) {
4012 char nidenum[LNET_MAX_STR_LEN];
4013 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
4014 if (!cYAML_create_string(nids, nidenum,
4015 libcfs_nid2str(nid_list.rlst_nid_array[i])))
4019 snprintf(err_str, sizeof(err_str), "success\n");
4024 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4025 cYAML_free_tree(root);
4026 } else if (show_rc != NULL && *show_rc != NULL) {
4027 struct cYAML *show_node;
4028 /* find the net node, if one doesn't exist
4029 * then insert one. Otherwise add to the one there
4031 show_node = cYAML_get_object_item(*show_rc, name);
4032 if (show_node != NULL && cYAML_is_sequence(show_node)) {
4033 cYAML_insert_child(show_node, nids);
4036 } else if (show_node == NULL) {
4037 cYAML_insert_sibling((*show_rc)->cy_child,
4041 cYAML_free_tree(root);
4047 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
4052 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
4053 struct cYAML **err_rc)
4055 struct libcfs_ioctl_data data;
4057 char err_str[LNET_MAX_STR_LEN] = "Error";
4058 lnet_nid_t pnid = LNET_NID_ANY;
4061 rc = LUSTRE_CFG_RC_BAD_PARAM;
4062 snprintf(err_str, LNET_MAX_STR_LEN,
4063 "--nid must be specified");
4067 pnid = libcfs_str2nid(peer_nid);
4068 if (pnid == LNET_NID_ANY) {
4069 rc = LUSTRE_CFG_RC_BAD_PARAM;
4070 snprintf(err_str, LNET_MAX_STR_LEN,
4071 "badly formatted primary NID: %s", peer_nid);
4075 LIBCFS_IOC_INIT(data);
4076 data.ioc_net = LNET_NIDNET(pnid);
4077 data.ioc_nid = pnid;
4079 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4083 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4089 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4090 struct cYAML **err_rc)
4092 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4093 seq_no, show_rc, err_rc);
4096 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4097 struct cYAML **err_rc)
4099 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4100 seq_no, show_rc, err_rc);
4103 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4104 struct cYAML **err_rc)
4106 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4107 char val[LNET_MAX_STR_LEN];
4108 int rsp_tracking = -1, l_errno = 0;
4109 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4111 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4115 snprintf(err_str, sizeof(err_str),
4116 "\"cannot get lnet_response_tracking value: %d\"", rc);
4118 rsp_tracking = atoi(val);
4121 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4122 "response_tracking", rsp_tracking,
4123 show_rc, err_rc, l_errno);
4126 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4127 struct cYAML **err_rc)
4129 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4130 char val[LNET_MAX_STR_LEN];
4131 int recov_limit = -1, l_errno = 0;
4132 char err_str[LNET_MAX_STR_LEN];
4134 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4136 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4140 snprintf(err_str, sizeof(err_str),
4141 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4143 recov_limit = atoi(val);
4146 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4147 "recovery_limit", recov_limit,
4148 show_rc, err_rc, l_errno);
4151 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4152 struct cYAML **show_rc,
4153 struct cYAML **err_rc)
4155 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4156 char val[LNET_MAX_STR_LEN];
4157 int interval = -1, l_errno = 0;
4158 char err_str[LNET_MAX_STR_LEN];
4160 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4162 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4163 val, 1, sizeof(val));
4166 snprintf(err_str, sizeof(err_str),
4167 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4170 interval = atoi(val);
4173 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4174 "max_recovery_ping_interval", interval,
4175 show_rc, err_rc, l_errno);
4179 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4180 struct cYAML **err_rc)
4182 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4183 char val[LNET_MAX_STR_LEN];
4184 int max_intf = -1, l_errno = 0;
4185 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4187 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4191 snprintf(err_str, sizeof(err_str),
4192 "\"cannot get max interfaces: %d\"", rc);
4194 max_intf = atoi(val);
4197 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4198 "max_interfaces", max_intf, show_rc,
4202 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4203 struct cYAML **err_rc)
4205 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4206 char val[LNET_MAX_STR_LEN];
4207 int discovery = -1, l_errno = 0;
4208 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4210 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4214 snprintf(err_str, sizeof(err_str),
4215 "\"cannot get discovery setting: %d\"", rc);
4218 * The kernel stores a discovery disabled value. User space
4219 * shows whether discovery is enabled. So the value must be
4222 discovery = !atoi(val);
4225 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4226 "discovery", discovery, show_rc,
4230 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4231 struct cYAML **err_rc)
4233 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4234 char val[LNET_MAX_STR_LEN];
4235 int drop_asym_route = -1, l_errno = 0;
4236 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4238 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4242 snprintf(err_str, sizeof(err_str),
4243 "\"cannot get drop asym route setting: %d\"", rc);
4245 drop_asym_route = atoi(val);
4248 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4249 "drop_asym_route", drop_asym_route,
4250 show_rc, err_rc, l_errno);
4253 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4254 struct cYAML **err_rc)
4256 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4257 "numa_range", show_rc, err_rc);
4260 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4261 struct cYAML **err_rc)
4263 struct lnet_ioctl_lnet_stats data;
4264 struct lnet_counters *cntrs;
4267 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4268 struct cYAML *root = NULL, *stats = NULL;
4270 LIBCFS_IOC_INIT_V2(data, st_hdr);
4272 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4277 "\"cannot get lnet statistics: %s\"",
4283 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4285 cntrs = &data.st_cntrs;
4287 root = cYAML_create_object(NULL, NULL);
4291 stats = cYAML_create_object(root, "statistics");
4295 if (!cYAML_create_number(stats, "msgs_alloc",
4296 cntrs->lct_common.lcc_msgs_alloc))
4299 if (!cYAML_create_number(stats, "msgs_max",
4300 cntrs->lct_common.lcc_msgs_max))
4303 if (!cYAML_create_number(stats, "rst_alloc",
4304 cntrs->lct_health.lch_rst_alloc))
4307 if (!cYAML_create_number(stats, "errors",
4308 cntrs->lct_common.lcc_errors))
4311 if (!cYAML_create_number(stats, "send_count",
4312 cntrs->lct_common.lcc_send_count))
4315 if (!cYAML_create_number(stats, "resend_count",
4316 cntrs->lct_health.lch_resend_count))
4319 if (!cYAML_create_number(stats, "response_timeout_count",
4320 cntrs->lct_health.lch_response_timeout_count))
4323 if (!cYAML_create_number(stats, "local_interrupt_count",
4324 cntrs->lct_health.lch_local_interrupt_count))
4327 if (!cYAML_create_number(stats, "local_dropped_count",
4328 cntrs->lct_health.lch_local_dropped_count))
4331 if (!cYAML_create_number(stats, "local_aborted_count",
4332 cntrs->lct_health.lch_local_aborted_count))
4335 if (!cYAML_create_number(stats, "local_no_route_count",
4336 cntrs->lct_health.lch_local_no_route_count))
4339 if (!cYAML_create_number(stats, "local_timeout_count",
4340 cntrs->lct_health.lch_local_timeout_count))
4343 if (!cYAML_create_number(stats, "local_error_count",
4344 cntrs->lct_health.lch_local_error_count))
4347 if (!cYAML_create_number(stats, "remote_dropped_count",
4348 cntrs->lct_health.lch_remote_dropped_count))
4351 if (!cYAML_create_number(stats, "remote_error_count",
4352 cntrs->lct_health.lch_remote_error_count))
4355 if (!cYAML_create_number(stats, "remote_timeout_count",
4356 cntrs->lct_health.lch_remote_timeout_count))
4359 if (!cYAML_create_number(stats, "network_timeout_count",
4360 cntrs->lct_health.lch_network_timeout_count))
4363 if (!cYAML_create_number(stats, "recv_count",
4364 cntrs->lct_common.lcc_recv_count))
4367 if (!cYAML_create_number(stats, "route_count",
4368 cntrs->lct_common.lcc_route_count))
4371 if (!cYAML_create_number(stats, "drop_count",
4372 cntrs->lct_common.lcc_drop_count))
4375 if (!cYAML_create_number(stats, "send_length",
4376 cntrs->lct_common.lcc_send_length))
4379 if (!cYAML_create_number(stats, "recv_length",
4380 cntrs->lct_common.lcc_recv_length))
4383 if (!cYAML_create_number(stats, "route_length",
4384 cntrs->lct_common.lcc_route_length))
4387 if (!cYAML_create_number(stats, "drop_length",
4388 cntrs->lct_common.lcc_drop_length))
4392 cYAML_print_tree(root);
4394 snprintf(err_str, sizeof(err_str), "\"success\"");
4395 rc = LUSTRE_CFG_RC_NO_ERR;
4397 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4398 cYAML_free_tree(root);
4399 } else if (show_rc != NULL && *show_rc != NULL) {
4400 cYAML_insert_sibling((*show_rc)->cy_child,
4407 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4412 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4414 struct libcfs_ioctl_data data;
4415 int rc = LUSTRE_CFG_RC_NO_ERR;
4417 char err_str[LNET_MAX_STR_LEN];
4419 LIBCFS_IOC_INIT(data);
4421 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4426 "\"cannot reset lnet statistics: %s\"",
4430 snprintf(err_str, sizeof(err_str), "\"success\"");
4431 rc = LUSTRE_CFG_RC_NO_ERR;
4434 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4438 typedef int (*cmd_handler_t)(struct cYAML *tree,
4439 struct cYAML **show_rc,
4440 struct cYAML **err_rc);
4442 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4443 struct cYAML **err_rc)
4445 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4447 net = cYAML_get_object_item(tree, "net");
4448 gw = cYAML_get_object_item(tree, "gateway");
4449 hop = cYAML_get_object_item(tree, "hop");
4450 prio = cYAML_get_object_item(tree, "priority");
4451 sen = cYAML_get_object_item(tree, "health_sensitivity");
4452 seq_no = cYAML_get_object_item(tree, "seq_no");
4454 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4455 (gw) ? gw->cy_valuestring : NULL,
4456 (hop) ? hop->cy_valueint : -1,
4457 (prio) ? prio->cy_valueint : -1,
4458 (sen) ? sen->cy_valueint : -1,
4459 (seq_no) ? seq_no->cy_valueint : -1,
4465 * 0: <intf_name>['['<expr>']']
4466 * 1: <intf_name>['['<expr>']']
4468 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4469 struct lnet_dlc_network_descr *nw_descr)
4471 struct cYAML *child = NULL;
4472 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4473 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4475 if (intf_tree == NULL || nw_descr == NULL)
4476 return LUSTRE_CFG_RC_BAD_PARAM;
4478 /* now grab all the interfaces and their cpts */
4479 child = intf_tree->cy_child;
4480 while (child != NULL) {
4481 if (child->cy_valuestring == NULL) {
4482 child = child->cy_next;
4486 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4489 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4490 child->cy_valuestring,
4491 strlen(child->cy_valuestring));
4492 if (rc != LUSTRE_CFG_RC_NO_ERR)
4496 child = child->cy_next;
4500 return LUSTRE_CFG_RC_MISSING_PARAM;
4505 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4507 list_del(&intf_descr->intf_on_network);
4508 free_intf_descr(intf_descr);
4515 yaml_extract_cmn_tunables(struct cYAML *tree,
4516 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4518 struct cYAML *tun, *item;
4520 tun = cYAML_get_object_item(tree, "tunables");
4522 item = cYAML_get_object_item(tun, "peer_timeout");
4524 tunables->lct_peer_timeout = item->cy_valueint;
4526 tunables->lct_peer_timeout = -1;
4527 item = cYAML_get_object_item(tun, "peer_credits");
4529 tunables->lct_peer_tx_credits = item->cy_valueint;
4530 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4532 tunables->lct_peer_rtr_credits = item->cy_valueint;
4533 item = cYAML_get_object_item(tun, "credits");
4535 tunables->lct_max_tx_credits = item->cy_valueint;
4544 yaml_extract_tunables(struct cYAML *tree,
4545 struct lnet_ioctl_config_lnd_tunables *tunables,
4550 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4555 lustre_yaml_extract_lnd_tunables(tree, net_type,
4562 yaml_extract_cpt(struct cYAML *tree,
4563 struct cfs_expr_list **global_cpts)
4568 smp = cYAML_get_object_item(tree, "CPT");
4570 rc = cfs_expr_list_parse(smp->cy_valuestring,
4571 strlen(smp->cy_valuestring),
4572 0, UINT_MAX, global_cpts);
4574 *global_cpts = NULL;
4580 * - net type: <net>[<NUM>]
4582 * - nid: <ip>@<net>[<NUM>]
4585 * 0: <intf_name>['['<expr>']']
4586 * 1: <intf_name>['['<expr>']']
4588 * peer_timeout: <NUM>
4589 * peer_credits: <NUM>
4590 * peer_buffer_credits: <NUM>
4593 * peercredits_hiw: <NUM>
4594 * map_on_demand: <NUM>
4595 * concurrent_sends: <NUM>
4596 * fmr_pool_size: <NUM>
4597 * fmr_flush_trigger: <NUM>
4600 * At least one interface is required. If no interfaces are provided the
4601 * network interface can not be configured.
4603 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4604 struct cYAML **err_rc)
4606 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4608 int num_entries = 0, rc;
4609 struct lnet_dlc_network_descr nw_descr;
4610 struct cfs_expr_list *global_cpts = NULL;
4611 struct lnet_ioctl_config_lnd_tunables tunables;
4614 memset(&tunables, 0, sizeof(tunables));
4615 /* Use LND defaults */
4616 tunables.lt_cmn.lct_peer_timeout = -1;
4617 tunables.lt_cmn.lct_peer_tx_credits = -1;
4618 tunables.lt_cmn.lct_peer_rtr_credits = -1;
4619 tunables.lt_cmn.lct_max_tx_credits = -1;
4621 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4622 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4624 ip2net = cYAML_get_object_item(tree, "ip2net");
4625 net = cYAML_get_object_item(tree, "net type");
4627 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4629 nw_descr.nw_id = LOLND;
4632 * if neither net nor ip2nets are present, then we can not
4633 * configure the network.
4635 if (!net && !ip2net)
4636 return LUSTRE_CFG_RC_MISSING_PARAM;
4638 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4639 if (local_nis == NULL)
4640 return LUSTRE_CFG_RC_MISSING_PARAM;
4642 if (!cYAML_is_sequence(local_nis))
4643 return LUSTRE_CFG_RC_BAD_PARAM;
4645 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4646 intf = cYAML_get_object_item(item, "interfaces");
4649 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4650 if (num_entries <= 0) {
4651 cYAML_build_error(num_entries, -1, "ni", "add",
4652 "bad interface list",
4654 return LUSTRE_CFG_RC_BAD_PARAM;
4658 found = yaml_extract_tunables(tree, &tunables,
4659 LNET_NETTYP(nw_descr.nw_id));
4660 yaml_extract_cpt(tree, &global_cpts);
4661 seq_no = cYAML_get_object_item(tree, "seq_no");
4663 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4664 (ip2net) ? ip2net->cy_valuestring : NULL,
4665 (found) ? &tunables : NULL,
4666 (seq_no) ? seq_no->cy_valueint : -1,
4669 if (global_cpts != NULL)
4670 cfs_expr_list_free(global_cpts);
4677 * - net-spec: <tcp|o2ib|gni>[NUM]
4679 * 0: <intf name>['['<expr>']']
4680 * 1: <intf name>['['<expr>']']
4682 * 0: <expr.expr.expr.expr>
4683 * 1: <expr.expr.expr.expr>
4685 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4686 struct cYAML **show_rc,
4687 struct cYAML **err_rc)
4689 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4691 struct lustre_lnet_ip2nets ip2nets;
4692 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4694 int rc = LUSTRE_CFG_RC_NO_ERR;
4695 struct cfs_expr_list *global_cpts = NULL;
4696 struct cfs_expr_list *el, *el_tmp;
4697 struct lnet_ioctl_config_lnd_tunables tunables;
4698 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4701 memset(&tunables, 0, sizeof(tunables));
4703 /* initialize all lists */
4704 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4705 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4706 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4708 net = cYAML_get_object_item(tree, "net-spec");
4710 return LUSTRE_CFG_RC_BAD_PARAM;
4712 if (net != NULL && net->cy_valuestring == NULL)
4713 return LUSTRE_CFG_RC_BAD_PARAM;
4715 /* assign the network id */
4716 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4717 if (ip2nets.ip2nets_net.nw_id == LNET_NET_ANY)
4718 return LUSTRE_CFG_RC_BAD_PARAM;
4720 seq_no = cYAML_get_object_item(tree, "seq_no");
4722 intf = cYAML_get_object_item(tree, "interfaces");
4724 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4726 return LUSTRE_CFG_RC_BAD_PARAM;
4729 ip_range = cYAML_get_object_item(tree, "ip-range");
4730 if (ip_range != NULL) {
4731 item = ip_range->cy_child;
4732 while (item != NULL) {
4733 if (item->cy_valuestring == NULL) {
4734 item = item->cy_next;
4738 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4739 item->cy_valuestring);
4741 if (rc != LUSTRE_CFG_RC_NO_ERR)
4744 item = item->cy_next;
4748 found = yaml_extract_tunables(tree, &tunables,
4749 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4750 yaml_extract_cpt(tree, &global_cpts);
4752 rc = lustre_lnet_config_ip2nets(&ip2nets,
4753 (found) ? &tunables : NULL,
4755 (seq_no) ? seq_no->cy_valueint : -1,
4758 if (global_cpts != NULL)
4759 cfs_expr_list_free(global_cpts);
4762 * don't stop because there was no match. Continue processing the
4763 * rest of the rules. If non-match then nothing is configured
4765 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4766 rc = LUSTRE_CFG_RC_NO_ERR;
4768 list_for_each_entry_safe(intf_descr, intf_tmp,
4769 &ip2nets.ip2nets_net.nw_intflist,
4771 list_del(&intf_descr->intf_on_network);
4772 free_intf_descr(intf_descr);
4775 list_for_each_entry_safe(ip_range_descr, tmp,
4776 &ip2nets.ip2nets_ip_ranges,
4778 list_del(&ip_range_descr->ipr_entry);
4779 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4781 list_del(&el->el_link);
4782 cfs_expr_list_free(el);
4784 free(ip_range_descr);
4790 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4791 struct cYAML **err_rc)
4793 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4795 int num_entries, rc;
4796 struct lnet_dlc_network_descr nw_descr;
4798 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4799 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4801 net = cYAML_get_object_item(tree, "net type");
4803 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4805 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4806 if (local_nis == NULL)
4807 return LUSTRE_CFG_RC_MISSING_PARAM;
4809 if (!cYAML_is_sequence(local_nis))
4810 return LUSTRE_CFG_RC_BAD_PARAM;
4812 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4813 intf = cYAML_get_object_item(item, "interfaces");
4816 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4817 if (num_entries <= 0) {
4818 cYAML_build_error(num_entries, -1, "ni", "add",
4819 "bad interface list",
4821 return LUSTRE_CFG_RC_BAD_PARAM;
4825 seq_no = cYAML_get_object_item(tree, "seq_no");
4827 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4828 (seq_no) ? seq_no->cy_valueint : -1,
4834 /* Create a nidstring parseable by the nidstrings library from the nid
4835 * information encoded in the CYAML structure.
4836 * NOTE: Caller must free memory allocated to nidstr
4838 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4839 char *prim_nid, int cmd)
4841 int num_strs = 0, rc;
4842 size_t buf_size, buf_pos, nidstr_len = 0;
4844 struct cYAML *child = NULL, *entry = NULL;
4846 if (cYAML_is_sequence(nids_entry)) {
4847 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4848 entry = cYAML_get_object_item(child, "nid");
4849 /* don't count an empty entry */
4850 if (!entry || !entry->cy_valuestring)
4854 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4855 if (cmd == LNETCTL_DEL_CMD) {
4857 * primary nid is present in the list of
4858 * nids so that means we want to delete
4859 * the entire peer, so no need to go
4860 * further. Just delete the entire peer.
4862 return LUSTRE_CFG_RC_NO_ERR;
4869 * + 1 for the space separating each string, and
4870 * accounts for the terminating null char
4872 nidstr_len += strlen(entry->cy_valuestring) + 1;
4877 if (num_strs == 0 && !prim_nid)
4878 return LUSTRE_CFG_RC_MISSING_PARAM;
4879 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4880 return LUSTRE_CFG_RC_NO_ERR;
4882 buffer = malloc(nidstr_len);
4884 return LUSTRE_CFG_RC_OUT_OF_MEM;
4886 /* now grab all the nids */
4889 buf_size = nidstr_len;
4891 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4892 entry = cYAML_get_object_item(child, "nid");
4893 if (!entry || !entry->cy_valuestring)
4897 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4901 rc = snprintf(buffer + buf_pos, buf_size, " ");
4902 buf_pos += (rc < buf_size) ? rc : buf_size;
4903 buf_size = nidstr_len - buf_pos;
4906 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4907 entry->cy_valuestring);
4908 buf_pos += (rc < buf_size) ? rc : buf_size;
4909 buf_size = nidstr_len - buf_pos;
4914 return LUSTRE_CFG_RC_NO_ERR;
4917 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4918 struct cYAML **err_rc, int cmd)
4920 int rc, num_nids = 0, seqn;
4921 bool mr_value = false;
4922 char *nidstr = NULL, *prim_nidstr;
4923 char err_str[LNET_MAX_STR_LEN];
4924 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4925 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4926 lnet_nid_t pnid = LNET_NID_ANY;
4929 seq_no = cYAML_get_object_item(tree, "seq_no");
4930 seqn = seq_no ? seq_no->cy_valueint : -1;
4932 prim_nid = cYAML_get_object_item(tree, "primary nid");
4933 peer_nis = cYAML_get_object_item(tree, "peer ni");
4935 rc = LUSTRE_CFG_RC_BAD_PARAM;
4936 snprintf(err_str, LNET_MAX_STR_LEN,
4937 "\"primary nid\" must be specified");
4941 prim_nidstr = prim_nid->cy_valuestring;
4943 /* if the provided primary NID is bad, no need to go any further */
4944 pnid = libcfs_str2nid(prim_nidstr);
4945 if (pnid == LNET_NID_ANY) {
4946 rc = LUSTRE_CFG_RC_BAD_PARAM;
4947 snprintf(err_str, LNET_MAX_STR_LEN,
4948 "badly formatted primary NID: %s", prim_nidstr);
4952 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4953 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4954 snprintf(err_str, LNET_MAX_STR_LEN,
4955 "No nids defined in YAML block");
4957 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4958 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4960 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4961 snprintf(err_str, LNET_MAX_STR_LEN,
4962 "Unrecognized error %d", rc);
4968 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4969 LNET_MAX_NIDS_PER_PEER,
4977 if (cmd == LNETCTL_ADD_CMD) {
4978 mr = cYAML_get_object_item(tree, "Multi-Rail");
4980 if (mr && mr->cy_valuestring) {
4981 if (strcmp(mr->cy_valuestring, "False") == 0)
4983 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4984 rc = LUSTRE_CFG_RC_BAD_PARAM;
4985 snprintf(err_str, LNET_MAX_STR_LEN,
4986 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4987 mr->cy_valuestring);
4993 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4994 num_nids, mr_value, force,
5001 if (rc != LUSTRE_CFG_RC_NO_ERR)
5002 cYAML_build_error(rc, seqn, "peer",
5003 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
5009 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
5010 struct cYAML **err_rc)
5012 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
5015 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
5016 struct cYAML **err_rc)
5018 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
5021 static int handle_yaml_config_buffers(struct cYAML *tree,
5022 struct cYAML **show_rc,
5023 struct cYAML **err_rc)
5026 struct cYAML *tiny, *small, *large, *seq_no;
5028 tiny = cYAML_get_object_item(tree, "tiny");
5029 small = cYAML_get_object_item(tree, "small");
5030 large = cYAML_get_object_item(tree, "large");
5031 seq_no = cYAML_get_object_item(tree, "seq_no");
5033 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
5034 (small) ? small->cy_valueint : -1,
5035 (large) ? large->cy_valueint : -1,
5036 (seq_no) ? seq_no->cy_valueint : -1,
5042 static int handle_yaml_config_routing(struct cYAML *tree,
5043 struct cYAML **show_rc,
5044 struct cYAML **err_rc)
5046 int rc = LUSTRE_CFG_RC_NO_ERR;
5047 struct cYAML *seq_no, *enable;
5049 seq_no = cYAML_get_object_item(tree, "seq_no");
5050 enable = cYAML_get_object_item(tree, "enable");
5053 rc = lustre_lnet_enable_routing(enable->cy_valueint,
5055 seq_no->cy_valueint : -1,
5062 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
5063 struct cYAML **err_rc)
5067 struct cYAML *seq_no;
5069 net = cYAML_get_object_item(tree, "net");
5070 gw = cYAML_get_object_item(tree, "gateway");
5071 seq_no = cYAML_get_object_item(tree, "seq_no");
5073 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5074 (gw) ? gw->cy_valuestring : NULL,
5075 (seq_no) ? seq_no->cy_valueint : -1,
5079 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5080 struct cYAML **err_rc)
5082 struct cYAML *seq_no;
5084 seq_no = cYAML_get_object_item(tree, "seq_no");
5086 return lustre_lnet_enable_routing(0, (seq_no) ?
5087 seq_no->cy_valueint : -1,
5091 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5092 struct cYAML **err_rc)
5098 struct cYAML *detail;
5099 struct cYAML *seq_no;
5101 net = cYAML_get_object_item(tree, "net");
5102 gw = cYAML_get_object_item(tree, "gateway");
5103 hop = cYAML_get_object_item(tree, "hop");
5104 prio = cYAML_get_object_item(tree, "priority");
5105 detail = cYAML_get_object_item(tree, "detail");
5106 seq_no = cYAML_get_object_item(tree, "seq_no");
5108 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5109 (gw) ? gw->cy_valuestring : NULL,
5110 (hop) ? hop->cy_valueint : -1,
5111 (prio) ? prio->cy_valueint : -1,
5112 (detail) ? detail->cy_valueint : 0,
5113 (seq_no) ? seq_no->cy_valueint : -1,
5114 show_rc, err_rc, false);
5117 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5118 struct cYAML **err_rc)
5120 struct cYAML *net, *detail, *seq_no;
5122 net = cYAML_get_object_item(tree, "net type");
5123 detail = cYAML_get_object_item(tree, "detail");
5124 seq_no = cYAML_get_object_item(tree, "seq_no");
5126 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5127 (detail) ? detail->cy_valueint : 0,
5128 (seq_no) ? seq_no->cy_valueint : -1,
5129 show_rc, err_rc, false);
5132 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5133 struct cYAML **err_rc)
5135 struct cYAML *seq_no;
5137 seq_no = cYAML_get_object_item(tree, "seq_no");
5139 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5140 show_rc, err_rc, false);
5143 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5144 struct cYAML **err_rc)
5146 struct cYAML *seq_no, *nid, *detail;
5148 seq_no = cYAML_get_object_item(tree, "seq_no");
5149 detail = cYAML_get_object_item(tree, "detail");
5150 nid = cYAML_get_object_item(tree, "nid");
5152 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5153 (detail) ? detail->cy_valueint : 0,
5154 (seq_no) ? seq_no->cy_valueint : -1,
5155 show_rc, err_rc, false);
5158 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5159 struct cYAML **err_rc)
5161 struct cYAML *seq_no;
5163 seq_no = cYAML_get_object_item(tree, "seq_no");
5165 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5169 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5170 struct cYAML **err_rc)
5172 struct cYAML *seq_no, *range;
5174 seq_no = cYAML_get_object_item(tree, "seq_no");
5175 range = cYAML_get_object_item(tree, "range");
5177 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5178 seq_no ? seq_no->cy_valueint : -1,
5182 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5183 struct cYAML **err_rc)
5185 struct cYAML *seq_no;
5187 seq_no = cYAML_get_object_item(tree, "seq_no");
5189 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5193 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5194 struct cYAML **err_rc)
5196 struct cYAML *seq_no;
5198 seq_no = cYAML_get_object_item(tree, "seq_no");
5200 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5204 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5205 struct cYAML **err_rc)
5207 struct cYAML *seq_no, *idx;
5209 seq_no = cYAML_get_object_item(tree, "seq_no");
5210 idx = cYAML_get_object_item(tree, "idx");
5212 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5213 seq_no ? seq_no->cy_valueint : -1,
5217 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5218 struct cYAML **err_rc)
5220 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5221 union lnet_udsp_action action;
5223 seq_no = cYAML_get_object_item(tree, "seq_no");
5224 src = cYAML_get_object_item(tree, "src");
5225 rte = cYAML_get_object_item(tree, "rte");
5226 dst = cYAML_get_object_item(tree, "dst");
5227 prio = cYAML_get_object_item(tree, "priority");
5228 idx = cYAML_get_object_item(tree, "idx");
5230 action.udsp_priority = prio ? prio->cy_valueint : -1;
5232 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5233 dst ? dst->cy_valuestring : NULL,
5234 rte ? rte->cy_valuestring : NULL,
5235 prio ? "priority" : "",
5237 idx ? idx->cy_valueint : -1,
5238 seq_no ? seq_no->cy_valueint : -1,
5242 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5243 struct cYAML **err_rc)
5245 struct cYAML *seq_no;
5248 seq_no = cYAML_get_object_item(tree, "seq_no");
5249 idx = cYAML_get_object_item(tree, "idx");
5251 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5252 seq_no ? seq_no->cy_valueint : -1,
5256 static int handle_yaml_config_global_settings(struct cYAML *tree,
5257 struct cYAML **show_rc,
5258 struct cYAML **err_rc)
5260 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5261 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5265 seq_no = cYAML_get_object_item(tree, "seq_no");
5266 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5267 if (!max_intf) /* try legacy name */
5268 max_intf = cYAML_get_object_item(tree, "max_intf");
5270 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5271 seq_no ? seq_no->cy_valueint
5275 numa = cYAML_get_object_item(tree, "numa_range");
5277 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5278 seq_no ? seq_no->cy_valueint
5282 discovery = cYAML_get_object_item(tree, "discovery");
5284 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5285 seq_no ? seq_no->cy_valueint
5289 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5290 if (drop_asym_route)
5291 rc = lustre_lnet_config_drop_asym_route(
5292 drop_asym_route->cy_valueint,
5293 seq_no ? seq_no->cy_valueint : -1,
5296 retry = cYAML_get_object_item(tree, "retry_count");
5298 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5299 seq_no ? seq_no->cy_valueint
5303 tto = cYAML_get_object_item(tree, "transaction_timeout");
5305 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5306 seq_no ? seq_no->cy_valueint
5310 sen = cYAML_get_object_item(tree, "health_sensitivity");
5312 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5313 seq_no ? seq_no->cy_valueint
5317 recov = cYAML_get_object_item(tree, "recovery_interval");
5319 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5320 seq_no ? seq_no->cy_valueint
5324 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5326 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5327 seq_no ? seq_no->cy_valueint
5331 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5333 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5334 seq_no ? seq_no->cy_valueint
5338 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5340 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5341 seq_no ? seq_no->cy_valueint
5348 static int handle_yaml_del_global_settings(struct cYAML *tree,
5349 struct cYAML **show_rc,
5350 struct cYAML **err_rc)
5352 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5355 seq_no = cYAML_get_object_item(tree, "seq_no");
5356 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5357 if (!max_intf) /* try legacy name */
5358 max_intf = cYAML_get_object_item(tree, "max_intf");
5360 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5361 seq_no ? seq_no->cy_valueint
5365 numa = cYAML_get_object_item(tree, "numa_range");
5367 rc = lustre_lnet_config_numa_range(0,
5368 seq_no ? seq_no->cy_valueint
5372 /* peer discovery is enabled by default */
5373 discovery = cYAML_get_object_item(tree, "discovery");
5375 rc = lustre_lnet_config_discovery(1,
5376 seq_no ? seq_no->cy_valueint
5380 /* asymmetrical route messages are accepted by default */
5381 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5382 if (drop_asym_route)
5383 rc = lustre_lnet_config_drop_asym_route(
5384 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5389 static int handle_yaml_show_global_settings(struct cYAML *tree,
5390 struct cYAML **show_rc,
5391 struct cYAML **err_rc)
5393 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5394 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5398 seq_no = cYAML_get_object_item(tree, "seq_no");
5399 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5400 if (!max_intf) /* try legacy name */
5401 max_intf = cYAML_get_object_item(tree, "max_intf");
5403 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5407 numa = cYAML_get_object_item(tree, "numa_range");
5409 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5413 discovery = cYAML_get_object_item(tree, "discovery");
5415 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5419 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5420 if (drop_asym_route)
5421 rc = lustre_lnet_show_drop_asym_route(
5422 seq_no ? seq_no->cy_valueint : -1,
5425 retry = cYAML_get_object_item(tree, "retry_count");
5427 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5431 tto = cYAML_get_object_item(tree, "transaction_timeout");
5433 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5437 sen = cYAML_get_object_item(tree, "health_sensitivity");
5439 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5443 recov = cYAML_get_object_item(tree, "recovery_interval");
5445 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5449 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5451 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5455 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5457 rc = lustre_lnet_show_response_tracking(seq_no ?
5458 seq_no->cy_valueint :
5462 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5464 rc = lustre_lnet_show_recovery_limit(seq_no ?
5465 seq_no->cy_valueint :
5472 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5473 struct cYAML **err_rc)
5475 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5477 seq_no = cYAML_get_object_item(tree, "seq_no");
5478 nid = cYAML_get_object_item(tree, "primary nid");
5479 timeout = cYAML_get_object_item(tree, "timeout");
5480 src_nid = cYAML_get_object_item(tree, "source_nid");
5482 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5483 (src_nid) ? src_nid->cy_valuestring : NULL,
5484 (timeout) ? timeout->cy_valueint : 1000,
5485 (seq_no) ? seq_no->cy_valueint : -1,
5489 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5490 struct cYAML **err_rc)
5492 struct cYAML *seq_no, *nid, *force;
5494 seq_no = cYAML_get_object_item(tree, "seq_no");
5495 nid = cYAML_get_object_item(tree, "primary nid");
5496 force = cYAML_get_object_item(tree, "force");
5498 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5499 (force) ? force->cy_valueint : 0,
5500 (seq_no) ? seq_no->cy_valueint : -1,
5504 static int handle_yaml_no_op()
5506 return LUSTRE_CFG_RC_NO_ERR;
5509 struct lookup_cmd_hdlr_tbl {
5514 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5515 { .name = "route", .cb = handle_yaml_config_route },
5516 { .name = "net", .cb = handle_yaml_config_ni },
5517 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5518 { .name = "peer", .cb = handle_yaml_config_peer },
5519 { .name = "routing", .cb = handle_yaml_config_routing },
5520 { .name = "buffers", .cb = handle_yaml_config_buffers },
5521 { .name = "statistics", .cb = handle_yaml_no_op },
5522 { .name = "global", .cb = handle_yaml_config_global_settings},
5523 { .name = "numa", .cb = handle_yaml_config_numa },
5524 { .name = "ping", .cb = handle_yaml_no_op },
5525 { .name = "discover", .cb = handle_yaml_no_op },
5526 { .name = "udsp", .cb = handle_yaml_config_udsp },
5529 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5530 { .name = "route", .cb = handle_yaml_del_route },
5531 { .name = "net", .cb = handle_yaml_del_ni },
5532 { .name = "ip2nets", .cb = handle_yaml_no_op },
5533 { .name = "peer", .cb = handle_yaml_del_peer },
5534 { .name = "routing", .cb = handle_yaml_del_routing },
5535 { .name = "buffers", .cb = handle_yaml_no_op },
5536 { .name = "statistics", .cb = handle_yaml_no_op },
5537 { .name = "global", .cb = handle_yaml_del_global_settings},
5538 { .name = "numa", .cb = handle_yaml_del_numa },
5539 { .name = "ping", .cb = handle_yaml_no_op },
5540 { .name = "discover", .cb = handle_yaml_no_op },
5541 { .name = "udsp", .cb = handle_yaml_del_udsp },
5544 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5545 { .name = "route", .cb = handle_yaml_show_route },
5546 { .name = "net", .cb = handle_yaml_show_net },
5547 { .name = "peer", .cb = handle_yaml_show_peers },
5548 { .name = "ip2nets", .cb = handle_yaml_no_op },
5549 { .name = "routing", .cb = handle_yaml_show_routing },
5550 { .name = "buffers", .cb = handle_yaml_show_routing },
5551 { .name = "statistics", .cb = handle_yaml_show_stats },
5552 { .name = "global", .cb = handle_yaml_show_global_settings},
5553 { .name = "numa", .cb = handle_yaml_show_numa },
5554 { .name = "ping", .cb = handle_yaml_no_op },
5555 { .name = "discover", .cb = handle_yaml_no_op },
5556 { .name = "udsp", .cb = handle_yaml_show_udsp },
5559 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5560 { .name = "route", .cb = handle_yaml_no_op },
5561 { .name = "net", .cb = handle_yaml_no_op },
5562 { .name = "peer", .cb = handle_yaml_no_op },
5563 { .name = "ip2nets", .cb = handle_yaml_no_op },
5564 { .name = "routing", .cb = handle_yaml_no_op },
5565 { .name = "buffers", .cb = handle_yaml_no_op },
5566 { .name = "statistics", .cb = handle_yaml_no_op },
5567 { .name = "global", .cb = handle_yaml_no_op },
5568 { .name = "numa", .cb = handle_yaml_no_op },
5569 { .name = "ping", .cb = handle_yaml_ping },
5570 { .name = "discover", .cb = handle_yaml_discover },
5573 static cmd_handler_t lookup_fn(char *key,
5574 struct lookup_cmd_hdlr_tbl *tbl)
5580 for (i = 0; tbl[i].name != NULL; i++) {
5581 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5588 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5589 struct cYAML **show_rc, struct cYAML **err_rc)
5591 struct cYAML *tree, *item = NULL, *head, *child;
5593 char err_str[LNET_MAX_STR_LEN];
5594 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5596 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5598 return LUSTRE_CFG_RC_BAD_PARAM;
5600 child = tree->cy_child;
5601 while (child != NULL) {
5602 cb = lookup_fn(child->cy_string, table);
5604 snprintf(err_str, sizeof(err_str),
5605 "\"call back for '%s' not found\"",
5607 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5608 "yaml", "helper", err_str, err_rc);
5612 if (cYAML_is_sequence(child)) {
5613 while ((head = cYAML_get_next_seq_item(child, &item))
5615 rc = cb(head, show_rc, err_rc);
5616 if (rc != LUSTRE_CFG_RC_NO_ERR)
5620 rc = cb(child, show_rc, err_rc);
5621 if (rc != LUSTRE_CFG_RC_NO_ERR)
5625 child = child->cy_next;
5629 cYAML_free_tree(tree);
5634 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5636 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5640 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5642 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5646 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5648 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5652 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5654 return lustre_yaml_cb_helper(f, lookup_exec_tbl,