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");
1017 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1020 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1026 /* filter on provided data */
1027 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1028 net != data.cfg_net)
1031 if (gateway_nid != LNET_NID_ANY &&
1032 gateway_nid != data.cfg_nid)
1036 hops != data.cfg_config_u.cfg_route.rtr_hop)
1040 prio != data.cfg_config_u.cfg_route.rtr_priority)
1043 /* default rc to -1 incase we hit the goto */
1047 item = cYAML_create_seq_item(route);
1051 if (first_seq == NULL)
1054 if (cYAML_create_string(item, "net",
1055 libcfs_net2str(data.cfg_net)) == NULL)
1058 if (cYAML_create_string(item, "gateway",
1059 libcfs_nid2str(data.cfg_nid)) == NULL)
1063 if (cYAML_create_number(item, "hop",
1064 (int) data.cfg_config_u.
1065 cfg_route.rtr_hop) ==
1069 if (cYAML_create_number(item, "priority",
1071 cfg_route.rtr_priority) == NULL)
1074 if (cYAML_create_number(item, "health_sensitivity",
1076 cfg_route.rtr_sensitivity) == NULL)
1079 rt_alive = data.cfg_config_u.cfg_route.rtr_flags &
1081 rt_multi_hop = data.cfg_config_u.cfg_route.rtr_flags &
1085 cYAML_create_string(item, "state",
1087 "up" : "down") == NULL)
1091 cYAML_create_string(item, "type",
1093 "multi-hop" : "single-hop") == NULL)
1098 /* print output iff show_rc is not provided */
1099 if (show_rc == NULL)
1100 cYAML_print_tree(root);
1102 if (l_errno != ENOENT) {
1105 "\"cannot get routes: %s\"",
1110 rc = LUSTRE_CFG_RC_NO_ERR;
1112 snprintf(err_str, sizeof(err_str), "\"success\"");
1114 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1115 cYAML_free_tree(root);
1116 } else if (show_rc != NULL && *show_rc != NULL) {
1117 struct cYAML *show_node;
1118 /* find the route node, if one doesn't exist then
1119 * insert one. Otherwise add to the one there
1121 show_node = cYAML_get_object_item(*show_rc, "route");
1122 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1123 cYAML_insert_child(show_node, first_seq);
1126 } else if (show_node == NULL) {
1127 cYAML_insert_sibling((*show_rc)->cy_child,
1131 cYAML_free_tree(root);
1137 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1142 static int socket_intf_query(int request, char *intf,
1148 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1149 return LUSTRE_CFG_RC_BAD_PARAM;
1151 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1153 return LUSTRE_CFG_RC_BAD_PARAM;
1155 strcpy(ifr->ifr_name, intf);
1156 rc = ioctl(sockfd, request, ifr);
1158 rc = LUSTRE_CFG_RC_BAD_PARAM;
1165 static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
1170 memset(&ifr, 0, sizeof(ifr));
1171 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1173 return LUSTRE_CFG_RC_BAD_PARAM;
1175 if ((ifr.ifr_flags & IFF_UP) == 0)
1176 return LUSTRE_CFG_RC_BAD_PARAM;
1178 memset(&ifr, 0, sizeof(ifr));
1179 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1181 return LUSTRE_CFG_RC_BAD_PARAM;
1183 *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1184 *ip = bswap_32(*ip);
1186 return LUSTRE_CFG_RC_NO_ERR;
1190 * for each interface in the array of interfaces find the IP address of
1191 * that interface, create its nid and add it to an array of NIDs.
1192 * Stop if any of the interfaces is down
1194 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1195 lnet_nid_t **nids, __u32 *nnids,
1196 char *err_str, size_t str_len)
1198 int i = 0, count = 0, rc;
1199 struct lnet_dlc_intf_descr *intf;
1200 char val[LNET_MAX_STR_LEN];
1207 if (nw == NULL || nids == NULL) {
1208 snprintf(err_str, str_len,
1209 "\"unexpected parameters to lustre_lnet_intf2nids()\"");
1210 err_str[str_len - 1] = '\0';
1211 return LUSTRE_CFG_RC_BAD_PARAM;
1214 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1217 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1221 *nids = calloc(count, sizeof(lnet_nid_t));
1222 if (*nids == NULL) {
1223 snprintf(err_str, str_len,
1224 "\"out of memory\"");
1225 err_str[str_len - 1] = '\0';
1226 return LUSTRE_CFG_RC_OUT_OF_MEM;
1229 * special case the GNI interface since it doesn't have an IP
1230 * address. The assumption is that there can only be one GNI
1231 * interface in the system. No interface name is provided.
1233 if (LNET_NETTYP(nw->nw_id) == GNILND) {
1234 rc = read_sysfs_file(gni_nid_path, "nid", val,
1237 snprintf(err_str, str_len,
1238 "\"cannot read gni nid\"");
1239 err_str[str_len - 1] = '\0';
1242 gni_num = atoi(val);
1244 (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
1249 /* look at the other interfaces */
1250 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1251 if (LNET_NETTYP(nw->nw_id) == PTL4LND) {
1252 /* handle LNDs with numeric interface name */
1253 num = strtoul(intf->intf_name, &endp, 0);
1254 if (endp == intf->intf_name || *endp != '\0') {
1255 rc = LUSTRE_CFG_RC_BAD_PARAM;
1256 snprintf(err_str, str_len,
1257 "\"couldn't query intf %s\"",
1259 err_str[str_len - 1] = '\0';
1262 (*nids)[i] = LNET_MKNID(nw->nw_id, num);
1265 /* handle LNDs with ip interface name */
1266 rc = lustre_lnet_queryip(intf, &ip);
1267 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1268 snprintf(err_str, str_len,
1269 "\"couldn't query intf %s\"",
1271 err_str[str_len - 1] = '\0';
1274 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1291 * called repeatedly until a match or no more ip range
1293 * ip_range expression
1294 * interface list with all the interface names.
1295 * all the interfaces in the system.
1297 * try to match the ip_range expr to one of the interfaces' IPs in
1298 * the system. If we hit a patch for an interface. Check if that
1299 * interface name is in the list.
1301 * If there are more than one interface in the list, then make sure
1302 * that the IPs for all of these interfaces match the ip ranges
1305 * for each interface in intf_list
1306 * look up the intf name in ifa
1307 * if not there then no match
1308 * check ip obtained from ifa against a match to any of the
1310 * If no match, then fail
1312 * The result is that all the interfaces have to match.
1314 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1315 struct list_head *intf_list,
1316 struct list_head *ip_ranges)
1320 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1321 struct ifaddrs *ifaddr = ifa;
1322 struct lustre_lnet_ip_range_descr *ip_range;
1326 * if there are no explicit interfaces, and no ip ranges, then
1327 * configure the first tcp interface we encounter.
1329 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1330 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1331 if (ifaddr->ifa_addr == NULL)
1334 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1337 family = ifaddr->ifa_addr->sa_family;
1338 if (family == AF_INET &&
1339 strcmp(ifaddr->ifa_name, "lo") != 0) {
1340 rc = lustre_lnet_add_intf_descr
1341 (intf_list, ifaddr->ifa_name,
1342 strlen(ifaddr->ifa_name));
1344 if (rc != LUSTRE_CFG_RC_NO_ERR)
1347 return LUSTRE_CFG_RC_MATCH;
1350 return LUSTRE_CFG_RC_NO_MATCH;
1354 * First interface which matches an IP pattern will be used
1356 if (list_empty(intf_list)) {
1358 * no interfaces provided in the rule, but an ip range is
1359 * provided, so try and match an interface to the ip
1362 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1363 if (ifaddr->ifa_addr == NULL)
1366 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1369 family = ifaddr->ifa_addr->sa_family;
1370 if (family == AF_INET) {
1371 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1374 list_for_each_entry(ip_range, ip_ranges,
1376 rc = cfs_ip_addr_match(bswap_32(ip),
1377 &ip_range->ipr_expr);
1381 rc = lustre_lnet_add_intf_descr
1382 (intf_list, ifaddr->ifa_name,
1383 strlen(ifaddr->ifa_name));
1385 if (rc != LUSTRE_CFG_RC_NO_ERR)
1391 if (!list_empty(intf_list))
1392 return LUSTRE_CFG_RC_MATCH;
1394 return LUSTRE_CFG_RC_NO_MATCH;
1398 * If an interface is explicitly specified the ip-range might or
1399 * might not be specified. if specified the interface needs to match the
1400 * ip-range. If no ip-range then the interfaces are
1401 * automatically matched if they are all up.
1402 * If > 1 interfaces all the interfaces must match for the NI to
1405 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1406 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1407 if (ifaddr->ifa_addr == NULL)
1410 family = ifaddr->ifa_addr->sa_family;
1411 if (family == AF_INET &&
1412 strcmp(intf_descr->intf_name,
1413 ifaddr->ifa_name) == 0)
1417 if (ifaddr == NULL) {
1418 list_del(&intf_descr->intf_on_network);
1419 free_intf_descr(intf_descr);
1423 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1424 list_del(&intf_descr->intf_on_network);
1425 free_intf_descr(intf_descr);
1429 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1432 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1433 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1439 /* no match for this interface */
1440 list_del(&intf_descr->intf_on_network);
1441 free_intf_descr(intf_descr);
1445 return LUSTRE_CFG_RC_MATCH;
1448 static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1449 lnet_nid_t **nids, __u32 *nnids,
1450 char *err_str, size_t str_len)
1452 struct ifaddrs *ifa;
1453 int rc = LUSTRE_CFG_RC_NO_ERR;
1455 rc = getifaddrs(&ifa);
1457 snprintf(err_str, str_len,
1458 "\"failed to get interface addresses: %d\"", -errno);
1459 err_str[str_len - 1] = '\0';
1463 rc = lustre_lnet_match_ip_to_intf(ifa,
1464 &ip2nets->ip2nets_net.nw_intflist,
1465 &ip2nets->ip2nets_ip_ranges);
1466 if (rc != LUSTRE_CFG_RC_MATCH) {
1467 snprintf(err_str, str_len,
1468 "\"couldn't match ip to existing interfaces\"");
1469 err_str[str_len - 1] = '\0';
1474 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
1475 err_str, sizeof(err_str));
1476 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1487 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1488 struct lnet_ioctl_config_lnd_tunables *tunables,
1489 struct cfs_expr_list *global_cpts,
1490 lnet_nid_t *nids, char *err_str)
1493 struct lnet_ioctl_config_ni *conf;
1494 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1495 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1498 struct lnet_dlc_intf_descr *intf_descr;
1500 struct cfs_expr_list *cpt_expr;
1502 list_for_each_entry(intf_descr, intf_list,
1504 if (tunables != NULL)
1505 len = sizeof(struct lnet_ioctl_config_ni) +
1506 sizeof(struct lnet_ioctl_config_lnd_tunables);
1508 len = sizeof(struct lnet_ioctl_config_ni);
1510 data = calloc(1, len);
1512 return LUSTRE_CFG_RC_OUT_OF_MEM;
1513 conf = (struct lnet_ioctl_config_ni*) data;
1514 if (tunables != NULL)
1515 tun = (struct lnet_ioctl_config_lnd_tunables*)
1518 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1519 conf->lic_cfg_hdr.ioc_len = len;
1520 conf->lic_nid = nids[i];
1521 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1524 if (intf_descr->cpt_expr != NULL)
1525 cpt_expr = intf_descr->cpt_expr;
1526 else if (global_cpts != NULL)
1527 cpt_expr = global_cpts;
1531 if (cpt_expr != NULL) {
1532 count = cfs_expr_list_values(cpt_expr,
1533 LNET_MAX_SHOW_NUM_CPT,
1536 memcpy(conf->lic_cpts, cpt_array,
1537 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1546 conf->lic_ncpts = count;
1548 if (tunables != NULL)
1549 memcpy(tun, tunables, sizeof(*tunables));
1551 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1556 "\"cannot add network: %s\"", strerror(errno));
1564 return LUSTRE_CFG_RC_NO_ERR;
1568 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1569 struct lnet_ioctl_config_lnd_tunables *tunables,
1570 struct cfs_expr_list *global_cpts,
1571 int seq_no, struct cYAML **err_rc)
1573 lnet_nid_t *nids = NULL;
1576 char err_str[LNET_MAX_STR_LEN];
1578 snprintf(err_str, sizeof(err_str), "\"success\"");
1583 "\"incomplete ip2nets information\"");
1584 rc = LUSTRE_CFG_RC_BAD_PARAM;
1589 * call below function to resolve the rules into a list of nids.
1590 * The memory is allocated in that function then freed here when
1591 * it's no longer needed.
1593 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
1595 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
1598 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1599 snprintf(err_str, sizeof(err_str),
1600 "\"no interfaces match ip2nets rules\"");
1604 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1605 tunables, global_cpts, nids,
1612 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1616 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1617 struct cfs_expr_list *global_cpts,
1619 struct lnet_ioctl_config_lnd_tunables *tunables,
1620 int seq_no, struct cYAML **err_rc)
1623 struct lnet_ioctl_config_ni *conf;
1624 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1625 char buf[LNET_MAX_STR_LEN];
1626 int rc = LUSTRE_CFG_RC_NO_ERR;
1627 char err_str[LNET_MAX_STR_LEN];
1628 lnet_nid_t *nids = NULL;
1632 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1635 snprintf(err_str, sizeof(err_str), "\"success\"");
1637 if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
1638 (list_empty(&nw_descr->nw_intflist) &&
1639 LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
1642 "\"missing mandatory parameters in NI config: '%s'\"",
1643 (nw_descr == NULL) ? "network , interface" :
1644 (nw_descr->nw_id == 0) ? "network" : "interface");
1645 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1649 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1652 "\"ip2net string too long %d\"",
1653 (int)strlen(ip2net));
1654 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1658 if (ip2net != NULL) {
1659 if (tunables != NULL)
1660 len = sizeof(struct lnet_ioctl_config_ni) +
1661 sizeof(struct lnet_ioctl_config_lnd_tunables);
1663 len = sizeof(struct lnet_ioctl_config_ni);
1664 data = calloc(1, len);
1666 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1669 conf = (struct lnet_ioctl_config_ni*) data;
1670 if (tunables != NULL)
1671 tun = (struct lnet_ioctl_config_lnd_tunables*)
1672 (data + sizeof(*conf));
1674 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1675 conf->lic_cfg_hdr.ioc_len = len;
1676 strncpy(conf->lic_legacy_ip2nets, ip2net,
1679 if (global_cpts != NULL) {
1680 count = cfs_expr_list_values(global_cpts,
1681 LNET_MAX_SHOW_NUM_CPT,
1684 memcpy(conf->lic_cpts, cpt_array,
1685 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1694 conf->lic_ncpts = count;
1696 if (tunables != NULL)
1697 memcpy(tun, tunables, sizeof(*tunables));
1699 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1704 "\"cannot add network: %s\"", strerror(errno));
1711 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1712 rc = LUSTRE_CFG_RC_NO_ERR;
1716 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1719 "\"cannot parse net '%s'\"",
1720 libcfs_net2str(nw_descr->nw_id));
1721 rc = LUSTRE_CFG_RC_BAD_PARAM;
1726 * special case the GNI since no interface name is expected
1728 if (list_empty(&nw_descr->nw_intflist) &&
1729 (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
1732 "\"no interface name provided\"");
1733 rc = LUSTRE_CFG_RC_BAD_PARAM;
1737 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1738 err_str, sizeof(err_str));
1740 rc = LUSTRE_CFG_RC_BAD_PARAM;
1744 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1745 tunables, global_cpts, nids,
1749 if (nw_descr != NULL) {
1750 list_for_each_entry_safe(intf_descr, tmp,
1751 &nw_descr->nw_intflist,
1753 list_del(&intf_descr->intf_on_network);
1754 free_intf_descr(intf_descr);
1758 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1769 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1770 int seq_no, struct cYAML **err_rc)
1772 struct lnet_ioctl_config_ni data;
1773 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1774 char err_str[LNET_MAX_STR_LEN];
1775 lnet_nid_t *nids = NULL;
1777 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1779 snprintf(err_str, sizeof(err_str), "\"success\"");
1781 if (nw_descr == NULL || nw_descr->nw_id == 0) {
1784 "\"missing mandatory parameter in deleting NI: '%s'\"",
1785 (nw_descr == NULL) ? "network , interface" :
1786 (nw_descr->nw_id == 0) ? "network" : "interface");
1787 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1791 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1792 return LUSTRE_CFG_RC_NO_ERR;
1794 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1797 "\"cannot parse net '%s'\"",
1798 libcfs_net2str(nw_descr->nw_id));
1799 rc = LUSTRE_CFG_RC_BAD_PARAM;
1803 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
1804 err_str, sizeof(err_str));
1806 rc = LUSTRE_CFG_RC_BAD_PARAM;
1811 * no interfaces just the nw_id is specified
1814 nids = calloc(1, sizeof(*nids));
1816 snprintf(err_str, sizeof(err_str),
1817 "\"out of memory\"");
1818 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1821 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1825 for (i = 0; i < nnids; i++) {
1826 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1827 data.lic_nid = nids[i];
1829 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1834 "\"cannot del network: %s\"", strerror(errno));
1838 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1840 list_del(&intf_descr->intf_on_network);
1841 free_intf_descr(intf_descr);
1845 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1854 lustre_lnet_config_healthv(int value, bool all, lnet_nid_t nid,
1855 enum lnet_health_type type, char *name,
1856 int seq_no, struct cYAML **err_rc)
1858 struct lnet_ioctl_reset_health_cfg data;
1859 int rc = LUSTRE_CFG_RC_NO_ERR;
1860 char err_str[LNET_MAX_STR_LEN];
1862 snprintf(err_str, sizeof(err_str), "\"success\"");
1864 LIBCFS_IOC_INIT_V2(data, rh_hdr);
1865 data.rh_type = type;
1867 data.rh_value = value;
1870 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_HEALHV, &data);
1874 sizeof(err_str), "Can not configure health value: %s",
1878 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
1883 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid, int seq_no,
1884 struct cYAML **err_rc)
1888 nid = libcfs_str2nid(ni_nid);
1891 return lustre_lnet_config_healthv(value, all, nid,
1892 LNET_HEALTH_TYPE_LOCAL_NI,
1893 "ni healthv", seq_no, err_rc);
1896 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *lpni_nid,
1897 int seq_no, struct cYAML **err_rc)
1901 nid = libcfs_str2nid(lpni_nid);
1904 return lustre_lnet_config_healthv(value, all, nid,
1905 LNET_HEALTH_TYPE_PEER_NI,
1906 "peer_ni healthv", seq_no, err_rc);
1910 add_msg_stats_to_yaml_blk(struct cYAML *yaml,
1911 struct lnet_ioctl_comm_count *counts)
1913 if (cYAML_create_number(yaml, "put",
1914 counts->ico_put_count)
1917 if (cYAML_create_number(yaml, "get",
1918 counts->ico_get_count)
1921 if (cYAML_create_number(yaml, "reply",
1922 counts->ico_reply_count)
1925 if (cYAML_create_number(yaml, "ack",
1926 counts->ico_ack_count)
1929 if (cYAML_create_number(yaml, "hello",
1930 counts->ico_hello_count)
1937 static struct lnet_ioctl_comm_count *
1938 get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
1941 return &msg_stats->im_send_stats;
1943 return &msg_stats->im_recv_stats;
1945 return &msg_stats->im_drop_stats;
1950 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1951 struct cYAML **show_rc, struct cYAML **err_rc,
1955 struct lnet_ioctl_config_ni *ni_data;
1956 struct lnet_ioctl_config_lnd_tunables *lnd;
1957 struct lnet_ioctl_element_stats *stats;
1958 struct lnet_ioctl_element_msg_stats msg_stats;
1959 struct lnet_ioctl_local_ni_hstats hstats;
1960 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1961 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1962 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1964 struct cYAML *root = NULL, *tunables = NULL,
1965 *net_node = NULL, *interfaces = NULL,
1966 *item = NULL, *first_seq = NULL,
1967 *tmp = NULL, *statistics = NULL,
1969 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1970 char str_buf[str_buf_len];
1972 char err_str[LNET_MAX_STR_LEN];
1973 bool exist = false, new_net = true;
1975 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1977 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1979 buf = calloc(1, buf_size);
1983 ni_data = (struct lnet_ioctl_config_ni *)buf;
1986 net = libcfs_str2net(nw);
1987 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1990 "\"cannot parse net '%s'\"", nw);
1991 rc = LUSTRE_CFG_RC_BAD_PARAM;
1996 root = cYAML_create_object(NULL, NULL);
2000 net_node = cYAML_create_seq(root, "net");
2001 if (net_node == NULL)
2007 memset(buf, 0, buf_size);
2009 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
2011 * set the ioc_len to the proper value since INIT assumes
2014 ni_data->lic_cfg_hdr.ioc_len = buf_size;
2015 ni_data->lic_idx = i;
2017 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
2023 rc_net = LNET_NIDNET(ni_data->lic_nid);
2025 /* filter on provided data */
2026 if (net != LNET_NIDNET(LNET_NID_ANY) &&
2030 /* if we're backing up don't store lo */
2031 if (backup && LNET_NETTYP(rc_net) == LOLND)
2034 /* default rc to -1 in case we hit the goto */
2038 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
2039 lnd = (struct lnet_ioctl_config_lnd_tunables *)
2040 (ni_data->lic_bulk + sizeof(*stats));
2042 if (rc_net != prev_net) {
2049 if (!cYAML_create_string(net_node, "net type",
2050 libcfs_net2str(rc_net)))
2053 tmp = cYAML_create_seq(net_node, "local NI(s)");
2059 /* create the tree to be printed. */
2060 item = cYAML_create_seq_item(tmp);
2064 if (first_seq == NULL)
2068 cYAML_create_string(item, "nid",
2069 libcfs_nid2str(ni_data->lic_nid)) == NULL)
2073 cYAML_create_string(item,
2075 (ni_data->lic_status ==
2076 LNET_NI_STATUS_UP) ?
2077 "up" : "down") == NULL)
2080 /* don't add interfaces unless there is at least one
2082 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
2083 interfaces = cYAML_create_object(item, "interfaces");
2084 if (interfaces == NULL)
2087 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
2088 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
2090 sizeof(str_buf), "%d", j);
2091 if (cYAML_create_string(interfaces,
2093 ni_data->lic_ni_intf[j]) ==
2105 goto continue_without_msg_stats;
2107 statistics = cYAML_create_object(item, "statistics");
2108 if (statistics == NULL)
2111 if (cYAML_create_number(statistics, "send_count",
2112 stats->iel_send_count)
2116 if (cYAML_create_number(statistics, "recv_count",
2117 stats->iel_recv_count)
2121 if (cYAML_create_number(statistics, "drop_count",
2122 stats->iel_drop_count)
2127 goto continue_without_msg_stats;
2129 LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
2130 msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
2131 msg_stats.im_idx = i;
2133 rc = l_ioctl(LNET_DEV_ID,
2134 IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
2138 goto continue_without_msg_stats;
2141 for (k = 0; k < 3; k++) {
2142 struct lnet_ioctl_comm_count *counts;
2143 struct cYAML *msg_statistics = NULL;
2145 msg_statistics = cYAML_create_object(item,
2146 (char *)gmsg_stat_names[k]);
2147 if (msg_statistics == NULL)
2150 counts = get_counts(&msg_stats, k);
2154 if (!add_msg_stats_to_yaml_blk(msg_statistics,
2159 LIBCFS_IOC_INIT_V2(hstats, hlni_hdr);
2160 hstats.hlni_nid = ni_data->lic_nid;
2161 /* grab health stats */
2162 rc = l_ioctl(LNET_DEV_ID,
2163 IOC_LIBCFS_GET_LOCAL_HSTATS,
2167 goto continue_without_msg_stats;
2169 yhstats = cYAML_create_object(item, "health stats");
2172 if (cYAML_create_number(yhstats, "health value",
2173 hstats.hlni_health_value)
2176 if (cYAML_create_number(yhstats, "interrupts",
2177 hstats.hlni_local_interrupt)
2180 if (cYAML_create_number(yhstats, "dropped",
2181 hstats.hlni_local_dropped)
2184 if (cYAML_create_number(yhstats, "aborted",
2185 hstats.hlni_local_aborted)
2188 if (cYAML_create_number(yhstats, "no route",
2189 hstats.hlni_local_no_route)
2192 if (cYAML_create_number(yhstats, "timeouts",
2193 hstats.hlni_local_timeout)
2196 if (cYAML_create_number(yhstats, "error",
2197 hstats.hlni_local_error)
2201 continue_without_msg_stats:
2202 tunables = cYAML_create_object(item, "tunables");
2206 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
2207 if (rc != LUSTRE_CFG_RC_NO_ERR)
2210 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
2212 if (rc != LUSTRE_CFG_RC_NO_ERR &&
2213 rc != LUSTRE_CFG_RC_NO_MATCH)
2216 if (rc != LUSTRE_CFG_RC_NO_MATCH) {
2217 tunables = cYAML_create_object(item,
2219 if (tunables == NULL)
2224 cYAML_create_number(item, "dev cpt",
2225 ni_data->lic_dev_cpt) == NULL)
2229 cYAML_create_number(item, "tcp bonding",
2230 ni_data->lic_tcp_bonding)
2234 /* out put the CPTs in the format: "[x,x,x,...]" */
2236 limit = str_buf + str_buf_len - 3;
2237 pos += scnprintf(pos, limit - pos, "\"[");
2238 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
2239 j < ni_data->lic_ncpts &&
2241 pos += scnprintf(pos, limit - pos,
2242 "%d", ni_data->lic_cpts[j]);
2243 if ((j + 1) < ni_data->lic_ncpts)
2244 pos += scnprintf(pos, limit - pos, ",");
2246 snprintf(pos, 3, "]\"");
2248 if (ni_data->lic_ncpts >= 1 &&
2249 cYAML_create_string(item, "CPT",
2255 /* Print out the net information only if show_rc is not provided */
2256 if (show_rc == NULL)
2257 cYAML_print_tree(root);
2259 if (l_errno != ENOENT) {
2262 "\"cannot get networks: %s\"",
2267 rc = LUSTRE_CFG_RC_NO_ERR;
2269 snprintf(err_str, sizeof(err_str), "\"success\"");
2271 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2272 cYAML_free_tree(root);
2273 } else if (show_rc != NULL && *show_rc != NULL) {
2274 struct cYAML *show_node;
2275 /* find the net node, if one doesn't exist
2276 * then insert one. Otherwise add to the one there
2278 show_node = cYAML_get_object_item(*show_rc, "net");
2279 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2280 cYAML_insert_child(show_node, first_seq);
2283 } else if (show_node == NULL) {
2284 cYAML_insert_sibling((*show_rc)->cy_child,
2288 cYAML_free_tree(root);
2294 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2299 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2301 struct lnet_ioctl_config_data data;
2302 int rc = LUSTRE_CFG_RC_NO_ERR;
2303 char err_str[LNET_MAX_STR_LEN];
2305 snprintf(err_str, sizeof(err_str), "\"success\"");
2307 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2308 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2310 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2315 "\"cannot %s routing %s\"",
2316 (enable) ? "enable" : "disable", strerror(errno));
2321 cYAML_build_error(rc, seq_no,
2322 (enable) ? ADD_CMD : DEL_CMD,
2323 "routing", err_str, err_rc);
2328 int ioctl_set_value(__u32 val, int ioc, char *name,
2329 int seq_no, struct cYAML **err_rc)
2331 struct lnet_ioctl_set_value data;
2332 int rc = LUSTRE_CFG_RC_NO_ERR;
2333 char err_str[LNET_MAX_STR_LEN];
2335 snprintf(err_str, sizeof(err_str), "\"success\"");
2337 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2338 data.sv_value = val;
2340 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2345 "\"cannot configure %s to %d: %s\"", name,
2346 val, strerror(errno));
2349 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2354 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc)
2356 int rc = LUSTRE_CFG_RC_NO_ERR;
2357 char err_str[LNET_MAX_STR_LEN];
2358 char val[LNET_MAX_STR_LEN];
2360 snprintf(err_str, sizeof(err_str), "\"success\"");
2362 snprintf(val, sizeof(val), "%d", intrv);
2364 rc = write_sysfs_file(modparam_path, "lnet_recovery_interval", val,
2365 1, strlen(val) + 1);
2367 snprintf(err_str, sizeof(err_str),
2368 "\"cannot configure recovery interval: %s\"",
2371 cYAML_build_error(rc, seq_no, ADD_CMD, "recovery_interval", err_str, err_rc);
2376 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc)
2378 int rc = LUSTRE_CFG_RC_NO_ERR;
2379 char err_str[LNET_MAX_STR_LEN];
2380 char val[LNET_MAX_STR_LEN];
2382 snprintf(err_str, sizeof(err_str), "\"success\"");
2384 snprintf(val, sizeof(val), "%d", sen);
2386 rc = write_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
2387 1, strlen(val) + 1);
2389 snprintf(err_str, sizeof(err_str),
2390 "\"cannot configure router health sensitivity: %s\"",
2393 cYAML_build_error(rc, seq_no, ADD_CMD, "router_sensitivity", err_str, err_rc);
2398 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc)
2400 int rc = LUSTRE_CFG_RC_NO_ERR;
2401 char err_str[LNET_MAX_STR_LEN];
2402 char val[LNET_MAX_STR_LEN];
2404 snprintf(err_str, sizeof(err_str), "\"success\"");
2406 snprintf(val, sizeof(val), "%d", sen);
2408 rc = write_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
2409 1, strlen(val) + 1);
2411 snprintf(err_str, sizeof(err_str),
2412 "\"cannot configure health sensitivity: %s\"",
2415 cYAML_build_error(rc, seq_no, ADD_CMD, "health_sensitivity", err_str, err_rc);
2420 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc)
2422 int rc = LUSTRE_CFG_RC_NO_ERR;
2423 char err_str[LNET_MAX_STR_LEN];
2424 char val[LNET_MAX_STR_LEN];
2426 snprintf(err_str, sizeof(err_str), "\"success\"");
2428 snprintf(val, sizeof(val), "%d", timeout);
2430 rc = write_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
2431 1, strlen(val) + 1);
2433 snprintf(err_str, sizeof(err_str),
2434 "\"cannot configure transaction timeout: %s\"",
2437 cYAML_build_error(rc, seq_no, ADD_CMD, "transaction_timeout", err_str, err_rc);
2442 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc)
2444 int rc = LUSTRE_CFG_RC_NO_ERR;
2445 char err_str[LNET_MAX_STR_LEN];
2446 char val[LNET_MAX_STR_LEN];
2448 snprintf(err_str, sizeof(err_str), "\"success\"");
2450 snprintf(val, sizeof(val), "%d", count);
2452 rc = write_sysfs_file(modparam_path, "lnet_retry_count", val,
2453 1, strlen(val) + 1);
2455 snprintf(err_str, sizeof(err_str),
2456 "\"cannot configure retry count: %s\"",
2459 cYAML_build_error(rc, seq_no, ADD_CMD, "retry_count", err_str, err_rc);
2464 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2466 int rc = LUSTRE_CFG_RC_NO_ERR;
2467 char err_str[LNET_MAX_STR_LEN];
2468 char val[LNET_MAX_STR_LEN];
2470 snprintf(err_str, sizeof(err_str), "\"success\"");
2472 snprintf(val, sizeof(val), "%d", max);
2474 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2475 1, strlen(val) + 1);
2477 snprintf(err_str, sizeof(err_str),
2478 "\"cannot configure max interfaces: %s\"",
2481 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2486 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2488 int rc = LUSTRE_CFG_RC_NO_ERR;
2489 char err_str[LNET_MAX_STR_LEN];
2490 char val[LNET_MAX_STR_LEN];
2492 snprintf(err_str, sizeof(err_str), "\"success\"");
2494 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2496 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2497 1, strlen(val) + 1);
2499 snprintf(err_str, sizeof(err_str),
2500 "\"cannot configure discovery: %s\"",
2503 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2509 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
2510 struct cYAML **err_rc)
2512 int rc = LUSTRE_CFG_RC_NO_ERR;
2513 char err_str[LNET_MAX_STR_LEN];
2514 char val[LNET_MAX_STR_LEN];
2516 snprintf(err_str, sizeof(err_str), "\"success\"");
2518 snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
2520 rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
2521 1, strlen(val) + 1);
2523 snprintf(err_str, sizeof(err_str),
2524 "\"cannot configure drop asym route: %s\"",
2527 cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
2534 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2536 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2537 "numa_range", seq_no, err_rc);
2540 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2541 struct cYAML **err_rc)
2543 struct lnet_ioctl_config_data data;
2544 int rc = LUSTRE_CFG_RC_NO_ERR;
2545 char err_str[LNET_MAX_STR_LEN];
2547 snprintf(err_str, sizeof(err_str), "\"success\"");
2549 /* -1 indicates to ignore changes to this field */
2550 if (tiny < -1 || small < -1 || large < -1) {
2553 "\"tiny, small and large must be >= 0\"");
2554 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2558 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2559 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2560 data.cfg_config_u.cfg_buffers.buf_small = small;
2561 data.cfg_config_u.cfg_buffers.buf_large = large;
2563 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2568 "\"cannot configure buffers: %s\"", strerror(errno));
2573 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2578 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2579 struct cYAML **err_rc, bool backup)
2581 struct lnet_ioctl_config_data *data;
2582 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2583 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2586 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2587 int buf_count[LNET_NRBPOOLS] = {0};
2588 struct cYAML *root = NULL, *pools_node = NULL,
2589 *type_node = NULL, *item = NULL, *cpt = NULL,
2590 *first_seq = NULL, *buffers = NULL;
2592 char err_str[LNET_MAX_STR_LEN];
2593 char node_name[LNET_MAX_STR_LEN];
2596 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2598 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2602 data = (struct lnet_ioctl_config_data *)buf;
2604 root = cYAML_create_object(NULL, NULL);
2609 pools_node = cYAML_create_object(root, "routing");
2611 pools_node = cYAML_create_seq(root, "routing");
2612 if (pools_node == NULL)
2616 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2617 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2618 sizeof(struct lnet_ioctl_pool_cfg);
2619 data->cfg_count = i;
2621 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2629 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2632 goto calculate_buffers;
2634 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2635 item = cYAML_create_seq_item(pools_node);
2639 if (first_seq == NULL)
2642 cpt = cYAML_create_object(item, node_name);
2647 /* create the tree and print */
2648 for (j = 0; j < LNET_NRBPOOLS; j++) {
2650 type_node = cYAML_create_object(cpt, pools[j]);
2651 if (type_node == NULL)
2655 cYAML_create_number(type_node, "npages",
2656 pool_cfg->pl_pools[j].pl_npages)
2660 cYAML_create_number(type_node, "nbuffers",
2661 pool_cfg->pl_pools[j].
2662 pl_nbuffers) == NULL)
2665 cYAML_create_number(type_node, "credits",
2666 pool_cfg->pl_pools[j].
2667 pl_credits) == NULL)
2670 cYAML_create_number(type_node, "mincredits",
2671 pool_cfg->pl_pools[j].
2672 pl_mincredits) == NULL)
2674 /* keep track of the total count for each of the
2675 * tiny, small and large buffers */
2676 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2680 if (pool_cfg != NULL) {
2682 if (cYAML_create_number(pools_node, "enable",
2683 pool_cfg->pl_routing) ==
2687 goto add_buffer_section;
2690 item = cYAML_create_seq_item(pools_node);
2694 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2700 /* create a buffers entry in the show. This is necessary so that
2701 * if the YAML output is used to configure a node, the buffer
2702 * configuration takes hold */
2703 buffers = cYAML_create_object(root, "buffers");
2704 if (buffers == NULL)
2707 for (i = 0; i < LNET_NRBPOOLS; i++) {
2708 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2712 if (show_rc == NULL)
2713 cYAML_print_tree(root);
2715 if (l_errno != ENOENT) {
2718 "\"cannot get routing information: %s\"",
2723 rc = LUSTRE_CFG_RC_NO_ERR;
2725 snprintf(err_str, sizeof(err_str), "\"success\"");
2726 rc = LUSTRE_CFG_RC_NO_ERR;
2730 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2731 cYAML_free_tree(root);
2732 } else if (show_rc != NULL && *show_rc != NULL) {
2733 struct cYAML *routing_node;
2734 /* there should exist only one routing block and one
2735 * buffers block. If there already exists a previous one
2736 * then don't add another */
2737 routing_node = cYAML_get_object_item(*show_rc, "routing");
2738 if (routing_node == NULL) {
2739 cYAML_insert_sibling((*show_rc)->cy_child,
2743 cYAML_free_tree(root);
2749 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2754 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2755 struct cYAML **show_rc, struct cYAML **err_rc,
2759 * TODO: This function is changing in a future patch to accommodate
2760 * PEER_LIST and proper filtering on any nid of the peer
2762 struct lnet_ioctl_peer_cfg peer_info;
2763 struct lnet_peer_ni_credit_info *lpni_cri;
2764 struct lnet_ioctl_element_stats *lpni_stats;
2765 struct lnet_ioctl_element_msg_stats *msg_stats;
2766 struct lnet_ioctl_peer_ni_hstats *hstats;
2768 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2773 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2774 *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
2775 *msg_statistics = NULL, *statistics = NULL,
2777 char err_str[LNET_MAX_STR_LEN];
2778 struct lnet_process_id *list = NULL;
2783 snprintf(err_str, sizeof(err_str),
2784 "\"out of memory\"");
2786 /* create struct cYAML root object */
2787 root = cYAML_create_object(NULL, NULL);
2791 peer_root = cYAML_create_seq(root, "peer");
2792 if (peer_root == NULL)
2796 size = count * sizeof(struct lnet_process_id);
2797 list = malloc(size);
2803 list[0].nid = libcfs_str2nid(knid);
2807 memset(&peer_info, 0, sizeof(peer_info));
2808 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2809 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2810 peer_info.prcfg_size = size;
2811 peer_info.prcfg_bulk = list;
2814 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2816 count = peer_info.prcfg_count;
2820 if (l_errno != E2BIG) {
2823 "\"cannot get peer list: %s\"",
2829 size = peer_info.prcfg_size;
2830 list = malloc(size);
2839 data = malloc(size);
2845 for (i = 0; i < count; i++) {
2847 memset(&peer_info, 0, sizeof(peer_info));
2848 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2849 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2850 peer_info.prcfg_prim_nid = list[i].nid;
2851 peer_info.prcfg_size = size;
2852 peer_info.prcfg_bulk = data;
2855 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2860 if (l_errno != E2BIG) {
2863 "\"cannot get peer information: %s\"",
2869 size = peer_info.prcfg_size;
2870 data = malloc(size);
2878 peer = cYAML_create_seq_item(peer_root);
2882 if (first_seq == NULL)
2885 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2886 if (cYAML_create_string(peer, "primary nid",
2887 libcfs_nid2str(pnid))
2890 if (cYAML_create_string(peer, "Multi-Rail",
2891 peer_info.prcfg_mr ? "True" : "False")
2895 * print out the state of the peer only if details are
2900 cYAML_create_number(peer, "peer state",
2901 peer_info.prcfg_state)
2906 tmp = cYAML_create_seq(peer, "peer ni");
2911 for (j = 0; j < peer_info.prcfg_count; j++) {
2913 lpni_cri = (void*)nidp + sizeof(nidp);
2914 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2915 msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
2916 hstats = (void *)msg_stats + sizeof(*msg_stats);
2917 lpni_data = (void *)hstats + sizeof(*hstats);
2919 peer_ni = cYAML_create_seq_item(tmp);
2920 if (peer_ni == NULL)
2923 if (cYAML_create_string(peer_ni, "nid",
2924 libcfs_nid2str(*nidp))
2931 if (cYAML_create_string(peer_ni, "state",
2932 lpni_cri->cr_aliveness)
2939 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2940 lpni_cri->cr_ni_peer_tx_credits)
2944 if (cYAML_create_number(peer_ni, "available_tx_credits",
2945 lpni_cri->cr_peer_tx_credits)
2949 if (cYAML_create_number(peer_ni, "min_tx_credits",
2950 lpni_cri->cr_peer_min_tx_credits)
2954 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2955 lpni_cri->cr_peer_tx_qnob)
2959 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2960 lpni_cri->cr_peer_rtr_credits)
2964 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2965 lpni_cri->cr_peer_min_rtr_credits)
2969 if (cYAML_create_number(peer_ni, "refcount",
2970 lpni_cri->cr_refcount) == NULL)
2973 statistics = cYAML_create_object(peer_ni, "statistics");
2974 if (statistics == NULL)
2977 if (cYAML_create_number(statistics, "send_count",
2978 lpni_stats->iel_send_count)
2982 if (cYAML_create_number(statistics, "recv_count",
2983 lpni_stats->iel_recv_count)
2987 if (cYAML_create_number(statistics, "drop_count",
2988 lpni_stats->iel_drop_count)
2995 for (k = 0; k < 3; k++) {
2996 struct lnet_ioctl_comm_count *counts;
2998 msg_statistics = cYAML_create_object(peer_ni,
2999 (char *) gmsg_stat_names[k]);
3000 if (msg_statistics == NULL)
3003 counts = get_counts(msg_stats, k);
3007 if (!add_msg_stats_to_yaml_blk(msg_statistics,
3012 yhstats = cYAML_create_object(peer_ni, "health stats");
3015 if (cYAML_create_number(yhstats, "health value",
3016 hstats->hlpni_health_value)
3019 if (cYAML_create_number(yhstats, "dropped",
3020 hstats->hlpni_remote_dropped)
3023 if (cYAML_create_number(yhstats, "timeout",
3024 hstats->hlpni_remote_timeout)
3027 if (cYAML_create_number(yhstats, "error",
3028 hstats->hlpni_remote_error)
3031 if (cYAML_create_number(yhstats, "network timeout",
3032 hstats->hlpni_network_timeout)
3038 /* print output iff show_rc is not provided */
3039 if (show_rc == NULL)
3040 cYAML_print_tree(root);
3042 snprintf(err_str, sizeof(err_str), "\"success\"");
3043 rc = LUSTRE_CFG_RC_NO_ERR;
3048 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
3049 cYAML_free_tree(root);
3050 } else if (show_rc != NULL && *show_rc != NULL) {
3051 struct cYAML *show_node;
3052 /* find the peer node, if one doesn't exist then
3053 * insert one. Otherwise add to the one there
3055 show_node = cYAML_get_object_item(*show_rc,
3057 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3058 cYAML_insert_child(show_node, first_seq);
3061 } else if (show_node == NULL) {
3062 cYAML_insert_sibling((*show_rc)->cy_child,
3066 cYAML_free_tree(root);
3072 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3078 int lustre_lnet_list_peer(int seq_no,
3079 struct cYAML **show_rc, struct cYAML **err_rc)
3081 struct lnet_ioctl_peer_cfg peer_info;
3082 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3087 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
3088 char err_str[LNET_MAX_STR_LEN];
3089 struct lnet_process_id *list = NULL;
3091 snprintf(err_str, sizeof(err_str),
3092 "\"out of memory\"");
3094 memset(&peer_info, 0, sizeof(peer_info));
3096 /* create struct cYAML root object */
3097 root = cYAML_create_object(NULL, NULL);
3101 list_root = cYAML_create_seq(root, "peer list");
3102 if (list_root == NULL)
3106 size = count * sizeof(struct lnet_process_id);
3107 list = malloc(size);
3113 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
3114 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
3115 peer_info.prcfg_size = size;
3116 peer_info.prcfg_bulk = list;
3119 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
3120 count = peer_info.prcfg_count;
3124 if (l_errno != E2BIG) {
3127 "\"cannot get peer list: %s\"",
3133 size = peer_info.prcfg_size;
3134 list = malloc(size);
3141 /* count is now the actual number of ids in the list. */
3142 for (i = 0; i < count; i++) {
3143 if (cYAML_create_string(list_root, "nid",
3144 libcfs_nid2str(list[i].nid))
3149 /* print output iff show_rc is not provided */
3150 if (show_rc == NULL)
3151 cYAML_print_tree(root);
3153 snprintf(err_str, sizeof(err_str), "\"success\"");
3154 rc = LUSTRE_CFG_RC_NO_ERR;
3159 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3160 cYAML_free_tree(root);
3161 } else if (show_rc != NULL && *show_rc != NULL) {
3162 struct cYAML *show_node;
3163 /* find the peer node, if one doesn't exist then
3164 * insert one. Otherwise add to the one there
3166 show_node = cYAML_get_object_item(*show_rc,
3168 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3169 cYAML_insert_child(show_node, first_seq);
3172 } else if (show_node == NULL) {
3173 cYAML_insert_sibling((*show_rc)->cy_child,
3177 cYAML_free_tree(root);
3183 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
3189 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
3192 struct cYAML *show_node;
3194 show_node = cYAML_get_object_item(show_rc, "global");
3195 if (show_node != NULL)
3196 cYAML_insert_sibling(show_node->cy_child,
3199 cYAML_insert_sibling(show_rc->cy_child,
3204 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
3205 char *name, __u32 value,
3206 struct cYAML **show_rc,
3207 struct cYAML **err_rc, int err)
3209 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3210 struct cYAML *root = NULL, *global = NULL;
3217 root = cYAML_create_object(NULL, NULL);
3221 global = cYAML_create_object(root, "global");
3225 if (cYAML_create_number(global, name,
3229 if (show_rc == NULL)
3230 cYAML_print_tree(root);
3232 snprintf(err_str, err_len, "\"success\"");
3234 rc = LUSTRE_CFG_RC_NO_ERR;
3237 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3238 cYAML_free_tree(root);
3239 } else if (show_rc != NULL && *show_rc != NULL) {
3240 add_to_global(*show_rc, global, root);
3245 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
3250 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
3251 struct cYAML **show_rc,
3252 struct cYAML **err_rc)
3254 struct lnet_ioctl_set_value data;
3257 char err_str[LNET_MAX_STR_LEN];
3259 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3261 LIBCFS_IOC_INIT_V2(data, sv_hdr);
3263 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
3268 "\"cannot get %s: %s\"",
3269 name, strerror(l_errno));
3272 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
3273 data.sv_value, show_rc, err_rc, l_errno);
3276 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
3277 struct cYAML **err_rc)
3279 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3280 char val[LNET_MAX_STR_LEN];
3281 int intrv = -1, l_errno = 0;
3282 char err_str[LNET_MAX_STR_LEN];
3284 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3286 rc = read_sysfs_file(modparam_path, "lnet_recovery_interval", val,
3290 snprintf(err_str, sizeof(err_str),
3291 "\"cannot get recovery interval: %d\"", rc);
3296 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3297 "recovery_interval", intrv, show_rc,
3301 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
3302 struct cYAML **err_rc)
3304 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3305 char val[LNET_MAX_STR_LEN];
3306 int sen = -1, l_errno = 0;
3307 char err_str[LNET_MAX_STR_LEN];
3309 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3311 rc = read_sysfs_file(modparam_path, "lnet_health_sensitivity", val,
3315 snprintf(err_str, sizeof(err_str),
3316 "\"cannot get health sensitivity: %d\"", rc);
3321 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3322 "health_sensitivity", sen, show_rc,
3326 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
3327 struct cYAML **err_rc)
3329 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3330 char val[LNET_MAX_STR_LEN];
3331 int sen = -1, l_errno = 0;
3332 char err_str[LNET_MAX_STR_LEN];
3334 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3336 rc = read_sysfs_file(modparam_path, "router_sensitivity_percentage", val,
3340 snprintf(err_str, sizeof(err_str),
3341 "\"cannot get router sensitivity percentage: %d\"", rc);
3346 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3347 "router_sensitivity", sen, show_rc,
3351 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
3352 struct cYAML **err_rc)
3354 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3355 char val[LNET_MAX_STR_LEN];
3356 int tto = -1, l_errno = 0;
3357 char err_str[LNET_MAX_STR_LEN];
3359 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3361 rc = read_sysfs_file(modparam_path, "lnet_transaction_timeout", val,
3365 snprintf(err_str, sizeof(err_str),
3366 "\"cannot get transaction timeout: %d\"", rc);
3371 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3372 "transaction_timeout", tto, show_rc,
3376 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
3377 struct cYAML **err_rc)
3379 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3380 char val[LNET_MAX_STR_LEN];
3381 int retry_count = -1, l_errno = 0;
3382 char err_str[LNET_MAX_STR_LEN];
3384 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3386 rc = read_sysfs_file(modparam_path, "lnet_retry_count", val,
3390 snprintf(err_str, sizeof(err_str),
3391 "\"cannot get retry count: %d\"", rc);
3393 retry_count = atoi(val);
3396 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3397 "retry_count", retry_count, show_rc,
3401 int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no,
3402 struct cYAML **show_rc, struct cYAML **err_rc)
3404 struct lnet_ioctl_recovery_list nid_list;
3405 struct cYAML *root = NULL, *nids = NULL;
3407 char err_str[LNET_MAX_STR_LEN];
3409 snprintf(err_str, sizeof(err_str), "failed to print recovery queue\n");
3411 LIBCFS_IOC_INIT_V2(nid_list, rlst_hdr);
3412 nid_list.rlst_type = type;
3414 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_RECOVERY_QUEUE, &nid_list);
3420 if (nid_list.rlst_num_nids == 0)
3423 root = cYAML_create_object(NULL, NULL);
3427 nids = cYAML_create_object(root, name);
3433 for (i = 0; i < nid_list.rlst_num_nids; i++) {
3434 char nidenum[LNET_MAX_STR_LEN];
3435 snprintf(nidenum, sizeof(nidenum), "nid-%d", i);
3436 if (!cYAML_create_string(nids, nidenum,
3437 libcfs_nid2str(nid_list.rlst_nid_array[i])))
3441 snprintf(err_str, sizeof(err_str), "success\n");
3446 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3447 cYAML_free_tree(root);
3448 } else if (show_rc != NULL && *show_rc != NULL) {
3449 struct cYAML *show_node;
3450 /* find the net node, if one doesn't exist
3451 * then insert one. Otherwise add to the one there
3453 show_node = cYAML_get_object_item(*show_rc, name);
3454 if (show_node != NULL && cYAML_is_sequence(show_node)) {
3455 cYAML_insert_child(show_node, nids);
3458 } else if (show_node == NULL) {
3459 cYAML_insert_sibling((*show_rc)->cy_child,
3463 cYAML_free_tree(root);
3469 cYAML_build_error(rc, seq_no, SHOW_CMD, name, err_str, err_rc);
3474 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
3475 struct cYAML **err_rc)
3477 return show_recovery_queue(LNET_HEALTH_TYPE_LOCAL_NI, "local NI recovery",
3478 seq_no, show_rc, err_rc);
3481 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
3482 struct cYAML **err_rc)
3484 return show_recovery_queue(LNET_HEALTH_TYPE_PEER_NI, "peer NI recovery",
3485 seq_no, show_rc, err_rc);
3488 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
3489 struct cYAML **err_rc)
3491 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3492 char val[LNET_MAX_STR_LEN];
3493 int max_intf = -1, l_errno = 0;
3494 char err_str[LNET_MAX_STR_LEN];
3496 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3498 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
3502 snprintf(err_str, sizeof(err_str),
3503 "\"cannot get max interfaces: %d\"", rc);
3505 max_intf = atoi(val);
3508 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3509 "max_intf", max_intf, show_rc,
3513 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
3514 struct cYAML **err_rc)
3516 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3517 char val[LNET_MAX_STR_LEN];
3518 int discovery = -1, l_errno = 0;
3519 char err_str[LNET_MAX_STR_LEN];
3521 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3523 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
3527 snprintf(err_str, sizeof(err_str),
3528 "\"cannot get discovery setting: %d\"", rc);
3531 * The kernel stores a discovery disabled value. User space
3532 * shows whether discovery is enabled. So the value must be
3535 discovery = !atoi(val);
3538 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3539 "discovery", discovery, show_rc,
3543 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
3544 struct cYAML **err_rc)
3546 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3547 char val[LNET_MAX_STR_LEN];
3548 int drop_asym_route = -1, l_errno = 0;
3549 char err_str[LNET_MAX_STR_LEN];
3551 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3553 rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
3557 snprintf(err_str, sizeof(err_str),
3558 "\"cannot get drop asym route setting: %d\"", rc);
3560 drop_asym_route = atoi(val);
3563 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
3564 "drop_asym_route", drop_asym_route,
3565 show_rc, err_rc, l_errno);
3568 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
3569 struct cYAML **err_rc)
3571 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
3572 "numa_range", show_rc, err_rc);
3575 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
3576 struct cYAML **err_rc)
3578 struct lnet_ioctl_lnet_stats data;
3579 struct lnet_counters *cntrs;
3582 char err_str[LNET_MAX_STR_LEN];
3583 struct cYAML *root = NULL, *stats = NULL;
3585 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
3587 LIBCFS_IOC_INIT_V2(data, st_hdr);
3589 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
3594 "\"cannot get lnet statistics: %s\"",
3600 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3602 cntrs = &data.st_cntrs;
3604 root = cYAML_create_object(NULL, NULL);
3608 stats = cYAML_create_object(root, "statistics");
3612 if (!cYAML_create_number(stats, "msgs_alloc",
3613 cntrs->lct_common.lcc_msgs_alloc))
3616 if (!cYAML_create_number(stats, "msgs_max",
3617 cntrs->lct_common.lcc_msgs_max))
3620 if (!cYAML_create_number(stats, "rst_alloc",
3621 cntrs->lct_health.lch_rst_alloc))
3624 if (!cYAML_create_number(stats, "errors",
3625 cntrs->lct_common.lcc_errors))
3628 if (!cYAML_create_number(stats, "send_count",
3629 cntrs->lct_common.lcc_send_count))
3632 if (!cYAML_create_number(stats, "resend_count",
3633 cntrs->lct_health.lch_resend_count))
3636 if (!cYAML_create_number(stats, "response_timeout_count",
3637 cntrs->lct_health.lch_response_timeout_count))
3640 if (!cYAML_create_number(stats, "local_interrupt_count",
3641 cntrs->lct_health.lch_local_interrupt_count))
3644 if (!cYAML_create_number(stats, "local_dropped_count",
3645 cntrs->lct_health.lch_local_dropped_count))
3648 if (!cYAML_create_number(stats, "local_aborted_count",
3649 cntrs->lct_health.lch_local_aborted_count))
3652 if (!cYAML_create_number(stats, "local_no_route_count",
3653 cntrs->lct_health.lch_local_no_route_count))
3656 if (!cYAML_create_number(stats, "local_timeout_count",
3657 cntrs->lct_health.lch_local_timeout_count))
3660 if (!cYAML_create_number(stats, "local_error_count",
3661 cntrs->lct_health.lch_local_error_count))
3664 if (!cYAML_create_number(stats, "remote_dropped_count",
3665 cntrs->lct_health.lch_remote_dropped_count))
3668 if (!cYAML_create_number(stats, "remote_error_count",
3669 cntrs->lct_health.lch_remote_error_count))
3672 if (!cYAML_create_number(stats, "remote_timeout_count",
3673 cntrs->lct_health.lch_remote_timeout_count))
3676 if (!cYAML_create_number(stats, "network_timeout_count",
3677 cntrs->lct_health.lch_network_timeout_count))
3680 if (!cYAML_create_number(stats, "recv_count",
3681 cntrs->lct_common.lcc_recv_count))
3684 if (!cYAML_create_number(stats, "route_count",
3685 cntrs->lct_common.lcc_route_count))
3688 if (!cYAML_create_number(stats, "drop_count",
3689 cntrs->lct_common.lcc_drop_count))
3692 if (!cYAML_create_number(stats, "send_length",
3693 cntrs->lct_common.lcc_send_length))
3696 if (!cYAML_create_number(stats, "recv_length",
3697 cntrs->lct_common.lcc_recv_length))
3700 if (!cYAML_create_number(stats, "route_length",
3701 cntrs->lct_common.lcc_route_length))
3704 if (!cYAML_create_number(stats, "drop_length",
3705 cntrs->lct_common.lcc_drop_length))
3709 cYAML_print_tree(root);
3711 snprintf(err_str, sizeof(err_str), "\"success\"");
3712 rc = LUSTRE_CFG_RC_NO_ERR;
3714 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
3715 cYAML_free_tree(root);
3716 } else if (show_rc != NULL && *show_rc != NULL) {
3717 cYAML_insert_sibling((*show_rc)->cy_child,
3724 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
3729 typedef int (*cmd_handler_t)(struct cYAML *tree,
3730 struct cYAML **show_rc,
3731 struct cYAML **err_rc);
3733 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
3734 struct cYAML **err_rc)
3736 struct cYAML *net, *gw, *hop, *prio, *sen, *seq_no;
3738 net = cYAML_get_object_item(tree, "net");
3739 gw = cYAML_get_object_item(tree, "gateway");
3740 hop = cYAML_get_object_item(tree, "hop");
3741 prio = cYAML_get_object_item(tree, "priority");
3742 sen = cYAML_get_object_item(tree, "health_sensitivity");
3743 seq_no = cYAML_get_object_item(tree, "seq_no");
3745 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
3746 (gw) ? gw->cy_valuestring : NULL,
3747 (hop) ? hop->cy_valueint : -1,
3748 (prio) ? prio->cy_valueint : -1,
3749 (sen) ? sen->cy_valueint : -1,
3750 (seq_no) ? seq_no->cy_valueint : -1,
3756 * 0: <intf_name>['['<expr>']']
3757 * 1: <intf_name>['['<expr>']']
3759 static int yaml_copy_intf_info(struct cYAML *intf_tree,
3760 struct lnet_dlc_network_descr *nw_descr)
3762 struct cYAML *child = NULL;
3763 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3764 struct lnet_dlc_intf_descr *intf_descr, *tmp;
3766 if (intf_tree == NULL || nw_descr == NULL)
3767 return LUSTRE_CFG_RC_BAD_PARAM;
3769 /* now grab all the interfaces and their cpts */
3770 child = intf_tree->cy_child;
3771 while (child != NULL) {
3772 if (child->cy_valuestring == NULL) {
3773 child = child->cy_next;
3777 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3780 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3781 child->cy_valuestring,
3782 strlen(child->cy_valuestring));
3783 if (rc != LUSTRE_CFG_RC_NO_ERR)
3787 child = child->cy_next;
3791 return LUSTRE_CFG_RC_MISSING_PARAM;
3796 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3798 list_del(&intf_descr->intf_on_network);
3799 free_intf_descr(intf_descr);
3806 yaml_extract_cmn_tunables(struct cYAML *tree,
3807 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3808 struct cfs_expr_list **global_cpts)
3810 struct cYAML *tun, *item, *smp;
3813 tun = cYAML_get_object_item(tree, "tunables");
3815 item = cYAML_get_object_item(tun, "peer_timeout");
3817 tunables->lct_peer_timeout = item->cy_valueint;
3818 item = cYAML_get_object_item(tun, "peer_credits");
3820 tunables->lct_peer_tx_credits = item->cy_valueint;
3821 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3823 tunables->lct_peer_rtr_credits = item->cy_valueint;
3824 item = cYAML_get_object_item(tun, "credits");
3826 tunables->lct_max_tx_credits = item->cy_valueint;
3827 smp = cYAML_get_object_item(tun, "CPT");
3829 rc = cfs_expr_list_parse(smp->cy_valuestring,
3830 strlen(smp->cy_valuestring),
3831 0, UINT_MAX, global_cpts);
3833 *global_cpts = NULL;
3843 yaml_extract_tunables(struct cYAML *tree,
3844 struct lnet_ioctl_config_lnd_tunables *tunables,
3845 struct cfs_expr_list **global_cpts,
3850 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3856 lustre_yaml_extract_lnd_tunables(tree, net_type,
3864 * - net type: <net>[<NUM>]
3866 * - nid: <ip>@<net>[<NUM>]
3869 * 0: <intf_name>['['<expr>']']
3870 * 1: <intf_name>['['<expr>']']
3872 * peer_timeout: <NUM>
3873 * peer_credits: <NUM>
3874 * peer_buffer_credits: <NUM>
3877 * peercredits_hiw: <NUM>
3878 * map_on_demand: <NUM>
3879 * concurrent_sends: <NUM>
3880 * fmr_pool_size: <NUM>
3881 * fmr_flush_trigger: <NUM>
3884 * At least one interface is required. If no interfaces are provided the
3885 * network interface can not be configured.
3887 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3888 struct cYAML **err_rc)
3890 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3892 int num_entries = 0, rc;
3893 struct lnet_dlc_network_descr nw_descr;
3894 struct cfs_expr_list *global_cpts = NULL;
3895 struct lnet_ioctl_config_lnd_tunables tunables;
3898 memset(&tunables, 0, sizeof(tunables));
3900 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3901 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3903 ip2net = cYAML_get_object_item(tree, "ip2net");
3904 net = cYAML_get_object_item(tree, "net type");
3906 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3908 nw_descr.nw_id = LOLND;
3911 * if neither net nor ip2nets are present, then we can not
3912 * configure the network.
3914 if (!net && !ip2net)
3915 return LUSTRE_CFG_RC_MISSING_PARAM;
3917 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3918 if (local_nis == NULL)
3919 return LUSTRE_CFG_RC_MISSING_PARAM;
3921 if (!cYAML_is_sequence(local_nis))
3922 return LUSTRE_CFG_RC_BAD_PARAM;
3924 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3925 intf = cYAML_get_object_item(item, "interfaces");
3928 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3929 if (num_entries <= 0) {
3930 cYAML_build_error(num_entries, -1, "ni", "add",
3931 "bad interface list",
3933 return LUSTRE_CFG_RC_BAD_PARAM;
3937 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3938 LNET_NETTYP(nw_descr.nw_id));
3939 seq_no = cYAML_get_object_item(tree, "seq_no");
3941 rc = lustre_lnet_config_ni(&nw_descr,
3943 (ip2net) ? ip2net->cy_valuestring : NULL,
3944 (found) ? &tunables: NULL,
3945 (seq_no) ? seq_no->cy_valueint : -1,
3948 if (global_cpts != NULL)
3949 cfs_expr_list_free(global_cpts);
3956 * - net-spec: <tcp|o2ib|gni>[NUM]
3958 * 0: <intf name>['['<expr>']']
3959 * 1: <intf name>['['<expr>']']
3961 * 0: <expr.expr.expr.expr>
3962 * 1: <expr.expr.expr.expr>
3964 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3965 struct cYAML **show_rc,
3966 struct cYAML **err_rc)
3968 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3970 struct lustre_lnet_ip2nets ip2nets;
3971 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3973 int rc = LUSTRE_CFG_RC_NO_ERR;
3974 struct cfs_expr_list *global_cpts = NULL;
3975 struct cfs_expr_list *el, *el_tmp;
3976 struct lnet_ioctl_config_lnd_tunables tunables;
3977 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3980 memset(&tunables, 0, sizeof(tunables));
3982 /* initialize all lists */
3983 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
3984 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
3985 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
3987 net = cYAML_get_object_item(tree, "net-spec");
3989 return LUSTRE_CFG_RC_BAD_PARAM;
3991 if (net != NULL && net->cy_valuestring == NULL)
3992 return LUSTRE_CFG_RC_BAD_PARAM;
3994 /* assign the network id */
3995 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
3996 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
3997 return LUSTRE_CFG_RC_BAD_PARAM;
3999 seq_no = cYAML_get_object_item(tree, "seq_no");
4001 intf = cYAML_get_object_item(tree, "interfaces");
4003 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
4005 return LUSTRE_CFG_RC_BAD_PARAM;
4008 ip_range = cYAML_get_object_item(tree, "ip-range");
4009 if (ip_range != NULL) {
4010 item = ip_range->cy_child;
4011 while (item != NULL) {
4012 if (item->cy_valuestring == NULL) {
4013 item = item->cy_next;
4017 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
4018 item->cy_valuestring);
4020 if (rc != LUSTRE_CFG_RC_NO_ERR)
4023 item = item->cy_next;
4027 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
4028 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
4030 rc = lustre_lnet_config_ip2nets(&ip2nets,
4031 (found) ? &tunables : NULL,
4033 (seq_no) ? seq_no->cy_valueint : -1,
4037 * don't stop because there was no match. Continue processing the
4038 * rest of the rules. If non-match then nothing is configured
4040 if (rc == LUSTRE_CFG_RC_NO_MATCH)
4041 rc = LUSTRE_CFG_RC_NO_ERR;
4043 list_for_each_entry_safe(intf_descr, intf_tmp,
4044 &ip2nets.ip2nets_net.nw_intflist,
4046 list_del(&intf_descr->intf_on_network);
4047 free_intf_descr(intf_descr);
4050 list_for_each_entry_safe(ip_range_descr, tmp,
4051 &ip2nets.ip2nets_ip_ranges,
4053 list_del(&ip_range_descr->ipr_entry);
4054 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
4056 list_del(&el->el_link);
4057 cfs_expr_list_free(el);
4059 free(ip_range_descr);
4065 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
4066 struct cYAML **err_rc)
4068 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
4070 int num_entries, rc;
4071 struct lnet_dlc_network_descr nw_descr;
4073 INIT_LIST_HEAD(&nw_descr.network_on_rule);
4074 INIT_LIST_HEAD(&nw_descr.nw_intflist);
4076 net = cYAML_get_object_item(tree, "net type");
4078 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
4080 local_nis = cYAML_get_object_item(tree, "local NI(s)");
4081 if (local_nis == NULL)
4082 return LUSTRE_CFG_RC_MISSING_PARAM;
4084 if (!cYAML_is_sequence(local_nis))
4085 return LUSTRE_CFG_RC_BAD_PARAM;
4087 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
4088 intf = cYAML_get_object_item(item, "interfaces");
4091 num_entries = yaml_copy_intf_info(intf, &nw_descr);
4092 if (num_entries <= 0) {
4093 cYAML_build_error(num_entries, -1, "ni", "add",
4094 "bad interface list",
4096 return LUSTRE_CFG_RC_BAD_PARAM;
4100 seq_no = cYAML_get_object_item(tree, "seq_no");
4102 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
4103 (seq_no) ? seq_no->cy_valueint : -1,
4109 /* Create a nidstring parseable by the nidstrings library from the nid
4110 * information encoded in the CYAML structure.
4111 * NOTE: Caller must free memory allocated to nidstr
4113 static int yaml_nids2nidstr(struct cYAML *nids_entry, char **nidstr,
4114 char *prim_nid, int cmd)
4116 int num_strs = 0, rc;
4117 size_t buf_size, buf_pos, nidstr_len = 0;
4119 struct cYAML *child = NULL, *entry = NULL;
4121 if (cYAML_is_sequence(nids_entry)) {
4122 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4123 entry = cYAML_get_object_item(child, "nid");
4124 /* don't count an empty entry */
4125 if (!entry || !entry->cy_valuestring)
4129 (strcmp(entry->cy_valuestring, prim_nid) == 0)) {
4130 if (cmd == LNETCTL_DEL_CMD) {
4132 * primary nid is present in the list of
4133 * nids so that means we want to delete
4134 * the entire peer, so no need to go
4135 * further. Just delete the entire peer.
4137 return LUSTRE_CFG_RC_NO_ERR;
4144 * + 1 for the space separating each string, and
4145 * accounts for the terminating null char
4147 nidstr_len += strlen(entry->cy_valuestring) + 1;
4152 if (num_strs == 0 && !prim_nid)
4153 return LUSTRE_CFG_RC_MISSING_PARAM;
4154 else if (num_strs == 0) /* Only the primary nid was given to add/del */
4155 return LUSTRE_CFG_RC_NO_ERR;
4157 buffer = malloc(nidstr_len);
4159 return LUSTRE_CFG_RC_OUT_OF_MEM;
4161 /* now grab all the nids */
4164 buf_size = nidstr_len;
4166 while (cYAML_get_next_seq_item(nids_entry, &child)) {
4167 entry = cYAML_get_object_item(child, "nid");
4168 if (!entry || !entry->cy_valuestring)
4172 (strcmp(entry->cy_valuestring, prim_nid) == 0))
4176 rc = snprintf(buffer + buf_pos, buf_size, " ");
4177 buf_pos += (rc < buf_size) ? rc : buf_size;
4178 buf_size = nidstr_len - buf_pos;
4181 rc = snprintf(buffer + buf_pos, buf_size, "%s",
4182 entry->cy_valuestring);
4183 buf_pos += (rc < buf_size) ? rc : buf_size;
4184 buf_size = nidstr_len - buf_pos;
4189 return LUSTRE_CFG_RC_NO_ERR;
4192 static int handle_yaml_peer_common(struct cYAML *tree, struct cYAML **show_rc,
4193 struct cYAML **err_rc, int cmd)
4195 int rc, num_nids = 0, seqn;
4197 char *nidstr = NULL, *prim_nidstr;
4198 char err_str[LNET_MAX_STR_LEN];
4199 struct cYAML *seq_no, *prim_nid, *mr, *peer_nis;
4200 lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
4202 seq_no = cYAML_get_object_item(tree, "seq_no");
4203 seqn = seq_no ? seq_no->cy_valueint : -1;
4205 prim_nid = cYAML_get_object_item(tree, "primary nid");
4206 prim_nidstr = prim_nid ? prim_nid->cy_valuestring : NULL;
4208 peer_nis = cYAML_get_object_item(tree, "peer ni");
4209 if (!(prim_nid || peer_nis)) {
4210 rc = LUSTRE_CFG_RC_BAD_PARAM;
4211 snprintf(err_str, LNET_MAX_STR_LEN,
4212 "Neither \"primary nid\" nor \"peer ni\" are defined");
4216 rc = yaml_nids2nidstr(peer_nis, &nidstr, prim_nidstr, cmd);
4217 if (rc == LUSTRE_CFG_RC_MISSING_PARAM) {
4218 snprintf(err_str, LNET_MAX_STR_LEN,
4219 "No nids defined in YAML block");
4221 } else if (rc == LUSTRE_CFG_RC_OUT_OF_MEM) {
4222 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
4224 } else if (rc != LUSTRE_CFG_RC_NO_ERR) {
4225 snprintf(err_str, LNET_MAX_STR_LEN,
4226 "Unrecognized error %d", rc);
4232 num_nids = lustre_lnet_parse_nidstr(nidstr, lnet_nidlist,
4233 LNET_MAX_NIDS_PER_PEER,
4241 if (cmd == LNETCTL_ADD_CMD) {
4242 mr = cYAML_get_object_item(tree, "Multi-Rail");
4244 if (mr && mr->cy_valuestring) {
4245 if (strcmp(mr->cy_valuestring, "False") == 0)
4247 else if (strcmp(mr->cy_valuestring, "True") != 0) {
4248 rc = LUSTRE_CFG_RC_BAD_PARAM;
4249 snprintf(err_str, LNET_MAX_STR_LEN,
4250 "Multi-Rail must be set to \"True\" or \"False\" found \"%s\"",
4251 mr->cy_valuestring);
4256 rc = lustre_lnet_config_peer_nidlist(prim_nidstr, lnet_nidlist,
4257 num_nids, mr_value, seqn,
4260 rc = lustre_lnet_del_peer_nidlist(prim_nidstr, lnet_nidlist,
4261 num_nids, seqn, err_rc);
4267 if (rc != LUSTRE_CFG_RC_NO_ERR)
4268 cYAML_build_error(rc, seqn, "peer",
4269 cmd == LNETCTL_ADD_CMD ? ADD_CMD : DEL_CMD,
4275 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
4276 struct cYAML **err_rc)
4278 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_ADD_CMD);
4281 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
4282 struct cYAML **err_rc)
4284 return handle_yaml_peer_common(tree, show_rc, err_rc, LNETCTL_DEL_CMD);
4287 static int handle_yaml_config_buffers(struct cYAML *tree,
4288 struct cYAML **show_rc,
4289 struct cYAML **err_rc)
4292 struct cYAML *tiny, *small, *large, *seq_no;
4294 tiny = cYAML_get_object_item(tree, "tiny");
4295 small = cYAML_get_object_item(tree, "small");
4296 large = cYAML_get_object_item(tree, "large");
4297 seq_no = cYAML_get_object_item(tree, "seq_no");
4299 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
4300 (small) ? small->cy_valueint : -1,
4301 (large) ? large->cy_valueint : -1,
4302 (seq_no) ? seq_no->cy_valueint : -1,
4308 static int handle_yaml_config_routing(struct cYAML *tree,
4309 struct cYAML **show_rc,
4310 struct cYAML **err_rc)
4312 int rc = LUSTRE_CFG_RC_NO_ERR;
4313 struct cYAML *seq_no, *enable;
4315 seq_no = cYAML_get_object_item(tree, "seq_no");
4316 enable = cYAML_get_object_item(tree, "enable");
4319 rc = lustre_lnet_enable_routing(enable->cy_valueint,
4321 seq_no->cy_valueint : -1,
4328 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
4329 struct cYAML **err_rc)
4333 struct cYAML *seq_no;
4335 net = cYAML_get_object_item(tree, "net");
4336 gw = cYAML_get_object_item(tree, "gateway");
4337 seq_no = cYAML_get_object_item(tree, "seq_no");
4339 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
4340 (gw) ? gw->cy_valuestring : NULL,
4341 (seq_no) ? seq_no->cy_valueint : -1,
4345 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
4346 struct cYAML **err_rc)
4348 struct cYAML *seq_no;
4350 seq_no = cYAML_get_object_item(tree, "seq_no");
4352 return lustre_lnet_enable_routing(0, (seq_no) ?
4353 seq_no->cy_valueint : -1,
4357 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
4358 struct cYAML **err_rc)
4364 struct cYAML *detail;
4365 struct cYAML *seq_no;
4367 net = cYAML_get_object_item(tree, "net");
4368 gw = cYAML_get_object_item(tree, "gateway");
4369 hop = cYAML_get_object_item(tree, "hop");
4370 prio = cYAML_get_object_item(tree, "priority");
4371 detail = cYAML_get_object_item(tree, "detail");
4372 seq_no = cYAML_get_object_item(tree, "seq_no");
4374 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
4375 (gw) ? gw->cy_valuestring : NULL,
4376 (hop) ? hop->cy_valueint : -1,
4377 (prio) ? prio->cy_valueint : -1,
4378 (detail) ? detail->cy_valueint : 0,
4379 (seq_no) ? seq_no->cy_valueint : -1,
4380 show_rc, err_rc, false);
4383 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
4384 struct cYAML **err_rc)
4386 struct cYAML *net, *detail, *seq_no;
4388 net = cYAML_get_object_item(tree, "net");
4389 detail = cYAML_get_object_item(tree, "detail");
4390 seq_no = cYAML_get_object_item(tree, "seq_no");
4392 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
4393 (detail) ? detail->cy_valueint : 0,
4394 (seq_no) ? seq_no->cy_valueint : -1,
4395 show_rc, err_rc, false);
4398 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
4399 struct cYAML **err_rc)
4401 struct cYAML *seq_no;
4403 seq_no = cYAML_get_object_item(tree, "seq_no");
4405 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
4406 show_rc, err_rc, false);
4409 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
4410 struct cYAML **err_rc)
4412 struct cYAML *seq_no, *nid, *detail;
4414 seq_no = cYAML_get_object_item(tree, "seq_no");
4415 detail = cYAML_get_object_item(tree, "detail");
4416 nid = cYAML_get_object_item(tree, "nid");
4418 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
4419 (detail) ? detail->cy_valueint : 0,
4420 (seq_no) ? seq_no->cy_valueint : -1,
4421 show_rc, err_rc, false);
4424 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
4425 struct cYAML **err_rc)
4427 struct cYAML *seq_no;
4429 seq_no = cYAML_get_object_item(tree, "seq_no");
4431 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
4435 static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
4436 struct cYAML **err_rc)
4438 struct cYAML *seq_no, *range;
4440 seq_no = cYAML_get_object_item(tree, "seq_no");
4441 range = cYAML_get_object_item(tree, "range");
4443 return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
4444 seq_no ? seq_no->cy_valueint : -1,
4448 static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
4449 struct cYAML **err_rc)
4451 struct cYAML *seq_no;
4453 seq_no = cYAML_get_object_item(tree, "seq_no");
4455 return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
4459 static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
4460 struct cYAML **err_rc)
4462 struct cYAML *seq_no;
4464 seq_no = cYAML_get_object_item(tree, "seq_no");
4466 return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
4470 static int handle_yaml_config_global_settings(struct cYAML *tree,
4471 struct cYAML **show_rc,
4472 struct cYAML **err_rc)
4474 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4475 *sen, *recov, *rsen, *drop_asym_route;
4478 seq_no = cYAML_get_object_item(tree, "seq_no");
4479 max_intf = cYAML_get_object_item(tree, "max_intf");
4481 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
4482 seq_no ? seq_no->cy_valueint
4486 numa = cYAML_get_object_item(tree, "numa_range");
4488 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
4489 seq_no ? seq_no->cy_valueint
4493 discovery = cYAML_get_object_item(tree, "discovery");
4495 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
4496 seq_no ? seq_no->cy_valueint
4500 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4501 if (drop_asym_route)
4502 rc = lustre_lnet_config_drop_asym_route(
4503 drop_asym_route->cy_valueint,
4504 seq_no ? seq_no->cy_valueint : -1,
4507 retry = cYAML_get_object_item(tree, "retry_count");
4509 rc = lustre_lnet_config_retry_count(retry->cy_valueint,
4510 seq_no ? seq_no->cy_valueint
4514 tto = cYAML_get_object_item(tree, "transaction_timeout");
4516 rc = lustre_lnet_config_transaction_to(tto->cy_valueint,
4517 seq_no ? seq_no->cy_valueint
4521 sen = cYAML_get_object_item(tree, "health_sensitivity");
4523 rc = lustre_lnet_config_hsensitivity(sen->cy_valueint,
4524 seq_no ? seq_no->cy_valueint
4528 recov = cYAML_get_object_item(tree, "recovery_interval");
4530 rc = lustre_lnet_config_recov_intrv(recov->cy_valueint,
4531 seq_no ? seq_no->cy_valueint
4535 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4537 rc = lustre_lnet_config_rtr_sensitivity(rsen->cy_valueint,
4538 seq_no ? seq_no->cy_valueint
4545 static int handle_yaml_del_global_settings(struct cYAML *tree,
4546 struct cYAML **show_rc,
4547 struct cYAML **err_rc)
4549 struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
4552 seq_no = cYAML_get_object_item(tree, "seq_no");
4553 max_intf = cYAML_get_object_item(tree, "max_intf");
4555 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
4556 seq_no ? seq_no->cy_valueint
4560 numa = cYAML_get_object_item(tree, "numa_range");
4562 rc = lustre_lnet_config_numa_range(0,
4563 seq_no ? seq_no->cy_valueint
4567 /* peer discovery is enabled by default */
4568 discovery = cYAML_get_object_item(tree, "discovery");
4570 rc = lustre_lnet_config_discovery(1,
4571 seq_no ? seq_no->cy_valueint
4575 /* asymmetrical route messages are accepted by default */
4576 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4577 if (drop_asym_route)
4578 rc = lustre_lnet_config_drop_asym_route(
4579 0, seq_no ? seq_no->cy_valueint : -1, err_rc);
4584 static int handle_yaml_show_global_settings(struct cYAML *tree,
4585 struct cYAML **show_rc,
4586 struct cYAML **err_rc)
4588 struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
4589 *sen, *recov, *rsen, *drop_asym_route;
4592 seq_no = cYAML_get_object_item(tree, "seq_no");
4593 max_intf = cYAML_get_object_item(tree, "max_intf");
4595 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
4599 numa = cYAML_get_object_item(tree, "numa_range");
4601 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
4605 discovery = cYAML_get_object_item(tree, "discovery");
4607 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
4611 drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
4612 if (drop_asym_route)
4613 rc = lustre_lnet_show_drop_asym_route(
4614 seq_no ? seq_no->cy_valueint : -1,
4617 retry = cYAML_get_object_item(tree, "retry_count");
4619 rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
4623 tto = cYAML_get_object_item(tree, "transaction_timeout");
4625 rc = lustre_lnet_show_transaction_to(seq_no ? seq_no->cy_valueint
4629 sen = cYAML_get_object_item(tree, "health_sensitivity");
4631 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4635 recov = cYAML_get_object_item(tree, "recovery_interval");
4637 rc = lustre_lnet_show_recov_intrv(seq_no ? seq_no->cy_valueint
4641 rsen = cYAML_get_object_item(tree, "router_sensitivity");
4643 rc = lustre_lnet_show_hsensitivity(seq_no ? seq_no->cy_valueint
4650 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
4651 struct cYAML **err_rc)
4653 struct cYAML *seq_no, *nid, *timeout;
4655 seq_no = cYAML_get_object_item(tree, "seq_no");
4656 nid = cYAML_get_object_item(tree, "primary nid");
4657 timeout = cYAML_get_object_item(tree, "timeout");
4659 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
4660 (timeout) ? timeout->cy_valueint : 1000,
4661 (seq_no) ? seq_no->cy_valueint : -1,
4665 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
4666 struct cYAML **err_rc)
4668 struct cYAML *seq_no, *nid, *force;
4670 seq_no = cYAML_get_object_item(tree, "seq_no");
4671 nid = cYAML_get_object_item(tree, "primary nid");
4672 force = cYAML_get_object_item(tree, "force");
4674 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
4675 (force) ? force->cy_valueint : 0,
4676 (seq_no) ? seq_no->cy_valueint : -1,
4680 static int handle_yaml_no_op()
4682 return LUSTRE_CFG_RC_NO_ERR;
4685 struct lookup_cmd_hdlr_tbl {
4690 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
4691 { .name = "route", .cb = handle_yaml_config_route },
4692 { .name = "net", .cb = handle_yaml_config_ni },
4693 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
4694 { .name = "peer", .cb = handle_yaml_config_peer },
4695 { .name = "routing", .cb = handle_yaml_config_routing },
4696 { .name = "buffers", .cb = handle_yaml_config_buffers },
4697 { .name = "statistics", .cb = handle_yaml_no_op },
4698 { .name = "global", .cb = handle_yaml_config_global_settings},
4699 { .name = "numa", .cb = handle_yaml_config_numa },
4700 { .name = "ping", .cb = handle_yaml_no_op },
4701 { .name = "discover", .cb = handle_yaml_no_op },
4704 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
4705 { .name = "route", .cb = handle_yaml_del_route },
4706 { .name = "net", .cb = handle_yaml_del_ni },
4707 { .name = "ip2nets", .cb = handle_yaml_no_op },
4708 { .name = "peer", .cb = handle_yaml_del_peer },
4709 { .name = "routing", .cb = handle_yaml_del_routing },
4710 { .name = "buffers", .cb = handle_yaml_no_op },
4711 { .name = "statistics", .cb = handle_yaml_no_op },
4712 { .name = "global", .cb = handle_yaml_del_global_settings},
4713 { .name = "numa", .cb = handle_yaml_del_numa },
4714 { .name = "ping", .cb = handle_yaml_no_op },
4715 { .name = "discover", .cb = handle_yaml_no_op },
4718 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
4719 { .name = "route", .cb = handle_yaml_show_route },
4720 { .name = "net", .cb = handle_yaml_show_net },
4721 { .name = "peer", .cb = handle_yaml_show_peers },
4722 { .name = "ip2nets", .cb = handle_yaml_no_op },
4723 { .name = "routing", .cb = handle_yaml_show_routing },
4724 { .name = "buffers", .cb = handle_yaml_show_routing },
4725 { .name = "statistics", .cb = handle_yaml_show_stats },
4726 { .name = "global", .cb = handle_yaml_show_global_settings},
4727 { .name = "numa", .cb = handle_yaml_show_numa },
4728 { .name = "ping", .cb = handle_yaml_no_op },
4729 { .name = "discover", .cb = handle_yaml_no_op },
4732 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
4733 { .name = "route", .cb = handle_yaml_no_op },
4734 { .name = "net", .cb = handle_yaml_no_op },
4735 { .name = "peer", .cb = handle_yaml_no_op },
4736 { .name = "ip2nets", .cb = handle_yaml_no_op },
4737 { .name = "routing", .cb = handle_yaml_no_op },
4738 { .name = "buffers", .cb = handle_yaml_no_op },
4739 { .name = "statistics", .cb = handle_yaml_no_op },
4740 { .name = "global", .cb = handle_yaml_no_op },
4741 { .name = "numa", .cb = handle_yaml_no_op },
4742 { .name = "ping", .cb = handle_yaml_ping },
4743 { .name = "discover", .cb = handle_yaml_discover },
4746 static cmd_handler_t lookup_fn(char *key,
4747 struct lookup_cmd_hdlr_tbl *tbl)
4753 for (i = 0; tbl[i].name != NULL; i++) {
4754 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
4761 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
4762 struct cYAML **show_rc, struct cYAML **err_rc)
4764 struct cYAML *tree, *item = NULL, *head, *child;
4766 char err_str[LNET_MAX_STR_LEN];
4767 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
4769 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
4771 return LUSTRE_CFG_RC_BAD_PARAM;
4773 child = tree->cy_child;
4774 while (child != NULL) {
4775 cb = lookup_fn(child->cy_string, table);
4777 snprintf(err_str, sizeof(err_str),
4778 "\"call back for '%s' not found\"",
4780 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
4781 "yaml", "helper", err_str, err_rc);
4785 if (cYAML_is_sequence(child)) {
4786 while ((head = cYAML_get_next_seq_item(child, &item))
4788 rc = cb(head, show_rc, err_rc);
4789 if (rc != LUSTRE_CFG_RC_NO_ERR)
4793 rc = cb(child, show_rc, err_rc);
4794 if (rc != LUSTRE_CFG_RC_NO_ERR)
4798 child = child->cy_next;
4802 cYAML_free_tree(tree);
4807 int lustre_yaml_config(char *f, struct cYAML **err_rc)
4809 return lustre_yaml_cb_helper(f, lookup_config_tbl,
4813 int lustre_yaml_del(char *f, struct cYAML **err_rc)
4815 return lustre_yaml_cb_helper(f, lookup_del_tbl,
4819 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4821 return lustre_yaml_cb_helper(f, lookup_show_tbl,
4825 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
4827 return lustre_yaml_cb_helper(f, lookup_exec_tbl,