Whamcloud - gitweb
LU-7101 lnet: per NI map-on-demand value
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig.c
index da7fe62..e2ef2b6 100644 (file)
@@ -43,7 +43,7 @@
 #include <libcfs/util/ioctl.h>
 #include <lnet/lnetctl.h>
 #include <lnet/socklnd.h>
-#include <lnet/lnet.h>
+#include "liblnd.h"
 #include "liblnetconfig.h"
 #include "cyaml.h"
 
@@ -443,15 +443,22 @@ out:
 int lustre_lnet_config_net(char *net, char *intf, char *ip2net,
                           int peer_to, int peer_cr, int peer_buf_cr,
                           int credits, char *smp, int seq_no,
+                          struct lnet_ioctl_config_lnd_tunables *lnd_tunables,
                           struct cYAML **err_rc)
 {
-       struct lnet_ioctl_config_data data;
+       struct lnet_ioctl_config_lnd_tunables *lnd = NULL;
+       struct lnet_ioctl_config_data *data;
+       size_t ioctl_size = sizeof(*data);
        char buf[LNET_MAX_STR_LEN];
        int rc = LUSTRE_CFG_RC_NO_ERR;
        char err_str[LNET_MAX_STR_LEN];
 
        snprintf(err_str, sizeof(err_str), "\"success\"");
 
+       /* No need to register lo */
+       if (net != NULL && !strcmp(net, "lo"))
+               return 0;
+
        if (ip2net == NULL && (intf == NULL || net == NULL)) {
                snprintf(err_str,
                         sizeof(err_str),
@@ -481,26 +488,41 @@ int lustre_lnet_config_net(char *net, char *intf, char *ip2net,
                goto out;
        }
 
+       if (lnd_tunables != NULL)
+               ioctl_size += sizeof(*lnd_tunables);
+
+       data = calloc(1, ioctl_size);
+       if (data == NULL)
+               goto out;
+
        if (ip2net == NULL)
                snprintf(buf, sizeof(buf) - 1, "%s(%s)%s",
                        net, intf,
                        (smp) ? smp : "");
 
-       LIBCFS_IOC_INIT_V2(data, cfg_hdr);
-       strncpy(data.cfg_config_u.cfg_net.net_intf,
+       LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
+       strncpy(data->cfg_config_u.cfg_net.net_intf,
                (ip2net != NULL) ? ip2net : buf, sizeof(buf));
-       data.cfg_config_u.cfg_net.net_peer_timeout = peer_to;
-       data.cfg_config_u.cfg_net.net_peer_tx_credits = peer_cr;
-       data.cfg_config_u.cfg_net.net_peer_rtr_credits = peer_buf_cr;
-       data.cfg_config_u.cfg_net.net_max_tx_credits = credits;
+       data->cfg_config_u.cfg_net.net_peer_timeout = peer_to;
+       data->cfg_config_u.cfg_net.net_peer_tx_credits = peer_cr;
+       data->cfg_config_u.cfg_net.net_peer_rtr_credits = peer_buf_cr;
+       data->cfg_config_u.cfg_net.net_max_tx_credits = credits;
+       /* Add in tunable settings if available */
+       if (lnd_tunables != NULL) {
+               lnd = (struct lnet_ioctl_config_lnd_tunables *)data->cfg_bulk;
+
+               data->cfg_hdr.ioc_len = ioctl_size;
+               memcpy(lnd, lnd_tunables, sizeof(*lnd_tunables));
+       }
 
-       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_NET, &data);
+       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_NET, data);
        if (rc < 0) {
                rc = -errno;
                snprintf(err_str,
                         sizeof(err_str),
                         "\"cannot add network: %s\"", strerror(errno));
        }
+       free(data);
 
 out:
        cYAML_build_error(rc, seq_no, ADD_CMD, "net", err_str, err_rc);
@@ -556,23 +578,25 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                         struct cYAML **show_rc, struct cYAML **err_rc)
 {
        char *buf;
+       struct lnet_ioctl_config_lnd_tunables *lnd_cfg;
        struct lnet_ioctl_config_data *data;
        struct lnet_ioctl_net_config *net_config;
        __u32 net = LNET_NIDNET(LNET_NID_ANY);
        int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
        int l_errno = 0;
-       struct cYAML *root = NULL, *tunables = NULL,
-               *net_node = NULL, *interfaces = NULL,
-               *item = NULL, *first_seq = NULL;
+       struct cYAML *root = NULL, *tunables = NULL, *net_node = NULL,
+               *interfaces = NULL, *item = NULL, *first_seq = NULL;
        int str_buf_len = LNET_MAX_SHOW_NUM_CPT * 2;
        char str_buf[str_buf_len];
        char *pos;
        char err_str[LNET_MAX_STR_LEN];
        bool exist = false;
+       size_t buf_len;
 
        snprintf(err_str, sizeof(err_str), "\"out of memory\"");
 
-       buf = calloc(1, sizeof(*data) + sizeof(*net_config));
+       buf_len = sizeof(*data) + sizeof(*net_config) + sizeof(*lnd_cfg);
+       buf = calloc(1, buf_len);
        if (buf == NULL)
                goto out;
 
@@ -600,15 +624,14 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
        for (i = 0;; i++) {
                pos = str_buf;
 
-               memset(buf, 0, sizeof(*data) + sizeof(*net_config));
+               memset(buf, 0, buf_len);
 
                LIBCFS_IOC_INIT_V2(*data, cfg_hdr);
                /*
                 * set the ioc_len to the proper value since INIT assumes
                 * size of data
                 */
-               data->cfg_hdr.ioc_len = sizeof(struct lnet_ioctl_config_data) +
-                 sizeof(struct lnet_ioctl_net_config);
+               data->cfg_hdr.ioc_len = buf_len;
                data->cfg_count = i;
 
                rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NET, data);
@@ -636,8 +659,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                if (first_seq == NULL)
                        first_seq = item;
 
-               if (cYAML_create_string(item,
-                                       "net",
+               if (cYAML_create_string(item, "net",
                                        libcfs_net2str(
                                                LNET_NIDNET(data->cfg_nid)))
                    == NULL)
@@ -647,8 +669,7 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                                        libcfs_nid2str(data->cfg_nid)) == NULL)
                        goto out;
 
-               if (cYAML_create_string(item,
-                                       "status",
+               if (cYAML_create_string(item, "status",
                                        (net_config->ni_status ==
                                          LNET_NI_STATUS_UP) ?
                                            "up" : "down") == NULL)
@@ -662,15 +683,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                                goto out;
 
                        for (j = 0; j < LNET_MAX_INTERFACES; j++) {
-                               if (strlen(net_config->ni_interfaces[j]) > 0) {
-                                       snprintf(str_buf,
-                                                sizeof(str_buf), "%d", j);
-                                       if (cYAML_create_string(interfaces,
-                                               str_buf,
-                                               net_config->ni_interfaces[j]) ==
-                                           NULL)
-                                               goto out;
-                               }
+                               if (lustre_interface_show_net(interfaces, j,
+                                                             detail, data,
+                                                             net_config) < 0)
+                                       goto out;
                        }
                }
 
@@ -683,23 +699,23 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
 
                        if (cYAML_create_number(tunables, "peer_timeout",
                                                data->cfg_config_u.cfg_net.
-                                                net_peer_timeout) == NULL)
+                                               net_peer_timeout) == NULL)
                                goto out;
 
                        if (cYAML_create_number(tunables, "peer_credits",
                                                data->cfg_config_u.cfg_net.
-                                                 net_peer_tx_credits) == NULL)
+                                               net_peer_tx_credits) == NULL)
                                goto out;
 
                        if (cYAML_create_number(tunables,
                                                "peer_buffer_credits",
                                                data->cfg_config_u.cfg_net.
-                                                 net_peer_rtr_credits) == NULL)
+                                               net_peer_rtr_credits) == NULL)
                                goto out;
 
                        if (cYAML_create_number(tunables, "credits",
                                                data->cfg_config_u.cfg_net.
-                                                 net_max_tx_credits) == NULL)
+                                               net_max_tx_credits) == NULL)
                                goto out;
 
                        /* out put the CPTs in the format: "[x,x,x,...]" */
