bdev: Introduce new bdev mutex for accessing bdevs list
In future patch in new spdk_bdev_open_ext function we will call spdk_bdev_get_by_name function and after that call and before calling old spdk_bdev_open routine bdev can be removed. We need to add mutex which will prevent that. Any future code should use this mutex when accessing the bdevs list to get a bdev and perform some operation on it. Signed-off-by: Maciej Szwed <maciej.szwed@intel.com> Change-Id: I785a1791346aebdd394fc51ad0e7fbfbabf317c9 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458457 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
parent
69a8877e82
commit
1b4c99a2ba
@ -106,6 +106,8 @@ struct spdk_bdev_mgr {
|
|||||||
bool init_complete;
|
bool init_complete;
|
||||||
bool module_init_complete;
|
bool module_init_complete;
|
||||||
|
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
#ifdef SPDK_CONFIG_VTUNE
|
#ifdef SPDK_CONFIG_VTUNE
|
||||||
__itt_domain *domain;
|
__itt_domain *domain;
|
||||||
#endif
|
#endif
|
||||||
@ -116,8 +118,10 @@ static struct spdk_bdev_mgr g_bdev_mgr = {
|
|||||||
.bdevs = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdevs),
|
.bdevs = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdevs),
|
||||||
.init_complete = false,
|
.init_complete = false,
|
||||||
.module_init_complete = false,
|
.module_init_complete = false,
|
||||||
|
.mutex = PTHREAD_MUTEX_INITIALIZER,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct spdk_bdev_opts g_bdev_opts = {
|
static struct spdk_bdev_opts g_bdev_opts = {
|
||||||
.bdev_io_pool_size = SPDK_BDEV_IO_POOL_SIZE,
|
.bdev_io_pool_size = SPDK_BDEV_IO_POOL_SIZE,
|
||||||
.bdev_io_cache_size = SPDK_BDEV_IO_CACHE_SIZE,
|
.bdev_io_cache_size = SPDK_BDEV_IO_CACHE_SIZE,
|
||||||
@ -787,6 +791,8 @@ spdk_bdev_subsystem_config_json(struct spdk_json_write_ctx *w)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_bdev_mgr.mutex);
|
||||||
|
|
||||||
TAILQ_FOREACH(bdev, &g_bdev_mgr.bdevs, internal.link) {
|
TAILQ_FOREACH(bdev, &g_bdev_mgr.bdevs, internal.link) {
|
||||||
if (bdev->fn_table->write_config_json) {
|
if (bdev->fn_table->write_config_json) {
|
||||||
bdev->fn_table->write_config_json(bdev, w);
|
bdev->fn_table->write_config_json(bdev, w);
|
||||||
@ -795,6 +801,8 @@ spdk_bdev_subsystem_config_json(struct spdk_json_write_ctx *w)
|
|||||||
spdk_bdev_qos_config_json(bdev, w);
|
spdk_bdev_qos_config_json(bdev, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||||
|
|
||||||
spdk_json_write_array_end(w);
|
spdk_json_write_array_end(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1112,6 +1120,7 @@ spdk_bdev_mgr_unregister_cb(void *io_device)
|
|||||||
g_fini_cb_arg = NULL;
|
g_fini_cb_arg = NULL;
|
||||||
g_bdev_mgr.init_complete = false;
|
g_bdev_mgr.init_complete = false;
|
||||||
g_bdev_mgr.module_init_complete = false;
|
g_bdev_mgr.module_init_complete = false;
|
||||||
|
pthread_mutex_destroy(&g_bdev_mgr.mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -4227,9 +4236,11 @@ spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_bdev_mgr.mutex);
|
||||||
pthread_mutex_lock(&bdev->internal.mutex);
|
pthread_mutex_lock(&bdev->internal.mutex);
|
||||||
if (bdev->internal.status == SPDK_BDEV_STATUS_REMOVING) {
|
if (bdev->internal.status == SPDK_BDEV_STATUS_REMOVING) {
|
||||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||||
|
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||||
if (cb_fn) {
|
if (cb_fn) {
|
||||||
cb_fn(cb_arg, -EBUSY);
|
cb_fn(cb_arg, -EBUSY);
|
||||||
}
|
}
|
||||||
@ -4243,6 +4254,7 @@ spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void
|
|||||||
/* Call under lock. */
|
/* Call under lock. */
|
||||||
rc = spdk_bdev_unregister_unsafe(bdev);
|
rc = spdk_bdev_unregister_unsafe(bdev);
|
||||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||||
|
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
spdk_bdev_fini(bdev);
|
spdk_bdev_fini(bdev);
|
||||||
|
Loading…
Reference in New Issue
Block a user