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\"");
2709 rc = LUSTRE_CFG_RC_NO_ERR;
2712 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR)
2713 cYAML_free_tree(root);
2714 else if (show_rc != NULL && *show_rc != NULL)
2715 add_to_global(*show_rc, global, root);
2719 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2724 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
2725 struct cYAML **err_rc)
2727 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2728 char val[LNET_MAX_STR_LEN];
2730 char err_str[LNET_MAX_STR_LEN];
2731 struct cYAML *root = NULL, *global = NULL;
2733 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2735 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2738 snprintf(err_str, sizeof(err_str),
2739 "\"cannot get discovery value: %d\"", rc);
2744 * the sysfs parameter read indicates if discovery is disabled,
2745 * but we report if discovery is enabled.
2747 discovery = !atoi(val);
2749 root = cYAML_create_object(NULL, NULL);
2753 global = cYAML_create_object(root, "global");
2757 if (cYAML_create_number(global, "discovery",
2761 if (show_rc == NULL)
2762 cYAML_print_tree(root);
2764 snprintf(err_str, sizeof(err_str), "\"success\"");
2766 rc = LUSTRE_CFG_RC_NO_ERR;
2769 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2770 cYAML_free_tree(root);
2771 } else if (show_rc != NULL && *show_rc != NULL) {
2772 add_to_global(*show_rc, global, root);
2777 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2782 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
2783 struct cYAML **err_rc)
2785 struct lnet_ioctl_set_value data;
2788 char err_str[LNET_MAX_STR_LEN];
2789 struct cYAML *root = NULL, *global = NULL;
2791 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2793 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2795 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NUMA_RANGE, &data);
2800 "\"cannot get numa range: %s\"",
2806 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2808 root = cYAML_create_object(NULL, NULL);
2812 global = cYAML_create_object(root, "global");
2816 if (cYAML_create_number(global, "numa_range",
2817 data.sv_value) == NULL)
2820 if (show_rc == NULL)
2821 cYAML_print_tree(root);
2823 snprintf(err_str, sizeof(err_str), "\"success\"");
2824 rc = LUSTRE_CFG_RC_NO_ERR;
2826 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2827 cYAML_free_tree(root);
2828 } else if (show_rc != NULL && *show_rc != NULL) {
2829 add_to_global(*show_rc, global, root);
2834 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2839 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
2840 struct cYAML **err_rc)
2842 struct lnet_ioctl_lnet_stats data;
2845 char err_str[LNET_MAX_STR_LEN];
2846 struct cYAML *root = NULL, *stats = NULL;
2848 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2850 LIBCFS_IOC_INIT_V2(data, st_hdr);
2852 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
2857 "\"cannot get lnet statistics: %s\"",
2863 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2865 root = cYAML_create_object(NULL, NULL);
2869 stats = cYAML_create_object(root, "statistics");
2873 if (cYAML_create_number(stats, "msgs_alloc",
2874 data.st_cntrs.msgs_alloc) == NULL)
2877 if (cYAML_create_number(stats, "msgs_max",
2878 data.st_cntrs.msgs_max) == NULL)
2881 if (cYAML_create_number(stats, "errors",
2882 data.st_cntrs.errors) == NULL)
2885 if (cYAML_create_number(stats, "send_count",
2886 data.st_cntrs.send_count) == NULL)
2889 if (cYAML_create_number(stats, "recv_count",
2890 data.st_cntrs.recv_count) == NULL)
2893 if (cYAML_create_number(stats, "route_count",
2894 data.st_cntrs.route_count) == NULL)
2897 if (cYAML_create_number(stats, "drop_count",
2898 data.st_cntrs.drop_count) == NULL)
2901 if (cYAML_create_number(stats, "send_length",
2902 data.st_cntrs.send_length) == NULL)
2905 if (cYAML_create_number(stats, "recv_length",
2906 data.st_cntrs.recv_length) == NULL)
2909 if (cYAML_create_number(stats, "route_length",
2910 data.st_cntrs.route_length) == NULL)
2913 if (cYAML_create_number(stats, "drop_length",
2914 data.st_cntrs.drop_length) == NULL)
2917 if (show_rc == NULL)
2918 cYAML_print_tree(root);
2920 snprintf(err_str, sizeof(err_str), "\"success\"");
2921 rc = LUSTRE_CFG_RC_NO_ERR;
2923 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2924 cYAML_free_tree(root);
2925 } else if (show_rc != NULL && *show_rc != NULL) {
2926 cYAML_insert_sibling((*show_rc)->cy_child,
2933 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
2938 typedef int (*cmd_handler_t)(struct cYAML *tree,
2939 struct cYAML **show_rc,
2940 struct cYAML **err_rc);
2942 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
2943 struct cYAML **err_rc)
2945 struct cYAML *net, *gw, *hop, *prio, *seq_no;
2947 net = cYAML_get_object_item(tree, "net");
2948 gw = cYAML_get_object_item(tree, "gateway");
2949 hop = cYAML_get_object_item(tree, "hop");
2950 prio = cYAML_get_object_item(tree, "priority");
2951 seq_no = cYAML_get_object_item(tree, "seq_no");
2953 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
2954 (gw) ? gw->cy_valuestring : NULL,
2955 (hop) ? hop->cy_valueint : -1,
2956 (prio) ? prio->cy_valueint : -1,
2957 (seq_no) ? seq_no->cy_valueint : -1,
2961 static void yaml_free_string_array(char **array, int num)
2964 char **sub_array = array;
2966 for (i = 0; i < num; i++) {
2967 if (*sub_array != NULL)
2977 * 0: <intf_name>['['<expr>']']
2978 * 1: <intf_name>['['<expr>']']
2980 static int yaml_copy_intf_info(struct cYAML *intf_tree,
2981 struct lnet_dlc_network_descr *nw_descr)
2983 struct cYAML *child = NULL;
2984 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
2985 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2987 if (intf_tree == NULL || nw_descr == NULL)
2988 return LUSTRE_CFG_RC_BAD_PARAM;
2990 /* now grab all the interfaces and their cpts */
2991 child = intf_tree->cy_child;
2992 while (child != NULL) {
2993 if (child->cy_valuestring == NULL) {
2994 child = child->cy_next;
2998 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
3001 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
3002 child->cy_valuestring,
3003 strlen(child->cy_valuestring));
3004 if (rc != LUSTRE_CFG_RC_NO_ERR)
3008 child = child->cy_next;
3012 return LUSTRE_CFG_RC_MISSING_PARAM;
3017 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
3019 list_del(&intf_descr->intf_on_network);
3020 free_intf_descr(intf_descr);
3027 yaml_extract_cmn_tunables(struct cYAML *tree,
3028 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3029 struct cfs_expr_list **global_cpts)
3031 struct cYAML *tun, *item, *smp;
3034 tun = cYAML_get_object_item(tree, "tunables");
3036 item = cYAML_get_object_item(tun, "peer_timeout");
3038 tunables->lct_peer_timeout = item->cy_valueint;
3039 item = cYAML_get_object_item(tun, "peer_credits");
3041 tunables->lct_peer_tx_credits = item->cy_valueint;
3042 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3044 tunables->lct_peer_rtr_credits = item->cy_valueint;
3045 item = cYAML_get_object_item(tun, "credits");
3047 tunables->lct_max_tx_credits = item->cy_valueint;
3048 smp = cYAML_get_object_item(tun, "CPT");
3050 rc = cfs_expr_list_parse(smp->cy_valuestring,
3051 strlen(smp->cy_valuestring),
3052 0, UINT_MAX, global_cpts);
3054 *global_cpts = NULL;
3064 yaml_extract_tunables(struct cYAML *tree,
3065 struct lnet_ioctl_config_lnd_tunables *tunables,
3066 struct cfs_expr_list **global_cpts,
3071 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3077 lustre_yaml_extract_lnd_tunables(tree, net_type,
3085 * - net type: <net>[<NUM>]
3087 * - nid: <ip>@<net>[<NUM>]
3090 * 0: <intf_name>['['<expr>']']
3091 * 1: <intf_name>['['<expr>']']
3093 * peer_timeout: <NUM>
3094 * peer_credits: <NUM>
3095 * peer_buffer_credits: <NUM>
3098 * peercredits_hiw: <NUM>
3099 * map_on_demand: <NUM>
3100 * concurrent_sends: <NUM>
3101 * fmr_pool_size: <NUM>
3102 * fmr_flush_trigger: <NUM>
3105 * At least one interface is required. If no interfaces are provided the
3106 * network interface can not be configured.
3108 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3109 struct cYAML **err_rc)
3111 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3113 int num_entries = 0, rc;
3114 struct lnet_dlc_network_descr nw_descr;
3115 struct cfs_expr_list *global_cpts = NULL;
3116 struct lnet_ioctl_config_lnd_tunables tunables;
3119 memset(&tunables, 0, sizeof(tunables));
3121 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3122 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3124 ip2net = cYAML_get_object_item(tree, "ip2net");
3125 net = cYAML_get_object_item(tree, "net type");
3127 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3129 nw_descr.nw_id = LOLND;
3132 * if neither net nor ip2nets are present, then we can not
3133 * configure the network.
3135 if (!net && !ip2net)
3136 return LUSTRE_CFG_RC_MISSING_PARAM;
3138 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3139 if (local_nis == NULL)
3140 return LUSTRE_CFG_RC_MISSING_PARAM;
3142 if (!cYAML_is_sequence(local_nis))
3143 return LUSTRE_CFG_RC_BAD_PARAM;
3145 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3146 intf = cYAML_get_object_item(item, "interfaces");
3149 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3150 if (num_entries <= 0) {
3151 cYAML_build_error(num_entries, -1, "ni", "add",
3152 "bad interface list",
3154 return LUSTRE_CFG_RC_BAD_PARAM;
3158 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3159 LNET_NETTYP(nw_descr.nw_id));
3160 seq_no = cYAML_get_object_item(tree, "seq_no");
3162 rc = lustre_lnet_config_ni(&nw_descr,
3164 (ip2net) ? ip2net->cy_valuestring : NULL,
3165 (found) ? &tunables: NULL,
3166 (seq_no) ? seq_no->cy_valueint : -1,
3169 if (global_cpts != NULL)
3170 cfs_expr_list_free(global_cpts);
3177 * - net-spec: <tcp|o2ib|gni>[NUM]
3179 * 0: <intf name>['['<expr>']']
3180 * 1: <intf name>['['<expr>']']
3182 * 0: <expr.expr.expr.expr>
3183 * 1: <expr.expr.expr.expr>
3185 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3186 struct cYAML **show_rc,
3187 struct cYAML **err_rc)
3189 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3191 struct lustre_lnet_ip2nets ip2nets;
3192 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3194 int rc = LUSTRE_CFG_RC_NO_ERR;
3195 struct cfs_expr_list *global_cpts = NULL;
3196 struct cfs_expr_list *el, *el_tmp;
3197 struct lnet_ioctl_config_lnd_tunables tunables;
3198 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3201 memset(&tunables, 0, sizeof(tunables));
3203 /* initialize all lists */
3204 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
3205 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
3206 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
3208 net = cYAML_get_object_item(tree, "net-spec");
3210 return LUSTRE_CFG_RC_BAD_PARAM;
3212 if (net != NULL && net->cy_valuestring == NULL)
3213 return LUSTRE_CFG_RC_BAD_PARAM;
3215 /* assign the network id */
3216 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
3217 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
3218 return LUSTRE_CFG_RC_BAD_PARAM;
3220 seq_no = cYAML_get_object_item(tree, "seq_no");
3222 intf = cYAML_get_object_item(tree, "interfaces");
3224 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
3226 return LUSTRE_CFG_RC_BAD_PARAM;
3229 ip_range = cYAML_get_object_item(tree, "ip-range");
3230 if (ip_range != NULL) {
3231 item = ip_range->cy_child;
3232 while (item != NULL) {
3233 if (item->cy_valuestring == NULL) {
3234 item = item->cy_next;
3238 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
3239 item->cy_valuestring);
3241 if (rc != LUSTRE_CFG_RC_NO_ERR)
3244 item = item->cy_next;
3248 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3249 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
3251 rc = lustre_lnet_config_ip2nets(&ip2nets,
3252 (found) ? &tunables : NULL,
3254 (seq_no) ? seq_no->cy_valueint : -1,
3258 * don't stop because there was no match. Continue processing the
3259 * rest of the rules. If non-match then nothing is configured
3261 if (rc == LUSTRE_CFG_RC_NO_MATCH)
3262 rc = LUSTRE_CFG_RC_NO_ERR;
3264 list_for_each_entry_safe(intf_descr, intf_tmp,
3265 &ip2nets.ip2nets_net.nw_intflist,
3267 list_del(&intf_descr->intf_on_network);
3268 free_intf_descr(intf_descr);
3271 list_for_each_entry_safe(ip_range_descr, tmp,
3272 &ip2nets.ip2nets_ip_ranges,
3274 list_del(&ip_range_descr->ipr_entry);
3275 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
3277 list_del(&el->el_link);
3278 cfs_expr_list_free(el);
3280 free(ip_range_descr);
3286 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
3287 struct cYAML **err_rc)
3289 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
3291 int num_entries, rc;
3292 struct lnet_dlc_network_descr nw_descr;
3294 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3295 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3297 net = cYAML_get_object_item(tree, "net type");
3299 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3301 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3302 if (local_nis == NULL)
3303 return LUSTRE_CFG_RC_MISSING_PARAM;
3305 if (!cYAML_is_sequence(local_nis))
3306 return LUSTRE_CFG_RC_BAD_PARAM;
3308 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3309 intf = cYAML_get_object_item(item, "interfaces");
3312 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3313 if (num_entries <= 0) {
3314 cYAML_build_error(num_entries, -1, "ni", "add",
3315 "bad interface list",
3317 return LUSTRE_CFG_RC_BAD_PARAM;
3321 seq_no = cYAML_get_object_item(tree, "seq_no");
3323 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
3324 (seq_no) ? seq_no->cy_valueint : -1,
3330 static int yaml_copy_peer_nids(struct cYAML *tree, char ***nidsppp, bool del)
3332 struct cYAML *nids_entry = NULL, *child = NULL, *entry = NULL,
3335 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3337 prim_nid = cYAML_get_object_item(tree, "primary nid");
3338 if (!prim_nid || !prim_nid->cy_valuestring)
3339 return LUSTRE_CFG_RC_MISSING_PARAM;
3341 nids_entry = cYAML_get_object_item(tree, "peer ni");
3342 if (cYAML_is_sequence(nids_entry)) {
3343 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3344 entry = cYAML_get_object_item(child, "nid");
3345 /* don't count an empty entry */
3346 if (!entry || !entry->cy_valuestring)
3349 if ((strcmp(entry->cy_valuestring, prim_nid->cy_valuestring)
3352 * primary nid is present in the list of
3353 * nids so that means we want to delete
3354 * the entire peer, so no need to go
3355 * further. Just delete the entire peer.
3365 return LUSTRE_CFG_RC_MISSING_PARAM;
3367 nids = calloc(sizeof(*nids) * num, 1);
3369 return LUSTRE_CFG_RC_OUT_OF_MEM;
3371 /* now grab all the nids */
3374 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3375 entry = cYAML_get_object_item(child, "nid");
3376 if (!entry || !entry->cy_valuestring)
3379 nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
3381 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3384 strncpy(nids[num], entry->cy_valuestring,
3385 strlen(entry->cy_valuestring));
3395 yaml_free_string_array(nids, num);
3400 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
3401 struct cYAML **err_rc)
3405 struct cYAML *seq_no, *prim_nid, *non_mr;
3407 num = yaml_copy_peer_nids(tree, &nids, false);
3411 seq_no = cYAML_get_object_item(tree, "seq_no");
3412 prim_nid = cYAML_get_object_item(tree, "primary nid");
3413 non_mr = cYAML_get_object_item(tree, "non_mr");
3415 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3417 (non_mr) ? false : true,
3418 (seq_no) ? seq_no->cy_valueint : -1,
3421 yaml_free_string_array(nids, num);
3425 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
3426 struct cYAML **err_rc)
3430 struct cYAML *seq_no, *prim_nid;
3432 num = yaml_copy_peer_nids(tree, &nids, true);
3436 seq_no = cYAML_get_object_item(tree, "seq_no");
3437 prim_nid = cYAML_get_object_item(tree, "primary nid");
3439 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3441 (seq_no) ? seq_no->cy_valueint : -1,
3444 yaml_free_string_array(nids, num);
3448 static int handle_yaml_config_buffers(struct cYAML *tree,
3449 struct cYAML **show_rc,
3450 struct cYAML **err_rc)
3453 struct cYAML *tiny, *small, *large, *seq_no;
3455 tiny = cYAML_get_object_item(tree, "tiny");
3456 small = cYAML_get_object_item(tree, "small");
3457 large = cYAML_get_object_item(tree, "large");
3458 seq_no = cYAML_get_object_item(tree, "seq_no");
3460 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
3461 (small) ? small->cy_valueint : -1,
3462 (large) ? large->cy_valueint : -1,
3463 (seq_no) ? seq_no->cy_valueint : -1,
3469 static int handle_yaml_config_routing(struct cYAML *tree,
3470 struct cYAML **show_rc,
3471 struct cYAML **err_rc)
3473 int rc = LUSTRE_CFG_RC_NO_ERR;
3474 struct cYAML *seq_no, *enable;
3476 seq_no = cYAML_get_object_item(tree, "seq_no");
3477 enable = cYAML_get_object_item(tree, "enable");
3480 rc = lustre_lnet_enable_routing(enable->cy_valueint,
3482 seq_no->cy_valueint : -1,
3489 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
3490 struct cYAML **err_rc)
3494 struct cYAML *seq_no;
3496 net = cYAML_get_object_item(tree, "net");
3497 gw = cYAML_get_object_item(tree, "gateway");
3498 seq_no = cYAML_get_object_item(tree, "seq_no");
3500 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
3501 (gw) ? gw->cy_valuestring : NULL,
3502 (seq_no) ? seq_no->cy_valueint : -1,
3506 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
3507 struct cYAML **err_rc)
3509 struct cYAML *seq_no;
3511 seq_no = cYAML_get_object_item(tree, "seq_no");
3513 return lustre_lnet_enable_routing(0, (seq_no) ?
3514 seq_no->cy_valueint : -1,
3518 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
3519 struct cYAML **err_rc)
3525 struct cYAML *detail;
3526 struct cYAML *seq_no;
3528 net = cYAML_get_object_item(tree, "net");
3529 gw = cYAML_get_object_item(tree, "gateway");
3530 hop = cYAML_get_object_item(tree, "hop");
3531 prio = cYAML_get_object_item(tree, "priority");
3532 detail = cYAML_get_object_item(tree, "detail");
3533 seq_no = cYAML_get_object_item(tree, "seq_no");
3535 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
3536 (gw) ? gw->cy_valuestring : NULL,
3537 (hop) ? hop->cy_valueint : -1,
3538 (prio) ? prio->cy_valueint : -1,
3539 (detail) ? detail->cy_valueint : 0,
3540 (seq_no) ? seq_no->cy_valueint : -1,
3545 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
3546 struct cYAML **err_rc)
3548 struct cYAML *net, *detail, *seq_no;
3550 net = cYAML_get_object_item(tree, "net");
3551 detail = cYAML_get_object_item(tree, "detail");
3552 seq_no = cYAML_get_object_item(tree, "seq_no");
3554 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
3555 (detail) ? detail->cy_valueint : 0,
3556 (seq_no) ? seq_no->cy_valueint : -1,
3561 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
3562 struct cYAML **err_rc)
3564 struct cYAML *seq_no;
3566 seq_no = cYAML_get_object_item(tree, "seq_no");
3568 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
3572 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
3573 struct cYAML **err_rc)
3575 struct cYAML *seq_no, *nid, *detail;
3577 seq_no = cYAML_get_object_item(tree, "seq_no");
3578 detail = cYAML_get_object_item(tree, "detail");
3579 nid = cYAML_get_object_item(tree, "nid");
3581 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
3582 (detail) ? detail->cy_valueint : 0,
3583 (seq_no) ? seq_no->cy_valueint : -1,
3587 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
3588 struct cYAML **err_rc)
3590 struct cYAML *seq_no;
3592 seq_no = cYAML_get_object_item(tree, "seq_no");
3594 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
3598 static int handle_yaml_config_global_settings(struct cYAML *tree,
3599 struct cYAML **show_rc,
3600 struct cYAML **err_rc)
3602 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3605 seq_no = cYAML_get_object_item(tree, "seq_no");
3606 max_intf = cYAML_get_object_item(tree, "max_intf");
3608 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
3609 seq_no ? seq_no->cy_valueint
3613 numa = cYAML_get_object_item(tree, "numa_range");
3615 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
3616 seq_no ? seq_no->cy_valueint
3620 discovery = cYAML_get_object_item(tree, "discovery");
3622 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
3623 seq_no ? seq_no->cy_valueint
3630 static int handle_yaml_del_global_settings(struct cYAML *tree,
3631 struct cYAML **show_rc,
3632 struct cYAML **err_rc)
3634 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3637 seq_no = cYAML_get_object_item(tree, "seq_no");
3638 max_intf = cYAML_get_object_item(tree, "max_intf");
3640 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
3641 seq_no ? seq_no->cy_valueint
3645 numa = cYAML_get_object_item(tree, "numa_range");
3647 rc = lustre_lnet_config_numa_range(0,
3648 seq_no ? seq_no->cy_valueint
3652 /* peer discovery is enabled by default */
3653 discovery = cYAML_get_object_item(tree, "discovery");
3655 rc = lustre_lnet_config_discovery(1,
3656 seq_no ? seq_no->cy_valueint
3663 static int handle_yaml_show_global_settings(struct cYAML *tree,
3664 struct cYAML **show_rc,
3665 struct cYAML **err_rc)
3667 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3670 seq_no = cYAML_get_object_item(tree, "seq_no");
3671 max_intf = cYAML_get_object_item(tree, "max_intf");
3673 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
3677 numa = cYAML_get_object_item(tree, "numa_range");
3679 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
3683 discovery = cYAML_get_object_item(tree, "discovery");
3685 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
3692 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
3693 struct cYAML **err_rc)
3695 struct cYAML *seq_no, *nid, *timeout;
3697 seq_no = cYAML_get_object_item(tree, "seq_no");
3698 nid = cYAML_get_object_item(tree, "primary nid");
3699 timeout = cYAML_get_object_item(tree, "timeout");
3701 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
3702 (timeout) ? timeout->cy_valueint : 1000,
3703 (seq_no) ? seq_no->cy_valueint : -1,
3707 static int handle_yaml_no_op()
3709 return LUSTRE_CFG_RC_NO_ERR;
3712 struct lookup_cmd_hdlr_tbl {
3717 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
3718 { .name = "route", .cb = handle_yaml_config_route },
3719 { .name = "net", .cb = handle_yaml_config_ni },
3720 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
3721 { .name = "peer", .cb = handle_yaml_config_peer },
3722 { .name = "routing", .cb = handle_yaml_config_routing },
3723 { .name = "buffers", .cb = handle_yaml_config_buffers },
3724 { .name = "statistics", .cb = handle_yaml_no_op },
3725 { .name = "global", .cb = handle_yaml_config_global_settings},
3726 { .name = "ping", .cb = handle_yaml_no_op },
3729 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
3730 { .name = "route", .cb = handle_yaml_del_route },
3731 { .name = "net", .cb = handle_yaml_del_ni },
3732 { .name = "ip2nets", .cb = handle_yaml_no_op },
3733 { .name = "peer", .cb = handle_yaml_del_peer },
3734 { .name = "routing", .cb = handle_yaml_del_routing },
3735 { .name = "buffers", .cb = handle_yaml_no_op },
3736 { .name = "statistics", .cb = handle_yaml_no_op },
3737 { .name = "global", .cb = handle_yaml_del_global_settings},
3738 { .name = "ping", .cb = handle_yaml_no_op },
3741 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
3742 { .name = "route", .cb = handle_yaml_show_route },
3743 { .name = "net", .cb = handle_yaml_show_net },
3744 { .name = "peer", .cb = handle_yaml_show_peers },
3745 { .name = "ip2nets", .cb = handle_yaml_no_op },
3746 { .name = "routing", .cb = handle_yaml_show_routing },
3747 { .name = "buffers", .cb = handle_yaml_show_routing },
3748 { .name = "statistics", .cb = handle_yaml_show_stats },
3749 { .name = "global", .cb = handle_yaml_show_global_settings},
3750 { .name = "ping", .cb = handle_yaml_no_op },
3753 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
3754 { .name = "route", .cb = handle_yaml_no_op },
3755 { .name = "net", .cb = handle_yaml_no_op },
3756 { .name = "peer", .cb = handle_yaml_no_op },
3757 { .name = "ip2nets", .cb = handle_yaml_no_op },
3758 { .name = "routing", .cb = handle_yaml_no_op },
3759 { .name = "buffers", .cb = handle_yaml_no_op },
3760 { .name = "statistics", .cb = handle_yaml_no_op },
3761 { .name = "global", .cb = handle_yaml_no_op },
3762 { .name = "ping", .cb = handle_yaml_ping },
3765 static cmd_handler_t lookup_fn(char *key,
3766 struct lookup_cmd_hdlr_tbl *tbl)
3772 for (i = 0; tbl[i].name != NULL; i++) {
3773 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
3780 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
3781 struct cYAML **show_rc, struct cYAML **err_rc)
3783 struct cYAML *tree, *item = NULL, *head, *child;
3785 char err_str[LNET_MAX_STR_LEN];
3786 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
3788 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
3790 return LUSTRE_CFG_RC_BAD_PARAM;
3792 child = tree->cy_child;
3793 while (child != NULL) {
3794 cb = lookup_fn(child->cy_string, table);
3796 snprintf(err_str, sizeof(err_str),
3797 "\"call back for '%s' not found\"",
3799 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
3800 "yaml", "helper", err_str, err_rc);
3804 if (cYAML_is_sequence(child)) {
3805 while ((head = cYAML_get_next_seq_item(child, &item))
3807 rc = cb(head, show_rc, err_rc);
3808 if (rc != LUSTRE_CFG_RC_NO_ERR)
3812 rc = cb(child, show_rc, err_rc);
3813 if (rc != LUSTRE_CFG_RC_NO_ERR)
3817 child = child->cy_next;
3821 cYAML_free_tree(tree);
3826 int lustre_yaml_config(char *f, struct cYAML **err_rc)
3828 return lustre_yaml_cb_helper(f, lookup_config_tbl,
3832 int lustre_yaml_del(char *f, struct cYAML **err_rc)
3834 return lustre_yaml_cb_helper(f, lookup_del_tbl,
3838 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3840 return lustre_yaml_cb_helper(f, lookup_show_tbl,
3844 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3846 return lustre_yaml_cb_helper(f, lookup_exec_tbl,