Commit c7d6a803 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger
Browse files

target: refactor init/drop_nodeacl methods



By always allocating and adding, respectively removing and freeing
the se_node_acl structure in core code we can remove tons of repeated
code in the init_nodeacl and drop_nodeacl routines.  Additionally
this now respects the get_default_queue_depth method in this code
path as well.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent e1750d20
Loading
Loading
Loading
Loading
+0 −77
Original line number Diff line number Diff line
@@ -50,15 +50,6 @@ def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
	buf = "#define " + fabric_mod_name.upper() + "_VERSION	\"v0.1\"\n"
	buf += "#define " + fabric_mod_name.upper() + "_NAMELEN	32\n"
	buf += "\n"
	buf += "struct " + fabric_mod_name + "_nacl {\n"
	buf += "	/* Binary World Wide unique Port Name for FC Initiator Nport */\n"
	buf += "	u64 nport_wwpn;\n"
	buf += "	/* ASCII formatted WWPN for FC Initiator Nport */\n"
	buf += "	char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
	buf += "	/* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
	buf += "	struct se_node_acl se_node_acl;\n"
	buf += "};\n"
	buf += "\n"
	buf += "struct " + fabric_mod_name + "_tpg {\n"
	buf += "	/* FC lport target portal group tag for TCM */\n"
	buf += "	u16 lport_tpgt;\n"
@@ -105,14 +96,6 @@ def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
	buf = "#define " + fabric_mod_name.upper() + "_VERSION  \"v0.1\"\n"
	buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
	buf += "\n"
	buf += "struct " + fabric_mod_name + "_nacl {\n"
	buf += "	/* Binary World Wide unique Port Name for SAS Initiator port */\n"
	buf += "	u64 iport_wwpn;\n"
	buf += "	/* ASCII formatted WWPN for Sas Initiator port */\n"
	buf += "	char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
	buf += "	/* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
	buf += "	struct se_node_acl se_node_acl;\n"
	buf += "};\n\n"
	buf += "struct " + fabric_mod_name + "_tpg {\n"
	buf += "	/* SAS port target portal group tag for TCM */\n"
	buf += "	u16 tport_tpgt;\n"
@@ -158,12 +141,6 @@ def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
	buf = "#define " + fabric_mod_name.upper() + "_VERSION  \"v0.1\"\n"
	buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
	buf += "\n"
	buf += "struct " + fabric_mod_name + "_nacl {\n"
	buf += "	/* ASCII formatted InitiatorName */\n"
	buf += "	char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
	buf += "	/* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
	buf += "	struct se_node_acl se_node_acl;\n"
	buf += "};\n\n"
	buf += "struct " + fabric_mod_name + "_tpg {\n"
	buf += "	/* iSCSI target portal group tag for TCM */\n"
	buf += "	u16 tport_tpgt;\n"
@@ -239,54 +216,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):

	buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n"

	buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
	buf += "	struct se_portal_group *se_tpg,\n"
	buf += "	struct config_group *group,\n"
	buf += "	const char *name)\n"
	buf += "{\n"
	buf += "	struct se_node_acl *se_nacl, *se_nacl_new;\n"
	buf += "	struct " + fabric_mod_name + "_nacl *nacl;\n"

	if proto_ident == "FC" or proto_ident == "SAS":
		buf += "	u64 wwpn = 0;\n"

	buf += "	u32 nexus_depth;\n\n"
	buf += "	/* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
	buf += "		return ERR_PTR(-EINVAL); */\n"
	buf += "	se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
	buf += "	if (!se_nacl_new)\n"
	buf += "		return ERR_PTR(-ENOMEM);\n"
	buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
	buf += "	nexus_depth = 1;\n"
	buf += "	/*\n"
	buf += "	 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
	buf += "	 * when converting a NodeACL from demo mode -> explict\n"
	buf += "	 */\n"
	buf += "	se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
	buf += "				name, nexus_depth);\n"
	buf += "	if (IS_ERR(se_nacl)) {\n"
	buf += "		" + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
	buf += "		return se_nacl;\n"
	buf += "	}\n"
	buf += "	/*\n"
	buf += "	 * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
	buf += "	 */\n"
	buf += "	nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"

	if proto_ident == "FC" or proto_ident == "SAS":
		buf += "	nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"

	buf += "	/* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
	buf += "	return se_nacl;\n"
	buf += "}\n\n"
	buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
	buf += "{\n"
	buf += "	struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
	buf += "				struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
	buf += "	core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
	buf += "	kfree(nacl);\n"
	buf += "}\n\n"

	buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
	buf += "	struct se_wwn *wwn,\n"
	buf += "	struct config_group *group,\n"
