Whamcloud - gitweb
LU-12930 various: use schedule_timeout_*interruptible
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 2ccbecc..d39e6b9 100644 (file)
@@ -180,7 +180,7 @@ MODULE_PARM_DESC(lnet_drop_asym_route,
                 "Set to 1 to drop asymmetrical route messages.");
 
 #define LNET_TRANSACTION_TIMEOUT_NO_HEALTH_DEFAULT 50
-#define LNET_TRANSACTION_TIMEOUT_HEALTH_DEFAULT 10
+#define LNET_TRANSACTION_TIMEOUT_HEALTH_DEFAULT 50
 
 unsigned lnet_transaction_timeout = LNET_TRANSACTION_TIMEOUT_HEALTH_DEFAULT;
 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
@@ -200,7 +200,7 @@ module_param_call(lnet_transaction_timeout, transaction_to_set, param_get_int,
 MODULE_PARM_DESC(lnet_transaction_timeout,
                "Maximum number of seconds to wait for a peer response.");
 
-#define LNET_RETRY_COUNT_HEALTH_DEFAULT 3
+#define LNET_RETRY_COUNT_HEALTH_DEFAULT 2
 unsigned lnet_retry_count = LNET_RETRY_COUNT_HEALTH_DEFAULT;
 static int retry_count_set(const char *val, cfs_kernel_param_arg_t *kp);
 #ifdef HAVE_KERNEL_PARAM_OPS
@@ -550,17 +550,14 @@ lnet_init_locks(void)
        mutex_init(&the_lnet.ln_lnd_mutex);
 }
 
-static void
-lnet_fini_locks(void)
-{
-}
-
 struct kmem_cache *lnet_mes_cachep;       /* MEs kmem_cache */
 struct kmem_cache *lnet_small_mds_cachep;  /* <= LNET_SMALL_MD_SIZE bytes
                                            *  MDs kmem_cache */
+struct kmem_cache *lnet_rspt_cachep;      /* response tracker cache */
+struct kmem_cache *lnet_msg_cachep;
 
 static int
