bdev: Hold mutex while removing name from name tree
We had not held mutex while removing bdev name or alias from bdev name tree for most cases. Fix these in this patch. spdk_bdev_unregister() already holds g_bdev_mgr.mutex when removing name, and so we do not need to change it. spdk_bdev_close() had not held g_bdev_mgr.mutex. What we want to lock is only when removing name from name tree, that is, calling bdev_name_del() in bdev_unregister_unsafe(). However, we need to keep hierarchical lock ordering. Hence get and free g_bdev_mgr.mutex outside of bdev->internal.mutex. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I4e2c8604e27c8603725efa9bc0bee2013eccb2ac Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8527 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
d06f1c498f
commit
cf8405fc24
@ -3318,7 +3318,9 @@ spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias)
|
||||
TAILQ_FOREACH(tmp, &bdev->aliases, tailq) {
|
||||
if (strcmp(alias, tmp->alias.name) == 0) {
|
||||
TAILQ_REMOVE(&bdev->aliases, tmp, tailq);
|
||||
pthread_mutex_lock(&g_bdev_mgr.mutex);
|
||||
bdev_name_del(&tmp->alias);
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
@ -3336,7 +3338,9 @@ spdk_bdev_alias_del_all(struct spdk_bdev *bdev)
|
||||
|
||||
TAILQ_FOREACH_SAFE(p, &bdev->aliases, tailq, tmp) {
|
||||
TAILQ_REMOVE(&bdev->aliases, p, tailq);
|
||||
pthread_mutex_lock(&g_bdev_mgr.mutex);
|
||||
bdev_name_del(&p->alias);
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
@ -5954,6 +5958,7 @@ spdk_bdev_close(struct spdk_bdev_desc *desc)
|
||||
|
||||
spdk_poller_unregister(&desc->io_timeout_poller);
|
||||
|
||||
pthread_mutex_lock(&g_bdev_mgr.mutex);
|
||||
pthread_mutex_lock(&bdev->internal.mutex);
|
||||
pthread_mutex_lock(&desc->mutex);
|
||||
|
||||
@ -5986,12 +5991,14 @@ spdk_bdev_close(struct spdk_bdev_desc *desc)
|
||||
if (bdev->internal.status == SPDK_BDEV_STATUS_REMOVING && TAILQ_EMPTY(&bdev->internal.open_descs)) {
|
||||
rc = bdev_unregister_unsafe(bdev);
|
||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
|
||||
if (rc == 0) {
|
||||
spdk_io_device_unregister(__bdev_to_io_dev(bdev), bdev_destroy_cb);
|
||||
}
|
||||
} else {
|
||||
pthread_mutex_unlock(&bdev->internal.mutex);
|
||||
pthread_mutex_unlock(&g_bdev_mgr.mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user