From 76add75f1b30b9b20d052026d8064dac27f7229f Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 2 Feb 2022 10:52:31 +0100 Subject: [PATCH] bdev: add internal bdev_alias_del This function takes a function callback to be used to delete a name from the global bdev name tree. It makes it easy to delete an alias with or without locking: ``` bdev_alias_del(bdev, alias, bdev_name_del); ``` or ``` pthread_mutex_lock(&g_bdev_mgr.mutex); bdev_alias_del(bdev, alias, bdev_name_del_unsafe); pthread_mutex_unlock(&g_bdev_mgr.mutex); ``` Signed-off-by: Konrad Sztyber Change-Id: Ida2209d6618a4ce31a6f73da285626c3ecb658fe Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11393 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk Reviewed-by: Ben Walker --- lib/bdev/bdev.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index b9d1f0a108..2dd97f0d31 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -3371,25 +3371,37 @@ spdk_bdev_alias_add(struct spdk_bdev *bdev, const char *alias) return 0; } -int -spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias) +static int +bdev_alias_del(struct spdk_bdev *bdev, const char *alias, + void (*alias_del_fn)(struct spdk_bdev_name *n)) { struct spdk_bdev_alias *tmp; TAILQ_FOREACH(tmp, &bdev->aliases, tailq) { if (strcmp(alias, tmp->alias.name) == 0) { TAILQ_REMOVE(&bdev->aliases, tmp, tailq); - bdev_name_del(&tmp->alias); + alias_del_fn(&tmp->alias); free(tmp); return 0; } } - SPDK_INFOLOG(bdev, "Alias %s does not exists\n", alias); - return -ENOENT; } +int +spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias) +{ + int rc; + + rc = bdev_alias_del(bdev, alias, bdev_name_del); + if (rc == -ENOENT) { + SPDK_INFOLOG(bdev, "Alias %s does not exist\n", alias); + } + + return rc; +} + void spdk_bdev_alias_del_all(struct spdk_bdev *bdev) {