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];
384 snprintf(err_str, sizeof(err_str), "\"Success\"");
386 LIBCFS_IOC_INIT(data);
388 /* Reverse logic is used here in order not to change
389 * the lctl utility */
390 data.ioc_flags = load_ni_from_mod ? 0 : 1;
392 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
394 rc = l_ioctl(LNET_DEV_ID, opc, &data);
398 "\"LNet %s error: %s\"", (up) ? "configure" :
399 "unconfigure", strerror(errno));
403 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
404 "lnet", err_str, err_rc);
409 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
410 char *err_str, char *cmd_str)
414 rc = l_ioctl(LNET_DEV_ID, cmd, data);
417 snprintf(err_str, LNET_MAX_STR_LEN,
418 "\"%s peer ni operation failed: %s\"",
419 cmd_str, strerror(errno));
425 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
426 int seq_no, struct cYAML **show_rc,
427 struct cYAML **err_rc)
430 struct lnet_ioctl_ping_data ping;
431 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
432 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
433 struct lnet_process_id id;
434 char err_str[LNET_MAX_STR_LEN] = {0};
435 char *sep, *token, *end;
438 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
442 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
444 data = calloc(1, len);
448 /* create struct cYAML root object */
449 root = cYAML_create_object(NULL, NULL);
453 ping_node = cYAML_create_seq(root, oper);
454 if (ping_node == NULL)
457 /* tokenise each nid in string ping_nids */
458 token = strtok(ping_nids, ",");
461 item = cYAML_create_seq_item(ping_node);
465 if (first_seq == NULL)
468 /* check if '-' is a part of NID, token */
469 sep = strchr(token, '-');
471 id.pid = LNET_PID_ANY;
472 /* if no net is specified, libcfs_str2nid() will assume tcp */
473 id.nid = libcfs_str2nid(token);
474 if (id.nid == LNET_NID_ANY) {
475 snprintf(err_str, sizeof(err_str),
476 "\"cannot parse NID '%s'\"",
478 rc = LUSTRE_CFG_RC_BAD_PARAM;
479 cYAML_build_error(rc, seq_no, MANAGE_CMD,
480 oper, err_str, err_rc);
484 if (token[0] == 'u' || token[0] == 'U')
485 id.pid = (strtoul(&token[1], &end, 0) |
486 (LNET_PID_USERFLAG));
488 id.pid = strtoul(token, &end, 0);
490 /* assuming '-' is part of hostname */
492 id.pid = LNET_PID_ANY;
493 id.nid = libcfs_str2nid(token);
494 if (id.nid == LNET_NID_ANY) {
495 snprintf(err_str, sizeof(err_str),
496 "\"cannot parse NID '%s'\"",
498 rc = LUSTRE_CFG_RC_BAD_PARAM;
499 cYAML_build_error(rc, seq_no, MANAGE_CMD,
505 id.nid = libcfs_str2nid(sep + 1);
506 if (id.nid == LNET_NID_ANY) {
507 snprintf(err_str, sizeof(err_str),
508 "\"cannot parse NID '%s'\"",
510 rc = LUSTRE_CFG_RC_BAD_PARAM;
511 cYAML_build_error(rc, seq_no, MANAGE_CMD,
518 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
519 ping.ping_hdr.ioc_len = sizeof(ping);
521 ping.op_param = param;
522 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
523 ping.ping_buf = data;
525 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
528 sizeof(err_str), "failed to %s %s: %s\n", oper,
529 id.pid == LNET_PID_ANY ?
530 libcfs_nid2str(id.nid) :
531 libcfs_id2str(id), strerror(errno));
532 rc = LUSTRE_CFG_RC_BAD_PARAM;
533 cYAML_build_error(rc, seq_no, MANAGE_CMD,
534 oper, err_str, err_rc);
538 if (cYAML_create_string(item, "primary nid",
539 libcfs_nid2str(ping.ping_id.nid)) == NULL)
542 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
543 "True" : "False") == NULL)
546 tmp = cYAML_create_seq(item, "peer ni");
550 for (i = 0; i < ping.ping_count; i++) {
551 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
553 peer_ni = cYAML_create_seq_item(tmp);
556 memset(buf, 0, sizeof buf);
557 snprintf(buf, sizeof buf, "nid");
558 if (cYAML_create_string(peer_ni, buf,
559 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
565 } while ((token = strtok(NULL, ",")) != NULL);
568 rc = LUSTRE_CFG_RC_NO_ERR;
573 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
574 cYAML_free_tree(root);
575 } else if (show_rc != NULL && *show_rc != NULL) {
576 struct cYAML *show_node;
577 show_node = cYAML_get_object_item(*show_rc, oper);
578 if (show_node != NULL && cYAML_is_sequence(show_node)) {
579 cYAML_insert_child(show_node, first_seq);
582 } else if (show_node == NULL) {
583 cYAML_insert_sibling((*show_rc)->cy_child,
587 cYAML_free_tree(root);
596 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
597 struct cYAML **show_rc, struct cYAML **err_rc)
601 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
602 seq_no, show_rc, err_rc);
606 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
607 struct cYAML **show_rc, struct cYAML **err_rc)
611 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
612 seq_no, show_rc, err_rc);
616 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
617 bool is_mr, __u32 cmd,
618 char *cmd_type, char *err_str)
620 struct lnet_ioctl_peer_cfg data;
623 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
624 /* When adding a peer we first need to create the peer using the
625 * specified (or implied) primary nid. Then we can add
626 * additional nids to this peer using the primary nid as a key
628 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
629 data.prcfg_mr = is_mr;
630 data.prcfg_prim_nid = nidlist[0];
631 data.prcfg_cfg_nid = LNET_NID_ANY;
633 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
639 /* Add or delete any specified NIs associated with the specified
640 * (or implied) primary nid
642 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
643 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
644 data.prcfg_mr = is_mr;
645 data.prcfg_prim_nid = nidlist[0];
646 data.prcfg_cfg_nid = nidlist[nid_idx];
648 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
654 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
655 /* In the delete case we may have been given just the
656 * primary nid of the peer. This tells us to delete the peer
657 * completely (rather than just delete some of its NIs)
659 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
660 data.prcfg_prim_nid = nidlist[0];
661 data.prcfg_cfg_nid = LNET_NID_ANY;
663 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
670 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
671 int cmd, int num_nids, bool is_mr, int seq_no,
672 struct cYAML **err_rc)
674 int rc = LUSTRE_CFG_RC_NO_ERR;
675 char err_str[LNET_MAX_STR_LEN];
676 lnet_nid_t *lnet_nidlist2 = NULL;
677 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
678 IOC_LIBCFS_DEL_PEER_NI;
679 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
682 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
683 if (!lnet_nidlist2) {
684 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
685 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
688 lnet_nidlist2[0] = pnid;
689 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
692 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
693 num_nids, is_mr, ioc_cmd,
699 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
704 replace_sep(char *str, char sep, char newsep)
710 for (i = 0; i < strlen(str); i++) {
711 /* don't replace ',' within [] */
714 else if (str[i] == ']')
716 else if (str[i] == sep && bracket == 0)
721 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
722 int cmd, int seq_no, struct cYAML **err_rc)
725 char err_str[LNET_MAX_STR_LEN] = "Error";
726 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
727 lnet_nid_t pnid = LNET_NID_ANY;
730 rc = LUSTRE_CFG_RC_BAD_PARAM;
731 snprintf(err_str, LNET_MAX_STR_LEN,
732 "--prim_nid must be specified");
736 pnid = libcfs_str2nid(prim_nid);
737 if (pnid == LNET_NID_ANY) {
738 rc = LUSTRE_CFG_RC_BAD_PARAM;
739 snprintf(err_str, LNET_MAX_STR_LEN,
740 "badly formatted primary NID: %s", prim_nid);
747 * if there is no primary nid we need to make the first nid in the
748 * nids list the primary nid
750 replace_sep(nids, ',', ' ');
751 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
752 LNET_MAX_NIDS_PER_PEER, err_str);
759 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
760 cmd, num_nids, is_mr,
764 if (rc != LUSTRE_CFG_RC_NO_ERR)
765 cYAML_build_error(rc, -1, "peer",
766 cmd == LNETCTL_ADD_CMD ? "add" : "del",
772 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
773 int sen, int seq_no, struct cYAML **err_rc,
776 int rc, num_nids, idx;
778 char err_str[LNET_MAX_STR_LEN];
779 struct lnet_ioctl_config_data data;
780 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
782 memset(err_str, 0, LNET_MAX_STR_LEN);
783 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
785 if (nw == NULL || nidstr == NULL) {
786 snprintf(err_str, LNET_MAX_STR_LEN,
787 "\"missing mandatory parameter:'%s'\"",
788 (nw == NULL && nidstr == NULL) ? "network, gateway" :
789 (nw == NULL) ? "network" : "gateway");
790 rc = LUSTRE_CFG_RC_MISSING_PARAM;
794 rnet = libcfs_str2net(nw);
795 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
796 snprintf(err_str, LNET_MAX_STR_LEN,
797 "\"cannot parse remote net %s\"", nw);
798 rc = LUSTRE_CFG_RC_BAD_PARAM;
802 replace_sep(nidstr, ',', ' ');
803 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
804 LNET_MAX_NIDS_PER_PEER, err_str);
810 for (idx = 0; idx < num_nids; idx++) {
811 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
813 if (cmd == LNETCTL_ADD_CMD) {
814 data.cfg_config_u.cfg_route.rtr_hop = hops;
815 data.cfg_config_u.cfg_route.rtr_priority = prio;
816 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
819 data.cfg_nid = lnet_nidlist[idx];
821 if (cmd == LNETCTL_ADD_CMD)
822 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
825 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
828 if (rc != 0 && errno != EEXIST &&
829 errno != EHOSTUNREACH) {
831 snprintf(err_str, LNET_MAX_STR_LEN,
832 "route operation failed: %s",
835 } else if (errno == EEXIST) {
837 * continue chugging along if one of the
838 * routes already exists
845 cYAML_build_error(rc, seq_no,
846 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
852 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
853 int sen, int seq_no, struct cYAML **err_rc)
856 char err_str[LNET_MAX_STR_LEN];
857 memset(err_str, 0, LNET_MAX_STR_LEN);
858 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
861 hops = LNET_UNDEFINED_HOPS;
862 } else if (hops < 1 || hops > 255) {
863 snprintf(err_str, LNET_MAX_STR_LEN,
864 "\"invalid hop count %d, must be between 1 and 255\"",
866 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
872 } else if (prio < 0) {
873 snprintf(err_str, LNET_MAX_STR_LEN,
874 "\"invalid priority %d, must be greater than 0\"",
876 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
882 } else if (sen < 1) {
883 snprintf(err_str, LNET_MAX_STR_LEN,
884 "\"invalid health sensitivity %d, must be 1 or greater\"",
886 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
890 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
891 err_rc, LNETCTL_ADD_CMD);
894 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
899 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
900 struct cYAML **err_rc)
902 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
906 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
907 int seq_no, struct cYAML **show_rc,
908 struct cYAML **err_rc, bool backup)
910 struct lnet_ioctl_config_data data;
911 lnet_nid_t gateway_nid;
912 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
914 __u32 net = LNET_NIDNET(LNET_NID_ANY);
916 struct cYAML *root = NULL, *route = NULL, *item = NULL;
917 struct cYAML *first_seq = NULL;
918 char err_str[LNET_MAX_STR_LEN];
921 snprintf(err_str, sizeof(err_str),
922 "\"out of memory\"");
925 net = libcfs_str2net(nw);
926 if (net == LNET_NIDNET(LNET_NID_ANY)) {
929 "\"cannot parse net '%s'\"", nw);
930 rc = LUSTRE_CFG_RC_BAD_PARAM;
935 /* show all routes without filtering on net */
936 net = LNET_NIDNET(LNET_NID_ANY);
940 gateway_nid = libcfs_str2nid(gw);
941 if (gateway_nid == LNET_NID_ANY) {
944 "\"cannot parse gateway NID '%s'\"", gw);
945 rc = LUSTRE_CFG_RC_BAD_PARAM;
949 /* show all routes with out filtering on gateway */
950 gateway_nid = LNET_NID_ANY;
952 if ((hops < 1 && hops != -1) || hops > 255) {
955 "\"invalid hop count %d, must be between 0 and 256\"",
957 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
961 /* create struct cYAML root object */
962 root = cYAML_create_object(NULL, NULL);
966 route = cYAML_create_seq(root, "route");
974 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
977 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
983 /* filter on provided data */
984 if (net != LNET_NIDNET(LNET_NID_ANY) &&
988 if (gateway_nid != LNET_NID_ANY &&
989 gateway_nid != data.cfg_nid)
993 hops != data.cfg_config_u.cfg_route.rtr_hop)
997 prio != data.cfg_config_u.cfg_route.rtr_priority)
1000 /* default rc to -1 incase we hit the goto */
1004 item = cYAML_create_seq_item(route);
1008 if (first_seq == NULL)
1011 if (cYAML_create_string(item, "net",
1012 libcfs_net2str(data.cfg_net)) == NULL)
1015 if (cYAML_create_string(item, "gateway",
1016 libcfs_nid2str(data.cfg_nid)) == NULL)
1020 if (cYAML_create_number(item, "hop",
1021 (int) data.cfg_config_u.
1022 cfg_route.rtr_hop) ==
1026 if (cYAML_create_number(item, "priority",
1028 cfg_route.rtr_priority) == NULL)
1031 if (cYAML_create_number(item, "health_sensitivity",
1033 cfg_route.rtr_sensitivity) == NULL)
1036 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1038 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1042 cYAML_create_string(item, "state",
1044 "up" : "down") == NULL)
1048 cYAML_create_string(item, "type",
1050 "multi-hop" : "single-hop") == NULL)
1055 /* print output iff show_rc is not provided */
1056 if (show_rc == NULL)
1057 cYAML_print_tree(root);
1059 if (l_errno != ENOENT) {
1062 "\"cannot get routes: %s\"",
1067 rc = LUSTRE_CFG_RC_NO_ERR;
1069 snprintf(err_str, sizeof(err_str), "\"success\"");
1071 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1072 cYAML_free_tree(root);
1073 } else if (show_rc != NULL && *show_rc != NULL) {
1074 struct cYAML *show_node;
1075 /* find the route node, if one doesn't exist then
1076 * insert one. Otherwise add to the one there
1078 show_node = cYAML_get_object_item(*show_rc, "route");
1079 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1080 cYAML_insert_child(show_node, first_seq);
1083 } else if (show_node == NULL) {
1084 cYAML_insert_sibling((*show_rc)->cy_child,
1088 cYAML_free_tree(root);
1094 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1099 static int socket_intf_query(int request, char *intf,
1105 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1106 return LUSTRE_CFG_RC_BAD_PARAM;
1108 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1110 return LUSTRE_CFG_RC_BAD_PARAM;
1112 strcpy(ifr->ifr_name, intf);
1113 rc = ioctl(sockfd, request, ifr);
1115 rc = LUSTRE_CFG_RC_BAD_PARAM;
1122 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1127 memset(&ifr, 0, sizeof(ifr));
1128 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1130 return LUSTRE_CFG_RC_BAD_PARAM;
1132 if ((ifr.ifr_flags & IFF_UP) == 0)
1133 return LUSTRE_CFG_RC_BAD_PARAM;
1135 memset(&ifr, 0, sizeof(ifr));
1136 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1138 return LUSTRE_CFG_RC_BAD_PARAM;
1140 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1141 *ip = bswap_32(*ip);
1143 return LUSTRE_CFG_RC_NO_ERR;
1147 * for each interface in the array of interfaces find the IP address of
1148 * that interface, create its nid and add it to an array of NIDs.
1149 * Stop if any of the interfaces is down
1151 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1152 lnet_nid_t **nids, __u32 *nnids,
1153 char *err_str, size_t str_len)
1155 int i = 0, count = 0, rc;
1156 struct lnet_dlc_intf_descr *intf;
1157 char val[LNET_MAX_STR_LEN];
1164 if (nw == NULL || nids == NULL) {
1165 snprintf(err_str, str_len,
1166 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1167 err_str[str_len - 1] = '\0';
1168 return LUSTRE_CFG_RC_BAD_PARAM;
1171 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1174 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1178 *nids = calloc(count, sizeof(lnet_nid_t));
1179 if (*nids == NULL) {
1180 snprintf(err_str, str_len,
1181 "\"out of memory\"");
1182 err_str[str_len - 1] = '\0';
1183 return LUSTRE_CFG_RC_OUT_OF_MEM;
1186 * special case the GNI interface since it doesn't have an IP
1187 * address. The assumption is that there can only be one GNI
1188 * interface in the system. No interface name is provided.
1190 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1191 rc = read_sysfs_file(gni_nid_path, "nid", val,
1194 snprintf(err_str, str_len,
1195 "\"cannot read gni nid\"");
1196 err_str[str_len - 1] = '\0';
1199 gni_num = atoi(val);
1201 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1206 /* look at the other interfaces */
1207 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1208 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1209 /* handle LNDs with numeric interface name */
1210 num = strtoul(intf->intf_name, &endp, 0);
1211 if (endp == intf->intf_name || *endp != '\0') {
1212 rc = LUSTRE_CFG_RC_BAD_PARAM;
1213 snprintf(err_str, str_len,
1214 "\"couldn't query intf %s\"",
1216 err_str[str_len - 1] = '\0';
1219 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1222 /* handle LNDs with ip interface name */
1223 rc = lustre_lnet_queryip(intf, &ip);
1224 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1225 snprintf(err_str, str_len,
1226 "\"couldn't query intf %s\"",
1228 err_str[str_len - 1] = '\0';
1231 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1248 * called repeatedly until a match or no more ip range
1250 * ip_range expression
1251 * interface list with all the interface names.
1252 * all the interfaces in the system.
1254 * try to match the ip_range expr to one of the interfaces' IPs in
1255 * the system. If we hit a patch for an interface. Check if that
1256 * interface name is in the list.
1258 * If there are more than one interface in the list, then make sure
1259 * that the IPs for all of these interfaces match the ip ranges
1262 * for each interface in intf_list
1263 * look up the intf name in ifa
1264 * if not there then no match
1265 * check ip obtained from ifa against a match to any of the
1267 * If no match, then fail
1269 * The result is that all the interfaces have to match.
1271 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1272 struct list_head *intf_list,
1273 struct list_head *ip_ranges)
1277 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1278 struct ifaddrs *ifaddr = ifa;
1279 struct lustre_lnet_ip_range_descr *ip_range;
1283 * if there are no explicit interfaces, and no ip ranges, then
1284 * configure the first tcp interface we encounter.
1286 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1287 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1288 if (ifaddr->ifa_addr == NULL)
1291 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1294 family = ifaddr->ifa_addr->sa_family;
1295 if (family == AF_INET &&
1296 strcmp(ifaddr->ifa_name, "lo") != 0) {
1297 rc = lustre_lnet_add_intf_descr
1298 (intf_list, ifaddr->ifa_name,
1299 strlen(ifaddr->ifa_name));
1301 if (rc != LUSTRE_CFG_RC_NO_ERR)
1304 return LUSTRE_CFG_RC_MATCH;
1307 return LUSTRE_CFG_RC_NO_MATCH;
1311 * First interface which matches an IP pattern will be used
1313 if (list_empty(intf_list)) {
1315 * no interfaces provided in the rule, but an ip range is
1316 * provided, so try and match an interface to the ip
1319 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1320 if (ifaddr->ifa_addr == NULL)
1323 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1326 family = ifaddr->ifa_addr->sa_family;
1327 if (family == AF_INET) {
1328 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1331 list_for_each_entry(ip_range, ip_ranges,
1333 rc = cfs_ip_addr_match(bswap_32(ip),
1334 &ip_range->ipr_expr);
1338 rc = lustre_lnet_add_intf_descr
1339 (intf_list, ifaddr->ifa_name,
1340 strlen(ifaddr->ifa_name));
1342 if (rc != LUSTRE_CFG_RC_NO_ERR)
1348 if (!list_empty(intf_list))
1349 return LUSTRE_CFG_RC_MATCH;
1351 return LUSTRE_CFG_RC_NO_MATCH;
1355 * If an interface is explicitly specified the ip-range might or
1356 * might not be specified. if specified the interface needs to match the
1357 * ip-range. If no ip-range then the interfaces are
1358 * automatically matched if they are all up.
1359 * If > 1 interfaces all the interfaces must match for the NI to
1362 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1363 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1364 if (ifaddr->ifa_addr == NULL)
1367 family = ifaddr->ifa_addr->sa_family;
1368 if (family == AF_INET &&
1369 strcmp(intf_descr->intf_name,
1370 ifaddr->ifa_name) == 0)
1374 if (ifaddr == NULL) {
1375 list_del(&intf_descr->intf_on_network);
1376 free_intf_descr(intf_descr);
1380 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1381 list_del(&intf_descr->intf_on_network);
1382 free_intf_descr(intf_descr);
1386 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1389 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1390 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1396 /* no match for this interface */
1397 list_del(&intf_descr->intf_on_network);
1398 free_intf_descr(intf_descr);
1402 return LUSTRE_CFG_RC_MATCH;
1405 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1406 lnet_nid_t **nids, __u32 *nnids,
1407 char *err_str, size_t str_len)
1409 struct ifaddrs *ifa;
1410 int rc = LUSTRE_CFG_RC_NO_ERR;
1412 rc = getifaddrs(&ifa);
1414 snprintf(err_str, str_len,
1415 "\"failed to get interface addresses: %d\"", -errno);
1416 err_str[str_len - 1] = '\0';
1420 rc = lustre_lnet_match_ip_to_intf(ifa,
1421 &ip2nets->ip2nets_net.nw_intflist,
1422 &ip2nets->ip2nets_ip_ranges);
1423 if (rc != LUSTRE_CFG_RC_MATCH) {
1424 snprintf(err_str, str_len,
1425 "\"couldn't match ip to existing interfaces\"");
1426 err_str[str_len - 1] = '\0';
1431 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1432 err_str, sizeof(err_str));
1433 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1444 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1445 struct lnet_ioctl_config_lnd_tunables *tunables,
1446 struct cfs_expr_list *global_cpts,
1447 lnet_nid_t *nids, char *err_str)
1450 struct lnet_ioctl_config_ni *conf;
1451 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1452 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1455 struct lnet_dlc_intf_descr *intf_descr;
1457 struct cfs_expr_list *cpt_expr;
1459 list_for_each_entry(intf_descr, intf_list,
1461 if (tunables != NULL)
1462 len = sizeof(struct lnet_ioctl_config_ni) +
1463 sizeof(struct lnet_ioctl_config_lnd_tunables);
1465 len = sizeof(struct lnet_ioctl_config_ni);
1467 data = calloc(1, len);
1469 return LUSTRE_CFG_RC_OUT_OF_MEM;
1470 conf = (struct lnet_ioctl_config_ni*) data;
1471 if (tunables != NULL)
1472 tun = (struct lnet_ioctl_config_lnd_tunables*)
1475 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1476 conf->lic_cfg_hdr.ioc_len = len;
1477 conf->lic_nid = nids[i];
1478 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1481 if (intf_descr->cpt_expr != NULL)
1482 cpt_expr = intf_descr->cpt_expr;
1483 else if (global_cpts != NULL)
1484 cpt_expr = global_cpts;
1488 if (cpt_expr != NULL) {
1489 count = cfs_expr_list_values(cpt_expr,
1490 LNET_MAX_SHOW_NUM_CPT,
1493 memcpy(conf->lic_cpts, cpt_array,
1494 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1503 conf->lic_ncpts = count;
1505 if (tunables != NULL)
1506 memcpy(tun, tunables, sizeof(*tunables));
1508 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1513 "\"cannot add network: %s\"", strerror(errno));
1521 return LUSTRE_CFG_RC_NO_ERR;
1525 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1526 struct lnet_ioctl_config_lnd_tunables *tunables,
1527 struct cfs_expr_list *global_cpts,
1528 int seq_no, struct cYAML **err_rc)
1530 lnet_nid_t *nids = NULL;
1533 char err_str[LNET_MAX_STR_LEN];
1535 snprintf(err_str, sizeof(err_str), "\"success\"");
1540 "\"incomplete ip2nets information\"");
1541 rc = LUSTRE_CFG_RC_BAD_PARAM;
1546 * call below function to resolve the rules into a list of nids.
1547 * The memory is allocated in that function then freed here when
1548 * it's no longer needed.
1550 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1552 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1555 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1556 snprintf(err_str, sizeof(err_str),
1557 "\"no interfaces match ip2nets rules\"");
1561 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1562 tunables, global_cpts, nids,
1569 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1573 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1574 struct cfs_expr_list *global_cpts,
1576 struct lnet_ioctl_config_lnd_tunables *tunables,
1577 int seq_no, struct cYAML **err_rc)
1580 struct lnet_ioctl_config_ni *conf;
1581 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1582 char buf[LNET_MAX_STR_LEN];
1583 int rc = LUSTRE_CFG_RC_NO_ERR;
1584 char err_str[LNET_MAX_STR_LEN];
1585 lnet_nid_t *nids = NULL;
1589 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1592 snprintf(err_str, sizeof(err_str), "\"success\"");
1594 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1595 (list_empty(&nw_descr->nw_intflist) &&
1596 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1599 "\"missing mandatory parameters in NI config: '%s'\"",
1600 (nw_descr == NULL) ? "network , interface" :
1601 (nw_descr->nw_id == 0) ? "network" : "interface");
1602 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1606 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1609 "\"ip2net string too long %d\"",
1610 (int)strlen(ip2net));
1611 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1615 if (ip2net != NULL) {
1616 if (tunables != NULL)
1617 len = sizeof(struct lnet_ioctl_config_ni) +
1618 sizeof(struct lnet_ioctl_config_lnd_tunables);
1620 len = sizeof(struct lnet_ioctl_config_ni);
1621 data = calloc(1, len);
1623 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1626 conf = (struct lnet_ioctl_config_ni*) data;
1627 if (tunables != NULL)
1628 tun = (struct lnet_ioctl_config_lnd_tunables*)
1629 (data + sizeof(*conf));
1631 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1632 conf->lic_cfg_hdr.ioc_len = len;
1633 strncpy(conf->lic_legacy_ip2nets, ip2net,
1636 if (global_cpts != NULL) {
1637 count = cfs_expr_list_values(global_cpts,
1638 LNET_MAX_SHOW_NUM_CPT,
1641 memcpy(conf->lic_cpts, cpt_array,
1642 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1651 conf->lic_ncpts = count;
1653 if (tunables != NULL)
1654 memcpy(tun, tunables, sizeof(*tunables));
1656 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1661 "\"cannot add network: %s\"", strerror(errno));
1668 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1669 rc = LUSTRE_CFG_RC_NO_ERR;
1673 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1676 "\"cannot parse net '%s'\"",
1677 libcfs_net2str(nw_descr->nw_id));
1678 rc = LUSTRE_CFG_RC_BAD_PARAM;
1683 * special case the GNI since no interface name is expected
1685 if (list_empty(&nw_descr->nw_intflist) &&
1686 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1689 "\"no interface name provided\"");
1690 rc = LUSTRE_CFG_RC_BAD_PARAM;
1694 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1695 err_str, sizeof(err_str));
1697 rc = LUSTRE_CFG_RC_BAD_PARAM;
1701 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1702 tunables, global_cpts, nids,
1706 if (nw_descr != NULL) {
1707 list_for_each_entry_safe(intf_descr, tmp,
1708 &nw_descr->nw_intflist,
1710 list_del(&intf_descr->intf_on_network);
1711 free_intf_descr(intf_descr);
1715 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1726 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1727 int seq_no, struct cYAML **err_rc)
1729 struct lnet_ioctl_config_ni data;
1730 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1731 char err_str[LNET_MAX_STR_LEN];
1732 lnet_nid_t *nids = NULL;
1734 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1736 snprintf(err_str, sizeof(err_str), "\"success\"");
1738 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1741 "\"missing mandatory parameter in deleting NI: '%s'\"",
1742 (nw_descr == NULL) ? "network , interface" :
1743 (nw_descr->nw_id == 0) ? "network" : "interface");
1744 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1748 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1749 return LUSTRE_CFG_RC_NO_ERR;
1751 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1754 "\"cannot parse net '%s'\"",
1755 libcfs_net2str(nw_descr->nw_id));
1756 rc = LUSTRE_CFG_RC_BAD_PARAM;
1760 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1761 err_str, sizeof(err_str));
1763 rc = LUSTRE_CFG_RC_BAD_PARAM;
1768 * no interfaces just the nw_id is specified
1771 nids = calloc(1, sizeof(*nids));
1773 snprintf(err_str, sizeof(err_str),
1774 "\"out of memory\"");
1775 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1778 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1782 for (i = 0; i < nnids; i++) {
1783 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1784 data.lic_nid = nids[i];
1786 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1791 "\"cannot del network: %s\"", strerror(errno));
1795 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1797 list_del(&intf_descr->intf_on_network);
1798 free_intf_descr(intf_descr);
1802 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1811 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1812 enum lnet_health_type type, char *name,
1813 int seq_no, struct cYAML **err_rc)
1815 struct lnet_ioctl_reset_health_cfg data;
1816 int rc = LUSTRE_CFG_RC_NO_ERR;
1817 char err_str[LNET_MAX_STR_LEN];
1819 snprintf(err_str, sizeof(err_str), "\"success\"");
1821 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1822 data.rh_type = type;
1824 data.rh_value = value;
1827 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1831 sizeof(err_str), "Can not configure health value: %s",
1835 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1840 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1841 struct cYAML **err_rc)
1845 nid = libcfs_str2nid(ni_nid);
1848 return lustre_lnet_config_healthv(value, all, nid,
1849 LNET_HEALTH_TYPE_LOCAL_NI,
1850 "ni healthv", seq_no, err_rc);
1853 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1854 int seq_no, struct cYAML **err_rc)
1858 nid = libcfs_str2nid(lpni_nid);
1861 return lustre_lnet_config_healthv(value, all, nid,
1862 LNET_HEALTH_TYPE_PEER_NI,
1863 "peer_ni healthv", seq_no, err_rc);
1867 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1868 struct lnet_ioctl_comm_count *counts)
1870 if (cYAML_create_number(yaml, "put",
1871 counts->ico_put_count)
1874 if (cYAML_create_number(yaml, "get",
1875 counts->ico_get_count)
1878 if (cYAML_create_number(yaml, "reply",
1879 counts->ico_reply_count)
1882 if (cYAML_create_number(yaml, "ack",
1883 counts->ico_ack_count)
1886 if (cYAML_create_number(yaml, "hello",
1887 counts->ico_hello_count)
1894 static struct lnet_ioctl_comm_count *
1895 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1898 return &msg_stats->im_send_stats;
1900 return &msg_stats->im_recv_stats;
1902 return &msg_stats->im_drop_stats;
1907 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1908 struct cYAML **show_rc, struct cYAML **err_rc,
1912 struct lnet_ioctl_config_ni *ni_data;
1913 struct lnet_ioctl_config_lnd_tunables *lnd;
1914 struct lnet_ioctl_element_stats *stats;
1915 struct lnet_ioctl_element_msg_stats msg_stats;
1916 struct lnet_ioctl_local_ni_hstats hstats;
1917 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1918 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1919 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1921 struct cYAML *root = NULL, *tunables = NULL,
1922 *net_node = NULL, *interfaces = NULL,
1923 *item = NULL, *first_seq = NULL,
1924 *tmp = NULL, *statistics = NULL,
1926 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1927 char str_buf[str_buf_len];
1929 char err_str[LNET_MAX_STR_LEN];
1930 bool exist = false, new_net = true;
1932 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1934 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1936 buf = calloc(1, buf_size);
1940 ni_data = (struct lnet_ioctl_config_ni *)buf;
1943 net = libcfs_str2net(nw);
1944 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1947 "\"cannot parse net '%s'\"", nw);
1948 rc = LUSTRE_CFG_RC_BAD_PARAM;
1953 root = cYAML_create_object(NULL, NULL);
1957 net_node = cYAML_create_seq(root, "net");
1958 if (net_node == NULL)
1964 memset(buf, 0, buf_size);
1966 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1968 * set the ioc_len to the proper value since INIT assumes
1971 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1972 ni_data->lic_idx = i;
1974 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1980 rc_net = LNET_NIDNET(ni_data->lic_nid);
1982 /* filter on provided data */
1983 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1987 /* if we're backing up don't store lo */
1988 if (backup && LNET_NETTYP(rc_net) == LOLND)
1991 /* default rc to -1 in case we hit the goto */
1995 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
1996 lnd = (struct lnet_ioctl_config_lnd_tunables *)
1997 (ni_data->lic_bulk + sizeof(*stats));
1999 if (rc_net != prev_net) {
2006 if (!cYAML_create_string(net_node, "net type",
2007 libcfs_net2str(rc_net)))
2010 tmp = cYAML_create_seq(net_node, "local NI(s)");
2016 /* create the tree to be printed. */
2017 item = cYAML_create_seq_item(tmp);
2021 if (first_seq == NULL)
2025 cYAML_create_string(item, "nid",
2026 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2030 cYAML_create_string(item,
2032 (ni_data->lic_status ==
2033 LNET_NI_STATUS_UP) ?
2034 "up" : "down") == NULL)
2037 /* don't add interfaces unless there is at least one
2039 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2040 interfaces = cYAML_create_object(item, "interfaces");
2041 if (interfaces == NULL)
2044 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2045 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2047 sizeof(str_buf), "%d", j);
2048 if (cYAML_create_string(interfaces,
2050 ni_data->lic_ni_intf[j]) ==
2062 goto continue_without_msg_stats;
2064 statistics = cYAML_create_object(item, "statistics");
2065 if (statistics == NULL)
2068 if (cYAML_create_number(statistics, "send_count",
2069 stats->iel_send_count)
2073 if (cYAML_create_number(statistics, "recv_count",
2074 stats->iel_recv_count)
2078 if (cYAML_create_number(statistics, "drop_count",
2079 stats->iel_drop_count)
2084 goto continue_without_msg_stats;
2086 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2087 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2088 msg_stats.im_idx = i;
2090 rc = l_ioctl(LNET_DEV_ID,
2091 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2095 goto continue_without_msg_stats;
2098 for (k = 0; k < 3; k++) {
2099 struct lnet_ioctl_comm_count *counts;
2100 struct cYAML *msg_statistics = NULL;
2102 msg_statistics = cYAML_create_object(item,
2103 (char *)gmsg_stat_names[k]);
2104 if (msg_statistics == NULL)
2107 counts = get_counts(&msg_stats, k);
2111 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2116 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2117 hstats.hlni_nid = ni_data->lic_nid;
2118 /* grab health stats */
2119 rc = l_ioctl(LNET_DEV_ID,
2120 IOC_LIBCFS_GET_LOCAL_HSTATS,
2124 goto continue_without_msg_stats;
2126 yhstats = cYAML_create_object(item, "health stats");
2129 if (cYAML_create_number(yhstats, "health value",
2130 hstats.hlni_health_value)
2133 if (cYAML_create_number(yhstats, "interrupts",
2134 hstats.hlni_local_interrupt)
2137 if (cYAML_create_number(yhstats, "dropped",
2138 hstats.hlni_local_dropped)
2141 if (cYAML_create_number(yhstats, "aborted",
2142 hstats.hlni_local_aborted)
2145 if (cYAML_create_number(yhstats, "no route",
2146 hstats.hlni_local_no_route)
2149 if (cYAML_create_number(yhstats, "timeouts",
2150 hstats.hlni_local_timeout)
2153 if (cYAML_create_number(yhstats, "error",
2154 hstats.hlni_local_error)
2158 continue_without_msg_stats:
2159 tunables = cYAML_create_object(item, "tunables");
2163 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2164 if (rc != LUSTRE_CFG_RC_NO_ERR)
2167 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2169 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2170 rc != LUSTRE_CFG_RC_NO_MATCH)
2173 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2174 tunables = cYAML_create_object(item,
2176 if (tunables == NULL)
2181 cYAML_create_number(item, "dev cpt",
2182 ni_data->lic_dev_cpt) == NULL)
2186 cYAML_create_number(item, "tcp bonding",
2187 ni_data->lic_tcp_bonding)
2191 /* out put the CPTs in the format: "[x,x,x,...]" */
2193 limit = str_buf + str_buf_len - 3;
2194 pos += scnprintf(pos, limit - pos, "\"[");
2195 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2196 j < ni_data->lic_ncpts &&
2198 pos += scnprintf(pos, limit - pos,
2199 "%d", ni_data->lic_cpts[j]);
2200 if ((j + 1) < ni_data->lic_ncpts)
2201 pos += scnprintf(pos, limit - pos, ",");
2203 snprintf(pos, 3, "]\"");
2205 if (ni_data->lic_ncpts >= 1 &&
2206 cYAML_create_string(item, "CPT",
2212 /* Print out the net information only if show_rc is not provided */
2213 if (show_rc == NULL)
2214 cYAML_print_tree(root);
2216 if (l_errno != ENOENT) {
2219 "\"cannot get networks: %s\"",
2224 rc = LUSTRE_CFG_RC_NO_ERR;
2226 snprintf(err_str, sizeof(err_str), "\"success\"");
2228 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2229 cYAML_free_tree(root);
2230 } else if (show_rc != NULL && *show_rc != NULL) {
2231 struct cYAML *show_node;
2232 /* find the net node, if one doesn't exist
2233 * then insert one. Otherwise add to the one there
2235 show_node = cYAML_get_object_item(*show_rc, "net");
2236 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2237 cYAML_insert_child(show_node, first_seq);
2240 } else if (show_node == NULL) {
2241 cYAML_insert_sibling((*show_rc)->cy_child,
2245 cYAML_free_tree(root);
2251 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2256 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2258 struct lnet_ioctl_config_data data;
2259 int rc = LUSTRE_CFG_RC_NO_ERR;
2260 char err_str[LNET_MAX_STR_LEN];
2262 snprintf(err_str, sizeof(err_str), "\"success\"");
2264 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2265 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2267 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2272 "\"cannot %s routing %s\"",
2273 (enable) ? "enable" : "disable", strerror(errno));
2278 cYAML_build_error(rc, seq_no,
2279 (enable) ? ADD_CMD : DEL_CMD,
2280 "routing", err_str, err_rc);
2285 int ioctl_set_value(__u32 val, int ioc, char *name,
2286 int seq_no, struct cYAML **err_rc)
2288 struct lnet_ioctl_set_value data;
2289 int rc = LUSTRE_CFG_RC_NO_ERR;
2290 char err_str[LNET_MAX_STR_LEN];
2292 snprintf(err_str, sizeof(err_str), "\"success\"");
2294 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2295 data.sv_value = val;
2297 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2302 "\"cannot configure %s to %d: %s\"", name,
2303 val, strerror(errno));
2306 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2311 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2313 int rc = LUSTRE_CFG_RC_NO_ERR;
2314 char err_str[LNET_MAX_STR_LEN];
2315 char val[LNET_MAX_STR_LEN];
2317 snprintf(err_str, sizeof(err_str), "\"success\"");
2319 snprintf(val, sizeof(val), "%d", intrv);
2321 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2322 1, strlen(val) + 1);
2324 snprintf(err_str, sizeof(err_str),
2325 "\"cannot configure recovery interval: %s\"",
2328 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2333 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2335 int rc = LUSTRE_CFG_RC_NO_ERR;
2336 char err_str[LNET_MAX_STR_LEN];
2337 char val[LNET_MAX_STR_LEN];
2339 snprintf(err_str, sizeof(err_str), "\"success\"");
2341 snprintf(val, sizeof(val), "%d", sen);
2343 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2344 1, strlen(val) + 1);
2346 snprintf(err_str, sizeof(err_str),
2347 "\"cannot configure router health sensitivity: %s\"",
2350 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2355 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2357 int rc = LUSTRE_CFG_RC_NO_ERR;
2358 char err_str[LNET_MAX_STR_LEN];
2359 char val[LNET_MAX_STR_LEN];
2361 snprintf(err_str, sizeof(err_str), "\"success\"");
2363 snprintf(val, sizeof(val), "%d", sen);
2365 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2366 1, strlen(val) + 1);
2368 snprintf(err_str, sizeof(err_str),
2369 "\"cannot configure health sensitivity: %s\"",
2372 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2377 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2379 int rc = LUSTRE_CFG_RC_NO_ERR;
2380 char err_str[LNET_MAX_STR_LEN];
2381 char val[LNET_MAX_STR_LEN];
2383 snprintf(err_str, sizeof(err_str), "\"success\"");
2385 snprintf(val, sizeof(val), "%d", timeout);
2387 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2388 1, strlen(val) + 1);
2390 snprintf(err_str, sizeof(err_str),
2391 "\"cannot configure transaction timeout: %s\"",
2394 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2399 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2401 int rc = LUSTRE_CFG_RC_NO_ERR;
2402 char err_str[LNET_MAX_STR_LEN];
2403 char val[LNET_MAX_STR_LEN];
2405 snprintf(err_str, sizeof(err_str), "\"success\"");
2407 snprintf(val, sizeof(val), "%d", count);
2409 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2410 1, strlen(val) + 1);
2412 snprintf(err_str, sizeof(err_str),
2413 "\"cannot configure retry count: %s\"",
2416 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2421 int lustre_lnet_config_response_tracking(int val, int seq_no,
2422 struct cYAML **err_rc)
2424 int rc = LUSTRE_CFG_RC_NO_ERR;
2425 char err_str[LNET_MAX_STR_LEN];
2426 char val_str[LNET_MAX_STR_LEN];
2428 if (val < 0 || val > 3) {
2429 rc = LUSTRE_CFG_RC_BAD_PARAM;
2430 snprintf(err_str, sizeof(err_str),
2431 "\"Valid values are: 0, 1, 2, or 3\"");
2433 snprintf(err_str, sizeof(err_str), "\"success\"");
2435 snprintf(val_str, sizeof(val_str), "%d", val);
2437 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2438 val_str, 1, strlen(val_str) + 1);
2440 snprintf(err_str, sizeof(err_str),
2441 "\"cannot configure response tracking: %s\"",
2445 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2451 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2453 int rc = LUSTRE_CFG_RC_NO_ERR;
2454 char err_str[LNET_MAX_STR_LEN];
2455 char val[LNET_MAX_STR_LEN];
2457 snprintf(err_str, sizeof(err_str), "\"success\"");
2459 snprintf(val, sizeof(val), "%d", max);
2461 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2462 1, strlen(val) + 1);
2464 snprintf(err_str, sizeof(err_str),
2465 "\"cannot configure max interfaces: %s\"",
2468 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2473 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2475 int rc = LUSTRE_CFG_RC_NO_ERR;
2476 char err_str[LNET_MAX_STR_LEN];
2477 char val[LNET_MAX_STR_LEN];
2479 snprintf(err_str, sizeof(err_str), "\"success\"");
2481 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2483 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2484 1, strlen(val) + 1);
2486 snprintf(err_str, sizeof(err_str),
2487 "\"cannot configure discovery: %s\"",
2490 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2496 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2497 struct cYAML **err_rc)
2499 int rc = LUSTRE_CFG_RC_NO_ERR;
2500 char err_str[LNET_MAX_STR_LEN];
2501 char val[LNET_MAX_STR_LEN];
2503 snprintf(err_str, sizeof(err_str), "\"success\"");
2505 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2507 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2508 1, strlen(val) + 1);
2510 snprintf(err_str, sizeof(err_str),
2511 "\"cannot configure drop asym route: %s\"",
2514 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2521 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2523 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2524 "numa_range", seq_no, err_rc);
2527 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2528 struct cYAML **err_rc)
2530 struct lnet_ioctl_config_data data;
2531 int rc = LUSTRE_CFG_RC_NO_ERR;
2532 char err_str[LNET_MAX_STR_LEN];
2534 snprintf(err_str, sizeof(err_str), "\"success\"");
2536 /* -1 indicates to ignore changes to this field */
2537 if (tiny < -1 || small < -1 || large < -1) {
2540 "\"tiny, small and large must be >= 0\"");
2541 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2545 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2546 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2547 data.cfg_config_u.cfg_buffers.buf_small = small;
2548 data.cfg_config_u.cfg_buffers.buf_large = large;
2550 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2555 "\"cannot configure buffers: %s\"", strerror(errno));
2560 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2565 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2566 struct cYAML **err_rc, bool backup)
2568 struct lnet_ioctl_config_data *data;
2569 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2570 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2573 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2574 int buf_count[LNET_NRBPOOLS] = {0};
2575 struct cYAML *root = NULL, *pools_node = NULL,
2576 *type_node = NULL, *item = NULL, *cpt = NULL,
2577 *first_seq = NULL, *buffers = NULL;
2579 char err_str[LNET_MAX_STR_LEN];
2580 char node_name[LNET_MAX_STR_LEN];
2583 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2585 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2589 data = (struct lnet_ioctl_config_data *)buf;
2591 root = cYAML_create_object(NULL, NULL);
2596 pools_node = cYAML_create_object(root, "routing");
2598 pools_node = cYAML_create_seq(root, "routing");
2599 if (pools_node == NULL)
2603 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2604 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2605 sizeof(struct lnet_ioctl_pool_cfg);
2606 data->cfg_count = i;
2608 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2616 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2619 goto calculate_buffers;
2621 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2622 item = cYAML_create_seq_item(pools_node);
2626 if (first_seq == NULL)
2629 cpt = cYAML_create_object(item, node_name);
2634 /* create the tree and print */
2635 for (j = 0; j < LNET_NRBPOOLS; j++) {
2637 type_node = cYAML_create_object(cpt, pools[j]);
2638 if (type_node == NULL)
2642 cYAML_create_number(type_node, "npages",
2643 pool_cfg->pl_pools[j].pl_npages)
2647 cYAML_create_number(type_node, "nbuffers",
2648 pool_cfg->pl_pools[j].
2649 pl_nbuffers) == NULL)
2652 cYAML_create_number(type_node, "credits",
2653 pool_cfg->pl_pools[j].
2654 pl_credits) == NULL)
2657 cYAML_create_number(type_node, "mincredits",
2658 pool_cfg->pl_pools[j].
2659 pl_mincredits) == NULL)
2661 /* keep track of the total count for each of the
2662 * tiny, small and large buffers */
2663 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2667 if (pool_cfg != NULL) {
2669 if (cYAML_create_number(pools_node, "enable",
2670 pool_cfg->pl_routing) ==
2674 goto add_buffer_section;
2677 item = cYAML_create_seq_item(pools_node);
2681 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2687 /* create a buffers entry in the show. This is necessary so that
2688 * if the YAML output is used to configure a node, the buffer
2689 * configuration takes hold */
2690 buffers = cYAML_create_object(root, "buffers");
2691 if (buffers == NULL)
2694 for (i = 0; i < LNET_NRBPOOLS; i++) {
2695 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2699 if (show_rc == NULL)
2700 cYAML_print_tree(root);
2702 if (l_errno != ENOENT) {
2705 "\"cannot get routing information: %s\"",
2710 rc = LUSTRE_CFG_RC_NO_ERR;
2712 snprintf(err_str, sizeof(err_str), "\"success\"");
2713 rc = LUSTRE_CFG_RC_NO_ERR;
2717 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2718 cYAML_free_tree(root);
2719 } else if (show_rc != NULL && *show_rc != NULL) {
2720 struct cYAML *routing_node;
2721 /* there should exist only one routing block and one
2722 * buffers block. If there already exists a previous one
2723 * then don't add another */
2724 routing_node = cYAML_get_object_item(*show_rc, "routing");
2725 if (routing_node == NULL) {
2726 cYAML_insert_sibling((*show_rc)->cy_child,
2730 cYAML_free_tree(root);
2736 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2741 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2742 struct cYAML **show_rc, struct cYAML **err_rc,
2746 * TODO: This function is changing in a future patch to accommodate
2747 * PEER_LIST and proper filtering on any nid of the peer
2749 struct lnet_ioctl_peer_cfg peer_info;
2750 struct lnet_peer_ni_credit_info *lpni_cri;
2751 struct lnet_ioctl_element_stats *lpni_stats;
2752 struct lnet_ioctl_element_msg_stats *msg_stats;
2753 struct lnet_ioctl_peer_ni_hstats *hstats;
2755 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2760 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2761 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2762 *msg_statistics = NULL, *statistics = NULL,
2764 char err_str[LNET_MAX_STR_LEN];
2765 struct lnet_process_id *list = NULL;
2770 snprintf(err_str, sizeof(err_str),
2771 "\"out of memory\"");
2773 /* create struct cYAML root object */
2774 root = cYAML_create_object(NULL, NULL);
2778 peer_root = cYAML_create_seq(root, "peer");
2779 if (peer_root == NULL)
2783 size = count * sizeof(struct lnet_process_id);
2784 list = malloc(size);
2790 list[0].nid = libcfs_str2nid(knid);
2794 memset(&peer_info, 0, sizeof(peer_info));
2795 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2796 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2797 peer_info.prcfg_size = size;
2798 peer_info.prcfg_bulk = list;
2801 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2803 count = peer_info.prcfg_count;
2807 if (l_errno != E2BIG) {
2810 "\"cannot get peer list: %s\"",
2816 size = peer_info.prcfg_size;
2817 list = malloc(size);
2826 data = malloc(size);
2832 for (i = 0; i < count; i++) {
2834 memset(&peer_info, 0, sizeof(peer_info));
2835 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2836 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2837 peer_info.prcfg_prim_nid = list[i].nid;
2838 peer_info.prcfg_size = size;
2839 peer_info.prcfg_bulk = data;
2842 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2847 if (l_errno != E2BIG) {
2850 "\"cannot get peer information: %s\"",
2856 size = peer_info.prcfg_size;
2857 data = malloc(size);
2865 peer = cYAML_create_seq_item(peer_root);
2869 if (first_seq == NULL)
2872 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2873 if (cYAML_create_string(peer, "primary nid",
2874 libcfs_nid2str(pnid))
2877 if (cYAML_create_string(peer, "Multi-Rail",
2878 peer_info.prcfg_mr ? "True" : "False")
2882 * print out the state of the peer only if details are
2887 cYAML_create_number(peer, "peer state",
2888 peer_info.prcfg_state)
2893 tmp = cYAML_create_seq(peer, "peer ni");
2898 for (j = 0; j < peer_info.prcfg_count; j++) {
2900 lpni_cri = (void*)nidp + sizeof(nidp);
2901 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2902 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2903 hstats = (void *)msg_stats + sizeof(*msg_stats);
2904 lpni_data = (void *)hstats + sizeof(*hstats);
2906 peer_ni = cYAML_create_seq_item(tmp);
2907 if (peer_ni == NULL)
2910 if (cYAML_create_string(peer_ni, "nid",
2911 libcfs_nid2str(*nidp))
2918 if (cYAML_create_string(peer_ni, "state",
2919 lpni_cri->cr_aliveness)
2926 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2927 lpni_cri->cr_ni_peer_tx_credits)
2931 if (cYAML_create_number(peer_ni, "available_tx_credits",
2932 lpni_cri->cr_peer_tx_credits)
2936 if (cYAML_create_number(peer_ni, "min_tx_credits",
2937 lpni_cri->cr_peer_min_tx_credits)
2941 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2942 lpni_cri->cr_peer_tx_qnob)
2946 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2947 lpni_cri->cr_peer_rtr_credits)
2951 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2952 lpni_cri->cr_peer_min_rtr_credits)
2956 if (cYAML_create_number(peer_ni, "refcount",
2957 lpni_cri->cr_refcount) == NULL)
2960 statistics = cYAML_create_object(peer_ni, "statistics");
2961 if (statistics == NULL)
2964 if (cYAML_create_number(statistics, "send_count",
2965 lpni_stats->iel_send_count)
2969 if (cYAML_create_number(statistics, "recv_count",
2970 lpni_stats->iel_recv_count)
2974 if (cYAML_create_number(statistics, "drop_count",
2975 lpni_stats->iel_drop_count)
2982 for (k = 0; k < 3; k++) {
2983 struct lnet_ioctl_comm_count *counts;
2985 msg_statistics = cYAML_create_object(peer_ni,
2986 (char *) gmsg_stat_names[k]);
2987 if (msg_statistics == NULL)
2990 counts = get_counts(msg_stats, k);
2994 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2999 yhstats = cYAML_create_object(peer_ni, "health stats");
3002 if (cYAML_create_number(yhstats, "health value",
3003 hstats->hlpni_health_value)
3006 if (cYAML_create_number(yhstats, "dropped",
3007 hstats->hlpni_remote_dropped)
3010 if (cYAML_create_number(yhstats, "timeout",
3011 hstats->hlpni_remote_timeout)
3014 if (cYAML_create_number(yhstats, "error",
3015 hstats->hlpni_remote_error)
3018 if (cYAML_create_number(yhstats, "network timeout",
3019 hstats->hlpni_network_timeout)
3025 /* print output iff show_rc is not provided */
3026 if (show_rc == NULL)
3027 cYAML_print_tree(root);
3029 snprintf(err_str, sizeof(err_str), "\"success\"");
3030 rc = LUSTRE_CFG_RC_NO_ERR;
3035 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3036 cYAML_free_tree(root);
3037 } else if (show_rc != NULL && *show_rc != NULL) {
3038 struct cYAML *show_node;
3039 /* find the peer node, if one doesn't exist then
3040 * insert one. Otherwise add to the one there
3042 show_node = cYAML_get_object_item(*show_rc,
3044 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3045 cYAML_insert_child(show_node, first_seq);
3048 } else if (show_node == NULL) {
3049 cYAML_insert_sibling((*show_rc)->cy_child,
3053 cYAML_free_tree(root);
3059 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3065 int lustre_lnet_list_peer(int seq_no,
3066 struct cYAML **show_rc, struct cYAML **err_rc)
3068 struct lnet_ioctl_peer_cfg peer_info;
3069 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3074 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3075 char err_str[LNET_MAX_STR_LEN];
3076 struct lnet_process_id *list = NULL;
3078 snprintf(err_str, sizeof(err_str),
3079 "\"out of memory\"");
3081 memset(&peer_info, 0, sizeof(peer_info));
3083 /* create struct cYAML root object */
3084 root = cYAML_create_object(NULL, NULL);
3088 list_root = cYAML_create_seq(root, "peer list");
3089 if (list_root == NULL)
3093 size = count * sizeof(struct lnet_process_id);
3094 list = malloc(size);
3100 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3101 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3102 peer_info.prcfg_size = size;
3103 peer_info.prcfg_bulk = list;
3106 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3107 count = peer_info.prcfg_count;
3111 if (l_errno != E2BIG) {
3114 "\"cannot get peer list: %s\"",
3120 size = peer_info.prcfg_size;
3121 list = malloc(size);
3128 /* count is now the actual number of ids in the list. */
3129 for (i = 0; i < count; i++) {
3130 if (cYAML_create_string(list_root, "nid",
3131 libcfs_nid2str(list[i].nid))
3136 /* print output iff show_rc is not provided */
3137 if (show_rc == NULL)
3138 cYAML_print_tree(root);
3140 snprintf(err_str, sizeof(err_str), "\"success\"");
3141 rc = LUSTRE_CFG_RC_NO_ERR;
3146 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3147 cYAML_free_tree(root);
3148 } else if (show_rc != NULL && *show_rc != NULL) {
3149 struct cYAML *show_node;
3150 /* find the peer node, if one doesn't exist then
3151 * insert one. Otherwise add to the one there
3153 show_node = cYAML_get_object_item(*show_rc,
3155 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3156 cYAML_insert_child(show_node, first_seq);
3159 } else if (show_node == NULL) {
3160 cYAML_insert_sibling((*show_rc)->cy_child,
3164 cYAML_free_tree(root);
3170 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3176 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3179 struct cYAML *show_node;
3181 show_node = cYAML_get_object_item(show_rc, "global");
3182 if (show_node != NULL)
3183 cYAML_insert_sibling(show_node->cy_child,
3186 cYAML_insert_sibling(show_rc->cy_child,
3191 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3192 char *name, __u64 value,
3193 struct cYAML **show_rc,
3194 struct cYAML **err_rc, int err)
3196 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3197 struct cYAML *root = NULL, *global = NULL;
3204 root = cYAML_create_object(NULL, NULL);
3208 global = cYAML_create_object(root, "global");
3212 if (cYAML_create_number(global, name,
3216 if (show_rc == NULL)
3217 cYAML_print_tree(root);
3219 snprintf(err_str, err_len, "\"success\"");
3221 rc = LUSTRE_CFG_RC_NO_ERR;
3224 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3225 cYAML_free_tree(root);
3226 } else if (show_rc != NULL && *show_rc != NULL) {
3227 add_to_global(*show_rc, global, root);
3232 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3237 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3238 struct cYAML **show_rc,
3239 struct cYAML **err_rc)
3241 struct lnet_ioctl_set_value data;
3244 char err_str[LNET_MAX_STR_LEN];
3246 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3248 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3250 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3255 "\"cannot get %s: %s\"",
3256 name, strerror(l_errno));
3259 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3260 data.sv_value, show_rc, err_rc, l_errno);
3263 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3264 struct cYAML **err_rc)
3266 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3267 char val[LNET_MAX_STR_LEN];
3268 int intrv = -1, l_errno = 0;
3269 char err_str[LNET_MAX_STR_LEN];
3271 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3273 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3277 snprintf(err_str, sizeof(err_str),
3278 "\"cannot get recovery interval: %d\"", rc);
3283 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3284 "recovery_interval", intrv, show_rc,
3288 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3289 struct cYAML **err_rc)
3291 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3292 char val[LNET_MAX_STR_LEN];
3293 int sen = -1, l_errno = 0;
3294 char err_str[LNET_MAX_STR_LEN];
3296 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3298 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3302 snprintf(err_str, sizeof(err_str),
3303 "\"cannot get health sensitivity: %d\"", rc);
3308 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3309 "health_sensitivity", sen, show_rc,
3313 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3314 struct cYAML **err_rc)
3316 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3317 char val[LNET_MAX_STR_LEN];
3318 int sen = -1, l_errno = 0;
3319 char err_str[LNET_MAX_STR_LEN];
3321 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3323 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3327 snprintf(err_str, sizeof(err_str),
3328 "\"cannot get router sensitivity percentage: %d\"", rc);
3333 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3334 "router_sensitivity", sen, show_rc,
3338 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3339 struct cYAML **err_rc)
3341 char val[LNET_MAX_STR_LEN];
3342 char err_str[LNET_MAX_STR_LEN];
3349 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3351 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3354 snprintf(err_str, sizeof(err_str),
3355 "\"cannot get LND timeout: %d\"", rc);
3356 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3357 "lnd_timeout", lnd_to, show_rc,
3361 fd = open(path.gl_pathv[0], O_RDONLY);
3364 snprintf(err_str, sizeof(err_str),
3365 "\"error opening %s\"", path.gl_pathv[0]);
3369 rc = read(fd, val, sizeof(val));
3376 snprintf(err_str, sizeof(err_str),
3377 "\"error reading %s\"", path.gl_pathv[0]);
3384 cfs_free_param_data(&path);
3386 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3387 "lnd_timeout", lnd_to, show_rc,
3391 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3392 struct cYAML **err_rc)
3394 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3395 char val[LNET_MAX_STR_LEN];
3396 int tto = -1, l_errno = 0;
3397 char err_str[LNET_MAX_STR_LEN];
3399 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3401 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3405 snprintf(err_str, sizeof(err_str),
3406 "\"cannot get transaction timeout: %d\"", rc);
3411 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3412 "transaction_timeout", tto, show_rc,
3416 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3417 struct cYAML **err_rc)
3419 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3420 char val[LNET_MAX_STR_LEN];
3421 int retry_count = -1, l_errno = 0;
3422 char err_str[LNET_MAX_STR_LEN];
3424 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3426 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3430 snprintf(err_str, sizeof(err_str),
3431 "\"cannot get retry count: %d\"", rc);
3433 retry_count = atoi(val);
3436 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3437 "retry_count", retry_count, show_rc,
3441 int lustre_lnet_calc_service_id(__u64 *service_id)
3443 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3444 char val[LNET_MAX_STR_LEN];
3445 int service_port = -1, l_errno = 0;
3447 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3451 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3452 strerror(l_errno), -l_errno);
3455 service_port = atoi(val);
3458 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3460 return LUSTRE_CFG_RC_NO_ERR;
3463 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3464 struct cYAML **show_rc, struct cYAML **err_rc)
3466 struct lnet_ioctl_recovery_list nid_list;
3467 struct cYAML *root = NULL, *nids = NULL;
3469 char err_str[LNET_MAX_STR_LEN];
3471 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3473 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3474 nid_list.rlst_type = type;
3476 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3482 if (nid_list.rlst_num_nids == 0)
3485 root = cYAML_create_object(NULL, NULL);
3489 nids = cYAML_create_object(root, name);
3495 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3496 char nidenum[LNET_MAX_STR_LEN];
3497 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3498 if (!cYAML_create_string(nids, nidenum,
3499 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3503 snprintf(err_str, sizeof(err_str), "success\n");
3508 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3509 cYAML_free_tree(root);
3510 } else if (show_rc != NULL && *show_rc != NULL) {
3511 struct cYAML *show_node;
3512 /* find the net node, if one doesn't exist
3513 * then insert one. Otherwise add to the one there
3515 show_node = cYAML_get_object_item(*show_rc, name);
3516 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3517 cYAML_insert_child(show_node, nids);
3520 } else if (show_node == NULL) {
3521 cYAML_insert_sibling((*show_rc)->cy_child,
3525 cYAML_free_tree(root);
3531 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3536 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3537 struct cYAML **err_rc)
3539 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3540 seq_no, show_rc, err_rc);
3543 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3544 struct cYAML **err_rc)
3546 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3547 seq_no, show_rc, err_rc);
3550 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
3551 struct cYAML **err_rc)
3553 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3554 char val[LNET_MAX_STR_LEN];
3555 int rsp_tracking = -1, l_errno = 0;
3556 char err_str[LNET_MAX_STR_LEN];
3558 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3560 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
3564 snprintf(err_str, sizeof(err_str),
3565 "\"cannot get lnet_response_tracking value: %d\"", rc);
3567 rsp_tracking = atoi(val);
3570 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3571 "response_tracking", rsp_tracking,
3572 show_rc, err_rc, l_errno);
3575 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3576 struct cYAML **err_rc)
3578 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3579 char val[LNET_MAX_STR_LEN];
3580 int max_intf = -1, l_errno = 0;
3581 char err_str[LNET_MAX_STR_LEN];
3583 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3585 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3589 snprintf(err_str, sizeof(err_str),
3590 "\"cannot get max interfaces: %d\"", rc);
3592 max_intf = atoi(val);
3595 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3596 "max_intf", max_intf, show_rc,
3600 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3601 struct cYAML **err_rc)
3603 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3604 char val[LNET_MAX_STR_LEN];
3605 int discovery = -1, l_errno = 0;
3606 char err_str[LNET_MAX_STR_LEN];
3608 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3610 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3614 snprintf(err_str, sizeof(err_str),
3615 "\"cannot get discovery setting: %d\"", rc);
3618 * The kernel stores a discovery disabled value. User space
3619 * shows whether discovery is enabled. So the value must be
3622 discovery = !atoi(val);
3625 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3626 "discovery", discovery, show_rc,
3630 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3631 struct cYAML **err_rc)
3633 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3634 char val[LNET_MAX_STR_LEN];
3635 int drop_asym_route = -1, l_errno = 0;
3636 char err_str[LNET_MAX_STR_LEN];
3638 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3640 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3644 snprintf(err_str, sizeof(err_str),
3645 "\"cannot get drop asym route setting: %d\"", rc);
3647 drop_asym_route = atoi(val);
3650 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3651 "drop_asym_route", drop_asym_route,
3652 show_rc, err_rc, l_errno);
3655 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3656 struct cYAML **err_rc)
3658 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3659 "numa_range", show_rc, err_rc);
3662 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3663 struct cYAML **err_rc)
3665 struct lnet_ioctl_lnet_stats data;
3666 struct lnet_counters *cntrs;
3669 char err_str[LNET_MAX_STR_LEN];
3670 struct cYAML *root = NULL, *stats = NULL;
3672 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3674 LIBCFS_IOC_INIT_V2(data, st_hdr);
3676 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3681 "\"cannot get lnet statistics: %s\"",
3687 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3689 cntrs = &data.st_cntrs;
3691 root = cYAML_create_object(NULL, NULL);
3695 stats = cYAML_create_object(root, "statistics");
3699 if (!cYAML_create_number(stats, "msgs_alloc",
3700 cntrs->lct_common.lcc_msgs_alloc))
3703 if (!cYAML_create_number(stats, "msgs_max",
3704 cntrs->lct_common.lcc_msgs_max))
3707 if (!cYAML_create_number(stats, "rst_alloc",
3708 cntrs->lct_health.lch_rst_alloc))
3711 if (!cYAML_create_number(stats, "errors",
3712 cntrs->lct_common.lcc_errors))
3715 if (!cYAML_create_number(stats, "send_count",
3716 cntrs->lct_common.lcc_send_count))
3719 if (!cYAML_create_number(stats, "resend_count",
3720 cntrs->lct_health.lch_resend_count))
3723 if (!cYAML_create_number(stats, "response_timeout_count",
3724 cntrs->lct_health.lch_response_timeout_count))
3727 if (!cYAML_create_number(stats, "local_interrupt_count",
3728 cntrs->lct_health.lch_local_interrupt_count))
3731 if (!cYAML_create_number(stats, "local_dropped_count",
3732 cntrs->lct_health.lch_local_dropped_count))
3735 if (!cYAML_create_number(stats, "local_aborted_count",
3736 cntrs->lct_health.lch_local_aborted_count))
3739 if (!cYAML_create_number(stats, "local_no_route_count",
3740 cntrs->lct_health.lch_local_no_route_count))
3743 if (!cYAML_create_number(stats, "local_timeout_count",
3744 cntrs->lct_health.lch_local_timeout_count))
3747 if (!cYAML_create_number(stats, "local_error_count",
3748 cntrs->lct_health.lch_local_error_count))
3751 if (!cYAML_create_number(stats, "remote_dropped_count",
3752 cntrs->lct_health.lch_remote_dropped_count))
3755 if (!cYAML_create_number(stats, "remote_error_count",
3756 cntrs->lct_health.lch_remote_error_count))
3759 if (!cYAML_create_number(stats, "remote_timeout_count",
3760 cntrs->lct_health.lch_remote_timeout_count))
3763 if (!cYAML_create_number(stats, "network_timeout_count",
3764 cntrs->lct_health.lch_network_timeout_count))
3767 if (!cYAML_create_number(stats, "recv_count",
3768 cntrs->lct_common.lcc_recv_count))
3771 if (!cYAML_create_number(stats, "route_count",
3772 cntrs->lct_common.lcc_route_count))
3775 if (!cYAML_create_number(stats, "drop_count",
3776 cntrs->lct_common.lcc_drop_count))
3779 if (!cYAML_create_number(stats, "send_length",
3780 cntrs->lct_common.lcc_send_length))
3783 if (!cYAML_create_number(stats, "recv_length",
3784 cntrs->lct_common.lcc_recv_length))
3787 if (!cYAML_create_number(stats, "route_length",
3788 cntrs->lct_common.lcc_route_length))
3791 if (!cYAML_create_number(stats, "drop_length",
3792 cntrs->lct_common.lcc_drop_length))
3796 cYAML_print_tree(root);
3798 snprintf(err_str, sizeof(err_str), "\"success\"");
3799 rc = LUSTRE_CFG_RC_NO_ERR;
3801 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3802 cYAML_free_tree(root);
3803 } else if (show_rc != NULL && *show_rc != NULL) {
3804 cYAML_insert_sibling((*show_rc)->cy_child,
3811 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3816 typedef int (*cmd_handler_t)(struct cYAML *tree,
3817 struct cYAML **show_rc,
3818 struct cYAML **err_rc);
3820 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3821 struct cYAML **err_rc)
3823 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3825 net = cYAML_get_object_item(tree, "net");
3826 gw = cYAML_get_object_item(tree, "gateway");
3827 hop = cYAML_get_object_item(tree, "hop");
3828 prio = cYAML_get_object_item(tree, "priority");
3829 sen = cYAML_get_object_item(tree, "health_sensitivity");
3830 seq_no = cYAML_get_object_item(tree, "seq_no");
3832 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3833 (gw) ? gw->cy_valuestring : NULL,
3834 (hop) ? hop->cy_valueint : -1,
3835 (prio) ? prio->cy_valueint : -1,
3836 (sen) ? sen->cy_valueint : -1,
3837 (seq_no) ? seq_no->cy_valueint : -1,
3843 * 0: <intf_name>['['<expr>']']
3844 * 1: <intf_name>['['<expr>']']
3846 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3847 struct lnet_dlc_network_descr *nw_descr)
3849 struct cYAML *child = NULL;
3850 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3851 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3853 if (intf_tree == NULL || nw_descr == NULL)
3854 return LUSTRE_CFG_RC_BAD_PARAM;
3856 /* now grab all the interfaces and their cpts */
3857 child = intf_tree->cy_child;
3858 while (child != NULL) {
3859 if (child->cy_valuestring == NULL) {
3860 child = child->cy_next;
3864 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3867 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3868 child->cy_valuestring,
3869 strlen(child->cy_valuestring));
3870 if (rc != LUSTRE_CFG_RC_NO_ERR)
3874 child = child->cy_next;
3878 return LUSTRE_CFG_RC_MISSING_PARAM;
3883 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3885 list_del(&intf_descr->intf_on_network);
3886 free_intf_descr(intf_descr);
3893 yaml_extract_cmn_tunables(struct cYAML *tree,
3894 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3895 struct cfs_expr_list **global_cpts)
3897 struct cYAML *tun, *item, *smp;
3900 tun = cYAML_get_object_item(tree, "tunables");
3902 item = cYAML_get_object_item(tun, "peer_timeout");
3904 tunables->lct_peer_timeout = item->cy_valueint;
3905 item = cYAML_get_object_item(tun, "peer_credits");
3907 tunables->lct_peer_tx_credits = item->cy_valueint;
3908 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3910 tunables->lct_peer_rtr_credits = item->cy_valueint;
3911 item = cYAML_get_object_item(tun, "credits");
3913 tunables->lct_max_tx_credits = item->cy_valueint;
3914 smp = cYAML_get_object_item(tun, "CPT");
3916 rc = cfs_expr_list_parse(smp->cy_valuestring,
3917 strlen(smp->cy_valuestring),
3918 0, UINT_MAX, global_cpts);
3920 *global_cpts = NULL;
3930 yaml_extract_tunables(struct cYAML *tree,
3931 struct lnet_ioctl_config_lnd_tunables *tunables,
3932 struct cfs_expr_list **global_cpts,
3937 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3943 lustre_yaml_extract_lnd_tunables(tree, net_type,
3951 * - net type: <net>[<NUM>]
3953 * - nid: <ip>@<net>[<NUM>]
3956 * 0: <intf_name>['['<expr>']']
3957 * 1: <intf_name>['['<expr>']']
3959 * peer_timeout: <NUM>
3960 * peer_credits: <NUM>
3961 * peer_buffer_credits: <NUM>
3964 * peercredits_hiw: <NUM>
3965 * map_on_demand: <NUM>
3966 * concurrent_sends: <NUM>
3967 * fmr_pool_size: <NUM>
3968 * fmr_flush_trigger: <NUM>
3971 * At least one interface is required. If no interfaces are provided the
3972 * network interface can not be configured.
3974 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3975 struct cYAML **err_rc)
3977 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3979 int num_entries = 0, rc;
3980 struct lnet_dlc_network_descr nw_descr;
3981 struct cfs_expr_list *global_cpts = NULL;
3982 struct lnet_ioctl_config_lnd_tunables tunables;
3985 memset(&tunables, 0, sizeof(tunables));
3987 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3988 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3990 ip2net = cYAML_get_object_item(tree, "ip2net");
3991 net = cYAML_get_object_item(tree, "net type");
3993 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3995 nw_descr.nw_id = LOLND;
3998 * if neither net nor ip2nets are present, then we can not
3999 * configure the network.
4001 if (!net && !ip2net)
4002 return LUSTRE_CFG_RC_MISSING_PARAM;
4004 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4005 if (local_nis == NULL)
4006 return LUSTRE_CFG_RC_MISSING_PARAM;
4008 if (!cYAML_is_sequence(local_nis))
4009 return LUSTRE_CFG_RC_BAD_PARAM;
4011 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4012 intf = cYAML_get_object_item(item, "interfaces");
4015 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4016 if (num_entries <= 0) {
4017 cYAML_build_error(num_entries, -1, "ni", "add",
4018 "bad interface list",
4020 return LUSTRE_CFG_RC_BAD_PARAM;
4024 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4025 LNET_NETTYP(nw_descr.nw_id));
4026 seq_no = cYAML_get_object_item(tree, "seq_no");
4028 rc = lustre_lnet_config_ni(&nw_descr,
4030 (ip2net) ? ip2net->cy_valuestring : NULL,
4031 (found) ? &tunables: NULL,
4032 (seq_no) ? seq_no->cy_valueint : -1,
4035 if (global_cpts != NULL)
4036 cfs_expr_list_free(global_cpts);
4043 * - net-spec: <tcp|o2ib|gni>[NUM]
4045 * 0: <intf name>['['<expr>']']
4046 * 1: <intf name>['['<expr>']']
4048 * 0: <expr.expr.expr.expr>
4049 * 1: <expr.expr.expr.expr>
4051 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4052 struct cYAML **show_rc,
4053 struct cYAML **err_rc)
4055 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4057 struct lustre_lnet_ip2nets ip2nets;
4058 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4060 int rc = LUSTRE_CFG_RC_NO_ERR;
4061 struct cfs_expr_list *global_cpts = NULL;
4062 struct cfs_expr_list *el, *el_tmp;
4063 struct lnet_ioctl_config_lnd_tunables tunables;
4064 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4067 memset(&tunables, 0, sizeof(tunables));
4069 /* initialize all lists */
4070 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4071 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4072 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4074 net = cYAML_get_object_item(tree, "net-spec");
4076 return LUSTRE_CFG_RC_BAD_PARAM;
4078 if (net != NULL && net->cy_valuestring == NULL)
4079 return LUSTRE_CFG_RC_BAD_PARAM;
4081 /* assign the network id */
4082 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4083 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4084 return LUSTRE_CFG_RC_BAD_PARAM;
4086 seq_no = cYAML_get_object_item(tree, "seq_no");
4088 intf = cYAML_get_object_item(tree, "interfaces");
4090 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4092 return LUSTRE_CFG_RC_BAD_PARAM;
4095 ip_range = cYAML_get_object_item(tree, "ip-range");
4096 if (ip_range != NULL) {
4097 item = ip_range->cy_child;
4098 while (item != NULL) {
4099 if (item->cy_valuestring == NULL) {
4100 item = item->cy_next;
4104 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4105 item->cy_valuestring);
4107 if (rc != LUSTRE_CFG_RC_NO_ERR)
4110 item = item->cy_next;
4114 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4115 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4117 rc = lustre_lnet_config_ip2nets(&ip2nets,
4118 (found) ? &tunables : NULL,
4120 (seq_no) ? seq_no->cy_valueint : -1,
4124 * don't stop because there was no match. Continue processing the
4125 * rest of the rules. If non-match then nothing is configured
4127 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4128 rc = LUSTRE_CFG_RC_NO_ERR;
4130 list_for_each_entry_safe(intf_descr, intf_tmp,
4131 &ip2nets.ip2nets_net.nw_intflist,
4133 list_del(&intf_descr->intf_on_network);
4134 free_intf_descr(intf_descr);
4137 list_for_each_entry_safe(ip_range_descr, tmp,
4138 &ip2nets.ip2nets_ip_ranges,
4140 list_del(&ip_range_descr->ipr_entry);
4141 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4143 list_del(&el->el_link);
4144 cfs_expr_list_free(el);
4146 free(ip_range_descr);
4152 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4153 struct cYAML **err_rc)
4155 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4157 int num_entries, rc;
4158 struct lnet_dlc_network_descr nw_descr;
4160 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4161 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4163 net = cYAML_get_object_item(tree, "net type");
4165 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4167 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4168 if (local_nis == NULL)
4169 return LUSTRE_CFG_RC_MISSING_PARAM;
4171 if (!cYAML_is_sequence(local_nis))
4172 return LUSTRE_CFG_RC_BAD_PARAM;
4174 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4175 intf = cYAML_get_object_item(item, "interfaces");
4178 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4179 if (num_entries <= 0) {
4180 cYAML_build_error(num_entries, -1, "ni", "add",
4181 "bad interface list",
4183 return LUSTRE_CFG_RC_BAD_PARAM;
4187 seq_no = cYAML_get_object_item(tree, "seq_no");
4189 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4190 (seq_no) ? seq_no->cy_valueint : -1,
4196 /* Create a nidstring parseable by the nidstrings library from the nid
4197 * information encoded in the CYAML structure.
4198 * NOTE: Caller must free memory allocated to nidstr
4200 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4201 char *prim_nid, int cmd)
4203 int num_strs = 0, rc;
4204 size_t buf_size, buf_pos, nidstr_len = 0;
4206 struct cYAML *child = NULL, *entry = NULL;
4208 if (cYAML_is_sequence(nids_entry)) {
4209 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4210 entry = cYAML_get_object_item(child, "nid");
4211 /* don't count an empty entry */
4212 if (!entry || !entry->cy_valuestring)
4216 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4217 if (cmd == LNETCTL_DEL_CMD) {
4219 * primary nid is present in the list of
4220 * nids so that means we want to delete
4221 * the entire peer, so no need to go
4222 * further. Just delete the entire peer.
4224 return LUSTRE_CFG_RC_NO_ERR;
4231 * + 1 for the space separating each string, and
4232 * accounts for the terminating null char
4234 nidstr_len += strlen(entry->cy_valuestring) + 1;
4239 if (num_strs == 0 && !prim_nid)
4240 return LUSTRE_CFG_RC_MISSING_PARAM;
4241 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4242 return LUSTRE_CFG_RC_NO_ERR;
4244 buffer = malloc(nidstr_len);
4246 return LUSTRE_CFG_RC_OUT_OF_MEM;
4248 /* now grab all the nids */
4251 buf_size = nidstr_len;
4253 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4254 entry = cYAML_get_object_item(child, "nid");
4255 if (!entry || !entry->cy_valuestring)
4259 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4263 rc = snprintf(buffer + buf_pos, buf_size, " ");
4264 buf_pos += (rc < buf_size) ? rc : buf_size;
4265 buf_size = nidstr_len - buf_pos;
4268 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4269 entry->cy_valuestring);
4270 buf_pos += (rc < buf_size) ? rc : buf_size;
4271 buf_size = nidstr_len - buf_pos;
4276 return LUSTRE_CFG_RC_NO_ERR;
4279 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4280 struct cYAML **err_rc, int cmd)
4282 int rc, num_nids = 0, seqn;
4283 bool mr_value = false;
4284 char *nidstr = NULL, *prim_nidstr;
4285 char err_str[LNET_MAX_STR_LEN];
4286 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4287 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4288 lnet_nid_t pnid = LNET_NID_ANY;
4290 seq_no = cYAML_get_object_item(tree, "seq_no");
4291 seqn = seq_no ? seq_no->cy_valueint : -1;
4293 prim_nid = cYAML_get_object_item(tree, "primary nid");
4294 peer_nis = cYAML_get_object_item(tree, "peer ni");
4296 rc = LUSTRE_CFG_RC_BAD_PARAM;
4297 snprintf(err_str, LNET_MAX_STR_LEN,
4298 "\"primary nid\" must be specified");
4302 prim_nidstr = prim_nid->cy_valuestring;
4304 /* if the provided primary NID is bad, no need to go any further */
4305 pnid = libcfs_str2nid(prim_nidstr);
4306 if (pnid == LNET_NID_ANY) {
4307 rc = LUSTRE_CFG_RC_BAD_PARAM;
4308 snprintf(err_str, LNET_MAX_STR_LEN,
4309 "badly formatted primary NID: %s", prim_nidstr);
4313 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4314 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4315 snprintf(err_str, LNET_MAX_STR_LEN,
4316 "No nids defined in YAML block");
4318 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4319 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4321 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4322 snprintf(err_str, LNET_MAX_STR_LEN,
4323 "Unrecognized error %d", rc);
4329 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4330 LNET_MAX_NIDS_PER_PEER,
4338 if (cmd == LNETCTL_ADD_CMD) {
4339 mr = cYAML_get_object_item(tree, "Multi-Rail");
4341 if (mr && mr->cy_valuestring) {
4342 if (strcmp(mr->cy_valuestring, "False") == 0)
4344 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4345 rc = LUSTRE_CFG_RC_BAD_PARAM;
4346 snprintf(err_str, LNET_MAX_STR_LEN,
4347 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4348 mr->cy_valuestring);
4354 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4355 num_nids, mr_value, seqn,
4362 if (rc != LUSTRE_CFG_RC_NO_ERR)
4363 cYAML_build_error(rc, seqn, "peer",
4364 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4370 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4371 struct cYAML **err_rc)
4373 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4376 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4377 struct cYAML **err_rc)
4379 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4382 static int handle_yaml_config_buffers(struct cYAML *tree,
4383 struct cYAML **show_rc,
4384 struct cYAML **err_rc)
4387 struct cYAML *tiny, *small, *large, *seq_no;
4389 tiny = cYAML_get_object_item(tree, "tiny");
4390 small = cYAML_get_object_item(tree, "small");
4391 large = cYAML_get_object_item(tree, "large");
4392 seq_no = cYAML_get_object_item(tree, "seq_no");
4394 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4395 (small) ? small->cy_valueint : -1,
4396 (large) ? large->cy_valueint : -1,
4397 (seq_no) ? seq_no->cy_valueint : -1,
4403 static int handle_yaml_config_routing(struct cYAML *tree,
4404 struct cYAML **show_rc,
4405 struct cYAML **err_rc)
4407 int rc = LUSTRE_CFG_RC_NO_ERR;
4408 struct cYAML *seq_no, *enable;
4410 seq_no = cYAML_get_object_item(tree, "seq_no");
4411 enable = cYAML_get_object_item(tree, "enable");
4414 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4416 seq_no->cy_valueint : -1,
4423 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4424 struct cYAML **err_rc)
4428 struct cYAML *seq_no;
4430 net = cYAML_get_object_item(tree, "net");
4431 gw = cYAML_get_object_item(tree, "gateway");
4432 seq_no = cYAML_get_object_item(tree, "seq_no");
4434 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4435 (gw) ? gw->cy_valuestring : NULL,
4436 (seq_no) ? seq_no->cy_valueint : -1,
4440 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4441 struct cYAML **err_rc)
4443 struct cYAML *seq_no;
4445 seq_no = cYAML_get_object_item(tree, "seq_no");
4447 return lustre_lnet_enable_routing(0, (seq_no) ?
4448 seq_no->cy_valueint : -1,
4452 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4453 struct cYAML **err_rc)
4459 struct cYAML *detail;
4460 struct cYAML *seq_no;
4462 net = cYAML_get_object_item(tree, "net");
4463 gw = cYAML_get_object_item(tree, "gateway");
4464 hop = cYAML_get_object_item(tree, "hop");
4465 prio = cYAML_get_object_item(tree, "priority");
4466 detail = cYAML_get_object_item(tree, "detail");
4467 seq_no = cYAML_get_object_item(tree, "seq_no");
4469 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4470 (gw) ? gw->cy_valuestring : NULL,
4471 (hop) ? hop->cy_valueint : -1,
4472 (prio) ? prio->cy_valueint : -1,
4473 (detail) ? detail->cy_valueint : 0,
4474 (seq_no) ? seq_no->cy_valueint : -1,
4475 show_rc, err_rc, false);
4478 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4479 struct cYAML **err_rc)
4481 struct cYAML *net, *detail, *seq_no;
4483 net = cYAML_get_object_item(tree, "net");
4484 detail = cYAML_get_object_item(tree, "detail");
4485 seq_no = cYAML_get_object_item(tree, "seq_no");
4487 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4488 (detail) ? detail->cy_valueint : 0,
4489 (seq_no) ? seq_no->cy_valueint : -1,
4490 show_rc, err_rc, false);
4493 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4494 struct cYAML **err_rc)
4496 struct cYAML *seq_no;
4498 seq_no = cYAML_get_object_item(tree, "seq_no");
4500 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4501 show_rc, err_rc, false);
4504 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4505 struct cYAML **err_rc)
4507 struct cYAML *seq_no, *nid, *detail;
4509 seq_no = cYAML_get_object_item(tree, "seq_no");
4510 detail = cYAML_get_object_item(tree, "detail");
4511 nid = cYAML_get_object_item(tree, "nid");
4513 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4514 (detail) ? detail->cy_valueint : 0,
4515 (seq_no) ? seq_no->cy_valueint : -1,
4516 show_rc, err_rc, false);
4519 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4520 struct cYAML **err_rc)
4522 struct cYAML *seq_no;
4524 seq_no = cYAML_get_object_item(tree, "seq_no");
4526 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4530 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4531 struct cYAML **err_rc)
4533 struct cYAML *seq_no, *range;
4535 seq_no = cYAML_get_object_item(tree, "seq_no");
4536 range = cYAML_get_object_item(tree, "range");
4538 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4539 seq_no ? seq_no->cy_valueint : -1,
4543 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4544 struct cYAML **err_rc)
4546 struct cYAML *seq_no;
4548 seq_no = cYAML_get_object_item(tree, "seq_no");
4550 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4554 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4555 struct cYAML **err_rc)
4557 struct cYAML *seq_no;
4559 seq_no = cYAML_get_object_item(tree, "seq_no");
4561 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4565 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
4566 struct cYAML **err_rc)
4568 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
4569 union lnet_udsp_action action;
4571 seq_no = cYAML_get_object_item(tree, "seq_no");
4572 src = cYAML_get_object_item(tree, "src");
4573 rte = cYAML_get_object_item(tree, "rte");
4574 dst = cYAML_get_object_item(tree, "dst");
4575 prio = cYAML_get_object_item(tree, "priority");
4576 idx = cYAML_get_object_item(tree, "idx");
4578 action.udsp_priority = prio ? prio->cy_valueint : -1;
4580 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
4581 dst ? dst->cy_valuestring : NULL,
4582 rte ? rte->cy_valuestring : NULL,
4583 prio ? "priority" : "",
4585 idx ? idx->cy_valueint : -1,
4586 seq_no ? seq_no->cy_valueint : -1,
4590 static int handle_yaml_config_global_settings(struct cYAML *tree,
4591 struct cYAML **show_rc,
4592 struct cYAML **err_rc)
4594 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4595 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking;
4598 seq_no = cYAML_get_object_item(tree, "seq_no");
4599 max_intf = cYAML_get_object_item(tree, "max_intf");
4601 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4602 seq_no ? seq_no->cy_valueint
4606 numa = cYAML_get_object_item(tree, "numa_range");
4608 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4609 seq_no ? seq_no->cy_valueint
4613 discovery = cYAML_get_object_item(tree, "discovery");
4615 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4616 seq_no ? seq_no->cy_valueint
4620 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4621 if (drop_asym_route)
4622 rc = lustre_lnet_config_drop_asym_route(
4623 drop_asym_route->cy_valueint,
4624 seq_no ? seq_no->cy_valueint : -1,
4627 retry = cYAML_get_object_item(tree, "retry_count");
4629 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4630 seq_no ? seq_no->cy_valueint
4634 tto = cYAML_get_object_item(tree, "transaction_timeout");
4636 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4637 seq_no ? seq_no->cy_valueint
4641 sen = cYAML_get_object_item(tree, "health_sensitivity");
4643 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4644 seq_no ? seq_no->cy_valueint
4648 recov = cYAML_get_object_item(tree, "recovery_interval");
4650 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4651 seq_no ? seq_no->cy_valueint
4655 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4657 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4658 seq_no ? seq_no->cy_valueint
4662 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4664 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
4665 seq_no ? seq_no->cy_valueint
4672 static int handle_yaml_del_global_settings(struct cYAML *tree,
4673 struct cYAML **show_rc,
4674 struct cYAML **err_rc)
4676 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4679 seq_no = cYAML_get_object_item(tree, "seq_no");
4680 max_intf = cYAML_get_object_item(tree, "max_intf");
4682 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4683 seq_no ? seq_no->cy_valueint
4687 numa = cYAML_get_object_item(tree, "numa_range");
4689 rc = lustre_lnet_config_numa_range(0,
4690 seq_no ? seq_no->cy_valueint
4694 /* peer discovery is enabled by default */
4695 discovery = cYAML_get_object_item(tree, "discovery");
4697 rc = lustre_lnet_config_discovery(1,
4698 seq_no ? seq_no->cy_valueint
4702 /* asymmetrical route messages are accepted by default */
4703 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4704 if (drop_asym_route)
4705 rc = lustre_lnet_config_drop_asym_route(
4706 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4711 static int handle_yaml_show_global_settings(struct cYAML *tree,
4712 struct cYAML **show_rc,
4713 struct cYAML **err_rc)
4715 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4716 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking;
4719 seq_no = cYAML_get_object_item(tree, "seq_no");
4720 max_intf = cYAML_get_object_item(tree, "max_intf");
4722 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4726 numa = cYAML_get_object_item(tree, "numa_range");
4728 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4732 discovery = cYAML_get_object_item(tree, "discovery");
4734 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4738 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4739 if (drop_asym_route)
4740 rc = lustre_lnet_show_drop_asym_route(
4741 seq_no ? seq_no->cy_valueint : -1,
4744 retry = cYAML_get_object_item(tree, "retry_count");
4746 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4750 tto = cYAML_get_object_item(tree, "transaction_timeout");
4752 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4756 sen = cYAML_get_object_item(tree, "health_sensitivity");
4758 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4762 recov = cYAML_get_object_item(tree, "recovery_interval");
4764 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4768 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4770 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4774 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
4776 rc = lustre_lnet_show_response_tracking(seq_no ?
4777 seq_no->cy_valueint :
4784 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4785 struct cYAML **err_rc)
4787 struct cYAML *seq_no, *nid, *timeout;
4789 seq_no = cYAML_get_object_item(tree, "seq_no");
4790 nid = cYAML_get_object_item(tree, "primary nid");
4791 timeout = cYAML_get_object_item(tree, "timeout");
4793 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4794 (timeout) ? timeout->cy_valueint : 1000,
4795 (seq_no) ? seq_no->cy_valueint : -1,
4799 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4800 struct cYAML **err_rc)
4802 struct cYAML *seq_no, *nid, *force;
4804 seq_no = cYAML_get_object_item(tree, "seq_no");
4805 nid = cYAML_get_object_item(tree, "primary nid");
4806 force = cYAML_get_object_item(tree, "force");
4808 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4809 (force) ? force->cy_valueint : 0,
4810 (seq_no) ? seq_no->cy_valueint : -1,
4814 static int handle_yaml_no_op()
4816 return LUSTRE_CFG_RC_NO_ERR;
4819 struct lookup_cmd_hdlr_tbl {
4824 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4825 { .name = "route", .cb = handle_yaml_config_route },
4826 { .name = "net", .cb = handle_yaml_config_ni },
4827 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4828 { .name = "peer", .cb = handle_yaml_config_peer },
4829 { .name = "routing", .cb = handle_yaml_config_routing },
4830 { .name = "buffers", .cb = handle_yaml_config_buffers },
4831 { .name = "statistics", .cb = handle_yaml_no_op },
4832 { .name = "global", .cb = handle_yaml_config_global_settings},
4833 { .name = "numa", .cb = handle_yaml_config_numa },
4834 { .name = "ping", .cb = handle_yaml_no_op },
4835 { .name = "discover", .cb = handle_yaml_no_op },
4836 { .name = "udsp", .cb = handle_yaml_config_udsp },
4839 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4840 { .name = "route", .cb = handle_yaml_del_route },
4841 { .name = "net", .cb = handle_yaml_del_ni },
4842 { .name = "ip2nets", .cb = handle_yaml_no_op },
4843 { .name = "peer", .cb = handle_yaml_del_peer },
4844 { .name = "routing", .cb = handle_yaml_del_routing },
4845 { .name = "buffers", .cb = handle_yaml_no_op },
4846 { .name = "statistics", .cb = handle_yaml_no_op },
4847 { .name = "global", .cb = handle_yaml_del_global_settings},
4848 { .name = "numa", .cb = handle_yaml_del_numa },
4849 { .name = "ping", .cb = handle_yaml_no_op },
4850 { .name = "discover", .cb = handle_yaml_no_op },
4853 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4854 { .name = "route", .cb = handle_yaml_show_route },
4855 { .name = "net", .cb = handle_yaml_show_net },
4856 { .name = "peer", .cb = handle_yaml_show_peers },
4857 { .name = "ip2nets", .cb = handle_yaml_no_op },
4858 { .name = "routing", .cb = handle_yaml_show_routing },
4859 { .name = "buffers", .cb = handle_yaml_show_routing },
4860 { .name = "statistics", .cb = handle_yaml_show_stats },
4861 { .name = "global", .cb = handle_yaml_show_global_settings},
4862 { .name = "numa", .cb = handle_yaml_show_numa },
4863 { .name = "ping", .cb = handle_yaml_no_op },
4864 { .name = "discover", .cb = handle_yaml_no_op },
4867 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4868 { .name = "route", .cb = handle_yaml_no_op },
4869 { .name = "net", .cb = handle_yaml_no_op },
4870 { .name = "peer", .cb = handle_yaml_no_op },
4871 { .name = "ip2nets", .cb = handle_yaml_no_op },
4872 { .name = "routing", .cb = handle_yaml_no_op },
4873 { .name = "buffers", .cb = handle_yaml_no_op },
4874 { .name = "statistics", .cb = handle_yaml_no_op },
4875 { .name = "global", .cb = handle_yaml_no_op },
4876 { .name = "numa", .cb = handle_yaml_no_op },
4877 { .name = "ping", .cb = handle_yaml_ping },
4878 { .name = "discover", .cb = handle_yaml_discover },
4881 static cmd_handler_t lookup_fn(char *key,
4882 struct lookup_cmd_hdlr_tbl *tbl)
4888 for (i = 0; tbl[i].name != NULL; i++) {
4889 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4896 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4897 struct cYAML **show_rc, struct cYAML **err_rc)
4899 struct cYAML *tree, *item = NULL, *head, *child;
4901 char err_str[LNET_MAX_STR_LEN];
4902 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4904 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4906 return LUSTRE_CFG_RC_BAD_PARAM;
4908 child = tree->cy_child;
4909 while (child != NULL) {
4910 cb = lookup_fn(child->cy_string, table);
4912 snprintf(err_str, sizeof(err_str),
4913 "\"call back for '%s' not found\"",
4915 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4916 "yaml", "helper", err_str, err_rc);
4920 if (cYAML_is_sequence(child)) {
4921 while ((head = cYAML_get_next_seq_item(child, &item))
4923 rc = cb(head, show_rc, err_rc);
4924 if (rc != LUSTRE_CFG_RC_NO_ERR)
4928 rc = cb(child, show_rc, err_rc);
4929 if (rc != LUSTRE_CFG_RC_NO_ERR)
4933 child = child->cy_next;
4937 cYAML_free_tree(tree);
4942 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4944 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4948 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4950 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4954 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4956 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4960 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4962 return lustre_yaml_cb_helper(f, lookup_exec_tbl,