Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

target: use per-attribute show and store methods



This also allows to remove the target-specific old configfs macros, and
gets rid of the target_core_fabric_configfs.h header which only had one
function declaration left that could be moved to a better place.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
Acked-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 64c6be0e
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -203,8 +203,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
	buf += "#include <scsi/scsi_proto.h>\n\n"
	buf += "#include <target/target_core_base.h>\n"
	buf += "#include <target/target_core_fabric.h>\n"
	buf += "#include <target/target_core_fabric_configfs.h>\n"
	buf += "#include <target/configfs_macros.h>\n\n"
	buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
	buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"

@@ -283,19 +281,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
	buf += "				struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
	buf += "	kfree(" + fabric_mod_port + ");\n"
	buf += "}\n\n"
	buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
	buf += "	struct target_fabric_configfs *tf,\n"
	buf += "	char *page)\n"
	buf += "{\n"
	buf += "	return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
	buf += "		\"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
	buf += "		utsname()->machine);\n"
	buf += "}\n\n"
	buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
	buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
	buf += "	&" + fabric_mod_name + "_wwn_version.attr,\n"
	buf += "	NULL,\n"
	buf += "};\n\n"

	buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
	buf += "	.module				= THIS_MODULE,\n"
@@ -328,8 +313,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 += "\n"
	buf += "	.tfc_wwn_attrs			= " + fabric_mod_name + "_wwn_attrs,\n"
	buf += "};\n\n"

	buf += "static int __init " + fabric_mod_name + "_init(void)\n"
+34 −44
Original line number Diff line number Diff line
@@ -43,9 +43,7 @@
#include <linux/atomic.h>
#include <scsi/scsi_proto.h>
#include <scsi/scsi_tcq.h>
#include <target/configfs_macros.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric_configfs.h>
#include <target/target_core_fabric.h>
#include "ib_srpt.h"

@@ -3545,20 +3543,19 @@ static void srpt_cleanup_nodeacl(struct se_node_acl *se_nacl)
	spin_unlock_irq(&sport->port_acl_lock);
}

static ssize_t srpt_tpg_attrib_show_srp_max_rdma_size(
	struct se_portal_group *se_tpg,
static ssize_t srpt_tpg_attrib_srp_max_rdma_size_show(struct config_item *item,
		char *page)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);

	return sprintf(page, "%u\n", sport->port_attrib.srp_max_rdma_size);
}

static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t srpt_tpg_attrib_srp_max_rdma_size_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
	unsigned long val;
	int ret;
@@ -3583,22 +3580,19 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size(
	return count;
}

TF_TPG_ATTRIB_ATTR(srpt, srp_max_rdma_size, S_IRUGO | S_IWUSR);

static ssize_t srpt_tpg_attrib_show_srp_max_rsp_size(
	struct se_portal_group *se_tpg,
static ssize_t srpt_tpg_attrib_srp_max_rsp_size_show(struct config_item *item,
		char *page)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);

	return sprintf(page, "%u\n", sport->port_attrib.srp_max_rsp_size);
}

static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t srpt_tpg_attrib_srp_max_rsp_size_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
	unsigned long val;
	int ret;
@@ -3623,22 +3617,19 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size(
	return count;
}

TF_TPG_ATTRIB_ATTR(srpt, srp_max_rsp_size, S_IRUGO | S_IWUSR);

static ssize_t srpt_tpg_attrib_show_srp_sq_size(
	struct se_portal_group *se_tpg,
static ssize_t srpt_tpg_attrib_srp_sq_size_show(struct config_item *item,
		char *page)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);

	return sprintf(page, "%u\n", sport->port_attrib.srp_sq_size);
}

