1
The following changes since commit 013a18edbbc59cdad019100c7d03c0494642b74c:
1
The following changes since commit 52ed34cbddde1cb89b2ac263e758e349a77f21e1:
2
2
3
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200514' into staging (2020-05-14 16:17:55 +0100)
3
Merge tag 'pull-request-2023-06-26' of https://gitlab.com/thuth/qemu into staging (2023-06-26 10:38:41 +0200)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
git://repo.or.cz/qemu/kevin.git tags/for-upstream
7
https://repo.or.cz/qemu/kevin.git tags/for-upstream
8
8
9
for you to fetch changes up to 7d8f21a650e562270f5ed5341134c9c2c39dc5e8:
9
for you to fetch changes up to 17362398ee1a7f04e8006a46333145d8b707fd35:
10
10
11
iotests/030: Reduce run time by unthrottling job earlier (2020-05-15 14:12:34 +0200)
11
block: use bdrv_co_debug_event in coroutine context (2023-06-28 09:46:34 +0200)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block layer patches:
14
Block layer patches
15
15
16
- Introduce real BdrvChildRole
16
- Re-enable the graph lock
17
- blk/bdrv_make_empty() functions instead of calling callbacks directly
17
- More fixes to coroutine_fn marking
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()
24
18
25
----------------------------------------------------------------
19
----------------------------------------------------------------
26
John Snow (1):
20
Kevin Wolf (11):
27
iotests: log messages from notrun()
21
iotests: Test active commit with iothread and background I/O
22
qdev-properties-system: Lock AioContext for blk_insert_bs()
23
test-block-iothread: Lock AioContext for blk_insert_bs()
24
block: Fix AioContext locking in bdrv_open_child()
25
block: Fix AioContext locking in bdrv_attach_child_common()
26
block: Fix AioContext locking in bdrv_reopen_parse_file_or_backing()
27
block: Fix AioContext locking in bdrv_open_inherit()
28
block: Fix AioContext locking in bdrv_open_backing_file()
29
blockjob: Fix AioContext locking in block_job_add_bdrv()
30
graph-lock: Unlock the AioContext while polling
31
Revert "graph-lock: Disable locking for now"
28
32
29
Kevin Wolf (8):
33
Paolo Bonzini (12):
30
iotests/109: Don't mirror with mismatched size
34
file-posix: remove incorrect coroutine_fn calls
31
iotests/229: Use blkdebug to inject an error
35
qed: mark more functions as coroutine_fns and GRAPH_RDLOCK
32
mirror: Make sure that source and target size match
36
vpc: mark more functions as coroutine_fns and GRAPH_RDLOCK
33
iotests: Mirror with different source/target size
37
bochs: mark more functions as coroutine_fns and GRAPH_RDLOCK
34
iotests: Fix incomplete type declarations
38
block: mark another function as coroutine_fns and GRAPH_UNLOCKED
35
iotests: Run pylint and mypy in a testcase
39
cloop: mark more functions as coroutine_fns and GRAPH_RDLOCK
36
replication: Avoid blk_make_empty() on read-only child
40
dmg: mark more functions as coroutine_fns and GRAPH_RDLOCK
37
iotests/030: Reduce run time by unthrottling job earlier
41
vmdk: mark more functions as coroutine_fns and GRAPH_RDLOCK
42
vhdx: mark more functions as coroutine_fns and GRAPH_RDLOCK
43
qcow2: mark more functions as coroutine_fns and GRAPH_RDLOCK
44
block: use bdrv_co_getlength in coroutine context
45
block: use bdrv_co_debug_event in coroutine context
38
46
39
Lukas Straub (1):
47
block/qcow2.h | 33 +++--
40
block/replication.c: Avoid cancelling the job twice
48
block/vhdx.h | 5 +-
41
49
include/block/block-io.h | 7 ++
42
Max Reitz (38):
50
include/block/graph-lock.h | 6 +-
43
block: Add bdrv_make_empty()
51
block.c | 114 ++++++++++++++++--
44
block: Add blk_make_empty()
52
block/bochs.c | 7 +-
45
block: Use blk_make_empty() after commits
53
block/cloop.c | 9 +-
46
block: Use bdrv_make_empty() where possible
54
block/dmg.c | 21 ++--
47
block: Mark commit, mirror, blkreplay as filters
55
block/file-posix.c | 29 +++--
48
block: Add BlockDriver.is_format
56
block/graph-lock.c | 43 +++----
49
block: Rename BdrvChildRole to BdrvChildClass
57
block/io.c | 14 +--
50
block: Add BdrvChildRole and BdrvChildRoleBits
58
block/parallels.c | 4 +-
51
block: Add BdrvChildRole to BdrvChild
59
block/qcow.c | 30 ++---
52
block: Pass BdrvChildRole to bdrv_child_perm()
60
block/qcow2-bitmap.c | 26 ++--
53
block: Pass BdrvChildRole to .inherit_options()
61
block/qcow2-cluster.c | 24 ++--
54
block: Pass parent_is_format to .inherit_options()
62
block/qcow2-refcount.c | 134 +++++++++++----------
55
block: Rename bdrv_inherited_options()
63
block/qcow2.c | 20 +--
56
block: Add generic bdrv_inherited_options()
64
block/qed-check.c | 5 +-
57
block: Use bdrv_inherited_options()
65
block/qed-table.c | 6 +-
58
block: Unify bdrv_child_cb_attach()
66
block/qed.c | 15 +--
59
block: Unify bdrv_child_cb_detach()
67
block/raw-format.c | 4 +-
60
block: Add child_of_bds
68
block/vhdx-log.c | 36 +++---
61
block: Distinguish paths in *_format_default_perms
69
block/vhdx.c | 73 ++++++-----
62
block: Pull out bdrv_default_perms_for_cow()
70
block/vmdk.c | 55 ++++-----
63
block: Pull out bdrv_default_perms_for_storage()
71
block/vpc.c | 52 ++++----
64
block: Relax *perms_for_storage for data children
72
blockjob.c | 17 ++-
65
block: Add bdrv_default_perms()
73
hw/core/qdev-properties-system.c | 8 +-
66
raw-format: Split raw_read_options()
74
tests/unit/test-block-iothread.c | 7 +-
67
block: Switch child_format users to child_of_bds
75
tests/qemu-iotests/tests/iothreads-commit-active | 85 +++++++++++++
68
block: Drop child_format
76
.../qemu-iotests/tests/iothreads-commit-active.out | 23 ++++
69
block: Make backing files child_of_bds children
77
30 files changed, 573 insertions(+), 339 deletions(-)
70
block: Drop child_backing
78
create mode 100755 tests/qemu-iotests/tests/iothreads-commit-active
71
block: Make format drivers use child_of_bds
79
create mode 100644 tests/qemu-iotests/tests/iothreads-commit-active.out
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()
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
1
We made sure that iotests.py passes pylint. It would be a shame if we
1
This is a better regression test for the bugs hidden by commit 80fc5d26
2
allowed new patches in that break this again, so let's just add a
2
('graph-lock: Disable locking for now'). With that commit reverted, it
3
meta-test case that runs pylint on it.
3
hangs instantaneously and reliably for me.
4
4
5
While we don't pass mypy --strict yet, we can already run it with a few
5
It is important to have a reliable test like this, because the following
6
options that would be part of --strict to make sure that we won't
6
commits will set out to fix the actual root cause of the deadlocks and
7
regress on these aspects at least until we can enable the full thing.
7
then finally revert commit 80fc5d26, which was only a stopgap solution.
8
8
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Message-Id: <20200511163529.349329-3-kwolf@redhat.com>
10
Message-ID: <20230605085711.21261-2-kwolf@redhat.com>
11
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Reviewed-by: John Snow <jsnow@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
13
---
15
tests/qemu-iotests/297 | 44 ++++++++++++++++++++++++++++++++++++++
14
.../tests/iothreads-commit-active | 85 +++++++++++++++++++
16
tests/qemu-iotests/297.out | 3 +++
15
.../tests/iothreads-commit-active.out | 23 +++++
17
tests/qemu-iotests/group | 1 +
16
2 files changed, 108 insertions(+)
18
3 files changed, 48 insertions(+)
17
create mode 100755 tests/qemu-iotests/tests/iothreads-commit-active
19
create mode 100755 tests/qemu-iotests/297
18
create mode 100644 tests/qemu-iotests/tests/iothreads-commit-active.out
20
create mode 100644 tests/qemu-iotests/297.out
21
19
22
diff --git a/tests/qemu-iotests/297 b/tests/qemu-iotests/297
20
diff --git a/tests/qemu-iotests/tests/iothreads-commit-active b/tests/qemu-iotests/tests/iothreads-commit-active
23
new file mode 100755
21
new file mode 100755
24
index XXXXXXX..XXXXXXX
22
index XXXXXXX..XXXXXXX
25
--- /dev/null
23
--- /dev/null
26
+++ b/tests/qemu-iotests/297
24
+++ b/tests/qemu-iotests/tests/iothreads-commit-active
27
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@
28
+#!/usr/bin/env bash
26
+#!/usr/bin/env python3
27
+# group: rw quick auto
29
+#
28
+#
30
+# Copyright (C) 2020 Red Hat, Inc.
29
+# Copyright (C) 2023 Red Hat, Inc.
31
+#
30
+#
32
+# This program is free software; you can redistribute it and/or modify
31
+# This program is free software; you can redistribute it and/or modify
33
+# it under the terms of the GNU General Public License as published by
32
+# it under the terms of the GNU General Public License as published by
34
+# the Free Software Foundation; either version 2 of the License, or
33
+# the Free Software Foundation; either version 2 of the License, or
35
+# (at your option) any later version.
34
+# (at your option) any later version.
...
...
39
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40
+# GNU General Public License for more details.
39
+# GNU General Public License for more details.
41
+#
40
+#
42
+# You should have received a copy of the GNU General Public License
41
+# You should have received a copy of the GNU General Public License
43
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
42
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
43
+#
44
+# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
44
+
45
+
45
+seq=$(basename $0)
46
+import asyncio
46
+echo "QA output created by $seq"
47
+import iotests
47
+
48
+
48
+status=1    # failure is the default!
49
+iotests.script_initialize(supported_fmts=['qcow2'],
50
+ supported_platforms=['linux'])
51
+iotests.verify_virtio_scsi_pci_or_ccw()
49
+
52
+
50
+# get standard environment
53
+with iotests.FilePath('disk0.img') as img_path, \
51
+. ./common.rc
54
+ iotests.FilePath('disk0-snap.img') as snap_path, \
55
+ iotests.FilePath('mirror-src.img') as src_path, \
56
+ iotests.FilePath('mirror-dst.img') as dst_path, \
57
+ iotests.VM() as vm:
52
+
58
+
53
+if ! type -p "pylint-3" > /dev/null; then
59
+ img_size = '10M'
54
+ _notrun "pylint-3 not found"
60
+ iotests.qemu_img_create('-f', iotests.imgfmt, img_path, img_size)
55
+fi
61
+ iotests.qemu_img_create('-f', iotests.imgfmt, '-b', img_path,
56
+if ! type -p "mypy" > /dev/null; then
62
+ '-F', iotests.imgfmt, snap_path)
57
+ _notrun "mypy not found"
63
+ iotests.qemu_img_create('-f', iotests.imgfmt, src_path, img_size)
58
+fi
64
+ iotests.qemu_img_create('-f', iotests.imgfmt, dst_path, img_size)
59
+
65
+
60
+pylint-3 --score=n iotests.py
66
+ iotests.qemu_io_log('-c', 'write 0 64k', img_path)
67
+ iotests.qemu_io_log('-c', 'write 1M 64k', snap_path)
68
+ iotests.qemu_io_log('-c', 'write 3M 64k', snap_path)
61
+
69
+
62
+MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
70
+ iotests.qemu_io_log('-c', f'write 0 {img_size}', src_path)
63
+ --disallow-any-generics --disallow-incomplete-defs \
64
+ --disallow-untyped-decorators --no-implicit-optional \
65
+ --warn-redundant-casts --warn-unused-ignores \
66
+ --no-implicit-reexport iotests.py
67
+
71
+
68
+# success, all done
72
+ iotests.log('Launching VM...')
69
+echo "*** done"
73
+ vm.add_object('iothread,id=iothread0')
70
+rm -f $seq.full
74
+ vm.add_object('throttle-group,x-bps-write=1048576,id=tg0')
71
+status=0
75
+ vm.add_blockdev(f'file,node-name=disk0-file,filename={img_path}')
72
diff --git a/tests/qemu-iotests/297.out b/tests/qemu-iotests/297.out
76
+ vm.add_blockdev('qcow2,node-name=disk0-fmt,file=disk0-file')
77
+ vm.add_drive(snap_path, 'backing=disk0-fmt,node-name=disk0',
78
+ interface='none')
79
+ vm.add_device('virtio-scsi,iothread=iothread0')
80
+ vm.add_device('scsi-hd,drive=drive0')
81
+
82
+ vm.add_blockdev(f'file,filename={src_path},node-name=mirror-src-file')
83
+ vm.add_blockdev('qcow2,file=mirror-src-file,node-name=mirror-src')
84
+ vm.add_blockdev(f'file,filename={dst_path},node-name=mirror-dst-file')
85
+ vm.add_blockdev('qcow2,file=mirror-dst-file,node-name=mirror-dst-fmt')
86
+ vm.add_blockdev('throttle,throttle-group=tg0,file=mirror-dst-fmt,'
87
+ 'node-name=mirror-dst')
88
+ vm.add_device('scsi-hd,drive=mirror-src')
89
+
90
+ vm.launch()
91
+
92
+ # The background I/O is created on unrelated nodes (so that they won't be
93
+ # drained together with the other ones), but on the same iothread
94
+ iotests.log('Creating some background I/O...')
95
+ iotests.log(vm.qmp('blockdev-mirror', job_id='job0', sync='full',
96
+ device='mirror-src', target='mirror-dst',
97
+ auto_dismiss=False))
98
+
99
+ iotests.log('Starting active commit...')
100
+ iotests.log(vm.qmp('block-commit', device='disk0', job_id='job1',
101
+ auto_dismiss=False))
102
+
103
+ # Should succeed and not time out
104
+ try:
105
+ vm.run_job('job1', wait=5.0)
106
+ vm.shutdown()
107
+ except asyncio.TimeoutError:
108
+ # VM may be stuck, kill it
109
+ vm.kill()
110
+ raise
111
diff --git a/tests/qemu-iotests/tests/iothreads-commit-active.out b/tests/qemu-iotests/tests/iothreads-commit-active.out
73
new file mode 100644
112
new file mode 100644
74
index XXXXXXX..XXXXXXX
113
index XXXXXXX..XXXXXXX
75
--- /dev/null
114
--- /dev/null
76
+++ b/tests/qemu-iotests/297.out
115
+++ b/tests/qemu-iotests/tests/iothreads-commit-active.out
77
@@ -XXX,XX +XXX,XX @@
116
@@ -XXX,XX +XXX,XX @@
78
+QA output created by 297
117
+wrote 65536/65536 bytes at offset 0
79
+Success: no issues found in 1 source file
118
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
80
+*** done
119
+
81
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
120
+wrote 65536/65536 bytes at offset 1048576
82
index XXXXXXX..XXXXXXX 100644
121
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
83
--- a/tests/qemu-iotests/group
122
+
84
+++ b/tests/qemu-iotests/group
123
+wrote 65536/65536 bytes at offset 3145728
85
@@ -XXX,XX +XXX,XX @@
124
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
86
289 rw quick
125
+
87
290 rw auto quick
126
+wrote 10485760/10485760 bytes at offset 0
88
292 rw auto quick
127
+10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
89
+297 meta
128
+
129
+Launching VM...
130
+Creating some background I/O...
131
+{"return": {}}
132
+Starting active commit...
133
+{"return": {}}
134
+{"execute": "job-complete", "arguments": {"id": "job1"}}
135
+{"return": {}}
136
+{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
137
+{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
138
+{"execute": "job-dismiss", "arguments": {"id": "job1"}}
139
+{"return": {}}
90
--
140
--
91
2.25.4
141
2.41.0
92
93
diff view generated by jsdifflib
1
test_overlapping_3() throttles its active commit job so it can be sure
1
blk_insert_bs() requires that callers hold the AioContext lock for the
2
the job is still busy when it checks that you can't start a conflicting
2
node that should be inserted. Take it.
3
streaming job.
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
3
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Message-Id: <20200513100025.33543-1-kwolf@redhat.com>
5
Message-ID: <20230605085711.21261-3-kwolf@redhat.com>
12
Reviewed-by: Alberto Garcia <berto@igalia.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
8
---
15
tests/qemu-iotests/030 | 6 +++---
9
hw/core/qdev-properties-system.c | 8 ++++++--
16
1 file changed, 3 insertions(+), 3 deletions(-)
10
1 file changed, 6 insertions(+), 2 deletions(-)
17
11
18
diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
12
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
19
index XXXXXXX..XXXXXXX 100755
13
index XXXXXXX..XXXXXXX 100644
20
--- a/tests/qemu-iotests/030
14
--- a/hw/core/qdev-properties-system.c
21
+++ b/tests/qemu-iotests/030
15
+++ b/hw/core/qdev-properties-system.c
22
@@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase):
16
@@ -XXX,XX +XXX,XX @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
23
self.assert_qmp(result, 'error/desc',
17
* aware of iothreads require their BlockBackends to be in the main
24
"Node 'node5' is busy: block device is in use by block job: commit")
18
* AioContext.
25
19
*/
26
+ result = self.vm.qmp('block-job-set-speed', device='commit-drive0', speed=0)
20
- ctx = iothread ? bdrv_get_aio_context(bs) : qemu_get_aio_context();
27
+ self.assert_qmp(result, 'return', {})
21
- blk = blk_new(ctx, 0, BLK_PERM_ALL);
22
+ ctx = bdrv_get_aio_context(bs);
23
+ blk = blk_new(iothread ? ctx : qemu_get_aio_context(),
24
+ 0, BLK_PERM_ALL);
25
blk_created = true;
26
27
+ aio_context_acquire(ctx);
28
ret = blk_insert_bs(blk, bs, errp);
29
+ aio_context_release(ctx);
28
+
30
+
29
event = self.vm.event_wait(name='BLOCK_JOB_READY')
31
if (ret < 0) {
30
self.assert_qmp(event, 'data/device', 'commit-drive0')
32
goto fail;
31
self.assert_qmp(event, 'data/type', 'commit')
33
}
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
--
34
--
41
2.25.4
35
2.41.0
42
43
diff view generated by jsdifflib
1
We need to fix only a few places so that iotests.py can pass
1
blk_insert_bs() requires that callers hold the AioContext lock for the
2
mypy --disallow-incomplete-defs, which seems to be a desirable option to
2
node that should be inserted. Take it.
3
have enabled in the long run.
4
3
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Message-Id: <20200511163529.349329-2-kwolf@redhat.com>
5
Message-ID: <20230605085711.21261-4-kwolf@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
8
---
11
tests/qemu-iotests/iotests.py | 8 ++++----
9
tests/unit/test-block-iothread.c | 7 ++++++-
12
1 file changed, 4 insertions(+), 4 deletions(-)
10
1 file changed, 6 insertions(+), 1 deletion(-)
13
11
14
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
12
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
15
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
16
--- a/tests/qemu-iotests/iotests.py
14
--- a/tests/unit/test-block-iothread.c
17
+++ b/tests/qemu-iotests/iotests.py
15
+++ b/tests/unit/test-block-iothread.c
18
@@ -XXX,XX +XXX,XX @@ def _verify_cache_mode(supported_cache_modes: Sequence[str] = ()) -> None:
16
@@ -XXX,XX +XXX,XX @@ static void test_attach_second_node(void)
19
if supported_cache_modes and (cachemode not in supported_cache_modes):
17
BlockDriverState *bs, *filter;
20
notrun('not suitable for this cache mode: %s' % cachemode)
18
QDict *options;
21
19
22
-def _verify_aio_mode(supported_aio_modes: Sequence[str] = ()):
20
+ aio_context_acquire(main_ctx);
23
+def _verify_aio_mode(supported_aio_modes: Sequence[str] = ()) -> None:
21
blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
24
if supported_aio_modes and (aiomode not in supported_aio_modes):
22
bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
25
notrun('not suitable for this aio mode: %s' % aiomode)
23
blk_insert_bs(blk, bs, &error_abort);
26
24
@@ -XXX,XX +XXX,XX @@ static void test_attach_second_node(void)
27
@@ -XXX,XX +XXX,XX @@ def skip_if_unsupported(required_formats=(), read_only=False):
25
qdict_put_str(options, "driver", "raw");
28
'''Skip Test Decorator
26
qdict_put_str(options, "file", "base");
29
Runs the test if all the required formats are whitelisted'''
27
30
def skip_test_decorator(func):
28
- aio_context_acquire(main_ctx);
31
- def func_wrapper(test_case: QMPTestCase, *args, **kwargs):
29
filter = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
32
+ def func_wrapper(test_case: QMPTestCase, *args: List[Any],
30
aio_context_release(main_ctx);
33
+ **kwargs: Dict[str, Any]) -> None:
31
34
if callable(required_formats):
32
@@ -XXX,XX +XXX,XX @@ static void test_attach_preserve_blk_ctx(void)
35
fmts = required_formats(test_case)
33
{
36
else:
34
IOThread *iothread = iothread_new();
37
@@ -XXX,XX +XXX,XX @@ def skip_if_unsupported(required_formats=(), read_only=False):
35
AioContext *ctx = iothread_get_aio_context(iothread);
38
if usf_list:
36
+ AioContext *main_ctx = qemu_get_aio_context();
39
msg = f'{test_case}: formats {usf_list} are not whitelisted'
37
BlockBackend *blk;
40
test_case.case_skip(msg)
38
BlockDriverState *bs;
41
- return None
39
42
else:
40
+ aio_context_acquire(main_ctx);
43
- return func(test_case, *args, **kwargs)
41
blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
44
+ func(test_case, *args, **kwargs)
42
bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
45
return func_wrapper
43
bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
46
return skip_test_decorator
44
@@ -XXX,XX +XXX,XX @@ static void test_attach_preserve_blk_ctx(void)
45
blk_insert_bs(blk, bs, &error_abort);
46
g_assert(blk_get_aio_context(blk) == ctx);
47
g_assert(bdrv_get_aio_context(bs) == ctx);
48
+ aio_context_release(main_ctx);
49
50
/* Remove the node again */
51
aio_context_acquire(ctx);
52
@@ -XXX,XX +XXX,XX @@ static void test_attach_preserve_blk_ctx(void)
53
g_assert(bdrv_get_aio_context(bs) == qemu_get_aio_context());
54
55
/* Re-attach the node */
56
+ aio_context_acquire(main_ctx);
57
blk_insert_bs(blk, bs, &error_abort);
58
+ aio_context_release(main_ctx);
59
g_assert(blk_get_aio_context(blk) == ctx);
60
g_assert(bdrv_get_aio_context(bs) == ctx);
47
61
48
--
62
--
49
2.25.4
63
2.41.0
50
51
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
bdrv_attach_child() requires that the caller holds the AioContext lock
2
for the new child node. Take it in bdrv_open_child() and document that
3
the caller must not hold any AioContext apart from the main AioContext.
2
4
3
This structure nearly only contains parent callbacks for child state
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
changes. It cannot really reflect a child's role, because different
6
Message-ID: <20230605085711.21261-5-kwolf@redhat.com>
5
roles may overlap (as we will see when real roles are introduced), and
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
9
---
15
include/block/block.h | 6 +-
10
block.c | 13 +++++++++++--
16
include/block/block_int.h | 22 +++---
11
1 file changed, 11 insertions(+), 2 deletions(-)
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
12
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
13
diff --git a/block.c b/block.c
151
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
152
--- a/block.c
15
--- a/block.c
153
+++ b/block.c
16
+++ b/block.c
154
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
17
@@ -XXX,XX +XXX,XX @@ done:
155
const char *reference,
18
*
156
QDict *options, int flags,
19
* The BlockdevRef will be removed from the options QDict.
157
BlockDriverState *parent,
20
*
158
- const BdrvChildRole *child_role,
21
+ * The caller must hold the lock of the main AioContext and no other AioContext.
159
+ const BdrvChildClass *child_class,
22
* @parent can move to a different AioContext in this function. Callers must
160
Error **errp);
23
* make sure that their AioContext locking is still correct after this.
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
*/
24
*/
321
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
25
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
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)
26
bool allow_none, Error **errp)
423
{
27
{
424
BlockDriverState *bs;
28
BlockDriverState *bs;
425
29
+ BdrvChild *child;
426
- bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role,
30
+ AioContext *ctx;
427
+ bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class,
31
428
allow_none, errp);
32
GLOBAL_STATE_CODE();
429
if (bs == NULL) {
33
34
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
430
return NULL;
35
return NULL;
431
}
36
}
432
37
433
- return bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
38
- return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
434
+ return bdrv_attach_child(parent, bs, bdref_key, child_class, errp);
39
- errp);
40
+ ctx = bdrv_get_aio_context(bs);
41
+ aio_context_acquire(ctx);
42
+ child = bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
43
+ errp);
44
+ aio_context_release(ctx);
45
+
46
+ return child;
435
}
47
}
436
48
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
/*
49
/*
957
* Initial graph:
50
* Wrapper on bdrv_open_child() for most popular case: open primary child of bs.
958
@@ -XXX,XX +XXX,XX @@ static BdrvChildRole detach_by_driver_cb_role;
959
*
51
*
960
* by_parent_cb == false: Test that bdrv_drain_invoke() doesn't poll
52
+ * The caller must hold the lock of the main AioContext and no other AioContext.
961
*
53
* @parent can move to a different AioContext in this function. Callers must
962
- * PA's BdrvChildRole has a .drained_begin callback that schedules a BH
54
* make sure that their AioContext locking is still correct after this.
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
*/
55
*/
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
--
56
--
1048
2.25.4
57
2.41.0
1049
1050
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
The function can move the child node to a different AioContext. In this
2
case, it also must take the AioContext lock for the new context before
3
calling functions that require the caller to hold the AioContext for the
4
child node.
2
5
3
Right now, bdrv_format_default_perms() is used by format parents
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
(generally). We want to switch to a model where most parents use a
7
Message-ID: <20230605085711.21261-6-kwolf@redhat.com>
5
single BdrvChildClass, which then decides the permissions based on the
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
---
10
---
18
block.c | 71 +++++++++++++++++++++++++++++++++++++--------------------
11
block.c | 21 ++++++++++++++++++++-
19
1 file changed, 46 insertions(+), 25 deletions(-)
12
1 file changed, 20 insertions(+), 1 deletion(-)
20
13
21
diff --git a/block.c b/block.c
14
diff --git a/block.c b/block.c
22
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
23
--- a/block.c
16
--- a/block.c
24
+++ b/block.c
17
+++ b/block.c
25
@@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
18
@@ -XXX,XX +XXX,XX @@ static TransactionActionDrv bdrv_attach_child_common_drv = {
26
*nshared = shared;
19
* Function doesn't update permissions, caller is responsible for this.
27
}
20
*
28
21
* Returns new created child.
29
+static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
22
+ *
30
+ const BdrvChildClass *child_class,
23
+ * The caller must hold the AioContext lock for @child_bs. Both @parent_bs and
31
+ BdrvChildRole role,
24
+ * @child_bs can move to a different AioContext in this function. Callers must
32
+ BlockReopenQueue *reopen_queue,
25
+ * make sure that their AioContext locking is still correct after this.
33
+ uint64_t perm, uint64_t shared,
26
*/
34
+ uint64_t *nperm, uint64_t *nshared)
27
static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
35
+{
28
const char *child_name,
36
+ int flags;
29
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
37
+
30
Transaction *tran, Error **errp)
38
+ assert(child_class == &child_file ||
31
{
39
+ (child_class == &child_of_bds &&
32
BdrvChild *new_child;
40
+ (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA))));
33
- AioContext *parent_ctx;
41
+
34
+ AioContext *parent_ctx, *new_child_ctx;
42
+ flags = bdrv_reopen_get_flags(reopen_queue, bs);
35
AioContext *child_ctx = bdrv_get_aio_context(child_bs);
43
+
36
44
+ /*
37
assert(child_class->get_parent_desc);
45
+ * Apart from the modifications below, the same permissions are
38
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
46
+ * forwarded and left alone as for filters
39
}
47
+ */
40
}
48
+ bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue,
41
49
+ perm, shared, &perm, &shared);
42
+ new_child_ctx = bdrv_get_aio_context(child_bs);
50
+
43
+ if (new_child_ctx != child_ctx) {
51
+ /* Format drivers may touch metadata even if the guest doesn't write */
44
+ aio_context_release(child_ctx);
52
+ if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
45
+ aio_context_acquire(new_child_ctx);
53
+ perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
54
+ }
46
+ }
55
+
47
+
56
+ /*
48
bdrv_ref(child_bs);
57
+ * bs->file always needs to be consistent because of the metadata. We
49
/*
58
+ * can never allow other users to resize or write to it.
50
* Let every new BdrvChild start with a drained parent. Inserting the child
59
+ */
51
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
60
+ if (!(flags & BDRV_O_NO_IO)) {
52
};
61
+ perm |= BLK_PERM_CONSISTENT_READ;
53
tran_add(tran, &bdrv_attach_child_common_drv, s);
62
+ }
54
63
+ shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
55
+ if (new_child_ctx != child_ctx) {
64
+
56
+ aio_context_release(new_child_ctx);
65
+ if (bs->open_flags & BDRV_O_INACTIVE) {
57
+ aio_context_acquire(child_ctx);
66
+ shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
67
+ }
58
+ }
68
+
59
+
69
+ *nperm = perm;
60
return new_child;
70
+ *nshared = shared;
61
}
71
+}
62
72
+
63
/*
73
void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
64
* Function doesn't update permissions, caller is responsible for this.
74
const BdrvChildClass *child_class,
65
+ *
75
BdrvChildRole role,
66
+ * The caller must hold the AioContext lock for @child_bs. Both @parent_bs and
76
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
67
+ * @child_bs can move to a different AioContext in this function. Callers must
77
assert(child_class == &child_backing || child_class == &child_file);
68
+ * make sure that their AioContext locking is still correct after this.
78
69
*/
79
if (!backing) {
70
static BdrvChild *bdrv_attach_child_noperm(BlockDriverState *parent_bs,
80
- int flags = bdrv_reopen_get_flags(reopen_queue, bs);
71
BlockDriverState *child_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
--
72
--
111
2.25.4
73
2.41.0
112
113
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
bdrv_set_file_or_backing_noperm() requires the caller to hold the
2
AioContext lock for the child node, but we hold the one for the parent
3
node in bdrv_reopen_parse_file_or_backing(). Take the other one
4
temporarily.
2
5
3
Right now, bdrv_format_default_perms() is used by format parents
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
(generally). We want to switch to a model where most parents use a
7
Message-ID: <20230605085711.21261-7-kwolf@redhat.com>
5
single BdrvChildClass, which then decides the permissions based on the
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
10
---
14
block.c | 62 +++++++++++++++++++++++++++++++++++++--------------------
11
block.c | 35 +++++++++++++++++++++++++++++++++--
15
1 file changed, 40 insertions(+), 22 deletions(-)
12
1 file changed, 33 insertions(+), 2 deletions(-)
16
13
17
diff --git a/block.c b/block.c
14
diff --git a/block.c b/block.c
18
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
19
--- a/block.c
16
--- a/block.c
20
+++ b/block.c
17
+++ b/block.c
21
@@ -XXX,XX +XXX,XX @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
18
@@ -XXX,XX +XXX,XX @@ static BdrvChildRole bdrv_backing_role(BlockDriverState *bs)
22
*nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED;
19
* callers which don't need their own reference any more must call bdrv_unref().
20
*
21
* Function doesn't update permissions, caller is responsible for this.
22
+ *
23
+ * The caller must hold the AioContext lock for @child_bs. Both @parent_bs and
24
+ * @child_bs can move to a different AioContext in this function. Callers must
25
+ * make sure that their AioContext locking is still correct after this.
26
*/
27
static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs,
28
BlockDriverState *child_bs,
29
@@ -XXX,XX +XXX,XX @@ out:
30
return 0;
23
}
31
}
24
32
25
+static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
33
+/*
26
+ const BdrvChildClass *child_class,
34
+ * The caller must hold the AioContext lock for @backing_hd. Both @bs and
27
+ BdrvChildRole role,
35
+ * @backing_hd can move to a different AioContext in this function. Callers must
28
+ BlockReopenQueue *reopen_queue,
36
+ * make sure that their AioContext locking is still correct after this.
29
+ uint64_t perm, uint64_t shared,
37
+ */
30
+ uint64_t *nperm, uint64_t *nshared)
38
static int bdrv_set_backing_noperm(BlockDriverState *bs,
31
+{
39
BlockDriverState *backing_hd,
32
+ assert(child_class == &child_backing ||
40
Transaction *tran, Error **errp)
33
+ (child_class == &child_of_bds && (role & BDRV_CHILD_COW)));
41
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
34
+
42
* backing BlockDriverState (or NULL).
35
+ /*
43
*
36
+ * We want consistent read from backing files if the parent needs it.
44
* Return 0 on success, otherwise return < 0 and set @errp.
37
+ * No other operations are performed on backing files.
45
+ *
38
+ */
46
+ * The caller must hold the AioContext lock of @reopen_state->bs.
39
+ perm &= BLK_PERM_CONSISTENT_READ;
47
+ * @reopen_state->bs can move to a different AioContext in this function.
40
+
48
+ * Callers must make sure that their AioContext locking is still correct after
41
+ /*
49
+ * this.
42
+ * If the parent can deal with changing data, we're okay with a
50
*/
43
+ * writable and resizable backing file.
51
static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
44
+ * TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too?
52
bool is_backing, Transaction *tran,
45
+ */
53
@@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
46
+ if (shared & BLK_PERM_WRITE) {
54
const char *child_name = is_backing ? "backing" : "file";
47
+ shared = BLK_PERM_WRITE | BLK_PERM_RESIZE;
55
QObject *value;
48
+ } else {
56
const char *str;
49
+ shared = 0;
57
+ AioContext *ctx, *old_ctx;
58
+ int ret;
59
60
GLOBAL_STATE_CODE();
61
62
@@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
63
reopen_state->old_file_bs = old_child_bs;
64
}
65
66
- return bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing,
67
- tran, errp);
68
+ old_ctx = bdrv_get_aio_context(bs);
69
+ ctx = bdrv_get_aio_context(new_child_bs);
70
+ if (old_ctx != ctx) {
71
+ aio_context_release(old_ctx);
72
+ aio_context_acquire(ctx);
50
+ }
73
+ }
51
+
74
+
52
+ shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD |
75
+ ret = bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing,
53
+ BLK_PERM_WRITE_UNCHANGED;
76
+ tran, errp);
54
+
77
+
55
+ if (bs->open_flags & BDRV_O_INACTIVE) {
78
+ if (old_ctx != ctx) {
56
+ shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
79
+ aio_context_release(ctx);
80
+ aio_context_acquire(old_ctx);
57
+ }
81
+ }
58
+
82
+
59
+ *nperm = perm;
83
+ return ret;
60
+ *nshared = shared;
61
+}
62
+
63
void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
64
const BdrvChildClass *child_class,
65
BdrvChildRole role,
66
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
67
*nperm = perm;
68
*nshared = shared;
69
} else {
70
- /* We want consistent read from backing files if the parent needs it.
71
- * No other operations are performed on backing files. */
72
- perm &= BLK_PERM_CONSISTENT_READ;
73
-
74
- /* If the parent can deal with changing data, we're okay with a
75
- * writable and resizable backing file. */
76
- /* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? */
77
- if (shared & BLK_PERM_WRITE) {
78
- shared = BLK_PERM_WRITE | BLK_PERM_RESIZE;
79
- } else {
80
- shared = 0;
81
- }
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
}
95
}
84
}
96
85
86
/*
87
@@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
88
* It is the responsibility of the caller to then call the abort() or
89
* commit() for any other BDS that have been left in a prepare() state
90
*
91
+ * The caller must hold the AioContext lock of @reopen_state->bs.
92
*/
93
static int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
94
BlockReopenQueue *queue,
97
--
95
--
98
2.25.4
96
2.41.0
99
100
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
bdrv_open_inherit() calls several functions for which it needs to hold
2
the AioContext lock, but currently doesn't. This includes calls in
3
bdrv_append_temp_snapshot(), for which bdrv_open_inherit() is the only
4
caller. Fix the locking in these places.
2
5
3
Make all parents of backing files pass the appropriate BdrvChildRole.
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
By doing so, we can switch their BdrvChildClass over to the generic
7
Message-ID: <20230605085711.21261-8-kwolf@redhat.com>
5
child_of_bds, which will do the right thing when given a correct
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
BdrvChildRole.
7
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Message-Id: <20200513110544.176672-24-mreitz@redhat.com>
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
10
---
13
block.c | 26 ++++++++++++++++++++------
11
block.c | 25 ++++++++++++++++++++++++-
14
block/backup-top.c | 2 +-
12
1 file changed, 24 insertions(+), 1 deletion(-)
15
block/vvfat.c | 3 ++-
16
tests/test-bdrv-drain.c | 13 +++++++------
17
4 files changed, 30 insertions(+), 14 deletions(-)
18
13
19
diff --git a/block.c b/block.c
14
diff --git a/block.c b/block.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
16
--- a/block.c
22
+++ b/block.c
17
+++ b/block.c
23
@@ -XXX,XX +XXX,XX @@ static bool bdrv_inherits_from_recursive(BlockDriverState *child,
18
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
24
return child != NULL;
19
int64_t total_size;
25
}
20
QemuOpts *opts = NULL;
26
21
BlockDriverState *bs_snapshot = NULL;
27
+/*
22
+ AioContext *ctx = bdrv_get_aio_context(bs);
28
+ * Return the BdrvChildRole for @bs's backing child. bs->backing is
23
int ret;
29
+ * mostly used for COW backing children (role = COW), but also for
24
30
+ * filtered children (role = FILTERED | PRIMARY).
25
GLOBAL_STATE_CODE();
31
+ */
26
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
32
+static BdrvChildRole bdrv_backing_role(BlockDriverState *bs)
27
instead of opening 'filename' directly */
33
+{
28
34
+ if (bs->drv && bs->drv->is_filter) {
29
/* Get the required size from the image */
35
+ return BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY;
30
+ aio_context_acquire(ctx);
36
+ } else {
31
total_size = bdrv_getlength(bs);
37
+ return BDRV_CHILD_COW;
32
+ aio_context_release(ctx);
38
+ }
39
+}
40
+
33
+
41
/*
34
if (total_size < 0) {
42
* Sets the backing file link of a BDS. A new reference is created; callers
35
error_setg_errno(errp, -total_size, "Could not get image size");
43
* which don't need their own reference any more must call bdrv_unref().
36
goto out;
44
@@ -XXX,XX +XXX,XX @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
37
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
45
goto out;
38
goto out;
46
}
39
}
47
40
48
- bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing,
41
+ aio_context_acquire(ctx);
49
- 0, errp);
42
ret = bdrv_append(bs_snapshot, bs, errp);
50
+ bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_of_bds,
43
+ aio_context_release(ctx);
51
+ bdrv_backing_role(bs), errp);
44
+
52
/* If backing_hd was already part of bs's backing chain, and
45
if (ret < 0) {
53
* inherits_from pointed recursively to bs then let's update it to
46
bs_snapshot = NULL;
54
* point directly to bs (else it will become NULL). */
47
goto out;
55
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
48
@@ -XXX,XX +XXX,XX @@ bdrv_open_inherit(const char *filename, const char *reference, QDict *options,
49
Error *local_err = NULL;
50
QDict *snapshot_options = NULL;
51
int snapshot_flags = 0;
52
+ AioContext *ctx = qemu_get_aio_context();
53
54
assert(!child_class || !flags);
55
assert(!child_class == !parent);
56
@@ -XXX,XX +XXX,XX @@ bdrv_open_inherit(const char *filename, const char *reference, QDict *options,
57
/* Not requesting BLK_PERM_CONSISTENT_READ because we're only
58
* looking at the header to guess the image format. This works even
59
* in cases where a guest would not see a consistent state. */
60
- file = blk_new(bdrv_get_aio_context(file_bs), 0, BLK_PERM_ALL);
61
+ ctx = bdrv_get_aio_context(file_bs);
62
+ aio_context_acquire(ctx);
63
+ file = blk_new(ctx, 0, BLK_PERM_ALL);
64
blk_insert_bs(file, file_bs, &local_err);
65
bdrv_unref(file_bs);
66
+ aio_context_release(ctx);
67
+
68
if (local_err) {
69
goto fail;
70
}
71
@@ -XXX,XX +XXX,XX @@ bdrv_open_inherit(const char *filename, const char *reference, QDict *options,
72
goto fail;
56
}
73
}
57
74
58
backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs,
75
+ /* The AioContext could have changed during bdrv_open_common() */
59
- &child_backing, 0, errp);
76
+ ctx = bdrv_get_aio_context(bs);
60
+ &child_of_bds, bdrv_backing_role(bs), errp);
77
+
61
if (!backing_hd) {
78
if (file) {
62
bs->open_flags |= BDRV_O_NO_BACKING;
79
+ aio_context_acquire(ctx);
63
error_prepend(errp, "Could not open backing file: ");
80
blk_unref(file);
64
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
81
+ aio_context_release(ctx);
65
if (state->replace_backing_bs && state->new_backing_bs) {
82
file = NULL;
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
}
83
}
91
84
92
- if (child_class == &child_file) {
85
@@ -XXX,XX +XXX,XX @@ bdrv_open_inherit(const char *filename, const char *reference, QDict *options,
93
+ if (!(role & BDRV_CHILD_FILTERED)) {
86
* (snapshot_bs); thus, we have to drop the strong reference to bs
94
/*
87
* (which we obtained by calling bdrv_new()). bs will not be deleted,
95
* Target child
88
* though, because the overlay still has a reference to it. */
96
*
89
+ aio_context_acquire(ctx);
97
diff --git a/block/vvfat.c b/block/vvfat.c
90
bdrv_unref(bs);
98
index XXXXXXX..XXXXXXX 100644
91
+ aio_context_release(ctx);
99
--- a/block/vvfat.c
92
bs = snapshot_bs;
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
}
93
}
123
94
124
@@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb)
95
return bs;
125
bdrv_ref(a);
96
126
child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, 0,
97
fail:
127
&error_abort);
98
+ aio_context_acquire(ctx);
128
- child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, 0,
99
blk_unref(file);
129
- &error_abort);
100
qobject_unref(snapshot_options);
130
+ child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds,
101
qobject_unref(bs->explicit_options);
131
+ BDRV_CHILD_COW, &error_abort);
102
@@ -XXX,XX +XXX,XX @@ fail:
132
103
bs->options = NULL;
133
bdrv_ref(a);
104
bs->explicit_options = NULL;
134
bdrv_attach_child(parent_a, a, "PA-A",
105
bdrv_unref(bs);
135
@@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void)
106
+ aio_context_release(ctx);
136
int i;
107
error_propagate(errp, local_err);
137
int ret;
108
return NULL;
138
109
139
- chain_child_class = child_backing;
110
close_and_fail:
140
+ chain_child_class = child_of_bds;
111
+ aio_context_acquire(ctx);
141
chain_child_class.update_filename = drop_intermediate_poll_update_filename;
112
bdrv_unref(bs);
142
113
+ aio_context_release(ctx);
143
for (i = 0; i < 3; i++) {
114
qobject_unref(snapshot_options);
144
@@ -XXX,XX +XXX,XX @@ static void test_drop_intermediate_poll(void)
115
qobject_unref(options);
145
/* Takes the reference to chain[i - 1] */
116
error_propagate(errp, local_err);
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);
150
}
151
}
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);
163
--
117
--
164
2.25.4
118
2.41.0
165
166
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
bdrv_set_backing() requires the caller to hold the AioContext lock for
2
@backing_hd. Take it in bdrv_open_backing_file() before calling the
3
function.
2
4
3
We can be less restrictive about pure data children than those with
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
metadata on them, so let bdrv_default_perms_for_storage() handle
6
Message-ID: <20230605085711.21261-9-kwolf@redhat.com>
5
metadata children differently from pure data children.
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
19
---
9
---
20
block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++----------
10
block.c | 5 +++++
21
1 file changed, 48 insertions(+), 10 deletions(-)
11
1 file changed, 5 insertions(+)
22
12
23
diff --git a/block.c b/block.c
13
diff --git a/block.c b/block.c
24
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
25
--- a/block.c
15
--- a/block.c
26
+++ b/block.c
16
+++ b/block.c
27
@@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
17
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
28
bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue,
18
int ret = 0;
29
perm, shared, &perm, &shared);
19
bool implicit_backing = false;
30
20
BlockDriverState *backing_hd;
31
- /* Format drivers may touch metadata even if the guest doesn't write */
21
+ AioContext *backing_hd_ctx;
32
- if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
22
QDict *options;
33
- perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
23
QDict *tmp_parent_options = NULL;
34
+ if (role & BDRV_CHILD_METADATA) {
24
Error *local_err = NULL;
35
+ /* Format drivers may touch metadata even if the guest doesn't write */
25
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
36
+ if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
26
37
+ perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
27
/* Hook up the backing file link; drop our reference, bs owns the
38
+ }
28
* backing_hd reference now */
29
+ backing_hd_ctx = bdrv_get_aio_context(backing_hd);
30
+ aio_context_acquire(backing_hd_ctx);
31
ret = bdrv_set_backing_hd(bs, backing_hd, errp);
32
bdrv_unref(backing_hd);
33
+ aio_context_release(backing_hd_ctx);
39
+
34
+
40
+ /*
35
if (ret < 0) {
41
+ * bs->file always needs to be consistent because of the
36
goto free_exit;
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
}
37
}
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
--
38
--
96
2.25.4
39
2.41.0
97
98
diff view generated by jsdifflib
1
This tests that the mirror job catches situations where the target node
1
bdrv_root_attach_child() requires callers to hold the AioContext lock
2
has a different size than the source node. It must also forbid resize
2
for child_bs. Take it in block_job_add_bdrv() before calling the
3
operations when the job is already running.
3
function.
4
4
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
6
Message-ID: <20230605085711.21261-10-kwolf@redhat.com>
7
Message-Id: <20200511135825.219437-5-kwolf@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@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>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
9
---
12
tests/qemu-iotests/041 | 45 ++++++++++++++++++++++++++++++++++++++
10
blockjob.c | 17 ++++++++++++-----
13
tests/qemu-iotests/041.out | 4 ++--
11
1 file changed, 12 insertions(+), 5 deletions(-)
14
2 files changed, 47 insertions(+), 2 deletions(-)
15
12
16
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
13
diff --git a/blockjob.c b/blockjob.c
17
index XXXXXXX..XXXXXXX 100755
18
--- a/tests/qemu-iotests/041
19
+++ b/tests/qemu-iotests/041
20
@@ -XXX,XX +XXX,XX @@ class TestSingleBlockdev(TestSingleDrive):
21
target=self.qmp_target)
22
self.assert_qmp(result, 'error/class', 'GenericError')
23
24
+ def do_test_resize(self, device, node):
25
+ def pre_finalize():
26
+ if device:
27
+ result = self.vm.qmp('block_resize', device=device, size=65536)
28
+ self.assert_qmp(result, 'error/class', 'GenericError')
29
+
30
+ result = self.vm.qmp('block_resize', node_name=node, size=65536)
31
+ self.assert_qmp(result, 'error/class', 'GenericError')
32
+
33
+ result = self.vm.qmp(self.qmp_cmd, job_id='job0', device='drive0',
34
+ sync='full', target=self.qmp_target,
35
+ auto_finalize=False, auto_dismiss=False)
36
+ self.assert_qmp(result, 'return', {})
37
+
38
+ result = self.vm.run_job('job0', auto_finalize=False,
39
+ pre_finalize=pre_finalize)
40
+ self.assertEqual(result, None)
41
+
42
+ def test_source_resize(self):
43
+ self.do_test_resize('drive0', 'top')
44
+
45
+ def test_target_resize(self):
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
80
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/041.out
15
--- a/blockjob.c
82
+++ b/tests/qemu-iotests/041.out
16
+++ b/blockjob.c
83
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
84
-..............................................................................................
18
uint64_t perm, uint64_t shared_perm, Error **errp)
85
+........................................................................................................
19
{
86
----------------------------------------------------------------------
20
BdrvChild *c;
87
-Ran 94 tests
21
+ AioContext *ctx = bdrv_get_aio_context(bs);
88
+Ran 104 tests
22
bool need_context_ops;
89
23
GLOBAL_STATE_CODE();
90
OK
24
25
bdrv_ref(bs);
26
27
- need_context_ops = bdrv_get_aio_context(bs) != job->job.aio_context;
28
+ need_context_ops = ctx != job->job.aio_context;
29
30
- if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) {
31
- aio_context_release(job->job.aio_context);
32
+ if (need_context_ops) {
33
+ if (job->job.aio_context != qemu_get_aio_context()) {
34
+ aio_context_release(job->job.aio_context);
35
+ }
36
+ aio_context_acquire(ctx);
37
}
38
c = bdrv_root_attach_child(bs, name, &child_job, 0, perm, shared_perm, job,
39
errp);
40
- if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) {
41
- aio_context_acquire(job->job.aio_context);
42
+ if (need_context_ops) {
43
+ aio_context_release(ctx);
44
+ if (job->job.aio_context != qemu_get_aio_context()) {
45
+ aio_context_acquire(job->job.aio_context);
46
+ }
47
}
48
if (c == NULL) {
49
return -EPERM;
91
--
50
--
92
2.25.4
51
2.41.0
93
94
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
If the caller keeps the AioContext lock for a block node in an iothread,
2
polling in bdrv_graph_wrlock() deadlocks if the condition isn't
3
fulfilled immediately.
2
4
3
bdrv_format_default_perms() has one code path for backing files, and one
5
Now that all callers make sure to actually have the AioContext locked
4
for storage files. We want to pull them out into their own functions,
6
when they call bdrv_replace_child_noperm() like they should, we can
5
so make sure they are completely distinct before so the next patches
7
change bdrv_graph_wrlock() to take a BlockDriverState whose AioContext
6
will be a bit cleaner.
8
lock the caller holds (NULL if it doesn't) and unlock it temporarily
9
while polling.
7
10
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Message-ID: <20230605085711.21261-11-kwolf@redhat.com>
10
Message-Id: <20200513110544.176672-16-mreitz@redhat.com>
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
15
---
13
block.c | 19 +++++++++++++------
16
include/block/graph-lock.h | 6 ++++--
14
1 file changed, 13 insertions(+), 6 deletions(-)
17
block.c | 4 ++--
18
block/graph-lock.c | 23 ++++++++++++++++++++++-
19
3 files changed, 28 insertions(+), 5 deletions(-)
15
20
21
diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/include/block/graph-lock.h
24
+++ b/include/block/graph-lock.h
25
@@ -XXX,XX +XXX,XX @@ void unregister_aiocontext(AioContext *ctx);
26
* The wrlock can only be taken from the main loop, with BQL held, as only the
27
* main loop is allowed to modify the graph.
28
*
29
+ * If @bs is non-NULL, its AioContext is temporarily released.
30
+ *
31
* This function polls. Callers must not hold the lock of any AioContext other
32
- * than the current one.
33
+ * than the current one and the one of @bs.
34
*/
35
-void bdrv_graph_wrlock(void) TSA_ACQUIRE(graph_lock) TSA_NO_TSA;
36
+void bdrv_graph_wrlock(BlockDriverState *bs) TSA_ACQUIRE(graph_lock) TSA_NO_TSA;
37
38
/*
39
* bdrv_graph_wrunlock:
16
diff --git a/block.c b/block.c
40
diff --git a/block.c b/block.c
17
index XXXXXXX..XXXXXXX 100644
41
index XXXXXXX..XXXXXXX 100644
18
--- a/block.c
42
--- a/block.c
19
+++ b/block.c
43
+++ b/block.c
20
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
44
@@ -XXX,XX +XXX,XX @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
21
perm |= BLK_PERM_CONSISTENT_READ;
45
* Replaces the node that a BdrvChild points to without updating permissions.
22
}
46
*
23
shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
47
* If @new_bs is non-NULL, the parent of @child must already be drained through
48
- * @child.
49
+ * @child and the caller must hold the AioContext lock for @new_bs.
50
*/
51
static void bdrv_replace_child_noperm(BdrvChild *child,
52
BlockDriverState *new_bs)
53
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child,
54
}
55
56
/* TODO Pull this up into the callers to avoid polling here */
57
- bdrv_graph_wrlock();
58
+ bdrv_graph_wrlock(new_bs);
59
if (old_bs) {
60
if (child->klass->detach) {
61
child->klass->detach(child);
62
diff --git a/block/graph-lock.c b/block/graph-lock.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/block/graph-lock.c
65
+++ b/block/graph-lock.c
66
@@ -XXX,XX +XXX,XX @@ static uint32_t reader_count(void)
67
}
68
#endif
69
70
-void bdrv_graph_wrlock(void)
71
+void bdrv_graph_wrlock(BlockDriverState *bs)
72
{
73
+ AioContext *ctx = NULL;
24
+
74
+
25
+ if (bs->open_flags & BDRV_O_INACTIVE) {
75
GLOBAL_STATE_CODE();
26
+ shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
76
/*
77
* TODO Some callers hold an AioContext lock when this is called, which
78
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(void)
79
*/
80
#if 0
81
assert(!qatomic_read(&has_writer));
82
+#endif
83
+
84
+ /*
85
+ * Release only non-mainloop AioContext. The mainloop often relies on the
86
+ * BQL and doesn't lock the main AioContext before doing things.
87
+ */
88
+ if (bs) {
89
+ ctx = bdrv_get_aio_context(bs);
90
+ if (ctx != qemu_get_aio_context()) {
91
+ aio_context_release(ctx);
92
+ } else {
93
+ ctx = NULL;
27
+ }
94
+ }
95
+ }
96
97
+#if 0
98
/* Make sure that constantly arriving new I/O doesn't cause starvation */
99
bdrv_drain_all_begin_nopoll();
100
101
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(void)
102
103
bdrv_drain_all_end();
104
#endif
28
+
105
+
29
+ *nperm = perm;
106
+ if (ctx) {
30
+ *nshared = shared;
107
+ aio_context_acquire(bdrv_get_aio_context(bs));
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
+ }
108
+ }
52
}
109
}
53
110
54
uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
111
void bdrv_graph_wrunlock(void)
55
--
112
--
56
2.25.4
113
2.41.0
57
58
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
Now that bdrv_graph_wrlock() temporarily drops the AioContext lock that
2
its caller holds, it can poll without causing deadlocks. We can now
3
re-enable graph locking.
2
4
3
Implementations should decide the necessary permissions based on @role.
5
This reverts commit ad128dff0bf4b6f971d05eb4335a627883a19c1d.
4
6
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Message-Id: <20200513110544.176672-35-mreitz@redhat.com>
8
Message-ID: <20230605085711.21261-12-kwolf@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
11
---
10
include/block/block_int.h | 4 +---
12
block/graph-lock.c | 26 --------------------------
11
block.c | 39 +++++++++++++++----------------------
13
1 file changed, 26 deletions(-)
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
14
25
diff --git a/include/block/block_int.h b/include/block/block_int.h
15
diff --git a/block/graph-lock.c b/block/graph-lock.c
26
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
27
--- a/include/block/block_int.h
17
--- a/block/graph-lock.c
28
+++ b/include/block/block_int.h
18
+++ b/block/graph-lock.c
29
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
19
@@ -XXX,XX +XXX,XX @@ BdrvGraphLock graph_lock;
30
* @reopen_queue.
20
/* Protects the list of aiocontext and orphaned_reader_count */
31
*/
21
static QemuMutex aio_context_list_lock;
32
void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c,
22
33
- const BdrvChildClass *child_class,
23
-#if 0
34
BdrvChildRole role,
24
/* Written and read with atomic operations. */
35
BlockReopenQueue *reopen_queue,
25
static int has_writer;
36
uint64_t parent_perm, uint64_t parent_shared,
26
-#endif
37
@@ -XXX,XX +XXX,XX @@ bool bdrv_recurse_can_replace(BlockDriverState *bs,
27
38
* child_of_bds child class and set an appropriate BdrvChildRole.
28
/*
39
*/
29
* A reader coroutine could move from an AioContext to another.
40
void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c,
30
@@ -XXX,XX +XXX,XX @@ void unregister_aiocontext(AioContext *ctx)
41
- const BdrvChildClass *child_class, BdrvChildRole role,
31
g_free(ctx->bdrv_graph);
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
}
32
}
53
33
54
static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
34
-#if 0
55
- BdrvChild *c, const BdrvChildClass *child_class,
35
static uint32_t reader_count(void)
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
{
36
{
62
assert(bs->drv && bs->drv->bdrv_child_perm);
37
BdrvGraphRWlock *brdv_graph;
63
- bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue,
38
@@ -XXX,XX +XXX,XX @@ static uint32_t reader_count(void)
64
+ bs->drv->bdrv_child_perm(bs, c, role, reopen_queue,
39
assert((int32_t)rd >= 0);
65
parent_perm, parent_shared,
40
return rd;
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
}
41
}
105
42
-#endif
106
static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
43
107
- const BdrvChildClass *child_class,
44
void bdrv_graph_wrlock(BlockDriverState *bs)
108
BdrvChildRole role,
109
BlockReopenQueue *reopen_queue,
110
uint64_t perm, uint64_t shared,
111
uint64_t *nperm, uint64_t *nshared)
112
{
45
{
113
- assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW));
46
AioContext *ctx = NULL;
114
+ assert(role & BDRV_CHILD_COW);
47
48
GLOBAL_STATE_CODE();
49
- /*
50
- * TODO Some callers hold an AioContext lock when this is called, which
51
- * causes deadlocks. Reenable once the AioContext locking is cleaned up (or
52
- * AioContext locks are gone).
53
- */
54
-#if 0
55
assert(!qatomic_read(&has_writer));
56
-#endif
115
57
116
/*
58
/*
117
* We want consistent read from backing files if the parent needs it.
59
* Release only non-mainloop AioContext. The mainloop often relies on the
118
@@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
60
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(BlockDriverState *bs)
61
}
62
}
63
64
-#if 0
65
/* Make sure that constantly arriving new I/O doesn't cause starvation */
66
bdrv_drain_all_begin_nopoll();
67
68
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(BlockDriverState *bs)
69
} while (reader_count() >= 1);
70
71
bdrv_drain_all_end();
72
-#endif
73
74
if (ctx) {
75
aio_context_acquire(bdrv_get_aio_context(bs));
76
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(BlockDriverState *bs)
77
void bdrv_graph_wrunlock(void)
78
{
79
GLOBAL_STATE_CODE();
80
-#if 0
81
QEMU_LOCK_GUARD(&aio_context_list_lock);
82
assert(qatomic_read(&has_writer));
83
84
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrunlock(void)
85
86
/* Wake up all coroutine that are waiting to read the graph */
87
qemu_co_enter_all(&reader_queue, &aio_context_list_lock);
88
-#endif
119
}
89
}
120
90
121
static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
91
void coroutine_fn bdrv_graph_co_rdlock(void)
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
{
92
{
128
int flags;
93
- /* TODO Reenable when wrlock is reenabled */
129
94
-#if 0
130
- assert(child_class == &child_of_bds &&
95
BdrvGraphRWlock *bdrv_graph;
131
- (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)));
96
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
132
+ assert(role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA));
97
133
98
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_graph_co_rdlock(void)
134
flags = bdrv_reopen_get_flags(reopen_queue, bs);
99
qemu_co_queue_wait(&reader_queue, &aio_context_list_lock);
135
100
}
136
@@ -XXX,XX +XXX,XX @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
101
}
137
* Apart from the modifications below, the same permissions are
102
-#endif
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
}
103
}
147
104
148
void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c,
105
void coroutine_fn bdrv_graph_co_rdunlock(void)
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
{
106
{
155
- assert(child_class == &child_of_bds);
107
-#if 0
156
-
108
BdrvGraphRWlock *bdrv_graph;
157
if (role & BDRV_CHILD_FILTERED) {
109
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
158
assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA |
110
159
BDRV_CHILD_COW)));
111
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_graph_co_rdunlock(void)
160
- bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue,
112
if (qatomic_read(&has_writer)) {
161
+ bdrv_filter_default_perms(bs, c, role, reopen_queue,
113
aio_wait_kick();
162
perm, shared, nperm, nshared);
114
}
163
} else if (role & BDRV_CHILD_COW) {
115
-#endif
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
}
116
}
207
117
208
static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,
118
void bdrv_graph_rdlock_main_loop(void)
209
- const BdrvChildClass *child_class,
119
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_rdunlock_main_loop(void)
210
BdrvChildRole role,
120
void assert_bdrv_graph_readable(void)
211
BlockReopenQueue *reopen_queue,
121
{
212
uint64_t perm, uint64_t shared,
122
/* reader_count() is slow due to aio_context_list_lock lock contention */
213
@@ -XXX,XX +XXX,XX @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,
123
- /* TODO Reenable when wrlock is reenabled */
214
*nperm = BLK_PERM_WRITE;
124
-#if 0
215
} else {
125
#ifdef CONFIG_DEBUG_GRAPH_LOCK
216
/* Source child */
126
assert(qemu_in_main_thread() || reader_count());
217
- bdrv_default_perms(bs, c, child_class, role, reopen_queue,
127
#endif
218
+ bdrv_default_perms(bs, c, role, reopen_queue,
128
-#endif
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
}
129
}
228
130
229
static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c,
131
void assert_bdrv_graph_writable(void)
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
{
132
{
236
BDRVBlkdebugState *s = bs->opaque;
133
assert(qemu_in_main_thread());
237
134
- /* TODO Reenable when wrlock is reenabled */
238
- bdrv_default_perms(bs, c, child_class, role, reopen_queue,
135
-#if 0
239
+ bdrv_default_perms(bs, c, role, reopen_queue,
136
assert(qatomic_read(&has_writer));
240
perm, shared, nperm, nshared);
137
-#endif
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
}
138
}
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
--
139
--
396
2.25.4
140
2.41.0
397
398
diff view generated by jsdifflib
1
This patch makes the raw image the same size as the file in a different
1
From: Paolo Bonzini <pbonzini@redhat.com>
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
2
5
We check only that the first 512 bytes are zeroed (instead of 64k)
3
raw_co_getlength is called by handle_aiocb_write_zeroes, which is not a coroutine
6
because some image formats create image files that are smaller than 64k,
4
function. This is harmless because raw_co_getlength does not actually suspend,
7
so trying to read 64k would result in I/O errors. Apart from this, 512
5
but in the interest of clarity make it a non-coroutine_fn that is just wrapped
8
is more appropriate anyway because the raw format driver protects
6
by the coroutine_fn raw_co_getlength. Likewise, check_cache_dropped was only
9
specifically the first 512 bytes.
7
a coroutine_fn because it called raw_co_getlength, so it can be made non-coroutine
8
as well.
10
9
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12
Message-Id: <20200511135825.219437-2-kwolf@redhat.com>
11
Message-ID: <20230601115145.196465-2-pbonzini@redhat.com>
13
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
14
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
14
---
17
tests/qemu-iotests/109 | 10 ++---
15
block/file-posix.c | 29 +++++++++++++++++------------
18
tests/qemu-iotests/109.out | 74 +++++++++++++-------------------
16
1 file changed, 17 insertions(+), 12 deletions(-)
19
tests/qemu-iotests/common.filter | 5 +++
20
3 files changed, 41 insertions(+), 48 deletions(-)
21
17
22
diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109
18
diff --git a/block/file-posix.c b/block/file-posix.c
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
19
index XXXXXXX..XXXXXXX 100644
70
--- a/tests/qemu-iotests/109.out
20
--- a/block/file-posix.c
71
+++ b/tests/qemu-iotests/109.out
21
+++ b/block/file-posix.c
72
@@ -XXX,XX +XXX,XX @@ QA output created by 109
22
@@ -XXX,XX +XXX,XX @@ static int fd_open(BlockDriverState *bs)
73
23
return -EIO;
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
}
24
}
359
25
360
+_filter_img_create_size()
26
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs);
27
+static int64_t raw_getlength(BlockDriverState *bs);
28
29
typedef struct RawPosixAIOData {
30
BlockDriverState *bs;
31
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_write_zeroes(void *opaque)
32
#ifdef CONFIG_FALLOCATE
33
/* Last resort: we are trying to extend the file with zeroed data. This
34
* can be done via fallocate(fd, 0) */
35
- len = raw_co_getlength(aiocb->bs);
36
+ len = raw_getlength(aiocb->bs);
37
if (s->has_fallocate && len >= 0 && aiocb->aio_offset >= len) {
38
int ret = do_fallocate(s->fd, 0, aiocb->aio_offset, aiocb->aio_nbytes);
39
if (ret == 0 || ret != -ENOTSUP) {
40
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
41
}
42
43
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
44
- int64_t cur_length = raw_co_getlength(bs);
45
+ int64_t cur_length = raw_getlength(bs);
46
47
if (offset != cur_length && exact) {
48
error_setg(errp, "Cannot resize device files");
49
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
50
}
51
52
#ifdef __OpenBSD__
53
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
54
+static int64_t raw_getlength(BlockDriverState *bs)
55
{
56
BDRVRawState *s = bs->opaque;
57
int fd = s->fd;
58
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
59
return st.st_size;
60
}
61
#elif defined(__NetBSD__)
62
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
63
+static int64_t raw_getlength(BlockDriverState *bs)
64
{
65
BDRVRawState *s = bs->opaque;
66
int fd = s->fd;
67
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
68
return st.st_size;
69
}
70
#elif defined(__sun__)
71
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
72
+static int64_t raw_getlength(BlockDriverState *bs)
73
{
74
BDRVRawState *s = bs->opaque;
75
struct dk_minfo minfo;
76
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
77
return size;
78
}
79
#elif defined(CONFIG_BSD)
80
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
81
+static int64_t raw_getlength(BlockDriverState *bs)
82
{
83
BDRVRawState *s = bs->opaque;
84
int fd = s->fd;
85
@@ -XXX,XX +XXX,XX @@ again:
86
return size;
87
}
88
#else
89
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
90
+static int64_t raw_getlength(BlockDriverState *bs)
91
{
92
BDRVRawState *s = bs->opaque;
93
int ret;
94
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
95
}
96
#endif
97
98
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
361
+{
99
+{
362
+ $SED -e "s# size=[0-9]\\+# size=SIZE#g"
100
+ return raw_getlength(bs);
363
+}
101
+}
364
+
102
+
365
_filter_img_info()
103
static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverState *bs)
366
{
104
{
367
if [[ "$1" == "--format-specific" ]]; then
105
struct stat st;
106
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs,
107
* round up if necessary.
108
*/
109
if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) {
110
- int64_t file_length = raw_co_getlength(bs);
111
+ int64_t file_length = raw_getlength(bs);
112
if (file_length > 0) {
113
/* Ignore errors, this is just a safeguard */
114
assert(hole == file_length);
115
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs,
116
117
#if defined(__linux__)
118
/* Verify that the file is not in the page cache */
119
-static void coroutine_fn check_cache_dropped(BlockDriverState *bs, Error **errp)
120
+static void check_cache_dropped(BlockDriverState *bs, Error **errp)
121
{
122
const size_t window_size = 128 * 1024 * 1024;
123
BDRVRawState *s = bs->opaque;
124
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn check_cache_dropped(BlockDriverState *bs, Error **errp)
125
page_size = sysconf(_SC_PAGESIZE);
126
vec = g_malloc(DIV_ROUND_UP(window_size, page_size));
127
128
- end = raw_co_getlength(bs);
129
+ end = raw_getlength(bs);
130
131
for (offset = 0; offset < end; offset += window_size) {
132
void *new_window;
133
@@ -XXX,XX +XXX,XX @@ static int cdrom_reopen(BlockDriverState *bs)
134
135
static bool coroutine_fn cdrom_co_is_inserted(BlockDriverState *bs)
136
{
137
- return raw_co_getlength(bs) > 0;
138
+ return raw_getlength(bs) > 0;
139
}
140
141
static void coroutine_fn cdrom_co_eject(BlockDriverState *bs, bool eject_flag)
368
--
142
--
369
2.25.4
143
2.41.0
370
371
diff view generated by jsdifflib
Deleted 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.
5
1
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
Deleted patch
1
If the target is shorter than the source, mirror would copy data until
2
it reaches the end of the target and then fail with an I/O error when
3
trying to write past the end.
4
1
5
If the target is longer than the source, the mirror job would complete
6
successfully, but the target wouldn't actually be an accurate copy of
7
the source image (it would contain some additional garbage at the end).
8
9
Fix this by checking that both images have the same size when the job
10
starts.
11
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Reviewed-by: Eric Blake <eblake@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>
18
---
19
block/mirror.c | 21 ++++++++++++---------
20
1 file changed, 12 insertions(+), 9 deletions(-)
21
22
diff --git a/block/mirror.c b/block/mirror.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/mirror.c
25
+++ b/block/mirror.c
26
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
27
BlockDriverState *target_bs = blk_bs(s->target);
28
bool need_drain = true;
29
int64_t length;
30
+ int64_t target_length;
31
BlockDriverInfo bdi;
32
char backing_filename[2]; /* we only need 2 characters because we are only
33
checking for a NULL string */
34
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
35
goto immediate_exit;
36
}
37
38
+ target_length = blk_getlength(s->target);
39
+ if (target_length < 0) {
40
+ ret = target_length;
41
+ goto immediate_exit;
42
+ }
43
+
44
/* Active commit must resize the base image if its size differs from the
45
* active layer. */
46
if (s->base == blk_bs(s->target)) {
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;
61
}
62
}
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) {
70
--
71
2.25.4
72
73
diff view generated by jsdifflib
Deleted patch
1
From: Lukas Straub <lukasstraub2@web.de>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
bdrv_commit() already has a BlockBackend pointing to the BDS that we
4
want to empty, it just has the wrong permissions.
5
6
qemu-img commit has no BlockBackend pointing to the old backing file
7
yet, but introducing one is simple.
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]
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
---
18
block/commit.c | 16 +++++++++-------
19
qemu-img.c | 19 ++++++++++++++-----
20
tests/qemu-iotests/098.out | 8 ++++----
21
3 files changed, 27 insertions(+), 16 deletions(-)
22
23
diff --git a/block/commit.c b/block/commit.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/block/commit.c
26
+++ b/block/commit.c
27
@@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs)
28
}
29
30
ctx = bdrv_get_aio_context(bs);
31
- src = blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL);
32
+ /* WRITE_UNCHANGED is required for bdrv_make_empty() */
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);
55
+
56
/*
57
* Make sure all data we wrote to the backing device is actually
58
* stable on disk.
59
diff --git a/qemu-img.c b/qemu-img.c
60
index XXXXXXX..XXXXXXX 100644
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;
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;
74
+
75
+ old_backing_blk = blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_ALL,
76
+ &local_err);
77
+ if (!old_backing_blk) {
78
+ goto unref_backing;
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
129
--
130
2.25.4
131
132
diff view generated by jsdifflib
Deleted 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.
4
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Commonly, they need to pass the BDRV_CHILD_IMAGE set as the
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
BdrvChildRole; but there are exceptions for drivers with external data
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
files (qcow2 and vmdk).
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
6
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Message-ID: <20230601115145.196465-3-pbonzini@redhat.com>
9
Message-Id: <20200513110544.176672-26-mreitz@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
11
---
12
block/bochs.c | 4 ++--
12
block/qed-check.c | 5 +++--
13
block/cloop.c | 4 ++--
13
block/qed.c | 7 ++++---
14
block/crypto.c | 4 ++--
14
2 files changed, 7 insertions(+), 5 deletions(-)
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
15
26
diff --git a/block/bochs.c b/block/bochs.c
16
diff --git a/block/qed-check.c b/block/qed-check.c
27
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
28
--- a/block/bochs.c
18
--- a/block/qed-check.c
29
+++ b/block/bochs.c
19
+++ b/block/qed-check.c
30
@@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
20
@@ -XXX,XX +XXX,XX @@ static void qed_check_for_leaks(QEDCheck *check)
31
return ret;
21
/**
22
* Mark an image clean once it passes check or has been repaired
23
*/
24
-static void qed_check_mark_clean(BDRVQEDState *s, BdrvCheckResult *result)
25
+static void coroutine_fn GRAPH_RDLOCK
26
+qed_check_mark_clean(BDRVQEDState *s, BdrvCheckResult *result)
27
{
28
/* Skip if there were unfixable corruptions or I/O errors */
29
if (result->corruptions > 0 || result->check_errors > 0) {
30
@@ -XXX,XX +XXX,XX @@ static void qed_check_mark_clean(BDRVQEDState *s, BdrvCheckResult *result)
32
}
31
}
33
32
34
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
33
/* Ensure fixes reach storage before clearing check bit */
35
- false, errp);
34
- bdrv_flush(s->bs);
36
+ bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
35
+ bdrv_co_flush(s->bs);
37
+ BDRV_CHILD_IMAGE, false, errp);
36
38
if (!bs->file) {
37
s->header.features &= ~QED_F_NEED_CHECK;
39
return -EINVAL;
38
qed_write_header_sync(s);
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
39
diff --git a/block/qed.c b/block/qed.c
168
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
169
--- a/block/qed.c
41
--- a/block/qed.c
170
+++ b/block/qed.c
42
+++ b/block/qed.c
171
@@ -XXX,XX +XXX,XX @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
43
@@ -XXX,XX +XXX,XX @@ static bool qed_is_image_size_valid(uint64_t image_size, uint32_t cluster_size,
172
.ret = -EINPROGRESS
44
*
173
};
45
* The string is NUL-terminated.
174
46
*/
175
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
47
-static int qed_read_string(BdrvChild *file, uint64_t offset, size_t n,
176
- false, errp);
48
- char *buf, size_t buflen)
177
+ bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
49
+static int coroutine_fn GRAPH_RDLOCK
178
+ BDRV_CHILD_IMAGE, false, errp);
50
+qed_read_string(BdrvChild *file, uint64_t offset,
179
if (!bs->file) {
51
+ size_t n, char *buf, size_t buflen)
52
{
53
int ret;
54
if (n >= buflen) {
180
return -EINVAL;
55
return -EINVAL;
181
}
56
}
182
diff --git a/block/vdi.c b/block/vdi.c
57
- ret = bdrv_pread(file, offset, n, buf, 0);
183
index XXXXXXX..XXXXXXX 100644
58
+ ret = bdrv_co_pread(file, offset, n, buf, 0);
184
--- a/block/vdi.c
59
if (ret < 0) {
185
+++ b/block/vdi.c
60
return ret;
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
}
61
}
280
--
62
--
281
2.25.4
63
2.41.0
282
283
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
Message-Id: <20200513110544.176672-25-mreitz@redhat.com>
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
Reviewed-by: Eric Blake <eblake@redhat.com>
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-4-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
11
---
8
include/block/block_int.h | 1 -
12
block/vpc.c | 52 ++++++++++++++++++++++++++--------------------------
9
block.c | 60 ++-------------------------------------
13
1 file changed, 26 insertions(+), 26 deletions(-)
10
2 files changed, 3 insertions(+), 58 deletions(-)
11
14
12
diff --git a/include/block/block_int.h b/include/block/block_int.h
15
diff --git a/block/vpc.c b/block/vpc.c
13
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
14
--- a/include/block/block_int.h
17
--- a/block/vpc.c
15
+++ b/include/block/block_int.h
18
+++ b/block/vpc.c
16
@@ -XXX,XX +XXX,XX @@ struct BdrvChildClass {
19
@@ -XXX,XX +XXX,XX @@ static int vpc_reopen_prepare(BDRVReopenState *state,
17
20
* operation (the block bitmaps is updated then), 0 otherwise.
18
extern const BdrvChildClass child_of_bds;
21
* If write is true then err must not be NULL.
19
extern const BdrvChildClass child_file;
22
*/
20
-extern const BdrvChildClass child_backing;
23
-static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
21
24
- bool write, int *err)
22
struct BdrvChild {
25
+static int64_t coroutine_fn GRAPH_RDLOCK
23
BlockDriverState *bs;
26
+get_image_offset(BlockDriverState *bs, uint64_t offset, bool write, int *err)
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
{
27
{
43
BlockDriverState *parent = c->opaque;
28
BDRVVPCState *s = bs->opaque;
44
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c)
29
uint64_t bitmap_offset, block_offset;
45
parent->backing_blocker = NULL;
30
@@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
46
}
31
47
32
s->last_bitmap_offset = bitmap_offset;
48
-/* XXX: Will be removed along with child_backing */
33
memset(bitmap, 0xff, s->bitmap_size);
49
-static void bdrv_child_cb_detach_backing(BdrvChild *c)
34
- r = bdrv_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap,
50
-{
35
- 0);
51
- if (!(c->role & BDRV_CHILD_COW)) {
36
+ r = bdrv_co_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap, 0);
52
- bdrv_backing_detach(c);
37
if (r < 0) {
53
- }
38
*err = r;
54
- bdrv_child_cb_detach(c);
39
return -2;
55
-}
40
@@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
56
-
41
*
57
-/*
42
* Returns 0 on success and < 0 on error
58
- * Returns the options and flags that bs->backing should get, based on the
43
*/
59
- * given options and flags for the parent BDS
44
-static int rewrite_footer(BlockDriverState *bs)
60
- */
45
+static int coroutine_fn GRAPH_RDLOCK rewrite_footer(BlockDriverState *bs)
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
{
46
{
73
@@ -XXX,XX +XXX,XX @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
47
int ret;
48
BDRVVPCState *s = bs->opaque;
49
int64_t offset = s->free_data_block_offset;
50
51
- ret = bdrv_pwrite_sync(bs->file, offset, sizeof(s->footer), &s->footer, 0);
52
+ ret = bdrv_co_pwrite_sync(bs->file, offset, sizeof(s->footer), &s->footer, 0);
53
if (ret < 0)
54
return ret;
55
56
@@ -XXX,XX +XXX,XX @@ static int rewrite_footer(BlockDriverState *bs)
57
*
58
* Returns the sectors' offset in the image file on success and < 0 on error
59
*/
60
-static int64_t alloc_block(BlockDriverState *bs, int64_t offset)
61
+static int64_t coroutine_fn GRAPH_RDLOCK
62
+alloc_block(BlockDriverState *bs, int64_t offset)
63
{
64
BDRVVPCState *s = bs->opaque;
65
int64_t bat_offset;
66
@@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset)
67
68
/* Initialize the block's bitmap */
69
memset(bitmap, 0xff, s->bitmap_size);
70
- ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset,
71
- s->bitmap_size, bitmap, 0);
72
+ ret = bdrv_co_pwrite_sync(bs->file, s->free_data_block_offset,
73
+ s->bitmap_size, bitmap, 0);
74
if (ret < 0) {
75
return ret;
76
}
77
@@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset)
78
/* Write BAT entry to disk */
79
bat_offset = s->bat_offset + (4 * index);
80
bat_value = cpu_to_be32(s->pagetable[index]);
81
- ret = bdrv_pwrite_sync(bs->file, bat_offset, 4, &bat_value, 0);
82
+ ret = bdrv_co_pwrite_sync(bs->file, bat_offset, 4, &bat_value, 0);
83
if (ret < 0)
84
goto fail;
85
86
@@ -XXX,XX +XXX,XX @@ fail:
74
return ret;
87
return ret;
75
}
88
}
76
89
77
-const BdrvChildClass child_backing = {
90
-static int coroutine_fn vpc_co_block_status(BlockDriverState *bs,
78
- .parent_is_bds = true,
91
- bool want_zero,
79
- .get_parent_desc = bdrv_child_get_parent_desc,
92
- int64_t offset, int64_t bytes,
80
- .attach = bdrv_child_cb_attach_backing,
93
- int64_t *pnum, int64_t *map,
81
- .detach = bdrv_child_cb_detach_backing,
94
- BlockDriverState **file)
82
- .inherit_options = bdrv_backing_options,
95
+static int coroutine_fn GRAPH_RDLOCK
83
- .drained_begin = bdrv_child_cb_drained_begin,
96
+vpc_co_block_status(BlockDriverState *bs, bool want_zero,
84
- .drained_poll = bdrv_child_cb_drained_poll,
97
+ int64_t offset, int64_t bytes,
85
- .drained_end = bdrv_child_cb_drained_end,
98
+ int64_t *pnum, int64_t *map,
86
- .inactivate = bdrv_child_cb_inactivate,
99
+ BlockDriverState **file)
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
{
100
{
99
- assert(child_class == &child_backing ||
101
BDRVVPCState *s = bs->opaque;
100
- (child_class == &child_of_bds && (role & BDRV_CHILD_COW)));
102
int64_t image_offset;
101
+ assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW));
103
@@ -XXX,XX +XXX,XX @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls,
102
104
return 0;
103
/*
105
}
104
* We want consistent read from backing files if the parent needs it.
106
105
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
107
-static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
106
uint64_t perm, uint64_t shared,
108
- int64_t total_sectors)
107
uint64_t *nperm, uint64_t *nshared)
109
+static int coroutine_fn create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
110
+ int64_t total_sectors)
108
{
111
{
109
- bool backing = (child_class == &child_backing);
112
VHDDynDiskHeader dyndisk_header;
110
-
113
uint8_t bat_sector[512];
111
if (child_class == &child_of_bds) {
114
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
112
bdrv_default_perms(bs, c, child_class, role, reopen_queue,
115
block_size = 0x200000;
113
perm, shared, nperm, nshared);
116
num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512);
114
return;
117
118
- ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
119
+ ret = blk_co_pwrite(blk, offset, sizeof(*footer), footer, 0);
120
if (ret < 0) {
121
goto fail;
115
}
122
}
116
123
117
- assert(child_class == &child_backing || child_class == &child_file);
124
offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
118
+ assert(child_class == &child_file);
125
- ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
119
126
+ ret = blk_co_pwrite(blk, offset, sizeof(*footer), footer, 0);
120
- if (!backing) {
127
if (ret < 0) {
121
- bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue,
128
goto fail;
122
- perm, shared, nperm, nshared);
129
}
123
- } else {
130
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
124
- bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue,
131
125
+ bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue,
132
memset(bat_sector, 0xFF, 512);
126
perm, shared, nperm, nshared);
133
for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) {
127
- }
134
- ret = blk_pwrite(blk, offset, 512, bat_sector, 0);
135
+ ret = blk_co_pwrite(blk, offset, 512, bat_sector, 0);
136
if (ret < 0) {
137
goto fail;
138
}
139
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
140
/* Write the header */
141
offset = 512;
142
143
- ret = blk_pwrite(blk, offset, sizeof(dyndisk_header), &dyndisk_header, 0);
144
+ ret = blk_co_pwrite(blk, offset, sizeof(dyndisk_header), &dyndisk_header, 0);
145
if (ret < 0) {
146
goto fail;
147
}
148
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
149
return ret;
128
}
150
}
129
151
130
void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c,
152
-static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer,
153
- int64_t total_size, Error **errp)
154
+static int coroutine_fn create_fixed_disk(BlockBackend *blk, VHDFooter *footer,
155
+ int64_t total_size, Error **errp)
156
{
157
int ret;
158
159
/* Add footer to total size */
160
total_size += sizeof(*footer);
161
162
- ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp);
163
+ ret = blk_co_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp);
164
if (ret < 0) {
165
return ret;
166
}
167
168
- ret = blk_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
169
- footer, 0);
170
+ ret = blk_co_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
171
+ footer, 0);
172
if (ret < 0) {
173
error_setg_errno(errp, -ret, "Unable to write VHD header");
174
return ret;
131
--
175
--
132
2.25.4
176
2.41.0
133
134
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Split raw_read_options() into one function that actually just reads the
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
options, and another that applies them. This will allow us to detect
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
whether the user has specified any options before attaching the file
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
child (so we can decide on its role based on the options).
7
6
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Message-ID: <20230601115145.196465-5-pbonzini@redhat.com>
10
Message-Id: <20200513110544.176672-21-mreitz@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
11
---
13
block/raw-format.c | 110 ++++++++++++++++++++++++++-------------------
12
block/bochs.c | 7 ++++---
14
1 file changed, 65 insertions(+), 45 deletions(-)
13
1 file changed, 4 insertions(+), 3 deletions(-)
15
14
16
diff --git a/block/raw-format.c b/block/raw-format.c
15
diff --git a/block/bochs.c b/block/bochs.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/block/raw-format.c
17
--- a/block/bochs.c
19
+++ b/block/raw-format.c
18
+++ b/block/bochs.c
20
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_create_opts = {
19
@@ -XXX,XX +XXX,XX @@ static void bochs_refresh_limits(BlockDriverState *bs, Error **errp)
21
}
20
bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
22
};
21
}
23
22
24
-static int raw_read_options(QDict *options, BlockDriverState *bs,
23
-static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
25
- BDRVRawState *s, Error **errp)
24
+static int64_t coroutine_fn GRAPH_RDLOCK
26
+static int raw_read_options(QDict *options, uint64_t *offset, bool *has_size,
25
+seek_to_sector(BlockDriverState *bs, int64_t sector_num)
27
+ uint64_t *size, Error **errp)
28
{
26
{
29
Error *local_err = NULL;
27
BDRVBochsState *s = bs->opaque;
30
QemuOpts *opts = NULL;
28
uint64_t offset = sector_num * 512;
31
- int64_t real_size = 0;
29
@@ -XXX,XX +XXX,XX @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
32
int ret;
30
(s->extent_blocks + s->bitmap_blocks));
33
31
34
- real_size = bdrv_getlength(bs->file->bs);
32
/* read in bitmap for current extent */
35
- if (real_size < 0) {
33
- ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), 1,
36
- error_setg_errno(errp, -real_size, "Could not get image size");
34
- &bitmap_entry, 0);
37
- return real_size;
35
+ ret = bdrv_co_pread(bs->file, bitmap_offset + (extent_offset / 8), 1,
38
- }
36
+ &bitmap_entry, 0);
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) {
37
if (ret < 0) {
186
return ret;
38
return ret;
187
}
39
}
188
--
40
--
189
2.25.4
41
2.41.0
190
191
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Replace child_file by child_of_bds in all remaining places (excluding
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
tests).
4
and they can suspend. Because this function operates on a BlockBackend, mark it
5
GRAPH_UNLOCKED.
5
6
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Message-Id: <20200513110544.176672-28-mreitz@redhat.com>
8
Message-ID: <20230601115145.196465-6-pbonzini@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
---
11
block.c | 3 ++-
12
block.c | 11 ++++++-----
12
block/backup-top.c | 4 ++--
13
1 file changed, 6 insertions(+), 5 deletions(-)
13
block/blklogwrites.c | 4 ++--
14
block/raw-format.c | 15 +++++++++++++--
15
4 files changed, 19 insertions(+), 7 deletions(-)
16
14
17
diff --git a/block.c b/block.c
15
diff --git a/block.c b/block.c
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
19
--- a/block.c
17
--- a/block.c
20
+++ b/block.c
18
+++ b/block.c
21
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
19
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
22
BlockDriverState *file_bs;
20
* On success, return @blk's actual length.
23
21
* Otherwise, return -errno.
24
file_bs = bdrv_open_child_bs(filename, options, "file", bs,
22
*/
25
- &child_file, 0, true, &local_err);
23
-static int64_t create_file_fallback_truncate(BlockBackend *blk,
26
+ &child_of_bds, BDRV_CHILD_IMAGE,
24
- int64_t minimum_size, Error **errp)
27
+ true, &local_err);
25
+static int64_t coroutine_fn GRAPH_UNLOCKED
28
if (local_err) {
26
+create_file_fallback_truncate(BlockBackend *blk, int64_t minimum_size,
29
goto fail;
27
+ Error **errp)
30
}
28
{
31
diff --git a/block/backup-top.c b/block/backup-top.c
29
Error *local_err = NULL;
32
index XXXXXXX..XXXXXXX 100644
30
int64_t size;
33
--- a/block/backup-top.c
31
@@ -XXX,XX +XXX,XX @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
34
+++ b/block/backup-top.c
32
35
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
33
GLOBAL_STATE_CODE();
36
source->supported_zero_flags);
34
37
35
- ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
38
bdrv_ref(target);
36
- &local_err);
39
- state->target = bdrv_attach_child(top, target, "target", &child_file, 0,
37
+ ret = blk_co_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
40
- errp);
38
+ &local_err);
41
+ state->target = bdrv_attach_child(top, target, "target", &child_of_bds,
39
if (ret < 0 && ret != -ENOTSUP) {
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);
40
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;
41
return ret;
75
}
42
}
76
43
77
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
44
- size = blk_getlength(blk);
78
- false, errp);
45
+ size = blk_co_getlength(blk);
79
+ /*
46
if (size < 0) {
80
+ * Without offset and a size limit, this driver behaves very much
47
error_free(local_err);
81
+ * like a filter. With any such limit, it does not.
48
error_setg_errno(errp, -size,
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
--
49
--
95
2.25.4
50
2.41.0
96
97
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
Reviewed-by: Eric Blake <eblake@redhat.com>
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
Message-Id: <20200513110544.176672-29-mreitz@redhat.com>
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-7-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
11
---
8
tests/test-bdrv-drain.c | 29 +++++++++++++++++------------
12
block/cloop.c | 9 +++++----
9
tests/test-bdrv-graph-mod.c | 6 ++++--
13
1 file changed, 5 insertions(+), 4 deletions(-)
10
2 files changed, 21 insertions(+), 14 deletions(-)
11
14
12
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
15
diff --git a/block/cloop.c b/block/cloop.c
13
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
14
--- a/tests/test-bdrv-drain.c
17
--- a/block/cloop.c
15
+++ b/tests/test-bdrv-drain.c
18
+++ b/block/cloop.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c,
19
@@ -XXX,XX +XXX,XX @@ static void cloop_refresh_limits(BlockDriverState *bs, Error **errp)
17
* detach_by_driver_cb_parent as one of them.
20
bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
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
}
21
}
64
22
65
static void detach_by_parent_aio_cb(void *opaque, int ret)
23
-static inline int cloop_read_block(BlockDriverState *bs, int block_num)
66
@@ -XXX,XX +XXX,XX @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child)
24
+static int coroutine_fn GRAPH_RDLOCK
25
+cloop_read_block(BlockDriverState *bs, int block_num)
67
{
26
{
68
aio_bh_schedule_oneshot(qemu_get_current_aio_context(),
27
BDRVCloopState *s = bs->opaque;
69
detach_indirect_bh, &detach_by_parent_data);
28
70
- child_file.drained_begin(child);
29
@@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num)
71
+ child_of_bds.drained_begin(child);
30
int ret;
31
uint32_t bytes = s->offsets[block_num + 1] - s->offsets[block_num];
32
33
- ret = bdrv_pread(bs->file, s->offsets[block_num], bytes,
34
- s->compressed_block, 0);
35
+ ret = bdrv_co_pread(bs->file, s->offsets[block_num], bytes,
36
+ s->compressed_block, 0);
37
if (ret < 0) {
38
return -1;
39
}
40
@@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num)
41
return 0;
72
}
42
}
73
43
74
static BdrvChildClass detach_by_driver_cb_class;
44
-static int coroutine_fn
75
@@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb)
45
+static int coroutine_fn GRAPH_RDLOCK
76
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0);
46
cloop_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
77
47
QEMUIOVector *qiov, BdrvRequestFlags flags)
78
if (!by_parent_cb) {
48
{
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
--
49
--
129
2.25.4
50
2.41.0
130
131
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
bdrv_default_perms() can decide which permission profile to use based on
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
the BdrvChildRole, so block drivers do not need to select it explicitly.
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
5
6
6
The blkverify driver now no longer shares the WRITE permission for the
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
image to verify. We thus have to adjust two places in
8
Message-ID: <20230601115145.196465-8-pbonzini@redhat.com>
8
test-block-iothread not to take it. (Note that in theory, blkverify
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
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>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
11
---
19
block/backup-top.c | 4 ++--
12
block/dmg.c | 21 +++++++++++----------
20
block/blkdebug.c | 4 ++--
13
1 file changed, 11 insertions(+), 10 deletions(-)
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
14
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
15
diff --git a/block/dmg.c b/block/dmg.c
160
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
161
--- a/block/dmg.c
17
--- a/block/dmg.c
162
+++ b/block/dmg.c
18
+++ b/block/dmg.c
163
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_dmg = {
19
@@ -XXX,XX +XXX,XX @@ err:
164
.bdrv_probe = dmg_probe,
20
return s->n_chunks; /* error */
165
.bdrv_open = dmg_open,
21
}
166
.bdrv_refresh_limits = dmg_refresh_limits,
22
167
- .bdrv_child_perm = bdrv_format_default_perms,
23
-static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
168
+ .bdrv_child_perm = bdrv_default_perms,
24
+static int coroutine_fn GRAPH_RDLOCK
169
.bdrv_co_preadv = dmg_co_preadv,
25
+dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
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
{
26
{
322
/*
27
BDRVDMGState *s = bs->opaque;
323
- * bdrv_format_default_perms() accepts only these two, so disguise
28
324
+ * bdrv_default_perms() accepts only these two, so disguise
29
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
325
* detach_by_driver_cb_parent as one of them.
30
case UDZO: { /* zlib compressed */
326
*/
31
/* we need to buffer, because only the chunk as whole can be
327
if (child_class != &child_file && child_class != &child_of_bds) {
32
* inflated. */
328
child_class = &child_of_bds;
33
- ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
329
}
34
- s->compressed_chunk, 0);
330
35
+ ret = bdrv_co_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
331
- bdrv_format_default_perms(bs, c, child_class, role, reopen_queue,
36
+ s->compressed_chunk, 0);
332
- perm, shared, nperm, nshared);
37
if (ret < 0) {
333
+ bdrv_default_perms(bs, c, child_class, role, reopen_queue,
38
return -1;
334
+ perm, shared, nperm, nshared);
39
}
40
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
41
}
42
/* we need to buffer, because only the chunk as whole can be
43
* inflated. */
44
- ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
45
- s->compressed_chunk, 0);
46
+ ret = bdrv_co_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
47
+ s->compressed_chunk, 0);
48
if (ret < 0) {
49
return -1;
50
}
51
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
52
}
53
/* we need to buffer, because only the chunk as whole can be
54
* inflated. */
55
- ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
56
- s->compressed_chunk, 0);
57
+ ret = bdrv_co_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
58
+ s->compressed_chunk, 0);
59
if (ret < 0) {
60
return -1;
61
}
62
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
63
}
64
break;
65
case UDRW: /* copy */
66
- ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
67
- s->uncompressed_chunk, 0);
68
+ ret = bdrv_co_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
69
+ s->uncompressed_chunk, 0);
70
if (ret < 0) {
71
return -1;
72
}
73
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
74
return 0;
335
}
75
}
336
76
337
static int bdrv_test_change_backing_file(BlockDriverState *bs,
77
-static int coroutine_fn
338
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test_top_driver = {
78
+static int coroutine_fn GRAPH_RDLOCK
339
.bdrv_close = bdrv_test_top_close,
79
dmg_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
340
.bdrv_co_preadv = bdrv_test_top_co_preadv,
80
QEMUIOVector *qiov, BdrvRequestFlags flags)
341
81
{
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
--
82
--
405
2.25.4
83
2.41.0
406
407
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
For now, all callers pass 0 and no callee evaluates this value. Later
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
patches will change both.
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
5
6
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Message-ID: <20230601115145.196465-9-pbonzini@redhat.com>
8
Message-Id: <20200513110544.176672-7-mreitz@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
---
11
include/block/block_int.h | 5 ++++-
12
block/vmdk.c | 27 ++++++++++++++-------------
12
block.c | 22 ++++++++++++----------
13
1 file changed, 14 insertions(+), 13 deletions(-)
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
14
26
diff --git a/include/block/block_int.h b/include/block/block_int.h
15
diff --git a/block/vmdk.c b/block/vmdk.c
27
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
28
--- a/include/block/block_int.h
17
--- a/block/vmdk.c
29
+++ b/include/block/block_int.h
18
+++ b/block/vmdk.c
30
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
19
@@ -XXX,XX +XXX,XX @@ out:
31
* the parents in @parent_perm and @parent_shared.
20
return ret;
32
*
21
}
33
* If @c is NULL, return the permissions for attaching a new child for the
22
34
- * given @child_class.
23
-static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
35
+ * given @child_class and @role.
24
+static int coroutine_fn GRAPH_RDLOCK
36
*
25
+vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
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
{
26
{
76
assert(bs->drv && bs->drv->bdrv_child_perm);
27
char *desc, *tmp_desc;
77
- bs->drv->bdrv_child_perm(bs, c, child_class, reopen_queue,
28
char *p_name, *tmp_str;
78
+ bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue,
29
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
79
parent_perm, parent_shared,
30
80
nperm, nshared);
31
desc = g_malloc0(DESC_SIZE);
81
/* TODO Take force_share from reopen_queue */
32
tmp_desc = g_malloc0(DESC_SIZE);
82
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,
33
- ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
83
uint64_t cur_perm, cur_shared;
34
+ ret = bdrv_co_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
84
bool child_tighten_restr;
35
if (ret < 0) {
85
36
goto out;
86
- bdrv_child_perm(bs, c->bs, c, c->klass, q,
37
}
87
+ bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q,
38
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
88
cumulative_perms, cumulative_shared_perms,
39
pstrcat(desc, DESC_SIZE, tmp_desc);
89
&cur_perm, &cur_shared);
40
}
90
ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children,
41
91
@@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
42
- ret = bdrv_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
92
/* Update all children */
43
+ ret = bdrv_co_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
93
QLIST_FOREACH(c, &bs->children, next) {
44
94
uint64_t cur_perm, cur_shared;
45
out:
95
- bdrv_child_perm(bs, c->bs, c, c->klass, NULL,
46
g_free(desc);
96
+ bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL,
47
@@ -XXX,XX +XXX,XX @@ vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
97
cumulative_perms, cumulative_shared_perms,
48
return ret;
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
}
49
}
111
50
112
void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
51
-static int GRAPH_UNLOCKED
113
const BdrvChildClass *child_class,
52
+static int coroutine_fn GRAPH_UNLOCKED
114
+ BdrvChildRole role,
53
vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
115
BlockReopenQueue *reopen_queue,
54
bool zeroed_grain, Error **errp)
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
{
55
{
196
BDRVBlkdebugState *s = bs->opaque;
56
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
197
57
int gd_buf_size;
198
- bdrv_filter_default_perms(bs, c, child_class, reopen_queue, perm, shared,
58
199
- nperm, nshared);
59
if (flat) {
200
+ bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue,
60
- ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
201
+ perm, shared, nperm, nshared);
61
+ ret = blk_co_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
202
62
goto exit;
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
}
63
}
219
64
magic = cpu_to_be32(VMDK4_MAGIC);
220
if (!strcmp(c->name, "log")) {
65
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
221
- bdrv_format_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm,
66
header.check_bytes[3] = 0xa;
222
- nshrd);
67
223
+ bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd,
68
/* write all the data */
224
+ nperm, nshrd);
69
- ret = blk_pwrite(blk, 0, sizeof(magic), &magic, 0);
225
} else {
70
+ ret = blk_co_pwrite(blk, 0, sizeof(magic), &magic, 0);
226
- bdrv_filter_default_perms(bs, c, child_class, ro_q, perm, shrd, nperm,
71
if (ret < 0) {
227
- nshrd);
72
error_setg(errp, QERR_IO_ERROR);
228
+ bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd,
73
goto exit;
229
+ nperm, nshrd);
230
}
74
}
231
}
75
- ret = blk_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
232
76
+ ret = blk_co_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
233
diff --git a/block/commit.c b/block/commit.c
77
if (ret < 0) {
234
index XXXXXXX..XXXXXXX 100644
78
error_setg(errp, QERR_IO_ERROR);
235
--- a/block/commit.c
79
goto exit;
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
}
80
}
320
81
321
- bdrv_format_default_perms(bs, c, child_class, reopen_queue, perm, shared,
82
- ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
322
- nperm, nshared);
83
- PREALLOC_MODE_OFF, 0, errp);
323
+ bdrv_format_default_perms(bs, c, child_class, role, reopen_queue,
84
+ ret = blk_co_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
324
+ perm, shared, nperm, nshared);
85
+ PREALLOC_MODE_OFF, 0, errp);
325
}
86
if (ret < 0) {
326
87
goto exit;
327
static int bdrv_test_change_backing_file(BlockDriverState *bs,
88
}
328
diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c
89
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
329
index XXXXXXX..XXXXXXX 100644
90
i < gt_count; i++, tmp += gt_size) {
330
--- a/tests/test-bdrv-graph-mod.c
91
gd_buf[i] = cpu_to_le32(tmp);
331
+++ b/tests/test-bdrv-graph-mod.c
92
}
332
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_pass_through = {
93
- ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
333
94
- gd_buf_size, gd_buf, 0);
334
static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c,
95
+ ret = blk_co_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
335
const BdrvChildClass *child_class,
96
+ gd_buf_size, gd_buf, 0);
336
+ BdrvChildRole role,
97
if (ret < 0) {
337
BlockReopenQueue *reopen_queue,
98
error_setg(errp, QERR_IO_ERROR);
338
uint64_t perm, uint64_t shared,
99
goto exit;
339
uint64_t *nperm, uint64_t *nshared)
100
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
101
i < gt_count; i++, tmp += gt_size) {
102
gd_buf[i] = cpu_to_le32(tmp);
103
}
104
- ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE,
105
- gd_buf_size, gd_buf, 0);
106
+ ret = blk_co_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE,
107
+ gd_buf_size, gd_buf, 0);
108
if (ret < 0) {
109
error_setg(errp, QERR_IO_ERROR);
110
}
340
--
111
--
341
2.25.4
112
2.41.0
342
343
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Let child_file's, child_format's, and child_backing's .inherit_options()
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
implementations fall back to bdrv_inherited_options() to show that it
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
would really work for all of these cases, if only the parents passed the
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
appropriate BdrvChildRole and parent_is_format values.
7
6
8
(Also, make bdrv_open_inherit(), the only place to explicitly call
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9
bdrv_backing_options(), call bdrv_inherited_options() instead.)
8
Message-ID: <20230601115145.196465-10-pbonzini@redhat.com>
10
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
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>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
31
---
11
---
32
block.c | 71 +++++++++++++++------------------------------------------
12
block/vhdx.h | 5 ++--
33
1 file changed, 19 insertions(+), 52 deletions(-)
13
block/vhdx-log.c | 36 +++++++++++++-----------
14
block/vhdx.c | 73 +++++++++++++++++++++++-------------------------
15
3 files changed, 57 insertions(+), 57 deletions(-)
34
16
35
diff --git a/block.c b/block.c
17
diff --git a/block/vhdx.h b/block/vhdx.h
36
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
37
--- a/block.c
19
--- a/block/vhdx.h
38
+++ b/block.c
20
+++ b/block/vhdx.h
39
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
21
@@ -XXX,XX +XXX,XX @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset);
40
BdrvChildRole child_role,
22
int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
41
Error **errp);
23
Error **errp);
42
24
43
+/* TODO: Remove when no longer needed */
25
-int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
44
+static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,
26
- void *data, uint32_t length, uint64_t offset);
45
+ int *child_flags, QDict *child_options,
27
+int coroutine_fn GRAPH_RDLOCK
46
+ int parent_flags, QDict *parent_options);
28
+vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
47
+
29
+ void *data, uint32_t length, uint64_t offset);
48
/* If non-zero, use only whitelisted block drivers */
30
49
static int use_bdrv_whitelist;
31
static inline void leguid_to_cpus(MSGUID *guid)
50
32
{
51
@@ -XXX,XX +XXX,XX @@ static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format,
33
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
52
int *child_flags, QDict *child_options,
34
index XXXXXXX..XXXXXXX 100644
53
int parent_flags, QDict *parent_options)
35
--- a/block/vhdx-log.c
54
{
36
+++ b/block/vhdx-log.c
55
- int flags = parent_flags;
37
@@ -XXX,XX +XXX,XX @@ exit:
56
-
38
* It is assumed that 'buffer' is at least 4096*num_sectors large.
57
- /* Enable protocol handling, disable format probing for bs->file */
39
*
58
- flags |= BDRV_O_PROTOCOL;
40
* 0 is returned on success, -errno otherwise */
59
-
41
-static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
60
- /* If the cache mode isn't explicitly set, inherit direct and no-flush from
42
- uint32_t *sectors_written, void *buffer,
61
- * the parent. */
43
- uint32_t num_sectors)
62
- qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
44
+static int coroutine_fn GRAPH_RDLOCK
63
- qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
45
+vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
64
- qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
46
+ uint32_t *sectors_written, void *buffer,
65
-
47
+ uint32_t num_sectors)
66
- /* Inherit the read-only option from the parent if it's not set */
48
{
67
- qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY);
49
int ret = 0;
68
- qdict_copy_default(child_options, parent_options, BDRV_OPT_AUTO_READ_ONLY);
50
uint64_t offset;
69
-
51
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
70
- /* Our block drivers take care to send flushes and respect unmap policy,
52
/* full */
71
- * so we can default to enable both on lower layers regardless of the
53
break;
72
- * corresponding parent options. */
54
}
73
- qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap");
55
- ret = bdrv_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp,
74
-
56
- 0);
75
- /* Clear flags that only apply to the top layer */
57
+ ret = bdrv_co_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp, 0);
76
- flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ |
58
if (ret < 0) {
77
- BDRV_O_NO_IO);
59
goto exit;
78
-
60
}
79
- *child_flags = flags;
61
@@ -XXX,XX +XXX,XX @@ static void vhdx_log_raw_to_le_sector(VHDXLogDescriptor *desc,
80
+ bdrv_inherited_options(BDRV_CHILD_IMAGE, true,
81
+ child_flags, child_options,
82
+ parent_flags, parent_options);
83
}
62
}
84
63
85
const BdrvChildClass child_file = {
64
86
@@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_fmt_options(BdrvChildRole role,
65
-static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
87
int *child_flags, QDict *child_options,
66
- void *data, uint32_t length, uint64_t offset)
88
int parent_flags, QDict *parent_options)
67
+static int coroutine_fn GRAPH_RDLOCK
89
{
68
+vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
90
- child_file.inherit_options(role, parent_is_format,
69
+ void *data, uint32_t length, uint64_t offset)
91
- child_flags, child_options,
70
{
92
- parent_flags, parent_options);
71
int ret = 0;
93
-
72
void *buffer = NULL;
94
- *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO);
73
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
95
+ bdrv_inherited_options(BDRV_CHILD_DATA, false,
74
96
+ child_flags, child_options,
75
sectors += partial_sectors;
97
+ parent_flags, parent_options);
76
77
- file_length = bdrv_getlength(bs->file->bs);
78
+ file_length = bdrv_co_getlength(bs->file->bs);
79
if (file_length < 0) {
80
ret = file_length;
81
goto exit;
82
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
83
84
if (i == 0 && leading_length) {
85
/* partial sector at the front of the buffer */
86
- ret = bdrv_pread(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE,
87
- merged_sector, 0);
88
+ ret = bdrv_co_pread(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE,
89
+ merged_sector, 0);
90
if (ret < 0) {
91
goto exit;
92
}
93
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
94
sector_write = merged_sector;
95
} else if (i == sectors - 1 && trailing_length) {
96
/* partial sector at the end of the buffer */
97
- ret = bdrv_pread(bs->file, file_offset + trailing_length,
98
- VHDX_LOG_SECTOR_SIZE - trailing_length,
99
- merged_sector + trailing_length, 0);
100
+ ret = bdrv_co_pread(bs->file, file_offset + trailing_length,
101
+ VHDX_LOG_SECTOR_SIZE - trailing_length,
102
+ merged_sector + trailing_length, 0);
103
if (ret < 0) {
104
goto exit;
105
}
106
@@ -XXX,XX +XXX,XX @@ exit:
98
}
107
}
99
108
100
const BdrvChildClass child_format = {
109
/* Perform a log write, and then immediately flush the entire log */
101
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format,
110
-int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
102
int *child_flags, QDict *child_options,
111
- void *data, uint32_t length, uint64_t offset)
103
int parent_flags, QDict *parent_options)
112
+int coroutine_fn
104
{
113
+vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
105
- int flags = parent_flags;
114
+ void *data, uint32_t length, uint64_t offset)
106
-
115
{
107
- /* The cache mode is inherited unmodified for backing files; except WCE,
116
int ret = 0;
108
- * which is only applied on the top level (BlockBackend) */
117
VHDXLogSequence logs = { .valid = true,
109
- qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
118
@@ -XXX,XX +XXX,XX @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
110
- qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
119
111
- qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
120
/* Make sure data written (new and/or changed blocks) is stable
112
-
121
* on disk, before creating log entry */
113
- /* backing files always opened read-only */
122
- ret = bdrv_flush(bs);
114
- qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on");
123
+ ret = bdrv_co_flush(bs);
115
- qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off");
124
if (ret < 0) {
116
- flags &= ~BDRV_O_COPY_ON_READ;
125
goto exit;
117
-
126
}
118
- /* snapshot=on is handled on the top layer */
127
@@ -XXX,XX +XXX,XX @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
119
- flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_TEMPORARY);
128
logs.log = s->log;
120
-
129
121
- *child_flags = flags;
130
/* Make sure log is stable on disk */
122
+ bdrv_inherited_options(BDRV_CHILD_COW, true,
131
- ret = bdrv_flush(bs);
123
+ child_flags, child_options,
132
+ ret = bdrv_co_flush(bs);
124
+ parent_flags, parent_options);
133
if (ret < 0) {
134
goto exit;
135
}
136
diff --git a/block/vhdx.c b/block/vhdx.c
137
index XXXXXXX..XXXXXXX 100644
138
--- a/block/vhdx.c
139
+++ b/block/vhdx.c
140
@@ -XXX,XX +XXX,XX @@ exit:
141
*
142
* Returns the file offset start of the new payload block
143
*/
144
-static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
145
- uint64_t *new_offset, bool *need_zero)
146
+static int coroutine_fn GRAPH_RDLOCK
147
+vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
148
+ uint64_t *new_offset, bool *need_zero)
149
{
150
int64_t current_len;
151
152
- current_len = bdrv_getlength(bs->file->bs);
153
+ current_len = bdrv_co_getlength(bs->file->bs);
154
if (current_len < 0) {
155
return current_len;
156
}
157
@@ -XXX,XX +XXX,XX @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
158
if (*need_zero) {
159
int ret;
160
161
- ret = bdrv_truncate(bs->file, *new_offset + s->block_size, false,
162
- PREALLOC_MODE_OFF, BDRV_REQ_ZERO_WRITE, NULL);
163
+ ret = bdrv_co_truncate(bs->file, *new_offset + s->block_size, false,
164
+ PREALLOC_MODE_OFF, BDRV_REQ_ZERO_WRITE, NULL);
165
if (ret != -ENOTSUP) {
166
*need_zero = false;
167
return ret;
168
}
169
}
170
171
- return bdrv_truncate(bs->file, *new_offset + s->block_size, false,
172
- PREALLOC_MODE_OFF, 0, NULL);
173
+ return bdrv_co_truncate(bs->file, *new_offset + s->block_size, false,
174
+ PREALLOC_MODE_OFF, 0, NULL);
125
}
175
}
126
176
127
static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
177
/*
128
@@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_backing = {
178
@@ -XXX,XX +XXX,XX @@ exit:
129
* Returns the options and flags that a generic child of a BDS should
179
* The first 64KB of the Metadata section is reserved for the metadata
130
* get, based on the given options and flags for the parent BDS.
180
* header and entries; beyond that, the metadata items themselves reside.
131
*/
181
*/
132
-static void __attribute__((unused))
182
-static int vhdx_create_new_metadata(BlockBackend *blk,
133
- bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,
183
- uint64_t image_size,
134
- int *child_flags, QDict *child_options,
184
- uint32_t block_size,
135
- int parent_flags, QDict *parent_options)
185
- uint32_t sector_size,
136
+static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,
186
- uint64_t metadata_offset,
137
+ int *child_flags, QDict *child_options,
187
- VHDXImageType type)
138
+ int parent_flags, QDict *parent_options)
188
+static int coroutine_fn
139
{
189
+vhdx_create_new_metadata(BlockBackend *blk, uint64_t image_size,
140
int flags = parent_flags;
190
+ uint32_t block_size, uint32_t sector_size,
141
191
+ uint64_t metadata_offset, VHDXImageType type)
142
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
192
{
143
flags, options);
193
int ret = 0;
144
/* Let bdrv_backing_options() override "read-only" */
194
uint32_t offset = 0;
145
qdict_del(options, BDRV_OPT_READ_ONLY);
195
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_new_metadata(BlockBackend *blk,
146
- bdrv_backing_options(0, true, &flags, options, flags, options);
196
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
147
+ bdrv_inherited_options(BDRV_CHILD_COW, true,
197
vhdx_metadata_entry_le_export(&md_table_entry[4]);
148
+ &flags, options, flags, options);
198
149
}
199
- ret = blk_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
150
200
+ ret = blk_co_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
151
bs->open_flags = flags;
201
if (ret < 0) {
202
goto exit;
203
}
204
205
- ret = blk_pwrite(blk, metadata_offset + (64 * KiB),
206
- VHDX_METADATA_ENTRY_BUFFER_SIZE, entry_buffer, 0);
207
+ ret = blk_co_pwrite(blk, metadata_offset + (64 * KiB),
208
+ VHDX_METADATA_ENTRY_BUFFER_SIZE, entry_buffer, 0);
209
if (ret < 0) {
210
goto exit;
211
}
212
@@ -XXX,XX +XXX,XX @@ exit:
213
* Fixed images: default state of the BAT is fully populated, with
214
* file offsets and state PAYLOAD_BLOCK_FULLY_PRESENT.
215
*/
216
-static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
217
- uint64_t image_size, VHDXImageType type,
218
- bool use_zero_blocks, uint64_t file_offset,
219
- uint32_t length, Error **errp)
220
+static int coroutine_fn
221
+vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
222
+ uint64_t image_size, VHDXImageType type,
223
+ bool use_zero_blocks, uint64_t file_offset,
224
+ uint32_t length, Error **errp)
225
{
226
int ret = 0;
227
uint64_t data_file_offset;
228
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
229
if (type == VHDX_TYPE_DYNAMIC) {
230
/* All zeroes, so we can just extend the file - the end of the BAT
231
* is the furthest thing we have written yet */
232
- ret = blk_truncate(blk, data_file_offset, false, PREALLOC_MODE_OFF,
233
- 0, errp);
234
+ ret = blk_co_truncate(blk, data_file_offset, false, PREALLOC_MODE_OFF,
235
+ 0, errp);
236
if (ret < 0) {
237
goto exit;
238
}
239
} else if (type == VHDX_TYPE_FIXED) {
240
- ret = blk_truncate(blk, data_file_offset + image_size, false,
241
- PREALLOC_MODE_OFF, 0, errp);
242
+ ret = blk_co_truncate(blk, data_file_offset + image_size, false,
243
+ PREALLOC_MODE_OFF, 0, errp);
244
if (ret < 0) {
245
goto exit;
246
}
247
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
248
s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]);
249
sector_num += s->sectors_per_block;
250
}
251
- ret = blk_pwrite(blk, file_offset, length, s->bat, 0);
252
+ ret = blk_co_pwrite(blk, file_offset, length, s->bat, 0);
253
if (ret < 0) {
254
error_setg_errno(errp, -ret, "Failed to write the BAT");
255
goto exit;
256
@@ -XXX,XX +XXX,XX @@ exit:
257
* to create the BAT itself, we will also cause the BAT to be
258
* created.
259
*/
260
-static int vhdx_create_new_region_table(BlockBackend *blk,
261
- uint64_t image_size,
262
- uint32_t block_size,
263
- uint32_t sector_size,
264
- uint32_t log_size,
265
- bool use_zero_blocks,
266
- VHDXImageType type,
267
- uint64_t *metadata_offset,
268
- Error **errp)
269
+static int coroutine_fn
270
+vhdx_create_new_region_table(BlockBackend *blk, uint64_t image_size,
271
+ uint32_t block_size, uint32_t sector_size,
272
+ uint32_t log_size, bool use_zero_blocks,
273
+ VHDXImageType type, uint64_t *metadata_offset,
274
+ Error **errp)
275
{
276
int ret = 0;
277
uint32_t offset = 0;
278
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_new_region_table(BlockBackend *blk,
279
}
280
281
/* Now write out the region headers to disk */
282
- ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, VHDX_HEADER_BLOCK_SIZE,
283
- buffer, 0);
284
+ ret = blk_co_pwrite(blk, VHDX_REGION_TABLE_OFFSET, VHDX_HEADER_BLOCK_SIZE,
285
+ buffer, 0);
286
if (ret < 0) {
287
error_setg_errno(errp, -ret, "Failed to write first region table");
288
goto exit;
289
}
290
291
- ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, VHDX_HEADER_BLOCK_SIZE,
292
- buffer, 0);
293
+ ret = blk_co_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, VHDX_HEADER_BLOCK_SIZE,
294
+ buffer, 0);
295
if (ret < 0) {
296
error_setg_errno(errp, -ret, "Failed to write second region table");
297
goto exit;
152
--
298
--
153
2.25.4
299
2.41.0
154
155
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
For now, all callers (effectively) pass 0 and no callee evaluates thie
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
value. Later patches will change both.
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
5
6
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Message-ID: <20230601115145.196465-11-pbonzini@redhat.com>
8
Message-Id: <20200513110544.176672-8-mreitz@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
---
11
include/block/block_int.h | 3 ++-
12
block/qcow2.h | 33 +++++------
12
block.c | 40 +++++++++++++++++++++++----------------
13
block/qcow2-bitmap.c | 26 +++++----
13
block/block-backend.c | 3 ++-
14
block/qcow2-cluster.c | 12 ++--
14
block/vvfat.c | 3 ++-
15
block/qcow2-refcount.c | 130 +++++++++++++++++++++--------------------
15
4 files changed, 30 insertions(+), 19 deletions(-)
16
block/qcow2.c | 2 +-
17
5 files changed, 105 insertions(+), 98 deletions(-)
16
18
17
diff --git a/include/block/block_int.h b/include/block/block_int.h
19
diff --git a/block/qcow2.h b/block/qcow2.h
18
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
19
--- a/include/block/block_int.h
21
--- a/block/qcow2.h
20
+++ b/include/block/block_int.h
22
+++ b/block/qcow2.h
21
@@ -XXX,XX +XXX,XX @@ struct BdrvChildClass {
23
@@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
22
* non-BDS parents. */
24
23
bool parent_is_bds;
25
int qcow2_mark_dirty(BlockDriverState *bs);
24
26
int qcow2_mark_corrupt(BlockDriverState *bs);
25
- void (*inherit_options)(int *child_flags, QDict *child_options,
27
-int qcow2_mark_consistent(BlockDriverState *bs);
26
+ void (*inherit_options)(BdrvChildRole role,
28
int qcow2_update_header(BlockDriverState *bs);
27
+ int *child_flags, QDict *child_options,
29
28
int parent_flags, QDict *parent_options);
30
void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
29
31
@@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
30
void (*change_media)(BdrvChild *child, bool load);
32
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
31
diff --git a/block.c b/block.c
33
int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
34
int64_t nb_clusters);
35
-int64_t coroutine_fn qcow2_alloc_bytes(BlockDriverState *bs, int size);
36
+int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int size);
37
void qcow2_free_clusters(BlockDriverState *bs,
38
int64_t offset, int64_t size,
39
enum qcow2_discard_type type);
40
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
41
42
int qcow2_flush_caches(BlockDriverState *bs);
43
int qcow2_write_caches(BlockDriverState *bs);
44
-int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
45
- BdrvCheckMode fix);
46
+int coroutine_fn qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
47
+ BdrvCheckMode fix);
48
49
void qcow2_process_discards(BlockDriverState *bs, int ret);
50
51
@@ -XXX,XX +XXX,XX @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
52
int64_t size);
53
int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
54
int64_t size, bool data_file);
55
-int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
56
- void **refcount_table,
57
- int64_t *refcount_table_size,
58
- int64_t offset, int64_t size);
59
+int coroutine_fn qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
60
+ void **refcount_table,
61
+ int64_t *refcount_table_size,
62
+ int64_t offset, int64_t size);
63
64
int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
65
BlockDriverAmendStatusCB *status_cb,
66
@@ -XXX,XX +XXX,XX @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset,
67
int coroutine_fn qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset,
68
unsigned int *bytes,
69
uint64_t *host_offset, QCowL2Meta **m);
70
-int coroutine_fn qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
71
- uint64_t offset,
72
- int compressed_size,
73
- uint64_t *host_offset);
74
+int coroutine_fn GRAPH_RDLOCK
75
+qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset,
76
+ int compressed_size, uint64_t *host_offset);
77
void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_entry,
78
uint64_t *coffset, int *csize);
79
80
@@ -XXX,XX +XXX,XX @@ void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset);
81
void qcow2_cache_discard(Qcow2Cache *c, void *table);
82
83
/* qcow2-bitmap.c functions */
84
-int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
85
- void **refcount_table,
86
- int64_t *refcount_table_size);
87
-bool coroutine_fn qcow2_load_dirty_bitmaps(BlockDriverState *bs,
88
- bool *header_updated, Error **errp);
89
+int coroutine_fn
90
+qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
91
+ void **refcount_table,
92
+ int64_t *refcount_table_size);
93
+bool coroutine_fn GRAPH_RDLOCK
94
+qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated, Error **errp);
95
bool qcow2_get_bitmap_info_list(BlockDriverState *bs,
96
Qcow2BitmapInfoList **info_list, Error **errp);
97
int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
98
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
32
index XXXXXXX..XXXXXXX 100644
99
index XXXXXXX..XXXXXXX 100644
33
--- a/block.c
100
--- a/block/qcow2-bitmap.c
34
+++ b/block.c
101
+++ b/block/qcow2-bitmap.c
35
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
102
@@ -XXX,XX +XXX,XX @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb)
36
QDict *options, int flags,
103
/* load_bitmap_data
37
BlockDriverState *parent,
104
* @bitmap_table entries must satisfy specification constraints.
38
const BdrvChildClass *child_class,
105
* @bitmap must be cleared */
39
+ BdrvChildRole child_role,
106
-static int load_bitmap_data(BlockDriverState *bs,
40
Error **errp);
107
- const uint64_t *bitmap_table,
41
108
- uint32_t bitmap_table_size,
42
/* If non-zero, use only whitelisted block drivers */
109
- BdrvDirtyBitmap *bitmap)
43
@@ -XXX,XX +XXX,XX @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
110
+static int coroutine_fn GRAPH_RDLOCK
44
* Returns the options and flags that bs->file should get if a protocol driver
111
+load_bitmap_data(BlockDriverState *bs, const uint64_t *bitmap_table,
45
* is expected, based on the given options and flags for the parent BDS
112
+ uint32_t bitmap_table_size, BdrvDirtyBitmap *bitmap)
46
*/
113
{
47
-static void bdrv_inherited_options(int *child_flags, QDict *child_options,
114
int ret = 0;
48
+static void bdrv_inherited_options(BdrvChildRole role,
115
BDRVQcow2State *s = bs->opaque;
49
+ int *child_flags, QDict *child_options,
116
@@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs,
50
int parent_flags, QDict *parent_options)
117
* already cleared */
51
{
118
}
52
int flags = parent_flags;
119
} else {
53
@@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_file = {
120
- ret = bdrv_pread(bs->file, data_offset, s->cluster_size, buf, 0);
54
* (and not only protocols) is permitted for it, based on the given options and
121
+ ret = bdrv_co_pread(bs->file, data_offset, s->cluster_size, buf, 0);
55
* flags for the parent BDS
122
if (ret < 0) {
56
*/
123
goto finish;
57
-static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options,
124
}
58
+static void bdrv_inherited_fmt_options(BdrvChildRole role,
125
@@ -XXX,XX +XXX,XX @@ finish:
59
+ int *child_flags, QDict *child_options,
126
return ret;
60
int parent_flags, QDict *parent_options)
127
}
61
{
128
62
- child_file.inherit_options(child_flags, child_options,
129
-static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
63
+ child_file.inherit_options(role, child_flags, child_options,
130
- Qcow2Bitmap *bm, Error **errp)
64
parent_flags, parent_options);
131
+static coroutine_fn GRAPH_RDLOCK
65
132
+BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
66
*child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO);
133
+ Qcow2Bitmap *bm, Error **errp)
67
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c)
134
{
68
* Returns the options and flags that bs->backing should get, based on the
135
int ret;
69
* given options and flags for the parent BDS
136
uint64_t *bitmap_table = NULL;
70
*/
137
@@ -XXX,XX +XXX,XX @@ fail:
71
-static void bdrv_backing_options(int *child_flags, QDict *child_options,
138
return NULL;
72
+static void bdrv_backing_options(BdrvChildRole role,
139
}
73
+ int *child_flags, QDict *child_options,
140
74
int parent_flags, QDict *parent_options)
141
-int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
75
{
142
- void **refcount_table,
76
int flags = parent_flags;
143
- int64_t *refcount_table_size)
77
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
144
+int coroutine_fn
145
+qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
146
+ void **refcount_table,
147
+ int64_t *refcount_table_size)
148
{
149
int ret;
150
BDRVQcow2State *s = bs->opaque;
151
@@ -XXX,XX +XXX,XX @@ static void set_readonly_helper(gpointer bitmap, gpointer value)
152
* If header_updated is not NULL then it is set appropriately regardless of
153
* the return value.
154
*/
155
-bool coroutine_fn qcow2_load_dirty_bitmaps(BlockDriverState *bs,
156
- bool *header_updated, Error **errp)
157
+bool coroutine_fn GRAPH_RDLOCK
158
+qcow2_load_dirty_bitmaps(BlockDriverState *bs,
159
+ bool *header_updated, Error **errp)
160
{
161
BDRVQcow2State *s = bs->opaque;
162
Qcow2BitmapList *bm_list;
163
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
164
index XXXXXXX..XXXXXXX 100644
165
--- a/block/qcow2-cluster.c
166
+++ b/block/qcow2-cluster.c
167
@@ -XXX,XX +XXX,XX @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
168
*
169
* Return 0 on success and -errno in error cases
170
*/
171
-int coroutine_fn qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
172
- uint64_t offset,
173
- int compressed_size,
174
- uint64_t *host_offset)
175
+int coroutine_fn GRAPH_RDLOCK
176
+qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset,
177
+ int compressed_size, uint64_t *host_offset)
178
{
179
BDRVQcow2State *s = bs->opaque;
180
int l2_index, ret;
181
@@ -XXX,XX +XXX,XX @@ fail:
182
* all clusters in the same L2 slice) and returns the number of zeroed
183
* clusters.
184
*/
185
-static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
186
- uint64_t nb_clusters, int flags)
187
+static int coroutine_fn
188
+zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
189
+ uint64_t nb_clusters, int flags)
190
{
191
BDRVQcow2State *s = bs->opaque;
192
uint64_t *l2_slice;
193
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
194
index XXXXXXX..XXXXXXX 100644
195
--- a/block/qcow2-refcount.c
196
+++ b/block/qcow2-refcount.c
197
@@ -XXX,XX +XXX,XX @@ int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offs
198
199
/* only used to allocate compressed sectors. We try to allocate
200
contiguous sectors. size must be <= cluster_size */
201
-int64_t coroutine_fn qcow2_alloc_bytes(BlockDriverState *bs, int size)
202
+int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int size)
203
{
204
BDRVQcow2State *s = bs->opaque;
205
int64_t offset;
206
@@ -XXX,XX +XXX,XX @@ static int realloc_refcount_array(BDRVQcow2State *s, void **array,
207
*
208
* Modifies the number of errors in res.
209
*/
210
-int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
211
- void **refcount_table,
212
- int64_t *refcount_table_size,
213
- int64_t offset, int64_t size)
214
+int coroutine_fn GRAPH_RDLOCK
215
+qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
216
+ void **refcount_table,
217
+ int64_t *refcount_table_size,
218
+ int64_t offset, int64_t size)
219
{
220
BDRVQcow2State *s = bs->opaque;
221
uint64_t start, last, cluster_offset, k, refcount;
222
@@ -XXX,XX +XXX,XX @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
223
return 0;
78
}
224
}
79
225
80
backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs,
226
- file_len = bdrv_getlength(bs->file->bs);
81
- &child_backing, errp);
227
+ file_len = bdrv_co_getlength(bs->file->bs);
82
+ &child_backing, 0, errp);
228
if (file_len < 0) {
83
if (!backing_hd) {
229
return file_len;
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
}
230
}
97
231
@@ -XXX,XX +XXX,XX @@ enum {
98
bs = bdrv_open_inherit(filename, reference, image_options, 0,
232
*
99
- parent, child_class, errp);
233
* On failure in-memory @l2_table may be modified.
100
+ parent, child_class, child_role, errp);
234
*/
101
if (!bs) {
235
-static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
102
goto done;
236
- uint64_t l2_offset,
237
- uint64_t *l2_table, int l2_index, bool active,
238
- bool *metadata_overlap)
239
+static int coroutine_fn GRAPH_RDLOCK
240
+fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
241
+ uint64_t l2_offset, uint64_t *l2_table,
242
+ int l2_index, bool active,
243
+ bool *metadata_overlap)
244
{
245
BDRVQcow2State *s = bs->opaque;
246
int ret;
247
@@ -XXX,XX +XXX,XX @@ static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
248
goto fail;
103
}
249
}
104
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
250
105
BlockDriverState *bs;
251
- ret = bdrv_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s),
106
252
- &l2_table[idx], 0);
107
bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_class,
253
+ ret = bdrv_co_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s),
108
- allow_none, errp);
254
+ &l2_table[idx], 0);
109
+ child_role, allow_none, errp);
255
if (ret < 0) {
110
if (bs == NULL) {
256
fprintf(stderr, "ERROR: Failed to overwrite L2 "
111
return NULL;
257
"table entry: %s\n", strerror(-ret));
258
@@ -XXX,XX +XXX,XX @@ fail:
259
* Returns the number of errors found by the checks or -errno if an internal
260
* error occurred.
261
*/
262
-static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
263
- void **refcount_table,
264
- int64_t *refcount_table_size, int64_t l2_offset,
265
- int flags, BdrvCheckMode fix, bool active)
266
+static int coroutine_fn GRAPH_RDLOCK
267
+check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
268
+ void **refcount_table,
269
+ int64_t *refcount_table_size, int64_t l2_offset,
270
+ int flags, BdrvCheckMode fix, bool active)
271
{
272
BDRVQcow2State *s = bs->opaque;
273
uint64_t l2_entry, l2_bitmap;
274
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
275
bool metadata_overlap;
276
277
/* Read L2 table from disk */
278
- ret = bdrv_pread(bs->file, l2_offset, l2_size_bytes, l2_table, 0);
279
+ ret = bdrv_co_pread(bs->file, l2_offset, l2_size_bytes, l2_table, 0);
280
if (ret < 0) {
281
fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n");
282
res->check_errors++;
283
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
284
* Returns the number of errors found by the checks or -errno if an internal
285
* error occurred.
286
*/
287
-static int check_refcounts_l1(BlockDriverState *bs,
288
- BdrvCheckResult *res,
289
- void **refcount_table,
290
- int64_t *refcount_table_size,
291
- int64_t l1_table_offset, int l1_size,
292
- int flags, BdrvCheckMode fix, bool active)
293
+static int coroutine_fn GRAPH_RDLOCK
294
+check_refcounts_l1(BlockDriverState *bs, BdrvCheckResult *res,
295
+ void **refcount_table, int64_t *refcount_table_size,
296
+ int64_t l1_table_offset, int l1_size,
297
+ int flags, BdrvCheckMode fix, bool active)
298
{
299
BDRVQcow2State *s = bs->opaque;
300
size_t l1_size_bytes = l1_size * L1E_SIZE;
301
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs,
112
}
302
}
113
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
303
114
304
/* Read L1 table entries from disk */
305
- ret = bdrv_pread(bs->file, l1_table_offset, l1_size_bytes, l1_table, 0);
306
+ ret = bdrv_co_pread(bs->file, l1_table_offset, l1_size_bytes, l1_table, 0);
307
if (ret < 0) {
308
fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n");
309
res->check_errors++;
310
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs,
311
* have been already detected and sufficiently signaled by the calling function
312
* (qcow2_check_refcounts) by the time this function is called).
313
*/
314
-static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
315
- BdrvCheckMode fix)
316
+static int coroutine_fn GRAPH_RDLOCK
317
+check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix)
318
{
319
BDRVQcow2State *s = bs->opaque;
320
uint64_t *l2_table = qemu_blockalign(bs, s->cluster_size);
321
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
322
}
323
}
324
325
- ret = bdrv_pread(bs->file, l2_offset, s->l2_size * l2_entry_size(s),
326
- l2_table, 0);
327
+ ret = bdrv_co_pread(bs->file, l2_offset, s->l2_size * l2_entry_size(s),
328
+ l2_table, 0);
329
if (ret < 0) {
330
fprintf(stderr, "ERROR: Could not read L2 table: %s\n",
331
strerror(-ret));
332
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
333
goto fail;
334
}
335
336
- ret = bdrv_pwrite(bs->file, l2_offset, s->cluster_size, l2_table,
337
- 0);
338
+ ret = bdrv_co_pwrite(bs->file, l2_offset, s->cluster_size, l2_table, 0);
339
if (ret < 0) {
340
fprintf(stderr, "ERROR: Could not write L2 table: %s\n",
341
strerror(-ret));
342
@@ -XXX,XX +XXX,XX @@ fail:
343
* Checks consistency of refblocks and accounts for each refblock in
344
* *refcount_table.
345
*/
346
-static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
347
- BdrvCheckMode fix, bool *rebuild,
348
- void **refcount_table, int64_t *nb_clusters)
349
+static int coroutine_fn GRAPH_RDLOCK
350
+check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
351
+ BdrvCheckMode fix, bool *rebuild,
352
+ void **refcount_table, int64_t *nb_clusters)
353
{
354
BDRVQcow2State *s = bs->opaque;
355
int64_t i, size;
356
@@ -XXX,XX +XXX,XX @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
357
goto resize_fail;
358
}
359
360
- ret = bdrv_truncate(bs->file, offset + s->cluster_size, false,
361
- PREALLOC_MODE_OFF, 0, &local_err);
362
+ ret = bdrv_co_truncate(bs->file, offset + s->cluster_size, false,
363
+ PREALLOC_MODE_OFF, 0, &local_err);
364
if (ret < 0) {
365
error_report_err(local_err);
366
goto resize_fail;
367
}
368
- size = bdrv_getlength(bs->file->bs);
369
+ size = bdrv_co_getlength(bs->file->bs);
370
if (size < 0) {
371
ret = size;
372
goto resize_fail;
373
@@ -XXX,XX +XXX,XX @@ resize_fail:
374
/*
375
* Calculates an in-memory refcount table.
376
*/
377
-static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
378
- BdrvCheckMode fix, bool *rebuild,
379
- void **refcount_table, int64_t *nb_clusters)
380
+static int coroutine_fn GRAPH_RDLOCK
381
+calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
382
+ BdrvCheckMode fix, bool *rebuild,
383
+ void **refcount_table, int64_t *nb_clusters)
384
{
385
BDRVQcow2State *s = bs->opaque;
386
int64_t i;
387
@@ -XXX,XX +XXX,XX @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
388
* Compares the actual reference count for each cluster in the image against the
389
* refcount as reported by the refcount structures on-disk.
390
*/
391
-static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
392
- BdrvCheckMode fix, bool *rebuild,
393
- int64_t *highest_cluster,
394
- void *refcount_table, int64_t nb_clusters)
395
+static void coroutine_fn
396
+compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
397
+ BdrvCheckMode fix, bool *rebuild,
398
+ int64_t *highest_cluster,
399
+ void *refcount_table, int64_t nb_clusters)
400
{
401
BDRVQcow2State *s = bs->opaque;
402
int64_t i;
403
@@ -XXX,XX +XXX,XX @@ static int64_t alloc_clusters_imrt(BlockDriverState *bs,
404
* Return whether the on-disk reftable array was resized (true/false),
405
* or -errno on error.
406
*/
407
-static int rebuild_refcounts_write_refblocks(
408
+static int coroutine_fn GRAPH_RDLOCK
409
+rebuild_refcounts_write_refblocks(
410
BlockDriverState *bs, void **refcount_table, int64_t *nb_clusters,
411
int64_t first_cluster, int64_t end_cluster,
412
uint64_t **on_disk_reftable_ptr, uint32_t *on_disk_reftable_entries_ptr,
413
@@ -XXX,XX +XXX,XX @@ static int rebuild_refcounts_write_refblocks(
414
on_disk_refblock = (void *)((char *) *refcount_table +
415
refblock_index * s->cluster_size);
416
417
- ret = bdrv_pwrite(bs->file, refblock_offset, s->cluster_size,
418
- on_disk_refblock, 0);
419
+ ret = bdrv_co_pwrite(bs->file, refblock_offset, s->cluster_size,
420
+ on_disk_refblock, 0);
421
if (ret < 0) {
422
error_setg_errno(errp, -ret, "ERROR writing refblock");
423
return ret;
424
@@ -XXX,XX +XXX,XX @@ static int rebuild_refcounts_write_refblocks(
425
* On success, the old refcount structure is leaked (it will be covered by the
426
* new refcount structure).
427
*/
428
-static int rebuild_refcount_structure(BlockDriverState *bs,
429
- BdrvCheckResult *res,
430
- void **refcount_table,
431
- int64_t *nb_clusters,
432
- Error **errp)
433
+static int coroutine_fn GRAPH_RDLOCK
434
+rebuild_refcount_structure(BlockDriverState *bs, BdrvCheckResult *res,
435
+ void **refcount_table, int64_t *nb_clusters,
436
+ Error **errp)
437
{
438
BDRVQcow2State *s = bs->opaque;
439
int64_t reftable_offset = -1;
440
@@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs,
115
}
441
}
116
442
117
- bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp);
443
assert(reftable_length < INT_MAX);
118
+ bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, 0, errp);
444
- ret = bdrv_pwrite(bs->file, reftable_offset, reftable_length,
119
obj = NULL;
445
- on_disk_reftable, 0);
120
qobject_unref(obj);
446
+ ret = bdrv_co_pwrite(bs->file, reftable_offset, reftable_length,
121
visit_free(v);
447
+ on_disk_reftable, 0);
122
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
448
if (ret < 0) {
123
QDict *options, int flags,
449
error_setg_errno(errp, -ret, "ERROR writing reftable");
124
BlockDriverState *parent,
450
goto fail;
125
const BdrvChildClass *child_class,
451
@@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs,
126
+ BdrvChildRole child_role,
452
reftable_offset_and_clusters.reftable_offset = cpu_to_be64(reftable_offset);
127
Error **errp)
453
reftable_offset_and_clusters.reftable_clusters =
128
{
454
cpu_to_be32(reftable_clusters);
455
- ret = bdrv_pwrite_sync(bs->file,
456
- offsetof(QCowHeader, refcount_table_offset),
457
- sizeof(reftable_offset_and_clusters),
458
- &reftable_offset_and_clusters, 0);
459
+ ret = bdrv_co_pwrite_sync(bs->file,
460
+ offsetof(QCowHeader, refcount_table_offset),
461
+ sizeof(reftable_offset_and_clusters),
462
+ &reftable_offset_and_clusters, 0);
463
if (ret < 0) {
464
error_setg_errno(errp, -ret, "ERROR setting reftable");
465
goto fail;
466
@@ -XXX,XX +XXX,XX @@ fail:
467
* Returns 0 if no errors are found, the number of errors in case the image is
468
* detected as corrupted, and -errno when an internal error occurred.
469
*/
470
-int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
471
- BdrvCheckMode fix)
472
+int coroutine_fn GRAPH_RDLOCK
473
+qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix)
474
{
475
BDRVQcow2State *s = bs->opaque;
476
BdrvCheckResult pre_compare_res;
477
@@ -XXX,XX +XXX,XX @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
478
bool rebuild = false;
129
int ret;
479
int ret;
130
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
480
131
481
- size = bdrv_getlength(bs->file->bs);
132
if (child_class) {
482
+ size = bdrv_co_getlength(bs->file->bs);
133
bs->inherits_from = parent;
483
if (size < 0) {
134
- child_class->inherit_options(&flags, options,
484
res->check_errors++;
135
+ child_class->inherit_options(child_role, &flags, options,
485
return size;
136
parent->open_flags, parent->options);
486
@@ -XXX,XX +XXX,XX @@ done:
137
}
487
return ret;
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
}
488
}
164
489
165
/* Return true if the NULL-terminated @list contains @str */
490
-static int64_t get_refblock_offset(BlockDriverState *bs, uint64_t offset)
166
@@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
491
+static int64_t coroutine_fn get_refblock_offset(BlockDriverState *bs,
167
BlockDriverState *bs,
492
+ uint64_t offset)
168
QDict *options,
493
{
169
const BdrvChildClass *klass,
494
BDRVQcow2State *s = bs->opaque;
170
+ BdrvChildRole role,
495
uint32_t index = offset_to_reftable_index(s, offset);
171
QDict *parent_options,
496
@@ -XXX,XX +XXX,XX @@ int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size)
172
int parent_flags,
497
return -EIO;
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
}
498
}
202
499
203
diff --git a/block/block-backend.c b/block/block-backend.c
500
-int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs)
501
+int coroutine_fn GRAPH_RDLOCK
502
+qcow2_detect_metadata_preallocation(BlockDriverState *bs)
503
{
504
BDRVQcow2State *s = bs->opaque;
505
int64_t i, end_cluster, cluster_count = 0, threshold;
506
diff --git a/block/qcow2.c b/block/qcow2.c
204
index XXXXXXX..XXXXXXX 100644
507
index XXXXXXX..XXXXXXX 100644
205
--- a/block/block-backend.c
508
--- a/block/qcow2.c
206
+++ b/block/block-backend.c
509
+++ b/block/qcow2.c
207
@@ -XXX,XX +XXX,XX @@ static QTAILQ_HEAD(, BlockBackend) block_backends =
510
@@ -XXX,XX +XXX,XX @@ int qcow2_mark_corrupt(BlockDriverState *bs)
208
static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =
511
* Marks the image as consistent, i.e., unsets the corrupt bit, and flushes
209
QTAILQ_HEAD_INITIALIZER(monitor_block_backends);
512
* before if necessary.
210
513
*/
211
-static void blk_root_inherit_options(int *child_flags, QDict *child_options,
514
-int qcow2_mark_consistent(BlockDriverState *bs)
212
+static void blk_root_inherit_options(BdrvChildRole role,
515
+static int coroutine_fn qcow2_mark_consistent(BlockDriverState *bs)
213
+ int *child_flags, QDict *child_options,
516
{
214
int parent_flags, QDict *parent_options)
517
BDRVQcow2State *s = bs->opaque;
215
{
518
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
--
519
--
232
2.25.4
520
2.41.0
233
234
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
For now, it is always set to 0. Later patches in this series will
3
bdrv_co_getlength was recently introduced, with bdrv_getlength becoming
4
ensure that all callers pass an appropriate combination of flags.
4
a wrapper for use in unknown context. Switch to bdrv_co_getlength when
5
possible.
5
6
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
Message-ID: <20230601115145.196465-12-pbonzini@redhat.com>
8
Message-Id: <20200513110544.176672-6-mreitz@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
---
11
include/block/block.h | 2 ++
12
block/io.c | 10 +++++-----
12
include/block/block_int.h | 2 ++
13
block/parallels.c | 4 ++--
13
block.c | 11 ++++++++---
14
block/qcow.c | 6 +++---
14
block/backup-top.c | 3 ++-
15
block/vmdk.c | 4 ++--
15
block/blkdebug.c | 2 +-
16
4 files changed, 12 insertions(+), 12 deletions(-)
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(-)
43
17
44
diff --git a/include/block/block.h b/include/block/block.h
18
diff --git a/block/io.c b/block/io.c
45
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
46
--- a/include/block/block.h
20
--- a/block/io.c
47
+++ b/include/block/block.h
21
+++ b/block/io.c
48
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
22
@@ -XXX,XX +XXX,XX @@ bdrv_aligned_preadv(BdrvChild *child, BdrvTrackedRequest *req,
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
}
23
}
123
24
124
bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing,
25
/* Forward the request to the BlockDriver, possibly fragmenting it */
125
- errp);
26
- total_bytes = bdrv_getlength(bs);
126
+ 0, errp);
27
+ total_bytes = bdrv_co_getlength(bs);
127
/* If backing_hd was already part of bs's backing chain, and
28
if (total_bytes < 0) {
128
* inherits_from pointed recursively to bs then let's update it to
29
ret = total_bytes;
129
* point directly to bs (else it will become NULL). */
30
goto out;
130
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
31
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
131
QDict *options, const char *bdref_key,
32
assert(pnum);
132
BlockDriverState *parent,
33
assert_bdrv_graph_readable();
133
const BdrvChildClass *child_class,
34
*pnum = 0;
134
+ BdrvChildRole child_role,
35
- total_size = bdrv_getlength(bs);
135
bool allow_none, Error **errp)
36
+ total_size = bdrv_co_getlength(bs);
136
{
37
if (total_size < 0) {
137
BlockDriverState *bs;
38
ret = total_size;
138
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
39
goto early_out;
139
return NULL;
40
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
41
bytes = n;
140
}
42
}
141
43
142
- return bdrv_attach_child(parent, bs, bdref_key, child_class, errp);
44
- /* Must be non-NULL or bdrv_getlength() would have failed */
143
+ return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
45
+ /* Must be non-NULL or bdrv_co_getlength() would have failed */
144
+ errp);
46
assert(bs->drv);
145
}
47
has_filtered_child = bdrv_filter_child(bs);
146
48
if (!bs->drv->bdrv_co_block_status && !has_filtered_child) {
147
/*
49
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
148
diff --git a/block/backup-top.c b/block/backup-top.c
50
if (!cow_bs) {
149
index XXXXXXX..XXXXXXX 100644
51
ret |= BDRV_BLOCK_ZERO;
150
--- a/block/backup-top.c
52
} else if (want_zero) {
151
+++ b/block/backup-top.c
53
- int64_t size2 = bdrv_getlength(cow_bs);
152
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
54
+ int64_t size2 = bdrv_co_getlength(cow_bs);
153
source->supported_zero_flags);
55
154
56
if (size2 >= 0 && offset >= size2) {
155
bdrv_ref(target);
57
ret |= BDRV_BLOCK_ZERO;
156
- state->target = bdrv_attach_child(top, target, "target", &child_file, errp);
58
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
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;
59
return ret;
262
}
60
}
263
61
264
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
62
- old_size = bdrv_getlength(bs);
265
+ bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
63
+ old_size = bdrv_co_getlength(bs);
266
false, errp);
64
if (old_size < 0) {
267
if (!bs->file) {
65
error_setg_errno(errp, -old_size, "Failed to get old image size");
268
return -EINVAL;
66
return old_size;
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
67
diff --git a/block/parallels.c b/block/parallels.c
335
index XXXXXXX..XXXXXXX 100644
68
index XXXXXXX..XXXXXXX 100644
336
--- a/block/parallels.c
69
--- a/block/parallels.c
337
+++ b/block/parallels.c
70
+++ b/block/parallels.c
338
@@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
71
@@ -XXX,XX +XXX,XX @@ allocate_clusters(BlockDriverState *bs, int64_t sector_num,
339
Error *local_err = NULL;
72
assert(idx < s->bat_size && idx + to_allocate <= s->bat_size);
340
char *buf;
73
341
74
space = to_allocate * s->tracks;
342
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
75
- len = bdrv_getlength(bs->file->bs);
343
+ bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
76
+ len = bdrv_co_getlength(bs->file->bs);
344
false, errp);
77
if (len < 0) {
345
if (!bs->file) {
78
return len;
346
return -EINVAL;
79
}
80
@@ -XXX,XX +XXX,XX @@ parallels_check_outside_image(BlockDriverState *bs, BdrvCheckResult *res,
81
uint32_t i;
82
int64_t off, high_off, size;
83
84
- size = bdrv_getlength(bs->file->bs);
85
+ size = bdrv_co_getlength(bs->file->bs);
86
if (size < 0) {
87
res->check_errors++;
88
return size;
347
diff --git a/block/qcow.c b/block/qcow.c
89
diff --git a/block/qcow.c b/block/qcow.c
348
index XXXXXXX..XXXXXXX 100644
90
index XXXXXXX..XXXXXXX 100644
349
--- a/block/qcow.c
91
--- a/block/qcow.c
350
+++ b/block/qcow.c
92
+++ b/block/qcow.c
351
@@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
93
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
352
qdict_extract_subqdict(options, &encryptopts, "encrypt.");
94
if (!allocate)
353
encryptfmt = qdict_get_try_str(encryptopts, "format");
95
return 0;
354
96
/* allocate a new l2 entry */
355
- bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
97
- l2_offset = bdrv_getlength(bs->file->bs);
356
+ bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
98
+ l2_offset = bdrv_co_getlength(bs->file->bs);
357
false, errp);
99
if (l2_offset < 0) {
358
if (!bs->file) {
100
return l2_offset;
359
ret = -EINVAL;
101
}
360
diff --git a/block/qcow2.c b/block/qcow2.c
102
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
361
index XXXXXXX..XXXXXXX 100644
103
if (decompress_cluster(bs, cluster_offset) < 0) {
362
--- a/block/qcow2.c
104
return -EIO;
363
+++ b/block/qcow2.c
105
}
364
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
106
- cluster_offset = bdrv_getlength(bs->file->bs);
365
107
+ cluster_offset = bdrv_co_getlength(bs->file->bs);
366
/* Open external data file */
108
if ((int64_t) cluster_offset < 0) {
367
s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file,
109
return cluster_offset;
368
- true, &local_err);
110
}
369
+ 0, true, &local_err);
111
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
370
if (local_err) {
112
return ret;
371
error_propagate(errp, local_err);
113
}
372
ret = -EINVAL;
114
} else {
373
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
115
- cluster_offset = bdrv_getlength(bs->file->bs);
374
if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
116
+ cluster_offset = bdrv_co_getlength(bs->file->bs);
375
if (!s->data_file && s->image_data_file) {
117
if ((int64_t) cluster_offset < 0) {
376
s->data_file = bdrv_open_child(s->image_data_file, options,
118
return cluster_offset;
377
- "data-file", bs, &child_file,
119
}
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
120
diff --git a/block/vmdk.c b/block/vmdk.c
492
index XXXXXXX..XXXXXXX 100644
121
index XXXXXXX..XXXXXXX 100644
493
--- a/block/vmdk.c
122
--- a/block/vmdk.c
494
+++ b/block/vmdk.c
123
+++ b/block/vmdk.c
495
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
124
@@ -XXX,XX +XXX,XX @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
496
assert(ret < 32);
125
int64_t length;
497
126
498
extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix,
127
for (i = 0; i < s->num_extents; i++) {
499
- bs, &child_file, false, &local_err);
128
- length = bdrv_getlength(s->extents[i].file->bs);
500
+ bs, &child_file, 0, false, &local_err);
129
+ length = bdrv_co_getlength(s->extents[i].file->bs);
501
g_free(extent_path);
130
if (length < 0) {
502
if (local_err) {
131
return length;
503
error_propagate(errp, local_err);
132
}
504
@@ -XXX,XX +XXX,XX @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
133
@@ -XXX,XX +XXX,XX @@ vmdk_co_check(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix)
505
uint32_t magic;
134
break;
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);
618
}
135
}
619
}
136
if (ret == VMDK_OK) {
620
137
- int64_t extent_len = bdrv_getlength(extent->file->bs);
621
@@ -XXX,XX +XXX,XX @@ static void do_test_replace_child_mid_drain(int old_drain_count,
138
+ int64_t extent_len = bdrv_co_getlength(extent->file->bs);
622
139
if (extent_len < 0) {
623
bdrv_ref(old_child_bs);
140
fprintf(stderr,
624
parent_bs->backing = bdrv_attach_child(parent_bs, old_child_bs, "child",
141
"ERROR: could not get extent file length for sector %"
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
652
--
142
--
653
2.25.4
143
2.41.0
654
655
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
We want to unify child_format and child_file at some point. One of the
3
bdrv_co_debug_event was recently introduced, with bdrv_debug_event
4
important things that set format drivers apart from other drivers is
4
becoming a wrapper for use in unknown context. Because most of the
5
that they do not expect other format nodes under them (except in the
5
time bdrv_debug_event is used on a BdrvChild via the wrapper macro
6
backing chain), i.e. we must not probe formats inside of formats. That
6
BLKDBG_EVENT, introduce a similar macro BLKDBG_CO_EVENT that calls
7
means we need something on which to distinguish format drivers from
7
bdrv_co_debug_event, and switch whenever possible.
8
others, and hence this flag.
9
8
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Message-ID: <20230601115145.196465-13-pbonzini@redhat.com>
12
Reviewed-by: Alberto Garcia <berto@igalia.com>
11
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
13
Message-Id: <20200513110544.176672-3-mreitz@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
13
---
16
include/block/block_int.h | 7 +++++++
14
include/block/block-io.h | 7 +++++++
17
block/bochs.c | 1 +
15
block/io.c | 4 ++--
18
block/cloop.c | 1 +
16
block/qcow.c | 24 ++++++++++++------------
19
block/crypto.c | 2 ++
17
block/qcow2-cluster.c | 12 ++++++------
20
block/dmg.c | 1 +
18
block/qcow2-refcount.c | 4 ++--
21
block/parallels.c | 1 +
19
block/qcow2.c | 18 +++++++++---------
22
block/qcow.c | 1 +
20
block/qed-table.c | 6 +++---
23
block/qcow2.c | 1 +
21
block/qed.c | 8 ++++----
24
block/qed.c | 1 +
22
block/raw-format.c | 4 ++--
25
block/raw-format.c | 1 +
23
block/vmdk.c | 24 ++++++++++++------------
26
block/vdi.c | 1 +
24
10 files changed, 59 insertions(+), 52 deletions(-)
27
block/vhdx.c | 1 +
28
block/vmdk.c | 1 +
29
block/vpc.c | 1 +
30
14 files changed, 21 insertions(+)
31
25
32
diff --git a/include/block/block_int.h b/include/block/block_int.h
26
diff --git a/include/block/block-io.h b/include/block/block-io.h
33
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
34
--- a/include/block/block_int.h
28
--- a/include/block/block-io.h
35
+++ b/include/block/block_int.h
29
+++ b/include/block/block-io.h
36
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
30
@@ -XXX,XX +XXX,XX @@ bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event);
37
* must implement them and return -ENOTSUP.
31
void co_wrapper_mixed_bdrv_rdlock
38
*/
32
bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event);
39
bool is_filter;
33
40
+ /*
34
+#define BLKDBG_CO_EVENT(child, evt) \
41
+ * Set to true if the BlockDriver is a format driver. Format nodes
35
+ do { \
42
+ * generally do not expect their children to be other format nodes
36
+ if (child) { \
43
+ * (except for backing files), and so format probing is disabled
37
+ bdrv_co_debug_event(child->bs, evt); \
44
+ * on those children.
38
+ } \
45
+ */
39
+ } while (0)
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
+
40
+
84
.strong_runtime_opts = block_crypto_strong_runtime_opts,
41
#define BLKDBG_EVENT(child, evt) \
85
};
42
do { \
86
43
if (child) { \
87
diff --git a/block/dmg.c b/block/dmg.c
44
diff --git a/block/io.c b/block/io.c
88
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
89
--- a/block/dmg.c
46
--- a/block/io.c
90
+++ b/block/dmg.c
47
+++ b/block/io.c
91
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_dmg = {
48
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
92
.bdrv_child_perm = bdrv_format_default_perms,
49
}
93
.bdrv_co_preadv = dmg_co_preadv,
50
94
.bdrv_close = dmg_close,
51
/* Write back cached data to the OS even with cache=unsafe */
95
+ .is_format = true,
52
- BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_OS);
96
};
53
+ BLKDBG_CO_EVENT(primary_child, BLKDBG_FLUSH_TO_OS);
97
54
if (bs->drv->bdrv_co_flush_to_os) {
98
static void bdrv_dmg_init(void)
55
ret = bs->drv->bdrv_co_flush_to_os(bs);
99
diff --git a/block/parallels.c b/block/parallels.c
56
if (ret < 0) {
100
index XXXXXXX..XXXXXXX 100644
57
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
101
--- a/block/parallels.c
58
goto flush_children;
102
+++ b/block/parallels.c
59
}
103
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_parallels = {
60
104
.bdrv_co_flush_to_os = parallels_co_flush_to_os,
61
- BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK);
105
.bdrv_co_readv = parallels_co_readv,
62
+ BLKDBG_CO_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK);
106
.bdrv_co_writev = parallels_co_writev,
63
if (!bs->drv) {
107
+ .is_format = true,
64
/* bs->drv->bdrv_co_flush() might have ejected the BDS
108
.supports_backing = true,
65
* (even in case of apparent success) */
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
66
diff --git a/block/qcow.c b/block/qcow.c
112
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
113
--- a/block/qcow.c
68
--- a/block/qcow.c
114
+++ b/block/qcow.c
69
+++ b/block/qcow.c
115
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qcow = {
70
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
116
.bdrv_co_create = qcow_co_create,
71
/* update the L1 entry */
117
.bdrv_co_create_opts = qcow_co_create_opts,
72
s->l1_table[l1_index] = l2_offset;
118
.bdrv_has_zero_init = bdrv_has_zero_init_1,
73
tmp = cpu_to_be64(l2_offset);
119
+ .is_format = true,
74
- BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
120
.supports_backing = true,
75
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L1_UPDATE);
121
.bdrv_refresh_limits = qcow_refresh_limits,
76
ret = bdrv_co_pwrite_sync(bs->file,
77
s->l1_table_offset + l1_index * sizeof(tmp),
78
sizeof(tmp), &tmp, 0);
79
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
80
}
81
}
82
l2_table = s->l2_cache + (min_index << s->l2_bits);
83
- BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
84
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L2_LOAD);
85
if (new_l2_table) {
86
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
87
ret = bdrv_co_pwrite_sync(bs->file, l2_offset,
88
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
89
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) {
90
if (!allocate)
91
return 0;
92
- BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC);
93
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC);
94
assert(QEMU_IS_ALIGNED(n_start | n_end, BDRV_SECTOR_SIZE));
95
/* allocate a new cluster */
96
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) &&
97
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
98
}
99
cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size);
100
/* write the cluster content */
101
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
102
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
103
ret = bdrv_co_pwrite(bs->file, cluster_offset, s->cluster_size,
104
s->cluster_cache, 0);
105
if (ret < 0) {
106
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
107
NULL) < 0) {
108
return -EIO;
109
}
110
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
111
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
112
ret = bdrv_co_pwrite(bs->file, cluster_offset + i,
113
BDRV_SECTOR_SIZE,
114
s->cluster_data, 0);
115
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
116
tmp = cpu_to_be64(cluster_offset);
117
l2_table[l2_index] = tmp;
118
if (allocate == 2) {
119
- BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
120
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
121
} else {
122
- BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
123
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L2_UPDATE);
124
}
125
ret = bdrv_co_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp),
126
sizeof(tmp), &tmp, 0);
127
@@ -XXX,XX +XXX,XX @@ decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
128
if (s->cluster_cache_offset != coffset) {
129
csize = cluster_offset >> (63 - s->cluster_bits);
130
csize &= (s->cluster_size - 1);
131
- BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
132
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
133
ret = bdrv_co_pread(bs->file, coffset, csize, s->cluster_data, 0);
134
if (ret < 0)
135
return -1;
136
@@ -XXX,XX +XXX,XX @@ qcow_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
137
/* read from the base image */
138
qemu_co_mutex_unlock(&s->lock);
139
/* qcow2 emits this on bs->file instead of bs->backing */
140
- BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
141
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
142
ret = bdrv_co_pread(bs->backing, offset, n, buf, 0);
143
qemu_co_mutex_lock(&s->lock);
144
if (ret < 0) {
145
@@ -XXX,XX +XXX,XX @@ qcow_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
146
break;
147
}
148
qemu_co_mutex_unlock(&s->lock);
149
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
150
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
151
ret = bdrv_co_pread(bs->file, cluster_offset + offset_in_cluster,
152
n, buf, 0);
153
qemu_co_mutex_lock(&s->lock);
154
@@ -XXX,XX +XXX,XX @@ qcow_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
155
}
156
157
qemu_co_mutex_unlock(&s->lock);
158
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
159
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
160
ret = bdrv_co_pwrite(bs->file, cluster_offset + offset_in_cluster,
161
n, buf, 0);
162
qemu_co_mutex_lock(&s->lock);
163
@@ -XXX,XX +XXX,XX @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
164
}
165
cluster_offset &= s->cluster_offset_mask;
166
167
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);
168
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);
169
ret = bdrv_co_pwrite(bs->file, cluster_offset, out_len, out_buf, 0);
170
if (ret < 0) {
171
goto fail;
172
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
173
index XXXXXXX..XXXXXXX 100644
174
--- a/block/qcow2-cluster.c
175
+++ b/block/qcow2-cluster.c
176
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs,
177
fprintf(stderr, "shrink l1_table from %d to %d\n", s->l1_size, new_l1_size);
178
#endif
179
180
- BLKDBG_EVENT(bs->file, BLKDBG_L1_SHRINK_WRITE_TABLE);
181
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L1_SHRINK_WRITE_TABLE);
182
ret = bdrv_co_pwrite_zeroes(bs->file,
183
s->l1_table_offset + new_l1_size * L1E_SIZE,
184
(s->l1_size - new_l1_size) * L1E_SIZE, 0);
185
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs,
186
goto fail;
187
}
188
189
- BLKDBG_EVENT(bs->file, BLKDBG_L1_SHRINK_FREE_L2_CLUSTERS);
190
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L1_SHRINK_FREE_L2_CLUSTERS);
191
for (i = s->l1_size - 1; i > new_l1_size - 1; i--) {
192
if ((s->l1_table[i] & L1E_OFFSET_MASK) == 0) {
193
continue;
194
@@ -XXX,XX +XXX,XX @@ do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset,
195
return 0;
196
}
197
198
- BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
199
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_COW_READ);
200
201
if (!bs->drv) {
202
return -ENOMEDIUM;
203
@@ -XXX,XX +XXX,XX @@ do_perform_cow_write(BlockDriverState *bs, uint64_t cluster_offset,
204
return ret;
205
}
206
207
- BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
208
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_COW_WRITE);
209
ret = bdrv_co_pwritev(s->data_file, cluster_offset + offset_in_cluster,
210
qiov->size, qiov, 0);
211
if (ret < 0) {
212
@@ -XXX,XX +XXX,XX @@ qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset,
213
214
/* compressed clusters never have the copied flag */
215
216
- BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
217
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
218
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_slice);
219
set_l2_entry(s, l2_slice, l2_index, cluster_offset);
220
if (has_subclusters(s)) {
221
@@ -XXX,XX +XXX,XX @@ perform_cow(BlockDriverState *bs, QCowL2Meta *m)
222
/* NOTE: we have a write_aio blkdebug event here followed by
223
* a cow_write one in do_perform_cow_write(), but there's only
224
* one single I/O operation */
225
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
226
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
227
ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
228
} else {
229
/* If there's no guest data then write both COW regions separately */
230
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
231
index XXXXXXX..XXXXXXX 100644
232
--- a/block/qcow2-refcount.c
233
+++ b/block/qcow2-refcount.c
234
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_refcount_init(BlockDriverState *bs)
235
ret = -ENOMEM;
236
goto fail;
237
}
238
- BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD);
239
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_REFTABLE_LOAD);
240
ret = bdrv_co_pread(bs->file, s->refcount_table_offset,
241
refcount_table_size2, s->refcount_table, 0);
242
if (ret < 0) {
243
@@ -XXX,XX +XXX,XX @@ int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int si
244
size_t free_in_cluster;
245
int ret;
246
247
- BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_BYTES);
248
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_BYTES);
249
assert(size > 0 && size <= s->cluster_size);
250
assert(!s->free_byte_offset || offset_into_cluster(s, s->free_byte_offset));
122
251
123
diff --git a/block/qcow2.c b/block/qcow2.c
252
diff --git a/block/qcow2.c b/block/qcow2.c
124
index XXXXXXX..XXXXXXX 100644
253
index XXXXXXX..XXXXXXX 100644
125
--- a/block/qcow2.c
254
--- a/block/qcow2.c
126
+++ b/block/qcow2.c
255
+++ b/block/qcow2.c
127
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_qcow2 = {
256
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_encrypted(BlockDriverState *bs,
128
.bdrv_save_vmstate = qcow2_save_vmstate,
257
return -ENOMEM;
129
.bdrv_load_vmstate = qcow2_load_vmstate,
258
}
130
259
131
+ .is_format = true,
260
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
132
.supports_backing = true,
261
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
133
.bdrv_change_backing_file = qcow2_change_backing_file,
262
ret = bdrv_co_pread(s->data_file, host_offset, bytes, buf, 0);
134
263
if (ret < 0) {
264
goto fail;
265
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type,
266
case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC:
267
assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part */
268
269
- BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
270
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
271
return bdrv_co_preadv_part(bs->backing, offset, bytes,
272
qiov, qiov_offset, 0);
273
274
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type,
275
offset, bytes, qiov, qiov_offset);
276
}
277
278
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
279
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
280
return bdrv_co_preadv_part(s->data_file, host_offset,
281
bytes, qiov, qiov_offset, 0);
282
283
@@ -XXX,XX +XXX,XX @@ handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta)
284
return ret;
285
}
286
287
- BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
288
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
289
ret = bdrv_co_pwrite_zeroes(s->data_file, start_offset, nb_bytes,
290
BDRV_REQ_NO_FALLBACK);
291
if (ret < 0) {
292
@@ -XXX,XX +XXX,XX @@ int qcow2_co_pwritev_task(BlockDriverState *bs, uint64_t host_offset,
293
* guest data now.
294
*/
295
if (!merge_cow(offset, bytes, qiov, qiov_offset, l2meta)) {
296
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
297
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
298
trace_qcow2_writev_data(qemu_coroutine_self(), host_offset);
299
ret = bdrv_co_pwritev_part(s->data_file, host_offset,
300
bytes, qiov, qiov_offset, 0);
301
@@ -XXX,XX +XXX,XX @@ qcow2_co_pwritev_compressed_task(BlockDriverState *bs,
302
goto fail;
303
}
304
305
- BLKDBG_EVENT(s->data_file, BLKDBG_WRITE_COMPRESSED);
306
+ BLKDBG_CO_EVENT(s->data_file, BLKDBG_WRITE_COMPRESSED);
307
ret = bdrv_co_pwrite(s->data_file, cluster_offset, out_len, out_buf, 0);
308
if (ret < 0) {
309
goto fail;
310
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_compressed(BlockDriverState *bs,
311
312
out_buf = qemu_blockalign(bs, s->cluster_size);
313
314
- BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
315
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
316
ret = bdrv_co_pread(bs->file, coffset, csize, buf, 0);
317
if (ret < 0) {
318
goto fail;
319
@@ -XXX,XX +XXX,XX @@ qcow2_co_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
320
return offset;
321
}
322
323
- BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_SAVE);
324
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_VMSTATE_SAVE);
325
return bs->drv->bdrv_co_pwritev_part(bs, offset, qiov->size, qiov, 0, 0);
326
}
327
328
@@ -XXX,XX +XXX,XX @@ qcow2_co_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
329
return offset;
330
}
331
332
- BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_LOAD);
333
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_VMSTATE_LOAD);
334
return bs->drv->bdrv_co_preadv_part(bs, offset, qiov->size, qiov, 0, 0);
335
}
336
337
diff --git a/block/qed-table.c b/block/qed-table.c
338
index XXXXXXX..XXXXXXX 100644
339
--- a/block/qed-table.c
340
+++ b/block/qed-table.c
341
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s)
342
int coroutine_fn qed_write_l1_table(BDRVQEDState *s, unsigned int index,
343
unsigned int n)
344
{
345
- BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE);
346
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_L1_UPDATE);
347
return qed_write_table(s, s->header.l1_table_offset,
348
s->l1_table, index, n, false);
349
}
350
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request,
351
request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache);
352
request->l2_table->table = qed_alloc_table(s);
353
354
- BLKDBG_EVENT(s->bs->file, BLKDBG_L2_LOAD);
355
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_L2_LOAD);
356
ret = qed_read_table(s, offset, request->l2_table->table);
357
358
if (ret) {
359
@@ -XXX,XX +XXX,XX @@ int coroutine_fn qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
360
unsigned int index, unsigned int n,
361
bool flush)
362
{
363
- BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE);
364
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_L2_UPDATE);
365
return qed_write_table(s, request->l2_table->offset,
366
request->l2_table->table, index, n, flush);
367
}
135
diff --git a/block/qed.c b/block/qed.c
368
diff --git a/block/qed.c b/block/qed.c
136
index XXXXXXX..XXXXXXX 100644
369
index XXXXXXX..XXXXXXX 100644
137
--- a/block/qed.c
370
--- a/block/qed.c
138
+++ b/block/qed.c
371
+++ b/block/qed.c
139
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qed = {
372
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn GRAPH_RDLOCK
140
.format_name = "qed",
373
qed_read_backing_file(BDRVQEDState *s, uint64_t pos, QEMUIOVector *qiov)
141
.instance_size = sizeof(BDRVQEDState),
374
{
142
.create_opts = &qed_create_opts,
375
if (s->bs->backing) {
143
+ .is_format = true,
376
- BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
144
.supports_backing = true,
377
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
145
378
return bdrv_co_preadv(s->bs->backing, pos, qiov->size, qiov, 0);
146
.bdrv_probe = bdrv_qed_probe,
379
}
380
qemu_iovec_memset(qiov, 0, 0, qiov->size);
381
@@ -XXX,XX +XXX,XX @@ qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, uint64_t len,
382
goto out;
383
}
384
385
- BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE);
386
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_COW_WRITE);
387
ret = bdrv_co_pwritev(s->bs->file, offset, qiov.size, &qiov, 0);
388
if (ret < 0) {
389
goto out;
390
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn GRAPH_RDLOCK qed_aio_write_main(QEDAIOCB *acb)
391
392
trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size);
393
394
- BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
395
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
396
return bdrv_co_pwritev(s->bs->file, offset, acb->cur_qiov.size,
397
&acb->cur_qiov, 0);
398
}
399
@@ -XXX,XX +XXX,XX @@ qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
400
} else if (ret != QED_CLUSTER_FOUND) {
401
r = qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov);
402
} else {
403
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
404
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
405
r = bdrv_co_preadv(bs->file, offset, acb->cur_qiov.size,
406
&acb->cur_qiov, 0);
407
}
147
diff --git a/block/raw-format.c b/block/raw-format.c
408
diff --git a/block/raw-format.c b/block/raw-format.c
148
index XXXXXXX..XXXXXXX 100644
409
index XXXXXXX..XXXXXXX 100644
149
--- a/block/raw-format.c
410
--- a/block/raw-format.c
150
+++ b/block/raw-format.c
411
+++ b/block/raw-format.c
151
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_raw = {
412
@@ -XXX,XX +XXX,XX @@ raw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
152
.bdrv_co_copy_range_to = &raw_co_copy_range_to,
413
return ret;
153
.bdrv_co_truncate = &raw_co_truncate,
414
}
154
.bdrv_getlength = &raw_getlength,
415
155
+ .is_format = true,
416
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
156
.has_variable_length = true,
417
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
157
.bdrv_measure = &raw_measure,
418
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
158
.bdrv_get_info = &raw_get_info,
419
}
159
diff --git a/block/vdi.c b/block/vdi.c
420
160
index XXXXXXX..XXXXXXX 100644
421
@@ -XXX,XX +XXX,XX @@ raw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
161
--- a/block/vdi.c
422
goto fail;
162
+++ b/block/vdi.c
423
}
163
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vdi = {
424
164
425
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
165
.bdrv_get_info = vdi_get_info,
426
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
166
427
ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
167
+ .is_format = true,
428
168
.create_opts = &vdi_create_opts,
429
fail:
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
430
diff --git a/block/vmdk.c b/block/vmdk.c
184
index XXXXXXX..XXXXXXX 100644
431
index XXXXXXX..XXXXXXX 100644
185
--- a/block/vmdk.c
432
--- a/block/vmdk.c
186
+++ b/block/vmdk.c
433
+++ b/block/vmdk.c
187
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vmdk = {
434
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
188
.bdrv_get_info = vmdk_get_info,
435
if (skip_start_bytes > 0) {
189
.bdrv_gather_child_options = vmdk_gather_child_options,
436
if (copy_from_backing) {
190
437
/* qcow2 emits this on bs->file instead of bs->backing */
191
+ .is_format = true,
438
- BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
192
.supports_backing = true,
439
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_READ);
193
.create_opts = &vmdk_create_opts,
440
ret = bdrv_co_pread(bs->backing, offset, skip_start_bytes,
194
};
441
whole_grain, 0);
195
diff --git a/block/vpc.c b/block/vpc.c
442
if (ret < 0) {
196
index XXXXXXX..XXXXXXX 100644
443
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
197
--- a/block/vpc.c
444
goto exit;
198
+++ b/block/vpc.c
445
}
199
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vpc = {
446
}
200
447
- BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
201
.bdrv_get_info = vpc_get_info,
448
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_WRITE);
202
449
ret = bdrv_co_pwrite(extent->file, cluster_offset, skip_start_bytes,
203
+ .is_format = true,
450
whole_grain, 0);
204
.create_opts = &vpc_create_opts,
451
if (ret < 0) {
205
.bdrv_has_zero_init = vpc_has_zero_init,
452
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
206
.strong_runtime_opts = vpc_strong_runtime_opts,
453
if (skip_end_bytes < cluster_bytes) {
454
if (copy_from_backing) {
455
/* qcow2 emits this on bs->file instead of bs->backing */
456
- BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
457
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_READ);
458
ret = bdrv_co_pread(bs->backing, offset + skip_end_bytes,
459
cluster_bytes - skip_end_bytes,
460
whole_grain + skip_end_bytes, 0);
461
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
462
goto exit;
463
}
464
}
465
- BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
466
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_WRITE);
467
ret = bdrv_co_pwrite(extent->file, cluster_offset + skip_end_bytes,
468
cluster_bytes - skip_end_bytes,
469
whole_grain + skip_end_bytes, 0);
470
@@ -XXX,XX +XXX,XX @@ vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, uint32_t offset)
471
{
472
offset = cpu_to_le32(offset);
473
/* update L2 table */
474
- BLKDBG_EVENT(extent->file, BLKDBG_L2_UPDATE);
475
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_L2_UPDATE);
476
if (bdrv_co_pwrite(extent->file,
477
((int64_t)m_data->l2_offset * 512)
478
+ (m_data->l2_index * sizeof(offset)),
479
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent,
480
}
481
}
482
l2_table = (char *)extent->l2_cache + (min_index * l2_size_bytes);
483
- BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD);
484
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_L2_LOAD);
485
if (bdrv_co_pread(extent->file,
486
(int64_t)l2_offset * 512,
487
l2_size_bytes,
488
@@ -XXX,XX +XXX,XX @@ vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
489
n_bytes = buf_len + sizeof(VmdkGrainMarker);
490
qemu_iovec_init_buf(&local_qiov, data, n_bytes);
491
492
- BLKDBG_EVENT(extent->file, BLKDBG_WRITE_COMPRESSED);
493
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_WRITE_COMPRESSED);
494
} else {
495
qemu_iovec_init(&local_qiov, qiov->niov);
496
qemu_iovec_concat(&local_qiov, qiov, qiov_offset, n_bytes);
497
498
- BLKDBG_EVENT(extent->file, BLKDBG_WRITE_AIO);
499
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_WRITE_AIO);
500
}
501
502
write_offset = cluster_offset + offset_in_cluster;
503
@@ -XXX,XX +XXX,XX @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset,
504
505
506
if (!extent->compressed) {
507
- BLKDBG_EVENT(extent->file, BLKDBG_READ_AIO);
508
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_READ_AIO);
509
ret = bdrv_co_preadv(extent->file,
510
cluster_offset + offset_in_cluster, bytes,
511
qiov, 0);
512
@@ -XXX,XX +XXX,XX @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset,
513
buf_bytes = cluster_bytes * 2;
514
cluster_buf = g_malloc(buf_bytes);
515
uncomp_buf = g_malloc(cluster_bytes);
516
- BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED);
517
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_READ_COMPRESSED);
518
ret = bdrv_co_pread(extent->file, cluster_offset, buf_bytes, cluster_buf,
519
0);
520
if (ret < 0) {
521
@@ -XXX,XX +XXX,XX @@ vmdk_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
522
qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes);
523
524
/* qcow2 emits this on bs->file instead of bs->backing */
525
- BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
526
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
527
ret = bdrv_co_preadv(bs->backing, offset, n_bytes,
528
&local_qiov, 0);
529
if (ret < 0) {
530
@@ -XXX,XX +XXX,XX @@ vmdk_co_check(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix)
531
BDRVVmdkState *s = bs->opaque;
532
VmdkExtent *extent = NULL;
533
int64_t sector_num = 0;
534
- int64_t total_sectors = bdrv_nb_sectors(bs);
535
+ int64_t total_sectors = bdrv_co_nb_sectors(bs);
536
int ret;
537
uint64_t cluster_offset;
538
207
--
539
--
208
2.25.4
540
2.41.0
209
210
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
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>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
15
block/block-backend.c | 11 +++++++----
16
block/vvfat.c | 4 +++-
17
2 files changed, 10 insertions(+), 5 deletions(-)
18
19
diff --git a/block/block-backend.c b/block/block-backend.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/block/block-backend.c
22
+++ b/block/block-backend.c
23
@@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
24
return NULL;
25
}
26
27
- blk->root = bdrv_root_attach_child(bs, "root", &child_root, 0, blk->ctx,
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) {
46
return -EPERM;
47
}
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;
63
--
64
2.25.4
65
66
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
1
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
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
1
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
Deleted patch
1
From: John Snow <jsnow@redhat.com>
2
1
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
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
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