[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 45/45] block/copy-before-write: correct permission scheme
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v5 45/45] block/copy-before-write: correct permission scheme |
Date: |
Thu, 31 Mar 2022 00:29:02 +0300 |
Finally we can strictly unshare write on source node, as all write must
go through copy-before-write filter. For this to work:
- Declare independent close, so that blockdev-del transaction action
may detach children of removed node at prepare phase (that's for
filter removement). We can do it because copy-before-write filter
doesn't do any IO on its children on close().
- Support BDRV_O_NOPERM, so that blockdev-add transaction action can
skip intermediate permission update. We can do it because
copy-before-write filter doesn't do any IO on its children on
open().
- Move to new block-graph modifying API in iotest image-fleecing.
Separate qom-set + del/add doesn't work anymore for
copy-before-write filter, because intermediate state violate new
strict permissions.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
---
block/copy-before-write.c | 17 ++++++++---------
tests/qemu-iotests/tests/image-fleecing | 20 +++++++++++++++-----
tests/qemu-iotests/tests/image-fleecing.out | 8 --------
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 4fad564691..90a9c7874a 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -319,12 +319,8 @@ static void cbw_child_perm(BlockDriverState *bs, BdrvChild
*c,
bdrv_default_perms(bs, c, role, reopen_queue,
perm, shared, nperm, nshared);
- if (!QLIST_EMPTY(&bs->parents)) {
- if (perm & BLK_PERM_WRITE) {
- *nperm = *nperm | BLK_PERM_CONSISTENT_READ;
- }
- *nshared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
- }
+ *nperm = *nperm | BLK_PERM_CONSISTENT_READ;
+ *nshared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
}
}
@@ -378,13 +374,15 @@ static int cbw_open(BlockDriverState *bs, QDict *options,
int flags,
int64_t cluster_size;
int ret;
- ret = bdrv_open_file_child(NULL, options, "file", bs, errp);
+ ret = bdrv_open_file_child_common(NULL, options, "file", bs,
+ !(flags & BDRV_O_NOPERM), errp);
if (ret < 0) {
return ret;
}
- s->target = bdrv_open_child(NULL, options, "target", bs, &child_of_bds,
- BDRV_CHILD_DATA, false, errp);
+ s->target = bdrv_open_child_common(NULL, options, "target", bs,
+ &child_of_bds, BDRV_CHILD_DATA, false,
+ !(flags & BDRV_O_NOPERM), errp);
if (!s->target) {
return -EINVAL;
}
@@ -444,6 +442,7 @@ static void cbw_close(BlockDriverState *bs)
BlockDriver bdrv_cbw_filter = {
.format_name = "copy-before-write",
.instance_size = sizeof(BDRVCopyBeforeWriteState),
+ .independent_close = true,
.bdrv_open = cbw_open,
.bdrv_close = cbw_close,
diff --git a/tests/qemu-iotests/tests/image-fleecing
b/tests/qemu-iotests/tests/image-fleecing
index b7e5076104..23b55ded70 100755
--- a/tests/qemu-iotests/tests/image-fleecing
+++ b/tests/qemu-iotests/tests/image-fleecing
@@ -131,9 +131,13 @@ def do_test(vm, use_cbw, use_snapshot_access_filter,
base_img_path,
if bitmap:
fl_cbw['bitmap'] = {'node': src_node, 'name': 'bitmap0'}
- log(vm.qmp('blockdev-add', fl_cbw))
-
- log(vm.qmp('qom-set', path=qom_path, property='drive', value='fl-cbw'))
+ log(vm.qmp('transaction', {'actions': [
+ {'type': 'blockdev-add', 'data': fl_cbw},
+ {'type': 'x-blockdev-replace', 'data': {
+ 'parent-type': 'qdev',
+ 'qdev-id': 'sda',
+ 'new-child': 'fl-cbw'}}
+ ]}))
if use_snapshot_access_filter:
log(vm.qmp('blockdev-add', {
@@ -242,8 +246,14 @@ def do_test(vm, use_cbw, use_snapshot_access_filter,
base_img_path,
if use_cbw:
if use_snapshot_access_filter:
log(vm.qmp('blockdev-del', node_name='fl-access'))
- log(vm.qmp('qom-set', path=qom_path, property='drive', value=src_node))
- log(vm.qmp('blockdev-del', node_name='fl-cbw'))
+ log(vm.qmp('transaction', {'actions': [
+ {'type': 'x-blockdev-replace', 'data': {
+ 'parent-type': 'qdev',
+ 'qdev-id': 'sda',
+ 'new-child': src_node}},
+ {'type': 'blockdev-del', 'data': {
+ 'node-name': 'fl-cbw'}}
+ ]}))
else:
log(vm.qmp('block-job-cancel', device='fleecing'))
e = vm.event_wait('BLOCK_JOB_CANCELLED')
diff --git a/tests/qemu-iotests/tests/image-fleecing.out
b/tests/qemu-iotests/tests/image-fleecing.out
index acfc89ff0e..33c6c239da 100644
--- a/tests/qemu-iotests/tests/image-fleecing.out
+++ b/tests/qemu-iotests/tests/image-fleecing.out
@@ -79,7 +79,6 @@ Done
--- Setting up Fleecing Graph ---
-{"return": {}}
{"return": {}}
{"return": {}}
@@ -124,7 +123,6 @@ read -P0 0x3fe0000 64k
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Confirming writes ---
@@ -152,7 +150,6 @@ Done
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Setting up NBD Export ---
@@ -196,7 +193,6 @@ read -P0 0x3fe0000 64k
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Confirming writes ---
@@ -224,7 +220,6 @@ Done
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Setting up NBD Export ---
@@ -280,7 +275,6 @@ read failed: Invalid argument
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Confirming writes ---
@@ -308,7 +302,6 @@ Done
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Starting actual backup ---
@@ -343,7 +336,6 @@ read -P0 0x3fe0000 64k
{"return": {}}
{"return": {}}
{"return": {}}
-{"return": {}}
--- Confirming writes ---
--
2.35.1
- [PATCH v5 13/45] block: Manipulate bs->file / bs->backing pointers in .attach/.detach, (continued)
- [PATCH v5 13/45] block: Manipulate bs->file / bs->backing pointers in .attach/.detach, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 38/45] qapi: add x-blockdev-replace transaction action, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 41/45] iotests.py: introduce VM.assert_edges_list() method, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 40/45] iotests.py: qemu_img_create: use imgfmt by default, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 06/45] test-bdrv-graph-mod: fix filters to be filters, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 11/45] Revert "block: Restructure remove_file_or_backing_child()", Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 18/45] block: bdrv_refresh_perms(): allow external tran, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 21/45] block: add bdrv_try_set_aio_context_tran transaction action, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 22/45] block: implemet bdrv_unref_tran(), Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 23/45] blockdev: refactor transaction to use Transaction API, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 45/45] block/copy-before-write: correct permission scheme,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v5 03/45] block/blklogwrites: don't care to remove bs->file child on failure, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 12/45] Revert "block: Pass BdrvChild ** to replace_child_noperm", Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 15/45] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 19/45] block: refactor bdrv_list_refresh_perms to allow any list of nodes, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 24/45] blockdev: transactions: rename some things, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 26/45] blockdev: transaction: refactor handling transaction properties, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 25/45] blockdev: qmp_transaction: refactor loop to classic for, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 30/45] block: bdrv_insert_node(): use BDRV_O_NOPERM, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 33/45] block-backend: blk_root(): drop const specifier on return type, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 29/45] block: introduce BDRV_O_NOPERM flag, Vladimir Sementsov-Ogievskiy, 2022/03/30