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 "liblnetconfig.h"
55 #define CONFIG_CMD "configure"
56 #define UNCONFIG_CMD "unconfigure"
59 #define SHOW_CMD "show"
61 #define MANAGE_CMD "manage"
63 #define MAX_NUM_IPS 128
65 #define modparam_path "/sys/module/lnet/parameters/"
66 #define gni_nid_path "/proc/cray_xt/"
68 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
72 * lustre_lnet_ip_range_descr
73 * Describes an IP range.
74 * Each octect is an expression
76 struct lustre_lnet_ip_range_descr {
77 struct list_head ipr_entry;
78 struct list_head ipr_expr;
83 * Describes an ip2nets rule. This can be on a list of rules.
85 struct lustre_lnet_ip2nets {
86 struct lnet_dlc_network_descr ip2nets_net;
87 struct list_head ip2nets_ip_ranges;
90 int open_sysfs_file(const char *path, const char *attr, const int mode)
93 char filename[LNET_MAX_STR_LEN];
95 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
98 snprintf(filename, sizeof(filename), "%s%s",
101 fd = open(filename, mode);
106 static int read_sysfs_file(const char *path, const char *attr,
107 void *val, const size_t size, const int nelem)
110 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
112 fd = open_sysfs_file(path, attr, O_RDONLY);
114 return LUSTRE_CFG_RC_NO_MATCH;
116 if (read(fd, val, size * nelem) == -1)
119 rc = LUSTRE_CFG_RC_NO_ERR;
126 static int write_sysfs_file(const char *path, const char *attr,
127 void *val, const size_t size, const int nelem)
130 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
132 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
134 return LUSTRE_CFG_RC_NO_MATCH;
136 if (write(fd, val, size * nelem) == -1)
139 rc = LUSTRE_CFG_RC_NO_ERR;
148 * frees the memory allocated for an intf descriptor.
150 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
155 if (intf_descr->cpt_expr != NULL)
156 cfs_expr_list_free(intf_descr->cpt_expr);
161 * lustre_lnet_add_ip_range
163 * given a string of the format:
164 * <expr.expr.expr.expr> parse each expr into
165 * a lustre_lnet_ip_range_descr structure and insert on the list.
167 * This function is called from
168 * YAML on each ip-range.
169 * As a result of lnetctl command
170 * When building a NID or P2P selection rules
172 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
174 struct lustre_lnet_ip_range_descr *ip_range;
177 ip_range = calloc(1, sizeof(*ip_range));
178 if (ip_range == NULL)
179 return LUSTRE_CFG_RC_OUT_OF_MEM;
181 INIT_LIST_HEAD(&ip_range->ipr_entry);
182 INIT_LIST_HEAD(&ip_range->ipr_expr);
184 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
185 &ip_range->ipr_expr);
187 return LUSTRE_CFG_RC_BAD_PARAM;
189 list_add_tail(&ip_range->ipr_entry, list);
191 return LUSTRE_CFG_RC_NO_ERR;
194 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
196 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
198 struct lnet_dlc_intf_descr *intf_descr = NULL;
200 char intf_string[LNET_MAX_STR_LEN];
202 if (len >= LNET_MAX_STR_LEN)
203 return LUSTRE_CFG_RC_BAD_PARAM;
205 strncpy(intf_string, intf, len);
206 intf_string[len] = '\0';
208 intf_descr = calloc(1, sizeof(*intf_descr));
209 if (intf_descr == NULL)
210 return LUSTRE_CFG_RC_OUT_OF_MEM;
212 INIT_LIST_HEAD(&intf_descr->intf_on_network);
214 intf_name = intf_string;
215 open_sq_bracket = strchr(intf_string, '[');
216 if (open_sq_bracket != NULL) {
217 close_sq_bracket = strchr(intf_string, ']');
218 if (close_sq_bracket == NULL) {
220 return LUSTRE_CFG_RC_BAD_PARAM;
222 rc = cfs_expr_list_parse(open_sq_bracket,
223 strlen(open_sq_bracket), 0, UINT_MAX,
224 &intf_descr->cpt_expr);
227 return LUSTRE_CFG_RC_BAD_PARAM;
229 strncpy(intf_descr->intf_name, intf_name,
230 open_sq_bracket - intf_name);
231 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
233 strcpy(intf_descr->intf_name, intf_name);
234 intf_descr->cpt_expr = NULL;
237 list_add_tail(&intf_descr->intf_on_network, list);
239 return LUSTRE_CFG_RC_NO_ERR;
242 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
244 if (nw_descr != NULL) {
246 INIT_LIST_HEAD(&nw_descr->network_on_rule);
247 INIT_LIST_HEAD(&nw_descr->nw_intflist);
251 int tokenize_nidstr(char *nidstr, char *out[LNET_MAX_STR_LEN], char *err_str)
253 int bracket = 0, num_str = 0;
254 char *strstart, *chptr;
257 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
258 return LUSTRE_CFG_RC_BAD_PARAM;
261 /* comma-separated nidranges -> space-separated nidranges */
265 if (*chptr == '\0') {
266 out[num_str] = strstart;
273 else if (*chptr == ']')
277 snprintf(err_str, LNET_MAX_STR_LEN,
278 "Mismatched brackets in nidstring \"%s\"",
280 return LUSTRE_CFG_RC_BAD_PARAM;
283 if (bracket == 0 && *chptr == ',') {
284 out[num_str] = strstart;
287 strstart = chptr + 1;
294 snprintf(err_str, LNET_MAX_STR_LEN,
295 "Mismatched brackets in nidstring \"%s\"", nidstr);
296 return LUSTRE_CFG_RC_BAD_PARAM;
302 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
303 int max_nids, char *err_str)
305 int rc, num_nids = 0;
306 struct list_head nidlist;
309 snprintf(err_str, LNET_MAX_STR_LEN, "supplied nidstr is NULL");
310 return LUSTRE_CFG_RC_BAD_PARAM;
313 if (strchr(nidstr, '*')) {
314 snprintf(err_str, LNET_MAX_STR_LEN,
315 "asterisk not allowed in nidstring \"%s\"", nidstr);
316 return LUSTRE_CFG_RC_BAD_PARAM;
319 INIT_LIST_HEAD(&nidlist);
320 rc = cfs_parse_nidlist(nidstr, strlen(nidstr), &nidlist);
322 snprintf(err_str, LNET_MAX_STR_LEN,
323 "Unable to parse nidlist from: %s\n", nidstr);
324 return LUSTRE_CFG_RC_BAD_PARAM;
327 if (list_empty(&nidlist)) {
328 snprintf(err_str, LNET_MAX_STR_LEN,
329 "\"%s\" does not specify any valid nid lists", nidstr);
330 return LUSTRE_CFG_RC_BAD_PARAM;
333 num_nids = cfs_expand_nidlist(&nidlist, lnet_nidlist, max_nids);
335 if (num_nids == -1) {
336 snprintf(err_str, LNET_MAX_STR_LEN,
337 "\"%s\" specifies more than the %d NIDs allowed by this operation.",
339 return LUSTRE_CFG_RC_BAD_PARAM;
343 snprintf(err_str, LNET_MAX_STR_LEN,
344 "Failed to expand nidstr: %s", strerror(num_nids));
345 return LUSTRE_CFG_RC_OUT_OF_MEM;
349 snprintf(err_str, LNET_MAX_STR_LEN,
350 "\"%s\" did not expand to any nids", nidstr);
351 return LUSTRE_CFG_RC_BAD_PARAM;
359 * <intf>[<expr>], <intf>[<expr>],..
361 int lustre_lnet_parse_interfaces(char *intf_str,
362 struct lnet_dlc_network_descr *nw_descr)
367 char *cur = intf_str, *next = NULL;
368 char *end = intf_str + strlen(intf_str);
370 struct lnet_dlc_intf_descr *intf_descr, *tmp;
372 if (nw_descr == NULL)
373 return LUSTRE_CFG_RC_BAD_PARAM;
376 open_square = strchr(cur, '[');
377 if (open_square != NULL) {
378 close_square = strchr(cur, ']');
379 if (close_square == NULL) {
380 rc = LUSTRE_CFG_RC_BAD_PARAM;
384 comma = strchr(cur, ',');
385 if (comma != NULL && comma > close_square) {
387 len = next - close_square;
393 comma = strchr(cur, ',');
403 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
404 if (rc != LUSTRE_CFG_RC_NO_ERR)
410 return LUSTRE_CFG_RC_NO_ERR;
413 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
415 list_del(&intf_descr->intf_on_network);
416 free_intf_descr(intf_descr);
422 int lustre_lnet_config_lib_init(void)
424 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
427 void lustre_lnet_config_lib_uninit(void)
429 unregister_ioc_dev(LNET_DEV_ID);
432 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
433 int seq_no, struct cYAML **err_rc)
435 struct libcfs_ioctl_data data;
438 char err_str[LNET_MAX_STR_LEN];
440 snprintf(err_str, sizeof(err_str), "\"Success\"");
442 LIBCFS_IOC_INIT(data);
444 /* Reverse logic is used here in order not to change
445 * the lctl utility */
446 data.ioc_flags = load_ni_from_mod ? 0 : 1;
448 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
450 rc = l_ioctl(LNET_DEV_ID, opc, &data);
454 "\"LNet %s error: %s\"", (up) ? "configure" :
455 "unconfigure", strerror(errno));
459 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
460 "lnet", err_str, err_rc);
465 static int dispatch_peer_ni_cmd(__u32 cmd, struct lnet_ioctl_peer_cfg *data,
466 char *err_str, char *cmd_str)
470 rc = l_ioctl(LNET_DEV_ID, cmd, data);
473 snprintf(err_str, LNET_MAX_STR_LEN,
474 "\"%s peer ni operation failed: %s\"",
475 cmd_str, strerror(errno));
481 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
482 int seq_no, struct cYAML **show_rc,
483 struct cYAML **err_rc)
486 struct lnet_ioctl_ping_data ping;
487 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
488 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
489 struct lnet_process_id id;
490 char err_str[LNET_MAX_STR_LEN] = {0};
491 char *sep, *token, *end;
494 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
498 len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
500 data = calloc(1, len);
504 /* create struct cYAML root object */
505 root = cYAML_create_object(NULL, NULL);
509 ping_node = cYAML_create_seq(root, oper);
510 if (ping_node == NULL)
513 /* tokenise each nid in string ping_nids */
514 token = strtok(ping_nids, ",");
517 item = cYAML_create_seq_item(ping_node);
521 if (first_seq == NULL)
524 /* check if '-' is a part of NID, token */
525 sep = strchr(token, '-');
527 id.pid = LNET_PID_ANY;
528 /* if no net is specified, libcfs_str2nid() will assume tcp */
529 id.nid = libcfs_str2nid(token);
530 if (id.nid == LNET_NID_ANY) {
531 snprintf(err_str, sizeof(err_str),
532 "\"cannot parse NID '%s'\"",
534 rc = LUSTRE_CFG_RC_BAD_PARAM;
535 cYAML_build_error(rc, seq_no, MANAGE_CMD,
536 oper, err_str, err_rc);
540 if (token[0] == 'u' || token[0] == 'U')
541 id.pid = (strtoul(&token[1], &end, 0) |
542 (LNET_PID_USERFLAG));
544 id.pid = strtoul(token, &end, 0);
546 /* assuming '-' is part of hostname */
548 id.pid = LNET_PID_ANY;
549 id.nid = libcfs_str2nid(token);
550 if (id.nid == LNET_NID_ANY) {
551 snprintf(err_str, sizeof(err_str),
552 "\"cannot parse NID '%s'\"",
554 rc = LUSTRE_CFG_RC_BAD_PARAM;
555 cYAML_build_error(rc, seq_no, MANAGE_CMD,
561 id.nid = libcfs_str2nid(sep + 1);
562 if (id.nid == LNET_NID_ANY) {
563 snprintf(err_str, sizeof(err_str),
564 "\"cannot parse NID '%s'\"",
566 rc = LUSTRE_CFG_RC_BAD_PARAM;
567 cYAML_build_error(rc, seq_no, MANAGE_CMD,
574 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
575 ping.ping_hdr.ioc_len = sizeof(ping);
577 ping.op_param = param;
578 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
579 ping.ping_buf = data;
581 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
584 sizeof(err_str), "failed to %s %s: %s\n", oper,
585 id.pid == LNET_PID_ANY ?
586 libcfs_nid2str(id.nid) :
587 libcfs_id2str(id), strerror(errno));
588 rc = LUSTRE_CFG_RC_BAD_PARAM;
589 cYAML_build_error(rc, seq_no, MANAGE_CMD,
590 oper, err_str, err_rc);
594 if (cYAML_create_string(item, "primary nid",
595 libcfs_nid2str(ping.ping_id.nid)) == NULL)
598 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ?
599 "True" : "False") == NULL)
602 tmp = cYAML_create_seq(item, "peer ni");
606 for (i = 0; i < ping.ping_count; i++) {
607 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
610 peer_ni = cYAML_create_seq_item(tmp);
613 memset(buf, 0, sizeof buf);
614 snprintf(buf, sizeof buf, "nid");
615 if (cYAML_create_string(peer_ni, buf,
616 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
622 } while ((token = strtok(NULL, ",")) != NULL);
625 rc = LUSTRE_CFG_RC_NO_ERR;
630 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
631 cYAML_free_tree(root);
632 } else if (show_rc != NULL && *show_rc != NULL) {
633 struct cYAML *show_node;
634 show_node = cYAML_get_object_item(*show_rc, oper);
635 if (show_node != NULL && cYAML_is_sequence(show_node)) {
636 cYAML_insert_child(show_node, first_seq);
639 } else if (show_node == NULL) {
640 cYAML_insert_sibling((*show_rc)->cy_child,
644 cYAML_free_tree(root);
653 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
654 struct cYAML **show_rc, struct cYAML **err_rc)
658 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
659 seq_no, show_rc, err_rc);
663 int lustre_lnet_discover_nid(char *ping_nids, int force, int seq_no,
664 struct cYAML **show_rc, struct cYAML **err_rc)
668 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
669 seq_no, show_rc, err_rc);
673 static int lustre_lnet_handle_peer_nidlist(lnet_nid_t *nidlist, int num_nids,
674 bool is_mr, __u32 cmd,
675 char *cmd_type, char *err_str)
677 struct lnet_ioctl_peer_cfg data;
680 if (cmd == IOC_LIBCFS_ADD_PEER_NI) {
681 /* When adding a peer we first need to create the peer using the
682 * specified (or implied) primary nid. Then we can add
683 * additional nids to this peer using the primary nid as a key
685 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
686 data.prcfg_mr = is_mr;
687 data.prcfg_prim_nid = nidlist[0];
688 data.prcfg_cfg_nid = LNET_NID_ANY;
690 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
696 /* Add or delete any specified NIs associated with the specified
697 * (or implied) primary nid
699 for (nid_idx = 1; nid_idx < num_nids; nid_idx++) {
700 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
701 data.prcfg_mr = is_mr;
702 data.prcfg_prim_nid = nidlist[0];
703 data.prcfg_cfg_nid = nidlist[nid_idx];
705 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
711 if (cmd == IOC_LIBCFS_DEL_PEER_NI && num_nids == 1) {
712 /* In the delete case we may have been given just the
713 * primary nid of the peer. This tells us to delete the peer
714 * completely (rather than just delete some of its NIs)
716 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
717 data.prcfg_prim_nid = nidlist[0];
718 data.prcfg_cfg_nid = LNET_NID_ANY;
720 rc = dispatch_peer_ni_cmd(cmd, &data, err_str, cmd_type);
726 int lustre_lnet_config_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
727 int num_nids, bool is_mr, int seq_no,
728 struct cYAML **err_rc)
730 int rc = LUSTRE_CFG_RC_NO_ERR;
731 char err_str[LNET_MAX_STR_LEN];
732 lnet_nid_t *lnet_nidlist2 = NULL;
736 pnid = libcfs_str2nid(pnidstr);
737 if (pnid == LNET_NID_ANY) {
738 snprintf(err_str, LNET_MAX_STR_LEN,
739 "bad primary NID: '%s'", pnidstr);
740 rc = LUSTRE_CFG_RC_MISSING_PARAM;
746 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
747 if (!lnet_nidlist2) {
748 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
749 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
752 lnet_nidlist2[0] = pnid;
753 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
757 rc = lustre_lnet_handle_peer_nidlist((pnidstr) ? lnet_nidlist2 :
760 IOC_LIBCFS_ADD_PEER_NI, ADD_CMD,
766 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
770 int lustre_lnet_del_peer_nidlist(char *pnidstr, lnet_nid_t *lnet_nidlist,
771 int num_nids, int seq_no,
772 struct cYAML **err_rc)
774 int rc = LUSTRE_CFG_RC_NO_ERR;
775 char err_str[LNET_MAX_STR_LEN];
776 lnet_nid_t *lnet_nidlist2 = NULL;
780 snprintf(err_str, sizeof(err_str),
781 "\"Primary nid is not provided\"");
782 rc = LUSTRE_CFG_RC_MISSING_PARAM;
786 pnid = libcfs_str2nid(pnidstr);
787 if (pnid == LNET_NID_ANY) {
788 rc = LUSTRE_CFG_RC_BAD_PARAM;
789 snprintf(err_str, sizeof(err_str),
796 lnet_nidlist2 = calloc(sizeof(*lnet_nidlist2), num_nids);
797 if (!lnet_nidlist2) {
798 snprintf(err_str, sizeof(err_str),
800 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
803 lnet_nidlist2[0] = pnid;
804 memcpy(&lnet_nidlist2[1], lnet_nidlist, sizeof(*lnet_nidlist) *
807 rc = lustre_lnet_handle_peer_nidlist(lnet_nidlist2, num_nids, false,
808 IOC_LIBCFS_DEL_PEER_NI, DEL_CMD,
814 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
818 int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio,
819 int sen, int seq_no, struct cYAML **err_rc,
822 int rc, num_nids, num_nidstrs, nid_idx, str_idx;
824 char err_str[LNET_MAX_STR_LEN];
825 char *nidstrarray[LNET_MAX_STR_LEN];
826 struct lnet_ioctl_config_data data;
827 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
829 if (nw == NULL || nidstr == NULL) {
830 snprintf(err_str, LNET_MAX_STR_LEN,
831 "\"missing mandatory parameter:'%s'\"",
832 (nw == NULL && nidstr == NULL) ? "network, gateway" :
833 (nw == NULL) ? "network" : "gateway");
834 rc = LUSTRE_CFG_RC_MISSING_PARAM;
838 rnet = libcfs_str2net(nw);
839 if (rnet == LNET_NIDNET(LNET_NID_ANY)) {
840 snprintf(err_str, LNET_MAX_STR_LEN,
841 "\"cannot parse remote net %s\"", nw);
842 rc = LUSTRE_CFG_RC_BAD_PARAM;
846 rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
852 for (str_idx = 0; str_idx < num_nidstrs; str_idx++) {
853 rc = lustre_lnet_parse_nidstr(nidstrarray[str_idx],
855 LNET_MAX_NIDS_PER_PEER, err_str);
861 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
863 if (cmd == LNETCTL_ADD_CMD) {
864 data.cfg_config_u.cfg_route.rtr_hop = hops;
865 data.cfg_config_u.cfg_route.rtr_priority = prio;
866 data.cfg_config_u.cfg_route.rtr_sensitivity = sen;
869 for (nid_idx = 0; nid_idx < num_nids; nid_idx++) {
870 data.cfg_nid = lnet_nidlist[nid_idx];
872 if (cmd == LNETCTL_ADD_CMD)
873 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE,
876 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE,
879 if (rc != 0 && errno != EEXIST &&
880 errno != EHOSTUNREACH) {
882 snprintf(err_str, LNET_MAX_STR_LEN,
883 "route operation failed: %s",
891 cYAML_build_error(rc, seq_no,
892 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD, "route",
898 int lustre_lnet_config_route(char *nw, char *nidstr, int hops, int prio,
899 int sen, int seq_no, struct cYAML **err_rc)
902 char err_str[LNET_MAX_STR_LEN];
905 hops = LNET_UNDEFINED_HOPS;
906 } else if (hops < 1 || hops > 255) {
907 snprintf(err_str, LNET_MAX_STR_LEN,
908 "\"invalid hop count %d, must be between 1 and 255\"",
910 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
916 } else if (prio < 0) {
917 snprintf(err_str, LNET_MAX_STR_LEN,
918 "\"invalid priority %d, must be greater than 0\"",
920 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
926 } else if (sen < 1) {
927 snprintf(err_str, LNET_MAX_STR_LEN,
928 "\"invalid health sensitivity %d, must be 1 or greater\"",
930 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
934 rc = lustre_lnet_route_common(nw, nidstr, hops, prio, sen, seq_no,
935 err_rc, LNETCTL_ADD_CMD);
937 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
942 int lustre_lnet_del_route(char *nw, char *nidstr, int seq_no,
943 struct cYAML **err_rc)
945 return lustre_lnet_route_common(nw, nidstr, 0, 0, 0, seq_no, err_rc,
949 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
950 int seq_no, struct cYAML **show_rc,
951 struct cYAML **err_rc, bool backup)
953 struct lnet_ioctl_config_data data;
954 lnet_nid_t gateway_nid;
955 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
957 __u32 net = LNET_NIDNET(LNET_NID_ANY);
959 struct cYAML *root = NULL, *route = NULL, *item = NULL;
960 struct cYAML *first_seq = NULL;
961 char err_str[LNET_MAX_STR_LEN];
964 snprintf(err_str, sizeof(err_str),
965 "\"out of memory\"");
968 net = libcfs_str2net(nw);
969 if (net == LNET_NIDNET(LNET_NID_ANY)) {
972 "\"cannot parse net '%s'\"", nw);
973 rc = LUSTRE_CFG_RC_BAD_PARAM;
978 /* show all routes without filtering on net */
979 net = LNET_NIDNET(LNET_NID_ANY);
983 gateway_nid = libcfs_str2nid(gw);
984 if (gateway_nid == LNET_NID_ANY) {
987 "\"cannot parse gateway NID '%s'\"", gw);
988 rc = LUSTRE_CFG_RC_BAD_PARAM;
992 /* show all routes with out filtering on gateway */
993 gateway_nid = LNET_NID_ANY;
995 if ((hops < 1 && hops != -1) || hops > 255) {
998 "\"invalid hop count %d, must be between 0 and 256\"",
1000 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1004 /* create struct cYAML root object */
1005 root = cYAML_create_object(NULL, NULL);
1009 route = cYAML_create_seq(root, "route");
1014 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1017 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1023 /* filter on provided data */
1024 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1025 net != data.cfg_net)
1028 if (gateway_nid != LNET_NID_ANY &&
1029 gateway_nid != data.cfg_nid)
1033 hops != data.cfg_config_u.cfg_route.rtr_hop)
1037 prio != data.cfg_config_u.cfg_route.rtr_priority)
1040 /* default rc to -1 incase we hit the goto */
1044 item = cYAML_create_seq_item(route);
1048 if (first_seq == NULL)
1051 if (cYAML_create_string(item, "net",
1052 libcfs_net2str(data.cfg_net)) == NULL)
1055 if (cYAML_create_string(item, "gateway",
1056 libcfs_nid2str(data.cfg_nid)) == NULL)
1060 if (cYAML_create_number(item, "hop",
1061 (int) data.cfg_config_u.
1062 cfg_route.rtr_hop) ==
1066 if (cYAML_create_number(item, "priority",
1068 cfg_route.rtr_priority) == NULL)
1071 if (cYAML_create_number(item, "health_sensitivity",
1073 cfg_route.rtr_sensitivity) == NULL)
1077 cYAML_create_string(item, "state",
1078 data.cfg_config_u.cfg_route.
1080 "up" : "down") == NULL)
1085 /* print output iff show_rc is not provided */
1086 if (show_rc == NULL)
1087 cYAML_print_tree(root);
1089 if (l_errno != ENOENT) {
1092 "\"cannot get routes: %s\"",
1097 rc = LUSTRE_CFG_RC_NO_ERR;
1099 snprintf(err_str, sizeof(err_str), "\"success\"");
1101 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1102 cYAML_free_tree(root);
1103 } else if (show_rc != NULL && *show_rc != NULL) {
1104 struct cYAML *show_node;
1105 /* find the route node, if one doesn't exist then
1106 * insert one. Otherwise add to the one there
1108 show_node = cYAML_get_object_item(*show_rc, "route");
1109 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1110 cYAML_insert_child(show_node, first_seq);
1113 } else if (show_node == NULL) {
1114 cYAML_insert_sibling((*show_rc)->cy_child,
1118 cYAML_free_tree(root);
1124 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1129 static int socket_intf_query(int request, char *intf,
1135 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1136 return LUSTRE_CFG_RC_BAD_PARAM;
1138 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1140 return LUSTRE_CFG_RC_BAD_PARAM;
1142 strcpy(ifr->ifr_name, intf);
1143 rc = ioctl(sockfd, request, ifr);
1145 rc = LUSTRE_CFG_RC_BAD_PARAM;
1152 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1157 memset(&ifr, 0, sizeof(ifr));
1158 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1160 return LUSTRE_CFG_RC_BAD_PARAM;
1162 if ((ifr.ifr_flags & IFF_UP) == 0)
1163 return LUSTRE_CFG_RC_BAD_PARAM;
1165 memset(&ifr, 0, sizeof(ifr));
1166 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1168 return LUSTRE_CFG_RC_BAD_PARAM;
1170 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1171 *ip = bswap_32(*ip);
1173 return LUSTRE_CFG_RC_NO_ERR;
1177 * for each interface in the array of interfaces find the IP address of
1178 * that interface, create its nid and add it to an array of NIDs.
1179 * Stop if any of the interfaces is down
1181 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1182 lnet_nid_t **nids, __u32 *nnids,
1183 char *err_str, size_t str_len)
1185 int i = 0, count = 0, rc;
1186 struct lnet_dlc_intf_descr *intf;
1187 char val[LNET_MAX_STR_LEN];
1194 if (nw == NULL || nids == NULL) {
1195 snprintf(err_str, str_len,
1196 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1197 err_str[str_len - 1] = '\0';
1198 return LUSTRE_CFG_RC_BAD_PARAM;
1201 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1204 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1208 *nids = calloc(count, sizeof(lnet_nid_t));
1209 if (*nids == NULL) {
1210 snprintf(err_str, str_len,
1211 "\"out of memory\"");
1212 err_str[str_len - 1] = '\0';
1213 return LUSTRE_CFG_RC_OUT_OF_MEM;
1216 * special case the GNI interface since it doesn't have an IP
1217 * address. The assumption is that there can only be one GNI
1218 * interface in the system. No interface name is provided.
1220 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1221 rc = read_sysfs_file(gni_nid_path, "nid", val,
1224 snprintf(err_str, str_len,
1225 "\"cannot read gni nid\"");
1226 err_str[str_len - 1] = '\0';
1229 gni_num = atoi(val);
1231 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1236 /* look at the other interfaces */
1237 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1238 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1239 /* handle LNDs with numeric interface name */
1240 num = strtoul(intf->intf_name, &endp, 0);
1241 if (endp == intf->intf_name || *endp != '\0') {
1242 rc = LUSTRE_CFG_RC_BAD_PARAM;
1243 snprintf(err_str, str_len,
1244 "\"couldn't query intf %s\"",
1246 err_str[str_len - 1] = '\0';
1249 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1252 /* handle LNDs with ip interface name */
1253 rc = lustre_lnet_queryip(intf, &ip);
1254 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1255 snprintf(err_str, str_len,
1256 "\"couldn't query intf %s\"",
1258 err_str[str_len - 1] = '\0';
1261 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1278 * called repeatedly until a match or no more ip range
1280 * ip_range expression
1281 * interface list with all the interface names.
1282 * all the interfaces in the system.
1284 * try to match the ip_range expr to one of the interfaces' IPs in
1285 * the system. If we hit a patch for an interface. Check if that
1286 * interface name is in the list.
1288 * If there are more than one interface in the list, then make sure
1289 * that the IPs for all of these interfaces match the ip ranges
1292 * for each interface in intf_list
1293 * look up the intf name in ifa
1294 * if not there then no match
1295 * check ip obtained from ifa against a match to any of the
1297 * If no match, then fail
1299 * The result is that all the interfaces have to match.
1301 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1302 struct list_head *intf_list,
1303 struct list_head *ip_ranges)
1307 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1308 struct ifaddrs *ifaddr = ifa;
1309 struct lustre_lnet_ip_range_descr *ip_range;
1313 * if there are no explicit interfaces, and no ip ranges, then
1314 * configure the first tcp interface we encounter.
1316 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1317 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1318 if (ifaddr->ifa_addr == NULL)
1321 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1324 family = ifaddr->ifa_addr->sa_family;
1325 if (family == AF_INET &&
1326 strcmp(ifaddr->ifa_name, "lo") != 0) {
1327 rc = lustre_lnet_add_intf_descr
1328 (intf_list, ifaddr->ifa_name,
1329 strlen(ifaddr->ifa_name));
1331 if (rc != LUSTRE_CFG_RC_NO_ERR)
1334 return LUSTRE_CFG_RC_MATCH;
1337 return LUSTRE_CFG_RC_NO_MATCH;
1341 * First interface which matches an IP pattern will be used
1343 if (list_empty(intf_list)) {
1345 * no interfaces provided in the rule, but an ip range is
1346 * provided, so try and match an interface to the ip
1349 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1350 if (ifaddr->ifa_addr == NULL)
1353 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1356 family = ifaddr->ifa_addr->sa_family;
1357 if (family == AF_INET) {
1358 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1361 list_for_each_entry(ip_range, ip_ranges,
1363 rc = cfs_ip_addr_match(bswap_32(ip),
1364 &ip_range->ipr_expr);
1368 rc = lustre_lnet_add_intf_descr
1369 (intf_list, ifaddr->ifa_name,
1370 strlen(ifaddr->ifa_name));
1372 if (rc != LUSTRE_CFG_RC_NO_ERR)
1378 if (!list_empty(intf_list))
1379 return LUSTRE_CFG_RC_MATCH;
1381 return LUSTRE_CFG_RC_NO_MATCH;
1385 * If an interface is explicitly specified the ip-range might or
1386 * might not be specified. if specified the interface needs to match the
1387 * ip-range. If no ip-range then the interfaces are
1388 * automatically matched if they are all up.
1389 * If > 1 interfaces all the interfaces must match for the NI to
1392 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1393 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1394 if (ifaddr->ifa_addr == NULL)
1397 family = ifaddr->ifa_addr->sa_family;
1398 if (family == AF_INET &&
1399 strcmp(intf_descr->intf_name,
1400 ifaddr->ifa_name) == 0)
1404 if (ifaddr == NULL) {
1405 list_del(&intf_descr->intf_on_network);
1406 free_intf_descr(intf_descr);
1410 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1411 list_del(&intf_descr->intf_on_network);
1412 free_intf_descr(intf_descr);
1416 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1419 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1420 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1426 /* no match for this interface */
1427 list_del(&intf_descr->intf_on_network);
1428 free_intf_descr(intf_descr);
1432 return LUSTRE_CFG_RC_MATCH;
1435 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1436 lnet_nid_t **nids, __u32 *nnids,
1437 char *err_str, size_t str_len)
1439 struct ifaddrs *ifa;
1440 int rc = LUSTRE_CFG_RC_NO_ERR;
1442 rc = getifaddrs(&ifa);
1444 snprintf(err_str, str_len,
1445 "\"failed to get interface addresses: %d\"", -errno);
1446 err_str[str_len - 1] = '\0';
1450 rc = lustre_lnet_match_ip_to_intf(ifa,
1451 &ip2nets->ip2nets_net.nw_intflist,
1452 &ip2nets->ip2nets_ip_ranges);
1453 if (rc != LUSTRE_CFG_RC_MATCH) {
1454 snprintf(err_str, str_len,
1455 "\"couldn't match ip to existing interfaces\"");
1456 err_str[str_len - 1] = '\0';
1461 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1462 err_str, sizeof(err_str));
1463 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1474 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1475 struct lnet_ioctl_config_lnd_tunables *tunables,
1476 struct cfs_expr_list *global_cpts,
1477 lnet_nid_t *nids, char *err_str)
1480 struct lnet_ioctl_config_ni *conf;
1481 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1482 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1485 struct lnet_dlc_intf_descr *intf_descr;
1487 struct cfs_expr_list *cpt_expr;
1489 list_for_each_entry(intf_descr, intf_list,
1491 if (tunables != NULL)
1492 len = sizeof(struct lnet_ioctl_config_ni) +
1493 sizeof(struct lnet_ioctl_config_lnd_tunables);
1495 len = sizeof(struct lnet_ioctl_config_ni);
1497 data = calloc(1, len);
1499 return LUSTRE_CFG_RC_OUT_OF_MEM;
1500 conf = (struct lnet_ioctl_config_ni*) data;
1501 if (tunables != NULL)
1502 tun = (struct lnet_ioctl_config_lnd_tunables*)
1505 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1506 conf->lic_cfg_hdr.ioc_len = len;
1507 conf->lic_nid = nids[i];
1508 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1511 if (intf_descr->cpt_expr != NULL)
1512 cpt_expr = intf_descr->cpt_expr;
1513 else if (global_cpts != NULL)
1514 cpt_expr = global_cpts;
1518 if (cpt_expr != NULL) {
1519 count = cfs_expr_list_values(cpt_expr,
1520 LNET_MAX_SHOW_NUM_CPT,
1523 memcpy(conf->lic_cpts, cpt_array,
1524 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1533 conf->lic_ncpts = count;
1535 if (tunables != NULL)
1536 memcpy(tun, tunables, sizeof(*tunables));
1538 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1543 "\"cannot add network: %s\"", strerror(errno));
1551 return LUSTRE_CFG_RC_NO_ERR;
1555 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1556 struct lnet_ioctl_config_lnd_tunables *tunables,
1557 struct cfs_expr_list *global_cpts,
1558 int seq_no, struct cYAML **err_rc)
1560 lnet_nid_t *nids = NULL;
1563 char err_str[LNET_MAX_STR_LEN];
1565 snprintf(err_str, sizeof(err_str), "\"success\"");
1570 "\"incomplete ip2nets information\"");
1571 rc = LUSTRE_CFG_RC_BAD_PARAM;
1576 * call below function to resolve the rules into a list of nids.
1577 * The memory is allocated in that function then freed here when
1578 * it's no longer needed.
1580 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1582 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1585 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1586 snprintf(err_str, sizeof(err_str),
1587 "\"no interfaces match ip2nets rules\"");
1591 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1592 tunables, global_cpts, nids,
1599 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1603 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1604 struct cfs_expr_list *global_cpts,
1606 struct lnet_ioctl_config_lnd_tunables *tunables,
1607 int seq_no, struct cYAML **err_rc)
1610 struct lnet_ioctl_config_ni *conf;
1611 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1612 char buf[LNET_MAX_STR_LEN];
1613 int rc = LUSTRE_CFG_RC_NO_ERR;
1614 char err_str[LNET_MAX_STR_LEN];
1615 lnet_nid_t *nids = NULL;
1619 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1622 snprintf(err_str, sizeof(err_str), "\"success\"");
1624 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1625 (list_empty(&nw_descr->nw_intflist) &&
1626 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1629 "\"missing mandatory parameters in NI config: '%s'\"",
1630 (nw_descr == NULL) ? "network , interface" :
1631 (nw_descr->nw_id == 0) ? "network" : "interface");
1632 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1636 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1639 "\"ip2net string too long %d\"",
1640 (int)strlen(ip2net));
1641 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1645 if (ip2net != NULL) {
1646 if (tunables != NULL)
1647 len = sizeof(struct lnet_ioctl_config_ni) +
1648 sizeof(struct lnet_ioctl_config_lnd_tunables);
1650 len = sizeof(struct lnet_ioctl_config_ni);
1651 data = calloc(1, len);
1653 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1656 conf = (struct lnet_ioctl_config_ni*) data;
1657 if (tunables != NULL)
1658 tun = (struct lnet_ioctl_config_lnd_tunables*)
1659 (data + sizeof(*conf));
1661 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1662 conf->lic_cfg_hdr.ioc_len = len;
1663 strncpy(conf->lic_legacy_ip2nets, ip2net,
1666 if (global_cpts != NULL) {
1667 count = cfs_expr_list_values(global_cpts,
1668 LNET_MAX_SHOW_NUM_CPT,
1671 memcpy(conf->lic_cpts, cpt_array,
1672 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1681 conf->lic_ncpts = count;
1683 if (tunables != NULL)
1684 memcpy(tun, tunables, sizeof(*tunables));
1686 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1691 "\"cannot add network: %s\"", strerror(errno));
1698 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1699 rc = LUSTRE_CFG_RC_NO_ERR;
1703 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1706 "\"cannot parse net '%s'\"",
1707 libcfs_net2str(nw_descr->nw_id));
1708 rc = LUSTRE_CFG_RC_BAD_PARAM;
1713 * special case the GNI since no interface name is expected
1715 if (list_empty(&nw_descr->nw_intflist) &&
1716 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1719 "\"no interface name provided\"");
1720 rc = LUSTRE_CFG_RC_BAD_PARAM;
1724 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1725 err_str, sizeof(err_str));
1727 rc = LUSTRE_CFG_RC_BAD_PARAM;
1731 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1732 tunables, global_cpts, nids,
1736 if (nw_descr != NULL) {
1737 list_for_each_entry_safe(intf_descr, tmp,
1738 &nw_descr->nw_intflist,
1740 list_del(&intf_descr->intf_on_network);
1741 free_intf_descr(intf_descr);
1745 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1756 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1757 int seq_no, struct cYAML **err_rc)
1759 struct lnet_ioctl_config_ni data;
1760 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1761 char err_str[LNET_MAX_STR_LEN];
1762 lnet_nid_t *nids = NULL;
1764 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1766 snprintf(err_str, sizeof(err_str), "\"success\"");
1768 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1771 "\"missing mandatory parameter in deleting NI: '%s'\"",
1772 (nw_descr == NULL) ? "network , interface" :
1773 (nw_descr->nw_id == 0) ? "network" : "interface");
1774 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1778 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1779 return LUSTRE_CFG_RC_NO_ERR;
1781 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1784 "\"cannot parse net '%s'\"",
1785 libcfs_net2str(nw_descr->nw_id));
1786 rc = LUSTRE_CFG_RC_BAD_PARAM;
1790 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1791 err_str, sizeof(err_str));
1793 rc = LUSTRE_CFG_RC_BAD_PARAM;
1798 * no interfaces just the nw_id is specified
1801 nids = calloc(1, sizeof(*nids));
1803 snprintf(err_str, sizeof(err_str),
1804 "\"out of memory\"");
1805 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1808 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1812 for (i = 0; i < nnids; i++) {
1813 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1814 data.lic_nid = nids[i];
1816 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1821 "\"cannot del network: %s\"", strerror(errno));
1825 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1827 list_del(&intf_descr->intf_on_network);
1828 free_intf_descr(intf_descr);
1832 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1841 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1842 enum lnet_health_type type, char *name,
1843 int seq_no, struct cYAML **err_rc)
1845 struct lnet_ioctl_reset_health_cfg data;
1846 int rc = LUSTRE_CFG_RC_NO_ERR;
1847 char err_str[LNET_MAX_STR_LEN];
1849 snprintf(err_str, sizeof(err_str), "\"success\"");
1851 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1852 data.rh_type = type;
1854 data.rh_value = value;
1857 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1861 sizeof(err_str), "Can not configure health value: %s",
1865 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1870 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1871 struct cYAML **err_rc)
1875 nid = libcfs_str2nid(ni_nid);
1878 return lustre_lnet_config_healthv(value, all, nid,
1879 LNET_HEALTH_TYPE_LOCAL_NI,
1880 "ni healthv", seq_no, err_rc);
1883 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1884 int seq_no, struct cYAML **err_rc)
1888 nid = libcfs_str2nid(lpni_nid);
1891 return lustre_lnet_config_healthv(value, all, nid,
1892 LNET_HEALTH_TYPE_PEER_NI,
1893 "peer_ni healthv", seq_no, err_rc);
1897 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1898 struct lnet_ioctl_comm_count *counts)
1900 if (cYAML_create_number(yaml, "put",
1901 counts->ico_put_count)
1904 if (cYAML_create_number(yaml, "get",
1905 counts->ico_get_count)
1908 if (cYAML_create_number(yaml, "reply",
1909 counts->ico_reply_count)
1912 if (cYAML_create_number(yaml, "ack",
1913 counts->ico_ack_count)
1916 if (cYAML_create_number(yaml, "hello",
1917 counts->ico_hello_count)
1924 static struct lnet_ioctl_comm_count *
1925 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1928 return &msg_stats->im_send_stats;
1930 return &msg_stats->im_recv_stats;
1932 return &msg_stats->im_drop_stats;
1937 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1938 struct cYAML **show_rc, struct cYAML **err_rc,
1942 struct lnet_ioctl_config_ni *ni_data;
1943 struct lnet_ioctl_config_lnd_tunables *lnd;
1944 struct lnet_ioctl_element_stats *stats;
1945 struct lnet_ioctl_element_msg_stats msg_stats;
1946 struct lnet_ioctl_local_ni_hstats hstats;
1947 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1948 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1949 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1951 struct cYAML *root = NULL, *tunables = NULL,
1952 *net_node = NULL, *interfaces = NULL,
1953 *item = NULL, *first_seq = NULL,
1954 *tmp = NULL, *statistics = NULL,
1956 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1957 char str_buf[str_buf_len];
1959 char err_str[LNET_MAX_STR_LEN];
1960 bool exist = false, new_net = true;
1962 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1964 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1966 buf = calloc(1, buf_size);
1970 ni_data = (struct lnet_ioctl_config_ni *)buf;
1973 net = libcfs_str2net(nw);
1974 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1977 "\"cannot parse net '%s'\"", nw);
1978 rc = LUSTRE_CFG_RC_BAD_PARAM;
1983 root = cYAML_create_object(NULL, NULL);
1987 net_node = cYAML_create_seq(root, "net");
1988 if (net_node == NULL)
1994 memset(buf, 0, buf_size);
1996 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1998 * set the ioc_len to the proper value since INIT assumes
2001 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2002 ni_data->lic_idx = i;
2004 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2010 rc_net = LNET_NIDNET(ni_data->lic_nid);
2012 /* filter on provided data */
2013 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2017 /* if we're backing up don't store lo */
2018 if (backup && LNET_NETTYP(rc_net) == LOLND)
2021 /* default rc to -1 in case we hit the goto */
2025 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2026 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2027 (ni_data->lic_bulk + sizeof(*stats));
2029 if (rc_net != prev_net) {
2036 if (!cYAML_create_string(net_node, "net type",
2037 libcfs_net2str(rc_net)))
2040 tmp = cYAML_create_seq(net_node, "local NI(s)");
2046 /* create the tree to be printed. */
2047 item = cYAML_create_seq_item(tmp);
2051 if (first_seq == NULL)
2055 cYAML_create_string(item, "nid",
2056 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2060 cYAML_create_string(item,
2062 (ni_data->lic_status ==
2063 LNET_NI_STATUS_UP) ?
2064 "up" : "down") == NULL)
2067 /* don't add interfaces unless there is at least one
2069 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2070 interfaces = cYAML_create_object(item, "interfaces");
2071 if (interfaces == NULL)
2074 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2075 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2077 sizeof(str_buf), "%d", j);
2078 if (cYAML_create_string(interfaces,
2080 ni_data->lic_ni_intf[j]) ==
2092 goto continue_without_msg_stats;
2094 statistics = cYAML_create_object(item, "statistics");
2095 if (statistics == NULL)
2098 if (cYAML_create_number(statistics, "send_count",
2099 stats->iel_send_count)
2103 if (cYAML_create_number(statistics, "recv_count",
2104 stats->iel_recv_count)
2108 if (cYAML_create_number(statistics, "drop_count",
2109 stats->iel_drop_count)
2114 goto continue_without_msg_stats;
2116 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2117 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2118 msg_stats.im_idx = i;
2120 rc = l_ioctl(LNET_DEV_ID,
2121 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2125 goto continue_without_msg_stats;
2128 for (k = 0; k < 3; k++) {
2129 struct lnet_ioctl_comm_count *counts;
2130 struct cYAML *msg_statistics = NULL;
2132 msg_statistics = cYAML_create_object(item,
2133 (char *)gmsg_stat_names[k]);
2134 if (msg_statistics == NULL)
2137 counts = get_counts(&msg_stats, k);
2141 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2146 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2147 hstats.hlni_nid = ni_data->lic_nid;
2148 /* grab health stats */
2149 rc = l_ioctl(LNET_DEV_ID,
2150 IOC_LIBCFS_GET_LOCAL_HSTATS,
2154 goto continue_without_msg_stats;
2156 yhstats = cYAML_create_object(item, "health stats");
2159 if (cYAML_create_number(yhstats, "health value",
2160 hstats.hlni_health_value)
2163 if (cYAML_create_number(yhstats, "interrupts",
2164 hstats.hlni_local_interrupt)
2167 if (cYAML_create_number(yhstats, "dropped",
2168 hstats.hlni_local_dropped)
2171 if (cYAML_create_number(yhstats, "aborted",
2172 hstats.hlni_local_aborted)
2175 if (cYAML_create_number(yhstats, "no route",
2176 hstats.hlni_local_no_route)
2179 if (cYAML_create_number(yhstats, "timeouts",
2180 hstats.hlni_local_timeout)
2183 if (cYAML_create_number(yhstats, "error",
2184 hstats.hlni_local_error)
2188 continue_without_msg_stats:
2189 tunables = cYAML_create_object(item, "tunables");
2193 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2194 if (rc != LUSTRE_CFG_RC_NO_ERR)
2197 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2199 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2200 rc != LUSTRE_CFG_RC_NO_MATCH)
2203 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2204 tunables = cYAML_create_object(item,
2206 if (tunables == NULL)
2211 cYAML_create_number(item, "dev cpt",
2212 ni_data->lic_dev_cpt) == NULL)
2216 cYAML_create_number(item, "tcp bonding",
2217 ni_data->lic_tcp_bonding)
2221 /* out put the CPTs in the format: "[x,x,x,...]" */
2223 limit = str_buf + str_buf_len - 3;
2224 pos += scnprintf(pos, limit - pos, "\"[");
2225 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2226 j < ni_data->lic_ncpts &&
2228 pos += scnprintf(pos, limit - pos,
2229 "%d", ni_data->lic_cpts[j]);
2230 if ((j + 1) < ni_data->lic_ncpts)
2231 pos += scnprintf(pos, limit - pos, ",");
2233 snprintf(pos, 3, "]\"");
2235 if (ni_data->lic_ncpts >= 1 &&
2236 cYAML_create_string(item, "CPT",
2242 /* Print out the net information only if show_rc is not provided */
2243 if (show_rc == NULL)
2244 cYAML_print_tree(root);
2246 if (l_errno != ENOENT) {
2249 "\"cannot get networks: %s\"",
2254 rc = LUSTRE_CFG_RC_NO_ERR;
2256 snprintf(err_str, sizeof(err_str), "\"success\"");
2258 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2259 cYAML_free_tree(root);
2260 } else if (show_rc != NULL && *show_rc != NULL) {
2261 struct cYAML *show_node;
2262 /* find the net node, if one doesn't exist
2263 * then insert one. Otherwise add to the one there
2265 show_node = cYAML_get_object_item(*show_rc, "net");
2266 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2267 cYAML_insert_child(show_node, first_seq);
2270 } else if (show_node == NULL) {
2271 cYAML_insert_sibling((*show_rc)->cy_child,
2275 cYAML_free_tree(root);
2281 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2286 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2288 struct lnet_ioctl_config_data data;
2289 int rc = LUSTRE_CFG_RC_NO_ERR;
2290 char err_str[LNET_MAX_STR_LEN];
2292 snprintf(err_str, sizeof(err_str), "\"success\"");
2294 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2295 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2297 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2302 "\"cannot %s routing %s\"",
2303 (enable) ? "enable" : "disable", strerror(errno));
2308 cYAML_build_error(rc, seq_no,
2309 (enable) ? ADD_CMD : DEL_CMD,
2310 "routing", err_str, err_rc);
2315 int ioctl_set_value(__u32 val, int ioc, char *name,
2316 int seq_no, struct cYAML **err_rc)
2318 struct lnet_ioctl_set_value data;
2319 int rc = LUSTRE_CFG_RC_NO_ERR;
2320 char err_str[LNET_MAX_STR_LEN];
2322 snprintf(err_str, sizeof(err_str), "\"success\"");
2324 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2325 data.sv_value = val;
2327 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2332 "\"cannot configure %s to %d: %s\"", name,
2333 val, strerror(errno));
2336 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2341 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2343 int rc = LUSTRE_CFG_RC_NO_ERR;
2344 char err_str[LNET_MAX_STR_LEN];
2345 char val[LNET_MAX_STR_LEN];
2347 snprintf(err_str, sizeof(err_str), "\"success\"");
2349 snprintf(val, sizeof(val), "%d", intrv);
2351 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2352 1, strlen(val) + 1);
2354 snprintf(err_str, sizeof(err_str),
2355 "\"cannot configure recovery interval: %s\"",
2358 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2363 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2365 int rc = LUSTRE_CFG_RC_NO_ERR;
2366 char err_str[LNET_MAX_STR_LEN];
2367 char val[LNET_MAX_STR_LEN];
2369 snprintf(err_str, sizeof(err_str), "\"success\"");
2371 snprintf(val, sizeof(val), "%d", sen);
2373 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2374 1, strlen(val) + 1);
2376 snprintf(err_str, sizeof(err_str),
2377 "\"cannot configure router health sensitivity: %s\"",
2380 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2385 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2387 int rc = LUSTRE_CFG_RC_NO_ERR;
2388 char err_str[LNET_MAX_STR_LEN];
2389 char val[LNET_MAX_STR_LEN];
2391 snprintf(err_str, sizeof(err_str), "\"success\"");
2393 snprintf(val, sizeof(val), "%d", sen);
2395 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2396 1, strlen(val) + 1);
2398 snprintf(err_str, sizeof(err_str),
2399 "\"cannot configure health sensitivity: %s\"",
2402 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2407 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2409 int rc = LUSTRE_CFG_RC_NO_ERR;
2410 char err_str[LNET_MAX_STR_LEN];
2411 char val[LNET_MAX_STR_LEN];
2413 snprintf(err_str, sizeof(err_str), "\"success\"");
2415 snprintf(val, sizeof(val), "%d", timeout);
2417 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2418 1, strlen(val) + 1);
2420 snprintf(err_str, sizeof(err_str),
2421 "\"cannot configure transaction timeout: %s\"",
2424 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2429 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2431 int rc = LUSTRE_CFG_RC_NO_ERR;
2432 char err_str[LNET_MAX_STR_LEN];
2433 char val[LNET_MAX_STR_LEN];
2435 snprintf(err_str, sizeof(err_str), "\"success\"");
2437 snprintf(val, sizeof(val), "%d", count);
2439 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2440 1, strlen(val) + 1);
2442 snprintf(err_str, sizeof(err_str),
2443 "\"cannot configure retry count: %s\"",
2446 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2451 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2453 int rc = LUSTRE_CFG_RC_NO_ERR;
2454 char err_str[LNET_MAX_STR_LEN];
2455 char val[LNET_MAX_STR_LEN];
2457 snprintf(err_str, sizeof(err_str), "\"success\"");
2459 snprintf(val, sizeof(val), "%d", max);
2461 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2462 1, strlen(val) + 1);
2464 snprintf(err_str, sizeof(err_str),
2465 "\"cannot configure max interfaces: %s\"",
2468 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2473 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2475 int rc = LUSTRE_CFG_RC_NO_ERR;
2476 char err_str[LNET_MAX_STR_LEN];
2477 char val[LNET_MAX_STR_LEN];
2479 snprintf(err_str, sizeof(err_str), "\"success\"");
2481 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2483 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2484 1, strlen(val) + 1);
2486 snprintf(err_str, sizeof(err_str),
2487 "\"cannot configure discovery: %s\"",
2490 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2496 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2497 struct cYAML **err_rc)
2499 int rc = LUSTRE_CFG_RC_NO_ERR;
2500 char err_str[LNET_MAX_STR_LEN];
2501 char val[LNET_MAX_STR_LEN];
2503 snprintf(err_str, sizeof(err_str), "\"success\"");
2505 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2507 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2508 1, strlen(val) + 1);
2510 snprintf(err_str, sizeof(err_str),
2511 "\"cannot configure drop asym route: %s\"",
2514 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2521 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2523 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2524 "numa_range", seq_no, err_rc);
2527 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2528 struct cYAML **err_rc)
2530 struct lnet_ioctl_config_data data;
2531 int rc = LUSTRE_CFG_RC_NO_ERR;
2532 char err_str[LNET_MAX_STR_LEN];
2534 snprintf(err_str, sizeof(err_str), "\"success\"");
2536 /* -1 indicates to ignore changes to this field */
2537 if (tiny < -1 || small < -1 || large < -1) {
2540 "\"tiny, small and large must be >= 0\"");
2541 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2545 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2546 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2547 data.cfg_config_u.cfg_buffers.buf_small = small;
2548 data.cfg_config_u.cfg_buffers.buf_large = large;
2550 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2555 "\"cannot configure buffers: %s\"", strerror(errno));
2560 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2565 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2566 struct cYAML **err_rc, bool backup)
2568 struct lnet_ioctl_config_data *data;
2569 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2570 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2573 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2574 int buf_count[LNET_NRBPOOLS] = {0};
2575 struct cYAML *root = NULL, *pools_node = NULL,
2576 *type_node = NULL, *item = NULL, *cpt = NULL,
2577 *first_seq = NULL, *buffers = NULL;
2579 char err_str[LNET_MAX_STR_LEN];
2580 char node_name[LNET_MAX_STR_LEN];
2583 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2585 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2589 data = (struct lnet_ioctl_config_data *)buf;
2591 root = cYAML_create_object(NULL, NULL);
2596 pools_node = cYAML_create_object(root, "routing");
2598 pools_node = cYAML_create_seq(root, "routing");
2599 if (pools_node == NULL)
2603 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2604 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2605 sizeof(struct lnet_ioctl_pool_cfg);
2606 data->cfg_count = i;
2608 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2616 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2619 goto calculate_buffers;
2621 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2622 item = cYAML_create_seq_item(pools_node);
2626 if (first_seq == NULL)
2629 cpt = cYAML_create_object(item, node_name);
2634 /* create the tree and print */
2635 for (j = 0; j < LNET_NRBPOOLS; j++) {
2637 type_node = cYAML_create_object(cpt, pools[j]);
2638 if (type_node == NULL)
2642 cYAML_create_number(type_node, "npages",
2643 pool_cfg->pl_pools[j].pl_npages)
2647 cYAML_create_number(type_node, "nbuffers",
2648 pool_cfg->pl_pools[j].
2649 pl_nbuffers) == NULL)
2652 cYAML_create_number(type_node, "credits",
2653 pool_cfg->pl_pools[j].
2654 pl_credits) == NULL)
2657 cYAML_create_number(type_node, "mincredits",
2658 pool_cfg->pl_pools[j].
2659 pl_mincredits) == NULL)
2661 /* keep track of the total count for each of the
2662 * tiny, small and large buffers */
2663 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2667 if (pool_cfg != NULL) {
2669 if (cYAML_create_number(pools_node, "enable",
2670 pool_cfg->pl_routing) ==
2674 goto add_buffer_section;
2677 item = cYAML_create_seq_item(pools_node);
2681 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2687 /* create a buffers entry in the show. This is necessary so that
2688 * if the YAML output is used to configure a node, the buffer
2689 * configuration takes hold */
2690 buffers = cYAML_create_object(root, "buffers");
2691 if (buffers == NULL)
2694 for (i = 0; i < LNET_NRBPOOLS; i++) {
2695 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2699 if (show_rc == NULL)
2700 cYAML_print_tree(root);
2702 if (l_errno != ENOENT) {
2705 "\"cannot get routing information: %s\"",
2710 rc = LUSTRE_CFG_RC_NO_ERR;
2712 snprintf(err_str, sizeof(err_str), "\"success\"");
2713 rc = LUSTRE_CFG_RC_NO_ERR;
2717 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2718 cYAML_free_tree(root);
2719 } else if (show_rc != NULL && *show_rc != NULL) {
2720 struct cYAML *routing_node;
2721 /* there should exist only one routing block and one
2722 * buffers block. If there already exists a previous one
2723 * then don't add another */
2724 routing_node = cYAML_get_object_item(*show_rc, "routing");
2725 if (routing_node == NULL) {
2726 cYAML_insert_sibling((*show_rc)->cy_child,
2730 cYAML_free_tree(root);
2736 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2741 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2742 struct cYAML **show_rc, struct cYAML **err_rc,
2746 * TODO: This function is changing in a future patch to accommodate
2747 * PEER_LIST and proper filtering on any nid of the peer
2749 struct lnet_ioctl_peer_cfg peer_info;
2750 struct lnet_peer_ni_credit_info *lpni_cri;
2751 struct lnet_ioctl_element_stats *lpni_stats;
2752 struct lnet_ioctl_element_msg_stats *msg_stats;
2753 struct lnet_ioctl_peer_ni_hstats *hstats;
2755 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2760 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2761 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2762 *msg_statistics = NULL, *statistics = NULL,
2764 char err_str[LNET_MAX_STR_LEN];
2765 struct lnet_process_id *list = NULL;
2770 snprintf(err_str, sizeof(err_str),
2771 "\"out of memory\"");
2773 /* create struct cYAML root object */
2774 root = cYAML_create_object(NULL, NULL);
2778 peer_root = cYAML_create_seq(root, "peer");
2779 if (peer_root == NULL)
2783 size = count * sizeof(struct lnet_process_id);
2784 list = malloc(size);
2790 list[0].nid = libcfs_str2nid(knid);
2794 memset(&peer_info, 0, sizeof(peer_info));
2795 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2796 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2797 peer_info.prcfg_size = size;
2798 peer_info.prcfg_bulk = list;
2801 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2803 count = peer_info.prcfg_count;
2807 if (l_errno != E2BIG) {
2810 "\"cannot get peer list: %s\"",
2816 size = peer_info.prcfg_size;
2817 list = malloc(size);
2826 data = malloc(size);
2832 for (i = 0; i < count; i++) {
2834 memset(&peer_info, 0, sizeof(peer_info));
2835 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2836 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2837 peer_info.prcfg_prim_nid = list[i].nid;
2838 peer_info.prcfg_size = size;
2839 peer_info.prcfg_bulk = data;
2842 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2847 if (l_errno != E2BIG) {
2850 "\"cannot get peer information: %s\"",
2856 size = peer_info.prcfg_size;
2857 data = malloc(size);
2865 peer = cYAML_create_seq_item(peer_root);
2869 if (first_seq == NULL)
2872 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2873 if (cYAML_create_string(peer, "primary nid",
2874 libcfs_nid2str(pnid))
2877 if (cYAML_create_string(peer, "Multi-Rail",
2878 peer_info.prcfg_mr ? "True" : "False")
2882 * print out the state of the peer only if details are
2887 cYAML_create_number(peer, "peer state",
2888 peer_info.prcfg_state)
2893 tmp = cYAML_create_seq(peer, "peer ni");
2898 for (j = 0; j < peer_info.prcfg_count; j++) {
2900 lpni_cri = (void*)nidp + sizeof(nidp);
2901 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2902 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2903 hstats = (void *)msg_stats + sizeof(*msg_stats);
2904 lpni_data = (void *)hstats + sizeof(*hstats);
2906 peer_ni = cYAML_create_seq_item(tmp);
2907 if (peer_ni == NULL)
2910 if (cYAML_create_string(peer_ni, "nid",
2911 libcfs_nid2str(*nidp))
2918 if (cYAML_create_string(peer_ni, "state",
2919 lpni_cri->cr_aliveness)
2926 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2927 lpni_cri->cr_ni_peer_tx_credits)
2931 if (cYAML_create_number(peer_ni, "available_tx_credits",
2932 lpni_cri->cr_peer_tx_credits)
2936 if (cYAML_create_number(peer_ni, "min_tx_credits",
2937 lpni_cri->cr_peer_min_tx_credits)
2941 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2942 lpni_cri->cr_peer_tx_qnob)
2946 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2947 lpni_cri->cr_peer_rtr_credits)
2951 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2952 lpni_cri->cr_peer_min_rtr_credits)
2956 if (cYAML_create_number(peer_ni, "refcount",
2957 lpni_cri->cr_refcount) == NULL)
2960 statistics = cYAML_create_object(peer_ni, "statistics");
2961 if (statistics == NULL)
2964 if (cYAML_create_number(statistics, "send_count",
2965 lpni_stats->iel_send_count)
2969 if (cYAML_create_number(statistics, "recv_count",
2970 lpni_stats->iel_recv_count)
2974 if (cYAML_create_number(statistics, "drop_count",
2975 lpni_stats->iel_drop_count)
2982 for (k = 0; k < 3; k++) {
2983 struct lnet_ioctl_comm_count *counts;
2985 msg_statistics = cYAML_create_object(peer_ni,
2986 (char *) gmsg_stat_names[k]);
2987 if (msg_statistics == NULL)
2990 counts = get_counts(msg_stats, k);
2994 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2999 yhstats = cYAML_create_object(peer_ni, "health stats");
3002 if (cYAML_create_number(yhstats, "health value",
3003 hstats->hlpni_health_value)
3006 if (cYAML_create_number(yhstats, "dropped",
3007 hstats->hlpni_remote_dropped)
3010 if (cYAML_create_number(yhstats, "timeout",
3011 hstats->hlpni_remote_timeout)
3014 if (cYAML_create_number(yhstats, "error",
3015 hstats->hlpni_remote_error)
3018 if (cYAML_create_number(yhstats, "network timeout",
3019 hstats->hlpni_network_timeout)
3025 /* print output iff show_rc is not provided */
3026 if (show_rc == NULL)
3027 cYAML_print_tree(root);
3029 snprintf(err_str, sizeof(err_str), "\"success\"");
3030 rc = LUSTRE_CFG_RC_NO_ERR;
3035 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3036 cYAML_free_tree(root);
3037 } else if (show_rc != NULL && *show_rc != NULL) {
3038 struct cYAML *show_node;
3039 /* find the peer node, if one doesn't exist then
3040 * insert one. Otherwise add to the one there
3042 show_node = cYAML_get_object_item(*show_rc,
3044 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3045 cYAML_insert_child(show_node, first_seq);
3048 } else if (show_node == NULL) {
3049 cYAML_insert_sibling((*show_rc)->cy_child,
3053 cYAML_free_tree(root);
3059 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3065 int lustre_lnet_list_peer(int seq_no,
3066 struct cYAML **show_rc, struct cYAML **err_rc)
3068 struct lnet_ioctl_peer_cfg peer_info;
3069 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3074 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3075 char err_str[LNET_MAX_STR_LEN];
3076 struct lnet_process_id *list = NULL;
3078 snprintf(err_str, sizeof(err_str),
3079 "\"out of memory\"");
3081 memset(&peer_info, 0, sizeof(peer_info));
3083 /* create struct cYAML root object */
3084 root = cYAML_create_object(NULL, NULL);
3088 list_root = cYAML_create_seq(root, "peer list");
3089 if (list_root == NULL)
3093 size = count * sizeof(struct lnet_process_id);
3094 list = malloc(size);
3100 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3101 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3102 peer_info.prcfg_size = size;
3103 peer_info.prcfg_bulk = list;
3106 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3107 count = peer_info.prcfg_count;
3111 if (l_errno != E2BIG) {
3114 "\"cannot get peer list: %s\"",
3120 size = peer_info.prcfg_size;
3121 list = malloc(size);
3128 /* count is now the actual number of ids in the list. */
3129 for (i = 0; i < count; i++) {
3130 if (cYAML_create_string(list_root, "nid",
3131 libcfs_nid2str(list[i].nid))
3136 /* print output iff show_rc is not provided */
3137 if (show_rc == NULL)
3138 cYAML_print_tree(root);
3140 snprintf(err_str, sizeof(err_str), "\"success\"");
3141 rc = LUSTRE_CFG_RC_NO_ERR;
3146 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3147 cYAML_free_tree(root);
3148 } else if (show_rc != NULL && *show_rc != NULL) {
3149 struct cYAML *show_node;
3150 /* find the peer node, if one doesn't exist then
3151 * insert one. Otherwise add to the one there
3153 show_node = cYAML_get_object_item(*show_rc,
3155 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3156 cYAML_insert_child(show_node, first_seq);
3159 } else if (show_node == NULL) {
3160 cYAML_insert_sibling((*show_rc)->cy_child,
3164 cYAML_free_tree(root);
3170 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3176 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3179 struct cYAML *show_node;
3181 show_node = cYAML_get_object_item(show_rc, "global");
3182 if (show_node != NULL)
3183 cYAML_insert_sibling(show_node->cy_child,
3186 cYAML_insert_sibling(show_rc->cy_child,
3191 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3192 char *name, __u32 value,
3193 struct cYAML **show_rc,
3194 struct cYAML **err_rc, int err)
3196 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3197 struct cYAML *root = NULL, *global = NULL;
3204 root = cYAML_create_object(NULL, NULL);
3208 global = cYAML_create_object(root, "global");
3212 if (cYAML_create_number(global, name,
3216 if (show_rc == NULL)
3217 cYAML_print_tree(root);
3219 snprintf(err_str, err_len, "\"success\"");
3221 rc = LUSTRE_CFG_RC_NO_ERR;
3224 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3225 cYAML_free_tree(root);
3226 } else if (show_rc != NULL && *show_rc != NULL) {
3227 add_to_global(*show_rc, global, root);
3232 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3237 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3238 struct cYAML **show_rc,
3239 struct cYAML **err_rc)
3241 struct lnet_ioctl_set_value data;
3244 char err_str[LNET_MAX_STR_LEN];
3246 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3248 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3250 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3255 "\"cannot get %s: %s\"",
3256 name, strerror(l_errno));
3259 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3260 data.sv_value, show_rc, err_rc, l_errno);
3263 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3264 struct cYAML **err_rc)
3266 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3267 char val[LNET_MAX_STR_LEN];
3268 int intrv = -1, l_errno = 0;
3269 char err_str[LNET_MAX_STR_LEN];
3271 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3273 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3277 snprintf(err_str, sizeof(err_str),
3278 "\"cannot get recovery interval: %d\"", rc);
3283 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3284 "recovery_interval", intrv, show_rc,
3288 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3289 struct cYAML **err_rc)
3291 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3292 char val[LNET_MAX_STR_LEN];
3293 int sen = -1, l_errno = 0;
3294 char err_str[LNET_MAX_STR_LEN];
3296 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3298 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3302 snprintf(err_str, sizeof(err_str),
3303 "\"cannot get health sensitivity: %d\"", rc);
3308 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3309 "health_sensitivity", sen, show_rc,
3313 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3314 struct cYAML **err_rc)
3316 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3317 char val[LNET_MAX_STR_LEN];
3318 int sen = -1, l_errno = 0;
3319 char err_str[LNET_MAX_STR_LEN];
3321 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3323 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3327 snprintf(err_str, sizeof(err_str),
3328 "\"cannot get router sensitivity percentage: %d\"", rc);
3333 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3334 "router_sensitivity", sen, show_rc,
3338 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3339 struct cYAML **err_rc)
3341 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3342 char val[LNET_MAX_STR_LEN];
3343 int tto = -1, l_errno = 0;
3344 char err_str[LNET_MAX_STR_LEN];
3346 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3348 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3352 snprintf(err_str, sizeof(err_str),
3353 "\"cannot get transaction timeout: %d\"", rc);
3358 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3359 "transaction_timeout", tto, show_rc,
3363 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3364 struct cYAML **err_rc)
3366 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3367 char val[LNET_MAX_STR_LEN];
3368 int retry_count = -1, l_errno = 0;
3369 char err_str[LNET_MAX_STR_LEN];
3371 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3373 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3377 snprintf(err_str, sizeof(err_str),
3378 "\"cannot get retry count: %d\"", rc);
3380 retry_count = atoi(val);
3383 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3384 "retry_count", retry_count, show_rc,
3388 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3389 struct cYAML **show_rc, struct cYAML **err_rc)
3391 struct lnet_ioctl_recovery_list nid_list;
3392 struct cYAML *root = NULL, *nids = NULL;
3394 char err_str[LNET_MAX_STR_LEN];
3396 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3398 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3399 nid_list.rlst_type = type;
3401 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3407 if (nid_list.rlst_num_nids == 0)
3410 root = cYAML_create_object(NULL, NULL);
3414 nids = cYAML_create_object(root, name);
3420 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3421 char nidenum[LNET_MAX_STR_LEN];
3422 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3423 if (!cYAML_create_string(nids, nidenum,
3424 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3428 snprintf(err_str, sizeof(err_str), "success\n");
3433 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3434 cYAML_free_tree(root);
3435 } else if (show_rc != NULL && *show_rc != NULL) {
3436 struct cYAML *show_node;
3437 /* find the net node, if one doesn't exist
3438 * then insert one. Otherwise add to the one there
3440 show_node = cYAML_get_object_item(*show_rc, name);
3441 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3442 cYAML_insert_child(show_node, nids);
3445 } else if (show_node == NULL) {
3446 cYAML_insert_sibling((*show_rc)->cy_child,
3450 cYAML_free_tree(root);
3456 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3461 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3462 struct cYAML **err_rc)
3464 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3465 seq_no, show_rc, err_rc);
3468 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3469 struct cYAML **err_rc)
3471 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3472 seq_no, show_rc, err_rc);
3475 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3476 struct cYAML **err_rc)
3478 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3479 char val[LNET_MAX_STR_LEN];
3480 int max_intf = -1, l_errno = 0;
3481 char err_str[LNET_MAX_STR_LEN];
3483 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3485 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3489 snprintf(err_str, sizeof(err_str),
3490 "\"cannot get max interfaces: %d\"", rc);
3492 max_intf = atoi(val);
3495 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3496 "max_intf", max_intf, show_rc,
3500 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3501 struct cYAML **err_rc)
3503 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3504 char val[LNET_MAX_STR_LEN];
3505 int discovery = -1, l_errno = 0;
3506 char err_str[LNET_MAX_STR_LEN];
3508 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3510 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3514 snprintf(err_str, sizeof(err_str),
3515 "\"cannot get discovery setting: %d\"", rc);
3518 * The kernel stores a discovery disabled value. User space
3519 * shows whether discovery is enabled. So the value must be
3522 discovery = !atoi(val);
3525 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3526 "discovery", discovery, show_rc,
3530 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3531 struct cYAML **err_rc)
3533 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3534 char val[LNET_MAX_STR_LEN];
3535 int drop_asym_route = -1, l_errno = 0;
3536 char err_str[LNET_MAX_STR_LEN];
3538 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3540 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3544 snprintf(err_str, sizeof(err_str),
3545 "\"cannot get drop asym route setting: %d\"", rc);
3547 drop_asym_route = atoi(val);
3550 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3551 "drop_asym_route", drop_asym_route,
3552 show_rc, err_rc, l_errno);
3555 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3556 struct cYAML **err_rc)
3558 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3559 "numa_range", show_rc, err_rc);
3562 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3563 struct cYAML **err_rc)
3565 struct lnet_ioctl_lnet_stats data;
3566 struct lnet_counters *cntrs;
3569 char err_str[LNET_MAX_STR_LEN];
3570 struct cYAML *root = NULL, *stats = NULL;
3572 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3574 LIBCFS_IOC_INIT_V2(data, st_hdr);
3576 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3581 "\"cannot get lnet statistics: %s\"",
3587 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3589 cntrs = &data.st_cntrs;
3591 root = cYAML_create_object(NULL, NULL);
3595 stats = cYAML_create_object(root, "statistics");
3599 if (!cYAML_create_number(stats, "msgs_alloc",
3600 cntrs->lct_common.lcc_msgs_alloc))
3603 if (!cYAML_create_number(stats, "msgs_max",
3604 cntrs->lct_common.lcc_msgs_max))
3607 if (!cYAML_create_number(stats, "rst_alloc",
3608 cntrs->lct_health.lch_rst_alloc))
3611 if (!cYAML_create_number(stats, "errors",
3612 cntrs->lct_common.lcc_errors))
3615 if (!cYAML_create_number(stats, "send_count",
3616 cntrs->lct_common.lcc_send_count))
3619 if (!cYAML_create_number(stats, "resend_count",
3620 cntrs->lct_health.lch_resend_count))
3623 if (!cYAML_create_number(stats, "response_timeout_count",
3624 cntrs->lct_health.lch_response_timeout_count))
3627 if (!cYAML_create_number(stats, "local_interrupt_count",
3628 cntrs->lct_health.lch_local_interrupt_count))
3631 if (!cYAML_create_number(stats, "local_dropped_count",
3632 cntrs->lct_health.lch_local_dropped_count))
3635 if (!cYAML_create_number(stats, "local_aborted_count",
3636 cntrs->lct_health.lch_local_aborted_count))
3639 if (!cYAML_create_number(stats, "local_no_route_count",
3640 cntrs->lct_health.lch_local_no_route_count))
3643 if (!cYAML_create_number(stats, "local_timeout_count",
3644 cntrs->lct_health.lch_local_timeout_count))
3647 if (!cYAML_create_number(stats, "local_error_count",
3648 cntrs->lct_health.lch_local_error_count))
3651 if (!cYAML_create_number(stats, "remote_dropped_count",
3652 cntrs->lct_health.lch_remote_dropped_count))
3655 if (!cYAML_create_number(stats, "remote_error_count",
3656 cntrs->lct_health.lch_remote_error_count))
3659 if (!cYAML_create_number(stats, "remote_timeout_count",
3660 cntrs->lct_health.lch_remote_timeout_count))
3663 if (!cYAML_create_number(stats, "network_timeout_count",
3664 cntrs->lct_health.lch_network_timeout_count))
3667 if (!cYAML_create_number(stats, "recv_count",
3668 cntrs->lct_common.lcc_recv_count))
3671 if (!cYAML_create_number(stats, "route_count",
3672 cntrs->lct_common.lcc_route_count))
3675 if (!cYAML_create_number(stats, "drop_count",
3676 cntrs->lct_common.lcc_drop_count))
3679 if (!cYAML_create_number(stats, "send_length",
3680 cntrs->lct_common.lcc_send_length))
3683 if (!cYAML_create_number(stats, "recv_length",
3684 cntrs->lct_common.lcc_recv_length))
3687 if (!cYAML_create_number(stats, "route_length",
3688 cntrs->lct_common.lcc_route_length))
3691 if (!cYAML_create_number(stats, "drop_length",
3692 cntrs->lct_common.lcc_drop_length))
3696 cYAML_print_tree(root);
3698 snprintf(err_str, sizeof(err_str), "\"success\"");
3699 rc = LUSTRE_CFG_RC_NO_ERR;
3701 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3702 cYAML_free_tree(root);
3703 } else if (show_rc != NULL && *show_rc != NULL) {
3704 cYAML_insert_sibling((*show_rc)->cy_child,
3711 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3716 typedef int (*cmd_handler_t)(struct cYAML *tree,
3717 struct cYAML **show_rc,
3718 struct cYAML **err_rc);
3720 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3721 struct cYAML **err_rc)
3723 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3725 net = cYAML_get_object_item(tree, "net");
3726 gw = cYAML_get_object_item(tree, "gateway");
3727 hop = cYAML_get_object_item(tree, "hop");
3728 prio = cYAML_get_object_item(tree, "priority");
3729 sen = cYAML_get_object_item(tree, "health_sensitivity");
3730 seq_no = cYAML_get_object_item(tree, "seq_no");
3732 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3733 (gw) ? gw->cy_valuestring : NULL,
3734 (hop) ? hop->cy_valueint : -1,
3735 (prio) ? prio->cy_valueint : -1,
3736 (sen) ? sen->cy_valueint : -1,
3737 (seq_no) ? seq_no->cy_valueint : -1,
3743 * 0: <intf_name>['['<expr>']']
3744 * 1: <intf_name>['['<expr>']']
3746 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3747 struct lnet_dlc_network_descr *nw_descr)
3749 struct cYAML *child = NULL;
3750 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3751 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3753 if (intf_tree == NULL || nw_descr == NULL)
3754 return LUSTRE_CFG_RC_BAD_PARAM;
3756 /* now grab all the interfaces and their cpts */
3757 child = intf_tree->cy_child;
3758 while (child != NULL) {
3759 if (child->cy_valuestring == NULL) {
3760 child = child->cy_next;
3764 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3767 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3768 child->cy_valuestring,
3769 strlen(child->cy_valuestring));
3770 if (rc != LUSTRE_CFG_RC_NO_ERR)
3774 child = child->cy_next;
3778 return LUSTRE_CFG_RC_MISSING_PARAM;
3783 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3785 list_del(&intf_descr->intf_on_network);
3786 free_intf_descr(intf_descr);
3793 yaml_extract_cmn_tunables(struct cYAML *tree,
3794 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3795 struct cfs_expr_list **global_cpts)
3797 struct cYAML *tun, *item, *smp;
3800 tun = cYAML_get_object_item(tree, "tunables");
3802 item = cYAML_get_object_item(tun, "peer_timeout");
3804 tunables->lct_peer_timeout = item->cy_valueint;
3805 item = cYAML_get_object_item(tun, "peer_credits");
3807 tunables->lct_peer_tx_credits = item->cy_valueint;
3808 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3810 tunables->lct_peer_rtr_credits = item->cy_valueint;
3811 item = cYAML_get_object_item(tun, "credits");
3813 tunables->lct_max_tx_credits = item->cy_valueint;
3814 smp = cYAML_get_object_item(tun, "CPT");
3816 rc = cfs_expr_list_parse(smp->cy_valuestring,
3817 strlen(smp->cy_valuestring),
3818 0, UINT_MAX, global_cpts);
3820 *global_cpts = NULL;
3830 yaml_extract_tunables(struct cYAML *tree,
3831 struct lnet_ioctl_config_lnd_tunables *tunables,
3832 struct cfs_expr_list **global_cpts,
3837 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3843 lustre_yaml_extract_lnd_tunables(tree, net_type,
3851 * - net type: <net>[<NUM>]
3853 * - nid: <ip>@<net>[<NUM>]
3856 * 0: <intf_name>['['<expr>']']
3857 * 1: <intf_name>['['<expr>']']
3859 * peer_timeout: <NUM>
3860 * peer_credits: <NUM>
3861 * peer_buffer_credits: <NUM>
3864 * peercredits_hiw: <NUM>
3865 * map_on_demand: <NUM>
3866 * concurrent_sends: <NUM>
3867 * fmr_pool_size: <NUM>
3868 * fmr_flush_trigger: <NUM>
3871 * At least one interface is required. If no interfaces are provided the
3872 * network interface can not be configured.
3874 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3875 struct cYAML **err_rc)
3877 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3879 int num_entries = 0, rc;
3880 struct lnet_dlc_network_descr nw_descr;
3881 struct cfs_expr_list *global_cpts = NULL;
3882 struct lnet_ioctl_config_lnd_tunables tunables;
3885 memset(&tunables, 0, sizeof(tunables));
3887 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3888 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3890 ip2net = cYAML_get_object_item(tree, "ip2net");
3891 net = cYAML_get_object_item(tree, "net type");
3893 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3895 nw_descr.nw_id = LOLND;
3898 * if neither net nor ip2nets are present, then we can not
3899 * configure the network.
3901 if (!net && !ip2net)
3902 return LUSTRE_CFG_RC_MISSING_PARAM;
3904 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3905 if (local_nis == NULL)
3906 return LUSTRE_CFG_RC_MISSING_PARAM;
3908 if (!cYAML_is_sequence(local_nis))
3909 return LUSTRE_CFG_RC_BAD_PARAM;
3911 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3912 intf = cYAML_get_object_item(item, "interfaces");
3915 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3916 if (num_entries <= 0) {
3917 cYAML_build_error(num_entries, -1, "ni", "add",
3918 "bad interface list",
3920 return LUSTRE_CFG_RC_BAD_PARAM;
3924 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3925 LNET_NETTYP(nw_descr.nw_id));
3926 seq_no = cYAML_get_object_item(tree, "seq_no");
3928 rc = lustre_lnet_config_ni(&nw_descr,
3930 (ip2net) ? ip2net->cy_valuestring : NULL,
3931 (found) ? &tunables: NULL,
3932 (seq_no) ? seq_no->cy_valueint : -1,
3935 if (global_cpts != NULL)
3936 cfs_expr_list_free(global_cpts);
3943 * - net-spec: <tcp|o2ib|gni>[NUM]
3945 * 0: <intf name>['['<expr>']']
3946 * 1: <intf name>['['<expr>']']
3948 * 0: <expr.expr.expr.expr>
3949 * 1: <expr.expr.expr.expr>
3951 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3952 struct cYAML **show_rc,
3953 struct cYAML **err_rc)
3955 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3957 struct lustre_lnet_ip2nets ip2nets;
3958 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3960 int rc = LUSTRE_CFG_RC_NO_ERR;
3961 struct cfs_expr_list *global_cpts = NULL;
3962 struct cfs_expr_list *el, *el_tmp;
3963 struct lnet_ioctl_config_lnd_tunables tunables;
3964 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3967 memset(&tunables, 0, sizeof(tunables));
3969 /* initialize all lists */
3970 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
3971 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
3972 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
3974 net = cYAML_get_object_item(tree, "net-spec");
3976 return LUSTRE_CFG_RC_BAD_PARAM;
3978 if (net != NULL && net->cy_valuestring == NULL)
3979 return LUSTRE_CFG_RC_BAD_PARAM;
3981 /* assign the network id */
3982 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
3983 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
3984 return LUSTRE_CFG_RC_BAD_PARAM;
3986 seq_no = cYAML_get_object_item(tree, "seq_no");
3988 intf = cYAML_get_object_item(tree, "interfaces");
3990 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
3992 return LUSTRE_CFG_RC_BAD_PARAM;
3995 ip_range = cYAML_get_object_item(tree, "ip-range");
3996 if (ip_range != NULL) {
3997 item = ip_range->cy_child;
3998 while (item != NULL) {
3999 if (item->cy_valuestring == NULL) {
4000 item = item->cy_next;
4004 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4005 item->cy_valuestring);
4007 if (rc != LUSTRE_CFG_RC_NO_ERR)
4010 item = item->cy_next;
4014 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4015 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4017 rc = lustre_lnet_config_ip2nets(&ip2nets,
4018 (found) ? &tunables : NULL,
4020 (seq_no) ? seq_no->cy_valueint : -1,
4024 * don't stop because there was no match. Continue processing the
4025 * rest of the rules. If non-match then nothing is configured
4027 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4028 rc = LUSTRE_CFG_RC_NO_ERR;
4030 list_for_each_entry_safe(intf_descr, intf_tmp,
4031 &ip2nets.ip2nets_net.nw_intflist,
4033 list_del(&intf_descr->intf_on_network);
4034 free_intf_descr(intf_descr);
4037 list_for_each_entry_safe(ip_range_descr, tmp,
4038 &ip2nets.ip2nets_ip_ranges,
4040 list_del(&ip_range_descr->ipr_entry);
4041 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4043 list_del(&el->el_link);
4044 cfs_expr_list_free(el);
4046 free(ip_range_descr);
4052 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4053 struct cYAML **err_rc)
4055 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4057 int num_entries, rc;
4058 struct lnet_dlc_network_descr nw_descr;
4060 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4061 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4063 net = cYAML_get_object_item(tree, "net type");
4065 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4067 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4068 if (local_nis == NULL)
4069 return LUSTRE_CFG_RC_MISSING_PARAM;
4071 if (!cYAML_is_sequence(local_nis))
4072 return LUSTRE_CFG_RC_BAD_PARAM;
4074 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4075 intf = cYAML_get_object_item(item, "interfaces");
4078 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4079 if (num_entries <= 0) {
4080 cYAML_build_error(num_entries, -1, "ni", "add",
4081 "bad interface list",
4083 return LUSTRE_CFG_RC_BAD_PARAM;
4087 seq_no = cYAML_get_object_item(tree, "seq_no");
4089 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4090 (seq_no) ? seq_no->cy_valueint : -1,
4096 /* Create a nidstring parseable by the nidstrings library from the nid
4097 * information encoded in the CYAML structure.
4098 * NOTE: Caller must free memory allocated to nidstr
4100 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4101 char *prim_nid, int cmd)
4103 int num_strs = 0, rc;
4104 size_t buf_size, buf_pos, nidstr_len = 0;
4106 struct cYAML *child = NULL, *entry = NULL;
4108 if (cYAML_is_sequence(nids_entry)) {
4109 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4110 entry = cYAML_get_object_item(child, "nid");
4111 /* don't count an empty entry */
4112 if (!entry || !entry->cy_valuestring)
4116 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4117 if (cmd == LNETCTL_DEL_CMD) {
4119 * primary nid is present in the list of
4120 * nids so that means we want to delete
4121 * the entire peer, so no need to go
4122 * further. Just delete the entire peer.
4124 return LUSTRE_CFG_RC_NO_ERR;
4131 * + 1 for the space separating each string, and
4132 * accounts for the terminating null char
4134 nidstr_len += strlen(entry->cy_valuestring) + 1;
4139 if (num_strs == 0 && !prim_nid)
4140 return LUSTRE_CFG_RC_MISSING_PARAM;
4141 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4142 return LUSTRE_CFG_RC_NO_ERR;
4144 buffer = malloc(nidstr_len);
4146 return LUSTRE_CFG_RC_OUT_OF_MEM;
4148 /* now grab all the nids */
4151 buf_size = nidstr_len;
4153 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4154 entry = cYAML_get_object_item(child, "nid");
4155 if (!entry || !entry->cy_valuestring)
4159 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4163 rc = snprintf(buffer + buf_pos, buf_size, " ");
4164 buf_pos += (rc < buf_size) ? rc : buf_size;
4165 buf_size = nidstr_len - buf_pos;
4168 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4169 entry->cy_valuestring);
4170 buf_pos += (rc < buf_size) ? rc : buf_size;
4171 buf_size = nidstr_len - buf_pos;
4176 return LUSTRE_CFG_RC_NO_ERR;
4179 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4180 struct cYAML **err_rc, int cmd)
4182 int rc, num_nids = 0, seqn;
4184 char *nidstr = NULL, *prim_nidstr;
4185 char err_str[LNET_MAX_STR_LEN];
4186 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4187 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4189 seq_no = cYAML_get_object_item(tree, "seq_no");
4190 seqn = seq_no ? seq_no->cy_valueint : -1;
4192 prim_nid = cYAML_get_object_item(tree, "primary nid");
4193 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4195 peer_nis = cYAML_get_object_item(tree, "peer ni");
4196 if (!(prim_nid || peer_nis)) {
4197 rc = LUSTRE_CFG_RC_BAD_PARAM;
4198 snprintf(err_str, LNET_MAX_STR_LEN,
4199 "Neither \"primary nid\" nor \"peer ni\" are defined");
4203 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4204 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4205 snprintf(err_str, LNET_MAX_STR_LEN,
4206 "No nids defined in YAML block");
4208 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4209 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4211 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4212 snprintf(err_str, LNET_MAX_STR_LEN,
4213 "Unrecognized error %d", rc);
4219 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4220 LNET_MAX_NIDS_PER_PEER,
4228 if (cmd == LNETCTL_ADD_CMD) {
4229 mr = cYAML_get_object_item(tree, "Multi-Rail");
4231 if (mr && mr->cy_valuestring) {
4232 if (strcmp(mr->cy_valuestring, "False") == 0)
4234 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4235 rc = LUSTRE_CFG_RC_BAD_PARAM;
4236 snprintf(err_str, LNET_MAX_STR_LEN,
4237 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4238 mr->cy_valuestring);
4243 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4244 num_nids, mr_value, seqn,
4247 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4248 num_nids, seqn, err_rc);
4254 if (rc != LUSTRE_CFG_RC_NO_ERR)
4255 cYAML_build_error(rc, seqn, "peer",
4256 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4262 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4263 struct cYAML **err_rc)
4265 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4268 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4269 struct cYAML **err_rc)
4271 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4274 static int handle_yaml_config_buffers(struct cYAML *tree,
4275 struct cYAML **show_rc,
4276 struct cYAML **err_rc)
4279 struct cYAML *tiny, *small, *large, *seq_no;
4281 tiny = cYAML_get_object_item(tree, "tiny");
4282 small = cYAML_get_object_item(tree, "small");
4283 large = cYAML_get_object_item(tree, "large");
4284 seq_no = cYAML_get_object_item(tree, "seq_no");
4286 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4287 (small) ? small->cy_valueint : -1,
4288 (large) ? large->cy_valueint : -1,
4289 (seq_no) ? seq_no->cy_valueint : -1,
4295 static int handle_yaml_config_routing(struct cYAML *tree,
4296 struct cYAML **show_rc,
4297 struct cYAML **err_rc)
4299 int rc = LUSTRE_CFG_RC_NO_ERR;
4300 struct cYAML *seq_no, *enable;
4302 seq_no = cYAML_get_object_item(tree, "seq_no");
4303 enable = cYAML_get_object_item(tree, "enable");
4306 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4308 seq_no->cy_valueint : -1,
4315 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4316 struct cYAML **err_rc)
4320 struct cYAML *seq_no;
4322 net = cYAML_get_object_item(tree, "net");
4323 gw = cYAML_get_object_item(tree, "gateway");
4324 seq_no = cYAML_get_object_item(tree, "seq_no");
4326 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4327 (gw) ? gw->cy_valuestring : NULL,
4328 (seq_no) ? seq_no->cy_valueint : -1,
4332 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4333 struct cYAML **err_rc)
4335 struct cYAML *seq_no;
4337 seq_no = cYAML_get_object_item(tree, "seq_no");
4339 return lustre_lnet_enable_routing(0, (seq_no) ?
4340 seq_no->cy_valueint : -1,
4344 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4345 struct cYAML **err_rc)
4351 struct cYAML *detail;
4352 struct cYAML *seq_no;
4354 net = cYAML_get_object_item(tree, "net");
4355 gw = cYAML_get_object_item(tree, "gateway");
4356 hop = cYAML_get_object_item(tree, "hop");
4357 prio = cYAML_get_object_item(tree, "priority");
4358 detail = cYAML_get_object_item(tree, "detail");
4359 seq_no = cYAML_get_object_item(tree, "seq_no");
4361 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4362 (gw) ? gw->cy_valuestring : NULL,
4363 (hop) ? hop->cy_valueint : -1,
4364 (prio) ? prio->cy_valueint : -1,
4365 (detail) ? detail->cy_valueint : 0,
4366 (seq_no) ? seq_no->cy_valueint : -1,
4367 show_rc, err_rc, false);
4370 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4371 struct cYAML **err_rc)
4373 struct cYAML *net, *detail, *seq_no;
4375 net = cYAML_get_object_item(tree, "net");
4376 detail = cYAML_get_object_item(tree, "detail");
4377 seq_no = cYAML_get_object_item(tree, "seq_no");
4379 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4380 (detail) ? detail->cy_valueint : 0,
4381 (seq_no) ? seq_no->cy_valueint : -1,
4382 show_rc, err_rc, false);
4385 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4386 struct cYAML **err_rc)
4388 struct cYAML *seq_no;
4390 seq_no = cYAML_get_object_item(tree, "seq_no");
4392 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4393 show_rc, err_rc, false);
4396 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4397 struct cYAML **err_rc)
4399 struct cYAML *seq_no, *nid, *detail;
4401 seq_no = cYAML_get_object_item(tree, "seq_no");
4402 detail = cYAML_get_object_item(tree, "detail");
4403 nid = cYAML_get_object_item(tree, "nid");
4405 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4406 (detail) ? detail->cy_valueint : 0,
4407 (seq_no) ? seq_no->cy_valueint : -1,
4408 show_rc, err_rc, false);
4411 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4412 struct cYAML **err_rc)
4414 struct cYAML *seq_no;
4416 seq_no = cYAML_get_object_item(tree, "seq_no");
4418 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4422 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4423 struct cYAML **err_rc)
4425 struct cYAML *seq_no, *range;
4427 seq_no = cYAML_get_object_item(tree, "seq_no");
4428 range = cYAML_get_object_item(tree, "range");
4430 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4431 seq_no ? seq_no->cy_valueint : -1,
4435 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4436 struct cYAML **err_rc)
4438 struct cYAML *seq_no;
4440 seq_no = cYAML_get_object_item(tree, "seq_no");
4442 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4446 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4447 struct cYAML **err_rc)
4449 struct cYAML *seq_no;
4451 seq_no = cYAML_get_object_item(tree, "seq_no");
4453 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4457 static int handle_yaml_config_global_settings(struct cYAML *tree,
4458 struct cYAML **show_rc,
4459 struct cYAML **err_rc)
4461 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4462 *sen, *recov, *rsen, *drop_asym_route;
4465 seq_no = cYAML_get_object_item(tree, "seq_no");
4466 max_intf = cYAML_get_object_item(tree, "max_intf");
4468 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4469 seq_no ? seq_no->cy_valueint
4473 numa = cYAML_get_object_item(tree, "numa_range");
4475 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4476 seq_no ? seq_no->cy_valueint
4480 discovery = cYAML_get_object_item(tree, "discovery");
4482 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4483 seq_no ? seq_no->cy_valueint
4487 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4488 if (drop_asym_route)
4489 rc = lustre_lnet_config_drop_asym_route(
4490 drop_asym_route->cy_valueint,
4491 seq_no ? seq_no->cy_valueint : -1,
4494 retry = cYAML_get_object_item(tree, "retry_count");
4496 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4497 seq_no ? seq_no->cy_valueint
4501 tto = cYAML_get_object_item(tree, "transaction_timeout");
4503 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4504 seq_no ? seq_no->cy_valueint
4508 sen = cYAML_get_object_item(tree, "health_sensitivity");
4510 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4511 seq_no ? seq_no->cy_valueint
4515 recov = cYAML_get_object_item(tree, "recovery_interval");
4517 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4518 seq_no ? seq_no->cy_valueint
4522 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4524 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4525 seq_no ? seq_no->cy_valueint
4532 static int handle_yaml_del_global_settings(struct cYAML *tree,
4533 struct cYAML **show_rc,
4534 struct cYAML **err_rc)
4536 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4539 seq_no = cYAML_get_object_item(tree, "seq_no");
4540 max_intf = cYAML_get_object_item(tree, "max_intf");
4542 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4543 seq_no ? seq_no->cy_valueint
4547 numa = cYAML_get_object_item(tree, "numa_range");
4549 rc = lustre_lnet_config_numa_range(0,
4550 seq_no ? seq_no->cy_valueint
4554 /* peer discovery is enabled by default */
4555 discovery = cYAML_get_object_item(tree, "discovery");
4557 rc = lustre_lnet_config_discovery(1,
4558 seq_no ? seq_no->cy_valueint
4562 /* asymmetrical route messages are accepted by default */
4563 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4564 if (drop_asym_route)
4565 rc = lustre_lnet_config_drop_asym_route(
4566 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4571 static int handle_yaml_show_global_settings(struct cYAML *tree,
4572 struct cYAML **show_rc,
4573 struct cYAML **err_rc)
4575 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4576 *sen, *recov, *rsen, *drop_asym_route;
4579 seq_no = cYAML_get_object_item(tree, "seq_no");
4580 max_intf = cYAML_get_object_item(tree, "max_intf");
4582 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4586 numa = cYAML_get_object_item(tree, "numa_range");
4588 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4592 discovery = cYAML_get_object_item(tree, "discovery");
4594 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4598 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4599 if (drop_asym_route)
4600 rc = lustre_lnet_show_drop_asym_route(
4601 seq_no ? seq_no->cy_valueint : -1,
4604 retry = cYAML_get_object_item(tree, "retry_count");
4606 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4610 tto = cYAML_get_object_item(tree, "transaction_timeout");
4612 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4616 sen = cYAML_get_object_item(tree, "health_sensitivity");
4618 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4622 recov = cYAML_get_object_item(tree, "recovery_interval");
4624 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4628 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4630 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4637 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4638 struct cYAML **err_rc)
4640 struct cYAML *seq_no, *nid, *timeout;
4642 seq_no = cYAML_get_object_item(tree, "seq_no");
4643 nid = cYAML_get_object_item(tree, "primary nid");
4644 timeout = cYAML_get_object_item(tree, "timeout");
4646 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4647 (timeout) ? timeout->cy_valueint : 1000,
4648 (seq_no) ? seq_no->cy_valueint : -1,
4652 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4653 struct cYAML **err_rc)
4655 struct cYAML *seq_no, *nid, *force;
4657 seq_no = cYAML_get_object_item(tree, "seq_no");
4658 nid = cYAML_get_object_item(tree, "primary nid");
4659 force = cYAML_get_object_item(tree, "force");
4661 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4662 (force) ? force->cy_valueint : 0,
4663 (seq_no) ? seq_no->cy_valueint : -1,
4667 static int handle_yaml_no_op()
4669 return LUSTRE_CFG_RC_NO_ERR;
4672 struct lookup_cmd_hdlr_tbl {
4677 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4678 { .name = "route", .cb = handle_yaml_config_route },
4679 { .name = "net", .cb = handle_yaml_config_ni },
4680 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4681 { .name = "peer", .cb = handle_yaml_config_peer },
4682 { .name = "routing", .cb = handle_yaml_config_routing },
4683 { .name = "buffers", .cb = handle_yaml_config_buffers },
4684 { .name = "statistics", .cb = handle_yaml_no_op },
4685 { .name = "global", .cb = handle_yaml_config_global_settings},
4686 { .name = "numa", .cb = handle_yaml_config_numa },
4687 { .name = "ping", .cb = handle_yaml_no_op },
4688 { .name = "discover", .cb = handle_yaml_no_op },
4691 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4692 { .name = "route", .cb = handle_yaml_del_route },
4693 { .name = "net", .cb = handle_yaml_del_ni },
4694 { .name = "ip2nets", .cb = handle_yaml_no_op },
4695 { .name = "peer", .cb = handle_yaml_del_peer },
4696 { .name = "routing", .cb = handle_yaml_del_routing },
4697 { .name = "buffers", .cb = handle_yaml_no_op },
4698 { .name = "statistics", .cb = handle_yaml_no_op },
4699 { .name = "global", .cb = handle_yaml_del_global_settings},
4700 { .name = "numa", .cb = handle_yaml_del_numa },
4701 { .name = "ping", .cb = handle_yaml_no_op },
4702 { .name = "discover", .cb = handle_yaml_no_op },
4705 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4706 { .name = "route", .cb = handle_yaml_show_route },
4707 { .name = "net", .cb = handle_yaml_show_net },
4708 { .name = "peer", .cb = handle_yaml_show_peers },
4709 { .name = "ip2nets", .cb = handle_yaml_no_op },
4710 { .name = "routing", .cb = handle_yaml_show_routing },
4711 { .name = "buffers", .cb = handle_yaml_show_routing },
4712 { .name = "statistics", .cb = handle_yaml_show_stats },
4713 { .name = "global", .cb = handle_yaml_show_global_settings},
4714 { .name = "numa", .cb = handle_yaml_show_numa },
4715 { .name = "ping", .cb = handle_yaml_no_op },
4716 { .name = "discover", .cb = handle_yaml_no_op },
4719 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4720 { .name = "route", .cb = handle_yaml_no_op },
4721 { .name = "net", .cb = handle_yaml_no_op },
4722 { .name = "peer", .cb = handle_yaml_no_op },
4723 { .name = "ip2nets", .cb = handle_yaml_no_op },
4724 { .name = "routing", .cb = handle_yaml_no_op },
4725 { .name = "buffers", .cb = handle_yaml_no_op },
4726 { .name = "statistics", .cb = handle_yaml_no_op },
4727 { .name = "global", .cb = handle_yaml_no_op },
4728 { .name = "numa", .cb = handle_yaml_no_op },
4729 { .name = "ping", .cb = handle_yaml_ping },
4730 { .name = "discover", .cb = handle_yaml_discover },
4733 static cmd_handler_t lookup_fn(char *key,
4734 struct lookup_cmd_hdlr_tbl *tbl)
4740 for (i = 0; tbl[i].name != NULL; i++) {
4741 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4748 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4749 struct cYAML **show_rc, struct cYAML **err_rc)
4751 struct cYAML *tree, *item = NULL, *head, *child;
4753 char err_str[LNET_MAX_STR_LEN];
4754 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4756 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4758 return LUSTRE_CFG_RC_BAD_PARAM;
4760 child = tree->cy_child;
4761 while (child != NULL) {
4762 cb = lookup_fn(child->cy_string, table);
4764 snprintf(err_str, sizeof(err_str),
4765 "\"call back for '%s' not found\"",
4767 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4768 "yaml", "helper", err_str, err_rc);
4772 if (cYAML_is_sequence(child)) {
4773 while ((head = cYAML_get_next_seq_item(child, &item))
4775 rc = cb(head, show_rc, err_rc);
4776 if (rc != LUSTRE_CFG_RC_NO_ERR)
4780 rc = cb(child, show_rc, err_rc);
4781 if (rc != LUSTRE_CFG_RC_NO_ERR)
4785 child = child->cy_next;
4789 cYAML_free_tree(tree);
4794 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4796 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4800 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4802 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4806 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4808 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4812 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4814 return lustre_yaml_cb_helper(f, lookup_exec_tbl,