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
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"
56 #define CONFIG_CMD "configure"
57 #define UNCONFIG_CMD "unconfigure"
60 #define SHOW_CMD "show"
62 #define MANAGE_CMD "manage"
64 #define modparam_path "/sys/module/lnet/parameters/"
67 * lustre_lnet_ip_range_descr
68 * Describes an IP range.
69 * Each octect is an expression
71 struct lustre_lnet_ip_range_descr {
72 struct list_head ipr_entry;
73 struct list_head ipr_expr;
78 * Describes an ip2nets rule. This can be on a list of rules.
80 struct lustre_lnet_ip2nets {
81 struct lnet_dlc_network_descr ip2nets_net;
82 struct list_head ip2nets_ip_ranges;
85 int open_sysfs_file(const char *path, const char *attr, const int mode)
88 char filename[LNET_MAX_STR_LEN];
90 if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
93 snprintf(filename, sizeof(filename), "%s%s",
96 fd = open(filename, mode);
101 static int read_sysfs_file(const char *path, const char *attr,
102 void *val, const size_t size, const int nelem)
105 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
107 fd = open_sysfs_file(path, attr, O_RDONLY);
109 return LUSTRE_CFG_RC_NO_MATCH;
111 if (read(fd, val, size * nelem) == -1)
114 rc = LUSTRE_CFG_RC_NO_ERR;
121 static int write_sysfs_file(const char *path, const char *attr,
122 void *val, const size_t size, const int nelem)
125 int rc = LUSTRE_CFG_RC_GENERIC_ERR;
127 fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
129 return LUSTRE_CFG_RC_NO_MATCH;
131 if (write(fd, val, size * nelem) == -1)
134 rc = LUSTRE_CFG_RC_NO_ERR;
143 * frees the memory allocated for an intf descriptor.
145 void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr)
150 if (intf_descr->cpt_expr != NULL)
151 cfs_expr_list_free(intf_descr->cpt_expr);
156 * lustre_lnet_add_ip_range
158 * given a string of the format:
159 * <expr.expr.expr.expr> parse each expr into
160 * a lustre_lnet_ip_range_descr structure and insert on the list.
162 * This function is called from
163 * YAML on each ip-range.
164 * As a result of lnetctl command
165 * When building a NID or P2P selection rules
167 int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range)
169 struct lustre_lnet_ip_range_descr *ip_range;
172 ip_range = calloc(1, sizeof(*ip_range));
173 if (ip_range == NULL)
174 return LUSTRE_CFG_RC_OUT_OF_MEM;
176 INIT_LIST_HEAD(&ip_range->ipr_entry);
177 INIT_LIST_HEAD(&ip_range->ipr_expr);
179 rc = cfs_ip_addr_parse(str_ip_range, strlen(str_ip_range),
180 &ip_range->ipr_expr);
182 return LUSTRE_CFG_RC_BAD_PARAM;
184 list_add_tail(&ip_range->ipr_entry, list);
186 return LUSTRE_CFG_RC_NO_ERR;
189 int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
191 char *open_sq_bracket = NULL, *close_sq_bracket = NULL,
193 struct lnet_dlc_intf_descr *intf_descr = NULL;
195 char intf_string[LNET_MAX_STR_LEN];
197 if (len >= LNET_MAX_STR_LEN)
198 return LUSTRE_CFG_RC_BAD_PARAM;
200 strncpy(intf_string, intf, len);
201 intf_string[len] = '\0';
203 intf_descr = calloc(1, sizeof(*intf_descr));
204 if (intf_descr == NULL)
205 return LUSTRE_CFG_RC_OUT_OF_MEM;
207 INIT_LIST_HEAD(&intf_descr->intf_on_network);
209 intf_name = intf_string;
210 open_sq_bracket = strchr(intf_string, '[');
211 if (open_sq_bracket != NULL) {
212 close_sq_bracket = strchr(intf_string, ']');
213 if (close_sq_bracket == NULL) {
215 return LUSTRE_CFG_RC_BAD_PARAM;
217 rc = cfs_expr_list_parse(open_sq_bracket,
218 strlen(open_sq_bracket), 0, UINT_MAX,
219 &intf_descr->cpt_expr);
222 return LUSTRE_CFG_RC_BAD_PARAM;
224 strncpy(intf_descr->intf_name, intf_name,
225 open_sq_bracket - intf_name);
226 intf_descr->intf_name[open_sq_bracket - intf_name] = '\0';
228 strcpy(intf_descr->intf_name, intf_name);
229 intf_descr->cpt_expr = NULL;
232 list_add_tail(&intf_descr->intf_on_network, list);
234 return LUSTRE_CFG_RC_NO_ERR;
237 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
239 if (nw_descr != NULL) {
240 INIT_LIST_HEAD(&nw_descr->network_on_rule);
241 INIT_LIST_HEAD(&nw_descr->nw_intflist);
245 int lustre_lnet_parse_nids(char *nids, char **array, int size,
249 char *comma = nids, *cur, *entry;
251 int i, len, start = 0, finish = 0;
253 if (nids == NULL || strlen(nids) == 0)
256 /* count the number or new nids, by counting the number of commas */
258 comma = strchr(comma, ',');
268 * if the array is not NULL allocate a large enough array to house
269 * the old and new entries
271 new_array = calloc(sizeof(char*),
272 (size > 0) ? size + num_nids : num_nids);
277 /* parse our the new nids and add them to the tail of the array */
280 start = (size > 0) ? size: 0;
281 finish = (size > 0) ? size + num_nids : num_nids;
282 for (i = start; i < finish; i++) {
283 comma = strchr(comma, ',');
286 * the length of the string to be parsed out is
287 * from cur to end of string. So it's good enough
290 len = strlen(cur) + 1;
292 /* length of the string is comma - cur */
293 len = (comma - cur) + 1;
295 entry = calloc(1, len);
297 finish = i > 0 ? i - 1: 0;
300 strncpy(entry, cur, len - 1);
302 new_array[i] = entry;
309 /* add the old entries in the array and delete the old array*/
310 for (i = 0; i < size; i++)
311 new_array[i] = array[i];
316 *out_array = new_array;
321 for (i = start; i < finish; i++)
331 * <intf>[<expr>], <intf>[<expr>],..
333 int lustre_lnet_parse_interfaces(char *intf_str,
334 struct lnet_dlc_network_descr *nw_descr)
339 char *cur = intf_str, *next = NULL;
340 char *end = intf_str + strlen(intf_str);
342 struct lnet_dlc_intf_descr *intf_descr, *tmp;
344 if (nw_descr == NULL)
345 return LUSTRE_CFG_RC_BAD_PARAM;
348 open_square = strchr(cur, '[');
349 if (open_square != NULL) {
350 close_square = strchr(cur, ']');
351 if (close_square == NULL) {
352 rc = LUSTRE_CFG_RC_BAD_PARAM;
356 comma = strchr(cur, ',');
357 if (comma != NULL && comma > close_square) {
359 len = next - close_square;
365 comma = strchr(cur, ',');
375 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist, cur, len);
376 if (rc != LUSTRE_CFG_RC_NO_ERR)
382 return LUSTRE_CFG_RC_NO_ERR;
385 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
387 list_del(&intf_descr->intf_on_network);
388 free_intf_descr(intf_descr);
394 int lustre_lnet_config_lib_init(void)
396 return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
397 LNET_DEV_MAJOR, LNET_DEV_MINOR);
400 void lustre_lnet_config_lib_uninit(void)
402 unregister_ioc_dev(LNET_DEV_ID);
405 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
406 int seq_no, struct cYAML **err_rc)
408 struct libcfs_ioctl_data data;
411 char err_str[LNET_MAX_STR_LEN];
413 snprintf(err_str, sizeof(err_str), "\"Success\"");
415 LIBCFS_IOC_INIT(data);
417 /* Reverse logic is used here in order not to change
418 * the lctl utility */
419 data.ioc_flags = load_ni_from_mod ? 0 : 1;
421 opc = up ? IOC_LIBCFS_CONFIGURE : IOC_LIBCFS_UNCONFIGURE;
423 rc = l_ioctl(LNET_DEV_ID, opc, &data);
427 "\"LNet %s error: %s\"", (up) ? "configure" :
428 "unconfigure", strerror(errno));
432 cYAML_build_error(rc, seq_no, (up) ? CONFIG_CMD : UNCONFIG_CMD,
433 "lnet", err_str, err_rc);
438 static lnet_nid_t *allocate_create_nid_array(char **nids, __u32 num_nids,
441 lnet_nid_t *array = NULL;
444 if (!nids || num_nids == 0) {
445 snprintf(err_str, LNET_MAX_STR_LEN, "no NIDs to add");
449 array = calloc(sizeof(*array) * num_nids, 1);
451 snprintf(err_str, LNET_MAX_STR_LEN, "out of memory");
455 for (i = 0; i < num_nids; i++) {
456 array[i] = libcfs_str2nid(nids[i]);
457 if (array[i] == LNET_NID_ANY) {
459 snprintf(err_str, LNET_MAX_STR_LEN,
469 static int dispatch_peer_ni_cmd(lnet_nid_t pnid, lnet_nid_t nid, __u32 cmd,
470 struct lnet_ioctl_peer_cfg *data,
471 char *err_str, char *cmd_str)
475 data->prcfg_prim_nid = pnid;
476 data->prcfg_cfg_nid = nid;
478 rc = l_ioctl(LNET_DEV_ID, cmd, data);
483 "\"cannot %s peer ni: %s\"",
484 (cmd_str) ? cmd_str : "add", strerror(errno));
490 static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
491 int seq_no, struct cYAML **show_rc,
492 struct cYAML **err_rc)
495 struct lnet_ioctl_ping_data ping;
496 struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
497 *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
498 lnet_process_id_t id;
499 char err_str[LNET_MAX_STR_LEN] = {0};
500 char *sep, *token, *end;
503 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
507 len = (sizeof(lnet_process_id_t) * LNET_INTERFACES_MAX_DEFAULT);
509 data = calloc(1, len);
513 /* create struct cYAML root object */
514 root = cYAML_create_object(NULL, NULL);
518 ping_node = cYAML_create_seq(root, oper);
519 if (ping_node == NULL)
522 /* tokenise each nid in string ping_nids */
523 token = strtok(ping_nids, ",");
526 item = cYAML_create_seq_item(ping_node);
530 if (first_seq == NULL)
533 /* check if '-' is a part of NID, token */
534 sep = strchr(token, '-');
536 id.pid = LNET_PID_ANY;
537 /* if no net is specified, libcfs_str2nid() will assume tcp */
538 id.nid = libcfs_str2nid(token);
539 if (id.nid == LNET_NID_ANY) {
540 snprintf(err_str, sizeof(err_str),
541 "\"cannot parse NID '%s'\"",
543 rc = LUSTRE_CFG_RC_BAD_PARAM;
544 cYAML_build_error(rc, seq_no, MANAGE_CMD,
545 oper, err_str, err_rc);
549 if (token[0] == 'u' || token[0] == 'U')
550 id.pid = (strtoul(&token[1], &end, 0) |
551 (LNET_PID_USERFLAG));
553 id.pid = strtoul(token, &end, 0);
555 /* assuming '-' is part of hostname */
557 id.pid = LNET_PID_ANY;
558 id.nid = libcfs_str2nid(token);
559 if (id.nid == LNET_NID_ANY) {
560 snprintf(err_str, sizeof(err_str),
561 "\"cannot parse NID '%s'\"",
563 rc = LUSTRE_CFG_RC_BAD_PARAM;
564 cYAML_build_error(rc, seq_no, MANAGE_CMD,
570 id.nid = libcfs_str2nid(sep + 1);
571 if (id.nid == LNET_NID_ANY) {
572 snprintf(err_str, sizeof(err_str),
573 "\"cannot parse NID '%s'\"",
575 rc = LUSTRE_CFG_RC_BAD_PARAM;
576 cYAML_build_error(rc, seq_no, MANAGE_CMD,
583 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
584 ping.ping_hdr.ioc_len = sizeof(ping);
586 ping.op_param = param;
587 ping.ping_count = LNET_INTERFACES_MAX_DEFAULT;
588 ping.ping_buf = data;
590 rc = l_ioctl(LNET_DEV_ID, ioc_call, &ping);
593 sizeof(err_str), "failed to %s %s: %s\n", oper,
594 id.pid == LNET_PID_ANY ?
595 libcfs_nid2str(id.nid) :
596 libcfs_id2str(id), strerror(errno));
597 rc = LUSTRE_CFG_RC_BAD_PARAM;
598 cYAML_build_error(rc, seq_no, MANAGE_CMD,
599 oper, err_str, err_rc);
603 if (cYAML_create_string(item, "primary nid",
604 libcfs_nid2str(ping.ping_id.nid)) == NULL)
607 if (cYAML_create_string(item, "Multi-Rail", ping.mr_info ? "True" :
611 tmp = cYAML_create_seq(item, "peer ni");
615 for (i = 0; i < ping.ping_count; i++) {
616 if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid),
619 peer_ni = cYAML_create_seq_item(tmp);
622 memset(buf, 0, sizeof buf);
623 snprintf(buf, sizeof buf, "nid");
624 if (cYAML_create_string(peer_ni, buf,
625 libcfs_nid2str(ping.ping_buf[i].nid)) == NULL)
631 } while ((token = strtok(NULL, ",")) != NULL);
634 rc = LUSTRE_CFG_RC_NO_ERR;
639 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
640 cYAML_free_tree(root);
641 } else if (show_rc != NULL && *show_rc != NULL) {
642 struct cYAML *show_node;
643 show_node = cYAML_get_object_item(*show_rc, oper);
644 if (show_node != NULL && cYAML_is_sequence(show_node)) {
645 cYAML_insert_child(show_node, first_seq);
648 } else if (show_node == NULL) {
649 cYAML_insert_sibling((*show_rc)->cy_child,
653 cYAML_free_tree(root);
662 int lustre_lnet_ping_nid(char *ping_nids, int timeout, int seq_no,
663 struct cYAML **show_rc, struct cYAML **err_rc)
667 rc = infra_ping_nid(ping_nids, "ping", timeout, IOC_LIBCFS_PING_PEER,
668 seq_no, show_rc, err_rc);
672 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
673 bool mr, int seq_no, struct cYAML **err_rc)
675 struct lnet_ioctl_peer_cfg data;
676 lnet_nid_t prim_nid = LNET_NID_ANY;
677 int rc = LUSTRE_CFG_RC_NO_ERR;
679 bool nid0_used = false;
680 char err_str[LNET_MAX_STR_LEN] = {0};
681 lnet_nid_t *nids = allocate_create_nid_array(nid, num_nids, err_str);
684 prim_nid = libcfs_str2nid(pnid);
685 if (prim_nid == LNET_NID_ANY) {
686 snprintf(err_str, sizeof(err_str),
689 rc = LUSTRE_CFG_RC_MISSING_PARAM;
692 } else if (!nids || nids[0] == LNET_NID_ANY) {
693 snprintf(err_str, sizeof(err_str),
694 "no NIDs provided for configuration");
695 rc = LUSTRE_CFG_RC_MISSING_PARAM;
698 prim_nid = LNET_NID_ANY;
701 snprintf(err_str, sizeof(err_str), "\"Success\"");
703 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
707 * if prim_nid is not specified use the first nid in the list of
708 * nids provided as the prim_nid. NOTE: on entering 'if' we must
709 * have at least 1 NID
711 if (prim_nid == LNET_NID_ANY) {
716 /* Create the prim_nid first */
717 rc = dispatch_peer_ni_cmd(prim_nid, LNET_NID_ANY,
718 IOC_LIBCFS_ADD_PEER_NI,
719 &data, err_str, "add");
724 /* add the rest of the nids to the key nid if any are available */
725 for (idx = nid0_used ? 1 : 0 ; nids && idx < num_nids; idx++) {
727 * If prim_nid is not provided then the first nid in the
728 * list becomes the prim_nid. First time round the loop use
729 * LNET_NID_ANY for the first parameter, then use nid[0]
730 * as the key nid after wards
732 rc = dispatch_peer_ni_cmd(prim_nid, nids[idx],
733 IOC_LIBCFS_ADD_PEER_NI, &data,
743 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
747 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
748 int seq_no, struct cYAML **err_rc)
750 struct lnet_ioctl_peer_cfg data;
752 int rc = LUSTRE_CFG_RC_NO_ERR;
754 char err_str[LNET_MAX_STR_LEN] = {0};
755 lnet_nid_t *nids = allocate_create_nid_array(nid, num_nids, err_str);
758 snprintf(err_str, sizeof(err_str),
759 "\"Primary nid is not provided\"");
760 rc = LUSTRE_CFG_RC_MISSING_PARAM;
763 prim_nid = libcfs_str2nid(pnid);
764 if (prim_nid == LNET_NID_ANY) {
765 rc = LUSTRE_CFG_RC_BAD_PARAM;
766 snprintf(err_str, sizeof(err_str),
773 snprintf(err_str, sizeof(err_str), "\"Success\"");
775 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
776 if (!nids || nids[0] == LNET_NID_ANY) {
777 rc = dispatch_peer_ni_cmd(prim_nid, LNET_NID_ANY,
778 IOC_LIBCFS_DEL_PEER_NI,
779 &data, err_str, "del");
783 for (idx = 0; nids && idx < num_nids; idx++) {
784 rc = dispatch_peer_ni_cmd(prim_nid, nids[idx],
785 IOC_LIBCFS_DEL_PEER_NI, &data,
795 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
799 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
800 int seq_no, struct cYAML **err_rc)
802 struct lnet_ioctl_config_data data;
803 lnet_nid_t gateway_nid;
804 int rc = LUSTRE_CFG_RC_NO_ERR;
805 __u32 net = LNET_NIDNET(LNET_NID_ANY);
806 char err_str[LNET_MAX_STR_LEN];
808 snprintf(err_str, sizeof(err_str), "\"Success\"");
810 if (nw == NULL || gw == NULL) {
813 "\"missing mandatory parameter(s): '%s'\"",
814 (nw == NULL && gw == NULL) ? "network, gateway" :
815 (nw == NULL) ? "network" : "gateway");
816 rc = LUSTRE_CFG_RC_MISSING_PARAM;
820 net = libcfs_str2net(nw);
821 if (net == LNET_NIDNET(LNET_NID_ANY)) {
824 "\"cannot parse net %s\"", nw);
825 rc = LUSTRE_CFG_RC_BAD_PARAM;
829 gateway_nid = libcfs_str2nid(gw);
830 if (gateway_nid == LNET_NID_ANY) {
833 "\"cannot parse gateway NID '%s'\"", gw);
834 rc = LUSTRE_CFG_RC_BAD_PARAM;
839 /* hops is undefined */
840 hops = LNET_UNDEFINED_HOPS;
841 } else if (hops < 1 || hops > 255) {
844 "\"invalid hop count %d, must be between 1 and 255\"",
846 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
852 } else if (prio < 0) {
855 "\"invalid priority %d, must be greater than 0\"",
857 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
861 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
863 data.cfg_config_u.cfg_route.rtr_hop = hops;
864 data.cfg_config_u.cfg_route.rtr_priority = prio;
865 data.cfg_nid = gateway_nid;
867 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
872 "\"cannot add route: %s\"", strerror(errno));
877 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
882 int lustre_lnet_del_route(char *nw, char *gw,
883 int seq_no, struct cYAML **err_rc)
885 struct lnet_ioctl_config_data data;
886 lnet_nid_t gateway_nid;
887 int rc = LUSTRE_CFG_RC_NO_ERR;
888 __u32 net = LNET_NIDNET(LNET_NID_ANY);
889 char err_str[LNET_MAX_STR_LEN];
891 snprintf(err_str, sizeof(err_str), "\"Success\"");
893 if (nw == NULL || gw == NULL) {
896 "\"missing mandatory parameter(s): '%s'\"",
897 (nw == NULL && gw == NULL) ? "network, gateway" :
898 (nw == NULL) ? "network" : "gateway");
899 rc = LUSTRE_CFG_RC_MISSING_PARAM;
903 net = libcfs_str2net(nw);
904 if (net == LNET_NIDNET(LNET_NID_ANY)) {
907 "\"cannot parse net '%s'\"", nw);
908 rc = LUSTRE_CFG_RC_BAD_PARAM;
912 gateway_nid = libcfs_str2nid(gw);
913 if (gateway_nid == LNET_NID_ANY) {
916 "\"cannot parse gateway NID '%s'\"", gw);
917 rc = LUSTRE_CFG_RC_BAD_PARAM;
921 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
923 data.cfg_nid = gateway_nid;
925 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
930 "\"cannot delete route: %s\"", strerror(errno));
935 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
940 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
941 int seq_no, struct cYAML **show_rc,
942 struct cYAML **err_rc)
944 struct lnet_ioctl_config_data data;
945 lnet_nid_t gateway_nid;
946 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
948 __u32 net = LNET_NIDNET(LNET_NID_ANY);
950 struct cYAML *root = NULL, *route = NULL, *item = NULL;
951 struct cYAML *first_seq = NULL;
952 char err_str[LNET_MAX_STR_LEN];
955 snprintf(err_str, sizeof(err_str),
956 "\"out of memory\"");
959 net = libcfs_str2net(nw);
960 if (net == LNET_NIDNET(LNET_NID_ANY)) {
963 "\"cannot parse net '%s'\"", nw);
964 rc = LUSTRE_CFG_RC_BAD_PARAM;
969 /* show all routes without filtering on net */
970 net = LNET_NIDNET(LNET_NID_ANY);
974 gateway_nid = libcfs_str2nid(gw);
975 if (gateway_nid == LNET_NID_ANY) {
978 "\"cannot parse gateway NID '%s'\"", gw);
979 rc = LUSTRE_CFG_RC_BAD_PARAM;
983 /* show all routes with out filtering on gateway */
984 gateway_nid = LNET_NID_ANY;
986 if ((hops < 1 && hops != -1) || hops > 255) {
989 "\"invalid hop count %d, must be between 0 and 256\"",
991 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
995 /* create struct cYAML root object */
996 root = cYAML_create_object(NULL, NULL);
1000 route = cYAML_create_seq(root, "route");
1005 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1008 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1014 /* filter on provided data */
1015 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1016 net != data.cfg_net)
1019 if (gateway_nid != LNET_NID_ANY &&
1020 gateway_nid != data.cfg_nid)
1024 hops != data.cfg_config_u.cfg_route.rtr_hop)
1028 prio != data.cfg_config_u.cfg_route.rtr_priority)
1031 /* default rc to -1 incase we hit the goto */
1035 item = cYAML_create_seq_item(route);
1039 if (first_seq == NULL)
1042 if (cYAML_create_string(item, "net",
1043 libcfs_net2str(data.cfg_net)) == NULL)
1046 if (cYAML_create_string(item, "gateway",
1047 libcfs_nid2str(data.cfg_nid)) == NULL)
1051 if (cYAML_create_number(item, "hop",
1052 (int) data.cfg_config_u.
1053 cfg_route.rtr_hop) ==
1057 if (cYAML_create_number(item, "priority",
1059 cfg_route.rtr_priority) == NULL)
1062 if (cYAML_create_string(item, "state",
1063 data.cfg_config_u.cfg_route.
1065 "up" : "down") == NULL)
1070 /* print output iff show_rc is not provided */
1071 if (show_rc == NULL)
1072 cYAML_print_tree(root);
1074 if (l_errno != ENOENT) {
1077 "\"cannot get routes: %s\"",
1082 rc = LUSTRE_CFG_RC_NO_ERR;
1084 snprintf(err_str, sizeof(err_str), "\"success\"");
1086 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1087 cYAML_free_tree(root);
1088 } else if (show_rc != NULL && *show_rc != NULL) {
1089 struct cYAML *show_node;
1090 /* find the route node, if one doesn't exist then
1091 * insert one. Otherwise add to the one there
1093 show_node = cYAML_get_object_item(*show_rc, "route");
1094 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1095 cYAML_insert_child(show_node, first_seq);
1098 } else if (show_node == NULL) {
1099 cYAML_insert_sibling((*show_rc)->cy_child,
1103 cYAML_free_tree(root);
1109 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1114 static int socket_intf_query(int request, char *intf,
1120 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1121 return LUSTRE_CFG_RC_BAD_PARAM;
1123 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1125 return LUSTRE_CFG_RC_BAD_PARAM;
1127 strcpy(ifr->ifr_name, intf);
1128 rc = ioctl(sockfd, request, ifr);
1130 rc = LUSTRE_CFG_RC_BAD_PARAM;
1138 * for each interface in the array of interfaces find the IP address of
1139 * that interface, create its nid and add it to an array of NIDs.
1140 * Stop if any of the interfaces is down
1142 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1143 lnet_nid_t **nids, __u32 *nnids)
1145 int i = 0, count = 0, rc;
1148 struct lnet_dlc_intf_descr *intf;
1150 if (nw == NULL || nids == NULL)
1151 return LUSTRE_CFG_RC_BAD_PARAM;
1153 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1156 *nids = calloc(count, sizeof(lnet_nid_t));
1158 return LUSTRE_CFG_RC_OUT_OF_MEM;
1160 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1161 memset(&ifr, 0, sizeof(ifr));
1162 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1166 if ((ifr.ifr_flags & IFF_UP) == 0) {
1167 rc = LUSTRE_CFG_RC_BAD_PARAM;
1171 memset(&ifr, 0, sizeof(ifr));
1172 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1176 ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1178 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1193 * called repeatedly until a match or no more ip range
1195 * ip_range expression
1196 * interface list with all the interface names.
1197 * all the interfaces in the system.
1199 * try to match the ip_range expr to one of the interfaces' IPs in
1200 * the system. If we hit a patch for an interface. Check if that
1201 * interface name is in the list.
1203 * If there are more than one interface in the list, then make sure
1204 * that the IPs for all of these interfaces match the ip ranges
1207 * for each interface in intf_list
1208 * look up the intf name in ifa
1209 * if not there then no match
1210 * check ip obtained from ifa against a match to any of the
1212 * If no match, then fail
1214 * The result is that all the interfaces have to match.
1216 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1217 struct list_head *intf_list,
1218 struct list_head *ip_ranges)
1222 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1223 struct ifaddrs *ifaddr = ifa;
1224 struct lustre_lnet_ip_range_descr *ip_range;
1228 * if there are no explicit interfaces, and no ip ranges, then
1229 * configure the first tcp interface we encounter.
1231 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1232 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1233 if (ifaddr->ifa_addr == NULL)
1236 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1239 family = ifaddr->ifa_addr->sa_family;
1240 if (family == AF_INET &&
1241 strcmp(ifaddr->ifa_name, "lo") != 0) {
1242 rc = lustre_lnet_add_intf_descr
1243 (intf_list, ifaddr->ifa_name,
1244 strlen(ifaddr->ifa_name));
1246 if (rc != LUSTRE_CFG_RC_NO_ERR)
1249 return LUSTRE_CFG_RC_MATCH;
1252 return LUSTRE_CFG_RC_NO_MATCH;
1256 * First interface which matches an IP pattern will be used
1258 if (list_empty(intf_list)) {
1260 * no interfaces provided in the rule, but an ip range is
1261 * provided, so try and match an interface to the ip
1264 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1265 if (ifaddr->ifa_addr == NULL)
1268 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1271 family = ifaddr->ifa_addr->sa_family;
1272 if (family == AF_INET) {
1273 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1276 list_for_each_entry(ip_range, ip_ranges,
1278 rc = cfs_ip_addr_match(bswap_32(ip),
1279 &ip_range->ipr_expr);
1283 rc = lustre_lnet_add_intf_descr
1284 (intf_list, ifaddr->ifa_name,
1285 strlen(ifaddr->ifa_name));
1287 if (rc != LUSTRE_CFG_RC_NO_ERR)
1293 if (!list_empty(intf_list))
1294 return LUSTRE_CFG_RC_MATCH;
1296 return LUSTRE_CFG_RC_NO_MATCH;
1300 * If an interface is explicitly specified the ip-range might or
1301 * might not be specified. if specified the interface needs to match the
1302 * ip-range. If no ip-range then the interfaces are
1303 * automatically matched if they are all up.
1304 * If > 1 interfaces all the interfaces must match for the NI to
1307 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1308 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1309 if (ifaddr->ifa_addr == NULL)
1312 family = ifaddr->ifa_addr->sa_family;
1313 if (family == AF_INET &&
1314 strcmp(intf_descr->intf_name,
1315 ifaddr->ifa_name) == 0)
1319 if (ifaddr == NULL) {
1320 list_del(&intf_descr->intf_on_network);
1321 free_intf_descr(intf_descr);
1325 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1326 list_del(&intf_descr->intf_on_network);
1327 free_intf_descr(intf_descr);
1331 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1334 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1335 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1341 /* no match for this interface */
1342 list_del(&intf_descr->intf_on_network);
1343 free_intf_descr(intf_descr);
1347 return LUSTRE_CFG_RC_MATCH;
1350 int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1351 lnet_nid_t **nids, __u32 *nnids)
1353 struct ifaddrs *ifa;
1354 int rc = LUSTRE_CFG_RC_NO_ERR;
1356 rc = getifaddrs(&ifa);
1360 rc = lustre_lnet_match_ip_to_intf(ifa,
1361 &ip2nets->ip2nets_net.nw_intflist,
1362 &ip2nets->ip2nets_ip_ranges);
1363 if (rc != LUSTRE_CFG_RC_MATCH) {
1368 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids);
1369 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1380 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1381 struct lnet_ioctl_config_lnd_tunables *tunables,
1382 struct cfs_expr_list *global_cpts,
1383 lnet_nid_t *nids, char *err_str)
1386 struct lnet_ioctl_config_ni *conf;
1387 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1388 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1391 struct lnet_dlc_intf_descr *intf_descr;
1393 struct cfs_expr_list *cpt_expr;
1395 list_for_each_entry(intf_descr, intf_list,
1397 if (tunables != NULL)
1398 len = sizeof(struct lnet_ioctl_config_ni) +
1399 sizeof(struct lnet_ioctl_config_lnd_tunables);
1401 len = sizeof(struct lnet_ioctl_config_ni);
1403 data = calloc(1, len);
1405 return LUSTRE_CFG_RC_OUT_OF_MEM;
1406 conf = (struct lnet_ioctl_config_ni*) data;
1407 if (tunables != NULL)
1408 tun = (struct lnet_ioctl_config_lnd_tunables*)
1411 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1412 conf->lic_cfg_hdr.ioc_len = len;
1413 conf->lic_nid = nids[i];
1414 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1417 if (intf_descr->cpt_expr != NULL)
1418 cpt_expr = intf_descr->cpt_expr;
1419 else if (global_cpts != NULL)
1420 cpt_expr = global_cpts;
1424 if (cpt_expr != NULL) {
1425 count = cfs_expr_list_values(cpt_expr,
1426 LNET_MAX_SHOW_NUM_CPT,
1429 memcpy(conf->lic_cpts, cpt_array,
1430 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1439 conf->lic_ncpts = count;
1441 if (tunables != NULL)
1442 memcpy(tun, tunables, sizeof(*tunables));
1444 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1449 "\"cannot add network: %s\"", strerror(errno));
1457 return LUSTRE_CFG_RC_NO_ERR;
1461 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1462 struct lnet_ioctl_config_lnd_tunables *tunables,
1463 struct cfs_expr_list *global_cpts,
1464 int seq_no, struct cYAML **err_rc)
1466 lnet_nid_t *nids = NULL;
1469 char err_str[LNET_MAX_STR_LEN];
1471 snprintf(err_str, sizeof(err_str), "\"success\"");
1476 "\"incomplete ip2nets information\"");
1477 rc = LUSTRE_CFG_RC_BAD_PARAM;
1482 * call below function to resolve the rules into a list of nids.
1483 * The memory is allocated in that function then freed here when
1484 * it's no longer needed.
1486 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids);
1487 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH) {
1490 "\"cannot resolve ip2nets rule\"");
1494 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1495 snprintf(err_str, sizeof(err_str),
1496 "\"no interfaces match ip2nets rules\"");
1500 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1501 tunables, global_cpts, nids,
1508 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1512 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1513 struct cfs_expr_list *global_cpts,
1515 struct lnet_ioctl_config_lnd_tunables *tunables,
1516 int seq_no, struct cYAML **err_rc)
1519 struct lnet_ioctl_config_ni *conf;
1520 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1521 char buf[LNET_MAX_STR_LEN];
1522 int rc = LUSTRE_CFG_RC_NO_ERR;
1523 char err_str[LNET_MAX_STR_LEN];
1524 lnet_nid_t *nids = NULL;
1528 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1531 snprintf(err_str, sizeof(err_str), "\"success\"");
1533 if (ip2net == NULL && nw_descr == NULL) {
1536 "\"mandatory parameters not specified.\"");
1537 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1541 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1544 "\"ip2net string too long %d\"",
1545 (int)strlen(ip2net));
1546 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1550 if (ip2net != NULL) {
1551 if (tunables != NULL)
1552 len = sizeof(struct lnet_ioctl_config_ni) +
1553 sizeof(struct lnet_ioctl_config_lnd_tunables);
1555 len = sizeof(struct lnet_ioctl_config_ni);
1556 data = calloc(1, len);
1558 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1561 conf = (struct lnet_ioctl_config_ni*) data;
1562 if (tunables != NULL)
1563 tun = (struct lnet_ioctl_config_lnd_tunables*)
1564 (data + sizeof(*conf));
1566 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1567 conf->lic_cfg_hdr.ioc_len = len;
1568 strncpy(conf->lic_legacy_ip2nets, ip2net,
1571 if (global_cpts != NULL) {
1572 count = cfs_expr_list_values(global_cpts,
1573 LNET_MAX_SHOW_NUM_CPT,
1576 memcpy(conf->lic_cpts, cpt_array,
1577 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1586 conf->lic_ncpts = count;
1588 if (tunables != NULL)
1589 memcpy(tun, tunables, sizeof(*tunables));
1591 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1596 "\"cannot add network: %s\"", strerror(errno));
1603 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1604 rc = LUSTRE_CFG_RC_NO_ERR;
1608 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1611 "\"cannot parse net '%s'\"",
1612 libcfs_net2str(nw_descr->nw_id));
1613 rc = LUSTRE_CFG_RC_BAD_PARAM;
1617 if (list_empty(&nw_descr->nw_intflist)) {
1620 "\"no interface name provided\"");
1621 rc = LUSTRE_CFG_RC_BAD_PARAM;
1625 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1627 snprintf(err_str, sizeof(err_str),
1628 "\"bad parameter\"");
1629 rc = LUSTRE_CFG_RC_BAD_PARAM;
1633 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1634 tunables, global_cpts, nids,
1638 if (nw_descr != NULL) {
1639 list_for_each_entry_safe(intf_descr, tmp,
1640 &nw_descr->nw_intflist,
1642 list_del(&intf_descr->intf_on_network);
1643 free_intf_descr(intf_descr);
1647 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1658 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1659 int seq_no, struct cYAML **err_rc)
1661 struct lnet_ioctl_config_ni data;
1662 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1663 char err_str[LNET_MAX_STR_LEN];
1664 lnet_nid_t *nids = NULL;
1666 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1668 snprintf(err_str, sizeof(err_str), "\"success\"");
1670 if (nw_descr == NULL) {
1673 "\"missing mandatory parameter\"");
1674 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1678 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1679 return LUSTRE_CFG_RC_NO_ERR;
1681 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1684 "\"cannot parse net '%s'\"",
1685 libcfs_net2str(nw_descr->nw_id));
1686 rc = LUSTRE_CFG_RC_BAD_PARAM;
1690 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1692 snprintf(err_str, sizeof(err_str),
1693 "\"bad parameter\"");
1694 rc = LUSTRE_CFG_RC_BAD_PARAM;
1699 * no interfaces just the nw_id is specified
1702 nids = calloc(1, sizeof(*nids));
1704 snprintf(err_str, sizeof(err_str),
1705 "\"out of memory\"");
1706 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1709 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1713 for (i = 0; i < nnids; i++) {
1714 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1715 data.lic_nid = nids[i];
1717 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1722 "\"cannot del network: %s\"", strerror(errno));
1726 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1728 list_del(&intf_descr->intf_on_network);
1729 free_intf_descr(intf_descr);
1733 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1741 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1742 struct cYAML **show_rc, struct cYAML **err_rc)
1745 struct lnet_ioctl_config_ni *ni_data;
1746 struct lnet_ioctl_config_lnd_tunables *lnd;
1747 struct lnet_ioctl_element_stats *stats;
1748 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1749 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1750 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1752 struct cYAML *root = NULL, *tunables = NULL,
1753 *net_node = NULL, *interfaces = NULL,
1754 *item = NULL, *first_seq = NULL,
1755 *tmp = NULL, *statistics = NULL;
1756 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1757 char str_buf[str_buf_len];
1759 char err_str[LNET_MAX_STR_LEN];
1760 bool exist = false, new_net = true;
1762 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1764 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1766 buf = calloc(1, buf_size);
1770 ni_data = (struct lnet_ioctl_config_ni *)buf;
1773 net = libcfs_str2net(nw);
1774 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1777 "\"cannot parse net '%s'\"", nw);
1778 rc = LUSTRE_CFG_RC_BAD_PARAM;
1783 root = cYAML_create_object(NULL, NULL);
1787 net_node = cYAML_create_seq(root, "net");
1788 if (net_node == NULL)
1795 memset(buf, 0, buf_size);
1797 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1799 * set the ioc_len to the proper value since INIT assumes
1802 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1803 ni_data->lic_idx = i;
1805 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1811 rc_net = LNET_NIDNET(ni_data->lic_nid);
1813 /* filter on provided data */
1814 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1818 /* default rc to -1 in case we hit the goto */
1822 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
1823 lnd = (struct lnet_ioctl_config_lnd_tunables *)
1824 (ni_data->lic_bulk + sizeof(*stats));
1826 if (rc_net != prev_net) {
1833 if (!cYAML_create_string(net_node, "net type",
1834 libcfs_net2str(rc_net)))
1837 tmp = cYAML_create_seq(net_node, "local NI(s)");
1843 /* create the tree to be printed. */
1844 item = cYAML_create_seq_item(tmp);
1848 if (first_seq == NULL)
1851 if (cYAML_create_string(item, "nid",
1852 libcfs_nid2str(ni_data->lic_nid)) == NULL)
1855 if (cYAML_create_string(item,
1857 (ni_data->lic_status ==
1858 LNET_NI_STATUS_UP) ?
1859 "up" : "down") == NULL)
1862 /* don't add interfaces unless there is at least one
1864 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
1865 interfaces = cYAML_create_object(item, "interfaces");
1866 if (interfaces == NULL)
1869 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
1870 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
1872 sizeof(str_buf), "%d", j);
1873 if (cYAML_create_string(interfaces,
1875 ni_data->lic_ni_intf[j]) ==
1885 statistics = cYAML_create_object(item, "statistics");
1886 if (statistics == NULL)
1889 if (cYAML_create_number(statistics, "send_count",
1890 stats->iel_send_count)
1894 if (cYAML_create_number(statistics, "recv_count",
1895 stats->iel_recv_count)
1899 if (cYAML_create_number(statistics, "drop_count",
1900 stats->iel_drop_count)
1904 tunables = cYAML_create_object(item, "tunables");
1908 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
1909 if (rc != LUSTRE_CFG_RC_NO_ERR)
1912 tunables = cYAML_create_object(item, "lnd tunables");
1913 if (tunables == NULL)
1916 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
1918 if (rc != LUSTRE_CFG_RC_NO_ERR)
1921 if (cYAML_create_number(item, "tcp bonding",
1922 ni_data->lic_tcp_bonding)
1926 if (cYAML_create_number(item, "dev cpt",
1927 ni_data->lic_dev_cpt) == NULL)
1930 /* out put the CPTs in the format: "[x,x,x,...]" */
1931 limit = str_buf + str_buf_len - 3;
1932 pos += snprintf(pos, limit - pos, "\"[");
1933 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
1934 j < ni_data->lic_ncpts &&
1936 pos += snprintf(pos, limit - pos,
1937 "%d", ni_data->lic_cpts[j]);
1938 if ((j + 1) < ni_data->lic_ncpts)
1939 pos += snprintf(pos, limit - pos, ",");
1941 pos += snprintf(pos, 3, "]\"");
1943 if (ni_data->lic_ncpts >= 1 &&
1944 cYAML_create_string(item, "CPT",
1950 /* Print out the net information only if show_rc is not provided */
1951 if (show_rc == NULL)
1952 cYAML_print_tree(root);
1954 if (l_errno != ENOENT) {
1957 "\"cannot get networks: %s\"",
1962 rc = LUSTRE_CFG_RC_NO_ERR;
1964 snprintf(err_str, sizeof(err_str), "\"success\"");
1966 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1967 cYAML_free_tree(root);
1968 } else if (show_rc != NULL && *show_rc != NULL) {
1969 struct cYAML *show_node;
1970 /* find the net node, if one doesn't exist
1971 * then insert one. Otherwise add to the one there
1973 show_node = cYAML_get_object_item(*show_rc, "net");
1974 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1975 cYAML_insert_child(show_node, first_seq);
1978 } else if (show_node == NULL) {
1979 cYAML_insert_sibling((*show_rc)->cy_child,
1983 cYAML_free_tree(root);
1989 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
1994 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
1996 struct lnet_ioctl_config_data data;
1997 int rc = LUSTRE_CFG_RC_NO_ERR;
1998 char err_str[LNET_MAX_STR_LEN];
2000 snprintf(err_str, sizeof(err_str), "\"success\"");
2002 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2003 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2005 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2010 "\"cannot %s routing %s\"",
2011 (enable) ? "enable" : "disable", strerror(errno));
2016 cYAML_build_error(rc, seq_no,
2017 (enable) ? ADD_CMD : DEL_CMD,
2018 "routing", err_str, err_rc);
2023 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2025 int rc = LUSTRE_CFG_RC_NO_ERR;
2026 char err_str[LNET_MAX_STR_LEN];
2027 char val[LNET_MAX_STR_LEN];
2029 snprintf(err_str, sizeof(err_str), "\"success\"");
2031 snprintf(val, sizeof(val), "%d", max);
2033 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2034 1, strlen(val) + 1);
2036 snprintf(err_str, sizeof(err_str),
2037 "\"cannot configure max interfaces: %s\"",
2040 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2045 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2047 int rc = LUSTRE_CFG_RC_NO_ERR;
2048 char err_str[LNET_MAX_STR_LEN];
2049 char val[LNET_MAX_STR_LEN];
2051 snprintf(err_str, sizeof(err_str), "\"success\"");
2053 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2055 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2056 1, strlen(val) + 1);
2058 snprintf(err_str, sizeof(err_str),
2059 "\"cannot configure discovery: %s\"",
2062 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2068 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2070 struct lnet_ioctl_set_value data;
2071 int rc = LUSTRE_CFG_RC_NO_ERR;
2072 char err_str[LNET_MAX_STR_LEN];
2074 snprintf(err_str, sizeof(err_str), "\"success\"");
2079 "\"range must be >= 0\"");
2080 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2084 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2085 data.sv_value = range;
2087 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_NUMA_RANGE, &data);
2092 "\"cannot configure numa_range: %s\"", strerror(errno));
2097 cYAML_build_error(rc, seq_no, ADD_CMD, "numa_range", err_str, err_rc);
2102 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2103 struct cYAML **err_rc)
2105 struct lnet_ioctl_config_data data;
2106 int rc = LUSTRE_CFG_RC_NO_ERR;
2107 char err_str[LNET_MAX_STR_LEN];
2109 snprintf(err_str, sizeof(err_str), "\"success\"");
2111 /* -1 indicates to ignore changes to this field */
2112 if (tiny < -1 || small < -1 || large < -1) {
2115 "\"tiny, small and large must be >= 0\"");
2116 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2120 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2121 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2122 data.cfg_config_u.cfg_buffers.buf_small = small;
2123 data.cfg_config_u.cfg_buffers.buf_large = large;
2125 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2130 "\"cannot configure buffers: %s\"", strerror(errno));
2135 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2140 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2141 struct cYAML **err_rc)
2143 struct lnet_ioctl_config_data *data;
2144 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2145 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2148 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2149 int buf_count[LNET_NRBPOOLS] = {0};
2150 struct cYAML *root = NULL, *pools_node = NULL,
2151 *type_node = NULL, *item = NULL, *cpt = NULL,
2152 *first_seq = NULL, *buffers = NULL;
2154 char err_str[LNET_MAX_STR_LEN];
2155 char node_name[LNET_MAX_STR_LEN];
2158 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2160 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2164 data = (struct lnet_ioctl_config_data *)buf;
2166 root = cYAML_create_object(NULL, NULL);
2170 pools_node = cYAML_create_seq(root, "routing");
2171 if (pools_node == NULL)
2175 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2176 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2177 sizeof(struct lnet_ioctl_pool_cfg);
2178 data->cfg_count = i;
2180 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2188 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2190 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2191 item = cYAML_create_seq_item(pools_node);
2195 if (first_seq == NULL)
2198 cpt = cYAML_create_object(item, node_name);
2202 /* create the tree and print */
2203 for (j = 0; j < LNET_NRBPOOLS; j++) {
2204 type_node = cYAML_create_object(cpt, pools[j]);
2205 if (type_node == NULL)
2207 if (cYAML_create_number(type_node, "npages",
2208 pool_cfg->pl_pools[j].pl_npages)
2211 if (cYAML_create_number(type_node, "nbuffers",
2212 pool_cfg->pl_pools[j].
2213 pl_nbuffers) == NULL)
2215 if (cYAML_create_number(type_node, "credits",
2216 pool_cfg->pl_pools[j].
2217 pl_credits) == NULL)
2219 if (cYAML_create_number(type_node, "mincredits",
2220 pool_cfg->pl_pools[j].
2221 pl_mincredits) == NULL)
2223 /* keep track of the total count for each of the
2224 * tiny, small and large buffers */
2225 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2229 if (pool_cfg != NULL) {
2230 item = cYAML_create_seq_item(pools_node);
2234 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2239 /* create a buffers entry in the show. This is necessary so that
2240 * if the YAML output is used to configure a node, the buffer
2241 * configuration takes hold */
2242 buffers = cYAML_create_object(root, "buffers");
2243 if (buffers == NULL)
2246 for (i = 0; i < LNET_NRBPOOLS; i++) {
2247 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2251 if (show_rc == NULL)
2252 cYAML_print_tree(root);
2254 if (l_errno != ENOENT) {
2257 "\"cannot get routing information: %s\"",
2262 rc = LUSTRE_CFG_RC_NO_ERR;
2264 snprintf(err_str, sizeof(err_str), "\"success\"");
2265 rc = LUSTRE_CFG_RC_NO_ERR;
2269 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2270 cYAML_free_tree(root);
2271 } else if (show_rc != NULL && *show_rc != NULL) {
2272 struct cYAML *routing_node;
2273 /* there should exist only one routing block and one
2274 * buffers block. If there already exists a previous one
2275 * then don't add another */
2276 routing_node = cYAML_get_object_item(*show_rc, "routing");
2277 if (routing_node == NULL) {
2278 cYAML_insert_sibling((*show_rc)->cy_child,
2282 cYAML_free_tree(root);
2288 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2293 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2294 struct cYAML **show_rc, struct cYAML **err_rc)
2297 * TODO: This function is changing in a future patch to accommodate
2298 * PEER_LIST and proper filtering on any nid of the peer
2300 struct lnet_ioctl_peer_cfg peer_info;
2301 struct lnet_peer_ni_credit_info *lpni_cri;
2302 struct lnet_ioctl_element_stats *lpni_stats;
2304 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2310 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2311 *first_seq = NULL, *peer_root = NULL, *tmp = NULL;
2312 char err_str[LNET_MAX_STR_LEN];
2313 lnet_process_id_t *list = NULL;
2317 snprintf(err_str, sizeof(err_str),
2318 "\"out of memory\"");
2320 /* create struct cYAML root object */
2321 root = cYAML_create_object(NULL, NULL);
2325 peer_root = cYAML_create_seq(root, "peer");
2326 if (peer_root == NULL)
2330 size = count * sizeof(lnet_process_id_t);
2331 list = malloc(size);
2337 list[0].nid = libcfs_str2nid(knid);
2341 memset(&peer_info, 0, sizeof(peer_info));
2342 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2343 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2344 peer_info.prcfg_size = size;
2345 peer_info.prcfg_bulk = list;
2348 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2350 count = peer_info.prcfg_count;
2354 if (l_errno != E2BIG) {
2357 "\"cannot get peer list: %s\"",
2363 size = peer_info.prcfg_size;
2364 list = malloc(size);
2373 data = malloc(size);
2378 for (i = 0; i < count; i++) {
2380 memset(&peer_info, 0, sizeof(peer_info));
2381 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2382 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2383 peer_info.prcfg_prim_nid = list[i].nid;
2384 peer_info.prcfg_size = size;
2385 peer_info.prcfg_bulk = data;
2388 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2393 if (l_errno != E2BIG) {
2396 "\"cannot get peer information: %s\"",
2402 size = peer_info.prcfg_size;
2403 data = malloc(size);
2410 peer = cYAML_create_seq_item(peer_root);
2414 if (first_seq == NULL)
2417 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2418 if (cYAML_create_string(peer, "primary nid",
2419 libcfs_nid2str(pnid))
2422 if (cYAML_create_string(peer, "Multi-Rail",
2423 peer_info.prcfg_mr ? "True" : "False")
2427 tmp = cYAML_create_seq(peer, "peer ni");
2432 for (j = 0; j < peer_info.prcfg_count; j++) {
2434 lpni_cri = (void*)nidp + sizeof(nidp);
2435 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2436 lpni_data = (void *)lpni_stats + sizeof(*lpni_stats);
2438 peer_ni = cYAML_create_seq_item(tmp);
2439 if (peer_ni == NULL)
2442 if (cYAML_create_string(peer_ni, "nid",
2443 libcfs_nid2str(*nidp))
2447 if (cYAML_create_string(peer_ni, "state",
2448 lpni_cri->cr_aliveness)
2455 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2456 lpni_cri->cr_ni_peer_tx_credits)
2460 if (cYAML_create_number(peer_ni, "available_tx_credits",
2461 lpni_cri->cr_peer_tx_credits)
2465 if (cYAML_create_number(peer_ni, "min_tx_credits",
2466 lpni_cri->cr_peer_min_tx_credits)
2470 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2471 lpni_cri->cr_peer_tx_qnob)
2475 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2476 lpni_cri->cr_peer_rtr_credits)
2480 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2481 lpni_cri->cr_peer_min_rtr_credits)
2485 if (cYAML_create_number(peer_ni, "send_count",
2486 lpni_stats->iel_send_count)
2490 if (cYAML_create_number(peer_ni, "recv_count",
2491 lpni_stats->iel_recv_count)
2495 if (cYAML_create_number(peer_ni, "drop_count",
2496 lpni_stats->iel_drop_count)
2500 if (cYAML_create_number(peer_ni, "refcount",
2501 lpni_cri->cr_refcount) == NULL)
2506 /* print output iff show_rc is not provided */
2507 if (show_rc == NULL)
2508 cYAML_print_tree(root);
2510 snprintf(err_str, sizeof(err_str), "\"success\"");
2511 rc = LUSTRE_CFG_RC_NO_ERR;
2516 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2517 cYAML_free_tree(root);
2518 } else if (show_rc != NULL && *show_rc != NULL) {
2519 struct cYAML *show_node;
2520 /* find the peer node, if one doesn't exist then
2521 * insert one. Otherwise add to the one there
2523 show_node = cYAML_get_object_item(*show_rc,
2525 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2526 cYAML_insert_child(show_node, first_seq);
2529 } else if (show_node == NULL) {
2530 cYAML_insert_sibling((*show_rc)->cy_child,
2534 cYAML_free_tree(root);
2540 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
2546 int lustre_lnet_list_peer(int seq_no,
2547 struct cYAML **show_rc, struct cYAML **err_rc)
2549 struct lnet_ioctl_peer_cfg peer_info;
2550 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2555 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
2556 char err_str[LNET_MAX_STR_LEN];
2557 lnet_process_id_t *list = NULL;
2559 snprintf(err_str, sizeof(err_str),
2560 "\"out of memory\"");
2562 memset(&peer_info, 0, sizeof(peer_info));
2564 /* create struct cYAML root object */
2565 root = cYAML_create_object(NULL, NULL);
2569 list_root = cYAML_create_seq(root, "peer list");
2570 if (list_root == NULL)
2574 size = count * sizeof(lnet_process_id_t);
2575 list = malloc(size);
2581 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2582 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2583 peer_info.prcfg_size = size;
2584 peer_info.prcfg_bulk = list;
2587 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
2588 count = peer_info.prcfg_count;
2592 if (l_errno != E2BIG) {
2595 "\"cannot get peer list: %s\"",
2601 size = peer_info.prcfg_size;
2602 list = malloc(size);
2609 /* count is now the actual number of ids in the list. */
2610 for (i = 0; i < count; i++) {
2611 if (cYAML_create_string(list_root, "nid",
2612 libcfs_nid2str(list[i].nid))
2617 /* print output iff show_rc is not provided */
2618 if (show_rc == NULL)
2619 cYAML_print_tree(root);
2621 snprintf(err_str, sizeof(err_str), "\"success\"");
2622 rc = LUSTRE_CFG_RC_NO_ERR;
2627 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2628 cYAML_free_tree(root);
2629 } else if (show_rc != NULL && *show_rc != NULL) {
2630 struct cYAML *show_node;
2631 /* find the peer node, if one doesn't exist then
2632 * insert one. Otherwise add to the one there
2634 show_node = cYAML_get_object_item(*show_rc,
2636 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2637 cYAML_insert_child(show_node, first_seq);
2640 } else if (show_node == NULL) {
2641 cYAML_insert_sibling((*show_rc)->cy_child,
2645 cYAML_free_tree(root);
2651 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
2657 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
2660 struct cYAML *show_node;
2662 show_node = cYAML_get_object_item(show_rc, "global");
2663 if (show_node != NULL)
2664 cYAML_insert_sibling(show_node->cy_child,
2667 cYAML_insert_sibling(show_rc->cy_child,
2672 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
2673 struct cYAML **err_rc)
2675 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2676 char val[LNET_MAX_STR_LEN];
2678 char err_str[LNET_MAX_STR_LEN];
2679 struct cYAML *root = NULL, *global = NULL;
2681 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2683 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2684 1, LNET_MAX_STR_LEN);
2686 snprintf(err_str, sizeof(err_str),
2687 "\"cannot get max interfaces: %d\"", rc);
2691 max_intf = atoi(val);
2693 root = cYAML_create_object(NULL, NULL);
2697 global = cYAML_create_object(root, "global");
2701 if (cYAML_create_number(global, "max_intf",
2705 if (show_rc == NULL)
2706 cYAML_print_tree(root);
2708 snprintf(err_str, sizeof(err_str), "\"success\"");
2710 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR)
2711 cYAML_free_tree(root);
2712 else if (show_rc != NULL && *show_rc != NULL)
2713 add_to_global(*show_rc, global, root);
2717 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2722 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
2723 struct cYAML **err_rc)
2725 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2726 char val[LNET_MAX_STR_LEN];
2728 char err_str[LNET_MAX_STR_LEN];
2729 struct cYAML *root = NULL, *global = NULL;
2731 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2733 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2736 snprintf(err_str, sizeof(err_str),
2737 "\"cannot get discovery value: %d\"", rc);
2742 * the sysfs parameter read indicates if discovery is disabled,
2743 * but we report if discovery is enabled.
2745 discovery = !atoi(val);
2747 root = cYAML_create_object(NULL, NULL);
2751 global = cYAML_create_object(root, "global");
2755 if (cYAML_create_number(global, "discovery",
2759 if (show_rc == NULL)
2760 cYAML_print_tree(root);
2762 snprintf(err_str, sizeof(err_str), "\"success\"");
2764 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2765 cYAML_free_tree(root);
2766 } else if (show_rc != NULL && *show_rc != NULL) {
2767 add_to_global(*show_rc, global, root);
2772 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2777 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
2778 struct cYAML **err_rc)
2780 struct lnet_ioctl_set_value data;
2783 char err_str[LNET_MAX_STR_LEN];
2784 struct cYAML *root = NULL, *global = NULL;
2786 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2788 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2790 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NUMA_RANGE, &data);
2795 "\"cannot get numa range: %s\"",
2801 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2803 root = cYAML_create_object(NULL, NULL);
2807 global = cYAML_create_object(root, "global");
2811 if (cYAML_create_number(global, "numa_range",
2812 data.sv_value) == NULL)
2815 if (show_rc == NULL)
2816 cYAML_print_tree(root);
2818 snprintf(err_str, sizeof(err_str), "\"success\"");
2819 rc = LUSTRE_CFG_RC_NO_ERR;
2821 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2822 cYAML_free_tree(root);
2823 } else if (show_rc != NULL && *show_rc != NULL) {
2824 add_to_global(*show_rc, global, root);
2829 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2834 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
2835 struct cYAML **err_rc)
2837 struct lnet_ioctl_lnet_stats data;
2840 char err_str[LNET_MAX_STR_LEN];
2841 struct cYAML *root = NULL, *stats = NULL;
2843 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2845 LIBCFS_IOC_INIT_V2(data, st_hdr);
2847 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
2852 "\"cannot get lnet statistics: %s\"",
2858 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2860 root = cYAML_create_object(NULL, NULL);
2864 stats = cYAML_create_object(root, "statistics");
2868 if (cYAML_create_number(stats, "msgs_alloc",
2869 data.st_cntrs.msgs_alloc) == NULL)
2872 if (cYAML_create_number(stats, "msgs_max",
2873 data.st_cntrs.msgs_max) == NULL)
2876 if (cYAML_create_number(stats, "errors",
2877 data.st_cntrs.errors) == NULL)
2880 if (cYAML_create_number(stats, "send_count",
2881 data.st_cntrs.send_count) == NULL)
2884 if (cYAML_create_number(stats, "recv_count",
2885 data.st_cntrs.recv_count) == NULL)
2888 if (cYAML_create_number(stats, "route_count",
2889 data.st_cntrs.route_count) == NULL)
2892 if (cYAML_create_number(stats, "drop_count",
2893 data.st_cntrs.drop_count) == NULL)
2896 if (cYAML_create_number(stats, "send_length",
2897 data.st_cntrs.send_length) == NULL)
2900 if (cYAML_create_number(stats, "recv_length",
2901 data.st_cntrs.recv_length) == NULL)
2904 if (cYAML_create_number(stats, "route_length",
2905 data.st_cntrs.route_length) == NULL)
2908 if (cYAML_create_number(stats, "drop_length",
2909 data.st_cntrs.drop_length) == NULL)
2912 if (show_rc == NULL)
2913 cYAML_print_tree(root);
2915 snprintf(err_str, sizeof(err_str), "\"success\"");
2916 rc = LUSTRE_CFG_RC_NO_ERR;
2918 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2919 cYAML_free_tree(root);
2920 } else if (show_rc != NULL && *show_rc != NULL) {
2921 cYAML_insert_sibling((*show_rc)->cy_child,
2928 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
2933 typedef int (*cmd_handler_t)(struct cYAML *tree,
2934 struct cYAML **show_rc,
2935 struct cYAML **err_rc);
2937 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
2938 struct cYAML **err_rc)
2940 struct cYAML *net, *gw, *hop, *prio, *seq_no;
2942 net = cYAML_get_object_item(tree, "net");
2943 gw = cYAML_get_object_item(tree, "gateway");
2944 hop = cYAML_get_object_item(tree, "hop");
2945 prio = cYAML_get_object_item(tree, "priority");
2946 seq_no = cYAML_get_object_item(tree, "seq_no");
2948 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
2949 (gw) ? gw->cy_valuestring : NULL,
2950 (hop) ? hop->cy_valueint : -1,
2951 (prio) ? prio->cy_valueint : -1,
2952 (seq_no) ? seq_no->cy_valueint : -1,
2956 static void yaml_free_string_array(char **array, int num)
2959 char **sub_array = array;
2961 for (i = 0; i < num; i++) {
2962 if (*sub_array != NULL)
2972 * 0: <intf_name>['['<expr>']']
2973 * 1: <intf_name>['['<expr>']']
2975 static int yaml_copy_intf_info(struct cYAML *intf_tree,
2976 struct lnet_dlc_network_descr *nw_descr)
2978 struct cYAML *child = NULL;
2979 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
2980 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2982 if (intf_tree == NULL || nw_descr == NULL)
2983 return LUSTRE_CFG_RC_BAD_PARAM;
2985 /* now grab all the interfaces and their cpts */
2986 child = intf_tree->cy_child;
2987 while (child != NULL) {
2988 if (child->cy_valuestring == NULL) {
2989 child = child->cy_next;
2993 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
2996 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
2997 child->cy_valuestring,
2998 strlen(child->cy_valuestring));
2999 if (rc != LUSTRE_CFG_RC_NO_ERR)
3003 child = child->cy_next;
3007 return LUSTRE_CFG_RC_MISSING_PARAM;
3012 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3014 list_del(&intf_descr->intf_on_network);
3015 free_intf_descr(intf_descr);
3022 yaml_extract_cmn_tunables(struct cYAML *tree,
3023 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3024 struct cfs_expr_list **global_cpts)
3026 struct cYAML *tun, *item, *smp;
3029 tun = cYAML_get_object_item(tree, "tunables");
3031 item = cYAML_get_object_item(tun, "peer_timeout");
3033 tunables->lct_peer_timeout = item->cy_valueint;
3034 item = cYAML_get_object_item(tun, "peer_credits");
3036 tunables->lct_peer_tx_credits = item->cy_valueint;
3037 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3039 tunables->lct_peer_rtr_credits = item->cy_valueint;
3040 item = cYAML_get_object_item(tun, "credits");
3042 tunables->lct_max_tx_credits = item->cy_valueint;
3043 smp = cYAML_get_object_item(tun, "CPT");
3045 rc = cfs_expr_list_parse(smp->cy_valuestring,
3046 strlen(smp->cy_valuestring),
3047 0, UINT_MAX, global_cpts);
3049 *global_cpts = NULL;
3059 yaml_extract_tunables(struct cYAML *tree,
3060 struct lnet_ioctl_config_lnd_tunables *tunables,
3061 struct cfs_expr_list **global_cpts,
3066 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3072 lustre_yaml_extract_lnd_tunables(tree, net_type,
3080 * - net type: <net>[<NUM>]
3082 * - nid: <ip>@<net>[<NUM>]
3085 * 0: <intf_name>['['<expr>']']
3086 * 1: <intf_name>['['<expr>']']
3088 * peer_timeout: <NUM>
3089 * peer_credits: <NUM>
3090 * peer_buffer_credits: <NUM>
3093 * peercredits_hiw: <NUM>
3094 * map_on_demand: <NUM>
3095 * concurrent_sends: <NUM>
3096 * fmr_pool_size: <NUM>
3097 * fmr_flush_trigger: <NUM>
3100 * At least one interface is required. If no interfaces are provided the
3101 * network interface can not be configured.
3103 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3104 struct cYAML **err_rc)
3106 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3108 int num_entries = 0, rc;
3109 struct lnet_dlc_network_descr nw_descr;
3110 struct cfs_expr_list *global_cpts = NULL;
3111 struct lnet_ioctl_config_lnd_tunables tunables;
3114 memset(&tunables, 0, sizeof(tunables));
3116 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3117 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3119 ip2net = cYAML_get_object_item(tree, "ip2net");
3120 net = cYAML_get_object_item(tree, "net type");
3122 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3124 nw_descr.nw_id = LOLND;
3127 * if neither net nor ip2nets are present, then we can not
3128 * configure the network.
3130 if (!net && !ip2net)
3131 return LUSTRE_CFG_RC_MISSING_PARAM;
3133 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3134 if (local_nis == NULL)
3135 return LUSTRE_CFG_RC_MISSING_PARAM;
3137 if (!cYAML_is_sequence(local_nis))
3138 return LUSTRE_CFG_RC_BAD_PARAM;
3140 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3141 intf = cYAML_get_object_item(item, "interfaces");
3144 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3145 if (num_entries <= 0) {
3146 cYAML_build_error(num_entries, -1, "ni", "add",
3147 "bad interface list",
3149 return LUSTRE_CFG_RC_BAD_PARAM;
3153 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3154 LNET_NETTYP(nw_descr.nw_id));
3155 seq_no = cYAML_get_object_item(tree, "seq_no");
3157 rc = lustre_lnet_config_ni(&nw_descr,
3159 (ip2net) ? ip2net->cy_valuestring : NULL,
3160 (found) ? &tunables: NULL,
3161 (seq_no) ? seq_no->cy_valueint : -1,
3164 if (global_cpts != NULL)
3165 cfs_expr_list_free(global_cpts);
3172 * - net-spec: <tcp|o2ib|gni>[NUM]
3174 * 0: <intf name>['['<expr>']']
3175 * 1: <intf name>['['<expr>']']
3177 * 0: <expr.expr.expr.expr>
3178 * 1: <expr.expr.expr.expr>
3180 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3181 struct cYAML **show_rc,
3182 struct cYAML **err_rc)
3184 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3186 struct lustre_lnet_ip2nets ip2nets;
3187 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3189 int rc = LUSTRE_CFG_RC_NO_ERR;
3190 struct cfs_expr_list *global_cpts = NULL;
3191 struct cfs_expr_list *el, *el_tmp;
3192 struct lnet_ioctl_config_lnd_tunables tunables;
3193 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3196 memset(&tunables, 0, sizeof(tunables));
3198 /* initialize all lists */
3199 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
3200 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
3201 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
3203 net = cYAML_get_object_item(tree, "net-spec");
3205 return LUSTRE_CFG_RC_BAD_PARAM;
3207 if (net != NULL && net->cy_valuestring == NULL)
3208 return LUSTRE_CFG_RC_BAD_PARAM;
3210 /* assign the network id */
3211 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
3212 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
3213 return LUSTRE_CFG_RC_BAD_PARAM;
3215 seq_no = cYAML_get_object_item(tree, "seq_no");
3217 intf = cYAML_get_object_item(tree, "interfaces");
3219 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
3221 return LUSTRE_CFG_RC_BAD_PARAM;
3224 ip_range = cYAML_get_object_item(tree, "ip-range");
3225 if (ip_range != NULL) {
3226 item = ip_range->cy_child;
3227 while (item != NULL) {
3228 if (item->cy_valuestring == NULL) {
3229 item = item->cy_next;
3233 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
3234 item->cy_valuestring);
3236 if (rc != LUSTRE_CFG_RC_NO_ERR)
3239 item = item->cy_next;
3243 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3244 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
3246 rc = lustre_lnet_config_ip2nets(&ip2nets,
3247 (found) ? &tunables : NULL,
3249 (seq_no) ? seq_no->cy_valueint : -1,
3253 * don't stop because there was no match. Continue processing the
3254 * rest of the rules. If non-match then nothing is configured
3256 if (rc == LUSTRE_CFG_RC_NO_MATCH)
3257 rc = LUSTRE_CFG_RC_NO_ERR;
3259 list_for_each_entry_safe(intf_descr, intf_tmp,
3260 &ip2nets.ip2nets_net.nw_intflist,
3262 list_del(&intf_descr->intf_on_network);
3263 free_intf_descr(intf_descr);
3266 list_for_each_entry_safe(ip_range_descr, tmp,
3267 &ip2nets.ip2nets_ip_ranges,
3269 list_del(&ip_range_descr->ipr_entry);
3270 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
3272 list_del(&el->el_link);
3273 cfs_expr_list_free(el);
3275 free(ip_range_descr);
3281 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
3282 struct cYAML **err_rc)
3284 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
3286 int num_entries, rc;
3287 struct lnet_dlc_network_descr nw_descr;
3289 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3290 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3292 net = cYAML_get_object_item(tree, "net type");
3294 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3296 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3297 if (local_nis == NULL)
3298 return LUSTRE_CFG_RC_MISSING_PARAM;
3300 if (!cYAML_is_sequence(local_nis))
3301 return LUSTRE_CFG_RC_BAD_PARAM;
3303 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3304 intf = cYAML_get_object_item(item, "interfaces");
3307 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3308 if (num_entries <= 0) {
3309 cYAML_build_error(num_entries, -1, "ni", "add",
3310 "bad interface list",
3312 return LUSTRE_CFG_RC_BAD_PARAM;
3316 seq_no = cYAML_get_object_item(tree, "seq_no");
3318 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
3319 (seq_no) ? seq_no->cy_valueint : -1,
3325 static int yaml_copy_peer_nids(struct cYAML *tree, char ***nidsppp, bool del)
3327 struct cYAML *nids_entry = NULL, *child = NULL, *entry = NULL,
3330 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3332 prim_nid = cYAML_get_object_item(tree, "primary nid");
3333 if (!prim_nid || !prim_nid->cy_valuestring)
3334 return LUSTRE_CFG_RC_MISSING_PARAM;
3336 nids_entry = cYAML_get_object_item(tree, "peer ni");
3337 if (cYAML_is_sequence(nids_entry)) {
3338 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3339 entry = cYAML_get_object_item(child, "nid");
3340 /* don't count an empty entry */
3341 if (!entry || !entry->cy_valuestring)
3344 if ((strcmp(entry->cy_valuestring, prim_nid->cy_valuestring)
3347 * primary nid is present in the list of
3348 * nids so that means we want to delete
3349 * the entire peer, so no need to go
3350 * further. Just delete the entire peer.
3360 return LUSTRE_CFG_RC_MISSING_PARAM;
3362 nids = calloc(sizeof(*nids) * num, 1);
3364 return LUSTRE_CFG_RC_OUT_OF_MEM;
3366 /* now grab all the nids */
3369 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3370 entry = cYAML_get_object_item(child, "nid");
3371 if (!entry || !entry->cy_valuestring)
3374 nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
3376 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3379 strncpy(nids[num], entry->cy_valuestring,
3380 strlen(entry->cy_valuestring));
3390 yaml_free_string_array(nids, num);
3395 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
3396 struct cYAML **err_rc)
3400 struct cYAML *seq_no, *prim_nid, *non_mr;
3402 num = yaml_copy_peer_nids(tree, &nids, false);
3406 seq_no = cYAML_get_object_item(tree, "seq_no");
3407 prim_nid = cYAML_get_object_item(tree, "primary nid");
3408 non_mr = cYAML_get_object_item(tree, "non_mr");
3410 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3412 (non_mr) ? false : true,
3413 (seq_no) ? seq_no->cy_valueint : -1,
3416 yaml_free_string_array(nids, num);
3420 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
3421 struct cYAML **err_rc)
3425 struct cYAML *seq_no, *prim_nid;
3427 num = yaml_copy_peer_nids(tree, &nids, true);
3431 seq_no = cYAML_get_object_item(tree, "seq_no");
3432 prim_nid = cYAML_get_object_item(tree, "primary nid");
3434 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3436 (seq_no) ? seq_no->cy_valueint : -1,
3439 yaml_free_string_array(nids, num);
3443 static int handle_yaml_config_buffers(struct cYAML *tree,
3444 struct cYAML **show_rc,
3445 struct cYAML **err_rc)
3448 struct cYAML *tiny, *small, *large, *seq_no;
3450 tiny = cYAML_get_object_item(tree, "tiny");
3451 small = cYAML_get_object_item(tree, "small");
3452 large = cYAML_get_object_item(tree, "large");
3453 seq_no = cYAML_get_object_item(tree, "seq_no");
3455 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
3456 (small) ? small->cy_valueint : -1,
3457 (large) ? large->cy_valueint : -1,
3458 (seq_no) ? seq_no->cy_valueint : -1,
3464 static int handle_yaml_config_routing(struct cYAML *tree,
3465 struct cYAML **show_rc,
3466 struct cYAML **err_rc)
3468 int rc = LUSTRE_CFG_RC_NO_ERR;
3469 struct cYAML *seq_no, *enable;
3471 seq_no = cYAML_get_object_item(tree, "seq_no");
3472 enable = cYAML_get_object_item(tree, "enable");
3475 rc = lustre_lnet_enable_routing(enable->cy_valueint,
3477 seq_no->cy_valueint : -1,
3484 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
3485 struct cYAML **err_rc)
3489 struct cYAML *seq_no;
3491 net = cYAML_get_object_item(tree, "net");
3492 gw = cYAML_get_object_item(tree, "gateway");
3493 seq_no = cYAML_get_object_item(tree, "seq_no");
3495 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
3496 (gw) ? gw->cy_valuestring : NULL,
3497 (seq_no) ? seq_no->cy_valueint : -1,
3501 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
3502 struct cYAML **err_rc)
3504 struct cYAML *seq_no;
3506 seq_no = cYAML_get_object_item(tree, "seq_no");
3508 return lustre_lnet_enable_routing(0, (seq_no) ?
3509 seq_no->cy_valueint : -1,
3513 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
3514 struct cYAML **err_rc)
3520 struct cYAML *detail;
3521 struct cYAML *seq_no;
3523 net = cYAML_get_object_item(tree, "net");
3524 gw = cYAML_get_object_item(tree, "gateway");
3525 hop = cYAML_get_object_item(tree, "hop");
3526 prio = cYAML_get_object_item(tree, "priority");
3527 detail = cYAML_get_object_item(tree, "detail");
3528 seq_no = cYAML_get_object_item(tree, "seq_no");
3530 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
3531 (gw) ? gw->cy_valuestring : NULL,
3532 (hop) ? hop->cy_valueint : -1,
3533 (prio) ? prio->cy_valueint : -1,
3534 (detail) ? detail->cy_valueint : 0,
3535 (seq_no) ? seq_no->cy_valueint : -1,
3540 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
3541 struct cYAML **err_rc)
3543 struct cYAML *net, *detail, *seq_no;
3545 net = cYAML_get_object_item(tree, "net");
3546 detail = cYAML_get_object_item(tree, "detail");
3547 seq_no = cYAML_get_object_item(tree, "seq_no");
3549 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
3550 (detail) ? detail->cy_valueint : 0,
3551 (seq_no) ? seq_no->cy_valueint : -1,
3556 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
3557 struct cYAML **err_rc)
3559 struct cYAML *seq_no;
3561 seq_no = cYAML_get_object_item(tree, "seq_no");
3563 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
3567 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
3568 struct cYAML **err_rc)
3570 struct cYAML *seq_no, *nid, *detail;
3572 seq_no = cYAML_get_object_item(tree, "seq_no");
3573 detail = cYAML_get_object_item(tree, "detail");
3574 nid = cYAML_get_object_item(tree, "nid");
3576 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
3577 (detail) ? detail->cy_valueint : 0,
3578 (seq_no) ? seq_no->cy_valueint : -1,
3582 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
3583 struct cYAML **err_rc)
3585 struct cYAML *seq_no;
3587 seq_no = cYAML_get_object_item(tree, "seq_no");
3589 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
3593 static int handle_yaml_config_global_settings(struct cYAML *tree,
3594 struct cYAML **show_rc,
3595 struct cYAML **err_rc)
3597 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3600 seq_no = cYAML_get_object_item(tree, "seq_no");
3601 max_intf = cYAML_get_object_item(tree, "max_intf");
3603 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
3604 seq_no ? seq_no->cy_valueint
3608 numa = cYAML_get_object_item(tree, "numa_range");
3610 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
3611 seq_no ? seq_no->cy_valueint
3615 discovery = cYAML_get_object_item(tree, "discovery");
3617 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
3618 seq_no ? seq_no->cy_valueint
3625 static int handle_yaml_del_global_settings(struct cYAML *tree,
3626 struct cYAML **show_rc,
3627 struct cYAML **err_rc)
3629 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3632 seq_no = cYAML_get_object_item(tree, "seq_no");
3633 max_intf = cYAML_get_object_item(tree, "max_intf");
3635 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
3636 seq_no ? seq_no->cy_valueint
3640 numa = cYAML_get_object_item(tree, "numa_range");
3642 rc = lustre_lnet_config_numa_range(0,
3643 seq_no ? seq_no->cy_valueint
3647 /* peer discovery is enabled by default */
3648 discovery = cYAML_get_object_item(tree, "discovery");
3650 rc = lustre_lnet_config_discovery(1,
3651 seq_no ? seq_no->cy_valueint
3658 static int handle_yaml_show_global_settings(struct cYAML *tree,
3659 struct cYAML **show_rc,
3660 struct cYAML **err_rc)
3662 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3665 seq_no = cYAML_get_object_item(tree, "seq_no");
3666 max_intf = cYAML_get_object_item(tree, "max_intf");
3668 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
3672 numa = cYAML_get_object_item(tree, "numa_range");
3674 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
3678 discovery = cYAML_get_object_item(tree, "discovery");
3680 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
3687 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
3688 struct cYAML **err_rc)
3690 struct cYAML *seq_no, *nid, *timeout;
3692 seq_no = cYAML_get_object_item(tree, "seq_no");
3693 nid = cYAML_get_object_item(tree, "primary nid");
3694 timeout = cYAML_get_object_item(tree, "timeout");
3696 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
3697 (timeout) ? timeout->cy_valueint : 1000,
3698 (seq_no) ? seq_no->cy_valueint : -1,
3702 static int handle_yaml_no_op()
3704 return LUSTRE_CFG_RC_NO_ERR;
3707 struct lookup_cmd_hdlr_tbl {
3712 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
3713 { .name = "route", .cb = handle_yaml_config_route },
3714 { .name = "net", .cb = handle_yaml_config_ni },
3715 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
3716 { .name = "peer", .cb = handle_yaml_config_peer },
3717 { .name = "routing", .cb = handle_yaml_config_routing },
3718 { .name = "buffers", .cb = handle_yaml_config_buffers },
3719 { .name = "statistics", .cb = handle_yaml_no_op },
3720 { .name = "global", .cb = handle_yaml_config_global_settings},
3721 { .name = "ping", .cb = handle_yaml_no_op },
3724 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
3725 { .name = "route", .cb = handle_yaml_del_route },
3726 { .name = "net", .cb = handle_yaml_del_ni },
3727 { .name = "ip2nets", .cb = handle_yaml_no_op },
3728 { .name = "peer", .cb = handle_yaml_del_peer },
3729 { .name = "routing", .cb = handle_yaml_del_routing },
3730 { .name = "buffers", .cb = handle_yaml_no_op },
3731 { .name = "statistics", .cb = handle_yaml_no_op },
3732 { .name = "global", .cb = handle_yaml_del_global_settings},
3733 { .name = "ping", .cb = handle_yaml_no_op },
3736 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
3737 { .name = "route", .cb = handle_yaml_show_route },
3738 { .name = "net", .cb = handle_yaml_show_net },
3739 { .name = "peer", .cb = handle_yaml_show_peers },
3740 { .name = "ip2nets", .cb = handle_yaml_no_op },
3741 { .name = "routing", .cb = handle_yaml_show_routing },
3742 { .name = "buffers", .cb = handle_yaml_show_routing },
3743 { .name = "statistics", .cb = handle_yaml_show_stats },
3744 { .name = "global", .cb = handle_yaml_show_global_settings},
3745 { .name = "ping", .cb = handle_yaml_no_op },
3748 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
3749 { .name = "route", .cb = handle_yaml_no_op },
3750 { .name = "net", .cb = handle_yaml_no_op },
3751 { .name = "peer", .cb = handle_yaml_no_op },
3752 { .name = "ip2nets", .cb = handle_yaml_no_op },
3753 { .name = "routing", .cb = handle_yaml_no_op },
3754 { .name = "buffers", .cb = handle_yaml_no_op },
3755 { .name = "statistics", .cb = handle_yaml_no_op },
3756 { .name = "global", .cb = handle_yaml_no_op },
3757 { .name = "ping", .cb = handle_yaml_ping },
3760 static cmd_handler_t lookup_fn(char *key,
3761 struct lookup_cmd_hdlr_tbl *tbl)
3767 for (i = 0; tbl[i].name != NULL; i++) {
3768 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
3775 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
3776 struct cYAML **show_rc, struct cYAML **err_rc)
3778 struct cYAML *tree, *item = NULL, *head, *child;
3780 char err_str[LNET_MAX_STR_LEN];
3781 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
3783 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
3785 return LUSTRE_CFG_RC_BAD_PARAM;
3787 child = tree->cy_child;
3788 while (child != NULL) {
3789 cb = lookup_fn(child->cy_string, table);
3791 snprintf(err_str, sizeof(err_str),
3792 "\"call back for '%s' not found\"",
3794 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
3795 "yaml", "helper", err_str, err_rc);
3799 if (cYAML_is_sequence(child)) {
3800 while ((head = cYAML_get_next_seq_item(child, &item))
3802 rc = cb(head, show_rc, err_rc);
3803 if (rc != LUSTRE_CFG_RC_NO_ERR)
3807 rc = cb(child, show_rc, err_rc);
3808 if (rc != LUSTRE_CFG_RC_NO_ERR)
3812 child = child->cy_next;
3816 cYAML_free_tree(tree);
3821 int lustre_yaml_config(char *f, struct cYAML **err_rc)
3823 return lustre_yaml_cb_helper(f, lookup_config_tbl,
3827 int lustre_yaml_del(char *f, struct cYAML **err_rc)
3829 return lustre_yaml_cb_helper(f, lookup_del_tbl,
3833 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3835 return lustre_yaml_cb_helper(f, lookup_show_tbl,
3839 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3841 return lustre_yaml_cb_helper(f, lookup_exec_tbl,