1 Subject: [SCSI] refactor sdev/starget/shost busy checking
2 From: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
3 Date: Thu Oct 23 11:42:16 2008 -0500:
4 Git: 9d11251709f31d49c8167a619d4475fdf6cd7f73
6 This patch refactors the busy checking codes of scsi_device,
7 Scsi_Host and scsi_target. There should be no functional change.
9 This is a preparation for another patch which exports scsi's busy
10 state to the block layer for request stacking drivers.
12 Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
13 Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
14 Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
15 Signed-off-by: Hannes Reinecke <hare@suse.de>
18 drivers/scsi/scsi_lib.c | 30 ++++++++++++++++++++----------
19 1 file changed, 20 insertions(+), 10 deletions(-)
21 --- a/drivers/scsi/scsi_lib.c
22 +++ b/drivers/scsi/scsi_lib.c
23 @@ -529,6 +529,14 @@ static void scsi_single_lun_run(struct s
24 spin_unlock_irqrestore(shost->host_lock, flags);
27 +static inline int scsi_device_is_busy(struct scsi_device *sdev)
29 + if (sdev->device_busy >= sdev->queue_depth || sdev->device_blocked)
35 static inline int scsi_target_is_busy(struct scsi_target *starget)
37 return ((starget->can_queue > 0 &&
38 @@ -536,6 +544,15 @@ static inline int scsi_target_is_busy(st
39 starget->target_blocked);
42 +static inline int scsi_host_is_busy(struct Scsi_Host *shost)
44 + if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
45 + shost->host_blocked || shost->host_self_blocked)
52 * Function: scsi_run_queue()
54 @@ -558,11 +575,7 @@ static void scsi_run_queue(struct reques
55 scsi_single_lun_run(sdev);
57 spin_lock_irqsave(shost->host_lock, flags);
58 - while (!list_empty(&shost->starved_list) &&
59 - !shost->host_blocked && !shost->host_self_blocked &&
60 - !((shost->can_queue > 0) &&
61 - (shost->host_busy >= shost->can_queue))) {
63 + while (!list_empty(&shost->starved_list) && !scsi_host_is_busy(shost)) {
67 @@ -1349,8 +1362,6 @@ EXPORT_SYMBOL(scsi_prep_fn);
68 static inline int scsi_dev_queue_ready(struct request_queue *q,
69 struct scsi_device *sdev)
71 - if (sdev->device_busy >= sdev->queue_depth)
73 if (sdev->device_busy == 0 && sdev->device_blocked) {
75 * unblock after device_blocked iterates to zero
76 @@ -1364,7 +1375,7 @@ static inline int scsi_dev_queue_ready(s
80 - if (sdev->device_blocked)
81 + if (scsi_device_is_busy(sdev))
85 @@ -1441,8 +1452,7 @@ static inline int scsi_host_queue_ready(
89 - if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
90 - shost->host_blocked || shost->host_self_blocked) {
91 + if (scsi_host_is_busy(shost)) {
92 if (list_empty(&sdev->starved_entry))
93 list_add_tail(&sdev->starved_entry, &shost->starved_list);