Skip to contentSkip to conversation

target: add sysfs support

PATCH In review Mike Christie 7 participants 42 messages May 10, 2020 – May 13, 2020

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

v5 cover target: add sysfs support

The following patches made over Linus's current tree allow lio to export info about structs like the se_session that the kernel initiates creation of via events like initiator login where there is no local user interaction like a mkdir.

Why sysfs when we have configfs?

I started with configfs and hit bugs like:

commit cc57c07343bd071cdf1915a91a24ab7d40c9b590

Author: Mike Christie <[email protected]>
Date:   Sun Jul 15 18:16:17 2018 -0500

configfs: fix registered group removal

and it turns out that bug was not really a bug and was just how configfs was meant to work. It seems it was not meant to be used where the kernel initiates creation of dirs/files as a result of some internal action. It's more geared to the user initiating the creation, and my patch just lead to other bugs and was reverted:

commit f19e4ed1e1edbfa3c9ccb9fed17759b7d6db24c6

Author: Al Viro <[email protected]>
Date:   Thu Aug 29 23:13:30 2019 -0400

configfs_register_group() shouldn't be (and isn't) called in
rmdirable parts

So to export the session info we have debugfs, sysfs, ioctl, netlink, etc. sysfs just seemed like a decent fit since one of the primary users is rtslib and it already has lots of file/dir handling code.

V4:
- Don't drop const char use in fabric drivers.
- add Documentation/ABI
- use initaitor port prefix instead of generic "session"
- only make session_id file if iSCSI format=1 is being used.

V3:
- drop format field
- delay tpg deletion to allow fabric modules time to remove their sessions.
- Added root sessions dir for easier lookup if userspace has the session id.
- add session symlink
- use simple ida.
- Fix goto use. Actually moved sysfs addition call to after nego to avoid sysfs additions when login ends up failing.
- Dropped target_setup_session callback fixups and dropped the init/free session callback for now. It's not immediately needed for this base session sysfs info support.

V2:
- rename top level dir to scsi_target
- Fix extra newline
- Copy data that's exported to sysfs so we do not have to worry about configfs and sysfs refcounts.
- Export session info needed for tracking sessions in userspace and handling commands like PGRs there (still needs a way to notify userspace when sessions are added/deleted, but that will be a different set since the focus is different).

#1 lore raw

PATCH v5 1/15 target: check enforce_pr_isids during registration

Move the check for enforce_pr_isids to the registration code where we can fail at the time an initiator tries to register a path without an isid. In its current place in __core_scsi3_locate_pr_reg, it is too late because it can be registered and be reported in PR in commands and it is stuck in this state because we cannot unregister it.

Note.
I am including in this patchset, because the 5th patch is built on top.

---
 drivers/target/target_core_pr.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/target/target_core_pr.c +15 -9
index 5e93169..cd2d32f 100644
@@ -1176,15 +1176,6 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg(
 		 * ISID, then we have found a match.
 		 */
 		if (!pr_reg->isid_present_at_reg) {
-			/*
-			 * Determine if this SCSI device server requires that
-			 * SCSI Intiatior TransportID w/ ISIDs is enforced
-			 * for fabric modules (iSCSI) requiring them.
-			 */
-			if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
-				if (dev->dev_attrib.enforce_pr_isids)
-					continue;
-			}
 			atomic_inc_mb(&pr_reg->pr_res_holders);
 			spin_unlock(&pr_tmpl->registration_lock);
 			return pr_reg;
@@ -1591,10 +1582,25 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
 				continue;
 			dest_rtpi = tmp_lun->lun_rtpi;
 
+			iport_ptr = NULL;
 			i_str = target_parse_pr_out_transport_id(tmp_tpg,
 					ptr, &tid_len, &iport_ptr);
 			if (!i_str)
 				continue;
+			/*
+			 * Determine if this SCSI device server requires that
+			 * SCSI Intiatior TransportID w/ ISIDs is enforced
+			 * for fabric modules (iSCSI) requiring them.
+			 */
+			if (tpg->se_tpg_tfo->sess_get_initiator_sid &&
+                            dev->dev_attrib.enforce_pr_isids &&
+			    !iport_ptr) {
+				pr_warn("SPC-PR: enforce_pr_isids is set but a isid has not been sent in the SPEC_I_PT data for %s.",
+					i_str);
+				ret = TCM_INVALID_PARAMETER_LIST;
+				spin_unlock(&dev->se_port_lock);
+				goto out_unmap;
+			}
 
 			atomic_inc_mb(&tmp_tpg->tpg_pr_ref_count);
 			spin_unlock(&dev->se_port_lock);
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v5 2/15 target: separate acl name from port ids

In reply to Mike Christie

The PGR code assumes the ACL name is going to be based on the SPC4 transportID type of values. The problem is that for iSCSI we have an extra session id as part of the SCSI port id and some fabric modules support or would like to support non transportID values for the ACL name. For example, iSCSI and SRP would like to use the source address for the ACL name, but that is not a valud transportID value that you can get in a PGR request.

This patch adds a new transport_id struct which maps to the SPC4 transportID. In the future it will be used for PGR commands instead of the ACL name. In this patchset it is used to export the initiator info in the session's sysfs dir, so tools can display the info and daemons that execute commands like PGRs in userspace can build a session id to I_T nexus mapping.

In this patch only srp is passing in different values for the transport id and acl name. The next patches will convert loop, scsi vhost and xen scsiback that are more complex due to their initiator name emulation.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>

---

V4:
- Don't drop const char use. We still have target_setup_session allocate the transport_id struct, but because every uses format=0 we just need to pass in the transport_id's name.

V3:
- drop format

 drivers/infiniband/ulp/srpt/ib_srpt.c    | 10 +++++---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c |  4 +--
 drivers/scsi/qla2xxx/tcm_qla2xxx.c       |  2 +-
 drivers/target/loopback/tcm_loop.c       |  3 ++-
 drivers/target/sbp/sbp_target.c          |  2 +-
 drivers/target/target_core_fabric_lib.c  | 41 +++++++++++++++++++++++++++++++
 drivers/target/target_core_transport.c   | 42 ++++++++++++++++++++++++--------
 drivers/target/tcm_fc/tfc_sess.c         |  3 ++-
 drivers/usb/gadget/function/f_tcm.c      |  3 ++-
 drivers/vhost/scsi.c                     |  1 +
 drivers/xen/xen-scsiback.c               |  3 ++-
 include/target/target_core_base.h        | 12 +++++++++
 include/target/target_core_fabric.h      |  5 +++-
 13 files changed, 108 insertions(+), 23 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +6 -4
index 9855274..d107f63 100644
@@ -2320,7 +2320,8 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
 			break;
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
 						tag_size, TARGET_PROT_NORMAL,
-						ch->sess_name, ch, NULL);
+						i_port_id + 2, ch->sess_name,
+						ch, NULL);
 	}
 	mutex_unlock(&sport->port_guid_id.mutex);
 
@@ -2329,14 +2330,15 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
 		if (!IS_ERR_OR_NULL(ch->sess))
 			break;
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
-					tag_size, TARGET_PROT_NORMAL, i_port_id,
-					ch, NULL);
+					tag_size, TARGET_PROT_NORMAL,
+					i_port_id + 2, i_port_id, ch, NULL);
 		if (!IS_ERR_OR_NULL(ch->sess))
 			break;
 		/* Retry without leading "0x" */
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
 						tag_size, TARGET_PROT_NORMAL,
-						i_port_id + 2, ch, NULL);
+						i_port_id + 2, i_port_id + 2,
+						ch, NULL);
 	}
 	mutex_unlock(&sport->port_gid_id.mutex);
 
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +2 -2
index d9e94e8..31459f3 100644
@@ -2223,8 +2223,8 @@ static int ibmvscsis_make_nexus(struct ibmvscsis_tport *tport)
 	}
 
 	nexus->se_sess = target_setup_session(&tport->se_tpg, 0, 0,
-					      TARGET_PROT_NORMAL, name, nexus,
-					      NULL);
+					      TARGET_PROT_NORMAL, name, name,
+					      nexus, NULL);
 	if (IS_ERR(nexus->se_sess)) {
 		rc = PTR_ERR(nexus->se_sess);
 		goto transport_init_fail;
drivers/scsi/qla2xxx/tcm_qla2xxx.c +1 -1
index 1f0a185..7b21809 100644
@@ -1483,7 +1483,7 @@ static int tcm_qla2xxx_check_initiator_node_acl(
 	 */
 	se_sess = target_setup_session(&tpg->se_tpg, num_tags,
 				       sizeof(struct qla_tgt_cmd),
-				       TARGET_PROT_ALL, port_name,
+				       TARGET_PROT_ALL, port_name, port_name,
 				       qlat_sess, tcm_qla2xxx_session_cb);
 	if (IS_ERR(se_sess))
 		return PTR_ERR(se_sess);
drivers/target/loopback/tcm_loop.c +2 -1
index 3305b47..74aded7 100644
@@ -742,7 +742,8 @@ static int tcm_loop_make_nexus(
 
 	tl_nexus->se_sess = target_setup_session(&tl_tpg->tl_se_tpg, 0, 0,
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
-					name, tl_nexus, tcm_loop_alloc_sess_cb);
+					name, name, tl_nexus,
+					tcm_loop_alloc_sess_cb);
 	if (IS_ERR(tl_nexus->se_sess)) {
 		ret = PTR_ERR(tl_nexus->se_sess);
 		kfree(tl_nexus);
drivers/target/sbp/sbp_target.c +1 -1
index e4a9b9f..2cac4d9 100644
@@ -199,7 +199,7 @@ static struct sbp_session *sbp_session_create(
 	sess->se_sess = target_setup_session(&tpg->se_tpg, 128,
 					     sizeof(struct sbp_target_request),
 					     TARGET_PROT_NORMAL, guid_str,
-					     sess, NULL);
+					     guid_str, sess, NULL);
 	if (IS_ERR(sess->se_sess)) {
 		pr_err("failed to init se_session\n");
 		ret = PTR_ERR(sess->se_sess);
drivers/target/target_core_fabric_lib.c +41 -0

44 lines not on this page · raw message

drivers/target/target_core_transport.c +32 -10

79 lines not on this page · raw message

drivers/target/tcm_fc/tfc_sess.c +2 -1
index 4fd6a1d..1d1c460 100644
@@ -230,7 +230,8 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
 	sess->se_sess = target_setup_session(se_tpg, TCM_FC_DEFAULT_TAGS,
 					     sizeof(struct ft_cmd),
 					     TARGET_PROT_NORMAL, &initiatorname[0],
-					     sess, ft_sess_alloc_cb);
+					     &initiatorname[0], sess,
+					     ft_sess_alloc_cb);
 	if (IS_ERR(sess->se_sess)) {
 		int rc = PTR_ERR(sess->se_sess);
 		kfree(sess);
drivers/usb/gadget/function/f_tcm.c +2 -1
index 3650493..cab3036 100644
@@ -1583,7 +1583,8 @@ static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name)
 						     USB_G_DEFAULT_SESSION_TAGS,
 						     sizeof(struct usbg_cmd),
 						     TARGET_PROT_NORMAL, name,
-						     tv_nexus, usbg_alloc_sess_cb);
+						     name, tv_nexus,
+						     usbg_alloc_sess_cb);
 	if (IS_ERR(tv_nexus->tvn_se_sess)) {
 #define MAKE_NEXUS_MSG "core_tpg_check_initiator_node_acl() failed for %s\n"
 		pr_debug(MAKE_NEXUS_MSG, name);
drivers/vhost/scsi.c +1 -0
index c399522..15aabc2 100644
@@ -1964,6 +1964,7 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 					VHOST_SCSI_DEFAULT_TAGS,
 					sizeof(struct vhost_scsi_cmd),
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
+					(unsigned char *)name,
 					(unsigned char *)name, tv_nexus,
 					vhost_scsi_nexus_cb);
 	if (IS_ERR(tv_nexus->tvn_se_sess)) {
drivers/xen/xen-scsiback.c +2 -1
index 75c0a2e..93cb386 100644
@@ -1531,7 +1531,8 @@ static int scsiback_make_nexus(struct scsiback_tpg *tpg,
 						     VSCSI_DEFAULT_SESSION_TAGS,
 						     sizeof(struct vscsibk_pend),
 						     TARGET_PROT_NORMAL, name,
-						     tv_nexus, scsiback_alloc_sess_cb);
+						     name, tv_nexus,
+						     scsiback_alloc_sess_cb);
 	if (IS_ERR(tv_nexus->tvn_se_sess)) {
 		kfree(tv_nexus);
 		ret = -ENOMEM;
include/target/target_core_base.h +12 -0
index 6d4a694..2e79cce 100644
@@ -331,6 +331,17 @@ struct t10_wwn {
 	struct list_head t10_vpd_list;
 };
 
+struct t10_transport_id {
+	/* The format=0 transport specific port id/name value. */
+	char *name;
+	/*
+	 * If proto is iSCSI and it's using format=1, then this is set to the
+	 * initiator session id string defined in spc4r37 table 508.
+	 */
+	char *session_id;
+	u8 proto;
+};
+
 struct t10_pr_registration {
 	/* Used for fabrics that contain WWN+ISID */
 #define PR_REG_ISID_LEN				16
@@ -610,6 +621,7 @@ static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item)
 struct se_session {
 	unsigned		sess_tearing_down:1;
 	u64			sess_bin_isid;
+	struct t10_transport_id	*tpt_id;
 	enum target_prot_op	sup_prot_ops;
 	enum target_prot_type	sess_prot_type;
 	struct se_node_acl	*se_node_acl;
include/target/target_core_fabric.h +4 -1
index 063f133..af1dd81 100644
@@ -125,9 +125,12 @@ struct target_core_fabric_ops {
 int target_depend_item(struct config_item *item);
 void target_undepend_item(struct config_item *item);
 
+struct t10_transport_id *target_create_transport_id(u8, const char *,
+						    const char *);
+void target_free_transport_id(struct t10_transport_id *);
 struct se_session *target_setup_session(struct se_portal_group *,
 		unsigned int, unsigned int, enum target_prot_op prot_op,
-		const char *, void *,
+		const char *, const char *, void *,
 		int (*callback)(struct se_portal_group *,
 				struct se_session *, void *));
 void target_remove_session(struct se_session *);
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v5 3/15 target: add helper to parse acl and transport name

In reply to Mike Christie

The drivers that emulate the initiator port id (loop, scsi vhost, xen scsiback) do almost the extact same parsing when making their I_T_nexus. This adds a helper that parses out the acl name and port name from the user buffer, so these types of drivers drop prefixes like "naa." when they need to for the SCSI SPC4 TransportID SAS address, but then keep it for the LIO ACL name.

The next patches will then convert those drivers.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>
---
 drivers/target/target_core_fabric_lib.c | 73 +++++++++++++++++++++++++++++++++
 include/target/target_core_fabric.h     |  2 +
 2 files changed, 75 insertions(+)
drivers/target/target_core_fabric_lib.c +73 -0
index e89b3d8..81ed7d5 100644
@@ -423,6 +423,79 @@ const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
 	return buf + offset;
 }
 
+/**
+ * target_parse_emulated_name - parse TransportID and acl name from user buffer
+ * @proto_id: SCSI protocol identifier
+ * @user_buf: buffer with emualted name to extract acl and TransportID from
+ * @acl_name: buffer to store se_node_acl name in
+ * @max_name_len: len of acl_name buffer
+ * @tpt_id_name: Pointer to the TransportID name will be stored here.
+ */
+int target_parse_emulated_name(u8 proto_id, const char *user_buf,
+			       unsigned char *acl_name, int max_name_len,
+			       unsigned char **tpt_id_name)
+{
+	int user_len = strlen(user_buf);
+	char *proto_prefix, *name_start;
+
+	if (user_len >= max_name_len) {
+		pr_err("Emulated name: %s, exceeds max: %d\n", user_buf,
+		       max_name_len);
+		return -EINVAL;
+	}
+
+	switch (proto_id) {
+	case SCSI_PROTOCOL_SAS:
+		proto_prefix = "naa.";
+		break;
+	case SCSI_PROTOCOL_FCP:
+		proto_prefix = "fc.";
+		break;
+	case SCSI_PROTOCOL_ISCSI:
+		proto_prefix = "iqn.";
+		break;
+	default:
+		pr_err("Unsupported proto_id: 0x%02x\n", proto_id);
+		return -EINVAL;
+	}
+
+	name_start = strstr(user_buf, proto_prefix);
+	if (!name_start) {
+		pr_err("Invalid emulated name %s. Must start with %s\n",
+		       user_buf, proto_prefix);
+		return -EINVAL;
+	}
+
+	switch (proto_id) {
+	case SCSI_PROTOCOL_SAS:
+		sprintf(acl_name, name_start);
+		break;
+	case SCSI_PROTOCOL_FCP:
+		sprintf(acl_name, &name_start[3]); /* Skip over "fc." */
+		break;
+	case SCSI_PROTOCOL_ISCSI:
+		sprintf(acl_name, name_start);
+		break;
+	}
+
+	if (acl_name[user_len - 1] = '\n')
+		acl_name[user_len - 1] = '\0';
+
+	if (proto_id = SCSI_PROTOCOL_SAS) {
+		/*
+		 * target_setup_session will want the naa. prefix to match
+		 * the ACL name, but the t10 transport id only wants the
+		 * address.
+		 */
+		*tpt_id_name = acl_name + 4;
+	} else {
+		*tpt_id_name = acl_name;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(target_parse_emulated_name);
+
 struct t10_transport_id *target_create_transport_id(u8 proto, const char *name,
 						    const char *session_id)
 {
include/target/target_core_fabric.h +2 -0
index af1dd81..0113e1c 100644
@@ -125,6 +125,8 @@ struct target_core_fabric_ops {
 int target_depend_item(struct config_item *item);
 void target_undepend_item(struct config_item *item);
 
+int target_parse_emulated_name(u8, const char *, unsigned char *, int,
+			       unsigned char **);
 struct t10_transport_id *target_create_transport_id(u8, const char *,
 						    const char *);
 void target_free_transport_id(struct t10_transport_id *);
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v5 4/15 tcm loop: use target_parse_emulated_name

In reply to Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

---
 drivers/target/loopback/tcm_loop.c | 65 ++++++--------------------------------
 1 file changed, 10 insertions(+), 55 deletions(-)
drivers/target/loopback/tcm_loop.c +10 -55
index 74aded7..64e5f1f 100644
@@ -725,7 +725,8 @@ static int tcm_loop_alloc_sess_cb(struct se_portal_group *se_tpg,
 
 static int tcm_loop_make_nexus(
 	struct tcm_loop_tpg *tl_tpg,
-	const char *name)
+	const char *tpt_id_name,
+	const char *acl_name)
 {
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
 	struct tcm_loop_nexus *tl_nexus;
@@ -742,7 +743,7 @@ static int tcm_loop_make_nexus(
 
 	tl_nexus->se_sess = target_setup_session(&tl_tpg->tl_se_tpg, 0, 0,
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
-					name, name, tl_nexus,
+					tpt_id_name, acl_name, tl_nexus,
 					tcm_loop_alloc_sess_cb);
 	if (IS_ERR(tl_nexus->se_sess)) {
 		ret = PTR_ERR(tl_nexus->se_sess);
@@ -751,7 +752,7 @@ static int tcm_loop_make_nexus(
 	}
 
 	pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated %s Initiator Port: %s\n",
-		 tcm_loop_dump_proto_id(tl_hba), name);
+		 tcm_loop_dump_proto_id(tl_hba), acl_name);
 	return 0;
 }
 
@@ -814,7 +815,7 @@ static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
 	struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
 			struct tcm_loop_tpg, tl_se_tpg);
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
-	unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
+	unsigned char i_port[TL_WWN_ADDR_LEN], *tpt_id_name;
 	int ret;
 	/*
 	 * Shutdown the active I_T nexus if 'NULL' is passed..
@@ -823,59 +824,13 @@ static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
 		ret = tcm_loop_drop_nexus(tl_tpg);
 		return (!ret) ? count : ret;
 	}
-	/*
-	 * Otherwise make sure the passed virtual Initiator port WWN matches
-	 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
-	 * tcm_loop_make_nexus()
-	 */
-	if (strlen(page) >= TL_WWN_ADDR_LEN) {
-		pr_err("Emulated NAA Sas Address: %s, exceeds max: %d\n",
-		       page, TL_WWN_ADDR_LEN);
-		return -EINVAL;
-	}
-	snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
 
-	ptr = strstr(i_port, "naa.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
-			pr_err("Passed SAS Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "fc.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
-			pr_err("Passed FCP Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[3]; /* Skip over "fc." */
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "iqn.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
-			pr_err("Passed iSCSI Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	pr_err("Unable to locate prefix for emulated Initiator Port: %s\n",
-	       i_port);
-	return -EINVAL;
-	/*
-	 * Clear any trailing newline for the NAA WWN
-	 */
-check_newline:
-	if (i_port[strlen(i_port)-1] = '\n')
-		i_port[strlen(i_port)-1] = '\0';
+	ret = target_parse_emulated_name(tl_hba->tl_proto_id, page, i_port,
+					 TL_WWN_ADDR_LEN, &tpt_id_name);
+	if (ret)
+		return ret;
 
-	ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
+	ret = tcm_loop_make_nexus(tl_tpg, tpt_id_name, i_port);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v5 5/15 vhost scsi: use target_parse_emulated_name

In reply to Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 drivers/vhost/scsi.c | 69 +++++++++-------------------------------------------
 1 file changed, 11 insertions(+), 58 deletions(-)
drivers/vhost/scsi.c +11 -58
index 15aabc2..37f66f8 100644
@@ -1938,7 +1938,8 @@ static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
 }
 
 static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
-				const char *name)
+				const char *tpt_id_name,
+				const char *acl_name)
 {
 	struct vhost_scsi_nexus *tv_nexus;
 
@@ -1964,8 +1965,8 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 					VHOST_SCSI_DEFAULT_TAGS,
 					sizeof(struct vhost_scsi_cmd),
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
-					(unsigned char *)name,
-					(unsigned char *)name, tv_nexus,
+					(unsigned char *)tpt_id_name,
+					(unsigned char *)acl_name, tv_nexus,
 					vhost_scsi_nexus_cb);
 	if (IS_ERR(tv_nexus->tvn_se_sess)) {
 		mutex_unlock(&tpg->tv_tpg_mutex);
@@ -2056,7 +2057,7 @@ static ssize_t vhost_scsi_tpg_nexus_store(struct config_item *item,
 	struct vhost_scsi_tpg *tpg = container_of(se_tpg,
 				struct vhost_scsi_tpg, se_tpg);
 	struct vhost_scsi_tport *tport_wwn = tpg->tport;
-	unsigned char i_port[VHOST_SCSI_NAMELEN], *ptr, *port_ptr;
+	unsigned char i_port[VHOST_SCSI_NAMELEN], *tpt_id_name;
 	int ret;
 	/*
 	 * Shutdown the active I_T nexus if 'NULL' is passed..
@@ -2065,62 +2066,14 @@ static ssize_t vhost_scsi_tpg_nexus_store(struct config_item *item,
 		ret = vhost_scsi_drop_nexus(tpg);
 		return (!ret) ? count : ret;
 	}
-	/*
-	 * Otherwise make sure the passed virtual Initiator port WWN matches
-	 * the fabric protocol_id set in vhost_scsi_make_tport(), and call
-	 * vhost_scsi_make_nexus().
-	 */
-	if (strlen(page) >= VHOST_SCSI_NAMELEN) {
-		pr_err("Emulated NAA Sas Address: %s, exceeds"
-				" max: %d\n", page, VHOST_SCSI_NAMELEN);
-		return -EINVAL;
-	}
-	snprintf(&i_port[0], VHOST_SCSI_NAMELEN, "%s", page);
 
-	ptr = strstr(i_port, "naa.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_SAS) {
-			pr_err("Passed SAS Initiator Port %s does not"
-				" match target port protoid: %s\n", i_port,
-				vhost_scsi_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "fc.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_FCP) {
-			pr_err("Passed FCP Initiator Port %s does not"
-				" match target port protoid: %s\n", i_port,
-				vhost_scsi_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[3]; /* Skip over "fc." */
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "iqn.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_ISCSI) {
-			pr_err("Passed iSCSI Initiator Port %s does not"
-				" match target port protoid: %s\n", i_port,
-				vhost_scsi_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	pr_err("Unable to locate prefix for emulated Initiator Port:"
-			" %s\n", i_port);
-	return -EINVAL;
-	/*
-	 * Clear any trailing newline for the NAA WWN
-	 */
-check_newline:
-	if (i_port[strlen(i_port)-1] = '\n')
-		i_port[strlen(i_port)-1] = '\0';
+	ret = target_parse_emulated_name(tport_wwn->tport_proto_id, page,
+					 i_port, VHOST_SCSI_NAMELEN,
+					 &tpt_id_name);
+	if (ret)
+		return ret;
 
-	ret = vhost_scsi_make_nexus(tpg, port_ptr);
+	ret = vhost_scsi_make_nexus(tpg, tpt_id_name, i_port);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH v5 6/15 xen scsiback: use target_parse_emulated_name

In reply to Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

---
 drivers/xen/xen-scsiback.c | 66 ++++++++--------------------------------------
 1 file changed, 11 insertions(+), 55 deletions(-)
drivers/xen/xen-scsiback.c +11 -55
index 93cb386..f70b6da 100644
@@ -1509,7 +1509,8 @@ static int scsiback_alloc_sess_cb(struct se_portal_group *se_tpg,
 }
 
 static int scsiback_make_nexus(struct scsiback_tpg *tpg,
-				const char *name)
+				const char *tpt_id_name,
+				const char *acl_name)
 {
 	struct scsiback_nexus *tv_nexus;
 	int ret = 0;
@@ -1530,8 +1531,9 @@ static int scsiback_make_nexus(struct scsiback_tpg *tpg,
 	tv_nexus->tvn_se_sess = target_setup_session(&tpg->se_tpg,
 						     VSCSI_DEFAULT_SESSION_TAGS,
 						     sizeof(struct vscsibk_pend),
-						     TARGET_PROT_NORMAL, name,
-						     name, tv_nexus,
+						     TARGET_PROT_NORMAL,
+						     tpt_id_name, acl_name,
+						     tv_nexus,
 						     scsiback_alloc_sess_cb);
 	if (IS_ERR(tv_nexus->tvn_se_sess)) {
 		kfree(tv_nexus);
@@ -1619,7 +1621,7 @@ static ssize_t scsiback_tpg_nexus_store(struct config_item *item,
 	struct scsiback_tpg *tpg = container_of(se_tpg,
 				struct scsiback_tpg, se_tpg);
 	struct scsiback_tport *tport_wwn = tpg->tport;
-	unsigned char i_port[VSCSI_NAMELEN], *ptr, *port_ptr;
+	unsigned char i_port[VSCSI_NAMELEN], *tpt_id_name;
 	int ret;
 	/*
 	 * Shutdown the active I_T nexus if 'NULL' is passed.
@@ -1628,59 +1630,13 @@ static ssize_t scsiback_tpg_nexus_store(struct config_item *item,
 		ret = scsiback_drop_nexus(tpg);
 		return (!ret) ? count : ret;
 	}
-	/*
-	 * Otherwise make sure the passed virtual Initiator port WWN matches
-	 * the fabric protocol_id set in scsiback_make_tport(), and call
-	 * scsiback_make_nexus().
-	 */
-	if (strlen(page) >= VSCSI_NAMELEN) {
-		pr_err("Emulated NAA Sas Address: %s, exceeds max: %d\n",
-			page, VSCSI_NAMELEN);
-		return -EINVAL;
-	}
-	snprintf(&i_port[0], VSCSI_NAMELEN, "%s", page);
 
-	ptr = strstr(i_port, "naa.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_SAS) {
-			pr_err("Passed SAS Initiator Port %s does not match target port protoid: %s\n",
-				i_port, scsiback_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "fc.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_FCP) {
-			pr_err("Passed FCP Initiator Port %s does not match target port protoid: %s\n",
-				i_port, scsiback_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[3]; /* Skip over "fc." */
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "iqn.");
-	if (ptr) {
-		if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_ISCSI) {
-			pr_err("Passed iSCSI Initiator Port %s does not match target port protoid: %s\n",
-				i_port, scsiback_dump_proto_id(tport_wwn));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	pr_err("Unable to locate prefix for emulated Initiator Port: %s\n",
-		i_port);
-	return -EINVAL;
-	/*
-	 * Clear any trailing newline for the NAA WWN
-	 */
-check_newline:
-	if (i_port[strlen(i_port) - 1] = '\n')
-		i_port[strlen(i_port) - 1] = '\0';
+	ret = target_parse_emulated_name(tport_wwn->tport_proto_id, page,
+					 i_port, VSCSI_NAMELEN, &tpt_id_name);
+	if (ret)
+		return ret;
 
-	ret = scsiback_make_nexus(tpg, port_ptr);
+	ret = scsiback_make_nexus(tpg, tpt_id_name, i_port);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v5 7/15 iscsi target: setup transport_id

In reply to Mike Christie

The iscsi target does its own session setup. This patch updates the driver so it sets up the transport id.

---
 drivers/target/iscsi/iscsi_target_nego.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/target/iscsi/iscsi_target_nego.c +28 -4
index 685d771..c44613a2 100644
@@ -1032,6 +1032,20 @@ static void iscsi_initiatorname_tolower(
 	}
 }
 
+static int iscsi_setup_i_tpt_id(struct iscsi_session *sess, char *iname)
+{
+	char isid_buf[13];
+
+	sprintf(isid_buf, "%6phN", sess->isid);
+
+	sess->se_sess->tpt_id = target_create_transport_id(SCSI_PROTOCOL_ISCSI,
+							   iname, isid_buf);
+	if (!sess->se_sess->tpt_id)
+		return -ENOMEM;
+
+	return 0;
+}
+
 /*
  * Processes the first Login Request..
  */
@@ -1260,11 +1274,21 @@ 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) {
+		if (iscsi_setup_i_tpt_id(sess, i_buf))
+			/* tags and nacl released when session is freed */
+			goto return_oom;
 	}
+
+	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;
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH v5 8/15 target: use tpt_id in target_stat_iport_port_ident_show

In reply to Mike Christie

Use the tpt_id session id instead of sess_get_initiator_sid.

Note that for userspace compat this patch continues the behavior:

1. Still add the "+i+" even if there is no session_id.
2. Use the acl initiatorname instead of the transportID port/addr/name.

---
 drivers/target/target_core_stat.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/target/target_core_stat.c +3 -9
index 237309d..3eb1b9b 100644
@@ -1308,9 +1308,7 @@ static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
 	struct se_lun_acl *lacl = iport_to_lacl(item);
 	struct se_node_acl *nacl = lacl->se_lun_nacl;
 	struct se_session *se_sess;
-	struct se_portal_group *tpg;
 	ssize_t ret;
-	unsigned char buf[64];
 
 	spin_lock_irq(&nacl->nacl_sess_lock);
 	se_sess = nacl->nacl_sess;
@@ -1319,13 +1317,9 @@ static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
 		return -ENODEV;
 	}
 
-	tpg = nacl->se_tpg;
-	/* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
-	memset(buf, 0, 64);
-	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
-		tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
-
-	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
+	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname,
+		       se_sess->tpt_id->session_id ? se_sess->tpt_id->session_id :
+		       "");
 	spin_unlock_irq(&nacl->nacl_sess_lock);
 	return ret;
 }
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH v5 9/15 target: drop sess_get_initiator_sid from PR code

In reply to Mike Christie

Use the transport id session id in the PR related code.

---
 drivers/target/target_core_pr.c        | 23 ++++-------------------
 drivers/target/target_core_transport.c | 11 ++++-------
 2 files changed, 8 insertions(+), 26 deletions(-)
drivers/target/target_core_pr.c +4 -19
index cd2d32f..fbe3638 100644
@@ -1204,17 +1204,7 @@ static struct t10_pr_registration *core_scsi3_locate_pr_reg(
 	struct se_node_acl *nacl,
 	struct se_session *sess)
 {
-	struct se_portal_group *tpg = nacl->se_tpg;
-	unsigned char buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
-
-	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
-		memset(&buf[0], 0, PR_REG_ISID_LEN);
-		tpg->se_tpg_tfo->sess_get_initiator_sid(sess, &buf[0],
-					PR_REG_ISID_LEN);
-		isid_ptr = &buf[0];
-	}
-
-	return __core_scsi3_locate_pr_reg(dev, nacl, isid_ptr);
+	return __core_scsi3_locate_pr_reg(dev, nacl, sess->tpt_id->session_id);
 }
 
 static void core_scsi3_put_pr_reg(struct t10_pr_registration *pr_reg)
@@ -1592,7 +1582,7 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
 			 * SCSI Intiatior TransportID w/ ISIDs is enforced
 			 * for fabric modules (iSCSI) requiring them.
 			 */
-			if (tpg->se_tpg_tfo->sess_get_initiator_sid &&
+			if (se_sess->tpt_id->session_id &&
                             dev->dev_attrib.enforce_pr_isids &&
 			    !iport_ptr) {
 				pr_warn("SPC-PR: enforce_pr_isids is set but a isid has not been sent in the SPEC_I_PT data for %s.",
@@ -2057,7 +2047,7 @@ static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, b
 	struct se_portal_group *se_tpg;
 	struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp;
 	struct t10_reservation *pr_tmpl = &dev->t10_pr;
-	unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
+	unsigned char *isid_ptr = NULL;
 	sense_reason_t ret = TCM_NO_SENSE;
 	int pr_holder = 0, type;
 
@@ -2067,12 +2057,7 @@ static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, b
 	}
 	se_tpg = se_sess->se_tpg;
 
-	if (se_tpg->se_tpg_tfo->sess_get_initiator_sid) {
-		memset(&isid_buf[0], 0, PR_REG_ISID_LEN);
-		se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, &isid_buf[0],
-				PR_REG_ISID_LEN);
-		isid_ptr = &isid_buf[0];
-	}
+	isid_ptr = se_sess->tpt_id->session_id;
 	/*
 	 * Follow logic from spc4r17 Section 5.7.7, Register Behaviors Table 47
 	 */
drivers/target/target_core_transport.c +4 -7
index fb00fcc..fdf84db 100644
@@ -343,7 +343,7 @@ void __transport_register_session(
 	void *fabric_sess_ptr)
 {
 	const struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo;
-	unsigned char buf[PR_REG_ISID_LEN];
+	unsigned char *sid;
 	unsigned long flags;
 
 	se_sess->se_tpg = se_tpg;
@@ -374,12 +374,9 @@ void __transport_register_session(
 		 * If the fabric module supports an ISID based TransportID,
 		 * save this value in binary from the fabric I_T Nexus now.
 		 */
-		if (se_tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
-			memset(&buf[0], 0, PR_REG_ISID_LEN);
-			se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess,
-					&buf[0], PR_REG_ISID_LEN);
-			se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]);
-		}
+		sid = se_sess->tpt_id->session_id;
+		if (sid)
+			se_sess->sess_bin_isid = get_unaligned_be64(sid);
 
 		spin_lock_irqsave(&se_nacl->nacl_sess_lock, flags);
 		/*
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v5 10/15 target: drop sess_get_initiator_sid

In reply to Mike Christie

sess_get_initiator_sid is no longer used. Drop it.

---
 drivers/infiniband/ulp/srpt/ib_srpt.c        |  1 -
 drivers/scsi/qla2xxx/tcm_qla2xxx.c           |  2 --
 drivers/target/iscsi/iscsi_target_configfs.c | 13 -------------
 drivers/target/tcm_fc/tfc_conf.c             |  1 -
 drivers/usb/gadget/function/f_tcm.c          |  1 -
 drivers/vhost/scsi.c                         |  1 -
 drivers/xen/xen-scsiback.c                   |  1 -
 include/target/target_core_fabric.h          |  6 ------
 8 files changed, 26 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +0 -1
index d107f63..3cda73c 100644
@@ -3844,7 +3844,6 @@ static ssize_t srpt_wwn_version_show(struct config_item *item, char *buf)
 	.check_stop_free		= srpt_check_stop_free,
 	.close_session			= srpt_close_session,
 	.sess_get_index			= srpt_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= srpt_write_pending,
 	.set_default_node_attributes	= srpt_set_default_node_attrs,
 	.get_cmd_state			= srpt_get_tcm_cmd_state,
drivers/scsi/qla2xxx/tcm_qla2xxx.c +0 -2
index 7b21809..fff695a 100644
@@ -1852,7 +1852,6 @@ static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
 	.release_cmd			= tcm_qla2xxx_release_cmd,
 	.close_session			= tcm_qla2xxx_close_session,
 	.sess_get_index			= tcm_qla2xxx_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= tcm_qla2xxx_write_pending,
 	.set_default_node_attributes	= tcm_qla2xxx_set_default_node_attrs,
 	.get_cmd_state			= tcm_qla2xxx_get_cmd_state,
@@ -1892,7 +1891,6 @@ static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
 	.release_cmd			= tcm_qla2xxx_release_cmd,
 	.close_session			= tcm_qla2xxx_close_session,
 	.sess_get_index			= tcm_qla2xxx_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= tcm_qla2xxx_write_pending,
 	.set_default_node_attributes	= tcm_qla2xxx_set_default_node_attrs,
 	.get_cmd_state			= tcm_qla2xxx_get_cmd_state,
drivers/target/iscsi/iscsi_target_configfs.c +0 -13
index 0fa1d57..4513740 100644
@@ -1349,18 +1349,6 @@ static u32 lio_sess_get_index(struct se_session *se_sess)
 	return sess->session_index;
 }
 
-static u32 lio_sess_get_initiator_sid(
-	struct se_session *se_sess,
-	unsigned char *buf,
-	u32 size)
-{
-	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
-	/*
-	 * iSCSI Initiator Session Identifier from RFC-3720.
-	 */
-	return snprintf(buf, size, "%6phN", sess->isid);
-}
-
 static int lio_queue_data_in(struct se_cmd *se_cmd)
 {
 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
@@ -1545,7 +1533,6 @@ static void lio_release_cmd(struct se_cmd *se_cmd)
 	.release_cmd			= lio_release_cmd,
 	.close_session			= lio_tpg_close_session,
 	.sess_get_index			= lio_sess_get_index,
-	.sess_get_initiator_sid		= lio_sess_get_initiator_sid,
 	.write_pending			= lio_write_pending,
 	.set_default_node_attributes	= lio_set_default_node_attributes,
 	.get_cmd_state			= iscsi_get_cmd_state,
drivers/target/tcm_fc/tfc_conf.c +0 -1
index 1a38c98..870b7bb 100644
@@ -427,7 +427,6 @@ static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
 	.release_cmd =			ft_release_cmd,
 	.close_session =		ft_sess_close,
 	.sess_get_index =		ft_sess_get_index,
-	.sess_get_initiator_sid =	NULL,
 	.write_pending =		ft_write_pending,
 	.set_default_node_attributes =	ft_set_default_node_attr,
 	.get_cmd_state =		ft_get_cmd_state,
drivers/usb/gadget/function/f_tcm.c +0 -1
index cab3036..e81bdbd 100644
@@ -1716,7 +1716,6 @@ static int usbg_check_stop_free(struct se_cmd *se_cmd)
 	.tpg_get_inst_index		= usbg_tpg_get_inst_index,
 	.release_cmd			= usbg_release_cmd,
 	.sess_get_index			= usbg_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= usbg_send_write_request,
 	.set_default_node_attributes	= usbg_set_default_node_attrs,
 	.get_cmd_state			= usbg_get_cmd_state,
drivers/vhost/scsi.c +0 -1
index 37f66f8..d7c9bfc 100644
@@ -2245,7 +2245,6 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
 	.release_cmd			= vhost_scsi_release_cmd,
 	.check_stop_free		= vhost_scsi_check_stop_free,
 	.sess_get_index			= vhost_scsi_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= vhost_scsi_write_pending,
 	.set_default_node_attributes	= vhost_scsi_set_default_node_attrs,
 	.get_cmd_state			= vhost_scsi_get_cmd_state,
drivers/xen/xen-scsiback.c +0 -1
index f70b6da..883b15c 100644
@@ -1769,7 +1769,6 @@ static int scsiback_check_false(struct se_portal_group *se_tpg)
 	.check_stop_free		= scsiback_check_stop_free,
 	.release_cmd			= scsiback_release_cmd,
 	.sess_get_index			= scsiback_sess_get_index,
-	.sess_get_initiator_sid		= NULL,
 	.write_pending			= scsiback_write_pending,
 	.set_default_node_attributes	= scsiback_set_default_node_attrs,
 	.get_cmd_state			= scsiback_get_cmd_state,
include/target/target_core_fabric.h +0 -6
index 0113e1c..ced377f 100644
@@ -67,12 +67,6 @@ struct target_core_fabric_ops {
 	void (*release_cmd)(struct se_cmd *);
 	void (*close_session)(struct se_session *);
 	u32 (*sess_get_index)(struct se_session *);
-	/*
-	 * Used only for SCSI fabrics that contain multi-value TransportIDs
-	 * (like iSCSI).  All other SCSI fabrics should set this to NULL.
-	 */
-	u32 (*sess_get_initiator_sid)(struct se_session *,
-				      unsigned char *, u32);
 	int (*write_pending)(struct se_cmd *);
 	void (*set_default_node_attributes)(struct se_node_acl *);
 	int (*get_cmd_state)(struct se_cmd *);
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v5 11/15 target: add sysfs support

In reply to Mike Christie

These next two patches add a sysfs interface that reports the target layer's I_T nexuses/sessions. For the non-SCSI people cc'd, this just means we are reporting a server's connections to remote clients.

This patch adds the upper level dirs which shows/organizes our local port (tpgts below) and the connection (session below). The next patch will then add the dirs/files for each connection/session which exports info like ACL/permissions and SCSI port values.

Here is the general layout:

[sys]# tree scsi_target/
scsi_target/

|-- fabric/target module
|   `-- target name
|       `-- tpgt_$target_port_group_number
|           `-- sessions
|               `-- initiator name - session ID number
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id

Here is an example with the scsi target layer's iSCSI driver:

scsi_target/

|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
|-- fc
|-- loopback
|-- qla2xxx_tcm

Note/Question for Greg:

We are not exporting info in the upper level dirs like "fabric/target module", "target name", tpgt, etc and just need those dirs to be able to organize/view the endpoints of the session. So, in this patch I made a new top level dir scsi_target and made the other dirs with kobject_create_and_add. It looks like we could also add device structs in the target related structs, use classes, and build the tree/hierarchy that way too. It was not clear to me when to use one or the other.

Cc Greg Kroah-Hartman <[email protected]>

---

V3:
- delay tpg deletion to allow fabric modules time to remove their sessions.
- Added root sessions dir for easier lookup if userspace has the session id.

V2:
- rename top level dir to scsi_target

 drivers/target/target_core_configfs.c        | 30 +++++++++++++++++++++
 drivers/target/target_core_fabric_configfs.c | 40 ++++++++++++++++++++++++++++
 drivers/target/target_core_internal.h        |  1 +
 include/target/target_core_base.h            |  4 +++
 4 files changed, 75 insertions(+)
drivers/target/target_core_configfs.c +30 -0
index ff82b21f..3eb2566 100644
@@ -63,6 +63,9 @@
 	pr_debug("Setup generic %s\n", __stringify(_name));		\
 }
 
+static struct kobject *tcm_core_kobj;
+static struct kobject *tcm_core_sessions_kobj;
+
 extern struct t10_alua_lu_gp *default_lu_gp;
 
 static LIST_HEAD(g_tf_list);
@@ -245,6 +248,11 @@ static struct config_group *target_core_register_fabric(
 	}
 	pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
 			" %s\n", tf->tf_ops->fabric_name);
+
+	tf->kobj = kobject_create_and_add(name, tcm_core_kobj);
+	if (!tf->kobj)
+		goto dec_tf;
+
 	/*
 	 * On a successful target_core_get_fabric() look, the returned
 	 * struct target_fabric_configfs *tf will contain a usage reference.
@@ -261,6 +269,10 @@ static struct config_group *target_core_register_fabric(
 	pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric: %s\n",
 		 config_item_name(&tf->tf_group.cg_item));
 	return &tf->tf_group;
+
+dec_tf:
+	atomic_dec(&tf->tf_access_cnt);
+	return ERR_PTR(-EINVAL);
 }
 
 /*
@@ -283,6 +295,9 @@ static void target_core_deregister_fabric(
 	pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
 			" %s\n", config_item_name(item));
 
+	kobject_del(tf->kobj);
+	kobject_put(tf->kobj);
+
 	configfs_remove_default_groups(&tf->tf_group);
 	config_item_put(item);
 }
@@ -3538,6 +3553,15 @@ static int __init target_core_init_configfs(void)
 
 	target_init_dbroot();
 
+	tcm_core_kobj = kobject_create_and_add("scsi_target", NULL);
+	if (!tcm_core_kobj)
+		goto out;
+
+	tcm_core_sessions_kobj = kobject_create_and_add("sessions",
+							tcm_core_kobj);
+	if (!tcm_core_sessions_kobj)
+		goto out;
+
 	return 0;
 
 out:
@@ -3555,6 +3579,12 @@ static int __init target_core_init_configfs(void)
 
 static void __exit target_core_exit_configfs(void)
 {
+	kobject_del(tcm_core_sessions_kobj);
+	kobject_put(tcm_core_sessions_kobj);
+
+	kobject_del(tcm_core_kobj);
+	kobject_put(tcm_core_kobj);
+
 	configfs_remove_default_groups(&alua_lu_gps_group);
 	configfs_remove_default_groups(&alua_group);
 	configfs_remove_default_groups(&target_core_hbagroup);
drivers/target/target_core_fabric_configfs.c +40 -0
index ee85602..efa01b3 100644
@@ -807,8 +807,23 @@ static void target_fabric_tpg_release(struct config_item *item)
 			struct se_portal_group, tpg_group);
 	struct se_wwn *wwn = se_tpg->se_tpg_wwn;
 	struct target_fabric_configfs *tf = wwn->wwn_tf;
+	struct kobject *sess_kobj, *tpg_kobj;
+
+	/*
+	 * Some fabric modules remove the session from the drop_tpg callout
+	 * so don't remove these parent dirs until after the session is
+	 * removed.
+	 */
+	sess_kobj = se_tpg->sessions_kobj;
+	tpg_kobj = se_tpg->kobj;
 
 	tf->tf_ops->fabric_drop_tpg(se_tpg);
+
+	kobject_del(sess_kobj);
+	kobject_put(sess_kobj);
+
+	kobject_del(tpg_kobj);
+	kobject_put(tpg_kobj);
 }
 
 static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
@@ -838,6 +853,14 @@ static struct config_group *target_fabric_make_tpg(
 	if (!se_tpg || IS_ERR(se_tpg))
 		return ERR_PTR(-EINVAL);
 
+	se_tpg->kobj = kobject_create_and_add(name, wwn->kobj);
+	if (!se_tpg->kobj)
+		goto drop_tpg;
+
+	se_tpg->sessions_kobj = kobject_create_and_add("sessions", se_tpg->kobj);
+	if (!se_tpg->sessions_kobj)
+		goto del_tpg_kobj;
+
 	config_group_init_type_name(&se_tpg->tpg_group, name,
 			&tf->tf_tpg_base_cit);
 
@@ -872,6 +895,13 @@ static struct config_group *target_fabric_make_tpg(
 			&se_tpg->tpg_group);
 
 	return &se_tpg->tpg_group;
+
+del_tpg_kobj:
+	kobject_del(se_tpg->kobj);
+	kobject_put(se_tpg->kobj);
+drop_tpg:
+	tf->tf_ops->fabric_drop_tpg(se_tpg);
+	return ERR_PTR(-EINVAL);
 }
 
 static void target_fabric_drop_tpg(
@@ -927,6 +957,7 @@ static struct config_group *target_fabric_make_wwn(
 	struct target_fabric_configfs *tf = container_of(group,
 				struct target_fabric_configfs, tf_group);
 	struct se_wwn *wwn;
+	int ret;
 
 	if (!tf->tf_ops->fabric_make_wwn) {
 		pr_err("tf->tf_ops.fabric_make_wwn is NULL\n");
@@ -938,6 +969,9 @@ static struct config_group *target_fabric_make_wwn(
 		return ERR_PTR(-EINVAL);
 
 	wwn->wwn_tf = tf;
+	wwn->kobj = kobject_create_and_add(name, tf->kobj);
+	if (!wwn->kobj)
+		goto drop_wwn;
 
 	config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit);
 
@@ -948,6 +982,10 @@ static struct config_group *target_fabric_make_wwn(
 	if (tf->tf_ops->add_wwn_groups)
 		tf->tf_ops->add_wwn_groups(wwn);
 	return &wwn->wwn_group;
+
+drop_wwn:
+	tf->tf_ops->fabric_drop_wwn(wwn);
+	return ERR_PTR(ret);
 }
 
 static void target_fabric_drop_wwn(
@@ -957,6 +995,8 @@ static void target_fabric_drop_wwn(
 	struct se_wwn *wwn = container_of(to_config_group(item),
 				struct se_wwn, wwn_group);
 
+	kobject_del(wwn->kobj);
+	kobject_put(wwn->kobj);
 	configfs_remove_default_groups(&wwn->wwn_group);
 	config_item_put(item);
 }
drivers/target/target_core_internal.h +1 -0
index 8533444..16ae020 100644
@@ -27,6 +27,7 @@ struct target_backend {
 struct target_fabric_configfs {
 	atomic_t		tf_access_cnt;
 	struct list_head	tf_list;
+	struct kobject		*kobj;
 	struct config_group	tf_group;
 	struct config_group	tf_disc_group;
 	const struct target_core_fabric_ops *tf_ops;
include/target/target_core_base.h +4 -0
index 2e79cce..b7f7e02 100644
@@ -8,6 +8,7 @@
 #include <linux/percpu-refcount.h>
 #include <linux/semaphore.h>     /* struct semaphore */
 #include <linux/completion.h>
+#include <linux/kobject.h>
 
 #define TARGET_CORE_VERSION		"v5.0"
 
@@ -902,6 +903,8 @@ struct se_portal_group {
 	/* Pointer to $FABRIC_MOD dependent code */
 	const struct target_core_fabric_ops *se_tpg_tfo;
 	struct se_wwn		*se_tpg_wwn;
+	struct kobject		*kobj;
+	struct kobject		*sessions_kobj;
 	struct config_group	tpg_group;
 	struct config_group	tpg_lun_group;
 	struct config_group	tpg_np_group;
@@ -940,6 +943,7 @@ struct se_wwn {
 	void			*priv;
 	struct config_group	wwn_group;
 	struct config_group	fabric_stat_group;
+	struct kobject		*kobj;
 };
 
 static inline void atomic_inc_mb(atomic_t *v)
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v5 12/15 target: add sysfs session helper functions

In reply to Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2 files/dirs initially.

acl - name of acl session is accessed through. transport_id - Contains fabric module specific transportID values.

See sysfs-scsi-target below for more info on each file/dir.

scsi_target/

|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
Cc Greg Kroah-Hartman <[email protected]>

---

V4:
- add Documentation/ABI
- use initaitor port prefix instead of generic "session"

V3:
- add session symlink
- use simple ida.

V2:
- Fix extra newline
- Copy data that's exported to sysfs so we do not have to worry about configfs and sysfs refcounts.
- adds back the global sid allocator instead of the per tpg one because in the future we will want to tag target_core_user commands with the session id. This will be needed when tcmu devices are mapped to multiple fabric modules or tpgs and they userspace needs to track the different session to command mappings for commands like PRs.

 Documentation/ABI/testing/sysfs-scsi-target |  46 ++++++
 drivers/target/Makefile                     |   1 +
 drivers/target/target_core_configfs.c       |   2 +-
 drivers/target/target_core_internal.h       |   5 +
 drivers/target/target_core_sysfs.c          | 233 ++++++++++++++++++++++++++++
 drivers/target/target_core_transport.c      |  35 ++++-
 include/target/target_core_base.h           |   6 +
 include/target/target_core_fabric.h         |   8 +-
 8 files changed, 328 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-scsi-target
 create mode 100644 drivers/target/target_core_sysfs.c
Documentation/ABI/testing/sysfs-scsi-target new file +46 -0
new file mode 100644
index 0000000..0408798
@@ -0,0 +1,46 @@
+What:		/sys/scsi_target/<fabric>/<target>/<tpgt_N>/sessions/<initiator-X>
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	The sessions dir contains a dir for each I_T Nexus. The name of
+		the dir is initiator port name followed by an integer that is
+		unique across all fabrics. The dir contains files that export
+		info like the ACL being used, SCSI port values, and fabric and
+		transport specific values.
+
+What:		/sys/scsi_target/<fabric>/.../sessions/<initiator-X>/acl
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	Returns the name of the ACL that was used to validate login or
+		an empty string if no user created ACL was used.
+
+What:		/sys/scsi_target/<fabric>/.../sessions/<initiator-X/transport_id
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	The transport_id contains the SCSI TransportID values for the
+		initiator port as defined in SPC4r37.
+
+What:		/sys/scsi_target/<fabric>/.../sessions/<initiator-X/transport_id/proto
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	Returns the SCSI protocol identifier in hex defined in SPC4r37.
+
+What:		/sys/scsi_target/<fabric>/.../sessions/<initiator-X/transport_id/name
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	Returns the port name/address/id in the protocol specific
+		TransportID format defined in SPC4r37's.
+
+What:		/sys/scsi_target/<fabric>/.../sessions/<initiator-X/transport_id/session_id
+Date:		May 9, 2020
+KernelVersion:	5.8
+Contact:	[email protected]
+Description:	If is proto=0x5 (iSCSI) and TPID FORMAT=1 this file will exist
+		and will return the iSCSI Initiator Session ID in ASCII
+		characters that are the hexadecimal digits converted from the
+		binary iSCSI initiator session identifier value. If iSCSI and
+		format=1 is not used by this session this file will not exist.
drivers/target/Makefile +1 -0
index 4563474..4a7246e 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 target_core_mod-y		:= target_core_configfs.o \
+				   target_core_sysfs.o \
 				   target_core_device.o \
 				   target_core_fabric_configfs.o \
 				   target_core_fabric_lib.o \
drivers/target/target_core_configfs.c +1 -1
index 3eb2566..7a9f607 100644
@@ -64,7 +64,7 @@
 }
 
 static struct kobject *tcm_core_kobj;
-static struct kobject *tcm_core_sessions_kobj;
+struct kobject *tcm_core_sessions_kobj;
 
 extern struct t10_alua_lu_gp *default_lu_gp;
 
drivers/target/target_core_internal.h +5 -0
index 16ae020..5bf216f 100644
@@ -91,6 +91,7 @@ int	target_for_each_device(int (*fn)(struct se_device *dev, void *data),
 			       void *data);
 
 /* target_core_configfs.c */
+extern struct kobject *tcm_core_sessions_kobj;
 extern struct configfs_item_operations target_core_dev_item_ops;
 void	target_setup_backend_cits(struct target_backend *);
 
@@ -106,6 +107,9 @@ int	target_get_pr_transport_id(struct se_node_acl *nacl,
 const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
 		char *buf, u32 *out_tid_len, char **port_nexus_ptr);
 
+/* target_core_sysfs.c */
+void	target_sysfs_init_session(struct se_session *sess);
+
 /* target_core_hba.c */
 struct se_hba *core_alloc_hba(const char *, u32, u32);
 int	core_delete_hba(struct se_hba *);
@@ -153,6 +157,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_free_session(struct se_session *);
 
 /* target_core_stat.c */
 void	target_stat_setup_dev_default_groups(struct se_device *);
drivers/target/target_core_sysfs.c new file +233 -0

233 lines not on this page · raw message

drivers/target/target_core_transport.c +29 -6
index fdf84db..04cb042 100644
@@ -42,6 +42,7 @@
 
 static struct workqueue_struct *target_completion_wq;
 static struct kmem_cache *se_sess_cache;
+static DEFINE_IDA(se_sess_ida);
 struct kmem_cache *se_ua_cache;
 struct kmem_cache *t10_pr_reg_cache;
 struct kmem_cache *t10_alua_lu_gp_cache;
@@ -251,14 +252,27 @@ struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops)
 				" se_sess_cache\n");
 		return ERR_PTR(-ENOMEM);
 	}
-	ret = transport_init_session(se_sess);
+
+	ret = ida_simple_get(&se_sess_ida, 1, 0, GFP_KERNEL);
 	if (ret < 0) {
-		kmem_cache_free(se_sess_cache, se_sess);
-		return ERR_PTR(ret);
+		pr_err("Unable to allocate session index.\n");
+		goto free_sess;
 	}
-	se_sess->sup_prot_ops = sup_prot_ops;
+	se_sess->sid = ret;
+
+	ret = transport_init_session(se_sess);
+	if (ret < 0)
+		goto free_sid;
 
+	se_sess->sup_prot_ops = sup_prot_ops;
+	target_sysfs_init_session(se_sess);
 	return se_sess;
+
+free_sid:
+	ida_simple_remove(&se_sess_ida, se_sess->sid);
+free_sess:
+	kmem_cache_free(se_sess_cache, se_sess);
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL(transport_alloc_session);
 
@@ -597,12 +611,21 @@ void transport_free_session(struct se_session *se_sess)
 		sbitmap_queue_free(&se_sess->sess_tag_pool);
 		kvfree(se_sess->sess_cmd_map);
 	}
-	target_free_transport_id(se_sess->tpt_id);
 	percpu_ref_exit(&se_sess->cmd_count);
-	kmem_cache_free(se_sess_cache, se_sess);
+	kobject_put(&se_sess->kobj);
 }
 EXPORT_SYMBOL(transport_free_session);
 
+void __target_free_session(struct se_session *se_sess)
+{
+	kfree(se_sess->acl_name);
+	target_free_transport_id(se_sess->tpt_id);
+
+	ida_simple_remove(&se_sess_ida, se_sess->sid);
+
+	kmem_cache_free(se_sess_cache, se_sess);
+}
+
 static int target_release_res(struct se_device *dev, void *data)
 {
 	struct se_session *sess = data;
include/target/target_core_base.h +6 -0
index b7f7e02..34d89cb 100644
@@ -9,6 +9,7 @@
 #include <linux/semaphore.h>     /* struct semaphore */
 #include <linux/completion.h>
 #include <linux/kobject.h>
+#include <linux/idr.h>
 
 #define TARGET_CORE_VERSION		"v5.0"
 
@@ -626,6 +627,7 @@ struct se_session {
 	enum target_prot_op	sup_prot_ops;
 	enum target_prot_type	sess_prot_type;
 	struct se_node_acl	*se_node_acl;
+	char			*acl_name;
 	struct se_portal_group *se_tpg;
 	void			*fabric_sess_ptr;
 	struct percpu_ref	cmd_count;
@@ -636,6 +638,10 @@ struct se_session {
 	wait_queue_head_t	cmd_list_wq;
 	void			*sess_cmd_map;
 	struct sbitmap_queue	sess_tag_pool;
+	struct kobject		kobj;
+	int			sid;
+	bool			sysfs_added;
+	const struct target_core_fabric_ops *tfo;
 };
 
 struct se_device;
include/target/target_core_fabric.h +7 -1
index ced377f..f876a05 100644
@@ -74,6 +74,10 @@ struct target_core_fabric_ops {
 	int (*queue_status)(struct se_cmd *);
 	void (*queue_tm_rsp)(struct se_cmd *);
 	void (*aborted_task)(struct se_cmd *);
+
+	/* Optional session management and sysfs callouts */
+	const struct attribute_group *session_attrs;
+
 	/*
 	 * fabric module calls for target_core_fabric_configfs.c
 	 */
@@ -145,7 +149,9 @@ 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 *);
-
+void	target_sysfs_remove_session(struct se_session *se_sess);
+int	target_sysfs_add_session(struct se_portal_group *se_tpg,
+				 struct se_session *se_sess);
 
 void	transport_init_se_cmd(struct se_cmd *,
 		const struct target_core_fabric_ops *,
Signature · 1 line
1.8.3.1
#39 lore raw

PATCH v5 13/15 target: add target_setup_session sysfs support

In reply to Mike Christie

This adds a session dir per session for users of target_setup_session.

---
 drivers/target/target_core_transport.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/target/target_core_transport.c +9 -1
index 04cb042..7bfeab2 100644
@@ -457,6 +457,7 @@ struct se_session *
 
 	if (IS_ERR(sess))
 		return sess;
+	sess->tfo = tpg->se_tpg_tfo;
 
 	sess->tpt_id = target_create_transport_id(tpg->proto_id, tpt_id_name,
 						  NULL);
@@ -471,6 +472,10 @@ struct se_session *
 		rc = -EACCES;
 		goto free_sess;
 	}
+
+	rc = target_sysfs_add_session(tpg, sess);
+	if (rc)
+		goto free_sess;
 	/*
 	 * Go ahead and perform any remaining fabric setup that is
 	 * required before transport_register_session().
@@ -478,12 +483,14 @@ struct se_session *
 	if (callback != NULL) {
 		rc = callback(tpg, sess, private);
 		if (rc)
-			goto free_sess;
+			goto rm_sysfs;
 	}
 
 	transport_register_session(tpg, sess->se_node_acl, sess, private);
 	return sess;
 
+rm_sysfs:
+	target_sysfs_remove_session(sess);
 free_sess:
 	transport_free_session(sess);
 	return ERR_PTR(rc);
@@ -674,6 +681,7 @@ void transport_deregister_session(struct se_session *se_sess)
 
 void target_remove_session(struct se_session *se_sess)
 {
+	target_sysfs_remove_session(se_sess);
 	transport_deregister_session_configfs(se_sess);
 	transport_deregister_session(se_sess);
 }
Signature · 1 line
1.8.3.1
#40 lore raw

PATCH v5 14/15 iscsi target: use session sysfs helpers

In reply to Mike Christie

The iscsi target login process breaks up session allocation and registration, so it does not use target_setup_session like every one else. This converts iscsi to use the session sysfs helpers and drops its session id to use the common one.

---
V3:
- Fix goto use. Actually moved sysfs addition call to after nego to avoid sysfs additions when login ends up failing.

 drivers/target/iscsi/iscsi_target.c          |  3 +--
 drivers/target/iscsi/iscsi_target_configfs.c |  4 +---
 drivers/target/iscsi/iscsi_target_login.c    | 16 ++--------------
 drivers/target/iscsi/iscsi_target_nego.c     |  8 ++++++++
 drivers/target/iscsi/iscsi_target_stat.c     |  3 +--
 include/target/iscsi/iscsi_target_core.h     |  2 --
 6 files changed, 13 insertions(+), 23 deletions(-)
drivers/target/iscsi/iscsi_target.c +1 -2
index 59379d6..e04aba4 100644
@@ -49,7 +49,6 @@
 static DEFINE_MUTEX(np_lock);
 
 static struct idr tiqn_idr;
-DEFINE_IDA(sess_ida);
 struct mutex auth_id_lock;
 
 struct iscsit_global *iscsit_global;
@@ -4359,6 +4358,7 @@ int iscsit_close_session(struct iscsi_session *sess)
 	iscsit_stop_time2retain_timer(sess);
 	spin_unlock_bh(&se_tpg->session_lock);
 
+	target_sysfs_remove_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
@@ -4403,7 +4403,6 @@ int iscsit_close_session(struct iscsi_session *sess)
 	pr_debug("Decremented number of active iSCSI Sessions on"
 		" iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions);
 
-	ida_free(&sess_ida, sess->session_index);
 	kfree(sess->sess_ops);
 	sess->sess_ops = NULL;
 	spin_unlock_bh(&se_tpg->session_lock);
drivers/target/iscsi/iscsi_target_configfs.c +1 -3
index 4513740..9301793 100644
@@ -1344,9 +1344,7 @@ static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
 
 static u32 lio_sess_get_index(struct se_session *se_sess)
 {
-	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
-
-	return sess->session_index;
+	return se_sess->sid;
 }
 
 static int lio_queue_data_in(struct se_cmd *se_cmd)
drivers/target/iscsi/iscsi_target_login.c +2 -14
index 731ee67..619ea09 100644
@@ -257,7 +257,6 @@ static int iscsi_login_zero_tsih_s1(
 {
 	struct iscsi_session *sess = NULL;
 	struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf;
-	int ret;
 
 	sess = kzalloc(sizeof(struct iscsi_session), GFP_KERNEL);
 	if (!sess) {
@@ -291,15 +290,6 @@ static int iscsi_login_zero_tsih_s1(
 	timer_setup(&sess->time2retain_timer,
 		    iscsit_handle_time2retain_timeout, 0);
 
-	ret = ida_alloc(&sess_ida, GFP_KERNEL);
-	if (ret < 0) {
-		pr_err("Session ID allocation failed %d\n", ret);
-		iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-				ISCSI_LOGIN_STATUS_NO_RESOURCES);
-		goto free_sess;
-	}
-
-	sess->session_index = ret;
 	sess->creation_time = get_jiffies_64();
 	/*
 	 * The FFP CmdSN window values will be allocated from the TPG's
@@ -313,7 +303,7 @@ static int iscsi_login_zero_tsih_s1(
 				ISCSI_LOGIN_STATUS_NO_RESOURCES);
 		pr_err("Unable to allocate memory for"
 				" struct iscsi_sess_ops.\n");
-		goto free_id;
+		goto free_sess;
 	}
 
 	sess->se_sess = transport_alloc_session(TARGET_PROT_NORMAL);
@@ -327,8 +317,6 @@ static int iscsi_login_zero_tsih_s1(
 
 free_ops:
 	kfree(sess->sess_ops);
-free_id:
-	ida_free(&sess_ida, sess->session_index);
 free_sess:
 	kfree(sess);
 	conn->sess = NULL;
@@ -1183,8 +1171,8 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
 	if (!zero_tsih || !conn->sess)
 		goto old_sess_out;
 
+	target_sysfs_remove_session(conn->sess->se_sess);
 	transport_free_session(conn->sess->se_sess);
-	ida_free(&sess_ida, conn->sess->session_index);
 	kfree(conn->sess->sess_ops);
 	kfree(conn->sess);
 	conn->sess = NULL;
drivers/target/iscsi/iscsi_target_nego.c +8 -0
index c44613a2..c5184c0 100644
@@ -359,6 +359,13 @@ static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_log
 					    ISCSI_LOGIN_STATUS_NO_RESOURCES);
 			return -1;
 		}
+
+		if (target_sysfs_add_session(&conn->tpg->tpg_se_tpg,
+					     conn->sess->se_sess)) {
+			iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
+					    ISCSI_LOGIN_STATUS_NO_RESOURCES);
+			return -1;
+		}
 	}
 
 	if (conn->conn_transport->iscsit_put_login_tx(conn, login,
@@ -1276,6 +1283,7 @@ int iscsi_target_locate_portal(
 	ret = transport_alloc_session_tags(sess->se_sess, tag_num, tag_size);
 	if (ret < 0)
 		goto return_oom;
+	sess->se_sess->tfo = &iscsi_ops;
 
 	if (conn->tpg != iscsit_global->discovery_tpg) {
 		if (iscsi_setup_i_tpt_id(sess, i_buf))
drivers/target/iscsi/iscsi_target_stat.c +1 -2
index 35e75a3..8167fdc 100644
@@ -630,8 +630,7 @@ static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
 	if (se_sess) {
 		sess = se_sess->fabric_sess_ptr;
 		if (sess)
-			ret = snprintf(page, PAGE_SIZE, "%u\n",
-					sess->session_index);
+			ret = snprintf(page, PAGE_SIZE, "%u\n", se_sess->sid);
 	}
 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
 
include/target/iscsi/iscsi_target_core.h +0 -2
index 591cd9e..443c5af 100644
@@ -657,8 +657,6 @@ struct iscsi_session {
 	/* LIO specific session ID */
 	u32			sid;
 	char			auth_type[8];
-	/* unique within the target */
-	int			session_index;
 	/* Used for session reference counting */
 	int			session_usage_count;
 	int			session_waiting_on_uc;
Signature · 1 line
1.8.3.1
#41 lore raw

PATCH v5 15/15 target: drop sess_get_index

In reply to Mike Christie

LIO now handles session id allocation so drop the callout.

---
 drivers/infiniband/ulp/srpt/ib_srpt.c        | 15 ---------------
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c     |  6 ------
 drivers/scsi/qla2xxx/tcm_qla2xxx.c           |  7 -------
 drivers/target/iscsi/iscsi_target_configfs.c |  6 ------
 drivers/target/loopback/tcm_loop.c           |  6 ------
 drivers/target/sbp/sbp_target.c              |  6 ------
 drivers/target/target_core_configfs.c        |  4 ----
 drivers/target/target_core_stat.c            |  5 +----
 drivers/target/tcm_fc/tfc_conf.c             |  1 -
 drivers/target/tcm_fc/tfc_sess.c             |  7 -------
 drivers/usb/gadget/function/f_tcm.c          |  6 ------
 drivers/vhost/scsi.c                         |  6 ------
 drivers/xen/xen-scsiback.c                   |  6 ------
 include/target/target_core_fabric.h          |  1 -
 14 files changed, 1 insertion(+), 81 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +0 -15
index 3cda73c..7fe76e0 100644
@@ -3353,20 +3353,6 @@ static void srpt_close_session(struct se_session *se_sess)
 	srpt_disconnect_ch_sync(ch);
 }
 
-/**
- * srpt_sess_get_index - return the value of scsiAttIntrPortIndex (SCSI-MIB)
- * @se_sess: SCSI target session.
- *
- * A quote from RFC 4455 (SCSI-MIB) about this MIB object:
- * This object represents an arbitrary integer used to uniquely identify a
- * particular attached remote initiator port to a particular SCSI target port
- * within a particular SCSI target device within a particular SCSI instance.
- */
-static u32 srpt_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static void srpt_set_default_node_attrs(struct se_node_acl *nacl)
 {
 }
@@ -3843,7 +3829,6 @@ static ssize_t srpt_wwn_version_show(struct config_item *item, char *buf)
 	.release_cmd			= srpt_release_cmd,
 	.check_stop_free		= srpt_check_stop_free,
 	.close_session			= srpt_close_session,
-	.sess_get_index			= srpt_sess_get_index,
 	.write_pending			= srpt_write_pending,
 	.set_default_node_attributes	= srpt_set_default_node_attrs,
 	.get_cmd_state			= srpt_get_tcm_cmd_state,
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +0 -6
index 31459f3..8d37375 100644
@@ -3739,11 +3739,6 @@ static void ibmvscsis_release_cmd(struct se_cmd *se_cmd)
 	spin_unlock_bh(&vscsi->intr_lock);
 }
 
-static u32 ibmvscsis_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static int ibmvscsis_write_pending(struct se_cmd *se_cmd)
 {
 	struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
@@ -4034,7 +4029,6 @@ static ssize_t ibmvscsis_tpg_enable_store(struct config_item *item,
 	.tpg_get_inst_index		= ibmvscsis_tpg_get_inst_index,
 	.check_stop_free		= ibmvscsis_check_stop_free,
 	.release_cmd			= ibmvscsis_release_cmd,
-	.sess_get_index			= ibmvscsis_sess_get_index,
 	.write_pending			= ibmvscsis_write_pending,
 	.set_default_node_attributes	= ibmvscsis_set_default_node_attrs,
 	.get_cmd_state			= ibmvscsis_get_cmd_state,
drivers/scsi/qla2xxx/tcm_qla2xxx.c +0 -7
index fff695a..8a68085 100644
@@ -377,11 +377,6 @@ static void tcm_qla2xxx_close_session(struct se_session *se_sess)
 	tcm_qla2xxx_put_sess(sess);
 }
 
-static u32 tcm_qla2xxx_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static int tcm_qla2xxx_write_pending(struct se_cmd *se_cmd)
 {
 	struct qla_tgt_cmd *cmd = container_of(se_cmd,
@@ -1851,7 +1846,6 @@ static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
 	.check_stop_free		= tcm_qla2xxx_check_stop_free,
 	.release_cmd			= tcm_qla2xxx_release_cmd,
 	.close_session			= tcm_qla2xxx_close_session,
-	.sess_get_index			= tcm_qla2xxx_sess_get_index,
 	.write_pending			= tcm_qla2xxx_write_pending,
 	.set_default_node_attributes	= tcm_qla2xxx_set_default_node_attrs,
 	.get_cmd_state			= tcm_qla2xxx_get_cmd_state,
@@ -1890,7 +1884,6 @@ static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
 	.check_stop_free                = tcm_qla2xxx_check_stop_free,
 	.release_cmd			= tcm_qla2xxx_release_cmd,
 	.close_session			= tcm_qla2xxx_close_session,
-	.sess_get_index			= tcm_qla2xxx_sess_get_index,
 	.write_pending			= tcm_qla2xxx_write_pending,
 	.set_default_node_attributes	= tcm_qla2xxx_set_default_node_attrs,
 	.get_cmd_state			= tcm_qla2xxx_get_cmd_state,
drivers/target/iscsi/iscsi_target_configfs.c +0 -6
index 9301793..141455e 100644
@@ -1342,11 +1342,6 @@ static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
 	return cmd->i_state;
 }
 
-static u32 lio_sess_get_index(struct se_session *se_sess)
-{
-	return se_sess->sid;
-}
-
 static int lio_queue_data_in(struct se_cmd *se_cmd)
 {
 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
@@ -1530,7 +1525,6 @@ static void lio_release_cmd(struct se_cmd *se_cmd)
 	.check_stop_free		= lio_check_stop_free,
 	.release_cmd			= lio_release_cmd,
 	.close_session			= lio_tpg_close_session,
-	.sess_get_index			= lio_sess_get_index,
 	.write_pending			= lio_write_pending,
 	.set_default_node_attributes	= lio_set_default_node_attributes,
 	.get_cmd_state			= iscsi_get_cmd_state,
drivers/target/loopback/tcm_loop.c +0 -6
index 64e5f1f..8daa424 100644
@@ -512,11 +512,6 @@ static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg)
 	return 1;
 }
 
-static u32 tcm_loop_sess_get_index(struct se_session *se_sess)
-{
-	return 1;
-}
-
 static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl)
 {
 	return;
@@ -1093,7 +1088,6 @@ static ssize_t tcm_loop_wwn_version_show(struct config_item *item, char *page)
 	.tpg_get_inst_index		= tcm_loop_get_inst_index,
 	.check_stop_free		= tcm_loop_check_stop_free,
 	.release_cmd			= tcm_loop_release_cmd,
-	.sess_get_index			= tcm_loop_sess_get_index,
 	.write_pending			= tcm_loop_write_pending,
 	.set_default_node_attributes	= tcm_loop_set_default_node_attributes,
 	.get_cmd_state			= tcm_loop_get_cmd_state,
drivers/target/sbp/sbp_target.c +0 -6
index 2cac4d9..782c326 100644
@@ -1708,11 +1708,6 @@ static void sbp_release_cmd(struct se_cmd *se_cmd)
 	sbp_free_request(req);
 }
 
-static u32 sbp_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static int sbp_write_pending(struct se_cmd *se_cmd)
 {
 	struct sbp_target_request *req = container_of(se_cmd,
@@ -2309,7 +2304,6 @@ static ssize_t sbp_tpg_attrib_max_logins_per_lun_store(struct config_item *item,
 	.tpg_check_prod_mode_write_protect = sbp_check_false,
 	.tpg_get_inst_index		= sbp_tpg_get_inst_index,
 	.release_cmd			= sbp_release_cmd,
-	.sess_get_index			= sbp_sess_get_index,
 	.write_pending			= sbp_write_pending,
 	.set_default_node_attributes	= sbp_set_default_node_attrs,
 	.get_cmd_state			= sbp_get_cmd_state,
drivers/target/target_core_configfs.c +0 -4
index 7a9f607..b3e52eb 100644
@@ -400,10 +400,6 @@ static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
 		pr_err("Missing tfo->release_cmd()\n");
 		return -EINVAL;
 	}
-	if (!tfo->sess_get_index) {
-		pr_err("Missing tfo->sess_get_index()\n");
-		return -EINVAL;
-	}
 	if (!tfo->write_pending) {
 		pr_err("Missing tfo->write_pending()\n");
 		return -EINVAL;
drivers/target/target_core_stat.c +1 -4
index 3eb1b9b..621dc17 100644
@@ -1264,7 +1264,6 @@ static ssize_t target_stat_iport_indx_show(struct config_item *item,
 	struct se_lun_acl *lacl = iport_to_lacl(item);
 	struct se_node_acl *nacl = lacl->se_lun_nacl;
 	struct se_session *se_sess;
-	struct se_portal_group *tpg;
 	ssize_t ret;
 
 	spin_lock_irq(&nacl->nacl_sess_lock);
@@ -1274,10 +1273,8 @@ static ssize_t target_stat_iport_indx_show(struct config_item *item,
 		return -ENODEV;
 	}
 
-	tpg = nacl->se_tpg;
 	/* scsiAttIntrPortIndex */
-	ret = snprintf(page, PAGE_SIZE, "%u\n",
-			tpg->se_tpg_tfo->sess_get_index(se_sess));
+	ret = snprintf(page, PAGE_SIZE, "%u\n", se_sess->sid);
 	spin_unlock_irq(&nacl->nacl_sess_lock);
 	return ret;
 }
drivers/target/tcm_fc/tfc_conf.c +0 -1
index 870b7bb..747824f 100644
@@ -426,7 +426,6 @@ static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
 	.check_stop_free =		ft_check_stop_free,
 	.release_cmd =			ft_release_cmd,
 	.close_session =		ft_sess_close,
-	.sess_get_index =		ft_sess_get_index,
 	.write_pending =		ft_write_pending,
 	.set_default_node_attributes =	ft_set_default_node_attr,
 	.get_cmd_state =		ft_get_cmd_state,
drivers/target/tcm_fc/tfc_sess.c +0 -7
index 1d1c460..84a2c5d 100644
@@ -326,13 +326,6 @@ void ft_sess_close(struct se_session *se_sess)
 	synchronize_rcu();		/* let transport deregister happen */
 }
 
-u32 ft_sess_get_index(struct se_session *se_sess)
-{
-	struct ft_sess *sess = se_sess->fabric_sess_ptr;
-
-	return sess->port_id;	/* XXX TBD probably not what is needed */
-}
-
 u32 ft_sess_get_port_name(struct se_session *se_sess,
 			  unsigned char *buf, u32 len)
 {
drivers/usb/gadget/function/f_tcm.c +0 -6
index e81bdbd..7bdd7c5 100644
@@ -1287,11 +1287,6 @@ static void usbg_release_cmd(struct se_cmd *se_cmd)
 	target_free_tag(se_sess, se_cmd);
 }
 
-static u32 usbg_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static void usbg_set_default_node_attrs(struct se_node_acl *nacl)
 {
 }
@@ -1715,7 +1710,6 @@ static int usbg_check_stop_free(struct se_cmd *se_cmd)
 	.tpg_check_prod_mode_write_protect = usbg_check_false,
 	.tpg_get_inst_index		= usbg_tpg_get_inst_index,
 	.release_cmd			= usbg_release_cmd,
-	.sess_get_index			= usbg_sess_get_index,
 	.write_pending			= usbg_send_write_request,
 	.set_default_node_attributes	= usbg_set_default_node_attrs,
 	.get_cmd_state			= usbg_get_cmd_state,
drivers/vhost/scsi.c +0 -6
index d7c9bfc..14f7c3bf 100644
@@ -340,11 +340,6 @@ static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
 	target_free_tag(se_sess, se_cmd);
 }
 
-static u32 vhost_scsi_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static int vhost_scsi_write_pending(struct se_cmd *se_cmd)
 {
 	/* Go ahead and process the write immediately */
@@ -2244,7 +2239,6 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
 	.tpg_get_inst_index		= vhost_scsi_tpg_get_inst_index,
 	.release_cmd			= vhost_scsi_release_cmd,
 	.check_stop_free		= vhost_scsi_check_stop_free,
-	.sess_get_index			= vhost_scsi_sess_get_index,
 	.write_pending			= vhost_scsi_write_pending,
 	.set_default_node_attributes	= vhost_scsi_set_default_node_attrs,
 	.get_cmd_state			= vhost_scsi_get_cmd_state,
drivers/xen/xen-scsiback.c +0 -6
index 883b15c..923c96a 100644
@@ -1392,11 +1392,6 @@ static void scsiback_release_cmd(struct se_cmd *se_cmd)
 	target_free_tag(se_cmd->se_sess, se_cmd);
 }
 
-static u32 scsiback_sess_get_index(struct se_session *se_sess)
-{
-	return 0;
-}
-
 static int scsiback_write_pending(struct se_cmd *se_cmd)
 {
 	/* Go ahead and process the write immediately */
@@ -1768,7 +1763,6 @@ static int scsiback_check_false(struct se_portal_group *se_tpg)
 	.tpg_get_inst_index		= scsiback_tpg_get_inst_index,
 	.check_stop_free		= scsiback_check_stop_free,
 	.release_cmd			= scsiback_release_cmd,
-	.sess_get_index			= scsiback_sess_get_index,
 	.write_pending			= scsiback_write_pending,
 	.set_default_node_attributes	= scsiback_set_default_node_attrs,
 	.get_cmd_state			= scsiback_get_cmd_state,
include/target/target_core_fabric.h +0 -1
index f876a05..54ce800 100644
@@ -66,7 +66,6 @@ struct target_core_fabric_ops {
 	int (*check_stop_free)(struct se_cmd *);
 	void (*release_cmd)(struct se_cmd *);
 	void (*close_session)(struct se_session *);
-	u32 (*sess_get_index)(struct se_session *);
 	int (*write_pending)(struct se_cmd *);
 	void (*set_default_node_attributes)(struct se_node_acl *);
 	int (*get_cmd_state)(struct se_cmd *);
Signature · 1 line
1.8.3.1
Reviewed-by on v5 1/15
#2 lore raw

Re: [PATCH 01/15] target: check enforce_pr_isids during registration

In reply to Mike Christie
Quoted 6 lines · Mike Christie

Move the check for enforce_pr_isids to the registration code where we can fail at the time an initiator tries to register a path without an isid. In its current place in __core_scsi3_locate_pr_reg, it is too late because it can be registered and be reported in PR in commands and it is stuck in this state because we cannot unregister it.

Quoted 8 lines

Note.
I am including in this patchset, because the 5th patch is built on top.

---
  drivers/target/target_core_pr.c | 24 +++++++++++++++---------
  1 file changed, 15 insertions(+), 9 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 2/15
#5 lore raw

Re: [PATCH 02/15] target: separate acl name from port ids

In reply to Mike Christie
Quoted 33 lines · Mike Christie

The PGR code assumes the ACL name is going to be based on the SPC4 transportID type of values. The problem is that for iSCSI we have an extra session id as part of the SCSI port id and some fabric modules support or would like to support non transportID values for the ACL name. For example, iSCSI and SRP would like to use the source address for the ACL name, but that is not a valud transportID value that you can get in a PGR request.

This patch adds a new transport_id struct which maps to the SPC4 transportID. In the future it will be used for PGR commands instead of the ACL name. In this patchset it is used to export the initiator info in the session's sysfs dir, so tools can display the info and daemons that execute commands like PGRs in userspace can build a session id to I_T nexus mapping.

In this patch only srp is passing in different values for the transport id and acl name. The next patches will convert loop, scsi vhost and xen scsiback that are more complex due to their initiator name emulation.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>

---

V4:
- Don't drop const char use. We still have target_setup_session allocate the transport_id struct, but because every uses format=0 we just need to pass in the transport_id's name.

V3:
- drop format

Quoted 15 lines
  drivers/infiniband/ulp/srpt/ib_srpt.c    | 10 +++++---
  drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c |  4 +--
  drivers/scsi/qla2xxx/tcm_qla2xxx.c       |  2 +-
  drivers/target/loopback/tcm_loop.c       |  3 ++-
  drivers/target/sbp/sbp_target.c          |  2 +-
  drivers/target/target_core_fabric_lib.c  | 41 +++++++++++++++++++++++++++++++
  drivers/target/target_core_transport.c   | 42 ++++++++++++++++++++++++--------
  drivers/target/tcm_fc/tfc_sess.c         |  3 ++-
  drivers/usb/gadget/function/f_tcm.c      |  3 ++-
  drivers/vhost/scsi.c                     |  1 +
  drivers/xen/xen-scsiback.c               |  3 ++-
  include/target/target_core_base.h        | 12 +++++++++
  include/target/target_core_fabric.h      |  5 +++-
  13 files changed, 108 insertions(+), 23 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 3/15
#8 lore raw

Re: [PATCH 03/15] target: add helper to parse acl and transport name

In reply to Mike Christie
Quoted 14 lines · Mike Christie

The drivers that emulate the initiator port id (loop, scsi vhost, xen scsiback) do almost the extact same parsing when making their I_T_nexus. This adds a helper that parses out the acl name and port name from the user buffer, so these types of drivers drop prefixes like "naa." when they need to for the SCSI SPC4 TransportID SAS address, but then keep it for the LIO ACL name.

The next patches will then convert those drivers.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>
Quoted 5 lines
---
  drivers/target/target_core_fabric_lib.c | 73 +++++++++++++++++++++++++++++++++
  include/target/target_core_fabric.h     |  2 +
  2 files changed, 75 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 4/15
#13 lore raw

Re: [PATCH 04/15] tcm loop: use target_parse_emulated_name

In reply to Mike Christie
Quoted 8 lines · Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

---
  drivers/target/loopback/tcm_loop.c | 65 ++++++--------------------------------
  1 file changed, 10 insertions(+), 55 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 5/15
#16 lore raw

Re: [PATCH 05/15] vhost scsi: use target_parse_emulated_name

In reply to Mike Christie
Quoted 12 lines · Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
  drivers/vhost/scsi.c | 69 +++++++++-------------------------------------------
  1 file changed, 11 insertions(+), 58 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 6/15
#18 lore raw

Re: [PATCH 06/15] xen scsiback: use target_parse_emulated_name

In reply to Mike Christie
Quoted 9 lines · Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

---
  drivers/xen/xen-scsiback.c | 66 ++++++++--------------------------------------
  1 file changed, 11 insertions(+), 55 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 7/15
#21 lore raw

Re: [PATCH 07/15] iscsi target: setup transport_id

In reply to Mike Christie
Quoted 8 lines · Mike Christie

The iscsi target does its own session setup. This patch updates the driver so it sets up the transport id.

---
  drivers/target/iscsi/iscsi_target_nego.c | 32 ++++++++++++++++++++++++++++----
  1 file changed, 28 insertions(+), 4 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 8/15
#23 lore raw

Re: [PATCH 08/15] target: use tpt_id in target_stat_iport_port_ident_show

In reply to Mike Christie
Quoted 4 lines · Mike Christie

Use the tpt_id session id instead of sess_get_initiator_sid.

Note that for userspace compat this patch continues the behavior:

Quoted 8 lines

1. Still add the "+i+" even if there is no session_id.
2. Use the acl initiatorname instead of the transportID port/addr/name.

---
  drivers/target/target_core_stat.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 9/15
#25 lore raw

Re: [PATCH 09/15] target: drop sess_get_initiator_sid from PR code

In reply to Mike Christie
Quoted 8 lines · Mike Christie

Use the transport id session id in the PR related code.

---
  drivers/target/target_core_pr.c        | 23 ++++-------------------
  drivers/target/target_core_transport.c | 11 ++++-------
  2 files changed, 8 insertions(+), 26 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Reviewed-by on v5 10/15
#27 lore raw

Re: [PATCH 10/15] target: drop sess_get_initiator_sid

In reply to Mike Christie
Quoted 4 lines · Mike Christie

sess_get_initiator_sid is no longer used. Drop it.

Quoted 11 lines
---
  drivers/infiniband/ulp/srpt/ib_srpt.c        |  1 -
  drivers/scsi/qla2xxx/tcm_qla2xxx.c           |  2 --
  drivers/target/iscsi/iscsi_target_configfs.c | 13 -------------
  drivers/target/tcm_fc/tfc_conf.c             |  1 -
  drivers/usb/gadget/function/f_tcm.c          |  1 -
  drivers/vhost/scsi.c                         |  1 -
  drivers/xen/xen-scsiback.c                   |  1 -
  include/target/target_core_fabric.h          |  6 ------
  8 files changed, 26 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
#29 lore raw
In reply to Mike Christie
Quoted 27 lines · Mike Christie

These next two patches add a sysfs interface that reports the target layer's I_T nexuses/sessions. For the non-SCSI people cc'd, this just means we are reporting a server's connections to remote clients.

This patch adds the upper level dirs which shows/organizes our local port (tpgts below) and the connection (session below). The next patch will then add the dirs/files for each connection/session which exports info like ACL/permissions and SCSI port values.

Here is the general layout:

[sys]# tree scsi_target/
scsi_target/

|-- fabric/target module
|   `-- target name
|       `-- tpgt_$target_port_group_number
|           `-- sessions
|               `-- initiator name - session ID number
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id

Here is an example with the scsi target layer's iSCSI driver:

scsi_target/

Quoted 15 lines
|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
|-- fc
|-- loopback
|-- qla2xxx_tcm

I'm not sure if we want to include the actual name for the target name or initiatorname; that we we'll get an instant denial of service if we fail to cleanup this directory and want to recreate a new one. Normally we have been using logical names for sysfs directories (ie targertport0 or session0) and include the actual names in a sysfs attribute. That way the structure can stay around for slightly longer (ie for cleanup operations) _and_ we can create a new one to allow new connections with the same credentials.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
#30 lore raw
In reply to Mike Christie
Quoted 44 lines · Mike Christie

These next two patches add a sysfs interface that reports the target layer's I_T nexuses/sessions. For the non-SCSI people cc'd, this just means we are reporting a server's connections to remote clients.

This patch adds the upper level dirs which shows/organizes our local port (tpgts below) and the connection (session below). The next patch will then add the dirs/files for each connection/session which exports info like ACL/permissions and SCSI port values.

Here is the general layout:

[sys]# tree scsi_target/
scsi_target/

|-- fabric/target module
|   `-- target name
|       `-- tpgt_$target_port_group_number
|           `-- sessions
|               `-- initiator name - session ID number
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id

Here is an example with the scsi target layer's iSCSI driver:

scsi_target/

|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
|-- fc
|-- loopback
|-- qla2xxx_tcm

Note/Question for Greg:

Quoted 7 lines

We are not exporting info in the upper level dirs like "fabric/target module", "target name", tpgt, etc and just need those dirs to be able to organize/view the endpoints of the session. So, in this patch I made a new top level dir scsi_target and made the other dirs with kobject_create_and_add. It looks like we could also add device structs in the target related structs, use classes, and build the tree/hierarchy that way too. It was not clear to me when to use one or the other.

Never use kobject calls in a driver subsystem like you have here, as those objects will not be seen by userspace tools that get uevents. Just use real 'struct devices' if you really really need a deep directory tree.

But I would push back here, why do you feel you want such a deep tree? What are you getting from this? Why do you need that "sessions" directory at all?

Try doing this with just attributes and if you really really need it, child devices.

Quoted 25 lines
Cc Greg Kroah-Hartman <[email protected]>

---

V3:
- delay tpg deletion to allow fabric modules time to remove their sessions.
- Added root sessions dir for easier lookup if userspace has the session id.

V2:
- rename top level dir to scsi_target

 drivers/target/target_core_configfs.c        | 30 +++++++++++++++++++++
 drivers/target/target_core_fabric_configfs.c | 40 ++++++++++++++++++++++++++++
 drivers/target/target_core_internal.h        |  1 +
 include/target/target_core_base.h            |  4 +++
 4 files changed, 75 insertions(+)
drivers/target/target_core_configfs.c +0 -0
index ff82b21f..3eb2566 100644

drivers/target/target_core_configfs.c line 67

Quoted 5 lines
drivers/target/target_core_configfs.c +2 -0
@@ -63,6 +63,9 @@
 	pr_debug("Setup generic %s\n", __stringify(_name));		\
 }
 
+static struct kobject *tcm_core_kobj;
+static struct kobject *tcm_core_sessions_kobj;

Static kobjects for multiple devices?

drivers/target/target_core_configfs.c static struct config_group *target_core_register_fabric( · line 254

Quoted 12 lines
drivers/target/target_core_configfs.c +5 -0
+
 extern struct t10_alua_lu_gp *default_lu_gp;
 
 static LIST_HEAD(g_tf_list);
@@ -245,6 +248,11 @@ static struct config_group *target_core_register_fabric(
 	}
 	pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
 			" %s\n", tf->tf_ops->fabric_name);
+
+	tf->kobj = kobject_create_and_add(name, tcm_core_kobj);
+	if (!tf->kobj)
+		goto dec_tf;

You just created a kobject here that did not send any information to userspace :(

What are you using this kobject for?

Quoted 26 lines
drivers/target/target_core_configfs.c +8 -0
+
 	/*
 	 * On a successful target_core_get_fabric() look, the returned
 	 * struct target_fabric_configfs *tf will contain a usage reference.
@@ -261,6 +269,10 @@ static struct config_group *target_core_register_fabric(
 	pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric: %s\n",
 		 config_item_name(&tf->tf_group.cg_item));
 	return &tf->tf_group;
+
+dec_tf:
+	atomic_dec(&tf->tf_access_cnt);
+	return ERR_PTR(-EINVAL);
 }
 
 /*
@@ -283,6 +295,9 @@ static void target_core_deregister_fabric(
 	pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
 			" %s\n", config_item_name(item));
 
+	kobject_del(tf->kobj);
+	kobject_put(tf->kobj);
+
 	configfs_remove_default_groups(&tf->tf_group);
 	config_item_put(item);
 }

drivers/target/target_core_configfs.c static int __init target_core_init_configfs(void) · line 3558

Quoted 6 lines
drivers/target/target_core_configfs.c +3 -0
@@ -3538,6 +3553,15 @@ static int __init target_core_init_configfs(void)
 
 	target_init_dbroot();
 
+	tcm_core_kobj = kobject_create_and_add("scsi_target", NULL);
+	if (!tcm_core_kobj)
+		goto out;

A brand new sysfs root directory? No, please do not do that at all. Why can't you use your driver's directory? Or your bus's directory, what is wrong with that?

drivers/target/target_core_configfs.c static int __init target_core_init_configfs(void) · line 3561

Quoted 3 lines
drivers/target/target_core_configfs.c +3 -0
+
+	tcm_core_sessions_kobj = kobject_create_and_add("sessions",
+							tcm_core_kobj);

And a subdir under that for no reason as well? Again, no, please do not do that.

For this reason alone I do not like this patch, no new root directories in sysfs please unless you can really justify it. A "mere" driver subsystem does not pass that test at all, sorry.

thanks,

greg k-h

#31 lore raw
Quoted 53 lines · Greg Kroah-Hartman
Quoted 44 lines · Mike Christie

These next two patches add a sysfs interface that reports the target layer's I_T nexuses/sessions. For the non-SCSI people cc'd, this just means we are reporting a server's connections to remote clients.

This patch adds the upper level dirs which shows/organizes our local port (tpgts below) and the connection (session below). The next patch will then add the dirs/files for each connection/session which exports info like ACL/permissions and SCSI port values.

Here is the general layout:

[sys]# tree scsi_target/
scsi_target/

|-- fabric/target module
|   `-- target name
|       `-- tpgt_$target_port_group_number
|           `-- sessions
|               `-- initiator name - session ID number
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id

Here is an example with the scsi target layer's iSCSI driver:

scsi_target/

|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
|-- fc
|-- loopback
|-- qla2xxx_tcm

Note/Question for Greg:

Quoted 7 lines

We are not exporting info in the upper level dirs like "fabric/target module", "target name", tpgt, etc and just need those dirs to be able to organize/view the endpoints of the session. So, in this patch I made a new top level dir scsi_target and made the other dirs with kobject_create_and_add. It looks like we could also add device structs in the target related structs, use classes, and build the tree/hierarchy that way too. It was not clear to me when to use one or the other.

Quoted 8 lines

Never use kobject calls in a driver subsystem like you have here, as those objects will not be seen by userspace tools that get uevents. Just use real 'struct devices' if you really really need a deep directory tree.

But I would push back here, why do you feel you want such a deep tree? What are you getting from this? Why do you need that "sessions" directory at all?

I do not need the sessions under the tpgt dir and will drop it. The target subsystem does not have a bus or use device structs at all right now. And, I saw how other code that does not have a bus like btrfs/ext4 use kobject_create_and_add() to group/organize objects and went wild with dirs :)

And, I can move the code to device structs, but had a question about the deep tree question.

A common operation will be that userspace knows the names of the objects above the session in the tree already. Apps then want to read in a specific session or scan the specific sessions in a target or a tpgt. The deep tree makes it easy to build the sysfs path and scan/read the specific object/objects.

I wanted to avoid the issue where apps have with the flat layout where they have to scan every session when they just want something specific.

Will a deep tree be ok for this type of reason?

#9 lore raw

Re: [PATCH 03/15] target: add helper to parse acl and transport name

In reply to Mike Christie
Quoted 67 lines · Mike Christie

The drivers that emulate the initiator port id (loop, scsi vhost, xen scsiback) do almost the extact same parsing when making their I_T_nexus. This adds a helper that parses out the acl name and port name from the user buffer, so these types of drivers drop prefixes like "naa." when they need to for the SCSI SPC4 TransportID SAS address, but then keep it for the LIO ACL name.

The next patches will then convert those drivers.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>
---
  drivers/target/target_core_fabric_lib.c | 73 +++++++++++++++++++++++++++++++++
  include/target/target_core_fabric.h     |  2 +
  2 files changed, 75 insertions(+)
drivers/target/target_core_fabric_lib.c +40 -0
index e89b3d8..81ed7d5 100644
@@ -423,6 +423,79 @@ const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
  	return buf + offset;
  }
 
+/**
+ * target_parse_emulated_name - parse TransportID and acl name from user buffer
+ * @proto_id: SCSI protocol identifier
+ * @user_buf: buffer with emualted name to extract acl and TransportID from
+ * @acl_name: buffer to store se_node_acl name in
+ * @max_name_len: len of acl_name buffer
+ * @tpt_id_name: Pointer to the TransportID name will be stored here.
+ */
+int target_parse_emulated_name(u8 proto_id, const char *user_buf,
+			       unsigned char *acl_name, int max_name_len,
+			       unsigned char **tpt_id_name)
+{
+	int user_len = strlen(user_buf);
+	char *proto_prefix, *name_start;
+
+	if (user_len >= max_name_len) {
+		pr_err("Emulated name: %s, exceeds max: %d\n", user_buf,
+		       max_name_len);
+		return -EINVAL;
+	}
+
+	switch (proto_id) {
+	case SCSI_PROTOCOL_SAS:
+		proto_prefix = "naa.";
+		break;
+	case SCSI_PROTOCOL_FCP:
+		proto_prefix = "fc.";
+		break;
+	case SCSI_PROTOCOL_ISCSI:
+		proto_prefix = "iqn.";
+		break;
+	default:
+		pr_err("Unsupported proto_id: 0x%02x\n", proto_id);
+		return -EINVAL;
+	}
+
+	name_start = strstr(user_buf, proto_prefix);
+	if (!name_start) {
+		pr_err("Invalid emulated name %s. Must start with %s\n",
+		       user_buf, proto_prefix);

drivers/target/target_core_fabric_lib.c const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, · line 475

Quoted 10 lines
drivers/target/target_core_fabric_lib.c +10 -0
+		return -EINVAL;
+	}
+
+	switch (proto_id) {
+	case SCSI_PROTOCOL_SAS:
+		sprintf(acl_name, name_start);
+		break;
+	case SCSI_PROTOCOL_FCP:
+		sprintf(acl_name, &name_start[3]); /* Skip over "fc." */
+		break;

Would it make sense to check acl_name for SAS and FCP according to the assumptions made in (sas|fc)_get_pr_transport_id() how the string should look like?

- SAS: 8 hex digits
- FC: 8 pairs of 2 hex digits separated by 7 colons

For compatibility reasons 16 hex digits could be allowed alternatively for FC, if fc_get_pr_transport_id() is enhanced accordingly.

Quoted 40 lines
drivers/target/target_core_fabric_lib.c +23 -0
+	case SCSI_PROTOCOL_ISCSI:
+		sprintf(acl_name, name_start);
+		break;
+	}
+
+	if (acl_name[user_len - 1] = '\n')
+		acl_name[user_len - 1] = '\0';
+
+	if (proto_id = SCSI_PROTOCOL_SAS) {
+		/*
+		 * target_setup_session will want the naa. prefix to match
+		 * the ACL name, but the t10 transport id only wants the
+		 * address.
+		 */
+		*tpt_id_name = acl_name + 4;
+	} else {
+		*tpt_id_name = acl_name;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(target_parse_emulated_name);
+
  struct t10_transport_id *target_create_transport_id(u8 proto, const char *name,
  						    const char *session_id)
  {
include/target/target_core_fabric.h +2 -0
index af1dd81..0113e1c 100644
@@ -125,6 +125,8 @@ struct target_core_fabric_ops {
  int target_depend_item(struct config_item *item);
  void target_undepend_item(struct config_item *item);
 
+int target_parse_emulated_name(u8, const char *, unsigned char *, int,
+			       unsigned char **);
  struct t10_transport_id *target_create_transport_id(u8, const char *,
  						    const char *);
  void target_free_transport_id(struct t10_transport_id *);
#34 lore raw

Re: [PATCH 12/15] target: add sysfs session helper functions

In reply to Mike Christie
Quoted 3 lines · Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2 files/dirs initially.

...

Quoted 28 lines
drivers/target/target_core_sysfs.c new file +28 -0
+
+int target_sysfs_add_session(struct se_portal_group *se_tpg,
+			     struct se_session *se_sess)
+{
+	int ret;
+
+	/*
+	 * Copy ACL name so we don't have to worry about mixing configfs
+	 * and sysfs refcounts.
+	 */
+	if (!se_sess->se_node_acl->dynamic_node_acl) {
+		se_sess->acl_name = kstrdup(se_sess->se_node_acl->initiatorname,
+					    GFP_KERNEL);
+		if (!se_sess->acl_name)
+			return -ENOMEM;
+	}
+
+	ret = kobject_add(&se_sess->kobj, se_tpg->sessions_kobj, "%s-%d",
+			  se_sess->tpt_id->name, se_sess->sid);
+	if (ret) {
+		pr_err("Could not add session%d to sysfs. Error %d.\n",
+		       se_sess->sid, ret);
+		goto free_acl_name;
+	}
+
+	ret = add_transport_id_attrs(se_sess);
+	if (ret)
+		goto del_kobj;

drivers/target/target_core_sysfs.c line 200

Quoted 10 lines
drivers/target/target_core_sysfs.c new file +10 -0
+
+	if (se_sess->tfo->session_attrs) {
+		ret = sysfs_create_group(&se_sess->kobj,
+					 se_sess->tfo->session_attrs);
+		if (ret)
+			goto rm_tpt_id_grps;
+	}
+
+	ret = sysfs_create_link(tcm_core_sessions_kobj, &se_sess->kobj,
+				se_sess->kobj.name);

I would prefer to have links named "session-%d" or "%d" only, of course with se_sess->sid as the value for '%d'.

If userspace knows the session-id only, such names make it easier to find the corresponding link.

Quoted 159 lines
drivers/target/target_core_sysfs.c new file +33 -0
+	if (ret)
+		goto rm_fabric_grps;
+
+	se_sess->sysfs_added = true;
+	return 0;
+
+rm_fabric_grps:
+	if (se_sess->tfo->session_attrs)
+		sysfs_remove_group(&se_sess->kobj, se_sess->tfo->session_attrs);
+rm_tpt_id_grps:
+	remove_transport_id_attrs(se_sess);
+del_kobj:
+	kobject_del(&se_sess->kobj);
+free_acl_name:
+	kfree(se_sess->acl_name);
+	se_sess->acl_name = NULL;
+	return ret;
+}
+EXPORT_SYMBOL(target_sysfs_add_session);
+
+void target_sysfs_remove_session(struct se_session *se_sess)
+{
+	/* discovery sessions are normally not added to sysfs */
+	if (!se_sess->sysfs_added)
+		return;
+
+	sysfs_remove_link(tcm_core_sessions_kobj, se_sess->kobj.name);
+	if (se_sess->tfo->session_attrs)
+		sysfs_remove_group(&se_sess->kobj, se_sess->tfo->session_attrs);
+	remove_transport_id_attrs(se_sess);
+	kobject_del(&se_sess->kobj);
+}
+EXPORT_SYMBOL(target_sysfs_remove_session);
drivers/target/target_core_transport.c +29 -6
index fdf84db..04cb042 100644
@@ -42,6 +42,7 @@
 
  static struct workqueue_struct *target_completion_wq;
  static struct kmem_cache *se_sess_cache;
+static DEFINE_IDA(se_sess_ida);
  struct kmem_cache *se_ua_cache;
  struct kmem_cache *t10_pr_reg_cache;
  struct kmem_cache *t10_alua_lu_gp_cache;
@@ -251,14 +252,27 @@ struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops)
  				" se_sess_cache\n");
  		return ERR_PTR(-ENOMEM);
  	}
-	ret = transport_init_session(se_sess);
+
+	ret = ida_simple_get(&se_sess_ida, 1, 0, GFP_KERNEL);
  	if (ret < 0) {
-		kmem_cache_free(se_sess_cache, se_sess);
-		return ERR_PTR(ret);
+		pr_err("Unable to allocate session index.\n");
+		goto free_sess;
  	}
-	se_sess->sup_prot_ops = sup_prot_ops;
+	se_sess->sid = ret;
+
+	ret = transport_init_session(se_sess);
+	if (ret < 0)
+		goto free_sid;
 
+	se_sess->sup_prot_ops = sup_prot_ops;
+	target_sysfs_init_session(se_sess);
  	return se_sess;
+
+free_sid:
+	ida_simple_remove(&se_sess_ida, se_sess->sid);
+free_sess:
+	kmem_cache_free(se_sess_cache, se_sess);
+	return ERR_PTR(ret);
  }
  EXPORT_SYMBOL(transport_alloc_session);
 
@@ -597,12 +611,21 @@ void transport_free_session(struct se_session *se_sess)
  		sbitmap_queue_free(&se_sess->sess_tag_pool);
  		kvfree(se_sess->sess_cmd_map);
  	}
-	target_free_transport_id(se_sess->tpt_id);
  	percpu_ref_exit(&se_sess->cmd_count);
-	kmem_cache_free(se_sess_cache, se_sess);
+	kobject_put(&se_sess->kobj);
  }
  EXPORT_SYMBOL(transport_free_session);
 
+void __target_free_session(struct se_session *se_sess)
+{
+	kfree(se_sess->acl_name);
+	target_free_transport_id(se_sess->tpt_id);
+
+	ida_simple_remove(&se_sess_ida, se_sess->sid);
+
+	kmem_cache_free(se_sess_cache, se_sess);
+}
+
  static int target_release_res(struct se_device *dev, void *data)
  {
  	struct se_session *sess = data;
include/target/target_core_base.h +6 -0
index b7f7e02..34d89cb 100644
@@ -9,6 +9,7 @@
  #include <linux/semaphore.h>     /* struct semaphore */
  #include <linux/completion.h>
  #include <linux/kobject.h>
+#include <linux/idr.h>
 
  #define TARGET_CORE_VERSION		"v5.0"
 
@@ -626,6 +627,7 @@ struct se_session {
  	enum target_prot_op	sup_prot_ops;
  	enum target_prot_type	sess_prot_type;
  	struct se_node_acl	*se_node_acl;
+	char			*acl_name;
  	struct se_portal_group *se_tpg;
  	void			*fabric_sess_ptr;
  	struct percpu_ref	cmd_count;
@@ -636,6 +638,10 @@ struct se_session {
  	wait_queue_head_t	cmd_list_wq;
  	void			*sess_cmd_map;
  	struct sbitmap_queue	sess_tag_pool;
+	struct kobject		kobj;
+	int			sid;
+	bool			sysfs_added;
+	const struct target_core_fabric_ops *tfo;
  };
 
  struct se_device;
include/target/target_core_fabric.h +7 -1
index ced377f..f876a05 100644
@@ -74,6 +74,10 @@ struct target_core_fabric_ops {
  	int (*queue_status)(struct se_cmd *);
  	void (*queue_tm_rsp)(struct se_cmd *);
  	void (*aborted_task)(struct se_cmd *);
+
+	/* Optional session management and sysfs callouts */
+	const struct attribute_group *session_attrs;
+
  	/*
  	 * fabric module calls for target_core_fabric_configfs.c
  	 */
@@ -145,7 +149,9 @@ 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 *);
-
+void	target_sysfs_remove_session(struct se_session *se_sess);
+int	target_sysfs_add_session(struct se_portal_group *se_tpg,
+				 struct se_session *se_sess);
 
  void	transport_init_se_cmd(struct se_cmd *,
  		const struct target_core_fabric_ops *,
maintainer
#35 lore raw

Re: [PATCH 12/15] target: add sysfs session helper functions

Quoted 40 lines · Bodo Stroesser
Quoted 3 lines · Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2 files/dirs initially.

...

Quoted 33 lines
drivers/target/target_core_sysfs.c new file +33 -0
+
+int target_sysfs_add_session(struct se_portal_group *se_tpg,
+                 struct se_session *se_sess)
+{
+    int ret;
+
+    /*
+     * Copy ACL name so we don't have to worry about mixing configfs
+     * and sysfs refcounts.
+     */
+    if (!se_sess->se_node_acl->dynamic_node_acl) {
+        se_sess->acl_name = kstrdup(se_sess->se_node_acl->initiatorname,
+                        GFP_KERNEL);
+        if (!se_sess->acl_name)
+            return -ENOMEM;
+    }
+
+    ret = kobject_add(&se_sess->kobj, se_tpg->sessions_kobj, "%s-%d",
+              se_sess->tpt_id->name, se_sess->sid);
+    if (ret) {
+        pr_err("Could not add session%d to sysfs. Error %d.\n",
+               se_sess->sid, ret);
+        goto free_acl_name;
+    }
+
+    ret = add_transport_id_attrs(se_sess);
+    if (ret)
+        goto del_kobj;
+
+    if (se_sess->tfo->session_attrs) {
+        ret = sysfs_create_group(&se_sess->kobj,
+                     se_sess->tfo->session_attrs);
+        if (ret)
Quoted 8 lines
Quoted 5 lines

+            goto rm_tpt_id_grps;
+    }
+
+    ret = sysfs_create_link(tcm_core_sessions_kobj, &se_sess->kobj, +                se_sess->kobj.name);

I would prefer to have links named "session-%d" or "%d" only, of course with se_sess->sid as the value for '%d'.

Isn't se_sess->sid a property that is filled in by the iSCSI target driver only? Is se_sess->sid zero for all other target drivers than the iSCSI target driver?

Quoted 2 lines

If userspace knows the session-id only, such names make it easier to find the corresponding link.

Personally I prefer the %s-%d naming scheme. I think that naming scheme has the following advantages:
1. No need to run cat ... to retrieve the initiator name.
2. It becomes possible to derive from the 'ls' output which initiators created multiple sessions.
3. All sessions created by the same initiator appear consecutively.

Thanks,

Bart.

#36 lore raw

Re: [PATCH 12/15] target: add sysfs session helper functions

Quoted 41 lines · Bart Van Assche
Quoted 40 lines · Bodo Stroesser
Quoted 3 lines · Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2 files/dirs initially.

...

Quoted 33 lines
drivers/target/target_core_sysfs.c new file +33 -0
+
+int target_sysfs_add_session(struct se_portal_group *se_tpg,
+                 struct se_session *se_sess)
+{
+    int ret;
+
+    /*
+     * Copy ACL name so we don't have to worry about mixing configfs
+     * and sysfs refcounts.
+     */
+    if (!se_sess->se_node_acl->dynamic_node_acl) {
+        se_sess->acl_name = kstrdup(se_sess->se_node_acl->initiatorname,
+                        GFP_KERNEL);
+        if (!se_sess->acl_name)
+            return -ENOMEM;
+    }
+
+    ret = kobject_add(&se_sess->kobj, se_tpg->sessions_kobj, "%s-%d",
+              se_sess->tpt_id->name, se_sess->sid);
+    if (ret) {
+        pr_err("Could not add session%d to sysfs. Error %d.\n",
+               se_sess->sid, ret);
+        goto free_acl_name;
+    }
+
+    ret = add_transport_id_attrs(se_sess);
+    if (ret)
+        goto del_kobj;
+
+    if (se_sess->tfo->session_attrs) {
+        ret = sysfs_create_group(&se_sess->kobj,
+                     se_sess->tfo->session_attrs);
+        if (ret)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

+            goto rm_tpt_id_grps;
+    }
+
+    ret = sysfs_create_link(tcm_core_sessions_kobj, &se_sess->kobj, +                se_sess->kobj.name);

I would prefer to have links named "session-%d" or "%d" only, of course with se_sess->sid as the value for '%d'.

Yeah for the part of your comment that got chopped I can see your point. For the dynamic acl case (userspace did not create an ACL so the kernel made a tmp one), then doing session-$id will be easier for userspace to lookup a specific session since it does not know the initiator name and only knows the session id.

Quoted 4 lines

Isn't se_sess->sid a property that is filled in by the iSCSI target driver only? Is se_sess->sid zero for all other target drivers than the iSCSI target driver?

No, in this patch in transport_alloc_session() I added a common sid allocator so all sessions have a unique id across all targets.

Quoted 11 lines
Quoted 3 lines

If userspace knows the session-id only, such names make it easier to find the corresponding link.

Personally I prefer the %s-%d naming scheme. I think that naming scheme has the following advantages:
1. No need to run cat ... to retrieve the initiator name.
2. It becomes possible to derive from the 'ls' output which initiators created multiple sessions.
3. All sessions created by the same initiator appear consecutively.

Ccing Hannes, because he was also saying that we should use generic names like target-%X, session-$d, etc. If we change all the code to use generic names for the target/fabric/tpgt/session, then examples like #2 or similar ones like using tree to see the topology from a SCSI'ish view would not work.

In the end, we have this issue with SCSI on the initiator side, and it's a pain, but not a show stopper.

#10 lore raw

Re: [PATCH 03/15] target: add helper to parse acl and transport name

In reply to Bodo Stroesser
Quoted 91 lines · Bodo Stroesser
Quoted 75 lines · Mike Christie

The drivers that emulate the initiator port id (loop, scsi vhost, xen scsiback)
do almost the extact same parsing when making their I_T_nexus. This adds a
helper that parses out the acl name and port name from the user buffer, so
these types of drivers drop prefixes like "naa." when they need to for the
SCSI SPC4 TransportID SAS address, but then keep it for the LIO ACL name.

The next patches will then convert those drivers.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>

---
  drivers/target/target_core_fabric_lib.c | 73
+++++++++++++++++++++++++++++++++
  include/target/target_core_fabric.h     |  2 +

  2 files changed, 75 insertions(+)
drivers/target/target_core_fabric_lib.c +0 -0
index e89b3d8..81ed7d5 100644
@@ -423,6 +423,79 @@ const char
 *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
       return buf + offset;
   }

  +/**
+ * target_parse_emulated_name - parse TransportID and acl name from user buffer
+ * @proto_id: SCSI protocol identifier
+ * @user_buf: buffer with emualted name to extract acl and TransportID from
+ * @acl_name: buffer to store se_node_acl name in
+ * @max_name_len: len of acl_name buffer
+ * @tpt_id_name: Pointer to the TransportID name will be stored here.
+ */

drivers/target/target_core_fabric_lib.c +32 -0
+int target_parse_emulated_name(u8 proto_id, const char *user_buf,
+                   unsigned char *acl_name, int max_name_len,
+                   unsigned char **tpt_id_name)
+{
+    int user_len = strlen(user_buf);
+    char *proto_prefix, *name_start;
+
+    if (user_len >= max_name_len) {
+        pr_err("Emulated name: %s, exceeds max: %d\n", user_buf,
+               max_name_len);
+        return -EINVAL;
+    }
+
+    switch (proto_id) {
+    case SCSI_PROTOCOL_SAS:
+        proto_prefix = "naa.";
+        break;
+    case SCSI_PROTOCOL_FCP:
+        proto_prefix = "fc.";
+        break;
+    case SCSI_PROTOCOL_ISCSI:
+        proto_prefix = "iqn.";
+        break;
+    default:
+        pr_err("Unsupported proto_id: 0x%02x\n", proto_id);
+        return -EINVAL;
+    }
+
+    name_start = strstr(user_buf, proto_prefix);
+    if (!name_start) {
+        pr_err("Invalid emulated name %s. Must start with %s\n",
+               user_buf, proto_prefix);

drivers/target/target_core_fabric_lib.c const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, · line 475

Quoted 10 lines
drivers/target/target_core_fabric_lib.c +10 -0
+        return -EINVAL;
+    }
+
+    switch (proto_id) {
+    case SCSI_PROTOCOL_SAS:
+        sprintf(acl_name, name_start);
+        break;
+    case SCSI_PROTOCOL_FCP:
+        sprintf(acl_name, &name_start[3]); /* Skip over "fc." */
+        break;

Would it make sense to check acl_name for SAS and FCP according to the assumptions made in (sas|fc)_get_pr_transport_id() how the string should look like?

Quoted 5 lines

- SAS: 8 hex digits
- FC: 8 pairs of 2 hex digits separated by 7 colons

For compatibility reasons 16 hex digits could be allowed alternatively for FC, if fc_get_pr_transport_id() is enhanced accordingly

In general I would say yes.

One hiccup I hit is that other than checking the prefix we have not been validating names. So we could have existing setups with completely bogus names like "naa.iworkbutamwrong", and if the user has never done workloads that use PRs then it has worked fine.

If we start to validate the name here, how do we handle a failure? I took the easy route and kept the existing behavior. For new functionality like if a userspace daemon detects the bad value in sysfs then I think it can decide to report a failover for that new functionality and we would be ok.

In the long run though code path wise, I am going to replace the nacl use in the PR code with the transport ID, so we won't have multiple places doing stuff like
"/* Skip over 'naa. prefix */"
.
I am trying to do that work in the PR related patchset and keep this focused on the sysfs part.

#32 lore raw
In reply to Mike Christie
Quoted 59 lines · Mike Christie
Quoted 58 lines · Greg Kroah-Hartman
Quoted 44 lines · Mike Christie

These next two patches add a sysfs interface that reports the target layer's I_T nexuses/sessions. For the non-SCSI people cc'd, this just means we are reporting a server's connections to remote clients.

This patch adds the upper level dirs which shows/organizes our local port (tpgts below) and the connection (session below). The next patch will then add the dirs/files for each connection/session which exports info like ACL/permissions and SCSI port values.

Here is the general layout:

[sys]# tree scsi_target/
scsi_target/

|-- fabric/target module
|   `-- target name
|       `-- tpgt_$target_port_group_number
|           `-- sessions
|               `-- initiator name - session ID number
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id

Here is an example with the scsi target layer's iSCSI driver:

scsi_target/

|-- iscsi
|   `-- iqn.1999-09.com.tcmu:minna
|       `-- tpgt_1
|           `-- sessions
|               `-- iqn.2005-03.com.ceph:ini1-1
|                   |-- acl
|                   `-- transport_id
|                       |-- name
|                       |-- proto
|                       `-- session_id
|-- fc
|-- loopback
|-- qla2xxx_tcm

Note/Question for Greg:

Quoted 7 lines

We are not exporting info in the upper level dirs like "fabric/target module", "target name", tpgt, etc and just need those dirs to be able to organize/view the endpoints of the session. So, in this patch I made a new top level dir scsi_target and made the other dirs with kobject_create_and_add. It looks like we could also add device structs in the target related structs, use classes, and build the tree/hierarchy that way too. It was not clear to me when to use one or the other.

Never use kobject calls in a driver subsystem like you have here, as those objects will not be seen by userspace tools that get uevents. Just use real 'struct devices' if you really really need a deep directory tree.

Quoted 7 lines
Quoted 3 lines

But I would push back here, why do you feel you want such a deep tree? What are you getting from this? Why do you need that "sessions" directory at all?

I do not need the sessions under the tpgt dir and will drop it. The target subsystem does not have a bus or use device structs at all right now.

Then fix that and everything shows up automatically "for free".

Quoted 3 lines

And, I saw how other code that does not have a bus like btrfs/ext4 use kobject_create_and_add() to group/organize objects and went wild with dirs :)

file systems are not devices with busses and drivers :)

Quoted 2 lines

And, I can move the code to device structs, but had a question about the deep tree question.

Don't do it.

Quoted 5 lines

A common operation will be that userspace knows the names of the objects above the session in the tree already. Apps then want to read in a specific session or scan the specific sessions in a target or a tpgt. The deep tree makes it easy to build the sysfs path and scan/read the specific object/objects.

Again, a "deep tree" with raw kobjects will be invisible to the normal userspace tools that monitor changes in sysfs for devices because they will not notice them at all.

Quoted 2 lines

I wanted to avoid the issue where apps have with the flat layout where they have to scan every session when they just want something specific.

There should not be any difference in "speed" for something like that, it's an in-ram filesystem with no i/o times.

Quoted 1 line

Will a deep tree be ok for this type of reason?

Nope :(

greg k-h

#37 lore raw

Re: [PATCH 12/15] target: add sysfs session helper functions

In reply to Mike Christie
Quoted 51 lines · Mike Christie
Quoted 41 lines · Bart Van Assche
Quoted 40 lines · Bodo Stroesser
Quoted 3 lines · Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2 files/dirs initially.

...

Quoted 33 lines
drivers/target/target_core_sysfs.c new file +33 -0
+
+int target_sysfs_add_session(struct se_portal_group *se_tpg,
+                 struct se_session *se_sess)
+{
+    int ret;
+
+    /*
+     * Copy ACL name so we don't have to worry about mixing configfs
+     * and sysfs refcounts.
+     */
+    if (!se_sess->se_node_acl->dynamic_node_acl) {
+        se_sess->acl_name = kstrdup(se_sess->se_node_acl->initiatorname,
+                        GFP_KERNEL);
+        if (!se_sess->acl_name)
+            return -ENOMEM;
+    }
+
+    ret = kobject_add(&se_sess->kobj, se_tpg->sessions_kobj, "%s-%d",
+              se_sess->tpt_id->name, se_sess->sid);
+    if (ret) {
+        pr_err("Could not add session%d to sysfs. Error %d.\n",
+               se_sess->sid, ret);
+        goto free_acl_name;
+    }
+
+    ret = add_transport_id_attrs(se_sess);
+    if (ret)
+        goto del_kobj;
+
+    if (se_sess->tfo->session_attrs) {
+        ret = sysfs_create_group(&se_sess->kobj,
+                     se_sess->tfo->session_attrs);
+        if (ret)
Quoted 8 lines
Quoted 8 lines

drivers/target/target_core_sysfs.c line 200

Quoted 5 lines
drivers/target/target_core_sysfs.c new file +5 -0
+            goto rm_tpt_id_grps;
+    }
+
+    ret = sysfs_create_link(tcm_core_sessions_kobj, &se_sess->kobj,
+                se_sess->kobj.name);

I would prefer to have links named "session-%d" or "%d" only, of course with se_sess->sid as the value for '%d'.

Quoted 5 lines

Yeah for the part of your comment that got chopped I can see your point. For the dynamic acl case (userspace did not create an ACL so the kernel made a tmp one), then doing session-$id will be easier for userspace to lookup a specific session since it does not know the initiator name and only knows the session id.

Yes, I meant, that "session-%d" or even "%d" only would be fine for the links in scsi_target/sessions. When looking for a session if session-id is known only, then this is easy to use.

Regarding the session folders in the tpgt_X folder, I think the "%s-%d" format with acl or initiator name followed by the session-id would be fine for both cases, with acl and with dynamic acl. Again the above links can be used for dynamic acl lookup.

Quoted 30 lines
Quoted 5 lines

Isn't se_sess->sid a property that is filled in by the iSCSI target driver only? Is se_sess->sid zero for all other target drivers than the iSCSI target driver?

No, in this patch in transport_alloc_session() I added a common sid allocator so all sessions have a unique id across all targets.

Quoted 11 lines
Quoted 3 lines

If userspace knows the session-id only, such names make it easier to find the corresponding link.

Personally I prefer the %s-%d naming scheme. I think that naming scheme has the following advantages:
1. No need to run cat ... to retrieve the initiator name.
2. It becomes possible to derive from the 'ls' output which initiators created multiple sessions.
3. All sessions created by the same initiator appear consecutively.

Ccing Hannes, because he was also saying that we should use generic names like target-%X, session-$d, etc. If we change all the code to use generic names for the target/fabric/tpgt/session, then examples like #2 or similar ones like using tree to see the topology from a SCSI'ish view would not work.

In the end, we have this issue with SCSI on the initiator side, and it's a pain, but not a show stopper.

#38 lore raw

Re: [PATCH 12/15] target: add sysfs session helper functions

Quoted 59 lines · Bodo Stroesser
Quoted 52 lines · Mike Christie
Quoted 42 lines · Bart Van Assche
Quoted 41 lines · Bodo Stroesser
Quoted 4 lines · Mike Christie

This patch adds helpers to add/remove a dir per session. There is only 2
files/dirs initially.

...

Quoted 33 lines
drivers/target/target_core_sysfs.c new file +33 -0
+
+int target_sysfs_add_session(struct se_portal_group *se_tpg,
+                 struct se_session *se_sess)
+{
+    int ret;
+
+    /*
+     * Copy ACL name so we don't have to worry about mixing configfs
+     * and sysfs refcounts.
+     */
+    if (!se_sess->se_node_acl->dynamic_node_acl) {
+        se_sess->acl_name >>>>> kstrdup(se_sess->se_node_acl->initiatorname,
+                        GFP_KERNEL);
+        if (!se_sess->acl_name)
+            return -ENOMEM;
+    }
+
+    ret = kobject_add(&se_sess->kobj, se_tpg->sessions_kobj, "%s-%d",
+              se_sess->tpt_id->name, se_sess->sid);
+    if (ret) {
+        pr_err("Could not add session%d to sysfs. Error %d.\n",
+               se_sess->sid, ret);
+        goto free_acl_name;
+    }
+
+    ret = add_transport_id_attrs(se_sess);
+    if (ret)
+        goto del_kobj;
+
+    if (se_sess->tfo->session_attrs) {
+        ret = sysfs_create_group(&se_sess->kobj,
+                     se_sess->tfo->session_attrs);
+        if (ret)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

+            goto rm_tpt_id_grps;
+    }
+
+    ret = sysfs_create_link(tcm_core_sessions_kobj, &se_sess->kobj, +                se_sess->kobj.name);

I would prefer to have links named "session-%d" or "%d" only, of course with se_sess->sid as the value for '%d'.

Quoted 5 lines

Yeah for the part of your comment that got chopped I can see your point. For the dynamic acl case (userspace did not create an ACL so the kernel made a tmp one), then doing session-$id will be easier for userspace to lookup a specific session since it does not know the initiator name and only knows the session id.

Quoted 9 lines

Yes, I meant, that "session-%d" or even "%d" only would be fine for the links in scsi_target/sessions. When looking for a session if session-id is known only, then this is easy to use.

Regarding the session folders in the tpgt_X folder, I think the "%s-%d" format with acl or initiator name followed by the session-id would be fine for both cases, with acl and with dynamic acl. Again the above links can be used for dynamic acl lookup.

I don't think that's possible.

To handle Greg's comment we will use device structs instead of kobjects directly. It's going to end up looking like drivers/scsi_transport_iscsi.c where that initiator side session has a device struct in it. You have a scsi_target_session class and device structs show up in /sys/class/scsi_target_session. In this case, you do not have control over the symlink name from /sys/class/scsi_target_session to /sys/devices/. The dir name and symlink name are going to be the device structs name.

Reviewed-by on v5 1/15
#3 lore raw

Re: [PATCH 01/15] target: check enforce_pr_isids during registration

In reply to Mike Christie
Quoted 51 lines · Mike Christie

Move the check for enforce_pr_isids to the registration code where we can fail at the time an initiator tries to register a path without an isid. In its current place in __core_scsi3_locate_pr_reg, it is too late because it can be registered and be reported in PR in commands and it is stuck in this state because we cannot unregister it.

Note.
I am including in this patchset, because the 5th patch is built on top.

---
 drivers/target/target_core_pr.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/target/target_core_pr.c +8 -9
index 5e93169..cd2d32f 100644
@@ -1176,15 +1176,6 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg(
 		 * ISID, then we have found a match.
 		 */
 		if (!pr_reg->isid_present_at_reg) {
-			/*
-			 * Determine if this SCSI device server requires that
-			 * SCSI Intiatior TransportID w/ ISIDs is enforced
-			 * for fabric modules (iSCSI) requiring them.
-			 */
-			if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
-				if (dev->dev_attrib.enforce_pr_isids)
-					continue;
-			}
 			atomic_inc_mb(&pr_reg->pr_res_holders);
 			spin_unlock(&pr_tmpl->registration_lock);
 			return pr_reg;
@@ -1591,10 +1582,25 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
 				continue;
 			dest_rtpi = tmp_lun->lun_rtpi;
 
+			iport_ptr = NULL;
 			i_str = target_parse_pr_out_transport_id(tmp_tpg,
 					ptr, &tid_len, &iport_ptr);
 			if (!i_str)
 				continue;
+			/*
+			 * Determine if this SCSI device server requires that
+			 * SCSI Intiatior TransportID w/ ISIDs is enforced
+			 * for fabric modules (iSCSI) requiring them.
+			 */
+			if (tpg->se_tpg_tfo->sess_get_initiator_sid &&
+                            dev->dev_attrib.enforce_pr_isids &&

drivers/target/target_core_pr.c static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) · line 1606

Quoted 10 lines
drivers/target/target_core_pr.c +7 -0
+			    !iport_ptr) {
+				pr_warn("SPC-PR: enforce_pr_isids is set but a isid has not been sent in the SPEC_I_PT data for %s.",
+					i_str);
+				ret = TCM_INVALID_PARAMETER_LIST;
+				spin_unlock(&dev->se_port_lock);
+				goto out_unmap;
+			}
 
 			atomic_inc_mb(&tmp_tpg->tpg_pr_ref_count);
 			spin_unlock(&dev->se_port_lock);
Reviewed-by on v5 2/15
#6 lore raw

Re: [PATCH 02/15] target: separate acl name from port ids

In reply to Mike Christie
Quoted 33 lines · Mike Christie

The PGR code assumes the ACL name is going to be based on the SPC4 transportID type of values. The problem is that for iSCSI we have an extra session id as part of the SCSI port id and some fabric modules support or would like to support non transportID values for the ACL name. For example, iSCSI and SRP would like to use the source address for the ACL name, but that is not a valud transportID value that you can get in a PGR request.

This patch adds a new transport_id struct which maps to the SPC4 transportID. In the future it will be used for PGR commands instead of the ACL name. In this patchset it is used to export the initiator info in the session's sysfs dir, so tools can display the info and daemons that execute commands like PGRs in userspace can build a session id to I_T nexus mapping.

In this patch only srp is passing in different values for the transport id and acl name. The next patches will convert loop, scsi vhost and xen scsiback that are more complex due to their initiator name emulation.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>

---

V4:
- Don't drop const char use. We still have target_setup_session allocate the transport_id struct, but because every uses format=0 we just need to pass in the transport_id's name.

V3:
- drop format

Quoted 15 lines
 drivers/infiniband/ulp/srpt/ib_srpt.c    | 10 +++++---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c |  4 +--
 drivers/scsi/qla2xxx/tcm_qla2xxx.c       |  2 +-
 drivers/target/loopback/tcm_loop.c       |  3 ++-
 drivers/target/sbp/sbp_target.c          |  2 +-
 drivers/target/target_core_fabric_lib.c  | 41 +++++++++++++++++++++++++++++++
 drivers/target/target_core_transport.c   | 42 ++++++++++++++++++++++++--------
 drivers/target/tcm_fc/tfc_sess.c         |  3 ++-
 drivers/usb/gadget/function/f_tcm.c      |  3 ++-
 drivers/vhost/scsi.c                     |  1 +
 drivers/xen/xen-scsiback.c               |  3 ++-
 include/target/target_core_base.h        | 12 +++++++++
 include/target/target_core_fabric.h      |  5 +++-
 13 files changed, 108 insertions(+), 23 deletions(-)
Reviewed-by on v5 3/15
#11 lore raw

Re: [PATCH 03/15] target: add helper to parse acl and transport name

In reply to Mike Christie
Quoted 19 lines · Mike Christie

The drivers that emulate the initiator port id (loop, scsi vhost, xen scsiback) do almost the extact same parsing when making their I_T_nexus. This adds a helper that parses out the acl name and port name from the user buffer, so these types of drivers drop prefixes like "naa." when they need to for the SCSI SPC4 TransportID SAS address, but then keep it for the LIO ACL name.

The next patches will then convert those drivers.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Juergen Gross <[email protected]>
---
 drivers/target/target_core_fabric_lib.c | 73 +++++++++++++++++++++++++++++++++
 include/target/target_core_fabric.h     |  2 +
 2 files changed, 75 insertions(+)

...

Reviewed-by on v5 4/15
#14 lore raw

Re: [PATCH 04/15] tcm loop: use target_parse_emulated_name

In reply to Mike Christie
Quoted 105 lines · Mike Christie

Use target_parse_emulated_name so the acl and SCSI names are properly formatted.

---
 drivers/target/loopback/tcm_loop.c | 65 ++++++--------------------------------
 1 file changed, 10 insertions(+), 55 deletions(-)
drivers/target/loopback/tcm_loop.c +5 -54
index 74aded7..64e5f1f 100644
@@ -725,7 +725,8 @@ static int tcm_loop_alloc_sess_cb(struct se_portal_group *se_tpg,
 
 static int tcm_loop_make_nexus(
 	struct tcm_loop_tpg *tl_tpg,
-	const char *name)
+	const char *tpt_id_name,
+	const char *acl_name)
 {
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
 	struct tcm_loop_nexus *tl_nexus;
@@ -742,7 +743,7 @@ static int tcm_loop_make_nexus(
 
 	tl_nexus->se_sess = target_setup_session(&tl_tpg->tl_se_tpg, 0, 0,
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
-					name, name, tl_nexus,
+					tpt_id_name, acl_name, tl_nexus,
 					tcm_loop_alloc_sess_cb);
 	if (IS_ERR(tl_nexus->se_sess)) {
 		ret = PTR_ERR(tl_nexus->se_sess);
@@ -751,7 +752,7 @@ static int tcm_loop_make_nexus(
 	}
 
 	pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated %s Initiator Port: %s\n",
-		 tcm_loop_dump_proto_id(tl_hba), name);
+		 tcm_loop_dump_proto_id(tl_hba), acl_name);
 	return 0;
 }
 
@@ -814,7 +815,7 @@ static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
 	struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
 			struct tcm_loop_tpg, tl_se_tpg);
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
-	unsigned char i_port[TL_WWN_ADDR_LEN], *ptr, *port_ptr;
+	unsigned char i_port[TL_WWN_ADDR_LEN], *tpt_id_name;
 	int ret;
 	/*
 	 * Shutdown the active I_T nexus if 'NULL' is passed..
@@ -823,59 +824,13 @@ static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
 		ret = tcm_loop_drop_nexus(tl_tpg);
 		return (!ret) ? count : ret;
 	}
-	/*
-	 * Otherwise make sure the passed virtual Initiator port WWN matches
-	 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
-	 * tcm_loop_make_nexus()
-	 */
-	if (strlen(page) >= TL_WWN_ADDR_LEN) {
-		pr_err("Emulated NAA Sas Address: %s, exceeds max: %d\n",
-		       page, TL_WWN_ADDR_LEN);
-		return -EINVAL;
-	}
-	snprintf(&i_port[0], TL_WWN_ADDR_LEN, "%s", page);
 
-	ptr = strstr(i_port, "naa.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_SAS) {
-			pr_err("Passed SAS Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "fc.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_FCP) {
-			pr_err("Passed FCP Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[3]; /* Skip over "fc." */
-		goto check_newline;
-	}
-	ptr = strstr(i_port, "iqn.");
-	if (ptr) {
-		if (tl_hba->tl_proto_id != SCSI_PROTOCOL_ISCSI) {
-			pr_err("Passed iSCSI Initiator Port %s does not match target port protoid: %s\n",
-			       i_port, tcm_loop_dump_proto_id(tl_hba));
-			return -EINVAL;
-		}
-		port_ptr = &i_port[0];
-		goto check_newline;
-	}
-	pr_err("Unable to locate prefix for emulated Initiator Port: %s\n",
-	       i_port);
-	return -EINVAL;
-	/*
-	 * Clear any trailing newline for the NAA WWN
-	 */
-check_newline:
-	if (i_port[strlen(i_port)-1] = '\n')
-		i_port[strlen(i_port)-1] = '\0';

drivers/target/loopback/tcm_loop.c static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item, · line 836

Quoted 10 lines
drivers/target/loopback/tcm_loop.c +5 -1
+	ret = target_parse_emulated_name(tl_hba->tl_proto_id, page, i_port,
+					 TL_WWN_ADDR_LEN, &tpt_id_name);
+	if (ret)
+		return ret;
 
-	ret = tcm_loop_make_nexus(tl_tpg, port_ptr);
+	ret = tcm_loop_make_nexus(tl_tpg, tpt_id_name, i_port);
 	if (ret < 0)
 		return ret;