@@ -408,12 +337,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
	buf += "	.fabric_drop_wwn		= " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
	buf += "	.fabric_make_tpg		= " + fabric_mod_name + "_make_tpg,\n"
	buf += "	.fabric_drop_tpg		= " + fabric_mod_name + "_drop_tpg,\n"
	buf += "	.fabric_post_link		= NULL,\n"
	buf += "	.fabric_pre_unlink		= NULL,\n"
	buf += "	.fabric_make_np			= NULL,\n"
	buf += "	.fabric_drop_np			= NULL,\n"
	buf += "	.fabric_make_nodeacl		= " + fabric_mod_name + "_make_nodeacl,\n"
	buf += "	.fabric_drop_nodeacl		= " + fabric_mod_name + "_drop_nodeacl,\n"
	buf += "\n"
	buf += "	.tfc_wwn_attrs			= " + fabric_mod_name + "_wwn_attrs;\n"
	buf += "};\n\n"
+2 −2
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@ fabric skeleton, by simply using:
This script will create a new drivers/target/$TCM_NEW_MOD/, and will do the following

	*) Generate new API callers for drivers/target/target_core_fabric_configs.c logic
	   ->make_nodeacl(), ->drop_nodeacl(), ->make_tpg(), ->drop_tpg()
	   ->make_wwn(), ->drop_wwn().  These are created into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c
	   ->make_tpg(), ->drop_tpg(), ->make_wwn(), ->drop_wwn().  These are created
	   into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c
	*) Generate basic infrastructure for loading/unloading LKMs and TCM/ConfigFS fabric module
	   using a skeleton struct target_core_fabric_ops API template.
	*) Based on user defined T10 Proto_Ident for the new fabric module being built,
+13 −45
Original line number Diff line number Diff line
@@ -3592,40 +3592,19 @@ out:
 * configfs callback function invoked for
 * mkdir /sys/kernel/config/target/$driver/$port/$tpg/acls/$i_port_id
 */
static struct se_node_acl *srpt_make_nodeacl(struct se_portal_group *tpg,
					     struct config_group *group,
					     const char *name)
static int srpt_init_nodeacl(struct se_node_acl *se_nacl, const char *name)
{
	struct srpt_port *sport = container_of(tpg, struct srpt_port, port_tpg_1);
	struct se_node_acl *se_nacl, *se_nacl_new;
	struct srpt_node_acl *nacl;
	int ret = 0;
	u32 nexus_depth = 1;
	struct srpt_port *sport =
		container_of(se_nacl->se_tpg, struct srpt_port, port_tpg_1);
	struct srpt_node_acl *nacl =
		container_of(se_nacl, struct srpt_node_acl, nacl);
	u8 i_port_id[16];

	if (srpt_parse_i_port_id(i_port_id, name) < 0) {
		pr_err("invalid initiator port ID %s\n", name);
		ret = -EINVAL;
		goto err;
		return -EINVAL;
	}

	se_nacl_new = srpt_alloc_fabric_acl(tpg);
	if (!se_nacl_new) {
		ret = -ENOMEM;
		goto err;
	}
	/*
	 * nacl_new may be released by core_tpg_add_initiator_node_acl()
	 * when converting a node ACL from demo mode to explict
	 */
	se_nacl = core_tpg_add_initiator_node_acl(tpg, se_nacl_new, name,
						  nexus_depth);
	if (IS_ERR(se_nacl)) {
		ret = PTR_ERR(se_nacl);
		goto err;
	}
	/* Locate our struct srpt_node_acl and set sdev and i_port_id. */
	nacl = container_of(se_nacl, struct srpt_node_acl, nacl);
	memcpy(&nacl->i_port_id[0], &i_port_id[0], 16);
	nacl->sport = sport;

@@ -3633,29 +3612,22 @@ static struct se_node_acl *srpt_make_nodeacl(struct se_portal_group *tpg,
	list_add_tail(&nacl->list, &sport->port_acl_list);
	spin_unlock_irq(&sport->port_acl_lock);

	return se_nacl;
err:
	return ERR_PTR(ret);
	return 0;
}

/*
 * configfs callback function invoked for
 * rmdir /sys/kernel/config/target/$driver/$port/$tpg/acls/$i_port_id
 */
static void srpt_drop_nodeacl(struct se_node_acl *se_nacl)
static void srpt_cleanup_nodeacl(struct se_node_acl *se_nacl)
{
	struct srpt_node_acl *nacl;
	struct srpt_device *sdev;
	struct srpt_port *sport;
	struct srpt_node_acl *nacl =
		container_of(se_nacl, struct srpt_node_acl, nacl);
	struct srpt_port *sport = nacl->sport;

	nacl = container_of(se_nacl, struct srpt_node_acl, nacl);
	sport = nacl->sport;
	sdev = sport->sdev;
	spin_lock_irq(&sport->port_acl_lock);
	list_del(&nacl->list);
	spin_unlock_irq(&sport->port_acl_lock);
	core_tpg_del_initiator_node_acl(&sport->port_tpg_1, se_nacl, 1);
	srpt_release_fabric_acl(NULL, se_nacl);
}

static ssize_t srpt_tpg_attrib_show_srp_max_rdma_size(
@@ -3948,12 +3920,8 @@ static const struct target_core_fabric_ops srpt_template = {
	.fabric_drop_wwn		= srpt_drop_tport,
	.fabric_make_tpg		= srpt_make_tpg,
	.fabric_drop_tpg		= srpt_drop_tpg,
	.fabric_post_link		= NULL,
	.fabric_pre_unlink		= NULL,
	.fabric_make_np			= NULL,
	.fabric_drop_np			= NULL,
	.fabric_make_nodeacl		= srpt_make_nodeacl,
	.fabric_drop_nodeacl		= srpt_drop_nodeacl,
	.fabric_init_nodeacl		= srpt_init_nodeacl,
	.fabric_cleanup_nodeacl		= srpt_cleanup_nodeacl,

	.tfc_wwn_attrs			= srpt_wwn_attrs,
	.tfc_tpg_base_attrs		= srpt_tpg_attrs,
+8 −51
Original line number Diff line number Diff line
@@ -847,53 +847,20 @@ static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess *sess)
	target_sess_cmd_list_set_waiting(sess->se_sess);
}

static struct se_node_acl *tcm_qla2xxx_make_nodeacl(
	struct se_portal_group *se_tpg,
	struct config_group *group,
static int tcm_qla2xxx_init_nodeacl(struct se_node_acl *se_nacl,
		const char *name)
{
	struct se_node_acl *se_nacl, *se_nacl_new;
	struct tcm_qla2xxx_nacl *nacl;
	struct tcm_qla2xxx_nacl *nacl =
		container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
	u64 wwnn;
	u32 qla2xxx_nexus_depth;

	if (tcm_qla2xxx_parse_wwn(name, &wwnn, 1) < 0)
		return ERR_PTR(-EINVAL);

	se_nacl_new = tcm_qla2xxx_alloc_fabric_acl(se_tpg);
	if (!se_nacl_new)
		return ERR_PTR(-ENOMEM);
/* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
	qla2xxx_nexus_depth = 1;
		return -EINVAL;

	/*
	 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
	 * when converting a NodeACL from demo mode -> explict
	 */
	se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
				name, qla2xxx_nexus_depth);
	if (IS_ERR(se_nacl)) {
		tcm_qla2xxx_release_fabric_acl(se_tpg, se_nacl_new);
		return se_nacl;
	}
	/*
	 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
	 */
	nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
	nacl->nport_wwnn = wwnn;
	tcm_qla2xxx_format_wwn(&nacl->nport_name[0], TCM_QLA2XXX_NAMELEN, wwnn);

	return se_nacl;
}

static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl *se_acl)
{
	struct se_portal_group *se_tpg = se_acl->se_tpg;
	struct tcm_qla2xxx_nacl *nacl = container_of(se_acl,
				struct tcm_qla2xxx_nacl, se_node_acl);

	core_tpg_del_initiator_node_acl(se_tpg, se_acl, 1);
	kfree(nacl);
	return 0;
}