static ssize_t srpt_tpg_attrib_store_srp_sq_size(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t srpt_tpg_attrib_srp_sq_size_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = attrib_to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
	unsigned long val;
	int ret;
@@ -3663,29 +3654,29 @@ static ssize_t srpt_tpg_attrib_store_srp_sq_size(
	return count;
}

TF_TPG_ATTRIB_ATTR(srpt, srp_sq_size, S_IRUGO | S_IWUSR);
CONFIGFS_ATTR(srpt_tpg_attrib_,  srp_max_rdma_size);
CONFIGFS_ATTR(srpt_tpg_attrib_,  srp_max_rsp_size);
CONFIGFS_ATTR(srpt_tpg_attrib_,  srp_sq_size);

static struct configfs_attribute *srpt_tpg_attrib_attrs[] = {
	&srpt_tpg_attrib_srp_max_rdma_size.attr,
	&srpt_tpg_attrib_srp_max_rsp_size.attr,
	&srpt_tpg_attrib_srp_sq_size.attr,
	&srpt_tpg_attrib_attr_srp_max_rdma_size,
	&srpt_tpg_attrib_attr_srp_max_rsp_size,
	&srpt_tpg_attrib_attr_srp_sq_size,
	NULL,
};

static ssize_t srpt_tpg_show_enable(
	struct se_portal_group *se_tpg,
	char *page)
static ssize_t srpt_tpg_enable_show(struct config_item *item, char *page)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);

	return snprintf(page, PAGE_SIZE, "%d\n", (sport->enabled) ? 1: 0);
}

static ssize_t srpt_tpg_store_enable(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t srpt_tpg_enable_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
	unsigned long tmp;
        int ret;
@@ -3708,10 +3699,10 @@ static ssize_t srpt_tpg_store_enable(
	return count;
}

TF_TPG_BASE_ATTR(srpt, enable, S_IRUGO | S_IWUSR);
CONFIGFS_ATTR(srpt_tpg_, enable);

static struct configfs_attribute *srpt_tpg_attrs[] = {
	&srpt_tpg_enable.attr,
	&srpt_tpg_attr_enable,
	NULL,
};

@@ -3781,16 +3772,15 @@ static void srpt_drop_tport(struct se_wwn *wwn)
	pr_debug("drop_tport(%s\n", config_item_name(&sport->port_wwn.wwn_group.cg_item));
}

static ssize_t srpt_wwn_show_attr_version(struct target_fabric_configfs *tf,
					      char *buf)
static ssize_t srpt_wwn_version_show(struct config_item *item, char *buf)
{
	return scnprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
}

TF_WWN_ATTR_RO(srpt, version);
CONFIGFS_ATTR_RO(srpt_wwn_, version);

static struct configfs_attribute *srpt_wwn_attrs[] = {
	&srpt_wwn_version.attr,
	&srpt_wwn_attr_version,
	NULL,
};

+51 −102
Original line number Diff line number Diff line
@@ -43,8 +43,6 @@
#include <scsi/scsi_cmnd.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric.h>
#include <target/target_core_fabric_configfs.h>
#include <target/configfs_macros.h>

#include "qla_def.h"
#include "qla_target.h"
@@ -729,23 +727,23 @@ static int tcm_qla2xxx_init_nodeacl(struct se_node_acl *se_nacl,

#define DEF_QLA_TPG_ATTRIB(name)					\
									\
static ssize_t tcm_qla2xxx_tpg_attrib_show_##name(			\
	struct se_portal_group *se_tpg,					\
	char *page)							\
static ssize_t tcm_qla2xxx_tpg_attrib_##name##_show(			\
		struct config_item *item, char *page)			\
{									\
	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,		\
			struct tcm_qla2xxx_tpg, se_tpg);		\
									\
	return sprintf(page, "%u\n", tpg->tpg_attrib.name);	\
}									\
									\
static ssize_t tcm_qla2xxx_tpg_attrib_store_##name(			\
	struct se_portal_group *se_tpg,					\
	const char *page,						\
	size_t count)							\
static ssize_t tcm_qla2xxx_tpg_attrib_##name##_store(			\
		struct config_item *item, const char *page, size_t count) \
{									\
	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,		\
			struct tcm_qla2xxx_tpg, se_tpg);		\
	struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib;		\
	unsigned long val;						\
	int ret;							\
									\
