Whamcloud - gitweb
LU-9480 lnet: add "lnetctl peer list"
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig.c
index fc06e96..bb35de5 100644 (file)
@@ -47,6 +47,8 @@
 #include <linux/lnet/lnetctl.h>
 #include "liblnd.h"
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <ifaddrs.h>
 #include "liblnetconfig.h"
 #include "cyaml.h"
@@ -58,6 +60,8 @@
 #define SHOW_CMD               "show"
 #define DBG_CMD                        "dbg"
 
+#define modparam_path "/sys/module/lnet/parameters/"
+
 /*
  * lustre_lnet_ip_range_descr
  *     Describes an IP range.
@@ -77,6 +81,62 @@ struct lustre_lnet_ip2nets {
        struct list_head ip2nets_ip_ranges;
 };
 
+int open_sysfs_file(const char *path, const char *attr, const int mode)
+{
+       int fd;
+       char filename[LNET_MAX_STR_LEN];
+
+       if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
+               return -1;
+
+       snprintf(filename, sizeof(filename), "%s%s",
+                path, attr);
+
+       fd = open(filename, mode);
+
+       return fd;
+}
+
+static int read_sysfs_file(const char *path, const char *attr,
+                          void *val, const size_t size, const int nelem)
+{
+       int fd;
+       int rc = LUSTRE_CFG_RC_GENERIC_ERR;
+
+       fd = open_sysfs_file(path, attr, O_RDONLY);
+       if (fd == -1)
+               return LUSTRE_CFG_RC_NO_MATCH;
+
+       if (read(fd, val, size * nelem) == -1)
+               goto close_fd;
+
+       rc = LUSTRE_CFG_RC_NO_ERR;
+
+close_fd:
+       close(fd);
+       return rc;
+}
+
+static int write_sysfs_file(const char *path, const char *attr,
+                           void *val, const size_t size, const int nelem)
+{
+       int fd;
+       int rc = LUSTRE_CFG_RC_GENERIC_ERR;
+
+       fd = open_sysfs_file(path, attr, O_WRONLY | O_TRUNC);
+       if (fd == -1)
+               return LUSTRE_CFG_RC_NO_MATCH;
+
+       if (write(fd, val, size * nelem) == -1)
+               goto close_fd;
+
+       rc = LUSTRE_CFG_RC_NO_ERR;
+
+close_fd:
+       close(fd);
+       return rc;
+}
+
 /*
  * free_intf_descr
  *     frees the memory allocated for an intf descriptor.
@@ -1623,7 +1683,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                        if (interfaces == NULL)
                                goto out;
 
-                       for (j = 0; j < LNET_NUM_INTERFACES; j++) {
+                       for (j = 0; j < LNET_INTERFACES_NUM; j++) {
                                if (strlen(ni_data->lic_ni_intf[j]) > 0) {
                                        snprintf(str_buf,
                                                 sizeof(str_buf), "%d", j);
@@ -1777,9 +1837,54 @@ out:
        return rc;
 }
 
+int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_NO_ERR;
+       char err_str[LNET_MAX_STR_LEN];
+       char val[LNET_MAX_STR_LEN];
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+
+       snprintf(val, sizeof(val), "%d", max);
+
+       rc = write_sysfs_file(modparam_path, "lnet_interfaces_max", val,
+                             1, strlen(val) + 1);
+       if (rc)
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot configure max interfaces: %s\"",
+                        strerror(errno));
+
+       cYAML_build_error(rc, seq_no, ADD_CMD, "max_interfaces", err_str, err_rc);
+
+       return rc;
+}
+
+int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_NO_ERR;
+       char err_str[LNET_MAX_STR_LEN];
+       char val[LNET_MAX_STR_LEN];
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+
+       snprintf(val, sizeof(val), "%u", (enable) ? 0 : 1);
+
+       rc = write_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
+                             1, strlen(val) + 1);
+       if (rc)
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot configure discovery: %s\"",
+                        strerror(errno));
+
+       cYAML_build_error(rc, seq_no, ADD_CMD, "discovery", err_str, err_rc);
+
+       return rc;
+
+}
+
 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
 {
-       struct lnet_ioctl_numa_range data;
+       struct lnet_ioctl_set_value data;
        int rc = LUSTRE_CFG_RC_NO_ERR;
        char err_str[LNET_MAX_STR_LEN];
 
@@ -1793,15 +1898,15 @@ int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
                goto out;
        }
 
-       LIBCFS_IOC_INIT_V2(data, nr_hdr);
-       data.nr_range = range;
+       LIBCFS_IOC_INIT_V2(data, sv_hdr);
+       data.sv_value = range;
 
        rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_SET_NUMA_RANGE, &data);
        if (rc != 0) {
                rc = -errno;
                snprintf(err_str,
                         sizeof(err_str),
-                        "\"cannot configure buffers: %s\"", strerror(errno));
+                        "\"cannot configure numa_range: %s\"", strerror(errno));
                goto out;
        }
 
@@ -2012,22 +2117,23 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
        struct lnet_ioctl_peer_cfg peer_info;
        struct lnet_peer_ni_credit_info *lpni_cri;
        struct lnet_ioctl_element_stats *lpni_stats;
-       int rc = LUSTRE_CFG_RC_OUT_OF_MEM, ncpt = 0, i = 0, j = 0;
+       lnet_nid_t *nidp;
+       int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+       int i;
+       int j;
        int l_errno = 0;
+       __u32 count;
+       __u32 size;
        struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
                     *first_seq = NULL, *peer_root = NULL, *tmp = NULL;
        char err_str[LNET_MAX_STR_LEN];
-       lnet_nid_t prev_primary_nid = LNET_NID_ANY, primary_nid = LNET_NID_ANY;
-       int data_size = sizeof(*lpni_cri) + sizeof(*lpni_stats);
-       char *data = malloc(data_size);
-       bool new_peer = true;
+       lnet_process_id_t *list = NULL;
+       void *data = NULL;
+       void *lpni_data;
 
        snprintf(err_str, sizeof(err_str),
                 "\"out of memory\"");
 
-       if (data == NULL)
-               goto out;
-
        /* create struct cYAML root object */
        root = cYAML_create_object(NULL, NULL);
        if (root == NULL)
