Re: [PATCH] scsi: scsi_dh_alua: set handler_data before alua_initialize()
From: Martin Wilck
Date: Wed Nov 11 2026 - 06:15:55 EST
On Mon, 2026-11-09 at 15:11 -0500, Laurence Oberman wrote:
> Since commit 50759b881e1d ("scsi: device_handler: alua: Call
> scsi_device_put() from non-atomic context"), alua_rtpg_queue() only
> queues an RTPG when sdev->handler_data points at an alua_dh_data
> whose
> port group matches:
>
> struct alua_dh_data *h = sdev->handler_data;
> ...
> if (h && rcu_dereference(h->pg) == pg) {
>
> However alua_bus_attach() only assigns sdev->handler_data after
> alua_initialize() returns, and alua_initialize() -> alua_check_vpd()
> is where the initial RTPG is queued. At that point handler_data is
> still NULL, so the initial RTPG is silently dropped: no RTPG is sent,
> nothing is logged, and sdev->access_state keeps its zeroed default of
> active/optimized for every path.
>
> With dm-multipath this goes unnoticed, as pg_init calls
> scsi_dh_activate() once the map is loaded, which queues an RTPG after
> handler_data is set, and multipathd's alua prioritizer issues its own
> RTPG from userspace. Anything relying on sdev->access_state without a
> subsequent activate (sysfs access_state/preferred_path, native SCSI
> multipath path selection) sees every path as active/optimized until a
> Unit Attention or rescan triggers an RTPG.
>
> Seen on an HP P2000 G3 FC array (implicit ALUA, two port groups, four
> paths per LUN) with dm-multipath not in use: sg_rtpg reports port
> group
> 0 active/non-optimized and port group 1 active/optimized, but
> /sys/class/scsi_device/H:C:T:L/device/access_state reads
> active/optimized on all four paths after boot, and no
> "alua: port group XX state ..." message is logged. Writing "activate"
> to dh_state sends the RTPG and corrects access_state.
>
> Kernels without commit 50759b881e1d queue the attach-time RTPG
> unconditionally and are not affected.
>
> Fix by assigning sdev->handler_data before calling alua_initialize(),
> and clearing it again on failure. sdev->handler is only set once
> scsi_dh_handler_attach() sees ->attach() succeed, so no handler
> callback can observe the partially initialised alua_dh_data. On the
> failure paths of alua_initialize(), h has not been added to a port
> group and no RTPG has been queued, so freeing it is unchanged.
>
> Fixes: 50759b881e1d ("scsi: device_handler: alua: Call
> scsi_device_put() from non-atomic context")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Laurence Oberman <loberman@xxxxxxxxxx>
Reviewed-by: Martin Wilck <mwilck@xxxxxxxx>
--
Dr. Martin Wilck <mwilck@xxxxxxxx>
SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg,
Germany
Geschäftsführer: Stefan Gaiser, Jochen Jaser, Abhinav Puri (HRB
36809,AG Nürnberg)