Commit 14b087b7 authored by Jim Harris's avatar Jim Harris
Browse files

bdev: complete 0 length spdk_bdev_unmap_blocks() calls immediately



This helps callers (such as SCSI layer) not have to worry about special
handling for 0-length SCSI unmap descriptors.

We don't actually complete it immediately, we will defer it using an
spdk_thread_send_msg() to the calling spdk_thread.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I47b888f2ab4915a358bde275e605f3d8af814d60
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21772


Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent bb374988
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -6210,6 +6210,15 @@ spdk_bdev_unmap(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
	return spdk_bdev_unmap_blocks(desc, ch, offset_blocks, num_blocks, cb, cb_arg);
}

static void
bdev_unmap_complete_cb(void *ctx)
{
	struct spdk_bdev_io *bdev_io = ctx;

	bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
	bdev_io->internal.cb(bdev_io, true, bdev_io->internal.caller_ctx);
}

int
spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
		       uint64_t offset_blocks, uint64_t num_blocks,
@@ -6227,11 +6236,6 @@ spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
		return -EINVAL;
	}

	if (num_blocks == 0) {
		SPDK_ERRLOG("Can't unmap 0 bytes\n");
		return -EINVAL;
	}

	bdev_io = bdev_channel_get_io(channel);
	if (!bdev_io) {
		return -ENOMEM;
@@ -6253,6 +6257,11 @@ spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
	bdev_io->u.bdev.memory_domain_ctx = NULL;
	bdev_io->u.bdev.accel_sequence = NULL;

	if (num_blocks == 0) {
		spdk_thread_send_msg(spdk_get_thread(), bdev_unmap_complete_cb, bdev_io);
		return 0;
	}

	bdev_io_submit(bdev_io);
	return 0;
}