]> git.baikalelectronics.ru Git - kernel.git/commitdiff
scsi: qla2xxx: Fix losing target when it reappears during delete
authorArun Easi <aeasi@marvell.com>
Thu, 16 Jun 2022 05:35:04 +0000 (22:35 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 17 Jun 2022 01:59:53 +0000 (21:59 -0400)
FC target disappeared during port perturbation tests due to a race that
tramples target state.  Fix the issue by adding state checks before
proceeding.

Link: https://lore.kernel.org/r/20220616053508.27186-8-njavali@marvell.com
Fixes: d5638e660741 ("scsi: qla2xxx: Changes to support FCP2 Target")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Easi <aeasi@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/qla2xxx/qla_attr.c

index 8b87fefda42304c288f54c6095e35e230d879b11..feca9e44b21c80a1f67e68cde88790b1e75ab441 100644 (file)
@@ -2714,17 +2714,24 @@ qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
        if (!fcport)
                return;
 
-       /* Now that the rport has been deleted, set the fcport state to
-          FCS_DEVICE_DEAD */
-       qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
+
+       /*
+        * Now that the rport has been deleted, set the fcport state to
+        * FCS_DEVICE_DEAD, if the fcport is still lost.
+        */
+       if (fcport->scan_state != QLA_FCPORT_FOUND)
+               qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
 
        /*
         * Transport has effectively 'deleted' the rport, clear
         * all local references.
         */
        spin_lock_irqsave(host->host_lock, flags);
-       fcport->rport = fcport->drport = NULL;
-       *((fc_port_t **)rport->dd_data) = NULL;
+       /* Confirm port has not reappeared before clearing pointers. */
+       if (rport->port_state != FC_PORTSTATE_ONLINE) {
+               fcport->rport = fcport->drport = NULL;
+               *((fc_port_t **)rport->dd_data) = NULL;
+       }
        spin_unlock_irqrestore(host->host_lock, flags);
 
        if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
@@ -2757,9 +2764,12 @@ qla2x00_terminate_rport_io(struct fc_rport *rport)
        /*
         * At this point all fcport's software-states are cleared.  Perform any
         * final cleanup of firmware resources (PCBs and XCBs).
+        *
+        * Attempt to cleanup only lost devices.
         */
        if (fcport->loop_id != FC_NO_LOOP_ID) {
-               if (IS_FWI2_CAPABLE(fcport->vha->hw)) {
+               if (IS_FWI2_CAPABLE(fcport->vha->hw) &&
+                   fcport->scan_state != QLA_FCPORT_FOUND) {
                        if (fcport->loop_id != FC_NO_LOOP_ID)
                                fcport->logout_on_delete = 1;
 
@@ -2769,7 +2779,7 @@ qla2x00_terminate_rport_io(struct fc_rport *rport)
                                       __LINE__);
                                qlt_schedule_sess_for_deletion(fcport);
                        }
-               } else {
+               } else if (!IS_FWI2_CAPABLE(fcport->vha->hw)) {
                        qla2x00_port_logout(fcport->vha, fcport);
                }
        }