1
The following changes since commit df34fe314b5da628bc9a2664fb1b887bc0a6cc6d:
1
The following changes since commit 52ed34cbddde1cb89b2ac263e758e349a77f21e1:
2
2
3
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20190708' into staging (2019-07-08 14:23:32 +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 f7077c9860a438087c2d9a8cc27cb8438c98a748:
9
for you to fetch changes up to 17362398ee1a7f04e8006a46333145d8b707fd35:
10
10
11
qcow2: Allow -o compat=v3 during qemu-img amend (2019-07-08 16:00:31 +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
- virtio-scsi: Fix request resubmission after I/O error with iothreads
16
- Re-enable the graph lock
17
- qcow2: Fix missing v2/v3 subformat aliases for amend
17
- More fixes to coroutine_fn marking
18
- qcow(1): More specific error message for wrong format version
19
- MAINTAINERS: update RBD block maintainer
20
18
21
----------------------------------------------------------------
19
----------------------------------------------------------------
22
Eric Blake (1):
20
Kevin Wolf (11):
23
qcow2: Allow -o compat=v3 during qemu-img amend
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"
24
32
25
Jason Dillaman (1):
33
Paolo Bonzini (12):
26
MAINTAINERS: update RBD block maintainer
34
file-posix: remove incorrect coroutine_fn calls
35
qed: mark more functions as coroutine_fns and GRAPH_RDLOCK
36
vpc: mark more functions as coroutine_fns and GRAPH_RDLOCK
37
bochs: mark more functions as coroutine_fns and GRAPH_RDLOCK
38
block: mark another function as coroutine_fns and GRAPH_UNLOCKED
39
cloop: mark more functions as coroutine_fns and GRAPH_RDLOCK
40
dmg: mark more functions as coroutine_fns and GRAPH_RDLOCK
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
27
46
28
John Snow (1):
47
block/qcow2.h | 33 +++--
29
block/qcow: Improve error when opening qcow2 files as qcow
48
block/vhdx.h | 5 +-
30
49
include/block/block-io.h | 7 ++
31
Stefan Hajnoczi (3):
50
include/block/graph-lock.h | 6 +-
32
vl: add qemu_add_vm_change_state_handler_prio()
51
block.c | 114 ++++++++++++++++--
33
qdev: add qdev_add_vm_change_state_handler()
52
block/bochs.c | 7 +-
34
virtio-scsi: restart DMA after iothread
53
block/cloop.c | 9 +-
35
54
block/dmg.c | 21 ++--
36
include/hw/qdev-core.h | 5 ++++
55
block/file-posix.c | 29 +++--
37
include/sysemu/sysemu.h | 2 ++
56
block/graph-lock.c | 43 +++----
38
block/qcow.c | 7 ++++-
57
block/io.c | 14 +--
39
block/qcow2.c | 6 ++--
58
block/parallels.c | 4 +-
40
hw/core/vm-change-state-handler.c | 61 +++++++++++++++++++++++++++++++++++++++
59
block/qcow.c | 30 ++---
41
hw/scsi/scsi-bus.c | 4 +--
60
block/qcow2-bitmap.c | 26 ++--
42
hw/virtio/virtio.c | 4 +--
61
block/qcow2-cluster.c | 24 ++--
43
vl.c | 59 +++++++++++++++++++++++++++++--------
62
block/qcow2-refcount.c | 134 +++++++++++----------
44
MAINTAINERS | 2 +-
63
block/qcow2.c | 20 +--
45
hw/core/Makefile.objs | 1 +
64
block/qed-check.c | 5 +-
46
10 files changed, 130 insertions(+), 21 deletions(-)
65
block/qed-table.c | 6 +-
47
create mode 100644 hw/core/vm-change-state-handler.c
66
block/qed.c | 15 +--
48
67
block/raw-format.c | 4 +-
68
block/vhdx-log.c | 36 +++---
69
block/vhdx.c | 73 ++++++-----
70
block/vmdk.c | 55 ++++-----
71
block/vpc.c | 52 ++++----
72
blockjob.c | 17 ++-
73
hw/core/qdev-properties-system.c | 8 +-
74
tests/unit/test-block-iothread.c | 7 +-
75
tests/qemu-iotests/tests/iothreads-commit-active | 85 +++++++++++++
76
.../qemu-iotests/tests/iothreads-commit-active.out | 23 ++++
77
30 files changed, 573 insertions(+), 339 deletions(-)
78
create mode 100755 tests/qemu-iotests/tests/iothreads-commit-active
79
create mode 100644 tests/qemu-iotests/tests/iothreads-commit-active.out
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
This is a better regression test for the bugs hidden by commit 80fc5d26
2
('graph-lock: Disable locking for now'). With that commit reverted, it
3
hangs instantaneously and reliably for me.
2
4
3
Children sometimes depend on their parent's vm change state handler
5
It is important to have a reliable test like this, because the following
4
having completed. Add a vm change state handler API for devices that
6
commits will set out to fix the actual root cause of the deadlocks and
5
guarantees tree depth ordering.
7
then finally revert commit 80fc5d26, which was only a stopgap solution.
6
8
7
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Message-ID: <20230605085711.21261-2-kwolf@redhat.com>
11
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
13
---
10
include/hw/qdev-core.h | 5 +++
14
.../tests/iothreads-commit-active | 85 +++++++++++++++++++
11
hw/core/vm-change-state-handler.c | 61 +++++++++++++++++++++++++++++++
15
.../tests/iothreads-commit-active.out | 23 +++++
12
hw/core/Makefile.objs | 1 +
16
2 files changed, 108 insertions(+)
13
3 files changed, 67 insertions(+)
17
create mode 100755 tests/qemu-iotests/tests/iothreads-commit-active
14
create mode 100644 hw/core/vm-change-state-handler.c
18
create mode 100644 tests/qemu-iotests/tests/iothreads-commit-active.out
15
19
16
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
20
diff --git a/tests/qemu-iotests/tests/iothreads-commit-active b/tests/qemu-iotests/tests/iothreads-commit-active
17
index XXXXXXX..XXXXXXX 100644
21
new file mode 100755
18
--- a/include/hw/qdev-core.h
22
index XXXXXXX..XXXXXXX
19
+++ b/include/hw/qdev-core.h
23
--- /dev/null
24
+++ b/tests/qemu-iotests/tests/iothreads-commit-active
20
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@
21
#include "qom/object.h"
26
+#!/usr/bin/env python3
22
#include "hw/irq.h"
27
+# group: rw quick auto
23
#include "hw/hotplug.h"
28
+#
24
+#include "sysemu/sysemu.h"
29
+# Copyright (C) 2023 Red Hat, Inc.
25
30
+#
26
enum {
31
+# This program is free software; you can redistribute it and/or modify
27
DEV_NVECTORS_UNSPECIFIED = -1,
32
+# it under the terms of the GNU General Public License as published by
28
@@ -XXX,XX +XXX,XX @@ static inline bool qbus_is_hotpluggable(BusState *bus)
33
+# the Free Software Foundation; either version 2 of the License, or
29
void device_listener_register(DeviceListener *listener);
34
+# (at your option) any later version.
30
void device_listener_unregister(DeviceListener *listener);
35
+#
31
36
+# This program is distributed in the hope that it will be useful,
32
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
37
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
33
+ VMChangeStateHandler *cb,
38
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
+ void *opaque);
39
+# GNU General Public License for more details.
40
+#
41
+# You should have received a copy of the GNU General Public License
42
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
43
+#
44
+# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
35
+
45
+
36
#endif
46
+import asyncio
37
diff --git a/hw/core/vm-change-state-handler.c b/hw/core/vm-change-state-handler.c
47
+import iotests
48
+
49
+iotests.script_initialize(supported_fmts=['qcow2'],
50
+ supported_platforms=['linux'])
51
+iotests.verify_virtio_scsi_pci_or_ccw()
52
+
53
+with iotests.FilePath('disk0.img') as img_path, \
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:
58
+
59
+ img_size = '10M'
60
+ iotests.qemu_img_create('-f', iotests.imgfmt, img_path, img_size)
61
+ iotests.qemu_img_create('-f', iotests.imgfmt, '-b', img_path,
62
+ '-F', iotests.imgfmt, snap_path)
63
+ iotests.qemu_img_create('-f', iotests.imgfmt, src_path, img_size)
64
+ iotests.qemu_img_create('-f', iotests.imgfmt, dst_path, img_size)
65
+
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)
69
+
70
+ iotests.qemu_io_log('-c', f'write 0 {img_size}', src_path)
71
+
72
+ iotests.log('Launching VM...')
73
+ vm.add_object('iothread,id=iothread0')
74
+ vm.add_object('throttle-group,x-bps-write=1048576,id=tg0')
75
+ vm.add_blockdev(f'file,node-name=disk0-file,filename={img_path}')
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
38
new file mode 100644
112
new file mode 100644
39
index XXXXXXX..XXXXXXX
113
index XXXXXXX..XXXXXXX
40
--- /dev/null
114
--- /dev/null
41
+++ b/hw/core/vm-change-state-handler.c
115
+++ b/tests/qemu-iotests/tests/iothreads-commit-active.out
42
@@ -XXX,XX +XXX,XX @@
116
@@ -XXX,XX +XXX,XX @@
43
+/*
117
+wrote 65536/65536 bytes at offset 0
44
+ * qdev vm change state handlers
118
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
45
+ *
46
+ * This program is free software; you can redistribute it and/or modify
47
+ * it under the terms of the GNU General Public License as published by
48
+ * the Free Software Foundation; either version 2 of the License,
49
+ * or (at your option) any later version.
50
+ *
51
+ * This program is distributed in the hope that it will be useful,
52
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54
+ * GNU General Public License for more details.
55
+ *
56
+ * You should have received a copy of the GNU General Public License
57
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
58
+ */
59
+
119
+
60
+#include "qemu/osdep.h"
120
+wrote 65536/65536 bytes at offset 1048576
61
+#include "hw/qdev.h"
121
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
62
+
122
+
63
+static int qdev_get_dev_tree_depth(DeviceState *dev)
123
+wrote 65536/65536 bytes at offset 3145728
64
+{
124
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
65
+ int depth;
66
+
125
+
67
+ for (depth = 0; dev; depth++) {
126
+wrote 10485760/10485760 bytes at offset 0
68
+ BusState *bus = dev->parent_bus;
127
+10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
69
+
128
+
70
+ if (!bus) {
129
+Launching VM...
71
+ break;
130
+Creating some background I/O...
72
+ }
131
+{"return": {}}
73
+
132
+Starting active commit...
74
+ dev = bus->parent;
133
+{"return": {}}
75
+ }
134
+{"execute": "job-complete", "arguments": {"id": "job1"}}
76
+
135
+{"return": {}}
77
+ return depth;
136
+{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
78
+}
137
+{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
79
+
138
+{"execute": "job-dismiss", "arguments": {"id": "job1"}}
80
+/**
139
+{"return": {}}
81
+ * qdev_add_vm_change_state_handler:
82
+ * @dev: the device that owns this handler
83
+ * @cb: the callback function to be invoked
84
+ * @opaque: user data passed to the callback function
85
+ *
86
+ * This function works like qemu_add_vm_change_state_handler() except callbacks
87
+ * are invoked in qdev tree depth order. Ordering is desirable when callbacks
88
+ * of children depend on their parent's callback having completed first.
89
+ *
90
+ * For example, when qdev_add_vm_change_state_handler() is used, a host
91
+ * controller's callback is invoked before the children on its bus when the VM
92
+ * starts running. The order is reversed when the VM stops running.
93
+ *
94
+ * Returns: an entry to be freed with qemu_del_vm_change_state_handler()
95
+ */
96
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
97
+ VMChangeStateHandler *cb,
98
+ void *opaque)
99
+{
100
+ int depth = qdev_get_dev_tree_depth(dev);
101
+
102
+ return qemu_add_vm_change_state_handler_prio(cb, opaque, depth);
103
+}
104
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
105
index XXXXXXX..XXXXXXX 100644
106
--- a/hw/core/Makefile.objs
107
+++ b/hw/core/Makefile.objs
108
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
109
common-obj-y += irq.o
110
common-obj-y += hotplug.o
111
common-obj-$(CONFIG_SOFTMMU) += nmi.o
112
+common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
113
114
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
115
common-obj-$(CONFIG_XILINX_AXI) += stream.o
116
--
140
--
117
2.20.1
141
2.41.0
118
119
diff view generated by jsdifflib
New patch
1
blk_insert_bs() requires that callers hold the AioContext lock for the
2
node that should be inserted. Take it.
1
3
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Message-ID: <20230605085711.21261-3-kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
hw/core/qdev-properties-system.c | 8 ++++++--
10
1 file changed, 6 insertions(+), 2 deletions(-)
11
12
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/core/qdev-properties-system.c
15
+++ b/hw/core/qdev-properties-system.c
16
@@ -XXX,XX +XXX,XX @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
17
* aware of iothreads require their BlockBackends to be in the main
18
* AioContext.
19
*/
20
- ctx = iothread ? bdrv_get_aio_context(bs) : qemu_get_aio_context();
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);
30
+
31
if (ret < 0) {
32
goto fail;
33
}
34
--
35
2.41.0
diff view generated by jsdifflib
New patch
1
blk_insert_bs() requires that callers hold the AioContext lock for the
2
node that should be inserted. Take it.
1
3
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Message-ID: <20230605085711.21261-4-kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
tests/unit/test-block-iothread.c | 7 ++++++-
10
1 file changed, 6 insertions(+), 1 deletion(-)
11
12
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tests/unit/test-block-iothread.c
15
+++ b/tests/unit/test-block-iothread.c
16
@@ -XXX,XX +XXX,XX @@ static void test_attach_second_node(void)
17
BlockDriverState *bs, *filter;
18
QDict *options;
19
20
+ aio_context_acquire(main_ctx);
21
blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
22
bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
23
blk_insert_bs(blk, bs, &error_abort);
24
@@ -XXX,XX +XXX,XX @@ static void test_attach_second_node(void)
25
qdict_put_str(options, "driver", "raw");
26
qdict_put_str(options, "file", "base");
27
28
- aio_context_acquire(main_ctx);
29
filter = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
30
aio_context_release(main_ctx);
31
32
@@ -XXX,XX +XXX,XX @@ static void test_attach_preserve_blk_ctx(void)
33
{
34
IOThread *iothread = iothread_new();
35
AioContext *ctx = iothread_get_aio_context(iothread);
36
+ AioContext *main_ctx = qemu_get_aio_context();
37
BlockBackend *blk;
38
BlockDriverState *bs;
39
40
+ aio_context_acquire(main_ctx);
41
blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
42
bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
43
bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
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);
61
62
--
63
2.41.0
diff view generated by jsdifflib
New patch
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.
1
4
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Message-ID: <20230605085711.21261-5-kwolf@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
block.c | 13 +++++++++++--
11
1 file changed, 11 insertions(+), 2 deletions(-)
12
13
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block.c
16
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ done:
18
*
19
* The BlockdevRef will be removed from the options QDict.
20
*
21
+ * The caller must hold the lock of the main AioContext and no other AioContext.
22
* @parent can move to a different AioContext in this function. Callers must
23
* make sure that their AioContext locking is still correct after this.
24
*/
25
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
26
bool allow_none, Error **errp)
27
{
28
BlockDriverState *bs;
29
+ BdrvChild *child;
30
+ AioContext *ctx;
31
32
GLOBAL_STATE_CODE();
33
34
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
35
return NULL;
36
}
37
38
- return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
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;
47
}
48
49
/*
50
* Wrapper on bdrv_open_child() for most popular case: open primary child of bs.
51
*
52
+ * The caller must hold the lock of the main AioContext and no other AioContext.
53
* @parent can move to a different AioContext in this function. Callers must
54
* make sure that their AioContext locking is still correct after this.
55
*/
56
--
57
2.41.0
diff view generated by jsdifflib
New patch
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.
1
5
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Message-ID: <20230605085711.21261-6-kwolf@redhat.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
block.c | 21 ++++++++++++++++++++-
12
1 file changed, 20 insertions(+), 1 deletion(-)
13
14
diff --git a/block.c b/block.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
17
+++ b/block.c
18
@@ -XXX,XX +XXX,XX @@ static TransactionActionDrv bdrv_attach_child_common_drv = {
19
* Function doesn't update permissions, caller is responsible for this.
20
*
21
* Returns new created child.
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 BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
28
const char *child_name,
29
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
30
Transaction *tran, Error **errp)
31
{
32
BdrvChild *new_child;
33
- AioContext *parent_ctx;
34
+ AioContext *parent_ctx, *new_child_ctx;
35
AioContext *child_ctx = bdrv_get_aio_context(child_bs);
36
37
assert(child_class->get_parent_desc);
38
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
39
}
40
}
41
42
+ new_child_ctx = bdrv_get_aio_context(child_bs);
43
+ if (new_child_ctx != child_ctx) {
44
+ aio_context_release(child_ctx);
45
+ aio_context_acquire(new_child_ctx);
46
+ }
47
+
48
bdrv_ref(child_bs);
49
/*
50
* Let every new BdrvChild start with a drained parent. Inserting the child
51
@@ -XXX,XX +XXX,XX @@ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs,
52
};
53
tran_add(tran, &bdrv_attach_child_common_drv, s);
54
55
+ if (new_child_ctx != child_ctx) {
56
+ aio_context_release(new_child_ctx);
57
+ aio_context_acquire(child_ctx);
58
+ }
59
+
60
return new_child;
61
}
62
63
/*
64
* Function doesn't update permissions, caller is responsible for this.
65
+ *
66
+ * The caller must hold the AioContext lock for @child_bs. Both @parent_bs and
67
+ * @child_bs can move to a different AioContext in this function. Callers must
68
+ * make sure that their AioContext locking is still correct after this.
69
*/
70
static BdrvChild *bdrv_attach_child_noperm(BlockDriverState *parent_bs,
71
BlockDriverState *child_bs,
72
--
73
2.41.0
diff view generated by jsdifflib
New patch
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.
1
5
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Message-ID: <20230605085711.21261-7-kwolf@redhat.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
block.c | 35 +++++++++++++++++++++++++++++++++--
12
1 file changed, 33 insertions(+), 2 deletions(-)
13
14
diff --git a/block.c b/block.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
17
+++ b/block.c
18
@@ -XXX,XX +XXX,XX @@ static BdrvChildRole bdrv_backing_role(BlockDriverState *bs)
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;
31
}
32
33
+/*
34
+ * The caller must hold the AioContext lock for @backing_hd. Both @bs and
35
+ * @backing_hd can move to a different AioContext in this function. Callers must
36
+ * make sure that their AioContext locking is still correct after this.
37
+ */
38
static int bdrv_set_backing_noperm(BlockDriverState *bs,
39
BlockDriverState *backing_hd,
40
Transaction *tran, Error **errp)
41
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
42
* backing BlockDriverState (or NULL).
43
*
44
* Return 0 on success, otherwise return < 0 and set @errp.
45
+ *
46
+ * The caller must hold the AioContext lock of @reopen_state->bs.
47
+ * @reopen_state->bs can move to a different AioContext in this function.
48
+ * Callers must make sure that their AioContext locking is still correct after
49
+ * this.
50
*/
51
static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
52
bool is_backing, Transaction *tran,
53
@@ -XXX,XX +XXX,XX @@ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
54
const char *child_name = is_backing ? "backing" : "file";
55
QObject *value;
56
const char *str;
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);
73
+ }
74
+
75
+ ret = bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing,
76
+ tran, errp);
77
+
78
+ if (old_ctx != ctx) {
79
+ aio_context_release(ctx);
80
+ aio_context_acquire(old_ctx);
81
+ }
82
+
83
+ return ret;
84
}
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,
95
--
96
2.41.0
diff view generated by jsdifflib
New patch
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.
1
5
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Message-ID: <20230605085711.21261-8-kwolf@redhat.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
block.c | 25 ++++++++++++++++++++++++-
12
1 file changed, 24 insertions(+), 1 deletion(-)
13
14
diff --git a/block.c b/block.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
17
+++ b/block.c
18
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
19
int64_t total_size;
20
QemuOpts *opts = NULL;
21
BlockDriverState *bs_snapshot = NULL;
22
+ AioContext *ctx = bdrv_get_aio_context(bs);
23
int ret;
24
25
GLOBAL_STATE_CODE();
26
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
27
instead of opening 'filename' directly */
28
29
/* Get the required size from the image */
30
+ aio_context_acquire(ctx);
31
total_size = bdrv_getlength(bs);
32
+ aio_context_release(ctx);
33
+
34
if (total_size < 0) {
35
error_setg_errno(errp, -total_size, "Could not get image size");
36
goto out;
37
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
38
goto out;
39
}
40
41
+ aio_context_acquire(ctx);
42
ret = bdrv_append(bs_snapshot, bs, errp);
43
+ aio_context_release(ctx);
44
+
45
if (ret < 0) {
46
bs_snapshot = NULL;
47
goto out;
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;
73
}
74
75
+ /* The AioContext could have changed during bdrv_open_common() */
76
+ ctx = bdrv_get_aio_context(bs);
77
+
78
if (file) {
79
+ aio_context_acquire(ctx);
80
blk_unref(file);
81
+ aio_context_release(ctx);
82
file = NULL;
83
}
84
85
@@ -XXX,XX +XXX,XX @@ bdrv_open_inherit(const char *filename, const char *reference, QDict *options,
86
* (snapshot_bs); thus, we have to drop the strong reference to bs
87
* (which we obtained by calling bdrv_new()). bs will not be deleted,
88
* though, because the overlay still has a reference to it. */
89
+ aio_context_acquire(ctx);
90
bdrv_unref(bs);
91
+ aio_context_release(ctx);
92
bs = snapshot_bs;
93
}
94
95
return bs;
96
97
fail:
98
+ aio_context_acquire(ctx);
99
blk_unref(file);
100
qobject_unref(snapshot_options);
101
qobject_unref(bs->explicit_options);
102
@@ -XXX,XX +XXX,XX @@ fail:
103
bs->options = NULL;
104
bs->explicit_options = NULL;
105
bdrv_unref(bs);
106
+ aio_context_release(ctx);
107
error_propagate(errp, local_err);
108
return NULL;
109
110
close_and_fail:
111
+ aio_context_acquire(ctx);
112
bdrv_unref(bs);
113
+ aio_context_release(ctx);
114
qobject_unref(snapshot_options);
115
qobject_unref(options);
116
error_propagate(errp, local_err);
117
--
118
2.41.0
diff view generated by jsdifflib
New patch
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.
1
4
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Message-ID: <20230605085711.21261-9-kwolf@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
block.c | 5 +++++
11
1 file changed, 5 insertions(+)
12
13
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block.c
16
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
18
int ret = 0;
19
bool implicit_backing = false;
20
BlockDriverState *backing_hd;
21
+ AioContext *backing_hd_ctx;
22
QDict *options;
23
QDict *tmp_parent_options = NULL;
24
Error *local_err = NULL;
25
@@ -XXX,XX +XXX,XX @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
26
27
/* Hook up the backing file link; drop our reference, bs owns the
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);
34
+
35
if (ret < 0) {
36
goto free_exit;
37
}
38
--
39
2.41.0
diff view generated by jsdifflib
New patch
1
bdrv_root_attach_child() requires callers to hold the AioContext lock
2
for child_bs. Take it in block_job_add_bdrv() before calling the
3
function.
1
4
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Message-ID: <20230605085711.21261-10-kwolf@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
blockjob.c | 17 ++++++++++++-----
11
1 file changed, 12 insertions(+), 5 deletions(-)
12
13
diff --git a/blockjob.c b/blockjob.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/blockjob.c
16
+++ b/blockjob.c
17
@@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
18
uint64_t perm, uint64_t shared_perm, Error **errp)
19
{
20
BdrvChild *c;
21
+ AioContext *ctx = bdrv_get_aio_context(bs);
22
bool need_context_ops;
23
GLOBAL_STATE_CODE();
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;
50
--
51
2.41.0
diff view generated by jsdifflib
New patch
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.
1
4
5
Now that all callers make sure to actually have the AioContext locked
6
when they call bdrv_replace_child_noperm() like they should, we can
7
change bdrv_graph_wrlock() to take a BlockDriverState whose AioContext
8
lock the caller holds (NULL if it doesn't) and unlock it temporarily
9
while polling.
10
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Message-ID: <20230605085711.21261-11-kwolf@redhat.com>
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
16
include/block/graph-lock.h | 6 ++++--
17
block.c | 4 ++--
18
block/graph-lock.c | 23 ++++++++++++++++++++++-
19
3 files changed, 28 insertions(+), 5 deletions(-)
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:
40
diff --git a/block.c b/block.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/block.c
43
+++ b/block.c
44
@@ -XXX,XX +XXX,XX @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
45
* Replaces the node that a BdrvChild points to without updating permissions.
46
*
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;
74
+
75
GLOBAL_STATE_CODE();
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;
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
105
+
106
+ if (ctx) {
107
+ aio_context_acquire(bdrv_get_aio_context(bs));
108
+ }
109
}
110
111
void bdrv_graph_wrunlock(void)
112
--
113
2.41.0
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@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
When the 'cont' command resumes guest execution the vm change state
5
This reverts commit ad128dff0bf4b6f971d05eb4335a627883a19c1d.
4
handlers are invoked. Unfortunately there is no explicit ordering
5
between classic qemu_add_vm_change_state_handler() callbacks. When two
6
layers of code both use vm change state handlers, we don't control which
7
handler runs first.
8
6
9
virtio-scsi with iothreads hits a deadlock when a failed SCSI command is
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
restarted and completes before the iothread is re-initialized.
8
Message-ID: <20230605085711.21261-12-kwolf@redhat.com>
11
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
12
This patch uses the new qdev_add_vm_change_state_handler() API to
13
guarantee that virtio-scsi's virtio change state handler executes before
14
the SCSI bus children. This way DMA is restarted after the iothread has
15
re-initialized.
16
17
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
19
---
11
---
20
hw/scsi/scsi-bus.c | 4 ++--
12
block/graph-lock.c | 26 --------------------------
21
hw/virtio/virtio.c | 4 ++--
13
1 file changed, 26 deletions(-)
22
2 files changed, 4 insertions(+), 4 deletions(-)
23
14
24
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
15
diff --git a/block/graph-lock.c b/block/graph-lock.c
25
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/scsi/scsi-bus.c
17
--- a/block/graph-lock.c
27
+++ b/hw/scsi/scsi-bus.c
18
+++ b/block/graph-lock.c
28
@@ -XXX,XX +XXX,XX @@ static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
19
@@ -XXX,XX +XXX,XX @@ BdrvGraphLock graph_lock;
29
error_propagate(errp, local_err);
20
/* Protects the list of aiocontext and orphaned_reader_count */
30
return;
21
static QemuMutex aio_context_list_lock;
22
23
-#if 0
24
/* Written and read with atomic operations. */
25
static int has_writer;
26
-#endif
27
28
/*
29
* A reader coroutine could move from an AioContext to another.
30
@@ -XXX,XX +XXX,XX @@ void unregister_aiocontext(AioContext *ctx)
31
g_free(ctx->bdrv_graph);
32
}
33
34
-#if 0
35
static uint32_t reader_count(void)
36
{
37
BdrvGraphRWlock *brdv_graph;
38
@@ -XXX,XX +XXX,XX @@ static uint32_t reader_count(void)
39
assert((int32_t)rd >= 0);
40
return rd;
41
}
42
-#endif
43
44
void bdrv_graph_wrlock(BlockDriverState *bs)
45
{
46
AioContext *ctx = NULL;
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
57
58
/*
59
* Release only non-mainloop AioContext. The mainloop often relies on the
60
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_wrlock(BlockDriverState *bs)
61
}
31
}
62
}
32
- dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
63
33
- dev);
64
-#if 0
34
+ dev->vmsentry = qdev_add_vm_change_state_handler(DEVICE(dev),
65
/* Make sure that constantly arriving new I/O doesn't cause starvation */
35
+ scsi_dma_restart_cb, dev);
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
36
}
89
}
37
90
38
static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp)
91
void coroutine_fn bdrv_graph_co_rdlock(void)
39
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
92
{
40
index XXXXXXX..XXXXXXX 100644
93
- /* TODO Reenable when wrlock is reenabled */
41
--- a/hw/virtio/virtio.c
94
-#if 0
42
+++ b/hw/virtio/virtio.c
95
BdrvGraphRWlock *bdrv_graph;
43
@@ -XXX,XX +XXX,XX @@ void virtio_init(VirtIODevice *vdev, const char *name,
96
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
44
} else {
97
45
vdev->config = NULL;
98
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_graph_co_rdlock(void)
99
qemu_co_queue_wait(&reader_queue, &aio_context_list_lock);
100
}
46
}
101
}
47
- vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
102
-#endif
48
- vdev);
103
}
49
+ vdev->vmstate = qdev_add_vm_change_state_handler(DEVICE(vdev),
104
50
+ virtio_vmstate_change, vdev);
105
void coroutine_fn bdrv_graph_co_rdunlock(void)
51
vdev->device_endian = virtio_default_endian();
106
{
52
vdev->use_guest_notifier_mask = true;
107
-#if 0
108
BdrvGraphRWlock *bdrv_graph;
109
bdrv_graph = qemu_get_current_aio_context()->bdrv_graph;
110
111
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_graph_co_rdunlock(void)
112
if (qatomic_read(&has_writer)) {
113
aio_wait_kick();
114
}
115
-#endif
116
}
117
118
void bdrv_graph_rdlock_main_loop(void)
119
@@ -XXX,XX +XXX,XX @@ void bdrv_graph_rdunlock_main_loop(void)
120
void assert_bdrv_graph_readable(void)
121
{
122
/* reader_count() is slow due to aio_context_list_lock lock contention */
123
- /* TODO Reenable when wrlock is reenabled */
124
-#if 0
125
#ifdef CONFIG_DEBUG_GRAPH_LOCK
126
assert(qemu_in_main_thread() || reader_count());
127
#endif
128
-#endif
129
}
130
131
void assert_bdrv_graph_writable(void)
132
{
133
assert(qemu_in_main_thread());
134
- /* TODO Reenable when wrlock is reenabled */
135
-#if 0
136
assert(qatomic_read(&has_writer));
137
-#endif
53
}
138
}
54
--
139
--
55
2.20.1
140
2.41.0
56
57
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
raw_co_getlength is called by handle_aiocb_write_zeroes, which is not a coroutine
4
function. This is harmless because raw_co_getlength does not actually suspend,
5
but in the interest of clarity make it a non-coroutine_fn that is just wrapped
6
by the coroutine_fn raw_co_getlength. Likewise, check_cache_dropped was only
7
a coroutine_fn because it called raw_co_getlength, so it can be made non-coroutine
8
as well.
9
10
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
11
Message-ID: <20230601115145.196465-2-pbonzini@redhat.com>
12
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
15
block/file-posix.c | 29 +++++++++++++++++------------
16
1 file changed, 17 insertions(+), 12 deletions(-)
17
18
diff --git a/block/file-posix.c b/block/file-posix.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/file-posix.c
21
+++ b/block/file-posix.c
22
@@ -XXX,XX +XXX,XX @@ static int fd_open(BlockDriverState *bs)
23
return -EIO;
24
}
25
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)
99
+{
100
+ return raw_getlength(bs);
101
+}
102
+
103
static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverState *bs)
104
{
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)
142
--
143
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-3-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/qed-check.c | 5 +++--
13
block/qed.c | 7 ++++---
14
2 files changed, 7 insertions(+), 5 deletions(-)
15
16
diff --git a/block/qed-check.c b/block/qed-check.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qed-check.c
19
+++ b/block/qed-check.c
20
@@ -XXX,XX +XXX,XX @@ static void qed_check_for_leaks(QEDCheck *check)
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)
31
}
32
33
/* Ensure fixes reach storage before clearing check bit */
34
- bdrv_flush(s->bs);
35
+ bdrv_co_flush(s->bs);
36
37
s->header.features &= ~QED_F_NEED_CHECK;
38
qed_write_header_sync(s);
39
diff --git a/block/qed.c b/block/qed.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/block/qed.c
42
+++ b/block/qed.c
43
@@ -XXX,XX +XXX,XX @@ static bool qed_is_image_size_valid(uint64_t image_size, uint32_t cluster_size,
44
*
45
* The string is NUL-terminated.
46
*/
47
-static int qed_read_string(BdrvChild *file, uint64_t offset, size_t n,
48
- char *buf, size_t buflen)
49
+static int coroutine_fn GRAPH_RDLOCK
50
+qed_read_string(BdrvChild *file, uint64_t offset,
51
+ size_t n, char *buf, size_t buflen)
52
{
53
int ret;
54
if (n >= buflen) {
55
return -EINVAL;
56
}
57
- ret = bdrv_pread(file, offset, n, buf, 0);
58
+ ret = bdrv_co_pread(file, offset, n, buf, 0);
59
if (ret < 0) {
60
return ret;
61
}
62
--
63
2.41.0
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Add an API for registering vm change state handlers with a well-defined
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
ordering. This is necessary when handlers depend on each other.
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
Small coding style fixes are included to make checkpatch.pl happy.
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
8
Message-ID: <20230601115145.196465-4-pbonzini@redhat.com>
8
Signed-off-by: Stefan Hajnoczi <stefanha@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/sysemu/sysemu.h | 2 ++
12
block/vpc.c | 52 ++++++++++++++++++++++++++--------------------------
12
vl.c | 59 ++++++++++++++++++++++++++++++++---------
13
1 file changed, 26 insertions(+), 26 deletions(-)
13
2 files changed, 49 insertions(+), 12 deletions(-)
14
14
15
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
15
diff --git a/block/vpc.c b/block/vpc.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/sysemu/sysemu.h
17
--- a/block/vpc.c
18
+++ b/include/sysemu/sysemu.h
18
+++ b/block/vpc.c
19
@@ -XXX,XX +XXX,XX @@ typedef void VMChangeStateHandler(void *opaque, int running, RunState state);
19
@@ -XXX,XX +XXX,XX @@ static int vpc_reopen_prepare(BDRVReopenState *state,
20
20
* operation (the block bitmaps is updated then), 0 otherwise.
21
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
21
* If write is true then err must not be NULL.
22
void *opaque);
22
*/
23
+VMChangeStateEntry *qemu_add_vm_change_state_handler_prio(
23
-static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
24
+ VMChangeStateHandler *cb, void *opaque, int priority);
24
- bool write, int *err)
25
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
25
+static int64_t coroutine_fn GRAPH_RDLOCK
26
void vm_state_notify(int running, RunState state);
26
+get_image_offset(BlockDriverState *bs, uint64_t offset, bool write, int *err)
27
28
diff --git a/vl.c b/vl.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/vl.c
31
+++ b/vl.c
32
@@ -XXX,XX +XXX,XX @@ static int machine_help_func(QemuOpts *opts, MachineState *machine)
33
struct vm_change_state_entry {
34
VMChangeStateHandler *cb;
35
void *opaque;
36
- QLIST_ENTRY (vm_change_state_entry) entries;
37
+ QTAILQ_ENTRY(vm_change_state_entry) entries;
38
+ int priority;
39
};
40
41
-static QLIST_HEAD(, vm_change_state_entry) vm_change_state_head;
42
+static QTAILQ_HEAD(, vm_change_state_entry) vm_change_state_head;
43
44
-VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
45
- void *opaque)
46
+/**
47
+ * qemu_add_vm_change_state_handler_prio:
48
+ * @cb: the callback to invoke
49
+ * @opaque: user data passed to the callback
50
+ * @priority: low priorities execute first when the vm runs and the reverse is
51
+ * true when the vm stops
52
+ *
53
+ * Register a callback function that is invoked when the vm starts or stops
54
+ * running.
55
+ *
56
+ * Returns: an entry to be freed using qemu_del_vm_change_state_handler()
57
+ */
58
+VMChangeStateEntry *qemu_add_vm_change_state_handler_prio(
59
+ VMChangeStateHandler *cb, void *opaque, int priority)
60
{
27
{
61
VMChangeStateEntry *e;
28
BDRVVPCState *s = bs->opaque;
62
+ VMChangeStateEntry *other;
29
uint64_t bitmap_offset, block_offset;
63
30
@@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
64
- e = g_malloc0(sizeof (*e));
31
65
-
32
s->last_bitmap_offset = bitmap_offset;
66
+ e = g_malloc0(sizeof(*e));
33
memset(bitmap, 0xff, s->bitmap_size);
67
e->cb = cb;
34
- r = bdrv_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap,
68
e->opaque = opaque;
35
- 0);
69
- QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
36
+ r = bdrv_co_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap, 0);
70
+ e->priority = priority;
37
if (r < 0) {
71
+
38
*err = r;
72
+ /* Keep list sorted in ascending priority order */
39
return -2;
73
+ QTAILQ_FOREACH(other, &vm_change_state_head, entries) {
40
@@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
74
+ if (priority < other->priority) {
41
*
75
+ QTAILQ_INSERT_BEFORE(other, e, entries);
42
* Returns 0 on success and < 0 on error
76
+ return e;
43
*/
77
+ }
44
-static int rewrite_footer(BlockDriverState *bs)
78
+ }
45
+static int coroutine_fn GRAPH_RDLOCK rewrite_footer(BlockDriverState *bs)
79
+
46
{
80
+ QTAILQ_INSERT_TAIL(&vm_change_state_head, e, entries);
47
int ret;
81
return e;
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:
87
return ret;
82
}
88
}
83
89
84
+VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
90
-static int coroutine_fn vpc_co_block_status(BlockDriverState *bs,
85
+ void *opaque)
91
- bool want_zero,
86
+{
92
- int64_t offset, int64_t bytes,
87
+ return qemu_add_vm_change_state_handler_prio(cb, opaque, 0);
93
- int64_t *pnum, int64_t *map,
88
+}
94
- BlockDriverState **file)
89
+
95
+static int coroutine_fn GRAPH_RDLOCK
90
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
96
+vpc_co_block_status(BlockDriverState *bs, bool want_zero,
97
+ int64_t offset, int64_t bytes,
98
+ int64_t *pnum, int64_t *map,
99
+ BlockDriverState **file)
91
{
100
{
92
- QLIST_REMOVE (e, entries);
101
BDRVVPCState *s = bs->opaque;
93
- g_free (e);
102
int64_t image_offset;
94
+ QTAILQ_REMOVE(&vm_change_state_head, e, entries);
103
@@ -XXX,XX +XXX,XX @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls,
95
+ g_free(e);
104
return 0;
96
}
105
}
97
106
98
void vm_state_notify(int running, RunState state)
107
-static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
99
@@ -XXX,XX +XXX,XX @@ void vm_state_notify(int running, RunState state)
108
- int64_t total_sectors)
100
109
+static int coroutine_fn create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
101
trace_vm_state_notify(running, state, RunState_str(state));
110
+ int64_t total_sectors)
102
111
{
103
- QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
112
VHDDynDiskHeader dyndisk_header;
104
- e->cb(e->opaque, running, state);
113
uint8_t bat_sector[512];
105
+ if (running) {
114
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
106
+ QTAILQ_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
115
block_size = 0x200000;
107
+ e->cb(e->opaque, running, state);
116
num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512);
108
+ }
117
109
+ } else {
118
- ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
110
+ QTAILQ_FOREACH_REVERSE_SAFE(e, &vm_change_state_head, entries, next) {
119
+ ret = blk_co_pwrite(blk, offset, sizeof(*footer), footer, 0);
111
+ e->cb(e->opaque, running, state);
120
if (ret < 0) {
112
+ }
121
goto fail;
113
}
122
}
123
124
offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
125
- ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
126
+ ret = blk_co_pwrite(blk, offset, sizeof(*footer), footer, 0);
127
if (ret < 0) {
128
goto fail;
129
}
130
@@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
131
132
memset(bat_sector, 0xFF, 512);
133
for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) {
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;
114
}
150
}
115
151
116
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
152
-static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer,
117
exit(1);
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;
118
}
166
}
119
167
120
- QLIST_INIT (&vm_change_state_head);
168
- ret = blk_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
121
+ QTAILQ_INIT(&vm_change_state_head);
169
- footer, 0);
122
os_setup_early_signal_handling();
170
+ ret = blk_co_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
123
171
+ footer, 0);
124
cpu_option = NULL;
172
if (ret < 0) {
173
error_setg_errno(errp, -ret, "Unable to write VHD header");
174
return ret;
125
--
175
--
126
2.20.1
176
2.41.0
127
128
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-5-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/bochs.c | 7 ++++---
13
1 file changed, 4 insertions(+), 3 deletions(-)
14
15
diff --git a/block/bochs.c b/block/bochs.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/bochs.c
18
+++ b/block/bochs.c
19
@@ -XXX,XX +XXX,XX @@ static void bochs_refresh_limits(BlockDriverState *bs, Error **errp)
20
bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
21
}
22
23
-static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
24
+static int64_t coroutine_fn GRAPH_RDLOCK
25
+seek_to_sector(BlockDriverState *bs, int64_t sector_num)
26
{
27
BDRVBochsState *s = bs->opaque;
28
uint64_t offset = sector_num * 512;
29
@@ -XXX,XX +XXX,XX @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
30
(s->extent_blocks + s->bitmap_blocks));
31
32
/* read in bitmap for current extent */
33
- ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), 1,
34
- &bitmap_entry, 0);
35
+ ret = bdrv_co_pread(bs->file, bitmap_offset + (extent_offset / 8), 1,
36
+ &bitmap_entry, 0);
37
if (ret < 0) {
38
return ret;
39
}
40
--
41
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
and they can suspend. Because this function operates on a BlockBackend, mark it
5
GRAPH_UNLOCKED.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-6-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block.c | 11 ++++++-----
13
1 file changed, 6 insertions(+), 5 deletions(-)
14
15
diff --git a/block.c b/block.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block.c
18
+++ b/block.c
19
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
20
* On success, return @blk's actual length.
21
* Otherwise, return -errno.
22
*/
23
-static int64_t create_file_fallback_truncate(BlockBackend *blk,
24
- int64_t minimum_size, Error **errp)
25
+static int64_t coroutine_fn GRAPH_UNLOCKED
26
+create_file_fallback_truncate(BlockBackend *blk, int64_t minimum_size,
27
+ Error **errp)
28
{
29
Error *local_err = NULL;
30
int64_t size;
31
@@ -XXX,XX +XXX,XX @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
32
33
GLOBAL_STATE_CODE();
34
35
- ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
36
- &local_err);
37
+ ret = blk_co_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
38
+ &local_err);
39
if (ret < 0 && ret != -ENOTSUP) {
40
error_propagate(errp, local_err);
41
return ret;
42
}
43
44
- size = blk_getlength(blk);
45
+ size = blk_co_getlength(blk);
46
if (size < 0) {
47
error_free(local_err);
48
error_setg_errno(errp, -size,
49
--
50
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
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>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/cloop.c | 9 +++++----
13
1 file changed, 5 insertions(+), 4 deletions(-)
14
15
diff --git a/block/cloop.c b/block/cloop.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/cloop.c
18
+++ b/block/cloop.c
19
@@ -XXX,XX +XXX,XX @@ static void cloop_refresh_limits(BlockDriverState *bs, Error **errp)
20
bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */
21
}
22
23
-static inline int cloop_read_block(BlockDriverState *bs, int block_num)
24
+static int coroutine_fn GRAPH_RDLOCK
25
+cloop_read_block(BlockDriverState *bs, int block_num)
26
{
27
BDRVCloopState *s = bs->opaque;
28
29
@@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num)
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;
42
}
43
44
-static int coroutine_fn
45
+static int coroutine_fn GRAPH_RDLOCK
46
cloop_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
47
QEMUIOVector *qiov, BdrvRequestFlags flags)
48
{
49
--
50
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-8-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/dmg.c | 21 +++++++++++----------
13
1 file changed, 11 insertions(+), 10 deletions(-)
14
15
diff --git a/block/dmg.c b/block/dmg.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/dmg.c
18
+++ b/block/dmg.c
19
@@ -XXX,XX +XXX,XX @@ err:
20
return s->n_chunks; /* error */
21
}
22
23
-static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
24
+static int coroutine_fn GRAPH_RDLOCK
25
+dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
26
{
27
BDRVDMGState *s = bs->opaque;
28
29
@@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
30
case UDZO: { /* zlib compressed */
31
/* we need to buffer, because only the chunk as whole can be
32
* inflated. */
33
- ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
34
- s->compressed_chunk, 0);
35
+ ret = bdrv_co_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
36
+ s->compressed_chunk, 0);
37
if (ret < 0) {
38
return -1;
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;
75
}
76
77
-static int coroutine_fn
78
+static int coroutine_fn GRAPH_RDLOCK
79
dmg_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
80
QEMUIOVector *qiov, BdrvRequestFlags flags)
81
{
82
--
83
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-9-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/vmdk.c | 27 ++++++++++++++-------------
13
1 file changed, 14 insertions(+), 13 deletions(-)
14
15
diff --git a/block/vmdk.c b/block/vmdk.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/vmdk.c
18
+++ b/block/vmdk.c
19
@@ -XXX,XX +XXX,XX @@ out:
20
return ret;
21
}
22
23
-static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
24
+static int coroutine_fn GRAPH_RDLOCK
25
+vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
26
{
27
char *desc, *tmp_desc;
28
char *p_name, *tmp_str;
29
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
30
31
desc = g_malloc0(DESC_SIZE);
32
tmp_desc = g_malloc0(DESC_SIZE);
33
- ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
34
+ ret = bdrv_co_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
35
if (ret < 0) {
36
goto out;
37
}
38
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
39
pstrcat(desc, DESC_SIZE, tmp_desc);
40
}
41
42
- ret = bdrv_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
43
+ ret = bdrv_co_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
44
45
out:
46
g_free(desc);
47
@@ -XXX,XX +XXX,XX @@ vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
48
return ret;
49
}
50
51
-static int GRAPH_UNLOCKED
52
+static int coroutine_fn GRAPH_UNLOCKED
53
vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
54
bool zeroed_grain, Error **errp)
55
{
56
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
57
int gd_buf_size;
58
59
if (flat) {
60
- ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
61
+ ret = blk_co_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
62
goto exit;
63
}
64
magic = cpu_to_be32(VMDK4_MAGIC);
65
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
66
header.check_bytes[3] = 0xa;
67
68
/* write all the data */
69
- ret = blk_pwrite(blk, 0, sizeof(magic), &magic, 0);
70
+ ret = blk_co_pwrite(blk, 0, sizeof(magic), &magic, 0);
71
if (ret < 0) {
72
error_setg(errp, QERR_IO_ERROR);
73
goto exit;
74
}
75
- ret = blk_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
76
+ ret = blk_co_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
77
if (ret < 0) {
78
error_setg(errp, QERR_IO_ERROR);
79
goto exit;
80
}
81
82
- ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
83
- PREALLOC_MODE_OFF, 0, errp);
84
+ ret = blk_co_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
85
+ PREALLOC_MODE_OFF, 0, errp);
86
if (ret < 0) {
87
goto exit;
88
}
89
@@ -XXX,XX +XXX,XX @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
90
i < gt_count; i++, tmp += gt_size) {
91
gd_buf[i] = cpu_to_le32(tmp);
92
}
93
- ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
94
- gd_buf_size, gd_buf, 0);
95
+ ret = blk_co_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
96
+ gd_buf_size, gd_buf, 0);
97
if (ret < 0) {
98
error_setg(errp, QERR_IO_ERROR);
99
goto exit;
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
}
111
--
112
2.41.0
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
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.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-10-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/vhdx.h | 5 ++--
13
block/vhdx-log.c | 36 +++++++++++++-----------
14
block/vhdx.c | 73 +++++++++++++++++++++++-------------------------
15
3 files changed, 57 insertions(+), 57 deletions(-)
16
17
diff --git a/block/vhdx.h b/block/vhdx.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/vhdx.h
20
+++ b/block/vhdx.h
21
@@ -XXX,XX +XXX,XX @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset);
22
int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
23
Error **errp);
24
25
-int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
26
- void *data, uint32_t length, uint64_t offset);
27
+int coroutine_fn GRAPH_RDLOCK
28
+vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
29
+ void *data, uint32_t length, uint64_t offset);
30
31
static inline void leguid_to_cpus(MSGUID *guid)
32
{
33
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/block/vhdx-log.c
36
+++ b/block/vhdx-log.c
37
@@ -XXX,XX +XXX,XX @@ exit:
38
* It is assumed that 'buffer' is at least 4096*num_sectors large.
39
*
40
* 0 is returned on success, -errno otherwise */
41
-static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
42
- uint32_t *sectors_written, void *buffer,
43
- uint32_t num_sectors)
44
+static int coroutine_fn GRAPH_RDLOCK
45
+vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
46
+ uint32_t *sectors_written, void *buffer,
47
+ uint32_t num_sectors)
48
{
49
int ret = 0;
50
uint64_t offset;
51
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
52
/* full */
53
break;
54
}
55
- ret = bdrv_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp,
56
- 0);
57
+ ret = bdrv_co_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp, 0);
58
if (ret < 0) {
59
goto exit;
60
}
61
@@ -XXX,XX +XXX,XX @@ static void vhdx_log_raw_to_le_sector(VHDXLogDescriptor *desc,
62
}
63
64
65
-static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
66
- void *data, uint32_t length, uint64_t offset)
67
+static int coroutine_fn GRAPH_RDLOCK
68
+vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
69
+ void *data, uint32_t length, uint64_t offset)
70
{
71
int ret = 0;
72
void *buffer = NULL;
73
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
74
75
sectors += partial_sectors;
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:
107
}
108
109
/* Perform a log write, and then immediately flush the entire log */
110
-int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
111
- void *data, uint32_t length, uint64_t offset)
112
+int coroutine_fn
113
+vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
114
+ void *data, uint32_t length, uint64_t offset)
115
{
116
int ret = 0;
117
VHDXLogSequence logs = { .valid = true,
118
@@ -XXX,XX +XXX,XX @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
119
120
/* Make sure data written (new and/or changed blocks) is stable
121
* on disk, before creating log entry */
122
- ret = bdrv_flush(bs);
123
+ ret = bdrv_co_flush(bs);
124
if (ret < 0) {
125
goto exit;
126
}
127
@@ -XXX,XX +XXX,XX @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
128
logs.log = s->log;
129
130
/* Make sure log is stable on disk */
131
- ret = bdrv_flush(bs);
132
+ ret = bdrv_co_flush(bs);
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);
175
}
176
177
/*
178
@@ -XXX,XX +XXX,XX @@ exit:
179
* The first 64KB of the Metadata section is reserved for the metadata
180
* header and entries; beyond that, the metadata items themselves reside.
181
*/
182
-static int vhdx_create_new_metadata(BlockBackend *blk,
183
- uint64_t image_size,
184
- uint32_t block_size,
185
- uint32_t sector_size,
186
- uint64_t metadata_offset,
187
- VHDXImageType type)
188
+static int coroutine_fn
189
+vhdx_create_new_metadata(BlockBackend *blk, uint64_t image_size,
190
+ uint32_t block_size, uint32_t sector_size,
191
+ uint64_t metadata_offset, VHDXImageType type)
192
{
193
int ret = 0;
194
uint32_t offset = 0;
195
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_new_metadata(BlockBackend *blk,
196
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
197
vhdx_metadata_entry_le_export(&md_table_entry[4]);
198
199
- ret = blk_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
200
+ ret = blk_co_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
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;
298
--
299
2.41.0
diff view generated by jsdifflib
1
From: Jason Dillaman <dillaman@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Remove Josh as per his request since he is no longer the upstream RBD
3
Mark functions as coroutine_fn when they are only called by other coroutine_fns
4
tech lead. Add myself as the maintainer since I am the current RBD tech
4
and they can suspend. Change calls to co_wrappers to use the non-wrapped
5
lead.
5
functions, which in turn requires adding GRAPH_RDLOCK annotations.
6
6
7
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Reviewed-by: Josh Durgin <jdurgin@redhat.com>
8
Message-ID: <20230601115145.196465-11-pbonzini@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
MAINTAINERS | 2 +-
12
block/qcow2.h | 33 +++++------
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
block/qcow2-bitmap.c | 26 +++++----
14
block/qcow2-cluster.c | 12 ++--
15
block/qcow2-refcount.c | 130 +++++++++++++++++++++--------------------
16
block/qcow2.c | 2 +-
17
5 files changed, 105 insertions(+), 98 deletions(-)
13
18
14
diff --git a/MAINTAINERS b/MAINTAINERS
19
diff --git a/block/qcow2.h b/block/qcow2.h
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/MAINTAINERS
21
--- a/block/qcow2.h
17
+++ b/MAINTAINERS
22
+++ b/block/qcow2.h
18
@@ -XXX,XX +XXX,XX @@ S: Supported
23
@@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
19
F: block/vmdk.c
24
20
25
int qcow2_mark_dirty(BlockDriverState *bs);
21
RBD
26
int qcow2_mark_corrupt(BlockDriverState *bs);
22
-M: Josh Durgin <jdurgin@redhat.com>
27
-int qcow2_mark_consistent(BlockDriverState *bs);
23
+M: Jason Dillaman <dillaman@redhat.com>
28
int qcow2_update_header(BlockDriverState *bs);
24
L: qemu-block@nongnu.org
29
25
S: Supported
30
void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
26
F: block/rbd.c
31
@@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
32
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
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
99
index XXXXXXX..XXXXXXX 100644
100
--- a/block/qcow2-bitmap.c
101
+++ b/block/qcow2-bitmap.c
102
@@ -XXX,XX +XXX,XX @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb)
103
/* load_bitmap_data
104
* @bitmap_table entries must satisfy specification constraints.
105
* @bitmap must be cleared */
106
-static int load_bitmap_data(BlockDriverState *bs,
107
- const uint64_t *bitmap_table,
108
- uint32_t bitmap_table_size,
109
- BdrvDirtyBitmap *bitmap)
110
+static int coroutine_fn GRAPH_RDLOCK
111
+load_bitmap_data(BlockDriverState *bs, const uint64_t *bitmap_table,
112
+ uint32_t bitmap_table_size, BdrvDirtyBitmap *bitmap)
113
{
114
int ret = 0;
115
BDRVQcow2State *s = bs->opaque;
116
@@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs,
117
* already cleared */
118
}
119
} else {
120
- ret = bdrv_pread(bs->file, data_offset, s->cluster_size, buf, 0);
121
+ ret = bdrv_co_pread(bs->file, data_offset, s->cluster_size, buf, 0);
122
if (ret < 0) {
123
goto finish;
124
}
125
@@ -XXX,XX +XXX,XX @@ finish:
126
return ret;
127
}
128
129
-static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
130
- Qcow2Bitmap *bm, Error **errp)
131
+static coroutine_fn GRAPH_RDLOCK
132
+BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
133
+ Qcow2Bitmap *bm, Error **errp)
134
{
135
int ret;
136
uint64_t *bitmap_table = NULL;
137
@@ -XXX,XX +XXX,XX @@ fail:
138
return NULL;
139
}
140
141
-int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
142
- void **refcount_table,
143
- int64_t *refcount_table_size)
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;
224
}
225
226
- file_len = bdrv_getlength(bs->file->bs);
227
+ file_len = bdrv_co_getlength(bs->file->bs);
228
if (file_len < 0) {
229
return file_len;
230
}
231
@@ -XXX,XX +XXX,XX @@ enum {
232
*
233
* On failure in-memory @l2_table may be modified.
234
*/
235
-static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
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;
249
}
250
251
- ret = bdrv_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s),
252
- &l2_table[idx], 0);
253
+ ret = bdrv_co_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s),
254
+ &l2_table[idx], 0);
255
if (ret < 0) {
256
fprintf(stderr, "ERROR: Failed to overwrite L2 "
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,
302
}
303
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,
441
}
442
443
assert(reftable_length < INT_MAX);
444
- ret = bdrv_pwrite(bs->file, reftable_offset, reftable_length,
445
- on_disk_reftable, 0);
446
+ ret = bdrv_co_pwrite(bs->file, reftable_offset, reftable_length,
447
+ on_disk_reftable, 0);
448
if (ret < 0) {
449
error_setg_errno(errp, -ret, "ERROR writing reftable");
450
goto fail;
451
@@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs,
452
reftable_offset_and_clusters.reftable_offset = cpu_to_be64(reftable_offset);
453
reftable_offset_and_clusters.reftable_clusters =
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;
479
int ret;
480
481
- size = bdrv_getlength(bs->file->bs);
482
+ size = bdrv_co_getlength(bs->file->bs);
483
if (size < 0) {
484
res->check_errors++;
485
return size;
486
@@ -XXX,XX +XXX,XX @@ done:
487
return ret;
488
}
489
490
-static int64_t get_refblock_offset(BlockDriverState *bs, uint64_t offset)
491
+static int64_t coroutine_fn get_refblock_offset(BlockDriverState *bs,
492
+ uint64_t offset)
493
{
494
BDRVQcow2State *s = bs->opaque;
495
uint32_t index = offset_to_reftable_index(s, offset);
496
@@ -XXX,XX +XXX,XX @@ int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size)
497
return -EIO;
498
}
499
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
507
index XXXXXXX..XXXXXXX 100644
508
--- a/block/qcow2.c
509
+++ b/block/qcow2.c
510
@@ -XXX,XX +XXX,XX @@ int qcow2_mark_corrupt(BlockDriverState *bs)
511
* Marks the image as consistent, i.e., unsets the corrupt bit, and flushes
512
* before if necessary.
513
*/
514
-int qcow2_mark_consistent(BlockDriverState *bs)
515
+static int coroutine_fn qcow2_mark_consistent(BlockDriverState *bs)
516
{
517
BDRVQcow2State *s = bs->opaque;
518
27
--
519
--
28
2.20.1
520
2.41.0
29
30
diff view generated by jsdifflib
1
From: John Snow <jsnow@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Reported-by: radmehrsaeed7@gmail.com
3
bdrv_co_getlength was recently introduced, with bdrv_getlength becoming
4
Fixes: https://bugs.launchpad.net/bugs/1832914
4
a wrapper for use in unknown context. Switch to bdrv_co_getlength when
5
Signed-off-by: John Snow <jsnow@redhat.com>
5
possible.
6
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
6
7
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-ID: <20230601115145.196465-12-pbonzini@redhat.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
11
---
10
block/qcow.c | 7 ++++++-
12
block/io.c | 10 +++++-----
11
1 file changed, 6 insertions(+), 1 deletion(-)
13
block/parallels.c | 4 ++--
14
block/qcow.c | 6 +++---
15
block/vmdk.c | 4 ++--
16
4 files changed, 12 insertions(+), 12 deletions(-)
12
17
18
diff --git a/block/io.c b/block/io.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/io.c
21
+++ b/block/io.c
22
@@ -XXX,XX +XXX,XX @@ bdrv_aligned_preadv(BdrvChild *child, BdrvTrackedRequest *req,
23
}
24
25
/* Forward the request to the BlockDriver, possibly fragmenting it */
26
- total_bytes = bdrv_getlength(bs);
27
+ total_bytes = bdrv_co_getlength(bs);
28
if (total_bytes < 0) {
29
ret = total_bytes;
30
goto out;
31
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
32
assert(pnum);
33
assert_bdrv_graph_readable();
34
*pnum = 0;
35
- total_size = bdrv_getlength(bs);
36
+ total_size = bdrv_co_getlength(bs);
37
if (total_size < 0) {
38
ret = total_size;
39
goto early_out;
40
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
41
bytes = n;
42
}
43
44
- /* Must be non-NULL or bdrv_getlength() would have failed */
45
+ /* Must be non-NULL or bdrv_co_getlength() would have failed */
46
assert(bs->drv);
47
has_filtered_child = bdrv_filter_child(bs);
48
if (!bs->drv->bdrv_co_block_status && !has_filtered_child) {
49
@@ -XXX,XX +XXX,XX @@ bdrv_co_block_status(BlockDriverState *bs, bool want_zero,
50
if (!cow_bs) {
51
ret |= BDRV_BLOCK_ZERO;
52
} else if (want_zero) {
53
- int64_t size2 = bdrv_getlength(cow_bs);
54
+ int64_t size2 = bdrv_co_getlength(cow_bs);
55
56
if (size2 >= 0 && offset >= size2) {
57
ret |= BDRV_BLOCK_ZERO;
58
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
59
return ret;
60
}
61
62
- old_size = bdrv_getlength(bs);
63
+ old_size = bdrv_co_getlength(bs);
64
if (old_size < 0) {
65
error_setg_errno(errp, -old_size, "Failed to get old image size");
66
return old_size;
67
diff --git a/block/parallels.c b/block/parallels.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/block/parallels.c
70
+++ b/block/parallels.c
71
@@ -XXX,XX +XXX,XX @@ allocate_clusters(BlockDriverState *bs, int64_t sector_num,
72
assert(idx < s->bat_size && idx + to_allocate <= s->bat_size);
73
74
space = to_allocate * s->tracks;
75
- len = bdrv_getlength(bs->file->bs);
76
+ len = bdrv_co_getlength(bs->file->bs);
77
if (len < 0) {
78
return len;
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;
13
diff --git a/block/qcow.c b/block/qcow.c
89
diff --git a/block/qcow.c b/block/qcow.c
14
index XXXXXXX..XXXXXXX 100644
90
index XXXXXXX..XXXXXXX 100644
15
--- a/block/qcow.c
91
--- a/block/qcow.c
16
+++ b/block/qcow.c
92
+++ b/block/qcow.c
17
@@ -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,
18
goto fail;
94
if (!allocate)
19
}
95
return 0;
20
if (header.version != QCOW_VERSION) {
96
/* allocate a new l2 entry */
21
- error_setg(errp, "Unsupported qcow version %" PRIu32, header.version);
97
- l2_offset = bdrv_getlength(bs->file->bs);
22
+ error_setg(errp, "qcow (v%d) does not support qcow version %" PRIu32,
98
+ l2_offset = bdrv_co_getlength(bs->file->bs);
23
+ QCOW_VERSION, header.version);
99
if (l2_offset < 0) {
24
+ if (header.version == 2 || header.version == 3) {
100
return l2_offset;
25
+ error_append_hint(errp, "Try the 'qcow2' driver instead.\n");
101
}
26
+ }
102
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
27
+
103
if (decompress_cluster(bs, cluster_offset) < 0) {
28
ret = -ENOTSUP;
104
return -EIO;
29
goto fail;
105
}
30
}
106
- cluster_offset = bdrv_getlength(bs->file->bs);
107
+ cluster_offset = bdrv_co_getlength(bs->file->bs);
108
if ((int64_t) cluster_offset < 0) {
109
return cluster_offset;
110
}
111
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
112
return ret;
113
}
114
} else {
115
- cluster_offset = bdrv_getlength(bs->file->bs);
116
+ cluster_offset = bdrv_co_getlength(bs->file->bs);
117
if ((int64_t) cluster_offset < 0) {
118
return cluster_offset;
119
}
120
diff --git a/block/vmdk.c b/block/vmdk.c
121
index XXXXXXX..XXXXXXX 100644
122
--- a/block/vmdk.c
123
+++ b/block/vmdk.c
124
@@ -XXX,XX +XXX,XX @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
125
int64_t length;
126
127
for (i = 0; i < s->num_extents; i++) {
128
- length = bdrv_getlength(s->extents[i].file->bs);
129
+ length = bdrv_co_getlength(s->extents[i].file->bs);
130
if (length < 0) {
131
return length;
132
}
133
@@ -XXX,XX +XXX,XX @@ vmdk_co_check(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix)
134
break;
135
}
136
if (ret == VMDK_OK) {
137
- int64_t extent_len = bdrv_getlength(extent->file->bs);
138
+ int64_t extent_len = bdrv_co_getlength(extent->file->bs);
139
if (extent_len < 0) {
140
fprintf(stderr,
141
"ERROR: could not get extent file length for sector %"
31
--
142
--
32
2.20.1
143
2.41.0
33
34
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Commit b76b4f60 allowed '-o compat=v3' as an alias for the
3
bdrv_co_debug_event was recently introduced, with bdrv_debug_event
4
less-appealing '-o compat=1.1' for 'qemu-img create' since we want to
4
becoming a wrapper for use in unknown context. Because most of the
5
use the QMP form as much as possible, but forgot to do likewise for
5
time bdrv_debug_event is used on a BdrvChild via the wrapper macro
6
qemu-img amend. Also, it doesn't help that '-o help' doesn't list our
6
BLKDBG_EVENT, introduce a similar macro BLKDBG_CO_EVENT that calls
7
new preferred spellings.
7
bdrv_co_debug_event, and switch whenever possible.
8
8
9
Signed-off-by: Eric Blake <eblake@redhat.com>
9
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
10
Message-ID: <20230601115145.196465-13-pbonzini@redhat.com>
11
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
13
---
12
block/qcow2.c | 6 +++---
14
include/block/block-io.h | 7 +++++++
13
1 file changed, 3 insertions(+), 3 deletions(-)
15
block/io.c | 4 ++--
16
block/qcow.c | 24 ++++++++++++------------
17
block/qcow2-cluster.c | 12 ++++++------
18
block/qcow2-refcount.c | 4 ++--
19
block/qcow2.c | 18 +++++++++---------
20
block/qed-table.c | 6 +++---
21
block/qed.c | 8 ++++----
22
block/raw-format.c | 4 ++--
23
block/vmdk.c | 24 ++++++++++++------------
24
10 files changed, 59 insertions(+), 52 deletions(-)
14
25
26
diff --git a/include/block/block-io.h b/include/block/block-io.h
27
index XXXXXXX..XXXXXXX 100644
28
--- a/include/block/block-io.h
29
+++ b/include/block/block-io.h
30
@@ -XXX,XX +XXX,XX @@ bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event);
31
void co_wrapper_mixed_bdrv_rdlock
32
bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event);
33
34
+#define BLKDBG_CO_EVENT(child, evt) \
35
+ do { \
36
+ if (child) { \
37
+ bdrv_co_debug_event(child->bs, evt); \
38
+ } \
39
+ } while (0)
40
+
41
#define BLKDBG_EVENT(child, evt) \
42
do { \
43
if (child) { \
44
diff --git a/block/io.c b/block/io.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/block/io.c
47
+++ b/block/io.c
48
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
49
}
50
51
/* Write back cached data to the OS even with cache=unsafe */
52
- BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_OS);
53
+ BLKDBG_CO_EVENT(primary_child, BLKDBG_FLUSH_TO_OS);
54
if (bs->drv->bdrv_co_flush_to_os) {
55
ret = bs->drv->bdrv_co_flush_to_os(bs);
56
if (ret < 0) {
57
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
58
goto flush_children;
59
}
60
61
- BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK);
62
+ BLKDBG_CO_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK);
63
if (!bs->drv) {
64
/* bs->drv->bdrv_co_flush() might have ejected the BDS
65
* (even in case of apparent success) */
66
diff --git a/block/qcow.c b/block/qcow.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/block/qcow.c
69
+++ b/block/qcow.c
70
@@ -XXX,XX +XXX,XX @@ get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
71
/* update the L1 entry */
72
s->l1_table[l1_index] = l2_offset;
73
tmp = cpu_to_be64(l2_offset);
74
- BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
75
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_L1_UPDATE);
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));
251
15
diff --git a/block/qcow2.c b/block/qcow2.c
252
diff --git a/block/qcow2.c b/block/qcow2.c
16
index XXXXXXX..XXXXXXX 100644
253
index XXXXXXX..XXXXXXX 100644
17
--- a/block/qcow2.c
254
--- a/block/qcow2.c
18
+++ b/block/qcow2.c
255
+++ b/block/qcow2.c
19
@@ -XXX,XX +XXX,XX @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
256
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_encrypted(BlockDriverState *bs,
20
compat = qemu_opt_get(opts, BLOCK_OPT_COMPAT_LEVEL);
257
return -ENOMEM;
21
if (!compat) {
258
}
22
/* preserve default */
259
23
- } else if (!strcmp(compat, "0.10")) {
260
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
24
+ } else if (!strcmp(compat, "0.10") || !strcmp(compat, "v2")) {
261
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
25
new_version = 2;
262
ret = bdrv_co_pread(s->data_file, host_offset, bytes, buf, 0);
26
- } else if (!strcmp(compat, "1.1")) {
263
if (ret < 0) {
27
+ } else if (!strcmp(compat, "1.1") || !strcmp(compat, "v3")) {
264
goto fail;
28
new_version = 3;
265
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type,
29
} else {
266
case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC:
30
error_setg(errp, "Unknown compatibility level %s", compat);
267
assert(bs->backing); /* otherwise handled in qcow2_co_preadv_part */
31
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qcow2_create_opts = {
268
32
{
269
- BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
33
.name = BLOCK_OPT_COMPAT_LEVEL,
270
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
34
.type = QEMU_OPT_STRING,
271
return bdrv_co_preadv_part(bs->backing, offset, bytes,
35
- .help = "Compatibility level (0.10 or 1.1)"
272
qiov, qiov_offset, 0);
36
+ .help = "Compatibility level (v2 [0.10] or v3 [1.1])"
273
37
},
274
@@ -XXX,XX +XXX,XX @@ qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type,
38
{
275
offset, bytes, qiov, qiov_offset);
39
.name = BLOCK_OPT_BACKING_FILE,
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
}
368
diff --git a/block/qed.c b/block/qed.c
369
index XXXXXXX..XXXXXXX 100644
370
--- a/block/qed.c
371
+++ b/block/qed.c
372
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn GRAPH_RDLOCK
373
qed_read_backing_file(BDRVQEDState *s, uint64_t pos, QEMUIOVector *qiov)
374
{
375
if (s->bs->backing) {
376
- BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
377
+ BLKDBG_CO_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
378
return bdrv_co_preadv(s->bs->backing, pos, qiov->size, qiov, 0);
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
}
408
diff --git a/block/raw-format.c b/block/raw-format.c
409
index XXXXXXX..XXXXXXX 100644
410
--- a/block/raw-format.c
411
+++ b/block/raw-format.c
412
@@ -XXX,XX +XXX,XX @@ raw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
413
return ret;
414
}
415
416
- BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
417
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_READ_AIO);
418
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
419
}
420
421
@@ -XXX,XX +XXX,XX @@ raw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
422
goto fail;
423
}
424
425
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
426
+ BLKDBG_CO_EVENT(bs->file, BLKDBG_WRITE_AIO);
427
ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
428
429
fail:
430
diff --git a/block/vmdk.c b/block/vmdk.c
431
index XXXXXXX..XXXXXXX 100644
432
--- a/block/vmdk.c
433
+++ b/block/vmdk.c
434
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
435
if (skip_start_bytes > 0) {
436
if (copy_from_backing) {
437
/* qcow2 emits this on bs->file instead of bs->backing */
438
- BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
439
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_READ);
440
ret = bdrv_co_pread(bs->backing, offset, skip_start_bytes,
441
whole_grain, 0);
442
if (ret < 0) {
443
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
444
goto exit;
445
}
446
}
447
- BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
448
+ BLKDBG_CO_EVENT(extent->file, BLKDBG_COW_WRITE);
449
ret = bdrv_co_pwrite(extent->file, cluster_offset, skip_start_bytes,
450
whole_grain, 0);
451
if (ret < 0) {
452
@@ -XXX,XX +XXX,XX @@ get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent,
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
40
--
539
--
41
2.20.1
540
2.41.0
42
43
diff view generated by jsdifflib