bdev/lvol: using spdk_bdev_alias_del_all() to delete all alias on destroy

So we don't need to allocate memory (maybe failed) just for free other
memory.

Change-Id: I2c83f6acc2aa6ed79455bff90f952a2e70b44d59
Signed-off-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-on: https://review.gerrithub.io/422203
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
wuzhouhui 2018-08-14 16:39:27 +08:00 committed by Changpeng Liu
parent b5616804dc
commit 6deac3e660
6 changed files with 54 additions and 9 deletions

View File

@ -18,6 +18,10 @@ each of the SPDK static ones. Although the production of the shared
libs conforms with conventional version naming practices, such naming
does not at this time confer any SPDK ABI compatibility claims.
### bdev
spdk_bdev_alias_del_all() was added to delete all alias from block device.
## v18.07:
### bdev

View File

@ -590,6 +590,13 @@ int spdk_bdev_alias_add(struct spdk_bdev *bdev, const char *alias);
*/
int spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias);
/**
* Removes all alias from block device alias list.
*
* \param bdev Block device to operate.
*/
void spdk_bdev_alias_del_all(struct spdk_bdev *bdev);
/**
* Get pointer to block device aliases list.
*

View File

@ -1570,6 +1570,18 @@ spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias)
return -ENOENT;
}
void
spdk_bdev_alias_del_all(struct spdk_bdev *bdev)
{
struct spdk_bdev_alias *p, *tmp;
TAILQ_FOREACH_SAFE(p, &bdev->aliases, tailq, tmp) {
TAILQ_REMOVE(&bdev->aliases, p, tailq);
free(p->alias);
free(p);
}
}
struct spdk_io_channel *
spdk_bdev_get_io_channel(struct spdk_bdev_desc *desc)
{

View File

@ -541,17 +541,10 @@ static int
vbdev_lvol_unregister(void *ctx)
{
struct spdk_lvol *lvol = ctx;
char *alias;
assert(lvol != NULL);
alias = spdk_sprintf_alloc("%s/%s", lvol->lvol_store->name, lvol->name);
if (alias != NULL) {
spdk_bdev_alias_del(lvol->bdev, alias);
free(alias);
} else {
SPDK_ERRLOG("Cannot alloc memory for alias\n");
}
spdk_bdev_alias_del_all(lvol->bdev);
spdk_lvol_close(lvol, _vbdev_lvol_unregister_cb, lvol->bdev);
/* return 1 to indicate we have an operation that must finish asynchronously before the

View File

@ -502,7 +502,7 @@ io_valid_test(void)
static void
alias_add_del_test(void)
{
struct spdk_bdev *bdev[2];
struct spdk_bdev *bdev[3];
int rc;
/* Creating and registering bdevs */
@ -512,6 +512,9 @@ alias_add_del_test(void)
bdev[1] = allocate_bdev("bdev1");
SPDK_CU_ASSERT_FATAL(bdev[1] != 0);
bdev[2] = allocate_bdev("bdev2");
SPDK_CU_ASSERT_FATAL(bdev[2] != 0);
/*
* Trying adding an alias identical to name.
* Alias is identical to name, so it can not be added to aliases list
@ -558,12 +561,26 @@ alias_add_del_test(void)
rc = spdk_bdev_alias_del(bdev[0], bdev[0]->name);
CU_ASSERT(rc != 0);
/* Trying to del all alias from empty alias list */
spdk_bdev_alias_del_all(bdev[2]);
CU_ASSERT(TAILQ_EMPTY(&bdev[2]->aliases));
/* Trying to del all alias from non-empty alias list */
rc = spdk_bdev_alias_add(bdev[2], "alias0");
CU_ASSERT(rc == 0);
rc = spdk_bdev_alias_add(bdev[2], "alias1");
CU_ASSERT(rc == 0);
spdk_bdev_alias_del_all(bdev[2]);
CU_ASSERT(TAILQ_EMPTY(&bdev[2]->aliases));
/* Unregister and free bdevs */
spdk_bdev_unregister(bdev[0], NULL, NULL);
spdk_bdev_unregister(bdev[1], NULL, NULL);
spdk_bdev_unregister(bdev[2], NULL, NULL);
free(bdev[0]);
free(bdev[1]);
free(bdev[2]);
}
static void

View File

@ -103,6 +103,18 @@ spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias)
return -ENOENT;
}
void
spdk_bdev_alias_del_all(struct spdk_bdev *bdev)
{
struct spdk_bdev_alias *p, *tmp;
TAILQ_FOREACH_SAFE(p, &bdev->aliases, tailq, tmp) {
TAILQ_REMOVE(&bdev->aliases, p, tailq);
free(p->alias);
free(p);
}
}
void
spdk_bdev_destruct_done(struct spdk_bdev *bdev, int bdeverrno)
{