git: a3af69fa81d2 - main - iscsi: Abort fewer data-out tasks on a terminating session.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 18 Jan 2022 17:30:03 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=a3af69fa81d2341a3864edc67419de3b3bad77d9

commit a3af69fa81d2341a3864edc67419de3b3bad77d9
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-01-18 17:28:43 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-01-18 17:28:43 +0000

    iscsi: Abort fewer data-out tasks on a terminating session.
    
    Only abort tasks queued for datamove after
    cfiscsi_sesssion_terminate_tasks has posted its internal
    CTL_TASK_I_T_NEXUS_RESET task.
    
    Reported by:    Jithesh Arakkan @ Chelsio
    Reviewed by:    mav
    Fixes:          0cd6e85e242b iscsi: Abort data-out tasks queued on a terminating session.
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D33747
---
 sys/cam/ctl/ctl_frontend_iscsi.c | 7 ++++++-
 sys/cam/ctl/ctl_frontend_iscsi.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c
index 6368a81fe66f..42abc49b7025 100644
--- a/sys/cam/ctl/ctl_frontend_iscsi.c
+++ b/sys/cam/ctl/ctl_frontend_iscsi.c
@@ -1155,6 +1155,7 @@ cfiscsi_session_terminate_tasks(struct cfiscsi_session *cs)
 	}
 
 	CFISCSI_SESSION_LOCK(cs);
+	cs->cs_terminating_tasks = true;
 	while ((cdw = TAILQ_FIRST(&cs->cs_waiting_for_data_out)) != NULL) {
 		TAILQ_REMOVE(&cs->cs_waiting_for_data_out, cdw, cdw_next);
 		CFISCSI_SESSION_UNLOCK(cs);
@@ -2783,8 +2784,12 @@ cfiscsi_datamove_out(union ctl_io *io)
 	cdw->cdw_r2t_end = io->scsiio.ext_data_filled + r2t_len;
 
 	CFISCSI_SESSION_LOCK(cs);
-	if (cs->cs_terminating) {
+	if (cs->cs_terminating_tasks) {
 		CFISCSI_SESSION_UNLOCK(cs);
+		KASSERT((io->io_hdr.flags & CTL_FLAG_ABORT) != 0,
+		    ("%s: I/O request %p on termating session %p not aborted",
+		    __func__, io, cs));
+		CFISCSI_SESSION_WARN(cs, "aborting data_wait for aborted I/O");
 		cfiscsi_data_wait_abort(cs, cdw, 44);
 		return;
 	}
diff --git a/sys/cam/ctl/ctl_frontend_iscsi.h b/sys/cam/ctl/ctl_frontend_iscsi.h
index 7c7f422a8d1f..165f0ad79d70 100644
--- a/sys/cam/ctl/ctl_frontend_iscsi.h
+++ b/sys/cam/ctl/ctl_frontend_iscsi.h
@@ -84,6 +84,7 @@ struct cfiscsi_session {
 	int				cs_timeout;
 	struct cv			cs_maintenance_cv;
 	bool				cs_terminating;
+	bool				cs_terminating_tasks;
 	bool				cs_handoff_in_progress;
 	bool				cs_tasks_aborted;
 	int				cs_max_burst_length;