[Devel] [PATCH hci-8.2 v9 8/9] dm-ploop: reload metadata on resume
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Thu Nov 19 17:16:26 MSK 2026
>> +void ploop_wait_prealloc(struct ploop *ploop)
>> +{
>> + if (!READ_ONCE(ploop->standby))
>> + wait_event(ploop->dispatcher_wq_prealloc,
>> + ploop_no_pending_prealloc(ploop));
>> +}
>> +
>> +void ploop_stop_prealloc(struct ploop *ploop)
>> +{
>> + ploop_drop_prealloc(ploop);
>> + ploop_wait_prealloc(ploop);
>> +}
> [Severity: Low]
> Does this skip only help when standby is already set on entry? The flag is tested once, before sleeping, and is not part of the wait_event() condition.
>
> ploop_check_standby_mode() sets the flag with WRITE_ONCE(ploop->standby, true) but never wakes dispatcher_wq_prealloc. If standby is set after the waiter has gone to sleep and the allocator is stuck in truncate on a dead file, the uninterruptible wait in ploop_postsuspend() (or in ploop_message()) never ends. dm_replace() then cannot suspend the device to recover it, which is the case the commit message says this is meant to avoid.
>
> Would it work to put the standby flag into the wait condition and call wake_up() on dispatcher_wq_prealloc when standby is set?
Standby is set only on completion of DM data and flush bios, and both
waits run on a suspended device, after DM has waited for all of them.
So the flag can't change while we sleep there.
>> static int ploop_preresume(struct dm_target *ti)
>> {
>> struct ploop *ploop = ti->private;
>> + unsigned int noio_flags;
>> + bool reload = false;
>> int ret = 0;
>>
>> + /* A resize of the suspended device may drop inflight_md late */
>> + if (!ploop_is_standby(ploop))
>> + wait_event(ploop->inflight_md_wq,
>> + !atomic_read(&ploop->inflight_md));
>> +
>> down_write(&ploop->ctl_rwsem);
>> + /* A message may have slipped in before the lock */
>> + if (!ploop_is_standby(ploop))
>> + wait_event(ploop->inflight_md_wq,
>> + !atomic_read(&ploop->inflight_md));
> [Severity: Low]
> The commit message says waits are done outside ctl_rwsem so that a stuck writeback doesn't block status and messages. Doesn't this second wait break that for the window it covers? It is an unbounded, uninterruptible wait_event() with ctl_rwsem held for write, and standby is not rechecked while it sleeps. If BAT writeback started by a message in that gap never completes, status and other messages block behind ctl_rwsem as well as the resume.
Messages write BAT synchronously while holding ctl_rwsem. If that
writeback hangs, the message
itself already blocks status and other messages. By the time preresume
takes the lock, the writeback
has finished. Only the reference drop after complete() is left, and it
does no IO.
>> if (ploop->noresume) {
>> ret = -EAGAIN;
>> + } else if (!ploop_is_standby(ploop) &&
>> + ploop_no_pending_prealloc(ploop)) {
>> + reload = true;
> [Severity: Medium]
> Can this skip the reload silently and still resume the device? When a prealloc is pending, the branch is not taken, ret stays 0 and suspended is cleared, so the new ploop runs with the BAT, holes_bitmap and file sizes read in ploop_ctr(). That is the stale-metadata state this patch is meant to remove.
>
> A pending prealloc is reachable from ploop_message(), which drops ctl_rwsem before waiting for the in-flight prealloc. target_message() does not take md->suspend_lock, so it can overlap with dm_resume():
>
> CPU0 (message, e.g. resize) CPU1 (resume ioctl)
> ploop_message()
> ploop_drop_prealloc()
> up_write(&ctl_rwsem)
> ploop_preresume()
> down_write(&ctl_rwsem)
> ploop_no_pending_prealloc() == 0
> reload skipped, suspended = false
> <-- stale metadata
> ploop_wait_prealloc()
>
> The same silent skip happens after a standby postsuspend that did not wait. ploop_reload_metadata() also returns 0 without logging when the md pages are not clean. Could preresume wait for the prealloc to finish, or fail the resume (for example with -EAGAIN) instead of succeeding without a reload?
fixed: preresume now waits for the prealloc in flight the same way as
for inflight_md,
before ctl_rwsem and again under it, then reloads unconditionally
outside standby.
Also added a warning when dirty md pages skip the reload.
More information about the Devel
mailing list