4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #ifndef HAVE_USRSPC_RDMA_PS_TCP
59 #define RDMA_PS_TCP 0x0106
62 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
66 * lustre_lnet_ip_range_descr
67 * Describes an IP range.
68 * Each octect is an expression
70 struct lustre_lnet_ip_range_descr {
71 struct list_head ipr_entry;
72 struct list_head ipr_expr;
77 * Describes an ip2nets rule. This can be on a list of rules.
79 struct lustre_lnet_ip2nets {
80 struct lnet_dlc_network_descr ip2nets_net;
81 struct list_head ip2nets_ip_ranges;
84 int open_sysfs_file(const char *path, const char *attr, const int mode)
87 char filename[LNET_MAX_STR_LEN];
89 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
92 snprintf(filename, sizeof(filename), "%s%s",
95 fd = open(filename, mode);
100 static int read_sysfs_file(const char *path, const char *attr,
101 void *val, const size_t size, const int nelem)
104 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
106 fd = open_sysfs_file(path, attr, O_RDONLY);
108 return LUSTRE_CFG_RC_NO_MATCH;
110 if (read(fd, val, size * nelem) == -1)
113 rc = LUSTRE_CFG_RC_NO_ERR;
120 static int write_sysfs_file(const char *path, const char *attr,
121 void *val, const size_t size, const int nelem)
124 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
126 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
128 return LUSTRE_CFG_RC_NO_MATCH;
130 if (write(fd, val, size * nelem) == -1)
133 rc = LUSTRE_CFG_RC_NO_ERR;
142 * frees the memory allocated for an intf descriptor.
144 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
149 if (intf_descr->cpt_expr != NULL)
150 cfs_expr_list_free(intf_descr->cpt_expr);
155 * lustre_lnet_add_ip_range
157 * given a string of the format:
158 * <expr.expr.expr.expr> parse each expr into
159 * a lustre_lnet_ip_range_descr structure and insert on the list.
161 * This function is called from
162 * YAML on each ip-range.
163 * As a result of lnetctl command
164 * When building a NID or P2P selection rules
166 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
168 struct lustre_lnet_ip_range_descr *ip_range;
171 ip_range = calloc(1, sizeof(*ip_range));
172 if (ip_range == NULL)
173 return LUSTRE_CFG_RC_OUT_OF_MEM;
175 INIT_LIST_HEAD(&ip_range->ipr_entry);
176 INIT_LIST_HEAD(&ip_range->ipr_expr);
178 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
179 &ip_range->ipr_expr);
181 return LUSTRE_CFG_RC_BAD_PARAM;
183 list_add_tail(&ip_range->ipr_entry, list);
185 return LUSTRE_CFG_RC_NO_ERR;
188 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
190 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
192 struct lnet_dlc_intf_descr *intf_descr = NULL;
194 char intf_string[LNET_MAX_STR_LEN];
196 if (len >= LNET_MAX_STR_LEN)
197 return LUSTRE_CFG_RC_BAD_PARAM;
199 strncpy(intf_string, intf, len);
200 intf_string[len] = '\0';
202 intf_descr = calloc(1, sizeof(*intf_descr));
203 if (intf_descr == NULL)
204 return LUSTRE_CFG_RC_OUT_OF_MEM;
206 INIT_LIST_HEAD(&intf_descr->intf_on_network);
208 intf_name = intf_string;
209 open_sq_bracket = strchr(intf_string, '[');
210 if (open_sq_bracket != NULL) {
211 close_sq_bracket = strchr(intf_string, ']');
212 if (close_sq_bracket == NULL) {
214 return LUSTRE_CFG_RC_BAD_PARAM;
216 rc = cfs_expr_list_parse(open_sq_bracket,
217 strlen(open_sq_bracket), 0, UINT_MAX,
218 &intf_descr->cpt_expr);
221 return LUSTRE_CFG_RC_BAD_PARAM;
223 strncpy(intf_descr->intf_name, intf_name,
224 open_sq_bracket - intf_name);
225 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
227 strcpy(intf_descr->intf_name, intf_name);
228 intf_descr->cpt_expr = NULL;
231 list_add_tail(&intf_descr->intf_on_network, list);
233 return LUSTRE_CFG_RC_NO_ERR;
236 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
238 if (nw_descr != NULL) {
240 INIT_LIST_HEAD(&nw_descr->network_on_rule);
241 INIT_LIST_HEAD(&nw_descr->nw_intflist);
245 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
246 int max_nids, char *err_str)
248 int rc, num_nids = 0;
249 struct list_head nidlist;
252 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
253 return LUSTRE_CFG_RC_BAD_PARAM;
256 if (strchr(nidstr, '*')) {
257 snprintf(err_str, LNET_MAX_STR_LEN,
258 "asterisk not allowed in nidstring \"%s\"", nidstr);
259 return LUSTRE_CFG_RC_BAD_PARAM;
262 INIT_LIST_HEAD(&nidlist);
263 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
265 snprintf(err_str, LNET_MAX_STR_LEN,
266 "Unable to parse nidlist from: %s\n", nidstr);
267 return LUSTRE_CFG_RC_BAD_PARAM;
270 if (list_empty(&nidlist)) {
271 snprintf(err_str, LNET_MAX_STR_LEN,
272 "\"%s\" does not specify any valid nid lists", nidstr);
273 return LUSTRE_CFG_RC_BAD_PARAM;
276 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
277 cfs_free_nidlist(&nidlist);
279 if (num_nids == -1) {
280 snprintf(err_str, LNET_MAX_STR_LEN,
281 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
283 return LUSTRE_CFG_RC_BAD_PARAM;
287 snprintf(err_str, LNET_MAX_STR_LEN,
288 "Failed to expand nidstr: %s", strerror(num_nids));
289 return LUSTRE_CFG_RC_OUT_OF_MEM;
293 snprintf(err_str, LNET_MAX_STR_LEN,
294 "\"%s\" did not expand to any nids", nidstr);
295 return LUSTRE_CFG_RC_BAD_PARAM;
303 * <intf>[<expr>], <intf>[<expr>],..
305 int lustre_lnet_parse_interfaces(char *intf_str,
306 struct lnet_dlc_network_descr *nw_descr)
311 char *cur = intf_str, *next = NULL;
312 char *end = intf_str + strlen(intf_str);
314 struct lnet_dlc_intf_descr *intf_descr, *tmp;
316 if (nw_descr == NULL)
317 return LUSTRE_CFG_RC_BAD_PARAM;
320 open_square = strchr(cur, '[');
321 if (open_square != NULL) {
322 close_square = strchr(cur, ']');
323 if (close_square == NULL) {
324 rc = LUSTRE_CFG_RC_BAD_PARAM;
328 comma = strchr(cur, ',');
329 if (comma != NULL && comma > close_square) {
331 len = next - close_square;
337 comma = strchr(cur, ',');
347 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
348 if (rc != LUSTRE_CFG_RC_NO_ERR)
354 return LUSTRE_CFG_RC_NO_ERR;
357 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
359 list_del(&intf_descr->intf_on_network);
360 free_intf_descr(intf_descr);
366 int lustre_lnet_config_lib_init(void)
368 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
371 void lustre_lnet_config_lib_uninit(void)
373 unregister_ioc_dev(LNET_DEV_ID);
376 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
377 int seq_no, struct cYAML **err_rc)
379 struct libcfs_ioctl_data data;
382 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
384 LIBCFS_IOC_INIT(data);
386 /* Reverse logic is used here in order not to change
387 * the lctl utility */
388 data.ioc_flags = load_ni_from_mod ? 0 : 1;
390 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
392 rc = l_ioctl(LNET_DEV_ID, opc, &data);
396 "\"LNet %s error: %s\"", (up) ? "configure" :
397 "unconfigure", strerror(errno));
401 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
402 "lnet", err_str, err_rc);
407 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
408 char *err_str, char *cmd_str)
412 rc = l_ioctl(LNET_DEV_ID, cmd, data);
415 snprintf(err_str, LNET_MAX_STR_LEN,
416 "\"%s peer ni operation failed: %s\"",
417 cmd_str, strerror(errno));
423 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
424 int param, int ioc_call, int seq_no,
425 struct cYAML **show_rc, struct cYAML **err_rc)
428 struct lnet_ioctl_ping_data ping;
429 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
430 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
431 struct lnet_process_id id;
432 char err_str[LNET_MAX_STR_LEN] = {0};
433 char *sep, *token, *end;
436 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
441 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
443 data = calloc(1, len);
447 /* create struct cYAML root object */
448 root = cYAML_create_object(NULL, NULL);
452 ping_node = cYAML_create_seq(root, oper);
453 if (ping_node == NULL)
457 src = libcfs_str2nid(src_nidstr);
458 if (src == LNET_NID_ANY) {
459 snprintf(err_str, sizeof(err_str),
460 "\"cannot parse source NID '%s'\"",
462 rc = LUSTRE_CFG_RC_BAD_PARAM;
463 cYAML_build_error(rc, seq_no, MANAGE_CMD,
464 oper, err_str, err_rc);
471 /* tokenise each nid in string ping_nids */
472 token = strtok(ping_nids, ",");
475 item = cYAML_create_seq_item(ping_node);
479 if (first_seq == NULL)
482 /* check if '-' is a part of NID, token */
483 sep = strchr(token, '-');
485 id.pid = LNET_PID_ANY;
486 /* if no net is specified, libcfs_str2nid() will assume tcp */
487 id.nid = libcfs_str2nid(token);
488 if (id.nid == LNET_NID_ANY) {
489 snprintf(err_str, sizeof(err_str),
490 "\"cannot parse NID '%s'\"",
492 rc = LUSTRE_CFG_RC_BAD_PARAM;
493 cYAML_build_error(rc, seq_no, MANAGE_CMD,
494 oper, err_str, err_rc);
498 if (token[0] == 'u' || token[0] == 'U')
499 id.pid = (strtoul(&token[1], &end, 0) |
500 (LNET_PID_USERFLAG));
502 id.pid = strtoul(token, &end, 0);
504 /* assuming '-' is part of hostname */
506 id.pid = LNET_PID_ANY;
507 id.nid = libcfs_str2nid(token);
508 if (id.nid == LNET_NID_ANY) {
509 snprintf(err_str, sizeof(err_str),
510 "\"cannot parse NID '%s'\"",
512 rc = LUSTRE_CFG_RC_BAD_PARAM;
513 cYAML_build_error(rc, seq_no, MANAGE_CMD,
519 id.nid = libcfs_str2nid(sep + 1);
520 if (id.nid == LNET_NID_ANY) {
521 snprintf(err_str, sizeof(err_str),
522 "\"cannot parse NID '%s'\"",
524 rc = LUSTRE_CFG_RC_BAD_PARAM;
525 cYAML_build_error(rc, seq_no, MANAGE_CMD,
532 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
533 ping.ping_hdr.ioc_len = sizeof(ping);
536 ping.op_param = param;
537 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
538 ping.ping_buf = data;
540 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
543 sizeof(err_str), "failed to %s %s: %s\n", oper,
544 id.pid == LNET_PID_ANY ?
545 libcfs_nid2str(id.nid) :
546 libcfs_id2str(id), strerror(errno));
547 rc = LUSTRE_CFG_RC_BAD_PARAM;
548 cYAML_build_error(rc, seq_no, MANAGE_CMD,
549 oper, err_str, err_rc);
553 if (cYAML_create_string(item, "primary nid",
554 libcfs_nid2str(ping.ping_id.nid)) == NULL)
557 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
558 "True" : "False") == NULL)
561 tmp = cYAML_create_seq(item, "peer ni");
565 for (i = 0; i < ping.ping_count; i++) {
566 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
568 peer_ni = cYAML_create_seq_item(tmp);
571 memset(buf, 0, sizeof buf);
572 snprintf(buf, sizeof buf, "nid");
573 if (cYAML_create_string(peer_ni, buf,
574 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
580 } while ((token = strtok(NULL, ",")) != NULL);
583 rc = LUSTRE_CFG_RC_NO_ERR;
588 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
589 cYAML_free_tree(root);
590 } else if (show_rc != NULL && *show_rc != NULL) {
591 struct cYAML *show_node;
592 show_node = cYAML_get_object_item(*show_rc, oper);
593 if (show_node != NULL && cYAML_is_sequence(show_node)) {
594 cYAML_insert_child(show_node, first_seq);
597 } else if (show_node == NULL) {
598 cYAML_insert_sibling((*show_rc)->cy_child,
602 cYAML_free_tree(root);
611 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
612 int seq_no, struct cYAML **show_rc,
613 struct cYAML **err_rc)
617 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
618 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
622 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
623 struct cYAML **show_rc, struct cYAML **err_rc)
627 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
628 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
632 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
633 bool is_mr, __u32 cmd,
634 char *cmd_type, char *err_str)
636 struct lnet_ioctl_peer_cfg data;
639 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
640 /* When adding a peer we first need to create the peer using the
641 * specified (or implied) primary nid. Then we can add
642 * additional nids to this peer using the primary nid as a key
644 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
645 data.prcfg_mr = is_mr;
646 data.prcfg_prim_nid = nidlist[0];
647 data.prcfg_cfg_nid = LNET_NID_ANY;
649 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
655 /* Add or delete any specified NIs associated with the specified
656 * (or implied) primary nid
658 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
659 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
660 data.prcfg_mr = is_mr;
661 data.prcfg_prim_nid = nidlist[0];
662 data.prcfg_cfg_nid = nidlist[nid_idx];
664 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
670 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
671 /* In the delete case we may have been given just the
672 * primary nid of the peer. This tells us to delete the peer
673 * completely (rather than just delete some of its NIs)
675 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
676 data.prcfg_prim_nid = nidlist[0];
677 data.prcfg_cfg_nid = LNET_NID_ANY;
679 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
686 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
687 int cmd, int num_nids, bool is_mr, int seq_no,
688 struct cYAML **err_rc)
690 int rc = LUSTRE_CFG_RC_NO_ERR;
691 char err_str[LNET_MAX_STR_LEN];
692 lnet_nid_t *lnet_nidlist2 = NULL;
693 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
694 IOC_LIBCFS_DEL_PEER_NI;
695 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
698 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
699 if (!lnet_nidlist2) {
700 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
701 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
704 lnet_nidlist2[0] = pnid;
705 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
708 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
709 num_nids, is_mr, ioc_cmd,
715 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
720 replace_sep(char *str, char sep, char newsep)
726 for (i = 0; i < strlen(str); i++) {
727 /* don't replace ',' within [] */
730 else if (str[i] == ']')
732 else if (str[i] == sep && bracket == 0)
737 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
738 int cmd, int seq_no, struct cYAML **err_rc)
741 char err_str[LNET_MAX_STR_LEN] = "Error";
742 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
743 lnet_nid_t pnid = LNET_NID_ANY;
746 rc = LUSTRE_CFG_RC_BAD_PARAM;
747 snprintf(err_str, LNET_MAX_STR_LEN,
748 "--prim_nid must be specified");
752 pnid = libcfs_str2nid(prim_nid);
753 if (pnid == LNET_NID_ANY) {
754 rc = LUSTRE_CFG_RC_BAD_PARAM;
755 snprintf(err_str, LNET_MAX_STR_LEN,
756 "badly formatted primary NID: %s", prim_nid);
763 * if there is no primary nid we need to make the first nid in the
764 * nids list the primary nid
766 replace_sep(nids, ',', ' ');
767 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
768 LNET_MAX_NIDS_PER_PEER, err_str);
775 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
776 cmd, num_nids, is_mr,
780 if (rc != LUSTRE_CFG_RC_NO_ERR)
781 cYAML_build_error(rc, -1, "peer",
782 cmd == LNETCTL_ADD_CMD ? "add" : "del",
788 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
789 int sen, int seq_no, struct cYAML **err_rc,
792 int rc, num_nids, idx;
794 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
795 struct lnet_ioctl_config_data data;
796 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
798 if (nw == NULL || nidstr == NULL) {
799 snprintf(err_str, LNET_MAX_STR_LEN,
800 "\"missing mandatory parameter:'%s'\"",
801 (nw == NULL && nidstr == NULL) ? "network, gateway" :
802 (nw == NULL) ? "network" : "gateway");
803 rc = LUSTRE_CFG_RC_MISSING_PARAM;
807 rnet = libcfs_str2net(nw);
808 if (rnet == LNET_NET_ANY) {
809 snprintf(err_str, LNET_MAX_STR_LEN,
810 "\"cannot parse remote net %s\"", nw);
811 rc = LUSTRE_CFG_RC_BAD_PARAM;
815 replace_sep(nidstr, ',', ' ');
816 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
817 LNET_MAX_NIDS_PER_PEER, err_str);
823 for (idx = 0; idx < num_nids; idx++) {
824 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
826 if (cmd == LNETCTL_ADD_CMD) {
827 data.cfg_config_u.cfg_route.rtr_hop = hops;
828 data.cfg_config_u.cfg_route.rtr_priority = prio;
829 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
832 data.cfg_nid = lnet_nidlist[idx];
834 if (cmd == LNETCTL_ADD_CMD)
835 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
838 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
841 if (rc != 0 && errno != EEXIST &&
842 errno != EHOSTUNREACH) {
844 snprintf(err_str, LNET_MAX_STR_LEN,
845 "route operation failed: %s",
848 } else if (errno == EEXIST) {
850 * continue chugging along if one of the
851 * routes already exists
858 cYAML_build_error(rc, seq_no,
859 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
865 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
866 int sen, int seq_no, struct cYAML **err_rc)
869 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
872 hops = LNET_UNDEFINED_HOPS;
873 } else if (hops < 1 || hops > 255) {
874 snprintf(err_str, LNET_MAX_STR_LEN,
875 "\"invalid hop count %d, must be between 1 and 255\"",
877 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
883 } else if (prio < 0) {
884 snprintf(err_str, LNET_MAX_STR_LEN,
885 "\"invalid priority %d, must be greater than 0\"",
887 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
893 } else if (sen < 1) {
894 snprintf(err_str, LNET_MAX_STR_LEN,
895 "\"invalid health sensitivity %d, must be 1 or greater\"",
897 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
901 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
902 err_rc, LNETCTL_ADD_CMD);
905 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
910 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
911 struct cYAML **err_rc)
913 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
917 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
918 int seq_no, struct cYAML **show_rc,
919 struct cYAML **err_rc, bool backup)
921 struct lnet_ioctl_config_data data;
922 lnet_nid_t gateway_nid;
923 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
925 __u32 net = LNET_NET_ANY;
927 struct cYAML *root = NULL, *route = NULL, *item = NULL;
928 struct cYAML *first_seq = NULL;
929 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
933 net = libcfs_str2net(nw);
934 if (net == LNET_NET_ANY) {
937 "\"cannot parse net '%s'\"", nw);
938 rc = LUSTRE_CFG_RC_BAD_PARAM;
943 /* show all routes without filtering on net */
948 gateway_nid = libcfs_str2nid(gw);
949 if (gateway_nid == LNET_NID_ANY) {
952 "\"cannot parse gateway NID '%s'\"", gw);
953 rc = LUSTRE_CFG_RC_BAD_PARAM;
957 /* show all routes with out filtering on gateway */
958 gateway_nid = LNET_NID_ANY;
960 if ((hops < 1 && hops != -1) || hops > 255) {
963 "\"invalid hop count %d, must be between 0 and 256\"",
965 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
969 /* create struct cYAML root object */
970 root = cYAML_create_object(NULL, NULL);
974 route = cYAML_create_seq(root, "route");
982 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
985 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
991 /* filter on provided data */
992 if (net != LNET_NET_ANY &&
996 if (gateway_nid != LNET_NID_ANY &&
997 gateway_nid != data.cfg_nid)
1001 hops != data.cfg_config_u.cfg_route.rtr_hop)
1005 prio != data.cfg_config_u.cfg_route.rtr_priority)
1008 /* default rc to -1 incase we hit the goto */
1012 item = cYAML_create_seq_item(route);
1016 if (first_seq == NULL)
1019 if (cYAML_create_string(item, "net",
1020 libcfs_net2str(data.cfg_net)) == NULL)
1023 if (cYAML_create_string(item, "gateway",
1024 libcfs_nid2str(data.cfg_nid)) == NULL)
1028 if (cYAML_create_number(item, "hop",
1029 (int) data.cfg_config_u.
1030 cfg_route.rtr_hop) ==
1034 if (cYAML_create_number(item, "priority",
1036 cfg_route.rtr_priority) == NULL)
1039 if (cYAML_create_number(item, "health_sensitivity",
1041 cfg_route.rtr_sensitivity) == NULL)
1044 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1046 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1050 cYAML_create_string(item, "state",
1052 "up" : "down") == NULL)
1056 cYAML_create_string(item, "type",
1058 "multi-hop" : "single-hop") == NULL)
1063 /* print output iff show_rc is not provided */
1064 if (show_rc == NULL)
1065 cYAML_print_tree(root);
1067 if (l_errno != ENOENT) {
1070 "\"cannot get routes: %s\"",
1075 rc = LUSTRE_CFG_RC_NO_ERR;
1077 snprintf(err_str, sizeof(err_str), "\"success\"");
1079 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1080 cYAML_free_tree(root);
1081 } else if (show_rc != NULL && *show_rc != NULL) {
1082 struct cYAML *show_node;
1083 /* find the route node, if one doesn't exist then
1084 * insert one. Otherwise add to the one there
1086 show_node = cYAML_get_object_item(*show_rc, "route");
1087 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1088 cYAML_insert_child(show_node, first_seq);
1091 } else if (show_node == NULL) {
1092 cYAML_insert_sibling((*show_rc)->cy_child,
1096 cYAML_free_tree(root);
1102 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1107 static int socket_intf_query(int request, char *intf,
1113 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1114 return LUSTRE_CFG_RC_BAD_PARAM;
1116 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1118 return LUSTRE_CFG_RC_BAD_PARAM;
1120 strcpy(ifr->ifr_name, intf);
1121 rc = ioctl(sockfd, request, ifr);
1123 rc = LUSTRE_CFG_RC_BAD_PARAM;
1130 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1135 memset(&ifr, 0, sizeof(ifr));
1136 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1138 return LUSTRE_CFG_RC_BAD_PARAM;
1140 if ((ifr.ifr_flags & IFF_UP) == 0)
1141 return LUSTRE_CFG_RC_BAD_PARAM;
1143 memset(&ifr, 0, sizeof(ifr));
1144 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1146 return LUSTRE_CFG_RC_BAD_PARAM;
1148 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1149 *ip = bswap_32(*ip);
1151 return LUSTRE_CFG_RC_NO_ERR;
1155 * for each interface in the array of interfaces find the IP address of
1156 * that interface, create its nid and add it to an array of NIDs.
1157 * Stop if any of the interfaces is down
1159 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1160 lnet_nid_t **nids, __u32 *nnids,
1161 char *err_str, size_t str_len)
1163 int i = 0, count = 0, rc;
1164 struct lnet_dlc_intf_descr *intf;
1165 char val[LNET_MAX_STR_LEN];
1172 if (nw == NULL || nids == NULL) {
1173 snprintf(err_str, str_len,
1174 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1175 return LUSTRE_CFG_RC_BAD_PARAM;
1178 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1181 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1185 *nids = calloc(count, sizeof(lnet_nid_t));
1186 if (*nids == NULL) {
1187 snprintf(err_str, str_len,
1188 "\"out of memory\"");
1189 return LUSTRE_CFG_RC_OUT_OF_MEM;
1192 * special case the GNI interface since it doesn't have an IP
1193 * address. The assumption is that there can only be one GNI
1194 * interface in the system. No interface name is provided.
1196 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1197 rc = read_sysfs_file(gni_nid_path, "nid", val,
1200 snprintf(err_str, str_len,
1201 "\"cannot read gni nid\"");
1204 gni_num = atoi(val);
1206 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1211 /* look at the other interfaces */
1212 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1213 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1214 /* handle LNDs with numeric interface name */
1215 num = strtoul(intf->intf_name, &endp, 0);
1216 if (endp == intf->intf_name || *endp != '\0') {
1217 rc = LUSTRE_CFG_RC_BAD_PARAM;
1218 snprintf(err_str, str_len,
1219 "\"couldn't query intf %s\"",
1223 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1226 /* handle LNDs with ip interface name */
1227 rc = lustre_lnet_queryip(intf, &ip);
1228 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1229 snprintf(err_str, str_len,
1230 "\"couldn't query intf %s\"",
1234 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1251 * called repeatedly until a match or no more ip range
1253 * ip_range expression
1254 * interface list with all the interface names.
1255 * all the interfaces in the system.
1257 * try to match the ip_range expr to one of the interfaces' IPs in
1258 * the system. If we hit a patch for an interface. Check if that
1259 * interface name is in the list.
1261 * If there are more than one interface in the list, then make sure
1262 * that the IPs for all of these interfaces match the ip ranges
1265 * for each interface in intf_list
1266 * look up the intf name in ifa
1267 * if not there then no match
1268 * check ip obtained from ifa against a match to any of the
1270 * If no match, then fail
1272 * The result is that all the interfaces have to match.
1274 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1275 struct list_head *intf_list,
1276 struct list_head *ip_ranges)
1280 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1281 struct ifaddrs *ifaddr = ifa;
1282 struct lustre_lnet_ip_range_descr *ip_range;
1286 * if there are no explicit interfaces, and no ip ranges, then
1287 * configure the first tcp interface we encounter.
1289 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1290 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1291 if (ifaddr->ifa_addr == NULL)
1294 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1297 family = ifaddr->ifa_addr->sa_family;
1298 if (family == AF_INET &&
1299 strcmp(ifaddr->ifa_name, "lo") != 0) {
1300 rc = lustre_lnet_add_intf_descr
1301 (intf_list, ifaddr->ifa_name,
1302 strlen(ifaddr->ifa_name));
1304 if (rc != LUSTRE_CFG_RC_NO_ERR)
1307 return LUSTRE_CFG_RC_MATCH;
1310 return LUSTRE_CFG_RC_NO_MATCH;
1314 * First interface which matches an IP pattern will be used
1316 if (list_empty(intf_list)) {
1318 * no interfaces provided in the rule, but an ip range is
1319 * provided, so try and match an interface to the ip
1322 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1323 if (ifaddr->ifa_addr == NULL)
1326 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1329 family = ifaddr->ifa_addr->sa_family;
1330 if (family == AF_INET) {
1331 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1334 list_for_each_entry(ip_range, ip_ranges,
1336 rc = cfs_ip_addr_match(bswap_32(ip),
1337 &ip_range->ipr_expr);
1341 rc = lustre_lnet_add_intf_descr
1342 (intf_list, ifaddr->ifa_name,
1343 strlen(ifaddr->ifa_name));
1345 if (rc != LUSTRE_CFG_RC_NO_ERR)
1351 if (!list_empty(intf_list))
1352 return LUSTRE_CFG_RC_MATCH;
1354 return LUSTRE_CFG_RC_NO_MATCH;
1358 * If an interface is explicitly specified the ip-range might or
1359 * might not be specified. if specified the interface needs to match the
1360 * ip-range. If no ip-range then the interfaces are
1361 * automatically matched if they are all up.
1362 * If > 1 interfaces all the interfaces must match for the NI to
1365 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1366 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1367 if (ifaddr->ifa_addr == NULL)
1370 family = ifaddr->ifa_addr->sa_family;
1371 if (family == AF_INET &&
1372 strcmp(intf_descr->intf_name,
1373 ifaddr->ifa_name) == 0)
1377 if (ifaddr == NULL) {
1378 list_del(&intf_descr->intf_on_network);
1379 free_intf_descr(intf_descr);
1383 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1384 list_del(&intf_descr->intf_on_network);
1385 free_intf_descr(intf_descr);
1389 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1392 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1393 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1399 /* no match for this interface */
1400 list_del(&intf_descr->intf_on_network);
1401 free_intf_descr(intf_descr);
1405 return LUSTRE_CFG_RC_MATCH;
1408 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1409 lnet_nid_t **nids, __u32 *nnids,
1410 char *err_str, size_t str_len)
1412 struct ifaddrs *ifa;
1413 int rc = LUSTRE_CFG_RC_NO_ERR;
1415 rc = getifaddrs(&ifa);
1417 snprintf(err_str, str_len,
1418 "\"failed to get interface addresses: %d\"", -errno);
1422 rc = lustre_lnet_match_ip_to_intf(ifa,
1423 &ip2nets->ip2nets_net.nw_intflist,
1424 &ip2nets->ip2nets_ip_ranges);
1425 if (rc != LUSTRE_CFG_RC_MATCH) {
1426 snprintf(err_str, str_len,
1427 "\"couldn't match ip to existing interfaces\"");
1432 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1434 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1445 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1446 struct lnet_ioctl_config_lnd_tunables *tunables,
1447 struct cfs_expr_list *global_cpts,
1448 lnet_nid_t *nids, char *err_str)
1451 struct lnet_ioctl_config_ni *conf;
1452 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1453 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1456 struct lnet_dlc_intf_descr *intf_descr;
1458 struct cfs_expr_list *cpt_expr;
1460 list_for_each_entry(intf_descr, intf_list,
1462 if (tunables != NULL)
1463 len = sizeof(struct lnet_ioctl_config_ni) +
1464 sizeof(struct lnet_ioctl_config_lnd_tunables);
1466 len = sizeof(struct lnet_ioctl_config_ni);
1468 data = calloc(1, len);
1470 return LUSTRE_CFG_RC_OUT_OF_MEM;
1471 conf = (struct lnet_ioctl_config_ni*) data;
1472 if (tunables != NULL)
1473 tun = (struct lnet_ioctl_config_lnd_tunables*)
1476 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1477 conf->lic_cfg_hdr.ioc_len = len;
1478 conf->lic_nid = nids[i];
1479 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1482 if (intf_descr->cpt_expr != NULL)
1483 cpt_expr = intf_descr->cpt_expr;
1484 else if (global_cpts != NULL)
1485 cpt_expr = global_cpts;
1489 if (cpt_expr != NULL) {
1490 count = cfs_expr_list_values(cpt_expr,
1491 LNET_MAX_SHOW_NUM_CPT,
1494 memcpy(conf->lic_cpts, cpt_array,
1495 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1504 conf->lic_ncpts = count;
1506 if (tunables != NULL)
1507 memcpy(tun, tunables, sizeof(*tunables));
1509 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1514 "\"cannot add network: %s\"", strerror(errno));
1522 return LUSTRE_CFG_RC_NO_ERR;
1526 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1527 struct lnet_ioctl_config_lnd_tunables *tunables,
1528 struct cfs_expr_list *global_cpts,
1529 int seq_no, struct cYAML **err_rc)
1531 lnet_nid_t *nids = NULL;
1534 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1539 "\"incomplete ip2nets information\"");
1540 rc = LUSTRE_CFG_RC_BAD_PARAM;
1545 * call below function to resolve the rules into a list of nids.
1546 * The memory is allocated in that function then freed here when
1547 * it's no longer needed.
1549 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1551 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1554 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1555 snprintf(err_str, sizeof(err_str),
1556 "\"no interfaces match ip2nets rules\"");
1560 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1561 tunables, global_cpts, nids,
1568 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1572 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1573 struct cfs_expr_list *global_cpts,
1575 struct lnet_ioctl_config_lnd_tunables *tunables,
1576 long int cpp, int seq_no, struct cYAML **err_rc)
1579 struct lnet_ioctl_config_ni *conf;
1580 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1581 char buf[LNET_MAX_STR_LEN];
1582 int rc = LUSTRE_CFG_RC_NO_ERR;
1583 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1584 lnet_nid_t *nids = NULL;
1588 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1591 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1592 (list_empty(&nw_descr->nw_intflist) &&
1593 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1596 "\"missing mandatory parameters in NI config: '%s'\"",
1597 (nw_descr == NULL) ? "network , interface" :
1598 (nw_descr->nw_id == 0) ? "network" : "interface");
1599 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1603 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1606 "\"ip2net string too long %d\"",
1607 (int)strlen(ip2net));
1608 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1612 if (ip2net != NULL) {
1613 if (tunables != NULL)
1614 len = sizeof(struct lnet_ioctl_config_ni) +
1615 sizeof(struct lnet_ioctl_config_lnd_tunables);
1617 len = sizeof(struct lnet_ioctl_config_ni);
1618 data = calloc(1, len);
1620 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1623 conf = (struct lnet_ioctl_config_ni*) data;
1624 if (tunables != NULL)
1625 tun = (struct lnet_ioctl_config_lnd_tunables*)
1626 (data + sizeof(*conf));
1628 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1629 conf->lic_cfg_hdr.ioc_len = len;
1630 strncpy(conf->lic_legacy_ip2nets, ip2net,
1633 if (global_cpts != NULL) {
1634 count = cfs_expr_list_values(global_cpts,
1635 LNET_MAX_SHOW_NUM_CPT,
1638 memcpy(conf->lic_cpts, cpt_array,
1639 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1648 conf->lic_ncpts = count;
1650 if (tunables != NULL)
1651 memcpy(tun, tunables, sizeof(*tunables));
1653 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1658 "\"cannot add network: %s\"", strerror(errno));
1665 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1666 rc = LUSTRE_CFG_RC_NO_ERR;
1670 if (nw_descr->nw_id == LNET_NET_ANY) {
1673 "\"cannot parse net '%s'\"",
1674 libcfs_net2str(nw_descr->nw_id));
1675 rc = LUSTRE_CFG_RC_BAD_PARAM;
1680 * special case the GNI since no interface name is expected
1682 if (list_empty(&nw_descr->nw_intflist) &&
1683 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1686 "\"no interface name provided\"");
1687 rc = LUSTRE_CFG_RC_BAD_PARAM;
1691 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND && (cpp > -1))
1692 tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
1693 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND && (cpp > -1))
1694 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
1696 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1697 err_str, sizeof(err_str));
1699 rc = LUSTRE_CFG_RC_BAD_PARAM;
1703 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1704 tunables, global_cpts, nids,
1708 if (nw_descr != NULL) {
1709 list_for_each_entry_safe(intf_descr, tmp,
1710 &nw_descr->nw_intflist,
1712 list_del(&intf_descr->intf_on_network);
1713 free_intf_descr(intf_descr);
1717 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1728 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1729 int seq_no, struct cYAML **err_rc)
1731 struct lnet_ioctl_config_ni data;
1732 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1733 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1734 lnet_nid_t *nids = NULL;
1736 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1738 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1741 "\"missing mandatory parameter in deleting NI: '%s'\"",
1742 (nw_descr == NULL) ? "network , interface" :
1743 (nw_descr->nw_id == 0) ? "network" : "interface");
1744 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1748 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1749 return LUSTRE_CFG_RC_NO_ERR;
1751 if (nw_descr->nw_id == LNET_NET_ANY) {
1754 "\"cannot parse net '%s'\"",
1755 libcfs_net2str(nw_descr->nw_id));
1756 rc = LUSTRE_CFG_RC_BAD_PARAM;
1760 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1761 err_str, sizeof(err_str));
1763 rc = LUSTRE_CFG_RC_BAD_PARAM;
1768 * no interfaces just the nw_id is specified
1771 nids = calloc(1, sizeof(*nids));
1773 snprintf(err_str, sizeof(err_str),
1774 "\"out of memory\"");
1775 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1778 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1782 for (i = 0; i < nnids; i++) {
1783 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1784 data.lic_nid = nids[i];
1786 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1791 "\"cannot del network: %s\"", strerror(errno));
1795 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1797 list_del(&intf_descr->intf_on_network);
1798 free_intf_descr(intf_descr);
1802 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1811 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1812 enum lnet_health_type type, char *name,
1813 int seq_no, struct cYAML **err_rc)
1815 struct lnet_ioctl_reset_health_cfg data;
1816 int rc = LUSTRE_CFG_RC_NO_ERR;
1817 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1819 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1820 data.rh_type = type;
1822 data.rh_value = value;
1825 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1829 sizeof(err_str), "Can not configure health value: %s",
1833 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1840 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1841 char *name, int seq_no,
1842 struct cYAML **err_rc)
1844 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1845 int rc = LUSTRE_CFG_RC_NO_ERR;
1846 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1848 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1849 data.rcpp_all = all;
1850 data.rcpp_value = value;
1851 data.rcpp_nid = nid;
1853 if (value < 0 || value > 127) {
1854 rc = LUSTRE_CFG_RC_BAD_PARAM;
1855 snprintf(err_str, sizeof(err_str),
1856 "\"Valid values are: 0-127\"");
1859 rc = l_ioctl(LNET_DEV_ID,
1860 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1865 "Can not configure conns_per_peer value: %s",
1869 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1874 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1875 struct cYAML **err_rc)
1879 nid = libcfs_str2nid(ni_nid);
1882 return lustre_lnet_config_healthv(value, all, nid,
1883 LNET_HEALTH_TYPE_LOCAL_NI,
1884 "ni healthv", seq_no, err_rc);
1887 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1888 int seq_no, struct cYAML **err_rc)
1892 nid = libcfs_str2nid(lpni_nid);
1895 return lustre_lnet_config_healthv(value, all, nid,
1896 LNET_HEALTH_TYPE_PEER_NI,
1897 "peer_ni healthv", seq_no, err_rc);
1900 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1901 int seq_no, struct cYAML **err_rc)
1906 nid = libcfs_str2nid(ni_nid);
1909 return lustre_lnet_config_conns_per_peer(value, all, nid,
1910 "ni conns_per_peer",
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;
1956 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
1957 struct cYAML *net_node)
1959 char tmp[LNET_MAX_STR_LEN];
1960 struct cYAML *udsp_net;
1961 bool created = false;
1965 /* add the UDSP info */
1966 udsp_net = cYAML_create_object(net_node, "udsp info");
1968 return LUSTRE_CFG_RC_OUT_OF_MEM;
1970 if (!cYAML_create_number(udsp_net, "net priority",
1971 (int) udsp_info->cud_net_priority))
1972 return LUSTRE_CFG_RC_OUT_OF_MEM;
1974 if (!cYAML_create_number(udsp_net, "nid priority",
1975 (int)udsp_info->cud_nid_priority))
1976 return LUSTRE_CFG_RC_OUT_OF_MEM;
1980 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
1981 memset(tmp, 0, LNET_MAX_STR_LEN);
1982 if (udsp_info->cud_pref_rtr_nid[i] == 0)
1985 pref = cYAML_create_object(udsp_net,
1986 "Preferred gateway NIDs");
1988 return LUSTRE_CFG_RC_OUT_OF_MEM;
1991 snprintf(tmp, sizeof(tmp), "NID-%d", i);
1992 if (!cYAML_create_string(pref, tmp,
1993 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
1994 return LUSTRE_CFG_RC_OUT_OF_MEM;
1997 return LUSTRE_CFG_RC_NO_ERR;
2001 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2002 struct cYAML *nid_node)
2004 char tmp[LNET_MAX_STR_LEN];
2005 struct cYAML *udsp_nid;
2006 bool created = false;
2010 /* add the UDSP info */
2011 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2013 return LUSTRE_CFG_RC_OUT_OF_MEM;
2015 if (!cYAML_create_number(udsp_nid, "net priority",
2016 (int) udsp_info->cud_net_priority))
2017 return LUSTRE_CFG_RC_OUT_OF_MEM;
2019 if (!cYAML_create_number(udsp_nid, "nid priority",
2020 (int) udsp_info->cud_nid_priority))
2021 return LUSTRE_CFG_RC_OUT_OF_MEM;
2024 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2025 memset(tmp, 0, LNET_MAX_STR_LEN);
2026 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2029 pref = cYAML_create_object(udsp_nid,
2030 "Preferred gateway NIDs");
2032 return LUSTRE_CFG_RC_OUT_OF_MEM;
2035 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2036 if (!cYAML_create_string(pref, tmp,
2037 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2038 return LUSTRE_CFG_RC_OUT_OF_MEM;
2043 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2044 memset(tmp, 0, LNET_MAX_STR_LEN);
2045 if (udsp_info->cud_pref_nid[i] == 0)
2048 pref = cYAML_create_object(udsp_nid,
2049 "Preferred source NIDs");
2051 return LUSTRE_CFG_RC_OUT_OF_MEM;
2054 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2055 if (!cYAML_create_string(pref, tmp,
2056 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2057 return LUSTRE_CFG_RC_OUT_OF_MEM;
2060 return LUSTRE_CFG_RC_NO_ERR;
2063 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2064 struct cYAML **show_rc, struct cYAML **err_rc,
2068 struct lnet_ioctl_config_ni *ni_data;
2069 struct lnet_ioctl_config_lnd_tunables *lnd;
2070 struct lnet_ioctl_element_stats *stats;
2071 struct lnet_ioctl_element_msg_stats msg_stats;
2072 struct lnet_ioctl_local_ni_hstats hstats;
2073 struct lnet_ioctl_construct_udsp_info udsp_info;
2074 __u32 net = LNET_NET_ANY;
2075 __u32 prev_net = LNET_NET_ANY;
2076 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2078 struct cYAML *root = NULL, *tunables = NULL,
2079 *net_node = NULL, *interfaces = NULL,
2080 *item = NULL, *first_seq = NULL,
2081 *tmp = NULL, *statistics = NULL,
2083 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2084 char str_buf[str_buf_len];
2086 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2087 bool exist = false, new_net = true;
2089 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2091 buf = calloc(1, buf_size);
2095 ni_data = (struct lnet_ioctl_config_ni *)buf;
2098 net = libcfs_str2net(nw);
2099 if (net == LNET_NET_ANY) {
2102 "\"cannot parse net '%s'\"", nw);
2103 rc = LUSTRE_CFG_RC_BAD_PARAM;
2108 root = cYAML_create_object(NULL, NULL);
2112 net_node = cYAML_create_seq(root, "net");
2113 if (net_node == NULL)
2119 memset(buf, 0, buf_size);
2121 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2123 * set the ioc_len to the proper value since INIT assumes
2126 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2127 ni_data->lic_idx = i;
2129 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2135 rc_net = LNET_NIDNET(ni_data->lic_nid);
2137 /* filter on provided data */
2138 if (net != LNET_NET_ANY &&
2142 /* if we're backing up don't store lo */
2143 if (backup && LNET_NETTYP(rc_net) == LOLND)
2146 /* default rc to -1 in case we hit the goto */
2150 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2151 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2152 (ni_data->lic_bulk + sizeof(*stats));
2154 if (rc_net != prev_net) {
2161 if (!cYAML_create_string(net_node, "net type",
2162 libcfs_net2str(rc_net)))
2165 tmp = cYAML_create_seq(net_node, "local NI(s)");
2171 /* create the tree to be printed. */
2172 item = cYAML_create_seq_item(tmp);
2176 if (first_seq == NULL)
2180 cYAML_create_string(item, "nid",
2181 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2185 cYAML_create_string(item,
2187 (ni_data->lic_status ==
2188 LNET_NI_STATUS_UP) ?
2189 "up" : "down") == NULL)
2192 /* don't add interfaces unless there is at least one
2194 if (strlen(ni_data->lic_ni_intf) > 0) {
2195 interfaces = cYAML_create_object(item, "interfaces");
2196 if (interfaces == NULL)
2199 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2200 if (cYAML_create_string(interfaces, str_buf,
2201 ni_data->lic_ni_intf) == NULL)
2210 goto continue_without_msg_stats;
2212 statistics = cYAML_create_object(item, "statistics");
2213 if (statistics == NULL)
2216 if (cYAML_create_number(statistics, "send_count",
2217 stats->iel_send_count)
2221 if (cYAML_create_number(statistics, "recv_count",
2222 stats->iel_recv_count)
2226 if (cYAML_create_number(statistics, "drop_count",
2227 stats->iel_drop_count)
2232 goto continue_without_udsp_info;
2234 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2235 udsp_info.cud_nid = ni_data->lic_nid;
2236 udsp_info.cud_peer = false;
2237 rc = l_ioctl(LNET_DEV_ID,
2238 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2242 goto continue_without_udsp_info;
2245 rc = create_local_udsp_info(&udsp_info, item);
2251 continue_without_udsp_info:
2253 goto continue_without_msg_stats;
2255 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2256 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2257 msg_stats.im_idx = i;
2259 rc = l_ioctl(LNET_DEV_ID,
2260 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2264 goto continue_without_msg_stats;
2267 for (k = 0; k < 3; k++) {
2268 struct lnet_ioctl_comm_count *counts;
2269 struct cYAML *msg_statistics = NULL;
2271 msg_statistics = cYAML_create_object(item,
2272 (char *)gmsg_stat_names[k]);
2273 if (msg_statistics == NULL)
2276 counts = get_counts(&msg_stats, k);
2280 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2285 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2286 hstats.hlni_nid = ni_data->lic_nid;
2287 /* grab health stats */
2288 rc = l_ioctl(LNET_DEV_ID,
2289 IOC_LIBCFS_GET_LOCAL_HSTATS,
2293 goto continue_without_msg_stats;
2295 yhstats = cYAML_create_object(item, "health stats");
2298 if (cYAML_create_number(yhstats, "fatal_error",
2299 hstats.hlni_fatal_error)
2302 if (cYAML_create_number(yhstats, "health value",
2303 hstats.hlni_health_value)
2306 if (cYAML_create_number(yhstats, "interrupts",
2307 hstats.hlni_local_interrupt)
2310 if (cYAML_create_number(yhstats, "dropped",
2311 hstats.hlni_local_dropped)
2314 if (cYAML_create_number(yhstats, "aborted",
2315 hstats.hlni_local_aborted)
2318 if (cYAML_create_number(yhstats, "no route",
2319 hstats.hlni_local_no_route)
2322 if (cYAML_create_number(yhstats, "timeouts",
2323 hstats.hlni_local_timeout)
2326 if (cYAML_create_number(yhstats, "error",
2327 hstats.hlni_local_error)
2330 if (cYAML_create_number(yhstats, "ping_count",
2331 hstats.hlni_ping_count)
2334 if (cYAML_create_number(yhstats, "next_ping",
2335 hstats.hlni_next_ping)
2339 continue_without_msg_stats:
2340 tunables = cYAML_create_object(item, "tunables");
2344 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2345 if (rc != LUSTRE_CFG_RC_NO_ERR)
2348 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2349 tunables = cYAML_create_object(item,
2351 if (tunables == NULL)
2355 rc = lustre_ni_show_tunables(tunables,
2356 LNET_NETTYP(rc_net),
2358 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2359 rc != LUSTRE_CFG_RC_NO_MATCH)
2363 cYAML_create_number(item, "dev cpt",
2364 ni_data->lic_dev_cpt) == NULL)
2367 /* out put the CPTs in the format: "[x,x,x,...]" */
2369 limit = str_buf + str_buf_len - 3;
2370 pos += scnprintf(pos, limit - pos, "\"[");
2371 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2372 j < ni_data->lic_ncpts &&
2374 pos += scnprintf(pos, limit - pos,
2375 "%d", ni_data->lic_cpts[j]);
2376 if ((j + 1) < ni_data->lic_ncpts)
2377 pos += scnprintf(pos, limit - pos, ",");
2379 snprintf(pos, 3, "]\"");
2381 if (ni_data->lic_ncpts >= 1 &&
2382 cYAML_create_string(item, "CPT",
2388 /* Print out the net information only if show_rc is not provided */
2389 if (show_rc == NULL)
2390 cYAML_print_tree(root);
2392 if (l_errno != ENOENT) {
2395 "\"cannot get networks: %s\"",
2400 rc = LUSTRE_CFG_RC_NO_ERR;
2402 snprintf(err_str, sizeof(err_str), "\"success\"");
2404 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2405 cYAML_free_tree(root);
2406 } else if (show_rc != NULL && *show_rc != NULL) {
2407 struct cYAML *show_node;
2408 /* find the net node, if one doesn't exist
2409 * then insert one. Otherwise add to the one there
2411 show_node = cYAML_get_object_item(*show_rc, "net");
2412 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2413 cYAML_insert_child(show_node, first_seq);
2416 } else if (show_node == NULL) {
2417 cYAML_insert_sibling((*show_rc)->cy_child,
2421 cYAML_free_tree(root);
2427 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2432 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2434 struct lnet_ioctl_config_data data;
2435 int rc = LUSTRE_CFG_RC_NO_ERR;
2436 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2438 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2439 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2441 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2446 "\"cannot %s routing %s\"",
2447 (enable) ? "enable" : "disable", strerror(errno));
2452 cYAML_build_error(rc, seq_no,
2453 (enable) ? ADD_CMD : DEL_CMD,
2454 "routing", err_str, err_rc);
2459 int ioctl_set_value(__u32 val, int ioc, char *name,
2460 int seq_no, struct cYAML **err_rc)
2462 struct lnet_ioctl_set_value data;
2463 int rc = LUSTRE_CFG_RC_NO_ERR;
2464 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2466 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2467 data.sv_value = val;
2469 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2474 "\"cannot configure %s to %d: %s\"", name,
2475 val, strerror(errno));
2478 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2483 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2485 int rc = LUSTRE_CFG_RC_NO_ERR;
2486 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2487 char val[LNET_MAX_STR_LEN];
2489 snprintf(val, sizeof(val), "%d", intrv);
2491 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2492 1, strlen(val) + 1);
2494 snprintf(err_str, sizeof(err_str),
2495 "\"cannot configure recovery interval: %s\"",
2498 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2503 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2505 int rc = LUSTRE_CFG_RC_NO_ERR;
2506 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2507 char val[LNET_MAX_STR_LEN];
2509 snprintf(val, sizeof(val), "%d", sen);
2511 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2512 1, strlen(val) + 1);
2514 snprintf(err_str, sizeof(err_str),
2515 "\"cannot configure router health sensitivity: %s\"",
2518 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2523 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2525 int rc = LUSTRE_CFG_RC_NO_ERR;
2526 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2527 char val[LNET_MAX_STR_LEN];
2529 snprintf(val, sizeof(val), "%d", sen);
2531 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2532 1, strlen(val) + 1);
2534 snprintf(err_str, sizeof(err_str),
2535 "\"cannot configure health sensitivity: %s\"",
2538 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2543 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2545 int rc = LUSTRE_CFG_RC_NO_ERR;
2546 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2547 char val[LNET_MAX_STR_LEN];
2549 snprintf(val, sizeof(val), "%d", timeout);
2551 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2552 1, strlen(val) + 1);
2554 snprintf(err_str, sizeof(err_str),
2555 "\"cannot configure transaction timeout: %s\"",
2558 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2563 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2565 int rc = LUSTRE_CFG_RC_NO_ERR;
2566 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2567 char val[LNET_MAX_STR_LEN];
2569 snprintf(val, sizeof(val), "%d", count);
2571 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2572 1, strlen(val) + 1);
2574 snprintf(err_str, sizeof(err_str),
2575 "\"cannot configure retry count: %s\"",
2578 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2583 int lustre_lnet_config_response_tracking(int val, int seq_no,
2584 struct cYAML **err_rc)
2586 int rc = LUSTRE_CFG_RC_NO_ERR;
2587 char err_str[LNET_MAX_STR_LEN];
2588 char val_str[LNET_MAX_STR_LEN];
2590 if (val < 0 || val > 3) {
2591 rc = LUSTRE_CFG_RC_BAD_PARAM;
2592 snprintf(err_str, sizeof(err_str),
2593 "\"Valid values are: 0, 1, 2, or 3\"");
2595 snprintf(err_str, sizeof(err_str), "\"success\"");
2597 snprintf(val_str, sizeof(val_str), "%d", val);
2599 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2600 val_str, 1, strlen(val_str) + 1);
2602 snprintf(err_str, sizeof(err_str),
2603 "\"cannot configure response tracking: %s\"",
2607 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2613 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2614 struct cYAML **err_rc)
2616 int rc = LUSTRE_CFG_RC_NO_ERR;
2617 char err_str[LNET_MAX_STR_LEN];
2618 char val_str[LNET_MAX_STR_LEN];
2621 rc = LUSTRE_CFG_RC_BAD_PARAM;
2622 snprintf(err_str, sizeof(err_str),
2623 "\"Must be greater than or equal to 0\"");
2625 snprintf(err_str, sizeof(err_str), "\"success\"");
2627 snprintf(val_str, sizeof(val_str), "%d", val);
2629 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2630 val_str, 1, strlen(val_str) + 1);
2632 snprintf(err_str, sizeof(err_str),
2633 "\"cannot configure recovery limit: %s\"",
2637 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2643 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2645 int rc = LUSTRE_CFG_RC_NO_ERR;
2646 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2647 char val[LNET_MAX_STR_LEN];
2649 snprintf(val, sizeof(val), "%d", max);
2651 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2652 1, strlen(val) + 1);
2654 snprintf(err_str, sizeof(err_str),
2655 "\"cannot configure max interfaces: %s\"",
2658 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2663 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2665 int rc = LUSTRE_CFG_RC_NO_ERR;
2666 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2667 char val[LNET_MAX_STR_LEN];
2669 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2671 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2672 1, strlen(val) + 1);
2674 snprintf(err_str, sizeof(err_str),
2675 "\"cannot configure discovery: %s\"",
2678 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2684 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2685 struct cYAML **err_rc)
2687 int rc = LUSTRE_CFG_RC_NO_ERR;
2688 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2689 char val[LNET_MAX_STR_LEN];
2691 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2693 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2694 1, strlen(val) + 1);
2696 snprintf(err_str, sizeof(err_str),
2697 "\"cannot configure drop asym route: %s\"",
2700 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2707 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2709 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2710 "numa_range", seq_no, err_rc);
2713 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2714 struct cYAML **err_rc)
2716 struct lnet_ioctl_config_data data;
2717 int rc = LUSTRE_CFG_RC_NO_ERR;
2718 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2720 /* -1 indicates to ignore changes to this field */
2721 if (tiny < -1 || small < -1 || large < -1) {
2724 "\"tiny, small and large must be >= 0\"");
2725 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2729 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2730 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2731 data.cfg_config_u.cfg_buffers.buf_small = small;
2732 data.cfg_config_u.cfg_buffers.buf_large = large;
2734 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2739 "\"cannot configure buffers: %s\"", strerror(errno));
2744 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2749 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2750 struct cYAML **err_rc)
2752 int rc = LUSTRE_CFG_RC_NO_ERR;
2753 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2754 char interval_str[LNET_MAX_STR_LEN];
2756 if (interval <= 0) {
2757 rc = LUSTRE_CFG_RC_BAD_PARAM;
2758 snprintf(err_str, sizeof(err_str),
2759 "\"must be strictly positive\"");
2762 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2764 rc = write_sysfs_file(modparam_path,
2765 "lnet_max_recovery_ping_interval",
2767 strlen(interval_str) + 1);
2769 snprintf(err_str, sizeof(err_str),
2770 "\"cannot configure maximum recovery ping interval: %s\"",
2774 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2781 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2782 struct cYAML **err_rc, bool backup)
2784 struct lnet_ioctl_config_data *data;
2785 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2786 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2789 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2790 int buf_count[LNET_NRBPOOLS] = {0};
2791 struct cYAML *root = NULL, *pools_node = NULL,
2792 *type_node = NULL, *item = NULL, *cpt = NULL,
2793 *first_seq = NULL, *buffers = NULL;
2795 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2796 char node_name[LNET_MAX_STR_LEN];
2799 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2803 data = (struct lnet_ioctl_config_data *)buf;
2805 root = cYAML_create_object(NULL, NULL);
2810 pools_node = cYAML_create_object(root, "routing");
2812 pools_node = cYAML_create_seq(root, "routing");
2813 if (pools_node == NULL)
2817 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2818 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2819 sizeof(struct lnet_ioctl_pool_cfg);
2820 data->cfg_count = i;
2822 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2830 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2833 goto calculate_buffers;
2835 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2836 item = cYAML_create_seq_item(pools_node);
2840 if (first_seq == NULL)
2843 cpt = cYAML_create_object(item, node_name);
2848 /* create the tree and print */
2849 for (j = 0; j < LNET_NRBPOOLS; j++) {
2851 type_node = cYAML_create_object(cpt, pools[j]);
2852 if (type_node == NULL)
2856 cYAML_create_number(type_node, "npages",
2857 pool_cfg->pl_pools[j].pl_npages)
2861 cYAML_create_number(type_node, "nbuffers",
2862 pool_cfg->pl_pools[j].
2863 pl_nbuffers) == NULL)
2866 cYAML_create_number(type_node, "credits",
2867 pool_cfg->pl_pools[j].
2868 pl_credits) == NULL)
2871 cYAML_create_number(type_node, "mincredits",
2872 pool_cfg->pl_pools[j].
2873 pl_mincredits) == NULL)
2875 /* keep track of the total count for each of the
2876 * tiny, small and large buffers */
2877 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2881 if (pool_cfg != NULL) {
2883 if (cYAML_create_number(pools_node, "enable",
2884 pool_cfg->pl_routing) ==
2888 goto add_buffer_section;
2891 item = cYAML_create_seq_item(pools_node);
2895 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2901 /* create a buffers entry in the show. This is necessary so that
2902 * if the YAML output is used to configure a node, the buffer
2903 * configuration takes hold */
2904 buffers = cYAML_create_object(root, "buffers");
2905 if (buffers == NULL)
2908 for (i = 0; i < LNET_NRBPOOLS; i++) {
2909 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2913 if (show_rc == NULL)
2914 cYAML_print_tree(root);
2916 if (l_errno != ENOENT) {
2919 "\"cannot get routing information: %s\"",
2924 rc = LUSTRE_CFG_RC_NO_ERR;
2926 snprintf(err_str, sizeof(err_str), "\"success\"");
2927 rc = LUSTRE_CFG_RC_NO_ERR;
2931 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2932 cYAML_free_tree(root);
2933 } else if (show_rc != NULL && *show_rc != NULL) {
2934 struct cYAML *routing_node;
2935 /* there should exist only one routing block and one
2936 * buffers block. If there already exists a previous one
2937 * then don't add another */
2938 routing_node = cYAML_get_object_item(*show_rc, "routing");
2939 if (routing_node == NULL) {
2940 cYAML_insert_sibling((*show_rc)->cy_child,
2944 cYAML_free_tree(root);
2950 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2955 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2956 struct cYAML **show_rc, struct cYAML **err_rc,
2960 * TODO: This function is changing in a future patch to accommodate
2961 * PEER_LIST and proper filtering on any nid of the peer
2963 struct lnet_ioctl_peer_cfg peer_info;
2964 struct lnet_peer_ni_credit_info *lpni_cri;
2965 struct lnet_ioctl_element_stats *lpni_stats;
2966 struct lnet_ioctl_element_msg_stats *msg_stats;
2967 struct lnet_ioctl_peer_ni_hstats *hstats;
2968 struct lnet_ioctl_construct_udsp_info udsp_info;
2970 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2975 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2976 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2977 *msg_statistics = NULL, *statistics = NULL,
2979 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2980 struct lnet_process_id *list = NULL;
2985 /* create struct cYAML root object */
2986 root = cYAML_create_object(NULL, NULL);
2990 peer_root = cYAML_create_seq(root, "peer");
2991 if (peer_root == NULL)
2995 size = count * sizeof(struct lnet_process_id);
2996 list = malloc(size);
3002 list[0].nid = libcfs_str2nid(knid);
3006 memset(&peer_info, 0, sizeof(peer_info));
3007 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3008 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3009 peer_info.prcfg_size = size;
3010 peer_info.prcfg_bulk = list;
3013 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3015 count = peer_info.prcfg_count;
3019 if (l_errno != E2BIG) {
3022 "\"cannot get peer list: %s\"",
3028 size = peer_info.prcfg_size;
3029 list = malloc(size);
3038 data = malloc(size);
3044 for (i = 0; i < count; i++) {
3046 memset(&peer_info, 0, sizeof(peer_info));
3047 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3048 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3049 peer_info.prcfg_prim_nid = list[i].nid;
3050 peer_info.prcfg_size = size;
3051 peer_info.prcfg_bulk = data;
3054 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3059 if (l_errno != E2BIG) {
3062 "\"cannot get peer information: %s\"",
3068 size = peer_info.prcfg_size;
3069 data = malloc(size);
3077 peer = cYAML_create_seq_item(peer_root);
3081 if (first_seq == NULL)
3084 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3085 if (cYAML_create_string(peer, "primary nid",
3086 libcfs_nid2str(pnid))
3089 if (cYAML_create_string(peer, "Multi-Rail",
3090 peer_info.prcfg_mr ? "True" : "False")
3094 * print out the state of the peer only if details are
3099 cYAML_create_number(peer, "peer state",
3100 peer_info.prcfg_state)
3105 tmp = cYAML_create_seq(peer, "peer ni");
3110 for (j = 0; j < peer_info.prcfg_count; j++) {
3112 lpni_cri = (void*)nidp + sizeof(nidp);
3113 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3114 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3115 hstats = (void *)msg_stats + sizeof(*msg_stats);
3116 lpni_data = (void *)hstats + sizeof(*hstats);
3118 peer_ni = cYAML_create_seq_item(tmp);
3119 if (peer_ni == NULL)
3122 if (cYAML_create_string(peer_ni, "nid",
3123 libcfs_nid2str(*nidp))
3131 goto continue_without_udsp_info;
3133 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3134 udsp_info.cud_nid = *nidp;
3135 udsp_info.cud_peer = true;
3136 rc = l_ioctl(LNET_DEV_ID,
3137 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3141 goto continue_without_udsp_info;
3144 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3150 continue_without_udsp_info:
3151 if (cYAML_create_string(peer_ni, "state",
3152 lpni_cri->cr_aliveness)
3159 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3160 lpni_cri->cr_ni_peer_tx_credits)
3164 if (cYAML_create_number(peer_ni, "available_tx_credits",
3165 lpni_cri->cr_peer_tx_credits)
3169 if (cYAML_create_number(peer_ni, "min_tx_credits",
3170 lpni_cri->cr_peer_min_tx_credits)
3174 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3175 lpni_cri->cr_peer_tx_qnob)
3179 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3180 lpni_cri->cr_peer_rtr_credits)
3184 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3185 lpni_cri->cr_peer_min_rtr_credits)
3189 if (cYAML_create_number(peer_ni, "refcount",
3190 lpni_cri->cr_refcount) == NULL)
3193 statistics = cYAML_create_object(peer_ni, "statistics");
3194 if (statistics == NULL)
3197 if (cYAML_create_number(statistics, "send_count",
3198 lpni_stats->iel_send_count)
3202 if (cYAML_create_number(statistics, "recv_count",
3203 lpni_stats->iel_recv_count)
3207 if (cYAML_create_number(statistics, "drop_count",
3208 lpni_stats->iel_drop_count)
3215 for (k = 0; k < 3; k++) {
3216 struct lnet_ioctl_comm_count *counts;
3218 msg_statistics = cYAML_create_object(peer_ni,
3219 (char *) gmsg_stat_names[k]);
3220 if (msg_statistics == NULL)
3223 counts = get_counts(msg_stats, k);
3227 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3232 yhstats = cYAML_create_object(peer_ni, "health stats");
3235 if (cYAML_create_number(yhstats, "health value",
3236 hstats->hlpni_health_value)
3239 if (cYAML_create_number(yhstats, "dropped",
3240 hstats->hlpni_remote_dropped)
3243 if (cYAML_create_number(yhstats, "timeout",
3244 hstats->hlpni_remote_timeout)
3247 if (cYAML_create_number(yhstats, "error",
3248 hstats->hlpni_remote_error)
3251 if (cYAML_create_number(yhstats, "network timeout",
3252 hstats->hlpni_network_timeout)
3255 if (cYAML_create_number(yhstats, "ping_count",
3256 hstats->hlpni_ping_count)
3260 if (cYAML_create_number(yhstats, "next_ping",
3261 hstats->hlpni_next_ping)
3268 /* print output iff show_rc is not provided */
3269 if (show_rc == NULL)
3270 cYAML_print_tree(root);
3272 snprintf(err_str, sizeof(err_str), "\"success\"");
3273 rc = LUSTRE_CFG_RC_NO_ERR;
3278 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3279 cYAML_free_tree(root);
3280 } else if (show_rc != NULL && *show_rc != NULL) {
3281 struct cYAML *show_node;
3282 /* find the peer node, if one doesn't exist then
3283 * insert one. Otherwise add to the one there
3285 show_node = cYAML_get_object_item(*show_rc,
3287 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3288 cYAML_insert_child(show_node, first_seq);
3291 } else if (show_node == NULL) {
3292 cYAML_insert_sibling((*show_rc)->cy_child,
3296 cYAML_free_tree(root);
3302 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3308 int lustre_lnet_list_peer(int seq_no,
3309 struct cYAML **show_rc, struct cYAML **err_rc)
3311 struct lnet_ioctl_peer_cfg peer_info;
3312 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3317 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3318 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3319 struct lnet_process_id *list = NULL;
3321 memset(&peer_info, 0, sizeof(peer_info));
3323 /* create struct cYAML root object */
3324 root = cYAML_create_object(NULL, NULL);
3328 list_root = cYAML_create_seq(root, "peer list");
3329 if (list_root == NULL)
3333 size = count * sizeof(struct lnet_process_id);
3334 list = malloc(size);
3340 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3341 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3342 peer_info.prcfg_size = size;
3343 peer_info.prcfg_bulk = list;
3346 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3347 count = peer_info.prcfg_count;
3351 if (l_errno != E2BIG) {
3354 "\"cannot get peer list: %s\"",
3360 size = peer_info.prcfg_size;
3361 list = malloc(size);
3368 /* count is now the actual number of ids in the list. */
3369 for (i = 0; i < count; i++) {
3370 if (cYAML_create_string(list_root, "nid",
3371 libcfs_nid2str(list[i].nid))
3376 /* print output iff show_rc is not provided */
3377 if (show_rc == NULL)
3378 cYAML_print_tree(root);
3380 snprintf(err_str, sizeof(err_str), "\"success\"");
3381 rc = LUSTRE_CFG_RC_NO_ERR;
3386 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3387 cYAML_free_tree(root);
3388 } else if (show_rc != NULL && *show_rc != NULL) {
3389 struct cYAML *show_node;
3390 /* find the peer node, if one doesn't exist then
3391 * insert one. Otherwise add to the one there
3393 show_node = cYAML_get_object_item(*show_rc,
3395 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3396 cYAML_insert_child(show_node, first_seq);
3399 } else if (show_node == NULL) {
3400 cYAML_insert_sibling((*show_rc)->cy_child,
3404 cYAML_free_tree(root);
3410 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3416 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3419 struct cYAML *show_node;
3421 show_node = cYAML_get_object_item(show_rc, "global");
3422 if (show_node != NULL)
3423 cYAML_insert_sibling(show_node->cy_child,
3426 cYAML_insert_sibling(show_rc->cy_child,
3431 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3432 char *name, __u64 value,
3433 struct cYAML **show_rc,
3434 struct cYAML **err_rc, int err)
3436 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3437 struct cYAML *root = NULL, *global = NULL;
3444 root = cYAML_create_object(NULL, NULL);
3448 global = cYAML_create_object(root, "global");
3452 if (cYAML_create_number(global, name,
3456 if (show_rc == NULL)
3457 cYAML_print_tree(root);
3459 snprintf(err_str, err_len, "\"success\"");
3461 rc = LUSTRE_CFG_RC_NO_ERR;
3464 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3465 cYAML_free_tree(root);
3466 } else if (show_rc != NULL && *show_rc != NULL) {
3467 add_to_global(*show_rc, global, root);
3472 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3477 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3478 struct cYAML **show_rc,
3479 struct cYAML **err_rc)
3481 struct lnet_ioctl_set_value data;
3484 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3486 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3488 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3493 "\"cannot get %s: %s\"",
3494 name, strerror(l_errno));
3497 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3498 data.sv_value, show_rc, err_rc, l_errno);
3501 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3502 struct cYAML **err_rc)
3504 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3505 char val[LNET_MAX_STR_LEN];
3506 int intrv = -1, l_errno = 0;
3507 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3509 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3513 snprintf(err_str, sizeof(err_str),
3514 "\"cannot get recovery interval: %d\"", rc);
3519 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3520 "recovery_interval", intrv, show_rc,
3524 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3525 struct cYAML **err_rc)
3527 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3528 char val[LNET_MAX_STR_LEN];
3529 int sen = -1, l_errno = 0;
3530 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3532 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3536 snprintf(err_str, sizeof(err_str),
3537 "\"cannot get health sensitivity: %d\"", rc);
3542 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3543 "health_sensitivity", sen, show_rc,
3547 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3548 struct cYAML **err_rc)
3550 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3551 char val[LNET_MAX_STR_LEN];
3552 int sen = -1, l_errno = 0;
3553 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3555 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3559 snprintf(err_str, sizeof(err_str),
3560 "\"cannot get router sensitivity percentage: %d\"", rc);
3565 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3566 "router_sensitivity", sen, show_rc,
3570 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3571 struct cYAML **err_rc)
3573 char val[LNET_MAX_STR_LEN];
3574 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3581 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3584 snprintf(err_str, sizeof(err_str),
3585 "\"cannot get LND timeout: %d\"", rc);
3586 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3587 "lnd_timeout", lnd_to, show_rc,
3591 fd = open(path.gl_pathv[0], O_RDONLY);
3594 snprintf(err_str, sizeof(err_str),
3595 "\"error opening %s\"", path.gl_pathv[0]);
3599 rc = read(fd, val, sizeof(val));
3606 snprintf(err_str, sizeof(err_str),
3607 "\"error reading %s\"", path.gl_pathv[0]);
3614 cfs_free_param_data(&path);
3616 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3617 "lnd_timeout", lnd_to, show_rc,
3621 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3622 struct cYAML **err_rc)
3624 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3625 char val[LNET_MAX_STR_LEN];
3626 int tto = -1, l_errno = 0;
3627 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3629 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3633 snprintf(err_str, sizeof(err_str),
3634 "\"cannot get transaction timeout: %d\"", rc);
3639 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3640 "transaction_timeout", tto, show_rc,
3644 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3645 struct cYAML **err_rc)
3647 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3648 char val[LNET_MAX_STR_LEN];
3649 int retry_count = -1, l_errno = 0;
3650 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3652 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3656 snprintf(err_str, sizeof(err_str),
3657 "\"cannot get retry count: %d\"", rc);
3659 retry_count = atoi(val);
3662 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3663 "retry_count", retry_count, show_rc,
3667 int lustre_lnet_calc_service_id(__u64 *service_id)
3669 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3670 char val[LNET_MAX_STR_LEN];
3671 int service_port = -1, l_errno = 0;
3673 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3677 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3678 strerror(l_errno), -l_errno);
3681 service_port = atoi(val);
3684 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3686 return LUSTRE_CFG_RC_NO_ERR;
3689 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3692 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3694 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3695 struct lnet_ioctl_config_ni *ni_data;
3696 struct lnet_ioctl_config_lnd_tunables *lnd;
3697 struct lnet_ioctl_element_stats *stats;
3698 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3699 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3700 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3701 int if_cnt = 0, prc;
3702 char syscmdbuf[LNET_MAX_STR_LEN];
3703 char cmdpath[LNET_MAX_STR_LEN];
3704 bool use_custom = false;
3706 buf = calloc(1, buf_size);
3710 ni_data = (struct lnet_ioctl_config_ni *)buf;
3713 ifstr_ptr = ifstr_buf;
3718 memset(buf, 0, buf_size);
3720 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3721 /* set the ioc_len to the proper value since INIT assumes
3724 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3725 ni_data->lic_idx = i;
3727 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3733 rc_net = LNET_NIDNET(ni_data->lic_nid);
3735 /* only need to setup routing for tcp */
3736 if (LNET_NETTYP(rc_net) != SOCKLND)
3739 /* don't add interfaces unless there is at least one
3742 if (strlen(ni_data->lic_ni_intf) > 0) {
3744 strcat(ifstr_ptr, ",");
3745 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3750 if (l_errno != ENOENT) {
3753 "\"cannot get networks: %s\"",
3758 rc = LUSTRE_CFG_RC_NO_ERR;
3761 snprintf(err_str, sizeof(err_str), "\"success\"");
3764 tmp_ptr = getenv("KSOCKLND_CONFIG");
3766 tmp_ptr2 = strrchr(tmp_ptr, '/');
3767 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3768 snprintf(cmdpath, sizeof(cmdpath), "%s",
3775 snprintf(cmdpath, sizeof(cmdpath),
3776 "/usr/sbin/ksocklnd-config");
3778 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3784 "\"snprintf failed : %s\"",
3787 } else if (prc >= LNET_MAX_STR_LEN) {
3788 snprintf(err_str, sizeof(err_str),
3789 "\"ksocklnd-config: argument too long\"");
3791 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3792 cmdpath, ifstr_ptr);
3798 "\"snprintf failed : %s\"",
3804 rc = system(syscmdbuf);
3809 "\"failed to execute ksocklnd-config : %s\"",
3819 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3826 lnet_nid_cpt_hash(lnet_nid_t nid, long int number)
3829 __u64 pair_bits = 0x0001000100010001LLU;
3830 __u64 mask = pair_bits * 0xFF;
3836 pair_sum = (key & mask) + ((key >> 8) & mask);
3837 pair_sum = (pair_sum * pair_bits) >> 48;
3839 return (unsigned int)(pair_sum) % number;
3842 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3844 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3848 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3853 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3857 nid = libcfs_str2nid(nidc);
3858 if (nid == LNET_NID_ANY) {
3859 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3864 return (int)lnet_nid_cpt_hash(nid, ncpts);
3867 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3868 struct cYAML **show_rc, struct cYAML **err_rc)
3870 struct lnet_ioctl_recovery_list nid_list;
3871 struct cYAML *root = NULL, *nids = NULL;
3873 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3875 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3876 nid_list.rlst_type = type;
3878 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3884 if (nid_list.rlst_num_nids == 0)
3887 root = cYAML_create_object(NULL, NULL);
3891 nids = cYAML_create_object(root, name);
3897 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3898 char nidenum[LNET_MAX_STR_LEN];
3899 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3900 if (!cYAML_create_string(nids, nidenum,
3901 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3905 snprintf(err_str, sizeof(err_str), "success\n");
3910 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3911 cYAML_free_tree(root);
3912 } else if (show_rc != NULL && *show_rc != NULL) {
3913 struct cYAML *show_node;
3914 /* find the net node, if one doesn't exist
3915 * then insert one. Otherwise add to the one there
3917 show_node = cYAML_get_object_item(*show_rc, name);
3918 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3919 cYAML_insert_child(show_node, nids);
3922 } else if (show_node == NULL) {
3923 cYAML_insert_sibling((*show_rc)->cy_child,
3927 cYAML_free_tree(root);
3933 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3938 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3939 struct cYAML **err_rc)
3941 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3942 seq_no, show_rc, err_rc);
3945 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3946 struct cYAML **err_rc)
3948 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3949 seq_no, show_rc, err_rc);
3952 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
3953 struct cYAML **err_rc)
3955 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3956 char val[LNET_MAX_STR_LEN];
3957 int rsp_tracking = -1, l_errno = 0;
3958 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3960 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
3964 snprintf(err_str, sizeof(err_str),
3965 "\"cannot get lnet_response_tracking value: %d\"", rc);
3967 rsp_tracking = atoi(val);
3970 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3971 "response_tracking", rsp_tracking,
3972 show_rc, err_rc, l_errno);
3975 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
3976 struct cYAML **err_rc)
3978 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3979 char val[LNET_MAX_STR_LEN];
3980 int recov_limit = -1, l_errno = 0;
3981 char err_str[LNET_MAX_STR_LEN];
3983 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3985 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
3989 snprintf(err_str, sizeof(err_str),
3990 "\"cannot get lnet_recovery_limit value: %d\"", rc);
3992 recov_limit = atoi(val);
3995 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3996 "recovery_limit", recov_limit,
3997 show_rc, err_rc, l_errno);
4000 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4001 struct cYAML **show_rc,
4002 struct cYAML **err_rc)
4004 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4005 char val[LNET_MAX_STR_LEN];
4006 int interval = -1, l_errno = 0;
4007 char err_str[LNET_MAX_STR_LEN];
4009 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4011 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4012 val, 1, sizeof(val));
4015 snprintf(err_str, sizeof(err_str),
4016 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4019 interval = atoi(val);
4022 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4023 "max_recovery_ping_interval", interval,
4024 show_rc, err_rc, l_errno);
4028 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4029 struct cYAML **err_rc)
4031 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4032 char val[LNET_MAX_STR_LEN];
4033 int max_intf = -1, l_errno = 0;
4034 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4036 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4040 snprintf(err_str, sizeof(err_str),
4041 "\"cannot get max interfaces: %d\"", rc);
4043 max_intf = atoi(val);
4046 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4047 "max_interfaces", max_intf, show_rc,
4051 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4052 struct cYAML **err_rc)
4054 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4055 char val[LNET_MAX_STR_LEN];
4056 int discovery = -1, l_errno = 0;
4057 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4059 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4063 snprintf(err_str, sizeof(err_str),
4064 "\"cannot get discovery setting: %d\"", rc);
4067 * The kernel stores a discovery disabled value. User space
4068 * shows whether discovery is enabled. So the value must be
4071 discovery = !atoi(val);
4074 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4075 "discovery", discovery, show_rc,
4079 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4080 struct cYAML **err_rc)
4082 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4083 char val[LNET_MAX_STR_LEN];
4084 int drop_asym_route = -1, l_errno = 0;
4085 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4087 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4091 snprintf(err_str, sizeof(err_str),
4092 "\"cannot get drop asym route setting: %d\"", rc);
4094 drop_asym_route = atoi(val);
4097 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4098 "drop_asym_route", drop_asym_route,
4099 show_rc, err_rc, l_errno);
4102 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4103 struct cYAML **err_rc)
4105 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4106 "numa_range", show_rc, err_rc);
4109 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4110 struct cYAML **err_rc)
4112 struct lnet_ioctl_lnet_stats data;
4113 struct lnet_counters *cntrs;
4116 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4117 struct cYAML *root = NULL, *stats = NULL;
4119 LIBCFS_IOC_INIT_V2(data, st_hdr);
4121 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4126 "\"cannot get lnet statistics: %s\"",
4132 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4134 cntrs = &data.st_cntrs;
4136 root = cYAML_create_object(NULL, NULL);
4140 stats = cYAML_create_object(root, "statistics");
4144 if (!cYAML_create_number(stats, "msgs_alloc",
4145 cntrs->lct_common.lcc_msgs_alloc))
4148 if (!cYAML_create_number(stats, "msgs_max",
4149 cntrs->lct_common.lcc_msgs_max))
4152 if (!cYAML_create_number(stats, "rst_alloc",
4153 cntrs->lct_health.lch_rst_alloc))
4156 if (!cYAML_create_number(stats, "errors",
4157 cntrs->lct_common.lcc_errors))
4160 if (!cYAML_create_number(stats, "send_count",
4161 cntrs->lct_common.lcc_send_count))
4164 if (!cYAML_create_number(stats, "resend_count",
4165 cntrs->lct_health.lch_resend_count))
4168 if (!cYAML_create_number(stats, "response_timeout_count",
4169 cntrs->lct_health.lch_response_timeout_count))
4172 if (!cYAML_create_number(stats, "local_interrupt_count",
4173 cntrs->lct_health.lch_local_interrupt_count))
4176 if (!cYAML_create_number(stats, "local_dropped_count",
4177 cntrs->lct_health.lch_local_dropped_count))
4180 if (!cYAML_create_number(stats, "local_aborted_count",
4181 cntrs->lct_health.lch_local_aborted_count))
4184 if (!cYAML_create_number(stats, "local_no_route_count",
4185 cntrs->lct_health.lch_local_no_route_count))
4188 if (!cYAML_create_number(stats, "local_timeout_count",
4189 cntrs->lct_health.lch_local_timeout_count))
4192 if (!cYAML_create_number(stats, "local_error_count",
4193 cntrs->lct_health.lch_local_error_count))
4196 if (!cYAML_create_number(stats, "remote_dropped_count",
4197 cntrs->lct_health.lch_remote_dropped_count))
4200 if (!cYAML_create_number(stats, "remote_error_count",
4201 cntrs->lct_health.lch_remote_error_count))
4204 if (!cYAML_create_number(stats, "remote_timeout_count",
4205 cntrs->lct_health.lch_remote_timeout_count))
4208 if (!cYAML_create_number(stats, "network_timeout_count",
4209 cntrs->lct_health.lch_network_timeout_count))
4212 if (!cYAML_create_number(stats, "recv_count",
4213 cntrs->lct_common.lcc_recv_count))
4216 if (!cYAML_create_number(stats, "route_count",
4217 cntrs->lct_common.lcc_route_count))
4220 if (!cYAML_create_number(stats, "drop_count",
4221 cntrs->lct_common.lcc_drop_count))
4224 if (!cYAML_create_number(stats, "send_length",
4225 cntrs->lct_common.lcc_send_length))
4228 if (!cYAML_create_number(stats, "recv_length",
4229 cntrs->lct_common.lcc_recv_length))
4232 if (!cYAML_create_number(stats, "route_length",
4233 cntrs->lct_common.lcc_route_length))
4236 if (!cYAML_create_number(stats, "drop_length",
4237 cntrs->lct_common.lcc_drop_length))
4241 cYAML_print_tree(root);
4243 snprintf(err_str, sizeof(err_str), "\"success\"");
4244 rc = LUSTRE_CFG_RC_NO_ERR;
4246 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4247 cYAML_free_tree(root);
4248 } else if (show_rc != NULL && *show_rc != NULL) {
4249 cYAML_insert_sibling((*show_rc)->cy_child,
4256 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4261 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4263 struct libcfs_ioctl_data data;
4264 int rc = LUSTRE_CFG_RC_NO_ERR;
4266 char err_str[LNET_MAX_STR_LEN];
4268 LIBCFS_IOC_INIT(data);
4270 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4275 "\"cannot reset lnet statistics: %s\"",
4279 snprintf(err_str, sizeof(err_str), "\"success\"");
4280 rc = LUSTRE_CFG_RC_NO_ERR;
4283 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4287 typedef int (*cmd_handler_t)(struct cYAML *tree,
4288 struct cYAML **show_rc,
4289 struct cYAML **err_rc);
4291 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4292 struct cYAML **err_rc)
4294 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4296 net = cYAML_get_object_item(tree, "net");
4297 gw = cYAML_get_object_item(tree, "gateway");
4298 hop = cYAML_get_object_item(tree, "hop");
4299 prio = cYAML_get_object_item(tree, "priority");
4300 sen = cYAML_get_object_item(tree, "health_sensitivity");
4301 seq_no = cYAML_get_object_item(tree, "seq_no");
4303 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4304 (gw) ? gw->cy_valuestring : NULL,
4305 (hop) ? hop->cy_valueint : -1,
4306 (prio) ? prio->cy_valueint : -1,
4307 (sen) ? sen->cy_valueint : -1,
4308 (seq_no) ? seq_no->cy_valueint : -1,
4314 * 0: <intf_name>['['<expr>']']
4315 * 1: <intf_name>['['<expr>']']
4317 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4318 struct lnet_dlc_network_descr *nw_descr)
4320 struct cYAML *child = NULL;
4321 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4322 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4324 if (intf_tree == NULL || nw_descr == NULL)
4325 return LUSTRE_CFG_RC_BAD_PARAM;
4327 /* now grab all the interfaces and their cpts */
4328 child = intf_tree->cy_child;
4329 while (child != NULL) {
4330 if (child->cy_valuestring == NULL) {
4331 child = child->cy_next;
4335 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4338 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4339 child->cy_valuestring,
4340 strlen(child->cy_valuestring));
4341 if (rc != LUSTRE_CFG_RC_NO_ERR)
4345 child = child->cy_next;
4349 return LUSTRE_CFG_RC_MISSING_PARAM;
4354 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4356 list_del(&intf_descr->intf_on_network);
4357 free_intf_descr(intf_descr);
4364 yaml_extract_cmn_tunables(struct cYAML *tree,
4365 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4366 struct cfs_expr_list **global_cpts)
4368 struct cYAML *tun, *item, *smp;
4371 tun = cYAML_get_object_item(tree, "tunables");
4373 item = cYAML_get_object_item(tun, "peer_timeout");
4375 tunables->lct_peer_timeout = item->cy_valueint;
4376 item = cYAML_get_object_item(tun, "peer_credits");
4378 tunables->lct_peer_tx_credits = item->cy_valueint;
4379 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4381 tunables->lct_peer_rtr_credits = item->cy_valueint;
4382 item = cYAML_get_object_item(tun, "credits");
4384 tunables->lct_max_tx_credits = item->cy_valueint;
4385 smp = cYAML_get_object_item(tun, "CPT");
4387 rc = cfs_expr_list_parse(smp->cy_valuestring,
4388 strlen(smp->cy_valuestring),
4389 0, UINT_MAX, global_cpts);
4391 *global_cpts = NULL;
4401 yaml_extract_tunables(struct cYAML *tree,
4402 struct lnet_ioctl_config_lnd_tunables *tunables,
4403 struct cfs_expr_list **global_cpts,
4408 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4414 lustre_yaml_extract_lnd_tunables(tree, net_type,
4422 * - net type: <net>[<NUM>]
4424 * - nid: <ip>@<net>[<NUM>]
4427 * 0: <intf_name>['['<expr>']']
4428 * 1: <intf_name>['['<expr>']']
4430 * peer_timeout: <NUM>
4431 * peer_credits: <NUM>
4432 * peer_buffer_credits: <NUM>
4435 * peercredits_hiw: <NUM>
4436 * map_on_demand: <NUM>
4437 * concurrent_sends: <NUM>
4438 * fmr_pool_size: <NUM>
4439 * fmr_flush_trigger: <NUM>
4442 * At least one interface is required. If no interfaces are provided the
4443 * network interface can not be configured.
4445 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4446 struct cYAML **err_rc)
4448 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4450 int num_entries = 0, rc;
4451 struct lnet_dlc_network_descr nw_descr;
4452 struct cfs_expr_list *global_cpts = NULL;
4453 struct lnet_ioctl_config_lnd_tunables tunables;
4456 memset(&tunables, 0, sizeof(tunables));
4458 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4459 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4461 ip2net = cYAML_get_object_item(tree, "ip2net");
4462 net = cYAML_get_object_item(tree, "net type");
4464 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4466 nw_descr.nw_id = LOLND;
4469 * if neither net nor ip2nets are present, then we can not
4470 * configure the network.
4472 if (!net && !ip2net)
4473 return LUSTRE_CFG_RC_MISSING_PARAM;
4475 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4476 if (local_nis == NULL)
4477 return LUSTRE_CFG_RC_MISSING_PARAM;
4479 if (!cYAML_is_sequence(local_nis))
4480 return LUSTRE_CFG_RC_BAD_PARAM;
4482 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4483 intf = cYAML_get_object_item(item, "interfaces");
4486 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4487 if (num_entries <= 0) {
4488 cYAML_build_error(num_entries, -1, "ni", "add",
4489 "bad interface list",
4491 return LUSTRE_CFG_RC_BAD_PARAM;
4495 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4496 LNET_NETTYP(nw_descr.nw_id));
4497 seq_no = cYAML_get_object_item(tree, "seq_no");
4499 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4500 (ip2net) ? ip2net->cy_valuestring : NULL,
4501 (found) ? &tunables : NULL, -1,
4502 (seq_no) ? seq_no->cy_valueint : -1,
4505 if (global_cpts != NULL)
4506 cfs_expr_list_free(global_cpts);
4513 * - net-spec: <tcp|o2ib|gni>[NUM]
4515 * 0: <intf name>['['<expr>']']
4516 * 1: <intf name>['['<expr>']']
4518 * 0: <expr.expr.expr.expr>
4519 * 1: <expr.expr.expr.expr>
4521 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4522 struct cYAML **show_rc,
4523 struct cYAML **err_rc)
4525 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4527 struct lustre_lnet_ip2nets ip2nets;
4528 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4530 int rc = LUSTRE_CFG_RC_NO_ERR;
4531 struct cfs_expr_list *global_cpts = NULL;
4532 struct cfs_expr_list *el, *el_tmp;
4533 struct lnet_ioctl_config_lnd_tunables tunables;
4534 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4537 memset(&tunables, 0, sizeof(tunables));
4539 /* initialize all lists */
4540 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4541 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4542 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4544 net = cYAML_get_object_item(tree, "net-spec");
4546 return LUSTRE_CFG_RC_BAD_PARAM;
4548 if (net != NULL && net->cy_valuestring == NULL)
4549 return LUSTRE_CFG_RC_BAD_PARAM;
4551 /* assign the network id */
4552 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4553 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4554 return LUSTRE_CFG_RC_BAD_PARAM;
4556 seq_no = cYAML_get_object_item(tree, "seq_no");
4558 intf = cYAML_get_object_item(tree, "interfaces");
4560 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4562 return LUSTRE_CFG_RC_BAD_PARAM;
4565 ip_range = cYAML_get_object_item(tree, "ip-range");
4566 if (ip_range != NULL) {
4567 item = ip_range->cy_child;
4568 while (item != NULL) {
4569 if (item->cy_valuestring == NULL) {
4570 item = item->cy_next;
4574 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4575 item->cy_valuestring);
4577 if (rc != LUSTRE_CFG_RC_NO_ERR)
4580 item = item->cy_next;
4584 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4585 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4587 rc = lustre_lnet_config_ip2nets(&ip2nets,
4588 (found) ? &tunables : NULL,
4590 (seq_no) ? seq_no->cy_valueint : -1,
4594 * don't stop because there was no match. Continue processing the
4595 * rest of the rules. If non-match then nothing is configured
4597 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4598 rc = LUSTRE_CFG_RC_NO_ERR;
4600 list_for_each_entry_safe(intf_descr, intf_tmp,
4601 &ip2nets.ip2nets_net.nw_intflist,
4603 list_del(&intf_descr->intf_on_network);
4604 free_intf_descr(intf_descr);
4607 list_for_each_entry_safe(ip_range_descr, tmp,
4608 &ip2nets.ip2nets_ip_ranges,
4610 list_del(&ip_range_descr->ipr_entry);
4611 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4613 list_del(&el->el_link);
4614 cfs_expr_list_free(el);
4616 free(ip_range_descr);
4622 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4623 struct cYAML **err_rc)
4625 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4627 int num_entries, rc;
4628 struct lnet_dlc_network_descr nw_descr;
4630 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4631 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4633 net = cYAML_get_object_item(tree, "net type");
4635 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4637 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4638 if (local_nis == NULL)
4639 return LUSTRE_CFG_RC_MISSING_PARAM;
4641 if (!cYAML_is_sequence(local_nis))
4642 return LUSTRE_CFG_RC_BAD_PARAM;
4644 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4645 intf = cYAML_get_object_item(item, "interfaces");
4648 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4649 if (num_entries <= 0) {
4650 cYAML_build_error(num_entries, -1, "ni", "add",
4651 "bad interface list",
4653 return LUSTRE_CFG_RC_BAD_PARAM;
4657 seq_no = cYAML_get_object_item(tree, "seq_no");
4659 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4660 (seq_no) ? seq_no->cy_valueint : -1,
4666 /* Create a nidstring parseable by the nidstrings library from the nid
4667 * information encoded in the CYAML structure.
4668 * NOTE: Caller must free memory allocated to nidstr
4670 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4671 char *prim_nid, int cmd)
4673 int num_strs = 0, rc;
4674 size_t buf_size, buf_pos, nidstr_len = 0;
4676 struct cYAML *child = NULL, *entry = NULL;
4678 if (cYAML_is_sequence(nids_entry)) {
4679 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4680 entry = cYAML_get_object_item(child, "nid");
4681 /* don't count an empty entry */
4682 if (!entry || !entry->cy_valuestring)
4686 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4687 if (cmd == LNETCTL_DEL_CMD) {
4689 * primary nid is present in the list of
4690 * nids so that means we want to delete
4691 * the entire peer, so no need to go
4692 * further. Just delete the entire peer.
4694 return LUSTRE_CFG_RC_NO_ERR;
4701 * + 1 for the space separating each string, and
4702 * accounts for the terminating null char
4704 nidstr_len += strlen(entry->cy_valuestring) + 1;
4709 if (num_strs == 0 && !prim_nid)
4710 return LUSTRE_CFG_RC_MISSING_PARAM;
4711 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4712 return LUSTRE_CFG_RC_NO_ERR;
4714 buffer = malloc(nidstr_len);
4716 return LUSTRE_CFG_RC_OUT_OF_MEM;
4718 /* now grab all the nids */
4721 buf_size = nidstr_len;
4723 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4724 entry = cYAML_get_object_item(child, "nid");
4725 if (!entry || !entry->cy_valuestring)
4729 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4733 rc = snprintf(buffer + buf_pos, buf_size, " ");
4734 buf_pos += (rc < buf_size) ? rc : buf_size;
4735 buf_size = nidstr_len - buf_pos;
4738 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4739 entry->cy_valuestring);
4740 buf_pos += (rc < buf_size) ? rc : buf_size;
4741 buf_size = nidstr_len - buf_pos;
4746 return LUSTRE_CFG_RC_NO_ERR;
4749 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4750 struct cYAML **err_rc, int cmd)
4752 int rc, num_nids = 0, seqn;
4753 bool mr_value = false;
4754 char *nidstr = NULL, *prim_nidstr;
4755 char err_str[LNET_MAX_STR_LEN];
4756 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4757 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4758 lnet_nid_t pnid = LNET_NID_ANY;
4760 seq_no = cYAML_get_object_item(tree, "seq_no");
4761 seqn = seq_no ? seq_no->cy_valueint : -1;
4763 prim_nid = cYAML_get_object_item(tree, "primary nid");
4764 peer_nis = cYAML_get_object_item(tree, "peer ni");
4766 rc = LUSTRE_CFG_RC_BAD_PARAM;
4767 snprintf(err_str, LNET_MAX_STR_LEN,
4768 "\"primary nid\" must be specified");
4772 prim_nidstr = prim_nid->cy_valuestring;
4774 /* if the provided primary NID is bad, no need to go any further */
4775 pnid = libcfs_str2nid(prim_nidstr);
4776 if (pnid == LNET_NID_ANY) {
4777 rc = LUSTRE_CFG_RC_BAD_PARAM;
4778 snprintf(err_str, LNET_MAX_STR_LEN,
4779 "badly formatted primary NID: %s", prim_nidstr);
4783 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4784 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4785 snprintf(err_str, LNET_MAX_STR_LEN,
4786 "No nids defined in YAML block");
4788 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4789 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4791 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4792 snprintf(err_str, LNET_MAX_STR_LEN,
4793 "Unrecognized error %d", rc);
4799 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4800 LNET_MAX_NIDS_PER_PEER,
4808 if (cmd == LNETCTL_ADD_CMD) {
4809 mr = cYAML_get_object_item(tree, "Multi-Rail");
4811 if (mr && mr->cy_valuestring) {
4812 if (strcmp(mr->cy_valuestring, "False") == 0)
4814 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4815 rc = LUSTRE_CFG_RC_BAD_PARAM;
4816 snprintf(err_str, LNET_MAX_STR_LEN,
4817 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4818 mr->cy_valuestring);
4824 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4825 num_nids, mr_value, seqn,
4832 if (rc != LUSTRE_CFG_RC_NO_ERR)
4833 cYAML_build_error(rc, seqn, "peer",
4834 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4840 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4841 struct cYAML **err_rc)
4843 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4846 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4847 struct cYAML **err_rc)
4849 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4852 static int handle_yaml_config_buffers(struct cYAML *tree,
4853 struct cYAML **show_rc,
4854 struct cYAML **err_rc)
4857 struct cYAML *tiny, *small, *large, *seq_no;
4859 tiny = cYAML_get_object_item(tree, "tiny");
4860 small = cYAML_get_object_item(tree, "small");
4861 large = cYAML_get_object_item(tree, "large");
4862 seq_no = cYAML_get_object_item(tree, "seq_no");
4864 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4865 (small) ? small->cy_valueint : -1,
4866 (large) ? large->cy_valueint : -1,
4867 (seq_no) ? seq_no->cy_valueint : -1,
4873 static int handle_yaml_config_routing(struct cYAML *tree,
4874 struct cYAML **show_rc,
4875 struct cYAML **err_rc)
4877 int rc = LUSTRE_CFG_RC_NO_ERR;
4878 struct cYAML *seq_no, *enable;
4880 seq_no = cYAML_get_object_item(tree, "seq_no");
4881 enable = cYAML_get_object_item(tree, "enable");
4884 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4886 seq_no->cy_valueint : -1,
4893 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4894 struct cYAML **err_rc)
4898 struct cYAML *seq_no;
4900 net = cYAML_get_object_item(tree, "net");
4901 gw = cYAML_get_object_item(tree, "gateway");
4902 seq_no = cYAML_get_object_item(tree, "seq_no");
4904 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4905 (gw) ? gw->cy_valuestring : NULL,
4906 (seq_no) ? seq_no->cy_valueint : -1,
4910 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4911 struct cYAML **err_rc)
4913 struct cYAML *seq_no;
4915 seq_no = cYAML_get_object_item(tree, "seq_no");
4917 return lustre_lnet_enable_routing(0, (seq_no) ?
4918 seq_no->cy_valueint : -1,
4922 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4923 struct cYAML **err_rc)
4929 struct cYAML *detail;
4930 struct cYAML *seq_no;
4932 net = cYAML_get_object_item(tree, "net");
4933 gw = cYAML_get_object_item(tree, "gateway");
4934 hop = cYAML_get_object_item(tree, "hop");
4935 prio = cYAML_get_object_item(tree, "priority");
4936 detail = cYAML_get_object_item(tree, "detail");
4937 seq_no = cYAML_get_object_item(tree, "seq_no");
4939 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4940 (gw) ? gw->cy_valuestring : NULL,
4941 (hop) ? hop->cy_valueint : -1,
4942 (prio) ? prio->cy_valueint : -1,
4943 (detail) ? detail->cy_valueint : 0,
4944 (seq_no) ? seq_no->cy_valueint : -1,
4945 show_rc, err_rc, false);
4948 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4949 struct cYAML **err_rc)
4951 struct cYAML *net, *detail, *seq_no;
4953 net = cYAML_get_object_item(tree, "net");
4954 detail = cYAML_get_object_item(tree, "detail");
4955 seq_no = cYAML_get_object_item(tree, "seq_no");
4957 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4958 (detail) ? detail->cy_valueint : 0,
4959 (seq_no) ? seq_no->cy_valueint : -1,
4960 show_rc, err_rc, false);
4963 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4964 struct cYAML **err_rc)
4966 struct cYAML *seq_no;
4968 seq_no = cYAML_get_object_item(tree, "seq_no");
4970 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4971 show_rc, err_rc, false);
4974 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4975 struct cYAML **err_rc)
4977 struct cYAML *seq_no, *nid, *detail;
4979 seq_no = cYAML_get_object_item(tree, "seq_no");
4980 detail = cYAML_get_object_item(tree, "detail");
4981 nid = cYAML_get_object_item(tree, "nid");
4983 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4984 (detail) ? detail->cy_valueint : 0,
4985 (seq_no) ? seq_no->cy_valueint : -1,
4986 show_rc, err_rc, false);
4989 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4990 struct cYAML **err_rc)
4992 struct cYAML *seq_no;
4994 seq_no = cYAML_get_object_item(tree, "seq_no");
4996 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5000 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5001 struct cYAML **err_rc)
5003 struct cYAML *seq_no, *range;
5005 seq_no = cYAML_get_object_item(tree, "seq_no");
5006 range = cYAML_get_object_item(tree, "range");
5008 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5009 seq_no ? seq_no->cy_valueint : -1,
5013 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5014 struct cYAML **err_rc)
5016 struct cYAML *seq_no;
5018 seq_no = cYAML_get_object_item(tree, "seq_no");
5020 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5024 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5025 struct cYAML **err_rc)
5027 struct cYAML *seq_no;
5029 seq_no = cYAML_get_object_item(tree, "seq_no");
5031 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5035 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5036 struct cYAML **err_rc)
5038 struct cYAML *seq_no, *idx;
5040 seq_no = cYAML_get_object_item(tree, "seq_no");
5041 idx = cYAML_get_object_item(tree, "idx");
5043 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5044 seq_no ? seq_no->cy_valueint : -1,
5048 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5049 struct cYAML **err_rc)
5051 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5052 union lnet_udsp_action action;
5054 seq_no = cYAML_get_object_item(tree, "seq_no");
5055 src = cYAML_get_object_item(tree, "src");
5056 rte = cYAML_get_object_item(tree, "rte");
5057 dst = cYAML_get_object_item(tree, "dst");
5058 prio = cYAML_get_object_item(tree, "priority");
5059 idx = cYAML_get_object_item(tree, "idx");
5061 action.udsp_priority = prio ? prio->cy_valueint : -1;
5063 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5064 dst ? dst->cy_valuestring : NULL,
5065 rte ? rte->cy_valuestring : NULL,
5066 prio ? "priority" : "",
5068 idx ? idx->cy_valueint : -1,
5069 seq_no ? seq_no->cy_valueint : -1,
5073 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5074 struct cYAML **err_rc)
5076 struct cYAML *seq_no;
5079 seq_no = cYAML_get_object_item(tree, "seq_no");
5080 idx = cYAML_get_object_item(tree, "idx");
5082 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5083 seq_no ? seq_no->cy_valueint : -1,
5087 static int handle_yaml_config_global_settings(struct cYAML *tree,
5088 struct cYAML **show_rc,
5089 struct cYAML **err_rc)
5091 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5092 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5096 seq_no = cYAML_get_object_item(tree, "seq_no");
5097 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5098 if (!max_intf) /* try legacy name */
5099 max_intf = cYAML_get_object_item(tree, "max_intf");
5101 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5102 seq_no ? seq_no->cy_valueint
5106 numa = cYAML_get_object_item(tree, "numa_range");
5108 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5109 seq_no ? seq_no->cy_valueint
5113 discovery = cYAML_get_object_item(tree, "discovery");
5115 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5116 seq_no ? seq_no->cy_valueint
5120 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5121 if (drop_asym_route)
5122 rc = lustre_lnet_config_drop_asym_route(
5123 drop_asym_route->cy_valueint,
5124 seq_no ? seq_no->cy_valueint : -1,
5127 retry = cYAML_get_object_item(tree, "retry_count");
5129 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5130 seq_no ? seq_no->cy_valueint
5134 tto = cYAML_get_object_item(tree, "transaction_timeout");
5136 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5137 seq_no ? seq_no->cy_valueint
5141 sen = cYAML_get_object_item(tree, "health_sensitivity");
5143 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5144 seq_no ? seq_no->cy_valueint
5148 recov = cYAML_get_object_item(tree, "recovery_interval");
5150 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5151 seq_no ? seq_no->cy_valueint
5155 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5157 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5158 seq_no ? seq_no->cy_valueint
5162 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5164 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5165 seq_no ? seq_no->cy_valueint
5169 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5171 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5172 seq_no ? seq_no->cy_valueint
5179 static int handle_yaml_del_global_settings(struct cYAML *tree,
5180 struct cYAML **show_rc,
5181 struct cYAML **err_rc)
5183 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5186 seq_no = cYAML_get_object_item(tree, "seq_no");
5187 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5188 if (!max_intf) /* try legacy name */
5189 max_intf = cYAML_get_object_item(tree, "max_intf");
5191 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5192 seq_no ? seq_no->cy_valueint
5196 numa = cYAML_get_object_item(tree, "numa_range");
5198 rc = lustre_lnet_config_numa_range(0,
5199 seq_no ? seq_no->cy_valueint
5203 /* peer discovery is enabled by default */
5204 discovery = cYAML_get_object_item(tree, "discovery");
5206 rc = lustre_lnet_config_discovery(1,
5207 seq_no ? seq_no->cy_valueint
5211 /* asymmetrical route messages are accepted by default */
5212 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5213 if (drop_asym_route)
5214 rc = lustre_lnet_config_drop_asym_route(
5215 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5220 static int handle_yaml_show_global_settings(struct cYAML *tree,
5221 struct cYAML **show_rc,
5222 struct cYAML **err_rc)
5224 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5225 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5229 seq_no = cYAML_get_object_item(tree, "seq_no");
5230 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5231 if (!max_intf) /* try legacy name */
5232 max_intf = cYAML_get_object_item(tree, "max_intf");
5234 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5238 numa = cYAML_get_object_item(tree, "numa_range");
5240 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5244 discovery = cYAML_get_object_item(tree, "discovery");
5246 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5250 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5251 if (drop_asym_route)
5252 rc = lustre_lnet_show_drop_asym_route(
5253 seq_no ? seq_no->cy_valueint : -1,
5256 retry = cYAML_get_object_item(tree, "retry_count");
5258 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5262 tto = cYAML_get_object_item(tree, "transaction_timeout");
5264 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5268 sen = cYAML_get_object_item(tree, "health_sensitivity");
5270 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5274 recov = cYAML_get_object_item(tree, "recovery_interval");
5276 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5280 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5282 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5286 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5288 rc = lustre_lnet_show_response_tracking(seq_no ?
5289 seq_no->cy_valueint :
5293 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5295 rc = lustre_lnet_show_recovery_limit(seq_no ?
5296 seq_no->cy_valueint :
5303 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5304 struct cYAML **err_rc)
5306 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5308 seq_no = cYAML_get_object_item(tree, "seq_no");
5309 nid = cYAML_get_object_item(tree, "primary nid");
5310 timeout = cYAML_get_object_item(tree, "timeout");
5311 src_nid = cYAML_get_object_item(tree, "source_nid");
5313 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5314 (src_nid) ? src_nid->cy_valuestring : NULL,
5315 (timeout) ? timeout->cy_valueint : 1000,
5316 (seq_no) ? seq_no->cy_valueint : -1,
5320 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5321 struct cYAML **err_rc)
5323 struct cYAML *seq_no, *nid, *force;
5325 seq_no = cYAML_get_object_item(tree, "seq_no");
5326 nid = cYAML_get_object_item(tree, "primary nid");
5327 force = cYAML_get_object_item(tree, "force");
5329 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5330 (force) ? force->cy_valueint : 0,
5331 (seq_no) ? seq_no->cy_valueint : -1,
5335 static int handle_yaml_no_op()
5337 return LUSTRE_CFG_RC_NO_ERR;
5340 struct lookup_cmd_hdlr_tbl {
5345 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5346 { .name = "route", .cb = handle_yaml_config_route },
5347 { .name = "net", .cb = handle_yaml_config_ni },
5348 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5349 { .name = "peer", .cb = handle_yaml_config_peer },
5350 { .name = "routing", .cb = handle_yaml_config_routing },
5351 { .name = "buffers", .cb = handle_yaml_config_buffers },
5352 { .name = "statistics", .cb = handle_yaml_no_op },
5353 { .name = "global", .cb = handle_yaml_config_global_settings},
5354 { .name = "numa", .cb = handle_yaml_config_numa },
5355 { .name = "ping", .cb = handle_yaml_no_op },
5356 { .name = "discover", .cb = handle_yaml_no_op },
5357 { .name = "udsp", .cb = handle_yaml_config_udsp },
5360 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5361 { .name = "route", .cb = handle_yaml_del_route },
5362 { .name = "net", .cb = handle_yaml_del_ni },
5363 { .name = "ip2nets", .cb = handle_yaml_no_op },
5364 { .name = "peer", .cb = handle_yaml_del_peer },
5365 { .name = "routing", .cb = handle_yaml_del_routing },
5366 { .name = "buffers", .cb = handle_yaml_no_op },
5367 { .name = "statistics", .cb = handle_yaml_no_op },
5368 { .name = "global", .cb = handle_yaml_del_global_settings},
5369 { .name = "numa", .cb = handle_yaml_del_numa },
5370 { .name = "ping", .cb = handle_yaml_no_op },
5371 { .name = "discover", .cb = handle_yaml_no_op },
5372 { .name = "udsp", .cb = handle_yaml_del_udsp },
5375 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5376 { .name = "route", .cb = handle_yaml_show_route },
5377 { .name = "net", .cb = handle_yaml_show_net },
5378 { .name = "peer", .cb = handle_yaml_show_peers },
5379 { .name = "ip2nets", .cb = handle_yaml_no_op },
5380 { .name = "routing", .cb = handle_yaml_show_routing },
5381 { .name = "buffers", .cb = handle_yaml_show_routing },
5382 { .name = "statistics", .cb = handle_yaml_show_stats },
5383 { .name = "global", .cb = handle_yaml_show_global_settings},
5384 { .name = "numa", .cb = handle_yaml_show_numa },
5385 { .name = "ping", .cb = handle_yaml_no_op },
5386 { .name = "discover", .cb = handle_yaml_no_op },
5387 { .name = "udsp", .cb = handle_yaml_show_udsp },
5390 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5391 { .name = "route", .cb = handle_yaml_no_op },
5392 { .name = "net", .cb = handle_yaml_no_op },
5393 { .name = "peer", .cb = handle_yaml_no_op },
5394 { .name = "ip2nets", .cb = handle_yaml_no_op },
5395 { .name = "routing", .cb = handle_yaml_no_op },
5396 { .name = "buffers", .cb = handle_yaml_no_op },
5397 { .name = "statistics", .cb = handle_yaml_no_op },
5398 { .name = "global", .cb = handle_yaml_no_op },
5399 { .name = "numa", .cb = handle_yaml_no_op },
5400 { .name = "ping", .cb = handle_yaml_ping },
5401 { .name = "discover", .cb = handle_yaml_discover },
5404 static cmd_handler_t lookup_fn(char *key,
5405 struct lookup_cmd_hdlr_tbl *tbl)
5411 for (i = 0; tbl[i].name != NULL; i++) {
5412 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5419 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5420 struct cYAML **show_rc, struct cYAML **err_rc)
5422 struct cYAML *tree, *item = NULL, *head, *child;
5424 char err_str[LNET_MAX_STR_LEN];
5425 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5427 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5429 return LUSTRE_CFG_RC_BAD_PARAM;
5431 child = tree->cy_child;
5432 while (child != NULL) {
5433 cb = lookup_fn(child->cy_string, table);
5435 snprintf(err_str, sizeof(err_str),
5436 "\"call back for '%s' not found\"",
5438 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5439 "yaml", "helper", err_str, err_rc);
5443 if (cYAML_is_sequence(child)) {
5444 while ((head = cYAML_get_next_seq_item(child, &item))
5446 rc = cb(head, show_rc, err_rc);
5447 if (rc != LUSTRE_CFG_RC_NO_ERR)
5451 rc = cb(child, show_rc, err_rc);
5452 if (rc != LUSTRE_CFG_RC_NO_ERR)
5456 child = child->cy_next;
5460 cYAML_free_tree(tree);
5465 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5467 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5471 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5473 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5477 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5479 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5483 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5485 return lustre_yaml_cb_helper(f, lookup_exec_tbl,