bdev: Consistently pass user context to fn_table calls

Some calls were passing bdev->ctxt, some calls just
bdev. In most of our implementations those are the
same pointer, but they aren't necessarily.

Change-Id: If2d19f9eef059aded10a917ffb270c1dc4a8dc41
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2017-04-04 14:10:00 -07:00 committed by Daniel Verkamp
parent 4f9f191c89
commit 9d73eed8a6
8 changed files with 40 additions and 38 deletions

View File

@ -129,16 +129,16 @@ struct spdk_bdev_module_if {
*/ */
struct spdk_bdev_fn_table { struct spdk_bdev_fn_table {
/** Destroy the backend block device object */ /** Destroy the backend block device object */
int (*destruct)(struct spdk_bdev *bdev); int (*destruct)(void *ctx);
/** Process the IO. */ /** Process the IO. */
void (*submit_request)(struct spdk_bdev_io *); void (*submit_request)(struct spdk_bdev_io *);
/** Check if the block device supports a specific I/O type. */ /** Check if the block device supports a specific I/O type. */
bool (*io_type_supported)(struct spdk_bdev *bdev, enum spdk_bdev_io_type); bool (*io_type_supported)(void *ctx, enum spdk_bdev_io_type);
/** Get an I/O channel for the specific bdev for the calling thread. */ /** Get an I/O channel for the specific bdev for the calling thread. */
struct spdk_io_channel *(*get_io_channel)(struct spdk_bdev *bdev, uint32_t priority); struct spdk_io_channel *(*get_io_channel)(void *ctx, uint32_t priority);
/** /**
* Output driver-specific configuration to a JSON stream. Optional - may be NULL. * Output driver-specific configuration to a JSON stream. Optional - may be NULL.
@ -147,7 +147,7 @@ struct spdk_bdev_fn_table {
* driver should write a name (based on the driver name) followed by a JSON value * driver should write a name (based on the driver name) followed by a JSON value
* (most likely another nested object). * (most likely another nested object).
*/ */
int (*dump_config_json)(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w); int (*dump_config_json)(void *ctx, struct spdk_json_write_ctx *w);
}; };
void spdk_bdev_register(struct spdk_bdev *bdev); void spdk_bdev_register(struct spdk_bdev *bdev);

View File

@ -160,9 +160,9 @@ blockdev_aio_flush(struct file_disk *fdisk, struct blockdev_aio_task *aio_task,
} }
static int static int
blockdev_aio_destruct(struct spdk_bdev *bdev) blockdev_aio_destruct(void *ctx)
{ {
struct file_disk *fdisk = (struct file_disk *)bdev; struct file_disk *fdisk = ctx;
int rc = 0; int rc = 0;
rc = blockdev_aio_close(fdisk); rc = blockdev_aio_close(fdisk);
@ -281,7 +281,7 @@ static void blockdev_aio_submit_request(struct spdk_bdev_io *bdev_io)
} }
static bool static bool
blockdev_aio_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) blockdev_aio_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
{ {
switch (io_type) { switch (io_type) {
case SPDK_BDEV_IO_TYPE_READ: case SPDK_BDEV_IO_TYPE_READ:
@ -320,9 +320,11 @@ blockdev_aio_destroy_cb(void *io_device, void *ctx_buf)
} }
static struct spdk_io_channel * static struct spdk_io_channel *
blockdev_aio_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) blockdev_aio_get_io_channel(void *ctx, uint32_t priority)
{ {
return spdk_get_io_channel(bdev, priority, false, NULL); struct file_disk *fdisk = ctx;
return spdk_get_io_channel(&fdisk->disk, priority, false, NULL);
} }
static const struct spdk_bdev_fn_table aio_fn_table = { static const struct spdk_bdev_fn_table aio_fn_table = {

View File

@ -56,7 +56,7 @@ struct blockdev_aio_io_channel {
}; };
struct file_disk { struct file_disk {
struct spdk_bdev disk; /* this must be first element */ struct spdk_bdev disk;
const char *file; const char *file;
int fd; int fd;
char disk_name[SPDK_BDEV_MAX_NAME_LENGTH]; char disk_name[SPDK_BDEV_MAX_NAME_LENGTH];

View File

@ -498,14 +498,14 @@ spdk_bdev_get_child_io(struct spdk_bdev_io *parent,
bool bool
spdk_bdev_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) spdk_bdev_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type)
{ {
return bdev->fn_table->io_type_supported(bdev, io_type); return bdev->fn_table->io_type_supported(bdev->ctxt, io_type);
} }
int int
spdk_bdev_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w) spdk_bdev_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w)
{ {
if (bdev->fn_table->dump_config_json) { if (bdev->fn_table->dump_config_json) {
return bdev->fn_table->dump_config_json(bdev, w); return bdev->fn_table->dump_config_json(bdev->ctxt, w);
} }
return 0; return 0;
@ -514,7 +514,7 @@ spdk_bdev_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w
struct spdk_io_channel * struct spdk_io_channel *
spdk_bdev_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) spdk_bdev_get_io_channel(struct spdk_bdev *bdev, uint32_t priority)
{ {
return bdev->fn_table->get_io_channel(bdev, priority); return bdev->fn_table->get_io_channel(bdev->ctxt, priority);
} }
static int static int

View File

@ -49,7 +49,7 @@
#define MALLOC_MAX_UNMAP_BDESC 1 #define MALLOC_MAX_UNMAP_BDESC 1
struct malloc_disk { struct malloc_disk {
struct spdk_bdev disk; /* this must be the first element */ struct spdk_bdev disk;
void *malloc_buf; void *malloc_buf;
struct malloc_disk *next; struct malloc_disk *next;
}; };
@ -126,9 +126,9 @@ blockdev_malloc_delete_from_list(struct malloc_disk *malloc_disk)
} }
static int static int
blockdev_malloc_destruct(struct spdk_bdev *bdev) blockdev_malloc_destruct(void *ctx)
{ {
struct malloc_disk *malloc_disk = (struct malloc_disk *)bdev; struct malloc_disk *malloc_disk = ctx;
blockdev_malloc_delete_from_list(malloc_disk); blockdev_malloc_delete_from_list(malloc_disk);
spdk_free(malloc_disk->malloc_buf); spdk_free(malloc_disk->malloc_buf);
spdk_free(malloc_disk); spdk_free(malloc_disk);
@ -336,7 +336,7 @@ static void blockdev_malloc_submit_request(struct spdk_bdev_io *bdev_io)
} }
static bool static bool
blockdev_malloc_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) blockdev_malloc_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
{ {
switch (io_type) { switch (io_type) {
case SPDK_BDEV_IO_TYPE_READ: case SPDK_BDEV_IO_TYPE_READ:
@ -352,7 +352,7 @@ blockdev_malloc_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type
} }
static struct spdk_io_channel * static struct spdk_io_channel *
blockdev_malloc_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) blockdev_malloc_get_io_channel(void *ctx, uint32_t priority)
{ {
return spdk_copy_engine_get_io_channel(priority); return spdk_copy_engine_get_io_channel(priority);
} }

View File

@ -197,9 +197,9 @@ bdev_nvme_poll_adminq(void *arg)
} }
static int static int
bdev_nvme_destruct(struct spdk_bdev *bdev) bdev_nvme_destruct(void *ctx)
{ {
struct nvme_bdev *nvme_disk = (struct nvme_bdev *)bdev; struct nvme_bdev *nvme_disk = ctx;
struct nvme_ctrlr *nvme_ctrlr = nvme_disk->nvme_ctrlr; struct nvme_ctrlr *nvme_ctrlr = nvme_disk->nvme_ctrlr;
pthread_mutex_lock(&g_bdev_nvme_mutex); pthread_mutex_lock(&g_bdev_nvme_mutex);
@ -321,9 +321,9 @@ bdev_nvme_submit_request(struct spdk_bdev_io *bdev_io)
} }
static bool static bool
bdev_nvme_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) bdev_nvme_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
{ {
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev; struct nvme_bdev *nbdev = ctx;
const struct spdk_nvme_ctrlr_data *cdata; const struct spdk_nvme_ctrlr_data *cdata;
switch (io_type) { switch (io_type) {
@ -369,17 +369,17 @@ bdev_nvme_destroy_cb(void *io_device, void *ctx_buf)
} }
static struct spdk_io_channel * static struct spdk_io_channel *
bdev_nvme_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) bdev_nvme_get_io_channel(void *ctx, uint32_t priority)
{ {
struct nvme_bdev *nvme_bdev = (struct nvme_bdev *)bdev; struct nvme_bdev *nvme_bdev = ctx;
return spdk_get_io_channel(nvme_bdev->nvme_ctrlr->ctrlr, priority, false, NULL); return spdk_get_io_channel(nvme_bdev->nvme_ctrlr->ctrlr, priority, false, NULL);
} }
static int static int
bdev_nvme_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w) bdev_nvme_dump_config_json(void *ctx, struct spdk_json_write_ctx *w)
{ {
struct nvme_bdev *nvme_bdev = (struct nvme_bdev *)bdev; struct nvme_bdev *nvme_bdev = ctx;
struct nvme_ctrlr *nvme_ctrlr = nvme_bdev->nvme_ctrlr; struct nvme_ctrlr *nvme_ctrlr = nvme_bdev->nvme_ctrlr;
const struct spdk_nvme_ctrlr_data *cdata; const struct spdk_nvme_ctrlr_data *cdata;
struct spdk_nvme_ns *ns; struct spdk_nvme_ns *ns;

View File

@ -254,7 +254,7 @@ blockdev_rbd_flush(struct blockdev_rbd *disk, struct spdk_io_channel *ch,
} }
static int static int
blockdev_rbd_destruct(struct spdk_bdev *bdev) blockdev_rbd_destruct(void *ctx)
{ {
return 0; return 0;
} }
@ -311,7 +311,7 @@ static void blockdev_rbd_submit_request(struct spdk_bdev_io *bdev_io)
} }
static bool static bool
blockdev_rbd_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) blockdev_rbd_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
{ {
switch (io_type) { switch (io_type) {
case SPDK_BDEV_IO_TYPE_READ: case SPDK_BDEV_IO_TYPE_READ:
@ -469,9 +469,9 @@ blockdev_rbd_destroy_cb(void *io_device, void *ctx_buf)
} }
static struct spdk_io_channel * static struct spdk_io_channel *
blockdev_rbd_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) blockdev_rbd_get_io_channel(void *ctx, uint32_t priority)
{ {
struct blockdev_rbd *rbd_bdev = (struct blockdev_rbd *)bdev; struct blockdev_rbd *rbd_bdev = ctx;
return spdk_get_io_channel(rbd_bdev, priority, false, NULL); return spdk_get_io_channel(rbd_bdev, priority, false, NULL);
} }

View File

@ -181,34 +181,34 @@ vbdev_split_free(struct split_disk *split_disk)
} }
static int static int
vbdev_split_destruct(struct spdk_bdev *bdev) vbdev_split_destruct(void *ctx)
{ {
struct split_disk *split_disk = (struct split_disk *)bdev; struct split_disk *split_disk = ctx;
vbdev_split_free(split_disk); vbdev_split_free(split_disk);
return 0; return 0;
} }
static bool static bool
vbdev_split_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) vbdev_split_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
{ {
struct split_disk *split_disk = (struct split_disk *)bdev; struct split_disk *split_disk = ctx;
return split_disk->base_bdev->fn_table->io_type_supported(split_disk->base_bdev, io_type); return split_disk->base_bdev->fn_table->io_type_supported(split_disk->base_bdev, io_type);
} }
static struct spdk_io_channel * static struct spdk_io_channel *
vbdev_split_get_io_channel(struct spdk_bdev *bdev, uint32_t priority) vbdev_split_get_io_channel(void *ctx, uint32_t priority)
{ {
struct split_disk *split_disk = (struct split_disk *)bdev; struct split_disk *split_disk = ctx;
return split_disk->base_bdev->fn_table->get_io_channel(split_disk->base_bdev, priority); return split_disk->base_bdev->fn_table->get_io_channel(split_disk->base_bdev, priority);
} }
static int static int
vbdev_split_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w) vbdev_split_dump_config_json(void *ctx, struct spdk_json_write_ctx *w)
{ {
struct split_disk *split_disk = (struct split_disk *)bdev; struct split_disk *split_disk = ctx;
spdk_json_write_name(w, "split"); spdk_json_write_name(w, "split");
spdk_json_write_object_begin(w); spdk_json_write_object_begin(w);