git: 3b0e3e8d2a6f - main - CTL: Fix double command completions on HA failover.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Tue, 14 Jun 2022 04:40:30 UTC
The branch main has been updated by mav:

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

commit 3b0e3e8d2a6fab953a0ce537b6131330ccf36170
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-06-14 04:24:39 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-06-14 04:24:39 +0000

    CTL: Fix double command completions on HA failover.
    
    I've found couple cases when CTL_FLAG_SENT_2OTHER_SC flags were not
    cleared on commands return from active node or the send failure.  It
    created races when ctl_failover_lun() call before ctl_process_done()
    could cause second ctl_done() and ctl_process_done() calls, causing
    all sorts of problems.
    
    MFC after:      2 weeks
    Sponsored by:   iXsystems, Inc.
---
 sys/cam/ctl/ctl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c
index 6d06d4f5ad14..1fda5bde72c2 100644
--- a/sys/cam/ctl/ctl.c
+++ b/sys/cam/ctl/ctl.c
@@ -800,6 +800,7 @@ ctl_isc_handler_finish_xfer(struct ctl_softc *ctl_softc,
 	}
 
 	ctsio = &msg_info->hdr.original_sc->scsiio;
+	ctsio->io_hdr.flags &= ~CTL_FLAG_SENT_2OTHER_SC;
 	ctsio->io_hdr.flags |= CTL_FLAG_IO_ACTIVE;
 	ctsio->io_hdr.msg_type = CTL_MSG_FINISH_IO;
 	ctsio->io_hdr.status = msg_info->hdr.status;
@@ -11658,6 +11659,8 @@ ctl_scsiio_precheck(struct ctl_scsiio *ctsio)
 		if ((isc_retval = ctl_ha_msg_send(CTL_HA_CHAN_CTL, &msg_info,
 		    sizeof(msg_info.scsi) - sizeof(msg_info.scsi.sense_data),
 		    M_WAITOK)) > CTL_HA_STATUS_SUCCESS) {
+			ctsio->io_hdr.flags &= ~CTL_FLAG_SENT_2OTHER_SC;
+			ctsio->io_hdr.flags |= CTL_FLAG_IO_ACTIVE;
 			ctl_set_busy(ctsio);
 			ctl_done((union ctl_io *)ctsio);
 			return;