From a591161cb23c6a6cf5cf9bb516a2e3e94a4662b8 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 16 May 2017 13:03:11 -0700 Subject: [PATCH] bdev: make struct spdk_bdev contents private Change-Id: If203e82f8cd10d5998a565ad490ef11e2916687f Signed-off-by: Daniel Verkamp --- include/spdk/bdev.h | 53 +------------------------------ include/spdk_internal/bdev.h | 52 ++++++++++++++++++++++++++++++ lib/bdev/null/blockdev_null_rpc.c | 2 +- lib/bdev/rpc/bdev_rpc.c | 3 +- test/lib/scsi/dev/dev_ut.c | 5 +++ test/lib/scsi/lun/lun_ut.c | 5 +++ 6 files changed, 66 insertions(+), 54 deletions(-) diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index b1128a2db..b0cc916f2 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -42,15 +42,11 @@ #include "spdk/stdinc.h" #include "spdk/event.h" -#include "spdk/queue.h" #include "spdk/scsi_spec.h" #define SPDK_BDEV_SMALL_BUF_MAX_SIZE 8192 #define SPDK_BDEV_LARGE_BUF_MAX_SIZE (64 * 1024) -#define SPDK_BDEV_MAX_NAME_LENGTH 16 -#define SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH 50 - typedef void (*spdk_bdev_remove_cb_t)(void *remove_ctx); /** @@ -77,54 +73,7 @@ enum spdk_bdev_status { * * This is a virtual representation of a block device that is exported by the backend. */ -struct spdk_bdev { - /** User context passed in by the backend */ - void *ctxt; - - /** Unique name for this block device. */ - char name[SPDK_BDEV_MAX_NAME_LENGTH]; - - /** Unique product name for this kind of block device. */ - char product_name[SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH]; - - /** Size in bytes of a logical block for the backend */ - uint32_t blocklen; - - /** Number of blocks */ - uint64_t blockcnt; - - /** write cache enabled, not used at the moment */ - int write_cache; - - /** - * This is used to make sure buffers are sector aligned. - * This causes double buffering on writes. - */ - int need_aligned_buffer; - - /** function table for all LUN ops */ - const struct spdk_bdev_fn_table *fn_table; - - /** Represents maximum unmap block descriptor count */ - uint32_t max_unmap_bdesc_count; - - /** generation value used by block device reset */ - uint32_t gencnt; - - /** Mutex protecting claimed */ - pthread_mutex_t mutex; - - /** The bdev status */ - enum spdk_bdev_status status; - - /** Remove callback function pointer to upper level stack */ - spdk_bdev_remove_cb_t remove_cb; - - /** Callback context for hot remove the device */ - void *remove_ctx; - - TAILQ_ENTRY(spdk_bdev) link; -}; +struct spdk_bdev; /** Blockdev I/O type */ enum spdk_bdev_io_type { diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 93bcbf94b..be5095e47 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -79,6 +79,9 @@ * must be passed to the bdev database via spdk_bdev_register(). */ +#define SPDK_BDEV_MAX_NAME_LENGTH 16 +#define SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH 50 + /** Block device module */ struct spdk_bdev_module_if { /** @@ -145,6 +148,55 @@ struct spdk_bdev_fn_table { int (*dump_config_json)(void *ctx, struct spdk_json_write_ctx *w); }; +struct spdk_bdev { + /** User context passed in by the backend */ + void *ctxt; + + /** Unique name for this block device. */ + char name[SPDK_BDEV_MAX_NAME_LENGTH]; + + /** Unique product name for this kind of block device. */ + char product_name[SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH]; + + /** Size in bytes of a logical block for the backend */ + uint32_t blocklen; + + /** Number of blocks */ + uint64_t blockcnt; + + /** write cache enabled, not used at the moment */ + int write_cache; + + /** + * This is used to make sure buffers are sector aligned. + * This causes double buffering on writes. + */ + int need_aligned_buffer; + + /** function table for all LUN ops */ + const struct spdk_bdev_fn_table *fn_table; + + /** Represents maximum unmap block descriptor count */ + uint32_t max_unmap_bdesc_count; + + /** generation value used by block device reset */ + uint32_t gencnt; + + /** Mutex protecting claimed */ + pthread_mutex_t mutex; + + /** The bdev status */ + enum spdk_bdev_status status; + + /** Remove callback function pointer to upper level stack */ + spdk_bdev_remove_cb_t remove_cb; + + /** Callback context for hot remove the device */ + void *remove_ctx; + + TAILQ_ENTRY(spdk_bdev) link; +}; + typedef void (*spdk_bdev_io_get_buf_cb)(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io); struct spdk_bdev_io { diff --git a/lib/bdev/null/blockdev_null_rpc.c b/lib/bdev/null/blockdev_null_rpc.c index e688b5836..32d3fbbcb 100644 --- a/lib/bdev/null/blockdev_null_rpc.c +++ b/lib/bdev/null/blockdev_null_rpc.c @@ -31,10 +31,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "spdk/bdev.h" #include "spdk/rpc.h" #include "spdk/util.h" +#include "spdk_internal/bdev.h" #include "spdk_internal/log.h" #include "blockdev_null.h" diff --git a/lib/bdev/rpc/bdev_rpc.c b/lib/bdev/rpc/bdev_rpc.c index 837ffeed8..aea21ac62 100644 --- a/lib/bdev/rpc/bdev_rpc.c +++ b/lib/bdev/rpc/bdev_rpc.c @@ -31,10 +31,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "spdk/bdev.h" #include "spdk/log.h" #include "spdk/rpc.h" +#include "spdk_internal/bdev.h" + static void spdk_rpc_get_bdevs(struct spdk_jsonrpc_server_conn *conn, const struct spdk_json_val *params, diff --git a/test/lib/scsi/dev/dev_ut.c b/test/lib/scsi/dev/dev_ut.c index 0d7b23902..5a85a3101 100644 --- a/test/lib/scsi/dev/dev_ut.c +++ b/test/lib/scsi/dev/dev_ut.c @@ -39,6 +39,11 @@ #include "dev.c" #include "port.c" +/* Unit test bdev mockup */ +struct spdk_bdev { + char name[100]; +}; + static struct spdk_bdev g_bdev = {}; struct lun_entry { diff --git a/test/lib/scsi/lun/lun_ut.c b/test/lib/scsi/lun/lun_ut.c index 81de68259..78f650e78 100644 --- a/test/lib/scsi/lun/lun_ut.c +++ b/test/lib/scsi/lun/lun_ut.c @@ -39,6 +39,11 @@ #include "lun.c" #include "lun_db.c" +/* Unit test bdev mockup */ +struct spdk_bdev { + int x; +}; + SPDK_LOG_REGISTER_TRACE_FLAG("scsi", SPDK_TRACE_SCSI) struct spdk_scsi_globals g_spdk_scsi;