bdev: add pointer to module structure

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ic3051b63942770e45be22af0ae03a78a7c543f81

Reviewed-on: https://review.gerrithub.io/368597
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-07-06 17:36:17 -07:00
parent 0bb3618a99
commit 4794c791de
11 changed files with 37 additions and 0 deletions

View File

@ -186,6 +186,11 @@ struct spdk_bdev {
*/
int need_aligned_buffer;
/**
* Pointer to the bdev module that registered this bdev.
*/
struct spdk_bdev_module_if *module;
/** function table for all LUN ops */
const struct spdk_bdev_fn_table *fn_table;
@ -450,4 +455,13 @@ spdk_bdev_io_from_ctx(void *ctx)
spdk_vbdev_module_list_add(&_name ## _if); \
}
#define SPDK_GET_BDEV_MODULE(name) &name ## _if
/*
* Modules are not required to use this macro. It allows modules to reference the module with
* SPDK_GET_BDEV_MODULE() before it is defined by SPDK_BDEV_MODULE_REGISTER or its VBDEV variant.
*/
#define SPDK_DECLARE_BDEV_MODULE(name) \
static struct spdk_bdev_module_if name ## _if;
#endif /* SPDK_INTERNAL_BDEV_H */

View File

@ -361,6 +361,7 @@ create_aio_disk(const char *name, const char *fname)
goto error_return;
}
fdisk->disk.product_name = "AIO disk";
fdisk->disk.module = SPDK_GET_BDEV_MODULE(aio);
fdisk->disk.need_aligned_buffer = 1;
fdisk->disk.write_cache = 1;

View File

@ -1360,6 +1360,8 @@ _spdk_bdev_register(struct spdk_bdev *bdev)
{
struct spdk_bdev_module_if *vbdev_module;
assert(bdev->module != NULL);
bdev->status = SPDK_BDEV_STATUS_READY;
/* initialize the reset generation value to zero */

View File

@ -48,6 +48,8 @@
#include "vbdev_error.h"
SPDK_DECLARE_BDEV_MODULE(error);
struct vbdev_error_info {
bool enabled;
uint32_t error_type;
@ -267,6 +269,7 @@ spdk_vbdev_error_create(struct spdk_bdev *base_bdev)
disk->disk.product_name = "Error Injection Disk";
disk->disk.ctxt = disk;
disk->disk.fn_table = &vbdev_error_fn_table;
disk->disk.module = SPDK_GET_BDEV_MODULE(error);
spdk_vbdev_register(&disk->disk, &base_bdev, 1);
TAILQ_INIT(&disk->pending_ios);
TAILQ_INSERT_TAIL(&g_vbdev_error_disks, disk, tailq);

View File

@ -50,6 +50,8 @@
#include "gpt.h"
SPDK_DECLARE_BDEV_MODULE(gpt);
/* Base block device gpt context */
struct spdk_gpt_bdev {
struct spdk_bdev_desc *bdev_desc;
@ -385,6 +387,7 @@ vbdev_gpt_create_bdevs(struct spdk_gpt_bdev *gpt_bdev)
d->disk.blockcnt = lba_end - lba_start;
d->disk.ctxt = d;
d->disk.fn_table = &vbdev_gpt_fn_table;
d->disk.module = SPDK_GET_BDEV_MODULE(gpt);
SPDK_TRACELOG(SPDK_TRACE_VBDEV_GPT, "gpt vbdev %s: base bdev: %s offset_bytes: "
"%" PRIu64 " offset_blocks: %" PRIu64 "\n",

View File

@ -422,6 +422,7 @@ struct spdk_bdev *create_malloc_disk(uint64_t num_blocks, uint32_t block_size)
mdisk->disk.ctxt = mdisk;
mdisk->disk.fn_table = &malloc_fn_table;
mdisk->disk.module = SPDK_GET_BDEV_MODULE(malloc);
spdk_bdev_register(&mdisk->disk);

View File

@ -43,6 +43,8 @@
#include "blockdev_null.h"
SPDK_DECLARE_BDEV_MODULE(null);
struct null_bdev {
struct spdk_bdev bdev;
TAILQ_ENTRY(null_bdev) tailq;
@ -156,6 +158,7 @@ create_null_bdev(const char *name, uint64_t num_blocks, uint32_t block_size)
bdev->bdev.ctxt = bdev;
bdev->bdev.fn_table = &null_fn_table;
bdev->bdev.module = SPDK_GET_BDEV_MODULE(null);
spdk_bdev_register(&bdev->bdev);

View File

@ -1066,6 +1066,7 @@ nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
bdev->disk.blockcnt = spdk_nvme_ns_get_num_sectors(ns);
bdev->disk.ctxt = bdev;
bdev->disk.fn_table = &nvmelib_fn_table;
bdev->disk.module = SPDK_GET_BDEV_MODULE(nvme);
spdk_bdev_register(&bdev->disk);
TAILQ_INSERT_TAIL(&g_nvme_bdevs, bdev, link);

View File

@ -537,6 +537,7 @@ spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block
rbd->disk.blockcnt = rbd->info.size / rbd->disk.blocklen;
rbd->disk.ctxt = rbd;
rbd->disk.fn_table = &rbd_fn_table;
rbd->disk.module = SPDK_GET_BDEV_MODULE(rbd);
SPDK_NOTICELOG("Add %s rbd disk to lun\n", rbd->disk.name);
TAILQ_INSERT_TAIL(&g_rbds, rbd, tailq);

View File

@ -47,6 +47,8 @@
#include "spdk_internal/bdev.h"
#include "spdk_internal/log.h"
SPDK_DECLARE_BDEV_MODULE(split);
/* Base block device split context */
struct split_base {
struct spdk_bdev *base_bdev;
@ -306,6 +308,7 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
d->disk.blockcnt = split_size_blocks;
d->disk.ctxt = d;
d->disk.fn_table = &vbdev_split_fn_table;
d->disk.module = SPDK_GET_BDEV_MODULE(split);
SPDK_TRACELOG(SPDK_TRACE_VBDEV_SPLIT, "Split vbdev %s: base bdev: %s offset_bytes: "
"%" PRIu64 " offset_blocks: %" PRIu64 "\n",

View File

@ -109,6 +109,9 @@ static struct spdk_bdev_fn_table fn_table = {
.destruct = stub_destruct,
};
SPDK_BDEV_MODULE_REGISTER(bdev_ut, NULL, NULL, NULL, NULL)
SPDK_VBDEV_MODULE_REGISTER(vbdev_ut, NULL, NULL, NULL, NULL, NULL)
static struct spdk_bdev *
allocate_bdev(char *name)
{
@ -119,6 +122,7 @@ allocate_bdev(char *name)
bdev->name = name;
bdev->fn_table = &fn_table;
bdev->module = SPDK_GET_BDEV_MODULE(bdev_ut);
spdk_bdev_register(bdev);
CU_ASSERT(TAILQ_EMPTY(&bdev->base_bdevs));
@ -138,6 +142,7 @@ allocate_vbdev(char *name, struct spdk_bdev *base1, struct spdk_bdev *base2)
bdev->name = name;
bdev->fn_table = &fn_table;
bdev->module = SPDK_GET_BDEV_MODULE(vbdev_ut);
/* vbdev must have at least one base bdev */
CU_ASSERT(base1 != NULL);