1 | The following changes since commit b55a69fe5f0a504dac6359bb7e99a72b130c3661: | 1 | The following changes since commit 013a18edbbc59cdad019100c7d03c0494642b74c: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20170607' into staging (2017-06-07 15:06:42 +0100) | 3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200514' into staging (2020-05-14 16:17:55 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | |||
7 | 6 | ||
8 | git://repo.or.cz/qemu/kevin.git tags/for-upstream | 7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream |
9 | 8 | ||
10 | for you to fetch changes up to 2cb8f869e43406ce829ebe3b16fecc78d367dc7f: | 9 | for you to fetch changes up to 7d8f21a650e562270f5ed5341134c9c2c39dc5e8: |
11 | 10 | ||
12 | block: fix external snapshot abort permission error (2017-06-07 18:51:51 +0200) | 11 | iotests/030: Reduce run time by unthrottling job earlier (2020-05-15 14:12:34 +0200) |
13 | 12 | ||
14 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
15 | Block layer patches | 14 | Block layer patches: |
15 | |||
16 | - Introduce real BdrvChildRole | ||
17 | - blk/bdrv_make_empty() functions instead of calling callbacks directly | ||
18 | - mirror: Make sure that source and target size match | ||
19 | - block-copy: Fix uninitialized variable | ||
20 | - block/replication: Avoid cancelling the job twice | ||
21 | - ahci: Log lost IRQs | ||
22 | - iotests: Run pylint and mypy in a testcase | ||
23 | - iotests: log messages from notrun() | ||
16 | 24 | ||
17 | ---------------------------------------------------------------- | 25 | ---------------------------------------------------------------- |
18 | Jeff Cody (1): | 26 | John Snow (1): |
19 | block: fix external snapshot abort permission error | 27 | iotests: log messages from notrun() |
20 | 28 | ||
21 | Kevin Wolf (6): | 29 | Kevin Wolf (8): |
22 | block: Fix anonymous BBs in blk_root_inactivate() | 30 | iotests/109: Don't mirror with mismatched size |
23 | migration: Inactivate images after .save_live_complete_precopy() | 31 | iotests/229: Use blkdebug to inject an error |
24 | migration/block: Clean up BBs in block_save_complete() | 32 | mirror: Make sure that source and target size match |
25 | qemu-iotests: Block migration test | 33 | iotests: Mirror with different source/target size |
26 | commit: Fix use after free in completion | 34 | iotests: Fix incomplete type declarations |
27 | qemu-iotests: Test automatic commit job cancel on hot unplug | 35 | iotests: Run pylint and mypy in a testcase |
36 | replication: Avoid blk_make_empty() on read-only child | ||
37 | iotests/030: Reduce run time by unthrottling job earlier | ||
28 | 38 | ||
29 | Peter Maydell (1): | 39 | Lukas Straub (1): |
30 | block/qcow.c: Fix memory leak in qcow_create() | 40 | block/replication.c: Avoid cancelling the job twice |
31 | 41 | ||
32 | block/block-backend.c | 2 +- | 42 | Max Reitz (38): |
33 | block/commit.c | 7 +++ | 43 | block: Add bdrv_make_empty() |
34 | block/qcow.c | 1 + | 44 | block: Add blk_make_empty() |
35 | blockdev.c | 4 ++ | 45 | block: Use blk_make_empty() after commits |
36 | migration/block.c | 22 +++++-- | 46 | block: Use bdrv_make_empty() where possible |
37 | migration/migration.c | 12 ++-- | 47 | block: Mark commit, mirror, blkreplay as filters |
38 | tests/qemu-iotests/040 | 35 +++++++++++- | 48 | block: Add BlockDriver.is_format |
39 | tests/qemu-iotests/040.out | 4 +- | 49 | block: Rename BdrvChildRole to BdrvChildClass |
40 | tests/qemu-iotests/183 | 140 +++++++++++++++++++++++++++++++++++++++++++++ | 50 | block: Add BdrvChildRole and BdrvChildRoleBits |
41 | tests/qemu-iotests/183.out | 46 +++++++++++++++ | 51 | block: Add BdrvChildRole to BdrvChild |
42 | tests/qemu-iotests/group | 1 + | 52 | block: Pass BdrvChildRole to bdrv_child_perm() |
43 | 11 files changed, 259 insertions(+), 15 deletions(-) | 53 | block: Pass BdrvChildRole to .inherit_options() |
44 | create mode 100755 tests/qemu-iotests/183 | 54 | block: Pass parent_is_format to .inherit_options() |
45 | create mode 100644 tests/qemu-iotests/183.out | 55 | block: Rename bdrv_inherited_options() |
56 | block: Add generic bdrv_inherited_options() | ||
57 | block: Use bdrv_inherited_options() | ||
58 | block: Unify bdrv_child_cb_attach() | ||
59 | block: Unify bdrv_child_cb_detach() | ||
60 | block: Add child_of_bds | ||
61 | block: Distinguish paths in *_format_default_perms | ||
62 | block: Pull out bdrv_default_perms_for_cow() | ||
63 | block: Pull out bdrv_default_perms_for_storage() | ||
64 | block: Relax *perms_for_storage for data children | ||
65 | block: Add bdrv_default_perms() | ||
66 | raw-format: Split raw_read_options() | ||
67 | block: Switch child_format users to child_of_bds | ||
68 | block: Drop child_format | ||
69 | block: Make backing files child_of_bds children | ||
70 | block: Drop child_backing | ||
71 | block: Make format drivers use child_of_bds | ||
72 | block: Make filter drivers use child_of_bds | ||
73 | block: Use child_of_bds in remaining places | ||
74 | tests: Use child_of_bds instead of child_file | ||
75 | block: Use bdrv_default_perms() | ||
76 | block: Make bdrv_filter_default_perms() static | ||
77 | block: Drop bdrv_format_default_perms() | ||
78 | block: Drop child_file | ||
79 | block: Pass BdrvChildRole in remaining cases | ||
80 | block: Drop @child_class from bdrv_child_perm() | ||
46 | 81 | ||
82 | Philippe Mathieu-Daudé (3): | ||
83 | block/block-copy: Fix uninitialized variable in block_copy_task_entry | ||
84 | block/block-copy: Simplify block_copy_do_copy() | ||
85 | hw/ide/ahci: Log lost IRQs | ||
86 | |||
87 | include/block/block.h | 65 ++++- | ||
88 | include/block/block_int.h | 57 ++-- | ||
89 | include/sysemu/block-backend.h | 2 + | ||
90 | block.c | 601 ++++++++++++++++++++++++--------------- | ||
91 | block/backup-top.c | 11 +- | ||
92 | block/blkdebug.c | 10 +- | ||
93 | block/blklogwrites.c | 16 +- | ||
94 | block/blkreplay.c | 8 +- | ||
95 | block/blkverify.c | 10 +- | ||
96 | block/block-backend.c | 30 +- | ||
97 | block/block-copy.c | 14 +- | ||
98 | block/bochs.c | 7 +- | ||
99 | block/cloop.c | 7 +- | ||
100 | block/commit.c | 20 +- | ||
101 | block/copy-on-read.c | 7 +- | ||
102 | block/crypto.c | 8 +- | ||
103 | block/dmg.c | 7 +- | ||
104 | block/filter-compress.c | 7 +- | ||
105 | block/io.c | 22 +- | ||
106 | block/mirror.c | 25 +- | ||
107 | block/parallels.c | 7 +- | ||
108 | block/qcow.c | 7 +- | ||
109 | block/qcow2.c | 20 +- | ||
110 | block/qed.c | 7 +- | ||
111 | block/quorum.c | 8 +- | ||
112 | block/raw-format.c | 128 +++++---- | ||
113 | block/replication.c | 23 +- | ||
114 | block/throttle.c | 7 +- | ||
115 | block/vdi.c | 7 +- | ||
116 | block/vhdx.c | 7 +- | ||
117 | block/vmdk.c | 23 +- | ||
118 | block/vpc.c | 7 +- | ||
119 | block/vvfat.c | 17 +- | ||
120 | blockjob.c | 7 +- | ||
121 | hw/ide/ahci.c | 1 + | ||
122 | qemu-img.c | 19 +- | ||
123 | tests/test-bdrv-drain.c | 72 +++-- | ||
124 | tests/test-bdrv-graph-mod.c | 10 +- | ||
125 | tests/test-block-iothread.c | 17 +- | ||
126 | tests/qemu-iotests/iotests.py | 19 +- | ||
127 | tests/qemu-iotests/030 | 6 +- | ||
128 | tests/qemu-iotests/041 | 45 +++ | ||
129 | tests/qemu-iotests/041.out | 4 +- | ||
130 | tests/qemu-iotests/098.out | 8 +- | ||
131 | tests/qemu-iotests/109 | 10 +- | ||
132 | tests/qemu-iotests/109.out | 74 ++--- | ||
133 | tests/qemu-iotests/229 | 15 +- | ||
134 | tests/qemu-iotests/229.out | 6 +- | ||
135 | tests/qemu-iotests/297 | 44 +++ | ||
136 | tests/qemu-iotests/297.out | 3 + | ||
137 | tests/qemu-iotests/common.filter | 5 + | ||
138 | tests/qemu-iotests/group | 1 + | ||
139 | 52 files changed, 995 insertions(+), 573 deletions(-) | ||
140 | create mode 100755 tests/qemu-iotests/297 | ||
141 | create mode 100644 tests/qemu-iotests/297.out | ||
142 | |||
143 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | This patch makes the raw image the same size as the file in a different | |
2 | format that is mirrored as raw to it to avoid errors when mirror starts | ||
3 | to enforce that source and target are the same size. | ||
4 | |||
5 | We check only that the first 512 bytes are zeroed (instead of 64k) | ||
6 | because some image formats create image files that are smaller than 64k, | ||
7 | so trying to read 64k would result in I/O errors. Apart from this, 512 | ||
8 | is more appropriate anyway because the raw format driver protects | ||
9 | specifically the first 512 bytes. | ||
10 | |||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | Message-Id: <20200511135825.219437-2-kwolf@redhat.com> | ||
13 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
14 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | --- | ||
17 | tests/qemu-iotests/109 | 10 ++--- | ||
18 | tests/qemu-iotests/109.out | 74 +++++++++++++------------------- | ||
19 | tests/qemu-iotests/common.filter | 5 +++ | ||
20 | 3 files changed, 41 insertions(+), 48 deletions(-) | ||
21 | |||
22 | diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109 | ||
23 | index XXXXXXX..XXXXXXX 100755 | ||
24 | --- a/tests/qemu-iotests/109 | ||
25 | +++ b/tests/qemu-iotests/109 | ||
26 | @@ -XXX,XX +XXX,XX @@ for fmt in qcow qcow2 qed vdi vmdk vpc; do | ||
27 | echo "=== Writing a $fmt header into raw ===" | ||
28 | echo | ||
29 | |||
30 | - _make_test_img 64M | ||
31 | TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M | ||
32 | + _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size | ||
33 | |||
34 | # This first test should fail: The image format was probed, we may not | ||
35 | # write an image header at the start of the image | ||
36 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" | | ||
37 | _filter_block_job_len | ||
38 | - $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io | ||
39 | + $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io | ||
40 | |||
41 | |||
42 | # When raw was explicitly specified, the same must succeed | ||
43 | @@ -XXX,XX +XXX,XX @@ for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \ | ||
44 | |||
45 | # Can't use _use_sample_img because that isn't designed to be used multiple | ||
46 | # times and it overwrites $TEST_IMG (both breaks cleanup) | ||
47 | - _make_test_img 64M | ||
48 | bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src" | ||
49 | + _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size | ||
50 | |||
51 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" | | ||
52 | _filter_block_job_offset | _filter_block_job_len | ||
53 | - $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io | ||
54 | + $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io | ||
55 | |||
56 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY" | ||
57 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" | ||
58 | @@ -XXX,XX +XXX,XX @@ echo "=== Write legitimate MBR into raw ===" | ||
59 | echo | ||
60 | |||
61 | for sample_img in grub_mbr.raw; do | ||
62 | - _make_test_img 64M | ||
63 | bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src" | ||
64 | + _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size | ||
65 | |||
66 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY" | ||
67 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" | ||
68 | diff --git a/tests/qemu-iotests/109.out b/tests/qemu-iotests/109.out | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/tests/qemu-iotests/109.out | ||
71 | +++ b/tests/qemu-iotests/109.out | ||
72 | @@ -XXX,XX +XXX,XX @@ QA output created by 109 | ||
73 | |||
74 | === Writing a qcow header into raw === | ||
75 | |||
76 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
77 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
78 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
79 | { 'execute': 'qmp_capabilities' } | ||
80 | {"return": {}} | ||
81 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
82 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
83 | {"execute":"quit"} | ||
84 | {"return": {}} | ||
85 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
86 | -read 65536/65536 bytes at offset 0 | ||
87 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
88 | +read 512/512 bytes at offset 0 | ||
89 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
90 | { 'execute': 'qmp_capabilities' } | ||
91 | {"return": {}} | ||
92 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
93 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
94 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}} | ||
95 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
96 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
97 | -Warning: Image size mismatch! | ||
98 | Images are identical. | ||
99 | |||
100 | === Writing a qcow2 header into raw === | ||
101 | |||
102 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
103 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
104 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
105 | { 'execute': 'qmp_capabilities' } | ||
106 | {"return": {}} | ||
107 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
108 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
109 | {"execute":"quit"} | ||
110 | {"return": {}} | ||
111 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
112 | -read 65536/65536 bytes at offset 0 | ||
113 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
114 | +read 512/512 bytes at offset 0 | ||
115 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
116 | { 'execute': 'qmp_capabilities' } | ||
117 | {"return": {}} | ||
118 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
119 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
120 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 197120, "offset": 197120, "speed": 0, "type": "mirror"}} | ||
121 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
122 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
123 | -Warning: Image size mismatch! | ||
124 | Images are identical. | ||
125 | |||
126 | === Writing a qed header into raw === | ||
127 | |||
128 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
129 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
130 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
131 | { 'execute': 'qmp_capabilities' } | ||
132 | {"return": {}} | ||
133 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
134 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
135 | {"execute":"quit"} | ||
136 | {"return": {}} | ||
137 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
138 | -read 65536/65536 bytes at offset 0 | ||
139 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
140 | +read 512/512 bytes at offset 0 | ||
141 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
142 | { 'execute': 'qmp_capabilities' } | ||
143 | {"return": {}} | ||
144 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
145 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
146 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 327680, "offset": 327680, "speed": 0, "type": "mirror"}} | ||
147 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
148 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
149 | -Warning: Image size mismatch! | ||
150 | Images are identical. | ||
151 | |||
152 | === Writing a vdi header into raw === | ||
153 | |||
154 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
155 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
156 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
157 | { 'execute': 'qmp_capabilities' } | ||
158 | {"return": {}} | ||
159 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
160 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
161 | {"execute":"quit"} | ||
162 | {"return": {}} | ||
163 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
164 | -read 65536/65536 bytes at offset 0 | ||
165 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
166 | +read 512/512 bytes at offset 0 | ||
167 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
168 | { 'execute': 'qmp_capabilities' } | ||
169 | {"return": {}} | ||
170 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
171 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
172 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}} | ||
173 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
174 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
175 | -Warning: Image size mismatch! | ||
176 | Images are identical. | ||
177 | |||
178 | === Writing a vmdk header into raw === | ||
179 | |||
180 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
181 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
182 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
183 | { 'execute': 'qmp_capabilities' } | ||
184 | {"return": {}} | ||
185 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
186 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
187 | {"execute":"quit"} | ||
188 | {"return": {}} | ||
189 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
190 | -read 65536/65536 bytes at offset 0 | ||
191 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
192 | +read 512/512 bytes at offset 0 | ||
193 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
194 | { 'execute': 'qmp_capabilities' } | ||
195 | {"return": {}} | ||
196 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
197 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
198 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}} | ||
199 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
200 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
201 | -Warning: Image size mismatch! | ||
202 | Images are identical. | ||
203 | |||
204 | === Writing a vpc header into raw === | ||
205 | |||
206 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
207 | Formatting 'TEST_DIR/t.raw.src', fmt=IMGFMT size=67108864 | ||
208 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
209 | { 'execute': 'qmp_capabilities' } | ||
210 | {"return": {}} | ||
211 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
212 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
213 | {"execute":"quit"} | ||
214 | {"return": {}} | ||
215 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
216 | -read 65536/65536 bytes at offset 0 | ||
217 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
218 | +read 512/512 bytes at offset 0 | ||
219 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
220 | { 'execute': 'qmp_capabilities' } | ||
221 | {"return": {}} | ||
222 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
223 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
224 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}} | ||
225 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
226 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
227 | -Warning: Image size mismatch! | ||
228 | Images are identical. | ||
229 | |||
230 | === Copying sample image empty.bochs into raw === | ||
231 | |||
232 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
233 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
234 | { 'execute': 'qmp_capabilities' } | ||
235 | {"return": {}} | ||
236 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
237 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
238 | {"execute":"quit"} | ||
239 | {"return": {}} | ||
240 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
241 | -read 65536/65536 bytes at offset 0 | ||
242 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
243 | +read 512/512 bytes at offset 0 | ||
244 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
245 | { 'execute': 'qmp_capabilities' } | ||
246 | {"return": {}} | ||
247 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
248 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
249 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}} | ||
250 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
251 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
252 | -Warning: Image size mismatch! | ||
253 | Images are identical. | ||
254 | |||
255 | === Copying sample image iotest-dirtylog-10G-4M.vhdx into raw === | ||
256 | |||
257 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
258 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
259 | { 'execute': 'qmp_capabilities' } | ||
260 | {"return": {}} | ||
261 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
262 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
263 | {"execute":"quit"} | ||
264 | {"return": {}} | ||
265 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
266 | -read 65536/65536 bytes at offset 0 | ||
267 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
268 | +read 512/512 bytes at offset 0 | ||
269 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
270 | { 'execute': 'qmp_capabilities' } | ||
271 | {"return": {}} | ||
272 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
273 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
274 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 31457280, "offset": 31457280, "speed": 0, "type": "mirror"}} | ||
275 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
276 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
277 | -Warning: Image size mismatch! | ||
278 | Images are identical. | ||
279 | |||
280 | === Copying sample image parallels-v1 into raw === | ||
281 | |||
282 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
283 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
284 | { 'execute': 'qmp_capabilities' } | ||
285 | {"return": {}} | ||
286 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
287 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
288 | {"execute":"quit"} | ||
289 | {"return": {}} | ||
290 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
291 | -read 65536/65536 bytes at offset 0 | ||
292 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
293 | +read 512/512 bytes at offset 0 | ||
294 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
295 | { 'execute': 'qmp_capabilities' } | ||
296 | {"return": {}} | ||
297 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
298 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
299 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 327680, "offset": 327680, "speed": 0, "type": "mirror"}} | ||
300 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
301 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
302 | -Warning: Image size mismatch! | ||
303 | Images are identical. | ||
304 | |||
305 | === Copying sample image simple-pattern.cloop into raw === | ||
306 | |||
307 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
308 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
309 | { 'execute': 'qmp_capabilities' } | ||
310 | {"return": {}} | ||
311 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
312 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
313 | {"execute":"quit"} | ||
314 | {"return": {}} | ||
315 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} | ||
316 | -read 65536/65536 bytes at offset 0 | ||
317 | -64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
318 | +read 512/512 bytes at offset 0 | ||
319 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
320 | { 'execute': 'qmp_capabilities' } | ||
321 | {"return": {}} | ||
322 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'format': 'IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
323 | @@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 0 | ||
324 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2048, "offset": 2048, "speed": 0, "type": "mirror"}} | ||
325 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
326 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
327 | -Warning: Image size mismatch! | ||
328 | Images are identical. | ||
329 | |||
330 | === Write legitimate MBR into raw === | ||
331 | |||
332 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
333 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE | ||
334 | { 'execute': 'qmp_capabilities' } | ||
335 | {"return": {}} | ||
336 | {'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} | ||
337 | @@ -XXX,XX +XXX,XX @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed | ||
338 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}} | ||
339 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
340 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
341 | -Warning: Image size mismatch! | ||
342 | Images are identical. | ||
343 | { 'execute': 'qmp_capabilities' } | ||
344 | {"return": {}} | ||
345 | @@ -XXX,XX +XXX,XX @@ Images are identical. | ||
346 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}} | ||
347 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "concluded", "id": "src"}} | ||
348 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "src"}} | ||
349 | -Warning: Image size mismatch! | ||
350 | Images are identical. | ||
351 | *** done | ||
352 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
353 | index XXXXXXX..XXXXXXX 100644 | ||
354 | --- a/tests/qemu-iotests/common.filter | ||
355 | +++ b/tests/qemu-iotests/common.filter | ||
356 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | ||
357 | -e "s# compression_type=[a-zA-Z0-9]\\+##g" | ||
358 | } | ||
359 | |||
360 | +_filter_img_create_size() | ||
361 | +{ | ||
362 | + $SED -e "s# size=[0-9]\\+# size=SIZE#g" | ||
363 | +} | ||
364 | + | ||
365 | _filter_img_info() | ||
366 | { | ||
367 | if [[ "$1" == "--format-specific" ]]; then | ||
368 | -- | ||
369 | 2.25.4 | ||
370 | |||
371 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 229 relies on the mirror running into an I/O error when the target is | ||
2 | smaller than the source. After changing mirror to catch this condition | ||
3 | while starting the job, this test case won't get a job that is paused | ||
4 | for an I/O error any more. Use blkdebug instead to inject an error. | ||
1 | 5 | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Message-Id: <20200511135825.219437-3-kwolf@redhat.com> | ||
9 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
10 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | tests/qemu-iotests/229 | 15 +++++++++++---- | ||
14 | tests/qemu-iotests/229.out | 6 +++--- | ||
15 | 2 files changed, 14 insertions(+), 7 deletions(-) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/229 b/tests/qemu-iotests/229 | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/229 | ||
20 | +++ b/tests/qemu-iotests/229 | ||
21 | @@ -XXX,XX +XXX,XX @@ _cleanup() | ||
22 | _cleanup_test_img | ||
23 | _rm_test_img "$TEST_IMG" | ||
24 | _rm_test_img "$DEST_IMG" | ||
25 | + rm -f "$TEST_DIR/blkdebug.conf" | ||
26 | } | ||
27 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
28 | |||
29 | @@ -XXX,XX +XXX,XX @@ _supported_os Linux | ||
30 | |||
31 | DEST_IMG="$TEST_DIR/d.$IMGFMT" | ||
32 | TEST_IMG="$TEST_DIR/b.$IMGFMT" | ||
33 | +BLKDEBUG_CONF="$TEST_DIR/blkdebug.conf" | ||
34 | |||
35 | _make_test_img 2M | ||
36 | - | ||
37 | -# destination for mirror will be too small, causing error | ||
38 | -TEST_IMG=$DEST_IMG _make_test_img 1M | ||
39 | +TEST_IMG=$DEST_IMG _make_test_img 2M | ||
40 | |||
41 | $QEMU_IO -c 'write 0 2M' "$TEST_IMG" | _filter_qemu_io | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ echo | ||
44 | echo '=== Starting drive-mirror, causing error & stop ===' | ||
45 | echo | ||
46 | |||
47 | +cat > "$BLKDEBUG_CONF" <<EOF | ||
48 | +[inject-error] | ||
49 | +event = "write_aio" | ||
50 | +errno = "5" | ||
51 | +once = "on" | ||
52 | +EOF | ||
53 | + | ||
54 | _send_qemu_cmd $QEMU_HANDLE \ | ||
55 | "{'execute': 'drive-mirror', | ||
56 | 'arguments': {'device': 'testdisk', | ||
57 | 'format': '$IMGFMT', | ||
58 | - 'target': '$DEST_IMG', | ||
59 | + 'target': 'blkdebug:$BLKDEBUG_CONF:$DEST_IMG', | ||
60 | 'sync': 'full', | ||
61 | 'mode': 'existing', | ||
62 | 'on-source-error': 'stop', | ||
63 | diff --git a/tests/qemu-iotests/229.out b/tests/qemu-iotests/229.out | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/tests/qemu-iotests/229.out | ||
66 | +++ b/tests/qemu-iotests/229.out | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | QA output created by 229 | ||
69 | Formatting 'TEST_DIR/b.IMGFMT', fmt=IMGFMT size=2097152 | ||
70 | -Formatting 'TEST_DIR/d.IMGFMT', fmt=IMGFMT size=1048576 | ||
71 | +Formatting 'TEST_DIR/d.IMGFMT', fmt=IMGFMT size=2097152 | ||
72 | wrote 2097152/2097152 bytes at offset 0 | ||
73 | 2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
74 | {'execute': 'qmp_capabilities'} | ||
75 | @@ -XXX,XX +XXX,XX @@ wrote 2097152/2097152 bytes at offset 0 | ||
76 | |||
77 | === Starting drive-mirror, causing error & stop === | ||
78 | |||
79 | -{'execute': 'drive-mirror', 'arguments': {'device': 'testdisk', 'format': 'IMGFMT', 'target': 'TEST_DIR/d.IMGFMT', 'sync': 'full', 'mode': 'existing', 'on-source-error': 'stop', 'on-target-error': 'stop' }} | ||
80 | +{'execute': 'drive-mirror', 'arguments': {'device': 'testdisk', 'format': 'IMGFMT', 'target': 'blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/d.IMGFMT', 'sync': 'full', 'mode': 'existing', 'on-source-error': 'stop', 'on-target-error': 'stop' }} | ||
81 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "testdisk"}} | ||
82 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "testdisk"}} | ||
83 | {"return": {}} | ||
84 | @@ -XXX,XX +XXX,XX @@ wrote 2097152/2097152 bytes at offset 0 | ||
85 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "testdisk"}} | ||
86 | {"return": {}} | ||
87 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "testdisk"}} | ||
88 | -{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "testdisk", "len": 2097152, "offset": 1048576, "speed": 0, "type": "mirror"}} | ||
89 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "testdisk", "len": 2097152, "offset": 2097152, "speed": 0, "type": "mirror"}} | ||
90 | *** done | ||
91 | -- | ||
92 | 2.25.4 | ||
93 | |||
94 | diff view generated by jsdifflib |
1 | Block migration may still access the image during its | 1 | If the target is shorter than the source, mirror would copy data until |
---|---|---|---|
2 | .save_live_complete_precopy() implementation, so we should only | 2 | it reaches the end of the target and then fail with an I/O error when |
3 | inactivate the image afterwards. | 3 | trying to write past the end. |
4 | 4 | ||
5 | Another reason for the change is that inactivating an image fails when | 5 | If the target is longer than the source, the mirror job would complete |
6 | there is still a non-device BlockBackend using it, which includes the | 6 | successfully, but the target wouldn't actually be an accurate copy of |
7 | BBs used by block migration. We want to give block migration a chance to | 7 | the source image (it would contain some additional garbage at the end). |
8 | release the BBs before trying to inactivate the image (this will be done | 8 | |
9 | in another patch). | 9 | Fix this by checking that both images have the same size when the job |
10 | starts. | ||
10 | 11 | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
13 | Reviewed-by: Juan Quintela <quintela@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | 13 | Reviewed-by: Eric Blake <eblake@redhat.com> |
15 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 14 | Message-Id: <20200511135825.219437-4-kwolf@redhat.com> |
15 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
16 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | --- | 18 | --- |
17 | migration/migration.c | 12 +++++++----- | 19 | block/mirror.c | 21 ++++++++++++--------- |
18 | 1 file changed, 7 insertions(+), 5 deletions(-) | 20 | 1 file changed, 12 insertions(+), 9 deletions(-) |
19 | 21 | ||
20 | diff --git a/migration/migration.c b/migration/migration.c | 22 | diff --git a/block/mirror.c b/block/mirror.c |
21 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/migration/migration.c | 24 | --- a/block/mirror.c |
23 | +++ b/migration/migration.c | 25 | +++ b/block/mirror.c |
24 | @@ -XXX,XX +XXX,XX @@ static void migration_completion(MigrationState *s, int current_active_state, | 26 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp) |
25 | 27 | BlockDriverState *target_bs = blk_bs(s->target); | |
26 | if (!ret) { | 28 | bool need_drain = true; |
27 | ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); | 29 | int64_t length; |
28 | + if (ret >= 0) { | 30 | + int64_t target_length; |
29 | + qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); | 31 | BlockDriverInfo bdi; |
30 | + qemu_savevm_state_complete_precopy(s->to_dst_file, false); | 32 | char backing_filename[2]; /* we only need 2 characters because we are only |
31 | + } | 33 | checking for a NULL string */ |
32 | /* | 34 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp) |
33 | * Don't mark the image with BDRV_O_INACTIVE flag if | 35 | goto immediate_exit; |
34 | * we will go into COLO stage later. | 36 | } |
35 | */ | 37 | |
36 | if (ret >= 0 && !migrate_colo_enabled()) { | 38 | + target_length = blk_getlength(s->target); |
37 | ret = bdrv_inactivate_all(); | 39 | + if (target_length < 0) { |
38 | - } | 40 | + ret = target_length; |
39 | - if (ret >= 0) { | 41 | + goto immediate_exit; |
40 | - qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); | 42 | + } |
41 | - qemu_savevm_state_complete_precopy(s->to_dst_file, false); | 43 | + |
42 | - s->block_inactive = true; | 44 | /* Active commit must resize the base image if its size differs from the |
43 | + if (ret >= 0) { | 45 | * active layer. */ |
44 | + s->block_inactive = true; | 46 | if (s->base == blk_bs(s->target)) { |
45 | + } | 47 | - int64_t base_length; |
48 | - | ||
49 | - base_length = blk_getlength(s->target); | ||
50 | - if (base_length < 0) { | ||
51 | - ret = base_length; | ||
52 | - goto immediate_exit; | ||
53 | - } | ||
54 | - | ||
55 | - if (s->bdev_length > base_length) { | ||
56 | + if (s->bdev_length > target_length) { | ||
57 | ret = blk_truncate(s->target, s->bdev_length, false, | ||
58 | PREALLOC_MODE_OFF, 0, NULL); | ||
59 | if (ret < 0) { | ||
60 | goto immediate_exit; | ||
46 | } | 61 | } |
47 | } | 62 | } |
48 | qemu_mutex_unlock_iothread(); | 63 | + } else if (s->bdev_length != target_length) { |
64 | + error_setg(errp, "Source and target image have different sizes"); | ||
65 | + ret = -EINVAL; | ||
66 | + goto immediate_exit; | ||
67 | } | ||
68 | |||
69 | if (s->bdev_length == 0) { | ||
49 | -- | 70 | -- |
50 | 1.8.3.1 | 71 | 2.25.4 |
51 | 72 | ||
52 | 73 | diff view generated by jsdifflib |
1 | This tests that the mirror job catches situations where the target node | ||
---|---|---|---|
2 | has a different size than the source node. It must also forbid resize | ||
3 | operations when the job is already running. | ||
4 | |||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | Reviewed-by: John Snow <jsnow@redhat.com> | 6 | Reviewed-by: Eric Blake <eblake@redhat.com> |
7 | Message-Id: <20200511135825.219437-5-kwolf@redhat.com> | ||
8 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
3 | --- | 11 | --- |
4 | tests/qemu-iotests/040 | 35 +++++++++++++++++++++++++++++++++-- | 12 | tests/qemu-iotests/041 | 45 ++++++++++++++++++++++++++++++++++++++ |
5 | tests/qemu-iotests/040.out | 4 ++-- | 13 | tests/qemu-iotests/041.out | 4 ++-- |
6 | 2 files changed, 35 insertions(+), 4 deletions(-) | 14 | 2 files changed, 47 insertions(+), 2 deletions(-) |
7 | 15 | ||
8 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 | 16 | diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 |
9 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100755 |
10 | --- a/tests/qemu-iotests/040 | 18 | --- a/tests/qemu-iotests/041 |
11 | +++ b/tests/qemu-iotests/040 | 19 | +++ b/tests/qemu-iotests/041 |
12 | @@ -XXX,XX +XXX,XX @@ class ImageCommitTestCase(iotests.QMPTestCase): | 20 | @@ -XXX,XX +XXX,XX @@ class TestSingleBlockdev(TestSingleDrive): |
13 | self.wait_for_complete() | 21 | target=self.qmp_target) |
14 | |||
15 | class TestSingleDrive(ImageCommitTestCase): | ||
16 | - image_len = 1 * 1024 * 1024 | ||
17 | + # Need some space after the copied data so that throttling is effective in | ||
18 | + # tests that use it rather than just completing the job immediately | ||
19 | + image_len = 2 * 1024 * 1024 | ||
20 | test_len = 1 * 1024 * 256 | ||
21 | |||
22 | def setUp(self): | ||
23 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
24 | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) | ||
25 | qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) | ||
26 | qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) | ||
27 | - self.vm = iotests.VM().add_drive(test_img) | ||
28 | + self.vm = iotests.VM().add_drive(test_img, interface="none") | ||
29 | + self.vm.add_device("virtio-scsi-pci") | ||
30 | + self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") | ||
31 | self.vm.launch() | ||
32 | |||
33 | def tearDown(self): | ||
34 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
35 | self.assert_qmp(result, 'error/class', 'GenericError') | 22 | self.assert_qmp(result, 'error/class', 'GenericError') |
36 | self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img) | 23 | |
37 | 24 | + def do_test_resize(self, device, node): | |
38 | + # When the job is running on a BB that is automatically deleted on hot | 25 | + def pre_finalize(): |
39 | + # unplug, the job is cancelled when the device disappears | 26 | + if device: |
40 | + def test_hot_unplug(self): | 27 | + result = self.vm.qmp('block_resize', device=device, size=65536) |
41 | + if self.image_len == 0: | 28 | + self.assert_qmp(result, 'error/class', 'GenericError') |
42 | + return | ||
43 | + | 29 | + |
44 | + self.assert_no_active_block_jobs() | 30 | + result = self.vm.qmp('block_resize', node_name=node, size=65536) |
45 | + result = self.vm.qmp('block-commit', device='drive0', top=mid_img, | 31 | + self.assert_qmp(result, 'error/class', 'GenericError') |
46 | + base=backing_img, speed=(self.image_len / 4)) | 32 | + |
47 | + self.assert_qmp(result, 'return', {}) | 33 | + result = self.vm.qmp(self.qmp_cmd, job_id='job0', device='drive0', |
48 | + result = self.vm.qmp('device_del', id='scsi0') | 34 | + sync='full', target=self.qmp_target, |
35 | + auto_finalize=False, auto_dismiss=False) | ||
49 | + self.assert_qmp(result, 'return', {}) | 36 | + self.assert_qmp(result, 'return', {}) |
50 | + | 37 | + |
51 | + cancelled = False | 38 | + result = self.vm.run_job('job0', auto_finalize=False, |
52 | + deleted = False | 39 | + pre_finalize=pre_finalize) |
53 | + while not cancelled or not deleted: | 40 | + self.assertEqual(result, None) |
54 | + for event in self.vm.get_qmp_events(wait=True): | ||
55 | + if event['event'] == 'DEVICE_DELETED': | ||
56 | + self.assert_qmp(event, 'data/device', 'scsi0') | ||
57 | + deleted = True | ||
58 | + elif event['event'] == 'BLOCK_JOB_CANCELLED': | ||
59 | + self.assert_qmp(event, 'data/device', 'drive0') | ||
60 | + cancelled = True | ||
61 | + else: | ||
62 | + self.fail("Unexpected event %s" % (event['event'])) | ||
63 | + | 41 | + |
64 | + self.assert_no_active_block_jobs() | 42 | + def test_source_resize(self): |
65 | 43 | + self.do_test_resize('drive0', 'top') | |
66 | class TestRelativePaths(ImageCommitTestCase): | 44 | + |
67 | image_len = 1 * 1024 * 1024 | 45 | + def test_target_resize(self): |
68 | diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out | 46 | + self.do_test_resize(None, self.qmp_target) |
47 | + | ||
48 | + def do_test_target_size(self, size): | ||
49 | + result = self.vm.qmp('block_resize', node_name=self.qmp_target, | ||
50 | + size=size) | ||
51 | + self.assert_qmp(result, 'return', {}) | ||
52 | + | ||
53 | + result = self.vm.qmp(self.qmp_cmd, job_id='job0', | ||
54 | + device='drive0', sync='full', auto_dismiss=False, | ||
55 | + target=self.qmp_target) | ||
56 | + self.assert_qmp(result, 'return', {}) | ||
57 | + | ||
58 | + result = self.vm.run_job('job0') | ||
59 | + self.assertEqual(result, 'Source and target image have different sizes') | ||
60 | + | ||
61 | + def test_small_target(self): | ||
62 | + self.do_test_target_size(self.image_len // 2) | ||
63 | + | ||
64 | + def test_large_target(self): | ||
65 | + self.do_test_target_size(self.image_len * 2) | ||
66 | + | ||
67 | test_large_cluster = None | ||
68 | test_image_not_found = None | ||
69 | test_small_buffer2 = None | ||
70 | @@ -XXX,XX +XXX,XX @@ class TestSingleDriveZeroLength(TestSingleDrive): | ||
71 | |||
72 | class TestSingleBlockdevZeroLength(TestSingleBlockdev): | ||
73 | image_len = 0 | ||
74 | + test_small_target = None | ||
75 | + test_large_target = None | ||
76 | |||
77 | class TestSingleDriveUnalignedLength(TestSingleDrive): | ||
78 | image_len = 1025 * 1024 | ||
79 | diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out | ||
69 | index XXXXXXX..XXXXXXX 100644 | 80 | index XXXXXXX..XXXXXXX 100644 |
70 | --- a/tests/qemu-iotests/040.out | 81 | --- a/tests/qemu-iotests/041.out |
71 | +++ b/tests/qemu-iotests/040.out | 82 | +++ b/tests/qemu-iotests/041.out |
72 | @@ -XXX,XX +XXX,XX @@ | 83 | @@ -XXX,XX +XXX,XX @@ |
73 | -......................... | 84 | -.............................................................................................. |
74 | +........................... | 85 | +........................................................................................................ |
75 | ---------------------------------------------------------------------- | 86 | ---------------------------------------------------------------------- |
76 | -Ran 25 tests | 87 | -Ran 94 tests |
77 | +Ran 27 tests | 88 | +Ran 104 tests |
78 | 89 | ||
79 | OK | 90 | OK |
80 | -- | 91 | -- |
81 | 1.8.3.1 | 92 | 2.25.4 |
82 | 93 | ||
83 | 94 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Lukas Straub <lukasstraub2@web.de> | ||
1 | 2 | ||
3 | If qemu in colo secondary mode is stopped, it crashes because | ||
4 | s->backup_job is canceled twice: First with job_cancel_sync_all() | ||
5 | in qemu_cleanup() and then in replication_stop(). | ||
6 | |||
7 | Fix this by assigning NULL to s->backup_job when the job completes | ||
8 | so replication_stop() and replication_do_checkpoint() won't touch | ||
9 | the job. | ||
10 | |||
11 | Signed-off-by: Lukas Straub <lukasstraub2@web.de> | ||
12 | Message-Id: <20200511090801.7ed5d8f3@luklap> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | block/replication.c | 2 ++ | ||
16 | 1 file changed, 2 insertions(+) | ||
17 | |||
18 | diff --git a/block/replication.c b/block/replication.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/replication.c | ||
21 | +++ b/block/replication.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void backup_job_cleanup(BlockDriverState *bs) | ||
23 | BDRVReplicationState *s = bs->opaque; | ||
24 | BlockDriverState *top_bs; | ||
25 | |||
26 | + s->backup_job = NULL; | ||
27 | + | ||
28 | top_bs = bdrv_lookup_bs(s->top_id, s->top_id, NULL); | ||
29 | if (!top_bs) { | ||
30 | return; | ||
31 | -- | ||
32 | 2.25.4 | ||
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We need to fix only a few places so that iotests.py can pass | ||
2 | mypy --disallow-incomplete-defs, which seems to be a desirable option to | ||
3 | have enabled in the long run. | ||
1 | 4 | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
6 | Message-Id: <20200511163529.349329-2-kwolf@redhat.com> | ||
7 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | tests/qemu-iotests/iotests.py | 8 ++++---- | ||
12 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
13 | |||
14 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/tests/qemu-iotests/iotests.py | ||
17 | +++ b/tests/qemu-iotests/iotests.py | ||
18 | @@ -XXX,XX +XXX,XX @@ def _verify_cache_mode(supported_cache_modes: Sequence[str] = ()) -> None: | ||
19 | if supported_cache_modes and (cachemode not in supported_cache_modes): | ||
20 | notrun('not suitable for this cache mode: %s' % cachemode) | ||
21 | |||
22 | -def _verify_aio_mode(supported_aio_modes: Sequence[str] = ()): | ||
23 | +def _verify_aio_mode(supported_aio_modes: Sequence[str] = ()) -> None: | ||
24 | if supported_aio_modes and (aiomode not in supported_aio_modes): | ||
25 | notrun('not suitable for this aio mode: %s' % aiomode) | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ def skip_if_unsupported(required_formats=(), read_only=False): | ||
28 | '''Skip Test Decorator | ||
29 | Runs the test if all the required formats are whitelisted''' | ||
30 | def skip_test_decorator(func): | ||
31 | - def func_wrapper(test_case: QMPTestCase, *args, **kwargs): | ||
32 | + def func_wrapper(test_case: QMPTestCase, *args: List[Any], | ||
33 | + **kwargs: Dict[str, Any]) -> None: | ||
34 | if callable(required_formats): | ||
35 | fmts = required_formats(test_case) | ||
36 | else: | ||
37 | @@ -XXX,XX +XXX,XX @@ def skip_if_unsupported(required_formats=(), read_only=False): | ||
38 | if usf_list: | ||
39 | msg = f'{test_case}: formats {usf_list} are not whitelisted' | ||
40 | test_case.case_skip(msg) | ||
41 | - return None | ||
42 | else: | ||
43 | - return func(test_case, *args, **kwargs) | ||
44 | + func(test_case, *args, **kwargs) | ||
45 | return func_wrapper | ||
46 | return skip_test_decorator | ||
47 | |||
48 | -- | ||
49 | 2.25.4 | ||
50 | |||
51 | diff view generated by jsdifflib |
1 | We made sure that iotests.py passes pylint. It would be a shame if we | ||
---|---|---|---|
2 | allowed new patches in that break this again, so let's just add a | ||
3 | meta-test case that runs pylint on it. | ||
4 | |||
5 | While we don't pass mypy --strict yet, we can already run it with a few | ||
6 | options that would be part of --strict to make sure that we won't | ||
7 | regress on these aspects at least until we can enable the full thing. | ||
8 | |||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 10 | Message-Id: <20200511163529.349329-3-kwolf@redhat.com> |
3 | Reviewed-by: Eric Blake <eblake@redhat.com> | 11 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
12 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
4 | --- | 14 | --- |
5 | tests/qemu-iotests/183 | 140 +++++++++++++++++++++++++++++++++++++++++++++ | 15 | tests/qemu-iotests/297 | 44 ++++++++++++++++++++++++++++++++++++++ |
6 | tests/qemu-iotests/183.out | 46 +++++++++++++++ | 16 | tests/qemu-iotests/297.out | 3 +++ |
7 | tests/qemu-iotests/group | 1 + | 17 | tests/qemu-iotests/group | 1 + |
8 | 3 files changed, 187 insertions(+) | 18 | 3 files changed, 48 insertions(+) |
9 | create mode 100755 tests/qemu-iotests/183 | 19 | create mode 100755 tests/qemu-iotests/297 |
10 | create mode 100644 tests/qemu-iotests/183.out | 20 | create mode 100644 tests/qemu-iotests/297.out |
11 | 21 | ||
12 | diff --git a/tests/qemu-iotests/183 b/tests/qemu-iotests/183 | 22 | diff --git a/tests/qemu-iotests/297 b/tests/qemu-iotests/297 |
13 | new file mode 100755 | 23 | new file mode 100755 |
14 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
15 | --- /dev/null | 25 | --- /dev/null |
16 | +++ b/tests/qemu-iotests/183 | 26 | +++ b/tests/qemu-iotests/297 |
17 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
18 | +#!/bin/bash | 28 | +#!/usr/bin/env bash |
19 | +# | 29 | +# |
20 | +# Test old-style block migration (migrate -b) | 30 | +# Copyright (C) 2020 Red Hat, Inc. |
21 | +# | ||
22 | +# Copyright (C) 2017 Red Hat, Inc. | ||
23 | +# | 31 | +# |
24 | +# This program is free software; you can redistribute it and/or modify | 32 | +# This program is free software; you can redistribute it and/or modify |
25 | +# it under the terms of the GNU General Public License as published by | 33 | +# it under the terms of the GNU General Public License as published by |
26 | +# the Free Software Foundation; either version 2 of the License, or | 34 | +# the Free Software Foundation; either version 2 of the License, or |
27 | +# (at your option) any later version. | 35 | +# (at your option) any later version. |
... | ... | ||
31 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 39 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
32 | +# GNU General Public License for more details. | 40 | +# GNU General Public License for more details. |
33 | +# | 41 | +# |
34 | +# You should have received a copy of the GNU General Public License | 42 | +# You should have received a copy of the GNU General Public License |
35 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | 43 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
36 | +# | ||
37 | + | 44 | + |
38 | +# creator | 45 | +seq=$(basename $0) |
39 | +owner=kwolf@redhat.com | ||
40 | + | ||
41 | +seq=`basename $0` | ||
42 | +echo "QA output created by $seq" | 46 | +echo "QA output created by $seq" |
43 | + | 47 | + |
44 | +here=`pwd` | 48 | +status=1 # failure is the default! |
45 | +status=1 # failure is the default! | ||
46 | + | 49 | + |
47 | +MIG_SOCKET="${TEST_DIR}/migrate" | 50 | +# get standard environment |
51 | +. ./common.rc | ||
48 | + | 52 | + |
49 | +_cleanup() | 53 | +if ! type -p "pylint-3" > /dev/null; then |
50 | +{ | 54 | + _notrun "pylint-3 not found" |
51 | + rm -f "${MIG_SOCKET}" | 55 | +fi |
52 | + rm -f "${TEST_IMG}.dest" | 56 | +if ! type -p "mypy" > /dev/null; then |
53 | + _cleanup_test_img | 57 | + _notrun "mypy not found" |
54 | + _cleanup_qemu | ||
55 | +} | ||
56 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
57 | + | ||
58 | +# get standard environment, filters and checks | ||
59 | +. ./common.rc | ||
60 | +. ./common.filter | ||
61 | +. ./common.qemu | ||
62 | + | ||
63 | +_supported_fmt qcow2 raw qed dmg quorum | ||
64 | +_supported_proto file | ||
65 | +_supported_os Linux | ||
66 | + | ||
67 | +size=64M | ||
68 | +_make_test_img $size | ||
69 | +TEST_IMG="${TEST_IMG}.dest" _make_test_img $size | ||
70 | + | ||
71 | +echo | ||
72 | +echo === Starting VMs === | ||
73 | +echo | ||
74 | + | ||
75 | +qemu_comm_method="qmp" | ||
76 | + | ||
77 | +_launch_qemu \ | ||
78 | + -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk | ||
79 | +src=$QEMU_HANDLE | ||
80 | +_send_qemu_cmd $src "{ 'execute': 'qmp_capabilities' }" 'return' | ||
81 | + | ||
82 | +_launch_qemu \ | ||
83 | + -drive file="${TEST_IMG}.dest",cache=$CACHEMODE,driver=$IMGFMT,id=disk \ | ||
84 | + -incoming "unix:${MIG_SOCKET}" | ||
85 | +dest=$QEMU_HANDLE | ||
86 | +_send_qemu_cmd $dest "{ 'execute': 'qmp_capabilities' }" 'return' | ||
87 | + | ||
88 | +echo | ||
89 | +echo === Write something on the source === | ||
90 | +echo | ||
91 | + | ||
92 | +_send_qemu_cmd $src \ | ||
93 | + "{ 'execute': 'human-monitor-command', | ||
94 | + 'arguments': { 'command-line': | ||
95 | + 'qemu-io disk \"write -P 0x55 0 64k\"' } }" \ | ||
96 | + 'return' | ||
97 | +_send_qemu_cmd $src \ | ||
98 | + "{ 'execute': 'human-monitor-command', | ||
99 | + 'arguments': { 'command-line': | ||
100 | + 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ | ||
101 | + 'return' | ||
102 | + | ||
103 | +echo | ||
104 | +echo === Do block migration to destination === | ||
105 | +echo | ||
106 | + | ||
107 | +reply="$(_send_qemu_cmd $src \ | ||
108 | + "{ 'execute': 'migrate', | ||
109 | + 'arguments': { 'uri': 'unix:${MIG_SOCKET}', 'blk': true } }" \ | ||
110 | + 'return\|error')" | ||
111 | +echo "$reply" | ||
112 | +if echo "$reply" | grep "compiled without old-style" > /dev/null; then | ||
113 | + _notrun "migrate -b support not compiled in" | ||
114 | +fi | 58 | +fi |
115 | + | 59 | + |
116 | +QEMU_COMM_TIMEOUT=0.1 qemu_cmd_repeat=50 silent=yes \ | 60 | +pylint-3 --score=n iotests.py |
117 | + _send_qemu_cmd $src "{ 'execute': 'query-migrate' }" '"status": "completed"' | ||
118 | +_send_qemu_cmd $src "{ 'execute': 'query-status' }" "return" | ||
119 | + | 61 | + |
120 | +echo | 62 | +MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \ |
121 | +echo === Do some I/O on the destination === | 63 | + --disallow-any-generics --disallow-incomplete-defs \ |
122 | +echo | 64 | + --disallow-untyped-decorators --no-implicit-optional \ |
123 | + | 65 | + --warn-redundant-casts --warn-unused-ignores \ |
124 | +# It is important that we use the BlockBackend of the guest device here instead | 66 | + --no-implicit-reexport iotests.py |
125 | +# of the node name, which would create a new BlockBackend and not test whether | ||
126 | +# the guest has the necessary permissions to access the image now | ||
127 | +silent=yes _send_qemu_cmd $dest "" "100 %" | ||
128 | +_send_qemu_cmd $dest "{ 'execute': 'query-status' }" "return" | ||
129 | +_send_qemu_cmd $dest \ | ||
130 | + "{ 'execute': 'human-monitor-command', | ||
131 | + 'arguments': { 'command-line': | ||
132 | + 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ | ||
133 | + 'return' | ||
134 | +_send_qemu_cmd $dest \ | ||
135 | + "{ 'execute': 'human-monitor-command', | ||
136 | + 'arguments': { 'command-line': | ||
137 | + 'qemu-io disk \"write -P 0x66 1M 64k\"' } }" \ | ||
138 | + 'return' | ||
139 | + | ||
140 | +echo | ||
141 | +echo === Shut down and check image === | ||
142 | +echo | ||
143 | + | ||
144 | +_send_qemu_cmd $src '{"execute":"quit"}' 'return' | ||
145 | +_send_qemu_cmd $dest '{"execute":"quit"}' 'return' | ||
146 | +wait=1 _cleanup_qemu | ||
147 | + | ||
148 | +_check_test_img | ||
149 | +TEST_IMG="${TEST_IMG}.dest" _check_test_img | ||
150 | + | ||
151 | +$QEMU_IO -c 'write -P 0x66 1M 64k' "$TEST_IMG" | _filter_qemu_io | ||
152 | +$QEMU_IMG compare "$TEST_IMG.dest" "$TEST_IMG" | ||
153 | + | 67 | + |
154 | +# success, all done | 68 | +# success, all done |
155 | +echo "*** done" | 69 | +echo "*** done" |
156 | +rm -f $seq.full | 70 | +rm -f $seq.full |
157 | +status=0 | 71 | +status=0 |
158 | diff --git a/tests/qemu-iotests/183.out b/tests/qemu-iotests/183.out | 72 | diff --git a/tests/qemu-iotests/297.out b/tests/qemu-iotests/297.out |
159 | new file mode 100644 | 73 | new file mode 100644 |
160 | index XXXXXXX..XXXXXXX | 74 | index XXXXXXX..XXXXXXX |
161 | --- /dev/null | 75 | --- /dev/null |
162 | +++ b/tests/qemu-iotests/183.out | 76 | +++ b/tests/qemu-iotests/297.out |
163 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ |
164 | +QA output created by 183 | 78 | +QA output created by 297 |
165 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | 79 | +Success: no issues found in 1 source file |
166 | +Formatting 'TEST_DIR/t.IMGFMT.dest', fmt=IMGFMT size=67108864 | ||
167 | + | ||
168 | +=== Starting VMs === | ||
169 | + | ||
170 | +{"return": {}} | ||
171 | +{"return": {}} | ||
172 | + | ||
173 | +=== Write something on the source === | ||
174 | + | ||
175 | +wrote 65536/65536 bytes at offset 0 | ||
176 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
177 | +{"return": ""} | ||
178 | +read 65536/65536 bytes at offset 0 | ||
179 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
180 | +{"return": ""} | ||
181 | + | ||
182 | +=== Do block migration to destination === | ||
183 | + | ||
184 | +{"return": {}} | ||
185 | +{"return": {"status": "postmigrate", "singlestep": false, "running": false}} | ||
186 | + | ||
187 | +=== Do some I/O on the destination === | ||
188 | + | ||
189 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "RESUME"} | ||
190 | +{"return": {"status": "running", "singlestep": false, "running": true}} | ||
191 | +read 65536/65536 bytes at offset 0 | ||
192 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
193 | +{"return": ""} | ||
194 | +wrote 65536/65536 bytes at offset 1048576 | ||
195 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
196 | +{"return": ""} | ||
197 | + | ||
198 | +=== Shut down and check image === | ||
199 | + | ||
200 | +{"return": {}} | ||
201 | +{"return": {}} | ||
202 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
203 | +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}} | ||
204 | +No errors were found on the image. | ||
205 | +No errors were found on the image. | ||
206 | +wrote 65536/65536 bytes at offset 1048576 | ||
207 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
208 | +Images are identical. | ||
209 | +*** done | 80 | +*** done |
210 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | 81 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group |
211 | index XXXXXXX..XXXXXXX 100644 | 82 | index XXXXXXX..XXXXXXX 100644 |
212 | --- a/tests/qemu-iotests/group | 83 | --- a/tests/qemu-iotests/group |
213 | +++ b/tests/qemu-iotests/group | 84 | +++ b/tests/qemu-iotests/group |
214 | @@ -XXX,XX +XXX,XX @@ | 85 | @@ -XXX,XX +XXX,XX @@ |
215 | 179 rw auto quick | 86 | 289 rw quick |
216 | 181 rw auto migration | 87 | 290 rw auto quick |
217 | 182 rw auto quick | 88 | 292 rw auto quick |
218 | +183 rw auto migration | 89 | +297 meta |
219 | -- | 90 | -- |
220 | 1.8.3.1 | 91 | 2.25.4 |
221 | 92 | ||
222 | 93 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Right now, all users of bdrv_make_empty() call the BlockDriver method | ||
4 | directly. That is not only bad style, it is also wrong, unless the | ||
5 | caller has a BdrvChild with a WRITE or WRITE_UNCHANGED permission. | ||
6 | (WRITE_UNCHANGED suffices, because callers generally use this function | ||
7 | to clear a node with a backing file after a commit operation.) | ||
8 | |||
9 | Introduce bdrv_make_empty() that verifies that it does. | ||
10 | |||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
12 | Message-Id: <20200429141126.85159-2-mreitz@redhat.com> | ||
13 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | --- | ||
16 | include/block/block.h | 1 + | ||
17 | block.c | 23 +++++++++++++++++++++++ | ||
18 | 2 files changed, 24 insertions(+) | ||
19 | |||
20 | diff --git a/include/block/block.h b/include/block/block.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/block/block.h | ||
23 | +++ b/include/block/block.h | ||
24 | @@ -XXX,XX +XXX,XX @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, | ||
25 | void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); | ||
26 | void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); | ||
27 | int bdrv_commit(BlockDriverState *bs); | ||
28 | +int bdrv_make_empty(BdrvChild *c, Error **errp); | ||
29 | int bdrv_change_backing_file(BlockDriverState *bs, | ||
30 | const char *backing_file, const char *backing_fmt); | ||
31 | void bdrv_register(BlockDriver *bdrv); | ||
32 | diff --git a/block.c b/block.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/block.c | ||
35 | +++ b/block.c | ||
36 | @@ -XXX,XX +XXX,XX @@ void bdrv_del_child(BlockDriverState *parent_bs, BdrvChild *child, Error **errp) | ||
37 | |||
38 | parent_bs->drv->bdrv_del_child(parent_bs, child, errp); | ||
39 | } | ||
40 | + | ||
41 | +int bdrv_make_empty(BdrvChild *c, Error **errp) | ||
42 | +{ | ||
43 | + BlockDriver *drv = c->bs->drv; | ||
44 | + int ret; | ||
45 | + | ||
46 | + assert(c->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)); | ||
47 | + | ||
48 | + if (!drv->bdrv_make_empty) { | ||
49 | + error_setg(errp, "%s does not support emptying nodes", | ||
50 | + drv->format_name); | ||
51 | + return -ENOTSUP; | ||
52 | + } | ||
53 | + | ||
54 | + ret = drv->bdrv_make_empty(c->bs); | ||
55 | + if (ret < 0) { | ||
56 | + error_setg_errno(errp, -ret, "Failed to empty %s", | ||
57 | + c->bs->filename); | ||
58 | + return ret; | ||
59 | + } | ||
60 | + | ||
61 | + return 0; | ||
62 | +} | ||
63 | -- | ||
64 | 2.25.4 | ||
65 | |||
66 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Two callers of BlockDriver.bdrv_make_empty() remain that should not call | ||
4 | this method directly. Both do not have access to a BdrvChild, but they | ||
5 | can use a BlockBackend, so we add this function that lets them use it. | ||
6 | |||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
8 | Message-Id: <20200429141126.85159-4-mreitz@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | include/sysemu/block-backend.h | 2 ++ | ||
13 | block/block-backend.c | 10 ++++++++++ | ||
14 | 2 files changed, 12 insertions(+) | ||
15 | |||
16 | diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/sysemu/block-backend.h | ||
19 | +++ b/include/sysemu/block-backend.h | ||
20 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, | ||
21 | |||
22 | const BdrvChild *blk_root(BlockBackend *blk); | ||
23 | |||
24 | +int blk_make_empty(BlockBackend *blk, Error **errp); | ||
25 | + | ||
26 | #endif | ||
27 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/block/block-backend.c | ||
30 | +++ b/block/block-backend.c | ||
31 | @@ -XXX,XX +XXX,XX @@ const BdrvChild *blk_root(BlockBackend *blk) | ||
32 | { | ||
33 | return blk->root; | ||
34 | } | ||
35 | + | ||
36 | +int blk_make_empty(BlockBackend *blk, Error **errp) | ||
37 | +{ | ||
38 | + if (!blk_is_available(blk)) { | ||
39 | + error_setg(errp, "No medium inserted"); | ||
40 | + return -ENOMEDIUM; | ||
41 | + } | ||
42 | + | ||
43 | + return bdrv_make_empty(blk->root, errp); | ||
44 | +} | ||
45 | -- | ||
46 | 2.25.4 | ||
47 | |||
48 | diff view generated by jsdifflib |
1 | The final bdrv_set_backing_hd() could be working on already freed nodes | 1 | From: Max Reitz <mreitz@redhat.com> |
---|---|---|---|
2 | because the commit job drops its references (through BlockBackends) to | ||
3 | both overlay_bs and top already a bit earlier. | ||
4 | 2 | ||
5 | One way to trigger the bug is hot unplugging a disk for which | 3 | bdrv_commit() already has a BlockBackend pointing to the BDS that we |
6 | blockdev_mark_auto_del() cancels the block job. | 4 | want to empty, it just has the wrong permissions. |
7 | 5 | ||
8 | Fix this by taking BDS-level references while we're still using the | 6 | qemu-img commit has no BlockBackend pointing to the old backing file |
9 | nodes. | 7 | yet, but introducing one is simple. |
10 | 8 | ||
9 | After this commit, bdrv_make_empty() is the only remaining caller of | ||
10 | BlockDriver.bdrv_make_empty(). | ||
11 | |||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | Message-Id: <20200429141126.85159-5-mreitz@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | [kwolf: Fixed up reference output for 098] | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
13 | --- | 17 | --- |
14 | block/commit.c | 7 +++++++ | 18 | block/commit.c | 16 +++++++++------- |
15 | 1 file changed, 7 insertions(+) | 19 | qemu-img.c | 19 ++++++++++++++----- |
20 | tests/qemu-iotests/098.out | 8 ++++---- | ||
21 | 3 files changed, 27 insertions(+), 16 deletions(-) | ||
16 | 22 | ||
17 | diff --git a/block/commit.c b/block/commit.c | 23 | diff --git a/block/commit.c b/block/commit.c |
18 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/commit.c | 25 | --- a/block/commit.c |
20 | +++ b/block/commit.c | 26 | +++ b/block/commit.c |
21 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 27 | @@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs) |
22 | int ret = data->ret; | 28 | } |
23 | bool remove_commit_top_bs = false; | 29 | |
24 | 30 | ctx = bdrv_get_aio_context(bs); | |
25 | + /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */ | 31 | - src = blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); |
26 | + bdrv_ref(top); | 32 | + /* WRITE_UNCHANGED is required for bdrv_make_empty() */ |
27 | + bdrv_ref(overlay_bs); | 33 | + src = blk_new(ctx, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED, |
34 | + BLK_PERM_ALL); | ||
35 | backing = blk_new(ctx, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL); | ||
36 | |||
37 | ret = blk_insert_bs(src, bs, &local_err); | ||
38 | @@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs) | ||
39 | } | ||
40 | } | ||
41 | |||
42 | - if (drv->bdrv_make_empty) { | ||
43 | - ret = drv->bdrv_make_empty(bs); | ||
44 | - if (ret < 0) { | ||
45 | - goto ro_cleanup; | ||
46 | - } | ||
47 | - blk_flush(src); | ||
48 | + ret = blk_make_empty(src, NULL); | ||
49 | + /* Ignore -ENOTSUP */ | ||
50 | + if (ret < 0 && ret != -ENOTSUP) { | ||
51 | + goto ro_cleanup; | ||
52 | } | ||
53 | |||
54 | + blk_flush(src); | ||
28 | + | 55 | + |
29 | /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before | 56 | /* |
30 | * the normal backing chain can be restored. */ | 57 | * Make sure all data we wrote to the backing device is actually |
31 | blk_unref(s->base); | 58 | * stable on disk. |
32 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 59 | diff --git a/qemu-img.c b/qemu-img.c |
33 | if (remove_commit_top_bs) { | 60 | index XXXXXXX..XXXXXXX 100644 |
34 | bdrv_set_backing_hd(overlay_bs, top, &error_abort); | 61 | --- a/qemu-img.c |
62 | +++ b/qemu-img.c | ||
63 | @@ -XXX,XX +XXX,XX @@ static int img_commit(int argc, char **argv) | ||
64 | goto unref_backing; | ||
35 | } | 65 | } |
66 | |||
67 | - if (!drop && bs->drv->bdrv_make_empty) { | ||
68 | - ret = bs->drv->bdrv_make_empty(bs); | ||
69 | - if (ret) { | ||
70 | - error_setg_errno(&local_err, -ret, "Could not empty %s", | ||
71 | - filename); | ||
72 | + if (!drop) { | ||
73 | + BlockBackend *old_backing_blk; | ||
36 | + | 74 | + |
37 | + bdrv_unref(overlay_bs); | 75 | + old_backing_blk = blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_ALL, |
38 | + bdrv_unref(top); | 76 | + &local_err); |
39 | } | 77 | + if (!old_backing_blk) { |
40 | 78 | + goto unref_backing; | |
41 | static void coroutine_fn commit_run(void *opaque) | 79 | + } |
80 | + ret = blk_make_empty(old_backing_blk, &local_err); | ||
81 | + blk_unref(old_backing_blk); | ||
82 | + if (ret == -ENOTSUP) { | ||
83 | + error_free(local_err); | ||
84 | + local_err = NULL; | ||
85 | + } else if (ret < 0) { | ||
86 | goto unref_backing; | ||
87 | } | ||
88 | } | ||
89 | diff --git a/tests/qemu-iotests/098.out b/tests/qemu-iotests/098.out | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/tests/qemu-iotests/098.out | ||
92 | +++ b/tests/qemu-iotests/098.out | ||
93 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | ||
94 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | ||
95 | wrote 65536/65536 bytes at offset 0 | ||
96 | 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
97 | -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
98 | +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
99 | No errors were found on the image. | ||
100 | |||
101 | === empty_image_prepare === | ||
102 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | ||
103 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | ||
104 | wrote 65536/65536 bytes at offset 0 | ||
105 | 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
106 | -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
107 | +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
108 | Leaked cluster 4 refcount=1 reference=0 | ||
109 | Leaked cluster 5 refcount=1 reference=0 | ||
110 | Repairing cluster 4 refcount=1 reference=0 | ||
111 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | ||
112 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | ||
113 | wrote 65536/65536 bytes at offset 0 | ||
114 | 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
115 | -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
116 | +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
117 | ERROR cluster 0 refcount=0 reference=1 | ||
118 | ERROR cluster 1 refcount=0 reference=1 | ||
119 | ERROR cluster 3 refcount=0 reference=1 | ||
120 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | ||
121 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | ||
122 | wrote 65536/65536 bytes at offset 0 | ||
123 | 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
124 | -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
125 | +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error | ||
126 | ERROR cluster 0 refcount=0 reference=1 | ||
127 | ERROR cluster 1 refcount=0 reference=1 | ||
128 | ERROR cluster 3 refcount=0 reference=1 | ||
42 | -- | 129 | -- |
43 | 1.8.3.1 | 130 | 2.25.4 |
44 | 131 | ||
45 | 132 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This is just a bandaid to keep tests/test-replication working after | ||
2 | bdrv_make_empty() starts to assert that we're not trying to call it on a | ||
3 | read-only child. | ||
1 | 4 | ||
5 | For the real solution in the future, replication should not steal the | ||
6 | BdrvChild from its backing file (this is never correct to do!), but | ||
7 | instead have its own child node references, with the appropriate | ||
8 | permissions. | ||
9 | |||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | block/replication.c | 13 +++++++++++-- | ||
13 | 1 file changed, 11 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/block/replication.c b/block/replication.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/replication.c | ||
18 | +++ b/block/replication.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) | ||
20 | return; | ||
21 | } | ||
22 | |||
23 | - ret = s->hidden_disk->bs->drv->bdrv_make_empty(s->hidden_disk->bs); | ||
24 | + BlockBackend *blk = blk_new(qemu_get_current_aio_context(), | ||
25 | + BLK_PERM_WRITE, BLK_PERM_ALL); | ||
26 | + blk_insert_bs(blk, s->hidden_disk->bs, &local_err); | ||
27 | + if (local_err) { | ||
28 | + error_propagate(errp, local_err); | ||
29 | + blk_unref(blk); | ||
30 | + return; | ||
31 | + } | ||
32 | + | ||
33 | + ret = blk_make_empty(blk, errp); | ||
34 | + blk_unref(blk); | ||
35 | if (ret < 0) { | ||
36 | - error_setg(errp, "Cannot make hidden disk empty"); | ||
37 | return; | ||
38 | } | ||
39 | } | ||
40 | -- | ||
41 | 2.25.4 | ||
42 | |||
43 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
6 | Message-Id: <20200429141126.85159-3-mreitz@redhat.com> | ||
7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | --- | ||
9 | block/replication.c | 3 +-- | ||
10 | block/vvfat.c | 4 +--- | ||
11 | 2 files changed, 2 insertions(+), 5 deletions(-) | ||
12 | |||
13 | diff --git a/block/replication.c b/block/replication.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/block/replication.c | ||
16 | +++ b/block/replication.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) | ||
18 | return; | ||
19 | } | ||
20 | |||
21 | - ret = s->active_disk->bs->drv->bdrv_make_empty(s->active_disk->bs); | ||
22 | + ret = bdrv_make_empty(s->active_disk, errp); | ||
23 | if (ret < 0) { | ||
24 | - error_setg(errp, "Cannot make active disk empty"); | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/block/vvfat.c | ||
31 | +++ b/block/vvfat.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int do_commit(BDRVVVFATState* s) | ||
33 | return ret; | ||
34 | } | ||
35 | |||
36 | - if (s->qcow->bs->drv && s->qcow->bs->drv->bdrv_make_empty) { | ||
37 | - s->qcow->bs->drv->bdrv_make_empty(s->qcow->bs); | ||
38 | - } | ||
39 | + bdrv_make_empty(s->qcow, NULL); | ||
40 | |||
41 | memset(s->used_clusters, 0, sector2cluster(s, s->sector_count)); | ||
42 | |||
43 | -- | ||
44 | 2.25.4 | ||
45 | |||
46 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | The commit, mirror, and blkreplay block nodes are filters, so they should | ||
4 | be marked as such. | ||
5 | |||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Message-Id: <20200513110544.176672-2-mreitz@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | --- | ||
10 | block/blkreplay.c | 1 + | ||
11 | block/commit.c | 2 ++ | ||
12 | block/mirror.c | 2 ++ | ||
13 | 3 files changed, 5 insertions(+) | ||
14 | |||
15 | diff --git a/block/blkreplay.c b/block/blkreplay.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/blkreplay.c | ||
18 | +++ b/block/blkreplay.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int blkreplay_snapshot_goto(BlockDriverState *bs, | ||
20 | static BlockDriver bdrv_blkreplay = { | ||
21 | .format_name = "blkreplay", | ||
22 | .instance_size = 0, | ||
23 | + .is_filter = true, | ||
24 | |||
25 | .bdrv_open = blkreplay_open, | ||
26 | .bdrv_child_perm = bdrv_filter_default_perms, | ||
27 | diff --git a/block/commit.c b/block/commit.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/block/commit.c | ||
30 | +++ b/block/commit.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_commit_top = { | ||
32 | .bdrv_co_block_status = bdrv_co_block_status_from_backing, | ||
33 | .bdrv_refresh_filename = bdrv_commit_top_refresh_filename, | ||
34 | .bdrv_child_perm = bdrv_commit_top_child_perm, | ||
35 | + | ||
36 | + .is_filter = true, | ||
37 | }; | ||
38 | |||
39 | void commit_start(const char *job_id, BlockDriverState *bs, | ||
40 | diff --git a/block/mirror.c b/block/mirror.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/block/mirror.c | ||
43 | +++ b/block/mirror.c | ||
44 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_mirror_top = { | ||
45 | .bdrv_co_block_status = bdrv_co_block_status_from_backing, | ||
46 | .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, | ||
47 | .bdrv_child_perm = bdrv_mirror_top_child_perm, | ||
48 | + | ||
49 | + .is_filter = true, | ||
50 | }; | ||
51 | |||
52 | static BlockJob *mirror_start_job( | ||
53 | -- | ||
54 | 2.25.4 | ||
55 | |||
56 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | We want to unify child_format and child_file at some point. One of the | ||
4 | important things that set format drivers apart from other drivers is | ||
5 | that they do not expect other format nodes under them (except in the | ||
6 | backing chain), i.e. we must not probe formats inside of formats. That | ||
7 | means we need something on which to distinguish format drivers from | ||
8 | others, and hence this flag. | ||
9 | |||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
13 | Message-Id: <20200513110544.176672-3-mreitz@redhat.com> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | --- | ||
16 | include/block/block_int.h | 7 +++++++ | ||
17 | block/bochs.c | 1 + | ||
18 | block/cloop.c | 1 + | ||
19 | block/crypto.c | 2 ++ | ||
20 | block/dmg.c | 1 + | ||
21 | block/parallels.c | 1 + | ||
22 | block/qcow.c | 1 + | ||
23 | block/qcow2.c | 1 + | ||
24 | block/qed.c | 1 + | ||
25 | block/raw-format.c | 1 + | ||
26 | block/vdi.c | 1 + | ||
27 | block/vhdx.c | 1 + | ||
28 | block/vmdk.c | 1 + | ||
29 | block/vpc.c | 1 + | ||
30 | 14 files changed, 21 insertions(+) | ||
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 BlockDriver { | ||
37 | * must implement them and return -ENOTSUP. | ||
38 | */ | ||
39 | bool is_filter; | ||
40 | + /* | ||
41 | + * Set to true if the BlockDriver is a format driver. Format nodes | ||
42 | + * generally do not expect their children to be other format nodes | ||
43 | + * (except for backing files), and so format probing is disabled | ||
44 | + * on those children. | ||
45 | + */ | ||
46 | + bool is_format; | ||
47 | /* | ||
48 | * Return true if @to_replace can be replaced by a BDS with the | ||
49 | * same data as @bs without it affecting @bs's behavior (that is, | ||
50 | diff --git a/block/bochs.c b/block/bochs.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/block/bochs.c | ||
53 | +++ b/block/bochs.c | ||
54 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_bochs = { | ||
55 | .bdrv_refresh_limits = bochs_refresh_limits, | ||
56 | .bdrv_co_preadv = bochs_co_preadv, | ||
57 | .bdrv_close = bochs_close, | ||
58 | + .is_format = true, | ||
59 | }; | ||
60 | |||
61 | static void bdrv_bochs_init(void) | ||
62 | diff --git a/block/cloop.c b/block/cloop.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/block/cloop.c | ||
65 | +++ b/block/cloop.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_cloop = { | ||
67 | .bdrv_refresh_limits = cloop_refresh_limits, | ||
68 | .bdrv_co_preadv = cloop_co_preadv, | ||
69 | .bdrv_close = cloop_close, | ||
70 | + .is_format = true, | ||
71 | }; | ||
72 | |||
73 | static void bdrv_cloop_init(void) | ||
74 | diff --git a/block/crypto.c b/block/crypto.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/block/crypto.c | ||
77 | +++ b/block/crypto.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_crypto_luks = { | ||
79 | .bdrv_get_info = block_crypto_get_info_luks, | ||
80 | .bdrv_get_specific_info = block_crypto_get_specific_info_luks, | ||
81 | |||
82 | + .is_format = true, | ||
83 | + | ||
84 | .strong_runtime_opts = block_crypto_strong_runtime_opts, | ||
85 | }; | ||
86 | |||
87 | diff --git a/block/dmg.c b/block/dmg.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/block/dmg.c | ||
90 | +++ b/block/dmg.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_dmg = { | ||
92 | .bdrv_child_perm = bdrv_format_default_perms, | ||
93 | .bdrv_co_preadv = dmg_co_preadv, | ||
94 | .bdrv_close = dmg_close, | ||
95 | + .is_format = true, | ||
96 | }; | ||
97 | |||
98 | static void bdrv_dmg_init(void) | ||
99 | diff --git a/block/parallels.c b/block/parallels.c | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/block/parallels.c | ||
102 | +++ b/block/parallels.c | ||
103 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_parallels = { | ||
104 | .bdrv_co_flush_to_os = parallels_co_flush_to_os, | ||
105 | .bdrv_co_readv = parallels_co_readv, | ||
106 | .bdrv_co_writev = parallels_co_writev, | ||
107 | + .is_format = true, | ||
108 | .supports_backing = true, | ||
109 | .bdrv_co_create = parallels_co_create, | ||
110 | .bdrv_co_create_opts = parallels_co_create_opts, | ||
111 | diff --git a/block/qcow.c b/block/qcow.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/block/qcow.c | ||
114 | +++ b/block/qcow.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qcow = { | ||
116 | .bdrv_co_create = qcow_co_create, | ||
117 | .bdrv_co_create_opts = qcow_co_create_opts, | ||
118 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
119 | + .is_format = true, | ||
120 | .supports_backing = true, | ||
121 | .bdrv_refresh_limits = qcow_refresh_limits, | ||
122 | |||
123 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/block/qcow2.c | ||
126 | +++ b/block/qcow2.c | ||
127 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_qcow2 = { | ||
128 | .bdrv_save_vmstate = qcow2_save_vmstate, | ||
129 | .bdrv_load_vmstate = qcow2_load_vmstate, | ||
130 | |||
131 | + .is_format = true, | ||
132 | .supports_backing = true, | ||
133 | .bdrv_change_backing_file = qcow2_change_backing_file, | ||
134 | |||
135 | diff --git a/block/qed.c b/block/qed.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/block/qed.c | ||
138 | +++ b/block/qed.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qed = { | ||
140 | .format_name = "qed", | ||
141 | .instance_size = sizeof(BDRVQEDState), | ||
142 | .create_opts = &qed_create_opts, | ||
143 | + .is_format = true, | ||
144 | .supports_backing = true, | ||
145 | |||
146 | .bdrv_probe = bdrv_qed_probe, | ||
147 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
148 | index XXXXXXX..XXXXXXX 100644 | ||
149 | --- a/block/raw-format.c | ||
150 | +++ b/block/raw-format.c | ||
151 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_raw = { | ||
152 | .bdrv_co_copy_range_to = &raw_co_copy_range_to, | ||
153 | .bdrv_co_truncate = &raw_co_truncate, | ||
154 | .bdrv_getlength = &raw_getlength, | ||
155 | + .is_format = true, | ||
156 | .has_variable_length = true, | ||
157 | .bdrv_measure = &raw_measure, | ||
158 | .bdrv_get_info = &raw_get_info, | ||
159 | diff --git a/block/vdi.c b/block/vdi.c | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/block/vdi.c | ||
162 | +++ b/block/vdi.c | ||
163 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vdi = { | ||
164 | |||
165 | .bdrv_get_info = vdi_get_info, | ||
166 | |||
167 | + .is_format = true, | ||
168 | .create_opts = &vdi_create_opts, | ||
169 | .bdrv_co_check = vdi_co_check, | ||
170 | }; | ||
171 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/block/vhdx.c | ||
174 | +++ b/block/vhdx.c | ||
175 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vhdx = { | ||
176 | .bdrv_co_check = vhdx_co_check, | ||
177 | .bdrv_has_zero_init = vhdx_has_zero_init, | ||
178 | |||
179 | + .is_format = true, | ||
180 | .create_opts = &vhdx_create_opts, | ||
181 | }; | ||
182 | |||
183 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
184 | index XXXXXXX..XXXXXXX 100644 | ||
185 | --- a/block/vmdk.c | ||
186 | +++ b/block/vmdk.c | ||
187 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vmdk = { | ||
188 | .bdrv_get_info = vmdk_get_info, | ||
189 | .bdrv_gather_child_options = vmdk_gather_child_options, | ||
190 | |||
191 | + .is_format = true, | ||
192 | .supports_backing = true, | ||
193 | .create_opts = &vmdk_create_opts, | ||
194 | }; | ||
195 | diff --git a/block/vpc.c b/block/vpc.c | ||
196 | index XXXXXXX..XXXXXXX 100644 | ||
197 | --- a/block/vpc.c | ||
198 | +++ b/block/vpc.c | ||
199 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vpc = { | ||
200 | |||
201 | .bdrv_get_info = vpc_get_info, | ||
202 | |||
203 | + .is_format = true, | ||
204 | .create_opts = &vpc_create_opts, | ||
205 | .bdrv_has_zero_init = vpc_has_zero_init, | ||
206 | .strong_runtime_opts = vpc_strong_runtime_opts, | ||
207 | -- | ||
208 | 2.25.4 | ||
209 | |||
210 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | This structure nearly only contains parent callbacks for child state | ||
4 | changes. It cannot really reflect a child's role, because different | ||
5 | roles may overlap (as we will see when real roles are introduced), and | ||
6 | because parents can have custom callbacks even when the child fulfills a | ||
7 | standard role. | ||
8 | |||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
11 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
12 | Message-Id: <20200513110544.176672-4-mreitz@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | include/block/block.h | 6 +- | ||
16 | include/block/block_int.h | 22 +++--- | ||
17 | block.c | 142 ++++++++++++++++++------------------ | ||
18 | block/backup-top.c | 8 +- | ||
19 | block/blkdebug.c | 4 +- | ||
20 | block/blklogwrites.c | 8 +- | ||
21 | block/block-backend.c | 6 +- | ||
22 | block/commit.c | 2 +- | ||
23 | block/copy-on-read.c | 2 +- | ||
24 | block/io.c | 22 +++--- | ||
25 | block/mirror.c | 2 +- | ||
26 | block/quorum.c | 2 +- | ||
27 | block/replication.c | 2 +- | ||
28 | block/vvfat.c | 6 +- | ||
29 | blockjob.c | 2 +- | ||
30 | tests/test-bdrv-drain.c | 36 ++++----- | ||
31 | tests/test-bdrv-graph-mod.c | 2 +- | ||
32 | 17 files changed, 141 insertions(+), 133 deletions(-) | ||
33 | |||
34 | diff --git a/include/block/block.h b/include/block/block.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/block/block.h | ||
37 | +++ b/include/block/block.h | ||
38 | @@ -XXX,XX +XXX,XX @@ | ||
39 | /* block.c */ | ||
40 | typedef struct BlockDriver BlockDriver; | ||
41 | typedef struct BdrvChild BdrvChild; | ||
42 | -typedef struct BdrvChildRole BdrvChildRole; | ||
43 | +typedef struct BdrvChildClass BdrvChildClass; | ||
44 | |||
45 | typedef struct BlockDriverInfo { | ||
46 | /* in bytes, 0 if irrelevant */ | ||
47 | @@ -XXX,XX +XXX,XX @@ int bdrv_parse_discard_flags(const char *mode, int *flags); | ||
48 | BdrvChild *bdrv_open_child(const char *filename, | ||
49 | QDict *options, const char *bdref_key, | ||
50 | BlockDriverState* parent, | ||
51 | - const BdrvChildRole *child_role, | ||
52 | + const BdrvChildClass *child_class, | ||
53 | bool allow_none, Error **errp); | ||
54 | BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); | ||
55 | void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
56 | @@ -XXX,XX +XXX,XX @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child); | ||
57 | BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
58 | BlockDriverState *child_bs, | ||
59 | const char *child_name, | ||
60 | - const BdrvChildRole *child_role, | ||
61 | + const BdrvChildClass *child_class, | ||
62 | Error **errp); | ||
63 | |||
64 | bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp); | ||
65 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/include/block/block_int.h | ||
68 | +++ b/include/block/block_int.h | ||
69 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
70 | * the parents in @parent_perm and @parent_shared. | ||
71 | * | ||
72 | * If @c is NULL, return the permissions for attaching a new child for the | ||
73 | - * given @role. | ||
74 | + * given @child_class. | ||
75 | * | ||
76 | * If @reopen_queue is non-NULL, don't return the currently needed | ||
77 | * permissions, but those that will be needed after applying the | ||
78 | * @reopen_queue. | ||
79 | */ | ||
80 | void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, | ||
81 | - const BdrvChildRole *role, | ||
82 | + const BdrvChildClass *child_class, | ||
83 | BlockReopenQueue *reopen_queue, | ||
84 | uint64_t parent_perm, uint64_t parent_shared, | ||
85 | uint64_t *nperm, uint64_t *nshared); | ||
86 | @@ -XXX,XX +XXX,XX @@ typedef struct BdrvAioNotifier { | ||
87 | QLIST_ENTRY(BdrvAioNotifier) list; | ||
88 | } BdrvAioNotifier; | ||
89 | |||
90 | -struct BdrvChildRole { | ||
91 | +struct BdrvChildClass { | ||
92 | /* If true, bdrv_replace_node() doesn't change the node this BdrvChild | ||
93 | * points to. */ | ||
94 | bool stay_at_node; | ||
95 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildRole { | ||
96 | void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); | ||
97 | }; | ||
98 | |||
99 | -extern const BdrvChildRole child_file; | ||
100 | -extern const BdrvChildRole child_format; | ||
101 | -extern const BdrvChildRole child_backing; | ||
102 | +extern const BdrvChildClass child_file; | ||
103 | +extern const BdrvChildClass child_format; | ||
104 | +extern const BdrvChildClass child_backing; | ||
105 | |||
106 | struct BdrvChild { | ||
107 | BlockDriverState *bs; | ||
108 | char *name; | ||
109 | - const BdrvChildRole *role; | ||
110 | + const BdrvChildClass *klass; | ||
111 | void *opaque; | ||
112 | |||
113 | /** | ||
114 | @@ -XXX,XX +XXX,XX @@ struct BdrvChild { | ||
115 | |||
116 | /* | ||
117 | * How many times the parent of this child has been drained | ||
118 | - * (through role->drained_*). | ||
119 | + * (through klass->drained_*). | ||
120 | * Usually, this is equal to bs->quiesce_counter (potentially | ||
121 | * reduced by bdrv_drain_all_count). It may differ while the | ||
122 | * child is entering or leaving a drained section. | ||
123 | @@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, | ||
124 | |||
125 | BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
126 | const char *child_name, | ||
127 | - const BdrvChildRole *child_role, | ||
128 | + const BdrvChildClass *child_class, | ||
129 | AioContext *ctx, | ||
130 | uint64_t perm, uint64_t shared_perm, | ||
131 | void *opaque, Error **errp); | ||
132 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); | ||
133 | * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to | ||
134 | * all children */ | ||
135 | void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
136 | - const BdrvChildRole *role, | ||
137 | + const BdrvChildClass *child_class, | ||
138 | BlockReopenQueue *reopen_queue, | ||
139 | uint64_t perm, uint64_t shared, | ||
140 | uint64_t *nperm, uint64_t *nshared); | ||
141 | @@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
142 | * requires WRITE | RESIZE for read-write images, always requires | ||
143 | * CONSISTENT_READ and doesn't share WRITE. */ | ||
144 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
145 | - const BdrvChildRole *role, | ||
146 | + const BdrvChildClass *child_class, | ||
147 | BlockReopenQueue *reopen_queue, | ||
148 | uint64_t perm, uint64_t shared, | ||
149 | uint64_t *nperm, uint64_t *nshared); | ||
150 | diff --git a/block.c b/block.c | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/block.c | ||
153 | +++ b/block.c | ||
154 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
155 | const char *reference, | ||
156 | QDict *options, int flags, | ||
157 | BlockDriverState *parent, | ||
158 | - const BdrvChildRole *child_role, | ||
159 | + const BdrvChildClass *child_class, | ||
160 | Error **errp); | ||
161 | |||
162 | /* If non-zero, use only whitelisted block drivers */ | ||
163 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options, | ||
164 | *child_flags = flags; | ||
165 | } | ||
166 | |||
167 | -const BdrvChildRole child_file = { | ||
168 | +const BdrvChildClass child_file = { | ||
169 | .parent_is_bds = true, | ||
170 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
171 | .inherit_options = bdrv_inherited_options, | ||
172 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, | ||
173 | *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); | ||
174 | } | ||
175 | |||
176 | -const BdrvChildRole child_format = { | ||
177 | +const BdrvChildClass child_format = { | ||
178 | .parent_is_bds = true, | ||
179 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
180 | .inherit_options = bdrv_inherited_fmt_options, | ||
181 | @@ -XXX,XX +XXX,XX @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | -const BdrvChildRole child_backing = { | ||
186 | +const BdrvChildClass child_backing = { | ||
187 | .parent_is_bds = true, | ||
188 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
189 | .attach = bdrv_backing_attach, | ||
190 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_writable(BlockDriverState *bs) | ||
191 | } | ||
192 | |||
193 | static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
194 | - BdrvChild *c, const BdrvChildRole *role, | ||
195 | + BdrvChild *c, const BdrvChildClass *child_class, | ||
196 | BlockReopenQueue *reopen_queue, | ||
197 | uint64_t parent_perm, uint64_t parent_shared, | ||
198 | uint64_t *nperm, uint64_t *nshared) | ||
199 | { | ||
200 | assert(bs->drv && bs->drv->bdrv_child_perm); | ||
201 | - bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, | ||
202 | + bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue, | ||
203 | parent_perm, parent_shared, | ||
204 | nperm, nshared); | ||
205 | /* TODO Take force_share from reopen_queue */ | ||
206 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
207 | uint64_t cur_perm, cur_shared; | ||
208 | bool child_tighten_restr; | ||
209 | |||
210 | - bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
211 | + bdrv_child_perm(bs, c->bs, c, c->klass, q, | ||
212 | cumulative_perms, cumulative_shared_perms, | ||
213 | &cur_perm, &cur_shared); | ||
214 | ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, | ||
215 | @@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, | ||
216 | /* Update all children */ | ||
217 | QLIST_FOREACH(c, &bs->children, next) { | ||
218 | uint64_t cur_perm, cur_shared; | ||
219 | - bdrv_child_perm(bs, c->bs, c, c->role, NULL, | ||
220 | + bdrv_child_perm(bs, c->bs, c, c->klass, NULL, | ||
221 | cumulative_perms, cumulative_shared_perms, | ||
222 | &cur_perm, &cur_shared); | ||
223 | bdrv_child_set_perm(c, cur_perm, cur_shared); | ||
224 | @@ -XXX,XX +XXX,XX @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, | ||
225 | |||
226 | static char *bdrv_child_user_desc(BdrvChild *c) | ||
227 | { | ||
228 | - if (c->role->get_parent_desc) { | ||
229 | - return c->role->get_parent_desc(c); | ||
230 | + if (c->klass->get_parent_desc) { | ||
231 | + return c->klass->get_parent_desc(c); | ||
232 | } | ||
233 | |||
234 | return g_strdup("another user"); | ||
235 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
236 | uint64_t perms, shared; | ||
237 | |||
238 | bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); | ||
239 | - bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared, | ||
240 | + bdrv_child_perm(bs, c->bs, c, c->klass, NULL, parent_perms, parent_shared, | ||
241 | &perms, &shared); | ||
242 | |||
243 | return bdrv_child_try_set_perm(c, perms, shared, errp); | ||
244 | } | ||
245 | |||
246 | void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
247 | - const BdrvChildRole *role, | ||
248 | + const BdrvChildClass *child_class, | ||
249 | BlockReopenQueue *reopen_queue, | ||
250 | uint64_t perm, uint64_t shared, | ||
251 | uint64_t *nperm, uint64_t *nshared) | ||
252 | @@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
253 | } | ||
254 | |||
255 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
256 | - const BdrvChildRole *role, | ||
257 | + const BdrvChildClass *child_class, | ||
258 | BlockReopenQueue *reopen_queue, | ||
259 | uint64_t perm, uint64_t shared, | ||
260 | uint64_t *nperm, uint64_t *nshared) | ||
261 | { | ||
262 | - bool backing = (role == &child_backing); | ||
263 | - assert(role == &child_backing || role == &child_file); | ||
264 | + bool backing = (child_class == &child_backing); | ||
265 | + assert(child_class == &child_backing || child_class == &child_file); | ||
266 | |||
267 | if (!backing) { | ||
268 | int flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
269 | |||
270 | /* Apart from the modifications below, the same permissions are | ||
271 | * forwarded and left alone as for filters */ | ||
272 | - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, | ||
273 | - &perm, &shared); | ||
274 | + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, | ||
275 | + perm, shared, &perm, &shared); | ||
276 | |||
277 | /* Format drivers may touch metadata even if the guest doesn't write */ | ||
278 | if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { | ||
279 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
280 | * If the new child node is drained but the old one was not, flush | ||
281 | * all outstanding requests to the old child node. | ||
282 | */ | ||
283 | - while (drain_saldo > 0 && child->role->drained_begin) { | ||
284 | + while (drain_saldo > 0 && child->klass->drained_begin) { | ||
285 | bdrv_parent_drained_begin_single(child, true); | ||
286 | drain_saldo--; | ||
287 | } | ||
288 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
289 | /* Detach first so that the recursive drain sections coming from @child | ||
290 | * are already gone and we only end the drain sections that came from | ||
291 | * elsewhere. */ | ||
292 | - if (child->role->detach) { | ||
293 | - child->role->detach(child); | ||
294 | + if (child->klass->detach) { | ||
295 | + child->klass->detach(child); | ||
296 | } | ||
297 | QLIST_REMOVE(child, next_parent); | ||
298 | } | ||
299 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
300 | /* Attach only after starting new drained sections, so that recursive | ||
301 | * drain sections coming from @child don't get an extra .drained_begin | ||
302 | * callback. */ | ||
303 | - if (child->role->attach) { | ||
304 | - child->role->attach(child); | ||
305 | + if (child->klass->attach) { | ||
306 | + child->klass->attach(child); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
311 | * If the old child node was drained but the new one is not, allow | ||
312 | * requests to come in only after the new node has been attached. | ||
313 | */ | ||
314 | - while (drain_saldo < 0 && child->role->drained_end) { | ||
315 | + while (drain_saldo < 0 && child->klass->drained_end) { | ||
316 | bdrv_parent_drained_end_single(child); | ||
317 | drain_saldo++; | ||
318 | } | ||
319 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) | ||
320 | */ | ||
321 | BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
322 | const char *child_name, | ||
323 | - const BdrvChildRole *child_role, | ||
324 | + const BdrvChildClass *child_class, | ||
325 | AioContext *ctx, | ||
326 | uint64_t perm, uint64_t shared_perm, | ||
327 | void *opaque, Error **errp) | ||
328 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
329 | *child = (BdrvChild) { | ||
330 | .bs = NULL, | ||
331 | .name = g_strdup(child_name), | ||
332 | - .role = child_role, | ||
333 | + .klass = child_class, | ||
334 | .perm = perm, | ||
335 | .shared_perm = shared_perm, | ||
336 | .opaque = opaque, | ||
337 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
338 | * try moving the parent into the AioContext of child_bs instead. */ | ||
339 | if (bdrv_get_aio_context(child_bs) != ctx) { | ||
340 | ret = bdrv_try_set_aio_context(child_bs, ctx, &local_err); | ||
341 | - if (ret < 0 && child_role->can_set_aio_ctx) { | ||
342 | + if (ret < 0 && child_class->can_set_aio_ctx) { | ||
343 | GSList *ignore = g_slist_prepend(NULL, child); | ||
344 | ctx = bdrv_get_aio_context(child_bs); | ||
345 | - if (child_role->can_set_aio_ctx(child, ctx, &ignore, NULL)) { | ||
346 | + if (child_class->can_set_aio_ctx(child, ctx, &ignore, NULL)) { | ||
347 | error_free(local_err); | ||
348 | ret = 0; | ||
349 | g_slist_free(ignore); | ||
350 | ignore = g_slist_prepend(NULL, child); | ||
351 | - child_role->set_aio_ctx(child, ctx, &ignore); | ||
352 | + child_class->set_aio_ctx(child, ctx, &ignore); | ||
353 | } | ||
354 | g_slist_free(ignore); | ||
355 | } | ||
356 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
357 | BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
358 | BlockDriverState *child_bs, | ||
359 | const char *child_name, | ||
360 | - const BdrvChildRole *child_role, | ||
361 | + const BdrvChildClass *child_class, | ||
362 | Error **errp) | ||
363 | { | ||
364 | BdrvChild *child; | ||
365 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
366 | bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); | ||
367 | |||
368 | assert(parent_bs->drv); | ||
369 | - bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, | ||
370 | + bdrv_child_perm(parent_bs, child_bs, NULL, child_class, NULL, | ||
371 | perm, shared_perm, &perm, &shared_perm); | ||
372 | |||
373 | - child = bdrv_root_attach_child(child_bs, child_name, child_role, | ||
374 | + child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
375 | bdrv_get_aio_context(parent_bs), | ||
376 | perm, shared_perm, parent_bs, errp); | ||
377 | if (child == NULL) { | ||
378 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) | ||
379 | { | ||
380 | BdrvChild *c; | ||
381 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
382 | - if (c->role->change_media) { | ||
383 | - c->role->change_media(c, load); | ||
384 | + if (c->klass->change_media) { | ||
385 | + c->klass->change_media(c, load); | ||
386 | } | ||
387 | } | ||
388 | } | ||
389 | @@ -XXX,XX +XXX,XX @@ free_exit: | ||
390 | |||
391 | static BlockDriverState * | ||
392 | bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | ||
393 | - BlockDriverState *parent, const BdrvChildRole *child_role, | ||
394 | + BlockDriverState *parent, const BdrvChildClass *child_class, | ||
395 | bool allow_none, Error **errp) | ||
396 | { | ||
397 | BlockDriverState *bs = NULL; | ||
398 | @@ -XXX,XX +XXX,XX @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | ||
399 | char *bdref_key_dot; | ||
400 | const char *reference; | ||
401 | |||
402 | - assert(child_role != NULL); | ||
403 | + assert(child_class != NULL); | ||
404 | |||
405 | bdref_key_dot = g_strdup_printf("%s.", bdref_key); | ||
406 | qdict_extract_subqdict(options, &image_options, bdref_key_dot); | ||
407 | @@ -XXX,XX +XXX,XX @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | ||
408 | } | ||
409 | |||
410 | bs = bdrv_open_inherit(filename, reference, image_options, 0, | ||
411 | - parent, child_role, errp); | ||
412 | + parent, child_class, errp); | ||
413 | if (!bs) { | ||
414 | goto done; | ||
415 | } | ||
416 | @@ -XXX,XX +XXX,XX @@ done: | ||
417 | BdrvChild *bdrv_open_child(const char *filename, | ||
418 | QDict *options, const char *bdref_key, | ||
419 | BlockDriverState *parent, | ||
420 | - const BdrvChildRole *child_role, | ||
421 | + const BdrvChildClass *child_class, | ||
422 | bool allow_none, Error **errp) | ||
423 | { | ||
424 | BlockDriverState *bs; | ||
425 | |||
426 | - bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role, | ||
427 | + bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class, | ||
428 | allow_none, errp); | ||
429 | if (bs == NULL) { | ||
430 | return NULL; | ||
431 | } | ||
432 | |||
433 | - return bdrv_attach_child(parent, bs, bdref_key, child_role, errp); | ||
434 | + return bdrv_attach_child(parent, bs, bdref_key, child_class, errp); | ||
435 | } | ||
436 | |||
437 | -/* TODO Future callers may need to specify parent/child_role in order for | ||
438 | - * option inheritance to work. Existing callers use it for the root node. */ | ||
439 | +/* | ||
440 | + * TODO Future callers may need to specify parent/child_class in order for | ||
441 | + * option inheritance to work. Existing callers use it for the root node. | ||
442 | + */ | ||
443 | BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) | ||
444 | { | ||
445 | BlockDriverState *bs = NULL; | ||
446 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
447 | const char *reference, | ||
448 | QDict *options, int flags, | ||
449 | BlockDriverState *parent, | ||
450 | - const BdrvChildRole *child_role, | ||
451 | + const BdrvChildClass *child_class, | ||
452 | Error **errp) | ||
453 | { | ||
454 | int ret; | ||
455 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
456 | QDict *snapshot_options = NULL; | ||
457 | int snapshot_flags = 0; | ||
458 | |||
459 | - assert(!child_role || !flags); | ||
460 | - assert(!child_role == !parent); | ||
461 | + assert(!child_class || !flags); | ||
462 | + assert(!child_class == !parent); | ||
463 | |||
464 | if (reference) { | ||
465 | bool options_non_empty = options ? qdict_size(options) : false; | ||
466 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
467 | |||
468 | bs->explicit_options = qdict_clone_shallow(options); | ||
469 | |||
470 | - if (child_role) { | ||
471 | + if (child_class) { | ||
472 | bs->inherits_from = parent; | ||
473 | - child_role->inherit_options(&flags, options, | ||
474 | - parent->open_flags, parent->options); | ||
475 | + child_class->inherit_options(&flags, options, | ||
476 | + parent->open_flags, parent->options); | ||
477 | } | ||
478 | |||
479 | ret = bdrv_fill_options(&options, filename, &flags, &local_err); | ||
480 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_recurse_has_child(BlockDriverState *bs, | ||
481 | static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
482 | BlockDriverState *bs, | ||
483 | QDict *options, | ||
484 | - const BdrvChildRole *role, | ||
485 | + const BdrvChildClass *klass, | ||
486 | QDict *parent_options, | ||
487 | int parent_flags, | ||
488 | bool keep_old_opts) | ||
489 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
490 | /* Inherit from parent node */ | ||
491 | if (parent_options) { | ||
492 | flags = 0; | ||
493 | - role->inherit_options(&flags, options, parent_flags, parent_options); | ||
494 | + klass->inherit_options(&flags, options, parent_flags, parent_options); | ||
495 | } else { | ||
496 | flags = bdrv_get_flags(bs); | ||
497 | } | ||
498 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
499 | } | ||
500 | |||
501 | bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, | ||
502 | - child->role, options, flags, child_keep_old); | ||
503 | + child->klass, options, flags, child_keep_old); | ||
504 | } | ||
505 | |||
506 | return bs_queue; | ||
507 | @@ -XXX,XX +XXX,XX @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, | ||
508 | } else { | ||
509 | uint64_t nperm, nshared; | ||
510 | |||
511 | - bdrv_child_perm(parent->state.bs, bs, c, c->role, q, | ||
512 | + bdrv_child_perm(parent->state.bs, bs, c, c->klass, q, | ||
513 | parent->state.perm, parent->state.shared_perm, | ||
514 | &nperm, &nshared); | ||
515 | |||
516 | @@ -XXX,XX +XXX,XX @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) | ||
517 | GHashTable *found; | ||
518 | bool ret; | ||
519 | |||
520 | - if (c->role->stay_at_node) { | ||
521 | + if (c->klass->stay_at_node) { | ||
522 | return false; | ||
523 | } | ||
524 | |||
525 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, | ||
526 | } | ||
527 | |||
528 | /* If so, update the backing file path in the image file */ | ||
529 | - if (c->role->update_filename) { | ||
530 | - ret = c->role->update_filename(c, base, backing_file_str, | ||
531 | - &local_err); | ||
532 | + if (c->klass->update_filename) { | ||
533 | + ret = c->klass->update_filename(c, base, backing_file_str, | ||
534 | + &local_err); | ||
535 | if (ret < 0) { | ||
536 | bdrv_abort_perm_update(base); | ||
537 | error_report_err(local_err); | ||
538 | @@ -XXX,XX +XXX,XX @@ const char *bdrv_get_parent_name(const BlockDriverState *bs) | ||
539 | |||
540 | /* If multiple parents have a name, just pick the first one. */ | ||
541 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
542 | - if (c->role->get_name) { | ||
543 | - name = c->role->get_name(c); | ||
544 | + if (c->klass->get_name) { | ||
545 | + name = c->klass->get_name(c); | ||
546 | if (name && *name) { | ||
547 | return name; | ||
548 | } | ||
549 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, | ||
550 | } | ||
551 | |||
552 | QLIST_FOREACH(parent, &bs->parents, next_parent) { | ||
553 | - if (parent->role->activate) { | ||
554 | - parent->role->activate(parent, &local_err); | ||
555 | + if (parent->klass->activate) { | ||
556 | + parent->klass->activate(parent, &local_err); | ||
557 | if (local_err) { | ||
558 | bs->open_flags |= BDRV_O_INACTIVE; | ||
559 | error_propagate(errp, local_err); | ||
560 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active) | ||
561 | BdrvChild *parent; | ||
562 | |||
563 | QLIST_FOREACH(parent, &bs->parents, next_parent) { | ||
564 | - if (parent->role->parent_is_bds) { | ||
565 | + if (parent->klass->parent_is_bds) { | ||
566 | BlockDriverState *parent_bs = parent->opaque; | ||
567 | if (!only_active || !(parent_bs->open_flags & BDRV_O_INACTIVE)) { | ||
568 | return true; | ||
569 | @@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) | ||
570 | } | ||
571 | |||
572 | QLIST_FOREACH(parent, &bs->parents, next_parent) { | ||
573 | - if (parent->role->inactivate) { | ||
574 | - ret = parent->role->inactivate(parent); | ||
575 | + if (parent->klass->inactivate) { | ||
576 | + ret = parent->klass->inactivate(parent); | ||
577 | if (ret < 0) { | ||
578 | return ret; | ||
579 | } | ||
580 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, | ||
581 | if (g_slist_find(*ignore, child)) { | ||
582 | continue; | ||
583 | } | ||
584 | - assert(child->role->set_aio_ctx); | ||
585 | + assert(child->klass->set_aio_ctx); | ||
586 | *ignore = g_slist_prepend(*ignore, child); | ||
587 | - child->role->set_aio_ctx(child, new_context, ignore); | ||
588 | + child->klass->set_aio_ctx(child, new_context, ignore); | ||
589 | } | ||
590 | |||
591 | bdrv_detach_aio_context(bs); | ||
592 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, | ||
593 | } | ||
594 | *ignore = g_slist_prepend(*ignore, c); | ||
595 | |||
596 | - /* A BdrvChildRole that doesn't handle AioContext changes cannot | ||
597 | - * tolerate any AioContext changes */ | ||
598 | - if (!c->role->can_set_aio_ctx) { | ||
599 | + /* | ||
600 | + * A BdrvChildClass that doesn't handle AioContext changes cannot | ||
601 | + * tolerate any AioContext changes | ||
602 | + */ | ||
603 | + if (!c->klass->can_set_aio_ctx) { | ||
604 | char *user = bdrv_child_user_desc(c); | ||
605 | error_setg(errp, "Changing iothreads is not supported by %s", user); | ||
606 | g_free(user); | ||
607 | return false; | ||
608 | } | ||
609 | - if (!c->role->can_set_aio_ctx(c, ctx, ignore, errp)) { | ||
610 | + if (!c->klass->can_set_aio_ctx(c, ctx, ignore, errp)) { | ||
611 | assert(!errp || *errp); | ||
612 | return false; | ||
613 | } | ||
614 | @@ -XXX,XX +XXX,XX @@ void bdrv_refresh_filename(BlockDriverState *bs) | ||
615 | drv->bdrv_gather_child_options(bs, opts, backing_overridden); | ||
616 | } else { | ||
617 | QLIST_FOREACH(child, &bs->children, next) { | ||
618 | - if (child->role == &child_backing && !backing_overridden) { | ||
619 | + if (child->klass == &child_backing && !backing_overridden) { | ||
620 | /* We can skip the backing BDS if it has not been overridden */ | ||
621 | continue; | ||
622 | } | ||
623 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
624 | index XXXXXXX..XXXXXXX 100644 | ||
625 | --- a/block/backup-top.c | ||
626 | +++ b/block/backup-top.c | ||
627 | @@ -XXX,XX +XXX,XX @@ static void backup_top_refresh_filename(BlockDriverState *bs) | ||
628 | } | ||
629 | |||
630 | static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
631 | - const BdrvChildRole *role, | ||
632 | + const BdrvChildClass *child_class, | ||
633 | BlockReopenQueue *reopen_queue, | ||
634 | uint64_t perm, uint64_t shared, | ||
635 | uint64_t *nperm, uint64_t *nshared) | ||
636 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
637 | return; | ||
638 | } | ||
639 | |||
640 | - if (role == &child_file) { | ||
641 | + if (child_class == &child_file) { | ||
642 | /* | ||
643 | * Target child | ||
644 | * | ||
645 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
646 | *nperm = BLK_PERM_WRITE; | ||
647 | } else { | ||
648 | /* Source child */ | ||
649 | - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, | ||
650 | - nperm, nshared); | ||
651 | + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, | ||
652 | + perm, shared, nperm, nshared); | ||
653 | |||
654 | if (perm & BLK_PERM_WRITE) { | ||
655 | *nperm = *nperm | BLK_PERM_CONSISTENT_READ; | ||
656 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
657 | index XXXXXXX..XXXXXXX 100644 | ||
658 | --- a/block/blkdebug.c | ||
659 | +++ b/block/blkdebug.c | ||
660 | @@ -XXX,XX +XXX,XX @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, | ||
661 | } | ||
662 | |||
663 | static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
664 | - const BdrvChildRole *role, | ||
665 | + const BdrvChildClass *child_class, | ||
666 | BlockReopenQueue *reopen_queue, | ||
667 | uint64_t perm, uint64_t shared, | ||
668 | uint64_t *nperm, uint64_t *nshared) | ||
669 | { | ||
670 | BDRVBlkdebugState *s = bs->opaque; | ||
671 | |||
672 | - bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, | ||
673 | + bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared, | ||
674 | nperm, nshared); | ||
675 | |||
676 | *nperm |= s->take_child_perms; | ||
677 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
678 | index XXXXXXX..XXXXXXX 100644 | ||
679 | --- a/block/blklogwrites.c | ||
680 | +++ b/block/blklogwrites.c | ||
681 | @@ -XXX,XX +XXX,XX @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) | ||
682 | } | ||
683 | |||
684 | static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
685 | - const BdrvChildRole *role, | ||
686 | + const BdrvChildClass *child_class, | ||
687 | BlockReopenQueue *ro_q, | ||
688 | uint64_t perm, uint64_t shrd, | ||
689 | uint64_t *nperm, uint64_t *nshrd) | ||
690 | @@ -XXX,XX +XXX,XX @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
691 | } | ||
692 | |||
693 | if (!strcmp(c->name, "log")) { | ||
694 | - bdrv_format_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd); | ||
695 | + bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, | ||
696 | + nshrd); | ||
697 | } else { | ||
698 | - bdrv_filter_default_perms(bs, c, role, ro_q, perm, shrd, nperm, nshrd); | ||
699 | + bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, | ||
700 | + nshrd); | ||
701 | } | ||
702 | } | ||
703 | |||
704 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
705 | index XXXXXXX..XXXXXXX 100644 | ||
706 | --- a/block/block-backend.c | ||
707 | +++ b/block/block-backend.c | ||
708 | @@ -XXX,XX +XXX,XX @@ static void blk_root_detach(BdrvChild *child) | ||
709 | } | ||
710 | } | ||
711 | |||
712 | -static const BdrvChildRole child_root = { | ||
713 | +static const BdrvChildClass child_root = { | ||
714 | .inherit_options = blk_root_inherit_options, | ||
715 | |||
716 | .change_media = blk_root_change_media, | ||
717 | @@ -XXX,XX +XXX,XX @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs) | ||
718 | { | ||
719 | BdrvChild *child; | ||
720 | QLIST_FOREACH(child, &bs->parents, next_parent) { | ||
721 | - if (child->role == &child_root) { | ||
722 | + if (child->klass == &child_root) { | ||
723 | return child->opaque; | ||
724 | } | ||
725 | } | ||
726 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_root_node(BlockDriverState *bs) | ||
727 | BdrvChild *c; | ||
728 | |||
729 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
730 | - if (c->role != &child_root) { | ||
731 | + if (c->klass != &child_root) { | ||
732 | return false; | ||
733 | } | ||
734 | } | ||
735 | diff --git a/block/commit.c b/block/commit.c | ||
736 | index XXXXXXX..XXXXXXX 100644 | ||
737 | --- a/block/commit.c | ||
738 | +++ b/block/commit.c | ||
739 | @@ -XXX,XX +XXX,XX @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) | ||
740 | } | ||
741 | |||
742 | static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
743 | - const BdrvChildRole *role, | ||
744 | + const BdrvChildClass *child_class, | ||
745 | BlockReopenQueue *reopen_queue, | ||
746 | uint64_t perm, uint64_t shared, | ||
747 | uint64_t *nperm, uint64_t *nshared) | ||
748 | diff --git a/block/copy-on-read.c b/block/copy-on-read.c | ||
749 | index XXXXXXX..XXXXXXX 100644 | ||
750 | --- a/block/copy-on-read.c | ||
751 | +++ b/block/copy-on-read.c | ||
752 | @@ -XXX,XX +XXX,XX @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, | ||
753 | #define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) | ||
754 | |||
755 | static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
756 | - const BdrvChildRole *role, | ||
757 | + const BdrvChildClass *child_class, | ||
758 | BlockReopenQueue *reopen_queue, | ||
759 | uint64_t perm, uint64_t shared, | ||
760 | uint64_t *nperm, uint64_t *nshared) | ||
761 | diff --git a/block/io.c b/block/io.c | ||
762 | index XXXXXXX..XXXXXXX 100644 | ||
763 | --- a/block/io.c | ||
764 | +++ b/block/io.c | ||
765 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore, | ||
766 | BdrvChild *c, *next; | ||
767 | |||
768 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { | ||
769 | - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { | ||
770 | + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { | ||
771 | continue; | ||
772 | } | ||
773 | bdrv_parent_drained_begin_single(c, false); | ||
774 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c, | ||
775 | { | ||
776 | assert(c->parent_quiesce_counter > 0); | ||
777 | c->parent_quiesce_counter--; | ||
778 | - if (c->role->drained_end) { | ||
779 | - c->role->drained_end(c, drained_end_counter); | ||
780 | + if (c->klass->drained_end) { | ||
781 | + c->klass->drained_end(c, drained_end_counter); | ||
782 | } | ||
783 | } | ||
784 | |||
785 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore, | ||
786 | BdrvChild *c; | ||
787 | |||
788 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
789 | - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { | ||
790 | + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { | ||
791 | continue; | ||
792 | } | ||
793 | bdrv_parent_drained_end_single_no_poll(c, drained_end_counter); | ||
794 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore, | ||
795 | |||
796 | static bool bdrv_parent_drained_poll_single(BdrvChild *c) | ||
797 | { | ||
798 | - if (c->role->drained_poll) { | ||
799 | - return c->role->drained_poll(c); | ||
800 | + if (c->klass->drained_poll) { | ||
801 | + return c->klass->drained_poll(c); | ||
802 | } | ||
803 | return false; | ||
804 | } | ||
805 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore, | ||
806 | bool busy = false; | ||
807 | |||
808 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { | ||
809 | - if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { | ||
810 | + if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) { | ||
811 | continue; | ||
812 | } | ||
813 | busy |= bdrv_parent_drained_poll_single(c); | ||
814 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore, | ||
815 | void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) | ||
816 | { | ||
817 | c->parent_quiesce_counter++; | ||
818 | - if (c->role->drained_begin) { | ||
819 | - c->role->drained_begin(c); | ||
820 | + if (c->klass->drained_begin) { | ||
821 | + c->klass->drained_begin(c); | ||
822 | } | ||
823 | if (poll) { | ||
824 | BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c)); | ||
825 | @@ -XXX,XX +XXX,XX @@ static void bdrv_parent_cb_resize(BlockDriverState *bs) | ||
826 | { | ||
827 | BdrvChild *c; | ||
828 | QLIST_FOREACH(c, &bs->parents, next_parent) { | ||
829 | - if (c->role->resize) { | ||
830 | - c->role->resize(c); | ||
831 | + if (c->klass->resize) { | ||
832 | + c->klass->resize(c); | ||
833 | } | ||
834 | } | ||
835 | } | ||
836 | diff --git a/block/mirror.c b/block/mirror.c | ||
837 | index XXXXXXX..XXXXXXX 100644 | ||
838 | --- a/block/mirror.c | ||
839 | +++ b/block/mirror.c | ||
840 | @@ -XXX,XX +XXX,XX @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) | ||
841 | } | ||
842 | |||
843 | static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
844 | - const BdrvChildRole *role, | ||
845 | + const BdrvChildClass *child_class, | ||
846 | BlockReopenQueue *reopen_queue, | ||
847 | uint64_t perm, uint64_t shared, | ||
848 | uint64_t *nperm, uint64_t *nshared) | ||
849 | diff --git a/block/quorum.c b/block/quorum.c | ||
850 | index XXXXXXX..XXXXXXX 100644 | ||
851 | --- a/block/quorum.c | ||
852 | +++ b/block/quorum.c | ||
853 | @@ -XXX,XX +XXX,XX @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) | ||
854 | } | ||
855 | |||
856 | static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
857 | - const BdrvChildRole *role, | ||
858 | + const BdrvChildClass *child_class, | ||
859 | BlockReopenQueue *reopen_queue, | ||
860 | uint64_t perm, uint64_t shared, | ||
861 | uint64_t *nperm, uint64_t *nshared) | ||
862 | diff --git a/block/replication.c b/block/replication.c | ||
863 | index XXXXXXX..XXXXXXX 100644 | ||
864 | --- a/block/replication.c | ||
865 | +++ b/block/replication.c | ||
866 | @@ -XXX,XX +XXX,XX @@ static void replication_close(BlockDriverState *bs) | ||
867 | } | ||
868 | |||
869 | static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
870 | - const BdrvChildRole *role, | ||
871 | + const BdrvChildClass *child_class, | ||
872 | BlockReopenQueue *reopen_queue, | ||
873 | uint64_t perm, uint64_t shared, | ||
874 | uint64_t *nperm, uint64_t *nshared) | ||
875 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
876 | index XXXXXXX..XXXXXXX 100644 | ||
877 | --- a/block/vvfat.c | ||
878 | +++ b/block/vvfat.c | ||
879 | @@ -XXX,XX +XXX,XX @@ static void vvfat_qcow_options(int *child_flags, QDict *child_options, | ||
880 | qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on"); | ||
881 | } | ||
882 | |||
883 | -static const BdrvChildRole child_vvfat_qcow = { | ||
884 | +static const BdrvChildClass child_vvfat_qcow = { | ||
885 | .parent_is_bds = true, | ||
886 | .inherit_options = vvfat_qcow_options, | ||
887 | }; | ||
888 | @@ -XXX,XX +XXX,XX @@ err: | ||
889 | } | ||
890 | |||
891 | static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
892 | - const BdrvChildRole *role, | ||
893 | + const BdrvChildClass *child_class, | ||
894 | BlockReopenQueue *reopen_queue, | ||
895 | uint64_t perm, uint64_t shared, | ||
896 | uint64_t *nperm, uint64_t *nshared) | ||
897 | { | ||
898 | BDRVVVFATState *s = bs->opaque; | ||
899 | |||
900 | - assert(c == s->qcow || role == &child_backing); | ||
901 | + assert(c == s->qcow || child_class == &child_backing); | ||
902 | |||
903 | if (c == s->qcow) { | ||
904 | /* This is a private node, nobody should try to attach to it */ | ||
905 | diff --git a/blockjob.c b/blockjob.c | ||
906 | index XXXXXXX..XXXXXXX 100644 | ||
907 | --- a/blockjob.c | ||
908 | +++ b/blockjob.c | ||
909 | @@ -XXX,XX +XXX,XX @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx, | ||
910 | job->job.aio_context = ctx; | ||
911 | } | ||
912 | |||
913 | -static const BdrvChildRole child_job = { | ||
914 | +static const BdrvChildClass child_job = { | ||
915 | .get_parent_desc = child_job_get_parent_desc, | ||
916 | .drained_begin = child_job_drained_begin, | ||
917 | .drained_poll = child_job_drained_poll, | ||
918 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
919 | index XXXXXXX..XXXXXXX 100644 | ||
920 | --- a/tests/test-bdrv-drain.c | ||
921 | +++ b/tests/test-bdrv-drain.c | ||
922 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, | ||
923 | } | ||
924 | |||
925 | static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
926 | - const BdrvChildRole *role, | ||
927 | + const BdrvChildClass *child_class, | ||
928 | BlockReopenQueue *reopen_queue, | ||
929 | uint64_t perm, uint64_t shared, | ||
930 | uint64_t *nperm, uint64_t *nshared) | ||
931 | { | ||
932 | - /* bdrv_format_default_perms() accepts only these two, so disguise | ||
933 | - * detach_by_driver_cb_role as one of them. */ | ||
934 | - if (role != &child_file && role != &child_backing) { | ||
935 | - role = &child_file; | ||
936 | + /* | ||
937 | + * bdrv_format_default_perms() accepts only these two, so disguise | ||
938 | + * detach_by_driver_cb_parent as one of them. | ||
939 | + */ | ||
940 | + if (child_class != &child_file && child_class != &child_backing) { | ||
941 | + child_class = &child_file; | ||
942 | } | ||
943 | |||
944 | - bdrv_format_default_perms(bs, c, role, reopen_queue, perm, shared, | ||
945 | + bdrv_format_default_perms(bs, c, child_class, reopen_queue, perm, shared, | ||
946 | nperm, nshared); | ||
947 | } | ||
948 | |||
949 | @@ -XXX,XX +XXX,XX @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) | ||
950 | child_file.drained_begin(child); | ||
951 | } | ||
952 | |||
953 | -static BdrvChildRole detach_by_driver_cb_role; | ||
954 | +static BdrvChildClass detach_by_driver_cb_class; | ||
955 | |||
956 | /* | ||
957 | * Initial graph: | ||
958 | @@ -XXX,XX +XXX,XX @@ static BdrvChildRole detach_by_driver_cb_role; | ||
959 | * | ||
960 | * by_parent_cb == false: Test that bdrv_drain_invoke() doesn't poll | ||
961 | * | ||
962 | - * PA's BdrvChildRole has a .drained_begin callback that schedules a BH | ||
963 | + * PA's BdrvChildClass has a .drained_begin callback that schedules a BH | ||
964 | * that does the same graph change. If bdrv_drain_invoke() calls it, the | ||
965 | * state is messed up, but if it is only polled in the single | ||
966 | * BDRV_POLL_WHILE() at the end of the drain, this should work fine. | ||
967 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
968 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); | ||
969 | |||
970 | if (!by_parent_cb) { | ||
971 | - detach_by_driver_cb_role = child_file; | ||
972 | - detach_by_driver_cb_role.drained_begin = | ||
973 | + detach_by_driver_cb_class = child_file; | ||
974 | + detach_by_driver_cb_class.drained_begin = | ||
975 | detach_by_driver_cb_drained_begin; | ||
976 | } | ||
977 | |||
978 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
979 | |||
980 | bdrv_ref(a); | ||
981 | bdrv_attach_child(parent_a, a, "PA-A", | ||
982 | - by_parent_cb ? &child_file : &detach_by_driver_cb_role, | ||
983 | + by_parent_cb ? &child_file : &detach_by_driver_cb_class, | ||
984 | &error_abort); | ||
985 | |||
986 | g_assert_cmpint(parent_a->refcnt, ==, 1); | ||
987 | @@ -XXX,XX +XXX,XX @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, | ||
988 | /** | ||
989 | * Test a poll in the midst of bdrv_drop_intermediate(). | ||
990 | * | ||
991 | - * bdrv_drop_intermediate() calls BdrvChildRole.update_filename(), | ||
992 | + * bdrv_drop_intermediate() calls BdrvChildClass.update_filename(), | ||
993 | * which can yield or poll. This may lead to graph changes, unless | ||
994 | * the whole subtree in question is drained. | ||
995 | * | ||
996 | @@ -XXX,XX +XXX,XX @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, | ||
997 | * | ||
998 | * The solution is for bdrv_drop_intermediate() to drain top's | ||
999 | * subtree. This prevents graph changes from happening just because | ||
1000 | - * BdrvChildRole.update_filename() yields or polls. Thus, the block | ||
1001 | + * BdrvChildClass.update_filename() yields or polls. Thus, the block | ||
1002 | * job is paused during that drained section and must finish before or | ||
1003 | * after. | ||
1004 | * | ||
1005 | @@ -XXX,XX +XXX,XX @@ static int drop_intermediate_poll_update_filename(BdrvChild *child, | ||
1006 | */ | ||
1007 | static void test_drop_intermediate_poll(void) | ||
1008 | { | ||
1009 | - static BdrvChildRole chain_child_role; | ||
1010 | + static BdrvChildClass chain_child_class; | ||
1011 | BlockDriverState *chain[3]; | ||
1012 | TestSimpleBlockJob *job; | ||
1013 | BlockDriverState *job_node; | ||
1014 | @@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void) | ||
1015 | int i; | ||
1016 | int ret; | ||
1017 | |||
1018 | - chain_child_role = child_backing; | ||
1019 | - chain_child_role.update_filename = drop_intermediate_poll_update_filename; | ||
1020 | + chain_child_class = child_backing; | ||
1021 | + chain_child_class.update_filename = drop_intermediate_poll_update_filename; | ||
1022 | |||
1023 | for (i = 0; i < 3; i++) { | ||
1024 | char name[32]; | ||
1025 | @@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void) | ||
1026 | if (i) { | ||
1027 | /* Takes the reference to chain[i - 1] */ | ||
1028 | chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], | ||
1029 | - "chain", &chain_child_role, | ||
1030 | + "chain", &chain_child_class, | ||
1031 | &error_abort); | ||
1032 | } | ||
1033 | } | ||
1034 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
1035 | index XXXXXXX..XXXXXXX 100644 | ||
1036 | --- a/tests/test-bdrv-graph-mod.c | ||
1037 | +++ b/tests/test-bdrv-graph-mod.c | ||
1038 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_pass_through = { | ||
1039 | }; | ||
1040 | |||
1041 | static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
1042 | - const BdrvChildRole *role, | ||
1043 | + const BdrvChildClass *child_class, | ||
1044 | BlockReopenQueue *reopen_queue, | ||
1045 | uint64_t perm, uint64_t shared, | ||
1046 | uint64_t *nperm, uint64_t *nshared) | ||
1047 | -- | ||
1048 | 2.25.4 | ||
1049 | |||
1050 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | This mask will supplement BdrvChildClass when it comes to what role (or | ||
4 | combination of roles) a child takes for its parent. It consists of | ||
5 | BdrvChildRoleBits values (which is an enum). | ||
6 | |||
7 | Because empty enums are not allowed, let us just start with it filled. | ||
8 | |||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-5-mreitz@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | --- | ||
14 | include/block/block.h | 56 +++++++++++++++++++++++++++++++++++++++++++ | ||
15 | 1 file changed, 56 insertions(+) | ||
16 | |||
17 | diff --git a/include/block/block.h b/include/block/block.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/block/block.h | ||
20 | +++ b/include/block/block.h | ||
21 | @@ -XXX,XX +XXX,XX @@ enum { | ||
22 | DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, | ||
23 | }; | ||
24 | |||
25 | +/* | ||
26 | + * Flags that parent nodes assign to child nodes to specify what kind of | ||
27 | + * role(s) they take. | ||
28 | + * | ||
29 | + * At least one of DATA, METADATA, FILTERED, or COW must be set for | ||
30 | + * every child. | ||
31 | + */ | ||
32 | +enum BdrvChildRoleBits { | ||
33 | + /* | ||
34 | + * This child stores data. | ||
35 | + * Any node may have an arbitrary number of such children. | ||
36 | + */ | ||
37 | + BDRV_CHILD_DATA = (1 << 0), | ||
38 | + | ||
39 | + /* | ||
40 | + * This child stores metadata. | ||
41 | + * Any node may have an arbitrary number of metadata-storing | ||
42 | + * children. | ||
43 | + */ | ||
44 | + BDRV_CHILD_METADATA = (1 << 1), | ||
45 | + | ||
46 | + /* | ||
47 | + * A child that always presents exactly the same visible data as | ||
48 | + * the parent, e.g. by virtue of the parent forwarding all reads | ||
49 | + * and writes. | ||
50 | + * This flag is mutually exclusive with DATA, METADATA, and COW. | ||
51 | + * Any node may have at most one filtered child at a time. | ||
52 | + */ | ||
53 | + BDRV_CHILD_FILTERED = (1 << 2), | ||
54 | + | ||
55 | + /* | ||
56 | + * Child from which to read all data that isn’t allocated in the | ||
57 | + * parent (i.e., the backing child); such data is copied to the | ||
58 | + * parent through COW (and optionally COR). | ||
59 | + * This field is mutually exclusive with DATA, METADATA, and | ||
60 | + * FILTERED. | ||
61 | + * Any node may have at most one such backing child at a time. | ||
62 | + */ | ||
63 | + BDRV_CHILD_COW = (1 << 3), | ||
64 | + | ||
65 | + /* | ||
66 | + * The primary child. For most drivers, this is the child whose | ||
67 | + * filename applies best to the parent node. | ||
68 | + * Any node may have at most one primary child at a time. | ||
69 | + */ | ||
70 | + BDRV_CHILD_PRIMARY = (1 << 4), | ||
71 | + | ||
72 | + /* Useful combination of flags */ | ||
73 | + BDRV_CHILD_IMAGE = BDRV_CHILD_DATA | ||
74 | + | BDRV_CHILD_METADATA | ||
75 | + | BDRV_CHILD_PRIMARY, | ||
76 | +}; | ||
77 | + | ||
78 | +/* Mask of BdrvChildRoleBits values */ | ||
79 | +typedef unsigned int BdrvChildRole; | ||
80 | + | ||
81 | char *bdrv_perm_names(uint64_t perm); | ||
82 | uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm); | ||
83 | |||
84 | -- | ||
85 | 2.25.4 | ||
86 | |||
87 | diff view generated by jsdifflib |
1 | From: Peter Maydell <peter.maydell@linaro.org> | 1 | From: Max Reitz <mreitz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Coverity points out that the code path in qcow_create() for | 3 | For now, it is always set to 0. Later patches in this series will |
4 | the magic "fat:" backing file name leaks the memory used to | 4 | ensure that all callers pass an appropriate combination of flags. |
5 | store the filename (CID 1307771). Free the memory before | ||
6 | we overwrite the pointer. | ||
7 | 5 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Message-Id: <20200513110544.176672-6-mreitz@redhat.com> |
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | --- | 10 | --- |
13 | block/qcow.c | 1 + | 11 | include/block/block.h | 2 ++ |
14 | 1 file changed, 1 insertion(+) | 12 | include/block/block_int.h | 2 ++ |
13 | block.c | 11 ++++++++--- | ||
14 | block/backup-top.c | 3 ++- | ||
15 | block/blkdebug.c | 2 +- | ||
16 | block/blklogwrites.c | 6 +++--- | ||
17 | block/blkreplay.c | 2 +- | ||
18 | block/blkverify.c | 4 ++-- | ||
19 | block/block-backend.c | 4 ++-- | ||
20 | block/bochs.c | 2 +- | ||
21 | block/cloop.c | 2 +- | ||
22 | block/copy-on-read.c | 2 +- | ||
23 | block/crypto.c | 2 +- | ||
24 | block/dmg.c | 2 +- | ||
25 | block/filter-compress.c | 2 +- | ||
26 | block/parallels.c | 2 +- | ||
27 | block/qcow.c | 2 +- | ||
28 | block/qcow2.c | 6 +++--- | ||
29 | block/qed.c | 2 +- | ||
30 | block/quorum.c | 4 ++-- | ||
31 | block/raw-format.c | 2 +- | ||
32 | block/replication.c | 2 +- | ||
33 | block/throttle.c | 2 +- | ||
34 | block/vdi.c | 2 +- | ||
35 | block/vhdx.c | 2 +- | ||
36 | block/vmdk.c | 4 ++-- | ||
37 | block/vpc.c | 2 +- | ||
38 | block/vvfat.c | 2 +- | ||
39 | blockjob.c | 5 +++-- | ||
40 | tests/test-bdrv-drain.c | 20 +++++++++++--------- | ||
41 | tests/test-bdrv-graph-mod.c | 4 ++-- | ||
42 | 31 files changed, 62 insertions(+), 49 deletions(-) | ||
15 | 43 | ||
44 | diff --git a/include/block/block.h b/include/block/block.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/include/block/block.h | ||
47 | +++ b/include/block/block.h | ||
48 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename, | ||
49 | QDict *options, const char *bdref_key, | ||
50 | BlockDriverState* parent, | ||
51 | const BdrvChildClass *child_class, | ||
52 | + BdrvChildRole child_role, | ||
53 | bool allow_none, Error **errp); | ||
54 | BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); | ||
55 | void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
56 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
57 | BlockDriverState *child_bs, | ||
58 | const char *child_name, | ||
59 | const BdrvChildClass *child_class, | ||
60 | + BdrvChildRole child_role, | ||
61 | Error **errp); | ||
62 | |||
63 | bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp); | ||
64 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/include/block/block_int.h | ||
67 | +++ b/include/block/block_int.h | ||
68 | @@ -XXX,XX +XXX,XX @@ struct BdrvChild { | ||
69 | BlockDriverState *bs; | ||
70 | char *name; | ||
71 | const BdrvChildClass *klass; | ||
72 | + BdrvChildRole role; | ||
73 | void *opaque; | ||
74 | |||
75 | /** | ||
76 | @@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, | ||
77 | BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
78 | const char *child_name, | ||
79 | const BdrvChildClass *child_class, | ||
80 | + BdrvChildRole child_role, | ||
81 | AioContext *ctx, | ||
82 | uint64_t perm, uint64_t shared_perm, | ||
83 | void *opaque, Error **errp); | ||
84 | diff --git a/block.c b/block.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/block.c | ||
87 | +++ b/block.c | ||
88 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) | ||
89 | BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
90 | const char *child_name, | ||
91 | const BdrvChildClass *child_class, | ||
92 | + BdrvChildRole child_role, | ||
93 | AioContext *ctx, | ||
94 | uint64_t perm, uint64_t shared_perm, | ||
95 | void *opaque, Error **errp) | ||
96 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, | ||
97 | .bs = NULL, | ||
98 | .name = g_strdup(child_name), | ||
99 | .klass = child_class, | ||
100 | + .role = child_role, | ||
101 | .perm = perm, | ||
102 | .shared_perm = shared_perm, | ||
103 | .opaque = opaque, | ||
104 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
105 | BlockDriverState *child_bs, | ||
106 | const char *child_name, | ||
107 | const BdrvChildClass *child_class, | ||
108 | + BdrvChildRole child_role, | ||
109 | Error **errp) | ||
110 | { | ||
111 | BdrvChild *child; | ||
112 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
113 | perm, shared_perm, &perm, &shared_perm); | ||
114 | |||
115 | child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
116 | - bdrv_get_aio_context(parent_bs), | ||
117 | + child_role, bdrv_get_aio_context(parent_bs), | ||
118 | perm, shared_perm, parent_bs, errp); | ||
119 | if (child == NULL) { | ||
120 | return NULL; | ||
121 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
122 | } | ||
123 | |||
124 | bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, | ||
125 | - errp); | ||
126 | + 0, errp); | ||
127 | /* If backing_hd was already part of bs's backing chain, and | ||
128 | * inherits_from pointed recursively to bs then let's update it to | ||
129 | * point directly to bs (else it will become NULL). */ | ||
130 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename, | ||
131 | QDict *options, const char *bdref_key, | ||
132 | BlockDriverState *parent, | ||
133 | const BdrvChildClass *child_class, | ||
134 | + BdrvChildRole child_role, | ||
135 | bool allow_none, Error **errp) | ||
136 | { | ||
137 | BlockDriverState *bs; | ||
138 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename, | ||
139 | return NULL; | ||
140 | } | ||
141 | |||
142 | - return bdrv_attach_child(parent, bs, bdref_key, child_class, errp); | ||
143 | + return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role, | ||
144 | + errp); | ||
145 | } | ||
146 | |||
147 | /* | ||
148 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/block/backup-top.c | ||
151 | +++ b/block/backup-top.c | ||
152 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, | ||
153 | source->supported_zero_flags); | ||
154 | |||
155 | bdrv_ref(target); | ||
156 | - state->target = bdrv_attach_child(top, target, "target", &child_file, errp); | ||
157 | + state->target = bdrv_attach_child(top, target, "target", &child_file, 0, | ||
158 | + errp); | ||
159 | if (!state->target) { | ||
160 | bdrv_unref(target); | ||
161 | bdrv_unref(top); | ||
162 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/block/blkdebug.c | ||
165 | +++ b/block/blkdebug.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, | ||
167 | |||
168 | /* Open the image file */ | ||
169 | bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image", | ||
170 | - bs, &child_file, false, &local_err); | ||
171 | + bs, &child_file, 0, false, &local_err); | ||
172 | if (local_err) { | ||
173 | ret = -EINVAL; | ||
174 | error_propagate(errp, local_err); | ||
175 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/block/blklogwrites.c | ||
178 | +++ b/block/blklogwrites.c | ||
179 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
180 | } | ||
181 | |||
182 | /* Open the file */ | ||
183 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, | ||
184 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
185 | &local_err); | ||
186 | if (local_err) { | ||
187 | ret = -EINVAL; | ||
188 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
189 | } | ||
190 | |||
191 | /* Open the log file */ | ||
192 | - s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, false, | ||
193 | - &local_err); | ||
194 | + s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, 0, | ||
195 | + false, &local_err); | ||
196 | if (local_err) { | ||
197 | ret = -EINVAL; | ||
198 | error_propagate(errp, local_err); | ||
199 | diff --git a/block/blkreplay.c b/block/blkreplay.c | ||
200 | index XXXXXXX..XXXXXXX 100644 | ||
201 | --- a/block/blkreplay.c | ||
202 | +++ b/block/blkreplay.c | ||
203 | @@ -XXX,XX +XXX,XX @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, | ||
204 | |||
205 | /* Open the image file */ | ||
206 | bs->file = bdrv_open_child(NULL, options, "image", | ||
207 | - bs, &child_file, false, &local_err); | ||
208 | + bs, &child_file, 0, false, &local_err); | ||
209 | if (local_err) { | ||
210 | ret = -EINVAL; | ||
211 | error_propagate(errp, local_err); | ||
212 | diff --git a/block/blkverify.c b/block/blkverify.c | ||
213 | index XXXXXXX..XXXXXXX 100644 | ||
214 | --- a/block/blkverify.c | ||
215 | +++ b/block/blkverify.c | ||
216 | @@ -XXX,XX +XXX,XX @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, | ||
217 | |||
218 | /* Open the raw file */ | ||
219 | bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw", | ||
220 | - bs, &child_file, false, &local_err); | ||
221 | + bs, &child_file, 0, false, &local_err); | ||
222 | if (local_err) { | ||
223 | ret = -EINVAL; | ||
224 | error_propagate(errp, local_err); | ||
225 | @@ -XXX,XX +XXX,XX @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, | ||
226 | |||
227 | /* Open the test file */ | ||
228 | s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, | ||
229 | - "test", bs, &child_format, false, | ||
230 | + "test", bs, &child_format, 0, false, | ||
231 | &local_err); | ||
232 | if (local_err) { | ||
233 | ret = -EINVAL; | ||
234 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
235 | index XXXXXXX..XXXXXXX 100644 | ||
236 | --- a/block/block-backend.c | ||
237 | +++ b/block/block-backend.c | ||
238 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, | ||
239 | return NULL; | ||
240 | } | ||
241 | |||
242 | - blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk->ctx, | ||
243 | + blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, | ||
244 | perm, BLK_PERM_ALL, blk, errp); | ||
245 | if (!blk->root) { | ||
246 | blk_unref(blk); | ||
247 | @@ -XXX,XX +XXX,XX @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) | ||
248 | { | ||
249 | ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | ||
250 | bdrv_ref(bs); | ||
251 | - blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk->ctx, | ||
252 | + blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, | ||
253 | blk->perm, blk->shared_perm, blk, errp); | ||
254 | if (blk->root == NULL) { | ||
255 | return -EPERM; | ||
256 | diff --git a/block/bochs.c b/block/bochs.c | ||
257 | index XXXXXXX..XXXXXXX 100644 | ||
258 | --- a/block/bochs.c | ||
259 | +++ b/block/bochs.c | ||
260 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
261 | return ret; | ||
262 | } | ||
263 | |||
264 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
265 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
266 | false, errp); | ||
267 | if (!bs->file) { | ||
268 | return -EINVAL; | ||
269 | diff --git a/block/cloop.c b/block/cloop.c | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/block/cloop.c | ||
272 | +++ b/block/cloop.c | ||
273 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
274 | return ret; | ||
275 | } | ||
276 | |||
277 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
278 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
279 | false, errp); | ||
280 | if (!bs->file) { | ||
281 | return -EINVAL; | ||
282 | diff --git a/block/copy-on-read.c b/block/copy-on-read.c | ||
283 | index XXXXXXX..XXXXXXX 100644 | ||
284 | --- a/block/copy-on-read.c | ||
285 | +++ b/block/copy-on-read.c | ||
286 | @@ -XXX,XX +XXX,XX @@ | ||
287 | static int cor_open(BlockDriverState *bs, QDict *options, int flags, | ||
288 | Error **errp) | ||
289 | { | ||
290 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, | ||
291 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
292 | errp); | ||
293 | if (!bs->file) { | ||
294 | return -EINVAL; | ||
295 | diff --git a/block/crypto.c b/block/crypto.c | ||
296 | index XXXXXXX..XXXXXXX 100644 | ||
297 | --- a/block/crypto.c | ||
298 | +++ b/block/crypto.c | ||
299 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_open_generic(QCryptoBlockFormat format, | ||
300 | unsigned int cflags = 0; | ||
301 | QDict *cryptoopts = NULL; | ||
302 | |||
303 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
304 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
305 | false, errp); | ||
306 | if (!bs->file) { | ||
307 | return -EINVAL; | ||
308 | diff --git a/block/dmg.c b/block/dmg.c | ||
309 | index XXXXXXX..XXXXXXX 100644 | ||
310 | --- a/block/dmg.c | ||
311 | +++ b/block/dmg.c | ||
312 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | ||
313 | return ret; | ||
314 | } | ||
315 | |||
316 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
317 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
318 | false, errp); | ||
319 | if (!bs->file) { | ||
320 | return -EINVAL; | ||
321 | diff --git a/block/filter-compress.c b/block/filter-compress.c | ||
322 | index XXXXXXX..XXXXXXX 100644 | ||
323 | --- a/block/filter-compress.c | ||
324 | +++ b/block/filter-compress.c | ||
325 | @@ -XXX,XX +XXX,XX @@ | ||
326 | static int compress_open(BlockDriverState *bs, QDict *options, int flags, | ||
327 | Error **errp) | ||
328 | { | ||
329 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, | ||
330 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
331 | errp); | ||
332 | if (!bs->file) { | ||
333 | return -EINVAL; | ||
334 | diff --git a/block/parallels.c b/block/parallels.c | ||
335 | index XXXXXXX..XXXXXXX 100644 | ||
336 | --- a/block/parallels.c | ||
337 | +++ b/block/parallels.c | ||
338 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
339 | Error *local_err = NULL; | ||
340 | char *buf; | ||
341 | |||
342 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
343 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
344 | false, errp); | ||
345 | if (!bs->file) { | ||
346 | return -EINVAL; | ||
16 | diff --git a/block/qcow.c b/block/qcow.c | 347 | diff --git a/block/qcow.c b/block/qcow.c |
17 | index XXXXXXX..XXXXXXX 100644 | 348 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/qcow.c | 349 | --- a/block/qcow.c |
19 | +++ b/block/qcow.c | 350 | +++ b/block/qcow.c |
20 | @@ -XXX,XX +XXX,XX @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) | 351 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, |
21 | header_size += backing_filename_len; | 352 | qdict_extract_subqdict(options, &encryptopts, "encrypt."); |
22 | } else { | 353 | encryptfmt = qdict_get_try_str(encryptopts, "format"); |
23 | /* special backing file for vvfat */ | 354 | |
24 | + g_free(backing_file); | 355 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, |
25 | backing_file = NULL; | 356 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, |
357 | false, errp); | ||
358 | if (!bs->file) { | ||
359 | ret = -EINVAL; | ||
360 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
361 | index XXXXXXX..XXXXXXX 100644 | ||
362 | --- a/block/qcow2.c | ||
363 | +++ b/block/qcow2.c | ||
364 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
365 | |||
366 | /* Open external data file */ | ||
367 | s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file, | ||
368 | - true, &local_err); | ||
369 | + 0, true, &local_err); | ||
370 | if (local_err) { | ||
371 | error_propagate(errp, local_err); | ||
372 | ret = -EINVAL; | ||
373 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
374 | if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { | ||
375 | if (!s->data_file && s->image_data_file) { | ||
376 | s->data_file = bdrv_open_child(s->image_data_file, options, | ||
377 | - "data-file", bs, &child_file, | ||
378 | + "data-file", bs, &child_file, 0, | ||
379 | false, errp); | ||
380 | if (!s->data_file) { | ||
381 | ret = -EINVAL; | ||
382 | @@ -XXX,XX +XXX,XX @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, | ||
383 | .ret = -EINPROGRESS | ||
384 | }; | ||
385 | |||
386 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
387 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
388 | false, errp); | ||
389 | if (!bs->file) { | ||
390 | return -EINVAL; | ||
391 | diff --git a/block/qed.c b/block/qed.c | ||
392 | index XXXXXXX..XXXXXXX 100644 | ||
393 | --- a/block/qed.c | ||
394 | +++ b/block/qed.c | ||
395 | @@ -XXX,XX +XXX,XX @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, | ||
396 | .ret = -EINPROGRESS | ||
397 | }; | ||
398 | |||
399 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
400 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
401 | false, errp); | ||
402 | if (!bs->file) { | ||
403 | return -EINVAL; | ||
404 | diff --git a/block/quorum.c b/block/quorum.c | ||
405 | index XXXXXXX..XXXXXXX 100644 | ||
406 | --- a/block/quorum.c | ||
407 | +++ b/block/quorum.c | ||
408 | @@ -XXX,XX +XXX,XX @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, | ||
409 | assert(ret < 32); | ||
410 | |||
411 | s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, | ||
412 | - &child_format, false, &local_err); | ||
413 | + &child_format, 0, false, &local_err); | ||
414 | if (local_err) { | ||
415 | ret = -EINVAL; | ||
416 | goto close_exit; | ||
417 | @@ -XXX,XX +XXX,XX @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, | ||
418 | /* We can safely add the child now */ | ||
419 | bdrv_ref(child_bs); | ||
420 | |||
421 | - child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, errp); | ||
422 | + child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, 0, errp); | ||
423 | if (child == NULL) { | ||
424 | s->next_child_index--; | ||
425 | goto out; | ||
426 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
427 | index XXXXXXX..XXXXXXX 100644 | ||
428 | --- a/block/raw-format.c | ||
429 | +++ b/block/raw-format.c | ||
430 | @@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, | ||
431 | BDRVRawState *s = bs->opaque; | ||
432 | int ret; | ||
433 | |||
434 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
435 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
436 | false, errp); | ||
437 | if (!bs->file) { | ||
438 | return -EINVAL; | ||
439 | diff --git a/block/replication.c b/block/replication.c | ||
440 | index XXXXXXX..XXXXXXX 100644 | ||
441 | --- a/block/replication.c | ||
442 | +++ b/block/replication.c | ||
443 | @@ -XXX,XX +XXX,XX @@ static int replication_open(BlockDriverState *bs, QDict *options, | ||
444 | const char *mode; | ||
445 | const char *top_id; | ||
446 | |||
447 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
448 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
449 | false, errp); | ||
450 | if (!bs->file) { | ||
451 | return -EINVAL; | ||
452 | diff --git a/block/throttle.c b/block/throttle.c | ||
453 | index XXXXXXX..XXXXXXX 100644 | ||
454 | --- a/block/throttle.c | ||
455 | +++ b/block/throttle.c | ||
456 | @@ -XXX,XX +XXX,XX @@ static int throttle_open(BlockDriverState *bs, QDict *options, | ||
457 | int ret; | ||
458 | |||
459 | bs->file = bdrv_open_child(NULL, options, "file", bs, | ||
460 | - &child_file, false, errp); | ||
461 | + &child_file, 0, false, errp); | ||
462 | if (!bs->file) { | ||
463 | return -EINVAL; | ||
464 | } | ||
465 | diff --git a/block/vdi.c b/block/vdi.c | ||
466 | index XXXXXXX..XXXXXXX 100644 | ||
467 | --- a/block/vdi.c | ||
468 | +++ b/block/vdi.c | ||
469 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
470 | Error *local_err = NULL; | ||
471 | QemuUUID uuid_link, uuid_parent; | ||
472 | |||
473 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
474 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
475 | false, errp); | ||
476 | if (!bs->file) { | ||
477 | return -EINVAL; | ||
478 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
479 | index XXXXXXX..XXXXXXX 100644 | ||
480 | --- a/block/vhdx.c | ||
481 | +++ b/block/vhdx.c | ||
482 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
483 | uint64_t signature; | ||
484 | Error *local_err = NULL; | ||
485 | |||
486 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
487 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
488 | false, errp); | ||
489 | if (!bs->file) { | ||
490 | return -EINVAL; | ||
491 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
492 | index XXXXXXX..XXXXXXX 100644 | ||
493 | --- a/block/vmdk.c | ||
494 | +++ b/block/vmdk.c | ||
495 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
496 | assert(ret < 32); | ||
497 | |||
498 | extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix, | ||
499 | - bs, &child_file, false, &local_err); | ||
500 | + bs, &child_file, 0, false, &local_err); | ||
501 | g_free(extent_path); | ||
502 | if (local_err) { | ||
503 | error_propagate(errp, local_err); | ||
504 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, | ||
505 | uint32_t magic; | ||
506 | Error *local_err = NULL; | ||
507 | |||
508 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
509 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
510 | false, errp); | ||
511 | if (!bs->file) { | ||
512 | return -EINVAL; | ||
513 | diff --git a/block/vpc.c b/block/vpc.c | ||
514 | index XXXXXXX..XXXXXXX 100644 | ||
515 | --- a/block/vpc.c | ||
516 | +++ b/block/vpc.c | ||
517 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
518 | int ret; | ||
519 | int64_t bs_size; | ||
520 | |||
521 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, | ||
522 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
523 | false, errp); | ||
524 | if (!bs->file) { | ||
525 | return -EINVAL; | ||
526 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
527 | index XXXXXXX..XXXXXXX 100644 | ||
528 | --- a/block/vvfat.c | ||
529 | +++ b/block/vvfat.c | ||
530 | @@ -XXX,XX +XXX,XX @@ static int enable_write_target(BlockDriverState *bs, Error **errp) | ||
531 | options = qdict_new(); | ||
532 | qdict_put_str(options, "write-target.driver", "qcow"); | ||
533 | s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs, | ||
534 | - &child_vvfat_qcow, false, errp); | ||
535 | + &child_vvfat_qcow, 0, false, errp); | ||
536 | qobject_unref(options); | ||
537 | if (!s->qcow) { | ||
538 | ret = -EINVAL; | ||
539 | diff --git a/blockjob.c b/blockjob.c | ||
540 | index XXXXXXX..XXXXXXX 100644 | ||
541 | --- a/blockjob.c | ||
542 | +++ b/blockjob.c | ||
543 | @@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, | ||
544 | if (job->job.aio_context != qemu_get_aio_context()) { | ||
545 | aio_context_release(job->job.aio_context); | ||
546 | } | ||
547 | - c = bdrv_root_attach_child(bs, name, &child_job, job->job.aio_context, | ||
548 | - perm, shared_perm, job, errp); | ||
549 | + c = bdrv_root_attach_child(bs, name, &child_job, 0, | ||
550 | + job->job.aio_context, perm, shared_perm, job, | ||
551 | + errp); | ||
552 | if (job->job.aio_context != qemu_get_aio_context()) { | ||
553 | aio_context_acquire(job->job.aio_context); | ||
554 | } | ||
555 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
556 | index XXXXXXX..XXXXXXX 100644 | ||
557 | --- a/tests/test-bdrv-drain.c | ||
558 | +++ b/tests/test-bdrv-drain.c | ||
559 | @@ -XXX,XX +XXX,XX @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, | ||
560 | |||
561 | null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, | ||
562 | &error_abort); | ||
563 | - bdrv_attach_child(bs, null_bs, "null-child", &child_file, &error_abort); | ||
564 | + bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); | ||
565 | |||
566 | /* This child will be the one to pass to requests through to, and | ||
567 | * it will stall until a drain occurs */ | ||
568 | @@ -XXX,XX +XXX,XX @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, | ||
569 | child_bs->total_sectors = 65536 >> BDRV_SECTOR_BITS; | ||
570 | /* Takes our reference to child_bs */ | ||
571 | tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", &child_file, | ||
572 | - &error_abort); | ||
573 | + 0, &error_abort); | ||
574 | |||
575 | /* This child is just there to be deleted | ||
576 | * (for detach_instead_of_delete == true) */ | ||
577 | null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, | ||
578 | &error_abort); | ||
579 | - bdrv_attach_child(bs, null_bs, "null-child", &child_file, &error_abort); | ||
580 | + bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); | ||
581 | |||
582 | blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); | ||
583 | blk_insert_bs(blk, bs, &error_abort); | ||
584 | @@ -XXX,XX +XXX,XX @@ static void detach_indirect_bh(void *opaque) | ||
585 | |||
586 | bdrv_ref(data->c); | ||
587 | data->child_c = bdrv_attach_child(data->parent_b, data->c, "PB-C", | ||
588 | - &child_file, &error_abort); | ||
589 | + &child_file, 0, &error_abort); | ||
590 | } | ||
591 | |||
592 | static void detach_by_parent_aio_cb(void *opaque, int ret) | ||
593 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
594 | /* Set child relationships */ | ||
595 | bdrv_ref(b); | ||
596 | bdrv_ref(a); | ||
597 | - child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, &error_abort); | ||
598 | - child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, &error_abort); | ||
599 | + child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, | ||
600 | + &error_abort); | ||
601 | + child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, 0, | ||
602 | + &error_abort); | ||
603 | |||
604 | bdrv_ref(a); | ||
605 | bdrv_attach_child(parent_a, a, "PA-A", | ||
606 | by_parent_cb ? &child_file : &detach_by_driver_cb_class, | ||
607 | - &error_abort); | ||
608 | + 0, &error_abort); | ||
609 | |||
610 | g_assert_cmpint(parent_a->refcnt, ==, 1); | ||
611 | g_assert_cmpint(parent_b->refcnt, ==, 1); | ||
612 | @@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void) | ||
613 | /* Takes the reference to chain[i - 1] */ | ||
614 | chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], | ||
615 | "chain", &chain_child_class, | ||
616 | - &error_abort); | ||
617 | + 0, &error_abort); | ||
26 | } | 618 | } |
27 | header.cluster_bits = 9; /* 512 byte cluster to avoid copying | 619 | } |
620 | |||
621 | @@ -XXX,XX +XXX,XX @@ static void do_test_replace_child_mid_drain(int old_drain_count, | ||
622 | |||
623 | bdrv_ref(old_child_bs); | ||
624 | parent_bs->backing = bdrv_attach_child(parent_bs, old_child_bs, "child", | ||
625 | - &child_backing, &error_abort); | ||
626 | + &child_backing, 0, &error_abort); | ||
627 | |||
628 | for (i = 0; i < old_drain_count; i++) { | ||
629 | bdrv_drained_begin(old_child_bs); | ||
630 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
631 | index XXXXXXX..XXXXXXX 100644 | ||
632 | --- a/tests/test-bdrv-graph-mod.c | ||
633 | +++ b/tests/test-bdrv-graph-mod.c | ||
634 | @@ -XXX,XX +XXX,XX @@ static void test_update_perm_tree(void) | ||
635 | |||
636 | blk_insert_bs(root, bs, &error_abort); | ||
637 | |||
638 | - bdrv_attach_child(filter, bs, "child", &child_file, &error_abort); | ||
639 | + bdrv_attach_child(filter, bs, "child", &child_file, 0, &error_abort); | ||
640 | |||
641 | bdrv_append(filter, bs, &local_err); | ||
642 | |||
643 | @@ -XXX,XX +XXX,XX @@ static void test_should_update_child(void) | ||
644 | bdrv_set_backing_hd(target, bs, &error_abort); | ||
645 | |||
646 | g_assert(target->backing->bs == bs); | ||
647 | - bdrv_attach_child(filter, target, "target", &child_file, &error_abort); | ||
648 | + bdrv_attach_child(filter, target, "target", &child_file, 0, &error_abort); | ||
649 | bdrv_append(filter, bs, &error_abort); | ||
650 | g_assert(target->backing->bs == bs); | ||
651 | |||
28 | -- | 652 | -- |
29 | 1.8.3.1 | 653 | 2.25.4 |
30 | 654 | ||
31 | 655 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | For now, all callers pass 0 and no callee evaluates this value. Later | ||
4 | patches will change both. | ||
5 | |||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Message-Id: <20200513110544.176672-7-mreitz@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | include/block/block_int.h | 5 ++++- | ||
12 | block.c | 22 ++++++++++++---------- | ||
13 | block/backup-top.c | 3 ++- | ||
14 | block/blkdebug.c | 5 +++-- | ||
15 | block/blklogwrites.c | 9 +++++---- | ||
16 | block/commit.c | 1 + | ||
17 | block/copy-on-read.c | 1 + | ||
18 | block/mirror.c | 1 + | ||
19 | block/quorum.c | 1 + | ||
20 | block/replication.c | 1 + | ||
21 | block/vvfat.c | 1 + | ||
22 | tests/test-bdrv-drain.c | 5 +++-- | ||
23 | tests/test-bdrv-graph-mod.c | 1 + | ||
24 | 13 files changed, 36 insertions(+), 20 deletions(-) | ||
25 | |||
26 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/block/block_int.h | ||
29 | +++ b/include/block/block_int.h | ||
30 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
31 | * the parents in @parent_perm and @parent_shared. | ||
32 | * | ||
33 | * If @c is NULL, return the permissions for attaching a new child for the | ||
34 | - * given @child_class. | ||
35 | + * given @child_class and @role. | ||
36 | * | ||
37 | * If @reopen_queue is non-NULL, don't return the currently needed | ||
38 | * permissions, but those that will be needed after applying the | ||
39 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
40 | */ | ||
41 | void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, | ||
42 | const BdrvChildClass *child_class, | ||
43 | + BdrvChildRole role, | ||
44 | BlockReopenQueue *reopen_queue, | ||
45 | uint64_t parent_perm, uint64_t parent_shared, | ||
46 | uint64_t *nperm, uint64_t *nshared); | ||
47 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); | ||
48 | * all children */ | ||
49 | void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
50 | const BdrvChildClass *child_class, | ||
51 | + BdrvChildRole child_role, | ||
52 | BlockReopenQueue *reopen_queue, | ||
53 | uint64_t perm, uint64_t shared, | ||
54 | uint64_t *nperm, uint64_t *nshared); | ||
55 | @@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
56 | * CONSISTENT_READ and doesn't share WRITE. */ | ||
57 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
58 | const BdrvChildClass *child_class, | ||
59 | + BdrvChildRole child_role, | ||
60 | BlockReopenQueue *reopen_queue, | ||
61 | uint64_t perm, uint64_t shared, | ||
62 | uint64_t *nperm, uint64_t *nshared); | ||
63 | diff --git a/block.c b/block.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/block.c | ||
66 | +++ b/block.c | ||
67 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_writable(BlockDriverState *bs) | ||
68 | |||
69 | static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
70 | BdrvChild *c, const BdrvChildClass *child_class, | ||
71 | - BlockReopenQueue *reopen_queue, | ||
72 | + BdrvChildRole role, BlockReopenQueue *reopen_queue, | ||
73 | uint64_t parent_perm, uint64_t parent_shared, | ||
74 | uint64_t *nperm, uint64_t *nshared) | ||
75 | { | ||
76 | assert(bs->drv && bs->drv->bdrv_child_perm); | ||
77 | - bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue, | ||
78 | + bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue, | ||
79 | parent_perm, parent_shared, | ||
80 | nperm, nshared); | ||
81 | /* TODO Take force_share from reopen_queue */ | ||
82 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
83 | uint64_t cur_perm, cur_shared; | ||
84 | bool child_tighten_restr; | ||
85 | |||
86 | - bdrv_child_perm(bs, c->bs, c, c->klass, q, | ||
87 | + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q, | ||
88 | cumulative_perms, cumulative_shared_perms, | ||
89 | &cur_perm, &cur_shared); | ||
90 | ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, | ||
91 | @@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, | ||
92 | /* Update all children */ | ||
93 | QLIST_FOREACH(c, &bs->children, next) { | ||
94 | uint64_t cur_perm, cur_shared; | ||
95 | - bdrv_child_perm(bs, c->bs, c, c->klass, NULL, | ||
96 | + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, | ||
97 | cumulative_perms, cumulative_shared_perms, | ||
98 | &cur_perm, &cur_shared); | ||
99 | bdrv_child_set_perm(c, cur_perm, cur_shared); | ||
100 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
101 | uint64_t perms, shared; | ||
102 | |||
103 | bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); | ||
104 | - bdrv_child_perm(bs, c->bs, c, c->klass, NULL, parent_perms, parent_shared, | ||
105 | - &perms, &shared); | ||
106 | + bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, | ||
107 | + parent_perms, parent_shared, &perms, &shared); | ||
108 | |||
109 | return bdrv_child_try_set_perm(c, perms, shared, errp); | ||
110 | } | ||
111 | |||
112 | void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
113 | const BdrvChildClass *child_class, | ||
114 | + BdrvChildRole role, | ||
115 | BlockReopenQueue *reopen_queue, | ||
116 | uint64_t perm, uint64_t shared, | ||
117 | uint64_t *nperm, uint64_t *nshared) | ||
118 | @@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
119 | |||
120 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
121 | const BdrvChildClass *child_class, | ||
122 | + BdrvChildRole role, | ||
123 | BlockReopenQueue *reopen_queue, | ||
124 | uint64_t perm, uint64_t shared, | ||
125 | uint64_t *nperm, uint64_t *nshared) | ||
126 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
127 | |||
128 | /* Apart from the modifications below, the same permissions are | ||
129 | * forwarded and left alone as for filters */ | ||
130 | - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, | ||
131 | + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
132 | perm, shared, &perm, &shared); | ||
133 | |||
134 | /* Format drivers may touch metadata even if the guest doesn't write */ | ||
135 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
136 | bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); | ||
137 | |||
138 | assert(parent_bs->drv); | ||
139 | - bdrv_child_perm(parent_bs, child_bs, NULL, child_class, NULL, | ||
140 | + bdrv_child_perm(parent_bs, child_bs, NULL, child_class, child_role, NULL, | ||
141 | perm, shared_perm, &perm, &shared_perm); | ||
142 | |||
143 | child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
144 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
145 | if (state->replace_backing_bs && state->new_backing_bs) { | ||
146 | uint64_t nperm, nshared; | ||
147 | bdrv_child_perm(state->bs, state->new_backing_bs, | ||
148 | - NULL, &child_backing, bs_queue, | ||
149 | + NULL, &child_backing, 0, bs_queue, | ||
150 | state->perm, state->shared_perm, | ||
151 | &nperm, &nshared); | ||
152 | ret = bdrv_check_update_perm(state->new_backing_bs, NULL, | ||
153 | @@ -XXX,XX +XXX,XX @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, | ||
154 | } else { | ||
155 | uint64_t nperm, nshared; | ||
156 | |||
157 | - bdrv_child_perm(parent->state.bs, bs, c, c->klass, q, | ||
158 | + bdrv_child_perm(parent->state.bs, bs, c, c->klass, c->role, q, | ||
159 | parent->state.perm, parent->state.shared_perm, | ||
160 | &nperm, &nshared); | ||
161 | |||
162 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/block/backup-top.c | ||
165 | +++ b/block/backup-top.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static void backup_top_refresh_filename(BlockDriverState *bs) | ||
167 | |||
168 | static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
169 | const BdrvChildClass *child_class, | ||
170 | + BdrvChildRole role, | ||
171 | BlockReopenQueue *reopen_queue, | ||
172 | uint64_t perm, uint64_t shared, | ||
173 | uint64_t *nperm, uint64_t *nshared) | ||
174 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
175 | *nperm = BLK_PERM_WRITE; | ||
176 | } else { | ||
177 | /* Source child */ | ||
178 | - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, | ||
179 | + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
180 | perm, shared, nperm, nshared); | ||
181 | |||
182 | if (perm & BLK_PERM_WRITE) { | ||
183 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
184 | index XXXXXXX..XXXXXXX 100644 | ||
185 | --- a/block/blkdebug.c | ||
186 | +++ b/block/blkdebug.c | ||
187 | @@ -XXX,XX +XXX,XX @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, | ||
188 | |||
189 | static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
190 | const BdrvChildClass *child_class, | ||
191 | + BdrvChildRole role, | ||
192 | BlockReopenQueue *reopen_queue, | ||
193 | uint64_t perm, uint64_t shared, | ||
194 | uint64_t *nperm, uint64_t *nshared) | ||
195 | { | ||
196 | BDRVBlkdebugState *s = bs->opaque; | ||
197 | |||
198 | - bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared, | ||
199 | - nperm, nshared); | ||
200 | + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
201 | + perm, shared, nperm, nshared); | ||
202 | |||
203 | *nperm |= s->take_child_perms; | ||
204 | *nshared &= ~s->unshare_child_perms; | ||
205 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
206 | index XXXXXXX..XXXXXXX 100644 | ||
207 | --- a/block/blklogwrites.c | ||
208 | +++ b/block/blklogwrites.c | ||
209 | @@ -XXX,XX +XXX,XX @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) | ||
210 | |||
211 | static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
212 | const BdrvChildClass *child_class, | ||
213 | + BdrvChildRole role, | ||
214 | BlockReopenQueue *ro_q, | ||
215 | uint64_t perm, uint64_t shrd, | ||
216 | uint64_t *nperm, uint64_t *nshrd) | ||
217 | @@ -XXX,XX +XXX,XX @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
218 | } | ||
219 | |||
220 | if (!strcmp(c->name, "log")) { | ||
221 | - bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, | ||
222 | - nshrd); | ||
223 | + bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
224 | + nperm, nshrd); | ||
225 | } else { | ||
226 | - bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm, | ||
227 | - nshrd); | ||
228 | + bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
229 | + nperm, nshrd); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | diff --git a/block/commit.c b/block/commit.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/block/commit.c | ||
236 | +++ b/block/commit.c | ||
237 | @@ -XXX,XX +XXX,XX @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) | ||
238 | |||
239 | static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
240 | const BdrvChildClass *child_class, | ||
241 | + BdrvChildRole role, | ||
242 | BlockReopenQueue *reopen_queue, | ||
243 | uint64_t perm, uint64_t shared, | ||
244 | uint64_t *nperm, uint64_t *nshared) | ||
245 | diff --git a/block/copy-on-read.c b/block/copy-on-read.c | ||
246 | index XXXXXXX..XXXXXXX 100644 | ||
247 | --- a/block/copy-on-read.c | ||
248 | +++ b/block/copy-on-read.c | ||
249 | @@ -XXX,XX +XXX,XX @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, | ||
250 | |||
251 | static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
252 | const BdrvChildClass *child_class, | ||
253 | + BdrvChildRole role, | ||
254 | BlockReopenQueue *reopen_queue, | ||
255 | uint64_t perm, uint64_t shared, | ||
256 | uint64_t *nperm, uint64_t *nshared) | ||
257 | diff --git a/block/mirror.c b/block/mirror.c | ||
258 | index XXXXXXX..XXXXXXX 100644 | ||
259 | --- a/block/mirror.c | ||
260 | +++ b/block/mirror.c | ||
261 | @@ -XXX,XX +XXX,XX @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) | ||
262 | |||
263 | static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
264 | const BdrvChildClass *child_class, | ||
265 | + BdrvChildRole role, | ||
266 | BlockReopenQueue *reopen_queue, | ||
267 | uint64_t perm, uint64_t shared, | ||
268 | uint64_t *nperm, uint64_t *nshared) | ||
269 | diff --git a/block/quorum.c b/block/quorum.c | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/block/quorum.c | ||
272 | +++ b/block/quorum.c | ||
273 | @@ -XXX,XX +XXX,XX @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) | ||
274 | |||
275 | static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
276 | const BdrvChildClass *child_class, | ||
277 | + BdrvChildRole role, | ||
278 | BlockReopenQueue *reopen_queue, | ||
279 | uint64_t perm, uint64_t shared, | ||
280 | uint64_t *nperm, uint64_t *nshared) | ||
281 | diff --git a/block/replication.c b/block/replication.c | ||
282 | index XXXXXXX..XXXXXXX 100644 | ||
283 | --- a/block/replication.c | ||
284 | +++ b/block/replication.c | ||
285 | @@ -XXX,XX +XXX,XX @@ static void replication_close(BlockDriverState *bs) | ||
286 | |||
287 | static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
288 | const BdrvChildClass *child_class, | ||
289 | + BdrvChildRole role, | ||
290 | BlockReopenQueue *reopen_queue, | ||
291 | uint64_t perm, uint64_t shared, | ||
292 | uint64_t *nperm, uint64_t *nshared) | ||
293 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
294 | index XXXXXXX..XXXXXXX 100644 | ||
295 | --- a/block/vvfat.c | ||
296 | +++ b/block/vvfat.c | ||
297 | @@ -XXX,XX +XXX,XX @@ err: | ||
298 | |||
299 | static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
300 | const BdrvChildClass *child_class, | ||
301 | + BdrvChildRole role, | ||
302 | BlockReopenQueue *reopen_queue, | ||
303 | uint64_t perm, uint64_t shared, | ||
304 | uint64_t *nperm, uint64_t *nshared) | ||
305 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
306 | index XXXXXXX..XXXXXXX 100644 | ||
307 | --- a/tests/test-bdrv-drain.c | ||
308 | +++ b/tests/test-bdrv-drain.c | ||
309 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, | ||
310 | |||
311 | static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
312 | const BdrvChildClass *child_class, | ||
313 | + BdrvChildRole role, | ||
314 | BlockReopenQueue *reopen_queue, | ||
315 | uint64_t perm, uint64_t shared, | ||
316 | uint64_t *nperm, uint64_t *nshared) | ||
317 | @@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
318 | child_class = &child_file; | ||
319 | } | ||
320 | |||
321 | - bdrv_format_default_perms(bs, c, child_class, reopen_queue, perm, shared, | ||
322 | - nperm, nshared); | ||
323 | + bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, | ||
324 | + perm, shared, nperm, nshared); | ||
325 | } | ||
326 | |||
327 | static int bdrv_test_change_backing_file(BlockDriverState *bs, | ||
328 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
329 | index XXXXXXX..XXXXXXX 100644 | ||
330 | --- a/tests/test-bdrv-graph-mod.c | ||
331 | +++ b/tests/test-bdrv-graph-mod.c | ||
332 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_pass_through = { | ||
333 | |||
334 | static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
335 | const BdrvChildClass *child_class, | ||
336 | + BdrvChildRole role, | ||
337 | BlockReopenQueue *reopen_queue, | ||
338 | uint64_t perm, uint64_t shared, | ||
339 | uint64_t *nperm, uint64_t *nshared) | ||
340 | -- | ||
341 | 2.25.4 | ||
342 | |||
343 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | For now, all callers (effectively) pass 0 and no callee evaluates thie | ||
4 | value. Later patches will change both. | ||
5 | |||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Message-Id: <20200513110544.176672-8-mreitz@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | include/block/block_int.h | 3 ++- | ||
12 | block.c | 40 +++++++++++++++++++++++---------------- | ||
13 | block/block-backend.c | 3 ++- | ||
14 | block/vvfat.c | 3 ++- | ||
15 | 4 files changed, 30 insertions(+), 19 deletions(-) | ||
16 | |||
17 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/block/block_int.h | ||
20 | +++ b/include/block/block_int.h | ||
21 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
22 | * non-BDS parents. */ | ||
23 | bool parent_is_bds; | ||
24 | |||
25 | - void (*inherit_options)(int *child_flags, QDict *child_options, | ||
26 | + void (*inherit_options)(BdrvChildRole role, | ||
27 | + int *child_flags, QDict *child_options, | ||
28 | int parent_flags, QDict *parent_options); | ||
29 | |||
30 | void (*change_media)(BdrvChild *child, bool load); | ||
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 | QDict *options, int flags, | ||
37 | BlockDriverState *parent, | ||
38 | const BdrvChildClass *child_class, | ||
39 | + BdrvChildRole child_role, | ||
40 | Error **errp); | ||
41 | |||
42 | /* If non-zero, use only whitelisted block drivers */ | ||
43 | @@ -XXX,XX +XXX,XX @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, | ||
44 | * Returns the options and flags that bs->file should get if a protocol driver | ||
45 | * is expected, based on the given options and flags for the parent BDS | ||
46 | */ | ||
47 | -static void bdrv_inherited_options(int *child_flags, QDict *child_options, | ||
48 | +static void bdrv_inherited_options(BdrvChildRole role, | ||
49 | + int *child_flags, QDict *child_options, | ||
50 | int parent_flags, QDict *parent_options) | ||
51 | { | ||
52 | int flags = parent_flags; | ||
53 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_file = { | ||
54 | * (and not only protocols) is permitted for it, based on the given options and | ||
55 | * flags for the parent BDS | ||
56 | */ | ||
57 | -static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, | ||
58 | +static void bdrv_inherited_fmt_options(BdrvChildRole role, | ||
59 | + int *child_flags, QDict *child_options, | ||
60 | int parent_flags, QDict *parent_options) | ||
61 | { | ||
62 | - child_file.inherit_options(child_flags, child_options, | ||
63 | + child_file.inherit_options(role, child_flags, child_options, | ||
64 | parent_flags, parent_options); | ||
65 | |||
66 | *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c) | ||
68 | * Returns the options and flags that bs->backing should get, based on the | ||
69 | * given options and flags for the parent BDS | ||
70 | */ | ||
71 | -static void bdrv_backing_options(int *child_flags, QDict *child_options, | ||
72 | +static void bdrv_backing_options(BdrvChildRole role, | ||
73 | + int *child_flags, QDict *child_options, | ||
74 | int parent_flags, QDict *parent_options) | ||
75 | { | ||
76 | int flags = parent_flags; | ||
77 | @@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, | ||
78 | } | ||
79 | |||
80 | backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs, | ||
81 | - &child_backing, errp); | ||
82 | + &child_backing, 0, errp); | ||
83 | if (!backing_hd) { | ||
84 | bs->open_flags |= BDRV_O_NO_BACKING; | ||
85 | error_prepend(errp, "Could not open backing file: "); | ||
86 | @@ -XXX,XX +XXX,XX @@ free_exit: | ||
87 | static BlockDriverState * | ||
88 | bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | ||
89 | BlockDriverState *parent, const BdrvChildClass *child_class, | ||
90 | - bool allow_none, Error **errp) | ||
91 | + BdrvChildRole child_role, bool allow_none, Error **errp) | ||
92 | { | ||
93 | BlockDriverState *bs = NULL; | ||
94 | QDict *image_options; | ||
95 | @@ -XXX,XX +XXX,XX @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, | ||
96 | } | ||
97 | |||
98 | bs = bdrv_open_inherit(filename, reference, image_options, 0, | ||
99 | - parent, child_class, errp); | ||
100 | + parent, child_class, child_role, errp); | ||
101 | if (!bs) { | ||
102 | goto done; | ||
103 | } | ||
104 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename, | ||
105 | BlockDriverState *bs; | ||
106 | |||
107 | bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class, | ||
108 | - allow_none, errp); | ||
109 | + child_role, allow_none, errp); | ||
110 | if (bs == NULL) { | ||
111 | return NULL; | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) | ||
114 | |||
115 | } | ||
116 | |||
117 | - bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp); | ||
118 | + bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, 0, errp); | ||
119 | obj = NULL; | ||
120 | qobject_unref(obj); | ||
121 | visit_free(v); | ||
122 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
123 | QDict *options, int flags, | ||
124 | BlockDriverState *parent, | ||
125 | const BdrvChildClass *child_class, | ||
126 | + BdrvChildRole child_role, | ||
127 | Error **errp) | ||
128 | { | ||
129 | int ret; | ||
130 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
131 | |||
132 | if (child_class) { | ||
133 | bs->inherits_from = parent; | ||
134 | - child_class->inherit_options(&flags, options, | ||
135 | + child_class->inherit_options(child_role, &flags, options, | ||
136 | parent->open_flags, parent->options); | ||
137 | } | ||
138 | |||
139 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
140 | flags, options); | ||
141 | /* Let bdrv_backing_options() override "read-only" */ | ||
142 | qdict_del(options, BDRV_OPT_READ_ONLY); | ||
143 | - bdrv_backing_options(&flags, options, flags, options); | ||
144 | + bdrv_backing_options(0, &flags, options, flags, options); | ||
145 | } | ||
146 | |||
147 | bs->open_flags = flags; | ||
148 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
149 | BlockDriverState *file_bs; | ||
150 | |||
151 | file_bs = bdrv_open_child_bs(filename, options, "file", bs, | ||
152 | - &child_file, true, &local_err); | ||
153 | + &child_file, 0, true, &local_err); | ||
154 | if (local_err) { | ||
155 | goto fail; | ||
156 | } | ||
157 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, | ||
158 | QDict *options, int flags, Error **errp) | ||
159 | { | ||
160 | return bdrv_open_inherit(filename, reference, options, flags, NULL, | ||
161 | - NULL, errp); | ||
162 | + NULL, 0, errp); | ||
163 | } | ||
164 | |||
165 | /* Return true if the NULL-terminated @list contains @str */ | ||
166 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
167 | BlockDriverState *bs, | ||
168 | QDict *options, | ||
169 | const BdrvChildClass *klass, | ||
170 | + BdrvChildRole role, | ||
171 | QDict *parent_options, | ||
172 | int parent_flags, | ||
173 | bool keep_old_opts) | ||
174 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
175 | /* Inherit from parent node */ | ||
176 | if (parent_options) { | ||
177 | flags = 0; | ||
178 | - klass->inherit_options(&flags, options, parent_flags, parent_options); | ||
179 | + klass->inherit_options(role, &flags, options, | ||
180 | + parent_flags, parent_options); | ||
181 | } else { | ||
182 | flags = bdrv_get_flags(bs); | ||
183 | } | ||
184 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
185 | } | ||
186 | |||
187 | bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, | ||
188 | - child->klass, options, flags, child_keep_old); | ||
189 | + child->klass, child->role, options, flags, | ||
190 | + child_keep_old); | ||
191 | } | ||
192 | |||
193 | return bs_queue; | ||
194 | @@ -XXX,XX +XXX,XX @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, | ||
195 | BlockDriverState *bs, | ||
196 | QDict *options, bool keep_old_opts) | ||
197 | { | ||
198 | - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0, | ||
199 | + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, NULL, 0, | ||
200 | keep_old_opts); | ||
201 | } | ||
202 | |||
203 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
204 | index XXXXXXX..XXXXXXX 100644 | ||
205 | --- a/block/block-backend.c | ||
206 | +++ b/block/block-backend.c | ||
207 | @@ -XXX,XX +XXX,XX @@ static QTAILQ_HEAD(, BlockBackend) block_backends = | ||
208 | static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = | ||
209 | QTAILQ_HEAD_INITIALIZER(monitor_block_backends); | ||
210 | |||
211 | -static void blk_root_inherit_options(int *child_flags, QDict *child_options, | ||
212 | +static void blk_root_inherit_options(BdrvChildRole role, | ||
213 | + int *child_flags, QDict *child_options, | ||
214 | int parent_flags, QDict *parent_options) | ||
215 | { | ||
216 | /* We're not supposed to call this function for root nodes */ | ||
217 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
218 | index XXXXXXX..XXXXXXX 100644 | ||
219 | --- a/block/vvfat.c | ||
220 | +++ b/block/vvfat.c | ||
221 | @@ -XXX,XX +XXX,XX @@ static BlockDriver vvfat_write_target = { | ||
222 | .bdrv_co_pwritev = write_target_commit, | ||
223 | }; | ||
224 | |||
225 | -static void vvfat_qcow_options(int *child_flags, QDict *child_options, | ||
226 | +static void vvfat_qcow_options(BdrvChildRole role, | ||
227 | + int *child_flags, QDict *child_options, | ||
228 | int parent_flags, QDict *parent_options) | ||
229 | { | ||
230 | qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "off"); | ||
231 | -- | ||
232 | 2.25.4 | ||
233 | |||
234 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | We plan to unify the generic .inherit_options() functions. The | ||
4 | resulting common function will need to decide whether to force-enable | ||
5 | format probing, force-disable it, or leave it as-is. To make this | ||
6 | decision, it will need to know whether the parent node is a format node | ||
7 | or not (because we never want format probing if the parent is a format | ||
8 | node already (except for the backing chain)). | ||
9 | |||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Message-Id: <20200513110544.176672-9-mreitz@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | include/block/block_int.h | 2 +- | ||
16 | block.c | 37 +++++++++++++++++++++++++++---------- | ||
17 | block/block-backend.c | 2 +- | ||
18 | block/vvfat.c | 2 +- | ||
19 | 4 files changed, 30 insertions(+), 13 deletions(-) | ||
20 | |||
21 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/block/block_int.h | ||
24 | +++ b/include/block/block_int.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
26 | * non-BDS parents. */ | ||
27 | bool parent_is_bds; | ||
28 | |||
29 | - void (*inherit_options)(BdrvChildRole role, | ||
30 | + void (*inherit_options)(BdrvChildRole role, bool parent_is_format, | ||
31 | int *child_flags, QDict *child_options, | ||
32 | int parent_flags, QDict *parent_options); | ||
33 | |||
34 | diff --git a/block.c b/block.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block.c | ||
37 | +++ b/block.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, | ||
39 | * Returns the options and flags that bs->file should get if a protocol driver | ||
40 | * is expected, based on the given options and flags for the parent BDS | ||
41 | */ | ||
42 | -static void bdrv_inherited_options(BdrvChildRole role, | ||
43 | +static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
44 | int *child_flags, QDict *child_options, | ||
45 | int parent_flags, QDict *parent_options) | ||
46 | { | ||
47 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_file = { | ||
48 | * flags for the parent BDS | ||
49 | */ | ||
50 | static void bdrv_inherited_fmt_options(BdrvChildRole role, | ||
51 | + bool parent_is_format, | ||
52 | int *child_flags, QDict *child_options, | ||
53 | int parent_flags, QDict *parent_options) | ||
54 | { | ||
55 | - child_file.inherit_options(role, child_flags, child_options, | ||
56 | + child_file.inherit_options(role, parent_is_format, | ||
57 | + child_flags, child_options, | ||
58 | parent_flags, parent_options); | ||
59 | |||
60 | *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); | ||
61 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c) | ||
62 | * Returns the options and flags that bs->backing should get, based on the | ||
63 | * given options and flags for the parent BDS | ||
64 | */ | ||
65 | -static void bdrv_backing_options(BdrvChildRole role, | ||
66 | +static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, | ||
67 | int *child_flags, QDict *child_options, | ||
68 | int parent_flags, QDict *parent_options) | ||
69 | { | ||
70 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
71 | bs->explicit_options = qdict_clone_shallow(options); | ||
72 | |||
73 | if (child_class) { | ||
74 | + bool parent_is_format; | ||
75 | + | ||
76 | + if (parent->drv) { | ||
77 | + parent_is_format = parent->drv->is_format; | ||
78 | + } else { | ||
79 | + /* | ||
80 | + * parent->drv is not set yet because this node is opened for | ||
81 | + * (potential) format probing. That means that @parent is going | ||
82 | + * to be a format node. | ||
83 | + */ | ||
84 | + parent_is_format = true; | ||
85 | + } | ||
86 | + | ||
87 | bs->inherits_from = parent; | ||
88 | - child_class->inherit_options(child_role, &flags, options, | ||
89 | + child_class->inherit_options(child_role, parent_is_format, | ||
90 | + &flags, options, | ||
91 | parent->open_flags, parent->options); | ||
92 | } | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
95 | flags, options); | ||
96 | /* Let bdrv_backing_options() override "read-only" */ | ||
97 | qdict_del(options, BDRV_OPT_READ_ONLY); | ||
98 | - bdrv_backing_options(0, &flags, options, flags, options); | ||
99 | + bdrv_backing_options(0, true, &flags, options, flags, options); | ||
100 | } | ||
101 | |||
102 | bs->open_flags = flags; | ||
103 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
104 | QDict *options, | ||
105 | const BdrvChildClass *klass, | ||
106 | BdrvChildRole role, | ||
107 | + bool parent_is_format, | ||
108 | QDict *parent_options, | ||
109 | int parent_flags, | ||
110 | bool keep_old_opts) | ||
111 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
112 | /* Inherit from parent node */ | ||
113 | if (parent_options) { | ||
114 | flags = 0; | ||
115 | - klass->inherit_options(role, &flags, options, | ||
116 | + klass->inherit_options(role, parent_is_format, &flags, options, | ||
117 | parent_flags, parent_options); | ||
118 | } else { | ||
119 | flags = bdrv_get_flags(bs); | ||
120 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
121 | } | ||
122 | |||
123 | bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, | ||
124 | - child->klass, child->role, options, flags, | ||
125 | - child_keep_old); | ||
126 | + child->klass, child->role, bs->drv->is_format, | ||
127 | + options, flags, child_keep_old); | ||
128 | } | ||
129 | |||
130 | return bs_queue; | ||
131 | @@ -XXX,XX +XXX,XX @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, | ||
132 | BlockDriverState *bs, | ||
133 | QDict *options, bool keep_old_opts) | ||
134 | { | ||
135 | - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, NULL, 0, | ||
136 | - keep_old_opts); | ||
137 | + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, 0, false, | ||
138 | + NULL, 0, keep_old_opts); | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
143 | index XXXXXXX..XXXXXXX 100644 | ||
144 | --- a/block/block-backend.c | ||
145 | +++ b/block/block-backend.c | ||
146 | @@ -XXX,XX +XXX,XX @@ static QTAILQ_HEAD(, BlockBackend) block_backends = | ||
147 | static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = | ||
148 | QTAILQ_HEAD_INITIALIZER(monitor_block_backends); | ||
149 | |||
150 | -static void blk_root_inherit_options(BdrvChildRole role, | ||
151 | +static void blk_root_inherit_options(BdrvChildRole role, bool parent_is_format, | ||
152 | int *child_flags, QDict *child_options, | ||
153 | int parent_flags, QDict *parent_options) | ||
154 | { | ||
155 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/block/vvfat.c | ||
158 | +++ b/block/vvfat.c | ||
159 | @@ -XXX,XX +XXX,XX @@ static BlockDriver vvfat_write_target = { | ||
160 | .bdrv_co_pwritev = write_target_commit, | ||
161 | }; | ||
162 | |||
163 | -static void vvfat_qcow_options(BdrvChildRole role, | ||
164 | +static void vvfat_qcow_options(BdrvChildRole role, bool parent_is_format, | ||
165 | int *child_flags, QDict *child_options, | ||
166 | int parent_flags, QDict *parent_options) | ||
167 | { | ||
168 | -- | ||
169 | 2.25.4 | ||
170 | |||
171 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | The other two .inherit_options implementations specify exactly for what | ||
4 | case they are used in their name, so do it for this one as well. | ||
5 | |||
6 | (The actual intention behind this patch is to follow it up with a | ||
7 | generic bdrv_inherited_options() that works for all three cases.) | ||
8 | |||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
11 | Message-Id: <20200513110544.176672-10-mreitz@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | --- | ||
14 | block.c | 8 ++++---- | ||
15 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
16 | |||
17 | diff --git a/block.c b/block.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block.c | ||
20 | +++ b/block.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, | ||
22 | * Returns the options and flags that bs->file should get if a protocol driver | ||
23 | * is expected, based on the given options and flags for the parent BDS | ||
24 | */ | ||
25 | -static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
26 | - int *child_flags, QDict *child_options, | ||
27 | - int parent_flags, QDict *parent_options) | ||
28 | +static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, | ||
29 | + int *child_flags, QDict *child_options, | ||
30 | + int parent_flags, QDict *parent_options) | ||
31 | { | ||
32 | int flags = parent_flags; | ||
33 | |||
34 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
35 | const BdrvChildClass child_file = { | ||
36 | .parent_is_bds = true, | ||
37 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
38 | - .inherit_options = bdrv_inherited_options, | ||
39 | + .inherit_options = bdrv_protocol_options, | ||
40 | .drained_begin = bdrv_child_cb_drained_begin, | ||
41 | .drained_poll = bdrv_child_cb_drained_poll, | ||
42 | .drained_end = bdrv_child_cb_drained_end, | ||
43 | -- | ||
44 | 2.25.4 | ||
45 | |||
46 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | After the series this patch belongs to, we want to have a common | ||
4 | BdrvChildClass that encompasses all of child_file, child_format, and | ||
5 | child_backing. Such a single class needs a single .inherit_options() | ||
6 | implementation, and this patch introduces it. | ||
7 | |||
8 | The next patch will show how the existing implementations can fall back | ||
9 | to it just by passing appropriate BdrvChildRole and parent_is_format | ||
10 | values. | ||
11 | |||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | Message-Id: <20200513110544.176672-11-mreitz@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | --- | ||
17 | block.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
18 | 1 file changed, 81 insertions(+) | ||
19 | |||
20 | diff --git a/block.c b/block.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/block.c | ||
23 | +++ b/block.c | ||
24 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_backing = { | ||
25 | .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
26 | }; | ||
27 | |||
28 | +/* | ||
29 | + * Returns the options and flags that a generic child of a BDS should | ||
30 | + * get, based on the given options and flags for the parent BDS. | ||
31 | + */ | ||
32 | +static void __attribute__((unused)) | ||
33 | + bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
34 | + int *child_flags, QDict *child_options, | ||
35 | + int parent_flags, QDict *parent_options) | ||
36 | +{ | ||
37 | + int flags = parent_flags; | ||
38 | + | ||
39 | + /* | ||
40 | + * First, decide whether to set, clear, or leave BDRV_O_PROTOCOL. | ||
41 | + * Generally, the question to answer is: Should this child be | ||
42 | + * format-probed by default? | ||
43 | + */ | ||
44 | + | ||
45 | + /* | ||
46 | + * Pure and non-filtered data children of non-format nodes should | ||
47 | + * be probed by default (even when the node itself has BDRV_O_PROTOCOL | ||
48 | + * set). This only affects a very limited set of drivers (namely | ||
49 | + * quorum and blkverify when this comment was written). | ||
50 | + * Force-clear BDRV_O_PROTOCOL then. | ||
51 | + */ | ||
52 | + if (!parent_is_format && | ||
53 | + (role & BDRV_CHILD_DATA) && | ||
54 | + !(role & (BDRV_CHILD_METADATA | BDRV_CHILD_FILTERED))) | ||
55 | + { | ||
56 | + flags &= ~BDRV_O_PROTOCOL; | ||
57 | + } | ||
58 | + | ||
59 | + /* | ||
60 | + * All children of format nodes (except for COW children) and all | ||
61 | + * metadata children in general should never be format-probed. | ||
62 | + * Force-set BDRV_O_PROTOCOL then. | ||
63 | + */ | ||
64 | + if ((parent_is_format && !(role & BDRV_CHILD_COW)) || | ||
65 | + (role & BDRV_CHILD_METADATA)) | ||
66 | + { | ||
67 | + flags |= BDRV_O_PROTOCOL; | ||
68 | + } | ||
69 | + | ||
70 | + /* | ||
71 | + * If the cache mode isn't explicitly set, inherit direct and no-flush from | ||
72 | + * the parent. | ||
73 | + */ | ||
74 | + qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); | ||
75 | + qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); | ||
76 | + qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); | ||
77 | + | ||
78 | + if (role & BDRV_CHILD_COW) { | ||
79 | + /* backing files are opened read-only by default */ | ||
80 | + qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); | ||
81 | + qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); | ||
82 | + } else { | ||
83 | + /* Inherit the read-only option from the parent if it's not set */ | ||
84 | + qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); | ||
85 | + qdict_copy_default(child_options, parent_options, | ||
86 | + BDRV_OPT_AUTO_READ_ONLY); | ||
87 | + } | ||
88 | + | ||
89 | + /* | ||
90 | + * bdrv_co_pdiscard() respects unmap policy for the parent, so we | ||
91 | + * can default to enable it on lower layers regardless of the | ||
92 | + * parent option. | ||
93 | + */ | ||
94 | + qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap"); | ||
95 | + | ||
96 | + /* Clear flags that only apply to the top layer */ | ||
97 | + flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ); | ||
98 | + | ||
99 | + if (role & BDRV_CHILD_METADATA) { | ||
100 | + flags &= ~BDRV_O_NO_IO; | ||
101 | + } | ||
102 | + if (role & BDRV_CHILD_COW) { | ||
103 | + flags &= ~BDRV_O_TEMPORARY; | ||
104 | + } | ||
105 | + | ||
106 | + *child_flags = flags; | ||
107 | +} | ||
108 | + | ||
109 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | ||
110 | { | ||
111 | int open_flags = flags; | ||
112 | -- | ||
113 | 2.25.4 | ||
114 | |||
115 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Let child_file's, child_format's, and child_backing's .inherit_options() | ||
4 | implementations fall back to bdrv_inherited_options() to show that it | ||
5 | would really work for all of these cases, if only the parents passed the | ||
6 | appropriate BdrvChildRole and parent_is_format values. | ||
7 | |||
8 | (Also, make bdrv_open_inherit(), the only place to explicitly call | ||
9 | bdrv_backing_options(), call bdrv_inherited_options() instead.) | ||
10 | |||
11 | This patch should incur only two visible changes, both for child_format | ||
12 | children, both of which are effectively bug fixes: | ||
13 | |||
14 | First, they no longer have discard=unmap set by default. This reason it | ||
15 | was set is because bdrv_inherited_fmt_options() fell through to | ||
16 | bdrv_protocol_options(), and that set it because "format drivers take | ||
17 | care to send flushes and respect unmap policy". None of the drivers | ||
18 | that use child_format for their children (quorum and blkverify) are | ||
19 | format drivers, though, so this reasoning does not apply here. | ||
20 | |||
21 | Second, they no longer have BDRV_O_NO_IO force-cleared. child_format | ||
22 | was used solely for children that do not store any metadata and as such | ||
23 | will not be accessed by their parents as long as those parents do not | ||
24 | receive I/O themselves. Thus, such children should inherit | ||
25 | BDRV_O_NO_IO. | ||
26 | |||
27 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
28 | Message-Id: <20200513110544.176672-12-mreitz@redhat.com> | ||
29 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
30 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
31 | --- | ||
32 | block.c | 71 +++++++++++++++------------------------------------------ | ||
33 | 1 file changed, 19 insertions(+), 52 deletions(-) | ||
34 | |||
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 BlockDriverState *bdrv_open_inherit(const char *filename, | ||
40 | BdrvChildRole child_role, | ||
41 | Error **errp); | ||
42 | |||
43 | +/* TODO: Remove when no longer needed */ | ||
44 | +static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
45 | + int *child_flags, QDict *child_options, | ||
46 | + int parent_flags, QDict *parent_options); | ||
47 | + | ||
48 | /* If non-zero, use only whitelisted block drivers */ | ||
49 | static int use_bdrv_whitelist; | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, | ||
52 | int *child_flags, QDict *child_options, | ||
53 | int parent_flags, QDict *parent_options) | ||
54 | { | ||
55 | - int flags = parent_flags; | ||
56 | - | ||
57 | - /* Enable protocol handling, disable format probing for bs->file */ | ||
58 | - flags |= BDRV_O_PROTOCOL; | ||
59 | - | ||
60 | - /* If the cache mode isn't explicitly set, inherit direct and no-flush from | ||
61 | - * the parent. */ | ||
62 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); | ||
63 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); | ||
64 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); | ||
65 | - | ||
66 | - /* Inherit the read-only option from the parent if it's not set */ | ||
67 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); | ||
68 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_AUTO_READ_ONLY); | ||
69 | - | ||
70 | - /* Our block drivers take care to send flushes and respect unmap policy, | ||
71 | - * so we can default to enable both on lower layers regardless of the | ||
72 | - * corresponding parent options. */ | ||
73 | - qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap"); | ||
74 | - | ||
75 | - /* Clear flags that only apply to the top layer */ | ||
76 | - flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ | | ||
77 | - BDRV_O_NO_IO); | ||
78 | - | ||
79 | - *child_flags = flags; | ||
80 | + bdrv_inherited_options(BDRV_CHILD_IMAGE, true, | ||
81 | + child_flags, child_options, | ||
82 | + parent_flags, parent_options); | ||
83 | } | ||
84 | |||
85 | const BdrvChildClass child_file = { | ||
86 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_fmt_options(BdrvChildRole role, | ||
87 | int *child_flags, QDict *child_options, | ||
88 | int parent_flags, QDict *parent_options) | ||
89 | { | ||
90 | - child_file.inherit_options(role, parent_is_format, | ||
91 | - child_flags, child_options, | ||
92 | - parent_flags, parent_options); | ||
93 | - | ||
94 | - *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO); | ||
95 | + bdrv_inherited_options(BDRV_CHILD_DATA, false, | ||
96 | + child_flags, child_options, | ||
97 | + parent_flags, parent_options); | ||
98 | } | ||
99 | |||
100 | const BdrvChildClass child_format = { | ||
101 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, | ||
102 | int *child_flags, QDict *child_options, | ||
103 | int parent_flags, QDict *parent_options) | ||
104 | { | ||
105 | - int flags = parent_flags; | ||
106 | - | ||
107 | - /* The cache mode is inherited unmodified for backing files; except WCE, | ||
108 | - * which is only applied on the top level (BlockBackend) */ | ||
109 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT); | ||
110 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH); | ||
111 | - qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE); | ||
112 | - | ||
113 | - /* backing files always opened read-only */ | ||
114 | - qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); | ||
115 | - qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); | ||
116 | - flags &= ~BDRV_O_COPY_ON_READ; | ||
117 | - | ||
118 | - /* snapshot=on is handled on the top layer */ | ||
119 | - flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_TEMPORARY); | ||
120 | - | ||
121 | - *child_flags = flags; | ||
122 | + bdrv_inherited_options(BDRV_CHILD_COW, true, | ||
123 | + child_flags, child_options, | ||
124 | + parent_flags, parent_options); | ||
125 | } | ||
126 | |||
127 | static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | ||
128 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_backing = { | ||
129 | * Returns the options and flags that a generic child of a BDS should | ||
130 | * get, based on the given options and flags for the parent BDS. | ||
131 | */ | ||
132 | -static void __attribute__((unused)) | ||
133 | - bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
134 | - int *child_flags, QDict *child_options, | ||
135 | - int parent_flags, QDict *parent_options) | ||
136 | +static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
137 | + int *child_flags, QDict *child_options, | ||
138 | + int parent_flags, QDict *parent_options) | ||
139 | { | ||
140 | int flags = parent_flags; | ||
141 | |||
142 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
143 | flags, options); | ||
144 | /* Let bdrv_backing_options() override "read-only" */ | ||
145 | qdict_del(options, BDRV_OPT_READ_ONLY); | ||
146 | - bdrv_backing_options(0, true, &flags, options, flags, options); | ||
147 | + bdrv_inherited_options(BDRV_CHILD_COW, true, | ||
148 | + &flags, options, flags, options); | ||
149 | } | ||
150 | |||
151 | bs->open_flags = flags; | ||
152 | -- | ||
153 | 2.25.4 | ||
154 | |||
155 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Make bdrv_child_cb_attach() call bdrv_backing_attach() for children with | ||
4 | a COW role (and drop the reverse call from bdrv_backing_attach()), so it | ||
5 | can be used for any child (with a proper role set). | ||
6 | |||
7 | Because so far no child has a proper role set, we need a temporary new | ||
8 | callback for child_backing.attach that ensures bdrv_backing_attach() is | ||
9 | called for all COW children that do not have their role set yet. | ||
10 | |||
11 | (Also, move bdrv_child_cb_attach() down to group it with | ||
12 | bdrv_inherited_options().) | ||
13 | |||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | Message-Id: <20200513110544.176672-13-mreitz@redhat.com> | ||
16 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | --- | ||
19 | block.c | 27 ++++++++++++++++++++------- | ||
20 | 1 file changed, 20 insertions(+), 7 deletions(-) | ||
21 | |||
22 | diff --git a/block.c b/block.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block.c | ||
25 | +++ b/block.c | ||
26 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
27 | static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
28 | int *child_flags, QDict *child_options, | ||
29 | int parent_flags, QDict *parent_options); | ||
30 | +static void bdrv_child_cb_attach(BdrvChild *child); | ||
31 | |||
32 | /* If non-zero, use only whitelisted block drivers */ | ||
33 | static int use_bdrv_whitelist; | ||
34 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child, | ||
35 | bdrv_drained_end_no_poll(bs, drained_end_counter); | ||
36 | } | ||
37 | |||
38 | -static void bdrv_child_cb_attach(BdrvChild *child) | ||
39 | -{ | ||
40 | - BlockDriverState *bs = child->opaque; | ||
41 | - bdrv_apply_subtree_drain(child, bs); | ||
42 | -} | ||
43 | - | ||
44 | static void bdrv_child_cb_detach(BdrvChild *child) | ||
45 | { | ||
46 | BlockDriverState *bs = child->opaque; | ||
47 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_attach(BdrvChild *c) | ||
48 | parent->backing_blocker); | ||
49 | bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, | ||
50 | parent->backing_blocker); | ||
51 | +} | ||
52 | |||
53 | +/* XXX: Will be removed along with child_backing */ | ||
54 | +static void bdrv_child_cb_attach_backing(BdrvChild *c) | ||
55 | +{ | ||
56 | + if (!(c->role & BDRV_CHILD_COW)) { | ||
57 | + bdrv_backing_attach(c); | ||
58 | + } | ||
59 | bdrv_child_cb_attach(c); | ||
60 | } | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | ||
63 | const BdrvChildClass child_backing = { | ||
64 | .parent_is_bds = true, | ||
65 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
66 | - .attach = bdrv_backing_attach, | ||
67 | + .attach = bdrv_child_cb_attach_backing, | ||
68 | .detach = bdrv_backing_detach, | ||
69 | .inherit_options = bdrv_backing_options, | ||
70 | .drained_begin = bdrv_child_cb_drained_begin, | ||
71 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
72 | *child_flags = flags; | ||
73 | } | ||
74 | |||
75 | +static void bdrv_child_cb_attach(BdrvChild *child) | ||
76 | +{ | ||
77 | + BlockDriverState *bs = child->opaque; | ||
78 | + | ||
79 | + if (child->role & BDRV_CHILD_COW) { | ||
80 | + bdrv_backing_attach(child); | ||
81 | + } | ||
82 | + | ||
83 | + bdrv_apply_subtree_drain(child, bs); | ||
84 | +} | ||
85 | + | ||
86 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | ||
87 | { | ||
88 | int open_flags = flags; | ||
89 | -- | ||
90 | 2.25.4 | ||
91 | |||
92 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Make bdrv_child_cb_detach() call bdrv_backing_detach() for children with | ||
4 | a COW role (and drop the reverse call from bdrv_backing_detach()), so it | ||
5 | can be used for any child (with a proper role set). | ||
6 | |||
7 | Because so far no child has a proper role set, we need a temporary new | ||
8 | callback for child_backing.detach that ensures bdrv_backing_detach() is | ||
9 | called for all COW children that do not have their role set yet. | ||
10 | |||
11 | (Also, move bdrv_child_cb_detach() down to group it with | ||
12 | bdrv_inherited_options() and bdrv_child_cb_attach().) | ||
13 | |||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | Message-Id: <20200513110544.176672-14-mreitz@redhat.com> | ||
16 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | --- | ||
19 | block.c | 27 ++++++++++++++++++++------- | ||
20 | 1 file changed, 20 insertions(+), 7 deletions(-) | ||
21 | |||
22 | diff --git a/block.c b/block.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block.c | ||
25 | +++ b/block.c | ||
26 | @@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
27 | int *child_flags, QDict *child_options, | ||
28 | int parent_flags, QDict *parent_options); | ||
29 | static void bdrv_child_cb_attach(BdrvChild *child); | ||
30 | +static void bdrv_child_cb_detach(BdrvChild *child); | ||
31 | |||
32 | /* If non-zero, use only whitelisted block drivers */ | ||
33 | static int use_bdrv_whitelist; | ||
34 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child, | ||
35 | bdrv_drained_end_no_poll(bs, drained_end_counter); | ||
36 | } | ||
37 | |||
38 | -static void bdrv_child_cb_detach(BdrvChild *child) | ||
39 | -{ | ||
40 | - BlockDriverState *bs = child->opaque; | ||
41 | - bdrv_unapply_subtree_drain(child, bs); | ||
42 | -} | ||
43 | - | ||
44 | static int bdrv_child_cb_inactivate(BdrvChild *child) | ||
45 | { | ||
46 | BlockDriverState *bs = child->opaque; | ||
47 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c) | ||
48 | bdrv_op_unblock_all(c->bs, parent->backing_blocker); | ||
49 | error_free(parent->backing_blocker); | ||
50 | parent->backing_blocker = NULL; | ||
51 | +} | ||
52 | |||
53 | +/* XXX: Will be removed along with child_backing */ | ||
54 | +static void bdrv_child_cb_detach_backing(BdrvChild *c) | ||
55 | +{ | ||
56 | + if (!(c->role & BDRV_CHILD_COW)) { | ||
57 | + bdrv_backing_detach(c); | ||
58 | + } | ||
59 | bdrv_child_cb_detach(c); | ||
60 | } | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_backing = { | ||
63 | .parent_is_bds = true, | ||
64 | .get_parent_desc = bdrv_child_get_parent_desc, | ||
65 | .attach = bdrv_child_cb_attach_backing, | ||
66 | - .detach = bdrv_backing_detach, | ||
67 | + .detach = bdrv_child_cb_detach_backing, | ||
68 | .inherit_options = bdrv_backing_options, | ||
69 | .drained_begin = bdrv_child_cb_drained_begin, | ||
70 | .drained_poll = bdrv_child_cb_drained_poll, | ||
71 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_attach(BdrvChild *child) | ||
72 | bdrv_apply_subtree_drain(child, bs); | ||
73 | } | ||
74 | |||
75 | +static void bdrv_child_cb_detach(BdrvChild *child) | ||
76 | +{ | ||
77 | + BlockDriverState *bs = child->opaque; | ||
78 | + | ||
79 | + if (child->role & BDRV_CHILD_COW) { | ||
80 | + bdrv_backing_detach(child); | ||
81 | + } | ||
82 | + | ||
83 | + bdrv_unapply_subtree_drain(child, bs); | ||
84 | +} | ||
85 | + | ||
86 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | ||
87 | { | ||
88 | int open_flags = flags; | ||
89 | -- | ||
90 | 2.25.4 | ||
91 | |||
92 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Any current user of child_file, child_format, and child_backing can and | ||
4 | should use this generic BdrvChildClass instead, as it can handle all of | ||
5 | these cases. However, to be able to do so, the users must pass the | ||
6 | appropriate BdrvChildRole when the child is created/attached. (The | ||
7 | following commits will take care of that.) | ||
8 | |||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-15-mreitz@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | --- | ||
14 | include/block/block_int.h | 1 + | ||
15 | block.c | 24 ++++++++++++++++++++++++ | ||
16 | 2 files changed, 25 insertions(+) | ||
17 | |||
18 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/block/block_int.h | ||
21 | +++ b/include/block/block_int.h | ||
22 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
23 | void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); | ||
24 | }; | ||
25 | |||
26 | +extern const BdrvChildClass child_of_bds; | ||
27 | extern const BdrvChildClass child_file; | ||
28 | extern const BdrvChildClass child_format; | ||
29 | extern const BdrvChildClass child_backing; | ||
30 | diff --git a/block.c b/block.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/block.c | ||
33 | +++ b/block.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_detach(BdrvChild *child) | ||
35 | bdrv_unapply_subtree_drain(child, bs); | ||
36 | } | ||
37 | |||
38 | +static int bdrv_child_cb_update_filename(BdrvChild *c, BlockDriverState *base, | ||
39 | + const char *filename, Error **errp) | ||
40 | +{ | ||
41 | + if (c->role & BDRV_CHILD_COW) { | ||
42 | + return bdrv_backing_update_filename(c, base, filename, errp); | ||
43 | + } | ||
44 | + return 0; | ||
45 | +} | ||
46 | + | ||
47 | +const BdrvChildClass child_of_bds = { | ||
48 | + .parent_is_bds = true, | ||
49 | + .get_parent_desc = bdrv_child_get_parent_desc, | ||
50 | + .inherit_options = bdrv_inherited_options, | ||
51 | + .drained_begin = bdrv_child_cb_drained_begin, | ||
52 | + .drained_poll = bdrv_child_cb_drained_poll, | ||
53 | + .drained_end = bdrv_child_cb_drained_end, | ||
54 | + .attach = bdrv_child_cb_attach, | ||
55 | + .detach = bdrv_child_cb_detach, | ||
56 | + .inactivate = bdrv_child_cb_inactivate, | ||
57 | + .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, | ||
58 | + .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
59 | + .update_filename = bdrv_child_cb_update_filename, | ||
60 | +}; | ||
61 | + | ||
62 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | ||
63 | { | ||
64 | int open_flags = flags; | ||
65 | -- | ||
66 | 2.25.4 | ||
67 | |||
68 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | bdrv_format_default_perms() has one code path for backing files, and one | ||
4 | for storage files. We want to pull them out into their own functions, | ||
5 | so make sure they are completely distinct before so the next patches | ||
6 | will be a bit cleaner. | ||
7 | |||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-16-mreitz@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block.c | 19 +++++++++++++------ | ||
14 | 1 file changed, 13 insertions(+), 6 deletions(-) | ||
15 | |||
16 | diff --git a/block.c b/block.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block.c | ||
19 | +++ b/block.c | ||
20 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
21 | perm |= BLK_PERM_CONSISTENT_READ; | ||
22 | } | ||
23 | shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
24 | + | ||
25 | + if (bs->open_flags & BDRV_O_INACTIVE) { | ||
26 | + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
27 | + } | ||
28 | + | ||
29 | + *nperm = perm; | ||
30 | + *nshared = shared; | ||
31 | } else { | ||
32 | /* We want consistent read from backing files if the parent needs it. | ||
33 | * No other operations are performed on backing files. */ | ||
34 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
35 | |||
36 | shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | | ||
37 | BLK_PERM_WRITE_UNCHANGED; | ||
38 | - } | ||
39 | |||
40 | - if (bs->open_flags & BDRV_O_INACTIVE) { | ||
41 | - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
42 | - } | ||
43 | + if (bs->open_flags & BDRV_O_INACTIVE) { | ||
44 | + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
45 | + } | ||
46 | |||
47 | - *nperm = perm; | ||
48 | - *nshared = shared; | ||
49 | + *nperm = perm; | ||
50 | + *nshared = shared; | ||
51 | + } | ||
52 | } | ||
53 | |||
54 | uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm) | ||
55 | -- | ||
56 | 2.25.4 | ||
57 | |||
58 | diff view generated by jsdifflib |
1 | We need to release any block migrations BlockBackends on the source | 1 | From: Max Reitz <mreitz@redhat.com> |
---|---|---|---|
2 | before successfully completing the migration because otherwise | ||
3 | inactivating the images will fail (inactivation only tolerates device | ||
4 | BBs). | ||
5 | 2 | ||
3 | Right now, bdrv_format_default_perms() is used by format parents | ||
4 | (generally). We want to switch to a model where most parents use a | ||
5 | single BdrvChildClass, which then decides the permissions based on the | ||
6 | child role. To do so, we have to split bdrv_format_default_perms() into | ||
7 | separate functions for each such role. | ||
8 | |||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-17-mreitz@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
10 | --- | 13 | --- |
11 | migration/block.c | 22 +++++++++++++++++----- | 14 | block.c | 62 +++++++++++++++++++++++++++++++++++++-------------------- |
12 | 1 file changed, 17 insertions(+), 5 deletions(-) | 15 | 1 file changed, 40 insertions(+), 22 deletions(-) |
13 | 16 | ||
14 | diff --git a/migration/block.c b/migration/block.c | 17 | diff --git a/block.c b/block.c |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/migration/block.c | 19 | --- a/block.c |
17 | +++ b/migration/block.c | 20 | +++ b/block.c |
18 | @@ -XXX,XX +XXX,XX @@ static int64_t get_remaining_dirty(void) | 21 | @@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, |
19 | return dirty << BDRV_SECTOR_BITS; | 22 | *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; |
20 | } | 23 | } |
21 | 24 | ||
22 | -/* Called with iothread lock taken. */ | 25 | +static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, |
23 | 26 | + const BdrvChildClass *child_class, | |
24 | -static void block_migration_cleanup(void *opaque) | 27 | + BdrvChildRole role, |
28 | + BlockReopenQueue *reopen_queue, | ||
29 | + uint64_t perm, uint64_t shared, | ||
30 | + uint64_t *nperm, uint64_t *nshared) | ||
31 | +{ | ||
32 | + assert(child_class == &child_backing || | ||
33 | + (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); | ||
25 | + | 34 | + |
26 | +/* Called with iothread lock taken. */ | 35 | + /* |
27 | +static void block_migration_cleanup_bmds(void) | 36 | + * We want consistent read from backing files if the parent needs it. |
28 | { | 37 | + * No other operations are performed on backing files. |
29 | BlkMigDevState *bmds; | 38 | + */ |
30 | - BlkMigBlock *blk; | 39 | + perm &= BLK_PERM_CONSISTENT_READ; |
31 | AioContext *ctx; | 40 | + |
32 | 41 | + /* | |
33 | - bdrv_drain_all(); | 42 | + * If the parent can deal with changing data, we're okay with a |
34 | - | 43 | + * writable and resizable backing file. |
35 | unset_dirty_tracking(); | 44 | + * TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? |
36 | 45 | + */ | |
37 | while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) { | 46 | + if (shared & BLK_PERM_WRITE) { |
38 | @@ -XXX,XX +XXX,XX @@ static void block_migration_cleanup(void *opaque) | 47 | + shared = BLK_PERM_WRITE | BLK_PERM_RESIZE; |
39 | g_free(bmds->aio_bitmap); | 48 | + } else { |
40 | g_free(bmds); | 49 | + shared = 0; |
41 | } | 50 | + } |
51 | + | ||
52 | + shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | | ||
53 | + BLK_PERM_WRITE_UNCHANGED; | ||
54 | + | ||
55 | + if (bs->open_flags & BDRV_O_INACTIVE) { | ||
56 | + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
57 | + } | ||
58 | + | ||
59 | + *nperm = perm; | ||
60 | + *nshared = shared; | ||
42 | +} | 61 | +} |
43 | + | 62 | + |
44 | +/* Called with iothread lock taken. */ | 63 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, |
45 | +static void block_migration_cleanup(void *opaque) | 64 | const BdrvChildClass *child_class, |
46 | +{ | 65 | BdrvChildRole role, |
47 | + BlkMigBlock *blk; | 66 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, |
48 | + | 67 | *nperm = perm; |
49 | + bdrv_drain_all(); | 68 | *nshared = shared; |
50 | + | 69 | } else { |
51 | + block_migration_cleanup_bmds(); | 70 | - /* We want consistent read from backing files if the parent needs it. |
52 | 71 | - * No other operations are performed on backing files. */ | |
53 | blk_mig_lock(); | 72 | - perm &= BLK_PERM_CONSISTENT_READ; |
54 | while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) { | 73 | - |
55 | @@ -XXX,XX +XXX,XX @@ static int block_save_complete(QEMUFile *f, void *opaque) | 74 | - /* If the parent can deal with changing data, we're okay with a |
56 | 75 | - * writable and resizable backing file. */ | |
57 | qemu_put_be64(f, BLK_MIG_FLAG_EOS); | 76 | - /* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? */ |
58 | 77 | - if (shared & BLK_PERM_WRITE) { | |
59 | + /* Make sure that our BlockBackends are gone, so that the block driver | 78 | - shared = BLK_PERM_WRITE | BLK_PERM_RESIZE; |
60 | + * nodes can be inactivated. */ | 79 | - } else { |
61 | + block_migration_cleanup_bmds(); | 80 | - shared = 0; |
62 | + | 81 | - } |
63 | return 0; | 82 | - |
83 | - shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | | ||
84 | - BLK_PERM_WRITE_UNCHANGED; | ||
85 | - | ||
86 | - if (bs->open_flags & BDRV_O_INACTIVE) { | ||
87 | - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
88 | - } | ||
89 | - | ||
90 | - *nperm = perm; | ||
91 | - *nshared = shared; | ||
92 | + bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, | ||
93 | + perm, shared, nperm, nshared); | ||
94 | } | ||
64 | } | 95 | } |
65 | 96 | ||
66 | -- | 97 | -- |
67 | 1.8.3.1 | 98 | 2.25.4 |
68 | 99 | ||
69 | 100 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Right now, bdrv_format_default_perms() is used by format parents | ||
4 | (generally). We want to switch to a model where most parents use a | ||
5 | single BdrvChildClass, which then decides the permissions based on the | ||
6 | child role. To do so, we have to split bdrv_format_default_perms() into | ||
7 | separate functions for each such role. | ||
8 | |||
9 | Note that bdrv_default_perms_for_storage() currently handles all DATA | | ||
10 | METADATA children. A follow-up patch is going to split it further into | ||
11 | one function for each case. | ||
12 | |||
13 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | Message-Id: <20200513110544.176672-18-mreitz@redhat.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
17 | --- | ||
18 | block.c | 71 +++++++++++++++++++++++++++++++++++++-------------------- | ||
19 | 1 file changed, 46 insertions(+), 25 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 @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, | ||
26 | *nshared = shared; | ||
27 | } | ||
28 | |||
29 | +static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
30 | + const BdrvChildClass *child_class, | ||
31 | + BdrvChildRole role, | ||
32 | + BlockReopenQueue *reopen_queue, | ||
33 | + uint64_t perm, uint64_t shared, | ||
34 | + uint64_t *nperm, uint64_t *nshared) | ||
35 | +{ | ||
36 | + int flags; | ||
37 | + | ||
38 | + assert(child_class == &child_file || | ||
39 | + (child_class == &child_of_bds && | ||
40 | + (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)))); | ||
41 | + | ||
42 | + flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
43 | + | ||
44 | + /* | ||
45 | + * Apart from the modifications below, the same permissions are | ||
46 | + * forwarded and left alone as for filters | ||
47 | + */ | ||
48 | + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
49 | + perm, shared, &perm, &shared); | ||
50 | + | ||
51 | + /* Format drivers may touch metadata even if the guest doesn't write */ | ||
52 | + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { | ||
53 | + perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
54 | + } | ||
55 | + | ||
56 | + /* | ||
57 | + * bs->file always needs to be consistent because of the metadata. We | ||
58 | + * can never allow other users to resize or write to it. | ||
59 | + */ | ||
60 | + if (!(flags & BDRV_O_NO_IO)) { | ||
61 | + perm |= BLK_PERM_CONSISTENT_READ; | ||
62 | + } | ||
63 | + shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
64 | + | ||
65 | + if (bs->open_flags & BDRV_O_INACTIVE) { | ||
66 | + shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
67 | + } | ||
68 | + | ||
69 | + *nperm = perm; | ||
70 | + *nshared = shared; | ||
71 | +} | ||
72 | + | ||
73 | void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
74 | const BdrvChildClass *child_class, | ||
75 | BdrvChildRole role, | ||
76 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
77 | assert(child_class == &child_backing || child_class == &child_file); | ||
78 | |||
79 | if (!backing) { | ||
80 | - int flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
81 | - | ||
82 | - /* Apart from the modifications below, the same permissions are | ||
83 | - * forwarded and left alone as for filters */ | ||
84 | - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
85 | - perm, shared, &perm, &shared); | ||
86 | - | ||
87 | - /* Format drivers may touch metadata even if the guest doesn't write */ | ||
88 | - if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { | ||
89 | - perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
90 | - } | ||
91 | - | ||
92 | - /* bs->file always needs to be consistent because of the metadata. We | ||
93 | - * can never allow other users to resize or write to it. */ | ||
94 | - if (!(flags & BDRV_O_NO_IO)) { | ||
95 | - perm |= BLK_PERM_CONSISTENT_READ; | ||
96 | - } | ||
97 | - shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
98 | - | ||
99 | - if (bs->open_flags & BDRV_O_INACTIVE) { | ||
100 | - shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
101 | - } | ||
102 | - | ||
103 | - *nperm = perm; | ||
104 | - *nshared = shared; | ||
105 | + bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
106 | + perm, shared, nperm, nshared); | ||
107 | } else { | ||
108 | bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, | ||
109 | perm, shared, nperm, nshared); | ||
110 | -- | ||
111 | 2.25.4 | ||
112 | |||
113 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | We can be less restrictive about pure data children than those with | ||
4 | metadata on them, so let bdrv_default_perms_for_storage() handle | ||
5 | metadata children differently from pure data children. | ||
6 | |||
7 | As explained in the code, the restrictions on metadata children are | ||
8 | strictly stricter than those for pure data children, so in theory we | ||
9 | just have to distinguish between pure-data and all other storage | ||
10 | children (pure metadata or data+metadata). In practice, that is not | ||
11 | obvious, though, so we have two independent code paths for metadata and | ||
12 | for data children, and data+metadata children will go through both | ||
13 | (without the path for data children doing anything meaningful). | ||
14 | |||
15 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
16 | Message-Id: <20200513110544.176672-19-mreitz@redhat.com> | ||
17 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | --- | ||
20 | block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++---------- | ||
21 | 1 file changed, 48 insertions(+), 10 deletions(-) | ||
22 | |||
23 | diff --git a/block.c b/block.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/block.c | ||
26 | +++ b/block.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
28 | bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
29 | perm, shared, &perm, &shared); | ||
30 | |||
31 | - /* Format drivers may touch metadata even if the guest doesn't write */ | ||
32 | - if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { | ||
33 | - perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
34 | + if (role & BDRV_CHILD_METADATA) { | ||
35 | + /* Format drivers may touch metadata even if the guest doesn't write */ | ||
36 | + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { | ||
37 | + perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
38 | + } | ||
39 | + | ||
40 | + /* | ||
41 | + * bs->file always needs to be consistent because of the | ||
42 | + * metadata. We can never allow other users to resize or write | ||
43 | + * to it. | ||
44 | + */ | ||
45 | + if (!(flags & BDRV_O_NO_IO)) { | ||
46 | + perm |= BLK_PERM_CONSISTENT_READ; | ||
47 | + } | ||
48 | + shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
49 | } | ||
50 | |||
51 | - /* | ||
52 | - * bs->file always needs to be consistent because of the metadata. We | ||
53 | - * can never allow other users to resize or write to it. | ||
54 | - */ | ||
55 | - if (!(flags & BDRV_O_NO_IO)) { | ||
56 | - perm |= BLK_PERM_CONSISTENT_READ; | ||
57 | + if (role & BDRV_CHILD_DATA) { | ||
58 | + /* | ||
59 | + * Technically, everything in this block is a subset of the | ||
60 | + * BDRV_CHILD_METADATA path taken above, and so this could | ||
61 | + * be an "else if" branch. However, that is not obvious, and | ||
62 | + * this function is not performance critical, therefore we let | ||
63 | + * this be an independent "if". | ||
64 | + */ | ||
65 | + | ||
66 | + /* | ||
67 | + * We cannot allow other users to resize the file because the | ||
68 | + * format driver might have some assumptions about the size | ||
69 | + * (e.g. because it is stored in metadata, or because the file | ||
70 | + * is split into fixed-size data files). | ||
71 | + */ | ||
72 | + shared &= ~BLK_PERM_RESIZE; | ||
73 | + | ||
74 | + /* | ||
75 | + * WRITE_UNCHANGED often cannot be performed as such on the | ||
76 | + * data file. For example, the qcow2 driver may still need to | ||
77 | + * write copied clusters on copy-on-read. | ||
78 | + */ | ||
79 | + if (perm & BLK_PERM_WRITE_UNCHANGED) { | ||
80 | + perm |= BLK_PERM_WRITE; | ||
81 | + } | ||
82 | + | ||
83 | + /* | ||
84 | + * If the data file is written to, the format driver may | ||
85 | + * expect to be able to resize it by writing beyond the EOF. | ||
86 | + */ | ||
87 | + if (perm & BLK_PERM_WRITE) { | ||
88 | + perm |= BLK_PERM_RESIZE; | ||
89 | + } | ||
90 | } | ||
91 | - shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
92 | |||
93 | if (bs->open_flags & BDRV_O_INACTIVE) { | ||
94 | shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE; | ||
95 | -- | ||
96 | 2.25.4 | ||
97 | |||
98 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | This callback can be used by BDSs that use child_of_bds with the | ||
4 | appropriate BdrvChildRole for their children. | ||
5 | |||
6 | Also, make bdrv_format_default_perms() use it for child_of_bds children | ||
7 | (just a temporary solution until we can drop bdrv_format_default_perms() | ||
8 | altogether). | ||
9 | |||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | Message-Id: <20200513110544.176672-20-mreitz@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | include/block/block_int.h | 11 +++++++++++ | ||
16 | block.c | 32 ++++++++++++++++++++++++++++++++ | ||
17 | 2 files changed, 43 insertions(+) | ||
18 | |||
19 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/include/block/block_int.h | ||
22 | +++ b/include/block/block_int.h | ||
23 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
24 | bool bdrv_recurse_can_replace(BlockDriverState *bs, | ||
25 | BlockDriverState *to_replace); | ||
26 | |||
27 | +/* | ||
28 | + * Default implementation for BlockDriver.bdrv_child_perm() that can | ||
29 | + * be used by block filters and image formats, as long as they use the | ||
30 | + * child_of_bds child class and set an appropriate BdrvChildRole. | ||
31 | + */ | ||
32 | +void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
33 | + const BdrvChildClass *child_class, BdrvChildRole role, | ||
34 | + BlockReopenQueue *reopen_queue, | ||
35 | + uint64_t perm, uint64_t shared, | ||
36 | + uint64_t *nperm, uint64_t *nshared); | ||
37 | + | ||
38 | /* | ||
39 | * Default implementation for drivers to pass bdrv_co_block_status() to | ||
40 | * their file. | ||
41 | diff --git a/block.c b/block.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/block.c | ||
44 | +++ b/block.c | ||
45 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
46 | uint64_t *nperm, uint64_t *nshared) | ||
47 | { | ||
48 | bool backing = (child_class == &child_backing); | ||
49 | + | ||
50 | + if (child_class == &child_of_bds) { | ||
51 | + bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
52 | + perm, shared, nperm, nshared); | ||
53 | + return; | ||
54 | + } | ||
55 | + | ||
56 | assert(child_class == &child_backing || child_class == &child_file); | ||
57 | |||
58 | if (!backing) { | ||
59 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
60 | } | ||
61 | } | ||
62 | |||
63 | +void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
64 | + const BdrvChildClass *child_class, BdrvChildRole role, | ||
65 | + BlockReopenQueue *reopen_queue, | ||
66 | + uint64_t perm, uint64_t shared, | ||
67 | + uint64_t *nperm, uint64_t *nshared) | ||
68 | +{ | ||
69 | + assert(child_class == &child_of_bds); | ||
70 | + | ||
71 | + if (role & BDRV_CHILD_FILTERED) { | ||
72 | + assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | | ||
73 | + BDRV_CHILD_COW))); | ||
74 | + bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
75 | + perm, shared, nperm, nshared); | ||
76 | + } else if (role & BDRV_CHILD_COW) { | ||
77 | + assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA))); | ||
78 | + bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, | ||
79 | + perm, shared, nperm, nshared); | ||
80 | + } else if (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)) { | ||
81 | + bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
82 | + perm, shared, nperm, nshared); | ||
83 | + } else { | ||
84 | + g_assert_not_reached(); | ||
85 | + } | ||
86 | +} | ||
87 | + | ||
88 | uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm) | ||
89 | { | ||
90 | static const uint64_t permissions[] = { | ||
91 | -- | ||
92 | 2.25.4 | ||
93 | |||
94 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Split raw_read_options() into one function that actually just reads the | ||
4 | options, and another that applies them. This will allow us to detect | ||
5 | whether the user has specified any options before attaching the file | ||
6 | child (so we can decide on its role based on the options). | ||
7 | |||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-21-mreitz@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block/raw-format.c | 110 ++++++++++++++++++++++++++------------------- | ||
14 | 1 file changed, 65 insertions(+), 45 deletions(-) | ||
15 | |||
16 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/raw-format.c | ||
19 | +++ b/block/raw-format.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_create_opts = { | ||
21 | } | ||
22 | }; | ||
23 | |||
24 | -static int raw_read_options(QDict *options, BlockDriverState *bs, | ||
25 | - BDRVRawState *s, Error **errp) | ||
26 | +static int raw_read_options(QDict *options, uint64_t *offset, bool *has_size, | ||
27 | + uint64_t *size, Error **errp) | ||
28 | { | ||
29 | Error *local_err = NULL; | ||
30 | QemuOpts *opts = NULL; | ||
31 | - int64_t real_size = 0; | ||
32 | int ret; | ||
33 | |||
34 | - real_size = bdrv_getlength(bs->file->bs); | ||
35 | - if (real_size < 0) { | ||
36 | - error_setg_errno(errp, -real_size, "Could not get image size"); | ||
37 | - return real_size; | ||
38 | - } | ||
39 | - | ||
40 | opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort); | ||
41 | qemu_opts_absorb_qdict(opts, options, &local_err); | ||
42 | if (local_err) { | ||
43 | @@ -XXX,XX +XXX,XX @@ static int raw_read_options(QDict *options, BlockDriverState *bs, | ||
44 | goto end; | ||
45 | } | ||
46 | |||
47 | - s->offset = qemu_opt_get_size(opts, "offset", 0); | ||
48 | - if (s->offset > real_size) { | ||
49 | - error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than " | ||
50 | - "size of the containing file (%" PRId64 ")", | ||
51 | - s->offset, real_size); | ||
52 | - ret = -EINVAL; | ||
53 | - goto end; | ||
54 | - } | ||
55 | + *offset = qemu_opt_get_size(opts, "offset", 0); | ||
56 | + *has_size = qemu_opt_find(opts, "size"); | ||
57 | + *size = qemu_opt_get_size(opts, "size", 0); | ||
58 | |||
59 | - if (qemu_opt_find(opts, "size") != NULL) { | ||
60 | - s->size = qemu_opt_get_size(opts, "size", 0); | ||
61 | - s->has_size = true; | ||
62 | - } else { | ||
63 | - s->has_size = false; | ||
64 | - s->size = real_size - s->offset; | ||
65 | + ret = 0; | ||
66 | +end: | ||
67 | + qemu_opts_del(opts); | ||
68 | + return ret; | ||
69 | +} | ||
70 | + | ||
71 | +static int raw_apply_options(BlockDriverState *bs, BDRVRawState *s, | ||
72 | + uint64_t offset, bool has_size, uint64_t size, | ||
73 | + Error **errp) | ||
74 | +{ | ||
75 | + int64_t real_size = 0; | ||
76 | + | ||
77 | + real_size = bdrv_getlength(bs->file->bs); | ||
78 | + if (real_size < 0) { | ||
79 | + error_setg_errno(errp, -real_size, "Could not get image size"); | ||
80 | + return real_size; | ||
81 | } | ||
82 | |||
83 | /* Check size and offset */ | ||
84 | - if ((real_size - s->offset) < s->size) { | ||
85 | + if (offset > real_size) { | ||
86 | + error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than " | ||
87 | + "size of the containing file (%" PRId64 ")", | ||
88 | + s->offset, real_size); | ||
89 | + return -EINVAL; | ||
90 | + } | ||
91 | + | ||
92 | + if (has_size && (real_size - offset) < size) { | ||
93 | error_setg(errp, "The sum of offset (%" PRIu64 ") and size " | ||
94 | - "(%" PRIu64 ") has to be smaller or equal to the " | ||
95 | - " actual size of the containing file (%" PRId64 ")", | ||
96 | - s->offset, s->size, real_size); | ||
97 | - ret = -EINVAL; | ||
98 | - goto end; | ||
99 | + "(%" PRIu64 ") has to be smaller or equal to the " | ||
100 | + " actual size of the containing file (%" PRId64 ")", | ||
101 | + s->offset, s->size, real_size); | ||
102 | + return -EINVAL; | ||
103 | } | ||
104 | |||
105 | /* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding | ||
106 | * up and leaking out of the specified area. */ | ||
107 | - if (s->has_size && !QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) { | ||
108 | + if (has_size && !QEMU_IS_ALIGNED(size, BDRV_SECTOR_SIZE)) { | ||
109 | error_setg(errp, "Specified size is not multiple of %llu", | ||
110 | - BDRV_SECTOR_SIZE); | ||
111 | - ret = -EINVAL; | ||
112 | - goto end; | ||
113 | + BDRV_SECTOR_SIZE); | ||
114 | + return -EINVAL; | ||
115 | } | ||
116 | |||
117 | - ret = 0; | ||
118 | - | ||
119 | -end: | ||
120 | + s->offset = offset; | ||
121 | + s->has_size = has_size; | ||
122 | + s->size = has_size ? size : real_size - offset; | ||
123 | |||
124 | - qemu_opts_del(opts); | ||
125 | - | ||
126 | - return ret; | ||
127 | + return 0; | ||
128 | } | ||
129 | |||
130 | static int raw_reopen_prepare(BDRVReopenState *reopen_state, | ||
131 | BlockReopenQueue *queue, Error **errp) | ||
132 | { | ||
133 | + bool has_size; | ||
134 | + uint64_t offset, size; | ||
135 | + int ret; | ||
136 | + | ||
137 | assert(reopen_state != NULL); | ||
138 | assert(reopen_state->bs != NULL); | ||
139 | |||
140 | reopen_state->opaque = g_new0(BDRVRawState, 1); | ||
141 | |||
142 | - return raw_read_options( | ||
143 | - reopen_state->options, | ||
144 | - reopen_state->bs, | ||
145 | - reopen_state->opaque, | ||
146 | - errp); | ||
147 | + ret = raw_read_options(reopen_state->options, &offset, &has_size, &size, | ||
148 | + errp); | ||
149 | + if (ret < 0) { | ||
150 | + return ret; | ||
151 | + } | ||
152 | + | ||
153 | + ret = raw_apply_options(reopen_state->bs, reopen_state->opaque, | ||
154 | + offset, has_size, size, errp); | ||
155 | + if (ret < 0) { | ||
156 | + return ret; | ||
157 | + } | ||
158 | + | ||
159 | + return 0; | ||
160 | } | ||
161 | |||
162 | static void raw_reopen_commit(BDRVReopenState *state) | ||
163 | @@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, | ||
164 | Error **errp) | ||
165 | { | ||
166 | BDRVRawState *s = bs->opaque; | ||
167 | + bool has_size; | ||
168 | + uint64_t offset, size; | ||
169 | int ret; | ||
170 | |||
171 | + ret = raw_read_options(options, &offset, &has_size, &size, errp); | ||
172 | + if (ret < 0) { | ||
173 | + return ret; | ||
174 | + } | ||
175 | + | ||
176 | bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
177 | false, errp); | ||
178 | if (!bs->file) { | ||
179 | @@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, | ||
180 | bs->file->bs->filename); | ||
181 | } | ||
182 | |||
183 | - ret = raw_read_options(options, bs, s, errp); | ||
184 | + ret = raw_apply_options(bs, s, offset, has_size, size, errp); | ||
185 | if (ret < 0) { | ||
186 | return ret; | ||
187 | } | ||
188 | -- | ||
189 | 2.25.4 | ||
190 | |||
191 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Both users (quorum and blkverify) use child_format for | ||
4 | not-really-filtered children, so the appropriate BdrvChildRole in both | ||
5 | cases is DATA. (Note that this will cause bdrv_inherited_options() to | ||
6 | force-allow format probing.) | ||
7 | |||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Message-Id: <20200513110544.176672-22-mreitz@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block/blkverify.c | 4 ++-- | ||
14 | block/quorum.c | 6 ++++-- | ||
15 | 2 files changed, 6 insertions(+), 4 deletions(-) | ||
16 | |||
17 | diff --git a/block/blkverify.c b/block/blkverify.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/blkverify.c | ||
20 | +++ b/block/blkverify.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, | ||
22 | |||
23 | /* Open the test file */ | ||
24 | s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, | ||
25 | - "test", bs, &child_format, 0, false, | ||
26 | - &local_err); | ||
27 | + "test", bs, &child_of_bds, BDRV_CHILD_DATA, | ||
28 | + false, &local_err); | ||
29 | if (local_err) { | ||
30 | ret = -EINVAL; | ||
31 | error_propagate(errp, local_err); | ||
32 | diff --git a/block/quorum.c b/block/quorum.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/block/quorum.c | ||
35 | +++ b/block/quorum.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, | ||
37 | assert(ret < 32); | ||
38 | |||
39 | s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, | ||
40 | - &child_format, 0, false, &local_err); | ||
41 | + &child_of_bds, BDRV_CHILD_DATA, false, | ||
42 | + &local_err); | ||
43 | if (local_err) { | ||
44 | ret = -EINVAL; | ||
45 | goto close_exit; | ||
46 | @@ -XXX,XX +XXX,XX @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, | ||
47 | /* We can safely add the child now */ | ||
48 | bdrv_ref(child_bs); | ||
49 | |||
50 | - child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, 0, errp); | ||
51 | + child = bdrv_attach_child(bs, child_bs, indexstr, &child_of_bds, | ||
52 | + BDRV_CHILD_DATA, errp); | ||
53 | if (child == NULL) { | ||
54 | s->next_child_index--; | ||
55 | goto out; | ||
56 | -- | ||
57 | 2.25.4 | ||
58 | |||
59 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Message-Id: <20200513110544.176672-23-mreitz@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | include/block/block_int.h | 1 - | ||
9 | block.c | 29 ----------------------------- | ||
10 | 2 files changed, 30 deletions(-) | ||
11 | |||
12 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/block/block_int.h | ||
15 | +++ b/include/block/block_int.h | ||
16 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
17 | |||
18 | extern const BdrvChildClass child_of_bds; | ||
19 | extern const BdrvChildClass child_file; | ||
20 | -extern const BdrvChildClass child_format; | ||
21 | extern const BdrvChildClass child_backing; | ||
22 | |||
23 | struct BdrvChild { | ||
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 @@ const BdrvChildClass child_file = { | ||
29 | .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
30 | }; | ||
31 | |||
32 | -/* | ||
33 | - * Returns the options and flags that bs->file should get if the use of formats | ||
34 | - * (and not only protocols) is permitted for it, based on the given options and | ||
35 | - * flags for the parent BDS | ||
36 | - */ | ||
37 | -static void bdrv_inherited_fmt_options(BdrvChildRole role, | ||
38 | - bool parent_is_format, | ||
39 | - int *child_flags, QDict *child_options, | ||
40 | - int parent_flags, QDict *parent_options) | ||
41 | -{ | ||
42 | - bdrv_inherited_options(BDRV_CHILD_DATA, false, | ||
43 | - child_flags, child_options, | ||
44 | - parent_flags, parent_options); | ||
45 | -} | ||
46 | - | ||
47 | -const BdrvChildClass child_format = { | ||
48 | - .parent_is_bds = true, | ||
49 | - .get_parent_desc = bdrv_child_get_parent_desc, | ||
50 | - .inherit_options = bdrv_inherited_fmt_options, | ||
51 | - .drained_begin = bdrv_child_cb_drained_begin, | ||
52 | - .drained_poll = bdrv_child_cb_drained_poll, | ||
53 | - .drained_end = bdrv_child_cb_drained_end, | ||
54 | - .attach = bdrv_child_cb_attach, | ||
55 | - .detach = bdrv_child_cb_detach, | ||
56 | - .inactivate = bdrv_child_cb_inactivate, | ||
57 | - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, | ||
58 | - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
59 | -}; | ||
60 | - | ||
61 | static void bdrv_backing_attach(BdrvChild *c) | ||
62 | { | ||
63 | BlockDriverState *parent = c->opaque; | ||
64 | -- | ||
65 | 2.25.4 | ||
66 | |||
67 | diff view generated by jsdifflib |
1 | From: Jeff Cody <jcody@redhat.com> | 1 | From: Max Reitz <mreitz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In external_snapshot_abort(), we try to undo what was done in | 3 | Make all parents of backing files pass the appropriate BdrvChildRole. |
4 | external_snapshot_prepare() calling bdrv_replace_node() to swap the | 4 | By doing so, we can switch their BdrvChildClass over to the generic |
5 | nodes back. However, we receive a permissions error as writers are | 5 | child_of_bds, which will do the right thing when given a correct |
6 | blocked on the old node, which is now the new node backing file. | 6 | BdrvChildRole. |
7 | 7 | ||
8 | An easy fix (initially suggested by Kevin Wolf) is to call | 8 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
9 | bdrv_set_backing_hd() on the new node, to set the backing node to NULL. | 9 | Message-Id: <20200513110544.176672-24-mreitz@redhat.com> |
10 | |||
11 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | 10 | Reviewed-by: Eric Blake <eblake@redhat.com> |
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
14 | --- | 12 | --- |
15 | blockdev.c | 4 ++++ | 13 | block.c | 26 ++++++++++++++++++++------ |
16 | 1 file changed, 4 insertions(+) | 14 | block/backup-top.c | 2 +- |
15 | block/vvfat.c | 3 ++- | ||
16 | tests/test-bdrv-drain.c | 13 +++++++------ | ||
17 | 4 files changed, 30 insertions(+), 14 deletions(-) | ||
17 | 18 | ||
18 | diff --git a/blockdev.c b/blockdev.c | 19 | diff --git a/block.c b/block.c |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/blockdev.c | 21 | --- a/block.c |
21 | +++ b/blockdev.c | 22 | +++ b/block.c |
22 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_abort(BlkActionState *common) | 23 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_inherits_from_recursive(BlockDriverState *child, |
23 | DO_UPCAST(ExternalSnapshotState, common, common); | 24 | return child != NULL; |
24 | if (state->new_bs) { | 25 | } |
25 | if (state->overlay_appended) { | 26 | |
26 | + bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd() | 27 | +/* |
27 | + close state->old_bs; we need it */ | 28 | + * Return the BdrvChildRole for @bs's backing child. bs->backing is |
28 | + bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); | 29 | + * mostly used for COW backing children (role = COW), but also for |
29 | bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); | 30 | + * filtered children (role = FILTERED | PRIMARY). |
30 | + bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_bs */ | 31 | + */ |
32 | +static BdrvChildRole bdrv_backing_role(BlockDriverState *bs) | ||
33 | +{ | ||
34 | + if (bs->drv && bs->drv->is_filter) { | ||
35 | + return BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; | ||
36 | + } else { | ||
37 | + return BDRV_CHILD_COW; | ||
38 | + } | ||
39 | +} | ||
40 | + | ||
41 | /* | ||
42 | * Sets the backing file link of a BDS. A new reference is created; callers | ||
43 | * which don't need their own reference any more must call bdrv_unref(). | ||
44 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, | ||
45 | goto out; | ||
46 | } | ||
47 | |||
48 | - bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing, | ||
49 | - 0, errp); | ||
50 | + bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_of_bds, | ||
51 | + bdrv_backing_role(bs), errp); | ||
52 | /* If backing_hd was already part of bs's backing chain, and | ||
53 | * inherits_from pointed recursively to bs then let's update it to | ||
54 | * point directly to bs (else it will become NULL). */ | ||
55 | @@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, | ||
56 | } | ||
57 | |||
58 | backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs, | ||
59 | - &child_backing, 0, errp); | ||
60 | + &child_of_bds, bdrv_backing_role(bs), errp); | ||
61 | if (!backing_hd) { | ||
62 | bs->open_flags |= BDRV_O_NO_BACKING; | ||
63 | error_prepend(errp, "Could not open backing file: "); | ||
64 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
65 | if (state->replace_backing_bs && state->new_backing_bs) { | ||
66 | uint64_t nperm, nshared; | ||
67 | bdrv_child_perm(state->bs, state->new_backing_bs, | ||
68 | - NULL, &child_backing, 0, bs_queue, | ||
69 | - state->perm, state->shared_perm, | ||
70 | + NULL, &child_of_bds, bdrv_backing_role(state->bs), | ||
71 | + bs_queue, state->perm, state->shared_perm, | ||
72 | &nperm, &nshared); | ||
73 | ret = bdrv_check_update_perm(state->new_backing_bs, NULL, | ||
74 | nperm, nshared, NULL, NULL, errp); | ||
75 | @@ -XXX,XX +XXX,XX @@ void bdrv_refresh_filename(BlockDriverState *bs) | ||
76 | drv->bdrv_gather_child_options(bs, opts, backing_overridden); | ||
77 | } else { | ||
78 | QLIST_FOREACH(child, &bs->children, next) { | ||
79 | - if (child->klass == &child_backing && !backing_overridden) { | ||
80 | + if (child == bs->backing && !backing_overridden) { | ||
81 | /* We can skip the backing BDS if it has not been overridden */ | ||
82 | continue; | ||
83 | } | ||
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 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
89 | return; | ||
90 | } | ||
91 | |||
92 | - if (child_class == &child_file) { | ||
93 | + if (!(role & BDRV_CHILD_FILTERED)) { | ||
94 | /* | ||
95 | * Target child | ||
96 | * | ||
97 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/block/vvfat.c | ||
100 | +++ b/block/vvfat.c | ||
101 | @@ -XXX,XX +XXX,XX @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
102 | { | ||
103 | BDRVVVFATState *s = bs->opaque; | ||
104 | |||
105 | - assert(c == s->qcow || child_class == &child_backing); | ||
106 | + assert(c == s->qcow || | ||
107 | + (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); | ||
108 | |||
109 | if (c == s->qcow) { | ||
110 | /* This is a private node, nobody should try to attach to it */ | ||
111 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/tests/test-bdrv-drain.c | ||
114 | +++ b/tests/test-bdrv-drain.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
116 | * bdrv_format_default_perms() accepts only these two, so disguise | ||
117 | * detach_by_driver_cb_parent as one of them. | ||
118 | */ | ||
119 | - if (child_class != &child_file && child_class != &child_backing) { | ||
120 | + if (child_class != &child_file && child_class != &child_of_bds) { | ||
121 | child_class = &child_file; | ||
122 | } | ||
123 | |||
124 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
125 | bdrv_ref(a); | ||
126 | child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, | ||
127 | &error_abort); | ||
128 | - child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, 0, | ||
129 | - &error_abort); | ||
130 | + child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds, | ||
131 | + BDRV_CHILD_COW, &error_abort); | ||
132 | |||
133 | bdrv_ref(a); | ||
134 | bdrv_attach_child(parent_a, a, "PA-A", | ||
135 | @@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void) | ||
136 | int i; | ||
137 | int ret; | ||
138 | |||
139 | - chain_child_class = child_backing; | ||
140 | + chain_child_class = child_of_bds; | ||
141 | chain_child_class.update_filename = drop_intermediate_poll_update_filename; | ||
142 | |||
143 | for (i = 0; i < 3; i++) { | ||
144 | @@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void) | ||
145 | /* Takes the reference to chain[i - 1] */ | ||
146 | chain[i]->backing = bdrv_attach_child(chain[i], chain[i - 1], | ||
147 | "chain", &chain_child_class, | ||
148 | - 0, &error_abort); | ||
149 | + BDRV_CHILD_COW, &error_abort); | ||
31 | } | 150 | } |
32 | } | 151 | } |
33 | } | 152 | |
153 | @@ -XXX,XX +XXX,XX @@ static void do_test_replace_child_mid_drain(int old_drain_count, | ||
154 | |||
155 | bdrv_ref(old_child_bs); | ||
156 | parent_bs->backing = bdrv_attach_child(parent_bs, old_child_bs, "child", | ||
157 | - &child_backing, 0, &error_abort); | ||
158 | + &child_of_bds, BDRV_CHILD_COW, | ||
159 | + &error_abort); | ||
160 | |||
161 | for (i = 0; i < old_drain_count; i++) { | ||
162 | bdrv_drained_begin(old_child_bs); | ||
34 | -- | 163 | -- |
35 | 1.8.3.1 | 164 | 2.25.4 |
36 | 165 | ||
37 | 166 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Message-Id: <20200513110544.176672-25-mreitz@redhat.com> | ||
5 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | include/block/block_int.h | 1 - | ||
9 | block.c | 60 ++------------------------------------- | ||
10 | 2 files changed, 3 insertions(+), 58 deletions(-) | ||
11 | |||
12 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/block/block_int.h | ||
15 | +++ b/include/block/block_int.h | ||
16 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
17 | |||
18 | extern const BdrvChildClass child_of_bds; | ||
19 | extern const BdrvChildClass child_file; | ||
20 | -extern const BdrvChildClass child_backing; | ||
21 | |||
22 | struct BdrvChild { | ||
23 | BlockDriverState *bs; | ||
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_backing_attach(BdrvChild *c) | ||
29 | parent->backing_blocker); | ||
30 | } | ||
31 | |||
32 | -/* XXX: Will be removed along with child_backing */ | ||
33 | -static void bdrv_child_cb_attach_backing(BdrvChild *c) | ||
34 | -{ | ||
35 | - if (!(c->role & BDRV_CHILD_COW)) { | ||
36 | - bdrv_backing_attach(c); | ||
37 | - } | ||
38 | - bdrv_child_cb_attach(c); | ||
39 | -} | ||
40 | - | ||
41 | static void bdrv_backing_detach(BdrvChild *c) | ||
42 | { | ||
43 | BlockDriverState *parent = c->opaque; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c) | ||
45 | parent->backing_blocker = NULL; | ||
46 | } | ||
47 | |||
48 | -/* XXX: Will be removed along with child_backing */ | ||
49 | -static void bdrv_child_cb_detach_backing(BdrvChild *c) | ||
50 | -{ | ||
51 | - if (!(c->role & BDRV_CHILD_COW)) { | ||
52 | - bdrv_backing_detach(c); | ||
53 | - } | ||
54 | - bdrv_child_cb_detach(c); | ||
55 | -} | ||
56 | - | ||
57 | -/* | ||
58 | - * Returns the options and flags that bs->backing should get, based on the | ||
59 | - * given options and flags for the parent BDS | ||
60 | - */ | ||
61 | -static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, | ||
62 | - int *child_flags, QDict *child_options, | ||
63 | - int parent_flags, QDict *parent_options) | ||
64 | -{ | ||
65 | - bdrv_inherited_options(BDRV_CHILD_COW, true, | ||
66 | - child_flags, child_options, | ||
67 | - parent_flags, parent_options); | ||
68 | -} | ||
69 | - | ||
70 | static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | ||
71 | const char *filename, Error **errp) | ||
72 | { | ||
73 | @@ -XXX,XX +XXX,XX @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | -const BdrvChildClass child_backing = { | ||
78 | - .parent_is_bds = true, | ||
79 | - .get_parent_desc = bdrv_child_get_parent_desc, | ||
80 | - .attach = bdrv_child_cb_attach_backing, | ||
81 | - .detach = bdrv_child_cb_detach_backing, | ||
82 | - .inherit_options = bdrv_backing_options, | ||
83 | - .drained_begin = bdrv_child_cb_drained_begin, | ||
84 | - .drained_poll = bdrv_child_cb_drained_poll, | ||
85 | - .drained_end = bdrv_child_cb_drained_end, | ||
86 | - .inactivate = bdrv_child_cb_inactivate, | ||
87 | - .update_filename = bdrv_backing_update_filename, | ||
88 | - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, | ||
89 | - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
90 | -}; | ||
91 | - | ||
92 | /* | ||
93 | * Returns the options and flags that a generic child of a BDS should | ||
94 | * get, based on the given options and flags for the parent BDS. | ||
95 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, | ||
96 | uint64_t perm, uint64_t shared, | ||
97 | uint64_t *nperm, uint64_t *nshared) | ||
98 | { | ||
99 | - assert(child_class == &child_backing || | ||
100 | - (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); | ||
101 | + assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW)); | ||
102 | |||
103 | /* | ||
104 | * We want consistent read from backing files if the parent needs it. | ||
105 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
106 | uint64_t perm, uint64_t shared, | ||
107 | uint64_t *nperm, uint64_t *nshared) | ||
108 | { | ||
109 | - bool backing = (child_class == &child_backing); | ||
110 | - | ||
111 | if (child_class == &child_of_bds) { | ||
112 | bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
113 | perm, shared, nperm, nshared); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | - assert(child_class == &child_backing || child_class == &child_file); | ||
118 | + assert(child_class == &child_file); | ||
119 | |||
120 | - if (!backing) { | ||
121 | - bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
122 | - perm, shared, nperm, nshared); | ||
123 | - } else { | ||
124 | - bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, | ||
125 | + bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
126 | perm, shared, nperm, nshared); | ||
127 | - } | ||
128 | } | ||
129 | |||
130 | void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
131 | -- | ||
132 | 2.25.4 | ||
133 | |||
134 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | Commonly, they need to pass the BDRV_CHILD_IMAGE set as the | ||
4 | BdrvChildRole; but there are exceptions for drivers with external data | ||
5 | files (qcow2 and vmdk). | ||
6 | |||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Message-Id: <20200513110544.176672-26-mreitz@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | block/bochs.c | 4 ++-- | ||
13 | block/cloop.c | 4 ++-- | ||
14 | block/crypto.c | 4 ++-- | ||
15 | block/dmg.c | 4 ++-- | ||
16 | block/parallels.c | 4 ++-- | ||
17 | block/qcow.c | 4 ++-- | ||
18 | block/qcow2.c | 19 +++++++++++++------ | ||
19 | block/qed.c | 4 ++-- | ||
20 | block/vdi.c | 4 ++-- | ||
21 | block/vhdx.c | 4 ++-- | ||
22 | block/vmdk.c | 20 +++++++++++++++++--- | ||
23 | block/vpc.c | 4 ++-- | ||
24 | 12 files changed, 50 insertions(+), 29 deletions(-) | ||
25 | |||
26 | diff --git a/block/bochs.c b/block/bochs.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/block/bochs.c | ||
29 | +++ b/block/bochs.c | ||
30 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
31 | return ret; | ||
32 | } | ||
33 | |||
34 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
35 | - false, errp); | ||
36 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
37 | + BDRV_CHILD_IMAGE, false, errp); | ||
38 | if (!bs->file) { | ||
39 | return -EINVAL; | ||
40 | } | ||
41 | diff --git a/block/cloop.c b/block/cloop.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/block/cloop.c | ||
44 | +++ b/block/cloop.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
46 | return ret; | ||
47 | } | ||
48 | |||
49 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
50 | - false, errp); | ||
51 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
52 | + BDRV_CHILD_IMAGE, false, errp); | ||
53 | if (!bs->file) { | ||
54 | return -EINVAL; | ||
55 | } | ||
56 | diff --git a/block/crypto.c b/block/crypto.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/block/crypto.c | ||
59 | +++ b/block/crypto.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_open_generic(QCryptoBlockFormat format, | ||
61 | unsigned int cflags = 0; | ||
62 | QDict *cryptoopts = NULL; | ||
63 | |||
64 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
65 | - false, errp); | ||
66 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
67 | + BDRV_CHILD_IMAGE, false, errp); | ||
68 | if (!bs->file) { | ||
69 | return -EINVAL; | ||
70 | } | ||
71 | diff --git a/block/dmg.c b/block/dmg.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/block/dmg.c | ||
74 | +++ b/block/dmg.c | ||
75 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | ||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
80 | - false, errp); | ||
81 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
82 | + BDRV_CHILD_IMAGE, false, errp); | ||
83 | if (!bs->file) { | ||
84 | return -EINVAL; | ||
85 | } | ||
86 | diff --git a/block/parallels.c b/block/parallels.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/block/parallels.c | ||
89 | +++ b/block/parallels.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
91 | Error *local_err = NULL; | ||
92 | char *buf; | ||
93 | |||
94 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
95 | - false, errp); | ||
96 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
97 | + BDRV_CHILD_IMAGE, false, errp); | ||
98 | if (!bs->file) { | ||
99 | return -EINVAL; | ||
100 | } | ||
101 | diff --git a/block/qcow.c b/block/qcow.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/block/qcow.c | ||
104 | +++ b/block/qcow.c | ||
105 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
106 | qdict_extract_subqdict(options, &encryptopts, "encrypt."); | ||
107 | encryptfmt = qdict_get_try_str(encryptopts, "format"); | ||
108 | |||
109 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
110 | - false, errp); | ||
111 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
112 | + BDRV_CHILD_IMAGE, false, errp); | ||
113 | if (!bs->file) { | ||
114 | ret = -EINVAL; | ||
115 | goto fail; | ||
116 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/block/qcow2.c | ||
119 | +++ b/block/qcow2.c | ||
120 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
121 | } | ||
122 | |||
123 | /* Open external data file */ | ||
124 | - s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file, | ||
125 | - 0, true, &local_err); | ||
126 | + s->data_file = bdrv_open_child(NULL, options, "data-file", bs, | ||
127 | + &child_of_bds, BDRV_CHILD_DATA, | ||
128 | + true, &local_err); | ||
129 | if (local_err) { | ||
130 | error_propagate(errp, local_err); | ||
131 | ret = -EINVAL; | ||
132 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
133 | if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { | ||
134 | if (!s->data_file && s->image_data_file) { | ||
135 | s->data_file = bdrv_open_child(s->image_data_file, options, | ||
136 | - "data-file", bs, &child_file, 0, | ||
137 | - false, errp); | ||
138 | + "data-file", bs, &child_of_bds, | ||
139 | + BDRV_CHILD_DATA, false, errp); | ||
140 | if (!s->data_file) { | ||
141 | ret = -EINVAL; | ||
142 | goto fail; | ||
143 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
144 | ret = -EINVAL; | ||
145 | goto fail; | ||
146 | } | ||
147 | + | ||
148 | + /* No data here */ | ||
149 | + bs->file->role &= ~BDRV_CHILD_DATA; | ||
150 | + | ||
151 | + /* Must succeed because we have given up permissions if anything */ | ||
152 | + bdrv_child_refresh_perms(bs, bs->file, &error_abort); | ||
153 | } else { | ||
154 | if (s->data_file) { | ||
155 | error_setg(errp, "'data-file' can only be set for images with an " | ||
156 | @@ -XXX,XX +XXX,XX @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, | ||
157 | .ret = -EINPROGRESS | ||
158 | }; | ||
159 | |||
160 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
161 | - false, errp); | ||
162 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
163 | + BDRV_CHILD_IMAGE, false, errp); | ||
164 | if (!bs->file) { | ||
165 | return -EINVAL; | ||
166 | } | ||
167 | diff --git a/block/qed.c b/block/qed.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/block/qed.c | ||
170 | +++ b/block/qed.c | ||
171 | @@ -XXX,XX +XXX,XX @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, | ||
172 | .ret = -EINPROGRESS | ||
173 | }; | ||
174 | |||
175 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
176 | - false, errp); | ||
177 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
178 | + BDRV_CHILD_IMAGE, false, errp); | ||
179 | if (!bs->file) { | ||
180 | return -EINVAL; | ||
181 | } | ||
182 | diff --git a/block/vdi.c b/block/vdi.c | ||
183 | index XXXXXXX..XXXXXXX 100644 | ||
184 | --- a/block/vdi.c | ||
185 | +++ b/block/vdi.c | ||
186 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
187 | Error *local_err = NULL; | ||
188 | QemuUUID uuid_link, uuid_parent; | ||
189 | |||
190 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
191 | - false, errp); | ||
192 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
193 | + BDRV_CHILD_IMAGE, false, errp); | ||
194 | if (!bs->file) { | ||
195 | return -EINVAL; | ||
196 | } | ||
197 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/block/vhdx.c | ||
200 | +++ b/block/vhdx.c | ||
201 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
202 | uint64_t signature; | ||
203 | Error *local_err = NULL; | ||
204 | |||
205 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
206 | - false, errp); | ||
207 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
208 | + BDRV_CHILD_IMAGE, false, errp); | ||
209 | if (!bs->file) { | ||
210 | return -EINVAL; | ||
211 | } | ||
212 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
213 | index XXXXXXX..XXXXXXX 100644 | ||
214 | --- a/block/vmdk.c | ||
215 | +++ b/block/vmdk.c | ||
216 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
217 | char *desc_file_dir = NULL; | ||
218 | char *extent_path; | ||
219 | BdrvChild *extent_file; | ||
220 | + BdrvChildRole extent_role; | ||
221 | BDRVVmdkState *s = bs->opaque; | ||
222 | VmdkExtent *extent; | ||
223 | char extent_opt_prefix[32]; | ||
224 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
225 | ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents); | ||
226 | assert(ret < 32); | ||
227 | |||
228 | + extent_role = BDRV_CHILD_DATA; | ||
229 | + if (strcmp(type, "FLAT") != 0 && strcmp(type, "VMFS") != 0) { | ||
230 | + /* non-flat extents have metadata */ | ||
231 | + extent_role |= BDRV_CHILD_METADATA; | ||
232 | + } | ||
233 | + | ||
234 | extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix, | ||
235 | - bs, &child_file, 0, false, &local_err); | ||
236 | + bs, &child_of_bds, extent_role, false, | ||
237 | + &local_err); | ||
238 | g_free(extent_path); | ||
239 | if (local_err) { | ||
240 | error_propagate(errp, local_err); | ||
241 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, | ||
242 | uint32_t magic; | ||
243 | Error *local_err = NULL; | ||
244 | |||
245 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
246 | - false, errp); | ||
247 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
248 | + BDRV_CHILD_IMAGE, false, errp); | ||
249 | if (!bs->file) { | ||
250 | return -EINVAL; | ||
251 | } | ||
252 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, | ||
253 | s->desc_offset = 0x200; | ||
254 | break; | ||
255 | default: | ||
256 | + /* No data in the descriptor file */ | ||
257 | + bs->file->role &= ~BDRV_CHILD_DATA; | ||
258 | + | ||
259 | + /* Must succeed because we have given up permissions if anything */ | ||
260 | + bdrv_child_refresh_perms(bs, bs->file, &error_abort); | ||
261 | + | ||
262 | ret = vmdk_open_desc_file(bs, flags, buf, options, errp); | ||
263 | break; | ||
264 | } | ||
265 | diff --git a/block/vpc.c b/block/vpc.c | ||
266 | index XXXXXXX..XXXXXXX 100644 | ||
267 | --- a/block/vpc.c | ||
268 | +++ b/block/vpc.c | ||
269 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
270 | int ret; | ||
271 | int64_t bs_size; | ||
272 | |||
273 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
274 | - false, errp); | ||
275 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
276 | + BDRV_CHILD_IMAGE, false, errp); | ||
277 | if (!bs->file) { | ||
278 | return -EINVAL; | ||
279 | } | ||
280 | -- | ||
281 | 2.25.4 | ||
282 | |||
283 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Note that some filters have secondary children, namely blkverify (the | ||
4 | image to be verified) and blklogwrites (the log). This patch does not | ||
5 | touch those children. | ||
6 | |||
7 | Note that for blkverify, the filtered child should not be format-probed. | ||
8 | While there is nothing enforcing this here, in practice, it will not be: | ||
9 | blkverify implements .bdrv_file_open. The block layer ensures (and in | ||
10 | fact, asserts) that BDRV_O_PROTOCOL is set for every BDS whose driver | ||
11 | implements .bdrv_file_open. This flag will then be bequeathed to | ||
12 | blkverify's children, and they will thus (by default) not be probed | ||
13 | either. | ||
14 | |||
15 | ("By default" refers to the fact that blkverify's other child (the | ||
16 | non-filtered one) will have BDRV_O_PROTOCOL force-unset, because that is | ||
17 | what happens for all non-filtered children of non-format drivers.) | ||
18 | |||
19 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
20 | Message-Id: <20200513110544.176672-27-mreitz@redhat.com> | ||
21 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
22 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
23 | --- | ||
24 | block/blkdebug.c | 4 +++- | ||
25 | block/blklogwrites.c | 3 ++- | ||
26 | block/blkreplay.c | 5 +++-- | ||
27 | block/blkverify.c | 4 +++- | ||
28 | block/copy-on-read.c | 5 +++-- | ||
29 | block/filter-compress.c | 5 +++-- | ||
30 | block/replication.c | 3 ++- | ||
31 | block/throttle.c | 5 +++-- | ||
32 | 8 files changed, 22 insertions(+), 12 deletions(-) | ||
33 | |||
34 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block/blkdebug.c | ||
37 | +++ b/block/blkdebug.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, | ||
39 | |||
40 | /* Open the image file */ | ||
41 | bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image", | ||
42 | - bs, &child_file, 0, false, &local_err); | ||
43 | + bs, &child_of_bds, | ||
44 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
45 | + false, &local_err); | ||
46 | if (local_err) { | ||
47 | ret = -EINVAL; | ||
48 | error_propagate(errp, local_err); | ||
49 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/block/blklogwrites.c | ||
52 | +++ b/block/blklogwrites.c | ||
53 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
54 | } | ||
55 | |||
56 | /* Open the file */ | ||
57 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
58 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
59 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, false, | ||
60 | &local_err); | ||
61 | if (local_err) { | ||
62 | ret = -EINVAL; | ||
63 | diff --git a/block/blkreplay.c b/block/blkreplay.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/block/blkreplay.c | ||
66 | +++ b/block/blkreplay.c | ||
67 | @@ -XXX,XX +XXX,XX @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, | ||
68 | int ret; | ||
69 | |||
70 | /* Open the image file */ | ||
71 | - bs->file = bdrv_open_child(NULL, options, "image", | ||
72 | - bs, &child_file, 0, false, &local_err); | ||
73 | + bs->file = bdrv_open_child(NULL, options, "image", bs, &child_of_bds, | ||
74 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
75 | + false, &local_err); | ||
76 | if (local_err) { | ||
77 | ret = -EINVAL; | ||
78 | error_propagate(errp, local_err); | ||
79 | diff --git a/block/blkverify.c b/block/blkverify.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/block/blkverify.c | ||
82 | +++ b/block/blkverify.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, | ||
84 | |||
85 | /* Open the raw file */ | ||
86 | bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw", | ||
87 | - bs, &child_file, 0, false, &local_err); | ||
88 | + bs, &child_of_bds, | ||
89 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
90 | + false, &local_err); | ||
91 | if (local_err) { | ||
92 | ret = -EINVAL; | ||
93 | error_propagate(errp, local_err); | ||
94 | diff --git a/block/copy-on-read.c b/block/copy-on-read.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/block/copy-on-read.c | ||
97 | +++ b/block/copy-on-read.c | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | static int cor_open(BlockDriverState *bs, QDict *options, int flags, | ||
100 | Error **errp) | ||
101 | { | ||
102 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
103 | - errp); | ||
104 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
105 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
106 | + false, errp); | ||
107 | if (!bs->file) { | ||
108 | return -EINVAL; | ||
109 | } | ||
110 | diff --git a/block/filter-compress.c b/block/filter-compress.c | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/block/filter-compress.c | ||
113 | +++ b/block/filter-compress.c | ||
114 | @@ -XXX,XX +XXX,XX @@ | ||
115 | static int compress_open(BlockDriverState *bs, QDict *options, int flags, | ||
116 | Error **errp) | ||
117 | { | ||
118 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, false, | ||
119 | - errp); | ||
120 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
121 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
122 | + false, errp); | ||
123 | if (!bs->file) { | ||
124 | return -EINVAL; | ||
125 | } | ||
126 | diff --git a/block/replication.c b/block/replication.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/block/replication.c | ||
129 | +++ b/block/replication.c | ||
130 | @@ -XXX,XX +XXX,XX @@ static int replication_open(BlockDriverState *bs, QDict *options, | ||
131 | const char *mode; | ||
132 | const char *top_id; | ||
133 | |||
134 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
135 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
136 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
137 | false, errp); | ||
138 | if (!bs->file) { | ||
139 | return -EINVAL; | ||
140 | diff --git a/block/throttle.c b/block/throttle.c | ||
141 | index XXXXXXX..XXXXXXX 100644 | ||
142 | --- a/block/throttle.c | ||
143 | +++ b/block/throttle.c | ||
144 | @@ -XXX,XX +XXX,XX @@ static int throttle_open(BlockDriverState *bs, QDict *options, | ||
145 | char *group; | ||
146 | int ret; | ||
147 | |||
148 | - bs->file = bdrv_open_child(NULL, options, "file", bs, | ||
149 | - &child_file, 0, false, errp); | ||
150 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
151 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
152 | + false, errp); | ||
153 | if (!bs->file) { | ||
154 | return -EINVAL; | ||
155 | } | ||
156 | -- | ||
157 | 2.25.4 | ||
158 | |||
159 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Replace child_file by child_of_bds in all remaining places (excluding | ||
4 | tests). | ||
5 | |||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Message-Id: <20200513110544.176672-28-mreitz@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | block.c | 3 ++- | ||
12 | block/backup-top.c | 4 ++-- | ||
13 | block/blklogwrites.c | 4 ++-- | ||
14 | block/raw-format.c | 15 +++++++++++++-- | ||
15 | 4 files changed, 19 insertions(+), 7 deletions(-) | ||
16 | |||
17 | diff --git a/block.c b/block.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block.c | ||
20 | +++ b/block.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename, | ||
22 | BlockDriverState *file_bs; | ||
23 | |||
24 | file_bs = bdrv_open_child_bs(filename, options, "file", bs, | ||
25 | - &child_file, 0, true, &local_err); | ||
26 | + &child_of_bds, BDRV_CHILD_IMAGE, | ||
27 | + true, &local_err); | ||
28 | if (local_err) { | ||
29 | goto fail; | ||
30 | } | ||
31 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block/backup-top.c | ||
34 | +++ b/block/backup-top.c | ||
35 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, | ||
36 | source->supported_zero_flags); | ||
37 | |||
38 | bdrv_ref(target); | ||
39 | - state->target = bdrv_attach_child(top, target, "target", &child_file, 0, | ||
40 | - errp); | ||
41 | + state->target = bdrv_attach_child(top, target, "target", &child_of_bds, | ||
42 | + BDRV_CHILD_DATA, errp); | ||
43 | if (!state->target) { | ||
44 | bdrv_unref(target); | ||
45 | bdrv_unref(top); | ||
46 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/block/blklogwrites.c | ||
49 | +++ b/block/blklogwrites.c | ||
50 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
51 | } | ||
52 | |||
53 | /* Open the log file */ | ||
54 | - s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, 0, | ||
55 | - false, &local_err); | ||
56 | + s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_of_bds, | ||
57 | + BDRV_CHILD_METADATA, false, &local_err); | ||
58 | if (local_err) { | ||
59 | ret = -EINVAL; | ||
60 | error_propagate(errp, local_err); | ||
61 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/block/raw-format.c | ||
64 | +++ b/block/raw-format.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, | ||
66 | BDRVRawState *s = bs->opaque; | ||
67 | bool has_size; | ||
68 | uint64_t offset, size; | ||
69 | + BdrvChildRole file_role; | ||
70 | int ret; | ||
71 | |||
72 | ret = raw_read_options(options, &offset, &has_size, &size, errp); | ||
73 | @@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0, | ||
78 | - false, errp); | ||
79 | + /* | ||
80 | + * Without offset and a size limit, this driver behaves very much | ||
81 | + * like a filter. With any such limit, it does not. | ||
82 | + */ | ||
83 | + if (offset || has_size) { | ||
84 | + file_role = BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY; | ||
85 | + } else { | ||
86 | + file_role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; | ||
87 | + } | ||
88 | + | ||
89 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
90 | + file_role, false, errp); | ||
91 | if (!bs->file) { | ||
92 | return -EINVAL; | ||
93 | } | ||
94 | -- | ||
95 | 2.25.4 | ||
96 | |||
97 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Message-Id: <20200513110544.176672-29-mreitz@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | tests/test-bdrv-drain.c | 29 +++++++++++++++++------------ | ||
9 | tests/test-bdrv-graph-mod.c | 6 ++++-- | ||
10 | 2 files changed, 21 insertions(+), 14 deletions(-) | ||
11 | |||
12 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tests/test-bdrv-drain.c | ||
15 | +++ b/tests/test-bdrv-drain.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
17 | * detach_by_driver_cb_parent as one of them. | ||
18 | */ | ||
19 | if (child_class != &child_file && child_class != &child_of_bds) { | ||
20 | - child_class = &child_file; | ||
21 | + child_class = &child_of_bds; | ||
22 | } | ||
23 | |||
24 | bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, | ||
25 | @@ -XXX,XX +XXX,XX @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, | ||
26 | |||
27 | null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, | ||
28 | &error_abort); | ||
29 | - bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); | ||
30 | + bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, | ||
31 | + BDRV_CHILD_DATA, &error_abort); | ||
32 | |||
33 | /* This child will be the one to pass to requests through to, and | ||
34 | * it will stall until a drain occurs */ | ||
35 | @@ -XXX,XX +XXX,XX @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, | ||
36 | &error_abort); | ||
37 | child_bs->total_sectors = 65536 >> BDRV_SECTOR_BITS; | ||
38 | /* Takes our reference to child_bs */ | ||
39 | - tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", &child_file, | ||
40 | - 0, &error_abort); | ||
41 | + tts->wait_child = bdrv_attach_child(bs, child_bs, "wait-child", | ||
42 | + &child_of_bds, | ||
43 | + BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, | ||
44 | + &error_abort); | ||
45 | |||
46 | /* This child is just there to be deleted | ||
47 | * (for detach_instead_of_delete == true) */ | ||
48 | null_bs = bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, | ||
49 | &error_abort); | ||
50 | - bdrv_attach_child(bs, null_bs, "null-child", &child_file, 0, &error_abort); | ||
51 | + bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, BDRV_CHILD_DATA, | ||
52 | + &error_abort); | ||
53 | |||
54 | blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); | ||
55 | blk_insert_bs(blk, bs, &error_abort); | ||
56 | @@ -XXX,XX +XXX,XX @@ static void detach_indirect_bh(void *opaque) | ||
57 | |||
58 | bdrv_ref(data->c); | ||
59 | data->child_c = bdrv_attach_child(data->parent_b, data->c, "PB-C", | ||
60 | - &child_file, 0, &error_abort); | ||
61 | + &child_of_bds, BDRV_CHILD_DATA, | ||
62 | + &error_abort); | ||
63 | } | ||
64 | |||
65 | static void detach_by_parent_aio_cb(void *opaque, int ret) | ||
66 | @@ -XXX,XX +XXX,XX @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) | ||
67 | { | ||
68 | aio_bh_schedule_oneshot(qemu_get_current_aio_context(), | ||
69 | detach_indirect_bh, &detach_by_parent_data); | ||
70 | - child_file.drained_begin(child); | ||
71 | + child_of_bds.drained_begin(child); | ||
72 | } | ||
73 | |||
74 | static BdrvChildClass detach_by_driver_cb_class; | ||
75 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
76 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); | ||
77 | |||
78 | if (!by_parent_cb) { | ||
79 | - detach_by_driver_cb_class = child_file; | ||
80 | + detach_by_driver_cb_class = child_of_bds; | ||
81 | detach_by_driver_cb_class.drained_begin = | ||
82 | detach_by_driver_cb_drained_begin; | ||
83 | } | ||
84 | @@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb) | ||
85 | /* Set child relationships */ | ||
86 | bdrv_ref(b); | ||
87 | bdrv_ref(a); | ||
88 | - child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0, | ||
89 | - &error_abort); | ||
90 | + child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_of_bds, | ||
91 | + BDRV_CHILD_DATA, &error_abort); | ||
92 | child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds, | ||
93 | BDRV_CHILD_COW, &error_abort); | ||
94 | |||
95 | bdrv_ref(a); | ||
96 | bdrv_attach_child(parent_a, a, "PA-A", | ||
97 | - by_parent_cb ? &child_file : &detach_by_driver_cb_class, | ||
98 | - 0, &error_abort); | ||
99 | + by_parent_cb ? &child_of_bds : &detach_by_driver_cb_class, | ||
100 | + BDRV_CHILD_DATA, &error_abort); | ||
101 | |||
102 | g_assert_cmpint(parent_a->refcnt, ==, 1); | ||
103 | g_assert_cmpint(parent_b->refcnt, ==, 1); | ||
104 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/tests/test-bdrv-graph-mod.c | ||
107 | +++ b/tests/test-bdrv-graph-mod.c | ||
108 | @@ -XXX,XX +XXX,XX @@ static void test_update_perm_tree(void) | ||
109 | |||
110 | blk_insert_bs(root, bs, &error_abort); | ||
111 | |||
112 | - bdrv_attach_child(filter, bs, "child", &child_file, 0, &error_abort); | ||
113 | + bdrv_attach_child(filter, bs, "child", &child_of_bds, | ||
114 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); | ||
115 | |||
116 | bdrv_append(filter, bs, &local_err); | ||
117 | |||
118 | @@ -XXX,XX +XXX,XX @@ static void test_should_update_child(void) | ||
119 | bdrv_set_backing_hd(target, bs, &error_abort); | ||
120 | |||
121 | g_assert(target->backing->bs == bs); | ||
122 | - bdrv_attach_child(filter, target, "target", &child_file, 0, &error_abort); | ||
123 | + bdrv_attach_child(filter, target, "target", &child_of_bds, | ||
124 | + BDRV_CHILD_DATA, &error_abort); | ||
125 | bdrv_append(filter, bs, &error_abort); | ||
126 | g_assert(target->backing->bs == bs); | ||
127 | |||
128 | -- | ||
129 | 2.25.4 | ||
130 | |||
131 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | bdrv_default_perms() can decide which permission profile to use based on | ||
4 | the BdrvChildRole, so block drivers do not need to select it explicitly. | ||
5 | |||
6 | The blkverify driver now no longer shares the WRITE permission for the | ||
7 | image to verify. We thus have to adjust two places in | ||
8 | test-block-iothread not to take it. (Note that in theory, blkverify | ||
9 | should behave like quorum in this regard and share neither WRITE nor | ||
10 | RESIZE for both of its children. In practice, it does not really | ||
11 | matter, because blkverify is used only for debugging, so we might as | ||
12 | well keep its permissions rather liberal.) | ||
13 | |||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
16 | Message-Id: <20200513110544.176672-30-mreitz@redhat.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | --- | ||
19 | block/backup-top.c | 4 ++-- | ||
20 | block/blkdebug.c | 4 ++-- | ||
21 | block/blklogwrites.c | 9 ++------- | ||
22 | block/blkreplay.c | 2 +- | ||
23 | block/blkverify.c | 2 +- | ||
24 | block/bochs.c | 2 +- | ||
25 | block/cloop.c | 2 +- | ||
26 | block/crypto.c | 2 +- | ||
27 | block/dmg.c | 2 +- | ||
28 | block/filter-compress.c | 2 +- | ||
29 | block/parallels.c | 2 +- | ||
30 | block/qcow.c | 2 +- | ||
31 | block/qcow2.c | 2 +- | ||
32 | block/qed.c | 2 +- | ||
33 | block/raw-format.c | 2 +- | ||
34 | block/throttle.c | 2 +- | ||
35 | block/vdi.c | 2 +- | ||
36 | block/vhdx.c | 2 +- | ||
37 | block/vmdk.c | 2 +- | ||
38 | block/vpc.c | 2 +- | ||
39 | tests/test-bdrv-drain.c | 10 +++++----- | ||
40 | tests/test-bdrv-graph-mod.c | 2 +- | ||
41 | tests/test-block-iothread.c | 17 ++++++++++++++--- | ||
42 | 23 files changed, 43 insertions(+), 37 deletions(-) | ||
43 | |||
44 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/block/backup-top.c | ||
47 | +++ b/block/backup-top.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
49 | *nperm = BLK_PERM_WRITE; | ||
50 | } else { | ||
51 | /* Source child */ | ||
52 | - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
53 | - perm, shared, nperm, nshared); | ||
54 | + bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
55 | + perm, shared, nperm, nshared); | ||
56 | |||
57 | if (perm & BLK_PERM_WRITE) { | ||
58 | *nperm = *nperm | BLK_PERM_CONSISTENT_READ; | ||
59 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/block/blkdebug.c | ||
62 | +++ b/block/blkdebug.c | ||
63 | @@ -XXX,XX +XXX,XX @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
64 | { | ||
65 | BDRVBlkdebugState *s = bs->opaque; | ||
66 | |||
67 | - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
68 | - perm, shared, nperm, nshared); | ||
69 | + bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
70 | + perm, shared, nperm, nshared); | ||
71 | |||
72 | *nperm |= s->take_child_perms; | ||
73 | *nshared &= ~s->unshare_child_perms; | ||
74 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/block/blklogwrites.c | ||
77 | +++ b/block/blklogwrites.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
79 | return; | ||
80 | } | ||
81 | |||
82 | - if (!strcmp(c->name, "log")) { | ||
83 | - bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
84 | - nperm, nshrd); | ||
85 | - } else { | ||
86 | - bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
87 | - nperm, nshrd); | ||
88 | - } | ||
89 | + bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
90 | + nperm, nshrd); | ||
91 | } | ||
92 | |||
93 | static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) | ||
94 | diff --git a/block/blkreplay.c b/block/blkreplay.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/block/blkreplay.c | ||
97 | +++ b/block/blkreplay.c | ||
98 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkreplay = { | ||
99 | .is_filter = true, | ||
100 | |||
101 | .bdrv_open = blkreplay_open, | ||
102 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
103 | + .bdrv_child_perm = bdrv_default_perms, | ||
104 | .bdrv_getlength = blkreplay_getlength, | ||
105 | |||
106 | .bdrv_co_preadv = blkreplay_co_preadv, | ||
107 | diff --git a/block/blkverify.c b/block/blkverify.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/block/blkverify.c | ||
110 | +++ b/block/blkverify.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkverify = { | ||
112 | .bdrv_parse_filename = blkverify_parse_filename, | ||
113 | .bdrv_file_open = blkverify_open, | ||
114 | .bdrv_close = blkverify_close, | ||
115 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
116 | + .bdrv_child_perm = bdrv_default_perms, | ||
117 | .bdrv_getlength = blkverify_getlength, | ||
118 | .bdrv_refresh_filename = blkverify_refresh_filename, | ||
119 | .bdrv_dirname = blkverify_dirname, | ||
120 | diff --git a/block/bochs.c b/block/bochs.c | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/block/bochs.c | ||
123 | +++ b/block/bochs.c | ||
124 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_bochs = { | ||
125 | .instance_size = sizeof(BDRVBochsState), | ||
126 | .bdrv_probe = bochs_probe, | ||
127 | .bdrv_open = bochs_open, | ||
128 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
129 | + .bdrv_child_perm = bdrv_default_perms, | ||
130 | .bdrv_refresh_limits = bochs_refresh_limits, | ||
131 | .bdrv_co_preadv = bochs_co_preadv, | ||
132 | .bdrv_close = bochs_close, | ||
133 | diff --git a/block/cloop.c b/block/cloop.c | ||
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/block/cloop.c | ||
136 | +++ b/block/cloop.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_cloop = { | ||
138 | .instance_size = sizeof(BDRVCloopState), | ||
139 | .bdrv_probe = cloop_probe, | ||
140 | .bdrv_open = cloop_open, | ||
141 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
142 | + .bdrv_child_perm = bdrv_default_perms, | ||
143 | .bdrv_refresh_limits = cloop_refresh_limits, | ||
144 | .bdrv_co_preadv = cloop_co_preadv, | ||
145 | .bdrv_close = cloop_close, | ||
146 | diff --git a/block/crypto.c b/block/crypto.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/block/crypto.c | ||
149 | +++ b/block/crypto.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_crypto_luks = { | ||
151 | .bdrv_close = block_crypto_close, | ||
152 | /* This driver doesn't modify LUKS metadata except when creating image. | ||
153 | * Allow share-rw=on as a special case. */ | ||
154 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
155 | + .bdrv_child_perm = bdrv_default_perms, | ||
156 | .bdrv_co_create = block_crypto_co_create_luks, | ||
157 | .bdrv_co_create_opts = block_crypto_co_create_opts_luks, | ||
158 | .bdrv_co_truncate = block_crypto_co_truncate, | ||
159 | diff --git a/block/dmg.c b/block/dmg.c | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/block/dmg.c | ||
162 | +++ b/block/dmg.c | ||
163 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_dmg = { | ||
164 | .bdrv_probe = dmg_probe, | ||
165 | .bdrv_open = dmg_open, | ||
166 | .bdrv_refresh_limits = dmg_refresh_limits, | ||
167 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
168 | + .bdrv_child_perm = bdrv_default_perms, | ||
169 | .bdrv_co_preadv = dmg_co_preadv, | ||
170 | .bdrv_close = dmg_close, | ||
171 | .is_format = true, | ||
172 | diff --git a/block/filter-compress.c b/block/filter-compress.c | ||
173 | index XXXXXXX..XXXXXXX 100644 | ||
174 | --- a/block/filter-compress.c | ||
175 | +++ b/block/filter-compress.c | ||
176 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_compress = { | ||
177 | .format_name = "compress", | ||
178 | |||
179 | .bdrv_open = compress_open, | ||
180 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
181 | + .bdrv_child_perm = bdrv_default_perms, | ||
182 | |||
183 | .bdrv_getlength = compress_getlength, | ||
184 | |||
185 | diff --git a/block/parallels.c b/block/parallels.c | ||
186 | index XXXXXXX..XXXXXXX 100644 | ||
187 | --- a/block/parallels.c | ||
188 | +++ b/block/parallels.c | ||
189 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_parallels = { | ||
190 | .bdrv_probe = parallels_probe, | ||
191 | .bdrv_open = parallels_open, | ||
192 | .bdrv_close = parallels_close, | ||
193 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
194 | + .bdrv_child_perm = bdrv_default_perms, | ||
195 | .bdrv_co_block_status = parallels_co_block_status, | ||
196 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
197 | .bdrv_co_flush_to_os = parallels_co_flush_to_os, | ||
198 | diff --git a/block/qcow.c b/block/qcow.c | ||
199 | index XXXXXXX..XXXXXXX 100644 | ||
200 | --- a/block/qcow.c | ||
201 | +++ b/block/qcow.c | ||
202 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qcow = { | ||
203 | .bdrv_probe = qcow_probe, | ||
204 | .bdrv_open = qcow_open, | ||
205 | .bdrv_close = qcow_close, | ||
206 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
207 | + .bdrv_child_perm = bdrv_default_perms, | ||
208 | .bdrv_reopen_prepare = qcow_reopen_prepare, | ||
209 | .bdrv_co_create = qcow_co_create, | ||
210 | .bdrv_co_create_opts = qcow_co_create_opts, | ||
211 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/block/qcow2.c | ||
214 | +++ b/block/qcow2.c | ||
215 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_qcow2 = { | ||
216 | .bdrv_reopen_commit_post = qcow2_reopen_commit_post, | ||
217 | .bdrv_reopen_abort = qcow2_reopen_abort, | ||
218 | .bdrv_join_options = qcow2_join_options, | ||
219 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
220 | + .bdrv_child_perm = bdrv_default_perms, | ||
221 | .bdrv_co_create_opts = qcow2_co_create_opts, | ||
222 | .bdrv_co_create = qcow2_co_create, | ||
223 | .bdrv_has_zero_init = qcow2_has_zero_init, | ||
224 | diff --git a/block/qed.c b/block/qed.c | ||
225 | index XXXXXXX..XXXXXXX 100644 | ||
226 | --- a/block/qed.c | ||
227 | +++ b/block/qed.c | ||
228 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qed = { | ||
229 | .bdrv_open = bdrv_qed_open, | ||
230 | .bdrv_close = bdrv_qed_close, | ||
231 | .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, | ||
232 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
233 | + .bdrv_child_perm = bdrv_default_perms, | ||
234 | .bdrv_co_create = bdrv_qed_co_create, | ||
235 | .bdrv_co_create_opts = bdrv_qed_co_create_opts, | ||
236 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
237 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/block/raw-format.c | ||
240 | +++ b/block/raw-format.c | ||
241 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_raw = { | ||
242 | .bdrv_reopen_commit = &raw_reopen_commit, | ||
243 | .bdrv_reopen_abort = &raw_reopen_abort, | ||
244 | .bdrv_open = &raw_open, | ||
245 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
246 | + .bdrv_child_perm = bdrv_default_perms, | ||
247 | .bdrv_co_create_opts = &raw_co_create_opts, | ||
248 | .bdrv_co_preadv = &raw_co_preadv, | ||
249 | .bdrv_co_pwritev = &raw_co_pwritev, | ||
250 | diff --git a/block/throttle.c b/block/throttle.c | ||
251 | index XXXXXXX..XXXXXXX 100644 | ||
252 | --- a/block/throttle.c | ||
253 | +++ b/block/throttle.c | ||
254 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_throttle = { | ||
255 | .bdrv_close = throttle_close, | ||
256 | .bdrv_co_flush = throttle_co_flush, | ||
257 | |||
258 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
259 | + .bdrv_child_perm = bdrv_default_perms, | ||
260 | |||
261 | .bdrv_getlength = throttle_getlength, | ||
262 | |||
263 | diff --git a/block/vdi.c b/block/vdi.c | ||
264 | index XXXXXXX..XXXXXXX 100644 | ||
265 | --- a/block/vdi.c | ||
266 | +++ b/block/vdi.c | ||
267 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vdi = { | ||
268 | .bdrv_open = vdi_open, | ||
269 | .bdrv_close = vdi_close, | ||
270 | .bdrv_reopen_prepare = vdi_reopen_prepare, | ||
271 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
272 | + .bdrv_child_perm = bdrv_default_perms, | ||
273 | .bdrv_co_create = vdi_co_create, | ||
274 | .bdrv_co_create_opts = vdi_co_create_opts, | ||
275 | .bdrv_has_zero_init = vdi_has_zero_init, | ||
276 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
277 | index XXXXXXX..XXXXXXX 100644 | ||
278 | --- a/block/vhdx.c | ||
279 | +++ b/block/vhdx.c | ||
280 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vhdx = { | ||
281 | .bdrv_open = vhdx_open, | ||
282 | .bdrv_close = vhdx_close, | ||
283 | .bdrv_reopen_prepare = vhdx_reopen_prepare, | ||
284 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
285 | + .bdrv_child_perm = bdrv_default_perms, | ||
286 | .bdrv_co_readv = vhdx_co_readv, | ||
287 | .bdrv_co_writev = vhdx_co_writev, | ||
288 | .bdrv_co_create = vhdx_co_create, | ||
289 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
290 | index XXXXXXX..XXXXXXX 100644 | ||
291 | --- a/block/vmdk.c | ||
292 | +++ b/block/vmdk.c | ||
293 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vmdk = { | ||
294 | .bdrv_open = vmdk_open, | ||
295 | .bdrv_co_check = vmdk_co_check, | ||
296 | .bdrv_reopen_prepare = vmdk_reopen_prepare, | ||
297 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
298 | + .bdrv_child_perm = bdrv_default_perms, | ||
299 | .bdrv_co_preadv = vmdk_co_preadv, | ||
300 | .bdrv_co_pwritev = vmdk_co_pwritev, | ||
301 | .bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed, | ||
302 | diff --git a/block/vpc.c b/block/vpc.c | ||
303 | index XXXXXXX..XXXXXXX 100644 | ||
304 | --- a/block/vpc.c | ||
305 | +++ b/block/vpc.c | ||
306 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vpc = { | ||
307 | .bdrv_open = vpc_open, | ||
308 | .bdrv_close = vpc_close, | ||
309 | .bdrv_reopen_prepare = vpc_reopen_prepare, | ||
310 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
311 | + .bdrv_child_perm = bdrv_default_perms, | ||
312 | .bdrv_co_create = vpc_co_create, | ||
313 | .bdrv_co_create_opts = vpc_co_create_opts, | ||
314 | |||
315 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
316 | index XXXXXXX..XXXXXXX 100644 | ||
317 | --- a/tests/test-bdrv-drain.c | ||
318 | +++ b/tests/test-bdrv-drain.c | ||
319 | @@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
320 | uint64_t *nperm, uint64_t *nshared) | ||
321 | { | ||
322 | /* | ||
323 | - * bdrv_format_default_perms() accepts only these two, so disguise | ||
324 | + * bdrv_default_perms() accepts only these two, so disguise | ||
325 | * detach_by_driver_cb_parent as one of them. | ||
326 | */ | ||
327 | if (child_class != &child_file && child_class != &child_of_bds) { | ||
328 | child_class = &child_of_bds; | ||
329 | } | ||
330 | |||
331 | - bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, | ||
332 | - perm, shared, nperm, nshared); | ||
333 | + bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
334 | + perm, shared, nperm, nshared); | ||
335 | } | ||
336 | |||
337 | static int bdrv_test_change_backing_file(BlockDriverState *bs, | ||
338 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test_top_driver = { | ||
339 | .bdrv_close = bdrv_test_top_close, | ||
340 | .bdrv_co_preadv = bdrv_test_top_co_preadv, | ||
341 | |||
342 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
343 | + .bdrv_child_perm = bdrv_default_perms, | ||
344 | }; | ||
345 | |||
346 | typedef struct TestCoDeleteByDrainData { | ||
347 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_replace_test = { | ||
348 | .bdrv_co_drain_begin = bdrv_replace_test_co_drain_begin, | ||
349 | .bdrv_co_drain_end = bdrv_replace_test_co_drain_end, | ||
350 | |||
351 | - .bdrv_child_perm = bdrv_format_default_perms, | ||
352 | + .bdrv_child_perm = bdrv_default_perms, | ||
353 | }; | ||
354 | |||
355 | static void coroutine_fn test_replace_child_mid_drain_read_co(void *opaque) | ||
356 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
357 | index XXXXXXX..XXXXXXX 100644 | ||
358 | --- a/tests/test-bdrv-graph-mod.c | ||
359 | +++ b/tests/test-bdrv-graph-mod.c | ||
360 | @@ -XXX,XX +XXX,XX @@ | ||
361 | |||
362 | static BlockDriver bdrv_pass_through = { | ||
363 | .format_name = "pass-through", | ||
364 | - .bdrv_child_perm = bdrv_filter_default_perms, | ||
365 | + .bdrv_child_perm = bdrv_default_perms, | ||
366 | }; | ||
367 | |||
368 | static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
369 | diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c | ||
370 | index XXXXXXX..XXXXXXX 100644 | ||
371 | --- a/tests/test-block-iothread.c | ||
372 | +++ b/tests/test-block-iothread.c | ||
373 | @@ -XXX,XX +XXX,XX @@ static void test_propagate_basic(void) | ||
374 | BlockDriverState *bs_a, *bs_b, *bs_verify; | ||
375 | QDict *options; | ||
376 | |||
377 | - /* Create bs_a and its BlockBackend */ | ||
378 | - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); | ||
379 | + /* | ||
380 | + * Create bs_a and its BlockBackend. We cannot take the RESIZE | ||
381 | + * permission because blkverify will not share it on the test | ||
382 | + * image. | ||
383 | + */ | ||
384 | + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, | ||
385 | + BLK_PERM_ALL); | ||
386 | bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort); | ||
387 | blk_insert_bs(blk, bs_a, &error_abort); | ||
388 | |||
389 | @@ -XXX,XX +XXX,XX @@ static void test_propagate_diamond(void) | ||
390 | qdict_put_str(options, "raw", "bs_c"); | ||
391 | |||
392 | bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); | ||
393 | - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); | ||
394 | + /* | ||
395 | + * Do not take the RESIZE permission: This would require the same | ||
396 | + * from bs_c and thus from bs_a; however, blkverify will not share | ||
397 | + * it on bs_b, and thus it will not be available for bs_a. | ||
398 | + */ | ||
399 | + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, | ||
400 | + BLK_PERM_ALL); | ||
401 | blk_insert_bs(blk, bs_verify, &error_abort); | ||
402 | |||
403 | /* Switch the AioContext */ | ||
404 | -- | ||
405 | 2.25.4 | ||
406 | |||
407 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Message-Id: <20200513110544.176672-31-mreitz@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | include/block/block_int.h | 10 ---------- | ||
9 | block.c | 17 +++++++++++------ | ||
10 | 2 files changed, 11 insertions(+), 16 deletions(-) | ||
11 | |||
12 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/block/block_int.h | ||
15 | +++ b/include/block/block_int.h | ||
16 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
17 | */ | ||
18 | int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); | ||
19 | |||
20 | -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by | ||
21 | - * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to | ||
22 | - * all children */ | ||
23 | -void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
24 | - const BdrvChildClass *child_class, | ||
25 | - BdrvChildRole child_role, | ||
26 | - BlockReopenQueue *reopen_queue, | ||
27 | - uint64_t perm, uint64_t shared, | ||
28 | - uint64_t *nperm, uint64_t *nshared); | ||
29 | - | ||
30 | /* Default implementation for BlockDriver.bdrv_child_perm() that can be used by | ||
31 | * (non-raw) image formats: Like above for bs->backing, but for bs->file it | ||
32 | * requires WRITE | RESIZE for read-write images, always requires | ||
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 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
38 | return bdrv_child_try_set_perm(c, perms, shared, errp); | ||
39 | } | ||
40 | |||
41 | -void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
42 | - const BdrvChildClass *child_class, | ||
43 | - BdrvChildRole role, | ||
44 | - BlockReopenQueue *reopen_queue, | ||
45 | - uint64_t perm, uint64_t shared, | ||
46 | - uint64_t *nperm, uint64_t *nshared) | ||
47 | +/* | ||
48 | + * Default implementation for .bdrv_child_perm() for block filters: | ||
49 | + * Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED, and RESIZE to the | ||
50 | + * filtered child. | ||
51 | + */ | ||
52 | +static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
53 | + const BdrvChildClass *child_class, | ||
54 | + BdrvChildRole role, | ||
55 | + BlockReopenQueue *reopen_queue, | ||
56 | + uint64_t perm, uint64_t shared, | ||
57 | + uint64_t *nperm, uint64_t *nshared) | ||
58 | { | ||
59 | *nperm = perm & DEFAULT_PERM_PASSTHROUGH; | ||
60 | *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED; | ||
61 | -- | ||
62 | 2.25.4 | ||
63 | |||
64 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Message-Id: <20200513110544.176672-32-mreitz@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | include/block/block_int.h | 11 ----------- | ||
9 | block.c | 19 ------------------- | ||
10 | 2 files changed, 30 deletions(-) | ||
11 | |||
12 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/block/block_int.h | ||
15 | +++ b/include/block/block_int.h | ||
16 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, | ||
17 | */ | ||
18 | int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp); | ||
19 | |||
20 | -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by | ||
21 | - * (non-raw) image formats: Like above for bs->backing, but for bs->file it | ||
22 | - * requires WRITE | RESIZE for read-write images, always requires | ||
23 | - * CONSISTENT_READ and doesn't share WRITE. */ | ||
24 | -void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
25 | - const BdrvChildClass *child_class, | ||
26 | - BdrvChildRole child_role, | ||
27 | - BlockReopenQueue *reopen_queue, | ||
28 | - uint64_t perm, uint64_t shared, | ||
29 | - uint64_t *nperm, uint64_t *nshared); | ||
30 | - | ||
31 | bool bdrv_recurse_can_replace(BlockDriverState *bs, | ||
32 | BlockDriverState *to_replace); | ||
33 | |||
34 | diff --git a/block.c b/block.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block.c | ||
37 | +++ b/block.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
39 | *nshared = shared; | ||
40 | } | ||
41 | |||
42 | -void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
43 | - const BdrvChildClass *child_class, | ||
44 | - BdrvChildRole role, | ||
45 | - BlockReopenQueue *reopen_queue, | ||
46 | - uint64_t perm, uint64_t shared, | ||
47 | - uint64_t *nperm, uint64_t *nshared) | ||
48 | -{ | ||
49 | - if (child_class == &child_of_bds) { | ||
50 | - bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
51 | - perm, shared, nperm, nshared); | ||
52 | - return; | ||
53 | - } | ||
54 | - | ||
55 | - assert(child_class == &child_file); | ||
56 | - | ||
57 | - bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
58 | - perm, shared, nperm, nshared); | ||
59 | -} | ||
60 | - | ||
61 | void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
62 | const BdrvChildClass *child_class, BdrvChildRole role, | ||
63 | BlockReopenQueue *reopen_queue, | ||
64 | -- | ||
65 | 2.25.4 | ||
66 | |||
67 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
4 | Message-Id: <20200513110544.176672-33-mreitz@redhat.com> | ||
5 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | ||
8 | include/block/block_int.h | 1 - | ||
9 | block.c | 39 ++------------------------------------- | ||
10 | tests/test-bdrv-drain.c | 8 +++----- | ||
11 | 3 files changed, 5 insertions(+), 43 deletions(-) | ||
12 | |||
13 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/include/block/block_int.h | ||
16 | +++ b/include/block/block_int.h | ||
17 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildClass { | ||
18 | }; | ||
19 | |||
20 | extern const BdrvChildClass child_of_bds; | ||
21 | -extern const BdrvChildClass child_file; | ||
22 | |||
23 | struct BdrvChild { | ||
24 | BlockDriverState *bs; | ||
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 BlockDriverState *bdrv_open_inherit(const char *filename, | ||
30 | BdrvChildRole child_role, | ||
31 | Error **errp); | ||
32 | |||
33 | -/* TODO: Remove when no longer needed */ | ||
34 | -static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, | ||
35 | - int *child_flags, QDict *child_options, | ||
36 | - int parent_flags, QDict *parent_options); | ||
37 | -static void bdrv_child_cb_attach(BdrvChild *child); | ||
38 | -static void bdrv_child_cb_detach(BdrvChild *child); | ||
39 | - | ||
40 | /* If non-zero, use only whitelisted block drivers */ | ||
41 | static int use_bdrv_whitelist; | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, | ||
44 | *child_flags &= ~BDRV_O_NATIVE_AIO; | ||
45 | } | ||
46 | |||
47 | -/* | ||
48 | - * Returns the options and flags that bs->file should get if a protocol driver | ||
49 | - * is expected, based on the given options and flags for the parent BDS | ||
50 | - */ | ||
51 | -static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, | ||
52 | - int *child_flags, QDict *child_options, | ||
53 | - int parent_flags, QDict *parent_options) | ||
54 | -{ | ||
55 | - bdrv_inherited_options(BDRV_CHILD_IMAGE, true, | ||
56 | - child_flags, child_options, | ||
57 | - parent_flags, parent_options); | ||
58 | -} | ||
59 | - | ||
60 | -const BdrvChildClass child_file = { | ||
61 | - .parent_is_bds = true, | ||
62 | - .get_parent_desc = bdrv_child_get_parent_desc, | ||
63 | - .inherit_options = bdrv_protocol_options, | ||
64 | - .drained_begin = bdrv_child_cb_drained_begin, | ||
65 | - .drained_poll = bdrv_child_cb_drained_poll, | ||
66 | - .drained_end = bdrv_child_cb_drained_end, | ||
67 | - .attach = bdrv_child_cb_attach, | ||
68 | - .detach = bdrv_child_cb_detach, | ||
69 | - .inactivate = bdrv_child_cb_inactivate, | ||
70 | - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, | ||
71 | - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, | ||
72 | -}; | ||
73 | - | ||
74 | static void bdrv_backing_attach(BdrvChild *c) | ||
75 | { | ||
76 | BlockDriverState *parent = c->opaque; | ||
77 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
78 | { | ||
79 | int flags; | ||
80 | |||
81 | - assert(child_class == &child_file || | ||
82 | - (child_class == &child_of_bds && | ||
83 | - (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)))); | ||
84 | + assert(child_class == &child_of_bds && | ||
85 | + (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA))); | ||
86 | |||
87 | flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
88 | |||
89 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/tests/test-bdrv-drain.c | ||
92 | +++ b/tests/test-bdrv-drain.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
94 | uint64_t *nperm, uint64_t *nshared) | ||
95 | { | ||
96 | /* | ||
97 | - * bdrv_default_perms() accepts only these two, so disguise | ||
98 | - * detach_by_driver_cb_parent as one of them. | ||
99 | + * bdrv_default_perms() accepts nothing else, so disguise | ||
100 | + * detach_by_driver_cb_parent. | ||
101 | */ | ||
102 | - if (child_class != &child_file && child_class != &child_of_bds) { | ||
103 | - child_class = &child_of_bds; | ||
104 | - } | ||
105 | + child_class = &child_of_bds; | ||
106 | |||
107 | bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
108 | perm, shared, nperm, nshared); | ||
109 | -- | ||
110 | 2.25.4 | ||
111 | |||
112 | diff view generated by jsdifflib |
1 | blk->name isn't an array, but a pointer that can be NULL. Checking for | 1 | From: Max Reitz <mreitz@redhat.com> |
---|---|---|---|
2 | an anonymous BB must involve a NULL check first, otherwise we get | ||
3 | crashes. | ||
4 | 2 | ||
3 | These calls have no real use for the child role yet, but it will not | ||
4 | harm to give one. | ||
5 | |||
6 | Notably, the bdrv_root_attach_child() call in blockjob.c is left | ||
7 | unmodified because there is not much the generic BlockJob object wants | ||
8 | from its children. | ||
9 | |||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | Message-Id: <20200513110544.176672-34-mreitz@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
7 | Reviewed-by: Juan Quintela <quintela@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
10 | --- | 14 | --- |
11 | block/block-backend.c | 2 +- | 15 | block/block-backend.c | 11 +++++++---- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 16 | block/vvfat.c | 4 +++- |
17 | 2 files changed, 10 insertions(+), 5 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/block/block-backend.c b/block/block-backend.c | 19 | diff --git a/block/block-backend.c b/block/block-backend.c |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/block-backend.c | 21 | --- a/block/block-backend.c |
17 | +++ b/block/block-backend.c | 22 | +++ b/block/block-backend.c |
18 | @@ -XXX,XX +XXX,XX @@ static int blk_root_inactivate(BdrvChild *child) | 23 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference, |
19 | * this point because the VM is stopped) and unattached monitor-owned | 24 | return NULL; |
20 | * BlockBackends. If there is still any other user like a block job, then | 25 | } |
21 | * we simply can't inactivate the image. */ | 26 | |
22 | - if (!blk->dev && !blk->name[0]) { | 27 | - blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, |
23 | + if (!blk->dev && !blk_name(blk)[0]) { | 28 | - perm, BLK_PERM_ALL, blk, errp); |
29 | + blk->root = bdrv_root_attach_child(bs, "root", &child_root, | ||
30 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
31 | + blk->ctx, perm, BLK_PERM_ALL, blk, errp); | ||
32 | if (!blk->root) { | ||
33 | blk_unref(blk); | ||
34 | return NULL; | ||
35 | @@ -XXX,XX +XXX,XX @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) | ||
36 | { | ||
37 | ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | ||
38 | bdrv_ref(bs); | ||
39 | - blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx, | ||
40 | - blk->perm, blk->shared_perm, blk, errp); | ||
41 | + blk->root = bdrv_root_attach_child(bs, "root", &child_root, | ||
42 | + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
43 | + blk->ctx, blk->perm, blk->shared_perm, | ||
44 | + blk, errp); | ||
45 | if (blk->root == NULL) { | ||
24 | return -EPERM; | 46 | return -EPERM; |
25 | } | 47 | } |
26 | 48 | diff --git a/block/vvfat.c b/block/vvfat.c | |
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/block/vvfat.c | ||
51 | +++ b/block/vvfat.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static int enable_write_target(BlockDriverState *bs, Error **errp) | ||
53 | options = qdict_new(); | ||
54 | qdict_put_str(options, "write-target.driver", "qcow"); | ||
55 | s->qcow = bdrv_open_child(s->qcow_filename, options, "write-target", bs, | ||
56 | - &child_vvfat_qcow, 0, false, errp); | ||
57 | + &child_vvfat_qcow, | ||
58 | + BDRV_CHILD_DATA | BDRV_CHILD_METADATA, | ||
59 | + false, errp); | ||
60 | qobject_unref(options); | ||
61 | if (!s->qcow) { | ||
62 | ret = -EINVAL; | ||
27 | -- | 63 | -- |
28 | 1.8.3.1 | 64 | 2.25.4 |
29 | 65 | ||
30 | 66 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Reitz <mreitz@redhat.com> | |
2 | |||
3 | Implementations should decide the necessary permissions based on @role. | ||
4 | |||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
6 | Message-Id: <20200513110544.176672-35-mreitz@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | --- | ||
10 | include/block/block_int.h | 4 +--- | ||
11 | block.c | 39 +++++++++++++++---------------------- | ||
12 | block/backup-top.c | 3 +-- | ||
13 | block/blkdebug.c | 3 +-- | ||
14 | block/blklogwrites.c | 3 +-- | ||
15 | block/commit.c | 1 - | ||
16 | block/copy-on-read.c | 1 - | ||
17 | block/mirror.c | 1 - | ||
18 | block/quorum.c | 1 - | ||
19 | block/replication.c | 1 - | ||
20 | block/vvfat.c | 4 +--- | ||
21 | tests/test-bdrv-drain.c | 19 +----------------- | ||
22 | tests/test-bdrv-graph-mod.c | 1 - | ||
23 | 13 files changed, 22 insertions(+), 59 deletions(-) | ||
24 | |||
25 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/block/block_int.h | ||
28 | +++ b/include/block/block_int.h | ||
29 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
30 | * @reopen_queue. | ||
31 | */ | ||
32 | void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, | ||
33 | - const BdrvChildClass *child_class, | ||
34 | BdrvChildRole role, | ||
35 | BlockReopenQueue *reopen_queue, | ||
36 | uint64_t parent_perm, uint64_t parent_shared, | ||
37 | @@ -XXX,XX +XXX,XX @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, | ||
38 | * child_of_bds child class and set an appropriate BdrvChildRole. | ||
39 | */ | ||
40 | void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
41 | - const BdrvChildClass *child_class, BdrvChildRole role, | ||
42 | - BlockReopenQueue *reopen_queue, | ||
43 | + BdrvChildRole role, BlockReopenQueue *reopen_queue, | ||
44 | uint64_t perm, uint64_t shared, | ||
45 | uint64_t *nperm, uint64_t *nshared); | ||
46 | |||
47 | diff --git a/block.c b/block.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/block.c | ||
50 | +++ b/block.c | ||
51 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_writable(BlockDriverState *bs) | ||
52 | } | ||
53 | |||
54 | static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, | ||
55 | - BdrvChild *c, const BdrvChildClass *child_class, | ||
56 | - BdrvChildRole role, BlockReopenQueue *reopen_queue, | ||
57 | + BdrvChild *c, BdrvChildRole role, | ||
58 | + BlockReopenQueue *reopen_queue, | ||
59 | uint64_t parent_perm, uint64_t parent_shared, | ||
60 | uint64_t *nperm, uint64_t *nshared) | ||
61 | { | ||
62 | assert(bs->drv && bs->drv->bdrv_child_perm); | ||
63 | - bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue, | ||
64 | + bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, | ||
65 | parent_perm, parent_shared, | ||
66 | nperm, nshared); | ||
67 | /* TODO Take force_share from reopen_queue */ | ||
68 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, | ||
69 | uint64_t cur_perm, cur_shared; | ||
70 | bool child_tighten_restr; | ||
71 | |||
72 | - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q, | ||
73 | + bdrv_child_perm(bs, c->bs, c, c->role, q, | ||
74 | cumulative_perms, cumulative_shared_perms, | ||
75 | &cur_perm, &cur_shared); | ||
76 | ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, | ||
77 | @@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, | ||
78 | /* Update all children */ | ||
79 | QLIST_FOREACH(c, &bs->children, next) { | ||
80 | uint64_t cur_perm, cur_shared; | ||
81 | - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, | ||
82 | + bdrv_child_perm(bs, c->bs, c, c->role, NULL, | ||
83 | cumulative_perms, cumulative_shared_perms, | ||
84 | &cur_perm, &cur_shared); | ||
85 | bdrv_child_set_perm(c, cur_perm, cur_shared); | ||
86 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
87 | uint64_t perms, shared; | ||
88 | |||
89 | bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); | ||
90 | - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, | ||
91 | + bdrv_child_perm(bs, c->bs, c, c->role, NULL, | ||
92 | parent_perms, parent_shared, &perms, &shared); | ||
93 | |||
94 | return bdrv_child_try_set_perm(c, perms, shared, errp); | ||
95 | @@ -XXX,XX +XXX,XX @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp) | ||
96 | * filtered child. | ||
97 | */ | ||
98 | static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
99 | - const BdrvChildClass *child_class, | ||
100 | BdrvChildRole role, | ||
101 | BlockReopenQueue *reopen_queue, | ||
102 | uint64_t perm, uint64_t shared, | ||
103 | @@ -XXX,XX +XXX,XX @@ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
104 | } | ||
105 | |||
106 | static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, | ||
107 | - const BdrvChildClass *child_class, | ||
108 | BdrvChildRole role, | ||
109 | BlockReopenQueue *reopen_queue, | ||
110 | uint64_t perm, uint64_t shared, | ||
111 | uint64_t *nperm, uint64_t *nshared) | ||
112 | { | ||
113 | - assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW)); | ||
114 | + assert(role & BDRV_CHILD_COW); | ||
115 | |||
116 | /* | ||
117 | * We want consistent read from backing files if the parent needs it. | ||
118 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, | ||
119 | } | ||
120 | |||
121 | static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
122 | - const BdrvChildClass *child_class, | ||
123 | BdrvChildRole role, | ||
124 | BlockReopenQueue *reopen_queue, | ||
125 | uint64_t perm, uint64_t shared, | ||
126 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
127 | { | ||
128 | int flags; | ||
129 | |||
130 | - assert(child_class == &child_of_bds && | ||
131 | - (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA))); | ||
132 | + assert(role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)); | ||
133 | |||
134 | flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
135 | |||
136 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
137 | * Apart from the modifications below, the same permissions are | ||
138 | * forwarded and left alone as for filters | ||
139 | */ | ||
140 | - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
141 | + bdrv_filter_default_perms(bs, c, role, reopen_queue, | ||
142 | perm, shared, &perm, &shared); | ||
143 | |||
144 | if (role & BDRV_CHILD_METADATA) { | ||
145 | @@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, | ||
146 | } | ||
147 | |||
148 | void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
149 | - const BdrvChildClass *child_class, BdrvChildRole role, | ||
150 | - BlockReopenQueue *reopen_queue, | ||
151 | + BdrvChildRole role, BlockReopenQueue *reopen_queue, | ||
152 | uint64_t perm, uint64_t shared, | ||
153 | uint64_t *nperm, uint64_t *nshared) | ||
154 | { | ||
155 | - assert(child_class == &child_of_bds); | ||
156 | - | ||
157 | if (role & BDRV_CHILD_FILTERED) { | ||
158 | assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | | ||
159 | BDRV_CHILD_COW))); | ||
160 | - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, | ||
161 | + bdrv_filter_default_perms(bs, c, role, reopen_queue, | ||
162 | perm, shared, nperm, nshared); | ||
163 | } else if (role & BDRV_CHILD_COW) { | ||
164 | assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA))); | ||
165 | - bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, | ||
166 | + bdrv_default_perms_for_cow(bs, c, role, reopen_queue, | ||
167 | perm, shared, nperm, nshared); | ||
168 | } else if (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)) { | ||
169 | - bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, | ||
170 | + bdrv_default_perms_for_storage(bs, c, role, reopen_queue, | ||
171 | perm, shared, nperm, nshared); | ||
172 | } else { | ||
173 | g_assert_not_reached(); | ||
174 | @@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, | ||
175 | bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); | ||
176 | |||
177 | assert(parent_bs->drv); | ||
178 | - bdrv_child_perm(parent_bs, child_bs, NULL, child_class, child_role, NULL, | ||
179 | + bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, | ||
180 | perm, shared_perm, &perm, &shared_perm); | ||
181 | |||
182 | child = bdrv_root_attach_child(child_bs, child_name, child_class, | ||
183 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) | ||
184 | if (state->replace_backing_bs && state->new_backing_bs) { | ||
185 | uint64_t nperm, nshared; | ||
186 | bdrv_child_perm(state->bs, state->new_backing_bs, | ||
187 | - NULL, &child_of_bds, bdrv_backing_role(state->bs), | ||
188 | + NULL, bdrv_backing_role(state->bs), | ||
189 | bs_queue, state->perm, state->shared_perm, | ||
190 | &nperm, &nshared); | ||
191 | ret = bdrv_check_update_perm(state->new_backing_bs, NULL, | ||
192 | @@ -XXX,XX +XXX,XX @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, | ||
193 | } else { | ||
194 | uint64_t nperm, nshared; | ||
195 | |||
196 | - bdrv_child_perm(parent->state.bs, bs, c, c->klass, c->role, q, | ||
197 | + bdrv_child_perm(parent->state.bs, bs, c, c->role, q, | ||
198 | parent->state.perm, parent->state.shared_perm, | ||
199 | &nperm, &nshared); | ||
200 | |||
201 | diff --git a/block/backup-top.c b/block/backup-top.c | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/block/backup-top.c | ||
204 | +++ b/block/backup-top.c | ||
205 | @@ -XXX,XX +XXX,XX @@ static void backup_top_refresh_filename(BlockDriverState *bs) | ||
206 | } | ||
207 | |||
208 | static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
209 | - const BdrvChildClass *child_class, | ||
210 | BdrvChildRole role, | ||
211 | BlockReopenQueue *reopen_queue, | ||
212 | uint64_t perm, uint64_t shared, | ||
213 | @@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
214 | *nperm = BLK_PERM_WRITE; | ||
215 | } else { | ||
216 | /* Source child */ | ||
217 | - bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
218 | + bdrv_default_perms(bs, c, role, reopen_queue, | ||
219 | perm, shared, nperm, nshared); | ||
220 | |||
221 | if (perm & BLK_PERM_WRITE) { | ||
222 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
223 | index XXXXXXX..XXXXXXX 100644 | ||
224 | --- a/block/blkdebug.c | ||
225 | +++ b/block/blkdebug.c | ||
226 | @@ -XXX,XX +XXX,XX @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, | ||
227 | } | ||
228 | |||
229 | static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
230 | - const BdrvChildClass *child_class, | ||
231 | BdrvChildRole role, | ||
232 | BlockReopenQueue *reopen_queue, | ||
233 | uint64_t perm, uint64_t shared, | ||
234 | @@ -XXX,XX +XXX,XX @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
235 | { | ||
236 | BDRVBlkdebugState *s = bs->opaque; | ||
237 | |||
238 | - bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
239 | + bdrv_default_perms(bs, c, role, reopen_queue, | ||
240 | perm, shared, nperm, nshared); | ||
241 | |||
242 | *nperm |= s->take_child_perms; | ||
243 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
244 | index XXXXXXX..XXXXXXX 100644 | ||
245 | --- a/block/blklogwrites.c | ||
246 | +++ b/block/blklogwrites.c | ||
247 | @@ -XXX,XX +XXX,XX @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) | ||
248 | } | ||
249 | |||
250 | static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
251 | - const BdrvChildClass *child_class, | ||
252 | BdrvChildRole role, | ||
253 | BlockReopenQueue *ro_q, | ||
254 | uint64_t perm, uint64_t shrd, | ||
255 | @@ -XXX,XX +XXX,XX @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | - bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, | ||
260 | + bdrv_default_perms(bs, c, role, ro_q, perm, shrd, | ||
261 | nperm, nshrd); | ||
262 | } | ||
263 | |||
264 | diff --git a/block/commit.c b/block/commit.c | ||
265 | index XXXXXXX..XXXXXXX 100644 | ||
266 | --- a/block/commit.c | ||
267 | +++ b/block/commit.c | ||
268 | @@ -XXX,XX +XXX,XX @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) | ||
269 | } | ||
270 | |||
271 | static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
272 | - const BdrvChildClass *child_class, | ||
273 | BdrvChildRole role, | ||
274 | BlockReopenQueue *reopen_queue, | ||
275 | uint64_t perm, uint64_t shared, | ||
276 | diff --git a/block/copy-on-read.c b/block/copy-on-read.c | ||
277 | index XXXXXXX..XXXXXXX 100644 | ||
278 | --- a/block/copy-on-read.c | ||
279 | +++ b/block/copy-on-read.c | ||
280 | @@ -XXX,XX +XXX,XX @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, | ||
281 | #define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) | ||
282 | |||
283 | static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
284 | - const BdrvChildClass *child_class, | ||
285 | BdrvChildRole role, | ||
286 | BlockReopenQueue *reopen_queue, | ||
287 | uint64_t perm, uint64_t shared, | ||
288 | diff --git a/block/mirror.c b/block/mirror.c | ||
289 | index XXXXXXX..XXXXXXX 100644 | ||
290 | --- a/block/mirror.c | ||
291 | +++ b/block/mirror.c | ||
292 | @@ -XXX,XX +XXX,XX @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) | ||
293 | } | ||
294 | |||
295 | static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
296 | - const BdrvChildClass *child_class, | ||
297 | BdrvChildRole role, | ||
298 | BlockReopenQueue *reopen_queue, | ||
299 | uint64_t perm, uint64_t shared, | ||
300 | diff --git a/block/quorum.c b/block/quorum.c | ||
301 | index XXXXXXX..XXXXXXX 100644 | ||
302 | --- a/block/quorum.c | ||
303 | +++ b/block/quorum.c | ||
304 | @@ -XXX,XX +XXX,XX @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) | ||
305 | } | ||
306 | |||
307 | static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
308 | - const BdrvChildClass *child_class, | ||
309 | BdrvChildRole role, | ||
310 | BlockReopenQueue *reopen_queue, | ||
311 | uint64_t perm, uint64_t shared, | ||
312 | diff --git a/block/replication.c b/block/replication.c | ||
313 | index XXXXXXX..XXXXXXX 100644 | ||
314 | --- a/block/replication.c | ||
315 | +++ b/block/replication.c | ||
316 | @@ -XXX,XX +XXX,XX @@ static void replication_close(BlockDriverState *bs) | ||
317 | } | ||
318 | |||
319 | static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
320 | - const BdrvChildClass *child_class, | ||
321 | BdrvChildRole role, | ||
322 | BlockReopenQueue *reopen_queue, | ||
323 | uint64_t perm, uint64_t shared, | ||
324 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
325 | index XXXXXXX..XXXXXXX 100644 | ||
326 | --- a/block/vvfat.c | ||
327 | +++ b/block/vvfat.c | ||
328 | @@ -XXX,XX +XXX,XX @@ err: | ||
329 | } | ||
330 | |||
331 | static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
332 | - const BdrvChildClass *child_class, | ||
333 | BdrvChildRole role, | ||
334 | BlockReopenQueue *reopen_queue, | ||
335 | uint64_t perm, uint64_t shared, | ||
336 | @@ -XXX,XX +XXX,XX @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
337 | { | ||
338 | BDRVVVFATState *s = bs->opaque; | ||
339 | |||
340 | - assert(c == s->qcow || | ||
341 | - (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); | ||
342 | + assert(c == s->qcow || (role & BDRV_CHILD_COW)); | ||
343 | |||
344 | if (c == s->qcow) { | ||
345 | /* This is a private node, nobody should try to attach to it */ | ||
346 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
347 | index XXXXXXX..XXXXXXX 100644 | ||
348 | --- a/tests/test-bdrv-drain.c | ||
349 | +++ b/tests/test-bdrv-drain.c | ||
350 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, | ||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | -static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
355 | - const BdrvChildClass *child_class, | ||
356 | - BdrvChildRole role, | ||
357 | - BlockReopenQueue *reopen_queue, | ||
358 | - uint64_t perm, uint64_t shared, | ||
359 | - uint64_t *nperm, uint64_t *nshared) | ||
360 | -{ | ||
361 | - /* | ||
362 | - * bdrv_default_perms() accepts nothing else, so disguise | ||
363 | - * detach_by_driver_cb_parent. | ||
364 | - */ | ||
365 | - child_class = &child_of_bds; | ||
366 | - | ||
367 | - bdrv_default_perms(bs, c, child_class, role, reopen_queue, | ||
368 | - perm, shared, nperm, nshared); | ||
369 | -} | ||
370 | - | ||
371 | static int bdrv_test_change_backing_file(BlockDriverState *bs, | ||
372 | const char *backing_file, | ||
373 | const char *backing_fmt) | ||
374 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test = { | ||
375 | .bdrv_co_drain_begin = bdrv_test_co_drain_begin, | ||
376 | .bdrv_co_drain_end = bdrv_test_co_drain_end, | ||
377 | |||
378 | - .bdrv_child_perm = bdrv_test_child_perm, | ||
379 | + .bdrv_child_perm = bdrv_default_perms, | ||
380 | |||
381 | .bdrv_change_backing_file = bdrv_test_change_backing_file, | ||
382 | }; | ||
383 | diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c | ||
384 | index XXXXXXX..XXXXXXX 100644 | ||
385 | --- a/tests/test-bdrv-graph-mod.c | ||
386 | +++ b/tests/test-bdrv-graph-mod.c | ||
387 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_pass_through = { | ||
388 | }; | ||
389 | |||
390 | static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
391 | - const BdrvChildClass *child_class, | ||
392 | BdrvChildRole role, | ||
393 | BlockReopenQueue *reopen_queue, | ||
394 | uint64_t perm, uint64_t shared, | ||
395 | -- | ||
396 | 2.25.4 | ||
397 | |||
398 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
1 | 2 | ||
3 | Fix when building with -Os: | ||
4 | |||
5 | CC block/block-copy.o | ||
6 | block/block-copy.c: In function ‘block_copy_task_entry’: | ||
7 | block/block-copy.c:428:38: error: ‘error_is_read’ may be used uninitialized in this function [-Werror=maybe-uninitialized] | ||
8 | 428 | t->call_state->error_is_read = error_is_read; | ||
9 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ | ||
10 | |||
11 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Message-Id: <20200507121129.29760-2-philmd@redhat.com> | ||
13 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | --- | ||
16 | block/block-copy.c | 2 +- | ||
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/block-copy.c | ||
22 | +++ b/block/block-copy.c | ||
23 | @@ -XXX,XX +XXX,XX @@ out: | ||
24 | static coroutine_fn int block_copy_task_entry(AioTask *task) | ||
25 | { | ||
26 | BlockCopyTask *t = container_of(task, BlockCopyTask, task); | ||
27 | - bool error_is_read; | ||
28 | + bool error_is_read = false; | ||
29 | int ret; | ||
30 | |||
31 | ret = block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes, | ||
32 | -- | ||
33 | 2.25.4 | ||
34 | |||
35 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
1 | 2 | ||
3 | block_copy_do_copy() is static, only used in block_copy_task_entry | ||
4 | with the error_is_read argument set. No need to check for it, | ||
5 | simplify. | ||
6 | |||
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-Id: <20200507121129.29760-3-philmd@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | block/block-copy.c | 12 +++--------- | ||
13 | 1 file changed, 3 insertions(+), 9 deletions(-) | ||
14 | |||
15 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/block-copy.c | ||
18 | +++ b/block/block-copy.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, | ||
20 | ~BDRV_REQ_WRITE_COMPRESSED); | ||
21 | if (ret < 0) { | ||
22 | trace_block_copy_write_zeroes_fail(s, offset, ret); | ||
23 | - if (error_is_read) { | ||
24 | - *error_is_read = false; | ||
25 | - } | ||
26 | + *error_is_read = false; | ||
27 | } | ||
28 | return ret; | ||
29 | } | ||
30 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, | ||
31 | ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0); | ||
32 | if (ret < 0) { | ||
33 | trace_block_copy_read_fail(s, offset, ret); | ||
34 | - if (error_is_read) { | ||
35 | - *error_is_read = true; | ||
36 | - } | ||
37 | + *error_is_read = true; | ||
38 | goto out; | ||
39 | } | ||
40 | |||
41 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s, | ||
42 | s->write_flags); | ||
43 | if (ret < 0) { | ||
44 | trace_block_copy_write_fail(s, offset, ret); | ||
45 | - if (error_is_read) { | ||
46 | - *error_is_read = false; | ||
47 | - } | ||
48 | + *error_is_read = false; | ||
49 | goto out; | ||
50 | } | ||
51 | |||
52 | -- | ||
53 | 2.25.4 | ||
54 | |||
55 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Shift the logging initialization up to occur prior to validation checks, | ||
4 | so that notrun() messages still get printed to console. | ||
5 | |||
6 | (Also, remove the "debugging messages active" message, because we don't | ||
7 | need to see that hundreds of times per iotest suite run.) | ||
8 | |||
9 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
10 | Message-Id: <20200514201614.19941-2-jsnow@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | tests/qemu-iotests/iotests.py | 11 +++++------ | ||
14 | 1 file changed, 5 insertions(+), 6 deletions(-) | ||
15 | |||
16 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/tests/qemu-iotests/iotests.py | ||
19 | +++ b/tests/qemu-iotests/iotests.py | ||
20 | @@ -XXX,XX +XXX,XX @@ def execute_setup_common(supported_fmts: Sequence[str] = (), | ||
21 | sys.stderr.write('Please run this test via the "check" script\n') | ||
22 | sys.exit(os.EX_USAGE) | ||
23 | |||
24 | + debug = '-d' in sys.argv | ||
25 | + if debug: | ||
26 | + sys.argv.remove('-d') | ||
27 | + logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN)) | ||
28 | + | ||
29 | _verify_image_format(supported_fmts, unsupported_fmts) | ||
30 | _verify_protocol(supported_protocols, unsupported_protocols) | ||
31 | _verify_platform(supported=supported_platforms) | ||
32 | _verify_cache_mode(supported_cache_modes) | ||
33 | _verify_aio_mode(supported_aio_modes) | ||
34 | |||
35 | - debug = '-d' in sys.argv | ||
36 | - if debug: | ||
37 | - sys.argv.remove('-d') | ||
38 | - logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN)) | ||
39 | - logger.debug("iotests debugging messages active") | ||
40 | - | ||
41 | return debug | ||
42 | |||
43 | def execute_test(*args, test_function=None, **kwargs): | ||
44 | -- | ||
45 | 2.25.4 | ||
46 | |||
47 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
3 | One might find interesting to look at AHCI IRQs. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Message-Id: <20200504094858.5975-1-f4bug@amsat.org> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Acked-by: John Snow <jsnow@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | hw/ide/ahci.c | 1 + | ||
12 | 1 file changed, 1 insertion(+) | ||
13 | |||
14 | diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/ide/ahci.c | ||
17 | +++ b/hw/ide/ahci.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void ahci_cmd_done(IDEDMA *dma) | ||
19 | |||
20 | static void ahci_irq_set(void *opaque, int n, int level) | ||
21 | { | ||
22 | + qemu_log_mask(LOG_UNIMP, "ahci: IRQ#%d level:%d\n", n, level); | ||
23 | } | ||
24 | |||
25 | static const IDEDMAOps ahci_dma_ops = { | ||
26 | -- | ||
27 | 2.25.4 | ||
28 | |||
29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | test_overlapping_3() throttles its active commit job so it can be sure | ||
2 | the job is still busy when it checks that you can't start a conflicting | ||
3 | streaming job. | ||
1 | 4 | ||
5 | However, it only sets the commit job back to full speed when it is | ||
6 | ready, which takes a few seconds while it's throttled. We can already | ||
7 | reset the limit after having checked that block-stream returns an error | ||
8 | and save these seconds. | ||
9 | |||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | Message-Id: <20200513100025.33543-1-kwolf@redhat.com> | ||
12 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | tests/qemu-iotests/030 | 6 +++--- | ||
16 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
17 | |||
18 | diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 | ||
19 | index XXXXXXX..XXXXXXX 100755 | ||
20 | --- a/tests/qemu-iotests/030 | ||
21 | +++ b/tests/qemu-iotests/030 | ||
22 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
23 | self.assert_qmp(result, 'error/desc', | ||
24 | "Node 'node5' is busy: block device is in use by block job: commit") | ||
25 | |||
26 | + result = self.vm.qmp('block-job-set-speed', device='commit-drive0', speed=0) | ||
27 | + self.assert_qmp(result, 'return', {}) | ||
28 | + | ||
29 | event = self.vm.event_wait(name='BLOCK_JOB_READY') | ||
30 | self.assert_qmp(event, 'data/device', 'commit-drive0') | ||
31 | self.assert_qmp(event, 'data/type', 'commit') | ||
32 | self.assert_qmp_absent(event, 'data/error') | ||
33 | |||
34 | - result = self.vm.qmp('block-job-set-speed', device='commit-drive0', speed=0) | ||
35 | - self.assert_qmp(result, 'return', {}) | ||
36 | - | ||
37 | result = self.vm.qmp('block-job-complete', device='commit-drive0') | ||
38 | self.assert_qmp(result, 'return', {}) | ||
39 | |||
40 | -- | ||
41 | 2.25.4 | ||
42 | |||
43 | diff view generated by jsdifflib |