qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Denis V. Lunev
Subject: [PATCH 1/6] preallocate: truncate the image inside bdrv_inactivate()
Date: Thu, 28 Nov 2024 19:25:48 +0100

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 --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,
 };
 
-- 
2.45.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]