aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorKiyoshi Ueda <k-ueda@ct.jp.nec.com>2008-10-04 14:11:06 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-10-23 12:42:16 -0400
commit9d11251709f31d49c8167a619d4475fdf6cd7f73 (patch)
tree0658cf513d86730d785b94eb2dd469ac4d0a51b0 /drivers/scsi
parent22ab019b6ff8f3f93ddc93135d7e7ff24d982fe0 (diff)
[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: Kiyoshi Ueda <k-ueda@ct.jp.nec.com> Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/scsi_lib.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f35a0951e469..1e7c9e9ef772 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -529,6 +529,14 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev)
529 spin_unlock_irqrestore(shost->host_lock, flags); 529 spin_unlock_irqrestore(shost->host_lock, flags);
530} 530}
531 531
532static inline int scsi_device_is_busy(struct scsi_device *sdev)
533{
534 if (sdev->device_busy >= sdev->queue_depth || sdev->device_blocked)
535 return 1;
536
537 return 0;
538}
539
532static inline int scsi_target_is_busy(struct scsi_target *starget) 540static inline int scsi_target_is_busy(struct scsi_target *starget)
533{ 541{
534 return ((starget->can_queue > 0 && 542 return ((starget->can_queue > 0 &&
@@ -536,6 +544,15 @@ static inline int scsi_target_is_busy(struct scsi_target *starget)
536 starget->target_blocked); 544 starget->target_blocked);
537} 545}
538 546
547static inline int scsi_host_is_busy(struct Scsi_Host *shost)
548{
549 if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
550 shost->host_blocked || shost->host_self_blocked)
551 return 1;
552
553 return 0;
554}
555
539/* 556/*
540 * Function: scsi_run_queue() 557 * Function: scsi_run_queue()
541 * 558 *
@@ -558,11 +575,7 @@ static void scsi_run_queue(struct request_queue *q)
558 scsi_single_lun_run(sdev); 575 scsi_single_lun_run(sdev);
559 576
560 spin_lock_irqsave(shost->host_lock, flags); 577 spin_lock_irqsave(shost->host_lock, flags);
561 while (!list_empty(&shost->starved_list) && 578 while (!list_empty(&shost->starved_list) && !scsi_host_is_busy(shost)) {
562 !shost->host_blocked && !shost->host_self_blocked &&
563 !((shost->can_queue > 0) &&
564 (shost->host_busy >= shost->can_queue))) {
565
566 int flagset; 579 int flagset;
567 580
568 /* 581 /*
@@ -1348,8 +1361,6 @@ int scsi_prep_fn(struct request_queue *q, struct request *req)
1348static inline int scsi_dev_queue_ready(struct request_queue *q, 1361static inline int scsi_dev_queue_ready(struct request_queue *q,
1349 struct scsi_device *sdev) 1362 struct scsi_device *sdev)
1350{ 1363{
1351 if (sdev->device_busy >= sdev->queue_depth)
1352 return 0;
1353 if (sdev->device_busy == 0 && sdev->device_blocked) { 1364 if (sdev->device_busy == 0 && sdev->device_blocked) {
1354 /* 1365 /*
1355 * unblock after device_blocked iterates to zero 1366 * unblock after device_blocked iterates to zero
@@ -1363,7 +1374,7 @@ static inline int scsi_dev_queue_ready(struct request_queue *q,
1363 return 0; 1374 return 0;
1364 } 1375 }
1365 } 1376 }
1366 if (sdev->device_blocked) 1377 if (scsi_device_is_busy(sdev))
1367 return 0; 1378 return 0;
1368 1379
1369 return 1; 1380 return 1;
@@ -1440,8 +1451,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1440 return 0; 1451 return 0;
1441 } 1452 }
1442 } 1453 }
1443 if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) || 1454 if (scsi_host_is_busy(shost)) {
1444 shost->host_blocked || shost->host_self_blocked) {
1445 if (list_empty(&sdev->starved_entry)) 1455 if (list_empty(&sdev->starved_entry))
1446 list_add_tail(&sdev->starved_entry, &shost->starved_list); 1456 list_add_tail(&sdev->starved_entry, &shost->starved_list);
1447 return 0; 1457 return 0;