linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
	Hannes Reinecke <hare@suse.com>
Subject: [PATCH 06/35] visorhba: sanitze private device data allocation
Date: Fri, 23 Jun 2017 15:02:26 +0200	[thread overview]
Message-ID: <1498222975-71858-7-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1498222975-71858-1-git-send-email-hare@suse.de>

There's no need to keep the private data for a device in a separate
list; better to store it in ->hostdata and do away with the additional
list.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/staging/unisys/visorhba/visorhba_main.c | 123 ++++++++++--------------
 1 file changed, 53 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c
index 6997b16..811abfc 100644
--- a/drivers/staging/unisys/visorhba/visorhba_main.c
+++ b/drivers/staging/unisys/visorhba/visorhba_main.c
@@ -47,8 +47,8 @@
 MODULE_ALIAS("visorbus:" SPAR_VHBA_CHANNEL_PROTOCOL_UUID_STR);
 
 struct visordisk_info {
+	struct scsi_device *sdev;
 	u32 valid;
-	u32 channel, id, lun;	/* Disk Path */
 	atomic_t ios_threshold;
 	atomic_t error_count;
 	struct visordisk_info *next;
@@ -101,12 +101,6 @@ struct visorhba_devices_open {
 	struct visorhba_devdata *devdata;
 };
 
-#define for_each_vdisk_match(iter, list, match) \
-	for (iter = &list->head; iter->next; iter = iter->next) \
-		if ((iter->channel == match->channel) && \
-		    (iter->id == match->id) && \
-		    (iter->lun == match->lun))
-
 /*
  *	visor_thread_start - starts a thread for the device
  *	@threadfn: Function the thread starts
@@ -296,10 +290,9 @@ static void cleanup_scsitaskmgmt_handles(struct idr *idrtable,
  *	Returns whether the command was queued successfully or not.
  */
 static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
-				    struct scsi_cmnd *scsicmd)
+				    struct scsi_device *scsidev)
 {
 	struct uiscmdrsp *cmdrsp;
-	struct scsi_device *scsidev = scsicmd->device;
 	struct visorhba_devdata *devdata =
 		(struct visorhba_devdata *)scsidev->host->hostdata;
 	int notifyresult = 0xffff;
@@ -347,12 +340,6 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
 	dev_dbg(&scsidev->sdev_gendev,
 		"visorhba: taskmgmt type=%d success; result=0x%x\n",
 		 tasktype, notifyresult);
-	if (tasktype == TASK_MGMT_ABORT_TASK)
-		scsicmd->result = DID_ABORT << 16;
-	else
-		scsicmd->result = DID_RESET << 16;
-
-	scsicmd->scsi_done(scsicmd);
 	cleanup_scsitaskmgmt_handles(&devdata->idr, cmdrsp);
 	return SUCCESS;
 
@@ -376,17 +363,20 @@ static int visorhba_abort_handler(struct scsi_cmnd *scsicmd)
 	/* issue TASK_MGMT_ABORT_TASK */
 	struct scsi_device *scsidev;
 	struct visordisk_info *vdisk;
-	struct visorhba_devdata *devdata;
+	int rtn;
 
 	scsidev = scsicmd->device;
-	devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
-	for_each_vdisk_match(vdisk, devdata, scsidev) {
-		if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
-			atomic_inc(&vdisk->error_count);
-		else
-			atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+	vdisk = scsidev->hostdata;
+	if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
+		atomic_inc(&vdisk->error_count);
+	else
+		atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+	rtn = forward_taskmgmt_command(TASK_MGMT_ABORT_TASK, scsidev);
+	if (rtn == SUCCESS) {
+		scsicmd->result = DID_ABORT << 16;
+		scsicmd->scsi_done(scsicmd);
 	}
-	return forward_taskmgmt_command(TASK_MGMT_ABORT_TASK, scsicmd);
+	return rtn;
 }
 
 /*
@@ -400,17 +390,20 @@ static int visorhba_device_reset_handler(struct scsi_cmnd *scsicmd)
 	/* issue TASK_MGMT_LUN_RESET */
 	struct scsi_device *scsidev;
 	struct visordisk_info *vdisk;
-	struct visorhba_devdata *devdata;
+	int rtn;
 
 	scsidev = scsicmd->device;
-	devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
-	for_each_vdisk_match(vdisk, devdata, scsidev) {
-		if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
-			atomic_inc(&vdisk->error_count);
-		else
-			atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+	vdisk = scsidev->hostdata;
+	if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
+		atomic_inc(&vdisk->error_count);
+	else
+		atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+	rtn = forward_taskmgmt_command(TASK_MGMT_LUN_RESET, scsidev);
+	if (rtn == SUCCESS) {
+		scsicmd->result = DID_RESET << 16;
+		scsicmd->scsi_done(scsicmd);
 	}
-	return forward_taskmgmt_command(TASK_MGMT_LUN_RESET, scsicmd);
+	return rtn;
 }
 
 /*
@@ -424,17 +417,22 @@ static int visorhba_bus_reset_handler(struct scsi_cmnd *scsicmd)
 {
 	struct scsi_device *scsidev;
 	struct visordisk_info *vdisk;
-	struct visorhba_devdata *devdata;
+	int rtn;
 
 	scsidev = scsicmd->device;
-	devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
-	for_each_vdisk_match(vdisk, devdata, scsidev) {
+	shost_for_each_device(scsidev, scsidev->host) {
+		vdisk = scsidev->hostdata;
 		if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
 			atomic_inc(&vdisk->error_count);
 		else
 			atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
 	}
-	return forward_taskmgmt_command(TASK_MGMT_BUS_RESET, scsicmd);
+	rtn = forward_taskmgmt_command(TASK_MGMT_BUS_RESET, scsidev);
+	if (rtn == SUCCESS) {
+		scsicmd->result = DID_RESET << 16;
+		scsicmd->scsi_done(scsicmd);
+	}
+	return rtn;
 }
 
 /*
@@ -569,25 +567,22 @@ static int visorhba_slave_alloc(struct scsi_device *scsidev)
 	 * LLD can alloc any struct & do init if needed.
 	 */
 	struct visordisk_info *vdisk;
-	struct visordisk_info *tmpvdisk;
 	struct visorhba_devdata *devdata;
 	struct Scsi_Host *scsihost = (struct Scsi_Host *)scsidev->host;
 
+	if (scsidev->hostdata)
+		return 0; /* already allocated return success */
+
 	devdata = (struct visorhba_devdata *)scsihost->hostdata;
 	if (!devdata)
 		return 0; /* even though we errored, treat as success */
 
-	for_each_vdisk_match(vdisk, devdata, scsidev)
-		return 0; /* already allocated return success */
-
-	tmpvdisk = kzalloc(sizeof(*tmpvdisk), GFP_ATOMIC);
-	if (!tmpvdisk)
+	vdisk = kzalloc(sizeof(*vdisk), GFP_ATOMIC);
+	if (!vdisk)
 		return -ENOMEM;
 
-	tmpvdisk->channel = scsidev->channel;
-	tmpvdisk->id = scsidev->id;
-	tmpvdisk->lun = scsidev->lun;
-	vdisk->next = tmpvdisk;
+	vdisk->sdev = scsidev;
+	scsidev->hostdata = vdisk;
 	return 0;
 }
 
