diff mbox series

[1/6] preallocate: truncate the image inside bdrv_inactivate()

Message ID 20241128183911.837699-2-den@openvz.org (mailing list archive)
State New
Headers show
Series block/preallocate: fix image truncation logic | expand

Commit Message

Denis V. Lunev" via Nov. 28, 2024, 6:25 p.m. UTC
Let us assume that we have the following quite usual chain:
    QCOW2 -> preallocate-filter -> raw-file
In this case in the case of the migration over shared storage, f.e. NFS
we go through
    bdrv_inactivate()
    bdrv_inactivate_recurse()
        qcow2_inactivate() <- writes a lot of data, f.e. CBT

        bdrv_get_cumulative_perm(qcow2)
        qcow2->open_flags |= BDRV_O_INACTIVE;
        bdrv_refresh_perms(qcow2)

        bdrv_inactivate_recurse(preallocate)
            preallocate_inactivate()

            bdrv_get_cumulative_perm(preallocate)
            preallocate->open_flags |= BDRV_O_INACTIVE;
            bdrv_refresh_perms(preallocate)

Right now preallocate_set_perm() is called through
bdrv_refresh_perms(qcow2) and this is the only moment when permissions
for the entire chain could be changed. If we will deny write permissions
here for the sake of the next step, the only place left for a whole
set of permissions changes would be preallocate_inactivate() callback.
This is all looking really terrible.

In addition to this, we are in trouble due truncate() operation
requested inside prealloc_set_perm() would be in reality called seriously
later, potentially once we have returned from bdrv_inactivate() to the
caller and the control has been passed to the migration target.

This patch has truncated the image inside preallocate_inactivate() thus
making further work inside preallocate_drop_resize_bh() noop.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
CC: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Hanna Reitz <hreitz@redhat.com>
---
 block/preallocate.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/block/preallocate.c b/block/preallocate.c
index d215bc5d6d..c14e6a530d 100644
--- a/block/preallocate.c
+++ b/block/preallocate.c
@@ -594,6 +594,11 @@  static void preallocate_child_perm(BlockDriverState *bs, BdrvChild *c,
     }
 }
 
+static int GRAPH_RDLOCK preallocate_inactivate(BlockDriverState *bs)
+{
+    return preallocate_drop_resize(bs, NULL);
+}
+
 static BlockDriver bdrv_preallocate_filter = {
     .format_name = "preallocate",
     .instance_size = sizeof(BDRVPreallocateState),
@@ -616,6 +621,8 @@  static BlockDriver bdrv_preallocate_filter = {
     .bdrv_set_perm = preallocate_set_perm,
     .bdrv_child_perm = preallocate_child_perm,
 
+    .bdrv_inactivate = preallocate_inactivate,
+
     .is_filter = true,
 };