4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #define CONFIG_CMD "configure"
59 #define UNCONFIG_CMD "unconfigure"
62 #define SHOW_CMD "show"
64 #define MANAGE_CMD "manage"
66 #define MAX_NUM_IPS 128
68 #define modparam_path "/sys/module/lnet/parameters/"
69 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
70 #define gni_nid_path "/proc/cray_xt/"
72 #ifndef HAVE_USRSPC_RDMA_PS_TCP
73 #define RDMA_PS_TCP 0x0106
76 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
80 * lustre_lnet_ip_range_descr
81 * Describes an IP range.
82 * Each octect is an expression
84 struct lustre_lnet_ip_range_descr {
85 struct list_head ipr_entry;
86 struct list_head ipr_expr;
91 * Describes an ip2nets rule. This can be on a list of rules.
93 struct lustre_lnet_ip2nets {
94 struct lnet_dlc_network_descr ip2nets_net;
95 struct list_head ip2nets_ip_ranges;
98 int open_sysfs_file(const char *path, const char *attr, const int mode)
101 char filename[LNET_MAX_STR_LEN];
103 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
106 snprintf(filename, sizeof(filename), "%s%s",
109 fd = open(filename, mode);
114 static int read_sysfs_file(const char *path, const char *attr,
115 void *val, const size_t size, const int nelem)
118 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
120 fd = open_sysfs_file(path, attr, O_RDONLY);
122 return LUSTRE_CFG_RC_NO_MATCH;
124 if (read(fd, val, size * nelem) == -1)
127 rc = LUSTRE_CFG_RC_NO_ERR;
134 static int write_sysfs_file(const char *path, const char *attr,
135 void *val, const size_t size, const int nelem)
138 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
140 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
142 return LUSTRE_CFG_RC_NO_MATCH;
144 if (write(fd, val, size * nelem) == -1)
147 rc = LUSTRE_CFG_RC_NO_ERR;
156 * frees the memory allocated for an intf descriptor.
158 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
163 if (intf_descr->cpt_expr != NULL)
164 cfs_expr_list_free(intf_descr->cpt_expr);
169 * lustre_lnet_add_ip_range
171 * given a string of the format:
172 * <expr.expr.expr.expr> parse each expr into
173 * a lustre_lnet_ip_range_descr structure and insert on the list.
175 * This function is called from
176 * YAML on each ip-range.
177 * As a result of lnetctl command
178 * When building a NID or P2P selection rules
180 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
182 struct lustre_lnet_ip_range_descr *ip_range;
185 ip_range = calloc(1, sizeof(*ip_range));
186 if (ip_range == NULL)
187 return LUSTRE_CFG_RC_OUT_OF_MEM;
189 INIT_LIST_HEAD(&ip_range->ipr_entry);
190 INIT_LIST_HEAD(&ip_range->ipr_expr);
192 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
193 &ip_range->ipr_expr);
195 return LUSTRE_CFG_RC_BAD_PARAM;
197 list_add_tail(&ip_range->ipr_entry, list);
199 return LUSTRE_CFG_RC_NO_ERR;
202 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
204 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
206 struct lnet_dlc_intf_descr *intf_descr = NULL;
208 char intf_string[LNET_MAX_STR_LEN];
210 if (len >= LNET_MAX_STR_LEN)
211 return LUSTRE_CFG_RC_BAD_PARAM;
213 strncpy(intf_string, intf, len);
214 intf_string[len] = '\0';
216 intf_descr = calloc(1, sizeof(*intf_descr));
217 if (intf_descr == NULL)
218 return LUSTRE_CFG_RC_OUT_OF_MEM;
220 INIT_LIST_HEAD(&intf_descr->intf_on_network);
222 intf_name = intf_string;
223 open_sq_bracket = strchr(intf_string, '[');
224 if (open_sq_bracket != NULL) {
225 close_sq_bracket = strchr(intf_string, ']');
226 if (close_sq_bracket == NULL) {
228 return LUSTRE_CFG_RC_BAD_PARAM;
230 rc = cfs_expr_list_parse(open_sq_bracket,
231 strlen(open_sq_bracket), 0, UINT_MAX,
232 &intf_descr->cpt_expr);
235 return LUSTRE_CFG_RC_BAD_PARAM;
237 strncpy(intf_descr->intf_name, intf_name,
238 open_sq_bracket - intf_name);
239 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
241 strcpy(intf_descr->intf_name, intf_name);
242 intf_descr->cpt_expr = NULL;
245 list_add_tail(&intf_descr->intf_on_network, list);
247 return LUSTRE_CFG_RC_NO_ERR;
250 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
252 if (nw_descr != NULL) {
254 INIT_LIST_HEAD(&nw_descr->network_on_rule);
255 INIT_LIST_HEAD(&nw_descr->nw_intflist);
259 int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
261 int bracket = 0, num_str = 0;
262 char *strstart, *chptr;
265 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
266 return LUSTRE_CFG_RC_BAD_PARAM;
269 /* comma-separated nidranges -> space-separated nidranges */
273 if (*chptr == '\0') {
274 out[num_str] = strstart;
281 else if (*chptr == ']')
285 snprintf(err_str, LNET_MAX_STR_LEN,
286 "Mismatched brackets in nidstring \"%s\"",
288 return LUSTRE_CFG_RC_BAD_PARAM;
291 if (bracket == 0 && *chptr == ',') {
292 out[num_str] = strstart;
295 strstart = chptr + 1;
302 snprintf(err_str, LNET_MAX_STR_LEN,
303 "Mismatched brackets in nidstring \"%s\"", nidstr);
304 return LUSTRE_CFG_RC_BAD_PARAM;
310 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
311 int max_nids, char *err_str)
313 int rc, num_nids = 0;
314 struct list_head nidlist;
317 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
318 return LUSTRE_CFG_RC_BAD_PARAM;
321 if (strchr(nidstr, '*')) {
322 snprintf(err_str, LNET_MAX_STR_LEN,
323 "asterisk not allowed in nidstring \"%s\"", nidstr);
324 return LUSTRE_CFG_RC_BAD_PARAM;
327 INIT_LIST_HEAD(&nidlist);
328 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
330 snprintf(err_str, LNET_MAX_STR_LEN,
331 "Unable to parse nidlist from: %s\n", nidstr);
332 return LUSTRE_CFG_RC_BAD_PARAM;
335 if (list_empty(&nidlist)) {
336 snprintf(err_str, LNET_MAX_STR_LEN,
337 "\"%s\" does not specify any valid nid lists", nidstr);
338 return LUSTRE_CFG_RC_BAD_PARAM;
341 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
343 if (num_nids == -1) {
344 snprintf(err_str, LNET_MAX_STR_LEN,
345 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
347 return LUSTRE_CFG_RC_BAD_PARAM;
351 snprintf(err_str, LNET_MAX_STR_LEN,
352 "Failed to expand nidstr: %s", strerror(num_nids));
353 return LUSTRE_CFG_RC_OUT_OF_MEM;
357 snprintf(err_str, LNET_MAX_STR_LEN,
358 "\"%s\" did not expand to any nids", nidstr);
359 return LUSTRE_CFG_RC_BAD_PARAM;
367 * <intf>[<expr>], <intf>[<expr>],..
369 int lustre_lnet_parse_interfaces(char *intf_str,
370 struct lnet_dlc_network_descr *nw_descr)
375 char *cur = intf_str, *next = NULL;
376 char *end = intf_str + strlen(intf_str);
378 struct lnet_dlc_intf_descr *intf_descr, *tmp;
380 if (nw_descr == NULL)
381 return LUSTRE_CFG_RC_BAD_PARAM;
384 open_square = strchr(cur, '[');
385 if (open_square != NULL) {
386 close_square = strchr(cur, ']');
387 if (close_square == NULL) {
388 rc = LUSTRE_CFG_RC_BAD_PARAM;
392 comma = strchr(cur, ',');
393 if (comma != NULL && comma > close_square) {
395 len = next - close_square;
401 comma = strchr(cur, ',');
411 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
412 if (rc != LUSTRE_CFG_RC_NO_ERR)
418 return LUSTRE_CFG_RC_NO_ERR;
421 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
423 list_del(&intf_descr->intf_on_network);
424 free_intf_descr(intf_descr);
430 int lustre_lnet_config_lib_init(void)
432 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
435 void lustre_lnet_config_lib_uninit(void)
437 unregister_ioc_dev(LNET_DEV_ID);
440 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
441 int seq_no, struct cYAML **err_rc)
443 struct libcfs_ioctl_data data;
446 char err_str[LNET_MAX_STR_LEN];
448 snprintf(err_str, sizeof(err_str), "\"Success\"");
450 LIBCFS_IOC_INIT(data);
452 /* Reverse logic is used here in order not to change
453 * the lctl utility */
454 data.ioc_flags = load_ni_from_mod ? 0 : 1;
456 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
458 rc = l_ioctl(LNET_DEV_ID, opc, &data);
462 "\"LNet %s error: %s\"", (up) ? "configure" :
463 "unconfigure", strerror(errno));
467 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
468 "lnet", err_str, err_rc);
473 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
474 char *err_str, char *cmd_str)
478 rc = l_ioctl(LNET_DEV_ID, cmd, data);
481 snprintf(err_str, LNET_MAX_STR_LEN,
482 "\"%s peer ni operation failed: %s\"",
483 cmd_str, strerror(errno));
489 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
490 int seq_no, struct cYAML **show_rc,
491 struct cYAML **err_rc)
494 struct lnet_ioctl_ping_data ping;
495 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
496 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
497 struct lnet_process_id id;
498 char err_str[LNET_MAX_STR_LEN] = {0};
499 char *sep, *token, *end;
502 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
506 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
508 data = calloc(1, len);
512 /* create struct cYAML root object */
513 root = cYAML_create_object(NULL, NULL);
517 ping_node = cYAML_create_seq(root, oper);
518 if (ping_node == NULL)
521 /* tokenise each nid in string ping_nids */
522 token = strtok(ping_nids, ",");
525 item = cYAML_create_seq_item(ping_node);
529 if (first_seq == NULL)
532 /* check if '-' is a part of NID, token */
533 sep = strchr(token, '-');
535 id.pid = LNET_PID_ANY;
536 /* if no net is specified, libcfs_str2nid() will assume tcp */
537 id.nid = libcfs_str2nid(token);
538 if (id.nid == LNET_NID_ANY) {
539 snprintf(err_str, sizeof(err_str),
540 "\"cannot parse NID '%s'\"",
542 rc = LUSTRE_CFG_RC_BAD_PARAM;
543 cYAML_build_error(rc, seq_no, MANAGE_CMD,
544 oper, err_str, err_rc);
548 if (token[0] == 'u' || token[0] == 'U')
549 id.pid = (strtoul(&token[1], &end, 0) |
550 (LNET_PID_USERFLAG));
552 id.pid = strtoul(token, &end, 0);
554 /* assuming '-' is part of hostname */
556 id.pid = LNET_PID_ANY;
557 id.nid = libcfs_str2nid(token);
558 if (id.nid == LNET_NID_ANY) {
559 snprintf(err_str, sizeof(err_str),
560 "\"cannot parse NID '%s'\"",
562 rc = LUSTRE_CFG_RC_BAD_PARAM;
563 cYAML_build_error(rc, seq_no, MANAGE_CMD,
569 id.nid = libcfs_str2nid(sep + 1);
570 if (id.nid == LNET_NID_ANY) {
571 snprintf(err_str, sizeof(err_str),
572 "\"cannot parse NID '%s'\"",
574 rc = LUSTRE_CFG_RC_BAD_PARAM;
575 cYAML_build_error(rc, seq_no, MANAGE_CMD,
582 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
583 ping.ping_hdr.ioc_len = sizeof(ping);
585 ping.op_param = param;
586 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
587 ping.ping_buf = data;
589 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
592 sizeof(err_str), "failed to %s %s: %s\n", oper,
593 id.pid == LNET_PID_ANY ?
594 libcfs_nid2str(id.nid) :
595 libcfs_id2str(id), strerror(errno));
596 rc = LUSTRE_CFG_RC_BAD_PARAM;
597 cYAML_build_error(rc, seq_no, MANAGE_CMD,
598 oper, err_str, err_rc);
602 if (cYAML_create_string(item, "primary nid",
603 libcfs_nid2str(ping.ping_id.nid)) == NULL)
606 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
607 "True" : "False") == NULL)
610 tmp = cYAML_create_seq(item, "peer ni");
614 for (i = 0; i < ping.ping_count; i++) {
615 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
617 peer_ni = cYAML_create_seq_item(tmp);
620 memset(buf, 0, sizeof buf);
621 snprintf(buf, sizeof buf, "nid");
622 if (cYAML_create_string(peer_ni, buf,
623 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
629 } while ((token = strtok(NULL, ",")) != NULL);
632 rc = LUSTRE_CFG_RC_NO_ERR;
637 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
638 cYAML_free_tree(root);
639 } else if (show_rc != NULL && *show_rc != NULL) {
640 struct cYAML *show_node;
641 show_node = cYAML_get_object_item(*show_rc, oper);
642 if (show_node != NULL && cYAML_is_sequence(show_node)) {
643 cYAML_insert_child(show_node, first_seq);
646 } else if (show_node == NULL) {
647 cYAML_insert_sibling((*show_rc)->cy_child,
651 cYAML_free_tree(root);
660 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
661 struct cYAML **show_rc, struct cYAML **err_rc)
665 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
666 seq_no, show_rc, err_rc);
670 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
671 struct cYAML **show_rc, struct cYAML **err_rc)
675 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
676 seq_no, show_rc, err_rc);
680 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
681 bool is_mr, __u32 cmd,
682 char *cmd_type, char *err_str)
684 struct lnet_ioctl_peer_cfg data;
687 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
688 /* When adding a peer we first need to create the peer using the
689 * specified (or implied) primary nid. Then we can add
690 * additional nids to this peer using the primary nid as a key
692 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
693 data.prcfg_mr = is_mr;
694 data.prcfg_prim_nid = nidlist[0];
695 data.prcfg_cfg_nid = LNET_NID_ANY;
697 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
703 /* Add or delete any specified NIs associated with the specified
704 * (or implied) primary nid
706 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
707 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
708 data.prcfg_mr = is_mr;
709 data.prcfg_prim_nid = nidlist[0];
710 data.prcfg_cfg_nid = nidlist[nid_idx];
712 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
718 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
719 /* In the delete case we may have been given just the
720 * primary nid of the peer. This tells us to delete the peer
721 * completely (rather than just delete some of its NIs)
723 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
724 data.prcfg_prim_nid = nidlist[0];
725 data.prcfg_cfg_nid = LNET_NID_ANY;
727 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
733 int lustre_lnet_config_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
734 int num_nids, bool is_mr, int seq_no,
735 struct cYAML **err_rc)
737 int rc = LUSTRE_CFG_RC_NO_ERR;
738 char err_str[LNET_MAX_STR_LEN];
739 lnet_nid_t *lnet_nidlist2 = NULL;
743 pnid = libcfs_str2nid(pnidstr);
744 if (pnid == LNET_NID_ANY) {
745 snprintf(err_str, LNET_MAX_STR_LEN,
746 "bad primary NID: '%s'", pnidstr);
747 rc = LUSTRE_CFG_RC_MISSING_PARAM;
753 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
754 if (!lnet_nidlist2) {
755 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
756 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
759 lnet_nidlist2[0] = pnid;
760 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
764 rc = lustre_lnet_handle_peer_nidlist((pnidstr) ? lnet_nidlist2 :
767 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
773 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
777 int lustre_lnet_del_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
778 int num_nids, int seq_no,
779 struct cYAML **err_rc)
781 int rc = LUSTRE_CFG_RC_NO_ERR;
782 char err_str[LNET_MAX_STR_LEN];
783 lnet_nid_t *lnet_nidlist2 = NULL;
787 snprintf(err_str, sizeof(err_str),
788 "\"Primary nid is not provided\"");
789 rc = LUSTRE_CFG_RC_MISSING_PARAM;
793 pnid = libcfs_str2nid(pnidstr);
794 if (pnid == LNET_NID_ANY) {
795 rc = LUSTRE_CFG_RC_BAD_PARAM;
796 snprintf(err_str, sizeof(err_str),
803 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
804 if (!lnet_nidlist2) {
805 snprintf(err_str, sizeof(err_str),
807 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
810 lnet_nidlist2[0] = pnid;
811 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
814 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2, num_nids, false,
815 IOC_LIBCFS_DEL_PEER_NI, DEL_CMD,
821 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
825 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
826 int sen, int seq_no, struct cYAML **err_rc,
829 int rc, num_nids, num_nidstrs, nid_idx, str_idx;
831 char err_str[LNET_MAX_STR_LEN];
832 char *nidstrarray[LNET_MAX_STR_LEN];
833 struct lnet_ioctl_config_data data;
834 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
836 memset(err_str, 0, LNET_MAX_STR_LEN);
837 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
839 if (nw == NULL || nidstr == NULL) {
840 snprintf(err_str, LNET_MAX_STR_LEN,
841 "\"missing mandatory parameter:'%s'\"",
842 (nw == NULL && nidstr == NULL) ? "network, gateway" :
843 (nw == NULL) ? "network" : "gateway");
844 rc = LUSTRE_CFG_RC_MISSING_PARAM;
848 rnet = libcfs_str2net(nw);
849 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
850 snprintf(err_str, LNET_MAX_STR_LEN,
851 "\"cannot parse remote net %s\"", nw);
852 rc = LUSTRE_CFG_RC_BAD_PARAM;
856 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
862 for (str_idx = 0; str_idx < num_nidstrs; str_idx++) {
863 rc = lustre_lnet_parse_nidstr(nidstrarray[str_idx],
865 LNET_MAX_NIDS_PER_PEER, err_str);
871 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
873 if (cmd == LNETCTL_ADD_CMD) {
874 data.cfg_config_u.cfg_route.rtr_hop = hops;
875 data.cfg_config_u.cfg_route.rtr_priority = prio;
876 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
879 for (nid_idx = 0; nid_idx < num_nids; nid_idx++) {
880 data.cfg_nid = lnet_nidlist[nid_idx];
882 if (cmd == LNETCTL_ADD_CMD)
883 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
886 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
889 if (rc != 0 && errno != EEXIST &&
890 errno != EHOSTUNREACH) {
892 snprintf(err_str, LNET_MAX_STR_LEN,
893 "route operation failed: %s",
901 cYAML_build_error(rc, seq_no,
902 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
908 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
909 int sen, int seq_no, struct cYAML **err_rc)
912 char err_str[LNET_MAX_STR_LEN];
913 memset(err_str, 0, LNET_MAX_STR_LEN);
914 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
917 hops = LNET_UNDEFINED_HOPS;
918 } else if (hops < 1 || hops > 255) {
919 snprintf(err_str, LNET_MAX_STR_LEN,
920 "\"invalid hop count %d, must be between 1 and 255\"",
922 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
928 } else if (prio < 0) {
929 snprintf(err_str, LNET_MAX_STR_LEN,
930 "\"invalid priority %d, must be greater than 0\"",
932 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
938 } else if (sen < 1) {
939 snprintf(err_str, LNET_MAX_STR_LEN,
940 "\"invalid health sensitivity %d, must be 1 or greater\"",
942 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
946 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
947 err_rc, LNETCTL_ADD_CMD);
950 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
955 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
956 struct cYAML **err_rc)
958 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
962 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
963 int seq_no, struct cYAML **show_rc,
964 struct cYAML **err_rc, bool backup)
966 struct lnet_ioctl_config_data data;
967 lnet_nid_t gateway_nid;
968 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
970 __u32 net = LNET_NIDNET(LNET_NID_ANY);
972 struct cYAML *root = NULL, *route = NULL, *item = NULL;
973 struct cYAML *first_seq = NULL;
974 char err_str[LNET_MAX_STR_LEN];
977 snprintf(err_str, sizeof(err_str),
978 "\"out of memory\"");
981 net = libcfs_str2net(nw);
982 if (net == LNET_NIDNET(LNET_NID_ANY)) {
985 "\"cannot parse net '%s'\"", nw);
986 rc = LUSTRE_CFG_RC_BAD_PARAM;
991 /* show all routes without filtering on net */
992 net = LNET_NIDNET(LNET_NID_ANY);
996 gateway_nid = libcfs_str2nid(gw);
997 if (gateway_nid == LNET_NID_ANY) {
1000 "\"cannot parse gateway NID '%s'\"", gw);
1001 rc = LUSTRE_CFG_RC_BAD_PARAM;
1005 /* show all routes with out filtering on gateway */
1006 gateway_nid = LNET_NID_ANY;
1008 if ((hops < 1 && hops != -1) || hops > 255) {
1011 "\"invalid hop count %d, must be between 0 and 256\"",
1013 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1017 /* create struct cYAML root object */
1018 root = cYAML_create_object(NULL, NULL);
1022 route = cYAML_create_seq(root, "route");
1030 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1033 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1039 /* filter on provided data */
1040 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1041 net != data.cfg_net)
1044 if (gateway_nid != LNET_NID_ANY &&
1045 gateway_nid != data.cfg_nid)
1049 hops != data.cfg_config_u.cfg_route.rtr_hop)
1053 prio != data.cfg_config_u.cfg_route.rtr_priority)
1056 /* default rc to -1 incase we hit the goto */
1060 item = cYAML_create_seq_item(route);
1064 if (first_seq == NULL)
1067 if (cYAML_create_string(item, "net",
1068 libcfs_net2str(data.cfg_net)) == NULL)
1071 if (cYAML_create_string(item, "gateway",
1072 libcfs_nid2str(data.cfg_nid)) == NULL)
1076 if (cYAML_create_number(item, "hop",
1077 (int) data.cfg_config_u.
1078 cfg_route.rtr_hop) ==
1082 if (cYAML_create_number(item, "priority",
1084 cfg_route.rtr_priority) == NULL)
1087 if (cYAML_create_number(item, "health_sensitivity",
1089 cfg_route.rtr_sensitivity) == NULL)
1092 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1094 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1098 cYAML_create_string(item, "state",
1100 "up" : "down") == NULL)
1104 cYAML_create_string(item, "type",
1106 "multi-hop" : "single-hop") == NULL)
1111 /* print output iff show_rc is not provided */
1112 if (show_rc == NULL)
1113 cYAML_print_tree(root);
1115 if (l_errno != ENOENT) {
1118 "\"cannot get routes: %s\"",
1123 rc = LUSTRE_CFG_RC_NO_ERR;
1125 snprintf(err_str, sizeof(err_str), "\"success\"");
1127 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1128 cYAML_free_tree(root);
1129 } else if (show_rc != NULL && *show_rc != NULL) {
1130 struct cYAML *show_node;
1131 /* find the route node, if one doesn't exist then
1132 * insert one. Otherwise add to the one there
1134 show_node = cYAML_get_object_item(*show_rc, "route");
1135 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1136 cYAML_insert_child(show_node, first_seq);
1139 } else if (show_node == NULL) {
1140 cYAML_insert_sibling((*show_rc)->cy_child,
1144 cYAML_free_tree(root);
1150 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1155 static int socket_intf_query(int request, char *intf,
1161 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1162 return LUSTRE_CFG_RC_BAD_PARAM;
1164 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1166 return LUSTRE_CFG_RC_BAD_PARAM;
1168 strcpy(ifr->ifr_name, intf);
1169 rc = ioctl(sockfd, request, ifr);
1171 rc = LUSTRE_CFG_RC_BAD_PARAM;
1178 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1183 memset(&ifr, 0, sizeof(ifr));
1184 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1186 return LUSTRE_CFG_RC_BAD_PARAM;
1188 if ((ifr.ifr_flags & IFF_UP) == 0)
1189 return LUSTRE_CFG_RC_BAD_PARAM;
1191 memset(&ifr, 0, sizeof(ifr));
1192 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1194 return LUSTRE_CFG_RC_BAD_PARAM;
1196 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1197 *ip = bswap_32(*ip);
1199 return LUSTRE_CFG_RC_NO_ERR;
1203 * for each interface in the array of interfaces find the IP address of
1204 * that interface, create its nid and add it to an array of NIDs.
1205 * Stop if any of the interfaces is down
1207 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1208 lnet_nid_t **nids, __u32 *nnids,
1209 char *err_str, size_t str_len)
1211 int i = 0, count = 0, rc;
1212 struct lnet_dlc_intf_descr *intf;
1213 char val[LNET_MAX_STR_LEN];
1220 if (nw == NULL || nids == NULL) {
1221 snprintf(err_str, str_len,
1222 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1223 err_str[str_len - 1] = '\0';
1224 return LUSTRE_CFG_RC_BAD_PARAM;
1227 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1230 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1234 *nids = calloc(count, sizeof(lnet_nid_t));
1235 if (*nids == NULL) {
1236 snprintf(err_str, str_len,
1237 "\"out of memory\"");
1238 err_str[str_len - 1] = '\0';
1239 return LUSTRE_CFG_RC_OUT_OF_MEM;
1242 * special case the GNI interface since it doesn't have an IP
1243 * address. The assumption is that there can only be one GNI
1244 * interface in the system. No interface name is provided.
1246 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1247 rc = read_sysfs_file(gni_nid_path, "nid", val,
1250 snprintf(err_str, str_len,
1251 "\"cannot read gni nid\"");
1252 err_str[str_len - 1] = '\0';
1255 gni_num = atoi(val);
1257 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1262 /* look at the other interfaces */
1263 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1264 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1265 /* handle LNDs with numeric interface name */
1266 num = strtoul(intf->intf_name, &endp, 0);
1267 if (endp == intf->intf_name || *endp != '\0') {
1268 rc = LUSTRE_CFG_RC_BAD_PARAM;
1269 snprintf(err_str, str_len,
1270 "\"couldn't query intf %s\"",
1272 err_str[str_len - 1] = '\0';
1275 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1278 /* handle LNDs with ip interface name */
1279 rc = lustre_lnet_queryip(intf, &ip);
1280 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1281 snprintf(err_str, str_len,
1282 "\"couldn't query intf %s\"",
1284 err_str[str_len - 1] = '\0';
1287 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1304 * called repeatedly until a match or no more ip range
1306 * ip_range expression
1307 * interface list with all the interface names.
1308 * all the interfaces in the system.
1310 * try to match the ip_range expr to one of the interfaces' IPs in
1311 * the system. If we hit a patch for an interface. Check if that
1312 * interface name is in the list.
1314 * If there are more than one interface in the list, then make sure
1315 * that the IPs for all of these interfaces match the ip ranges
1318 * for each interface in intf_list
1319 * look up the intf name in ifa
1320 * if not there then no match
1321 * check ip obtained from ifa against a match to any of the
1323 * If no match, then fail
1325 * The result is that all the interfaces have to match.
1327 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1328 struct list_head *intf_list,
1329 struct list_head *ip_ranges)
1333 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1334 struct ifaddrs *ifaddr = ifa;
1335 struct lustre_lnet_ip_range_descr *ip_range;
1339 * if there are no explicit interfaces, and no ip ranges, then
1340 * configure the first tcp interface we encounter.
1342 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1343 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1344 if (ifaddr->ifa_addr == NULL)
1347 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1350 family = ifaddr->ifa_addr->sa_family;
1351 if (family == AF_INET &&
1352 strcmp(ifaddr->ifa_name, "lo") != 0) {
1353 rc = lustre_lnet_add_intf_descr
1354 (intf_list, ifaddr->ifa_name,
1355 strlen(ifaddr->ifa_name));
1357 if (rc != LUSTRE_CFG_RC_NO_ERR)
1360 return LUSTRE_CFG_RC_MATCH;
1363 return LUSTRE_CFG_RC_NO_MATCH;
1367 * First interface which matches an IP pattern will be used
1369 if (list_empty(intf_list)) {
1371 * no interfaces provided in the rule, but an ip range is
1372 * provided, so try and match an interface to the ip
1375 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1376 if (ifaddr->ifa_addr == NULL)
1379 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1382 family = ifaddr->ifa_addr->sa_family;
1383 if (family == AF_INET) {
1384 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1387 list_for_each_entry(ip_range, ip_ranges,
1389 rc = cfs_ip_addr_match(bswap_32(ip),
1390 &ip_range->ipr_expr);
1394 rc = lustre_lnet_add_intf_descr
1395 (intf_list, ifaddr->ifa_name,
1396 strlen(ifaddr->ifa_name));
1398 if (rc != LUSTRE_CFG_RC_NO_ERR)
1404 if (!list_empty(intf_list))
1405 return LUSTRE_CFG_RC_MATCH;
1407 return LUSTRE_CFG_RC_NO_MATCH;
1411 * If an interface is explicitly specified the ip-range might or
1412 * might not be specified. if specified the interface needs to match the
1413 * ip-range. If no ip-range then the interfaces are
1414 * automatically matched if they are all up.
1415 * If > 1 interfaces all the interfaces must match for the NI to
1418 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1419 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1420 if (ifaddr->ifa_addr == NULL)
1423 family = ifaddr->ifa_addr->sa_family;
1424 if (family == AF_INET &&
1425 strcmp(intf_descr->intf_name,
1426 ifaddr->ifa_name) == 0)
1430 if (ifaddr == NULL) {
1431 list_del(&intf_descr->intf_on_network);
1432 free_intf_descr(intf_descr);
1436 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1437 list_del(&intf_descr->intf_on_network);
1438 free_intf_descr(intf_descr);
1442 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1445 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1446 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1452 /* no match for this interface */
1453 list_del(&intf_descr->intf_on_network);
1454 free_intf_descr(intf_descr);
1458 return LUSTRE_CFG_RC_MATCH;
1461 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1462 lnet_nid_t **nids, __u32 *nnids,
1463 char *err_str, size_t str_len)
1465 struct ifaddrs *ifa;
1466 int rc = LUSTRE_CFG_RC_NO_ERR;
1468 rc = getifaddrs(&ifa);
1470 snprintf(err_str, str_len,
1471 "\"failed to get interface addresses: %d\"", -errno);
1472 err_str[str_len - 1] = '\0';
1476 rc = lustre_lnet_match_ip_to_intf(ifa,
1477 &ip2nets->ip2nets_net.nw_intflist,
1478 &ip2nets->ip2nets_ip_ranges);
1479 if (rc != LUSTRE_CFG_RC_MATCH) {
1480 snprintf(err_str, str_len,
1481 "\"couldn't match ip to existing interfaces\"");
1482 err_str[str_len - 1] = '\0';
1487 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1488 err_str, sizeof(err_str));
1489 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1500 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1501 struct lnet_ioctl_config_lnd_tunables *tunables,
1502 struct cfs_expr_list *global_cpts,
1503 lnet_nid_t *nids, char *err_str)
1506 struct lnet_ioctl_config_ni *conf;
1507 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1508 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1511 struct lnet_dlc_intf_descr *intf_descr;
1513 struct cfs_expr_list *cpt_expr;
1515 list_for_each_entry(intf_descr, intf_list,
1517 if (tunables != NULL)
1518 len = sizeof(struct lnet_ioctl_config_ni) +
1519 sizeof(struct lnet_ioctl_config_lnd_tunables);
1521 len = sizeof(struct lnet_ioctl_config_ni);
1523 data = calloc(1, len);
1525 return LUSTRE_CFG_RC_OUT_OF_MEM;
1526 conf = (struct lnet_ioctl_config_ni*) data;
1527 if (tunables != NULL)
1528 tun = (struct lnet_ioctl_config_lnd_tunables*)
1531 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1532 conf->lic_cfg_hdr.ioc_len = len;
1533 conf->lic_nid = nids[i];
1534 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1537 if (intf_descr->cpt_expr != NULL)
1538 cpt_expr = intf_descr->cpt_expr;
1539 else if (global_cpts != NULL)
1540 cpt_expr = global_cpts;
1544 if (cpt_expr != NULL) {
1545 count = cfs_expr_list_values(cpt_expr,
1546 LNET_MAX_SHOW_NUM_CPT,
1549 memcpy(conf->lic_cpts, cpt_array,
1550 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1559 conf->lic_ncpts = count;
1561 if (tunables != NULL)
1562 memcpy(tun, tunables, sizeof(*tunables));
1564 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1569 "\"cannot add network: %s\"", strerror(errno));
1577 return LUSTRE_CFG_RC_NO_ERR;
1581 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1582 struct lnet_ioctl_config_lnd_tunables *tunables,
1583 struct cfs_expr_list *global_cpts,
1584 int seq_no, struct cYAML **err_rc)
1586 lnet_nid_t *nids = NULL;
1589 char err_str[LNET_MAX_STR_LEN];
1591 snprintf(err_str, sizeof(err_str), "\"success\"");
1596 "\"incomplete ip2nets information\"");
1597 rc = LUSTRE_CFG_RC_BAD_PARAM;
1602 * call below function to resolve the rules into a list of nids.
1603 * The memory is allocated in that function then freed here when
1604 * it's no longer needed.
1606 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1608 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1611 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1612 snprintf(err_str, sizeof(err_str),
1613 "\"no interfaces match ip2nets rules\"");
1617 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1618 tunables, global_cpts, nids,
1625 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1629 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1630 struct cfs_expr_list *global_cpts,
1632 struct lnet_ioctl_config_lnd_tunables *tunables,
1633 int seq_no, struct cYAML **err_rc)
1636 struct lnet_ioctl_config_ni *conf;
1637 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1638 char buf[LNET_MAX_STR_LEN];
1639 int rc = LUSTRE_CFG_RC_NO_ERR;
1640 char err_str[LNET_MAX_STR_LEN];
1641 lnet_nid_t *nids = NULL;
1645 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1648 snprintf(err_str, sizeof(err_str), "\"success\"");
1650 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1651 (list_empty(&nw_descr->nw_intflist) &&
1652 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1655 "\"missing mandatory parameters in NI config: '%s'\"",
1656 (nw_descr == NULL) ? "network , interface" :
1657 (nw_descr->nw_id == 0) ? "network" : "interface");
1658 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1662 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1665 "\"ip2net string too long %d\"",
1666 (int)strlen(ip2net));
1667 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1671 if (ip2net != NULL) {
1672 if (tunables != NULL)
1673 len = sizeof(struct lnet_ioctl_config_ni) +
1674 sizeof(struct lnet_ioctl_config_lnd_tunables);
1676 len = sizeof(struct lnet_ioctl_config_ni);
1677 data = calloc(1, len);
1679 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1682 conf = (struct lnet_ioctl_config_ni*) data;
1683 if (tunables != NULL)
1684 tun = (struct lnet_ioctl_config_lnd_tunables*)
1685 (data + sizeof(*conf));
1687 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1688 conf->lic_cfg_hdr.ioc_len = len;
1689 strncpy(conf->lic_legacy_ip2nets, ip2net,
1692 if (global_cpts != NULL) {
1693 count = cfs_expr_list_values(global_cpts,
1694 LNET_MAX_SHOW_NUM_CPT,
1697 memcpy(conf->lic_cpts, cpt_array,
1698 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1707 conf->lic_ncpts = count;
1709 if (tunables != NULL)
1710 memcpy(tun, tunables, sizeof(*tunables));
1712 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1717 "\"cannot add network: %s\"", strerror(errno));
1724 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1725 rc = LUSTRE_CFG_RC_NO_ERR;
1729 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1732 "\"cannot parse net '%s'\"",
1733 libcfs_net2str(nw_descr->nw_id));
1734 rc = LUSTRE_CFG_RC_BAD_PARAM;
1739 * special case the GNI since no interface name is expected
1741 if (list_empty(&nw_descr->nw_intflist) &&
1742 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1745 "\"no interface name provided\"");
1746 rc = LUSTRE_CFG_RC_BAD_PARAM;
1750 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1751 err_str, sizeof(err_str));
1753 rc = LUSTRE_CFG_RC_BAD_PARAM;
1757 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1758 tunables, global_cpts, nids,
1762 if (nw_descr != NULL) {
1763 list_for_each_entry_safe(intf_descr, tmp,
1764 &nw_descr->nw_intflist,
1766 list_del(&intf_descr->intf_on_network);
1767 free_intf_descr(intf_descr);
1771 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1782 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1783 int seq_no, struct cYAML **err_rc)
1785 struct lnet_ioctl_config_ni data;
1786 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1787 char err_str[LNET_MAX_STR_LEN];
1788 lnet_nid_t *nids = NULL;
1790 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1792 snprintf(err_str, sizeof(err_str), "\"success\"");
1794 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1797 "\"missing mandatory parameter in deleting NI: '%s'\"",
1798 (nw_descr == NULL) ? "network , interface" :
1799 (nw_descr->nw_id == 0) ? "network" : "interface");
1800 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1804 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1805 return LUSTRE_CFG_RC_NO_ERR;
1807 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1810 "\"cannot parse net '%s'\"",
1811 libcfs_net2str(nw_descr->nw_id));
1812 rc = LUSTRE_CFG_RC_BAD_PARAM;
1816 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1817 err_str, sizeof(err_str));
1819 rc = LUSTRE_CFG_RC_BAD_PARAM;
1824 * no interfaces just the nw_id is specified
1827 nids = calloc(1, sizeof(*nids));
1829 snprintf(err_str, sizeof(err_str),
1830 "\"out of memory\"");
1831 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1834 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1838 for (i = 0; i < nnids; i++) {
1839 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1840 data.lic_nid = nids[i];
1842 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1847 "\"cannot del network: %s\"", strerror(errno));
1851 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1853 list_del(&intf_descr->intf_on_network);
1854 free_intf_descr(intf_descr);
1858 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1867 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1868 enum lnet_health_type type, char *name,
1869 int seq_no, struct cYAML **err_rc)
1871 struct lnet_ioctl_reset_health_cfg data;
1872 int rc = LUSTRE_CFG_RC_NO_ERR;
1873 char err_str[LNET_MAX_STR_LEN];
1875 snprintf(err_str, sizeof(err_str), "\"success\"");
1877 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1878 data.rh_type = type;
1880 data.rh_value = value;
1883 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1887 sizeof(err_str), "Can not configure health value: %s",
1891 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1896 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1897 struct cYAML **err_rc)
1901 nid = libcfs_str2nid(ni_nid);
1904 return lustre_lnet_config_healthv(value, all, nid,
1905 LNET_HEALTH_TYPE_LOCAL_NI,
1906 "ni healthv", seq_no, err_rc);
1909 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1910 int seq_no, struct cYAML **err_rc)
1914 nid = libcfs_str2nid(lpni_nid);
1917 return lustre_lnet_config_healthv(value, all, nid,
1918 LNET_HEALTH_TYPE_PEER_NI,
1919 "peer_ni healthv", seq_no, err_rc);
1923 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1924 struct lnet_ioctl_comm_count *counts)
1926 if (cYAML_create_number(yaml, "put",
1927 counts->ico_put_count)
1930 if (cYAML_create_number(yaml, "get",
1931 counts->ico_get_count)
1934 if (cYAML_create_number(yaml, "reply",
1935 counts->ico_reply_count)
1938 if (cYAML_create_number(yaml, "ack",
1939 counts->ico_ack_count)
1942 if (cYAML_create_number(yaml, "hello",
1943 counts->ico_hello_count)
1950 static struct lnet_ioctl_comm_count *
1951 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1954 return &msg_stats->im_send_stats;
1956 return &msg_stats->im_recv_stats;
1958 return &msg_stats->im_drop_stats;
1963 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1964 struct cYAML **show_rc, struct cYAML **err_rc,
1968 struct lnet_ioctl_config_ni *ni_data;
1969 struct lnet_ioctl_config_lnd_tunables *lnd;
1970 struct lnet_ioctl_element_stats *stats;
1971 struct lnet_ioctl_element_msg_stats msg_stats;
1972 struct lnet_ioctl_local_ni_hstats hstats;
1973 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1974 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1975 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1977 struct cYAML *root = NULL, *tunables = NULL,
1978 *net_node = NULL, *interfaces = NULL,
1979 *item = NULL, *first_seq = NULL,
1980 *tmp = NULL, *statistics = NULL,
1982 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1983 char str_buf[str_buf_len];
1985 char err_str[LNET_MAX_STR_LEN];
1986 bool exist = false, new_net = true;
1988 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1990 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1992 buf = calloc(1, buf_size);
1996 ni_data = (struct lnet_ioctl_config_ni *)buf;
1999 net = libcfs_str2net(nw);
2000 if (net == LNET_NIDNET(LNET_NID_ANY)) {
2003 "\"cannot parse net '%s'\"", nw);
2004 rc = LUSTRE_CFG_RC_BAD_PARAM;
2009 root = cYAML_create_object(NULL, NULL);
2013 net_node = cYAML_create_seq(root, "net");
2014 if (net_node == NULL)
2020 memset(buf, 0, buf_size);
2022 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2024 * set the ioc_len to the proper value since INIT assumes
2027 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2028 ni_data->lic_idx = i;
2030 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2036 rc_net = LNET_NIDNET(ni_data->lic_nid);
2038 /* filter on provided data */
2039 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2043 /* if we're backing up don't store lo */
2044 if (backup && LNET_NETTYP(rc_net) == LOLND)
2047 /* default rc to -1 in case we hit the goto */
2051 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2052 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2053 (ni_data->lic_bulk + sizeof(*stats));
2055 if (rc_net != prev_net) {
2062 if (!cYAML_create_string(net_node, "net type",
2063 libcfs_net2str(rc_net)))
2066 tmp = cYAML_create_seq(net_node, "local NI(s)");
2072 /* create the tree to be printed. */
2073 item = cYAML_create_seq_item(tmp);
2077 if (first_seq == NULL)
2081 cYAML_create_string(item, "nid",
2082 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2086 cYAML_create_string(item,
2088 (ni_data->lic_status ==
2089 LNET_NI_STATUS_UP) ?
2090 "up" : "down") == NULL)
2093 /* don't add interfaces unless there is at least one
2095 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2096 interfaces = cYAML_create_object(item, "interfaces");
2097 if (interfaces == NULL)
2100 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2101 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2103 sizeof(str_buf), "%d", j);
2104 if (cYAML_create_string(interfaces,
2106 ni_data->lic_ni_intf[j]) ==
2118 goto continue_without_msg_stats;
2120 statistics = cYAML_create_object(item, "statistics");
2121 if (statistics == NULL)
2124 if (cYAML_create_number(statistics, "send_count",
2125 stats->iel_send_count)
2129 if (cYAML_create_number(statistics, "recv_count",
2130 stats->iel_recv_count)
2134 if (cYAML_create_number(statistics, "drop_count",
2135 stats->iel_drop_count)
2140 goto continue_without_msg_stats;
2142 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2143 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2144 msg_stats.im_idx = i;
2146 rc = l_ioctl(LNET_DEV_ID,
2147 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2151 goto continue_without_msg_stats;
2154 for (k = 0; k < 3; k++) {
2155 struct lnet_ioctl_comm_count *counts;
2156 struct cYAML *msg_statistics = NULL;
2158 msg_statistics = cYAML_create_object(item,
2159 (char *)gmsg_stat_names[k]);
2160 if (msg_statistics == NULL)
2163 counts = get_counts(&msg_stats, k);
2167 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2172 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2173 hstats.hlni_nid = ni_data->lic_nid;
2174 /* grab health stats */
2175 rc = l_ioctl(LNET_DEV_ID,
2176 IOC_LIBCFS_GET_LOCAL_HSTATS,
2180 goto continue_without_msg_stats;
2182 yhstats = cYAML_create_object(item, "health stats");
2185 if (cYAML_create_number(yhstats, "health value",
2186 hstats.hlni_health_value)
2189 if (cYAML_create_number(yhstats, "interrupts",
2190 hstats.hlni_local_interrupt)
2193 if (cYAML_create_number(yhstats, "dropped",
2194 hstats.hlni_local_dropped)
2197 if (cYAML_create_number(yhstats, "aborted",
2198 hstats.hlni_local_aborted)
2201 if (cYAML_create_number(yhstats, "no route",
2202 hstats.hlni_local_no_route)
2205 if (cYAML_create_number(yhstats, "timeouts",
2206 hstats.hlni_local_timeout)
2209 if (cYAML_create_number(yhstats, "error",
2210 hstats.hlni_local_error)
2214 continue_without_msg_stats:
2215 tunables = cYAML_create_object(item, "tunables");
2219 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2220 if (rc != LUSTRE_CFG_RC_NO_ERR)
2223 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2225 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2226 rc != LUSTRE_CFG_RC_NO_MATCH)
2229 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2230 tunables = cYAML_create_object(item,
2232 if (tunables == NULL)
2237 cYAML_create_number(item, "dev cpt",
2238 ni_data->lic_dev_cpt) == NULL)
2242 cYAML_create_number(item, "tcp bonding",
2243 ni_data->lic_tcp_bonding)
2247 /* out put the CPTs in the format: "[x,x,x,...]" */
2249 limit = str_buf + str_buf_len - 3;
2250 pos += scnprintf(pos, limit - pos, "\"[");
2251 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2252 j < ni_data->lic_ncpts &&
2254 pos += scnprintf(pos, limit - pos,
2255 "%d", ni_data->lic_cpts[j]);
2256 if ((j + 1) < ni_data->lic_ncpts)
2257 pos += scnprintf(pos, limit - pos, ",");
2259 snprintf(pos, 3, "]\"");
2261 if (ni_data->lic_ncpts >= 1 &&
2262 cYAML_create_string(item, "CPT",
2268 /* Print out the net information only if show_rc is not provided */
2269 if (show_rc == NULL)
2270 cYAML_print_tree(root);
2272 if (l_errno != ENOENT) {
2275 "\"cannot get networks: %s\"",
2280 rc = LUSTRE_CFG_RC_NO_ERR;
2282 snprintf(err_str, sizeof(err_str), "\"success\"");
2284 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2285 cYAML_free_tree(root);
2286 } else if (show_rc != NULL && *show_rc != NULL) {
2287 struct cYAML *show_node;
2288 /* find the net node, if one doesn't exist
2289 * then insert one. Otherwise add to the one there
2291 show_node = cYAML_get_object_item(*show_rc, "net");
2292 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2293 cYAML_insert_child(show_node, first_seq);
2296 } else if (show_node == NULL) {
2297 cYAML_insert_sibling((*show_rc)->cy_child,
2301 cYAML_free_tree(root);
2307 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2312 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2314 struct lnet_ioctl_config_data data;
2315 int rc = LUSTRE_CFG_RC_NO_ERR;
2316 char err_str[LNET_MAX_STR_LEN];
2318 snprintf(err_str, sizeof(err_str), "\"success\"");
2320 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2321 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2323 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2328 "\"cannot %s routing %s\"",
2329 (enable) ? "enable" : "disable", strerror(errno));
2334 cYAML_build_error(rc, seq_no,
2335 (enable) ? ADD_CMD : DEL_CMD,
2336 "routing", err_str, err_rc);
2341 int ioctl_set_value(__u32 val, int ioc, char *name,
2342 int seq_no, struct cYAML **err_rc)
2344 struct lnet_ioctl_set_value data;
2345 int rc = LUSTRE_CFG_RC_NO_ERR;
2346 char err_str[LNET_MAX_STR_LEN];
2348 snprintf(err_str, sizeof(err_str), "\"success\"");
2350 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2351 data.sv_value = val;
2353 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2358 "\"cannot configure %s to %d: %s\"", name,
2359 val, strerror(errno));
2362 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2367 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2369 int rc = LUSTRE_CFG_RC_NO_ERR;
2370 char err_str[LNET_MAX_STR_LEN];
2371 char val[LNET_MAX_STR_LEN];
2373 snprintf(err_str, sizeof(err_str), "\"success\"");
2375 snprintf(val, sizeof(val), "%d", intrv);
2377 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2378 1, strlen(val) + 1);
2380 snprintf(err_str, sizeof(err_str),
2381 "\"cannot configure recovery interval: %s\"",
2384 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2389 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2391 int rc = LUSTRE_CFG_RC_NO_ERR;
2392 char err_str[LNET_MAX_STR_LEN];
2393 char val[LNET_MAX_STR_LEN];
2395 snprintf(err_str, sizeof(err_str), "\"success\"");
2397 snprintf(val, sizeof(val), "%d", sen);
2399 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2400 1, strlen(val) + 1);
2402 snprintf(err_str, sizeof(err_str),
2403 "\"cannot configure router health sensitivity: %s\"",
2406 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2411 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2413 int rc = LUSTRE_CFG_RC_NO_ERR;
2414 char err_str[LNET_MAX_STR_LEN];
2415 char val[LNET_MAX_STR_LEN];
2417 snprintf(err_str, sizeof(err_str), "\"success\"");
2419 snprintf(val, sizeof(val), "%d", sen);
2421 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2422 1, strlen(val) + 1);
2424 snprintf(err_str, sizeof(err_str),
2425 "\"cannot configure health sensitivity: %s\"",
2428 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2433 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2435 int rc = LUSTRE_CFG_RC_NO_ERR;
2436 char err_str[LNET_MAX_STR_LEN];
2437 char val[LNET_MAX_STR_LEN];
2439 snprintf(err_str, sizeof(err_str), "\"success\"");
2441 snprintf(val, sizeof(val), "%d", timeout);
2443 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2444 1, strlen(val) + 1);
2446 snprintf(err_str, sizeof(err_str),
2447 "\"cannot configure transaction timeout: %s\"",
2450 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2455 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2457 int rc = LUSTRE_CFG_RC_NO_ERR;
2458 char err_str[LNET_MAX_STR_LEN];
2459 char val[LNET_MAX_STR_LEN];
2461 snprintf(err_str, sizeof(err_str), "\"success\"");
2463 snprintf(val, sizeof(val), "%d", count);
2465 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2466 1, strlen(val) + 1);
2468 snprintf(err_str, sizeof(err_str),
2469 "\"cannot configure retry count: %s\"",
2472 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2477 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2479 int rc = LUSTRE_CFG_RC_NO_ERR;
2480 char err_str[LNET_MAX_STR_LEN];
2481 char val[LNET_MAX_STR_LEN];
2483 snprintf(err_str, sizeof(err_str), "\"success\"");
2485 snprintf(val, sizeof(val), "%d", max);
2487 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2488 1, strlen(val) + 1);
2490 snprintf(err_str, sizeof(err_str),
2491 "\"cannot configure max interfaces: %s\"",
2494 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2499 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2501 int rc = LUSTRE_CFG_RC_NO_ERR;
2502 char err_str[LNET_MAX_STR_LEN];
2503 char val[LNET_MAX_STR_LEN];
2505 snprintf(err_str, sizeof(err_str), "\"success\"");
2507 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2509 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2510 1, strlen(val) + 1);
2512 snprintf(err_str, sizeof(err_str),
2513 "\"cannot configure discovery: %s\"",
2516 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2522 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2523 struct cYAML **err_rc)
2525 int rc = LUSTRE_CFG_RC_NO_ERR;
2526 char err_str[LNET_MAX_STR_LEN];
2527 char val[LNET_MAX_STR_LEN];
2529 snprintf(err_str, sizeof(err_str), "\"success\"");
2531 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2533 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2534 1, strlen(val) + 1);
2536 snprintf(err_str, sizeof(err_str),
2537 "\"cannot configure drop asym route: %s\"",
2540 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2547 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2549 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2550 "numa_range", seq_no, err_rc);
2553 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2554 struct cYAML **err_rc)
2556 struct lnet_ioctl_config_data data;
2557 int rc = LUSTRE_CFG_RC_NO_ERR;
2558 char err_str[LNET_MAX_STR_LEN];
2560 snprintf(err_str, sizeof(err_str), "\"success\"");
2562 /* -1 indicates to ignore changes to this field */
2563 if (tiny < -1 || small < -1 || large < -1) {
2566 "\"tiny, small and large must be >= 0\"");
2567 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2571 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2572 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2573 data.cfg_config_u.cfg_buffers.buf_small = small;
2574 data.cfg_config_u.cfg_buffers.buf_large = large;
2576 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2581 "\"cannot configure buffers: %s\"", strerror(errno));
2586 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2591 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2592 struct cYAML **err_rc, bool backup)
2594 struct lnet_ioctl_config_data *data;
2595 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2596 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2599 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2600 int buf_count[LNET_NRBPOOLS] = {0};
2601 struct cYAML *root = NULL, *pools_node = NULL,
2602 *type_node = NULL, *item = NULL, *cpt = NULL,
2603 *first_seq = NULL, *buffers = NULL;
2605 char err_str[LNET_MAX_STR_LEN];
2606 char node_name[LNET_MAX_STR_LEN];
2609 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2611 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2615 data = (struct lnet_ioctl_config_data *)buf;
2617 root = cYAML_create_object(NULL, NULL);
2622 pools_node = cYAML_create_object(root, "routing");
2624 pools_node = cYAML_create_seq(root, "routing");
2625 if (pools_node == NULL)
2629 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2630 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2631 sizeof(struct lnet_ioctl_pool_cfg);
2632 data->cfg_count = i;
2634 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2642 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2645 goto calculate_buffers;
2647 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2648 item = cYAML_create_seq_item(pools_node);
2652 if (first_seq == NULL)
2655 cpt = cYAML_create_object(item, node_name);
2660 /* create the tree and print */
2661 for (j = 0; j < LNET_NRBPOOLS; j++) {
2663 type_node = cYAML_create_object(cpt, pools[j]);
2664 if (type_node == NULL)
2668 cYAML_create_number(type_node, "npages",
2669 pool_cfg->pl_pools[j].pl_npages)
2673 cYAML_create_number(type_node, "nbuffers",
2674 pool_cfg->pl_pools[j].
2675 pl_nbuffers) == NULL)
2678 cYAML_create_number(type_node, "credits",
2679 pool_cfg->pl_pools[j].
2680 pl_credits) == NULL)
2683 cYAML_create_number(type_node, "mincredits",
2684 pool_cfg->pl_pools[j].
2685 pl_mincredits) == NULL)
2687 /* keep track of the total count for each of the
2688 * tiny, small and large buffers */
2689 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2693 if (pool_cfg != NULL) {
2695 if (cYAML_create_number(pools_node, "enable",
2696 pool_cfg->pl_routing) ==
2700 goto add_buffer_section;
2703 item = cYAML_create_seq_item(pools_node);
2707 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2713 /* create a buffers entry in the show. This is necessary so that
2714 * if the YAML output is used to configure a node, the buffer
2715 * configuration takes hold */
2716 buffers = cYAML_create_object(root, "buffers");
2717 if (buffers == NULL)
2720 for (i = 0; i < LNET_NRBPOOLS; i++) {
2721 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2725 if (show_rc == NULL)
2726 cYAML_print_tree(root);
2728 if (l_errno != ENOENT) {
2731 "\"cannot get routing information: %s\"",
2736 rc = LUSTRE_CFG_RC_NO_ERR;
2738 snprintf(err_str, sizeof(err_str), "\"success\"");
2739 rc = LUSTRE_CFG_RC_NO_ERR;
2743 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2744 cYAML_free_tree(root);
2745 } else if (show_rc != NULL && *show_rc != NULL) {
2746 struct cYAML *routing_node;
2747 /* there should exist only one routing block and one
2748 * buffers block. If there already exists a previous one
2749 * then don't add another */
2750 routing_node = cYAML_get_object_item(*show_rc, "routing");
2751 if (routing_node == NULL) {
2752 cYAML_insert_sibling((*show_rc)->cy_child,
2756 cYAML_free_tree(root);
2762 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2767 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2768 struct cYAML **show_rc, struct cYAML **err_rc,
2772 * TODO: This function is changing in a future patch to accommodate
2773 * PEER_LIST and proper filtering on any nid of the peer
2775 struct lnet_ioctl_peer_cfg peer_info;
2776 struct lnet_peer_ni_credit_info *lpni_cri;
2777 struct lnet_ioctl_element_stats *lpni_stats;
2778 struct lnet_ioctl_element_msg_stats *msg_stats;
2779 struct lnet_ioctl_peer_ni_hstats *hstats;
2781 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2786 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2787 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2788 *msg_statistics = NULL, *statistics = NULL,
2790 char err_str[LNET_MAX_STR_LEN];
2791 struct lnet_process_id *list = NULL;
2796 snprintf(err_str, sizeof(err_str),
2797 "\"out of memory\"");
2799 /* create struct cYAML root object */
2800 root = cYAML_create_object(NULL, NULL);
2804 peer_root = cYAML_create_seq(root, "peer");
2805 if (peer_root == NULL)
2809 size = count * sizeof(struct lnet_process_id);
2810 list = malloc(size);
2816 list[0].nid = libcfs_str2nid(knid);
2820 memset(&peer_info, 0, sizeof(peer_info));
2821 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2822 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2823 peer_info.prcfg_size = size;
2824 peer_info.prcfg_bulk = list;
2827 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2829 count = peer_info.prcfg_count;
2833 if (l_errno != E2BIG) {
2836 "\"cannot get peer list: %s\"",
2842 size = peer_info.prcfg_size;
2843 list = malloc(size);
2852 data = malloc(size);
2858 for (i = 0; i < count; i++) {
2860 memset(&peer_info, 0, sizeof(peer_info));
2861 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2862 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2863 peer_info.prcfg_prim_nid = list[i].nid;
2864 peer_info.prcfg_size = size;
2865 peer_info.prcfg_bulk = data;
2868 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2873 if (l_errno != E2BIG) {
2876 "\"cannot get peer information: %s\"",
2882 size = peer_info.prcfg_size;
2883 data = malloc(size);
2891 peer = cYAML_create_seq_item(peer_root);
2895 if (first_seq == NULL)
2898 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2899 if (cYAML_create_string(peer, "primary nid",
2900 libcfs_nid2str(pnid))
2903 if (cYAML_create_string(peer, "Multi-Rail",
2904 peer_info.prcfg_mr ? "True" : "False")
2908 * print out the state of the peer only if details are
2913 cYAML_create_number(peer, "peer state",
2914 peer_info.prcfg_state)
2919 tmp = cYAML_create_seq(peer, "peer ni");
2924 for (j = 0; j < peer_info.prcfg_count; j++) {
2926 lpni_cri = (void*)nidp + sizeof(nidp);
2927 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2928 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2929 hstats = (void *)msg_stats + sizeof(*msg_stats);
2930 lpni_data = (void *)hstats + sizeof(*hstats);
2932 peer_ni = cYAML_create_seq_item(tmp);
2933 if (peer_ni == NULL)
2936 if (cYAML_create_string(peer_ni, "nid",
2937 libcfs_nid2str(*nidp))
2944 if (cYAML_create_string(peer_ni, "state",
2945 lpni_cri->cr_aliveness)
2952 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2953 lpni_cri->cr_ni_peer_tx_credits)
2957 if (cYAML_create_number(peer_ni, "available_tx_credits",
2958 lpni_cri->cr_peer_tx_credits)
2962 if (cYAML_create_number(peer_ni, "min_tx_credits",
2963 lpni_cri->cr_peer_min_tx_credits)
2967 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2968 lpni_cri->cr_peer_tx_qnob)
2972 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2973 lpni_cri->cr_peer_rtr_credits)
2977 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2978 lpni_cri->cr_peer_min_rtr_credits)
2982 if (cYAML_create_number(peer_ni, "refcount",
2983 lpni_cri->cr_refcount) == NULL)
2986 statistics = cYAML_create_object(peer_ni, "statistics");
2987 if (statistics == NULL)
2990 if (cYAML_create_number(statistics, "send_count",
2991 lpni_stats->iel_send_count)
2995 if (cYAML_create_number(statistics, "recv_count",
2996 lpni_stats->iel_recv_count)
3000 if (cYAML_create_number(statistics, "drop_count",
3001 lpni_stats->iel_drop_count)
3008 for (k = 0; k < 3; k++) {
3009 struct lnet_ioctl_comm_count *counts;
3011 msg_statistics = cYAML_create_object(peer_ni,
3012 (char *) gmsg_stat_names[k]);
3013 if (msg_statistics == NULL)
3016 counts = get_counts(msg_stats, k);
3020 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3025 yhstats = cYAML_create_object(peer_ni, "health stats");
3028 if (cYAML_create_number(yhstats, "health value",
3029 hstats->hlpni_health_value)
3032 if (cYAML_create_number(yhstats, "dropped",
3033 hstats->hlpni_remote_dropped)
3036 if (cYAML_create_number(yhstats, "timeout",
3037 hstats->hlpni_remote_timeout)
3040 if (cYAML_create_number(yhstats, "error",
3041 hstats->hlpni_remote_error)
3044 if (cYAML_create_number(yhstats, "network timeout",
3045 hstats->hlpni_network_timeout)
3051 /* print output iff show_rc is not provided */
3052 if (show_rc == NULL)
3053 cYAML_print_tree(root);
3055 snprintf(err_str, sizeof(err_str), "\"success\"");
3056 rc = LUSTRE_CFG_RC_NO_ERR;
3061 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3062 cYAML_free_tree(root);
3063 } else if (show_rc != NULL && *show_rc != NULL) {
3064 struct cYAML *show_node;
3065 /* find the peer node, if one doesn't exist then
3066 * insert one. Otherwise add to the one there
3068 show_node = cYAML_get_object_item(*show_rc,
3070 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3071 cYAML_insert_child(show_node, first_seq);
3074 } else if (show_node == NULL) {
3075 cYAML_insert_sibling((*show_rc)->cy_child,
3079 cYAML_free_tree(root);
3085 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3091 int lustre_lnet_list_peer(int seq_no,
3092 struct cYAML **show_rc, struct cYAML **err_rc)
3094 struct lnet_ioctl_peer_cfg peer_info;
3095 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3100 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3101 char err_str[LNET_MAX_STR_LEN];
3102 struct lnet_process_id *list = NULL;
3104 snprintf(err_str, sizeof(err_str),
3105 "\"out of memory\"");
3107 memset(&peer_info, 0, sizeof(peer_info));
3109 /* create struct cYAML root object */
3110 root = cYAML_create_object(NULL, NULL);
3114 list_root = cYAML_create_seq(root, "peer list");
3115 if (list_root == NULL)
3119 size = count * sizeof(struct lnet_process_id);
3120 list = malloc(size);
3126 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3127 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3128 peer_info.prcfg_size = size;
3129 peer_info.prcfg_bulk = list;
3132 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3133 count = peer_info.prcfg_count;
3137 if (l_errno != E2BIG) {
3140 "\"cannot get peer list: %s\"",
3146 size = peer_info.prcfg_size;
3147 list = malloc(size);
3154 /* count is now the actual number of ids in the list. */
3155 for (i = 0; i < count; i++) {
3156 if (cYAML_create_string(list_root, "nid",
3157 libcfs_nid2str(list[i].nid))
3162 /* print output iff show_rc is not provided */
3163 if (show_rc == NULL)
3164 cYAML_print_tree(root);
3166 snprintf(err_str, sizeof(err_str), "\"success\"");
3167 rc = LUSTRE_CFG_RC_NO_ERR;
3172 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3173 cYAML_free_tree(root);
3174 } else if (show_rc != NULL && *show_rc != NULL) {
3175 struct cYAML *show_node;
3176 /* find the peer node, if one doesn't exist then
3177 * insert one. Otherwise add to the one there
3179 show_node = cYAML_get_object_item(*show_rc,
3181 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3182 cYAML_insert_child(show_node, first_seq);
3185 } else if (show_node == NULL) {
3186 cYAML_insert_sibling((*show_rc)->cy_child,
3190 cYAML_free_tree(root);
3196 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3202 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3205 struct cYAML *show_node;
3207 show_node = cYAML_get_object_item(show_rc, "global");
3208 if (show_node != NULL)
3209 cYAML_insert_sibling(show_node->cy_child,
3212 cYAML_insert_sibling(show_rc->cy_child,
3217 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3218 char *name, __u64 value,
3219 struct cYAML **show_rc,
3220 struct cYAML **err_rc, int err)
3222 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3223 struct cYAML *root = NULL, *global = NULL;
3230 root = cYAML_create_object(NULL, NULL);
3234 global = cYAML_create_object(root, "global");
3238 if (cYAML_create_number(global, name,
3242 if (show_rc == NULL)
3243 cYAML_print_tree(root);
3245 snprintf(err_str, err_len, "\"success\"");
3247 rc = LUSTRE_CFG_RC_NO_ERR;
3250 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3251 cYAML_free_tree(root);
3252 } else if (show_rc != NULL && *show_rc != NULL) {
3253 add_to_global(*show_rc, global, root);
3258 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3263 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3264 struct cYAML **show_rc,
3265 struct cYAML **err_rc)
3267 struct lnet_ioctl_set_value data;
3270 char err_str[LNET_MAX_STR_LEN];
3272 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3274 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3276 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3281 "\"cannot get %s: %s\"",
3282 name, strerror(l_errno));
3285 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3286 data.sv_value, show_rc, err_rc, l_errno);
3289 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3290 struct cYAML **err_rc)
3292 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3293 char val[LNET_MAX_STR_LEN];
3294 int intrv = -1, l_errno = 0;
3295 char err_str[LNET_MAX_STR_LEN];
3297 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3299 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3303 snprintf(err_str, sizeof(err_str),
3304 "\"cannot get recovery interval: %d\"", rc);
3309 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3310 "recovery_interval", intrv, show_rc,
3314 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3315 struct cYAML **err_rc)
3317 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3318 char val[LNET_MAX_STR_LEN];
3319 int sen = -1, l_errno = 0;
3320 char err_str[LNET_MAX_STR_LEN];
3322 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3324 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3328 snprintf(err_str, sizeof(err_str),
3329 "\"cannot get health sensitivity: %d\"", rc);
3334 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3335 "health_sensitivity", sen, show_rc,
3339 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3340 struct cYAML **err_rc)
3342 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3343 char val[LNET_MAX_STR_LEN];
3344 int sen = -1, l_errno = 0;
3345 char err_str[LNET_MAX_STR_LEN];
3347 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3349 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3353 snprintf(err_str, sizeof(err_str),
3354 "\"cannot get router sensitivity percentage: %d\"", rc);
3359 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3360 "router_sensitivity", sen, show_rc,
3364 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3365 struct cYAML **err_rc)
3367 char val[LNET_MAX_STR_LEN];
3368 char err_str[LNET_MAX_STR_LEN];
3375 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3377 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3380 snprintf(err_str, sizeof(err_str),
3381 "\"cannot get LND timeout: %d\"", rc);
3382 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3383 "lnd_timeout", lnd_to, show_rc,
3387 fd = open(path.gl_pathv[0], O_RDONLY);
3390 snprintf(err_str, sizeof(err_str),
3391 "\"error opening %s\"", path.gl_pathv[0]);
3395 rc = read(fd, val, sizeof(val));
3402 snprintf(err_str, sizeof(err_str),
3403 "\"error reading %s\"", path.gl_pathv[0]);
3410 cfs_free_param_data(&path);
3412 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3413 "lnd_timeout", lnd_to, show_rc,
3417 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3418 struct cYAML **err_rc)
3420 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3421 char val[LNET_MAX_STR_LEN];
3422 int tto = -1, l_errno = 0;
3423 char err_str[LNET_MAX_STR_LEN];
3425 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3427 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3431 snprintf(err_str, sizeof(err_str),
3432 "\"cannot get transaction timeout: %d\"", rc);
3437 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3438 "transaction_timeout", tto, show_rc,
3442 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3443 struct cYAML **err_rc)
3445 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3446 char val[LNET_MAX_STR_LEN];
3447 int retry_count = -1, l_errno = 0;
3448 char err_str[LNET_MAX_STR_LEN];
3450 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3452 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3456 snprintf(err_str, sizeof(err_str),
3457 "\"cannot get retry count: %d\"", rc);
3459 retry_count = atoi(val);
3462 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3463 "retry_count", retry_count, show_rc,
3467 int lustre_lnet_calc_service_id(__u64 *service_id)
3469 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3470 char val[LNET_MAX_STR_LEN];
3471 int service_port = -1, l_errno = 0;
3473 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3477 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3478 strerror(l_errno), -l_errno);
3481 service_port = atoi(val);
3484 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3486 return LUSTRE_CFG_RC_NO_ERR;
3489 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3490 struct cYAML **show_rc, struct cYAML **err_rc)
3492 struct lnet_ioctl_recovery_list nid_list;
3493 struct cYAML *root = NULL, *nids = NULL;
3495 char err_str[LNET_MAX_STR_LEN];
3497 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3499 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3500 nid_list.rlst_type = type;
3502 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3508 if (nid_list.rlst_num_nids == 0)
3511 root = cYAML_create_object(NULL, NULL);
3515 nids = cYAML_create_object(root, name);
3521 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3522 char nidenum[LNET_MAX_STR_LEN];
3523 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3524 if (!cYAML_create_string(nids, nidenum,
3525 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3529 snprintf(err_str, sizeof(err_str), "success\n");
3534 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3535 cYAML_free_tree(root);
3536 } else if (show_rc != NULL && *show_rc != NULL) {
3537 struct cYAML *show_node;
3538 /* find the net node, if one doesn't exist
3539 * then insert one. Otherwise add to the one there
3541 show_node = cYAML_get_object_item(*show_rc, name);
3542 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3543 cYAML_insert_child(show_node, nids);
3546 } else if (show_node == NULL) {
3547 cYAML_insert_sibling((*show_rc)->cy_child,
3551 cYAML_free_tree(root);
3557 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3562 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3563 struct cYAML **err_rc)
3565 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3566 seq_no, show_rc, err_rc);
3569 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3570 struct cYAML **err_rc)
3572 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3573 seq_no, show_rc, err_rc);
3576 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3577 struct cYAML **err_rc)
3579 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3580 char val[LNET_MAX_STR_LEN];
3581 int max_intf = -1, l_errno = 0;
3582 char err_str[LNET_MAX_STR_LEN];
3584 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3586 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3590 snprintf(err_str, sizeof(err_str),
3591 "\"cannot get max interfaces: %d\"", rc);
3593 max_intf = atoi(val);
3596 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3597 "max_intf", max_intf, show_rc,
3601 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3602 struct cYAML **err_rc)
3604 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3605 char val[LNET_MAX_STR_LEN];
3606 int discovery = -1, l_errno = 0;
3607 char err_str[LNET_MAX_STR_LEN];
3609 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3611 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3615 snprintf(err_str, sizeof(err_str),
3616 "\"cannot get discovery setting: %d\"", rc);
3619 * The kernel stores a discovery disabled value. User space
3620 * shows whether discovery is enabled. So the value must be
3623 discovery = !atoi(val);
3626 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3627 "discovery", discovery, show_rc,
3631 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3632 struct cYAML **err_rc)
3634 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3635 char val[LNET_MAX_STR_LEN];
3636 int drop_asym_route = -1, l_errno = 0;
3637 char err_str[LNET_MAX_STR_LEN];
3639 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3641 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3645 snprintf(err_str, sizeof(err_str),
3646 "\"cannot get drop asym route setting: %d\"", rc);
3648 drop_asym_route = atoi(val);
3651 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3652 "drop_asym_route", drop_asym_route,
3653 show_rc, err_rc, l_errno);
3656 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3657 struct cYAML **err_rc)
3659 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3660 "numa_range", show_rc, err_rc);
3663 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3664 struct cYAML **err_rc)
3666 struct lnet_ioctl_lnet_stats data;
3667 struct lnet_counters *cntrs;
3670 char err_str[LNET_MAX_STR_LEN];
3671 struct cYAML *root = NULL, *stats = NULL;
3673 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3675 LIBCFS_IOC_INIT_V2(data, st_hdr);
3677 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3682 "\"cannot get lnet statistics: %s\"",
3688 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3690 cntrs = &data.st_cntrs;
3692 root = cYAML_create_object(NULL, NULL);
3696 stats = cYAML_create_object(root, "statistics");
3700 if (!cYAML_create_number(stats, "msgs_alloc",
3701 cntrs->lct_common.lcc_msgs_alloc))
3704 if (!cYAML_create_number(stats, "msgs_max",
3705 cntrs->lct_common.lcc_msgs_max))
3708 if (!cYAML_create_number(stats, "rst_alloc",
3709 cntrs->lct_health.lch_rst_alloc))
3712 if (!cYAML_create_number(stats, "errors",
3713 cntrs->lct_common.lcc_errors))
3716 if (!cYAML_create_number(stats, "send_count",
3717 cntrs->lct_common.lcc_send_count))
3720 if (!cYAML_create_number(stats, "resend_count",
3721 cntrs->lct_health.lch_resend_count))
3724 if (!cYAML_create_number(stats, "response_timeout_count",
3725 cntrs->lct_health.lch_response_timeout_count))
3728 if (!cYAML_create_number(stats, "local_interrupt_count",
3729 cntrs->lct_health.lch_local_interrupt_count))
3732 if (!cYAML_create_number(stats, "local_dropped_count",
3733 cntrs->lct_health.lch_local_dropped_count))
3736 if (!cYAML_create_number(stats, "local_aborted_count",
3737 cntrs->lct_health.lch_local_aborted_count))
3740 if (!cYAML_create_number(stats, "local_no_route_count",
3741 cntrs->lct_health.lch_local_no_route_count))
3744 if (!cYAML_create_number(stats, "local_timeout_count",
3745 cntrs->lct_health.lch_local_timeout_count))
3748 if (!cYAML_create_number(stats, "local_error_count",
3749 cntrs->lct_health.lch_local_error_count))
3752 if (!cYAML_create_number(stats, "remote_dropped_count",
3753 cntrs->lct_health.lch_remote_dropped_count))
3756 if (!cYAML_create_number(stats, "remote_error_count",
3757 cntrs->lct_health.lch_remote_error_count))
3760 if (!cYAML_create_number(stats, "remote_timeout_count",
3761 cntrs->lct_health.lch_remote_timeout_count))
3764 if (!cYAML_create_number(stats, "network_timeout_count",
3765 cntrs->lct_health.lch_network_timeout_count))
3768 if (!cYAML_create_number(stats, "recv_count",
3769 cntrs->lct_common.lcc_recv_count))
3772 if (!cYAML_create_number(stats, "route_count",
3773 cntrs->lct_common.lcc_route_count))
3776 if (!cYAML_create_number(stats, "drop_count",
3777 cntrs->lct_common.lcc_drop_count))
3780 if (!cYAML_create_number(stats, "send_length",
3781 cntrs->lct_common.lcc_send_length))
3784 if (!cYAML_create_number(stats, "recv_length",
3785 cntrs->lct_common.lcc_recv_length))
3788 if (!cYAML_create_number(stats, "route_length",
3789 cntrs->lct_common.lcc_route_length))
3792 if (!cYAML_create_number(stats, "drop_length",
3793 cntrs->lct_common.lcc_drop_length))
3797 cYAML_print_tree(root);
3799 snprintf(err_str, sizeof(err_str), "\"success\"");
3800 rc = LUSTRE_CFG_RC_NO_ERR;
3802 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3803 cYAML_free_tree(root);
3804 } else if (show_rc != NULL && *show_rc != NULL) {
3805 cYAML_insert_sibling((*show_rc)->cy_child,
3812 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3817 typedef int (*cmd_handler_t)(struct cYAML *tree,
3818 struct cYAML **show_rc,
3819 struct cYAML **err_rc);
3821 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3822 struct cYAML **err_rc)
3824 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3826 net = cYAML_get_object_item(tree, "net");
3827 gw = cYAML_get_object_item(tree, "gateway");
3828 hop = cYAML_get_object_item(tree, "hop");
3829 prio = cYAML_get_object_item(tree, "priority");
3830 sen = cYAML_get_object_item(tree, "health_sensitivity");
3831 seq_no = cYAML_get_object_item(tree, "seq_no");
3833 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3834 (gw) ? gw->cy_valuestring : NULL,
3835 (hop) ? hop->cy_valueint : -1,
3836 (prio) ? prio->cy_valueint : -1,
3837 (sen) ? sen->cy_valueint : -1,
3838 (seq_no) ? seq_no->cy_valueint : -1,
3844 * 0: <intf_name>['['<expr>']']
3845 * 1: <intf_name>['['<expr>']']
3847 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3848 struct lnet_dlc_network_descr *nw_descr)
3850 struct cYAML *child = NULL;
3851 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3852 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3854 if (intf_tree == NULL || nw_descr == NULL)
3855 return LUSTRE_CFG_RC_BAD_PARAM;
3857 /* now grab all the interfaces and their cpts */
3858 child = intf_tree->cy_child;
3859 while (child != NULL) {
3860 if (child->cy_valuestring == NULL) {
3861 child = child->cy_next;
3865 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3868 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3869 child->cy_valuestring,
3870 strlen(child->cy_valuestring));
3871 if (rc != LUSTRE_CFG_RC_NO_ERR)
3875 child = child->cy_next;
3879 return LUSTRE_CFG_RC_MISSING_PARAM;
3884 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3886 list_del(&intf_descr->intf_on_network);
3887 free_intf_descr(intf_descr);
3894 yaml_extract_cmn_tunables(struct cYAML *tree,
3895 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3896 struct cfs_expr_list **global_cpts)
3898 struct cYAML *tun, *item, *smp;
3901 tun = cYAML_get_object_item(tree, "tunables");
3903 item = cYAML_get_object_item(tun, "peer_timeout");
3905 tunables->lct_peer_timeout = item->cy_valueint;
3906 item = cYAML_get_object_item(tun, "peer_credits");
3908 tunables->lct_peer_tx_credits = item->cy_valueint;
3909 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3911 tunables->lct_peer_rtr_credits = item->cy_valueint;
3912 item = cYAML_get_object_item(tun, "credits");
3914 tunables->lct_max_tx_credits = item->cy_valueint;
3915 smp = cYAML_get_object_item(tun, "CPT");
3917 rc = cfs_expr_list_parse(smp->cy_valuestring,
3918 strlen(smp->cy_valuestring),
3919 0, UINT_MAX, global_cpts);
3921 *global_cpts = NULL;
3931 yaml_extract_tunables(struct cYAML *tree,
3932 struct lnet_ioctl_config_lnd_tunables *tunables,
3933 struct cfs_expr_list **global_cpts,
3938 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3944 lustre_yaml_extract_lnd_tunables(tree, net_type,
3952 * - net type: <net>[<NUM>]
3954 * - nid: <ip>@<net>[<NUM>]
3957 * 0: <intf_name>['['<expr>']']
3958 * 1: <intf_name>['['<expr>']']
3960 * peer_timeout: <NUM>
3961 * peer_credits: <NUM>
3962 * peer_buffer_credits: <NUM>
3965 * peercredits_hiw: <NUM>
3966 * map_on_demand: <NUM>
3967 * concurrent_sends: <NUM>
3968 * fmr_pool_size: <NUM>
3969 * fmr_flush_trigger: <NUM>
3972 * At least one interface is required. If no interfaces are provided the
3973 * network interface can not be configured.
3975 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3976 struct cYAML **err_rc)
3978 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3980 int num_entries = 0, rc;
3981 struct lnet_dlc_network_descr nw_descr;
3982 struct cfs_expr_list *global_cpts = NULL;
3983 struct lnet_ioctl_config_lnd_tunables tunables;
3986 memset(&tunables, 0, sizeof(tunables));
3988 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3989 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3991 ip2net = cYAML_get_object_item(tree, "ip2net");
3992 net = cYAML_get_object_item(tree, "net type");
3994 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3996 nw_descr.nw_id = LOLND;
3999 * if neither net nor ip2nets are present, then we can not
4000 * configure the network.
4002 if (!net && !ip2net)
4003 return LUSTRE_CFG_RC_MISSING_PARAM;
4005 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4006 if (local_nis == NULL)
4007 return LUSTRE_CFG_RC_MISSING_PARAM;
4009 if (!cYAML_is_sequence(local_nis))
4010 return LUSTRE_CFG_RC_BAD_PARAM;
4012 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4013 intf = cYAML_get_object_item(item, "interfaces");
4016 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4017 if (num_entries <= 0) {
4018 cYAML_build_error(num_entries, -1, "ni", "add",
4019 "bad interface list",
4021 return LUSTRE_CFG_RC_BAD_PARAM;
4025 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4026 LNET_NETTYP(nw_descr.nw_id));
4027 seq_no = cYAML_get_object_item(tree, "seq_no");
4029 rc = lustre_lnet_config_ni(&nw_descr,
4031 (ip2net) ? ip2net->cy_valuestring : NULL,
4032 (found) ? &tunables: NULL,
4033 (seq_no) ? seq_no->cy_valueint : -1,
4036 if (global_cpts != NULL)
4037 cfs_expr_list_free(global_cpts);
4044 * - net-spec: <tcp|o2ib|gni>[NUM]
4046 * 0: <intf name>['['<expr>']']
4047 * 1: <intf name>['['<expr>']']
4049 * 0: <expr.expr.expr.expr>
4050 * 1: <expr.expr.expr.expr>
4052 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4053 struct cYAML **show_rc,
4054 struct cYAML **err_rc)
4056 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4058 struct lustre_lnet_ip2nets ip2nets;
4059 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4061 int rc = LUSTRE_CFG_RC_NO_ERR;
4062 struct cfs_expr_list *global_cpts = NULL;
4063 struct cfs_expr_list *el, *el_tmp;
4064 struct lnet_ioctl_config_lnd_tunables tunables;
4065 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4068 memset(&tunables, 0, sizeof(tunables));
4070 /* initialize all lists */
4071 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4072 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4073 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4075 net = cYAML_get_object_item(tree, "net-spec");
4077 return LUSTRE_CFG_RC_BAD_PARAM;
4079 if (net != NULL && net->cy_valuestring == NULL)
4080 return LUSTRE_CFG_RC_BAD_PARAM;
4082 /* assign the network id */
4083 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4084 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4085 return LUSTRE_CFG_RC_BAD_PARAM;
4087 seq_no = cYAML_get_object_item(tree, "seq_no");
4089 intf = cYAML_get_object_item(tree, "interfaces");
4091 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4093 return LUSTRE_CFG_RC_BAD_PARAM;
4096 ip_range = cYAML_get_object_item(tree, "ip-range");
4097 if (ip_range != NULL) {
4098 item = ip_range->cy_child;
4099 while (item != NULL) {
4100 if (item->cy_valuestring == NULL) {
4101 item = item->cy_next;
4105 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4106 item->cy_valuestring);
4108 if (rc != LUSTRE_CFG_RC_NO_ERR)
4111 item = item->cy_next;
4115 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4116 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4118 rc = lustre_lnet_config_ip2nets(&ip2nets,
4119 (found) ? &tunables : NULL,
4121 (seq_no) ? seq_no->cy_valueint : -1,
4125 * don't stop because there was no match. Continue processing the
4126 * rest of the rules. If non-match then nothing is configured
4128 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4129 rc = LUSTRE_CFG_RC_NO_ERR;
4131 list_for_each_entry_safe(intf_descr, intf_tmp,
4132 &ip2nets.ip2nets_net.nw_intflist,
4134 list_del(&intf_descr->intf_on_network);
4135 free_intf_descr(intf_descr);
4138 list_for_each_entry_safe(ip_range_descr, tmp,
4139 &ip2nets.ip2nets_ip_ranges,
4141 list_del(&ip_range_descr->ipr_entry);
4142 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4144 list_del(&el->el_link);
4145 cfs_expr_list_free(el);
4147 free(ip_range_descr);
4153 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4154 struct cYAML **err_rc)
4156 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4158 int num_entries, rc;
4159 struct lnet_dlc_network_descr nw_descr;
4161 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4162 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4164 net = cYAML_get_object_item(tree, "net type");
4166 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4168 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4169 if (local_nis == NULL)
4170 return LUSTRE_CFG_RC_MISSING_PARAM;
4172 if (!cYAML_is_sequence(local_nis))
4173 return LUSTRE_CFG_RC_BAD_PARAM;
4175 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4176 intf = cYAML_get_object_item(item, "interfaces");
4179 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4180 if (num_entries <= 0) {
4181 cYAML_build_error(num_entries, -1, "ni", "add",
4182 "bad interface list",
4184 return LUSTRE_CFG_RC_BAD_PARAM;
4188 seq_no = cYAML_get_object_item(tree, "seq_no");
4190 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4191 (seq_no) ? seq_no->cy_valueint : -1,
4197 /* Create a nidstring parseable by the nidstrings library from the nid
4198 * information encoded in the CYAML structure.
4199 * NOTE: Caller must free memory allocated to nidstr
4201 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4202 char *prim_nid, int cmd)
4204 int num_strs = 0, rc;
4205 size_t buf_size, buf_pos, nidstr_len = 0;
4207 struct cYAML *child = NULL, *entry = NULL;
4209 if (cYAML_is_sequence(nids_entry)) {
4210 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4211 entry = cYAML_get_object_item(child, "nid");
4212 /* don't count an empty entry */
4213 if (!entry || !entry->cy_valuestring)
4217 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4218 if (cmd == LNETCTL_DEL_CMD) {
4220 * primary nid is present in the list of
4221 * nids so that means we want to delete
4222 * the entire peer, so no need to go
4223 * further. Just delete the entire peer.
4225 return LUSTRE_CFG_RC_NO_ERR;
4232 * + 1 for the space separating each string, and
4233 * accounts for the terminating null char
4235 nidstr_len += strlen(entry->cy_valuestring) + 1;
4240 if (num_strs == 0 && !prim_nid)
4241 return LUSTRE_CFG_RC_MISSING_PARAM;
4242 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4243 return LUSTRE_CFG_RC_NO_ERR;
4245 buffer = malloc(nidstr_len);
4247 return LUSTRE_CFG_RC_OUT_OF_MEM;
4249 /* now grab all the nids */
4252 buf_size = nidstr_len;
4254 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4255 entry = cYAML_get_object_item(child, "nid");
4256 if (!entry || !entry->cy_valuestring)
4260 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4264 rc = snprintf(buffer + buf_pos, buf_size, " ");
4265 buf_pos += (rc < buf_size) ? rc : buf_size;
4266 buf_size = nidstr_len - buf_pos;
4269 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4270 entry->cy_valuestring);
4271 buf_pos += (rc < buf_size) ? rc : buf_size;
4272 buf_size = nidstr_len - buf_pos;
4277 return LUSTRE_CFG_RC_NO_ERR;
4280 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4281 struct cYAML **err_rc, int cmd)
4283 int rc, num_nids = 0, seqn;
4285 char *nidstr = NULL, *prim_nidstr;
4286 char err_str[LNET_MAX_STR_LEN];
4287 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4288 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4290 seq_no = cYAML_get_object_item(tree, "seq_no");
4291 seqn = seq_no ? seq_no->cy_valueint : -1;
4293 prim_nid = cYAML_get_object_item(tree, "primary nid");
4294 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4296 peer_nis = cYAML_get_object_item(tree, "peer ni");
4297 if (!(prim_nid || peer_nis)) {
4298 rc = LUSTRE_CFG_RC_BAD_PARAM;
4299 snprintf(err_str, LNET_MAX_STR_LEN,
4300 "Neither \"primary nid\" nor \"peer ni\" are defined");
4304 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4305 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4306 snprintf(err_str, LNET_MAX_STR_LEN,
4307 "No nids defined in YAML block");
4309 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4310 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4312 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4313 snprintf(err_str, LNET_MAX_STR_LEN,
4314 "Unrecognized error %d", rc);
4320 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4321 LNET_MAX_NIDS_PER_PEER,
4329 if (cmd == LNETCTL_ADD_CMD) {
4330 mr = cYAML_get_object_item(tree, "Multi-Rail");
4332 if (mr && mr->cy_valuestring) {
4333 if (strcmp(mr->cy_valuestring, "False") == 0)
4335 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4336 rc = LUSTRE_CFG_RC_BAD_PARAM;
4337 snprintf(err_str, LNET_MAX_STR_LEN,
4338 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4339 mr->cy_valuestring);
4344 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4345 num_nids, mr_value, seqn,
4348 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4349 num_nids, seqn, err_rc);
4355 if (rc != LUSTRE_CFG_RC_NO_ERR)
4356 cYAML_build_error(rc, seqn, "peer",
4357 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4363 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4364 struct cYAML **err_rc)
4366 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4369 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4370 struct cYAML **err_rc)
4372 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4375 static int handle_yaml_config_buffers(struct cYAML *tree,
4376 struct cYAML **show_rc,
4377 struct cYAML **err_rc)
4380 struct cYAML *tiny, *small, *large, *seq_no;
4382 tiny = cYAML_get_object_item(tree, "tiny");
4383 small = cYAML_get_object_item(tree, "small");
4384 large = cYAML_get_object_item(tree, "large");
4385 seq_no = cYAML_get_object_item(tree, "seq_no");
4387 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4388 (small) ? small->cy_valueint : -1,
4389 (large) ? large->cy_valueint : -1,
4390 (seq_no) ? seq_no->cy_valueint : -1,
4396 static int handle_yaml_config_routing(struct cYAML *tree,
4397 struct cYAML **show_rc,
4398 struct cYAML **err_rc)
4400 int rc = LUSTRE_CFG_RC_NO_ERR;
4401 struct cYAML *seq_no, *enable;
4403 seq_no = cYAML_get_object_item(tree, "seq_no");
4404 enable = cYAML_get_object_item(tree, "enable");
4407 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4409 seq_no->cy_valueint : -1,
4416 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4417 struct cYAML **err_rc)
4421 struct cYAML *seq_no;
4423 net = cYAML_get_object_item(tree, "net");
4424 gw = cYAML_get_object_item(tree, "gateway");
4425 seq_no = cYAML_get_object_item(tree, "seq_no");
4427 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4428 (gw) ? gw->cy_valuestring : NULL,
4429 (seq_no) ? seq_no->cy_valueint : -1,
4433 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4434 struct cYAML **err_rc)
4436 struct cYAML *seq_no;
4438 seq_no = cYAML_get_object_item(tree, "seq_no");
4440 return lustre_lnet_enable_routing(0, (seq_no) ?
4441 seq_no->cy_valueint : -1,
4445 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4446 struct cYAML **err_rc)
4452 struct cYAML *detail;
4453 struct cYAML *seq_no;
4455 net = cYAML_get_object_item(tree, "net");
4456 gw = cYAML_get_object_item(tree, "gateway");
4457 hop = cYAML_get_object_item(tree, "hop");
4458 prio = cYAML_get_object_item(tree, "priority");
4459 detail = cYAML_get_object_item(tree, "detail");
4460 seq_no = cYAML_get_object_item(tree, "seq_no");
4462 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4463 (gw) ? gw->cy_valuestring : NULL,
4464 (hop) ? hop->cy_valueint : -1,
4465 (prio) ? prio->cy_valueint : -1,
4466 (detail) ? detail->cy_valueint : 0,
4467 (seq_no) ? seq_no->cy_valueint : -1,
4468 show_rc, err_rc, false);
4471 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4472 struct cYAML **err_rc)
4474 struct cYAML *net, *detail, *seq_no;
4476 net = cYAML_get_object_item(tree, "net");
4477 detail = cYAML_get_object_item(tree, "detail");
4478 seq_no = cYAML_get_object_item(tree, "seq_no");
4480 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4481 (detail) ? detail->cy_valueint : 0,
4482 (seq_no) ? seq_no->cy_valueint : -1,
4483 show_rc, err_rc, false);
4486 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4487 struct cYAML **err_rc)
4489 struct cYAML *seq_no;
4491 seq_no = cYAML_get_object_item(tree, "seq_no");
4493 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4494 show_rc, err_rc, false);
4497 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4498 struct cYAML **err_rc)
4500 struct cYAML *seq_no, *nid, *detail;
4502 seq_no = cYAML_get_object_item(tree, "seq_no");
4503 detail = cYAML_get_object_item(tree, "detail");
4504 nid = cYAML_get_object_item(tree, "nid");
4506 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4507 (detail) ? detail->cy_valueint : 0,
4508 (seq_no) ? seq_no->cy_valueint : -1,
4509 show_rc, err_rc, false);
4512 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4513 struct cYAML **err_rc)
4515 struct cYAML *seq_no;
4517 seq_no = cYAML_get_object_item(tree, "seq_no");
4519 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4523 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4524 struct cYAML **err_rc)
4526 struct cYAML *seq_no, *range;
4528 seq_no = cYAML_get_object_item(tree, "seq_no");
4529 range = cYAML_get_object_item(tree, "range");
4531 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4532 seq_no ? seq_no->cy_valueint : -1,
4536 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4537 struct cYAML **err_rc)
4539 struct cYAML *seq_no;
4541 seq_no = cYAML_get_object_item(tree, "seq_no");
4543 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4547 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4548 struct cYAML **err_rc)
4550 struct cYAML *seq_no;
4552 seq_no = cYAML_get_object_item(tree, "seq_no");
4554 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4558 static int handle_yaml_config_global_settings(struct cYAML *tree,
4559 struct cYAML **show_rc,
4560 struct cYAML **err_rc)
4562 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4563 *sen, *recov, *rsen, *drop_asym_route;
4566 seq_no = cYAML_get_object_item(tree, "seq_no");
4567 max_intf = cYAML_get_object_item(tree, "max_intf");
4569 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4570 seq_no ? seq_no->cy_valueint
4574 numa = cYAML_get_object_item(tree, "numa_range");
4576 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4577 seq_no ? seq_no->cy_valueint
4581 discovery = cYAML_get_object_item(tree, "discovery");
4583 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4584 seq_no ? seq_no->cy_valueint
4588 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4589 if (drop_asym_route)
4590 rc = lustre_lnet_config_drop_asym_route(
4591 drop_asym_route->cy_valueint,
4592 seq_no ? seq_no->cy_valueint : -1,
4595 retry = cYAML_get_object_item(tree, "retry_count");
4597 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4598 seq_no ? seq_no->cy_valueint
4602 tto = cYAML_get_object_item(tree, "transaction_timeout");
4604 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4605 seq_no ? seq_no->cy_valueint
4609 sen = cYAML_get_object_item(tree, "health_sensitivity");
4611 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4612 seq_no ? seq_no->cy_valueint
4616 recov = cYAML_get_object_item(tree, "recovery_interval");
4618 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4619 seq_no ? seq_no->cy_valueint
4623 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4625 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4626 seq_no ? seq_no->cy_valueint
4633 static int handle_yaml_del_global_settings(struct cYAML *tree,
4634 struct cYAML **show_rc,
4635 struct cYAML **err_rc)
4637 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4640 seq_no = cYAML_get_object_item(tree, "seq_no");
4641 max_intf = cYAML_get_object_item(tree, "max_intf");
4643 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4644 seq_no ? seq_no->cy_valueint
4648 numa = cYAML_get_object_item(tree, "numa_range");
4650 rc = lustre_lnet_config_numa_range(0,
4651 seq_no ? seq_no->cy_valueint
4655 /* peer discovery is enabled by default */
4656 discovery = cYAML_get_object_item(tree, "discovery");
4658 rc = lustre_lnet_config_discovery(1,
4659 seq_no ? seq_no->cy_valueint
4663 /* asymmetrical route messages are accepted by default */
4664 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4665 if (drop_asym_route)
4666 rc = lustre_lnet_config_drop_asym_route(
4667 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4672 static int handle_yaml_show_global_settings(struct cYAML *tree,
4673 struct cYAML **show_rc,
4674 struct cYAML **err_rc)
4676 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4677 *sen, *recov, *rsen, *drop_asym_route;
4680 seq_no = cYAML_get_object_item(tree, "seq_no");
4681 max_intf = cYAML_get_object_item(tree, "max_intf");
4683 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4687 numa = cYAML_get_object_item(tree, "numa_range");
4689 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4693 discovery = cYAML_get_object_item(tree, "discovery");
4695 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4699 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4700 if (drop_asym_route)
4701 rc = lustre_lnet_show_drop_asym_route(
4702 seq_no ? seq_no->cy_valueint : -1,
4705 retry = cYAML_get_object_item(tree, "retry_count");
4707 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4711 tto = cYAML_get_object_item(tree, "transaction_timeout");
4713 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4717 sen = cYAML_get_object_item(tree, "health_sensitivity");
4719 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4723 recov = cYAML_get_object_item(tree, "recovery_interval");
4725 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4729 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4731 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4738 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4739 struct cYAML **err_rc)
4741 struct cYAML *seq_no, *nid, *timeout;
4743 seq_no = cYAML_get_object_item(tree, "seq_no");
4744 nid = cYAML_get_object_item(tree, "primary nid");
4745 timeout = cYAML_get_object_item(tree, "timeout");
4747 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4748 (timeout) ? timeout->cy_valueint : 1000,
4749 (seq_no) ? seq_no->cy_valueint : -1,
4753 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4754 struct cYAML **err_rc)
4756 struct cYAML *seq_no, *nid, *force;
4758 seq_no = cYAML_get_object_item(tree, "seq_no");
4759 nid = cYAML_get_object_item(tree, "primary nid");
4760 force = cYAML_get_object_item(tree, "force");
4762 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4763 (force) ? force->cy_valueint : 0,
4764 (seq_no) ? seq_no->cy_valueint : -1,
4768 static int handle_yaml_no_op()
4770 return LUSTRE_CFG_RC_NO_ERR;
4773 struct lookup_cmd_hdlr_tbl {
4778 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4779 { .name = "route", .cb = handle_yaml_config_route },
4780 { .name = "net", .cb = handle_yaml_config_ni },
4781 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4782 { .name = "peer", .cb = handle_yaml_config_peer },
4783 { .name = "routing", .cb = handle_yaml_config_routing },
4784 { .name = "buffers", .cb = handle_yaml_config_buffers },
4785 { .name = "statistics", .cb = handle_yaml_no_op },
4786 { .name = "global", .cb = handle_yaml_config_global_settings},
4787 { .name = "numa", .cb = handle_yaml_config_numa },
4788 { .name = "ping", .cb = handle_yaml_no_op },
4789 { .name = "discover", .cb = handle_yaml_no_op },
4792 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4793 { .name = "route", .cb = handle_yaml_del_route },
4794 { .name = "net", .cb = handle_yaml_del_ni },
4795 { .name = "ip2nets", .cb = handle_yaml_no_op },
4796 { .name = "peer", .cb = handle_yaml_del_peer },
4797 { .name = "routing", .cb = handle_yaml_del_routing },
4798 { .name = "buffers", .cb = handle_yaml_no_op },
4799 { .name = "statistics", .cb = handle_yaml_no_op },
4800 { .name = "global", .cb = handle_yaml_del_global_settings},
4801 { .name = "numa", .cb = handle_yaml_del_numa },
4802 { .name = "ping", .cb = handle_yaml_no_op },
4803 { .name = "discover", .cb = handle_yaml_no_op },
4806 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4807 { .name = "route", .cb = handle_yaml_show_route },
4808 { .name = "net", .cb = handle_yaml_show_net },
4809 { .name = "peer", .cb = handle_yaml_show_peers },
4810 { .name = "ip2nets", .cb = handle_yaml_no_op },
4811 { .name = "routing", .cb = handle_yaml_show_routing },
4812 { .name = "buffers", .cb = handle_yaml_show_routing },
4813 { .name = "statistics", .cb = handle_yaml_show_stats },
4814 { .name = "global", .cb = handle_yaml_show_global_settings},
4815 { .name = "numa", .cb = handle_yaml_show_numa },
4816 { .name = "ping", .cb = handle_yaml_no_op },
4817 { .name = "discover", .cb = handle_yaml_no_op },
4820 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4821 { .name = "route", .cb = handle_yaml_no_op },
4822 { .name = "net", .cb = handle_yaml_no_op },
4823 { .name = "peer", .cb = handle_yaml_no_op },
4824 { .name = "ip2nets", .cb = handle_yaml_no_op },
4825 { .name = "routing", .cb = handle_yaml_no_op },
4826 { .name = "buffers", .cb = handle_yaml_no_op },
4827 { .name = "statistics", .cb = handle_yaml_no_op },
4828 { .name = "global", .cb = handle_yaml_no_op },
4829 { .name = "numa", .cb = handle_yaml_no_op },
4830 { .name = "ping", .cb = handle_yaml_ping },
4831 { .name = "discover", .cb = handle_yaml_discover },
4834 static cmd_handler_t lookup_fn(char *key,
4835 struct lookup_cmd_hdlr_tbl *tbl)
4841 for (i = 0; tbl[i].name != NULL; i++) {
4842 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4849 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4850 struct cYAML **show_rc, struct cYAML **err_rc)
4852 struct cYAML *tree, *item = NULL, *head, *child;
4854 char err_str[LNET_MAX_STR_LEN];
4855 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4857 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4859 return LUSTRE_CFG_RC_BAD_PARAM;
4861 child = tree->cy_child;
4862 while (child != NULL) {
4863 cb = lookup_fn(child->cy_string, table);
4865 snprintf(err_str, sizeof(err_str),
4866 "\"call back for '%s' not found\"",
4868 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4869 "yaml", "helper", err_str, err_rc);
4873 if (cYAML_is_sequence(child)) {
4874 while ((head = cYAML_get_next_seq_item(child, &item))
4876 rc = cb(head, show_rc, err_rc);
4877 if (rc != LUSTRE_CFG_RC_NO_ERR)
4881 rc = cb(child, show_rc, err_rc);
4882 if (rc != LUSTRE_CFG_RC_NO_ERR)
4886 child = child->cy_next;
4890 cYAML_free_tree(tree);
4895 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4897 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4901 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4903 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4907 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4909 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4913 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4915 return lustre_yaml_cb_helper(f, lookup_exec_tbl,