[Devel] [PATCH hci-8.1 v3 5/5] dm-ploop: truncate unused tail of top delta on suspend

Denis V. Lunev den at openvz.org
Thu Oct 8 19:51:23 MSK 2026


On 08.10.2026 16:03, Alexander Ivanov wrote:
> +	end = ploop_calc_used_end(ploop, top->file);
> +	if (end < 0) {
> +		PL_ERR("Can't find used end of top delta: %lld", end);
> +		return;
> +	}
> +	if (end >= top->file_size)
> +		return;
> +
> +	ret = do_ftruncate(top->file, end, 0);

Two problems here.

1. A device in standby. ploop switches the queue to standby when the
lease of the delta is stolen (-EBUSY) or the mount is gone. dm_replace()
in libploop recovers such a device: it suspends it and reloads the
table with fresh files. With this patch postsuspend first reads the BAT
from the dead file and then truncates it, and a truncate on a dead file
hangs. That happens with md->suspend_lock held, so the device can be
neither replaced nor removed afterwards. Please do nothing in
postsuspend when blk_queue_standby(ploop_blk_queue(ploop)) is set, and
skip the prealloc wait from 4/5 in that case too.

2. Another live writer. The truncation assumes the ploop being suspended
is the only one writing to the top delta. libploop can break that
on the ploop_tg_deinit() error path (see my reply to 4/5). Then
suspending or removing the stale instance cuts clusters that the live
one has written but whose BAT update is not on disk yet. Before this
patch that was harmless, since postsuspend never wrote. A cheap
guard: do not truncate when i_size_read(file_inode(top->file)) !=
top->file_size. Any other writer grows the file, so the sizes no longer
match.

> +		ext_clu = SEC_TO_CLU(ploop, ext_off);
> +		if (CLU_TO_SEC(ploop, ext_clu) != ext_off ||
> +		    ext_clu >= BAT_ENTRY_NONE) {
> +			used_end = -EPROTO;
> +			goto out;
> +		}

I checked this against delta_save_optional_header(): the bitmap blocks
are appended at EOF and the header block goes after them, so keeping
everything up to the header cluster is right. A bogus offset leads to
"Can't find used end of top delta" on every suspend. That is fine as
long as it stays rare.

The comment above ploop_calc_used_end() and the one inside it repeat the
commit message almost word for word. One line pointing to
delta_save_optional_header() is enough.


More information about the Devel mailing list