vbdev: close the base bdev on its opened thread

With the JSON configure, the base device will be opened on the
same thread (RPC thread) to handle the JSON operation. Later the
virtual device upon the base device can be opened on another
thread. At the time of virtual device destruction, the base
device is also closed at the thread where opening the virtual
device, it is actually different than the original thread where
this base device is opened through the JSON configure.

Add a thread here to record the exact thread where the base
device is opened and then later route it back to handle the base
device close operation.

Change-Id: I4f48e829a70a83bd71d05dbb13f88819201d9c15
Signed-off-by: GangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/969
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
GangCao 2020-02-20 15:08:07 -05:00 committed by Tomasz Zawadzki
parent 5e1b30bd28
commit e41d1a9411

View File

@ -86,6 +86,7 @@ struct vbdev_passthru {
struct spdk_bdev_desc *base_desc; /* its descriptor we get from open */
struct spdk_bdev pt_bdev; /* the PT virtual bdev */
TAILQ_ENTRY(vbdev_passthru) link;
struct spdk_thread *thread; /* thread where base device is opened */
};
static TAILQ_HEAD(, vbdev_passthru) g_pt_nodes = TAILQ_HEAD_INITIALIZER(g_pt_nodes);
@ -127,6 +128,14 @@ _device_unregister_cb(void *io_device)
free(pt_node);
}
/* Wrapper for the bdev close operation. */
static void
_vbdev_passthru_destruct(void *ctx)
{
struct spdk_bdev_desc *desc = ctx;
spdk_bdev_close(desc);
}
/* Called after we've unregistered following a hot remove callback.
* Our finish entry point will be called next.
*/
@ -144,8 +153,8 @@ vbdev_passthru_destruct(void *ctx)
/* Unclaim the underlying bdev. */
spdk_bdev_module_release_bdev(pt_node->base_bdev);
/* Close the underlying bdev. */
spdk_bdev_close(pt_node->base_desc);
/* Close the underlying bdev on its same opened thread. */
spdk_thread_send_msg(pt_node->thread, _vbdev_passthru_destruct, pt_node->base_desc);
/* Unregister the io_device. */
spdk_io_device_unregister(pt_node, _device_unregister_cb);
@ -685,6 +694,9 @@ vbdev_passthru_register(struct spdk_bdev *bdev)
}
SPDK_NOTICELOG("bdev opened\n");
/* Save the thread where the base device is opened */
pt_node->thread = spdk_get_thread();
rc = spdk_bdev_module_claim_bdev(bdev, pt_node->base_desc, pt_node->pt_bdev.module);
if (rc) {
SPDK_ERRLOG("could not claim bdev %s\n", spdk_bdev_get_name(bdev));