4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #define CONFIG_CMD "configure"
59 #define UNCONFIG_CMD "unconfigure"
62 #define SHOW_CMD "show"
64 #define MANAGE_CMD "manage"
66 #define MAX_NUM_IPS 128
68 #define modparam_path "/sys/module/lnet/parameters/"
69 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
70 #define gni_nid_path "/proc/cray_xt/"
72 #ifndef HAVE_USRSPC_RDMA_PS_TCP
73 #define RDMA_PS_TCP 0x0106
76 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
80 * lustre_lnet_ip_range_descr
81 * Describes an IP range.
82 * Each octect is an expression
84 struct lustre_lnet_ip_range_descr {
85 struct list_head ipr_entry;
86 struct list_head ipr_expr;
91 * Describes an ip2nets rule. This can be on a list of rules.
93 struct lustre_lnet_ip2nets {
94 struct lnet_dlc_network_descr ip2nets_net;
95 struct list_head ip2nets_ip_ranges;
98 int open_sysfs_file(const char *path, const char *attr, const int mode)
101 char filename[LNET_MAX_STR_LEN];
103 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
106 snprintf(filename, sizeof(filename), "%s%s",
109 fd = open(filename, mode);
114 static int read_sysfs_file(const char *path, const char *attr,
115 void *val, const size_t size, const int nelem)
118 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
120 fd = open_sysfs_file(path, attr, O_RDONLY);
122 return LUSTRE_CFG_RC_NO_MATCH;
124 if (read(fd, val, size * nelem) == -1)
127 rc = LUSTRE_CFG_RC_NO_ERR;
134 static int write_sysfs_file(const char *path, const char *attr,
135 void *val, const size_t size, const int nelem)
138 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
140 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
142 return LUSTRE_CFG_RC_NO_MATCH;
144 if (write(fd, val, size * nelem) == -1)
147 rc = LUSTRE_CFG_RC_NO_ERR;
156 * frees the memory allocated for an intf descriptor.
158 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
163 if (intf_descr->cpt_expr != NULL)
164 cfs_expr_list_free(intf_descr->cpt_expr);
169 * lustre_lnet_add_ip_range
171 * given a string of the format:
172 * <expr.expr.expr.expr> parse each expr into
173 * a lustre_lnet_ip_range_descr structure and insert on the list.
175 * This function is called from
176 * YAML on each ip-range.
177 * As a result of lnetctl command
178 * When building a NID or P2P selection rules
180 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
182 struct lustre_lnet_ip_range_descr *ip_range;
185 ip_range = calloc(1, sizeof(*ip_range));
186 if (ip_range == NULL)
187 return LUSTRE_CFG_RC_OUT_OF_MEM;
189 INIT_LIST_HEAD(&ip_range->ipr_entry);
190 INIT_LIST_HEAD(&ip_range->ipr_expr);
192 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
193 &ip_range->ipr_expr);
195 return LUSTRE_CFG_RC_BAD_PARAM;
197 list_add_tail(&ip_range->ipr_entry, list);
199 return LUSTRE_CFG_RC_NO_ERR;
202 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
204 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
206 struct lnet_dlc_intf_descr *intf_descr = NULL;
208 char intf_string[LNET_MAX_STR_LEN];
210 if (len >= LNET_MAX_STR_LEN)
211 return LUSTRE_CFG_RC_BAD_PARAM;
213 strncpy(intf_string, intf, len);
214 intf_string[len] = '\0';
216 intf_descr = calloc(1, sizeof(*intf_descr));
217 if (intf_descr == NULL)
218 return LUSTRE_CFG_RC_OUT_OF_MEM;
220 INIT_LIST_HEAD(&intf_descr->intf_on_network);
222 intf_name = intf_string;
223 open_sq_bracket = strchr(intf_string, '[');
224 if (open_sq_bracket != NULL) {
225 close_sq_bracket = strchr(intf_string, ']');
226 if (close_sq_bracket == NULL) {
228 return LUSTRE_CFG_RC_BAD_PARAM;
230 rc = cfs_expr_list_parse(open_sq_bracket,
231 strlen(open_sq_bracket), 0, UINT_MAX,
232 &intf_descr->cpt_expr);
235 return LUSTRE_CFG_RC_BAD_PARAM;
237 strncpy(intf_descr->intf_name, intf_name,
238 open_sq_bracket - intf_name);
239 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
241 strcpy(intf_descr->intf_name, intf_name);
242 intf_descr->cpt_expr = NULL;
245 list_add_tail(&intf_descr->intf_on_network, list);
247 return LUSTRE_CFG_RC_NO_ERR;
250 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
252 if (nw_descr != NULL) {
254 INIT_LIST_HEAD(&nw_descr->network_on_rule);
255 INIT_LIST_HEAD(&nw_descr->nw_intflist);
259 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
260 int max_nids, char *err_str)
262 int rc, num_nids = 0;
263 struct list_head nidlist;
266 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
267 return LUSTRE_CFG_RC_BAD_PARAM;
270 if (strchr(nidstr, '*')) {
271 snprintf(err_str, LNET_MAX_STR_LEN,
272 "asterisk not allowed in nidstring \"%s\"", nidstr);
273 return LUSTRE_CFG_RC_BAD_PARAM;
276 INIT_LIST_HEAD(&nidlist);
277 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
279 snprintf(err_str, LNET_MAX_STR_LEN,
280 "Unable to parse nidlist from: %s\n", nidstr);
281 return LUSTRE_CFG_RC_BAD_PARAM;
284 if (list_empty(&nidlist)) {
285 snprintf(err_str, LNET_MAX_STR_LEN,
286 "\"%s\" does not specify any valid nid lists", nidstr);
287 return LUSTRE_CFG_RC_BAD_PARAM;
290 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
291 cfs_free_nidlist(&nidlist);
293 if (num_nids == -1) {
294 snprintf(err_str, LNET_MAX_STR_LEN,
295 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
297 return LUSTRE_CFG_RC_BAD_PARAM;
301 snprintf(err_str, LNET_MAX_STR_LEN,
302 "Failed to expand nidstr: %s", strerror(num_nids));
303 return LUSTRE_CFG_RC_OUT_OF_MEM;
307 snprintf(err_str, LNET_MAX_STR_LEN,
308 "\"%s\" did not expand to any nids", nidstr);
309 return LUSTRE_CFG_RC_BAD_PARAM;
317 * <intf>[<expr>], <intf>[<expr>],..
319 int lustre_lnet_parse_interfaces(char *intf_str,
320 struct lnet_dlc_network_descr *nw_descr)
325 char *cur = intf_str, *next = NULL;
326 char *end = intf_str + strlen(intf_str);
328 struct lnet_dlc_intf_descr *intf_descr, *tmp;
330 if (nw_descr == NULL)
331 return LUSTRE_CFG_RC_BAD_PARAM;
334 open_square = strchr(cur, '[');
335 if (open_square != NULL) {
336 close_square = strchr(cur, ']');
337 if (close_square == NULL) {
338 rc = LUSTRE_CFG_RC_BAD_PARAM;
342 comma = strchr(cur, ',');
343 if (comma != NULL && comma > close_square) {
345 len = next - close_square;
351 comma = strchr(cur, ',');
361 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
362 if (rc != LUSTRE_CFG_RC_NO_ERR)
368 return LUSTRE_CFG_RC_NO_ERR;
371 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
373 list_del(&intf_descr->intf_on_network);
374 free_intf_descr(intf_descr);
380 int lustre_lnet_config_lib_init(void)
382 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
385 void lustre_lnet_config_lib_uninit(void)
387 unregister_ioc_dev(LNET_DEV_ID);
390 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
391 int seq_no, struct cYAML **err_rc)
393 struct libcfs_ioctl_data data;
396 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
398 LIBCFS_IOC_INIT(data);
400 /* Reverse logic is used here in order not to change
401 * the lctl utility */
402 data.ioc_flags = load_ni_from_mod ? 0 : 1;
404 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
406 rc = l_ioctl(LNET_DEV_ID, opc, &data);
410 "\"LNet %s error: %s\"", (up) ? "configure" :
411 "unconfigure", strerror(errno));
415 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
416 "lnet", err_str, err_rc);
421 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
422 char *err_str, char *cmd_str)
426 rc = l_ioctl(LNET_DEV_ID, cmd, data);
429 snprintf(err_str, LNET_MAX_STR_LEN,
430 "\"%s peer ni operation failed: %s\"",
431 cmd_str, strerror(errno));
437 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
438 int seq_no, struct cYAML **show_rc,
439 struct cYAML **err_rc)
442 struct lnet_ioctl_ping_data ping;
443 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
444 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
445 struct lnet_process_id id;
446 char err_str[LNET_MAX_STR_LEN] = {0};
447 char *sep, *token, *end;
450 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
454 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
456 data = calloc(1, len);
460 /* create struct cYAML root object */
461 root = cYAML_create_object(NULL, NULL);
465 ping_node = cYAML_create_seq(root, oper);
466 if (ping_node == NULL)
469 /* tokenise each nid in string ping_nids */
470 token = strtok(ping_nids, ",");
473 item = cYAML_create_seq_item(ping_node);
477 if (first_seq == NULL)
480 /* check if '-' is a part of NID, token */
481 sep = strchr(token, '-');
483 id.pid = LNET_PID_ANY;
484 /* if no net is specified, libcfs_str2nid() will assume tcp */
485 id.nid = libcfs_str2nid(token);
486 if (id.nid == LNET_NID_ANY) {
487 snprintf(err_str, sizeof(err_str),
488 "\"cannot parse NID '%s'\"",
490 rc = LUSTRE_CFG_RC_BAD_PARAM;
491 cYAML_build_error(rc, seq_no, MANAGE_CMD,
492 oper, err_str, err_rc);
496 if (token[0] == 'u' || token[0] == 'U')
497 id.pid = (strtoul(&token[1], &end, 0) |
498 (LNET_PID_USERFLAG));
500 id.pid = strtoul(token, &end, 0);
502 /* assuming '-' is part of hostname */
504 id.pid = LNET_PID_ANY;
505 id.nid = libcfs_str2nid(token);
506 if (id.nid == LNET_NID_ANY) {
507 snprintf(err_str, sizeof(err_str),
508 "\"cannot parse NID '%s'\"",
510 rc = LUSTRE_CFG_RC_BAD_PARAM;
511 cYAML_build_error(rc, seq_no, MANAGE_CMD,
517 id.nid = libcfs_str2nid(sep + 1);
518 if (id.nid == LNET_NID_ANY) {
519 snprintf(err_str, sizeof(err_str),
520 "\"cannot parse NID '%s'\"",
522 rc = LUSTRE_CFG_RC_BAD_PARAM;
523 cYAML_build_error(rc, seq_no, MANAGE_CMD,
530 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
531 ping.ping_hdr.ioc_len = sizeof(ping);
533 ping.op_param = param;
534 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
535 ping.ping_buf = data;
537 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
540 sizeof(err_str), "failed to %s %s: %s\n", oper,
541 id.pid == LNET_PID_ANY ?
542 libcfs_nid2str(id.nid) :
543 libcfs_id2str(id), strerror(errno));
544 rc = LUSTRE_CFG_RC_BAD_PARAM;
545 cYAML_build_error(rc, seq_no, MANAGE_CMD,
546 oper, err_str, err_rc);
550 if (cYAML_create_string(item, "primary nid",
551 libcfs_nid2str(ping.ping_id.nid)) == NULL)
554 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
555 "True" : "False") == NULL)
558 tmp = cYAML_create_seq(item, "peer ni");
562 for (i = 0; i < ping.ping_count; i++) {
563 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
565 peer_ni = cYAML_create_seq_item(tmp);
568 memset(buf, 0, sizeof buf);
569 snprintf(buf, sizeof buf, "nid");
570 if (cYAML_create_string(peer_ni, buf,
571 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
577 } while ((token = strtok(NULL, ",")) != NULL);
580 rc = LUSTRE_CFG_RC_NO_ERR;
585 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
586 cYAML_free_tree(root);
587 } else if (show_rc != NULL && *show_rc != NULL) {
588 struct cYAML *show_node;
589 show_node = cYAML_get_object_item(*show_rc, oper);
590 if (show_node != NULL && cYAML_is_sequence(show_node)) {
591 cYAML_insert_child(show_node, first_seq);
594 } else if (show_node == NULL) {
595 cYAML_insert_sibling((*show_rc)->cy_child,
599 cYAML_free_tree(root);
608 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
609 struct cYAML **show_rc, struct cYAML **err_rc)
613 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
614 seq_no, show_rc, err_rc);
618 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
619 struct cYAML **show_rc, struct cYAML **err_rc)
623 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
624 seq_no, show_rc, err_rc);
628 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
629 bool is_mr, __u32 cmd,
630 char *cmd_type, char *err_str)
632 struct lnet_ioctl_peer_cfg data;
635 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
636 /* When adding a peer we first need to create the peer using the
637 * specified (or implied) primary nid. Then we can add
638 * additional nids to this peer using the primary nid as a key
640 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
641 data.prcfg_mr = is_mr;
642 data.prcfg_prim_nid = nidlist[0];
643 data.prcfg_cfg_nid = LNET_NID_ANY;
645 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
651 /* Add or delete any specified NIs associated with the specified
652 * (or implied) primary nid
654 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
655 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
656 data.prcfg_mr = is_mr;
657 data.prcfg_prim_nid = nidlist[0];
658 data.prcfg_cfg_nid = nidlist[nid_idx];
660 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
666 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
667 /* In the delete case we may have been given just the
668 * primary nid of the peer. This tells us to delete the peer
669 * completely (rather than just delete some of its NIs)
671 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
672 data.prcfg_prim_nid = nidlist[0];
673 data.prcfg_cfg_nid = LNET_NID_ANY;
675 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
682 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
683 int cmd, int num_nids, bool is_mr, int seq_no,
684 struct cYAML **err_rc)
686 int rc = LUSTRE_CFG_RC_NO_ERR;
687 char err_str[LNET_MAX_STR_LEN];
688 lnet_nid_t *lnet_nidlist2 = NULL;
689 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
690 IOC_LIBCFS_DEL_PEER_NI;
691 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
694 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
695 if (!lnet_nidlist2) {
696 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
697 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
700 lnet_nidlist2[0] = pnid;
701 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
704 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
705 num_nids, is_mr, ioc_cmd,
711 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
716 replace_sep(char *str, char sep, char newsep)
722 for (i = 0; i < strlen(str); i++) {
723 /* don't replace ',' within [] */
726 else if (str[i] == ']')
728 else if (str[i] == sep && bracket == 0)
733 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
734 int cmd, int seq_no, struct cYAML **err_rc)
737 char err_str[LNET_MAX_STR_LEN] = "Error";
738 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
739 lnet_nid_t pnid = LNET_NID_ANY;
742 rc = LUSTRE_CFG_RC_BAD_PARAM;
743 snprintf(err_str, LNET_MAX_STR_LEN,
744 "--prim_nid must be specified");
748 pnid = libcfs_str2nid(prim_nid);
749 if (pnid == LNET_NID_ANY) {
750 rc = LUSTRE_CFG_RC_BAD_PARAM;
751 snprintf(err_str, LNET_MAX_STR_LEN,
752 "badly formatted primary NID: %s", prim_nid);
759 * if there is no primary nid we need to make the first nid in the
760 * nids list the primary nid
762 replace_sep(nids, ',', ' ');
763 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
764 LNET_MAX_NIDS_PER_PEER, err_str);
771 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
772 cmd, num_nids, is_mr,
776 if (rc != LUSTRE_CFG_RC_NO_ERR)
777 cYAML_build_error(rc, -1, "peer",
778 cmd == LNETCTL_ADD_CMD ? "add" : "del",
784 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
785 int sen, int seq_no, struct cYAML **err_rc,
788 int rc, num_nids, idx;
790 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
791 struct lnet_ioctl_config_data data;
792 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
794 if (nw == NULL || nidstr == NULL) {
795 snprintf(err_str, LNET_MAX_STR_LEN,
796 "\"missing mandatory parameter:'%s'\"",
797 (nw == NULL && nidstr == NULL) ? "network, gateway" :
798 (nw == NULL) ? "network" : "gateway");
799 rc = LUSTRE_CFG_RC_MISSING_PARAM;
803 rnet = libcfs_str2net(nw);
804 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
805 snprintf(err_str, LNET_MAX_STR_LEN,
806 "\"cannot parse remote net %s\"", nw);
807 rc = LUSTRE_CFG_RC_BAD_PARAM;
811 replace_sep(nidstr, ',', ' ');
812 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
813 LNET_MAX_NIDS_PER_PEER, err_str);
819 for (idx = 0; idx < num_nids; idx++) {
820 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
822 if (cmd == LNETCTL_ADD_CMD) {
823 data.cfg_config_u.cfg_route.rtr_hop = hops;
824 data.cfg_config_u.cfg_route.rtr_priority = prio;
825 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
828 data.cfg_nid = lnet_nidlist[idx];
830 if (cmd == LNETCTL_ADD_CMD)
831 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
834 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
837 if (rc != 0 && errno != EEXIST &&
838 errno != EHOSTUNREACH) {
840 snprintf(err_str, LNET_MAX_STR_LEN,
841 "route operation failed: %s",
844 } else if (errno == EEXIST) {
846 * continue chugging along if one of the
847 * routes already exists
854 cYAML_build_error(rc, seq_no,
855 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
861 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
862 int sen, int seq_no, struct cYAML **err_rc)
865 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
868 hops = LNET_UNDEFINED_HOPS;
869 } else if (hops < 1 || hops > 255) {
870 snprintf(err_str, LNET_MAX_STR_LEN,
871 "\"invalid hop count %d, must be between 1 and 255\"",
873 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
879 } else if (prio < 0) {
880 snprintf(err_str, LNET_MAX_STR_LEN,
881 "\"invalid priority %d, must be greater than 0\"",
883 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
889 } else if (sen < 1) {
890 snprintf(err_str, LNET_MAX_STR_LEN,
891 "\"invalid health sensitivity %d, must be 1 or greater\"",
893 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
897 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
898 err_rc, LNETCTL_ADD_CMD);
901 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
906 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
907 struct cYAML **err_rc)
909 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
913 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
914 int seq_no, struct cYAML **show_rc,
915 struct cYAML **err_rc, bool backup)
917 struct lnet_ioctl_config_data data;
918 lnet_nid_t gateway_nid;
919 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
921 __u32 net = LNET_NIDNET(LNET_NID_ANY);
923 struct cYAML *root = NULL, *route = NULL, *item = NULL;
924 struct cYAML *first_seq = NULL;
925 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
929 net = libcfs_str2net(nw);
930 if (net == LNET_NIDNET(LNET_NID_ANY)) {
933 "\"cannot parse net '%s'\"", nw);
934 rc = LUSTRE_CFG_RC_BAD_PARAM;
939 /* show all routes without filtering on net */
940 net = LNET_NIDNET(LNET_NID_ANY);
944 gateway_nid = libcfs_str2nid(gw);
945 if (gateway_nid == LNET_NID_ANY) {
948 "\"cannot parse gateway NID '%s'\"", gw);
949 rc = LUSTRE_CFG_RC_BAD_PARAM;
953 /* show all routes with out filtering on gateway */
954 gateway_nid = LNET_NID_ANY;
956 if ((hops < 1 && hops != -1) || hops > 255) {
959 "\"invalid hop count %d, must be between 0 and 256\"",
961 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
965 /* create struct cYAML root object */
966 root = cYAML_create_object(NULL, NULL);
970 route = cYAML_create_seq(root, "route");
978 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
981 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
987 /* filter on provided data */
988 if (net != LNET_NIDNET(LNET_NID_ANY) &&
992 if (gateway_nid != LNET_NID_ANY &&
993 gateway_nid != data.cfg_nid)
997 hops != data.cfg_config_u.cfg_route.rtr_hop)
1001 prio != data.cfg_config_u.cfg_route.rtr_priority)
1004 /* default rc to -1 incase we hit the goto */
1008 item = cYAML_create_seq_item(route);
1012 if (first_seq == NULL)
1015 if (cYAML_create_string(item, "net",
1016 libcfs_net2str(data.cfg_net)) == NULL)
1019 if (cYAML_create_string(item, "gateway",
1020 libcfs_nid2str(data.cfg_nid)) == NULL)
1024 if (cYAML_create_number(item, "hop",
1025 (int) data.cfg_config_u.
1026 cfg_route.rtr_hop) ==
1030 if (cYAML_create_number(item, "priority",
1032 cfg_route.rtr_priority) == NULL)
1035 if (cYAML_create_number(item, "health_sensitivity",
1037 cfg_route.rtr_sensitivity) == NULL)
1040 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1042 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1046 cYAML_create_string(item, "state",
1048 "up" : "down") == NULL)
1052 cYAML_create_string(item, "type",
1054 "multi-hop" : "single-hop") == NULL)
1059 /* print output iff show_rc is not provided */
1060 if (show_rc == NULL)
1061 cYAML_print_tree(root);
1063 if (l_errno != ENOENT) {
1066 "\"cannot get routes: %s\"",
1071 rc = LUSTRE_CFG_RC_NO_ERR;
1073 snprintf(err_str, sizeof(err_str), "\"success\"");
1075 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1076 cYAML_free_tree(root);
1077 } else if (show_rc != NULL && *show_rc != NULL) {
1078 struct cYAML *show_node;
1079 /* find the route node, if one doesn't exist then
1080 * insert one. Otherwise add to the one there
1082 show_node = cYAML_get_object_item(*show_rc, "route");
1083 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1084 cYAML_insert_child(show_node, first_seq);
1087 } else if (show_node == NULL) {
1088 cYAML_insert_sibling((*show_rc)->cy_child,
1092 cYAML_free_tree(root);
1098 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1103 static int socket_intf_query(int request, char *intf,
1109 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1110 return LUSTRE_CFG_RC_BAD_PARAM;
1112 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1114 return LUSTRE_CFG_RC_BAD_PARAM;
1116 strcpy(ifr->ifr_name, intf);
1117 rc = ioctl(sockfd, request, ifr);
1119 rc = LUSTRE_CFG_RC_BAD_PARAM;
1126 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1131 memset(&ifr, 0, sizeof(ifr));
1132 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1134 return LUSTRE_CFG_RC_BAD_PARAM;
1136 if ((ifr.ifr_flags & IFF_UP) == 0)
1137 return LUSTRE_CFG_RC_BAD_PARAM;
1139 memset(&ifr, 0, sizeof(ifr));
1140 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1142 return LUSTRE_CFG_RC_BAD_PARAM;
1144 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1145 *ip = bswap_32(*ip);
1147 return LUSTRE_CFG_RC_NO_ERR;
1151 * for each interface in the array of interfaces find the IP address of
1152 * that interface, create its nid and add it to an array of NIDs.
1153 * Stop if any of the interfaces is down
1155 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1156 lnet_nid_t **nids, __u32 *nnids,
1157 char *err_str, size_t str_len)
1159 int i = 0, count = 0, rc;
1160 struct lnet_dlc_intf_descr *intf;
1161 char val[LNET_MAX_STR_LEN];
1168 if (nw == NULL || nids == NULL) {
1169 snprintf(err_str, str_len,
1170 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1171 return LUSTRE_CFG_RC_BAD_PARAM;
1174 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1177 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1181 *nids = calloc(count, sizeof(lnet_nid_t));
1182 if (*nids == NULL) {
1183 snprintf(err_str, str_len,
1184 "\"out of memory\"");
1185 return LUSTRE_CFG_RC_OUT_OF_MEM;
1188 * special case the GNI interface since it doesn't have an IP
1189 * address. The assumption is that there can only be one GNI
1190 * interface in the system. No interface name is provided.
1192 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1193 rc = read_sysfs_file(gni_nid_path, "nid", val,
1196 snprintf(err_str, str_len,
1197 "\"cannot read gni nid\"");
1200 gni_num = atoi(val);
1202 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1207 /* look at the other interfaces */
1208 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1209 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1210 /* handle LNDs with numeric interface name */
1211 num = strtoul(intf->intf_name, &endp, 0);
1212 if (endp == intf->intf_name || *endp != '\0') {
1213 rc = LUSTRE_CFG_RC_BAD_PARAM;
1214 snprintf(err_str, str_len,
1215 "\"couldn't query intf %s\"",
1219 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1222 /* handle LNDs with ip interface name */
1223 rc = lustre_lnet_queryip(intf, &ip);
1224 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1225 snprintf(err_str, str_len,
1226 "\"couldn't query intf %s\"",
1230 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1247 * called repeatedly until a match or no more ip range
1249 * ip_range expression
1250 * interface list with all the interface names.
1251 * all the interfaces in the system.
1253 * try to match the ip_range expr to one of the interfaces' IPs in
1254 * the system. If we hit a patch for an interface. Check if that
1255 * interface name is in the list.
1257 * If there are more than one interface in the list, then make sure
1258 * that the IPs for all of these interfaces match the ip ranges
1261 * for each interface in intf_list
1262 * look up the intf name in ifa
1263 * if not there then no match
1264 * check ip obtained from ifa against a match to any of the
1266 * If no match, then fail
1268 * The result is that all the interfaces have to match.
1270 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1271 struct list_head *intf_list,
1272 struct list_head *ip_ranges)
1276 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1277 struct ifaddrs *ifaddr = ifa;
1278 struct lustre_lnet_ip_range_descr *ip_range;
1282 * if there are no explicit interfaces, and no ip ranges, then
1283 * configure the first tcp interface we encounter.
1285 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1286 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1287 if (ifaddr->ifa_addr == NULL)
1290 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1293 family = ifaddr->ifa_addr->sa_family;
1294 if (family == AF_INET &&
1295 strcmp(ifaddr->ifa_name, "lo") != 0) {
1296 rc = lustre_lnet_add_intf_descr
1297 (intf_list, ifaddr->ifa_name,
1298 strlen(ifaddr->ifa_name));
1300 if (rc != LUSTRE_CFG_RC_NO_ERR)
1303 return LUSTRE_CFG_RC_MATCH;
1306 return LUSTRE_CFG_RC_NO_MATCH;
1310 * First interface which matches an IP pattern will be used
1312 if (list_empty(intf_list)) {
1314 * no interfaces provided in the rule, but an ip range is
1315 * provided, so try and match an interface to the ip
1318 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1319 if (ifaddr->ifa_addr == NULL)
1322 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1325 family = ifaddr->ifa_addr->sa_family;
1326 if (family == AF_INET) {
1327 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1330 list_for_each_entry(ip_range, ip_ranges,
1332 rc = cfs_ip_addr_match(bswap_32(ip),
1333 &ip_range->ipr_expr);
1337 rc = lustre_lnet_add_intf_descr
1338 (intf_list, ifaddr->ifa_name,
1339 strlen(ifaddr->ifa_name));
1341 if (rc != LUSTRE_CFG_RC_NO_ERR)
1347 if (!list_empty(intf_list))
1348 return LUSTRE_CFG_RC_MATCH;
1350 return LUSTRE_CFG_RC_NO_MATCH;
1354 * If an interface is explicitly specified the ip-range might or
1355 * might not be specified. if specified the interface needs to match the
1356 * ip-range. If no ip-range then the interfaces are
1357 * automatically matched if they are all up.
1358 * If > 1 interfaces all the interfaces must match for the NI to
1361 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1362 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1363 if (ifaddr->ifa_addr == NULL)
1366 family = ifaddr->ifa_addr->sa_family;
1367 if (family == AF_INET &&
1368 strcmp(intf_descr->intf_name,
1369 ifaddr->ifa_name) == 0)
1373 if (ifaddr == NULL) {
1374 list_del(&intf_descr->intf_on_network);
1375 free_intf_descr(intf_descr);
1379 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1380 list_del(&intf_descr->intf_on_network);
1381 free_intf_descr(intf_descr);
1385 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1388 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1389 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1395 /* no match for this interface */
1396 list_del(&intf_descr->intf_on_network);
1397 free_intf_descr(intf_descr);
1401 return LUSTRE_CFG_RC_MATCH;
1404 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1405 lnet_nid_t **nids, __u32 *nnids,
1406 char *err_str, size_t str_len)
1408 struct ifaddrs *ifa;
1409 int rc = LUSTRE_CFG_RC_NO_ERR;
1411 rc = getifaddrs(&ifa);
1413 snprintf(err_str, str_len,
1414 "\"failed to get interface addresses: %d\"", -errno);
1418 rc = lustre_lnet_match_ip_to_intf(ifa,
1419 &ip2nets->ip2nets_net.nw_intflist,
1420 &ip2nets->ip2nets_ip_ranges);
1421 if (rc != LUSTRE_CFG_RC_MATCH) {
1422 snprintf(err_str, str_len,
1423 "\"couldn't match ip to existing interfaces\"");
1428 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1430 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1441 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1442 struct lnet_ioctl_config_lnd_tunables *tunables,
1443 struct cfs_expr_list *global_cpts,
1444 lnet_nid_t *nids, char *err_str)
1447 struct lnet_ioctl_config_ni *conf;
1448 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1449 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1452 struct lnet_dlc_intf_descr *intf_descr;
1454 struct cfs_expr_list *cpt_expr;
1456 list_for_each_entry(intf_descr, intf_list,
1458 if (tunables != NULL)
1459 len = sizeof(struct lnet_ioctl_config_ni) +
1460 sizeof(struct lnet_ioctl_config_lnd_tunables);
1462 len = sizeof(struct lnet_ioctl_config_ni);
1464 data = calloc(1, len);
1466 return LUSTRE_CFG_RC_OUT_OF_MEM;
1467 conf = (struct lnet_ioctl_config_ni*) data;
1468 if (tunables != NULL)
1469 tun = (struct lnet_ioctl_config_lnd_tunables*)
1472 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1473 conf->lic_cfg_hdr.ioc_len = len;
1474 conf->lic_nid = nids[i];
1475 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1478 if (intf_descr->cpt_expr != NULL)
1479 cpt_expr = intf_descr->cpt_expr;
1480 else if (global_cpts != NULL)
1481 cpt_expr = global_cpts;
1485 if (cpt_expr != NULL) {
1486 count = cfs_expr_list_values(cpt_expr,
1487 LNET_MAX_SHOW_NUM_CPT,
1490 memcpy(conf->lic_cpts, cpt_array,
1491 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1500 conf->lic_ncpts = count;
1502 if (tunables != NULL)
1503 memcpy(tun, tunables, sizeof(*tunables));
1505 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1510 "\"cannot add network: %s\"", strerror(errno));
1518 return LUSTRE_CFG_RC_NO_ERR;
1522 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1523 struct lnet_ioctl_config_lnd_tunables *tunables,
1524 struct cfs_expr_list *global_cpts,
1525 int seq_no, struct cYAML **err_rc)
1527 lnet_nid_t *nids = NULL;
1530 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1535 "\"incomplete ip2nets information\"");
1536 rc = LUSTRE_CFG_RC_BAD_PARAM;
1541 * call below function to resolve the rules into a list of nids.
1542 * The memory is allocated in that function then freed here when
1543 * it's no longer needed.
1545 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1547 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1550 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1551 snprintf(err_str, sizeof(err_str),
1552 "\"no interfaces match ip2nets rules\"");
1556 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1557 tunables, global_cpts, nids,
1564 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1568 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1569 struct cfs_expr_list *global_cpts,
1571 struct lnet_ioctl_config_lnd_tunables *tunables,
1572 int seq_no, struct cYAML **err_rc)
1575 struct lnet_ioctl_config_ni *conf;
1576 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1577 char buf[LNET_MAX_STR_LEN];
1578 int rc = LUSTRE_CFG_RC_NO_ERR;
1579 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1580 lnet_nid_t *nids = NULL;
1584 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1587 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1588 (list_empty(&nw_descr->nw_intflist) &&
1589 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1592 "\"missing mandatory parameters in NI config: '%s'\"",
1593 (nw_descr == NULL) ? "network , interface" :
1594 (nw_descr->nw_id == 0) ? "network" : "interface");
1595 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1599 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1602 "\"ip2net string too long %d\"",
1603 (int)strlen(ip2net));
1604 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1608 if (ip2net != NULL) {
1609 if (tunables != NULL)
1610 len = sizeof(struct lnet_ioctl_config_ni) +
1611 sizeof(struct lnet_ioctl_config_lnd_tunables);
1613 len = sizeof(struct lnet_ioctl_config_ni);
1614 data = calloc(1, len);
1616 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1619 conf = (struct lnet_ioctl_config_ni*) data;
1620 if (tunables != NULL)
1621 tun = (struct lnet_ioctl_config_lnd_tunables*)
1622 (data + sizeof(*conf));
1624 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1625 conf->lic_cfg_hdr.ioc_len = len;
1626 strncpy(conf->lic_legacy_ip2nets, ip2net,
1629 if (global_cpts != NULL) {
1630 count = cfs_expr_list_values(global_cpts,
1631 LNET_MAX_SHOW_NUM_CPT,
1634 memcpy(conf->lic_cpts, cpt_array,
1635 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1644 conf->lic_ncpts = count;
1646 if (tunables != NULL)
1647 memcpy(tun, tunables, sizeof(*tunables));
1649 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1654 "\"cannot add network: %s\"", strerror(errno));
1661 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1662 rc = LUSTRE_CFG_RC_NO_ERR;
1666 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1669 "\"cannot parse net '%s'\"",
1670 libcfs_net2str(nw_descr->nw_id));
1671 rc = LUSTRE_CFG_RC_BAD_PARAM;
1676 * special case the GNI since no interface name is expected
1678 if (list_empty(&nw_descr->nw_intflist) &&
1679 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1682 "\"no interface name provided\"");
1683 rc = LUSTRE_CFG_RC_BAD_PARAM;
1687 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1688 err_str, sizeof(err_str));
1690 rc = LUSTRE_CFG_RC_BAD_PARAM;
1694 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1695 tunables, global_cpts, nids,
1699 if (nw_descr != NULL) {
1700 list_for_each_entry_safe(intf_descr, tmp,
1701 &nw_descr->nw_intflist,
1703 list_del(&intf_descr->intf_on_network);
1704 free_intf_descr(intf_descr);
1708 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1719 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1720 int seq_no, struct cYAML **err_rc)
1722 struct lnet_ioctl_config_ni data;
1723 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1724 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1725 lnet_nid_t *nids = NULL;
1727 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1729 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1732 "\"missing mandatory parameter in deleting NI: '%s'\"",
1733 (nw_descr == NULL) ? "network , interface" :
1734 (nw_descr->nw_id == 0) ? "network" : "interface");
1735 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1739 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1740 return LUSTRE_CFG_RC_NO_ERR;
1742 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1745 "\"cannot parse net '%s'\"",
1746 libcfs_net2str(nw_descr->nw_id));
1747 rc = LUSTRE_CFG_RC_BAD_PARAM;
1751 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1752 err_str, sizeof(err_str));
1754 rc = LUSTRE_CFG_RC_BAD_PARAM;
1759 * no interfaces just the nw_id is specified
1762 nids = calloc(1, sizeof(*nids));
1764 snprintf(err_str, sizeof(err_str),
1765 "\"out of memory\"");
1766 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1769 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1773 for (i = 0; i < nnids; i++) {
1774 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1775 data.lic_nid = nids[i];
1777 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1782 "\"cannot del network: %s\"", strerror(errno));
1786 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1788 list_del(&intf_descr->intf_on_network);
1789 free_intf_descr(intf_descr);
1793 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1802 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1803 enum lnet_health_type type, char *name,
1804 int seq_no, struct cYAML **err_rc)
1806 struct lnet_ioctl_reset_health_cfg data;
1807 int rc = LUSTRE_CFG_RC_NO_ERR;
1808 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1810 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1811 data.rh_type = type;
1813 data.rh_value = value;
1816 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1820 sizeof(err_str), "Can not configure health value: %s",
1824 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1829 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1830 struct cYAML **err_rc)
1834 nid = libcfs_str2nid(ni_nid);
1837 return lustre_lnet_config_healthv(value, all, nid,
1838 LNET_HEALTH_TYPE_LOCAL_NI,
1839 "ni healthv", seq_no, err_rc);
1842 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1843 int seq_no, struct cYAML **err_rc)
1847 nid = libcfs_str2nid(lpni_nid);
1850 return lustre_lnet_config_healthv(value, all, nid,
1851 LNET_HEALTH_TYPE_PEER_NI,
1852 "peer_ni healthv", seq_no, err_rc);
1856 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1857 struct lnet_ioctl_comm_count *counts)
1859 if (cYAML_create_number(yaml, "put",
1860 counts->ico_put_count)
1863 if (cYAML_create_number(yaml, "get",
1864 counts->ico_get_count)
1867 if (cYAML_create_number(yaml, "reply",
1868 counts->ico_reply_count)
1871 if (cYAML_create_number(yaml, "ack",
1872 counts->ico_ack_count)
1875 if (cYAML_create_number(yaml, "hello",
1876 counts->ico_hello_count)
1883 static struct lnet_ioctl_comm_count *
1884 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1887 return &msg_stats->im_send_stats;
1889 return &msg_stats->im_recv_stats;
1891 return &msg_stats->im_drop_stats;
1896 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1897 struct cYAML **show_rc, struct cYAML **err_rc,
1901 struct lnet_ioctl_config_ni *ni_data;
1902 struct lnet_ioctl_config_lnd_tunables *lnd;
1903 struct lnet_ioctl_element_stats *stats;
1904 struct lnet_ioctl_element_msg_stats msg_stats;
1905 struct lnet_ioctl_local_ni_hstats hstats;
1906 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1907 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1908 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1910 struct cYAML *root = NULL, *tunables = NULL,
1911 *net_node = NULL, *interfaces = NULL,
1912 *item = NULL, *first_seq = NULL,
1913 *tmp = NULL, *statistics = NULL,
1915 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1916 char str_buf[str_buf_len];
1918 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
1919 bool exist = false, new_net = true;
1921 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1923 buf = calloc(1, buf_size);
1927 ni_data = (struct lnet_ioctl_config_ni *)buf;
1930 net = libcfs_str2net(nw);
1931 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1934 "\"cannot parse net '%s'\"", nw);
1935 rc = LUSTRE_CFG_RC_BAD_PARAM;
1940 root = cYAML_create_object(NULL, NULL);
1944 net_node = cYAML_create_seq(root, "net");
1945 if (net_node == NULL)
1951 memset(buf, 0, buf_size);
1953 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1955 * set the ioc_len to the proper value since INIT assumes
1958 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1959 ni_data->lic_idx = i;
1961 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1967 rc_net = LNET_NIDNET(ni_data->lic_nid);
1969 /* filter on provided data */
1970 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1974 /* if we're backing up don't store lo */
1975 if (backup && LNET_NETTYP(rc_net) == LOLND)
1978 /* default rc to -1 in case we hit the goto */
1982 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
1983 lnd = (struct lnet_ioctl_config_lnd_tunables *)
1984 (ni_data->lic_bulk + sizeof(*stats));
1986 if (rc_net != prev_net) {
1993 if (!cYAML_create_string(net_node, "net type",
1994 libcfs_net2str(rc_net)))
1997 tmp = cYAML_create_seq(net_node, "local NI(s)");
2003 /* create the tree to be printed. */
2004 item = cYAML_create_seq_item(tmp);
2008 if (first_seq == NULL)
2012 cYAML_create_string(item, "nid",
2013 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2017 cYAML_create_string(item,
2019 (ni_data->lic_status ==
2020 LNET_NI_STATUS_UP) ?
2021 "up" : "down") == NULL)
2024 /* don't add interfaces unless there is at least one
2026 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2027 interfaces = cYAML_create_object(item, "interfaces");
2028 if (interfaces == NULL)
2031 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2032 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2034 sizeof(str_buf), "%d", j);
2035 if (cYAML_create_string(interfaces,
2037 ni_data->lic_ni_intf[j]) ==
2049 goto continue_without_msg_stats;
2051 statistics = cYAML_create_object(item, "statistics");
2052 if (statistics == NULL)
2055 if (cYAML_create_number(statistics, "send_count",
2056 stats->iel_send_count)
2060 if (cYAML_create_number(statistics, "recv_count",
2061 stats->iel_recv_count)
2065 if (cYAML_create_number(statistics, "drop_count",
2066 stats->iel_drop_count)
2071 goto continue_without_msg_stats;
2073 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2074 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2075 msg_stats.im_idx = i;
2077 rc = l_ioctl(LNET_DEV_ID,
2078 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2082 goto continue_without_msg_stats;
2085 for (k = 0; k < 3; k++) {
2086 struct lnet_ioctl_comm_count *counts;
2087 struct cYAML *msg_statistics = NULL;
2089 msg_statistics = cYAML_create_object(item,
2090 (char *)gmsg_stat_names[k]);
2091 if (msg_statistics == NULL)
2094 counts = get_counts(&msg_stats, k);
2098 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2103 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2104 hstats.hlni_nid = ni_data->lic_nid;
2105 /* grab health stats */
2106 rc = l_ioctl(LNET_DEV_ID,
2107 IOC_LIBCFS_GET_LOCAL_HSTATS,
2111 goto continue_without_msg_stats;
2113 yhstats = cYAML_create_object(item, "health stats");
2116 if (cYAML_create_number(yhstats, "health value",
2117 hstats.hlni_health_value)
2120 if (cYAML_create_number(yhstats, "interrupts",
2121 hstats.hlni_local_interrupt)
2124 if (cYAML_create_number(yhstats, "dropped",
2125 hstats.hlni_local_dropped)
2128 if (cYAML_create_number(yhstats, "aborted",
2129 hstats.hlni_local_aborted)
2132 if (cYAML_create_number(yhstats, "no route",
2133 hstats.hlni_local_no_route)
2136 if (cYAML_create_number(yhstats, "timeouts",
2137 hstats.hlni_local_timeout)
2140 if (cYAML_create_number(yhstats, "error",
2141 hstats.hlni_local_error)
2145 continue_without_msg_stats:
2146 tunables = cYAML_create_object(item, "tunables");
2150 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2151 if (rc != LUSTRE_CFG_RC_NO_ERR)
2154 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2156 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2157 rc != LUSTRE_CFG_RC_NO_MATCH)
2160 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2161 tunables = cYAML_create_object(item,
2163 if (tunables == NULL)
2168 cYAML_create_number(item, "dev cpt",
2169 ni_data->lic_dev_cpt) == NULL)
2173 cYAML_create_number(item, "tcp bonding",
2174 ni_data->lic_tcp_bonding)
2178 /* out put the CPTs in the format: "[x,x,x,...]" */
2180 limit = str_buf + str_buf_len - 3;
2181 pos += scnprintf(pos, limit - pos, "\"[");
2182 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2183 j < ni_data->lic_ncpts &&
2185 pos += scnprintf(pos, limit - pos,
2186 "%d", ni_data->lic_cpts[j]);
2187 if ((j + 1) < ni_data->lic_ncpts)
2188 pos += scnprintf(pos, limit - pos, ",");
2190 snprintf(pos, 3, "]\"");
2192 if (ni_data->lic_ncpts >= 1 &&
2193 cYAML_create_string(item, "CPT",
2199 /* Print out the net information only if show_rc is not provided */
2200 if (show_rc == NULL)
2201 cYAML_print_tree(root);
2203 if (l_errno != ENOENT) {
2206 "\"cannot get networks: %s\"",
2211 rc = LUSTRE_CFG_RC_NO_ERR;
2213 snprintf(err_str, sizeof(err_str), "\"success\"");
2215 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2216 cYAML_free_tree(root);
2217 } else if (show_rc != NULL && *show_rc != NULL) {
2218 struct cYAML *show_node;
2219 /* find the net node, if one doesn't exist
2220 * then insert one. Otherwise add to the one there
2222 show_node = cYAML_get_object_item(*show_rc, "net");
2223 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2224 cYAML_insert_child(show_node, first_seq);
2227 } else if (show_node == NULL) {
2228 cYAML_insert_sibling((*show_rc)->cy_child,
2232 cYAML_free_tree(root);
2238 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2243 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2245 struct lnet_ioctl_config_data data;
2246 int rc = LUSTRE_CFG_RC_NO_ERR;
2247 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2249 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2250 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2252 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2257 "\"cannot %s routing %s\"",
2258 (enable) ? "enable" : "disable", strerror(errno));
2263 cYAML_build_error(rc, seq_no,
2264 (enable) ? ADD_CMD : DEL_CMD,
2265 "routing", err_str, err_rc);
2270 int ioctl_set_value(__u32 val, int ioc, char *name,
2271 int seq_no, struct cYAML **err_rc)
2273 struct lnet_ioctl_set_value data;
2274 int rc = LUSTRE_CFG_RC_NO_ERR;
2275 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2277 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2278 data.sv_value = val;
2280 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2285 "\"cannot configure %s to %d: %s\"", name,
2286 val, strerror(errno));
2289 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2294 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2296 int rc = LUSTRE_CFG_RC_NO_ERR;
2297 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2298 char val[LNET_MAX_STR_LEN];
2300 snprintf(val, sizeof(val), "%d", intrv);
2302 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2303 1, strlen(val) + 1);
2305 snprintf(err_str, sizeof(err_str),
2306 "\"cannot configure recovery interval: %s\"",
2309 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2314 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2316 int rc = LUSTRE_CFG_RC_NO_ERR;
2317 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2318 char val[LNET_MAX_STR_LEN];
2320 snprintf(val, sizeof(val), "%d", sen);
2322 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2323 1, strlen(val) + 1);
2325 snprintf(err_str, sizeof(err_str),
2326 "\"cannot configure router health sensitivity: %s\"",
2329 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2334 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2336 int rc = LUSTRE_CFG_RC_NO_ERR;
2337 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2338 char val[LNET_MAX_STR_LEN];
2340 snprintf(val, sizeof(val), "%d", sen);
2342 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2343 1, strlen(val) + 1);
2345 snprintf(err_str, sizeof(err_str),
2346 "\"cannot configure health sensitivity: %s\"",
2349 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2354 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2356 int rc = LUSTRE_CFG_RC_NO_ERR;
2357 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2358 char val[LNET_MAX_STR_LEN];
2360 snprintf(val, sizeof(val), "%d", timeout);
2362 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2363 1, strlen(val) + 1);
2365 snprintf(err_str, sizeof(err_str),
2366 "\"cannot configure transaction timeout: %s\"",
2369 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2374 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2376 int rc = LUSTRE_CFG_RC_NO_ERR;
2377 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2378 char val[LNET_MAX_STR_LEN];
2380 snprintf(val, sizeof(val), "%d", count);
2382 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2383 1, strlen(val) + 1);
2385 snprintf(err_str, sizeof(err_str),
2386 "\"cannot configure retry count: %s\"",
2389 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2394 int lustre_lnet_config_response_tracking(int val, int seq_no,
2395 struct cYAML **err_rc)
2397 int rc = LUSTRE_CFG_RC_NO_ERR;
2398 char err_str[LNET_MAX_STR_LEN];
2399 char val_str[LNET_MAX_STR_LEN];
2401 if (val < 0 || val > 3) {
2402 rc = LUSTRE_CFG_RC_BAD_PARAM;
2403 snprintf(err_str, sizeof(err_str),
2404 "\"Valid values are: 0, 1, 2, or 3\"");
2406 snprintf(err_str, sizeof(err_str), "\"success\"");
2408 snprintf(val_str, sizeof(val_str), "%d", val);
2410 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2411 val_str, 1, strlen(val_str) + 1);
2413 snprintf(err_str, sizeof(err_str),
2414 "\"cannot configure response tracking: %s\"",
2418 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2424 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2426 int rc = LUSTRE_CFG_RC_NO_ERR;
2427 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2428 char val[LNET_MAX_STR_LEN];
2430 snprintf(val, sizeof(val), "%d", max);
2432 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2433 1, strlen(val) + 1);
2435 snprintf(err_str, sizeof(err_str),
2436 "\"cannot configure max interfaces: %s\"",
2439 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2444 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2446 int rc = LUSTRE_CFG_RC_NO_ERR;
2447 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2448 char val[LNET_MAX_STR_LEN];
2450 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2452 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2453 1, strlen(val) + 1);
2455 snprintf(err_str, sizeof(err_str),
2456 "\"cannot configure discovery: %s\"",
2459 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2465 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2466 struct cYAML **err_rc)
2468 int rc = LUSTRE_CFG_RC_NO_ERR;
2469 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2470 char val[LNET_MAX_STR_LEN];
2472 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2474 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2475 1, strlen(val) + 1);
2477 snprintf(err_str, sizeof(err_str),
2478 "\"cannot configure drop asym route: %s\"",
2481 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2488 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2490 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2491 "numa_range", seq_no, err_rc);
2494 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2495 struct cYAML **err_rc)
2497 struct lnet_ioctl_config_data data;
2498 int rc = LUSTRE_CFG_RC_NO_ERR;
2499 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2501 /* -1 indicates to ignore changes to this field */
2502 if (tiny < -1 || small < -1 || large < -1) {
2505 "\"tiny, small and large must be >= 0\"");
2506 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2510 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2511 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2512 data.cfg_config_u.cfg_buffers.buf_small = small;
2513 data.cfg_config_u.cfg_buffers.buf_large = large;
2515 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2520 "\"cannot configure buffers: %s\"", strerror(errno));
2525 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2530 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2531 struct cYAML **err_rc, bool backup)
2533 struct lnet_ioctl_config_data *data;
2534 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2535 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2538 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2539 int buf_count[LNET_NRBPOOLS] = {0};
2540 struct cYAML *root = NULL, *pools_node = NULL,
2541 *type_node = NULL, *item = NULL, *cpt = NULL,
2542 *first_seq = NULL, *buffers = NULL;
2544 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2545 char node_name[LNET_MAX_STR_LEN];
2548 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2552 data = (struct lnet_ioctl_config_data *)buf;
2554 root = cYAML_create_object(NULL, NULL);
2559 pools_node = cYAML_create_object(root, "routing");
2561 pools_node = cYAML_create_seq(root, "routing");
2562 if (pools_node == NULL)
2566 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2567 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2568 sizeof(struct lnet_ioctl_pool_cfg);
2569 data->cfg_count = i;
2571 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2579 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2582 goto calculate_buffers;
2584 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2585 item = cYAML_create_seq_item(pools_node);
2589 if (first_seq == NULL)
2592 cpt = cYAML_create_object(item, node_name);
2597 /* create the tree and print */
2598 for (j = 0; j < LNET_NRBPOOLS; j++) {
2600 type_node = cYAML_create_object(cpt, pools[j]);
2601 if (type_node == NULL)
2605 cYAML_create_number(type_node, "npages",
2606 pool_cfg->pl_pools[j].pl_npages)
2610 cYAML_create_number(type_node, "nbuffers",
2611 pool_cfg->pl_pools[j].
2612 pl_nbuffers) == NULL)
2615 cYAML_create_number(type_node, "credits",
2616 pool_cfg->pl_pools[j].
2617 pl_credits) == NULL)
2620 cYAML_create_number(type_node, "mincredits",
2621 pool_cfg->pl_pools[j].
2622 pl_mincredits) == NULL)
2624 /* keep track of the total count for each of the
2625 * tiny, small and large buffers */
2626 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2630 if (pool_cfg != NULL) {
2632 if (cYAML_create_number(pools_node, "enable",
2633 pool_cfg->pl_routing) ==
2637 goto add_buffer_section;
2640 item = cYAML_create_seq_item(pools_node);
2644 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2650 /* create a buffers entry in the show. This is necessary so that
2651 * if the YAML output is used to configure a node, the buffer
2652 * configuration takes hold */
2653 buffers = cYAML_create_object(root, "buffers");
2654 if (buffers == NULL)
2657 for (i = 0; i < LNET_NRBPOOLS; i++) {
2658 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2662 if (show_rc == NULL)
2663 cYAML_print_tree(root);
2665 if (l_errno != ENOENT) {
2668 "\"cannot get routing information: %s\"",
2673 rc = LUSTRE_CFG_RC_NO_ERR;
2675 snprintf(err_str, sizeof(err_str), "\"success\"");
2676 rc = LUSTRE_CFG_RC_NO_ERR;
2680 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2681 cYAML_free_tree(root);
2682 } else if (show_rc != NULL && *show_rc != NULL) {
2683 struct cYAML *routing_node;
2684 /* there should exist only one routing block and one
2685 * buffers block. If there already exists a previous one
2686 * then don't add another */
2687 routing_node = cYAML_get_object_item(*show_rc, "routing");
2688 if (routing_node == NULL) {
2689 cYAML_insert_sibling((*show_rc)->cy_child,
2693 cYAML_free_tree(root);
2699 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2704 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2705 struct cYAML **show_rc, struct cYAML **err_rc,
2709 * TODO: This function is changing in a future patch to accommodate
2710 * PEER_LIST and proper filtering on any nid of the peer
2712 struct lnet_ioctl_peer_cfg peer_info;
2713 struct lnet_peer_ni_credit_info *lpni_cri;
2714 struct lnet_ioctl_element_stats *lpni_stats;
2715 struct lnet_ioctl_element_msg_stats *msg_stats;
2716 struct lnet_ioctl_peer_ni_hstats *hstats;
2718 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2723 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2724 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2725 *msg_statistics = NULL, *statistics = NULL,
2727 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2728 struct lnet_process_id *list = NULL;
2733 /* create struct cYAML root object */
2734 root = cYAML_create_object(NULL, NULL);
2738 peer_root = cYAML_create_seq(root, "peer");
2739 if (peer_root == NULL)
2743 size = count * sizeof(struct lnet_process_id);
2744 list = malloc(size);
2750 list[0].nid = libcfs_str2nid(knid);
2754 memset(&peer_info, 0, sizeof(peer_info));
2755 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2756 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2757 peer_info.prcfg_size = size;
2758 peer_info.prcfg_bulk = list;
2761 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2763 count = peer_info.prcfg_count;
2767 if (l_errno != E2BIG) {
2770 "\"cannot get peer list: %s\"",
2776 size = peer_info.prcfg_size;
2777 list = malloc(size);
2786 data = malloc(size);
2792 for (i = 0; i < count; i++) {
2794 memset(&peer_info, 0, sizeof(peer_info));
2795 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2796 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2797 peer_info.prcfg_prim_nid = list[i].nid;
2798 peer_info.prcfg_size = size;
2799 peer_info.prcfg_bulk = data;
2802 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2807 if (l_errno != E2BIG) {
2810 "\"cannot get peer information: %s\"",
2816 size = peer_info.prcfg_size;
2817 data = malloc(size);
2825 peer = cYAML_create_seq_item(peer_root);
2829 if (first_seq == NULL)
2832 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2833 if (cYAML_create_string(peer, "primary nid",
2834 libcfs_nid2str(pnid))
2837 if (cYAML_create_string(peer, "Multi-Rail",
2838 peer_info.prcfg_mr ? "True" : "False")
2842 * print out the state of the peer only if details are
2847 cYAML_create_number(peer, "peer state",
2848 peer_info.prcfg_state)
2853 tmp = cYAML_create_seq(peer, "peer ni");
2858 for (j = 0; j < peer_info.prcfg_count; j++) {
2860 lpni_cri = (void*)nidp + sizeof(nidp);
2861 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2862 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2863 hstats = (void *)msg_stats + sizeof(*msg_stats);
2864 lpni_data = (void *)hstats + sizeof(*hstats);
2866 peer_ni = cYAML_create_seq_item(tmp);
2867 if (peer_ni == NULL)
2870 if (cYAML_create_string(peer_ni, "nid",
2871 libcfs_nid2str(*nidp))
2878 if (cYAML_create_string(peer_ni, "state",
2879 lpni_cri->cr_aliveness)
2886 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2887 lpni_cri->cr_ni_peer_tx_credits)
2891 if (cYAML_create_number(peer_ni, "available_tx_credits",
2892 lpni_cri->cr_peer_tx_credits)
2896 if (cYAML_create_number(peer_ni, "min_tx_credits",
2897 lpni_cri->cr_peer_min_tx_credits)
2901 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2902 lpni_cri->cr_peer_tx_qnob)
2906 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2907 lpni_cri->cr_peer_rtr_credits)
2911 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2912 lpni_cri->cr_peer_min_rtr_credits)
2916 if (cYAML_create_number(peer_ni, "refcount",
2917 lpni_cri->cr_refcount) == NULL)
2920 statistics = cYAML_create_object(peer_ni, "statistics");
2921 if (statistics == NULL)
2924 if (cYAML_create_number(statistics, "send_count",
2925 lpni_stats->iel_send_count)
2929 if (cYAML_create_number(statistics, "recv_count",
2930 lpni_stats->iel_recv_count)
2934 if (cYAML_create_number(statistics, "drop_count",
2935 lpni_stats->iel_drop_count)
2942 for (k = 0; k < 3; k++) {
2943 struct lnet_ioctl_comm_count *counts;
2945 msg_statistics = cYAML_create_object(peer_ni,
2946 (char *) gmsg_stat_names[k]);
2947 if (msg_statistics == NULL)
2950 counts = get_counts(msg_stats, k);
2954 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2959 yhstats = cYAML_create_object(peer_ni, "health stats");
2962 if (cYAML_create_number(yhstats, "health value",
2963 hstats->hlpni_health_value)
2966 if (cYAML_create_number(yhstats, "dropped",
2967 hstats->hlpni_remote_dropped)
2970 if (cYAML_create_number(yhstats, "timeout",
2971 hstats->hlpni_remote_timeout)
2974 if (cYAML_create_number(yhstats, "error",
2975 hstats->hlpni_remote_error)
2978 if (cYAML_create_number(yhstats, "network timeout",
2979 hstats->hlpni_network_timeout)
2985 /* print output iff show_rc is not provided */
2986 if (show_rc == NULL)
2987 cYAML_print_tree(root);
2989 snprintf(err_str, sizeof(err_str), "\"success\"");
2990 rc = LUSTRE_CFG_RC_NO_ERR;
2995 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2996 cYAML_free_tree(root);
2997 } else if (show_rc != NULL && *show_rc != NULL) {
2998 struct cYAML *show_node;
2999 /* find the peer node, if one doesn't exist then
3000 * insert one. Otherwise add to the one there
3002 show_node = cYAML_get_object_item(*show_rc,
3004 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3005 cYAML_insert_child(show_node, first_seq);
3008 } else if (show_node == NULL) {
3009 cYAML_insert_sibling((*show_rc)->cy_child,
3013 cYAML_free_tree(root);
3019 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3025 int lustre_lnet_list_peer(int seq_no,
3026 struct cYAML **show_rc, struct cYAML **err_rc)
3028 struct lnet_ioctl_peer_cfg peer_info;
3029 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3034 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3035 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3036 struct lnet_process_id *list = NULL;
3038 memset(&peer_info, 0, sizeof(peer_info));
3040 /* create struct cYAML root object */
3041 root = cYAML_create_object(NULL, NULL);
3045 list_root = cYAML_create_seq(root, "peer list");
3046 if (list_root == NULL)
3050 size = count * sizeof(struct lnet_process_id);
3051 list = malloc(size);
3057 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3058 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3059 peer_info.prcfg_size = size;
3060 peer_info.prcfg_bulk = list;
3063 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3064 count = peer_info.prcfg_count;
3068 if (l_errno != E2BIG) {
3071 "\"cannot get peer list: %s\"",
3077 size = peer_info.prcfg_size;
3078 list = malloc(size);
3085 /* count is now the actual number of ids in the list. */
3086 for (i = 0; i < count; i++) {
3087 if (cYAML_create_string(list_root, "nid",
3088 libcfs_nid2str(list[i].nid))
3093 /* print output iff show_rc is not provided */
3094 if (show_rc == NULL)
3095 cYAML_print_tree(root);
3097 snprintf(err_str, sizeof(err_str), "\"success\"");
3098 rc = LUSTRE_CFG_RC_NO_ERR;
3103 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3104 cYAML_free_tree(root);
3105 } else if (show_rc != NULL && *show_rc != NULL) {
3106 struct cYAML *show_node;
3107 /* find the peer node, if one doesn't exist then
3108 * insert one. Otherwise add to the one there
3110 show_node = cYAML_get_object_item(*show_rc,
3112 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3113 cYAML_insert_child(show_node, first_seq);
3116 } else if (show_node == NULL) {
3117 cYAML_insert_sibling((*show_rc)->cy_child,
3121 cYAML_free_tree(root);
3127 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3133 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3136 struct cYAML *show_node;
3138 show_node = cYAML_get_object_item(show_rc, "global");
3139 if (show_node != NULL)
3140 cYAML_insert_sibling(show_node->cy_child,
3143 cYAML_insert_sibling(show_rc->cy_child,
3148 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3149 char *name, __u64 value,
3150 struct cYAML **show_rc,
3151 struct cYAML **err_rc, int err)
3153 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3154 struct cYAML *root = NULL, *global = NULL;
3161 root = cYAML_create_object(NULL, NULL);
3165 global = cYAML_create_object(root, "global");
3169 if (cYAML_create_number(global, name,
3173 if (show_rc == NULL)
3174 cYAML_print_tree(root);
3176 snprintf(err_str, err_len, "\"success\"");
3178 rc = LUSTRE_CFG_RC_NO_ERR;
3181 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3182 cYAML_free_tree(root);
3183 } else if (show_rc != NULL && *show_rc != NULL) {
3184 add_to_global(*show_rc, global, root);
3189 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3194 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3195 struct cYAML **show_rc,
3196 struct cYAML **err_rc)
3198 struct lnet_ioctl_set_value data;
3201 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3203 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3205 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3210 "\"cannot get %s: %s\"",
3211 name, strerror(l_errno));
3214 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3215 data.sv_value, show_rc, err_rc, l_errno);
3218 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3219 struct cYAML **err_rc)
3221 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3222 char val[LNET_MAX_STR_LEN];
3223 int intrv = -1, l_errno = 0;
3224 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3226 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3230 snprintf(err_str, sizeof(err_str),
3231 "\"cannot get recovery interval: %d\"", rc);
3236 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3237 "recovery_interval", intrv, show_rc,
3241 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3242 struct cYAML **err_rc)
3244 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3245 char val[LNET_MAX_STR_LEN];
3246 int sen = -1, l_errno = 0;
3247 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3249 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3253 snprintf(err_str, sizeof(err_str),
3254 "\"cannot get health sensitivity: %d\"", rc);
3259 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3260 "health_sensitivity", sen, show_rc,
3264 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3265 struct cYAML **err_rc)
3267 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3268 char val[LNET_MAX_STR_LEN];
3269 int sen = -1, l_errno = 0;
3270 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3272 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3276 snprintf(err_str, sizeof(err_str),
3277 "\"cannot get router sensitivity percentage: %d\"", rc);
3282 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3283 "router_sensitivity", sen, show_rc,
3287 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3288 struct cYAML **err_rc)
3290 char val[LNET_MAX_STR_LEN];
3291 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3298 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3301 snprintf(err_str, sizeof(err_str),
3302 "\"cannot get LND timeout: %d\"", rc);
3303 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3304 "lnd_timeout", lnd_to, show_rc,
3308 fd = open(path.gl_pathv[0], O_RDONLY);
3311 snprintf(err_str, sizeof(err_str),
3312 "\"error opening %s\"", path.gl_pathv[0]);
3316 rc = read(fd, val, sizeof(val));
3323 snprintf(err_str, sizeof(err_str),
3324 "\"error reading %s\"", path.gl_pathv[0]);
3331 cfs_free_param_data(&path);
3333 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3334 "lnd_timeout", lnd_to, show_rc,
3338 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3339 struct cYAML **err_rc)
3341 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3342 char val[LNET_MAX_STR_LEN];
3343 int tto = -1, l_errno = 0;
3344 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3346 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3350 snprintf(err_str, sizeof(err_str),
3351 "\"cannot get transaction timeout: %d\"", rc);
3356 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3357 "transaction_timeout", tto, show_rc,
3361 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3362 struct cYAML **err_rc)
3364 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3365 char val[LNET_MAX_STR_LEN];
3366 int retry_count = -1, l_errno = 0;
3367 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3369 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3373 snprintf(err_str, sizeof(err_str),
3374 "\"cannot get retry count: %d\"", rc);
3376 retry_count = atoi(val);
3379 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3380 "retry_count", retry_count, show_rc,
3384 int lustre_lnet_calc_service_id(__u64 *service_id)
3386 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3387 char val[LNET_MAX_STR_LEN];
3388 int service_port = -1, l_errno = 0;
3390 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3394 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3395 strerror(l_errno), -l_errno);
3398 service_port = atoi(val);
3401 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3403 return LUSTRE_CFG_RC_NO_ERR;
3406 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3407 struct cYAML **show_rc, struct cYAML **err_rc)
3409 struct lnet_ioctl_recovery_list nid_list;
3410 struct cYAML *root = NULL, *nids = NULL;
3412 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3414 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3415 nid_list.rlst_type = type;
3417 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3423 if (nid_list.rlst_num_nids == 0)
3426 root = cYAML_create_object(NULL, NULL);
3430 nids = cYAML_create_object(root, name);
3436 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3437 char nidenum[LNET_MAX_STR_LEN];
3438 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3439 if (!cYAML_create_string(nids, nidenum,
3440 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3444 snprintf(err_str, sizeof(err_str), "success\n");
3449 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3450 cYAML_free_tree(root);
3451 } else if (show_rc != NULL && *show_rc != NULL) {
3452 struct cYAML *show_node;
3453 /* find the net node, if one doesn't exist
3454 * then insert one. Otherwise add to the one there
3456 show_node = cYAML_get_object_item(*show_rc, name);
3457 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3458 cYAML_insert_child(show_node, nids);
3461 } else if (show_node == NULL) {
3462 cYAML_insert_sibling((*show_rc)->cy_child,
3466 cYAML_free_tree(root);
3472 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3477 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3478 struct cYAML **err_rc)
3480 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3481 seq_no, show_rc, err_rc);
3484 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3485 struct cYAML **err_rc)
3487 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3488 seq_no, show_rc, err_rc);
3491 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
3492 struct cYAML **err_rc)
3494 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3495 char val[LNET_MAX_STR_LEN];
3496 int rsp_tracking = -1, l_errno = 0;
3497 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3499 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
3503 snprintf(err_str, sizeof(err_str),
3504 "\"cannot get lnet_response_tracking value: %d\"", rc);
3506 rsp_tracking = atoi(val);
3509 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3510 "response_tracking", rsp_tracking,
3511 show_rc, err_rc, l_errno);
3514 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3515 struct cYAML **err_rc)
3517 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3518 char val[LNET_MAX_STR_LEN];
3519 int max_intf = -1, l_errno = 0;
3520 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3522 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3526 snprintf(err_str, sizeof(err_str),
3527 "\"cannot get max interfaces: %d\"", rc);
3529 max_intf = atoi(val);
3532 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3533 "max_intf", max_intf, show_rc,
3537 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3538 struct cYAML **err_rc)
3540 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3541 char val[LNET_MAX_STR_LEN];
3542 int discovery = -1, l_errno = 0;
3543 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3545 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3549 snprintf(err_str, sizeof(err_str),
3550 "\"cannot get discovery setting: %d\"", rc);
3553 * The kernel stores a discovery disabled value. User space
3554 * shows whether discovery is enabled. So the value must be
3557 discovery = !atoi(val);
3560 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3561 "discovery", discovery, show_rc,
3565 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3566 struct cYAML **err_rc)
3568 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3569 char val[LNET_MAX_STR_LEN];
3570 int drop_asym_route = -1, l_errno = 0;
3571 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3573 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3577 snprintf(err_str, sizeof(err_str),
3578 "\"cannot get drop asym route setting: %d\"", rc);
3580 drop_asym_route = atoi(val);
3583 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3584 "drop_asym_route", drop_asym_route,
3585 show_rc, err_rc, l_errno);
3588 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3589 struct cYAML **err_rc)
3591 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3592 "numa_range", show_rc, err_rc);
3595 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3596 struct cYAML **err_rc)
3598 struct lnet_ioctl_lnet_stats data;
3599 struct lnet_counters *cntrs;
3602 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3603 struct cYAML *root = NULL, *stats = NULL;
3605 LIBCFS_IOC_INIT_V2(data, st_hdr);
3607 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3612 "\"cannot get lnet statistics: %s\"",
3618 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3620 cntrs = &data.st_cntrs;
3622 root = cYAML_create_object(NULL, NULL);
3626 stats = cYAML_create_object(root, "statistics");
3630 if (!cYAML_create_number(stats, "msgs_alloc",
3631 cntrs->lct_common.lcc_msgs_alloc))
3634 if (!cYAML_create_number(stats, "msgs_max",
3635 cntrs->lct_common.lcc_msgs_max))
3638 if (!cYAML_create_number(stats, "rst_alloc",
3639 cntrs->lct_health.lch_rst_alloc))
3642 if (!cYAML_create_number(stats, "errors",
3643 cntrs->lct_common.lcc_errors))
3646 if (!cYAML_create_number(stats, "send_count",
3647 cntrs->lct_common.lcc_send_count))
3650 if (!cYAML_create_number(stats, "resend_count",
3651 cntrs->lct_health.lch_resend_count))
3654 if (!cYAML_create_number(stats, "response_timeout_count",
3655 cntrs->lct_health.lch_response_timeout_count))
3658 if (!cYAML_create_number(stats, "local_interrupt_count",
3659 cntrs->lct_health.lch_local_interrupt_count))
3662 if (!cYAML_create_number(stats, "local_dropped_count",
3663 cntrs->lct_health.lch_local_dropped_count))
3666 if (!cYAML_create_number(stats, "local_aborted_count",
3667 cntrs->lct_health.lch_local_aborted_count))
3670 if (!cYAML_create_number(stats, "local_no_route_count",
3671 cntrs->lct_health.lch_local_no_route_count))
3674 if (!cYAML_create_number(stats, "local_timeout_count",
3675 cntrs->lct_health.lch_local_timeout_count))
3678 if (!cYAML_create_number(stats, "local_error_count",
3679 cntrs->lct_health.lch_local_error_count))
3682 if (!cYAML_create_number(stats, "remote_dropped_count",
3683 cntrs->lct_health.lch_remote_dropped_count))
3686 if (!cYAML_create_number(stats, "remote_error_count",
3687 cntrs->lct_health.lch_remote_error_count))
3690 if (!cYAML_create_number(stats, "remote_timeout_count",
3691 cntrs->lct_health.lch_remote_timeout_count))
3694 if (!cYAML_create_number(stats, "network_timeout_count",
3695 cntrs->lct_health.lch_network_timeout_count))
3698 if (!cYAML_create_number(stats, "recv_count",
3699 cntrs->lct_common.lcc_recv_count))
3702 if (!cYAML_create_number(stats, "route_count",
3703 cntrs->lct_common.lcc_route_count))
3706 if (!cYAML_create_number(stats, "drop_count",
3707 cntrs->lct_common.lcc_drop_count))
3710 if (!cYAML_create_number(stats, "send_length",
3711 cntrs->lct_common.lcc_send_length))
3714 if (!cYAML_create_number(stats, "recv_length",
3715 cntrs->lct_common.lcc_recv_length))
3718 if (!cYAML_create_number(stats, "route_length",
3719 cntrs->lct_common.lcc_route_length))
3722 if (!cYAML_create_number(stats, "drop_length",
3723 cntrs->lct_common.lcc_drop_length))
3727 cYAML_print_tree(root);
3729 snprintf(err_str, sizeof(err_str), "\"success\"");
3730 rc = LUSTRE_CFG_RC_NO_ERR;
3732 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3733 cYAML_free_tree(root);
3734 } else if (show_rc != NULL && *show_rc != NULL) {
3735 cYAML_insert_sibling((*show_rc)->cy_child,
3742 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3747 typedef int (*cmd_handler_t)(struct cYAML *tree,
3748 struct cYAML **show_rc,
3749 struct cYAML **err_rc);
3751 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3752 struct cYAML **err_rc)
3754 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3756 net = cYAML_get_object_item(tree, "net");
3757 gw = cYAML_get_object_item(tree, "gateway");
3758 hop = cYAML_get_object_item(tree, "hop");
3759 prio = cYAML_get_object_item(tree, "priority");
3760 sen = cYAML_get_object_item(tree, "health_sensitivity");
3761 seq_no = cYAML_get_object_item(tree, "seq_no");
3763 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3764 (gw) ? gw->cy_valuestring : NULL,
3765 (hop) ? hop->cy_valueint : -1,
3766 (prio) ? prio->cy_valueint : -1,
3767 (sen) ? sen->cy_valueint : -1,
3768 (seq_no) ? seq_no->cy_valueint : -1,
3774 * 0: <intf_name>['['<expr>']']
3775 * 1: <intf_name>['['<expr>']']
3777 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3778 struct lnet_dlc_network_descr *nw_descr)
3780 struct cYAML *child = NULL;
3781 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3782 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3784 if (intf_tree == NULL || nw_descr == NULL)
3785 return LUSTRE_CFG_RC_BAD_PARAM;
3787 /* now grab all the interfaces and their cpts */
3788 child = intf_tree->cy_child;
3789 while (child != NULL) {
3790 if (child->cy_valuestring == NULL) {
3791 child = child->cy_next;
3795 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3798 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3799 child->cy_valuestring,
3800 strlen(child->cy_valuestring));
3801 if (rc != LUSTRE_CFG_RC_NO_ERR)
3805 child = child->cy_next;
3809 return LUSTRE_CFG_RC_MISSING_PARAM;
3814 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3816 list_del(&intf_descr->intf_on_network);
3817 free_intf_descr(intf_descr);
3824 yaml_extract_cmn_tunables(struct cYAML *tree,
3825 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3826 struct cfs_expr_list **global_cpts)
3828 struct cYAML *tun, *item, *smp;
3831 tun = cYAML_get_object_item(tree, "tunables");
3833 item = cYAML_get_object_item(tun, "peer_timeout");
3835 tunables->lct_peer_timeout = item->cy_valueint;
3836 item = cYAML_get_object_item(tun, "peer_credits");
3838 tunables->lct_peer_tx_credits = item->cy_valueint;
3839 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3841 tunables->lct_peer_rtr_credits = item->cy_valueint;
3842 item = cYAML_get_object_item(tun, "credits");
3844 tunables->lct_max_tx_credits = item->cy_valueint;
3845 smp = cYAML_get_object_item(tun, "CPT");
3847 rc = cfs_expr_list_parse(smp->cy_valuestring,
3848 strlen(smp->cy_valuestring),
3849 0, UINT_MAX, global_cpts);
3851 *global_cpts = NULL;
3861 yaml_extract_tunables(struct cYAML *tree,
3862 struct lnet_ioctl_config_lnd_tunables *tunables,
3863 struct cfs_expr_list **global_cpts,
3868 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3874 lustre_yaml_extract_lnd_tunables(tree, net_type,
3882 * - net type: <net>[<NUM>]
3884 * - nid: <ip>@<net>[<NUM>]
3887 * 0: <intf_name>['['<expr>']']
3888 * 1: <intf_name>['['<expr>']']
3890 * peer_timeout: <NUM>
3891 * peer_credits: <NUM>
3892 * peer_buffer_credits: <NUM>
3895 * peercredits_hiw: <NUM>
3896 * map_on_demand: <NUM>
3897 * concurrent_sends: <NUM>
3898 * fmr_pool_size: <NUM>
3899 * fmr_flush_trigger: <NUM>
3902 * At least one interface is required. If no interfaces are provided the
3903 * network interface can not be configured.
3905 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3906 struct cYAML **err_rc)
3908 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3910 int num_entries = 0, rc;
3911 struct lnet_dlc_network_descr nw_descr;
3912 struct cfs_expr_list *global_cpts = NULL;
3913 struct lnet_ioctl_config_lnd_tunables tunables;
3916 memset(&tunables, 0, sizeof(tunables));
3918 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3919 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3921 ip2net = cYAML_get_object_item(tree, "ip2net");
3922 net = cYAML_get_object_item(tree, "net type");
3924 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3926 nw_descr.nw_id = LOLND;
3929 * if neither net nor ip2nets are present, then we can not
3930 * configure the network.
3932 if (!net && !ip2net)
3933 return LUSTRE_CFG_RC_MISSING_PARAM;
3935 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3936 if (local_nis == NULL)
3937 return LUSTRE_CFG_RC_MISSING_PARAM;
3939 if (!cYAML_is_sequence(local_nis))
3940 return LUSTRE_CFG_RC_BAD_PARAM;
3942 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3943 intf = cYAML_get_object_item(item, "interfaces");
3946 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3947 if (num_entries <= 0) {
3948 cYAML_build_error(num_entries, -1, "ni", "add",
3949 "bad interface list",
3951 return LUSTRE_CFG_RC_BAD_PARAM;
3955 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3956 LNET_NETTYP(nw_descr.nw_id));
3957 seq_no = cYAML_get_object_item(tree, "seq_no");
3959 rc = lustre_lnet_config_ni(&nw_descr,
3961 (ip2net) ? ip2net->cy_valuestring : NULL,
3962 (found) ? &tunables: NULL,
3963 (seq_no) ? seq_no->cy_valueint : -1,
3966 if (global_cpts != NULL)
3967 cfs_expr_list_free(global_cpts);
3974 * - net-spec: <tcp|o2ib|gni>[NUM]
3976 * 0: <intf name>['['<expr>']']
3977 * 1: <intf name>['['<expr>']']
3979 * 0: <expr.expr.expr.expr>
3980 * 1: <expr.expr.expr.expr>
3982 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3983 struct cYAML **show_rc,
3984 struct cYAML **err_rc)
3986 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3988 struct lustre_lnet_ip2nets ip2nets;
3989 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3991 int rc = LUSTRE_CFG_RC_NO_ERR;
3992 struct cfs_expr_list *global_cpts = NULL;
3993 struct cfs_expr_list *el, *el_tmp;
3994 struct lnet_ioctl_config_lnd_tunables tunables;
3995 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3998 memset(&tunables, 0, sizeof(tunables));
4000 /* initialize all lists */
4001 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4002 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4003 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4005 net = cYAML_get_object_item(tree, "net-spec");
4007 return LUSTRE_CFG_RC_BAD_PARAM;
4009 if (net != NULL && net->cy_valuestring == NULL)
4010 return LUSTRE_CFG_RC_BAD_PARAM;
4012 /* assign the network id */
4013 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4014 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4015 return LUSTRE_CFG_RC_BAD_PARAM;
4017 seq_no = cYAML_get_object_item(tree, "seq_no");
4019 intf = cYAML_get_object_item(tree, "interfaces");
4021 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4023 return LUSTRE_CFG_RC_BAD_PARAM;
4026 ip_range = cYAML_get_object_item(tree, "ip-range");
4027 if (ip_range != NULL) {
4028 item = ip_range->cy_child;
4029 while (item != NULL) {
4030 if (item->cy_valuestring == NULL) {
4031 item = item->cy_next;
4035 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4036 item->cy_valuestring);
4038 if (rc != LUSTRE_CFG_RC_NO_ERR)
4041 item = item->cy_next;
4045 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4046 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4048 rc = lustre_lnet_config_ip2nets(&ip2nets,
4049 (found) ? &tunables : NULL,
4051 (seq_no) ? seq_no->cy_valueint : -1,
4055 * don't stop because there was no match. Continue processing the
4056 * rest of the rules. If non-match then nothing is configured
4058 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4059 rc = LUSTRE_CFG_RC_NO_ERR;
4061 list_for_each_entry_safe(intf_descr, intf_tmp,
4062 &ip2nets.ip2nets_net.nw_intflist,
4064 list_del(&intf_descr->intf_on_network);
4065 free_intf_descr(intf_descr);
4068 list_for_each_entry_safe(ip_range_descr, tmp,
4069 &ip2nets.ip2nets_ip_ranges,
4071 list_del(&ip_range_descr->ipr_entry);
4072 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4074 list_del(&el->el_link);
4075 cfs_expr_list_free(el);
4077 free(ip_range_descr);
4083 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4084 struct cYAML **err_rc)
4086 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4088 int num_entries, rc;
4089 struct lnet_dlc_network_descr nw_descr;
4091 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4092 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4094 net = cYAML_get_object_item(tree, "net type");
4096 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4098 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4099 if (local_nis == NULL)
4100 return LUSTRE_CFG_RC_MISSING_PARAM;
4102 if (!cYAML_is_sequence(local_nis))
4103 return LUSTRE_CFG_RC_BAD_PARAM;
4105 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4106 intf = cYAML_get_object_item(item, "interfaces");
4109 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4110 if (num_entries <= 0) {
4111 cYAML_build_error(num_entries, -1, "ni", "add",
4112 "bad interface list",
4114 return LUSTRE_CFG_RC_BAD_PARAM;
4118 seq_no = cYAML_get_object_item(tree, "seq_no");
4120 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4121 (seq_no) ? seq_no->cy_valueint : -1,
4127 /* Create a nidstring parseable by the nidstrings library from the nid
4128 * information encoded in the CYAML structure.
4129 * NOTE: Caller must free memory allocated to nidstr
4131 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4132 char *prim_nid, int cmd)
4134 int num_strs = 0, rc;
4135 size_t buf_size, buf_pos, nidstr_len = 0;
4137 struct cYAML *child = NULL, *entry = NULL;
4139 if (cYAML_is_sequence(nids_entry)) {
4140 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4141 entry = cYAML_get_object_item(child, "nid");
4142 /* don't count an empty entry */
4143 if (!entry || !entry->cy_valuestring)
4147 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4148 if (cmd == LNETCTL_DEL_CMD) {
4150 * primary nid is present in the list of
4151 * nids so that means we want to delete
4152 * the entire peer, so no need to go
4153 * further. Just delete the entire peer.
4155 return LUSTRE_CFG_RC_NO_ERR;
4162 * + 1 for the space separating each string, and
4163 * accounts for the terminating null char
4165 nidstr_len += strlen(entry->cy_valuestring) + 1;
4170 if (num_strs == 0 && !prim_nid)
4171 return LUSTRE_CFG_RC_MISSING_PARAM;
4172 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4173 return LUSTRE_CFG_RC_NO_ERR;
4175 buffer = malloc(nidstr_len);
4177 return LUSTRE_CFG_RC_OUT_OF_MEM;
4179 /* now grab all the nids */
4182 buf_size = nidstr_len;
4184 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4185 entry = cYAML_get_object_item(child, "nid");
4186 if (!entry || !entry->cy_valuestring)
4190 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4194 rc = snprintf(buffer + buf_pos, buf_size, " ");
4195 buf_pos += (rc < buf_size) ? rc : buf_size;
4196 buf_size = nidstr_len - buf_pos;
4199 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4200 entry->cy_valuestring);
4201 buf_pos += (rc < buf_size) ? rc : buf_size;
4202 buf_size = nidstr_len - buf_pos;
4207 return LUSTRE_CFG_RC_NO_ERR;
4210 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4211 struct cYAML **err_rc, int cmd)
4213 int rc, num_nids = 0, seqn;
4214 bool mr_value = false;
4215 char *nidstr = NULL, *prim_nidstr;
4216 char err_str[LNET_MAX_STR_LEN];
4217 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4218 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4219 lnet_nid_t pnid = LNET_NID_ANY;
4221 seq_no = cYAML_get_object_item(tree, "seq_no");
4222 seqn = seq_no ? seq_no->cy_valueint : -1;
4224 prim_nid = cYAML_get_object_item(tree, "primary nid");
4225 peer_nis = cYAML_get_object_item(tree, "peer ni");
4227 rc = LUSTRE_CFG_RC_BAD_PARAM;
4228 snprintf(err_str, LNET_MAX_STR_LEN,
4229 "\"primary nid\" must be specified");
4233 prim_nidstr = prim_nid->cy_valuestring;
4235 /* if the provided primary NID is bad, no need to go any further */
4236 pnid = libcfs_str2nid(prim_nidstr);
4237 if (pnid == LNET_NID_ANY) {
4238 rc = LUSTRE_CFG_RC_BAD_PARAM;
4239 snprintf(err_str, LNET_MAX_STR_LEN,
4240 "badly formatted primary NID: %s", prim_nidstr);
4244 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4245 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4246 snprintf(err_str, LNET_MAX_STR_LEN,
4247 "No nids defined in YAML block");
4249 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4250 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4252 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4253 snprintf(err_str, LNET_MAX_STR_LEN,
4254 "Unrecognized error %d", rc);
4260 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4261 LNET_MAX_NIDS_PER_PEER,
4269 if (cmd == LNETCTL_ADD_CMD) {
4270 mr = cYAML_get_object_item(tree, "Multi-Rail");
4272 if (mr && mr->cy_valuestring) {
4273 if (strcmp(mr->cy_valuestring, "False") == 0)
4275 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4276 rc = LUSTRE_CFG_RC_BAD_PARAM;
4277 snprintf(err_str, LNET_MAX_STR_LEN,
4278 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4279 mr->cy_valuestring);
4285 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4286 num_nids, mr_value, seqn,
4293 if (rc != LUSTRE_CFG_RC_NO_ERR)
4294 cYAML_build_error(rc, seqn, "peer",
4295 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4301 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4302 struct cYAML **err_rc)
4304 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4307 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4308 struct cYAML **err_rc)
4310 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4313 static int handle_yaml_config_buffers(struct cYAML *tree,
4314 struct cYAML **show_rc,
4315 struct cYAML **err_rc)
4318 struct cYAML *tiny, *small, *large, *seq_no;
4320 tiny = cYAML_get_object_item(tree, "tiny");
4321 small = cYAML_get_object_item(tree, "small");
4322 large = cYAML_get_object_item(tree, "large");
4323 seq_no = cYAML_get_object_item(tree, "seq_no");
4325 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4326 (small) ? small->cy_valueint : -1,
4327 (large) ? large->cy_valueint : -1,
4328 (seq_no) ? seq_no->cy_valueint : -1,
4334 static int handle_yaml_config_routing(struct cYAML *tree,
4335 struct cYAML **show_rc,
4336 struct cYAML **err_rc)
4338 int rc = LUSTRE_CFG_RC_NO_ERR;
4339 struct cYAML *seq_no, *enable;
4341 seq_no = cYAML_get_object_item(tree, "seq_no");
4342 enable = cYAML_get_object_item(tree, "enable");
4345 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4347 seq_no->cy_valueint : -1,
4354 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4355 struct cYAML **err_rc)
4359 struct cYAML *seq_no;
4361 net = cYAML_get_object_item(tree, "net");
4362 gw = cYAML_get_object_item(tree, "gateway");
4363 seq_no = cYAML_get_object_item(tree, "seq_no");
4365 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4366 (gw) ? gw->cy_valuestring : NULL,
4367 (seq_no) ? seq_no->cy_valueint : -1,
4371 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4372 struct cYAML **err_rc)
4374 struct cYAML *seq_no;
4376 seq_no = cYAML_get_object_item(tree, "seq_no");
4378 return lustre_lnet_enable_routing(0, (seq_no) ?
4379 seq_no->cy_valueint : -1,
4383 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4384 struct cYAML **err_rc)
4390 struct cYAML *detail;
4391 struct cYAML *seq_no;
4393 net = cYAML_get_object_item(tree, "net");
4394 gw = cYAML_get_object_item(tree, "gateway");
4395 hop = cYAML_get_object_item(tree, "hop");
4396 prio = cYAML_get_object_item(tree, "priority");
4397 detail = cYAML_get_object_item(tree, "detail");
4398 seq_no = cYAML_get_object_item(tree, "seq_no");
4400 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4401 (gw) ? gw->cy_valuestring : NULL,
4402 (hop) ? hop->cy_valueint : -1,
4403 (prio) ? prio->cy_valueint : -1,
4404 (detail) ? detail->cy_valueint : 0,
4405 (seq_no) ? seq_no->cy_valueint : -1,
4406 show_rc, err_rc, false);
4409 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4410 struct cYAML **err_rc)
4412 struct cYAML *net, *detail, *seq_no;
4414 net = cYAML_get_object_item(tree, "net");
4415 detail = cYAML_get_object_item(tree, "detail");
4416 seq_no = cYAML_get_object_item(tree, "seq_no");
4418 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4419 (detail) ? detail->cy_valueint : 0,
4420 (seq_no) ? seq_no->cy_valueint : -1,
4421 show_rc, err_rc, false);
4424 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4425 struct cYAML **err_rc)
4427 struct cYAML *seq_no;
4429 seq_no = cYAML_get_object_item(tree, "seq_no");
4431 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4432 show_rc, err_rc, false);
4435 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4436 struct cYAML **err_rc)
4438 struct cYAML *seq_no, *nid, *detail;
4440 seq_no = cYAML_get_object_item(tree, "seq_no");
4441 detail = cYAML_get_object_item(tree, "detail");
4442 nid = cYAML_get_object_item(tree, "nid");
4444 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4445 (detail) ? detail->cy_valueint : 0,
4446 (seq_no) ? seq_no->cy_valueint : -1,
4447 show_rc, err_rc, false);
4450 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4451 struct cYAML **err_rc)
4453 struct cYAML *seq_no;
4455 seq_no = cYAML_get_object_item(tree, "seq_no");
4457 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4461 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4462 struct cYAML **err_rc)
4464 struct cYAML *seq_no, *range;
4466 seq_no = cYAML_get_object_item(tree, "seq_no");
4467 range = cYAML_get_object_item(tree, "range");
4469 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4470 seq_no ? seq_no->cy_valueint : -1,
4474 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4475 struct cYAML **err_rc)
4477 struct cYAML *seq_no;
4479 seq_no = cYAML_get_object_item(tree, "seq_no");
4481 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4485 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4486 struct cYAML **err_rc)
4488 struct cYAML *seq_no;
4490 seq_no = cYAML_get_object_item(tree, "seq_no");
4492 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4496 static int handle_yaml_config_global_settings(struct cYAML *tree,
4497 struct cYAML **show_rc,
4498 struct cYAML **err_rc)
4500 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4501 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking;
4504 seq_no = cYAML_get_object_item(tree, "seq_no");
4505 max_intf = cYAML_get_object_item(tree, "max_intf");
4507 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4508 seq_no ? seq_no->cy_valueint
4512 numa = cYAML_get_object_item(tree, "numa_range");
4514 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4515 seq_no ? seq_no->cy_valueint
4519 discovery = cYAML_get_object_item(tree, "discovery");
4521 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4522 seq_no ? seq_no->cy_valueint
4526 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4527 if (drop_asym_route)
4528 rc = lustre_lnet_config_drop_asym_route(
4529 drop_asym_route->cy_valueint,
4530 seq_no ? seq_no->cy_valueint : -1,
4533 retry = cYAML_get_object_item(tree, "retry_count");
4535 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4536 seq_no ? seq_no->cy_valueint
4540 tto = cYAML_get_object_item(tree, "transaction_timeout");
4542 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4543 seq_no ? seq_no->cy_valueint
4547 sen = cYAML_get_object_item(tree, "health_sensitivity");
4549 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4550 seq_no ? seq_no->cy_valueint
4554 recov = cYAML_get_object_item(tree, "recovery_interval");
4556 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4557 seq_no ? seq_no->cy_valueint
4561 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4563 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4564 seq_no ? seq_no->cy_valueint
4568 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4570 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
4571 seq_no ? seq_no->cy_valueint
4578 static int handle_yaml_del_global_settings(struct cYAML *tree,
4579 struct cYAML **show_rc,
4580 struct cYAML **err_rc)
4582 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4585 seq_no = cYAML_get_object_item(tree, "seq_no");
4586 max_intf = cYAML_get_object_item(tree, "max_intf");
4588 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4589 seq_no ? seq_no->cy_valueint
4593 numa = cYAML_get_object_item(tree, "numa_range");
4595 rc = lustre_lnet_config_numa_range(0,
4596 seq_no ? seq_no->cy_valueint
4600 /* peer discovery is enabled by default */
4601 discovery = cYAML_get_object_item(tree, "discovery");
4603 rc = lustre_lnet_config_discovery(1,
4604 seq_no ? seq_no->cy_valueint
4608 /* asymmetrical route messages are accepted by default */
4609 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4610 if (drop_asym_route)
4611 rc = lustre_lnet_config_drop_asym_route(
4612 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4617 static int handle_yaml_show_global_settings(struct cYAML *tree,
4618 struct cYAML **show_rc,
4619 struct cYAML **err_rc)
4621 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4622 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking;
4625 seq_no = cYAML_get_object_item(tree, "seq_no");
4626 max_intf = cYAML_get_object_item(tree, "max_intf");
4628 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4632 numa = cYAML_get_object_item(tree, "numa_range");
4634 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4638 discovery = cYAML_get_object_item(tree, "discovery");
4640 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4644 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4645 if (drop_asym_route)
4646 rc = lustre_lnet_show_drop_asym_route(
4647 seq_no ? seq_no->cy_valueint : -1,
4650 retry = cYAML_get_object_item(tree, "retry_count");
4652 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4656 tto = cYAML_get_object_item(tree, "transaction_timeout");
4658 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4662 sen = cYAML_get_object_item(tree, "health_sensitivity");
4664 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4668 recov = cYAML_get_object_item(tree, "recovery_interval");
4670 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4674 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4676 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4680 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4682 rc = lustre_lnet_show_response_tracking(seq_no ?
4683 seq_no->cy_valueint :
4690 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4691 struct cYAML **err_rc)
4693 struct cYAML *seq_no, *nid, *timeout;
4695 seq_no = cYAML_get_object_item(tree, "seq_no");
4696 nid = cYAML_get_object_item(tree, "primary nid");
4697 timeout = cYAML_get_object_item(tree, "timeout");
4699 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4700 (timeout) ? timeout->cy_valueint : 1000,
4701 (seq_no) ? seq_no->cy_valueint : -1,
4705 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4706 struct cYAML **err_rc)
4708 struct cYAML *seq_no, *nid, *force;
4710 seq_no = cYAML_get_object_item(tree, "seq_no");
4711 nid = cYAML_get_object_item(tree, "primary nid");
4712 force = cYAML_get_object_item(tree, "force");
4714 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4715 (force) ? force->cy_valueint : 0,
4716 (seq_no) ? seq_no->cy_valueint : -1,
4720 static int handle_yaml_no_op()
4722 return LUSTRE_CFG_RC_NO_ERR;
4725 struct lookup_cmd_hdlr_tbl {
4730 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4731 { .name = "route", .cb = handle_yaml_config_route },
4732 { .name = "net", .cb = handle_yaml_config_ni },
4733 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4734 { .name = "peer", .cb = handle_yaml_config_peer },
4735 { .name = "routing", .cb = handle_yaml_config_routing },
4736 { .name = "buffers", .cb = handle_yaml_config_buffers },
4737 { .name = "statistics", .cb = handle_yaml_no_op },
4738 { .name = "global", .cb = handle_yaml_config_global_settings},
4739 { .name = "numa", .cb = handle_yaml_config_numa },
4740 { .name = "ping", .cb = handle_yaml_no_op },
4741 { .name = "discover", .cb = handle_yaml_no_op },
4744 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4745 { .name = "route", .cb = handle_yaml_del_route },
4746 { .name = "net", .cb = handle_yaml_del_ni },
4747 { .name = "ip2nets", .cb = handle_yaml_no_op },
4748 { .name = "peer", .cb = handle_yaml_del_peer },
4749 { .name = "routing", .cb = handle_yaml_del_routing },
4750 { .name = "buffers", .cb = handle_yaml_no_op },
4751 { .name = "statistics", .cb = handle_yaml_no_op },
4752 { .name = "global", .cb = handle_yaml_del_global_settings},
4753 { .name = "numa", .cb = handle_yaml_del_numa },
4754 { .name = "ping", .cb = handle_yaml_no_op },
4755 { .name = "discover", .cb = handle_yaml_no_op },
4758 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4759 { .name = "route", .cb = handle_yaml_show_route },
4760 { .name = "net", .cb = handle_yaml_show_net },
4761 { .name = "peer", .cb = handle_yaml_show_peers },
4762 { .name = "ip2nets", .cb = handle_yaml_no_op },
4763 { .name = "routing", .cb = handle_yaml_show_routing },
4764 { .name = "buffers", .cb = handle_yaml_show_routing },
4765 { .name = "statistics", .cb = handle_yaml_show_stats },
4766 { .name = "global", .cb = handle_yaml_show_global_settings},
4767 { .name = "numa", .cb = handle_yaml_show_numa },
4768 { .name = "ping", .cb = handle_yaml_no_op },
4769 { .name = "discover", .cb = handle_yaml_no_op },
4772 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4773 { .name = "route", .cb = handle_yaml_no_op },
4774 { .name = "net", .cb = handle_yaml_no_op },
4775 { .name = "peer", .cb = handle_yaml_no_op },
4776 { .name = "ip2nets", .cb = handle_yaml_no_op },
4777 { .name = "routing", .cb = handle_yaml_no_op },
4778 { .name = "buffers", .cb = handle_yaml_no_op },
4779 { .name = "statistics", .cb = handle_yaml_no_op },
4780 { .name = "global", .cb = handle_yaml_no_op },
4781 { .name = "numa", .cb = handle_yaml_no_op },
4782 { .name = "ping", .cb = handle_yaml_ping },
4783 { .name = "discover", .cb = handle_yaml_discover },
4786 static cmd_handler_t lookup_fn(char *key,
4787 struct lookup_cmd_hdlr_tbl *tbl)
4793 for (i = 0; tbl[i].name != NULL; i++) {
4794 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4801 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4802 struct cYAML **show_rc, struct cYAML **err_rc)
4804 struct cYAML *tree, *item = NULL, *head, *child;
4806 char err_str[LNET_MAX_STR_LEN];
4807 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4809 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4811 return LUSTRE_CFG_RC_BAD_PARAM;
4813 child = tree->cy_child;
4814 while (child != NULL) {
4815 cb = lookup_fn(child->cy_string, table);
4817 snprintf(err_str, sizeof(err_str),
4818 "\"call back for '%s' not found\"",
4820 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4821 "yaml", "helper", err_str, err_rc);
4825 if (cYAML_is_sequence(child)) {
4826 while ((head = cYAML_get_next_seq_item(child, &item))
4828 rc = cb(head, show_rc, err_rc);
4829 if (rc != LUSTRE_CFG_RC_NO_ERR)
4833 rc = cb(child, show_rc, err_rc);
4834 if (rc != LUSTRE_CFG_RC_NO_ERR)
4838 child = child->cy_next;
4842 cYAML_free_tree(tree);
4847 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4849 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4853 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4855 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4859 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4861 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4865 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4867 return lustre_yaml_cb_helper(f, lookup_exec_tbl,