Commit 4036f95b authored by Jim Harris's avatar Jim Harris
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ie6d432d616be45c7a4232aff1548cef198702bc0

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472438


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 296e7fba
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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.
+13 −11
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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 *