[Devel] [PATCH hci-8.2 v8 8/9] dm-ploop: reload metadata on resume

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Wed Nov 18 16:30:31 MSK 2026


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dm-ploop: prealloc_stopped drops resize allocation requests
  on suspended device
- [Low] dm-ploop: top_flipped is not cleared when reload is skipped on
  resume
- [Low] dm-ploop: preresume wait and reload clean check are not under
  one lock
--

commit 240134d129537e6ddb55602e031529c851f3f05c
Author: Alexander Ivanov <alexander.ivanov at virtuozzo.com>

dm-ploop: reload metadata on resume

The patch reloads the top delta header, the BAT of every delta, the delta file sizes, the BAT tree and holes_bitmap in ploop_preresume(). Preallocation is requested after the reload. The patch also adds waits in postsuspend and preresume, and a per-ploop standby flag.

> diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
> --- a/drivers/md/dm-ploop-bat.c
> +++ b/drivers/md/dm-ploop-bat.c

[ ... ]

> +	/*
> +	 * 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.

[ ... ]

> 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.

[ ... ]

> diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
> --- a/drivers/md/dm-ploop-target.c
> +++ b/drivers/md/dm-ploop-target.c

[ ... ]

>  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?

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118131032.3372996-1-alexander.ivanov@virtuozzo.com?part=8



More information about the Devel mailing list