[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/32] block: bdrv_inactivate_recurse(): check for permissions and
From: |
Hanna Reitz |
Subject: |
[PULL 17/32] block: bdrv_inactivate_recurse(): check for permissions and fix crash |
Date: |
Wed, 15 Sep 2021 19:53:03 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
We must not inactivate child when parent has write permissions on
it.
Calling .bdrv_inactivate() doesn't help: actually only qcow2 has this
handler and it is used to flush caches, not for permission
manipulations.
So, let's simply check cumulative parent permissions before
inactivating the node.
This commit fixes a crash when we do migration during backup: prior to
the commit nothing prevents all nodes inactivation at migration finish
and following backup write to the target crashes on assertion
"assert(!(bs->open_flags & BDRV_O_INACTIVE));" in
bdrv_co_write_req_prepare().
After the commit, we rely on the fact that copy-before-write filter
keeps write permission on target node to be able to write to it. So
inactivation fails and migration fails as expected.
Corresponding test now passes, so, enable it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20210911120027.8063-3-vsementsov@virtuozzo.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
block.c | 8 ++++++++
tests/qemu-iotests/tests/migrate-during-backup | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 00982edf45..5ce08a79fd 100644
--- a/block.c
+++ b/block.c
@@ -6326,6 +6326,7 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs)
{
BdrvChild *child, *parent;
int ret;
+ uint64_t cumulative_perms, cumulative_shared_perms;
if (!bs->drv) {
return -ENOMEDIUM;
@@ -6356,6 +6357,13 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs)
}
}
+ bdrv_get_cumulative_perm(bs, &cumulative_perms,
+ &cumulative_shared_perms);
+ if (cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) {
+ /* Our inactive parents still need write access. Inactivation failed.
*/
+ return -EPERM;
+ }
+
bs->open_flags |= BDRV_O_INACTIVE;
/*
diff --git a/tests/qemu-iotests/tests/migrate-during-backup
b/tests/qemu-iotests/tests/migrate-during-backup
index 1046904c5a..34103229ee 100755
--- a/tests/qemu-iotests/tests/migrate-during-backup
+++ b/tests/qemu-iotests/tests/migrate-during-backup
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# group: migration disabled
+# group: migration
#
# Copyright (c) 2021 Virtuozzo International GmbH
#
--
2.31.1
- [PULL 05/32] block/file-posix: Do not force-cap *pnum, (continued)
- [PULL 05/32] block/file-posix: Do not force-cap *pnum, Hanna Reitz, 2021/09/15
- [PULL 03/32] block: block-status cache for data regions, Hanna Reitz, 2021/09/15
- [PULL 06/32] block/gluster: Do not force-cap *pnum, Hanna Reitz, 2021/09/15
- [PULL 07/32] block/iscsi: Do not force-cap *pnum, Hanna Reitz, 2021/09/15
- [PULL 09/32] iotests: Fix use-{list,dict}-literal warnings, Hanna Reitz, 2021/09/15
- [PULL 13/32] mirror-top-perms: Fix AbnormalShutdown path, Hanna Reitz, 2021/09/15
- [PULL 08/32] iotests: Fix unspecified-encoding pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 15/32] block/mirror: fix NULL pointer dereference in mirror_wait_on_conflicts(), Hanna Reitz, 2021/09/15
- [PULL 10/32] iotests/297: Drop 169 and 199 from the skip list, Hanna Reitz, 2021/09/15
- [PULL 14/32] iotests/297: Cover tests/, Hanna Reitz, 2021/09/15
- [PULL 17/32] block: bdrv_inactivate_recurse(): check for permissions and fix crash,
Hanna Reitz <=
- [PULL 12/32] migrate-bitmaps-test: Fix pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 11/32] migrate-bitmaps-postcopy-test: Fix pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 16/32] tests: add migrate-during-backup, Hanna Reitz, 2021/09/15
- [PULL 19/32] qcow2: refactor handle_dependencies() loop body, Hanna Reitz, 2021/09/15
- [PULL 18/32] simplebench: add img_bench_templater.py, Hanna Reitz, 2021/09/15
- [PULL 21/32] qemu-img: Allow target be aligned to sector size, Hanna Reitz, 2021/09/15
- [PULL 20/32] qcow2: handle_dependencies(): relax conflict detection, Hanna Reitz, 2021/09/15
- [PULL 22/32] qcow2-refcount: improve style of check_refcounts_l2(), Hanna Reitz, 2021/09/15
- [PULL 23/32] qcow2: compressed read: simplify cluster descriptor passing, Hanna Reitz, 2021/09/15
- [PULL 25/32] qcow2-refcount: introduce fix_l2_entry_by_zero(), Hanna Reitz, 2021/09/15