iscsi: Ensure uniqueness of network portal by mutex
Network portal must be unique globally but mutex is not added yet. This patch is added to ensure it. Change-Id: I3cdd85fd524b0da767d3cd83022e0637f3a32bc9 Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/396846 Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
5d2881c6dd
commit
950065042c
@ -69,18 +69,13 @@ spdk_iscsi_portal_find_by_addr(const char *host, const char *port)
|
|||||||
struct spdk_iscsi_portal *
|
struct spdk_iscsi_portal *
|
||||||
spdk_iscsi_portal_create(const char *host, const char *port, const char *cpumask)
|
spdk_iscsi_portal_create(const char *host, const char *port, const char *cpumask)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_portal *p = NULL;
|
struct spdk_iscsi_portal *p = NULL, *tmp;
|
||||||
struct spdk_cpuset *core_mask = NULL;
|
struct spdk_cpuset *core_mask = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
assert(host != NULL);
|
assert(host != NULL);
|
||||||
assert(port != NULL);
|
assert(port != NULL);
|
||||||
|
|
||||||
p = spdk_iscsi_portal_find_by_addr(host, port);
|
|
||||||
if (p != NULL) {
|
|
||||||
SPDK_ERRLOG("portal (%s, %s) already exists\n", host, port);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = calloc(1, sizeof(*p));
|
p = calloc(1, sizeof(*p));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
@ -140,7 +135,16 @@ spdk_iscsi_portal_create(const char *host, const char *port, const char *cpumask
|
|||||||
p->group = NULL; /* set at a later time by caller */
|
p->group = NULL; /* set at a later time by caller */
|
||||||
p->acceptor_poller = NULL;
|
p->acceptor_poller = NULL;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||||
|
tmp = spdk_iscsi_portal_find_by_addr(host, port);
|
||||||
|
if (tmp != NULL) {
|
||||||
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
|
SPDK_ERRLOG("portal (%s, %s) already exists\n", host, port);
|
||||||
|
goto error_out;
|
||||||
|
}
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&g_spdk_iscsi.portal_head, p, g_tailq);
|
TAILQ_INSERT_TAIL(&g_spdk_iscsi.portal_head, p, g_tailq);
|
||||||
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
@ -159,11 +163,16 @@ spdk_iscsi_portal_destroy(struct spdk_iscsi_portal *p)
|
|||||||
assert(p != NULL);
|
assert(p != NULL);
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_portal_destroy\n");
|
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_portal_destroy\n");
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||||
TAILQ_REMOVE(&g_spdk_iscsi.portal_head, p, g_tailq);
|
TAILQ_REMOVE(&g_spdk_iscsi.portal_head, p, g_tailq);
|
||||||
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
|
|
||||||
free(p->host);
|
free(p->host);
|
||||||
free(p->port);
|
free(p->port);
|
||||||
spdk_cpuset_free(p->cpumask);
|
spdk_cpuset_free(p->cpumask);
|
||||||
free(p);
|
free(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -562,13 +571,16 @@ spdk_iscsi_portal_grp_array_create(void)
|
|||||||
void
|
void
|
||||||
spdk_iscsi_portal_grp_array_destroy(void)
|
spdk_iscsi_portal_grp_array_destroy(void)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_portal_grp *pg, *tmp;
|
struct spdk_iscsi_portal_grp *pg;
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_portal_grp_array_destroy\n");
|
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_portal_grp_array_destroy\n");
|
||||||
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||||
TAILQ_FOREACH_SAFE(pg, &g_spdk_iscsi.pg_head, tailq, tmp) {
|
while (!TAILQ_EMPTY(&g_spdk_iscsi.pg_head)) {
|
||||||
|
pg = TAILQ_FIRST(&g_spdk_iscsi.pg_head);
|
||||||
TAILQ_REMOVE(&g_spdk_iscsi.pg_head, pg, tailq);
|
TAILQ_REMOVE(&g_spdk_iscsi.pg_head, pg, tailq);
|
||||||
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
spdk_iscsi_portal_grp_destroy(pg);
|
spdk_iscsi_portal_grp_destroy(pg);
|
||||||
|
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
}
|
}
|
||||||
@ -653,7 +665,5 @@ spdk_iscsi_portal_grp_release(struct spdk_iscsi_portal_grp *pg)
|
|||||||
{
|
{
|
||||||
spdk_iscsi_portal_grp_close(pg);
|
spdk_iscsi_portal_grp_close(pg);
|
||||||
spdk_iscsi_portal_grp_unregister(pg);
|
spdk_iscsi_portal_grp_unregister(pg);
|
||||||
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
|
||||||
spdk_iscsi_portal_grp_destroy(pg);
|
spdk_iscsi_portal_grp_destroy(pg);
|
||||||
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ static int
|
|||||||
test_setup(void)
|
test_setup(void)
|
||||||
{
|
{
|
||||||
TAILQ_INIT(&g_spdk_iscsi.portal_head);
|
TAILQ_INIT(&g_spdk_iscsi.portal_head);
|
||||||
|
pthread_mutex_init(&g_spdk_iscsi.mutex, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user