Commit 7394f690 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/376037


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
parent 7987a7b2
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -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 */
+6 −6
Original line number Diff line number Diff line
@@ -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:
+19 −19
Original line number Diff line number Diff line
@@ -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:
+7 −9
Original line number Diff line number Diff line
@@ -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);

+14 −22
Original line number Diff line number Diff line
@@ -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;
Loading