@@ -2037,69 +2143,121 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
        if (peer_root == NULL)
                goto out;
 
-       if (knid != NULL)
-               primary_nid = libcfs_str2nid(knid);
-
-       do {
-               for (i = 0;; i++) {
-                       memset(data, 0, data_size);
+       count = 1000;
+       size = count * sizeof(lnet_process_id_t);
+       list = malloc(size);
+       if (list == NULL) {
+               l_errno = ENOMEM;
+               goto out;
+       }
+       if (knid != NULL) {
+               list[0].nid = libcfs_str2nid(knid);
+               count = 1;
+       } else {
+               for (;;) {
                        memset(&peer_info, 0, sizeof(peer_info));
                        LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
                        peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
-                       peer_info.prcfg_count = i;
-                       peer_info.prcfg_bulk = (void *)data;
-                       peer_info.prcfg_size = data_size;
-
-                       rc = l_ioctl(LNET_DEV_ID,
-                                    IOC_LIBCFS_GET_PEER_NI, &peer_info);
-                       if (rc != 0) {
-                               l_errno = errno;
+                       peer_info.prcfg_size = size;
+                       peer_info.prcfg_bulk = list;
+
+                       l_errno = 0;
+                       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST,
+                                    &peer_info);
+                       count = peer_info.prcfg_count;
+                       if (rc == 0)
                                break;
+                       l_errno = errno;
+                       if (l_errno != E2BIG) {
+                               snprintf(err_str,
+                                       sizeof(err_str),
+                                       "\"cannot get peer list: %s\"",
+                                       strerror(l_errno));
+                               rc = -l_errno;
+                               goto out;
+                       }
+                       free(list);
+                       size = peer_info.prcfg_size;
+                       list = malloc(size);
+                       if (list == NULL) {
+                               l_errno = ENOMEM;
+                               goto out;
                        }
+               }
+       }
 
-                       if (primary_nid != LNET_NID_ANY &&
-                           primary_nid != peer_info.prcfg_prim_nid)
-                                       continue;
+       size = 4096;
+       data = malloc(size);
+       if (data == NULL) {
+               l_errno = ENOMEM;
+               goto out;
+       }
+       for (i = 0; i < count; i++) {
+               for (;;) {
+                       memset(&peer_info, 0, sizeof(peer_info));
+                       LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
+                       peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
+                       peer_info.prcfg_prim_nid = list[i].nid;
+                       peer_info.prcfg_size = size;
+                       peer_info.prcfg_bulk = data;
+
+                       l_errno = 0;
+                       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_NI,
+                                    &peer_info);
+                       if (rc == 0)
+                               break;
+                       l_errno = errno;
+                       if (l_errno != E2BIG) {
+                               snprintf(err_str,
+                                       sizeof(err_str),
+                                       "\"cannot get peer information: %s\"",
+                                       strerror(l_errno));
+                               rc = -l_errno;
+                               goto out;
+                       }
+                       free(data);
+                       size = peer_info.prcfg_size;
+                       data = malloc(size);
+                       if (data == NULL) {
+                               l_errno = ENOMEM;
+                               goto out;
+                       }
+               }
 
-                       lpni_cri = peer_info.prcfg_bulk;
-                       lpni_stats = peer_info.prcfg_bulk + sizeof(*lpni_cri);
+               peer = cYAML_create_seq_item(peer_root);
+               if (peer == NULL)
+                       goto out;
 
-                       peer = cYAML_create_seq_item(peer_root);
-                       if (peer == NULL)
-                               goto out;
+               if (first_seq == NULL)
+                       first_seq = peer;
 
-                       if (peer_info.prcfg_prim_nid != prev_primary_nid) {
-                               prev_primary_nid = peer_info.prcfg_prim_nid;
-                               new_peer = true;
-                       }
+               lnet_nid_t pnid = peer_info.prcfg_prim_nid;
+               if (cYAML_create_string(peer, "primary nid",
+                                       libcfs_nid2str(pnid))
+                   == NULL)
+                       goto out;
+               if (cYAML_create_string(peer, "Multi-Rail",
+                                       peer_info.prcfg_mr ? "True" : "False")
+                   == NULL)
+                       goto out;
 
-                       if (new_peer) {
-                               lnet_nid_t pnid = peer_info.prcfg_prim_nid;
-                               if (cYAML_create_string(peer, "primary nid",
-                                                       libcfs_nid2str(pnid))
-                                   == NULL)
-                                       goto out;
-                               if (cYAML_create_string(peer, "Multi-Rail",
-                                                       peer_info.prcfg_mr ?
-                                                       "True" : "False")
-                                   == NULL)
-                                       goto out;
-                               tmp = cYAML_create_seq(peer, "peer ni");
-                               if (tmp == NULL)
-                                       goto out;
-                               new_peer = false;
-                       }
+               tmp = cYAML_create_seq(peer, "peer ni");
+               if (tmp == NULL)
+                       goto out;
 
-                       if (first_seq == NULL)
-                               first_seq = peer;
+               lpni_data = data;
+               for (j = 0; j < peer_info.prcfg_count; j++) {
+                       nidp = lpni_data;
+                       lpni_cri = (void*)nidp + sizeof(nidp);
+                       lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
+                       lpni_data = (void *)lpni_stats + sizeof(*lpni_stats);
 
                        peer_ni = cYAML_create_seq_item(tmp);
                        if (peer_ni == NULL)
                                goto out;
 
                        if (cYAML_create_string(peer_ni, "nid",
-                                               libcfs_nid2str
-                                                (peer_info.prcfg_cfg_nid))
+                                               libcfs_nid2str(*nidp))
                            == NULL)
                                goto out;
 
@@ -2160,18 +2318,118 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                                                lpni_cri->cr_refcount) == NULL)
                                goto out;
                }
