diff --git a/include/spdk/io_channel.h b/include/spdk/io_channel.h index 67d64f240..5eb4305a9 100644 --- a/include/spdk/io_channel.h +++ b/include/spdk/io_channel.h @@ -154,6 +154,12 @@ void spdk_put_io_channel(struct spdk_io_channel *ch); */ void *spdk_io_channel_get_ctx(struct spdk_io_channel *ch); +/** + * \brief Returns an I/O channel from a context buffer. This is + * the inverse of spdk_io_channel_get_ctx(). + */ +struct spdk_io_channel *spdk_io_channel_from_ctx(void *ctx); + /** * \brief Returns the spdk_thread associated with an I/O channel. */ diff --git a/lib/util/io_channel.c b/lib/util/io_channel.c index 4a1b1bbc8..2272cecf2 100644 --- a/lib/util/io_channel.c +++ b/lib/util/io_channel.c @@ -400,6 +400,12 @@ spdk_io_channel_get_ctx(struct spdk_io_channel *ch) return (uint8_t *)ch + sizeof(*ch); } +struct spdk_io_channel * +spdk_io_channel_from_ctx(void *ctx) +{ + return (struct spdk_io_channel *)((uint8_t *)ctx - sizeof(struct spdk_io_channel)); +} + struct spdk_thread * spdk_io_channel_get_thread(struct spdk_io_channel *ch) {