/* Start items for tcm_qla2xxx_tpg_attrib_cit */
@@ -2024,12 +1991,7 @@ static const struct target_core_fabric_ops tcm_qla2xxx_ops = {
	.fabric_drop_wwn		= tcm_qla2xxx_drop_lport,
	.fabric_make_tpg		= tcm_qla2xxx_make_tpg,
	.fabric_drop_tpg		= tcm_qla2xxx_drop_tpg,
	.fabric_post_link		= NULL,
	.fabric_pre_unlink		= NULL,
	.fabric_make_np			= NULL,
	.fabric_drop_np			= NULL,
	.fabric_make_nodeacl		= tcm_qla2xxx_make_nodeacl,
	.fabric_drop_nodeacl		= tcm_qla2xxx_drop_nodeacl,
	.fabric_init_nodeacl		= tcm_qla2xxx_init_nodeacl,

	.tfc_wwn_attrs			= tcm_qla2xxx_wwn_attrs,
	.tfc_tpg_base_attrs		= tcm_qla2xxx_tpg_attrs,
@@ -2079,12 +2041,7 @@ static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
	.fabric_drop_wwn		= tcm_qla2xxx_npiv_drop_lport,
	.fabric_make_tpg		= tcm_qla2xxx_npiv_make_tpg,
	.fabric_drop_tpg		= tcm_qla2xxx_drop_tpg,
	.fabric_post_link		= NULL,
	.fabric_pre_unlink		= NULL,
	.fabric_make_np			= NULL,
	.fabric_drop_np			= NULL,
	.fabric_make_nodeacl		= tcm_qla2xxx_make_nodeacl,
	.fabric_drop_nodeacl		= tcm_qla2xxx_drop_nodeacl,
	.fabric_init_nodeacl		= tcm_qla2xxx_init_nodeacl,

	.tfc_wwn_attrs			= tcm_qla2xxx_wwn_attrs,
	.tfc_tpg_base_attrs		= tcm_qla2xxx_npiv_tpg_attrs,
+10 −39
Original line number Diff line number Diff line
@@ -874,43 +874,19 @@ static struct se_node_acl *lio_tpg_alloc_fabric_acl(
	return &acl->se_node_acl;
}

static struct se_node_acl *lio_target_make_nodeacl(
	struct se_portal_group *se_tpg,
	struct config_group *group,
static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
		const char *name)
{
	struct config_group *stats_cg;
	struct iscsi_node_acl *acl;
	struct se_node_acl *se_nacl_new, *se_nacl;
	struct iscsi_portal_group *tpg = container_of(se_tpg,
			struct iscsi_portal_group, tpg_se_tpg);
	u32 cmdsn_depth;

	se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg);
	if (!se_nacl_new)
		return ERR_PTR(-ENOMEM);

	cmdsn_depth = tpg->tpg_attrib.default_cmdsn_depth;
	/*
	 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
	 * when converting a NdoeACL from demo mode -> explict
	 */
	se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
				name, cmdsn_depth);
	if (IS_ERR(se_nacl))
		return se_nacl;

	acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
	stats_cg = &se_nacl->acl_fabric_stat_group;
	struct iscsi_node_acl *acl =
		container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
	struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group;

	stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
				GFP_KERNEL);
	if (!stats_cg->default_groups) {
		pr_err("Unable to allocate memory for"
				" stats_cg->default_groups\n");
		core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
		kfree(acl);
		return ERR_PTR(-ENOMEM);
		return -ENOMEM;
	}

	stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group;
@@ -918,13 +894,11 @@ static struct se_node_acl *lio_target_make_nodeacl(
	config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
			"iscsi_sess_stats", &iscsi_stat_sess_cit);

	return se_nacl;
	return 0;
}

static void lio_target_drop_nodeacl(
	struct se_node_acl *se_nacl)
static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
{
	struct se_portal_group *se_tpg = se_nacl->se_tpg;
	struct iscsi_node_acl *acl = container_of(se_nacl,
			struct iscsi_node_acl, se_node_acl);
	struct config_item *df_item;
@@ -938,9 +912,6 @@ static void lio_target_drop_nodeacl(
		config_item_put(df_item);
	}
	kfree(stats_cg->default_groups);

	core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
	kfree(acl);
}

/* End items for lio_target_acl_cit */
@@ -2020,8 +1991,8 @@ const struct target_core_fabric_ops iscsi_ops = {
	.fabric_drop_tpg		= lio_target_tiqn_deltpg,
	.fabric_make_np			= lio_target_call_addnptotpg,
	.fabric_drop_np			= lio_target_call_delnpfromtpg,
	.fabric_make_nodeacl		= lio_target_make_nodeacl,
	.fabric_drop_nodeacl		= lio_target_drop_nodeacl,
	.fabric_init_nodeacl		= lio_target_init_nodeacl,
	.fabric_cleanup_nodeacl		= lio_target_cleanup_nodeacl,

	.tfc_discovery_attrs		= lio_target_discovery_auth_attrs,
	.tfc_wwn_attrs			= lio_target_wwn_attrs,
Loading