bdev/rbd: simplify pool_name allocation

Remove the complex list management for pool_name and just strdup() it
directly.  It is not worth the trouble to save a few bytes.

Change-Id: I8a4f7eeea619bd824ea593854423e317041c540e
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-11-08 11:25:29 -07:00
parent 9f2e5cd713
commit 2b2ce628dc

View File

@ -54,15 +54,9 @@
#include "bdev_module.h"
static TAILQ_HEAD(, blockdev_rbd_pool_info) g_rbd_pools = TAILQ_HEAD_INITIALIZER(g_rbd_pools);
static TAILQ_HEAD(, blockdev_rbd) g_rbds = TAILQ_HEAD_INITIALIZER(g_rbds);
static int blockdev_rbd_count = 0;
struct blockdev_rbd_pool_info {
char *name;
TAILQ_ENTRY(blockdev_rbd_pool_info) tailq;
};
enum blockdev_rbd_data_direction {
BLOCKDEV_RBD_READ = 0,
BLOCKDEV_RBD_WRITE = 1,
@ -80,8 +74,8 @@ struct blockdev_rbd_io {
struct blockdev_rbd {
struct spdk_bdev disk;
char *rbd_name;
char *pool_name;
rbd_image_info_t info;
struct blockdev_rbd_pool_info *pool_info;
TAILQ_ENTRY(blockdev_rbd) tailq;
};
@ -96,17 +90,6 @@ struct blockdev_rbd_io_channel {
struct spdk_poller *poller;
};
static void
blockdev_rbd_free_pool_info(struct blockdev_rbd_pool_info *pool_info)
{
if (!pool_info) {
return;
}
free(pool_info->name);
free(pool_info);
}
static void
blockdev_rbd_free(struct blockdev_rbd *rbd)
{
@ -115,6 +98,7 @@ blockdev_rbd_free(struct blockdev_rbd *rbd)
}
free(rbd->rbd_name);
free(rbd->pool_name);
free(rbd);
}
@ -446,18 +430,16 @@ blockdev_rbd_create_cb(void *io_device, uint32_t priority,
{
struct blockdev_rbd_io_channel *ch = ctx_buf;
int ret;
struct blockdev_rbd_pool_info *pool_info;
ch->disk = (struct blockdev_rbd *)io_device;
pool_info = ch->disk->pool_info;
ch->image = NULL;
ch->io_ctx = NULL;
ch->pfd.fd = -1;
ret = blockdev_rados_context_init(pool_info->name, &ch->cluster, &ch->io_ctx);
ret = blockdev_rados_context_init(ch->disk->pool_name, &ch->cluster, &ch->io_ctx);
if (ret < 0) {
SPDK_ERRLOG("Failed to create rados context for rbd_pool=%s\n",
pool_info->name);
ch->disk->pool_name);
goto err;
}
@ -523,7 +505,6 @@ static const struct spdk_bdev_fn_table rbd_fn_table = {
static void
blockdev_rbd_library_fini(void)
{
struct blockdev_rbd_pool_info *pool_info;
struct blockdev_rbd *rbd;
while (!TAILQ_EMPTY(&g_rbds)) {
@ -531,45 +512,11 @@ blockdev_rbd_library_fini(void)
TAILQ_REMOVE(&g_rbds, rbd, tailq);
blockdev_rbd_free(rbd);
}
while (!TAILQ_EMPTY(&g_rbd_pools)) {
pool_info = TAILQ_FIRST(&g_rbd_pools);
TAILQ_REMOVE(&g_rbd_pools, pool_info, tailq);
blockdev_rbd_free_pool_info(pool_info);
}
}
static struct blockdev_rbd_pool_info *
blockdev_rbd_pool_info_init(const char *rbd_pool_name)
{
struct blockdev_rbd_pool_info *pool_info;
TAILQ_FOREACH(pool_info, &g_rbd_pools, tailq) {
if (!strcmp(pool_info->name, rbd_pool_name)) {
return pool_info;
}
}
pool_info = calloc(1, sizeof(struct blockdev_rbd_pool_info));
if (!pool_info) {
SPDK_ERRLOG("Failed to allocate blockdev_rbd_pool_info struct\n");
return NULL;
}
pool_info->name = strdup(rbd_pool_name);
if (!pool_info->name) {
blockdev_rbd_free_pool_info(pool_info);
return NULL;
}
TAILQ_INSERT_TAIL(&g_rbd_pools, pool_info, tailq);
return pool_info;
}
struct spdk_bdev *
spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block_size)
{
struct blockdev_rbd_pool_info *pool_info;
struct blockdev_rbd *rbd;
int ret;
@ -577,30 +524,26 @@ spdk_bdev_rbd_create(const char *pool_name, const char *rbd_name, uint32_t block
return NULL;
}
pool_info = blockdev_rbd_pool_info_init(pool_name);
if (pool_info == NULL) {
SPDK_ERRLOG("failed to create blockdev_rbd_pool_info\n");
return NULL;
}
rbd = calloc(1, sizeof(struct blockdev_rbd));
if (rbd == NULL) {
SPDK_ERRLOG("Failed to allocate blockdev_rbd struct\n");
blockdev_rbd_free_pool_info(pool_info);
return NULL;
}
rbd->pool_info = pool_info;
rbd->rbd_name = strdup(rbd_name);
if (!rbd->rbd_name) {
blockdev_rbd_free_pool_info(pool_info);
blockdev_rbd_free(rbd);
return NULL;
}
ret = blockdev_rbd_init(pool_info->name, rbd_name, &rbd->info);
rbd->pool_name = strdup(pool_name);
if (!rbd->pool_name) {
blockdev_rbd_free(rbd);
return NULL;
}
ret = blockdev_rbd_init(rbd->pool_name, rbd_name, &rbd->info);
if (ret < 0) {
blockdev_rbd_free_pool_info(pool_info);
blockdev_rbd_free(rbd);
SPDK_ERRLOG("Failed to init rbd device\n");
return NULL;