4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Copyright (c) 2014, 2017, Intel Corporation.
24 * Amir Shehata <amir.shehata@intel.com>
29 * 1. APIs that take the actual parameters expanded. This is for other
30 * entities that would like to link against the library and call the APIs
31 * directly without having to form an intermediate representation.
32 * 2. APIs that take a YAML file and parses out the information there and
33 * calls the APIs mentioned in 1
44 #include <sys/ioctl.h>
46 #include <libcfs/util/ioctl.h>
47 #include <linux/lnet/lnetctl.h>
49 #include <sys/types.h>
53 #include <rdma/rdma_user_cm.h>
54 #include "liblnetconfig.h"
56 #include <libcfs/util/param.h>
58 #ifndef HAVE_USRSPC_RDMA_PS_TCP
59 #define RDMA_PS_TCP 0x0106
62 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
66 * lustre_lnet_ip_range_descr
67 * Describes an IP range.
68 * Each octect is an expression
70 struct lustre_lnet_ip_range_descr {
71 struct list_head ipr_entry;
72 struct list_head ipr_expr;
77 * Describes an ip2nets rule. This can be on a list of rules.
79 struct lustre_lnet_ip2nets {
80 struct lnet_dlc_network_descr ip2nets_net;
81 struct list_head ip2nets_ip_ranges;
84 int open_sysfs_file(const char *path, const char *attr, const int mode)
87 char filename[LNET_MAX_STR_LEN];
89 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
92 snprintf(filename, sizeof(filename), "%s%s",
95 fd = open(filename, mode);
100 static int read_sysfs_file(const char *path, const char *attr,
101 void *val, const size_t size, const int nelem)
104 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
106 fd = open_sysfs_file(path, attr, O_RDONLY);
108 return LUSTRE_CFG_RC_NO_MATCH;
110 if (read(fd, val, size * nelem) == -1)
113 rc = LUSTRE_CFG_RC_NO_ERR;
120 static int write_sysfs_file(const char *path, const char *attr,
121 void *val, const size_t size, const int nelem)
124 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
126 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
128 return LUSTRE_CFG_RC_NO_MATCH;
130 if (write(fd, val, size * nelem) == -1)
133 rc = LUSTRE_CFG_RC_NO_ERR;
142 * frees the memory allocated for an intf descriptor.
144 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
149 if (intf_descr->cpt_expr != NULL)
150 cfs_expr_list_free(intf_descr->cpt_expr);
155 * lustre_lnet_add_ip_range
157 * given a string of the format:
158 * <expr.expr.expr.expr> parse each expr into
159 * a lustre_lnet_ip_range_descr structure and insert on the list.
161 * This function is called from
162 * YAML on each ip-range.
163 * As a result of lnetctl command
164 * When building a NID or P2P selection rules
166 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
168 struct lustre_lnet_ip_range_descr *ip_range;
171 ip_range = calloc(1, sizeof(*ip_range));
172 if (ip_range == NULL)
173 return LUSTRE_CFG_RC_OUT_OF_MEM;
175 INIT_LIST_HEAD(&ip_range->ipr_entry);
176 INIT_LIST_HEAD(&ip_range->ipr_expr);
178 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
179 &ip_range->ipr_expr);
181 return LUSTRE_CFG_RC_BAD_PARAM;
183 list_add_tail(&ip_range->ipr_entry, list);
185 return LUSTRE_CFG_RC_NO_ERR;
188 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
190 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
192 struct lnet_dlc_intf_descr *intf_descr = NULL;
194 char intf_string[LNET_MAX_STR_LEN];
196 if (len >= LNET_MAX_STR_LEN)
197 return LUSTRE_CFG_RC_BAD_PARAM;
199 strncpy(intf_string, intf, len);
200 intf_string[len] = '\0';
202 intf_descr = calloc(1, sizeof(*intf_descr));
203 if (intf_descr == NULL)
204 return LUSTRE_CFG_RC_OUT_OF_MEM;
206 INIT_LIST_HEAD(&intf_descr->intf_on_network);
208 intf_name = intf_string;
209 open_sq_bracket = strchr(intf_string, '[');
210 if (open_sq_bracket != NULL) {
211 close_sq_bracket = strchr(intf_string, ']');
212 if (close_sq_bracket == NULL) {
214 return LUSTRE_CFG_RC_BAD_PARAM;
216 rc = cfs_expr_list_parse(open_sq_bracket,
217 strlen(open_sq_bracket), 0, UINT_MAX,
218 &intf_descr->cpt_expr);
221 return LUSTRE_CFG_RC_BAD_PARAM;
223 strncpy(intf_descr->intf_name, intf_name,
224 open_sq_bracket - intf_name);
225 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
227 strcpy(intf_descr->intf_name, intf_name);
228 intf_descr->cpt_expr = NULL;
231 list_add_tail(&intf_descr->intf_on_network, list);
233 return LUSTRE_CFG_RC_NO_ERR;
236 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
238 if (nw_descr != NULL) {
240 INIT_LIST_HEAD(&nw_descr->network_on_rule);
241 INIT_LIST_HEAD(&nw_descr->nw_intflist);
245 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
246 int max_nids, char *err_str)
248 int rc, num_nids = 0;
249 struct list_head nidlist;
252 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
253 return LUSTRE_CFG_RC_BAD_PARAM;
256 if (strchr(nidstr, '*')) {
257 snprintf(err_str, LNET_MAX_STR_LEN,
258 "asterisk not allowed in nidstring \"%s\"", nidstr);
259 return LUSTRE_CFG_RC_BAD_PARAM;
262 INIT_LIST_HEAD(&nidlist);
263 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
265 snprintf(err_str, LNET_MAX_STR_LEN,
266 "Unable to parse nidlist from: %s\n", nidstr);
267 return LUSTRE_CFG_RC_BAD_PARAM;
270 if (list_empty(&nidlist)) {
271 snprintf(err_str, LNET_MAX_STR_LEN,
272 "\"%s\" does not specify any valid nid lists", nidstr);
273 return LUSTRE_CFG_RC_BAD_PARAM;
276 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
277 cfs_free_nidlist(&nidlist);
279 if (num_nids == -1) {
280 snprintf(err_str, LNET_MAX_STR_LEN,
281 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
283 return LUSTRE_CFG_RC_BAD_PARAM;
287 snprintf(err_str, LNET_MAX_STR_LEN,
288 "Failed to expand nidstr: %s", strerror(num_nids));
289 return LUSTRE_CFG_RC_OUT_OF_MEM;
293 snprintf(err_str, LNET_MAX_STR_LEN,
294 "\"%s\" did not expand to any nids", nidstr);
295 return LUSTRE_CFG_RC_BAD_PARAM;
303 * <intf>[<expr>], <intf>[<expr>],..
305 int lustre_lnet_parse_interfaces(char *intf_str,
306 struct lnet_dlc_network_descr *nw_descr)
311 char *cur = intf_str, *next = NULL;
312 char *end = intf_str + strlen(intf_str);
314 struct lnet_dlc_intf_descr *intf_descr, *tmp;
316 if (nw_descr == NULL)
317 return LUSTRE_CFG_RC_BAD_PARAM;
320 open_square = strchr(cur, '[');
321 if (open_square != NULL) {
322 close_square = strchr(cur, ']');
323 if (close_square == NULL) {
324 rc = LUSTRE_CFG_RC_BAD_PARAM;
328 comma = strchr(cur, ',');
329 if (comma != NULL && comma > close_square) {
331 len = next - close_square;
337 comma = strchr(cur, ',');
347 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
348 if (rc != LUSTRE_CFG_RC_NO_ERR)
354 return LUSTRE_CFG_RC_NO_ERR;
357 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
359 list_del(&intf_descr->intf_on_network);
360 free_intf_descr(intf_descr);
366 int lustre_lnet_config_lib_init(void)
368 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
371 void lustre_lnet_config_lib_uninit(void)
373 unregister_ioc_dev(LNET_DEV_ID);
376 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
377 int seq_no, struct cYAML **err_rc)
379 struct libcfs_ioctl_data data;
382 char err_str[LNET_MAX_STR_LEN] = "\"Success\"";
384 LIBCFS_IOC_INIT(data);
386 /* Reverse logic is used here in order not to change
387 * the lctl utility */
388 data.ioc_flags = load_ni_from_mod ? 0 : 1;
390 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
392 rc = l_ioctl(LNET_DEV_ID, opc, &data);
396 "\"LNet %s error: %s\"", (up) ? "configure" :
397 "unconfigure", strerror(errno));
401 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
402 "lnet", err_str, err_rc);
407 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
408 char *err_str, char *cmd_str)
412 rc = l_ioctl(LNET_DEV_ID, cmd, data);
415 snprintf(err_str, LNET_MAX_STR_LEN,
416 "\"%s peer ni operation failed: %s\"",
417 cmd_str, strerror(errno));
423 static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper,
424 int param, int ioc_call, int seq_no,
425 struct cYAML **show_rc, struct cYAML **err_rc)
428 struct lnet_ioctl_ping_data ping;
429 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
430 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
431 struct lnet_process_id id;
432 char err_str[LNET_MAX_STR_LEN] = {0};
433 char *sep, *token, *end;
436 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
441 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
443 data = calloc(1, len);
447 /* create struct cYAML root object */
448 root = cYAML_create_object(NULL, NULL);
452 ping_node = cYAML_create_seq(root, oper);
453 if (ping_node == NULL)
457 src = libcfs_str2nid(src_nidstr);
458 if (src == LNET_NID_ANY) {
459 snprintf(err_str, sizeof(err_str),
460 "\"cannot parse source NID '%s'\"",
462 rc = LUSTRE_CFG_RC_BAD_PARAM;
463 cYAML_build_error(rc, seq_no, MANAGE_CMD,
464 oper, err_str, err_rc);
471 /* tokenise each nid in string ping_nids */
472 token = strtok(ping_nids, ",");
475 item = cYAML_create_seq_item(ping_node);
479 if (first_seq == NULL)
482 /* check if '-' is a part of NID, token */
483 sep = strchr(token, '-');
485 id.pid = LNET_PID_ANY;
486 /* if no net is specified, libcfs_str2nid() will assume tcp */
487 id.nid = libcfs_str2nid(token);
488 if (id.nid == LNET_NID_ANY) {
489 snprintf(err_str, sizeof(err_str),
490 "\"cannot parse NID '%s'\"",
492 rc = LUSTRE_CFG_RC_BAD_PARAM;
493 cYAML_build_error(rc, seq_no, MANAGE_CMD,
494 oper, err_str, err_rc);
498 if (token[0] == 'u' || token[0] == 'U')
499 id.pid = (strtoul(&token[1], &end, 0) |
500 (LNET_PID_USERFLAG));
502 id.pid = strtoul(token, &end, 0);
504 /* assuming '-' is part of hostname */
506 id.pid = LNET_PID_ANY;
507 id.nid = libcfs_str2nid(token);
508 if (id.nid == LNET_NID_ANY) {
509 snprintf(err_str, sizeof(err_str),
510 "\"cannot parse NID '%s'\"",
512 rc = LUSTRE_CFG_RC_BAD_PARAM;
513 cYAML_build_error(rc, seq_no, MANAGE_CMD,
519 id.nid = libcfs_str2nid(sep + 1);
520 if (id.nid == LNET_NID_ANY) {
521 snprintf(err_str, sizeof(err_str),
522 "\"cannot parse NID '%s'\"",
524 rc = LUSTRE_CFG_RC_BAD_PARAM;
525 cYAML_build_error(rc, seq_no, MANAGE_CMD,
532 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
533 ping.ping_hdr.ioc_len = sizeof(ping);
536 ping.op_param = param;
537 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
538 ping.ping_buf = data;
540 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
543 sizeof(err_str), "failed to %s %s: %s\n", oper,
544 id.pid == LNET_PID_ANY ?
545 libcfs_nid2str(id.nid) :
546 libcfs_id2str(id), strerror(errno));
547 rc = LUSTRE_CFG_RC_BAD_PARAM;
548 cYAML_build_error(rc, seq_no, MANAGE_CMD,
549 oper, err_str, err_rc);
553 if (cYAML_create_string(item, "primary nid",
554 libcfs_nid2str(ping.ping_id.nid)) == NULL)
557 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
558 "True" : "False") == NULL)
561 tmp = cYAML_create_seq(item, "peer ni");
565 for (i = 0; i < ping.ping_count; i++) {
566 if (ping.ping_buf[i].nid == LNET_NID_LO_0)
568 peer_ni = cYAML_create_seq_item(tmp);
571 memset(buf, 0, sizeof buf);
572 snprintf(buf, sizeof buf, "nid");
573 if (cYAML_create_string(peer_ni, buf,
574 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
580 } while ((token = strtok(NULL, ",")) != NULL);
583 rc = LUSTRE_CFG_RC_NO_ERR;
588 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
589 cYAML_free_tree(root);
590 } else if (show_rc != NULL && *show_rc != NULL) {
591 struct cYAML *show_node;
592 show_node = cYAML_get_object_item(*show_rc, oper);
593 if (show_node != NULL && cYAML_is_sequence(show_node)) {
594 cYAML_insert_child(show_node, first_seq);
597 } else if (show_node == NULL) {
598 cYAML_insert_sibling((*show_rc)->cy_child,
602 cYAML_free_tree(root);
611 int lustre_lnet_ping_nid(char *ping_nids, char *src_nidstr, int timeout,
612 int seq_no, struct cYAML **show_rc,
613 struct cYAML **err_rc)
617 rc = infra_ping_nid(ping_nids, src_nidstr, "ping", timeout,
618 IOC_LIBCFS_PING_PEER, seq_no, show_rc, err_rc);
622 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
623 struct cYAML **show_rc, struct cYAML **err_rc)
627 rc = infra_ping_nid(ping_nids, NULL, "discover", force,
628 IOC_LIBCFS_DISCOVER, seq_no, show_rc, err_rc);
632 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
633 bool is_mr, __u32 cmd,
634 char *cmd_type, char *err_str)
636 struct lnet_ioctl_peer_cfg data;
639 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
640 /* When adding a peer we first need to create the peer using the
641 * specified (or implied) primary nid. Then we can add
642 * additional nids to this peer using the primary nid as a key
644 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
645 data.prcfg_mr = is_mr;
646 data.prcfg_prim_nid = nidlist[0];
647 data.prcfg_cfg_nid = LNET_NID_ANY;
649 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
655 /* Add or delete any specified NIs associated with the specified
656 * (or implied) primary nid
658 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
659 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
660 data.prcfg_mr = is_mr;
661 data.prcfg_prim_nid = nidlist[0];
662 data.prcfg_cfg_nid = nidlist[nid_idx];
664 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
670 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
671 /* In the delete case we may have been given just the
672 * primary nid of the peer. This tells us to delete the peer
673 * completely (rather than just delete some of its NIs)
675 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
676 data.prcfg_prim_nid = nidlist[0];
677 data.prcfg_cfg_nid = LNET_NID_ANY;
679 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
686 lustre_lnet_mod_peer_nidlist(lnet_nid_t pnid, lnet_nid_t *lnet_nidlist,
687 int cmd, int num_nids, bool is_mr, int seq_no,
688 struct cYAML **err_rc)
690 int rc = LUSTRE_CFG_RC_NO_ERR;
691 char err_str[LNET_MAX_STR_LEN];
692 lnet_nid_t *lnet_nidlist2 = NULL;
693 int ioc_cmd = (cmd == LNETCTL_ADD_CMD) ? IOC_LIBCFS_ADD_PEER_NI :
694 IOC_LIBCFS_DEL_PEER_NI;
695 char *cmd_str = (cmd == LNETCTL_ADD_CMD) ? ADD_CMD : DEL_CMD;
698 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
699 if (!lnet_nidlist2) {
700 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
701 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
704 lnet_nidlist2[0] = pnid;
705 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
708 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2,
709 num_nids, is_mr, ioc_cmd,
715 cYAML_build_error(rc, seq_no, cmd_str, "peer_ni", err_str, err_rc);
720 replace_sep(char *str, char sep, char newsep)
726 for (i = 0; i < strlen(str); i++) {
727 /* don't replace ',' within [] */
730 else if (str[i] == ']')
732 else if (str[i] == sep && bracket == 0)
737 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
738 int cmd, int seq_no, struct cYAML **err_rc)
741 char err_str[LNET_MAX_STR_LEN] = "Error";
742 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
743 lnet_nid_t pnid = LNET_NID_ANY;
746 rc = LUSTRE_CFG_RC_BAD_PARAM;
747 snprintf(err_str, LNET_MAX_STR_LEN,
748 "--prim_nid must be specified");
752 pnid = libcfs_str2nid(prim_nid);
753 if (pnid == LNET_NID_ANY) {
754 rc = LUSTRE_CFG_RC_BAD_PARAM;
755 snprintf(err_str, LNET_MAX_STR_LEN,
756 "badly formatted primary NID: %s", prim_nid);
763 * if there is no primary nid we need to make the first nid in the
764 * nids list the primary nid
766 replace_sep(nids, ',', ' ');
767 rc = lustre_lnet_parse_nidstr(nids, lnet_nidlist,
768 LNET_MAX_NIDS_PER_PEER, err_str);
775 rc = lustre_lnet_mod_peer_nidlist(pnid, lnet_nidlist,
776 cmd, num_nids, is_mr,
780 if (rc != LUSTRE_CFG_RC_NO_ERR)
781 cYAML_build_error(rc, -1, "peer",
782 cmd == LNETCTL_ADD_CMD ? "add" : "del",
788 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
789 int sen, int seq_no, struct cYAML **err_rc,
792 int rc, num_nids, idx;
794 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
795 struct lnet_ioctl_config_data data;
796 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
798 if (nw == NULL || nidstr == NULL) {
799 snprintf(err_str, LNET_MAX_STR_LEN,
800 "\"missing mandatory parameter:'%s'\"",
801 (nw == NULL && nidstr == NULL) ? "network, gateway" :
802 (nw == NULL) ? "network" : "gateway");
803 rc = LUSTRE_CFG_RC_MISSING_PARAM;
807 rnet = libcfs_str2net(nw);
808 if (rnet == LNET_NET_ANY) {
809 snprintf(err_str, LNET_MAX_STR_LEN,
810 "\"cannot parse remote net %s\"", nw);
811 rc = LUSTRE_CFG_RC_BAD_PARAM;
815 replace_sep(nidstr, ',', ' ');
816 rc = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
817 LNET_MAX_NIDS_PER_PEER, err_str);
823 for (idx = 0; idx < num_nids; idx++) {
824 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
826 if (cmd == LNETCTL_ADD_CMD) {
827 data.cfg_config_u.cfg_route.rtr_hop = hops;
828 data.cfg_config_u.cfg_route.rtr_priority = prio;
829 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
832 data.cfg_nid = lnet_nidlist[idx];
834 if (cmd == LNETCTL_ADD_CMD)
835 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
838 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
841 if (rc != 0 && errno != EEXIST &&
842 errno != EHOSTUNREACH) {
844 snprintf(err_str, LNET_MAX_STR_LEN,
845 "route operation failed: %s",
848 } else if (errno == EEXIST) {
850 * continue chugging along if one of the
851 * routes already exists
858 cYAML_build_error(rc, seq_no,
859 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
865 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
866 int sen, int seq_no, struct cYAML **err_rc)
869 char err_str[LNET_MAX_STR_LEN] = "\"generic error\"";
872 hops = LNET_UNDEFINED_HOPS;
873 } else if (hops < 1 || hops > 255) {
874 snprintf(err_str, LNET_MAX_STR_LEN,
875 "\"invalid hop count %d, must be between 1 and 255\"",
877 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
883 } else if (prio < 0) {
884 snprintf(err_str, LNET_MAX_STR_LEN,
885 "\"invalid priority %d, must be greater than 0\"",
887 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
893 } else if (sen < 1) {
894 snprintf(err_str, LNET_MAX_STR_LEN,
895 "\"invalid health sensitivity %d, must be 1 or greater\"",
897 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
901 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
902 err_rc, LNETCTL_ADD_CMD);
905 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
910 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
911 struct cYAML **err_rc)
913 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
917 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
918 int seq_no, struct cYAML **show_rc,
919 struct cYAML **err_rc, bool backup)
921 struct lnet_ioctl_config_data data;
922 lnet_nid_t gateway_nid;
923 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
925 __u32 net = LNET_NET_ANY;
927 struct cYAML *root = NULL, *route = NULL, *item = NULL;
928 struct cYAML *first_seq = NULL;
929 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
933 net = libcfs_str2net(nw);
934 if (net == LNET_NET_ANY) {
937 "\"cannot parse net '%s'\"", nw);
938 rc = LUSTRE_CFG_RC_BAD_PARAM;
943 /* show all routes without filtering on net */
948 gateway_nid = libcfs_str2nid(gw);
949 if (gateway_nid == LNET_NID_ANY) {
952 "\"cannot parse gateway NID '%s'\"", gw);
953 rc = LUSTRE_CFG_RC_BAD_PARAM;
957 /* show all routes with out filtering on gateway */
958 gateway_nid = LNET_NID_ANY;
960 if ((hops < 1 && hops != -1) || hops > 255) {
963 "\"invalid hop count %d, must be between 0 and 256\"",
965 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
969 /* create struct cYAML root object */
970 root = cYAML_create_object(NULL, NULL);
974 route = cYAML_create_seq(root, "route");
982 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
985 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
991 /* filter on provided data */
992 if (net != LNET_NET_ANY &&
996 if (gateway_nid != LNET_NID_ANY &&
997 gateway_nid != data.cfg_nid)
1001 hops != data.cfg_config_u.cfg_route.rtr_hop)
1005 prio != data.cfg_config_u.cfg_route.rtr_priority)
1008 /* default rc to -1 incase we hit the goto */
1012 item = cYAML_create_seq_item(route);
1016 if (first_seq == NULL)
1019 if (cYAML_create_string(item, "net",
1020 libcfs_net2str(data.cfg_net)) == NULL)
1023 if (cYAML_create_string(item, "gateway",
1024 libcfs_nid2str(data.cfg_nid)) == NULL)
1028 if (cYAML_create_number(item, "hop",
1029 (int) data.cfg_config_u.
1030 cfg_route.rtr_hop) ==
1034 if (cYAML_create_number(item, "priority",
1036 cfg_route.rtr_priority) == NULL)
1039 if (cYAML_create_number(item, "health_sensitivity",
1041 cfg_route.rtr_sensitivity) == NULL)
1044 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1046 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1050 cYAML_create_string(item, "state",
1052 "up" : "down") == NULL)
1056 cYAML_create_string(item, "type",
1058 "multi-hop" : "single-hop") == NULL)
1063 /* print output iff show_rc is not provided */
1064 if (show_rc == NULL)
1065 cYAML_print_tree(root);
1067 if (l_errno != ENOENT) {
1070 "\"cannot get routes: %s\"",
1075 rc = LUSTRE_CFG_RC_NO_ERR;
1077 snprintf(err_str, sizeof(err_str), "\"success\"");
1079 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1080 cYAML_free_tree(root);
1081 } else if (show_rc != NULL && *show_rc != NULL) {
1082 struct cYAML *show_node;
1083 /* find the route node, if one doesn't exist then
1084 * insert one. Otherwise add to the one there
1086 show_node = cYAML_get_object_item(*show_rc, "route");
1087 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1088 cYAML_insert_child(show_node, first_seq);
1091 } else if (show_node == NULL) {
1092 cYAML_insert_sibling((*show_rc)->cy_child,
1096 cYAML_free_tree(root);
1102 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1107 static int socket_intf_query(int request, char *intf,
1113 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1114 return LUSTRE_CFG_RC_BAD_PARAM;
1116 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1118 return LUSTRE_CFG_RC_BAD_PARAM;
1120 strcpy(ifr->ifr_name, intf);
1121 rc = ioctl(sockfd, request, ifr);
1123 rc = LUSTRE_CFG_RC_BAD_PARAM;
1130 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1135 memset(&ifr, 0, sizeof(ifr));
1136 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1138 return LUSTRE_CFG_RC_BAD_PARAM;
1140 if ((ifr.ifr_flags & IFF_UP) == 0)
1141 return LUSTRE_CFG_RC_BAD_PARAM;
1143 memset(&ifr, 0, sizeof(ifr));
1144 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1146 return LUSTRE_CFG_RC_BAD_PARAM;
1148 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1149 *ip = bswap_32(*ip);
1151 return LUSTRE_CFG_RC_NO_ERR;
1155 * for each interface in the array of interfaces find the IP address of
1156 * that interface, create its nid and add it to an array of NIDs.
1157 * Stop if any of the interfaces is down
1159 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1160 lnet_nid_t **nids, __u32 *nnids,
1161 char *err_str, size_t str_len)
1163 int i = 0, count = 0, rc;
1164 struct lnet_dlc_intf_descr *intf;
1165 char val[LNET_MAX_STR_LEN];
1172 if (nw == NULL || nids == NULL) {
1173 snprintf(err_str, str_len,
1174 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1175 return LUSTRE_CFG_RC_BAD_PARAM;
1178 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1181 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1185 *nids = calloc(count, sizeof(lnet_nid_t));
1186 if (*nids == NULL) {
1187 snprintf(err_str, str_len,
1188 "\"out of memory\"");
1189 return LUSTRE_CFG_RC_OUT_OF_MEM;
1192 * special case the GNI interface since it doesn't have an IP
1193 * address. The assumption is that there can only be one GNI
1194 * interface in the system. No interface name is provided.
1196 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1197 rc = read_sysfs_file(gni_nid_path, "nid", val,
1200 snprintf(err_str, str_len,
1201 "\"cannot read gni nid\"");
1204 gni_num = atoi(val);
1206 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1211 /* look at the other interfaces */
1212 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1213 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1214 /* handle LNDs with numeric interface name */
1215 num = strtoul(intf->intf_name, &endp, 0);
1216 if (endp == intf->intf_name || *endp != '\0') {
1217 rc = LUSTRE_CFG_RC_BAD_PARAM;
1218 snprintf(err_str, str_len,
1219 "\"couldn't query intf %s\"",
1223 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1226 /* handle LNDs with ip interface name */
1227 rc = lustre_lnet_queryip(intf, &ip);
1228 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1229 snprintf(err_str, str_len,
1230 "\"couldn't query intf %s\"",
1234 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1251 * called repeatedly until a match or no more ip range
1253 * ip_range expression
1254 * interface list with all the interface names.
1255 * all the interfaces in the system.
1257 * try to match the ip_range expr to one of the interfaces' IPs in
1258 * the system. If we hit a patch for an interface. Check if that
1259 * interface name is in the list.
1261 * If there are more than one interface in the list, then make sure
1262 * that the IPs for all of these interfaces match the ip ranges
1265 * for each interface in intf_list
1266 * look up the intf name in ifa
1267 * if not there then no match
1268 * check ip obtained from ifa against a match to any of the
1270 * If no match, then fail
1272 * The result is that all the interfaces have to match.
1274 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1275 struct list_head *intf_list,
1276 struct list_head *ip_ranges)
1280 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1281 struct ifaddrs *ifaddr = ifa;
1282 struct lustre_lnet_ip_range_descr *ip_range;
1286 * if there are no explicit interfaces, and no ip ranges, then
1287 * configure the first tcp interface we encounter.
1289 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1290 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1291 if (ifaddr->ifa_addr == NULL)
1294 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1297 family = ifaddr->ifa_addr->sa_family;
1298 if (family == AF_INET &&
1299 strcmp(ifaddr->ifa_name, "lo") != 0) {
1300 rc = lustre_lnet_add_intf_descr
1301 (intf_list, ifaddr->ifa_name,
1302 strlen(ifaddr->ifa_name));
1304 if (rc != LUSTRE_CFG_RC_NO_ERR)
1307 return LUSTRE_CFG_RC_MATCH;
1310 return LUSTRE_CFG_RC_NO_MATCH;
1314 * First interface which matches an IP pattern will be used
1316 if (list_empty(intf_list)) {
1318 * no interfaces provided in the rule, but an ip range is
1319 * provided, so try and match an interface to the ip
1322 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1323 if (ifaddr->ifa_addr == NULL)
1326 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1329 family = ifaddr->ifa_addr->sa_family;
1330 if (family == AF_INET) {
1331 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1334 list_for_each_entry(ip_range, ip_ranges,
1336 rc = cfs_ip_addr_match(bswap_32(ip),
1337 &ip_range->ipr_expr);
1341 rc = lustre_lnet_add_intf_descr
1342 (intf_list, ifaddr->ifa_name,
1343 strlen(ifaddr->ifa_name));
1345 if (rc != LUSTRE_CFG_RC_NO_ERR)
1351 if (!list_empty(intf_list))
1352 return LUSTRE_CFG_RC_MATCH;
1354 return LUSTRE_CFG_RC_NO_MATCH;
1358 * If an interface is explicitly specified the ip-range might or
1359 * might not be specified. if specified the interface needs to match the
1360 * ip-range. If no ip-range then the interfaces are
1361 * automatically matched if they are all up.
1362 * If > 1 interfaces all the interfaces must match for the NI to
1365 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1366 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1367 if (ifaddr->ifa_addr == NULL)
1370 family = ifaddr->ifa_addr->sa_family;
1371 if (family == AF_INET &&
1372 strcmp(intf_descr->intf_name,
1373 ifaddr->ifa_name) == 0)
1377 if (ifaddr == NULL) {
1378 list_del(&intf_descr->intf_on_network);
1379 free_intf_descr(intf_descr);
1383 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1384 list_del(&intf_descr->intf_on_network);
1385 free_intf_descr(intf_descr);
1389 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1392 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1393 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1399 /* no match for this interface */
1400 list_del(&intf_descr->intf_on_network);
1401 free_intf_descr(intf_descr);
1405 return LUSTRE_CFG_RC_MATCH;
1408 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1409 lnet_nid_t **nids, __u32 *nnids,
1410 char *err_str, size_t str_len)
1412 struct ifaddrs *ifa;
1413 int rc = LUSTRE_CFG_RC_NO_ERR;
1415 rc = getifaddrs(&ifa);
1417 snprintf(err_str, str_len,
1418 "\"failed to get interface addresses: %d\"", -errno);
1422 rc = lustre_lnet_match_ip_to_intf(ifa,
1423 &ip2nets->ip2nets_net.nw_intflist,
1424 &ip2nets->ip2nets_ip_ranges);
1425 if (rc != LUSTRE_CFG_RC_MATCH) {
1426 snprintf(err_str, str_len,
1427 "\"couldn't match ip to existing interfaces\"");
1432 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1434 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1445 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1446 struct lnet_ioctl_config_lnd_tunables *tunables,
1447 struct cfs_expr_list *global_cpts,
1448 lnet_nid_t *nids, char *err_str)
1451 struct lnet_ioctl_config_ni *conf;
1452 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1453 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1456 struct lnet_dlc_intf_descr *intf_descr;
1458 struct cfs_expr_list *cpt_expr;
1460 list_for_each_entry(intf_descr, intf_list,
1462 if (tunables != NULL)
1463 len = sizeof(struct lnet_ioctl_config_ni) +
1464 sizeof(struct lnet_ioctl_config_lnd_tunables);
1466 len = sizeof(struct lnet_ioctl_config_ni);
1468 data = calloc(1, len);
1470 return LUSTRE_CFG_RC_OUT_OF_MEM;
1471 conf = (struct lnet_ioctl_config_ni*) data;
1472 if (tunables != NULL)
1473 tun = (struct lnet_ioctl_config_lnd_tunables*)
1476 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1477 conf->lic_cfg_hdr.ioc_len = len;
1478 conf->lic_nid = nids[i];
1479 strncpy(conf->lic_ni_intf, intf_descr->intf_name,
1482 if (intf_descr->cpt_expr != NULL)
1483 cpt_expr = intf_descr->cpt_expr;
1484 else if (global_cpts != NULL)
1485 cpt_expr = global_cpts;
1489 if (cpt_expr != NULL) {
1490 count = cfs_expr_list_values(cpt_expr,
1491 LNET_MAX_SHOW_NUM_CPT,
1494 memcpy(conf->lic_cpts, cpt_array,
1495 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1504 conf->lic_ncpts = count;
1506 if (tunables != NULL)
1507 memcpy(tun, tunables, sizeof(*tunables));
1509 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1514 "\"cannot add network: %s\"", strerror(errno));
1522 return LUSTRE_CFG_RC_NO_ERR;
1526 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1527 struct lnet_ioctl_config_lnd_tunables *tunables,
1528 struct cfs_expr_list *global_cpts,
1529 int seq_no, struct cYAML **err_rc)
1531 lnet_nid_t *nids = NULL;
1534 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1539 "\"incomplete ip2nets information\"");
1540 rc = LUSTRE_CFG_RC_BAD_PARAM;
1545 * call below function to resolve the rules into a list of nids.
1546 * The memory is allocated in that function then freed here when
1547 * it's no longer needed.
1549 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1551 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1554 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1555 snprintf(err_str, sizeof(err_str),
1556 "\"no interfaces match ip2nets rules\"");
1560 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1561 tunables, global_cpts, nids,
1568 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1572 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1573 struct cfs_expr_list *global_cpts,
1575 struct lnet_ioctl_config_lnd_tunables *tunables,
1576 long int cpp, int seq_no, struct cYAML **err_rc)
1579 struct lnet_ioctl_config_ni *conf;
1580 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1581 char buf[LNET_MAX_STR_LEN];
1582 int rc = LUSTRE_CFG_RC_NO_ERR;
1583 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1584 lnet_nid_t *nids = NULL;
1588 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1591 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1592 (list_empty(&nw_descr->nw_intflist) &&
1593 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1596 "\"missing mandatory parameters in NI config: '%s'\"",
1597 (nw_descr == NULL) ? "network , interface" :
1598 (nw_descr->nw_id == 0) ? "network" : "interface");
1599 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1603 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1606 "\"ip2net string too long %d\"",
1607 (int)strlen(ip2net));
1608 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1612 if (ip2net != NULL) {
1613 if (tunables != NULL)
1614 len = sizeof(struct lnet_ioctl_config_ni) +
1615 sizeof(struct lnet_ioctl_config_lnd_tunables);
1617 len = sizeof(struct lnet_ioctl_config_ni);
1618 data = calloc(1, len);
1620 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1623 conf = (struct lnet_ioctl_config_ni*) data;
1624 if (tunables != NULL)
1625 tun = (struct lnet_ioctl_config_lnd_tunables*)
1626 (data + sizeof(*conf));
1628 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1629 conf->lic_cfg_hdr.ioc_len = len;
1630 strncpy(conf->lic_legacy_ip2nets, ip2net,
1633 if (global_cpts != NULL) {
1634 count = cfs_expr_list_values(global_cpts,
1635 LNET_MAX_SHOW_NUM_CPT,
1638 memcpy(conf->lic_cpts, cpt_array,
1639 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1648 conf->lic_ncpts = count;
1650 if (tunables != NULL)
1651 memcpy(tun, tunables, sizeof(*tunables));
1653 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1658 "\"cannot add network: %s\"", strerror(errno));
1665 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1666 rc = LUSTRE_CFG_RC_NO_ERR;
1670 if (nw_descr->nw_id == LNET_NET_ANY) {
1673 "\"cannot parse net '%s'\"",
1674 libcfs_net2str(nw_descr->nw_id));
1675 rc = LUSTRE_CFG_RC_BAD_PARAM;
1680 * special case the GNI since no interface name is expected
1682 if (list_empty(&nw_descr->nw_intflist) &&
1683 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1686 "\"no interface name provided\"");
1687 rc = LUSTRE_CFG_RC_BAD_PARAM;
1691 if (LNET_NETTYP(nw_descr->nw_id) == SOCKLND && (cpp > -1))
1692 tunables->lt_tun.lnd_tun_u.lnd_sock.lnd_conns_per_peer = cpp;
1693 else if (LNET_NETTYP(nw_descr->nw_id) == O2IBLND && (cpp > -1))
1694 tunables->lt_tun.lnd_tun_u.lnd_o2ib.lnd_conns_per_peer = cpp;
1696 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1697 err_str, sizeof(err_str));
1699 rc = LUSTRE_CFG_RC_BAD_PARAM;
1703 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1704 tunables, global_cpts, nids,
1708 if (nw_descr != NULL) {
1709 list_for_each_entry_safe(intf_descr, tmp,
1710 &nw_descr->nw_intflist,
1712 list_del(&intf_descr->intf_on_network);
1713 free_intf_descr(intf_descr);
1717 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1728 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1729 int seq_no, struct cYAML **err_rc)
1731 struct lnet_ioctl_config_ni data;
1732 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1733 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1734 lnet_nid_t *nids = NULL;
1736 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1738 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1741 "\"missing mandatory parameter in deleting NI: '%s'\"",
1742 (nw_descr == NULL) ? "network , interface" :
1743 (nw_descr->nw_id == 0) ? "network" : "interface");
1744 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1748 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1749 return LUSTRE_CFG_RC_NO_ERR;
1751 if (nw_descr->nw_id == LNET_NET_ANY) {
1754 "\"cannot parse net '%s'\"",
1755 libcfs_net2str(nw_descr->nw_id));
1756 rc = LUSTRE_CFG_RC_BAD_PARAM;
1760 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1761 err_str, sizeof(err_str));
1763 rc = LUSTRE_CFG_RC_BAD_PARAM;
1768 * no interfaces just the nw_id is specified
1771 nids = calloc(1, sizeof(*nids));
1773 snprintf(err_str, sizeof(err_str),
1774 "\"out of memory\"");
1775 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1778 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1782 for (i = 0; i < nnids; i++) {
1783 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1784 data.lic_nid = nids[i];
1786 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1791 "\"cannot del network: %s\"", strerror(errno));
1795 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1797 list_del(&intf_descr->intf_on_network);
1798 free_intf_descr(intf_descr);
1802 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1811 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1812 enum lnet_health_type type, char *name,
1813 int seq_no, struct cYAML **err_rc)
1815 struct lnet_ioctl_reset_health_cfg data;
1816 int rc = LUSTRE_CFG_RC_NO_ERR;
1817 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1819 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1820 data.rh_type = type;
1822 data.rh_value = value;
1825 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1829 sizeof(err_str), "Can not configure health value: %s",
1833 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1840 lustre_lnet_config_conns_per_peer(int value, bool all, lnet_nid_t nid,
1841 char *name, int seq_no,
1842 struct cYAML **err_rc)
1844 struct lnet_ioctl_reset_conns_per_peer_cfg data;
1845 int rc = LUSTRE_CFG_RC_NO_ERR;
1846 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
1848 LIBCFS_IOC_INIT_V2(data, rcpp_hdr);
1849 data.rcpp_all = all;
1850 data.rcpp_value = value;
1851 data.rcpp_nid = nid;
1853 if (value < 0 || value > 127) {
1854 rc = LUSTRE_CFG_RC_BAD_PARAM;
1855 snprintf(err_str, sizeof(err_str),
1856 "\"Valid values are: 0-127\"");
1859 rc = l_ioctl(LNET_DEV_ID,
1860 IOC_LIBCFS_SET_CONNS_PER_PEER, &data);
1865 "Can not configure conns_per_peer value: %s",
1869 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1874 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1875 struct cYAML **err_rc)
1879 nid = libcfs_str2nid(ni_nid);
1882 return lustre_lnet_config_healthv(value, all, nid,
1883 LNET_HEALTH_TYPE_LOCAL_NI,
1884 "ni healthv", seq_no, err_rc);
1887 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1888 int seq_no, struct cYAML **err_rc)
1892 nid = libcfs_str2nid(lpni_nid);
1895 return lustre_lnet_config_healthv(value, all, nid,
1896 LNET_HEALTH_TYPE_PEER_NI,
1897 "peer_ni healthv", seq_no, err_rc);
1900 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
1901 int seq_no, struct cYAML **err_rc)
1906 nid = libcfs_str2nid(ni_nid);
1909 return lustre_lnet_config_conns_per_peer(value, all, nid,
1910 "ni conns_per_peer",
1915 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1916 struct lnet_ioctl_comm_count *counts)
1918 if (cYAML_create_number(yaml, "put",
1919 counts->ico_put_count)
1922 if (cYAML_create_number(yaml, "get",
1923 counts->ico_get_count)
1926 if (cYAML_create_number(yaml, "reply",
1927 counts->ico_reply_count)
1930 if (cYAML_create_number(yaml, "ack",
1931 counts->ico_ack_count)
1934 if (cYAML_create_number(yaml, "hello",
1935 counts->ico_hello_count)
1942 static struct lnet_ioctl_comm_count *
1943 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1946 return &msg_stats->im_send_stats;
1948 return &msg_stats->im_recv_stats;
1950 return &msg_stats->im_drop_stats;
1956 create_local_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
1957 struct cYAML *net_node)
1959 char tmp[LNET_MAX_STR_LEN];
1960 struct cYAML *udsp_net;
1961 bool created = false;
1965 /* add the UDSP info */
1966 udsp_net = cYAML_create_object(net_node, "udsp info");
1968 return LUSTRE_CFG_RC_OUT_OF_MEM;
1970 if (!cYAML_create_number(udsp_net, "net priority",
1971 (int) udsp_info->cud_net_priority))
1972 return LUSTRE_CFG_RC_OUT_OF_MEM;
1974 if (!cYAML_create_number(udsp_net, "nid priority",
1975 (int)udsp_info->cud_nid_priority))
1976 return LUSTRE_CFG_RC_OUT_OF_MEM;
1980 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
1981 memset(tmp, 0, LNET_MAX_STR_LEN);
1982 if (udsp_info->cud_pref_rtr_nid[i] == 0)
1985 pref = cYAML_create_object(udsp_net,
1986 "Preferred gateway NIDs");
1988 return LUSTRE_CFG_RC_OUT_OF_MEM;
1991 snprintf(tmp, sizeof(tmp), "NID-%d", i);
1992 if (!cYAML_create_string(pref, tmp,
1993 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
1994 return LUSTRE_CFG_RC_OUT_OF_MEM;
1997 return LUSTRE_CFG_RC_NO_ERR;
2001 create_remote_udsp_info(struct lnet_ioctl_construct_udsp_info *udsp_info,
2002 struct cYAML *nid_node)
2004 char tmp[LNET_MAX_STR_LEN];
2005 struct cYAML *udsp_nid;
2006 bool created = false;
2010 /* add the UDSP info */
2011 udsp_nid = cYAML_create_object(nid_node, "udsp info");
2013 return LUSTRE_CFG_RC_OUT_OF_MEM;
2015 if (!cYAML_create_number(udsp_nid, "net priority",
2016 (int) udsp_info->cud_net_priority))
2017 return LUSTRE_CFG_RC_OUT_OF_MEM;
2019 if (!cYAML_create_number(udsp_nid, "nid priority",
2020 (int) udsp_info->cud_nid_priority))
2021 return LUSTRE_CFG_RC_OUT_OF_MEM;
2024 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2025 memset(tmp, 0, LNET_MAX_STR_LEN);
2026 if (udsp_info->cud_pref_rtr_nid[i] == 0)
2029 pref = cYAML_create_object(udsp_nid,
2030 "Preferred gateway NIDs");
2032 return LUSTRE_CFG_RC_OUT_OF_MEM;
2035 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2036 if (!cYAML_create_string(pref, tmp,
2037 libcfs_nid2str(udsp_info->cud_pref_rtr_nid[i])))
2038 return LUSTRE_CFG_RC_OUT_OF_MEM;
2043 for (i = 0; i < LNET_MAX_SHOW_NUM_NID; i++) {
2044 memset(tmp, 0, LNET_MAX_STR_LEN);
2045 if (udsp_info->cud_pref_nid[i] == 0)
2048 pref = cYAML_create_object(udsp_nid,
2049 "Preferred source NIDs");
2051 return LUSTRE_CFG_RC_OUT_OF_MEM;
2054 snprintf(tmp, sizeof(tmp), "NID-%d", i);
2055 if (!cYAML_create_string(pref, tmp,
2056 libcfs_nid2str(udsp_info->cud_pref_nid[i])))
2057 return LUSTRE_CFG_RC_OUT_OF_MEM;
2060 return LUSTRE_CFG_RC_NO_ERR;
2063 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
2064 struct cYAML **show_rc, struct cYAML **err_rc,
2068 struct lnet_ioctl_config_ni *ni_data;
2069 struct lnet_ioctl_config_lnd_tunables *lnd;
2070 struct lnet_ioctl_element_stats *stats;
2071 struct lnet_ioctl_element_msg_stats msg_stats;
2072 struct lnet_ioctl_local_ni_hstats hstats;
2073 struct lnet_ioctl_construct_udsp_info udsp_info;
2074 __u32 net = LNET_NET_ANY;
2075 __u32 prev_net = LNET_NET_ANY;
2076 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
2078 struct cYAML *root = NULL, *tunables = NULL,
2079 *net_node = NULL, *interfaces = NULL,
2080 *item = NULL, *first_seq = NULL,
2081 *tmp = NULL, *statistics = NULL,
2083 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
2084 char str_buf[str_buf_len];
2086 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2087 bool exist = false, new_net = true;
2089 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
2091 buf = calloc(1, buf_size);
2095 ni_data = (struct lnet_ioctl_config_ni *)buf;
2098 net = libcfs_str2net(nw);
2099 if (net == LNET_NET_ANY) {
2102 "\"cannot parse net '%s'\"", nw);
2103 rc = LUSTRE_CFG_RC_BAD_PARAM;
2108 root = cYAML_create_object(NULL, NULL);
2112 net_node = cYAML_create_seq(root, "net");
2113 if (net_node == NULL)
2119 memset(buf, 0, buf_size);
2121 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2123 * set the ioc_len to the proper value since INIT assumes
2126 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2127 ni_data->lic_idx = i;
2129 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2135 rc_net = LNET_NIDNET(ni_data->lic_nid);
2137 /* filter on provided data */
2138 if (net != LNET_NET_ANY &&
2142 /* if we're backing up don't store lo */
2143 if (backup && LNET_NETTYP(rc_net) == LOLND)
2146 /* default rc to -1 in case we hit the goto */
2150 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2151 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2152 (ni_data->lic_bulk + sizeof(*stats));
2154 if (rc_net != prev_net) {
2161 if (!cYAML_create_string(net_node, "net type",
2162 libcfs_net2str(rc_net)))
2165 tmp = cYAML_create_seq(net_node, "local NI(s)");
2171 /* create the tree to be printed. */
2172 item = cYAML_create_seq_item(tmp);
2176 if (first_seq == NULL)
2180 cYAML_create_string(item, "nid",
2181 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2185 cYAML_create_string(item,
2187 (ni_data->lic_status ==
2188 LNET_NI_STATUS_UP) ?
2189 "up" : "down") == NULL)
2192 /* don't add interfaces unless there is at least one
2194 if (strlen(ni_data->lic_ni_intf) > 0) {
2195 interfaces = cYAML_create_object(item, "interfaces");
2196 if (interfaces == NULL)
2199 snprintf(str_buf, sizeof(str_buf), "%d", 0);
2200 if (cYAML_create_string(interfaces, str_buf,
2201 ni_data->lic_ni_intf) == NULL)
2210 goto continue_without_msg_stats;
2212 statistics = cYAML_create_object(item, "statistics");
2213 if (statistics == NULL)
2216 if (cYAML_create_number(statistics, "send_count",
2217 stats->iel_send_count)
2221 if (cYAML_create_number(statistics, "recv_count",
2222 stats->iel_recv_count)
2226 if (cYAML_create_number(statistics, "drop_count",
2227 stats->iel_drop_count)
2232 goto continue_without_udsp_info;
2234 LIBCFS_IOC_INIT_V2(udsp_info, cud_hdr);
2235 udsp_info.cud_nid = ni_data->lic_nid;
2236 udsp_info.cud_peer = false;
2237 rc = l_ioctl(LNET_DEV_ID,
2238 IOC_LIBCFS_GET_CONST_UDSP_INFO,
2242 goto continue_without_udsp_info;
2245 rc = create_local_udsp_info(&udsp_info, item);
2251 continue_without_udsp_info:
2253 goto continue_without_msg_stats;
2255 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2256 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2257 msg_stats.im_idx = i;
2259 rc = l_ioctl(LNET_DEV_ID,
2260 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2264 goto continue_without_msg_stats;
2267 for (k = 0; k < 3; k++) {
2268 struct lnet_ioctl_comm_count *counts;
2269 struct cYAML *msg_statistics = NULL;
2271 msg_statistics = cYAML_create_object(item,
2272 (char *)gmsg_stat_names[k]);
2273 if (msg_statistics == NULL)
2276 counts = get_counts(&msg_stats, k);
2280 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2285 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2286 hstats.hlni_nid = ni_data->lic_nid;
2287 /* grab health stats */
2288 rc = l_ioctl(LNET_DEV_ID,
2289 IOC_LIBCFS_GET_LOCAL_HSTATS,
2293 goto continue_without_msg_stats;
2295 yhstats = cYAML_create_object(item, "health stats");
2298 if (cYAML_create_number(yhstats, "fatal_error",
2299 hstats.hlni_fatal_error)
2302 if (cYAML_create_number(yhstats, "health value",
2303 hstats.hlni_health_value)
2306 if (cYAML_create_number(yhstats, "interrupts",
2307 hstats.hlni_local_interrupt)
2310 if (cYAML_create_number(yhstats, "dropped",
2311 hstats.hlni_local_dropped)
2314 if (cYAML_create_number(yhstats, "aborted",
2315 hstats.hlni_local_aborted)
2318 if (cYAML_create_number(yhstats, "no route",
2319 hstats.hlni_local_no_route)
2322 if (cYAML_create_number(yhstats, "timeouts",
2323 hstats.hlni_local_timeout)
2326 if (cYAML_create_number(yhstats, "error",
2327 hstats.hlni_local_error)
2330 if (cYAML_create_number(yhstats, "ping_count",
2331 hstats.hlni_ping_count)
2334 if (cYAML_create_number(yhstats, "next_ping",
2335 hstats.hlni_next_ping)
2339 continue_without_msg_stats:
2340 tunables = cYAML_create_object(item, "tunables");
2344 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2345 if (rc != LUSTRE_CFG_RC_NO_ERR)
2348 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2349 tunables = cYAML_create_object(item,
2351 if (tunables == NULL)
2355 rc = lustre_ni_show_tunables(tunables,
2356 LNET_NETTYP(rc_net),
2358 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2359 rc != LUSTRE_CFG_RC_NO_MATCH)
2363 cYAML_create_number(item, "dev cpt",
2364 ni_data->lic_dev_cpt) == NULL)
2367 /* out put the CPTs in the format: "[x,x,x,...]" */
2369 limit = str_buf + str_buf_len - 3;
2370 pos += scnprintf(pos, limit - pos, "\"[");
2371 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2372 j < ni_data->lic_ncpts &&
2374 pos += scnprintf(pos, limit - pos,
2375 "%d", ni_data->lic_cpts[j]);
2376 if ((j + 1) < ni_data->lic_ncpts)
2377 pos += scnprintf(pos, limit - pos, ",");
2379 snprintf(pos, 3, "]\"");
2381 if (ni_data->lic_ncpts >= 1 &&
2382 cYAML_create_string(item, "CPT",
2388 /* Print out the net information only if show_rc is not provided */
2389 if (show_rc == NULL)
2390 cYAML_print_tree(root);
2392 if (l_errno != ENOENT) {
2395 "\"cannot get networks: %s\"",
2400 rc = LUSTRE_CFG_RC_NO_ERR;
2402 snprintf(err_str, sizeof(err_str), "\"success\"");
2404 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2405 cYAML_free_tree(root);
2406 } else if (show_rc != NULL && *show_rc != NULL) {
2407 struct cYAML *show_node;
2408 /* find the net node, if one doesn't exist
2409 * then insert one. Otherwise add to the one there
2411 show_node = cYAML_get_object_item(*show_rc, "net");
2412 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2413 cYAML_insert_child(show_node, first_seq);
2416 } else if (show_node == NULL) {
2417 cYAML_insert_sibling((*show_rc)->cy_child,
2421 cYAML_free_tree(root);
2427 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2432 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2434 struct lnet_ioctl_config_data data;
2435 int rc = LUSTRE_CFG_RC_NO_ERR;
2436 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2438 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2439 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2441 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2446 "\"cannot %s routing %s\"",
2447 (enable) ? "enable" : "disable", strerror(errno));
2452 cYAML_build_error(rc, seq_no,
2453 (enable) ? ADD_CMD : DEL_CMD,
2454 "routing", err_str, err_rc);
2459 int ioctl_set_value(__u32 val, int ioc, char *name,
2460 int seq_no, struct cYAML **err_rc)
2462 struct lnet_ioctl_set_value data;
2463 int rc = LUSTRE_CFG_RC_NO_ERR;
2464 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2466 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2467 data.sv_value = val;
2469 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2474 "\"cannot configure %s to %d: %s\"", name,
2475 val, strerror(errno));
2478 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2483 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2485 int rc = LUSTRE_CFG_RC_NO_ERR;
2486 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2487 char val[LNET_MAX_STR_LEN];
2489 snprintf(val, sizeof(val), "%d", intrv);
2491 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2492 1, strlen(val) + 1);
2494 snprintf(err_str, sizeof(err_str),
2495 "\"cannot configure recovery interval: %s\"",
2498 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2503 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2505 int rc = LUSTRE_CFG_RC_NO_ERR;
2506 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2507 char val[LNET_MAX_STR_LEN];
2509 snprintf(val, sizeof(val), "%d", sen);
2511 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2512 1, strlen(val) + 1);
2514 snprintf(err_str, sizeof(err_str),
2515 "\"cannot configure router health sensitivity: %s\"",
2518 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2523 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2525 int rc = LUSTRE_CFG_RC_NO_ERR;
2526 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2527 char val[LNET_MAX_STR_LEN];
2529 snprintf(val, sizeof(val), "%d", sen);
2531 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2532 1, strlen(val) + 1);
2534 snprintf(err_str, sizeof(err_str),
2535 "\"cannot configure health sensitivity: %s\"",
2538 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2543 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2545 int rc = LUSTRE_CFG_RC_NO_ERR;
2546 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2547 char val[LNET_MAX_STR_LEN];
2549 snprintf(val, sizeof(val), "%d", timeout);
2551 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2552 1, strlen(val) + 1);
2554 snprintf(err_str, sizeof(err_str),
2555 "\"cannot configure transaction timeout: %s\"",
2558 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2563 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2565 int rc = LUSTRE_CFG_RC_NO_ERR;
2566 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2567 char val[LNET_MAX_STR_LEN];
2569 snprintf(val, sizeof(val), "%d", count);
2571 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2572 1, strlen(val) + 1);
2574 snprintf(err_str, sizeof(err_str),
2575 "\"cannot configure retry count: %s\"",
2578 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2583 int lustre_lnet_config_response_tracking(int val, int seq_no,
2584 struct cYAML **err_rc)
2586 int rc = LUSTRE_CFG_RC_NO_ERR;
2587 char err_str[LNET_MAX_STR_LEN];
2588 char val_str[LNET_MAX_STR_LEN];
2590 if (val < 0 || val > 3) {
2591 rc = LUSTRE_CFG_RC_BAD_PARAM;
2592 snprintf(err_str, sizeof(err_str),
2593 "\"Valid values are: 0, 1, 2, or 3\"");
2595 snprintf(err_str, sizeof(err_str), "\"success\"");
2597 snprintf(val_str, sizeof(val_str), "%d", val);
2599 rc = write_sysfs_file(modparam_path, "lnet_response_tracking",
2600 val_str, 1, strlen(val_str) + 1);
2602 snprintf(err_str, sizeof(err_str),
2603 "\"cannot configure response tracking: %s\"",
2607 cYAML_build_error(rc, seq_no, ADD_CMD, "response_tracking", err_str,
2613 int lustre_lnet_config_recovery_limit(int val, int seq_no,
2614 struct cYAML **err_rc)
2616 int rc = LUSTRE_CFG_RC_NO_ERR;
2617 char err_str[LNET_MAX_STR_LEN];
2618 char val_str[LNET_MAX_STR_LEN];
2621 rc = LUSTRE_CFG_RC_BAD_PARAM;
2622 snprintf(err_str, sizeof(err_str),
2623 "\"Must be greater than or equal to 0\"");
2625 snprintf(err_str, sizeof(err_str), "\"success\"");
2627 snprintf(val_str, sizeof(val_str), "%d", val);
2629 rc = write_sysfs_file(modparam_path, "lnet_recovery_limit",
2630 val_str, 1, strlen(val_str) + 1);
2632 snprintf(err_str, sizeof(err_str),
2633 "\"cannot configure recovery limit: %s\"",
2637 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_limit", err_str,
2643 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2645 int rc = LUSTRE_CFG_RC_NO_ERR;
2646 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2647 char val[LNET_MAX_STR_LEN];
2649 snprintf(val, sizeof(val), "%d", max);
2651 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2652 1, strlen(val) + 1);
2654 snprintf(err_str, sizeof(err_str),
2655 "\"cannot configure max interfaces: %s\"",
2658 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2663 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2665 int rc = LUSTRE_CFG_RC_NO_ERR;
2666 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2667 char val[LNET_MAX_STR_LEN];
2669 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2671 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2672 1, strlen(val) + 1);
2674 snprintf(err_str, sizeof(err_str),
2675 "\"cannot configure discovery: %s\"",
2678 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2684 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2685 struct cYAML **err_rc)
2687 int rc = LUSTRE_CFG_RC_NO_ERR;
2688 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2689 char val[LNET_MAX_STR_LEN];
2691 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2693 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2694 1, strlen(val) + 1);
2696 snprintf(err_str, sizeof(err_str),
2697 "\"cannot configure drop asym route: %s\"",
2700 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2707 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2709 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2710 "numa_range", seq_no, err_rc);
2713 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2714 struct cYAML **err_rc)
2716 struct lnet_ioctl_config_data data;
2717 int rc = LUSTRE_CFG_RC_NO_ERR;
2718 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2720 /* -1 indicates to ignore changes to this field */
2721 if (tiny < -1 || small < -1 || large < -1) {
2724 "\"tiny, small and large must be >= 0\"");
2725 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2729 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2730 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2731 data.cfg_config_u.cfg_buffers.buf_small = small;
2732 data.cfg_config_u.cfg_buffers.buf_large = large;
2734 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2739 "\"cannot configure buffers: %s\"", strerror(errno));
2744 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2749 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
2750 struct cYAML **err_rc)
2752 int rc = LUSTRE_CFG_RC_NO_ERR;
2753 char err_str[LNET_MAX_STR_LEN] = "\"success\"";
2754 char interval_str[LNET_MAX_STR_LEN];
2756 if (interval <= 0) {
2757 rc = LUSTRE_CFG_RC_BAD_PARAM;
2758 snprintf(err_str, sizeof(err_str),
2759 "\"must be strictly positive\"");
2762 snprintf(interval_str, sizeof(interval_str), "%d", interval);
2764 rc = write_sysfs_file(modparam_path,
2765 "lnet_max_recovery_ping_interval",
2767 strlen(interval_str) + 1);
2769 snprintf(err_str, sizeof(err_str),
2770 "\"cannot configure maximum recovery ping interval: %s\"",
2774 cYAML_build_error(rc, seq_no, ADD_CMD, "maximum recovery ping interval",
2781 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2782 struct cYAML **err_rc, bool backup)
2784 struct lnet_ioctl_config_data *data;
2785 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2786 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2789 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2790 int buf_count[LNET_NRBPOOLS] = {0};
2791 struct cYAML *root = NULL, *pools_node = NULL,
2792 *type_node = NULL, *item = NULL, *cpt = NULL,
2793 *first_seq = NULL, *buffers = NULL;
2795 char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
2796 char node_name[LNET_MAX_STR_LEN];
2799 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2803 data = (struct lnet_ioctl_config_data *)buf;
2805 root = cYAML_create_object(NULL, NULL);
2810 pools_node = cYAML_create_object(root, "routing");
2812 pools_node = cYAML_create_seq(root, "routing");
2813 if (pools_node == NULL)
2817 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2818 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2819 sizeof(struct lnet_ioctl_pool_cfg);
2820 data->cfg_count = i;
2822 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2830 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2833 goto calculate_buffers;
2835 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2836 item = cYAML_create_seq_item(pools_node);
2840 if (first_seq == NULL)
2843 cpt = cYAML_create_object(item, node_name);
2848 /* create the tree and print */
2849 for (j = 0; j < LNET_NRBPOOLS; j++) {
2851 type_node = cYAML_create_object(cpt, pools[j]);
2852 if (type_node == NULL)
2856 cYAML_create_number(type_node, "npages",
2857 pool_cfg->pl_pools[j].pl_npages)
2861 cYAML_create_number(type_node, "nbuffers",
2862 pool_cfg->pl_pools[j].
2863 pl_nbuffers) == NULL)
2866 cYAML_create_number(type_node, "credits",
2867 pool_cfg->pl_pools[j].
2868 pl_credits) == NULL)
2871 cYAML_create_number(type_node, "mincredits",
2872 pool_cfg->pl_pools[j].
2873 pl_mincredits) == NULL)
2875 /* keep track of the total count for each of the
2876 * tiny, small and large buffers */
2877 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2881 if (pool_cfg != NULL) {
2883 if (cYAML_create_number(pools_node, "enable",
2884 pool_cfg->pl_routing) ==
2888 goto add_buffer_section;
2891 item = cYAML_create_seq_item(pools_node);
2895 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2901 /* create a buffers entry in the show. This is necessary so that
2902 * if the YAML output is used to configure a node, the buffer
2903 * configuration takes hold */
2904 buffers = cYAML_create_object(root, "buffers");
2905 if (buffers == NULL)
2908 for (i = 0; i < LNET_NRBPOOLS; i++) {
2909 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2913 if (show_rc == NULL)
2914 cYAML_print_tree(root);
2916 if (l_errno != ENOENT) {
2919 "\"cannot get routing information: %s\"",
2924 rc = LUSTRE_CFG_RC_NO_ERR;
2926 snprintf(err_str, sizeof(err_str), "\"success\"");
2927 rc = LUSTRE_CFG_RC_NO_ERR;
2931 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2932 cYAML_free_tree(root);
2933 } else if (show_rc != NULL && *show_rc != NULL) {
2934 struct cYAML *routing_node;
2935 /* there should exist only one routing block and one
2936 * buffers block. If there already exists a previous one
2937 * then don't add another */
2938 routing_node = cYAML_get_object_item(*show_rc, "routing");
2939 if (routing_node == NULL) {
2940 cYAML_insert_sibling((*show_rc)->cy_child,
2944 cYAML_free_tree(root);
2950 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2955 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2956 struct cYAML **show_rc, struct cYAML **err_rc,
2960 * TODO: This function is changing in a future patch to accommodate
2961 * PEER_LIST and proper filtering on any nid of the peer
2963 struct lnet_ioctl_peer_cfg peer_info;
2964 struct lnet_peer_ni_credit_info *lpni_cri;
2965 struct lnet_ioctl_element_stats *lpni_stats;
2966 struct lnet_ioctl_element_msg_stats *msg_stats;
2967 struct lnet_ioctl_peer_ni_hstats *hstats;
2968 struct lnet_ioctl_construct_udsp_info udsp_info;