Commit 61a28d40 authored by Patrick Mansfield's avatar Patrick Mansfield Committed by James Bottomley

[PATCH] 4/7 cleanup/consolidate code in scsi_request_fn

Cleanup and consolidate scsi_device and scsi_host checks in
scsi_request_fn.
parent 13a390f2
...@@ -1042,6 +1042,79 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) ...@@ -1042,6 +1042,79 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
return BLKPREP_OK; return BLKPREP_OK;
} }
/*
* scsi_check_sdev: if we can send requests to sdev, return 0 else return 1.
*
* Called with the queue_lock held.
*/
static inline int scsi_check_sdev(struct request_queue *q,
struct scsi_device *sdev)
{
if (sdev->device_busy >= sdev->queue_depth)
return 1;
if (sdev->device_busy == 0 && sdev->device_blocked) {
/*
* unblock after device_blocked iterates to zero
*/
if (--sdev->device_blocked == 0) {
SCSI_LOG_MLQUEUE(3,
printk("scsi%d (%d:%d) unblocking device at"
" zero depth\n", sdev->host->host_no,
sdev->id, sdev->lun));
} else {
blk_plug_device(q);
return 1;
}
}
if (sdev->device_blocked)
return 1;
return 0;
}
/*
* scsi_check_shost: if we can send requests to shost, return 0 else return 1.
*
* Called with the queue_lock held.
*/
static inline int scsi_check_shost(struct request_queue *q,
struct Scsi_Host *shost,
struct scsi_device *sdev)
{
if (shost->in_recovery)
return 1;
if (shost->host_busy == 0 && shost->host_blocked) {
/*
* unblock after host_blocked iterates to zero
*/
if (--shost->host_blocked == 0) {
SCSI_LOG_MLQUEUE(3,
printk("scsi%d unblocking host at zero depth\n",
shost->host_no));
} else {
blk_plug_device(q);
return 1;
}
}
if (!list_empty(&sdev->starved_entry))
return 1;
if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
shost->host_blocked || shost->host_self_blocked) {
SCSI_LOG_MLQUEUE(3,
printk("add starved dev <%d,%d,%d,%d>; host "
"limit %d, busy %d, blocked %d selfblocked %d\n",
sdev->host->host_no, sdev->channel,
sdev->id, sdev->lun,
shost->can_queue, shost->host_busy,
shost->host_blocked, shost->host_self_blocked));
list_add_tail(&sdev->starved_entry,
&shost->starved_list);
return 1;
}
return 0;
}
/* /*
* Function: scsi_request_fn() * Function: scsi_request_fn()
* *
...@@ -1067,13 +1140,8 @@ static void scsi_request_fn(request_queue_t *q) ...@@ -1067,13 +1140,8 @@ static void scsi_request_fn(request_queue_t *q)
* the host is no longer able to accept any more requests. * the host is no longer able to accept any more requests.
*/ */
for (;;) { for (;;) {
/* if (blk_queue_plugged(q))
* Check this again - each time we loop through we will have break;
* released the lock and grabbed it again, so each time
* we need to check to see if the queue is plugged or not.
*/
if (shost->in_recovery || blk_queue_plugged(q))
return;
/* /*
* get next queueable request. We do this early to make sure * get next queueable request. We do this early to make sure
...@@ -1083,49 +1151,12 @@ static void scsi_request_fn(request_queue_t *q) ...@@ -1083,49 +1151,12 @@ static void scsi_request_fn(request_queue_t *q)
*/ */
req = elv_next_request(q); req = elv_next_request(q);
if (sdev->device_busy >= sdev->queue_depth) if (scsi_check_sdev(q, sdev))
break; break;
if (shost->host_busy == 0 && shost->host_blocked) { if (scsi_check_shost(q, shost, sdev))
/* unblock after host_blocked iterates to zero */
if (--shost->host_blocked == 0) {
SCSI_LOG_MLQUEUE(3,
printk("scsi%d unblocking host at zero depth\n",
shost->host_no));
} else {
blk_plug_device(q);
break;
}
}
if (sdev->device_busy == 0 && sdev->device_blocked) {
/* unblock after device_blocked iterates to zero */
if (--sdev->device_blocked == 0) {
SCSI_LOG_MLQUEUE(3,
printk("scsi%d (%d:%d) unblocking device at zero depth\n",
shost->host_no, sdev->id, sdev->lun));
} else {
blk_plug_device(q);
break;
}
}
/*
* If the device cannot accept another request, then quit.
*/
if (sdev->device_blocked)
break;
if (!list_empty(&sdev->starved_entry))
break; break;
if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
shost->host_blocked || shost->host_self_blocked) {
list_add_tail(&sdev->starved_entry,
&shost->starved_list);
break;
}
if (sdev->single_lun && scsi_single_lun_check(sdev)) if (sdev->single_lun && scsi_single_lun_check(sdev))
break; break;
...@@ -1140,7 +1171,7 @@ static void scsi_request_fn(request_queue_t *q) ...@@ -1140,7 +1171,7 @@ static void scsi_request_fn(request_queue_t *q)
/* If the device is busy, a returning I/O /* If the device is busy, a returning I/O
* will restart the queue. Otherwise, we have * will restart the queue. Otherwise, we have
* to plug the queue */ * to plug the queue */
if(sdev->device_busy == 0) if (sdev->device_busy == 0)
blk_plug_device(q); blk_plug_device(q);
break; break;
} }
......
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