linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: James Bottomley <jbottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org,
	Sean Stewart <sean.stewart@netapp.com>,
	Martin George <marting@netapp.com>,
	Hannes Reinecke <hare@suse.de>
Subject: [PATCH 06/16] scsi_dh_alua: use local buffer for VPD inquiry
Date: Fri, 20 Dec 2013 13:13:31 +0100	[thread overview]
Message-ID: <1387541621-54967-7-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1387541621-54967-1-git-send-email-hare@suse.de>

VPD inquiry need to be done only once, so we can be using
a local buffer here.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/device_handler/scsi_dh_alua.c | 45 ++++++++++++++++++------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index adc77ef..49952f4 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -322,16 +322,27 @@ static int alua_check_tpgs(struct scsi_device *sdev, struct alua_dh_data *h)
  */
 static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
 {
+	unsigned char *buff;
+	unsigned char bufflen = 36;
 	int len, timeout = ALUA_FAILOVER_TIMEOUT;
 	unsigned char sense[SCSI_SENSE_BUFFERSIZE];
 	struct scsi_sense_hdr sense_hdr;
 	unsigned retval;
 	unsigned char *d;
 	unsigned long expiry;
+	int err;
 
 	expiry = round_jiffies_up(jiffies + timeout);
  retry:
-	retval = submit_vpd_inquiry(sdev, h->buff, h->bufflen, sense);
+	buff = kmalloc(bufflen, GFP_ATOMIC);
+	if (!buff) {
+		sdev_printk(KERN_WARNING, sdev,
+			    "%s: kmalloc buffer failed\n",
+			    ALUA_DH_NAME);
+		/* Temporary failure, bypass */
+		return SCSI_DH_DEV_TEMP_BUSY;
+	}
+	retval = submit_vpd_inquiry(sdev, buff, bufflen, sense);
 	if (retval) {
 		unsigned err;
 
@@ -345,6 +356,7 @@ static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
 				err = SCSI_DH_DEV_TEMP_BUSY;
 			else
 				err = SCSI_DH_IO;
+			kfree(buff);
 			return err;
 		}
 		err = alua_check_sense(sdev, &sense_hdr);
@@ -362,24 +374,19 @@ static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
 	}
 
 	/* Check if vpd page exceeds initial buffer */
-	len = (h->buff[2] << 8) + h->buff[3] + 4;
-	if (len > h->bufflen) {
+	len = (buff[2] << 8) + buff[3] + 4;
+	if (len > bufflen) {
 		/* Resubmit with the correct length */
-		if (realloc_buffer(h, len)) {
-			sdev_printk(KERN_WARNING, sdev,
-				    "%s: kmalloc buffer failed\n",
-				    ALUA_DH_NAME);
-			/* Temporary failure, bypass */
-			return SCSI_DH_DEV_TEMP_BUSY;
-		}
+		kfree(buff);
+		bufflen = len;
 		goto retry;
 	}
 
 	/*
 	 * Now look for the correct descriptor.
 	 */
-	d = h->buff + 4;
-	while (d < h->buff + len) {
+	d = buff + 4;
+	while (d < buff + len) {
 		switch (d[1] & 0xf) {
 		case 0x4:
 			/* Relative target port */
@@ -406,13 +413,15 @@ static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h)
 			    ALUA_DH_NAME);
 		h->state = TPGS_STATE_OPTIMIZED;
 		h->tpgs = TPGS_MODE_NONE;
-		return SCSI_DH_DEV_UNSUPP;
+		err = SCSI_DH_DEV_UNSUPP;
+	} else {
+		sdev_printk(KERN_INFO, sdev,
+			    "%s: port group %02x rel port %02x\n",
+			    ALUA_DH_NAME, h->group_id, h->rel_port);
+		err = SCSI_DH_OK;
 	}
-	sdev_printk(KERN_INFO, sdev,
-		    "%s: port group %02x rel port %02x\n",
-		    ALUA_DH_NAME, h->group_id, h->rel_port);
-
-	return SCSI_DH_OK;
+	kfree(buff);
+	return err;
 }
 
 static char print_alua_state(int state)
-- 
1.7.12.4


  parent reply	other threads:[~2013-12-20 12:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20 12:13 [PATCH 00/16] scsi_dh_alua updates Hannes Reinecke
2013-12-20 12:13 ` [PATCH 01/16] scsi_dh_alua: Improve error handling Hannes Reinecke
2013-12-20 12:13 ` [PATCH 02/16] scsi_dh_alua: use flag for RTPG extended header Hannes Reinecke
2013-12-20 12:13 ` [PATCH 03/16] scsi_dh_alua: Pass buffer as function argument Hannes Reinecke
2013-12-20 12:13 ` [PATCH 04/16] scsi_dh_alua: Make stpg synchronous Hannes Reinecke
2013-12-20 12:13 ` [PATCH 05/16] scsi_dh_alua: put sense buffer on stack Hannes Reinecke
2013-12-20 12:13 ` Hannes Reinecke [this message]
2014-01-17  9:04   ` [PATCH 06/16] scsi_dh_alua: use local buffer for VPD inquiry Mike Christie
2014-01-17  9:38     ` Hannes Reinecke
2013-12-20 12:13 ` [PATCH 07/16] scsi_dh_alua: Use separate alua_port_group structure Hannes Reinecke
2013-12-20 12:13 ` [PATCH 08/16] scsi_dh_alua: parse target device id Hannes Reinecke
2013-12-20 12:13 ` [PATCH 09/16] scsi_dh_alua: simplify sense code handling Hannes Reinecke
2013-12-20 12:13 ` [PATCH 10/16] scsi_dh_alua: Do not attach to management devices Hannes Reinecke
2013-12-20 12:13 ` [PATCH 11/16] scsi_dh_alua: multipath failover fails with error 15 Hannes Reinecke
2013-12-20 12:13 ` [PATCH 12/16] scsi_dh: return individual errors in scsi_dh_activate() Hannes Reinecke
2013-12-20 12:13 ` [PATCH 13/16] scsi_dh_alua: Clarify logging message Hannes Reinecke
2013-12-20 12:13 ` [PATCH 14/16] scsi_dh: invoke callback if ->activate is not present Hannes Reinecke
2013-12-20 12:13 ` [PATCH 15/16] scsi_dh_alua: revert commit a8e5a2d593cbfccf530c3382c2c328d2edaa7b66 Hannes Reinecke
2013-12-20 12:13 ` [PATCH 16/16] scsi_dh_alua: Use workqueue for RTPG Hannes Reinecke
2014-01-21  8:25   ` Vaughan Cao
  -- strict thread matches above, loose matches on Subject: below --
2014-01-31  9:29 [PATCHv2 00/16] scsi_dh_alua updates Hannes Reinecke
2014-01-31  9:29 ` [PATCH 06/16] scsi_dh_alua: use local buffer for VPD inquiry Hannes Reinecke
2014-02-13  9:51   ` Maurizio Lombardi
2014-02-13 10:10     ` Hannes Reinecke
2014-02-14 11:41   ` Bart Van Assche

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=1387541621-54967-7-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=jbottomley@parallels.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=marting@netapp.com \
    --cc=sean.stewart@netapp.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).