Commit 9d112517 authored by Kiyoshi Ueda's avatar Kiyoshi Ueda Committed by James Bottomley

[SCSI] refactor sdev/starget/shost busy checking

This patch refactors the busy checking codes of scsi_device,
Scsi_Host and scsi_target.  There should be no functional change.

This is a preparation for another patch which exports scsi's busy
state to the block layer for request stacking drivers.
Signed-off-by: default avatarKiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: default avatarJun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 22ab019b
...@@ -529,6 +529,14 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev) ...@@ -529,6 +529,14 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev)
spin_unlock_irqrestore(shost->host_lock, flags); spin_unlock_irqrestore(shost->host_lock, flags);
} }
static inline int scsi_device_is_busy(struct scsi_device *sdev)
{
if (sdev->device_busy >= sdev->queue_depth || sdev->device_blocked)
return 1;
return 0;
}
static inline int scsi_target_is_busy(struct scsi_target *starget) static inline int scsi_target_is_busy(struct scsi_target *starget)
{ {
return ((starget->can_queue > 0 && return ((starget->can_queue > 0 &&
...@@ -536,6 +544,15 @@ static inline int scsi_target_is_busy(struct scsi_target *starget) ...@@ -536,6 +544,15 @@ static inline int scsi_target_is_busy(struct scsi_target *starget)
starget->target_blocked); starget->target_blocked);
} }
static inline int scsi_host_is_busy(struct Scsi_Host *shost)
{
if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
shost->host_blocked || shost->host_self_blocked)
return 1;
return 0;
}
/* /*
* Function: scsi_run_queue() * Function: scsi_run_queue()
* *
...@@ -558,11 +575,7 @@ static void scsi_run_queue(struct request_queue *q) ...@@ -558,11 +575,7 @@ static void scsi_run_queue(struct request_queue *q)
scsi_single_lun_run(sdev); scsi_single_lun_run(sdev);
spin_lock_irqsave(shost->host_lock, flags); spin_lock_irqsave(shost->host_lock, flags);
while (!list_empty(&shost->starved_list) && while (!list_empty(&shost->starved_list) && !scsi_host_is_busy(shost)) {
!shost->host_blocked && !shost->host_self_blocked &&
!((shost->can_queue > 0) &&
(shost->host_busy >= shost->can_queue))) {
int flagset; int flagset;
/* /*
...@@ -1348,8 +1361,6 @@ int scsi_prep_fn(struct request_queue *q, struct request *req) ...@@ -1348,8 +1361,6 @@ int scsi_prep_fn(struct request_queue *q, struct request *req)
static inline int scsi_dev_queue_ready(struct request_queue *q, static inline int scsi_dev_queue_ready(struct request_queue *q,
struct scsi_device *sdev) struct scsi_device *sdev)
{ {
if (sdev->device_busy >= sdev->queue_depth)
return 0;
if (sdev->device_busy == 0 && sdev->device_blocked) { if (sdev->device_busy == 0 && sdev->device_blocked) {
/* /*
* unblock after device_blocked iterates to zero * unblock after device_blocked iterates to zero
...@@ -1363,7 +1374,7 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, ...@@ -1363,7 +1374,7 @@ static inline int scsi_dev_queue_ready(struct request_queue *q,
return 0; return 0;
} }
} }
if (sdev->device_blocked) if (scsi_device_is_busy(sdev))
return 0; return 0;
return 1; return 1;
...@@ -1440,8 +1451,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q, ...@@ -1440,8 +1451,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
return 0; return 0;
} }
} }
if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) || if (scsi_host_is_busy(shost)) {
shost->host_blocked || shost->host_self_blocked) {
if (list_empty(&sdev->starved_entry)) if (list_empty(&sdev->starved_entry))
list_add_tail(&sdev->starved_entry, &shost->starved_list); list_add_tail(&sdev->starved_entry, &shost->starved_list);
return 0; return 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