Skip to contentSkip to conversation

target: add session dir in configfs

PATCH Applied Mike Christie 2 participants 3 messages Jul 15, 2018 – Jul 18, 2018 SCSI target

lore
Share & tools
lore
#0 lore raw

PATCH 9/15 target: add session dir in configfs

Drivers like iscsi will dump one of the session's info in a info file under the acl. The problem with this is that it only prints one session and only sessions with an acl.

Then there is a dynamic_sessions file which dumps the initiator name of each session without an acl. The problem with this is that the info printed is limited to only the node name. For iscsi we do not get the entire initiator port string (name + isid). Also all dynamic sessions are printed in one file so setups that do a target per lun quickly run out of space.

To handle all these issues, this patch adds a per session dir under the tpg. We can then export info like initiator name and if needed isid. These patches will then also add some files to test sessions.

TODO:
1. handle target_fabric_register_session failure in iscsi target.

---
 drivers/target/iscsi/iscsi_target.c          |  4 ++
 drivers/target/iscsi/iscsi_target_login.c    |  3 ++
 drivers/target/target_core_fabric_configfs.c | 47 +++++++++++++++++++++++
 drivers/target/target_core_internal.h        |  2 +
 drivers/target/target_core_transport.c       | 57 ++++++++++++++++++++--------
 include/target/target_core_base.h            |  3 ++
 include/target/target_core_fabric.h          |  5 ++-
 7 files changed, 105 insertions(+), 16 deletions(-)
drivers/target/iscsi/iscsi_target.c +4 -0
index 6d81a59..793ee98 100644
@@ -4324,6 +4324,10 @@ int iscsit_close_session(struct iscsi_session *sess)
 	iscsit_stop_time2retain_timer(sess);
 	spin_unlock_bh(&se_tpg->session_lock);
 
+
+	if (tpg != iscsit_global->discovery_tpg)
+		target_fabric_unregister_session(sess->se_sess);
+
 	/*
 	 * transport_deregister_session_configfs() will clear the
 	 * struct se_node_acl->nacl_sess pointer now as a iscsi_np process context
drivers/target/iscsi/iscsi_target_login.c +3 -0
index d6a4b93..48a9522 100644
@@ -778,6 +778,9 @@ void iscsi_post_login_handler(
 
 	iscsit_determine_maxcmdsn(sess);
 
+	if (tpg != iscsit_global->discovery_tpg)
+		target_fabric_register_session(se_tpg, se_sess);
+
 	spin_lock_bh(&se_tpg->session_lock);
 	__transport_register_session(&sess->tpg->tpg_se_tpg,
 			se_sess->se_node_acl, se_sess, sess);
drivers/target/target_core_fabric_configfs.c +47 -0

59 lines not on this page · raw message

drivers/target/target_core_internal.h +2 -0
index 0c66355..73c90ae 100644
@@ -44,6 +44,7 @@ struct target_fabric_configfs {
 	struct config_item_type tf_tpg_attrib_cit;
 	struct config_item_type tf_tpg_auth_cit;
 	struct config_item_type tf_tpg_param_cit;
+	struct config_item_type tf_tpg_session_cit;
 	struct config_item_type tf_tpg_nacl_cit;
 	struct config_item_type tf_tpg_nacl_base_cit;
 	struct config_item_type tf_tpg_nacl_attrib_cit;
@@ -154,6 +155,7 @@ void	target_qf_do_work(struct work_struct *work);
 bool	target_check_wce(struct se_device *dev);
 bool	target_check_fua(struct se_device *dev);
 void	__target_execute_cmd(struct se_cmd *, bool);
+void	target_release_session(struct se_session *);
 
 /* target_core_stat.c */
 void	target_stat_setup_dev_default_groups(struct se_device *);
drivers/target/target_core_transport.c +42 -15

106 lines not on this page · raw message

include/target/target_core_base.h +3 -0
index d5efde8..01caaa3 100644
@@ -610,6 +610,8 @@ struct se_session {
 	void			*sess_cmd_map;
 	struct sbitmap_queue	sess_tag_pool;
 	int			sid;
+	struct config_group	group;
+	struct config_item_type	cit;
 };
 
 struct se_device;
@@ -887,6 +889,7 @@ struct se_portal_group {
 	struct config_group	tpg_attrib_group;
 	struct config_group	tpg_auth_group;
 	struct config_group	tpg_param_group;
+	struct config_group	tpg_session_group;
 };
 
 static inline struct se_portal_group *to_tpg(struct config_item *item)
