void
lnet_init_locks(void)
{
- cfs_spin_lock_init (&the_lnet.ln_lock);
- cfs_waitq_init (&the_lnet.ln_waitq);
- cfs_mutex_init(&the_lnet.ln_lnd_mutex);
- cfs_mutex_init(&the_lnet.ln_api_mutex);
+ cfs_spin_lock_init (&the_lnet.ln_lock);
+ cfs_waitq_init(&the_lnet.ln_eq_waitq);
+ cfs_mutex_init(&the_lnet.ln_lnd_mutex);
+ cfs_mutex_init(&the_lnet.ln_api_mutex);
}
void
void lnet_init_locks(void)
{
- pthread_cond_init(&the_lnet.ln_cond, NULL);
- pthread_mutex_init(&the_lnet.ln_lock, NULL);
- pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL);
- pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
+ pthread_cond_init(&the_lnet.ln_eq_cond, NULL);
+ pthread_mutex_init(&the_lnet.ln_lock, NULL);
+ pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL);
+ pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);
}
void lnet_fini_locks(void)
{
- pthread_mutex_destroy(&the_lnet.ln_api_mutex);
- pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
- pthread_mutex_destroy(&the_lnet.ln_lock);
- pthread_cond_destroy(&the_lnet.ln_cond);
+ pthread_mutex_destroy(&the_lnet.ln_api_mutex);
+ pthread_mutex_destroy(&the_lnet.ln_lnd_mutex);
+ pthread_mutex_destroy(&the_lnet.ln_lock);
+ pthread_cond_destroy(&the_lnet.ln_eq_cond);
}
# endif
LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
}
-#ifndef LNET_USE_LIB_FREELIST
-
-int
-lnet_descriptor_setup (void)
-{
- return 0;
-}
-
-void
-lnet_descriptor_cleanup (void)
-{
-}
-
-#else
+#ifdef LNET_USE_LIB_FREELIST
int
lnet_freelist_init (lnet_freelist_t *fl, int n, int size)
memset (fl, 0, sizeof (*fl));
}
-int
-lnet_descriptor_setup (void)
-{
- /* NB on failure caller must still call lnet_descriptor_cleanup */
- /* ****** */
- int rc;
-
- memset (&the_lnet.ln_free_msgs, 0, sizeof (the_lnet.ln_free_msgs));
- rc = lnet_freelist_init(&the_lnet.ln_free_msgs,
- LNET_FL_MAX_MSGS, sizeof(lnet_msg_t));
- if (rc != 0)
- return (rc);
- return (rc);
-}
-
-void
-lnet_descriptor_cleanup (void)
-{
- lnet_freelist_fini (&the_lnet.ln_free_msgs);
-}
-
#endif /* LNET_USE_LIB_FREELIST */
__u64
cfs_list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
}
-cfs_list_t *
-lnet_portal_mhash_alloc(void)
-{
- cfs_list_t *mhash;
- int i;
-
- LIBCFS_ALLOC(mhash, sizeof(cfs_list_t) * LNET_PORTAL_HASH_SIZE);
- if (mhash == NULL)
- return NULL;
-
- for (i = 0; i < LNET_PORTAL_HASH_SIZE; i++)
- CFS_INIT_LIST_HEAD(&mhash[i]);
-
- return mhash;
-}
-
-void
-lnet_portal_mhash_free(cfs_list_t *mhash)
-{
- int i;
-
- for (i = 0; i < LNET_PORTAL_HASH_SIZE; i++) {
- while (!cfs_list_empty(&mhash[i])) {
- lnet_me_t *me = cfs_list_entry(mhash[i].next,
- lnet_me_t, me_list);
- CERROR ("Active ME %p on exit portal mhash\n", me);
- cfs_list_del(&me->me_list);
- lnet_me_free(me);
- }
- }
- LIBCFS_FREE(mhash, sizeof(cfs_list_t) * LNET_PORTAL_HASH_SIZE);
-}
-
-int
-lnet_init_finalizers(void)
-{
-#ifdef __KERNEL__
- int i;
-
- the_lnet.ln_nfinalizers = (int) cfs_num_online_cpus();
-
- LIBCFS_ALLOC(the_lnet.ln_finalizers,
- the_lnet.ln_nfinalizers *
- sizeof(*the_lnet.ln_finalizers));
- if (the_lnet.ln_finalizers == NULL) {
- CERROR("Can't allocate ln_finalizers\n");
- return -ENOMEM;
- }
-
- for (i = 0; i < the_lnet.ln_nfinalizers; i++)
- the_lnet.ln_finalizers[i] = NULL;
-#else
- the_lnet.ln_finalizing = 0;
-#endif
-
- CFS_INIT_LIST_HEAD(&the_lnet.ln_finalizeq);
- return 0;
-}
-
-void
-lnet_fini_finalizers(void)
-{
-#ifdef __KERNEL__
- int i;
-
- for (i = 0; i < the_lnet.ln_nfinalizers; i++)
- LASSERT (the_lnet.ln_finalizers[i] == NULL);
-
- LIBCFS_FREE(the_lnet.ln_finalizers,
- the_lnet.ln_nfinalizers *
- sizeof(*the_lnet.ln_finalizers));
-#else
- LASSERT (!the_lnet.ln_finalizing);
-#endif
- LASSERT (cfs_list_empty(&the_lnet.ln_finalizeq));
-}
-
#ifndef __KERNEL__
/**
* Reserved API - do not use.
{
/* Prepare to bring up the network */
int rc = 0;
- int i;
LASSERT (the_lnet.ln_refcount == 0);
}
#endif
- rc = lnet_descriptor_setup();
- if (rc != 0)
- return -ENOMEM;
-
memset(&the_lnet.ln_counters, 0,
sizeof(the_lnet.ln_counters));
- CFS_INIT_LIST_HEAD (&the_lnet.ln_active_msgs);
CFS_INIT_LIST_HEAD (&the_lnet.ln_test_peers);
CFS_INIT_LIST_HEAD (&the_lnet.ln_nis);
CFS_INIT_LIST_HEAD (&the_lnet.ln_zombie_nis);
lnet_init_rtrpools();
- rc = lnet_create_peer_table();
+ rc = lnet_peer_table_create();
if (rc != 0)
goto failed0;
- rc = lnet_init_finalizers();
+ /* NB: we will have instance of message container per CPT soon */
+ rc = lnet_msg_container_setup(&the_lnet.ln_msg_container);
if (rc != 0)
goto failed1;
goto failed3;
}
- the_lnet.ln_nportals = MAX_PORTALS;
- LIBCFS_ALLOC(the_lnet.ln_portals,
- the_lnet.ln_nportals *
- sizeof(*the_lnet.ln_portals));
- if (the_lnet.ln_portals == NULL) {
- rc = -ENOMEM;
- goto failed3;
- }
-
- for (i = 0; i < the_lnet.ln_nportals; i++) {
- CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_mlist));
- CFS_INIT_LIST_HEAD(&(the_lnet.ln_portals[i].ptl_msgq));
- the_lnet.ln_portals[i].ptl_options = 0;
- }
+ rc = lnet_portals_create();
+ if (rc != 0) {
+ CERROR("Failed to create portals for LNet: %d\n", rc);
+ goto failed3;
+ }
- return 0;
+ return 0;
failed3:
/* NB: lnet_res_container_cleanup is safe to call for
lnet_res_container_cleanup(&the_lnet.ln_me_container);
lnet_res_container_cleanup(&the_lnet.ln_eq_container);
failed2:
- lnet_fini_finalizers();
+ lnet_msg_container_cleanup(&the_lnet.ln_msg_container);
failed1:
- lnet_destroy_peer_table();
+ lnet_peer_table_destroy();
failed0:
- lnet_descriptor_cleanup();
return rc;
}
int
lnet_unprepare (void)
{
- int idx;
-
/* NB no LNET_LOCK since this is the last reference. All LND instances
* have shut down already, so it is safe to unlink and free all
* descriptors, even those that appear committed to a network op (eg MD
LASSERT (cfs_list_empty(&the_lnet.ln_zombie_nis));
LASSERT (the_lnet.ln_nzombie_nis == 0);
- for (idx = 0; idx < the_lnet.ln_nportals; idx++) {
- lnet_portal_t *ptl = &the_lnet.ln_portals[idx];
-
- LASSERT (cfs_list_empty(&ptl->ptl_msgq));
-
- while (!cfs_list_empty(&ptl->ptl_mlist)) {
- lnet_me_t *me = cfs_list_entry(ptl->ptl_mlist.next,
- lnet_me_t, me_list);
- CERROR ("Active ME %p on exit\n", me);
- cfs_list_del (&me->me_list);
- lnet_me_free (me);
- }
-
- if (ptl->ptl_mhash != NULL) {
- LASSERT (lnet_portal_is_unique(ptl));
- lnet_portal_mhash_free(ptl->ptl_mhash);
- }
- }
+ lnet_portals_destroy();
lnet_res_container_cleanup(&the_lnet.ln_md_container);
lnet_res_container_cleanup(&the_lnet.ln_me_container);
lnet_res_container_cleanup(&the_lnet.ln_eq_container);
- while (!cfs_list_empty (&the_lnet.ln_active_msgs)) {
- lnet_msg_t *msg = cfs_list_entry (the_lnet.ln_active_msgs.next,
- lnet_msg_t, msg_activelist);
-
- CERROR ("Active msg %p on exit\n", msg);
- LASSERT (msg->msg_onactivelist);
- msg->msg_onactivelist = 0;
- cfs_list_del (&msg->msg_activelist);
- lnet_msg_free (msg);
- }
-
- LIBCFS_FREE(the_lnet.ln_portals,
- the_lnet.ln_nportals * sizeof(*the_lnet.ln_portals));
-
lnet_free_rtrpools();
- lnet_fini_finalizers();
- lnet_destroy_peer_table();
- lnet_descriptor_cleanup();
+ lnet_msg_container_cleanup(&the_lnet.ln_msg_container);
+ lnet_peer_table_destroy();
- return (0);
+ return 0;
}
lnet_ni_t *
}
/* Drop the cached eqwait NI. */
- if (the_lnet.ln_eqwaitni != NULL) {
- lnet_ni_decref_locked(the_lnet.ln_eqwaitni);
- the_lnet.ln_eqwaitni = NULL;
- }
+ if (the_lnet.ln_eq_waitni != NULL) {
+ lnet_ni_decref_locked(the_lnet.ln_eq_waitni);
+ the_lnet.ln_eq_waitni = NULL;
+ }
/* Drop the cached loopback NI. */
if (the_lnet.ln_loni != NULL) {
/* Clear the peer table and wait for all peers to go (they hold refs on
* their NIs) */
- lnet_clear_peer_table();
+ lnet_peer_table_cleanup();
LNET_LOCK();
/* Now wait for the NI's I just nuked to show up on ln_zombie_nis
#ifndef __KERNEL__
if (lnd->lnd_wait != NULL) {
- if (the_lnet.ln_eqwaitni == NULL) {
- lnet_ni_addref(ni);
- the_lnet.ln_eqwaitni = ni;
- }
+ if (the_lnet.ln_eq_waitni == NULL) {
+ lnet_ni_addref(ni);
+ the_lnet.ln_eq_waitni = ni;
+ }
} else {
# ifndef HAVE_LIBPTHREAD
LCONSOLE_ERROR_MSG(0x106, "LND %s not supported in a "
nicount++;
}
- if (the_lnet.ln_eqwaitni != NULL && nicount > 1) {
- lnd_type = the_lnet.ln_eqwaitni->ni_lnd->lnd_type;
+ if (the_lnet.ln_eq_waitni != NULL && nicount > 1) {
+ lnd_type = the_lnet.ln_eq_waitni->ni_lnd->lnd_type;
LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network"
"\n",
libcfs_lnd2str(lnd_type));