[PATCH 09/14] scsi: core: increase/decrease target_busy if set error handler

JiangJianJun posted 14 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 09/14] scsi: core: increase/decrease target_busy if set error handler
Posted by JiangJianJun 1 month, 2 weeks ago
From: JiangJianJun <jiangjianjun3@h-partners.com>

This is preparation for a genernal target based error handle strategy
to check if to wake up actual error handler, we should enable counter
field scsi_target.target_busy in this case.

Signed-off-by: JiangJianJun <jiangjianjun3@h-partners.com>
---
 drivers/scsi/scsi_lib.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 63bd33af336b..5115ab5d0942 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -393,7 +393,7 @@ void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd)
 
 	scsi_dec_host_busy(shost, cmd);
 
-	if (starget->can_queue > 0)
+	if (starget->can_queue > 0 || starget->eh)
 		atomic_dec(&starget->target_busy);
 
 	sbitmap_put(&sdev->budget_map, cmd->budget_token);
@@ -1412,8 +1412,11 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost,
 		spin_unlock_irq(shost->host_lock);
 	}
 
-	if (starget->can_queue <= 0)
+	if (starget->can_queue <= 0) {
+		if (starget->eh)
+			atomic_inc(&starget->target_busy);
 		return 1;
+	}
 
 	busy = atomic_inc_return(&starget->target_busy) - 1;
 	if (atomic_read(&starget->target_blocked) > 0) {
@@ -1885,7 +1888,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
 out_dec_host_busy:
 	scsi_dec_host_busy(shost, cmd);
 out_dec_target_busy:
-	if (scsi_target(sdev)->can_queue > 0)
+	if (scsi_target(sdev)->can_queue > 0 || scsi_target(sdev)->eh)
 		atomic_dec(&scsi_target(sdev)->target_busy);
 out_put_budget:
 	scsi_mq_put_budget(q, cmd->budget_token);
-- 
2.33.0