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 <jiewei@smartx.com>
Change-Id: I3d2ca7a8737972e0b33ce92e464da42c48f89dec
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8189
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Jiewei Ke 2021-06-05 08:50:15 -04:00 committed by Jim Harris
parent 2509e1248c
commit 5fc0475c14
21 changed files with 103 additions and 40 deletions

View File

@ -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;
}
/**

View File

@ -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_ */

View File

@ -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);
}

View File

@ -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;

View File

@ -45,6 +45,7 @@
#include "spdk/log.h"
#include "spdk_internal/thread.h"
#include "thread_internal.h"
#ifdef __linux__
#include <sys/timerfd.h>
@ -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)
{

View File

@ -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_ */

View File

@ -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;

View File

@ -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;

View File

@ -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 <rte_crypto.h>
@ -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));

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 {

View File

@ -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"

View File

@ -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;

View File

@ -32,6 +32,7 @@
*/
#include "spdk/stdinc.h"
#include "thread/thread_internal.h"
#include "spdk_cunit.h"
#include "common/lib/ut_multithread.c"

View File

@ -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"

View File

@ -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"

View File

@ -36,6 +36,7 @@
#include "spdk_cunit.h"
#include "spdk_internal/mock.h"
#include "thread/thread_internal.h"
#include "nvmf/ctrlr_bdev.c"

View File

@ -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"