module/raid: implement func pointers for raid related functtions

Next patch will rename the relevant functions so it's clear they're
RAID 0.  This patch simply takes those functions which include RAID
specific mapping and assign them to existing functions via func
pointers in the RAID struct.

Change-Id: I8c7724d855937a9c1ca78cdb8ec500521f23b12d
Signed-off-by: paul luse <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467553
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
paul luse 2019-09-05 18:43:26 -04:00 committed by Jim Harris
parent 877d91755a
commit 576729ed29
2 changed files with 51 additions and 8 deletions

View File

@ -386,9 +386,9 @@ raid_bdev_io_submit_fail_process(struct raid_bdev *raid_bdev, struct spdk_bdev_i
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
} else {
/* Queue the IO to bdev layer wait queue */
pd_idx = get_curr_base_bdev_index(raid_bdev, raid_io);
pd_idx = raid_bdev->fn_table->get_curr_base_index(raid_bdev, raid_io);
raid_io->waitq_entry.bdev = raid_bdev->base_bdev_info[pd_idx].bdev;
raid_io->waitq_entry.cb_fn = raid_bdev_waitq_io_process;
raid_io->waitq_entry.cb_fn = raid_bdev->fn_table->waitq_io_process;
raid_io->waitq_entry.cb_arg = raid_io;
raid_ch = spdk_io_channel_get_ctx(raid_io->ch);
if (spdk_bdev_queue_io_wait(raid_bdev->base_bdev_info[pd_idx].bdev,
@ -707,9 +707,9 @@ _raid_bdev_submit_null_payload_request_next(void *_bdev_io)
raid_io = (struct raid_bdev_io *)bdev_io->driver_ctx;
raid_ch = spdk_io_channel_get_ctx(raid_io->ch);
_raid_bdev_get_io_range(&io_range, raid_bdev->num_base_bdevs,
raid_bdev->strip_size, raid_bdev->strip_size_shift,
bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks);
raid_bdev->fn_table->get_io_range(&io_range, raid_bdev->num_base_bdevs,
raid_bdev->strip_size, raid_bdev->strip_size_shift,
bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks);
raid_io->base_bdev_io_expected = io_range.n_disks_involved;
@ -723,7 +723,7 @@ _raid_bdev_submit_null_payload_request_next(void *_bdev_io)
*/
disk_idx = (io_range.start_disk + raid_io->base_bdev_io_submitted) % raid_bdev->num_base_bdevs;
_raid_bdev_split_io_range(&io_range, disk_idx, &offset_in_disk, &nblocks_in_disk);
raid_bdev->fn_table->split_io_range(&io_range, disk_idx, &offset_in_disk, &nblocks_in_disk);
switch (bdev_io->type) {
case SPDK_BDEV_IO_TYPE_UNMAP:
@ -797,12 +797,16 @@ static void
raid_bdev_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
bool success)
{
struct raid_bdev *raid_bdev;
raid_bdev = (struct raid_bdev *)bdev_io->bdev->ctxt;
if (!success) {
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
return;
}
raid_bdev_start_rw_request(ch, bdev_io);
raid_bdev->fn_table->start_rw_request(ch, bdev_io);
}
/*
@ -819,13 +823,17 @@ raid_bdev_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
static void
raid_bdev_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
{
struct raid_bdev *raid_bdev;
raid_bdev = (struct raid_bdev *)bdev_io->bdev->ctxt;
switch (bdev_io->type) {
case SPDK_BDEV_IO_TYPE_READ:
spdk_bdev_io_get_buf(bdev_io, raid_bdev_get_buf_cb,
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen);
break;
case SPDK_BDEV_IO_TYPE_WRITE:
raid_bdev_start_rw_request(ch, bdev_io);
raid_bdev->fn_table->start_rw_request(ch, bdev_io);
break;
case SPDK_BDEV_IO_TYPE_RESET:
@ -1505,6 +1513,14 @@ raid_bdev_init(void)
return 0;
}
static const struct raid_fn_table g_raid0_fn_table = {
.start_rw_request = raid_bdev_start_rw_request,
.get_curr_base_index = get_curr_base_bdev_index,
.waitq_io_process = raid_bdev_waitq_io_process,
.get_io_range = _raid_bdev_get_io_range,
.split_io_range = _raid_bdev_split_io_range,
};
/*
* brief:
* raid_bdev_create allocates raid bdev based on passed configuration
@ -1543,6 +1559,17 @@ raid_bdev_create(struct raid_bdev_config *raid_cfg)
raid_bdev->strip_size_kb = raid_cfg->strip_size;
raid_bdev->state = RAID_BDEV_STATE_CONFIGURING;
raid_bdev->config = raid_cfg;
raid_bdev->raid_level = raid_cfg->raid_level;
switch (raid_bdev->raid_level) {
case 0:
raid_bdev->fn_table = &g_raid0_fn_table;
break;
default:
SPDK_ERRLOG("invalid raid level %u\n", raid_bdev->raid_level);
free(raid_bdev);
return -ENOMEM;
}
raid_bdev_gen = &raid_bdev->bdev;

View File

@ -110,6 +110,19 @@ struct raid_bdev_io_range {
uint8_t n_disks_involved;
};
struct raid_bdev;
struct raid_fn_table {
void (*start_rw_request)(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io);
void (*waitq_io_process)(void *ctx);
uint8_t (*get_curr_base_index)(struct raid_bdev *raid_bdev, struct raid_bdev_io *raid_io);
void (*get_io_range)(struct raid_bdev_io_range *io_range,
uint8_t num_base_bdevs, uint64_t strip_size, uint64_t strip_size_shift,
uint64_t offset_blocks, uint64_t num_blocks);
void (*split_io_range)(struct raid_bdev_io_range *io_range, uint8_t disk_idx,
uint64_t *_offset_in_disk, uint64_t *_nblocks_in_disk);
};
/*
* raid_bdev is the single entity structure which contains SPDK block device
* and the information related to any raid bdev either configured or
@ -160,6 +173,9 @@ struct raid_bdev {
/* Set to true if destroy of this raid bdev is started. */
bool destroy_started;
/* function table for RAID operations */
const struct raid_fn_table *fn_table;
};
/*