Commit a4253fde authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Martin K. Petersen

scsi_dh_alua: simplify alua_initialize()

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();
Reviewed-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 0047220c
...@@ -92,6 +92,7 @@ struct alua_dh_data { ...@@ -92,6 +92,7 @@ struct alua_dh_data {
#define ALUA_POLICY_SWITCH_CURRENT 0 #define ALUA_POLICY_SWITCH_CURRENT 0
#define ALUA_POLICY_SWITCH_ALL 1 #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 char print_alua_state(int);
static void release_port_group(struct kref *kref) static void release_port_group(struct kref *kref)
...@@ -294,7 +295,8 @@ static int alua_check_tpgs(struct scsi_device *sdev) ...@@ -294,7 +295,8 @@ static int alua_check_tpgs(struct scsi_device *sdev)
* Extract the relative target port and the target port group * Extract the relative target port and the target port group
* descriptor from the list of identificators. * descriptor from the list of identificators.
*/ */
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)
{ {
int rel_port = -1, group_id; int rel_port = -1, group_id;
...@@ -310,13 +312,21 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h) ...@@ -310,13 +312,21 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h)
ALUA_DH_NAME); ALUA_DH_NAME);
return SCSI_DH_DEV_UNSUPP; return SCSI_DH_DEV_UNSUPP;
} }
h->group_id = group_id;
h->pg = alua_alloc_pg(sdev, group_id, tpgs);
if (IS_ERR(h->pg)) {
if (PTR_ERR(h->pg) == -ENOMEM)
return SCSI_DH_NOMEM;
return SCSI_DH_DEV_UNSUPP;
}
h->rel_port = rel_port;
sdev_printk(KERN_INFO, sdev, sdev_printk(KERN_INFO, sdev,
"%s: port group %x rel port %x\n", "%s: device %s port group %x rel port %x\n",
ALUA_DH_NAME, h->group_id, h->rel_port); ALUA_DH_NAME, h->pg->device_id_str,
h->group_id, h->rel_port);
return 0; return alua_rtpg(sdev, h->pg, 0);
} }
static char print_alua_state(int state) static char print_alua_state(int state)
...@@ -633,23 +643,9 @@ static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h) ...@@ -633,23 +643,9 @@ static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h)
int err = SCSI_DH_DEV_UNSUPP, tpgs; int err = SCSI_DH_DEV_UNSUPP, tpgs;
tpgs = alua_check_tpgs(sdev); tpgs = alua_check_tpgs(sdev);
if (tpgs == TPGS_MODE_NONE) if (tpgs != TPGS_MODE_NONE)
goto out; err = alua_check_vpd(sdev, h, tpgs);
err = alua_check_vpd(sdev, h);
if (err != SCSI_DH_OK)
goto out;
h->pg = alua_alloc_pg(sdev, h->group_id, tpgs);
if (IS_ERR(h->pg)) {
if (PTR_ERR(h->pg) == -ENOMEM)
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; return err;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment