[Devel] [PATCH hci-8.1 v7 09/10] dm-ploop: reload metadata on resume
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Wed Nov 18 12:09:15 MSK 2026
>> diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
>> index 442537340b51..e7571b383f00 100644
>> --- a/drivers/md/dm-ploop-map.c
>> +++ b/drivers/md/dm-ploop-map.c
>> @@ -1267,6 +1267,12 @@ int ploop_no_pending_prealloc(struct ploop *ploop)
>> return ret;
>> }
>>
>> +void ploop_wait_prealloc(struct ploop *ploop)
>> +{
>> + wait_event_killable(ploop->dispatcher_wq_prealloc,
>> + ploop_no_pending_prealloc(ploop));
>> +}
>> +
> [Severity: Medium]
> Does dropping the return value of wait_event_killable() leave the old allocator unfenced?
>
> If dmsetup gets a fatal signal while a preallocation is pending, the wait returns -ERESTARTSYS. ploop_postsuspend() returns void, so it carries on and marks the device suspended while the allocator may still be running.
>
> ploop_preallocate_cluster() computes new_len = top->file_size + prealloc_in_progress and calls do_ftruncate() or vfs_fallocate() with no suspend check. It can then resize the top delta under a new ploop that has already reloaded the size. ploop_preresume() of the new ploop only checks its own prealloc state, which is zero.
>
> That can corrupt the top delta image. Could the killed wait be reported to the caller, or the old allocator be stopped from touching the file once suspended?
Fixed.
>> static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu, struct file *file)
>> {
>> struct ploop_delta *top = ploop_top_delta(ploop);
>> @@ -1443,6 +1449,7 @@ static void ploop_check_standby_mode(struct ploop *ploop, long res)
>> spin_lock_irqsave(&q->queue_lock, flags);
>> prev = test_and_set_bit(QUEUE_FLAG_STANDBY, &q->queue_flags);
>> spin_unlock_irqrestore(&q->queue_lock, flags);
>> + WRITE_ONCE(ploop->standby, true);
>>
>> if (!prev)
>> PL_INFO("was switched into the standby mode");
> [Severity: Low]
> Is it intended that ploop->standby is never cleared?
>
> This is the only writer. The queue bit it shadows is cleared by ploop_ctr() of a new table. Suppose an instance enters standby, a new table's ploop_ctr() clears the queue bit, and the new table is then abandoned. The old instance serves IO again, but ploop_preresume() keeps skipping ploop_reload_metadata() and ploop_should_prealloc() for it, and ploop_postsuspend() keeps skipping the prealloc wait.
>
> If userspace then changes the images on the suspended device (merge or snapshot trim) and resumes this same instance, it keeps a stale BAT. That is the corruption this patch is meant to prevent. Normal recovery through dm_replace() creates a new instance, so it is not affected. Should the flag be cleared when the instance leaves standby?
Yes, it is intended: the flag means this instance's files failed and
nothing proves they are alive again,
so recovery goes only through a new table via dm_replace(), while the
stale-BAT case needs the images
to be modified under the suspended old instance and that instance then
resumed, which libploop
never does (and before this patch that case did not reload anything
either).
>> @@ -755,18 +755,47 @@ static void ploop_postsuspend(struct dm_target *ti)
>> {
>> struct ploop *ploop = ti->private;
>>
>> - wait_event(ploop->dispatcher_wq_prealloc,
>> - ploop_no_pending_prealloc(ploop));
>> + /*
>> + * Let the next resumed ploop (maybe of reloaded table)
>> + * see final size of the top delta. Don't wait in standby
>> + * mode: the allocator may be stuck on the dead file, while
>> + * dm_replace() of libploop must be able to suspend the device
>> + * to recover it. The wait is killable for the same reason.
>> + * If the wait is skipped or killed, a ploop of a reloaded
>> + * table may see a stale size, and a late truncate of our
>> + * allocator may shrink the file under it.
>> + */
>> + if (!ploop_is_standby(ploop))
>> + ploop_wait_prealloc(ploop);
>> + /*
>> + * Data bios are completed before BAT writeback is finished
>> + * (see ploop_put_piwb()), so wait for it explicitly to make
>> + * md pages clean for ploop_reload_metadata().
>> + */
>> + wait_event(ploop->inflight_md_wq, !atomic_read(&ploop->inflight_md));
>> ploop_set_suspended(ti, true);
>> }
> [Severity: Medium]
> Can this wait_event() hang suspend in standby?
>
> The comment above explains that the prealloc wait is skipped in standby and made killable because the backing file may be dead. The inflight_md wait right below has neither a standby bypass nor a killable variant. A BAT index write stuck on a hung delta file keeps inflight_md non-zero, so ploop_postsuspend() sits in D state and the dm_replace() recovery stalls.
>
> ploop_presuspend() does not drain BAT writes. The kt_worker->inflight_pios counter it waits on drops once the pio is handed to a runner through ploop_runners_add_work() in ploop_index_wb_submit(), not when the write completes.
>
> Skipping the wait in standby looks safe, since ploop_preresume() skips the reload there. The final patch of the series, "dm-ploop: truncate unused tail of top delta on suspend", keeps this wait and moves it under ctl_rwsem held for write, so a hang would then also block ploop_message() and ploop_preresume().
Fixed.
More information about the Devel
mailing list