Whamcloud - gitweb
Revert "LU-5568 lnet: fix kernel crash when network failed to start"
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 58a4aa1..7fc2158 100644 (file)
@@ -36,6 +36,7 @@
 
 #define DEBUG_SUBSYSTEM S_LNET
 #include <lnet/lib-lnet.h>
+#include <lnet/lib-dlc.h>
 #ifdef __KERNEL__
 #include <linux/log2.h>
 #endif
@@ -67,36 +68,40 @@ 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");
 
-char *
+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);
+
+static char *
 lnet_get_routes(void)
 {
         return routes;
 }
 
-char *
+static char *
 lnet_get_networks(void)
 {
-        char   *nets;
-        int     rc;
+       char   *nets;
+       int     rc;
 
-        if (*networks != 0 && *ip2nets != 0) {
-                LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
-                                   "'ip2nets' but not both at once\n");
-                return NULL;
-        }
+       if (*networks != 0 && *ip2nets != 0) {
+               LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
+                                  "'ip2nets' but not both at once\n");
+               return NULL;
+       }
 
-        if (*ip2nets != 0) {
-                rc = lnet_parse_ip2nets(&nets, ip2nets);
-                return (rc == 0) ? nets : NULL;
-        }
+       if (*ip2nets != 0) {
+               rc = lnet_parse_ip2nets(&nets, ip2nets);
+               return (rc == 0) ? nets : NULL;
+       }
 
-        if (*networks != 0)
-                return networks;
+       if (*networks != 0)
+               return networks;
 
-        return "tcp";
+       return "tcp";
 }
 
-void
+static void
 lnet_init_locks(void)
 {
        spin_lock_init(&the_lnet.ln_eq_wait_lock);
@@ -105,14 +110,14 @@ lnet_init_locks(void)
        mutex_init(&the_lnet.ln_api_mutex);
 }
 
-void
+static void
 lnet_fini_locks(void)
 {
 }
 
 #else
 
-char *
+static char *
 lnet_get_routes(void)
 {
         char *str = getenv("LNET_ROUTES");
@@ -120,7 +125,7 @@ lnet_get_routes(void)
         return (str == NULL) ? "" : str;
 }
 
