2016-08-02 16:34:45 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-08-02 16:34:45 +00:00
|
|
|
|
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/init_grp.h"
|
|
|
|
|
2017-10-10 01:24:13 +00:00
|
|
|
static struct spdk_iscsi_init_grp *
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_create(int tag)
|
2017-10-10 01:24:13 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
|
|
|
ig = calloc(1, sizeof(*ig));
|
|
|
|
if (ig == NULL) {
|
2017-12-26 20:59:09 +00:00
|
|
|
SPDK_ERRLOG("calloc() failed for initiator group\n");
|
2017-10-10 01:24:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ig->tag = tag;
|
2017-11-15 00:14:27 +00:00
|
|
|
TAILQ_INIT(&ig->initiator_head);
|
|
|
|
TAILQ_INIT(&ig->netmask_head);
|
2017-10-10 01:24:13 +00:00
|
|
|
return ig;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
static struct spdk_iscsi_initiator_name *
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_find_initiator(struct spdk_iscsi_init_grp *ig, char *name)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_initiator_name *iname;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(iname, &ig->initiator_head, tailq) {
|
|
|
|
if (!strcmp(iname->name, name)) {
|
|
|
|
return iname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-24 01:01:12 +00:00
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_add_initiator(struct spdk_iscsi_init_grp *ig, char *name)
|
2017-10-24 01:01:12 +00:00
|
|
|
{
|
2017-11-15 00:14:27 +00:00
|
|
|
struct spdk_iscsi_initiator_name *iname;
|
2017-11-29 05:51:23 +00:00
|
|
|
char *p;
|
2019-06-27 23:49:28 +00:00
|
|
|
size_t len;
|
2017-10-24 01:01:12 +00:00
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
if (ig->ninitiators >= MAX_INITIATOR) {
|
|
|
|
SPDK_ERRLOG("> MAX_INITIATOR(=%d) is not allowed\n", MAX_INITIATOR);
|
2017-10-24 01:01:12 +00:00
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2019-06-27 23:49:28 +00:00
|
|
|
len = strlen(name);
|
|
|
|
if (len > MAX_INITIATOR_NAME) {
|
2018-11-19 08:20:32 +00:00
|
|
|
SPDK_ERRLOG("Initiator Name is larger than 223 bytes\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
iname = iscsi_init_grp_find_initiator(ig, name);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (iname != NULL) {
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
2019-06-27 23:49:28 +00:00
|
|
|
iname = calloc(1, sizeof(*iname));
|
2017-11-15 00:14:27 +00:00
|
|
|
if (iname == NULL) {
|
2017-12-26 20:59:09 +00:00
|
|
|
SPDK_ERRLOG("malloc() failed for initiator name str\n");
|
2017-10-24 01:01:12 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-06-27 23:49:28 +00:00
|
|
|
memcpy(iname->name, name, len);
|
2017-11-15 00:14:27 +00:00
|
|
|
|
2017-11-29 05:51:23 +00:00
|
|
|
/* Replace "ALL" by "ANY" if set */
|
|
|
|
p = strstr(iname->name, "ALL");
|
|
|
|
if (p != NULL) {
|
|
|
|
SPDK_WARNLOG("Please use \"%s\" instead of \"%s\"\n", "ANY", "ALL");
|
|
|
|
SPDK_WARNLOG("Converting \"%s\" to \"%s\" automatically\n", "ALL", "ANY");
|
2018-04-09 23:08:14 +00:00
|
|
|
memcpy(p, "ANY", 3);
|
2017-11-29 05:51:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ig->initiator_head, iname, tailq);
|
|
|
|
ig->ninitiators++;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "InitiatorName %s\n", name);
|
2017-11-15 00:14:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_initiator(struct spdk_iscsi_init_grp *ig, char *name)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_initiator_name *iname;
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
iname = iscsi_init_grp_find_initiator(ig, name);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (iname == NULL) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&ig->initiator_head, iname, tailq);
|
|
|
|
ig->ninitiators--;
|
|
|
|
free(iname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_add_initiators(struct spdk_iscsi_init_grp *ig, int num_inames,
|
|
|
|
char **inames)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for (i = 0; i < num_inames; i++) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_initiator(ig, inames[i]);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (rc < 0) {
|
2017-10-24 01:01:12 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (; i > 0; --i) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_initiator(ig, inames[i - 1]);
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
2017-11-15 00:14:27 +00:00
|
|
|
return rc;
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_all_initiators(struct spdk_iscsi_init_grp *ig)
|
2017-10-24 01:01:12 +00:00
|
|
|
{
|
2017-11-15 00:14:27 +00:00
|
|
|
struct spdk_iscsi_initiator_name *iname, *tmp;
|
2017-10-24 01:01:12 +00:00
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
TAILQ_FOREACH_SAFE(iname, &ig->initiator_head, tailq, tmp) {
|
|
|
|
TAILQ_REMOVE(&ig->initiator_head, iname, tailq);
|
|
|
|
ig->ninitiators--;
|
|
|
|
free(iname);
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
2017-11-15 00:14:27 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 23:22:00 +00:00
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_initiators(struct spdk_iscsi_init_grp *ig, int num_inames, char **inames)
|
2018-02-06 23:22:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for (i = 0; i < num_inames; i++) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_delete_initiator(ig, inames[i]);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (; i > 0; --i) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_initiator(ig, inames[i - 1]);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc != 0) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_all_initiators(ig);
|
2018-02-06 23:22:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
static struct spdk_iscsi_initiator_netmask *
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_find_netmask(struct spdk_iscsi_init_grp *ig, const char *mask)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_initiator_netmask *netmask;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(netmask, &ig->netmask_head, tailq) {
|
|
|
|
if (!strcmp(netmask->mask, mask)) {
|
|
|
|
return netmask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_add_netmask(struct spdk_iscsi_init_grp *ig, char *mask)
|
2017-10-24 01:01:12 +00:00
|
|
|
{
|
2017-11-15 00:14:27 +00:00
|
|
|
struct spdk_iscsi_initiator_netmask *imask;
|
2017-11-29 05:51:23 +00:00
|
|
|
char *p;
|
2019-06-28 00:24:49 +00:00
|
|
|
size_t len;
|
2017-10-24 01:01:12 +00:00
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
if (ig->nnetmasks >= MAX_NETMASK) {
|
|
|
|
SPDK_ERRLOG("> MAX_NETMASK(=%d) is not allowed\n", MAX_NETMASK);
|
2017-10-24 01:01:12 +00:00
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2019-06-28 00:24:49 +00:00
|
|
|
len = strlen(mask);
|
|
|
|
if (len > MAX_INITIATOR_ADDR) {
|
|
|
|
SPDK_ERRLOG("Initiator Name is larger than %d bytes\n", MAX_INITIATOR_ADDR);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
imask = iscsi_init_grp_find_netmask(ig, mask);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (imask != NULL) {
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
2019-06-28 00:24:49 +00:00
|
|
|
imask = calloc(1, sizeof(*imask));
|
2017-11-15 00:14:27 +00:00
|
|
|
if (imask == NULL) {
|
2017-12-26 20:59:09 +00:00
|
|
|
SPDK_ERRLOG("malloc() failed for inititator mask str\n");
|
2017-10-24 01:01:12 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-06-28 00:24:49 +00:00
|
|
|
memcpy(imask->mask, mask, len);
|
2017-11-15 00:14:27 +00:00
|
|
|
|
2017-11-29 05:51:23 +00:00
|
|
|
/* Replace "ALL" by "ANY" if set */
|
|
|
|
p = strstr(imask->mask, "ALL");
|
|
|
|
if (p != NULL) {
|
|
|
|
SPDK_WARNLOG("Please use \"%s\" instead of \"%s\"\n", "ANY", "ALL");
|
|
|
|
SPDK_WARNLOG("Converting \"%s\" to \"%s\" automatically\n", "ALL", "ANY");
|
2018-04-09 23:08:14 +00:00
|
|
|
memcpy(p, "ANY", 3);
|
2017-11-29 05:51:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ig->netmask_head, imask, tailq);
|
|
|
|
ig->nnetmasks++;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "Netmask %s\n", mask);
|
2017-11-15 00:14:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_netmask(struct spdk_iscsi_init_grp *ig, char *mask)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_initiator_netmask *imask;
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
imask = iscsi_init_grp_find_netmask(ig, mask);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (imask == NULL) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&ig->netmask_head, imask, tailq);
|
|
|
|
ig->nnetmasks--;
|
|
|
|
free(imask);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_add_netmasks(struct spdk_iscsi_init_grp *ig, int num_imasks, char **imasks)
|
2017-11-15 00:14:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for (i = 0; i < num_imasks; i++) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_netmask(ig, imasks[i]);
|
2017-11-15 00:14:27 +00:00
|
|
|
if (rc != 0) {
|
2017-10-24 01:01:12 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (; i > 0; --i) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_netmask(ig, imasks[i - 1]);
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
2017-11-15 00:14:27 +00:00
|
|
|
return rc;
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_all_netmasks(struct spdk_iscsi_init_grp *ig)
|
2017-10-24 01:01:12 +00:00
|
|
|
{
|
2017-11-15 00:14:27 +00:00
|
|
|
struct spdk_iscsi_initiator_netmask *imask, *tmp;
|
2017-10-24 01:01:12 +00:00
|
|
|
|
2017-11-15 00:14:27 +00:00
|
|
|
TAILQ_FOREACH_SAFE(imask, &ig->netmask_head, tailq, tmp) {
|
|
|
|
TAILQ_REMOVE(&ig->netmask_head, imask, tailq);
|
|
|
|
ig->nnetmasks--;
|
|
|
|
free(imask);
|
2017-10-24 01:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 23:22:00 +00:00
|
|
|
static int
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_netmasks(struct spdk_iscsi_init_grp *ig, int num_imasks, char **imasks)
|
2018-02-06 23:22:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for (i = 0; i < num_imasks; i++) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_delete_netmask(ig, imasks[i]);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (; i > 0; --i) {
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_netmask(ig, imasks[i - 1]);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc != 0) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_all_netmasks(ig);
|
2018-02-06 23:22:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-10-24 01:01:12 +00:00
|
|
|
|
2018-02-05 04:02:25 +00:00
|
|
|
int
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_register(struct spdk_iscsi_init_grp *ig)
|
2017-12-21 05:25:47 +00:00
|
|
|
{
|
2018-02-05 04:02:25 +00:00
|
|
|
struct spdk_iscsi_init_grp *tmp;
|
|
|
|
int rc = -1;
|
|
|
|
|
2017-12-21 05:25:47 +00:00
|
|
|
assert(ig != NULL);
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2020-04-15 21:39:41 +00:00
|
|
|
tmp = iscsi_init_grp_find_by_tag(ig->tag);
|
2018-02-05 04:02:25 +00:00
|
|
|
if (tmp == NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_iscsi.ig_head, ig, tailq);
|
2018-02-05 04:02:25 +00:00
|
|
|
rc = 0;
|
|
|
|
}
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-05 04:02:25 +00:00
|
|
|
|
|
|
|
return rc;
|
2017-12-21 05:25:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
/*
|
|
|
|
* Create initiator group from list of initiator ip/hostnames and netmasks
|
|
|
|
* The initiator hostname/netmask lists are allocated by the caller on the
|
|
|
|
* heap. Freed later by common initiator_group_destroy() code
|
|
|
|
*/
|
|
|
|
int
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_create_from_initiator_list(int tag,
|
2016-08-02 16:34:45 +00:00
|
|
|
int num_initiator_names,
|
|
|
|
char **initiator_names,
|
|
|
|
int num_initiator_masks,
|
|
|
|
char **initiator_masks)
|
|
|
|
{
|
2017-10-24 01:01:12 +00:00
|
|
|
int rc = -1;
|
2016-08-02 16:34:45 +00:00
|
|
|
struct spdk_iscsi_init_grp *ig = NULL;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi,
|
2016-08-02 16:34:45 +00:00
|
|
|
"add initiator group (from initiator list) tag=%d, #initiators=%d, #masks=%d\n",
|
|
|
|
tag, num_initiator_names, num_initiator_masks);
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
ig = iscsi_init_grp_create(tag);
|
2016-08-02 16:34:45 +00:00
|
|
|
if (!ig) {
|
2017-10-10 01:24:13 +00:00
|
|
|
SPDK_ERRLOG("initiator group create error (%d)\n", tag);
|
2017-10-24 01:01:12 +00:00
|
|
|
return rc;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_initiators(ig, num_initiator_names,
|
|
|
|
initiator_names);
|
2017-10-24 01:01:12 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add initiator name error\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_netmasks(ig, num_initiator_masks,
|
|
|
|
initiator_masks);
|
2017-10-24 01:01:12 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add initiator netmask error\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-15 21:39:41 +00:00
|
|
|
rc = iscsi_init_grp_register(ig);
|
2018-02-05 04:02:25 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("initiator group register error (%d)\n", tag);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_destroy(ig);
|
2016-08-02 16:34:45 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-02-06 23:22:00 +00:00
|
|
|
int
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_add_initiators_from_initiator_list(int tag,
|
2018-02-06 23:22:00 +00:00
|
|
|
int num_initiator_names,
|
|
|
|
char **initiator_names,
|
|
|
|
int num_initiator_masks,
|
|
|
|
char **initiator_masks)
|
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi,
|
2018-02-06 23:22:00 +00:00
|
|
|
"add initiator to initiator group: tag=%d, #initiators=%d, #masks=%d\n",
|
|
|
|
tag, num_initiator_names, num_initiator_masks);
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2020-04-15 21:39:41 +00:00
|
|
|
ig = iscsi_init_grp_find_by_tag(tag);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (!ig) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-06 23:22:00 +00:00
|
|
|
SPDK_ERRLOG("initiator group (%d) is not found\n", tag);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_initiators(ig, num_initiator_names,
|
|
|
|
initiator_names);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add initiator name error\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_add_netmasks(ig, num_initiator_masks,
|
|
|
|
initiator_masks);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add initiator netmask error\n");
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_initiators(ig, num_initiator_names,
|
|
|
|
initiator_names);
|
2018-02-06 23:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-06 23:22:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_delete_initiators_from_initiator_list(int tag,
|
2018-02-06 23:22:00 +00:00
|
|
|
int num_initiator_names,
|
|
|
|
char **initiator_names,
|
|
|
|
int num_initiator_masks,
|
|
|
|
char **initiator_masks)
|
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi,
|
2018-02-06 23:22:00 +00:00
|
|
|
"delete initiator from initiator group: tag=%d, #initiators=%d, #masks=%d\n",
|
|
|
|
tag, num_initiator_names, num_initiator_masks);
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2020-04-15 21:39:41 +00:00
|
|
|
ig = iscsi_init_grp_find_by_tag(tag);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (!ig) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-06 23:22:00 +00:00
|
|
|
SPDK_ERRLOG("initiator group (%d) is not found\n", tag);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_delete_initiators(ig, num_initiator_names,
|
|
|
|
initiator_names);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("delete initiator name error\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
rc = iscsi_init_grp_delete_netmasks(ig, num_initiator_masks,
|
|
|
|
initiator_masks);
|
2018-02-06 23:22:00 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("delete initiator netmask error\n");
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_add_initiators(ig, num_initiator_names,
|
|
|
|
initiator_names);
|
2018-02-06 23:22:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-06 23:22:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-02-05 04:02:25 +00:00
|
|
|
void
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_destroy(struct spdk_iscsi_init_grp *ig)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
if (!ig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_delete_all_initiators(ig);
|
|
|
|
iscsi_init_grp_delete_all_netmasks(ig);
|
2016-08-02 16:34:45 +00:00
|
|
|
free(ig);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct spdk_iscsi_init_grp *
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_find_by_tag(int tag)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(ig, &g_iscsi.ig_head, tailq) {
|
2016-08-02 16:34:45 +00:00
|
|
|
if (ig->tag == tag) {
|
|
|
|
return ig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grps_destroy(void)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig, *tmp;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(iscsi, "iscsi_init_grp_array_destroy\n");
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
TAILQ_FOREACH_SAFE(ig, &g_iscsi.ig_head, tailq, tmp) {
|
|
|
|
TAILQ_REMOVE(&g_iscsi.ig_head, ig, tailq);
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_destroy(ig);
|
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-02-05 04:02:25 +00:00
|
|
|
struct spdk_iscsi_init_grp *
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_unregister(int tag)
|
2018-02-05 04:02:25 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
|
|
|
TAILQ_FOREACH(ig, &g_iscsi.ig_head, tailq) {
|
2018-02-05 04:02:25 +00:00
|
|
|
if (ig->tag == tag) {
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_REMOVE(&g_iscsi.ig_head, ig, tailq);
|
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-02-05 04:02:25 +00:00
|
|
|
return ig;
|
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-02-05 04:02:25 +00:00
|
|
|
return NULL;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2018-05-09 22:55:12 +00:00
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_info_json(struct spdk_iscsi_init_grp *ig,
|
|
|
|
struct spdk_json_write_ctx *w)
|
2018-05-09 22:55:12 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_initiator_name *iname;
|
|
|
|
struct spdk_iscsi_initiator_netmask *imask;
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_int32(w, "tag", ig->tag);
|
|
|
|
|
|
|
|
spdk_json_write_named_array_begin(w, "initiators");
|
|
|
|
TAILQ_FOREACH(iname, &ig->initiator_head, tailq) {
|
|
|
|
spdk_json_write_string(w, iname->name);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_array_begin(w, "netmasks");
|
|
|
|
TAILQ_FOREACH(imask, &ig->netmask_head, tailq) {
|
|
|
|
spdk_json_write_string(w, imask->mask);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_config_json(struct spdk_iscsi_init_grp *ig,
|
|
|
|
struct spdk_json_write_ctx *w)
|
2018-05-09 22:55:12 +00:00
|
|
|
{
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2019-09-03 08:53:37 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "iscsi_create_initiator_group");
|
2018-05-09 22:55:12 +00:00
|
|
|
|
|
|
|
spdk_json_write_name(w, "params");
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_info_json(ig, w);
|
2018-05-09 22:55:12 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grps_info_json(struct spdk_json_write_ctx *w)
|
2018-05-09 22:55:12 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(ig, &g_iscsi.ig_head, tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_info_json(ig, w);
|
2018-05-09 22:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grps_config_json(struct spdk_json_write_ctx *w)
|
2018-05-09 22:55:12 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
TAILQ_FOREACH(ig, &g_iscsi.ig_head, tailq) {
|
2019-03-27 21:53:37 +00:00
|
|
|
iscsi_init_grp_config_json(ig, w);
|
2018-05-09 22:55:12 +00:00
|
|
|
}
|
|
|
|
}
|