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 <konrad.sztyber@intel.com>
Change-Id: Ida2209d6618a4ce31a6f73da285626c3ecb658fe
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11393
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-02 10:52:31 +01:00 committed by Jim Harris
parent dcbba659a6
commit 76add75f1b

View File

@ -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)
{