1 | The following changes since commit 7b1db0908d88f0c9cfac24e214ff72a860692e23: | 1 | The following changes since commit ccdf06c1db192152ac70a1dd974c624f566cb7d4: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20180323' into staging (2018-03-25 13:51:33 +0100) | 3 | Open 6.1 development tree (2021-04-30 11:15:40 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream | 7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream |
8 | 8 | ||
9 | for you to fetch changes up to 0b7e7f66813a7e346e12d47be977a32a530a6316: | 9 | for you to fetch changes up to 68bf7336533faa6aa90fdd4558edddbf5d8ef814: |
10 | 10 | ||
11 | qemu-iotests: Test vhdx image creation with QMP (2018-03-26 12:17:43 +0200) | 11 | vhost-user-blk: Fail gracefully on too large queue size (2021-04-30 12:27:48 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block layer patches | 14 | Block layer patches |
15 | 15 | ||
16 | - Fix permission update order problems with block graph changes | ||
17 | - qemu-img convert: Unshare write permission for source | ||
18 | - vhost-user-blk: Fail gracefully on too large queue size | ||
19 | |||
16 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
17 | Alberto Garcia (1): | 21 | Kevin Wolf (3): |
18 | qcow2: Reset free_cluster_index when allocating a new refcount block | 22 | block: Add BDRV_O_NO_SHARE for blk_new_open() |
23 | qemu-img convert: Unshare write permission for source | ||
24 | vhost-user-blk: Fail gracefully on too large queue size | ||
19 | 25 | ||
20 | Eric Blake (1): | 26 | Vladimir Sementsov-Ogievskiy (36): |
21 | iotests: 163 is not quick | 27 | tests/test-bdrv-graph-mod: add test_parallel_exclusive_write |
28 | tests/test-bdrv-graph-mod: add test_parallel_perm_update | ||
29 | tests/test-bdrv-graph-mod: add test_append_greedy_filter | ||
30 | block: bdrv_append(): don't consume reference | ||
31 | block: BdrvChildClass: add .get_parent_aio_context handler | ||
32 | block: drop ctx argument from bdrv_root_attach_child | ||
33 | block: make bdrv_reopen_{prepare,commit,abort} private | ||
34 | util: add transactions.c | ||
35 | block: bdrv_refresh_perms: check for parents permissions conflict | ||
36 | block: refactor bdrv_child* permission functions | ||
37 | block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms() | ||
38 | block: inline bdrv_child_*() permission functions calls | ||
39 | block: use topological sort for permission update | ||
40 | block: add bdrv_drv_set_perm transaction action | ||
41 | block: add bdrv_list_* permission update functions | ||
42 | block: add bdrv_replace_child_safe() transaction action | ||
43 | block: fix bdrv_replace_node_common | ||
44 | block: add bdrv_attach_child_common() transaction action | ||
45 | block: add bdrv_attach_child_noperm() transaction action | ||
46 | block: split out bdrv_replace_node_noperm() | ||
47 | block: adapt bdrv_append() for inserting filters | ||
48 | block: add bdrv_remove_filter_or_cow transaction action | ||
49 | block: introduce bdrv_drop_filter() | ||
50 | block/backup-top: drop .active | ||
51 | block: drop ignore_children for permission update functions | ||
52 | block: make bdrv_unset_inherits_from to be a transaction action | ||
53 | block: make bdrv_refresh_limits() to be a transaction action | ||
54 | block: add bdrv_set_backing_noperm() transaction action | ||
55 | block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare | ||
56 | block: bdrv_reopen_multiple: refresh permissions on updated graph | ||
57 | block: drop unused permission update functions | ||
58 | block: inline bdrv_check_perm_common() | ||
59 | block: inline bdrv_replace_child() | ||
60 | block: refactor bdrv_child_set_perm_safe() transaction action | ||
61 | block: rename bdrv_replace_child_safe() to bdrv_replace_child() | ||
62 | block: refactor bdrv_node_check_perm() | ||
22 | 63 | ||
23 | Fabiano Rosas (5): | 64 | include/block/block.h | 14 +- |
24 | block/replication: Remove protocol_name field | 65 | include/block/block_int.h | 8 +- |
25 | block/quorum: Remove protocol-related fields | 66 | include/qemu/transactions.h | 63 ++ |
26 | block/throttle: Remove protocol-related fields | 67 | block.c | 1329 ++++++++++++++++++++------------- |
27 | block/blkreplay: Remove protocol-related fields | 68 | block/backup-top.c | 48 +- |
28 | include/block/block_int: Document protocol related functions | 69 | block/block-backend.c | 30 +- |
70 | block/commit.c | 1 + | ||
71 | block/file-posix.c | 91 +-- | ||
72 | block/io.c | 31 +- | ||
73 | block/mirror.c | 3 - | ||
74 | blockdev.c | 4 - | ||
75 | blockjob.c | 11 +- | ||
76 | hw/block/vhost-user-blk.c | 5 + | ||
77 | qemu-img.c | 2 +- | ||
78 | tests/unit/test-bdrv-drain.c | 2 +- | ||
79 | tests/unit/test-bdrv-graph-mod.c | 209 +++++- | ||
80 | util/transactions.c | 96 +++ | ||
81 | MAINTAINERS | 6 + | ||
82 | tests/qemu-iotests/245 | 2 +- | ||
83 | tests/qemu-iotests/283.out | 2 +- | ||
84 | tests/qemu-iotests/tests/qsd-jobs.out | 2 +- | ||
85 | util/meson.build | 1 + | ||
86 | 22 files changed, 1280 insertions(+), 680 deletions(-) | ||
87 | create mode 100644 include/qemu/transactions.h | ||
88 | create mode 100644 util/transactions.c | ||
29 | 89 | ||
30 | Kevin Wolf (12): | ||
31 | vdi: Change 'static' create option to 'preallocation' in QMP | ||
32 | vdi: Fix build with CONFIG_VDI_DEBUG | ||
33 | qemu-iotests: Test vdi image creation with QMP | ||
34 | qemu-iotests: Enable 025 for luks | ||
35 | luks: Turn another invalid assertion into check | ||
36 | qemu-iotests: Test invalid resize on luks | ||
37 | parallels: Check maximum cluster size on create | ||
38 | qemu-iotests: Test parallels image creation with QMP | ||
39 | vhdx: Require power-of-two block size on create | ||
40 | vhdx: Don't use error_setg_errno() with constant errno | ||
41 | vhdx: Check for 4 GB maximum log size on creation | ||
42 | qemu-iotests: Test vhdx image creation with QMP | ||
43 | 90 | ||
44 | qapi/block-core.json | 7 +- | ||
45 | include/block/block_int.h | 8 ++ | ||
46 | replication.h | 1 - | ||
47 | block/blkreplay.c | 3 +- | ||
48 | block/crypto.c | 6 +- | ||
49 | block/parallels.c | 5 + | ||
50 | block/qcow2-refcount.c | 7 + | ||
51 | block/quorum.c | 3 +- | ||
52 | block/replication.c | 1 - | ||
53 | block/throttle.c | 3 +- | ||
54 | block/vdi.c | 46 ++++-- | ||
55 | block/vhdx.c | 17 ++- | ||
56 | tests/qemu-iotests/025 | 9 +- | ||
57 | tests/qemu-iotests/026.out | 6 +- | ||
58 | tests/qemu-iotests/121 | 20 +++ | ||
59 | tests/qemu-iotests/121.out | 10 ++ | ||
60 | tests/qemu-iotests/210 | 37 +++++ | ||
61 | tests/qemu-iotests/210.out | 16 +++ | ||
62 | tests/qemu-iotests/211 | 246 ++++++++++++++++++++++++++++++++ | ||
63 | tests/qemu-iotests/211.out | 97 +++++++++++++ | ||
64 | tests/qemu-iotests/212 | 326 ++++++++++++++++++++++++++++++++++++++++++ | ||
65 | tests/qemu-iotests/212.out | 111 ++++++++++++++ | ||
66 | tests/qemu-iotests/213 | 349 +++++++++++++++++++++++++++++++++++++++++++++ | ||
67 | tests/qemu-iotests/213.out | 121 ++++++++++++++++ | ||
68 | tests/qemu-iotests/group | 5 +- | ||
69 | 25 files changed, 1423 insertions(+), 37 deletions(-) | ||
70 | create mode 100755 tests/qemu-iotests/211 | ||
71 | create mode 100644 tests/qemu-iotests/211.out | ||
72 | create mode 100755 tests/qemu-iotests/212 | ||
73 | create mode 100644 tests/qemu-iotests/212.out | ||
74 | create mode 100755 tests/qemu-iotests/213 | ||
75 | create mode 100644 tests/qemu-iotests/213.out | ||
76 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Add the test that shows that concept of ignore_children is incomplete. | ||
4 | Actually, when we want to update something, ignoring permission of some | ||
5 | existing BdrvChild, we should ignore also the propagated effect of this | ||
6 | child to the other children. But that's not done. Better approach | ||
7 | (update permissions on already updated graph) will be implemented | ||
8 | later. | ||
9 | |||
10 | Now the test fails, so it's added with -d argument to not break make | ||
11 | check. | ||
12 | |||
13 | Test fails with | ||
14 | |||
15 | "Conflicts with use by fl1 as 'backing', which does not allow 'write' on base" | ||
16 | |||
17 | because when updating permissions we can ignore original top->fl1 | ||
18 | BdrvChild. But we don't ignore exclusive write permission in fl1->base | ||
19 | BdrvChild, which is propagated. Correct thing to do is make graph | ||
20 | change first and then do permission update from the top node. | ||
21 | |||
22 | To run test do | ||
23 | |||
24 | ./test-bdrv-graph-mod -d -p /bdrv-graph-mod/parallel-exclusive-write | ||
25 | |||
26 | from <build-directory>/tests. | ||
27 | |||
28 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
29 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
30 | Message-Id: <20210428151804.439460-2-vsementsov@virtuozzo.com> | ||
31 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
32 | --- | ||
33 | tests/unit/test-bdrv-graph-mod.c | 70 +++++++++++++++++++++++++++++++- | ||
34 | 1 file changed, 69 insertions(+), 1 deletion(-) | ||
35 | |||
36 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
39 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | /* | ||
42 | * Block node graph modifications tests | ||
43 | * | ||
44 | - * Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. | ||
45 | + * Copyright (c) 2019-2021 Virtuozzo International GmbH. All rights reserved. | ||
46 | * | ||
47 | * This program is free software; you can redistribute it and/or modify | ||
48 | * it under the terms of the GNU General Public License as published by | ||
49 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_no_perm = { | ||
50 | .bdrv_child_perm = no_perm_default_perms, | ||
51 | }; | ||
52 | |||
53 | +static void exclusive_write_perms(BlockDriverState *bs, BdrvChild *c, | ||
54 | + BdrvChildRole role, | ||
55 | + BlockReopenQueue *reopen_queue, | ||
56 | + uint64_t perm, uint64_t shared, | ||
57 | + uint64_t *nperm, uint64_t *nshared) | ||
58 | +{ | ||
59 | + *nperm = BLK_PERM_WRITE; | ||
60 | + *nshared = BLK_PERM_ALL & ~BLK_PERM_WRITE; | ||
61 | +} | ||
62 | + | ||
63 | +static BlockDriver bdrv_exclusive_writer = { | ||
64 | + .format_name = "exclusive-writer", | ||
65 | + .bdrv_child_perm = exclusive_write_perms, | ||
66 | +}; | ||
67 | + | ||
68 | static BlockDriverState *no_perm_node(const char *name) | ||
69 | { | ||
70 | return bdrv_new_open_driver(&bdrv_no_perm, name, BDRV_O_RDWR, &error_abort); | ||
71 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *pass_through_node(const char *name) | ||
72 | BDRV_O_RDWR, &error_abort); | ||
73 | } | ||
74 | |||
75 | +static BlockDriverState *exclusive_writer_node(const char *name) | ||
76 | +{ | ||
77 | + return bdrv_new_open_driver(&bdrv_exclusive_writer, name, | ||
78 | + BDRV_O_RDWR, &error_abort); | ||
79 | +} | ||
80 | + | ||
81 | /* | ||
82 | * test_update_perm_tree | ||
83 | * | ||
84 | @@ -XXX,XX +XXX,XX @@ static void test_should_update_child(void) | ||
85 | blk_unref(root); | ||
86 | } | ||
87 | |||
88 | +/* | ||
89 | + * test_parallel_exclusive_write | ||
90 | + * | ||
91 | + * Check that when we replace node, old permissions of the node being removed | ||
92 | + * doesn't break the replacement. | ||
93 | + */ | ||
94 | +static void test_parallel_exclusive_write(void) | ||
95 | +{ | ||
96 | + BlockDriverState *top = exclusive_writer_node("top"); | ||
97 | + BlockDriverState *base = no_perm_node("base"); | ||
98 | + BlockDriverState *fl1 = pass_through_node("fl1"); | ||
99 | + BlockDriverState *fl2 = pass_through_node("fl2"); | ||
100 | + | ||
101 | + /* | ||
102 | + * bdrv_attach_child() eats child bs reference, so we need two @base | ||
103 | + * references for two filters: | ||
104 | + */ | ||
105 | + bdrv_ref(base); | ||
106 | + | ||
107 | + bdrv_attach_child(top, fl1, "backing", &child_of_bds, BDRV_CHILD_DATA, | ||
108 | + &error_abort); | ||
109 | + bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILTERED, | ||
110 | + &error_abort); | ||
111 | + bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILTERED, | ||
112 | + &error_abort); | ||
113 | + | ||
114 | + bdrv_replace_node(fl1, fl2, &error_abort); | ||
115 | + | ||
116 | + bdrv_unref(fl2); | ||
117 | + bdrv_unref(top); | ||
118 | +} | ||
119 | + | ||
120 | int main(int argc, char *argv[]) | ||
121 | { | ||
122 | + int i; | ||
123 | + bool debug = false; | ||
124 | + | ||
125 | + for (i = 1; i < argc; i++) { | ||
126 | + if (!strcmp(argv[i], "-d")) { | ||
127 | + debug = true; | ||
128 | + break; | ||
129 | + } | ||
130 | + } | ||
131 | + | ||
132 | bdrv_init(); | ||
133 | qemu_init_main_loop(&error_abort); | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
136 | g_test_add_func("/bdrv-graph-mod/should-update-child", | ||
137 | test_should_update_child); | ||
138 | |||
139 | + if (debug) { | ||
140 | + g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
141 | + test_parallel_exclusive_write); | ||
142 | + } | ||
143 | + | ||
144 | return g_test_run(); | ||
145 | } | ||
146 | -- | ||
147 | 2.30.2 | ||
148 | |||
149 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Add test to show that simple DFS recursion order is not correct for | ||
4 | permission update. Correct order is topological-sort order, which will | ||
5 | be introduced later. | ||
6 | |||
7 | Consider the block driver which has two filter children: one active | ||
8 | with exclusive write access and one inactive with no specific | ||
9 | permissions. | ||
10 | |||
11 | And, these two children has a common base child, like this: | ||
12 | |||
13 | ┌─────┐ ┌──────┐ | ||
14 | │ fl2 │ ◀── │ top │ | ||
15 | └─────┘ └──────┘ | ||
16 | │ │ | ||
17 | │ │ w | ||
18 | │ ▼ | ||
19 | │ ┌──────┐ | ||
20 | │ │ fl1 │ | ||
21 | │ └──────┘ | ||
22 | │ │ | ||
23 | │ │ w | ||
24 | │ ▼ | ||
25 | │ ┌──────┐ | ||
26 | └───────▶ │ base │ | ||
27 | └──────┘ | ||
28 | |||
29 | So, exclusive write is propagated. | ||
30 | |||
31 | Assume, we want to make fl2 active instead of fl1. | ||
32 | So, we set some option for top driver and do permission update. | ||
33 | |||
34 | If permission update (remember, it's DFS) goes first through | ||
35 | top->fl1->base branch it will succeed: it firstly drop exclusive write | ||
36 | permissions and than apply them for another BdrvChildren. | ||
37 | But if permission update goes first through top->fl2->base branch it | ||
38 | will fail, as when we try to update fl2->base child, old not yet | ||
39 | updated fl1->base child will be in conflict. | ||
40 | |||
41 | Now test fails, so it runs only with -d flag. To run do | ||
42 | |||
43 | ./test-bdrv-graph-mod -d -p /bdrv-graph-mod/parallel-perm-update | ||
44 | |||
45 | from <build-directory>/tests. | ||
46 | |||
47 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
48 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
49 | Message-Id: <20210428151804.439460-3-vsementsov@virtuozzo.com> | ||
50 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
51 | --- | ||
52 | tests/unit/test-bdrv-graph-mod.c | 116 +++++++++++++++++++++++++++++++ | ||
53 | 1 file changed, 116 insertions(+) | ||
54 | |||
55 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
58 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static void test_parallel_exclusive_write(void) | ||
60 | bdrv_unref(top); | ||
61 | } | ||
62 | |||
63 | +static void write_to_file_perms(BlockDriverState *bs, BdrvChild *c, | ||
64 | + BdrvChildRole role, | ||
65 | + BlockReopenQueue *reopen_queue, | ||
66 | + uint64_t perm, uint64_t shared, | ||
67 | + uint64_t *nperm, uint64_t *nshared) | ||
68 | +{ | ||
69 | + if (bs->file && c == bs->file) { | ||
70 | + *nperm = BLK_PERM_WRITE; | ||
71 | + *nshared = BLK_PERM_ALL & ~BLK_PERM_WRITE; | ||
72 | + } else { | ||
73 | + *nperm = 0; | ||
74 | + *nshared = BLK_PERM_ALL; | ||
75 | + } | ||
76 | +} | ||
77 | + | ||
78 | +static BlockDriver bdrv_write_to_file = { | ||
79 | + .format_name = "tricky-perm", | ||
80 | + .bdrv_child_perm = write_to_file_perms, | ||
81 | +}; | ||
82 | + | ||
83 | + | ||
84 | +/* | ||
85 | + * The following test shows that topological-sort order is required for | ||
86 | + * permission update, simple DFS is not enough. | ||
87 | + * | ||
88 | + * Consider the block driver which has two filter children: one active | ||
89 | + * with exclusive write access and one inactive with no specific | ||
90 | + * permissions. | ||
91 | + * | ||
92 | + * And, these two children has a common base child, like this: | ||
93 | + * | ||
94 | + * ┌─────┐ ┌──────┐ | ||
95 | + * │ fl2 │ ◀── │ top │ | ||
96 | + * └─────┘ └──────┘ | ||
97 | + * │ │ | ||
98 | + * │ │ w | ||
99 | + * │ ▼ | ||
100 | + * │ ┌──────┐ | ||
101 | + * │ │ fl1 │ | ||
102 | + * │ └──────┘ | ||
103 | + * │ │ | ||
104 | + * │ │ w | ||
105 | + * │ ▼ | ||
106 | + * │ ┌──────┐ | ||
107 | + * └───────▶ │ base │ | ||
108 | + * └──────┘ | ||
109 | + * | ||
110 | + * So, exclusive write is propagated. | ||
111 | + * | ||
112 | + * Assume, we want to make fl2 active instead of fl1. | ||
113 | + * So, we set some option for top driver and do permission update. | ||
114 | + * | ||
115 | + * With simple DFS, if permission update goes first through | ||
116 | + * top->fl1->base branch it will succeed: it firstly drop exclusive write | ||
117 | + * permissions and than apply them for another BdrvChildren. | ||
118 | + * But if permission update goes first through top->fl2->base branch it | ||
119 | + * will fail, as when we try to update fl2->base child, old not yet | ||
120 | + * updated fl1->base child will be in conflict. | ||
121 | + * | ||
122 | + * With topological-sort order we always update parents before children, so fl1 | ||
123 | + * and fl2 are both updated when we update base and there is no conflict. | ||
124 | + */ | ||
125 | +static void test_parallel_perm_update(void) | ||
126 | +{ | ||
127 | + BlockDriverState *top = no_perm_node("top"); | ||
128 | + BlockDriverState *tricky = | ||
129 | + bdrv_new_open_driver(&bdrv_write_to_file, "tricky", BDRV_O_RDWR, | ||
130 | + &error_abort); | ||
131 | + BlockDriverState *base = no_perm_node("base"); | ||
132 | + BlockDriverState *fl1 = pass_through_node("fl1"); | ||
133 | + BlockDriverState *fl2 = pass_through_node("fl2"); | ||
134 | + BdrvChild *c_fl1, *c_fl2; | ||
135 | + | ||
136 | + /* | ||
137 | + * bdrv_attach_child() eats child bs reference, so we need two @base | ||
138 | + * references for two filters: | ||
139 | + */ | ||
140 | + bdrv_ref(base); | ||
141 | + | ||
142 | + bdrv_attach_child(top, tricky, "file", &child_of_bds, BDRV_CHILD_DATA, | ||
143 | + &error_abort); | ||
144 | + c_fl1 = bdrv_attach_child(tricky, fl1, "first", &child_of_bds, | ||
145 | + BDRV_CHILD_FILTERED, &error_abort); | ||
146 | + c_fl2 = bdrv_attach_child(tricky, fl2, "second", &child_of_bds, | ||
147 | + BDRV_CHILD_FILTERED, &error_abort); | ||
148 | + bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILTERED, | ||
149 | + &error_abort); | ||
150 | + bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILTERED, | ||
151 | + &error_abort); | ||
152 | + | ||
153 | + /* Select fl1 as first child to be active */ | ||
154 | + tricky->file = c_fl1; | ||
155 | + bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); | ||
156 | + | ||
157 | + assert(c_fl1->perm & BLK_PERM_WRITE); | ||
158 | + assert(!(c_fl2->perm & BLK_PERM_WRITE)); | ||
159 | + | ||
160 | + /* Now, try to switch active child and update permissions */ | ||
161 | + tricky->file = c_fl2; | ||
162 | + bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); | ||
163 | + | ||
164 | + assert(c_fl2->perm & BLK_PERM_WRITE); | ||
165 | + assert(!(c_fl1->perm & BLK_PERM_WRITE)); | ||
166 | + | ||
167 | + /* Switch once more, to not care about real child order in the list */ | ||
168 | + tricky->file = c_fl1; | ||
169 | + bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); | ||
170 | + | ||
171 | + assert(c_fl1->perm & BLK_PERM_WRITE); | ||
172 | + assert(!(c_fl2->perm & BLK_PERM_WRITE)); | ||
173 | + | ||
174 | + bdrv_unref(top); | ||
175 | +} | ||
176 | + | ||
177 | int main(int argc, char *argv[]) | ||
178 | { | ||
179 | int i; | ||
180 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
181 | if (debug) { | ||
182 | g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
183 | test_parallel_exclusive_write); | ||
184 | + g_test_add_func("/bdrv-graph-mod/parallel-perm-update", | ||
185 | + test_parallel_perm_update); | ||
186 | } | ||
187 | |||
188 | return g_test_run(); | ||
189 | -- | ||
190 | 2.30.2 | ||
191 | |||
192 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | bdrv_append() is not quite good for inserting filters: it does extra | ||
4 | permission update in intermediate state, where filter get it filtered | ||
5 | child but is not yet replace it in a backing chain. | ||
6 | |||
7 | Some filters (for example backup-top) may want permissions even when | ||
8 | have no parents. And described intermediate state becomes invalid. | ||
9 | |||
10 | That's (half a) reason, why we need "inactive" state for backup-top | ||
11 | filter. | ||
12 | |||
13 | bdrv_append() will be improved later, now let's add a unit test. | ||
14 | |||
15 | Now test fails, so it runs only with -d flag. To run do | ||
16 | |||
17 | ./test-bdrv-graph-mod -d -p /bdrv-graph-mod/append-greedy-filter | ||
18 | |||
19 | from <build-directory>/tests. | ||
20 | |||
21 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
22 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
23 | Message-Id: <20210428151804.439460-4-vsementsov@virtuozzo.com> | ||
24 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
25 | --- | ||
26 | tests/unit/test-bdrv-graph-mod.c | 33 ++++++++++++++++++++++++++++++++ | ||
27 | 1 file changed, 33 insertions(+) | ||
28 | |||
29 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
32 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void test_parallel_perm_update(void) | ||
34 | bdrv_unref(top); | ||
35 | } | ||
36 | |||
37 | +/* | ||
38 | + * It's possible that filter required permissions allows to insert it to backing | ||
39 | + * chain, like: | ||
40 | + * | ||
41 | + * 1. [top] -> [filter] -> [base] | ||
42 | + * | ||
43 | + * but doesn't allow to add it as a branch: | ||
44 | + * | ||
45 | + * 2. [filter] --\ | ||
46 | + * v | ||
47 | + * [top] -> [base] | ||
48 | + * | ||
49 | + * So, inserting such filter should do all graph modifications and only then | ||
50 | + * update permissions. If we try to go through intermediate state [2] and update | ||
51 | + * permissions on it we'll fail. | ||
52 | + * | ||
53 | + * Let's check that bdrv_append() can append such a filter. | ||
54 | + */ | ||
55 | +static void test_append_greedy_filter(void) | ||
56 | +{ | ||
57 | + BlockDriverState *top = exclusive_writer_node("top"); | ||
58 | + BlockDriverState *base = no_perm_node("base"); | ||
59 | + BlockDriverState *fl = exclusive_writer_node("fl1"); | ||
60 | + | ||
61 | + bdrv_attach_child(top, base, "backing", &child_of_bds, BDRV_CHILD_COW, | ||
62 | + &error_abort); | ||
63 | + | ||
64 | + bdrv_append(fl, base, &error_abort); | ||
65 | + bdrv_unref(top); | ||
66 | +} | ||
67 | + | ||
68 | int main(int argc, char *argv[]) | ||
69 | { | ||
70 | int i; | ||
71 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
72 | test_parallel_exclusive_write); | ||
73 | g_test_add_func("/bdrv-graph-mod/parallel-perm-update", | ||
74 | test_parallel_perm_update); | ||
75 | + g_test_add_func("/bdrv-graph-mod/append-greedy-filter", | ||
76 | + test_append_greedy_filter); | ||
77 | } | ||
78 | |||
79 | return g_test_run(); | ||
80 | -- | ||
81 | 2.30.2 | ||
82 | |||
83 | diff view generated by jsdifflib |
1 | error_setg_errno() is meant for cases where we got an errno from the OS | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | that can add useful extra information to an error message. It's | ||
3 | pointless if we pass a constant errno, these cases should use plain | ||
4 | error_setg(). | ||
5 | 2 | ||
3 | We have too much comments for this feature. It seems better just don't | ||
4 | do it. Most of real users (tests don't count) have to create additional | ||
5 | reference. | ||
6 | |||
7 | Drop also comment in external_snapshot_prepare: | ||
8 | - bdrv_append doesn't "remove" old bs in common sense, it sounds | ||
9 | strange | ||
10 | - the fact that bdrv_append can fail is obvious from the context | ||
11 | - the fact that we must rollback all changes in transaction abort is | ||
12 | known (it's the direct role of abort) | ||
13 | |||
14 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
15 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | Message-Id: <20210428151804.439460-5-vsementsov@virtuozzo.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
9 | --- | 18 | --- |
10 | block/vhdx.c | 9 ++++----- | 19 | block.c | 25 +++---------------------- |
11 | 1 file changed, 4 insertions(+), 5 deletions(-) | 20 | block/backup-top.c | 1 - |
21 | block/commit.c | 1 + | ||
22 | block/mirror.c | 3 --- | ||
23 | blockdev.c | 4 ---- | ||
24 | tests/unit/test-bdrv-drain.c | 2 +- | ||
25 | tests/unit/test-bdrv-graph-mod.c | 3 +++ | ||
26 | 7 files changed, 8 insertions(+), 31 deletions(-) | ||
12 | 27 | ||
13 | diff --git a/block/vhdx.c b/block/vhdx.c | 28 | diff --git a/block.c b/block.c |
14 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/vhdx.c | 30 | --- a/block.c |
16 | +++ b/block/vhdx.c | 31 | +++ b/block.c |
17 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 32 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, |
18 | /* Validate options and set default values */ | 33 | goto out; |
19 | image_size = vhdx_opts->size; | ||
20 | if (image_size > VHDX_MAX_IMAGE_SIZE) { | ||
21 | - error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB"); | ||
22 | + error_setg(errp, "Image size too large; max of 64TB"); | ||
23 | return -EINVAL; | ||
24 | } | 34 | } |
25 | 35 | ||
26 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 36 | - /* bdrv_append() consumes a strong reference to bs_snapshot |
27 | log_size = vhdx_opts->log_size; | 37 | - * (i.e. it will call bdrv_unref() on it) even on error, so in |
38 | - * order to be able to return one, we have to increase | ||
39 | - * bs_snapshot's refcount here */ | ||
40 | - bdrv_ref(bs_snapshot); | ||
41 | ret = bdrv_append(bs_snapshot, bs, errp); | ||
42 | if (ret < 0) { | ||
43 | bs_snapshot = NULL; | ||
44 | @@ -XXX,XX +XXX,XX @@ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
45 | * bs_new must not be attached to a BlockBackend. | ||
46 | * | ||
47 | * This function does not create any image files. | ||
48 | - * | ||
49 | - * bdrv_append() takes ownership of a bs_new reference and unrefs it because | ||
50 | - * that's what the callers commonly need. bs_new will be referenced by the old | ||
51 | - * parents of bs_top after bdrv_append() returns. If the caller needs to keep a | ||
52 | - * reference of its own, it must call bdrv_ref(). | ||
53 | */ | ||
54 | int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, | ||
55 | Error **errp) | ||
56 | { | ||
57 | int ret = bdrv_set_backing_hd(bs_new, bs_top, errp); | ||
58 | if (ret < 0) { | ||
59 | - goto out; | ||
60 | + return ret; | ||
28 | } | 61 | } |
29 | if (log_size < MiB || (log_size % MiB) != 0) { | 62 | |
30 | - error_setg_errno(errp, EINVAL, "Log size must be a multiple of 1 MB"); | 63 | ret = bdrv_replace_node(bs_top, bs_new, errp); |
31 | + error_setg(errp, "Log size must be a multiple of 1 MB"); | 64 | if (ret < 0) { |
32 | return -EINVAL; | 65 | bdrv_set_backing_hd(bs_new, NULL, &error_abort); |
66 | - goto out; | ||
67 | + return ret; | ||
33 | } | 68 | } |
34 | 69 | ||
35 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 70 | - ret = 0; |
71 | - | ||
72 | -out: | ||
73 | - /* | ||
74 | - * bs_new is now referenced by its new parents, we don't need the | ||
75 | - * additional reference any more. | ||
76 | - */ | ||
77 | - bdrv_unref(bs_new); | ||
78 | - | ||
79 | - return ret; | ||
80 | + return 0; | ||
81 | } | ||
82 | |||
83 | static void bdrv_delete(BlockDriverState *bs) | ||
84 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/block/backup-top.c | ||
87 | +++ b/block/backup-top.c | ||
88 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, | ||
89 | |||
90 | bdrv_drained_begin(source); | ||
91 | |||
92 | - bdrv_ref(top); | ||
93 | ret = bdrv_append(top, source, errp); | ||
94 | if (ret < 0) { | ||
95 | error_prepend(errp, "Cannot append backup-top filter: "); | ||
96 | diff --git a/block/commit.c b/block/commit.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/block/commit.c | ||
99 | +++ b/block/commit.c | ||
100 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
101 | commit_top_bs->total_sectors = top->total_sectors; | ||
102 | |||
103 | ret = bdrv_append(commit_top_bs, top, errp); | ||
104 | + bdrv_unref(commit_top_bs); /* referenced by new parents or failed */ | ||
105 | if (ret < 0) { | ||
106 | commit_top_bs = NULL; | ||
107 | goto fail; | ||
108 | diff --git a/block/mirror.c b/block/mirror.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/block/mirror.c | ||
111 | +++ b/block/mirror.c | ||
112 | @@ -XXX,XX +XXX,XX @@ static BlockJob *mirror_start_job( | ||
113 | |||
114 | bs_opaque->is_commit = target_is_backing; | ||
115 | |||
116 | - /* bdrv_append takes ownership of the mirror_top_bs reference, need to keep | ||
117 | - * it alive until block_job_create() succeeds even if bs has no parent. */ | ||
118 | - bdrv_ref(mirror_top_bs); | ||
119 | bdrv_drained_begin(bs); | ||
120 | ret = bdrv_append(mirror_top_bs, bs, errp); | ||
121 | bdrv_drained_end(bs); | ||
122 | diff --git a/blockdev.c b/blockdev.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/blockdev.c | ||
125 | +++ b/blockdev.c | ||
126 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
127 | goto out; | ||
36 | } | 128 | } |
37 | 129 | ||
38 | if (block_size < MiB || (block_size % MiB) != 0) { | 130 | - /* This removes our old bs and adds the new bs. This is an operation that |
39 | - error_setg_errno(errp, EINVAL, "Block size must be a multiple of 1 MB"); | 131 | - * can fail, so we need to do it in .prepare; undoing it for abort is |
40 | + error_setg(errp, "Block size must be a multiple of 1 MB"); | 132 | - * always possible. */ |
41 | return -EINVAL; | 133 | - bdrv_ref(state->new_bs); |
42 | } | 134 | ret = bdrv_append(state->new_bs, state->old_bs, errp); |
43 | if (!is_power_of_2(block_size)) { | 135 | if (ret < 0) { |
44 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 136 | goto out; |
45 | return -EINVAL; | 137 | diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c |
46 | } | 138 | index XXXXXXX..XXXXXXX 100644 |
47 | if (block_size > VHDX_BLOCK_SIZE_MAX) { | 139 | --- a/tests/unit/test-bdrv-drain.c |
48 | - error_setg_errno(errp, EINVAL, "Block size must not exceed %d", | 140 | +++ b/tests/unit/test-bdrv-drain.c |
49 | - VHDX_BLOCK_SIZE_MAX); | 141 | @@ -XXX,XX +XXX,XX @@ static void test_append_to_drained(void) |
50 | + error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX); | 142 | g_assert_cmpint(base_s->drain_count, ==, 1); |
51 | return -EINVAL; | 143 | g_assert_cmpint(base->in_flight, ==, 0); |
52 | } | 144 | |
145 | - /* Takes ownership of overlay, so we don't have to unref it later */ | ||
146 | bdrv_append(overlay, base, &error_abort); | ||
147 | g_assert_cmpint(base->in_flight, ==, 0); | ||
148 | g_assert_cmpint(overlay->in_flight, ==, 0); | ||
149 | @@ -XXX,XX +XXX,XX @@ static void test_append_to_drained(void) | ||
150 | g_assert_cmpint(overlay->quiesce_counter, ==, 0); | ||
151 | g_assert_cmpint(overlay_s->drain_count, ==, 0); | ||
152 | |||
153 | + bdrv_unref(overlay); | ||
154 | bdrv_unref(base); | ||
155 | blk_unref(blk); | ||
156 | } | ||
157 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
158 | index XXXXXXX..XXXXXXX 100644 | ||
159 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
160 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
161 | @@ -XXX,XX +XXX,XX @@ static void test_update_perm_tree(void) | ||
162 | ret = bdrv_append(filter, bs, NULL); | ||
163 | g_assert_cmpint(ret, <, 0); | ||
164 | |||
165 | + bdrv_unref(filter); | ||
166 | blk_unref(root); | ||
167 | } | ||
168 | |||
169 | @@ -XXX,XX +XXX,XX @@ static void test_should_update_child(void) | ||
170 | bdrv_append(filter, bs, &error_abort); | ||
171 | g_assert(target->backing->bs == bs); | ||
172 | |||
173 | + bdrv_unref(filter); | ||
174 | bdrv_unref(bs); | ||
175 | blk_unref(root); | ||
176 | } | ||
177 | @@ -XXX,XX +XXX,XX @@ static void test_append_greedy_filter(void) | ||
178 | &error_abort); | ||
179 | |||
180 | bdrv_append(fl, base, &error_abort); | ||
181 | + bdrv_unref(fl); | ||
182 | bdrv_unref(top); | ||
183 | } | ||
53 | 184 | ||
54 | -- | 185 | -- |
55 | 2.13.6 | 186 | 2.30.2 |
56 | 187 | ||
57 | 188 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Add new handler to get aio context and implement it in all child | ||
4 | classes. Add corresponding public interface to be used soon. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Message-Id: <20210428151804.439460-6-vsementsov@virtuozzo.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | include/block/block.h | 2 ++ | ||
13 | include/block/block_int.h | 2 ++ | ||
14 | block.c | 13 +++++++++++++ | ||
15 | block/block-backend.c | 9 +++++++++ | ||
16 | blockjob.c | 8 ++++++++ | ||
17 | 5 files changed, 34 insertions(+) | ||
18 | |||
19 | diff --git a/include/block/block.h b/include/block/block.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/include/block/block.h | ||
22 | +++ b/include/block/block.h | ||
23 | @@ -XXX,XX +XXX,XX @@ bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, | ||
24 | GSList **ignore, Error **errp); | ||
25 | bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, | ||
26 | GSList **ignore, Error **errp); | ||
27 | +AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); | ||
28 | + | ||
29 | int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); | ||
30 | int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); | ||
31 | |||
32 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/include/block/block_int.h | ||
35 | +++ b/include/block/block_int.h | ||
36 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
37 | bool (*can_set_aio_ctx)(BdrvChild *child, AioContext *ctx, | ||
38 | GSList **ignore, Error **errp); | ||
39 | void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); | ||
40 | + | ||
41 | + AioContext *(*get_parent_aio_context)(BdrvChild *child); | ||
42 | }; | ||
43 | |||
44 | extern const BdrvChildClass child_of_bds; | ||
45 | diff --git a/block.c b/block.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/block.c | ||
48 | +++ b/block.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static int bdrv_child_cb_update_filename(BdrvChild *c, BlockDriverState *base, | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | +static AioContext *bdrv_child_cb_get_parent_aio_context(BdrvChild *c) | ||
54 | +{ | ||
55 | + BlockDriverState *bs = c->opaque; | ||
56 | + | ||
57 | + return bdrv_get_aio_context(bs); | ||
58 | +} | ||
59 | + | ||
60 | const BdrvChildClass child_of_bds = { | ||
61 | .parent_is_bds = true, | ||
62 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
63 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_of_bds = { | ||
64 | .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, | ||
65 | .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
66 | .update_filename = bdrv_child_cb_update_filename, | ||
67 | + .get_parent_aio_context = bdrv_child_cb_get_parent_aio_context, | ||
68 | }; | ||
69 | |||
70 | +AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c) | ||
71 | +{ | ||
72 | + return c->klass->get_parent_aio_context(c); | ||
73 | +} | ||
74 | + | ||
75 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | ||
76 | { | ||
77 | int open_flags = flags; | ||
78 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/block/block-backend.c | ||
81 | +++ b/block/block-backend.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static void blk_root_detach(BdrvChild *child) | ||
83 | } | ||
84 | } | ||
85 | |||
86 | +static AioContext *blk_root_get_parent_aio_context(BdrvChild *c) | ||
87 | +{ | ||
88 | + BlockBackend *blk = c->opaque; | ||
89 | + | ||
90 | + return blk_get_aio_context(blk); | ||
91 | +} | ||
92 | + | ||
93 | static const BdrvChildClass child_root = { | ||
94 | .inherit_options = blk_root_inherit_options, | ||
95 | |||
96 | @@ -XXX,XX +XXX,XX @@ static const BdrvChildClass child_root = { | ||
97 | |||
98 | .can_set_aio_ctx = blk_root_can_set_aio_ctx, | ||
99 | .set_aio_ctx = blk_root_set_aio_ctx, | ||
100 | + | ||
101 | + .get_parent_aio_context = blk_root_get_parent_aio_context, | ||
102 | }; | ||
103 | |||
104 | /* | ||
105 | diff --git a/blockjob.c b/blockjob.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/blockjob.c | ||
108 | +++ b/blockjob.c | ||
109 | @@ -XXX,XX +XXX,XX @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx, | ||
110 | job->job.aio_context = ctx; | ||
111 | } | ||
112 | |||
113 | +static AioContext *child_job_get_parent_aio_context(BdrvChild *c) | ||
114 | +{ | ||
115 | + BlockJob *job = c->opaque; | ||
116 | + | ||
117 | + return job->job.aio_context; | ||
118 | +} | ||
119 | + | ||
120 | static const BdrvChildClass child_job = { | ||
121 | .get_parent_desc = child_job_get_parent_desc, | ||
122 | .drained_begin = child_job_drained_begin, | ||
123 | @@ -XXX,XX +XXX,XX @@ static const BdrvChildClass child_job = { | ||
124 | .can_set_aio_ctx = child_job_can_set_aio_ctx, | ||
125 | .set_aio_ctx = child_job_set_aio_ctx, | ||
126 | .stay_at_node = true, | ||
127 | + .get_parent_aio_context = child_job_get_parent_aio_context, | ||
128 | }; | ||
129 | |||
130 | void block_job_remove_all_bdrv(BlockJob *job) | ||
131 | -- | ||
132 | 2.30.2 | ||
133 | |||
134 | diff view generated by jsdifflib |
1 | What static=on really does is what we call metadata preallocation for | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | other block drivers. While we can still change the QMP interface, make | ||
3 | it more consistent by using 'preallocation' for VDI, too. | ||
4 | 2 | ||
5 | This doesn't implement any new functionality, so the only supported | 3 | Passing parent aio context is redundant, as child_class and parent |
6 | preallocation modes are 'off' and 'metadata' for now. | 4 | opaque pointer are enough to retrieve it. Drop the argument and use new |
5 | bdrv_child_get_parent_aio_context() interface. | ||
7 | 6 | ||
7 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Message-Id: <20210428151804.439460-7-vsementsov@virtuozzo.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | --- | 12 | --- |
11 | qapi/block-core.json | 7 +++---- | 13 | include/block/block_int.h | 1 - |
12 | block/vdi.c | 24 ++++++++++++++++++++++-- | 14 | block.c | 8 +++++--- |
13 | 2 files changed, 25 insertions(+), 6 deletions(-) | 15 | block/block-backend.c | 4 ++-- |
16 | blockjob.c | 3 +-- | ||
17 | 4 files changed, 8 insertions(+), 8 deletions(-) | ||
14 | 18 | ||
15 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 19 | diff --git a/include/block/block_int.h b/include/block/block_int.h |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/qapi/block-core.json | 21 | --- a/include/block/block_int.h |
18 | +++ b/qapi/block-core.json | 22 | +++ b/include/block/block_int.h |
19 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, |
20 | # | 24 | const char *child_name, |
21 | # @file Node to create the image format on | 25 | const BdrvChildClass *child_class, |
22 | # @size Size of the virtual disk in bytes | 26 | BdrvChildRole child_role, |
23 | -# @static Whether to create a statically (true) or | 27 | - AioContext *ctx, |
24 | -# dynamically (false) allocated image | 28 | uint64_t perm, uint64_t shared_perm, |
25 | -# (default: false, i.e. dynamic) | 29 | void *opaque, Error **errp); |
26 | +# @preallocation Preallocation mode for the new image (allowed values: off, | 30 | void bdrv_root_unref_child(BdrvChild *child); |
27 | +# metadata; default: off) | 31 | diff --git a/block.c b/block.c |
28 | # | ||
29 | # Since: 2.12 | ||
30 | ## | ||
31 | { 'struct': 'BlockdevCreateOptionsVdi', | ||
32 | 'data': { 'file': 'BlockdevRef', | ||
33 | 'size': 'size', | ||
34 | - '*static': 'bool' } } | ||
35 | + '*preallocation': 'PreallocMode' } } | ||
36 | |||
37 | ## | ||
38 | # @BlockdevVhdxSubformat: | ||
39 | diff --git a/block/vdi.c b/block/vdi.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/block/vdi.c | 33 | --- a/block.c |
42 | +++ b/block/vdi.c | 34 | +++ b/block.c |
43 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | 35 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, |
44 | int ret = 0; | 36 | const char *child_name, |
45 | uint64_t bytes = 0; | 37 | const BdrvChildClass *child_class, |
46 | uint32_t blocks; | 38 | BdrvChildRole child_role, |
47 | - uint32_t image_type = VDI_TYPE_DYNAMIC; | 39 | - AioContext *ctx, |
48 | + uint32_t image_type; | 40 | uint64_t perm, uint64_t shared_perm, |
49 | VdiHeader header; | 41 | void *opaque, Error **errp) |
50 | size_t i; | 42 | { |
51 | size_t bmap_size; | 43 | BdrvChild *child; |
52 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | ||
53 | |||
54 | /* Validate options and set default values */ | ||
55 | bytes = vdi_opts->size; | ||
56 | - if (vdi_opts->q_static) { | ||
57 | + | ||
58 | + if (!vdi_opts->has_preallocation) { | ||
59 | + vdi_opts->preallocation = PREALLOC_MODE_OFF; | ||
60 | + } | ||
61 | + switch (vdi_opts->preallocation) { | ||
62 | + case PREALLOC_MODE_OFF: | ||
63 | + image_type = VDI_TYPE_DYNAMIC; | ||
64 | + break; | ||
65 | + case PREALLOC_MODE_METADATA: | ||
66 | image_type = VDI_TYPE_STATIC; | ||
67 | + break; | ||
68 | + default: | ||
69 | + error_setg(errp, "Preallocation mode not supported for vdi"); | ||
70 | + return -EINVAL; | ||
71 | } | ||
72 | + | ||
73 | #ifndef CONFIG_VDI_STATIC_IMAGE | ||
74 | if (image_type == VDI_TYPE_STATIC) { | ||
75 | ret = -ENOTSUP; | ||
76 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, | ||
77 | BlockdevCreateOptions *create_options = NULL; | ||
78 | BlockDriverState *bs_file = NULL; | ||
79 | uint64_t block_size = DEFAULT_CLUSTER_SIZE; | ||
80 | + bool is_static = false; | ||
81 | Visitor *v; | ||
82 | Error *local_err = NULL; | 44 | Error *local_err = NULL; |
83 | int ret; | 45 | int ret; |
84 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, | 46 | + AioContext *ctx; |
85 | goto done; | 47 | |
48 | ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp); | ||
49 | if (ret < 0) { | ||
50 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
51 | .opaque = opaque, | ||
52 | }; | ||
53 | |||
54 | + ctx = bdrv_child_get_parent_aio_context(child); | ||
55 | + | ||
56 | /* If the AioContexts don't match, first try to move the subtree of | ||
57 | * child_bs into the AioContext of the new parent. If this doesn't work, | ||
58 | * try moving the parent into the AioContext of child_bs instead. */ | ||
59 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
60 | perm, shared_perm, &perm, &shared_perm); | ||
61 | |||
62 | child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
63 | - child_role, bdrv_get_aio_context(parent_bs), | ||
64 | - perm, shared_perm, parent_bs, errp); | ||
65 | + child_role, perm, shared_perm, parent_bs, | ||
66 | + errp); | ||
67 | if (child == NULL) { | ||
68 | return NULL; | ||
86 | } | 69 | } |
87 | #endif | 70 | diff --git a/block/block-backend.c b/block/block-backend.c |
88 | + if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) { | 71 | index XXXXXXX..XXXXXXX 100644 |
89 | + is_static = true; | 72 | --- a/block/block-backend.c |
90 | + } | 73 | +++ b/block/block-backend.c |
91 | 74 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, | |
92 | qdict = qemu_opts_to_qdict_filtered(opts, NULL, &vdi_create_opts, true); | 75 | |
93 | 76 | blk->root = bdrv_root_attach_child(bs, "root", &child_root, | |
94 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, | 77 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, |
95 | 78 | - blk->ctx, perm, BLK_PERM_ALL, blk, errp); | |
96 | qdict_put_str(qdict, "driver", "vdi"); | 79 | + perm, BLK_PERM_ALL, blk, errp); |
97 | qdict_put_str(qdict, "file", bs_file->node_name); | 80 | if (!blk->root) { |
98 | + if (is_static) { | 81 | blk_unref(blk); |
99 | + qdict_put_str(qdict, "preallocation", "metadata"); | 82 | return NULL; |
100 | + } | 83 | @@ -XXX,XX +XXX,XX @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) |
101 | 84 | bdrv_ref(bs); | |
102 | /* Get the QAPI object */ | 85 | blk->root = bdrv_root_attach_child(bs, "root", &child_root, |
103 | v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | 86 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, |
87 | - blk->ctx, blk->perm, blk->shared_perm, | ||
88 | + blk->perm, blk->shared_perm, | ||
89 | blk, errp); | ||
90 | if (blk->root == NULL) { | ||
91 | return -EPERM; | ||
92 | diff --git a/blockjob.c b/blockjob.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/blockjob.c | ||
95 | +++ b/blockjob.c | ||
96 | @@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, | ||
97 | if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) { | ||
98 | aio_context_release(job->job.aio_context); | ||
99 | } | ||
100 | - c = bdrv_root_attach_child(bs, name, &child_job, 0, | ||
101 | - job->job.aio_context, perm, shared_perm, job, | ||
102 | + c = bdrv_root_attach_child(bs, name, &child_job, 0, perm, shared_perm, job, | ||
103 | errp); | ||
104 | if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) { | ||
105 | aio_context_acquire(job->job.aio_context); | ||
104 | -- | 106 | -- |
105 | 2.13.6 | 107 | 2.30.2 |
106 | 108 | ||
107 | 109 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | These functions are called only from bdrv_reopen_multiple() in block.c. | ||
4 | No reason to publish them. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Message-Id: <20210428151804.439460-8-vsementsov@virtuozzo.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | include/block/block.h | 4 ---- | ||
13 | block.c | 13 +++++++++---- | ||
14 | 2 files changed, 9 insertions(+), 8 deletions(-) | ||
15 | |||
16 | diff --git a/include/block/block.h b/include/block/block.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/block/block.h | ||
19 | +++ b/include/block/block.h | ||
20 | @@ -XXX,XX +XXX,XX @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, | ||
21 | int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp); | ||
22 | int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, | ||
23 | Error **errp); | ||
24 | -int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
25 | - BlockReopenQueue *queue, Error **errp); | ||
26 | -void bdrv_reopen_commit(BDRVReopenState *reopen_state); | ||
27 | -void bdrv_reopen_abort(BDRVReopenState *reopen_state); | ||
28 | int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, | ||
29 | int64_t bytes, BdrvRequestFlags flags); | ||
30 | int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); | ||
31 | diff --git a/block.c b/block.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block.c | ||
34 | +++ b/block.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
36 | BdrvChildRole child_role, | ||
37 | Error **errp); | ||
38 | |||
39 | +static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue | ||
40 | + *queue, Error **errp); | ||
41 | +static void bdrv_reopen_commit(BDRVReopenState *reopen_state); | ||
42 | +static void bdrv_reopen_abort(BDRVReopenState *reopen_state); | ||
43 | + | ||
44 | /* If non-zero, use only whitelisted block drivers */ | ||
45 | static int use_bdrv_whitelist; | ||
46 | |||
47 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, | ||
48 | * commit() for any other BDS that have been left in a prepare() state | ||
49 | * | ||
50 | */ | ||
51 | -int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, | ||
52 | - Error **errp) | ||
53 | +static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
54 | + BlockReopenQueue *queue, Error **errp) | ||
55 | { | ||
56 | int ret = -1; | ||
57 | int old_flags; | ||
58 | @@ -XXX,XX +XXX,XX @@ error: | ||
59 | * makes them final by swapping the staging BlockDriverState contents into | ||
60 | * the active BlockDriverState contents. | ||
61 | */ | ||
62 | -void bdrv_reopen_commit(BDRVReopenState *reopen_state) | ||
63 | +static void bdrv_reopen_commit(BDRVReopenState *reopen_state) | ||
64 | { | ||
65 | BlockDriver *drv; | ||
66 | BlockDriverState *bs; | ||
67 | @@ -XXX,XX +XXX,XX @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) | ||
68 | * Abort the reopen, and delete and free the staged changes in | ||
69 | * reopen_state | ||
70 | */ | ||
71 | -void bdrv_reopen_abort(BDRVReopenState *reopen_state) | ||
72 | +static void bdrv_reopen_abort(BDRVReopenState *reopen_state) | ||
73 | { | ||
74 | BlockDriver *drv; | ||
75 | |||
76 | -- | ||
77 | 2.30.2 | ||
78 | |||
79 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | |
2 | |||
3 | Add simple transaction API to use in further update of block graph | ||
4 | operations. | ||
5 | |||
6 | Supposed usage is: | ||
7 | |||
8 | - "prepare" is main function of the action and it should make the main | ||
9 | effect of the action to be visible for the following actions, keeping | ||
10 | possibility of roll-back, saving necessary things in action state, | ||
11 | which is prepended to the action list (to do that, prepare func | ||
12 | should call tran_add()). So, driver struct doesn't include "prepare" | ||
13 | field, as it is supposed to be called directly. | ||
14 | |||
15 | - commit/rollback is supposed to be called for the list of action | ||
16 | states, to commit/rollback all the actions in reverse order | ||
17 | |||
18 | - When possible "commit" should not make visible effect for other | ||
19 | actions, which make possible transparent logical interaction between | ||
20 | actions. | ||
21 | |||
22 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
23 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
24 | Message-Id: <20210428151804.439460-9-vsementsov@virtuozzo.com> | ||
25 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
26 | --- | ||
27 | include/qemu/transactions.h | 63 ++++++++++++++++++++++++ | ||
28 | util/transactions.c | 96 +++++++++++++++++++++++++++++++++++++ | ||
29 | MAINTAINERS | 6 +++ | ||
30 | util/meson.build | 1 + | ||
31 | 4 files changed, 166 insertions(+) | ||
32 | create mode 100644 include/qemu/transactions.h | ||
33 | create mode 100644 util/transactions.c | ||
34 | |||
35 | diff --git a/include/qemu/transactions.h b/include/qemu/transactions.h | ||
36 | new file mode 100644 | ||
37 | index XXXXXXX..XXXXXXX | ||
38 | --- /dev/null | ||
39 | +++ b/include/qemu/transactions.h | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | +/* | ||
42 | + * Simple transactions API | ||
43 | + * | ||
44 | + * Copyright (c) 2021 Virtuozzo International GmbH. | ||
45 | + * | ||
46 | + * Author: | ||
47 | + * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
48 | + * | ||
49 | + * This program is free software; you can redistribute it and/or modify | ||
50 | + * it under the terms of the GNU General Public License as published by | ||
51 | + * the Free Software Foundation; either version 2 of the License, or | ||
52 | + * (at your option) any later version. | ||
53 | + * | ||
54 | + * This program is distributed in the hope that it will be useful, | ||
55 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
56 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
57 | + * GNU General Public License for more details. | ||
58 | + * | ||
59 | + * You should have received a copy of the GNU General Public License | ||
60 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
61 | + * | ||
62 | + * | ||
63 | + * = Generic transaction API = | ||
64 | + * | ||
65 | + * The intended usage is the following: you create "prepare" functions, which | ||
66 | + * represents the actions. They will usually have Transaction* argument, and | ||
67 | + * call tran_add() to register finalization callbacks. For finalization | ||
68 | + * callbacks, prepare corresponding TransactionActionDrv structures. | ||
69 | + * | ||
70 | + * Then, when you need to make a transaction, create an empty Transaction by | ||
71 | + * tran_create(), call your "prepare" functions on it, and finally call | ||
72 | + * tran_abort() or tran_commit() to finalize the transaction by corresponding | ||
73 | + * finalization actions in reverse order. | ||
74 | + */ | ||
75 | + | ||
76 | +#ifndef QEMU_TRANSACTIONS_H | ||
77 | +#define QEMU_TRANSACTIONS_H | ||
78 | + | ||
79 | +#include <gmodule.h> | ||
80 | + | ||
81 | +typedef struct TransactionActionDrv { | ||
82 | + void (*abort)(void *opaque); | ||
83 | + void (*commit)(void *opaque); | ||
84 | + void (*clean)(void *opaque); | ||
85 | +} TransactionActionDrv; | ||
86 | + | ||
87 | +typedef struct Transaction Transaction; | ||
88 | + | ||
89 | +Transaction *tran_new(void); | ||
90 | +void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque); | ||
91 | +void tran_abort(Transaction *tran); | ||
92 | +void tran_commit(Transaction *tran); | ||
93 | + | ||
94 | +static inline void tran_finalize(Transaction *tran, int ret) | ||
95 | +{ | ||
96 | + if (ret < 0) { | ||
97 | + tran_abort(tran); | ||
98 | + } else { | ||
99 | + tran_commit(tran); | ||
100 | + } | ||
101 | +} | ||
102 | + | ||
103 | +#endif /* QEMU_TRANSACTIONS_H */ | ||
104 | diff --git a/util/transactions.c b/util/transactions.c | ||
105 | new file mode 100644 | ||
106 | index XXXXXXX..XXXXXXX | ||
107 | --- /dev/null | ||
108 | +++ b/util/transactions.c | ||
109 | @@ -XXX,XX +XXX,XX @@ | ||
110 | +/* | ||
111 | + * Simple transactions API | ||
112 | + * | ||
113 | + * Copyright (c) 2021 Virtuozzo International GmbH. | ||
114 | + * | ||
115 | + * Author: | ||
116 | + * Sementsov-Ogievskiy Vladimir <vsementsov@virtuozzo.com> | ||
117 | + * | ||
118 | + * This program is free software; you can redistribute it and/or modify | ||
119 | + * it under the terms of the GNU General Public License as published by | ||
120 | + * the Free Software Foundation; either version 2 of the License, or | ||
121 | + * (at your option) any later version. | ||
122 | + * | ||
123 | + * This program is distributed in the hope that it will be useful, | ||
124 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
125 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
126 | + * GNU General Public License for more details. | ||
127 | + * | ||
128 | + * You should have received a copy of the GNU General Public License | ||
129 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
130 | + */ | ||
131 | + | ||
132 | +#include "qemu/osdep.h" | ||
133 | + | ||
134 | +#include "qemu/transactions.h" | ||
135 | +#include "qemu/queue.h" | ||
136 | + | ||
137 | +typedef struct TransactionAction { | ||
138 | + TransactionActionDrv *drv; | ||
139 | + void *opaque; | ||
140 | + QSLIST_ENTRY(TransactionAction) entry; | ||
141 | +} TransactionAction; | ||
142 | + | ||
143 | +struct Transaction { | ||
144 | + QSLIST_HEAD(, TransactionAction) actions; | ||
145 | +}; | ||
146 | + | ||
147 | +Transaction *tran_new(void) | ||
148 | +{ | ||
149 | + Transaction *tran = g_new(Transaction, 1); | ||
150 | + | ||
151 | + QSLIST_INIT(&tran->actions); | ||
152 | + | ||
153 | + return tran; | ||
154 | +} | ||
155 | + | ||
156 | +void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque) | ||
157 | +{ | ||
158 | + TransactionAction *act; | ||
159 | + | ||
160 | + act = g_new(TransactionAction, 1); | ||
161 | + *act = (TransactionAction) { | ||
162 | + .drv = drv, | ||
163 | + .opaque = opaque | ||
164 | + }; | ||
165 | + | ||
166 | + QSLIST_INSERT_HEAD(&tran->actions, act, entry); | ||
167 | +} | ||
168 | + | ||
169 | +void tran_abort(Transaction *tran) | ||
170 | +{ | ||
171 | + TransactionAction *act, *next; | ||
172 | + | ||
173 | + QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { | ||
174 | + if (act->drv->abort) { | ||
175 | + act->drv->abort(act->opaque); | ||
176 | + } | ||
177 | + | ||
178 | + if (act->drv->clean) { | ||
179 | + act->drv->clean(act->opaque); | ||
180 | + } | ||
181 | + | ||
182 | + g_free(act); | ||
183 | + } | ||
184 | + | ||
185 | + g_free(tran); | ||
186 | +} | ||
187 | + | ||
188 | +void tran_commit(Transaction *tran) | ||
189 | +{ | ||
190 | + TransactionAction *act, *next; | ||
191 | + | ||
192 | + QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { | ||
193 | + if (act->drv->commit) { | ||
194 | + act->drv->commit(act->opaque); | ||
195 | + } | ||
196 | + | ||
197 | + if (act->drv->clean) { | ||
198 | + act->drv->clean(act->opaque); | ||
199 | + } | ||
200 | + | ||
201 | + g_free(act); | ||
202 | + } | ||
203 | + | ||
204 | + g_free(tran); | ||
205 | +} | ||
206 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
207 | index XXXXXXX..XXXXXXX 100644 | ||
208 | --- a/MAINTAINERS | ||
209 | +++ b/MAINTAINERS | ||
210 | @@ -XXX,XX +XXX,XX @@ M: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
211 | S: Maintained | ||
212 | F: scripts/simplebench/ | ||
213 | |||
214 | +Transactions helper | ||
215 | +M: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
216 | +S: Maintained | ||
217 | +F: include/qemu/transactions.h | ||
218 | +F: util/transactions.c | ||
219 | + | ||
220 | QAPI | ||
221 | M: Markus Armbruster <armbru@redhat.com> | ||
222 | M: Michael Roth <michael.roth@amd.com> | ||
223 | diff --git a/util/meson.build b/util/meson.build | ||
224 | index XXXXXXX..XXXXXXX 100644 | ||
225 | --- a/util/meson.build | ||
226 | +++ b/util/meson.build | ||
227 | @@ -XXX,XX +XXX,XX @@ util_ss.add(files('qsp.c')) | ||
228 | util_ss.add(files('range.c')) | ||
229 | util_ss.add(files('stats64.c')) | ||
230 | util_ss.add(files('systemd.c')) | ||
231 | +util_ss.add(files('transactions.c')) | ||
232 | util_ss.add(when: 'CONFIG_POSIX', if_true: files('drm.c')) | ||
233 | util_ss.add(files('guest-random.c')) | ||
234 | util_ss.add(files('yank.c')) | ||
235 | -- | ||
236 | 2.30.2 | ||
237 | |||
238 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Add additional check that node parents do not interfere with each | ||
4 | other. This should not hurt existing callers and allows in further | ||
5 | patch use bdrv_refresh_perms() to update a subtree of changed | ||
6 | BdrvChild (check that change is correct). | ||
7 | |||
8 | New check will substitute bdrv_check_update_perm() in following | ||
9 | permissions refactoring, so keep error messages the same to avoid | ||
10 | unit test result changes. | ||
11 | |||
12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
13 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
14 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | Message-Id: <20210428151804.439460-10-vsementsov@virtuozzo.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
17 | --- | ||
18 | block.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--------- | ||
19 | 1 file changed, 54 insertions(+), 9 deletions(-) | ||
20 | |||
21 | diff --git a/block.c b/block.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/block.c | ||
24 | +++ b/block.c | ||
25 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_writable(BlockDriverState *bs) | ||
26 | return bdrv_is_writable_after_reopen(bs, NULL); | ||
27 | } | ||
28 | |||
29 | +static char *bdrv_child_user_desc(BdrvChild *c) | ||
30 | +{ | ||
31 | + if (c->klass->get_parent_desc) { | ||
32 | + return c->klass->get_parent_desc(c); | ||
33 | + } | ||
34 | + | ||
35 | + return g_strdup("another user"); | ||
36 | +} | ||
37 | + | ||
38 | +static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp) | ||
39 | +{ | ||
40 | + g_autofree char *user = NULL; | ||
41 | + g_autofree char *perm_names = NULL; | ||
42 | + | ||
43 | + if ((b->perm & a->shared_perm) == b->perm) { | ||
44 | + return true; | ||
45 | + } | ||
46 | + | ||
47 | + perm_names = bdrv_perm_names(b->perm & ~a->shared_perm); | ||
48 | + user = bdrv_child_user_desc(a); | ||
49 | + error_setg(errp, "Conflicts with use by %s as '%s', which does not " | ||
50 | + "allow '%s' on %s", | ||
51 | + user, a->name, perm_names, bdrv_get_node_name(b->bs)); | ||
52 | + | ||
53 | + return false; | ||
54 | +} | ||
55 | + | ||
56 | +static bool bdrv_parent_perms_conflict(BlockDriverState *bs, Error **errp) | ||
57 | +{ | ||
58 | + BdrvChild *a, *b; | ||
59 | + | ||
60 | + /* | ||
61 | + * During the loop we'll look at each pair twice. That's correct because | ||
62 | + * bdrv_a_allow_b() is asymmetric and we should check each pair in both | ||
63 | + * directions. | ||
64 | + */ | ||
65 | + QLIST_FOREACH(a, &bs->parents, next_parent) { | ||
66 | + QLIST_FOREACH(b, &bs->parents, next_parent) { | ||
67 | + if (a == b) { | ||
68 | + continue; | ||
69 | + } | ||
70 | + | ||
71 | + if (!bdrv_a_allow_b(a, b, errp)) { | ||
72 | + return true; | ||
73 | + } | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + return false; | ||
78 | +} | ||
79 | + | ||
80 | static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
81 | BdrvChild *c, BdrvChildRole role, | ||
82 | BlockReopenQueue *reopen_queue, | ||
83 | @@ -XXX,XX +XXX,XX @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, | ||
84 | *shared_perm = cumulative_shared_perms; | ||
85 | } | ||
86 | |||
87 | -static char *bdrv_child_user_desc(BdrvChild *c) | ||
88 | -{ | ||
89 | - if (c->klass->get_parent_desc) { | ||
90 | - return c->klass->get_parent_desc(c); | ||
91 | - } | ||
92 | - | ||
93 | - return g_strdup("another user"); | ||
94 | -} | ||
95 | - | ||
96 | char *bdrv_perm_names(uint64_t perm) | ||
97 | { | ||
98 | struct perm_name { | ||
99 | @@ -XXX,XX +XXX,XX @@ static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) | ||
100 | int ret; | ||
101 | uint64_t perm, shared_perm; | ||
102 | |||
103 | + if (bdrv_parent_perms_conflict(bs, errp)) { | ||
104 | + return -EPERM; | ||
105 | + } | ||
106 | bdrv_get_cumulative_perm(bs, &perm, &shared_perm); | ||
107 | ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, errp); | ||
108 | if (ret < 0) { | ||
109 | -- | ||
110 | 2.30.2 | ||
111 | |||
112 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Split out non-recursive parts, and refactor as block graph transaction | ||
4 | action. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-11-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | block.c | 79 ++++++++++++++++++++++++++++++++++++++++++--------------- | ||
12 | 1 file changed, 59 insertions(+), 20 deletions(-) | ||
13 | |||
14 | diff --git a/block.c b/block.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block.c | ||
17 | +++ b/block.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "qemu/timer.h" | ||
20 | #include "qemu/cutils.h" | ||
21 | #include "qemu/id.h" | ||
22 | +#include "qemu/transactions.h" | ||
23 | #include "block/coroutines.h" | ||
24 | |||
25 | #ifdef CONFIG_BSD | ||
26 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
27 | } | ||
28 | } | ||
29 | |||
30 | +static void bdrv_child_set_perm_commit(void *opaque) | ||
31 | +{ | ||
32 | + BdrvChild *c = opaque; | ||
33 | + | ||
34 | + c->has_backup_perm = false; | ||
35 | +} | ||
36 | + | ||
37 | +static void bdrv_child_set_perm_abort(void *opaque) | ||
38 | +{ | ||
39 | + BdrvChild *c = opaque; | ||
40 | + /* | ||
41 | + * We may have child->has_backup_perm unset at this point, as in case of | ||
42 | + * _check_ stage of permission update failure we may _check_ not the whole | ||
43 | + * subtree. Still, _abort_ is called on the whole subtree anyway. | ||
44 | + */ | ||
45 | + if (c->has_backup_perm) { | ||
46 | + c->perm = c->backup_perm; | ||
47 | + c->shared_perm = c->backup_shared_perm; | ||
48 | + c->has_backup_perm = false; | ||
49 | + } | ||
50 | +} | ||
51 | + | ||
52 | +static TransactionActionDrv bdrv_child_set_pem_drv = { | ||
53 | + .abort = bdrv_child_set_perm_abort, | ||
54 | + .commit = bdrv_child_set_perm_commit, | ||
55 | +}; | ||
56 | + | ||
57 | +/* | ||
58 | + * With tran=NULL needs to be followed by direct call to either | ||
59 | + * bdrv_child_set_perm_commit() or bdrv_child_set_perm_abort(). | ||
60 | + * | ||
61 | + * With non-NULL tran needs to be followed by tran_abort() or tran_commit() | ||
62 | + * instead. | ||
63 | + */ | ||
64 | +static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm, | ||
65 | + uint64_t shared, Transaction *tran) | ||
66 | +{ | ||
67 | + if (!c->has_backup_perm) { | ||
68 | + c->has_backup_perm = true; | ||
69 | + c->backup_perm = c->perm; | ||
70 | + c->backup_shared_perm = c->shared_perm; | ||
71 | + } | ||
72 | + /* | ||
73 | + * Note: it's OK if c->has_backup_perm was already set, as we can find the | ||
74 | + * same c twice during check_perm procedure | ||
75 | + */ | ||
76 | + | ||
77 | + c->perm = perm; | ||
78 | + c->shared_perm = shared; | ||
79 | + | ||
80 | + if (tran) { | ||
81 | + tran_add(tran, &bdrv_child_set_pem_drv, c); | ||
82 | + } | ||
83 | +} | ||
84 | + | ||
85 | /* | ||
86 | * Check whether permissions on this node can be changed in a way that | ||
87 | * @cumulative_perms and @cumulative_shared_perms are the new cumulative | ||
88 | @@ -XXX,XX +XXX,XX @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | - if (!c->has_backup_perm) { | ||
93 | - c->has_backup_perm = true; | ||
94 | - c->backup_perm = c->perm; | ||
95 | - c->backup_shared_perm = c->shared_perm; | ||
96 | - } | ||
97 | - /* | ||
98 | - * Note: it's OK if c->has_backup_perm was already set, as we can find the | ||
99 | - * same child twice during check_perm procedure | ||
100 | - */ | ||
101 | - | ||
102 | - c->perm = perm; | ||
103 | - c->shared_perm = shared; | ||
104 | + bdrv_child_set_perm_safe(c, perm, shared, NULL); | ||
105 | |||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static void bdrv_child_set_perm(BdrvChild *c) | ||
110 | { | ||
111 | - c->has_backup_perm = false; | ||
112 | - | ||
113 | + bdrv_child_set_perm_commit(c); | ||
114 | bdrv_set_perm(c->bs); | ||
115 | } | ||
116 | |||
117 | static void bdrv_child_abort_perm_update(BdrvChild *c) | ||
118 | { | ||
119 | - if (c->has_backup_perm) { | ||
120 | - c->perm = c->backup_perm; | ||
121 | - c->shared_perm = c->backup_shared_perm; | ||
122 | - c->has_backup_perm = false; | ||
123 | - } | ||
124 | - | ||
125 | + bdrv_child_set_perm_abort(c); | ||
126 | bdrv_abort_perm_update(c->bs); | ||
127 | } | ||
128 | |||
129 | -- | ||
130 | 2.30.2 | ||
131 | |||
132 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | We are going to drop recursive bdrv_child_* functions, so stop use them | ||
4 | in bdrv_child_try_set_perm() as a first step. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-12-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | block.c | 14 ++++++++------ | ||
12 | 1 file changed, 8 insertions(+), 6 deletions(-) | ||
13 | |||
14 | diff --git a/block.c b/block.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block.c | ||
17 | +++ b/block.c | ||
18 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
19 | Error **errp) | ||
20 | { | ||
21 | Error *local_err = NULL; | ||
22 | + Transaction *tran = tran_new(); | ||
23 | int ret; | ||
24 | |||
25 | - ret = bdrv_child_check_perm(c, NULL, perm, shared, NULL, &local_err); | ||
26 | + bdrv_child_set_perm_safe(c, perm, shared, tran); | ||
27 | + | ||
28 | + ret = bdrv_refresh_perms(c->bs, &local_err); | ||
29 | + | ||
30 | + tran_finalize(tran, ret); | ||
31 | + | ||
32 | if (ret < 0) { | ||
33 | - bdrv_child_abort_perm_update(c); | ||
34 | if ((perm & ~c->perm) || (c->shared_perm & ~shared)) { | ||
35 | /* tighten permissions */ | ||
36 | error_propagate(errp, local_err); | ||
37 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
38 | error_free(local_err); | ||
39 | ret = 0; | ||
40 | } | ||
41 | - return ret; | ||
42 | } | ||
43 | |||
44 | - bdrv_child_set_perm(c); | ||
45 | - | ||
46 | - return 0; | ||
47 | + return ret; | ||
48 | } | ||
49 | |||
50 | int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
51 | -- | ||
52 | 2.30.2 | ||
53 | |||
54 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Each of them has only one caller. Open-coding simplifies further | ||
4 | pemission-update system changes. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Message-Id: <20210428151804.439460-13-vsementsov@virtuozzo.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | block.c | 59 +++++++++++++++++---------------------------------------- | ||
13 | 1 file changed, 17 insertions(+), 42 deletions(-) | ||
14 | |||
15 | diff --git a/block.c b/block.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block.c | ||
18 | +++ b/block.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int bdrv_fill_options(QDict **options, const char *filename, | ||
20 | return 0; | ||
21 | } | ||
22 | |||
23 | -static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, | ||
24 | - uint64_t perm, uint64_t shared, | ||
25 | - GSList *ignore_children, Error **errp); | ||
26 | -static void bdrv_child_abort_perm_update(BdrvChild *c); | ||
27 | -static void bdrv_child_set_perm(BdrvChild *c); | ||
28 | +static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
29 | + uint64_t new_used_perm, | ||
30 | + uint64_t new_shared_perm, | ||
31 | + GSList *ignore_children, | ||
32 | + Error **errp); | ||
33 | |||
34 | typedef struct BlockReopenQueueEntry { | ||
35 | bool prepared; | ||
36 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
37 | /* Check all children */ | ||
38 | QLIST_FOREACH(c, &bs->children, next) { | ||
39 | uint64_t cur_perm, cur_shared; | ||
40 | + GSList *cur_ignore_children; | ||
41 | |||
42 | bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
43 | cumulative_perms, cumulative_shared_perms, | ||
44 | &cur_perm, &cur_shared); | ||
45 | - ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, | ||
46 | - errp); | ||
47 | + | ||
48 | + cur_ignore_children = g_slist_prepend(g_slist_copy(ignore_children), c); | ||
49 | + ret = bdrv_check_update_perm(c->bs, q, cur_perm, cur_shared, | ||
50 | + cur_ignore_children, errp); | ||
51 | + g_slist_free(cur_ignore_children); | ||
52 | if (ret < 0) { | ||
53 | return ret; | ||
54 | } | ||
55 | + | ||
56 | + bdrv_child_set_perm_safe(c, cur_perm, cur_shared, NULL); | ||
57 | } | ||
58 | |||
59 | return 0; | ||
60 | @@ -XXX,XX +XXX,XX @@ static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
61 | } | ||
62 | |||
63 | QLIST_FOREACH(c, &bs->children, next) { | ||
64 | - bdrv_child_abort_perm_update(c); | ||
65 | + bdrv_child_set_perm_abort(c); | ||
66 | + bdrv_abort_perm_update(c->bs); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | @@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs) | ||
71 | |||
72 | /* Update all children */ | ||
73 | QLIST_FOREACH(c, &bs->children, next) { | ||
74 | - bdrv_child_set_perm(c); | ||
75 | + bdrv_child_set_perm_commit(c); | ||
76 | + bdrv_set_perm(c->bs); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
81 | ignore_children, errp); | ||
82 | } | ||
83 | |||
84 | -/* Needs to be followed by a call to either bdrv_child_set_perm() or | ||
85 | - * bdrv_child_abort_perm_update(). */ | ||
86 | -static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, | ||
87 | - uint64_t perm, uint64_t shared, | ||
88 | - GSList *ignore_children, Error **errp) | ||
89 | -{ | ||
90 | - int ret; | ||
91 | - | ||
92 | - ignore_children = g_slist_prepend(g_slist_copy(ignore_children), c); | ||
93 | - ret = bdrv_check_update_perm(c->bs, q, perm, shared, ignore_children, errp); | ||
94 | - g_slist_free(ignore_children); | ||
95 | - | ||
96 | - if (ret < 0) { | ||
97 | - return ret; | ||
98 | - } | ||
99 | - | ||
100 | - bdrv_child_set_perm_safe(c, perm, shared, NULL); | ||
101 | - | ||
102 | - return 0; | ||
103 | -} | ||
104 | - | ||
105 | -static void bdrv_child_set_perm(BdrvChild *c) | ||
106 | -{ | ||
107 | - bdrv_child_set_perm_commit(c); | ||
108 | - bdrv_set_perm(c->bs); | ||
109 | -} | ||
110 | - | ||
111 | -static void bdrv_child_abort_perm_update(BdrvChild *c) | ||
112 | -{ | ||
113 | - bdrv_child_set_perm_abort(c); | ||
114 | - bdrv_abort_perm_update(c->bs); | ||
115 | -} | ||
116 | - | ||
117 | static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) | ||
118 | { | ||
119 | int ret; | ||
120 | -- | ||
121 | 2.30.2 | ||
122 | |||
123 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | |
2 | |||
3 | Rewrite bdrv_check_perm(), bdrv_abort_perm_update() and bdrv_set_perm() | ||
4 | to update nodes in topological sort order instead of simple DFS. With | ||
5 | topologically sorted nodes, we update a node only when all its parents | ||
6 | already updated. With DFS it's not so. | ||
7 | |||
8 | Consider the following example: | ||
9 | |||
10 | A -+ | ||
11 | | | | ||
12 | | v | ||
13 | | B | ||
14 | | | | ||
15 | v | | ||
16 | C<-+ | ||
17 | |||
18 | A is parent for B and C, B is parent for C. | ||
19 | |||
20 | Obviously, to update permissions, we should go in order A B C, so, when | ||
21 | we update C, all parent permissions already updated. But with current | ||
22 | approach (simple recursion) we can update in sequence A C B C (C is | ||
23 | updated twice). On first update of C, we consider old B permissions, so | ||
24 | doing wrong thing. If it succeed, all is OK, on second C update we will | ||
25 | finish with correct graph. But if the wrong thing failed, we break the | ||
26 | whole process for no reason (it's possible that updated B permission | ||
27 | will be less strict, but we will never check it). | ||
28 | |||
29 | Also new approach gives a way to simultaneously and correctly update | ||
30 | several nodes, we just need to run bdrv_topological_dfs() several times | ||
31 | to add all nodes and their subtrees into one topologically sorted list | ||
32 | (next patch will update bdrv_replace_node() in this manner). | ||
33 | |||
34 | Test test_parallel_perm_update() is now passing, so move it out of | ||
35 | debugging "if". | ||
36 | |||
37 | We also need to support ignore_children in | ||
38 | bdrv_parent_perms_conflict() | ||
39 | |||
40 | For test 283 order of conflicting parents check is changed. | ||
41 | |||
42 | Note also that in bdrv_check_perm() we don't check for parents conflict | ||
43 | at root bs, as we may be in the middle of permission update in | ||
44 | bdrv_reopen_multiple(). bdrv_reopen_multiple() will be updated soon. | ||
45 | |||
46 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
47 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
48 | Message-Id: <20210428151804.439460-14-vsementsov@virtuozzo.com> | ||
49 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
50 | --- | ||
51 | block.c | 116 +++++++++++++++++++++++++------ | ||
52 | tests/unit/test-bdrv-graph-mod.c | 4 +- | ||
53 | tests/qemu-iotests/283.out | 2 +- | ||
54 | 3 files changed, 99 insertions(+), 23 deletions(-) | ||
55 | |||
56 | diff --git a/block.c b/block.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/block.c | ||
59 | +++ b/block.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp) | ||
61 | return false; | ||
62 | } | ||
63 | |||
64 | -static bool bdrv_parent_perms_conflict(BlockDriverState *bs, Error **errp) | ||
65 | +static bool bdrv_parent_perms_conflict(BlockDriverState *bs, | ||
66 | + GSList *ignore_children, | ||
67 | + Error **errp) | ||
68 | { | ||
69 | BdrvChild *a, *b; | ||
70 | |||
71 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_perms_conflict(BlockDriverState *bs, Error **errp) | ||
72 | * directions. | ||
73 | */ | ||
74 | QLIST_FOREACH(a, &bs->parents, next_parent) { | ||
75 | + if (g_slist_find(ignore_children, a)) { | ||
76 | + continue; | ||
77 | + } | ||
78 | + | ||
79 | QLIST_FOREACH(b, &bs->parents, next_parent) { | ||
80 | - if (a == b) { | ||
81 | + if (a == b || g_slist_find(ignore_children, b)) { | ||
82 | continue; | ||
83 | } | ||
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
86 | } | ||
87 | } | ||
88 | |||
89 | +/* | ||
90 | + * Adds the whole subtree of @bs (including @bs itself) to the @list (except for | ||
91 | + * nodes that are already in the @list, of course) so that final list is | ||
92 | + * topologically sorted. Return the result (GSList @list object is updated, so | ||
93 | + * don't use old reference after function call). | ||
94 | + * | ||
95 | + * On function start @list must be already topologically sorted and for any node | ||
96 | + * in the @list the whole subtree of the node must be in the @list as well. The | ||
97 | + * simplest way to satisfy this criteria: use only result of | ||
98 | + * bdrv_topological_dfs() or NULL as @list parameter. | ||
99 | + */ | ||
100 | +static GSList *bdrv_topological_dfs(GSList *list, GHashTable *found, | ||
101 | + BlockDriverState *bs) | ||
102 | +{ | ||
103 | + BdrvChild *child; | ||
104 | + g_autoptr(GHashTable) local_found = NULL; | ||
105 | + | ||
106 | + if (!found) { | ||
107 | + assert(!list); | ||
108 | + found = local_found = g_hash_table_new(NULL, NULL); | ||
109 | + } | ||
110 | + | ||
111 | + if (g_hash_table_contains(found, bs)) { | ||
112 | + return list; | ||
113 | + } | ||
114 | + g_hash_table_add(found, bs); | ||
115 | + | ||
116 | + QLIST_FOREACH(child, &bs->children, next) { | ||
117 | + list = bdrv_topological_dfs(list, found, child->bs); | ||
118 | + } | ||
119 | + | ||
120 | + return g_slist_prepend(list, bs); | ||
121 | +} | ||
122 | + | ||
123 | static void bdrv_child_set_perm_commit(void *opaque) | ||
124 | { | ||
125 | BdrvChild *c = opaque; | ||
126 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm, | ||
127 | * A call to this function must always be followed by a call to bdrv_set_perm() | ||
128 | * or bdrv_abort_perm_update(). | ||
129 | */ | ||
130 | -static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
131 | - uint64_t cumulative_perms, | ||
132 | - uint64_t cumulative_shared_perms, | ||
133 | - GSList *ignore_children, Error **errp) | ||
134 | +static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
135 | + uint64_t cumulative_perms, | ||
136 | + uint64_t cumulative_shared_perms, | ||
137 | + GSList *ignore_children, Error **errp) | ||
138 | { | ||
139 | BlockDriver *drv = bs->drv; | ||
140 | BdrvChild *c; | ||
141 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
142 | /* Check all children */ | ||
143 | QLIST_FOREACH(c, &bs->children, next) { | ||
144 | uint64_t cur_perm, cur_shared; | ||
145 | - GSList *cur_ignore_children; | ||
146 | |||
147 | bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
148 | cumulative_perms, cumulative_shared_perms, | ||
149 | &cur_perm, &cur_shared); | ||
150 | + bdrv_child_set_perm_safe(c, cur_perm, cur_shared, NULL); | ||
151 | + } | ||
152 | + | ||
153 | + return 0; | ||
154 | +} | ||
155 | + | ||
156 | +static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
157 | + uint64_t cumulative_perms, | ||
158 | + uint64_t cumulative_shared_perms, | ||
159 | + GSList *ignore_children, Error **errp) | ||
160 | +{ | ||
161 | + int ret; | ||
162 | + BlockDriverState *root = bs; | ||
163 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, root); | ||
164 | |||
165 | - cur_ignore_children = g_slist_prepend(g_slist_copy(ignore_children), c); | ||
166 | - ret = bdrv_check_update_perm(c->bs, q, cur_perm, cur_shared, | ||
167 | - cur_ignore_children, errp); | ||
168 | - g_slist_free(cur_ignore_children); | ||
169 | + for ( ; list; list = list->next) { | ||
170 | + bs = list->data; | ||
171 | + | ||
172 | + if (bs != root) { | ||
173 | + if (bdrv_parent_perms_conflict(bs, ignore_children, errp)) { | ||
174 | + return -EINVAL; | ||
175 | + } | ||
176 | + | ||
177 | + bdrv_get_cumulative_perm(bs, &cumulative_perms, | ||
178 | + &cumulative_shared_perms); | ||
179 | + } | ||
180 | + | ||
181 | + ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
182 | + cumulative_shared_perms, | ||
183 | + ignore_children, errp); | ||
184 | if (ret < 0) { | ||
185 | return ret; | ||
186 | } | ||
187 | - | ||
188 | - bdrv_child_set_perm_safe(c, cur_perm, cur_shared, NULL); | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
193 | * Notifies drivers that after a previous bdrv_check_perm() call, the | ||
194 | * permission update is not performed and any preparations made for it (e.g. | ||
195 | * taken file locks) need to be undone. | ||
196 | - * | ||
197 | - * This function recursively notifies all child nodes. | ||
198 | */ | ||
199 | -static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
200 | +static void bdrv_node_abort_perm_update(BlockDriverState *bs) | ||
201 | { | ||
202 | BlockDriver *drv = bs->drv; | ||
203 | BdrvChild *c; | ||
204 | @@ -XXX,XX +XXX,XX @@ static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
205 | |||
206 | QLIST_FOREACH(c, &bs->children, next) { | ||
207 | bdrv_child_set_perm_abort(c); | ||
208 | - bdrv_abort_perm_update(c->bs); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | -static void bdrv_set_perm(BlockDriverState *bs) | ||
213 | +static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
214 | +{ | ||
215 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
216 | + | ||
217 | + for ( ; list; list = list->next) { | ||
218 | + bdrv_node_abort_perm_update((BlockDriverState *)list->data); | ||
219 | + } | ||
220 | +} | ||
221 | + | ||
222 | +static void bdrv_node_set_perm(BlockDriverState *bs) | ||
223 | { | ||
224 | uint64_t cumulative_perms, cumulative_shared_perms; | ||
225 | BlockDriver *drv = bs->drv; | ||
226 | @@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs) | ||
227 | /* Update all children */ | ||
228 | QLIST_FOREACH(c, &bs->children, next) { | ||
229 | bdrv_child_set_perm_commit(c); | ||
230 | - bdrv_set_perm(c->bs); | ||
231 | + } | ||
232 | +} | ||
233 | + | ||
234 | +static void bdrv_set_perm(BlockDriverState *bs) | ||
235 | +{ | ||
236 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
237 | + | ||
238 | + for ( ; list; list = list->next) { | ||
239 | + bdrv_node_set_perm((BlockDriverState *)list->data); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | @@ -XXX,XX +XXX,XX @@ static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) | ||
244 | int ret; | ||
245 | uint64_t perm, shared_perm; | ||
246 | |||
247 | - if (bdrv_parent_perms_conflict(bs, errp)) { | ||
248 | + if (bdrv_parent_perms_conflict(bs, NULL, errp)) { | ||
249 | return -EPERM; | ||
250 | } | ||
251 | bdrv_get_cumulative_perm(bs, &perm, &shared_perm); | ||
252 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
253 | index XXXXXXX..XXXXXXX 100644 | ||
254 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
255 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
256 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
257 | g_test_add_func("/bdrv-graph-mod/update-perm-tree", test_update_perm_tree); | ||
258 | g_test_add_func("/bdrv-graph-mod/should-update-child", | ||
259 | test_should_update_child); | ||
260 | + g_test_add_func("/bdrv-graph-mod/parallel-perm-update", | ||
261 | + test_parallel_perm_update); | ||
262 | |||
263 | if (debug) { | ||
264 | g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
265 | test_parallel_exclusive_write); | ||
266 | - g_test_add_func("/bdrv-graph-mod/parallel-perm-update", | ||
267 | - test_parallel_perm_update); | ||
268 | g_test_add_func("/bdrv-graph-mod/append-greedy-filter", | ||
269 | test_append_greedy_filter); | ||
270 | } | ||
271 | diff --git a/tests/qemu-iotests/283.out b/tests/qemu-iotests/283.out | ||
272 | index XXXXXXX..XXXXXXX 100644 | ||
273 | --- a/tests/qemu-iotests/283.out | ||
274 | +++ b/tests/qemu-iotests/283.out | ||
275 | @@ -XXX,XX +XXX,XX @@ | ||
276 | {"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": "base", "node-name": "other", "take-child-perms": ["write"]}} | ||
277 | {"return": {}} | ||
278 | {"execute": "blockdev-backup", "arguments": {"device": "source", "sync": "full", "target": "target"}} | ||
279 | -{"error": {"class": "GenericError", "desc": "Cannot set permissions for backup-top filter: Conflicts with use by other as 'image', which uses 'write' on base"}} | ||
280 | +{"error": {"class": "GenericError", "desc": "Cannot set permissions for backup-top filter: Conflicts with use by source as 'image', which does not allow 'write' on base"}} | ||
281 | |||
282 | === backup-top should be gone after job-finalize === | ||
283 | |||
284 | -- | ||
285 | 2.30.2 | ||
286 | |||
287 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Refactor calling driver callbacks to a separate transaction action to | ||
4 | be used later. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-15-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | block.c | 70 ++++++++++++++++++++++++++++++++++++++++++++------------- | ||
12 | 1 file changed, 54 insertions(+), 16 deletions(-) | ||
13 | |||
14 | diff --git a/block.c b/block.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block.c | ||
17 | +++ b/block.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm, | ||
19 | } | ||
20 | } | ||
21 | |||
22 | +static void bdrv_drv_set_perm_commit(void *opaque) | ||
23 | +{ | ||
24 | + BlockDriverState *bs = opaque; | ||
25 | + uint64_t cumulative_perms, cumulative_shared_perms; | ||
26 | + | ||
27 | + if (bs->drv->bdrv_set_perm) { | ||
28 | + bdrv_get_cumulative_perm(bs, &cumulative_perms, | ||
29 | + &cumulative_shared_perms); | ||
30 | + bs->drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); | ||
31 | + } | ||
32 | +} | ||
33 | + | ||
34 | +static void bdrv_drv_set_perm_abort(void *opaque) | ||
35 | +{ | ||
36 | + BlockDriverState *bs = opaque; | ||
37 | + | ||
38 | + if (bs->drv->bdrv_abort_perm_update) { | ||
39 | + bs->drv->bdrv_abort_perm_update(bs); | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +TransactionActionDrv bdrv_drv_set_perm_drv = { | ||
44 | + .abort = bdrv_drv_set_perm_abort, | ||
45 | + .commit = bdrv_drv_set_perm_commit, | ||
46 | +}; | ||
47 | + | ||
48 | +static int bdrv_drv_set_perm(BlockDriverState *bs, uint64_t perm, | ||
49 | + uint64_t shared_perm, Transaction *tran, | ||
50 | + Error **errp) | ||
51 | +{ | ||
52 | + if (!bs->drv) { | ||
53 | + return 0; | ||
54 | + } | ||
55 | + | ||
56 | + if (bs->drv->bdrv_check_perm) { | ||
57 | + int ret = bs->drv->bdrv_check_perm(bs, perm, shared_perm, errp); | ||
58 | + if (ret < 0) { | ||
59 | + return ret; | ||
60 | + } | ||
61 | + } | ||
62 | + | ||
63 | + if (tran) { | ||
64 | + tran_add(tran, &bdrv_drv_set_perm_drv, bs); | ||
65 | + } | ||
66 | + | ||
67 | + return 0; | ||
68 | +} | ||
69 | + | ||
70 | /* | ||
71 | * Check whether permissions on this node can be changed in a way that | ||
72 | * @cumulative_perms and @cumulative_shared_perms are the new cumulative | ||
73 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | - if (drv->bdrv_check_perm) { | ||
78 | - ret = drv->bdrv_check_perm(bs, cumulative_perms, | ||
79 | - cumulative_shared_perms, errp); | ||
80 | - if (ret < 0) { | ||
81 | - return ret; | ||
82 | - } | ||
83 | + ret = bdrv_drv_set_perm(bs, cumulative_perms, cumulative_shared_perms, NULL, | ||
84 | + errp); | ||
85 | + if (ret < 0) { | ||
86 | + return ret; | ||
87 | } | ||
88 | |||
89 | /* Drivers that never have children can omit .bdrv_child_perm() */ | ||
90 | @@ -XXX,XX +XXX,XX @@ static void bdrv_node_abort_perm_update(BlockDriverState *bs) | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | - if (drv->bdrv_abort_perm_update) { | ||
95 | - drv->bdrv_abort_perm_update(bs); | ||
96 | - } | ||
97 | + bdrv_drv_set_perm_abort(bs); | ||
98 | |||
99 | QLIST_FOREACH(c, &bs->children, next) { | ||
100 | bdrv_child_set_perm_abort(c); | ||
101 | @@ -XXX,XX +XXX,XX @@ static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
102 | |||
103 | static void bdrv_node_set_perm(BlockDriverState *bs) | ||
104 | { | ||
105 | - uint64_t cumulative_perms, cumulative_shared_perms; | ||
106 | BlockDriver *drv = bs->drv; | ||
107 | BdrvChild *c; | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ static void bdrv_node_set_perm(BlockDriverState *bs) | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | - bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms); | ||
114 | - | ||
115 | - /* Update this node */ | ||
116 | - if (drv->bdrv_set_perm) { | ||
117 | - drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); | ||
118 | - } | ||
119 | + bdrv_drv_set_perm_commit(bs); | ||
120 | |||
121 | /* Drivers that never have children can omit .bdrv_child_perm() */ | ||
122 | if (!drv->bdrv_child_perm) { | ||
123 | -- | ||
124 | 2.30.2 | ||
125 | |||
126 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | |
2 | |||
3 | Add new interface, allowing use of existing node list. It will be used | ||
4 | to fix bdrv_replace_node() in the further commit. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-16-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | block.c | 106 +++++++++++++++++++++++++++++++++++++------------------- | ||
12 | 1 file changed, 71 insertions(+), 35 deletions(-) | ||
13 | |||
14 | diff --git a/block.c b/block.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block.c | ||
17 | +++ b/block.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static int bdrv_drv_set_perm(BlockDriverState *bs, uint64_t perm, | ||
19 | static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
20 | uint64_t cumulative_perms, | ||
21 | uint64_t cumulative_shared_perms, | ||
22 | - GSList *ignore_children, Error **errp) | ||
23 | + GSList *ignore_children, | ||
24 | + Transaction *tran, Error **errp) | ||
25 | { | ||
26 | BlockDriver *drv = bs->drv; | ||
27 | BdrvChild *c; | ||
28 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | - ret = bdrv_drv_set_perm(bs, cumulative_perms, cumulative_shared_perms, NULL, | ||
33 | + ret = bdrv_drv_set_perm(bs, cumulative_perms, cumulative_shared_perms, tran, | ||
34 | errp); | ||
35 | if (ret < 0) { | ||
36 | return ret; | ||
37 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
38 | bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
39 | cumulative_perms, cumulative_shared_perms, | ||
40 | &cur_perm, &cur_shared); | ||
41 | - bdrv_child_set_perm_safe(c, cur_perm, cur_shared, NULL); | ||
42 | + bdrv_child_set_perm_safe(c, cur_perm, cur_shared, tran); | ||
43 | } | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | -static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
49 | - uint64_t cumulative_perms, | ||
50 | - uint64_t cumulative_shared_perms, | ||
51 | - GSList *ignore_children, Error **errp) | ||
52 | +/* | ||
53 | + * If use_cumulative_perms is true, use cumulative_perms and | ||
54 | + * cumulative_shared_perms for first element of the list. Otherwise just refresh | ||
55 | + * all permissions. | ||
56 | + */ | ||
57 | +static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
58 | + bool use_cumulative_perms, | ||
59 | + uint64_t cumulative_perms, | ||
60 | + uint64_t cumulative_shared_perms, | ||
61 | + GSList *ignore_children, | ||
62 | + Transaction *tran, Error **errp) | ||
63 | { | ||
64 | int ret; | ||
65 | - BlockDriverState *root = bs; | ||
66 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, root); | ||
67 | + BlockDriverState *bs; | ||
68 | |||
69 | - for ( ; list; list = list->next) { | ||
70 | + if (use_cumulative_perms) { | ||
71 | bs = list->data; | ||
72 | |||
73 | - if (bs != root) { | ||
74 | - if (bdrv_parent_perms_conflict(bs, ignore_children, errp)) { | ||
75 | - return -EINVAL; | ||
76 | - } | ||
77 | + ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
78 | + cumulative_shared_perms, | ||
79 | + ignore_children, tran, errp); | ||
80 | + if (ret < 0) { | ||
81 | + return ret; | ||
82 | + } | ||
83 | |||
84 | - bdrv_get_cumulative_perm(bs, &cumulative_perms, | ||
85 | - &cumulative_shared_perms); | ||
86 | + list = list->next; | ||
87 | + } | ||
88 | + | ||
89 | + for ( ; list; list = list->next) { | ||
90 | + bs = list->data; | ||
91 | + | ||
92 | + if (bdrv_parent_perms_conflict(bs, ignore_children, errp)) { | ||
93 | + return -EINVAL; | ||
94 | } | ||
95 | |||
96 | + bdrv_get_cumulative_perm(bs, &cumulative_perms, | ||
97 | + &cumulative_shared_perms); | ||
98 | + | ||
99 | ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
100 | cumulative_shared_perms, | ||
101 | - ignore_children, errp); | ||
102 | + ignore_children, tran, errp); | ||
103 | if (ret < 0) { | ||
104 | return ret; | ||
105 | } | ||
106 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | +static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
111 | + uint64_t cumulative_perms, | ||
112 | + uint64_t cumulative_shared_perms, | ||
113 | + GSList *ignore_children, Error **errp) | ||
114 | +{ | ||
115 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
116 | + return bdrv_check_perm_common(list, q, true, cumulative_perms, | ||
117 | + cumulative_shared_perms, ignore_children, | ||
118 | + NULL, errp); | ||
119 | +} | ||
120 | + | ||
121 | +static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | ||
122 | + Transaction *tran, Error **errp) | ||
123 | +{ | ||
124 | + return bdrv_check_perm_common(list, q, false, 0, 0, NULL, tran, errp); | ||
125 | +} | ||
126 | + | ||
127 | /* | ||
128 | * Notifies drivers that after a previous bdrv_check_perm() call, the | ||
129 | * permission update is not performed and any preparations made for it (e.g. | ||
130 | @@ -XXX,XX +XXX,XX @@ static void bdrv_node_abort_perm_update(BlockDriverState *bs) | ||
131 | } | ||
132 | } | ||
133 | |||
134 | -static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
135 | +static void bdrv_list_abort_perm_update(GSList *list) | ||
136 | { | ||
137 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
138 | - | ||
139 | for ( ; list; list = list->next) { | ||
140 | bdrv_node_abort_perm_update((BlockDriverState *)list->data); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | +static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
145 | +{ | ||
146 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
147 | + return bdrv_list_abort_perm_update(list); | ||
148 | +} | ||
149 | + | ||
150 | static void bdrv_node_set_perm(BlockDriverState *bs) | ||
151 | { | ||
152 | BlockDriver *drv = bs->drv; | ||
153 | @@ -XXX,XX +XXX,XX @@ static void bdrv_node_set_perm(BlockDriverState *bs) | ||
154 | } | ||
155 | } | ||
156 | |||
157 | -static void bdrv_set_perm(BlockDriverState *bs) | ||
158 | +static void bdrv_list_set_perm(GSList *list) | ||
159 | { | ||
160 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
161 | - | ||
162 | for ( ; list; list = list->next) { | ||
163 | bdrv_node_set_perm((BlockDriverState *)list->data); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | +static void bdrv_set_perm(BlockDriverState *bs) | ||
168 | +{ | ||
169 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
170 | + return bdrv_list_set_perm(list); | ||
171 | +} | ||
172 | + | ||
173 | void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, | ||
174 | uint64_t *shared_perm) | ||
175 | { | ||
176 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
177 | static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) | ||
178 | { | ||
179 | int ret; | ||
180 | - uint64_t perm, shared_perm; | ||
181 | + Transaction *tran = tran_new(); | ||
182 | + g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
183 | |||
184 | - if (bdrv_parent_perms_conflict(bs, NULL, errp)) { | ||
185 | - return -EPERM; | ||
186 | - } | ||
187 | - bdrv_get_cumulative_perm(bs, &perm, &shared_perm); | ||
188 | - ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, errp); | ||
189 | - if (ret < 0) { | ||
190 | - bdrv_abort_perm_update(bs); | ||
191 | - return ret; | ||
192 | - } | ||
193 | - bdrv_set_perm(bs); | ||
194 | + ret = bdrv_list_refresh_perms(list, NULL, tran, errp); | ||
195 | + tran_finalize(tran, ret); | ||
196 | |||
197 | - return 0; | ||
198 | + return ret; | ||
199 | } | ||
200 | |||
201 | int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
202 | -- | ||
203 | 2.30.2 | ||
204 | |||
205 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
---|---|---|---|
2 | |||
3 | To be used in the following commit. | ||
4 | |||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
6 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Message-Id: <20210428151804.439460-17-vsementsov@virtuozzo.com> | ||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | --- | 9 | --- |
3 | tests/qemu-iotests/213 | 349 +++++++++++++++++++++++++++++++++++++++++++++ | 10 | block.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | tests/qemu-iotests/213.out | 121 ++++++++++++++++ | 11 | 1 file changed, 54 insertions(+) |
5 | tests/qemu-iotests/group | 1 + | ||
6 | 3 files changed, 471 insertions(+) | ||
7 | create mode 100755 tests/qemu-iotests/213 | ||
8 | create mode 100644 tests/qemu-iotests/213.out | ||
9 | 12 | ||
10 | diff --git a/tests/qemu-iotests/213 b/tests/qemu-iotests/213 | 13 | diff --git a/block.c b/block.c |
11 | new file mode 100755 | 14 | index XXXXXXX..XXXXXXX 100644 |
12 | index XXXXXXX..XXXXXXX | 15 | --- a/block.c |
13 | --- /dev/null | 16 | +++ b/block.c |
14 | +++ b/tests/qemu-iotests/213 | 17 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, |
15 | @@ -XXX,XX +XXX,XX @@ | 18 | BdrvChildRole child_role, |
16 | +#!/bin/bash | 19 | Error **errp); |
17 | +# | 20 | |
18 | +# Test vhdx and file image creation | 21 | +static void bdrv_replace_child_noperm(BdrvChild *child, |
19 | +# | 22 | + BlockDriverState *new_bs); |
20 | +# Copyright (C) 2018 Red Hat, Inc. | ||
21 | +# | ||
22 | +# This program is free software; you can redistribute it and/or modify | ||
23 | +# it under the terms of the GNU General Public License as published by | ||
24 | +# the Free Software Foundation; either version 2 of the License, or | ||
25 | +# (at your option) any later version. | ||
26 | +# | ||
27 | +# This program is distributed in the hope that it will be useful, | ||
28 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | +# GNU General Public License for more details. | ||
31 | +# | ||
32 | +# You should have received a copy of the GNU General Public License | ||
33 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | +# | ||
35 | + | 23 | + |
36 | +# creator | 24 | static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue |
37 | +owner=kwolf@redhat.com | 25 | *queue, Error **errp); |
26 | static void bdrv_reopen_commit(BDRVReopenState *reopen_state); | ||
27 | @@ -XXX,XX +XXX,XX @@ static int bdrv_drv_set_perm(BlockDriverState *bs, uint64_t perm, | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | +typedef struct BdrvReplaceChildState { | ||
32 | + BdrvChild *child; | ||
33 | + BlockDriverState *old_bs; | ||
34 | +} BdrvReplaceChildState; | ||
38 | + | 35 | + |
39 | +seq=`basename $0` | 36 | +static void bdrv_replace_child_commit(void *opaque) |
40 | +echo "QA output created by $seq" | 37 | +{ |
38 | + BdrvReplaceChildState *s = opaque; | ||
41 | + | 39 | + |
42 | +here=`pwd` | 40 | + bdrv_unref(s->old_bs); |
43 | +status=1 # failure is the default! | ||
44 | + | ||
45 | +# get standard environment, filters and checks | ||
46 | +. ./common.rc | ||
47 | +. ./common.filter | ||
48 | + | ||
49 | +_supported_fmt vhdx | ||
50 | +_supported_proto file | ||
51 | +_supported_os Linux | ||
52 | + | ||
53 | +function do_run_qemu() | ||
54 | +{ | ||
55 | + echo Testing: "$@" | ||
56 | + $QEMU -nographic -qmp stdio -serial none "$@" | ||
57 | + echo | ||
58 | +} | 41 | +} |
59 | + | 42 | + |
60 | +function run_qemu() | 43 | +static void bdrv_replace_child_abort(void *opaque) |
61 | +{ | 44 | +{ |
62 | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ | 45 | + BdrvReplaceChildState *s = opaque; |
63 | + | _filter_qemu | _filter_imgfmt \ | 46 | + BlockDriverState *new_bs = s->child->bs; |
64 | + | _filter_actual_image_size | 47 | + |
48 | + /* old_bs reference is transparently moved from @s to @s->child */ | ||
49 | + bdrv_replace_child_noperm(s->child, s->old_bs); | ||
50 | + bdrv_unref(new_bs); | ||
65 | +} | 51 | +} |
66 | + | 52 | + |
67 | +echo | 53 | +static TransactionActionDrv bdrv_replace_child_drv = { |
68 | +echo "=== Successful image creation (defaults) ===" | 54 | + .commit = bdrv_replace_child_commit, |
69 | +echo | 55 | + .abort = bdrv_replace_child_abort, |
56 | + .clean = g_free, | ||
57 | +}; | ||
70 | + | 58 | + |
71 | +size=$((128 * 1024 * 1024)) | 59 | +/* |
60 | + * bdrv_replace_child_safe | ||
61 | + * | ||
62 | + * Note: real unref of old_bs is done only on commit. | ||
63 | + */ | ||
64 | +__attribute__((unused)) | ||
65 | +static void bdrv_replace_child_safe(BdrvChild *child, BlockDriverState *new_bs, | ||
66 | + Transaction *tran) | ||
67 | +{ | ||
68 | + BdrvReplaceChildState *s = g_new(BdrvReplaceChildState, 1); | ||
69 | + *s = (BdrvReplaceChildState) { | ||
70 | + .child = child, | ||
71 | + .old_bs = child->bs, | ||
72 | + }; | ||
73 | + tran_add(tran, &bdrv_replace_child_drv, s); | ||
72 | + | 74 | + |
73 | +run_qemu <<EOF | 75 | + if (new_bs) { |
74 | +{ "execute": "qmp_capabilities" } | 76 | + bdrv_ref(new_bs); |
75 | +{ "execute": "x-blockdev-create", | 77 | + } |
76 | + "arguments": { | 78 | + bdrv_replace_child_noperm(child, new_bs); |
77 | + "driver": "file", | 79 | + /* old_bs reference is transparently moved from @child to @s */ |
78 | + "filename": "$TEST_IMG", | ||
79 | + "size": 0 | ||
80 | + } | ||
81 | +} | 80 | +} |
82 | +{ "execute": "blockdev-add", | ||
83 | + "arguments": { | ||
84 | + "driver": "file", | ||
85 | + "node-name": "imgfile", | ||
86 | + "filename": "$TEST_IMG" | ||
87 | + } | ||
88 | +} | ||
89 | +{ "execute": "x-blockdev-create", | ||
90 | + "arguments": { | ||
91 | + "driver": "$IMGFMT", | ||
92 | + "file": "imgfile", | ||
93 | + "size": $size | ||
94 | + } | ||
95 | +} | ||
96 | +{ "execute": "quit" } | ||
97 | +EOF | ||
98 | + | 81 | + |
99 | +_img_info --format-specific | _filter_img_info --format-specific | 82 | /* |
100 | + | 83 | * Check whether permissions on this node can be changed in a way that |
101 | +echo | 84 | * @cumulative_perms and @cumulative_shared_perms are the new cumulative |
102 | +echo "=== Successful image creation (explicit defaults) ===" | ||
103 | +echo | ||
104 | + | ||
105 | +# Choose a different size to show that we got a new image | ||
106 | +size=$((64 * 1024 * 1024)) | ||
107 | + | ||
108 | +run_qemu <<EOF | ||
109 | +{ "execute": "qmp_capabilities" } | ||
110 | +{ "execute": "x-blockdev-create", | ||
111 | + "arguments": { | ||
112 | + "driver": "file", | ||
113 | + "filename": "$TEST_IMG", | ||
114 | + "size": 0 | ||
115 | + } | ||
116 | +} | ||
117 | +{ "execute": "x-blockdev-create", | ||
118 | + "arguments": { | ||
119 | + "driver": "$IMGFMT", | ||
120 | + "file": { | ||
121 | + "driver": "file", | ||
122 | + "filename": "$TEST_IMG" | ||
123 | + }, | ||
124 | + "size": $size, | ||
125 | + "log-size": 1048576, | ||
126 | + "block-size": 8388608, | ||
127 | + "subformat": "dynamic", | ||
128 | + "block-state-zero": true | ||
129 | + } | ||
130 | +} | ||
131 | +{ "execute": "quit" } | ||
132 | +EOF | ||
133 | + | ||
134 | +_img_info --format-specific | _filter_img_info --format-specific | ||
135 | + | ||
136 | +echo | ||
137 | +echo "=== Successful image creation (with non-default options) ===" | ||
138 | +echo | ||
139 | + | ||
140 | +# Choose a different size to show that we got a new image | ||
141 | +size=$((32 * 1024 * 1024)) | ||
142 | + | ||
143 | +run_qemu <<EOF | ||
144 | +{ "execute": "qmp_capabilities" } | ||
145 | +{ "execute": "x-blockdev-create", | ||
146 | + "arguments": { | ||
147 | + "driver": "file", | ||
148 | + "filename": "$TEST_IMG", | ||
149 | + "size": 0 | ||
150 | + } | ||
151 | +} | ||
152 | +{ "execute": "x-blockdev-create", | ||
153 | + "arguments": { | ||
154 | + "driver": "$IMGFMT", | ||
155 | + "file": { | ||
156 | + "driver": "file", | ||
157 | + "filename": "$TEST_IMG" | ||
158 | + }, | ||
159 | + "size": $size, | ||
160 | + "log-size": 8388608, | ||
161 | + "block-size": 268435456, | ||
162 | + "subformat": "fixed", | ||
163 | + "block-state-zero": false | ||
164 | + } | ||
165 | +} | ||
166 | +{ "execute": "quit" } | ||
167 | +EOF | ||
168 | + | ||
169 | +_img_info --format-specific | _filter_img_info --format-specific | ||
170 | + | ||
171 | +echo | ||
172 | +echo "=== Invalid BlockdevRef ===" | ||
173 | +echo | ||
174 | + | ||
175 | +run_qemu <<EOF | ||
176 | +{ "execute": "qmp_capabilities" } | ||
177 | +{ "execute": "x-blockdev-create", | ||
178 | + "arguments": { | ||
179 | + "driver": "$IMGFMT", | ||
180 | + "file": "this doesn't exist", | ||
181 | + "size": $size | ||
182 | + } | ||
183 | +} | ||
184 | +{ "execute": "quit" } | ||
185 | +EOF | ||
186 | + | ||
187 | +echo | ||
188 | +echo "=== Zero size ===" | ||
189 | +echo | ||
190 | + | ||
191 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
192 | +{ "execute": "qmp_capabilities" } | ||
193 | +{ "execute": "x-blockdev-create", | ||
194 | + "arguments": { | ||
195 | + "driver": "$IMGFMT", | ||
196 | + "file": "node0", | ||
197 | + "size": 0 | ||
198 | + } | ||
199 | +} | ||
200 | +{ "execute": "quit" } | ||
201 | +EOF | ||
202 | + | ||
203 | +_img_info | _filter_img_info | ||
204 | + | ||
205 | +echo | ||
206 | +echo "=== Maximum size ===" | ||
207 | +echo | ||
208 | + | ||
209 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
210 | +{ "execute": "qmp_capabilities" } | ||
211 | +{ "execute": "x-blockdev-create", | ||
212 | + "arguments": { | ||
213 | + "driver": "$IMGFMT", | ||
214 | + "file": "node0", | ||
215 | + "size": 70368744177664 | ||
216 | + } | ||
217 | +} | ||
218 | +{ "execute": "quit" } | ||
219 | +EOF | ||
220 | + | ||
221 | +_img_info | _filter_img_info | ||
222 | + | ||
223 | +echo | ||
224 | +echo "=== Invalid sizes ===" | ||
225 | +echo | ||
226 | + | ||
227 | +# TODO Negative image sizes aren't handled correctly, but this is a problem | ||
228 | +# with QAPI's implementation of the 'size' type and affects other commands as | ||
229 | +# well. Once this is fixed, we may want to add a test case here. | ||
230 | + | ||
231 | +# 1. 2^64 - 512 | ||
232 | +# 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this) | ||
233 | +# 3. 2^63 - 512 (generally valid, but with the image header the file will | ||
234 | +# exceed 63 bits) | ||
235 | +# 4. 2^46 + 1 (one byte more than maximum image size) | ||
236 | + | ||
237 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
238 | +{ "execute": "qmp_capabilities" } | ||
239 | +{ "execute": "x-blockdev-create", | ||
240 | + "arguments": { | ||
241 | + "driver": "$IMGFMT", | ||
242 | + "file": "node0", | ||
243 | + "size": 18446744073709551104 | ||
244 | + } | ||
245 | +} | ||
246 | +{ "execute": "x-blockdev-create", | ||
247 | + "arguments": { | ||
248 | + "driver": "$IMGFMT", | ||
249 | + "file": "node0", | ||
250 | + "size": 9223372036854775808 | ||
251 | + } | ||
252 | +} | ||
253 | +{ "execute": "x-blockdev-create", | ||
254 | + "arguments": { | ||
255 | + "driver": "$IMGFMT", | ||
256 | + "file": "node0", | ||
257 | + "size": 9223372036854775296 | ||
258 | + } | ||
259 | +} | ||
260 | +{ "execute": "x-blockdev-create", | ||
261 | + "arguments": { | ||
262 | + "driver": "$IMGFMT", | ||
263 | + "file": "node0", | ||
264 | + "size": 70368744177665 | ||
265 | + } | ||
266 | +} | ||
267 | +{ "execute": "quit" } | ||
268 | +EOF | ||
269 | + | ||
270 | +echo | ||
271 | +echo "=== Invalid block size ===" | ||
272 | +echo | ||
273 | + | ||
274 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
275 | +{ "execute": "qmp_capabilities" } | ||
276 | +{ "execute": "x-blockdev-create", | ||
277 | + "arguments": { | ||
278 | + "driver": "$IMGFMT", | ||
279 | + "file": "node0", | ||
280 | + "size": 67108864, | ||
281 | + "block-size": 1234567 | ||
282 | + } | ||
283 | +} | ||
284 | +{ "execute": "x-blockdev-create", | ||
285 | + "arguments": { | ||
286 | + "driver": "$IMGFMT", | ||
287 | + "file": "node0", | ||
288 | + "size": 67108864, | ||
289 | + "block-size": 128 | ||
290 | + } | ||
291 | +} | ||
292 | +{ "execute": "x-blockdev-create", | ||
293 | + "arguments": { | ||
294 | + "driver": "$IMGFMT", | ||
295 | + "file": "node0", | ||
296 | + "size": 67108864, | ||
297 | + "block-size": 3145728 | ||
298 | + } | ||
299 | +} | ||
300 | +{ "execute": "x-blockdev-create", | ||
301 | + "arguments": { | ||
302 | + "driver": "$IMGFMT", | ||
303 | + "file": "node0", | ||
304 | + "size": 67108864, | ||
305 | + "block-size": 536870912 | ||
306 | + } | ||
307 | +} | ||
308 | +{ "execute": "x-blockdev-create", | ||
309 | + "arguments": { | ||
310 | + "driver": "$IMGFMT", | ||
311 | + "file": "node0", | ||
312 | + "size": 67108864, | ||
313 | + "block-size": 0 | ||
314 | + } | ||
315 | +} | ||
316 | +{ "execute": "quit" } | ||
317 | +EOF | ||
318 | + | ||
319 | +echo | ||
320 | +echo "=== Invalid log size ===" | ||
321 | +echo | ||
322 | + | ||
323 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
324 | +{ "execute": "qmp_capabilities" } | ||
325 | +{ "execute": "x-blockdev-create", | ||
326 | + "arguments": { | ||
327 | + "driver": "$IMGFMT", | ||
328 | + "file": "node0", | ||
329 | + "size": 67108864, | ||
330 | + "log-size": 1234567 | ||
331 | + } | ||
332 | +} | ||
333 | +{ "execute": "x-blockdev-create", | ||
334 | + "arguments": { | ||
335 | + "driver": "$IMGFMT", | ||
336 | + "file": "node0", | ||
337 | + "size": 67108864, | ||
338 | + "log-size": 128 | ||
339 | + } | ||
340 | +} | ||
341 | +{ "execute": "x-blockdev-create", | ||
342 | + "arguments": { | ||
343 | + "driver": "$IMGFMT", | ||
344 | + "file": "node0", | ||
345 | + "size": 67108864, | ||
346 | + "log-size": 4294967296 | ||
347 | + } | ||
348 | +} | ||
349 | +{ "execute": "x-blockdev-create", | ||
350 | + "arguments": { | ||
351 | + "driver": "$IMGFMT", | ||
352 | + "file": "node0", | ||
353 | + "size": 67108864, | ||
354 | + "log-size": 0 | ||
355 | + } | ||
356 | +} | ||
357 | +{ "execute": "quit" } | ||
358 | +EOF | ||
359 | + | ||
360 | + | ||
361 | +# success, all done | ||
362 | +echo "*** done" | ||
363 | +rm -f $seq.full | ||
364 | +status=0 | ||
365 | diff --git a/tests/qemu-iotests/213.out b/tests/qemu-iotests/213.out | ||
366 | new file mode 100644 | ||
367 | index XXXXXXX..XXXXXXX | ||
368 | --- /dev/null | ||
369 | +++ b/tests/qemu-iotests/213.out | ||
370 | @@ -XXX,XX +XXX,XX @@ | ||
371 | +QA output created by 213 | ||
372 | + | ||
373 | +=== Successful image creation (defaults) === | ||
374 | + | ||
375 | +Testing: | ||
376 | +QMP_VERSION | ||
377 | +{"return": {}} | ||
378 | +{"return": {}} | ||
379 | +{"return": {}} | ||
380 | +{"return": {}} | ||
381 | +{"return": {}} | ||
382 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
383 | + | ||
384 | +image: TEST_DIR/t.IMGFMT | ||
385 | +file format: IMGFMT | ||
386 | +virtual size: 128M (134217728 bytes) | ||
387 | + | ||
388 | +=== Successful image creation (explicit defaults) === | ||
389 | + | ||
390 | +Testing: | ||
391 | +QMP_VERSION | ||
392 | +{"return": {}} | ||
393 | +{"return": {}} | ||
394 | +{"return": {}} | ||
395 | +{"return": {}} | ||
396 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
397 | + | ||
398 | +image: TEST_DIR/t.IMGFMT | ||
399 | +file format: IMGFMT | ||
400 | +virtual size: 64M (67108864 bytes) | ||
401 | + | ||
402 | +=== Successful image creation (with non-default options) === | ||
403 | + | ||
404 | +Testing: | ||
405 | +QMP_VERSION | ||
406 | +{"return": {}} | ||
407 | +{"return": {}} | ||
408 | +{"return": {}} | ||
409 | +{"return": {}} | ||
410 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
411 | + | ||
412 | +image: TEST_DIR/t.IMGFMT | ||
413 | +file format: IMGFMT | ||
414 | +virtual size: 32M (33554432 bytes) | ||
415 | + | ||
416 | +=== Invalid BlockdevRef === | ||
417 | + | ||
418 | +Testing: | ||
419 | +QMP_VERSION | ||
420 | +{"return": {}} | ||
421 | +{"error": {"class": "GenericError", "desc": "Cannot find device=this doesn't exist nor node_name=this doesn't exist"}} | ||
422 | +{"return": {}} | ||
423 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
424 | + | ||
425 | + | ||
426 | +=== Zero size === | ||
427 | + | ||
428 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
429 | +QMP_VERSION | ||
430 | +{"return": {}} | ||
431 | +{"return": {}} | ||
432 | +{"return": {}} | ||
433 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
434 | + | ||
435 | +image: TEST_DIR/t.IMGFMT | ||
436 | +file format: IMGFMT | ||
437 | +virtual size: 0 (0 bytes) | ||
438 | + | ||
439 | +=== Maximum size === | ||
440 | + | ||
441 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
442 | +QMP_VERSION | ||
443 | +{"return": {}} | ||
444 | +{"return": {}} | ||
445 | +{"return": {}} | ||
446 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
447 | + | ||
448 | +image: TEST_DIR/t.IMGFMT | ||
449 | +file format: IMGFMT | ||
450 | +virtual size: 64T (70368744177664 bytes) | ||
451 | + | ||
452 | +=== Invalid sizes === | ||
453 | + | ||
454 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
455 | +QMP_VERSION | ||
456 | +{"return": {}} | ||
457 | +{"error": {"class": "GenericError", "desc": "Image size too large; max of 64TB"}} | ||
458 | +{"error": {"class": "GenericError", "desc": "Image size too large; max of 64TB"}} | ||
459 | +{"error": {"class": "GenericError", "desc": "Image size too large; max of 64TB"}} | ||
460 | +{"error": {"class": "GenericError", "desc": "Image size too large; max of 64TB"}} | ||
461 | +{"return": {}} | ||
462 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
463 | + | ||
464 | + | ||
465 | +=== Invalid block size === | ||
466 | + | ||
467 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
468 | +QMP_VERSION | ||
469 | +{"return": {}} | ||
470 | +{"error": {"class": "GenericError", "desc": "Block size must be a multiple of 1 MB"}} | ||
471 | +{"error": {"class": "GenericError", "desc": "Block size must be a multiple of 1 MB"}} | ||
472 | +{"error": {"class": "GenericError", "desc": "Block size must be a power of two"}} | ||
473 | +{"error": {"class": "GenericError", "desc": "Block size must not exceed 268435456"}} | ||
474 | +{"error": {"class": "GenericError", "desc": "Block size must be a multiple of 1 MB"}} | ||
475 | +{"return": {}} | ||
476 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
477 | + | ||
478 | + | ||
479 | +=== Invalid log size === | ||
480 | + | ||
481 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
482 | +QMP_VERSION | ||
483 | +{"return": {}} | ||
484 | +{"error": {"class": "GenericError", "desc": "Log size must be a multiple of 1 MB"}} | ||
485 | +{"error": {"class": "GenericError", "desc": "Log size must be a multiple of 1 MB"}} | ||
486 | +{"error": {"class": "GenericError", "desc": "Log size must be smaller than 4 GB"}} | ||
487 | +{"error": {"class": "GenericError", "desc": "Log size must be a multiple of 1 MB"}} | ||
488 | +{"return": {}} | ||
489 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
490 | + | ||
491 | +*** done | ||
492 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
493 | index XXXXXXX..XXXXXXX 100644 | ||
494 | --- a/tests/qemu-iotests/group | ||
495 | +++ b/tests/qemu-iotests/group | ||
496 | @@ -XXX,XX +XXX,XX @@ | ||
497 | 210 rw auto | ||
498 | 211 rw auto quick | ||
499 | 212 rw auto quick | ||
500 | +213 rw auto quick | ||
501 | -- | 85 | -- |
502 | 2.13.6 | 86 | 2.30.2 |
503 | 87 | ||
504 | 88 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | inore_children thing doesn't help to track all propagated permissions | ||
4 | of children we want to ignore. The simplest way to correctly update | ||
5 | permissions is update graph first and then do permission update. In | ||
6 | this case we just referesh permissions for the whole subgraph (in | ||
7 | topological-sort defined order) and everything is correctly calculated | ||
8 | automatically without any ignore_children. | ||
9 | |||
10 | So, refactor bdrv_replace_node_common to first do graph update and then | ||
11 | refresh the permissions. | ||
12 | |||
13 | Test test_parallel_exclusive_write() now pass, so move it out of | ||
14 | debugging "if". | ||
15 | |||
16 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
17 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | Message-Id: <20210428151804.439460-18-vsementsov@virtuozzo.com> | ||
19 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
20 | --- | ||
21 | block.c | 43 +++++++++++++------------------- | ||
22 | tests/unit/test-bdrv-graph-mod.c | 4 +-- | ||
23 | 2 files changed, 20 insertions(+), 27 deletions(-) | ||
24 | |||
25 | diff --git a/block.c b/block.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/block.c | ||
28 | +++ b/block.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static TransactionActionDrv bdrv_replace_child_drv = { | ||
30 | * | ||
31 | * Note: real unref of old_bs is done only on commit. | ||
32 | */ | ||
33 | -__attribute__((unused)) | ||
34 | static void bdrv_replace_child_safe(BdrvChild *child, BlockDriverState *new_bs, | ||
35 | Transaction *tran) | ||
36 | { | ||
37 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
38 | bool auto_skip, Error **errp) | ||
39 | { | ||
40 | BdrvChild *c, *next; | ||
41 | - GSList *list = NULL, *p; | ||
42 | - uint64_t perm = 0, shared = BLK_PERM_ALL; | ||
43 | + Transaction *tran = tran_new(); | ||
44 | + g_autoptr(GHashTable) found = NULL; | ||
45 | + g_autoptr(GSList) refresh_list = NULL; | ||
46 | int ret; | ||
47 | |||
48 | /* Make sure that @from doesn't go away until we have successfully attached | ||
49 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
50 | assert(bdrv_get_aio_context(from) == bdrv_get_aio_context(to)); | ||
51 | bdrv_drained_begin(from); | ||
52 | |||
53 | - /* Put all parents into @list and calculate their cumulative permissions */ | ||
54 | + /* | ||
55 | + * Do the replacement without permission update. | ||
56 | + * Replacement may influence the permissions, we should calculate new | ||
57 | + * permissions based on new graph. If we fail, we'll roll-back the | ||
58 | + * replacement. | ||
59 | + */ | ||
60 | QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { | ||
61 | assert(c->bs == from); | ||
62 | if (!should_update_child(c, to)) { | ||
63 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
64 | c->name, from->node_name); | ||
65 | goto out; | ||
66 | } | ||
67 | - list = g_slist_prepend(list, c); | ||
68 | - perm |= c->perm; | ||
69 | - shared &= c->shared_perm; | ||
70 | + bdrv_replace_child_safe(c, to, tran); | ||
71 | } | ||
72 | |||
73 | - /* Check whether the required permissions can be granted on @to, ignoring | ||
74 | - * all BdrvChild in @list so that they can't block themselves. */ | ||
75 | - ret = bdrv_check_update_perm(to, NULL, perm, shared, list, errp); | ||
76 | - if (ret < 0) { | ||
77 | - bdrv_abort_perm_update(to); | ||
78 | - goto out; | ||
79 | - } | ||
80 | + found = g_hash_table_new(NULL, NULL); | ||
81 | |||
82 | - /* Now actually perform the change. We performed the permission check for | ||
83 | - * all elements of @list at once, so set the permissions all at once at the | ||
84 | - * very end. */ | ||
85 | - for (p = list; p != NULL; p = p->next) { | ||
86 | - c = p->data; | ||
87 | + refresh_list = bdrv_topological_dfs(refresh_list, found, to); | ||
88 | + refresh_list = bdrv_topological_dfs(refresh_list, found, from); | ||
89 | |||
90 | - bdrv_ref(to); | ||
91 | - bdrv_replace_child_noperm(c, to); | ||
92 | - bdrv_unref(from); | ||
93 | + ret = bdrv_list_refresh_perms(refresh_list, NULL, tran, errp); | ||
94 | + if (ret < 0) { | ||
95 | + goto out; | ||
96 | } | ||
97 | |||
98 | - bdrv_set_perm(to); | ||
99 | - | ||
100 | ret = 0; | ||
101 | |||
102 | out: | ||
103 | - g_slist_free(list); | ||
104 | + tran_finalize(tran, ret); | ||
105 | + | ||
106 | bdrv_drained_end(from); | ||
107 | bdrv_unref(from); | ||
108 | |||
109 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
112 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
113 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
114 | test_should_update_child); | ||
115 | g_test_add_func("/bdrv-graph-mod/parallel-perm-update", | ||
116 | test_parallel_perm_update); | ||
117 | + g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
118 | + test_parallel_exclusive_write); | ||
119 | |||
120 | if (debug) { | ||
121 | - g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
122 | - test_parallel_exclusive_write); | ||
123 | g_test_add_func("/bdrv-graph-mod/append-greedy-filter", | ||
124 | test_append_greedy_filter); | ||
125 | } | ||
126 | -- | ||
127 | 2.30.2 | ||
128 | |||
129 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | |
2 | |||
3 | Split out no-perm part of bdrv_root_attach_child() into separate | ||
4 | transaction action. bdrv_root_attach_child() now moves to new | ||
5 | permission update paradigm: first update graph relations then update | ||
6 | permissions. | ||
7 | |||
8 | qsd-jobs test output updated. Seems now permission update goes in | ||
9 | another order. Still, the test comment say that we only want to check | ||
10 | that command doesn't crash, and it's still so. | ||
11 | |||
12 | Error message is a bit misleading as it looks like job was added first. | ||
13 | But actually in new paradigm of graph update we can't distinguish such | ||
14 | things. We should update the error message, but let's not do it now. | ||
15 | |||
16 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
17 | Message-Id: <20210428151804.439460-19-vsementsov@virtuozzo.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | --- | ||
20 | block.c | 190 ++++++++++++++++++-------- | ||
21 | tests/qemu-iotests/tests/qsd-jobs.out | 2 +- | ||
22 | 2 files changed, 137 insertions(+), 55 deletions(-) | ||
23 | |||
24 | diff --git a/block.c b/block.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/block.c | ||
27 | +++ b/block.c | ||
28 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) | ||
29 | } | ||
30 | } | ||
31 | |||
32 | -/* | ||
33 | - * This function steals the reference to child_bs from the caller. | ||
34 | - * That reference is later dropped by bdrv_root_unref_child(). | ||
35 | - * | ||
36 | - * On failure NULL is returned, errp is set and the reference to | ||
37 | - * child_bs is also dropped. | ||
38 | - * | ||
39 | - * The caller must hold the AioContext lock @child_bs, but not that of @ctx | ||
40 | - * (unless @child_bs is already in @ctx). | ||
41 | - */ | ||
42 | -BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
43 | - const char *child_name, | ||
44 | - const BdrvChildClass *child_class, | ||
45 | - BdrvChildRole child_role, | ||
46 | - uint64_t perm, uint64_t shared_perm, | ||
47 | - void *opaque, Error **errp) | ||
48 | +static void bdrv_remove_empty_child(BdrvChild *child) | ||
49 | { | ||
50 | - BdrvChild *child; | ||
51 | - Error *local_err = NULL; | ||
52 | - int ret; | ||
53 | - AioContext *ctx; | ||
54 | + assert(!child->bs); | ||
55 | + QLIST_SAFE_REMOVE(child, next); | ||
56 | + g_free(child->name); | ||
57 | + g_free(child); | ||
58 | +} | ||
59 | |||
60 | - ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp); | ||
61 | - if (ret < 0) { | ||
62 | - bdrv_abort_perm_update(child_bs); | ||
63 | - bdrv_unref(child_bs); | ||
64 | - return NULL; | ||
65 | +typedef struct BdrvAttachChildCommonState { | ||
66 | + BdrvChild **child; | ||
67 | + AioContext *old_parent_ctx; | ||
68 | + AioContext *old_child_ctx; | ||
69 | +} BdrvAttachChildCommonState; | ||
70 | + | ||
71 | +static void bdrv_attach_child_common_abort(void *opaque) | ||
72 | +{ | ||
73 | + BdrvAttachChildCommonState *s = opaque; | ||
74 | + BdrvChild *child = *s->child; | ||
75 | + BlockDriverState *bs = child->bs; | ||
76 | + | ||
77 | + bdrv_replace_child_noperm(child, NULL); | ||
78 | + | ||
79 | + if (bdrv_get_aio_context(bs) != s->old_child_ctx) { | ||
80 | + bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); | ||
81 | } | ||
82 | |||
83 | - child = g_new(BdrvChild, 1); | ||
84 | - *child = (BdrvChild) { | ||
85 | + if (bdrv_child_get_parent_aio_context(child) != s->old_parent_ctx) { | ||
86 | + GSList *ignore = g_slist_prepend(NULL, child); | ||
87 | + | ||
88 | + child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, | ||
89 | + &error_abort); | ||
90 | + g_slist_free(ignore); | ||
91 | + ignore = g_slist_prepend(NULL, child); | ||
92 | + child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); | ||
93 | + | ||
94 | + g_slist_free(ignore); | ||
95 | + } | ||
96 | + | ||
97 | + bdrv_unref(bs); | ||
98 | + bdrv_remove_empty_child(child); | ||
99 | + *s->child = NULL; | ||
100 | +} | ||
101 | + | ||
102 | +static TransactionActionDrv bdrv_attach_child_common_drv = { | ||
103 | + .abort = bdrv_attach_child_common_abort, | ||
104 | + .clean = g_free, | ||
105 | +}; | ||
106 | + | ||
107 | +/* | ||
108 | + * Common part of attaching bdrv child to bs or to blk or to job | ||
109 | + */ | ||
110 | +static int bdrv_attach_child_common(BlockDriverState *child_bs, | ||
111 | + const char *child_name, | ||
112 | + const BdrvChildClass *child_class, | ||
113 | + BdrvChildRole child_role, | ||
114 | + uint64_t perm, uint64_t shared_perm, | ||
115 | + void *opaque, BdrvChild **child, | ||
116 | + Transaction *tran, Error **errp) | ||
117 | +{ | ||
118 | + BdrvChild *new_child; | ||
119 | + AioContext *parent_ctx; | ||
120 | + AioContext *child_ctx = bdrv_get_aio_context(child_bs); | ||
121 | + | ||
122 | + assert(child); | ||
123 | + assert(*child == NULL); | ||
124 | + | ||
125 | + new_child = g_new(BdrvChild, 1); | ||
126 | + *new_child = (BdrvChild) { | ||
127 | .bs = NULL, | ||
128 | .name = g_strdup(child_name), | ||
129 | .klass = child_class, | ||
130 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
131 | .opaque = opaque, | ||
132 | }; | ||
133 | |||
134 | - ctx = bdrv_child_get_parent_aio_context(child); | ||
135 | - | ||
136 | - /* If the AioContexts don't match, first try to move the subtree of | ||
137 | + /* | ||
138 | + * If the AioContexts don't match, first try to move the subtree of | ||
139 | * child_bs into the AioContext of the new parent. If this doesn't work, | ||
140 | - * try moving the parent into the AioContext of child_bs instead. */ | ||
141 | - if (bdrv_get_aio_context(child_bs) != ctx) { | ||
142 | - ret = bdrv_try_set_aio_context(child_bs, ctx, &local_err); | ||
143 | + * try moving the parent into the AioContext of child_bs instead. | ||
144 | + */ | ||
145 | + parent_ctx = bdrv_child_get_parent_aio_context(new_child); | ||
146 | + if (child_ctx != parent_ctx) { | ||
147 | + Error *local_err = NULL; | ||
148 | + int ret = bdrv_try_set_aio_context(child_bs, parent_ctx, &local_err); | ||
149 | + | ||
150 | if (ret < 0 && child_class->can_set_aio_ctx) { | ||
151 | - GSList *ignore = g_slist_prepend(NULL, child); | ||
152 | - ctx = bdrv_get_aio_context(child_bs); | ||
153 | - if (child_class->can_set_aio_ctx(child, ctx, &ignore, NULL)) { | ||
154 | + GSList *ignore = g_slist_prepend(NULL, new_child); | ||
155 | + if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore, | ||
156 | + NULL)) | ||
157 | + { | ||
158 | error_free(local_err); | ||
159 | ret = 0; | ||
160 | g_slist_free(ignore); | ||
161 | - ignore = g_slist_prepend(NULL, child); | ||
162 | - child_class->set_aio_ctx(child, ctx, &ignore); | ||
163 | + ignore = g_slist_prepend(NULL, new_child); | ||
164 | + child_class->set_aio_ctx(new_child, child_ctx, &ignore); | ||
165 | } | ||
166 | g_slist_free(ignore); | ||
167 | } | ||
168 | + | ||
169 | if (ret < 0) { | ||
170 | error_propagate(errp, local_err); | ||
171 | - g_free(child); | ||
172 | - bdrv_abort_perm_update(child_bs); | ||
173 | - bdrv_unref(child_bs); | ||
174 | - return NULL; | ||
175 | + bdrv_remove_empty_child(new_child); | ||
176 | + return ret; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | - /* This performs the matching bdrv_set_perm() for the above check. */ | ||
181 | - bdrv_replace_child(child, child_bs); | ||
182 | + bdrv_ref(child_bs); | ||
183 | + bdrv_replace_child_noperm(new_child, child_bs); | ||
184 | |||
185 | + *child = new_child; | ||
186 | + | ||
187 | + BdrvAttachChildCommonState *s = g_new(BdrvAttachChildCommonState, 1); | ||
188 | + *s = (BdrvAttachChildCommonState) { | ||
189 | + .child = child, | ||
190 | + .old_parent_ctx = parent_ctx, | ||
191 | + .old_child_ctx = child_ctx, | ||
192 | + }; | ||
193 | + tran_add(tran, &bdrv_attach_child_common_drv, s); | ||
194 | + | ||
195 | + return 0; | ||
196 | +} | ||
197 | + | ||
198 | +static void bdrv_detach_child(BdrvChild *child) | ||
199 | +{ | ||
200 | + bdrv_replace_child(child, NULL); | ||
201 | + bdrv_remove_empty_child(child); | ||
202 | +} | ||
203 | + | ||
204 | +/* | ||
205 | + * This function steals the reference to child_bs from the caller. | ||
206 | + * That reference is later dropped by bdrv_root_unref_child(). | ||
207 | + * | ||
208 | + * On failure NULL is returned, errp is set and the reference to | ||
209 | + * child_bs is also dropped. | ||
210 | + * | ||
211 | + * The caller must hold the AioContext lock @child_bs, but not that of @ctx | ||
212 | + * (unless @child_bs is already in @ctx). | ||
213 | + */ | ||
214 | +BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
215 | + const char *child_name, | ||
216 | + const BdrvChildClass *child_class, | ||
217 | + BdrvChildRole child_role, | ||
218 | + uint64_t perm, uint64_t shared_perm, | ||
219 | + void *opaque, Error **errp) | ||
220 | +{ | ||
221 | + int ret; | ||
222 | + BdrvChild *child = NULL; | ||
223 | + Transaction *tran = tran_new(); | ||
224 | + | ||
225 | + ret = bdrv_attach_child_common(child_bs, child_name, child_class, | ||
226 | + child_role, perm, shared_perm, opaque, | ||
227 | + &child, tran, errp); | ||
228 | + if (ret < 0) { | ||
229 | + bdrv_unref(child_bs); | ||
230 | + return NULL; | ||
231 | + } | ||
232 | + | ||
233 | + ret = bdrv_refresh_perms(child_bs, errp); | ||
234 | + tran_finalize(tran, ret); | ||
235 | + | ||
236 | + bdrv_unref(child_bs); | ||
237 | return child; | ||
238 | } | ||
239 | |||
240 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
241 | return child; | ||
242 | } | ||
243 | |||
244 | -static void bdrv_detach_child(BdrvChild *child) | ||
245 | -{ | ||
246 | - QLIST_SAFE_REMOVE(child, next); | ||
247 | - | ||
248 | - bdrv_replace_child(child, NULL); | ||
249 | - | ||
250 | - g_free(child->name); | ||
251 | - g_free(child); | ||
252 | -} | ||
253 | - | ||
254 | /* Callers must ensure that child->frozen is false. */ | ||
255 | void bdrv_root_unref_child(BdrvChild *child) | ||
256 | { | ||
257 | diff --git a/tests/qemu-iotests/tests/qsd-jobs.out b/tests/qemu-iotests/tests/qsd-jobs.out | ||
258 | index XXXXXXX..XXXXXXX 100644 | ||
259 | --- a/tests/qemu-iotests/tests/qsd-jobs.out | ||
260 | +++ b/tests/qemu-iotests/tests/qsd-jobs.out | ||
261 | @@ -XXX,XX +XXX,XX @@ QMP_VERSION | ||
262 | {"return": {}} | ||
263 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} | ||
264 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "job0"}} | ||
265 | -{"error": {"class": "GenericError", "desc": "Conflicts with use by a block device as 'root', which uses 'write' on fmt_base"}} | ||
266 | +{"error": {"class": "GenericError", "desc": "Conflicts with use by stream job 'job0' as 'intermediate node', which does not allow 'write' on fmt_base"}} | ||
267 | {"return": {}} | ||
268 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_EXPORT_DELETED", "data": {"id": "export1"}} | ||
269 | *** done | ||
270 | -- | ||
271 | 2.30.2 | ||
272 | |||
273 | diff view generated by jsdifflib |
1 | From: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | The throttle driver is not a protocol so it should implement bdrv_open | 3 | Split no-perm part of bdrv_attach_child as separate transaction action. |
4 | instead of bdrv_file_open and not provide a protocol_name. | 4 | It will be used in later commits. |
5 | 5 | ||
6 | Attempts to invoke this driver using protocol syntax | 6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
7 | (i.e. throttle:<filename:options:...>) will now fail gracefully: | 7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
8 | 8 | Message-Id: <20210428151804.439460-20-vsementsov@virtuozzo.com> | |
9 | $ qemu-img info throttle:foo | ||
10 | qemu-img: Could not open 'throttle:foo': Unknown protocol 'throttle' | ||
11 | |||
12 | Signed-off-by: Fabiano Rosas <farosas@linux.vnet.ibm.com> | ||
13 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
14 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
16 | --- | 10 | --- |
17 | block/throttle.c | 3 +-- | 11 | block.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++----------- |
18 | 1 file changed, 1 insertion(+), 2 deletions(-) | 12 | 1 file changed, 58 insertions(+), 13 deletions(-) |
19 | 13 | ||
20 | diff --git a/block/throttle.c b/block/throttle.c | 14 | diff --git a/block.c b/block.c |
21 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/block/throttle.c | 16 | --- a/block.c |
23 | +++ b/block/throttle.c | 17 | +++ b/block.c |
24 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs) | 18 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, |
25 | 19 | ||
26 | static BlockDriver bdrv_throttle = { | 20 | static void bdrv_replace_child_noperm(BdrvChild *child, |
27 | .format_name = "throttle", | 21 | BlockDriverState *new_bs); |
28 | - .protocol_name = "throttle", | 22 | +static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, |
29 | .instance_size = sizeof(ThrottleGroupMember), | 23 | + BlockDriverState *child_bs, |
30 | 24 | + const char *child_name, | |
31 | - .bdrv_file_open = throttle_open, | 25 | + const BdrvChildClass *child_class, |
32 | + .bdrv_open = throttle_open, | 26 | + BdrvChildRole child_role, |
33 | .bdrv_close = throttle_close, | 27 | + BdrvChild **child, |
34 | .bdrv_co_flush = throttle_co_flush, | 28 | + Transaction *tran, |
29 | + Error **errp); | ||
30 | |||
31 | static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue | ||
32 | *queue, Error **errp); | ||
33 | @@ -XXX,XX +XXX,XX @@ static int bdrv_attach_child_common(BlockDriverState *child_bs, | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | +static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, | ||
38 | + BlockDriverState *child_bs, | ||
39 | + const char *child_name, | ||
40 | + const BdrvChildClass *child_class, | ||
41 | + BdrvChildRole child_role, | ||
42 | + BdrvChild **child, | ||
43 | + Transaction *tran, | ||
44 | + Error **errp) | ||
45 | +{ | ||
46 | + int ret; | ||
47 | + uint64_t perm, shared_perm; | ||
48 | + | ||
49 | + assert(parent_bs->drv); | ||
50 | + | ||
51 | + bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); | ||
52 | + bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, | ||
53 | + perm, shared_perm, &perm, &shared_perm); | ||
54 | + | ||
55 | + ret = bdrv_attach_child_common(child_bs, child_name, child_class, | ||
56 | + child_role, perm, shared_perm, parent_bs, | ||
57 | + child, tran, errp); | ||
58 | + if (ret < 0) { | ||
59 | + return ret; | ||
60 | + } | ||
61 | + | ||
62 | + QLIST_INSERT_HEAD(&parent_bs->children, *child, next); | ||
63 | + /* | ||
64 | + * child is removed in bdrv_attach_child_common_abort(), so don't care to | ||
65 | + * abort this change separately. | ||
66 | + */ | ||
67 | + | ||
68 | + return 0; | ||
69 | +} | ||
70 | + | ||
71 | static void bdrv_detach_child(BdrvChild *child) | ||
72 | { | ||
73 | bdrv_replace_child(child, NULL); | ||
74 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
75 | BdrvChildRole child_role, | ||
76 | Error **errp) | ||
77 | { | ||
78 | - BdrvChild *child; | ||
79 | - uint64_t perm, shared_perm; | ||
80 | - | ||
81 | - bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); | ||
82 | + int ret; | ||
83 | + BdrvChild *child = NULL; | ||
84 | + Transaction *tran = tran_new(); | ||
85 | |||
86 | - assert(parent_bs->drv); | ||
87 | - bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, | ||
88 | - perm, shared_perm, &perm, &shared_perm); | ||
89 | + ret = bdrv_attach_child_noperm(parent_bs, child_bs, child_name, child_class, | ||
90 | + child_role, &child, tran, errp); | ||
91 | + if (ret < 0) { | ||
92 | + goto out; | ||
93 | + } | ||
94 | |||
95 | - child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
96 | - child_role, perm, shared_perm, parent_bs, | ||
97 | - errp); | ||
98 | - if (child == NULL) { | ||
99 | - return NULL; | ||
100 | + ret = bdrv_refresh_perms(parent_bs, errp); | ||
101 | + if (ret < 0) { | ||
102 | + goto out; | ||
103 | } | ||
104 | |||
105 | - QLIST_INSERT_HEAD(&parent_bs->children, child, next); | ||
106 | +out: | ||
107 | + tran_finalize(tran, ret); | ||
108 | + | ||
109 | + bdrv_unref(child_bs); | ||
110 | + | ||
111 | return child; | ||
112 | } | ||
35 | 113 | ||
36 | -- | 114 | -- |
37 | 2.13.6 | 115 | 2.30.2 |
38 | 116 | ||
39 | 117 | diff view generated by jsdifflib |
1 | It's unclear what the real maximum is, but we use an uint32_t to store | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | the log size in vhdx_co_create(), so we should check that the given | ||
3 | value fits in 32 bits. | ||
4 | 2 | ||
3 | Split part of bdrv_replace_node_common() to be used separately. | ||
4 | |||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
6 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Message-Id: <20210428151804.439460-21-vsementsov@virtuozzo.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
7 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
8 | --- | 9 | --- |
9 | block/vhdx.c | 4 ++++ | 10 | block.c | 50 +++++++++++++++++++++++++++++++------------------- |
10 | 1 file changed, 4 insertions(+) | 11 | 1 file changed, 31 insertions(+), 19 deletions(-) |
11 | 12 | ||
12 | diff --git a/block/vhdx.c b/block/vhdx.c | 13 | diff --git a/block.c b/block.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/block/vhdx.c | 15 | --- a/block.c |
15 | +++ b/block/vhdx.c | 16 | +++ b/block.c |
16 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 17 | @@ -XXX,XX +XXX,XX @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) |
17 | if (!vhdx_opts->has_log_size) { | 18 | return ret; |
18 | log_size = DEFAULT_LOG_SIZE; | 19 | } |
19 | } else { | 20 | |
20 | + if (vhdx_opts->log_size > UINT32_MAX) { | 21 | +static int bdrv_replace_node_noperm(BlockDriverState *from, |
21 | + error_setg(errp, "Log size must be smaller than 4 GB"); | 22 | + BlockDriverState *to, |
23 | + bool auto_skip, Transaction *tran, | ||
24 | + Error **errp) | ||
25 | +{ | ||
26 | + BdrvChild *c, *next; | ||
27 | + | ||
28 | + QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { | ||
29 | + assert(c->bs == from); | ||
30 | + if (!should_update_child(c, to)) { | ||
31 | + if (auto_skip) { | ||
32 | + continue; | ||
33 | + } | ||
34 | + error_setg(errp, "Should not change '%s' link to '%s'", | ||
35 | + c->name, from->node_name); | ||
22 | + return -EINVAL; | 36 | + return -EINVAL; |
23 | + } | 37 | + } |
24 | log_size = vhdx_opts->log_size; | 38 | + if (c->frozen) { |
39 | + error_setg(errp, "Cannot change '%s' link to '%s'", | ||
40 | + c->name, from->node_name); | ||
41 | + return -EPERM; | ||
42 | + } | ||
43 | + bdrv_replace_child_safe(c, to, tran); | ||
44 | + } | ||
45 | + | ||
46 | + return 0; | ||
47 | +} | ||
48 | + | ||
49 | /* | ||
50 | * With auto_skip=true bdrv_replace_node_common skips updating from parents | ||
51 | * if it creates a parent-child relation loop or if parent is block-job. | ||
52 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
53 | BlockDriverState *to, | ||
54 | bool auto_skip, Error **errp) | ||
55 | { | ||
56 | - BdrvChild *c, *next; | ||
57 | Transaction *tran = tran_new(); | ||
58 | g_autoptr(GHashTable) found = NULL; | ||
59 | g_autoptr(GSList) refresh_list = NULL; | ||
60 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
61 | * permissions based on new graph. If we fail, we'll roll-back the | ||
62 | * replacement. | ||
63 | */ | ||
64 | - QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { | ||
65 | - assert(c->bs == from); | ||
66 | - if (!should_update_child(c, to)) { | ||
67 | - if (auto_skip) { | ||
68 | - continue; | ||
69 | - } | ||
70 | - ret = -EINVAL; | ||
71 | - error_setg(errp, "Should not change '%s' link to '%s'", | ||
72 | - c->name, from->node_name); | ||
73 | - goto out; | ||
74 | - } | ||
75 | - if (c->frozen) { | ||
76 | - ret = -EPERM; | ||
77 | - error_setg(errp, "Cannot change '%s' link to '%s'", | ||
78 | - c->name, from->node_name); | ||
79 | - goto out; | ||
80 | - } | ||
81 | - bdrv_replace_child_safe(c, to, tran); | ||
82 | + ret = bdrv_replace_node_noperm(from, to, auto_skip, tran, errp); | ||
83 | + if (ret < 0) { | ||
84 | + goto out; | ||
25 | } | 85 | } |
26 | if (log_size < MiB || (log_size % MiB) != 0) { | 86 | |
87 | found = g_hash_table_new(NULL, NULL); | ||
27 | -- | 88 | -- |
28 | 2.13.6 | 89 | 2.30.2 |
29 | 90 | ||
30 | 91 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | bdrv_append is not very good for inserting filters: it does extra | ||
4 | permission update as part of bdrv_set_backing_hd(). During this update | ||
5 | filter may conflict with other parents of top_bs. | ||
6 | |||
7 | Instead, let's first do all graph modifications and after it update | ||
8 | permissions. | ||
9 | |||
10 | append-greedy-filter test-case in test-bdrv-graph-mod is now works, so | ||
11 | move it out of debug option. | ||
12 | |||
13 | Note: bdrv_append() is still only works for backing-child based | ||
14 | filters. It's something to improve later. | ||
15 | |||
16 | Note2: we use the fact that bdrv_append() is used to append new nodes, | ||
17 | without backing child, so we don't need frozen check and inherits_from | ||
18 | logic from bdrv_set_backing_hd(). | ||
19 | |||
20 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
21 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
22 | Message-Id: <20210428151804.439460-22-vsementsov@virtuozzo.com> | ||
23 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
24 | --- | ||
25 | block.c | 27 ++++++++++++++++++++------- | ||
26 | tests/unit/test-bdrv-graph-mod.c | 17 ++--------------- | ||
27 | 2 files changed, 22 insertions(+), 22 deletions(-) | ||
28 | |||
29 | diff --git a/block.c b/block.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/block.c | ||
32 | +++ b/block.c | ||
33 | @@ -XXX,XX +XXX,XX @@ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
34 | * This will modify the BlockDriverState fields, and swap contents | ||
35 | * between bs_new and bs_top. Both bs_new and bs_top are modified. | ||
36 | * | ||
37 | - * bs_new must not be attached to a BlockBackend. | ||
38 | + * bs_new must not be attached to a BlockBackend and must not have backing | ||
39 | + * child. | ||
40 | * | ||
41 | * This function does not create any image files. | ||
42 | */ | ||
43 | int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, | ||
44 | Error **errp) | ||
45 | { | ||
46 | - int ret = bdrv_set_backing_hd(bs_new, bs_top, errp); | ||
47 | + int ret; | ||
48 | + Transaction *tran = tran_new(); | ||
49 | + | ||
50 | + assert(!bs_new->backing); | ||
51 | + | ||
52 | + ret = bdrv_attach_child_noperm(bs_new, bs_top, "backing", | ||
53 | + &child_of_bds, bdrv_backing_role(bs_new), | ||
54 | + &bs_new->backing, tran, errp); | ||
55 | if (ret < 0) { | ||
56 | - return ret; | ||
57 | + goto out; | ||
58 | } | ||
59 | |||
60 | - ret = bdrv_replace_node(bs_top, bs_new, errp); | ||
61 | + ret = bdrv_replace_node_noperm(bs_top, bs_new, true, tran, errp); | ||
62 | if (ret < 0) { | ||
63 | - bdrv_set_backing_hd(bs_new, NULL, &error_abort); | ||
64 | - return ret; | ||
65 | + goto out; | ||
66 | } | ||
67 | |||
68 | - return 0; | ||
69 | + ret = bdrv_refresh_perms(bs_new, errp); | ||
70 | +out: | ||
71 | + tran_finalize(tran, ret); | ||
72 | + | ||
73 | + bdrv_refresh_limits(bs_top, NULL); | ||
74 | + | ||
75 | + return ret; | ||
76 | } | ||
77 | |||
78 | static void bdrv_delete(BlockDriverState *bs) | ||
79 | diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-mod.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/tests/unit/test-bdrv-graph-mod.c | ||
82 | +++ b/tests/unit/test-bdrv-graph-mod.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static void test_append_greedy_filter(void) | ||
84 | |||
85 | int main(int argc, char *argv[]) | ||
86 | { | ||
87 | - int i; | ||
88 | - bool debug = false; | ||
89 | - | ||
90 | - for (i = 1; i < argc; i++) { | ||
91 | - if (!strcmp(argv[i], "-d")) { | ||
92 | - debug = true; | ||
93 | - break; | ||
94 | - } | ||
95 | - } | ||
96 | - | ||
97 | bdrv_init(); | ||
98 | qemu_init_main_loop(&error_abort); | ||
99 | |||
100 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) | ||
101 | test_parallel_perm_update); | ||
102 | g_test_add_func("/bdrv-graph-mod/parallel-exclusive-write", | ||
103 | test_parallel_exclusive_write); | ||
104 | - | ||
105 | - if (debug) { | ||
106 | - g_test_add_func("/bdrv-graph-mod/append-greedy-filter", | ||
107 | - test_append_greedy_filter); | ||
108 | - } | ||
109 | + g_test_add_func("/bdrv-graph-mod/append-greedy-filter", | ||
110 | + test_append_greedy_filter); | ||
111 | |||
112 | return g_test_run(); | ||
113 | } | ||
114 | -- | ||
115 | 2.30.2 | ||
116 | |||
117 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
---|---|---|---|
2 | |||
3 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
5 | Message-Id: <20210428151804.439460-23-vsementsov@virtuozzo.com> | ||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | --- | 7 | --- |
3 | tests/qemu-iotests/212 | 326 +++++++++++++++++++++++++++++++++++++++++++++ | 8 | block.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
4 | tests/qemu-iotests/212.out | 111 +++++++++++++++ | 9 | 1 file changed, 82 insertions(+), 2 deletions(-) |
5 | tests/qemu-iotests/group | 1 + | ||
6 | 3 files changed, 438 insertions(+) | ||
7 | create mode 100755 tests/qemu-iotests/212 | ||
8 | create mode 100644 tests/qemu-iotests/212.out | ||
9 | 10 | ||
10 | diff --git a/tests/qemu-iotests/212 b/tests/qemu-iotests/212 | 11 | diff --git a/block.c b/block.c |
11 | new file mode 100755 | 12 | index XXXXXXX..XXXXXXX 100644 |
12 | index XXXXXXX..XXXXXXX | 13 | --- a/block.c |
13 | --- /dev/null | 14 | +++ b/block.c |
14 | +++ b/tests/qemu-iotests/212 | 15 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) |
15 | @@ -XXX,XX +XXX,XX @@ | 16 | } |
16 | +#!/bin/bash | 17 | } |
17 | +# | 18 | |
18 | +# Test parallels and file image creation | 19 | +static void bdrv_child_free(void *opaque) |
19 | +# | 20 | +{ |
20 | +# Copyright (C) 2018 Red Hat, Inc. | 21 | + BdrvChild *c = opaque; |
21 | +# | ||
22 | +# This program is free software; you can redistribute it and/or modify | ||
23 | +# it under the terms of the GNU General Public License as published by | ||
24 | +# the Free Software Foundation; either version 2 of the License, or | ||
25 | +# (at your option) any later version. | ||
26 | +# | ||
27 | +# This program is distributed in the hope that it will be useful, | ||
28 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | +# GNU General Public License for more details. | ||
31 | +# | ||
32 | +# You should have received a copy of the GNU General Public License | ||
33 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | +# | ||
35 | + | 22 | + |
36 | +# creator | 23 | + g_free(c->name); |
37 | +owner=kwolf@redhat.com | 24 | + g_free(c); |
38 | + | ||
39 | +seq=`basename $0` | ||
40 | +echo "QA output created by $seq" | ||
41 | + | ||
42 | +here=`pwd` | ||
43 | +status=1 # failure is the default! | ||
44 | + | ||
45 | +# get standard environment, filters and checks | ||
46 | +. ./common.rc | ||
47 | +. ./common.filter | ||
48 | + | ||
49 | +_supported_fmt parallels | ||
50 | +_supported_proto file | ||
51 | +_supported_os Linux | ||
52 | + | ||
53 | +function do_run_qemu() | ||
54 | +{ | ||
55 | + echo Testing: "$@" | ||
56 | + $QEMU -nographic -qmp stdio -serial none "$@" | ||
57 | + echo | ||
58 | +} | 25 | +} |
59 | + | 26 | + |
60 | +function run_qemu() | 27 | static void bdrv_remove_empty_child(BdrvChild *child) |
28 | { | ||
29 | assert(!child->bs); | ||
30 | QLIST_SAFE_REMOVE(child, next); | ||
31 | - g_free(child->name); | ||
32 | - g_free(child); | ||
33 | + bdrv_child_free(child); | ||
34 | } | ||
35 | |||
36 | typedef struct BdrvAttachChildCommonState { | ||
37 | @@ -XXX,XX +XXX,XX @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) | ||
38 | return ret; | ||
39 | } | ||
40 | |||
41 | +typedef struct BdrvRemoveFilterOrCowChild { | ||
42 | + BdrvChild *child; | ||
43 | + bool is_backing; | ||
44 | +} BdrvRemoveFilterOrCowChild; | ||
45 | + | ||
46 | +static void bdrv_remove_filter_or_cow_child_abort(void *opaque) | ||
61 | +{ | 47 | +{ |
62 | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ | 48 | + BdrvRemoveFilterOrCowChild *s = opaque; |
63 | + | _filter_qemu | _filter_imgfmt \ | 49 | + BlockDriverState *parent_bs = s->child->opaque; |
64 | + | _filter_actual_image_size | 50 | + |
51 | + QLIST_INSERT_HEAD(&parent_bs->children, s->child, next); | ||
52 | + if (s->is_backing) { | ||
53 | + parent_bs->backing = s->child; | ||
54 | + } else { | ||
55 | + parent_bs->file = s->child; | ||
56 | + } | ||
57 | + | ||
58 | + /* | ||
59 | + * We don't have to restore child->bs here to undo bdrv_replace_child() | ||
60 | + * because that function is transactionable and it registered own completion | ||
61 | + * entries in @tran, so .abort() for bdrv_replace_child_safe() will be | ||
62 | + * called automatically. | ||
63 | + */ | ||
65 | +} | 64 | +} |
66 | + | 65 | + |
67 | +echo | 66 | +static void bdrv_remove_filter_or_cow_child_commit(void *opaque) |
68 | +echo "=== Successful image creation (defaults) ===" | 67 | +{ |
69 | +echo | 68 | + BdrvRemoveFilterOrCowChild *s = opaque; |
70 | + | 69 | + |
71 | +size=$((128 * 1024 * 1024)) | 70 | + bdrv_child_free(s->child); |
71 | +} | ||
72 | + | 72 | + |
73 | +run_qemu <<EOF | 73 | +static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv = { |
74 | +{ "execute": "qmp_capabilities" } | 74 | + .abort = bdrv_remove_filter_or_cow_child_abort, |
75 | +{ "execute": "x-blockdev-create", | 75 | + .commit = bdrv_remove_filter_or_cow_child_commit, |
76 | + "arguments": { | 76 | + .clean = g_free, |
77 | + "driver": "file", | 77 | +}; |
78 | + "filename": "$TEST_IMG", | 78 | + |
79 | + "size": 0 | 79 | +/* |
80 | + } | 80 | + * A function to remove backing-chain child of @bs if exists: cow child for |
81 | + * format nodes (always .backing) and filter child for filters (may be .file or | ||
82 | + * .backing) | ||
83 | + */ | ||
84 | +__attribute__((unused)) | ||
85 | +static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, | ||
86 | + Transaction *tran) | ||
87 | +{ | ||
88 | + BdrvRemoveFilterOrCowChild *s; | ||
89 | + BdrvChild *child = bdrv_filter_or_cow_child(bs); | ||
90 | + | ||
91 | + if (!child) { | ||
92 | + return; | ||
93 | + } | ||
94 | + | ||
95 | + if (child->bs) { | ||
96 | + bdrv_replace_child_safe(child, NULL, tran); | ||
97 | + } | ||
98 | + | ||
99 | + s = g_new(BdrvRemoveFilterOrCowChild, 1); | ||
100 | + *s = (BdrvRemoveFilterOrCowChild) { | ||
101 | + .child = child, | ||
102 | + .is_backing = (child == bs->backing), | ||
103 | + }; | ||
104 | + tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); | ||
105 | + | ||
106 | + QLIST_SAFE_REMOVE(child, next); | ||
107 | + if (s->is_backing) { | ||
108 | + bs->backing = NULL; | ||
109 | + } else { | ||
110 | + bs->file = NULL; | ||
111 | + } | ||
81 | +} | 112 | +} |
82 | +{ "execute": "blockdev-add", | ||
83 | + "arguments": { | ||
84 | + "driver": "file", | ||
85 | + "node-name": "imgfile", | ||
86 | + "filename": "$TEST_IMG" | ||
87 | + } | ||
88 | +} | ||
89 | +{ "execute": "x-blockdev-create", | ||
90 | + "arguments": { | ||
91 | + "driver": "$IMGFMT", | ||
92 | + "file": "imgfile", | ||
93 | + "size": $size | ||
94 | + } | ||
95 | +} | ||
96 | +{ "execute": "quit" } | ||
97 | +EOF | ||
98 | + | 113 | + |
99 | +_img_info --format-specific | _filter_img_info --format-specific | 114 | static int bdrv_replace_node_noperm(BlockDriverState *from, |
100 | + | 115 | BlockDriverState *to, |
101 | +echo | 116 | bool auto_skip, Transaction *tran, |
102 | +echo "=== Successful image creation (explicit defaults) ===" | ||
103 | +echo | ||
104 | + | ||
105 | +# Choose a different size to show that we got a new image | ||
106 | +size=$((64 * 1024 * 1024)) | ||
107 | + | ||
108 | +run_qemu <<EOF | ||
109 | +{ "execute": "qmp_capabilities" } | ||
110 | +{ "execute": "x-blockdev-create", | ||
111 | + "arguments": { | ||
112 | + "driver": "file", | ||
113 | + "filename": "$TEST_IMG", | ||
114 | + "size": 0 | ||
115 | + } | ||
116 | +} | ||
117 | +{ "execute": "x-blockdev-create", | ||
118 | + "arguments": { | ||
119 | + "driver": "$IMGFMT", | ||
120 | + "file": { | ||
121 | + "driver": "file", | ||
122 | + "filename": "$TEST_IMG" | ||
123 | + }, | ||
124 | + "size": $size, | ||
125 | + "cluster-size": 1048576 | ||
126 | + } | ||
127 | +} | ||
128 | +{ "execute": "quit" } | ||
129 | +EOF | ||
130 | + | ||
131 | +_img_info --format-specific | _filter_img_info --format-specific | ||
132 | + | ||
133 | +echo | ||
134 | +echo "=== Successful image creation (with non-default options) ===" | ||
135 | +echo | ||
136 | + | ||
137 | +# Choose a different size to show that we got a new image | ||
138 | +size=$((32 * 1024 * 1024)) | ||
139 | + | ||
140 | +run_qemu <<EOF | ||
141 | +{ "execute": "qmp_capabilities" } | ||
142 | +{ "execute": "x-blockdev-create", | ||
143 | + "arguments": { | ||
144 | + "driver": "file", | ||
145 | + "filename": "$TEST_IMG", | ||
146 | + "size": 0 | ||
147 | + } | ||
148 | +} | ||
149 | +{ "execute": "x-blockdev-create", | ||
150 | + "arguments": { | ||
151 | + "driver": "$IMGFMT", | ||
152 | + "file": { | ||
153 | + "driver": "file", | ||
154 | + "filename": "$TEST_IMG" | ||
155 | + }, | ||
156 | + "size": $size, | ||
157 | + "cluster-size": 65536 | ||
158 | + } | ||
159 | +} | ||
160 | +{ "execute": "quit" } | ||
161 | +EOF | ||
162 | + | ||
163 | +_img_info --format-specific | _filter_img_info --format-specific | ||
164 | + | ||
165 | +echo | ||
166 | +echo "=== Invalid BlockdevRef ===" | ||
167 | +echo | ||
168 | + | ||
169 | +run_qemu <<EOF | ||
170 | +{ "execute": "qmp_capabilities" } | ||
171 | +{ "execute": "x-blockdev-create", | ||
172 | + "arguments": { | ||
173 | + "driver": "$IMGFMT", | ||
174 | + "file": "this doesn't exist", | ||
175 | + "size": $size | ||
176 | + } | ||
177 | +} | ||
178 | +{ "execute": "quit" } | ||
179 | +EOF | ||
180 | + | ||
181 | +echo | ||
182 | +echo "=== Zero size ===" | ||
183 | +echo | ||
184 | + | ||
185 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
186 | +{ "execute": "qmp_capabilities" } | ||
187 | +{ "execute": "x-blockdev-create", | ||
188 | + "arguments": { | ||
189 | + "driver": "$IMGFMT", | ||
190 | + "file": "node0", | ||
191 | + "size": 0 | ||
192 | + } | ||
193 | +} | ||
194 | +{ "execute": "quit" } | ||
195 | +EOF | ||
196 | + | ||
197 | +_img_info | _filter_img_info | ||
198 | + | ||
199 | +echo | ||
200 | +echo "=== Maximum size ===" | ||
201 | +echo | ||
202 | + | ||
203 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
204 | +{ "execute": "qmp_capabilities" } | ||
205 | +{ "execute": "x-blockdev-create", | ||
206 | + "arguments": { | ||
207 | + "driver": "$IMGFMT", | ||
208 | + "file": "node0", | ||
209 | + "size": 4503599627369984 | ||
210 | + } | ||
211 | +} | ||
212 | +{ "execute": "quit" } | ||
213 | +EOF | ||
214 | + | ||
215 | +_img_info | _filter_img_info | ||
216 | + | ||
217 | +echo | ||
218 | +echo "=== Invalid sizes ===" | ||
219 | +echo | ||
220 | + | ||
221 | +# TODO Negative image sizes aren't handled correctly, but this is a problem | ||
222 | +# with QAPI's implementation of the 'size' type and affects other commands as | ||
223 | +# well. Once this is fixed, we may want to add a test case here. | ||
224 | + | ||
225 | +# 1. Misaligned image size | ||
226 | +# 2. 2^64 - 512 | ||
227 | +# 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this) | ||
228 | +# 4. 2^63 - 512 (generally valid, but with the image header the file will | ||
229 | +# exceed 63 bits) | ||
230 | +# 5. 2^52 (512 bytes more than maximum image size) | ||
231 | + | ||
232 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
233 | +{ "execute": "qmp_capabilities" } | ||
234 | +{ "execute": "x-blockdev-create", | ||
235 | + "arguments": { | ||
236 | + "driver": "$IMGFMT", | ||
237 | + "file": "node0", | ||
238 | + "size": 1234 | ||
239 | + } | ||
240 | +} | ||
241 | +{ "execute": "x-blockdev-create", | ||
242 | + "arguments": { | ||
243 | + "driver": "$IMGFMT", | ||
244 | + "file": "node0", | ||
245 | + "size": 18446744073709551104 | ||
246 | + } | ||
247 | +} | ||
248 | +{ "execute": "x-blockdev-create", | ||
249 | + "arguments": { | ||
250 | + "driver": "$IMGFMT", | ||
251 | + "file": "node0", | ||
252 | + "size": 9223372036854775808 | ||
253 | + } | ||
254 | +} | ||
255 | +{ "execute": "x-blockdev-create", | ||
256 | + "arguments": { | ||
257 | + "driver": "$IMGFMT", | ||
258 | + "file": "node0", | ||
259 | + "size": 9223372036854775296 | ||
260 | + } | ||
261 | +} | ||
262 | +{ "execute": "x-blockdev-create", | ||
263 | + "arguments": { | ||
264 | + "driver": "$IMGFMT", | ||
265 | + "file": "node0", | ||
266 | + "size": 4503599627370497 | ||
267 | + } | ||
268 | +} | ||
269 | +{ "execute": "quit" } | ||
270 | +EOF | ||
271 | + | ||
272 | +echo | ||
273 | +echo "=== Invalid cluster size ===" | ||
274 | +echo | ||
275 | + | ||
276 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
277 | +{ "execute": "qmp_capabilities" } | ||
278 | +{ "execute": "x-blockdev-create", | ||
279 | + "arguments": { | ||
280 | + "driver": "$IMGFMT", | ||
281 | + "file": "node0", | ||
282 | + "size": 67108864, | ||
283 | + "cluster-size": 1234 | ||
284 | + } | ||
285 | +} | ||
286 | +{ "execute": "x-blockdev-create", | ||
287 | + "arguments": { | ||
288 | + "driver": "$IMGFMT", | ||
289 | + "file": "node0", | ||
290 | + "size": 67108864, | ||
291 | + "cluster-size": 128 | ||
292 | + } | ||
293 | +} | ||
294 | +{ "execute": "x-blockdev-create", | ||
295 | + "arguments": { | ||
296 | + "driver": "$IMGFMT", | ||
297 | + "file": "node0", | ||
298 | + "size": 67108864, | ||
299 | + "cluster-size": 4294967296 | ||
300 | + } | ||
301 | +} | ||
302 | +{ "execute": "x-blockdev-create", | ||
303 | + "arguments": { | ||
304 | + "driver": "$IMGFMT", | ||
305 | + "file": "node0", | ||
306 | + "size": 67108864, | ||
307 | + "cluster-size": 9223372036854775808 | ||
308 | + } | ||
309 | +} | ||
310 | +{ "execute": "x-blockdev-create", | ||
311 | + "arguments": { | ||
312 | + "driver": "$IMGFMT", | ||
313 | + "file": "node0", | ||
314 | + "size": 67108864, | ||
315 | + "cluster-size": 18446744073709551104 | ||
316 | + } | ||
317 | +} | ||
318 | +{ "execute": "x-blockdev-create", | ||
319 | + "arguments": { | ||
320 | + "driver": "$IMGFMT", | ||
321 | + "file": "node0", | ||
322 | + "size": 67108864, | ||
323 | + "cluster-size": 0 | ||
324 | + } | ||
325 | +} | ||
326 | +{ "execute": "x-blockdev-create", | ||
327 | + "arguments": { | ||
328 | + "driver": "$IMGFMT", | ||
329 | + "file": "node0", | ||
330 | + "size": 281474976710656, | ||
331 | + "cluster-size": 512 | ||
332 | + } | ||
333 | +} | ||
334 | +{ "execute": "quit" } | ||
335 | +EOF | ||
336 | + | ||
337 | + | ||
338 | +# success, all done | ||
339 | +echo "*** done" | ||
340 | +rm -f $seq.full | ||
341 | +status=0 | ||
342 | diff --git a/tests/qemu-iotests/212.out b/tests/qemu-iotests/212.out | ||
343 | new file mode 100644 | ||
344 | index XXXXXXX..XXXXXXX | ||
345 | --- /dev/null | ||
346 | +++ b/tests/qemu-iotests/212.out | ||
347 | @@ -XXX,XX +XXX,XX @@ | ||
348 | +QA output created by 212 | ||
349 | + | ||
350 | +=== Successful image creation (defaults) === | ||
351 | + | ||
352 | +Testing: | ||
353 | +QMP_VERSION | ||
354 | +{"return": {}} | ||
355 | +{"return": {}} | ||
356 | +{"return": {}} | ||
357 | +{"return": {}} | ||
358 | +{"return": {}} | ||
359 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
360 | + | ||
361 | +image: TEST_DIR/t.IMGFMT | ||
362 | +file format: IMGFMT | ||
363 | +virtual size: 128M (134217728 bytes) | ||
364 | + | ||
365 | +=== Successful image creation (explicit defaults) === | ||
366 | + | ||
367 | +Testing: | ||
368 | +QMP_VERSION | ||
369 | +{"return": {}} | ||
370 | +{"return": {}} | ||
371 | +{"return": {}} | ||
372 | +{"return": {}} | ||
373 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
374 | + | ||
375 | +image: TEST_DIR/t.IMGFMT | ||
376 | +file format: IMGFMT | ||
377 | +virtual size: 64M (67108864 bytes) | ||
378 | + | ||
379 | +=== Successful image creation (with non-default options) === | ||
380 | + | ||
381 | +Testing: | ||
382 | +QMP_VERSION | ||
383 | +{"return": {}} | ||
384 | +{"return": {}} | ||
385 | +{"return": {}} | ||
386 | +{"return": {}} | ||
387 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
388 | + | ||
389 | +image: TEST_DIR/t.IMGFMT | ||
390 | +file format: IMGFMT | ||
391 | +virtual size: 32M (33554432 bytes) | ||
392 | + | ||
393 | +=== Invalid BlockdevRef === | ||
394 | + | ||
395 | +Testing: | ||
396 | +QMP_VERSION | ||
397 | +{"return": {}} | ||
398 | +{"error": {"class": "GenericError", "desc": "Cannot find device=this doesn't exist nor node_name=this doesn't exist"}} | ||
399 | +{"return": {}} | ||
400 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
401 | + | ||
402 | + | ||
403 | +=== Zero size === | ||
404 | + | ||
405 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
406 | +QMP_VERSION | ||
407 | +{"return": {}} | ||
408 | +{"return": {}} | ||
409 | +{"return": {}} | ||
410 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
411 | + | ||
412 | +image: TEST_DIR/t.IMGFMT | ||
413 | +file format: IMGFMT | ||
414 | +virtual size: 0 (0 bytes) | ||
415 | + | ||
416 | +=== Maximum size === | ||
417 | + | ||
418 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
419 | +QMP_VERSION | ||
420 | +{"return": {}} | ||
421 | +{"return": {}} | ||
422 | +{"return": {}} | ||
423 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
424 | + | ||
425 | +image: TEST_DIR/t.IMGFMT | ||
426 | +file format: IMGFMT | ||
427 | +virtual size: 4096T (4503599627369984 bytes) | ||
428 | + | ||
429 | +=== Invalid sizes === | ||
430 | + | ||
431 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
432 | +QMP_VERSION | ||
433 | +{"return": {}} | ||
434 | +{"error": {"class": "GenericError", "desc": "Image size must be a multiple of 512 bytes"}} | ||
435 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
436 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
437 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
438 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
439 | +{"return": {}} | ||
440 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
441 | + | ||
442 | + | ||
443 | +=== Invalid cluster size === | ||
444 | + | ||
445 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
446 | +QMP_VERSION | ||
447 | +{"return": {}} | ||
448 | +{"error": {"class": "GenericError", "desc": "Cluster size must be a multiple of 512 bytes"}} | ||
449 | +{"error": {"class": "GenericError", "desc": "Cluster size must be a multiple of 512 bytes"}} | ||
450 | +{"error": {"class": "GenericError", "desc": "Cluster size is too large"}} | ||
451 | +{"error": {"class": "GenericError", "desc": "Cluster size is too large"}} | ||
452 | +{"error": {"class": "GenericError", "desc": "Cluster size is too large"}} | ||
453 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
454 | +{"error": {"class": "GenericError", "desc": "Image size is too large for this cluster size"}} | ||
455 | +{"return": {}} | ||
456 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
457 | + | ||
458 | +*** done | ||
459 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
460 | index XXXXXXX..XXXXXXX 100644 | ||
461 | --- a/tests/qemu-iotests/group | ||
462 | +++ b/tests/qemu-iotests/group | ||
463 | @@ -XXX,XX +XXX,XX @@ | ||
464 | 209 rw auto quick | ||
465 | 210 rw auto | ||
466 | 211 rw auto quick | ||
467 | +212 rw auto quick | ||
468 | -- | 117 | -- |
469 | 2.13.6 | 118 | 2.30.2 |
470 | 119 | ||
471 | 120 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Using bdrv_replace_node() for removing filter is not good enough: it | ||
4 | keeps child reference of the filter, which may conflict with original | ||
5 | top node during permission update. | ||
6 | |||
7 | Instead let's create new interface, which will do all graph | ||
8 | modifications first and then update permissions. | ||
9 | |||
10 | Let's modify bdrv_replace_node_common(), allowing it additionally drop | ||
11 | backing chain child link pointing to new node. This is quite | ||
12 | appropriate for bdrv_drop_intermediate() and makes possible to add | ||
13 | new bdrv_drop_filter() as a simple wrapper. | ||
14 | |||
15 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
16 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
17 | Message-Id: <20210428151804.439460-24-vsementsov@virtuozzo.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | --- | ||
20 | include/block/block.h | 1 + | ||
21 | block.c | 43 +++++++++++++++++++++++++++++++++++++++---- | ||
22 | 2 files changed, 40 insertions(+), 4 deletions(-) | ||
23 | |||
24 | diff --git a/include/block/block.h b/include/block/block.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/block/block.h | ||
27 | +++ b/include/block/block.h | ||
28 | @@ -XXX,XX +XXX,XX @@ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
29 | Error **errp); | ||
30 | BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_options, | ||
31 | int flags, Error **errp); | ||
32 | +int bdrv_drop_filter(BlockDriverState *bs, Error **errp); | ||
33 | |||
34 | int bdrv_parse_aio(const char *mode, int *flags); | ||
35 | int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough); | ||
36 | diff --git a/block.c b/block.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block.c | ||
39 | +++ b/block.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv = { | ||
41 | * format nodes (always .backing) and filter child for filters (may be .file or | ||
42 | * .backing) | ||
43 | */ | ||
44 | -__attribute__((unused)) | ||
45 | static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, | ||
46 | Transaction *tran) | ||
47 | { | ||
48 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_noperm(BlockDriverState *from, | ||
49 | * | ||
50 | * With auto_skip=false the error is returned if from has a parent which should | ||
51 | * not be updated. | ||
52 | + * | ||
53 | + * With @detach_subchain=true @to must be in a backing chain of @from. In this | ||
54 | + * case backing link of the cow-parent of @to is removed. | ||
55 | */ | ||
56 | static int bdrv_replace_node_common(BlockDriverState *from, | ||
57 | BlockDriverState *to, | ||
58 | - bool auto_skip, Error **errp) | ||
59 | + bool auto_skip, bool detach_subchain, | ||
60 | + Error **errp) | ||
61 | { | ||
62 | Transaction *tran = tran_new(); | ||
63 | g_autoptr(GHashTable) found = NULL; | ||
64 | g_autoptr(GSList) refresh_list = NULL; | ||
65 | + BlockDriverState *to_cow_parent; | ||
66 | int ret; | ||
67 | |||
68 | + if (detach_subchain) { | ||
69 | + assert(bdrv_chain_contains(from, to)); | ||
70 | + assert(from != to); | ||
71 | + for (to_cow_parent = from; | ||
72 | + bdrv_filter_or_cow_bs(to_cow_parent) != to; | ||
73 | + to_cow_parent = bdrv_filter_or_cow_bs(to_cow_parent)) | ||
74 | + { | ||
75 | + ; | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | /* Make sure that @from doesn't go away until we have successfully attached | ||
80 | * all of its parents to @to. */ | ||
81 | bdrv_ref(from); | ||
82 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_common(BlockDriverState *from, | ||
83 | goto out; | ||
84 | } | ||
85 | |||
86 | + if (detach_subchain) { | ||
87 | + bdrv_remove_filter_or_cow_child(to_cow_parent, tran); | ||
88 | + } | ||
89 | + | ||
90 | found = g_hash_table_new(NULL, NULL); | ||
91 | |||
92 | refresh_list = bdrv_topological_dfs(refresh_list, found, to); | ||
93 | @@ -XXX,XX +XXX,XX @@ out: | ||
94 | int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
95 | Error **errp) | ||
96 | { | ||
97 | - return bdrv_replace_node_common(from, to, true, errp); | ||
98 | + return bdrv_replace_node_common(from, to, true, false, errp); | ||
99 | +} | ||
100 | + | ||
101 | +int bdrv_drop_filter(BlockDriverState *bs, Error **errp) | ||
102 | +{ | ||
103 | + return bdrv_replace_node_common(bs, bdrv_filter_or_cow_bs(bs), true, true, | ||
104 | + errp); | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, | ||
109 | updated_children = g_slist_prepend(updated_children, c); | ||
110 | } | ||
111 | |||
112 | - bdrv_replace_node_common(top, base, false, &local_err); | ||
113 | + /* | ||
114 | + * It seems correct to pass detach_subchain=true here, but it triggers | ||
115 | + * one more yet not fixed bug, when due to nested aio_poll loop we switch to | ||
116 | + * another drained section, which modify the graph (for example, removing | ||
117 | + * the child, which we keep in updated_children list). So, it's a TODO. | ||
118 | + * | ||
119 | + * Note, bug triggered if pass detach_subchain=true here and run | ||
120 | + * test-bdrv-drain. test_drop_intermediate_poll() test-case will crash. | ||
121 | + * That's a FIXME. | ||
122 | + */ | ||
123 | + bdrv_replace_node_common(top, base, false, false, &local_err); | ||
124 | if (local_err) { | ||
125 | error_report_err(local_err); | ||
126 | goto exit; | ||
127 | -- | ||
128 | 2.30.2 | ||
129 | |||
130 | diff view generated by jsdifflib |
1 | From: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | The quorum driver is not a protocol so it should implement bdrv_open | 3 | We don't need this workaround anymore: bdrv_append is already smart |
4 | instead of bdrv_file_open and not provide a protocol_name. | 4 | enough and we can use new bdrv_drop_filter(). |
5 | 5 | ||
6 | Attempts to invoke this driver using protocol syntax | 6 | This commit efficiently reverts also recent 705dde27c6c53b73, which |
7 | (i.e. quorum:<filename:options:...>) will now fail gracefully: | 7 | checked .active on io path. Still it said that the problem should be |
8 | theoretical. And the logic of filter removement is changed anyway. | ||
8 | 9 | ||
9 | $ qemu-img info quorum:foo | 10 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
10 | qemu-img: Could not open 'quorum:foo': Unknown protocol 'quorum' | 11 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
11 | 12 | Message-Id: <20210428151804.439460-25-vsementsov@virtuozzo.com> | |
12 | Signed-off-by: Fabiano Rosas <farosas@linux.vnet.ibm.com> | ||
13 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
14 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
16 | --- | 14 | --- |
17 | block/quorum.c | 3 +-- | 15 | block/backup-top.c | 47 +------------------------------------- |
18 | 1 file changed, 1 insertion(+), 2 deletions(-) | 16 | tests/qemu-iotests/283.out | 2 +- |
17 | 2 files changed, 2 insertions(+), 47 deletions(-) | ||
19 | 18 | ||
20 | diff --git a/block/quorum.c b/block/quorum.c | 19 | diff --git a/block/backup-top.c b/block/backup-top.c |
21 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/block/quorum.c | 21 | --- a/block/backup-top.c |
23 | +++ b/block/quorum.c | 22 | +++ b/block/backup-top.c |
24 | @@ -XXX,XX +XXX,XX @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options) | 23 | @@ -XXX,XX +XXX,XX @@ |
25 | 24 | typedef struct BDRVBackupTopState { | |
26 | static BlockDriver bdrv_quorum = { | 25 | BlockCopyState *bcs; |
27 | .format_name = "quorum", | 26 | BdrvChild *target; |
28 | - .protocol_name = "quorum", | 27 | - bool active; |
29 | 28 | int64_t cluster_size; | |
30 | .instance_size = sizeof(BDRVQuorumState), | 29 | } BDRVBackupTopState; |
31 | 30 | ||
32 | - .bdrv_file_open = quorum_open, | 31 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int backup_top_co_preadv( |
33 | + .bdrv_open = quorum_open, | 32 | BlockDriverState *bs, uint64_t offset, uint64_t bytes, |
34 | .bdrv_close = quorum_close, | 33 | QEMUIOVector *qiov, int flags) |
35 | .bdrv_refresh_filename = quorum_refresh_filename, | 34 | { |
35 | - BDRVBackupTopState *s = bs->opaque; | ||
36 | - | ||
37 | - if (!s->active) { | ||
38 | - return -EIO; | ||
39 | - } | ||
40 | - | ||
41 | return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); | ||
42 | } | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int backup_top_cbw(BlockDriverState *bs, uint64_t offset, | ||
45 | BDRVBackupTopState *s = bs->opaque; | ||
46 | uint64_t off, end; | ||
47 | |||
48 | - if (!s->active) { | ||
49 | - return -EIO; | ||
50 | - } | ||
51 | - | ||
52 | if (flags & BDRV_REQ_WRITE_UNCHANGED) { | ||
53 | return 0; | ||
54 | } | ||
55 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
56 | uint64_t perm, uint64_t shared, | ||
57 | uint64_t *nperm, uint64_t *nshared) | ||
58 | { | ||
59 | - BDRVBackupTopState *s = bs->opaque; | ||
60 | - | ||
61 | - if (!s->active) { | ||
62 | - /* | ||
63 | - * The filter node may be in process of bdrv_append(), which firstly do | ||
64 | - * bdrv_set_backing_hd() and then bdrv_replace_node(). This means that | ||
65 | - * we can't unshare BLK_PERM_WRITE during bdrv_append() operation. So, | ||
66 | - * let's require nothing during bdrv_append() and refresh permissions | ||
67 | - * after it (see bdrv_backup_top_append()). | ||
68 | - */ | ||
69 | - *nperm = 0; | ||
70 | - *nshared = BLK_PERM_ALL; | ||
71 | - return; | ||
72 | - } | ||
73 | - | ||
74 | if (!(role & BDRV_CHILD_FILTERED)) { | ||
75 | /* | ||
76 | * Target child | ||
77 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, | ||
78 | } | ||
79 | appended = true; | ||
80 | |||
81 | - /* | ||
82 | - * bdrv_append() finished successfully, now we can require permissions | ||
83 | - * we want. | ||
84 | - */ | ||
85 | - state->active = true; | ||
86 | - ret = bdrv_child_refresh_perms(top, top->backing, errp); | ||
87 | - if (ret < 0) { | ||
88 | - error_prepend(errp, "Cannot set permissions for backup-top filter: "); | ||
89 | - goto fail; | ||
90 | - } | ||
91 | - | ||
92 | state->cluster_size = cluster_size; | ||
93 | state->bcs = block_copy_state_new(top->backing, state->target, | ||
94 | cluster_size, perf->use_copy_range, | ||
95 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, | ||
96 | |||
97 | fail: | ||
98 | if (appended) { | ||
99 | - state->active = false; | ||
100 | bdrv_backup_top_drop(top); | ||
101 | } else { | ||
102 | bdrv_unref(top); | ||
103 | @@ -XXX,XX +XXX,XX @@ void bdrv_backup_top_drop(BlockDriverState *bs) | ||
104 | { | ||
105 | BDRVBackupTopState *s = bs->opaque; | ||
106 | |||
107 | - bdrv_drained_begin(bs); | ||
108 | + bdrv_drop_filter(bs, &error_abort); | ||
109 | |||
110 | block_copy_state_free(s->bcs); | ||
111 | |||
112 | - s->active = false; | ||
113 | - bdrv_child_refresh_perms(bs, bs->backing, &error_abort); | ||
114 | - bdrv_replace_node(bs, bs->backing->bs, &error_abort); | ||
115 | - bdrv_set_backing_hd(bs, NULL, &error_abort); | ||
116 | - | ||
117 | - bdrv_drained_end(bs); | ||
118 | - | ||
119 | bdrv_unref(bs); | ||
120 | } | ||
121 | diff --git a/tests/qemu-iotests/283.out b/tests/qemu-iotests/283.out | ||
122 | index XXXXXXX..XXXXXXX 100644 | ||
123 | --- a/tests/qemu-iotests/283.out | ||
124 | +++ b/tests/qemu-iotests/283.out | ||
125 | @@ -XXX,XX +XXX,XX @@ | ||
126 | {"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": "base", "node-name": "other", "take-child-perms": ["write"]}} | ||
127 | {"return": {}} | ||
128 | {"execute": "blockdev-backup", "arguments": {"device": "source", "sync": "full", "target": "target"}} | ||
129 | -{"error": {"class": "GenericError", "desc": "Cannot set permissions for backup-top filter: Conflicts with use by source as 'image', which does not allow 'write' on base"}} | ||
130 | +{"error": {"class": "GenericError", "desc": "Cannot append backup-top filter: Conflicts with use by source as 'image', which does not allow 'write' on base"}} | ||
131 | |||
132 | === backup-top should be gone after job-finalize === | ||
36 | 133 | ||
37 | -- | 134 | -- |
38 | 2.13.6 | 135 | 2.30.2 |
39 | 136 | ||
40 | 137 | diff view generated by jsdifflib |
1 | Use qemu_uuid_unparse() instead of uuid_unparse() to make vdi.c compile | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | again when CONFIG_VDI_DEBUG is set. In order to prevent future bitrot, | ||
3 | replace '#ifdef CONFIG_VDI_DEBUG' by 'if (VDI_DEBUG)' so that the | ||
4 | compiler always sees the code. | ||
5 | 2 | ||
3 | This argument is always NULL. Drop it. | ||
4 | |||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
6 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Message-Id: <20210428151804.439460-26-vsementsov@virtuozzo.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | --- | 9 | --- |
9 | block/vdi.c | 22 ++++++++++------------ | 10 | block.c | 38 +++++++++++--------------------------- |
10 | 1 file changed, 10 insertions(+), 12 deletions(-) | 11 | 1 file changed, 11 insertions(+), 27 deletions(-) |
11 | 12 | ||
12 | diff --git a/block/vdi.c b/block/vdi.c | 13 | diff --git a/block.c b/block.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/block/vdi.c | 15 | --- a/block.c |
15 | +++ b/block/vdi.c | 16 | +++ b/block.c |
16 | @@ -XXX,XX +XXX,XX @@ static void vdi_header_to_le(VdiHeader *header) | 17 | @@ -XXX,XX +XXX,XX @@ static int bdrv_fill_options(QDict **options, const char *filename, |
17 | qemu_uuid_bswap(&header->uuid_parent); | 18 | static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, |
19 | uint64_t new_used_perm, | ||
20 | uint64_t new_shared_perm, | ||
21 | - GSList *ignore_children, | ||
22 | Error **errp); | ||
23 | |||
24 | typedef struct BlockReopenQueueEntry { | ||
25 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp) | ||
26 | return false; | ||
18 | } | 27 | } |
19 | 28 | ||
20 | -#if defined(CONFIG_VDI_DEBUG) | 29 | -static bool bdrv_parent_perms_conflict(BlockDriverState *bs, |
21 | static void vdi_header_print(VdiHeader *header) | 30 | - GSList *ignore_children, |
31 | - Error **errp) | ||
32 | +static bool bdrv_parent_perms_conflict(BlockDriverState *bs, Error **errp) | ||
22 | { | 33 | { |
23 | char uuid[37]; | 34 | BdrvChild *a, *b; |
24 | @@ -XXX,XX +XXX,XX @@ static void vdi_header_print(VdiHeader *header) | 35 | |
25 | logout("block extra 0x%04x\n", header->block_extra); | 36 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_perms_conflict(BlockDriverState *bs, |
26 | logout("blocks tot. 0x%04x\n", header->blocks_in_image); | 37 | * directions. |
27 | logout("blocks all. 0x%04x\n", header->blocks_allocated); | 38 | */ |
28 | - uuid_unparse(header->uuid_image, uuid); | 39 | QLIST_FOREACH(a, &bs->parents, next_parent) { |
29 | + qemu_uuid_unparse(&header->uuid_image, uuid); | 40 | - if (g_slist_find(ignore_children, a)) { |
30 | logout("uuid image %s\n", uuid); | 41 | - continue; |
31 | - uuid_unparse(header->uuid_last_snap, uuid); | 42 | - } |
32 | + qemu_uuid_unparse(&header->uuid_last_snap, uuid); | 43 | - |
33 | logout("uuid snap %s\n", uuid); | 44 | QLIST_FOREACH(b, &bs->parents, next_parent) { |
34 | - uuid_unparse(header->uuid_link, uuid); | 45 | - if (a == b || g_slist_find(ignore_children, b)) { |
35 | + qemu_uuid_unparse(&header->uuid_link, uuid); | 46 | + if (a == b) { |
36 | logout("uuid link %s\n", uuid); | 47 | continue; |
37 | - uuid_unparse(header->uuid_parent, uuid); | 48 | } |
38 | + qemu_uuid_unparse(&header->uuid_parent, uuid); | 49 | |
39 | logout("uuid parent %s\n", uuid); | 50 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_safe(BdrvChild *child, BlockDriverState *new_bs, |
51 | static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
52 | uint64_t cumulative_perms, | ||
53 | uint64_t cumulative_shared_perms, | ||
54 | - GSList *ignore_children, | ||
55 | Transaction *tran, Error **errp) | ||
56 | { | ||
57 | BlockDriver *drv = bs->drv; | ||
58 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
59 | bool use_cumulative_perms, | ||
60 | uint64_t cumulative_perms, | ||
61 | uint64_t cumulative_shared_perms, | ||
62 | - GSList *ignore_children, | ||
63 | Transaction *tran, Error **errp) | ||
64 | { | ||
65 | int ret; | ||
66 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
67 | |||
68 | ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
69 | cumulative_shared_perms, | ||
70 | - ignore_children, tran, errp); | ||
71 | + tran, errp); | ||
72 | if (ret < 0) { | ||
73 | return ret; | ||
74 | } | ||
75 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
76 | for ( ; list; list = list->next) { | ||
77 | bs = list->data; | ||
78 | |||
79 | - if (bdrv_parent_perms_conflict(bs, ignore_children, errp)) { | ||
80 | + if (bdrv_parent_perms_conflict(bs, errp)) { | ||
81 | return -EINVAL; | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
85 | |||
86 | ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
87 | cumulative_shared_perms, | ||
88 | - ignore_children, tran, errp); | ||
89 | + tran, errp); | ||
90 | if (ret < 0) { | ||
91 | return ret; | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
94 | |||
95 | static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
96 | uint64_t cumulative_perms, | ||
97 | - uint64_t cumulative_shared_perms, | ||
98 | - GSList *ignore_children, Error **errp) | ||
99 | + uint64_t cumulative_shared_perms, Error **errp) | ||
100 | { | ||
101 | g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
102 | return bdrv_check_perm_common(list, q, true, cumulative_perms, | ||
103 | - cumulative_shared_perms, ignore_children, | ||
104 | - NULL, errp); | ||
105 | + cumulative_shared_perms, NULL, errp); | ||
40 | } | 106 | } |
41 | -#endif | 107 | |
42 | 108 | static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | |
43 | static int coroutine_fn vdi_co_check(BlockDriverState *bs, BdrvCheckResult *res, | 109 | Transaction *tran, Error **errp) |
44 | BdrvCheckMode fix) | 110 | { |
45 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | 111 | - return bdrv_check_perm_common(list, q, false, 0, 0, NULL, tran, errp); |
112 | + return bdrv_check_perm_common(list, q, false, 0, 0, tran, errp); | ||
113 | } | ||
114 | |||
115 | /* | ||
116 | @@ -XXX,XX +XXX,XX @@ char *bdrv_perm_names(uint64_t perm) | ||
117 | static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
118 | uint64_t new_used_perm, | ||
119 | uint64_t new_shared_perm, | ||
120 | - GSList *ignore_children, | ||
121 | Error **errp) | ||
122 | { | ||
123 | BdrvChild *c; | ||
124 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
125 | assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); | ||
126 | |||
127 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
128 | - if (g_slist_find(ignore_children, c)) { | ||
129 | - continue; | ||
130 | - } | ||
131 | - | ||
132 | if ((new_used_perm & c->shared_perm) != new_used_perm) { | ||
133 | char *user = bdrv_child_user_desc(c); | ||
134 | char *perm_names = bdrv_perm_names(new_used_perm & ~c->shared_perm); | ||
135 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
46 | } | 136 | } |
47 | 137 | ||
48 | vdi_header_to_cpu(&header); | 138 | return bdrv_check_perm(bs, q, cumulative_perms, cumulative_shared_perms, |
49 | -#if defined(CONFIG_VDI_DEBUG) | 139 | - ignore_children, errp); |
50 | - vdi_header_print(&header); | 140 | + errp); |
51 | -#endif | 141 | } |
52 | + if (VDI_DEBUG) { | 142 | |
53 | + vdi_header_print(&header); | 143 | static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) |
54 | + } | 144 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) |
55 | 145 | QTAILQ_FOREACH(bs_entry, bs_queue, entry) { | |
56 | if (header.disk_size > VDI_DISK_SIZE_MAX) { | 146 | BDRVReopenState *state = &bs_entry->state; |
57 | error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64 | 147 | ret = bdrv_check_perm(state->bs, bs_queue, state->perm, |
58 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | 148 | - state->shared_perm, NULL, errp); |
59 | qemu_uuid_generate(&header.uuid_image); | 149 | + state->shared_perm, errp); |
60 | qemu_uuid_generate(&header.uuid_last_snap); | 150 | if (ret < 0) { |
61 | /* There is no need to set header.uuid_link or header.uuid_parent here. */ | 151 | goto cleanup_perm; |
62 | -#if defined(CONFIG_VDI_DEBUG) | 152 | } |
63 | - vdi_header_print(&header); | 153 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) |
64 | -#endif | 154 | bs_queue, state->perm, state->shared_perm, |
65 | + if (VDI_DEBUG) { | 155 | &nperm, &nshared); |
66 | + vdi_header_print(&header); | 156 | ret = bdrv_check_update_perm(state->new_backing_bs, NULL, |
67 | + } | 157 | - nperm, nshared, NULL, errp); |
68 | vdi_header_to_le(&header); | 158 | + nperm, nshared, errp); |
69 | ret = blk_pwrite(blk, offset, &header, sizeof(header), 0); | 159 | if (ret < 0) { |
70 | if (ret < 0) { | 160 | goto cleanup_perm; |
161 | } | ||
71 | -- | 162 | -- |
72 | 2.13.6 | 163 | 2.30.2 |
73 | 164 | ||
74 | 165 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
---|---|---|---|
2 | |||
3 | To be used in the further commit. | ||
4 | |||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
6 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Message-Id: <20210428151804.439460-27-vsementsov@virtuozzo.com> | ||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
3 | --- | 9 | --- |
4 | tests/qemu-iotests/211 | 246 +++++++++++++++++++++++++++++++++++++++++++++ | 10 | block.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- |
5 | tests/qemu-iotests/211.out | 97 ++++++++++++++++++ | 11 | 1 file changed, 42 insertions(+), 4 deletions(-) |
6 | tests/qemu-iotests/group | 1 + | ||
7 | 3 files changed, 344 insertions(+) | ||
8 | create mode 100755 tests/qemu-iotests/211 | ||
9 | create mode 100644 tests/qemu-iotests/211.out | ||
10 | 12 | ||
11 | diff --git a/tests/qemu-iotests/211 b/tests/qemu-iotests/211 | 13 | diff --git a/block.c b/block.c |
12 | new file mode 100755 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | index XXXXXXX..XXXXXXX | 15 | --- a/block.c |
14 | --- /dev/null | 16 | +++ b/block.c |
15 | +++ b/tests/qemu-iotests/211 | 17 | @@ -XXX,XX +XXX,XX @@ void bdrv_root_unref_child(BdrvChild *child) |
16 | @@ -XXX,XX +XXX,XX @@ | 18 | bdrv_unref(child_bs); |
17 | +#!/bin/bash | 19 | } |
18 | +# | 20 | |
19 | +# Test VDI and file image creation | 21 | +typedef struct BdrvSetInheritsFrom { |
20 | +# | 22 | + BlockDriverState *bs; |
21 | +# Copyright (C) 2018 Red Hat, Inc. | 23 | + BlockDriverState *old_inherits_from; |
22 | +# | 24 | +} BdrvSetInheritsFrom; |
23 | +# This program is free software; you can redistribute it and/or modify | ||
24 | +# it under the terms of the GNU General Public License as published by | ||
25 | +# the Free Software Foundation; either version 2 of the License, or | ||
26 | +# (at your option) any later version. | ||
27 | +# | ||
28 | +# This program is distributed in the hope that it will be useful, | ||
29 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
30 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
31 | +# GNU General Public License for more details. | ||
32 | +# | ||
33 | +# You should have received a copy of the GNU General Public License | ||
34 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
35 | +# | ||
36 | + | 25 | + |
37 | +# creator | 26 | +static void bdrv_set_inherits_from_abort(void *opaque) |
38 | +owner=kwolf@redhat.com | 27 | +{ |
28 | + BdrvSetInheritsFrom *s = opaque; | ||
39 | + | 29 | + |
40 | +seq=`basename $0` | 30 | + s->bs->inherits_from = s->old_inherits_from; |
41 | +echo "QA output created by $seq" | ||
42 | + | ||
43 | +here=`pwd` | ||
44 | +status=1 # failure is the default! | ||
45 | + | ||
46 | +# get standard environment, filters and checks | ||
47 | +. ./common.rc | ||
48 | +. ./common.filter | ||
49 | + | ||
50 | +_supported_fmt vdi | ||
51 | +_supported_proto file | ||
52 | +_supported_os Linux | ||
53 | + | ||
54 | +function do_run_qemu() | ||
55 | +{ | ||
56 | + echo Testing: "$@" | ||
57 | + $QEMU -nographic -qmp stdio -serial none "$@" | ||
58 | + echo | ||
59 | +} | 31 | +} |
60 | + | 32 | + |
61 | +function run_qemu() | 33 | +static TransactionActionDrv bdrv_set_inherits_from_drv = { |
34 | + .abort = bdrv_set_inherits_from_abort, | ||
35 | + .clean = g_free, | ||
36 | +}; | ||
37 | + | ||
38 | +/* @tran is allowed to be NULL. In this case no rollback is possible */ | ||
39 | +static void bdrv_set_inherits_from(BlockDriverState *bs, | ||
40 | + BlockDriverState *new_inherits_from, | ||
41 | + Transaction *tran) | ||
62 | +{ | 42 | +{ |
63 | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ | 43 | + if (tran) { |
64 | + | _filter_qemu | _filter_imgfmt \ | 44 | + BdrvSetInheritsFrom *s = g_new(BdrvSetInheritsFrom, 1); |
65 | + | _filter_actual_image_size | 45 | + |
46 | + *s = (BdrvSetInheritsFrom) { | ||
47 | + .bs = bs, | ||
48 | + .old_inherits_from = bs->inherits_from, | ||
49 | + }; | ||
50 | + | ||
51 | + tran_add(tran, &bdrv_set_inherits_from_drv, s); | ||
52 | + } | ||
53 | + | ||
54 | + bs->inherits_from = new_inherits_from; | ||
66 | +} | 55 | +} |
67 | + | 56 | + |
68 | +echo | 57 | /** |
69 | +echo "=== Successful image creation (defaults) ===" | 58 | * Clear all inherits_from pointers from children and grandchildren of |
70 | +echo | 59 | * @root that point to @root, where necessary. |
71 | + | 60 | + * @tran is allowed to be NULL. In this case no rollback is possible |
72 | +size=$((128 * 1024 * 1024)) | 61 | */ |
73 | + | 62 | -static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child) |
74 | +run_qemu <<EOF | 63 | +static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child, |
75 | +{ "execute": "qmp_capabilities" } | 64 | + Transaction *tran) |
76 | +{ "execute": "x-blockdev-create", | 65 | { |
77 | + "arguments": { | 66 | BdrvChild *c; |
78 | + "driver": "file", | 67 | |
79 | + "filename": "$TEST_IMG", | 68 | @@ -XXX,XX +XXX,XX @@ static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child) |
80 | + "size": 0 | 69 | } |
81 | + } | 70 | } |
82 | +} | 71 | if (c == NULL) { |
83 | +{ "execute": "blockdev-add", | 72 | - child->bs->inherits_from = NULL; |
84 | + "arguments": { | 73 | + bdrv_set_inherits_from(child->bs, NULL, tran); |
85 | + "driver": "file", | 74 | } |
86 | + "node-name": "imgfile", | 75 | } |
87 | + "filename": "$TEST_IMG" | 76 | |
88 | + } | 77 | QLIST_FOREACH(c, &child->bs->children, next) { |
89 | +} | 78 | - bdrv_unset_inherits_from(root, c); |
90 | +{ "execute": "x-blockdev-create", | 79 | + bdrv_unset_inherits_from(root, c, tran); |
91 | + "arguments": { | 80 | } |
92 | + "driver": "$IMGFMT", | 81 | } |
93 | + "file": "imgfile", | 82 | |
94 | + "size": $size | 83 | @@ -XXX,XX +XXX,XX @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) |
95 | + } | 84 | return; |
96 | +} | 85 | } |
97 | +{ "execute": "quit" } | 86 | |
98 | +EOF | 87 | - bdrv_unset_inherits_from(parent, child); |
99 | + | 88 | + bdrv_unset_inherits_from(parent, child, NULL); |
100 | +_img_info --format-specific | _filter_img_info --format-specific | 89 | bdrv_root_unref_child(child); |
101 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | 90 | } |
102 | + | 91 | |
103 | +echo | ||
104 | +echo "=== Successful image creation (explicit defaults) ===" | ||
105 | +echo | ||
106 | + | ||
107 | +# Choose a different size to show that we got a new image | ||
108 | +size=$((64 * 1024 * 1024)) | ||
109 | + | ||
110 | +run_qemu <<EOF | ||
111 | +{ "execute": "qmp_capabilities" } | ||
112 | +{ "execute": "x-blockdev-create", | ||
113 | + "arguments": { | ||
114 | + "driver": "file", | ||
115 | + "filename": "$TEST_IMG", | ||
116 | + "size": 0 | ||
117 | + } | ||
118 | +} | ||
119 | +{ "execute": "x-blockdev-create", | ||
120 | + "arguments": { | ||
121 | + "driver": "$IMGFMT", | ||
122 | + "file": { | ||
123 | + "driver": "file", | ||
124 | + "filename": "$TEST_IMG" | ||
125 | + }, | ||
126 | + "size": $size, | ||
127 | + "preallocation": "off" | ||
128 | + } | ||
129 | +} | ||
130 | +{ "execute": "quit" } | ||
131 | +EOF | ||
132 | + | ||
133 | +_img_info --format-specific | _filter_img_info --format-specific | ||
134 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
135 | + | ||
136 | +echo | ||
137 | +echo "=== Successful image creation (with non-default options) ===" | ||
138 | +echo | ||
139 | + | ||
140 | +# Choose a different size to show that we got a new image | ||
141 | +size=$((32 * 1024 * 1024)) | ||
142 | + | ||
143 | +run_qemu <<EOF | ||
144 | +{ "execute": "qmp_capabilities" } | ||
145 | +{ "execute": "x-blockdev-create", | ||
146 | + "arguments": { | ||
147 | + "driver": "file", | ||
148 | + "filename": "$TEST_IMG", | ||
149 | + "size": 0 | ||
150 | + } | ||
151 | +} | ||
152 | +{ "execute": "x-blockdev-create", | ||
153 | + "arguments": { | ||
154 | + "driver": "$IMGFMT", | ||
155 | + "file": { | ||
156 | + "driver": "file", | ||
157 | + "filename": "$TEST_IMG" | ||
158 | + }, | ||
159 | + "size": $size, | ||
160 | + "preallocation": "metadata" | ||
161 | + } | ||
162 | +} | ||
163 | +{ "execute": "quit" } | ||
164 | +EOF | ||
165 | + | ||
166 | +_img_info --format-specific | _filter_img_info --format-specific | ||
167 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
168 | + | ||
169 | +echo | ||
170 | +echo "=== Invalid BlockdevRef ===" | ||
171 | +echo | ||
172 | + | ||
173 | +run_qemu <<EOF | ||
174 | +{ "execute": "qmp_capabilities" } | ||
175 | +{ "execute": "x-blockdev-create", | ||
176 | + "arguments": { | ||
177 | + "driver": "$IMGFMT", | ||
178 | + "file": "this doesn't exist", | ||
179 | + "size": $size | ||
180 | + } | ||
181 | +} | ||
182 | +{ "execute": "quit" } | ||
183 | +EOF | ||
184 | + | ||
185 | +echo | ||
186 | +echo "=== Zero size ===" | ||
187 | +echo | ||
188 | + | ||
189 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
190 | +{ "execute": "qmp_capabilities" } | ||
191 | +{ "execute": "x-blockdev-create", | ||
192 | + "arguments": { | ||
193 | + "driver": "$IMGFMT", | ||
194 | + "file": "node0", | ||
195 | + "size": 0 | ||
196 | + } | ||
197 | +} | ||
198 | +{ "execute": "quit" } | ||
199 | +EOF | ||
200 | + | ||
201 | +_img_info | _filter_img_info | ||
202 | + | ||
203 | +echo | ||
204 | +echo "=== Maximum size ===" | ||
205 | +echo | ||
206 | + | ||
207 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
208 | +{ "execute": "qmp_capabilities" } | ||
209 | +{ "execute": "x-blockdev-create", | ||
210 | + "arguments": { | ||
211 | + "driver": "$IMGFMT", | ||
212 | + "file": "node0", | ||
213 | + "size": 562949819203584 | ||
214 | + } | ||
215 | +} | ||
216 | +{ "execute": "quit" } | ||
217 | +EOF | ||
218 | + | ||
219 | +_img_info | _filter_img_info | ||
220 | + | ||
221 | +echo | ||
222 | +echo "=== Invalid sizes ===" | ||
223 | +echo | ||
224 | + | ||
225 | +# TODO Negative image sizes aren't handled correctly, but this is a problem | ||
226 | +# with QAPI's implementation of the 'size' type and affects other commands as | ||
227 | +# well. Once this is fixed, we may want to add a test case here. | ||
228 | + | ||
229 | +# 1. 2^64 - 512 | ||
230 | +# 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this) | ||
231 | +# 3. 0x1fffff8000001 (one byte more than maximum image size for VDI) | ||
232 | + | ||
233 | +run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF | ||
234 | +{ "execute": "qmp_capabilities" } | ||
235 | +{ "execute": "x-blockdev-create", | ||
236 | + "arguments": { | ||
237 | + "driver": "$IMGFMT", | ||
238 | + "file": "node0", | ||
239 | + "size": 18446744073709551104 | ||
240 | + } | ||
241 | +} | ||
242 | +{ "execute": "x-blockdev-create", | ||
243 | + "arguments": { | ||
244 | + "driver": "$IMGFMT", | ||
245 | + "file": "node0", | ||
246 | + "size": 9223372036854775808 | ||
247 | + } | ||
248 | +} | ||
249 | +{ "execute": "x-blockdev-create", | ||
250 | + "arguments": { | ||
251 | + "driver": "$IMGFMT", | ||
252 | + "file": "node0", | ||
253 | + "size": 562949819203585 | ||
254 | + } | ||
255 | +} | ||
256 | +{ "execute": "quit" } | ||
257 | +EOF | ||
258 | + | ||
259 | +# success, all done | ||
260 | +echo "*** done" | ||
261 | +rm -f $seq.full | ||
262 | +status=0 | ||
263 | diff --git a/tests/qemu-iotests/211.out b/tests/qemu-iotests/211.out | ||
264 | new file mode 100644 | ||
265 | index XXXXXXX..XXXXXXX | ||
266 | --- /dev/null | ||
267 | +++ b/tests/qemu-iotests/211.out | ||
268 | @@ -XXX,XX +XXX,XX @@ | ||
269 | +QA output created by 211 | ||
270 | + | ||
271 | +=== Successful image creation (defaults) === | ||
272 | + | ||
273 | +Testing: | ||
274 | +QMP_VERSION | ||
275 | +{"return": {}} | ||
276 | +{"return": {}} | ||
277 | +{"return": {}} | ||
278 | +{"return": {}} | ||
279 | +{"return": {}} | ||
280 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
281 | + | ||
282 | +image: TEST_DIR/t.IMGFMT | ||
283 | +file format: IMGFMT | ||
284 | +virtual size: 128M (134217728 bytes) | ||
285 | +[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false}] | ||
286 | + | ||
287 | +=== Successful image creation (explicit defaults) === | ||
288 | + | ||
289 | +Testing: | ||
290 | +QMP_VERSION | ||
291 | +{"return": {}} | ||
292 | +{"return": {}} | ||
293 | +{"return": {}} | ||
294 | +{"return": {}} | ||
295 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
296 | + | ||
297 | +image: TEST_DIR/t.IMGFMT | ||
298 | +file format: IMGFMT | ||
299 | +virtual size: 64M (67108864 bytes) | ||
300 | +[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}] | ||
301 | + | ||
302 | +=== Successful image creation (with non-default options) === | ||
303 | + | ||
304 | +Testing: | ||
305 | +QMP_VERSION | ||
306 | +{"return": {}} | ||
307 | +{"return": {}} | ||
308 | +{"return": {}} | ||
309 | +{"return": {}} | ||
310 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
311 | + | ||
312 | +image: TEST_DIR/t.IMGFMT | ||
313 | +file format: IMGFMT | ||
314 | +virtual size: 32M (33554432 bytes) | ||
315 | +[{ "start": 0, "length": 3072, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
316 | +{ "start": 3072, "length": 33551360, "depth": 0, "zero": true, "data": true, "offset": OFFSET}] | ||
317 | + | ||
318 | +=== Invalid BlockdevRef === | ||
319 | + | ||
320 | +Testing: | ||
321 | +QMP_VERSION | ||
322 | +{"return": {}} | ||
323 | +{"error": {"class": "GenericError", "desc": "Cannot find device=this doesn't exist nor node_name=this doesn't exist"}} | ||
324 | +{"return": {}} | ||
325 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
326 | + | ||
327 | + | ||
328 | +=== Zero size === | ||
329 | + | ||
330 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
331 | +QMP_VERSION | ||
332 | +{"return": {}} | ||
333 | +{"return": {}} | ||
334 | +{"return": {}} | ||
335 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
336 | + | ||
337 | +image: TEST_DIR/t.IMGFMT | ||
338 | +file format: IMGFMT | ||
339 | +virtual size: 0 (0 bytes) | ||
340 | + | ||
341 | +=== Maximum size === | ||
342 | + | ||
343 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
344 | +QMP_VERSION | ||
345 | +{"return": {}} | ||
346 | +{"return": {}} | ||
347 | +{"return": {}} | ||
348 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
349 | + | ||
350 | +image: TEST_DIR/t.IMGFMT | ||
351 | +file format: IMGFMT | ||
352 | +virtual size: 512T (562949819203584 bytes) | ||
353 | + | ||
354 | +=== Invalid sizes === | ||
355 | + | ||
356 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 | ||
357 | +QMP_VERSION | ||
358 | +{"return": {}} | ||
359 | +{"error": {"class": "GenericError", "desc": "Unsupported VDI image size (size is 0xfffffffffffffe00, max supported is 0x1fffff8000000)"}} | ||
360 | +{"error": {"class": "GenericError", "desc": "Unsupported VDI image size (size is 0x8000000000000000, max supported is 0x1fffff8000000)"}} | ||
361 | +{"error": {"class": "GenericError", "desc": "Unsupported VDI image size (size is 0x1fffff8000001, max supported is 0x1fffff8000000)"}} | ||
362 | +{"return": {}} | ||
363 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
364 | + | ||
365 | +*** done | ||
366 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
367 | index XXXXXXX..XXXXXXX 100644 | ||
368 | --- a/tests/qemu-iotests/group | ||
369 | +++ b/tests/qemu-iotests/group | ||
370 | @@ -XXX,XX +XXX,XX @@ | ||
371 | 208 rw auto quick | ||
372 | 209 rw auto quick | ||
373 | 210 rw auto | ||
374 | +211 rw auto quick | ||
375 | -- | 92 | -- |
376 | 2.13.6 | 93 | 2.30.2 |
377 | 94 | ||
378 | 95 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | To be used in further commit. | ||
4 | |||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
6 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Message-Id: <20210428151804.439460-28-vsementsov@virtuozzo.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | --- | ||
10 | include/block/block.h | 3 ++- | ||
11 | block.c | 9 ++++----- | ||
12 | block/io.c | 31 +++++++++++++++++++++++++++++-- | ||
13 | 3 files changed, 35 insertions(+), 8 deletions(-) | ||
14 | |||
15 | diff --git a/include/block/block.h b/include/block/block.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/block/block.h | ||
18 | +++ b/include/block/block.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #include "block/dirty-bitmap.h" | ||
21 | #include "block/blockjob.h" | ||
22 | #include "qemu/hbitmap.h" | ||
23 | +#include "qemu/transactions.h" | ||
24 | |||
25 | /* | ||
26 | * generated_co_wrapper | ||
27 | @@ -XXX,XX +XXX,XX @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); | ||
28 | BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, | ||
29 | BlockDriverState *in_bs, Error **errp); | ||
30 | void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); | ||
31 | -void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); | ||
32 | +void bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error **errp); | ||
33 | int bdrv_commit(BlockDriverState *bs); | ||
34 | int bdrv_make_empty(BdrvChild *c, Error **errp); | ||
35 | int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, | ||
36 | diff --git a/block.c b/block.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block.c | ||
39 | +++ b/block.c | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | #include "qemu/timer.h" | ||
42 | #include "qemu/cutils.h" | ||
43 | #include "qemu/id.h" | ||
44 | -#include "qemu/transactions.h" | ||
45 | #include "block/coroutines.h" | ||
46 | |||
47 | #ifdef CONFIG_BSD | ||
48 | @@ -XXX,XX +XXX,XX @@ static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, | ||
49 | return ret; | ||
50 | } | ||
51 | |||
52 | - bdrv_refresh_limits(bs, &local_err); | ||
53 | + bdrv_refresh_limits(bs, NULL, &local_err); | ||
54 | if (local_err) { | ||
55 | error_propagate(errp, local_err); | ||
56 | return -EINVAL; | ||
57 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
58 | } | ||
59 | |||
60 | out: | ||
61 | - bdrv_refresh_limits(bs, NULL); | ||
62 | + bdrv_refresh_limits(bs, NULL, NULL); | ||
63 | |||
64 | return ret; | ||
65 | } | ||
66 | @@ -XXX,XX +XXX,XX @@ static void bdrv_reopen_commit(BDRVReopenState *reopen_state) | ||
67 | bdrv_set_backing_hd(bs, reopen_state->new_backing_bs, &error_abort); | ||
68 | } | ||
69 | |||
70 | - bdrv_refresh_limits(bs, NULL); | ||
71 | + bdrv_refresh_limits(bs, NULL, NULL); | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | @@ -XXX,XX +XXX,XX @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, | ||
76 | out: | ||
77 | tran_finalize(tran, ret); | ||
78 | |||
79 | - bdrv_refresh_limits(bs_top, NULL); | ||
80 | + bdrv_refresh_limits(bs_top, NULL, NULL); | ||
81 | |||
82 | return ret; | ||
83 | } | ||
84 | diff --git a/block/io.c b/block/io.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/block/io.c | ||
87 | +++ b/block/io.c | ||
88 | @@ -XXX,XX +XXX,XX @@ static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) | ||
89 | dst->max_iov = MIN_NON_ZERO(dst->max_iov, src->max_iov); | ||
90 | } | ||
91 | |||
92 | -void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) | ||
93 | +typedef struct BdrvRefreshLimitsState { | ||
94 | + BlockDriverState *bs; | ||
95 | + BlockLimits old_bl; | ||
96 | +} BdrvRefreshLimitsState; | ||
97 | + | ||
98 | +static void bdrv_refresh_limits_abort(void *opaque) | ||
99 | +{ | ||
100 | + BdrvRefreshLimitsState *s = opaque; | ||
101 | + | ||
102 | + s->bs->bl = s->old_bl; | ||
103 | +} | ||
104 | + | ||
105 | +static TransactionActionDrv bdrv_refresh_limits_drv = { | ||
106 | + .abort = bdrv_refresh_limits_abort, | ||
107 | + .clean = g_free, | ||
108 | +}; | ||
109 | + | ||
110 | +/* @tran is allowed to be NULL, in this case no rollback is possible. */ | ||
111 | +void bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error **errp) | ||
112 | { | ||
113 | ERRP_GUARD(); | ||
114 | BlockDriver *drv = bs->drv; | ||
115 | BdrvChild *c; | ||
116 | bool have_limits; | ||
117 | |||
118 | + if (tran) { | ||
119 | + BdrvRefreshLimitsState *s = g_new(BdrvRefreshLimitsState, 1); | ||
120 | + *s = (BdrvRefreshLimitsState) { | ||
121 | + .bs = bs, | ||
122 | + .old_bl = bs->bl, | ||
123 | + }; | ||
124 | + tran_add(tran, &bdrv_refresh_limits_drv, s); | ||
125 | + } | ||
126 | + | ||
127 | memset(&bs->bl, 0, sizeof(bs->bl)); | ||
128 | |||
129 | if (!drv) { | ||
130 | @@ -XXX,XX +XXX,XX @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) | ||
131 | QLIST_FOREACH(c, &bs->children, next) { | ||
132 | if (c->role & (BDRV_CHILD_DATA | BDRV_CHILD_FILTERED | BDRV_CHILD_COW)) | ||
133 | { | ||
134 | - bdrv_refresh_limits(c->bs, errp); | ||
135 | + bdrv_refresh_limits(c->bs, tran, errp); | ||
136 | if (*errp) { | ||
137 | return; | ||
138 | } | ||
139 | -- | ||
140 | 2.30.2 | ||
141 | |||
142 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | Split out no-perm part of bdrv_set_backing_hd() as a separate | ||
4 | transaction action. Note the in case of existing BdrvChild we reuse it, | ||
5 | not recreate, just to do less actions. | ||
6 | |||
7 | We don't need to create extra reference to backing_hd as we don't lose | ||
8 | it in bdrv_attach_child(). | ||
9 | |||
10 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
11 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | Message-Id: <20210428151804.439460-29-vsementsov@virtuozzo.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | block.c | 54 +++++++++++++++++++++++++++++++++++++----------------- | ||
16 | 1 file changed, 37 insertions(+), 17 deletions(-) | ||
17 | |||
18 | diff --git a/block.c b/block.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block.c | ||
21 | +++ b/block.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, | ||
23 | BdrvChild **child, | ||
24 | Transaction *tran, | ||
25 | Error **errp); | ||
26 | +static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, | ||
27 | + Transaction *tran); | ||
28 | |||
29 | static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue | ||
30 | *queue, Error **errp); | ||
31 | @@ -XXX,XX +XXX,XX @@ static BdrvChildRole bdrv_backing_role(BlockDriverState *bs) | ||
32 | * Sets the bs->backing link of a BDS. A new reference is created; callers | ||
33 | * which don't need their own reference any more must call bdrv_unref(). | ||
34 | */ | ||
35 | -int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
36 | - Error **errp) | ||
37 | +static int bdrv_set_backing_noperm(BlockDriverState *bs, | ||
38 | + BlockDriverState *backing_hd, | ||
39 | + Transaction *tran, Error **errp) | ||
40 | { | ||
41 | int ret = 0; | ||
42 | bool update_inherits_from = bdrv_chain_contains(bs, backing_hd) && | ||
43 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
44 | return -EPERM; | ||
45 | } | ||
46 | |||
47 | - if (backing_hd) { | ||
48 | - bdrv_ref(backing_hd); | ||
49 | - } | ||
50 | - | ||
51 | if (bs->backing) { | ||
52 | /* Cannot be frozen, we checked that above */ | ||
53 | - bdrv_unref_child(bs, bs->backing); | ||
54 | - bs->backing = NULL; | ||
55 | + bdrv_unset_inherits_from(bs, bs->backing, tran); | ||
56 | + bdrv_remove_filter_or_cow_child(bs, tran); | ||
57 | } | ||
58 | |||
59 | if (!backing_hd) { | ||
60 | goto out; | ||
61 | } | ||
62 | |||
63 | - bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_of_bds, | ||
64 | - bdrv_backing_role(bs), errp); | ||
65 | - if (!bs->backing) { | ||
66 | - ret = -EPERM; | ||
67 | - goto out; | ||
68 | + ret = bdrv_attach_child_noperm(bs, backing_hd, "backing", | ||
69 | + &child_of_bds, bdrv_backing_role(bs), | ||
70 | + &bs->backing, tran, errp); | ||
71 | + if (ret < 0) { | ||
72 | + return ret; | ||
73 | } | ||
74 | |||
75 | - /* If backing_hd was already part of bs's backing chain, and | ||
76 | + | ||
77 | + /* | ||
78 | + * If backing_hd was already part of bs's backing chain, and | ||
79 | * inherits_from pointed recursively to bs then let's update it to | ||
80 | - * point directly to bs (else it will become NULL). */ | ||
81 | + * point directly to bs (else it will become NULL). | ||
82 | + */ | ||
83 | if (update_inherits_from) { | ||
84 | - backing_hd->inherits_from = bs; | ||
85 | + bdrv_set_inherits_from(backing_hd, bs, tran); | ||
86 | } | ||
87 | |||
88 | out: | ||
89 | - bdrv_refresh_limits(bs, NULL, NULL); | ||
90 | + bdrv_refresh_limits(bs, tran, NULL); | ||
91 | + | ||
92 | + return 0; | ||
93 | +} | ||
94 | + | ||
95 | +int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
96 | + Error **errp) | ||
97 | +{ | ||
98 | + int ret; | ||
99 | + Transaction *tran = tran_new(); | ||
100 | + | ||
101 | + ret = bdrv_set_backing_noperm(bs, backing_hd, tran, errp); | ||
102 | + if (ret < 0) { | ||
103 | + goto out; | ||
104 | + } | ||
105 | + | ||
106 | + ret = bdrv_refresh_perms(bs, errp); | ||
107 | +out: | ||
108 | + tran_finalize(tran, ret); | ||
109 | |||
110 | return ret; | ||
111 | } | ||
112 | -- | ||
113 | 2.30.2 | ||
114 | |||
115 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | During reopen we may add backing bs from other aio context, which may | ||
4 | lead to changing original context of top bs. | ||
5 | |||
6 | We are going to move graph modification to prepare stage. So, it will | ||
7 | be possible that bdrv_flush() in bdrv_reopen_prepare called on bs in | ||
8 | non-original aio context, which we didn't aquire which leads to crash. | ||
9 | |||
10 | To avoid this problem move bdrv_flush() to be a separate reopen stage | ||
11 | before bdrv_reopen_prepare(). | ||
12 | |||
13 | This doesn't seem correct to acquire only one aio context and not all | ||
14 | contexts participating in reopen. But it's not obvious how to do it | ||
15 | correctly, keeping in mind: | ||
16 | |||
17 | 1. rules of bdrv_set_aio_context_ignore() that requires new_context | ||
18 | lock not being held | ||
19 | |||
20 | 2. possible deadlocks because of holding all (or several?) AioContext | ||
21 | locks | ||
22 | |||
23 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
24 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
25 | Message-Id: <20210428151804.439460-30-vsementsov@virtuozzo.com> | ||
26 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
27 | --- | ||
28 | block.c | 14 ++++++++------ | ||
29 | 1 file changed, 8 insertions(+), 6 deletions(-) | ||
30 | |||
31 | diff --git a/block.c b/block.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block.c | ||
34 | +++ b/block.c | ||
35 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
36 | |||
37 | assert(bs_queue != NULL); | ||
38 | |||
39 | + QTAILQ_FOREACH(bs_entry, bs_queue, entry) { | ||
40 | + ret = bdrv_flush(bs_entry->state.bs); | ||
41 | + if (ret < 0) { | ||
42 | + error_setg_errno(errp, -ret, "Error flushing drive"); | ||
43 | + goto cleanup; | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | QTAILQ_FOREACH(bs_entry, bs_queue, entry) { | ||
48 | assert(bs_entry->state.bs->quiesce_counter > 0); | ||
49 | if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) { | ||
50 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
51 | bdrv_reopen_perm(queue, reopen_state->bs, | ||
52 | &reopen_state->perm, &reopen_state->shared_perm); | ||
53 | |||
54 | - ret = bdrv_flush(reopen_state->bs); | ||
55 | - if (ret) { | ||
56 | - error_setg_errno(errp, -ret, "Error flushing drive"); | ||
57 | - goto error; | ||
58 | - } | ||
59 | - | ||
60 | if (drv->bdrv_reopen_prepare) { | ||
61 | /* | ||
62 | * If a driver-specific option is missing, it means that we | ||
63 | -- | ||
64 | 2.30.2 | ||
65 | |||
66 | diff view generated by jsdifflib |
1 | Images with a non-power-of-two block size are invalid and cannot be | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | opened. Reject such block sizes when creating an image. | ||
3 | 2 | ||
3 | Move bdrv_reopen_multiple to new paradigm of permission update: | ||
4 | first update graph relations, then do refresh the permissions. | ||
5 | |||
6 | We have to modify reopen process in file-posix driver: with new scheme | ||
7 | we don't have prepared permissions in raw_reopen_prepare(), so we | ||
8 | should reconfigure fd in raw_check_perm(). Still this seems more native | ||
9 | and simple anyway. | ||
10 | |||
11 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Message-Id: <20210428151804.439460-31-vsementsov@virtuozzo.com> | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
5 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
7 | --- | 15 | --- |
8 | block/vhdx.c | 4 ++++ | 16 | include/block/block.h | 3 +- |
9 | 1 file changed, 4 insertions(+) | 17 | block.c | 187 ++++++++++++------------------------------ |
18 | block/file-posix.c | 91 +++++++------------- | ||
19 | 3 files changed, 84 insertions(+), 197 deletions(-) | ||
10 | 20 | ||
11 | diff --git a/block/vhdx.c b/block/vhdx.c | 21 | diff --git a/include/block/block.h b/include/block/block.h |
12 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/block/vhdx.c | 23 | --- a/include/block/block.h |
14 | +++ b/block/vhdx.c | 24 | +++ b/include/block/block.h |
15 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | 25 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVReopenState { |
16 | error_setg_errno(errp, EINVAL, "Block size must be a multiple of 1 MB"); | 26 | BlockdevDetectZeroesOptions detect_zeroes; |
17 | return -EINVAL; | 27 | bool backing_missing; |
18 | } | 28 | bool replace_backing_bs; /* new_backing_bs is ignored if this is false */ |
19 | + if (!is_power_of_2(block_size)) { | 29 | - BlockDriverState *new_backing_bs; /* If NULL then detach the current bs */ |
20 | + error_setg(errp, "Block size must be a power of two"); | 30 | - uint64_t perm, shared_perm; |
21 | + return -EINVAL; | 31 | + BlockDriverState *old_backing_bs; /* keep pointer for permissions update */ |
32 | QDict *options; | ||
33 | QDict *explicit_options; | ||
34 | void *opaque; | ||
35 | diff --git a/block.c b/block.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/block.c | ||
38 | +++ b/block.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, | ||
40 | static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, | ||
41 | Transaction *tran); | ||
42 | |||
43 | -static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue | ||
44 | - *queue, Error **errp); | ||
45 | +static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
46 | + BlockReopenQueue *queue, | ||
47 | + Transaction *set_backings_tran, Error **errp); | ||
48 | static void bdrv_reopen_commit(BDRVReopenState *reopen_state); | ||
49 | static void bdrv_reopen_abort(BDRVReopenState *reopen_state); | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ static void bdrv_list_abort_perm_update(GSList *list) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | +__attribute__((unused)) | ||
56 | static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
57 | { | ||
58 | g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
59 | @@ -XXX,XX +XXX,XX @@ char *bdrv_perm_names(uint64_t perm) | ||
60 | * | ||
61 | * Needs to be followed by a call to either bdrv_set_perm() or | ||
62 | * bdrv_abort_perm_update(). */ | ||
63 | +__attribute__((unused)) | ||
64 | static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
65 | uint64_t new_used_perm, | ||
66 | uint64_t new_shared_perm, | ||
67 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
68 | bs_entry->state.explicit_options = explicit_options; | ||
69 | bs_entry->state.flags = flags; | ||
70 | |||
71 | - /* This needs to be overwritten in bdrv_reopen_prepare() */ | ||
72 | - bs_entry->state.perm = UINT64_MAX; | ||
73 | - bs_entry->state.shared_perm = 0; | ||
74 | - | ||
75 | /* | ||
76 | * If keep_old_opts is false then it means that unspecified | ||
77 | * options must be reset to their original value. We don't allow | ||
78 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
79 | { | ||
80 | int ret = -1; | ||
81 | BlockReopenQueueEntry *bs_entry, *next; | ||
82 | + Transaction *tran = tran_new(); | ||
83 | + g_autoptr(GHashTable) found = NULL; | ||
84 | + g_autoptr(GSList) refresh_list = NULL; | ||
85 | |||
86 | assert(bs_queue != NULL); | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
89 | |||
90 | QTAILQ_FOREACH(bs_entry, bs_queue, entry) { | ||
91 | assert(bs_entry->state.bs->quiesce_counter > 0); | ||
92 | - if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) { | ||
93 | - goto cleanup; | ||
94 | + ret = bdrv_reopen_prepare(&bs_entry->state, bs_queue, tran, errp); | ||
95 | + if (ret < 0) { | ||
96 | + goto abort; | ||
97 | } | ||
98 | bs_entry->prepared = true; | ||
99 | } | ||
100 | |||
101 | + found = g_hash_table_new(NULL, NULL); | ||
102 | QTAILQ_FOREACH(bs_entry, bs_queue, entry) { | ||
103 | BDRVReopenState *state = &bs_entry->state; | ||
104 | - ret = bdrv_check_perm(state->bs, bs_queue, state->perm, | ||
105 | - state->shared_perm, errp); | ||
106 | - if (ret < 0) { | ||
107 | - goto cleanup_perm; | ||
108 | - } | ||
109 | - /* Check if new_backing_bs would accept the new permissions */ | ||
110 | - if (state->replace_backing_bs && state->new_backing_bs) { | ||
111 | - uint64_t nperm, nshared; | ||
112 | - bdrv_child_perm(state->bs, state->new_backing_bs, | ||
113 | - NULL, bdrv_backing_role(state->bs), | ||
114 | - bs_queue, state->perm, state->shared_perm, | ||
115 | - &nperm, &nshared); | ||
116 | - ret = bdrv_check_update_perm(state->new_backing_bs, NULL, | ||
117 | - nperm, nshared, errp); | ||
118 | - if (ret < 0) { | ||
119 | - goto cleanup_perm; | ||
120 | - } | ||
121 | + | ||
122 | + refresh_list = bdrv_topological_dfs(refresh_list, found, state->bs); | ||
123 | + if (state->old_backing_bs) { | ||
124 | + refresh_list = bdrv_topological_dfs(refresh_list, found, | ||
125 | + state->old_backing_bs); | ||
126 | } | ||
127 | - bs_entry->perms_checked = true; | ||
22 | + } | 128 | + } |
23 | if (block_size > VHDX_BLOCK_SIZE_MAX) { | 129 | + |
24 | error_setg_errno(errp, EINVAL, "Block size must not exceed %d", | 130 | + /* |
25 | VHDX_BLOCK_SIZE_MAX); | 131 | + * Note that file-posix driver rely on permission update done during reopen |
132 | + * (even if no permission changed), because it wants "new" permissions for | ||
133 | + * reconfiguring the fd and that's why it does it in raw_check_perm(), not | ||
134 | + * in raw_reopen_prepare() which is called with "old" permissions. | ||
135 | + */ | ||
136 | + ret = bdrv_list_refresh_perms(refresh_list, bs_queue, tran, errp); | ||
137 | + if (ret < 0) { | ||
138 | + goto abort; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
143 | bdrv_reopen_commit(&bs_entry->state); | ||
144 | } | ||
145 | |||
146 | - ret = 0; | ||
147 | -cleanup_perm: | ||
148 | - QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { | ||
149 | - BDRVReopenState *state = &bs_entry->state; | ||
150 | - | ||
151 | - if (!bs_entry->perms_checked) { | ||
152 | - continue; | ||
153 | - } | ||
154 | - | ||
155 | - if (ret == 0) { | ||
156 | - uint64_t perm, shared; | ||
157 | + tran_commit(tran); | ||
158 | |||
159 | - bdrv_get_cumulative_perm(state->bs, &perm, &shared); | ||
160 | - assert(perm == state->perm); | ||
161 | - assert(shared == state->shared_perm); | ||
162 | + QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) { | ||
163 | + BlockDriverState *bs = bs_entry->state.bs; | ||
164 | |||
165 | - bdrv_set_perm(state->bs); | ||
166 | - } else { | ||
167 | - bdrv_abort_perm_update(state->bs); | ||
168 | - if (state->replace_backing_bs && state->new_backing_bs) { | ||
169 | - bdrv_abort_perm_update(state->new_backing_bs); | ||
170 | - } | ||
171 | + if (bs->drv->bdrv_reopen_commit_post) { | ||
172 | + bs->drv->bdrv_reopen_commit_post(&bs_entry->state); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | - if (ret == 0) { | ||
177 | - QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) { | ||
178 | - BlockDriverState *bs = bs_entry->state.bs; | ||
179 | + ret = 0; | ||
180 | + goto cleanup; | ||
181 | |||
182 | - if (bs->drv->bdrv_reopen_commit_post) | ||
183 | - bs->drv->bdrv_reopen_commit_post(&bs_entry->state); | ||
184 | +abort: | ||
185 | + tran_abort(tran); | ||
186 | + QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { | ||
187 | + if (bs_entry->prepared) { | ||
188 | + bdrv_reopen_abort(&bs_entry->state); | ||
189 | } | ||
190 | + qobject_unref(bs_entry->state.explicit_options); | ||
191 | + qobject_unref(bs_entry->state.options); | ||
192 | } | ||
193 | + | ||
194 | cleanup: | ||
195 | QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { | ||
196 | - if (ret) { | ||
197 | - if (bs_entry->prepared) { | ||
198 | - bdrv_reopen_abort(&bs_entry->state); | ||
199 | - } | ||
200 | - qobject_unref(bs_entry->state.explicit_options); | ||
201 | - qobject_unref(bs_entry->state.options); | ||
202 | - } | ||
203 | - if (bs_entry->state.new_backing_bs) { | ||
204 | - bdrv_unref(bs_entry->state.new_backing_bs); | ||
205 | - } | ||
206 | g_free(bs_entry); | ||
207 | } | ||
208 | g_free(bs_queue); | ||
209 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, | ||
210 | return ret; | ||
211 | } | ||
212 | |||
213 | -static BlockReopenQueueEntry *find_parent_in_reopen_queue(BlockReopenQueue *q, | ||
214 | - BdrvChild *c) | ||
215 | -{ | ||
216 | - BlockReopenQueueEntry *entry; | ||
217 | - | ||
218 | - QTAILQ_FOREACH(entry, q, entry) { | ||
219 | - BlockDriverState *bs = entry->state.bs; | ||
220 | - BdrvChild *child; | ||
221 | - | ||
222 | - QLIST_FOREACH(child, &bs->children, next) { | ||
223 | - if (child == c) { | ||
224 | - return entry; | ||
225 | - } | ||
226 | - } | ||
227 | - } | ||
228 | - | ||
229 | - return NULL; | ||
230 | -} | ||
231 | - | ||
232 | -static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, | ||
233 | - uint64_t *perm, uint64_t *shared) | ||
234 | -{ | ||
235 | - BdrvChild *c; | ||
236 | - BlockReopenQueueEntry *parent; | ||
237 | - uint64_t cumulative_perms = 0; | ||
238 | - uint64_t cumulative_shared_perms = BLK_PERM_ALL; | ||
239 | - | ||
240 | - QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
241 | - parent = find_parent_in_reopen_queue(q, c); | ||
242 | - if (!parent) { | ||
243 | - cumulative_perms |= c->perm; | ||
244 | - cumulative_shared_perms &= c->shared_perm; | ||
245 | - } else { | ||
246 | - uint64_t nperm, nshared; | ||
247 | - | ||
248 | - bdrv_child_perm(parent->state.bs, bs, c, c->role, q, | ||
249 | - parent->state.perm, parent->state.shared_perm, | ||
250 | - &nperm, &nshared); | ||
251 | - | ||
252 | - cumulative_perms |= nperm; | ||
253 | - cumulative_shared_perms &= nshared; | ||
254 | - } | ||
255 | - } | ||
256 | - *perm = cumulative_perms; | ||
257 | - *shared = cumulative_shared_perms; | ||
258 | -} | ||
259 | - | ||
260 | static bool bdrv_reopen_can_attach(BlockDriverState *parent, | ||
261 | BdrvChild *child, | ||
262 | BlockDriverState *new_child, | ||
263 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_reopen_can_attach(BlockDriverState *parent, | ||
264 | * Return 0 on success, otherwise return < 0 and set @errp. | ||
265 | */ | ||
266 | static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, | ||
267 | + Transaction *set_backings_tran, | ||
268 | Error **errp) | ||
269 | { | ||
270 | BlockDriverState *bs = reopen_state->bs; | ||
271 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, | ||
272 | |||
273 | /* If we want to replace the backing file we need some extra checks */ | ||
274 | if (new_backing_bs != bdrv_filter_or_cow_bs(overlay_bs)) { | ||
275 | + int ret; | ||
276 | + | ||
277 | /* Check for implicit nodes between bs and its backing file */ | ||
278 | if (bs != overlay_bs) { | ||
279 | error_setg(errp, "Cannot change backing link if '%s' has " | ||
280 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, | ||
281 | return -EPERM; | ||
282 | } | ||
283 | reopen_state->replace_backing_bs = true; | ||
284 | - if (new_backing_bs) { | ||
285 | - bdrv_ref(new_backing_bs); | ||
286 | - reopen_state->new_backing_bs = new_backing_bs; | ||
287 | + reopen_state->old_backing_bs = bs->backing ? bs->backing->bs : NULL; | ||
288 | + ret = bdrv_set_backing_noperm(bs, new_backing_bs, set_backings_tran, | ||
289 | + errp); | ||
290 | + if (ret < 0) { | ||
291 | + return ret; | ||
292 | } | ||
293 | } | ||
294 | |||
295 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, | ||
296 | * | ||
297 | */ | ||
298 | static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
299 | - BlockReopenQueue *queue, Error **errp) | ||
300 | + BlockReopenQueue *queue, | ||
301 | + Transaction *set_backings_tran, Error **errp) | ||
302 | { | ||
303 | int ret = -1; | ||
304 | int old_flags; | ||
305 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
306 | goto error; | ||
307 | } | ||
308 | |||
309 | - /* Calculate required permissions after reopening */ | ||
310 | - bdrv_reopen_perm(queue, reopen_state->bs, | ||
311 | - &reopen_state->perm, &reopen_state->shared_perm); | ||
312 | - | ||
313 | if (drv->bdrv_reopen_prepare) { | ||
314 | /* | ||
315 | * If a driver-specific option is missing, it means that we | ||
316 | @@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, | ||
317 | * either a reference to an existing node (using its node name) | ||
318 | * or NULL to simply detach the current backing file. | ||
319 | */ | ||
320 | - ret = bdrv_reopen_parse_backing(reopen_state, errp); | ||
321 | + ret = bdrv_reopen_parse_backing(reopen_state, set_backings_tran, errp); | ||
322 | if (ret < 0) { | ||
323 | goto error; | ||
324 | } | ||
325 | @@ -XXX,XX +XXX,XX @@ static void bdrv_reopen_commit(BDRVReopenState *reopen_state) | ||
326 | qdict_del(bs->explicit_options, child->name); | ||
327 | qdict_del(bs->options, child->name); | ||
328 | } | ||
329 | - | ||
330 | - /* | ||
331 | - * Change the backing file if a new one was specified. We do this | ||
332 | - * after updating bs->options, so bdrv_refresh_filename() (called | ||
333 | - * from bdrv_set_backing_hd()) has the new values. | ||
334 | - */ | ||
335 | - if (reopen_state->replace_backing_bs) { | ||
336 | - BlockDriverState *old_backing_bs = child_bs(bs->backing); | ||
337 | - assert(!old_backing_bs || !old_backing_bs->implicit); | ||
338 | - /* Abort the permission update on the backing bs we're detaching */ | ||
339 | - if (old_backing_bs) { | ||
340 | - bdrv_abort_perm_update(old_backing_bs); | ||
341 | - } | ||
342 | - bdrv_set_backing_hd(bs, reopen_state->new_backing_bs, &error_abort); | ||
343 | - } | ||
344 | - | ||
345 | bdrv_refresh_limits(bs, NULL, NULL); | ||
346 | } | ||
347 | |||
348 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
349 | index XXXXXXX..XXXXXXX 100644 | ||
350 | --- a/block/file-posix.c | ||
351 | +++ b/block/file-posix.c | ||
352 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVRawState { | ||
353 | } BDRVRawState; | ||
354 | |||
355 | typedef struct BDRVRawReopenState { | ||
356 | - int fd; | ||
357 | int open_flags; | ||
358 | bool drop_cache; | ||
359 | bool check_cache_dropped; | ||
360 | @@ -XXX,XX +XXX,XX @@ static int raw_reopen_prepare(BDRVReopenState *state, | ||
361 | BDRVRawReopenState *rs; | ||
362 | QemuOpts *opts; | ||
363 | int ret; | ||
364 | - Error *local_err = NULL; | ||
365 | |||
366 | assert(state != NULL); | ||
367 | assert(state->bs != NULL); | ||
368 | @@ -XXX,XX +XXX,XX @@ static int raw_reopen_prepare(BDRVReopenState *state, | ||
369 | * bdrv_reopen_prepare() will detect changes and complain. */ | ||
370 | qemu_opts_to_qdict(opts, state->options); | ||
371 | |||
372 | - rs->fd = raw_reconfigure_getfd(state->bs, state->flags, &rs->open_flags, | ||
373 | - state->perm, true, &local_err); | ||
374 | - if (local_err) { | ||
375 | - error_propagate(errp, local_err); | ||
376 | - ret = -1; | ||
377 | - goto out; | ||
378 | - } | ||
379 | - | ||
380 | - /* Fail already reopen_prepare() if we can't get a working O_DIRECT | ||
381 | - * alignment with the new fd. */ | ||
382 | - if (rs->fd != -1) { | ||
383 | - raw_probe_alignment(state->bs, rs->fd, &local_err); | ||
384 | - if (local_err) { | ||
385 | - error_propagate(errp, local_err); | ||
386 | - ret = -EINVAL; | ||
387 | - goto out_fd; | ||
388 | - } | ||
389 | - } | ||
390 | + /* | ||
391 | + * As part of reopen prepare we also want to create new fd by | ||
392 | + * raw_reconfigure_getfd(). But it wants updated "perm", when in | ||
393 | + * bdrv_reopen_multiple() .bdrv_reopen_prepare() callback called prior to | ||
394 | + * permission update. Happily, permission update is always a part (a seprate | ||
395 | + * stage) of bdrv_reopen_multiple() so we can rely on this fact and | ||
396 | + * reconfigure fd in raw_check_perm(). | ||
397 | + */ | ||
398 | |||
399 | s->reopen_state = state; | ||
400 | ret = 0; | ||
401 | -out_fd: | ||
402 | - if (ret < 0) { | ||
403 | - qemu_close(rs->fd); | ||
404 | - rs->fd = -1; | ||
405 | - } | ||
406 | + | ||
407 | out: | ||
408 | qemu_opts_del(opts); | ||
409 | return ret; | ||
410 | @@ -XXX,XX +XXX,XX @@ static void raw_reopen_commit(BDRVReopenState *state) | ||
411 | s->drop_cache = rs->drop_cache; | ||
412 | s->check_cache_dropped = rs->check_cache_dropped; | ||
413 | s->open_flags = rs->open_flags; | ||
414 | - | ||
415 | - qemu_close(s->fd); | ||
416 | - s->fd = rs->fd; | ||
417 | - | ||
418 | g_free(state->opaque); | ||
419 | state->opaque = NULL; | ||
420 | |||
421 | @@ -XXX,XX +XXX,XX @@ static void raw_reopen_abort(BDRVReopenState *state) | ||
422 | return; | ||
423 | } | ||
424 | |||
425 | - if (rs->fd >= 0) { | ||
426 | - qemu_close(rs->fd); | ||
427 | - rs->fd = -1; | ||
428 | - } | ||
429 | g_free(state->opaque); | ||
430 | state->opaque = NULL; | ||
431 | |||
432 | @@ -XXX,XX +XXX,XX @@ static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared, | ||
433 | Error **errp) | ||
434 | { | ||
435 | BDRVRawState *s = bs->opaque; | ||
436 | - BDRVRawReopenState *rs = NULL; | ||
437 | + int input_flags = s->reopen_state ? s->reopen_state->flags : bs->open_flags; | ||
438 | int open_flags; | ||
439 | int ret; | ||
440 | |||
441 | - if (s->perm_change_fd) { | ||
442 | + /* We may need a new fd if auto-read-only switches the mode */ | ||
443 | + ret = raw_reconfigure_getfd(bs, input_flags, &open_flags, perm, | ||
444 | + false, errp); | ||
445 | + if (ret < 0) { | ||
446 | + return ret; | ||
447 | + } else if (ret != s->fd) { | ||
448 | + Error *local_err = NULL; | ||
449 | + | ||
450 | /* | ||
451 | - * In the context of reopen, this function may be called several times | ||
452 | - * (directly and recursively while change permissions of the parent). | ||
453 | - * This is even true for children that don't inherit from the original | ||
454 | - * reopen node, so s->reopen_state is not set. | ||
455 | - * | ||
456 | - * Ignore all but the first call. | ||
457 | + * Fail already check_perm() if we can't get a working O_DIRECT | ||
458 | + * alignment with the new fd. | ||
459 | */ | ||
460 | - return 0; | ||
461 | - } | ||
462 | - | ||
463 | - if (s->reopen_state) { | ||
464 | - /* We already have a new file descriptor to set permissions for */ | ||
465 | - assert(s->reopen_state->perm == perm); | ||
466 | - assert(s->reopen_state->shared_perm == shared); | ||
467 | - rs = s->reopen_state->opaque; | ||
468 | - s->perm_change_fd = rs->fd; | ||
469 | - s->perm_change_flags = rs->open_flags; | ||
470 | - } else { | ||
471 | - /* We may need a new fd if auto-read-only switches the mode */ | ||
472 | - ret = raw_reconfigure_getfd(bs, bs->open_flags, &open_flags, perm, | ||
473 | - false, errp); | ||
474 | - if (ret < 0) { | ||
475 | - return ret; | ||
476 | - } else if (ret != s->fd) { | ||
477 | - s->perm_change_fd = ret; | ||
478 | - s->perm_change_flags = open_flags; | ||
479 | + raw_probe_alignment(bs, ret, &local_err); | ||
480 | + if (local_err) { | ||
481 | + error_propagate(errp, local_err); | ||
482 | + return -EINVAL; | ||
483 | } | ||
484 | + | ||
485 | + s->perm_change_fd = ret; | ||
486 | + s->perm_change_flags = open_flags; | ||
487 | } | ||
488 | |||
489 | /* Prepare permissions on old fd to avoid conflicts between old and new, | ||
490 | @@ -XXX,XX +XXX,XX @@ static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared, | ||
491 | return 0; | ||
492 | |||
493 | fail: | ||
494 | - if (s->perm_change_fd && !s->reopen_state) { | ||
495 | + if (s->perm_change_fd) { | ||
496 | qemu_close(s->perm_change_fd); | ||
497 | } | ||
498 | s->perm_change_fd = 0; | ||
499 | @@ -XXX,XX +XXX,XX @@ static void raw_abort_perm_update(BlockDriverState *bs) | ||
500 | |||
501 | /* For reopen, .bdrv_reopen_abort is called afterwards and will close | ||
502 | * the file descriptor. */ | ||
503 | - if (s->perm_change_fd && !s->reopen_state) { | ||
504 | + if (s->perm_change_fd) { | ||
505 | qemu_close(s->perm_change_fd); | ||
506 | } | ||
507 | s->perm_change_fd = 0; | ||
26 | -- | 508 | -- |
27 | 2.13.6 | 509 | 2.30.2 |
28 | 510 | ||
29 | 511 | diff view generated by jsdifflib |
1 | This tests that the .bdrv_truncate implementation for luks doesn't crash | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | for invalid image sizes. | ||
3 | 2 | ||
3 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
5 | Message-Id: <20210428151804.439460-32-vsementsov@virtuozzo.com> | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
5 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | --- | 7 | --- |
7 | tests/qemu-iotests/210 | 37 +++++++++++++++++++++++++++++++++++++ | 8 | block.c | 103 -------------------------------------------------------- |
8 | tests/qemu-iotests/210.out | 16 ++++++++++++++++ | 9 | 1 file changed, 103 deletions(-) |
9 | 2 files changed, 53 insertions(+) | ||
10 | 10 | ||
11 | diff --git a/tests/qemu-iotests/210 b/tests/qemu-iotests/210 | 11 | diff --git a/block.c b/block.c |
12 | index XXXXXXX..XXXXXXX 100755 | ||
13 | --- a/tests/qemu-iotests/210 | ||
14 | +++ b/tests/qemu-iotests/210 | ||
15 | @@ -XXX,XX +XXX,XX @@ run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \ | ||
16 | { "execute": "quit" } | ||
17 | EOF | ||
18 | |||
19 | +echo | ||
20 | +echo "=== Resize image with invalid sizes ===" | ||
21 | +echo | ||
22 | + | ||
23 | +run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \ | ||
24 | + -blockdev driver=luks,file=node0,key-secret=keysec0,node-name=node1 \ | ||
25 | + -object secret,id=keysec0,data="foo" <<EOF | ||
26 | +{ "execute": "qmp_capabilities" } | ||
27 | +{ "execute": "block_resize", | ||
28 | + "arguments": { | ||
29 | + "node-name": "node1", | ||
30 | + "size": 9223372036854775296 | ||
31 | + } | ||
32 | +} | ||
33 | +{ "execute": "block_resize", | ||
34 | + "arguments": { | ||
35 | + "node-name": "node1", | ||
36 | + "size": 9223372036854775808 | ||
37 | + } | ||
38 | +} | ||
39 | +{ "execute": "block_resize", | ||
40 | + "arguments": { | ||
41 | + "node-name": "node1", | ||
42 | + "size": 18446744073709551104 | ||
43 | + } | ||
44 | +} | ||
45 | +{ "execute": "block_resize", | ||
46 | + "arguments": { | ||
47 | + "node-name": "node1", | ||
48 | + "size": -9223372036854775808 | ||
49 | + } | ||
50 | +} | ||
51 | +{ "execute": "quit" } | ||
52 | +EOF | ||
53 | + | ||
54 | +_img_info | _filter_img_info | ||
55 | + | ||
56 | # success, all done | ||
57 | echo "*** done" | ||
58 | rm -f $seq.full | ||
59 | diff --git a/tests/qemu-iotests/210.out b/tests/qemu-iotests/210.out | ||
60 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/tests/qemu-iotests/210.out | 13 | --- a/block.c |
62 | +++ b/tests/qemu-iotests/210.out | 14 | +++ b/block.c |
63 | @@ -XXX,XX +XXX,XX @@ QMP_VERSION | 15 | @@ -XXX,XX +XXX,XX @@ static int bdrv_fill_options(QDict **options, const char *filename, |
64 | {"return": {}} | 16 | return 0; |
65 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | 17 | } |
66 | 18 | ||
67 | + | 19 | -static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, |
68 | +=== Resize image with invalid sizes === | 20 | - uint64_t new_used_perm, |
69 | + | 21 | - uint64_t new_shared_perm, |
70 | +Testing: -blockdev driver=file,filename=TEST_DIR/t.IMGFMT,node-name=node0 -blockdev driver=IMGFMT,file=node0,key-secret=keysec0,node-name=node1 -object secret,id=keysec0,data=foo | 22 | - Error **errp); |
71 | +QMP_VERSION | 23 | - |
72 | +{"return": {}} | 24 | typedef struct BlockReopenQueueEntry { |
73 | +{"error": {"class": "GenericError", "desc": "The requested file size is too large"}} | 25 | bool prepared; |
74 | +{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'size', expected: integer"}} | 26 | bool perms_checked; |
75 | +{"error": {"class": "GenericError", "desc": "Invalid parameter type for 'size', expected: integer"}} | 27 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, |
76 | +{"error": {"class": "GenericError", "desc": "Parameter 'size' expects a >0 size"}} | 28 | return 0; |
77 | +{"return": {}} | 29 | } |
78 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | 30 | |
79 | + | 31 | -static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, |
80 | +image: json:{"driver": "IMGFMT", "file": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "key-secret": "keysec0"} | 32 | - uint64_t cumulative_perms, |
81 | +file format: IMGFMT | 33 | - uint64_t cumulative_shared_perms, Error **errp) |
82 | +virtual size: 0 (0 bytes) | 34 | -{ |
83 | *** done | 35 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); |
36 | - return bdrv_check_perm_common(list, q, true, cumulative_perms, | ||
37 | - cumulative_shared_perms, NULL, errp); | ||
38 | -} | ||
39 | - | ||
40 | static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | ||
41 | Transaction *tran, Error **errp) | ||
42 | { | ||
43 | return bdrv_check_perm_common(list, q, false, 0, 0, tran, errp); | ||
44 | } | ||
45 | |||
46 | -/* | ||
47 | - * Notifies drivers that after a previous bdrv_check_perm() call, the | ||
48 | - * permission update is not performed and any preparations made for it (e.g. | ||
49 | - * taken file locks) need to be undone. | ||
50 | - */ | ||
51 | -static void bdrv_node_abort_perm_update(BlockDriverState *bs) | ||
52 | -{ | ||
53 | - BlockDriver *drv = bs->drv; | ||
54 | - BdrvChild *c; | ||
55 | - | ||
56 | - if (!drv) { | ||
57 | - return; | ||
58 | - } | ||
59 | - | ||
60 | - bdrv_drv_set_perm_abort(bs); | ||
61 | - | ||
62 | - QLIST_FOREACH(c, &bs->children, next) { | ||
63 | - bdrv_child_set_perm_abort(c); | ||
64 | - } | ||
65 | -} | ||
66 | - | ||
67 | -static void bdrv_list_abort_perm_update(GSList *list) | ||
68 | -{ | ||
69 | - for ( ; list; list = list->next) { | ||
70 | - bdrv_node_abort_perm_update((BlockDriverState *)list->data); | ||
71 | - } | ||
72 | -} | ||
73 | - | ||
74 | -__attribute__((unused)) | ||
75 | -static void bdrv_abort_perm_update(BlockDriverState *bs) | ||
76 | -{ | ||
77 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); | ||
78 | - return bdrv_list_abort_perm_update(list); | ||
79 | -} | ||
80 | - | ||
81 | static void bdrv_node_set_perm(BlockDriverState *bs) | ||
82 | { | ||
83 | BlockDriver *drv = bs->drv; | ||
84 | @@ -XXX,XX +XXX,XX @@ char *bdrv_perm_names(uint64_t perm) | ||
85 | return g_string_free(result, FALSE); | ||
86 | } | ||
87 | |||
88 | -/* | ||
89 | - * Checks whether a new reference to @bs can be added if the new user requires | ||
90 | - * @new_used_perm/@new_shared_perm as its permissions. If @ignore_children is | ||
91 | - * set, the BdrvChild objects in this list are ignored in the calculations; | ||
92 | - * this allows checking permission updates for an existing reference. | ||
93 | - * | ||
94 | - * Needs to be followed by a call to either bdrv_set_perm() or | ||
95 | - * bdrv_abort_perm_update(). */ | ||
96 | -__attribute__((unused)) | ||
97 | -static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
98 | - uint64_t new_used_perm, | ||
99 | - uint64_t new_shared_perm, | ||
100 | - Error **errp) | ||
101 | -{ | ||
102 | - BdrvChild *c; | ||
103 | - uint64_t cumulative_perms = new_used_perm; | ||
104 | - uint64_t cumulative_shared_perms = new_shared_perm; | ||
105 | - | ||
106 | - | ||
107 | - /* There is no reason why anyone couldn't tolerate write_unchanged */ | ||
108 | - assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); | ||
109 | - | ||
110 | - QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
111 | - if ((new_used_perm & c->shared_perm) != new_used_perm) { | ||
112 | - char *user = bdrv_child_user_desc(c); | ||
113 | - char *perm_names = bdrv_perm_names(new_used_perm & ~c->shared_perm); | ||
114 | - | ||
115 | - error_setg(errp, "Conflicts with use by %s as '%s', which does not " | ||
116 | - "allow '%s' on %s", | ||
117 | - user, c->name, perm_names, bdrv_get_node_name(c->bs)); | ||
118 | - g_free(user); | ||
119 | - g_free(perm_names); | ||
120 | - return -EPERM; | ||
121 | - } | ||
122 | - | ||
123 | - if ((c->perm & new_shared_perm) != c->perm) { | ||
124 | - char *user = bdrv_child_user_desc(c); | ||
125 | - char *perm_names = bdrv_perm_names(c->perm & ~new_shared_perm); | ||
126 | - | ||
127 | - error_setg(errp, "Conflicts with use by %s as '%s', which uses " | ||
128 | - "'%s' on %s", | ||
129 | - user, c->name, perm_names, bdrv_get_node_name(c->bs)); | ||
130 | - g_free(user); | ||
131 | - g_free(perm_names); | ||
132 | - return -EPERM; | ||
133 | - } | ||
134 | - | ||
135 | - cumulative_perms |= c->perm; | ||
136 | - cumulative_shared_perms &= c->shared_perm; | ||
137 | - } | ||
138 | - | ||
139 | - return bdrv_check_perm(bs, q, cumulative_perms, cumulative_shared_perms, | ||
140 | - errp); | ||
141 | -} | ||
142 | |||
143 | static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) | ||
144 | { | ||
84 | -- | 145 | -- |
85 | 2.13.6 | 146 | 2.30.2 |
86 | 147 | ||
87 | 148 | diff view generated by jsdifflib |
1 | We want to test resizing even for luks. The only change that is needed | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | is to explicitly zero out new space for luks because it's undefined. | ||
3 | 2 | ||
3 | bdrv_check_perm_common() has only one caller, so no more sense in | ||
4 | "common". | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-33-vsementsov@virtuozzo.com> | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
5 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
7 | --- | 10 | --- |
8 | tests/qemu-iotests/025 | 9 ++++++++- | 11 | block.c | 32 +++----------------------------- |
9 | 1 file changed, 8 insertions(+), 1 deletion(-) | 12 | 1 file changed, 3 insertions(+), 29 deletions(-) |
10 | 13 | ||
11 | diff --git a/tests/qemu-iotests/025 b/tests/qemu-iotests/025 | 14 | diff --git a/block.c b/block.c |
12 | index XXXXXXX..XXXXXXX 100755 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tests/qemu-iotests/025 | 16 | --- a/block.c |
14 | +++ b/tests/qemu-iotests/025 | 17 | +++ b/block.c |
15 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 18 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, |
16 | . ./common.filter | 19 | return 0; |
17 | . ./common.pattern | 20 | } |
18 | 21 | ||
19 | -_supported_fmt raw qcow2 qed | 22 | -/* |
20 | +_supported_fmt raw qcow2 qed luks | 23 | - * If use_cumulative_perms is true, use cumulative_perms and |
21 | _supported_proto file sheepdog rbd nfs | 24 | - * cumulative_shared_perms for first element of the list. Otherwise just refresh |
22 | _supported_os Linux | 25 | - * all permissions. |
23 | 26 | - */ | |
24 | @@ -XXX,XX +XXX,XX @@ length | 27 | -static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, |
25 | EOF | 28 | - bool use_cumulative_perms, |
26 | _check_test_img | 29 | - uint64_t cumulative_perms, |
27 | 30 | - uint64_t cumulative_shared_perms, | |
28 | +# bdrv_truncate() doesn't zero the new space, so we need to do that explicitly. | 31 | - Transaction *tran, Error **errp) |
29 | +# We still want to test automatic zeroing for other formats even though | 32 | +static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, |
30 | +# bdrv_truncate() doesn't guarantee it. | 33 | + Transaction *tran, Error **errp) |
31 | +if [ "$IMGFMT" == "luks" ]; then | 34 | { |
32 | + $QEMU_IO -c "write -z $small_size $((big_size - small_size))" "$TEST_IMG" > /dev/null | 35 | int ret; |
33 | +fi | 36 | + uint64_t cumulative_perms, cumulative_shared_perms; |
34 | + | 37 | BlockDriverState *bs; |
35 | echo | 38 | |
36 | echo "=== Verifying image size after reopen" | 39 | - if (use_cumulative_perms) { |
37 | $QEMU_IO -c "length" "$TEST_IMG" | 40 | - bs = list->data; |
41 | - | ||
42 | - ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
43 | - cumulative_shared_perms, | ||
44 | - tran, errp); | ||
45 | - if (ret < 0) { | ||
46 | - return ret; | ||
47 | - } | ||
48 | - | ||
49 | - list = list->next; | ||
50 | - } | ||
51 | - | ||
52 | for ( ; list; list = list->next) { | ||
53 | bs = list->data; | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm_common(GSList *list, BlockReopenQueue *q, | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | -static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | ||
60 | - Transaction *tran, Error **errp) | ||
61 | -{ | ||
62 | - return bdrv_check_perm_common(list, q, false, 0, 0, tran, errp); | ||
63 | -} | ||
64 | - | ||
65 | static void bdrv_node_set_perm(BlockDriverState *bs) | ||
66 | { | ||
67 | BlockDriver *drv = bs->drv; | ||
38 | -- | 68 | -- |
39 | 2.13.6 | 69 | 2.30.2 |
40 | 70 | ||
41 | 71 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | When we try to allocate new clusters we first look for available ones | 3 | bdrv_replace_child() has only one caller, the second argument is |
4 | starting from s->free_cluster_index and once we find them we increase | 4 | unused. Inline it now. This triggers deletion of some more unused |
5 | their reference counts. Before we get to call update_refcount() to do | 5 | interfaces. |
6 | this last step s->free_cluster_index is already pointing to the next | ||
7 | cluster after the ones we are trying to allocate. | ||
8 | 6 | ||
9 | During update_refcount() it may happen however that we also need to | 7 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
10 | allocate a new refcount block in order to store the refcounts of these | 8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
11 | new clusters (and to complicate things further that may also require | 9 | Message-Id: <20210428151804.439460-34-vsementsov@virtuozzo.com> |
12 | us to grow the refcount table). After all this we don't know if the | ||
13 | clusters that we originally tried to allocate are still available, so | ||
14 | we return -EAGAIN to ask the caller to restart the search for free | ||
15 | clusters. | ||
16 | |||
17 | This is what can happen in a common scenario: | ||
18 | |||
19 | 1) We want to allocate a new cluster and we see that cluster N is | ||
20 | free. | ||
21 | |||
22 | 2) We try to increase N's refcount but all refcount blocks are full, | ||
23 | so we allocate a new one at N+1 (where s->free_cluster_index was | ||
24 | pointing at). | ||
25 | |||
26 | 3) Once we're done we return -EAGAIN to look again for a free | ||
27 | cluster, but now s->free_cluster_index points at N+2, so that's | ||
28 | the one we allocate. Cluster N remains unallocated and we have a | ||
29 | hole in the qcow2 file. | ||
30 | |||
31 | This can be reproduced easily: | ||
32 | |||
33 | qemu-img create -f qcow2 -o cluster_size=512 hd.qcow2 1M | ||
34 | qemu-io -c 'write 0 124k' hd.qcow2 | ||
35 | |||
36 | After this the image has 132608 bytes (256 clusters), and the refcount | ||
37 | block is full. If we write 512 more bytes it should allocate two new | ||
38 | clusters: the data cluster itself and a new refcount block. | ||
39 | |||
40 | qemu-io -c 'write 124k 512' hd.qcow2 | ||
41 | |||
42 | However the image has now three new clusters (259 in total), and the | ||
43 | first one of them is empty (and unallocated): | ||
44 | |||
45 | dd if=hd.qcow2 bs=512c skip=256 count=1 | hexdump -C | ||
46 | |||
47 | If we write larger amounts of data in the last step instead of the 512 | ||
48 | bytes used in this example we can create larger holes in the qcow2 | ||
49 | file. | ||
50 | |||
51 | What this patch does is reset s->free_cluster_index to its previous | ||
52 | value when alloc_refcount_block() returns -EAGAIN. This way the caller | ||
53 | will try to allocate again the original clusters if they are still | ||
54 | free. | ||
55 | |||
56 | The output of iotest 026 also needs to be updated because now that | ||
57 | images have no holes some tests fail at a different point and the | ||
58 | number of leaked clusters is different. | ||
59 | |||
60 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
61 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
62 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
63 | --- | 11 | --- |
64 | block/qcow2-refcount.c | 7 +++++++ | 12 | block.c | 101 ++++++++++---------------------------------------------- |
65 | tests/qemu-iotests/026.out | 6 +++--- | 13 | 1 file changed, 18 insertions(+), 83 deletions(-) |
66 | tests/qemu-iotests/121 | 20 ++++++++++++++++++++ | ||
67 | tests/qemu-iotests/121.out | 10 ++++++++++ | ||
68 | 4 files changed, 40 insertions(+), 3 deletions(-) | ||
69 | 14 | ||
70 | diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c | 15 | diff --git a/block.c b/block.c |
71 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
72 | --- a/block/qcow2-refcount.c | 17 | --- a/block.c |
73 | +++ b/block/qcow2-refcount.c | 18 | +++ b/block.c |
74 | @@ -XXX,XX +XXX,XX @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, | 19 | @@ -XXX,XX +XXX,XX @@ static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, |
75 | qcow2_cache_put(s->refcount_block_cache, &refcount_block); | 20 | return 0; |
76 | } | 21 | } |
77 | ret = alloc_refcount_block(bs, cluster_index, &refcount_block); | 22 | |
78 | + /* If the caller needs to restart the search for free clusters, | 23 | -static void bdrv_node_set_perm(BlockDriverState *bs) |
79 | + * try the same ones first to see if they're still free. */ | 24 | -{ |
80 | + if (ret == -EAGAIN) { | 25 | - BlockDriver *drv = bs->drv; |
81 | + if (s->free_cluster_index > (start >> s->cluster_bits)) { | 26 | - BdrvChild *c; |
82 | + s->free_cluster_index = (start >> s->cluster_bits); | 27 | - |
83 | + } | 28 | - if (!drv) { |
84 | + } | 29 | - return; |
85 | if (ret < 0) { | 30 | - } |
86 | goto fail; | 31 | - |
87 | } | 32 | - bdrv_drv_set_perm_commit(bs); |
88 | diff --git a/tests/qemu-iotests/026.out b/tests/qemu-iotests/026.out | 33 | - |
89 | index XXXXXXX..XXXXXXX 100644 | 34 | - /* Drivers that never have children can omit .bdrv_child_perm() */ |
90 | --- a/tests/qemu-iotests/026.out | 35 | - if (!drv->bdrv_child_perm) { |
91 | +++ b/tests/qemu-iotests/026.out | 36 | - assert(QLIST_EMPTY(&bs->children)); |
92 | @@ -XXX,XX +XXX,XX @@ Failed to flush the L2 table cache: No space left on device | 37 | - return; |
93 | Failed to flush the refcount block cache: No space left on device | 38 | - } |
94 | write failed: No space left on device | 39 | - |
95 | 40 | - /* Update all children */ | |
96 | -11 leaked clusters were found on the image. | 41 | - QLIST_FOREACH(c, &bs->children, next) { |
97 | +10 leaked clusters were found on the image. | 42 | - bdrv_child_set_perm_commit(c); |
98 | This means waste of disk space, but no harm to data. | 43 | - } |
99 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | 44 | -} |
100 | 45 | - | |
101 | @@ -XXX,XX +XXX,XX @@ Failed to flush the L2 table cache: No space left on device | 46 | -static void bdrv_list_set_perm(GSList *list) |
102 | Failed to flush the refcount block cache: No space left on device | 47 | -{ |
103 | write failed: No space left on device | 48 | - for ( ; list; list = list->next) { |
104 | 49 | - bdrv_node_set_perm((BlockDriverState *)list->data); | |
105 | -11 leaked clusters were found on the image. | 50 | - } |
106 | +10 leaked clusters were found on the image. | 51 | -} |
107 | This means waste of disk space, but no harm to data. | 52 | - |
108 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | 53 | -static void bdrv_set_perm(BlockDriverState *bs) |
109 | 54 | -{ | |
110 | @@ -XXX,XX +XXX,XX @@ Failed to flush the L2 table cache: No space left on device | 55 | - g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); |
111 | Failed to flush the refcount block cache: No space left on device | 56 | - return bdrv_list_set_perm(list); |
112 | write failed: No space left on device | 57 | -} |
113 | 58 | - | |
114 | -11 leaked clusters were found on the image. | 59 | void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, |
115 | +10 leaked clusters were found on the image. | 60 | uint64_t *shared_perm) |
116 | This means waste of disk space, but no harm to data. | 61 | { |
117 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | 62 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, |
118 | 63 | } | |
119 | diff --git a/tests/qemu-iotests/121 b/tests/qemu-iotests/121 | 64 | } |
120 | index XXXXXXX..XXXXXXX 100755 | 65 | |
121 | --- a/tests/qemu-iotests/121 | 66 | -/* |
122 | +++ b/tests/qemu-iotests/121 | 67 | - * Updates @child to change its reference to point to @new_bs, including |
123 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c 'write 63M 130K' "$TEST_IMG" | _filter_qemu_io | 68 | - * checking and applying the necessary permission updates both to the old node |
124 | 69 | - * and to @new_bs. | |
125 | _check_test_img | 70 | - * |
126 | 71 | - * NULL is passed as @new_bs for removing the reference before freeing @child. | |
127 | +echo | 72 | - * |
128 | +echo '=== Allocating a new refcount block must not leave holes in the image ===' | 73 | - * If @new_bs is not NULL, bdrv_check_perm() must be called beforehand, as this |
129 | +echo | 74 | - * function uses bdrv_set_perm() to update the permissions according to the new |
75 | - * reference that @new_bs gets. | ||
76 | - * | ||
77 | - * Callers must ensure that child->frozen is false. | ||
78 | - */ | ||
79 | -static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) | ||
80 | -{ | ||
81 | - BlockDriverState *old_bs = child->bs; | ||
82 | - | ||
83 | - /* Asserts that child->frozen == false */ | ||
84 | - bdrv_replace_child_noperm(child, new_bs); | ||
85 | - | ||
86 | - /* | ||
87 | - * Start with the new node's permissions. If @new_bs is a (direct | ||
88 | - * or indirect) child of @old_bs, we must complete the permission | ||
89 | - * update on @new_bs before we loosen the restrictions on @old_bs. | ||
90 | - * Otherwise, bdrv_check_perm() on @old_bs would re-initiate | ||
91 | - * updating the permissions of @new_bs, and thus not purely loosen | ||
92 | - * restrictions. | ||
93 | - */ | ||
94 | - if (new_bs) { | ||
95 | - bdrv_set_perm(new_bs); | ||
96 | - } | ||
97 | - | ||
98 | - if (old_bs) { | ||
99 | - /* | ||
100 | - * Update permissions for old node. We're just taking a parent away, so | ||
101 | - * we're loosening restrictions. Errors of permission update are not | ||
102 | - * fatal in this case, ignore them. | ||
103 | - */ | ||
104 | - bdrv_refresh_perms(old_bs, NULL); | ||
105 | - | ||
106 | - /* When the parent requiring a non-default AioContext is removed, the | ||
107 | - * node moves back to the main AioContext */ | ||
108 | - bdrv_try_set_aio_context(old_bs, qemu_get_aio_context(), NULL); | ||
109 | - } | ||
110 | -} | ||
111 | - | ||
112 | static void bdrv_child_free(void *opaque) | ||
113 | { | ||
114 | BdrvChild *c = opaque; | ||
115 | @@ -XXX,XX +XXX,XX @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, | ||
116 | |||
117 | static void bdrv_detach_child(BdrvChild *child) | ||
118 | { | ||
119 | - bdrv_replace_child(child, NULL); | ||
120 | + BlockDriverState *old_bs = child->bs; | ||
130 | + | 121 | + |
131 | +IMGOPTS='cluster_size=512,refcount_bits=16' _make_test_img 1M | 122 | + bdrv_replace_child_noperm(child, NULL); |
123 | bdrv_remove_empty_child(child); | ||
132 | + | 124 | + |
133 | +# This results in an image with 256 used clusters: the qcow2 header, | 125 | + if (old_bs) { |
134 | +# the refcount table, one refcount block, the L1 table, four L2 tables | 126 | + /* |
135 | +# and 248 data clusters | 127 | + * Update permissions for old node. We're just taking a parent away, so |
136 | +$QEMU_IO -c 'write 0 124k' "$TEST_IMG" | _filter_qemu_io | 128 | + * we're loosening restrictions. Errors of permission update are not |
129 | + * fatal in this case, ignore them. | ||
130 | + */ | ||
131 | + bdrv_refresh_perms(old_bs, NULL); | ||
137 | + | 132 | + |
138 | +# 256 clusters of 512 bytes each give us a 128K image | 133 | + /* |
139 | +stat -c "size=%s (expected 131072)" $TEST_IMG | 134 | + * When the parent requiring a non-default AioContext is removed, the |
140 | + | 135 | + * node moves back to the main AioContext |
141 | +# All 256 entries of the refcount block are used, so writing a new | 136 | + */ |
142 | +# data cluster also allocates a new refcount block | 137 | + bdrv_try_set_aio_context(old_bs, qemu_get_aio_context(), NULL); |
143 | +$QEMU_IO -c 'write 124k 512' "$TEST_IMG" | _filter_qemu_io | 138 | + } |
144 | + | 139 | } |
145 | +# Two more clusters, the image size should be 129K now | 140 | |
146 | +stat -c "size=%s (expected 132096)" $TEST_IMG | 141 | /* |
147 | |||
148 | # success, all done | ||
149 | echo | ||
150 | diff --git a/tests/qemu-iotests/121.out b/tests/qemu-iotests/121.out | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/tests/qemu-iotests/121.out | ||
153 | +++ b/tests/qemu-iotests/121.out | ||
154 | @@ -XXX,XX +XXX,XX @@ wrote 133120/133120 bytes at offset 66060288 | ||
155 | 130 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
156 | No errors were found on the image. | ||
157 | |||
158 | +=== Allocating a new refcount block must not leave holes in the image === | ||
159 | + | ||
160 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 | ||
161 | +wrote 126976/126976 bytes at offset 0 | ||
162 | +124 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
163 | +size=131072 (expected 131072) | ||
164 | +wrote 512/512 bytes at offset 126976 | ||
165 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
166 | +size=132096 (expected 132096) | ||
167 | + | ||
168 | *** done | ||
169 | -- | 142 | -- |
170 | 2.13.6 | 143 | 2.30.2 |
171 | 144 | ||
172 | 145 | diff view generated by jsdifflib |
1 | From: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Clarify that: | 3 | Old interfaces dropped, nobody directly calls |
4 | bdrv_child_set_perm_abort() and bdrv_child_set_perm_commit(), so we can | ||
5 | use personal state structure for the action and stop exploiting | ||
6 | BdrvChild structure. Also, drop "_safe" suffix which is redundant now. | ||
4 | 7 | ||
5 | - for protocols the brdv_file_open function is used instead | 8 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
6 | of bdrv_open; | 9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
7 | 10 | Message-Id: <20210428151804.439460-35-vsementsov@virtuozzo.com> | |
8 | - when protocol_name is set, a driver should expect | ||
9 | to be given only a filename and no other options. | ||
10 | |||
11 | Signed-off-by: Fabiano Rosas <farosas@linux.vnet.ibm.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
13 | --- | 12 | --- |
14 | include/block/block_int.h | 8 ++++++++ | 13 | include/block/block_int.h | 5 ---- |
15 | 1 file changed, 8 insertions(+) | 14 | block.c | 63 ++++++++++++++------------------------- |
15 | 2 files changed, 22 insertions(+), 46 deletions(-) | ||
16 | 16 | ||
17 | diff --git a/include/block/block_int.h b/include/block/block_int.h | 17 | diff --git a/include/block/block_int.h b/include/block/block_int.h |
18 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/block/block_int.h | 19 | --- a/include/block/block_int.h |
20 | +++ b/include/block/block_int.h | 20 | +++ b/include/block/block_int.h |
21 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | 21 | @@ -XXX,XX +XXX,XX @@ struct BdrvChild { |
22 | 22 | */ | |
23 | int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags, | 23 | uint64_t shared_perm; |
24 | Error **errp); | 24 | |
25 | - /* backup of permissions during permission update procedure */ | ||
26 | - bool has_backup_perm; | ||
27 | - uint64_t backup_perm; | ||
28 | - uint64_t backup_shared_perm; | ||
29 | - | ||
30 | /* | ||
31 | * This link is frozen: the child can neither be replaced nor | ||
32 | * detached from the parent. | ||
33 | diff --git a/block.c b/block.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/block.c | ||
36 | +++ b/block.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static GSList *bdrv_topological_dfs(GSList *list, GHashTable *found, | ||
38 | return g_slist_prepend(list, bs); | ||
39 | } | ||
40 | |||
41 | -static void bdrv_child_set_perm_commit(void *opaque) | ||
42 | -{ | ||
43 | - BdrvChild *c = opaque; | ||
44 | - | ||
45 | - c->has_backup_perm = false; | ||
46 | -} | ||
47 | +typedef struct BdrvChildSetPermState { | ||
48 | + BdrvChild *child; | ||
49 | + uint64_t old_perm; | ||
50 | + uint64_t old_shared_perm; | ||
51 | +} BdrvChildSetPermState; | ||
52 | |||
53 | static void bdrv_child_set_perm_abort(void *opaque) | ||
54 | { | ||
55 | - BdrvChild *c = opaque; | ||
56 | - /* | ||
57 | - * We may have child->has_backup_perm unset at this point, as in case of | ||
58 | - * _check_ stage of permission update failure we may _check_ not the whole | ||
59 | - * subtree. Still, _abort_ is called on the whole subtree anyway. | ||
60 | - */ | ||
61 | - if (c->has_backup_perm) { | ||
62 | - c->perm = c->backup_perm; | ||
63 | - c->shared_perm = c->backup_shared_perm; | ||
64 | - c->has_backup_perm = false; | ||
65 | - } | ||
66 | + BdrvChildSetPermState *s = opaque; | ||
25 | + | 67 | + |
26 | + /* Protocol drivers should implement this instead of bdrv_open */ | 68 | + s->child->perm = s->old_perm; |
27 | int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, | 69 | + s->child->shared_perm = s->old_shared_perm; |
28 | Error **errp); | 70 | } |
29 | void (*bdrv_close)(BlockDriverState *bs); | 71 | |
30 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | 72 | static TransactionActionDrv bdrv_child_set_pem_drv = { |
31 | */ | 73 | .abort = bdrv_child_set_perm_abort, |
32 | int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); | 74 | - .commit = bdrv_child_set_perm_commit, |
33 | 75 | + .clean = g_free, | |
34 | + /* | 76 | }; |
35 | + * Drivers setting this field must be able to work with just a plain | 77 | |
36 | + * filename with '<protocol_name>:' as a prefix, and no other options. | 78 | -/* |
37 | + * Options may be extracted from the filename by implementing | 79 | - * With tran=NULL needs to be followed by direct call to either |
38 | + * bdrv_parse_filename. | 80 | - * bdrv_child_set_perm_commit() or bdrv_child_set_perm_abort(). |
39 | + */ | 81 | - * |
40 | const char *protocol_name; | 82 | - * With non-NULL tran needs to be followed by tran_abort() or tran_commit() |
41 | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, | 83 | - * instead. |
42 | PreallocMode prealloc, Error **errp); | 84 | - */ |
85 | -static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm, | ||
86 | - uint64_t shared, Transaction *tran) | ||
87 | +static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, | ||
88 | + uint64_t shared, Transaction *tran) | ||
89 | { | ||
90 | - if (!c->has_backup_perm) { | ||
91 | - c->has_backup_perm = true; | ||
92 | - c->backup_perm = c->perm; | ||
93 | - c->backup_shared_perm = c->shared_perm; | ||
94 | - } | ||
95 | - /* | ||
96 | - * Note: it's OK if c->has_backup_perm was already set, as we can find the | ||
97 | - * same c twice during check_perm procedure | ||
98 | - */ | ||
99 | + BdrvChildSetPermState *s = g_new(BdrvChildSetPermState, 1); | ||
100 | + | ||
101 | + *s = (BdrvChildSetPermState) { | ||
102 | + .child = c, | ||
103 | + .old_perm = c->perm, | ||
104 | + .old_shared_perm = c->shared_perm, | ||
105 | + }; | ||
106 | |||
107 | c->perm = perm; | ||
108 | c->shared_perm = shared; | ||
109 | |||
110 | - if (tran) { | ||
111 | - tran_add(tran, &bdrv_child_set_pem_drv, c); | ||
112 | - } | ||
113 | + tran_add(tran, &bdrv_child_set_pem_drv, s); | ||
114 | } | ||
115 | |||
116 | static void bdrv_drv_set_perm_commit(void *opaque) | ||
117 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
118 | bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
119 | cumulative_perms, cumulative_shared_perms, | ||
120 | &cur_perm, &cur_shared); | ||
121 | - bdrv_child_set_perm_safe(c, cur_perm, cur_shared, tran); | ||
122 | + bdrv_child_set_perm(c, cur_perm, cur_shared, tran); | ||
123 | } | ||
124 | |||
125 | return 0; | ||
126 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
127 | Transaction *tran = tran_new(); | ||
128 | int ret; | ||
129 | |||
130 | - bdrv_child_set_perm_safe(c, perm, shared, tran); | ||
131 | + bdrv_child_set_perm(c, perm, shared, tran); | ||
132 | |||
133 | ret = bdrv_refresh_perms(c->bs, &local_err); | ||
134 | |||
43 | -- | 135 | -- |
44 | 2.13.6 | 136 | 2.30.2 |
45 | 137 | ||
46 | 138 | diff view generated by jsdifflib |
1 | It's unclear what the real maximum cluster size is for the Parallels | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | format, but let's at least make sure that we don't get integer | ||
3 | overflows in our .bdrv_co_create implementation. | ||
4 | 2 | ||
3 | We don't have bdrv_replace_child(), so it's time for | ||
4 | bdrv_replace_child_safe() to take its place. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Message-Id: <20210428151804.439460-36-vsementsov@virtuozzo.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
7 | --- | 10 | --- |
8 | block/parallels.c | 5 +++++ | 11 | block.c | 10 +++++----- |
9 | 1 file changed, 5 insertions(+) | 12 | 1 file changed, 5 insertions(+), 5 deletions(-) |
10 | 13 | ||
11 | diff --git a/block/parallels.c b/block/parallels.c | 14 | diff --git a/block.c b/block.c |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/block/parallels.c | 16 | --- a/block.c |
14 | +++ b/block/parallels.c | 17 | +++ b/block.c |
15 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, | 18 | @@ -XXX,XX +XXX,XX @@ static TransactionActionDrv bdrv_replace_child_drv = { |
16 | cl_size = DEFAULT_CLUSTER_SIZE; | 19 | }; |
20 | |||
21 | /* | ||
22 | - * bdrv_replace_child_safe | ||
23 | + * bdrv_replace_child | ||
24 | * | ||
25 | * Note: real unref of old_bs is done only on commit. | ||
26 | */ | ||
27 | -static void bdrv_replace_child_safe(BdrvChild *child, BlockDriverState *new_bs, | ||
28 | - Transaction *tran) | ||
29 | +static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs, | ||
30 | + Transaction *tran) | ||
31 | { | ||
32 | BdrvReplaceChildState *s = g_new(BdrvReplaceChildState, 1); | ||
33 | *s = (BdrvReplaceChildState) { | ||
34 | @@ -XXX,XX +XXX,XX @@ static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, | ||
17 | } | 35 | } |
18 | 36 | ||
19 | + /* XXX What is the real limit here? This is an insanely large maximum. */ | 37 | if (child->bs) { |
20 | + if (cl_size >= INT64_MAX / MAX_PARALLELS_IMAGE_FACTOR) { | 38 | - bdrv_replace_child_safe(child, NULL, tran); |
21 | + error_setg(errp, "Cluster size is too large"); | 39 | + bdrv_replace_child(child, NULL, tran); |
22 | + return -EINVAL; | 40 | } |
23 | + } | 41 | |
24 | if (total_size >= MAX_PARALLELS_IMAGE_FACTOR * cl_size) { | 42 | s = g_new(BdrvRemoveFilterOrCowChild, 1); |
25 | error_setg(errp, "Image size is too large for this cluster size"); | 43 | @@ -XXX,XX +XXX,XX @@ static int bdrv_replace_node_noperm(BlockDriverState *from, |
26 | return -E2BIG; | 44 | c->name, from->node_name); |
45 | return -EPERM; | ||
46 | } | ||
47 | - bdrv_replace_child_safe(c, to, tran); | ||
48 | + bdrv_replace_child(c, to, tran); | ||
49 | } | ||
50 | |||
51 | return 0; | ||
27 | -- | 52 | -- |
28 | 2.13.6 | 53 | 2.30.2 |
29 | 54 | ||
30 | 55 | diff view generated by jsdifflib |
1 | From: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | The blkreplay driver is not a protocol so it should implement bdrv_open | 3 | Now, bdrv_node_check_perm() is called only with fresh cumulative |
4 | instead of bdrv_file_open and not provide a protocol_name. | 4 | permissions, so its actually "refresh_perm". |
5 | 5 | ||
6 | Attempts to invoke this driver using protocol syntax | 6 | Move permission calculation to the function. Also, drop unreachable |
7 | (i.e. blkreplay:<filename:options:...>) will now fail gracefully: | 7 | error message and rewrite the remaining one to be more generic (as now |
8 | we don't know which node is added and which was already here). | ||
8 | 9 | ||
9 | $ qemu-img info blkreplay:foo | 10 | Add also Virtuozzo copyright, as big work is done at this point. |
10 | qemu-img: Could not open 'blkreplay:foo': Unknown protocol 'blkreplay' | ||
11 | 11 | ||
12 | Signed-off-by: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
13 | Reviewed-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru> | 13 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
14 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 14 | Message-Id: <20210428151804.439460-37-vsementsov@virtuozzo.com> |
15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
16 | --- | 16 | --- |
17 | block/blkreplay.c | 3 +-- | 17 | block.c | 38 +++++++++++--------------------------- |
18 | 1 file changed, 1 insertion(+), 2 deletions(-) | 18 | tests/qemu-iotests/245 | 2 +- |
19 | 2 files changed, 12 insertions(+), 28 deletions(-) | ||
19 | 20 | ||
20 | diff --git a/block/blkreplay.c b/block/blkreplay.c | 21 | diff --git a/block.c b/block.c |
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/block.c | ||
24 | +++ b/block.c | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | * QEMU System Emulator block driver | ||
27 | * | ||
28 | * Copyright (c) 2003 Fabrice Bellard | ||
29 | + * Copyright (c) 2020 Virtuozzo International GmbH. | ||
30 | * | ||
31 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
32 | * of this software and associated documentation files (the "Software"), to deal | ||
33 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs, | ||
34 | } | ||
35 | |||
36 | /* | ||
37 | - * Check whether permissions on this node can be changed in a way that | ||
38 | - * @cumulative_perms and @cumulative_shared_perms are the new cumulative | ||
39 | - * permissions of all its parents. This involves checking whether all necessary | ||
40 | - * permission changes to child nodes can be performed. | ||
41 | - * | ||
42 | - * A call to this function must always be followed by a call to bdrv_set_perm() | ||
43 | - * or bdrv_abort_perm_update(). | ||
44 | + * Refresh permissions in @bs subtree. The function is intended to be called | ||
45 | + * after some graph modification that was done without permission update. | ||
46 | */ | ||
47 | -static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
48 | - uint64_t cumulative_perms, | ||
49 | - uint64_t cumulative_shared_perms, | ||
50 | - Transaction *tran, Error **errp) | ||
51 | +static int bdrv_node_refresh_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
52 | + Transaction *tran, Error **errp) | ||
53 | { | ||
54 | BlockDriver *drv = bs->drv; | ||
55 | BdrvChild *c; | ||
56 | int ret; | ||
57 | + uint64_t cumulative_perms, cumulative_shared_perms; | ||
58 | + | ||
59 | + bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms); | ||
60 | |||
61 | /* Write permissions never work with read-only images */ | ||
62 | if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && | ||
63 | @@ -XXX,XX +XXX,XX @@ static int bdrv_node_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
64 | if (!bdrv_is_writable_after_reopen(bs, NULL)) { | ||
65 | error_setg(errp, "Block node is read-only"); | ||
66 | } else { | ||
67 | - uint64_t current_perms, current_shared; | ||
68 | - bdrv_get_cumulative_perm(bs, ¤t_perms, ¤t_shared); | ||
69 | - if (current_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) { | ||
70 | - error_setg(errp, "Cannot make block node read-only, there is " | ||
71 | - "a writer on it"); | ||
72 | - } else { | ||
73 | - error_setg(errp, "Cannot make block node read-only and create " | ||
74 | - "a writer on it"); | ||
75 | - } | ||
76 | + error_setg(errp, "Read-only block node '%s' cannot support " | ||
77 | + "read-write users", bdrv_get_node_name(bs)); | ||
78 | } | ||
79 | |||
80 | return -EPERM; | ||
81 | @@ -XXX,XX +XXX,XX @@ static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | ||
82 | Transaction *tran, Error **errp) | ||
83 | { | ||
84 | int ret; | ||
85 | - uint64_t cumulative_perms, cumulative_shared_perms; | ||
86 | BlockDriverState *bs; | ||
87 | |||
88 | for ( ; list; list = list->next) { | ||
89 | @@ -XXX,XX +XXX,XX @@ static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q, | ||
90 | return -EINVAL; | ||
91 | } | ||
92 | |||
93 | - bdrv_get_cumulative_perm(bs, &cumulative_perms, | ||
94 | - &cumulative_shared_perms); | ||
95 | - | ||
96 | - ret = bdrv_node_check_perm(bs, q, cumulative_perms, | ||
97 | - cumulative_shared_perms, | ||
98 | - tran, errp); | ||
99 | + ret = bdrv_node_refresh_perm(bs, q, tran, errp); | ||
100 | if (ret < 0) { | ||
101 | return ret; | ||
102 | } | ||
103 | diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 | ||
21 | index XXXXXXX..XXXXXXX 100755 | 104 | index XXXXXXX..XXXXXXX 100755 |
22 | --- a/block/blkreplay.c | 105 | --- a/tests/qemu-iotests/245 |
23 | +++ b/block/blkreplay.c | 106 | +++ b/tests/qemu-iotests/245 |
24 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs) | 107 | @@ -XXX,XX +XXX,XX @@ class TestBlockdevReopen(iotests.QMPTestCase): |
25 | 108 | # We can't reopen hd1 to read-only, as block-stream requires it to be | |
26 | static BlockDriver bdrv_blkreplay = { | 109 | # read-write |
27 | .format_name = "blkreplay", | 110 | self.reopen(opts['backing'], {'read-only': True}, |
28 | - .protocol_name = "blkreplay", | 111 | - "Cannot make block node read-only, there is a writer on it") |
29 | .instance_size = 0, | 112 | + "Read-only block node 'hd1' cannot support read-write users") |
30 | 113 | ||
31 | - .bdrv_file_open = blkreplay_open, | 114 | # We can't remove hd2 while the stream job is ongoing |
32 | + .bdrv_open = blkreplay_open, | 115 | opts['backing']['backing'] = None |
33 | .bdrv_close = blkreplay_close, | ||
34 | .bdrv_child_perm = bdrv_filter_default_perms, | ||
35 | .bdrv_getlength = blkreplay_getlength, | ||
36 | -- | 116 | -- |
37 | 2.13.6 | 117 | 2.30.2 |
38 | 118 | ||
39 | 119 | diff view generated by jsdifflib |
1 | Commit e39e959e fixed an invalid assertion in the .bdrv_length | 1 | Normally, blk_new_open() just shares all permissions. This was fine |
---|---|---|---|
2 | implementation, but left a similar assertion in place for | 2 | originally when permissions only protected against uses in the same |
3 | .bdrv_truncate. Instead of crashing when the user requests a too large | 3 | process because no other part of the code would actually get to access |
4 | image size, fail gracefully. | 4 | the block nodes opened with blk_new_open(). However, since we use it for |
5 | file locking now, unsharing permissions becomes desirable. | ||
5 | 6 | ||
6 | A file size of exactly INT64_MAX caused failure before, but is actually | 7 | Add a new BDRV_O_NO_SHARE flag that is used in blk_new_open() to unshare |
7 | legal. | 8 | any permissions that can be unshared. |
8 | 9 | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | Message-Id: <20210422164344.283389-2-kwolf@redhat.com> | ||
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | 12 | Reviewed-by: Eric Blake <eblake@redhat.com> |
11 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | 13 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | 15 | --- |
13 | block/crypto.c | 6 +++++- | 16 | include/block/block.h | 1 + |
14 | 1 file changed, 5 insertions(+), 1 deletion(-) | 17 | block/block-backend.c | 19 +++++++++++++------ |
18 | 2 files changed, 14 insertions(+), 6 deletions(-) | ||
15 | 19 | ||
16 | diff --git a/block/crypto.c b/block/crypto.c | 20 | diff --git a/include/block/block.h b/include/block/block.h |
17 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/crypto.c | 22 | --- a/include/block/block.h |
19 | +++ b/block/crypto.c | 23 | +++ b/include/block/block.h |
20 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_truncate(BlockDriverState *bs, int64_t offset, | 24 | @@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry { |
21 | BlockCrypto *crypto = bs->opaque; | 25 | uint32_t cylinders; |
22 | uint64_t payload_offset = | 26 | } HDGeometry; |
23 | qcrypto_block_get_payload_offset(crypto->block); | 27 | |
24 | - assert(payload_offset < (INT64_MAX - offset)); | 28 | +#define BDRV_O_NO_SHARE 0x0001 /* don't share permissions */ |
25 | + | 29 | #define BDRV_O_RDWR 0x0002 |
26 | + if (payload_offset > INT64_MAX - offset) { | 30 | #define BDRV_O_RESIZE 0x0004 /* request permission for resizing the node */ |
27 | + error_setg(errp, "The requested file size is too large"); | 31 | #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */ |
28 | + return -EFBIG; | 32 | diff --git a/block/block-backend.c b/block/block-backend.c |
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/block/block-backend.c | ||
35 | +++ b/block/block-backend.c | ||
36 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, | ||
37 | BlockBackend *blk; | ||
38 | BlockDriverState *bs; | ||
39 | uint64_t perm = 0; | ||
40 | + uint64_t shared = BLK_PERM_ALL; | ||
41 | |||
42 | - /* blk_new_open() is mainly used in .bdrv_create implementations and the | ||
43 | - * tools where sharing isn't a concern because the BDS stays private, so we | ||
44 | - * just request permission according to the flags. | ||
45 | + /* | ||
46 | + * blk_new_open() is mainly used in .bdrv_create implementations and the | ||
47 | + * tools where sharing isn't a major concern because the BDS stays private | ||
48 | + * and the file is generally not supposed to be used by a second process, | ||
49 | + * so we just request permission according to the flags. | ||
50 | * | ||
51 | * The exceptions are xen_disk and blockdev_init(); in these cases, the | ||
52 | * caller of blk_new_open() doesn't make use of the permissions, but they | ||
53 | * shouldn't hurt either. We can still share everything here because the | ||
54 | - * guest devices will add their own blockers if they can't share. */ | ||
55 | + * guest devices will add their own blockers if they can't share. | ||
56 | + */ | ||
57 | if ((flags & BDRV_O_NO_IO) == 0) { | ||
58 | perm |= BLK_PERM_CONSISTENT_READ; | ||
59 | if (flags & BDRV_O_RDWR) { | ||
60 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, | ||
61 | if (flags & BDRV_O_RESIZE) { | ||
62 | perm |= BLK_PERM_RESIZE; | ||
63 | } | ||
64 | + if (flags & BDRV_O_NO_SHARE) { | ||
65 | + shared = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED; | ||
29 | + } | 66 | + } |
30 | 67 | ||
31 | offset += payload_offset; | 68 | - blk = blk_new(qemu_get_aio_context(), perm, BLK_PERM_ALL); |
32 | 69 | + blk = blk_new(qemu_get_aio_context(), perm, shared); | |
70 | bs = bdrv_open(filename, reference, options, flags, errp); | ||
71 | if (!bs) { | ||
72 | blk_unref(blk); | ||
73 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, | ||
74 | |||
75 | blk->root = bdrv_root_attach_child(bs, "root", &child_root, | ||
76 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
77 | - perm, BLK_PERM_ALL, blk, errp); | ||
78 | + perm, shared, blk, errp); | ||
79 | if (!blk->root) { | ||
80 | blk_unref(blk); | ||
81 | return NULL; | ||
33 | -- | 82 | -- |
34 | 2.13.6 | 83 | 2.30.2 |
35 | 84 | ||
36 | 85 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | For a successful conversion of an image, we must make sure that its |
---|---|---|---|
2 | content doesn't change during the conversion. | ||
2 | 3 | ||
3 | Testing on ext4, most 'quick' qcow2 tests took less than 5 seconds, | 4 | A special case of this is using the same image file both as the source |
4 | but 163 took more than 20. Let's remove it from the quick set. | 5 | and as the destination. If both input and output format are raw, the |
6 | operation would just be useless work, with other formats it is a sure | ||
7 | way to destroy the image. This will now fail because the image file | ||
8 | can't be opened a second time for the output when opening it for the | ||
9 | input has already acquired file locks to unshare BLK_PERM_WRITE. | ||
5 | 10 | ||
6 | Signed-off-by: Eric Blake <eblake@redhat.com> | 11 | Nevertheless, if there is some reason in a special case why it is |
12 | actually okay to allow writes to the image while it is being converted, | ||
13 | -U can still be used to force sharing all permissions. | ||
14 | |||
15 | Note that for most image formats, BLK_PERM_WRITE would already be | ||
16 | unshared by the format driver, so this only really makes a difference | ||
17 | for raw source images (but any output format). | ||
18 | |||
19 | Reported-by: Xueqiang Wei <xuwei@redhat.com> | ||
20 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
21 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
22 | Message-Id: <20210422164344.283389-3-kwolf@redhat.com> | ||
23 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 24 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
8 | --- | 25 | --- |
9 | tests/qemu-iotests/group | 2 +- | 26 | qemu-img.c | 2 +- |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 27 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 28 | ||
12 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | 29 | diff --git a/qemu-img.c b/qemu-img.c |
13 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tests/qemu-iotests/group | 31 | --- a/qemu-img.c |
15 | +++ b/tests/qemu-iotests/group | 32 | +++ b/qemu-img.c |
16 | @@ -XXX,XX +XXX,XX @@ | 33 | @@ -XXX,XX +XXX,XX @@ static void set_rate_limit(BlockBackend *blk, int64_t rate_limit) |
17 | 159 rw auto quick | 34 | |
18 | 160 rw auto quick | 35 | static int img_convert(int argc, char **argv) |
19 | 162 auto quick | 36 | { |
20 | -163 rw auto quick | 37 | - int c, bs_i, flags, src_flags = 0; |
21 | +163 rw auto | 38 | + int c, bs_i, flags, src_flags = BDRV_O_NO_SHARE; |
22 | 165 rw auto quick | 39 | const char *fmt = NULL, *out_fmt = NULL, *cache = "unsafe", |
23 | 169 rw auto quick | 40 | *src_cache = BDRV_DEFAULT_CACHE, *out_baseimg = NULL, |
24 | 170 rw auto quick | 41 | *out_filename, *out_baseimg_param, *snapshot_name = NULL; |
25 | -- | 42 | -- |
26 | 2.13.6 | 43 | 2.30.2 |
27 | 44 | ||
28 | 45 | diff view generated by jsdifflib |
1 | From: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 1 | virtio_add_queue() aborts when queue_size > VIRTQUEUE_MAX_SIZE, so |
---|---|---|---|
2 | vhost_user_blk_device_realize() should check this before calling it. | ||
2 | 3 | ||
3 | The protocol_name field is used when selecting a driver via protocol | 4 | Simple reproducer: |
4 | syntax (i.e. <protocol_name>:<filename:options:...>). Drivers that are | ||
5 | only selected explicitly (e.g. driver=replication,mode=primary,...) | ||
6 | should not have a protocol_name. | ||
7 | 5 | ||
8 | This patch removes the protocol_name field from the brdv_replication | 6 | qemu-system-x86_64 \ |
9 | structure so that attempts to invoke this driver using protocol syntax | 7 | -chardev null,id=foo \ |
10 | will fail gracefully: | 8 | -device vhost-user-blk-pci,queue-size=4096,chardev=foo |
11 | 9 | ||
12 | $ qemu-img info replication:foo | 10 | Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1935014 |
13 | qemu-img: Could not open 'replication:': Unknown protocol 'replication' | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
14 | 12 | Message-Id: <20210413165654.50810-1-kwolf@redhat.com> | |
15 | Buglink: https://bugs.launchpad.net/qemu/+bug/1726733 | 13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
16 | Signed-off-by: Fabiano Rosas <farosas@linux.vnet.ibm.com> | 14 | Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com> |
17 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
16 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
19 | --- | 18 | --- |
20 | replication.h | 1 - | 19 | hw/block/vhost-user-blk.c | 5 +++++ |
21 | block/replication.c | 1 - | 20 | 1 file changed, 5 insertions(+) |
22 | 2 files changed, 2 deletions(-) | ||
23 | 21 | ||
24 | diff --git a/replication.h b/replication.h | 22 | diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c |
25 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/replication.h | 24 | --- a/hw/block/vhost-user-blk.c |
27 | +++ b/replication.h | 25 | +++ b/hw/block/vhost-user-blk.c |
28 | @@ -XXX,XX +XXX,XX @@ typedef struct ReplicationState ReplicationState; | 26 | @@ -XXX,XX +XXX,XX @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) |
29 | * | 27 | error_setg(errp, "vhost-user-blk: queue size must be non-zero"); |
30 | * BlockDriver bdrv_replication = { | 28 | return; |
31 | * .format_name = "replication", | 29 | } |
32 | - * .protocol_name = "replication", | 30 | + if (s->queue_size > VIRTQUEUE_MAX_SIZE) { |
33 | * .instance_size = sizeof(BDRVReplicationState), | 31 | + error_setg(errp, "vhost-user-blk: queue size must not exceed %d", |
34 | * | 32 | + VIRTQUEUE_MAX_SIZE); |
35 | * .bdrv_open = replication_open, | 33 | + return; |
36 | diff --git a/block/replication.c b/block/replication.c | 34 | + } |
37 | index XXXXXXX..XXXXXXX 100644 | 35 | |
38 | --- a/block/replication.c | 36 | if (!vhost_user_init(&s->vhost_user, &s->chardev, errp)) { |
39 | +++ b/block/replication.c | 37 | return; |
40 | @@ -XXX,XX +XXX,XX @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) | ||
41 | |||
42 | BlockDriver bdrv_replication = { | ||
43 | .format_name = "replication", | ||
44 | - .protocol_name = "replication", | ||
45 | .instance_size = sizeof(BDRVReplicationState), | ||
46 | |||
47 | .bdrv_open = replication_open, | ||
48 | -- | 38 | -- |
49 | 2.13.6 | 39 | 2.30.2 |
50 | 40 | ||
51 | 41 | diff view generated by jsdifflib |