From 0247a9945aa2b9f24b884daca2adb5c47b3c8857 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 5 Apr 2021 17:00:18 +0900 Subject: [PATCH] thread: Add spdk_io_channel_get_io_device() to get io_device from io_channel This will be useful as the same purpose as spdk_io_channel_iter_get_io_device() and will be used in the following patches. Signed-off-by: Shuhei Matsumoto Change-Id: Id45f5980c65543703b91df2afeb47448232fe503 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7237 Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- CHANGELOG.md | 5 +++++ include/spdk/thread.h | 9 +++++++++ lib/thread/spdk_thread.map | 1 + lib/thread/thread.c | 6 ++++++ test/unit/lib/thread/thread.c/thread_ut.c | 3 +++ 5 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c1ca3070..86706bfde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,11 @@ bool to int. We can use RPC to configure different value of enable_placement_id. Then we can leverage SO_INCOMING_CPU to get placement_id, which aims to utilize CPU cache locality, enabled by setting enable_placement_id=2. +### thread + +A new API `spdk_io_channel_get_io_device` was added to get the io_device for the specified +I/O channel. + ## v21.01: ### idxd diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 7b738885e..71c620f23 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -721,6 +721,15 @@ struct spdk_io_channel *spdk_io_channel_iter_get_channel(struct spdk_io_channel_ */ void *spdk_io_channel_iter_get_ctx(struct spdk_io_channel_iter *i); +/** + * Get the io_device for the specified I/O channel. + * + * \param ch I/O channel. + * + * \return a pointer to the io_device for the I/O channel + */ +void *spdk_io_channel_get_io_device(struct spdk_io_channel *ch); + /** * Helper function to iterate all channels for spdk_for_each_channel(). * diff --git a/lib/thread/spdk_thread.map b/lib/thread/spdk_thread.map index ea0024412..2b064f715 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -41,6 +41,7 @@ spdk_io_channel_get_ctx; spdk_io_channel_from_ctx; spdk_io_channel_get_thread; + spdk_io_channel_get_io_device; spdk_for_each_channel; spdk_io_channel_iter_get_io_device; spdk_io_channel_iter_get_channel; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index ab19a8f11..1d3fa20ec 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1680,6 +1680,12 @@ spdk_io_channel_get_thread(struct spdk_io_channel *ch) return ch->thread; } +void * +spdk_io_channel_get_io_device(struct spdk_io_channel *ch) +{ + return ch->dev->io_device; +} + struct spdk_io_channel_iter { void *io_device; struct io_device *dev; diff --git a/test/unit/lib/thread/thread.c/thread_ut.c b/test/unit/lib/thread/thread.c/thread_ut.c index 2afe913b6..11e3bf3c9 100644 --- a/test/unit/lib/thread/thread.c/thread_ut.c +++ b/test/unit/lib/thread/thread.c/thread_ut.c @@ -702,12 +702,14 @@ channel(void) ch1 = spdk_get_io_channel(&g_device1); CU_ASSERT(g_create_cb_calls == 1); SPDK_CU_ASSERT_FATAL(ch1 != NULL); + CU_ASSERT(spdk_io_channel_get_io_device(ch1) == &g_device1); g_create_cb_calls = 0; ch2 = spdk_get_io_channel(&g_device1); CU_ASSERT(g_create_cb_calls == 0); CU_ASSERT(ch1 == ch2); SPDK_CU_ASSERT_FATAL(ch2 != NULL); + CU_ASSERT(spdk_io_channel_get_io_device(ch2) == &g_device1); g_destroy_cb_calls = 0; spdk_put_io_channel(ch2); @@ -719,6 +721,7 @@ channel(void) CU_ASSERT(g_create_cb_calls == 1); CU_ASSERT(ch1 != ch2); SPDK_CU_ASSERT_FATAL(ch2 != NULL); + CU_ASSERT(spdk_io_channel_get_io_device(ch2) == &g_device2); ctx = spdk_io_channel_get_ctx(ch2); CU_ASSERT(*(uint64_t *)ctx == g_ctx2);