-char *
+static char *
 lnet_get_networks (void)
 {
        static char       default_networks[256];
@@ -160,14 +165,14 @@ lnet_get_networks (void)
 
 # ifndef HAVE_LIBPTHREAD
 
-void lnet_init_locks(void)
+static void lnet_init_locks(void)
 {
        the_lnet.ln_eq_wait_lock = 0;
        the_lnet.ln_lnd_mutex = 0;
        the_lnet.ln_api_mutex = 0;
 }
 
-void lnet_fini_locks(void)
+static void lnet_fini_locks(void)
 {
        LASSERT(the_lnet.ln_api_mutex == 0);
        LASSERT(the_lnet.ln_lnd_mutex == 0);
@@ -176,7 +181,7 @@ void lnet_fini_locks(void)
 
 # else
 
-void lnet_init_locks(void)
+static void lnet_init_locks(void)
 {
        pthread_cond_init(&the_lnet.ln_eq_cond, NULL);
        pthread_mutex_init(&the_lnet.ln_eq_wait_lock, NULL);
@@ -184,7 +189,7 @@ void lnet_init_locks(void)
        pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
 }
 
-void lnet_fini_locks(void)
+static void lnet_fini_locks(void)
 {
        pthread_mutex_destroy(&the_lnet.ln_api_mutex);
        pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
@@ -268,7 +273,7 @@ lnet_create_locks(void)
        return -ENOMEM;
 }
 
-void lnet_assert_wire_constants (void)
+static void lnet_assert_wire_constants(void)
 {
         /* Wire protocol assertions generated by 'wirecheck'
          * running on Linux robert.bartonsoftware.com 2.6.8-1.521
@@ -361,7 +366,7 @@ void lnet_assert_wire_constants (void)
         CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);
 }
 
-lnd_t *
+static lnd_t *
 lnet_find_lnd_by_type (int type)
 {
        lnd_t            *lnd;
@@ -503,7 +508,7 @@ lnet_freelist_fini(lnet_freelist_t *fl)
 
 #endif /* LNET_USE_LIB_FREELIST */
 
-__u64 lnet_create_interface_cookie (void)
+static __u64 lnet_create_interface_cookie(void)
 {
        /* NB the interface cookie in wire handles guards against delayed
         * replies and ACKs appearing valid after reboot. Initialisation time,
@@ -538,7 +543,7 @@ lnet_res_type2str(int type)
        }
 }
 
-void
+static void
 lnet_res_container_cleanup(struct lnet_res_container *rec)
 {
        int     count = 0;
@@ -582,7 +587,7 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
        rec->rec_type = 0; /* mark it as finalized */
 }
 
-int
+static int
 lnet_res_container_setup(struct lnet_res_container *rec,
                         int cpt, int type, int objnum, int objsz)
 {
@@ -710,9 +715,9 @@ lnet_server_mode() {
 }
 #endif
 
-int lnet_unprepare(void);
+static int lnet_unprepare(void);
 
-int
+static int
 lnet_prepare(lnet_pid_t requested_pid)
 {
        /* Prepare to bring up the network */
@@ -807,7 +812,7 @@ lnet_prepare(lnet_pid_t requested_pid)
        return rc;
 }
 
-int
+static int
 lnet_unprepare (void)
 {
        /* NB no LNET_LOCK since this is the last reference.  All LND instances
@@ -1761,7 +1766,6 @@ LNetNIInit(lnet_pid_t requested_pid)
        lnet_ping_info_t        *pinfo;
        lnet_handle_md_t        md_handle;
        struct list_head        net_head;
-       char                    *nets;
 
        INIT_LIST_HEAD(&net_head);
 
@@ -1776,13 +1780,13 @@ LNetNIInit(lnet_pid_t requested_pid)
                return rc;
        }
 
-       nets = lnet_get_networks();
-
        rc = lnet_prepare(requested_pid);
        if (rc != 0)
                goto failed0;
 
-       rc = lnet_parse_networks(&net_head, nets);
+       rc = lnet_parse_networks(&net_head,
+                                !the_lnet.ln_nis_from_mod_params ?
+                                  lnet_get_networks() : "");
        if (rc < 0)
                goto failed1;
 
@@ -1897,6 +1901,93 @@ LNetNIFini()
 }
 EXPORT_SYMBOL(LNetNIFini);
 
+/**
+ * Grabs the ni data from the ni structure and fills the out
+ * parameters
+ *
+ * \param[in] ni network       interface structure
+ * \param[out] cpt_count       the number of cpts the ni is on
+ * \param[out] nid             Network Interface ID
+ * \param[out] peer_timeout    NI peer timeout
+ * \param[out] peer_tx_crdits  NI peer transmit credits
+ * \param[out] peer_rtr_credits NI peer router credits
+ * \param[out] max_tx_credits  NI max transmit credit
+ * \param[out] net_config      Network configuration
+ */
+static void
+lnet_fill_ni_info(struct lnet_ni *ni, __u32 *cpt_count, __u64 *nid,
+                 int *peer_timeout, int *peer_tx_credits,
+                 int *peer_rtr_credits, int *max_tx_credits,
+                 struct lnet_ioctl_net_config *net_config)
+{
+       int i;
+
+       if (ni == NULL)
+               return;
+
+       if (net_config == NULL)
+               return;
+
+       CLASSERT(ARRAY_SIZE(ni->ni_interfaces) ==
+                ARRAY_SIZE(net_config->ni_interfaces));
+
+       if (ni->ni_interfaces[0] != NULL) {
+               for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
+                       if (ni->ni_interfaces[i] != NULL) {
+                               strncpy(net_config->ni_interfaces[i],
+                                       ni->ni_interfaces[i],
+                                       sizeof(net_config->ni_interfaces[i]));
+                       }
+               }
+       }
+
+       *nid = ni->ni_nid;
+       *peer_timeout = ni->ni_peertimeout;
+       *peer_tx_credits = ni->ni_peertxcredits;
+       *peer_rtr_credits = ni->ni_peerrtrcredits;
+       *max_tx_credits = ni->ni_maxtxcredits;
+
+       net_config->ni_status = ni->ni_status->ns_status;
+
+       for (i = 0;
+            ni->ni_cpts != NULL && i < ni->ni_ncpts &&
+            i < LNET_MAX_SHOW_NUM_CPT;
+            i++)
+               net_config->ni_cpts[i] = ni->ni_cpts[i];
+
+       *cpt_count = ni->ni_ncpts;
+}
+
+int
+lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid, int *peer_timeout,
+                   int *peer_tx_credits, int *peer_rtr_credits,
+                   int *max_tx_credits,
+                   struct lnet_ioctl_net_config *net_config)
+{
+       struct lnet_ni          *ni;
+       struct list_head        *tmp;
+       int                     cpt;
+       int                     rc = -ENOENT;
+
+       cpt = lnet_net_lock_current();
+
+       list_for_each(tmp, &the_lnet.ln_nis) {
+               ni = list_entry(tmp, lnet_ni_t, ni_list);
+               if (idx-- == 0) {
+                       rc = 0;
+                       lnet_ni_lock(ni);
+                       lnet_fill_ni_info(ni, cpt_count, nid, peer_timeout,
+                                         peer_tx_credits, peer_rtr_credits,
+                                         max_tx_credits, net_config);
+                       lnet_ni_unlock(ni);
+                       break;
+               }
+       }
+
+       lnet_net_unlock(cpt);
+       return rc;
+}
+
 int
 lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
                __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
@@ -1979,6 +2070,7 @@ int
 LNetCtl(unsigned int cmd, void *arg)
 {
        struct libcfs_ioctl_data *data = arg;
+       struct lnet_ioctl_config_data *config;
        lnet_process_id_t         id = {0};
        lnet_ni_t                *ni;
        int                       rc;
@@ -1995,23 +2087,111 @@ LNetCtl(unsigned int cmd, void *arg)
                return lnet_fail_nid(data->ioc_nid, data->ioc_count);
 
        case IOC_LIBCFS_ADD_ROUTE:
+               config = arg;
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
-               rc = lnet_add_route(data->ioc_net, data->ioc_count,
-                                   data->ioc_nid, data->ioc_priority);
+               rc = lnet_add_route(config->cfg_net,
+                                   config->cfg_config_u.cfg_route.rtr_hop,
+                                   config->cfg_nid,
+                                   config->cfg_config_u.cfg_route.
+                                       rtr_priority);
                LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
                return (rc != 0) ? rc : lnet_check_routes();
 
        case IOC_LIBCFS_DEL_ROUTE:
+               config = arg;
                LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
-               rc = lnet_del_route(data->ioc_net, data->ioc_nid);
+               rc = lnet_del_route(config->cfg_net, config->cfg_nid);
                LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
                return rc;
 
        case IOC_LIBCFS_GET_ROUTE:
-               return lnet_get_route(data->ioc_count,
-                                     &data->ioc_net, &data->ioc_count,
-                                     &data->ioc_nid, &data->ioc_flags,
-                                     &data->ioc_priority);
+               config = arg;
+               return lnet_get_route(config->cfg_count,
+                                     &config->cfg_net,
+                                     &config->cfg_config_u.cfg_route.rtr_hop,
+                                     &config->cfg_nid,
+                                     &config->cfg_config_u.cfg_route.rtr_flags,
+                                     &config->cfg_config_u.cfg_route.
+                                       rtr_priority);
+
+       case IOC_LIBCFS_GET_NET: {
+               struct lnet_ioctl_net_config *net_config;
+               config = arg;
+               net_config = (struct lnet_ioctl_net_config *)
+                       config->cfg_bulk;
+               if (config == NULL || net_config == NULL)
+                       return -1;
+
+               return lnet_get_net_config(config->cfg_count,
+                                          &config->cfg_ncpts,
+                                          &config->cfg_nid,
+                                          &config->cfg_config_u.
+                                               cfg_net.net_peer_timeout,
+                                          &config->cfg_config_u.cfg_net.
+                                               net_peer_tx_credits,
+                                          &config->cfg_config_u.cfg_net.
+                                               net_peer_rtr_credits,
+                                          &config->cfg_config_u.cfg_net.
+                                               net_max_tx_credits,
+                                          net_config);
+       }
+
+       case IOC_LIBCFS_GET_LNET_STATS:
+       {
+               struct lnet_ioctl_lnet_stats *lnet_stats = arg;
+
+               lnet_counters_get(&lnet_stats->st_cntrs);
+               return 0;
+       }
+
+#if defined(__KERNEL__) && defined(LNET_ROUTER)
+       case IOC_LIBCFS_CONFIG_RTR:
+               config = arg;
+               LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
+               if (config->cfg_config_u.cfg_buffers.buf_enable) {
+                       rc = lnet_rtrpools_enable();
+                       LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
+                       return rc;
+               }
+               lnet_rtrpools_disable();
+               LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
+               return 0;
+
+       case IOC_LIBCFS_ADD_BUF:
+               config = arg;
+               LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
+               rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
+                                               buf_tiny,
+                                         config->cfg_config_u.cfg_buffers.
+                                               buf_small,
+                                         config->cfg_config_u.cfg_buffers.
+                                               buf_large);
+               LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
+               return rc;
+#endif
+
+       case IOC_LIBCFS_GET_BUF: {
+               struct lnet_ioctl_pool_cfg *pool_cfg;
+               config = arg;
+               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;
+               return lnet_get_peer_info(
+                  peer_info->pr_count,
+                  &peer_info->pr_nid,
+                  peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_rtr_credits,
+                  &peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
+       }
+
        case IOC_LIBCFS_NOTIFY_ROUTER:
                return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
                                   cfs_time_current() -
@@ -2040,7 +2220,7 @@ LNetCtl(unsigned int cmd, void *arg)
                id.nid = data->ioc_nid;
                id.pid = data->ioc_u32[0];
                rc = lnet_ping(id, data->ioc_u32[1], /* timeout */
-                              (lnet_process_id_t *)data->ioc_pbuf1,
+                              (lnet_process_id_t __user *)data->ioc_pbuf1,
                               data->ioc_plen1/sizeof(lnet_process_id_t));
                if (rc < 0)
                        return rc;
@@ -2139,8 +2319,8 @@ LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
 }
 EXPORT_SYMBOL(LNetSnprintHandle);
 
-int
-lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids,
+static int
+lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
          int n_ids)
 {
        lnet_handle_eq_t     eqh;
@@ -2169,7 +2349,7 @@ lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids,
                return -EINVAL;
 
        if (id.pid == LNET_PID_ANY)
-               id.pid = LUSTRE_SRV_LNET_PID;
+               id.pid = LNET_PID_LUSTRE;
 
        LIBCFS_ALLOC(info, infosz);
        if (info == NULL)