Commit 10d62184 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

lib/iscsi: Create portal group as public or private portal group



In SPDK iSCSI target, portal group works almost as identifier of
portal.

To support iSCSI login redirection, we need to have two types of
portal groups, public and private portal groups.

We need portals of public portal groups to redirect to a portal in
a private portal groups at login via temporary login redirection
funciton, and we need to make SendTargets return only portals in
public portal groups.

To do these simply, we mark primary or secondary portal group expicitly
at its creation by this patch.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Iccf87a4b9dd1f4a8fbb857a399b8f2dbc7c0b3ab
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3491


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 0f22282f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -3868,7 +3868,8 @@ Example response:
          "port": "3260"
        }
      ],
      "tag": 1
      "tag": 1,
      "private": false
    }
  ]
}
@@ -3884,6 +3885,7 @@ Name | Optional | Type | Description
--------------------------- | -------- | --------| -----------
tag                         | Required | number  | Portal group tag
portals                     | Required | array   | Not empty array of portals
private                     | Optional | boolean | When true, portals in this group are not returned by a discovery session. Used for login redirection. (default: `false`)

Portal object

+3 −1
Original line number Diff line number Diff line
@@ -731,6 +731,7 @@ struct rpc_portal_list {
struct rpc_portal_group {
	int32_t tag;
	struct rpc_portal_list portal_list;
	bool is_private;
};

static void
@@ -784,6 +785,7 @@ decode_rpc_portal_list(const struct spdk_json_val *val, void *out)
static const struct spdk_json_object_decoder rpc_portal_group_decoders[] = {
	{"tag", offsetof(struct rpc_portal_group, tag), spdk_json_decode_int32},
	{"portals", offsetof(struct rpc_portal_group, portal_list), decode_rpc_portal_list},
	{"private", offsetof(struct rpc_portal_group, is_private), spdk_json_decode_bool, true},
};

static void
@@ -804,7 +806,7 @@ rpc_iscsi_create_portal_group(struct spdk_jsonrpc_request *request,
		goto out;
	}

	pg = iscsi_portal_grp_create(req.tag);
	pg = iscsi_portal_grp_create(req.tag, req.is_private);
	if (pg == NULL) {
		SPDK_ERRLOG("portal_grp_create failed\n");
		goto out;
+5 −2
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ iscsi_parse_redirect_addr(struct sockaddr_storage *sa,
}

struct spdk_iscsi_portal_grp *
iscsi_portal_grp_create(int tag)
iscsi_portal_grp_create(int tag, bool is_private)
{
	struct spdk_iscsi_portal_grp *pg = malloc(sizeof(*pg));

@@ -317,6 +317,7 @@ iscsi_portal_grp_create(int tag)

	pg->ref = 0;
	pg->tag = tag;
	pg->is_private = is_private;

	pthread_mutex_lock(&g_iscsi.mutex);
	pg->disable_chap = g_iscsi.disable_chap;
@@ -425,7 +426,7 @@ iscsi_parse_portal_grp(struct spdk_conf_section *sp)
		SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Comment %s\n", val);
	}

	pg = iscsi_portal_grp_create(spdk_conf_section_get_num(sp));
	pg = iscsi_portal_grp_create(spdk_conf_section_get_num(sp), false);
	if (!pg) {
		SPDK_ERRLOG("portal group malloc error (%s)\n", spdk_conf_section_get_name(sp));
		return -1;
@@ -653,6 +654,8 @@ iscsi_portal_grp_info_json(struct spdk_iscsi_portal_grp *pg,
	}
	spdk_json_write_array_end(w);

	spdk_json_write_named_bool(w, "private", pg->is_private);

	spdk_json_write_object_end(w);
}

+11 −1
Original line number Diff line number Diff line
@@ -54,6 +54,16 @@ struct spdk_iscsi_portal {
struct spdk_iscsi_portal_grp {
	int					ref;
	int					tag;

	/* For login redirection, there are two types of portal groups, public and
	 * private portal groups. Public portal groups have their portals returned
	 * by a discovery session. Private portal groups do not have their portals
	 * returned by a discovery session. A public portal group may optionally
	 * specify a redirect portal for non-discovery logins. This redirect portal
	 * must be from a private portal group.
	 */
	bool					is_private;

	bool					disable_chap;
	bool					require_chap;
	bool					mutual_chap;
@@ -67,7 +77,7 @@ struct spdk_iscsi_portal_grp {
struct spdk_iscsi_portal *iscsi_portal_create(const char *host, const char *port);
void iscsi_portal_destroy(struct spdk_iscsi_portal *p);

struct spdk_iscsi_portal_grp *iscsi_portal_grp_create(int tag);
struct spdk_iscsi_portal_grp *iscsi_portal_grp_create(int tag, bool is_private);
void iscsi_portal_grp_add_portal(struct spdk_iscsi_portal_grp *pg,
				 struct spdk_iscsi_portal *p);
struct spdk_iscsi_portal *iscsi_portal_grp_find_portal_by_addr(
+6 −1
Original line number Diff line number Diff line
@@ -1103,7 +1103,8 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
        rpc.iscsi.iscsi_create_portal_group(
            args.client,
            portals=portals,
            tag=args.tag)
            tag=args.tag,
            private=args.private)

    p = subparsers.add_parser('iscsi_create_portal_group', aliases=['add_portal_group'],
                              help='Add a portal group')
@@ -1111,6 +1112,10 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
        'tag', help='Portal group tag (unique, integer > 0)', type=int)
    p.add_argument('portal_list', help="""List of portals in host:port format, separated by whitespace
    Example: '192.168.100.100:3260 192.168.100.100:3261 192.168.100.100:3262""")
    p.add_argument('-p', '--private', help="""Public (false) or private (true) portal group.
    Private portal groups do not have their portals returned by a discovery session. A public
    portal group may optionally specify a redirect portal for non-discovery logins. This redirect
    portal must be from a private portal group.""", action='store_true')
    p.set_defaults(func=iscsi_create_portal_group)

    def iscsi_create_initiator_group(args):
Loading