[Devel] [PATCH hci-8.2 v8 8/9] dm-ploop: reload metadata on resume
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Wed Nov 18 17:07:26 MSK 2026
>> + /*
>> + * Header of top delta is written with BAT page 0. Userspace doesn't
>> + * mark the delta, which becomes top after flip_upper_deltas, as in
>> + * use, and relies that the in-use signature of the old top delta
>> + * will be written to it. So keep the signature we had. In other
>> + * cases take it from disk: userspace may have changed it on the
>> + * suspended device (e.g. marked the image closed on umount).
>> + */
>> + if (ploop->top_flipped) {
>> + old_hdr = ploop_md_first_entry(&old_bat_entries)->kmpage;
>> + hdr = ploop_md_first_entry(&ploop->bat_entries)->kmpage;
>> + hdr->m_DiskInUse = old_hdr->m_DiskInUse;
>> + ploop->top_flipped = false;
>> + }
> [Severity: Low]
> Is top_flipped ever cleared if the reload is skipped?
>
> It is cleared only here, after a full reload. ploop_reload_metadata() returns 0 early when the md pages are not clean, and ploop_preresume() skips the reload in standby or while preallocation is pending. In all those cases resume still succeeds and the flag stays set after flip_upper_deltas.
>
> If userspace later marks the image closed on disk while suspended, the next successful reload copies the in-memory IN_USE over the on-disk value. Umount then trims the image and CBT is lost. That contradicts the commit message, which says the signature is taken from disk except right after flip_upper_deltas.
Fixed.
>
> [ ... ]
>
>> diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
>> --- a/drivers/md/dm-ploop-map.c
>> +++ b/drivers/md/dm-ploop-map.c
>> @@ -1195,6 +1195,8 @@ static int ploop_preallocate_cluster(struct ploop *ploop, struct file *file)
>>
>> spin_lock_irqsave(&ploop->bat_lock, flags);
>> prealloc_more:
>> + if (READ_ONCE(ploop->prealloc_stopped))
>> + ploop->prealloc_size = 0;
>> ploop->prealloc_in_progress = ploop->prealloc_size;
>> ploop->prealloc_size = 0;
> [Severity: Medium]
> Does this also drop the synchronous request that a resize message on a suspended device depends on?
>
> ploop_postsuspend() sets prealloc_stopped and only a successful preresume clears it. A grow resize sent while suspended goes ploop_resize() -> ... -> ploop_prepare_reloc_index_wb() -> ploop_allocate_cluster(). That calls ploop_req_prealloc() and wakes the allocator. ploop_preallocate_cluster() then zeroes prealloc_size and grows nothing.
>
> ploop_allocate_cluster() then sees end > top->file_size and logs "Prealloc failed". It retries three times, each dropped the same way, and returns -EIO. The resize fails whenever the relocation needs the top delta to grow.
>
> The commit message says only pending requests are dropped. The flag cannot tell a stale background request from a required synchronous one. The last patch in the series, which truncates the unused tail on suspend, makes growth more likely and does not change this check.
Fixed.
>> 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 leave BAT writeback in flight */
>> + if (!ploop_is_standby(ploop))
>> + wait_event(ploop->inflight_md_wq,
>> + !atomic_read(&ploop->inflight_md));
>> +
>> down_write(&ploop->ctl_rwsem);
> [Severity: Low]
> Can a resize message slip in between this wait and down_write(&ploop->ctl_rwsem)?
>
> ploop_resize() does not require the device to be suspended, so it can start BAT writeback or dirty md pages in that window. ploop_reload_metadata() then sees unclean pages and returns 0 without any log message. Resume succeeds and the device goes live with the stale BAT read in ploop_ctr(). That is the situation this patch is meant to prevent.
>
> Would it work to wait for inflight_md and run the clean check under the same lock?
The race needs userspace to send a resize to the new table concurrently
with its resume,
which libploop does not do, and waiting under ctl_rwsem would not cover
the wider
case of a resize sent to a table before its first resume anyway.
More information about the Devel
mailing list