diff --git a/CHANGELOG.md b/CHANGELOG.md index 0912e64e31..0a753e7c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ Updated ISA-L submodule to commit f3993f5c0b6911 which includes implementation and optimization for aarch64. +### thread + +`spdk_thread_send_msg` now returns int indicating if the message was successfully +sent. + ## v19.10: ### rpc diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 218bcf802c..a29d807df1 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -373,8 +373,12 @@ int spdk_thread_get_stats(struct spdk_thread_stats *stats); * \param thread The target thread. * \param fn This function will be called on the given thread. * \param ctx This context will be passed to fn when called. + * + * \return 0 on success + * \return -ENOMEM if the message could not be allocated + * \return -EIO if the message could not be sent to the destination thread */ -void spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx); +int spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx); /** * Send a message to each thread, serially. diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 98581bd922..cf3c7d6caa 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -648,17 +648,14 @@ spdk_thread_get_stats(struct spdk_thread_stats *stats) return 0; } -void +int spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx) { struct spdk_thread *local_thread; struct spdk_msg *msg; int rc; - if (!thread) { - assert(false); - return; - } + assert(thread != NULL); local_thread = _get_thread(); @@ -675,8 +672,8 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx if (msg == NULL) { msg = spdk_mempool_get(g_spdk_msg_mempool); if (!msg) { - assert(false); - return; + SPDK_ERRLOG("msg could not be allocated\n"); + return -ENOMEM; } } @@ -685,10 +682,12 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx rc = spdk_ring_enqueue(thread->messages, (void **)&msg, 1, NULL); if (rc != 1) { - assert(false); + SPDK_ERRLOG("msg could not be enqueued\n"); spdk_mempool_put(g_spdk_msg_mempool, msg); - return; + return -EIO; } + + return 0; } struct spdk_poller * @@ -1200,6 +1199,7 @@ spdk_for_each_channel(void *io_device, spdk_channel_msg fn, void *ctx, struct spdk_thread *thread; struct spdk_io_channel *ch; struct spdk_io_channel_iter *i; + int rc; i = calloc(1, sizeof(*i)); if (!i) { @@ -1223,7 +1223,8 @@ spdk_for_each_channel(void *io_device, spdk_channel_msg fn, void *ctx, i->cur_thread = thread; i->ch = ch; pthread_mutex_unlock(&g_devlist_mutex); - spdk_thread_send_msg(thread, _call_channel, i); + rc = spdk_thread_send_msg(thread, _call_channel, i); + assert(rc == 0); return; } } @@ -1231,7 +1232,8 @@ spdk_for_each_channel(void *io_device, spdk_channel_msg fn, void *ctx, pthread_mutex_unlock(&g_devlist_mutex); - spdk_thread_send_msg(i->orig_thread, _call_completion, i); + rc = spdk_thread_send_msg(i->orig_thread, _call_completion, i); + assert(rc == 0); } void diff --git a/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c b/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c index 530c859b02..e0509fe847 100644 --- a/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c +++ b/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c @@ -145,10 +145,11 @@ spdk_bdev_close(struct spdk_bdev_desc *desc) { } -void +int spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx) { fn(ctx); + return 0; } struct spdk_thread *