2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-08-02 16:34:45 +00:00
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-07 19:58:14 +00:00
|
|
|
#include "spdk/sock.h"
|
2017-12-18 04:29:37 +00:00
|
|
|
#include "spdk/string.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
#include "iscsi/iscsi.h"
|
|
|
|
#include "iscsi/conn.h"
|
|
|
|
#include "iscsi/portal_grp.h"
|
2019-09-25 06:42:29 +00:00
|
|
|
#include "iscsi/tgt_node.h"
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
#define PORTNUMSTRLEN 32
|
2019-05-13 22:12:32 +00:00
|
|
|
#define ACCEPT_TIMEOUT_US 1000 /* 1ms */
|
|
|
|
|
|
|
|
static int
|
|
|
|
iscsi_portal_accept(void *arg)
|
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *portal = arg;
|
|
|
|
struct spdk_sock *sock;
|
|
|
|
int rc;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (portal->sock == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
sock = spdk_sock_accept(portal->sock);
|
|
|
|
if (sock != NULL) {
|
2020-04-15 22:28:10 +00:00
|
|
|
rc = iscsi_conn_construct(portal, sock);
|
2019-05-13 22:12:32 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
spdk_sock_close(&sock);
|
|
|
|
SPDK_ERRLOG("spdk_iscsi_connection_construct() failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
|
|
|
SPDK_ERRLOG("accept error(%d): %s\n", errno, spdk_strerror(errno));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-09-30 02:23:27 +00:00
|
|
|
static struct spdk_iscsi_portal *
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_find_by_addr(const char *host, const char *port)
|
2017-09-30 02:23:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(p, &g_iscsi.portal_head, g_tailq) {
|
2017-09-30 02:23:27 +00:00
|
|
|
if (!strcmp(p->host, host) && !strcmp(p->port, port)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
/* Assumes caller allocated host and port strings on the heap */
|
|
|
|
struct spdk_iscsi_portal *
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_create(const char *host, const char *port)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-01-29 01:30:45 +00:00
|
|
|
struct spdk_iscsi_portal *p = NULL, *tmp;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2016-08-08 18:07:41 +00:00
|
|
|
assert(host != NULL);
|
|
|
|
assert(port != NULL);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2019-06-28 01:47:10 +00:00
|
|
|
if (strlen(host) > MAX_PORTAL_ADDR || strlen(port) > MAX_PORTAL_PORT) {
|
2019-06-28 01:36:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-30 02:23:27 +00:00
|
|
|
|
2018-01-19 08:57:27 +00:00
|
|
|
p = calloc(1, sizeof(*p));
|
2016-08-02 16:34:45 +00:00
|
|
|
if (!p) {
|
2018-01-19 08:57:27 +00:00
|
|
|
SPDK_ERRLOG("calloc() failed for portal\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-11-13 01:36:50 +00:00
|
|
|
|
|
|
|
/* check and overwrite abbreviation of wildcard */
|
|
|
|
if (strcasecmp(host, "[*]") == 0) {
|
|
|
|
SPDK_WARNLOG("Please use \"[::]\" as IPv6 wildcard\n");
|
|
|
|
SPDK_WARNLOG("Convert \"[*]\" to \"[::]\" automatically\n");
|
|
|
|
SPDK_WARNLOG("(Use of \"[*]\" will be deprecated in a future release)");
|
2019-06-28 01:36:31 +00:00
|
|
|
snprintf(p->host, sizeof(p->host), "[::]");
|
2017-11-13 01:36:50 +00:00
|
|
|
} else if (strcasecmp(host, "*") == 0) {
|
|
|
|
SPDK_WARNLOG("Please use \"0.0.0.0\" as IPv4 wildcard\n");
|
|
|
|
SPDK_WARNLOG("Convert \"*\" to \"0.0.0.0\" automatically\n");
|
|
|
|
SPDK_WARNLOG("(Use of \"[*]\" will be deprecated in a future release)");
|
2019-06-28 01:36:31 +00:00
|
|
|
snprintf(p->host, sizeof(p->host), "0.0.0.0");
|
2017-11-13 01:36:50 +00:00
|
|
|
} else {
|
2019-06-28 01:36:31 +00:00
|
|
|
memcpy(p->host, host, strlen(host));
|
2018-01-19 08:57:27 +00:00
|
|
|
}
|
2017-11-13 01:36:50 +00:00
|
|
|
|
2019-06-28 01:47:10 +00:00
|
|
|
memcpy(p->port, port, strlen(port));
|
2018-01-19 08:57:27 +00:00
|
|
|
|
2018-02-07 21:46:22 +00:00
|
|
|
p->sock = NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
p->group = NULL; /* set at a later time by caller */
|
2017-09-30 04:01:07 +00:00
|
|
|
p->acceptor_poller = NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2019-03-27 21:53:37 +00:00
|
|
|
tmp = iscsi_portal_find_by_addr(host, port);
|
2018-01-29 01:30:45 +00:00
|
|
|
if (tmp != NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-01-29 01:30:45 +00:00
|
|
|
SPDK_ERRLOG("portal (%s, %s) already exists\n", host, port);
|
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_iscsi.portal_head, p, g_tailq);
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2017-09-30 02:23:27 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
return p;
|
2018-01-19 08:57:27 +00:00
|
|
|
|
|
|
|
error_out:
|
|
|
|
free(p);
|
|
|
|
|
|
|
|
return NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_destroy(struct spdk_iscsi_portal *p)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2016-08-08 18:07:41 +00:00
|
|
|
assert(p != NULL);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "iscsi_portal_destroy\n");
|
2018-01-29 01:30:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
TAILQ_REMOVE(&g_iscsi.portal_head, p, g_tailq);
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-01-29 01:30:45 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
free(p);
|
2018-01-29 01:30:45 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 05:37:49 +00:00
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_open(struct spdk_iscsi_portal *p)
|
2017-09-28 05:37:49 +00:00
|
|
|
{
|
2018-02-07 21:46:22 +00:00
|
|
|
struct spdk_sock *sock;
|
|
|
|
int port;
|
2017-09-28 05:37:49 +00:00
|
|
|
|
2018-02-07 21:46:22 +00:00
|
|
|
if (p->sock != NULL) {
|
2017-09-28 05:37:49 +00:00
|
|
|
SPDK_ERRLOG("portal (%s, %s) is already opened\n",
|
|
|
|
p->host, p->port);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
port = (int)strtol(p->port, NULL, 0);
|
sock: Add impl_name parameter in spdk_sock_listen/connect.
Purpose: With this patch,
(1)We can support using different sock implementations in
one application together.
(2)For one IP address managed by kernel, we can use different method
to listen/connect, e.g., posix, or uring. With this patch, we can
designate the specified sock implementation if impl_name is not NULL
and valid. Otherwise, spdk_sock_listen/connect will try to use the sock
implementations in the list by order if impl_name is NULL.
Without this patch, the app will always use the same type of sock implementation
if the order is fixed. For example, if we have posix and uring together,
the first one will always be uring.
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Change-Id: Ic49563f5025085471d356798e522ff7ab748f586
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478140
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2019-12-17 13:57:10 +00:00
|
|
|
sock = spdk_sock_listen(p->host, port, NULL);
|
2018-02-07 21:46:22 +00:00
|
|
|
if (sock == NULL) {
|
2017-09-28 05:37:49 +00:00
|
|
|
SPDK_ERRLOG("listen error %.64s.%d\n", p->host, port);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->sock = sock;
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
/*
|
|
|
|
* When the portal is created by config file, incoming connection
|
|
|
|
* requests for the socket are pended to accept until reactors start.
|
|
|
|
* However the gap between listen() and accept() will be slight and
|
|
|
|
* the requests will be queued by the nonzero backlog of the socket
|
|
|
|
* or resend by TCP.
|
|
|
|
*/
|
2020-04-14 06:49:46 +00:00
|
|
|
p->acceptor_poller = SPDK_POLLER_REGISTER(iscsi_portal_accept, p, ACCEPT_TIMEOUT_US);
|
2017-09-30 04:01:07 +00:00
|
|
|
|
2017-09-28 05:37:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_close(struct spdk_iscsi_portal *p)
|
2017-09-28 05:37:49 +00:00
|
|
|
{
|
2018-02-07 21:46:22 +00:00
|
|
|
if (p->sock) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "close portal (%s, %s)\n",
|
2017-09-28 05:37:49 +00:00
|
|
|
p->host, p->port);
|
2020-01-21 06:27:50 +00:00
|
|
|
spdk_poller_unregister(&p->acceptor_poller);
|
2018-02-07 21:46:22 +00:00
|
|
|
spdk_sock_close(&p->sock);
|
2017-09-28 05:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 02:12:32 +00:00
|
|
|
static void
|
|
|
|
iscsi_portal_pause(struct spdk_iscsi_portal *p)
|
|
|
|
{
|
|
|
|
assert(p->acceptor_poller != NULL);
|
|
|
|
|
|
|
|
spdk_poller_pause(p->acceptor_poller);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iscsi_portal_resume(struct spdk_iscsi_portal *p)
|
|
|
|
{
|
|
|
|
assert(p->acceptor_poller != NULL);
|
|
|
|
|
|
|
|
spdk_poller_resume(p->acceptor_poller);
|
|
|
|
}
|
|
|
|
|
2020-07-21 06:39:00 +00:00
|
|
|
int
|
|
|
|
iscsi_parse_redirect_addr(struct sockaddr_storage *sa,
|
|
|
|
const char *host, const char *port)
|
|
|
|
{
|
|
|
|
struct addrinfo hints, *res;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (host == NULL || port == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = PF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_NUMERICSERV;
|
|
|
|
hints.ai_flags |= AI_NUMERICHOST;
|
|
|
|
rc = getaddrinfo(host, port, &hints, &res);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("getaddinrfo failed: %s (%d)\n", gai_strerror(rc), rc);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res->ai_addrlen > sizeof(*sa)) {
|
|
|
|
SPDK_ERRLOG("getaddrinfo() ai_addrlen %zu too large\n",
|
|
|
|
(size_t)res->ai_addrlen);
|
|
|
|
rc = -EINVAL;
|
|
|
|
} else {
|
|
|
|
memcpy(sa, res->ai_addr, res->ai_addrlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(res);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
struct spdk_iscsi_portal_grp *
|
2020-07-21 12:53:06 +00:00
|
|
|
iscsi_portal_grp_create(int tag, bool is_private)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg = malloc(sizeof(*pg));
|
|
|
|
|
|
|
|
if (!pg) {
|
2017-12-26 20:59:09 +00:00
|
|
|
SPDK_ERRLOG("malloc() failed for portal group\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pg->ref = 0;
|
|
|
|
pg->tag = tag;
|
2020-07-21 12:53:06 +00:00
|
|
|
pg->is_private = is_private;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
pg->disable_chap = g_iscsi.disable_chap;
|
|
|
|
pg->require_chap = g_iscsi.require_chap;
|
|
|
|
pg->mutual_chap = g_iscsi.mutual_chap;
|
|
|
|
pg->chap_group = g_iscsi.chap_group;
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2019-09-25 04:53:34 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
TAILQ_INIT(&pg->head);
|
|
|
|
|
|
|
|
return pg;
|
|
|
|
}
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_destroy(struct spdk_iscsi_portal_grp *pg)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
|
|
|
|
2016-08-08 18:07:41 +00:00
|
|
|
assert(pg != NULL);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "iscsi_portal_grp_destroy\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
while (!TAILQ_EMPTY(&pg->head)) {
|
|
|
|
p = TAILQ_FIRST(&pg->head);
|
2017-09-30 02:23:27 +00:00
|
|
|
TAILQ_REMOVE(&pg->head, p, per_pg_tailq);
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_destroy(p);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
free(pg);
|
|
|
|
}
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
int
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_register(struct spdk_iscsi_portal_grp *pg)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-01-29 07:51:51 +00:00
|
|
|
int rc = -1;
|
|
|
|
struct spdk_iscsi_portal_grp *tmp;
|
|
|
|
|
2016-08-08 18:07:41 +00:00
|
|
|
assert(pg != NULL);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2020-04-15 21:54:21 +00:00
|
|
|
tmp = iscsi_portal_grp_find_by_tag(pg->tag);
|
2018-01-29 07:51:51 +00:00
|
|
|
if (tmp == NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_iscsi.pg_head, pg, tailq);
|
2018-01-29 07:51:51 +00:00
|
|
|
rc = 0;
|
|
|
|
}
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-01-29 07:51:51 +00:00
|
|
|
return rc;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_add_portal(struct spdk_iscsi_portal_grp *pg,
|
|
|
|
struct spdk_iscsi_portal *p)
|
2017-12-22 11:22:01 +00:00
|
|
|
{
|
|
|
|
assert(pg != NULL);
|
|
|
|
assert(p != NULL);
|
|
|
|
|
|
|
|
p->group = pg;
|
|
|
|
TAILQ_INSERT_TAIL(&pg->head, p, per_pg_tailq);
|
|
|
|
}
|
|
|
|
|
2020-07-17 09:40:38 +00:00
|
|
|
struct spdk_iscsi_portal *
|
|
|
|
iscsi_portal_grp_find_portal_by_addr(struct spdk_iscsi_portal_grp *pg,
|
|
|
|
const char *host, const char *port)
|
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
|
|
|
if (!strcmp(p->host, host) && !strcmp(p->port, port)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-25 06:42:29 +00:00
|
|
|
int
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_set_chap_params(struct spdk_iscsi_portal_grp *pg,
|
|
|
|
bool disable_chap, bool require_chap,
|
|
|
|
bool mutual_chap, int32_t chap_group)
|
2019-09-25 06:42:29 +00:00
|
|
|
{
|
2020-04-15 21:04:36 +00:00
|
|
|
if (!iscsi_check_chap_params(disable_chap, require_chap,
|
|
|
|
mutual_chap, chap_group)) {
|
2019-09-25 06:42:29 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pg->disable_chap = disable_chap;
|
|
|
|
pg->require_chap = require_chap;
|
|
|
|
pg->mutual_chap = mutual_chap;
|
|
|
|
pg->chap_group = chap_group;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
struct spdk_iscsi_portal_grp *
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_find_by_tag(int tag)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(pg, &g_iscsi.pg_head, tailq) {
|
2016-08-02 16:34:45 +00:00
|
|
|
if (pg->tag == tag) {
|
|
|
|
return pg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grps_destroy(void)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-01-29 01:30:45 +00:00
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "iscsi_portal_grps_destroy\n");
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
while (!TAILQ_EMPTY(&g_iscsi.pg_head)) {
|
|
|
|
pg = TAILQ_FIRST(&g_iscsi.pg_head);
|
|
|
|
TAILQ_REMOVE(&g_iscsi.pg_head, pg, tailq);
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_destroy(pg);
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
int
|
2020-11-12 02:12:32 +00:00
|
|
|
iscsi_portal_grp_open(struct spdk_iscsi_portal_grp *pg, bool pause)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
2017-09-28 05:37:49 +00:00
|
|
|
int rc;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2017-09-30 02:23:27 +00:00
|
|
|
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_portal_open(p);
|
2017-09-28 05:37:49 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-11-12 02:12:32 +00:00
|
|
|
|
|
|
|
if (pause) {
|
|
|
|
iscsi_portal_pause(p);
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-28 05:37:49 +00:00
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_close(struct spdk_iscsi_portal_grp *pg)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
|
|
|
|
2017-09-30 02:23:27 +00:00
|
|
|
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_close(p);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 02:12:32 +00:00
|
|
|
void
|
|
|
|
iscsi_portal_grp_resume(struct spdk_iscsi_portal_grp *pg)
|
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *p;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
|
|
|
iscsi_portal_resume(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 05:37:49 +00:00
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_close_all(void)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "iscsi_portal_grp_close_all\n");
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
TAILQ_FOREACH(pg, &g_iscsi.pg_head, tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_close(pg);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 07:51:51 +00:00
|
|
|
struct spdk_iscsi_portal_grp *
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_unregister(int tag)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-01-29 07:51:51 +00:00
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
TAILQ_FOREACH(pg, &g_iscsi.pg_head, tailq) {
|
2018-01-29 07:51:51 +00:00
|
|
|
if (pg->tag == tag) {
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_REMOVE(&g_iscsi.pg_head, pg, tailq);
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-01-29 07:51:51 +00:00
|
|
|
return pg;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-01-29 07:51:51 +00:00
|
|
|
return NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_release(struct spdk_iscsi_portal_grp *pg)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_close(pg);
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_destroy(pg);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2018-05-09 22:56:04 +00:00
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_info_json(struct spdk_iscsi_portal_grp *pg,
|
|
|
|
struct spdk_json_write_ctx *w)
|
2018-05-09 22:56:04 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal *portal;
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_int32(w, "tag", pg->tag);
|
|
|
|
|
|
|
|
spdk_json_write_named_array_begin(w, "portals");
|
|
|
|
TAILQ_FOREACH(portal, &pg->head, per_pg_tailq) {
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "host", portal->host);
|
|
|
|
spdk_json_write_named_string(w, "port", portal->port);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2020-07-21 12:53:06 +00:00
|
|
|
spdk_json_write_named_bool(w, "private", pg->is_private);
|
|
|
|
|
2018-05-09 22:56:04 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_config_json(struct spdk_iscsi_portal_grp *pg,
|
|
|
|
struct spdk_json_write_ctx *w)
|
2018-05-09 22:56:04 +00:00
|
|
|
{
|
2018-05-13 23:02:19 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2019-09-09 10:35:30 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "iscsi_create_portal_group");
|
2018-05-09 22:56:04 +00:00
|
|
|
|
|
|
|
spdk_json_write_name(w, "params");
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_info_json(pg, w);
|
2018-05-09 22:56:04 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grps_info_json(struct spdk_json_write_ctx *w)
|
2018-05-09 22:56:04 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(pg, &g_iscsi.pg_head, tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_info_json(pg, w);
|
2018-05-09 22:56:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grps_config_json(struct spdk_json_write_ctx *w)
|
2018-05-09 22:56:04 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(pg, &g_iscsi.pg_head, tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_portal_grp_config_json(pg, w);
|
2018-05-09 22:56:04 +00:00
|
|
|
}
|
|
|
|
}
|