Commit c270e476 authored by Patrick Mansfield's avatar Patrick Mansfield Committed by James Bottomley

[PATCH] 5/7 alloc a request_queue on each scsi_alloc_sdev call

Call scsi_alloc_queue each time we call scsi_alloc_sdev; call
scsi_free_queue each time we do not find backing LUN.

This code is less optimal, but leads to cleaner code, and the lock
split-up patch needs this change.
parent 61a28d40
......@@ -380,7 +380,7 @@ static void print_inquiry(unsigned char *inq_result)
* Scsi_Device pointer, or NULL on failure.
**/
static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
struct request_queue **q, uint channel, uint id, uint lun)
uint channel, uint id, uint lun)
{
struct scsi_device *sdev, *device;
......@@ -415,14 +415,9 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
*/
sdev->borken = 1;
if (!q || *q == NULL) {
sdev->request_queue = scsi_alloc_queue(shost);
if (!sdev->request_queue)
goto out_free_dev;
} else {
sdev->request_queue = *q;
*q = NULL;
}
sdev->request_queue->queuedata = sdev;
scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
......@@ -462,10 +457,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
return sdev;
out_free_queue:
if (q && sdev->request_queue) {
*q = sdev->request_queue;
sdev->request_queue = NULL;
} else if (sdev->request_queue)
if (sdev->request_queue)
scsi_free_queue(sdev->request_queue);
out_free_dev:
......@@ -1282,15 +1274,15 @@ static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq,
* SCSI_SCAN_LUN_PRESENT: a new Scsi_Device was allocated and initialized
**/
static int scsi_probe_and_add_lun(struct Scsi_Host *host,
struct request_queue **q, uint channel, uint id, uint lun,
int *bflagsp, struct scsi_device **sdevp)
uint channel, uint id, uint lun, int *bflagsp,
struct scsi_device **sdevp)
{
struct scsi_device *sdev;
struct scsi_request *sreq;
unsigned char *result;
int bflags, res = SCSI_SCAN_NO_RESPONSE;
sdev = scsi_alloc_sdev(host, q, channel, id, lun);
sdev = scsi_alloc_sdev(host, channel, id, lun);
if (!sdev)
goto out;
sreq = scsi_allocate_request(sdev);
......@@ -1344,13 +1336,8 @@ static int scsi_probe_and_add_lun(struct Scsi_Host *host,
if (res == SCSI_SCAN_LUN_PRESENT) {
if (sdevp)
*sdevp = sdev;
} else {
if (q) {
*q = sdev->request_queue;
sdev->request_queue = NULL;
}
} else
scsi_free_sdev(sdev);
}
out:
return res;
}
......@@ -1368,9 +1355,8 @@ static int scsi_probe_and_add_lun(struct Scsi_Host *host,
*
* Modifies sdevscan->lun.
**/
static void scsi_sequential_lun_scan(struct Scsi_Host *shost,
struct request_queue **q, uint channel, uint id,
int bflags, int lun0_res, int scsi_level)
static void scsi_sequential_lun_scan(struct Scsi_Host *shost, uint channel,
uint id, int bflags, int lun0_res, int scsi_level)
{
unsigned int sparse_lun, lun, max_dev_lun;
......@@ -1438,7 +1424,7 @@ static void scsi_sequential_lun_scan(struct Scsi_Host *shost,
* sparse_lun.
*/
for (lun = 1; lun < max_dev_lun; ++lun)
if ((scsi_probe_and_add_lun(shost, q, channel, id, lun,
if ((scsi_probe_and_add_lun(shost, channel, id, lun,
NULL, NULL) != SCSI_SCAN_LUN_PRESENT) && !sparse_lun)
return;
}
......@@ -1491,8 +1477,7 @@ static int scsilun_to_int(ScsiLun *scsilun)
* 0: scan completed (or no memory, so further scanning is futile)
* 1: no report lun scan, or not configured
**/
static int scsi_report_lun_scan(Scsi_Device *sdev, struct request_queue **q,
int bflags)
static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
{
#ifdef CONFIG_SCSI_REPORT_LUNS
......@@ -1653,8 +1638,8 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, struct request_queue **q,
} else {
int res;
res = scsi_probe_and_add_lun(sdev->host, q,
sdev->channel, sdev->id, lun, NULL, NULL);
res = scsi_probe_and_add_lun(sdev->host, sdev->channel,
sdev->id, lun, NULL, NULL);
if (res == SCSI_SCAN_NO_RESPONSE) {
/*
* Got some results, but now none, abort.
......@@ -1682,8 +1667,7 @@ struct scsi_device *scsi_add_device(struct Scsi_Host *shost,
struct scsi_device *sdev;
int error = -ENODEV, res;
res = scsi_probe_and_add_lun(shost, NULL, channel, id, lun,
NULL, &sdev);
res = scsi_probe_and_add_lun(shost, channel, id, lun, NULL, &sdev);
if (res == SCSI_SCAN_LUN_PRESENT)
error = scsi_attach_device(sdev);
......@@ -1724,8 +1708,8 @@ int scsi_remove_device(struct scsi_device *sdev)
* First try a REPORT LUN scan, if that does not scan the target, do a
* sequential scan of LUNs on the target id.
**/
static void scsi_scan_target(struct Scsi_Host *shost, struct request_queue **q,
unsigned int channel, unsigned int id)
static void scsi_scan_target(struct Scsi_Host *shost, unsigned int channel,
unsigned int id)
{
int bflags = 0;
int res;
......@@ -1741,14 +1725,14 @@ static void scsi_scan_target(struct Scsi_Host *shost, struct request_queue **q,
* Scan LUN 0, if there is some response, scan further. Ideally, we
* would not configure LUN 0 until all LUNs are scanned.
*/
res = scsi_probe_and_add_lun(shost, q, channel, id, 0, &bflags, &sdev);
res = scsi_probe_and_add_lun(shost, channel, id, 0, &bflags, &sdev);
if (res == SCSI_SCAN_LUN_PRESENT) {
if (scsi_report_lun_scan(sdev, q, bflags) != 0)
if (scsi_report_lun_scan(sdev, bflags) != 0)
/*
* The REPORT LUN did not scan the target,
* do a sequential scan.
*/
scsi_sequential_lun_scan(shost, q, channel, id, bflags,
scsi_sequential_lun_scan(shost, channel, id, bflags,
res, sdev->scsi_level);
} else if (res == SCSI_SCAN_TARGET_PRESENT) {
/*
......@@ -1757,7 +1741,7 @@ static void scsi_scan_target(struct Scsi_Host *shost, struct request_queue **q,
* sequential lun scan with a bflags of SPARSELUN and
* a default scsi level of SCSI_2
*/
scsi_sequential_lun_scan(shost, q, channel, id, BLIST_SPARSELUN,
scsi_sequential_lun_scan(shost, channel, id, BLIST_SPARSELUN,
SCSI_SCAN_TARGET_PRESENT, SCSI_2);
}
}
......@@ -1772,7 +1756,6 @@ static void scsi_scan_target(struct Scsi_Host *shost, struct request_queue **q,
**/
void scsi_scan_host(struct Scsi_Host *shost)
{
struct request_queue *q = NULL;
uint channel, id, order_id;
/*
......@@ -1797,12 +1780,9 @@ void scsi_scan_host(struct Scsi_Host *shost)
order_id = shost->max_id - id - 1;
else
order_id = id;
scsi_scan_target(shost, &q, channel, order_id);
scsi_scan_target(shost, channel, order_id);
}
}
if (q)
scsi_free_queue(q);
}
void scsi_forget_host(struct Scsi_Host *shost)
......@@ -1841,7 +1821,7 @@ struct scsi_device *scsi_get_host_dev(struct Scsi_Host *shost)
{
struct scsi_device *sdev;
sdev = scsi_alloc_sdev(shost, NULL, 0, shost->this_id, 0);
sdev = scsi_alloc_sdev(shost, 0, shost->this_id, 0);
if (sdev) {
sdev->borken = 0;
}
......
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