+       }
+
+       /* print output iff show_rc is not provided */
+       if (show_rc == NULL)
+               cYAML_print_tree(root);
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+       rc = LUSTRE_CFG_RC_NO_ERR;
+
+out:
+       free(list);
+       free(data);
+       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_free_tree(root);
+       } else if (show_rc != NULL && *show_rc != NULL) {
+               struct cYAML *show_node;
+               /* find the peer node, if one doesn't exist then
+                * insert one.  Otherwise add to the one there
+                */
+               show_node = cYAML_get_object_item(*show_rc,
+                                                 "peer");
+               if (show_node != NULL && cYAML_is_sequence(show_node)) {
+                       cYAML_insert_child(show_node, first_seq);
+                       free(peer_root);
+                       free(root);
+               } else if (show_node == NULL) {
+                       cYAML_insert_sibling((*show_rc)->cy_child,
+                                            peer_root);
+                       free(root);
+               } else {
+                       cYAML_free_tree(root);
+               }
+       } else {
+               *show_rc = root;
+       }
+
+       cYAML_build_error(rc, seq_no, SHOW_CMD, "peer", err_str,
+                         err_rc);
+
+       return rc;
+}
+
+int lustre_lnet_list_peer(int seq_no,
+                         struct cYAML **show_rc, struct cYAML **err_rc)
+{
+       struct lnet_ioctl_peer_cfg peer_info;
+       int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+       __u32 count;
+       __u32 size;
+       int i = 0;
+       int l_errno = 0;
+       struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
+       char err_str[LNET_MAX_STR_LEN];
+       lnet_process_id_t *list = NULL;
+
+       snprintf(err_str, sizeof(err_str),
+                "\"out of memory\"");
+
+       memset(&peer_info, 0, sizeof(peer_info));
 
-               if (l_errno != ENOENT) {
+       /* create struct cYAML root object */
+       root = cYAML_create_object(NULL, NULL);
+       if (root == NULL)
+               goto out;
+
+       list_root = cYAML_create_seq(root, "peer list");
+       if (list_root == NULL)
+               goto out;
+
+       count = 1000;
+       size = count * sizeof(lnet_process_id_t);
+       list = malloc(size);
+       if (list == NULL) {
+               l_errno = ENOMEM;
+               goto out;
+       }
+       for (;;) {
+               LIBCFS_IOC_INIT_V2(peer_info, prcfg_hdr);
+               peer_info.prcfg_hdr.ioc_len = sizeof(peer_info);
+               peer_info.prcfg_size = size;
+               peer_info.prcfg_bulk = list;
+
+               l_errno = 0;
+               rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER_LIST, &peer_info);
+               count = peer_info.prcfg_count;
+               if (rc == 0)
+                       break;
+               l_errno = errno;
+               if (l_errno != E2BIG) {
                        snprintf(err_str,
                                sizeof(err_str),
-                               "\"cannot get peer information: %s\"",
+                               "\"cannot get peer list: %s\"",
                                strerror(l_errno));
                        rc = -l_errno;
                        goto out;
                }
+               free(list);
+               size = peer_info.prcfg_size;
+               list = malloc(size);
+               if (list == NULL) {
+                       l_errno = ENOMEM;
+                       goto out;
+               }
+       }
 
-               j++;
-       } while (j < ncpt);
+       /* count is now the actual number of ids in the list. */
+       for (i = 0; i < count; i++) {
+               if (cYAML_create_string(list_root, "nid",
+                                       libcfs_nid2str(list[i].nid))
+                   == NULL)
+                       goto out;
+       }
 
        /* print output iff show_rc is not provided */
        if (show_rc == NULL)
@@ -2181,6 +2439,8 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
        rc = LUSTRE_CFG_RC_NO_ERR;
 
 out:
+       if (list != NULL)
+               free(list);
        if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_free_tree(root);
        } else if (show_rc != NULL && *show_rc != NULL) {
@@ -2192,11 +2452,11 @@ out:
                                                  "peer");
                if (show_node != NULL && cYAML_is_sequence(show_node)) {
                        cYAML_insert_child(show_node, first_seq);
-                       free(peer_root);
+                       free(list_root);
                        free(root);
                } else if (show_node == NULL) {
                        cYAML_insert_sibling((*show_rc)->cy_child,
-                                            peer_root);
+                                            list_root);
                        free(root);
                } else {
                        cYAML_free_tree(root);
@@ -2211,18 +2471,138 @@ out:
        return rc;
 }
 
+static void add_to_global(struct cYAML *show_rc, struct cYAML *node,
+                         struct cYAML *root)
+{
+       struct cYAML *show_node;
+
+       show_node = cYAML_get_object_item(show_rc, "global");
+       if (show_node != NULL)
+               cYAML_insert_sibling(show_node->cy_child,
+                                    node->cy_child);
+       else
+               cYAML_insert_sibling(show_rc->cy_child,
+                                    node);
+       free(root);
+}
+
+int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
+                             struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+       char val[LNET_MAX_STR_LEN];
+       int max_intf;
+       char err_str[LNET_MAX_STR_LEN];
+       struct cYAML *root = NULL, *global = NULL;
+
+       snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+       rc = read_sysfs_file(modparam_path, "lnet_interfaces_max", val,
+                            1, LNET_MAX_STR_LEN);
+       if (rc) {
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot get max interfaces: %d\"", rc);
+               goto out;
+       }
+
+       max_intf = atoi(val);
+
+       root = cYAML_create_object(NULL, NULL);
+       if (root == NULL)
+               goto out;
+
+       global = cYAML_create_object(root, "global");
+       if (global == NULL)
+               goto out;
+
+       if (cYAML_create_number(global, "max_intf",
+                               max_intf) == NULL)
+               goto out;
+
+       if (show_rc == NULL)
+               cYAML_print_tree(root);
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+out:
+       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_free_tree(root);
+       else if (show_rc != NULL && *show_rc != NULL)
+               add_to_global(*show_rc, global, root);
+       else
+               *show_rc = root;
+
+       cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
+
+       return rc;
+}
+
+int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
+                              struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+       char val[LNET_MAX_STR_LEN];
+       __u32 discovery;
+       char err_str[LNET_MAX_STR_LEN];
+       struct cYAML *root = NULL, *global = NULL;
+
+       snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+       rc = read_sysfs_file(modparam_path, "lnet_peer_discovery_disabled", val,
+                            1, sizeof(val));
+       if (rc) {
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot get discovery value: %d\"", rc);
+               goto out;
+       }
+
+       /*
+        * the sysfs parameter read indicates if discovery is disabled,
+        * but we report if discovery is enabled.
+        */
+       discovery = !atoi(val);
+
+       root = cYAML_create_object(NULL, NULL);
+       if (root == NULL)
+               goto out;
+
+       global = cYAML_create_object(root, "global");
+       if (global == NULL)
+               goto out;
+
+       if (cYAML_create_number(global, "discovery",
+                               discovery) == NULL)
+               goto out;
+
+       if (show_rc == NULL)
+               cYAML_print_tree(root);
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+out:
+       if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_free_tree(root);
+       } else if (show_rc != NULL && *show_rc != NULL) {
+               add_to_global(*show_rc, global, root);
+       } else {
+               *show_rc = root;
+       }
+
+       cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
+
+       return rc;
+}
+
 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
                                struct cYAML **err_rc)
 {
-       struct lnet_ioctl_numa_range data;
+       struct lnet_ioctl_set_value data;
        int rc;
        int l_errno;
        char err_str[LNET_MAX_STR_LEN];
-       struct cYAML *root = NULL, *range = NULL;
+       struct cYAML *root = NULL, *global = NULL;
 
        snprintf(err_str, sizeof(err_str), "\"out of memory\"");
 
-       LIBCFS_IOC_INIT_V2(data, nr_hdr);
+       LIBCFS_IOC_INIT_V2(data, sv_hdr);
 
        rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NUMA_RANGE, &data);
        if (rc != 0) {
@@ -2241,12 +2621,12 @@ int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
        if (root == NULL)
                goto out;
 
-       range = cYAML_create_object(root, "numa");
-       if (range == NULL)
+       global = cYAML_create_object(root, "global");
+       if (global == NULL)
                goto out;
 
-       if (cYAML_create_number(range, "range",
-                               data.nr_range) == NULL)
+       if (cYAML_create_number(global, "numa_range",
+                               data.sv_value) == NULL)
                goto out;
 
        if (show_rc == NULL)
@@ -2258,14 +2638,12 @@ out:
        if (show_rc == NULL || rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_free_tree(root);
        } else if (show_rc != NULL && *show_rc != NULL) {
-               cYAML_insert_sibling((*show_rc)->cy_child,
-                                       root->cy_child);
-               free(root);
+               add_to_global(*show_rc, global, root);
        } else {
                *show_rc = root;
        }
 
-       cYAML_build_error(rc, seq_no, SHOW_CMD, "numa", err_str, err_rc);
+       cYAML_build_error(rc, seq_no, SHOW_CMD, "global", err_str, err_rc);
 
        return rc;
 }
@@ -3029,39 +3407,98 @@ static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
                                      show_rc, err_rc);
 }
 
-static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
-                                 struct cYAML **err_rc)
+static int handle_yaml_config_global_settings(struct cYAML *tree,
+                                             struct cYAML **show_rc,
+                                             struct cYAML **err_rc)
 {
-       struct cYAML *seq_no, *range;
+       struct cYAML *max_intf, *numa, *discovery, *seq_no;
+       int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
-       range = cYAML_get_object_item(tree, "range");
+       max_intf = cYAML_get_object_item(tree, "max_intf");
+       if (max_intf)
+               rc = lustre_lnet_config_max_intf(max_intf->cy_valueint,
+                                                seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                err_rc);
+
+       numa = cYAML_get_object_item(tree, "numa_range");
+       if (numa)
+               rc = lustre_lnet_config_numa_range(numa->cy_valueint,
+                                                  seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                  err_rc);
+
+       discovery = cYAML_get_object_item(tree, "discovery");
+       if (discovery)
+               rc = lustre_lnet_config_discovery(discovery->cy_valueint,
+                                                 seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                 err_rc);
 
-       return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
-                                            seq_no ? seq_no->cy_valueint : -1,
-                                            err_rc);
+       return rc;
 }
 
-static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
-                              struct cYAML **err_rc)
+static int handle_yaml_del_global_settings(struct cYAML *tree,
+                                          struct cYAML **show_rc,
+                                          struct cYAML **err_rc)
 {
-       struct cYAML *seq_no;
+       struct cYAML *max_intf, *numa, *discovery, *seq_no;
+       int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
+       max_intf = cYAML_get_object_item(tree, "max_intf");
+       if (max_intf)
+               rc = lustre_lnet_config_max_intf(LNET_INTERFACES_MAX_DEFAULT,
+                                                seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                err_rc);
+
+       numa = cYAML_get_object_item(tree, "numa_range");
+       if (numa)
+               rc = lustre_lnet_config_numa_range(0,
+                                                  seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                  err_rc);
+
+       /* peer discovery is enabled by default */
+       discovery = cYAML_get_object_item(tree, "discovery");
+       if (discovery)
+               rc = lustre_lnet_config_discovery(1,
+                                                 seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                 err_rc);
 
-       return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
-                                            err_rc);
+       return rc;
 }
 
