Commit 3ac82ba7 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Jim Harris
Browse files

bdev: allow locked lba range owner channel to be unset



This will be used by the following patch adding bdev quiesce API. It
will allow it to be simpler, without having to provide the io channel.
The owner channel is only necessary to allow I/Os associated with a lock
to execute and quiescing will not allow any I/O.

cb_arg is also not required if ch is NULL so move the check from
_bdev_lock_lba_range() to bdev_lock_lba_range() where it is necessary.

Change-Id: I8ea166ad61324e620abbc37325b691c4370ac9a1
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17889


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 345c632c
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -9198,7 +9198,10 @@ bdev_lock_lba_range_cb(struct spdk_bdev *bdev, void *_ctx, int status)
	 * locking channel, so that this channel will know that it is allowed
	 * to write to this range.
	 */
	if (ctx->owner_range != NULL) {
		ctx->owner_range->owner_ch = ctx->range.owner_ch;
	}

	ctx->cb_fn(ctx->cb_arg, status);

	/* Don't free the ctx here.  Its range is in the bdev's global list of
@@ -9283,7 +9286,8 @@ static void
bdev_lock_lba_range_ctx(struct spdk_bdev *bdev, struct locked_lba_range_ctx *ctx)
{
	assert(spdk_get_thread() == ctx->range.owner_thread);
	assert(spdk_io_channel_get_thread(ctx->range.owner_ch->channel) == ctx->range.owner_thread);
	assert(ctx->range.owner_ch == NULL ||
	       spdk_io_channel_get_thread(ctx->range.owner_ch->channel) == ctx->range.owner_thread);

	/* We will add a copy of this range to each channel now. */
	spdk_bdev_for_each_channel(bdev, bdev_lock_lba_range_get_channel, ctx,
@@ -9310,11 +9314,6 @@ _bdev_lock_lba_range(struct spdk_bdev *bdev, struct spdk_bdev_channel *ch,
{
	struct locked_lba_range_ctx *ctx;

	if (cb_arg == NULL) {
		SPDK_ERRLOG("cb_arg must not be NULL\n");
		return -EINVAL;
	}

	ctx = calloc(1, sizeof(*ctx));
	if (ctx == NULL) {
		return -ENOMEM;
@@ -9352,6 +9351,11 @@ bdev_lock_lba_range(struct spdk_bdev_desc *desc, struct spdk_io_channel *_ch,
	struct spdk_bdev *bdev = spdk_bdev_desc_get_bdev(desc);
	struct spdk_bdev_channel *ch = __io_ch_to_bdev_ch(_ch);

	if (cb_arg == NULL) {
		SPDK_ERRLOG("cb_arg must not be NULL\n");
		return -EINVAL;
	}

	return _bdev_lock_lba_range(bdev, ch, offset, length, cb_fn, cb_arg);
}

@@ -9452,7 +9456,7 @@ _bdev_unlock_lba_range(struct spdk_bdev *bdev, uint64_t offset, uint64_t length,
	 */
	TAILQ_FOREACH(range, &bdev->internal.locked_ranges, tailq) {
		if (range->offset == offset && range->length == length &&
		    range->locked_ctx == cb_arg) {
		    (range->owner_ch == NULL || range->locked_ctx == cb_arg)) {
			break;
		}
	}