diff --git a/include/spdk/thread.h b/include/spdk/thread.h index b68a73ea6..ca895f673 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -506,7 +506,7 @@ struct spdk_io_channel *spdk_get_io_channel(void *io_device); /** * Release a reference to an I/O channel. This happens asynchronously. * - * Actual release will happen on the same thread that called spdk_get_io_channel() + * This must be called on the same thread that called spdk_get_io_channel() * for the specified I/O channel. If this releases the last reference to the * I/O channel, The destroy_cb function specified in spdk_io_device_register() * will be invoked to release any associated resources. diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 136e92bcb..b6e855037 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1200,8 +1200,8 @@ _spdk_put_io_channel(void *arg) } SPDK_DEBUGLOG(SPDK_LOG_THREAD, - "Releasing io_channel %p for io_device %s (%p). Channel thread %p. Current thread %s\n", - ch, ch->dev->name, ch->dev->io_device, ch->thread, thread->name); + "Releasing io_channel %p for io_device %s (%p) on thread %s\n", + ch, ch->dev->name, ch->dev->io_device, thread->name); assert(ch->thread == thread); @@ -1245,15 +1245,30 @@ _spdk_put_io_channel(void *arg) void spdk_put_io_channel(struct spdk_io_channel *ch) { + struct spdk_thread *thread; + + thread = spdk_get_thread(); + if (!thread) { + SPDK_ERRLOG("called from non-SPDK thread\n"); + assert(false); + return; + } + + if (ch->thread != thread) { + SPDK_ERRLOG("different from the thread that called get_io_channel()\n"); + assert(false); + return; + } + SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Putting io_channel %p for io_device %s (%p) on thread %s refcnt %u\n", - ch, ch->dev->name, ch->dev->io_device, ch->thread->name, ch->ref); + ch, ch->dev->name, ch->dev->io_device, thread->name, ch->ref); ch->ref--; if (ch->ref == 0) { ch->destroy_ref++; - spdk_thread_send_msg(ch->thread, _spdk_put_io_channel, ch); + spdk_thread_send_msg(thread, _spdk_put_io_channel, ch); } } diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 355c891b7..4104fb0e8 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -4772,7 +4772,9 @@ blob_thin_prov_rw(void) CU_ASSERT(g_bserrno == 0); CU_ASSERT(free_clusters == spdk_bs_free_cluster_count(bs)); + set_thread(1); spdk_bs_free_io_channel(channel_thread1); + set_thread(0); spdk_bs_free_io_channel(channel); poll_threads();