bdev: move the locks inside bdev_name_del

Additionally, added an unsafe version, bedv_name_del_unsafe, which can
be used while already holding the mutex.  It'll make it easier to remove
an alias without taking a lock.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: If986909cc52c9b9bdb6f429654b01b83b08b1ea3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11392
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Konrad Sztyber 2022-02-01 15:23:05 +01:00 committed by Jim Harris
parent 8175ef2944
commit dcbba659a6

View File

@ -3329,12 +3329,20 @@ bdev_name_add(struct spdk_bdev_name *bdev_name, struct spdk_bdev *bdev, const ch
}
static void
bdev_name_del(struct spdk_bdev_name *bdev_name)
bdev_name_del_unsafe(struct spdk_bdev_name *bdev_name)
{
RB_REMOVE(bdev_name_tree, &g_bdev_mgr.bdev_names, bdev_name);
free(bdev_name->name);
}
static void
bdev_name_del(struct spdk_bdev_name *bdev_name)
{
pthread_mutex_lock(&g_bdev_mgr.mutex);
bdev_name_del_unsafe(bdev_name);
pthread_mutex_unlock(&g_bdev_mgr.mutex);
}
int
spdk_bdev_alias_add(struct spdk_bdev *bdev, const char *alias)
{
@ -3371,9 +3379,7 @@ 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;
}
@ -3391,9 +3397,7 @@ 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);
}
}
@ -5866,7 +5870,7 @@ _remove_notify(void *arg)
pthread_mutex_unlock(&desc->mutex);
}
/* Must be called while holding bdev->internal.mutex.
/* Must be called while holding g_bdev_mgr.mutex and bdev->internal.mutex.
* returns: 0 - bdev removed and ready to be destructed.
* -EBUSY - bdev can't be destructed yet. */
static int
@ -5894,7 +5898,7 @@ bdev_unregister_unsafe(struct spdk_bdev *bdev)
if (rc == 0) {
TAILQ_REMOVE(&g_bdev_mgr.bdevs, bdev, internal.link);
SPDK_DEBUGLOG(bdev, "Removing bdev %s from list done\n", bdev->name);
bdev_name_del(&bdev->internal.bdev_name);
bdev_name_del_unsafe(&bdev->internal.bdev_name);
spdk_notify_send("bdev_unregister", spdk_bdev_get_name(bdev));
}