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 ?
608 "True" : "False") == NULL)
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_discover_nid(char *ping_nids, int force, int seq_no,
673 struct cYAML **show_rc, struct cYAML **err_rc)
677 rc = infra_ping_nid(ping_nids, "discover", force, IOC_LIBCFS_DISCOVER,
678 seq_no, show_rc, err_rc);
682 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
683 bool mr, int seq_no, struct cYAML **err_rc)
685 struct lnet_ioctl_peer_cfg data;
686 lnet_nid_t prim_nid = LNET_NID_ANY;
687 int rc = LUSTRE_CFG_RC_NO_ERR;
689 bool nid0_used = false;
690 char err_str[LNET_MAX_STR_LEN] = {0};
691 lnet_nid_t *nids = allocate_create_nid_array(nid, num_nids, err_str);
694 prim_nid = libcfs_str2nid(pnid);
695 if (prim_nid == LNET_NID_ANY) {
696 snprintf(err_str, sizeof(err_str),
699 rc = LUSTRE_CFG_RC_MISSING_PARAM;
702 } else if (!nids || nids[0] == LNET_NID_ANY) {
703 snprintf(err_str, sizeof(err_str),
704 "no NIDs provided for configuration");
705 rc = LUSTRE_CFG_RC_MISSING_PARAM;
708 prim_nid = LNET_NID_ANY;
711 snprintf(err_str, sizeof(err_str), "\"Success\"");
713 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
717 * if prim_nid is not specified use the first nid in the list of
718 * nids provided as the prim_nid. NOTE: on entering 'if' we must
719 * have at least 1 NID
721 if (prim_nid == LNET_NID_ANY) {
726 /* Create the prim_nid first */
727 rc = dispatch_peer_ni_cmd(prim_nid, LNET_NID_ANY,
728 IOC_LIBCFS_ADD_PEER_NI,
729 &data, err_str, "add");
734 /* add the rest of the nids to the key nid if any are available */
735 for (idx = nid0_used ? 1 : 0 ; nids && idx < num_nids; idx++) {
737 * If prim_nid is not provided then the first nid in the
738 * list becomes the prim_nid. First time round the loop use
739 * LNET_NID_ANY for the first parameter, then use nid[0]
740 * as the key nid after wards
742 rc = dispatch_peer_ni_cmd(prim_nid, nids[idx],
743 IOC_LIBCFS_ADD_PEER_NI, &data,
753 cYAML_build_error(rc, seq_no, ADD_CMD, "peer_ni", err_str, err_rc);
757 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
758 int seq_no, struct cYAML **err_rc)
760 struct lnet_ioctl_peer_cfg data;
762 int rc = LUSTRE_CFG_RC_NO_ERR;
764 char err_str[LNET_MAX_STR_LEN] = {0};
765 lnet_nid_t *nids = allocate_create_nid_array(nid, num_nids, err_str);
768 snprintf(err_str, sizeof(err_str),
769 "\"Primary nid is not provided\"");
770 rc = LUSTRE_CFG_RC_MISSING_PARAM;
773 prim_nid = libcfs_str2nid(pnid);
774 if (prim_nid == LNET_NID_ANY) {
775 rc = LUSTRE_CFG_RC_BAD_PARAM;
776 snprintf(err_str, sizeof(err_str),
783 snprintf(err_str, sizeof(err_str), "\"Success\"");
785 LIBCFS_IOC_INIT_V2(data, prcfg_hdr);
786 if (!nids || nids[0] == LNET_NID_ANY) {
787 rc = dispatch_peer_ni_cmd(prim_nid, LNET_NID_ANY,
788 IOC_LIBCFS_DEL_PEER_NI,
789 &data, err_str, "del");
793 for (idx = 0; nids && idx < num_nids; idx++) {
794 rc = dispatch_peer_ni_cmd(prim_nid, nids[idx],
795 IOC_LIBCFS_DEL_PEER_NI, &data,
805 cYAML_build_error(rc, seq_no, DEL_CMD, "peer_ni", err_str, err_rc);
809 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
810 int seq_no, struct cYAML **err_rc)
812 struct lnet_ioctl_config_data data;
813 lnet_nid_t gateway_nid;
814 int rc = LUSTRE_CFG_RC_NO_ERR;
815 __u32 net = LNET_NIDNET(LNET_NID_ANY);
816 char err_str[LNET_MAX_STR_LEN];
818 snprintf(err_str, sizeof(err_str), "\"Success\"");
820 if (nw == NULL || gw == NULL) {
823 "\"missing mandatory parameter(s): '%s'\"",
824 (nw == NULL && gw == NULL) ? "network, gateway" :
825 (nw == NULL) ? "network" : "gateway");
826 rc = LUSTRE_CFG_RC_MISSING_PARAM;
830 net = libcfs_str2net(nw);
831 if (net == LNET_NIDNET(LNET_NID_ANY)) {
834 "\"cannot parse net %s\"", nw);
835 rc = LUSTRE_CFG_RC_BAD_PARAM;
839 gateway_nid = libcfs_str2nid(gw);
840 if (gateway_nid == LNET_NID_ANY) {
843 "\"cannot parse gateway NID '%s'\"", gw);
844 rc = LUSTRE_CFG_RC_BAD_PARAM;
849 /* hops is undefined */
850 hops = LNET_UNDEFINED_HOPS;
851 } else if (hops < 1 || hops > 255) {
854 "\"invalid hop count %d, must be between 1 and 255\"",
856 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
862 } else if (prio < 0) {
865 "\"invalid priority %d, must be greater than 0\"",
867 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
871 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
873 data.cfg_config_u.cfg_route.rtr_hop = hops;
874 data.cfg_config_u.cfg_route.rtr_priority = prio;
875 data.cfg_nid = gateway_nid;
877 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
882 "\"cannot add route: %s\"", strerror(errno));
887 cYAML_build_error(rc, seq_no, ADD_CMD, "route", err_str, err_rc);
892 int lustre_lnet_del_route(char *nw, char *gw,
893 int seq_no, struct cYAML **err_rc)
895 struct lnet_ioctl_config_data data;
896 lnet_nid_t gateway_nid;
897 int rc = LUSTRE_CFG_RC_NO_ERR;
898 __u32 net = LNET_NIDNET(LNET_NID_ANY);
899 char err_str[LNET_MAX_STR_LEN];
901 snprintf(err_str, sizeof(err_str), "\"Success\"");
903 if (nw == NULL || gw == NULL) {
906 "\"missing mandatory parameter(s): '%s'\"",
907 (nw == NULL && gw == NULL) ? "network, gateway" :
908 (nw == NULL) ? "network" : "gateway");
909 rc = LUSTRE_CFG_RC_MISSING_PARAM;
913 net = libcfs_str2net(nw);
914 if (net == LNET_NIDNET(LNET_NID_ANY)) {
917 "\"cannot parse net '%s'\"", nw);
918 rc = LUSTRE_CFG_RC_BAD_PARAM;
922 gateway_nid = libcfs_str2nid(gw);
923 if (gateway_nid == LNET_NID_ANY) {
926 "\"cannot parse gateway NID '%s'\"", gw);
927 rc = LUSTRE_CFG_RC_BAD_PARAM;
931 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
933 data.cfg_nid = gateway_nid;
935 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
940 "\"cannot delete route: %s\"", strerror(errno));
945 cYAML_build_error(rc, seq_no, DEL_CMD, "route", err_str, err_rc);
950 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
951 int seq_no, struct cYAML **show_rc,
952 struct cYAML **err_rc)
954 struct lnet_ioctl_config_data data;
955 lnet_nid_t gateway_nid;
956 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
958 __u32 net = LNET_NIDNET(LNET_NID_ANY);
960 struct cYAML *root = NULL, *route = NULL, *item = NULL;
961 struct cYAML *first_seq = NULL;
962 char err_str[LNET_MAX_STR_LEN];
965 snprintf(err_str, sizeof(err_str),
966 "\"out of memory\"");
969 net = libcfs_str2net(nw);
970 if (net == LNET_NIDNET(LNET_NID_ANY)) {
973 "\"cannot parse net '%s'\"", nw);
974 rc = LUSTRE_CFG_RC_BAD_PARAM;
979 /* show all routes without filtering on net */
980 net = LNET_NIDNET(LNET_NID_ANY);
984 gateway_nid = libcfs_str2nid(gw);
985 if (gateway_nid == LNET_NID_ANY) {
988 "\"cannot parse gateway NID '%s'\"", gw);
989 rc = LUSTRE_CFG_RC_BAD_PARAM;
993 /* show all routes with out filtering on gateway */
994 gateway_nid = LNET_NID_ANY;
996 if ((hops < 1 && hops != -1) || hops > 255) {
999 "\"invalid hop count %d, must be between 0 and 256\"",
1001 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1005 /* create struct cYAML root object */
1006 root = cYAML_create_object(NULL, NULL);
1010 route = cYAML_create_seq(root, "route");
1015 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1018 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1024 /* filter on provided data */
1025 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1026 net != data.cfg_net)
1029 if (gateway_nid != LNET_NID_ANY &&
1030 gateway_nid != data.cfg_nid)
1034 hops != data.cfg_config_u.cfg_route.rtr_hop)
1038 prio != data.cfg_config_u.cfg_route.rtr_priority)
1041 /* default rc to -1 incase we hit the goto */
1045 item = cYAML_create_seq_item(route);
1049 if (first_seq == NULL)
1052 if (cYAML_create_string(item, "net",
1053 libcfs_net2str(data.cfg_net)) == NULL)
1056 if (cYAML_create_string(item, "gateway",
1057 libcfs_nid2str(data.cfg_nid)) == NULL)
1061 if (cYAML_create_number(item, "hop",
1062 (int) data.cfg_config_u.
1063 cfg_route.rtr_hop) ==
1067 if (cYAML_create_number(item, "priority",
1069 cfg_route.rtr_priority) == NULL)
1072 if (cYAML_create_string(item, "state",
1073 data.cfg_config_u.cfg_route.
1075 "up" : "down") == NULL)
1080 /* print output iff show_rc is not provided */
1081 if (show_rc == NULL)
1082 cYAML_print_tree(root);
1084 if (l_errno != ENOENT) {
1087 "\"cannot get routes: %s\"",
1092 rc = LUSTRE_CFG_RC_NO_ERR;
1094 snprintf(err_str, sizeof(err_str), "\"success\"");
1096 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1097 cYAML_free_tree(root);
1098 } else if (show_rc != NULL && *show_rc != NULL) {
1099 struct cYAML *show_node;
1100 /* find the route node, if one doesn't exist then
1101 * insert one. Otherwise add to the one there
1103 show_node = cYAML_get_object_item(*show_rc, "route");
1104 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1105 cYAML_insert_child(show_node, first_seq);
1108 } else if (show_node == NULL) {
1109 cYAML_insert_sibling((*show_rc)->cy_child,
1113 cYAML_free_tree(root);
1119 cYAML_build_error(rc, seq_no, SHOW_CMD, "route", err_str, err_rc);
1124 static int socket_intf_query(int request, char *intf,
1130 if (strlen(intf) >= IFNAMSIZ || ifr == NULL)
1131 return LUSTRE_CFG_RC_BAD_PARAM;
1133 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
1135 return LUSTRE_CFG_RC_BAD_PARAM;
1137 strcpy(ifr->ifr_name, intf);
1138 rc = ioctl(sockfd, request, ifr);
1140 rc = LUSTRE_CFG_RC_BAD_PARAM;
1148 * for each interface in the array of interfaces find the IP address of
1149 * that interface, create its nid and add it to an array of NIDs.
1150 * Stop if any of the interfaces is down
1152 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
1153 lnet_nid_t **nids, __u32 *nnids)
1155 int i = 0, count = 0, rc;
1158 struct lnet_dlc_intf_descr *intf;
1160 if (nw == NULL || nids == NULL)
1161 return LUSTRE_CFG_RC_BAD_PARAM;
1163 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
1166 *nids = calloc(count, sizeof(lnet_nid_t));
1168 return LUSTRE_CFG_RC_OUT_OF_MEM;
1170 list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
1171 memset(&ifr, 0, sizeof(ifr));
1172 rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
1176 if ((ifr.ifr_flags & IFF_UP) == 0) {
1177 rc = LUSTRE_CFG_RC_BAD_PARAM;
1181 memset(&ifr, 0, sizeof(ifr));
1182 rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
1186 ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
1188 (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
1203 * called repeatedly until a match or no more ip range
1205 * ip_range expression
1206 * interface list with all the interface names.
1207 * all the interfaces in the system.
1209 * try to match the ip_range expr to one of the interfaces' IPs in
1210 * the system. If we hit a patch for an interface. Check if that
1211 * interface name is in the list.
1213 * If there are more than one interface in the list, then make sure
1214 * that the IPs for all of these interfaces match the ip ranges
1217 * for each interface in intf_list
1218 * look up the intf name in ifa
1219 * if not there then no match
1220 * check ip obtained from ifa against a match to any of the
1222 * If no match, then fail
1224 * The result is that all the interfaces have to match.
1226 int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
1227 struct list_head *intf_list,
1228 struct list_head *ip_ranges)
1232 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1233 struct ifaddrs *ifaddr = ifa;
1234 struct lustre_lnet_ip_range_descr *ip_range;
1238 * if there are no explicit interfaces, and no ip ranges, then
1239 * configure the first tcp interface we encounter.
1241 if (list_empty(intf_list) && list_empty(ip_ranges)) {
1242 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1243 if (ifaddr->ifa_addr == NULL)
1246 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1249 family = ifaddr->ifa_addr->sa_family;
1250 if (family == AF_INET &&
1251 strcmp(ifaddr->ifa_name, "lo") != 0) {
1252 rc = lustre_lnet_add_intf_descr
1253 (intf_list, ifaddr->ifa_name,
1254 strlen(ifaddr->ifa_name));
1256 if (rc != LUSTRE_CFG_RC_NO_ERR)
1259 return LUSTRE_CFG_RC_MATCH;
1262 return LUSTRE_CFG_RC_NO_MATCH;
1266 * First interface which matches an IP pattern will be used
1268 if (list_empty(intf_list)) {
1270 * no interfaces provided in the rule, but an ip range is
1271 * provided, so try and match an interface to the ip
1274 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1275 if (ifaddr->ifa_addr == NULL)
1278 if ((ifaddr->ifa_flags & IFF_UP) == 0)
1281 family = ifaddr->ifa_addr->sa_family;
1282 if (family == AF_INET) {
1283 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->
1286 list_for_each_entry(ip_range, ip_ranges,
1288 rc = cfs_ip_addr_match(bswap_32(ip),
1289 &ip_range->ipr_expr);
1293 rc = lustre_lnet_add_intf_descr
1294 (intf_list, ifaddr->ifa_name,
1295 strlen(ifaddr->ifa_name));
1297 if (rc != LUSTRE_CFG_RC_NO_ERR)
1303 if (!list_empty(intf_list))
1304 return LUSTRE_CFG_RC_MATCH;
1306 return LUSTRE_CFG_RC_NO_MATCH;
1310 * If an interface is explicitly specified the ip-range might or
1311 * might not be specified. if specified the interface needs to match the
1312 * ip-range. If no ip-range then the interfaces are
1313 * automatically matched if they are all up.
1314 * If > 1 interfaces all the interfaces must match for the NI to
1317 list_for_each_entry_safe(intf_descr, tmp, intf_list, intf_on_network) {
1318 for (ifaddr = ifa; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
1319 if (ifaddr->ifa_addr == NULL)
1322 family = ifaddr->ifa_addr->sa_family;
1323 if (family == AF_INET &&
1324 strcmp(intf_descr->intf_name,
1325 ifaddr->ifa_name) == 0)
1329 if (ifaddr == NULL) {
1330 list_del(&intf_descr->intf_on_network);
1331 free_intf_descr(intf_descr);
1335 if ((ifaddr->ifa_flags & IFF_UP) == 0) {
1336 list_del(&intf_descr->intf_on_network);
1337 free_intf_descr(intf_descr);
1341 ip = ((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr.s_addr;
1344 list_for_each_entry(ip_range, ip_ranges, ipr_entry) {
1345 rc = cfs_ip_addr_match(bswap_32(ip), &ip_range->ipr_expr);
1351 /* no match for this interface */
1352 list_del(&intf_descr->intf_on_network);
1353 free_intf_descr(intf_descr);
1357 return LUSTRE_CFG_RC_MATCH;
1360 int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
1361 lnet_nid_t **nids, __u32 *nnids)
1363 struct ifaddrs *ifa;
1364 int rc = LUSTRE_CFG_RC_NO_ERR;
1366 rc = getifaddrs(&ifa);
1370 rc = lustre_lnet_match_ip_to_intf(ifa,
1371 &ip2nets->ip2nets_net.nw_intflist,
1372 &ip2nets->ip2nets_ip_ranges);
1373 if (rc != LUSTRE_CFG_RC_MATCH) {
1378 rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids);
1379 if (rc != LUSTRE_CFG_RC_NO_ERR) {
1390 lustre_lnet_ioctl_config_ni(struct list_head *intf_list,
1391 struct lnet_ioctl_config_lnd_tunables *tunables,
1392 struct cfs_expr_list *global_cpts,
1393 lnet_nid_t *nids, char *err_str)
1396 struct lnet_ioctl_config_ni *conf;
1397 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1398 int rc = LUSTRE_CFG_RC_NO_ERR, i = 0;
1401 struct lnet_dlc_intf_descr *intf_descr;
1403 struct cfs_expr_list *cpt_expr;
1405 list_for_each_entry(intf_descr, intf_list,
1407 if (tunables != NULL)
1408 len = sizeof(struct lnet_ioctl_config_ni) +
1409 sizeof(struct lnet_ioctl_config_lnd_tunables);
1411 len = sizeof(struct lnet_ioctl_config_ni);
1413 data = calloc(1, len);
1415 return LUSTRE_CFG_RC_OUT_OF_MEM;
1416 conf = (struct lnet_ioctl_config_ni*) data;
1417 if (tunables != NULL)
1418 tun = (struct lnet_ioctl_config_lnd_tunables*)
1421 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1422 conf->lic_cfg_hdr.ioc_len = len;
1423 conf->lic_nid = nids[i];
1424 strncpy(conf->lic_ni_intf[0], intf_descr->intf_name,
1427 if (intf_descr->cpt_expr != NULL)
1428 cpt_expr = intf_descr->cpt_expr;
1429 else if (global_cpts != NULL)
1430 cpt_expr = global_cpts;
1434 if (cpt_expr != NULL) {
1435 count = cfs_expr_list_values(cpt_expr,
1436 LNET_MAX_SHOW_NUM_CPT,
1439 memcpy(conf->lic_cpts, cpt_array,
1440 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1449 conf->lic_ncpts = count;
1451 if (tunables != NULL)
1452 memcpy(tun, tunables, sizeof(*tunables));
1454 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1459 "\"cannot add network: %s\"", strerror(errno));
1467 return LUSTRE_CFG_RC_NO_ERR;
1471 lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
1472 struct lnet_ioctl_config_lnd_tunables *tunables,
1473 struct cfs_expr_list *global_cpts,
1474 int seq_no, struct cYAML **err_rc)
1476 lnet_nid_t *nids = NULL;
1479 char err_str[LNET_MAX_STR_LEN];
1481 snprintf(err_str, sizeof(err_str), "\"success\"");
1486 "\"incomplete ip2nets information\"");
1487 rc = LUSTRE_CFG_RC_BAD_PARAM;
1492 * call below function to resolve the rules into a list of nids.
1493 * The memory is allocated in that function then freed here when
1494 * it's no longer needed.
1496 rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids);
1497 if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH) {
1500 "\"cannot resolve ip2nets rule\"");
1504 if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
1505 snprintf(err_str, sizeof(err_str),
1506 "\"no interfaces match ip2nets rules\"");
1510 rc = lustre_lnet_ioctl_config_ni(&ip2nets->ip2nets_net.nw_intflist,
1511 tunables, global_cpts, nids,
1518 cYAML_build_error(rc, seq_no, ADD_CMD, "ip2nets", err_str, err_rc);
1522 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
1523 struct cfs_expr_list *global_cpts,
1525 struct lnet_ioctl_config_lnd_tunables *tunables,
1526 int seq_no, struct cYAML **err_rc)
1529 struct lnet_ioctl_config_ni *conf;
1530 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
1531 char buf[LNET_MAX_STR_LEN];
1532 int rc = LUSTRE_CFG_RC_NO_ERR;
1533 char err_str[LNET_MAX_STR_LEN];
1534 lnet_nid_t *nids = NULL;
1538 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1541 snprintf(err_str, sizeof(err_str), "\"success\"");
1543 if (ip2net == NULL && nw_descr == NULL) {
1546 "\"mandatory parameters not specified.\"");
1547 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1551 if (ip2net != NULL && strlen(ip2net) >= sizeof(buf)) {
1554 "\"ip2net string too long %d\"",
1555 (int)strlen(ip2net));
1556 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
1560 if (ip2net != NULL) {
1561 if (tunables != NULL)
1562 len = sizeof(struct lnet_ioctl_config_ni) +
1563 sizeof(struct lnet_ioctl_config_lnd_tunables);
1565 len = sizeof(struct lnet_ioctl_config_ni);
1566 data = calloc(1, len);
1568 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1571 conf = (struct lnet_ioctl_config_ni*) data;
1572 if (tunables != NULL)
1573 tun = (struct lnet_ioctl_config_lnd_tunables*)
1574 (data + sizeof(*conf));
1576 LIBCFS_IOC_INIT_V2(*conf, lic_cfg_hdr);
1577 conf->lic_cfg_hdr.ioc_len = len;
1578 strncpy(conf->lic_legacy_ip2nets, ip2net,
1581 if (global_cpts != NULL) {
1582 count = cfs_expr_list_values(global_cpts,
1583 LNET_MAX_SHOW_NUM_CPT,
1586 memcpy(conf->lic_cpts, cpt_array,
1587 sizeof(cpt_array[0]) * LNET_MAX_STR_LEN);
1596 conf->lic_ncpts = count;
1598 if (tunables != NULL)
1599 memcpy(tun, tunables, sizeof(*tunables));
1601 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_LOCAL_NI, data);
1606 "\"cannot add network: %s\"", strerror(errno));
1613 if (LNET_NETTYP(nw_descr->nw_id) == LOLND) {
1614 rc = LUSTRE_CFG_RC_NO_ERR;
1618 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1621 "\"cannot parse net '%s'\"",
1622 libcfs_net2str(nw_descr->nw_id));
1623 rc = LUSTRE_CFG_RC_BAD_PARAM;
1627 if (list_empty(&nw_descr->nw_intflist)) {
1630 "\"no interface name provided\"");
1631 rc = LUSTRE_CFG_RC_BAD_PARAM;
1635 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1637 snprintf(err_str, sizeof(err_str),
1638 "\"bad parameter\"");
1639 rc = LUSTRE_CFG_RC_BAD_PARAM;
1643 rc = lustre_lnet_ioctl_config_ni(&nw_descr->nw_intflist,
1644 tunables, global_cpts, nids,
1648 if (nw_descr != NULL) {
1649 list_for_each_entry_safe(intf_descr, tmp,
1650 &nw_descr->nw_intflist,
1652 list_del(&intf_descr->intf_on_network);
1653 free_intf_descr(intf_descr);
1657 cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
1668 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
1669 int seq_no, struct cYAML **err_rc)
1671 struct lnet_ioctl_config_ni data;
1672 int rc = LUSTRE_CFG_RC_NO_ERR, i;
1673 char err_str[LNET_MAX_STR_LEN];
1674 lnet_nid_t *nids = NULL;
1676 struct lnet_dlc_intf_descr *intf_descr, *tmp;
1678 snprintf(err_str, sizeof(err_str), "\"success\"");
1680 if (nw_descr == NULL) {
1683 "\"missing mandatory parameter\"");
1684 rc = LUSTRE_CFG_RC_MISSING_PARAM;
1688 if (LNET_NETTYP(nw_descr->nw_id) == LOLND)
1689 return LUSTRE_CFG_RC_NO_ERR;
1691 if (nw_descr->nw_id == LNET_NIDNET(LNET_NID_ANY)) {
1694 "\"cannot parse net '%s'\"",
1695 libcfs_net2str(nw_descr->nw_id));
1696 rc = LUSTRE_CFG_RC_BAD_PARAM;
1700 rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
1702 snprintf(err_str, sizeof(err_str),
1703 "\"bad parameter\"");
1704 rc = LUSTRE_CFG_RC_BAD_PARAM;
1709 * no interfaces just the nw_id is specified
1712 nids = calloc(1, sizeof(*nids));
1714 snprintf(err_str, sizeof(err_str),
1715 "\"out of memory\"");
1716 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
1719 nids[0] = LNET_MKNID(nw_descr->nw_id, 0);
1723 for (i = 0; i < nnids; i++) {
1724 LIBCFS_IOC_INIT_V2(data, lic_cfg_hdr);
1725 data.lic_nid = nids[i];
1727 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_LOCAL_NI, &data);
1732 "\"cannot del network: %s\"", strerror(errno));
1736 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
1738 list_del(&intf_descr->intf_on_network);
1739 free_intf_descr(intf_descr);
1743 cYAML_build_error(rc, seq_no, DEL_CMD, "net", err_str, err_rc);
1751 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
1752 struct cYAML **show_rc, struct cYAML **err_rc)
1755 struct lnet_ioctl_config_ni *ni_data;
1756 struct lnet_ioctl_config_lnd_tunables *lnd;
1757 struct lnet_ioctl_element_stats *stats;
1758 __u32 net = LNET_NIDNET(LNET_NID_ANY);
1759 __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
1760 int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
1762 struct cYAML *root = NULL, *tunables = NULL,
1763 *net_node = NULL, *interfaces = NULL,
1764 *item = NULL, *first_seq = NULL,
1765 *tmp = NULL, *statistics = NULL;
1766 int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
1767 char str_buf[str_buf_len];
1769 char err_str[LNET_MAX_STR_LEN];
1770 bool exist = false, new_net = true;
1772 size_t buf_size = sizeof(*ni_data) + sizeof(*lnd) + sizeof(*stats);
1774 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
1776 buf = calloc(1, buf_size);
1780 ni_data = (struct lnet_ioctl_config_ni *)buf;
1783 net = libcfs_str2net(nw);
1784 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1787 "\"cannot parse net '%s'\"", nw);
1788 rc = LUSTRE_CFG_RC_BAD_PARAM;
1793 root = cYAML_create_object(NULL, NULL);
1797 net_node = cYAML_create_seq(root, "net");
1798 if (net_node == NULL)
1805 memset(buf, 0, buf_size);
1807 LIBCFS_IOC_INIT_V2(*ni_data, lic_cfg_hdr);
1809 * set the ioc_len to the proper value since INIT assumes
1812 ni_data->lic_cfg_hdr.ioc_len = buf_size;
1813 ni_data->lic_idx = i;
1815 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LOCAL_NI, ni_data);
1821 rc_net = LNET_NIDNET(ni_data->lic_nid);
1823 /* filter on provided data */
1824 if (net != LNET_NIDNET(LNET_NID_ANY) &&
1828 /* default rc to -1 in case we hit the goto */
1832 stats = (struct lnet_ioctl_element_stats *)ni_data->lic_bulk;
1833 lnd = (struct lnet_ioctl_config_lnd_tunables *)
1834 (ni_data->lic_bulk + sizeof(*stats));
1836 if (rc_net != prev_net) {
1843 if (!cYAML_create_string(net_node, "net type",
1844 libcfs_net2str(rc_net)))
1847 tmp = cYAML_create_seq(net_node, "local NI(s)");
1853 /* create the tree to be printed. */
1854 item = cYAML_create_seq_item(tmp);
1858 if (first_seq == NULL)
1861 if (cYAML_create_string(item, "nid",
1862 libcfs_nid2str(ni_data->lic_nid)) == NULL)
1865 if (cYAML_create_string(item,
1867 (ni_data->lic_status ==
1868 LNET_NI_STATUS_UP) ?
1869 "up" : "down") == NULL)
1872 /* don't add interfaces unless there is at least one
1874 if (strlen(ni_data->lic_ni_intf[0]) > 0) {
1875 interfaces = cYAML_create_object(item, "interfaces");
1876 if (interfaces == NULL)
1879 for (j = 0; j < LNET_INTERFACES_NUM; j++) {
1880 if (strlen(ni_data->lic_ni_intf[j]) > 0) {
1882 sizeof(str_buf), "%d", j);
1883 if (cYAML_create_string(interfaces,
1885 ni_data->lic_ni_intf[j]) ==
1895 statistics = cYAML_create_object(item, "statistics");
1896 if (statistics == NULL)
1899 if (cYAML_create_number(statistics, "send_count",
1900 stats->iel_send_count)
1904 if (cYAML_create_number(statistics, "recv_count",
1905 stats->iel_recv_count)
1909 if (cYAML_create_number(statistics, "drop_count",
1910 stats->iel_drop_count)
1914 tunables = cYAML_create_object(item, "tunables");
1918 rc = lustre_net_show_tunables(tunables, &lnd->lt_cmn);
1919 if (rc != LUSTRE_CFG_RC_NO_ERR)
1922 tunables = cYAML_create_object(item, "lnd tunables");
1923 if (tunables == NULL)
1926 rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
1928 if (rc != LUSTRE_CFG_RC_NO_ERR)
1931 if (cYAML_create_number(item, "tcp bonding",
1932 ni_data->lic_tcp_bonding)
1936 if (cYAML_create_number(item, "dev cpt",
1937 ni_data->lic_dev_cpt) == NULL)
1940 /* out put the CPTs in the format: "[x,x,x,...]" */
1941 limit = str_buf + str_buf_len - 3;
1942 pos += snprintf(pos, limit - pos, "\"[");
1943 for (j = 0 ; ni_data->lic_ncpts >= 1 &&
1944 j < ni_data->lic_ncpts &&
1946 pos += snprintf(pos, limit - pos,
1947 "%d", ni_data->lic_cpts[j]);
1948 if ((j + 1) < ni_data->lic_ncpts)
1949 pos += snprintf(pos, limit - pos, ",");
1951 pos += snprintf(pos, 3, "]\"");
1953 if (ni_data->lic_ncpts >= 1 &&
1954 cYAML_create_string(item, "CPT",
1960 /* Print out the net information only if show_rc is not provided */
1961 if (show_rc == NULL)
1962 cYAML_print_tree(root);
1964 if (l_errno != ENOENT) {
1967 "\"cannot get networks: %s\"",
1972 rc = LUSTRE_CFG_RC_NO_ERR;
1974 snprintf(err_str, sizeof(err_str), "\"success\"");
1976 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
1977 cYAML_free_tree(root);
1978 } else if (show_rc != NULL && *show_rc != NULL) {
1979 struct cYAML *show_node;
1980 /* find the net node, if one doesn't exist
1981 * then insert one. Otherwise add to the one there
1983 show_node = cYAML_get_object_item(*show_rc, "net");
1984 if (show_node != NULL && cYAML_is_sequence(show_node)) {
1985 cYAML_insert_child(show_node, first_seq);
1988 } else if (show_node == NULL) {
1989 cYAML_insert_sibling((*show_rc)->cy_child,
1993 cYAML_free_tree(root);
1999 cYAML_build_error(rc, seq_no, SHOW_CMD, "net", err_str, err_rc);
2004 int lustre_lnet_enable_routing(int enable, int seq_no, struct cYAML **err_rc)
2006 struct lnet_ioctl_config_data data;
2007 int rc = LUSTRE_CFG_RC_NO_ERR;
2008 char err_str[LNET_MAX_STR_LEN];
2010 snprintf(err_str, sizeof(err_str), "\"success\"");
2012 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2013 data.cfg_config_u.cfg_buffers.buf_enable = (enable) ? 1 : 0;
2015 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIG_RTR, &data);
2020 "\"cannot %s routing %s\"",
2021 (enable) ? "enable" : "disable", strerror(errno));
2026 cYAML_build_error(rc, seq_no,
2027 (enable) ? ADD_CMD : DEL_CMD,
2028 "routing", err_str, err_rc);
2033 int ioctl_set_value(__u32 val, int ioc, char *name,
2034 int seq_no, struct cYAML **err_rc)
2036 struct lnet_ioctl_set_value data;
2037 int rc = LUSTRE_CFG_RC_NO_ERR;
2038 char err_str[LNET_MAX_STR_LEN];
2040 snprintf(err_str, sizeof(err_str), "\"success\"");
2042 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2043 data.sv_value = val;
2045 rc = l_ioctl(LNET_DEV_ID, ioc , &data);
2050 "\"cannot configure %s to %d: %s\"", name,
2051 val, strerror(errno));
2054 cYAML_build_error(rc, seq_no, ADD_CMD, name, err_str, err_rc);
2059 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
2061 int rc = LUSTRE_CFG_RC_NO_ERR;
2062 char err_str[LNET_MAX_STR_LEN];
2063 char val[LNET_MAX_STR_LEN];
2065 snprintf(err_str, sizeof(err_str), "\"success\"");
2067 snprintf(val, sizeof(val), "%d", max);
2069 rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2070 1, strlen(val) + 1);
2072 snprintf(err_str, sizeof(err_str),
2073 "\"cannot configure max interfaces: %s\"",
2076 cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
2081 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
2083 int rc = LUSTRE_CFG_RC_NO_ERR;
2084 char err_str[LNET_MAX_STR_LEN];
2085 char val[LNET_MAX_STR_LEN];
2087 snprintf(err_str, sizeof(err_str), "\"success\"");
2089 snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
2091 rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2092 1, strlen(val) + 1);
2094 snprintf(err_str, sizeof(err_str),
2095 "\"cannot configure discovery: %s\"",
2098 cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
2104 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
2106 return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
2107 "numa_range", seq_no, err_rc);
2110 int lustre_lnet_config_buffers(int tiny, int small, int large, int seq_no,
2111 struct cYAML **err_rc)
2113 struct lnet_ioctl_config_data data;
2114 int rc = LUSTRE_CFG_RC_NO_ERR;
2115 char err_str[LNET_MAX_STR_LEN];
2117 snprintf(err_str, sizeof(err_str), "\"success\"");
2119 /* -1 indicates to ignore changes to this field */
2120 if (tiny < -1 || small < -1 || large < -1) {
2123 "\"tiny, small and large must be >= 0\"");
2124 rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM;
2128 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
2129 data.cfg_config_u.cfg_buffers.buf_tiny = tiny;
2130 data.cfg_config_u.cfg_buffers.buf_small = small;
2131 data.cfg_config_u.cfg_buffers.buf_large = large;
2133 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_BUF, &data);
2138 "\"cannot configure buffers: %s\"", strerror(errno));
2143 cYAML_build_error(rc, seq_no, ADD_CMD, "buf", err_str, err_rc);
2148 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
2149 struct cYAML **err_rc)
2151 struct lnet_ioctl_config_data *data;
2152 struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
2153 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2156 char *pools[LNET_NRBPOOLS] = {"tiny", "small", "large"};
2157 int buf_count[LNET_NRBPOOLS] = {0};
2158 struct cYAML *root = NULL, *pools_node = NULL,
2159 *type_node = NULL, *item = NULL, *cpt = NULL,
2160 *first_seq = NULL, *buffers = NULL;
2162 char err_str[LNET_MAX_STR_LEN];
2163 char node_name[LNET_MAX_STR_LEN];
2166 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2168 buf = calloc(1, sizeof(*data) + sizeof(*pool_cfg));
2172 data = (struct lnet_ioctl_config_data *)buf;
2174 root = cYAML_create_object(NULL, NULL);
2178 pools_node = cYAML_create_seq(root, "routing");
2179 if (pools_node == NULL)
2183 LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
2184 data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
2185 sizeof(struct lnet_ioctl_pool_cfg);
2186 data->cfg_count = i;
2188 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_BUF, data);
2196 pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
2198 snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
2199 item = cYAML_create_seq_item(pools_node);
2203 if (first_seq == NULL)
2206 cpt = cYAML_create_object(item, node_name);
2210 /* create the tree and print */
2211 for (j = 0; j < LNET_NRBPOOLS; j++) {
2212 type_node = cYAML_create_object(cpt, pools[j]);
2213 if (type_node == NULL)
2215 if (cYAML_create_number(type_node, "npages",
2216 pool_cfg->pl_pools[j].pl_npages)
2219 if (cYAML_create_number(type_node, "nbuffers",
2220 pool_cfg->pl_pools[j].
2221 pl_nbuffers) == NULL)
2223 if (cYAML_create_number(type_node, "credits",
2224 pool_cfg->pl_pools[j].
2225 pl_credits) == NULL)
2227 if (cYAML_create_number(type_node, "mincredits",
2228 pool_cfg->pl_pools[j].
2229 pl_mincredits) == NULL)
2231 /* keep track of the total count for each of the
2232 * tiny, small and large buffers */
2233 buf_count[j] += pool_cfg->pl_pools[j].pl_nbuffers;
2237 if (pool_cfg != NULL) {
2238 item = cYAML_create_seq_item(pools_node);
2242 if (cYAML_create_number(item, "enable", pool_cfg->pl_routing) ==
2247 /* create a buffers entry in the show. This is necessary so that
2248 * if the YAML output is used to configure a node, the buffer
2249 * configuration takes hold */
2250 buffers = cYAML_create_object(root, "buffers");
2251 if (buffers == NULL)
2254 for (i = 0; i < LNET_NRBPOOLS; i++) {
2255 if (cYAML_create_number(buffers, pools[i], buf_count[i]) == NULL)
2259 if (show_rc == NULL)
2260 cYAML_print_tree(root);
2262 if (l_errno != ENOENT) {
2265 "\"cannot get routing information: %s\"",
2270 rc = LUSTRE_CFG_RC_NO_ERR;
2272 snprintf(err_str, sizeof(err_str), "\"success\"");
2273 rc = LUSTRE_CFG_RC_NO_ERR;
2277 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR || !exist) {
2278 cYAML_free_tree(root);
2279 } else if (show_rc != NULL && *show_rc != NULL) {
2280 struct cYAML *routing_node;
2281 /* there should exist only one routing block and one
2282 * buffers block. If there already exists a previous one
2283 * then don't add another */
2284 routing_node = cYAML_get_object_item(*show_rc, "routing");
2285 if (routing_node == NULL) {
2286 cYAML_insert_sibling((*show_rc)->cy_child,
2290 cYAML_free_tree(root);
2296 cYAML_build_error(rc, seq_no, SHOW_CMD, "routing", err_str, err_rc);
2301 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
2302 struct cYAML **show_rc, struct cYAML **err_rc)
2305 * TODO: This function is changing in a future patch to accommodate
2306 * PEER_LIST and proper filtering on any nid of the peer
2308 struct lnet_ioctl_peer_cfg peer_info;
2309 struct lnet_peer_ni_credit_info *lpni_cri;
2310 struct lnet_ioctl_element_stats *lpni_stats;
2312 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2318 struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
2319 *first_seq = NULL, *peer_root = NULL, *tmp = NULL;
2320 char err_str[LNET_MAX_STR_LEN];
2321 lnet_process_id_t *list = NULL;
2325 snprintf(err_str, sizeof(err_str),
2326 "\"out of memory\"");
2328 /* create struct cYAML root object */
2329 root = cYAML_create_object(NULL, NULL);
2333 peer_root = cYAML_create_seq(root, "peer");
2334 if (peer_root == NULL)
2338 size = count * sizeof(lnet_process_id_t);
2339 list = malloc(size);
2345 list[0].nid = libcfs_str2nid(knid);
2349 memset(&peer_info, 0, sizeof(peer_info));
2350 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2351 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2352 peer_info.prcfg_size = size;
2353 peer_info.prcfg_bulk = list;
2356 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
2358 count = peer_info.prcfg_count;
2362 if (l_errno != E2BIG) {
2365 "\"cannot get peer list: %s\"",
2371 size = peer_info.prcfg_size;
2372 list = malloc(size);
2381 data = malloc(size);
2386 for (i = 0; i < count; i++) {
2388 memset(&peer_info, 0, sizeof(peer_info));
2389 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2390 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2391 peer_info.prcfg_prim_nid = list[i].nid;
2392 peer_info.prcfg_size = size;
2393 peer_info.prcfg_bulk = data;
2396 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
2401 if (l_errno != E2BIG) {
2404 "\"cannot get peer information: %s\"",
2410 size = peer_info.prcfg_size;
2411 data = malloc(size);
2418 peer = cYAML_create_seq_item(peer_root);
2422 if (first_seq == NULL)
2425 lnet_nid_t pnid = peer_info.prcfg_prim_nid;
2426 if (cYAML_create_string(peer, "primary nid",
2427 libcfs_nid2str(pnid))
2430 if (cYAML_create_string(peer, "Multi-Rail",
2431 peer_info.prcfg_mr ? "True" : "False")
2435 tmp = cYAML_create_seq(peer, "peer ni");
2440 for (j = 0; j < peer_info.prcfg_count; j++) {
2442 lpni_cri = (void*)nidp + sizeof(nidp);
2443 lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
2444 lpni_data = (void *)lpni_stats + sizeof(*lpni_stats);
2446 peer_ni = cYAML_create_seq_item(tmp);
2447 if (peer_ni == NULL)
2450 if (cYAML_create_string(peer_ni, "nid",
2451 libcfs_nid2str(*nidp))
2455 if (cYAML_create_string(peer_ni, "state",
2456 lpni_cri->cr_aliveness)
2463 if (cYAML_create_number(peer_ni, "max_ni_tx_credits",
2464 lpni_cri->cr_ni_peer_tx_credits)
2468 if (cYAML_create_number(peer_ni, "available_tx_credits",
2469 lpni_cri->cr_peer_tx_credits)
2473 if (cYAML_create_number(peer_ni, "min_tx_credits",
2474 lpni_cri->cr_peer_min_tx_credits)
2478 if (cYAML_create_number(peer_ni, "tx_q_num_of_buf",
2479 lpni_cri->cr_peer_tx_qnob)
2483 if (cYAML_create_number(peer_ni, "available_rtr_credits",
2484 lpni_cri->cr_peer_rtr_credits)
2488 if (cYAML_create_number(peer_ni, "min_rtr_credits",
2489 lpni_cri->cr_peer_min_rtr_credits)
2493 if (cYAML_create_number(peer_ni, "send_count",
2494 lpni_stats->iel_send_count)
2498 if (cYAML_create_number(peer_ni, "recv_count",
2499 lpni_stats->iel_recv_count)
2503 if (cYAML_create_number(peer_ni, "drop_count",
2504 lpni_stats->iel_drop_count)
2508 if (cYAML_create_number(peer_ni, "refcount",
2509 lpni_cri->cr_refcount) == NULL)
2514 /* print output iff show_rc is not provided */
2515 if (show_rc == NULL)
2516 cYAML_print_tree(root);
2518 snprintf(err_str, sizeof(err_str), "\"success\"");
2519 rc = LUSTRE_CFG_RC_NO_ERR;
2524 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2525 cYAML_free_tree(root);
2526 } else if (show_rc != NULL && *show_rc != NULL) {
2527 struct cYAML *show_node;
2528 /* find the peer node, if one doesn't exist then
2529 * insert one. Otherwise add to the one there
2531 show_node = cYAML_get_object_item(*show_rc,
2533 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2534 cYAML_insert_child(show_node, first_seq);
2537 } else if (show_node == NULL) {
2538 cYAML_insert_sibling((*show_rc)->cy_child,
2542 cYAML_free_tree(root);
2548 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
2554 int lustre_lnet_list_peer(int seq_no,
2555 struct cYAML **show_rc, struct cYAML **err_rc)
2557 struct lnet_ioctl_peer_cfg peer_info;
2558 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2563 struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
2564 char err_str[LNET_MAX_STR_LEN];
2565 lnet_process_id_t *list = NULL;
2567 snprintf(err_str, sizeof(err_str),
2568 "\"out of memory\"");
2570 memset(&peer_info, 0, sizeof(peer_info));
2572 /* create struct cYAML root object */
2573 root = cYAML_create_object(NULL, NULL);
2577 list_root = cYAML_create_seq(root, "peer list");
2578 if (list_root == NULL)
2582 size = count * sizeof(lnet_process_id_t);
2583 list = malloc(size);
2589 LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
2590 peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
2591 peer_info.prcfg_size = size;
2592 peer_info.prcfg_bulk = list;
2595 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
2596 count = peer_info.prcfg_count;
2600 if (l_errno != E2BIG) {
2603 "\"cannot get peer list: %s\"",
2609 size = peer_info.prcfg_size;
2610 list = malloc(size);
2617 /* count is now the actual number of ids in the list. */
2618 for (i = 0; i < count; i++) {
2619 if (cYAML_create_string(list_root, "nid",
2620 libcfs_nid2str(list[i].nid))
2625 /* print output iff show_rc is not provided */
2626 if (show_rc == NULL)
2627 cYAML_print_tree(root);
2629 snprintf(err_str, sizeof(err_str), "\"success\"");
2630 rc = LUSTRE_CFG_RC_NO_ERR;
2635 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2636 cYAML_free_tree(root);
2637 } else if (show_rc != NULL && *show_rc != NULL) {
2638 struct cYAML *show_node;
2639 /* find the peer node, if one doesn't exist then
2640 * insert one. Otherwise add to the one there
2642 show_node = cYAML_get_object_item(*show_rc,
2644 if (show_node != NULL && cYAML_is_sequence(show_node)) {
2645 cYAML_insert_child(show_node, first_seq);
2648 } else if (show_node == NULL) {
2649 cYAML_insert_sibling((*show_rc)->cy_child,
2653 cYAML_free_tree(root);
2659 cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
2665 static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
2668 struct cYAML *show_node;
2670 show_node = cYAML_get_object_item(show_rc, "global");
2671 if (show_node != NULL)
2672 cYAML_insert_sibling(show_node->cy_child,
2675 cYAML_insert_sibling(show_rc->cy_child,
2680 static int build_global_yaml_entry(char *err_str, int err_len, int seq_no,
2681 char *name, __u32 value,
2682 struct cYAML **show_rc,
2683 struct cYAML **err_rc, int err)
2685 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2686 struct cYAML *root = NULL, *global = NULL;
2693 root = cYAML_create_object(NULL, NULL);
2697 global = cYAML_create_object(root, "global");
2701 if (cYAML_create_number(global, name,
2705 if (show_rc == NULL)
2706 cYAML_print_tree(root);
2708 snprintf(err_str, err_len, "\"success\"");
2710 rc = LUSTRE_CFG_RC_NO_ERR;
2713 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2714 cYAML_free_tree(root);
2715 } else if (show_rc != NULL && *show_rc != NULL) {
2716 add_to_global(*show_rc, global, root);
2721 cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
2726 static int ioctl_show_global_values(int ioc, int seq_no, char *name,
2727 struct cYAML **show_rc,
2728 struct cYAML **err_rc)
2730 struct lnet_ioctl_set_value data;
2733 char err_str[LNET_MAX_STR_LEN];
2735 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2737 LIBCFS_IOC_INIT_V2(data, sv_hdr);
2739 rc = l_ioctl(LNET_DEV_ID, ioc, &data);
2744 "\"cannot get %s: %s\"",
2745 name, strerror(l_errno));
2748 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no, name,
2749 data.sv_value, show_rc, err_rc, l_errno);
2752 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
2753 struct cYAML **err_rc)
2755 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2756 char val[LNET_MAX_STR_LEN];
2757 int max_intf = -1, l_errno = 0;
2758 char err_str[LNET_MAX_STR_LEN];
2760 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2762 rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
2766 snprintf(err_str, sizeof(err_str),
2767 "\"cannot get max interfaces: %d\"", rc);
2769 max_intf = atoi(val);
2772 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
2773 "max_intf", max_intf, show_rc,
2777 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
2778 struct cYAML **err_rc)
2780 int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2781 char val[LNET_MAX_STR_LEN];
2782 int discovery = -1, l_errno = 0;
2783 char err_str[LNET_MAX_STR_LEN];
2785 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2787 rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
2791 snprintf(err_str, sizeof(err_str),
2792 "\"cannot get discovery setting: %d\"", rc);
2795 * The kernel stores a discovery disabled value. User space
2796 * shows whether discovery is enabled. So the value must be
2799 discovery = !atoi(val);
2802 return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
2803 "discovery", discovery, show_rc,
2807 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
2808 struct cYAML **err_rc)
2810 return ioctl_show_global_values(IOC_LIBCFS_GET_NUMA_RANGE, seq_no,
2811 "numa_range", show_rc, err_rc);
2814 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
2815 struct cYAML **err_rc)
2817 struct lnet_ioctl_lnet_stats data;
2820 char err_str[LNET_MAX_STR_LEN];
2821 struct cYAML *root = NULL, *stats = NULL;
2823 snprintf(err_str, sizeof(err_str), "\"out of memory\"");
2825 LIBCFS_IOC_INIT_V2(data, st_hdr);
2827 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
2832 "\"cannot get lnet statistics: %s\"",
2838 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
2840 root = cYAML_create_object(NULL, NULL);
2844 stats = cYAML_create_object(root, "statistics");
2848 if (cYAML_create_number(stats, "msgs_alloc",
2849 data.st_cntrs.msgs_alloc) == NULL)
2852 if (cYAML_create_number(stats, "msgs_max",
2853 data.st_cntrs.msgs_max) == NULL)
2856 if (cYAML_create_number(stats, "errors",
2857 data.st_cntrs.errors) == NULL)
2860 if (cYAML_create_number(stats, "send_count",
2861 data.st_cntrs.send_count) == NULL)
2864 if (cYAML_create_number(stats, "recv_count",
2865 data.st_cntrs.recv_count) == NULL)
2868 if (cYAML_create_number(stats, "route_count",
2869 data.st_cntrs.route_count) == NULL)
2872 if (cYAML_create_number(stats, "drop_count",
2873 data.st_cntrs.drop_count) == NULL)
2876 if (cYAML_create_number(stats, "send_length",
2877 data.st_cntrs.send_length) == NULL)
2880 if (cYAML_create_number(stats, "recv_length",
2881 data.st_cntrs.recv_length) == NULL)
2884 if (cYAML_create_number(stats, "route_length",
2885 data.st_cntrs.route_length) == NULL)
2888 if (cYAML_create_number(stats, "drop_length",
2889 data.st_cntrs.drop_length) == NULL)
2892 if (show_rc == NULL)
2893 cYAML_print_tree(root);
2895 snprintf(err_str, sizeof(err_str), "\"success\"");
2896 rc = LUSTRE_CFG_RC_NO_ERR;
2898 if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
2899 cYAML_free_tree(root);
2900 } else if (show_rc != NULL && *show_rc != NULL) {
2901 cYAML_insert_sibling((*show_rc)->cy_child,
2908 cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc);
2913 typedef int (*cmd_handler_t)(struct cYAML *tree,
2914 struct cYAML **show_rc,
2915 struct cYAML **err_rc);
2917 static int handle_yaml_config_route(struct cYAML *tree, struct cYAML **show_rc,
2918 struct cYAML **err_rc)
2920 struct cYAML *net, *gw, *hop, *prio, *seq_no;
2922 net = cYAML_get_object_item(tree, "net");
2923 gw = cYAML_get_object_item(tree, "gateway");
2924 hop = cYAML_get_object_item(tree, "hop");
2925 prio = cYAML_get_object_item(tree, "priority");
2926 seq_no = cYAML_get_object_item(tree, "seq_no");
2928 return lustre_lnet_config_route((net) ? net->cy_valuestring : NULL,
2929 (gw) ? gw->cy_valuestring : NULL,
2930 (hop) ? hop->cy_valueint : -1,
2931 (prio) ? prio->cy_valueint : -1,
2932 (seq_no) ? seq_no->cy_valueint : -1,
2936 static void yaml_free_string_array(char **array, int num)
2939 char **sub_array = array;
2941 for (i = 0; i < num; i++) {
2942 if (*sub_array != NULL)
2952 * 0: <intf_name>['['<expr>']']
2953 * 1: <intf_name>['['<expr>']']
2955 static int yaml_copy_intf_info(struct cYAML *intf_tree,
2956 struct lnet_dlc_network_descr *nw_descr)
2958 struct cYAML *child = NULL;
2959 int intf_num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
2960 struct lnet_dlc_intf_descr *intf_descr, *tmp;
2962 if (intf_tree == NULL || nw_descr == NULL)
2963 return LUSTRE_CFG_RC_BAD_PARAM;
2965 /* now grab all the interfaces and their cpts */
2966 child = intf_tree->cy_child;
2967 while (child != NULL) {
2968 if (child->cy_valuestring == NULL) {
2969 child = child->cy_next;
2973 if (strlen(child->cy_valuestring) >= LNET_MAX_STR_LEN)
2976 rc = lustre_lnet_add_intf_descr(&nw_descr->nw_intflist,
2977 child->cy_valuestring,
2978 strlen(child->cy_valuestring));
2979 if (rc != LUSTRE_CFG_RC_NO_ERR)
2983 child = child->cy_next;
2987 return LUSTRE_CFG_RC_MISSING_PARAM;
2992 list_for_each_entry_safe(intf_descr, tmp, &nw_descr->nw_intflist,
2994 list_del(&intf_descr->intf_on_network);
2995 free_intf_descr(intf_descr);
3002 yaml_extract_cmn_tunables(struct cYAML *tree,
3003 struct lnet_ioctl_config_lnd_cmn_tunables *tunables,
3004 struct cfs_expr_list **global_cpts)
3006 struct cYAML *tun, *item, *smp;
3009 tun = cYAML_get_object_item(tree, "tunables");
3011 item = cYAML_get_object_item(tun, "peer_timeout");
3013 tunables->lct_peer_timeout = item->cy_valueint;
3014 item = cYAML_get_object_item(tun, "peer_credits");
3016 tunables->lct_peer_tx_credits = item->cy_valueint;
3017 item = cYAML_get_object_item(tun, "peer_buffer_credits");
3019 tunables->lct_peer_rtr_credits = item->cy_valueint;
3020 item = cYAML_get_object_item(tun, "credits");
3022 tunables->lct_max_tx_credits = item->cy_valueint;
3023 smp = cYAML_get_object_item(tun, "CPT");
3025 rc = cfs_expr_list_parse(smp->cy_valuestring,
3026 strlen(smp->cy_valuestring),
3027 0, UINT_MAX, global_cpts);
3029 *global_cpts = NULL;
3039 yaml_extract_tunables(struct cYAML *tree,
3040 struct lnet_ioctl_config_lnd_tunables *tunables,
3041 struct cfs_expr_list **global_cpts,
3046 rc = yaml_extract_cmn_tunables(tree, &tunables->lt_cmn,
3052 lustre_yaml_extract_lnd_tunables(tree, net_type,
3060 * - net type: <net>[<NUM>]
3062 * - nid: <ip>@<net>[<NUM>]
3065 * 0: <intf_name>['['<expr>']']
3066 * 1: <intf_name>['['<expr>']']
3068 * peer_timeout: <NUM>
3069 * peer_credits: <NUM>
3070 * peer_buffer_credits: <NUM>
3073 * peercredits_hiw: <NUM>
3074 * map_on_demand: <NUM>
3075 * concurrent_sends: <NUM>
3076 * fmr_pool_size: <NUM>
3077 * fmr_flush_trigger: <NUM>
3080 * At least one interface is required. If no interfaces are provided the
3081 * network interface can not be configured.
3083 static int handle_yaml_config_ni(struct cYAML *tree, struct cYAML **show_rc,
3084 struct cYAML **err_rc)
3086 struct cYAML *net, *intf, *seq_no, *ip2net = NULL, *local_nis = NULL,
3088 int num_entries = 0, rc;
3089 struct lnet_dlc_network_descr nw_descr;
3090 struct cfs_expr_list *global_cpts = NULL;
3091 struct lnet_ioctl_config_lnd_tunables tunables;
3094 memset(&tunables, 0, sizeof(tunables));
3096 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3097 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3099 ip2net = cYAML_get_object_item(tree, "ip2net");
3100 net = cYAML_get_object_item(tree, "net type");
3102 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3104 nw_descr.nw_id = LOLND;
3107 * if neither net nor ip2nets are present, then we can not
3108 * configure the network.
3110 if (!net && !ip2net)
3111 return LUSTRE_CFG_RC_MISSING_PARAM;
3113 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3114 if (local_nis == NULL)
3115 return LUSTRE_CFG_RC_MISSING_PARAM;
3117 if (!cYAML_is_sequence(local_nis))
3118 return LUSTRE_CFG_RC_BAD_PARAM;
3120 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3121 intf = cYAML_get_object_item(item, "interfaces");
3124 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3125 if (num_entries <= 0) {
3126 cYAML_build_error(num_entries, -1, "ni", "add",
3127 "bad interface list",
3129 return LUSTRE_CFG_RC_BAD_PARAM;
3133 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3134 LNET_NETTYP(nw_descr.nw_id));
3135 seq_no = cYAML_get_object_item(tree, "seq_no");
3137 rc = lustre_lnet_config_ni(&nw_descr,
3139 (ip2net) ? ip2net->cy_valuestring : NULL,
3140 (found) ? &tunables: NULL,
3141 (seq_no) ? seq_no->cy_valueint : -1,
3144 if (global_cpts != NULL)
3145 cfs_expr_list_free(global_cpts);
3152 * - net-spec: <tcp|o2ib|gni>[NUM]
3154 * 0: <intf name>['['<expr>']']
3155 * 1: <intf name>['['<expr>']']
3157 * 0: <expr.expr.expr.expr>
3158 * 1: <expr.expr.expr.expr>
3160 static int handle_yaml_config_ip2nets(struct cYAML *tree,
3161 struct cYAML **show_rc,
3162 struct cYAML **err_rc)
3164 struct cYAML *net, *ip_range, *item = NULL, *intf = NULL,
3166 struct lustre_lnet_ip2nets ip2nets;
3167 struct lustre_lnet_ip_range_descr *ip_range_descr = NULL,
3169 int rc = LUSTRE_CFG_RC_NO_ERR;
3170 struct cfs_expr_list *global_cpts = NULL;
3171 struct cfs_expr_list *el, *el_tmp;
3172 struct lnet_ioctl_config_lnd_tunables tunables;
3173 struct lnet_dlc_intf_descr *intf_descr, *intf_tmp;
3176 memset(&tunables, 0, sizeof(tunables));
3178 /* initialize all lists */
3179 INIT_LIST_HEAD(&ip2nets.ip2nets_ip_ranges);
3180 INIT_LIST_HEAD(&ip2nets.ip2nets_net.network_on_rule);
3181 INIT_LIST_HEAD(&ip2nets.ip2nets_net.nw_intflist);
3183 net = cYAML_get_object_item(tree, "net-spec");
3185 return LUSTRE_CFG_RC_BAD_PARAM;
3187 if (net != NULL && net->cy_valuestring == NULL)
3188 return LUSTRE_CFG_RC_BAD_PARAM;
3190 /* assign the network id */
3191 ip2nets.ip2nets_net.nw_id = libcfs_str2net(net->cy_valuestring);
3192 if (ip2nets.ip2nets_net.nw_id == LNET_NID_ANY)
3193 return LUSTRE_CFG_RC_BAD_PARAM;
3195 seq_no = cYAML_get_object_item(tree, "seq_no");
3197 intf = cYAML_get_object_item(tree, "interfaces");
3199 rc = yaml_copy_intf_info(intf, &ip2nets.ip2nets_net);
3201 return LUSTRE_CFG_RC_BAD_PARAM;
3204 ip_range = cYAML_get_object_item(tree, "ip-range");
3205 if (ip_range != NULL) {
3206 item = ip_range->cy_child;
3207 while (item != NULL) {
3208 if (item->cy_valuestring == NULL) {
3209 item = item->cy_next;
3213 rc = lustre_lnet_add_ip_range(&ip2nets.ip2nets_ip_ranges,
3214 item->cy_valuestring);
3216 if (rc != LUSTRE_CFG_RC_NO_ERR)
3219 item = item->cy_next;
3223 found = yaml_extract_tunables(tree, &tunables, &global_cpts,
3224 LNET_NETTYP(ip2nets.ip2nets_net.nw_id));
3226 rc = lustre_lnet_config_ip2nets(&ip2nets,
3227 (found) ? &tunables : NULL,
3229 (seq_no) ? seq_no->cy_valueint : -1,
3233 * don't stop because there was no match. Continue processing the
3234 * rest of the rules. If non-match then nothing is configured
3236 if (rc == LUSTRE_CFG_RC_NO_MATCH)
3237 rc = LUSTRE_CFG_RC_NO_ERR;
3239 list_for_each_entry_safe(intf_descr, intf_tmp,
3240 &ip2nets.ip2nets_net.nw_intflist,
3242 list_del(&intf_descr->intf_on_network);
3243 free_intf_descr(intf_descr);
3246 list_for_each_entry_safe(ip_range_descr, tmp,
3247 &ip2nets.ip2nets_ip_ranges,
3249 list_del(&ip_range_descr->ipr_entry);
3250 list_for_each_entry_safe(el, el_tmp, &ip_range_descr->ipr_expr,
3252 list_del(&el->el_link);
3253 cfs_expr_list_free(el);
3255 free(ip_range_descr);
3261 static int handle_yaml_del_ni(struct cYAML *tree, struct cYAML **show_rc,
3262 struct cYAML **err_rc)
3264 struct cYAML *net = NULL, *intf = NULL, *seq_no = NULL, *item = NULL,
3266 int num_entries, rc;
3267 struct lnet_dlc_network_descr nw_descr;
3269 INIT_LIST_HEAD(&nw_descr.network_on_rule);
3270 INIT_LIST_HEAD(&nw_descr.nw_intflist);
3272 net = cYAML_get_object_item(tree, "net type");
3274 nw_descr.nw_id = libcfs_str2net(net->cy_valuestring);
3276 local_nis = cYAML_get_object_item(tree, "local NI(s)");
3277 if (local_nis == NULL)
3278 return LUSTRE_CFG_RC_MISSING_PARAM;
3280 if (!cYAML_is_sequence(local_nis))
3281 return LUSTRE_CFG_RC_BAD_PARAM;
3283 while (cYAML_get_next_seq_item(local_nis, &item) != NULL) {
3284 intf = cYAML_get_object_item(item, "interfaces");
3287 num_entries = yaml_copy_intf_info(intf, &nw_descr);
3288 if (num_entries <= 0) {
3289 cYAML_build_error(num_entries, -1, "ni", "add",
3290 "bad interface list",
3292 return LUSTRE_CFG_RC_BAD_PARAM;
3296 seq_no = cYAML_get_object_item(tree, "seq_no");
3298 rc = lustre_lnet_del_ni((net) ? &nw_descr : NULL,
3299 (seq_no) ? seq_no->cy_valueint : -1,
3305 static int yaml_copy_peer_nids(struct cYAML *tree, char ***nidsppp, bool del)
3307 struct cYAML *nids_entry = NULL, *child = NULL, *entry = NULL,
3310 int num = 0, rc = LUSTRE_CFG_RC_NO_ERR;
3312 prim_nid = cYAML_get_object_item(tree, "primary nid");
3313 if (!prim_nid || !prim_nid->cy_valuestring)
3314 return LUSTRE_CFG_RC_MISSING_PARAM;
3316 nids_entry = cYAML_get_object_item(tree, "peer ni");
3317 if (cYAML_is_sequence(nids_entry)) {
3318 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3319 entry = cYAML_get_object_item(child, "nid");
3320 /* don't count an empty entry */
3321 if (!entry || !entry->cy_valuestring)
3324 if ((strcmp(entry->cy_valuestring, prim_nid->cy_valuestring)
3327 * primary nid is present in the list of
3328 * nids so that means we want to delete
3329 * the entire peer, so no need to go
3330 * further. Just delete the entire peer.
3340 return LUSTRE_CFG_RC_MISSING_PARAM;
3342 nids = calloc(sizeof(*nids) * num, 1);
3344 return LUSTRE_CFG_RC_OUT_OF_MEM;
3346 /* now grab all the nids */
3349 while (cYAML_get_next_seq_item(nids_entry, &child)) {
3350 entry = cYAML_get_object_item(child, "nid");
3351 if (!entry || !entry->cy_valuestring)
3354 nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
3356 rc = LUSTRE_CFG_RC_OUT_OF_MEM;
3359 strncpy(nids[num], entry->cy_valuestring,
3360 strlen(entry->cy_valuestring));
3370 yaml_free_string_array(nids, num);
3375 static int handle_yaml_config_peer(struct cYAML *tree, struct cYAML **show_rc,
3376 struct cYAML **err_rc)
3380 struct cYAML *seq_no, *prim_nid, *non_mr;
3382 num = yaml_copy_peer_nids(tree, &nids, false);
3386 seq_no = cYAML_get_object_item(tree, "seq_no");
3387 prim_nid = cYAML_get_object_item(tree, "primary nid");
3388 non_mr = cYAML_get_object_item(tree, "non_mr");
3390 rc = lustre_lnet_config_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3392 (non_mr) ? false : true,
3393 (seq_no) ? seq_no->cy_valueint : -1,
3396 yaml_free_string_array(nids, num);
3400 static int handle_yaml_del_peer(struct cYAML *tree, struct cYAML **show_rc,
3401 struct cYAML **err_rc)
3405 struct cYAML *seq_no, *prim_nid;
3407 num = yaml_copy_peer_nids(tree, &nids, true);
3411 seq_no = cYAML_get_object_item(tree, "seq_no");
3412 prim_nid = cYAML_get_object_item(tree, "primary nid");
3414 rc = lustre_lnet_del_peer_nid((prim_nid) ? prim_nid->cy_valuestring : NULL,
3416 (seq_no) ? seq_no->cy_valueint : -1,
3419 yaml_free_string_array(nids, num);
3423 static int handle_yaml_config_buffers(struct cYAML *tree,
3424 struct cYAML **show_rc,
3425 struct cYAML **err_rc)
3428 struct cYAML *tiny, *small, *large, *seq_no;
3430 tiny = cYAML_get_object_item(tree, "tiny");
3431 small = cYAML_get_object_item(tree, "small");
3432 large = cYAML_get_object_item(tree, "large");
3433 seq_no = cYAML_get_object_item(tree, "seq_no");
3435 rc = lustre_lnet_config_buffers((tiny) ? tiny->cy_valueint : -1,
3436 (small) ? small->cy_valueint : -1,
3437 (large) ? large->cy_valueint : -1,
3438 (seq_no) ? seq_no->cy_valueint : -1,
3444 static int handle_yaml_config_routing(struct cYAML *tree,
3445 struct cYAML **show_rc,
3446 struct cYAML **err_rc)
3448 int rc = LUSTRE_CFG_RC_NO_ERR;
3449 struct cYAML *seq_no, *enable;
3451 seq_no = cYAML_get_object_item(tree, "seq_no");
3452 enable = cYAML_get_object_item(tree, "enable");
3455 rc = lustre_lnet_enable_routing(enable->cy_valueint,
3457 seq_no->cy_valueint : -1,
3464 static int handle_yaml_del_route(struct cYAML *tree, struct cYAML **show_rc,
3465 struct cYAML **err_rc)
3469 struct cYAML *seq_no;
3471 net = cYAML_get_object_item(tree, "net");
3472 gw = cYAML_get_object_item(tree, "gateway");
3473 seq_no = cYAML_get_object_item(tree, "seq_no");
3475 return lustre_lnet_del_route((net) ? net->cy_valuestring : NULL,
3476 (gw) ? gw->cy_valuestring : NULL,
3477 (seq_no) ? seq_no->cy_valueint : -1,
3481 static int handle_yaml_del_routing(struct cYAML *tree, struct cYAML **show_rc,
3482 struct cYAML **err_rc)
3484 struct cYAML *seq_no;
3486 seq_no = cYAML_get_object_item(tree, "seq_no");
3488 return lustre_lnet_enable_routing(0, (seq_no) ?
3489 seq_no->cy_valueint : -1,
3493 static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
3494 struct cYAML **err_rc)
3500 struct cYAML *detail;
3501 struct cYAML *seq_no;
3503 net = cYAML_get_object_item(tree, "net");
3504 gw = cYAML_get_object_item(tree, "gateway");
3505 hop = cYAML_get_object_item(tree, "hop");
3506 prio = cYAML_get_object_item(tree, "priority");
3507 detail = cYAML_get_object_item(tree, "detail");
3508 seq_no = cYAML_get_object_item(tree, "seq_no");
3510 return lustre_lnet_show_route((net) ? net->cy_valuestring : NULL,
3511 (gw) ? gw->cy_valuestring : NULL,
3512 (hop) ? hop->cy_valueint : -1,
3513 (prio) ? prio->cy_valueint : -1,
3514 (detail) ? detail->cy_valueint : 0,
3515 (seq_no) ? seq_no->cy_valueint : -1,
3520 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
3521 struct cYAML **err_rc)
3523 struct cYAML *net, *detail, *seq_no;
3525 net = cYAML_get_object_item(tree, "net");
3526 detail = cYAML_get_object_item(tree, "detail");
3527 seq_no = cYAML_get_object_item(tree, "seq_no");
3529 return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
3530 (detail) ? detail->cy_valueint : 0,
3531 (seq_no) ? seq_no->cy_valueint : -1,
3536 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
3537 struct cYAML **err_rc)
3539 struct cYAML *seq_no;
3541 seq_no = cYAML_get_object_item(tree, "seq_no");
3543 return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
3547 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
3548 struct cYAML **err_rc)
3550 struct cYAML *seq_no, *nid, *detail;
3552 seq_no = cYAML_get_object_item(tree, "seq_no");
3553 detail = cYAML_get_object_item(tree, "detail");
3554 nid = cYAML_get_object_item(tree, "nid");
3556 return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
3557 (detail) ? detail->cy_valueint : 0,
3558 (seq_no) ? seq_no->cy_valueint : -1,
3562 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
3563 struct cYAML **err_rc)
3565 struct cYAML *seq_no;
3567 seq_no = cYAML_get_object_item(tree, "seq_no");
3569 return lustre_lnet_show_stats((seq_no) ? seq_no->cy_valueint : -1,
3573 static int handle_yaml_config_global_settings(struct cYAML *tree,
3574 struct cYAML **show_rc,
3575 struct cYAML **err_rc)
3577 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3580 seq_no = cYAML_get_object_item(tree, "seq_no");
3581 max_intf = cYAML_get_object_item(tree, "max_intf");
3583 rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
3584 seq_no ? seq_no->cy_valueint
3588 numa = cYAML_get_object_item(tree, "numa_range");
3590 rc = lustre_lnet_config_numa_range(numa->cy_valueint,
3591 seq_no ? seq_no->cy_valueint
3595 discovery = cYAML_get_object_item(tree, "discovery");
3597 rc = lustre_lnet_config_discovery(discovery->cy_valueint,
3598 seq_no ? seq_no->cy_valueint
3605 static int handle_yaml_del_global_settings(struct cYAML *tree,
3606 struct cYAML **show_rc,
3607 struct cYAML **err_rc)
3609 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3612 seq_no = cYAML_get_object_item(tree, "seq_no");
3613 max_intf = cYAML_get_object_item(tree, "max_intf");
3615 rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
3616 seq_no ? seq_no->cy_valueint
3620 numa = cYAML_get_object_item(tree, "numa_range");
3622 rc = lustre_lnet_config_numa_range(0,
3623 seq_no ? seq_no->cy_valueint
3627 /* peer discovery is enabled by default */
3628 discovery = cYAML_get_object_item(tree, "discovery");
3630 rc = lustre_lnet_config_discovery(1,
3631 seq_no ? seq_no->cy_valueint
3638 static int handle_yaml_show_global_settings(struct cYAML *tree,
3639 struct cYAML **show_rc,
3640 struct cYAML **err_rc)
3642 struct cYAML *max_intf, *numa, *discovery, *seq_no;
3645 seq_no = cYAML_get_object_item(tree, "seq_no");
3646 max_intf = cYAML_get_object_item(tree, "max_intf");
3648 rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
3652 numa = cYAML_get_object_item(tree, "numa_range");
3654 rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
3658 discovery = cYAML_get_object_item(tree, "discovery");
3660 rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
3667 static int handle_yaml_ping(struct cYAML *tree, struct cYAML **show_rc,
3668 struct cYAML **err_rc)
3670 struct cYAML *seq_no, *nid, *timeout;
3672 seq_no = cYAML_get_object_item(tree, "seq_no");
3673 nid = cYAML_get_object_item(tree, "primary nid");
3674 timeout = cYAML_get_object_item(tree, "timeout");
3676 return lustre_lnet_ping_nid((nid) ? nid->cy_valuestring : NULL,
3677 (timeout) ? timeout->cy_valueint : 1000,
3678 (seq_no) ? seq_no->cy_valueint : -1,
3682 static int handle_yaml_discover(struct cYAML *tree, struct cYAML **show_rc,
3683 struct cYAML **err_rc)
3685 struct cYAML *seq_no, *nid, *force;
3687 seq_no = cYAML_get_object_item(tree, "seq_no");
3688 nid = cYAML_get_object_item(tree, "primary nid");
3689 force = cYAML_get_object_item(tree, "force");
3691 return lustre_lnet_discover_nid((nid) ? nid->cy_valuestring : NULL,
3692 (force) ? force->cy_valueint : 0,
3693 (seq_no) ? seq_no->cy_valueint : -1,
3697 static int handle_yaml_no_op()
3699 return LUSTRE_CFG_RC_NO_ERR;
3702 struct lookup_cmd_hdlr_tbl {
3707 static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
3708 { .name = "route", .cb = handle_yaml_config_route },
3709 { .name = "net", .cb = handle_yaml_config_ni },
3710 { .name = "ip2nets", .cb = handle_yaml_config_ip2nets },
3711 { .name = "peer", .cb = handle_yaml_config_peer },
3712 { .name = "routing", .cb = handle_yaml_config_routing },
3713 { .name = "buffers", .cb = handle_yaml_config_buffers },
3714 { .name = "statistics", .cb = handle_yaml_no_op },
3715 { .name = "global", .cb = handle_yaml_config_global_settings},
3716 { .name = "ping", .cb = handle_yaml_no_op },
3717 { .name = "discover", .cb = handle_yaml_no_op },
3720 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
3721 { .name = "route", .cb = handle_yaml_del_route },
3722 { .name = "net", .cb = handle_yaml_del_ni },
3723 { .name = "ip2nets", .cb = handle_yaml_no_op },
3724 { .name = "peer", .cb = handle_yaml_del_peer },
3725 { .name = "routing", .cb = handle_yaml_del_routing },
3726 { .name = "buffers", .cb = handle_yaml_no_op },
3727 { .name = "statistics", .cb = handle_yaml_no_op },
3728 { .name = "global", .cb = handle_yaml_del_global_settings},
3729 { .name = "ping", .cb = handle_yaml_no_op },
3730 { .name = "discover", .cb = handle_yaml_no_op },
3733 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
3734 { .name = "route", .cb = handle_yaml_show_route },
3735 { .name = "net", .cb = handle_yaml_show_net },
3736 { .name = "peer", .cb = handle_yaml_show_peers },
3737 { .name = "ip2nets", .cb = handle_yaml_no_op },
3738 { .name = "routing", .cb = handle_yaml_show_routing },
3739 { .name = "buffers", .cb = handle_yaml_show_routing },
3740 { .name = "statistics", .cb = handle_yaml_show_stats },
3741 { .name = "global", .cb = handle_yaml_show_global_settings},
3742 { .name = "ping", .cb = handle_yaml_no_op },
3743 { .name = "discover", .cb = handle_yaml_no_op },
3746 static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
3747 { .name = "route", .cb = handle_yaml_no_op },
3748 { .name = "net", .cb = handle_yaml_no_op },
3749 { .name = "peer", .cb = handle_yaml_no_op },
3750 { .name = "ip2nets", .cb = handle_yaml_no_op },
3751 { .name = "routing", .cb = handle_yaml_no_op },
3752 { .name = "buffers", .cb = handle_yaml_no_op },
3753 { .name = "statistics", .cb = handle_yaml_no_op },
3754 { .name = "global", .cb = handle_yaml_no_op },
3755 { .name = "ping", .cb = handle_yaml_ping },
3756 { .name = "discover", .cb = handle_yaml_discover },
3759 static cmd_handler_t lookup_fn(char *key,
3760 struct lookup_cmd_hdlr_tbl *tbl)
3766 for (i = 0; tbl[i].name != NULL; i++) {
3767 if (strncmp(key, tbl[i].name, strlen(tbl[i].name)) == 0)
3774 static int lustre_yaml_cb_helper(char *f, struct lookup_cmd_hdlr_tbl *table,
3775 struct cYAML **show_rc, struct cYAML **err_rc)
3777 struct cYAML *tree, *item = NULL, *head, *child;
3779 char err_str[LNET_MAX_STR_LEN];
3780 int rc = LUSTRE_CFG_RC_NO_ERR, return_rc = LUSTRE_CFG_RC_NO_ERR;
3782 tree = cYAML_build_tree(f, NULL, 0, err_rc, false);
3784 return LUSTRE_CFG_RC_BAD_PARAM;
3786 child = tree->cy_child;
3787 while (child != NULL) {
3788 cb = lookup_fn(child->cy_string, table);
3790 snprintf(err_str, sizeof(err_str),
3791 "\"call back for '%s' not found\"",
3793 cYAML_build_error(LUSTRE_CFG_RC_BAD_PARAM, -1,
3794 "yaml", "helper", err_str, err_rc);
3798 if (cYAML_is_sequence(child)) {
3799 while ((head = cYAML_get_next_seq_item(child, &item))
3801 rc = cb(head, show_rc, err_rc);
3802 if (rc != LUSTRE_CFG_RC_NO_ERR)
3806 rc = cb(child, show_rc, err_rc);
3807 if (rc != LUSTRE_CFG_RC_NO_ERR)
3811 child = child->cy_next;
3815 cYAML_free_tree(tree);
3820 int lustre_yaml_config(char *f, struct cYAML **err_rc)
3822 return lustre_yaml_cb_helper(f, lookup_config_tbl,
3826 int lustre_yaml_del(char *f, struct cYAML **err_rc)
3828 return lustre_yaml_cb_helper(f, lookup_del_tbl,
3832 int lustre_yaml_show(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3834 return lustre_yaml_cb_helper(f, lookup_show_tbl,
3838 int lustre_yaml_exec(char *f, struct cYAML **show_rc, struct cYAML **err_rc)
3840 return lustre_yaml_cb_helper(f, lookup_exec_tbl,