@@ -603,17 +598,11 @@ static void visorhba_slave_destroy(struct scsi_device *scsidev)
 	/* midlevel calls this after device has been quiesced and
 	 * before it is to be deleted.
 	 */
-	struct visordisk_info *vdisk, *delvdisk;
-	struct visorhba_devdata *devdata;
-	struct Scsi_Host *scsihost = (struct Scsi_Host *)scsidev->host;
+	struct visordisk_info *vdisk;
 
-	devdata = (struct visorhba_devdata *)scsihost->hostdata;
-	for_each_vdisk_match(vdisk, devdata, scsidev) {
-		delvdisk = vdisk->next;
-		vdisk->next = delvdisk->next;
-		kfree(delvdisk);
-		return;
-	}
+	vdisk = scsidev->hostdata;
+	scsidev->hostdata = NULL;
+	kfree(vdisk);
 }
 
 static struct scsi_host_template visorhba_driver_template = {
@@ -787,7 +776,6 @@ static int visorhba_serverdown(struct visorhba_devdata *devdata)
 static void
 do_scsi_linuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
 {
-	struct visorhba_devdata *devdata;
 	struct visordisk_info *vdisk;
 	struct scsi_device *scsidev;
 
@@ -800,12 +788,10 @@ static int visorhba_serverdown(struct visorhba_devdata *devdata)
 	    (cmdrsp->scsi.addlstat == ADDL_SEL_TIMEOUT))
 		return;
 	/* Okay see what our error_count is here.... */
-	devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
-	for_each_vdisk_match(vdisk, devdata, scsidev) {
-		if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT) {
-			atomic_inc(&vdisk->error_count);
-			atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
-		}
+	vdisk = scsidev->hostdata;
+	if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT) {
+		atomic_inc(&vdisk->error_count);
+		atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
 	}
 }
 