@@ -755,81 +753,39 @@ static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
				" ret: %d\n", ret);			\
		return -EINVAL;						\
	}								\
	ret = tcm_qla2xxx_set_attrib_##name(tpg, val);			\
									\
	return (!ret) ? count : -EINVAL;				\
}

#define DEF_QLA_TPG_ATTR_BOOL(_name)					\
									\
static int tcm_qla2xxx_set_attrib_##_name(				\
	struct tcm_qla2xxx_tpg *tpg,					\
	unsigned long val)						\
{									\
	struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib;		\
									\
	if ((val != 0) && (val != 1)) {					\
		pr_err("Illegal boolean value %lu\n", val);		\
		return -EINVAL;						\
	}								\
									\
	a->_name = val;							\
	return 0;							\
}

#define QLA_TPG_ATTR(_name, _mode) \
	TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
	a->name = val;							\
									\
	return count;							\
}									\
CONFIGFS_ATTR(tcm_qla2xxx_tpg_attrib_, name)

/*
 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
 */
DEF_QLA_TPG_ATTR_BOOL(generate_node_acls);
DEF_QLA_TPG_ATTRIB(generate_node_acls);
QLA_TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);

/*
 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
 */
DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls);
DEF_QLA_TPG_ATTRIB(cache_dynamic_acls);
QLA_TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);

/*
 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
 */
DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect);
DEF_QLA_TPG_ATTRIB(demo_mode_write_protect);
QLA_TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);

/*
 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
 */
DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect);
DEF_QLA_TPG_ATTRIB(prod_mode_write_protect);
QLA_TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);

/*
 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
 */
DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only);
DEF_QLA_TPG_ATTRIB(demo_mode_login_only);
QLA_TPG_ATTR(demo_mode_login_only, S_IRUGO | S_IWUSR);

static struct configfs_attribute *tcm_qla2xxx_tpg_attrib_attrs[] = {
	&tcm_qla2xxx_tpg_attrib_generate_node_acls.attr,
	&tcm_qla2xxx_tpg_attrib_cache_dynamic_acls.attr,
	&tcm_qla2xxx_tpg_attrib_demo_mode_write_protect.attr,
	&tcm_qla2xxx_tpg_attrib_prod_mode_write_protect.attr,
	&tcm_qla2xxx_tpg_attrib_demo_mode_login_only.attr,
	&tcm_qla2xxx_tpg_attrib_attr_generate_node_acls,
	&tcm_qla2xxx_tpg_attrib_attr_cache_dynamic_acls,
	&tcm_qla2xxx_tpg_attrib_attr_demo_mode_write_protect,
	&tcm_qla2xxx_tpg_attrib_attr_prod_mode_write_protect,
	&tcm_qla2xxx_tpg_attrib_attr_demo_mode_login_only,
	NULL,
};

/* End items for tcm_qla2xxx_tpg_attrib_cit */

static ssize_t tcm_qla2xxx_tpg_show_enable(
	struct se_portal_group *se_tpg,
static ssize_t tcm_qla2xxx_tpg_enable_show(struct config_item *item,
		char *page)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
			struct tcm_qla2xxx_tpg, se_tpg);

@@ -865,11 +821,10 @@ static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
	complete(&base_tpg->tpg_base_comp);
}

static ssize_t tcm_qla2xxx_tpg_store_enable(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t tcm_qla2xxx_tpg_enable_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
			struct tcm_qla2xxx_tpg, se_tpg);
	unsigned long op;
@@ -909,22 +864,16 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
	return count;
}

TF_TPG_BASE_ATTR(tcm_qla2xxx, enable, S_IRUGO | S_IWUSR);

