bdev: convert bdev module APIs to use blocks
The bdev modules now take all read, write, unmap, and flush requests in terms of blocks rather than bytes. The public bdev APIs still accept offset and length in bytes for now. Change-Id: I57f0955d52272f57755f0ff4dbc56721fdc2ef51 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/376037 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
parent
7987a7b243
commit
7394f69054
@ -273,10 +273,10 @@ struct spdk_bdev_io {
|
||||
int iovcnt;
|
||||
|
||||
/** Total size of data to be transferred. */
|
||||
size_t len;
|
||||
uint64_t num_blocks;
|
||||
|
||||
/** Starting offset (in bytes) of the bdev for this I/O. */
|
||||
uint64_t offset;
|
||||
/** Starting offset (in blocks) of the bdev for this I/O. */
|
||||
uint64_t offset_blocks;
|
||||
} read;
|
||||
struct {
|
||||
/** For basic write case, use our own iovec element */
|
||||
@ -289,24 +289,24 @@ struct spdk_bdev_io {
|
||||
int iovcnt;
|
||||
|
||||
/** Total size of data to be transferred. */
|
||||
size_t len;
|
||||
uint64_t num_blocks;
|
||||
|
||||
/** Starting offset (in bytes) of the bdev for this I/O. */
|
||||
uint64_t offset;
|
||||
/** Starting offset (in blocks) of the bdev for this I/O. */
|
||||
uint64_t offset_blocks;
|
||||
} write;
|
||||
struct {
|
||||
/** Total size of region to be unmapped. */
|
||||
uint64_t len;
|
||||
uint64_t num_blocks;
|
||||
|
||||
/** Starting offset (in bytes) of the bdev for this I/O. */
|
||||
uint64_t offset;
|
||||
/** Starting offset (in blocks) of the bdev for this I/O. */
|
||||
uint64_t offset_blocks;
|
||||
} unmap;
|
||||
struct {
|
||||
/** Represents starting offset in bytes of the range to be flushed. */
|
||||
uint64_t offset;
|
||||
/** Represents starting offset in blocks of the range to be flushed. */
|
||||
uint64_t offset_blocks;
|
||||
|
||||
/** Represents the number of bytes to be flushed, starting at offset. */
|
||||
uint64_t len;
|
||||
/** Represents the number of blocks to be flushed, starting at offset_blocks. */
|
||||
uint64_t num_blocks;
|
||||
} flush;
|
||||
struct {
|
||||
/* The NVMe command to execute */
|
||||
|
@ -236,8 +236,8 @@ static void bdev_aio_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io
|
||||
(struct bdev_aio_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.read.iovs,
|
||||
bdev_io->u.read.iovcnt,
|
||||
bdev_io->u.read.len,
|
||||
bdev_io->u.read.offset);
|
||||
bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.read.offset_blocks * bdev_io->bdev->blocklen);
|
||||
}
|
||||
|
||||
static int _bdev_aio_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
@ -253,14 +253,14 @@ static int _bdev_aio_submit_request(struct spdk_io_channel *ch, struct spdk_bdev
|
||||
(struct bdev_aio_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.write.iovs,
|
||||
bdev_io->u.write.iovcnt,
|
||||
bdev_io->u.write.len,
|
||||
bdev_io->u.write.offset);
|
||||
bdev_io->u.write.num_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.write.offset_blocks * bdev_io->bdev->blocklen);
|
||||
return 0;
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
bdev_aio_flush((struct file_disk *)bdev_io->bdev->ctxt,
|
||||
(struct bdev_aio_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.flush.offset,
|
||||
bdev_io->u.flush.len);
|
||||
bdev_io->u.flush.offset_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.flush.num_blocks * bdev_io->bdev->blocklen);
|
||||
return 0;
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_RESET:
|
||||
|
@ -223,7 +223,7 @@ spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf)
|
||||
|
||||
bdev_io->buf = buf;
|
||||
bdev_io->u.read.iovs[0].iov_base = (void *)((unsigned long)((char *)buf + 512) & ~511UL);
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.len;
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen;
|
||||
bdev_io->get_buf_cb(bdev_io->ch->channel, bdev_io);
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
||||
|
||||
assert(bdev_io->u.read.iovcnt == 1);
|
||||
|
||||
length = bdev_io->u.read.len;
|
||||
length = bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen;
|
||||
buf = bdev_io->buf;
|
||||
|
||||
ch = spdk_io_channel_get_ctx(bdev_io->ch->mgmt_channel);
|
||||
@ -264,7 +264,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
||||
void
|
||||
spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb)
|
||||
{
|
||||
uint64_t len = bdev_io->u.read.len;
|
||||
uint64_t len = bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen;
|
||||
struct spdk_mempool *pool;
|
||||
need_buf_tailq_t *tailq;
|
||||
void *buf = NULL;
|
||||
@ -833,8 +833,8 @@ spdk_bdev_read(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
bdev_io->u.read.iov.iov_len = nbytes;
|
||||
bdev_io->u.read.iovs = &bdev_io->u.read.iov;
|
||||
bdev_io->u.read.iovcnt = 1;
|
||||
bdev_io->u.read.len = nbytes;
|
||||
bdev_io->u.read.offset = offset;
|
||||
bdev_io->u.read.num_blocks = nbytes / bdev->blocklen;
|
||||
bdev_io->u.read.offset_blocks = offset / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -871,8 +871,8 @@ spdk_bdev_readv(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
bdev_io->u.read.iovs = iov;
|
||||
bdev_io->u.read.iovcnt = iovcnt;
|
||||
bdev_io->u.read.len = nbytes;
|
||||
bdev_io->u.read.offset = offset;
|
||||
bdev_io->u.read.num_blocks = nbytes / bdev->blocklen;
|
||||
bdev_io->u.read.offset_blocks = offset / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -914,8 +914,8 @@ spdk_bdev_write(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
bdev_io->u.write.iov.iov_len = nbytes;
|
||||
bdev_io->u.write.iovs = &bdev_io->u.write.iov;
|
||||
bdev_io->u.write.iovcnt = 1;
|
||||
bdev_io->u.write.len = nbytes;
|
||||
bdev_io->u.write.offset = offset;
|
||||
bdev_io->u.write.num_blocks = nbytes / bdev->blocklen;
|
||||
bdev_io->u.write.offset_blocks = offset / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -956,8 +956,8 @@ spdk_bdev_writev(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
bdev_io->u.write.iovs = iov;
|
||||
bdev_io->u.write.iovcnt = iovcnt;
|
||||
bdev_io->u.write.len = len;
|
||||
bdev_io->u.write.offset = offset;
|
||||
bdev_io->u.write.num_blocks = len / bdev->blocklen;
|
||||
bdev_io->u.write.offset_blocks = offset / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -990,8 +990,8 @@ spdk_bdev_write_zeroes(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
}
|
||||
|
||||
bdev_io->ch = channel;
|
||||
bdev_io->u.write.len = len;
|
||||
bdev_io->u.write.offset = offset;
|
||||
bdev_io->u.write.num_blocks = len / bdev->blocklen;
|
||||
bdev_io->u.write.offset_blocks = offset / bdev->blocklen;
|
||||
bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE_ZEROES;
|
||||
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
@ -1036,8 +1036,8 @@ spdk_bdev_unmap(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
|
||||
bdev_io->ch = channel;
|
||||
bdev_io->type = SPDK_BDEV_IO_TYPE_UNMAP;
|
||||
bdev_io->u.unmap.offset = offset;
|
||||
bdev_io->u.unmap.len = nbytes;
|
||||
bdev_io->u.unmap.offset_blocks = offset / bdev->blocklen;
|
||||
bdev_io->u.unmap.num_blocks = nbytes / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -1071,8 +1071,8 @@ spdk_bdev_flush(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
|
||||
bdev_io->ch = channel;
|
||||
bdev_io->type = SPDK_BDEV_IO_TYPE_FLUSH;
|
||||
bdev_io->u.flush.offset = offset;
|
||||
bdev_io->u.flush.len = length;
|
||||
bdev_io->u.flush.offset_blocks = offset / bdev->blocklen;
|
||||
bdev_io->u.flush.num_blocks = length / bdev->blocklen;
|
||||
spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);
|
||||
|
||||
rc = spdk_bdev_io_submit(bdev_io);
|
||||
@ -1308,11 +1308,11 @@ spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status sta
|
||||
if (status == SPDK_BDEV_IO_STATUS_SUCCESS) {
|
||||
switch (bdev_io->type) {
|
||||
case SPDK_BDEV_IO_TYPE_READ:
|
||||
bdev_io->ch->stat.bytes_read += bdev_io->u.read.len;
|
||||
bdev_io->ch->stat.bytes_read += bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen;
|
||||
bdev_io->ch->stat.num_read_ops++;
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||
bdev_io->ch->stat.bytes_written += bdev_io->u.write.len;
|
||||
bdev_io->ch->stat.bytes_written += bdev_io->u.write.num_blocks * bdev_io->bdev->blocklen;
|
||||
bdev_io->ch->stat.num_write_ops++;
|
||||
break;
|
||||
default:
|
||||
|
@ -67,7 +67,6 @@ struct gpt_partition_disk {
|
||||
uint32_t partition_index;
|
||||
struct spdk_gpt_bdev *gpt_base;
|
||||
uint64_t offset_blocks;
|
||||
uint64_t offset_bytes;
|
||||
TAILQ_ENTRY(gpt_partition_disk) tailq;
|
||||
};
|
||||
|
||||
@ -159,25 +158,25 @@ spdk_gpt_base_bdev_init(struct spdk_bdev *bdev)
|
||||
static void
|
||||
gpt_read(struct gpt_partition_disk *gpt_partition_disk, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
bdev_io->u.read.offset += gpt_partition_disk->offset_bytes;
|
||||
bdev_io->u.read.offset_blocks += gpt_partition_disk->offset_blocks;
|
||||
}
|
||||
|
||||
static void
|
||||
gpt_write(struct gpt_partition_disk *gpt_partition_disk, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
bdev_io->u.write.offset += gpt_partition_disk->offset_bytes;
|
||||
bdev_io->u.write.offset_blocks += gpt_partition_disk->offset_blocks;
|
||||
}
|
||||
|
||||
static void
|
||||
gpt_unmap(struct gpt_partition_disk *gpt_partition_disk, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
bdev_io->u.unmap.offset += gpt_partition_disk->offset_bytes;
|
||||
bdev_io->u.unmap.offset_blocks += gpt_partition_disk->offset_blocks;
|
||||
}
|
||||
|
||||
static void
|
||||
gpt_flush(struct gpt_partition_disk *gpt_partition_disk, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
bdev_io->u.flush.offset += gpt_partition_disk->offset_bytes;
|
||||
bdev_io->u.flush.offset_blocks += gpt_partition_disk->offset_blocks;
|
||||
}
|
||||
|
||||
|
||||
@ -403,16 +402,15 @@ vbdev_gpt_create_bdevs(struct spdk_gpt_bdev *gpt_bdev)
|
||||
d->partition_index = i;
|
||||
d->disk.product_name = "GPT Disk";
|
||||
d->base_bdev = base_bdev;
|
||||
d->offset_bytes = lba_start * gpt->sector_size;
|
||||
d->offset_blocks = lba_start;
|
||||
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_DEBUGLOG(SPDK_TRACE_VBDEV_GPT, "gpt vbdev %s: base bdev: %s offset_bytes: "
|
||||
"%" PRIu64 " offset_blocks: %" PRIu64 "\n",
|
||||
d->disk.name, spdk_bdev_get_name(base_bdev), d->offset_bytes, d->offset_blocks);
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_VBDEV_GPT, "gpt vbdev %s: base bdev: %s"
|
||||
" offset_blocks: %" PRIu64 "\n",
|
||||
d->disk.name, spdk_bdev_get_name(base_bdev), d->offset_blocks);
|
||||
|
||||
vbdev_gpt_base_get_ref(gpt_bdev, d);
|
||||
|
||||
|
@ -236,16 +236,6 @@ bdev_malloc_unmap(struct malloc_disk *mdisk,
|
||||
uint64_t offset,
|
||||
uint64_t byte_count)
|
||||
{
|
||||
uint64_t lba;
|
||||
uint32_t block_count;
|
||||
|
||||
lba = offset / mdisk->disk.blocklen;
|
||||
block_count = byte_count / mdisk->disk.blocklen;
|
||||
|
||||
if (lba >= mdisk->disk.blockcnt || block_count > mdisk->disk.blockcnt - lba) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
task->status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
task->num_outstanding = 1;
|
||||
|
||||
@ -272,14 +262,16 @@ bdev_malloc_reset(struct malloc_disk *mdisk, struct malloc_task *task)
|
||||
|
||||
static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
uint32_t block_size = bdev_io->bdev->blocklen;
|
||||
|
||||
switch (bdev_io->type) {
|
||||
case SPDK_BDEV_IO_TYPE_READ:
|
||||
if (bdev_io->u.read.iovs[0].iov_base == NULL) {
|
||||
assert(bdev_io->u.read.iovcnt == 1);
|
||||
bdev_io->u.read.iovs[0].iov_base =
|
||||
((struct malloc_disk *)bdev_io->bdev->ctxt)->malloc_buf +
|
||||
bdev_io->u.read.offset;
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.len;
|
||||
bdev_io->u.read.offset_blocks * block_size;
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.num_blocks * block_size;
|
||||
spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bdev_io->driver_ctx),
|
||||
SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
return 0;
|
||||
@ -290,8 +282,8 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.read.iovs,
|
||||
bdev_io->u.read.iovcnt,
|
||||
bdev_io->u.read.len,
|
||||
bdev_io->u.read.offset);
|
||||
bdev_io->u.read.num_blocks * block_size,
|
||||
bdev_io->u.read.offset_blocks * block_size);
|
||||
return 0;
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||
@ -300,8 +292,8 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.write.iovs,
|
||||
bdev_io->u.write.iovcnt,
|
||||
bdev_io->u.write.len,
|
||||
bdev_io->u.write.offset);
|
||||
bdev_io->u.write.num_blocks * block_size,
|
||||
bdev_io->u.write.offset_blocks * block_size);
|
||||
return 0;
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_RESET:
|
||||
@ -311,23 +303,23 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
return bdev_malloc_flush((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.flush.offset,
|
||||
bdev_io->u.flush.len);
|
||||
bdev_io->u.flush.offset_blocks * block_size,
|
||||
bdev_io->u.flush.num_blocks * block_size);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_UNMAP:
|
||||
return bdev_malloc_unmap((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.unmap.offset,
|
||||
bdev_io->u.unmap.len);
|
||||
bdev_io->u.unmap.offset_blocks * block_size,
|
||||
bdev_io->u.unmap.num_blocks * block_size);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
||||
/* bdev_malloc_unmap is implemented with a call to mem_cpy_fill which zeroes out all of the requested bytes. */
|
||||
return bdev_malloc_unmap((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.write.offset,
|
||||
bdev_io->u.write.len);
|
||||
bdev_io->u.write.offset_blocks * block_size,
|
||||
bdev_io->u.write.num_blocks * block_size);
|
||||
|
||||
default:
|
||||
return -1;
|
||||
|
@ -79,7 +79,7 @@ bdev_null_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
|
||||
if (bdev_io->u.read.iovs[0].iov_base == NULL) {
|
||||
assert(bdev_io->u.read.iovcnt == 1);
|
||||
bdev_io->u.read.iovs[0].iov_base = g_null_read_buf;
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.len;
|
||||
bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen;
|
||||
}
|
||||
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
break;
|
||||
|
@ -139,8 +139,8 @@ static int bdev_nvme_library_init(void);
|
||||
static void bdev_nvme_library_fini(void);
|
||||
static int bdev_nvme_queue_cmd(struct nvme_bdev *bdev, struct spdk_nvme_qpair *qpair,
|
||||
struct nvme_bdev_io *bio,
|
||||
int direction, struct iovec *iov, int iovcnt, uint64_t nbytes,
|
||||
uint64_t offset);
|
||||
int direction, struct iovec *iov, int iovcnt, uint64_t lba_count,
|
||||
uint64_t lba);
|
||||
static int bdev_nvme_admin_passthru(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
|
||||
struct nvme_bdev_io *bio,
|
||||
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
|
||||
@ -161,29 +161,29 @@ SPDK_BDEV_MODULE_REGISTER(nvme, bdev_nvme_library_init, bdev_nvme_library_fini,
|
||||
static int
|
||||
bdev_nvme_readv(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
|
||||
struct nvme_bdev_io *bio,
|
||||
struct iovec *iov, int iovcnt, uint64_t nbytes, uint64_t offset)
|
||||
struct iovec *iov, int iovcnt, uint64_t lba_count, uint64_t lba)
|
||||
{
|
||||
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_BDEV_NVME, "read %lu bytes with offset %#lx\n",
|
||||
nbytes, offset);
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_BDEV_NVME, "read %lu blocks with offset %#lx\n",
|
||||
lba_count, lba);
|
||||
|
||||
return bdev_nvme_queue_cmd(nbdev, nvme_ch->qpair, bio, BDEV_DISK_READ,
|
||||
iov, iovcnt, nbytes, offset);
|
||||
iov, iovcnt, lba_count, lba);
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_nvme_writev(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
|
||||
struct nvme_bdev_io *bio,
|
||||
struct iovec *iov, int iovcnt, size_t len, uint64_t offset)
|
||||
struct iovec *iov, int iovcnt, uint64_t lba_count, uint64_t lba)
|
||||
{
|
||||
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_BDEV_NVME, "write %lu bytes with offset %#lx\n",
|
||||
len, offset);
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_BDEV_NVME, "write %lu blocks with offset %#lx\n",
|
||||
lba_count, lba);
|
||||
|
||||
return bdev_nvme_queue_cmd(nbdev, nvme_ch->qpair, bio, BDEV_DISK_WRITE,
|
||||
iov, iovcnt, len, offset);
|
||||
iov, iovcnt, lba_count, lba);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -332,8 +332,8 @@ bdev_nvme_reset(struct nvme_bdev *nbdev, struct nvme_bdev_io *bio)
|
||||
static int
|
||||
bdev_nvme_unmap(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
|
||||
struct nvme_bdev_io *bio,
|
||||
uint64_t offset,
|
||||
uint64_t nbytes);
|
||||
uint64_t offset_blocks,
|
||||
uint64_t num_blocks);
|
||||
|
||||
static void
|
||||
bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
@ -345,8 +345,8 @@ bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
||||
bdev_io->u.read.iovs,
|
||||
bdev_io->u.read.iovcnt,
|
||||
bdev_io->u.read.len,
|
||||
bdev_io->u.read.offset);
|
||||
bdev_io->u.read.num_blocks,
|
||||
bdev_io->u.read.offset_blocks);
|
||||
|
||||
if (ret < 0) {
|
||||
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
||||
@ -373,22 +373,22 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
|
||||
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
||||
bdev_io->u.write.iovs,
|
||||
bdev_io->u.write.iovcnt,
|
||||
bdev_io->u.write.len,
|
||||
bdev_io->u.write.offset);
|
||||
bdev_io->u.write.num_blocks,
|
||||
bdev_io->u.write.offset_blocks);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
||||
return bdev_nvme_unmap((struct nvme_bdev *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
||||
bdev_io->u.write.len,
|
||||
bdev_io->u.write.offset);
|
||||
bdev_io->u.write.num_blocks,
|
||||
bdev_io->u.write.offset_blocks);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_UNMAP:
|
||||
return bdev_nvme_unmap((struct nvme_bdev *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
||||
bdev_io->u.unmap.offset,
|
||||
bdev_io->u.unmap.len);
|
||||
bdev_io->u.unmap.offset_blocks,
|
||||
bdev_io->u.unmap.num_blocks);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_RESET:
|
||||
return bdev_nvme_reset((struct nvme_bdev *)bdev_io->bdev->ctxt,
|
||||
@ -397,8 +397,8 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
return bdev_nvme_flush((struct nvme_bdev *)bdev_io->bdev->ctxt,
|
||||
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
||||
bdev_io->u.flush.offset,
|
||||
bdev_io->u.flush.len);
|
||||
bdev_io->u.flush.offset_blocks,
|
||||
bdev_io->u.flush.num_blocks);
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_NVME_ADMIN:
|
||||
return bdev_nvme_admin_passthru((struct nvme_bdev *)bdev_io->bdev->ctxt,
|
||||
@ -1222,11 +1222,9 @@ bdev_nvme_queued_next_sge(void *ref, void **address, uint32_t *length)
|
||||
static int
|
||||
bdev_nvme_queue_cmd(struct nvme_bdev *bdev, struct spdk_nvme_qpair *qpair,
|
||||
struct nvme_bdev_io *bio,
|
||||
int direction, struct iovec *iov, int iovcnt, uint64_t nbytes,
|
||||
uint64_t offset)
|
||||
int direction, struct iovec *iov, int iovcnt, uint64_t lba_count,
|
||||
uint64_t lba)
|
||||
{
|
||||
uint32_t lba_count = nbytes / bdev->disk.blocklen;
|
||||
uint64_t lba = offset / bdev->disk.blocklen;
|
||||
int rc;
|
||||
|
||||
bio->iovs = iov;
|
||||
@ -1253,15 +1251,15 @@ bdev_nvme_queue_cmd(struct nvme_bdev *bdev, struct spdk_nvme_qpair *qpair,
|
||||
static int
|
||||
bdev_nvme_unmap(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
|
||||
struct nvme_bdev_io *bio,
|
||||
uint64_t offset,
|
||||
uint64_t nbytes)
|
||||
uint64_t offset_blocks,
|
||||
uint64_t num_blocks)
|
||||
{
|
||||
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
||||
int rc = 0;
|
||||
struct spdk_nvme_dsm_range dsm_range = {};
|
||||
|
||||
dsm_range.starting_lba = offset / nbdev->disk.blocklen;
|
||||
dsm_range.length = nbytes / nbdev->disk.blocklen;
|
||||
dsm_range.starting_lba = offset_blocks;
|
||||
dsm_range.length = num_blocks;
|
||||
|
||||
rc = spdk_nvme_ns_cmd_dataset_management(nbdev->ns, nvme_ch->qpair,
|
||||
SPDK_NVME_DSM_ATTR_DEALLOCATE,
|
||||
|
@ -260,8 +260,8 @@ static void bdev_rbd_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io
|
||||
bdev_io,
|
||||
bdev_io->u.read.iovs,
|
||||
bdev_io->u.read.iovcnt,
|
||||
bdev_io->u.read.len,
|
||||
bdev_io->u.read.offset);
|
||||
bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.read.offset_blocks * bdev_io->bdev->blocklen);
|
||||
|
||||
if (ret != 0) {
|
||||
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
||||
@ -281,14 +281,14 @@ static int _bdev_rbd_submit_request(struct spdk_io_channel *ch, struct spdk_bdev
|
||||
bdev_io,
|
||||
bdev_io->u.write.iovs,
|
||||
bdev_io->u.write.iovcnt,
|
||||
bdev_io->u.write.len,
|
||||
bdev_io->u.write.offset);
|
||||
bdev_io->u.write.num_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.write.offset_blocks * bdev_io->bdev->blocklen);
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
return bdev_rbd_flush((struct bdev_rbd *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
bdev_io,
|
||||
bdev_io->u.flush.offset,
|
||||
bdev_io->u.flush.len);
|
||||
bdev_io->u.flush.offset_blocks * bdev_io->bdev->blocklen,
|
||||
bdev_io->u.flush.num_blocks * bdev_io->bdev->blocklen);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -337,7 +337,7 @@ bdev_rbd_io_poll(void *arg)
|
||||
bdev_io = rbd_aio_get_arg(comps[i]);
|
||||
io_status = rbd_aio_get_return_value(comps[i]);
|
||||
if (bdev_io->type == SPDK_BDEV_IO_TYPE_READ) {
|
||||
if ((int)bdev_io->u.read.len == io_status) {
|
||||
if ((int)(bdev_io->u.read.num_blocks * bdev_io->bdev->blocklen) == io_status) {
|
||||
status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
} else {
|
||||
status = SPDK_BDEV_IO_STATUS_FAILED;
|
||||
|
@ -62,7 +62,6 @@ struct split_disk {
|
||||
struct spdk_bdev disk;
|
||||
struct split_base *base;
|
||||
uint64_t offset_blocks;
|
||||
uint64_t offset_bytes;
|
||||
TAILQ_ENTRY(split_disk) tailq;
|
||||
};
|
||||
|
||||
@ -90,33 +89,36 @@ vbdev_split_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev
|
||||
struct split_disk *split_disk = split_ch->disk;
|
||||
struct spdk_io_channel *base_ch = split_ch->base_ch;
|
||||
struct spdk_bdev_desc *base_desc = split_disk->base->desc;
|
||||
uint64_t offset;
|
||||
uint32_t block_size = split_disk->disk.blocklen;
|
||||
uint64_t offset_blocks;
|
||||
int rc = 0;
|
||||
|
||||
/* Modify the I/O to adjust for the offset within the base bdev. */
|
||||
switch (bdev_io->type) {
|
||||
case SPDK_BDEV_IO_TYPE_READ:
|
||||
offset = bdev_io->u.read.offset + split_disk->offset_bytes;
|
||||
offset_blocks = bdev_io->u.read.offset_blocks + split_disk->offset_blocks;
|
||||
rc = spdk_bdev_readv(base_desc, base_ch, bdev_io->u.read.iovs,
|
||||
bdev_io->u.read.iovcnt, offset,
|
||||
bdev_io->u.read.len, vbdev_split_complete_io,
|
||||
bdev_io->u.read.iovcnt, offset_blocks * block_size,
|
||||
bdev_io->u.read.num_blocks * block_size, vbdev_split_complete_io,
|
||||
bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||
offset = bdev_io->u.write.offset + split_disk->offset_bytes;
|
||||
offset_blocks = bdev_io->u.write.offset_blocks + split_disk->offset_blocks;
|
||||
rc = spdk_bdev_writev(base_desc, base_ch, bdev_io->u.write.iovs,
|
||||
bdev_io->u.write.iovcnt, offset,
|
||||
bdev_io->u.write.len, vbdev_split_complete_io,
|
||||
bdev_io->u.write.iovcnt, offset_blocks * block_size,
|
||||
bdev_io->u.write.num_blocks * block_size, vbdev_split_complete_io,
|
||||
bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_UNMAP:
|
||||
offset = bdev_io->u.unmap.offset + split_disk->offset_bytes;
|
||||
rc = spdk_bdev_unmap(base_desc, base_ch, offset, bdev_io->u.unmap.len,
|
||||
offset_blocks = bdev_io->u.unmap.offset_blocks + split_disk->offset_blocks;
|
||||
rc = spdk_bdev_unmap(base_desc, base_ch, offset_blocks * block_size,
|
||||
bdev_io->u.unmap.num_blocks * block_size,
|
||||
vbdev_split_complete_io, bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
offset = bdev_io->u.flush.offset + split_disk->offset_bytes;
|
||||
rc = spdk_bdev_flush(base_desc, base_ch, offset, bdev_io->u.flush.len,
|
||||
offset_blocks = bdev_io->u.flush.offset_blocks + split_disk->offset_blocks;
|
||||
rc = spdk_bdev_flush(base_desc, base_ch, offset_blocks * block_size,
|
||||
bdev_io->u.flush.num_blocks * block_size,
|
||||
vbdev_split_complete_io, bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_RESET:
|
||||
@ -270,7 +272,7 @@ split_channel_destroy_cb(void *io_device, void *ctx_buf)
|
||||
static int
|
||||
vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t split_size_mb)
|
||||
{
|
||||
uint64_t split_size_bytes, split_size_blocks, offset_bytes, offset_blocks;
|
||||
uint64_t split_size_blocks, offset_blocks;
|
||||
uint64_t max_split_count;
|
||||
uint64_t mb = 1024 * 1024;
|
||||
uint64_t i;
|
||||
@ -292,8 +294,6 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_VBDEV_SPLIT, "Split size not specified by user\n");
|
||||
}
|
||||
|
||||
split_size_bytes = split_size_blocks * base_bdev->blocklen;
|
||||
|
||||
max_split_count = base_bdev->blockcnt / split_size_blocks;
|
||||
if (split_count > max_split_count) {
|
||||
SPDK_WARNLOG("Split count %" PRIu64 " is greater than maximum possible split count "
|
||||
@ -302,8 +302,8 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
|
||||
}
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_VBDEV_SPLIT, "base_bdev: %s split_count: %" PRIu64
|
||||
" split_size_bytes: %" PRIu64 "\n",
|
||||
spdk_bdev_get_name(base_bdev), split_count, split_size_bytes);
|
||||
" split_size_blocks: %" PRIu64 "\n",
|
||||
spdk_bdev_get_name(base_bdev), split_count, split_size_blocks);
|
||||
|
||||
split_base = calloc(1, sizeof(*split_base));
|
||||
if (!split_base) {
|
||||
@ -329,7 +329,6 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset_bytes = 0;
|
||||
offset_blocks = 0;
|
||||
for (i = 0; i < split_count; i++) {
|
||||
struct split_disk *d;
|
||||
@ -354,16 +353,15 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
|
||||
goto cleanup;
|
||||
}
|
||||
d->disk.product_name = "Split Disk";
|
||||
d->offset_bytes = offset_bytes;
|
||||
d->offset_blocks = offset_blocks;
|
||||
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_DEBUGLOG(SPDK_TRACE_VBDEV_SPLIT, "Split vbdev %s: base bdev: %s offset_bytes: "
|
||||
"%" PRIu64 " offset_blocks: %" PRIu64 "\n",
|
||||
d->disk.name, spdk_bdev_get_name(base_bdev), d->offset_bytes, d->offset_blocks);
|
||||
SPDK_DEBUGLOG(SPDK_TRACE_VBDEV_SPLIT, "Split vbdev %s: base bdev: %s"
|
||||
" offset_blocks: %" PRIu64 "\n",
|
||||
d->disk.name, spdk_bdev_get_name(base_bdev), d->offset_blocks);
|
||||
|
||||
vbdev_split_base_get_ref(split_base, d);
|
||||
|
||||
@ -374,7 +372,6 @@ vbdev_split_create(struct spdk_bdev *base_bdev, uint64_t split_count, uint64_t s
|
||||
|
||||
TAILQ_INSERT_TAIL(&g_split_disks, d, tailq);
|
||||
|
||||
offset_bytes += split_size_bytes;
|
||||
offset_blocks += split_size_blocks;
|
||||
}
|
||||
|
||||
|
@ -123,14 +123,14 @@ bdev_virtio_rw(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
vreq->iov = bdev_io->u.read.iovs;
|
||||
vreq->iovcnt = bdev_io->u.read.iovcnt;
|
||||
req->cdb[0] = SPDK_SBC_READ_10;
|
||||
to_be32(&req->cdb[2], bdev_io->u.read.offset / disk->block_size);
|
||||
to_be16(&req->cdb[7], bdev_io->u.read.len / disk->block_size);
|
||||
to_be32(&req->cdb[2], bdev_io->u.read.offset_blocks);
|
||||
to_be16(&req->cdb[7], bdev_io->u.read.num_blocks);
|
||||
} else {
|
||||
vreq->iov = bdev_io->u.write.iovs;
|
||||
vreq->iovcnt = bdev_io->u.write.iovcnt;
|
||||
req->cdb[0] = SPDK_SBC_WRITE_10;
|
||||
to_be32(&req->cdb[2], bdev_io->u.write.offset / disk->block_size);
|
||||
to_be16(&req->cdb[7], bdev_io->u.write.len / disk->block_size);
|
||||
to_be32(&req->cdb[2], bdev_io->u.write.offset_blocks);
|
||||
to_be16(&req->cdb[7], bdev_io->u.write.num_blocks);
|
||||
}
|
||||
|
||||
virtio_xmit_pkts(disk->hw->vqs[2], vreq);
|
||||
|
Loading…
Reference in New Issue
Block a user