From 4036f95bf8ee340375616c31dd71fcab215e02cb Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 25 Oct 2019 15:47:57 -0700 Subject: [PATCH] thread: return int from spdk_thread_seng_msg This at least allows the caller to know there was a problem, and that the messages wasn't actually sent. SPDK by default creates huge rings so this problem should never occur, but out-of-tree use cases may send messages much more often and require at least a notification when it fails. While here, change the thread check to an assert. There's no need to work around someone calling this function with a null thread parameter. Fixes issue #811. Signed-off-by: Jim Harris Change-Id: Ie6d432d616be45c7a4232aff1548cef198702bc0 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472438 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Tomasz Zawadzki --- CHANGELOG.md | 5 ++++ include/spdk/thread.h | 6 ++++- lib/thread/thread.c | 24 ++++++++++--------- .../lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c | 3 ++- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0912e64e3..0a753e7c6 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 218bcf802..a29d807df 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 98581bd92..cf3c7d6ca 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 530c859b0..e0509fe84 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 *