Commit 60c38d40 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

bdev: Change unmap to use offset/len instead of descriptors



This is far simpler, although it does limit the bdev
layer to unmapped just one range per command. In practice,
all of our code reports limits of just one range per command
anyway.

Change-Id: I99247ab349fe85b9925769e965833b06708d0d70
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/370382


Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 914b1d15
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6,6 +6,10 @@ An [fio](http://github.com/axboe/fio) plugin was added that can route
I/O to the bdev layer. See the [plugin documentation](https://github.com/spdk/spdk/blob/master/examples/bdev/fio_plugin/README.md)
for more information.

spdk_bdev_unmap() was modified to take an offset and a length in bytes as
arguments instead of requiring the user to provide an array of SCSI
unmap descriptors. This limits unmaps to a single contiguous range.

## v17.07: Build system improvements, userspace vhost-blk target, and GPT bdev

### Build System
+3 −12
Original line number Diff line number Diff line
@@ -210,14 +210,6 @@ uint32_t spdk_bdev_get_block_size(const struct spdk_bdev *bdev);
 */
uint64_t spdk_bdev_get_num_blocks(const struct spdk_bdev *bdev);

/**
 * Get maximum number of descriptors per unmap request.
 *
 * \param bdev Block device to query.
 * \return Maximum number of unmap descriptors per request.
 */
uint32_t spdk_bdev_get_max_unmap_descriptors(const struct spdk_bdev *bdev);

/**
 * Get minimum I/O buffer address alignment for a bdev.
 *
@@ -344,8 +336,8 @@ int spdk_bdev_writev(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
 *
 * \param bdev Block device
 * \param ch I/O channel. Obtained by calling spdk_bdev_get_io_channel().
 * \param unmap_d An array of unmap descriptors.
 * \param bdesc_count The number of elements in unmap_d.
 * \param offset The offset, in bytes, from the start of the block device.
 * \param nbytes The number of bytes to unmap. Must be a multiple of the block size.
 * \param cb Called when the request is complete.
 * \param cb_arg Argument passed to cb.
 *
@@ -354,8 +346,7 @@ int spdk_bdev_writev(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
 * negated errno on failure, in which case the callback will not be called.
 */
int spdk_bdev_unmap(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
		    struct spdk_scsi_unmap_bdesc *unmap_d,
		    uint16_t bdesc_count,
		    uint64_t offset, uint64_t nbytes,
		    spdk_bdev_io_completion_cb cb, void *cb_arg);

/**
+0 −6
Original line number Diff line number Diff line
@@ -94,12 +94,6 @@ struct spdk_bs_dev_cb_args {
	spdk_bs_dev_cpl		cb_fn;
	struct spdk_io_channel	*channel;
	void			*cb_arg;
	/*
	 * Blobstore device implementations can use this for scratch space for any data
	 *  structures needed to translate the function arguments to the required format
	 *  for the backing store.
	 */
	uint8_t			scratch[32];
};

struct spdk_bs_dev {
+4 −7
Original line number Diff line number Diff line
@@ -200,9 +200,6 @@ struct spdk_bdev {
	/** function table for all LUN ops */
	const struct spdk_bdev_fn_table *fn_table;

	/** Represents maximum unmap block descriptor count */
	uint32_t max_unmap_bdesc_count;

	/** generation value used by block device reset */
	uint32_t gencnt;

@@ -299,11 +296,11 @@ struct spdk_bdev_io {
			uint64_t offset;
		} write;
		struct {
			/** Represents the unmap block descriptors. */
			struct spdk_scsi_unmap_bdesc *unmap_bdesc;
			/** Total size of region to be unmapped. */
			uint64_t len;

			/** Count of unmap block descriptors. */
			uint16_t bdesc_count;
			/** Starting offset (in bytes) of the bdev for this I/O. */
			uint64_t offset;
		} unmap;
		struct {
			/** Represents starting offset in bytes of the range to be flushed. */
+6 −15
Original line number Diff line number Diff line
@@ -722,12 +722,6 @@ spdk_bdev_get_num_blocks(const struct spdk_bdev *bdev)
	return bdev->blockcnt;
}

uint32_t
spdk_bdev_get_max_unmap_descriptors(const struct spdk_bdev *bdev)
{
	return bdev->max_unmap_bdesc_count;
}

size_t
spdk_bdev_get_buf_align(const struct spdk_bdev *bdev)
{
@@ -931,8 +925,7 @@ spdk_bdev_writev(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,

int
spdk_bdev_unmap(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
		struct spdk_scsi_unmap_bdesc *unmap_d,
		uint16_t bdesc_count,
		uint64_t offset, uint64_t nbytes,
		spdk_bdev_io_completion_cb cb, void *cb_arg)
{
	struct spdk_bdev *bdev = desc->bdev;
@@ -944,14 +937,12 @@ spdk_bdev_unmap(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
		return -EBADF;
	}

	if (bdesc_count == 0) {
		SPDK_ERRLOG("Invalid bdesc_count 0\n");
	if (spdk_bdev_io_valid(bdev, offset, nbytes) != 0) {
		return -EINVAL;
	}

	if (bdesc_count > bdev->max_unmap_bdesc_count) {
		SPDK_ERRLOG("Invalid bdesc_count %u > max_unmap_bdesc_count %u\n",
			    bdesc_count, bdev->max_unmap_bdesc_count);
	if (nbytes == 0) {
		SPDK_ERRLOG("Can't unmap 0 bytes\n");
		return -EINVAL;
	}

@@ -963,8 +954,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.unmap_bdesc = unmap_d;
	bdev_io->u.unmap.bdesc_count = bdesc_count;
	bdev_io->u.unmap.offset = offset;
	bdev_io->u.unmap.len = nbytes;
	spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb);

	rc = spdk_bdev_io_submit(bdev_io);
Loading