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 #define CONFIG_CMD "configure"
57 #define UNCONFIG_CMD "unconfigure"
60 #define SHOW_CMD "show"
62 #define MANAGE_CMD "manage"
64 #define MAX_NUM_IPS 128
66 #define modparam_path "/sys/module/lnet/parameters/"
67 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
68 #define gni_nid_path "/proc/cray_xt/"
70 #ifndef HAVE_USRSPC_RDMA_PS_TCP
71 #define RDMA_PS_TCP 0x0106
74 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
78 * lustre_lnet_ip_range_descr
79 * Describes an IP range.
80 * Each octect is an expression
82 struct lustre_lnet_ip_range_descr {
83 struct list_head ipr_entry;
84 struct list_head ipr_expr;
89 * Describes an ip2nets rule. This can be on a list of rules.
91 struct lustre_lnet_ip2nets {
92 struct lnet_dlc_network_descr ip2nets_net;
93 struct list_head ip2nets_ip_ranges;
96 int open_sysfs_file(const char *path, const char *attr, const int mode)
99 char filename[LNET_MAX_STR_LEN];
101 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
104 snprintf(filename, sizeof(filename), "%s%s",
107 fd = open(filename, mode);
112 static int read_sysfs_file(const char *path, const char *attr,
113 void *val, const size_t size, const int nelem)
116 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
118 fd = open_sysfs_file(path, attr, O_RDONLY);
120 return LUSTRE_CFG_RC_NO_MATCH;
122 if (read(fd, val, size * nelem) == -1)
125 rc = LUSTRE_CFG_RC_NO_ERR;
132 static int write_sysfs_file(const char *path, const char *attr,
133 void *val, const size_t size, const int nelem)
136 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
138 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
140 return LUSTRE_CFG_RC_NO_MATCH;
142 if (write(fd, val, size * nelem) == -1)
145 rc = LUSTRE_CFG_RC_NO_ERR;
154 * frees the memory allocated for an intf descriptor.
156 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
161 if (intf_descr->cpt_expr != NULL)
162 cfs_expr_list_free(intf_descr->cpt_expr);
167 * lustre_lnet_add_ip_range
169 * given a string of the format:
170 * <expr.expr.expr.expr> parse each expr into
171 * a lustre_lnet_ip_range_descr structure and insert on the list.
173 * This function is called from
174 * YAML on each ip-range.
175 * As a result of lnetctl command
176 * When building a NID or P2P selection rules
178 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
180 struct lustre_lnet_ip_range_descr *ip_range;
183 ip_range = calloc(1, sizeof(*ip_range));
184 if (ip_range == NULL)
185 return LUSTRE_CFG_RC_OUT_OF_MEM;
187 INIT_LIST_HEAD(&ip_range->ipr_entry);
188 INIT_LIST_HEAD(&ip_range->ipr_expr);
190 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
191 &ip_range->ipr_expr);
193 return LUSTRE_CFG_RC_BAD_PARAM;
195 list_add_tail(&ip_range->ipr_entry, list);
197 return LUSTRE_CFG_RC_NO_ERR;
200 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
202 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
204 struct lnet_dlc_intf_descr *intf_descr = NULL;
206 char intf_string[LNET_MAX_STR_LEN];
208 if (len >= LNET_MAX_STR_LEN)
209 return LUSTRE_CFG_RC_BAD_PARAM;
211 strncpy(intf_string, intf, len);
212 intf_string[len] = '\0';
214 intf_descr = calloc(1, sizeof(*intf_descr));
215 if (intf_descr == NULL)
216 return LUSTRE_CFG_RC_OUT_OF_MEM;
218 INIT_LIST_HEAD(&intf_descr->intf_on_network);
220 intf_name = intf_string;
221 open_sq_bracket = strchr(intf_string, '[');
222 if (open_sq_bracket != NULL) {
223 close_sq_bracket = strchr(intf_string, ']');
224 if (close_sq_bracket == NULL) {
226 return LUSTRE_CFG_RC_BAD_PARAM;
228 rc = cfs_expr_list_parse(open_sq_bracket,
229 strlen(open_sq_bracket), 0, UINT_MAX,
230 &intf_descr->cpt_expr);
233 return LUSTRE_CFG_RC_BAD_PARAM;
235 strncpy(intf_descr->intf_name, intf_name,
236 open_sq_bracket - intf_name);
237 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
239 strcpy(intf_descr->intf_name, intf_name);
240 intf_descr->cpt_expr = NULL;
243 list_add_tail(&intf_descr->intf_on_network, list);
245 return LUSTRE_CFG_RC_NO_ERR;
248 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
250 if (nw_descr != NULL) {
252 INIT_LIST_HEAD(&nw_descr->network_on_rule);
253 INIT_LIST_HEAD(&nw_descr->nw_intflist);
257 int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
259 int bracket = 0, num_str = 0;
260 char *strstart, *chptr;
263 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
264 return LUSTRE_CFG_RC_BAD_PARAM;
267 /* comma-separated nidranges -> space-separated nidranges */
271 if (*chptr == '\0') {
272 out[num_str] = strstart;
279 else if (*chptr == ']')
283 snprintf(err_str, LNET_MAX_STR_LEN,
284 "Mismatched brackets in nidstring \"%s\"",
286 return LUSTRE_CFG_RC_BAD_PARAM;
289 if (bracket == 0 && *chptr == ',') {
290 out[num_str] = strstart;
293 strstart = chptr + 1;
300 snprintf(err_str, LNET_MAX_STR_LEN,
301 "Mismatched brackets in nidstring \"%s\"", nidstr);
302 return LUSTRE_CFG_RC_BAD_PARAM;
308 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
309 int max_nids, char *err_str)
311 int rc, num_nids = 0;
312 struct list_head nidlist;
315 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
316 return LUSTRE_CFG_RC_BAD_PARAM;
319 if (strchr(nidstr, '*')) {
320 snprintf(err_str, LNET_MAX_STR_LEN,
321 "asterisk not allowed in nidstring \"%s\"", nidstr);
322 return LUSTRE_CFG_RC_BAD_PARAM;
325 INIT_LIST_HEAD(&nidlist);
326 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
328 snprintf(err_str, LNET_MAX_STR_LEN,
329 "Unable to parse nidlist from: %s\n", nidstr);
330 return LUSTRE_CFG_RC_BAD_PARAM;
333 if (list_empty(&nidlist)) {
334 snprintf(err_str, LNET_MAX_STR_LEN,
335 "\"%s\" does not specify any valid nid lists", nidstr);
336 return LUSTRE_CFG_RC_BAD_PARAM;
339 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
341 if (num_nids == -1) {
342 snprintf(err_str, LNET_MAX_STR_LEN,
343 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
345 return LUSTRE_CFG_RC_BAD_PARAM;
349 snprintf(err_str, LNET_MAX_STR_LEN,
350 "Failed to expand nidstr: %s", strerror(num_nids));
351 return LUSTRE_CFG_RC_OUT_OF_MEM;
355 snprintf(err_str, LNET_MAX_STR_LEN,
356 "\"%s\" did not expand to any nids", nidstr);
357 return LUSTRE_CFG_RC_BAD_PARAM;
365 * <intf>[<expr>], <intf>[<expr>],..
367 int lustre_lnet_parse_interfaces(char *intf_str,
368 struct lnet_dlc_network_descr *nw_descr)
373 char *cur = intf_str, *next = NULL;
374 char *end = intf_str + strlen(intf_str);
376 struct lnet_dlc_intf_descr *intf_descr, *tmp;
378 if (nw_descr == NULL)
379 return LUSTRE_CFG_RC_BAD_PARAM;
382 open_square = strchr(cur, '[');
383 if (open_square != NULL) {
384 close_square = strchr(cur, ']');
385 if (close_square == NULL) {
386 rc = LUSTRE_CFG_RC_BAD_PARAM;
390 comma = strchr(cur, ',');
391 if (comma != NULL && comma > close_square) {
393 len = next - close_square;
399 comma = strchr(cur, ',');
409 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
410 if (rc != LUSTRE_CFG_RC_NO_ERR)
416 return LUSTRE_CFG_RC_NO_ERR;
419 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
421 list_del(&intf_descr->intf_on_network);
422 free_intf_descr(intf_descr);
428 int lustre_lnet_config_lib_init(void)
430 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
433 void lustre_lnet_config_lib_uninit(void)
435 unregister_ioc_dev(LNET_DEV_ID);
438 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
439 int seq_no, struct cYAML **err_rc)
441 struct libcfs_ioctl_data data;
444 char err_str[LNET_MAX_STR_LEN];
446 snprintf(err_str, sizeof(err_str), "\"Success\"");
448 LIBCFS_IOC_INIT(data);
450 /* Reverse logic is used here in order not to change
451 * the lctl utility */
452 data.ioc_flags = load_ni_from_mod ? 0 : 1;
454 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
456 rc = l_ioctl(LNET_DEV_ID, opc, &data);
460 "\"LNet %s error: %s\"", (up) ? "configure" :
461 "unconfigure", strerror(errno));
465 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
466 "lnet", err_str, err_rc);
471 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
472 char *err_str, char *cmd_str)
476 rc = l_ioctl(LNET_DEV_ID, cmd, data);
479 snprintf(err_str, LNET_MAX_STR_LEN,
480 "\"%s peer ni operation failed: %s\"",
481 cmd_str, strerror(errno));
487 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
488 int seq_no, struct cYAML **show_rc,
489 struct cYAML **err_rc)
492 struct lnet_ioctl_ping_data ping;
493 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
494 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
495 struct lnet_process_id id;
496 char err_str[LNET_MAX_STR_LEN] = {0};
497 char *sep, *token, *end;
500 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
504 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
506 data = calloc(1, len);
510 /* create struct cYAML root object */
511 root = cYAML_create_object(NULL, NULL);
515 ping_node = cYAML_create_seq(root, oper);
516 if (ping_node == NULL)
519 /* tokenise each nid in string ping_nids */
520 token = strtok(ping_nids, ",");
523 item = cYAML_create_seq_item(ping_node);
527 if (first_seq == NULL)
530 /* check if '-' is a part of NID, token */
531 sep = strchr(token, '-');
533 id.pid = LNET_PID_ANY;
534 /* if no net is specified, libcfs_str2nid() will assume tcp */
535 id.nid = libcfs_str2nid(token);
536 if (id.nid == LNET_NID_ANY) {
537 snprintf(err_str, sizeof(err_str),
538 "\"cannot parse NID '%s'\"",
540 rc = LUSTRE_CFG_RC_BAD_PARAM;
541 cYAML_build_error(rc, seq_no, MANAGE_CMD,
542 oper, err_str, err_rc);
546 if (token[0] == 'u' || token[0] == 'U')
547 id.pid = (strtoul(&token[1], &end, 0) |
548 (LNET_PID_USERFLAG));
550 id.pid = strtoul(token, &end, 0);
552 /* assuming '-' is part of hostname */
554 id.pid = LNET_PID_ANY;
555 id.nid = libcfs_str2nid(token);
556 if (id.nid == LNET_NID_ANY) {
557 snprintf(err_str, sizeof(err_str),
558 "\"cannot parse NID '%s'\"",
560 rc = LUSTRE_CFG_RC_BAD_PARAM;
561 cYAML_build_error(rc, seq_no, MANAGE_CMD,
567 id.nid = libcfs_str2nid(sep + 1);
568 if (id.nid == LNET_NID_ANY) {
569 snprintf(err_str, sizeof(err_str),
570 "\"cannot parse NID '%s'\"",
572 rc = LUSTRE_CFG_RC_BAD_PARAM;
573 cYAML_build_error(rc, seq_no, MANAGE_CMD,
580 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
581 ping.ping_hdr.ioc_len = sizeof(ping);
583 ping.op_param = param;
584 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
585 ping.ping_buf = data;
587 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
590 sizeof(err_str), "failed to %s %s: %s\n", oper,
591 id.pid == LNET_PID_ANY ?
592 libcfs_nid2str(id.nid) :
593 libcfs_id2str(id), strerror(errno));
594 rc = LUSTRE_CFG_RC_BAD_PARAM;
595 cYAML_build_error(rc, seq_no, MANAGE_CMD,
596 oper, err_str, err_rc);
600 if (cYAML_create_string(item, "primary nid",
601 libcfs_nid2str(ping.ping_id.nid)) == NULL)
604 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
605 "True" : "False") == NULL)
608 tmp = cYAML_create_seq(item, "peer ni");
612 for (i = 0; i < ping.ping_count; i++) {
613 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
616 peer_ni = cYAML_create_seq_item(tmp);
619 memset(buf, 0, sizeof buf);
620 snprintf(buf, sizeof buf, "nid");
621 if (cYAML_create_string(peer_ni, buf,
622 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
628 } while ((token = strtok(NULL, ",")) != NULL);
631 rc = LUSTRE_CFG_RC_NO_ERR;
636 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
637 cYAML_free_tree(root);
638 } else if (show_rc != NULL && *show_rc != NULL) {
639 struct cYAML *show_node;
640 show_node = cYAML_get_object_item(*show_rc, oper);
641 if (show_node != NULL && cYAML_is_sequence(show_node)) {
642 cYAML_insert_child(show_node, first_seq);
645 } else if (show_node == NULL) {
646 cYAML_insert_sibling((*show_rc)->cy_child,
650 cYAML_free_tree(root);
659 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
660 struct cYAML **show_rc, struct cYAML **err_rc)
664 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
665 seq_no, show_rc, err_rc);
669 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
670 struct cYAML **show_rc, struct cYAML **err_rc)
674 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
675 seq_no, show_rc, err_rc);
679 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
680 bool is_mr, __u32 cmd,
681 char *cmd_type, char *err_str)
683 struct lnet_ioctl_peer_cfg data;
686 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
687 /* When adding a peer we first need to create the peer using the
688 * specified (or implied) primary nid. Then we can add
689 * additional nids to this peer using the primary nid as a key
691 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
692 data.prcfg_mr = is_mr;
693 data.prcfg_prim_nid = nidlist[0];
694 data.prcfg_cfg_nid = LNET_NID_ANY;
696 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
702 /* Add or delete any specified NIs associated with the specified
703 * (or implied) primary nid
705 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
706 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
707 data.prcfg_mr = is_mr;
708 data.prcfg_prim_nid = nidlist[0];
709 data.prcfg_cfg_nid = nidlist[nid_idx];
711 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
717 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
718 /* In the delete case we may have been given just the
719 * primary nid of the peer. This tells us to delete the peer
720 * completely (rather than just delete some of its NIs)
722 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
723 data.prcfg_prim_nid = nidlist[0];
724 data.prcfg_cfg_nid = LNET_NID_ANY;
726 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
732 int lustre_lnet_config_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
733 int num_nids, bool is_mr, int seq_no,
734 struct cYAML **err_rc)
736 int rc = LUSTRE_CFG_RC_NO_ERR;
737 char err_str[LNET_MAX_STR_LEN];
738 lnet_nid_t *lnet_nidlist2 = NULL;
742 pnid = libcfs_str2nid(pnidstr);
743 if (pnid == LNET_NID_ANY) {
744 snprintf(err_str, LNET_MAX_STR_LEN,
745 "bad primary NID: '%s'", pnidstr);
746 rc = LUSTRE_CFG_RC_MISSING_PARAM;
752 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
753 if (!lnet_nidlist2) {
754 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
755 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
758 lnet_nidlist2[0] = pnid;
759 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
763 rc = lustre_lnet_handle_peer_nidlist((pnidstr) ? lnet_nidlist2 :
766 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
772 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
776 int lustre_lnet_del_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
777 int num_nids, int seq_no,
778 struct cYAML **err_rc)
780 int rc = LUSTRE_CFG_RC_NO_ERR;
781 char err_str[LNET_MAX_STR_LEN];
782 lnet_nid_t *lnet_nidlist2 = NULL;
786 snprintf(err_str, sizeof(err_str),
787 "\"Primary nid is not provided\"");
788 rc = LUSTRE_CFG_RC_MISSING_PARAM;
792 pnid = libcfs_str2nid(pnidstr);
793 if (pnid == LNET_NID_ANY) {
794 rc = LUSTRE_CFG_RC_BAD_PARAM;
795 snprintf(err_str, sizeof(err_str),
802 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
803 if (!lnet_nidlist2) {
804 snprintf(err_str, sizeof(err_str),
806 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
809 lnet_nidlist2[0] = pnid;
810 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
813 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2, num_nids, false,
814 IOC_LIBCFS_DEL_PEER_NI, DEL_CMD,
820 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
824 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
825 int sen, int seq_no, struct cYAML **err_rc,
828 int rc, num_nids, num_nidstrs, nid_idx, str_idx;
830 char err_str[LNET_MAX_STR_LEN];
831 char *nidstrarray[LNET_MAX_STR_LEN];
832 struct lnet_ioctl_config_data data;
833 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
835 if (nw == NULL || nidstr == NULL) {
836 snprintf(err_str, LNET_MAX_STR_LEN,
837 "\"missing mandatory parameter:'%s'\"",
838 (nw == NULL && nidstr == NULL) ? "network, gateway" :
839 (nw == NULL) ? "network" : "gateway");
840 rc = LUSTRE_CFG_RC_MISSING_PARAM;
844 rnet = libcfs_str2net(nw);
845 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
846 snprintf(err_str, LNET_MAX_STR_LEN,
847 "\"cannot parse remote net %s\"", nw);
848 rc = LUSTRE_CFG_RC_BAD_PARAM;
852 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
858 for (str_idx = 0; str_idx < num_nidstrs; str_idx++) {
859 rc = lustre_lnet_parse_nidstr(nidstrarray[str_idx],
861 LNET_MAX_NIDS_PER_PEER, err_str);
867 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
869 if (cmd == LNETCTL_ADD_CMD) {
870 data.cfg_config_u.cfg_route.rtr_hop = hops;
871 data.cfg_config_u.cfg_route.rtr_priority = prio;
872 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
875 for (nid_idx = 0; nid_idx < num_nids; nid_idx++) {
876 data.cfg_nid = lnet_nidlist[nid_idx];
878 if (cmd == LNETCTL_ADD_CMD)
879 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
882 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
885 if (rc != 0 && errno != EEXIST &&
886 errno != EHOSTUNREACH) {
888 snprintf(err_str, LNET_MAX_STR_LEN,
889 "route operation failed: %s",
897 cYAML_build_error(rc, seq_no,
898 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
904 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
905 int sen, int seq_no, struct cYAML **err_rc)
908 char err_str[LNET_MAX_STR_LEN];
911 hops = LNET_UNDEFINED_HOPS;
912 } else if (hops < 1 || hops > 255) {
913 snprintf(err_str, LNET_MAX_STR_LEN,
914 "\"invalid hop count %d, must be between 1 and 255\"",
916 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
922 } else if (prio < 0) {
923 snprintf(err_str, LNET_MAX_STR_LEN,
924 "\"invalid priority %d, must be greater than 0\"",
926 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
932 } else if (sen < 1) {
933 snprintf(err_str, LNET_MAX_STR_LEN,
934 "\"invalid health sensitivity %d, must be 1 or greater\"",
936 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
940 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
941 err_rc, LNETCTL_ADD_CMD);
943 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
948 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
949 struct cYAML **err_rc)
951 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
955 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
956 int seq_no, struct cYAML **show_rc,
957 struct cYAML **err_rc, bool backup)
959 struct lnet_ioctl_config_data data;
960 lnet_nid_t gateway_nid;
961 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
963 __u32 net = LNET_NIDNET(LNET_NID_ANY);
965 struct cYAML *root = NULL, *route = NULL, *item = NULL;
966 struct cYAML *first_seq = NULL;
967 char err_str[LNET_MAX_STR_LEN];
970 snprintf(err_str, sizeof(err_str),
971 "\"out of memory\"");
974 net = libcfs_str2net(nw);
975 if (net == LNET_NIDNET(LNET_NID_ANY)) {
978 "\"cannot parse net '%s'\"", nw);
979 rc = LUSTRE_CFG_RC_BAD_PARAM;
984 /* show all routes without filtering on net */
985 net = LNET_NIDNET(LNET_NID_ANY);
989 gateway_nid = libcfs_str2nid(gw);
990 if (gateway_nid == LNET_NID_ANY) {
993 "\"cannot parse gateway NID '%s'\"", gw);
994 rc = LUSTRE_CFG_RC_BAD_PARAM;
998 /* show all routes with out filtering on gateway */
999 gateway_nid = LNET_NID_ANY;
1001 if ((hops < 1 && hops != -1) || hops > 255) {
1004 "\"invalid hop count %d, must be between 0 and 256\"",
1006 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1010 /* create struct cYAML root object */
1011 root = cYAML_create_object(NULL, NULL);
1015 route = cYAML_create_seq(root, "route");
1023 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1026 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1032 /* filter on provided data */
1033 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1034 net != data.cfg_net)
1037 if (gateway_nid != LNET_NID_ANY &&
1038 gateway_nid != data.cfg_nid)
1042 hops != data.cfg_config_u.cfg_route.rtr_hop)
1046 prio != data.cfg_config_u.cfg_route.rtr_priority)
1049 /* default rc to -1 incase we hit the goto */
1053 item = cYAML_create_seq_item(route);
1057 if (first_seq == NULL)
1060 if (cYAML_create_string(item, "net",
1061 libcfs_net2str(data.cfg_net)) == NULL)
1064 if (cYAML_create_string(item, "gateway",
1065 libcfs_nid2str(data.cfg_nid)) == NULL)
1069 if (cYAML_create_number(item, "hop",
1070 (int) data.cfg_config_u.
1071 cfg_route.rtr_hop) ==
1075 if (cYAML_create_number(item, "priority",
1077 cfg_route.rtr_priority) == NULL)
1080 if (cYAML_create_number(item, "health_sensitivity",
1082 cfg_route.rtr_sensitivity) == NULL)
1085 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1087 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1091 cYAML_create_string(item, "state",
1093 "up" : "down") == NULL)
1097 cYAML_create_string(item, "type",
1099 "multi-hop" : "single-hop") == NULL)
1104 /* print output iff show_rc is not provided */
1105 if (show_rc == NULL)
1106 cYAML_print_tree(root);
1108 if (l_errno != ENOENT) {
1111 "\"cannot get routes: %s\"",
1116 rc = LUSTRE_CFG_RC_NO_ERR;
1118 snprintf(err_str, sizeof(err_str), "\"success\"");
1120 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1121 cYAML_free_tree(root);
1122 } else if (show_rc != NULL && *show_rc != NULL) {
1123 struct cYAML *show_node;
1124 /* find the route node, if one doesn't exist then
1125 * insert one. Otherwise add to the one there
1127 show_node = cYAML_get_object_item(*show_rc, "route");
1128 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1129 cYAML_insert_child(show_node, first_seq);
1132 } else if (show_node == NULL) {
1133 cYAML_insert_sibling((*show_rc)->cy_child,
1137 cYAML_free_tree(root);
1143 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1148 static int socket_intf_query(int request, char *intf,
1154 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1155 return LUSTRE_CFG_RC_BAD_PARAM;
1157 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1159 return LUSTRE_CFG_RC_BAD_PARAM;
1161 strcpy(ifr->ifr_name, intf);
1162 rc = ioctl(sockfd, request, ifr);
1164 rc = LUSTRE_CFG_RC_BAD_PARAM;
1171 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1176 memset(&ifr, 0, sizeof(ifr));
1177 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1179 return LUSTRE_CFG_RC_BAD_PARAM;
1181 if ((ifr.ifr_flags & IFF_UP) == 0)
1182 return LUSTRE_CFG_RC_BAD_PARAM;
1184 memset(&ifr, 0, sizeof(ifr));
1185 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1187 return LUSTRE_CFG_RC_BAD_PARAM;
1189 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1190 *ip = bswap_32(*ip);
1192 return LUSTRE_CFG_RC_NO_ERR;
1196 * for each interface in the array of interfaces find the IP address of
1197 * that interface, create its nid and add it to an array of NIDs.
1198 * Stop if any of the interfaces is down
1200 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1201 lnet_nid_t **nids, __u32 *nnids,
1202 char *err_str, size_t str_len)
1204 int i = 0, count = 0, rc;
1205 struct lnet_dlc_intf_descr *intf;
1206 char val[LNET_MAX_STR_LEN];
1213 if (nw == NULL || nids == NULL) {
1214 snprintf(err_str, str_len,
1215 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1216 err_str[str_len - 1] = '\0';
1217 return LUSTRE_CFG_RC_BAD_PARAM;
1220 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1223 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1227 *nids = calloc(count, sizeof(lnet_nid_t));
1228 if (*nids == NULL) {
1229 snprintf(err_str, str_len,
1230 "\"out of memory\"");
1231 err_str[str_len - 1] = '\0';
1232 return LUSTRE_CFG_RC_OUT_OF_MEM;
1235 * special case the GNI interface since it doesn't have an IP
1236 * address. The assumption is that there can only be one GNI
1237 * interface in the system. No interface name is provided.
1239 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1240 rc = read_sysfs_file(gni_nid_path, "nid", val,
1243 snprintf(err_str, str_len,
1244 "\"cannot read gni nid\"");
1245 err_str[str_len - 1] = '\0';
1248 gni_num = atoi(val);
1250 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1255 /* look at the other interfaces */
1256 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1257 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1258 /* handle LNDs with numeric interface name */
1259 num = strtoul(intf->intf_name, &endp, 0);
1260 if (endp == intf->intf_name || *endp != '\0') {
1261 rc = LUSTRE_CFG_RC_BAD_PARAM;
1262 snprintf(err_str, str_len,
1263 "\"couldn't query intf %s\"",
1265 err_str[str_len - 1] = '\0';
1268 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1271 /* handle LNDs with ip interface name */
1272 rc = lustre_lnet_queryip(intf, &ip);
1273 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1274 snprintf(err_str, str_len,
1275 "\"couldn't query intf %s\"",
1277 err_str[str_len - 1] = '\0';
1280 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1297 * called repeatedly until a match or no more ip range
1299 * ip_range expression
1300 * interface list with all the interface names.
1301 * all the interfaces in the system.
1303 * try to match the ip_range expr to one of the interfaces' IPs in
1304 * the system. If we hit a patch for an interface. Check if that
1305 * interface name is in the list.
1307 * If there are more than one interface in the list, then make sure
1308 * that the IPs for all of these interfaces match the ip ranges
1311 * for each interface in intf_list
1312 * look up the intf name in ifa
1313 * if not there then no match
1314 * check ip obtained from ifa against a match to any of the
1316 * If no match, then fail
1318 * The result is that all the interfaces have to match.
1320 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1321 struct list_head *intf_list,
1322 struct list_head *ip_ranges)
1326 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1327 struct ifaddrs *ifaddr = ifa;
1328 struct lustre_lnet_ip_range_descr *ip_range;
1332 * if there are no explicit interfaces, and no ip ranges, then
1333 * configure the first tcp interface we encounter.
1335 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1336 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1337 if (ifaddr->ifa_addr == NULL)
1340 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1343 family = ifaddr->ifa_addr->sa_family;
1344 if (family == AF_INET &&
1345 strcmp(ifaddr->ifa_name, "lo") != 0) {
1346 rc = lustre_lnet_add_intf_descr
1347 (intf_list, ifaddr->ifa_name,
1348 strlen(ifaddr->ifa_name));
1350 if (rc != LUSTRE_CFG_RC_NO_ERR)
1353 return LUSTRE_CFG_RC_MATCH;
1356 return LUSTRE_CFG_RC_NO_MATCH;
1360 * First interface which matches an IP pattern will be used
1362 if (list_empty(intf_list)) {
1364 * no interfaces provided in the rule, but an ip range is
1365 * provided, so try and match an interface to the ip
1368 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1369 if (ifaddr->ifa_addr == NULL)
1372 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1375 family = ifaddr->ifa_addr->sa_family;
1376 if (family == AF_INET) {
1377 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1380 list_for_each_entry(ip_range, ip_ranges,
1382 rc = cfs_ip_addr_match(bswap_32(ip),
1383 &ip_range->ipr_expr);
1387 rc = lustre_lnet_add_intf_descr
1388 (intf_list, ifaddr->ifa_name,
1389 strlen(ifaddr->ifa_name));
1391 if (rc != LUSTRE_CFG_RC_NO_ERR)
1397 if (!list_empty(intf_list))
1398 return LUSTRE_CFG_RC_MATCH;
1400 return LUSTRE_CFG_RC_NO_MATCH;
1404 * If an interface is explicitly specified the ip-range might or
1405 * might not be specified. if specified the interface needs to match the
1406 * ip-range. If no ip-range then the interfaces are
1407 * automatically matched if they are all up.
1408 * If > 1 interfaces all the interfaces must match for the NI to
1411 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1412 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1413 if (ifaddr->ifa_addr == NULL)
1416 family = ifaddr->ifa_addr->sa_family;
1417 if (family == AF_INET &&
1418 strcmp(intf_descr->intf_name,
1419 ifaddr->ifa_name) == 0)
1423 if (ifaddr == NULL) {
1424 list_del(&intf_descr->intf_on_network);
1425 free_intf_descr(intf_descr);
1429 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1430 list_del(&intf_descr->intf_on_network);
1431 free_intf_descr(intf_descr);
1435 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1438 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1439 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1445 /* no match for this interface */
1446 list_del(&intf_descr->intf_on_network);
1447 free_intf_descr(intf_descr);
1451 return LUSTRE_CFG_RC_MATCH;
1454 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1455 lnet_nid_t **nids, __u32 *nnids,
1456 char *err_str, size_t str_len)
1458 struct ifaddrs *ifa;
1459 int rc = LUSTRE_CFG_RC_NO_ERR;
1461 rc = getifaddrs(&ifa);
1463 snprintf(err_str, str_len,
1464 "\"failed to get interface addresses: %d\"", -errno);
1465 err_str[str_len - 1] = '\0';
1469 rc = lustre_lnet_match_ip_to_intf(ifa,
1470 &ip2nets->ip2nets_net.nw_intflist,
1471 &ip2nets->ip2nets_ip_ranges);
1472 if (rc != LUSTRE_CFG_RC_MATCH) {
1473 snprintf(err_str, str_len,
1474 "\"couldn't match ip to existing interfaces\"");
1475 err_str[str_len - 1] = '\0';
1480 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1481 err_str, sizeof(err_str));
1482 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1493 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1494 struct lnet_ioctl_config_lnd_tunables *tunables,
1495 struct cfs_expr_list *global_cpts,
1496 lnet_nid_t *nids, char *err_str)
1499 struct lnet_ioctl_config_ni *conf;
1500 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1501 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1504 struct lnet_dlc_intf_descr *intf_descr;
1506 struct cfs_expr_list *cpt_expr;
1508 list_for_each_entry(intf_descr, intf_list,
1510 if (tunables != NULL)
1511 len = sizeof(struct lnet_ioctl_config_ni) +
1512 sizeof(struct lnet_ioctl_config_lnd_tunables);
1514 len = sizeof(struct lnet_ioctl_config_ni);
1516 data = calloc(1, len);
1518 return LUSTRE_CFG_RC_OUT_OF_MEM;
1519 conf = (struct lnet_ioctl_config_ni*) data;
1520 if (tunables != NULL)
1521 tun = (struct lnet_ioctl_config_lnd_tunables*)
1524 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1525 conf->lic_cfg_hdr.ioc_len = len;
1526 conf->lic_nid = nids[i];
1527 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1530 if (intf_descr->cpt_expr != NULL)
1531 cpt_expr = intf_descr->cpt_expr;
1532 else if (global_cpts != NULL)
1533 cpt_expr = global_cpts;
1537 if (cpt_expr != NULL) {
1538 count = cfs_expr_list_values(cpt_expr,
1539 LNET_MAX_SHOW_NUM_CPT,
1542 memcpy(conf->lic_cpts, cpt_array,
1543 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1552 conf->lic_ncpts = count;
1554 if (tunables != NULL)
1555 memcpy(tun, tunables, sizeof(*tunables));
1557 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1562 "\"cannot add network: %s\"", strerror(errno));
1570 return LUSTRE_CFG_RC_NO_ERR;
1574 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1575 struct lnet_ioctl_config_lnd_tunables *tunables,
1576 struct cfs_expr_list *global_cpts,
1577 int seq_no, struct cYAML **err_rc)
1579 lnet_nid_t *nids = NULL;
1582 char err_str[LNET_MAX_STR_LEN];
1584 snprintf(err_str, sizeof(err_str), "\"success\"");
1589 "\"incomplete ip2nets information\"");
1590 rc = LUSTRE_CFG_RC_BAD_PARAM;
1595 * call below function to resolve the rules into a list of nids.
1596 * The memory is allocated in that function then freed here when
1597 * it's no longer needed.
1599 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1601 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1604 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1605 snprintf(err_str, sizeof(err_str),
1606 "\"no interfaces match ip2nets rules\"");
1610 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1611 tunables, global_cpts, nids,
1618 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1622 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1623 struct cfs_expr_list *global_cpts,
1625 struct lnet_ioctl_config_lnd_tunables *tunables,
1626 int seq_no, struct cYAML **err_rc)
1629 struct lnet_ioctl_config_ni *conf;
1630 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1631 char buf[LNET_MAX_STR_LEN];
1632 int rc = LUSTRE_CFG_RC_NO_ERR;
1633 char err_str[LNET_MAX_STR_LEN];
1634 lnet_nid_t *nids = NULL;
1638 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1641 snprintf(err_str, sizeof(err_str), "\"success\"");
1643 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1644 (list_empty(&nw_descr->nw_intflist) &&
1645 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1648 "\"missing mandatory parameters in NI config: '%s'\"",
1649 (nw_descr == NULL) ? "network , interface" :
1650 (nw_descr->nw_id == 0) ? "network" : "interface");
1651 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1655 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1658 "\"ip2net string too long %d\"",
1659 (int)strlen(ip2net));
1660 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1664 if (ip2net != NULL) {
1665 if (tunables != NULL)
1666 len = sizeof(struct lnet_ioctl_config_ni) +
1667 sizeof(struct lnet_ioctl_config_lnd_tunables);
1669 len = sizeof(struct lnet_ioctl_config_ni);
1670 data = calloc(1, len);
1672 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1675 conf = (struct lnet_ioctl_config_ni*) data;
1676 if (tunables != NULL)
1677 tun = (struct lnet_ioctl_config_lnd_tunables*)
1678 (data + sizeof(*conf));
1680 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1681 conf->lic_cfg_hdr.ioc_len = len;
1682 strncpy(conf->lic_legacy_ip2nets, ip2net,
1685 if (global_cpts != NULL) {
1686 count = cfs_expr_list_values(global_cpts,
1687 LNET_MAX_SHOW_NUM_CPT,
1690 memcpy(conf->lic_cpts, cpt_array,
1691 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1700 conf->lic_ncpts = count;
1702 if (tunables != NULL)
1703 memcpy(tun, tunables, sizeof(*tunables));
1705 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1710 "\"cannot add network: %s\"", strerror(errno));
1717 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1718 rc = LUSTRE_CFG_RC_NO_ERR;
1722 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1725 "\"cannot parse net '%s'\"",
1726 libcfs_net2str(nw_descr->nw_id));
1727 rc = LUSTRE_CFG_RC_BAD_PARAM;
1732 * special case the GNI since no interface name is expected
1734 if (list_empty(&nw_descr->nw_intflist) &&
1735 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1738 "\"no interface name provided\"");
1739 rc = LUSTRE_CFG_RC_BAD_PARAM;
1743 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1744 err_str, sizeof(err_str));
1746 rc = LUSTRE_CFG_RC_BAD_PARAM;
1750 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1751 tunables, global_cpts, nids,
1755 if (nw_descr != NULL) {
1756 list_for_each_entry_safe(intf_descr, tmp,
1757 &nw_descr->nw_intflist,
1759 list_del(&intf_descr->intf_on_network);
1760 free_intf_descr(intf_descr);
1764 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1775 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1776 int seq_no, struct cYAML **err_rc)
1778 struct lnet_ioctl_config_ni data;
1779 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1780 char err_str[LNET_MAX_STR_LEN];
1781 lnet_nid_t *nids = NULL;
1783 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1785 snprintf(err_str, sizeof(err_str), "\"success\"");
1787 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1790 "\"missing mandatory parameter in deleting NI: '%s'\"",
1791 (nw_descr == NULL) ? "network , interface" :
1792 (nw_descr->nw_id == 0) ? "network" : "interface");
1793 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1797 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1798 return LUSTRE_CFG_RC_NO_ERR;
1800 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1803 "\"cannot parse net '%s'\"",
1804 libcfs_net2str(nw_descr->nw_id));
1805 rc = LUSTRE_CFG_RC_BAD_PARAM;
1809 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1810 err_str, sizeof(err_str));
1812 rc = LUSTRE_CFG_RC_BAD_PARAM;
1817 * no interfaces just the nw_id is specified
1820 nids = calloc(1, sizeof(*nids));
1822 snprintf(err_str, sizeof(err_str),
1823 "\"out of memory\"");
1824 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1827 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1831 for (i = 0; i < nnids; i++) {
1832 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1833 data.lic_nid = nids[i];
1835 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1840 "\"cannot del network: %s\"", strerror(errno));
1844 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1846 list_del(&intf_descr->intf_on_network);
1847 free_intf_descr(intf_descr);
1851 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1860 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1861 enum lnet_health_type type, char *name,
1862 int seq_no, struct cYAML **err_rc)
1864 struct lnet_ioctl_reset_health_cfg data;
1865 int rc = LUSTRE_CFG_RC_NO_ERR;
1866 char err_str[LNET_MAX_STR_LEN];
1868 snprintf(err_str, sizeof(err_str), "\"success\"");
1870 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1871 data.rh_type = type;
1873 data.rh_value = value;
1876 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1880 sizeof(err_str), "Can not configure health value: %s",
1884 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1889 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1890 struct cYAML **err_rc)
1894 nid = libcfs_str2nid(ni_nid);
1897 return lustre_lnet_config_healthv(value, all, nid,
1898 LNET_HEALTH_TYPE_LOCAL_NI,
1899 "ni healthv", seq_no, err_rc);
1902 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1903 int seq_no, struct cYAML **err_rc)
1907 nid = libcfs_str2nid(lpni_nid);
1910 return lustre_lnet_config_healthv(value, all, nid,
1911 LNET_HEALTH_TYPE_PEER_NI,
1912 "peer_ni healthv", seq_no, err_rc);
1916 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1917 struct lnet_ioctl_comm_count *counts)
1919 if (cYAML_create_number(yaml, "put",
1920 counts->ico_put_count)
1923 if (cYAML_create_number(yaml, "get",
1924 counts->ico_get_count)
1927 if (cYAML_create_number(yaml, "reply",
1928 counts->ico_reply_count)
1931 if (cYAML_create_number(yaml, "ack",
1932 counts->ico_ack_count)
1935 if (cYAML_create_number(yaml, "hello",
1936 counts->ico_hello_count)
1943 static struct lnet_ioctl_comm_count *
1944 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1947 return &msg_stats->im_send_stats;
1949 return &msg_stats->im_recv_stats;
1951 return &msg_stats->im_drop_stats;
1956 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1957 struct cYAML **show_rc, struct cYAML **err_rc,
1961 struct lnet_ioctl_config_ni *ni_data;
1962 struct lnet_ioctl_config_lnd_tunables *lnd;
1963 struct lnet_ioctl_element_stats *stats;
1964 struct lnet_ioctl_element_msg_stats msg_stats;
1965 struct lnet_ioctl_local_ni_hstats hstats;
1966 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1967 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1968 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1970 struct cYAML *root = NULL, *tunables = NULL,
1971 *net_node = NULL, *interfaces = NULL,
1972 *item = NULL, *first_seq = NULL,
1973 *tmp = NULL, *statistics = NULL,
1975 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1976 char str_buf[str_buf_len];
1978 char err_str[LNET_MAX_STR_LEN];
1979 bool exist = false, new_net = true;
1981 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1983 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1985 buf = calloc(1, buf_size);
1989 ni_data = (struct lnet_ioctl_config_ni *)buf;
1992 net = libcfs_str2net(nw);
1993 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1996 "\"cannot parse net '%s'\"", nw);
1997 rc = LUSTRE_CFG_RC_BAD_PARAM;
2002 root = cYAML_create_object(NULL, NULL);
2006 net_node = cYAML_create_seq(root, "net");
2007 if (net_node == NULL)
2013 memset(buf, 0, buf_size);
2015 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2017 * set the ioc_len to the proper value since INIT assumes
2020 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2021 ni_data->lic_idx = i;
2023 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2029 rc_net = LNET_NIDNET(ni_data->lic_nid);
2031 /* filter on provided data */
2032 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2036 /* if we're backing up don't store lo */
2037 if (backup && LNET_NETTYP(rc_net) == LOLND)
2040 /* default rc to -1 in case we hit the goto */
2044 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2045 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2046 (ni_data->lic_bulk + sizeof(*stats));
2048 if (rc_net != prev_net) {
2055 if (!cYAML_create_string(net_node, "net type",
2056 libcfs_net2str(rc_net)))
2059 tmp = cYAML_create_seq(net_node, "local NI(s)");
2065 /* create the tree to be printed. */
2066 item = cYAML_create_seq_item(tmp);
2070 if (first_seq == NULL)
2074 cYAML_create_string(item, "nid",
2075 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2079 cYAML_create_string(item,
2081 (ni_data->lic_status ==
2082 LNET_NI_STATUS_UP) ?
2083 "up" : "down") == NULL)
2086 /* don't add interfaces unless there is at least one
2088 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2089 interfaces = cYAML_create_object(item, "interfaces");
2090 if (interfaces == NULL)
2093 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2094 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2096 sizeof(str_buf), "%d", j);
2097 if (cYAML_create_string(interfaces,
2099 ni_data->lic_ni_intf[j]) ==
2111 goto continue_without_msg_stats;
2113 statistics = cYAML_create_object(item, "statistics");
2114 if (statistics == NULL)
2117 if (cYAML_create_number(statistics, "send_count",
2118 stats->iel_send_count)
2122 if (cYAML_create_number(statistics, "recv_count",
2123 stats->iel_recv_count)
2127 if (cYAML_create_number(statistics, "drop_count",
2128 stats->iel_drop_count)
2133 goto continue_without_msg_stats;
2135 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2136 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2137 msg_stats.im_idx = i;
2139 rc = l_ioctl(LNET_DEV_ID,
2140 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2144 goto continue_without_msg_stats;
2147 for (k = 0; k < 3; k++) {
2148 struct lnet_ioctl_comm_count *counts;
2149 struct cYAML *msg_statistics = NULL;
2151 msg_statistics = cYAML_create_object(item,
2152 (char *)gmsg_stat_names[k]);
2153 if (msg_statistics == NULL)
2156 counts = get_counts(&msg_stats, k);
2160 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2165 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2166 hstats.hlni_nid = ni_data->lic_nid;
2167 /* grab health stats */
2168 rc = l_ioctl(LNET_DEV_ID,
2169 IOC_LIBCFS_GET_LOCAL_HSTATS,
2173 goto continue_without_msg_stats;
2175 yhstats = cYAML_create_object(item, "health stats");
2178 if (cYAML_create_number(yhstats, "health value",
2179 hstats.hlni_health_value)
2182 if (cYAML_create_number(yhstats, "interrupts",
2183 hstats.hlni_local_interrupt)
2186 if (cYAML_create_number(yhstats, "dropped",
2187 hstats.hlni_local_dropped)
2190 if (cYAML_create_number(yhstats, "aborted",
2191 hstats.hlni_local_aborted)
2194 if (cYAML_create_number(yhstats, "no route",
2195 hstats.hlni_local_no_route)
2198 if (cYAML_create_number(yhstats, "timeouts",
2199 hstats.hlni_local_timeout)
2202 if (cYAML_create_number(yhstats, "error",
2203 hstats.hlni_local_error)
2207 continue_without_msg_stats:
2208 tunables = cYAML_create_object(item, "tunables");
2212 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2213 if (rc != LUSTRE_CFG_RC_NO_ERR)
2216 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2218 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2219 rc != LUSTRE_CFG_RC_NO_MATCH)
2222 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2223 tunables = cYAML_create_object(item,
2225 if (tunables == NULL)
2230 cYAML_create_number(item, "dev cpt",
2231 ni_data->lic_dev_cpt) == NULL)
2235 cYAML_create_number(item, "tcp bonding",
2236 ni_data->lic_tcp_bonding)
2240 /* out put the CPTs in the format: "[x,x,x,...]" */
2242 limit = str_buf + str_buf_len - 3;
2243 pos += scnprintf(pos, limit - pos, "\"[");
2244 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2245 j < ni_data->lic_ncpts &&
2247 pos += scnprintf(pos, limit - pos,
2248 "%d", ni_data->lic_cpts[j]);
2249 if ((j + 1) < ni_data->lic_ncpts)
2250 pos += scnprintf(pos, limit - pos, ",");
2252 snprintf(pos, 3, "]\"");
2254 if (ni_data->lic_ncpts >= 1 &&
2255 cYAML_create_string(item, "CPT",
2261 /* Print out the net information only if show_rc is not provided */
2262 if (show_rc == NULL)
2263 cYAML_print_tree(root);
2265 if (l_errno != ENOENT) {
2268 "\"cannot get networks: %s\"",
2273 rc = LUSTRE_CFG_RC_NO_ERR;
2275 snprintf(err_str, sizeof(err_str), "\"success\"");
2277 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2278 cYAML_free_tree(root);
2279 } else if (show_rc != NULL && *show_rc != NULL) {
2280 struct cYAML *show_node;
2281 /* find the net node, if one doesn't exist
2282 * then insert one. Otherwise add to the one there
2284 show_node = cYAML_get_object_item(*show_rc, "net");
2285 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2286 cYAML_insert_child(show_node, first_seq);
2289 } else if (show_node == NULL) {
2290 cYAML_insert_sibling((*show_rc)->cy_child,
2294 cYAML_free_tree(root);
2300 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2305 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2307 struct lnet_ioctl_config_data data;
2308 int rc = LUSTRE_CFG_RC_NO_ERR;
2309 char err_str[LNET_MAX_STR_LEN];
2311 snprintf(err_str, sizeof(err_str), "\"success\"");
2313 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2314 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2316 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2321 "\"cannot %s routing %s\"",
2322 (enable) ? "enable" : "disable", strerror(errno));
2327 cYAML_build_error(rc, seq_no,
2328 (enable) ? ADD_CMD : DEL_CMD,
2329 "routing", err_str, err_rc);
2334 int ioctl_set_value(__u32 val, int ioc, char *name,
2335 int seq_no, struct cYAML **err_rc)
2337 struct lnet_ioctl_set_value data;
2338 int rc = LUSTRE_CFG_RC_NO_ERR;
2339 char err_str[LNET_MAX_STR_LEN];
2341 snprintf(err_str, sizeof(err_str), "\"success\"");
2343 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2344 data.sv_value = val;
2346 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2351 "\"cannot configure %s to %d: %s\"", name,
2352 val, strerror(errno));
2355 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2360 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2362 int rc = LUSTRE_CFG_RC_NO_ERR;
2363 char err_str[LNET_MAX_STR_LEN];
2364 char val[LNET_MAX_STR_LEN];
2366 snprintf(err_str, sizeof(err_str), "\"success\"");
2368 snprintf(val, sizeof(val), "%d", intrv);
2370 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2371 1, strlen(val) + 1);
2373 snprintf(err_str, sizeof(err_str),
2374 "\"cannot configure recovery interval: %s\"",
2377 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2382 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2384 int rc = LUSTRE_CFG_RC_NO_ERR;
2385 char err_str[LNET_MAX_STR_LEN];
2386 char val[LNET_MAX_STR_LEN];
2388 snprintf(err_str, sizeof(err_str), "\"success\"");
2390 snprintf(val, sizeof(val), "%d", sen);
2392 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2393 1, strlen(val) + 1);
2395 snprintf(err_str, sizeof(err_str),
2396 "\"cannot configure router health sensitivity: %s\"",
2399 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2404 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2406 int rc = LUSTRE_CFG_RC_NO_ERR;
2407 char err_str[LNET_MAX_STR_LEN];
2408 char val[LNET_MAX_STR_LEN];
2410 snprintf(err_str, sizeof(err_str), "\"success\"");
2412 snprintf(val, sizeof(val), "%d", sen);
2414 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2415 1, strlen(val) + 1);
2417 snprintf(err_str, sizeof(err_str),
2418 "\"cannot configure health sensitivity: %s\"",
2421 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2426 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2428 int rc = LUSTRE_CFG_RC_NO_ERR;
2429 char err_str[LNET_MAX_STR_LEN];
2430 char val[LNET_MAX_STR_LEN];
2432 snprintf(err_str, sizeof(err_str), "\"success\"");
2434 snprintf(val, sizeof(val), "%d", timeout);
2436 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2437 1, strlen(val) + 1);
2439 snprintf(err_str, sizeof(err_str),
2440 "\"cannot configure transaction timeout: %s\"",
2443 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2448 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2450 int rc = LUSTRE_CFG_RC_NO_ERR;
2451 char err_str[LNET_MAX_STR_LEN];
2452 char val[LNET_MAX_STR_LEN];
2454 snprintf(err_str, sizeof(err_str), "\"success\"");
2456 snprintf(val, sizeof(val), "%d", count);
2458 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2459 1, strlen(val) + 1);
2461 snprintf(err_str, sizeof(err_str),
2462 "\"cannot configure retry count: %s\"",
2465 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2470 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2472 int rc = LUSTRE_CFG_RC_NO_ERR;
2473 char err_str[LNET_MAX_STR_LEN];
2474 char val[LNET_MAX_STR_LEN];
2476 snprintf(err_str, sizeof(err_str), "\"success\"");
2478 snprintf(val, sizeof(val), "%d", max);
2480 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2481 1, strlen(val) + 1);
2483 snprintf(err_str, sizeof(err_str),
2484 "\"cannot configure max interfaces: %s\"",
2487 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2492 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2494 int rc = LUSTRE_CFG_RC_NO_ERR;
2495 char err_str[LNET_MAX_STR_LEN];
2496 char val[LNET_MAX_STR_LEN];
2498 snprintf(err_str, sizeof(err_str), "\"success\"");
2500 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2502 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2503 1, strlen(val) + 1);
2505 snprintf(err_str, sizeof(err_str),
2506 "\"cannot configure discovery: %s\"",
2509 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2515 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2516 struct cYAML **err_rc)
2518 int rc = LUSTRE_CFG_RC_NO_ERR;
2519 char err_str[LNET_MAX_STR_LEN];
2520 char val[LNET_MAX_STR_LEN];
2522 snprintf(err_str, sizeof(err_str), "\"success\"");
2524 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2526 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2527 1, strlen(val) + 1);
2529 snprintf(err_str, sizeof(err_str),
2530 "\"cannot configure drop asym route: %s\"",
2533 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2540 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2542 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2543 "numa_range", seq_no, err_rc);
2546 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2547 struct cYAML **err_rc)
2549 struct lnet_ioctl_config_data data;
2550 int rc = LUSTRE_CFG_RC_NO_ERR;
2551 char err_str[LNET_MAX_STR_LEN];
2553 snprintf(err_str, sizeof(err_str), "\"success\"");
2555 /* -1 indicates to ignore changes to this field */
2556 if (tiny < -1 || small < -1 || large < -1) {
2559 "\"tiny, small and large must be >= 0\"");
2560 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2564 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2565 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2566 data.cfg_config_u.cfg_buffers.buf_small = small;
2567 data.cfg_config_u.cfg_buffers.buf_large = large;
2569 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2574 "\"cannot configure buffers: %s\"", strerror(errno));
2579 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2584 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2585 struct cYAML **err_rc, bool backup)
2587 struct lnet_ioctl_config_data *data;
2588 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2589 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2592 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2593 int buf_count[LNET_NRBPOOLS] = {0};
2594 struct cYAML *root = NULL, *pools_node = NULL,
2595 *type_node = NULL, *item = NULL, *cpt = NULL,
2596 *first_seq = NULL, *buffers = NULL;
2598 char err_str[LNET_MAX_STR_LEN];
2599 char node_name[LNET_MAX_STR_LEN];
2602 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2604 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2608 data = (struct lnet_ioctl_config_data *)buf;
2610 root = cYAML_create_object(NULL, NULL);
2615 pools_node = cYAML_create_object(root, "routing");
2617 pools_node = cYAML_create_seq(root, "routing");
2618 if (pools_node == NULL)
2622 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2623 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2624 sizeof(struct lnet_ioctl_pool_cfg);
2625 data->cfg_count = i;
2627 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2635 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2638 goto calculate_buffers;
2640 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2641 item = cYAML_create_seq_item(pools_node);
2645 if (first_seq == NULL)
2648 cpt = cYAML_create_object(item, node_name);
2653 /* create the tree and print */
2654 for (j = 0; j < LNET_NRBPOOLS; j++) {
2656 type_node = cYAML_create_object(cpt, pools[j]);
2657 if (type_node == NULL)
2661 cYAML_create_number(type_node, "npages",
2662 pool_cfg->pl_pools[j].pl_npages)
2666 cYAML_create_number(type_node, "nbuffers",
2667 pool_cfg->pl_pools[j].
2668 pl_nbuffers) == NULL)
2671 cYAML_create_number(type_node, "credits",
2672 pool_cfg->pl_pools[j].
2673 pl_credits) == NULL)
2676 cYAML_create_number(type_node, "mincredits",
2677 pool_cfg->pl_pools[j].
2678 pl_mincredits) == NULL)
2680 /* keep track of the total count for each of the
2681 * tiny, small and large buffers */
2682 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2686 if (pool_cfg != NULL) {
2688 if (cYAML_create_number(pools_node, "enable",
2689 pool_cfg->pl_routing) ==
2693 goto add_buffer_section;
2696 item = cYAML_create_seq_item(pools_node);
2700 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2706 /* create a buffers entry in the show. This is necessary so that
2707 * if the YAML output is used to configure a node, the buffer
2708 * configuration takes hold */
2709 buffers = cYAML_create_object(root, "buffers");
2710 if (buffers == NULL)
2713 for (i = 0; i < LNET_NRBPOOLS; i++) {
2714 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2718 if (show_rc == NULL)
2719 cYAML_print_tree(root);
2721 if (l_errno != ENOENT) {
2724 "\"cannot get routing information: %s\"",
2729 rc = LUSTRE_CFG_RC_NO_ERR;
2731 snprintf(err_str, sizeof(err_str), "\"success\"");
2732 rc = LUSTRE_CFG_RC_NO_ERR;
2736 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2737 cYAML_free_tree(root);
2738 } else if (show_rc != NULL && *show_rc != NULL) {
2739 struct cYAML *routing_node;
2740 /* there should exist only one routing block and one
2741 * buffers block. If there already exists a previous one
2742 * then don't add another */
2743 routing_node = cYAML_get_object_item(*show_rc, "routing");
2744 if (routing_node == NULL) {
2745 cYAML_insert_sibling((*show_rc)->cy_child,
2749 cYAML_free_tree(root);
2755 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2760 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2761 struct cYAML **show_rc, struct cYAML **err_rc,
2765 * TODO: This function is changing in a future patch to accommodate
2766 * PEER_LIST and proper filtering on any nid of the peer
2768 struct lnet_ioctl_peer_cfg peer_info;
2769 struct lnet_peer_ni_credit_info *lpni_cri;
2770 struct lnet_ioctl_element_stats *lpni_stats;
2771 struct lnet_ioctl_element_msg_stats *msg_stats;
2772 struct lnet_ioctl_peer_ni_hstats *hstats;
2774 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2779 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2780 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2781 *msg_statistics = NULL, *statistics = NULL,
2783 char err_str[LNET_MAX_STR_LEN];
2784 struct lnet_process_id *list = NULL;
2789 snprintf(err_str, sizeof(err_str),
2790 "\"out of memory\"");
2792 /* create struct cYAML root object */
2793 root = cYAML_create_object(NULL, NULL);
2797 peer_root = cYAML_create_seq(root, "peer");
2798 if (peer_root == NULL)
2802 size = count * sizeof(struct lnet_process_id);
2803 list = malloc(size);
2809 list[0].nid = libcfs_str2nid(knid);
2813 memset(&peer_info, 0, sizeof(peer_info));
2814 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2815 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2816 peer_info.prcfg_size = size;
2817 peer_info.prcfg_bulk = list;
2820 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2822 count = peer_info.prcfg_count;
2826 if (l_errno != E2BIG) {
2829 "\"cannot get peer list: %s\"",
2835 size = peer_info.prcfg_size;
2836 list = malloc(size);
2845 data = malloc(size);
2851 for (i = 0; i < count; i++) {
2853 memset(&peer_info, 0, sizeof(peer_info));
2854 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2855 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2856 peer_info.prcfg_prim_nid = list[i].nid;
2857 peer_info.prcfg_size = size;
2858 peer_info.prcfg_bulk = data;
2861 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2866 if (l_errno != E2BIG) {
2869 "\"cannot get peer information: %s\"",
2875 size = peer_info.prcfg_size;
2876 data = malloc(size);
2884 peer = cYAML_create_seq_item(peer_root);
2888 if (first_seq == NULL)
2891 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2892 if (cYAML_create_string(peer, "primary nid",
2893 libcfs_nid2str(pnid))
2896 if (cYAML_create_string(peer, "Multi-Rail",
2897 peer_info.prcfg_mr ? "True" : "False")
2901 * print out the state of the peer only if details are
2906 cYAML_create_number(peer, "peer state",
2907 peer_info.prcfg_state)
2912 tmp = cYAML_create_seq(peer, "peer ni");
2917 for (j = 0; j < peer_info.prcfg_count; j++) {
2919 lpni_cri = (void*)nidp + sizeof(nidp);
2920 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2921 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2922 hstats = (void *)msg_stats + sizeof(*msg_stats);
2923 lpni_data = (void *)hstats + sizeof(*hstats);
2925 peer_ni = cYAML_create_seq_item(tmp);
2926 if (peer_ni == NULL)
2929 if (cYAML_create_string(peer_ni, "nid",
2930 libcfs_nid2str(*nidp))
2937 if (cYAML_create_string(peer_ni, "state",
2938 lpni_cri->cr_aliveness)
2945 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2946 lpni_cri->cr_ni_peer_tx_credits)
2950 if (cYAML_create_number(peer_ni, "available_tx_credits",
2951 lpni_cri->cr_peer_tx_credits)
2955 if (cYAML_create_number(peer_ni, "min_tx_credits",
2956 lpni_cri->cr_peer_min_tx_credits)
2960 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2961 lpni_cri->cr_peer_tx_qnob)
2965 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2966 lpni_cri->cr_peer_rtr_credits)
2970 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2971 lpni_cri->cr_peer_min_rtr_credits)
2975 if (cYAML_create_number(peer_ni, "refcount",
2976 lpni_cri->cr_refcount) == NULL)
2979 statistics = cYAML_create_object(peer_ni, "statistics");
2980 if (statistics == NULL)
2983 if (cYAML_create_number(statistics, "send_count",
2984 lpni_stats->iel_send_count)
2988 if (cYAML_create_number(statistics, "recv_count",
2989 lpni_stats->iel_recv_count)
2993 if (cYAML_create_number(statistics, "drop_count",
2994 lpni_stats->iel_drop_count)
3001 for (k = 0; k < 3; k++) {
3002 struct lnet_ioctl_comm_count *counts;
3004 msg_statistics = cYAML_create_object(peer_ni,
3005 (char *) gmsg_stat_names[k]);
3006 if (msg_statistics == NULL)
3009 counts = get_counts(msg_stats, k);
3013 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3018 yhstats = cYAML_create_object(peer_ni, "health stats");
3021 if (cYAML_create_number(yhstats, "health value",
3022 hstats->hlpni_health_value)
3025 if (cYAML_create_number(yhstats, "dropped",
3026 hstats->hlpni_remote_dropped)
3029 if (cYAML_create_number(yhstats, "timeout",
3030 hstats->hlpni_remote_timeout)
3033 if (cYAML_create_number(yhstats, "error",
3034 hstats->hlpni_remote_error)
3037 if (cYAML_create_number(yhstats, "network timeout",
3038 hstats->hlpni_network_timeout)
3044 /* print output iff show_rc is not provided */
3045 if (show_rc == NULL)
3046 cYAML_print_tree(root);
3048 snprintf(err_str, sizeof(err_str), "\"success\"");
3049 rc = LUSTRE_CFG_RC_NO_ERR;
3054 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3055 cYAML_free_tree(root);
3056 } else if (show_rc != NULL && *show_rc != NULL) {
3057 struct cYAML *show_node;
3058 /* find the peer node, if one doesn't exist then
3059 * insert one. Otherwise add to the one there
3061 show_node = cYAML_get_object_item(*show_rc,
3063 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3064 cYAML_insert_child(show_node, first_seq);
3067 } else if (show_node == NULL) {
3068 cYAML_insert_sibling((*show_rc)->cy_child,
3072 cYAML_free_tree(root);
3078 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3084 int lustre_lnet_list_peer(int seq_no,
3085 struct cYAML **show_rc, struct cYAML **err_rc)
3087 struct lnet_ioctl_peer_cfg peer_info;
3088 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3093 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3094 char err_str[LNET_MAX_STR_LEN];
3095 struct lnet_process_id *list = NULL;
3097 snprintf(err_str, sizeof(err_str),
3098 "\"out of memory\"");
3100 memset(&peer_info, 0, sizeof(peer_info));
3102 /* create struct cYAML root object */
3103 root = cYAML_create_object(NULL, NULL);
3107 list_root = cYAML_create_seq(root, "peer list");
3108 if (list_root == NULL)
3112 size = count * sizeof(struct lnet_process_id);
3113 list = malloc(size);
3119 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3120 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3121 peer_info.prcfg_size = size;
3122 peer_info.prcfg_bulk = list;
3125 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3126 count = peer_info.prcfg_count;
3130 if (l_errno != E2BIG) {
3133 "\"cannot get peer list: %s\"",
3139 size = peer_info.prcfg_size;
3140 list = malloc(size);
3147 /* count is now the actual number of ids in the list. */
3148 for (i = 0; i < count; i++) {
3149 if (cYAML_create_string(list_root, "nid",
3150 libcfs_nid2str(list[i].nid))
3155 /* print output iff show_rc is not provided */
3156 if (show_rc == NULL)
3157 cYAML_print_tree(root);
3159 snprintf(err_str, sizeof(err_str), "\"success\"");
3160 rc = LUSTRE_CFG_RC_NO_ERR;
3165 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3166 cYAML_free_tree(root);
3167 } else if (show_rc != NULL && *show_rc != NULL) {
3168 struct cYAML *show_node;
3169 /* find the peer node, if one doesn't exist then
3170 * insert one. Otherwise add to the one there
3172 show_node = cYAML_get_object_item(*show_rc,
3174 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3175 cYAML_insert_child(show_node, first_seq);
3178 } else if (show_node == NULL) {
3179 cYAML_insert_sibling((*show_rc)->cy_child,
3183 cYAML_free_tree(root);
3189 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3195 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3198 struct cYAML *show_node;
3200 show_node = cYAML_get_object_item(show_rc, "global");
3201 if (show_node != NULL)
3202 cYAML_insert_sibling(show_node->cy_child,
3205 cYAML_insert_sibling(show_rc->cy_child,
3210 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3211 char *name, __u64 value,
3212 struct cYAML **show_rc,
3213 struct cYAML **err_rc, int err)
3215 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3216 struct cYAML *root = NULL, *global = NULL;
3223 root = cYAML_create_object(NULL, NULL);
3227 global = cYAML_create_object(root, "global");
3231 if (cYAML_create_number(global, name,
3235 if (show_rc == NULL)
3236 cYAML_print_tree(root);
3238 snprintf(err_str, err_len, "\"success\"");
3240 rc = LUSTRE_CFG_RC_NO_ERR;
3243 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3244 cYAML_free_tree(root);
3245 } else if (show_rc != NULL && *show_rc != NULL) {
3246 add_to_global(*show_rc, global, root);
3251 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3256 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3257 struct cYAML **show_rc,
3258 struct cYAML **err_rc)
3260 struct lnet_ioctl_set_value data;
3263 char err_str[LNET_MAX_STR_LEN];
3265 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3267 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3269 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3274 "\"cannot get %s: %s\"",
3275 name, strerror(l_errno));
3278 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3279 data.sv_value, show_rc, err_rc, l_errno);
3282 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3283 struct cYAML **err_rc)
3285 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3286 char val[LNET_MAX_STR_LEN];
3287 int intrv = -1, l_errno = 0;
3288 char err_str[LNET_MAX_STR_LEN];
3290 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3292 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3296 snprintf(err_str, sizeof(err_str),
3297 "\"cannot get recovery interval: %d\"", rc);
3302 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3303 "recovery_interval", intrv, show_rc,
3307 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3308 struct cYAML **err_rc)
3310 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3311 char val[LNET_MAX_STR_LEN];
3312 int sen = -1, l_errno = 0;
3313 char err_str[LNET_MAX_STR_LEN];
3315 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3317 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3321 snprintf(err_str, sizeof(err_str),
3322 "\"cannot get health sensitivity: %d\"", rc);
3327 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3328 "health_sensitivity", sen, show_rc,
3332 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3333 struct cYAML **err_rc)
3335 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3336 char val[LNET_MAX_STR_LEN];
3337 int sen = -1, l_errno = 0;
3338 char err_str[LNET_MAX_STR_LEN];
3340 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3342 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3346 snprintf(err_str, sizeof(err_str),
3347 "\"cannot get router sensitivity percentage: %d\"", rc);
3352 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3353 "router_sensitivity", sen, show_rc,
3357 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3358 struct cYAML **err_rc)
3360 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3361 char val[LNET_MAX_STR_LEN];
3362 int tto = -1, l_errno = 0;
3363 char err_str[LNET_MAX_STR_LEN];
3365 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3367 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3371 snprintf(err_str, sizeof(err_str),
3372 "\"cannot get transaction timeout: %d\"", rc);
3377 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3378 "transaction_timeout", tto, show_rc,
3382 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3383 struct cYAML **err_rc)
3385 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3386 char val[LNET_MAX_STR_LEN];
3387 int retry_count = -1, l_errno = 0;
3388 char err_str[LNET_MAX_STR_LEN];
3390 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3392 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3396 snprintf(err_str, sizeof(err_str),
3397 "\"cannot get retry count: %d\"", rc);
3399 retry_count = atoi(val);
3402 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3403 "retry_count", retry_count, show_rc,
3407 int lustre_lnet_calc_service_id(__u64 *service_id)
3409 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3410 char val[LNET_MAX_STR_LEN];
3411 int service_port = -1, l_errno = 0;
3413 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3417 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3418 strerror(l_errno), -l_errno);
3421 service_port = atoi(val);
3424 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3426 return LUSTRE_CFG_RC_NO_ERR;
3429 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3430 struct cYAML **show_rc, struct cYAML **err_rc)
3432 struct lnet_ioctl_recovery_list nid_list;
3433 struct cYAML *root = NULL, *nids = NULL;
3435 char err_str[LNET_MAX_STR_LEN];
3437 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3439 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3440 nid_list.rlst_type = type;
3442 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3448 if (nid_list.rlst_num_nids == 0)
3451 root = cYAML_create_object(NULL, NULL);
3455 nids = cYAML_create_object(root, name);
3461 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3462 char nidenum[LNET_MAX_STR_LEN];
3463 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3464 if (!cYAML_create_string(nids, nidenum,
3465 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3469 snprintf(err_str, sizeof(err_str), "success\n");
3474 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3475 cYAML_free_tree(root);
3476 } else if (show_rc != NULL && *show_rc != NULL) {
3477 struct cYAML *show_node;
3478 /* find the net node, if one doesn't exist
3479 * then insert one. Otherwise add to the one there
3481 show_node = cYAML_get_object_item(*show_rc, name);
3482 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3483 cYAML_insert_child(show_node, nids);
3486 } else if (show_node == NULL) {
3487 cYAML_insert_sibling((*show_rc)->cy_child,
3491 cYAML_free_tree(root);
3497 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3502 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3503 struct cYAML **err_rc)
3505 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3506 seq_no, show_rc, err_rc);
3509 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3510 struct cYAML **err_rc)
3512 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3513 seq_no, show_rc, err_rc);
3516 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3517 struct cYAML **err_rc)
3519 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3520 char val[LNET_MAX_STR_LEN];
3521 int max_intf = -1, l_errno = 0;
3522 char err_str[LNET_MAX_STR_LEN];
3524 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3526 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3530 snprintf(err_str, sizeof(err_str),
3531 "\"cannot get max interfaces: %d\"", rc);
3533 max_intf = atoi(val);
3536 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3537 "max_intf", max_intf, show_rc,
3541 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3542 struct cYAML **err_rc)
3544 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3545 char val[LNET_MAX_STR_LEN];
3546 int discovery = -1, l_errno = 0;
3547 char err_str[LNET_MAX_STR_LEN];
3549 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3551 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3555 snprintf(err_str, sizeof(err_str),
3556 "\"cannot get discovery setting: %d\"", rc);
3559 * The kernel stores a discovery disabled value. User space
3560 * shows whether discovery is enabled. So the value must be
3563 discovery = !atoi(val);
3566 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3567 "discovery", discovery, show_rc,
3571 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3572 struct cYAML **err_rc)
3574 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3575 char val[LNET_MAX_STR_LEN];
3576 int drop_asym_route = -1, l_errno = 0;
3577 char err_str[LNET_MAX_STR_LEN];
3579 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3581 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3585 snprintf(err_str, sizeof(err_str),
3586 "\"cannot get drop asym route setting: %d\"", rc);
3588 drop_asym_route = atoi(val);
3591 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3592 "drop_asym_route", drop_asym_route,
3593 show_rc, err_rc, l_errno);
3596 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3597 struct cYAML **err_rc)
3599 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3600 "numa_range", show_rc, err_rc);
3603 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3604 struct cYAML **err_rc)
3606 struct lnet_ioctl_lnet_stats data;
3607 struct lnet_counters *cntrs;
3610 char err_str[LNET_MAX_STR_LEN];
3611 struct cYAML *root = NULL, *stats = NULL;
3613 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3615 LIBCFS_IOC_INIT_V2(data, st_hdr);
3617 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3622 "\"cannot get lnet statistics: %s\"",
3628 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3630 cntrs = &data.st_cntrs;
3632 root = cYAML_create_object(NULL, NULL);
3636 stats = cYAML_create_object(root, "statistics");
3640 if (!cYAML_create_number(stats, "msgs_alloc",
3641 cntrs->lct_common.lcc_msgs_alloc))
3644 if (!cYAML_create_number(stats, "msgs_max",
3645 cntrs->lct_common.lcc_msgs_max))
3648 if (!cYAML_create_number(stats, "rst_alloc",
3649 cntrs->lct_health.lch_rst_alloc))
3652 if (!cYAML_create_number(stats, "errors",
3653 cntrs->lct_common.lcc_errors))
3656 if (!cYAML_create_number(stats, "send_count",
3657 cntrs->lct_common.lcc_send_count))
3660 if (!cYAML_create_number(stats, "resend_count",
3661 cntrs->lct_health.lch_resend_count))
3664 if (!cYAML_create_number(stats, "response_timeout_count",
3665 cntrs->lct_health.lch_response_timeout_count))
3668 if (!cYAML_create_number(stats, "local_interrupt_count",
3669 cntrs->lct_health.lch_local_interrupt_count))
3672 if (!cYAML_create_number(stats, "local_dropped_count",
3673 cntrs->lct_health.lch_local_dropped_count))
3676 if (!cYAML_create_number(stats, "local_aborted_count",
3677 cntrs->lct_health.lch_local_aborted_count))
3680 if (!cYAML_create_number(stats, "local_no_route_count",
3681 cntrs->lct_health.lch_local_no_route_count))
3684 if (!cYAML_create_number(stats, "local_timeout_count",
3685 cntrs->lct_health.lch_local_timeout_count))
3688 if (!cYAML_create_number(stats, "local_error_count",
3689 cntrs->lct_health.lch_local_error_count))
3692 if (!cYAML_create_number(stats, "remote_dropped_count",
3693 cntrs->lct_health.lch_remote_dropped_count))
3696 if (!cYAML_create_number(stats, "remote_error_count",
3697 cntrs->lct_health.lch_remote_error_count))
3700 if (!cYAML_create_number(stats, "remote_timeout_count",
3701 cntrs->lct_health.lch_remote_timeout_count))
3704 if (!cYAML_create_number(stats, "network_timeout_count",
3705 cntrs->lct_health.lch_network_timeout_count))
3708 if (!cYAML_create_number(stats, "recv_count",
3709 cntrs->lct_common.lcc_recv_count))
3712 if (!cYAML_create_number(stats, "route_count",
3713 cntrs->lct_common.lcc_route_count))
3716 if (!cYAML_create_number(stats, "drop_count",
3717 cntrs->lct_common.lcc_drop_count))
3720 if (!cYAML_create_number(stats, "send_length",
3721 cntrs->lct_common.lcc_send_length))
3724 if (!cYAML_create_number(stats, "recv_length",
3725 cntrs->lct_common.lcc_recv_length))
3728 if (!cYAML_create_number(stats, "route_length",
3729 cntrs->lct_common.lcc_route_length))
3732 if (!cYAML_create_number(stats, "drop_length",
3733 cntrs->lct_common.lcc_drop_length))
3737 cYAML_print_tree(root);
3739 snprintf(err_str, sizeof(err_str), "\"success\"");
3740 rc = LUSTRE_CFG_RC_NO_ERR;
3742 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3743 cYAML_free_tree(root);
3744 } else if (show_rc != NULL && *show_rc != NULL) {
3745 cYAML_insert_sibling((*show_rc)->cy_child,
3752 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3757 typedef int (*cmd_handler_t)(struct cYAML *tree,
3758 struct cYAML **show_rc,
3759 struct cYAML **err_rc);
3761 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3762 struct cYAML **err_rc)
3764 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3766 net = cYAML_get_object_item(tree, "net");
3767 gw = cYAML_get_object_item(tree, "gateway");
3768 hop = cYAML_get_object_item(tree, "hop");
3769 prio = cYAML_get_object_item(tree, "priority");
3770 sen = cYAML_get_object_item(tree, "health_sensitivity");
3771 seq_no = cYAML_get_object_item(tree, "seq_no");
3773 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3774 (gw) ? gw->cy_valuestring : NULL,
3775 (hop) ? hop->cy_valueint : -1,
3776 (prio) ? prio->cy_valueint : -1,
3777 (sen) ? sen->cy_valueint : -1,
3778 (seq_no) ? seq_no->cy_valueint : -1,
3784 * 0: <intf_name>['['<expr>']']
3785 * 1: <intf_name>['['<expr>']']
3787 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3788 struct lnet_dlc_network_descr *nw_descr)
3790 struct cYAML *child = NULL;
3791 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3792 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3794 if (intf_tree == NULL || nw_descr == NULL)
3795 return LUSTRE_CFG_RC_BAD_PARAM;
3797 /* now grab all the interfaces and their cpts */
3798 child = intf_tree->cy_child;
3799 while (child != NULL) {
3800 if (child->cy_valuestring == NULL) {
3801 child = child->cy_next;
3805 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3808 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3809 child->cy_valuestring,
3810 strlen(child->cy_valuestring));
3811 if (rc != LUSTRE_CFG_RC_NO_ERR)
3815 child = child->cy_next;
3819 return LUSTRE_CFG_RC_MISSING_PARAM;
3824 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3826 list_del(&intf_descr->intf_on_network);
3827 free_intf_descr(intf_descr);
3834 yaml_extract_cmn_tunables(struct cYAML *tree,
3835 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3836 struct cfs_expr_list **global_cpts)
3838 struct cYAML *tun, *item, *smp;
3841 tun = cYAML_get_object_item(tree, "tunables");
3843 item = cYAML_get_object_item(tun, "peer_timeout");
3845 tunables->lct_peer_timeout = item->cy_valueint;
3846 item = cYAML_get_object_item(tun, "peer_credits");
3848 tunables->lct_peer_tx_credits = item->cy_valueint;
3849 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3851 tunables->lct_peer_rtr_credits = item->cy_valueint;
3852 item = cYAML_get_object_item(tun, "credits");
3854 tunables->lct_max_tx_credits = item->cy_valueint;
3855 smp = cYAML_get_object_item(tun, "CPT");
3857 rc = cfs_expr_list_parse(smp->cy_valuestring,
3858 strlen(smp->cy_valuestring),
3859 0, UINT_MAX, global_cpts);
3861 *global_cpts = NULL;
3871 yaml_extract_tunables(struct cYAML *tree,
3872 struct lnet_ioctl_config_lnd_tunables *tunables,
3873 struct cfs_expr_list **global_cpts,
3878 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3884 lustre_yaml_extract_lnd_tunables(tree, net_type,
3892 * - net type: <net>[<NUM>]
3894 * - nid: <ip>@<net>[<NUM>]
3897 * 0: <intf_name>['['<expr>']']
3898 * 1: <intf_name>['['<expr>']']
3900 * peer_timeout: <NUM>
3901 * peer_credits: <NUM>
3902 * peer_buffer_credits: <NUM>
3905 * peercredits_hiw: <NUM>
3906 * map_on_demand: <NUM>
3907 * concurrent_sends: <NUM>
3908 * fmr_pool_size: <NUM>
3909 * fmr_flush_trigger: <NUM>
3912 * At least one interface is required. If no interfaces are provided the
3913 * network interface can not be configured.
3915 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3916 struct cYAML **err_rc)
3918 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3920 int num_entries = 0, rc;
3921 struct lnet_dlc_network_descr nw_descr;
3922 struct cfs_expr_list *global_cpts = NULL;
3923 struct lnet_ioctl_config_lnd_tunables tunables;
3926 memset(&tunables, 0, sizeof(tunables));
3928 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3929 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3931 ip2net = cYAML_get_object_item(tree, "ip2net");
3932 net = cYAML_get_object_item(tree, "net type");
3934 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3936 nw_descr.nw_id = LOLND;
3939 * if neither net nor ip2nets are present, then we can not
3940 * configure the network.
3942 if (!net && !ip2net)
3943 return LUSTRE_CFG_RC_MISSING_PARAM;
3945 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3946 if (local_nis == NULL)
3947 return LUSTRE_CFG_RC_MISSING_PARAM;
3949 if (!cYAML_is_sequence(local_nis))
3950 return LUSTRE_CFG_RC_BAD_PARAM;
3952 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3953 intf = cYAML_get_object_item(item, "interfaces");
3956 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3957 if (num_entries <= 0) {
3958 cYAML_build_error(num_entries, -1, "ni", "add",
3959 "bad interface list",
3961 return LUSTRE_CFG_RC_BAD_PARAM;
3965 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3966 LNET_NETTYP(nw_descr.nw_id));
3967 seq_no = cYAML_get_object_item(tree, "seq_no");
3969 rc = lustre_lnet_config_ni(&nw_descr,
3971 (ip2net) ? ip2net->cy_valuestring : NULL,
3972 (found) ? &tunables: NULL,
3973 (seq_no) ? seq_no->cy_valueint : -1,
3976 if (global_cpts != NULL)
3977 cfs_expr_list_free(global_cpts);
3984 * - net-spec: <tcp|o2ib|gni>[NUM]
3986 * 0: <intf name>['['<expr>']']
3987 * 1: <intf name>['['<expr>']']
3989 * 0: <expr.expr.expr.expr>
3990 * 1: <expr.expr.expr.expr>
3992 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3993 struct cYAML **show_rc,
3994 struct cYAML **err_rc)
3996 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3998 struct lustre_lnet_ip2nets ip2nets;
3999 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4001 int rc = LUSTRE_CFG_RC_NO_ERR;
4002 struct cfs_expr_list *global_cpts = NULL;
4003 struct cfs_expr_list *el, *el_tmp;
4004 struct lnet_ioctl_config_lnd_tunables tunables;
4005 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4008 memset(&tunables, 0, sizeof(tunables));
4010 /* initialize all lists */
4011 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4012 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4013 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4015 net = cYAML_get_object_item(tree, "net-spec");
4017 return LUSTRE_CFG_RC_BAD_PARAM;
4019 if (net != NULL && net->cy_valuestring == NULL)
4020 return LUSTRE_CFG_RC_BAD_PARAM;
4022 /* assign the network id */
4023 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4024 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4025 return LUSTRE_CFG_RC_BAD_PARAM;
4027 seq_no = cYAML_get_object_item(tree, "seq_no");
4029 intf = cYAML_get_object_item(tree, "interfaces");
4031 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4033 return LUSTRE_CFG_RC_BAD_PARAM;
4036 ip_range = cYAML_get_object_item(tree, "ip-range");
4037 if (ip_range != NULL) {
4038 item = ip_range->cy_child;
4039 while (item != NULL) {
4040 if (item->cy_valuestring == NULL) {
4041 item = item->cy_next;
4045 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4046 item->cy_valuestring);
4048 if (rc != LUSTRE_CFG_RC_NO_ERR)
4051 item = item->cy_next;
4055 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4056 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4058 rc = lustre_lnet_config_ip2nets(&ip2nets,
4059 (found) ? &tunables : NULL,
4061 (seq_no) ? seq_no->cy_valueint : -1,
4065 * don't stop because there was no match. Continue processing the
4066 * rest of the rules. If non-match then nothing is configured
4068 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4069 rc = LUSTRE_CFG_RC_NO_ERR;
4071 list_for_each_entry_safe(intf_descr, intf_tmp,
4072 &ip2nets.ip2nets_net.nw_intflist,
4074 list_del(&intf_descr->intf_on_network);
4075 free_intf_descr(intf_descr);
4078 list_for_each_entry_safe(ip_range_descr, tmp,
4079 &ip2nets.ip2nets_ip_ranges,
4081 list_del(&ip_range_descr->ipr_entry);
4082 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4084 list_del(&el->el_link);
4085 cfs_expr_list_free(el);
4087 free(ip_range_descr);
4093 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4094 struct cYAML **err_rc)
4096 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4098 int num_entries, rc;
4099 struct lnet_dlc_network_descr nw_descr;
4101 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4102 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4104 net = cYAML_get_object_item(tree, "net type");
4106 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4108 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4109 if (local_nis == NULL)
4110 return LUSTRE_CFG_RC_MISSING_PARAM;
4112 if (!cYAML_is_sequence(local_nis))
4113 return LUSTRE_CFG_RC_BAD_PARAM;
4115 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4116 intf = cYAML_get_object_item(item, "interfaces");
4119 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4120 if (num_entries <= 0) {
4121 cYAML_build_error(num_entries, -1, "ni", "add",
4122 "bad interface list",
4124 return LUSTRE_CFG_RC_BAD_PARAM;
4128 seq_no = cYAML_get_object_item(tree, "seq_no");
4130 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4131 (seq_no) ? seq_no->cy_valueint : -1,
4137 /* Create a nidstring parseable by the nidstrings library from the nid
4138 * information encoded in the CYAML structure.
4139 * NOTE: Caller must free memory allocated to nidstr
4141 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4142 char *prim_nid, int cmd)
4144 int num_strs = 0, rc;
4145 size_t buf_size, buf_pos, nidstr_len = 0;
4147 struct cYAML *child = NULL, *entry = NULL;
4149 if (cYAML_is_sequence(nids_entry)) {
4150 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4151 entry = cYAML_get_object_item(child, "nid");
4152 /* don't count an empty entry */
4153 if (!entry || !entry->cy_valuestring)
4157 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4158 if (cmd == LNETCTL_DEL_CMD) {
4160 * primary nid is present in the list of
4161 * nids so that means we want to delete
4162 * the entire peer, so no need to go
4163 * further. Just delete the entire peer.
4165 return LUSTRE_CFG_RC_NO_ERR;
4172 * + 1 for the space separating each string, and
4173 * accounts for the terminating null char
4175 nidstr_len += strlen(entry->cy_valuestring) + 1;
4180 if (num_strs == 0 && !prim_nid)
4181 return LUSTRE_CFG_RC_MISSING_PARAM;
4182 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4183 return LUSTRE_CFG_RC_NO_ERR;
4185 buffer = malloc(nidstr_len);
4187 return LUSTRE_CFG_RC_OUT_OF_MEM;
4189 /* now grab all the nids */
4192 buf_size = nidstr_len;
4194 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4195 entry = cYAML_get_object_item(child, "nid");
4196 if (!entry || !entry->cy_valuestring)
4200 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4204 rc = snprintf(buffer + buf_pos, buf_size, " ");
4205 buf_pos += (rc < buf_size) ? rc : buf_size;
4206 buf_size = nidstr_len - buf_pos;
4209 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4210 entry->cy_valuestring);
4211 buf_pos += (rc < buf_size) ? rc : buf_size;
4212 buf_size = nidstr_len - buf_pos;
4217 return LUSTRE_CFG_RC_NO_ERR;
4220 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4221 struct cYAML **err_rc, int cmd)
4223 int rc, num_nids = 0, seqn;
4225 char *nidstr = NULL, *prim_nidstr;
4226 char err_str[LNET_MAX_STR_LEN];
4227 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4228 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4230 seq_no = cYAML_get_object_item(tree, "seq_no");
4231 seqn = seq_no ? seq_no->cy_valueint : -1;
4233 prim_nid = cYAML_get_object_item(tree, "primary nid");
4234 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4236 peer_nis = cYAML_get_object_item(tree, "peer ni");
4237 if (!(prim_nid || peer_nis)) {
4238 rc = LUSTRE_CFG_RC_BAD_PARAM;
4239 snprintf(err_str, LNET_MAX_STR_LEN,
4240 "Neither \"primary nid\" nor \"peer ni\" are defined");
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);
4284 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4285 num_nids, mr_value, seqn,
4288 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4289 num_nids, seqn, err_rc);
4295 if (rc != LUSTRE_CFG_RC_NO_ERR)
4296 cYAML_build_error(rc, seqn, "peer",
4297 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4303 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4304 struct cYAML **err_rc)
4306 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4309 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4310 struct cYAML **err_rc)
4312 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4315 static int handle_yaml_config_buffers(struct cYAML *tree,
4316 struct cYAML **show_rc,
4317 struct cYAML **err_rc)
4320 struct cYAML *tiny, *small, *large, *seq_no;
4322 tiny = cYAML_get_object_item(tree, "tiny");
4323 small = cYAML_get_object_item(tree, "small");
4324 large = cYAML_get_object_item(tree, "large");
4325 seq_no = cYAML_get_object_item(tree, "seq_no");
4327 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4328 (small) ? small->cy_valueint : -1,
4329 (large) ? large->cy_valueint : -1,
4330 (seq_no) ? seq_no->cy_valueint : -1,
4336 static int handle_yaml_config_routing(struct cYAML *tree,
4337 struct cYAML **show_rc,
4338 struct cYAML **err_rc)
4340 int rc = LUSTRE_CFG_RC_NO_ERR;
4341 struct cYAML *seq_no, *enable;
4343 seq_no = cYAML_get_object_item(tree, "seq_no");
4344 enable = cYAML_get_object_item(tree, "enable");
4347 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4349 seq_no->cy_valueint : -1,
4356 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4357 struct cYAML **err_rc)
4361 struct cYAML *seq_no;
4363 net = cYAML_get_object_item(tree, "net");
4364 gw = cYAML_get_object_item(tree, "gateway");
4365 seq_no = cYAML_get_object_item(tree, "seq_no");
4367 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4368 (gw) ? gw->cy_valuestring : NULL,
4369 (seq_no) ? seq_no->cy_valueint : -1,
4373 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4374 struct cYAML **err_rc)
4376 struct cYAML *seq_no;
4378 seq_no = cYAML_get_object_item(tree, "seq_no");
4380 return lustre_lnet_enable_routing(0, (seq_no) ?
4381 seq_no->cy_valueint : -1,
4385 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4386 struct cYAML **err_rc)
4392 struct cYAML *detail;
4393 struct cYAML *seq_no;
4395 net = cYAML_get_object_item(tree, "net");
4396 gw = cYAML_get_object_item(tree, "gateway");
4397 hop = cYAML_get_object_item(tree, "hop");
4398 prio = cYAML_get_object_item(tree, "priority");
4399 detail = cYAML_get_object_item(tree, "detail");
4400 seq_no = cYAML_get_object_item(tree, "seq_no");
4402 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4403 (gw) ? gw->cy_valuestring : NULL,
4404 (hop) ? hop->cy_valueint : -1,
4405 (prio) ? prio->cy_valueint : -1,
4406 (detail) ? detail->cy_valueint : 0,
4407 (seq_no) ? seq_no->cy_valueint : -1,
4408 show_rc, err_rc, false);
4411 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4412 struct cYAML **err_rc)
4414 struct cYAML *net, *detail, *seq_no;
4416 net = cYAML_get_object_item(tree, "net");
4417 detail = cYAML_get_object_item(tree, "detail");
4418 seq_no = cYAML_get_object_item(tree, "seq_no");
4420 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4421 (detail) ? detail->cy_valueint : 0,
4422 (seq_no) ? seq_no->cy_valueint : -1,
4423 show_rc, err_rc, false);
4426 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4427 struct cYAML **err_rc)
4429 struct cYAML *seq_no;
4431 seq_no = cYAML_get_object_item(tree, "seq_no");
4433 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4434 show_rc, err_rc, false);
4437 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4438 struct cYAML **err_rc)
4440 struct cYAML *seq_no, *nid, *detail;
4442 seq_no = cYAML_get_object_item(tree, "seq_no");
4443 detail = cYAML_get_object_item(tree, "detail");
4444 nid = cYAML_get_object_item(tree, "nid");
4446 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4447 (detail) ? detail->cy_valueint : 0,
4448 (seq_no) ? seq_no->cy_valueint : -1,
4449 show_rc, err_rc, false);
4452 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4453 struct cYAML **err_rc)
4455 struct cYAML *seq_no;
4457 seq_no = cYAML_get_object_item(tree, "seq_no");
4459 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4463 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4464 struct cYAML **err_rc)
4466 struct cYAML *seq_no, *range;
4468 seq_no = cYAML_get_object_item(tree, "seq_no");
4469 range = cYAML_get_object_item(tree, "range");
4471 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4472 seq_no ? seq_no->cy_valueint : -1,
4476 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4477 struct cYAML **err_rc)
4479 struct cYAML *seq_no;
4481 seq_no = cYAML_get_object_item(tree, "seq_no");
4483 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4487 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4488 struct cYAML **err_rc)
4490 struct cYAML *seq_no;
4492 seq_no = cYAML_get_object_item(tree, "seq_no");
4494 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4498 static int handle_yaml_config_global_settings(struct cYAML *tree,
4499 struct cYAML **show_rc,
4500 struct cYAML **err_rc)
4502 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4503 *sen, *recov, *rsen, *drop_asym_route;
4506 seq_no = cYAML_get_object_item(tree, "seq_no");
4507 max_intf = cYAML_get_object_item(tree, "max_intf");
4509 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4510 seq_no ? seq_no->cy_valueint
4514 numa = cYAML_get_object_item(tree, "numa_range");
4516 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4517 seq_no ? seq_no->cy_valueint
4521 discovery = cYAML_get_object_item(tree, "discovery");
4523 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4524 seq_no ? seq_no->cy_valueint
4528 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4529 if (drop_asym_route)
4530 rc = lustre_lnet_config_drop_asym_route(
4531 drop_asym_route->cy_valueint,
4532 seq_no ? seq_no->cy_valueint : -1,
4535 retry = cYAML_get_object_item(tree, "retry_count");
4537 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4538 seq_no ? seq_no->cy_valueint
4542 tto = cYAML_get_object_item(tree, "transaction_timeout");
4544 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4545 seq_no ? seq_no->cy_valueint
4549 sen = cYAML_get_object_item(tree, "health_sensitivity");
4551 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4552 seq_no ? seq_no->cy_valueint
4556 recov = cYAML_get_object_item(tree, "recovery_interval");
4558 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4559 seq_no ? seq_no->cy_valueint
4563 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4565 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4566 seq_no ? seq_no->cy_valueint
4573 static int handle_yaml_del_global_settings(struct cYAML *tree,
4574 struct cYAML **show_rc,
4575 struct cYAML **err_rc)
4577 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4580 seq_no = cYAML_get_object_item(tree, "seq_no");
4581 max_intf = cYAML_get_object_item(tree, "max_intf");
4583 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4584 seq_no ? seq_no->cy_valueint
4588 numa = cYAML_get_object_item(tree, "numa_range");
4590 rc = lustre_lnet_config_numa_range(0,
4591 seq_no ? seq_no->cy_valueint
4595 /* peer discovery is enabled by default */
4596 discovery = cYAML_get_object_item(tree, "discovery");
4598 rc = lustre_lnet_config_discovery(1,
4599 seq_no ? seq_no->cy_valueint
4603 /* asymmetrical route messages are accepted by default */
4604 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4605 if (drop_asym_route)
4606 rc = lustre_lnet_config_drop_asym_route(
4607 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4612 static int handle_yaml_show_global_settings(struct cYAML *tree,
4613 struct cYAML **show_rc,
4614 struct cYAML **err_rc)
4616 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4617 *sen, *recov, *rsen, *drop_asym_route;
4620 seq_no = cYAML_get_object_item(tree, "seq_no");
4621 max_intf = cYAML_get_object_item(tree, "max_intf");
4623 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4627 numa = cYAML_get_object_item(tree, "numa_range");
4629 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4633 discovery = cYAML_get_object_item(tree, "discovery");
4635 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4639 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4640 if (drop_asym_route)
4641 rc = lustre_lnet_show_drop_asym_route(
4642 seq_no ? seq_no->cy_valueint : -1,
4645 retry = cYAML_get_object_item(tree, "retry_count");
4647 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4651 tto = cYAML_get_object_item(tree, "transaction_timeout");
4653 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4657 sen = cYAML_get_object_item(tree, "health_sensitivity");
4659 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4663 recov = cYAML_get_object_item(tree, "recovery_interval");
4665 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4669 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4671 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4678 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4679 struct cYAML **err_rc)
4681 struct cYAML *seq_no, *nid, *timeout;
4683 seq_no = cYAML_get_object_item(tree, "seq_no");
4684 nid = cYAML_get_object_item(tree, "primary nid");
4685 timeout = cYAML_get_object_item(tree, "timeout");
4687 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4688 (timeout) ? timeout->cy_valueint : 1000,
4689 (seq_no) ? seq_no->cy_valueint : -1,
4693 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4694 struct cYAML **err_rc)
4696 struct cYAML *seq_no, *nid, *force;
4698 seq_no = cYAML_get_object_item(tree, "seq_no");
4699 nid = cYAML_get_object_item(tree, "primary nid");
4700 force = cYAML_get_object_item(tree, "force");
4702 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4703 (force) ? force->cy_valueint : 0,
4704 (seq_no) ? seq_no->cy_valueint : -1,
4708 static int handle_yaml_no_op()
4710 return LUSTRE_CFG_RC_NO_ERR;
4713 struct lookup_cmd_hdlr_tbl {
4718 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4719 { .name = "route", .cb = handle_yaml_config_route },
4720 { .name = "net", .cb = handle_yaml_config_ni },
4721 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4722 { .name = "peer", .cb = handle_yaml_config_peer },
4723 { .name = "routing", .cb = handle_yaml_config_routing },
4724 { .name = "buffers", .cb = handle_yaml_config_buffers },
4725 { .name = "statistics", .cb = handle_yaml_no_op },
4726 { .name = "global", .cb = handle_yaml_config_global_settings},
4727 { .name = "numa", .cb = handle_yaml_config_numa },
4728 { .name = "ping", .cb = handle_yaml_no_op },
4729 { .name = "discover", .cb = handle_yaml_no_op },
4732 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4733 { .name = "route", .cb = handle_yaml_del_route },
4734 { .name = "net", .cb = handle_yaml_del_ni },
4735 { .name = "ip2nets", .cb = handle_yaml_no_op },
4736 { .name = "peer", .cb = handle_yaml_del_peer },
4737 { .name = "routing", .cb = handle_yaml_del_routing },
4738 { .name = "buffers", .cb = handle_yaml_no_op },
4739 { .name = "statistics", .cb = handle_yaml_no_op },
4740 { .name = "global", .cb = handle_yaml_del_global_settings},
4741 { .name = "numa", .cb = handle_yaml_del_numa },
4742 { .name = "ping", .cb = handle_yaml_no_op },
4743 { .name = "discover", .cb = handle_yaml_no_op },
4746 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4747 { .name = "route", .cb = handle_yaml_show_route },
4748 { .name = "net", .cb = handle_yaml_show_net },
4749 { .name = "peer", .cb = handle_yaml_show_peers },
4750 { .name = "ip2nets", .cb = handle_yaml_no_op },
4751 { .name = "routing", .cb = handle_yaml_show_routing },
4752 { .name = "buffers", .cb = handle_yaml_show_routing },
4753 { .name = "statistics", .cb = handle_yaml_show_stats },
4754 { .name = "global", .cb = handle_yaml_show_global_settings},
4755 { .name = "numa", .cb = handle_yaml_show_numa },
4756 { .name = "ping", .cb = handle_yaml_no_op },
4757 { .name = "discover", .cb = handle_yaml_no_op },
4760 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4761 { .name = "route", .cb = handle_yaml_no_op },
4762 { .name = "net", .cb = handle_yaml_no_op },
4763 { .name = "peer", .cb = handle_yaml_no_op },
4764 { .name = "ip2nets", .cb = handle_yaml_no_op },
4765 { .name = "routing", .cb = handle_yaml_no_op },
4766 { .name = "buffers", .cb = handle_yaml_no_op },
4767 { .name = "statistics", .cb = handle_yaml_no_op },
4768 { .name = "global", .cb = handle_yaml_no_op },
4769 { .name = "numa", .cb = handle_yaml_no_op },
4770 { .name = "ping", .cb = handle_yaml_ping },
4771 { .name = "discover", .cb = handle_yaml_discover },
4774 static cmd_handler_t lookup_fn(char *key,
4775 struct lookup_cmd_hdlr_tbl *tbl)
4781 for (i = 0; tbl[i].name != NULL; i++) {
4782 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4789 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4790 struct cYAML **show_rc, struct cYAML **err_rc)
4792 struct cYAML *tree, *item = NULL, *head, *child;
4794 char err_str[LNET_MAX_STR_LEN];
4795 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4797 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4799 return LUSTRE_CFG_RC_BAD_PARAM;
4801 child = tree->cy_child;
4802 while (child != NULL) {
4803 cb = lookup_fn(child->cy_string, table);
4805 snprintf(err_str, sizeof(err_str),
4806 "\"call back for '%s' not found\"",
4808 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4809 "yaml", "helper", err_str, err_rc);
4813 if (cYAML_is_sequence(child)) {
4814 while ((head = cYAML_get_next_seq_item(child, &item))
4816 rc = cb(head, show_rc, err_rc);
4817 if (rc != LUSTRE_CFG_RC_NO_ERR)
4821 rc = cb(child, show_rc, err_rc);
4822 if (rc != LUSTRE_CFG_RC_NO_ERR)
4826 child = child->cy_next;
4830 cYAML_free_tree(tree);
4835 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4837 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4841 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4843 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4847 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4849 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4853 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4855 return lustre_yaml_cb_helper(f, lookup_exec_tbl,