nvmf: Add utility functions to create/destroy listen addresses.

Change-Id: I58c21caa8f7f0b564c6d8684fe6c7501e810dfa0
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2017-01-19 11:17:16 -07:00
parent ec38ec127c
commit 06b9c46561
4 changed files with 98 additions and 26 deletions

View File

@ -83,6 +83,55 @@ spdk_nvmf_tgt_fini(void)
return 0;
}
struct spdk_nvmf_listen_addr *
spdk_nvmf_listen_addr_create(char *trname, char *traddr, char *trsvcid)
{
struct spdk_nvmf_listen_addr *listen_addr;
const struct spdk_nvmf_transport *transport;
transport = spdk_nvmf_transport_get(trname);
if (!transport) {
return NULL;
}
listen_addr = calloc(1, sizeof(*listen_addr));
if (!listen_addr) {
return NULL;
}
listen_addr->traddr = strdup(traddr);
if (!listen_addr->traddr) {
free(listen_addr);
return NULL;
}
listen_addr->trsvcid = strdup(trsvcid);
if (!listen_addr->trsvcid) {
free(listen_addr->traddr);
free(listen_addr);
return NULL;
}
listen_addr->trname = strdup(trname);
if (!listen_addr->trname) {
free(listen_addr->traddr);
free(listen_addr->trsvcid);
free(listen_addr);
return NULL;
}
return listen_addr;
}
void
spdk_nvmf_listen_addr_destroy(struct spdk_nvmf_listen_addr *addr)
{
free(addr->trname);
free(addr->trsvcid);
free(addr->traddr);
free(addr);
}
SPDK_TRACE_REGISTER_FN(nvmf_trace)
{
spdk_trace_register_object(OBJECT_NVMF_IO, 'r');

View File

@ -78,4 +78,8 @@ nvmf_u32log2(uint32_t x)
extern struct spdk_nvmf_globals g_nvmf_tgt;
struct spdk_nvmf_listen_addr *spdk_nvmf_listen_addr_create(char *trname, char *traddr,
char *trsvcid);
void spdk_nvmf_listen_addr_destroy(struct spdk_nvmf_listen_addr *addr);
#endif /* __NVMF_INTERNAL_H__ */

View File

@ -225,10 +225,7 @@ spdk_nvmf_delete_subsystem(struct spdk_nvmf_subsystem *subsystem)
TAILQ_FOREACH_SAFE(listen_addr, &subsystem->listen_addrs, link, listen_addr_tmp) {
TAILQ_REMOVE(&subsystem->listen_addrs, listen_addr, link);
free(listen_addr->traddr);
free(listen_addr->trsvcid);
free(listen_addr->trname);
free(listen_addr);
spdk_nvmf_listen_addr_destroy(listen_addr);
subsystem->num_listen_addrs--;
}
@ -266,32 +263,11 @@ spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem,
return -1;
}
listen_addr = calloc(1, sizeof(*listen_addr));
listen_addr = spdk_nvmf_listen_addr_create(trname, traddr, trsvcid);
if (!listen_addr) {
return -1;
}
listen_addr->traddr = strdup(traddr);
if (!listen_addr->traddr) {
free(listen_addr);
return -1;
}
listen_addr->trsvcid = strdup(trsvcid);
if (!listen_addr->trsvcid) {
free(listen_addr->traddr);
free(listen_addr);
return -1;
}
listen_addr->trname = strdup(trname);
if (!listen_addr->trname) {
free(listen_addr->traddr);
free(listen_addr->trsvcid);
free(listen_addr);
return -1;
}
TAILQ_INSERT_HEAD(&subsystem->listen_addrs, listen_addr, link);
subsystem->num_listen_addrs++;
g_discovery_genctr++;

View File

@ -48,6 +48,49 @@ SPDK_LOG_REGISTER_TRACE_FLAG("nvmf", SPDK_TRACE_NVMF)
struct spdk_nvmf_globals g_nvmf_tgt;
struct spdk_nvmf_listen_addr *
spdk_nvmf_listen_addr_create(char *trname, char *traddr, char *trsvcid)
{
struct spdk_nvmf_listen_addr *listen_addr;
listen_addr = calloc(1, sizeof(*listen_addr));
if (!listen_addr) {
return NULL;
}
listen_addr->traddr = strdup(traddr);
if (!listen_addr->traddr) {
free(listen_addr);
return NULL;
}
listen_addr->trsvcid = strdup(trsvcid);
if (!listen_addr->trsvcid) {
free(listen_addr->traddr);
free(listen_addr);
return NULL;
}
listen_addr->trname = strdup(trname);
if (!listen_addr->trname) {
free(listen_addr->traddr);
free(listen_addr->trsvcid);
free(listen_addr);
return NULL;
}
return listen_addr;
}
void
spdk_nvmf_listen_addr_destroy(struct spdk_nvmf_listen_addr *addr)
{
free(addr->trname);
free(addr->trsvcid);
free(addr->traddr);
free(addr);
}
static int
test_transport1_listen_addr_add(struct spdk_nvmf_listen_addr *listen_addr)
{