Commit 15de0539 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Tomasz Zawadzki
Browse files

lib/bdev: defer unregister if bdev has locked ranges



Any locked ranges should be unlocked by the bdev module before the bdev
finishes unregistering. Give it a chance to do so.

Change-Id: I639a5e221def4452a6c6eb5f025bd5f231734466
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@solidigm.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26491


Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent 16b0f882
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -8277,6 +8277,8 @@ bdev_destroy_cb(void *io_device)
		return;
	}

	assert(TAILQ_EMPTY(&bdev->internal.locked_ranges));

	cb_fn = bdev->internal.unregister_cb;
	cb_arg = bdev->internal.unregister_ctx;

@@ -8384,6 +8386,12 @@ bdev_unregister(struct spdk_bdev *bdev, void *_ctx, int status)

	spdk_spin_lock(&g_bdev_mgr.spinlock);
	spdk_spin_lock(&bdev->internal.spinlock);
	if (!TAILQ_EMPTY(&bdev->internal.locked_ranges)) {
		/* Unregister will be continued after all ranges are unlocked. */
		spdk_spin_unlock(&bdev->internal.spinlock);
		spdk_spin_unlock(&g_bdev_mgr.spinlock);
		return;
	}
	/*
	 * Set the status to REMOVING after completing to abort channels. Otherwise,
	 * the last spdk_bdev_close() may call spdk_io_device_unregister() while
@@ -8400,6 +8408,14 @@ bdev_unregister(struct spdk_bdev *bdev, void *_ctx, int status)
	}
}

static void
_bdev_unregister(void *ctx)
{
	struct spdk_bdev *bdev = ctx;

	bdev_unregister(bdev, NULL, 0);
}

void
spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
{
@@ -10598,6 +10614,11 @@ bdev_unlock_lba_range_cb(struct spdk_bdev *bdev, void *_ctx, int status)
					     bdev_lock_lba_range_ctx_msg, pending_ctx);
		}
	}

	if (bdev->internal.status == SPDK_BDEV_STATUS_UNREGISTERING &&
	    TAILQ_EMPTY(&bdev->internal.locked_ranges)) {
		spdk_thread_send_msg(bdev->internal.unregister_td, _bdev_unregister, bdev);
	}
	spdk_spin_unlock(&bdev->internal.spinlock);

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