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 *oper, int param, int ioc_call,
424 int seq_no, struct cYAML **show_rc,
425 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;
440 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
442 data = calloc(1, len);
446 /* create struct cYAML root object */
447 root = cYAML_create_object(NULL, NULL);
451 ping_node = cYAML_create_seq(root, oper);
452 if (ping_node == NULL)
455 /* tokenise each nid in string ping_nids */
456 token = strtok(ping_nids, ",");
459 item = cYAML_create_seq_item(ping_node);
463 if (first_seq == NULL)
466 /* check if '-' is a part of NID, token */
467 sep = strchr(token, '-');
469 id.pid = LNET_PID_ANY;
470 /* if no net is specified, libcfs_str2nid() will assume tcp */
471 id.nid = libcfs_str2nid(token);
472 if (id.nid == LNET_NID_ANY) {
473 snprintf(err_str, sizeof(err_str),
474 "\"cannot parse NID '%s'\"",
476 rc = LUSTRE_CFG_RC_BAD_PARAM;
477 cYAML_build_error(rc, seq_no, MANAGE_CMD,
478 oper, err_str, err_rc);
482 if (token[0] == 'u' || token[0] == 'U')
483 id.pid = (strtoul(&token[1], &end, 0) |
484 (LNET_PID_USERFLAG));
486 id.pid = strtoul(token, &end, 0);
488 /* assuming '-' is part of hostname */
490 id.pid = LNET_PID_ANY;
491 id.nid = libcfs_str2nid(token);
492 if (id.nid == LNET_NID_ANY) {
493 snprintf(err_str, sizeof(err_str),
494 "\"cannot parse NID '%s'\"",
496 rc = LUSTRE_CFG_RC_BAD_PARAM;
497 cYAML_build_error(rc, seq_no, MANAGE_CMD,
503 id.nid = libcfs_str2nid(sep + 1);
504 if (id.nid == LNET_NID_ANY) {
505 snprintf(err_str, sizeof(err_str),
506 "\"cannot parse NID '%s'\"",
508 rc = LUSTRE_CFG_RC_BAD_PARAM;
509 cYAML_build_error(rc, seq_no, MANAGE_CMD,
516 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
517 ping.ping_hdr.ioc_len = sizeof(ping);
519 ping.op_param = param;
520 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
521 ping.ping_buf = data;
523 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
526 sizeof(err_str), "failed to %s %s: %s\n", oper,
527 id.pid == LNET_PID_ANY ?
528 libcfs_nid2str(id.nid) :
529 libcfs_id2str(id), strerror(errno));
530 rc = LUSTRE_CFG_RC_BAD_PARAM;
531 cYAML_build_error(rc, seq_no, MANAGE_CMD,
532 oper, err_str, err_rc);
536 if (cYAML_create_string(item, "primary nid",
537 libcfs_nid2str(ping.ping_id.nid)) == NULL)
540 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
541 "True" : "False") == NULL)
544 tmp = cYAML_create_seq(item, "peer ni");
548 for (i = 0; i < ping.ping_count; i++) {
549 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
551 peer_ni = cYAML_create_seq_item(tmp);
554 memset(buf, 0, sizeof buf);
555 snprintf(buf, sizeof buf, "nid");
556 if (cYAML_create_string(peer_ni, buf,
557 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
563 } while ((token = strtok(NULL, ",")) != NULL);
566 rc = LUSTRE_CFG_RC_NO_ERR;
571 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
572 cYAML_free_tree(root);
573 } else if (show_rc != NULL && *show_rc != NULL) {
574 struct cYAML *show_node;
575 show_node = cYAML_get_object_item(*show_rc, oper);
576 if (show_node != NULL && cYAML_is_sequence(show_node)) {
577 cYAML_insert_child(show_node, first_seq);
580 } else if (show_node == NULL) {
581 cYAML_insert_sibling((*show_rc)->cy_child,
585 cYAML_free_tree(root);
594 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
595 struct cYAML **show_rc, struct cYAML **err_rc)
599 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
600 seq_no, show_rc, err_rc);
604 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
605 struct cYAML **show_rc, struct cYAML **err_rc)
609 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
610 seq_no, show_rc, err_rc);
614 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
615 bool is_mr, __u32 cmd,
616 char *cmd_type, char *err_str)
618 struct lnet_ioctl_peer_cfg data;
621 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
622 /* When adding a peer we first need to create the peer using the
623 * specified (or implied) primary nid. Then we can add
624 * additional nids to this peer using the primary nid as a key
626 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
627 data.prcfg_mr = is_mr;
628 data.prcfg_prim_nid = nidlist[0];
629 data.prcfg_cfg_nid = LNET_NID_ANY;
631 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
637 /* Add or delete any specified NIs associated with the specified
638 * (or implied) primary nid
640 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
641 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
642 data.prcfg_mr = is_mr;
643 data.prcfg_prim_nid = nidlist[0];
644 data.prcfg_cfg_nid = nidlist[nid_idx];
646 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
652 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
653 /* In the delete case we may have been given just the
654 * primary nid of the peer. This tells us to delete the peer
655 * completely (rather than just delete some of its NIs)
657 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
658 data.prcfg_prim_nid = nidlist[0];
659 data.prcfg_cfg_nid = LNET_NID_ANY;
661 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
668 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
669 int cmd, int num_nids, bool is_mr, int seq_no,
670 struct cYAML **err_rc)
672 int rc = LUSTRE_CFG_RC_NO_ERR;
673 char err_str[LNET_MAX_STR_LEN];
674 lnet_nid_t *lnet_nidlist2 = NULL;
675 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
676 IOC_LIBCFS_DEL_PEER_NI;
677 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
680 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
681 if (!lnet_nidlist2) {
682 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
683 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
686 lnet_nidlist2[0] = pnid;
687 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
690 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
691 num_nids, is_mr, ioc_cmd,
697 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
702 replace_sep(char *str, char sep, char newsep)
708 for (i = 0; i < strlen(str); i++) {
709 /* don't replace ',' within [] */
712 else if (str[i] == ']')
714 else if (str[i] == sep && bracket == 0)
719 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
720 int cmd, int seq_no, struct cYAML **err_rc)
723 char err_str[LNET_MAX_STR_LEN] = "Error";
724 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
725 lnet_nid_t pnid = LNET_NID_ANY;
728 rc = LUSTRE_CFG_RC_BAD_PARAM;
729 snprintf(err_str, LNET_MAX_STR_LEN,
730 "--prim_nid must be specified");
734 pnid = libcfs_str2nid(prim_nid);
735 if (pnid == LNET_NID_ANY) {
736 rc = LUSTRE_CFG_RC_BAD_PARAM;
737 snprintf(err_str, LNET_MAX_STR_LEN,
738 "badly formatted primary NID: %s", prim_nid);
745 * if there is no primary nid we need to make the first nid in the
746 * nids list the primary nid
748 replace_sep(nids, ',', ' ');
749 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
750 LNET_MAX_NIDS_PER_PEER, err_str);
757 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
758 cmd, num_nids, is_mr,
762 if (rc != LUSTRE_CFG_RC_NO_ERR)
763 cYAML_build_error(rc, -1, "peer",
764 cmd == LNETCTL_ADD_CMD ? "add" : "del",
770 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
771 int sen, int seq_no, struct cYAML **err_rc,
774 int rc, num_nids, idx;
776 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
777 struct lnet_ioctl_config_data data;
778 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
780 if (nw == NULL || nidstr == NULL) {
781 snprintf(err_str, LNET_MAX_STR_LEN,
782 "\"missing mandatory parameter:'%s'\"",
783 (nw == NULL && nidstr == NULL) ? "network, gateway" :
784 (nw == NULL) ? "network" : "gateway");
785 rc = LUSTRE_CFG_RC_MISSING_PARAM;
789 rnet = libcfs_str2net(nw);
790 if (rnet == LNET_NET_ANY) {
791 snprintf(err_str, LNET_MAX_STR_LEN,
792 "\"cannot parse remote net %s\"", nw);
793 rc = LUSTRE_CFG_RC_BAD_PARAM;
797 replace_sep(nidstr, ',', ' ');
798 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
799 LNET_MAX_NIDS_PER_PEER, err_str);
805 for (idx = 0; idx < num_nids; idx++) {
806 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
808 if (cmd == LNETCTL_ADD_CMD) {
809 data.cfg_config_u.cfg_route.rtr_hop = hops;
810 data.cfg_config_u.cfg_route.rtr_priority = prio;
811 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
814 data.cfg_nid = lnet_nidlist[idx];
816 if (cmd == LNETCTL_ADD_CMD)
817 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
820 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
823 if (rc != 0 && errno != EEXIST &&
824 errno != EHOSTUNREACH) {
826 snprintf(err_str, LNET_MAX_STR_LEN,
827 "route operation failed: %s",
830 } else if (errno == EEXIST) {
832 * continue chugging along if one of the
833 * routes already exists
840 cYAML_build_error(rc, seq_no,
841 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
847 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
848 int sen, int seq_no, struct cYAML **err_rc)
851 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
854 hops = LNET_UNDEFINED_HOPS;
855 } else if (hops < 1 || hops > 255) {
856 snprintf(err_str, LNET_MAX_STR_LEN,
857 "\"invalid hop count %d, must be between 1 and 255\"",
859 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
865 } else if (prio < 0) {
866 snprintf(err_str, LNET_MAX_STR_LEN,
867 "\"invalid priority %d, must be greater than 0\"",
869 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
875 } else if (sen < 1) {
876 snprintf(err_str, LNET_MAX_STR_LEN,
877 "\"invalid health sensitivity %d, must be 1 or greater\"",
879 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
883 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
884 err_rc, LNETCTL_ADD_CMD);
887 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
892 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
893 struct cYAML **err_rc)
895 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
899 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
900 int seq_no, struct cYAML **show_rc,
901 struct cYAML **err_rc, bool backup)
903 struct lnet_ioctl_config_data data;
904 lnet_nid_t gateway_nid;
905 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
907 __u32 net = LNET_NET_ANY;
909 struct cYAML *root = NULL, *route = NULL, *item = NULL;
910 struct cYAML *first_seq = NULL;
911 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
915 net = libcfs_str2net(nw);
916 if (net == LNET_NET_ANY) {
919 "\"cannot parse net '%s'\"", nw);
920 rc = LUSTRE_CFG_RC_BAD_PARAM;
925 /* show all routes without filtering on net */
930 gateway_nid = libcfs_str2nid(gw);
931 if (gateway_nid == LNET_NID_ANY) {
934 "\"cannot parse gateway NID '%s'\"", gw);
935 rc = LUSTRE_CFG_RC_BAD_PARAM;
939 /* show all routes with out filtering on gateway */
940 gateway_nid = LNET_NID_ANY;
942 if ((hops < 1 && hops != -1) || hops > 255) {
945 "\"invalid hop count %d, must be between 0 and 256\"",
947 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
951 /* create struct cYAML root object */
952 root = cYAML_create_object(NULL, NULL);
956 route = cYAML_create_seq(root, "route");
964 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
967 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
973 /* filter on provided data */
974 if (net != LNET_NET_ANY &&
978 if (gateway_nid != LNET_NID_ANY &&
979 gateway_nid != data.cfg_nid)
983 hops != data.cfg_config_u.cfg_route.rtr_hop)
987 prio != data.cfg_config_u.cfg_route.rtr_priority)
990 /* default rc to -1 incase we hit the goto */
994 item = cYAML_create_seq_item(route);
998 if (first_seq == NULL)
1001 if (cYAML_create_string(item, "net",
1002 libcfs_net2str(data.cfg_net)) == NULL)
1005 if (cYAML_create_string(item, "gateway",
1006 libcfs_nid2str(data.cfg_nid)) == NULL)
1010 if (cYAML_create_number(item, "hop",
1011 (int) data.cfg_config_u.
1012 cfg_route.rtr_hop) ==
1016 if (cYAML_create_number(item, "priority",
1018 cfg_route.rtr_priority) == NULL)
1021 if (cYAML_create_number(item, "health_sensitivity",
1023 cfg_route.rtr_sensitivity) == NULL)
1026 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1028 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1032 cYAML_create_string(item, "state",
1034 "up" : "down") == NULL)
1038 cYAML_create_string(item, "type",
1040 "multi-hop" : "single-hop") == NULL)
1045 /* print output iff show_rc is not provided */
1046 if (show_rc == NULL)
1047 cYAML_print_tree(root);
1049 if (l_errno != ENOENT) {
1052 "\"cannot get routes: %s\"",
1057 rc = LUSTRE_CFG_RC_NO_ERR;
1059 snprintf(err_str, sizeof(err_str), "\"success\"");
1061 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1062 cYAML_free_tree(root);
1063 } else if (show_rc != NULL && *show_rc != NULL) {
1064 struct cYAML *show_node;
1065 /* find the route node, if one doesn't exist then
1066 * insert one. Otherwise add to the one there
1068 show_node = cYAML_get_object_item(*show_rc, "route");
1069 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1070 cYAML_insert_child(show_node, first_seq);
1073 } else if (show_node == NULL) {
1074 cYAML_insert_sibling((*show_rc)->cy_child,
1078 cYAML_free_tree(root);
1084 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1089 static int socket_intf_query(int request, char *intf,
1095 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1096 return LUSTRE_CFG_RC_BAD_PARAM;
1098 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1100 return LUSTRE_CFG_RC_BAD_PARAM;
1102 strcpy(ifr->ifr_name, intf);
1103 rc = ioctl(sockfd, request, ifr);
1105 rc = LUSTRE_CFG_RC_BAD_PARAM;
1112 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1117 memset(&ifr, 0, sizeof(ifr));
1118 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1120 return LUSTRE_CFG_RC_BAD_PARAM;
1122 if ((ifr.ifr_flags & IFF_UP) == 0)
1123 return LUSTRE_CFG_RC_BAD_PARAM;
1125 memset(&ifr, 0, sizeof(ifr));
1126 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1128 return LUSTRE_CFG_RC_BAD_PARAM;
1130 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1131 *ip = bswap_32(*ip);
1133 return LUSTRE_CFG_RC_NO_ERR;
1137 * for each interface in the array of interfaces find the IP address of
1138 * that interface, create its nid and add it to an array of NIDs.
1139 * Stop if any of the interfaces is down
1141 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1142 lnet_nid_t **nids, __u32 *nnids,
1143 char *err_str, size_t str_len)
1145 int i = 0, count = 0, rc;
1146 struct lnet_dlc_intf_descr *intf;
1147 char val[LNET_MAX_STR_LEN];
1154 if (nw == NULL || nids == NULL) {
1155 snprintf(err_str, str_len,
1156 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1157 return LUSTRE_CFG_RC_BAD_PARAM;
1160 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1163 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1167 *nids = calloc(count, sizeof(lnet_nid_t));
1168 if (*nids == NULL) {
1169 snprintf(err_str, str_len,
1170 "\"out of memory\"");
1171 return LUSTRE_CFG_RC_OUT_OF_MEM;
1174 * special case the GNI interface since it doesn't have an IP
1175 * address. The assumption is that there can only be one GNI
1176 * interface in the system. No interface name is provided.
1178 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1179 rc = read_sysfs_file(gni_nid_path, "nid", val,
1182 snprintf(err_str, str_len,
1183 "\"cannot read gni nid\"");
1186 gni_num = atoi(val);
1188 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1193 /* look at the other interfaces */
1194 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1195 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1196 /* handle LNDs with numeric interface name */
1197 num = strtoul(intf->intf_name, &endp, 0);
1198 if (endp == intf->intf_name || *endp != '\0') {
1199 rc = LUSTRE_CFG_RC_BAD_PARAM;
1200 snprintf(err_str, str_len,
1201 "\"couldn't query intf %s\"",
1205 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1208 /* handle LNDs with ip interface name */
1209 rc = lustre_lnet_queryip(intf, &ip);
1210 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1211 snprintf(err_str, str_len,
1212 "\"couldn't query intf %s\"",
1216 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1233 * called repeatedly until a match or no more ip range
1235 * ip_range expression
1236 * interface list with all the interface names.
1237 * all the interfaces in the system.
1239 * try to match the ip_range expr to one of the interfaces' IPs in
1240 * the system. If we hit a patch for an interface. Check if that
1241 * interface name is in the list.
1243 * If there are more than one interface in the list, then make sure
1244 * that the IPs for all of these interfaces match the ip ranges
1247 * for each interface in intf_list
1248 * look up the intf name in ifa
1249 * if not there then no match
1250 * check ip obtained from ifa against a match to any of the
1252 * If no match, then fail
1254 * The result is that all the interfaces have to match.
1256 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1257 struct list_head *intf_list,
1258 struct list_head *ip_ranges)
1262 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1263 struct ifaddrs *ifaddr = ifa;
1264 struct lustre_lnet_ip_range_descr *ip_range;
1268 * if there are no explicit interfaces, and no ip ranges, then
1269 * configure the first tcp interface we encounter.
1271 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1272 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1273 if (ifaddr->ifa_addr == NULL)
1276 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1279 family = ifaddr->ifa_addr->sa_family;
1280 if (family == AF_INET &&
1281 strcmp(ifaddr->ifa_name, "lo") != 0) {
1282 rc = lustre_lnet_add_intf_descr
1283 (intf_list, ifaddr->ifa_name,
1284 strlen(ifaddr->ifa_name));
1286 if (rc != LUSTRE_CFG_RC_NO_ERR)
1289 return LUSTRE_CFG_RC_MATCH;
1292 return LUSTRE_CFG_RC_NO_MATCH;
1296 * First interface which matches an IP pattern will be used
1298 if (list_empty(intf_list)) {
1300 * no interfaces provided in the rule, but an ip range is
1301 * provided, so try and match an interface to the ip
1304 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1305 if (ifaddr->ifa_addr == NULL)
1308 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1311 family = ifaddr->ifa_addr->sa_family;
1312 if (family == AF_INET) {
1313 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1316 list_for_each_entry(ip_range, ip_ranges,
1318 rc = cfs_ip_addr_match(bswap_32(ip),
1319 &ip_range->ipr_expr);
1323 rc = lustre_lnet_add_intf_descr
1324 (intf_list, ifaddr->ifa_name,
1325 strlen(ifaddr->ifa_name));
1327 if (rc != LUSTRE_CFG_RC_NO_ERR)
1333 if (!list_empty(intf_list))
1334 return LUSTRE_CFG_RC_MATCH;
1336 return LUSTRE_CFG_RC_NO_MATCH;
1340 * If an interface is explicitly specified the ip-range might or
1341 * might not be specified. if specified the interface needs to match the
1342 * ip-range. If no ip-range then the interfaces are
1343 * automatically matched if they are all up.
1344 * If > 1 interfaces all the interfaces must match for the NI to
1347 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1348 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1349 if (ifaddr->ifa_addr == NULL)
1352 family = ifaddr->ifa_addr->sa_family;
1353 if (family == AF_INET &&
1354 strcmp(intf_descr->intf_name,
1355 ifaddr->ifa_name) == 0)
1359 if (ifaddr == NULL) {
1360 list_del(&intf_descr->intf_on_network);
1361 free_intf_descr(intf_descr);
1365 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1366 list_del(&intf_descr->intf_on_network);
1367 free_intf_descr(intf_descr);
1371 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1374 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1375 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1381 /* no match for this interface */
1382 list_del(&intf_descr->intf_on_network);
1383 free_intf_descr(intf_descr);
1387 return LUSTRE_CFG_RC_MATCH;
1390 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1391 lnet_nid_t **nids, __u32 *nnids,
1392 char *err_str, size_t str_len)
1394 struct ifaddrs *ifa;
1395 int rc = LUSTRE_CFG_RC_NO_ERR;
1397 rc = getifaddrs(&ifa);
1399 snprintf(err_str, str_len,
1400 "\"failed to get interface addresses: %d\"", -errno);
1404 rc = lustre_lnet_match_ip_to_intf(ifa,
1405 &ip2nets->ip2nets_net.nw_intflist,
1406 &ip2nets->ip2nets_ip_ranges);
1407 if (rc != LUSTRE_CFG_RC_MATCH) {
1408 snprintf(err_str, str_len,
1409 "\"couldn't match ip to existing interfaces\"");
1414 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1416 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1427 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1428 struct lnet_ioctl_config_lnd_tunables *tunables,
1429 struct cfs_expr_list *global_cpts,
1430 lnet_nid_t *nids, char *err_str)
1433 struct lnet_ioctl_config_ni *conf;
1434 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1435 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1438 struct lnet_dlc_intf_descr *intf_descr;
1440 struct cfs_expr_list *cpt_expr;
1442 list_for_each_entry(intf_descr, intf_list,
1444 if (tunables != NULL)
1445 len = sizeof(struct lnet_ioctl_config_ni) +
1446 sizeof(struct lnet_ioctl_config_lnd_tunables);
1448 len = sizeof(struct lnet_ioctl_config_ni);
1450 data = calloc(1, len);
1452 return LUSTRE_CFG_RC_OUT_OF_MEM;
1453 conf = (struct lnet_ioctl_config_ni*) data;
1454 if (tunables != NULL)
1455 tun = (struct lnet_ioctl_config_lnd_tunables*)
1458 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1459 conf->lic_cfg_hdr.ioc_len = len;
1460 conf->lic_nid = nids[i];
1461 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1464 if (intf_descr->cpt_expr != NULL)
1465 cpt_expr = intf_descr->cpt_expr;
1466 else if (global_cpts != NULL)
1467 cpt_expr = global_cpts;
1471 if (cpt_expr != NULL) {
1472 count = cfs_expr_list_values(cpt_expr,
1473 LNET_MAX_SHOW_NUM_CPT,
1476 memcpy(conf->lic_cpts, cpt_array,
1477 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1486 conf->lic_ncpts = count;
1488 if (tunables != NULL)
1489 memcpy(tun, tunables, sizeof(*tunables));
1491 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1496 "\"cannot add network: %s\"", strerror(errno));
1504 return LUSTRE_CFG_RC_NO_ERR;
1508 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1509 struct lnet_ioctl_config_lnd_tunables *tunables,
1510 struct cfs_expr_list *global_cpts,
1511 int seq_no, struct cYAML **err_rc)
1513 lnet_nid_t *nids = NULL;
1516 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1521 "\"incomplete ip2nets information\"");
1522 rc = LUSTRE_CFG_RC_BAD_PARAM;
1527 * call below function to resolve the rules into a list of nids.
1528 * The memory is allocated in that function then freed here when
1529 * it's no longer needed.
1531 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1533 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1536 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1537 snprintf(err_str, sizeof(err_str),
1538 "\"no interfaces match ip2nets rules\"");
1542 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1543 tunables, global_cpts, nids,
1550 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1554 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1555 struct cfs_expr_list *global_cpts,
1557 struct lnet_ioctl_config_lnd_tunables *tunables,
1558 int seq_no, struct cYAML **err_rc)
1561 struct lnet_ioctl_config_ni *conf;
1562 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1563 char buf[LNET_MAX_STR_LEN];
1564 int rc = LUSTRE_CFG_RC_NO_ERR;
1565 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1566 lnet_nid_t *nids = NULL;
1570 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1573 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1574 (list_empty(&nw_descr->nw_intflist) &&
1575 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1578 "\"missing mandatory parameters in NI config: '%s'\"",
1579 (nw_descr == NULL) ? "network , interface" :
1580 (nw_descr->nw_id == 0) ? "network" : "interface");
1581 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1585 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1588 "\"ip2net string too long %d\"",
1589 (int)strlen(ip2net));
1590 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1594 if (ip2net != NULL) {
1595 if (tunables != NULL)
1596 len = sizeof(struct lnet_ioctl_config_ni) +
1597 sizeof(struct lnet_ioctl_config_lnd_tunables);
1599 len = sizeof(struct lnet_ioctl_config_ni);
1600 data = calloc(1, len);
1602 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1605 conf = (struct lnet_ioctl_config_ni*) data;
1606 if (tunables != NULL)
1607 tun = (struct lnet_ioctl_config_lnd_tunables*)
1608 (data + sizeof(*conf));
1610 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1611 conf->lic_cfg_hdr.ioc_len = len;
1612 strncpy(conf->lic_legacy_ip2nets, ip2net,
1615 if (global_cpts != NULL) {
1616 count = cfs_expr_list_values(global_cpts,
1617 LNET_MAX_SHOW_NUM_CPT,
1620 memcpy(conf->lic_cpts, cpt_array,
1621 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1630 conf->lic_ncpts = count;
1632 if (tunables != NULL)
1633 memcpy(tun, tunables, sizeof(*tunables));
1635 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1640 "\"cannot add network: %s\"", strerror(errno));
1647 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1648 rc = LUSTRE_CFG_RC_NO_ERR;
1652 if (nw_descr->nw_id == LNET_NET_ANY) {
1655 "\"cannot parse net '%s'\"",
1656 libcfs_net2str(nw_descr->nw_id));
1657 rc = LUSTRE_CFG_RC_BAD_PARAM;
1662 * special case the GNI since no interface name is expected
1664 if (list_empty(&nw_descr->nw_intflist) &&
1665 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1668 "\"no interface name provided\"");
1669 rc = LUSTRE_CFG_RC_BAD_PARAM;
1673 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1674 err_str, sizeof(err_str));
1676 rc = LUSTRE_CFG_RC_BAD_PARAM;
1680 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1681 tunables, global_cpts, nids,
1685 if (nw_descr != NULL) {
1686 list_for_each_entry_safe(intf_descr, tmp,
1687 &nw_descr->nw_intflist,
1689 list_del(&intf_descr->intf_on_network);
1690 free_intf_descr(intf_descr);
1694 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1705 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1706 int seq_no, struct cYAML **err_rc)
1708 struct lnet_ioctl_config_ni data;
1709 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1710 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1711 lnet_nid_t *nids = NULL;
1713 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1715 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1718 "\"missing mandatory parameter in deleting NI: '%s'\"",
1719 (nw_descr == NULL) ? "network , interface" :
1720 (nw_descr->nw_id == 0) ? "network" : "interface");
1721 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1725 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1726 return LUSTRE_CFG_RC_NO_ERR;
1728 if (nw_descr->nw_id == LNET_NET_ANY) {
1731 "\"cannot parse net '%s'\"",
1732 libcfs_net2str(nw_descr->nw_id));
1733 rc = LUSTRE_CFG_RC_BAD_PARAM;
1737 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1738 err_str, sizeof(err_str));
1740 rc = LUSTRE_CFG_RC_BAD_PARAM;
1745 * no interfaces just the nw_id is specified
1748 nids = calloc(1, sizeof(*nids));
1750 snprintf(err_str, sizeof(err_str),
1751 "\"out of memory\"");
1752 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1755 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1759 for (i = 0; i < nnids; i++) {
1760 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1761 data.lic_nid = nids[i];
1763 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1768 "\"cannot del network: %s\"", strerror(errno));
1772 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1774 list_del(&intf_descr->intf_on_network);
1775 free_intf_descr(intf_descr);
1779 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1788 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1789 enum lnet_health_type type, char *name,
1790 int seq_no, struct cYAML **err_rc)
1792 struct lnet_ioctl_reset_health_cfg data;
1793 int rc = LUSTRE_CFG_RC_NO_ERR;
1794 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1796 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1797 data.rh_type = type;
1799 data.rh_value = value;
1802 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1806 sizeof(err_str), "Can not configure health value: %s",
1810 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1815 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1816 struct cYAML **err_rc)
1820 nid = libcfs_str2nid(ni_nid);
1823 return lustre_lnet_config_healthv(value, all, nid,
1824 LNET_HEALTH_TYPE_LOCAL_NI,
1825 "ni healthv", seq_no, err_rc);
1828 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1829 int seq_no, struct cYAML **err_rc)
1833 nid = libcfs_str2nid(lpni_nid);
1836 return lustre_lnet_config_healthv(value, all, nid,
1837 LNET_HEALTH_TYPE_PEER_NI,
1838 "peer_ni healthv", seq_no, err_rc);
1842 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1843 struct lnet_ioctl_comm_count *counts)
1845 if (cYAML_create_number(yaml, "put",
1846 counts->ico_put_count)
1849 if (cYAML_create_number(yaml, "get",
1850 counts->ico_get_count)
1853 if (cYAML_create_number(yaml, "reply",
1854 counts->ico_reply_count)
1857 if (cYAML_create_number(yaml, "ack",
1858 counts->ico_ack_count)
1861 if (cYAML_create_number(yaml, "hello",
1862 counts->ico_hello_count)
1869 static struct lnet_ioctl_comm_count *
1870 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1873 return &msg_stats->im_send_stats;
1875 return &msg_stats->im_recv_stats;
1877 return &msg_stats->im_drop_stats;
1883 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
1884 struct cYAML *net_node)
1886 char tmp[LNET_MAX_STR_LEN];
1887 struct cYAML *udsp_net;
1888 bool created = false;
1892 /* add the UDSP info */
1893 udsp_net = cYAML_create_object(net_node, "udsp info");
1895 return LUSTRE_CFG_RC_OUT_OF_MEM;
1897 if (!cYAML_create_number(udsp_net, "net priority",
1898 (int) udsp_info->cud_net_priority))
1899 return LUSTRE_CFG_RC_OUT_OF_MEM;
1901 if (!cYAML_create_number(udsp_net, "nid priority",
1902 (int)udsp_info->cud_nid_priority))
1903 return LUSTRE_CFG_RC_OUT_OF_MEM;
1907 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
1908 memset(tmp, 0, LNET_MAX_STR_LEN);
1909 if (udsp_info->cud_pref_rtr_nid[i] == 0)
1912 pref = cYAML_create_object(udsp_net,
1913 "Preferred gateway NIDs");
1915 return LUSTRE_CFG_RC_OUT_OF_MEM;
1918 snprintf(tmp, sizeof(tmp), "NID-%d", i);
1919 if (!cYAML_create_string(pref, tmp,
1920 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
1921 return LUSTRE_CFG_RC_OUT_OF_MEM;
1924 return LUSTRE_CFG_RC_NO_ERR;
1928 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
1929 struct cYAML *nid_node)
1931 char tmp[LNET_MAX_STR_LEN];
1932 struct cYAML *udsp_nid;
1933 bool created = false;
1937 /* add the UDSP info */
1938 udsp_nid = cYAML_create_object(nid_node, "udsp info");
1940 return LUSTRE_CFG_RC_OUT_OF_MEM;
1942 if (!cYAML_create_number(udsp_nid, "net priority",
1943 (int) udsp_info->cud_net_priority))
1944 return LUSTRE_CFG_RC_OUT_OF_MEM;
1946 if (!cYAML_create_number(udsp_nid, "nid priority",
1947 (int) udsp_info->cud_nid_priority))
1948 return LUSTRE_CFG_RC_OUT_OF_MEM;
1951 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
1952 memset(tmp, 0, LNET_MAX_STR_LEN);
1953 if (udsp_info->cud_pref_rtr_nid[i] == 0)
1956 pref = cYAML_create_object(udsp_nid,
1957 "Preferred gateway NIDs");
1959 return LUSTRE_CFG_RC_OUT_OF_MEM;
1962 snprintf(tmp, sizeof(tmp), "NID-%d", i);
1963 if (!cYAML_create_string(pref, tmp,
1964 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
1965 return LUSTRE_CFG_RC_OUT_OF_MEM;
1970 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
1971 memset(tmp, 0, LNET_MAX_STR_LEN);
1972 if (udsp_info->cud_pref_nid[i] == 0)
1975 pref = cYAML_create_object(udsp_nid,
1976 "Preferred source NIDs");
1978 return LUSTRE_CFG_RC_OUT_OF_MEM;
1981 snprintf(tmp, sizeof(tmp), "NID-%d", i);
1982 if (!cYAML_create_string(pref, tmp,
1983 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
1984 return LUSTRE_CFG_RC_OUT_OF_MEM;
1987 return LUSTRE_CFG_RC_NO_ERR;
1990 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1991 struct cYAML **show_rc, struct cYAML **err_rc,
1995 struct lnet_ioctl_config_ni *ni_data;
1996 struct lnet_ioctl_config_lnd_tunables *lnd;
1997 struct lnet_ioctl_element_stats *stats;
1998 struct lnet_ioctl_element_msg_stats msg_stats;
1999 struct lnet_ioctl_local_ni_hstats hstats;
2000 struct lnet_ioctl_construct_udsp_info udsp_info;
2001 __u32 net = LNET_NET_ANY;
2002 __u32 prev_net = LNET_NET_ANY;
2003 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2005 struct cYAML *root = NULL, *tunables = NULL,
2006 *net_node = NULL, *interfaces = NULL,
2007 *item = NULL, *first_seq = NULL,
2008 *tmp = NULL, *statistics = NULL,
2010 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2011 char str_buf[str_buf_len];
2013 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2014 bool exist = false, new_net = true;
2016 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2018 buf = calloc(1, buf_size);
2022 ni_data = (struct lnet_ioctl_config_ni *)buf;
2025 net = libcfs_str2net(nw);
2026 if (net == LNET_NET_ANY) {
2029 "\"cannot parse net '%s'\"", nw);
2030 rc = LUSTRE_CFG_RC_BAD_PARAM;
2035 root = cYAML_create_object(NULL, NULL);
2039 net_node = cYAML_create_seq(root, "net");
2040 if (net_node == NULL)
2046 memset(buf, 0, buf_size);
2048 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2050 * set the ioc_len to the proper value since INIT assumes
2053 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2054 ni_data->lic_idx = i;
2056 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2062 rc_net = LNET_NIDNET(ni_data->lic_nid);
2064 /* filter on provided data */
2065 if (net != LNET_NET_ANY &&
2069 /* if we're backing up don't store lo */
2070 if (backup && LNET_NETTYP(rc_net) == LOLND)
2073 /* default rc to -1 in case we hit the goto */
2077 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2078 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2079 (ni_data->lic_bulk + sizeof(*stats));
2081 if (rc_net != prev_net) {
2088 if (!cYAML_create_string(net_node, "net type",
2089 libcfs_net2str(rc_net)))
2092 tmp = cYAML_create_seq(net_node, "local NI(s)");
2098 /* create the tree to be printed. */
2099 item = cYAML_create_seq_item(tmp);
2103 if (first_seq == NULL)
2107 cYAML_create_string(item, "nid",
2108 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2112 cYAML_create_string(item,
2114 (ni_data->lic_status ==
2115 LNET_NI_STATUS_UP) ?
2116 "up" : "down") == NULL)
2119 /* don't add interfaces unless there is at least one
2121 if (strlen(ni_data->lic_ni_intf) > 0) {
2122 interfaces = cYAML_create_object(item, "interfaces");
2123 if (interfaces == NULL)
2126 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2127 if (cYAML_create_string(interfaces, str_buf,
2128 ni_data->lic_ni_intf) == NULL)
2137 goto continue_without_msg_stats;
2139 statistics = cYAML_create_object(item, "statistics");
2140 if (statistics == NULL)
2143 if (cYAML_create_number(statistics, "send_count",
2144 stats->iel_send_count)
2148 if (cYAML_create_number(statistics, "recv_count",
2149 stats->iel_recv_count)
2153 if (cYAML_create_number(statistics, "drop_count",
2154 stats->iel_drop_count)
2159 goto continue_without_udsp_info;
2161 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2162 udsp_info.cud_nid = ni_data->lic_nid;
2163 udsp_info.cud_peer = false;
2164 rc = l_ioctl(LNET_DEV_ID,
2165 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2169 goto continue_without_udsp_info;
2172 rc = create_local_udsp_info(&udsp_info, item);
2178 continue_without_udsp_info:
2180 goto continue_without_msg_stats;
2182 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2183 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2184 msg_stats.im_idx = i;
2186 rc = l_ioctl(LNET_DEV_ID,
2187 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2191 goto continue_without_msg_stats;
2194 for (k = 0; k < 3; k++) {
2195 struct lnet_ioctl_comm_count *counts;
2196 struct cYAML *msg_statistics = NULL;
2198 msg_statistics = cYAML_create_object(item,
2199 (char *)gmsg_stat_names[k]);
2200 if (msg_statistics == NULL)
2203 counts = get_counts(&msg_stats, k);
2207 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2212 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2213 hstats.hlni_nid = ni_data->lic_nid;
2214 /* grab health stats */
2215 rc = l_ioctl(LNET_DEV_ID,
2216 IOC_LIBCFS_GET_LOCAL_HSTATS,
2220 goto continue_without_msg_stats;
2222 yhstats = cYAML_create_object(item, "health stats");
2225 if (cYAML_create_number(yhstats, "health value",
2226 hstats.hlni_health_value)
2229 if (cYAML_create_number(yhstats, "interrupts",
2230 hstats.hlni_local_interrupt)
2233 if (cYAML_create_number(yhstats, "dropped",
2234 hstats.hlni_local_dropped)
2237 if (cYAML_create_number(yhstats, "aborted",
2238 hstats.hlni_local_aborted)
2241 if (cYAML_create_number(yhstats, "no route",
2242 hstats.hlni_local_no_route)
2245 if (cYAML_create_number(yhstats, "timeouts",
2246 hstats.hlni_local_timeout)
2249 if (cYAML_create_number(yhstats, "error",
2250 hstats.hlni_local_error)
2254 continue_without_msg_stats:
2255 tunables = cYAML_create_object(item, "tunables");
2259 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2260 if (rc != LUSTRE_CFG_RC_NO_ERR)
2263 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2265 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2266 rc != LUSTRE_CFG_RC_NO_MATCH)
2269 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2270 tunables = cYAML_create_object(item,
2272 if (tunables == NULL)
2277 cYAML_create_number(item, "dev cpt",
2278 ni_data->lic_dev_cpt) == NULL)
2281 /* out put the CPTs in the format: "[x,x,x,...]" */
2283 limit = str_buf + str_buf_len - 3;
2284 pos += scnprintf(pos, limit - pos, "\"[");
2285 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2286 j < ni_data->lic_ncpts &&
2288 pos += scnprintf(pos, limit - pos,
2289 "%d", ni_data->lic_cpts[j]);
2290 if ((j + 1) < ni_data->lic_ncpts)
2291 pos += scnprintf(pos, limit - pos, ",");
2293 snprintf(pos, 3, "]\"");
2295 if (ni_data->lic_ncpts >= 1 &&
2296 cYAML_create_string(item, "CPT",
2302 /* Print out the net information only if show_rc is not provided */
2303 if (show_rc == NULL)
2304 cYAML_print_tree(root);
2306 if (l_errno != ENOENT) {
2309 "\"cannot get networks: %s\"",
2314 rc = LUSTRE_CFG_RC_NO_ERR;
2316 snprintf(err_str, sizeof(err_str), "\"success\"");
2318 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2319 cYAML_free_tree(root);
2320 } else if (show_rc != NULL && *show_rc != NULL) {
2321 struct cYAML *show_node;
2322 /* find the net node, if one doesn't exist
2323 * then insert one. Otherwise add to the one there
2325 show_node = cYAML_get_object_item(*show_rc, "net");
2326 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2327 cYAML_insert_child(show_node, first_seq);
2330 } else if (show_node == NULL) {
2331 cYAML_insert_sibling((*show_rc)->cy_child,
2335 cYAML_free_tree(root);
2341 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2346 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2348 struct lnet_ioctl_config_data data;
2349 int rc = LUSTRE_CFG_RC_NO_ERR;
2350 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2352 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2353 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2355 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2360 "\"cannot %s routing %s\"",
2361 (enable) ? "enable" : "disable", strerror(errno));
2366 cYAML_build_error(rc, seq_no,
2367 (enable) ? ADD_CMD : DEL_CMD,
2368 "routing", err_str, err_rc);
2373 int ioctl_set_value(__u32 val, int ioc, char *name,
2374 int seq_no, struct cYAML **err_rc)
2376 struct lnet_ioctl_set_value data;
2377 int rc = LUSTRE_CFG_RC_NO_ERR;
2378 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2380 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2381 data.sv_value = val;
2383 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2388 "\"cannot configure %s to %d: %s\"", name,
2389 val, strerror(errno));
2392 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2397 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2399 int rc = LUSTRE_CFG_RC_NO_ERR;
2400 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2401 char val[LNET_MAX_STR_LEN];
2403 snprintf(val, sizeof(val), "%d", intrv);
2405 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2406 1, strlen(val) + 1);
2408 snprintf(err_str, sizeof(err_str),
2409 "\"cannot configure recovery interval: %s\"",
2412 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2417 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2419 int rc = LUSTRE_CFG_RC_NO_ERR;
2420 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2421 char val[LNET_MAX_STR_LEN];
2423 snprintf(val, sizeof(val), "%d", sen);
2425 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2426 1, strlen(val) + 1);
2428 snprintf(err_str, sizeof(err_str),
2429 "\"cannot configure router health sensitivity: %s\"",
2432 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2437 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2439 int rc = LUSTRE_CFG_RC_NO_ERR;
2440 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2441 char val[LNET_MAX_STR_LEN];
2443 snprintf(val, sizeof(val), "%d", sen);
2445 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2446 1, strlen(val) + 1);
2448 snprintf(err_str, sizeof(err_str),
2449 "\"cannot configure health sensitivity: %s\"",
2452 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2457 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2459 int rc = LUSTRE_CFG_RC_NO_ERR;
2460 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2461 char val[LNET_MAX_STR_LEN];
2463 snprintf(val, sizeof(val), "%d", timeout);
2465 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2466 1, strlen(val) + 1);
2468 snprintf(err_str, sizeof(err_str),
2469 "\"cannot configure transaction timeout: %s\"",
2472 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2477 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2479 int rc = LUSTRE_CFG_RC_NO_ERR;
2480 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2481 char val[LNET_MAX_STR_LEN];
2483 snprintf(val, sizeof(val), "%d", count);
2485 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2486 1, strlen(val) + 1);
2488 snprintf(err_str, sizeof(err_str),
2489 "\"cannot configure retry count: %s\"",
2492 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2497 int lustre_lnet_config_response_tracking(int val, int seq_no,
2498 struct cYAML **err_rc)
2500 int rc = LUSTRE_CFG_RC_NO_ERR;
2501 char err_str[LNET_MAX_STR_LEN];
2502 char val_str[LNET_MAX_STR_LEN];
2504 if (val < 0 || val > 3) {
2505 rc = LUSTRE_CFG_RC_BAD_PARAM;
2506 snprintf(err_str, sizeof(err_str),
2507 "\"Valid values are: 0, 1, 2, or 3\"");
2509 snprintf(err_str, sizeof(err_str), "\"success\"");
2511 snprintf(val_str, sizeof(val_str), "%d", val);
2513 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2514 val_str, 1, strlen(val_str) + 1);
2516 snprintf(err_str, sizeof(err_str),
2517 "\"cannot configure response tracking: %s\"",
2521 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2527 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2528 struct cYAML **err_rc)
2530 int rc = LUSTRE_CFG_RC_NO_ERR;
2531 char err_str[LNET_MAX_STR_LEN];
2532 char val_str[LNET_MAX_STR_LEN];
2535 rc = LUSTRE_CFG_RC_BAD_PARAM;
2536 snprintf(err_str, sizeof(err_str),
2537 "\"Must be greater than or equal to 0\"");
2539 snprintf(err_str, sizeof(err_str), "\"success\"");
2541 snprintf(val_str, sizeof(val_str), "%d", val);
2543 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2544 val_str, 1, strlen(val_str) + 1);
2546 snprintf(err_str, sizeof(err_str),
2547 "\"cannot configure recovery limit: %s\"",
2551 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2557 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2559 int rc = LUSTRE_CFG_RC_NO_ERR;
2560 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2561 char val[LNET_MAX_STR_LEN];
2563 snprintf(val, sizeof(val), "%d", max);
2565 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2566 1, strlen(val) + 1);
2568 snprintf(err_str, sizeof(err_str),
2569 "\"cannot configure max interfaces: %s\"",
2572 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2577 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2579 int rc = LUSTRE_CFG_RC_NO_ERR;
2580 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2581 char val[LNET_MAX_STR_LEN];
2583 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2585 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2586 1, strlen(val) + 1);
2588 snprintf(err_str, sizeof(err_str),
2589 "\"cannot configure discovery: %s\"",
2592 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2598 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2599 struct cYAML **err_rc)
2601 int rc = LUSTRE_CFG_RC_NO_ERR;
2602 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2603 char val[LNET_MAX_STR_LEN];
2605 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2607 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2608 1, strlen(val) + 1);
2610 snprintf(err_str, sizeof(err_str),
2611 "\"cannot configure drop asym route: %s\"",
2614 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2621 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2623 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2624 "numa_range", seq_no, err_rc);
2627 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2628 struct cYAML **err_rc)
2630 struct lnet_ioctl_config_data data;
2631 int rc = LUSTRE_CFG_RC_NO_ERR;
2632 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2634 /* -1 indicates to ignore changes to this field */
2635 if (tiny < -1 || small < -1 || large < -1) {
2638 "\"tiny, small and large must be >= 0\"");
2639 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2643 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2644 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2645 data.cfg_config_u.cfg_buffers.buf_small = small;
2646 data.cfg_config_u.cfg_buffers.buf_large = large;
2648 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2653 "\"cannot configure buffers: %s\"", strerror(errno));
2658 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2663 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2664 struct cYAML **err_rc, bool backup)
2666 struct lnet_ioctl_config_data *data;
2667 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2668 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2671 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2672 int buf_count[LNET_NRBPOOLS] = {0};
2673 struct cYAML *root = NULL, *pools_node = NULL,
2674 *type_node = NULL, *item = NULL, *cpt = NULL,
2675 *first_seq = NULL, *buffers = NULL;
2677 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2678 char node_name[LNET_MAX_STR_LEN];
2681 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2685 data = (struct lnet_ioctl_config_data *)buf;
2687 root = cYAML_create_object(NULL, NULL);
2692 pools_node = cYAML_create_object(root, "routing");
2694 pools_node = cYAML_create_seq(root, "routing");
2695 if (pools_node == NULL)
2699 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2700 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2701 sizeof(struct lnet_ioctl_pool_cfg);
2702 data->cfg_count = i;
2704 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2712 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2715 goto calculate_buffers;
2717 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2718 item = cYAML_create_seq_item(pools_node);
2722 if (first_seq == NULL)
2725 cpt = cYAML_create_object(item, node_name);
2730 /* create the tree and print */
2731 for (j = 0; j < LNET_NRBPOOLS; j++) {
2733 type_node = cYAML_create_object(cpt, pools[j]);
2734 if (type_node == NULL)
2738 cYAML_create_number(type_node, "npages",
2739 pool_cfg->pl_pools[j].pl_npages)
2743 cYAML_create_number(type_node, "nbuffers",
2744 pool_cfg->pl_pools[j].
2745 pl_nbuffers) == NULL)
2748 cYAML_create_number(type_node, "credits",
2749 pool_cfg->pl_pools[j].
2750 pl_credits) == NULL)
2753 cYAML_create_number(type_node, "mincredits",
2754 pool_cfg->pl_pools[j].
2755 pl_mincredits) == NULL)
2757 /* keep track of the total count for each of the
2758 * tiny, small and large buffers */
2759 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2763 if (pool_cfg != NULL) {
2765 if (cYAML_create_number(pools_node, "enable",
2766 pool_cfg->pl_routing) ==
2770 goto add_buffer_section;
2773 item = cYAML_create_seq_item(pools_node);
2777 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2783 /* create a buffers entry in the show. This is necessary so that
2784 * if the YAML output is used to configure a node, the buffer
2785 * configuration takes hold */
2786 buffers = cYAML_create_object(root, "buffers");
2787 if (buffers == NULL)
2790 for (i = 0; i < LNET_NRBPOOLS; i++) {
2791 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2795 if (show_rc == NULL)
2796 cYAML_print_tree(root);
2798 if (l_errno != ENOENT) {
2801 "\"cannot get routing information: %s\"",
2806 rc = LUSTRE_CFG_RC_NO_ERR;
2808 snprintf(err_str, sizeof(err_str), "\"success\"");
2809 rc = LUSTRE_CFG_RC_NO_ERR;
2813 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2814 cYAML_free_tree(root);
2815 } else if (show_rc != NULL && *show_rc != NULL) {
2816 struct cYAML *routing_node;
2817 /* there should exist only one routing block and one
2818 * buffers block. If there already exists a previous one
2819 * then don't add another */
2820 routing_node = cYAML_get_object_item(*show_rc, "routing");
2821 if (routing_node == NULL) {
2822 cYAML_insert_sibling((*show_rc)->cy_child,
2826 cYAML_free_tree(root);
2832 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2837 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2838 struct cYAML **show_rc, struct cYAML **err_rc,
2842 * TODO: This function is changing in a future patch to accommodate
2843 * PEER_LIST and proper filtering on any nid of the peer
2845 struct lnet_ioctl_peer_cfg peer_info;
2846 struct lnet_peer_ni_credit_info *lpni_cri;
2847 struct lnet_ioctl_element_stats *lpni_stats;
2848 struct lnet_ioctl_element_msg_stats *msg_stats;
2849 struct lnet_ioctl_peer_ni_hstats *hstats;
2850 struct lnet_ioctl_construct_udsp_info udsp_info;
2852 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2857 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2858 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2859 *msg_statistics = NULL, *statistics = NULL,
2861 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2862 struct lnet_process_id *list = NULL;
2867 /* create struct cYAML root object */
2868 root = cYAML_create_object(NULL, NULL);
2872 peer_root = cYAML_create_seq(root, "peer");
2873 if (peer_root == NULL)
2877 size = count * sizeof(struct lnet_process_id);
2878 list = malloc(size);
2884 list[0].nid = libcfs_str2nid(knid);
2888 memset(&peer_info, 0, sizeof(peer_info));
2889 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2890 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2891 peer_info.prcfg_size = size;
2892 peer_info.prcfg_bulk = list;
2895 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2897 count = peer_info.prcfg_count;
2901 if (l_errno != E2BIG) {
2904 "\"cannot get peer list: %s\"",
2910 size = peer_info.prcfg_size;
2911 list = malloc(size);
2920 data = malloc(size);
2926 for (i = 0; i < count; i++) {
2928 memset(&peer_info, 0, sizeof(peer_info));
2929 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2930 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2931 peer_info.prcfg_prim_nid = list[i].nid;
2932 peer_info.prcfg_size = size;
2933 peer_info.prcfg_bulk = data;
2936 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2941 if (l_errno != E2BIG) {
2944 "\"cannot get peer information: %s\"",
2950 size = peer_info.prcfg_size;
2951 data = malloc(size);
2959 peer = cYAML_create_seq_item(peer_root);
2963 if (first_seq == NULL)
2966 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2967 if (cYAML_create_string(peer, "primary nid",
2968 libcfs_nid2str(pnid))
2971 if (cYAML_create_string(peer, "Multi-Rail",
2972 peer_info.prcfg_mr ? "True" : "False")
2976 * print out the state of the peer only if details are
2981 cYAML_create_number(peer, "peer state",
2982 peer_info.prcfg_state)
2987 tmp = cYAML_create_seq(peer, "peer ni");
2992 for (j = 0; j < peer_info.prcfg_count; j++) {
2994 lpni_cri = (void*)nidp + sizeof(nidp);
2995 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2996 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2997 hstats = (void *)msg_stats + sizeof(*msg_stats);
2998 lpni_data = (void *)hstats + sizeof(*hstats);
3000 peer_ni = cYAML_create_seq_item(tmp);
3001 if (peer_ni == NULL)
3004 if (cYAML_create_string(peer_ni, "nid",
3005 libcfs_nid2str(*nidp))
3013 goto continue_without_udsp_info;
3015 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3016 udsp_info.cud_nid = *nidp;
3017 udsp_info.cud_peer = true;
3018 rc = l_ioctl(LNET_DEV_ID,
3019 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3023 goto continue_without_udsp_info;
3026 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3032 continue_without_udsp_info:
3033 if (cYAML_create_string(peer_ni, "state",
3034 lpni_cri->cr_aliveness)
3041 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3042 lpni_cri->cr_ni_peer_tx_credits)
3046 if (cYAML_create_number(peer_ni, "available_tx_credits",
3047 lpni_cri->cr_peer_tx_credits)
3051 if (cYAML_create_number(peer_ni, "min_tx_credits",
3052 lpni_cri->cr_peer_min_tx_credits)
3056 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3057 lpni_cri->cr_peer_tx_qnob)
3061 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3062 lpni_cri->cr_peer_rtr_credits)
3066 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3067 lpni_cri->cr_peer_min_rtr_credits)
3071 if (cYAML_create_number(peer_ni, "refcount",
3072 lpni_cri->cr_refcount) == NULL)
3075 statistics = cYAML_create_object(peer_ni, "statistics");
3076 if (statistics == NULL)
3079 if (cYAML_create_number(statistics, "send_count",
3080 lpni_stats->iel_send_count)
3084 if (cYAML_create_number(statistics, "recv_count",
3085 lpni_stats->iel_recv_count)
3089 if (cYAML_create_number(statistics, "drop_count",
3090 lpni_stats->iel_drop_count)
3097 for (k = 0; k < 3; k++) {
3098 struct lnet_ioctl_comm_count *counts;
3100 msg_statistics = cYAML_create_object(peer_ni,
3101 (char *) gmsg_stat_names[k]);
3102 if (msg_statistics == NULL)
3105 counts = get_counts(msg_stats, k);
3109 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3114 yhstats = cYAML_create_object(peer_ni, "health stats");
3117 if (cYAML_create_number(yhstats, "health value",
3118 hstats->hlpni_health_value)
3121 if (cYAML_create_number(yhstats, "dropped",
3122 hstats->hlpni_remote_dropped)
3125 if (cYAML_create_number(yhstats, "timeout",
3126 hstats->hlpni_remote_timeout)
3129 if (cYAML_create_number(yhstats, "error",
3130 hstats->hlpni_remote_error)
3133 if (cYAML_create_number(yhstats, "network timeout",
3134 hstats->hlpni_network_timeout)
3140 /* print output iff show_rc is not provided */
3141 if (show_rc == NULL)
3142 cYAML_print_tree(root);
3144 snprintf(err_str, sizeof(err_str), "\"success\"");
3145 rc = LUSTRE_CFG_RC_NO_ERR;
3150 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3151 cYAML_free_tree(root);
3152 } else if (show_rc != NULL && *show_rc != NULL) {
3153 struct cYAML *show_node;
3154 /* find the peer node, if one doesn't exist then
3155 * insert one. Otherwise add to the one there
3157 show_node = cYAML_get_object_item(*show_rc,
3159 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3160 cYAML_insert_child(show_node, first_seq);
3163 } else if (show_node == NULL) {
3164 cYAML_insert_sibling((*show_rc)->cy_child,
3168 cYAML_free_tree(root);
3174 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3180 int lustre_lnet_list_peer(int seq_no,
3181 struct cYAML **show_rc, struct cYAML **err_rc)
3183 struct lnet_ioctl_peer_cfg peer_info;
3184 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3189 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3190 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3191 struct lnet_process_id *list = NULL;
3193 memset(&peer_info, 0, sizeof(peer_info));
3195 /* create struct cYAML root object */
3196 root = cYAML_create_object(NULL, NULL);
3200 list_root = cYAML_create_seq(root, "peer list");
3201 if (list_root == NULL)
3205 size = count * sizeof(struct lnet_process_id);
3206 list = malloc(size);
3212 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3213 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3214 peer_info.prcfg_size = size;
3215 peer_info.prcfg_bulk = list;
3218 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3219 count = peer_info.prcfg_count;
3223 if (l_errno != E2BIG) {
3226 "\"cannot get peer list: %s\"",
3232 size = peer_info.prcfg_size;
3233 list = malloc(size);
3240 /* count is now the actual number of ids in the list. */
3241 for (i = 0; i < count; i++) {
3242 if (cYAML_create_string(list_root, "nid",
3243 libcfs_nid2str(list[i].nid))
3248 /* print output iff show_rc is not provided */
3249 if (show_rc == NULL)
3250 cYAML_print_tree(root);
3252 snprintf(err_str, sizeof(err_str), "\"success\"");
3253 rc = LUSTRE_CFG_RC_NO_ERR;
3258 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3259 cYAML_free_tree(root);
3260 } else if (show_rc != NULL && *show_rc != NULL) {
3261 struct cYAML *show_node;
3262 /* find the peer node, if one doesn't exist then
3263 * insert one. Otherwise add to the one there
3265 show_node = cYAML_get_object_item(*show_rc,
3267 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3268 cYAML_insert_child(show_node, first_seq);
3271 } else if (show_node == NULL) {
3272 cYAML_insert_sibling((*show_rc)->cy_child,
3276 cYAML_free_tree(root);
3282 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3288 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3291 struct cYAML *show_node;
3293 show_node = cYAML_get_object_item(show_rc, "global");
3294 if (show_node != NULL)
3295 cYAML_insert_sibling(show_node->cy_child,
3298 cYAML_insert_sibling(show_rc->cy_child,
3303 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3304 char *name, __u64 value,
3305 struct cYAML **show_rc,
3306 struct cYAML **err_rc, int err)
3308 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3309 struct cYAML *root = NULL, *global = NULL;
3316 root = cYAML_create_object(NULL, NULL);
3320 global = cYAML_create_object(root, "global");
3324 if (cYAML_create_number(global, name,
3328 if (show_rc == NULL)
3329 cYAML_print_tree(root);
3331 snprintf(err_str, err_len, "\"success\"");
3333 rc = LUSTRE_CFG_RC_NO_ERR;
3336 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3337 cYAML_free_tree(root);
3338 } else if (show_rc != NULL && *show_rc != NULL) {
3339 add_to_global(*show_rc, global, root);
3344 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3349 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3350 struct cYAML **show_rc,
3351 struct cYAML **err_rc)
3353 struct lnet_ioctl_set_value data;
3356 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3358 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3360 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3365 "\"cannot get %s: %s\"",
3366 name, strerror(l_errno));
3369 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3370 data.sv_value, show_rc, err_rc, l_errno);
3373 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3374 struct cYAML **err_rc)
3376 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3377 char val[LNET_MAX_STR_LEN];
3378 int intrv = -1, l_errno = 0;
3379 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3381 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3385 snprintf(err_str, sizeof(err_str),
3386 "\"cannot get recovery interval: %d\"", rc);
3391 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3392 "recovery_interval", intrv, show_rc,
3396 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3397 struct cYAML **err_rc)
3399 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3400 char val[LNET_MAX_STR_LEN];
3401 int sen = -1, l_errno = 0;
3402 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3404 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3408 snprintf(err_str, sizeof(err_str),
3409 "\"cannot get health sensitivity: %d\"", rc);
3414 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3415 "health_sensitivity", sen, show_rc,
3419 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3420 struct cYAML **err_rc)
3422 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3423 char val[LNET_MAX_STR_LEN];
3424 int sen = -1, l_errno = 0;
3425 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3427 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3431 snprintf(err_str, sizeof(err_str),
3432 "\"cannot get router sensitivity percentage: %d\"", rc);
3437 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3438 "router_sensitivity", sen, show_rc,
3442 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3443 struct cYAML **err_rc)
3445 char val[LNET_MAX_STR_LEN];
3446 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3453 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3456 snprintf(err_str, sizeof(err_str),
3457 "\"cannot get LND timeout: %d\"", rc);
3458 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3459 "lnd_timeout", lnd_to, show_rc,
3463 fd = open(path.gl_pathv[0], O_RDONLY);
3466 snprintf(err_str, sizeof(err_str),
3467 "\"error opening %s\"", path.gl_pathv[0]);
3471 rc = read(fd, val, sizeof(val));
3478 snprintf(err_str, sizeof(err_str),
3479 "\"error reading %s\"", path.gl_pathv[0]);
3486 cfs_free_param_data(&path);
3488 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3489 "lnd_timeout", lnd_to, show_rc,
3493 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3494 struct cYAML **err_rc)
3496 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3497 char val[LNET_MAX_STR_LEN];
3498 int tto = -1, l_errno = 0;
3499 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3501 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3505 snprintf(err_str, sizeof(err_str),
3506 "\"cannot get transaction timeout: %d\"", rc);
3511 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3512 "transaction_timeout", tto, show_rc,
3516 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3517 struct cYAML **err_rc)
3519 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3520 char val[LNET_MAX_STR_LEN];
3521 int retry_count = -1, l_errno = 0;
3522 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3524 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3528 snprintf(err_str, sizeof(err_str),
3529 "\"cannot get retry count: %d\"", rc);
3531 retry_count = atoi(val);
3534 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3535 "retry_count", retry_count, show_rc,
3539 int lustre_lnet_calc_service_id(__u64 *service_id)
3541 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3542 char val[LNET_MAX_STR_LEN];
3543 int service_port = -1, l_errno = 0;
3545 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3549 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3550 strerror(l_errno), -l_errno);
3553 service_port = atoi(val);
3556 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3558 return LUSTRE_CFG_RC_NO_ERR;
3561 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3562 struct cYAML **show_rc, struct cYAML **err_rc)
3564 struct lnet_ioctl_recovery_list nid_list;
3565 struct cYAML *root = NULL, *nids = NULL;
3567 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3569 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3570 nid_list.rlst_type = type;
3572 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3578 if (nid_list.rlst_num_nids == 0)
3581 root = cYAML_create_object(NULL, NULL);
3585 nids = cYAML_create_object(root, name);
3591 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3592 char nidenum[LNET_MAX_STR_LEN];
3593 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3594 if (!cYAML_create_string(nids, nidenum,
3595 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3599 snprintf(err_str, sizeof(err_str), "success\n");
3604 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3605 cYAML_free_tree(root);
3606 } else if (show_rc != NULL && *show_rc != NULL) {
3607 struct cYAML *show_node;
3608 /* find the net node, if one doesn't exist
3609 * then insert one. Otherwise add to the one there
3611 show_node = cYAML_get_object_item(*show_rc, name);
3612 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3613 cYAML_insert_child(show_node, nids);
3616 } else if (show_node == NULL) {
3617 cYAML_insert_sibling((*show_rc)->cy_child,
3621 cYAML_free_tree(root);
3627 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3632 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3633 struct cYAML **err_rc)
3635 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3636 seq_no, show_rc, err_rc);
3639 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3640 struct cYAML **err_rc)
3642 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3643 seq_no, show_rc, err_rc);
3646 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
3647 struct cYAML **err_rc)
3649 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3650 char val[LNET_MAX_STR_LEN];
3651 int rsp_tracking = -1, l_errno = 0;
3652 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3654 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
3658 snprintf(err_str, sizeof(err_str),
3659 "\"cannot get lnet_response_tracking value: %d\"", rc);
3661 rsp_tracking = atoi(val);
3664 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3665 "response_tracking", rsp_tracking,
3666 show_rc, err_rc, l_errno);
3669 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
3670 struct cYAML **err_rc)
3672 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3673 char val[LNET_MAX_STR_LEN];
3674 int recov_limit = -1, l_errno = 0;
3675 char err_str[LNET_MAX_STR_LEN];
3677 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3679 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
3683 snprintf(err_str, sizeof(err_str),
3684 "\"cannot get lnet_recovery_limit value: %d\"", rc);
3686 recov_limit = atoi(val);
3689 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3690 "recovery_limit", recov_limit,
3691 show_rc, err_rc, l_errno);
3694 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3695 struct cYAML **err_rc)
3697 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3698 char val[LNET_MAX_STR_LEN];
3699 int max_intf = -1, l_errno = 0;
3700 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3702 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3706 snprintf(err_str, sizeof(err_str),
3707 "\"cannot get max interfaces: %d\"", rc);
3709 max_intf = atoi(val);
3712 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3713 "max_interfaces", max_intf, show_rc,
3717 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3718 struct cYAML **err_rc)
3720 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3721 char val[LNET_MAX_STR_LEN];
3722 int discovery = -1, l_errno = 0;
3723 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3725 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3729 snprintf(err_str, sizeof(err_str),
3730 "\"cannot get discovery setting: %d\"", rc);
3733 * The kernel stores a discovery disabled value. User space
3734 * shows whether discovery is enabled. So the value must be
3737 discovery = !atoi(val);
3740 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3741 "discovery", discovery, show_rc,
3745 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3746 struct cYAML **err_rc)
3748 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3749 char val[LNET_MAX_STR_LEN];
3750 int drop_asym_route = -1, l_errno = 0;
3751 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3753 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3757 snprintf(err_str, sizeof(err_str),
3758 "\"cannot get drop asym route setting: %d\"", rc);
3760 drop_asym_route = atoi(val);
3763 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3764 "drop_asym_route", drop_asym_route,
3765 show_rc, err_rc, l_errno);
3768 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3769 struct cYAML **err_rc)
3771 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3772 "numa_range", show_rc, err_rc);
3775 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3776 struct cYAML **err_rc)
3778 struct lnet_ioctl_lnet_stats data;
3779 struct lnet_counters *cntrs;
3782 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3783 struct cYAML *root = NULL, *stats = NULL;
3785 LIBCFS_IOC_INIT_V2(data, st_hdr);
3787 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3792 "\"cannot get lnet statistics: %s\"",
3798 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3800 cntrs = &data.st_cntrs;
3802 root = cYAML_create_object(NULL, NULL);
3806 stats = cYAML_create_object(root, "statistics");
3810 if (!cYAML_create_number(stats, "msgs_alloc",
3811 cntrs->lct_common.lcc_msgs_alloc))
3814 if (!cYAML_create_number(stats, "msgs_max",
3815 cntrs->lct_common.lcc_msgs_max))
3818 if (!cYAML_create_number(stats, "rst_alloc",
3819 cntrs->lct_health.lch_rst_alloc))
3822 if (!cYAML_create_number(stats, "errors",
3823 cntrs->lct_common.lcc_errors))
3826 if (!cYAML_create_number(stats, "send_count",
3827 cntrs->lct_common.lcc_send_count))
3830 if (!cYAML_create_number(stats, "resend_count",
3831 cntrs->lct_health.lch_resend_count))
3834 if (!cYAML_create_number(stats, "response_timeout_count",
3835 cntrs->lct_health.lch_response_timeout_count))
3838 if (!cYAML_create_number(stats, "local_interrupt_count",
3839 cntrs->lct_health.lch_local_interrupt_count))
3842 if (!cYAML_create_number(stats, "local_dropped_count",
3843 cntrs->lct_health.lch_local_dropped_count))
3846 if (!cYAML_create_number(stats, "local_aborted_count",
3847 cntrs->lct_health.lch_local_aborted_count))
3850 if (!cYAML_create_number(stats, "local_no_route_count",
3851 cntrs->lct_health.lch_local_no_route_count))
3854 if (!cYAML_create_number(stats, "local_timeout_count",
3855 cntrs->lct_health.lch_local_timeout_count))
3858 if (!cYAML_create_number(stats, "local_error_count",
3859 cntrs->lct_health.lch_local_error_count))
3862 if (!cYAML_create_number(stats, "remote_dropped_count",
3863 cntrs->lct_health.lch_remote_dropped_count))
3866 if (!cYAML_create_number(stats, "remote_error_count",
3867 cntrs->lct_health.lch_remote_error_count))
3870 if (!cYAML_create_number(stats, "remote_timeout_count",
3871 cntrs->lct_health.lch_remote_timeout_count))
3874 if (!cYAML_create_number(stats, "network_timeout_count",
3875 cntrs->lct_health.lch_network_timeout_count))
3878 if (!cYAML_create_number(stats, "recv_count",
3879 cntrs->lct_common.lcc_recv_count))
3882 if (!cYAML_create_number(stats, "route_count",
3883 cntrs->lct_common.lcc_route_count))
3886 if (!cYAML_create_number(stats, "drop_count",
3887 cntrs->lct_common.lcc_drop_count))
3890 if (!cYAML_create_number(stats, "send_length",
3891 cntrs->lct_common.lcc_send_length))
3894 if (!cYAML_create_number(stats, "recv_length",
3895 cntrs->lct_common.lcc_recv_length))
3898 if (!cYAML_create_number(stats, "route_length",
3899 cntrs->lct_common.lcc_route_length))
3902 if (!cYAML_create_number(stats, "drop_length",
3903 cntrs->lct_common.lcc_drop_length))
3907 cYAML_print_tree(root);
3909 snprintf(err_str, sizeof(err_str), "\"success\"");
3910 rc = LUSTRE_CFG_RC_NO_ERR;
3912 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3913 cYAML_free_tree(root);
3914 } else if (show_rc != NULL && *show_rc != NULL) {
3915 cYAML_insert_sibling((*show_rc)->cy_child,
3922 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3927 typedef int (*cmd_handler_t)(struct cYAML *tree,
3928 struct cYAML **show_rc,
3929 struct cYAML **err_rc);
3931 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3932 struct cYAML **err_rc)
3934 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3936 net = cYAML_get_object_item(tree, "net");
3937 gw = cYAML_get_object_item(tree, "gateway");
3938 hop = cYAML_get_object_item(tree, "hop");
3939 prio = cYAML_get_object_item(tree, "priority");
3940 sen = cYAML_get_object_item(tree, "health_sensitivity");
3941 seq_no = cYAML_get_object_item(tree, "seq_no");
3943 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3944 (gw) ? gw->cy_valuestring : NULL,
3945 (hop) ? hop->cy_valueint : -1,
3946 (prio) ? prio->cy_valueint : -1,
3947 (sen) ? sen->cy_valueint : -1,
3948 (seq_no) ? seq_no->cy_valueint : -1,
3954 * 0: <intf_name>['['<expr>']']
3955 * 1: <intf_name>['['<expr>']']
3957 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3958 struct lnet_dlc_network_descr *nw_descr)
3960 struct cYAML *child = NULL;
3961 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3962 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3964 if (intf_tree == NULL || nw_descr == NULL)
3965 return LUSTRE_CFG_RC_BAD_PARAM;
3967 /* now grab all the interfaces and their cpts */
3968 child = intf_tree->cy_child;
3969 while (child != NULL) {
3970 if (child->cy_valuestring == NULL) {
3971 child = child->cy_next;
3975 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3978 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3979 child->cy_valuestring,
3980 strlen(child->cy_valuestring));
3981 if (rc != LUSTRE_CFG_RC_NO_ERR)
3985 child = child->cy_next;
3989 return LUSTRE_CFG_RC_MISSING_PARAM;
3994 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3996 list_del(&intf_descr->intf_on_network);
3997 free_intf_descr(intf_descr);
4004 yaml_extract_cmn_tunables(struct cYAML *tree,
4005 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
4006 struct cfs_expr_list **global_cpts)
4008 struct cYAML *tun, *item, *smp;
4011 tun = cYAML_get_object_item(tree, "tunables");
4013 item = cYAML_get_object_item(tun, "peer_timeout");
4015 tunables->lct_peer_timeout = item->cy_valueint;
4016 item = cYAML_get_object_item(tun, "peer_credits");
4018 tunables->lct_peer_tx_credits = item->cy_valueint;
4019 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4021 tunables->lct_peer_rtr_credits = item->cy_valueint;
4022 item = cYAML_get_object_item(tun, "credits");
4024 tunables->lct_max_tx_credits = item->cy_valueint;
4025 smp = cYAML_get_object_item(tun, "CPT");
4027 rc = cfs_expr_list_parse(smp->cy_valuestring,
4028 strlen(smp->cy_valuestring),
4029 0, UINT_MAX, global_cpts);
4031 *global_cpts = NULL;
4041 yaml_extract_tunables(struct cYAML *tree,
4042 struct lnet_ioctl_config_lnd_tunables *tunables,
4043 struct cfs_expr_list **global_cpts,
4048 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
4054 lustre_yaml_extract_lnd_tunables(tree, net_type,
4062 * - net type: <net>[<NUM>]
4064 * - nid: <ip>@<net>[<NUM>]
4067 * 0: <intf_name>['['<expr>']']
4068 * 1: <intf_name>['['<expr>']']
4070 * peer_timeout: <NUM>
4071 * peer_credits: <NUM>
4072 * peer_buffer_credits: <NUM>
4075 * peercredits_hiw: <NUM>
4076 * map_on_demand: <NUM>
4077 * concurrent_sends: <NUM>
4078 * fmr_pool_size: <NUM>
4079 * fmr_flush_trigger: <NUM>
4082 * At least one interface is required. If no interfaces are provided the
4083 * network interface can not be configured.
4085 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4086 struct cYAML **err_rc)
4088 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4090 int num_entries = 0, rc;
4091 struct lnet_dlc_network_descr nw_descr;
4092 struct cfs_expr_list *global_cpts = NULL;
4093 struct lnet_ioctl_config_lnd_tunables tunables;
4096 memset(&tunables, 0, sizeof(tunables));
4098 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4099 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4101 ip2net = cYAML_get_object_item(tree, "ip2net");
4102 net = cYAML_get_object_item(tree, "net type");
4104 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4106 nw_descr.nw_id = LOLND;
4109 * if neither net nor ip2nets are present, then we can not
4110 * configure the network.
4112 if (!net && !ip2net)
4113 return LUSTRE_CFG_RC_MISSING_PARAM;
4115 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4116 if (local_nis == NULL)
4117 return LUSTRE_CFG_RC_MISSING_PARAM;
4119 if (!cYAML_is_sequence(local_nis))
4120 return LUSTRE_CFG_RC_BAD_PARAM;
4122 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4123 intf = cYAML_get_object_item(item, "interfaces");
4126 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4127 if (num_entries <= 0) {
4128 cYAML_build_error(num_entries, -1, "ni", "add",
4129 "bad interface list",
4131 return LUSTRE_CFG_RC_BAD_PARAM;
4135 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4136 LNET_NETTYP(nw_descr.nw_id));
4137 seq_no = cYAML_get_object_item(tree, "seq_no");
4139 rc = lustre_lnet_config_ni(&nw_descr,
4141 (ip2net) ? ip2net->cy_valuestring : NULL,
4142 (found) ? &tunables: NULL,
4143 (seq_no) ? seq_no->cy_valueint : -1,
4146 if (global_cpts != NULL)
4147 cfs_expr_list_free(global_cpts);
4154 * - net-spec: <tcp|o2ib|gni>[NUM]
4156 * 0: <intf name>['['<expr>']']
4157 * 1: <intf name>['['<expr>']']
4159 * 0: <expr.expr.expr.expr>
4160 * 1: <expr.expr.expr.expr>
4162 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4163 struct cYAML **show_rc,
4164 struct cYAML **err_rc)
4166 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4168 struct lustre_lnet_ip2nets ip2nets;
4169 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4171 int rc = LUSTRE_CFG_RC_NO_ERR;
4172 struct cfs_expr_list *global_cpts = NULL;
4173 struct cfs_expr_list *el, *el_tmp;
4174 struct lnet_ioctl_config_lnd_tunables tunables;
4175 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4178 memset(&tunables, 0, sizeof(tunables));
4180 /* initialize all lists */
4181 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4182 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4183 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4185 net = cYAML_get_object_item(tree, "net-spec");
4187 return LUSTRE_CFG_RC_BAD_PARAM;
4189 if (net != NULL && net->cy_valuestring == NULL)
4190 return LUSTRE_CFG_RC_BAD_PARAM;
4192 /* assign the network id */
4193 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4194 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4195 return LUSTRE_CFG_RC_BAD_PARAM;
4197 seq_no = cYAML_get_object_item(tree, "seq_no");
4199 intf = cYAML_get_object_item(tree, "interfaces");
4201 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4203 return LUSTRE_CFG_RC_BAD_PARAM;
4206 ip_range = cYAML_get_object_item(tree, "ip-range");
4207 if (ip_range != NULL) {
4208 item = ip_range->cy_child;
4209 while (item != NULL) {
4210 if (item->cy_valuestring == NULL) {
4211 item = item->cy_next;
4215 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4216 item->cy_valuestring);
4218 if (rc != LUSTRE_CFG_RC_NO_ERR)
4221 item = item->cy_next;
4225 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4226 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4228 rc = lustre_lnet_config_ip2nets(&ip2nets,
4229 (found) ? &tunables : NULL,
4231 (seq_no) ? seq_no->cy_valueint : -1,
4235 * don't stop because there was no match. Continue processing the
4236 * rest of the rules. If non-match then nothing is configured
4238 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4239 rc = LUSTRE_CFG_RC_NO_ERR;
4241 list_for_each_entry_safe(intf_descr, intf_tmp,
4242 &ip2nets.ip2nets_net.nw_intflist,
4244 list_del(&intf_descr->intf_on_network);
4245 free_intf_descr(intf_descr);
4248 list_for_each_entry_safe(ip_range_descr, tmp,
4249 &ip2nets.ip2nets_ip_ranges,
4251 list_del(&ip_range_descr->ipr_entry);
4252 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4254 list_del(&el->el_link);
4255 cfs_expr_list_free(el);
4257 free(ip_range_descr);
4263 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4264 struct cYAML **err_rc)
4266 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4268 int num_entries, rc;
4269 struct lnet_dlc_network_descr nw_descr;
4271 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4272 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4274 net = cYAML_get_object_item(tree, "net type");
4276 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4278 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4279 if (local_nis == NULL)
4280 return LUSTRE_CFG_RC_MISSING_PARAM;
4282 if (!cYAML_is_sequence(local_nis))
4283 return LUSTRE_CFG_RC_BAD_PARAM;
4285 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4286 intf = cYAML_get_object_item(item, "interfaces");
4289 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4290 if (num_entries <= 0) {
4291 cYAML_build_error(num_entries, -1, "ni", "add",
4292 "bad interface list",
4294 return LUSTRE_CFG_RC_BAD_PARAM;
4298 seq_no = cYAML_get_object_item(tree, "seq_no");
4300 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4301 (seq_no) ? seq_no->cy_valueint : -1,
4307 /* Create a nidstring parseable by the nidstrings library from the nid
4308 * information encoded in the CYAML structure.
4309 * NOTE: Caller must free memory allocated to nidstr
4311 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4312 char *prim_nid, int cmd)
4314 int num_strs = 0, rc;
4315 size_t buf_size, buf_pos, nidstr_len = 0;
4317 struct cYAML *child = NULL, *entry = NULL;
4319 if (cYAML_is_sequence(nids_entry)) {
4320 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4321 entry = cYAML_get_object_item(child, "nid");
4322 /* don't count an empty entry */
4323 if (!entry || !entry->cy_valuestring)
4327 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4328 if (cmd == LNETCTL_DEL_CMD) {
4330 * primary nid is present in the list of
4331 * nids so that means we want to delete
4332 * the entire peer, so no need to go
4333 * further. Just delete the entire peer.
4335 return LUSTRE_CFG_RC_NO_ERR;
4342 * + 1 for the space separating each string, and
4343 * accounts for the terminating null char
4345 nidstr_len += strlen(entry->cy_valuestring) + 1;
4350 if (num_strs == 0 && !prim_nid)
4351 return LUSTRE_CFG_RC_MISSING_PARAM;
4352 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4353 return LUSTRE_CFG_RC_NO_ERR;
4355 buffer = malloc(nidstr_len);
4357 return LUSTRE_CFG_RC_OUT_OF_MEM;
4359 /* now grab all the nids */
4362 buf_size = nidstr_len;
4364 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4365 entry = cYAML_get_object_item(child, "nid");
4366 if (!entry || !entry->cy_valuestring)
4370 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4374 rc = snprintf(buffer + buf_pos, buf_size, " ");
4375 buf_pos += (rc < buf_size) ? rc : buf_size;
4376 buf_size = nidstr_len - buf_pos;
4379 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4380 entry->cy_valuestring);
4381 buf_pos += (rc < buf_size) ? rc : buf_size;
4382 buf_size = nidstr_len - buf_pos;
4387 return LUSTRE_CFG_RC_NO_ERR;
4390 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4391 struct cYAML **err_rc, int cmd)
4393 int rc, num_nids = 0, seqn;
4394 bool mr_value = false;
4395 char *nidstr = NULL, *prim_nidstr;
4396 char err_str[LNET_MAX_STR_LEN];
4397 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4398 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4399 lnet_nid_t pnid = LNET_NID_ANY;
4401 seq_no = cYAML_get_object_item(tree, "seq_no");
4402 seqn = seq_no ? seq_no->cy_valueint : -1;
4404 prim_nid = cYAML_get_object_item(tree, "primary nid");
4405 peer_nis = cYAML_get_object_item(tree, "peer ni");
4407 rc = LUSTRE_CFG_RC_BAD_PARAM;
4408 snprintf(err_str, LNET_MAX_STR_LEN,
4409 "\"primary nid\" must be specified");
4413 prim_nidstr = prim_nid->cy_valuestring;
4415 /* if the provided primary NID is bad, no need to go any further */
4416 pnid = libcfs_str2nid(prim_nidstr);
4417 if (pnid == LNET_NID_ANY) {
4418 rc = LUSTRE_CFG_RC_BAD_PARAM;
4419 snprintf(err_str, LNET_MAX_STR_LEN,
4420 "badly formatted primary NID: %s", prim_nidstr);
4424 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4425 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4426 snprintf(err_str, LNET_MAX_STR_LEN,
4427 "No nids defined in YAML block");
4429 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4430 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4432 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4433 snprintf(err_str, LNET_MAX_STR_LEN,
4434 "Unrecognized error %d", rc);
4440 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4441 LNET_MAX_NIDS_PER_PEER,
4449 if (cmd == LNETCTL_ADD_CMD) {
4450 mr = cYAML_get_object_item(tree, "Multi-Rail");
4452 if (mr && mr->cy_valuestring) {
4453 if (strcmp(mr->cy_valuestring, "False") == 0)
4455 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4456 rc = LUSTRE_CFG_RC_BAD_PARAM;
4457 snprintf(err_str, LNET_MAX_STR_LEN,
4458 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4459 mr->cy_valuestring);
4465 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4466 num_nids, mr_value, seqn,
4473 if (rc != LUSTRE_CFG_RC_NO_ERR)
4474 cYAML_build_error(rc, seqn, "peer",
4475 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4481 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4482 struct cYAML **err_rc)
4484 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4487 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4488 struct cYAML **err_rc)
4490 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4493 static int handle_yaml_config_buffers(struct cYAML *tree,
4494 struct cYAML **show_rc,
4495 struct cYAML **err_rc)
4498 struct cYAML *tiny, *small, *large, *seq_no;
4500 tiny = cYAML_get_object_item(tree, "tiny");
4501 small = cYAML_get_object_item(tree, "small");
4502 large = cYAML_get_object_item(tree, "large");
4503 seq_no = cYAML_get_object_item(tree, "seq_no");
4505 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4506 (small) ? small->cy_valueint : -1,
4507 (large) ? large->cy_valueint : -1,
4508 (seq_no) ? seq_no->cy_valueint : -1,
4514 static int handle_yaml_config_routing(struct cYAML *tree,
4515 struct cYAML **show_rc,
4516 struct cYAML **err_rc)
4518 int rc = LUSTRE_CFG_RC_NO_ERR;
4519 struct cYAML *seq_no, *enable;
4521 seq_no = cYAML_get_object_item(tree, "seq_no");
4522 enable = cYAML_get_object_item(tree, "enable");
4525 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4527 seq_no->cy_valueint : -1,
4534 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4535 struct cYAML **err_rc)
4539 struct cYAML *seq_no;
4541 net = cYAML_get_object_item(tree, "net");
4542 gw = cYAML_get_object_item(tree, "gateway");
4543 seq_no = cYAML_get_object_item(tree, "seq_no");
4545 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4546 (gw) ? gw->cy_valuestring : NULL,
4547 (seq_no) ? seq_no->cy_valueint : -1,
4551 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4552 struct cYAML **err_rc)
4554 struct cYAML *seq_no;
4556 seq_no = cYAML_get_object_item(tree, "seq_no");
4558 return lustre_lnet_enable_routing(0, (seq_no) ?
4559 seq_no->cy_valueint : -1,
4563 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4564 struct cYAML **err_rc)
4570 struct cYAML *detail;
4571 struct cYAML *seq_no;
4573 net = cYAML_get_object_item(tree, "net");
4574 gw = cYAML_get_object_item(tree, "gateway");
4575 hop = cYAML_get_object_item(tree, "hop");
4576 prio = cYAML_get_object_item(tree, "priority");
4577 detail = cYAML_get_object_item(tree, "detail");
4578 seq_no = cYAML_get_object_item(tree, "seq_no");
4580 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4581 (gw) ? gw->cy_valuestring : NULL,
4582 (hop) ? hop->cy_valueint : -1,
4583 (prio) ? prio->cy_valueint : -1,
4584 (detail) ? detail->cy_valueint : 0,
4585 (seq_no) ? seq_no->cy_valueint : -1,
4586 show_rc, err_rc, false);
4589 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4590 struct cYAML **err_rc)
4592 struct cYAML *net, *detail, *seq_no;
4594 net = cYAML_get_object_item(tree, "net");
4595 detail = cYAML_get_object_item(tree, "detail");
4596 seq_no = cYAML_get_object_item(tree, "seq_no");
4598 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4599 (detail) ? detail->cy_valueint : 0,
4600 (seq_no) ? seq_no->cy_valueint : -1,
4601 show_rc, err_rc, false);
4604 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4605 struct cYAML **err_rc)
4607 struct cYAML *seq_no;
4609 seq_no = cYAML_get_object_item(tree, "seq_no");
4611 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4612 show_rc, err_rc, false);
4615 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4616 struct cYAML **err_rc)
4618 struct cYAML *seq_no, *nid, *detail;
4620 seq_no = cYAML_get_object_item(tree, "seq_no");
4621 detail = cYAML_get_object_item(tree, "detail");
4622 nid = cYAML_get_object_item(tree, "nid");
4624 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4625 (detail) ? detail->cy_valueint : 0,
4626 (seq_no) ? seq_no->cy_valueint : -1,
4627 show_rc, err_rc, false);
4630 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4631 struct cYAML **err_rc)
4633 struct cYAML *seq_no;
4635 seq_no = cYAML_get_object_item(tree, "seq_no");
4637 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4641 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4642 struct cYAML **err_rc)
4644 struct cYAML *seq_no, *range;
4646 seq_no = cYAML_get_object_item(tree, "seq_no");
4647 range = cYAML_get_object_item(tree, "range");
4649 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4650 seq_no ? seq_no->cy_valueint : -1,
4654 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4655 struct cYAML **err_rc)
4657 struct cYAML *seq_no;
4659 seq_no = cYAML_get_object_item(tree, "seq_no");
4661 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4665 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4666 struct cYAML **err_rc)
4668 struct cYAML *seq_no;
4670 seq_no = cYAML_get_object_item(tree, "seq_no");
4672 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4676 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
4677 struct cYAML **err_rc)
4679 struct cYAML *seq_no, *idx;
4681 seq_no = cYAML_get_object_item(tree, "seq_no");
4682 idx = cYAML_get_object_item(tree, "idx");
4684 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
4685 seq_no ? seq_no->cy_valueint : -1,
4689 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
4690 struct cYAML **err_rc)
4692 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
4693 union lnet_udsp_action action;
4695 seq_no = cYAML_get_object_item(tree, "seq_no");
4696 src = cYAML_get_object_item(tree, "src");
4697 rte = cYAML_get_object_item(tree, "rte");
4698 dst = cYAML_get_object_item(tree, "dst");
4699 prio = cYAML_get_object_item(tree, "priority");
4700 idx = cYAML_get_object_item(tree, "idx");
4702 action.udsp_priority = prio ? prio->cy_valueint : -1;
4704 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
4705 dst ? dst->cy_valuestring : NULL,
4706 rte ? rte->cy_valuestring : NULL,
4707 prio ? "priority" : "",
4709 idx ? idx->cy_valueint : -1,
4710 seq_no ? seq_no->cy_valueint : -1,
4714 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
4715 struct cYAML **err_rc)
4717 struct cYAML *seq_no;
4720 seq_no = cYAML_get_object_item(tree, "seq_no");
4721 idx = cYAML_get_object_item(tree, "idx");
4723 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
4724 seq_no ? seq_no->cy_valueint : -1,
4728 static int handle_yaml_config_global_settings(struct cYAML *tree,
4729 struct cYAML **show_rc,
4730 struct cYAML **err_rc)
4732 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4733 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
4737 seq_no = cYAML_get_object_item(tree, "seq_no");
4738 max_intf = cYAML_get_object_item(tree, "max_interfaces");
4739 if (!max_intf) /* try legacy name */
4740 max_intf = cYAML_get_object_item(tree, "max_intf");
4742 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4743 seq_no ? seq_no->cy_valueint
4747 numa = cYAML_get_object_item(tree, "numa_range");
4749 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4750 seq_no ? seq_no->cy_valueint
4754 discovery = cYAML_get_object_item(tree, "discovery");
4756 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4757 seq_no ? seq_no->cy_valueint
4761 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4762 if (drop_asym_route)
4763 rc = lustre_lnet_config_drop_asym_route(
4764 drop_asym_route->cy_valueint,
4765 seq_no ? seq_no->cy_valueint : -1,
4768 retry = cYAML_get_object_item(tree, "retry_count");
4770 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4771 seq_no ? seq_no->cy_valueint
4775 tto = cYAML_get_object_item(tree, "transaction_timeout");
4777 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4778 seq_no ? seq_no->cy_valueint
4782 sen = cYAML_get_object_item(tree, "health_sensitivity");
4784 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4785 seq_no ? seq_no->cy_valueint
4789 recov = cYAML_get_object_item(tree, "recovery_interval");
4791 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4792 seq_no ? seq_no->cy_valueint
4796 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4798 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4799 seq_no ? seq_no->cy_valueint
4803 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4805 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
4806 seq_no ? seq_no->cy_valueint
4810 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
4812 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
4813 seq_no ? seq_no->cy_valueint
4820 static int handle_yaml_del_global_settings(struct cYAML *tree,
4821 struct cYAML **show_rc,
4822 struct cYAML **err_rc)
4824 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4827 seq_no = cYAML_get_object_item(tree, "seq_no");
4828 max_intf = cYAML_get_object_item(tree, "max_interfaces");
4829 if (!max_intf) /* try legacy name */
4830 max_intf = cYAML_get_object_item(tree, "max_intf");
4832 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4833 seq_no ? seq_no->cy_valueint
4837 numa = cYAML_get_object_item(tree, "numa_range");
4839 rc = lustre_lnet_config_numa_range(0,
4840 seq_no ? seq_no->cy_valueint
4844 /* peer discovery is enabled by default */
4845 discovery = cYAML_get_object_item(tree, "discovery");
4847 rc = lustre_lnet_config_discovery(1,
4848 seq_no ? seq_no->cy_valueint
4852 /* asymmetrical route messages are accepted by default */
4853 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4854 if (drop_asym_route)
4855 rc = lustre_lnet_config_drop_asym_route(
4856 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4861 static int handle_yaml_show_global_settings(struct cYAML *tree,
4862 struct cYAML **show_rc,
4863 struct cYAML **err_rc)
4865 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4866 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
4870 seq_no = cYAML_get_object_item(tree, "seq_no");
4871 max_intf = cYAML_get_object_item(tree, "max_interfaces");
4872 if (!max_intf) /* try legacy name */
4873 max_intf = cYAML_get_object_item(tree, "max_intf");
4875 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4879 numa = cYAML_get_object_item(tree, "numa_range");
4881 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4885 discovery = cYAML_get_object_item(tree, "discovery");
4887 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4891 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4892 if (drop_asym_route)
4893 rc = lustre_lnet_show_drop_asym_route(
4894 seq_no ? seq_no->cy_valueint : -1,
4897 retry = cYAML_get_object_item(tree, "retry_count");
4899 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4903 tto = cYAML_get_object_item(tree, "transaction_timeout");
4905 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4909 sen = cYAML_get_object_item(tree, "health_sensitivity");
4911 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4915 recov = cYAML_get_object_item(tree, "recovery_interval");
4917 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4921 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4923 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4927 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4929 rc = lustre_lnet_show_response_tracking(seq_no ?
4930 seq_no->cy_valueint :
4934 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
4936 rc = lustre_lnet_show_recovery_limit(seq_no ?
4937 seq_no->cy_valueint :
4944 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4945 struct cYAML **err_rc)
4947 struct cYAML *seq_no, *nid, *timeout;
4949 seq_no = cYAML_get_object_item(tree, "seq_no");
4950 nid = cYAML_get_object_item(tree, "primary nid");
4951 timeout = cYAML_get_object_item(tree, "timeout");
4953 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4954 (timeout) ? timeout->cy_valueint : 1000,
4955 (seq_no) ? seq_no->cy_valueint : -1,
4959 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4960 struct cYAML **err_rc)
4962 struct cYAML *seq_no, *nid, *force;
4964 seq_no = cYAML_get_object_item(tree, "seq_no");
4965 nid = cYAML_get_object_item(tree, "primary nid");
4966 force = cYAML_get_object_item(tree, "force");
4968 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4969 (force) ? force->cy_valueint : 0,
4970 (seq_no) ? seq_no->cy_valueint : -1,
4974 static int handle_yaml_no_op()
4976 return LUSTRE_CFG_RC_NO_ERR;
4979 struct lookup_cmd_hdlr_tbl {
4984 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4985 { .name = "route", .cb = handle_yaml_config_route },
4986 { .name = "net", .cb = handle_yaml_config_ni },
4987 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4988 { .name = "peer", .cb = handle_yaml_config_peer },
4989 { .name = "routing", .cb = handle_yaml_config_routing },
4990 { .name = "buffers", .cb = handle_yaml_config_buffers },
4991 { .name = "statistics", .cb = handle_yaml_no_op },
4992 { .name = "global", .cb = handle_yaml_config_global_settings},
4993 { .name = "numa", .cb = handle_yaml_config_numa },
4994 { .name = "ping", .cb = handle_yaml_no_op },
4995 { .name = "discover", .cb = handle_yaml_no_op },
4996 { .name = "udsp", .cb = handle_yaml_config_udsp },
4999 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5000 { .name = "route", .cb = handle_yaml_del_route },
5001 { .name = "net", .cb = handle_yaml_del_ni },
5002 { .name = "ip2nets", .cb = handle_yaml_no_op },
5003 { .name = "peer", .cb = handle_yaml_del_peer },
5004 { .name = "routing", .cb = handle_yaml_del_routing },
5005 { .name = "buffers", .cb = handle_yaml_no_op },
5006 { .name = "statistics", .cb = handle_yaml_no_op },
5007 { .name = "global", .cb = handle_yaml_del_global_settings},
5008 { .name = "numa", .cb = handle_yaml_del_numa },
5009 { .name = "ping", .cb = handle_yaml_no_op },
5010 { .name = "discover", .cb = handle_yaml_no_op },
5011 { .name = "udsp", .cb = handle_yaml_del_udsp },
5014 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5015 { .name = "route", .cb = handle_yaml_show_route },
5016 { .name = "net", .cb = handle_yaml_show_net },
5017 { .name = "peer", .cb = handle_yaml_show_peers },
5018 { .name = "ip2nets", .cb = handle_yaml_no_op },
5019 { .name = "routing", .cb = handle_yaml_show_routing },
5020 { .name = "buffers", .cb = handle_yaml_show_routing },
5021 { .name = "statistics", .cb = handle_yaml_show_stats },
5022 { .name = "global", .cb = handle_yaml_show_global_settings},
5023 { .name = "numa", .cb = handle_yaml_show_numa },
5024 { .name = "ping", .cb = handle_yaml_no_op },
5025 { .name = "discover", .cb = handle_yaml_no_op },
5026 { .name = "udsp", .cb = handle_yaml_show_udsp },
5029 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5030 { .name = "route", .cb = handle_yaml_no_op },
5031 { .name = "net", .cb = handle_yaml_no_op },
5032 { .name = "peer", .cb = handle_yaml_no_op },
5033 { .name = "ip2nets", .cb = handle_yaml_no_op },
5034 { .name = "routing", .cb = handle_yaml_no_op },
5035 { .name = "buffers", .cb = handle_yaml_no_op },
5036 { .name = "statistics", .cb = handle_yaml_no_op },
5037 { .name = "global", .cb = handle_yaml_no_op },
5038 { .name = "numa", .cb = handle_yaml_no_op },
5039 { .name = "ping", .cb = handle_yaml_ping },
5040 { .name = "discover", .cb = handle_yaml_discover },
5043 static cmd_handler_t lookup_fn(char *key,
5044 struct lookup_cmd_hdlr_tbl *tbl)
5050 for (i = 0; tbl[i].name != NULL; i++) {
5051 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5058 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5059 struct cYAML **show_rc, struct cYAML **err_rc)
5061 struct cYAML *tree, *item = NULL, *head, *child;
5063 char err_str[LNET_MAX_STR_LEN];
5064 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5066 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5068 return LUSTRE_CFG_RC_BAD_PARAM;
5070 child = tree->cy_child;
5071 while (child != NULL) {
5072 cb = lookup_fn(child->cy_string, table);
5074 snprintf(err_str, sizeof(err_str),
5075 "\"call back for '%s' not found\"",
5077 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5078 "yaml", "helper", err_str, err_rc);
5082 if (cYAML_is_sequence(child)) {
5083 while ((head = cYAML_get_next_seq_item(child, &item))
5085 rc = cb(head, show_rc, err_rc);
5086 if (rc != LUSTRE_CFG_RC_NO_ERR)
5090 rc = cb(child, show_rc, err_rc);
5091 if (rc != LUSTRE_CFG_RC_NO_ERR)
5095 child = child->cy_next;
5099 cYAML_free_tree(tree);
5104 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5106 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5110 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5112 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5116 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5118 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5122 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5124 return lustre_yaml_cb_helper(f, lookup_exec_tbl,