Skip to contentSkip to conversation

target: 64-bit LUN support

PATCH In review Hannes Reinecke 4 participants 7 messages Jun 10, 2015 – Jun 11, 2015

Subsystems (4)
lore
Share & tools
lore
#1 lore raw

PATCH 1/2 target: use 64-bit LUNs

In reply to Hannes Reinecke

As we're now using a list to hold the LUNs the target core can now converted to use 64-bit LUNs internally.

---
 drivers/target/iscsi/iscsi_target_tmr.c      |  4 +--
 drivers/target/loopback/tcm_loop.c           |  4 +--
 drivers/target/target_core_alua.c            |  2 +-
 drivers/target/target_core_configfs.c        | 12 ++++----
 drivers/target/target_core_device.c          | 30 +++++++++----------
 drivers/target/target_core_fabric_configfs.c | 18 ++++--------
 drivers/target/target_core_internal.h        | 10 +++----
 drivers/target/target_core_pr.c              | 43 ++++++++++++++--------------
 drivers/target/target_core_pr.h              |  6 ++--
 drivers/target/target_core_tpg.c             |  6 ++--
 drivers/target/target_core_transport.c       |  6 ++--
 drivers/target/target_core_ua.c              |  8 +++---
 drivers/target/target_core_ua.h              |  2 +-
 include/target/target_core_base.h            | 19 ++++++------
 include/target/target_core_fabric.h          | 10 +++----
 15 files changed, 88 insertions(+), 92 deletions(-)
drivers/target/iscsi/iscsi_target_tmr.c +2 -2
index b0224a7..5159882 100644
@@ -120,7 +120,7 @@ u8 iscsit_tmr_task_reassign(
 	struct iscsi_tmr_req *tmr_req = cmd->tmr_req;
 	struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req;
 	struct iscsi_tm *hdr = (struct iscsi_tm *) buf;
-	int ret, ref_lun;
+	u64 ret, ref_lun;
 
 	pr_debug("Got TASK_REASSIGN TMR ITT: 0x%08x,"
 		" RefTaskTag: 0x%08x, ExpDataSN: 0x%08x, CID: %hu\n",
@@ -164,7 +164,7 @@ u8 iscsit_tmr_task_reassign(
 	ref_lun = scsilun_to_int(&hdr->lun);
 	if (ref_lun != ref_cmd->se_cmd.orig_fe_lun) {
 		pr_err("Unable to perform connection recovery for"
-			" differing ref_lun: %d ref_cmd orig_fe_lun: %u\n",
+			" differing ref_lun: %llu ref_cmd orig_fe_lun: %llu\n",
 			ref_lun, ref_cmd->se_cmd.orig_fe_lun);
 		return ISCSI_TMF_RSP_REJECTED;
 	}
drivers/target/loopback/tcm_loop.c +2 -2
index 562906a..a7bb0b0 100644
@@ -215,7 +215,7 @@ static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
  * to struct scsi_device
  */
 static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg,
-			      int lun, int task, enum tcm_tmreq_table tmr)
+			      u64 lun, int task, enum tcm_tmreq_table tmr)
 {
 	struct se_cmd *se_cmd = NULL;
 	struct se_session *se_sess;
@@ -747,7 +747,7 @@ static void tcm_loop_port_unlink(
 				se_lun->unpacked_lun);
 	if (!sd) {
 		pr_err("Unable to locate struct scsi_device for %d:%d:"
-			"%d\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
+			"%llu\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun);
 		return;
 	}
 	/*
drivers/target/target_core_alua.c +1 -1
index 02d8e1a..2318e6e 100644
@@ -1257,7 +1257,7 @@ static int core_alua_update_tpg_secondary_metadata(struct se_lun *lun)
 			atomic_read(&lun->lun_tg_pt_secondary_offline),
 			lun->lun_tg_pt_secondary_stat);
 
-	snprintf(path, ALUA_METADATA_PATH_LEN, "/var/target/alua/%s/%s/lun_%u",
+	snprintf(path, ALUA_METADATA_PATH_LEN, "/var/target/alua/%s/%s/lun_%llu",
 			se_tpg->se_tpg_tfo->get_fabric_name(), wwn,
 			lun->unpacked_lun);
 
drivers/target/target_core_configfs.c +6 -6
index f97b969..68addbc 100644
@@ -1438,7 +1438,7 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
 		tfo->tpg_get_wwn(se_tpg));
 	len += sprintf(page+len, "SPC-3 Reservation: Relative Port"
 		" Identifier Tag: %hu %s Portal Group Tag: %hu"
-		" %s Logical Unit: %u\n", pr_reg->tg_pt_sep_rtpi,
+		" %s Logical Unit: %llu\n", pr_reg->tg_pt_sep_rtpi,
 		tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg),
 		tfo->get_fabric_name(), pr_reg->pr_aptpl_target_lun);
 
@@ -1565,12 +1565,12 @@ static match_table_t tokens = {
 	{Opt_res_type, "res_type=%d"},
 	{Opt_res_scope, "res_scope=%d"},
 	{Opt_res_all_tg_pt, "res_all_tg_pt=%d"},
-	{Opt_mapped_lun, "mapped_lun=%d"},
+	{Opt_mapped_lun, "mapped_lun=%lld"},
 	{Opt_target_fabric, "target_fabric=%s"},
 	{Opt_target_node, "target_node=%s"},
 	{Opt_tpgt, "tpgt=%d"},
 	{Opt_port_rtpi, "port_rtpi=%d"},
-	{Opt_target_lun, "target_lun=%d"},
+	{Opt_target_lun, "target_lun=%lld"},
 	{Opt_err, NULL}
 };
 
@@ -1585,7 +1585,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 	substring_t args[MAX_OPT_ARGS];
 	unsigned long long tmp_ll;
 	u64 sa_res_key = 0;
-	u32 mapped_lun = 0, target_lun = 0;
+	u64 mapped_lun = 0, target_lun = 0;
 	int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token;
 	u16 tpgt = 0;
 	u8 type = 0;
@@ -1675,7 +1675,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 			break;
 		case Opt_mapped_lun:
 			match_int(args, &arg);
-			mapped_lun = (u32)arg;
+			mapped_lun = (u64)arg;
 			break;
 		/*
 		 * PR APTPL Metadata for Target Port
@@ -1710,7 +1710,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 			break;
 		case Opt_target_lun:
 			match_int(args, &arg);
-			target_lun = (u32)arg;
+			target_lun = (u64)arg;
 			break;
 		default:
 			break;
drivers/target/target_core_device.c +15 -15
index 6941e3b..6fe4223 100644
@@ -56,7 +56,7 @@ static struct se_hba *lun0_hba;
 struct se_device *g_lun0_dev;
 
 sense_reason_t
-transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
+transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
 {
 	struct se_lun *se_lun = NULL;
 	struct se_session *se_sess = se_cmd->se_sess;
@@ -74,7 +74,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
 		if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
 		    (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) {
 			pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
-				" Access for 0x%08x\n",
+				" Access for 0x%08llx\n",
 				se_cmd->se_tfo->get_fabric_name(),
 				unpacked_lun);
 			rcu_read_unlock();
@@ -107,7 +107,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
 		 */
 		if (unpacked_lun != 0) {
 			pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
-				" Access for 0x%08x\n",
+				" Access for 0x%08llx\n",
 				se_cmd->se_tfo->get_fabric_name(),
 				unpacked_lun);
 			return TCM_NON_EXISTENT_LUN;
@@ -147,7 +147,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
 }
 EXPORT_SYMBOL(transport_lookup_cmd_lun);
 
-int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
+int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
 {
 	struct se_dev_entry *deve;
 	struct se_lun *se_lun = NULL;
@@ -172,7 +172,7 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
 
 	if (!se_lun) {
 		pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
-			" Access for 0x%08x\n",
+			" Access for 0x%08llx\n",
 			se_cmd->se_tfo->get_fabric_name(),
 			unpacked_lun);
 		return -ENODEV;
@@ -260,7 +260,7 @@ void core_free_device_list_for_node(
 }
 
 void core_update_device_list_access(
-	u32 mapped_lun,
+	u64 mapped_lun,
 	u32 lun_access,
 	struct se_node_acl *nacl)
 {
@@ -283,7 +283,7 @@ void core_update_device_list_access(
 /*
  * Called with rcu_read_lock or nacl->device_list_lock held.
  */
-struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *nacl, u32 mapped_lun)
+struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *nacl, u64 mapped_lun)
 {
 	struct se_dev_entry *deve;
 
@@ -309,7 +309,7 @@ void target_pr_kref_release(struct kref *kref)
 int core_enable_device_list_for_node(
 	struct se_lun *lun,
 	struct se_lun_acl *lun_acl,
-	u32 mapped_lun,
+	u64 mapped_lun,
 	u32 lun_access,
 	struct se_node_acl *nacl,
 	struct se_portal_group *tpg)
@@ -550,7 +550,7 @@ int core_dev_add_lun(
 	if (rc < 0)
 		return rc;
 
-	pr_debug("%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from"
+	pr_debug("%s_TPG[%u]_LUN[%llu] - Activated %s Logical Unit from"
 		" CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
 		tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
 		tpg->se_tpg_tfo->get_fabric_name(), dev->se_hba->hba_id);
@@ -583,7 +583,7 @@ void core_dev_del_lun(
 	struct se_portal_group *tpg,
 	struct se_lun *lun)
 {
-	pr_debug("%s_TPG[%u]_LUN[%u] - Deactivating %s Logical Unit from"
+	pr_debug("%s_TPG[%u]_LUN[%llu] - Deactivating %s Logical Unit from"
 		" device object\n", tpg->se_tpg_tfo->get_fabric_name(),
 		tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
 		tpg->se_tpg_tfo->get_fabric_name());
@@ -594,7 +594,7 @@ void core_dev_del_lun(
 struct se_lun_acl *core_dev_init_initiator_node_lun_acl(
 	struct se_portal_group *tpg,
 	struct se_node_acl *nacl,
-	u32 mapped_lun,
+	u64 mapped_lun,
 	int *ret)
 {
 	struct se_lun_acl *lacl;
@@ -646,7 +646,7 @@ int core_dev_add_initiator_node_lun_acl(
 			lun_access, nacl, tpg) < 0)
 		return -EINVAL;
 
-	pr_debug("%s_TPG[%hu]_LUN[%u->%u] - Added %s ACL for "
+	pr_debug("%s_TPG[%hu]_LUN[%llu->%llu] - Added %s ACL for "
 		" InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
 		tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, lacl->mapped_lun,
 		(lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO",
@@ -678,8 +678,8 @@ int core_dev_del_initiator_node_lun_acl(
 		core_disable_device_list_for_node(lun, deve, nacl, tpg);
 	mutex_unlock(&nacl->lun_entry_mutex);
 
-	pr_debug("%s_TPG[%hu]_LUN[%u] - Removed ACL for"
-		" InitiatorNode: %s Mapped LUN: %u\n",
+	pr_debug("%s_TPG[%hu]_LUN[%llu] - Removed ACL for"
+		" InitiatorNode: %s Mapped LUN: %llu\n",
 		tpg->se_tpg_tfo->get_fabric_name(),
 		tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
 		lacl->initiatorname, lacl->mapped_lun);
@@ -692,7 +692,7 @@ void core_dev_free_initiator_node_lun_acl(
 	struct se_lun_acl *lacl)
 {
 	pr_debug("%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s"
-		" Mapped LUN: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
+		" Mapped LUN: %llu\n", tpg->se_tpg_tfo->get_fabric_name(),
 		tpg->se_tpg_tfo->tpg_get_tag(tpg),
 		tpg->se_tpg_tfo->get_fabric_name(),
 		lacl->initiatorname, lacl->mapped_lun);
drivers/target/target_core_fabric_configfs.c +6 -12
index 0ee182f..2fd493e 100644
@@ -202,7 +202,7 @@ static ssize_t target_fabric_mappedlun_store_write_protect(
 			lacl->se_lun_nacl);
 
 	pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
-		" Mapped LUN: %u Write Protect bit to %s\n",
+		" Mapped LUN: %llu Write Protect bit to %s\n",
 		se_tpg->se_tpg_tfo->get_fabric_name(),
 		lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF");
 
@@ -322,7 +322,7 @@ static struct config_group *target_fabric_make_mappedlun(
 	struct config_item *acl_ci;
 	struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
 	char *buf;
-	unsigned long mapped_lun;
+	unsigned long long mapped_lun;
 	int ret = 0;
 
 	acl_ci = &group->cg_item;
@@ -350,15 +350,11 @@ static struct config_group *target_fabric_make_mappedlun(
 	 * Determine the Mapped LUN value.  This is what the SCSI Initiator
 	 * Port will actually see.
 	 */
-	ret = kstrtoul(buf + 4, 0, &mapped_lun);
+	ret = kstrtoull(buf + 4, 0, &mapped_lun);
 	if (ret)
 		goto out;
-	if (mapped_lun > UINT_MAX) {
-		ret = -EINVAL;
-		goto out;
-	}
 	if (mapped_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
-		pr_err("Mapped LUN: %lu exceeds TRANSPORT_MAX_LUNS_PER_TPG"
+		pr_err("Mapped LUN: %llu exceeds TRANSPORT_MAX_LUNS_PER_TPG"
 			"-1: %u for Target Portal Group: %u\n", mapped_lun,
 			TRANSPORT_MAX_LUNS_PER_TPG-1,
 			se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg));
@@ -881,7 +877,7 @@ static struct config_group *target_fabric_make_lun(
 			struct se_portal_group, tpg_lun_group);
 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
 	struct config_group *lun_cg = NULL, *port_stat_grp = NULL;
-	unsigned long unpacked_lun;
+	unsigned long long unpacked_lun;
 	int errno;
 
 	if (strstr(name, "lun_") != name) {
@@ -889,11 +885,9 @@ static struct config_group *target_fabric_make_lun(
 				" \"lun_$LUN_NUMBER\"\n");
 		return ERR_PTR(-EINVAL);
 	}
-	errno = kstrtoul(name + 4, 0, &unpacked_lun);
+	errno = kstrtoull(name + 4, 0, &unpacked_lun);
 	if (errno)
 		return ERR_PTR(errno);
-	if (unpacked_lun > UINT_MAX)
-		return ERR_PTR(-EINVAL);
 
 	lun = core_tpg_alloc_lun(se_tpg, unpacked_lun);
 	if (IS_ERR(lun))
drivers/target/target_core_internal.h +5 -5
index 8d8737a..5111789 100644
@@ -26,10 +26,10 @@ struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16);
 void	target_pr_kref_release(struct kref *);
 void	core_free_device_list_for_node(struct se_node_acl *,
 		struct se_portal_group *);
-void	core_update_device_list_access(u32, u32, struct se_node_acl *);
-struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u32);
+void	core_update_device_list_access(u64, u32, struct se_node_acl *);
+struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u64);
 int	core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
-		u32, u32, struct se_node_acl *, struct se_portal_group *);
+		u64, u32, struct se_node_acl *, struct se_portal_group *);
 void	core_disable_device_list_for_node(struct se_lun *, struct se_dev_entry *,
 		struct se_node_acl *, struct se_portal_group *);
 void	core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *);
@@ -37,7 +37,7 @@ int	core_dev_add_lun(struct se_portal_group *, struct se_device *,
 		struct se_lun *lun);
 void	core_dev_del_lun(struct se_portal_group *, struct se_lun *);
 struct se_lun_acl *core_dev_init_initiator_node_lun_acl(struct se_portal_group *,
-		struct se_node_acl *, u32, int *);
+		struct se_node_acl *, u64, int *);
 int	core_dev_add_initiator_node_lun_acl(struct se_portal_group *,
 		struct se_lun_acl *, struct se_lun *lun, u32);
 int	core_dev_del_initiator_node_lun_acl(struct se_lun *,
@@ -80,7 +80,7 @@ struct se_node_acl *__core_tpg_get_initiator_node_acl(struct se_portal_group *tp
 void	core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *,
 				  struct se_lun *);
 void	core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *);
-struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u32);
+struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64);
 int	core_tpg_add_lun(struct se_portal_group *, struct se_lun *,
 		u32, struct se_device *);
 void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
drivers/target/target_core_pr.c +22 -21

150 lines not on this page · raw message

drivers/target/target_core_pr.h +3 -3
index 749fd7b..e3d26e9 100644
@@ -56,11 +56,11 @@ extern sense_reason_t target_scsi2_reservation_release(struct se_cmd *);
 extern sense_reason_t target_scsi2_reservation_reserve(struct se_cmd *);
 extern int core_scsi3_alloc_aptpl_registration(
 			struct t10_reservation *, u64,
-			unsigned char *, unsigned char *, u32,
-			unsigned char *, u16, u32, int, int, u8);
+			unsigned char *, unsigned char *, u64,
+			unsigned char *, u16, u64, int, int, u8);
 extern int core_scsi3_check_aptpl_registration(struct se_device *,
 			struct se_portal_group *, struct se_lun *,
-			struct se_node_acl *, u32);
+			struct se_node_acl *, u64);
 extern void core_scsi3_free_pr_reg_from_nacl(struct se_device *,
 					     struct se_node_acl *);
 extern void core_scsi3_free_all_registrations(struct se_device *);
drivers/target/target_core_tpg.c +3 -3
index 2e77eeb..82ed8a0 100644
@@ -122,7 +122,7 @@ void core_tpg_add_node_to_devs(
 				lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
 		}
 
-		pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%u] - Adding %s"
+		pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%llu] - Adding %s"
 			" access for LUN in Demo Mode\n",
 			tpg->se_tpg_tfo->get_fabric_name(),
 			tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
@@ -598,12 +598,12 @@ EXPORT_SYMBOL(core_tpg_deregister);
 
 struct se_lun *core_tpg_alloc_lun(
 	struct se_portal_group *tpg,
-	u32 unpacked_lun)
+	u64 unpacked_lun)
 {
 	struct se_lun *lun;
 
 	if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
-		pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG"
+		pr_err("%s LUN: %llu exceeds TRANSPORT_MAX_LUNS_PER_TPG"
 			"-1: %u for Target Portal Group: %u\n",
 			tpg->se_tpg_tfo->get_fabric_name(),
 			unpacked_lun, TRANSPORT_MAX_LUNS_PER_TPG-1,
drivers/target/target_core_transport.c +3 -3
index f2640ec..3da2386 100644
@@ -1389,7 +1389,7 @@ transport_generic_map_mem_to_cmd(struct se_cmd *cmd, struct scatterlist *sgl,
  * assumes internal allocation of fabric payload buffer by target-core.
  */
 int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess,
-		unsigned char *cdb, unsigned char *sense, u32 unpacked_lun,
+		unsigned char *cdb, unsigned char *sense, u64 unpacked_lun,
 		u32 data_length, int task_attr, int data_dir, int flags,
 		struct scatterlist *sgl, u32 sgl_count,
 		struct scatterlist *sgl_bidi, u32 sgl_bidi_count,
@@ -1525,7 +1525,7 @@ EXPORT_SYMBOL(target_submit_cmd_map_sgls);
  * It also assumes interal target core SGL memory allocation.
  */
 int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess,
-		unsigned char *cdb, unsigned char *sense, u32 unpacked_lun,
+		unsigned char *cdb, unsigned char *sense, u64 unpacked_lun,
 		u32 data_length, int task_attr, int data_dir, int flags)
 {
 	return target_submit_cmd_map_sgls(se_cmd, se_sess, cdb, sense,
@@ -1562,7 +1562,7 @@ static void target_complete_tmr_failure(struct work_struct *work)
  **/
 
 int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
-		unsigned char *sense, u32 unpacked_lun,
+		unsigned char *sense, u64 unpacked_lun,
 		void *fabric_tmr_ptr, unsigned char tm_type,
 		gfp_t gfp, unsigned int tag, int flags)
 {
drivers/target/target_core_ua.c +4 -4
index 6c9616d..e53d4ee 100644
@@ -88,7 +88,7 @@ target_scsi3_ua_check(struct se_cmd *cmd)
 
 int core_scsi3_ua_allocate(
 	struct se_node_acl *nacl,
-	u32 unpacked_lun,
+	u64 unpacked_lun,
 	u8 asc,
 	u8 ascq)
 {
@@ -177,7 +177,7 @@ int core_scsi3_ua_allocate(
 	list_add_tail(&ua->ua_nacl_list, &deve->ua_list);
 	spin_unlock(&deve->ua_lock);
 
-	pr_debug("[%s]: Allocated UNIT ATTENTION, mapped LUN: %u, ASC:"
+	pr_debug("[%s]: Allocated UNIT ATTENTION, mapped LUN: %llu, ASC:"
 		" 0x%02x, ASCQ: 0x%02x\n",
 		nacl->se_tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun,
 		asc, ascq);
@@ -267,7 +267,7 @@ void core_scsi3_ua_for_check_condition(
 	rcu_read_unlock();
 
 	pr_debug("[%s]: %s UNIT ATTENTION condition with"
-		" INTLCK_CTRL: %d, mapped LUN: %u, got CDB: 0x%02x"
+		" INTLCK_CTRL: %d, mapped LUN: %llu, got CDB: 0x%02x"
 		" reported ASC: 0x%02x, ASCQ: 0x%02x\n",
 		nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
 		(dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" :
@@ -329,7 +329,7 @@ int core_scsi3_ua_clear_for_request_sense(
 	rcu_read_unlock();
 
 	pr_debug("[%s]: Released UNIT ATTENTION condition, mapped"
-		" LUN: %u, got REQUEST_SENSE reported ASC: 0x%02x,"
+		" LUN: %llu, got REQUEST_SENSE reported ASC: 0x%02x,"
 		" ASCQ: 0x%02x\n", nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
 		cmd->orig_fe_lun, *asc, *ascq);
 
drivers/target/target_core_ua.h +1 -1
index a6b56b3..6e592b1 100644
@@ -28,7 +28,7 @@
 extern struct kmem_cache *se_ua_cache;
 
 extern sense_reason_t target_scsi3_ua_check(struct se_cmd *);
-extern int core_scsi3_ua_allocate(struct se_node_acl *, u32, u8, u8);
+extern int core_scsi3_ua_allocate(struct se_node_acl *, u64, u8, u8);
 extern void core_scsi3_ua_release_all(struct se_dev_entry *);
 extern void core_scsi3_ua_for_check_condition(struct se_cmd *, u8 *, u8 *);
 extern int core_scsi3_ua_clear_for_request_sense(struct se_cmd *,
include/target/target_core_base.h +10 -9
index 8855249..64de2bd 100644
@@ -356,8 +356,8 @@ struct t10_pr_registration {
 	int pr_res_scope;
 	/* Used for fabric initiator WWPNs using a ISID */
 	bool isid_present_at_reg;
-	u32 pr_res_mapped_lun;
-	u32 pr_aptpl_target_lun;
+	u64 pr_res_mapped_lun;
+	u64 pr_aptpl_target_lun;
 	u16 tg_pt_sep_rtpi;
 	u32 pr_res_generation;
 	u64 pr_reg_bin_isid;
@@ -477,7 +477,7 @@ struct se_cmd {
 	/* Total size in bytes associated with command */
 	u32			data_length;
 	u32			residual_count;
-	u32			orig_fe_lun;
+	u64			orig_fe_lun;
 	/* Persistent Reservation key */
 	u64			pr_res_key;
 	/* Used for sense data */
@@ -615,7 +615,7 @@ struct se_ml_stat_grps {
 
 struct se_lun_acl {
 	char			initiatorname[TRANSPORT_IQN_LEN];
-	u32			mapped_lun;
+	u64			mapped_lun;
 	struct se_node_acl	*se_lun_nacl;
 	struct se_lun		*se_lun;
 	struct config_group	se_lun_group;
@@ -624,10 +624,10 @@ struct se_lun_acl {
 
 struct se_dev_entry {
 	/* See transport_lunflags_table */
-	u32			lun_flags;
-	u32			mapped_lun;
+	u64			mapped_lun;
 	u64			pr_res_key;
 	u64			creation_time;
+	u32			lun_flags;
 	u32			attach_count;
 	atomic_long_t		total_cmds;
 	atomic_long_t		read_bytes;
@@ -697,14 +697,15 @@ struct scsi_port_stats {
 };
 
 struct se_lun {
-	/* RELATIVE TARGET PORT IDENTIFER */
-	u16			lun_rtpi;
+	u64			unpacked_lun;
 #define SE_LUN_LINK_MAGIC			0xffff7771
 	u32			lun_link_magic;
 	u32			lun_access;
 	u32			lun_flags;
-	u32			unpacked_lun;
 	u32			lun_index;
+
+	/* RELATIVE TARGET PORT IDENTIFER */
+	u16			lun_rtpi;
 	atomic_t		lun_acl_count;
 	struct se_device __rcu	*lun_se_dev;
 
include/target/target_core_fabric.h +5 -5
index 72c4a12..3beb8d5 100644
@@ -117,16 +117,16 @@ void	transport_deregister_session(struct se_session *);
 void	transport_init_se_cmd(struct se_cmd *,
 		const struct target_core_fabric_ops *,
 		struct se_session *, u32, int, int, unsigned char *);
-sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32);
+sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64);
 sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
 int	target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
-		unsigned char *, unsigned char *, u32, u32, int, int, int,
+		unsigned char *, unsigned char *, u64, u32, int, int, int,
 		struct scatterlist *, u32, struct scatterlist *, u32,
 		struct scatterlist *, u32);
 int	target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *,
-		unsigned char *, u32, u32, int, int, int);
+		unsigned char *, u64, u32, int, int, int);
 int	target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
-		unsigned char *sense, u32 unpacked_lun,
+		unsigned char *sense, u64 unpacked_lun,
 		void *fabric_tmr_ptr, unsigned char tm_type,
 		gfp_t, unsigned int, int);
 int	transport_handle_cdb_direct(struct se_cmd *);
@@ -152,7 +152,7 @@ void	core_tmr_release_req(struct se_tmr_req *);
 int	transport_generic_handle_tmr(struct se_cmd *);
 void	transport_generic_request_failure(struct se_cmd *, sense_reason_t);
 void	__target_execute_cmd(struct se_cmd *);
-int	transport_lookup_tmr_lun(struct se_cmd *, u32);
+int	transport_lookup_tmr_lun(struct se_cmd *, u64);
 
 struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
 		unsigned char *);
Signature · 1 line
1.8.5.2
#0 lore raw

cover target: 64-bit LUN support

Hi Nic,

here's now the patchset for making LIO-target support 64-bit LUNs. Pretty straightforward, plus an additional patch to remove the now obsolete limitation on 256 LUNs per TPG. There had been a comment in the header that REPORT LUN emulation would only support up to one page in payload, but I couldn't find any evidence for this in the code.

As usual, comments and reviews are welcome.

Patchset is relative to the 'for-next' branch of target-pending.

Hannes Reinecke (2):
target: use 64-bit LUNs
target: Remove TARGET_MAX_LUNS_PER_TRANSPORT

 drivers/target/iscsi/iscsi_target_tmr.c      |  4 +--
 drivers/target/loopback/tcm_loop.c           |  4 +--
 drivers/target/target_core_alua.c            |  2 +-
 drivers/target/target_core_configfs.c        | 12 ++++----
 drivers/target/target_core_device.c          | 39 ++++++++++---------------
 drivers/target/target_core_fabric_configfs.c | 24 ++++------------
 drivers/target/target_core_internal.h        | 10 +++----
 drivers/target/target_core_pr.c              | 43 ++++++++++++++--------------
 drivers/target/target_core_pr.h              |  6 ++--
 drivers/target/target_core_tpg.c             | 13 ++-------
 drivers/target/target_core_transport.c       |  6 ++--
 drivers/target/target_core_ua.c              |  8 +++---
 drivers/target/target_core_ua.h              |  2 +-
 drivers/xen/xen-scsiback.c                   |  7 +++--
 include/target/target_core_base.h            | 22 +++++++-------
 include/target/target_core_fabric.h          | 10 +++----
 16 files changed, 90 insertions(+), 122 deletions(-)
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH 2/2 target: Remove TARGET_MAX_LUNS_PER_TRANSPORT

LUN allocation is now fully dynamic, so there is no need to artificially restrain the number of exported LUNs.

---
 drivers/target/target_core_device.c          | 9 ---------
 drivers/target/target_core_fabric_configfs.c | 8 --------
 drivers/target/target_core_tpg.c             | 9 ---------
 drivers/xen/xen-scsiback.c                   | 7 ++++---
 include/target/target_core_base.h            | 3 ---
 5 files changed, 4 insertions(+), 32 deletions(-)
drivers/target/target_core_device.c +0 -9
index 6fe4223..650613e 100644
@@ -63,9 +63,6 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
 	struct se_node_acl *nacl = se_sess->se_node_acl;
 	struct se_dev_entry *deve;
 
-	if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG)
-		return TCM_NON_EXISTENT_LUN;
-
 	rcu_read_lock();
 	deve = target_nacl_find_deve(nacl, unpacked_lun);
 	if (deve) {
@@ -156,9 +153,6 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
 	struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
 	unsigned long flags;
 
-	if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG)
-		return -ENODEV;
-
 	rcu_read_lock();
 	deve = target_nacl_find_deve(nacl, unpacked_lun);
 	if (deve) {
@@ -197,9 +191,6 @@ bool target_lun_is_rdonly(struct se_cmd *cmd)
 	struct se_dev_entry *deve;
 	bool ret;
 
-	if (cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY)
-		return true;
-
 	rcu_read_lock();
 	deve = target_nacl_find_deve(se_sess->se_node_acl, cmd->orig_fe_lun);
 	ret = (deve && deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY);
drivers/target/target_core_fabric_configfs.c +0 -8
index 2fd493e..6cfee59 100644
@@ -353,14 +353,6 @@ static struct config_group *target_fabric_make_mappedlun(
 	ret = kstrtoull(buf + 4, 0, &mapped_lun);
 	if (ret)
 		goto out;
-	if (mapped_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
-		pr_err("Mapped LUN: %llu exceeds TRANSPORT_MAX_LUNS_PER_TPG"
-			"-1: %u for Target Portal Group: %u\n", mapped_lun,
-			TRANSPORT_MAX_LUNS_PER_TPG-1,
-			se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg));
-		ret = -EINVAL;
-		goto out;
-	}
 
 	lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl,
 			mapped_lun, &ret);
drivers/target/target_core_tpg.c +0 -9
index 82ed8a0..aa39bc8 100644
@@ -602,15 +602,6 @@ struct se_lun *core_tpg_alloc_lun(
 {
 	struct se_lun *lun;
 
-	if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
-		pr_err("%s LUN: %llu exceeds TRANSPORT_MAX_LUNS_PER_TPG"
-			"-1: %u for Target Portal Group: %u\n",
-			tpg->se_tpg_tfo->get_fabric_name(),
-			unpacked_lun, TRANSPORT_MAX_LUNS_PER_TPG-1,
-			tpg->se_tpg_tfo->tpg_get_tag(tpg));
-		return ERR_PTR(-EOVERFLOW);
-	}
-
 	lun = kzalloc(sizeof(*lun), GFP_KERNEL);
 	if (!lun) {
 		pr_err("Unable to allocate se_lun memory\n");
drivers/xen/xen-scsiback.c +4 -3
index 25144a0..10d6780 100644
@@ -864,7 +864,7 @@ static int scsiback_add_translation_entry(struct vscsibk_info *info,
 	struct list_head *head = &(info->v2p_entry_lists);
 	unsigned long flags;
 	char *lunp;
-	unsigned int unpacked_lun;
+	unsigned long long unpacked_lun;
 	struct se_lun *se_lun;
 	struct scsiback_tpg *tpg_entry, *tpg = NULL;
 	char *error = "doesn't exist";
@@ -876,9 +876,10 @@ static int scsiback_add_translation_entry(struct vscsibk_info *info,
 	}
 	*lunp = 0;
 	lunp++;
-	if (kstrtouint(lunp, 10, &unpacked_lun) || unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) {
+	err = kstrtoull(lunp, 10, &unpacked_lun);
+	if (err < 0) {
 		pr_err("lun number not valid: %s\n", lunp);
-		return -EINVAL;
+		return err;
 	}
 
 	mutex_lock(&scsiback_mutex);
include/target/target_core_base.h +0 -3
index 64de2bd..d30271e 100644
@@ -13,9 +13,6 @@
 #define TARGET_CORE_MOD_VERSION		"v4.1.0"
 #define TARGET_CORE_VERSION		TARGET_CORE_MOD_VERSION
 
-/* Maximum Number of LUNs per Target Portal Group */
-/* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
-#define TRANSPORT_MAX_LUNS_PER_TPG		256
 /*
  * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
  *
Signature · 1 line
1.8.5.2
#3 lore raw
In reply to Hannes Reinecke

Hi Hannes,

Quoted 26 lines · Hannes Reinecke

Hi Nic,

here's now the patchset for making LIO-target support 64-bit LUNs. Pretty straightforward, plus an additional patch to remove the now obsolete limitation on 256 LUNs per TPG. There had been a comment in the header that REPORT LUN emulation would only support up to one page in payload, but I couldn't find any evidence for this in the code.

As usual, comments and reviews are welcome.

Patchset is relative to the 'for-next' branch of target-pending.

Hannes Reinecke (2):
target: use 64-bit LUNs
target: Remove TARGET_MAX_LUNS_PER_TRANSPORT

 drivers/target/iscsi/iscsi_target_tmr.c      |  4 +--
 drivers/target/loopback/tcm_loop.c           |  4 +--
 drivers/target/target_core_alua.c            |  2 +-
 drivers/target/target_core_configfs.c        | 12 ++++----
 drivers/target/target_core_device.c          | 39 ++++++++++---------------
 drivers/target/target_core_fabric_configfs.c | 24 ++++------------
 drivers/target/target_core_internal.h        | 10 +++----
 drivers/target/target_core_pr.c              | 43 ++++++++++++++--------------
 drivers/target/target_core_pr.h              |  6 ++--
Quoted 9 lines
 drivers/target/target_core_tpg.c             | 13 ++-------
 drivers/target/target_core_transport.c       |  6 ++--
 drivers/target/target_core_ua.c              |  8 +++---
 drivers/target/target_core_ua.h              |  2 +-
 drivers/xen/xen-scsiback.c                   |  7 +++--
 include/target/target_core_base.h            | 22 +++++++-------
 include/target/target_core_fabric.h          | 10 +++----
 16 files changed, 90 insertions(+), 122 deletions(-)

Looks good, applied to target-pending/for-next.

Thanks for rebasing this to the latest for-next btw, and dropping the last remaining TARGET_MAX_LUNS_PER_TRANSPORT vestiges as well. :)

--nab

#4 lore raw
In reply to Hannes Reinecke
Quoted 10 lines · Hannes Reinecke

Hi Nic,

here's now the patchset for making LIO-target support 64-bit LUNs. Pretty straightforward, plus an additional patch to remove the now obsolete limitation on 256 LUNs per TPG. There had been a comment in the header that REPORT LUN emulation would only support up to one page in payload, but I couldn't find any evidence for this in the code.

As usual, comments and reviews are welcome.

Hi Hannes,

I think we also need to take care of how we report LUNs in spc.c spc_emulate_report_luns(). From reading SAM-5 4.7.7 (addressing methods) it looks like we're currently using the simple addressing format (address method = 0) and if we want to report more than 14 bits we would need to report the luns with a different addressing format.

I'm wondering if this could be seen as a bug in int_to_scsilun, but in any case I hope you'll take a look and make sure we're ok?

Thanks -- Regards -- Andy

#5 lore raw
Quoted 21 lines · Andy Grover
Quoted 10 lines · Hannes Reinecke

Hi Nic,

here's now the patchset for making LIO-target support 64-bit LUNs. Pretty straightforward, plus an additional patch to remove the now obsolete limitation on 256 LUNs per TPG. There had been a comment in the header that REPORT LUN emulation would only support up to one page in payload, but I couldn't find any evidence for this in the code.

As usual, comments and reviews are welcome.

Hi Hannes,

I think we also need to take care of how we report LUNs in spc.c spc_emulate_report_luns(). From reading SAM-5 4.7.7 (addressing methods) it looks like we're currently using the simple addressing format (address method = 0) and if we want to report more than 14 bits we would need to report the luns with a different addressing format.

Quoted 3 lines

I'm wondering if this could be seen as a bug in int_to_scsilun, but in any case I hope you'll take a look and make sure we're ok?

Actually, I've been thinking about this. Currently I'm not sure if we should fully embrace this route; after all, 'scsilun_to_int' is meant to be a conversion from the (abstract) LUN number into our internal representation.
And as it's internal we're free to use whatever we like.

Where we need to fix up things is in reporting; whenever we display LUN numbers to userspace (printk or sysfs-wise) we probably should use the appropriate format.

I'll see if I can whip up a printk format for this. Never liked the '%llu' format for LUNs anyway.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		               zSeries & Storage
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
#6 lore raw
Quoted 6 lines · Hannes Reinecke

Actually, I've been thinking about this. Currently I'm not sure if we should fully embrace this route; after all, 'scsilun_to_int' is meant to be a conversion from the (abstract) LUN number into our internal representation.
And as it's internal we're free to use whatever we like.

Quoted 6 lines

Where we need to fix up things is in reporting; whenever we display LUN numbers to userspace (printk or sysfs-wise) we probably should use the appropriate format.

I'll see if I can whip up a printk format for this. Never liked the '%llu' format for LUNs anyway.

Hello Hannes,

Making how LUNs are displayed dependent on the LUN addressing method sounds like a good idea to me. One step further would be to ensure that the format in which LUNs are entered through configfs matches the format used to display LUNs. This may require to add an additional configuration parameter in configfs for the LUN addressing format. E.g. for users who connect an AIX initiator system to LIO it would be much more convenient to use LUN numbers like 1, 2, 3 instead of the raw LUN numbers 256, 512, 768.

Thanks,

Bart.