On Mon, Nov 02, 2026 at 04:31:50PM -0800, Brian Bunker wrote: > ev_add_path() sets mpp->force_readonly when a newly added path is > read-only, but never clears it. If a map is created or reloaded while > its storage is write protected, the flag stays set. When write protect > is cleared, the reload that uev_update_path() does for the DISK_RO=0 > uevent uses the stale flag and loads the map read-only, even though all > of its paths are read-write. uev_update_path() clears the flag after > that reload, so the map only recovers if another DISK_RO=0 uevent > reloads it again. If none comes, the map stays read-only, and since > mpp->dmi.read_only is then 1, needs_ro_update() also ignores later > DISK_RO=1 uevents for it. > > Fix this by setting force_readonly before each load and clearing it > once the load has succeeded: > > - uev_update_path() no longer takes the path's ro state from the > uevent's DISK_RO. The uevent only says that something changed. The > kernel updates the ro attribute before it sends the uevent, so sysfs > is current when the uevent is handled, while the uevent itself may > have been queued behind later changes. It just calls > needs_ro_update(), which reads the ro state of all of the map's paths > from sysfs. > > - needs_ro_update() no longer takes an ro value. It sets > force_readonly from the ro state of the map's paths, and returns true > if that differs from the map's current state. If the map is already > read-only and has to stay so, it clears the flag and returns false, > since dm has to reopen the paths for any read-write reload anyway. If > the map has no dm info, it fetches it, and returns false if that > fails, instead of assuming a reload is needed. Since the flag is > recomputed on every call, a failed read-only reload is retried on the > next uevent without any special handling. > > - ev_add_path() sets it from all of the map's paths rather than only > the path being added, and only when it is about to load the map > (need_do_map). mpp->paths is up to date there after adopt_paths(), > while mpp->pg doesn't contain the new paths yet. > > - update_map(), which does reloads that were delayed while the map was > waiting for udev (UDEV_WAIT_RELOAD), recomputes it from the map's > paths before setting up the map. > > - dm_addmap_create() clears it as soon as it has read it. A failed > create leaves no map behind, and the next create computes the flag > again. > > - dm_addmap_reload() clears it once the reload and resume have > succeeded. If the reload fails, the map keeps its old table, and the > flag stays set so that the next reload tries again. > > Signed-off-by: Brian Bunker <[email protected]> Thanks for dealing with all the revisions
Reviewed-by: Benjamin Marzinski <[email protected]>