-lnet_descriptor_setup(void)
+lnet_slab_setup(void)
 {
        /* create specific kmem_cache for MEs and small MDs (i.e., originally
         * allocated in <size-xxx> kmem_cache).
@@ -576,12 +573,32 @@ lnet_descriptor_setup(void)
        if (!lnet_small_mds_cachep)
                return -ENOMEM;
 
+       lnet_rspt_cachep = kmem_cache_create("lnet_rspt", sizeof(struct lnet_rsp_tracker),
+                                           0, 0, NULL);
+       if (!lnet_rspt_cachep)
+               return -ENOMEM;
+
+       lnet_msg_cachep = kmem_cache_create("lnet_msg", sizeof(struct lnet_msg),
+                                           0, 0, NULL);
+       if (!lnet_msg_cachep)
+               return -ENOMEM;
+
        return 0;
 }
 
 static void
-lnet_descriptor_cleanup(void)
+lnet_slab_cleanup(void)
 {
+       if (lnet_msg_cachep) {
+               kmem_cache_destroy(lnet_msg_cachep);
+               lnet_msg_cachep = NULL;
+       }
+
+
+       if (lnet_rspt_cachep) {
+               kmem_cache_destroy(lnet_rspt_cachep);
+               lnet_rspt_cachep = NULL;
+       }
 
        if (lnet_small_mds_cachep) {
                kmem_cache_destroy(lnet_small_mds_cachep);
@@ -643,8 +660,6 @@ lnet_destroy_locks(void)
                cfs_percpt_lock_free(the_lnet.ln_net_lock);
                the_lnet.ln_net_lock = NULL;
        }
-
-       lnet_fini_locks();
 }
 
 static int
@@ -1155,7 +1170,7 @@ lnet_prepare(lnet_pid_t requested_pid)
        LNetInvalidateEQHandle(&the_lnet.ln_mt_eqh);
        init_completion(&the_lnet.ln_started);
 
-       rc = lnet_descriptor_setup();
+       rc = lnet_slab_setup();
        if (rc != 0)
                goto failed;
 
@@ -1190,14 +1205,6 @@ lnet_prepare(lnet_pid_t requested_pid)
        if (rc != 0)
                goto failed;
 
-       recs = lnet_res_containers_create(LNET_COOKIE_TYPE_ME);
-       if (recs == NULL) {
-               rc = -ENOMEM;
-               goto failed;
-       }
-
-       the_lnet.ln_me_containers = recs;
-
        recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD);
        if (recs == NULL) {
                rc = -ENOMEM;
@@ -1259,11 +1266,6 @@ lnet_unprepare (void)
                the_lnet.ln_md_containers = NULL;
        }
 
-       if (the_lnet.ln_me_containers != NULL) {
-               lnet_res_containers_destroy(the_lnet.ln_me_containers);
-               the_lnet.ln_me_containers = NULL;
-       }
-
        lnet_res_container_cleanup(&the_lnet.ln_eq_container);
 
        lnet_msg_containers_destroy();
@@ -1275,7 +1277,7 @@ lnet_unprepare (void)
                the_lnet.ln_counters = NULL;
        }
        lnet_destroy_remote_nets_table();
-       lnet_descriptor_cleanup();
+       lnet_slab_cleanup();
 
        return 0;
 }
@@ -1511,7 +1513,7 @@ lnet_ping_buffer_alloc(int nnis, gfp_t gfp)
 void
 lnet_ping_buffer_free(struct lnet_ping_buffer *pbuf)
 {
-       LASSERT(lnet_ping_buffer_numref(pbuf) == 0);
+       LASSERT(atomic_read(&pbuf->pb_refcnt) == 0);
        LIBCFS_FREE(pbuf, LNET_PING_BUFFER_SIZE(pbuf->pb_nnis));
 }
 
@@ -1673,7 +1675,7 @@ lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
                .nid = LNET_NID_ANY,
                .pid = LNET_PID_ANY
        };
-       struct lnet_handle_me me_handle;
+       struct lnet_me *me;
        struct lnet_md md = { NULL };
        int rc, rc2;
 
@@ -1693,11 +1695,11 @@ lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
        }
 
        /* Ping target ME/MD */
-       rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
+       me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
                          LNET_PROTO_PING_MATCHBITS, 0,
-                         LNET_UNLINK, LNET_INS_AFTER,
-                         &me_handle);
-       if (rc != 0) {
+                         LNET_UNLINK, LNET_INS_AFTER);
+       if (IS_ERR(me)) {
+               rc = PTR_ERR(me);
                CERROR("Can't create ping target ME: %d\n", rc);
                goto fail_decref_ping_buffer;
        }
@@ -1712,7 +1714,7 @@ lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
        md.eq_handle = the_lnet.ln_ping_target_eq;
        md.user_ptr  = *ppbuf;
 
