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, 2016, 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
43 #include <sys/ioctl.h>
45 #include <libcfs/util/ioctl.h>
46 #include <lnet/lnetctl.h>
47 #include <lnet/socklnd.h>
49 #include <lnet/lnet.h>
50 #include <libcfs/libcfs_string.h>
51 #include <sys/types.h>
53 #include "liblnetconfig.h"
56 #define CONFIG_CMD "configure"
57 #define UNCONFIG_CMD "unconfigure"
60 #define SHOW_CMD "show"
64 * lustre_lnet_ip_range_descr
65 * Describes an IP range.
66 * Each octect is an expression
68 struct lustre_lnet_ip_range_descr {
69 struct list_head ipr_entry;
70 struct list_head ipr_expr;
75 * Describes an ip2nets rule. This can be on a list of rules.
77 struct lustre_lnet_ip2nets {
78 struct lnet_dlc_network_descr ip2nets_net;
79 struct list_head ip2nets_ip_ranges;
83 * lustre_lnet_add_ip_range
85 * given a string of the format:
86 * <expr.expr.expr.expr> parse each expr into
87 * a lustre_lnet_ip_range_descr structure and insert on the list.
89 * This function is called from
90 * YAML on each ip-range.
91 * As a result of lnetctl command
92 * When building a NID or P2P selection rules
94 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
96 struct lustre_lnet_ip_range_descr *ip_range;
99 ip_range = calloc(1, sizeof(*ip_range));
100 if (ip_range == NULL)
101 return LUSTRE_CFG_RC_OUT_OF_MEM;
103 INIT_LIST_HEAD(&ip_range->ipr_entry);
104 INIT_LIST_HEAD(&ip_range->ipr_expr);
106 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
107 &ip_range->ipr_expr);
109 return LUSTRE_CFG_RC_BAD_PARAM;
111 list_add_tail(&ip_range->ipr_entry, list);
113 return LUSTRE_CFG_RC_NO_ERR;
116 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
118 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
120 struct lnet_dlc_intf_descr *intf_descr = NULL;
122 char intf_string[LNET_MAX_STR_LEN];
124 if (len >= LNET_MAX_STR_LEN)
125 return LUSTRE_CFG_RC_BAD_PARAM;
127 strncpy(intf_string, intf, len);
128 intf_string[len] = '\0';
130 intf_descr = calloc(1, sizeof(*intf_descr));
131 if (intf_descr == NULL)
132 return LUSTRE_CFG_RC_OUT_OF_MEM;
134 INIT_LIST_HEAD(&intf_descr->intf_on_network);
136 intf_name = intf_string;
137 open_sq_bracket = strchr(intf_string, '[');
138 if (open_sq_bracket != NULL) {
139 close_sq_bracket = strchr(intf_string, ']');
140 if (close_sq_bracket == NULL) {
142 return LUSTRE_CFG_RC_BAD_PARAM;
144 rc = cfs_expr_list_parse(open_sq_bracket,
145 strlen(open_sq_bracket), 0, UINT_MAX,
146 &intf_descr->cpt_expr);
149 return LUSTRE_CFG_RC_BAD_PARAM;
151 strncpy(intf_descr->intf_name, intf_name,
152 open_sq_bracket - intf_name);
153 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
155 strcpy(intf_descr->intf_name, intf_name);
156 intf_descr->cpt_expr = NULL;
159 list_add_tail(&intf_descr->intf_on_network, list);
161 return LUSTRE_CFG_RC_NO_ERR;
164 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
166 if (nw_descr != NULL) {
167 INIT_LIST_HEAD(&nw_descr->network_on_rule);
168 INIT_LIST_HEAD(&nw_descr->nw_intflist);
174 * <intf>[<expr>], <intf>[<expr>],..
176 int lustre_lnet_parse_interfaces(char *intf_str,
177 struct lnet_dlc_network_descr *nw_descr)
182 char *cur = intf_str, *next = NULL;
183 char *end = intf_str + strlen(intf_str);
185 struct lnet_dlc_intf_descr *intf_descr, *tmp;
187 if (nw_descr == NULL)
188 return LUSTRE_CFG_RC_BAD_PARAM;
191 open_square = strchr(cur, '[');
192 if (open_square != NULL) {
193 close_square = strchr(cur, ']');
194 if (close_square == NULL) {
195 rc = LUSTRE_CFG_RC_BAD_PARAM;
199 comma = strchr(cur, ',');
200 if (comma != NULL && comma > close_square) {
202 len = next - close_square;
208 comma = strchr(cur, ',');
218 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
219 if (rc != LUSTRE_CFG_RC_NO_ERR)
225 return LUSTRE_CFG_RC_NO_ERR;
228 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
230 if (intf_descr->cpt_expr != NULL)
231 cfs_expr_list_free(intf_descr->cpt_expr);
238 int lustre_lnet_config_lib_init(void)
240 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
241 LNET_DEV_MAJOR, LNET_DEV_MINOR);
244 void lustre_lnet_config_lib_uninit(void)
246 unregister_ioc_dev(LNET_DEV_ID);
249 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
250 int seq_no, struct cYAML **err_rc)
252 struct libcfs_ioctl_data data;
255 char err_str[LNET_MAX_STR_LEN];
257 snprintf(err_str, sizeof(err_str), "\"Success\"");
259 LIBCFS_IOC_INIT(data);
261 /* Reverse logic is used here in order not to change
262 * the lctl utility */
263 data.ioc_flags = load_ni_from_mod ? 0 : 1;
265 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
267 rc = l_ioctl(LNET_DEV_ID, opc, &data);
271 "\"LNet %s error: %s\"", (up) ? "configure" :
272 "unconfigure", strerror(errno));
276 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
277 "lnet", err_str, err_rc);
282 static lnet_nid_t *allocate_create_nid_array(char **nids, char *err_str)
284 lnet_nid_t *array = NULL;
288 snprintf(err_str, LNET_MAX_STR_LEN, "no NIDs to add");
292 /* count the size of the array */
293 while (nids[idx] != NULL)
296 array = calloc(sizeof(*array) * idx + 1, 1);
298 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
303 while (nids[idx] != NULL) {
304 array[idx] = libcfs_str2nid(nids[idx]);
305 if (array[idx] == LNET_NID_ANY) {
307 snprintf(err_str, LNET_MAX_STR_LEN,
315 /* identify last entry */
316 array[idx] = LNET_NID_ANY;
321 static int dispatch_peer_ni_cmd(lnet_nid_t knid, lnet_nid_t nid, __u32 cmd,
322 struct lnet_ioctl_peer_cfg *data,
323 char *err_str, char *cmd_str)
327 data->prcfg_key_nid = knid;
328 data->prcfg_cfg_nid = nid;
330 rc = l_ioctl(LNET_DEV_ID, cmd, data);
335 "\"cannot %s peer ni: %s\"",
336 (cmd_str) ? cmd_str : "add", strerror(errno));
342 int lustre_lnet_config_peer_nid(char *knid, char **nid, bool mr, int seq_no,
343 struct cYAML **err_rc)
345 struct lnet_ioctl_peer_cfg data;
346 lnet_nid_t key_nid = LNET_NID_ANY;
347 int rc = LUSTRE_CFG_RC_NO_ERR;
349 char err_str[LNET_MAX_STR_LEN] = {0};
350 lnet_nid_t *nids = allocate_create_nid_array(nid, err_str);
353 key_nid = libcfs_str2nid(knid);
354 if (key_nid == LNET_NID_ANY) {
355 snprintf(err_str, sizeof(err_str),
358 rc = LUSTRE_CFG_RC_MISSING_PARAM;
361 } else if (nids[0] == LNET_NID_ANY) {
362 snprintf(err_str, sizeof(err_str),
363 "no NIDs provided for configuration");
364 rc = LUSTRE_CFG_RC_MISSING_PARAM;
367 key_nid = LNET_NID_ANY;
370 snprintf(err_str, sizeof(err_str), "\"Success\"");
372 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
374 if (nids[0] == LNET_NID_ANY) {
375 rc = dispatch_peer_ni_cmd(LNET_NID_ANY, key_nid,
376 IOC_LIBCFS_ADD_PEER_NI,
377 &data, err_str, "add");
381 while (nids[idx] != LNET_NID_ANY) {
383 * If key_nid is not provided then the first nid in the
384 * list becomes the key_nid. First time round the loop use
385 * LNET_NID_ANY for the first parameter, then use nid[0]
386 * as the key nid after wards
388 rc = dispatch_peer_ni_cmd(key_nid, nids[idx],
389 IOC_LIBCFS_ADD_PEER_NI, &data,
395 if (idx == 0 && key_nid == LNET_NID_ANY)
404 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
408 int lustre_lnet_del_peer_nid(char *knid, char **nid, int seq_no,
409 struct cYAML **err_rc)
411 struct lnet_ioctl_peer_cfg data;
413 int rc = LUSTRE_CFG_RC_NO_ERR;
415 char err_str[LNET_MAX_STR_LEN] = {0};
416 lnet_nid_t *nids = allocate_create_nid_array(nid, err_str);
419 snprintf(err_str, sizeof(err_str),
420 "\"Primary nid is not provided\"");
421 rc = LUSTRE_CFG_RC_MISSING_PARAM;
424 key_nid = libcfs_str2nid(knid);
425 if (key_nid == LNET_NID_ANY) {
426 rc = LUSTRE_CFG_RC_BAD_PARAM;
427 snprintf(err_str, sizeof(err_str),
434 snprintf(err_str, sizeof(err_str), "\"Success\"");
436 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
437 if (nids[0] == LNET_NID_ANY) {
438 rc = dispatch_peer_ni_cmd(key_nid, LNET_NID_ANY,
439 IOC_LIBCFS_DEL_PEER_NI,
440 &data, err_str, "del");
444 while (nids[idx] != LNET_NID_ANY) {
445 rc = dispatch_peer_ni_cmd(key_nid, nids[idx],
446 IOC_LIBCFS_DEL_PEER_NI, &data,
458 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
462 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
463 int seq_no, struct cYAML **err_rc)
465 struct lnet_ioctl_config_data data;
466 lnet_nid_t gateway_nid;
467 int rc = LUSTRE_CFG_RC_NO_ERR;
468 __u32 net = LNET_NIDNET(LNET_NID_ANY);
469 char err_str[LNET_MAX_STR_LEN];
471 snprintf(err_str, sizeof(err_str), "\"Success\"");
473 if (nw == NULL || gw == NULL) {
476 "\"missing mandatory parameter(s): '%s'\"",
477 (nw == NULL && gw == NULL) ? "network, gateway" :
478 (nw == NULL) ? "network" : "gateway");
479 rc = LUSTRE_CFG_RC_MISSING_PARAM;
483 net = libcfs_str2net(nw);
484 if (net == LNET_NIDNET(LNET_NID_ANY)) {
487 "\"cannot parse net %s\"", nw);
488 rc = LUSTRE_CFG_RC_BAD_PARAM;
492 if (LNET_NETTYP(net) == CIBLND ||
493 LNET_NETTYP(net) == OPENIBLND ||
494 LNET_NETTYP(net) == IIBLND ||
495 LNET_NETTYP(net) == VIBLND) {
498 "\"obselete LNet type '%s'\"", libcfs_lnd2str(net));
499 rc = LUSTRE_CFG_RC_BAD_PARAM;
503 gateway_nid = libcfs_str2nid(gw);
504 if (gateway_nid == LNET_NID_ANY) {
507 "\"cannot parse gateway NID '%s'\"", gw);
508 rc = LUSTRE_CFG_RC_BAD_PARAM;
513 /* hops is undefined */
514 hops = LNET_UNDEFINED_HOPS;
515 } else if (hops < 1 || hops > 255) {
518 "\"invalid hop count %d, must be between 1 and 255\"",
520 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
526 } else if (prio < 0) {
529 "\"invalid priority %d, must be greater than 0\"",
531 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
535 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
537 data.cfg_config_u.cfg_route.rtr_hop = hops;
538 data.cfg_config_u.cfg_route.rtr_priority = prio;
539 data.cfg_nid = gateway_nid;
541 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
546 "\"cannot add route: %s\"", strerror(errno));
551 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
556 int lustre_lnet_del_route(char *nw, char *gw,
557 int seq_no, struct cYAML **err_rc)
559 struct lnet_ioctl_config_data data;
560 lnet_nid_t gateway_nid;
561 int rc = LUSTRE_CFG_RC_NO_ERR;
562 __u32 net = LNET_NIDNET(LNET_NID_ANY);
563 char err_str[LNET_MAX_STR_LEN];
565 snprintf(err_str, sizeof(err_str), "\"Success\"");
567 if (nw == NULL || gw == NULL) {
570 "\"missing mandatory parameter(s): '%s'\"",
571 (nw == NULL && gw == NULL) ? "network, gateway" :
572 (nw == NULL) ? "network" : "gateway");
573 rc = LUSTRE_CFG_RC_MISSING_PARAM;
577 net = libcfs_str2net(nw);
578 if (net == LNET_NIDNET(LNET_NID_ANY)) {
581 "\"cannot parse net '%s'\"", nw);
582 rc = LUSTRE_CFG_RC_BAD_PARAM;
586 if (LNET_NETTYP(net) == CIBLND ||
587 LNET_NETTYP(net) == OPENIBLND ||
588 LNET_NETTYP(net) == IIBLND ||
589 LNET_NETTYP(net) == VIBLND) {
592 "\"obselete LNet type '%s'\"", libcfs_lnd2str(net));
593 rc = LUSTRE_CFG_RC_BAD_PARAM;
597 gateway_nid = libcfs_str2nid(gw);
598 if (gateway_nid == LNET_NID_ANY) {
601 "\"cannot parse gateway NID '%s'\"", gw);
602 rc = LUSTRE_CFG_RC_BAD_PARAM;
606 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
608 data.cfg_nid = gateway_nid;
610 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
615 "\"cannot delete route: %s\"", strerror(errno));
620 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
625 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
626 int seq_no, struct cYAML **show_rc,
627 struct cYAML **err_rc)
629 struct lnet_ioctl_config_data data;
630 lnet_nid_t gateway_nid;
631 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
633 __u32 net = LNET_NIDNET(LNET_NID_ANY);
635 struct cYAML *root = NULL, *route = NULL, *item = NULL;
636 struct cYAML *first_seq = NULL;
637 char err_str[LNET_MAX_STR_LEN];
640 snprintf(err_str, sizeof(err_str),
641 "\"out of memory\"");
644 net = libcfs_str2net(nw);
645 if (net == LNET_NIDNET(LNET_NID_ANY)) {
648 "\"cannot parse net '%s'\"", nw);
649 rc = LUSTRE_CFG_RC_BAD_PARAM;
653 if (LNET_NETTYP(net) == CIBLND ||
654 LNET_NETTYP(net) == OPENIBLND ||
655 LNET_NETTYP(net) == IIBLND ||
656 LNET_NETTYP(net) == VIBLND) {
659 "\"obsolete LNet type '%s'\"",
660 libcfs_lnd2str(net));
661 rc = LUSTRE_CFG_RC_BAD_PARAM;
665 /* show all routes without filtering on net */
666 net = LNET_NIDNET(LNET_NID_ANY);
670 gateway_nid = libcfs_str2nid(gw);
671 if (gateway_nid == LNET_NID_ANY) {
674 "\"cannot parse gateway NID '%s'\"", gw);
675 rc = LUSTRE_CFG_RC_BAD_PARAM;
679 /* show all routes with out filtering on gateway */
680 gateway_nid = LNET_NID_ANY;
682 if ((hops < 1 && hops != -1) || hops > 255) {
685 "\"invalid hop count %d, must be between 0 and 256\"",
687 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
691 /* create struct cYAML root object */
692 root = cYAML_create_object(NULL, NULL);
696 route = cYAML_create_seq(root, "route");
701 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
704 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
710 /* filter on provided data */
711 if (net != LNET_NIDNET(LNET_NID_ANY) &&
715 if (gateway_nid != LNET_NID_ANY &&
716 gateway_nid != data.cfg_nid)
720 hops != data.cfg_config_u.cfg_route.rtr_hop)
724 prio != data.cfg_config_u.cfg_route.rtr_priority)
727 /* default rc to -1 incase we hit the goto */
731 item = cYAML_create_seq_item(route);
735 if (first_seq == NULL)
738 if (cYAML_create_string(item, "net",
739 libcfs_net2str(data.cfg_net)) == NULL)
742 if (cYAML_create_string(item, "gateway",
743 libcfs_nid2str(data.cfg_nid)) == NULL)
747 if (cYAML_create_number(item, "hop",
748 data.cfg_config_u.cfg_route.
753 if (cYAML_create_number(item, "priority",
755 cfg_route.rtr_priority) == NULL)
758 if (cYAML_create_string(item, "state",
759 data.cfg_config_u.cfg_route.
761 "up" : "down") == NULL)
766 /* print output iff show_rc is not provided */
768 cYAML_print_tree(root);
770 if (l_errno != ENOENT) {
773 "\"cannot get routes: %s\"",
778 rc = LUSTRE_CFG_RC_NO_ERR;
780 snprintf(err_str, sizeof(err_str), "\"success\"");
782 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
783 cYAML_free_tree(root);
784 } else if (show_rc != NULL && *show_rc != NULL) {
785 struct cYAML *show_node;
786 /* find the route node, if one doesn't exist then
787 * insert one. Otherwise add to the one there
789 show_node = cYAML_get_object_item(*show_rc, "route");
790 if (show_node != NULL && cYAML_is_sequence(show_node)) {
791 cYAML_insert_child(show_node, first_seq);
794 } else if (show_node == NULL) {
795 cYAML_insert_sibling((*show_rc)->cy_child,
799 cYAML_free_tree(root);
805 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
810 static int socket_intf_query(int request, char *intf,
816 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
817 return LUSTRE_CFG_RC_BAD_PARAM;
819 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
821 return LUSTRE_CFG_RC_BAD_PARAM;
823 strcpy(ifr->ifr_name, intf);
824 rc = ioctl(sockfd, request, ifr);
826 return LUSTRE_CFG_RC_BAD_PARAM;
832 * for each interface in the array of interfaces find the IP address of
833 * that interface, create its nid and add it to an array of NIDs.
834 * Stop if any of the interfaces is down
836 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
837 lnet_nid_t **nids, __u32 *nnids)
839 int i = 0, count = 0, rc;
842 struct lnet_dlc_intf_descr *intf;
844 if (nw == NULL || nids == NULL)
845 return LUSTRE_CFG_RC_BAD_PARAM;
847 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
850 *nids = calloc(count, sizeof(lnet_nid_t));
852 return LUSTRE_CFG_RC_OUT_OF_MEM;
854 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
855 memset(&ifr, 0, sizeof(ifr));
856 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
860 if ((ifr.ifr_flags & IFF_UP) == 0) {
861 rc = LUSTRE_CFG_RC_BAD_PARAM;
865 memset(&ifr, 0, sizeof(ifr));
866 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
870 ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
872 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
887 * called repeatedly until a match or no more ip range
889 * ip_range expression
890 * interface list with all the interface names.
891 * all the interfaces in the system.
893 * try to match the ip_range expr to one of the interfaces' IPs in
894 * the system. If we hit a patch for an interface. Check if that
895 * interface name is in the list.
897 * If there are more than one interface in the list, then make sure
898 * that the IPs for all of these interfaces match the ip ranges
901 * for each interface in intf_list
902 * look up the intf name in ifa
903 * if not there then no match
904 * check ip obtained from ifa against a match to any of the
906 * If no match, then fail
908 * The result is that all the interfaces have to match.
910 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
911 struct list_head *intf_list,
912 struct list_head *ip_ranges)
916 struct lnet_dlc_intf_descr *intf_descr;
917 struct ifaddrs *ifaddr = ifa;
918 struct lustre_lnet_ip_range_descr *ip_range;
922 * if there are no explicit interfaces, and no ip ranges, then
923 * configure the first tcp interface we encounter.
925 if (list_empty(intf_list) && list_empty(ip_ranges)) {
926 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
927 if (ifaddr->ifa_addr == NULL)
930 if ((ifaddr->ifa_flags & IFF_UP) == 0)
933 family = ifaddr->ifa_addr->sa_family;
934 if (family == AF_INET) {
935 rc = lustre_lnet_add_intf_descr
936 (intf_list, ifaddr->ifa_name,
937 strlen(ifaddr->ifa_name));
939 if (rc != LUSTRE_CFG_RC_NO_ERR)
942 return LUSTRE_CFG_RC_MATCH;
945 return LUSTRE_CFG_RC_NO_MATCH;
949 * First interface which matches an IP pattern will be used
951 if (list_empty(intf_list)) {
953 * no interfaces provided in the rule, but an ip range is
954 * provided, so try and match an interface to the ip
957 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
958 if (ifaddr->ifa_addr == NULL)
961 if ((ifaddr->ifa_flags & IFF_UP) == 0)
964 family = ifaddr->ifa_addr->sa_family;
965 if (family == AF_INET) {
966 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
969 list_for_each_entry(ip_range, ip_ranges,
971 rc = cfs_ip_addr_match(bswap_32(ip),
972 &ip_range->ipr_expr);
976 rc = lustre_lnet_add_intf_descr
977 (intf_list, ifaddr->ifa_name,
978 strlen(ifaddr->ifa_name));
980 if (rc != LUSTRE_CFG_RC_NO_ERR)
983 return LUSTRE_CFG_RC_MATCH;
990 * If an interface is explicitly specified the ip-range might or
991 * might not be specified. if specified the interface needs to match the
992 * ip-range. If no ip-range then the interfaces are
993 * automatically matched if they are all up.
994 * If > 1 interfaces all the interfaces must match for the NI to
997 list_for_each_entry(intf_descr, intf_list, intf_on_network) {
998 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
999 if (ifaddr->ifa_addr == NULL)
1002 family = ifaddr->ifa_addr->sa_family;
1003 if (family == AF_INET &&
1004 strcmp(intf_descr->intf_name,
1005 ifaddr->ifa_name) == 0)
1010 return LUSTRE_CFG_RC_NO_MATCH;
1012 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1013 return LUSTRE_CFG_RC_NO_MATCH;
1015 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1017 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1018 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1022 return LUSTRE_CFG_RC_NO_MATCH;
1026 return LUSTRE_CFG_RC_MATCH;
1029 int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1030 lnet_nid_t **nids, __u32 *nnids)
1032 struct ifaddrs *ifa;
1033 int rc = LUSTRE_CFG_RC_NO_ERR;
1035 rc = getifaddrs(&ifa);
1039 rc = lustre_lnet_match_ip_to_intf(ifa,
1040 &ip2nets->ip2nets_net.nw_intflist,
1041 &ip2nets->ip2nets_ip_ranges);
1042 if (rc != LUSTRE_CFG_RC_MATCH) {
1047 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids);
1048 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1059 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1060 struct lnet_ioctl_config_lnd_tunables *tunables,
1061 struct cfs_expr_list *global_cpts,
1062 lnet_nid_t *nids, char *err_str)
1065 struct lnet_ioctl_config_ni *conf;
1066 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1067 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1070 struct lnet_dlc_intf_descr *intf_descr;
1072 struct cfs_expr_list *cpt_expr;
1074 list_for_each_entry(intf_descr, intf_list,
1076 if (i == 0 && tunables != NULL)
1077 len = sizeof(struct lnet_ioctl_config_ni) +
1078 sizeof(struct lnet_ioctl_config_lnd_tunables);
1080 len = sizeof(struct lnet_ioctl_config_ni);
1082 data = calloc(1, len);
1083 conf = (struct lnet_ioctl_config_ni*) data;
1084 if (i == 0 && tunables != NULL)
1085 tun = (struct lnet_ioctl_config_lnd_tunables*)
1086 (data + sizeof(*conf));
1088 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1089 conf->lic_cfg_hdr.ioc_len = len;
1090 conf->lic_nid = nids[i];
1091 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1094 if (intf_descr->cpt_expr != NULL)
1095 cpt_expr = intf_descr->cpt_expr;
1096 else if (global_cpts != NULL)
1097 cpt_expr = global_cpts;
1101 if (cpt_expr != NULL) {
1102 count = cfs_expr_list_values(cpt_expr,
1103 LNET_MAX_SHOW_NUM_CPT,
1106 memcpy(conf->lic_cpts, cpt_array,
1107 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1116 conf->lic_ncpts = count;
1118 if (i == 0 && tunables != NULL)
1119 /* TODO put in the LND tunables */
1120 memcpy(tun, tunables, sizeof(*tunables));
1122 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1127 "\"cannot add network: %s\"", strerror(errno));
1133 return LUSTRE_CFG_RC_NO_ERR;
1137 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1138 struct lnet_ioctl_config_lnd_tunables *tunables,
1139 struct cfs_expr_list *global_cpts,
1140 int seq_no, struct cYAML **err_rc)
1142 lnet_nid_t *nids = NULL;
1145 char err_str[LNET_MAX_STR_LEN];
1147 snprintf(err_str, sizeof(err_str), "\"success\"");
1149 if (ip2nets == NULL ||
1150 list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1153 "\"incomplete ip2nets information\"");
1154 rc = LUSTRE_CFG_RC_BAD_PARAM;
1158 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids);
1159 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH) {
1162 "\"cannot resolve ip2nets rule\"");
1166 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1167 tunables, global_cpts, nids,
1169 if (rc != LUSTRE_CFG_RC_NO_ERR)
1173 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1177 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1178 struct cfs_expr_list *global_cpts,
1180 struct lnet_ioctl_config_lnd_tunables *tunables,
1181 int seq_no, struct cYAML **err_rc)
1184 struct lnet_ioctl_config_ni *conf;
1185 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1186 char buf[LNET_MAX_STR_LEN];
1187 int rc = LUSTRE_CFG_RC_NO_ERR;
1188 char err_str[LNET_MAX_STR_LEN];
1189 lnet_nid_t *nids = NULL;
1193 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1196 snprintf(err_str, sizeof(err_str), "\"success\"");
1198 if (ip2net == NULL && nw_descr == NULL) {
1201 "\"mandatory parameters not specified.\"");
1202 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1206 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1209 "\"ip2net string too long %d\"",
1210 (int)strlen(ip2net));
1211 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1215 if (ip2net != NULL) {
1216 if (tunables != NULL)
1217 len = sizeof(struct lnet_ioctl_config_ni) +
1218 sizeof(struct lnet_ioctl_config_lnd_tunables);
1220 len = sizeof(struct lnet_ioctl_config_ni);
1221 data = calloc(1, len);
1222 conf = (struct lnet_ioctl_config_ni*) data;
1223 if (tunables != NULL)
1224 tun = (struct lnet_ioctl_config_lnd_tunables*)
1225 (data + sizeof(*conf));
1227 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1228 conf->lic_cfg_hdr.ioc_len = len;
1229 strncpy(conf->lic_legacy_ip2nets, ip2net,
1232 if (global_cpts != NULL) {
1233 count = cfs_expr_list_values(global_cpts,
1234 LNET_MAX_SHOW_NUM_CPT,
1237 memcpy(conf->lic_cpts, cpt_array,
1238 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1247 conf->lic_ncpts = count;
1249 if (tunables != NULL)
1250 memcpy(tun, tunables, sizeof(*tunables));
1252 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1257 "\"cannot add network: %s\"", strerror(errno));
1264 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1265 return LUSTRE_CFG_RC_NO_ERR;
1267 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1270 "\"cannot parse net '%s'\"",
1271 libcfs_net2str(nw_descr->nw_id));
1272 rc = LUSTRE_CFG_RC_BAD_PARAM;
1276 if (list_empty(&nw_descr->nw_intflist)) {
1279 "\"no interface name provided\"");
1280 rc = LUSTRE_CFG_RC_BAD_PARAM;
1284 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1286 snprintf(err_str, sizeof(err_str),
1287 "\"bad parameter\"");
1288 rc = LUSTRE_CFG_RC_BAD_PARAM;
1292 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1293 tunables, global_cpts, nids,
1297 if (nw_descr != NULL) {
1298 list_for_each_entry_safe(intf_descr, tmp,
1299 &nw_descr->nw_intflist,
1301 if (intf_descr->cpt_expr != NULL)
1302 cfs_expr_list_free(intf_descr->cpt_expr);
1307 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1318 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1319 int seq_no, struct cYAML **err_rc)
1321 struct lnet_ioctl_config_ni data;
1322 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1323 char err_str[LNET_MAX_STR_LEN];
1324 lnet_nid_t *nids = NULL;
1326 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1328 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1329 return LUSTRE_CFG_RC_NO_ERR;
1331 snprintf(err_str, sizeof(err_str), "\"success\"");
1333 if (nw_descr == NULL) {
1336 "\"missing mandatory parameter\"");
1337 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1341 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1344 "\"cannot parse net '%s'\"",
1345 libcfs_net2str(nw_descr->nw_id));
1346 rc = LUSTRE_CFG_RC_BAD_PARAM;
1350 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1352 snprintf(err_str, sizeof(err_str),
1353 "\"bad parameter\"");
1354 rc = LUSTRE_CFG_RC_BAD_PARAM;
1359 * no interfaces just the nw_id is specified
1362 nids = calloc(1, sizeof(*nids));
1364 snprintf(err_str, sizeof(err_str),
1365 "\"out of memory\"");
1366 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1369 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1373 for (i = 0; i < nnids; i++) {
1374 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1375 data.lic_nid = nids[i];
1377 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1382 "\"cannot del network: %s\"", strerror(errno));
1386 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1388 if (intf_descr->cpt_expr != NULL)
1389 cfs_expr_list_free(intf_descr->cpt_expr);
1394 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1402 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1403 struct cYAML **show_rc, struct cYAML **err_rc)
1406 struct lnet_ioctl_config_ni *ni_data;
1407 struct lnet_ioctl_config_lnd_tunables *lnd;
1408 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1409 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1410 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1412 struct cYAML *root = NULL, *tunables = NULL,
1413 *net_node = NULL, *interfaces = NULL,
1414 *item = NULL, *first_seq = NULL,
1416 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1417 char str_buf[str_buf_len];
1419 char err_str[LNET_MAX_STR_LEN];
1420 bool exist = false, new_net = true;
1422 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd);
1424 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1426 buf = calloc(1, buf_size);
1430 ni_data = (struct lnet_ioctl_config_ni *)buf;
1433 net = libcfs_str2net(nw);
1434 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1437 "\"cannot parse net '%s'\"", nw);
1438 rc = LUSTRE_CFG_RC_BAD_PARAM;
1443 root = cYAML_create_object(NULL, NULL);
1447 net_node = cYAML_create_seq(root, "net");
1448 if (net_node == NULL)
1455 memset(buf, 0, buf_size);
1457 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1459 * set the ioc_len to the proper value since INIT assumes
1462 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1463 ni_data->lic_idx = i;
1465 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1471 rc_net = LNET_NIDNET(ni_data->lic_nid);
1473 /* filter on provided data */
1474 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1478 /* default rc to -1 in case we hit the goto */
1482 lnd = (struct lnet_ioctl_config_lnd_tunables *)ni_data->lic_bulk;
1484 if (rc_net != prev_net) {
1491 if (!cYAML_create_string(net_node, "net type",
1492 libcfs_net2str(rc_net)))
1495 tmp = cYAML_create_seq(net_node, "local NI(s)");
1501 /* create the tree to be printed. */
1502 item = cYAML_create_seq_item(tmp);
1506 if (first_seq == NULL)
1509 if (cYAML_create_string(item, "nid",
1510 libcfs_nid2str(ni_data->lic_nid)) == NULL)
1513 if (cYAML_create_string(item,
1515 (ni_data->lic_status ==
1516 LNET_NI_STATUS_UP) ?
1517 "up" : "down") == NULL)
1520 /* don't add interfaces unless there is at least one
1522 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
1523 interfaces = cYAML_create_object(item, "interfaces");
1524 if (interfaces == NULL)
1527 for (j = 0; j < LNET_MAX_INTERFACES; j++) {
1528 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
1530 sizeof(str_buf), "%d", j);
1531 if (cYAML_create_string(interfaces,
1533 ni_data->lic_ni_intf[j]) ==
1543 tunables = cYAML_create_object(item, "tunables");
1547 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
1548 if (rc != LUSTRE_CFG_RC_NO_ERR)
1551 tunables = cYAML_create_object(item, "lnd tunables");
1552 if (tunables == NULL)
1555 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
1557 if (rc != LUSTRE_CFG_RC_NO_ERR)
1560 if (cYAML_create_number(item, "tcp bonding",
1561 ni_data->lic_tcp_bonding)
1565 if (cYAML_create_number(item, "dev cpt",
1566 ni_data->lic_dev_cpt) == NULL)
1569 /* out put the CPTs in the format: "[x,x,x,...]" */
1570 limit = str_buf + str_buf_len - 3;
1571 pos += snprintf(pos, limit - pos, "\"[");
1572 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
1573 j < ni_data->lic_ncpts &&
1575 pos += snprintf(pos, limit - pos,
1576 "%d", ni_data->lic_cpts[j]);
1577 if ((j + 1) < ni_data->lic_ncpts)
1578 pos += snprintf(pos, limit - pos, ",");
1580 pos += snprintf(pos, 3, "]\"");
1582 if (ni_data->lic_ncpts >= 1 &&
1583 cYAML_create_string(item, "CPT",
1589 /* Print out the net information only if show_rc is not provided */
1590 if (show_rc == NULL)
1591 cYAML_print_tree(root);
1593 if (l_errno != ENOENT) {
1596 "\"cannot get networks: %s\"",
1601 rc = LUSTRE_CFG_RC_NO_ERR;
1603 snprintf(err_str, sizeof(err_str), "\"success\"");
1605 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1606 cYAML_free_tree(root);
1607 } else if (show_rc != NULL && *show_rc != NULL) {
1608 struct cYAML *show_node;
1609 /* find the net node, if one doesn't exist
1610 * then insert one. Otherwise add to the one there
1612 show_node = cYAML_get_object_item(*show_rc, "net");
1613 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1614 cYAML_insert_child(show_node, first_seq);
1617 } else if (show_node == NULL) {
1618 cYAML_insert_sibling((*show_rc)->cy_child,
1622 cYAML_free_tree(root);
1628 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
1633 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
1635 struct lnet_ioctl_config_data data;
1636 int rc = LUSTRE_CFG_RC_NO_ERR;
1637 char err_str[LNET_MAX_STR_LEN];
1639 snprintf(err_str, sizeof(err_str), "\"success\"");
1641 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1642 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
1644 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
1649 "\"cannot %s routing %s\"",
1650 (enable) ? "enable" : "disable", strerror(errno));
1655 cYAML_build_error(rc, seq_no,
1656 (enable) ? ADD_CMD : DEL_CMD,
1657 "routing", err_str, err_rc);
1662 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
1664 struct lnet_ioctl_numa_range data;
1665 int rc = LUSTRE_CFG_RC_NO_ERR;
1666 char err_str[LNET_MAX_STR_LEN];
1668 snprintf(err_str, sizeof(err_str), "\"success\"");
1673 "\"range must be >= 0\"");
1674 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1678 LIBCFS_IOC_INIT_V2(data, nr_hdr);
1679 data.nr_range = range;
1681 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_NUMA_RANGE, &data);
1686 "\"cannot configure buffers: %s\"", strerror(errno));
1691 cYAML_build_error(rc, seq_no, ADD_CMD, "numa_range", err_str, err_rc);
1696 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
1697 struct cYAML **err_rc)
1699 struct lnet_ioctl_config_data data;
1700 int rc = LUSTRE_CFG_RC_NO_ERR;
1701 char err_str[LNET_MAX_STR_LEN];
1703 snprintf(err_str, sizeof(err_str), "\"success\"");
1705 /* -1 indicates to ignore changes to this field */
1706 if (tiny < -1 || small < -1 || large < -1) {
1709 "\"tiny, small and large must be >= 0\"");
1710 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1714 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1715 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
1716 data.cfg_config_u.cfg_buffers.buf_small = small;
1717 data.cfg_config_u.cfg_buffers.buf_large = large;
1719 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
1724 "\"cannot configure buffers: %s\"", strerror(errno));
1729 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
1734 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
1735 struct cYAML **err_rc)
1737 struct lnet_ioctl_config_data *data;
1738 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
1739 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1742 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
1743 int buf_count[LNET_NRBPOOLS] = {0};
1744 struct cYAML *root = NULL, *pools_node = NULL,
1745 *type_node = NULL, *item = NULL, *cpt = NULL,
1746 *first_seq = NULL, *buffers = NULL;
1748 char err_str[LNET_MAX_STR_LEN];
1749 char node_name[LNET_MAX_STR_LEN];
1752 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1754 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
1758 data = (struct lnet_ioctl_config_data *)buf;
1760 root = cYAML_create_object(NULL, NULL);
1764 pools_node = cYAML_create_seq(root, "routing");
1765 if (pools_node == NULL)
1769 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
1770 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
1771 sizeof(struct lnet_ioctl_pool_cfg);
1772 data->cfg_count = i;
1774 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
1782 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
1784 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
1785 item = cYAML_create_seq_item(pools_node);
1789 if (first_seq == NULL)
1792 cpt = cYAML_create_object(item, node_name);
1796 /* create the tree and print */
1797 for (j = 0; j < LNET_NRBPOOLS; j++) {
1798 type_node = cYAML_create_object(cpt, pools[j]);
1799 if (type_node == NULL)
1801 if (cYAML_create_number(type_node, "npages",
1802 pool_cfg->pl_pools[j].pl_npages)
1805 if (cYAML_create_number(type_node, "nbuffers",
1806 pool_cfg->pl_pools[j].
1807 pl_nbuffers) == NULL)
1809 if (cYAML_create_number(type_node, "credits",
1810 pool_cfg->pl_pools[j].
1811 pl_credits) == NULL)
1813 if (cYAML_create_number(type_node, "mincredits",
1814 pool_cfg->pl_pools[j].
1815 pl_mincredits) == NULL)
1817 /* keep track of the total count for each of the
1818 * tiny, small and large buffers */
1819 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
1823 if (pool_cfg != NULL) {
1824 item = cYAML_create_seq_item(pools_node);
1828 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
1833 /* create a buffers entry in the show. This is necessary so that
1834 * if the YAML output is used to configure a node, the buffer
1835 * configuration takes hold */
1836 buffers = cYAML_create_object(root, "buffers");
1837 if (buffers == NULL)
1840 for (i = 0; i < LNET_NRBPOOLS; i++) {
1841 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
1845 if (show_rc == NULL)
1846 cYAML_print_tree(root);
1848 if (l_errno != ENOENT) {
1851 "\"cannot get routing information: %s\"",
1856 rc = LUSTRE_CFG_RC_NO_ERR;
1858 snprintf(err_str, sizeof(err_str), "\"success\"");
1859 rc = LUSTRE_CFG_RC_NO_ERR;
1863 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1864 cYAML_free_tree(root);
1865 } else if (show_rc != NULL && *show_rc != NULL) {
1866 struct cYAML *routing_node;
1867 /* there should exist only one routing block and one
1868 * buffers block. If there already exists a previous one
1869 * then don't add another */
1870 routing_node = cYAML_get_object_item(*show_rc, "routing");
1871 if (routing_node == NULL) {
1872 cYAML_insert_sibling((*show_rc)->cy_child,
1876 cYAML_free_tree(root);
1882 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
1887 int lustre_lnet_show_peer(char *knid, int seq_no, struct cYAML **show_rc,
1888 struct cYAML **err_rc)
1890 struct lnet_ioctl_peer_cfg *peer_info;
1891 struct lnet_peer_ni_credit_info *lpni_cri;
1892 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, ncpt = 0, i = 0, j = 0;
1894 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
1895 *first_seq = NULL, *peer_root = NULL, *tmp = NULL;
1896 char err_str[LNET_MAX_STR_LEN];
1897 lnet_nid_t prev_primary_nid = LNET_NID_ANY, primary_nid = LNET_NID_ANY;
1898 char *data = calloc(sizeof(*peer_info) + sizeof(*lpni_cri), 1);
1899 bool new_peer = true;
1901 snprintf(err_str, sizeof(err_str),
1902 "\"out of memory\"");
1907 peer_info = (struct lnet_ioctl_peer_cfg *)data;
1909 /* create struct cYAML root object */
1910 root = cYAML_create_object(NULL, NULL);
1914 peer_root = cYAML_create_seq(root, "peer");
1915 if (peer_root == NULL)
1919 primary_nid = libcfs_str2nid(knid);
1923 memset(data, 0, sizeof(*peer_info) + sizeof(*lpni_cri));
1924 LIBCFS_IOC_INIT_V2(*peer_info, prcfg_hdr);
1925 peer_info->prcfg_hdr.ioc_len = sizeof(*peer_info) +
1927 peer_info->prcfg_idx = i;
1929 rc = l_ioctl(LNET_DEV_ID,
1930 IOC_LIBCFS_GET_PEER_NI, peer_info);
1936 if (primary_nid != LNET_NID_ANY &&
1937 primary_nid != peer_info->prcfg_key_nid)
1940 lpni_cri = (struct lnet_peer_ni_credit_info*)peer_info->prcfg_bulk;
1942 peer = cYAML_create_seq_item(peer_root);
1946 if (peer_info->prcfg_key_nid != prev_primary_nid) {
1947 prev_primary_nid = peer_info->prcfg_key_nid;
1952 lnet_nid_t pnid = peer_info->prcfg_key_nid;
1953 if (cYAML_create_string(peer, "primary nid",
1954 libcfs_nid2str(pnid))
1957 tmp = cYAML_create_seq(peer, "peer ni");
1963 if (first_seq == NULL)
1966 peer_ni = cYAML_create_seq_item(tmp);
1967 if (peer_ni == NULL)
1970 if (cYAML_create_string(peer_ni, "nid",
1972 (peer_info->prcfg_cfg_nid))
1976 if (cYAML_create_string(peer_ni, "state",
1977 lpni_cri->cr_aliveness)
1981 if (cYAML_create_number(peer_ni, "refcount",
1982 lpni_cri->cr_refcount) == NULL)
1985 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
1986 lpni_cri->cr_ni_peer_tx_credits)
1990 if (cYAML_create_number(peer_ni, "available_tx_credits",
1991 lpni_cri->cr_peer_tx_credits)
1995 if (cYAML_create_number(peer_ni, "available_rtr_credits",
1996 lpni_cri->cr_peer_rtr_credits)
2000 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2001 lpni_cri->cr_peer_min_rtr_credits)
2005 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2006 lpni_cri->cr_peer_tx_qnob)
2011 if (l_errno != ENOENT) {
2014 "\"cannot get peer information: %s\"",
2023 /* print output iff show_rc is not provided */
2024 if (show_rc == NULL)
2025 cYAML_print_tree(root);
2027 snprintf(err_str, sizeof(err_str), "\"success\"");
2028 rc = LUSTRE_CFG_RC_NO_ERR;
2031 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2032 cYAML_free_tree(root);
2033 } else if (show_rc != NULL && *show_rc != NULL) {
2034 struct cYAML *show_node;
2035 /* find the peer node, if one doesn't exist then
2036 * insert one. Otherwise add to the one there
2038 show_node = cYAML_get_object_item(*show_rc,
2040 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2041 cYAML_insert_child(show_node, first_seq);
2044 } else if (show_node == NULL) {
2045 cYAML_insert_sibling((*show_rc)->cy_child,
2049 cYAML_free_tree(root);
2055 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
2061 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
2062 struct cYAML **err_rc)
2064 struct lnet_ioctl_numa_range data;
2065 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2067 char err_str[LNET_MAX_STR_LEN];
2068 struct cYAML *root = NULL, *range = NULL;
2070 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2072 LIBCFS_IOC_INIT_V2(data, nr_hdr);
2074 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NUMA_RANGE, &data);
2079 "\"cannot get numa range: %s\"",
2085 root = cYAML_create_object(NULL, NULL);
2089 range = cYAML_create_object(root, "numa");
2093 if (cYAML_create_number(range, "range",
2094 data.nr_range) == NULL)
2097 if (show_rc == NULL)
2098 cYAML_print_tree(root);
2100 snprintf(err_str, sizeof(err_str), "\"success\"");
2102 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2103 cYAML_free_tree(root);
2104 } else if (show_rc != NULL && *show_rc != NULL) {
2105 cYAML_insert_sibling((*show_rc)->cy_child,
2112 cYAML_build_error(rc, seq_no, SHOW_CMD, "numa", err_str, err_rc);
2117 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
2118 struct cYAML **err_rc)
2120 struct lnet_ioctl_lnet_stats data;
2121 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2123 char err_str[LNET_MAX_STR_LEN];
2124 struct cYAML *root = NULL, *stats = NULL;
2126 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2128 LIBCFS_IOC_INIT_V2(data, st_hdr);
2130 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
2135 "\"cannot get lnet statistics: %s\"",
2141 root = cYAML_create_object(NULL, NULL);
2145 stats = cYAML_create_object(root, "statistics");
2149 if (cYAML_create_number(stats, "msgs_alloc",
2150 data.st_cntrs.msgs_alloc) == NULL)
2153 if (cYAML_create_number(stats, "msgs_max",
2154 data.st_cntrs.msgs_max) == NULL)
2157 if (cYAML_create_number(stats, "errors",
2158 data.st_cntrs.errors) == NULL)
2161 if (cYAML_create_number(stats, "send_count",
2162 data.st_cntrs.send_count) == NULL)
2165 if (cYAML_create_number(stats, "recv_count",
2166 data.st_cntrs.recv_count) == NULL)
2169 if (cYAML_create_number(stats, "route_count",
2170 data.st_cntrs.route_count) == NULL)
2173 if (cYAML_create_number(stats, "drop_count",
2174 data.st_cntrs.drop_count) == NULL)
2177 if (cYAML_create_number(stats, "send_length",
2178 data.st_cntrs.send_length) == NULL)
2181 if (cYAML_create_number(stats, "recv_length",
2182 data.st_cntrs.recv_length) == NULL)
2185 if (cYAML_create_number(stats, "route_length",
2186 data.st_cntrs.route_length) == NULL)
2189 if (cYAML_create_number(stats, "drop_length",
2190 data.st_cntrs.drop_length) == NULL)
2193 if (show_rc == NULL)
2194 cYAML_print_tree(root);
2196 snprintf(err_str, sizeof(err_str), "\"success\"");
2198 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2199 cYAML_free_tree(root);
2200 } else if (show_rc != NULL && *show_rc != NULL) {
2201 cYAML_insert_sibling((*show_rc)->cy_child,
2208 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
2213 typedef int (*cmd_handler_t)(struct cYAML *tree,
2214 struct cYAML **show_rc,
2215 struct cYAML **err_rc);
2217 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
2218 struct cYAML **err_rc)
2220 struct cYAML *net, *gw, *hop, *prio, *seq_no;
2222 net = cYAML_get_object_item(tree, "net");
2223 gw = cYAML_get_object_item(tree, "gateway");
2224 hop = cYAML_get_object_item(tree, "hop");
2225 prio = cYAML_get_object_item(tree, "priority");
2226 seq_no = cYAML_get_object_item(tree, "seq_no");
2228 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
2229 (gw) ? gw->cy_valuestring : NULL,
2230 (hop) ? hop->cy_valueint : -1,
2231 (prio) ? prio->cy_valueint : -1,
2232 (seq_no) ? seq_no->cy_valueint : -1,
2236 static void yaml_free_string_array(char **array, int num)
2239 char **sub_array = array;
2241 for (i = 0; i < num; i++) {
2242 if (*sub_array != NULL)
2251 * 0: <intf_name>['['<expr>']']
2252 * 1: <intf_name>['['<expr>']']
2254 static int yaml_copy_intf_info(struct cYAML *intf_tree,
2255 struct lnet_dlc_network_descr *nw_descr)
2257 struct cYAML *child = NULL;
2258 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
2259 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2261 if (intf_tree == NULL || nw_descr == NULL)
2262 return LUSTRE_CFG_RC_BAD_PARAM;
2264 /* now grab all the interfaces and their cpts */
2265 child = intf_tree->cy_child;
2266 while (child != NULL) {
2267 if (child->cy_valuestring == NULL) {
2268 child = child->cy_next;
2272 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
2275 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
2276 child->cy_valuestring,
2277 strlen(child->cy_valuestring));
2278 if (rc != LUSTRE_CFG_RC_NO_ERR)
2282 child = child->cy_next;
2286 return LUSTRE_CFG_RC_MISSING_PARAM;
2291 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2293 if (intf_descr->cpt_expr != NULL)
2294 cfs_expr_list_free(intf_descr->cpt_expr);
2302 yaml_extract_cmn_tunables(struct cYAML *tree,
2303 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
2304 int *num_global_cpts,
2305 struct cfs_expr_list **global_cpts)
2307 struct cYAML *tun, *item, *smp;
2309 tun = cYAML_get_object_item(tree, "tunables");
2311 item = cYAML_get_object_item(tun, "peer_timeout");
2313 tunables->lct_peer_timeout = item->cy_valueint;
2314 item = cYAML_get_object_item(tun, "peer_credits");
2316 tunables->lct_peer_tx_credits = item->cy_valueint;
2317 item = cYAML_get_object_item(tun, "peer_buffer_credits");
2319 tunables->lct_peer_rtr_credits = item->cy_valueint;
2320 item = cYAML_get_object_item(tun, "credits");
2322 tunables->lct_max_tx_credits = item->cy_valueint;
2323 smp = cYAML_get_object_item(tun, "CPT");
2326 cfs_expr_list_parse(smp->cy_valuestring,
2327 strlen(smp->cy_valuestring),
2328 0, UINT_MAX, global_cpts);
2338 yaml_extract_tunables(struct cYAML *tree,
2339 struct lnet_ioctl_config_lnd_tunables *tunables,
2340 int *num_global_cpts,
2341 struct cfs_expr_list **global_cpts,
2346 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
2347 num_global_cpts, global_cpts);
2352 lustre_yaml_extract_lnd_tunables(tree, net_type,
2360 * - net type: <net>[<NUM>]
2362 * - nid: <ip>@<net>[<NUM>]
2365 * 0: <intf_name>['['<expr>']']
2366 * 1: <intf_name>['['<expr>']']
2368 * peer_timeout: <NUM>
2369 * peer_credits: <NUM>
2370 * peer_buffer_credits: <NUM>
2373 * peercredits_hiw: <NUM>
2374 * map_on_demand: <NUM>
2375 * concurrent_sends: <NUM>
2376 * fmr_pool_size: <NUM>
2377 * fmr_flush_trigger: <NUM>
2380 * At least one interface is required. If no interfaces are provided the
2381 * network interface can not be configured.
2383 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
2384 struct cYAML **err_rc)
2386 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
2388 int num_entries = 0, num_global_cpts = 0, rc;
2389 struct lnet_dlc_network_descr nw_descr;
2390 struct cfs_expr_list *global_cpts = NULL;
2391 struct lnet_ioctl_config_lnd_tunables tunables;
2394 memset(&tunables, 0, sizeof(tunables));
2396 INIT_LIST_HEAD(&nw_descr.network_on_rule);
2397 INIT_LIST_HEAD(&nw_descr.nw_intflist);
2399 ip2net = cYAML_get_object_item(tree, "ip2net");
2400 net = cYAML_get_object_item(tree, "net type");
2402 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
2405 * if neither net nor ip2nets are present, then we can not
2406 * configure the network.
2408 if (!net && !ip2net)
2409 return LUSTRE_CFG_RC_MISSING_PARAM;
2411 local_nis = cYAML_get_object_item(tree, "local NI(s)");
2412 if (local_nis == NULL)
2413 return LUSTRE_CFG_RC_MISSING_PARAM;
2415 if (!cYAML_is_sequence(local_nis))
2416 return LUSTRE_CFG_RC_BAD_PARAM;
2418 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
2419 intf = cYAML_get_object_item(item, "interfaces");
2422 num_entries = yaml_copy_intf_info(intf, &nw_descr);
2423 if (num_entries <= 0) {
2424 cYAML_build_error(num_entries, -1, "ni", "add",
2425 "bad interface list",
2427 return LUSTRE_CFG_RC_BAD_PARAM;
2431 found = yaml_extract_tunables(tree, &tunables, &num_global_cpts,
2433 LNET_NETTYP(nw_descr.nw_id));
2434 seq_no = cYAML_get_object_item(tree, "seq_no");
2436 rc = lustre_lnet_config_ni(&nw_descr,
2437 (num_global_cpts > 0) ? global_cpts: NULL,
2438 (ip2net) ? ip2net->cy_valuestring : NULL,
2439 (found) ? &tunables: NULL,
2440 (seq_no) ? seq_no->cy_valueint : -1,
2443 if (global_cpts != NULL)
2444 cfs_expr_list_free(global_cpts);
2451 * - net-spec: <tcp|o2ib|gni>[NUM]
2453 * 0: <intf name>['['<expr>']']
2454 * 1: <intf name>['['<expr>']']
2456 * 0: <expr.expr.expr.expr>
2457 * 1: <expr.expr.expr.expr>
2459 static int handle_yaml_config_ip2nets(struct cYAML *tree,
2460 struct cYAML **show_rc,
2461 struct cYAML **err_rc)
2463 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
2465 struct lustre_lnet_ip2nets ip2nets;
2466 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
2468 int rc = LUSTRE_CFG_RC_NO_ERR, num_global_cpts = 0;
2469 struct cfs_expr_list *global_cpts = NULL;
2470 struct cfs_expr_list *el, *el_tmp;
2471 struct lnet_ioctl_config_lnd_tunables tunables;
2472 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
2475 memset(&tunables, 0, sizeof(tunables));
2477 /* initialize all lists */
2478 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
2479 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
2480 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
2482 net = cYAML_get_object_item(tree, "net-spec");
2484 return LUSTRE_CFG_RC_BAD_PARAM;
2486 if (net != NULL && net->cy_valuestring == NULL)
2487 return LUSTRE_CFG_RC_BAD_PARAM;
2489 /* assign the network id */
2490 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
2491 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
2492 return LUSTRE_CFG_RC_BAD_PARAM;
2494 seq_no = cYAML_get_object_item(tree, "seq_no");
2496 intf = cYAML_get_object_item(tree, "interfaces");
2498 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
2500 return LUSTRE_CFG_RC_BAD_PARAM;
2503 ip_range = cYAML_get_object_item(tree, "ip-range");
2504 if (ip_range != NULL) {
2505 item = ip_range->cy_child;
2506 while (item != NULL) {
2507 if (item->cy_valuestring == NULL) {
2508 item = item->cy_next;
2512 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
2513 item->cy_valuestring);
2515 if (rc != LUSTRE_CFG_RC_NO_ERR)
2518 item = item->cy_next;
2522 found = yaml_extract_tunables(tree, &tunables, &num_global_cpts,
2524 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
2526 rc = lustre_lnet_config_ip2nets(&ip2nets,
2527 (found) ? &tunables : NULL,
2528 (num_global_cpts > 0) ? global_cpts : NULL,
2529 (seq_no) ? seq_no->cy_valueint : -1,
2533 * don't stop because there was no match. Continue processing the
2534 * rest of the rules. If non-match then nothing is configured
2536 if (rc == LUSTRE_CFG_RC_NO_MATCH)
2537 rc = LUSTRE_CFG_RC_NO_ERR;
2539 list_for_each_entry_safe(intf_descr, intf_tmp,
2540 &ip2nets.ip2nets_net.nw_intflist,
2542 if (intf_descr->cpt_expr != NULL)
2543 cfs_expr_list_free(intf_descr->cpt_expr);
2547 list_for_each_entry_safe(ip_range_descr, tmp,
2548 &ip2nets.ip2nets_ip_ranges,
2550 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
2552 cfs_expr_list_free(el);
2553 free(ip_range_descr);
2559 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
2560 struct cYAML **err_rc)
2562 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
2564 int num_entries, rc;
2565 struct lnet_dlc_network_descr nw_descr;
2567 INIT_LIST_HEAD(&nw_descr.network_on_rule);
2568 INIT_LIST_HEAD(&nw_descr.nw_intflist);
2570 net = cYAML_get_object_item(tree, "net type");
2572 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
2574 local_nis = cYAML_get_object_item(tree, "local NI(s)");
2575 if (local_nis == NULL)
2576 return LUSTRE_CFG_RC_MISSING_PARAM;
2578 if (!cYAML_is_sequence(local_nis))
2579 return LUSTRE_CFG_RC_BAD_PARAM;
2581 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
2582 intf = cYAML_get_object_item(item, "interfaces");
2585 num_entries = yaml_copy_intf_info(intf, &nw_descr);
2586 if (num_entries <= 0) {
2587 cYAML_build_error(num_entries, -1, "ni", "add",
2588 "bad interface list",
2590 return LUSTRE_CFG_RC_BAD_PARAM;
2594 seq_no = cYAML_get_object_item(tree, "seq_no");
2596 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
2597 (seq_no) ? seq_no->cy_valueint : -1,
2603 static int yaml_copy_peer_nids(struct cYAML *tree, char ***nidsppp)
2605 struct cYAML *nids_entry = NULL, *child;
2607 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
2609 nids_entry = cYAML_get_object_item(tree, "nids");
2610 if (nids_entry != NULL) {
2612 child = nids_entry->cy_child;
2613 while (child != NULL) {
2615 child = child->cy_next;
2619 return LUSTRE_CFG_RC_MISSING_PARAM;
2621 nids = calloc(sizeof(*nids) * num, 1);
2623 return LUSTRE_CFG_RC_OUT_OF_MEM;
2625 /* now grab all the nids */
2626 child = nids_entry->cy_child;
2628 while (child != NULL) {
2629 nids[num] = calloc(strlen(child->cy_valuestring) + 1,
2631 if (nids[num] == NULL) {
2632 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2635 strncpy(nids[num], child->cy_valuestring,
2636 strlen(child->cy_valuestring));
2637 child = child->cy_next;
2642 rc = LUSTRE_CFG_RC_MISSING_PARAM;
2651 yaml_free_string_array(nids, num);
2656 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
2657 struct cYAML **err_rc)
2661 struct cYAML *seq_no, *key_nid, *non_mr;
2663 num = yaml_copy_peer_nids(tree, &nids);
2667 seq_no = cYAML_get_object_item(tree, "seq_no");
2668 key_nid = cYAML_get_object_item(tree, "key_nid");
2669 non_mr = cYAML_get_object_item(tree, "non_mr");
2671 rc = lustre_lnet_config_peer_nid((key_nid) ? key_nid->cy_valuestring : NULL,
2673 (non_mr) ? false : true,
2674 (seq_no) ? seq_no->cy_valueint : -1,
2677 yaml_free_string_array(nids, num);
2681 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
2682 struct cYAML **err_rc)
2686 struct cYAML *seq_no, *key_nid;
2688 num = yaml_copy_peer_nids(tree, &nids);
2692 seq_no = cYAML_get_object_item(tree, "seq_no");
2693 key_nid = cYAML_get_object_item(tree, "key_nid");
2695 rc = lustre_lnet_del_peer_nid((key_nid) ? key_nid->cy_valuestring : NULL,
2697 (seq_no) ? seq_no->cy_valueint : -1,
2700 yaml_free_string_array(nids, num);
2704 static int handle_yaml_config_buffers(struct cYAML *tree,
2705 struct cYAML **show_rc,
2706 struct cYAML **err_rc)
2709 struct cYAML *tiny, *small, *large, *seq_no;
2711 tiny = cYAML_get_object_item(tree, "tiny");
2712 small = cYAML_get_object_item(tree, "small");
2713 large = cYAML_get_object_item(tree, "large");
2714 seq_no = cYAML_get_object_item(tree, "seq_no");
2716 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
2717 (small) ? small->cy_valueint : -1,
2718 (large) ? large->cy_valueint : -1,
2719 (seq_no) ? seq_no->cy_valueint : -1,
2725 static int handle_yaml_config_routing(struct cYAML *tree,
2726 struct cYAML **show_rc,
2727 struct cYAML **err_rc)
2729 int rc = LUSTRE_CFG_RC_NO_ERR;
2730 struct cYAML *seq_no, *enable;
2732 seq_no = cYAML_get_object_item(tree, "seq_no");
2733 enable = cYAML_get_object_item(tree, "enable");
2736 rc = lustre_lnet_enable_routing(enable->cy_valueint,
2738 seq_no->cy_valueint : -1,
2745 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
2746 struct cYAML **err_rc)
2750 struct cYAML *seq_no;
2752 net = cYAML_get_object_item(tree, "net");
2753 gw = cYAML_get_object_item(tree, "gateway");
2754 seq_no = cYAML_get_object_item(tree, "seq_no");
2756 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
2757 (gw) ? gw->cy_valuestring : NULL,
2758 (seq_no) ? seq_no->cy_valueint : -1,
2762 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
2763 struct cYAML **err_rc)
2765 struct cYAML *seq_no;
2767 seq_no = cYAML_get_object_item(tree, "seq_no");
2769 return lustre_lnet_enable_routing(0, (seq_no) ?
2770 seq_no->cy_valueint : -1,
2774 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
2775 struct cYAML **err_rc)
2781 struct cYAML *detail;
2782 struct cYAML *seq_no;
2784 net = cYAML_get_object_item(tree, "net");
2785 gw = cYAML_get_object_item(tree, "gateway");
2786 hop = cYAML_get_object_item(tree, "hop");
2787 prio = cYAML_get_object_item(tree, "priority");
2788 detail = cYAML_get_object_item(tree, "detail");
2789 seq_no = cYAML_get_object_item(tree, "seq_no");
2791 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
2792 (gw) ? gw->cy_valuestring : NULL,
2793 (hop) ? hop->cy_valueint : -1,
2794 (prio) ? prio->cy_valueint : -1,
2795 (detail) ? detail->cy_valueint : 0,
2796 (seq_no) ? seq_no->cy_valueint : -1,
2801 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
2802 struct cYAML **err_rc)
2804 struct cYAML *net, *detail, *seq_no;
2806 net = cYAML_get_object_item(tree, "net");
2807 detail = cYAML_get_object_item(tree, "detail");
2808 seq_no = cYAML_get_object_item(tree, "seq_no");
2810 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
2811 (detail) ? detail->cy_valueint : 0,
2812 (seq_no) ? seq_no->cy_valueint : -1,
2817 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
2818 struct cYAML **err_rc)
2820 struct cYAML *seq_no;
2822 seq_no = cYAML_get_object_item(tree, "seq_no");
2824 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
2828 static int handle_yaml_show_credits(struct cYAML *tree, struct cYAML **show_rc,
2829 struct cYAML **err_rc)
2831 struct cYAML *seq_no, *key_nid;
2833 seq_no = cYAML_get_object_item(tree, "seq_no");
2834 key_nid = cYAML_get_object_item(tree, "key_nid");
2836 return lustre_lnet_show_peer((key_nid) ? key_nid->cy_valuestring : NULL,
2837 (seq_no) ? seq_no->cy_valueint : -1,
2841 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
2842 struct cYAML **err_rc)
2844 struct cYAML *seq_no;
2846 seq_no = cYAML_get_object_item(tree, "seq_no");
2848 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
2852 struct lookup_cmd_hdlr_tbl {
2857 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
2858 {"route", handle_yaml_config_route},
2859 {"net", handle_yaml_config_ni},
2860 {"ip2nets", handle_yaml_config_ip2nets},
2861 {"peer", handle_yaml_config_peer},
2862 {"routing", handle_yaml_config_routing},
2863 {"buffers", handle_yaml_config_buffers},
2867 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
2868 {"route", handle_yaml_del_route},
2869 {"net", handle_yaml_del_ni},
2870 {"peer", handle_yaml_del_peer},
2871 {"routing", handle_yaml_del_routing},
2875 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
2876 {"route", handle_yaml_show_route},
2877 {"net", handle_yaml_show_net},
2878 {"buffers", handle_yaml_show_routing},
2879 {"routing", handle_yaml_show_routing},
2880 {"credits", handle_yaml_show_credits},
2881 {"statistics", handle_yaml_show_stats},
2885 static cmd_handler_t lookup_fn(char *key,
2886 struct lookup_cmd_hdlr_tbl *tbl)
2892 for (i = 0; tbl[i].name != NULL; i++) {
2893 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
2900 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
2901 struct cYAML **show_rc, struct cYAML **err_rc)
2903 struct cYAML *tree, *item = NULL, *head, *child;
2905 char err_str[LNET_MAX_STR_LEN];
2906 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
2908 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
2910 return LUSTRE_CFG_RC_BAD_PARAM;
2912 child = tree->cy_child;
2913 while (child != NULL) {
2914 cb = lookup_fn(child->cy_string, table);
2916 snprintf(err_str, sizeof(err_str),
2917 "\"call back for '%s' not found\"",
2919 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
2920 "yaml", "helper", err_str, err_rc);
2924 if (cYAML_is_sequence(child)) {
2925 while ((head = cYAML_get_next_seq_item(child, &item))
2927 rc = cb(head, show_rc, err_rc);
2928 if (rc != LUSTRE_CFG_RC_NO_ERR)
2932 rc = cb(child, show_rc, err_rc);
2933 if (rc != LUSTRE_CFG_RC_NO_ERR)
2937 child = child->cy_next;
2941 cYAML_free_tree(tree);
2946 int lustre_yaml_config(char *f, struct cYAML **err_rc)
2948 return lustre_yaml_cb_helper(f, lookup_config_tbl,
2952 int lustre_yaml_del(char *f, struct cYAML **err_rc)
2954 return lustre_yaml_cb_helper(f, lookup_del_tbl,
2958 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
2960 return lustre_yaml_cb_helper(f, lookup_show_tbl,
2964 int lustre_lnet_send_dbg_task(enum lnet_dbg_task dbg_task,
2965 struct lnet_dbg_task_info *dbg_info,
2966 struct cYAML **show_rc,
2967 struct cYAML **err_rc)
2969 struct lnet_ioctl_dbg *dbg;
2970 struct lnet_dbg_task_info *info;
2971 int rc = LUSTRE_CFG_RC_NO_ERR;
2972 char err_str[LNET_MAX_STR_LEN];
2974 snprintf(err_str, sizeof(err_str), "\"success\"");
2976 dbg = calloc(1, sizeof(*dbg) + sizeof(*info));
2978 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2979 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2983 info = (struct lnet_dbg_task_info *)dbg->dbg_bulk;
2985 LIBCFS_IOC_INIT_V2(*dbg, dbg_hdr);
2987 dbg->dbg_task = dbg_task;
2989 memcpy(info, dbg_info, sizeof(*info));
2991 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DBG, dbg);
2996 "\"debug task failed %s\"", strerror(errno));
3001 cYAML_build_error(rc, -1, DBG_CMD,
3002 "debug", err_str, err_rc);