include/target/target_core_fabric.h +4 -1
index aa69b13..36077d6 100644
@@ -128,7 +128,10 @@ void	transport_free_session(struct se_session *);
 void	target_put_nacl(struct se_node_acl *);
 void	transport_deregister_session_configfs(struct se_session *);
 void	transport_deregister_session(struct se_session *);
-
+int	target_fabric_init_session(struct se_session *);
+int	target_fabric_register_session(struct se_portal_group *,
+				       struct se_session *);
+void	target_fabric_unregister_session(struct se_session *);
 
 void	transport_init_se_cmd(struct se_cmd *,
 		const struct target_core_fabric_ops *,
Signature · 1 line
2.7.2
#1 lore raw
Quoted 3 lines · Mike Christie

TODO:
1. handle target_fabric_register_session failure in iscsi target.

I fixed this in the updated attached patch. So Bodo and reviewers please use that instead.

From 895edd5d20df208c3dfae8d826a3c3fc9999bd68 Mon Sep 17 00:00:00 2001
From: Mike Christie <[email protected]>
Date: Mon, 16 Jul 2018 13:37:12 -0500
Subject: [PATCH 09/15] target: add session dir in configfs

Drivers like iscsi will dump one of the session's info in a info file under the acl. The problem with this is that it only prints one session and only sessions with an acl.

Then there is a dynamic_sessions file which dumps the initiator name of each session without an acl. The problem with this is that the info printed is limited to only the node name. For iscsi we do not get the entire initiator port string (name + isid). Also all dynamic sessions are printed in one file so setups that do a target per lun quickly run out of space.

To handle all these issues, this patch adds a per session dir under the tpg. We can then export info like initiator name and if needed isid. These patches will then also add some files to test sessions.

---
 drivers/target/iscsi/iscsi_target.c          |  3 ++
 drivers/target/iscsi/iscsi_target_login.c    |  6 ++-
 drivers/target/iscsi/iscsi_target_nego.c     | 24 ++++++++++--
 drivers/target/target_core_fabric_configfs.c | 47 +++++++++++++++++++++++
 drivers/target/target_core_internal.h        |  2 +
 drivers/target/target_core_transport.c       | 57 ++++++++++++++++++++--------
 include/target/iscsi/iscsi_target_core.h     |  1 +
 include/target/target_core_base.h            |  3 ++
 include/target/target_core_fabric.h          |  5 ++-
 9 files changed, 127 insertions(+), 21 deletions(-)
drivers/target/iscsi/iscsi_target.c +3 -0
index 6d81a59..f350c68 100644
@@ -4324,6 +4324,9 @@ int iscsit_close_session(struct iscsi_session *sess)
 	iscsit_stop_time2retain_timer(sess);
 	spin_unlock_bh(&se_tpg->session_lock);
 
+	if (sess->fabric_registered)
+		target_fabric_unregister_session(sess->se_sess);
+
 	/*
 	 * transport_deregister_session_configfs() will clear the
 	 * struct se_node_acl->nacl_sess pointer now as a iscsi_np process context
drivers/target/iscsi/iscsi_target_login.c +5 -1
index d6a4b93..4f80965 100644
@@ -1145,8 +1145,12 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
 				   ISCSI_LOGIN_STATUS_INIT_ERR);
 	if (!zero_tsih || !conn->sess)
 		goto old_sess_out;
-	if (conn->sess->se_sess)
+	if (conn->sess->se_sess) {
+		if (conn->sess->fabric_registered)
+			target_fabric_unregister_session(conn->sess->se_sess);
+
 		transport_free_session(conn->sess->se_sess);
+	}
 	kfree(conn->sess->sess_ops);
 	kfree(conn->sess);
 	conn->sess = NULL;
drivers/target/iscsi/iscsi_target_nego.c +20 -4
index 8a5e8d1..fe08e40 100644
@@ -1279,11 +1279,27 @@ int iscsi_target_locate_portal(
 	tag_size = sizeof(struct iscsi_cmd) + conn->conn_transport->priv_size;
 
 	ret = transport_alloc_session_tags(sess->se_sess, tag_num, tag_size);
-	if (ret < 0) {
-		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-				    ISCSI_LOGIN_STATUS_NO_RESOURCES);
-		ret = -1;
+	if (ret < 0)
+		goto return_oom;
+
+	if (conn->tpg != iscsit_global->discovery_tpg) {
+		ret = target_fabric_register_session(&conn->tpg->tpg_se_tpg,
+						     sess->se_sess);
+		if (ret) {
+			pr_err("Could not register session to configfs. Err %d.\n",
+			       ret);
+			/* tags and nacl released when session is freed */
+			goto return_oom;
+		}
+		sess->fabric_registered = true;
 	}
+
+	goto out;
+
+return_oom:
+	iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
+			    ISCSI_LOGIN_STATUS_NO_RESOURCES);
+	ret = -1;
 out:
 	kfree(tmpbuf);
 	return ret;
drivers/target/target_core_fabric_configfs.c +47 -0

59 lines not on this page · raw message

drivers/target/target_core_internal.h +2 -0
index 0c66355..73c90ae 100644
@@ -44,6 +44,7 @@ struct target_fabric_configfs {
 	struct config_item_type tf_tpg_attrib_cit;
 	struct config_item_type tf_tpg_auth_cit;
 	struct config_item_type tf_tpg_param_cit;
+	struct config_item_type tf_tpg_session_cit;
 	struct config_item_type tf_tpg_nacl_cit;
 	struct config_item_type tf_tpg_nacl_base_cit;
 	struct config_item_type tf_tpg_nacl_attrib_cit;
@@ -154,6 +155,7 @@ void	transport_dump_dev_info(struct se_device *, struct se_lun *,
 bool	target_check_wce(struct se_device *dev);
 bool	target_check_fua(struct se_device *dev);
 void	__target_execute_cmd(struct se_cmd *, bool);
+void	target_release_session(struct se_session *);
 
 /* target_core_stat.c */
 void	target_stat_setup_dev_default_groups(struct se_device *);
drivers/target/target_core_transport.c +42 -15

106 lines not on this page · raw message

include/target/iscsi/iscsi_target_core.h +1 -0
index 10031dc..e6ff787 100644
@@ -688,6 +688,7 @@ struct iscsi_session {
 	struct completion	session_waiting_on_uc_comp;
 	struct timer_list	time2retain_timer;
 	struct iscsi_sess_ops	*sess_ops;
+	bool			fabric_registered;
 	struct se_session	*se_sess;
 	struct iscsi_portal_group *tpg;
 } ____cacheline_aligned;
include/target/target_core_base.h +3 -0
index d5efde8..01caaa3 100644
@@ -610,6 +610,8 @@ struct se_session {
 	void			*sess_cmd_map;
 	struct sbitmap_queue	sess_tag_pool;
 	int			sid;
+	struct config_group	group;
+	struct config_item_type	cit;
 };
 
 struct se_device;
@@ -887,6 +889,7 @@ struct se_portal_group {
 	struct config_group	tpg_attrib_group;
 	struct config_group	tpg_auth_group;
 	struct config_group	tpg_param_group;
+	struct config_group	tpg_session_group;
 };
 
 static inline struct se_portal_group *to_tpg(struct config_item *item)
include/target/target_core_fabric.h +4 -1
index aa69b13..36077d6 100644
@@ -128,7 +128,10 @@ void	transport_register_session(struct se_portal_group *,
 void	target_put_nacl(struct se_node_acl *);
 void	transport_deregister_session_configfs(struct se_session *);
 void	transport_deregister_session(struct se_session *);
-
+int	target_fabric_init_session(struct se_session *);
+int	target_fabric_register_session(struct se_portal_group *,
+				       struct se_session *);
+void	target_fabric_unregister_session(struct se_session *);
 
 void	transport_init_se_cmd(struct se_cmd *,
 		const struct target_core_fabric_ops *,
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Mike Christie

On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
+AD4- +-static void target+AF8-fabric+AF8-session+AF8-release(struct config+AF8-item +ACo-item) +AD4- +-+AHs-
+AD4- +- struct se+AF8-session +ACo-se+AF8-sess +AD0- container+AF8-of(to+AF8-config+AF8-group(item),
+AD4- +- struct se+AF8-session, group)+ADs-
+AD4- +- target+AF8-release+AF8-session(se+AF8-sess)+ADs-
+AD4- +-+AH0-

Please consider changing the target+AF8-fabric+AF8- prefix into target+AF8- for all new functions. Otherwise this patch looks fine to me.

Bart.