static ssize_t tcm_qla2xxx_tpg_show_dynamic_sessions(
	struct se_portal_group *se_tpg,
static ssize_t tcm_qla2xxx_tpg_dynamic_sessions_show(struct config_item *item,
		char *page)
{
	return target_show_dynamic_sessions(se_tpg, page);
	return target_show_dynamic_sessions(to_tpg(item), page);
}

TF_TPG_BASE_ATTR_RO(tcm_qla2xxx, dynamic_sessions);

static ssize_t tcm_qla2xxx_tpg_store_fabric_prot_type(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t tcm_qla2xxx_tpg_fabric_prot_type_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
				struct tcm_qla2xxx_tpg, se_tpg);
	unsigned long val;
@@ -943,21 +892,24 @@ static ssize_t tcm_qla2xxx_tpg_store_fabric_prot_type(
	return count;
}

static ssize_t tcm_qla2xxx_tpg_show_fabric_prot_type(
	struct se_portal_group *se_tpg,
static ssize_t tcm_qla2xxx_tpg_fabric_prot_type_show(struct config_item *item,
		char *page)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
				struct tcm_qla2xxx_tpg, se_tpg);

	return sprintf(page, "%d\n", tpg->tpg_attrib.fabric_prot_type);
}
TF_TPG_BASE_ATTR(tcm_qla2xxx, fabric_prot_type, S_IRUGO | S_IWUSR);

CONFIGFS_ATTR_WO(tcm_qla2xxx_tpg_, enable);
CONFIGFS_ATTR_RO(tcm_qla2xxx_tpg_, dynamic_sessions);
CONFIGFS_ATTR(tcm_qla2xxx_tpg_, fabric_prot_type);

static struct configfs_attribute *tcm_qla2xxx_tpg_attrs[] = {
	&tcm_qla2xxx_tpg_enable.attr,
	&tcm_qla2xxx_tpg_dynamic_sessions.attr,
	&tcm_qla2xxx_tpg_fabric_prot_type.attr,
	&tcm_qla2xxx_tpg_attr_enable,
	&tcm_qla2xxx_tpg_attr_dynamic_sessions,
	&tcm_qla2xxx_tpg_attr_fabric_prot_type,
	NULL,
};

@@ -1030,18 +982,16 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
	kfree(tpg);
}

static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
	struct se_portal_group *se_tpg,
static ssize_t tcm_qla2xxx_npiv_tpg_enable_show(struct config_item *item,
		char *page)
{
	return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
	return tcm_qla2xxx_tpg_enable_show(item, page);
}

static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
	struct se_portal_group *se_tpg,
	const char *page,
	size_t count)
static ssize_t tcm_qla2xxx_npiv_tpg_enable_store(struct config_item *item,
		const char *page, size_t count)
{
	struct se_portal_group *se_tpg = to_tpg(item);
	struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
	struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
			struct tcm_qla2xxx_lport, lport_wwn);
@@ -1077,10 +1027,10 @@ static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
	return count;
}

TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
CONFIGFS_ATTR(tcm_qla2xxx_npiv_tpg_, enable);

static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
        &tcm_qla2xxx_npiv_tpg_enable.attr,
        &tcm_qla2xxx_npiv_tpg_attr_enable,
        NULL,
};

@@ -1783,8 +1733,7 @@ static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn *wwn)
}


static ssize_t tcm_qla2xxx_wwn_show_attr_version(
	struct target_fabric_configfs *tf,
static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
		char *page)
{
	return sprintf(page,
@@ -1793,10 +1742,10 @@ static ssize_t tcm_qla2xxx_wwn_show_attr_version(
	    utsname()->machine);
}

TF_WWN_ATTR_RO(tcm_qla2xxx, version);
CONFIGFS_ATTR_RO(tcm_qla2xxx_wwn_, version);

static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = {
	&tcm_qla2xxx_wwn_version.attr,
	&tcm_qla2xxx_wwn_attr_version,
	NULL,
};

+271 −520

File changed.

Preview size limit exceeded, changes collapsed.

+262 −404

File changed.

Preview size limit exceeded, changes collapsed.

Loading