-static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
-                               struct cYAML **err_rc)
+static int handle_yaml_show_global_settings(struct cYAML *tree,
+                                           struct cYAML **show_rc,
+                                           struct cYAML **err_rc)
 {
-       struct cYAML *seq_no;
+       struct cYAML *max_intf, *numa, *discovery, *seq_no;
+       int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
+       max_intf = cYAML_get_object_item(tree, "max_intf");
+       if (max_intf)
+               rc = lustre_lnet_show_max_intf(seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                               show_rc, err_rc);
+
+       numa = cYAML_get_object_item(tree, "numa_range");
+       if (numa)
+               rc = lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                                show_rc, err_rc);
+
+       discovery = cYAML_get_object_item(tree, "discovery");
+       if (discovery)
+               rc = lustre_lnet_show_discovery(seq_no ? seq_no->cy_valueint
+                                                       : -1,
+                                               show_rc, err_rc);
 
-       return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
-                                          show_rc, err_rc);
+       return rc;
 }
 
 struct lookup_cmd_hdlr_tbl {
@@ -3076,7 +3513,7 @@ static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
        { .name = "peer",       .cb = handle_yaml_config_peer },
        { .name = "routing",    .cb = handle_yaml_config_routing },
        { .name = "buffers",    .cb = handle_yaml_config_buffers },
-       { .name = "numa",       .cb = handle_yaml_config_numa },
+       { .name = "global",     .cb = handle_yaml_config_global_settings},
        { .name = NULL } };
 
 static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
@@ -3084,7 +3521,7 @@ static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
        { .name = "net",        .cb = handle_yaml_del_ni },
        { .name = "peer",       .cb = handle_yaml_del_peer },
        { .name = "routing",    .cb = handle_yaml_del_routing },
-       { .name = "numa",       .cb = handle_yaml_del_numa },
+       { .name = "global",     .cb = handle_yaml_del_global_settings},
        { .name = NULL } };
 
 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
@@ -3094,7 +3531,7 @@ static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
        { .name = "routing",    .cb = handle_yaml_show_routing },
        { .name = "peer",       .cb = handle_yaml_show_peers },
        { .name = "statistics", .cb = handle_yaml_show_stats },
-       { .name = "numa",       .cb = handle_yaml_show_numa },
+       { .name = "global",     .cb = handle_yaml_show_global_settings},
        { .name = NULL } };
 
 static cmd_handler_t lookup_fn(char *key,