From da11a46466bd41f2d36bdce2e059d8aeb1ac502a Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 22 Jan 2020 11:46:04 -0700 Subject: [PATCH] bdev: start lock process on original channel If a locking operation has to wait because of an existing lock, we queue the lock context. When the existing lock finishes unlocking, we restart the queued lock context. But we have to make sure we restart the lock context on the same thread it was originally submitted, since it has a channel associated with it. Signed-off-by: Jim Harris Change-Id: I555515f3adfc3c13a86584c601ed541d605980b7 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482463 Community-CI: Broadcom SPDK FC-NVMe CI Reviewed-by: Maciej Szwed Reviewed-by: Ben Walker Reviewed-by: Alexey Marchuk Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- lib/bdev/bdev.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 53a887777..5a1bb0acf 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -6147,6 +6147,8 @@ bdev_lock_lba_range_get_channel(struct spdk_io_channel_iter *i) static void bdev_lock_lba_range_ctx(struct spdk_bdev *bdev, struct locked_lba_range_ctx *ctx) { + assert(spdk_get_thread() == ctx->range.owner_ch->channel->thread); + /* We will add a copy of this range to each channel now. */ spdk_for_each_channel(__bdev_to_io_dev(bdev), bdev_lock_lba_range_get_channel, ctx, bdev_lock_lba_range_cb); @@ -6207,6 +6209,14 @@ bdev_lock_lba_range(struct spdk_bdev_desc *desc, struct spdk_io_channel *_ch, return 0; } +static void +bdev_lock_lba_range_ctx_msg(void *_ctx) +{ + struct locked_lba_range_ctx *ctx = _ctx; + + bdev_lock_lba_range_ctx(ctx->bdev, ctx); +} + static void bdev_unlock_lba_range_cb(struct spdk_io_channel_iter *i, int status) { @@ -6228,7 +6238,8 @@ bdev_unlock_lba_range_cb(struct spdk_io_channel_iter *i, int status) TAILQ_REMOVE(&bdev->internal.pending_locked_ranges, range, tailq); pending_ctx = SPDK_CONTAINEROF(range, struct locked_lba_range_ctx, range); TAILQ_INSERT_TAIL(&bdev->internal.locked_ranges, range, tailq); - bdev_lock_lba_range_ctx(bdev, pending_ctx); + spdk_thread_send_msg(pending_ctx->range.owner_ch->channel->thread, + bdev_lock_lba_range_ctx_msg, pending_ctx); } } pthread_mutex_unlock(&bdev->internal.mutex);