From 5fc0475c140b86802ab8759a43845dcc34e7329d Mon Sep 17 00:00:00 2001 From: Jiewei Ke Date: Sat, 5 Jun 2021 08:50:15 -0400 Subject: [PATCH] thread: Make the definition of struct spdk_io_channel private Move the definition of structure spdk_io_channel into lib/thread/thread_internal.h, so we don't have to update SO_VER for other libraries in future when we need to change the internal details on the structure. Signed-off-by: Jiewei Ke Change-Id: I3d2ca7a8737972e0b33ce92e464da42c48f89dec Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8189 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ziye Yang Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- include/spdk/thread.h | 29 +------- include/spdk_internal/thread.h | 8 ++- lib/event/app_rpc.c | 2 +- lib/thread/spdk_thread.map | 1 + lib/thread/thread.c | 7 ++ lib/thread/thread_internal.h | 68 +++++++++++++++++++ test/unit/lib/accel/accel.c/accel_engine_ut.c | 3 +- test/unit/lib/bdev/compress.c/compress_ut.c | 3 +- test/unit/lib/bdev/crypto.c/crypto_ut.c | 3 +- .../bdev/nvme/bdev_ocssd.c/bdev_ocssd_ut.c | 2 +- .../lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c | 1 + .../vbdev_zone_block.c/vbdev_zone_block_ut.c | 2 +- test/unit/lib/blob/bs_dev_common.c | 2 +- test/unit/lib/blob/bs_scheduler.c | 2 + .../blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 2 +- test/unit/lib/ftl/common/utils.c | 1 + test/unit/lib/ftl/ftl_io.c/ftl_io_ut.c | 1 + test/unit/lib/lvol/lvol.c/lvol_ut.c | 2 +- test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c | 1 + .../lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c | 1 + test/unit/lib/thread/thread.c/thread_ut.c | 2 +- 21 files changed, 103 insertions(+), 40 deletions(-) create mode 100644 lib/thread/thread_internal.h diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 3f0459670c..c602b6ec01 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -39,9 +39,7 @@ #define SPDK_THREAD_H_ #include "spdk/stdinc.h" - #include "spdk/cpuset.h" -#include "spdk/queue.h" #ifdef __cplusplus extern "C" { @@ -210,30 +208,7 @@ typedef void (*spdk_channel_msg)(struct spdk_io_channel_iter *i); */ typedef void (*spdk_channel_for_each_cpl)(struct spdk_io_channel_iter *i, int status); -/** - * \brief Represents a per-thread channel for accessing an I/O device. - * - * An I/O device may be a physical entity (i.e. NVMe controller) or a software - * entity (i.e. a blobstore). - * - * This structure is not part of the API - all accesses should be done through - * spdk_io_channel function calls. - */ -struct spdk_io_channel { - struct spdk_thread *thread; - struct io_device *dev; - uint32_t ref; - uint32_t destroy_ref; - TAILQ_ENTRY(spdk_io_channel) tailq; - spdk_io_channel_destroy_cb destroy_cb; - - /* - * Modules will allocate extra memory off the end of this structure - * to store references to hardware-specific references (i.e. NVMe queue - * pairs, or references to child device spdk_io_channels (i.e. - * virtual bdevs). - */ -}; +#define SPDK_IO_CHANNEL_STRUCT_SIZE 96 /** * Initialize the threading library. Must be called once prior to allocating any threads. @@ -688,7 +663,7 @@ void spdk_put_io_channel(struct spdk_io_channel *ch); static inline void * spdk_io_channel_get_ctx(struct spdk_io_channel *ch) { - return (uint8_t *)ch + sizeof(*ch); + return (uint8_t *)ch + SPDK_IO_CHANNEL_STRUCT_SIZE; } /** diff --git a/include/spdk_internal/thread.h b/include/spdk_internal/thread.h index 1fd6548005..752d45dd49 100644 --- a/include/spdk_internal/thread.h +++ b/include/spdk_internal/thread.h @@ -31,8 +31,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SPDK_THREAD_INTERNAL_H_ -#define SPDK_THREAD_INTERNAL_H_ +#ifndef SPDK_INTERNAL_THREAD_H_ +#define SPDK_INTERNAL_THREAD_H_ #include "spdk/stdinc.h" #include "spdk/thread.h" @@ -44,6 +44,7 @@ struct spdk_poller_stats { uint64_t busy_count; }; +struct io_device; struct spdk_thread; const char *spdk_poller_get_name(struct spdk_poller *poller); @@ -51,6 +52,7 @@ const char *spdk_poller_get_state_str(struct spdk_poller *poller); uint64_t spdk_poller_get_period_ticks(struct spdk_poller *poller); void spdk_poller_get_stats(struct spdk_poller *poller, struct spdk_poller_stats *stats); +const char *spdk_io_channel_get_io_device_name(struct spdk_io_channel *ch); int spdk_io_channel_get_ref_count(struct spdk_io_channel *ch); const char *spdk_io_device_get_name(struct io_device *dev); @@ -65,4 +67,4 @@ struct spdk_poller *spdk_thread_get_next_paused_poller(struct spdk_poller *prev) struct spdk_io_channel *spdk_thread_get_first_io_channel(struct spdk_thread *thread); struct spdk_io_channel *spdk_thread_get_next_io_channel(struct spdk_io_channel *prev); -#endif /* SPDK_THREAD_INTERNAL_H_ */ +#endif /* SPDK_INTERNAL_THREAD_H_ */ diff --git a/lib/event/app_rpc.c b/lib/event/app_rpc.c index dba215898e..380c712a59 100644 --- a/lib/event/app_rpc.c +++ b/lib/event/app_rpc.c @@ -321,7 +321,7 @@ static void rpc_get_io_channel(struct spdk_io_channel *ch, struct spdk_json_write_ctx *w) { spdk_json_write_object_begin(w); - spdk_json_write_named_string(w, "name", spdk_io_device_get_name(ch->dev)); + spdk_json_write_named_string(w, "name", spdk_io_channel_get_io_device_name(ch)); spdk_json_write_named_uint32(w, "ref", spdk_io_channel_get_ref_count(ch)); spdk_json_write_object_end(w); } diff --git a/lib/thread/spdk_thread.map b/lib/thread/spdk_thread.map index ff8488ea94..94b5c5e6b0 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -61,6 +61,7 @@ spdk_poller_get_state_str; spdk_poller_get_period_ticks; spdk_poller_get_stats; + spdk_io_channel_get_io_device_name; spdk_io_channel_get_ref_count; spdk_io_device_get_name; spdk_thread_get_first_active_poller; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 86ecab7301..74bb83b426 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -45,6 +45,7 @@ #include "spdk/log.h" #include "spdk_internal/thread.h" +#include "thread_internal.h" #ifdef __linux__ #include @@ -2209,6 +2210,12 @@ spdk_io_channel_get_io_device(struct spdk_io_channel *ch) return ch->dev->io_device; } +const char * +spdk_io_channel_get_io_device_name(struct spdk_io_channel *ch) +{ + return spdk_io_device_get_name(ch->dev); +} + int spdk_io_channel_get_ref_count(struct spdk_io_channel *ch) { diff --git a/lib/thread/thread_internal.h b/lib/thread/thread_internal.h new file mode 100644 index 0000000000..e8de395136 --- /dev/null +++ b/lib/thread/thread_internal.h @@ -0,0 +1,68 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SPDK_THREAD_INTERNAL_H_ +#define SPDK_THREAD_INTERNAL_H_ + +#include "spdk/assert.h" +#include "spdk/queue.h" +#include "spdk/thread.h" + +/** + * \brief Represents a per-thread channel for accessing an I/O device. + * + * An I/O device may be a physical entity (i.e. NVMe controller) or a software + * entity (i.e. a blobstore). + * + * This structure is not part of the API - all accesses should be done through + * spdk_io_channel function calls. + */ +struct spdk_io_channel { + struct spdk_thread *thread; + struct io_device *dev; + uint32_t ref; + uint32_t destroy_ref; + TAILQ_ENTRY(spdk_io_channel) tailq; + spdk_io_channel_destroy_cb destroy_cb; + + uint8_t _padding[48]; + /* + * Modules will allocate extra memory off the end of this structure + * to store references to hardware-specific references (i.e. NVMe queue + * pairs, or references to child device spdk_io_channels (i.e. + * virtual bdevs). + */ +}; + +SPDK_STATIC_ASSERT(sizeof(struct spdk_io_channel) == SPDK_IO_CHANNEL_STRUCT_SIZE, "incorrect size"); + +#endif /* SPDK_THREAD_INTERNAL_H_ */ diff --git a/test/unit/lib/accel/accel.c/accel_engine_ut.c b/test/unit/lib/accel/accel.c/accel_engine_ut.c index dbd1282db1..b137f5ab7f 100644 --- a/test/unit/lib/accel/accel.c/accel_engine_ut.c +++ b/test/unit/lib/accel/accel.c/accel_engine_ut.c @@ -33,6 +33,7 @@ #include "spdk_cunit.h" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "common/lib/test_env.c" #include "accel/accel_engine.c" @@ -185,7 +186,7 @@ test_spdk_accel_get_capabilities(void) SPDK_CU_ASSERT_FATAL(ch != NULL); /* Setup a few capabilites and make sure they are reported as expected. */ - accel_ch = (struct accel_io_channel *)((char *)ch + sizeof(struct spdk_io_channel)); + accel_ch = (struct accel_io_channel *)spdk_io_channel_get_ctx(ch); accel_ch->engine = &engine; expected_cap = ACCEL_COPY | ACCEL_DUALCAST | ACCEL_CRC32C; accel_ch->engine->capabilities = expected_cap; diff --git a/test/unit/lib/bdev/compress.c/compress_ut.c b/test/unit/lib/bdev/compress.c/compress_ut.c index b75d7d4fa5..54a1f80c0e 100644 --- a/test/unit/lib/bdev/compress.c/compress_ut.c +++ b/test/unit/lib/bdev/compress.c/compress_ut.c @@ -36,6 +36,7 @@ #define UNIT_TEST_NO_VTOPHYS #include "common/lib/test_env.c" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "unit/lib/json_mock.c" #include "spdk/reduce.h" @@ -590,7 +591,7 @@ test_setup(void) g_bdev_io->bdev = &g_comp_bdev.comp_bdev; g_io_ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct comp_io_channel)); g_io_ch->thread = thread; - g_comp_ch = (struct comp_io_channel *)((uint8_t *)g_io_ch + sizeof(struct spdk_io_channel)); + g_comp_ch = (struct comp_io_channel *)spdk_io_channel_get_ctx(g_io_ch); g_io_ctx = (struct comp_bdev_io *)g_bdev_io->driver_ctx; g_io_ctx->comp_ch = g_comp_ch; diff --git a/test/unit/lib/bdev/crypto.c/crypto_ut.c b/test/unit/lib/bdev/crypto.c/crypto_ut.c index dcf20cdd51..6dbc646cb9 100644 --- a/test/unit/lib/bdev/crypto.c/crypto_ut.c +++ b/test/unit/lib/bdev/crypto.c/crypto_ut.c @@ -35,6 +35,7 @@ #include "common/lib/test_env.c" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "unit/lib/json_mock.c" #include @@ -317,7 +318,7 @@ test_setup(void) g_bdev_io->u.bdev.iovs = calloc(1, sizeof(struct iovec) * 128); g_bdev_io->bdev = &g_crypto_bdev.crypto_bdev; g_io_ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct crypto_io_channel)); - g_crypto_ch = (struct crypto_io_channel *)((uint8_t *)g_io_ch + sizeof(struct spdk_io_channel)); + g_crypto_ch = (struct crypto_io_channel *)spdk_io_channel_get_ctx(g_io_ch); g_io_ctx = (struct crypto_bdev_io *)g_bdev_io->driver_ctx; memset(&g_device, 0, sizeof(struct vbdev_dev)); memset(&g_crypto_bdev, 0, sizeof(struct vbdev_crypto)); diff --git a/test/unit/lib/bdev/nvme/bdev_ocssd.c/bdev_ocssd_ut.c b/test/unit/lib/bdev/nvme/bdev_ocssd.c/bdev_ocssd_ut.c index 66f2eb8cc5..5cbb4ec919 100644 --- a/test/unit/lib/bdev/nvme/bdev_ocssd.c/bdev_ocssd_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_ocssd.c/bdev_ocssd_ut.c @@ -34,10 +34,10 @@ #include "spdk/stdinc.h" #include "spdk_cunit.h" #include "spdk/nvme_ocssd_spec.h" -#include "spdk/thread.h" #include "spdk/bdev_module.h" #include "spdk/util.h" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "bdev/nvme/bdev_ocssd.c" #include "bdev/nvme/common.c" diff --git a/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c b/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c index 15eed95a39..574f8b09d0 100644 --- a/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c +++ b/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c @@ -35,6 +35,7 @@ #include "spdk_cunit.h" #include "spdk/env.h" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "bdev/raid/bdev_raid.c" #include "bdev/raid/bdev_raid_rpc.c" #include "bdev/raid/raid0.c" diff --git a/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c b/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c index bf62922c06..899418b78c 100644 --- a/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c +++ b/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c @@ -35,7 +35,7 @@ #include "spdk_cunit.h" #include "spdk/env.h" #include "spdk_internal/mock.h" -#include "spdk/thread.h" +#include "thread/thread_internal.h" #include "common/lib/test_env.c" #include "bdev/zone_block/vbdev_zone_block.c" #include "bdev/zone_block/vbdev_zone_block_rpc.c" diff --git a/test/unit/lib/blob/bs_dev_common.c b/test/unit/lib/blob/bs_dev_common.c index 4e94fef8be..686d03b6d1 100644 --- a/test/unit/lib/blob/bs_dev_common.c +++ b/test/unit/lib/blob/bs_dev_common.c @@ -31,7 +31,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "spdk/thread.h" +#include "thread/thread_internal.h" #include "bs_scheduler.c" diff --git a/test/unit/lib/blob/bs_scheduler.c b/test/unit/lib/blob/bs_scheduler.c index 4b58fa0070..0e73120d5a 100644 --- a/test/unit/lib/blob/bs_scheduler.c +++ b/test/unit/lib/blob/bs_scheduler.c @@ -31,6 +31,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "spdk/thread.h" + bool g_scheduler_delay = false; struct scheduled_ops { diff --git a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index 442026b1a9..4a5337e3fc 100644 --- a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -36,8 +36,8 @@ #include "spdk/blobfs.h" #include "spdk/env.h" #include "spdk/log.h" -#include "spdk/thread.h" #include "spdk/barrier.h" +#include "thread/thread_internal.h" #include "spdk_cunit.h" #include "unit/lib/blob/bs_dev_common.c" diff --git a/test/unit/lib/ftl/common/utils.c b/test/unit/lib/ftl/common/utils.c index cd834069d3..59db375f41 100644 --- a/test/unit/lib/ftl/common/utils.c +++ b/test/unit/lib/ftl/common/utils.c @@ -33,6 +33,7 @@ #include "spdk/ftl.h" #include "ftl/ftl_core.h" +#include "thread/thread_internal.h" struct base_bdev_geometry { size_t write_unit_size; diff --git a/test/unit/lib/ftl/ftl_io.c/ftl_io_ut.c b/test/unit/lib/ftl/ftl_io.c/ftl_io_ut.c index ba4211ccf9..3a2eb25c8b 100644 --- a/test/unit/lib/ftl/ftl_io.c/ftl_io_ut.c +++ b/test/unit/lib/ftl/ftl_io.c/ftl_io_ut.c @@ -32,6 +32,7 @@ */ #include "spdk/stdinc.h" +#include "thread/thread_internal.h" #include "spdk_cunit.h" #include "common/lib/ut_multithread.c" diff --git a/test/unit/lib/lvol/lvol.c/lvol_ut.c b/test/unit/lib/lvol/lvol.c/lvol_ut.c index d48238dff0..4bc3f0b726 100644 --- a/test/unit/lib/lvol/lvol.c/lvol_ut.c +++ b/test/unit/lib/lvol/lvol.c/lvol_ut.c @@ -33,10 +33,10 @@ #include "spdk_cunit.h" #include "spdk/blob.h" -#include "spdk/thread.h" #include "spdk/util.h" #include "spdk/bdev_module.h" +#include "thread/thread_internal.h" #include "common/lib/ut_multithread.c" diff --git a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c index f7cf138d53..af85fecdd7 100644 --- a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c +++ b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c @@ -35,6 +35,7 @@ #include "spdk_cunit.h" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "common/lib/ut_multithread.c" #include "nvmf/ctrlr.c" diff --git a/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c b/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c index 6f6bc08371..b21fb56b9b 100644 --- a/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c +++ b/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c @@ -36,6 +36,7 @@ #include "spdk_cunit.h" #include "spdk_internal/mock.h" +#include "thread/thread_internal.h" #include "nvmf/ctrlr_bdev.c" diff --git a/test/unit/lib/thread/thread.c/thread_ut.c b/test/unit/lib/thread/thread.c/thread_ut.c index 150aaed842..fe29d4e9aa 100644 --- a/test/unit/lib/thread/thread.c/thread_ut.c +++ b/test/unit/lib/thread/thread.c/thread_ut.c @@ -35,7 +35,7 @@ #include "spdk_cunit.h" -#include "spdk_internal/thread.h" +#include "thread/thread_internal.h" #include "thread/thread.c" #include "common/lib/ut_multithread.c"