diff mbox series

[37/40] scsi: libiscsi: add new task state for requeues

Message ID 20210403232333.212927-38-michael.christie@oracle.com
State New
Headers show
Series iscsi lock and refcount fix ups | expand

Commit Message

Mike Christie April 3, 2021, 11:23 p.m. UTC
This is a prep patch for the next patch that removes the frwd lock use
when adding to the cmdqueue/requeue. This adds a new state
ISCSI_TASK_REQUEUED so we can quickly check if the cmd is already
requeued for R2T handling.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/scsi/libiscsi.c | 16 ++++++++++++----
 include/scsi/libiscsi.h |  1 +
 2 files changed, 13 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 136531200643..1c134f721a56 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -574,7 +574,7 @@  static bool cleanup_queued_task(struct iscsi_task *task)
 		 * If it's on a list but still running this could be cleanup
 		 * from a TMF or session recovery.
 		 */
-		if (task->state == ISCSI_TASK_RUNNING ||
+		if (task->state == ISCSI_TASK_REQUEUED ||
 		    task->state == ISCSI_TASK_COMPLETED)
 			iscsi_put_task(task);
 	}
@@ -1565,15 +1565,19 @@  void iscsi_requeue_task(struct iscsi_task *task)
 	 * is handling the r2ts while we are adding new ones
 	 */
 	spin_lock_bh(&conn->session->frwd_lock);
-	if (list_empty(&task->running)) {
-		list_add_tail(&task->running, &conn->requeue);
-	} else {
+	spin_lock(&task->lock);
+	if (task->state == ISCSI_TASK_REQUEUED) {
 		/*
 		 * Don't need the extra ref since it's already requeued and
 		 * has a ref.
 		 */
 		iscsi_put_task(task);
+	} else {
+		task->state = ISCSI_TASK_REQUEUED;
+		list_add_tail(&task->running, &conn->requeue);
 	}
+	spin_unlock(&task->lock);
+
 	iscsi_conn_queue_work(conn);
 	spin_unlock_bh(&conn->session->frwd_lock);
 }
@@ -1639,7 +1643,11 @@  static int iscsi_data_xmit(struct iscsi_conn *conn)
 		if (iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_DATA_OUT))
 			break;
 
+		spin_lock_bh(&task->lock);
+		task->state = ISCSI_TASK_RUNNING;
 		list_del_init(&task->running);
+		spin_unlock_bh(&task->lock);
+
 		rc = iscsi_xmit_task(conn, task, true);
 		if (rc)
 			goto done;
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index c053de831c2c..358701227f7f 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -95,6 +95,7 @@  enum {
 	ISCSI_TASK_FREE,
 	ISCSI_TASK_COMPLETED,
 	ISCSI_TASK_PENDING,
+	ISCSI_TASK_REQUEUED,
 	ISCSI_TASK_RUNNING,
 	ISCSI_TASK_ABRT_TMF,		/* aborted due to TMF */
 };