target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Christie <mchristi@redhat.com>
To: target-devel@vger.kernel.org
Subject: [PATCH 11/15] target: export initiator port values for all sessions
Date: Sun, 15 Jul 2018 23:16:27 +0000	[thread overview]
Message-ID: <1531696591-8558-12-git-send-email-mchristi@redhat.com> (raw)

Export the initiator port info in configfs

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 drivers/target/target_core_fabric_configfs.c | 48 ++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c
index 497fa01..2deda28 100644
--- a/drivers/target/target_core_fabric_configfs.c
+++ b/drivers/target/target_core_fabric_configfs.c
@@ -897,6 +897,53 @@ static void target_fabric_drop_tpg(
 	config_item_put(item);
 }
 
+static ssize_t target_fabric_session_initiator_port_show(
+	struct config_item *item, char *page)
+{
+	struct se_session *se_sess = container_of(to_config_group(item),
+						  struct se_session, group);
+	ssize_t len;
+	int isid_len = 0;
+	unsigned long flags;
+
+	spin_lock_irqsave(&se_sess->configfs_lock, flags);
+	if (!se_sess->se_tpg) {
+		len = -ENOTCONN;
+		goto unlock;
+	}
+
+	if (se_sess->se_tpg->se_tpg_tfo->sess_get_initiator_sid)
+		isid_len = 15;
+
+	if (strlen(se_sess->se_node_acl->initiatorname) + isid_len + 1 >
+	    PAGE_SIZE) {
+		len = -EINVAL;
+		goto unlock;
+	}
+
+	if (se_sess->se_tpg->se_tpg_tfo->sess_get_initiator_sid) {
+		len = snprintf(page, PAGE_SIZE, "%s 0x%6phN\n",
+			       se_sess->se_node_acl->initiatorname,
+			       &se_sess->sess_bin_isid);
+	} else {
+		len = snprintf(page, PAGE_SIZE, "%s\n",
+			       se_sess->se_node_acl->initiatorname);
+	}
+	len += 1; /* Include NULL terminator */
+
+unlock:
+	spin_unlock_irqrestore(&se_sess->configfs_lock, flags);
+
+	return len;
+}
+
+CONFIGFS_ATTR_RO(target_fabric_session_, initiator_port);
+
+static struct configfs_attribute *target_fabric_session_attrs[] = {
+	&target_fabric_session_attr_initiator_port,
+	NULL,
+};
+
 static void target_fabric_session_release(struct config_item *item)
 {
 	struct se_session *se_sess = container_of(to_config_group(item),
@@ -918,6 +965,7 @@ int target_fabric_init_session(struct se_session *se_sess)
 
 	se_sess->cit.ct_owner = THIS_MODULE;
 	se_sess->cit.ct_item_ops = &target_session_item_ops;
+	se_sess->cit.ct_attrs = target_fabric_session_attrs;
 	config_group_init_type_name(&se_sess->group, name, &se_sess->cit);
 	kfree(name);
 	return 0;
-- 
2.7.2


             reply	other threads:[~2018-07-15 23:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-15 23:16 Mike Christie [this message]
2018-07-18 22:41 ` [PATCH 11/15] target: export initiator port values for all sessions Bart Van Assche
2018-07-18 23:04 ` Mike Christie
2018-07-19  2:15 ` Mike Christie
2018-07-19 15:37 ` Bart Van Assche
2018-07-19 15:38 ` Bart Van Assche
2018-07-19 16:38 ` Mike Christie
2018-07-19 17:07 ` Bart Van Assche
2018-07-19 20:47 ` Christoph Hellwig
2018-07-19 21:30 ` Mike Christie
2018-07-20 15:10 ` Christoph Hellwig
2018-08-01 16:44 ` Mike Christie
2018-08-01 17:11 ` Mike Christie
2018-08-01 17:38 ` Bart Van Assche

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=1531696591-8558-12-git-send-email-mchristi@redhat.com \
    --to=mchristi@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).