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 <libcfs/util/hash.h>
48 #include <linux/lnet/lnetctl.h>
50 #include <sys/types.h>
54 #include <rdma/rdma_user_cm.h>
55 #include "liblnetconfig.h"
57 #include <libcfs/util/param.h>
59 #ifndef HAVE_USRSPC_RDMA_PS_TCP
60 #define RDMA_PS_TCP 0x0106
63 #define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
64 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
68 * lustre_lnet_ip_range_descr
69 * Describes an IP range.
70 * Each octect is an expression
72 struct lustre_lnet_ip_range_descr {
73 struct list_head ipr_entry;
74 struct list_head ipr_expr;
79 * Describes an ip2nets rule. This can be on a list of rules.
81 struct lustre_lnet_ip2nets {
82 struct lnet_dlc_network_descr ip2nets_net;
83 struct list_head ip2nets_ip_ranges;
86 int open_sysfs_file(const char *path, const char *attr, const int mode)
89 char filename[LNET_MAX_STR_LEN];
90 size_t size = sizeof(filename);
93 namelen = snprintf(filename, size, "%s%s", path, attr);
95 filename[size - 1] = '\0';
97 fd = open(filename, mode);
102 static int read_sysfs_file(const char *path, const char *attr,
103 void *val, const size_t size, const int nelem)
106 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
108 fd = open_sysfs_file(path, attr, O_RDONLY);
110 return LUSTRE_CFG_RC_NO_MATCH;
112 if (read(fd, val, size * nelem) == -1)
115 rc = LUSTRE_CFG_RC_NO_ERR;
122 static int write_sysfs_file(const char *path, const char *attr,
123 void *val, const size_t size, const int nelem)
126 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
128 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
130 return LUSTRE_CFG_RC_NO_MATCH;
132 if (write(fd, val, size * nelem) == -1)
135 rc = LUSTRE_CFG_RC_NO_ERR;
144 * frees the memory allocated for an intf descriptor.
146 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
151 if (intf_descr->cpt_expr != NULL)
152 cfs_expr_list_free(intf_descr->cpt_expr);
157 * lustre_lnet_add_ip_range
159 * given a string of the format:
160 * <expr.expr.expr.expr> parse each expr into
161 * a lustre_lnet_ip_range_descr structure and insert on the list.
163 * This function is called from
164 * YAML on each ip-range.
165 * As a result of lnetctl command
166 * When building a NID or P2P selection rules
168 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
170 struct lustre_lnet_ip_range_descr *ip_range;
173 ip_range = calloc(1, sizeof(*ip_range));
174 if (ip_range == NULL)
175 return LUSTRE_CFG_RC_OUT_OF_MEM;
177 INIT_LIST_HEAD(&ip_range->ipr_entry);
178 INIT_LIST_HEAD(&ip_range->ipr_expr);
180 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
181 &ip_range->ipr_expr);
183 return LUSTRE_CFG_RC_BAD_PARAM;
185 list_add_tail(&ip_range->ipr_entry, list);
187 return LUSTRE_CFG_RC_NO_ERR;
190 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
192 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
194 struct lnet_dlc_intf_descr *intf_descr = NULL;
196 char intf_string[LNET_MAX_STR_LEN];
198 if (len >= LNET_MAX_STR_LEN)
199 return LUSTRE_CFG_RC_BAD_PARAM;
201 strncpy(intf_string, intf, len);
202 intf_string[len] = '\0';
204 intf_descr = calloc(1, sizeof(*intf_descr));
205 if (intf_descr == NULL)
206 return LUSTRE_CFG_RC_OUT_OF_MEM;
208 INIT_LIST_HEAD(&intf_descr->intf_on_network);
210 intf_name = intf_string;
211 open_sq_bracket = strchr(intf_string, '[');
212 if (open_sq_bracket != NULL) {
213 close_sq_bracket = strchr(intf_string, ']');
214 if (close_sq_bracket == NULL) {
216 return LUSTRE_CFG_RC_BAD_PARAM;
218 rc = cfs_expr_list_parse(open_sq_bracket,
219 strlen(open_sq_bracket), 0, UINT_MAX,
220 &intf_descr->cpt_expr);
223 return LUSTRE_CFG_RC_BAD_PARAM;
225 strncpy(intf_descr->intf_name, intf_name,
226 open_sq_bracket - intf_name);
227 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
229 strcpy(intf_descr->intf_name, intf_name);
230 intf_descr->cpt_expr = NULL;
233 list_add_tail(&intf_descr->intf_on_network, list);
235 return LUSTRE_CFG_RC_NO_ERR;
238 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
240 if (nw_descr != NULL) {
242 INIT_LIST_HEAD(&nw_descr->network_on_rule);
243 INIT_LIST_HEAD(&nw_descr->nw_intflist);
247 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
248 int max_nids, char *err_str)
250 int rc, num_nids = 0;
251 struct list_head nidlist;
254 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
255 return LUSTRE_CFG_RC_BAD_PARAM;
258 if (strchr(nidstr, '*')) {
259 snprintf(err_str, LNET_MAX_STR_LEN,
260 "asterisk not allowed in nidstring \"%s\"", nidstr);
261 return LUSTRE_CFG_RC_BAD_PARAM;
264 INIT_LIST_HEAD(&nidlist);
265 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
267 snprintf(err_str, LNET_MAX_STR_LEN,
268 "Unable to parse nidlist from: %s\n", nidstr);
269 return LUSTRE_CFG_RC_BAD_PARAM;
272 if (list_empty(&nidlist)) {
273 snprintf(err_str, LNET_MAX_STR_LEN,
274 "\"%s\" does not specify any valid nid lists", nidstr);
275 return LUSTRE_CFG_RC_BAD_PARAM;
278 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
279 cfs_free_nidlist(&nidlist);
281 if (num_nids == -1) {
282 snprintf(err_str, LNET_MAX_STR_LEN,
283 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
285 return LUSTRE_CFG_RC_BAD_PARAM;
289 snprintf(err_str, LNET_MAX_STR_LEN,
290 "Failed to expand nidstr: %s", strerror(num_nids));
291 return LUSTRE_CFG_RC_OUT_OF_MEM;
295 snprintf(err_str, LNET_MAX_STR_LEN,
296 "\"%s\" did not expand to any nids", nidstr);
297 return LUSTRE_CFG_RC_BAD_PARAM;
305 * <intf>[<expr>], <intf>[<expr>],..
307 int lustre_lnet_parse_interfaces(char *intf_str,
308 struct lnet_dlc_network_descr *nw_descr)
313 char *cur = intf_str, *next = NULL;
314 char *end = intf_str + strlen(intf_str);
316 struct lnet_dlc_intf_descr *intf_descr, *tmp;
318 if (nw_descr == NULL)
319 return LUSTRE_CFG_RC_BAD_PARAM;
322 open_square = strchr(cur, '[');
323 if (open_square != NULL) {
324 close_square = strchr(cur, ']');
325 if (close_square == NULL) {
326 rc = LUSTRE_CFG_RC_BAD_PARAM;
330 comma = strchr(cur, ',');
331 if (comma != NULL && comma > close_square) {
333 len = next - close_square;
339 comma = strchr(cur, ',');
349 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
350 if (rc != LUSTRE_CFG_RC_NO_ERR)
356 return LUSTRE_CFG_RC_NO_ERR;
359 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
361 list_del(&intf_descr->intf_on_network);
362 free_intf_descr(intf_descr);
368 int lustre_lnet_config_lib_init(void)
370 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
373 void lustre_lnet_config_lib_uninit(void)
375 unregister_ioc_dev(LNET_DEV_ID);
378 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
379 int seq_no, struct cYAML **err_rc)
381 struct libcfs_ioctl_data data;
384 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
386 LIBCFS_IOC_INIT(data);
388 /* Reverse logic is used here in order not to change
389 * the lctl utility */
390 data.ioc_flags = load_ni_from_mod ? 0 : 1;
392 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
394 rc = l_ioctl(LNET_DEV_ID, opc, &data);
398 "\"LNet %s error: %s\"", (up) ? "configure" :
399 "unconfigure", strerror(errno));
403 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
404 "lnet", err_str, err_rc);
409 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
410 char *err_str, char *cmd_str)
414 rc = l_ioctl(LNET_DEV_ID, cmd, data);
417 snprintf(err_str, LNET_MAX_STR_LEN,
418 "\"%s peer ni operation failed: %s\"",
419 cmd_str, strerror(errno));
425 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
426 int param, int ioc_call, int seq_no,
427 struct cYAML **show_rc, struct cYAML **err_rc)
430 struct lnet_ioctl_ping_data ping;
431 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
432 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
433 struct lnet_process_id id;
434 char err_str[LNET_MAX_STR_LEN] = {0};
435 char *sep, *token, *end;
438 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
443 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
445 data = calloc(1, len);
449 /* create struct cYAML root object */
450 root = cYAML_create_object(NULL, NULL);
454 ping_node = cYAML_create_seq(root, oper);
455 if (ping_node == NULL)
459 src = libcfs_str2nid(src_nidstr);
460 if (src == LNET_NID_ANY) {
461 snprintf(err_str, sizeof(err_str),
462 "\"cannot parse source NID '%s'\"",
464 rc = LUSTRE_CFG_RC_BAD_PARAM;
465 cYAML_build_error(rc, seq_no, MANAGE_CMD,
466 oper, err_str, err_rc);
473 /* tokenise each nid in string ping_nids */
474 token = strtok(ping_nids, ",");
477 item = cYAML_create_seq_item(ping_node);
481 if (first_seq == NULL)
484 /* check if '-' is a part of NID, token */
485 sep = strchr(token, '-');
487 id.pid = LNET_PID_ANY;
488 /* if no net is specified, libcfs_str2nid() will assume tcp */
489 id.nid = libcfs_str2nid(token);
490 if (id.nid == LNET_NID_ANY) {
491 snprintf(err_str, sizeof(err_str),
492 "\"cannot parse NID '%s'\"",
494 rc = LUSTRE_CFG_RC_BAD_PARAM;
495 cYAML_build_error(rc, seq_no, MANAGE_CMD,
496 oper, err_str, err_rc);
500 if (token[0] == 'u' || token[0] == 'U')
501 id.pid = (strtoul(&token[1], &end, 0) |
502 (LNET_PID_USERFLAG));
504 id.pid = strtoul(token, &end, 0);
506 /* assuming '-' is part of hostname */
508 id.pid = LNET_PID_ANY;
509 id.nid = libcfs_str2nid(token);
510 if (id.nid == LNET_NID_ANY) {
511 snprintf(err_str, sizeof(err_str),
512 "\"cannot parse NID '%s'\"",
514 rc = LUSTRE_CFG_RC_BAD_PARAM;
515 cYAML_build_error(rc, seq_no, MANAGE_CMD,
521 id.nid = libcfs_str2nid(sep + 1);
522 if (id.nid == LNET_NID_ANY) {
523 snprintf(err_str, sizeof(err_str),
524 "\"cannot parse NID '%s'\"",
526 rc = LUSTRE_CFG_RC_BAD_PARAM;
527 cYAML_build_error(rc, seq_no, MANAGE_CMD,
534 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
535 ping.ping_hdr.ioc_len = sizeof(ping);
538 ping.op_param = param;
539 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
540 ping.ping_buf = data;
542 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
545 sizeof(err_str), "failed to %s %s: %s\n", oper,
546 id.pid == LNET_PID_ANY ?
547 libcfs_nid2str(id.nid) :
548 libcfs_id2str(id), strerror(errno));
549 rc = LUSTRE_CFG_RC_BAD_PARAM;
550 cYAML_build_error(rc, seq_no, MANAGE_CMD,
551 oper, err_str, err_rc);
555 if (cYAML_create_string(item, "primary nid",
556 libcfs_nid2str(ping.ping_id.nid)) == NULL)
559 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
560 "True" : "False") == NULL)
563 tmp = cYAML_create_seq(item, "peer ni");
567 for (i = 0; i < ping.ping_count; i++) {
568 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
570 peer_ni = cYAML_create_seq_item(tmp);
573 memset(buf, 0, sizeof buf);
574 snprintf(buf, sizeof buf, "nid");
575 if (cYAML_create_string(peer_ni, buf,
576 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
582 } while ((token = strtok(NULL, ",")) != NULL);
585 rc = LUSTRE_CFG_RC_NO_ERR;
590 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
591 cYAML_free_tree(root);
592 } else if (show_rc != NULL && *show_rc != NULL) {
593 struct cYAML *show_node;
594 show_node = cYAML_get_object_item(*show_rc, oper);
595 if (show_node != NULL && cYAML_is_sequence(show_node)) {
596 cYAML_insert_child(show_node, first_seq);
599 } else if (show_node == NULL) {
600 cYAML_insert_sibling((*show_rc)->cy_child,
604 cYAML_free_tree(root);
613 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
614 int seq_no, struct cYAML **show_rc,
615 struct cYAML **err_rc)
619 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
620 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
624 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
625 struct cYAML **show_rc, struct cYAML **err_rc)
629 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
630 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
634 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
635 bool is_mr, int option, __u32 cmd,
636 char *cmd_type, char *err_str)
638 struct lnet_ioctl_peer_cfg data;
641 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
642 /* When adding a peer we first need to create the peer using the
643 * specified (or implied) primary nid. Then we can add
644 * additional nids to this peer using the primary nid as a key
646 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
647 data.prcfg_mr = is_mr;
648 data.prcfg_prim_nid = nidlist[0];
649 data.prcfg_cfg_nid = LNET_NID_ANY;
650 data.prcfg_count = option;
652 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
658 /* Add or delete any specified NIs associated with the specified
659 * (or implied) primary nid
661 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
662 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
663 data.prcfg_mr = is_mr;
664 data.prcfg_prim_nid = nidlist[0];
665 data.prcfg_cfg_nid = nidlist[nid_idx];
666 data.prcfg_count = option;
668 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
674 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
675 /* In the delete case we may have been given just the
676 * primary nid of the peer. This tells us to delete the peer
677 * completely (rather than just delete some of its NIs)
679 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
680 data.prcfg_prim_nid = nidlist[0];
681 data.prcfg_cfg_nid = LNET_NID_ANY;
682 data.prcfg_count = option;
684 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
691 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
692 int cmd, int num_nids, bool is_mr, int option,
693 int seq_no, struct cYAML **err_rc)
695 int rc = LUSTRE_CFG_RC_NO_ERR;
696 char err_str[LNET_MAX_STR_LEN];
697 lnet_nid_t *lnet_nidlist2 = NULL;
698 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
699 IOC_LIBCFS_DEL_PEER_NI;
700 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
703 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
704 if (!lnet_nidlist2) {
705 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
706 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
709 lnet_nidlist2[0] = pnid;
710 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
713 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
714 num_nids, is_mr, option,
715 ioc_cmd, cmd_str, err_str);
720 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
725 replace_sep(char *str, char sep, char newsep)
731 for (i = 0; i < strlen(str); i++) {
732 /* don't replace ',' within [] */
735 else if (str[i] == ']')
737 else if (str[i] == sep && bracket == 0)
742 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr, int cmd,
743 int option, int seq_no, struct cYAML **err_rc)
746 char err_str[LNET_MAX_STR_LEN] = "Error";
747 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
748 lnet_nid_t pnid = LNET_NID_ANY;
751 rc = LUSTRE_CFG_RC_BAD_PARAM;
752 snprintf(err_str, LNET_MAX_STR_LEN,
753 "--prim_nid must be specified");
757 pnid = libcfs_str2nid(prim_nid);
758 if (pnid == LNET_NID_ANY) {
759 rc = LUSTRE_CFG_RC_BAD_PARAM;
760 snprintf(err_str, LNET_MAX_STR_LEN,
761 "badly formatted primary NID: %s", prim_nid);
768 * if there is no primary nid we need to make the first nid in the
769 * nids list the primary nid
771 replace_sep(nids, ',', ' ');
772 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
773 LNET_MAX_NIDS_PER_PEER, err_str);
780 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
781 cmd, num_nids, is_mr,
785 if (rc != LUSTRE_CFG_RC_NO_ERR)
786 cYAML_build_error(rc, -1, "peer",
787 cmd == LNETCTL_ADD_CMD ? "add" : "del",
793 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
794 int sen, int seq_no, struct cYAML **err_rc,
797 int rc, num_nids, idx;
799 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
800 struct lnet_ioctl_config_data data;
801 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
803 if (nw == NULL || nidstr == NULL) {
804 snprintf(err_str, LNET_MAX_STR_LEN,
805 "\"missing mandatory parameter:'%s'\"",
806 (nw == NULL && nidstr == NULL) ? "network, gateway" :
807 (nw == NULL) ? "network" : "gateway");
808 rc = LUSTRE_CFG_RC_MISSING_PARAM;
812 rnet = libcfs_str2net(nw);
813 if (rnet == LNET_NET_ANY) {
814 snprintf(err_str, LNET_MAX_STR_LEN,
815 "\"cannot parse remote net %s\"", nw);
816 rc = LUSTRE_CFG_RC_BAD_PARAM;
820 replace_sep(nidstr, ',', ' ');
821 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
822 LNET_MAX_NIDS_PER_PEER, err_str);
828 for (idx = 0; idx < num_nids; idx++) {
829 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
831 if (cmd == LNETCTL_ADD_CMD) {
832 data.cfg_config_u.cfg_route.rtr_hop = hops;
833 data.cfg_config_u.cfg_route.rtr_priority = prio;
834 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
837 data.cfg_nid = lnet_nidlist[idx];
839 if (cmd == LNETCTL_ADD_CMD)
840 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
843 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
846 if (rc != 0 && errno != EEXIST &&
847 errno != EHOSTUNREACH) {
849 snprintf(err_str, LNET_MAX_STR_LEN,
850 "route operation failed: %s",
853 } else if (errno == EEXIST) {
855 * continue chugging along if one of the
856 * routes already exists
863 cYAML_build_error(rc, seq_no,
864 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
870 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
871 int sen, int seq_no, struct cYAML **err_rc)
874 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
877 hops = LNET_UNDEFINED_HOPS;
878 } else if (hops < 1 || hops > 255) {
879 snprintf(err_str, LNET_MAX_STR_LEN,
880 "\"invalid hop count %d, must be between 1 and 255\"",
882 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
888 } else if (prio < 0) {
889 snprintf(err_str, LNET_MAX_STR_LEN,
890 "\"invalid priority %d, must be greater than 0\"",
892 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
898 } else if (sen < 1) {
899 snprintf(err_str, LNET_MAX_STR_LEN,
900 "\"invalid health sensitivity %d, must be 1 or greater\"",
902 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
906 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
907 err_rc, LNETCTL_ADD_CMD);
910 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
915 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
916 struct cYAML **err_rc)
918 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
922 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
923 int seq_no, struct cYAML **show_rc,
924 struct cYAML **err_rc, bool backup)
926 struct lnet_ioctl_config_data data;
927 lnet_nid_t gateway_nid;
928 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
930 __u32 net = LNET_NET_ANY;
932 struct cYAML *root = NULL, *route = NULL, *item = NULL;
933 struct cYAML *first_seq = NULL;
934 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
938 net = libcfs_str2net(nw);
939 if (net == LNET_NET_ANY) {
942 "\"cannot parse net '%s'\"", nw);
943 rc = LUSTRE_CFG_RC_BAD_PARAM;
948 /* show all routes without filtering on net */
953 gateway_nid = libcfs_str2nid(gw);
954 if (gateway_nid == LNET_NID_ANY) {
957 "\"cannot parse gateway NID '%s'\"", gw);
958 rc = LUSTRE_CFG_RC_BAD_PARAM;
962 /* show all routes with out filtering on gateway */
963 gateway_nid = LNET_NID_ANY;
965 if ((hops < 1 && hops != -1) || hops > 255) {
968 "\"invalid hop count %d, must be between 0 and 256\"",
970 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
974 /* create struct cYAML root object */
975 root = cYAML_create_object(NULL, NULL);
979 route = cYAML_create_seq(root, "route");
987 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
990 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
996 /* filter on provided data */
997 if (net != LNET_NET_ANY &&
1001 if (gateway_nid != LNET_NID_ANY &&
1002 gateway_nid != data.cfg_nid)
1006 hops != data.cfg_config_u.cfg_route.rtr_hop)
1010 prio != data.cfg_config_u.cfg_route.rtr_priority)
1013 /* default rc to -1 incase we hit the goto */
1017 item = cYAML_create_seq_item(route);
1021 if (first_seq == NULL)
1024 if (cYAML_create_string(item, "net",
1025 libcfs_net2str(data.cfg_net)) == NULL)
1028 if (cYAML_create_string(item, "gateway",
1029 libcfs_nid2str(data.cfg_nid)) == NULL)
1033 if (cYAML_create_number(item, "hop",
1034 (int) data.cfg_config_u.
1035 cfg_route.rtr_hop) ==
1039 if (cYAML_create_number(item, "priority",
1041 cfg_route.rtr_priority) == NULL)
1044 if (cYAML_create_number(item, "health_sensitivity",
1046 cfg_route.rtr_sensitivity) == NULL)
1049 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1051 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1055 cYAML_create_string(item, "state",
1057 "up" : "down") == NULL)
1061 cYAML_create_string(item, "type",
1063 "multi-hop" : "single-hop") == NULL)
1068 /* print output iff show_rc is not provided */
1069 if (show_rc == NULL)
1070 cYAML_print_tree(root);
1072 if (l_errno != ENOENT) {
1075 "\"cannot get routes: %s\"",
1080 rc = LUSTRE_CFG_RC_NO_ERR;
1082 snprintf(err_str, sizeof(err_str), "\"success\"");
1084 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1085 cYAML_free_tree(root);
1086 } else if (show_rc != NULL && *show_rc != NULL) {
1087 struct cYAML *show_node;
1088 /* find the route node, if one doesn't exist then
1089 * insert one. Otherwise add to the one there
1091 show_node = cYAML_get_object_item(*show_rc, "route");
1092 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1093 cYAML_insert_child(show_node, first_seq);
1096 } else if (show_node == NULL) {
1097 cYAML_insert_sibling((*show_rc)->cy_child,
1101 cYAML_free_tree(root);
1107 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1112 static int socket_intf_query(int request, char *intf,
1118 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1119 return LUSTRE_CFG_RC_BAD_PARAM;
1121 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1123 return LUSTRE_CFG_RC_BAD_PARAM;
1125 strcpy(ifr->ifr_name, intf);
1126 rc = ioctl(sockfd, request, ifr);
1128 rc = LUSTRE_CFG_RC_BAD_PARAM;
1135 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1140 memset(&ifr, 0, sizeof(ifr));
1141 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1143 return LUSTRE_CFG_RC_BAD_PARAM;
1145 if ((ifr.ifr_flags & IFF_UP) == 0)
1146 return LUSTRE_CFG_RC_BAD_PARAM;
1148 memset(&ifr, 0, sizeof(ifr));
1149 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1151 return LUSTRE_CFG_RC_BAD_PARAM;
1153 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1154 *ip = bswap_32(*ip);
1156 return LUSTRE_CFG_RC_NO_ERR;
1159 static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
1162 unsigned int nic_index;
1164 char *nic_addr_path;
1169 rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
1171 return LUSTRE_CFG_RC_NO_MATCH;
1173 size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
1174 nic_addr_path = malloc(size);
1176 return LUSTRE_CFG_RC_OUT_OF_MEM;
1177 sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
1179 rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
1180 free(nic_addr_path);
1182 return LUSTRE_CFG_RC_NO_MATCH;
1184 addr = strtol(val, NULL, 16);
1185 if (addr == LONG_MIN || addr == LONG_MAX)
1186 return LUSTRE_CFG_RC_NO_MATCH;
1190 return LUSTRE_CFG_RC_NO_ERR;
1194 * for each interface in the array of interfaces find the IP address of
1195 * that interface, create its nid and add it to an array of NIDs.
1196 * Stop if any of the interfaces is down
1198 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1199 lnet_nid_t **nids, __u32 *nnids,
1200 char *err_str, size_t str_len)
1202 int i = 0, count = 0, rc;
1203 struct lnet_dlc_intf_descr *intf;
1204 char val[LNET_MAX_STR_LEN];
1212 if (nw == NULL || nids == NULL) {
1213 snprintf(err_str, str_len,
1214 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1215 return LUSTRE_CFG_RC_BAD_PARAM;
1218 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1221 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1225 *nids = calloc(count, sizeof(lnet_nid_t));
1226 if (*nids == NULL) {
1227 snprintf(err_str, str_len,
1228 "\"out of memory\"");
1229 return LUSTRE_CFG_RC_OUT_OF_MEM;
1232 * special case the GNI interface since it doesn't have an IP
1233 * address. The assumption is that there can only be one GNI
1234 * interface in the system. No interface name is provided.
1236 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1237 rc = read_sysfs_file(gni_nid_path, "nid", val,
1240 snprintf(err_str, str_len,
1241 "\"cannot read gni nid\"");
1244 gni_num = atoi(val);
1246 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1249 } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
1250 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1251 rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
1252 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1253 snprintf(err_str, str_len,
1254 "\"couldn't query kfi intf %s\"",
1256 err_str[str_len - 1] = '\0';
1260 (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
1266 /* look at the other interfaces */
1267 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1268 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1269 /* handle LNDs with numeric interface name */
1270 num = strtoul(intf->intf_name, &endp, 0);
1271 if (endp == intf->intf_name || *endp != '\0') {
1272 rc = LUSTRE_CFG_RC_BAD_PARAM;
1273 snprintf(err_str, str_len,
1274 "\"couldn't query intf %s\"",
1278 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1281 /* handle LNDs with ip interface name */
1282 rc = lustre_lnet_queryip(intf, &ip);
1283 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1284 snprintf(err_str, str_len,
1285 "\"couldn't query intf %s\"",
1289 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1306 * called repeatedly until a match or no more ip range
1308 * ip_range expression
1309 * interface list with all the interface names.
1310 * all the interfaces in the system.
1312 * try to match the ip_range expr to one of the interfaces' IPs in
1313 * the system. If we hit a patch for an interface. Check if that
1314 * interface name is in the list.
1316 * If there are more than one interface in the list, then make sure
1317 * that the IPs for all of these interfaces match the ip ranges
1320 * for each interface in intf_list
1321 * look up the intf name in ifa
1322 * if not there then no match
1323 * check ip obtained from ifa against a match to any of the
1325 * If no match, then fail
1327 * The result is that all the interfaces have to match.
1329 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1330 struct list_head *intf_list,
1331 struct list_head *ip_ranges)
1335 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1336 struct ifaddrs *ifaddr = ifa;
1337 struct lustre_lnet_ip_range_descr *ip_range;
1341 * if there are no explicit interfaces, and no ip ranges, then
1342 * configure the first tcp interface we encounter.
1344 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1345 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1346 if (ifaddr->ifa_addr == NULL)
1349 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1352 family = ifaddr->ifa_addr->sa_family;
1353 if (family == AF_INET &&
1354 strcmp(ifaddr->ifa_name, "lo") != 0) {
1355 rc = lustre_lnet_add_intf_descr
1356 (intf_list, ifaddr->ifa_name,
1357 strlen(ifaddr->ifa_name));
1359 if (rc != LUSTRE_CFG_RC_NO_ERR)
1362 return LUSTRE_CFG_RC_MATCH;
1365 return LUSTRE_CFG_RC_NO_MATCH;
1369 * First interface which matches an IP pattern will be used
1371 if (list_empty(intf_list)) {
1373 * no interfaces provided in the rule, but an ip range is
1374 * provided, so try and match an interface to the ip
1377 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1378 if (ifaddr->ifa_addr == NULL)
1381 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1384 family = ifaddr->ifa_addr->sa_family;
1385 if (family == AF_INET) {
1386 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1389 list_for_each_entry(ip_range, ip_ranges,
1391 rc = cfs_ip_addr_match(bswap_32(ip),
1392 &ip_range->ipr_expr);
1396 rc = lustre_lnet_add_intf_descr
1397 (intf_list, ifaddr->ifa_name,
1398 strlen(ifaddr->ifa_name));
1400 if (rc != LUSTRE_CFG_RC_NO_ERR)
1406 if (!list_empty(intf_list))
1407 return LUSTRE_CFG_RC_MATCH;
1409 return LUSTRE_CFG_RC_NO_MATCH;
1413 * If an interface is explicitly specified the ip-range might or
1414 * might not be specified. if specified the interface needs to match the
1415 * ip-range. If no ip-range then the interfaces are
1416 * automatically matched if they are all up.
1417 * If > 1 interfaces all the interfaces must match for the NI to
1420 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1421 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1422 if (ifaddr->ifa_addr == NULL)
1425 family = ifaddr->ifa_addr->sa_family;
1426 if (family == AF_INET &&
1427 strcmp(intf_descr->intf_name,
1428 ifaddr->ifa_name) == 0)
1432 if (ifaddr == NULL) {
1433 list_del(&intf_descr->intf_on_network);
1434 free_intf_descr(intf_descr);
1438 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1439 list_del(&intf_descr->intf_on_network);
1440 free_intf_descr(intf_descr);
1444 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1447 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1448 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1454 /* no match for this interface */
1455 list_del(&intf_descr->intf_on_network);
1456 free_intf_descr(intf_descr);
1460 return LUSTRE_CFG_RC_MATCH;
1463 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1464 lnet_nid_t **nids, __u32 *nnids,
1465 char *err_str, size_t str_len)
1467 struct ifaddrs *ifa;
1468 int rc = LUSTRE_CFG_RC_NO_ERR;
1470 rc = getifaddrs(&ifa);
1472 snprintf(err_str, str_len,
1473 "\"failed to get interface addresses: %d\"", -errno);
1477 rc = lustre_lnet_match_ip_to_intf(ifa,
1478 &ip2nets->ip2nets_net.nw_intflist,
1479 &ip2nets->ip2nets_ip_ranges);
1480 if (rc != LUSTRE_CFG_RC_MATCH) {
1481 snprintf(err_str, str_len,
1482 "\"couldn't match ip to existing interfaces\"");
1487 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1489 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1500 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1501 struct lnet_ioctl_config_lnd_tunables *tunables,
1502 struct cfs_expr_list *global_cpts,
1503 lnet_nid_t *nids, char *err_str)
1506 struct lnet_ioctl_config_ni *conf;
1507 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1508 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1511 struct lnet_dlc_intf_descr *intf_descr;
1513 struct cfs_expr_list *cpt_expr;
1515 list_for_each_entry(intf_descr, intf_list,
1517 if (tunables != NULL)
1518 len = sizeof(struct lnet_ioctl_config_ni) +
1519 sizeof(struct lnet_ioctl_config_lnd_tunables);
1521 len = sizeof(struct lnet_ioctl_config_ni);
1523 data = calloc(1, len);
1525 return LUSTRE_CFG_RC_OUT_OF_MEM;
1526 conf = (struct lnet_ioctl_config_ni*) data;
1527 if (tunables != NULL)
1528 tun = (struct lnet_ioctl_config_lnd_tunables*)
1531 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1532 conf->lic_cfg_hdr.ioc_len = len;
1533 conf->lic_nid = nids[i];
1534 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1537 if (intf_descr->cpt_expr != NULL)
1538 cpt_expr = intf_descr->cpt_expr;
1539 else if (global_cpts != NULL)
1540 cpt_expr = global_cpts;
1544 if (cpt_expr != NULL) {
1545 count = cfs_expr_list_values(cpt_expr,
1546 LNET_MAX_SHOW_NUM_CPT,
1549 memcpy(conf->lic_cpts, cpt_array,
1550 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1559 conf->lic_ncpts = count;
1561 if (tunables != NULL)
1562 memcpy(tun, tunables, sizeof(*tunables));
1564 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1569 "\"cannot add network: %s\"", strerror(errno));
1577 return LUSTRE_CFG_RC_NO_ERR;
1581 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1582 struct lnet_ioctl_config_lnd_tunables *tunables,
1583 struct cfs_expr_list *global_cpts,
1584 int seq_no, struct cYAML **err_rc)
1586 lnet_nid_t *nids = NULL;
1589 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1594 "\"incomplete ip2nets information\"");
1595 rc = LUSTRE_CFG_RC_BAD_PARAM;
1600 * call below function to resolve the rules into a list of nids.
1601 * The memory is allocated in that function then freed here when
1602 * it's no longer needed.
1604 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1606 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1609 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1610 snprintf(err_str, sizeof(err_str),
1611 "\"no interfaces match ip2nets rules\"");
1615 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1616 tunables, global_cpts, nids,
1623 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1627 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1628 struct cfs_expr_list *global_cpts,
1630 struct lnet_ioctl_config_lnd_tunables *tunables,
1631 int seq_no, struct cYAML **err_rc)
1634 struct lnet_ioctl_config_ni *conf;
1635 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1636 char buf[LNET_MAX_STR_LEN];
1637 int rc = LUSTRE_CFG_RC_NO_ERR;
1638 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1639 lnet_nid_t *nids = NULL;
1643 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1646 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1647 (list_empty(&nw_descr->nw_intflist) &&
1648 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1651 "\"missing mandatory parameters in NI config: '%s'\"",
1652 (nw_descr == NULL) ? "network , interface" :
1653 (nw_descr->nw_id == 0) ? "network" : "interface");
1654 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1658 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1661 "\"ip2net string too long %d\"",
1662 (int)strlen(ip2net));
1663 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1667 if (ip2net != NULL) {
1668 if (tunables != NULL)
1669 len = sizeof(struct lnet_ioctl_config_ni) +
1670 sizeof(struct lnet_ioctl_config_lnd_tunables);
1672 len = sizeof(struct lnet_ioctl_config_ni);
1673 data = calloc(1, len);
1675 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1678 conf = (struct lnet_ioctl_config_ni*) data;
1679 if (tunables != NULL)
1680 tun = (struct lnet_ioctl_config_lnd_tunables*)
1681 (data + sizeof(*conf));
1683 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1684 conf->lic_cfg_hdr.ioc_len = len;
1685 strncpy(conf->lic_legacy_ip2nets, ip2net,
1688 if (global_cpts != NULL) {
1689 count = cfs_expr_list_values(global_cpts,
1690 LNET_MAX_SHOW_NUM_CPT,
1693 memcpy(conf->lic_cpts, cpt_array,
1694 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1703 conf->lic_ncpts = count;
1705 if (tunables != NULL)
1706 memcpy(tun, tunables, sizeof(*tunables));
1708 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1713 "\"cannot add network: %s\"", strerror(errno));
1720 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1721 rc = LUSTRE_CFG_RC_NO_ERR;
1725 if (nw_descr->nw_id == LNET_NET_ANY) {
1728 "\"cannot parse net '%s'\"",
1729 libcfs_net2str(nw_descr->nw_id));
1730 rc = LUSTRE_CFG_RC_BAD_PARAM;
1735 * special case the GNI since no interface name is expected
1737 if (list_empty(&nw_descr->nw_intflist) &&
1738 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1741 "\"no interface name provided\"");
1742 rc = LUSTRE_CFG_RC_BAD_PARAM;
1746 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1747 err_str, sizeof(err_str));
1749 rc = LUSTRE_CFG_RC_BAD_PARAM;
1753 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1754 tunables, global_cpts, nids,
1758 if (nw_descr != NULL) {
1759 list_for_each_entry_safe(intf_descr, tmp,
1760 &nw_descr->nw_intflist,
1762 list_del(&intf_descr->intf_on_network);
1763 free_intf_descr(intf_descr);
1767 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1778 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1779 int seq_no, struct cYAML **err_rc)
1781 struct lnet_ioctl_config_ni data;
1782 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1783 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1784 lnet_nid_t *nids = NULL;
1786 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1788 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1791 "\"missing mandatory parameter in deleting NI: '%s'\"",
1792 (nw_descr == NULL) ? "network , interface" :
1793 (nw_descr->nw_id == 0) ? "network" : "interface");
1794 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1798 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1799 return LUSTRE_CFG_RC_NO_ERR;
1801 if (nw_descr->nw_id == LNET_NET_ANY) {
1804 "\"cannot parse net '%s'\"",
1805 libcfs_net2str(nw_descr->nw_id));
1806 rc = LUSTRE_CFG_RC_BAD_PARAM;
1810 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1811 err_str, sizeof(err_str));
1813 rc = LUSTRE_CFG_RC_BAD_PARAM;
1818 * no interfaces just the nw_id is specified
1821 nids = calloc(1, sizeof(*nids));
1823 snprintf(err_str, sizeof(err_str),
1824 "\"out of memory\"");
1825 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1828 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1832 for (i = 0; i < nnids; i++) {
1833 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1834 data.lic_nid = nids[i];
1836 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1841 "\"cannot del network: %s\"", strerror(errno));
1845 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1847 list_del(&intf_descr->intf_on_network);
1848 free_intf_descr(intf_descr);
1852 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1861 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1862 enum lnet_health_type type, char *name,
1863 int seq_no, struct cYAML **err_rc)
1865 struct lnet_ioctl_reset_health_cfg data;
1866 int rc = LUSTRE_CFG_RC_NO_ERR;
1867 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1869 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1870 data.rh_type = type;
1872 data.rh_value = value;
1875 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1879 sizeof(err_str), "Can not configure health value: %s",
1883 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1889 lustre_lnet_config_peer(int state, lnet_nid_t nid, char *name,
1890 int seq_no, struct cYAML **err_rc)
1892 struct lnet_ioctl_peer_cfg data;
1893 int rc = LUSTRE_CFG_RC_NO_ERR;
1894 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1896 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
1897 data.prcfg_state = state;
1898 data.prcfg_prim_nid = nid;
1899 data.prcfg_cfg_nid = LNET_NID_ANY;
1901 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_PEER, &data);
1905 sizeof(err_str), "Can not set peer property: %s",
1909 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1915 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1916 char *name, int seq_no,
1917 struct cYAML **err_rc)
1919 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1920 int rc = LUSTRE_CFG_RC_NO_ERR;
1921 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1923 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1924 data.rcpp_all = all;
1925 data.rcpp_value = value;
1926 data.rcpp_nid = nid;
1928 if (value < 0 || value > 127) {
1929 rc = LUSTRE_CFG_RC_BAD_PARAM;
1930 snprintf(err_str, sizeof(err_str),
1931 "\"Valid values are: 0-127\"");
1934 rc = l_ioctl(LNET_DEV_ID,
1935 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1940 "Can not configure conns_per_peer value: %s",
1944 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1949 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1950 struct cYAML **err_rc)
1954 nid = libcfs_str2nid(ni_nid);
1957 return lustre_lnet_config_healthv(value, all, nid,
1958 LNET_HEALTH_TYPE_LOCAL_NI,
1959 "ni healthv", seq_no, err_rc);
1962 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1963 int seq_no, struct cYAML **err_rc)
1967 nid = libcfs_str2nid(lpni_nid);
1970 return lustre_lnet_config_healthv(value, all, nid,
1971 LNET_HEALTH_TYPE_PEER_NI,
1972 "peer_ni healthv", seq_no, err_rc);
1975 int lustre_lnet_set_peer_state(int state, char *lpni_nid, int seq_no,
1976 struct cYAML **err_rc)
1981 nid = libcfs_str2nid(lpni_nid);
1984 return lustre_lnet_config_peer(state, nid, "peer state", seq_no,
1988 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1989 int seq_no, struct cYAML **err_rc)
1994 nid = libcfs_str2nid(ni_nid);
1997 return lustre_lnet_config_conns_per_peer(value, all, nid,
1998 "ni conns_per_peer",
2003 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
2004 struct lnet_ioctl_comm_count *counts)
2006 if (cYAML_create_number(yaml, "put",
2007 counts->ico_put_count)
2010 if (cYAML_create_number(yaml, "get",
2011 counts->ico_get_count)
2014 if (cYAML_create_number(yaml, "reply",
2015 counts->ico_reply_count)
2018 if (cYAML_create_number(yaml, "ack",
2019 counts->ico_ack_count)
2022 if (cYAML_create_number(yaml, "hello",
2023 counts->ico_hello_count)
2030 static struct lnet_ioctl_comm_count *
2031 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
2034 return &msg_stats->im_send_stats;
2036 return &msg_stats->im_recv_stats;
2038 return &msg_stats->im_drop_stats;
2044 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2045 struct cYAML *net_node)
2047 char tmp[LNET_MAX_STR_LEN];
2048 struct cYAML *udsp_net;
2049 bool created = false;
2053 /* add the UDSP info */
2054 udsp_net = cYAML_create_object(net_node, "udsp info");
2056 return LUSTRE_CFG_RC_OUT_OF_MEM;
2058 if (!cYAML_create_number(udsp_net, "net priority",
2059 (int) udsp_info->cud_net_priority))
2060 return LUSTRE_CFG_RC_OUT_OF_MEM;
2062 if (!cYAML_create_number(udsp_net, "nid priority",
2063 (int)udsp_info->cud_nid_priority))
2064 return LUSTRE_CFG_RC_OUT_OF_MEM;
2068 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2069 memset(tmp, 0, LNET_MAX_STR_LEN);
2070 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2073 pref = cYAML_create_object(udsp_net,
2074 "Preferred gateway NIDs");
2076 return LUSTRE_CFG_RC_OUT_OF_MEM;
2079 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2080 if (!cYAML_create_string(pref, tmp,
2081 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2082 return LUSTRE_CFG_RC_OUT_OF_MEM;
2085 return LUSTRE_CFG_RC_NO_ERR;
2089 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2090 struct cYAML *nid_node)
2092 char tmp[LNET_MAX_STR_LEN];
2093 struct cYAML *udsp_nid;
2094 bool created = false;
2098 /* add the UDSP info */
2099 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2101 return LUSTRE_CFG_RC_OUT_OF_MEM;
2103 if (!cYAML_create_number(udsp_nid, "net priority",
2104 (int) udsp_info->cud_net_priority))
2105 return LUSTRE_CFG_RC_OUT_OF_MEM;
2107 if (!cYAML_create_number(udsp_nid, "nid priority",
2108 (int) udsp_info->cud_nid_priority))
2109 return LUSTRE_CFG_RC_OUT_OF_MEM;
2112 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2113 memset(tmp, 0, LNET_MAX_STR_LEN);
2114 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2117 pref = cYAML_create_object(udsp_nid,
2118 "Preferred gateway NIDs");
2120 return LUSTRE_CFG_RC_OUT_OF_MEM;
2123 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2124 if (!cYAML_create_string(pref, tmp,
2125 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2126 return LUSTRE_CFG_RC_OUT_OF_MEM;
2131 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2132 memset(tmp, 0, LNET_MAX_STR_LEN);
2133 if (udsp_info->cud_pref_nid[i] == 0)
2136 pref = cYAML_create_object(udsp_nid,
2137 "Preferred source NIDs");
2139 return LUSTRE_CFG_RC_OUT_OF_MEM;
2142 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2143 if (!cYAML_create_string(pref, tmp,
2144 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2145 return LUSTRE_CFG_RC_OUT_OF_MEM;
2148 return LUSTRE_CFG_RC_NO_ERR;
2151 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2152 struct cYAML **show_rc, struct cYAML **err_rc,
2156 struct lnet_ioctl_config_ni *ni_data;
2157 struct lnet_ioctl_config_lnd_tunables *lnd;
2158 struct lnet_ioctl_element_stats *stats;
2159 struct lnet_ioctl_element_msg_stats msg_stats;
2160 struct lnet_ioctl_local_ni_hstats hstats;
2161 struct lnet_ioctl_construct_udsp_info udsp_info;
2162 __u32 net = LNET_NET_ANY;
2163 __u32 prev_net = LNET_NET_ANY;
2164 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2166 struct cYAML *root = NULL, *tunables = NULL,
2167 *net_node = NULL, *interfaces = NULL,
2168 *item = NULL, *first_seq = NULL,
2169 *tmp = NULL, *statistics = NULL,
2171 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2172 char str_buf[str_buf_len];
2174 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2175 bool exist = false, new_net = true;
2177 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2179 buf = calloc(1, buf_size);
2183 ni_data = (struct lnet_ioctl_config_ni *)buf;
2186 net = libcfs_str2net(nw);
2187 if (net == LNET_NET_ANY) {
2190 "\"cannot parse net '%s'\"", nw);
2191 rc = LUSTRE_CFG_RC_BAD_PARAM;
2196 root = cYAML_create_object(NULL, NULL);
2200 net_node = cYAML_create_seq(root, "net");
2201 if (net_node == NULL)
2207 memset(buf, 0, buf_size);
2209 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2211 * set the ioc_len to the proper value since INIT assumes
2214 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2215 ni_data->lic_idx = i;
2217 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2223 rc_net = LNET_NIDNET(ni_data->lic_nid);
2225 /* filter on provided data */
2226 if (net != LNET_NET_ANY &&
2230 /* if we're backing up don't store lo */
2231 if (backup && LNET_NETTYP(rc_net) == LOLND)
2234 /* default rc to -1 in case we hit the goto */
2238 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2239 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2240 (ni_data->lic_bulk + sizeof(*stats));
2242 if (rc_net != prev_net) {
2249 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2253 if (first_seq == NULL)
2256 tmp = cYAML_create_seq(net_node, "local NI(s)");
2262 /* create the tree to be printed. */
2263 item = cYAML_create_seq_item(tmp);
2268 cYAML_create_string(item, "nid",
2269 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2273 cYAML_create_string(item,
2275 (ni_data->lic_status ==
2276 LNET_NI_STATUS_UP) ?
2277 "up" : "down") == NULL)
2280 /* don't add interfaces unless there is at least one
2282 if (strlen(ni_data->lic_ni_intf) > 0) {
2283 interfaces = cYAML_create_object(item, "interfaces");
2284 if (interfaces == NULL)
2287 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2288 if (cYAML_create_string(interfaces, str_buf,
2289 ni_data->lic_ni_intf) == NULL)
2298 goto continue_without_msg_stats;
2300 statistics = cYAML_create_object(item, "statistics");
2301 if (statistics == NULL)
2304 if (cYAML_create_number(statistics, "send_count",
2305 stats->iel_send_count)
2309 if (cYAML_create_number(statistics, "recv_count",
2310 stats->iel_recv_count)
2314 if (cYAML_create_number(statistics, "drop_count",
2315 stats->iel_drop_count)
2320 goto continue_without_udsp_info;
2322 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2323 udsp_info.cud_nid = ni_data->lic_nid;
2324 udsp_info.cud_peer = false;
2325 rc = l_ioctl(LNET_DEV_ID,
2326 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2330 goto continue_without_udsp_info;
2333 rc = create_local_udsp_info(&udsp_info, item);
2339 continue_without_udsp_info:
2341 goto continue_without_msg_stats;
2343 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2344 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2345 msg_stats.im_idx = i;
2347 rc = l_ioctl(LNET_DEV_ID,
2348 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2352 goto continue_without_msg_stats;
2355 for (k = 0; k < 3; k++) {
2356 struct lnet_ioctl_comm_count *counts;
2357 struct cYAML *msg_statistics = NULL;
2359 msg_statistics = cYAML_create_object(item,
2360 (char *)gmsg_stat_names[k]);
2361 if (msg_statistics == NULL)
2364 counts = get_counts(&msg_stats, k);
2368 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2373 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2374 hstats.hlni_nid = ni_data->lic_nid;
2375 /* grab health stats */
2376 rc = l_ioctl(LNET_DEV_ID,
2377 IOC_LIBCFS_GET_LOCAL_HSTATS,
2381 goto continue_without_msg_stats;
2383 yhstats = cYAML_create_object(item, "health stats");
2386 if (cYAML_create_number(yhstats, "fatal_error",
2387 hstats.hlni_fatal_error)
2390 if (cYAML_create_number(yhstats, "health value",
2391 hstats.hlni_health_value)
2394 if (cYAML_create_number(yhstats, "interrupts",
2395 hstats.hlni_local_interrupt)
2398 if (cYAML_create_number(yhstats, "dropped",
2399 hstats.hlni_local_dropped)
2402 if (cYAML_create_number(yhstats, "aborted",
2403 hstats.hlni_local_aborted)
2406 if (cYAML_create_number(yhstats, "no route",
2407 hstats.hlni_local_no_route)
2410 if (cYAML_create_number(yhstats, "timeouts",
2411 hstats.hlni_local_timeout)
2414 if (cYAML_create_number(yhstats, "error",
2415 hstats.hlni_local_error)
2418 if (cYAML_create_number(yhstats, "ping_count",
2419 hstats.hlni_ping_count)
2422 if (cYAML_create_number(yhstats, "next_ping",
2423 hstats.hlni_next_ping)
2427 continue_without_msg_stats:
2428 tunables = cYAML_create_object(item, "tunables");
2432 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2433 if (rc != LUSTRE_CFG_RC_NO_ERR)
2436 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2437 tunables = cYAML_create_object(item,
2439 if (tunables == NULL)
2443 rc = lustre_ni_show_tunables(tunables,
2444 LNET_NETTYP(rc_net),
2445 &lnd->lt_tun, backup);
2446 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2447 rc != LUSTRE_CFG_RC_NO_MATCH)
2451 cYAML_create_number(item, "dev cpt",
2452 ni_data->lic_dev_cpt) == NULL)
2455 /* out put the CPTs in the format: "[x,x,x,...]" */
2457 limit = str_buf + str_buf_len - 3;
2458 pos += scnprintf(pos, limit - pos, "\"[");
2459 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2460 j < ni_data->lic_ncpts &&
2462 pos += scnprintf(pos, limit - pos,
2463 "%d", ni_data->lic_cpts[j]);
2464 if ((j + 1) < ni_data->lic_ncpts)
2465 pos += scnprintf(pos, limit - pos, ",");
2467 snprintf(pos, 3, "]\"");
2469 if (ni_data->lic_ncpts >= 1 &&
2470 cYAML_create_string(item, "CPT",
2476 /* Print out the net information only if show_rc is not provided */
2477 if (show_rc == NULL)
2478 cYAML_print_tree(root);
2480 if (l_errno != ENOENT) {
2483 "\"cannot get networks: %s\"",
2488 rc = LUSTRE_CFG_RC_NO_ERR;
2490 snprintf(err_str, sizeof(err_str), "\"success\"");
2492 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2493 cYAML_free_tree(root);
2494 } else if (show_rc != NULL && *show_rc != NULL) {
2495 struct cYAML *show_node;
2496 /* find the net node, if one doesn't exist
2497 * then insert one. Otherwise add to the one there
2499 show_node = cYAML_get_object_item(*show_rc, "net");
2500 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2501 cYAML_insert_child(show_node, first_seq);
2504 } else if (show_node == NULL) {
2505 cYAML_insert_sibling((*show_rc)->cy_child,
2509 cYAML_free_tree(root);
2515 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2520 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2522 struct lnet_ioctl_config_data data;
2523 int rc = LUSTRE_CFG_RC_NO_ERR;
2524 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2526 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2527 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2529 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2534 "\"cannot %s routing %s\"",
2535 (enable) ? "enable" : "disable", strerror(errno));
2540 cYAML_build_error(rc, seq_no,
2541 (enable) ? ADD_CMD : DEL_CMD,
2542 "routing", err_str, err_rc);
2547 int ioctl_set_value(__u32 val, int ioc, char *name,
2548 int seq_no, struct cYAML **err_rc)
2550 struct lnet_ioctl_set_value data;
2551 int rc = LUSTRE_CFG_RC_NO_ERR;
2552 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2554 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2555 data.sv_value = val;
2557 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2562 "\"cannot configure %s to %d: %s\"", name,
2563 val, strerror(errno));
2566 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2571 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2573 int rc = LUSTRE_CFG_RC_NO_ERR;
2574 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2575 char val[LNET_MAX_STR_LEN];
2577 snprintf(val, sizeof(val), "%d", intrv);
2579 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2580 1, strlen(val) + 1);
2582 snprintf(err_str, sizeof(err_str),
2583 "\"cannot configure recovery interval: %s\"",
2586 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2591 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2593 int rc = LUSTRE_CFG_RC_NO_ERR;
2594 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2595 char val[LNET_MAX_STR_LEN];
2597 snprintf(val, sizeof(val), "%d", sen);
2599 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2600 1, strlen(val) + 1);
2602 snprintf(err_str, sizeof(err_str),
2603 "\"cannot configure router health sensitivity: %s\"",
2606 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2611 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2613 int rc = LUSTRE_CFG_RC_NO_ERR;
2614 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2615 char val[LNET_MAX_STR_LEN];
2617 snprintf(val, sizeof(val), "%d", sen);
2619 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2620 1, strlen(val) + 1);
2622 snprintf(err_str, sizeof(err_str),
2623 "\"cannot configure health sensitivity: %s\"",
2626 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2631 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2633 int rc = LUSTRE_CFG_RC_NO_ERR;
2634 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2635 char val[LNET_MAX_STR_LEN];
2637 snprintf(val, sizeof(val), "%d", timeout);
2639 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2640 1, strlen(val) + 1);
2642 snprintf(err_str, sizeof(err_str),
2643 "\"cannot configure transaction timeout: %s\"",
2646 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2651 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2653 int rc = LUSTRE_CFG_RC_NO_ERR;
2654 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2655 char val[LNET_MAX_STR_LEN];
2657 snprintf(val, sizeof(val), "%d", count);
2659 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2660 1, strlen(val) + 1);
2662 snprintf(err_str, sizeof(err_str),
2663 "\"cannot configure retry count: %s\"",
2666 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2671 int lustre_lnet_config_response_tracking(int val, int seq_no,
2672 struct cYAML **err_rc)
2674 int rc = LUSTRE_CFG_RC_NO_ERR;
2675 char err_str[LNET_MAX_STR_LEN];
2676 char val_str[LNET_MAX_STR_LEN];
2678 if (val < 0 || val > 3) {
2679 rc = LUSTRE_CFG_RC_BAD_PARAM;
2680 snprintf(err_str, sizeof(err_str),
2681 "\"Valid values are: 0, 1, 2, or 3\"");
2683 snprintf(err_str, sizeof(err_str), "\"success\"");
2685 snprintf(val_str, sizeof(val_str), "%d", val);
2687 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2688 val_str, 1, strlen(val_str) + 1);
2690 snprintf(err_str, sizeof(err_str),
2691 "\"cannot configure response tracking: %s\"",
2695 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2701 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2702 struct cYAML **err_rc)
2704 int rc = LUSTRE_CFG_RC_NO_ERR;
2705 char err_str[LNET_MAX_STR_LEN];
2706 char val_str[LNET_MAX_STR_LEN];
2709 rc = LUSTRE_CFG_RC_BAD_PARAM;
2710 snprintf(err_str, sizeof(err_str),
2711 "\"Must be greater than or equal to 0\"");
2713 snprintf(err_str, sizeof(err_str), "\"success\"");
2715 snprintf(val_str, sizeof(val_str), "%d", val);
2717 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2718 val_str, 1, strlen(val_str) + 1);
2720 snprintf(err_str, sizeof(err_str),
2721 "\"cannot configure recovery limit: %s\"",
2725 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2731 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2733 int rc = LUSTRE_CFG_RC_NO_ERR;
2734 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2735 char val[LNET_MAX_STR_LEN];
2737 snprintf(val, sizeof(val), "%d", max);
2739 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2740 1, strlen(val) + 1);
2742 snprintf(err_str, sizeof(err_str),
2743 "\"cannot configure max interfaces: %s\"",
2746 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2751 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2753 int rc = LUSTRE_CFG_RC_NO_ERR;
2754 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2755 char val[LNET_MAX_STR_LEN];
2757 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2759 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2760 1, strlen(val) + 1);
2762 snprintf(err_str, sizeof(err_str),
2763 "\"cannot configure discovery: %s\"",
2766 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2772 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2773 struct cYAML **err_rc)
2775 int rc = LUSTRE_CFG_RC_NO_ERR;
2776 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2777 char val[LNET_MAX_STR_LEN];
2779 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2781 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2782 1, strlen(val) + 1);
2784 snprintf(err_str, sizeof(err_str),
2785 "\"cannot configure drop asym route: %s\"",
2788 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2795 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2797 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2798 "numa_range", seq_no, err_rc);
2801 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2802 struct cYAML **err_rc)
2804 struct lnet_ioctl_config_data data;
2805 int rc = LUSTRE_CFG_RC_NO_ERR;
2806 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2808 /* -1 indicates to ignore changes to this field */
2809 if (tiny < -1 || small < -1 || large < -1) {
2812 "\"tiny, small and large must be >= 0\"");
2813 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2817 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2818 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2819 data.cfg_config_u.cfg_buffers.buf_small = small;
2820 data.cfg_config_u.cfg_buffers.buf_large = large;
2822 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2827 "\"cannot configure buffers: %s\"", strerror(errno));
2832 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2837 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2838 struct cYAML **err_rc)
2840 int rc = LUSTRE_CFG_RC_NO_ERR;
2841 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2842 char interval_str[LNET_MAX_STR_LEN];
2844 if (interval <= 0) {
2845 rc = LUSTRE_CFG_RC_BAD_PARAM;
2846 snprintf(err_str, sizeof(err_str),
2847 "\"must be strictly positive\"");
2850 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2852 rc = write_sysfs_file(modparam_path,
2853 "lnet_max_recovery_ping_interval",
2855 strlen(interval_str) + 1);
2857 snprintf(err_str, sizeof(err_str),
2858 "\"cannot configure maximum recovery ping interval: %s\"",
2862 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2869 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2870 struct cYAML **err_rc, bool backup)
2872 struct lnet_ioctl_config_data *data;
2873 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2874 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2877 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2878 int buf_count[LNET_NRBPOOLS] = {0};
2879 struct cYAML *root = NULL, *pools_node = NULL,
2880 *type_node = NULL, *item = NULL, *cpt = NULL,
2881 *first_seq = NULL, *buffers = NULL;
2883 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2884 char node_name[LNET_MAX_STR_LEN];
2887 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2891 data = (struct lnet_ioctl_config_data *)buf;
2893 root = cYAML_create_object(NULL, NULL);
2898 pools_node = cYAML_create_object(root, "routing");
2900 pools_node = cYAML_create_seq(root, "routing");
2901 if (pools_node == NULL)
2905 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2906 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2907 sizeof(struct lnet_ioctl_pool_cfg);
2908 data->cfg_count = i;
2910 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2918 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2921 goto calculate_buffers;
2923 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2924 item = cYAML_create_seq_item(pools_node);
2928 if (first_seq == NULL)
2931 cpt = cYAML_create_object(item, node_name);
2936 /* create the tree and print */
2937 for (j = 0; j < LNET_NRBPOOLS; j++) {
2939 type_node = cYAML_create_object(cpt, pools[j]);
2940 if (type_node == NULL)
2944 cYAML_create_number(type_node, "npages",
2945 pool_cfg->pl_pools[j].pl_npages)
2949 cYAML_create_number(type_node, "nbuffers",
2950 pool_cfg->pl_pools[j].
2951 pl_nbuffers) == NULL)
2954 cYAML_create_number(type_node, "credits",
2955 pool_cfg->pl_pools[j].
2956 pl_credits) == NULL)
2959 cYAML_create_number(type_node, "mincredits",
2960 pool_cfg->pl_pools[j].
2961 pl_mincredits) == NULL)
2963 /* keep track of the total count for each of the
2964 * tiny, small and large buffers */
2965 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2969 if (pool_cfg != NULL) {
2971 if (cYAML_create_number(pools_node, "enable",
2972 pool_cfg->pl_routing) ==
2976 goto add_buffer_section;
2979 item = cYAML_create_seq_item(pools_node);
2983 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2989 /* create a buffers entry in the show. This is necessary so that
2990 * if the YAML output is used to configure a node, the buffer
2991 * configuration takes hold */
2992 buffers = cYAML_create_object(root, "buffers");
2993 if (buffers == NULL)
2996 for (i = 0; i < LNET_NRBPOOLS; i++) {
2997 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
3001 if (show_rc == NULL)
3002 cYAML_print_tree(root);
3004 if (l_errno != ENOENT) {
3007 "\"cannot get routing information: %s\"",
3012 rc = LUSTRE_CFG_RC_NO_ERR;
3014 snprintf(err_str, sizeof(err_str), "\"success\"");
3015 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 *routing_node;
3023 /* there should exist only one routing block and one
3024 * buffers block. If there already exists a previous one
3025 * then don't add another */
3026 routing_node = cYAML_get_object_item(*show_rc, "routing");
3027 if (routing_node == NULL) {
3028 cYAML_insert_sibling((*show_rc)->cy_child,
3032 cYAML_free_tree(root);
3038 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3043 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3044 struct cYAML **show_rc, struct cYAML **err_rc,
3048 * TODO: This function is changing in a future patch to accommodate
3049 * PEER_LIST and proper filtering on any nid of the peer
3051 struct lnet_ioctl_peer_cfg peer_info;
3052 struct lnet_peer_ni_credit_info *lpni_cri;
3053 struct lnet_ioctl_element_stats *lpni_stats;
3054 struct lnet_ioctl_element_msg_stats *msg_stats;
3055 struct lnet_ioctl_peer_ni_hstats *hstats;
3056 struct lnet_ioctl_construct_udsp_info udsp_info;
3058 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3063 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3064 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3065 *msg_statistics = NULL, *statistics = NULL,
3067 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3068 struct lnet_process_id *list = NULL;
3073 /* create struct cYAML root object */
3074 root = cYAML_create_object(NULL, NULL);
3078 peer_root = cYAML_create_seq(root, "peer");
3079 if (peer_root == NULL)
3083 size = count * sizeof(struct lnet_process_id);
3084 list = malloc(size);
3090 list[0].nid = libcfs_str2nid(knid);
3094 memset(&peer_info, 0, sizeof(peer_info));
3095 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3096 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3097 peer_info.prcfg_size = size;
3098 peer_info.prcfg_bulk = list;
3101 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3103 count = peer_info.prcfg_count;
3107 if (l_errno != E2BIG) {
3110 "\"cannot get peer list: %s\"",
3116 size = peer_info.prcfg_size;
3117 list = malloc(size);
3126 data = malloc(size);
3132 for (i = 0; i < count; i++) {
3134 memset(&peer_info, 0, sizeof(peer_info));
3135 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3136 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3137 peer_info.prcfg_prim_nid = list[i].nid;
3138 peer_info.prcfg_size = size;
3139 peer_info.prcfg_bulk = data;
3142 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3147 if (l_errno != E2BIG) {
3150 "\"cannot get peer information: %s\"",
3156 size = peer_info.prcfg_size;
3157 data = malloc(size);
3165 peer = cYAML_create_seq_item(peer_root);
3169 if (first_seq == NULL)
3172 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3173 if (cYAML_create_string(peer, "primary nid",
3174 libcfs_nid2str(pnid))
3177 if (cYAML_create_string(peer, "Multi-Rail",
3178 peer_info.prcfg_mr ? "True" : "False")
3182 * print out the state of the peer only if details are
3187 cYAML_create_number(peer, "peer state",
3188 peer_info.prcfg_state)
3193 tmp = cYAML_create_seq(peer, "peer ni");
3198 for (j = 0; j < peer_info.prcfg_count; j++) {
3200 lpni_cri = (void*)nidp + sizeof(nidp);
3201 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3202 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3203 hstats = (void *)msg_stats + sizeof(*msg_stats);
3204 lpni_data = (void *)hstats + sizeof(*hstats);
3206 peer_ni = cYAML_create_seq_item(tmp);
3207 if (peer_ni == NULL)
3210 if (cYAML_create_string(peer_ni, "nid",
3211 libcfs_nid2str(*nidp))
3219 goto continue_without_udsp_info;
3221 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3222 udsp_info.cud_nid = *nidp;
3223 udsp_info.cud_peer = true;
3224 rc = l_ioctl(LNET_DEV_ID,
3225 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3229 goto continue_without_udsp_info;
3232 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3238 continue_without_udsp_info:
3239 if (cYAML_create_string(peer_ni, "state",
3240 lpni_cri->cr_aliveness)
3247 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3248 lpni_cri->cr_ni_peer_tx_credits)
3252 if (cYAML_create_number(peer_ni, "available_tx_credits",
3253 lpni_cri->cr_peer_tx_credits)
3257 if (cYAML_create_number(peer_ni, "min_tx_credits",
3258 lpni_cri->cr_peer_min_tx_credits)
3262 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3263 lpni_cri->cr_peer_tx_qnob)
3267 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3268 lpni_cri->cr_peer_rtr_credits)
3272 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3273 lpni_cri->cr_peer_min_rtr_credits)
3277 if (cYAML_create_number(peer_ni, "refcount",
3278 lpni_cri->cr_refcount) == NULL)
3281 statistics = cYAML_create_object(peer_ni, "statistics");
3282 if (statistics == NULL)
3285 if (cYAML_create_number(statistics, "send_count",
3286 lpni_stats->iel_send_count)
3290 if (cYAML_create_number(statistics, "recv_count",
3291 lpni_stats->iel_recv_count)
3295 if (cYAML_create_number(statistics, "drop_count",
3296 lpni_stats->iel_drop_count)
3303 for (k = 0; k < 3; k++) {
3304 struct lnet_ioctl_comm_count *counts;
3306 msg_statistics = cYAML_create_object(peer_ni,
3307 (char *) gmsg_stat_names[k]);
3308 if (msg_statistics == NULL)
3311 counts = get_counts(msg_stats, k);
3315 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3320 yhstats = cYAML_create_object(peer_ni, "health stats");
3323 if (cYAML_create_number(yhstats, "health value",
3324 hstats->hlpni_health_value)
3327 if (cYAML_create_number(yhstats, "dropped",
3328 hstats->hlpni_remote_dropped)
3331 if (cYAML_create_number(yhstats, "timeout",
3332 hstats->hlpni_remote_timeout)
3335 if (cYAML_create_number(yhstats, "error",
3336 hstats->hlpni_remote_error)
3339 if (cYAML_create_number(yhstats, "network timeout",
3340 hstats->hlpni_network_timeout)
3343 if (cYAML_create_number(yhstats, "ping_count",
3344 hstats->hlpni_ping_count)
3348 if (cYAML_create_number(yhstats, "next_ping",
3349 hstats->hlpni_next_ping)
3356 /* print output iff show_rc is not provided */
3357 if (show_rc == NULL)
3358 cYAML_print_tree(root);
3360 snprintf(err_str, sizeof(err_str), "\"success\"");
3361 rc = LUSTRE_CFG_RC_NO_ERR;
3366 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3367 cYAML_free_tree(root);
3368 } else if (show_rc != NULL && *show_rc != NULL) {
3369 struct cYAML *show_node;
3370 /* find the peer node, if one doesn't exist then
3371 * insert one. Otherwise add to the one there
3373 show_node = cYAML_get_object_item(*show_rc,
3375 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3376 cYAML_insert_child(show_node, first_seq);
3379 } else if (show_node == NULL) {
3380 cYAML_insert_sibling((*show_rc)->cy_child,
3384 cYAML_free_tree(root);
3390 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3396 int lustre_lnet_list_peer(int seq_no,
3397 struct cYAML **show_rc, struct cYAML **err_rc)
3399 struct lnet_ioctl_peer_cfg peer_info;
3400 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3405 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3406 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3407 struct lnet_process_id *list = NULL;
3409 memset(&peer_info, 0, sizeof(peer_info));
3411 /* create struct cYAML root object */
3412 root = cYAML_create_object(NULL, NULL);
3416 list_root = cYAML_create_seq(root, "peer list");
3417 if (list_root == NULL)
3421 size = count * sizeof(struct lnet_process_id);
3422 list = malloc(size);
3428 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3429 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3430 peer_info.prcfg_size = size;
3431 peer_info.prcfg_bulk = list;
3434 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3435 count = peer_info.prcfg_count;
3439 if (l_errno != E2BIG) {
3442 "\"cannot get peer list: %s\"",
3448 size = peer_info.prcfg_size;
3449 list = malloc(size);
3456 /* count is now the actual number of ids in the list. */
3457 for (i = 0; i < count; i++) {
3458 if (cYAML_create_string(list_root, "nid",
3459 libcfs_nid2str(list[i].nid))
3464 /* print output iff show_rc is not provided */
3465 if (show_rc == NULL)
3466 cYAML_print_tree(root);
3468 snprintf(err_str, sizeof(err_str), "\"success\"");
3469 rc = LUSTRE_CFG_RC_NO_ERR;
3474 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3475 cYAML_free_tree(root);
3476 } else if (show_rc != NULL && *show_rc != NULL) {
3477 struct cYAML *show_node;
3478 /* find the peer node, if one doesn't exist then
3479 * insert one. Otherwise add to the one there
3481 show_node = cYAML_get_object_item(*show_rc,
3483 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3484 cYAML_insert_child(show_node, first_seq);
3487 } else if (show_node == NULL) {
3488 cYAML_insert_sibling((*show_rc)->cy_child,
3492 cYAML_free_tree(root);
3498 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3504 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3507 struct cYAML *show_node;
3509 show_node = cYAML_get_object_item(show_rc, "global");
3510 if (show_node != NULL)
3511 cYAML_insert_sibling(show_node->cy_child,
3514 cYAML_insert_sibling(show_rc->cy_child,
3519 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3520 char *name, __u64 value,
3521 struct cYAML **show_rc,
3522 struct cYAML **err_rc, int err)
3524 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3525 struct cYAML *root = NULL, *global = NULL;
3532 root = cYAML_create_object(NULL, NULL);
3536 global = cYAML_create_object(root, "global");
3540 if (cYAML_create_number(global, name,
3544 if (show_rc == NULL)
3545 cYAML_print_tree(root);
3547 snprintf(err_str, err_len, "\"success\"");
3549 rc = LUSTRE_CFG_RC_NO_ERR;
3552 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3553 cYAML_free_tree(root);
3554 } else if (show_rc != NULL && *show_rc != NULL) {
3555 add_to_global(*show_rc, global, root);
3560 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3565 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3566 struct cYAML **show_rc,
3567 struct cYAML **err_rc)
3569 struct lnet_ioctl_set_value data;
3572 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3574 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3576 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3581 "\"cannot get %s: %s\"",
3582 name, strerror(l_errno));
3585 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3586 data.sv_value, show_rc, err_rc, l_errno);
3589 int lustre_lnet_show_recov_intrv(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 intrv = -1, l_errno = 0;
3595 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3597 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3601 snprintf(err_str, sizeof(err_str),
3602 "\"cannot get recovery interval: %d\"", rc);
3607 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3608 "recovery_interval", intrv, show_rc,
3612 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3613 struct cYAML **err_rc)
3615 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3616 char val[LNET_MAX_STR_LEN];
3617 int sen = -1, l_errno = 0;
3618 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3620 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3624 snprintf(err_str, sizeof(err_str),
3625 "\"cannot get health sensitivity: %d\"", rc);
3630 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3631 "health_sensitivity", sen, show_rc,
3635 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3636 struct cYAML **err_rc)
3638 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3639 char val[LNET_MAX_STR_LEN];
3640 int sen = -1, l_errno = 0;
3641 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3643 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3647 snprintf(err_str, sizeof(err_str),
3648 "\"cannot get router sensitivity percentage: %d\"", rc);
3653 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3654 "router_sensitivity", sen, show_rc,
3658 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3659 struct cYAML **err_rc)
3661 char val[LNET_MAX_STR_LEN];
3662 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3669 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3672 snprintf(err_str, sizeof(err_str),
3673 "\"cannot get LND timeout: %d\"", rc);
3674 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3675 "lnd_timeout", lnd_to, show_rc,
3679 fd = open(path.gl_pathv[0], O_RDONLY);
3682 snprintf(err_str, sizeof(err_str),
3683 "\"error opening %s\"", path.gl_pathv[0]);
3687 rc = read(fd, val, sizeof(val));
3694 snprintf(err_str, sizeof(err_str),
3695 "\"error reading %s\"", path.gl_pathv[0]);
3702 cfs_free_param_data(&path);
3704 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3705 "lnd_timeout", lnd_to, show_rc,
3709 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3710 struct cYAML **err_rc)
3712 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3713 char val[LNET_MAX_STR_LEN];
3714 int tto = -1, l_errno = 0;
3715 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3717 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3721 snprintf(err_str, sizeof(err_str),
3722 "\"cannot get transaction timeout: %d\"", rc);
3727 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3728 "transaction_timeout", tto, show_rc,
3732 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3733 struct cYAML **err_rc)
3735 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3736 char val[LNET_MAX_STR_LEN];
3737 int retry_count = -1, l_errno = 0;
3738 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3740 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3744 snprintf(err_str, sizeof(err_str),
3745 "\"cannot get retry count: %d\"", rc);
3747 retry_count = atoi(val);
3750 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3751 "retry_count", retry_count, show_rc,
3755 int lustre_lnet_calc_service_id(__u64 *service_id)
3757 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3758 char val[LNET_MAX_STR_LEN];
3759 int service_port = -1, l_errno = 0;
3761 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3765 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3766 strerror(l_errno), -l_errno);
3769 service_port = atoi(val);
3772 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3774 return LUSTRE_CFG_RC_NO_ERR;
3777 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3780 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3782 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3783 struct lnet_ioctl_config_ni *ni_data;
3784 struct lnet_ioctl_config_lnd_tunables *lnd;
3785 struct lnet_ioctl_element_stats *stats;
3786 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3787 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3788 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3789 int if_cnt = 0, prc;
3790 char syscmdbuf[LNET_MAX_STR_LEN];
3791 char cmdpath[LNET_MAX_STR_LEN];
3792 bool use_custom = false;
3794 buf = calloc(1, buf_size);
3798 ni_data = (struct lnet_ioctl_config_ni *)buf;
3801 ifstr_ptr = ifstr_buf;
3806 memset(buf, 0, buf_size);
3808 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3809 /* set the ioc_len to the proper value since INIT assumes
3812 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3813 ni_data->lic_idx = i;
3815 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3821 rc_net = LNET_NIDNET(ni_data->lic_nid);
3823 /* only need to setup routing for tcp */
3824 if (LNET_NETTYP(rc_net) != SOCKLND)
3827 /* don't add interfaces unless there is at least one
3830 if (strlen(ni_data->lic_ni_intf) > 0) {
3832 strcat(ifstr_ptr, ",");
3833 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3838 if (l_errno != ENOENT) {
3841 "\"cannot get networks: %s\"",
3846 rc = LUSTRE_CFG_RC_NO_ERR;
3849 snprintf(err_str, sizeof(err_str), "\"success\"");
3852 tmp_ptr = getenv("KSOCKLND_CONFIG");
3854 tmp_ptr2 = strrchr(tmp_ptr, '/');
3855 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3856 snprintf(cmdpath, sizeof(cmdpath), "%s",
3863 snprintf(cmdpath, sizeof(cmdpath),
3864 "/usr/sbin/ksocklnd-config");
3866 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3872 "\"snprintf failed : %s\"",
3875 } else if (prc >= LNET_MAX_STR_LEN) {
3876 snprintf(err_str, sizeof(err_str),
3877 "\"ksocklnd-config: argument too long\"");
3879 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3880 cmdpath, ifstr_ptr);
3886 "\"snprintf failed : %s\"",
3892 rc = system(syscmdbuf);
3897 "\"failed to execute ksocklnd-config : %s\"",
3907 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3914 lnet_nid_cpt_hash(lnet_nid_t nid, long int number, unsigned int cpt_bits)
3917 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
3923 if (lnd == KFILND || lnd == GNILND) {
3924 cpt = hash_long(key, cpt_bits);
3926 /* NB: The number of CPTs needn't be a power of 2 */
3928 cpt = (key + cpt + (cpt >> 1)) % number;
3930 __u64 pair_bits = 0x0001000100010001LLU;
3931 __u64 mask = pair_bits * 0xFF;
3933 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
3934 * (number of CPTs) to match nid to a CPT.
3936 pair_sum = (key & mask) + ((key >> 8) & mask);
3937 pair_sum = (pair_sum * pair_bits) >> 48;
3938 cpt = (unsigned int)(pair_sum) % number;
3944 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3946 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3948 unsigned int cpt_bits;
3951 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3956 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3961 fprintf(stderr, "error:\n msg: \"number of CPTs must be >= 1\"\n");
3966 while ((1 << cpt_bits) < ncpts)
3969 nid = libcfs_str2nid(nidc);
3970 if (nid == LNET_NID_ANY) {
3971 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3976 return (int)lnet_nid_cpt_hash(nid, ncpts, cpt_bits);
3979 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3980 struct cYAML **show_rc, struct cYAML **err_rc)
3982 struct lnet_ioctl_recovery_list nid_list;
3983 struct cYAML *root = NULL, *nids = NULL;
3985 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3987 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3988 nid_list.rlst_type = type;
3990 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3996 if (nid_list.rlst_num_nids == 0)
3999 root = cYAML_create_object(NULL, NULL);
4003 nids = cYAML_create_object(root, name);
4009 for (i = 0; i < nid_list.rlst_num_nids; i++) {
4010 char nidenum[LNET_MAX_STR_LEN];
4011 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
4012 if (!cYAML_create_string(nids, nidenum,
4013 libcfs_nid2str(nid_list.rlst_nid_array[i])))
4017 snprintf(err_str, sizeof(err_str), "success\n");
4022 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4023 cYAML_free_tree(root);
4024 } else if (show_rc != NULL && *show_rc != NULL) {
4025 struct cYAML *show_node;
4026 /* find the net node, if one doesn't exist
4027 * then insert one. Otherwise add to the one there
4029 show_node = cYAML_get_object_item(*show_rc, name);
4030 if (show_node != NULL && cYAML_is_sequence(show_node)) {
4031 cYAML_insert_child(show_node, nids);
4034 } else if (show_node == NULL) {
4035 cYAML_insert_sibling((*show_rc)->cy_child,
4039 cYAML_free_tree(root);
4045 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
4050 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
4051 struct cYAML **err_rc)
4053 struct libcfs_ioctl_data data;
4055 char err_str[LNET_MAX_STR_LEN] = "Error";
4056 lnet_nid_t pnid = LNET_NID_ANY;
4059 rc = LUSTRE_CFG_RC_BAD_PARAM;
4060 snprintf(err_str, LNET_MAX_STR_LEN,
4061 "--nid must be specified");
4065 pnid = libcfs_str2nid(peer_nid);
4066 if (pnid == LNET_NID_ANY) {
4067 rc = LUSTRE_CFG_RC_BAD_PARAM;
4068 snprintf(err_str, LNET_MAX_STR_LEN,
4069 "badly formatted primary NID: %s", peer_nid);
4073 LIBCFS_IOC_INIT(data);
4074 data.ioc_net = LNET_NIDNET(pnid);
4075 data.ioc_nid = pnid;
4077 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4081 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4087 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4088 struct cYAML **err_rc)
4090 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4091 seq_no, show_rc, err_rc);
4094 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4095 struct cYAML **err_rc)
4097 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4098 seq_no, show_rc, err_rc);
4101 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4102 struct cYAML **err_rc)
4104 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4105 char val[LNET_MAX_STR_LEN];
4106 int rsp_tracking = -1, l_errno = 0;
4107 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4109 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4113 snprintf(err_str, sizeof(err_str),
4114 "\"cannot get lnet_response_tracking value: %d\"", rc);
4116 rsp_tracking = atoi(val);
4119 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4120 "response_tracking", rsp_tracking,
4121 show_rc, err_rc, l_errno);
4124 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4125 struct cYAML **err_rc)
4127 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4128 char val[LNET_MAX_STR_LEN];
4129 int recov_limit = -1, l_errno = 0;
4130 char err_str[LNET_MAX_STR_LEN];
4132 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4134 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4138 snprintf(err_str, sizeof(err_str),
4139 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4141 recov_limit = atoi(val);
4144 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4145 "recovery_limit", recov_limit,
4146 show_rc, err_rc, l_errno);
4149 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4150 struct cYAML **show_rc,
4151 struct cYAML **err_rc)
4153 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4154 char val[LNET_MAX_STR_LEN];
4155 int interval = -1, l_errno = 0;
4156 char err_str[LNET_MAX_STR_LEN];
4158 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4160 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4161 val, 1, sizeof(val));
4164 snprintf(err_str, sizeof(err_str),
4165 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4168 interval = atoi(val);
4171 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4172 "max_recovery_ping_interval", interval,
4173 show_rc, err_rc, l_errno);
4177 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4178 struct cYAML **err_rc)
4180 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4181 char val[LNET_MAX_STR_LEN];
4182 int max_intf = -1, l_errno = 0;
4183 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4185 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4189 snprintf(err_str, sizeof(err_str),
4190 "\"cannot get max interfaces: %d\"", rc);
4192 max_intf = atoi(val);
4195 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4196 "max_interfaces", max_intf, show_rc,
4200 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4201 struct cYAML **err_rc)
4203 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4204 char val[LNET_MAX_STR_LEN];
4205 int discovery = -1, l_errno = 0;
4206 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4208 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4212 snprintf(err_str, sizeof(err_str),
4213 "\"cannot get discovery setting: %d\"", rc);
4216 * The kernel stores a discovery disabled value. User space
4217 * shows whether discovery is enabled. So the value must be
4220 discovery = !atoi(val);
4223 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4224 "discovery", discovery, show_rc,
4228 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4229 struct cYAML **err_rc)
4231 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4232 char val[LNET_MAX_STR_LEN];
4233 int drop_asym_route = -1, l_errno = 0;
4234 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4236 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4240 snprintf(err_str, sizeof(err_str),
4241 "\"cannot get drop asym route setting: %d\"", rc);
4243 drop_asym_route = atoi(val);
4246 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4247 "drop_asym_route", drop_asym_route,
4248 show_rc, err_rc, l_errno);
4251 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4252 struct cYAML **err_rc)
4254 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4255 "numa_range", show_rc, err_rc);
4258 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4259 struct cYAML **err_rc)
4261 struct lnet_ioctl_lnet_stats data;
4262 struct lnet_counters *cntrs;
4265 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4266 struct cYAML *root = NULL, *stats = NULL;
4268 LIBCFS_IOC_INIT_V2(data, st_hdr);
4270 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4275 "\"cannot get lnet statistics: %s\"",
4281 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4283 cntrs = &data.st_cntrs;
4285 root = cYAML_create_object(NULL, NULL);
4289 stats = cYAML_create_object(root, "statistics");
4293 if (!cYAML_create_number(stats, "msgs_alloc",
4294 cntrs->lct_common.lcc_msgs_alloc))
4297 if (!cYAML_create_number(stats, "msgs_max",
4298 cntrs->lct_common.lcc_msgs_max))
4301 if (!cYAML_create_number(stats, "rst_alloc",
4302 cntrs->lct_health.lch_rst_alloc))
4305 if (!cYAML_create_number(stats, "errors",
4306 cntrs->lct_common.lcc_errors))
4309 if (!cYAML_create_number(stats, "send_count",
4310 cntrs->lct_common.lcc_send_count))
4313 if (!cYAML_create_number(stats, "resend_count",
4314 cntrs->lct_health.lch_resend_count))
4317 if (!cYAML_create_number(stats, "response_timeout_count",
4318 cntrs->lct_health.lch_response_timeout_count))
4321 if (!cYAML_create_number(stats, "local_interrupt_count",
4322 cntrs->lct_health.lch_local_interrupt_count))
4325 if (!cYAML_create_number(stats, "local_dropped_count",
4326 cntrs->lct_health.lch_local_dropped_count))
4329 if (!cYAML_create_number(stats, "local_aborted_count",
4330 cntrs->lct_health.lch_local_aborted_count))
4333 if (!cYAML_create_number(stats, "local_no_route_count",
4334 cntrs->lct_health.lch_local_no_route_count))
4337 if (!cYAML_create_number(stats, "local_timeout_count",
4338 cntrs->lct_health.lch_local_timeout_count))
4341 if (!cYAML_create_number(stats, "local_error_count",
4342 cntrs->lct_health.lch_local_error_count))
4345 if (!cYAML_create_number(stats, "remote_dropped_count",
4346 cntrs->lct_health.lch_remote_dropped_count))
4349 if (!cYAML_create_number(stats, "remote_error_count",
4350 cntrs->lct_health.lch_remote_error_count))
4353 if (!cYAML_create_number(stats, "remote_timeout_count",
4354 cntrs->lct_health.lch_remote_timeout_count))
4357 if (!cYAML_create_number(stats, "network_timeout_count",
4358 cntrs->lct_health.lch_network_timeout_count))
4361 if (!cYAML_create_number(stats, "recv_count",
4362 cntrs->lct_common.lcc_recv_count))
4365 if (!cYAML_create_number(stats, "route_count",
4366 cntrs->lct_common.lcc_route_count))
4369 if (!cYAML_create_number(stats, "drop_count",
4370 cntrs->lct_common.lcc_drop_count))
4373 if (!cYAML_create_number(stats, "send_length",
4374 cntrs->lct_common.lcc_send_length))
4377 if (!cYAML_create_number(stats, "recv_length",
4378 cntrs->lct_common.lcc_recv_length))
4381 if (!cYAML_create_number(stats, "route_length",
4382 cntrs->lct_common.lcc_route_length))
4385 if (!cYAML_create_number(stats, "drop_length",
4386 cntrs->lct_common.lcc_drop_length))
4390 cYAML_print_tree(root);
4392 snprintf(err_str, sizeof(err_str), "\"success\"");
4393 rc = LUSTRE_CFG_RC_NO_ERR;
4395 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4396 cYAML_free_tree(root);
4397 } else if (show_rc != NULL && *show_rc != NULL) {
4398 cYAML_insert_sibling((*show_rc)->cy_child,
4405 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4410 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4412 struct libcfs_ioctl_data data;
4413 int rc = LUSTRE_CFG_RC_NO_ERR;
4415 char err_str[LNET_MAX_STR_LEN];
4417 LIBCFS_IOC_INIT(data);
4419 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4424 "\"cannot reset lnet statistics: %s\"",
4428 snprintf(err_str, sizeof(err_str), "\"success\"");
4429 rc = LUSTRE_CFG_RC_NO_ERR;
4432 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4436 typedef int (*cmd_handler_t)(struct cYAML *tree,
4437 struct cYAML **show_rc,
4438 struct cYAML **err_rc);
4440 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4441 struct cYAML **err_rc)
4443 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4445 net = cYAML_get_object_item(tree, "net");
4446 gw = cYAML_get_object_item(tree, "gateway");
4447 hop = cYAML_get_object_item(tree, "hop");
4448 prio = cYAML_get_object_item(tree, "priority");
4449 sen = cYAML_get_object_item(tree, "health_sensitivity");
4450 seq_no = cYAML_get_object_item(tree, "seq_no");
4452 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4453 (gw) ? gw->cy_valuestring : NULL,
4454 (hop) ? hop->cy_valueint : -1,
4455 (prio) ? prio->cy_valueint : -1,
4456 (sen) ? sen->cy_valueint : -1,
4457 (seq_no) ? seq_no->cy_valueint : -1,
4463 * 0: <intf_name>['['<expr>']']
4464 * 1: <intf_name>['['<expr>']']
4466 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4467 struct lnet_dlc_network_descr *nw_descr)
4469 struct cYAML *child = NULL;
4470 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4471 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4473 if (intf_tree == NULL || nw_descr == NULL)
4474 return LUSTRE_CFG_RC_BAD_PARAM;
4476 /* now grab all the interfaces and their cpts */
4477 child = intf_tree->cy_child;
4478 while (child != NULL) {
4479 if (child->cy_valuestring == NULL) {
4480 child = child->cy_next;
4484 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4487 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4488 child->cy_valuestring,
4489 strlen(child->cy_valuestring));
4490 if (rc != LUSTRE_CFG_RC_NO_ERR)
4494 child = child->cy_next;
4498 return LUSTRE_CFG_RC_MISSING_PARAM;
4503 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4505 list_del(&intf_descr->intf_on_network);
4506 free_intf_descr(intf_descr);
4513 yaml_extract_cmn_tunables(struct cYAML *tree,
4514 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4516 struct cYAML *tun, *item;
4518 tun = cYAML_get_object_item(tree, "tunables");
4520 item = cYAML_get_object_item(tun, "peer_timeout");
4522 tunables->lct_peer_timeout = item->cy_valueint;
4524 tunables->lct_peer_timeout = -1;
4525 item = cYAML_get_object_item(tun, "peer_credits");
4527 tunables->lct_peer_tx_credits = item->cy_valueint;
4528 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4530 tunables->lct_peer_rtr_credits = item->cy_valueint;
4531 item = cYAML_get_object_item(tun, "credits");
4533 tunables->lct_max_tx_credits = item->cy_valueint;
4542 yaml_extract_tunables(struct cYAML *tree,
4543 struct lnet_ioctl_config_lnd_tunables *tunables,
4548 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4553 lustre_yaml_extract_lnd_tunables(tree, net_type,
4560 yaml_extract_cpt(struct cYAML *tree,
4561 struct cfs_expr_list **global_cpts)
4566 smp = cYAML_get_object_item(tree, "CPT");
4568 rc = cfs_expr_list_parse(smp->cy_valuestring,
4569 strlen(smp->cy_valuestring),
4570 0, UINT_MAX, global_cpts);
4572 *global_cpts = NULL;
4578 * - net type: <net>[<NUM>]
4580 * - nid: <ip>@<net>[<NUM>]
4583 * 0: <intf_name>['['<expr>']']
4584 * 1: <intf_name>['['<expr>']']
4586 * peer_timeout: <NUM>
4587 * peer_credits: <NUM>
4588 * peer_buffer_credits: <NUM>
4591 * peercredits_hiw: <NUM>
4592 * map_on_demand: <NUM>
4593 * concurrent_sends: <NUM>
4594 * fmr_pool_size: <NUM>
4595 * fmr_flush_trigger: <NUM>
4598 * At least one interface is required. If no interfaces are provided the
4599 * network interface can not be configured.
4601 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4602 struct cYAML **err_rc)
4604 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4606 int num_entries = 0, rc;
4607 struct lnet_dlc_network_descr nw_descr;
4608 struct cfs_expr_list *global_cpts = NULL;
4609 struct lnet_ioctl_config_lnd_tunables tunables;
4612 memset(&tunables, 0, sizeof(tunables));
4613 /* Use LND defaults */
4614 tunables.lt_cmn.lct_peer_timeout = -1;
4615 tunables.lt_cmn.lct_peer_tx_credits = -1;
4616 tunables.lt_cmn.lct_peer_rtr_credits = -1;
4617 tunables.lt_cmn.lct_max_tx_credits = -1;
4619 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4620 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4622 ip2net = cYAML_get_object_item(tree, "ip2net");
4623 net = cYAML_get_object_item(tree, "net type");
4625 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4627 nw_descr.nw_id = LOLND;
4630 * if neither net nor ip2nets are present, then we can not
4631 * configure the network.
4633 if (!net && !ip2net)
4634 return LUSTRE_CFG_RC_MISSING_PARAM;
4636 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4637 if (local_nis == NULL)
4638 return LUSTRE_CFG_RC_MISSING_PARAM;
4640 if (!cYAML_is_sequence(local_nis))
4641 return LUSTRE_CFG_RC_BAD_PARAM;
4643 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4644 intf = cYAML_get_object_item(item, "interfaces");
4647 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4648 if (num_entries <= 0) {
4649 cYAML_build_error(num_entries, -1, "ni", "add",
4650 "bad interface list",
4652 return LUSTRE_CFG_RC_BAD_PARAM;
4656 found = yaml_extract_tunables(tree, &tunables,
4657 LNET_NETTYP(nw_descr.nw_id));
4658 yaml_extract_cpt(tree, &global_cpts);
4659 seq_no = cYAML_get_object_item(tree, "seq_no");
4661 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4662 (ip2net) ? ip2net->cy_valuestring : NULL,
4663 (found) ? &tunables : NULL,
4664 (seq_no) ? seq_no->cy_valueint : -1,
4667 if (global_cpts != NULL)
4668 cfs_expr_list_free(global_cpts);
4675 * - net-spec: <tcp|o2ib|gni>[NUM]
4677 * 0: <intf name>['['<expr>']']
4678 * 1: <intf name>['['<expr>']']
4680 * 0: <expr.expr.expr.expr>
4681 * 1: <expr.expr.expr.expr>
4683 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4684 struct cYAML **show_rc,
4685 struct cYAML **err_rc)
4687 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4689 struct lustre_lnet_ip2nets ip2nets;
4690 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4692 int rc = LUSTRE_CFG_RC_NO_ERR;
4693 struct cfs_expr_list *global_cpts = NULL;
4694 struct cfs_expr_list *el, *el_tmp;
4695 struct lnet_ioctl_config_lnd_tunables tunables;
4696 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4699 memset(&tunables, 0, sizeof(tunables));
4701 /* initialize all lists */
4702 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4703 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4704 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4706 net = cYAML_get_object_item(tree, "net-spec");
4708 return LUSTRE_CFG_RC_BAD_PARAM;
4710 if (net != NULL && net->cy_valuestring == NULL)
4711 return LUSTRE_CFG_RC_BAD_PARAM;
4713 /* assign the network id */
4714 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4715 if (ip2nets.ip2nets_net.nw_id == LNET_NET_ANY)
4716 return LUSTRE_CFG_RC_BAD_PARAM;
4718 seq_no = cYAML_get_object_item(tree, "seq_no");
4720 intf = cYAML_get_object_item(tree, "interfaces");
4722 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4724 return LUSTRE_CFG_RC_BAD_PARAM;
4727 ip_range = cYAML_get_object_item(tree, "ip-range");
4728 if (ip_range != NULL) {
4729 item = ip_range->cy_child;
4730 while (item != NULL) {
4731 if (item->cy_valuestring == NULL) {
4732 item = item->cy_next;
4736 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4737 item->cy_valuestring);
4739 if (rc != LUSTRE_CFG_RC_NO_ERR)
4742 item = item->cy_next;
4746 found = yaml_extract_tunables(tree, &tunables,
4747 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4748 yaml_extract_cpt(tree, &global_cpts);
4750 rc = lustre_lnet_config_ip2nets(&ip2nets,
4751 (found) ? &tunables : NULL,
4753 (seq_no) ? seq_no->cy_valueint : -1,
4756 if (global_cpts != NULL)
4757 cfs_expr_list_free(global_cpts);
4760 * don't stop because there was no match. Continue processing the
4761 * rest of the rules. If non-match then nothing is configured
4763 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4764 rc = LUSTRE_CFG_RC_NO_ERR;
4766 list_for_each_entry_safe(intf_descr, intf_tmp,
4767 &ip2nets.ip2nets_net.nw_intflist,
4769 list_del(&intf_descr->intf_on_network);
4770 free_intf_descr(intf_descr);
4773 list_for_each_entry_safe(ip_range_descr, tmp,
4774 &ip2nets.ip2nets_ip_ranges,
4776 list_del(&ip_range_descr->ipr_entry);
4777 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4779 list_del(&el->el_link);
4780 cfs_expr_list_free(el);
4782 free(ip_range_descr);
4788 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4789 struct cYAML **err_rc)
4791 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4793 int num_entries, rc;
4794 struct lnet_dlc_network_descr nw_descr;
4796 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4797 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4799 net = cYAML_get_object_item(tree, "net type");
4801 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4803 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4804 if (local_nis == NULL)
4805 return LUSTRE_CFG_RC_MISSING_PARAM;
4807 if (!cYAML_is_sequence(local_nis))
4808 return LUSTRE_CFG_RC_BAD_PARAM;
4810 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4811 intf = cYAML_get_object_item(item, "interfaces");
4814 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4815 if (num_entries <= 0) {
4816 cYAML_build_error(num_entries, -1, "ni", "add",
4817 "bad interface list",
4819 return LUSTRE_CFG_RC_BAD_PARAM;
4823 seq_no = cYAML_get_object_item(tree, "seq_no");
4825 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4826 (seq_no) ? seq_no->cy_valueint : -1,
4832 /* Create a nidstring parseable by the nidstrings library from the nid
4833 * information encoded in the CYAML structure.
4834 * NOTE: Caller must free memory allocated to nidstr
4836 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4837 char *prim_nid, int cmd)
4839 int num_strs = 0, rc;
4840 size_t buf_size, buf_pos, nidstr_len = 0;
4842 struct cYAML *child = NULL, *entry = NULL;
4844 if (cYAML_is_sequence(nids_entry)) {
4845 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4846 entry = cYAML_get_object_item(child, "nid");
4847 /* don't count an empty entry */
4848 if (!entry || !entry->cy_valuestring)
4852 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4853 if (cmd == LNETCTL_DEL_CMD) {
4855 * primary nid is present in the list of
4856 * nids so that means we want to delete
4857 * the entire peer, so no need to go
4858 * further. Just delete the entire peer.
4860 return LUSTRE_CFG_RC_NO_ERR;
4867 * + 1 for the space separating each string, and
4868 * accounts for the terminating null char
4870 nidstr_len += strlen(entry->cy_valuestring) + 1;
4875 if (num_strs == 0 && !prim_nid)
4876 return LUSTRE_CFG_RC_MISSING_PARAM;
4877 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4878 return LUSTRE_CFG_RC_NO_ERR;
4880 buffer = malloc(nidstr_len);
4882 return LUSTRE_CFG_RC_OUT_OF_MEM;
4884 /* now grab all the nids */
4887 buf_size = nidstr_len;
4889 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4890 entry = cYAML_get_object_item(child, "nid");
4891 if (!entry || !entry->cy_valuestring)
4895 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4899 rc = snprintf(buffer + buf_pos, buf_size, " ");
4900 buf_pos += (rc < buf_size) ? rc : buf_size;
4901 buf_size = nidstr_len - buf_pos;
4904 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4905 entry->cy_valuestring);
4906 buf_pos += (rc < buf_size) ? rc : buf_size;
4907 buf_size = nidstr_len - buf_pos;
4912 return LUSTRE_CFG_RC_NO_ERR;
4915 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4916 struct cYAML **err_rc, int cmd)
4918 int rc, num_nids = 0, seqn;
4919 bool mr_value = false;
4920 char *nidstr = NULL, *prim_nidstr;
4921 char err_str[LNET_MAX_STR_LEN];
4922 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4923 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4924 lnet_nid_t pnid = LNET_NID_ANY;
4927 seq_no = cYAML_get_object_item(tree, "seq_no");
4928 seqn = seq_no ? seq_no->cy_valueint : -1;
4930 prim_nid = cYAML_get_object_item(tree, "primary nid");
4931 peer_nis = cYAML_get_object_item(tree, "peer ni");
4933 rc = LUSTRE_CFG_RC_BAD_PARAM;
4934 snprintf(err_str, LNET_MAX_STR_LEN,
4935 "\"primary nid\" must be specified");
4939 prim_nidstr = prim_nid->cy_valuestring;
4941 /* if the provided primary NID is bad, no need to go any further */
4942 pnid = libcfs_str2nid(prim_nidstr);
4943 if (pnid == LNET_NID_ANY) {
4944 rc = LUSTRE_CFG_RC_BAD_PARAM;
4945 snprintf(err_str, LNET_MAX_STR_LEN,
4946 "badly formatted primary NID: %s", prim_nidstr);
4950 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4951 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4952 snprintf(err_str, LNET_MAX_STR_LEN,
4953 "No nids defined in YAML block");
4955 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4956 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4958 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4959 snprintf(err_str, LNET_MAX_STR_LEN,
4960 "Unrecognized error %d", rc);
4966 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4967 LNET_MAX_NIDS_PER_PEER,
4975 if (cmd == LNETCTL_ADD_CMD) {
4976 mr = cYAML_get_object_item(tree, "Multi-Rail");
4978 if (mr && mr->cy_valuestring) {
4979 if (strcmp(mr->cy_valuestring, "False") == 0)
4981 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4982 rc = LUSTRE_CFG_RC_BAD_PARAM;
4983 snprintf(err_str, LNET_MAX_STR_LEN,
4984 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4985 mr->cy_valuestring);
4991 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4992 num_nids, mr_value, force,
4999 if (rc != LUSTRE_CFG_RC_NO_ERR)
5000 cYAML_build_error(rc, seqn, "peer",
5001 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
5007 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
5008 struct cYAML **err_rc)
5010 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
5013 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
5014 struct cYAML **err_rc)
5016 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
5019 static int handle_yaml_config_buffers(struct cYAML *tree,
5020 struct cYAML **show_rc,
5021 struct cYAML **err_rc)
5024 struct cYAML *tiny, *small, *large, *seq_no;
5026 tiny = cYAML_get_object_item(tree, "tiny");
5027 small = cYAML_get_object_item(tree, "small");
5028 large = cYAML_get_object_item(tree, "large");
5029 seq_no = cYAML_get_object_item(tree, "seq_no");
5031 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
5032 (small) ? small->cy_valueint : -1,
5033 (large) ? large->cy_valueint : -1,
5034 (seq_no) ? seq_no->cy_valueint : -1,
5040 static int handle_yaml_config_routing(struct cYAML *tree,
5041 struct cYAML **show_rc,
5042 struct cYAML **err_rc)
5044 int rc = LUSTRE_CFG_RC_NO_ERR;
5045 struct cYAML *seq_no, *enable;
5047 seq_no = cYAML_get_object_item(tree, "seq_no");
5048 enable = cYAML_get_object_item(tree, "enable");
5051 rc = lustre_lnet_enable_routing(enable->cy_valueint,
5053 seq_no->cy_valueint : -1,
5060 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
5061 struct cYAML **err_rc)
5065 struct cYAML *seq_no;
5067 net = cYAML_get_object_item(tree, "net");
5068 gw = cYAML_get_object_item(tree, "gateway");
5069 seq_no = cYAML_get_object_item(tree, "seq_no");
5071 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5072 (gw) ? gw->cy_valuestring : NULL,
5073 (seq_no) ? seq_no->cy_valueint : -1,
5077 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5078 struct cYAML **err_rc)
5080 struct cYAML *seq_no;
5082 seq_no = cYAML_get_object_item(tree, "seq_no");
5084 return lustre_lnet_enable_routing(0, (seq_no) ?
5085 seq_no->cy_valueint : -1,
5089 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5090 struct cYAML **err_rc)
5096 struct cYAML *detail;
5097 struct cYAML *seq_no;
5099 net = cYAML_get_object_item(tree, "net");
5100 gw = cYAML_get_object_item(tree, "gateway");
5101 hop = cYAML_get_object_item(tree, "hop");
5102 prio = cYAML_get_object_item(tree, "priority");
5103 detail = cYAML_get_object_item(tree, "detail");
5104 seq_no = cYAML_get_object_item(tree, "seq_no");
5106 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5107 (gw) ? gw->cy_valuestring : NULL,
5108 (hop) ? hop->cy_valueint : -1,
5109 (prio) ? prio->cy_valueint : -1,
5110 (detail) ? detail->cy_valueint : 0,
5111 (seq_no) ? seq_no->cy_valueint : -1,
5112 show_rc, err_rc, false);
5115 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5116 struct cYAML **err_rc)
5118 struct cYAML *net, *detail, *seq_no;
5120 net = cYAML_get_object_item(tree, "net type");
5121 detail = cYAML_get_object_item(tree, "detail");
5122 seq_no = cYAML_get_object_item(tree, "seq_no");
5124 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5125 (detail) ? detail->cy_valueint : 0,
5126 (seq_no) ? seq_no->cy_valueint : -1,
5127 show_rc, err_rc, false);
5130 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5131 struct cYAML **err_rc)
5133 struct cYAML *seq_no;
5135 seq_no = cYAML_get_object_item(tree, "seq_no");
5137 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5138 show_rc, err_rc, false);
5141 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5142 struct cYAML **err_rc)
5144 struct cYAML *seq_no, *nid, *detail;
5146 seq_no = cYAML_get_object_item(tree, "seq_no");
5147 detail = cYAML_get_object_item(tree, "detail");
5148 nid = cYAML_get_object_item(tree, "nid");
5150 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5151 (detail) ? detail->cy_valueint : 0,
5152 (seq_no) ? seq_no->cy_valueint : -1,
5153 show_rc, err_rc, false);
5156 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5157 struct cYAML **err_rc)
5159 struct cYAML *seq_no;
5161 seq_no = cYAML_get_object_item(tree, "seq_no");
5163 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5167 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5168 struct cYAML **err_rc)
5170 struct cYAML *seq_no, *range;
5172 seq_no = cYAML_get_object_item(tree, "seq_no");
5173 range = cYAML_get_object_item(tree, "range");
5175 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5176 seq_no ? seq_no->cy_valueint : -1,
5180 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5181 struct cYAML **err_rc)
5183 struct cYAML *seq_no;
5185 seq_no = cYAML_get_object_item(tree, "seq_no");
5187 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5191 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5192 struct cYAML **err_rc)
5194 struct cYAML *seq_no;
5196 seq_no = cYAML_get_object_item(tree, "seq_no");
5198 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5202 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5203 struct cYAML **err_rc)
5205 struct cYAML *seq_no, *idx;
5207 seq_no = cYAML_get_object_item(tree, "seq_no");
5208 idx = cYAML_get_object_item(tree, "idx");
5210 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5211 seq_no ? seq_no->cy_valueint : -1,
5215 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5216 struct cYAML **err_rc)
5218 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5219 union lnet_udsp_action action;
5221 seq_no = cYAML_get_object_item(tree, "seq_no");
5222 src = cYAML_get_object_item(tree, "src");
5223 rte = cYAML_get_object_item(tree, "rte");
5224 dst = cYAML_get_object_item(tree, "dst");
5225 prio = cYAML_get_object_item(tree, "priority");
5226 idx = cYAML_get_object_item(tree, "idx");
5228 action.udsp_priority = prio ? prio->cy_valueint : -1;
5230 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5231 dst ? dst->cy_valuestring : NULL,
5232 rte ? rte->cy_valuestring : NULL,
5233 prio ? "priority" : "",
5235 idx ? idx->cy_valueint : -1,
5236 seq_no ? seq_no->cy_valueint : -1,
5240 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5241 struct cYAML **err_rc)
5243 struct cYAML *seq_no;
5246 seq_no = cYAML_get_object_item(tree, "seq_no");
5247 idx = cYAML_get_object_item(tree, "idx");
5249 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5250 seq_no ? seq_no->cy_valueint : -1,
5254 static int handle_yaml_config_global_settings(struct cYAML *tree,
5255 struct cYAML **show_rc,
5256 struct cYAML **err_rc)
5258 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5259 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5263 seq_no = cYAML_get_object_item(tree, "seq_no");
5264 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5265 if (!max_intf) /* try legacy name */
5266 max_intf = cYAML_get_object_item(tree, "max_intf");
5268 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5269 seq_no ? seq_no->cy_valueint
5273 numa = cYAML_get_object_item(tree, "numa_range");
5275 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5276 seq_no ? seq_no->cy_valueint
5280 discovery = cYAML_get_object_item(tree, "discovery");
5282 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5283 seq_no ? seq_no->cy_valueint
5287 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5288 if (drop_asym_route)
5289 rc = lustre_lnet_config_drop_asym_route(
5290 drop_asym_route->cy_valueint,
5291 seq_no ? seq_no->cy_valueint : -1,
5294 retry = cYAML_get_object_item(tree, "retry_count");
5296 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5297 seq_no ? seq_no->cy_valueint
5301 tto = cYAML_get_object_item(tree, "transaction_timeout");
5303 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5304 seq_no ? seq_no->cy_valueint
5308 sen = cYAML_get_object_item(tree, "health_sensitivity");
5310 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5311 seq_no ? seq_no->cy_valueint
5315 recov = cYAML_get_object_item(tree, "recovery_interval");
5317 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5318 seq_no ? seq_no->cy_valueint
5322 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5324 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5325 seq_no ? seq_no->cy_valueint
5329 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5331 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5332 seq_no ? seq_no->cy_valueint
5336 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5338 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5339 seq_no ? seq_no->cy_valueint
5346 static int handle_yaml_del_global_settings(struct cYAML *tree,
5347 struct cYAML **show_rc,
5348 struct cYAML **err_rc)
5350 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5353 seq_no = cYAML_get_object_item(tree, "seq_no");
5354 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5355 if (!max_intf) /* try legacy name */
5356 max_intf = cYAML_get_object_item(tree, "max_intf");
5358 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5359 seq_no ? seq_no->cy_valueint
5363 numa = cYAML_get_object_item(tree, "numa_range");
5365 rc = lustre_lnet_config_numa_range(0,
5366 seq_no ? seq_no->cy_valueint
5370 /* peer discovery is enabled by default */
5371 discovery = cYAML_get_object_item(tree, "discovery");
5373 rc = lustre_lnet_config_discovery(1,
5374 seq_no ? seq_no->cy_valueint
5378 /* asymmetrical route messages are accepted by default */
5379 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5380 if (drop_asym_route)
5381 rc = lustre_lnet_config_drop_asym_route(
5382 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5387 static int handle_yaml_show_global_settings(struct cYAML *tree,
5388 struct cYAML **show_rc,
5389 struct cYAML **err_rc)
5391 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5392 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5396 seq_no = cYAML_get_object_item(tree, "seq_no");
5397 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5398 if (!max_intf) /* try legacy name */
5399 max_intf = cYAML_get_object_item(tree, "max_intf");
5401 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5405 numa = cYAML_get_object_item(tree, "numa_range");
5407 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5411 discovery = cYAML_get_object_item(tree, "discovery");
5413 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5417 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5418 if (drop_asym_route)
5419 rc = lustre_lnet_show_drop_asym_route(
5420 seq_no ? seq_no->cy_valueint : -1,
5423 retry = cYAML_get_object_item(tree, "retry_count");
5425 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5429 tto = cYAML_get_object_item(tree, "transaction_timeout");
5431 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5435 sen = cYAML_get_object_item(tree, "health_sensitivity");
5437 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5441 recov = cYAML_get_object_item(tree, "recovery_interval");
5443 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5447 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5449 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5453 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5455 rc = lustre_lnet_show_response_tracking(seq_no ?
5456 seq_no->cy_valueint :
5460 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5462 rc = lustre_lnet_show_recovery_limit(seq_no ?
5463 seq_no->cy_valueint :
5470 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5471 struct cYAML **err_rc)
5473 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5475 seq_no = cYAML_get_object_item(tree, "seq_no");
5476 nid = cYAML_get_object_item(tree, "primary nid");
5477 timeout = cYAML_get_object_item(tree, "timeout");
5478 src_nid = cYAML_get_object_item(tree, "source_nid");
5480 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5481 (src_nid) ? src_nid->cy_valuestring : NULL,
5482 (timeout) ? timeout->cy_valueint : 1000,
5483 (seq_no) ? seq_no->cy_valueint : -1,
5487 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5488 struct cYAML **err_rc)
5490 struct cYAML *seq_no, *nid, *force;
5492 seq_no = cYAML_get_object_item(tree, "seq_no");
5493 nid = cYAML_get_object_item(tree, "primary nid");
5494 force = cYAML_get_object_item(tree, "force");
5496 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5497 (force) ? force->cy_valueint : 0,
5498 (seq_no) ? seq_no->cy_valueint : -1,
5502 static int handle_yaml_no_op()
5504 return LUSTRE_CFG_RC_NO_ERR;
5507 struct lookup_cmd_hdlr_tbl {
5512 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5513 { .name = "route", .cb = handle_yaml_config_route },
5514 { .name = "net", .cb = handle_yaml_config_ni },
5515 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5516 { .name = "peer", .cb = handle_yaml_config_peer },
5517 { .name = "routing", .cb = handle_yaml_config_routing },
5518 { .name = "buffers", .cb = handle_yaml_config_buffers },
5519 { .name = "statistics", .cb = handle_yaml_no_op },
5520 { .name = "global", .cb = handle_yaml_config_global_settings},
5521 { .name = "numa", .cb = handle_yaml_config_numa },
5522 { .name = "ping", .cb = handle_yaml_no_op },
5523 { .name = "discover", .cb = handle_yaml_no_op },
5524 { .name = "udsp", .cb = handle_yaml_config_udsp },
5527 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5528 { .name = "route", .cb = handle_yaml_del_route },
5529 { .name = "net", .cb = handle_yaml_del_ni },
5530 { .name = "ip2nets", .cb = handle_yaml_no_op },
5531 { .name = "peer", .cb = handle_yaml_del_peer },
5532 { .name = "routing", .cb = handle_yaml_del_routing },
5533 { .name = "buffers", .cb = handle_yaml_no_op },
5534 { .name = "statistics", .cb = handle_yaml_no_op },
5535 { .name = "global", .cb = handle_yaml_del_global_settings},
5536 { .name = "numa", .cb = handle_yaml_del_numa },
5537 { .name = "ping", .cb = handle_yaml_no_op },
5538 { .name = "discover", .cb = handle_yaml_no_op },
5539 { .name = "udsp", .cb = handle_yaml_del_udsp },
5542 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5543 { .name = "route", .cb = handle_yaml_show_route },
5544 { .name = "net", .cb = handle_yaml_show_net },
5545 { .name = "peer", .cb = handle_yaml_show_peers },
5546 { .name = "ip2nets", .cb = handle_yaml_no_op },
5547 { .name = "routing", .cb = handle_yaml_show_routing },
5548 { .name = "buffers", .cb = handle_yaml_show_routing },
5549 { .name = "statistics", .cb = handle_yaml_show_stats },
5550 { .name = "global", .cb = handle_yaml_show_global_settings},
5551 { .name = "numa", .cb = handle_yaml_show_numa },
5552 { .name = "ping", .cb = handle_yaml_no_op },
5553 { .name = "discover", .cb = handle_yaml_no_op },
5554 { .name = "udsp", .cb = handle_yaml_show_udsp },
5557 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5558 { .name = "route", .cb = handle_yaml_no_op },
5559 { .name = "net", .cb = handle_yaml_no_op },
5560 { .name = "peer", .cb = handle_yaml_no_op },
5561 { .name = "ip2nets", .cb = handle_yaml_no_op },
5562 { .name = "routing", .cb = handle_yaml_no_op },
5563 { .name = "buffers", .cb = handle_yaml_no_op },
5564 { .name = "statistics", .cb = handle_yaml_no_op },
5565 { .name = "global", .cb = handle_yaml_no_op },
5566 { .name = "numa", .cb = handle_yaml_no_op },
5567 { .name = "ping", .cb = handle_yaml_ping },
5568 { .name = "discover", .cb = handle_yaml_discover },
5571 static cmd_handler_t lookup_fn(char *key,
5572 struct lookup_cmd_hdlr_tbl *tbl)
5578 for (i = 0; tbl[i].name != NULL; i++) {
5579 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5586 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5587 struct cYAML **show_rc, struct cYAML **err_rc)
5589 struct cYAML *tree, *item = NULL, *head, *child;
5591 char err_str[LNET_MAX_STR_LEN];
5592 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5594 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5596 return LUSTRE_CFG_RC_BAD_PARAM;
5598 child = tree->cy_child;
5599 while (child != NULL) {
5600 cb = lookup_fn(child->cy_string, table);
5602 snprintf(err_str, sizeof(err_str),
5603 "\"call back for '%s' not found\"",
5605 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5606 "yaml", "helper", err_str, err_rc);
5610 if (cYAML_is_sequence(child)) {
5611 while ((head = cYAML_get_next_seq_item(child, &item))
5613 rc = cb(head, show_rc, err_rc);
5614 if (rc != LUSTRE_CFG_RC_NO_ERR)
5618 rc = cb(child, show_rc, err_rc);
5619 if (rc != LUSTRE_CFG_RC_NO_ERR)
5623 child = child->cy_next;
5627 cYAML_free_tree(tree);
5632 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5634 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5638 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5640 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5644 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5646 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5650 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5652 return lustre_yaml_cb_helper(f, lookup_exec_tbl,