@@ -1263,6 +1279,8 @@ static int handle_yaml_config_net(struct cYAML *tree, struct cYAML **show_rc,
        struct cYAML *net, *intf, *tunables, *seq_no,
              *peer_to = NULL, *peer_buf_cr = NULL, *peer_cr = NULL,
              *credits = NULL, *ip2net = NULL, *smp = NULL, *child;
+       struct lnet_ioctl_config_lnd_tunables *lnd_tunables_p = NULL;
+       struct lnet_ioctl_config_lnd_tunables lnd_tunables;
        char devs[LNET_MAX_STR_LEN];
        char *loc = devs;
        int size = LNET_MAX_STR_LEN;
@@ -1276,6 +1294,11 @@ static int handle_yaml_config_net(struct cYAML *tree, struct cYAML **show_rc,
                /* grab all the interfaces */
                child = intf->cy_child;
                while (child != NULL && size > 0) {
+                       struct cYAML *lnd_params;
+
+                       if (child->cy_valuestring == NULL)
+                               goto ignore_child;
+
                        if (loc > devs)
                                num  = snprintf(loc, size, ",%s",
                                                child->cy_valuestring);
@@ -1285,6 +1308,17 @@ static int handle_yaml_config_net(struct cYAML *tree, struct cYAML **show_rc,
                        size -= num;
                        loc += num;
                        intf_found = true;
+
+                       lnd_params = cYAML_get_object_item(intf,
+                                                          "lnd tunables");
+                       if (lnd_params != NULL) {
+                               const char *dev_name = child->cy_valuestring;
+                               lnd_tunables_p = &lnd_tunables;
+
+                               lustre_interface_parse(lnd_params, dev_name,
+                                                      lnd_tunables_p);
+                       }
+ignore_child:
                        child = child->cy_next;
                }
        }
@@ -1310,6 +1344,7 @@ static int handle_yaml_config_net(struct cYAML *tree, struct cYAML **show_rc,
                                      (credits) ? credits->cy_valueint : -1,
                                      (smp) ? smp->cy_valuestring : NULL,
                                      (seq_no) ? seq_no->cy_valueint : -1,
+                                     lnd_tunables_p,
                                      err_rc);
 }