@@ -846,7 +832,6 @@ static int set_no_disk_inquiry_result(unsigned char *buf,
 	char *this_page_orig;
 	int bufind = 0;
 	struct visordisk_info *vdisk;
-	struct visorhba_devdata *devdata;
 
 	scsidev = scsicmd->device;
 	if ((cmdrsp->scsi.cmnd[0] == INQUIRY) &&
@@ -883,13 +868,11 @@ static int set_no_disk_inquiry_result(unsigned char *buf,
 		}
 		kfree(buf);
 	} else {
-		devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
-		for_each_vdisk_match(vdisk, devdata, scsidev) {
-			if (atomic_read(&vdisk->ios_threshold) > 0) {
-				atomic_dec(&vdisk->ios_threshold);
-				if (atomic_read(&vdisk->ios_threshold) == 0)
-					atomic_set(&vdisk->error_count, 0);
-			}
+		vdisk = scsidev->hostdata;
+		if (atomic_read(&vdisk->ios_threshold) > 0) {
+			atomic_dec(&vdisk->ios_threshold);
+			if (atomic_read(&vdisk->ios_threshold) == 0)
+				atomic_set(&vdisk->error_count, 0);
 		}
 	}
 }
-- 
1.8.5.6

  parent reply	other threads:[~2017-06-23 13:03 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 13:02 [RFC PATCH 00/35] SCSI EH argument reshuffling Hannes Reinecke
2017-06-23 13:02 ` [PATCH 01/35] scsi: fix comment in scsi_device_set_state() Hannes Reinecke
2017-06-23 15:56   ` Bart Van Assche
2017-06-27 23:54   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 02/35] mptfc: Do not call fc_block_scsi_eh() on host reset Hannes Reinecke
2017-06-27 23:55   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 03/35] ibmvfc: " Hannes Reinecke
2017-06-27 23:55   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 04/35] fc_fcp: do not call fc_block_scsi_eh() from " Hannes Reinecke
2017-06-27 23:55   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 05/35] fnic: do not call host reset from command abort Hannes Reinecke
2017-06-27 23:55   ` Christoph Hellwig
2017-06-23 13:02 ` Hannes Reinecke [this message]
2017-06-27 23:56   ` [PATCH 06/35] visorhba: sanitze private device data allocation Christoph Hellwig
2017-06-23 13:02 ` [PATCH 07/35] uas: move eh_bus_reset_handler to eh_device_reset_handler Hannes Reinecke
2017-06-27 23:56   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 08/35] lpfc: drop lpfc_no_handler and lpfc_bus_reset_handler() Hannes Reinecke
2017-06-27 23:57   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 09/35] libsas: move bus_reset_handler() to target_reset_handler() Hannes Reinecke
2017-06-27 23:57   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 10/35] bfa: move bus reset to target reset Hannes Reinecke
2017-06-27 23:57   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 11/35] hptiop: Simplify reset handling Hannes Reinecke
2017-06-27 23:59   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 12/35] fdomain: move bus reset to host reset Hannes Reinecke
2017-06-23 23:49   ` kbuild test robot
2017-06-23 13:02 ` [PATCH 13/35] scsi: drop bus reset for wd33c93-compatible boards Hannes Reinecke
2017-06-28  0:00   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 14/35] rtsx: drop bus reset function Hannes Reinecke
2017-06-28  0:00   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 15/35] qlogicpti: move bus reset to host reset Hannes Reinecke
2017-06-28  0:01   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 16/35] acornscsi: " Hannes Reinecke
2017-06-28  0:01   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 17/35] NCR5380: Move " Hannes Reinecke
2017-06-24  7:24   ` Finn Thain
2017-06-25  8:57     ` Hannes Reinecke
2017-06-23 13:02 ` [PATCH 18/35] qlogicfas: move bus_reset to host_reset Hannes Reinecke
2017-06-28  0:01   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 19/35] aacraid: split off lun reset function Hannes Reinecke
2017-06-23 16:46   ` Dave Carroll
2017-06-23 13:02 ` [PATCH 20/35] sym53c8xx_2: split off bus reset from host reset Hannes Reinecke
2017-06-23 13:02 ` [PATCH 21/35] zfcp: open-code fc_block_scsi_eh() for " Hannes Reinecke
2017-06-23 13:02 ` [PATCH 22/35] scsi: Use Scsi_Host as argument for eh_host_reset_handler Hannes Reinecke
2017-06-23 16:32   ` Bart Van Assche
2017-06-23 23:51   ` kbuild test robot
2017-06-24  0:38   ` kbuild test robot
2017-06-23 13:02 ` [PATCH 23/35] qedf: drop bus reset handler Hannes Reinecke
2017-06-28  0:05   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 24/35] scsi_transport_fc: Use fc_rport as argument for fc_block_scsi_eh Hannes Reinecke
2017-06-23 13:02 ` [PATCH 25/35] mptfc: simplify mpt_fc_block_error_handler() Hannes Reinecke
2017-06-23 13:02 ` [PATCH 26/35] mptfusion: correct definitions for mptscsih_dev_reset() Hannes Reinecke
2017-06-23 13:02 ` [PATCH 27/35] scsi: Use Scsi_Host and channel number as argument for eh_bus_reset_handler() Hannes Reinecke
2017-06-24  0:00   ` kbuild test robot
2017-06-24  0:06   ` kbuild test robot
2017-06-23 13:02 ` [PATCH 28/35] libiscsi: use cls_session as argument for target and session reset Hannes Reinecke
2017-06-23 13:02 ` [PATCH 29/35] bnx2fc: remove obsolete bnx2fc_eh_host_reset() definition Hannes Reinecke
2017-06-28  0:05   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 30/35] bnx2fc: Do not rely on a scsi command when issueing lun or target reset Hannes Reinecke
2017-06-23 13:02 ` [PATCH 31/35] zfcp: do not rely on scsi command for debugging message Hannes Reinecke
2017-06-23 13:02 ` [PATCH 32/35] zfcp: use scsi device as argument for zfcp_task_mgmt_function() Hannes Reinecke
2017-06-23 16:48   ` Bart Van Assche
2017-06-23 13:02 ` [PATCH 33/35] scsi: Use scsi_target as argument for eh_target_reset_handler() Hannes Reinecke
2017-06-23 18:34   ` Bart Van Assche
2017-06-24  0:59   ` kbuild test robot
2017-06-23 13:02 ` [PATCH 34/35] scsi: Move eh_device_reset_handler() to use scsi_device as argument Hannes Reinecke
2017-06-23 18:44   ` Bart Van Assche
2017-06-24  0:46   ` kbuild test robot
2017-06-24  1:10   ` kbuild test robot
2017-06-24  7:07   ` Christoph Hellwig
2017-06-23 13:02 ` [PATCH 35/35] scsi: Do not allocate scsi command in scsi_ioctl_reset() Hannes Reinecke
2017-06-23 17:49   ` Bart Van Assche
2017-06-24  7:09   ` Christoph Hellwig
2017-06-27 23:54 ` [RFC PATCH 00/35] SCSI EH argument reshuffling Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1498222975-71858-7-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).