4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #define CONFIG_CMD "configure"
57 #define UNCONFIG_CMD "unconfigure"
60 #define SHOW_CMD "show"
62 #define MANAGE_CMD "manage"
64 #define MAX_NUM_IPS 128
66 #define modparam_path "/sys/module/lnet/parameters/"
67 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
68 #define gni_nid_path "/proc/cray_xt/"
70 #ifndef HAVE_USRSPC_RDMA_PS_TCP
71 #define RDMA_PS_TCP 0x0106
74 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
78 * lustre_lnet_ip_range_descr
79 * Describes an IP range.
80 * Each octect is an expression
82 struct lustre_lnet_ip_range_descr {
83 struct list_head ipr_entry;
84 struct list_head ipr_expr;
89 * Describes an ip2nets rule. This can be on a list of rules.
91 struct lustre_lnet_ip2nets {
92 struct lnet_dlc_network_descr ip2nets_net;
93 struct list_head ip2nets_ip_ranges;
96 int open_sysfs_file(const char *path, const char *attr, const int mode)
99 char filename[LNET_MAX_STR_LEN];
101 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
104 snprintf(filename, sizeof(filename), "%s%s",
107 fd = open(filename, mode);
112 static int read_sysfs_file(const char *path, const char *attr,
113 void *val, const size_t size, const int nelem)
116 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
118 fd = open_sysfs_file(path, attr, O_RDONLY);
120 return LUSTRE_CFG_RC_NO_MATCH;
122 if (read(fd, val, size * nelem) == -1)
125 rc = LUSTRE_CFG_RC_NO_ERR;
132 static int write_sysfs_file(const char *path, const char *attr,
133 void *val, const size_t size, const int nelem)
136 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
138 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
140 return LUSTRE_CFG_RC_NO_MATCH;
142 if (write(fd, val, size * nelem) == -1)
145 rc = LUSTRE_CFG_RC_NO_ERR;
154 * frees the memory allocated for an intf descriptor.
156 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
161 if (intf_descr->cpt_expr != NULL)
162 cfs_expr_list_free(intf_descr->cpt_expr);
167 * lustre_lnet_add_ip_range
169 * given a string of the format:
170 * <expr.expr.expr.expr> parse each expr into
171 * a lustre_lnet_ip_range_descr structure and insert on the list.
173 * This function is called from
174 * YAML on each ip-range.
175 * As a result of lnetctl command
176 * When building a NID or P2P selection rules
178 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
180 struct lustre_lnet_ip_range_descr *ip_range;
183 ip_range = calloc(1, sizeof(*ip_range));
184 if (ip_range == NULL)
185 return LUSTRE_CFG_RC_OUT_OF_MEM;
187 INIT_LIST_HEAD(&ip_range->ipr_entry);
188 INIT_LIST_HEAD(&ip_range->ipr_expr);
190 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
191 &ip_range->ipr_expr);
193 return LUSTRE_CFG_RC_BAD_PARAM;
195 list_add_tail(&ip_range->ipr_entry, list);
197 return LUSTRE_CFG_RC_NO_ERR;
200 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
202 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
204 struct lnet_dlc_intf_descr *intf_descr = NULL;
206 char intf_string[LNET_MAX_STR_LEN];
208 if (len >= LNET_MAX_STR_LEN)
209 return LUSTRE_CFG_RC_BAD_PARAM;
211 strncpy(intf_string, intf, len);
212 intf_string[len] = '\0';
214 intf_descr = calloc(1, sizeof(*intf_descr));
215 if (intf_descr == NULL)
216 return LUSTRE_CFG_RC_OUT_OF_MEM;
218 INIT_LIST_HEAD(&intf_descr->intf_on_network);
220 intf_name = intf_string;
221 open_sq_bracket = strchr(intf_string, '[');
222 if (open_sq_bracket != NULL) {
223 close_sq_bracket = strchr(intf_string, ']');
224 if (close_sq_bracket == NULL) {
226 return LUSTRE_CFG_RC_BAD_PARAM;
228 rc = cfs_expr_list_parse(open_sq_bracket,
229 strlen(open_sq_bracket), 0, UINT_MAX,
230 &intf_descr->cpt_expr);
233 return LUSTRE_CFG_RC_BAD_PARAM;
235 strncpy(intf_descr->intf_name, intf_name,
236 open_sq_bracket - intf_name);
237 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
239 strcpy(intf_descr->intf_name, intf_name);
240 intf_descr->cpt_expr = NULL;
243 list_add_tail(&intf_descr->intf_on_network, list);
245 return LUSTRE_CFG_RC_NO_ERR;
248 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
250 if (nw_descr != NULL) {
252 INIT_LIST_HEAD(&nw_descr->network_on_rule);
253 INIT_LIST_HEAD(&nw_descr->nw_intflist);
257 int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
259 int bracket = 0, num_str = 0;
260 char *strstart, *chptr;
263 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
264 return LUSTRE_CFG_RC_BAD_PARAM;
267 /* comma-separated nidranges -> space-separated nidranges */
271 if (*chptr == '\0') {
272 out[num_str] = strstart;
279 else if (*chptr == ']')
283 snprintf(err_str, LNET_MAX_STR_LEN,
284 "Mismatched brackets in nidstring \"%s\"",
286 return LUSTRE_CFG_RC_BAD_PARAM;
289 if (bracket == 0 && *chptr == ',') {
290 out[num_str] = strstart;
293 strstart = chptr + 1;
300 snprintf(err_str, LNET_MAX_STR_LEN,
301 "Mismatched brackets in nidstring \"%s\"", nidstr);
302 return LUSTRE_CFG_RC_BAD_PARAM;
308 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
309 int max_nids, char *err_str)
311 int rc, num_nids = 0;
312 struct list_head nidlist;
315 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
316 return LUSTRE_CFG_RC_BAD_PARAM;
319 if (strchr(nidstr, '*')) {
320 snprintf(err_str, LNET_MAX_STR_LEN,
321 "asterisk not allowed in nidstring \"%s\"", nidstr);
322 return LUSTRE_CFG_RC_BAD_PARAM;
325 INIT_LIST_HEAD(&nidlist);
326 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
328 snprintf(err_str, LNET_MAX_STR_LEN,
329 "Unable to parse nidlist from: %s\n", nidstr);
330 return LUSTRE_CFG_RC_BAD_PARAM;
333 if (list_empty(&nidlist)) {
334 snprintf(err_str, LNET_MAX_STR_LEN,
335 "\"%s\" does not specify any valid nid lists", nidstr);
336 return LUSTRE_CFG_RC_BAD_PARAM;
339 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
341 if (num_nids == -1) {
342 snprintf(err_str, LNET_MAX_STR_LEN,
343 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
345 return LUSTRE_CFG_RC_BAD_PARAM;
349 snprintf(err_str, LNET_MAX_STR_LEN,
350 "Failed to expand nidstr: %s", strerror(num_nids));
351 return LUSTRE_CFG_RC_OUT_OF_MEM;
355 snprintf(err_str, LNET_MAX_STR_LEN,
356 "\"%s\" did not expand to any nids", nidstr);
357 return LUSTRE_CFG_RC_BAD_PARAM;
365 * <intf>[<expr>], <intf>[<expr>],..
367 int lustre_lnet_parse_interfaces(char *intf_str,
368 struct lnet_dlc_network_descr *nw_descr)
373 char *cur = intf_str, *next = NULL;
374 char *end = intf_str + strlen(intf_str);
376 struct lnet_dlc_intf_descr *intf_descr, *tmp;
378 if (nw_descr == NULL)
379 return LUSTRE_CFG_RC_BAD_PARAM;
382 open_square = strchr(cur, '[');
383 if (open_square != NULL) {
384 close_square = strchr(cur, ']');
385 if (close_square == NULL) {
386 rc = LUSTRE_CFG_RC_BAD_PARAM;
390 comma = strchr(cur, ',');
391 if (comma != NULL && comma > close_square) {
393 len = next - close_square;
399 comma = strchr(cur, ',');
409 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
410 if (rc != LUSTRE_CFG_RC_NO_ERR)
416 return LUSTRE_CFG_RC_NO_ERR;
419 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
421 list_del(&intf_descr->intf_on_network);
422 free_intf_descr(intf_descr);
428 int lustre_lnet_config_lib_init(void)
430 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
433 void lustre_lnet_config_lib_uninit(void)
435 unregister_ioc_dev(LNET_DEV_ID);
438 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
439 int seq_no, struct cYAML **err_rc)
441 struct libcfs_ioctl_data data;
444 char err_str[LNET_MAX_STR_LEN];
446 snprintf(err_str, sizeof(err_str), "\"Success\"");
448 LIBCFS_IOC_INIT(data);
450 /* Reverse logic is used here in order not to change
451 * the lctl utility */
452 data.ioc_flags = load_ni_from_mod ? 0 : 1;
454 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
456 rc = l_ioctl(LNET_DEV_ID, opc, &data);
460 "\"LNet %s error: %s\"", (up) ? "configure" :
461 "unconfigure", strerror(errno));
465 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
466 "lnet", err_str, err_rc);
471 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
472 char *err_str, char *cmd_str)
476 rc = l_ioctl(LNET_DEV_ID, cmd, data);
479 snprintf(err_str, LNET_MAX_STR_LEN,
480 "\"%s peer ni operation failed: %s\"",
481 cmd_str, strerror(errno));
487 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
488 int seq_no, struct cYAML **show_rc,
489 struct cYAML **err_rc)
492 struct lnet_ioctl_ping_data ping;
493 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
494 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
495 struct lnet_process_id id;
496 char err_str[LNET_MAX_STR_LEN] = {0};
497 char *sep, *token, *end;
500 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
504 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
506 data = calloc(1, len);
510 /* create struct cYAML root object */
511 root = cYAML_create_object(NULL, NULL);
515 ping_node = cYAML_create_seq(root, oper);
516 if (ping_node == NULL)
519 /* tokenise each nid in string ping_nids */
520 token = strtok(ping_nids, ",");
523 item = cYAML_create_seq_item(ping_node);
527 if (first_seq == NULL)
530 /* check if '-' is a part of NID, token */
531 sep = strchr(token, '-');
533 id.pid = LNET_PID_ANY;
534 /* if no net is specified, libcfs_str2nid() will assume tcp */
535 id.nid = libcfs_str2nid(token);
536 if (id.nid == LNET_NID_ANY) {
537 snprintf(err_str, sizeof(err_str),
538 "\"cannot parse NID '%s'\"",
540 rc = LUSTRE_CFG_RC_BAD_PARAM;
541 cYAML_build_error(rc, seq_no, MANAGE_CMD,
542 oper, err_str, err_rc);
546 if (token[0] == 'u' || token[0] == 'U')
547 id.pid = (strtoul(&token[1], &end, 0) |
548 (LNET_PID_USERFLAG));
550 id.pid = strtoul(token, &end, 0);
552 /* assuming '-' is part of hostname */
554 id.pid = LNET_PID_ANY;
555 id.nid = libcfs_str2nid(token);
556 if (id.nid == LNET_NID_ANY) {
557 snprintf(err_str, sizeof(err_str),
558 "\"cannot parse NID '%s'\"",
560 rc = LUSTRE_CFG_RC_BAD_PARAM;
561 cYAML_build_error(rc, seq_no, MANAGE_CMD,
567 id.nid = libcfs_str2nid(sep + 1);
568 if (id.nid == LNET_NID_ANY) {
569 snprintf(err_str, sizeof(err_str),
570 "\"cannot parse NID '%s'\"",
572 rc = LUSTRE_CFG_RC_BAD_PARAM;
573 cYAML_build_error(rc, seq_no, MANAGE_CMD,
580 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
581 ping.ping_hdr.ioc_len = sizeof(ping);
583 ping.op_param = param;
584 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
585 ping.ping_buf = data;
587 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
590 sizeof(err_str), "failed to %s %s: %s\n", oper,
591 id.pid == LNET_PID_ANY ?
592 libcfs_nid2str(id.nid) :
593 libcfs_id2str(id), strerror(errno));
594 rc = LUSTRE_CFG_RC_BAD_PARAM;
595 cYAML_build_error(rc, seq_no, MANAGE_CMD,
596 oper, err_str, err_rc);
600 if (cYAML_create_string(item, "primary nid",
601 libcfs_nid2str(ping.ping_id.nid)) == NULL)
604 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
605 "True" : "False") == NULL)
608 tmp = cYAML_create_seq(item, "peer ni");
612 for (i = 0; i < ping.ping_count; i++) {
613 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
615 peer_ni = cYAML_create_seq_item(tmp);
618 memset(buf, 0, sizeof buf);
619 snprintf(buf, sizeof buf, "nid");
620 if (cYAML_create_string(peer_ni, buf,
621 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
627 } while ((token = strtok(NULL, ",")) != NULL);
630 rc = LUSTRE_CFG_RC_NO_ERR;
635 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
636 cYAML_free_tree(root);
637 } else if (show_rc != NULL && *show_rc != NULL) {
638 struct cYAML *show_node;
639 show_node = cYAML_get_object_item(*show_rc, oper);
640 if (show_node != NULL && cYAML_is_sequence(show_node)) {
641 cYAML_insert_child(show_node, first_seq);
644 } else if (show_node == NULL) {
645 cYAML_insert_sibling((*show_rc)->cy_child,
649 cYAML_free_tree(root);
658 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
659 struct cYAML **show_rc, struct cYAML **err_rc)
663 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
664 seq_no, show_rc, err_rc);
668 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
669 struct cYAML **show_rc, struct cYAML **err_rc)
673 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
674 seq_no, show_rc, err_rc);
678 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
679 bool is_mr, __u32 cmd,
680 char *cmd_type, char *err_str)
682 struct lnet_ioctl_peer_cfg data;
685 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
686 /* When adding a peer we first need to create the peer using the
687 * specified (or implied) primary nid. Then we can add
688 * additional nids to this peer using the primary nid as a key
690 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
691 data.prcfg_mr = is_mr;
692 data.prcfg_prim_nid = nidlist[0];
693 data.prcfg_cfg_nid = LNET_NID_ANY;
695 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
701 /* Add or delete any specified NIs associated with the specified
702 * (or implied) primary nid
704 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
705 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
706 data.prcfg_mr = is_mr;
707 data.prcfg_prim_nid = nidlist[0];
708 data.prcfg_cfg_nid = nidlist[nid_idx];
710 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
716 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
717 /* In the delete case we may have been given just the
718 * primary nid of the peer. This tells us to delete the peer
719 * completely (rather than just delete some of its NIs)
721 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
722 data.prcfg_prim_nid = nidlist[0];
723 data.prcfg_cfg_nid = LNET_NID_ANY;
725 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
731 int lustre_lnet_config_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
732 int num_nids, bool is_mr, int seq_no,
733 struct cYAML **err_rc)
735 int rc = LUSTRE_CFG_RC_NO_ERR;
736 char err_str[LNET_MAX_STR_LEN];
737 lnet_nid_t *lnet_nidlist2 = NULL;
741 pnid = libcfs_str2nid(pnidstr);
742 if (pnid == LNET_NID_ANY) {
743 snprintf(err_str, LNET_MAX_STR_LEN,
744 "bad primary NID: '%s'", pnidstr);
745 rc = LUSTRE_CFG_RC_MISSING_PARAM;
751 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
752 if (!lnet_nidlist2) {
753 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
754 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
757 lnet_nidlist2[0] = pnid;
758 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
762 rc = lustre_lnet_handle_peer_nidlist((pnidstr) ? lnet_nidlist2 :
765 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
771 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
775 int lustre_lnet_del_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
776 int num_nids, int seq_no,
777 struct cYAML **err_rc)
779 int rc = LUSTRE_CFG_RC_NO_ERR;
780 char err_str[LNET_MAX_STR_LEN];
781 lnet_nid_t *lnet_nidlist2 = NULL;
785 snprintf(err_str, sizeof(err_str),
786 "\"Primary nid is not provided\"");
787 rc = LUSTRE_CFG_RC_MISSING_PARAM;
791 pnid = libcfs_str2nid(pnidstr);
792 if (pnid == LNET_NID_ANY) {
793 rc = LUSTRE_CFG_RC_BAD_PARAM;
794 snprintf(err_str, sizeof(err_str),
801 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
802 if (!lnet_nidlist2) {
803 snprintf(err_str, sizeof(err_str),
805 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
808 lnet_nidlist2[0] = pnid;
809 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
812 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2, num_nids, false,
813 IOC_LIBCFS_DEL_PEER_NI, DEL_CMD,
819 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
823 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
824 int sen, int seq_no, struct cYAML **err_rc,
827 int rc, num_nids, num_nidstrs, nid_idx, str_idx;
829 char err_str[LNET_MAX_STR_LEN];
830 char *nidstrarray[LNET_MAX_STR_LEN];
831 struct lnet_ioctl_config_data data;
832 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
834 if (nw == NULL || nidstr == NULL) {
835 snprintf(err_str, LNET_MAX_STR_LEN,
836 "\"missing mandatory parameter:'%s'\"",
837 (nw == NULL && nidstr == NULL) ? "network, gateway" :
838 (nw == NULL) ? "network" : "gateway");
839 rc = LUSTRE_CFG_RC_MISSING_PARAM;
843 rnet = libcfs_str2net(nw);
844 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
845 snprintf(err_str, LNET_MAX_STR_LEN,
846 "\"cannot parse remote net %s\"", nw);
847 rc = LUSTRE_CFG_RC_BAD_PARAM;
851 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
857 for (str_idx = 0; str_idx < num_nidstrs; str_idx++) {
858 rc = lustre_lnet_parse_nidstr(nidstrarray[str_idx],
860 LNET_MAX_NIDS_PER_PEER, err_str);
866 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
868 if (cmd == LNETCTL_ADD_CMD) {
869 data.cfg_config_u.cfg_route.rtr_hop = hops;
870 data.cfg_config_u.cfg_route.rtr_priority = prio;
871 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
874 for (nid_idx = 0; nid_idx < num_nids; nid_idx++) {
875 data.cfg_nid = lnet_nidlist[nid_idx];
877 if (cmd == LNETCTL_ADD_CMD)
878 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
881 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
884 if (rc != 0 && errno != EEXIST &&
885 errno != EHOSTUNREACH) {
887 snprintf(err_str, LNET_MAX_STR_LEN,
888 "route operation failed: %s",
896 cYAML_build_error(rc, seq_no,
897 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
903 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
904 int sen, int seq_no, struct cYAML **err_rc)
907 char err_str[LNET_MAX_STR_LEN];
910 hops = LNET_UNDEFINED_HOPS;
911 } else if (hops < 1 || hops > 255) {
912 snprintf(err_str, LNET_MAX_STR_LEN,
913 "\"invalid hop count %d, must be between 1 and 255\"",
915 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
921 } else if (prio < 0) {
922 snprintf(err_str, LNET_MAX_STR_LEN,
923 "\"invalid priority %d, must be greater than 0\"",
925 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
931 } else if (sen < 1) {
932 snprintf(err_str, LNET_MAX_STR_LEN,
933 "\"invalid health sensitivity %d, must be 1 or greater\"",
935 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
939 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
940 err_rc, LNETCTL_ADD_CMD);
942 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
947 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
948 struct cYAML **err_rc)
950 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
954 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
955 int seq_no, struct cYAML **show_rc,
956 struct cYAML **err_rc, bool backup)
958 struct lnet_ioctl_config_data data;
959 lnet_nid_t gateway_nid;
960 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
962 __u32 net = LNET_NIDNET(LNET_NID_ANY);
964 struct cYAML *root = NULL, *route = NULL, *item = NULL;
965 struct cYAML *first_seq = NULL;
966 char err_str[LNET_MAX_STR_LEN];
969 snprintf(err_str, sizeof(err_str),
970 "\"out of memory\"");
973 net = libcfs_str2net(nw);
974 if (net == LNET_NIDNET(LNET_NID_ANY)) {
977 "\"cannot parse net '%s'\"", nw);
978 rc = LUSTRE_CFG_RC_BAD_PARAM;
983 /* show all routes without filtering on net */
984 net = LNET_NIDNET(LNET_NID_ANY);
988 gateway_nid = libcfs_str2nid(gw);
989 if (gateway_nid == LNET_NID_ANY) {
992 "\"cannot parse gateway NID '%s'\"", gw);
993 rc = LUSTRE_CFG_RC_BAD_PARAM;
997 /* show all routes with out filtering on gateway */
998 gateway_nid = LNET_NID_ANY;
1000 if ((hops < 1 && hops != -1) || hops > 255) {
1003 "\"invalid hop count %d, must be between 0 and 256\"",
1005 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1009 /* create struct cYAML root object */
1010 root = cYAML_create_object(NULL, NULL);
1014 route = cYAML_create_seq(root, "route");
1022 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1025 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1031 /* filter on provided data */
1032 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1033 net != data.cfg_net)
1036 if (gateway_nid != LNET_NID_ANY &&
1037 gateway_nid != data.cfg_nid)
1041 hops != data.cfg_config_u.cfg_route.rtr_hop)
1045 prio != data.cfg_config_u.cfg_route.rtr_priority)
1048 /* default rc to -1 incase we hit the goto */
1052 item = cYAML_create_seq_item(route);
1056 if (first_seq == NULL)
1059 if (cYAML_create_string(item, "net",
1060 libcfs_net2str(data.cfg_net)) == NULL)
1063 if (cYAML_create_string(item, "gateway",
1064 libcfs_nid2str(data.cfg_nid)) == NULL)
1068 if (cYAML_create_number(item, "hop",
1069 (int) data.cfg_config_u.
1070 cfg_route.rtr_hop) ==
1074 if (cYAML_create_number(item, "priority",
1076 cfg_route.rtr_priority) == NULL)
1079 if (cYAML_create_number(item, "health_sensitivity",
1081 cfg_route.rtr_sensitivity) == NULL)
1084 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1086 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1090 cYAML_create_string(item, "state",
1092 "up" : "down") == NULL)
1096 cYAML_create_string(item, "type",
1098 "multi-hop" : "single-hop") == NULL)
1103 /* print output iff show_rc is not provided */
1104 if (show_rc == NULL)
1105 cYAML_print_tree(root);
1107 if (l_errno != ENOENT) {
1110 "\"cannot get routes: %s\"",
1115 rc = LUSTRE_CFG_RC_NO_ERR;
1117 snprintf(err_str, sizeof(err_str), "\"success\"");
1119 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1120 cYAML_free_tree(root);
1121 } else if (show_rc != NULL && *show_rc != NULL) {
1122 struct cYAML *show_node;
1123 /* find the route node, if one doesn't exist then
1124 * insert one. Otherwise add to the one there
1126 show_node = cYAML_get_object_item(*show_rc, "route");
1127 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1128 cYAML_insert_child(show_node, first_seq);
1131 } else if (show_node == NULL) {
1132 cYAML_insert_sibling((*show_rc)->cy_child,
1136 cYAML_free_tree(root);
1142 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1147 static int socket_intf_query(int request, char *intf,
1153 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1154 return LUSTRE_CFG_RC_BAD_PARAM;
1156 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1158 return LUSTRE_CFG_RC_BAD_PARAM;
1160 strcpy(ifr->ifr_name, intf);
1161 rc = ioctl(sockfd, request, ifr);
1163 rc = LUSTRE_CFG_RC_BAD_PARAM;
1170 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1175 memset(&ifr, 0, sizeof(ifr));
1176 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1178 return LUSTRE_CFG_RC_BAD_PARAM;
1180 if ((ifr.ifr_flags & IFF_UP) == 0)
1181 return LUSTRE_CFG_RC_BAD_PARAM;
1183 memset(&ifr, 0, sizeof(ifr));
1184 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1186 return LUSTRE_CFG_RC_BAD_PARAM;
1188 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1189 *ip = bswap_32(*ip);
1191 return LUSTRE_CFG_RC_NO_ERR;
1195 * for each interface in the array of interfaces find the IP address of
1196 * that interface, create its nid and add it to an array of NIDs.
1197 * Stop if any of the interfaces is down
1199 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1200 lnet_nid_t **nids, __u32 *nnids,
1201 char *err_str, size_t str_len)
1203 int i = 0, count = 0, rc;
1204 struct lnet_dlc_intf_descr *intf;
1205 char val[LNET_MAX_STR_LEN];
1212 if (nw == NULL || nids == NULL) {
1213 snprintf(err_str, str_len,
1214 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1215 err_str[str_len - 1] = '\0';
1216 return LUSTRE_CFG_RC_BAD_PARAM;
1219 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1222 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1226 *nids = calloc(count, sizeof(lnet_nid_t));
1227 if (*nids == NULL) {
1228 snprintf(err_str, str_len,
1229 "\"out of memory\"");
1230 err_str[str_len - 1] = '\0';
1231 return LUSTRE_CFG_RC_OUT_OF_MEM;
1234 * special case the GNI interface since it doesn't have an IP
1235 * address. The assumption is that there can only be one GNI
1236 * interface in the system. No interface name is provided.
1238 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1239 rc = read_sysfs_file(gni_nid_path, "nid", val,
1242 snprintf(err_str, str_len,
1243 "\"cannot read gni nid\"");
1244 err_str[str_len - 1] = '\0';
1247 gni_num = atoi(val);
1249 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1254 /* look at the other interfaces */
1255 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1256 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1257 /* handle LNDs with numeric interface name */
1258 num = strtoul(intf->intf_name, &endp, 0);
1259 if (endp == intf->intf_name || *endp != '\0') {
1260 rc = LUSTRE_CFG_RC_BAD_PARAM;
1261 snprintf(err_str, str_len,
1262 "\"couldn't query intf %s\"",
1264 err_str[str_len - 1] = '\0';
1267 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1270 /* handle LNDs with ip interface name */
1271 rc = lustre_lnet_queryip(intf, &ip);
1272 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1273 snprintf(err_str, str_len,
1274 "\"couldn't query intf %s\"",
1276 err_str[str_len - 1] = '\0';
1279 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1296 * called repeatedly until a match or no more ip range
1298 * ip_range expression
1299 * interface list with all the interface names.
1300 * all the interfaces in the system.
1302 * try to match the ip_range expr to one of the interfaces' IPs in
1303 * the system. If we hit a patch for an interface. Check if that
1304 * interface name is in the list.
1306 * If there are more than one interface in the list, then make sure
1307 * that the IPs for all of these interfaces match the ip ranges
1310 * for each interface in intf_list
1311 * look up the intf name in ifa
1312 * if not there then no match
1313 * check ip obtained from ifa against a match to any of the
1315 * If no match, then fail
1317 * The result is that all the interfaces have to match.
1319 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1320 struct list_head *intf_list,
1321 struct list_head *ip_ranges)
1325 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1326 struct ifaddrs *ifaddr = ifa;
1327 struct lustre_lnet_ip_range_descr *ip_range;
1331 * if there are no explicit interfaces, and no ip ranges, then
1332 * configure the first tcp interface we encounter.
1334 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1335 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1336 if (ifaddr->ifa_addr == NULL)
1339 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1342 family = ifaddr->ifa_addr->sa_family;
1343 if (family == AF_INET &&
1344 strcmp(ifaddr->ifa_name, "lo") != 0) {
1345 rc = lustre_lnet_add_intf_descr
1346 (intf_list, ifaddr->ifa_name,
1347 strlen(ifaddr->ifa_name));
1349 if (rc != LUSTRE_CFG_RC_NO_ERR)
1352 return LUSTRE_CFG_RC_MATCH;
1355 return LUSTRE_CFG_RC_NO_MATCH;
1359 * First interface which matches an IP pattern will be used
1361 if (list_empty(intf_list)) {
1363 * no interfaces provided in the rule, but an ip range is
1364 * provided, so try and match an interface to the ip
1367 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1368 if (ifaddr->ifa_addr == NULL)
1371 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1374 family = ifaddr->ifa_addr->sa_family;
1375 if (family == AF_INET) {
1376 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1379 list_for_each_entry(ip_range, ip_ranges,
1381 rc = cfs_ip_addr_match(bswap_32(ip),
1382 &ip_range->ipr_expr);
1386 rc = lustre_lnet_add_intf_descr
1387 (intf_list, ifaddr->ifa_name,
1388 strlen(ifaddr->ifa_name));
1390 if (rc != LUSTRE_CFG_RC_NO_ERR)
1396 if (!list_empty(intf_list))
1397 return LUSTRE_CFG_RC_MATCH;
1399 return LUSTRE_CFG_RC_NO_MATCH;
1403 * If an interface is explicitly specified the ip-range might or
1404 * might not be specified. if specified the interface needs to match the
1405 * ip-range. If no ip-range then the interfaces are
1406 * automatically matched if they are all up.
1407 * If > 1 interfaces all the interfaces must match for the NI to
1410 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1411 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1412 if (ifaddr->ifa_addr == NULL)
1415 family = ifaddr->ifa_addr->sa_family;
1416 if (family == AF_INET &&
1417 strcmp(intf_descr->intf_name,
1418 ifaddr->ifa_name) == 0)
1422 if (ifaddr == NULL) {
1423 list_del(&intf_descr->intf_on_network);
1424 free_intf_descr(intf_descr);
1428 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1429 list_del(&intf_descr->intf_on_network);
1430 free_intf_descr(intf_descr);
1434 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1437 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1438 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1444 /* no match for this interface */
1445 list_del(&intf_descr->intf_on_network);
1446 free_intf_descr(intf_descr);
1450 return LUSTRE_CFG_RC_MATCH;
1453 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1454 lnet_nid_t **nids, __u32 *nnids,
1455 char *err_str, size_t str_len)
1457 struct ifaddrs *ifa;
1458 int rc = LUSTRE_CFG_RC_NO_ERR;
1460 rc = getifaddrs(&ifa);
1462 snprintf(err_str, str_len,
1463 "\"failed to get interface addresses: %d\"", -errno);
1464 err_str[str_len - 1] = '\0';
1468 rc = lustre_lnet_match_ip_to_intf(ifa,
1469 &ip2nets->ip2nets_net.nw_intflist,
1470 &ip2nets->ip2nets_ip_ranges);
1471 if (rc != LUSTRE_CFG_RC_MATCH) {
1472 snprintf(err_str, str_len,
1473 "\"couldn't match ip to existing interfaces\"");
1474 err_str[str_len - 1] = '\0';
1479 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1480 err_str, sizeof(err_str));
1481 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1492 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1493 struct lnet_ioctl_config_lnd_tunables *tunables,
1494 struct cfs_expr_list *global_cpts,
1495 lnet_nid_t *nids, char *err_str)
1498 struct lnet_ioctl_config_ni *conf;
1499 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1500 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1503 struct lnet_dlc_intf_descr *intf_descr;
1505 struct cfs_expr_list *cpt_expr;
1507 list_for_each_entry(intf_descr, intf_list,
1509 if (tunables != NULL)
1510 len = sizeof(struct lnet_ioctl_config_ni) +
1511 sizeof(struct lnet_ioctl_config_lnd_tunables);
1513 len = sizeof(struct lnet_ioctl_config_ni);
1515 data = calloc(1, len);
1517 return LUSTRE_CFG_RC_OUT_OF_MEM;
1518 conf = (struct lnet_ioctl_config_ni*) data;
1519 if (tunables != NULL)
1520 tun = (struct lnet_ioctl_config_lnd_tunables*)
1523 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1524 conf->lic_cfg_hdr.ioc_len = len;
1525 conf->lic_nid = nids[i];
1526 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1529 if (intf_descr->cpt_expr != NULL)
1530 cpt_expr = intf_descr->cpt_expr;
1531 else if (global_cpts != NULL)
1532 cpt_expr = global_cpts;
1536 if (cpt_expr != NULL) {
1537 count = cfs_expr_list_values(cpt_expr,
1538 LNET_MAX_SHOW_NUM_CPT,
1541 memcpy(conf->lic_cpts, cpt_array,
1542 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1551 conf->lic_ncpts = count;
1553 if (tunables != NULL)
1554 memcpy(tun, tunables, sizeof(*tunables));
1556 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1561 "\"cannot add network: %s\"", strerror(errno));
1569 return LUSTRE_CFG_RC_NO_ERR;
1573 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1574 struct lnet_ioctl_config_lnd_tunables *tunables,
1575 struct cfs_expr_list *global_cpts,
1576 int seq_no, struct cYAML **err_rc)
1578 lnet_nid_t *nids = NULL;
1581 char err_str[LNET_MAX_STR_LEN];
1583 snprintf(err_str, sizeof(err_str), "\"success\"");
1588 "\"incomplete ip2nets information\"");
1589 rc = LUSTRE_CFG_RC_BAD_PARAM;
1594 * call below function to resolve the rules into a list of nids.
1595 * The memory is allocated in that function then freed here when
1596 * it's no longer needed.
1598 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1600 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1603 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1604 snprintf(err_str, sizeof(err_str),
1605 "\"no interfaces match ip2nets rules\"");
1609 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1610 tunables, global_cpts, nids,
1617 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1621 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1622 struct cfs_expr_list *global_cpts,
1624 struct lnet_ioctl_config_lnd_tunables *tunables,
1625 int seq_no, struct cYAML **err_rc)
1628 struct lnet_ioctl_config_ni *conf;
1629 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1630 char buf[LNET_MAX_STR_LEN];
1631 int rc = LUSTRE_CFG_RC_NO_ERR;
1632 char err_str[LNET_MAX_STR_LEN];
1633 lnet_nid_t *nids = NULL;
1637 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1640 snprintf(err_str, sizeof(err_str), "\"success\"");
1642 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1643 (list_empty(&nw_descr->nw_intflist) &&
1644 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1647 "\"missing mandatory parameters in NI config: '%s'\"",
1648 (nw_descr == NULL) ? "network , interface" :
1649 (nw_descr->nw_id == 0) ? "network" : "interface");
1650 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1654 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1657 "\"ip2net string too long %d\"",
1658 (int)strlen(ip2net));
1659 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1663 if (ip2net != NULL) {
1664 if (tunables != NULL)
1665 len = sizeof(struct lnet_ioctl_config_ni) +
1666 sizeof(struct lnet_ioctl_config_lnd_tunables);
1668 len = sizeof(struct lnet_ioctl_config_ni);
1669 data = calloc(1, len);
1671 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1674 conf = (struct lnet_ioctl_config_ni*) data;
1675 if (tunables != NULL)
1676 tun = (struct lnet_ioctl_config_lnd_tunables*)
1677 (data + sizeof(*conf));
1679 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1680 conf->lic_cfg_hdr.ioc_len = len;
1681 strncpy(conf->lic_legacy_ip2nets, ip2net,
1684 if (global_cpts != NULL) {
1685 count = cfs_expr_list_values(global_cpts,
1686 LNET_MAX_SHOW_NUM_CPT,
1689 memcpy(conf->lic_cpts, cpt_array,
1690 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1699 conf->lic_ncpts = count;
1701 if (tunables != NULL)
1702 memcpy(tun, tunables, sizeof(*tunables));
1704 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1709 "\"cannot add network: %s\"", strerror(errno));
1716 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1717 rc = LUSTRE_CFG_RC_NO_ERR;
1721 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1724 "\"cannot parse net '%s'\"",
1725 libcfs_net2str(nw_descr->nw_id));
1726 rc = LUSTRE_CFG_RC_BAD_PARAM;
1731 * special case the GNI since no interface name is expected
1733 if (list_empty(&nw_descr->nw_intflist) &&
1734 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1737 "\"no interface name provided\"");
1738 rc = LUSTRE_CFG_RC_BAD_PARAM;
1742 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1743 err_str, sizeof(err_str));
1745 rc = LUSTRE_CFG_RC_BAD_PARAM;
1749 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1750 tunables, global_cpts, nids,
1754 if (nw_descr != NULL) {
1755 list_for_each_entry_safe(intf_descr, tmp,
1756 &nw_descr->nw_intflist,
1758 list_del(&intf_descr->intf_on_network);
1759 free_intf_descr(intf_descr);
1763 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1774 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1775 int seq_no, struct cYAML **err_rc)
1777 struct lnet_ioctl_config_ni data;
1778 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1779 char err_str[LNET_MAX_STR_LEN];
1780 lnet_nid_t *nids = NULL;
1782 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1784 snprintf(err_str, sizeof(err_str), "\"success\"");
1786 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1789 "\"missing mandatory parameter in deleting NI: '%s'\"",
1790 (nw_descr == NULL) ? "network , interface" :
1791 (nw_descr->nw_id == 0) ? "network" : "interface");
1792 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1796 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1797 return LUSTRE_CFG_RC_NO_ERR;
1799 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1802 "\"cannot parse net '%s'\"",
1803 libcfs_net2str(nw_descr->nw_id));
1804 rc = LUSTRE_CFG_RC_BAD_PARAM;
1808 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1809 err_str, sizeof(err_str));
1811 rc = LUSTRE_CFG_RC_BAD_PARAM;
1816 * no interfaces just the nw_id is specified
1819 nids = calloc(1, sizeof(*nids));
1821 snprintf(err_str, sizeof(err_str),
1822 "\"out of memory\"");
1823 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1826 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1830 for (i = 0; i < nnids; i++) {
1831 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1832 data.lic_nid = nids[i];
1834 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1839 "\"cannot del network: %s\"", strerror(errno));
1843 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1845 list_del(&intf_descr->intf_on_network);
1846 free_intf_descr(intf_descr);
1850 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1859 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1860 enum lnet_health_type type, char *name,
1861 int seq_no, struct cYAML **err_rc)
1863 struct lnet_ioctl_reset_health_cfg data;
1864 int rc = LUSTRE_CFG_RC_NO_ERR;
1865 char err_str[LNET_MAX_STR_LEN];
1867 snprintf(err_str, sizeof(err_str), "\"success\"");
1869 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1870 data.rh_type = type;
1872 data.rh_value = value;
1875 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1879 sizeof(err_str), "Can not configure health value: %s",
1883 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1888 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1889 struct cYAML **err_rc)
1893 nid = libcfs_str2nid(ni_nid);
1896 return lustre_lnet_config_healthv(value, all, nid,
1897 LNET_HEALTH_TYPE_LOCAL_NI,
1898 "ni healthv", seq_no, err_rc);
1901 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1902 int seq_no, struct cYAML **err_rc)
1906 nid = libcfs_str2nid(lpni_nid);
1909 return lustre_lnet_config_healthv(value, all, nid,
1910 LNET_HEALTH_TYPE_PEER_NI,
1911 "peer_ni healthv", seq_no, err_rc);
1915 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1916 struct lnet_ioctl_comm_count *counts)
1918 if (cYAML_create_number(yaml, "put",
1919 counts->ico_put_count)
1922 if (cYAML_create_number(yaml, "get",
1923 counts->ico_get_count)
1926 if (cYAML_create_number(yaml, "reply",
1927 counts->ico_reply_count)
1930 if (cYAML_create_number(yaml, "ack",
1931 counts->ico_ack_count)
1934 if (cYAML_create_number(yaml, "hello",
1935 counts->ico_hello_count)
1942 static struct lnet_ioctl_comm_count *
1943 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1946 return &msg_stats->im_send_stats;
1948 return &msg_stats->im_recv_stats;
1950 return &msg_stats->im_drop_stats;
1955 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1956 struct cYAML **show_rc, struct cYAML **err_rc,
1960 struct lnet_ioctl_config_ni *ni_data;
1961 struct lnet_ioctl_config_lnd_tunables *lnd;
1962 struct lnet_ioctl_element_stats *stats;
1963 struct lnet_ioctl_element_msg_stats msg_stats;
1964 struct lnet_ioctl_local_ni_hstats hstats;
1965 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1966 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1967 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1969 struct cYAML *root = NULL, *tunables = NULL,
1970 *net_node = NULL, *interfaces = NULL,
1971 *item = NULL, *first_seq = NULL,
1972 *tmp = NULL, *statistics = NULL,
1974 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1975 char str_buf[str_buf_len];
1977 char err_str[LNET_MAX_STR_LEN];
1978 bool exist = false, new_net = true;
1980 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1982 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1984 buf = calloc(1, buf_size);
1988 ni_data = (struct lnet_ioctl_config_ni *)buf;
1991 net = libcfs_str2net(nw);
1992 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1995 "\"cannot parse net '%s'\"", nw);
1996 rc = LUSTRE_CFG_RC_BAD_PARAM;
2001 root = cYAML_create_object(NULL, NULL);
2005 net_node = cYAML_create_seq(root, "net");
2006 if (net_node == NULL)
2012 memset(buf, 0, buf_size);
2014 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2016 * set the ioc_len to the proper value since INIT assumes
2019 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2020 ni_data->lic_idx = i;
2022 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2028 rc_net = LNET_NIDNET(ni_data->lic_nid);
2030 /* filter on provided data */
2031 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2035 /* if we're backing up don't store lo */
2036 if (backup && LNET_NETTYP(rc_net) == LOLND)
2039 /* default rc to -1 in case we hit the goto */
2043 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2044 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2045 (ni_data->lic_bulk + sizeof(*stats));
2047 if (rc_net != prev_net) {
2054 if (!cYAML_create_string(net_node, "net type",
2055 libcfs_net2str(rc_net)))
2058 tmp = cYAML_create_seq(net_node, "local NI(s)");
2064 /* create the tree to be printed. */
2065 item = cYAML_create_seq_item(tmp);
2069 if (first_seq == NULL)
2073 cYAML_create_string(item, "nid",
2074 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2078 cYAML_create_string(item,
2080 (ni_data->lic_status ==
2081 LNET_NI_STATUS_UP) ?
2082 "up" : "down") == NULL)
2085 /* don't add interfaces unless there is at least one
2087 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2088 interfaces = cYAML_create_object(item, "interfaces");
2089 if (interfaces == NULL)
2092 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2093 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2095 sizeof(str_buf), "%d", j);
2096 if (cYAML_create_string(interfaces,
2098 ni_data->lic_ni_intf[j]) ==
2110 goto continue_without_msg_stats;
2112 statistics = cYAML_create_object(item, "statistics");
2113 if (statistics == NULL)
2116 if (cYAML_create_number(statistics, "send_count",
2117 stats->iel_send_count)
2121 if (cYAML_create_number(statistics, "recv_count",
2122 stats->iel_recv_count)
2126 if (cYAML_create_number(statistics, "drop_count",
2127 stats->iel_drop_count)
2132 goto continue_without_msg_stats;
2134 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2135 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2136 msg_stats.im_idx = i;
2138 rc = l_ioctl(LNET_DEV_ID,
2139 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2143 goto continue_without_msg_stats;
2146 for (k = 0; k < 3; k++) {
2147 struct lnet_ioctl_comm_count *counts;
2148 struct cYAML *msg_statistics = NULL;
2150 msg_statistics = cYAML_create_object(item,
2151 (char *)gmsg_stat_names[k]);
2152 if (msg_statistics == NULL)
2155 counts = get_counts(&msg_stats, k);
2159 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2164 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2165 hstats.hlni_nid = ni_data->lic_nid;
2166 /* grab health stats */
2167 rc = l_ioctl(LNET_DEV_ID,
2168 IOC_LIBCFS_GET_LOCAL_HSTATS,
2172 goto continue_without_msg_stats;
2174 yhstats = cYAML_create_object(item, "health stats");
2177 if (cYAML_create_number(yhstats, "health value",
2178 hstats.hlni_health_value)
2181 if (cYAML_create_number(yhstats, "interrupts",
2182 hstats.hlni_local_interrupt)
2185 if (cYAML_create_number(yhstats, "dropped",
2186 hstats.hlni_local_dropped)
2189 if (cYAML_create_number(yhstats, "aborted",
2190 hstats.hlni_local_aborted)
2193 if (cYAML_create_number(yhstats, "no route",
2194 hstats.hlni_local_no_route)
2197 if (cYAML_create_number(yhstats, "timeouts",
2198 hstats.hlni_local_timeout)
2201 if (cYAML_create_number(yhstats, "error",
2202 hstats.hlni_local_error)
2206 continue_without_msg_stats:
2207 tunables = cYAML_create_object(item, "tunables");
2211 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2212 if (rc != LUSTRE_CFG_RC_NO_ERR)
2215 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2217 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2218 rc != LUSTRE_CFG_RC_NO_MATCH)
2221 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2222 tunables = cYAML_create_object(item,
2224 if (tunables == NULL)
2229 cYAML_create_number(item, "dev cpt",
2230 ni_data->lic_dev_cpt) == NULL)
2234 cYAML_create_number(item, "tcp bonding",
2235 ni_data->lic_tcp_bonding)
2239 /* out put the CPTs in the format: "[x,x,x,...]" */
2241 limit = str_buf + str_buf_len - 3;
2242 pos += scnprintf(pos, limit - pos, "\"[");
2243 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2244 j < ni_data->lic_ncpts &&
2246 pos += scnprintf(pos, limit - pos,
2247 "%d", ni_data->lic_cpts[j]);
2248 if ((j + 1) < ni_data->lic_ncpts)
2249 pos += scnprintf(pos, limit - pos, ",");
2251 snprintf(pos, 3, "]\"");
2253 if (ni_data->lic_ncpts >= 1 &&
2254 cYAML_create_string(item, "CPT",
2260 /* Print out the net information only if show_rc is not provided */
2261 if (show_rc == NULL)
2262 cYAML_print_tree(root);
2264 if (l_errno != ENOENT) {
2267 "\"cannot get networks: %s\"",
2272 rc = LUSTRE_CFG_RC_NO_ERR;
2274 snprintf(err_str, sizeof(err_str), "\"success\"");
2276 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2277 cYAML_free_tree(root);
2278 } else if (show_rc != NULL && *show_rc != NULL) {
2279 struct cYAML *show_node;
2280 /* find the net node, if one doesn't exist
2281 * then insert one. Otherwise add to the one there
2283 show_node = cYAML_get_object_item(*show_rc, "net");
2284 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2285 cYAML_insert_child(show_node, first_seq);
2288 } else if (show_node == NULL) {
2289 cYAML_insert_sibling((*show_rc)->cy_child,
2293 cYAML_free_tree(root);
2299 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2304 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2306 struct lnet_ioctl_config_data data;
2307 int rc = LUSTRE_CFG_RC_NO_ERR;
2308 char err_str[LNET_MAX_STR_LEN];
2310 snprintf(err_str, sizeof(err_str), "\"success\"");
2312 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2313 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2315 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2320 "\"cannot %s routing %s\"",
2321 (enable) ? "enable" : "disable", strerror(errno));
2326 cYAML_build_error(rc, seq_no,
2327 (enable) ? ADD_CMD : DEL_CMD,
2328 "routing", err_str, err_rc);
2333 int ioctl_set_value(__u32 val, int ioc, char *name,
2334 int seq_no, struct cYAML **err_rc)
2336 struct lnet_ioctl_set_value data;
2337 int rc = LUSTRE_CFG_RC_NO_ERR;
2338 char err_str[LNET_MAX_STR_LEN];
2340 snprintf(err_str, sizeof(err_str), "\"success\"");
2342 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2343 data.sv_value = val;
2345 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2350 "\"cannot configure %s to %d: %s\"", name,
2351 val, strerror(errno));
2354 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2359 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2361 int rc = LUSTRE_CFG_RC_NO_ERR;
2362 char err_str[LNET_MAX_STR_LEN];
2363 char val[LNET_MAX_STR_LEN];
2365 snprintf(err_str, sizeof(err_str), "\"success\"");
2367 snprintf(val, sizeof(val), "%d", intrv);
2369 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2370 1, strlen(val) + 1);
2372 snprintf(err_str, sizeof(err_str),
2373 "\"cannot configure recovery interval: %s\"",
2376 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2381 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2383 int rc = LUSTRE_CFG_RC_NO_ERR;
2384 char err_str[LNET_MAX_STR_LEN];
2385 char val[LNET_MAX_STR_LEN];
2387 snprintf(err_str, sizeof(err_str), "\"success\"");
2389 snprintf(val, sizeof(val), "%d", sen);
2391 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2392 1, strlen(val) + 1);
2394 snprintf(err_str, sizeof(err_str),
2395 "\"cannot configure router health sensitivity: %s\"",
2398 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2403 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2405 int rc = LUSTRE_CFG_RC_NO_ERR;
2406 char err_str[LNET_MAX_STR_LEN];
2407 char val[LNET_MAX_STR_LEN];
2409 snprintf(err_str, sizeof(err_str), "\"success\"");
2411 snprintf(val, sizeof(val), "%d", sen);
2413 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2414 1, strlen(val) + 1);
2416 snprintf(err_str, sizeof(err_str),
2417 "\"cannot configure health sensitivity: %s\"",
2420 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2425 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2427 int rc = LUSTRE_CFG_RC_NO_ERR;
2428 char err_str[LNET_MAX_STR_LEN];
2429 char val[LNET_MAX_STR_LEN];
2431 snprintf(err_str, sizeof(err_str), "\"success\"");
2433 snprintf(val, sizeof(val), "%d", timeout);
2435 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2436 1, strlen(val) + 1);
2438 snprintf(err_str, sizeof(err_str),
2439 "\"cannot configure transaction timeout: %s\"",
2442 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2447 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2449 int rc = LUSTRE_CFG_RC_NO_ERR;
2450 char err_str[LNET_MAX_STR_LEN];
2451 char val[LNET_MAX_STR_LEN];
2453 snprintf(err_str, sizeof(err_str), "\"success\"");
2455 snprintf(val, sizeof(val), "%d", count);
2457 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2458 1, strlen(val) + 1);
2460 snprintf(err_str, sizeof(err_str),
2461 "\"cannot configure retry count: %s\"",
2464 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2469 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2471 int rc = LUSTRE_CFG_RC_NO_ERR;
2472 char err_str[LNET_MAX_STR_LEN];
2473 char val[LNET_MAX_STR_LEN];
2475 snprintf(err_str, sizeof(err_str), "\"success\"");
2477 snprintf(val, sizeof(val), "%d", max);
2479 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2480 1, strlen(val) + 1);
2482 snprintf(err_str, sizeof(err_str),
2483 "\"cannot configure max interfaces: %s\"",
2486 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2491 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2493 int rc = LUSTRE_CFG_RC_NO_ERR;
2494 char err_str[LNET_MAX_STR_LEN];
2495 char val[LNET_MAX_STR_LEN];
2497 snprintf(err_str, sizeof(err_str), "\"success\"");
2499 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2501 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2502 1, strlen(val) + 1);
2504 snprintf(err_str, sizeof(err_str),
2505 "\"cannot configure discovery: %s\"",
2508 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2514 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2515 struct cYAML **err_rc)
2517 int rc = LUSTRE_CFG_RC_NO_ERR;
2518 char err_str[LNET_MAX_STR_LEN];
2519 char val[LNET_MAX_STR_LEN];
2521 snprintf(err_str, sizeof(err_str), "\"success\"");
2523 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2525 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2526 1, strlen(val) + 1);
2528 snprintf(err_str, sizeof(err_str),
2529 "\"cannot configure drop asym route: %s\"",
2532 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2539 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2541 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2542 "numa_range", seq_no, err_rc);
2545 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2546 struct cYAML **err_rc)
2548 struct lnet_ioctl_config_data data;
2549 int rc = LUSTRE_CFG_RC_NO_ERR;
2550 char err_str[LNET_MAX_STR_LEN];
2552 snprintf(err_str, sizeof(err_str), "\"success\"");
2554 /* -1 indicates to ignore changes to this field */
2555 if (tiny < -1 || small < -1 || large < -1) {
2558 "\"tiny, small and large must be >= 0\"");
2559 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2563 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2564 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2565 data.cfg_config_u.cfg_buffers.buf_small = small;
2566 data.cfg_config_u.cfg_buffers.buf_large = large;
2568 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2573 "\"cannot configure buffers: %s\"", strerror(errno));
2578 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2583 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2584 struct cYAML **err_rc, bool backup)
2586 struct lnet_ioctl_config_data *data;
2587 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2588 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2591 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2592 int buf_count[LNET_NRBPOOLS] = {0};
2593 struct cYAML *root = NULL, *pools_node = NULL,
2594 *type_node = NULL, *item = NULL, *cpt = NULL,
2595 *first_seq = NULL, *buffers = NULL;
2597 char err_str[LNET_MAX_STR_LEN];
2598 char node_name[LNET_MAX_STR_LEN];
2601 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2603 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2607 data = (struct lnet_ioctl_config_data *)buf;
2609 root = cYAML_create_object(NULL, NULL);
2614 pools_node = cYAML_create_object(root, "routing");
2616 pools_node = cYAML_create_seq(root, "routing");
2617 if (pools_node == NULL)
2621 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2622 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2623 sizeof(struct lnet_ioctl_pool_cfg);
2624 data->cfg_count = i;
2626 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2634 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2637 goto calculate_buffers;
2639 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2640 item = cYAML_create_seq_item(pools_node);
2644 if (first_seq == NULL)
2647 cpt = cYAML_create_object(item, node_name);
2652 /* create the tree and print */
2653 for (j = 0; j < LNET_NRBPOOLS; j++) {
2655 type_node = cYAML_create_object(cpt, pools[j]);
2656 if (type_node == NULL)
2660 cYAML_create_number(type_node, "npages",
2661 pool_cfg->pl_pools[j].pl_npages)
2665 cYAML_create_number(type_node, "nbuffers",
2666 pool_cfg->pl_pools[j].
2667 pl_nbuffers) == NULL)
2670 cYAML_create_number(type_node, "credits",
2671 pool_cfg->pl_pools[j].
2672 pl_credits) == NULL)
2675 cYAML_create_number(type_node, "mincredits",
2676 pool_cfg->pl_pools[j].
2677 pl_mincredits) == NULL)
2679 /* keep track of the total count for each of the
2680 * tiny, small and large buffers */
2681 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2685 if (pool_cfg != NULL) {
2687 if (cYAML_create_number(pools_node, "enable",
2688 pool_cfg->pl_routing) ==
2692 goto add_buffer_section;
2695 item = cYAML_create_seq_item(pools_node);
2699 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2705 /* create a buffers entry in the show. This is necessary so that
2706 * if the YAML output is used to configure a node, the buffer
2707 * configuration takes hold */
2708 buffers = cYAML_create_object(root, "buffers");
2709 if (buffers == NULL)
2712 for (i = 0; i < LNET_NRBPOOLS; i++) {
2713 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2717 if (show_rc == NULL)
2718 cYAML_print_tree(root);
2720 if (l_errno != ENOENT) {
2723 "\"cannot get routing information: %s\"",
2728 rc = LUSTRE_CFG_RC_NO_ERR;
2730 snprintf(err_str, sizeof(err_str), "\"success\"");
2731 rc = LUSTRE_CFG_RC_NO_ERR;
2735 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2736 cYAML_free_tree(root);
2737 } else if (show_rc != NULL && *show_rc != NULL) {
2738 struct cYAML *routing_node;
2739 /* there should exist only one routing block and one
2740 * buffers block. If there already exists a previous one
2741 * then don't add another */
2742 routing_node = cYAML_get_object_item(*show_rc, "routing");
2743 if (routing_node == NULL) {
2744 cYAML_insert_sibling((*show_rc)->cy_child,
2748 cYAML_free_tree(root);
2754 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2759 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2760 struct cYAML **show_rc, struct cYAML **err_rc,
2764 * TODO: This function is changing in a future patch to accommodate
2765 * PEER_LIST and proper filtering on any nid of the peer
2767 struct lnet_ioctl_peer_cfg peer_info;
2768 struct lnet_peer_ni_credit_info *lpni_cri;
2769 struct lnet_ioctl_element_stats *lpni_stats;
2770 struct lnet_ioctl_element_msg_stats *msg_stats;
2771 struct lnet_ioctl_peer_ni_hstats *hstats;
2773 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2778 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2779 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2780 *msg_statistics = NULL, *statistics = NULL,
2782 char err_str[LNET_MAX_STR_LEN];
2783 struct lnet_process_id *list = NULL;
2788 snprintf(err_str, sizeof(err_str),
2789 "\"out of memory\"");
2791 /* create struct cYAML root object */
2792 root = cYAML_create_object(NULL, NULL);
2796 peer_root = cYAML_create_seq(root, "peer");
2797 if (peer_root == NULL)
2801 size = count * sizeof(struct lnet_process_id);
2802 list = malloc(size);
2808 list[0].nid = libcfs_str2nid(knid);
2812 memset(&peer_info, 0, sizeof(peer_info));
2813 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2814 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2815 peer_info.prcfg_size = size;
2816 peer_info.prcfg_bulk = list;
2819 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2821 count = peer_info.prcfg_count;
2825 if (l_errno != E2BIG) {
2828 "\"cannot get peer list: %s\"",
2834 size = peer_info.prcfg_size;
2835 list = malloc(size);
2844 data = malloc(size);
2850 for (i = 0; i < count; i++) {
2852 memset(&peer_info, 0, sizeof(peer_info));
2853 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2854 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2855 peer_info.prcfg_prim_nid = list[i].nid;
2856 peer_info.prcfg_size = size;
2857 peer_info.prcfg_bulk = data;
2860 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2865 if (l_errno != E2BIG) {
2868 "\"cannot get peer information: %s\"",
2874 size = peer_info.prcfg_size;
2875 data = malloc(size);
2883 peer = cYAML_create_seq_item(peer_root);
2887 if (first_seq == NULL)
2890 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2891 if (cYAML_create_string(peer, "primary nid",
2892 libcfs_nid2str(pnid))
2895 if (cYAML_create_string(peer, "Multi-Rail",
2896 peer_info.prcfg_mr ? "True" : "False")
2900 * print out the state of the peer only if details are
2905 cYAML_create_number(peer, "peer state",
2906 peer_info.prcfg_state)
2911 tmp = cYAML_create_seq(peer, "peer ni");
2916 for (j = 0; j < peer_info.prcfg_count; j++) {
2918 lpni_cri = (void*)nidp + sizeof(nidp);
2919 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2920 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2921 hstats = (void *)msg_stats + sizeof(*msg_stats);
2922 lpni_data = (void *)hstats + sizeof(*hstats);
2924 peer_ni = cYAML_create_seq_item(tmp);
2925 if (peer_ni == NULL)
2928 if (cYAML_create_string(peer_ni, "nid",
2929 libcfs_nid2str(*nidp))
2936 if (cYAML_create_string(peer_ni, "state",
2937 lpni_cri->cr_aliveness)
2944 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2945 lpni_cri->cr_ni_peer_tx_credits)
2949 if (cYAML_create_number(peer_ni, "available_tx_credits",
2950 lpni_cri->cr_peer_tx_credits)
2954 if (cYAML_create_number(peer_ni, "min_tx_credits",
2955 lpni_cri->cr_peer_min_tx_credits)
2959 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2960 lpni_cri->cr_peer_tx_qnob)
2964 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2965 lpni_cri->cr_peer_rtr_credits)
2969 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2970 lpni_cri->cr_peer_min_rtr_credits)
2974 if (cYAML_create_number(peer_ni, "refcount",
2975 lpni_cri->cr_refcount) == NULL)
2978 statistics = cYAML_create_object(peer_ni, "statistics");
2979 if (statistics == NULL)
2982 if (cYAML_create_number(statistics, "send_count",
2983 lpni_stats->iel_send_count)
2987 if (cYAML_create_number(statistics, "recv_count",
2988 lpni_stats->iel_recv_count)
2992 if (cYAML_create_number(statistics, "drop_count",
2993 lpni_stats->iel_drop_count)
3000 for (k = 0; k < 3; k++) {
3001 struct lnet_ioctl_comm_count *counts;
3003 msg_statistics = cYAML_create_object(peer_ni,
3004 (char *) gmsg_stat_names[k]);
3005 if (msg_statistics == NULL)
3008 counts = get_counts(msg_stats, k);
3012 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3017 yhstats = cYAML_create_object(peer_ni, "health stats");
3020 if (cYAML_create_number(yhstats, "health value",
3021 hstats->hlpni_health_value)
3024 if (cYAML_create_number(yhstats, "dropped",
3025 hstats->hlpni_remote_dropped)
3028 if (cYAML_create_number(yhstats, "timeout",
3029 hstats->hlpni_remote_timeout)
3032 if (cYAML_create_number(yhstats, "error",
3033 hstats->hlpni_remote_error)
3036 if (cYAML_create_number(yhstats, "network timeout",
3037 hstats->hlpni_network_timeout)
3043 /* print output iff show_rc is not provided */
3044 if (show_rc == NULL)
3045 cYAML_print_tree(root);
3047 snprintf(err_str, sizeof(err_str), "\"success\"");
3048 rc = LUSTRE_CFG_RC_NO_ERR;
3053 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3054 cYAML_free_tree(root);
3055 } else if (show_rc != NULL && *show_rc != NULL) {
3056 struct cYAML *show_node;
3057 /* find the peer node, if one doesn't exist then
3058 * insert one. Otherwise add to the one there
3060 show_node = cYAML_get_object_item(*show_rc,
3062 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3063 cYAML_insert_child(show_node, first_seq);
3066 } else if (show_node == NULL) {
3067 cYAML_insert_sibling((*show_rc)->cy_child,
3071 cYAML_free_tree(root);
3077 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3083 int lustre_lnet_list_peer(int seq_no,
3084 struct cYAML **show_rc, struct cYAML **err_rc)
3086 struct lnet_ioctl_peer_cfg peer_info;
3087 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3092 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3093 char err_str[LNET_MAX_STR_LEN];
3094 struct lnet_process_id *list = NULL;
3096 snprintf(err_str, sizeof(err_str),
3097 "\"out of memory\"");
3099 memset(&peer_info, 0, sizeof(peer_info));
3101 /* create struct cYAML root object */
3102 root = cYAML_create_object(NULL, NULL);
3106 list_root = cYAML_create_seq(root, "peer list");
3107 if (list_root == NULL)
3111 size = count * sizeof(struct lnet_process_id);
3112 list = malloc(size);
3118 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3119 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3120 peer_info.prcfg_size = size;
3121 peer_info.prcfg_bulk = list;
3124 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3125 count = peer_info.prcfg_count;
3129 if (l_errno != E2BIG) {
3132 "\"cannot get peer list: %s\"",
3138 size = peer_info.prcfg_size;
3139 list = malloc(size);
3146 /* count is now the actual number of ids in the list. */
3147 for (i = 0; i < count; i++) {
3148 if (cYAML_create_string(list_root, "nid",
3149 libcfs_nid2str(list[i].nid))
3154 /* print output iff show_rc is not provided */
3155 if (show_rc == NULL)
3156 cYAML_print_tree(root);
3158 snprintf(err_str, sizeof(err_str), "\"success\"");
3159 rc = LUSTRE_CFG_RC_NO_ERR;
3164 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3165 cYAML_free_tree(root);
3166 } else if (show_rc != NULL && *show_rc != NULL) {
3167 struct cYAML *show_node;
3168 /* find the peer node, if one doesn't exist then
3169 * insert one. Otherwise add to the one there
3171 show_node = cYAML_get_object_item(*show_rc,
3173 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3174 cYAML_insert_child(show_node, first_seq);
3177 } else if (show_node == NULL) {
3178 cYAML_insert_sibling((*show_rc)->cy_child,
3182 cYAML_free_tree(root);
3188 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3194 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3197 struct cYAML *show_node;
3199 show_node = cYAML_get_object_item(show_rc, "global");
3200 if (show_node != NULL)
3201 cYAML_insert_sibling(show_node->cy_child,
3204 cYAML_insert_sibling(show_rc->cy_child,
3209 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3210 char *name, __u64 value,
3211 struct cYAML **show_rc,
3212 struct cYAML **err_rc, int err)
3214 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3215 struct cYAML *root = NULL, *global = NULL;
3222 root = cYAML_create_object(NULL, NULL);
3226 global = cYAML_create_object(root, "global");
3230 if (cYAML_create_number(global, name,
3234 if (show_rc == NULL)
3235 cYAML_print_tree(root);
3237 snprintf(err_str, err_len, "\"success\"");
3239 rc = LUSTRE_CFG_RC_NO_ERR;
3242 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3243 cYAML_free_tree(root);
3244 } else if (show_rc != NULL && *show_rc != NULL) {
3245 add_to_global(*show_rc, global, root);
3250 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3255 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3256 struct cYAML **show_rc,
3257 struct cYAML **err_rc)
3259 struct lnet_ioctl_set_value data;
3262 char err_str[LNET_MAX_STR_LEN];
3264 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3266 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3268 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3273 "\"cannot get %s: %s\"",
3274 name, strerror(l_errno));
3277 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3278 data.sv_value, show_rc, err_rc, l_errno);
3281 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3282 struct cYAML **err_rc)
3284 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3285 char val[LNET_MAX_STR_LEN];
3286 int intrv = -1, l_errno = 0;
3287 char err_str[LNET_MAX_STR_LEN];
3289 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3291 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3295 snprintf(err_str, sizeof(err_str),
3296 "\"cannot get recovery interval: %d\"", rc);
3301 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3302 "recovery_interval", intrv, show_rc,
3306 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3307 struct cYAML **err_rc)
3309 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3310 char val[LNET_MAX_STR_LEN];
3311 int sen = -1, l_errno = 0;
3312 char err_str[LNET_MAX_STR_LEN];
3314 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3316 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3320 snprintf(err_str, sizeof(err_str),
3321 "\"cannot get health sensitivity: %d\"", rc);
3326 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3327 "health_sensitivity", sen, show_rc,
3331 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3332 struct cYAML **err_rc)
3334 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3335 char val[LNET_MAX_STR_LEN];
3336 int sen = -1, l_errno = 0;
3337 char err_str[LNET_MAX_STR_LEN];
3339 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3341 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3345 snprintf(err_str, sizeof(err_str),
3346 "\"cannot get router sensitivity percentage: %d\"", rc);
3351 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3352 "router_sensitivity", sen, show_rc,
3356 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3357 struct cYAML **err_rc)
3359 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3360 char val[LNET_MAX_STR_LEN];
3361 int tto = -1, l_errno = 0;
3362 char err_str[LNET_MAX_STR_LEN];
3364 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3366 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3370 snprintf(err_str, sizeof(err_str),
3371 "\"cannot get transaction timeout: %d\"", rc);
3376 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3377 "transaction_timeout", tto, show_rc,
3381 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3382 struct cYAML **err_rc)
3384 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3385 char val[LNET_MAX_STR_LEN];
3386 int retry_count = -1, l_errno = 0;
3387 char err_str[LNET_MAX_STR_LEN];
3389 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3391 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3395 snprintf(err_str, sizeof(err_str),
3396 "\"cannot get retry count: %d\"", rc);
3398 retry_count = atoi(val);
3401 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3402 "retry_count", retry_count, show_rc,
3406 int lustre_lnet_calc_service_id(__u64 *service_id)
3408 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3409 char val[LNET_MAX_STR_LEN];
3410 int service_port = -1, l_errno = 0;
3412 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3416 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3417 strerror(l_errno), -l_errno);
3420 service_port = atoi(val);
3423 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3425 return LUSTRE_CFG_RC_NO_ERR;
3428 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3429 struct cYAML **show_rc, struct cYAML **err_rc)
3431 struct lnet_ioctl_recovery_list nid_list;
3432 struct cYAML *root = NULL, *nids = NULL;
3434 char err_str[LNET_MAX_STR_LEN];
3436 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3438 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3439 nid_list.rlst_type = type;
3441 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3447 if (nid_list.rlst_num_nids == 0)
3450 root = cYAML_create_object(NULL, NULL);
3454 nids = cYAML_create_object(root, name);
3460 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3461 char nidenum[LNET_MAX_STR_LEN];
3462 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3463 if (!cYAML_create_string(nids, nidenum,
3464 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3468 snprintf(err_str, sizeof(err_str), "success\n");
3473 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3474 cYAML_free_tree(root);
3475 } else if (show_rc != NULL && *show_rc != NULL) {
3476 struct cYAML *show_node;
3477 /* find the net node, if one doesn't exist
3478 * then insert one. Otherwise add to the one there
3480 show_node = cYAML_get_object_item(*show_rc, name);
3481 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3482 cYAML_insert_child(show_node, nids);
3485 } else if (show_node == NULL) {
3486 cYAML_insert_sibling((*show_rc)->cy_child,
3490 cYAML_free_tree(root);
3496 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3501 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3502 struct cYAML **err_rc)
3504 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3505 seq_no, show_rc, err_rc);
3508 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3509 struct cYAML **err_rc)
3511 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3512 seq_no, show_rc, err_rc);
3515 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3516 struct cYAML **err_rc)
3518 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3519 char val[LNET_MAX_STR_LEN];
3520 int max_intf = -1, l_errno = 0;
3521 char err_str[LNET_MAX_STR_LEN];
3523 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3525 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3529 snprintf(err_str, sizeof(err_str),
3530 "\"cannot get max interfaces: %d\"", rc);
3532 max_intf = atoi(val);
3535 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3536 "max_intf", max_intf, show_rc,
3540 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3541 struct cYAML **err_rc)
3543 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3544 char val[LNET_MAX_STR_LEN];
3545 int discovery = -1, l_errno = 0;
3546 char err_str[LNET_MAX_STR_LEN];
3548 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3550 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3554 snprintf(err_str, sizeof(err_str),
3555 "\"cannot get discovery setting: %d\"", rc);
3558 * The kernel stores a discovery disabled value. User space
3559 * shows whether discovery is enabled. So the value must be
3562 discovery = !atoi(val);
3565 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3566 "discovery", discovery, show_rc,
3570 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3571 struct cYAML **err_rc)
3573 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3574 char val[LNET_MAX_STR_LEN];
3575 int drop_asym_route = -1, l_errno = 0;
3576 char err_str[LNET_MAX_STR_LEN];
3578 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3580 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3584 snprintf(err_str, sizeof(err_str),
3585 "\"cannot get drop asym route setting: %d\"", rc);
3587 drop_asym_route = atoi(val);
3590 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3591 "drop_asym_route", drop_asym_route,
3592 show_rc, err_rc, l_errno);
3595 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3596 struct cYAML **err_rc)
3598 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3599 "numa_range", show_rc, err_rc);
3602 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3603 struct cYAML **err_rc)
3605 struct lnet_ioctl_lnet_stats data;
3606 struct lnet_counters *cntrs;
3609 char err_str[LNET_MAX_STR_LEN];
3610 struct cYAML *root = NULL, *stats = NULL;
3612 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3614 LIBCFS_IOC_INIT_V2(data, st_hdr);
3616 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3621 "\"cannot get lnet statistics: %s\"",
3627 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3629 cntrs = &data.st_cntrs;
3631 root = cYAML_create_object(NULL, NULL);
3635 stats = cYAML_create_object(root, "statistics");
3639 if (!cYAML_create_number(stats, "msgs_alloc",
3640 cntrs->lct_common.lcc_msgs_alloc))
3643 if (!cYAML_create_number(stats, "msgs_max",
3644 cntrs->lct_common.lcc_msgs_max))
3647 if (!cYAML_create_number(stats, "rst_alloc",
3648 cntrs->lct_health.lch_rst_alloc))
3651 if (!cYAML_create_number(stats, "errors",
3652 cntrs->lct_common.lcc_errors))
3655 if (!cYAML_create_number(stats, "send_count",
3656 cntrs->lct_common.lcc_send_count))
3659 if (!cYAML_create_number(stats, "resend_count",
3660 cntrs->lct_health.lch_resend_count))
3663 if (!cYAML_create_number(stats, "response_timeout_count",
3664 cntrs->lct_health.lch_response_timeout_count))
3667 if (!cYAML_create_number(stats, "local_interrupt_count",
3668 cntrs->lct_health.lch_local_interrupt_count))
3671 if (!cYAML_create_number(stats, "local_dropped_count",
3672 cntrs->lct_health.lch_local_dropped_count))
3675 if (!cYAML_create_number(stats, "local_aborted_count",
3676 cntrs->lct_health.lch_local_aborted_count))
3679 if (!cYAML_create_number(stats, "local_no_route_count",
3680 cntrs->lct_health.lch_local_no_route_count))
3683 if (!cYAML_create_number(stats, "local_timeout_count",
3684 cntrs->lct_health.lch_local_timeout_count))
3687 if (!cYAML_create_number(stats, "local_error_count",
3688 cntrs->lct_health.lch_local_error_count))
3691 if (!cYAML_create_number(stats, "remote_dropped_count",
3692 cntrs->lct_health.lch_remote_dropped_count))
3695 if (!cYAML_create_number(stats, "remote_error_count",
3696 cntrs->lct_health.lch_remote_error_count))
3699 if (!cYAML_create_number(stats, "remote_timeout_count",
3700 cntrs->lct_health.lch_remote_timeout_count))
3703 if (!cYAML_create_number(stats, "network_timeout_count",
3704 cntrs->lct_health.lch_network_timeout_count))
3707 if (!cYAML_create_number(stats, "recv_count",
3708 cntrs->lct_common.lcc_recv_count))
3711 if (!cYAML_create_number(stats, "route_count",
3712 cntrs->lct_common.lcc_route_count))
3715 if (!cYAML_create_number(stats, "drop_count",
3716 cntrs->lct_common.lcc_drop_count))
3719 if (!cYAML_create_number(stats, "send_length",
3720 cntrs->lct_common.lcc_send_length))
3723 if (!cYAML_create_number(stats, "recv_length",
3724 cntrs->lct_common.lcc_recv_length))
3727 if (!cYAML_create_number(stats, "route_length",
3728 cntrs->lct_common.lcc_route_length))
3731 if (!cYAML_create_number(stats, "drop_length",
3732 cntrs->lct_common.lcc_drop_length))
3736 cYAML_print_tree(root);
3738 snprintf(err_str, sizeof(err_str), "\"success\"");
3739 rc = LUSTRE_CFG_RC_NO_ERR;
3741 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3742 cYAML_free_tree(root);
3743 } else if (show_rc != NULL && *show_rc != NULL) {
3744 cYAML_insert_sibling((*show_rc)->cy_child,
3751 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3756 typedef int (*cmd_handler_t)(struct cYAML *tree,
3757 struct cYAML **show_rc,
3758 struct cYAML **err_rc);
3760 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3761 struct cYAML **err_rc)
3763 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3765 net = cYAML_get_object_item(tree, "net");
3766 gw = cYAML_get_object_item(tree, "gateway");
3767 hop = cYAML_get_object_item(tree, "hop");
3768 prio = cYAML_get_object_item(tree, "priority");
3769 sen = cYAML_get_object_item(tree, "health_sensitivity");
3770 seq_no = cYAML_get_object_item(tree, "seq_no");
3772 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3773 (gw) ? gw->cy_valuestring : NULL,
3774 (hop) ? hop->cy_valueint : -1,
3775 (prio) ? prio->cy_valueint : -1,
3776 (sen) ? sen->cy_valueint : -1,
3777 (seq_no) ? seq_no->cy_valueint : -1,
3783 * 0: <intf_name>['['<expr>']']
3784 * 1: <intf_name>['['<expr>']']
3786 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3787 struct lnet_dlc_network_descr *nw_descr)
3789 struct cYAML *child = NULL;
3790 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3791 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3793 if (intf_tree == NULL || nw_descr == NULL)
3794 return LUSTRE_CFG_RC_BAD_PARAM;
3796 /* now grab all the interfaces and their cpts */
3797 child = intf_tree->cy_child;
3798 while (child != NULL) {
3799 if (child->cy_valuestring == NULL) {
3800 child = child->cy_next;
3804 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3807 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3808 child->cy_valuestring,
3809 strlen(child->cy_valuestring));
3810 if (rc != LUSTRE_CFG_RC_NO_ERR)
3814 child = child->cy_next;
3818 return LUSTRE_CFG_RC_MISSING_PARAM;
3823 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3825 list_del(&intf_descr->intf_on_network);
3826 free_intf_descr(intf_descr);
3833 yaml_extract_cmn_tunables(struct cYAML *tree,
3834 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3835 struct cfs_expr_list **global_cpts)
3837 struct cYAML *tun, *item, *smp;
3840 tun = cYAML_get_object_item(tree, "tunables");
3842 item = cYAML_get_object_item(tun, "peer_timeout");
3844 tunables->lct_peer_timeout = item->cy_valueint;
3845 item = cYAML_get_object_item(tun, "peer_credits");
3847 tunables->lct_peer_tx_credits = item->cy_valueint;
3848 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3850 tunables->lct_peer_rtr_credits = item->cy_valueint;
3851 item = cYAML_get_object_item(tun, "credits");
3853 tunables->lct_max_tx_credits = item->cy_valueint;
3854 smp = cYAML_get_object_item(tun, "CPT");
3856 rc = cfs_expr_list_parse(smp->cy_valuestring,
3857 strlen(smp->cy_valuestring),
3858 0, UINT_MAX, global_cpts);
3860 *global_cpts = NULL;
3870 yaml_extract_tunables(struct cYAML *tree,
3871 struct lnet_ioctl_config_lnd_tunables *tunables,
3872 struct cfs_expr_list **global_cpts,
3877 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3883 lustre_yaml_extract_lnd_tunables(tree, net_type,
3891 * - net type: <net>[<NUM>]
3893 * - nid: <ip>@<net>[<NUM>]
3896 * 0: <intf_name>['['<expr>']']
3897 * 1: <intf_name>['['<expr>']']
3899 * peer_timeout: <NUM>
3900 * peer_credits: <NUM>
3901 * peer_buffer_credits: <NUM>
3904 * peercredits_hiw: <NUM>
3905 * map_on_demand: <NUM>
3906 * concurrent_sends: <NUM>
3907 * fmr_pool_size: <NUM>
3908 * fmr_flush_trigger: <NUM>
3911 * At least one interface is required. If no interfaces are provided the
3912 * network interface can not be configured.
3914 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3915 struct cYAML **err_rc)
3917 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3919 int num_entries = 0, rc;
3920 struct lnet_dlc_network_descr nw_descr;
3921 struct cfs_expr_list *global_cpts = NULL;
3922 struct lnet_ioctl_config_lnd_tunables tunables;
3925 memset(&tunables, 0, sizeof(tunables));
3927 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3928 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3930 ip2net = cYAML_get_object_item(tree, "ip2net");
3931 net = cYAML_get_object_item(tree, "net type");
3933 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3935 nw_descr.nw_id = LOLND;
3938 * if neither net nor ip2nets are present, then we can not
3939 * configure the network.
3941 if (!net && !ip2net)
3942 return LUSTRE_CFG_RC_MISSING_PARAM;
3944 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3945 if (local_nis == NULL)
3946 return LUSTRE_CFG_RC_MISSING_PARAM;
3948 if (!cYAML_is_sequence(local_nis))
3949 return LUSTRE_CFG_RC_BAD_PARAM;
3951 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3952 intf = cYAML_get_object_item(item, "interfaces");
3955 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3956 if (num_entries <= 0) {
3957 cYAML_build_error(num_entries, -1, "ni", "add",
3958 "bad interface list",
3960 return LUSTRE_CFG_RC_BAD_PARAM;
3964 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3965 LNET_NETTYP(nw_descr.nw_id));
3966 seq_no = cYAML_get_object_item(tree, "seq_no");
3968 rc = lustre_lnet_config_ni(&nw_descr,
3970 (ip2net) ? ip2net->cy_valuestring : NULL,
3971 (found) ? &tunables: NULL,
3972 (seq_no) ? seq_no->cy_valueint : -1,
3975 if (global_cpts != NULL)
3976 cfs_expr_list_free(global_cpts);
3983 * - net-spec: <tcp|o2ib|gni>[NUM]
3985 * 0: <intf name>['['<expr>']']
3986 * 1: <intf name>['['<expr>']']
3988 * 0: <expr.expr.expr.expr>
3989 * 1: <expr.expr.expr.expr>
3991 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3992 struct cYAML **show_rc,
3993 struct cYAML **err_rc)
3995 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3997 struct lustre_lnet_ip2nets ip2nets;
3998 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4000 int rc = LUSTRE_CFG_RC_NO_ERR;
4001 struct cfs_expr_list *global_cpts = NULL;
4002 struct cfs_expr_list *el, *el_tmp;
4003 struct lnet_ioctl_config_lnd_tunables tunables;
4004 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4007 memset(&tunables, 0, sizeof(tunables));
4009 /* initialize all lists */
4010 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4011 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4012 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4014 net = cYAML_get_object_item(tree, "net-spec");
4016 return LUSTRE_CFG_RC_BAD_PARAM;
4018 if (net != NULL && net->cy_valuestring == NULL)
4019 return LUSTRE_CFG_RC_BAD_PARAM;
4021 /* assign the network id */
4022 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4023 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4024 return LUSTRE_CFG_RC_BAD_PARAM;
4026 seq_no = cYAML_get_object_item(tree, "seq_no");
4028 intf = cYAML_get_object_item(tree, "interfaces");
4030 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4032 return LUSTRE_CFG_RC_BAD_PARAM;
4035 ip_range = cYAML_get_object_item(tree, "ip-range");
4036 if (ip_range != NULL) {
4037 item = ip_range->cy_child;
4038 while (item != NULL) {
4039 if (item->cy_valuestring == NULL) {
4040 item = item->cy_next;
4044 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4045 item->cy_valuestring);
4047 if (rc != LUSTRE_CFG_RC_NO_ERR)
4050 item = item->cy_next;
4054 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4055 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4057 rc = lustre_lnet_config_ip2nets(&ip2nets,
4058 (found) ? &tunables : NULL,
4060 (seq_no) ? seq_no->cy_valueint : -1,
4064 * don't stop because there was no match. Continue processing the
4065 * rest of the rules. If non-match then nothing is configured
4067 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4068 rc = LUSTRE_CFG_RC_NO_ERR;
4070 list_for_each_entry_safe(intf_descr, intf_tmp,
4071 &ip2nets.ip2nets_net.nw_intflist,
4073 list_del(&intf_descr->intf_on_network);
4074 free_intf_descr(intf_descr);
4077 list_for_each_entry_safe(ip_range_descr, tmp,
4078 &ip2nets.ip2nets_ip_ranges,
4080 list_del(&ip_range_descr->ipr_entry);
4081 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4083 list_del(&el->el_link);
4084 cfs_expr_list_free(el);
4086 free(ip_range_descr);
4092 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4093 struct cYAML **err_rc)
4095 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4097 int num_entries, rc;
4098 struct lnet_dlc_network_descr nw_descr;
4100 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4101 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4103 net = cYAML_get_object_item(tree, "net type");
4105 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4107 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4108 if (local_nis == NULL)
4109 return LUSTRE_CFG_RC_MISSING_PARAM;
4111 if (!cYAML_is_sequence(local_nis))
4112 return LUSTRE_CFG_RC_BAD_PARAM;
4114 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4115 intf = cYAML_get_object_item(item, "interfaces");
4118 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4119 if (num_entries <= 0) {
4120 cYAML_build_error(num_entries, -1, "ni", "add",
4121 "bad interface list",
4123 return LUSTRE_CFG_RC_BAD_PARAM;
4127 seq_no = cYAML_get_object_item(tree, "seq_no");
4129 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4130 (seq_no) ? seq_no->cy_valueint : -1,
4136 /* Create a nidstring parseable by the nidstrings library from the nid
4137 * information encoded in the CYAML structure.
4138 * NOTE: Caller must free memory allocated to nidstr
4140 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4141 char *prim_nid, int cmd)
4143 int num_strs = 0, rc;
4144 size_t buf_size, buf_pos, nidstr_len = 0;
4146 struct cYAML *child = NULL, *entry = NULL;
4148 if (cYAML_is_sequence(nids_entry)) {
4149 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4150 entry = cYAML_get_object_item(child, "nid");
4151 /* don't count an empty entry */
4152 if (!entry || !entry->cy_valuestring)
4156 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4157 if (cmd == LNETCTL_DEL_CMD) {
4159 * primary nid is present in the list of
4160 * nids so that means we want to delete
4161 * the entire peer, so no need to go
4162 * further. Just delete the entire peer.
4164 return LUSTRE_CFG_RC_NO_ERR;
4171 * + 1 for the space separating each string, and
4172 * accounts for the terminating null char
4174 nidstr_len += strlen(entry->cy_valuestring) + 1;
4179 if (num_strs == 0 && !prim_nid)
4180 return LUSTRE_CFG_RC_MISSING_PARAM;
4181 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4182 return LUSTRE_CFG_RC_NO_ERR;
4184 buffer = malloc(nidstr_len);
4186 return LUSTRE_CFG_RC_OUT_OF_MEM;
4188 /* now grab all the nids */
4191 buf_size = nidstr_len;
4193 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4194 entry = cYAML_get_object_item(child, "nid");
4195 if (!entry || !entry->cy_valuestring)
4199 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4203 rc = snprintf(buffer + buf_pos, buf_size, " ");
4204 buf_pos += (rc < buf_size) ? rc : buf_size;
4205 buf_size = nidstr_len - buf_pos;
4208 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4209 entry->cy_valuestring);
4210 buf_pos += (rc < buf_size) ? rc : buf_size;
4211 buf_size = nidstr_len - buf_pos;
4216 return LUSTRE_CFG_RC_NO_ERR;
4219 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4220 struct cYAML **err_rc, int cmd)
4222 int rc, num_nids = 0, seqn;
4224 char *nidstr = NULL, *prim_nidstr;
4225 char err_str[LNET_MAX_STR_LEN];
4226 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4227 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4229 seq_no = cYAML_get_object_item(tree, "seq_no");
4230 seqn = seq_no ? seq_no->cy_valueint : -1;
4232 prim_nid = cYAML_get_object_item(tree, "primary nid");
4233 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4235 peer_nis = cYAML_get_object_item(tree, "peer ni");
4236 if (!(prim_nid || peer_nis)) {
4237 rc = LUSTRE_CFG_RC_BAD_PARAM;
4238 snprintf(err_str, LNET_MAX_STR_LEN,
4239 "Neither \"primary nid\" nor \"peer ni\" are defined");
4243 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4244 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4245 snprintf(err_str, LNET_MAX_STR_LEN,
4246 "No nids defined in YAML block");
4248 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4249 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4251 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4252 snprintf(err_str, LNET_MAX_STR_LEN,
4253 "Unrecognized error %d", rc);
4259 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4260 LNET_MAX_NIDS_PER_PEER,
4268 if (cmd == LNETCTL_ADD_CMD) {
4269 mr = cYAML_get_object_item(tree, "Multi-Rail");
4271 if (mr && mr->cy_valuestring) {
4272 if (strcmp(mr->cy_valuestring, "False") == 0)
4274 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4275 rc = LUSTRE_CFG_RC_BAD_PARAM;
4276 snprintf(err_str, LNET_MAX_STR_LEN,
4277 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4278 mr->cy_valuestring);
4283 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4284 num_nids, mr_value, seqn,
4287 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4288 num_nids, seqn, err_rc);
4294 if (rc != LUSTRE_CFG_RC_NO_ERR)
4295 cYAML_build_error(rc, seqn, "peer",
4296 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4302 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4303 struct cYAML **err_rc)
4305 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4308 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4309 struct cYAML **err_rc)
4311 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4314 static int handle_yaml_config_buffers(struct cYAML *tree,
4315 struct cYAML **show_rc,
4316 struct cYAML **err_rc)
4319 struct cYAML *tiny, *small, *large, *seq_no;
4321 tiny = cYAML_get_object_item(tree, "tiny");
4322 small = cYAML_get_object_item(tree, "small");
4323 large = cYAML_get_object_item(tree, "large");
4324 seq_no = cYAML_get_object_item(tree, "seq_no");
4326 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4327 (small) ? small->cy_valueint : -1,
4328 (large) ? large->cy_valueint : -1,
4329 (seq_no) ? seq_no->cy_valueint : -1,
4335 static int handle_yaml_config_routing(struct cYAML *tree,
4336 struct cYAML **show_rc,
4337 struct cYAML **err_rc)
4339 int rc = LUSTRE_CFG_RC_NO_ERR;
4340 struct cYAML *seq_no, *enable;
4342 seq_no = cYAML_get_object_item(tree, "seq_no");
4343 enable = cYAML_get_object_item(tree, "enable");
4346 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4348 seq_no->cy_valueint : -1,
4355 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4356 struct cYAML **err_rc)
4360 struct cYAML *seq_no;
4362 net = cYAML_get_object_item(tree, "net");
4363 gw = cYAML_get_object_item(tree, "gateway");
4364 seq_no = cYAML_get_object_item(tree, "seq_no");
4366 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4367 (gw) ? gw->cy_valuestring : NULL,
4368 (seq_no) ? seq_no->cy_valueint : -1,
4372 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4373 struct cYAML **err_rc)
4375 struct cYAML *seq_no;
4377 seq_no = cYAML_get_object_item(tree, "seq_no");
4379 return lustre_lnet_enable_routing(0, (seq_no) ?
4380 seq_no->cy_valueint : -1,
4384 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4385 struct cYAML **err_rc)
4391 struct cYAML *detail;
4392 struct cYAML *seq_no;
4394 net = cYAML_get_object_item(tree, "net");
4395 gw = cYAML_get_object_item(tree, "gateway");
4396 hop = cYAML_get_object_item(tree, "hop");
4397 prio = cYAML_get_object_item(tree, "priority");
4398 detail = cYAML_get_object_item(tree, "detail");
4399 seq_no = cYAML_get_object_item(tree, "seq_no");
4401 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4402 (gw) ? gw->cy_valuestring : NULL,
4403 (hop) ? hop->cy_valueint : -1,
4404 (prio) ? prio->cy_valueint : -1,
4405 (detail) ? detail->cy_valueint : 0,
4406 (seq_no) ? seq_no->cy_valueint : -1,
4407 show_rc, err_rc, false);
4410 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4411 struct cYAML **err_rc)
4413 struct cYAML *net, *detail, *seq_no;
4415 net = cYAML_get_object_item(tree, "net");
4416 detail = cYAML_get_object_item(tree, "detail");
4417 seq_no = cYAML_get_object_item(tree, "seq_no");
4419 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4420 (detail) ? detail->cy_valueint : 0,
4421 (seq_no) ? seq_no->cy_valueint : -1,
4422 show_rc, err_rc, false);
4425 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4426 struct cYAML **err_rc)
4428 struct cYAML *seq_no;
4430 seq_no = cYAML_get_object_item(tree, "seq_no");
4432 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4433 show_rc, err_rc, false);
4436 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4437 struct cYAML **err_rc)
4439 struct cYAML *seq_no, *nid, *detail;
4441 seq_no = cYAML_get_object_item(tree, "seq_no");
4442 detail = cYAML_get_object_item(tree, "detail");
4443 nid = cYAML_get_object_item(tree, "nid");
4445 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4446 (detail) ? detail->cy_valueint : 0,
4447 (seq_no) ? seq_no->cy_valueint : -1,
4448 show_rc, err_rc, false);
4451 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4452 struct cYAML **err_rc)
4454 struct cYAML *seq_no;
4456 seq_no = cYAML_get_object_item(tree, "seq_no");
4458 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4462 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4463 struct cYAML **err_rc)
4465 struct cYAML *seq_no, *range;
4467 seq_no = cYAML_get_object_item(tree, "seq_no");
4468 range = cYAML_get_object_item(tree, "range");
4470 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4471 seq_no ? seq_no->cy_valueint : -1,
4475 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4476 struct cYAML **err_rc)
4478 struct cYAML *seq_no;
4480 seq_no = cYAML_get_object_item(tree, "seq_no");
4482 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4486 static int handle_yaml_show_numa(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_numa_range(seq_no ? seq_no->cy_valueint : -1,
4497 static int handle_yaml_config_global_settings(struct cYAML *tree,
4498 struct cYAML **show_rc,
4499 struct cYAML **err_rc)
4501 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4502 *sen, *recov, *rsen, *drop_asym_route;
4505 seq_no = cYAML_get_object_item(tree, "seq_no");
4506 max_intf = cYAML_get_object_item(tree, "max_intf");
4508 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4509 seq_no ? seq_no->cy_valueint
4513 numa = cYAML_get_object_item(tree, "numa_range");
4515 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4516 seq_no ? seq_no->cy_valueint
4520 discovery = cYAML_get_object_item(tree, "discovery");
4522 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4523 seq_no ? seq_no->cy_valueint
4527 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4528 if (drop_asym_route)
4529 rc = lustre_lnet_config_drop_asym_route(
4530 drop_asym_route->cy_valueint,
4531 seq_no ? seq_no->cy_valueint : -1,
4534 retry = cYAML_get_object_item(tree, "retry_count");
4536 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4537 seq_no ? seq_no->cy_valueint
4541 tto = cYAML_get_object_item(tree, "transaction_timeout");
4543 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4544 seq_no ? seq_no->cy_valueint
4548 sen = cYAML_get_object_item(tree, "health_sensitivity");
4550 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4551 seq_no ? seq_no->cy_valueint
4555 recov = cYAML_get_object_item(tree, "recovery_interval");
4557 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4558 seq_no ? seq_no->cy_valueint
4562 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4564 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4565 seq_no ? seq_no->cy_valueint
4572 static int handle_yaml_del_global_settings(struct cYAML *tree,
4573 struct cYAML **show_rc,
4574 struct cYAML **err_rc)
4576 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4579 seq_no = cYAML_get_object_item(tree, "seq_no");
4580 max_intf = cYAML_get_object_item(tree, "max_intf");
4582 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4583 seq_no ? seq_no->cy_valueint
4587 numa = cYAML_get_object_item(tree, "numa_range");
4589 rc = lustre_lnet_config_numa_range(0,
4590 seq_no ? seq_no->cy_valueint
4594 /* peer discovery is enabled by default */
4595 discovery = cYAML_get_object_item(tree, "discovery");
4597 rc = lustre_lnet_config_discovery(1,
4598 seq_no ? seq_no->cy_valueint
4602 /* asymmetrical route messages are accepted by default */
4603 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4604 if (drop_asym_route)
4605 rc = lustre_lnet_config_drop_asym_route(
4606 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4611 static int handle_yaml_show_global_settings(struct cYAML *tree,
4612 struct cYAML **show_rc,
4613 struct cYAML **err_rc)
4615 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4616 *sen, *recov, *rsen, *drop_asym_route;
4619 seq_no = cYAML_get_object_item(tree, "seq_no");
4620 max_intf = cYAML_get_object_item(tree, "max_intf");
4622 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4626 numa = cYAML_get_object_item(tree, "numa_range");
4628 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4632 discovery = cYAML_get_object_item(tree, "discovery");
4634 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4638 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4639 if (drop_asym_route)
4640 rc = lustre_lnet_show_drop_asym_route(
4641 seq_no ? seq_no->cy_valueint : -1,
4644 retry = cYAML_get_object_item(tree, "retry_count");
4646 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4650 tto = cYAML_get_object_item(tree, "transaction_timeout");
4652 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4656 sen = cYAML_get_object_item(tree, "health_sensitivity");
4658 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4662 recov = cYAML_get_object_item(tree, "recovery_interval");
4664 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4668 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4670 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4677 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4678 struct cYAML **err_rc)
4680 struct cYAML *seq_no, *nid, *timeout;
4682 seq_no = cYAML_get_object_item(tree, "seq_no");
4683 nid = cYAML_get_object_item(tree, "primary nid");
4684 timeout = cYAML_get_object_item(tree, "timeout");
4686 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4687 (timeout) ? timeout->cy_valueint : 1000,
4688 (seq_no) ? seq_no->cy_valueint : -1,
4692 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4693 struct cYAML **err_rc)
4695 struct cYAML *seq_no, *nid, *force;
4697 seq_no = cYAML_get_object_item(tree, "seq_no");
4698 nid = cYAML_get_object_item(tree, "primary nid");
4699 force = cYAML_get_object_item(tree, "force");
4701 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4702 (force) ? force->cy_valueint : 0,
4703 (seq_no) ? seq_no->cy_valueint : -1,
4707 static int handle_yaml_no_op()
4709 return LUSTRE_CFG_RC_NO_ERR;
4712 struct lookup_cmd_hdlr_tbl {
4717 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4718 { .name = "route", .cb = handle_yaml_config_route },
4719 { .name = "net", .cb = handle_yaml_config_ni },
4720 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4721 { .name = "peer", .cb = handle_yaml_config_peer },
4722 { .name = "routing", .cb = handle_yaml_config_routing },
4723 { .name = "buffers", .cb = handle_yaml_config_buffers },
4724 { .name = "statistics", .cb = handle_yaml_no_op },
4725 { .name = "global", .cb = handle_yaml_config_global_settings},
4726 { .name = "numa", .cb = handle_yaml_config_numa },
4727 { .name = "ping", .cb = handle_yaml_no_op },
4728 { .name = "discover", .cb = handle_yaml_no_op },
4731 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4732 { .name = "route", .cb = handle_yaml_del_route },
4733 { .name = "net", .cb = handle_yaml_del_ni },
4734 { .name = "ip2nets", .cb = handle_yaml_no_op },
4735 { .name = "peer", .cb = handle_yaml_del_peer },
4736 { .name = "routing", .cb = handle_yaml_del_routing },
4737 { .name = "buffers", .cb = handle_yaml_no_op },
4738 { .name = "statistics", .cb = handle_yaml_no_op },
4739 { .name = "global", .cb = handle_yaml_del_global_settings},
4740 { .name = "numa", .cb = handle_yaml_del_numa },
4741 { .name = "ping", .cb = handle_yaml_no_op },
4742 { .name = "discover", .cb = handle_yaml_no_op },
4745 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4746 { .name = "route", .cb = handle_yaml_show_route },
4747 { .name = "net", .cb = handle_yaml_show_net },
4748 { .name = "peer", .cb = handle_yaml_show_peers },
4749 { .name = "ip2nets", .cb = handle_yaml_no_op },
4750 { .name = "routing", .cb = handle_yaml_show_routing },
4751 { .name = "buffers", .cb = handle_yaml_show_routing },
4752 { .name = "statistics", .cb = handle_yaml_show_stats },
4753 { .name = "global", .cb = handle_yaml_show_global_settings},
4754 { .name = "numa", .cb = handle_yaml_show_numa },
4755 { .name = "ping", .cb = handle_yaml_no_op },
4756 { .name = "discover", .cb = handle_yaml_no_op },
4759 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4760 { .name = "route", .cb = handle_yaml_no_op },
4761 { .name = "net", .cb = handle_yaml_no_op },
4762 { .name = "peer", .cb = handle_yaml_no_op },
4763 { .name = "ip2nets", .cb = handle_yaml_no_op },
4764 { .name = "routing", .cb = handle_yaml_no_op },
4765 { .name = "buffers", .cb = handle_yaml_no_op },
4766 { .name = "statistics", .cb = handle_yaml_no_op },
4767 { .name = "global", .cb = handle_yaml_no_op },
4768 { .name = "numa", .cb = handle_yaml_no_op },
4769 { .name = "ping", .cb = handle_yaml_ping },
4770 { .name = "discover", .cb = handle_yaml_discover },
4773 static cmd_handler_t lookup_fn(char *key,
4774 struct lookup_cmd_hdlr_tbl *tbl)
4780 for (i = 0; tbl[i].name != NULL; i++) {
4781 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4788 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4789 struct cYAML **show_rc, struct cYAML **err_rc)
4791 struct cYAML *tree, *item = NULL, *head, *child;
4793 char err_str[LNET_MAX_STR_LEN];
4794 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4796 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4798 return LUSTRE_CFG_RC_BAD_PARAM;
4800 child = tree->cy_child;
4801 while (child != NULL) {
4802 cb = lookup_fn(child->cy_string, table);
4804 snprintf(err_str, sizeof(err_str),
4805 "\"call back for '%s' not found\"",
4807 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4808 "yaml", "helper", err_str, err_rc);
4812 if (cYAML_is_sequence(child)) {
4813 while ((head = cYAML_get_next_seq_item(child, &item))
4815 rc = cb(head, show_rc, err_rc);
4816 if (rc != LUSTRE_CFG_RC_NO_ERR)
4820 rc = cb(child, show_rc, err_rc);
4821 if (rc != LUSTRE_CFG_RC_NO_ERR)
4825 child = child->cy_next;
4829 cYAML_free_tree(tree);
4834 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4836 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4840 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4842 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4846 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4848 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4852 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4854 return lustre_yaml_cb_helper(f, lookup_exec_tbl,