-       rc = LNetMDAttach(me_handle, md, LNET_RETAIN, ping_mdh);
+       rc = LNetMDAttach(me, md, LNET_RETAIN, ping_mdh);
        if (rc != 0) {
                CERROR("Can't attach ping target MD: %d\n", rc);
                goto fail_unlink_ping_me;
@@ -1722,10 +1724,9 @@ lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf,
        return 0;
 
 fail_unlink_ping_me:
-       rc2 = LNetMEUnlink(me_handle);
-       LASSERT(rc2 == 0);
+       LNetMEUnlink(me);
 fail_decref_ping_buffer:
-       LASSERT(lnet_ping_buffer_numref(*ppbuf) == 1);
+       LASSERT(atomic_read(&(*ppbuf)->pb_refcnt) == 1);
        lnet_ping_buffer_decref(*ppbuf);
        *ppbuf = NULL;
 fail_free_eq:
@@ -1746,10 +1747,9 @@ lnet_ping_md_unlink(struct lnet_ping_buffer *pbuf,
        LNetInvalidateMDHandle(ping_mdh);
 
        /* NB the MD could be busy; this just starts the unlink */
-       while (lnet_ping_buffer_numref(pbuf) > 1) {
+       while (atomic_read(&pbuf->pb_refcnt) > 1) {
                CDEBUG(D_NET, "Still waiting for ping data MD to unlink\n");
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(1));
+               schedule_timeout_uninterruptible(cfs_time_seconds(1));
        }
 
        cfs_restore_sigs(blocked);
@@ -1855,7 +1855,7 @@ int lnet_push_target_resize(void)
 {
        struct lnet_process_id id = { LNET_NID_ANY, LNET_PID_ANY };
        struct lnet_md md = { NULL };
-       struct lnet_handle_me meh;
+       struct lnet_me *me;
        struct lnet_handle_md mdh;
        struct lnet_handle_md old_mdh;
        struct lnet_ping_buffer *pbuf;
@@ -1874,11 +1874,12 @@ again:
                goto fail_return;
        }
 
-       rc = LNetMEAttach(LNET_RESERVED_PORTAL, id,
+       me = LNetMEAttach(LNET_RESERVED_PORTAL, id,
                          LNET_PROTO_PING_MATCHBITS, 0,
-                         LNET_UNLINK, LNET_INS_AFTER,
-                         &meh);
-       if (rc) {
+                         LNET_UNLINK, LNET_INS_AFTER);
+
+       if (IS_ERR(me)) {
+               rc = PTR_ERR(me);
                CERROR("Can't create push target ME: %d\n", rc);
                goto fail_decref_pbuf;
        }
@@ -1893,10 +1894,10 @@ again:
        md.user_ptr  = pbuf;
        md.eq_handle = the_lnet.ln_push_target_eq;
 
-       rc = LNetMDAttach(meh, md, LNET_RETAIN, &mdh);
+       rc = LNetMDAttach(me, md, LNET_RETAIN, &mdh);
        if (rc) {
                CERROR("Can't attach push MD: %d\n", rc);
-               goto fail_unlink_meh;
+               goto fail_unlink_me;
        }
        lnet_ping_buffer_addref(pbuf);
 
@@ -1919,8 +1920,8 @@ again:
 
        return 0;
 
-fail_unlink_meh:
-       LNetMEUnlink(meh);
+fail_unlink_me:
+       LNetMEUnlink(me);
 fail_decref_pbuf:
        lnet_ping_buffer_decref(pbuf);
 fail_return:
@@ -1979,10 +1980,9 @@ static void lnet_push_target_fini(void)
        LNetInvalidateMDHandle(&the_lnet.ln_push_target_md);
 
        /* Wait for the unlink to complete. */
-       while (lnet_ping_buffer_numref(the_lnet.ln_push_target) > 1) {
+       while (atomic_read(&the_lnet.ln_push_target->pb_refcnt) > 1) {
                CDEBUG(D_NET, "Still waiting for ping data MD to unlink\n");
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(1));
+               schedule_timeout_uninterruptible(cfs_time_seconds(1));
        }
 
        lnet_ping_buffer_decref(the_lnet.ln_push_target);
@@ -2058,8 +2058,7 @@ lnet_clear_zombies_nis_locked(struct lnet_net *net)
                                       "Waiting for zombie LNI %s\n",
                                       libcfs_nid2str(ni->ni_nid));
                        }
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(cfs_time_seconds(1));
+                       schedule_timeout_uninterruptible(cfs_time_seconds(1));
                        lnet_net_lock(LNET_LOCK_EX);
                        continue;
                }
@@ -2069,7 +2068,14 @@ lnet_clear_zombies_nis_locked(struct lnet_net *net)
                islo = ni->ni_net->net_lnd->lnd_type == LOLND;
 
                LASSERT(!in_interrupt());
+               /* Holding the mutex makes it safe for lnd_shutdown
+                * to call module_put(). Module unload cannot finish
+                * until lnet_unregister_lnd() completes, and that
+                * requires the mutex.
+                */
+               mutex_lock(&the_lnet.ln_lnd_mutex);
                (net->net_lnd->lnd_shutdown)(ni);
