Whamcloud - gitweb
LU-6002 lnet: startup acceptor thread dynamically
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 0d1e7ec..75ff383 100644 (file)
@@ -68,7 +68,6 @@ static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
 CFS_MODULE_PARM(rnet_htable_size, "i", int, 0444,
                "size of remote network hash table");
 
-static void lnet_ping_target_fini(void);
 static int lnet_ping(lnet_process_id_t id, int timeout_ms,
                     lnet_process_id_t *ids, int n_ids);
 
@@ -1108,7 +1107,7 @@ lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle,
 {
        lnet_handle_me_t  me_handle;
        lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY};
-       lnet_md_t         md = {0};
+       lnet_md_t         md = {NULL};
        int               rc, rc2;
 
        if (set_eq) {
@@ -2021,6 +2020,16 @@ lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
        if (rc != 0)
                goto failed1;
 
+       if (ni->ni_lnd->lnd_accept != NULL) {
+               rc = lnet_acceptor_start();
+               if (rc < 0) {
+                       /* shutdown the ni that we just started */
+                       CERROR("Failed to start up acceptor thread\n");
+                       lnet_shutdown_lndni(ni);
+                       goto failed1;
+               }
+       }
+
        lnet_ping_target_update(pinfo, md_handle);
        LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
 
@@ -2068,6 +2077,10 @@ lnet_dyn_del_ni(__u32 net)
        lnet_ni_decref_locked(ni, 0);
 
        lnet_shutdown_lndni(ni);
+
+       if (lnet_count_acceptor_nis() == 0)
+               lnet_acceptor_stop();
+
        lnet_ping_target_update(pinfo, md_handle);
        goto out;
 failed:
@@ -2116,6 +2129,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_ADD_ROUTE:
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < sizeof(*config))
+                       return -EINVAL;
+
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
                rc = lnet_add_route(config->cfg_net,
                                    config->cfg_config_u.cfg_route.rtr_hop,
@@ -2127,6 +2144,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_DEL_ROUTE:
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < sizeof(*config))
+                       return -EINVAL;
+
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
                rc = lnet_del_route(config->cfg_net, config->cfg_nid);
                LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
@@ -2134,6 +2155,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_GET_ROUTE:
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < sizeof(*config))
+                       return -EINVAL;
+
                return lnet_get_route(config->cfg_count,
                                      &config->cfg_net,
                                      &config->cfg_config_u.cfg_route.rtr_hop,
@@ -2144,7 +2169,13 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_GET_NET: {
                struct lnet_ioctl_net_config *net_config;
+               size_t total = sizeof(*config) + sizeof(*net_config);
+
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < total)
+                       return -EINVAL;
+
                net_config = (struct lnet_ioctl_net_config *)
                        config->cfg_bulk;
                if (config == NULL || net_config == NULL)
@@ -2168,6 +2199,9 @@ LNetCtl(unsigned int cmd, void *arg)
        {
                struct lnet_ioctl_lnet_stats *lnet_stats = arg;
 
+               if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
+                       return -EINVAL;
+
                lnet_counters_get(&lnet_stats->st_cntrs);
                return 0;
        }
@@ -2175,6 +2209,10 @@ LNetCtl(unsigned int cmd, void *arg)
 #if defined(__KERNEL__) && defined(LNET_ROUTER)
        case IOC_LIBCFS_CONFIG_RTR:
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < sizeof(*config))
+                       return -EINVAL;
+
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
                if (config->cfg_config_u.cfg_buffers.buf_enable) {
                        rc = lnet_rtrpools_enable();
@@ -2187,6 +2225,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_ADD_BUF:
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < sizeof(*config))
+                       return -EINVAL;
+
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
                rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
                                                buf_tiny,
@@ -2200,13 +2242,23 @@ LNetCtl(unsigned int cmd, void *arg)
 
        case IOC_LIBCFS_GET_BUF: {
                struct lnet_ioctl_pool_cfg *pool_cfg;
+               size_t total = sizeof(*config) + sizeof(*pool_cfg);
+
                config = arg;
+
+               if (config->cfg_hdr.ioc_len < total)
+                       return -EINVAL;
+
                pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
                return lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
        }
 
        case IOC_LIBCFS_GET_PEER_INFO: {
                struct lnet_ioctl_peer *peer_info = arg;
+
+               if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
+                       return -EINVAL;
+
                return lnet_get_peer_info(
                   peer_info->pr_count,
                   &peer_info->pr_nid,
@@ -2357,7 +2409,7 @@ lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
        lnet_handle_eq_t     eqh;
        lnet_handle_md_t     mdh;
        lnet_event_t         event;
-       lnet_md_t            md = {0};
+       lnet_md_t            md = { NULL };
        int                  which;
        int                  unlinked = 0;
        int                  replied = 0;