On Tue, Mar 10, 2026 at 11:49:21AM +0000, John Garry wrote:
> Add a dedicated ALUA driver which can be used for native SCSI multipath
> and also DH-based ALUA support.
> 
> Only core functions to submit a RTPG, STPG, tur, and also helper functions
> are added.
> 
> The code from scsi_dh_alua.c to maintain the port groups is not added,
> because it is quite intertwined with the DH code. However the port group
> management code would be quite useful.
> 
> Hannes Reinecke originally authored this code.
> 
> Signed-off-by: John Garry <[email protected]>
> diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
> new file mode 100644
> index 0000000000000..2e4102192dcb9
> --- /dev/null
> +++ b/drivers/scsi/scsi_alua.c
> @@ -0,0 +1,204 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Generic SCSI-3 ALUA SCSI driver
> + *
> + * Copyright (C) 2007-2010 Hannes Reinecke, SUSE Linux Products GmbH.
> + * All rights reserved.
> + */
> +
> +#include <scsi/scsi.h>
> +#include <scsi/scsi_proto.h>
> +#include <scsi/scsi_dbg.h>
> +#include <scsi/scsi_eh.h>
> +#include <scsi/scsi_alua.h>
> +
> +#define DRV_NAME "alua"
> +
> +#define ALUA_FAILOVER_RETRIES                5
> +
> +/*
> + * alua_check_tpgs - Evaluate TPGS setting
> + * @sdev: device to be checked
> + *
> + * Examine the TPGS setting of the sdev to find out if ALUA
> + * is supported.
> + */
> +int alua_check_tpgs(struct scsi_device *sdev)
> +{
> +     int tpgs = TPGS_MODE_NONE;
> +
> +     /*
> +      * ALUA support for non-disk devices is fraught with
> +      * difficulties, so disable it for now.
> +      */
> +     if (sdev->type != TYPE_DISK) {
> +             sdev_printk(KERN_INFO, sdev,
> +                         "%s: disable for non-disk devices\n",
> +                         DRV_NAME);
> +             return tpgs;
> +     }
> +
> +     tpgs = scsi_device_tpgs(sdev);
> +     switch (tpgs) {
> +     case TPGS_MODE_EXPLICIT|TPGS_MODE_IMPLICIT:
> +             sdev_printk(KERN_INFO, sdev,
> +                         "%s: supports implicit and explicit TPGS\n",
> +                         DRV_NAME);
> +             break;
> +     case TPGS_MODE_EXPLICIT:
> +             sdev_printk(KERN_INFO, sdev, "%s: supports explicit TPGS\n",
> +                         DRV_NAME);
> +             break;
> +     case TPGS_MODE_IMPLICIT:
> +             sdev_printk(KERN_INFO, sdev, "%s: supports implicit TPGS\n",
> +                         DRV_NAME);
> +             break;
> +     case TPGS_MODE_NONE:
> +             sdev_printk(KERN_INFO, sdev, "%s: not supported\n",
> +                         DRV_NAME);
> +             break;
> +     default:
> +             sdev_printk(KERN_INFO, sdev,
> +                         "%s: unsupported TPGS setting %d\n",
> +                         DRV_NAME, tpgs);
> +             tpgs = TPGS_MODE_NONE;
> +             break;
> +     }
> +
> +     return tpgs;
> +}
> +EXPORT_SYMBOL_GPL(alua_check_tpgs);
> +
> +/*
> + * alua_tur - Send a TEST UNIT READY
> + * @sdev: device to which the TEST UNIT READY command should be send
> + *
> + * Send a TEST UNIT READY to @sdev to figure out the device state
> + * Returns SCSI_DH_RETRY if the sense code is NOT READY/ALUA TRANSITIONING,
> + * 0 if no error occurred, and SCSI_DH_IO otherwise.

Nitpick: The comment here still references SCSI_DH_ values

-Ben

> + */
> +int alua_tur(struct scsi_device *sdev)


Reply via email to