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];
91 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
94 snprintf(filename, sizeof(filename), "%s%s",
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);
1890 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1891 char *name, int seq_no,
1892 struct cYAML **err_rc)
1894 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1895 int rc = LUSTRE_CFG_RC_NO_ERR;
1896 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1898 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1899 data.rcpp_all = all;
1900 data.rcpp_value = value;
1901 data.rcpp_nid = nid;
1903 if (value < 0 || value > 127) {
1904 rc = LUSTRE_CFG_RC_BAD_PARAM;
1905 snprintf(err_str, sizeof(err_str),
1906 "\"Valid values are: 0-127\"");
1909 rc = l_ioctl(LNET_DEV_ID,
1910 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1915 "Can not configure conns_per_peer value: %s",
1919 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1924 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1925 struct cYAML **err_rc)
1929 nid = libcfs_str2nid(ni_nid);
1932 return lustre_lnet_config_healthv(value, all, nid,
1933 LNET_HEALTH_TYPE_LOCAL_NI,
1934 "ni healthv", seq_no, err_rc);
1937 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1938 int seq_no, struct cYAML **err_rc)
1942 nid = libcfs_str2nid(lpni_nid);
1945 return lustre_lnet_config_healthv(value, all, nid,
1946 LNET_HEALTH_TYPE_PEER_NI,
1947 "peer_ni healthv", seq_no, err_rc);
1950 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1951 int seq_no, struct cYAML **err_rc)
1956 nid = libcfs_str2nid(ni_nid);
1959 return lustre_lnet_config_conns_per_peer(value, all, nid,
1960 "ni conns_per_peer",
1965 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1966 struct lnet_ioctl_comm_count *counts)
1968 if (cYAML_create_number(yaml, "put",
1969 counts->ico_put_count)
1972 if (cYAML_create_number(yaml, "get",
1973 counts->ico_get_count)
1976 if (cYAML_create_number(yaml, "reply",
1977 counts->ico_reply_count)
1980 if (cYAML_create_number(yaml, "ack",
1981 counts->ico_ack_count)
1984 if (cYAML_create_number(yaml, "hello",
1985 counts->ico_hello_count)
1992 static struct lnet_ioctl_comm_count *
1993 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1996 return &msg_stats->im_send_stats;
1998 return &msg_stats->im_recv_stats;
2000 return &msg_stats->im_drop_stats;
2006 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2007 struct cYAML *net_node)
2009 char tmp[LNET_MAX_STR_LEN];
2010 struct cYAML *udsp_net;
2011 bool created = false;
2015 /* add the UDSP info */
2016 udsp_net = cYAML_create_object(net_node, "udsp info");
2018 return LUSTRE_CFG_RC_OUT_OF_MEM;
2020 if (!cYAML_create_number(udsp_net, "net priority",
2021 (int) udsp_info->cud_net_priority))
2022 return LUSTRE_CFG_RC_OUT_OF_MEM;
2024 if (!cYAML_create_number(udsp_net, "nid priority",
2025 (int)udsp_info->cud_nid_priority))
2026 return LUSTRE_CFG_RC_OUT_OF_MEM;
2030 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2031 memset(tmp, 0, LNET_MAX_STR_LEN);
2032 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2035 pref = cYAML_create_object(udsp_net,
2036 "Preferred gateway NIDs");
2038 return LUSTRE_CFG_RC_OUT_OF_MEM;
2041 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2042 if (!cYAML_create_string(pref, tmp,
2043 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2044 return LUSTRE_CFG_RC_OUT_OF_MEM;
2047 return LUSTRE_CFG_RC_NO_ERR;
2051 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2052 struct cYAML *nid_node)
2054 char tmp[LNET_MAX_STR_LEN];
2055 struct cYAML *udsp_nid;
2056 bool created = false;
2060 /* add the UDSP info */
2061 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2063 return LUSTRE_CFG_RC_OUT_OF_MEM;
2065 if (!cYAML_create_number(udsp_nid, "net priority",
2066 (int) udsp_info->cud_net_priority))
2067 return LUSTRE_CFG_RC_OUT_OF_MEM;
2069 if (!cYAML_create_number(udsp_nid, "nid priority",
2070 (int) udsp_info->cud_nid_priority))
2071 return LUSTRE_CFG_RC_OUT_OF_MEM;
2074 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2075 memset(tmp, 0, LNET_MAX_STR_LEN);
2076 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2079 pref = cYAML_create_object(udsp_nid,
2080 "Preferred gateway NIDs");
2082 return LUSTRE_CFG_RC_OUT_OF_MEM;
2085 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2086 if (!cYAML_create_string(pref, tmp,
2087 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2088 return LUSTRE_CFG_RC_OUT_OF_MEM;
2093 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2094 memset(tmp, 0, LNET_MAX_STR_LEN);
2095 if (udsp_info->cud_pref_nid[i] == 0)
2098 pref = cYAML_create_object(udsp_nid,
2099 "Preferred source NIDs");
2101 return LUSTRE_CFG_RC_OUT_OF_MEM;
2104 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2105 if (!cYAML_create_string(pref, tmp,
2106 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2107 return LUSTRE_CFG_RC_OUT_OF_MEM;
2110 return LUSTRE_CFG_RC_NO_ERR;
2113 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2114 struct cYAML **show_rc, struct cYAML **err_rc,
2118 struct lnet_ioctl_config_ni *ni_data;
2119 struct lnet_ioctl_config_lnd_tunables *lnd;
2120 struct lnet_ioctl_element_stats *stats;
2121 struct lnet_ioctl_element_msg_stats msg_stats;
2122 struct lnet_ioctl_local_ni_hstats hstats;
2123 struct lnet_ioctl_construct_udsp_info udsp_info;
2124 __u32 net = LNET_NET_ANY;
2125 __u32 prev_net = LNET_NET_ANY;
2126 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2128 struct cYAML *root = NULL, *tunables = NULL,
2129 *net_node = NULL, *interfaces = NULL,
2130 *item = NULL, *first_seq = NULL,
2131 *tmp = NULL, *statistics = NULL,
2133 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2134 char str_buf[str_buf_len];
2136 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2137 bool exist = false, new_net = true;
2139 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2141 buf = calloc(1, buf_size);
2145 ni_data = (struct lnet_ioctl_config_ni *)buf;
2148 net = libcfs_str2net(nw);
2149 if (net == LNET_NET_ANY) {
2152 "\"cannot parse net '%s'\"", nw);
2153 rc = LUSTRE_CFG_RC_BAD_PARAM;
2158 root = cYAML_create_object(NULL, NULL);
2162 net_node = cYAML_create_seq(root, "net");
2163 if (net_node == NULL)
2169 memset(buf, 0, buf_size);
2171 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2173 * set the ioc_len to the proper value since INIT assumes
2176 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2177 ni_data->lic_idx = i;
2179 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2185 rc_net = LNET_NIDNET(ni_data->lic_nid);
2187 /* filter on provided data */
2188 if (net != LNET_NET_ANY &&
2192 /* if we're backing up don't store lo */
2193 if (backup && LNET_NETTYP(rc_net) == LOLND)
2196 /* default rc to -1 in case we hit the goto */
2200 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2201 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2202 (ni_data->lic_bulk + sizeof(*stats));
2204 if (rc_net != prev_net) {
2211 tmp = cYAML_create_string(net_node, "net type", libcfs_net2str(rc_net));
2215 if (first_seq == NULL)
2218 tmp = cYAML_create_seq(net_node, "local NI(s)");
2224 /* create the tree to be printed. */
2225 item = cYAML_create_seq_item(tmp);
2230 cYAML_create_string(item, "nid",
2231 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2235 cYAML_create_string(item,
2237 (ni_data->lic_status ==
2238 LNET_NI_STATUS_UP) ?
2239 "up" : "down") == NULL)
2242 /* don't add interfaces unless there is at least one
2244 if (strlen(ni_data->lic_ni_intf) > 0) {
2245 interfaces = cYAML_create_object(item, "interfaces");
2246 if (interfaces == NULL)
2249 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2250 if (cYAML_create_string(interfaces, str_buf,
2251 ni_data->lic_ni_intf) == NULL)
2260 goto continue_without_msg_stats;
2262 statistics = cYAML_create_object(item, "statistics");
2263 if (statistics == NULL)
2266 if (cYAML_create_number(statistics, "send_count",
2267 stats->iel_send_count)
2271 if (cYAML_create_number(statistics, "recv_count",
2272 stats->iel_recv_count)
2276 if (cYAML_create_number(statistics, "drop_count",
2277 stats->iel_drop_count)
2282 goto continue_without_udsp_info;
2284 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2285 udsp_info.cud_nid = ni_data->lic_nid;
2286 udsp_info.cud_peer = false;
2287 rc = l_ioctl(LNET_DEV_ID,
2288 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2292 goto continue_without_udsp_info;
2295 rc = create_local_udsp_info(&udsp_info, item);
2301 continue_without_udsp_info:
2303 goto continue_without_msg_stats;
2305 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2306 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2307 msg_stats.im_idx = i;
2309 rc = l_ioctl(LNET_DEV_ID,
2310 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2314 goto continue_without_msg_stats;
2317 for (k = 0; k < 3; k++) {
2318 struct lnet_ioctl_comm_count *counts;
2319 struct cYAML *msg_statistics = NULL;
2321 msg_statistics = cYAML_create_object(item,
2322 (char *)gmsg_stat_names[k]);
2323 if (msg_statistics == NULL)
2326 counts = get_counts(&msg_stats, k);
2330 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2335 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2336 hstats.hlni_nid = ni_data->lic_nid;
2337 /* grab health stats */
2338 rc = l_ioctl(LNET_DEV_ID,
2339 IOC_LIBCFS_GET_LOCAL_HSTATS,
2343 goto continue_without_msg_stats;
2345 yhstats = cYAML_create_object(item, "health stats");
2348 if (cYAML_create_number(yhstats, "fatal_error",
2349 hstats.hlni_fatal_error)
2352 if (cYAML_create_number(yhstats, "health value",
2353 hstats.hlni_health_value)
2356 if (cYAML_create_number(yhstats, "interrupts",
2357 hstats.hlni_local_interrupt)
2360 if (cYAML_create_number(yhstats, "dropped",
2361 hstats.hlni_local_dropped)
2364 if (cYAML_create_number(yhstats, "aborted",
2365 hstats.hlni_local_aborted)
2368 if (cYAML_create_number(yhstats, "no route",
2369 hstats.hlni_local_no_route)
2372 if (cYAML_create_number(yhstats, "timeouts",
2373 hstats.hlni_local_timeout)
2376 if (cYAML_create_number(yhstats, "error",
2377 hstats.hlni_local_error)
2380 if (cYAML_create_number(yhstats, "ping_count",
2381 hstats.hlni_ping_count)
2384 if (cYAML_create_number(yhstats, "next_ping",
2385 hstats.hlni_next_ping)
2389 continue_without_msg_stats:
2390 tunables = cYAML_create_object(item, "tunables");
2394 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2395 if (rc != LUSTRE_CFG_RC_NO_ERR)
2398 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2399 tunables = cYAML_create_object(item,
2401 if (tunables == NULL)
2405 rc = lustre_ni_show_tunables(tunables,
2406 LNET_NETTYP(rc_net),
2407 &lnd->lt_tun, backup);
2408 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2409 rc != LUSTRE_CFG_RC_NO_MATCH)
2413 cYAML_create_number(item, "dev cpt",
2414 ni_data->lic_dev_cpt) == NULL)
2417 /* out put the CPTs in the format: "[x,x,x,...]" */
2419 limit = str_buf + str_buf_len - 3;
2420 pos += scnprintf(pos, limit - pos, "\"[");
2421 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2422 j < ni_data->lic_ncpts &&
2424 pos += scnprintf(pos, limit - pos,
2425 "%d", ni_data->lic_cpts[j]);
2426 if ((j + 1) < ni_data->lic_ncpts)
2427 pos += scnprintf(pos, limit - pos, ",");
2429 snprintf(pos, 3, "]\"");
2431 if (ni_data->lic_ncpts >= 1 &&
2432 cYAML_create_string(item, "CPT",
2438 /* Print out the net information only if show_rc is not provided */
2439 if (show_rc == NULL)
2440 cYAML_print_tree(root);
2442 if (l_errno != ENOENT) {
2445 "\"cannot get networks: %s\"",
2450 rc = LUSTRE_CFG_RC_NO_ERR;
2452 snprintf(err_str, sizeof(err_str), "\"success\"");
2454 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2455 cYAML_free_tree(root);
2456 } else if (show_rc != NULL && *show_rc != NULL) {
2457 struct cYAML *show_node;
2458 /* find the net node, if one doesn't exist
2459 * then insert one. Otherwise add to the one there
2461 show_node = cYAML_get_object_item(*show_rc, "net");
2462 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2463 cYAML_insert_child(show_node, first_seq);
2466 } else if (show_node == NULL) {
2467 cYAML_insert_sibling((*show_rc)->cy_child,
2471 cYAML_free_tree(root);
2477 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2482 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2484 struct lnet_ioctl_config_data data;
2485 int rc = LUSTRE_CFG_RC_NO_ERR;
2486 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2488 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2489 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2491 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2496 "\"cannot %s routing %s\"",
2497 (enable) ? "enable" : "disable", strerror(errno));
2502 cYAML_build_error(rc, seq_no,
2503 (enable) ? ADD_CMD : DEL_CMD,
2504 "routing", err_str, err_rc);
2509 int ioctl_set_value(__u32 val, int ioc, char *name,
2510 int seq_no, struct cYAML **err_rc)
2512 struct lnet_ioctl_set_value data;
2513 int rc = LUSTRE_CFG_RC_NO_ERR;
2514 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2516 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2517 data.sv_value = val;
2519 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2524 "\"cannot configure %s to %d: %s\"", name,
2525 val, strerror(errno));
2528 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2533 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2535 int rc = LUSTRE_CFG_RC_NO_ERR;
2536 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2537 char val[LNET_MAX_STR_LEN];
2539 snprintf(val, sizeof(val), "%d", intrv);
2541 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2542 1, strlen(val) + 1);
2544 snprintf(err_str, sizeof(err_str),
2545 "\"cannot configure recovery interval: %s\"",
2548 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2553 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2555 int rc = LUSTRE_CFG_RC_NO_ERR;
2556 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2557 char val[LNET_MAX_STR_LEN];
2559 snprintf(val, sizeof(val), "%d", sen);
2561 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2562 1, strlen(val) + 1);
2564 snprintf(err_str, sizeof(err_str),
2565 "\"cannot configure router health sensitivity: %s\"",
2568 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2573 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2575 int rc = LUSTRE_CFG_RC_NO_ERR;
2576 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2577 char val[LNET_MAX_STR_LEN];
2579 snprintf(val, sizeof(val), "%d", sen);
2581 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2582 1, strlen(val) + 1);
2584 snprintf(err_str, sizeof(err_str),
2585 "\"cannot configure health sensitivity: %s\"",
2588 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2593 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2595 int rc = LUSTRE_CFG_RC_NO_ERR;
2596 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2597 char val[LNET_MAX_STR_LEN];
2599 snprintf(val, sizeof(val), "%d", timeout);
2601 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2602 1, strlen(val) + 1);
2604 snprintf(err_str, sizeof(err_str),
2605 "\"cannot configure transaction timeout: %s\"",
2608 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2613 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2615 int rc = LUSTRE_CFG_RC_NO_ERR;
2616 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2617 char val[LNET_MAX_STR_LEN];
2619 snprintf(val, sizeof(val), "%d", count);
2621 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2622 1, strlen(val) + 1);
2624 snprintf(err_str, sizeof(err_str),
2625 "\"cannot configure retry count: %s\"",
2628 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2633 int lustre_lnet_config_response_tracking(int val, int seq_no,
2634 struct cYAML **err_rc)
2636 int rc = LUSTRE_CFG_RC_NO_ERR;
2637 char err_str[LNET_MAX_STR_LEN];
2638 char val_str[LNET_MAX_STR_LEN];
2640 if (val < 0 || val > 3) {
2641 rc = LUSTRE_CFG_RC_BAD_PARAM;
2642 snprintf(err_str, sizeof(err_str),
2643 "\"Valid values are: 0, 1, 2, or 3\"");
2645 snprintf(err_str, sizeof(err_str), "\"success\"");
2647 snprintf(val_str, sizeof(val_str), "%d", val);
2649 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2650 val_str, 1, strlen(val_str) + 1);
2652 snprintf(err_str, sizeof(err_str),
2653 "\"cannot configure response tracking: %s\"",
2657 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2663 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2664 struct cYAML **err_rc)
2666 int rc = LUSTRE_CFG_RC_NO_ERR;
2667 char err_str[LNET_MAX_STR_LEN];
2668 char val_str[LNET_MAX_STR_LEN];
2671 rc = LUSTRE_CFG_RC_BAD_PARAM;
2672 snprintf(err_str, sizeof(err_str),
2673 "\"Must be greater than or equal to 0\"");
2675 snprintf(err_str, sizeof(err_str), "\"success\"");
2677 snprintf(val_str, sizeof(val_str), "%d", val);
2679 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2680 val_str, 1, strlen(val_str) + 1);
2682 snprintf(err_str, sizeof(err_str),
2683 "\"cannot configure recovery limit: %s\"",
2687 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2693 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2695 int rc = LUSTRE_CFG_RC_NO_ERR;
2696 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2697 char val[LNET_MAX_STR_LEN];
2699 snprintf(val, sizeof(val), "%d", max);
2701 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2702 1, strlen(val) + 1);
2704 snprintf(err_str, sizeof(err_str),
2705 "\"cannot configure max interfaces: %s\"",
2708 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2713 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2715 int rc = LUSTRE_CFG_RC_NO_ERR;
2716 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2717 char val[LNET_MAX_STR_LEN];
2719 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2721 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2722 1, strlen(val) + 1);
2724 snprintf(err_str, sizeof(err_str),
2725 "\"cannot configure discovery: %s\"",
2728 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2734 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2735 struct cYAML **err_rc)
2737 int rc = LUSTRE_CFG_RC_NO_ERR;
2738 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2739 char val[LNET_MAX_STR_LEN];
2741 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2743 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2744 1, strlen(val) + 1);
2746 snprintf(err_str, sizeof(err_str),
2747 "\"cannot configure drop asym route: %s\"",
2750 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2757 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2759 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2760 "numa_range", seq_no, err_rc);
2763 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2764 struct cYAML **err_rc)
2766 struct lnet_ioctl_config_data data;
2767 int rc = LUSTRE_CFG_RC_NO_ERR;
2768 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2770 /* -1 indicates to ignore changes to this field */
2771 if (tiny < -1 || small < -1 || large < -1) {
2774 "\"tiny, small and large must be >= 0\"");
2775 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2779 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2780 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2781 data.cfg_config_u.cfg_buffers.buf_small = small;
2782 data.cfg_config_u.cfg_buffers.buf_large = large;
2784 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2789 "\"cannot configure buffers: %s\"", strerror(errno));
2794 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2799 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2800 struct cYAML **err_rc)
2802 int rc = LUSTRE_CFG_RC_NO_ERR;
2803 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2804 char interval_str[LNET_MAX_STR_LEN];
2806 if (interval <= 0) {
2807 rc = LUSTRE_CFG_RC_BAD_PARAM;
2808 snprintf(err_str, sizeof(err_str),
2809 "\"must be strictly positive\"");
2812 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2814 rc = write_sysfs_file(modparam_path,
2815 "lnet_max_recovery_ping_interval",
2817 strlen(interval_str) + 1);
2819 snprintf(err_str, sizeof(err_str),
2820 "\"cannot configure maximum recovery ping interval: %s\"",
2824 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2831 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2832 struct cYAML **err_rc, bool backup)
2834 struct lnet_ioctl_config_data *data;
2835 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2836 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2839 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2840 int buf_count[LNET_NRBPOOLS] = {0};
2841 struct cYAML *root = NULL, *pools_node = NULL,
2842 *type_node = NULL, *item = NULL, *cpt = NULL,
2843 *first_seq = NULL, *buffers = NULL;
2845 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2846 char node_name[LNET_MAX_STR_LEN];
2849 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2853 data = (struct lnet_ioctl_config_data *)buf;
2855 root = cYAML_create_object(NULL, NULL);
2860 pools_node = cYAML_create_object(root, "routing");
2862 pools_node = cYAML_create_seq(root, "routing");
2863 if (pools_node == NULL)
2867 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2868 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2869 sizeof(struct lnet_ioctl_pool_cfg);
2870 data->cfg_count = i;
2872 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2880 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2883 goto calculate_buffers;
2885 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2886 item = cYAML_create_seq_item(pools_node);
2890 if (first_seq == NULL)
2893 cpt = cYAML_create_object(item, node_name);
2898 /* create the tree and print */
2899 for (j = 0; j < LNET_NRBPOOLS; j++) {
2901 type_node = cYAML_create_object(cpt, pools[j]);
2902 if (type_node == NULL)
2906 cYAML_create_number(type_node, "npages",
2907 pool_cfg->pl_pools[j].pl_npages)
2911 cYAML_create_number(type_node, "nbuffers",
2912 pool_cfg->pl_pools[j].
2913 pl_nbuffers) == NULL)
2916 cYAML_create_number(type_node, "credits",
2917 pool_cfg->pl_pools[j].
2918 pl_credits) == NULL)
2921 cYAML_create_number(type_node, "mincredits",
2922 pool_cfg->pl_pools[j].
2923 pl_mincredits) == NULL)
2925 /* keep track of the total count for each of the
2926 * tiny, small and large buffers */
2927 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2931 if (pool_cfg != NULL) {
2933 if (cYAML_create_number(pools_node, "enable",
2934 pool_cfg->pl_routing) ==
2938 goto add_buffer_section;
2941 item = cYAML_create_seq_item(pools_node);
2945 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2951 /* create a buffers entry in the show. This is necessary so that
2952 * if the YAML output is used to configure a node, the buffer
2953 * configuration takes hold */
2954 buffers = cYAML_create_object(root, "buffers");
2955 if (buffers == NULL)
2958 for (i = 0; i < LNET_NRBPOOLS; i++) {
2959 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2963 if (show_rc == NULL)
2964 cYAML_print_tree(root);
2966 if (l_errno != ENOENT) {
2969 "\"cannot get routing information: %s\"",
2974 rc = LUSTRE_CFG_RC_NO_ERR;
2976 snprintf(err_str, sizeof(err_str), "\"success\"");
2977 rc = LUSTRE_CFG_RC_NO_ERR;
2981 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2982 cYAML_free_tree(root);
2983 } else if (show_rc != NULL && *show_rc != NULL) {
2984 struct cYAML *routing_node;
2985 /* there should exist only one routing block and one
2986 * buffers block. If there already exists a previous one
2987 * then don't add another */
2988 routing_node = cYAML_get_object_item(*show_rc, "routing");
2989 if (routing_node == NULL) {
2990 cYAML_insert_sibling((*show_rc)->cy_child,
2994 cYAML_free_tree(root);
3000 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
3005 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
3006 struct cYAML **show_rc, struct cYAML **err_rc,
3010 * TODO: This function is changing in a future patch to accommodate
3011 * PEER_LIST and proper filtering on any nid of the peer
3013 struct lnet_ioctl_peer_cfg peer_info;
3014 struct lnet_peer_ni_credit_info *lpni_cri;
3015 struct lnet_ioctl_element_stats *lpni_stats;
3016 struct lnet_ioctl_element_msg_stats *msg_stats;
3017 struct lnet_ioctl_peer_ni_hstats *hstats;
3018 struct lnet_ioctl_construct_udsp_info udsp_info;
3020 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3025 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
3026 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
3027 *msg_statistics = NULL, *statistics = NULL,
3029 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3030 struct lnet_process_id *list = NULL;
3035 /* create struct cYAML root object */
3036 root = cYAML_create_object(NULL, NULL);
3040 peer_root = cYAML_create_seq(root, "peer");
3041 if (peer_root == NULL)
3045 size = count * sizeof(struct lnet_process_id);
3046 list = malloc(size);
3052 list[0].nid = libcfs_str2nid(knid);
3056 memset(&peer_info, 0, sizeof(peer_info));
3057 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3058 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3059 peer_info.prcfg_size = size;
3060 peer_info.prcfg_bulk = list;
3063 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
3065 count = peer_info.prcfg_count;
3069 if (l_errno != E2BIG) {
3072 "\"cannot get peer list: %s\"",
3078 size = peer_info.prcfg_size;
3079 list = malloc(size);
3088 data = malloc(size);
3094 for (i = 0; i < count; i++) {
3096 memset(&peer_info, 0, sizeof(peer_info));
3097 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3098 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3099 peer_info.prcfg_prim_nid = list[i].nid;
3100 peer_info.prcfg_size = size;
3101 peer_info.prcfg_bulk = data;
3104 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
3109 if (l_errno != E2BIG) {
3112 "\"cannot get peer information: %s\"",
3118 size = peer_info.prcfg_size;
3119 data = malloc(size);
3127 peer = cYAML_create_seq_item(peer_root);
3131 if (first_seq == NULL)
3134 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
3135 if (cYAML_create_string(peer, "primary nid",
3136 libcfs_nid2str(pnid))
3139 if (cYAML_create_string(peer, "Multi-Rail",
3140 peer_info.prcfg_mr ? "True" : "False")
3144 * print out the state of the peer only if details are
3149 cYAML_create_number(peer, "peer state",
3150 peer_info.prcfg_state)
3155 tmp = cYAML_create_seq(peer, "peer ni");
3160 for (j = 0; j < peer_info.prcfg_count; j++) {
3162 lpni_cri = (void*)nidp + sizeof(nidp);
3163 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
3164 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
3165 hstats = (void *)msg_stats + sizeof(*msg_stats);
3166 lpni_data = (void *)hstats + sizeof(*hstats);
3168 peer_ni = cYAML_create_seq_item(tmp);
3169 if (peer_ni == NULL)
3172 if (cYAML_create_string(peer_ni, "nid",
3173 libcfs_nid2str(*nidp))
3181 goto continue_without_udsp_info;
3183 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
3184 udsp_info.cud_nid = *nidp;
3185 udsp_info.cud_peer = true;
3186 rc = l_ioctl(LNET_DEV_ID,
3187 IOC_LIBCFS_GET_CONST_UDSP_INFO,
3191 goto continue_without_udsp_info;
3194 rc = create_remote_udsp_info(&udsp_info, peer_ni);
3200 continue_without_udsp_info:
3201 if (cYAML_create_string(peer_ni, "state",
3202 lpni_cri->cr_aliveness)
3209 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
3210 lpni_cri->cr_ni_peer_tx_credits)
3214 if (cYAML_create_number(peer_ni, "available_tx_credits",
3215 lpni_cri->cr_peer_tx_credits)
3219 if (cYAML_create_number(peer_ni, "min_tx_credits",
3220 lpni_cri->cr_peer_min_tx_credits)
3224 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
3225 lpni_cri->cr_peer_tx_qnob)
3229 if (cYAML_create_number(peer_ni, "available_rtr_credits",
3230 lpni_cri->cr_peer_rtr_credits)
3234 if (cYAML_create_number(peer_ni, "min_rtr_credits",
3235 lpni_cri->cr_peer_min_rtr_credits)
3239 if (cYAML_create_number(peer_ni, "refcount",
3240 lpni_cri->cr_refcount) == NULL)
3243 statistics = cYAML_create_object(peer_ni, "statistics");
3244 if (statistics == NULL)
3247 if (cYAML_create_number(statistics, "send_count",
3248 lpni_stats->iel_send_count)
3252 if (cYAML_create_number(statistics, "recv_count",
3253 lpni_stats->iel_recv_count)
3257 if (cYAML_create_number(statistics, "drop_count",
3258 lpni_stats->iel_drop_count)
3265 for (k = 0; k < 3; k++) {
3266 struct lnet_ioctl_comm_count *counts;
3268 msg_statistics = cYAML_create_object(peer_ni,
3269 (char *) gmsg_stat_names[k]);
3270 if (msg_statistics == NULL)
3273 counts = get_counts(msg_stats, k);
3277 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3282 yhstats = cYAML_create_object(peer_ni, "health stats");
3285 if (cYAML_create_number(yhstats, "health value",
3286 hstats->hlpni_health_value)
3289 if (cYAML_create_number(yhstats, "dropped",
3290 hstats->hlpni_remote_dropped)
3293 if (cYAML_create_number(yhstats, "timeout",
3294 hstats->hlpni_remote_timeout)
3297 if (cYAML_create_number(yhstats, "error",
3298 hstats->hlpni_remote_error)
3301 if (cYAML_create_number(yhstats, "network timeout",
3302 hstats->hlpni_network_timeout)
3305 if (cYAML_create_number(yhstats, "ping_count",
3306 hstats->hlpni_ping_count)
3310 if (cYAML_create_number(yhstats, "next_ping",
3311 hstats->hlpni_next_ping)
3318 /* print output iff show_rc is not provided */
3319 if (show_rc == NULL)
3320 cYAML_print_tree(root);
3322 snprintf(err_str, sizeof(err_str), "\"success\"");
3323 rc = LUSTRE_CFG_RC_NO_ERR;
3328 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3329 cYAML_free_tree(root);
3330 } else if (show_rc != NULL && *show_rc != NULL) {
3331 struct cYAML *show_node;
3332 /* find the peer node, if one doesn't exist then
3333 * insert one. Otherwise add to the one there
3335 show_node = cYAML_get_object_item(*show_rc,
3337 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3338 cYAML_insert_child(show_node, first_seq);
3341 } else if (show_node == NULL) {
3342 cYAML_insert_sibling((*show_rc)->cy_child,
3346 cYAML_free_tree(root);
3352 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3358 int lustre_lnet_list_peer(int seq_no,
3359 struct cYAML **show_rc, struct cYAML **err_rc)
3361 struct lnet_ioctl_peer_cfg peer_info;
3362 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3367 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3368 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3369 struct lnet_process_id *list = NULL;
3371 memset(&peer_info, 0, sizeof(peer_info));
3373 /* create struct cYAML root object */
3374 root = cYAML_create_object(NULL, NULL);
3378 list_root = cYAML_create_seq(root, "peer list");
3379 if (list_root == NULL)
3383 size = count * sizeof(struct lnet_process_id);
3384 list = malloc(size);
3390 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3391 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3392 peer_info.prcfg_size = size;
3393 peer_info.prcfg_bulk = list;
3396 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3397 count = peer_info.prcfg_count;
3401 if (l_errno != E2BIG) {
3404 "\"cannot get peer list: %s\"",
3410 size = peer_info.prcfg_size;
3411 list = malloc(size);
3418 /* count is now the actual number of ids in the list. */
3419 for (i = 0; i < count; i++) {
3420 if (cYAML_create_string(list_root, "nid",
3421 libcfs_nid2str(list[i].nid))
3426 /* print output iff show_rc is not provided */
3427 if (show_rc == NULL)
3428 cYAML_print_tree(root);
3430 snprintf(err_str, sizeof(err_str), "\"success\"");
3431 rc = LUSTRE_CFG_RC_NO_ERR;
3436 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3437 cYAML_free_tree(root);
3438 } else if (show_rc != NULL && *show_rc != NULL) {
3439 struct cYAML *show_node;
3440 /* find the peer node, if one doesn't exist then
3441 * insert one. Otherwise add to the one there
3443 show_node = cYAML_get_object_item(*show_rc,
3445 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3446 cYAML_insert_child(show_node, first_seq);
3449 } else if (show_node == NULL) {
3450 cYAML_insert_sibling((*show_rc)->cy_child,
3454 cYAML_free_tree(root);
3460 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3466 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3469 struct cYAML *show_node;
3471 show_node = cYAML_get_object_item(show_rc, "global");
3472 if (show_node != NULL)
3473 cYAML_insert_sibling(show_node->cy_child,
3476 cYAML_insert_sibling(show_rc->cy_child,
3481 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3482 char *name, __u64 value,
3483 struct cYAML **show_rc,
3484 struct cYAML **err_rc, int err)
3486 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3487 struct cYAML *root = NULL, *global = NULL;
3494 root = cYAML_create_object(NULL, NULL);
3498 global = cYAML_create_object(root, "global");
3502 if (cYAML_create_number(global, name,
3506 if (show_rc == NULL)
3507 cYAML_print_tree(root);
3509 snprintf(err_str, err_len, "\"success\"");
3511 rc = LUSTRE_CFG_RC_NO_ERR;
3514 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3515 cYAML_free_tree(root);
3516 } else if (show_rc != NULL && *show_rc != NULL) {
3517 add_to_global(*show_rc, global, root);
3522 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3527 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3528 struct cYAML **show_rc,
3529 struct cYAML **err_rc)
3531 struct lnet_ioctl_set_value data;
3534 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3536 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3538 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3543 "\"cannot get %s: %s\"",
3544 name, strerror(l_errno));
3547 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3548 data.sv_value, show_rc, err_rc, l_errno);
3551 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3552 struct cYAML **err_rc)
3554 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3555 char val[LNET_MAX_STR_LEN];
3556 int intrv = -1, l_errno = 0;
3557 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3559 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3563 snprintf(err_str, sizeof(err_str),
3564 "\"cannot get recovery interval: %d\"", rc);
3569 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3570 "recovery_interval", intrv, show_rc,
3574 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3575 struct cYAML **err_rc)
3577 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3578 char val[LNET_MAX_STR_LEN];
3579 int sen = -1, l_errno = 0;
3580 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3582 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3586 snprintf(err_str, sizeof(err_str),
3587 "\"cannot get health sensitivity: %d\"", rc);
3592 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3593 "health_sensitivity", sen, show_rc,
3597 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3598 struct cYAML **err_rc)
3600 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3601 char val[LNET_MAX_STR_LEN];
3602 int sen = -1, l_errno = 0;
3603 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3605 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3609 snprintf(err_str, sizeof(err_str),
3610 "\"cannot get router sensitivity percentage: %d\"", rc);
3615 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3616 "router_sensitivity", sen, show_rc,
3620 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
3621 struct cYAML **err_rc)
3623 char val[LNET_MAX_STR_LEN];
3624 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3631 rc = cfs_get_param_paths(&path, "lnet_lnd_timeout");
3634 snprintf(err_str, sizeof(err_str),
3635 "\"cannot get LND timeout: %d\"", rc);
3636 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3637 "lnd_timeout", lnd_to, show_rc,
3641 fd = open(path.gl_pathv[0], O_RDONLY);
3644 snprintf(err_str, sizeof(err_str),
3645 "\"error opening %s\"", path.gl_pathv[0]);
3649 rc = read(fd, val, sizeof(val));
3656 snprintf(err_str, sizeof(err_str),
3657 "\"error reading %s\"", path.gl_pathv[0]);
3664 cfs_free_param_data(&path);
3666 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3667 "lnd_timeout", lnd_to, show_rc,
3671 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3672 struct cYAML **err_rc)
3674 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3675 char val[LNET_MAX_STR_LEN];
3676 int tto = -1, l_errno = 0;
3677 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3679 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3683 snprintf(err_str, sizeof(err_str),
3684 "\"cannot get transaction timeout: %d\"", rc);
3689 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3690 "transaction_timeout", tto, show_rc,
3694 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3695 struct cYAML **err_rc)
3697 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3698 char val[LNET_MAX_STR_LEN];
3699 int retry_count = -1, l_errno = 0;
3700 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3702 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3706 snprintf(err_str, sizeof(err_str),
3707 "\"cannot get retry count: %d\"", rc);
3709 retry_count = atoi(val);
3712 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3713 "retry_count", retry_count, show_rc,
3717 int lustre_lnet_calc_service_id(__u64 *service_id)
3719 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3720 char val[LNET_MAX_STR_LEN];
3721 int service_port = -1, l_errno = 0;
3723 rc = read_sysfs_file(o2ib_modparam_path, "service", val,
3727 fprintf(stderr, "error:\n msg: \"cannot get service port: %s (%d)\"\n",
3728 strerror(l_errno), -l_errno);
3731 service_port = atoi(val);
3734 *service_id = htobe64(((__u64)RDMA_PS_TCP << 16) + service_port);
3736 return LUSTRE_CFG_RC_NO_ERR;
3739 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc)
3742 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i;
3744 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
3745 struct lnet_ioctl_config_ni *ni_data;
3746 struct lnet_ioctl_config_lnd_tunables *lnd;
3747 struct lnet_ioctl_element_stats *stats;
3748 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
3749 char ifstr_buf[LNET_INTERFACES_NUM*LNET_MAX_STR_LEN];
3750 char *ifstr_ptr, *tmp_ptr, *tmp_ptr2;
3751 int if_cnt = 0, prc;
3752 char syscmdbuf[LNET_MAX_STR_LEN];
3753 char cmdpath[LNET_MAX_STR_LEN];
3754 bool use_custom = false;
3756 buf = calloc(1, buf_size);
3760 ni_data = (struct lnet_ioctl_config_ni *)buf;
3763 ifstr_ptr = ifstr_buf;
3768 memset(buf, 0, buf_size);
3770 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
3771 /* set the ioc_len to the proper value since INIT assumes
3774 ni_data->lic_cfg_hdr.ioc_len = buf_size;
3775 ni_data->lic_idx = i;
3777 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
3783 rc_net = LNET_NIDNET(ni_data->lic_nid);
3785 /* only need to setup routing for tcp */
3786 if (LNET_NETTYP(rc_net) != SOCKLND)
3789 /* don't add interfaces unless there is at least one
3792 if (strlen(ni_data->lic_ni_intf) > 0) {
3794 strcat(ifstr_ptr, ",");
3795 strcat(ifstr_ptr, ni_data->lic_ni_intf);
3800 if (l_errno != ENOENT) {
3803 "\"cannot get networks: %s\"",
3808 rc = LUSTRE_CFG_RC_NO_ERR;
3811 snprintf(err_str, sizeof(err_str), "\"success\"");
3814 tmp_ptr = getenv("KSOCKLND_CONFIG");
3816 tmp_ptr2 = strrchr(tmp_ptr, '/');
3817 if (tmp_ptr2 && !strcmp(tmp_ptr2, "/ksocklnd-config")) {
3818 snprintf(cmdpath, sizeof(cmdpath), "%s",
3825 snprintf(cmdpath, sizeof(cmdpath),
3826 "/usr/sbin/ksocklnd-config");
3828 prc = snprintf(0, 0, "%s %s", cmdpath, ifstr_ptr);
3834 "\"snprintf failed : %s\"",
3837 } else if (prc >= LNET_MAX_STR_LEN) {
3838 snprintf(err_str, sizeof(err_str),
3839 "\"ksocklnd-config: argument too long\"");
3841 prc = snprintf(syscmdbuf, sizeof(syscmdbuf), "%s %s",
3842 cmdpath, ifstr_ptr);
3848 "\"snprintf failed : %s\"",
3854 rc = system(syscmdbuf);
3859 "\"failed to execute ksocklnd-config : %s\"",
3869 cYAML_build_error(rc, -1, MANAGE_CMD, "setup-mrrouting", err_str,
3876 lnet_nid_cpt_hash(lnet_nid_t nid, long int number, unsigned int cpt_bits)
3879 __u16 lnd = LNET_NETTYP(LNET_NIDNET(nid));
3885 if (lnd == KFILND || lnd == GNILND) {
3886 cpt = hash_long(key, cpt_bits);
3888 /* NB: The number of CPTs needn't be a power of 2 */
3890 cpt = (key + cpt + (cpt >> 1)) % number;
3892 __u64 pair_bits = 0x0001000100010001LLU;
3893 __u64 mask = pair_bits * 0xFF;
3895 /* For ipv4 NIDs, use (sum-by-multiplication of nid bytes) mod
3896 * (number of CPTs) to match nid to a CPT.
3898 pair_sum = (key & mask) + ((key >> 8) & mask);
3899 pair_sum = (pair_sum * pair_bits) >> 48;
3900 cpt = (unsigned int)(pair_sum) % number;
3906 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)
3908 int rc = LUSTRE_CFG_RC_BAD_PARAM;
3910 unsigned int cpt_bits;
3913 fprintf(stderr, "error:\n msg: \"no NID provided\"\n");
3918 fprintf(stderr, "error:\n msg: \"number of CPTs not provided\"\n");
3923 fprintf(stderr, "error:\n msg: \"number of CPTs must be >= 1\"\n");
3928 while ((1 << cpt_bits) < ncpts)
3931 nid = libcfs_str2nid(nidc);
3932 if (nid == LNET_NID_ANY) {
3933 fprintf(stderr, "error:\n msg: \"bad NID provided %s\"\n",
3938 return (int)lnet_nid_cpt_hash(nid, ncpts, cpt_bits);
3941 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3942 struct cYAML **show_rc, struct cYAML **err_rc)
3944 struct lnet_ioctl_recovery_list nid_list;
3945 struct cYAML *root = NULL, *nids = NULL;
3947 char err_str[LNET_MAX_STR_LEN] = "failed to print recovery queue\n";
3949 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3950 nid_list.rlst_type = type;
3952 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3958 if (nid_list.rlst_num_nids == 0)
3961 root = cYAML_create_object(NULL, NULL);
3965 nids = cYAML_create_object(root, name);
3971 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3972 char nidenum[LNET_MAX_STR_LEN];
3973 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3974 if (!cYAML_create_string(nids, nidenum,
3975 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3979 snprintf(err_str, sizeof(err_str), "success\n");
3984 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3985 cYAML_free_tree(root);
3986 } else if (show_rc != NULL && *show_rc != NULL) {
3987 struct cYAML *show_node;
3988 /* find the net node, if one doesn't exist
3989 * then insert one. Otherwise add to the one there
3991 show_node = cYAML_get_object_item(*show_rc, name);
3992 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3993 cYAML_insert_child(show_node, nids);
3996 } else if (show_node == NULL) {
3997 cYAML_insert_sibling((*show_rc)->cy_child,
4001 cYAML_free_tree(root);
4007 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
4012 int lustre_lnet_show_peer_debug_info(char *peer_nid, int seq_no,
4013 struct cYAML **err_rc)
4015 struct libcfs_ioctl_data data;
4017 char err_str[LNET_MAX_STR_LEN] = "Error";
4018 lnet_nid_t pnid = LNET_NID_ANY;
4021 rc = LUSTRE_CFG_RC_BAD_PARAM;
4022 snprintf(err_str, LNET_MAX_STR_LEN,
4023 "--nid must be specified");
4027 pnid = libcfs_str2nid(peer_nid);
4028 if (pnid == LNET_NID_ANY) {
4029 rc = LUSTRE_CFG_RC_BAD_PARAM;
4030 snprintf(err_str, LNET_MAX_STR_LEN,
4031 "badly formatted primary NID: %s", peer_nid);
4035 LIBCFS_IOC_INIT(data);
4036 data.ioc_net = LNET_NIDNET(pnid);
4037 data.ioc_nid = pnid;
4039 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
4043 cYAML_build_error(rc, seq_no, "debug", "peer", err_str,
4049 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
4050 struct cYAML **err_rc)
4052 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
4053 seq_no, show_rc, err_rc);
4056 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
4057 struct cYAML **err_rc)
4059 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
4060 seq_no, show_rc, err_rc);
4063 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
4064 struct cYAML **err_rc)
4066 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4067 char val[LNET_MAX_STR_LEN];
4068 int rsp_tracking = -1, l_errno = 0;
4069 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4071 rc = read_sysfs_file(modparam_path, "lnet_response_tracking", val,
4075 snprintf(err_str, sizeof(err_str),
4076 "\"cannot get lnet_response_tracking value: %d\"", rc);
4078 rsp_tracking = atoi(val);
4081 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4082 "response_tracking", rsp_tracking,
4083 show_rc, err_rc, l_errno);
4086 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
4087 struct cYAML **err_rc)
4089 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4090 char val[LNET_MAX_STR_LEN];
4091 int recov_limit = -1, l_errno = 0;
4092 char err_str[LNET_MAX_STR_LEN];
4094 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4096 rc = read_sysfs_file(modparam_path, "lnet_recovery_limit", val,
4100 snprintf(err_str, sizeof(err_str),
4101 "\"cannot get lnet_recovery_limit value: %d\"", rc);
4103 recov_limit = atoi(val);
4106 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4107 "recovery_limit", recov_limit,
4108 show_rc, err_rc, l_errno);
4111 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
4112 struct cYAML **show_rc,
4113 struct cYAML **err_rc)
4115 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4116 char val[LNET_MAX_STR_LEN];
4117 int interval = -1, l_errno = 0;
4118 char err_str[LNET_MAX_STR_LEN];
4120 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
4122 rc = read_sysfs_file(modparam_path, "lnet_max_recovery_ping_interval",
4123 val, 1, sizeof(val));
4126 snprintf(err_str, sizeof(err_str),
4127 "\"cannot get lnet_max_recovery_ping_interval value: %d\"",
4130 interval = atoi(val);
4133 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4134 "max_recovery_ping_interval", interval,
4135 show_rc, err_rc, l_errno);
4139 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
4140 struct cYAML **err_rc)
4142 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4143 char val[LNET_MAX_STR_LEN];
4144 int max_intf = -1, l_errno = 0;
4145 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4147 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
4151 snprintf(err_str, sizeof(err_str),
4152 "\"cannot get max interfaces: %d\"", rc);
4154 max_intf = atoi(val);
4157 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4158 "max_interfaces", max_intf, show_rc,
4162 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
4163 struct cYAML **err_rc)
4165 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4166 char val[LNET_MAX_STR_LEN];
4167 int discovery = -1, l_errno = 0;
4168 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4170 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
4174 snprintf(err_str, sizeof(err_str),
4175 "\"cannot get discovery setting: %d\"", rc);
4178 * The kernel stores a discovery disabled value. User space
4179 * shows whether discovery is enabled. So the value must be
4182 discovery = !atoi(val);
4185 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4186 "discovery", discovery, show_rc,
4190 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
4191 struct cYAML **err_rc)
4193 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4194 char val[LNET_MAX_STR_LEN];
4195 int drop_asym_route = -1, l_errno = 0;
4196 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4198 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
4202 snprintf(err_str, sizeof(err_str),
4203 "\"cannot get drop asym route setting: %d\"", rc);
4205 drop_asym_route = atoi(val);
4208 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
4209 "drop_asym_route", drop_asym_route,
4210 show_rc, err_rc, l_errno);
4213 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
4214 struct cYAML **err_rc)
4216 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
4217 "numa_range", show_rc, err_rc);
4220 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
4221 struct cYAML **err_rc)
4223 struct lnet_ioctl_lnet_stats data;
4224 struct lnet_counters *cntrs;
4227 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
4228 struct cYAML *root = NULL, *stats = NULL;
4230 LIBCFS_IOC_INIT_V2(data, st_hdr);
4232 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
4237 "\"cannot get lnet statistics: %s\"",
4243 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
4245 cntrs = &data.st_cntrs;
4247 root = cYAML_create_object(NULL, NULL);
4251 stats = cYAML_create_object(root, "statistics");
4255 if (!cYAML_create_number(stats, "msgs_alloc",
4256 cntrs->lct_common.lcc_msgs_alloc))
4259 if (!cYAML_create_number(stats, "msgs_max",
4260 cntrs->lct_common.lcc_msgs_max))
4263 if (!cYAML_create_number(stats, "rst_alloc",
4264 cntrs->lct_health.lch_rst_alloc))
4267 if (!cYAML_create_number(stats, "errors",
4268 cntrs->lct_common.lcc_errors))
4271 if (!cYAML_create_number(stats, "send_count",
4272 cntrs->lct_common.lcc_send_count))
4275 if (!cYAML_create_number(stats, "resend_count",
4276 cntrs->lct_health.lch_resend_count))
4279 if (!cYAML_create_number(stats, "response_timeout_count",
4280 cntrs->lct_health.lch_response_timeout_count))
4283 if (!cYAML_create_number(stats, "local_interrupt_count",
4284 cntrs->lct_health.lch_local_interrupt_count))
4287 if (!cYAML_create_number(stats, "local_dropped_count",
4288 cntrs->lct_health.lch_local_dropped_count))
4291 if (!cYAML_create_number(stats, "local_aborted_count",
4292 cntrs->lct_health.lch_local_aborted_count))
4295 if (!cYAML_create_number(stats, "local_no_route_count",
4296 cntrs->lct_health.lch_local_no_route_count))
4299 if (!cYAML_create_number(stats, "local_timeout_count",
4300 cntrs->lct_health.lch_local_timeout_count))
4303 if (!cYAML_create_number(stats, "local_error_count",
4304 cntrs->lct_health.lch_local_error_count))
4307 if (!cYAML_create_number(stats, "remote_dropped_count",
4308 cntrs->lct_health.lch_remote_dropped_count))
4311 if (!cYAML_create_number(stats, "remote_error_count",
4312 cntrs->lct_health.lch_remote_error_count))
4315 if (!cYAML_create_number(stats, "remote_timeout_count",
4316 cntrs->lct_health.lch_remote_timeout_count))
4319 if (!cYAML_create_number(stats, "network_timeout_count",
4320 cntrs->lct_health.lch_network_timeout_count))
4323 if (!cYAML_create_number(stats, "recv_count",
4324 cntrs->lct_common.lcc_recv_count))
4327 if (!cYAML_create_number(stats, "route_count",
4328 cntrs->lct_common.lcc_route_count))
4331 if (!cYAML_create_number(stats, "drop_count",
4332 cntrs->lct_common.lcc_drop_count))
4335 if (!cYAML_create_number(stats, "send_length",
4336 cntrs->lct_common.lcc_send_length))
4339 if (!cYAML_create_number(stats, "recv_length",
4340 cntrs->lct_common.lcc_recv_length))
4343 if (!cYAML_create_number(stats, "route_length",
4344 cntrs->lct_common.lcc_route_length))
4347 if (!cYAML_create_number(stats, "drop_length",
4348 cntrs->lct_common.lcc_drop_length))
4352 cYAML_print_tree(root);
4354 snprintf(err_str, sizeof(err_str), "\"success\"");
4355 rc = LUSTRE_CFG_RC_NO_ERR;
4357 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
4358 cYAML_free_tree(root);
4359 } else if (show_rc != NULL && *show_rc != NULL) {
4360 cYAML_insert_sibling((*show_rc)->cy_child,
4367 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4372 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc)
4374 struct libcfs_ioctl_data data;
4375 int rc = LUSTRE_CFG_RC_NO_ERR;
4377 char err_str[LNET_MAX_STR_LEN];
4379 LIBCFS_IOC_INIT(data);
4381 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data);
4386 "\"cannot reset lnet statistics: %s\"",
4390 snprintf(err_str, sizeof(err_str), "\"success\"");
4391 rc = LUSTRE_CFG_RC_NO_ERR;
4394 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
4398 typedef int (*cmd_handler_t)(struct cYAML *tree,
4399 struct cYAML **show_rc,
4400 struct cYAML **err_rc);
4402 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
4403 struct cYAML **err_rc)
4405 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
4407 net = cYAML_get_object_item(tree, "net");
4408 gw = cYAML_get_object_item(tree, "gateway");
4409 hop = cYAML_get_object_item(tree, "hop");
4410 prio = cYAML_get_object_item(tree, "priority");
4411 sen = cYAML_get_object_item(tree, "health_sensitivity");
4412 seq_no = cYAML_get_object_item(tree, "seq_no");
4414 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
4415 (gw) ? gw->cy_valuestring : NULL,
4416 (hop) ? hop->cy_valueint : -1,
4417 (prio) ? prio->cy_valueint : -1,
4418 (sen) ? sen->cy_valueint : -1,
4419 (seq_no) ? seq_no->cy_valueint : -1,
4425 * 0: <intf_name>['['<expr>']']
4426 * 1: <intf_name>['['<expr>']']
4428 static int yaml_copy_intf_info(struct cYAML *intf_tree,
4429 struct lnet_dlc_network_descr *nw_descr)
4431 struct cYAML *child = NULL;
4432 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
4433 struct lnet_dlc_intf_descr *intf_descr, *tmp;
4435 if (intf_tree == NULL || nw_descr == NULL)
4436 return LUSTRE_CFG_RC_BAD_PARAM;
4438 /* now grab all the interfaces and their cpts */
4439 child = intf_tree->cy_child;
4440 while (child != NULL) {
4441 if (child->cy_valuestring == NULL) {
4442 child = child->cy_next;
4446 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
4449 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
4450 child->cy_valuestring,
4451 strlen(child->cy_valuestring));
4452 if (rc != LUSTRE_CFG_RC_NO_ERR)
4456 child = child->cy_next;
4460 return LUSTRE_CFG_RC_MISSING_PARAM;
4465 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
4467 list_del(&intf_descr->intf_on_network);
4468 free_intf_descr(intf_descr);
4475 yaml_extract_cmn_tunables(struct cYAML *tree,
4476 struct lnet_ioctl_config_lnd_cmn_tunables *tunables)
4478 struct cYAML *tun, *item;
4480 tun = cYAML_get_object_item(tree, "tunables");
4482 item = cYAML_get_object_item(tun, "peer_timeout");
4484 tunables->lct_peer_timeout = item->cy_valueint;
4486 tunables->lct_peer_timeout = -1;
4487 item = cYAML_get_object_item(tun, "peer_credits");
4489 tunables->lct_peer_tx_credits = item->cy_valueint;
4490 item = cYAML_get_object_item(tun, "peer_buffer_credits");
4492 tunables->lct_peer_rtr_credits = item->cy_valueint;
4493 item = cYAML_get_object_item(tun, "credits");
4495 tunables->lct_max_tx_credits = item->cy_valueint;
4504 yaml_extract_tunables(struct cYAML *tree,
4505 struct lnet_ioctl_config_lnd_tunables *tunables,
4510 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn);
4515 lustre_yaml_extract_lnd_tunables(tree, net_type,
4522 yaml_extract_cpt(struct cYAML *tree,
4523 struct cfs_expr_list **global_cpts)
4528 smp = cYAML_get_object_item(tree, "CPT");
4530 rc = cfs_expr_list_parse(smp->cy_valuestring,
4531 strlen(smp->cy_valuestring),
4532 0, UINT_MAX, global_cpts);
4534 *global_cpts = NULL;
4540 * - net type: <net>[<NUM>]
4542 * - nid: <ip>@<net>[<NUM>]
4545 * 0: <intf_name>['['<expr>']']
4546 * 1: <intf_name>['['<expr>']']
4548 * peer_timeout: <NUM>
4549 * peer_credits: <NUM>
4550 * peer_buffer_credits: <NUM>
4553 * peercredits_hiw: <NUM>
4554 * map_on_demand: <NUM>
4555 * concurrent_sends: <NUM>
4556 * fmr_pool_size: <NUM>
4557 * fmr_flush_trigger: <NUM>
4560 * At least one interface is required. If no interfaces are provided the
4561 * network interface can not be configured.
4563 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
4564 struct cYAML **err_rc)
4566 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
4568 int num_entries = 0, rc;
4569 struct lnet_dlc_network_descr nw_descr;
4570 struct cfs_expr_list *global_cpts = NULL;
4571 struct lnet_ioctl_config_lnd_tunables tunables;
4574 memset(&tunables, 0, sizeof(tunables));
4575 /* Use LND defaults */
4576 tunables.lt_cmn.lct_peer_timeout = -1;
4577 tunables.lt_cmn.lct_peer_tx_credits = -1;
4578 tunables.lt_cmn.lct_peer_rtr_credits = -1;
4579 tunables.lt_cmn.lct_max_tx_credits = -1;
4581 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4582 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4584 ip2net = cYAML_get_object_item(tree, "ip2net");
4585 net = cYAML_get_object_item(tree, "net type");
4587 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4589 nw_descr.nw_id = LOLND;
4592 * if neither net nor ip2nets are present, then we can not
4593 * configure the network.
4595 if (!net && !ip2net)
4596 return LUSTRE_CFG_RC_MISSING_PARAM;
4598 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4599 if (local_nis == NULL)
4600 return LUSTRE_CFG_RC_MISSING_PARAM;
4602 if (!cYAML_is_sequence(local_nis))
4603 return LUSTRE_CFG_RC_BAD_PARAM;
4605 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4606 intf = cYAML_get_object_item(item, "interfaces");
4609 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4610 if (num_entries <= 0) {
4611 cYAML_build_error(num_entries, -1, "ni", "add",
4612 "bad interface list",
4614 return LUSTRE_CFG_RC_BAD_PARAM;
4618 found = yaml_extract_tunables(tree, &tunables,
4619 LNET_NETTYP(nw_descr.nw_id));
4620 yaml_extract_cpt(tree, &global_cpts);
4621 seq_no = cYAML_get_object_item(tree, "seq_no");
4623 rc = lustre_lnet_config_ni(&nw_descr, global_cpts,
4624 (ip2net) ? ip2net->cy_valuestring : NULL,
4625 (found) ? &tunables : NULL,
4626 (seq_no) ? seq_no->cy_valueint : -1,
4629 if (global_cpts != NULL)
4630 cfs_expr_list_free(global_cpts);
4637 * - net-spec: <tcp|o2ib|gni>[NUM]
4639 * 0: <intf name>['['<expr>']']
4640 * 1: <intf name>['['<expr>']']
4642 * 0: <expr.expr.expr.expr>
4643 * 1: <expr.expr.expr.expr>
4645 static int handle_yaml_config_ip2nets(struct cYAML *tree,
4646 struct cYAML **show_rc,
4647 struct cYAML **err_rc)
4649 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
4651 struct lustre_lnet_ip2nets ip2nets;
4652 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
4654 int rc = LUSTRE_CFG_RC_NO_ERR;
4655 struct cfs_expr_list *global_cpts = NULL;
4656 struct cfs_expr_list *el, *el_tmp;
4657 struct lnet_ioctl_config_lnd_tunables tunables;
4658 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
4661 memset(&tunables, 0, sizeof(tunables));
4663 /* initialize all lists */
4664 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
4665 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
4666 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
4668 net = cYAML_get_object_item(tree, "net-spec");
4670 return LUSTRE_CFG_RC_BAD_PARAM;
4672 if (net != NULL && net->cy_valuestring == NULL)
4673 return LUSTRE_CFG_RC_BAD_PARAM;
4675 /* assign the network id */
4676 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
4677 if (ip2nets.ip2nets_net.nw_id == LNET_NET_ANY)
4678 return LUSTRE_CFG_RC_BAD_PARAM;
4680 seq_no = cYAML_get_object_item(tree, "seq_no");
4682 intf = cYAML_get_object_item(tree, "interfaces");
4684 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4686 return LUSTRE_CFG_RC_BAD_PARAM;
4689 ip_range = cYAML_get_object_item(tree, "ip-range");
4690 if (ip_range != NULL) {
4691 item = ip_range->cy_child;
4692 while (item != NULL) {
4693 if (item->cy_valuestring == NULL) {
4694 item = item->cy_next;
4698 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4699 item->cy_valuestring);
4701 if (rc != LUSTRE_CFG_RC_NO_ERR)
4704 item = item->cy_next;
4708 found = yaml_extract_tunables(tree, &tunables,
4709 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4710 yaml_extract_cpt(tree, &global_cpts);
4712 rc = lustre_lnet_config_ip2nets(&ip2nets,
4713 (found) ? &tunables : NULL,
4715 (seq_no) ? seq_no->cy_valueint : -1,
4718 if (global_cpts != NULL)
4719 cfs_expr_list_free(global_cpts);
4722 * don't stop because there was no match. Continue processing the
4723 * rest of the rules. If non-match then nothing is configured
4725 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4726 rc = LUSTRE_CFG_RC_NO_ERR;
4728 list_for_each_entry_safe(intf_descr, intf_tmp,
4729 &ip2nets.ip2nets_net.nw_intflist,
4731 list_del(&intf_descr->intf_on_network);
4732 free_intf_descr(intf_descr);
4735 list_for_each_entry_safe(ip_range_descr, tmp,
4736 &ip2nets.ip2nets_ip_ranges,
4738 list_del(&ip_range_descr->ipr_entry);
4739 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4741 list_del(&el->el_link);
4742 cfs_expr_list_free(el);
4744 free(ip_range_descr);
4750 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4751 struct cYAML **err_rc)
4753 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4755 int num_entries, rc;
4756 struct lnet_dlc_network_descr nw_descr;
4758 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4759 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4761 net = cYAML_get_object_item(tree, "net type");
4763 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4765 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4766 if (local_nis == NULL)
4767 return LUSTRE_CFG_RC_MISSING_PARAM;
4769 if (!cYAML_is_sequence(local_nis))
4770 return LUSTRE_CFG_RC_BAD_PARAM;
4772 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4773 intf = cYAML_get_object_item(item, "interfaces");
4776 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4777 if (num_entries <= 0) {
4778 cYAML_build_error(num_entries, -1, "ni", "add",
4779 "bad interface list",
4781 return LUSTRE_CFG_RC_BAD_PARAM;
4785 seq_no = cYAML_get_object_item(tree, "seq_no");
4787 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4788 (seq_no) ? seq_no->cy_valueint : -1,
4794 /* Create a nidstring parseable by the nidstrings library from the nid
4795 * information encoded in the CYAML structure.
4796 * NOTE: Caller must free memory allocated to nidstr
4798 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4799 char *prim_nid, int cmd)
4801 int num_strs = 0, rc;
4802 size_t buf_size, buf_pos, nidstr_len = 0;
4804 struct cYAML *child = NULL, *entry = NULL;
4806 if (cYAML_is_sequence(nids_entry)) {
4807 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4808 entry = cYAML_get_object_item(child, "nid");
4809 /* don't count an empty entry */
4810 if (!entry || !entry->cy_valuestring)
4814 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4815 if (cmd == LNETCTL_DEL_CMD) {
4817 * primary nid is present in the list of
4818 * nids so that means we want to delete
4819 * the entire peer, so no need to go
4820 * further. Just delete the entire peer.
4822 return LUSTRE_CFG_RC_NO_ERR;
4829 * + 1 for the space separating each string, and
4830 * accounts for the terminating null char
4832 nidstr_len += strlen(entry->cy_valuestring) + 1;
4837 if (num_strs == 0 && !prim_nid)
4838 return LUSTRE_CFG_RC_MISSING_PARAM;
4839 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4840 return LUSTRE_CFG_RC_NO_ERR;
4842 buffer = malloc(nidstr_len);
4844 return LUSTRE_CFG_RC_OUT_OF_MEM;
4846 /* now grab all the nids */
4849 buf_size = nidstr_len;
4851 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4852 entry = cYAML_get_object_item(child, "nid");
4853 if (!entry || !entry->cy_valuestring)
4857 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4861 rc = snprintf(buffer + buf_pos, buf_size, " ");
4862 buf_pos += (rc < buf_size) ? rc : buf_size;
4863 buf_size = nidstr_len - buf_pos;
4866 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4867 entry->cy_valuestring);
4868 buf_pos += (rc < buf_size) ? rc : buf_size;
4869 buf_size = nidstr_len - buf_pos;
4874 return LUSTRE_CFG_RC_NO_ERR;
4877 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4878 struct cYAML **err_rc, int cmd)
4880 int rc, num_nids = 0, seqn;
4881 bool mr_value = false;
4882 char *nidstr = NULL, *prim_nidstr;
4883 char err_str[LNET_MAX_STR_LEN];
4884 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4885 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4886 lnet_nid_t pnid = LNET_NID_ANY;
4889 seq_no = cYAML_get_object_item(tree, "seq_no");
4890 seqn = seq_no ? seq_no->cy_valueint : -1;
4892 prim_nid = cYAML_get_object_item(tree, "primary nid");
4893 peer_nis = cYAML_get_object_item(tree, "peer ni");
4895 rc = LUSTRE_CFG_RC_BAD_PARAM;
4896 snprintf(err_str, LNET_MAX_STR_LEN,
4897 "\"primary nid\" must be specified");
4901 prim_nidstr = prim_nid->cy_valuestring;
4903 /* if the provided primary NID is bad, no need to go any further */
4904 pnid = libcfs_str2nid(prim_nidstr);
4905 if (pnid == LNET_NID_ANY) {
4906 rc = LUSTRE_CFG_RC_BAD_PARAM;
4907 snprintf(err_str, LNET_MAX_STR_LEN,
4908 "badly formatted primary NID: %s", prim_nidstr);
4912 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4913 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4914 snprintf(err_str, LNET_MAX_STR_LEN,
4915 "No nids defined in YAML block");
4917 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4918 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4920 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4921 snprintf(err_str, LNET_MAX_STR_LEN,
4922 "Unrecognized error %d", rc);
4928 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4929 LNET_MAX_NIDS_PER_PEER,
4937 if (cmd == LNETCTL_ADD_CMD) {
4938 mr = cYAML_get_object_item(tree, "Multi-Rail");
4940 if (mr && mr->cy_valuestring) {
4941 if (strcmp(mr->cy_valuestring, "False") == 0)
4943 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4944 rc = LUSTRE_CFG_RC_BAD_PARAM;
4945 snprintf(err_str, LNET_MAX_STR_LEN,
4946 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4947 mr->cy_valuestring);
4953 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist, cmd,
4954 num_nids, mr_value, force,
4961 if (rc != LUSTRE_CFG_RC_NO_ERR)
4962 cYAML_build_error(rc, seqn, "peer",
4963 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4969 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4970 struct cYAML **err_rc)
4972 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4975 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4976 struct cYAML **err_rc)
4978 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4981 static int handle_yaml_config_buffers(struct cYAML *tree,
4982 struct cYAML **show_rc,
4983 struct cYAML **err_rc)
4986 struct cYAML *tiny, *small, *large, *seq_no;
4988 tiny = cYAML_get_object_item(tree, "tiny");
4989 small = cYAML_get_object_item(tree, "small");
4990 large = cYAML_get_object_item(tree, "large");
4991 seq_no = cYAML_get_object_item(tree, "seq_no");
4993 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4994 (small) ? small->cy_valueint : -1,
4995 (large) ? large->cy_valueint : -1,
4996 (seq_no) ? seq_no->cy_valueint : -1,
5002 static int handle_yaml_config_routing(struct cYAML *tree,
5003 struct cYAML **show_rc,
5004 struct cYAML **err_rc)
5006 int rc = LUSTRE_CFG_RC_NO_ERR;
5007 struct cYAML *seq_no, *enable;
5009 seq_no = cYAML_get_object_item(tree, "seq_no");
5010 enable = cYAML_get_object_item(tree, "enable");
5013 rc = lustre_lnet_enable_routing(enable->cy_valueint,
5015 seq_no->cy_valueint : -1,
5022 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
5023 struct cYAML **err_rc)
5027 struct cYAML *seq_no;
5029 net = cYAML_get_object_item(tree, "net");
5030 gw = cYAML_get_object_item(tree, "gateway");
5031 seq_no = cYAML_get_object_item(tree, "seq_no");
5033 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
5034 (gw) ? gw->cy_valuestring : NULL,
5035 (seq_no) ? seq_no->cy_valueint : -1,
5039 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
5040 struct cYAML **err_rc)
5042 struct cYAML *seq_no;
5044 seq_no = cYAML_get_object_item(tree, "seq_no");
5046 return lustre_lnet_enable_routing(0, (seq_no) ?
5047 seq_no->cy_valueint : -1,
5051 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
5052 struct cYAML **err_rc)
5058 struct cYAML *detail;
5059 struct cYAML *seq_no;
5061 net = cYAML_get_object_item(tree, "net");
5062 gw = cYAML_get_object_item(tree, "gateway");
5063 hop = cYAML_get_object_item(tree, "hop");
5064 prio = cYAML_get_object_item(tree, "priority");
5065 detail = cYAML_get_object_item(tree, "detail");
5066 seq_no = cYAML_get_object_item(tree, "seq_no");
5068 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
5069 (gw) ? gw->cy_valuestring : NULL,
5070 (hop) ? hop->cy_valueint : -1,
5071 (prio) ? prio->cy_valueint : -1,
5072 (detail) ? detail->cy_valueint : 0,
5073 (seq_no) ? seq_no->cy_valueint : -1,
5074 show_rc, err_rc, false);
5077 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
5078 struct cYAML **err_rc)
5080 struct cYAML *net, *detail, *seq_no;
5082 net = cYAML_get_object_item(tree, "net type");
5083 detail = cYAML_get_object_item(tree, "detail");
5084 seq_no = cYAML_get_object_item(tree, "seq_no");
5086 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
5087 (detail) ? detail->cy_valueint : 0,
5088 (seq_no) ? seq_no->cy_valueint : -1,
5089 show_rc, err_rc, false);
5092 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
5093 struct cYAML **err_rc)
5095 struct cYAML *seq_no;
5097 seq_no = cYAML_get_object_item(tree, "seq_no");
5099 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
5100 show_rc, err_rc, false);
5103 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
5104 struct cYAML **err_rc)
5106 struct cYAML *seq_no, *nid, *detail;
5108 seq_no = cYAML_get_object_item(tree, "seq_no");
5109 detail = cYAML_get_object_item(tree, "detail");
5110 nid = cYAML_get_object_item(tree, "nid");
5112 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
5113 (detail) ? detail->cy_valueint : 0,
5114 (seq_no) ? seq_no->cy_valueint : -1,
5115 show_rc, err_rc, false);
5118 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
5119 struct cYAML **err_rc)
5121 struct cYAML *seq_no;
5123 seq_no = cYAML_get_object_item(tree, "seq_no");
5125 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
5129 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
5130 struct cYAML **err_rc)
5132 struct cYAML *seq_no, *range;
5134 seq_no = cYAML_get_object_item(tree, "seq_no");
5135 range = cYAML_get_object_item(tree, "range");
5137 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
5138 seq_no ? seq_no->cy_valueint : -1,
5142 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
5143 struct cYAML **err_rc)
5145 struct cYAML *seq_no;
5147 seq_no = cYAML_get_object_item(tree, "seq_no");
5149 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
5153 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
5154 struct cYAML **err_rc)
5156 struct cYAML *seq_no;
5158 seq_no = cYAML_get_object_item(tree, "seq_no");
5160 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
5164 static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
5165 struct cYAML **err_rc)
5167 struct cYAML *seq_no, *idx;
5169 seq_no = cYAML_get_object_item(tree, "seq_no");
5170 idx = cYAML_get_object_item(tree, "idx");
5172 return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
5173 seq_no ? seq_no->cy_valueint : -1,
5177 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
5178 struct cYAML **err_rc)
5180 struct cYAML *seq_no, *src, *rte, *dst, *prio, *idx;
5181 union lnet_udsp_action action;
5183 seq_no = cYAML_get_object_item(tree, "seq_no");
5184 src = cYAML_get_object_item(tree, "src");
5185 rte = cYAML_get_object_item(tree, "rte");
5186 dst = cYAML_get_object_item(tree, "dst");
5187 prio = cYAML_get_object_item(tree, "priority");
5188 idx = cYAML_get_object_item(tree, "idx");
5190 action.udsp_priority = prio ? prio->cy_valueint : -1;
5192 return lustre_lnet_add_udsp(src ? src->cy_valuestring : NULL,
5193 dst ? dst->cy_valuestring : NULL,
5194 rte ? rte->cy_valuestring : NULL,
5195 prio ? "priority" : "",
5197 idx ? idx->cy_valueint : -1,
5198 seq_no ? seq_no->cy_valueint : -1,
5202 static int handle_yaml_show_udsp(struct cYAML *tree, struct cYAML **show_rc,
5203 struct cYAML **err_rc)
5205 struct cYAML *seq_no;
5208 seq_no = cYAML_get_object_item(tree, "seq_no");
5209 idx = cYAML_get_object_item(tree, "idx");
5211 return lustre_lnet_show_udsp(idx ? idx->cy_valueint : -1,
5212 seq_no ? seq_no->cy_valueint : -1,
5216 static int handle_yaml_config_global_settings(struct cYAML *tree,
5217 struct cYAML **show_rc,
5218 struct cYAML **err_rc)
5220 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5221 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5225 seq_no = cYAML_get_object_item(tree, "seq_no");
5226 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5227 if (!max_intf) /* try legacy name */
5228 max_intf = cYAML_get_object_item(tree, "max_intf");
5230 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
5231 seq_no ? seq_no->cy_valueint
5235 numa = cYAML_get_object_item(tree, "numa_range");
5237 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
5238 seq_no ? seq_no->cy_valueint
5242 discovery = cYAML_get_object_item(tree, "discovery");
5244 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
5245 seq_no ? seq_no->cy_valueint
5249 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5250 if (drop_asym_route)
5251 rc = lustre_lnet_config_drop_asym_route(
5252 drop_asym_route->cy_valueint,
5253 seq_no ? seq_no->cy_valueint : -1,
5256 retry = cYAML_get_object_item(tree, "retry_count");
5258 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
5259 seq_no ? seq_no->cy_valueint
5263 tto = cYAML_get_object_item(tree, "transaction_timeout");
5265 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
5266 seq_no ? seq_no->cy_valueint
5270 sen = cYAML_get_object_item(tree, "health_sensitivity");
5272 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
5273 seq_no ? seq_no->cy_valueint
5277 recov = cYAML_get_object_item(tree, "recovery_interval");
5279 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
5280 seq_no ? seq_no->cy_valueint
5284 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5286 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
5287 seq_no ? seq_no->cy_valueint
5291 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5293 rc = lustre_lnet_config_response_tracking(rsp_tracking->cy_valueint,
5294 seq_no ? seq_no->cy_valueint
5298 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5300 rc = lustre_lnet_config_recovery_limit(recov_limit->cy_valueint,
5301 seq_no ? seq_no->cy_valueint
5308 static int handle_yaml_del_global_settings(struct cYAML *tree,
5309 struct cYAML **show_rc,
5310 struct cYAML **err_rc)
5312 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
5315 seq_no = cYAML_get_object_item(tree, "seq_no");
5316 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5317 if (!max_intf) /* try legacy name */
5318 max_intf = cYAML_get_object_item(tree, "max_intf");
5320 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
5321 seq_no ? seq_no->cy_valueint
5325 numa = cYAML_get_object_item(tree, "numa_range");
5327 rc = lustre_lnet_config_numa_range(0,
5328 seq_no ? seq_no->cy_valueint
5332 /* peer discovery is enabled by default */
5333 discovery = cYAML_get_object_item(tree, "discovery");
5335 rc = lustre_lnet_config_discovery(1,
5336 seq_no ? seq_no->cy_valueint
5340 /* asymmetrical route messages are accepted by default */
5341 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5342 if (drop_asym_route)
5343 rc = lustre_lnet_config_drop_asym_route(
5344 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
5349 static int handle_yaml_show_global_settings(struct cYAML *tree,
5350 struct cYAML **show_rc,
5351 struct cYAML **err_rc)
5353 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
5354 *sen, *recov, *rsen, *drop_asym_route, *rsp_tracking,
5358 seq_no = cYAML_get_object_item(tree, "seq_no");
5359 max_intf = cYAML_get_object_item(tree, "max_interfaces");
5360 if (!max_intf) /* try legacy name */
5361 max_intf = cYAML_get_object_item(tree, "max_intf");
5363 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
5367 numa = cYAML_get_object_item(tree, "numa_range");
5369 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
5373 discovery = cYAML_get_object_item(tree, "discovery");
5375 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
5379 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
5380 if (drop_asym_route)
5381 rc = lustre_lnet_show_drop_asym_route(
5382 seq_no ? seq_no->cy_valueint : -1,
5385 retry = cYAML_get_object_item(tree, "retry_count");
5387 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
5391 tto = cYAML_get_object_item(tree, "transaction_timeout");
5393 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
5397 sen = cYAML_get_object_item(tree, "health_sensitivity");
5399 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5403 recov = cYAML_get_object_item(tree, "recovery_interval");
5405 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
5409 rsen = cYAML_get_object_item(tree, "router_sensitivity");
5411 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
5415 rsp_tracking = cYAML_get_object_item(tree, "response_tracking");
5417 rc = lustre_lnet_show_response_tracking(seq_no ?
5418 seq_no->cy_valueint :
5422 recov_limit = cYAML_get_object_item(tree, "recovery_limit");
5424 rc = lustre_lnet_show_recovery_limit(seq_no ?
5425 seq_no->cy_valueint :
5432 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
5433 struct cYAML **err_rc)
5435 struct cYAML *seq_no, *nid, *timeout, *src_nid;
5437 seq_no = cYAML_get_object_item(tree, "seq_no");
5438 nid = cYAML_get_object_item(tree, "primary nid");
5439 timeout = cYAML_get_object_item(tree, "timeout");
5440 src_nid = cYAML_get_object_item(tree, "source_nid");
5442 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
5443 (src_nid) ? src_nid->cy_valuestring : NULL,
5444 (timeout) ? timeout->cy_valueint : 1000,
5445 (seq_no) ? seq_no->cy_valueint : -1,
5449 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
5450 struct cYAML **err_rc)
5452 struct cYAML *seq_no, *nid, *force;
5454 seq_no = cYAML_get_object_item(tree, "seq_no");
5455 nid = cYAML_get_object_item(tree, "primary nid");
5456 force = cYAML_get_object_item(tree, "force");
5458 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
5459 (force) ? force->cy_valueint : 0,
5460 (seq_no) ? seq_no->cy_valueint : -1,
5464 static int handle_yaml_no_op()
5466 return LUSTRE_CFG_RC_NO_ERR;
5469 struct lookup_cmd_hdlr_tbl {
5474 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
5475 { .name = "route", .cb = handle_yaml_config_route },
5476 { .name = "net", .cb = handle_yaml_config_ni },
5477 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
5478 { .name = "peer", .cb = handle_yaml_config_peer },
5479 { .name = "routing", .cb = handle_yaml_config_routing },
5480 { .name = "buffers", .cb = handle_yaml_config_buffers },
5481 { .name = "statistics", .cb = handle_yaml_no_op },
5482 { .name = "global", .cb = handle_yaml_config_global_settings},
5483 { .name = "numa", .cb = handle_yaml_config_numa },
5484 { .name = "ping", .cb = handle_yaml_no_op },
5485 { .name = "discover", .cb = handle_yaml_no_op },
5486 { .name = "udsp", .cb = handle_yaml_config_udsp },
5489 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
5490 { .name = "route", .cb = handle_yaml_del_route },
5491 { .name = "net", .cb = handle_yaml_del_ni },
5492 { .name = "ip2nets", .cb = handle_yaml_no_op },
5493 { .name = "peer", .cb = handle_yaml_del_peer },
5494 { .name = "routing", .cb = handle_yaml_del_routing },
5495 { .name = "buffers", .cb = handle_yaml_no_op },
5496 { .name = "statistics", .cb = handle_yaml_no_op },
5497 { .name = "global", .cb = handle_yaml_del_global_settings},
5498 { .name = "numa", .cb = handle_yaml_del_numa },
5499 { .name = "ping", .cb = handle_yaml_no_op },
5500 { .name = "discover", .cb = handle_yaml_no_op },
5501 { .name = "udsp", .cb = handle_yaml_del_udsp },
5504 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
5505 { .name = "route", .cb = handle_yaml_show_route },
5506 { .name = "net", .cb = handle_yaml_show_net },
5507 { .name = "peer", .cb = handle_yaml_show_peers },
5508 { .name = "ip2nets", .cb = handle_yaml_no_op },
5509 { .name = "routing", .cb = handle_yaml_show_routing },
5510 { .name = "buffers", .cb = handle_yaml_show_routing },
5511 { .name = "statistics", .cb = handle_yaml_show_stats },
5512 { .name = "global", .cb = handle_yaml_show_global_settings},
5513 { .name = "numa", .cb = handle_yaml_show_numa },
5514 { .name = "ping", .cb = handle_yaml_no_op },
5515 { .name = "discover", .cb = handle_yaml_no_op },
5516 { .name = "udsp", .cb = handle_yaml_show_udsp },
5519 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
5520 { .name = "route", .cb = handle_yaml_no_op },
5521 { .name = "net", .cb = handle_yaml_no_op },
5522 { .name = "peer", .cb = handle_yaml_no_op },
5523 { .name = "ip2nets", .cb = handle_yaml_no_op },
5524 { .name = "routing", .cb = handle_yaml_no_op },
5525 { .name = "buffers", .cb = handle_yaml_no_op },
5526 { .name = "statistics", .cb = handle_yaml_no_op },
5527 { .name = "global", .cb = handle_yaml_no_op },
5528 { .name = "numa", .cb = handle_yaml_no_op },
5529 { .name = "ping", .cb = handle_yaml_ping },
5530 { .name = "discover", .cb = handle_yaml_discover },
5533 static cmd_handler_t lookup_fn(char *key,
5534 struct lookup_cmd_hdlr_tbl *tbl)
5540 for (i = 0; tbl[i].name != NULL; i++) {
5541 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
5548 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
5549 struct cYAML **show_rc, struct cYAML **err_rc)
5551 struct cYAML *tree, *item = NULL, *head, *child;
5553 char err_str[LNET_MAX_STR_LEN];
5554 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
5556 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
5558 return LUSTRE_CFG_RC_BAD_PARAM;
5560 child = tree->cy_child;
5561 while (child != NULL) {
5562 cb = lookup_fn(child->cy_string, table);
5564 snprintf(err_str, sizeof(err_str),
5565 "\"call back for '%s' not found\"",
5567 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
5568 "yaml", "helper", err_str, err_rc);
5572 if (cYAML_is_sequence(child)) {
5573 while ((head = cYAML_get_next_seq_item(child, &item))
5575 rc = cb(head, show_rc, err_rc);
5576 if (rc != LUSTRE_CFG_RC_NO_ERR)
5580 rc = cb(child, show_rc, err_rc);
5581 if (rc != LUSTRE_CFG_RC_NO_ERR)
5585 child = child->cy_next;
5589 cYAML_free_tree(tree);
5594 int lustre_yaml_config(char *f, struct cYAML **err_rc)
5596 return lustre_yaml_cb_helper(f, lookup_config_tbl,
5600 int lustre_yaml_del(char *f, struct cYAML **err_rc)
5602 return lustre_yaml_cb_helper(f, lookup_del_tbl,
5606 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5608 return lustre_yaml_cb_helper(f, lookup_show_tbl,
5612 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
5614 return lustre_yaml_cb_helper(f, lookup_exec_tbl,