+               mutex_unlock(&the_lnet.ln_lnd_mutex);
 
                if (!islo)
                        CDEBUG(D_LNI, "Removed LNI %s\n",
@@ -2134,11 +2140,9 @@ static void
 lnet_shutdown_lndnets(void)
 {
        struct lnet_net *net;
-       struct list_head resend;
+       LIST_HEAD(resend);
        struct lnet_msg *msg, *tmp;
 
-       INIT_LIST_HEAD(&resend);
-
        /* NB called holding the global mutex */
 
        /* All quiet on the API front */
@@ -2269,21 +2273,19 @@ static int
 lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
 {
        struct lnet_ni *ni;
-       struct lnet_net *net_l = NULL;
-       struct list_head        local_ni_list;
-       int                     rc;
-       int                     ni_count = 0;
-       __u32                   lnd_type;
+       struct lnet_net *net_l = NULL;
+       LIST_HEAD(local_ni_list);
+       int rc;
+       int ni_count = 0;
+       __u32 lnd_type;
        const struct lnet_lnd  *lnd;
-       int                     peer_timeout =
+       int peer_timeout =
                net->net_tunables.lct_peer_timeout;
-       int                     maxtxcredits =
+       int maxtxcredits =
                net->net_tunables.lct_max_tx_credits;
-       int                     peerrtrcredits =
+       int peerrtrcredits =
                net->net_tunables.lct_peer_rtr_credits;
 
-       INIT_LIST_HEAD(&local_ni_list);
-
        /*
         * make sure that this net is unique. If it isn't then
         * we are adding interfaces to an already existing network, and
@@ -2381,9 +2383,6 @@ lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
                if (rc < 0)
                        goto failed1;
 
-               LASSERT(ni->ni_net->net_tunables.lct_peer_timeout <= 0 ||
-                       ni->ni_net->net_lnd->lnd_query != NULL);
-
                lnet_ni_addref(ni);
                list_add_tail(&ni->ni_netlist, &local_ni_list);
 
@@ -2581,11 +2580,9 @@ LNetNIInit(lnet_pid_t requested_pid)
        int                     ni_count;
        struct lnet_ping_buffer *pbuf;
        struct lnet_handle_md   ping_mdh;
-       struct list_head        net_head;
+       LIST_HEAD(net_head);
        struct lnet_net         *net;
 
-       INIT_LIST_HEAD(&net_head);
-
        mutex_lock(&the_lnet.ln_api_mutex);
 
        CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
@@ -3172,9 +3169,7 @@ static int lnet_handle_legacy_ip2nets(char *ip2nets,
        struct lnet_net *net;
        char *nets;
        int rc;
-       struct list_head net_head;
-
-       INIT_LIST_HEAD(&net_head);
+       LIST_HEAD(net_head);
 
        rc = lnet_parse_ip2nets(&nets, ip2nets);
        if (rc < 0)
@@ -3353,14 +3348,12 @@ unlock_api_mutex:
 int
 lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
 {
-       struct lnet_net         *net;
-       struct list_head        net_head;
-       int                     rc;
+       struct lnet_net *net;
+       LIST_HEAD(net_head);
+       int rc;
        struct lnet_ioctl_config_lnd_tunables tun;
        char *nets = conf->cfg_config_u.cfg_net.net_intf;
 
-       INIT_LIST_HEAD(&net_head);
-
        /* Create a net/ni structures for the network string */
        rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
        if (rc <= 0)
@@ -3916,9 +3909,7 @@ LNetCtl(unsigned int cmd, void *arg)
                return 0;
 
        case IOC_LIBCFS_TESTPROTOCOMPAT:
-               lnet_net_lock(LNET_LOCK_EX);
                the_lnet.ln_testprotocompat = data->ioc_flags;
-               lnet_net_unlock(LNET_LOCK_EX);
                return 0;
 
        case IOC_LIBCFS_LNET_FAULT: