Skip to contentSkip to conversation

target: Updates for v3.1-rc1

PATCH In review Nicholas A. Bellinger 4 participants 38 messages Jul 21, 2011 – Jul 23, 2011

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

cover target: Updates for v3.1-rc1

From: Nicholas Bellinger <[email protected]>

Hello folks,

This is the first set of pending drivers/target/ updates for the v3.1 merge window. It contains updates for drivers/target core and loopback + tcm_fc modules and get mainline synced up with the latest lio-core-2.6.git/master v4.1.0-rc1 HEAD as requested by hch.

I'll be squashing these into a proper GIT PULL to Linus shortly, so please let me know if anything else is missing and/or needs to be addressed for the first round of v3.1 updates.

The 3.1-pending branch is available directly via git here:

git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git 3.1-pending

Thank you!

--nab

Andy Grover (66):
target: use errno values instead of returning -1 for everything
target: Rename transport_calc_sg_num to transport_init_task_sg
target: Fix leak in error path in transport_init_task_sg
target: Remove pscsi_get_sh() in _pscsi.c
target: Make two runtime checks into WARN_ONs
target: Remove hba queue depth and convert to spin_lock_irq usage
target: dev->dev_status_queue_obj is unused
target: Make struct se_queue_req.cmd type struct se_cmd *
target: Remove __transport_get_qr_from_queue()
target: Rename se_dev->g_se_dev_list to se_dev_node
target: Remove struct se_global
target: Simplify scsi mib index table code
target: Make dev_queue_obj a member of se_device instead of a pointer
target: remove extraneous returns at end of void functions
target: Ensure transport_dump_vpd_ident_type returns null-terminated
str
target: Function pointers don't need to use '&' to be assigned
target: Fix comment in __transport_execute_tasks()
target: Misc style cleanups
target: rename struct pr_reservation_template to pr_reservation
target: Remove #defines that just perform indirection
target: Inline transport_get_task_from_execute_queue()
target: Remove unneeded casts to void*
target: Rename get_lun_for_{cmd,tmr} to lookup_{cmd,tmr}_lun
target: Make t_task a member of se_cmd, not a pointer
target: Handle functions returning "-2"
target: Use cmd->se_dev over cmd->se_lun->lun_se_dev
target: Embed qr in struct se_cmd
target: Replace embedded struct se_queue_req with a list_head
target: Rename list_heads that are nodes in struct se_cmd to "*_node"
target: Fold transport_device_setup_cmd() into lookup_{tmr,cmd}_lun()
target: Make t_mem_list and t_mem_list_bidi members of t_task
target: Add comment & cleanup transport_map_sg_to_mem()
target: Remove unneeded checks in transport_free_pages()
target: Replace custom sg<->buf functions with lib funcs
target: Simplify sector limiting code
target: get_cdb should never return NULL
target: Simplify transport_memcpy_se_mem_read_contig
target: Use assignment rather than increment for t_task_cdbs
target: Don't pass dma_size to generic_get_mem
target: Pass sg with type scatterlist in transport_map_sg_to_mem
target: Move task_sg_num next to task_sg in struct se_task
target: inline struct se_transport_task into struct se_cmd
target: Change name & semantics of transport_get_sectors()
target: Remove unused members of se_cmd
target: Rename se_cmd.t_task_cdbs to t_task_list_num
target: Fix some spelling
target: Remove unused var from transport_generic_do_tmr
target: map_sg_to_mem: return sg_count in return value target/pscsi: Use min_t for sector limits
target/pscsi: Unused param for pscsi_get_bio()
target: Rename get_cdb_count to allocate_tasks
target: Remove ifdeffed code in t_g_process_write
target: Pass 2nd param of transport_split_cdb by value
target: Make all control CDBs scatter-gather
target: Enforce 1 page max for control cdb buffer sizes
target: Remove direct ramdisk code
target: Eliminate usage of struct se_mem
target: Rename task_sg_num to task_sg_nents
target: Remove custom debug macros for pr_debug. Use pr_err().
target: Remove custom debug macros in non-iscsi fabrics
target: Set WSNZ=1 in block limits VPD. Abort if WRITE_SAME sectors =

    0

target: Remove transport do_se_mem_map callback
target: Further simplify transport_free_pages
target: Redo task allocation return value handling
target: Remove extra parentheses
target: change alloc_task call to take *cdb, not *cmd

Andy Shevchenko (2):
target: fix typo Assoication -> Association
target: remove custom hex2bin() implementation

Christoph Hellwig (6):
target: remove the always-noop ->new_cmd_failure method
target: remove the unused SCF_SE_DISABLE_ONLINE_CHECK flag
target: remove the unused SCF_CMD_PASSTHROUGH_NOALLOC flag
target: remove the unused SCF_EMULATE_SYNC_UNMAP flag
target: remove the unused SCF_EMULATE_SYNC_CACHE flag
target: merge release_cmd methods

Dan Carpenter (1):
tcm_loop: off by one in tcm_loop_make_naa_tpg()

Fubo Chen (1):
target: Check LUN numbers in transport_get_lun_for_[cmd,tmr]

Jesper Juhl (2):
loopback: Remove duplicate scsi/scsi_tcq.h include
loopback: Fix memory leak in tcm_loop_make_scsi_hba()

Nicholas Bellinger (17):
target: Minor header comment fixes
target: use MAINTENANCE_IN and MAINTENANCE_OUT definitions in scsi.h
target: Remove unnecessary *cdb transport_get_lun_for_cmd parameter
target: Remove unused su_group usage in fabric register/dergister
target: Fix double test of inquiry_prod
target: Fix WRITE_SAME_16 t_task_lba assignment bug
target: Fix WRITE_SAME_[16,32] number of blocks=0 case
tcm_fc: Makefile cleanups
tcm_fc: Convert to wake_up_process and schedule_timeout_interruptible
target: Make transport_generic_new_cmd() available for iscsi-target
target: Remove fabric callback to allocate iovecs
target: Fix transport_generic_new_cmd WRITE comment
target: Add transport_handle_cdb_direct optimization
target: Add SCF_EMULATE_QUEUE_FULL -> transport_handle_queue_full target/iblock: Use request_queue->nr_request for se_device defaults
target: ->map_task_SG conversion to ->map_control_SG and

    ->map_data_SG

target: Update QUEUE ALGORITHM MODIFIER control page default

Roland Dreier (7):
target: Make transport_lookup_cmd_lun() locking IRQ-safe
target: Make se_dev_check_online() locking IRQ-safe
target: Make se_tmr_lock IRQ-safe target/iblock: Remove unused iblock_dev members
target: Allow for built-in target modules
target: Fix reporting of supported VPD pages
target: Implement Block Device Characteristics VPD page

Stefan Hajnoczi (1):
loopback: Only build tcm_loop as module

 drivers/target/loopback/Kconfig              |    9 +-
 drivers/target/loopback/tcm_loop.c           |  207 +-
 drivers/target/loopback/tcm_loop.h           |    6 -
 drivers/target/target_core_alua.c            |  426 ++--
 drivers/target/target_core_cdb.c             |  457 ++--
 drivers/target/target_core_configfs.c        |  667 +++---
 drivers/target/target_core_device.c          |  819 +++---
 drivers/target/target_core_fabric_configfs.c |  122 +-
 drivers/target/target_core_fabric_lib.c      |   27 +-
 drivers/target/target_core_file.c            |  149 +-
 drivers/target/target_core_file.h            |    4 -
 drivers/target/target_core_hba.c             |   37 +-
 drivers/target/target_core_iblock.c          |  199 +-
 drivers/target/target_core_iblock.h          |    9 -
 drivers/target/target_core_pr.c              |  862 ++++---
 drivers/target/target_core_pr.h              |    2 +-
 drivers/target/target_core_pscsi.c           |  316 +--
 drivers/target/target_core_pscsi.h           |    4 +-
 drivers/target/target_core_rd.c              |  483 +---
 drivers/target/target_core_rd.h              |    4 -
 drivers/target/target_core_scdb.c            |   20 +-
 drivers/target/target_core_scdb.h            |   10 +-
 drivers/target/target_core_stat.c            |  112 +-
 drivers/target/target_core_tmr.c             |  185 +-
 drivers/target/target_core_tpg.c             |  206 +-
 drivers/target/target_core_transport.c       | 3688 ++++++++++----------------
 drivers/target/target_core_ua.c              |   62 +-
 drivers/target/tcm_fc/Makefile               |   17 +-
 drivers/target/tcm_fc/tcm_fc.h               |   25 -
 drivers/target/tcm_fc/tfc_cmd.c              |  114 +-
 drivers/target/tcm_fc/tfc_conf.c             |   47 +-
 drivers/target/tcm_fc/tfc_io.c               |  130 +-
 drivers/target/tcm_fc/tfc_sess.c             |   18 +-
 include/target/target_core_base.h            |  226 +-
 include/target/target_core_device.h          |    6 +-
 include/target/target_core_fabric_ops.h      |    9 +-
 include/target/target_core_transport.h       |   43 +-
 37 files changed, 4089 insertions(+), 5638 deletions(-)
Signature · 1 line
1.7.6
#8 lore raw

PATCH 6/103 target: Remove unused su_group usage in fabric register/dergister

From: Nicholas Bellinger <[email protected]>

This patch removes two instances of left over v3.x code performing local scope access to struct target_core_fabric_ops->tf_subsys->su_group in target_fabric_configfs_register() and target_fabric_configfs_deregister().

---
 drivers/target/target_core_configfs.c |   15 ---------------
 1 files changed, 0 insertions(+), 15 deletions(-)
drivers/target/target_core_configfs.c +0 -15
index 25c1f49..c614000 100644
@@ -533,7 +533,6 @@ static int target_fabric_tf_ops_check(
 int target_fabric_configfs_register(
 	struct target_fabric_configfs *tf)
 {
-	struct config_group *su_group;
 	int ret;
 
 	if (!(tf)) {
@@ -546,12 +545,6 @@ int target_fabric_configfs_register(
 			" pointer\n");
 		return -EINVAL;
 	}
-	su_group = &tf->tf_subsys->su_group;
-	if (!(su_group)) {
-		printk(KERN_ERR "Unable to locate target struct config_group"
-			" pointer\n");
-		return -EINVAL;
-	}
 	ret = target_fabric_tf_ops_check(tf);
 	if (ret < 0)
 		return ret;
@@ -565,7 +558,6 @@ EXPORT_SYMBOL(target_fabric_configfs_register);
 void target_fabric_configfs_deregister(
 	struct target_fabric_configfs *tf)
 {
-	struct config_group *su_group;
 	struct configfs_subsystem *su;
 
 	if (!(tf)) {
@@ -579,13 +571,6 @@ void target_fabric_configfs_deregister(
 			" pointer\n");
 		return;
 	}
-	su_group = &tf->tf_subsys->su_group;
-	if (!(su_group)) {
-		printk(KERN_ERR "Unable to locate target struct config_group"
-			" pointer\n");
-		return;
-	}
-
 	printk(KERN_INFO "<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
 			">>>>>>>>>>>>\n");
 	mutex_lock(&g_tf_lock);
Signature · 1 line
1.7.6
#12 lore raw

PATCH 10/103 target: Remove pscsi_get_sh() in _pscsi.c

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

It only wrapped scsi_host_lookup, which can just be used directly without too much trouble.

(nab: Fix pdv_host_id usage)

---
 drivers/target/target_core_pscsi.c |   30 ++++++------------------------
 1 files changed, 6 insertions(+), 24 deletions(-)
drivers/target/target_core_pscsi.c +6 -24
index fb2e8cb..d39226f 100644
@@ -55,24 +55,6 @@ static struct se_subsystem_api pscsi_template;
 
 static void pscsi_req_done(struct request *, int);
 
-/*	pscsi_get_sh():
- *
- *
- */
-static struct Scsi_Host *pscsi_get_sh(u32 host_no)
-{
-	struct Scsi_Host *sh = NULL;
-
-	sh = scsi_host_lookup(host_no);
-	if (IS_ERR(sh)) {
-		printk(KERN_ERR "Unable to locate SCSI HBA with Host ID:"
-				" %u\n", host_no);
-		return NULL;
-	}
-
-	return sh;
-}
-
 /*	pscsi_attach_hba():
  *
  * 	pscsi_get_sh() used scsi_host_lookup() to locate struct Scsi_Host.
@@ -154,11 +136,11 @@ static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
 	 * Otherwise, locate struct Scsi_Host from the original passed
 	 * pSCSI Host ID and enable for phba mode
 	 */
-	sh = pscsi_get_sh(phv->phv_host_id);
-	if (!(sh)) {
+	sh = scsi_host_lookup(phv->phv_host_id);
+	if (IS_ERR(sh)) {
 		printk(KERN_ERR "pSCSI: Unable to locate SCSI Host for"
 			" phv_host_id: %d\n", phv->phv_host_id);
-		return -1;
+		return PTR_ERR(sh);
 	}
 	/*
 	 * Usually the SCSI LLD will use the hostt->can_queue value to define
@@ -601,11 +583,11 @@ static struct se_device *pscsi_create_virtdevice(
 			hba->hba_flags |= HBA_FLAGS_PSCSI_MODE;
 			sh = phv->phv_lld_host;
 		} else {
-			sh = pscsi_get_sh(pdv->pdv_host_id);
-			if (!(sh)) {
+			sh = scsi_host_lookup(pdv->pdv_host_id);
+			if (IS_ERR(sh)) {
 				printk(KERN_ERR "pSCSI: Unable to locate"
 					" pdv_host_id: %d\n", pdv->pdv_host_id);
-				return ERR_PTR(-ENODEV);
+				return (struct se_device *) sh;
 			}
 		}
 	} else {
Signature · 1 line
1.7.6
#14 lore raw

PATCH 12/103 tcm_loop: off by one in tcm_loop_make_naa_tpg()

In reply to Nicholas A. Bellinger

From: Dan Carpenter <[email protected]>

This is an off by one 'tgpt' check in tcm_loop_make_naa_tpg() that could result in memory corruption.

---
 drivers/target/loopback/tcm_loop.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/target/loopback/tcm_loop.c +1 -1
index 3274fec..26e3681 100644
@@ -1230,7 +1230,7 @@ struct se_portal_group *tcm_loop_make_naa_tpg(
 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
 	tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
 
-	if (tpgt > TL_TPGS_PER_HBA) {
+	if (tpgt >= TL_TPGS_PER_HBA) {
 		printk(KERN_ERR "Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
 				" %u\n", tpgt, TL_TPGS_PER_HBA);
 		return ERR_PTR(-EINVAL);
Signature · 1 line
1.7.6
#15 lore raw

PATCH 13/103 target: Remove hba queue depth and convert to spin_lock_irq usage

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

The queue depth in the virtual hba is no longer needed, we can just rely on the per-device queue depth limits.

Remove hba_queue_lock, since updating a single atomic no longer needs protection. This patch also converts se_dev->execute_task_lock usage in __transport_execute_tasks to use execute_task_lock with spin_lock_irq

Remove load_balance_queue, unused.

---
 drivers/target/target_core_file.c      |    7 +----
 drivers/target/target_core_file.h      |    2 -
 drivers/target/target_core_hba.c       |    4 ---
 drivers/target/target_core_iblock.c    |    7 +----
 drivers/target/target_core_iblock.h    |    1 -
 drivers/target/target_core_pscsi.c     |   22 +------------------
 drivers/target/target_core_pscsi.h     |    1 -
 drivers/target/target_core_rd.c        |    7 +----
 drivers/target/target_core_rd.h        |    2 -
 drivers/target/target_core_transport.c |   35 ++++++-------------------------
 include/target/target_core_base.h      |    5 ----
 11 files changed, 15 insertions(+), 78 deletions(-)
drivers/target/target_core_file.c +2 -5
index 40386ec..5ca1f5b 100644
@@ -72,17 +72,14 @@ static int fd_attach_hba(struct se_hba *hba, u32 host_id)
 
 	fd_host->fd_host_id = host_id;
 
-	atomic_set(&hba->left_queue_depth, FD_HBA_QUEUE_DEPTH);
-	atomic_set(&hba->max_queue_depth, FD_HBA_QUEUE_DEPTH);
 	hba->hba_ptr = (void *) fd_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM FILEIO HBA Driver %s on Generic"
 		" Target Core Stack %s\n", hba->hba_id, FD_VERSION,
 		TARGET_CORE_MOD_VERSION);
 	printk(KERN_INFO "CORE_HBA[%d] - Attached FILEIO HBA: %u to Generic"
-		" Target Core with TCQ Depth: %d MaxSectors: %u\n",
-		hba->hba_id, fd_host->fd_host_id,
-		atomic_read(&hba->max_queue_depth), FD_MAX_SECTORS);
+		" MaxSectors: %u\n",
+		hba->hba_id, fd_host->fd_host_id, FD_MAX_SECTORS);
 
 	return 0;
 }
drivers/target/target_core_file.h +0 -2
index ef4de2b..6386d3f 100644
@@ -4,8 +4,6 @@
 #define FD_VERSION		"4.0"
 
 #define FD_MAX_DEV_NAME		256
-/* Maximum queuedepth for the FILEIO HBA */
-#define FD_HBA_QUEUE_DEPTH	256
 #define FD_DEVICE_QUEUE_DEPTH	32
 #define FD_MAX_DEVICE_QUEUE_DEPTH 128
 #define FD_BLOCKSIZE		512
drivers/target/target_core_hba.c +0 -4
index ddf5ae0..8f3a0c4 100644
@@ -110,15 +110,11 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags)
 
 	INIT_LIST_HEAD(&hba->hba_dev_list);
 	spin_lock_init(&hba->device_lock);
-	spin_lock_init(&hba->hba_queue_lock);
 	mutex_init(&hba->hba_access_mutex);
 
 	hba->hba_index = scsi_get_new_index(SCSI_INST_INDEX);
 	hba->hba_flags |= hba_flags;
 
-	atomic_set(&hba->max_queue_depth, 0);
-	atomic_set(&hba->left_queue_depth, 0);
-
 	hba->transport = core_get_backend(plugin_name);
 	if (!hba->transport) {
 		ret = -EINVAL;
drivers/target/target_core_iblock.c +2 -5
index 5d5bd6e..5bd4f1c 100644
@@ -74,17 +74,14 @@ static int iblock_attach_hba(struct se_hba *hba, u32 host_id)
 
 	ib_host->iblock_host_id = host_id;
 
-	atomic_set(&hba->left_queue_depth, IBLOCK_HBA_QUEUE_DEPTH);
-	atomic_set(&hba->max_queue_depth, IBLOCK_HBA_QUEUE_DEPTH);
 	hba->hba_ptr = (void *) ib_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM iBlock HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
 		IBLOCK_VERSION, TARGET_CORE_MOD_VERSION);
 
-	printk(KERN_INFO "CORE_HBA[%d] - Attached iBlock HBA: %u to Generic"
-		" Target Core TCQ Depth: %d\n", hba->hba_id,
-		ib_host->iblock_host_id, atomic_read(&hba->max_queue_depth));
+	printk(KERN_INFO "CORE_HBA[%d] - Attached iBlock HBA: %u to Generic\n",
+		hba->hba_id, ib_host->iblock_host_id);
 
 	return 0;
 }
drivers/target/target_core_iblock.h +0 -1
index 64c1f4d..6b6d17b 100644
@@ -3,7 +3,6 @@
 
 #define IBLOCK_VERSION		"4.0"
 
-#define IBLOCK_HBA_QUEUE_DEPTH	512
 #define IBLOCK_DEVICE_QUEUE_DEPTH	32
 #define IBLOCK_MAX_DEVICE_QUEUE_DEPTH	128
 #define IBLOCK_MAX_CDBS		16
drivers/target/target_core_pscsi.c +2 -20
index d39226f..e221dea 100644
@@ -62,7 +62,6 @@ static void pscsi_req_done(struct request *, int);
  */
 static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
 {
-	int hba_depth;
 	struct pscsi_hba_virt *phv;
 
 	phv = kzalloc(sizeof(struct pscsi_hba_virt), GFP_KERNEL);
@@ -72,18 +71,14 @@ static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
 	}
 	phv->phv_host_id = host_id;
 	phv->phv_mode = PHV_VIRUTAL_HOST_ID;
-	hba_depth = PSCSI_VIRTUAL_HBA_DEPTH;
-	atomic_set(&hba->left_queue_depth, hba_depth);
-	atomic_set(&hba->max_queue_depth, hba_depth);
 
 	hba->hba_ptr = (void *)phv;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM SCSI HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
 		PSCSI_VERSION, TARGET_CORE_MOD_VERSION);
-	printk(KERN_INFO "CORE_HBA[%d] - Attached SCSI HBA to Generic"
-		" Target Core with TCQ Depth: %d\n", hba->hba_id,
-		atomic_read(&hba->max_queue_depth));
+	printk(KERN_INFO "CORE_HBA[%d] - Attached SCSI HBA to Generic\n",
+	       hba->hba_id);
 
 	return 0;
 }
@@ -112,7 +107,6 @@ static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
 {
 	struct pscsi_hba_virt *phv = (struct pscsi_hba_virt *)hba->hba_ptr;
 	struct Scsi_Host *sh = phv->phv_lld_host;
-	int hba_depth = PSCSI_VIRTUAL_HBA_DEPTH;
 	/*
 	 * Release the struct Scsi_Host
 	 */
@@ -122,8 +116,6 @@ static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
 
 		phv->phv_lld_host = NULL;
 		phv->phv_mode = PHV_VIRUTAL_HOST_ID;
-		atomic_set(&hba->left_queue_depth, hba_depth);
-		atomic_set(&hba->max_queue_depth, hba_depth);
 
 		printk(KERN_INFO "CORE_HBA[%d] - Disabled pSCSI HBA Passthrough"
 			" %s\n", hba->hba_id, (sh->hostt->name) ?
@@ -142,16 +134,6 @@ static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
 			" phv_host_id: %d\n", phv->phv_host_id);
 		return PTR_ERR(sh);
 	}
-	/*
-	 * Usually the SCSI LLD will use the hostt->can_queue value to define
-	 * its HBA TCQ depth.  Some other drivers (like 2.6 megaraid) don't set
-	 * this at all and set sh->can_queue at runtime.
-	 */
-	hba_depth = (sh->hostt->can_queue > sh->can_queue) ?
-		sh->hostt->can_queue : sh->can_queue;
-
-	atomic_set(&hba->left_queue_depth, hba_depth);
-	atomic_set(&hba->max_queue_depth, hba_depth);
 
 	phv->phv_lld_host = sh;
 	phv->phv_mode = PHV_LLD_SCSI_HOST_NO;
drivers/target/target_core_pscsi.h +0 -1
index a4cd5d3..280b689 100644
@@ -2,7 +2,6 @@
 #define TARGET_CORE_PSCSI_H
 
 #define PSCSI_VERSION		"v4.0"
-#define PSCSI_VIRTUAL_HBA_DEPTH	2048
 
 /* used in pscsi_find_alloc_len() */
 #ifndef INQUIRY_DATA_SIZE
drivers/target/target_core_rd.c +2 -5
index 2a00f70..0a424bb 100644
@@ -66,17 +66,14 @@ static int rd_attach_hba(struct se_hba *hba, u32 host_id)
 
 	rd_host->rd_host_id = host_id;
 
-	atomic_set(&hba->left_queue_depth, RD_HBA_QUEUE_DEPTH);
-	atomic_set(&hba->max_queue_depth, RD_HBA_QUEUE_DEPTH);
 	hba->hba_ptr = (void *) rd_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM Ramdisk HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
 		RD_HBA_VERSION, TARGET_CORE_MOD_VERSION);
 	printk(KERN_INFO "CORE_HBA[%d] - Attached Ramdisk HBA: %u to Generic"
-		" Target Core TCQ Depth: %d MaxSectors: %u\n", hba->hba_id,
-		rd_host->rd_host_id, atomic_read(&hba->max_queue_depth),
-		RD_MAX_SECTORS);
+		" MaxSectors: %u\n", hba->hba_id,
+		rd_host->rd_host_id, RD_MAX_SECTORS);
 
 	return 0;
 }
drivers/target/target_core_rd.h +0 -2
index 3ea19e2..bab9302 100644
@@ -7,8 +7,6 @@
 
 /* Largest piece of memory kmalloc can allocate */
 #define RD_MAX_ALLOCATION_SIZE	65536
-/* Maximum queuedepth for the Ramdisk HBA */
-#define RD_HBA_QUEUE_DEPTH	256
 #define RD_DEVICE_QUEUE_DEPTH	32
 #define RD_MAX_DEVICE_QUEUE_DEPTH 128
 #define RD_BLOCKSIZE		512
drivers/target/target_core_transport.c +7 -28
index 99b9e33..ae153bf 100644
@@ -959,12 +959,8 @@ void transport_complete_task(struct se_task *task, int success)
 	printk(KERN_INFO "task: %p CDB: 0x%02x obj_ptr: %p\n", task,
 			T_TASK(cmd)->t_task_cdb[0], dev);
 #endif
-	if (dev) {
-		spin_lock_irqsave(&SE_HBA(dev)->hba_queue_lock, flags);
+	if (dev)
 		atomic_inc(&dev->depth_left);
-		atomic_inc(&SE_HBA(dev)->left_queue_depth);
-		spin_unlock_irqrestore(&SE_HBA(dev)->hba_queue_lock, flags);
-	}
 
 	spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
 	atomic_set(&task->task_active, 0);
@@ -2140,16 +2136,6 @@ static int transport_stop_tasks_for_cmd(struct se_cmd *cmd)
 	return ret;
 }
 
-static void transport_failure_reset_queue_depth(struct se_device *dev)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&SE_HBA(dev)->hba_queue_lock, flags);
-	atomic_inc(&dev->depth_left);
-	atomic_inc(&SE_HBA(dev)->left_queue_depth);
-	spin_unlock_irqrestore(&SE_HBA(dev)->hba_queue_lock, flags);
-}
-
 /*
  * Handle SAM-esque emulation for generic transport request failures.
  */
@@ -2181,7 +2167,7 @@ static void transport_generic_request_failure(
 	transport_stop_all_task_timers(cmd);
 
 	if (dev)
-		transport_failure_reset_queue_depth(dev);
+		atomic_inc(&dev->depth_left);
 	/*
 	 * For SAM Task Attribute emulation for failed struct se_cmd
 	 */
@@ -2650,26 +2636,19 @@ static int __transport_execute_tasks(struct se_device *dev)
 	 * struct se_transport_task's to the selected transport.
 	 */
 check_depth:
-	spin_lock_irqsave(&SE_HBA(dev)->hba_queue_lock, flags);
-	if (!(atomic_read(&dev->depth_left)) ||
-	    !(atomic_read(&SE_HBA(dev)->left_queue_depth))) {
-		spin_unlock_irqrestore(&SE_HBA(dev)->hba_queue_lock, flags);
+	if (!atomic_read(&dev->depth_left))
 		return transport_tcq_window_closed(dev);
-	}
+
 	dev->dev_tcq_window_closed = 0;
 
-	spin_lock(&dev->execute_task_lock);
+	spin_lock_irq(&dev->execute_task_lock);
 	task = transport_get_task_from_execute_queue(dev);
-	spin_unlock(&dev->execute_task_lock);
+	spin_unlock_irq(&dev->execute_task_lock);
 
-	if (!task) {
-		spin_unlock_irqrestore(&SE_HBA(dev)->hba_queue_lock, flags);
+	if (!task)
 		return 0;
-	}
 
 	atomic_dec(&dev->depth_left);
-	atomic_dec(&SE_HBA(dev)->left_queue_depth);
-	spin_unlock_irqrestore(&SE_HBA(dev)->hba_queue_lock, flags);
 
 	cmd = TASK_CMD(task);
 
include/target/target_core_base.h +0 -5
index 561ac99..e35e9e4 100644
@@ -837,17 +837,12 @@ struct se_hba {
 	/* Virtual iSCSI devices attached. */
 	u32			dev_count;
 	u32			hba_index;
-	atomic_t		load_balance_queue;
-	atomic_t		left_queue_depth;
-	/* Maximum queue depth the HBA can handle. */
-	atomic_t		max_queue_depth;
 	/* Pointer to transport specific host structure. */
 	void			*hba_ptr;
 	/* Linked list for struct se_device */
 	struct list_head	hba_dev_list;
 	struct list_head	hba_list;
 	spinlock_t		device_lock;
-	spinlock_t		hba_queue_lock;
 	struct config_group	hba_group;
 	struct mutex		hba_access_mutex;
 	struct se_subsystem_api *transport;
Signature · 1 line
1.7.6
#17 lore raw

PATCH 15/103 target: Make struct se_queue_req.cmd type struct se_cmd *

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Doesn't appear to ever be used as anything but a se_cmd*, so it's safer to make it a pointer to a type.

Simplifies a few functions.

---
 drivers/target/target_core_transport.c |   30 ++++++++++++------------------
 include/target/target_core_base.h      |    2 +-
 2 files changed, 13 insertions(+), 19 deletions(-)
drivers/target/target_core_transport.c +12 -18
index fffa905..002ea6f 100644
@@ -817,7 +817,7 @@ static int transport_add_cmd_to_queue(
 	}
 	INIT_LIST_HEAD(&qr->qr_list);
 
-	qr->cmd = (void *)cmd;
+	qr->cmd = cmd;
 	qr->state = t_state;
 
 	if (t_state) {
@@ -843,7 +843,6 @@ static int transport_add_cmd_to_queue(
 static struct se_queue_req *
 __transport_get_qr_from_queue(struct se_queue_obj *qobj)
 {
-	struct se_cmd *cmd;
 	struct se_queue_req *qr = NULL;
 
 	if (list_empty(&qobj->qobj_list))
@@ -852,10 +851,9 @@ __transport_get_qr_from_queue(struct se_queue_obj *qobj)
 	list_for_each_entry(qr, &qobj->qobj_list, qr_list)
 		break;
 
-	if (qr->cmd) {
-		cmd = (struct se_cmd *)qr->cmd;
-		atomic_dec(&T_TASK(cmd)->t_transport_queue_active);
-	}
+	if (qr->cmd)
+		atomic_dec(&T_TASK(qr->cmd)->t_transport_queue_active);
+
 	list_del(&qr->qr_list);
 	atomic_dec(&qobj->queue_cnt);
 
@@ -865,7 +863,6 @@ __transport_get_qr_from_queue(struct se_queue_obj *qobj)
 static struct se_queue_req *
 transport_get_qr_from_queue(struct se_queue_obj *qobj)
 {
-	struct se_cmd *cmd;
 	struct se_queue_req *qr;
 	unsigned long flags;
 
@@ -878,10 +875,9 @@ transport_get_qr_from_queue(struct se_queue_obj *qobj)
 	list_for_each_entry(qr, &qobj->qobj_list, qr_list)
 		break;
 
-	if (qr->cmd) {
-		cmd = (struct se_cmd *)qr->cmd;
-		atomic_dec(&T_TASK(cmd)->t_transport_queue_active);
-	}
+	if (qr->cmd)
+		atomic_dec(&T_TASK(qr->cmd)->t_transport_queue_active);
+
 	list_del(&qr->qr_list);
 	atomic_dec(&qobj->queue_cnt);
 	spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
@@ -892,7 +888,6 @@ transport_get_qr_from_queue(struct se_queue_obj *qobj)
 static void transport_remove_cmd_from_queue(struct se_cmd *cmd,
 		struct se_queue_obj *qobj)
 {
-	struct se_cmd *q_cmd;
 	struct se_queue_req *qr = NULL, *qr_p = NULL;
 	unsigned long flags;
 
@@ -903,11 +898,10 @@ static void transport_remove_cmd_from_queue(struct se_cmd *cmd,
 	}
 
 	list_for_each_entry_safe(qr, qr_p, &qobj->qobj_list, qr_list) {
-		q_cmd = (struct se_cmd *)qr->cmd;
-		if (q_cmd != cmd)
+		if (qr->cmd != cmd)
 			continue;
 
-		atomic_dec(&T_TASK(q_cmd)->t_transport_queue_active);
+		atomic_dec(&T_TASK(qr->cmd)->t_transport_queue_active);
 		atomic_dec(&qobj->queue_cnt);
 		list_del(&qr->qr_list);
 		kfree(qr);
@@ -1287,7 +1281,7 @@ static void transport_release_all_cmds(struct se_device *dev)
 	list_for_each_entry_safe(qr, qr_p, &dev->dev_queue_obj->qobj_list,
 				qr_list) {
 
-		cmd = (struct se_cmd *)qr->cmd;
+		cmd = qr->cmd;
 		t_state = qr->state;
 		list_del(&qr->qr_list);
 		kfree(qr);
@@ -6023,7 +6017,7 @@ static void transport_processing_shutdown(struct se_device *dev)
 	while ((qr = __transport_get_qr_from_queue(dev->dev_queue_obj))) {
 		spin_unlock_irqrestore(
 				&dev->dev_queue_obj->cmd_queue_lock, flags);
-		cmd = (struct se_cmd *)qr->cmd;
+		cmd = qr->cmd;
 		state = qr->state;
 		kfree(qr);
 
@@ -6081,7 +6075,7 @@ get_cmd:
 		if (!(qr))
 			continue;
 
-		cmd = (struct se_cmd *)qr->cmd;
+		cmd = qr->cmd;
 		t_state = qr->state;
 		kfree(qr);
 
include/target/target_core_base.h +1 -1
index b2b4cf9..e35338d 100644
@@ -397,7 +397,7 @@ struct t10_reservation_template {
 
 struct se_queue_req {
 	int			state;
-	void			*cmd;
+	struct se_cmd		*cmd;
 	struct list_head	qr_list;
 } ____cacheline_aligned;
 
Signature · 1 line
1.7.6
#26 lore raw

PATCH 19/103 target: Simplify scsi mib index table code

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Taking scsi_mib_index and its lock out of the struct makes it possible to initialize both without code.

Replace type check with BUG_ON, since only bugs will cause type to be invalid. Nobody checks retval, in any case.

Remove wraparound protection. Will anyone really ever hit 4 billion mib index values?? If this is a concern, then the solution should probably be to make the index a u64 -- this interface wants to hand out unique values, and on wrap they would no longer meet that criteria, even if we skip 0.

---
 drivers/target/target_core_configfs.c  |    1 -
 drivers/target/target_core_transport.c |   28 +++++++---------------------
 include/target/target_core_base.h      |    5 -----
 include/target/target_core_transport.h |    1 -
 4 files changed, 7 insertions(+), 28 deletions(-)
drivers/target/target_core_configfs.c +0 -1
index 82c8e9a..27effbc 100644
@@ -3140,7 +3140,6 @@ static int __init target_core_init_configfs(void)
 
 	INIT_LIST_HEAD(&g_tf_list);
 	mutex_init(&g_tf_lock);
-	init_scsi_index_table();
 	ret = init_se_kmem_caches();
 	if (ret < 0)
 		return ret;
drivers/target/target_core_transport.c +7 -21
index 0f084a1..4bfa61f 100644
@@ -346,18 +346,9 @@ void release_se_kmem_caches(void)
 	kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache);
 }
 
-/* SCSI statistics table index */
-static struct scsi_index_table scsi_index_table;
-
-/*
- * Initialize the index table for allocating unique row indexes to various mib
- * tables.
- */
-void init_scsi_index_table(void)
-{
-	memset(&scsi_index_table, 0, sizeof(struct scsi_index_table));
-	spin_lock_init(&scsi_index_table.lock);
-}
+/* This code ensures unique mib indexes are handed out. */
+static DEFINE_SPINLOCK(scsi_mib_index_lock);
+static u32 scsi_mib_index[SCSI_INDEX_TYPE_MAX];
 
 /*
  * Allocate a new row index for the entry type specified
@@ -366,16 +357,11 @@ u32 scsi_get_new_index(scsi_index_t type)
 {
 	u32 new_index;
 
-	if ((type < 0) || (type >= SCSI_INDEX_TYPE_MAX)) {
-		printk(KERN_ERR "Invalid index type %d\n", type);
-		return -EINVAL;
-	}
+	BUG_ON((type < 0) || (type >= SCSI_INDEX_TYPE_MAX));
 
-	spin_lock(&scsi_index_table.lock);
-	new_index = ++scsi_index_table.scsi_mib_index[type];
-	if (new_index == 0)
-		new_index = ++scsi_index_table.scsi_mib_index[type];
-	spin_unlock(&scsi_index_table.lock);
+	spin_lock(&scsi_mib_index_lock);
+	new_index = ++scsi_mib_index[type];
+	spin_unlock(&scsi_mib_index_lock);
 
 	return new_index;
 }
include/target/target_core_base.h +0 -5
index de7bec6..23dd6b7 100644
@@ -205,11 +205,6 @@ typedef enum {
 	SCSI_INDEX_TYPE_MAX
 } scsi_index_t;
 
-struct scsi_index_table {
-	spinlock_t	lock;
-	u32		scsi_mib_index[SCSI_INDEX_TYPE_MAX];
-} ____cacheline_aligned;
-
 struct se_cmd;
 
 struct t10_alua {
include/target/target_core_transport.h +0 -1
index 06b8900..da982e9 100644
@@ -113,7 +113,6 @@ extern struct kmem_cache *se_mem_cache;
 
 extern int init_se_kmem_caches(void);
 extern void release_se_kmem_caches(void);
-extern void init_scsi_index_table(void);
 extern u32 scsi_get_new_index(scsi_index_t);
 extern void transport_init_queue_obj(struct se_queue_obj *);
 extern int transport_subsystem_check_init(void);
Signature · 1 line
1.7.6
#29 lore raw

PATCH 22/103 target: Ensure transport_dump_vpd_ident_type returns null-terminated str

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

strncpy() may leave the string not NULL-terminated if the buffer length is shorter than the string. Return -EINVAL if too short, instead.

---
 drivers/target/target_core_transport.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/target/target_core_transport.c +5 -2
index 473032e..72e4726 100644
@@ -1392,10 +1392,13 @@ int transport_dump_vpd_ident_type(
 		break;
 	}
 
-	if (p_buf)
+	if (p_buf) {
+		if (p_buf_len < strlen(buf)+1)
+			return -EINVAL;
 		strncpy(p_buf, buf, p_buf_len);
-	else
+	} else {
 		printk("%s", buf);
+	}
 
 	return ret;
 }
Signature · 1 line
1.7.6
#9 lore raw

PATCH 7/103 target: use errno values instead of returning -1 for everything

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Return errno values instead of -1. If checking the errno of a function, return what that function returned instead of -1, as well.

---
 drivers/target/loopback/tcm_loop.c     |    4 +-
 drivers/target/target_core_alua.c      |   24 ++++----
 drivers/target/target_core_cdb.c       |   12 ++--
 drivers/target/target_core_configfs.c  |   12 ++--
 drivers/target/target_core_device.c    |   98 ++++++++++++++++----------------
 drivers/target/target_core_file.c      |   14 ++--
 drivers/target/target_core_iblock.c    |    2 +-
 drivers/target/target_core_pr.c        |   36 ++++++------
 drivers/target/target_core_pscsi.c     |    8 +-
 drivers/target/target_core_rd.c        |   24 ++++----
 drivers/target/target_core_tpg.c       |   11 ++-
 drivers/target/target_core_transport.c |   51 +++++++++--------
 drivers/target/target_core_ua.c        |   16 +++---
 drivers/target/tcm_fc/tfc_conf.c       |    4 +-
 14 files changed, 161 insertions(+), 155 deletions(-)
drivers/target/loopback/tcm_loop.c +2 -2
index 2d0f22a..3274fec 100644
@@ -1402,9 +1402,9 @@ static int tcm_loop_register_configfs(void)
 	 * Register the top level struct config_item_type with TCM core
 	 */
 	fabric = target_fabric_configfs_init(THIS_MODULE, "loopback");
-	if (!fabric) {
+	if (IS_ERR(fabric)) {
 		printk(KERN_ERR "tcm_loop_register_configfs() failed!\n");
-		return -1;
+		return PTR_ERR(fabric);
 	}
 	/*
 	 * Setup the fabric API of function pointers used by target_core_mod
drivers/target/target_core_alua.c +12 -12
index 47abb42..a993f3c 100644
@@ -522,7 +522,7 @@ static int core_alua_state_check(
 	default:
 		printk(KERN_ERR "Unknown ALUA access state: 0x%02x\n",
 				out_alua_state);
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
@@ -553,7 +553,7 @@ static int core_alua_check_transition(int state, int *primary)
 		break;
 	default:
 		printk(KERN_ERR "Unknown ALUA access state: 0x%02x\n", state);
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
@@ -977,7 +977,7 @@ static int core_alua_set_tg_pt_secondary_state(
 		spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock);
 		printk(KERN_ERR "Unable to complete secondary state"
 				" transition\n");
-		return -1;
+		return -EINVAL;
 	}
 	trans_delay_msecs = tg_pt_gp->tg_pt_gp_trans_delay_msecs;
 	/*
@@ -1015,7 +1015,7 @@ static int core_alua_set_tg_pt_secondary_state(
 		if (!(md_buf)) {
 			printk(KERN_ERR "Unable to allocate md_buf for"
 				" secondary ALUA access metadata\n");
-			return -1;
+			return -ENOMEM;
 		}
 		mutex_lock(&port->sep_tg_pt_md_mutex);
 		core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem, port,
@@ -1062,7 +1062,7 @@ int core_alua_set_lu_gp_id(struct t10_alua_lu_gp *lu_gp, u16 lu_gp_id)
 	if (lu_gp->lu_gp_valid_id) {
 		printk(KERN_WARNING "ALUA LU Group already has a valid ID,"
 			" ignoring request\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	spin_lock(&se_global->lu_gps_lock);
@@ -1071,7 +1071,7 @@ int core_alua_set_lu_gp_id(struct t10_alua_lu_gp *lu_gp, u16 lu_gp_id)
 				" 0x0000ffff reached\n");
 		spin_unlock(&se_global->lu_gps_lock);
 		kmem_cache_free(t10_alua_lu_gp_cache, lu_gp);
-		return -1;
+		return -ENOSPC;
 	}
 again:
 	lu_gp_id_tmp = (lu_gp_id != 0) ? lu_gp_id :
@@ -1086,7 +1086,7 @@ again:
 				" already exists, ignoring request\n",
 				lu_gp_id);
 			spin_unlock(&se_global->lu_gps_lock);
-			return -1;
+			return -EINVAL;
 		}
 	}
 
@@ -1330,7 +1330,7 @@ int core_alua_set_tg_pt_gp_id(
 	if (tg_pt_gp->tg_pt_gp_valid_id) {
 		printk(KERN_WARNING "ALUA TG PT Group already has a valid ID,"
 			" ignoring request\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	spin_lock(&T10_ALUA(su_dev)->tg_pt_gps_lock);
@@ -1339,7 +1339,7 @@ int core_alua_set_tg_pt_gp_id(
 			" 0x0000ffff reached\n");
 		spin_unlock(&T10_ALUA(su_dev)->tg_pt_gps_lock);
 		kmem_cache_free(t10_alua_tg_pt_gp_cache, tg_pt_gp);
-		return -1;
+		return -ENOSPC;
 	}
 again:
 	tg_pt_gp_id_tmp = (tg_pt_gp_id != 0) ? tg_pt_gp_id :
@@ -1354,7 +1354,7 @@ again:
 			printk(KERN_ERR "ALUA Target Port Group ID: %hu already"
 				" exists, ignoring request\n", tg_pt_gp_id);
 			spin_unlock(&T10_ALUA(su_dev)->tg_pt_gps_lock);
-			return -1;
+			return -EINVAL;
 		}
 	}
 
@@ -1967,8 +1967,8 @@ int core_setup_alua(struct se_device *dev, int force_pt)
 		 * LUN Group.
 		 */
 		lu_gp_mem = core_alua_allocate_lu_gp_mem(dev);
-		if (IS_ERR(lu_gp_mem) || !lu_gp_mem)
-			return -1;
+		if (IS_ERR(lu_gp_mem))
+			return PTR_ERR(lu_gp_mem);
 
 		alua->alua_type = SPC3_ALUA_EMULATED;
 		alua->alua_state_check = &core_alua_state_check;
drivers/target/target_core_cdb.c +6 -6
index 7f19c8b..b39ffad 100644
@@ -75,7 +75,7 @@ target_emulate_inquiry_std(struct se_cmd *cmd)
 	if (cmd->data_length < 6) {
 		printk(KERN_ERR "SCSI Inquiry payload length: %u"
 			" too small for EVPD=0\n", cmd->data_length);
-		return -1;
+		return -EINVAL;
 	}
 
 	buf[0] = dev->transport->get_device_type(dev);
@@ -501,7 +501,7 @@ target_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
 		printk(KERN_INFO "Received data_length: %u"
 			" too small for EVPD 0xb0\n",
 			cmd->data_length);
-		return -1;
+		return -EINVAL;
 	}
 
 	if (have_tp && cmd->data_length < (0x3c + 4)) {
@@ -637,7 +637,7 @@ target_emulate_inquiry(struct se_cmd *cmd)
 	if (cmd->data_length < 4) {
 		printk(KERN_ERR "SCSI Inquiry payload length: %u"
 			" too small for EVPD=1\n", cmd->data_length);
-		return -1;
+		return -EINVAL;
 	}
 	buf[0] = dev->transport->get_device_type(dev);
 
@@ -656,7 +656,7 @@ target_emulate_inquiry(struct se_cmd *cmd)
 		return target_emulate_evpd_b2(cmd, buf);
 	default:
 		printk(KERN_ERR "Unknown VPD Code: 0x%02x\n", cdb[2]);
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
@@ -991,7 +991,7 @@ target_emulate_unmap(struct se_task *task)
 		if (ret < 0) {
 			printk(KERN_ERR "blkdev_issue_discard() failed: %d\n",
 					ret);
-			return -1;
+			return ret;
 		}
 
 		ptr += 16;
@@ -1024,7 +1024,7 @@ target_emulate_write_same(struct se_task *task)
 	ret = dev->transport->do_discard(dev, lba, range);
 	if (ret < 0) {
 		printk(KERN_INFO "blkdev_issue_discard() failed for WRITE_SAME\n");
-		return -1;
+		return ret;
 	}
 
 	task->task_scsi_status = GOOD;
drivers/target/target_core_configfs.c +6 -6
index c614000..d140258 100644
@@ -298,21 +298,21 @@ struct target_fabric_configfs *target_fabric_configfs_init(
 
 	if (!(fabric_mod)) {
 		printk(KERN_ERR "Missing struct module *fabric_mod pointer\n");
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	}
 	if (!(name)) {
 		printk(KERN_ERR "Unable to locate passed fabric name\n");
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	}
 	if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) {
 		printk(KERN_ERR "Passed name: %s exceeds TARGET_FABRIC"
 			"_NAME_SIZE\n", name);
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	}
 
 	tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
 	if (!(tf))
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&tf->tf_list);
 	atomic_set(&tf->tf_access_cnt, 0);
@@ -3133,7 +3133,7 @@ static int __init target_core_init_configfs(void)
 	init_scsi_index_table();
 	ret = init_se_global();
 	if (ret < 0)
-		return -1;
+		return ret;
 	/*
 	 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
 	 * and ALUA Logical Unit Group and Target Port Group infrastructure.
@@ -3241,7 +3241,7 @@ out_global:
 		kfree(hba_cg->default_groups);
 	kfree(target_cg->default_groups);
 	release_se_global();
-	return -1;
+	return ret;
 }
 
 static void __exit target_core_exit_configfs(void)
drivers/target/target_core_device.c +49 -49

351 lines not on this page · raw message

drivers/target/target_core_file.c +7 -7
index 150c430..40386ec 100644
@@ -67,7 +67,7 @@ static int fd_attach_hba(struct se_hba *hba, u32 host_id)
 	fd_host = kzalloc(sizeof(struct fd_host), GFP_KERNEL);
 	if (!(fd_host)) {
 		printk(KERN_ERR "Unable to allocate memory for struct fd_host\n");
-		return -1;
+		return -ENOMEM;
 	}
 
 	fd_host->fd_host_id = host_id;
@@ -300,7 +300,7 @@ static int fd_do_readv(struct se_task *task)
 	iov = kzalloc(sizeof(struct iovec) * task->task_sg_num, GFP_KERNEL);
 	if (!(iov)) {
 		printk(KERN_ERR "Unable to allocate fd_do_readv iov[]\n");
-		return -1;
+		return -ENOMEM;
 	}
 
 	for (i = 0; i < task->task_sg_num; i++) {
@@ -324,13 +324,13 @@ static int fd_do_readv(struct se_task *task)
 			printk(KERN_ERR "vfs_readv() returned %d,"
 				" expecting %d for S_ISBLK\n", ret,
 				(int)task->task_size);
-			return -1;
+			return (ret < 0 ? ret : -EINVAL);
 		}
 	} else {
 		if (ret < 0) {
 			printk(KERN_ERR "vfs_readv() returned %d for non"
 				" S_ISBLK\n", ret);
-			return -1;
+			return ret;
 		}
 	}
 
@@ -350,7 +350,7 @@ static int fd_do_writev(struct se_task *task)
 	iov = kzalloc(sizeof(struct iovec) * task->task_sg_num, GFP_KERNEL);
 	if (!(iov)) {
 		printk(KERN_ERR "Unable to allocate fd_do_writev iov[]\n");
-		return -1;
+		return -ENOMEM;
 	}
 
 	for (i = 0; i < task->task_sg_num; i++) {
@@ -367,7 +367,7 @@ static int fd_do_writev(struct se_task *task)
 
 	if (ret < 0 || ret != task->task_size) {
 		printk(KERN_ERR "vfs_writev() returned %d\n", ret);
-		return -1;
+		return (ret < 0 ? ret : -EINVAL);
 	}
 
 	return 1;
@@ -599,7 +599,7 @@ static ssize_t fd_check_configfs_dev_params(struct se_hba *hba, struct se_subsys
 
 	if (!(fd_dev->fbd_flags & FBDF_HAS_PATH)) {
 		printk(KERN_ERR "Missing fd_dev_name=\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
drivers/target/target_core_iblock.c +1 -1
index 8663900..5d5bd6e 100644
@@ -527,7 +527,7 @@ static ssize_t iblock_check_configfs_dev_params(
 
 	if (!(ibd->ibd_flags & IBDF_HAS_UDEV_PATH)) {
 		printk(KERN_ERR "Missing udev_path= parameters for IBLOCK\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
drivers/target/target_core_pr.c +18 -18
index b662db3..99b97db 100644
@@ -105,13 +105,13 @@ static int core_scsi2_reservation_check(struct se_cmd *cmd, u32 *pr_reg_type)
 	}
 	if (dev->dev_reserved_node_acl != sess->se_node_acl) {
 		spin_unlock(&dev->dev_reservation_lock);
-		return -1;
+		return -EINVAL;
 	}
 	if (!(dev->dev_flags & DF_SPC2_RESERVATIONS_WITH_ISID)) {
 		spin_unlock(&dev->dev_reservation_lock);
 		return 0;
 	}
-	ret = (dev->dev_res_bin_isid == sess->sess_bin_isid) ? 0 : -1;
+	ret = (dev->dev_res_bin_isid == sess->sess_bin_isid) ? 0 : -EINVAL;
 	spin_unlock(&dev->dev_reservation_lock);
 
 	return ret;
@@ -362,7 +362,7 @@ static int core_scsi3_pr_seq_non_holder(
 			registered_nexus = 1;
 		break;
 	default:
-		return -1;
+		return -EINVAL;
 	}
 	/*
 	 * Referenced from spc4r17 table 45 for *NON* PR holder access
@@ -414,7 +414,7 @@ static int core_scsi3_pr_seq_non_holder(
 		default:
 			printk(KERN_ERR "Unknown PERSISTENT_RESERVE_OUT service"
 				" action: 0x%02x\n", cdb[1] & 0x1f);
-			return -1;
+			return -EINVAL;
 		}
 		break;
 	case RELEASE:
@@ -461,7 +461,7 @@ static int core_scsi3_pr_seq_non_holder(
 		default:
 			printk(KERN_ERR "Unknown MI Service Action: 0x%02x\n",
 				(cdb[1] & 0x1f));
-			return -1;
+			return -EINVAL;
 		}
 		break;
 	case ACCESS_CONTROL_IN:
@@ -592,14 +592,14 @@ static int core_scsi3_pr_reservation_check(
 	cmd->pr_res_key = dev->dev_pr_res_holder->pr_res_key;
 	if (dev->dev_pr_res_holder->pr_reg_nacl != sess->se_node_acl) {
 		spin_unlock(&dev->dev_reservation_lock);
-		return -1;
+		return -EINVAL;
 	}
 	if (!(dev->dev_pr_res_holder->isid_present_at_reg)) {
 		spin_unlock(&dev->dev_reservation_lock);
 		return 0;
 	}
 	ret = (dev->dev_pr_res_holder->pr_reg_bin_isid ==
-	       sess->sess_bin_isid) ? 0 : -1;
+	       sess->sess_bin_isid) ? 0 : -EINVAL;
 	/*
 	 * Use bit in *pr_reg_type to notify ISID mismatch in
 	 * core_scsi3_pr_seq_non_holder().
@@ -819,13 +819,13 @@ int core_scsi3_alloc_aptpl_registration(
 
 	if (!(i_port) || !(t_port) || !(sa_res_key)) {
 		printk(KERN_ERR "Illegal parameters for APTPL registration\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	pr_reg = kmem_cache_zalloc(t10_pr_reg_cache, GFP_KERNEL);
 	if (!(pr_reg)) {
 		printk(KERN_ERR "Unable to allocate struct t10_pr_registration\n");
-		return -1;
+		return -ENOMEM;
 	}
 	pr_reg->pr_aptpl_buf = kzalloc(pr_tmpl->pr_aptpl_buf_len, GFP_KERNEL);
 
@@ -1107,7 +1107,7 @@ static int core_scsi3_alloc_registration(
 	pr_reg = __core_scsi3_alloc_registration(dev, nacl, deve, isid,
 			sa_res_key, all_tg_pt, aptpl);
 	if (!(pr_reg))
-		return -1;
+		return -EPERM;
 
 	__core_scsi3_add_registration(dev, nacl, pr_reg,
 			register_type, register_move);
@@ -1240,7 +1240,7 @@ static int core_scsi3_check_implict_release(
 			" UNREGISTER while existing reservation with matching"
 			" key 0x%016Lx is present from another SCSI Initiator"
 			" Port\n", pr_reg->pr_res_key);
-		ret = -1;
+		ret = -EPERM;
 	}
 	spin_unlock(&dev->dev_reservation_lock);
 
@@ -1920,7 +1920,7 @@ static int __core_scsi3_update_aptpl_buf(
 			printk(KERN_ERR "Unable to update renaming"
 				" APTPL metadata\n");
 			spin_unlock(&T10_RES(su_dev)->registration_lock);
-			return -1;
+			return -EMSGSIZE;
 		}
 		len += sprintf(buf+len, "%s", tmp);
 
@@ -1938,7 +1938,7 @@ static int __core_scsi3_update_aptpl_buf(
 			printk(KERN_ERR "Unable to update renaming"
 				" APTPL metadata\n");
 			spin_unlock(&T10_RES(su_dev)->registration_lock);
-			return -1;
+			return -EMSGSIZE;
 		}
 		len += sprintf(buf+len, "%s", tmp);
 		reg_count++;
@@ -1989,7 +1989,7 @@ static int __core_scsi3_write_aptpl_to_file(
 	if (strlen(&wwn->unit_serial[0]) >= 512) {
 		printk(KERN_ERR "WWN value for struct se_device does not fit"
 			" into path buffer\n");
-		return -1;
+		return -EMSGSIZE;
 	}
 
 	snprintf(path, 512, "/var/target/pr/aptpl_%s", &wwn->unit_serial[0]);
@@ -1997,7 +1997,7 @@ static int __core_scsi3_write_aptpl_to_file(
 	if (IS_ERR(file) || !file || !file->f_dentry) {
 		printk(KERN_ERR "filp_open(%s) for APTPL metadata"
 			" failed\n", path);
-		return -1;
+		return (PTR_ERR(file) < 0 ? PTR_ERR(file) : -ENOENT);
 	}
 
 	iov[0].iov_base = &buf[0];
@@ -2014,7 +2014,7 @@ static int __core_scsi3_write_aptpl_to_file(
 	if (ret < 0) {
 		printk("Error writing APTPL metadata file: %s\n", path);
 		filp_close(file, NULL);
-		return -1;
+		return -EIO;
 	}
 	filp_close(file, NULL);
 
@@ -2049,14 +2049,14 @@ static int core_scsi3_update_and_write_aptpl(
 	ret = core_scsi3_update_aptpl_buf(dev, buf, pr_aptpl_buf_len,
 				clear_aptpl_metadata);
 	if (ret != 0)
-		return -1;
+		return ret;
 	/*
 	 * __core_scsi3_write_aptpl_to_file() will call strlen()
 	 * on the passed buf to determine pr_aptpl_buf_len.
 	 */
 	ret = __core_scsi3_write_aptpl_to_file(dev, buf, 0);
 	if (ret != 0)
-		return -1;
+		return ret;
 
 	return ret;
 }
drivers/target/target_core_pscsi.c +4 -4
index 331d423..fb2e8cb 100644
@@ -86,7 +86,7 @@ static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
 	phv = kzalloc(sizeof(struct pscsi_hba_virt), GFP_KERNEL);
 	if (!(phv)) {
 		printk(KERN_ERR "Unable to allocate struct pscsi_hba_virt\n");
-		return -1;
+		return -ENOMEM;
 	}
 	phv->phv_host_id = host_id;
 	phv->phv_mode = PHV_VIRUTAL_HOST_ID;
@@ -236,7 +236,7 @@ pscsi_get_inquiry_vpd_serial(struct scsi_device *sdev, struct t10_wwn *wwn)
 
 	buf = kzalloc(INQUIRY_VPD_SERIAL_LEN, GFP_KERNEL);
 	if (!buf)
-		return -1;
+		return -ENOMEM;
 
 	memset(cdb, 0, MAX_COMMAND_SIZE);
 	cdb[0] = INQUIRY;
@@ -259,7 +259,7 @@ pscsi_get_inquiry_vpd_serial(struct scsi_device *sdev, struct t10_wwn *wwn)
 
 out_free:
 	kfree(buf);
-	return -1;
+	return -EPERM;
 }
 
 static void
@@ -1030,7 +1030,7 @@ static ssize_t pscsi_check_configfs_dev_params(
 	    !(pdv->pdv_flags & PDF_HAS_LUN_ID)) {
 		printk(KERN_ERR "Missing scsi_channel_id=, scsi_target_id= and"
 			" scsi_lun_id= parameters\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
drivers/target/target_core_rd.c +12 -12
index 7837dd3..793a94b 100644
@@ -383,7 +383,7 @@ static int rd_MEMCPY_read(struct rd_request *req)
 
 	table = rd_get_sg_table(dev, req->rd_page);
 	if (!(table))
-		return -1;
+		return -EINVAL;
 
 	table_sg_end = (table->page_end_offset - req->rd_page);
 	sg_d = task->task_sg;
@@ -481,7 +481,7 @@ static int rd_MEMCPY_read(struct rd_request *req)
 #endif
 		table = rd_get_sg_table(dev, req->rd_page);
 		if (!(table))
-			return -1;
+			return -EINVAL;
 
 		sg_s = &table->sg_table[j = 0];
 	}
@@ -506,7 +506,7 @@ static int rd_MEMCPY_write(struct rd_request *req)
 
 	table = rd_get_sg_table(dev, req->rd_page);
 	if (!(table))
-		return -1;
+		return -EINVAL;
 
 	table_sg_end = (table->page_end_offset - req->rd_page);
 	sg_d = &table->sg_table[req->rd_page - table->page_start_offset];
@@ -604,7 +604,7 @@ static int rd_MEMCPY_write(struct rd_request *req)
 #endif
 		table = rd_get_sg_table(dev, req->rd_page);
 		if (!(table))
-			return -1;
+			return -EINVAL;
 
 		sg_d = &table->sg_table[j = 0];
 	}
@@ -664,7 +664,7 @@ static int rd_DIRECT_with_offset(
 
 	table = rd_get_sg_table(dev, req->rd_page);
 	if (!(table))
-		return -1;
+		return -EINVAL;
 
 	table_sg_end = (table->page_end_offset - req->rd_page);
 	sg_s = &table->sg_table[req->rd_page - table->page_start_offset];
@@ -678,7 +678,7 @@ static int rd_DIRECT_with_offset(
 		se_mem = kmem_cache_zalloc(se_mem_cache, GFP_KERNEL);
 		if (!(se_mem)) {
 			printk(KERN_ERR "Unable to allocate struct se_mem\n");
-			return -1;
+			return -ENOMEM;
 		}
 		INIT_LIST_HEAD(&se_mem->se_list);
 
@@ -734,7 +734,7 @@ check_eot:
 #endif
 		table = rd_get_sg_table(dev, req->rd_page);
 		if (!(table))
-			return -1;
+			return -EINVAL;
 
 		sg_s = &table->sg_table[j = 0];
 	}
@@ -767,7 +767,7 @@ static int rd_DIRECT_without_offset(
 
 	table = rd_get_sg_table(dev, req->rd_page);
 	if (!(table))
-		return -1;
+		return -EINVAL;
 
 	sg_s = &table->sg_table[req->rd_page - table->page_start_offset];
 #ifdef DEBUG_RAMDISK_DR
@@ -780,7 +780,7 @@ static int rd_DIRECT_without_offset(
 		se_mem = kmem_cache_zalloc(se_mem_cache, GFP_KERNEL);
 		if (!(se_mem)) {
 			printk(KERN_ERR "Unable to allocate struct se_mem\n");
-			return -1;
+			return -ENOMEM;
 		}
 		INIT_LIST_HEAD(&se_mem->se_list);
 
@@ -816,7 +816,7 @@ static int rd_DIRECT_without_offset(
 #endif
 		table = rd_get_sg_table(dev, req->rd_page);
 		if (!(table))
-			return -1;
+			return -EINVAL;
 
 		sg_s = &table->sg_table[j = 0];
 	}
@@ -876,7 +876,7 @@ static int rd_DIRECT_do_se_mem_map(
 	if (cmd->data_direction == DMA_TO_DEVICE) {
 		printk(KERN_ERR "DMA_TO_DEVICE not supported for"
 				" RAMDISK_DR with task_sg_chaining=1\n");
-		return -1;
+		return -ENOSYS;
 	}
 	/*
 	 * Special case for if task_sg_chaining is enabled, then
@@ -975,7 +975,7 @@ static ssize_t rd_check_configfs_dev_params(struct se_hba *hba, struct se_subsys
 
 	if (!(rd_dev->rd_flags & RDF_HAS_PAGE_COUNT)) {
 		printk(KERN_INFO "Missing rd_pages= parameter\n");
-		return -1;
+		return -EINVAL;
 	}
 
 	return 0;
drivers/target/target_core_tpg.c +7 -4
index 5ec745f..dc024c1 100644
@@ -233,7 +233,7 @@ static int core_create_device_list_for_node(struct se_node_acl *nacl)
 	if (!(nacl->device_list)) {
 		printk(KERN_ERR "Unable to allocate memory for"
 			" struct se_node_acl->device_list\n");
-		return -1;
+		return -ENOMEM;
 	}
 	for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
 		deve = &nacl->device_list[i];
@@ -614,7 +614,7 @@ static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg)
 
 	ret = core_tpg_post_addlun(se_tpg, lun, lun_access, dev);
 	if (ret < 0)
-		return -1;
+		return ret;
 
 	return 0;
 }
@@ -772,8 +772,11 @@ int core_tpg_post_addlun(
 	u32 lun_access,
 	void *lun_ptr)
 {
-	if (core_dev_export(lun_ptr, tpg, lun) < 0)
-		return -1;
+	int ret;
+
+	ret = core_dev_export(lun_ptr, tpg, lun);
+	if (ret < 0)
+		return ret;
 
 	spin_lock(&tpg->tpg_lun_lock);
 	lun->lun_access = lun_access;
drivers/target/target_core_transport.c +27 -24

194 lines not on this page · raw message

drivers/target/target_core_ua.c +8 -8
index df35517..4f754ca 100644
@@ -80,10 +80,10 @@ int core_scsi3_ua_check(
 	case REQUEST_SENSE:
 		return 0;
 	default:
-		return -1;
+		return -EINVAL;
 	}
 
-	return -1;
+	return -EINVAL;
 }
 
 int core_scsi3_ua_allocate(
@@ -98,12 +98,12 @@ int core_scsi3_ua_allocate(
 	 * PASSTHROUGH OPS
 	 */
 	if (!(nacl))
-		return -1;
+		return -EINVAL;
 
 	ua = kmem_cache_zalloc(se_ua_cache, GFP_ATOMIC);
 	if (!(ua)) {
 		printk(KERN_ERR "Unable to allocate struct se_ua\n");
-		return -1;
+		return -ENOMEM;
 	}
 	INIT_LIST_HEAD(&ua->ua_dev_list);
 	INIT_LIST_HEAD(&ua->ua_nacl_list);
@@ -285,17 +285,17 @@ int core_scsi3_ua_clear_for_request_sense(
 	int head = 1;
 
 	if (!(sess))
-		return -1;
+		return -EINVAL;
 
 	nacl = sess->se_node_acl;
 	if (!(nacl))
-		return -1;
+		return -EINVAL;
 
 	spin_lock_irq(&nacl->device_list_lock);
 	deve = &nacl->device_list[cmd->orig_fe_lun];
 	if (!(atomic_read(&deve->ua_count))) {
 		spin_unlock_irq(&nacl->device_list_lock);
-		return -1;
+		return -EPERM;
 	}
 	/*
 	 * The highest priority Unit Attentions are placed at the head of the
@@ -328,5 +328,5 @@ int core_scsi3_ua_clear_for_request_sense(
 		" ASCQ: 0x%02x\n", TPG_TFO(nacl->se_tpg)->get_fabric_name(),
 		cmd->orig_fe_lun, *asc, *ascq);
 
-	return (head) ? -1 : 0;
+	return (head) ? -EPERM : 0;
 }
drivers/target/tcm_fc/tfc_conf.c +2 -2
index 84e868c..8c5067c 100644
@@ -582,10 +582,10 @@ int ft_register_configfs(void)
 	 * Register the top level struct config_item_type with TCM core
 	 */
 	fabric = target_fabric_configfs_init(THIS_MODULE, "fc");
-	if (!fabric) {
+	if (IS_ERR(fabric)) {
 		printk(KERN_INFO "%s: target_fabric_configfs_init() failed!\n",
 		       __func__);
-		return -1;
+		return PTR_ERR(fabric);
 	}
 	fabric->tf_ops = ft_fabric_ops;
 
Signature · 1 line
1.7.6
#5 lore raw

PATCH 5/103 loopback: Only build tcm_loop as module

In reply to Nicholas A. Bellinger

From: Stefan Hajnoczi <[email protected]>

The tcm_loop must be built as a module. It cannot be built in.

---
 drivers/target/loopback/Kconfig |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/target/loopback/Kconfig +2 -1
index 57dcbc2..1bd6a65 100644
@@ -1,7 +1,8 @@
 config LOOPBACK_TARGET
 	tristate "TCM Virtual SAS target and Linux/SCSI LDD fabric loopback module"
+	depends on m
 	help
-	  Say Y here to enable the TCM Virtual SAS target and Linux/SCSI LLD
+	  Say M here to enable the TCM Virtual SAS target and Linux/SCSI LLD
 	  fabric loopback module.
 
 config LOOPBACK_TARGET_CDB_DEBUG
Signature · 1 line
1.7.6
#3 lore raw

PATCH 3/103 target: use MAINTENANCE_IN and MAINTENANCE_OUT definitions in scsi.h

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

---
 drivers/target/target_core_transport.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/target/target_core_transport.c +2 -2
index 4b9b716..1882251 100644
@@ -3325,7 +3325,7 @@ static int transport_generic_cmd_sequencer(
 			goto out_unsupported_cdb;
 		}
 		break;
-	case 0xa3:
+	case MAINTENANCE_IN:
 		if (TRANSPORT(dev)->get_device_type(dev) != TYPE_ROM) {
 			/* MAINTENANCE_IN from SCC-2 */
 			/*
@@ -3395,7 +3395,7 @@ static int transport_generic_cmd_sequencer(
 		size = READ_POSITION_LEN;
 		cmd->se_cmd_flags |= SCF_SCSI_CONTROL_NONSG_IO_CDB;
 		break;
-	case 0xa4:
+	case MAINTENANCE_OUT:
 		if (TRANSPORT(dev)->get_device_type(dev) != TYPE_ROM) {
 			/* MAINTENANCE_OUT from SCC-2
 			 *
Signature · 1 line
1.7.6
#2 lore raw

PATCH 2/103 target: Minor header comment fixes

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

---
 drivers/target/target_core_device.c |    2 +-
 drivers/target/target_core_hba.c    |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/target/target_core_device.c +1 -1
index f5516a1..1b5d78f 100644
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * Filename:  target_core_device.c (based on iscsi_target_device.c)
  *
- * This file contains the iSCSI Virtual Device and Disk Transport
+ * This file contains the TCM Virtual Device and Disk Transport
  * agnostic related functions.
  *
  * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc.
drivers/target/target_core_hba.c +1 -1
index 0b8f8da..ddf5ae0 100644
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * Filename:  target_core_hba.c
  *
- * This file copntains the iSCSI HBA Transport related functions.
+ * This file contains the TCM HBA Transport related functions.
  *
  * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc.
  * Copyright (c) 2005, 2006, 2007 SBE, Inc.
Signature · 1 line
1.7.6
#10 lore raw

PATCH 8/103 target: Rename transport_calc_sg_num to transport_init_task_sg

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

The function doesn't just calculate how many sgs there are, it also allocates and initializes the task_sg.

---
 drivers/target/target_core_rd.c        |    7 ++++---
 drivers/target/target_core_transport.c |   15 ++++++++-------
 include/target/target_core_transport.h |    2 +-
 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/target/target_core_rd.c +4 -3
index 793a94b..2a00f70 100644
@@ -884,11 +884,12 @@ static int rd_DIRECT_do_se_mem_map(
 	 * transport_do_task_sg_chain() for creating chainged SGLs
 	 * across multiple struct se_task->task_sg[].
 	 */
-	if (!(transport_calc_sg_num(task,
+	ret = transport_init_task_sg(task,
 			list_entry(T_TASK(cmd)->t_mem_list->next,
 				   struct se_mem, se_list),
-			task_offset)))
-		return -1;
+			task_offset);
+	if (ret <= 0)
+		return ret;
 
 	return transport_map_mem_to_sg(task, se_mem_list, task->task_sg,
 			list_entry(T_TASK(cmd)->t_mem_list->next,
drivers/target/target_core_transport.c +8 -7
index 66c4093..bae584d 100644
@@ -4411,7 +4411,7 @@ out:
 	return -ENOMEM;
 }
 
-u32 transport_calc_sg_num(
+int transport_init_task_sg(
 	struct se_task *task,
 	struct se_mem *in_se_mem,
 	u32 task_offset)
@@ -4786,7 +4786,7 @@ void transport_do_task_sg_chain(struct se_cmd *cmd)
 					&T_TASK(cmd)->t_task_list))) {
 				/*
 				 * Clear existing SGL termination bit set in
-				 * transport_calc_sg_num(), see sg_mark_end()
+				 * transport_init_task_sg(), see sg_mark_end()
 				 */
 				sg_end_cur = &task->task_sg[task->task_sg_num - 1];
 				sg_end_cur->page_link &= ~0x02;
@@ -4812,7 +4812,7 @@ void transport_do_task_sg_chain(struct se_cmd *cmd)
 		if (!(list_is_last(&task->t_list, &T_TASK(cmd)->t_task_list))) {
 			/*
 			 * Clear existing SGL termination bit set in
-			 * transport_calc_sg_num(), see sg_mark_end()
+			 * transport_init_task_sg(), see sg_mark_end()
 			 */
 			sg_end = &task->task_sg[task->task_sg_num - 1];
 			sg_end->page_link &= ~0x02;
@@ -4878,7 +4878,7 @@ static int transport_do_se_mem_map(
 	 * This is the normal path for all normal non BIDI and BIDI-COMMAND
 	 * WRITE payloads..  If we need to do BIDI READ passthrough for
 	 * TCM/pSCSI the first call to transport_do_se_mem_map ->
-	 * transport_calc_sg_num() -> transport_map_mem_to_sg() will do the
+	 * transport_init_task_sg() -> transport_map_mem_to_sg() will do the
 	 * allocation for task->task_sg_bidi, and the subsequent call to
 	 * transport_do_se_mem_map() from transport_generic_get_cdb_count()
 	 */
@@ -4887,8 +4887,9 @@ static int transport_do_se_mem_map(
 		 * Assume default that transport plugin speaks preallocated
 		 * scatterlists.
 		 */
-		if (!(transport_calc_sg_num(task, in_se_mem, task_offset)))
-			return -1;
+		ret = transport_init_task_sg(task, in_se_mem, task_offset);
+		if (ret <= 0)
+			return ret;
 		/*
 		 * struct se_task->task_sg now contains the struct scatterlist array.
 		 */
@@ -4986,7 +4987,7 @@ static u32 transport_generic_get_cdb_count(
 		 *
 		 * Note that the first call to transport_do_se_mem_map() above will
 		 * allocate struct se_task->task_sg_bidi in transport_do_se_mem_map()
-		 * -> transport_calc_sg_num(), and the second here will do the
+		 * -> transport_init_task_sg(), and the second here will do the
 		 * mapping for SCSI READ for BIDI-COMMAND passthrough with TCM/pSCSI.
 		 */
 		if (task->task_sg_bidi != NULL) {
include/target/target_core_transport.h +1 -1
index 24a1c6c..199a404 100644
@@ -184,7 +184,7 @@ extern void transport_send_task_abort(struct se_cmd *);
 extern void transport_release_cmd_to_pool(struct se_cmd *);
 extern void transport_generic_free_cmd(struct se_cmd *, int, int, int);
 extern void transport_generic_wait_for_cmds(struct se_cmd *, int);
-extern u32 transport_calc_sg_num(struct se_task *, struct se_mem *, u32);
+extern int transport_init_task_sg(struct se_task *, struct se_mem *, u32);
 extern int transport_map_mem_to_sg(struct se_task *, struct list_head *,
 					void *, struct se_mem *,
 					struct se_mem **, u32 *, u32 *);
Signature · 1 line
1.7.6
#20 lore raw

PATCH 18/103 target: Remove struct se_global

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Much of what was in se_global was actually only used by one source file, so those variables could be taken out of se_global and made static in that file.

Removed unneeded g_ prefixes from variables affected.

Renamed struct list_heads that were there to be put on another list head from *_list to *_node, which helps to differentiate things a little better. from list_heads that are actually the heads of lists.

Rename init/release_se_global() to *_kmem_caches(), to reflect the changes.

---
 drivers/target/target_core_alua.c      |   60 +++++++++++++++++-------------
 drivers/target/target_core_configfs.c  |   63 ++++++++++++++++++--------------
 drivers/target/target_core_device.c    |   27 ++++++++------
 drivers/target/target_core_hba.c       |   19 ++++++----
 drivers/target/target_core_tpg.c       |   22 +++++++----
 drivers/target/target_core_transport.c |   40 +++------------------
 include/target/target_core_base.h      |   30 ++--------------
 include/target/target_core_transport.h |    6 +--
 8 files changed, 122 insertions(+), 145 deletions(-)
drivers/target/target_core_alua.c +34 -26
index a993f3c..62522d6 100644
@@ -46,6 +46,14 @@ static int core_alua_set_tg_pt_secondary_state(
 		struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem,
 		struct se_port *port, int explict, int offline);
 
+static u16 alua_lu_gps_counter;
+static u32 alua_lu_gps_count;
+
+static DEFINE_SPINLOCK(lu_gps_lock);
+static LIST_HEAD(lu_gps_list);
+
+struct t10_alua_lu_gp *default_lu_gp;
+
 /*
  * REPORT_TARGET_PORT_GROUPS
  *
@@ -1038,15 +1046,15 @@ core_alua_allocate_lu_gp(const char *name, int def_group)
 		printk(KERN_ERR "Unable to allocate struct t10_alua_lu_gp\n");
 		return ERR_PTR(-ENOMEM);
 	}
-	INIT_LIST_HEAD(&lu_gp->lu_gp_list);
+	INIT_LIST_HEAD(&lu_gp->lu_gp_node);
 	INIT_LIST_HEAD(&lu_gp->lu_gp_mem_list);
 	spin_lock_init(&lu_gp->lu_gp_lock);
 	atomic_set(&lu_gp->lu_gp_ref_cnt, 0);
 
 	if (def_group) {
-		lu_gp->lu_gp_id = se_global->alua_lu_gps_counter++;
+		lu_gp->lu_gp_id = alua_lu_gps_counter++;
 		lu_gp->lu_gp_valid_id = 1;
-		se_global->alua_lu_gps_count++;
+		alua_lu_gps_count++;
 	}
 
 	return lu_gp;
@@ -1065,19 +1073,19 @@ int core_alua_set_lu_gp_id(struct t10_alua_lu_gp *lu_gp, u16 lu_gp_id)
 		return -EINVAL;
 	}
 
-	spin_lock(&se_global->lu_gps_lock);
-	if (se_global->alua_lu_gps_count == 0x0000ffff) {
-		printk(KERN_ERR "Maximum ALUA se_global->alua_lu_gps_count:"
+	spin_lock(&lu_gps_lock);
+	if (alua_lu_gps_count == 0x0000ffff) {
+		printk(KERN_ERR "Maximum ALUA alua_lu_gps_count:"
 				" 0x0000ffff reached\n");
-		spin_unlock(&se_global->lu_gps_lock);
+		spin_unlock(&lu_gps_lock);
 		kmem_cache_free(t10_alua_lu_gp_cache, lu_gp);
 		return -ENOSPC;
 	}
 again:
 	lu_gp_id_tmp = (lu_gp_id != 0) ? lu_gp_id :
-				se_global->alua_lu_gps_counter++;
+				alua_lu_gps_counter++;
 
-	list_for_each_entry(lu_gp_tmp, &se_global->g_lu_gps_list, lu_gp_list) {
+	list_for_each_entry(lu_gp_tmp, &lu_gps_list, lu_gp_node) {
 		if (lu_gp_tmp->lu_gp_id == lu_gp_id_tmp) {
 			if (!(lu_gp_id))
 				goto again;
@@ -1085,16 +1093,16 @@ again:
 			printk(KERN_WARNING "ALUA Logical Unit Group ID: %hu"
 				" already exists, ignoring request\n",
 				lu_gp_id);
-			spin_unlock(&se_global->lu_gps_lock);
+			spin_unlock(&lu_gps_lock);
 			return -EINVAL;
 		}
 	}
 
 	lu_gp->lu_gp_id = lu_gp_id_tmp;
 	lu_gp->lu_gp_valid_id = 1;
-	list_add_tail(&lu_gp->lu_gp_list, &se_global->g_lu_gps_list);
-	se_global->alua_lu_gps_count++;
-	spin_unlock(&se_global->lu_gps_lock);
+	list_add_tail(&lu_gp->lu_gp_node, &lu_gps_list);
+	alua_lu_gps_count++;
+	spin_unlock(&lu_gps_lock);
 
 	return 0;
 }
@@ -1130,11 +1138,11 @@ void core_alua_free_lu_gp(struct t10_alua_lu_gp *lu_gp)
 	 * no associations can be made while we are releasing
 	 * struct t10_alua_lu_gp.
 	 */
-	spin_lock(&se_global->lu_gps_lock);
+	spin_lock(&lu_gps_lock);
 	atomic_set(&lu_gp->lu_gp_shutdown, 1);
-	list_del(&lu_gp->lu_gp_list);
-	se_global->alua_lu_gps_count--;
-	spin_unlock(&se_global->lu_gps_lock);
+	list_del(&lu_gp->lu_gp_node);
+	alua_lu_gps_count--;
+	spin_unlock(&lu_gps_lock);
 	/*
 	 * Allow struct t10_alua_lu_gp * referenced by core_alua_get_lu_gp_by_name()
 	 * in target_core_configfs.c:target_core_store_alua_lu_gp() to be
@@ -1165,9 +1173,9 @@ void core_alua_free_lu_gp(struct t10_alua_lu_gp *lu_gp)
 		 * we want to re-assocate a given lu_gp_mem with default_lu_gp.
 		 */
 		spin_lock(&lu_gp_mem->lu_gp_mem_lock);
-		if (lu_gp != se_global->default_lu_gp)
+		if (lu_gp != default_lu_gp)
 			__core_alua_attach_lu_gp_mem(lu_gp_mem,
-					se_global->default_lu_gp);
+					default_lu_gp);
 		else
 			lu_gp_mem->lu_gp = NULL;
 		spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
@@ -1218,27 +1226,27 @@ struct t10_alua_lu_gp *core_alua_get_lu_gp_by_name(const char *name)
 	struct t10_alua_lu_gp *lu_gp;
 	struct config_item *ci;
 
-	spin_lock(&se_global->lu_gps_lock);
-	list_for_each_entry(lu_gp, &se_global->g_lu_gps_list, lu_gp_list) {
+	spin_lock(&lu_gps_lock);
+	list_for_each_entry(lu_gp, &lu_gps_list, lu_gp_node) {
 		if (!(lu_gp->lu_gp_valid_id))
 			continue;
 		ci = &lu_gp->lu_gp_group.cg_item;
 		if (!(strcmp(config_item_name(ci), name))) {
 			atomic_inc(&lu_gp->lu_gp_ref_cnt);
-			spin_unlock(&se_global->lu_gps_lock);
+			spin_unlock(&lu_gps_lock);
 			return lu_gp;
 		}
 	}
-	spin_unlock(&se_global->lu_gps_lock);
+	spin_unlock(&lu_gps_lock);
 
 	return NULL;
 }
 
 void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp *lu_gp)
 {
-	spin_lock(&se_global->lu_gps_lock);
+	spin_lock(&lu_gps_lock);
 	atomic_dec(&lu_gp->lu_gp_ref_cnt);
-	spin_unlock(&se_global->lu_gps_lock);
+	spin_unlock(&lu_gps_lock);
 }
 
 /*
@@ -1974,7 +1982,7 @@ int core_setup_alua(struct se_device *dev, int force_pt)
 		alua->alua_state_check = &core_alua_state_check;
 		spin_lock(&lu_gp_mem->lu_gp_mem_lock);
 		__core_alua_attach_lu_gp_mem(lu_gp_mem,
-				se_global->default_lu_gp);
+				default_lu_gp);
 		spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
 
 		printk(KERN_INFO "%s: Adding to default ALUA LU Group:"
drivers/target/target_core_configfs.c +36 -27

186 lines not on this page · raw message

drivers/target/target_core_device.c +16 -11
index 4d8da32..c9a3f73 100644
@@ -54,6 +54,11 @@
 static void se_dev_start(struct se_device *dev);
 static void se_dev_stop(struct se_device *dev);
 
+static struct se_hba *lun0_hba;
+static struct se_subsystem_dev *lun0_su_dev;
+/* not static, needed by tpg.c */
+struct se_device *g_lun0_dev;
+
 int transport_get_lun_for_cmd(
 	struct se_cmd *se_cmd,
 	u32 unpacked_lun)
@@ -1579,7 +1584,7 @@ int core_dev_setup_virtual_lun0(void)
 	if (IS_ERR(hba))
 		return PTR_ERR(hba);
 
-	se_global->g_lun0_hba = hba;
+	lun0_hba = hba;
 	t = hba->transport;
 
 	se_dev = kzalloc(sizeof(struct se_subsystem_dev), GFP_KERNEL);
@@ -1612,7 +1617,7 @@ int core_dev_setup_virtual_lun0(void)
 		ret = -ENOMEM;
 		goto out;
 	}
-	se_global->g_lun0_su_dev = se_dev;
+	lun0_su_dev = se_dev;
 
 	memset(buf, 0, 16);
 	sprintf(buf, "rd_pages=8");
@@ -1624,15 +1629,15 @@ int core_dev_setup_virtual_lun0(void)
 		goto out;
 	}
 	se_dev->se_dev_ptr = dev;
-	se_global->g_lun0_dev = dev;
+	g_lun0_dev = dev;
 
 	return 0;
 out:
-	se_global->g_lun0_su_dev = NULL;
+	lun0_su_dev = NULL;
 	kfree(se_dev);
-	if (se_global->g_lun0_hba) {
-		core_delete_hba(se_global->g_lun0_hba);
-		se_global->g_lun0_hba = NULL;
+	if (lun0_hba) {
+		core_delete_hba(lun0_hba);
+		lun0_hba = NULL;
 	}
 	return ret;
 }
@@ -1640,14 +1645,14 @@ out:
 
 void core_dev_release_virtual_lun0(void)
 {
-	struct se_hba *hba = se_global->g_lun0_hba;
-	struct se_subsystem_dev *su_dev = se_global->g_lun0_su_dev;
+	struct se_hba *hba = lun0_hba;
+	struct se_subsystem_dev *su_dev = lun0_su_dev;
 
 	if (!(hba))
 		return;
 
-	if (se_global->g_lun0_dev)
-		se_free_virtual_device(se_global->g_lun0_dev, hba);
+	if (g_lun0_dev)
+		se_free_virtual_device(g_lun0_dev, hba);
 
 	kfree(su_dev);
 	core_delete_hba(hba);
drivers/target/target_core_hba.c +12 -7
index 8f3a0c4..bd9da25 100644
@@ -45,6 +45,11 @@
 static LIST_HEAD(subsystem_list);
 static DEFINE_MUTEX(subsystem_mutex);
 
+static u32 hba_id_counter;
+
+static DEFINE_SPINLOCK(hba_lock);
+static LIST_HEAD(hba_list);
+
 int transport_subsystem_register(struct se_subsystem_api *sub_api)
 {
 	struct se_subsystem_api *s;
@@ -125,10 +130,10 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags)
 	if (ret < 0)
 		goto out_module_put;
 
-	spin_lock(&se_global->hba_lock);
-	hba->hba_id = se_global->g_hba_id_counter++;
-	list_add_tail(&hba->hba_list, &se_global->g_hba_list);
-	spin_unlock(&se_global->hba_lock);
+	spin_lock(&hba_lock);
+	hba->hba_id = hba_id_counter++;
+	list_add_tail(&hba->hba_node, &hba_list);
+	spin_unlock(&hba_lock);
 
 	printk(KERN_INFO "CORE_HBA[%d] - Attached HBA to Generic Target"
 			" Core\n", hba->hba_id);
@@ -152,9 +157,9 @@ core_delete_hba(struct se_hba *hba)
 
 	hba->transport->detach_hba(hba);
 
-	spin_lock(&se_global->hba_lock);
-	list_del(&hba->hba_list);
-	spin_unlock(&se_global->hba_lock);
+	spin_lock(&hba_lock);
+	list_del(&hba->hba_node);
+	spin_unlock(&hba_lock);
 
 	printk(KERN_INFO "CORE_HBA[%d] - Detached HBA from Generic Target"
 			" Core\n", hba->hba_id);
drivers/target/target_core_tpg.c +14 -8
index dc024c1..4e2bee9 100644
@@ -44,6 +44,12 @@
 #include <target/target_core_fabric_ops.h>
 
 #include "target_core_hba.h"
+#include "target_core_stat.h"
+
+extern struct se_device *g_lun0_dev;
+
+static DEFINE_SPINLOCK(tpg_lock);
+static LIST_HEAD(tpg_list);
 
 /*	core_clear_initiator_node_from_tpg():
  *
@@ -597,7 +603,7 @@ EXPORT_SYMBOL(core_tpg_set_initiator_node_queue_depth);
 static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg)
 {
 	/* Set in core_dev_setup_virtual_lun0() */
-	struct se_device *dev = se_global->g_lun0_dev;
+	struct se_device *dev = g_lun0_dev;
 	struct se_lun *lun = &se_tpg->tpg_virt_lun0;
 	u32 lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
 	int ret;
@@ -663,7 +669,7 @@ int core_tpg_register(
 	se_tpg->se_tpg_wwn = se_wwn;
 	atomic_set(&se_tpg->tpg_pr_ref_count, 0);
 	INIT_LIST_HEAD(&se_tpg->acl_node_list);
-	INIT_LIST_HEAD(&se_tpg->se_tpg_list);
+	INIT_LIST_HEAD(&se_tpg->se_tpg_node);
 	INIT_LIST_HEAD(&se_tpg->tpg_sess_list);
 	spin_lock_init(&se_tpg->acl_node_lock);
 	spin_lock_init(&se_tpg->session_lock);
@@ -676,9 +682,9 @@ int core_tpg_register(
 		}
 	}
 
-	spin_lock_bh(&se_global->se_tpg_lock);
-	list_add_tail(&se_tpg->se_tpg_list, &se_global->g_se_tpg_list);
-	spin_unlock_bh(&se_global->se_tpg_lock);
+	spin_lock_bh(&tpg_lock);
+	list_add_tail(&se_tpg->se_tpg_node, &tpg_list);
+	spin_unlock_bh(&tpg_lock);
 
 	printk(KERN_INFO "TARGET_CORE[%s]: Allocated %s struct se_portal_group for"
 		" endpoint: %s, Portal Tag: %u\n", tfo->get_fabric_name(),
@@ -701,9 +707,9 @@ int core_tpg_deregister(struct se_portal_group *se_tpg)
 		TPG_TFO(se_tpg)->tpg_get_wwn(se_tpg),
 		TPG_TFO(se_tpg)->tpg_get_tag(se_tpg));
 
-	spin_lock_bh(&se_global->se_tpg_lock);
-	list_del(&se_tpg->se_tpg_list);
-	spin_unlock_bh(&se_global->se_tpg_lock);
+	spin_lock_bh(&tpg_lock);
+	list_del(&se_tpg->se_tpg_node);
+	spin_unlock_bh(&tpg_lock);
 
 	while (atomic_read(&se_tpg->tpg_pr_ref_count) != 0)
 		cpu_relax();
drivers/target/target_core_transport.c +5 -35
index 56249cf..0f084a1 100644
@@ -184,7 +184,7 @@
 #define DEBUG_STA(x...)
 #endif
 
-struct se_global *se_global;
+static int sub_api_initialized;
 
 static struct kmem_cache *se_cmd_cache;
 static struct kmem_cache *se_sess_cache;
@@ -227,26 +227,8 @@ static void transport_remove_cmd_from_queue(struct se_cmd *cmd,
 static int transport_set_sense_codes(struct se_cmd *cmd, u8 asc, u8 ascq);
 static void transport_stop_all_task_timers(struct se_cmd *cmd);
 
-int init_se_global(void)
+int init_se_kmem_caches(void)
 {
-	struct se_global *global;
-
-	global = kzalloc(sizeof(struct se_global), GFP_KERNEL);
-	if (!(global)) {
-		printk(KERN_ERR "Unable to allocate memory for struct se_global\n");
-		return -ENOMEM;
-	}
-
-	INIT_LIST_HEAD(&global->g_lu_gps_list);
-	INIT_LIST_HEAD(&global->g_se_tpg_list);
-	INIT_LIST_HEAD(&global->g_hba_list);
-	INIT_LIST_HEAD(&global->g_se_dev_list);
-	spin_lock_init(&global->g_device_lock);
-	spin_lock_init(&global->hba_lock);
-	spin_lock_init(&global->se_tpg_lock);
-	spin_lock_init(&global->lu_gps_lock);
-	spin_lock_init(&global->plugin_class_lock);
-
 	se_cmd_cache = kmem_cache_create("se_cmd_cache",
 			sizeof(struct se_cmd), __alignof__(struct se_cmd), 0, NULL);
 	if (!(se_cmd_cache)) {
@@ -325,8 +307,6 @@ int init_se_global(void)
 		goto out;
 	}
 
-	se_global = global;
-
 	return 0;
 out:
 	if (se_cmd_cache)
@@ -349,18 +329,11 @@ out:
 		kmem_cache_destroy(t10_alua_tg_pt_gp_cache);
 	if (t10_alua_tg_pt_gp_mem_cache)
 		kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache);
-	kfree(global);
 	return -ENOMEM;
 }
 
-void release_se_global(void)
+void release_se_kmem_caches(void)
 {
-	struct se_global *global;
-
-	global = se_global;
-	if (!(global))
-		return;
-
 	kmem_cache_destroy(se_cmd_cache);
 	kmem_cache_destroy(se_tmr_req_cache);
 	kmem_cache_destroy(se_sess_cache);
@@ -371,9 +344,6 @@ void release_se_global(void)
 	kmem_cache_destroy(t10_alua_lu_gp_mem_cache);
 	kmem_cache_destroy(t10_alua_tg_pt_gp_cache);
 	kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache);
-	kfree(global);
-
-	se_global = NULL;
 }
 
 /* SCSI statistics table index */
@@ -446,7 +416,7 @@ int transport_subsystem_check_init(void)
 {
 	int ret;
 
-	if (se_global->g_sub_api_initialized)
+	if (sub_api_initialized)
 		return 0;
 	/*
 	 * Request the loading of known TCM subsystem plugins..
@@ -455,7 +425,7 @@ int transport_subsystem_check_init(void)
 	if (ret < 0)
 		return ret;
 
-	se_global->g_sub_api_initialized = 1;
+	sub_api_initialized = 1;
 	return 0;
 }
 
include/target/target_core_base.h +3 -27
index 8467a8d..de7bec6 100644
@@ -235,7 +235,7 @@ struct t10_alua_lu_gp {
 	atomic_t lu_gp_ref_cnt;
 	spinlock_t lu_gp_lock;
 	struct config_group lu_gp_group;
-	struct list_head lu_gp_list;
+	struct list_head lu_gp_node;
 	struct list_head lu_gp_mem_list;
 } ____cacheline_aligned;
 
@@ -840,7 +840,7 @@ struct se_hba {
 	void			*hba_ptr;
 	/* Linked list for struct se_device */
 	struct list_head	hba_dev_list;
-	struct list_head	hba_list;
+	struct list_head	hba_node;
 	spinlock_t		device_lock;
 	struct config_group	hba_group;
 	struct mutex		hba_access_mutex;
@@ -924,7 +924,7 @@ struct se_portal_group {
 	spinlock_t		tpg_lun_lock;
 	/* Pointer to $FABRIC_MOD portal group */
 	void			*se_tpg_fabric_ptr;
-	struct list_head	se_tpg_list;
+	struct list_head	se_tpg_node;
 	/* linked list for initiator ACL list */
 	struct list_head	acl_node_list;
 	struct se_lun		*tpg_lun_list;
@@ -952,28 +952,4 @@ struct se_wwn {
 	struct config_group	fabric_stat_group;
 } ____cacheline_aligned;
 
-struct se_global {
-	u16			alua_lu_gps_counter;
-	int			g_sub_api_initialized;
-	u32			in_shutdown;
-	u32			alua_lu_gps_count;
-	u32			g_hba_id_counter;
-	struct config_group	target_core_hbagroup;
-	struct config_group	alua_group;
-	struct config_group	alua_lu_gps_group;
-	struct list_head	g_lu_gps_list;
-	struct list_head	g_se_tpg_list;
-	struct list_head	g_hba_list;
-	struct list_head	g_se_dev_list;
-	struct se_hba		*g_lun0_hba;
-	struct se_subsystem_dev *g_lun0_su_dev;
-	struct se_device	*g_lun0_dev;
-	struct t10_alua_lu_gp	*default_lu_gp;
-	spinlock_t		g_device_lock;
-	spinlock_t		hba_lock;
-	spinlock_t		se_tpg_lock;
-	spinlock_t		lu_gps_lock;
-	spinlock_t		plugin_class_lock;
-} ____cacheline_aligned;
-
 #endif /* TARGET_CORE_BASE_H */
include/target/target_core_transport.h +2 -4
index 199a404..06b8900 100644
@@ -111,8 +111,8 @@ struct se_subsystem_api;
 
 extern struct kmem_cache *se_mem_cache;
 
-extern int init_se_global(void);
-extern void release_se_global(void);
+extern int init_se_kmem_caches(void);
+extern void release_se_kmem_caches(void);
 extern void init_scsi_index_table(void);
 extern u32 scsi_get_new_index(scsi_index_t);
 extern void transport_init_queue_obj(struct se_queue_obj *);
@@ -355,6 +355,4 @@ struct se_subsystem_api {
 #define TRANSPORT(dev)		((dev)->transport)
 #define HBA_TRANSPORT(hba)	((hba)->transport)
 
-extern struct se_global *se_global;
-
 #endif /* TARGET_CORE_TRANSPORT_H */
Signature · 1 line
1.7.6
#27 lore raw

PATCH 20/103 target: Make dev_queue_obj a member of se_device instead of a pointer

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

This saves us having to alloc/free memory for it separately from se_device.

---
 drivers/target/target_core_device.c    |    1 -
 drivers/target/target_core_tmr.c       |    2 +-
 drivers/target/target_core_transport.c |   52 +++++++++++++------------------
 include/target/target_core_base.h      |    2 +-
 4 files changed, 24 insertions(+), 33 deletions(-)
drivers/target/target_core_device.c +0 -1
index c9a3f73..fe5474c 100644
@@ -760,7 +760,6 @@ void se_release_device_for_hba(struct se_device *dev)
 	core_scsi3_free_all_registrations(dev);
 	se_release_vpd_for_dev(dev);
 
-	kfree(dev->dev_queue_obj);
 	kfree(dev);
 
 	return;
drivers/target/target_core_tmr.c +1 -1
index 179063d..7cd8e29 100644
@@ -117,7 +117,7 @@ int core_tmr_lun_reset(
 	struct se_queue_req *qr, *qr_tmp;
 	struct se_node_acl *tmr_nacl = NULL;
 	struct se_portal_group *tmr_tpg = NULL;
-	struct se_queue_obj *qobj = dev->dev_queue_obj;
+	struct se_queue_obj *qobj = &dev->dev_queue_obj;
 	struct se_tmr_req *tmr_p, *tmr_pp;
 	struct se_task *task, *task_tmp;
 	unsigned long flags;
drivers/target/target_core_transport.c +22 -30

174 lines not on this page · raw message

include/target/target_core_base.h +1 -1
index 23dd6b7..112eb38 100644
@@ -778,7 +778,7 @@ struct se_device {
 	struct se_obj		dev_obj;
 	struct se_obj		dev_access_obj;
 	struct se_obj		dev_export_obj;
-	struct se_queue_obj	*dev_queue_obj;
+	struct se_queue_obj	dev_queue_obj;
 	spinlock_t		delayed_cmd_lock;
 	spinlock_t		ordered_cmd_lock;
 	spinlock_t		execute_task_lock;
Signature · 1 line
1.7.6
#13 lore raw

PATCH 11/103 target: Make two runtime checks into WARN_ONs

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

The params are checked in the calling functions, so these ones in transport_get_sense_data and transport_map_sg_to_mem should be unnecessary, unless calling code becomes buggy.

---
 drivers/target/target_core_transport.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
drivers/target/target_core_transport.c +4 -8
index edf24b4..99b9e33 100644
@@ -2997,10 +2997,8 @@ static int transport_get_sense_data(struct se_cmd *cmd)
 	unsigned long flags;
 	u32 offset = 0;
 
-	if (!SE_LUN(cmd)) {
-		printk(KERN_ERR "SE_LUN(cmd) is NULL\n");
-		return -1;
-	}
+	WARN_ON(!SE_LUN(cmd));
+
 	spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
 	if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) {
 		spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
@@ -4595,10 +4593,8 @@ static int transport_map_sg_to_mem(
 	struct scatterlist *sg;
 	u32 sg_count = 1, cmd_size = cmd->data_length;
 
-	if (!in_mem) {
-		printk(KERN_ERR "No source scatterlist\n");
-		return -1;
-	}
+	WARN_ON(!in_mem);
+
 	sg = (struct scatterlist *)in_mem;
 
 	while (cmd_size) {
Signature · 1 line
1.7.6
#4 lore raw

PATCH 4/103 target: Remove unnecessary *cdb transport_get_lun_for_cmd parameter

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch removes the now unnecessary 'unsigned char *cdb' function parameter from transport_get_lun_for_cmd(). This also includes updating lio-target, tcm_loop and tcm_fc usage of transport_get_lun_for_cmd().

---
 drivers/target/loopback/tcm_loop.c  |    2 +-
 drivers/target/target_core_device.c |    1 -
 drivers/target/tcm_fc/tfc_cmd.c     |    2 +-
 include/target/target_core_device.h |    2 +-
 4 files changed, 3 insertions(+), 4 deletions(-)
drivers/target/loopback/tcm_loop.c +1 -1
index 70c2e7f..2d0f22a 100644
@@ -122,7 +122,7 @@ static struct se_cmd *tcm_loop_allocate_core_cmd(
 	/*
 	 * Locate the struct se_lun pointer and attach it to struct se_cmd
 	 */
-	if (transport_get_lun_for_cmd(se_cmd, NULL, tl_cmd->sc->device->lun) < 0) {
+	if (transport_get_lun_for_cmd(se_cmd, tl_cmd->sc->device->lun) < 0) {
 		kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
 		set_host_byte(sc, DID_NO_CONNECT);
 		return NULL;
drivers/target/target_core_device.c +0 -1
index 1b5d78f..b0ebe9a 100644
@@ -56,7 +56,6 @@ static void se_dev_stop(struct se_device *dev);
 
 int transport_get_lun_for_cmd(
 	struct se_cmd *se_cmd,
-	unsigned char *cdb,
 	u32 unpacked_lun)
 {
 	struct se_dev_entry *deve;
drivers/target/tcm_fc/tfc_cmd.c +1 -1
index b2a1067..92a449a 100644
@@ -637,7 +637,7 @@ static void ft_send_cmd(struct ft_cmd *cmd)
 	fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd);
 
 	cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
-	ret = transport_get_lun_for_cmd(&cmd->se_cmd, NULL, cmd->lun);
+	ret = transport_get_lun_for_cmd(&cmd->se_cmd, cmd->lun);
 	if (ret < 0) {
 		ft_dump_cmd(cmd, __func__);
 		transport_send_check_condition_and_sense(&cmd->se_cmd,
include/target/target_core_device.h +1 -1
index 52b18a5..d9745bf 100644
@@ -1,7 +1,7 @@
 #ifndef TARGET_CORE_DEVICE_H
 #define TARGET_CORE_DEVICE_H
 
-extern int transport_get_lun_for_cmd(struct se_cmd *, unsigned char *, u32);
+extern int transport_get_lun_for_cmd(struct se_cmd *, u32);
 extern int transport_get_lun_for_tmr(struct se_cmd *, u32);
 extern struct se_dev_entry *core_get_se_deve_from_rtpi(
 					struct se_node_acl *, u16);
Signature · 1 line
1.7.6
#19 lore raw

PATCH 17/103 target: Rename se_dev->g_se_dev_list to se_dev_node

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

The g_ annotation might lead one to believe this is a global variable, when it is per-subsystem. Calling it se_dev_node also connotes the member is for being put on a list, and it is not the head of a list itself.

---
 drivers/target/target_core_configfs.c |    6 +++---
 drivers/target/target_core_device.c   |    2 +-
 include/target/target_core_base.h     |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/target/target_core_configfs.c +3 -3
index d140258..03cda0e 100644
@@ -2748,7 +2748,7 @@ static struct config_group *target_core_make_subdev(
 				" struct se_subsystem_dev\n");
 		goto unlock;
 	}
-	INIT_LIST_HEAD(&se_dev->g_se_dev_list);
+	INIT_LIST_HEAD(&se_dev->se_dev_node);
 	INIT_LIST_HEAD(&se_dev->t10_wwn.t10_vpd_list);
 	spin_lock_init(&se_dev->t10_wwn.t10_vpd_lock);
 	INIT_LIST_HEAD(&se_dev->t10_reservation.registration_list);
@@ -2785,7 +2785,7 @@ static struct config_group *target_core_make_subdev(
 		goto out;
 	}
 	spin_lock(&se_global->g_device_lock);
-	list_add_tail(&se_dev->g_se_dev_list, &se_global->g_se_dev_list);
+	list_add_tail(&se_dev->se_dev_node, &se_global->g_se_dev_list);
 	spin_unlock(&se_global->g_device_lock);
 
 	config_group_init_type_name(&se_dev->se_dev_group, name,
@@ -2882,7 +2882,7 @@ static void target_core_drop_subdev(
 	t = hba->transport;
 
 	spin_lock(&se_global->g_device_lock);
-	list_del(&se_dev->g_se_dev_list);
+	list_del(&se_dev->se_dev_node);
 	spin_unlock(&se_global->g_device_lock);
 
 	dev_stat_grp = &DEV_STAT_GRP(se_dev)->stat_group;
drivers/target/target_core_device.c +1 -1
index f03e0cc..4d8da32 100644
@@ -1589,7 +1589,7 @@ int core_dev_setup_virtual_lun0(void)
 		ret = -ENOMEM;
 		goto out;
 	}
-	INIT_LIST_HEAD(&se_dev->g_se_dev_list);
+	INIT_LIST_HEAD(&se_dev->se_dev_node);
 	INIT_LIST_HEAD(&se_dev->t10_wwn.t10_vpd_list);
 	spin_lock_init(&se_dev->t10_wwn.t10_vpd_lock);
 	INIT_LIST_HEAD(&se_dev->t10_reservation.registration_list);
include/target/target_core_base.h +1 -1
index e35338d..8467a8d 100644
@@ -730,7 +730,7 @@ struct se_subsystem_dev {
 	struct t10_reservation_template t10_reservation;
 	spinlock_t      se_dev_lock;
 	void            *se_dev_su_ptr;
-	struct list_head g_se_dev_list;
+	struct list_head se_dev_node;
 	struct config_group se_dev_group;
 	/* For T10 Reservations */
 	struct config_group se_dev_pr_group;
Signature · 1 line
1.7.6
#34 lore raw

PATCH 27/103 target: Remove #defines that just perform indirection

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Generally, the kernel style prefers to use such macros for longer conversions, container_of, that sort of thing. If it's just to refer to a member variable, then for clarity it can just be used directly.

Usually the length difference is small, but one macro does shorten a struct member name: se_subsystem_dev.t10_reservation. We shorten t10_reservation member name (but not type) to t10_pr.

Finally, there are some bare numbers in _stat.c that this patch fixes by using sizeof(), and we also remove extraneous memcpy()s.

Finally, make string fields in struct t10_wwn chars, to cut down on casting.

---
 drivers/target/loopback/tcm_loop.c           |    4 +-
 drivers/target/target_core_alua.c            |  138 ++--
 drivers/target/target_core_cdb.c             |  134 ++--
 drivers/target/target_core_configfs.c        |   79 +-
 drivers/target/target_core_device.c          |  297 ++++----
 drivers/target/target_core_fabric_configfs.c |   12 +-
 drivers/target/target_core_file.c            |   24 +-
 drivers/target/target_core_iblock.c          |   42 +-
 drivers/target/target_core_pr.c              |  328 ++++----
 drivers/target/target_core_pscsi.c           |   19 +-
 drivers/target/target_core_rd.c              |   28 +-
 drivers/target/target_core_stat.c            |  112 ++--
 drivers/target/target_core_tmr.c             |   82 +-
 drivers/target/target_core_tpg.c             |  106 ++--
 drivers/target/target_core_transport.c       | 1196 +++++++++++++-------------
 drivers/target/target_core_ua.c              |   16 +-
 drivers/target/tcm_fc/tfc_cmd.c              |    6 +-
 drivers/target/tcm_fc/tfc_io.c               |    4 +-
 include/target/target_core_base.h            |   38 +-
 include/target/target_core_transport.h       |    3 -
 20 files changed, 1318 insertions(+), 1350 deletions(-)
drivers/target/loopback/tcm_loop.c +2 -2
index 26e3681..1f1695a 100644
@@ -118,7 +118,7 @@ static struct se_cmd *tcm_loop_allocate_core_cmd(
 	 * Signal BIDI usage with T_TASK(cmd)->t_tasks_bidi
 	 */
 	if (scsi_bidi_cmnd(sc))
-		T_TASK(se_cmd)->t_tasks_bidi = 1;
+		se_cmd->t_task->t_tasks_bidi = 1;
 	/*
 	 * Locate the struct se_lun pointer and attach it to struct se_cmd
 	 */
@@ -176,7 +176,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
 		 * For BIDI commands, pass in the extra READ buffer
 		 * to transport_generic_map_mem_to_cmd() below..
 		 */
-		if (T_TASK(se_cmd)->t_tasks_bidi) {
+		if (se_cmd->t_task->t_tasks_bidi) {
 			struct scsi_data_buffer *sdb = scsi_in(sc);
 
 			mem_bidi_ptr = (void *)sdb->table.sgl;
drivers/target/target_core_alua.c +69 -69

374 lines not on this page · raw message

drivers/target/target_core_cdb.c +67 -67

416 lines not on this page · raw message

drivers/target/target_core_configfs.c +40 -39

250 lines not on this page · raw message

drivers/target/target_core_device.c +149 -148

737 lines not on this page · raw message

drivers/target/target_core_fabric_configfs.c +6 -6
index 07ab5a3..0b1659d 100644
@@ -118,7 +118,7 @@ static int target_fabric_mappedlun_link(
 		lun_access = deve->lun_flags;
 	else
 		lun_access =
-			(TPG_TFO(se_tpg)->tpg_check_prod_mode_write_protect(
+			(se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect(
 				se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY :
 					   TRANSPORT_LUNFLAGS_READ_WRITE;
 	spin_unlock_irq(&lacl->se_lun_nacl->device_list_lock);
@@ -204,7 +204,7 @@ static ssize_t target_fabric_mappedlun_store_write_protect(
 
 	printk(KERN_INFO "%s_ConfigFS: Changed Initiator ACL: %s"
 		" Mapped LUN: %u Write Protect bit to %s\n",
-		TPG_TFO(se_tpg)->get_fabric_name(),
+		se_tpg->se_tpg_tfo->get_fabric_name(),
 		lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF");
 
 	return count;
@@ -379,7 +379,7 @@ static struct config_group *target_fabric_make_mappedlun(
 	lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group;
 	lacl_cg->default_groups[1] = NULL;
 
-	ml_stat_grp = &ML_STAT_GRPS(lacl)->stat_group;
+	ml_stat_grp = &lacl->ml_stat_grps.stat_group;
 	ml_stat_grp->default_groups = kzalloc(sizeof(struct config_group) * 3,
 				GFP_KERNEL);
 	if (!ml_stat_grp->default_groups) {
@@ -408,7 +408,7 @@ static void target_fabric_drop_mappedlun(
 	struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
 	int i;
 
-	ml_stat_grp = &ML_STAT_GRPS(lacl)->stat_group;
+	ml_stat_grp = &lacl->ml_stat_grps.stat_group;
 	for (i = 0; ml_stat_grp->default_groups[i]; i++) {
 		df_item = &ml_stat_grp->default_groups[i]->cg_item;
 		ml_stat_grp->default_groups[i] = NULL;
@@ -914,7 +914,7 @@ static struct config_group *target_fabric_make_lun(
 	lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group;
 	lun_cg->default_groups[1] = NULL;
 
-	port_stat_grp = &PORT_STAT_GRP(lun)->stat_group;
+	port_stat_grp = &lun->port_stat_grps.stat_group;
 	port_stat_grp->default_groups =  kzalloc(sizeof(struct config_group) * 3,
 				GFP_KERNEL);
 	if (!port_stat_grp->default_groups) {
@@ -941,7 +941,7 @@ static void target_fabric_drop_lun(
 	struct config_group *lun_cg, *port_stat_grp;
 	int i;
 
-	port_stat_grp = &PORT_STAT_GRP(lun)->stat_group;
+	port_stat_grp = &lun->port_stat_grps.stat_group;
 	for (i = 0; port_stat_grp->default_groups[i]; i++) {
 		df_item = &port_stat_grp->default_groups[i]->cg_item;
 		port_stat_grp->default_groups[i] = NULL;
drivers/target/target_core_file.c +13 -11
index 5ca1f5b..0c44bc0 100644
@@ -72,7 +72,7 @@ static int fd_attach_hba(struct se_hba *hba, u32 host_id)
 
 	fd_host->fd_host_id = host_id;
 
-	hba->hba_ptr = (void *) fd_host;
+	hba->hba_ptr = fd_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM FILEIO HBA Driver %s on Generic"
 		" Target Core Stack %s\n", hba->hba_id, FD_VERSION,
@@ -279,7 +279,7 @@ fd_alloc_task(struct se_cmd *cmd)
 		return NULL;
 	}
 
-	fd_req->fd_dev = SE_DEV(cmd)->dev_ptr;
+	fd_req->fd_dev = cmd->se_lun->lun_se_dev->dev_ptr;
 
 	return &fd_req->fd_task;
 }
@@ -291,7 +291,8 @@ static int fd_do_readv(struct se_task *task)
 	struct scatterlist *sg = task->task_sg;
 	struct iovec *iov;
 	mm_segment_t old_fs;
-	loff_t pos = (task->task_lba * DEV_ATTRIB(task->se_dev)->block_size);
+	loff_t pos = (task->task_lba *
+		      task->se_dev->se_sub_dev->se_dev_attrib.block_size);
 	int ret = 0, i;
 
 	iov = kzalloc(sizeof(struct iovec) * task->task_sg_num, GFP_KERNEL);
@@ -341,7 +342,8 @@ static int fd_do_writev(struct se_task *task)
 	struct scatterlist *sg = task->task_sg;
 	struct iovec *iov;
 	mm_segment_t old_fs;
-	loff_t pos = (task->task_lba * DEV_ATTRIB(task->se_dev)->block_size);
+	loff_t pos = (task->task_lba *
+		      task->se_dev->se_sub_dev->se_dev_attrib.block_size);
 	int ret, i = 0;
 
 	iov = kzalloc(sizeof(struct iovec) * task->task_sg_num, GFP_KERNEL);
@@ -372,7 +374,7 @@ static int fd_do_writev(struct se_task *task)
 
 static void fd_emulate_sync_cache(struct se_task *task)
 {
-	struct se_cmd *cmd = TASK_CMD(task);
+	struct se_cmd *cmd = task->task_se_cmd;
 	struct se_device *dev = cmd->se_dev;
 	struct fd_dev *fd_dev = dev->dev_ptr;
 	int immed = (cmd->t_task->t_task_cdb[1] & 0x2);
@@ -393,7 +395,7 @@ static void fd_emulate_sync_cache(struct se_task *task)
 		start = 0;
 		end = LLONG_MAX;
 	} else {
-		start = cmd->t_task->t_task_lba * DEV_ATTRIB(dev)->block_size;
+		start = cmd->t_task->t_task_lba * dev->se_sub_dev->se_dev_attrib.block_size;
 		if (cmd->data_length)
 			end = start + cmd->data_length;
 		else
@@ -443,7 +445,7 @@ static void fd_emulate_write_fua(struct se_cmd *cmd, struct se_task *task)
 {
 	struct se_device *dev = cmd->se_dev;
 	struct fd_dev *fd_dev = dev->dev_ptr;
-	loff_t start = task->task_lba * DEV_ATTRIB(dev)->block_size;
+	loff_t start = task->task_lba * dev->se_sub_dev->se_dev_attrib.block_size;
 	loff_t end = start + task->task_size;
 	int ret;
 
@@ -471,9 +473,9 @@ static int fd_do_task(struct se_task *task)
 		ret = fd_do_writev(task);
 
 		if (ret > 0 &&
-		    DEV_ATTRIB(dev)->emulate_write_cache > 0 &&
-		    DEV_ATTRIB(dev)->emulate_fua_write > 0 &&
-		    T_TASK(cmd)->t_tasks_fua) {
+		    dev->se_sub_dev->se_dev_attrib.emulate_write_cache > 0 &&
+		    dev->se_sub_dev->se_dev_attrib.emulate_fua_write > 0 &&
+		    cmd->t_task->t_tasks_fua) {
 			/*
 			 * We might need to be a bit smarter here
 			 * and return some sense data to let the initiator
@@ -651,7 +653,7 @@ static sector_t fd_get_blocks(struct se_device *dev)
 {
 	struct fd_dev *fd_dev = dev->dev_ptr;
 	unsigned long long blocks_long = div_u64(fd_dev->fd_dev_size,
-			DEV_ATTRIB(dev)->block_size);
+			dev->se_sub_dev->se_dev_attrib.block_size);
 
 	return blocks_long;
 }
drivers/target/target_core_iblock.c +21 -21

118 lines not on this page · raw message

drivers/target/target_core_pr.c +164 -164

963 lines not on this page · raw message

drivers/target/target_core_pscsi.c +9 -10
index afe5f57..44a79a5 100644

Lines of this file are not shown. View the raw message.

drivers/target/target_core_rd.c +13 -15
index 0a424bb..fbf06c3 100644

Lines of this file are not shown. View the raw message.

drivers/target/target_core_stat.c +55 -57

112 lines not on this page · raw message

drivers/target/target_core_tmr.c +41 -41

82 lines not on this page · raw message

drivers/target/target_core_tpg.c +53 -53

106 lines not on this page · raw message

drivers/target/target_core_transport.c +598 -598

1,196 lines not on this page · raw message

drivers/target/target_core_ua.c +8 -8
index 4f754ca..16f41d1 100644

Lines of this file are not shown. View the raw message.

drivers/target/tcm_fc/tfc_cmd.c +3 -3
index 5823ccf..19b2b99 100644

Lines of this file are not shown. View the raw message.

drivers/target/tcm_fc/tfc_io.c +2 -2
index 8c4a240..47efcfb 100644

Lines of this file are not shown. View the raw message.

include/target/target_core_base.h +5 -33
index 2b989b3..b0b83ed 100644

Lines of this file are not shown. View the raw message.

include/target/target_core_transport.h +0 -3
index da982e9..1dd4d18 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.6

Part of the diff is not shown here. View the raw message.

#31 lore raw

PATCH 24/103 target: Fix comment in __transport_execute_tasks()

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

cmd->transport_emulate_cdb is used for a variety of purposes beyond REPORT_LUNS currently, so update the comment explaining its use to reflect this.

---
 drivers/target/target_core_transport.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/target/target_core_transport.c +1 -1
index acb5ef7..a224010 100644
@@ -2576,7 +2576,7 @@ check_depth:
 	spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
 	/*
 	 * The struct se_cmd->transport_emulate_cdb() function pointer is used
-	 * to grab REPORT_LUNS CDBs before they hit the
+	 * to grab REPORT_LUNS and other CDBs we want to handle before they hit the
 	 * struct se_subsystem_api->do_task() caller below.
 	 */
 	if (cmd->transport_emulate_cdb) {
Signature · 1 line
1.7.6
#11 lore raw

PATCH 9/103 target: Fix leak in error path in transport_init_task_sg

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

If the function fails to allocate mem for task_sg_bidi, it would return with an error, and the task_sg would be allocated but only partially initialized. This patch frees the task_sg in that scenario.

---
 drivers/target/target_core_transport.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/target/target_core_transport.c +2 -0
index bae584d..edf24b4 100644
@@ -4499,6 +4499,8 @@ next:
 		task->task_sg_bidi = kzalloc(task_sg_num_padded *
 				sizeof(struct scatterlist), GFP_KERNEL);
 		if (!(task->task_sg_bidi)) {
+			kfree(task->task_sg);
+			task->task_sg = NULL;
 			printk(KERN_ERR "Unable to allocate memory for"
 				" task->task_sg_bidi\n");
 			return -ENOMEM;
Signature · 1 line
1.7.6
#33 lore raw

PATCH 26/103 target: rename struct pr_reservation_template to pr_reservation

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

"_template" in the name doesn't seem (to me) to be worth the added verbosity.

---
 drivers/target/target_core_pr.c   |    4 ++--
 drivers/target/target_core_pr.h   |    2 +-
 include/target/target_core_base.h |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/target/target_core_pr.c +2 -2
index 99b97db..2ddbe0d 100644
@@ -4019,7 +4019,7 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
 	struct se_subsystem_dev *su_dev = SU_DEV(se_dev);
 	struct se_portal_group *se_tpg;
 	struct t10_pr_registration *pr_reg, *pr_reg_tmp;
-	struct t10_reservation_template *pr_tmpl = &SU_DEV(se_dev)->t10_reservation;
+	struct t10_reservation *pr_tmpl = &SU_DEV(se_dev)->t10_reservation;
 	unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf;
 	u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len;
 	u32 off = 8; /* off into first Full Status descriptor */
@@ -4213,7 +4213,7 @@ static int core_pt_seq_non_holder(
 int core_setup_reservations(struct se_device *dev, int force_pt)
 {
 	struct se_subsystem_dev *su_dev = dev->se_sub_dev;
-	struct t10_reservation_template *rest = &su_dev->t10_reservation;
+	struct t10_reservation *rest = &su_dev->t10_reservation;
 	/*
 	 * If this device is from Target_Core_Mod/pSCSI, use the reservations
 	 * of the Underlying SCSI hardware.  In Linux/SCSI terms, this can
drivers/target/target_core_pr.h +1 -1
index 5603bcf..c8f47d0 100644
@@ -49,7 +49,7 @@ extern int core_pr_dump_initiator_port(struct t10_pr_registration *,
 			char *, u32);
 extern int core_scsi2_emulate_crh(struct se_cmd *);
 extern int core_scsi3_alloc_aptpl_registration(
-			struct t10_reservation_template *, u64,
+			struct t10_reservation *, u64,
 			unsigned char *, unsigned char *, u32,
 			unsigned char *, u16, u32, int, int, u8);
 extern int core_scsi3_check_aptpl_registration(struct se_device *,
include/target/target_core_base.h +3 -3
index 112eb38..2b989b3 100644
@@ -361,13 +361,13 @@ struct t10_reservation_ops {
 	int (*t10_pr_clear)(struct se_cmd *);
 };
 
-struct t10_reservation_template {
+struct t10_reservation {
 	/* Reservation effects all target ports */
 	int pr_all_tg_pt;
 	/* Activate Persistence across Target Power Loss enabled
 	 * for SCSI device */
 	int pr_aptpl_active;
-	/* Used by struct t10_reservation_template->pr_aptpl_buf_len */
+	/* Used by struct t10_reservation->pr_aptpl_buf_len */
 #define PR_APTPL_BUF_LEN			8192
 	u32 pr_aptpl_buf_len;
 	u32 pr_generation;
@@ -722,7 +722,7 @@ struct se_subsystem_dev {
 	/* T10 Inquiry and VPD WWN Information */
 	struct t10_wwn	t10_wwn;
 	/* T10 SPC-2 + SPC-3 Reservations */
-	struct t10_reservation_template t10_reservation;
+	struct t10_reservation t10_reservation;
 	spinlock_t      se_dev_lock;
 	void            *se_dev_su_ptr;
 	struct list_head se_dev_node;
Signature · 1 line
1.7.6
#1 lore raw

PATCH 1/103 target: Check LUN numbers in transport_get_lun_for_[cmd,tmr]

In reply to Nicholas A. Bellinger

From: Fubo Chen <[email protected]>

This patch checks the passed 'unpacked_lun' against TRANSPORT_MAX_LUNS_PER_TPG before reading from struct se_node_acl->device_list[].

---
 drivers/target/target_core_device.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/target/target_core_device.c +12 -0
index ba698ea..f5516a1 100644
@@ -65,6 +65,12 @@ int transport_get_lun_for_cmd(
 	unsigned long flags;
 	int read_only = 0;
 
+	if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) {
+		se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN;
+		se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
+		return -1;
+	}
+
 	spin_lock_irq(&SE_NODE_ACL(se_sess)->device_list_lock);
 	deve = se_cmd->se_deve =
 			&SE_NODE_ACL(se_sess)->device_list[unpacked_lun];
@@ -187,6 +193,12 @@ int transport_get_lun_for_tmr(
 	struct se_session *se_sess = SE_SESS(se_cmd);
 	struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
 
+	if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) {
+		se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN;
+		se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
+		return -1;
+	}
+
 	spin_lock_irq(&SE_NODE_ACL(se_sess)->device_list_lock);
 	deve = se_cmd->se_deve =
 			&SE_NODE_ACL(se_sess)->device_list[unpacked_lun];
Signature · 1 line
1.7.6
#28 lore raw

PATCH 21/103 target: remove extraneous returns at end of void functions

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

---
 drivers/target/target_core_configfs.c  |    3 ---
 drivers/target/target_core_device.c    |   12 ------------
 drivers/target/target_core_pscsi.c     |    2 --
 drivers/target/target_core_transport.c |    2 --
 drivers/target/tcm_fc/tfc_cmd.c        |    1 -
 5 files changed, 0 insertions(+), 20 deletions(-)
drivers/target/target_core_configfs.c +0 -3
index 27effbc..8196b72 100644
@@ -601,7 +601,6 @@ void target_fabric_configfs_deregister(
 
 	printk("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
 			">>>>>\n");
-	return;
 }
 EXPORT_SYMBOL(target_fabric_configfs_deregister);
 
@@ -3304,8 +3303,6 @@ static void __exit target_core_exit_configfs(void)
 	core_dev_release_virtual_lun0();
 	rd_module_exit();
 	release_se_kmem_caches();
-
-	return;
 }
 
 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
drivers/target/target_core_device.c +0 -12
index fe5474c..ff57891 100644
@@ -339,8 +339,6 @@ void core_dec_lacl_count(struct se_node_acl *se_nacl, struct se_cmd *se_cmd)
 	deve = &se_nacl->device_list[se_cmd->orig_fe_lun];
 	deve->deve_cmds--;
 	spin_unlock_irq(&se_nacl->device_list_lock);
-
-	return;
 }
 
 void core_update_device_list_access(
@@ -360,8 +358,6 @@ void core_update_device_list_access(
 		deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
 	}
 	spin_unlock_irq(&nacl->device_list_lock);
-
-	return;
 }
 
 /*      core_update_device_list_for_node():
@@ -508,8 +504,6 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
 		spin_lock_bh(&tpg->acl_node_lock);
 	}
 	spin_unlock_bh(&tpg->acl_node_lock);
-
-	return;
 }
 
 static struct se_port *core_alloc_port(struct se_device *dev)
@@ -623,8 +617,6 @@ static void core_release_port(struct se_device *dev, struct se_port *port)
 	list_del(&port->sep_list);
 	dev->dev_port_count--;
 	kfree(port);
-
-	return;
 }
 
 int core_dev_export(
@@ -761,8 +753,6 @@ void se_release_device_for_hba(struct se_device *dev)
 	se_release_vpd_for_dev(dev);
 
 	kfree(dev);
-
-	return;
 }
 
 void se_release_vpd_for_dev(struct se_device *dev)
@@ -776,8 +766,6 @@ void se_release_vpd_for_dev(struct se_device *dev)
 		kfree(vpd);
 	}
 	spin_unlock(&DEV_T10_WWN(dev)->t10_vpd_lock);
-
-	return;
 }
 
 /*	se_free_virtual_device():
drivers/target/target_core_pscsi.c +0 -2
index e221dea..afe5f57 100644
@@ -1369,8 +1369,6 @@ static inline void pscsi_process_SAM_status(
 		transport_complete_task(task, 0);
 		break;
 	}
-
-	return;
 }
 
 static void pscsi_req_done(struct request *req, int uptodate)
drivers/target/target_core_transport.c +0 -2
index 7e0d69a..473032e 100644
@@ -1103,8 +1103,6 @@ static void transport_add_tasks_from_cmd(struct se_cmd *cmd)
 		task_prev = task;
 	}
 	spin_unlock_irqrestore(&dev->execute_task_lock, flags);
-
-	return;
 }
 
 /*	transport_get_task_from_execute_queue():
drivers/target/tcm_fc/tfc_cmd.c +0 -1
index 92a449a..5823ccf 100644
@@ -670,7 +670,6 @@ static void ft_send_cmd(struct ft_cmd *cmd)
 
 err:
 	ft_send_resp_code(cmd, FCP_CMND_FIELDS_INVALID);
-	return;
 }
 
 /*
Signature · 1 line
1.7.6
#32 lore raw

PATCH 25/103 target: Misc style cleanups

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Typo

Local variables should be declared on separate lines (simplifies diffs)

Prefer (!foo) over (foo == 0)

---
 drivers/target/target_core_transport.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/target/target_core_transport.c +6 -4
index a224010..101bc20 100644
@@ -644,7 +644,7 @@ static int transport_cmd_check_stop(
 	}
 	/*
 	 * Determine if frontend context caller is requesting the stopping of
-	 * this command for frontend excpections.
+	 * this command for frontend exceptions.
 	 */
 	if (atomic_read(&T_TASK(cmd)->t_transport_stop)) {
 		DEBUG_CS("%s:%d atomic_read(&T_TASK(cmd)->t_transport_stop) =="
@@ -1314,7 +1314,8 @@ int transport_dump_vpd_assoc(
 	int p_buf_len)
 {
 	unsigned char buf[VPD_TMP_BUF_SIZE];
-	int ret = 0, len;
+	int ret = 0;
+	int len;
 
 	memset(buf, 0, VPD_TMP_BUF_SIZE);
 	len = sprintf(buf, "T10 VPD Identifier Association: ");
@@ -1361,7 +1362,8 @@ int transport_dump_vpd_ident_type(
 	int p_buf_len)
 {
 	unsigned char buf[VPD_TMP_BUF_SIZE];
-	int ret = 0, len;
+	int ret = 0;
+	int len;
 
 	memset(buf, 0, VPD_TMP_BUF_SIZE);
 	len = sprintf(buf, "T10 VPD Identifier Type: ");
@@ -2510,7 +2512,7 @@ static int transport_execute_tasks(struct se_cmd *cmd)
 		 * attribute for the tasks of the received struct se_cmd CDB
 		 */
 		add_tasks = transport_execute_task_attr(cmd);
-		if (add_tasks == 0)
+		if (!add_tasks)
 			goto execute_tasks;
 		/*
 		 * This calls transport_add_tasks_from_cmd() to handle
Signature · 1 line
1.7.6
#36 lore raw

PATCH 29/103 target: Fix double test of inquiry_prod

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

The code in transport_add_device_to_core_hba() really intends to make sure that neither inquiry_prod nor inquiry_rev is NULL.

---
 drivers/target/target_core_transport.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/target/target_core_transport.c +1 -1
index e4406c9..6f5d4df 100644
@@ -1623,7 +1623,7 @@ struct se_device *transport_add_device_to_core_hba(
 	 * setup.
 	 */
 	if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) {
-		if (!(inquiry_prod) || !(inquiry_prod)) {
+		if (!inquiry_prod || !inquiry_rev) {
 			printk(KERN_ERR "All non TCM/pSCSI plugins require"
 				" INQUIRY consts\n");
 			goto out;
Signature · 1 line
1.7.6
#18 lore raw

PATCH 16/103 target: Remove __transport_get_qr_from_queue()

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

The only use of it seems to be wrapped by a lock, so it should just use the locked version.

---
 drivers/target/target_core_transport.c |   27 +--------------------------
 1 files changed, 1 insertions(+), 26 deletions(-)
drivers/target/target_core_transport.c +1 -26
index 002ea6f..56249cf 100644
@@ -841,26 +841,6 @@ static int transport_add_cmd_to_queue(
  * Called with struct se_queue_obj->cmd_queue_lock held.
  */
 static struct se_queue_req *
-__transport_get_qr_from_queue(struct se_queue_obj *qobj)
-{
-	struct se_queue_req *qr = NULL;
-
-	if (list_empty(&qobj->qobj_list))
-		return NULL;
-
-	list_for_each_entry(qr, &qobj->qobj_list, qr_list)
-		break;
-
-	if (qr->cmd)
-		atomic_dec(&T_TASK(qr->cmd)->t_transport_queue_active);
-
-	list_del(&qr->qr_list);
-	atomic_dec(&qobj->queue_cnt);
-
-	return qr;
-}
-
-static struct se_queue_req *
 transport_get_qr_from_queue(struct se_queue_obj *qobj)
 {
 	struct se_queue_req *qr;
@@ -6013,10 +5993,7 @@ static void transport_processing_shutdown(struct se_device *dev)
 	/*
 	 * Empty the struct se_device's struct se_cmd list.
 	 */
-	spin_lock_irqsave(&dev->dev_queue_obj->cmd_queue_lock, flags);
-	while ((qr = __transport_get_qr_from_queue(dev->dev_queue_obj))) {
-		spin_unlock_irqrestore(
-				&dev->dev_queue_obj->cmd_queue_lock, flags);
+	while ((qr = transport_get_qr_from_queue(dev->dev_queue_obj))) {
 		cmd = qr->cmd;
 		state = qr->state;
 		kfree(qr);
@@ -6035,9 +6012,7 @@ static void transport_processing_shutdown(struct se_device *dev)
 			if (transport_cmd_check_stop(cmd, 1, 0))
 				transport_generic_remove(cmd, 0, 0);
 		}
-		spin_lock_irqsave(&dev->dev_queue_obj->cmd_queue_lock, flags);
 	}
-	spin_unlock_irqrestore(&dev->dev_queue_obj->cmd_queue_lock, flags);
 }
 
 /*	transport_processing_thread():
Signature · 1 line
1.7.6
#16 lore raw

PATCH 14/103 target: dev->dev_status_queue_obj is unused

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Looks safe to remove.

---
 drivers/target/target_core_device.c    |    1 -
 drivers/target/target_core_transport.c |   12 ------------
 include/target/target_core_base.h      |    1 -
 3 files changed, 0 insertions(+), 14 deletions(-)
drivers/target/target_core_device.c +0 -1
index 818c65b..f03e0cc 100644
@@ -755,7 +755,6 @@ void se_release_device_for_hba(struct se_device *dev)
 	core_scsi3_free_all_registrations(dev);
 	se_release_vpd_for_dev(dev);
 
-	kfree(dev->dev_status_queue_obj);
 	kfree(dev->dev_queue_obj);
 	kfree(dev);
 
drivers/target/target_core_transport.c +0 -12
index ae153bf..fffa905 100644
@@ -1642,17 +1642,6 @@ struct se_device *transport_add_device_to_core_hba(
 	}
 	transport_init_queue_obj(dev->dev_queue_obj);
 
-	dev->dev_status_queue_obj = kzalloc(sizeof(struct se_queue_obj),
-					GFP_KERNEL);
-	if (!(dev->dev_status_queue_obj)) {
-		printk(KERN_ERR "Unable to allocate memory for"
-				" dev->dev_status_queue_obj\n");
-		kfree(dev->dev_queue_obj);
-		kfree(dev);
-		return NULL;
-	}
-	transport_init_queue_obj(dev->dev_status_queue_obj);
-
 	dev->dev_flags		= device_flags;
 	dev->dev_status		|= TRANSPORT_DEVICE_DEACTIVATED;
 	dev->dev_ptr		= (void *) transport_dev;
@@ -1753,7 +1742,6 @@ out:
 
 	se_release_vpd_for_dev(dev);
 
-	kfree(dev->dev_status_queue_obj);
 	kfree(dev->dev_queue_obj);
 	kfree(dev);
 
include/target/target_core_base.h +0 -1
index e35e9e4..b2b4cf9 100644
@@ -784,7 +784,6 @@ struct se_device {
 	struct se_obj		dev_access_obj;
 	struct se_obj		dev_export_obj;
 	struct se_queue_obj	*dev_queue_obj;
-	struct se_queue_obj	*dev_status_queue_obj;
 	spinlock_t		delayed_cmd_lock;
 	spinlock_t		ordered_cmd_lock;
 	spinlock_t		execute_task_lock;
Signature · 1 line
1.7.6
#30 lore raw

PATCH 23/103 target: Function pointers don't need to use '&' to be assigned

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

---
 drivers/target/target_core_transport.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/target/target_core_transport.c +6 -6
index 72e4726..acb5ef7 100644
@@ -3226,7 +3226,7 @@ static int transport_generic_cmd_sequencer(
 				cmd->transport_emulate_cdb =
 				(T10_ALUA(su_dev)->alua_type ==
 				 SPC3_ALUA_EMULATED) ?
-				&core_emulate_report_target_port_groups :
+				core_emulate_report_target_port_groups :
 				NULL;
 			}
 			size = (cdb[6] << 24) | (cdb[7] << 16) |
@@ -3273,7 +3273,7 @@ static int transport_generic_cmd_sequencer(
 		cmd->transport_emulate_cdb =
 			(T10_RES(su_dev)->res_type ==
 			 SPC3_PERSISTENT_RESERVATIONS) ?
-			&core_scsi3_emulate_pr : NULL;
+			core_scsi3_emulate_pr : NULL;
 		size = (cdb[7] << 8) + cdb[8];
 		cmd->se_cmd_flags |= SCF_SCSI_CONTROL_NONSG_IO_CDB;
 		break;
@@ -3296,7 +3296,7 @@ static int transport_generic_cmd_sequencer(
 				cmd->transport_emulate_cdb =
 				(T10_ALUA(su_dev)->alua_type ==
 					SPC3_ALUA_EMULATED) ?
-				&core_emulate_set_target_port_groups :
+				core_emulate_set_target_port_groups :
 				NULL;
 			}
 
@@ -3393,7 +3393,7 @@ static int transport_generic_cmd_sequencer(
 		cmd->transport_emulate_cdb =
 				(T10_RES(su_dev)->res_type !=
 				 SPC_PASSTHROUGH) ?
-				&core_scsi2_emulate_crh : NULL;
+				core_scsi2_emulate_crh : NULL;
 		cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
 		break;
 	case RELEASE:
@@ -3410,7 +3410,7 @@ static int transport_generic_cmd_sequencer(
 		cmd->transport_emulate_cdb =
 				(T10_RES(su_dev)->res_type !=
 				 SPC_PASSTHROUGH) ?
-				&core_scsi2_emulate_crh : NULL;
+				core_scsi2_emulate_crh : NULL;
 		cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
 		break;
 	case SYNCHRONIZE_CACHE:
@@ -3516,7 +3516,7 @@ static int transport_generic_cmd_sequencer(
 		break;
 	case REPORT_LUNS:
 		cmd->transport_emulate_cdb =
-				&transport_core_report_lun_response;
+				transport_core_report_lun_response;
 		size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
 		/*
 		 * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
Signature · 1 line
1.7.6
#37 lore raw

PATCH 30/103 target: Remove unneeded casts to void*

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

---
 drivers/target/loopback/tcm_loop.c     |   12 ++++++------
 drivers/target/target_core_configfs.c  |    4 ++--
 drivers/target/target_core_file.c      |    2 +-
 drivers/target/target_core_iblock.c    |    6 +++---
 drivers/target/target_core_pscsi.c     |   10 +++++-----
 drivers/target/target_core_rd.c        |    4 ++--
 drivers/target/target_core_transport.c |    8 ++++----
 drivers/target/tcm_fc/tfc_conf.c       |    2 +-
 8 files changed, 24 insertions(+), 24 deletions(-)
drivers/target/loopback/tcm_loop.c +6 -6
index 1f1695a..e1d17b9 100644
@@ -171,7 +171,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
 	 */
 	if (scsi_sg_count(sc)) {
 		se_cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM;
-		mem_ptr = (void *)scsi_sglist(sc);
+		mem_ptr = scsi_sglist(sc);
 		/*
 		 * For BIDI commands, pass in the extra READ buffer
 		 * to transport_generic_map_mem_to_cmd() below..
@@ -179,7 +179,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
 		if (se_cmd->t_task->t_tasks_bidi) {
 			struct scsi_data_buffer *sdb = scsi_in(sc);
 
-			mem_bidi_ptr = (void *)sdb->table.sgl;
+			mem_bidi_ptr = sdb->table.sgl;
 			sg_no_bidi = sdb->table.nents;
 		}
 	} else {
@@ -384,7 +384,7 @@ static int tcm_loop_device_reset(struct scsi_cmnd *sc)
 	/*
 	 * Allocate the LUN_RESET TMR
 	 */
-	se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, (void *)tl_tmr,
+	se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, tl_tmr,
 				TMR_LUN_RESET);
 	if (IS_ERR(se_cmd->se_tmr_req))
 		goto release;
@@ -904,7 +904,7 @@ static int tcm_loop_queue_status(struct se_cmd *se_cmd)
 	   ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
 	    (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
 
-		memcpy((void *)sc->sense_buffer, (void *)se_cmd->sense_buffer,
+		memcpy(sc->sense_buffer, se_cmd->sense_buffer,
 				SCSI_SENSE_BUFFERSIZE);
 		sc->result = SAM_STAT_CHECK_CONDITION;
 		set_driver_byte(sc, DRIVER_SENSE);
@@ -1054,7 +1054,7 @@ static int tcm_loop_make_nexus(
 	 * transport_register_session()
 	 */
 	__transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
-			tl_nexus->se_sess, (void *)tl_nexus);
+			tl_nexus->se_sess, tl_nexus);
 	tl_tpg->tl_hba->tl_nexus = tl_nexus;
 	printk(KERN_INFO "TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
 		" %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
@@ -1242,7 +1242,7 @@ struct se_portal_group *tcm_loop_make_naa_tpg(
 	 * Register the tl_tpg as a emulated SAS TCM Target Endpoint
 	 */
 	ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops,
-			wwn, &tl_tpg->tl_se_tpg, (void *)tl_tpg,
+			wwn, &tl_tpg->tl_se_tpg, tl_tpg,
 			TRANSPORT_TPG_TYPE_NORMAL);
 	if (ret < 0)
 		return ERR_PTR(-ENOMEM);
drivers/target/target_core_configfs.c +2 -2
index 64418ef..ac7f765 100644
@@ -2037,7 +2037,7 @@ static ssize_t target_core_dev_show(struct config_item *item,
 	if (!(tc_attr->show))
 		return -EINVAL;
 
-	return tc_attr->show((void *)se_dev, page);
+	return tc_attr->show(se_dev, page);
 }
 
 static ssize_t target_core_dev_store(struct config_item *item,
@@ -2053,7 +2053,7 @@ static ssize_t target_core_dev_store(struct config_item *item,
 	if (!(tc_attr->store))
 		return -EINVAL;
 
-	return tc_attr->store((void *)se_dev, page, count);
+	return tc_attr->store(se_dev, page, count);
 }
 
 static struct configfs_item_operations target_core_dev_item_ops = {
drivers/target/target_core_file.c +1 -1
index 0c44bc0..46825ce 100644
@@ -223,7 +223,7 @@ static struct se_device *fd_create_virtdevice(
 	dev_limits.queue_depth = FD_DEVICE_QUEUE_DEPTH;
 
 	dev = transport_add_device_to_core_hba(hba, &fileio_template,
-				se_dev, dev_flags, (void *)fd_dev,
+				se_dev, dev_flags, fd_dev,
 				&dev_limits, "FILEIO", FD_VERSION);
 	if (!(dev))
 		goto fail;
drivers/target/target_core_iblock.c +3 -3
index fb15987..b0bafe4 100644
@@ -74,7 +74,7 @@ static int iblock_attach_hba(struct se_hba *hba, u32 host_id)
 
 	ib_host->iblock_host_id = host_id;
 
-	hba->hba_ptr = (void *) ib_host;
+	hba->hba_ptr = ib_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM iBlock HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
@@ -172,7 +172,7 @@ static struct se_device *iblock_create_virtdevice(
 	ib_dev->ibd_bd = bd;
 
 	dev = transport_add_device_to_core_hba(hba,
-			&iblock_template, se_dev, dev_flags, (void *)ib_dev,
+			&iblock_template, se_dev, dev_flags, ib_dev,
 			&dev_limits, "IBLOCK", IBLOCK_VERSION);
 	if (!(dev))
 		goto failed;
@@ -593,7 +593,7 @@ static struct bio *iblock_get_bio(
 	DEBUG_IBLOCK("Allocated bio: %p task_size: %u\n", bio, task->task_size);
 
 	bio->bi_bdev = ib_dev->ibd_bd;
-	bio->bi_private = (void *) task;
+	bio->bi_private = task;
 	bio->bi_destructor = iblock_bio_destructor;
 	bio->bi_end_io = &iblock_bio_done;
 	bio->bi_sector = lba;
drivers/target/target_core_pscsi.c +5 -5
index 44a79a5..823da67 100644
@@ -72,7 +72,7 @@ static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
 	phv->phv_host_id = host_id;
 	phv->phv_mode = PHV_VIRUTAL_HOST_ID;
 
-	hba->hba_ptr = (void *)phv;
+	hba->hba_ptr = phv;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM SCSI HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
@@ -355,7 +355,7 @@ static struct se_device *pscsi_add_device_to_list(
 	pdv->pdv_sd = sd;
 
 	dev = transport_add_device_to_core_hba(hba, &pscsi_template,
-				se_dev, dev_flags, (void *)pdv,
+				se_dev, dev_flags, pdv,
 				&dev_limits, NULL, NULL);
 	if (!(dev)) {
 		pdv->pdv_sd = NULL;
@@ -394,7 +394,7 @@ static void *pscsi_allocate_virtdevice(struct se_hba *hba, const char *name)
 	pdv->pdv_se_hba = hba;
 
 	printk(KERN_INFO "PSCSI: Allocated pdv: %p for %s\n", pdv, name);
-	return (void *)pdv;
+	return pdv;
 }
 
 /*
@@ -812,7 +812,7 @@ static inline void pscsi_blk_init_request(
 	 * also set the end_io_data pointer.to struct se_task.
 	 */
 	req->end_io = pscsi_req_done;
-	req->end_io_data = (void *)task;
+	req->end_io_data = task;
 	/*
 	 * Load the referenced struct se_task's SCSI CDB into
 	 * include/linux/blkdev.h:struct request->cmd
@@ -822,7 +822,7 @@ static inline void pscsi_blk_init_request(
 	/*
 	 * Setup pointer for outgoing sense data.
 	 */
-	req->sense = (void *)&pt->pscsi_sense[0];
+	req->sense = &pt->pscsi_sense[0];
 	req->sense_len = 0;
 }
 
drivers/target/target_core_rd.c +2 -2
index fbf06c3..63cd5a7 100644
@@ -66,7 +66,7 @@ static int rd_attach_hba(struct se_hba *hba, u32 host_id)
 
 	rd_host->rd_host_id = host_id;
 
-	hba->hba_ptr = (void *) rd_host;
+	hba->hba_ptr = rd_host;
 
 	printk(KERN_INFO "CORE_HBA[%d] - TCM Ramdisk HBA Driver %s on"
 		" Generic Target Core Stack %s\n", hba->hba_id,
@@ -271,7 +271,7 @@ static struct se_device *rd_create_virtdevice(
 
 	dev = transport_add_device_to_core_hba(hba,
 			(rd_dev->rd_direct) ? &rd_dr_template :
-			&rd_mcp_template, se_dev, dev_flags, (void *)rd_dev,
+			&rd_mcp_template, se_dev, dev_flags, rd_dev,
 			&dev_limits, prod, rev);
 	if (!(dev))
 		goto fail;
drivers/target/target_core_transport.c +4 -4
index 6f5d4df..6198a7e 100644
@@ -201,7 +201,7 @@ struct kmem_cache *t10_alua_tg_pt_gp_mem_cache;
 typedef int (*map_func_t)(struct se_task *, u32);
 
 static int transport_generic_write_pending(struct se_cmd *);
-static int transport_processing_thread(void *);
+static int transport_processing_thread(void *param);
 static int __transport_execute_tasks(struct se_device *dev);
 static void transport_complete_task_attr(struct se_cmd *cmd);
 static void transport_direct_request_timeout(struct se_cmd *cmd);
@@ -1548,7 +1548,7 @@ struct se_device *transport_add_device_to_core_hba(
 	transport_init_queue_obj(&dev->dev_queue_obj);
 	dev->dev_flags		= device_flags;
 	dev->dev_status		|= TRANSPORT_DEVICE_DEACTIVATED;
-	dev->dev_ptr		= (void *) transport_dev;
+	dev->dev_ptr		= transport_dev;
 	dev->se_hba		= hba;
 	dev->se_sub_dev		= se_dev;
 	dev->transport		= transport;
@@ -2908,7 +2908,7 @@ static int transport_get_sense_data(struct se_cmd *cmd)
 		offset = cmd->se_tfo->set_fabric_sense_len(cmd,
 				TRANSPORT_SENSE_BUFFER);
 
-		memcpy((void *)&buffer[offset], (void *)sense_buffer,
+		memcpy(&buffer[offset], sense_buffer,
 				TRANSPORT_SENSE_BUFFER);
 		cmd->scsi_status = task->task_scsi_status;
 		/* Automatically padded */
@@ -5379,7 +5379,7 @@ int transport_clear_lun_from_sessions(struct se_lun *lun)
 {
 	struct task_struct *kt;
 
-	kt = kthread_run(transport_clear_lun_thread, (void *)lun,
+	kt = kthread_run(transport_clear_lun_thread, lun,
 			"tcm_cl_%u", lun->unpacked_lun);
 	if (IS_ERR(kt)) {
 		printk(KERN_ERR "Unable to start clear_lun thread\n");
drivers/target/tcm_fc/tfc_conf.c +1 -1
index 8c5067c..58e4745 100644
@@ -331,7 +331,7 @@ static struct se_portal_group *ft_add_tpg(
 	transport_init_queue_obj(&tpg->qobj);
 
 	ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
-				(void *)tpg, TRANSPORT_TPG_TYPE_NORMAL);
+				tpg, TRANSPORT_TPG_TYPE_NORMAL);
 	if (ret < 0) {
 		kfree(tpg);
 		return NULL;
Signature · 1 line
1.7.6
#35 lore raw

PATCH 28/103 target: Inline transport_get_task_from_execute_queue()

In reply to Nicholas A. Bellinger

From: Andy Grover <[email protected]>

Only used in one place, and inline code is pretty short.

(nab: Fix __transport_execute_tasks() bugs from Andy's
original patch)

---
 drivers/target/target_core_transport.c |   37 ++++++++-----------------------
 1 files changed, 10 insertions(+), 27 deletions(-)
drivers/target/target_core_transport.c +10 -27
index 9c8641ea..e4406c9 100644
@@ -1105,28 +1105,6 @@ static void transport_add_tasks_from_cmd(struct se_cmd *cmd)
 	spin_unlock_irqrestore(&dev->execute_task_lock, flags);
 }
 
-/*	transport_get_task_from_execute_queue():
- *
- *	Called with dev->execute_task_lock held.
- */
-static struct se_task *
-transport_get_task_from_execute_queue(struct se_device *dev)
-{
-	struct se_task *task;
-
-	if (list_empty(&dev->execute_task_list))
-		return NULL;
-
-	list_for_each_entry(task, &dev->execute_task_list, t_execute_list)
-		break;
-
-	list_del(&task->t_execute_list);
-	atomic_set(&task->task_execute_queue, 0);
-	atomic_dec(&dev->execute_tasks);
-
-	return task;
-}
-
 /*	transport_remove_task_from_execute_queue():
  *
  *
@@ -2541,7 +2519,7 @@ static int __transport_execute_tasks(struct se_device *dev)
 {
 	int error;
 	struct se_cmd *cmd = NULL;
-	struct se_task *task;
+	struct se_task *task = NULL;
 	unsigned long flags;
 
 	/*
@@ -2555,11 +2533,16 @@ check_depth:
 	dev->dev_tcq_window_closed = 0;
 
 	spin_lock_irq(&dev->execute_task_lock);
-	task = transport_get_task_from_execute_queue(dev);
-	spin_unlock_irq(&dev->execute_task_lock);
-
-	if (!task)
+	if (list_empty(&dev->execute_task_list)) {
+		spin_unlock_irq(&dev->execute_task_lock);
 		return 0;
+	}
+	task = list_first_entry(&dev->execute_task_list,
+				struct se_task, t_execute_list);
+	list_del(&task->t_execute_list);
+	atomic_set(&task->task_execute_queue, 0);
+	atomic_dec(&dev->execute_tasks);
+	spin_unlock_irq(&dev->execute_task_lock);
 
 	atomic_dec(&dev->depth_left);
 
Signature · 1 line
1.7.6
#6 lore raw

Re: [PATCH 005/103] loopback: Only build tcm_loop as module

In reply to Nicholas A. Bellinger

Nick, please drop this patch. It doesn't make any sense -- after my fix that you have later in your series, tcm_loop works perfectly well built-in (and in fact is useful for quick debugging, along with "qemu -kernel").

- R.

Quoted 23 lines · Nicholas A. Bellinger

From: Stefan Hajnoczi <[email protected]>

The tcm_loop must be built as a module.  It cannot be built in.

---
 drivers/target/loopback/Kconfig |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/target/loopback/Kconfig +0 -0
index 57dcbc2..1bd6a65 100644
@@ -1,7 +1,8 @@

 config LOOPBACK_TARGET
       tristate "TCM Virtual SAS target and Linux/SCSI LDD fabric loopback module"
+       depends on m
       help
-         Say Y here to enable the TCM Virtual SAS target and Linux/SCSI LLD
+         Say M here to enable the TCM Virtual SAS target and Linux/SCSI LLD fabric loopback module.

Quoted 9 lines

 config LOOPBACK_TARGET_CDB_DEBUG
--
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [PATCH 005/103] loopback: Only build tcm_loop as module

Quoted 4 lines · Roland Dreier

Nick, please drop this patch. It doesn't make any sense -- after my fix that you have later in your series, tcm_loop works perfectly well built-in (and in fact is useful for quick debugging, along with "qemu -kernel").

Thanks Roland, dropping this patch now.

--nab

Quoted 36 lines

- R.

Quoted 32 lines · Nicholas A. Bellinger

From: Stefan Hajnoczi <[email protected]>

The tcm_loop must be built as a module. It cannot be built in.

---
 drivers/target/loopback/Kconfig |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/target/loopback/Kconfig +2 -2
index 57dcbc2..1bd6a65 100644
@@ -1,7 +1,8 @@
 config LOOPBACK_TARGET
       tristate "TCM Virtual SAS target and Linux/SCSI LDD fabric loopback module"
+       depends on m
       help
-         Say Y here to enable the TCM Virtual SAS target and Linux/SCSI LLD
+         Say M here to enable the TCM Virtual SAS target and Linux/SCSI LLD
         fabric loopback module.
 
 config LOOPBACK_TARGET_CDB_DEBUG
--

1.7.6

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw

Re: [PATCH 018/103] target: Remove struct se_global

In reply to Nicholas A. Bellinger
Quoted 13 lines · Nicholas A. Bellinger
drivers/target/target_core_configfs.c +1 -0
index 03cda0e..82c8e9a 100644
@@ -37,6 +37,7 @@
  #include <linux/parser.h>
  #include <linux/syscalls.h>
  #include <linux/configfs.h>
+#include <linux/spinlock.h>
 
  #include <target/target_core_base.h>
  #include <target/target_core_device.h>

drivers/target/target_core_configfs.c line 56

Quoted 4 lines
drivers/target/target_core_configfs.c +1 -0
@@ -52,6 +53,8 @@
  #include "target_core_rd.h"
  #include "target_core_stat.h"
 
+extern struct t10_alua_lu_gp *default_lu_gp;

I see here an extern declaration in a .c file. Shouldn't instead that be moved to a header file ?

Fubo.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw

Re: [PATCH 018/103] target: Remove struct se_global

In reply to Nicholas A. Bellinger

drivers/target/target_core_tpg.c line 49

Quoted 12 lines · Nicholas A. Bellinger

From: Andy Grover <[email protected]>

drivers/target/target_core_tpg.c +3 -0
index dc024c1..4e2bee9 100644
@@ -44,6 +44,12 @@
  #include <target/target_core_fabric_ops.h>
 
  #include "target_core_hba.h"
+#include "target_core_stat.h"
+
+extern struct se_device *g_lun0_dev;

Same here: another extern declaraion in a C file.

Fubo.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw

Re: [PATCH 018/103] target: Remove struct se_global

In reply to Fubo Chen
Quoted 18 lines · Fubo Chen
Quoted 16 lines · Nicholas A. Bellinger
drivers/target/target_core_configfs.c +1 -0
index 03cda0e..82c8e9a 100644
@@ -37,6 +37,7 @@
 #include <linux/parser.h>
 #include <linux/syscalls.h>
 #include <linux/configfs.h>
+#include <linux/spinlock.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_device.h>
@@ -52,6 +53,8 @@
 #include "target_core_rd.h"
 #include "target_core_stat.h"
 
Quoted 5 lines

drivers/target/target_core_configfs.c line 56

Quoted 1 line
drivers/target/target_core_configfs.c +1 -0
+extern struct t10_alua_lu_gp *default_lu_gp;

I see here an extern declaration in a .c file. Shouldn't instead that be moved to a header file ?

I don't really have a strong preference here either way, and will defer to Andy and Christoph for mainline style consideration on these two particular bits..

Thanks for your review!

--nab

#23 lore raw

Re: [PATCH 018/103] target: Remove struct se_global

Quoted 5 lines · Nicholas A. Bellinger
Quoted 5 lines
Quoted 4 lines

#include "target_core_rd.h"
#include "target_core_stat.h"

+extern struct t10_alua_lu_gp *default_lu_gp;

Quoted 7 lines
Quoted 3 lines

I see here an extern declaration in a .c file. Shouldn't instead that be moved to a header file ?

I don't really have a strong preference here either way, and will defer to Andy and Christoph for mainline style consideration on these two particular bits..

externs should always be in headers. In fact sparse will complain about having it in the .c file.

#24 lore raw

Re: [PATCH 018/103] target: Remove struct se_global

Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Nicholas A. Bellinger
Quoted 8 lines
Quoted 4 lines

#include "target_core_rd.h"
#include "target_core_stat.h"

+extern struct t10_alua_lu_gp *default_lu_gp;

I see here an extern declaration in a .c file. Shouldn't instead that be moved to a header file ?

Quoted 7 lines
Quoted 3 lines

I don't really have a strong preference here either way, and will defer to Andy and Christoph for mainline style consideration on these two particular bits..

externs should always be in headers. In fact sparse will complain about having it in the .c file.

Ok, fixing this up now in lio-core-2.6.git and will get this included into the initial merge.