iscsi: turn the <open/close portal> code into functions
Group the code fragments of open/close portal procedure and create spdk_iscsi_portal_open/close() function. Change-Id: Id6e291f3f6e5a926f3ea0d01741a200fa64db81b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/379934 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
72500a9f45
commit
0b4a37d86b
@ -83,6 +83,40 @@ spdk_iscsi_portal_destroy(struct spdk_iscsi_portal *p)
|
|||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
spdk_iscsi_portal_open(struct spdk_iscsi_portal *p)
|
||||||
|
{
|
||||||
|
int port, sock;
|
||||||
|
|
||||||
|
if (p->sock >= 0) {
|
||||||
|
SPDK_ERRLOG("portal (%s, %s) is already opened\n",
|
||||||
|
p->host, p->port);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
port = (int)strtol(p->port, NULL, 0);
|
||||||
|
sock = spdk_sock_listen(p->host, port);
|
||||||
|
if (sock < 0) {
|
||||||
|
SPDK_ERRLOG("listen error %.64s.%d\n", p->host, port);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->sock = sock;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spdk_iscsi_portal_close(struct spdk_iscsi_portal *p)
|
||||||
|
{
|
||||||
|
if (p->sock >= 0) {
|
||||||
|
SPDK_DEBUGLOG(SPDK_TRACE_NET, "close portal (%s, %s)\n",
|
||||||
|
p->host, p->port);
|
||||||
|
close(p->sock);
|
||||||
|
p->sock = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
spdk_iscsi_portal_create_from_configline(const char *portalstring,
|
spdk_iscsi_portal_create_from_configline(const char *portalstring,
|
||||||
struct spdk_iscsi_portal **ip,
|
struct spdk_iscsi_portal **ip,
|
||||||
@ -296,7 +330,7 @@ spdk_iscsi_portal_grp_create_from_portal_list(int tag,
|
|||||||
struct spdk_iscsi_portal **portal_list,
|
struct spdk_iscsi_portal **portal_list,
|
||||||
int num_portals)
|
int num_portals)
|
||||||
{
|
{
|
||||||
int i = 0, rc = 0, port;
|
int i = 0, rc = 0;
|
||||||
struct spdk_iscsi_portal_grp *pg;
|
struct spdk_iscsi_portal_grp *pg;
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "add portal group (from portal list) %d\n", tag);
|
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "add portal group (from portal list) %d\n", tag);
|
||||||
@ -318,19 +352,12 @@ spdk_iscsi_portal_grp_create_from_portal_list(int tag,
|
|||||||
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI,
|
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI,
|
||||||
"RIndex=%d, Host=%s, Port=%s, Tag=%d\n",
|
"RIndex=%d, Host=%s, Port=%s, Tag=%d\n",
|
||||||
i, p->host, p->port, tag);
|
i, p->host, p->port, tag);
|
||||||
|
rc = spdk_iscsi_portal_open(p);
|
||||||
port = (int)strtol(p->port, NULL, 0);
|
if (rc < 0) {
|
||||||
p->sock = spdk_sock_listen(p->host, port);
|
|
||||||
|
|
||||||
if (p->sock < 0) {
|
|
||||||
/* if listening failed on any port, do not register the portal group
|
/* if listening failed on any port, do not register the portal group
|
||||||
* and close any previously opened. */
|
* and close any previously opened. */
|
||||||
SPDK_ERRLOG("listen error %.64s:%d\n", p->host, port);
|
|
||||||
rc = -1;
|
|
||||||
|
|
||||||
for (--i; i >= 0; --i) {
|
for (--i; i >= 0; --i) {
|
||||||
spdk_sock_close(portal_list[i]->sock);
|
spdk_iscsi_portal_close(portal_list[i]);
|
||||||
portal_list[i]->sock = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -502,20 +529,12 @@ static int
|
|||||||
spdk_iscsi_portal_grp_open(struct spdk_iscsi_portal_grp *pg)
|
spdk_iscsi_portal_grp_open(struct spdk_iscsi_portal_grp *pg)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_portal *p;
|
struct spdk_iscsi_portal *p;
|
||||||
int port;
|
int rc;
|
||||||
int sock;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(p, &pg->head, tailq) {
|
TAILQ_FOREACH(p, &pg->head, tailq) {
|
||||||
if (p->sock < 0) {
|
rc = spdk_iscsi_portal_open(p);
|
||||||
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "open host %s, port %s, tag %d\n",
|
if (rc < 0) {
|
||||||
p->host, p->port, pg->tag);
|
return rc;
|
||||||
port = (int)strtol(p->port, NULL, 0);
|
|
||||||
sock = spdk_sock_listen(p->host, port);
|
|
||||||
if (sock < 0) {
|
|
||||||
SPDK_ERRLOG("listen error %.64s:%d\n", p->host, port);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
p->sock = sock;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -540,39 +559,27 @@ spdk_iscsi_portal_grp_open_all(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
spdk_iscsi_portal_grp_close(struct spdk_iscsi_portal_grp *pg)
|
spdk_iscsi_portal_grp_close(struct spdk_iscsi_portal_grp *pg)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_portal *p;
|
struct spdk_iscsi_portal *p;
|
||||||
|
|
||||||
TAILQ_FOREACH(p, &pg->head, tailq) {
|
TAILQ_FOREACH(p, &pg->head, tailq) {
|
||||||
if (p->sock >= 0) {
|
spdk_iscsi_portal_close(p);
|
||||||
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "close host %s, port %s, tag %d\n",
|
|
||||||
p->host, p->port, pg->tag);
|
|
||||||
close(p->sock);
|
|
||||||
p->sock = -1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
spdk_iscsi_portal_grp_close_all(void)
|
spdk_iscsi_portal_grp_close_all(void)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_portal_grp *pg;
|
struct spdk_iscsi_portal_grp *pg;
|
||||||
int rc;
|
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "spdk_iscsi_portal_grp_close_all\n");
|
SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "spdk_iscsi_portal_grp_close_all\n");
|
||||||
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||||
rc = spdk_iscsi_portal_grp_close(pg);
|
spdk_iscsi_portal_grp_close(pg);
|
||||||
if (rc < 0) {
|
|
||||||
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -81,5 +81,5 @@ void spdk_iscsi_portal_grp_array_destroy(void);
|
|||||||
struct spdk_iscsi_portal_grp *spdk_iscsi_portal_grp_find_by_tag(int tag);
|
struct spdk_iscsi_portal_grp *spdk_iscsi_portal_grp_find_by_tag(int tag);
|
||||||
|
|
||||||
int spdk_iscsi_portal_grp_open_all(void);
|
int spdk_iscsi_portal_grp_open_all(void);
|
||||||
int spdk_iscsi_portal_grp_close_all(void);
|
void spdk_iscsi_portal_grp_close_all(void);
|
||||||
#endif // SPDK_PORTAL_GRP_H
|
#endif // SPDK_PORTAL_GRP_H
|
||||||
|
@ -72,10 +72,9 @@ spdk_iscsi_acceptor_stop(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
spdk_iscsi_portal_grp_close_all(void)
|
spdk_iscsi_portal_grp_close_all(void)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user