From: Hannes Reinecke <hare@suse.de>
To: James Bottomley <james.bottomley@hansenpartnership.com>
Cc: linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Bart van Assche <bart.vanassche@sandisk.com>,
Ewan Milne <emilne@redhat.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH 25/36] scsi_dh_alua: simplify alua_initialize()
Date: Tue, 29 Sep 2015 12:47:27 +0200 [thread overview]
Message-ID: <1443523658-87622-26-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1443523658-87622-1-git-send-email-hare@suse.de>
Rework alua_check_vpd() to use scsi_vpd_get_tpg()
and move the port group selection into the function, too.
With that we can simplify alua_initialize() to just
call alua_check_tpgs() and alua_check_vpd();
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/scsi/device_handler/scsi_dh_alua.c | 99 ++++++++++--------------------
1 file changed, 34 insertions(+), 65 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index e2e6177..1755591 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -82,7 +82,6 @@ struct alua_port_group {
struct alua_dh_data {
struct alua_port_group *pg;
- int group_id;
int rel_port;
struct scsi_device *sdev;
activate_complete callback_fn;
@@ -92,6 +91,7 @@ struct alua_dh_data {
#define ALUA_POLICY_SWITCH_CURRENT 0
#define ALUA_POLICY_SWITCH_ALL 1
+static int alua_rtpg(struct scsi_device *, struct alua_port_group *, int);
static char print_alua_state(int);
static void release_port_group(struct kref *kref)
@@ -292,35 +292,18 @@ static int alua_check_tpgs(struct scsi_device *sdev)
*
* Extract the relative target port and the target port group
* descriptor from the list of identificators.
+ *
+ * Returns 0 or SCSI_DH_ error code on failure.
*/
-static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h)
+static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h,
+ int tpgs)
{
- unsigned char *d;
-
- if (!sdev->vpd_pg83)
- return SCSI_DH_DEV_UNSUPP;
-
- /*
- * Look for the correct descriptor.
- */
- d = sdev->vpd_pg83 + 4;
- while (d < sdev->vpd_pg83 + sdev->vpd_pg83_len) {
- switch (d[1] & 0xf) {
- case 0x4:
- /* Relative target port */
- h->rel_port = get_unaligned_be16(&d[6]);
- break;
- case 0x5:
- /* Target port group */
- h->group_id = get_unaligned_be16(&d[6]);
- break;
- default:
- break;
- }
- d += d[3] + 4;
- }
+ int rel_port = -1, group_id;
+ char id_str[256];
+ int id_size;
- if (h->group_id == -1) {
+ group_id = scsi_vpd_tpg_id(sdev, &rel_port);
+ if (group_id < 0) {
/*
* Internal error; TPGS supported but required
* VPD identification descriptors not present.
@@ -331,11 +314,29 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h)
ALUA_DH_NAME);
return SCSI_DH_DEV_UNSUPP;
}
+ h->rel_port = rel_port;
+
+ id_size = scsi_vpd_lun_id(sdev, id_str, 256);
+ if (id_size <= 0) {
+ /*
+ * Internal error: TPGS supported but no device
+ * identifcation found. Disable ALUA support.
+ */
+ sdev_printk(KERN_INFO, sdev,
+ "%s: No device descriptors found\n",
+ ALUA_DH_NAME);
+ return SCSI_DH_DEV_UNSUPP;
+ }
sdev_printk(KERN_INFO, sdev,
- "%s: port group %02x rel port %02x\n",
- ALUA_DH_NAME, h->group_id, h->rel_port);
+ "%s: device %s port group %02x "
+ "rel port %02x\n", ALUA_DH_NAME,
+ id_str, group_id, h->rel_port);
- return 0;
+ h->pg = alua_get_pg(sdev, group_id, tpgs, id_str, id_size);
+ if (!h->pg)
+ return SCSI_DH_NOMEM;
+
+ return alua_rtpg(sdev, h->pg, 0);
}
static char print_alua_state(int state)
@@ -653,46 +654,14 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg)
static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h)
{
int err = SCSI_DH_DEV_UNSUPP, tpgs;
- char device_id_str[256];
- int device_id_len;
tpgs = alua_check_tpgs(sdev);
- if (tpgs == TPGS_MODE_NONE)
- goto out;
-
- err = alua_check_vpd(sdev, h);
- if (err != SCSI_DH_OK)
- goto out;
+ if (tpgs != TPGS_MODE_NONE)
+ err = alua_check_vpd(sdev, h, tpgs);
- device_id_len = scsi_vpd_lun_id(sdev, device_id_str,
- sizeof(device_id_str));
- if (device_id_len <= 0) {
- /*
- * Internal error: TPGS supported but no device
- * identifcation found. Disable ALUA support.
- */
- sdev_printk(KERN_INFO, sdev,
- "%s: No device descriptors found\n",
- ALUA_DH_NAME);
- goto out;
- }
- sdev_printk(KERN_INFO, sdev,
- "%s: device %s port group %02x "
- "rel port %02x\n", ALUA_DH_NAME,
- device_id_str, h->group_id, h->rel_port);
-
- h->pg = alua_get_pg(sdev, h->group_id, tpgs,
- device_id_str, device_id_len);
- if (!h->pg) {
- err = SCSI_DH_NOMEM;
- goto out;
- }
- kref_get(&h->pg->kref);
- err = alua_rtpg(sdev, h->pg, 0);
- kref_put(&h->pg->kref, release_port_group);
-out:
return err;
}
+
/*
* alua_set_params - set/unset the optimize flag
* @sdev: device on the path to be activated
--
1.8.5.6
next prev parent reply other threads:[~2015-09-29 10:48 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 10:47 [PATCHv5 00/36] asynchronous ALUA device handler Hannes Reinecke
2015-09-29 10:47 ` [PATCH 01/36] scsi_dh: move 'dh_state' sysfs attribute to generic code Hannes Reinecke
2015-10-01 23:18 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 02/36] scsi: ignore errors from scsi_dh_add_device() Hannes Reinecke
2015-09-29 10:47 ` [PATCH 03/36] scsi_dh_alua: Disable ALUA handling for non-disk devices Hannes Reinecke
2015-09-29 10:47 ` [PATCH 04/36] scsi_dh_alua: Use vpd_pg83 information Hannes Reinecke
2015-09-29 10:47 ` [PATCH 05/36] scsi_dh_alua: improved logging Hannes Reinecke
2015-09-29 10:47 ` [PATCH 06/36] scsi_dh_alua: sanitze sense code handling Hannes Reinecke
2015-10-01 23:39 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 07/36] scsi_dh_alua: use standard logging functions Hannes Reinecke
2015-10-01 23:50 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 08/36] scsi_dh_alua: return standard SCSI return codes in submit_rtpg Hannes Reinecke
2015-10-01 23:58 ` Bart Van Assche
2015-10-02 6:03 ` Hannes Reinecke
2015-09-29 10:47 ` [PATCH 09/36] scsi_dh_alua: fixup description of stpg_endio() Hannes Reinecke
2015-09-29 10:47 ` [PATCH 10/36] scsi: remove scsi_show_sense_hdr() Hannes Reinecke
2015-09-29 10:47 ` [PATCH 11/36] scsi_dh_alua: use flag for RTPG extended header Hannes Reinecke
2015-09-29 10:47 ` [PATCH 12/36] scsi_dh_alua: use unaligned access macros Hannes Reinecke
2015-10-02 0:01 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 13/36] scsi_dh_alua: Pass buffer as function argument Hannes Reinecke
2015-09-29 10:47 ` [PATCH 14/36] scsi_dh_alua: separate out alua_stpg() Hannes Reinecke
2015-10-02 0:07 ` Bart Van Assche
2015-10-02 6:06 ` Hannes Reinecke
2015-10-02 15:03 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 15/36] scsi_dh_alua: Make stpg synchronous Hannes Reinecke
2015-10-02 17:33 ` Bart Van Assche
2015-10-07 20:48 ` Hannes Reinecke
2015-09-29 10:47 ` [PATCH 16/36] scsi_dh_alua: call alua_rtpg() if stpg fails Hannes Reinecke
2015-10-02 17:14 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 17/36] scsi_dh_alua: switch to scsi_execute_req_flags() Hannes Reinecke
2015-09-29 10:47 ` [PATCH 18/36] scsi_dh_alua: rework alua_check_tpgs() to return the tpgs mode Hannes Reinecke
2015-09-29 10:47 ` [PATCH 19/36] scsi_dh_alua: Use separate alua_port_group structure Hannes Reinecke
2015-09-29 10:47 ` [PATCH 20/36] scsi_dh_alua: allocate RTPG buffer separately Hannes Reinecke
2015-09-29 10:47 ` [PATCH 21/36] scsi_dh_alua: simplify sense code handling Hannes Reinecke
2015-09-29 10:47 ` [PATCH 22/36] scsi: Add scsi_vpd_lun_id() Hannes Reinecke
2015-09-29 10:47 ` [PATCH 23/36] scsi_dh_alua: use unique device id Hannes Reinecke
2015-09-29 10:47 ` [PATCH 24/36] scsi: Add scsi_vpd_tpg_id() Hannes Reinecke
2015-09-29 10:47 ` Hannes Reinecke [this message]
2015-09-29 10:47 ` [PATCH 26/36] revert "scsi_dh_alua: ALUA hander attach should succeed while TPG is transitioning" Hannes Reinecke
2015-09-29 10:47 ` [PATCH 27/36] scsi_dh_alua: Use workqueue for RTPG Hannes Reinecke
2015-09-29 13:27 ` kbuild test robot
2015-10-01 23:34 ` Bart Van Assche
2015-10-02 5:59 ` Hannes Reinecke
2015-09-29 10:47 ` [PATCH 28/36] scsi_dh_alua: Recheck state on unit attention Hannes Reinecke
2015-09-29 10:47 ` [PATCH 29/36] scsi_dh_alua: update all port states Hannes Reinecke
2015-09-29 10:47 ` [PATCH 30/36] scsi_dh_alua: Send TEST UNIT READY to poll for transitioning Hannes Reinecke
2015-09-29 10:47 ` [PATCH 31/36] scsi: rescan VPD attributes Hannes Reinecke
2015-09-29 13:38 ` kbuild test robot
2015-09-29 13:40 ` kbuild test robot
2015-09-29 13:40 ` [PATCH] scsi: fix ifnullfree.cocci warnings kbuild test robot
2015-09-29 10:47 ` [PATCH 32/36] scsi_dh: add 'rescan' callback Hannes Reinecke
2015-09-29 10:47 ` [PATCH 33/36] scsi: Add 'access_state' attribute Hannes Reinecke
2015-09-29 13:51 ` kbuild test robot
2015-10-01 23:04 ` Bart Van Assche
2015-09-29 10:47 ` [PATCH 34/36] scsi_dh_alua: use common definitions for ALUA state Hannes Reinecke
2015-09-29 10:47 ` [PATCH 35/36] scsi_dh_alua: update 'access_state' field Hannes Reinecke
2015-09-29 10:47 ` [PATCH 36/36] scsi_dh_alua: Update version to 2.0 Hannes Reinecke
2015-09-29 18:29 ` [PATCHv5 00/36] asynchronous ALUA device handler Bart Van Assche
2015-09-30 13:21 ` Hannes Reinecke
2015-09-30 21:32 ` Bart Van Assche
2015-10-13 9:44 ` Hannes Reinecke
2015-10-13 15:07 ` Bart Van Assche
2015-10-13 15:13 ` Hannes Reinecke
2015-10-13 15:40 ` 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=1443523658-87622-26-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=bart.vanassche@sandisk.com \
--cc=emilne@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.