From: Dmitry Bogdanov <d.bogdanov@yadro.com>
To: Martin Petersen <martin.petersen@oracle.com>,
<target-devel@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
Mike Christie <michael.christie@oracle.com>,
<linux-scsi@vger.kernel.org>, <linux@yadro.com>,
Dmitry Bogdanov <d.bogdanov@yadro.com>
Subject: [PATCH v5 1/4] scsi: target: core: Add RTPI field to target port
Date: Wed, 1 Mar 2023 11:45:09 +0300 [thread overview]
Message-ID: <20230301084512.21956-2-d.bogdanov@yadro.com> (raw)
In-Reply-To: <20230301084512.21956-1-d.bogdanov@yadro.com>
SAM-5 4.6.5.2 (Relative Port Identifier attribute) defines the attribute
as unique across SCSI target ports.
The change introduces RTPI attribute to se_portal group. The value is
unique across all enabled SCSI target ports. It also limits number of
SCSI target ports to 65535.
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
v4:
use unused variable in target_tpg_disable
make tpg_rtpi variable u16 again
v3:
make variable static
change core_ prefix to target_
split to tpg_enable/tpg_disable functions
v2:
rewrite using XArray to track usage of RTPI
---
drivers/target/target_core_fabric_configfs.c | 9 ++--
drivers/target/target_core_internal.h | 2 +
drivers/target/target_core_tpg.c | 54 ++++++++++++++++++++
include/target/target_core_base.h | 2 +
4 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c
index 67b18a67317a..873da49ab704 100644
--- a/drivers/target/target_core_fabric_configfs.c
+++ b/drivers/target/target_core_fabric_configfs.c
@@ -836,13 +836,12 @@ static ssize_t target_fabric_tpg_base_enable_store(struct config_item *item,
if (se_tpg->enabled == op)
return count;
-
- ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, op);
+ if (op)
+ ret = target_tpg_enable(se_tpg);
+ else
+ ret = target_tpg_disable(se_tpg);
if (ret)
return ret;
-
- se_tpg->enabled = op;
-
return count;
}
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 38a6d08f75b3..82fd5768a662 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -132,6 +132,8 @@ void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg,
const char *initiatorname);
void core_tpg_del_initiator_node_acl(struct se_node_acl *acl);
+int target_tpg_enable(struct se_portal_group *se_tpg);
+int target_tpg_disable(struct se_portal_group *se_tpg);
/* target_core_transport.c */
int init_se_kmem_caches(void);
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 736847c933e5..0de3385b94c5 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -31,6 +31,7 @@
#include "target_core_ua.h"
extern struct se_device *g_lun0_dev;
+static DEFINE_XARRAY_ALLOC(tpg_xa);
/* __core_tpg_get_initiator_node_acl():
*
@@ -439,6 +440,57 @@ static void core_tpg_lun_ref_release(struct percpu_ref *ref)
complete(&lun->lun_shutdown_comp);
}
+static int target_tpg_register_rtpi(struct se_portal_group *se_tpg)
+{
+ u32 val;
+ int ret;
+
+ ret = xa_alloc(&tpg_xa, &val, se_tpg,
+ XA_LIMIT(1, USHRT_MAX), GFP_KERNEL);
+ if (!ret)
+ se_tpg->tpg_rtpi = val;
+
+ return ret;
+}
+
+static void target_tpg_deregister_rtpi(struct se_portal_group *se_tpg)
+{
+ if (se_tpg->tpg_rtpi && se_tpg->enabled)
+ xa_erase(&tpg_xa, se_tpg->tpg_rtpi);
+}
+
+int target_tpg_enable(struct se_portal_group *se_tpg)
+{
+ int ret;
+
+ ret = target_tpg_register_rtpi(se_tpg);
+ if (ret)
+ return ret;
+
+ ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, true);
+ if (ret) {
+ target_tpg_deregister_rtpi(se_tpg);
+ return ret;
+ }
+
+ se_tpg->enabled = true;
+
+ return 0;
+}
+
+int target_tpg_disable(struct se_portal_group *se_tpg)
+{
+ int ret;
+
+ target_tpg_deregister_rtpi(se_tpg);
+
+ ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, false);
+ if (!ret)
+ se_tpg->enabled = false;
+
+ return ret;
+}
+
/* Does not change se_wwn->priv. */
int core_tpg_register(
struct se_wwn *se_wwn,
@@ -535,6 +587,8 @@ int core_tpg_deregister(struct se_portal_group *se_tpg)
kfree_rcu(se_tpg->tpg_virt_lun0, rcu_head);
}
+ target_tpg_deregister_rtpi(se_tpg);
+
return 0;
}
EXPORT_SYMBOL(core_tpg_deregister);
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 12c9ba16217e..814edf746395 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -920,6 +920,8 @@ struct se_portal_group {
*/
int proto_id;
bool enabled;
+ /* RELATIVE TARGET PORT IDENTIFIER */
+ u16 tpg_rtpi;
/* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
atomic_t tpg_pr_ref_count;
/* Spinlock for adding/removing ACLed Nodes */
--
2.25.1
next prev parent reply other threads:[~2023-03-01 8:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 8:45 [PATCH v5 0/5] scsi: target: make RTPI an TPG identifier Dmitry Bogdanov
2023-03-01 8:45 ` Dmitry Bogdanov [this message]
2023-03-01 8:45 ` [PATCH v5 2/4] scsi: target: core: Use RTPI from target port Dmitry Bogdanov
2023-03-01 8:45 ` [PATCH v5 3/4] scsi: target: core: Drop device-based RTPI Dmitry Bogdanov
2023-03-01 8:45 ` [PATCH v5 4/4] scsi: target: core: Add RTPI attribute for target port Dmitry Bogdanov
2023-03-07 17:33 ` [PATCH v5 0/5] scsi: target: make RTPI an TPG identifier Mike Christie
2023-03-10 2:37 ` Martin K. Petersen
2023-03-17 4:04 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230301084512.21956-2-d.bogdanov@yadro.com \
--to=d.bogdanov@yadro.com \
--cc=hch@infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux@yadro.com \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.