4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #define CONFIG_CMD "configure"
59 #define UNCONFIG_CMD "unconfigure"
62 #define SHOW_CMD "show"
64 #define MANAGE_CMD "manage"
66 #define MAX_NUM_IPS 128
68 #define modparam_path "/sys/module/lnet/parameters/"
69 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
70 #define gni_nid_path "/proc/cray_xt/"
72 #ifndef HAVE_USRSPC_RDMA_PS_TCP
73 #define RDMA_PS_TCP 0x0106
76 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
80 * lustre_lnet_ip_range_descr
81 * Describes an IP range.
82 * Each octect is an expression
84 struct lustre_lnet_ip_range_descr {
85 struct list_head ipr_entry;
86 struct list_head ipr_expr;
91 * Describes an ip2nets rule. This can be on a list of rules.
93 struct lustre_lnet_ip2nets {
94 struct lnet_dlc_network_descr ip2nets_net;
95 struct list_head ip2nets_ip_ranges;
98 int open_sysfs_file(const char *path, const char *attr, const int mode)
101 char filename[LNET_MAX_STR_LEN];
103 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
106 snprintf(filename, sizeof(filename), "%s%s",
109 fd = open(filename, mode);
114 static int read_sysfs_file(const char *path, const char *attr,
115 void *val, const size_t size, const int nelem)
118 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
120 fd = open_sysfs_file(path, attr, O_RDONLY);
122 return LUSTRE_CFG_RC_NO_MATCH;
124 if (read(fd, val, size * nelem) == -1)
127 rc = LUSTRE_CFG_RC_NO_ERR;
134 static int write_sysfs_file(const char *path, const char *attr,
135 void *val, const size_t size, const int nelem)
138 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
140 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
142 return LUSTRE_CFG_RC_NO_MATCH;
144 if (write(fd, val, size * nelem) == -1)
147 rc = LUSTRE_CFG_RC_NO_ERR;
156 * frees the memory allocated for an intf descriptor.
158 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
163 if (intf_descr->cpt_expr != NULL)
164 cfs_expr_list_free(intf_descr->cpt_expr);
169 * lustre_lnet_add_ip_range
171 * given a string of the format:
172 * <expr.expr.expr.expr> parse each expr into
173 * a lustre_lnet_ip_range_descr structure and insert on the list.
175 * This function is called from
176 * YAML on each ip-range.
177 * As a result of lnetctl command
178 * When building a NID or P2P selection rules
180 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
182 struct lustre_lnet_ip_range_descr *ip_range;
185 ip_range = calloc(1, sizeof(*ip_range));
186 if (ip_range == NULL)
187 return LUSTRE_CFG_RC_OUT_OF_MEM;
189 INIT_LIST_HEAD(&ip_range->ipr_entry);
190 INIT_LIST_HEAD(&ip_range->ipr_expr);
192 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
193 &ip_range->ipr_expr);
195 return LUSTRE_CFG_RC_BAD_PARAM;
197 list_add_tail(&ip_range->ipr_entry, list);
199 return LUSTRE_CFG_RC_NO_ERR;
202 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
204 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
206 struct lnet_dlc_intf_descr *intf_descr = NULL;
208 char intf_string[LNET_MAX_STR_LEN];
210 if (len >= LNET_MAX_STR_LEN)
211 return LUSTRE_CFG_RC_BAD_PARAM;
213 strncpy(intf_string, intf, len);
214 intf_string[len] = '\0';
216 intf_descr = calloc(1, sizeof(*intf_descr));
217 if (intf_descr == NULL)
218 return LUSTRE_CFG_RC_OUT_OF_MEM;
220 INIT_LIST_HEAD(&intf_descr->intf_on_network);
222 intf_name = intf_string;
223 open_sq_bracket = strchr(intf_string, '[');
224 if (open_sq_bracket != NULL) {
225 close_sq_bracket = strchr(intf_string, ']');
226 if (close_sq_bracket == NULL) {
228 return LUSTRE_CFG_RC_BAD_PARAM;
230 rc = cfs_expr_list_parse(open_sq_bracket,
231 strlen(open_sq_bracket), 0, UINT_MAX,
232 &intf_descr->cpt_expr);
235 return LUSTRE_CFG_RC_BAD_PARAM;
237 strncpy(intf_descr->intf_name, intf_name,
238 open_sq_bracket - intf_name);
239 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
241 strcpy(intf_descr->intf_name, intf_name);
242 intf_descr->cpt_expr = NULL;
245 list_add_tail(&intf_descr->intf_on_network, list);
247 return LUSTRE_CFG_RC_NO_ERR;
250 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
252 if (nw_descr != NULL) {
254 INIT_LIST_HEAD(&nw_descr->network_on_rule);
255 INIT_LIST_HEAD(&nw_descr->nw_intflist);
259 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
260 int max_nids, char *err_str)
262 int rc, num_nids = 0;
263 struct list_head nidlist;
266 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
267 return LUSTRE_CFG_RC_BAD_PARAM;
270 if (strchr(nidstr, '*')) {
271 snprintf(err_str, LNET_MAX_STR_LEN,
272 "asterisk not allowed in nidstring \"%s\"", nidstr);
273 return LUSTRE_CFG_RC_BAD_PARAM;
276 INIT_LIST_HEAD(&nidlist);
277 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
279 snprintf(err_str, LNET_MAX_STR_LEN,
280 "Unable to parse nidlist from: %s\n", nidstr);
281 return LUSTRE_CFG_RC_BAD_PARAM;
284 if (list_empty(&nidlist)) {
285 snprintf(err_str, LNET_MAX_STR_LEN,
286 "\"%s\" does not specify any valid nid lists", nidstr);
287 return LUSTRE_CFG_RC_BAD_PARAM;
290 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
291 cfs_free_nidlist(&nidlist);
293 if (num_nids == -1) {
294 snprintf(err_str, LNET_MAX_STR_LEN,
295 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
297 return LUSTRE_CFG_RC_BAD_PARAM;
301 snprintf(err_str, LNET_MAX_STR_LEN,
302 "Failed to expand nidstr: %s", strerror(num_nids));
303 return LUSTRE_CFG_RC_OUT_OF_MEM;
307 snprintf(err_str, LNET_MAX_STR_LEN,
308 "\"%s\" did not expand to any nids", nidstr);
309 return LUSTRE_CFG_RC_BAD_PARAM;
317 * <intf>[<expr>], <intf>[<expr>],..
319 int lustre_lnet_parse_interfaces(char *intf_str,
320 struct lnet_dlc_network_descr *nw_descr)
325 char *cur = intf_str, *next = NULL;
326 char *end = intf_str + strlen(intf_str);
328 struct lnet_dlc_intf_descr *intf_descr, *tmp;
330 if (nw_descr == NULL)
331 return LUSTRE_CFG_RC_BAD_PARAM;
334 open_square = strchr(cur, '[');
335 if (open_square != NULL) {
336 close_square = strchr(cur, ']');
337 if (close_square == NULL) {
338 rc = LUSTRE_CFG_RC_BAD_PARAM;
342 comma = strchr(cur, ',');
343 if (comma != NULL && comma > close_square) {
345 len = next - close_square;
351 comma = strchr(cur, ',');
361 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
362 if (rc != LUSTRE_CFG_RC_NO_ERR)
368 return LUSTRE_CFG_RC_NO_ERR;
371 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
373 list_del(&intf_descr->intf_on_network);
374 free_intf_descr(intf_descr);
380 int lustre_lnet_config_lib_init(void)
382 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
385 void lustre_lnet_config_lib_uninit(void)
387 unregister_ioc_dev(LNET_DEV_ID);
390 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
391 int seq_no, struct cYAML **err_rc)
393 struct libcfs_ioctl_data data;
396 char err_str[LNET_MAX_STR_LEN];
398 snprintf(err_str, sizeof(err_str), "\"Success\"");
400 LIBCFS_IOC_INIT(data);
402 /* Reverse logic is used here in order not to change
403 * the lctl utility */
404 data.ioc_flags = load_ni_from_mod ? 0 : 1;
406 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
408 rc = l_ioctl(LNET_DEV_ID, opc, &data);
412 "\"LNet %s error: %s\"", (up) ? "configure" :
413 "unconfigure", strerror(errno));
417 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
418 "lnet", err_str, err_rc);
423 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
424 char *err_str, char *cmd_str)
428 rc = l_ioctl(LNET_DEV_ID, cmd, data);
431 snprintf(err_str, LNET_MAX_STR_LEN,
432 "\"%s peer ni operation failed: %s\"",
433 cmd_str, strerror(errno));
439 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
440 int seq_no, struct cYAML **show_rc,
441 struct cYAML **err_rc)
444 struct lnet_ioctl_ping_data ping;
445 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
446 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
447 struct lnet_process_id id;
448 char err_str[LNET_MAX_STR_LEN] = {0};
449 char *sep, *token, *end;
452 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
456 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
458 data = calloc(1, len);
462 /* create struct cYAML root object */
463 root = cYAML_create_object(NULL, NULL);
467 ping_node = cYAML_create_seq(root, oper);
468 if (ping_node == NULL)
471 /* tokenise each nid in string ping_nids */
472 token = strtok(ping_nids, ",");
475 item = cYAML_create_seq_item(ping_node);
479 if (first_seq == NULL)
482 /* check if '-' is a part of NID, token */
483 sep = strchr(token, '-');
485 id.pid = LNET_PID_ANY;
486 /* if no net is specified, libcfs_str2nid() will assume tcp */
487 id.nid = libcfs_str2nid(token);
488 if (id.nid == LNET_NID_ANY) {
489 snprintf(err_str, sizeof(err_str),
490 "\"cannot parse NID '%s'\"",
492 rc = LUSTRE_CFG_RC_BAD_PARAM;
493 cYAML_build_error(rc, seq_no, MANAGE_CMD,
494 oper, err_str, err_rc);
498 if (token[0] == 'u' || token[0] == 'U')
499 id.pid = (strtoul(&token[1], &end, 0) |
500 (LNET_PID_USERFLAG));
502 id.pid = strtoul(token, &end, 0);
504 /* assuming '-' is part of hostname */
506 id.pid = LNET_PID_ANY;
507 id.nid = libcfs_str2nid(token);
508 if (id.nid == LNET_NID_ANY) {
509 snprintf(err_str, sizeof(err_str),
510 "\"cannot parse NID '%s'\"",
512 rc = LUSTRE_CFG_RC_BAD_PARAM;
513 cYAML_build_error(rc, seq_no, MANAGE_CMD,
519 id.nid = libcfs_str2nid(sep + 1);
520 if (id.nid == LNET_NID_ANY) {
521 snprintf(err_str, sizeof(err_str),
522 "\"cannot parse NID '%s'\"",
524 rc = LUSTRE_CFG_RC_BAD_PARAM;
525 cYAML_build_error(rc, seq_no, MANAGE_CMD,
532 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
533 ping.ping_hdr.ioc_len = sizeof(ping);
535 ping.op_param = param;
536 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
537 ping.ping_buf = data;
539 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
542 sizeof(err_str), "failed to %s %s: %s\n", oper,
543 id.pid == LNET_PID_ANY ?
544 libcfs_nid2str(id.nid) :
545 libcfs_id2str(id), strerror(errno));
546 rc = LUSTRE_CFG_RC_BAD_PARAM;
547 cYAML_build_error(rc, seq_no, MANAGE_CMD,
548 oper, err_str, err_rc);
552 if (cYAML_create_string(item, "primary nid",
553 libcfs_nid2str(ping.ping_id.nid)) == NULL)
556 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
557 "True" : "False") == NULL)
560 tmp = cYAML_create_seq(item, "peer ni");
564 for (i = 0; i < ping.ping_count; i++) {
565 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
567 peer_ni = cYAML_create_seq_item(tmp);
570 memset(buf, 0, sizeof buf);
571 snprintf(buf, sizeof buf, "nid");
572 if (cYAML_create_string(peer_ni, buf,
573 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
579 } while ((token = strtok(NULL, ",")) != NULL);
582 rc = LUSTRE_CFG_RC_NO_ERR;
587 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
588 cYAML_free_tree(root);
589 } else if (show_rc != NULL && *show_rc != NULL) {
590 struct cYAML *show_node;
591 show_node = cYAML_get_object_item(*show_rc, oper);
592 if (show_node != NULL && cYAML_is_sequence(show_node)) {
593 cYAML_insert_child(show_node, first_seq);
596 } else if (show_node == NULL) {
597 cYAML_insert_sibling((*show_rc)->cy_child,
601 cYAML_free_tree(root);
610 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
611 struct cYAML **show_rc, struct cYAML **err_rc)
615 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
616 seq_no, show_rc, err_rc);
620 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
621 struct cYAML **show_rc, struct cYAML **err_rc)
625 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
626 seq_no, show_rc, err_rc);
630 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
631 bool is_mr, __u32 cmd,
632 char *cmd_type, char *err_str)
634 struct lnet_ioctl_peer_cfg data;
637 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
638 /* When adding a peer we first need to create the peer using the
639 * specified (or implied) primary nid. Then we can add
640 * additional nids to this peer using the primary nid as a key
642 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
643 data.prcfg_mr = is_mr;
644 data.prcfg_prim_nid = nidlist[0];
645 data.prcfg_cfg_nid = LNET_NID_ANY;
647 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
653 /* Add or delete any specified NIs associated with the specified
654 * (or implied) primary nid
656 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
657 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
658 data.prcfg_mr = is_mr;
659 data.prcfg_prim_nid = nidlist[0];
660 data.prcfg_cfg_nid = nidlist[nid_idx];
662 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
668 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
669 /* In the delete case we may have been given just the
670 * primary nid of the peer. This tells us to delete the peer
671 * completely (rather than just delete some of its NIs)
673 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
674 data.prcfg_prim_nid = nidlist[0];
675 data.prcfg_cfg_nid = LNET_NID_ANY;
677 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
684 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
685 int cmd, int num_nids, bool is_mr, int seq_no,
686 struct cYAML **err_rc)
688 int rc = LUSTRE_CFG_RC_NO_ERR;
689 char err_str[LNET_MAX_STR_LEN];
690 lnet_nid_t *lnet_nidlist2 = NULL;
691 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
692 IOC_LIBCFS_DEL_PEER_NI;
693 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
696 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
697 if (!lnet_nidlist2) {
698 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
699 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
702 lnet_nidlist2[0] = pnid;
703 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
706 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
707 num_nids, is_mr, ioc_cmd,
713 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
718 replace_sep(char *str, char sep, char newsep)
724 for (i = 0; i < strlen(str); i++) {
725 /* don't replace ',' within [] */
728 else if (str[i] == ']')
730 else if (str[i] == sep && bracket == 0)
735 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
736 int cmd, int seq_no, struct cYAML **err_rc)
739 char err_str[LNET_MAX_STR_LEN] = "Error";
740 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
741 lnet_nid_t pnid = LNET_NID_ANY;
744 rc = LUSTRE_CFG_RC_BAD_PARAM;
745 snprintf(err_str, LNET_MAX_STR_LEN,
746 "--prim_nid must be specified");
750 pnid = libcfs_str2nid(prim_nid);
751 if (pnid == LNET_NID_ANY) {
752 rc = LUSTRE_CFG_RC_BAD_PARAM;
753 snprintf(err_str, LNET_MAX_STR_LEN,
754 "badly formatted primary NID: %s", prim_nid);
761 * if there is no primary nid we need to make the first nid in the
762 * nids list the primary nid
764 replace_sep(nids, ',', ' ');
765 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
766 LNET_MAX_NIDS_PER_PEER, err_str);
773 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
774 cmd, num_nids, is_mr,
778 if (rc != LUSTRE_CFG_RC_NO_ERR)
779 cYAML_build_error(rc, -1, "peer",
780 cmd == LNETCTL_ADD_CMD ? "add" : "del",
786 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
787 int sen, int seq_no, struct cYAML **err_rc,
790 int rc, num_nids, idx;
792 char err_str[LNET_MAX_STR_LEN];
793 struct lnet_ioctl_config_data data;
794 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
796 memset(err_str, 0, LNET_MAX_STR_LEN);
797 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
799 if (nw == NULL || nidstr == NULL) {
800 snprintf(err_str, LNET_MAX_STR_LEN,
801 "\"missing mandatory parameter:'%s'\"",
802 (nw == NULL && nidstr == NULL) ? "network, gateway" :
803 (nw == NULL) ? "network" : "gateway");
804 rc = LUSTRE_CFG_RC_MISSING_PARAM;
808 rnet = libcfs_str2net(nw);
809 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
810 snprintf(err_str, LNET_MAX_STR_LEN,
811 "\"cannot parse remote net %s\"", nw);
812 rc = LUSTRE_CFG_RC_BAD_PARAM;
816 replace_sep(nidstr, ',', ' ');
817 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
818 LNET_MAX_NIDS_PER_PEER, err_str);
824 for (idx = 0; idx < num_nids; idx++) {
825 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
827 if (cmd == LNETCTL_ADD_CMD) {
828 data.cfg_config_u.cfg_route.rtr_hop = hops;
829 data.cfg_config_u.cfg_route.rtr_priority = prio;
830 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
833 data.cfg_nid = lnet_nidlist[idx];
835 if (cmd == LNETCTL_ADD_CMD)
836 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
839 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
842 if (rc != 0 && errno != EEXIST &&
843 errno != EHOSTUNREACH) {
845 snprintf(err_str, LNET_MAX_STR_LEN,
846 "route operation failed: %s",
849 } else if (errno == EEXIST) {
851 * continue chugging along if one of the
852 * routes already exists
859 cYAML_build_error(rc, seq_no,
860 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
866 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
867 int sen, int seq_no, struct cYAML **err_rc)
870 char err_str[LNET_MAX_STR_LEN];
871 memset(err_str, 0, LNET_MAX_STR_LEN);
872 snprintf(err_str, LNET_MAX_STR_LEN, "\"generic error\"");
875 hops = LNET_UNDEFINED_HOPS;
876 } else if (hops < 1 || hops > 255) {
877 snprintf(err_str, LNET_MAX_STR_LEN,
878 "\"invalid hop count %d, must be between 1 and 255\"",
880 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
886 } else if (prio < 0) {
887 snprintf(err_str, LNET_MAX_STR_LEN,
888 "\"invalid priority %d, must be greater than 0\"",
890 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
896 } else if (sen < 1) {
897 snprintf(err_str, LNET_MAX_STR_LEN,
898 "\"invalid health sensitivity %d, must be 1 or greater\"",
900 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
904 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
905 err_rc, LNETCTL_ADD_CMD);
908 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
913 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
914 struct cYAML **err_rc)
916 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
920 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
921 int seq_no, struct cYAML **show_rc,
922 struct cYAML **err_rc, bool backup)
924 struct lnet_ioctl_config_data data;
925 lnet_nid_t gateway_nid;
926 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
928 __u32 net = LNET_NIDNET(LNET_NID_ANY);
930 struct cYAML *root = NULL, *route = NULL, *item = NULL;
931 struct cYAML *first_seq = NULL;
932 char err_str[LNET_MAX_STR_LEN];
935 snprintf(err_str, sizeof(err_str),
936 "\"out of memory\"");
939 net = libcfs_str2net(nw);
940 if (net == LNET_NIDNET(LNET_NID_ANY)) {
943 "\"cannot parse net '%s'\"", nw);
944 rc = LUSTRE_CFG_RC_BAD_PARAM;
949 /* show all routes without filtering on net */
950 net = LNET_NIDNET(LNET_NID_ANY);
954 gateway_nid = libcfs_str2nid(gw);
955 if (gateway_nid == LNET_NID_ANY) {
958 "\"cannot parse gateway NID '%s'\"", gw);
959 rc = LUSTRE_CFG_RC_BAD_PARAM;
963 /* show all routes with out filtering on gateway */
964 gateway_nid = LNET_NID_ANY;
966 if ((hops < 1 && hops != -1) || hops > 255) {
969 "\"invalid hop count %d, must be between 0 and 256\"",
971 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
975 /* create struct cYAML root object */
976 root = cYAML_create_object(NULL, NULL);
980 route = cYAML_create_seq(root, "route");
988 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
991 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
997 /* filter on provided data */
998 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1002 if (gateway_nid != LNET_NID_ANY &&
1003 gateway_nid != data.cfg_nid)
1007 hops != data.cfg_config_u.cfg_route.rtr_hop)
1011 prio != data.cfg_config_u.cfg_route.rtr_priority)
1014 /* default rc to -1 incase we hit the goto */
1018 item = cYAML_create_seq_item(route);
1022 if (first_seq == NULL)
1025 if (cYAML_create_string(item, "net",
1026 libcfs_net2str(data.cfg_net)) == NULL)
1029 if (cYAML_create_string(item, "gateway",
1030 libcfs_nid2str(data.cfg_nid)) == NULL)
1034 if (cYAML_create_number(item, "hop",
1035 (int) data.cfg_config_u.
1036 cfg_route.rtr_hop) ==
1040 if (cYAML_create_number(item, "priority",
1042 cfg_route.rtr_priority) == NULL)
1045 if (cYAML_create_number(item, "health_sensitivity",
1047 cfg_route.rtr_sensitivity) == NULL)
1050 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1052 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1056 cYAML_create_string(item, "state",
1058 "up" : "down") == NULL)
1062 cYAML_create_string(item, "type",
1064 "multi-hop" : "single-hop") == NULL)
1069 /* print output iff show_rc is not provided */
1070 if (show_rc == NULL)
1071 cYAML_print_tree(root);
1073 if (l_errno != ENOENT) {
1076 "\"cannot get routes: %s\"",
1081 rc = LUSTRE_CFG_RC_NO_ERR;
1083 snprintf(err_str, sizeof(err_str), "\"success\"");
1085 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1086 cYAML_free_tree(root);
1087 } else if (show_rc != NULL && *show_rc != NULL) {
1088 struct cYAML *show_node;
1089 /* find the route node, if one doesn't exist then
1090 * insert one. Otherwise add to the one there
1092 show_node = cYAML_get_object_item(*show_rc, "route");
1093 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1094 cYAML_insert_child(show_node, first_seq);
1097 } else if (show_node == NULL) {
1098 cYAML_insert_sibling((*show_rc)->cy_child,
1102 cYAML_free_tree(root);
1108 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1113 static int socket_intf_query(int request, char *intf,
1119 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1120 return LUSTRE_CFG_RC_BAD_PARAM;
1122 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1124 return LUSTRE_CFG_RC_BAD_PARAM;
1126 strcpy(ifr->ifr_name, intf);
1127 rc = ioctl(sockfd, request, ifr);
1129 rc = LUSTRE_CFG_RC_BAD_PARAM;
1136 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1141 memset(&ifr, 0, sizeof(ifr));
1142 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1144 return LUSTRE_CFG_RC_BAD_PARAM;
1146 if ((ifr.ifr_flags & IFF_UP) == 0)
1147 return LUSTRE_CFG_RC_BAD_PARAM;
1149 memset(&ifr, 0, sizeof(ifr));
1150 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1152 return LUSTRE_CFG_RC_BAD_PARAM;
1154 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1155 *ip = bswap_32(*ip);
1157 return LUSTRE_CFG_RC_NO_ERR;
1161 * for each interface in the array of interfaces find the IP address of
1162 * that interface, create its nid and add it to an array of NIDs.
1163 * Stop if any of the interfaces is down
1165 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1166 lnet_nid_t **nids, __u32 *nnids,
1167 char *err_str, size_t str_len)
1169 int i = 0, count = 0, rc;
1170 struct lnet_dlc_intf_descr *intf;
1171 char val[LNET_MAX_STR_LEN];
1178 if (nw == NULL || nids == NULL) {
1179 snprintf(err_str, str_len,
1180 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1181 err_str[str_len - 1] = '\0';
1182 return LUSTRE_CFG_RC_BAD_PARAM;
1185 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1188 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1192 *nids = calloc(count, sizeof(lnet_nid_t));
1193 if (*nids == NULL) {
1194 snprintf(err_str, str_len,
1195 "\"out of memory\"");
1196 err_str[str_len - 1] = '\0';
1197 return LUSTRE_CFG_RC_OUT_OF_MEM;
1200 * special case the GNI interface since it doesn't have an IP
1201 * address. The assumption is that there can only be one GNI
1202 * interface in the system. No interface name is provided.
1204 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1205 rc = read_sysfs_file(gni_nid_path, "nid", val,
1208 snprintf(err_str, str_len,
1209 "\"cannot read gni nid\"");
1210 err_str[str_len - 1] = '\0';
1213 gni_num = atoi(val);
1215 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1220 /* look at the other interfaces */
1221 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1222 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1223 /* handle LNDs with numeric interface name */
1224 num = strtoul(intf->intf_name, &endp, 0);
1225 if (endp == intf->intf_name || *endp != '\0') {
1226 rc = LUSTRE_CFG_RC_BAD_PARAM;
1227 snprintf(err_str, str_len,
1228 "\"couldn't query intf %s\"",
1230 err_str[str_len - 1] = '\0';
1233 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1236 /* handle LNDs with ip interface name */
1237 rc = lustre_lnet_queryip(intf, &ip);
1238 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1239 snprintf(err_str, str_len,
1240 "\"couldn't query intf %s\"",
1242 err_str[str_len - 1] = '\0';
1245 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1262 * called repeatedly until a match or no more ip range
1264 * ip_range expression
1265 * interface list with all the interface names.
1266 * all the interfaces in the system.
1268 * try to match the ip_range expr to one of the interfaces' IPs in
1269 * the system. If we hit a patch for an interface. Check if that
1270 * interface name is in the list.
1272 * If there are more than one interface in the list, then make sure
1273 * that the IPs for all of these interfaces match the ip ranges
1276 * for each interface in intf_list
1277 * look up the intf name in ifa
1278 * if not there then no match
1279 * check ip obtained from ifa against a match to any of the
1281 * If no match, then fail
1283 * The result is that all the interfaces have to match.
1285 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1286 struct list_head *intf_list,
1287 struct list_head *ip_ranges)
1291 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1292 struct ifaddrs *ifaddr = ifa;
1293 struct lustre_lnet_ip_range_descr *ip_range;
1297 * if there are no explicit interfaces, and no ip ranges, then
1298 * configure the first tcp interface we encounter.
1300 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1301 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1302 if (ifaddr->ifa_addr == NULL)
1305 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1308 family = ifaddr->ifa_addr->sa_family;
1309 if (family == AF_INET &&
1310 strcmp(ifaddr->ifa_name, "lo") != 0) {
1311 rc = lustre_lnet_add_intf_descr
1312 (intf_list, ifaddr->ifa_name,
1313 strlen(ifaddr->ifa_name));
1315 if (rc != LUSTRE_CFG_RC_NO_ERR)
1318 return LUSTRE_CFG_RC_MATCH;
1321 return LUSTRE_CFG_RC_NO_MATCH;
1325 * First interface which matches an IP pattern will be used
1327 if (list_empty(intf_list)) {
1329 * no interfaces provided in the rule, but an ip range is
1330 * provided, so try and match an interface to the ip
1333 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1334 if (ifaddr->ifa_addr == NULL)
1337 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1340 family = ifaddr->ifa_addr->sa_family;
1341 if (family == AF_INET) {
1342 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1345 list_for_each_entry(ip_range, ip_ranges,
1347 rc = cfs_ip_addr_match(bswap_32(ip),
1348 &ip_range->ipr_expr);
1352 rc = lustre_lnet_add_intf_descr
1353 (intf_list, ifaddr->ifa_name,
1354 strlen(ifaddr->ifa_name));
1356 if (rc != LUSTRE_CFG_RC_NO_ERR)
1362 if (!list_empty(intf_list))
1363 return LUSTRE_CFG_RC_MATCH;
1365 return LUSTRE_CFG_RC_NO_MATCH;
1369 * If an interface is explicitly specified the ip-range might or
1370 * might not be specified. if specified the interface needs to match the
1371 * ip-range. If no ip-range then the interfaces are
1372 * automatically matched if they are all up.
1373 * If > 1 interfaces all the interfaces must match for the NI to
1376 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1377 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1378 if (ifaddr->ifa_addr == NULL)
1381 family = ifaddr->ifa_addr->sa_family;
1382 if (family == AF_INET &&
1383 strcmp(intf_descr->intf_name,
1384 ifaddr->ifa_name) == 0)
1388 if (ifaddr == NULL) {
1389 list_del(&intf_descr->intf_on_network);
1390 free_intf_descr(intf_descr);
1394 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1395 list_del(&intf_descr->intf_on_network);
1396 free_intf_descr(intf_descr);
1400 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1403 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1404 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1410 /* no match for this interface */
1411 list_del(&intf_descr->intf_on_network);
1412 free_intf_descr(intf_descr);
1416 return LUSTRE_CFG_RC_MATCH;
1419 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1420 lnet_nid_t **nids, __u32 *nnids,
1421 char *err_str, size_t str_len)
1423 struct ifaddrs *ifa;
1424 int rc = LUSTRE_CFG_RC_NO_ERR;
1426 rc = getifaddrs(&ifa);
1428 snprintf(err_str, str_len,
1429 "\"failed to get interface addresses: %d\"", -errno);
1430 err_str[str_len - 1] = '\0';
1434 rc = lustre_lnet_match_ip_to_intf(ifa,
1435 &ip2nets->ip2nets_net.nw_intflist,
1436 &ip2nets->ip2nets_ip_ranges);
1437 if (rc != LUSTRE_CFG_RC_MATCH) {
1438 snprintf(err_str, str_len,
1439 "\"couldn't match ip to existing interfaces\"");
1440 err_str[str_len - 1] = '\0';
1445 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1446 err_str, sizeof(err_str));
1447 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1458 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1459 struct lnet_ioctl_config_lnd_tunables *tunables,
1460 struct cfs_expr_list *global_cpts,
1461 lnet_nid_t *nids, char *err_str)
1464 struct lnet_ioctl_config_ni *conf;
1465 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1466 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1469 struct lnet_dlc_intf_descr *intf_descr;
1471 struct cfs_expr_list *cpt_expr;
1473 list_for_each_entry(intf_descr, intf_list,
1475 if (tunables != NULL)
1476 len = sizeof(struct lnet_ioctl_config_ni) +
1477 sizeof(struct lnet_ioctl_config_lnd_tunables);
1479 len = sizeof(struct lnet_ioctl_config_ni);
1481 data = calloc(1, len);
1483 return LUSTRE_CFG_RC_OUT_OF_MEM;
1484 conf = (struct lnet_ioctl_config_ni*) data;
1485 if (tunables != NULL)
1486 tun = (struct lnet_ioctl_config_lnd_tunables*)
1489 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1490 conf->lic_cfg_hdr.ioc_len = len;
1491 conf->lic_nid = nids[i];
1492 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1495 if (intf_descr->cpt_expr != NULL)
1496 cpt_expr = intf_descr->cpt_expr;
1497 else if (global_cpts != NULL)
1498 cpt_expr = global_cpts;
1502 if (cpt_expr != NULL) {
1503 count = cfs_expr_list_values(cpt_expr,
1504 LNET_MAX_SHOW_NUM_CPT,
1507 memcpy(conf->lic_cpts, cpt_array,
1508 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1517 conf->lic_ncpts = count;
1519 if (tunables != NULL)
1520 memcpy(tun, tunables, sizeof(*tunables));
1522 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1527 "\"cannot add network: %s\"", strerror(errno));
1535 return LUSTRE_CFG_RC_NO_ERR;
1539 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1540 struct lnet_ioctl_config_lnd_tunables *tunables,
1541 struct cfs_expr_list *global_cpts,
1542 int seq_no, struct cYAML **err_rc)
1544 lnet_nid_t *nids = NULL;
1547 char err_str[LNET_MAX_STR_LEN];
1549 snprintf(err_str, sizeof(err_str), "\"success\"");
1554 "\"incomplete ip2nets information\"");
1555 rc = LUSTRE_CFG_RC_BAD_PARAM;
1560 * call below function to resolve the rules into a list of nids.
1561 * The memory is allocated in that function then freed here when
1562 * it's no longer needed.
1564 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1566 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1569 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1570 snprintf(err_str, sizeof(err_str),
1571 "\"no interfaces match ip2nets rules\"");
1575 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1576 tunables, global_cpts, nids,
1583 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1587 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1588 struct cfs_expr_list *global_cpts,
1590 struct lnet_ioctl_config_lnd_tunables *tunables,
1591 int seq_no, struct cYAML **err_rc)
1594 struct lnet_ioctl_config_ni *conf;
1595 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1596 char buf[LNET_MAX_STR_LEN];
1597 int rc = LUSTRE_CFG_RC_NO_ERR;
1598 char err_str[LNET_MAX_STR_LEN];
1599 lnet_nid_t *nids = NULL;
1603 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1606 snprintf(err_str, sizeof(err_str), "\"success\"");
1608 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1609 (list_empty(&nw_descr->nw_intflist) &&
1610 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1613 "\"missing mandatory parameters in NI config: '%s'\"",
1614 (nw_descr == NULL) ? "network , interface" :
1615 (nw_descr->nw_id == 0) ? "network" : "interface");
1616 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1620 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1623 "\"ip2net string too long %d\"",
1624 (int)strlen(ip2net));
1625 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1629 if (ip2net != NULL) {
1630 if (tunables != NULL)
1631 len = sizeof(struct lnet_ioctl_config_ni) +
1632 sizeof(struct lnet_ioctl_config_lnd_tunables);
1634 len = sizeof(struct lnet_ioctl_config_ni);
1635 data = calloc(1, len);
1637 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1640 conf = (struct lnet_ioctl_config_ni*) data;
1641 if (tunables != NULL)
1642 tun = (struct lnet_ioctl_config_lnd_tunables*)
1643 (data + sizeof(*conf));
1645 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1646 conf->lic_cfg_hdr.ioc_len = len;
1647 strncpy(conf->lic_legacy_ip2nets, ip2net,
1650 if (global_cpts != NULL) {
1651 count = cfs_expr_list_values(global_cpts,
1652 LNET_MAX_SHOW_NUM_CPT,
1655 memcpy(conf->lic_cpts, cpt_array,
1656 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1665 conf->lic_ncpts = count;
1667 if (tunables != NULL)
1668 memcpy(tun, tunables, sizeof(*tunables));
1670 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1675 "\"cannot add network: %s\"", strerror(errno));
1682 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1683 rc = LUSTRE_CFG_RC_NO_ERR;
1687 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1690 "\"cannot parse net '%s'\"",
1691 libcfs_net2str(nw_descr->nw_id));
1692 rc = LUSTRE_CFG_RC_BAD_PARAM;
1697 * special case the GNI since no interface name is expected
1699 if (list_empty(&nw_descr->nw_intflist) &&
1700 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1703 "\"no interface name provided\"");
1704 rc = LUSTRE_CFG_RC_BAD_PARAM;
1708 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1709 err_str, sizeof(err_str));
1711 rc = LUSTRE_CFG_RC_BAD_PARAM;
1715 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1716 tunables, global_cpts, nids,
1720 if (nw_descr != NULL) {
1721 list_for_each_entry_safe(intf_descr, tmp,
1722 &nw_descr->nw_intflist,
1724 list_del(&intf_descr->intf_on_network);
1725 free_intf_descr(intf_descr);
1729 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1740 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1741 int seq_no, struct cYAML **err_rc)
1743 struct lnet_ioctl_config_ni data;
1744 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1745 char err_str[LNET_MAX_STR_LEN];
1746 lnet_nid_t *nids = NULL;
1748 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1750 snprintf(err_str, sizeof(err_str), "\"success\"");
1752 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1755 "\"missing mandatory parameter in deleting NI: '%s'\"",
1756 (nw_descr == NULL) ? "network , interface" :
1757 (nw_descr->nw_id == 0) ? "network" : "interface");
1758 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1762 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1763 return LUSTRE_CFG_RC_NO_ERR;
1765 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1768 "\"cannot parse net '%s'\"",
1769 libcfs_net2str(nw_descr->nw_id));
1770 rc = LUSTRE_CFG_RC_BAD_PARAM;
1774 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1775 err_str, sizeof(err_str));
1777 rc = LUSTRE_CFG_RC_BAD_PARAM;
1782 * no interfaces just the nw_id is specified
1785 nids = calloc(1, sizeof(*nids));
1787 snprintf(err_str, sizeof(err_str),
1788 "\"out of memory\"");
1789 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1792 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1796 for (i = 0; i < nnids; i++) {
1797 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1798 data.lic_nid = nids[i];
1800 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1805 "\"cannot del network: %s\"", strerror(errno));
1809 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1811 list_del(&intf_descr->intf_on_network);
1812 free_intf_descr(intf_descr);
1816 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1825 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1826 enum lnet_health_type type, char *name,
1827 int seq_no, struct cYAML **err_rc)
1829 struct lnet_ioctl_reset_health_cfg data;
1830 int rc = LUSTRE_CFG_RC_NO_ERR;
1831 char err_str[LNET_MAX_STR_LEN];
1833 snprintf(err_str, sizeof(err_str), "\"success\"");
1835 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1836 data.rh_type = type;
1838 data.rh_value = value;
1841 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1845 sizeof(err_str), "Can not configure health value: %s",
1849 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1854 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1855 struct cYAML **err_rc)
1859 nid = libcfs_str2nid(ni_nid);
1862 return lustre_lnet_config_healthv(value, all, nid,
1863 LNET_HEALTH_TYPE_LOCAL_NI,
1864 "ni healthv", seq_no, err_rc);
1867 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1868 int seq_no, struct cYAML **err_rc)
1872 nid = libcfs_str2nid(lpni_nid);
1875 return lustre_lnet_config_healthv(value, all, nid,
1876 LNET_HEALTH_TYPE_PEER_NI,
1877 "peer_ni healthv", seq_no, err_rc);
1881 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1882 struct lnet_ioctl_comm_count *counts)
1884 if (cYAML_create_number(yaml, "put",
1885 counts->ico_put_count)
1888 if (cYAML_create_number(yaml, "get",
1889 counts->ico_get_count)
1892 if (cYAML_create_number(yaml, "reply",
1893 counts->ico_reply_count)
1896 if (cYAML_create_number(yaml, "ack",
1897 counts->ico_ack_count)
1900 if (cYAML_create_number(yaml, "hello",
1901 counts->ico_hello_count)
1908 static struct lnet_ioctl_comm_count *
1909 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1912 return &msg_stats->im_send_stats;
1914 return &msg_stats->im_recv_stats;
1916 return &msg_stats->im_drop_stats;
1921 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1922 struct cYAML **show_rc, struct cYAML **err_rc,
1926 struct lnet_ioctl_config_ni *ni_data;
1927 struct lnet_ioctl_config_lnd_tunables *lnd;
1928 struct lnet_ioctl_element_stats *stats;
1929 struct lnet_ioctl_element_msg_stats msg_stats;
1930 struct lnet_ioctl_local_ni_hstats hstats;
1931 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1932 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1933 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1935 struct cYAML *root = NULL, *tunables = NULL,
1936 *net_node = NULL, *interfaces = NULL,
1937 *item = NULL, *first_seq = NULL,
1938 *tmp = NULL, *statistics = NULL,
1940 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1941 char str_buf[str_buf_len];
1943 char err_str[LNET_MAX_STR_LEN];
1944 bool exist = false, new_net = true;
1946 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1948 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1950 buf = calloc(1, buf_size);
1954 ni_data = (struct lnet_ioctl_config_ni *)buf;
1957 net = libcfs_str2net(nw);
1958 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1961 "\"cannot parse net '%s'\"", nw);
1962 rc = LUSTRE_CFG_RC_BAD_PARAM;
1967 root = cYAML_create_object(NULL, NULL);
1971 net_node = cYAML_create_seq(root, "net");
1972 if (net_node == NULL)
1978 memset(buf, 0, buf_size);
1980 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1982 * set the ioc_len to the proper value since INIT assumes
1985 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1986 ni_data->lic_idx = i;
1988 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1994 rc_net = LNET_NIDNET(ni_data->lic_nid);
1996 /* filter on provided data */
1997 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2001 /* if we're backing up don't store lo */
2002 if (backup && LNET_NETTYP(rc_net) == LOLND)
2005 /* default rc to -1 in case we hit the goto */
2009 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2010 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2011 (ni_data->lic_bulk + sizeof(*stats));
2013 if (rc_net != prev_net) {
2020 if (!cYAML_create_string(net_node, "net type",
2021 libcfs_net2str(rc_net)))
2024 tmp = cYAML_create_seq(net_node, "local NI(s)");
2030 /* create the tree to be printed. */
2031 item = cYAML_create_seq_item(tmp);
2035 if (first_seq == NULL)
2039 cYAML_create_string(item, "nid",
2040 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2044 cYAML_create_string(item,
2046 (ni_data->lic_status ==
2047 LNET_NI_STATUS_UP) ?
2048 "up" : "down") == NULL)
2051 /* don't add interfaces unless there is at least one
2053 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2054 interfaces = cYAML_create_object(item, "interfaces");
2055 if (interfaces == NULL)
2058 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2059 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2061 sizeof(str_buf), "%d", j);
2062 if (cYAML_create_string(interfaces,
2064 ni_data->lic_ni_intf[j]) ==
2076 goto continue_without_msg_stats;
2078 statistics = cYAML_create_object(item, "statistics");
2079 if (statistics == NULL)
2082 if (cYAML_create_number(statistics, "send_count",
2083 stats->iel_send_count)
2087 if (cYAML_create_number(statistics, "recv_count",
2088 stats->iel_recv_count)
2092 if (cYAML_create_number(statistics, "drop_count",
2093 stats->iel_drop_count)
2098 goto continue_without_msg_stats;
2100 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2101 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2102 msg_stats.im_idx = i;
2104 rc = l_ioctl(LNET_DEV_ID,
2105 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2109 goto continue_without_msg_stats;
2112 for (k = 0; k < 3; k++) {
2113 struct lnet_ioctl_comm_count *counts;
2114 struct cYAML *msg_statistics = NULL;
2116 msg_statistics = cYAML_create_object(item,
2117 (char *)gmsg_stat_names[k]);
2118 if (msg_statistics == NULL)
2121 counts = get_counts(&msg_stats, k);
2125 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2130 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2131 hstats.hlni_nid = ni_data->lic_nid;
2132 /* grab health stats */
2133 rc = l_ioctl(LNET_DEV_ID,
2134 IOC_LIBCFS_GET_LOCAL_HSTATS,
2138 goto continue_without_msg_stats;
2140 yhstats = cYAML_create_object(item, "health stats");
2143 if (cYAML_create_number(yhstats, "health value",
2144 hstats.hlni_health_value)
2147 if (cYAML_create_number(yhstats, "interrupts",
2148 hstats.hlni_local_interrupt)
2151 if (cYAML_create_number(yhstats, "dropped",
2152 hstats.hlni_local_dropped)
2155 if (cYAML_create_number(yhstats, "aborted",
2156 hstats.hlni_local_aborted)
2159 if (cYAML_create_number(yhstats, "no route",
2160 hstats.hlni_local_no_route)
2163 if (cYAML_create_number(yhstats, "timeouts",
2164 hstats.hlni_local_timeout)
2167 if (cYAML_create_number(yhstats, "error",
2168 hstats.hlni_local_error)
2172 continue_without_msg_stats:
2173 tunables = cYAML_create_object(item, "tunables");
2177 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2178 if (rc != LUSTRE_CFG_RC_NO_ERR)
2181 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2183 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2184 rc != LUSTRE_CFG_RC_NO_MATCH)
2187 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2188 tunables = cYAML_create_object(item,
2190 if (tunables == NULL)
2195 cYAML_create_number(item, "dev cpt",
2196 ni_data->lic_dev_cpt) == NULL)
2200 cYAML_create_number(item, "tcp bonding",
2201 ni_data->lic_tcp_bonding)
2205 /* out put the CPTs in the format: "[x,x,x,...]" */
2207 limit = str_buf + str_buf_len - 3;
2208 pos += scnprintf(pos, limit - pos, "\"[");
2209 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2210 j < ni_data->lic_ncpts &&
2212 pos += scnprintf(pos, limit - pos,
2213 "%d", ni_data->lic_cpts[j]);
2214 if ((j + 1) < ni_data->lic_ncpts)
2215 pos += scnprintf(pos, limit - pos, ",");
2217 snprintf(pos, 3, "]\"");
2219 if (ni_data->lic_ncpts >= 1 &&
2220 cYAML_create_string(item, "CPT",
2226 /* Print out the net information only if show_rc is not provided */
2227 if (show_rc == NULL)
2228 cYAML_print_tree(root);
2230 if (l_errno != ENOENT) {
2233 "\"cannot get networks: %s\"",
2238 rc = LUSTRE_CFG_RC_NO_ERR;
2240 snprintf(err_str, sizeof(err_str), "\"success\"");
2242 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2243 cYAML_free_tree(root);
2244 } else if (show_rc != NULL && *show_rc != NULL) {
2245 struct cYAML *show_node;
2246 /* find the net node, if one doesn't exist
2247 * then insert one. Otherwise add to the one there
2249 show_node = cYAML_get_object_item(*show_rc, "net");
2250 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2251 cYAML_insert_child(show_node, first_seq);
2254 } else if (show_node == NULL) {
2255 cYAML_insert_sibling((*show_rc)->cy_child,
2259 cYAML_free_tree(root);
2265 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2270 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2272 struct lnet_ioctl_config_data data;
2273 int rc = LUSTRE_CFG_RC_NO_ERR;
2274 char err_str[LNET_MAX_STR_LEN];
2276 snprintf(err_str, sizeof(err_str), "\"success\"");
2278 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2279 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2281 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2286 "\"cannot %s routing %s\"",
2287 (enable) ? "enable" : "disable", strerror(errno));
2292 cYAML_build_error(rc, seq_no,
2293 (enable) ? ADD_CMD : DEL_CMD,
2294 "routing", err_str, err_rc);
2299 int ioctl_set_value(__u32 val, int ioc, char *name,
2300 int seq_no, struct cYAML **err_rc)
2302 struct lnet_ioctl_set_value data;
2303 int rc = LUSTRE_CFG_RC_NO_ERR;
2304 char err_str[LNET_MAX_STR_LEN];
2306 snprintf(err_str, sizeof(err_str), "\"success\"");
2308 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2309 data.sv_value = val;
2311 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2316 "\"cannot configure %s to %d: %s\"", name,
2317 val, strerror(errno));
2320 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2325 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2327 int rc = LUSTRE_CFG_RC_NO_ERR;
2328 char err_str[LNET_MAX_STR_LEN];
2329 char val[LNET_MAX_STR_LEN];
2331 snprintf(err_str, sizeof(err_str), "\"success\"");
2333 snprintf(val, sizeof(val), "%d", intrv);
2335 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2336 1, strlen(val) + 1);
2338 snprintf(err_str, sizeof(err_str),
2339 "\"cannot configure recovery interval: %s\"",
2342 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2347 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2349 int rc = LUSTRE_CFG_RC_NO_ERR;
2350 char err_str[LNET_MAX_STR_LEN];
2351 char val[LNET_MAX_STR_LEN];
2353 snprintf(err_str, sizeof(err_str), "\"success\"");
2355 snprintf(val, sizeof(val), "%d", sen);
2357 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2358 1, strlen(val) + 1);
2360 snprintf(err_str, sizeof(err_str),
2361 "\"cannot configure router health sensitivity: %s\"",
2364 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2369 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2371 int rc = LUSTRE_CFG_RC_NO_ERR;
2372 char err_str[LNET_MAX_STR_LEN];
2373 char val[LNET_MAX_STR_LEN];
2375 snprintf(err_str, sizeof(err_str), "\"success\"");
2377 snprintf(val, sizeof(val), "%d", sen);
2379 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2380 1, strlen(val) + 1);
2382 snprintf(err_str, sizeof(err_str),
2383 "\"cannot configure health sensitivity: %s\"",
2386 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2391 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2393 int rc = LUSTRE_CFG_RC_NO_ERR;
2394 char err_str[LNET_MAX_STR_LEN];
2395 char val[LNET_MAX_STR_LEN];
2397 snprintf(err_str, sizeof(err_str), "\"success\"");
2399 snprintf(val, sizeof(val), "%d", timeout);
2401 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2402 1, strlen(val) + 1);
2404 snprintf(err_str, sizeof(err_str),
2405 "\"cannot configure transaction timeout: %s\"",
2408 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2413 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2415 int rc = LUSTRE_CFG_RC_NO_ERR;
2416 char err_str[LNET_MAX_STR_LEN];
2417 char val[LNET_MAX_STR_LEN];
2419 snprintf(err_str, sizeof(err_str), "\"success\"");
2421 snprintf(val, sizeof(val), "%d", count);
2423 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2424 1, strlen(val) + 1);
2426 snprintf(err_str, sizeof(err_str),
2427 "\"cannot configure retry count: %s\"",
2430 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2435 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2437 int rc = LUSTRE_CFG_RC_NO_ERR;
2438 char err_str[LNET_MAX_STR_LEN];
2439 char val[LNET_MAX_STR_LEN];
2441 snprintf(err_str, sizeof(err_str), "\"success\"");
2443 snprintf(val, sizeof(val), "%d", max);
2445 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2446 1, strlen(val) + 1);
2448 snprintf(err_str, sizeof(err_str),
2449 "\"cannot configure max interfaces: %s\"",
2452 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2457 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2459 int rc = LUSTRE_CFG_RC_NO_ERR;
2460 char err_str[LNET_MAX_STR_LEN];
2461 char val[LNET_MAX_STR_LEN];
2463 snprintf(err_str, sizeof(err_str), "\"success\"");
2465 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2467 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2468 1, strlen(val) + 1);
2470 snprintf(err_str, sizeof(err_str),
2471 "\"cannot configure discovery: %s\"",
2474 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2480 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2481 struct cYAML **err_rc)
2483 int rc = LUSTRE_CFG_RC_NO_ERR;
2484 char err_str[LNET_MAX_STR_LEN];
2485 char val[LNET_MAX_STR_LEN];
2487 snprintf(err_str, sizeof(err_str), "\"success\"");
2489 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2491 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2492 1, strlen(val) + 1);
2494 snprintf(err_str, sizeof(err_str),
2495 "\"cannot configure drop asym route: %s\"",
2498 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2505 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2507 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2508 "numa_range", seq_no, err_rc);
2511 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2512 struct cYAML **err_rc)
2514 struct lnet_ioctl_config_data data;
2515 int rc = LUSTRE_CFG_RC_NO_ERR;
2516 char err_str[LNET_MAX_STR_LEN];
2518 snprintf(err_str, sizeof(err_str), "\"success\"");
2520 /* -1 indicates to ignore changes to this field */
2521 if (tiny < -1 || small < -1 || large < -1) {
2524 "\"tiny, small and large must be >= 0\"");
2525 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2529 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2530 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2531 data.cfg_config_u.cfg_buffers.buf_small = small;
2532 data.cfg_config_u.cfg_buffers.buf_large = large;
2534 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2539 "\"cannot configure buffers: %s\"", strerror(errno));
2544 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2549 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2550 struct cYAML **err_rc, bool backup)
2552 struct lnet_ioctl_config_data *data;
2553 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2554 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2557 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2558 int buf_count[LNET_NRBPOOLS] = {0};
2559 struct cYAML *root = NULL, *pools_node = NULL,
2560 *type_node = NULL, *item = NULL, *cpt = NULL,
2561 *first_seq = NULL, *buffers = NULL;
2563 char err_str[LNET_MAX_STR_LEN];
2564 char node_name[LNET_MAX_STR_LEN];
2567 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2569 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2573 data = (struct lnet_ioctl_config_data *)buf;
2575 root = cYAML_create_object(NULL, NULL);
2580 pools_node = cYAML_create_object(root, "routing");
2582 pools_node = cYAML_create_seq(root, "routing");
2583 if (pools_node == NULL)
2587 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2588 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2589 sizeof(struct lnet_ioctl_pool_cfg);
2590 data->cfg_count = i;
2592 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2600 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2603 goto calculate_buffers;
2605 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2606 item = cYAML_create_seq_item(pools_node);
2610 if (first_seq == NULL)
2613 cpt = cYAML_create_object(item, node_name);
2618 /* create the tree and print */
2619 for (j = 0; j < LNET_NRBPOOLS; j++) {
2621 type_node = cYAML_create_object(cpt, pools[j]);
2622 if (type_node == NULL)
2626 cYAML_create_number(type_node, "npages",
2627 pool_cfg->pl_pools[j].pl_npages)
2631 cYAML_create_number(type_node, "nbuffers",
2632 pool_cfg->pl_pools[j].
2633 pl_nbuffers) == NULL)
2636 cYAML_create_number(type_node, "credits",
2637 pool_cfg->pl_pools[j].
2638 pl_credits) == NULL)
2641 cYAML_create_number(type_node, "mincredits",
2642 pool_cfg->pl_pools[j].
2643 pl_mincredits) == NULL)
2645 /* keep track of the total count for each of the
2646 * tiny, small and large buffers */
2647 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2651 if (pool_cfg != NULL) {
2653 if (cYAML_create_number(pools_node, "enable",
2654 pool_cfg->pl_routing) ==
2658 goto add_buffer_section;
2661 item = cYAML_create_seq_item(pools_node);
2665 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2671 /* create a buffers entry in the show. This is necessary so that
2672 * if the YAML output is used to configure a node, the buffer
2673 * configuration takes hold */
2674 buffers = cYAML_create_object(root, "buffers");
2675 if (buffers == NULL)
2678 for (i = 0; i < LNET_NRBPOOLS; i++) {
2679 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2683 if (show_rc == NULL)
2684 cYAML_print_tree(root);
2686 if (l_errno != ENOENT) {
2689 "\"cannot get routing information: %s\"",
2694 rc = LUSTRE_CFG_RC_NO_ERR;
2696 snprintf(err_str, sizeof(err_str), "\"success\"");
2697 rc = LUSTRE_CFG_RC_NO_ERR;
2701 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2702 cYAML_free_tree(root);
2703 } else if (show_rc != NULL && *show_rc != NULL) {
2704 struct cYAML *routing_node;
2705 /* there should exist only one routing block and one
2706 * buffers block. If there already exists a previous one
2707 * then don't add another */
2708 routing_node = cYAML_get_object_item(*show_rc, "routing");
2709 if (routing_node == NULL) {
2710 cYAML_insert_sibling((*show_rc)->cy_child,
2714 cYAML_free_tree(root);
2720 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2725 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2726 struct cYAML **show_rc, struct cYAML **err_rc,
2730 * TODO: This function is changing in a future patch to accommodate
2731 * PEER_LIST and proper filtering on any nid of the peer
2733 struct lnet_ioctl_peer_cfg peer_info;
2734 struct lnet_peer_ni_credit_info *lpni_cri;
2735 struct lnet_ioctl_element_stats *lpni_stats;
2736 struct lnet_ioctl_element_msg_stats *msg_stats;
2737 struct lnet_ioctl_peer_ni_hstats *hstats;
2739 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2744 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2745 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2746 *msg_statistics = NULL, *statistics = NULL,
2748 char err_str[LNET_MAX_STR_LEN];
2749 struct lnet_process_id *list = NULL;
2754 snprintf(err_str, sizeof(err_str),
2755 "\"out of memory\"");
2757 /* create struct cYAML root object */
2758 root = cYAML_create_object(NULL, NULL);
2762 peer_root = cYAML_create_seq(root, "peer");
2763 if (peer_root == NULL)
2767 size = count * sizeof(struct lnet_process_id);
2768 list = malloc(size);
2774 list[0].nid = libcfs_str2nid(knid);
2778 memset(&peer_info, 0, sizeof(peer_info));
2779 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2780 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2781 peer_info.prcfg_size = size;
2782 peer_info.prcfg_bulk = list;
2785 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2787 count = peer_info.prcfg_count;
2791 if (l_errno != E2BIG) {
2794 "\"cannot get peer list: %s\"",
2800 size = peer_info.prcfg_size;
2801 list = malloc(size);
2810 data = malloc(size);
2816 for (i = 0; i < count; i++) {
2818 memset(&peer_info, 0, sizeof(peer_info));
2819 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2820 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2821 peer_info.prcfg_prim_nid = list[i].nid;
2822 peer_info.prcfg_size = size;
2823 peer_info.prcfg_bulk = data;
2826 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2831 if (l_errno != E2BIG) {
2834 "\"cannot get peer information: %s\"",
2840 size = peer_info.prcfg_size;
2841 data = malloc(size);
2849 peer = cYAML_create_seq_item(peer_root);
2853 if (first_seq == NULL)
2856 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2857 if (cYAML_create_string(peer, "primary nid",
2858 libcfs_nid2str(pnid))
2861 if (cYAML_create_string(peer, "Multi-Rail",
2862 peer_info.prcfg_mr ? "True" : "False")
2866 * print out the state of the peer only if details are
2871 cYAML_create_number(peer, "peer state",
2872 peer_info.prcfg_state)
2877 tmp = cYAML_create_seq(peer, "peer ni");
2882 for (j = 0; j < peer_info.prcfg_count; j++) {
2884 lpni_cri = (void*)nidp + sizeof(nidp);
2885 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2886 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2887 hstats = (void *)msg_stats + sizeof(*msg_stats);
2888 lpni_data = (void *)hstats + sizeof(*hstats);
2890 peer_ni = cYAML_create_seq_item(tmp);
2891 if (peer_ni == NULL)
2894 if (cYAML_create_string(peer_ni, "nid",
2895 libcfs_nid2str(*nidp))
2902 if (cYAML_create_string(peer_ni, "state",
2903 lpni_cri->cr_aliveness)
2910 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2911 lpni_cri->cr_ni_peer_tx_credits)
2915 if (cYAML_create_number(peer_ni, "available_tx_credits",
2916 lpni_cri->cr_peer_tx_credits)
2920 if (cYAML_create_number(peer_ni, "min_tx_credits",
2921 lpni_cri->cr_peer_min_tx_credits)
2925 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2926 lpni_cri->cr_peer_tx_qnob)
2930 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2931 lpni_cri->cr_peer_rtr_credits)
2935 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2936 lpni_cri->cr_peer_min_rtr_credits)
2940 if (cYAML_create_number(peer_ni, "refcount",
2941 lpni_cri->cr_refcount) == NULL)
2944 statistics = cYAML_create_object(peer_ni, "statistics");
2945 if (statistics == NULL)
2948 if (cYAML_create_number(statistics, "send_count",
2949 lpni_stats->iel_send_count)
2953 if (cYAML_create_number(statistics, "recv_count",
2954 lpni_stats->iel_recv_count)
2958 if (cYAML_create_number(statistics, "drop_count",
2959 lpni_stats->iel_drop_count)
2966 for (k = 0; k < 3; k++) {
2967 struct lnet_ioctl_comm_count *counts;
2969 msg_statistics = cYAML_create_object(peer_ni,
2970 (char *) gmsg_stat_names[k]);
2971 if (msg_statistics == NULL)
2974 counts = get_counts(msg_stats, k);
2978 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2983 yhstats = cYAML_create_object(peer_ni, "health stats");
2986 if (cYAML_create_number(yhstats, "health value",
2987 hstats->hlpni_health_value)
2990 if (cYAML_create_number(yhstats, "dropped",
2991 hstats->hlpni_remote_dropped)
2994 if (cYAML_create_number(yhstats, "timeout",
2995 hstats->hlpni_remote_timeout)
2998 if (cYAML_create_number(yhstats, "error",
2999 hstats->hlpni_remote_error)
3002 if (cYAML_create_number(yhstats, "network timeout",
3003 hstats->hlpni_network_timeout)
3009 /* print output iff show_rc is not provided */
3010 if (show_rc == NULL)
3011 cYAML_print_tree(root);
3013 snprintf(err_str, sizeof(err_str), "\"success\"");
3014 rc = LUSTRE_CFG_RC_NO_ERR;
3019 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3020 cYAML_free_tree(root);
3021 } else if (show_rc != NULL && *show_rc != NULL) {
3022 struct cYAML *show_node;
3023 /* find the peer node, if one doesn't exist then
3024 * insert one. Otherwise add to the one there
3026 show_node = cYAML_get_object_item(*show_rc,
3028 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3029 cYAML_insert_child(show_node, first_seq);
3032 } else if (show_node == NULL) {
3033 cYAML_insert_sibling((*show_rc)->cy_child,
3037 cYAML_free_tree(root);
3043 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3049 int lustre_lnet_list_peer(int seq_no,
3050 struct cYAML **show_rc, struct cYAML **err_rc)
3052 struct lnet_ioctl_peer_cfg peer_info;
3053 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3058 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3059 char err_str[LNET_MAX_STR_LEN];
3060 struct lnet_process_id *list = NULL;
3062 snprintf(err_str, sizeof(err_str),
3063 "\"out of memory\"");
3065 memset(&peer_info, 0, sizeof(peer_info));
3067 /* create struct cYAML root object */
3068 root = cYAML_create_object(NULL, NULL);
3072 list_root = cYAML_create_seq(root, "peer list");
3073 if (list_root == NULL)
3077 size = count * sizeof(struct lnet_process_id);
3078 list = malloc(size);
3084 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3085 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3086 peer_info.prcfg_size = size;
3087 peer_info.prcfg_bulk = list;
3090 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3091 count = peer_info.prcfg_count;
3095 if (l_errno != E2BIG) {
3098 "\"cannot get peer list: %s\"",
3104 size = peer_info.prcfg_size;
3105 list = malloc(size);
3112 /* count is now the actual number of ids in the list. */
3113 for (i = 0; i < count; i++) {
3114 if (cYAML_create_string(list_root, "nid",
3115 libcfs_nid2str(list[i].nid))
3120 /* print output iff show_rc is not provided */
3121 if (show_rc == NULL)
3122 cYAML_print_tree(root);
3124 snprintf(err_str, sizeof(err_str), "\"success\"");
3125 rc = LUSTRE_CFG_RC_NO_ERR;
3130 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3131 cYAML_free_tree(root);
3132 } else if (show_rc != NULL && *show_rc != NULL) {
3133 struct cYAML *show_node;
3134 /* find the peer node, if one doesn't exist then
3135 * insert one. Otherwise add to the one there
3137 show_node = cYAML_get_object_item(*show_rc,
3139 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3140 cYAML_insert_child(show_node, first_seq);
3143 } else if (show_node == NULL) {
3144 cYAML_insert_sibling((*show_rc)->cy_child,
3148 cYAML_free_tree(root);
3154 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3160 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3163 struct cYAML *show_node;
3165 show_node = cYAML_get_object_item(show_rc, "global");
3166 if (show_node != NULL)
3167 cYAML_insert_sibling(show_node->cy_child,
3170 cYAML_insert_sibling(show_rc->cy_child,
3175 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3176 char *name, __u64 value,
3177 struct cYAML **show_rc,
3178 struct cYAML **err_rc, int err)
3180 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3181 struct cYAML *root = NULL, *global = NULL;
3188 root = cYAML_create_object(NULL, NULL);
3192 global = cYAML_create_object(root, "global");
3196 if (cYAML_create_number(global, name,
3200 if (show_rc == NULL)
3201 cYAML_print_tree(root);
3203 snprintf(err_str, err_len, "\"success\"");
3205 rc = LUSTRE_CFG_RC_NO_ERR;
3208 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3209 cYAML_free_tree(root);
3210 } else if (show_rc != NULL && *show_rc != NULL) {
3211 add_to_global(*show_rc, global, root);
3216 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3221 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3222 struct cYAML **show_rc,
3223 struct cYAML **err_rc)
3225 struct lnet_ioctl_set_value data;
3228 char err_str[LNET_MAX_STR_LEN];
3230 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3232 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3234 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3239 "\"cannot get %s: %s\"",
3240 name, strerror(l_errno));
3243 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3244 data.sv_value, show_rc, err_rc, l_errno);
3247 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3248 struct cYAML **err_rc)
3250 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3251 char val[LNET_MAX_STR_LEN];
3252 int intrv = -1, l_errno = 0;
3253 char err_str[LNET_MAX_STR_LEN];
3255 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3257 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3261 snprintf(err_str, sizeof(err_str),
3262 "\"cannot get recovery interval: %d\"", rc);
3267 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3268 "recovery_interval", intrv, show_rc,
3272 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3273 struct cYAML **err_rc)
3275 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3276 char val[LNET_MAX_STR_LEN];
3277 int sen = -1, l_errno = 0;
3278 char err_str[LNET_MAX_STR_LEN];
3280 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3282 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3286 snprintf(err_str, sizeof(err_str),
3287 "\"cannot get health sensitivity: %d\"", rc);
3292 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3293 "health_sensitivity", sen, show_rc,
3297 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3298 struct cYAML **err_rc)
3300 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3301 char val[LNET_MAX_STR_LEN];
3302 int sen = -1, l_errno = 0;
3303 char err_str[LNET_MAX_STR_LEN];
3305 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3307 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3311 snprintf(err_str, sizeof(err_str),
3312 "\"cannot get router sensitivity percentage: %d\"", rc);
3317 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3318 "router_sensitivity", sen, show_rc,
3322 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3323 struct cYAML **err_rc)
3325 char val[LNET_MAX_STR_LEN];
3326 char err_str[LNET_MAX_STR_LEN];
3333 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3335 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3338 snprintf(err_str, sizeof(err_str),
3339 "\"cannot get LND timeout: %d\"", rc);
3340 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3341 "lnd_timeout", lnd_to, show_rc,
3345 fd = open(path.gl_pathv[0], O_RDONLY);
3348 snprintf(err_str, sizeof(err_str),
3349 "\"error opening %s\"", path.gl_pathv[0]);
3353 rc = read(fd, val, sizeof(val));
3360 snprintf(err_str, sizeof(err_str),
3361 "\"error reading %s\"", path.gl_pathv[0]);
3368 cfs_free_param_data(&path);
3370 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3371 "lnd_timeout", lnd_to, show_rc,
3375 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3376 struct cYAML **err_rc)
3378 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3379 char val[LNET_MAX_STR_LEN];
3380 int tto = -1, l_errno = 0;
3381 char err_str[LNET_MAX_STR_LEN];
3383 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3385 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3389 snprintf(err_str, sizeof(err_str),
3390 "\"cannot get transaction timeout: %d\"", rc);
3395 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3396 "transaction_timeout", tto, show_rc,
3400 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3401 struct cYAML **err_rc)
3403 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3404 char val[LNET_MAX_STR_LEN];
3405 int retry_count = -1, l_errno = 0;
3406 char err_str[LNET_MAX_STR_LEN];
3408 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3410 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3414 snprintf(err_str, sizeof(err_str),
3415 "\"cannot get retry count: %d\"", rc);
3417 retry_count = atoi(val);
3420 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3421 "retry_count", retry_count, show_rc,
3425 int lustre_lnet_calc_service_id(__u64 *service_id)
3427 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3428 char val[LNET_MAX_STR_LEN];
3429 int service_port = -1, l_errno = 0;
3431 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3435 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3436 strerror(l_errno), -l_errno);
3439 service_port = atoi(val);
3442 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3444 return LUSTRE_CFG_RC_NO_ERR;
3447 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3448 struct cYAML **show_rc, struct cYAML **err_rc)
3450 struct lnet_ioctl_recovery_list nid_list;
3451 struct cYAML *root = NULL, *nids = NULL;
3453 char err_str[LNET_MAX_STR_LEN];
3455 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3457 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3458 nid_list.rlst_type = type;
3460 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3466 if (nid_list.rlst_num_nids == 0)
3469 root = cYAML_create_object(NULL, NULL);
3473 nids = cYAML_create_object(root, name);
3479 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3480 char nidenum[LNET_MAX_STR_LEN];
3481 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3482 if (!cYAML_create_string(nids, nidenum,
3483 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3487 snprintf(err_str, sizeof(err_str), "success\n");
3492 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3493 cYAML_free_tree(root);
3494 } else if (show_rc != NULL && *show_rc != NULL) {
3495 struct cYAML *show_node;
3496 /* find the net node, if one doesn't exist
3497 * then insert one. Otherwise add to the one there
3499 show_node = cYAML_get_object_item(*show_rc, name);
3500 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3501 cYAML_insert_child(show_node, nids);
3504 } else if (show_node == NULL) {
3505 cYAML_insert_sibling((*show_rc)->cy_child,
3509 cYAML_free_tree(root);
3515 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3520 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3521 struct cYAML **err_rc)
3523 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3524 seq_no, show_rc, err_rc);
3527 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3528 struct cYAML **err_rc)
3530 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3531 seq_no, show_rc, err_rc);
3534 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3535 struct cYAML **err_rc)
3537 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3538 char val[LNET_MAX_STR_LEN];
3539 int max_intf = -1, l_errno = 0;
3540 char err_str[LNET_MAX_STR_LEN];
3542 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3544 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3548 snprintf(err_str, sizeof(err_str),
3549 "\"cannot get max interfaces: %d\"", rc);
3551 max_intf = atoi(val);
3554 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3555 "max_intf", max_intf, show_rc,
3559 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3560 struct cYAML **err_rc)
3562 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3563 char val[LNET_MAX_STR_LEN];
3564 int discovery = -1, l_errno = 0;
3565 char err_str[LNET_MAX_STR_LEN];
3567 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3569 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3573 snprintf(err_str, sizeof(err_str),
3574 "\"cannot get discovery setting: %d\"", rc);
3577 * The kernel stores a discovery disabled value. User space
3578 * shows whether discovery is enabled. So the value must be
3581 discovery = !atoi(val);
3584 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3585 "discovery", discovery, show_rc,
3589 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3590 struct cYAML **err_rc)
3592 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3593 char val[LNET_MAX_STR_LEN];
3594 int drop_asym_route = -1, l_errno = 0;
3595 char err_str[LNET_MAX_STR_LEN];
3597 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3599 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3603 snprintf(err_str, sizeof(err_str),
3604 "\"cannot get drop asym route setting: %d\"", rc);
3606 drop_asym_route = atoi(val);
3609 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3610 "drop_asym_route", drop_asym_route,
3611 show_rc, err_rc, l_errno);
3614 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3615 struct cYAML **err_rc)
3617 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3618 "numa_range", show_rc, err_rc);
3621 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3622 struct cYAML **err_rc)
3624 struct lnet_ioctl_lnet_stats data;
3625 struct lnet_counters *cntrs;
3628 char err_str[LNET_MAX_STR_LEN];
3629 struct cYAML *root = NULL, *stats = NULL;
3631 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3633 LIBCFS_IOC_INIT_V2(data, st_hdr);
3635 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3640 "\"cannot get lnet statistics: %s\"",
3646 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3648 cntrs = &data.st_cntrs;
3650 root = cYAML_create_object(NULL, NULL);
3654 stats = cYAML_create_object(root, "statistics");
3658 if (!cYAML_create_number(stats, "msgs_alloc",
3659 cntrs->lct_common.lcc_msgs_alloc))
3662 if (!cYAML_create_number(stats, "msgs_max",
3663 cntrs->lct_common.lcc_msgs_max))
3666 if (!cYAML_create_number(stats, "rst_alloc",
3667 cntrs->lct_health.lch_rst_alloc))
3670 if (!cYAML_create_number(stats, "errors",
3671 cntrs->lct_common.lcc_errors))
3674 if (!cYAML_create_number(stats, "send_count",
3675 cntrs->lct_common.lcc_send_count))
3678 if (!cYAML_create_number(stats, "resend_count",
3679 cntrs->lct_health.lch_resend_count))
3682 if (!cYAML_create_number(stats, "response_timeout_count",
3683 cntrs->lct_health.lch_response_timeout_count))
3686 if (!cYAML_create_number(stats, "local_interrupt_count",
3687 cntrs->lct_health.lch_local_interrupt_count))
3690 if (!cYAML_create_number(stats, "local_dropped_count",
3691 cntrs->lct_health.lch_local_dropped_count))
3694 if (!cYAML_create_number(stats, "local_aborted_count",
3695 cntrs->lct_health.lch_local_aborted_count))
3698 if (!cYAML_create_number(stats, "local_no_route_count",
3699 cntrs->lct_health.lch_local_no_route_count))
3702 if (!cYAML_create_number(stats, "local_timeout_count",
3703 cntrs->lct_health.lch_local_timeout_count))
3706 if (!cYAML_create_number(stats, "local_error_count",
3707 cntrs->lct_health.lch_local_error_count))
3710 if (!cYAML_create_number(stats, "remote_dropped_count",
3711 cntrs->lct_health.lch_remote_dropped_count))
3714 if (!cYAML_create_number(stats, "remote_error_count",
3715 cntrs->lct_health.lch_remote_error_count))
3718 if (!cYAML_create_number(stats, "remote_timeout_count",
3719 cntrs->lct_health.lch_remote_timeout_count))
3722 if (!cYAML_create_number(stats, "network_timeout_count",
3723 cntrs->lct_health.lch_network_timeout_count))
3726 if (!cYAML_create_number(stats, "recv_count",
3727 cntrs->lct_common.lcc_recv_count))
3730 if (!cYAML_create_number(stats, "route_count",
3731 cntrs->lct_common.lcc_route_count))
3734 if (!cYAML_create_number(stats, "drop_count",
3735 cntrs->lct_common.lcc_drop_count))
3738 if (!cYAML_create_number(stats, "send_length",
3739 cntrs->lct_common.lcc_send_length))
3742 if (!cYAML_create_number(stats, "recv_length",
3743 cntrs->lct_common.lcc_recv_length))
3746 if (!cYAML_create_number(stats, "route_length",
3747 cntrs->lct_common.lcc_route_length))
3750 if (!cYAML_create_number(stats, "drop_length",
3751 cntrs->lct_common.lcc_drop_length))
3755 cYAML_print_tree(root);
3757 snprintf(err_str, sizeof(err_str), "\"success\"");
3758 rc = LUSTRE_CFG_RC_NO_ERR;
3760 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3761 cYAML_free_tree(root);
3762 } else if (show_rc != NULL && *show_rc != NULL) {
3763 cYAML_insert_sibling((*show_rc)->cy_child,
3770 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3775 typedef int (*cmd_handler_t)(struct cYAML *tree,
3776 struct cYAML **show_rc,
3777 struct cYAML **err_rc);
3779 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3780 struct cYAML **err_rc)
3782 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3784 net = cYAML_get_object_item(tree, "net");
3785 gw = cYAML_get_object_item(tree, "gateway");
3786 hop = cYAML_get_object_item(tree, "hop");
3787 prio = cYAML_get_object_item(tree, "priority");
3788 sen = cYAML_get_object_item(tree, "health_sensitivity");
3789 seq_no = cYAML_get_object_item(tree, "seq_no");
3791 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3792 (gw) ? gw->cy_valuestring : NULL,
3793 (hop) ? hop->cy_valueint : -1,
3794 (prio) ? prio->cy_valueint : -1,
3795 (sen) ? sen->cy_valueint : -1,
3796 (seq_no) ? seq_no->cy_valueint : -1,
3802 * 0: <intf_name>['['<expr>']']
3803 * 1: <intf_name>['['<expr>']']
3805 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3806 struct lnet_dlc_network_descr *nw_descr)
3808 struct cYAML *child = NULL;
3809 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3810 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3812 if (intf_tree == NULL || nw_descr == NULL)
3813 return LUSTRE_CFG_RC_BAD_PARAM;
3815 /* now grab all the interfaces and their cpts */
3816 child = intf_tree->cy_child;
3817 while (child != NULL) {
3818 if (child->cy_valuestring == NULL) {
3819 child = child->cy_next;
3823 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3826 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3827 child->cy_valuestring,
3828 strlen(child->cy_valuestring));
3829 if (rc != LUSTRE_CFG_RC_NO_ERR)
3833 child = child->cy_next;
3837 return LUSTRE_CFG_RC_MISSING_PARAM;
3842 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3844 list_del(&intf_descr->intf_on_network);
3845 free_intf_descr(intf_descr);
3852 yaml_extract_cmn_tunables(struct cYAML *tree,
3853 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3854 struct cfs_expr_list **global_cpts)
3856 struct cYAML *tun, *item, *smp;
3859 tun = cYAML_get_object_item(tree, "tunables");
3861 item = cYAML_get_object_item(tun, "peer_timeout");
3863 tunables->lct_peer_timeout = item->cy_valueint;
3864 item = cYAML_get_object_item(tun, "peer_credits");
3866 tunables->lct_peer_tx_credits = item->cy_valueint;
3867 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3869 tunables->lct_peer_rtr_credits = item->cy_valueint;
3870 item = cYAML_get_object_item(tun, "credits");
3872 tunables->lct_max_tx_credits = item->cy_valueint;
3873 smp = cYAML_get_object_item(tun, "CPT");
3875 rc = cfs_expr_list_parse(smp->cy_valuestring,
3876 strlen(smp->cy_valuestring),
3877 0, UINT_MAX, global_cpts);
3879 *global_cpts = NULL;
3889 yaml_extract_tunables(struct cYAML *tree,
3890 struct lnet_ioctl_config_lnd_tunables *tunables,
3891 struct cfs_expr_list **global_cpts,
3896 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3902 lustre_yaml_extract_lnd_tunables(tree, net_type,
3910 * - net type: <net>[<NUM>]
3912 * - nid: <ip>@<net>[<NUM>]
3915 * 0: <intf_name>['['<expr>']']
3916 * 1: <intf_name>['['<expr>']']
3918 * peer_timeout: <NUM>
3919 * peer_credits: <NUM>
3920 * peer_buffer_credits: <NUM>
3923 * peercredits_hiw: <NUM>
3924 * map_on_demand: <NUM>
3925 * concurrent_sends: <NUM>
3926 * fmr_pool_size: <NUM>
3927 * fmr_flush_trigger: <NUM>
3930 * At least one interface is required. If no interfaces are provided the
3931 * network interface can not be configured.
3933 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3934 struct cYAML **err_rc)
3936 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3938 int num_entries = 0, rc;
3939 struct lnet_dlc_network_descr nw_descr;
3940 struct cfs_expr_list *global_cpts = NULL;
3941 struct lnet_ioctl_config_lnd_tunables tunables;
3944 memset(&tunables, 0, sizeof(tunables));
3946 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3947 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3949 ip2net = cYAML_get_object_item(tree, "ip2net");
3950 net = cYAML_get_object_item(tree, "net type");
3952 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3954 nw_descr.nw_id = LOLND;
3957 * if neither net nor ip2nets are present, then we can not
3958 * configure the network.
3960 if (!net && !ip2net)
3961 return LUSTRE_CFG_RC_MISSING_PARAM;
3963 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3964 if (local_nis == NULL)
3965 return LUSTRE_CFG_RC_MISSING_PARAM;
3967 if (!cYAML_is_sequence(local_nis))
3968 return LUSTRE_CFG_RC_BAD_PARAM;
3970 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3971 intf = cYAML_get_object_item(item, "interfaces");
3974 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3975 if (num_entries <= 0) {
3976 cYAML_build_error(num_entries, -1, "ni", "add",
3977 "bad interface list",
3979 return LUSTRE_CFG_RC_BAD_PARAM;
3983 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3984 LNET_NETTYP(nw_descr.nw_id));
3985 seq_no = cYAML_get_object_item(tree, "seq_no");
3987 rc = lustre_lnet_config_ni(&nw_descr,
3989 (ip2net) ? ip2net->cy_valuestring : NULL,
3990 (found) ? &tunables: NULL,
3991 (seq_no) ? seq_no->cy_valueint : -1,
3994 if (global_cpts != NULL)
3995 cfs_expr_list_free(global_cpts);
4002 * - net-spec: <tcp|o2ib|gni>[NUM]
4004 * 0: <intf name>['['<expr>']']
4005 * 1: <intf name>['['<expr>']']
4007 * 0: <expr.expr.expr.expr>
4008 * 1: <expr.expr.expr.expr>
4010 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4011 struct cYAML **show_rc,
4012 struct cYAML **err_rc)
4014 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4016 struct lustre_lnet_ip2nets ip2nets;
4017 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4019 int rc = LUSTRE_CFG_RC_NO_ERR;
4020 struct cfs_expr_list *global_cpts = NULL;
4021 struct cfs_expr_list *el, *el_tmp;
4022 struct lnet_ioctl_config_lnd_tunables tunables;
4023 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4026 memset(&tunables, 0, sizeof(tunables));
4028 /* initialize all lists */
4029 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4030 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4031 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4033 net = cYAML_get_object_item(tree, "net-spec");
4035 return LUSTRE_CFG_RC_BAD_PARAM;
4037 if (net != NULL && net->cy_valuestring == NULL)
4038 return LUSTRE_CFG_RC_BAD_PARAM;
4040 /* assign the network id */
4041 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4042 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
4043 return LUSTRE_CFG_RC_BAD_PARAM;
4045 seq_no = cYAML_get_object_item(tree, "seq_no");
4047 intf = cYAML_get_object_item(tree, "interfaces");
4049 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4051 return LUSTRE_CFG_RC_BAD_PARAM;
4054 ip_range = cYAML_get_object_item(tree, "ip-range");
4055 if (ip_range != NULL) {
4056 item = ip_range->cy_child;
4057 while (item != NULL) {
4058 if (item->cy_valuestring == NULL) {
4059 item = item->cy_next;
4063 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4064 item->cy_valuestring);
4066 if (rc != LUSTRE_CFG_RC_NO_ERR)
4069 item = item->cy_next;
4073 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4074 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4076 rc = lustre_lnet_config_ip2nets(&ip2nets,
4077 (found) ? &tunables : NULL,
4079 (seq_no) ? seq_no->cy_valueint : -1,
4083 * don't stop because there was no match. Continue processing the
4084 * rest of the rules. If non-match then nothing is configured
4086 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4087 rc = LUSTRE_CFG_RC_NO_ERR;
4089 list_for_each_entry_safe(intf_descr, intf_tmp,
4090 &ip2nets.ip2nets_net.nw_intflist,
4092 list_del(&intf_descr->intf_on_network);
4093 free_intf_descr(intf_descr);
4096 list_for_each_entry_safe(ip_range_descr, tmp,
4097 &ip2nets.ip2nets_ip_ranges,
4099 list_del(&ip_range_descr->ipr_entry);
4100 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4102 list_del(&el->el_link);
4103 cfs_expr_list_free(el);
4105 free(ip_range_descr);
4111 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4112 struct cYAML **err_rc)
4114 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4116 int num_entries, rc;
4117 struct lnet_dlc_network_descr nw_descr;
4119 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4120 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4122 net = cYAML_get_object_item(tree, "net type");
4124 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4126 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4127 if (local_nis == NULL)
4128 return LUSTRE_CFG_RC_MISSING_PARAM;
4130 if (!cYAML_is_sequence(local_nis))
4131 return LUSTRE_CFG_RC_BAD_PARAM;
4133 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4134 intf = cYAML_get_object_item(item, "interfaces");
4137 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4138 if (num_entries <= 0) {
4139 cYAML_build_error(num_entries, -1, "ni", "add",
4140 "bad interface list",
4142 return LUSTRE_CFG_RC_BAD_PARAM;
4146 seq_no = cYAML_get_object_item(tree, "seq_no");
4148 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4149 (seq_no) ? seq_no->cy_valueint : -1,
4155 /* Create a nidstring parseable by the nidstrings library from the nid
4156 * information encoded in the CYAML structure.
4157 * NOTE: Caller must free memory allocated to nidstr
4159 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4160 char *prim_nid, int cmd)
4162 int num_strs = 0, rc;
4163 size_t buf_size, buf_pos, nidstr_len = 0;
4165 struct cYAML *child = NULL, *entry = NULL;
4167 if (cYAML_is_sequence(nids_entry)) {
4168 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4169 entry = cYAML_get_object_item(child, "nid");
4170 /* don't count an empty entry */
4171 if (!entry || !entry->cy_valuestring)
4175 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4176 if (cmd == LNETCTL_DEL_CMD) {
4178 * primary nid is present in the list of
4179 * nids so that means we want to delete
4180 * the entire peer, so no need to go
4181 * further. Just delete the entire peer.
4183 return LUSTRE_CFG_RC_NO_ERR;
4190 * + 1 for the space separating each string, and
4191 * accounts for the terminating null char
4193 nidstr_len += strlen(entry->cy_valuestring) + 1;
4198 if (num_strs == 0 && !prim_nid)
4199 return LUSTRE_CFG_RC_MISSING_PARAM;
4200 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4201 return LUSTRE_CFG_RC_NO_ERR;
4203 buffer = malloc(nidstr_len);
4205 return LUSTRE_CFG_RC_OUT_OF_MEM;
4207 /* now grab all the nids */
4210 buf_size = nidstr_len;
4212 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4213 entry = cYAML_get_object_item(child, "nid");
4214 if (!entry || !entry->cy_valuestring)
4218 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4222 rc = snprintf(buffer + buf_pos, buf_size, " ");
4223 buf_pos += (rc < buf_size) ? rc : buf_size;
4224 buf_size = nidstr_len - buf_pos;
4227 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4228 entry->cy_valuestring);
4229 buf_pos += (rc < buf_size) ? rc : buf_size;
4230 buf_size = nidstr_len - buf_pos;
4235 return LUSTRE_CFG_RC_NO_ERR;
4238 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4239 struct cYAML **err_rc, int cmd)
4241 int rc, num_nids = 0, seqn;
4242 bool mr_value = false;
4243 char *nidstr = NULL, *prim_nidstr;
4244 char err_str[LNET_MAX_STR_LEN];
4245 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4246 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4247 lnet_nid_t pnid = LNET_NID_ANY;
4249 seq_no = cYAML_get_object_item(tree, "seq_no");
4250 seqn = seq_no ? seq_no->cy_valueint : -1;
4252 prim_nid = cYAML_get_object_item(tree, "primary nid");
4253 peer_nis = cYAML_get_object_item(tree, "peer ni");
4255 rc = LUSTRE_CFG_RC_BAD_PARAM;
4256 snprintf(err_str, LNET_MAX_STR_LEN,
4257 "\"primary nid\" must be specified");
4261 prim_nidstr = prim_nid->cy_valuestring;
4263 /* if the provided primary NID is bad, no need to go any further */
4264 pnid = libcfs_str2nid(prim_nidstr);
4265 if (pnid == LNET_NID_ANY) {
4266 rc = LUSTRE_CFG_RC_BAD_PARAM;
4267 snprintf(err_str, LNET_MAX_STR_LEN,
4268 "badly formatted primary NID: %s", prim_nidstr);
4272 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4273 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4274 snprintf(err_str, LNET_MAX_STR_LEN,
4275 "No nids defined in YAML block");
4277 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4278 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4280 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4281 snprintf(err_str, LNET_MAX_STR_LEN,
4282 "Unrecognized error %d", rc);
4288 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4289 LNET_MAX_NIDS_PER_PEER,
4297 if (cmd == LNETCTL_ADD_CMD) {
4298 mr = cYAML_get_object_item(tree, "Multi-Rail");
4300 if (mr && mr->cy_valuestring) {
4301 if (strcmp(mr->cy_valuestring, "False") == 0)
4303 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4304 rc = LUSTRE_CFG_RC_BAD_PARAM;
4305 snprintf(err_str, LNET_MAX_STR_LEN,
4306 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4307 mr->cy_valuestring);
4313 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4314 num_nids, mr_value, seqn,
4321 if (rc != LUSTRE_CFG_RC_NO_ERR)
4322 cYAML_build_error(rc, seqn, "peer",
4323 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4329 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4330 struct cYAML **err_rc)
4332 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4335 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4336 struct cYAML **err_rc)
4338 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4341 static int handle_yaml_config_buffers(struct cYAML *tree,
4342 struct cYAML **show_rc,
4343 struct cYAML **err_rc)
4346 struct cYAML *tiny, *small, *large, *seq_no;
4348 tiny = cYAML_get_object_item(tree, "tiny");
4349 small = cYAML_get_object_item(tree, "small");
4350 large = cYAML_get_object_item(tree, "large");
4351 seq_no = cYAML_get_object_item(tree, "seq_no");
4353 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4354 (small) ? small->cy_valueint : -1,
4355 (large) ? large->cy_valueint : -1,
4356 (seq_no) ? seq_no->cy_valueint : -1,
4362 static int handle_yaml_config_routing(struct cYAML *tree,
4363 struct cYAML **show_rc,
4364 struct cYAML **err_rc)
4366 int rc = LUSTRE_CFG_RC_NO_ERR;
4367 struct cYAML *seq_no, *enable;
4369 seq_no = cYAML_get_object_item(tree, "seq_no");
4370 enable = cYAML_get_object_item(tree, "enable");
4373 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4375 seq_no->cy_valueint : -1,
4382 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4383 struct cYAML **err_rc)
4387 struct cYAML *seq_no;
4389 net = cYAML_get_object_item(tree, "net");
4390 gw = cYAML_get_object_item(tree, "gateway");
4391 seq_no = cYAML_get_object_item(tree, "seq_no");
4393 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4394 (gw) ? gw->cy_valuestring : NULL,
4395 (seq_no) ? seq_no->cy_valueint : -1,
4399 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4400 struct cYAML **err_rc)
4402 struct cYAML *seq_no;
4404 seq_no = cYAML_get_object_item(tree, "seq_no");
4406 return lustre_lnet_enable_routing(0, (seq_no) ?
4407 seq_no->cy_valueint : -1,
4411 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4412 struct cYAML **err_rc)
4418 struct cYAML *detail;
4419 struct cYAML *seq_no;
4421 net = cYAML_get_object_item(tree, "net");
4422 gw = cYAML_get_object_item(tree, "gateway");
4423 hop = cYAML_get_object_item(tree, "hop");
4424 prio = cYAML_get_object_item(tree, "priority");
4425 detail = cYAML_get_object_item(tree, "detail");
4426 seq_no = cYAML_get_object_item(tree, "seq_no");
4428 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4429 (gw) ? gw->cy_valuestring : NULL,
4430 (hop) ? hop->cy_valueint : -1,
4431 (prio) ? prio->cy_valueint : -1,
4432 (detail) ? detail->cy_valueint : 0,
4433 (seq_no) ? seq_no->cy_valueint : -1,
4434 show_rc, err_rc, false);
4437 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4438 struct cYAML **err_rc)
4440 struct cYAML *net, *detail, *seq_no;
4442 net = cYAML_get_object_item(tree, "net");
4443 detail = cYAML_get_object_item(tree, "detail");
4444 seq_no = cYAML_get_object_item(tree, "seq_no");
4446 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4447 (detail) ? detail->cy_valueint : 0,
4448 (seq_no) ? seq_no->cy_valueint : -1,
4449 show_rc, err_rc, false);
4452 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4453 struct cYAML **err_rc)
4455 struct cYAML *seq_no;
4457 seq_no = cYAML_get_object_item(tree, "seq_no");
4459 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4460 show_rc, err_rc, false);
4463 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4464 struct cYAML **err_rc)
4466 struct cYAML *seq_no, *nid, *detail;
4468 seq_no = cYAML_get_object_item(tree, "seq_no");
4469 detail = cYAML_get_object_item(tree, "detail");
4470 nid = cYAML_get_object_item(tree, "nid");
4472 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
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_stats(struct cYAML *tree, struct cYAML **show_rc,
4479 struct cYAML **err_rc)
4481 struct cYAML *seq_no;
4483 seq_no = cYAML_get_object_item(tree, "seq_no");
4485 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4489 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4490 struct cYAML **err_rc)
4492 struct cYAML *seq_no, *range;
4494 seq_no = cYAML_get_object_item(tree, "seq_no");
4495 range = cYAML_get_object_item(tree, "range");
4497 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4498 seq_no ? seq_no->cy_valueint : -1,
4502 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4503 struct cYAML **err_rc)
4505 struct cYAML *seq_no;
4507 seq_no = cYAML_get_object_item(tree, "seq_no");
4509 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4513 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4514 struct cYAML **err_rc)
4516 struct cYAML *seq_no;
4518 seq_no = cYAML_get_object_item(tree, "seq_no");
4520 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4524 static int handle_yaml_config_global_settings(struct cYAML *tree,
4525 struct cYAML **show_rc,
4526 struct cYAML **err_rc)
4528 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4529 *sen, *recov, *rsen, *drop_asym_route;
4532 seq_no = cYAML_get_object_item(tree, "seq_no");
4533 max_intf = cYAML_get_object_item(tree, "max_intf");
4535 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4536 seq_no ? seq_no->cy_valueint
4540 numa = cYAML_get_object_item(tree, "numa_range");
4542 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4543 seq_no ? seq_no->cy_valueint
4547 discovery = cYAML_get_object_item(tree, "discovery");
4549 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4550 seq_no ? seq_no->cy_valueint
4554 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4555 if (drop_asym_route)
4556 rc = lustre_lnet_config_drop_asym_route(
4557 drop_asym_route->cy_valueint,
4558 seq_no ? seq_no->cy_valueint : -1,
4561 retry = cYAML_get_object_item(tree, "retry_count");
4563 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4564 seq_no ? seq_no->cy_valueint
4568 tto = cYAML_get_object_item(tree, "transaction_timeout");
4570 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4571 seq_no ? seq_no->cy_valueint
4575 sen = cYAML_get_object_item(tree, "health_sensitivity");
4577 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4578 seq_no ? seq_no->cy_valueint
4582 recov = cYAML_get_object_item(tree, "recovery_interval");
4584 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4585 seq_no ? seq_no->cy_valueint
4589 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4591 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4592 seq_no ? seq_no->cy_valueint
4599 static int handle_yaml_del_global_settings(struct cYAML *tree,
4600 struct cYAML **show_rc,
4601 struct cYAML **err_rc)
4603 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4606 seq_no = cYAML_get_object_item(tree, "seq_no");
4607 max_intf = cYAML_get_object_item(tree, "max_intf");
4609 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4610 seq_no ? seq_no->cy_valueint
4614 numa = cYAML_get_object_item(tree, "numa_range");
4616 rc = lustre_lnet_config_numa_range(0,
4617 seq_no ? seq_no->cy_valueint
4621 /* peer discovery is enabled by default */
4622 discovery = cYAML_get_object_item(tree, "discovery");
4624 rc = lustre_lnet_config_discovery(1,
4625 seq_no ? seq_no->cy_valueint
4629 /* asymmetrical route messages are accepted by default */
4630 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4631 if (drop_asym_route)
4632 rc = lustre_lnet_config_drop_asym_route(
4633 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4638 static int handle_yaml_show_global_settings(struct cYAML *tree,
4639 struct cYAML **show_rc,
4640 struct cYAML **err_rc)
4642 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4643 *sen, *recov, *rsen, *drop_asym_route;
4646 seq_no = cYAML_get_object_item(tree, "seq_no");
4647 max_intf = cYAML_get_object_item(tree, "max_intf");
4649 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4653 numa = cYAML_get_object_item(tree, "numa_range");
4655 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4659 discovery = cYAML_get_object_item(tree, "discovery");
4661 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4665 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4666 if (drop_asym_route)
4667 rc = lustre_lnet_show_drop_asym_route(
4668 seq_no ? seq_no->cy_valueint : -1,
4671 retry = cYAML_get_object_item(tree, "retry_count");
4673 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4677 tto = cYAML_get_object_item(tree, "transaction_timeout");
4679 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4683 sen = cYAML_get_object_item(tree, "health_sensitivity");
4685 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4689 recov = cYAML_get_object_item(tree, "recovery_interval");
4691 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4695 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4697 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4704 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4705 struct cYAML **err_rc)
4707 struct cYAML *seq_no, *nid, *timeout;
4709 seq_no = cYAML_get_object_item(tree, "seq_no");
4710 nid = cYAML_get_object_item(tree, "primary nid");
4711 timeout = cYAML_get_object_item(tree, "timeout");
4713 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4714 (timeout) ? timeout->cy_valueint : 1000,
4715 (seq_no) ? seq_no->cy_valueint : -1,
4719 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4720 struct cYAML **err_rc)
4722 struct cYAML *seq_no, *nid, *force;
4724 seq_no = cYAML_get_object_item(tree, "seq_no");
4725 nid = cYAML_get_object_item(tree, "primary nid");
4726 force = cYAML_get_object_item(tree, "force");
4728 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4729 (force) ? force->cy_valueint : 0,
4730 (seq_no) ? seq_no->cy_valueint : -1,
4734 static int handle_yaml_no_op()
4736 return LUSTRE_CFG_RC_NO_ERR;
4739 struct lookup_cmd_hdlr_tbl {
4744 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4745 { .name = "route", .cb = handle_yaml_config_route },
4746 { .name = "net", .cb = handle_yaml_config_ni },
4747 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4748 { .name = "peer", .cb = handle_yaml_config_peer },
4749 { .name = "routing", .cb = handle_yaml_config_routing },
4750 { .name = "buffers", .cb = handle_yaml_config_buffers },
4751 { .name = "statistics", .cb = handle_yaml_no_op },
4752 { .name = "global", .cb = handle_yaml_config_global_settings},
4753 { .name = "numa", .cb = handle_yaml_config_numa },
4754 { .name = "ping", .cb = handle_yaml_no_op },
4755 { .name = "discover", .cb = handle_yaml_no_op },
4758 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4759 { .name = "route", .cb = handle_yaml_del_route },
4760 { .name = "net", .cb = handle_yaml_del_ni },
4761 { .name = "ip2nets", .cb = handle_yaml_no_op },
4762 { .name = "peer", .cb = handle_yaml_del_peer },
4763 { .name = "routing", .cb = handle_yaml_del_routing },
4764 { .name = "buffers", .cb = handle_yaml_no_op },
4765 { .name = "statistics", .cb = handle_yaml_no_op },
4766 { .name = "global", .cb = handle_yaml_del_global_settings},
4767 { .name = "numa", .cb = handle_yaml_del_numa },
4768 { .name = "ping", .cb = handle_yaml_no_op },
4769 { .name = "discover", .cb = handle_yaml_no_op },
4772 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4773 { .name = "route", .cb = handle_yaml_show_route },
4774 { .name = "net", .cb = handle_yaml_show_net },
4775 { .name = "peer", .cb = handle_yaml_show_peers },
4776 { .name = "ip2nets", .cb = handle_yaml_no_op },
4777 { .name = "routing", .cb = handle_yaml_show_routing },
4778 { .name = "buffers", .cb = handle_yaml_show_routing },
4779 { .name = "statistics", .cb = handle_yaml_show_stats },
4780 { .name = "global", .cb = handle_yaml_show_global_settings},
4781 { .name = "numa", .cb = handle_yaml_show_numa },
4782 { .name = "ping", .cb = handle_yaml_no_op },
4783 { .name = "discover", .cb = handle_yaml_no_op },
4786 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4787 { .name = "route", .cb = handle_yaml_no_op },
4788 { .name = "net", .cb = handle_yaml_no_op },
4789 { .name = "peer", .cb = handle_yaml_no_op },
4790 { .name = "ip2nets", .cb = handle_yaml_no_op },
4791 { .name = "routing", .cb = handle_yaml_no_op },
4792 { .name = "buffers", .cb = handle_yaml_no_op },
4793 { .name = "statistics", .cb = handle_yaml_no_op },
4794 { .name = "global", .cb = handle_yaml_no_op },
4795 { .name = "numa", .cb = handle_yaml_no_op },
4796 { .name = "ping", .cb = handle_yaml_ping },
4797 { .name = "discover", .cb = handle_yaml_discover },
4800 static cmd_handler_t lookup_fn(char *key,
4801 struct lookup_cmd_hdlr_tbl *tbl)
4807 for (i = 0; tbl[i].name != NULL; i++) {
4808 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4815 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4816 struct cYAML **show_rc, struct cYAML **err_rc)
4818 struct cYAML *tree, *item = NULL, *head, *child;
4820 char err_str[LNET_MAX_STR_LEN];
4821 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4823 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4825 return LUSTRE_CFG_RC_BAD_PARAM;
4827 child = tree->cy_child;
4828 while (child != NULL) {
4829 cb = lookup_fn(child->cy_string, table);
4831 snprintf(err_str, sizeof(err_str),
4832 "\"call back for '%s' not found\"",
4834 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4835 "yaml", "helper", err_str, err_rc);
4839 if (cYAML_is_sequence(child)) {
4840 while ((head = cYAML_get_next_seq_item(child, &item))
4842 rc = cb(head, show_rc, err_rc);
4843 if (rc != LUSTRE_CFG_RC_NO_ERR)
4847 rc = cb(child, show_rc, err_rc);
4848 if (rc != LUSTRE_CFG_RC_NO_ERR)
4852 child = child->cy_next;
4856 cYAML_free_tree(tree);
4861 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4863 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4867 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4869 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4873 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4875 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4879 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4881 return lustre_yaml_cb_helper(f, lookup_exec_tbl,