1
The following changes since commit 4c8c1cc544dbd5e2564868e61c5037258e393832:
1
The following changes since commit ec11dc41eec5142b4776db1296972c6323ba5847:
2
2
3
Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-2.10-pull-request' into staging (2017-06-22 19:01:58 +0100)
3
Merge tag 'pull-misc-2022-05-11' of git://repo.or.cz/qemu/armbru into staging (2022-05-11 09:00:26 -0700)
4
4
5
are available in the git repository at:
5
are available in the Git repository at:
6
7
6
8
git://repo.or.cz/qemu/kevin.git tags/for-upstream
7
git://repo.or.cz/qemu/kevin.git tags/for-upstream
9
8
10
for you to fetch changes up to 1512008812410ca4054506a7c44343088abdd977:
9
for you to fetch changes up to f70625299ecc9ba577c87f3d1d75012c747c7d88:
11
10
12
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-06-23' into queue-block (2017-06-23 14:09:12 +0200)
11
qemu-iotests: inline common.config into common.rc (2022-05-12 15:42:49 +0200)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
15
16
Block layer patches
14
Block layer patches
17
15
16
- coroutine: Fix crashes due to too large pool batch size
17
- fdc: Prevent end-of-track overrun
18
- nbd: MULTI_CONN for shared writable exports
19
- iotests test runner improvements
20
18
----------------------------------------------------------------
21
----------------------------------------------------------------
19
Alberto Garcia (9):
22
Daniel P. Berrangé (2):
20
throttle: Update throttle-groups.c documentation
23
tests/qemu-iotests: print intent to run a test in TAP mode
21
qcow2: Remove unused Error variable in do_perform_cow()
24
.gitlab-ci.d: export meson testlog.txt as an artifact
22
qcow2: Use unsigned int for both members of Qcow2COWRegion
23
qcow2: Make perform_cow() call do_perform_cow() twice
24
qcow2: Split do_perform_cow() into _read(), _encrypt() and _write()
25
qcow2: Allow reading both COW regions with only one request
26
qcow2: Pass a QEMUIOVector to do_perform_cow_{read,write}()
27
qcow2: Merge the writing of the COW regions with the guest data
28
qcow2: Use offset_into_cluster() and offset_to_l2_index()
29
25
30
Kevin Wolf (37):
26
Eric Blake (2):
31
commit: Fix completion with extra reference
27
qemu-nbd: Pass max connections to blockdev layer
32
qemu-iotests: Allow starting new qemu after cleanup
28
nbd/server: Allow MULTI_CONN for shared writable exports
33
qemu-iotests: Test exiting qemu with running job
34
doc: Document generic -blockdev options
35
doc: Document driver-specific -blockdev options
36
qed: Use bottom half to resume waiting requests
37
qed: Make qed_read_table() synchronous
38
qed: Remove callback from qed_read_table()
39
qed: Remove callback from qed_read_l2_table()
40
qed: Remove callback from qed_find_cluster()
41
qed: Make qed_read_backing_file() synchronous
42
qed: Make qed_copy_from_backing_file() synchronous
43
qed: Remove callback from qed_copy_from_backing_file()
44
qed: Make qed_write_header() synchronous
45
qed: Remove callback from qed_write_header()
46
qed: Make qed_write_table() synchronous
47
qed: Remove GenericCB
48
qed: Remove callback from qed_write_table()
49
qed: Make qed_aio_read_data() synchronous
50
qed: Make qed_aio_write_main() synchronous
51
qed: Inline qed_commit_l2_update()
52
qed: Add return value to qed_aio_write_l1_update()
53
qed: Add return value to qed_aio_write_l2_update()
54
qed: Add return value to qed_aio_write_main()
55
qed: Add return value to qed_aio_write_cow()
56
qed: Add return value to qed_aio_write_inplace/alloc()
57
qed: Add return value to qed_aio_read/write_data()
58
qed: Remove ret argument from qed_aio_next_io()
59
qed: Remove recursion in qed_aio_next_io()
60
qed: Implement .bdrv_co_readv/writev
61
qed: Use CoQueue for serialising allocations
62
qed: Simplify request handling
63
qed: Use a coroutine for need_check_timer
64
qed: Add coroutine_fn to I/O path functions
65
qed: Use bdrv_co_* for coroutine_fns
66
block: Remove bdrv_aio_readv/writev/flush()
67
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-06-23' into queue-block
68
29
69
Manos Pitsidianakis (1):
30
Hanna Reitz (1):
70
block: change variable names in BlockDriverState
31
iotests/testrunner: Flush after run_test()
71
32
72
Max Reitz (3):
33
Kevin Wolf (2):
73
blkdebug: Catch bs->exact_filename overflow
34
coroutine: Rename qemu_coroutine_inc/dec_pool_size()
74
blkverify: Catch bs->exact_filename overflow
35
coroutine: Revert to constant batch size
75
block: Do not strcmp() with NULL uri->scheme
76
36
77
Stefan Hajnoczi (10):
37
Paolo Bonzini (1):
78
block: count bdrv_co_rw_vmstate() requests
38
qemu-iotests: inline common.config into common.rc
79
block: use BDRV_POLL_WHILE() in bdrv_rw_vmstate()
80
migration: avoid recursive AioContext locking in save_vmstate()
81
migration: use bdrv_drain_all_begin/end() instead bdrv_drain_all()
82
virtio-pci: use ioeventfd even when KVM is disabled
83
migration: hold AioContext lock for loadvm qemu_fclose()
84
qemu-iotests: 068: extract _qemu() function
85
qemu-iotests: 068: use -drive/-device instead of -hda
86
qemu-iotests: 068: test iothread mode
87
qemu-img: don't shadow opts variable in img_dd()
88
39
89
Stephen Bates (1):
40
Philippe Mathieu-Daudé (2):
90
nvme: Add support for Read Data and Write Data in CMBs.
41
hw/block/fdc: Prevent end-of-track overrun (CVE-2021-3507)
42
tests/qtest/fdc-test: Add a regression test for CVE-2021-3507
91
43
92
sochin.jiang (1):
44
qapi/block-export.json | 8 +-
93
fix: avoid an infinite loop or a dangling pointer problem in img_commit
45
docs/interop/nbd.txt | 1 +
46
docs/tools/qemu-nbd.rst | 3 +-
47
include/block/nbd.h | 5 +-
48
include/qemu/coroutine.h | 6 +-
49
blockdev-nbd.c | 13 +-
50
hw/block/fdc.c | 8 ++
51
hw/block/virtio-blk.c | 6 +-
52
nbd/server.c | 10 +-
53
qemu-nbd.c | 2 +-
54
tests/qtest/fdc-test.c | 21 ++++
55
util/qemu-coroutine.c | 26 ++--
56
tests/qemu-iotests/testrunner.py | 4 +
57
.gitlab-ci.d/buildtest-template.yml | 12 +-
58
MAINTAINERS | 1 +
59
tests/qemu-iotests/common.config | 41 -------
60
tests/qemu-iotests/common.rc | 31 +++--
61
tests/qemu-iotests/tests/nbd-multiconn | 145 +++++++++++++++++++++++
62
tests/qemu-iotests/tests/nbd-multiconn.out | 5 +
63
tests/qemu-iotests/tests/nbd-qemu-allocation.out | 2 +-
64
20 files changed, 261 insertions(+), 89 deletions(-)
65
delete mode 100644 tests/qemu-iotests/common.config
66
create mode 100755 tests/qemu-iotests/tests/nbd-multiconn
67
create mode 100644 tests/qemu-iotests/tests/nbd-multiconn.out
94
68
95
block/Makefile.objs | 2 +-
96
block/blkdebug.c | 46 +--
97
block/blkreplay.c | 8 +-
98
block/blkverify.c | 12 +-
99
block/block-backend.c | 22 +-
100
block/commit.c | 7 +
101
block/file-posix.c | 34 +-
102
block/io.c | 240 ++-----------
103
block/iscsi.c | 20 +-
104
block/mirror.c | 8 +-
105
block/nbd-client.c | 8 +-
106
block/nbd-client.h | 4 +-
107
block/nbd.c | 6 +-
108
block/nfs.c | 2 +-
109
block/qcow2-cluster.c | 201 ++++++++---
110
block/qcow2.c | 94 +++--
111
block/qcow2.h | 11 +-
112
block/qed-cluster.c | 124 +++----
113
block/qed-gencb.c | 33 --
114
block/qed-table.c | 261 +++++---------
115
block/qed.c | 779 ++++++++++++++++-------------------------
116
block/qed.h | 54 +--
117
block/raw-format.c | 8 +-
118
block/rbd.c | 4 +-
119
block/sheepdog.c | 12 +-
120
block/ssh.c | 2 +-
121
block/throttle-groups.c | 2 +-
122
block/trace-events | 3 -
123
blockjob.c | 4 +-
124
hw/block/nvme.c | 83 +++--
125
hw/block/nvme.h | 1 +
126
hw/virtio/virtio-pci.c | 2 +-
127
include/block/block.h | 16 +-
128
include/block/block_int.h | 6 +-
129
include/block/blockjob.h | 18 +
130
include/sysemu/block-backend.h | 20 +-
131
migration/savevm.c | 32 +-
132
qemu-img.c | 29 +-
133
qemu-io-cmds.c | 46 +--
134
qemu-options.hx | 221 ++++++++++--
135
tests/qemu-iotests/068 | 37 +-
136
tests/qemu-iotests/068.out | 11 +-
137
tests/qemu-iotests/185 | 206 +++++++++++
138
tests/qemu-iotests/185.out | 59 ++++
139
tests/qemu-iotests/common.qemu | 3 +
140
tests/qemu-iotests/group | 1 +
141
46 files changed, 1477 insertions(+), 1325 deletions(-)
142
delete mode 100644 block/qed-gencb.c
143
create mode 100755 tests/qemu-iotests/185
144
create mode 100644 tests/qemu-iotests/185.out
145
69
diff view generated by jsdifflib
Deleted patch
1
commit_complete() can't assume that after its block_job_completed() the
2
job is actually immediately freed; someone else may still be holding
3
references. In this case, the op blockers on the intermediate nodes make
4
the graph reconfiguration in the completion code fail.
5
1
6
Call block_job_remove_all_bdrv() manually so that we know for sure that
7
any blockers on intermediate nodes are given up.
8
9
Cc: qemu-stable@nongnu.org
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
---
14
block/commit.c | 7 +++++++
15
1 file changed, 7 insertions(+)
16
17
diff --git a/block/commit.c b/block/commit.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/commit.c
20
+++ b/block/commit.c
21
@@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque)
22
}
23
g_free(s->backing_file_str);
24
blk_unref(s->top);
25
+
26
+ /* If there is more than one reference to the job (e.g. if called from
27
+ * block_job_finish_sync()), block_job_completed() won't free it and
28
+ * therefore the blockers on the intermediate nodes remain. This would
29
+ * cause bdrv_set_backing_hd() to fail. */
30
+ block_job_remove_all_bdrv(job);
31
+
32
block_job_completed(&s->common, ret);
33
g_free(data);
34
35
--
36
1.8.3.1
37
38
diff view generated by jsdifflib
Deleted patch
1
After _cleanup_qemu(), test cases should be able to start the next qemu
2
process and call _cleanup_qemu() for that one as well. For this to work
3
cleanly, we need to improve the cleanup so that the second invocation
4
doesn't try to kill the qemu instances from the first invocation a
5
second time (which would result in error messages).
6
1
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
---
11
tests/qemu-iotests/common.qemu | 3 +++
12
1 file changed, 3 insertions(+)
13
14
diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu
15
index XXXXXXX..XXXXXXX 100644
16
--- a/tests/qemu-iotests/common.qemu
17
+++ b/tests/qemu-iotests/common.qemu
18
@@ -XXX,XX +XXX,XX @@ function _cleanup_qemu()
19
rm -f "${QEMU_FIFO_IN}_${i}" "${QEMU_FIFO_OUT}_${i}"
20
eval "exec ${QEMU_IN[$i]}<&-" # close file descriptors
21
eval "exec ${QEMU_OUT[$i]}<&-"
22
+
23
+ unset QEMU_IN[$i]
24
+ unset QEMU_OUT[$i]
25
done
26
}
27
--
28
1.8.3.1
29
30
diff view generated by jsdifflib
1
From: Alberto Garcia <berto@igalia.com>
1
It's true that these functions currently affect the batch size in which
2
coroutines are reused (i.e. moved from the global release pool to the
3
allocation pool of a specific thread), but this is a bug and will be
4
fixed in a separate patch.
2
5
3
Instead of calling perform_cow() twice with a different COW region
6
In fact, the comment in the header file already just promises that it
4
each time, call it just once and make perform_cow() handle both
7
influences the pool size, so reflect this in the name of the functions.
5
regions.
8
As a nice side effect, the shorter function name makes some line
9
wrapping unnecessary.
6
10
7
This patch simply moves code around. The next one will do the actual
11
Cc: qemu-stable@nongnu.org
8
reordering of the COW operations.
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
13
Message-Id: <20220510151020.105528-2-kwolf@redhat.com>
10
Signed-off-by: Alberto Garcia <berto@igalia.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
15
---
15
block/qcow2-cluster.c | 36 ++++++++++++++++++++++--------------
16
include/qemu/coroutine.h | 6 +++---
16
1 file changed, 22 insertions(+), 14 deletions(-)
17
hw/block/virtio-blk.c | 6 ++----
18
util/qemu-coroutine.c | 4 ++--
19
3 files changed, 7 insertions(+), 9 deletions(-)
17
20
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
21
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
19
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2-cluster.c
23
--- a/include/qemu/coroutine.h
21
+++ b/block/qcow2-cluster.c
24
+++ b/include/qemu/coroutine.h
22
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn do_perform_cow(BlockDriverState *bs,
25
@@ -XXX,XX +XXX,XX @@ void coroutine_fn yield_until_fd_readable(int fd);
23
struct iovec iov;
26
/**
24
int ret;
27
* Increase coroutine pool size
25
28
*/
26
+ if (bytes == 0) {
29
-void qemu_coroutine_increase_pool_batch_size(unsigned int additional_pool_size);
27
+ return 0;
30
+void qemu_coroutine_inc_pool_size(unsigned int additional_pool_size);
28
+ }
31
29
+
32
/**
30
iov.iov_len = bytes;
33
- * Devcrease coroutine pool size
31
iov.iov_base = qemu_try_blockalign(bs, iov.iov_len);
34
+ * Decrease coroutine pool size
32
if (iov.iov_base == NULL) {
35
*/
33
@@ -XXX,XX +XXX,XX @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
36
-void qemu_coroutine_decrease_pool_batch_size(unsigned int additional_pool_size);
34
return cluster_offset;
37
+void qemu_coroutine_dec_pool_size(unsigned int additional_pool_size);
38
39
#include "qemu/lockable.h"
40
41
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/block/virtio-blk.c
44
+++ b/hw/block/virtio-blk.c
45
@@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
46
for (i = 0; i < conf->num_queues; i++) {
47
virtio_add_queue(vdev, conf->queue_size, virtio_blk_handle_output);
48
}
49
- qemu_coroutine_increase_pool_batch_size(conf->num_queues * conf->queue_size
50
- / 2);
51
+ qemu_coroutine_inc_pool_size(conf->num_queues * conf->queue_size / 2);
52
virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err);
53
if (err != NULL) {
54
error_propagate(errp, err);
55
@@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_unrealize(DeviceState *dev)
56
for (i = 0; i < conf->num_queues; i++) {
57
virtio_del_queue(vdev, i);
58
}
59
- qemu_coroutine_decrease_pool_batch_size(conf->num_queues * conf->queue_size
60
- / 2);
61
+ qemu_coroutine_dec_pool_size(conf->num_queues * conf->queue_size / 2);
62
qemu_del_vm_change_state_handler(s->change);
63
blockdev_mark_auto_del(s->blk);
64
virtio_cleanup(vdev);
65
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
66
index XXXXXXX..XXXXXXX 100644
67
--- a/util/qemu-coroutine.c
68
+++ b/util/qemu-coroutine.c
69
@@ -XXX,XX +XXX,XX @@ AioContext *coroutine_fn qemu_coroutine_get_aio_context(Coroutine *co)
70
return co->ctx;
35
}
71
}
36
72
37
-static int perform_cow(BlockDriverState *bs, QCowL2Meta *m, Qcow2COWRegion *r)
73
-void qemu_coroutine_increase_pool_batch_size(unsigned int additional_pool_size)
38
+static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
74
+void qemu_coroutine_inc_pool_size(unsigned int additional_pool_size)
39
{
75
{
40
BDRVQcow2State *s = bs->opaque;
76
qatomic_add(&pool_batch_size, additional_pool_size);
41
+ Qcow2COWRegion *start = &m->cow_start;
42
+ Qcow2COWRegion *end = &m->cow_end;
43
int ret;
44
45
- if (r->nb_bytes == 0) {
46
+ if (start->nb_bytes == 0 && end->nb_bytes == 0) {
47
return 0;
48
}
49
50
qemu_co_mutex_unlock(&s->lock);
51
- ret = do_perform_cow(bs, m->offset, m->alloc_offset, r->offset, r->nb_bytes);
52
- qemu_co_mutex_lock(&s->lock);
53
-
54
+ ret = do_perform_cow(bs, m->offset, m->alloc_offset,
55
+ start->offset, start->nb_bytes);
56
if (ret < 0) {
57
- return ret;
58
+ goto fail;
59
}
60
61
+ ret = do_perform_cow(bs, m->offset, m->alloc_offset,
62
+ end->offset, end->nb_bytes);
63
+
64
+fail:
65
+ qemu_co_mutex_lock(&s->lock);
66
+
67
/*
68
* Before we update the L2 table to actually point to the new cluster, we
69
* need to be sure that the refcounts have been increased and COW was
70
* handled.
71
*/
72
- qcow2_cache_depends_on_flush(s->l2_table_cache);
73
+ if (ret == 0) {
74
+ qcow2_cache_depends_on_flush(s->l2_table_cache);
75
+ }
76
77
- return 0;
78
+ return ret;
79
}
77
}
80
78
81
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
79
-void qemu_coroutine_decrease_pool_batch_size(unsigned int removing_pool_size)
82
@@ -XXX,XX +XXX,XX @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
80
+void qemu_coroutine_dec_pool_size(unsigned int removing_pool_size)
83
}
81
{
84
82
qatomic_sub(&pool_batch_size, removing_pool_size);
85
/* copy content of unmodified sectors */
83
}
86
- ret = perform_cow(bs, m, &m->cow_start);
87
- if (ret < 0) {
88
- goto err;
89
- }
90
-
91
- ret = perform_cow(bs, m, &m->cow_end);
92
+ ret = perform_cow(bs, m);
93
if (ret < 0) {
94
goto err;
95
}
96
--
84
--
97
1.8.3.1
85
2.35.3
98
99
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
Commit 4c41c69e changed the way the coroutine pool is sized because for
2
virtio-blk devices with a large queue size and heavy I/O, it was just
3
too small and caused coroutines to be deleted and reallocated soon
4
afterwards. The change made the size dynamic based on the number of
5
queues and the queue size of virtio-blk devices.
2
6
3
The bs->exact_filename field may not be sufficient to store the full
7
There are two important numbers here: Slightly simplified, when a
4
blkverify node filename. In this case, we should not generate a filename
8
coroutine terminates, it is generally stored in the global release pool
5
at all instead of an unusable one.
9
up to a certain pool size, and if the pool is full, it is freed.
10
Conversely, when allocating a new coroutine, the coroutines in the
11
release pool are reused if the pool already has reached a certain
12
minimum size (the batch size), otherwise we allocate new coroutines.
13
14
The problem after commit 4c41c69e is that it not only increases the
15
maximum pool size (which is the intended effect), but also the batch
16
size for reusing coroutines (which is a bug). It means that in cases
17
with many devices and/or a large queue size (which defaults to the
18
number of vcpus for virtio-blk-pci), many thousand coroutines could be
19
sitting in the release pool without being reused.
20
21
This is not only a waste of memory and allocations, but it actually
22
makes the QEMU process likely to hit the vm.max_map_count limit on Linux
23
because each coroutine requires two mappings (its stack and the guard
24
page for the stack), causing it to abort() in qemu_alloc_stack() because
25
when the limit is hit, mprotect() starts to fail with ENOMEM.
26
27
In order to fix the problem, change the batch size back to 64 to avoid
28
uselessly accumulating coroutines in the release pool, but keep the
29
dynamic maximum pool size so that coroutines aren't freed too early
30
in heavy I/O scenarios.
31
32
Note that this fix doesn't strictly make it impossible to hit the limit,
33
but this would only happen if most of the coroutines are actually in use
34
at the same time, not just sitting in a pool. This is the same behaviour
35
as we already had before commit 4c41c69e. Fully preventing this would
36
require allowing qemu_coroutine_create() to return an error, but it
37
doesn't seem to be a scenario that people hit in practice.
6
38
7
Cc: qemu-stable@nongnu.org
39
Cc: qemu-stable@nongnu.org
8
Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
40
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2079938
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
41
Fixes: 4c41c69e05fe28c0f95f8abd2ebf407e95a4f04b
10
Message-id: 20170613172006.19685-3-mreitz@redhat.com
42
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Reviewed-by: Alberto Garcia <berto@igalia.com>
43
Message-Id: <20220510151020.105528-3-kwolf@redhat.com>
12
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
44
Tested-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
45
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
46
---
15
block/blkverify.c | 12 ++++++++----
47
util/qemu-coroutine.c | 22 ++++++++++++++--------
16
1 file changed, 8 insertions(+), 4 deletions(-)
48
1 file changed, 14 insertions(+), 8 deletions(-)
17
49
18
diff --git a/block/blkverify.c b/block/blkverify.c
50
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
19
index XXXXXXX..XXXXXXX 100644
51
index XXXXXXX..XXXXXXX 100644
20
--- a/block/blkverify.c
52
--- a/util/qemu-coroutine.c
21
+++ b/block/blkverify.c
53
+++ b/util/qemu-coroutine.c
22
@@ -XXX,XX +XXX,XX @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
54
@@ -XXX,XX +XXX,XX @@
23
if (bs->file->bs->exact_filename[0]
55
#include "qemu/coroutine-tls.h"
24
&& s->test_file->bs->exact_filename[0])
56
#include "block/aio.h"
25
{
57
26
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
58
-/** Initial batch size is 64, and is increased on demand */
27
- "blkverify:%s:%s",
59
+/**
28
- bs->file->bs->exact_filename,
60
+ * The minimal batch size is always 64, coroutines from the release_pool are
29
- s->test_file->bs->exact_filename);
61
+ * reused as soon as there are 64 coroutines in it. The maximum pool size starts
30
+ int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
62
+ * with 64 and is increased on demand so that coroutines are not deleted even if
31
+ "blkverify:%s:%s",
63
+ * they are not immediately reused.
32
+ bs->file->bs->exact_filename,
64
+ */
33
+ s->test_file->bs->exact_filename);
65
enum {
34
+ if (ret >= sizeof(bs->exact_filename)) {
66
- POOL_INITIAL_BATCH_SIZE = 64,
35
+ /* An overflow makes the filename unusable, so do not report any */
67
+ POOL_MIN_BATCH_SIZE = 64,
36
+ bs->exact_filename[0] = 0;
68
+ POOL_INITIAL_MAX_SIZE = 64,
37
+ }
69
};
38
}
70
71
/** Free list to speed up creation */
72
static QSLIST_HEAD(, Coroutine) release_pool = QSLIST_HEAD_INITIALIZER(pool);
73
-static unsigned int pool_batch_size = POOL_INITIAL_BATCH_SIZE;
74
+static unsigned int pool_max_size = POOL_INITIAL_MAX_SIZE;
75
static unsigned int release_pool_size;
76
77
typedef QSLIST_HEAD(, Coroutine) CoroutineQSList;
78
@@ -XXX,XX +XXX,XX @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque)
79
80
co = QSLIST_FIRST(alloc_pool);
81
if (!co) {
82
- if (release_pool_size > qatomic_read(&pool_batch_size)) {
83
+ if (release_pool_size > POOL_MIN_BATCH_SIZE) {
84
/* Slow path; a good place to register the destructor, too. */
85
Notifier *notifier = get_ptr_coroutine_pool_cleanup_notifier();
86
if (!notifier->notify) {
87
@@ -XXX,XX +XXX,XX @@ static void coroutine_delete(Coroutine *co)
88
co->caller = NULL;
89
90
if (CONFIG_COROUTINE_POOL) {
91
- if (release_pool_size < qatomic_read(&pool_batch_size) * 2) {
92
+ if (release_pool_size < qatomic_read(&pool_max_size) * 2) {
93
QSLIST_INSERT_HEAD_ATOMIC(&release_pool, co, pool_next);
94
qatomic_inc(&release_pool_size);
95
return;
96
}
97
- if (get_alloc_pool_size() < qatomic_read(&pool_batch_size)) {
98
+ if (get_alloc_pool_size() < qatomic_read(&pool_max_size)) {
99
QSLIST_INSERT_HEAD(get_ptr_alloc_pool(), co, pool_next);
100
set_alloc_pool_size(get_alloc_pool_size() + 1);
101
return;
102
@@ -XXX,XX +XXX,XX @@ AioContext *coroutine_fn qemu_coroutine_get_aio_context(Coroutine *co)
103
104
void qemu_coroutine_inc_pool_size(unsigned int additional_pool_size)
105
{
106
- qatomic_add(&pool_batch_size, additional_pool_size);
107
+ qatomic_add(&pool_max_size, additional_pool_size);
39
}
108
}
40
109
110
void qemu_coroutine_dec_pool_size(unsigned int removing_pool_size)
111
{
112
- qatomic_sub(&pool_batch_size, removing_pool_size);
113
+ qatomic_sub(&pool_max_size, removing_pool_size);
114
}
41
--
115
--
42
1.8.3.1
116
2.35.3
43
44
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
blk/bdrv_drain_all() only takes effect for a single instant and then
3
When stdout is not a terminal, the buffer may not be flushed at each end
4
resumes block jobs, guest devices, and other external clients like the
4
of line, so we should flush after each test is done. This is especially
5
NBD server. This can be handy when performing a synchronous drain
5
apparent when run by check-block, in two ways:
6
before terminating the program, for example.
7
6
8
Monitor commands usually need to quiesce I/O across an entire code
7
First, when running make check-block -jX with X > 1, progress indication
9
region so blk/bdrv_drain_all() is not suitable. They must use
8
was missing, even though testrunner.py does theoretically print each
10
bdrv_drain_all_begin/end() to mark the region. This prevents new I/O
9
test's status once it has been run, even in multi-processing mode.
11
requests from slipping in or worse - block jobs completing and modifying
10
Flushing after each test restores this progress indication.
12
the graph.
13
11
14
I audited other blk/bdrv_drain_all() callers but did not find anything
12
Second, sometimes make check-block failed altogether, with an error
15
that needs a similar fix. This patch fixes the savevm/loadvm commands.
13
message that "too few tests [were] run". I presume that's because one
16
Although I haven't encountered a read world issue this makes the code
14
worker process in the job pool did not get to flush its stdout before
17
safer.
15
the main process exited, and so meson did not get to see that worker's
16
test results. In any case, by flushing at the end of run_test(), the
17
problem has disappeared for me.
18
18
19
Suggested-by: Kevin Wolf <kwolf@redhat.com>
19
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
20
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
20
Message-Id: <20220506134215.10086-1-hreitz@redhat.com>
21
Reviewed-by: Eric Blake <eblake@redhat.com>
21
Reviewed-by: Eric Blake <eblake@redhat.com>
22
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
23
---
23
---
24
migration/savevm.c | 18 +++++++++++++++---
24
tests/qemu-iotests/testrunner.py | 1 +
25
1 file changed, 15 insertions(+), 3 deletions(-)
25
1 file changed, 1 insertion(+)
26
26
27
diff --git a/migration/savevm.c b/migration/savevm.c
27
diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py
28
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
29
--- a/migration/savevm.c
29
--- a/tests/qemu-iotests/testrunner.py
30
+++ b/migration/savevm.c
30
+++ b/tests/qemu-iotests/testrunner.py
31
@@ -XXX,XX +XXX,XX @@ int save_snapshot(const char *name, Error **errp)
31
@@ -XXX,XX +XXX,XX @@ def run_test(self, test: str,
32
}
32
else:
33
vm_stop(RUN_STATE_SAVE_VM);
33
print(res.casenotrun)
34
34
35
+ bdrv_drain_all_begin();
35
+ sys.stdout.flush()
36
+
36
return res
37
aio_context_acquire(aio_context);
37
38
38
def run_tests(self, tests: List[str], jobs: int = 1) -> bool:
39
memset(sn, 0, sizeof(*sn));
40
@@ -XXX,XX +XXX,XX @@ int save_snapshot(const char *name, Error **errp)
41
if (aio_context) {
42
aio_context_release(aio_context);
43
}
44
+
45
+ bdrv_drain_all_end();
46
+
47
if (saved_vm_running) {
48
vm_start();
49
}
50
@@ -XXX,XX +XXX,XX @@ int load_snapshot(const char *name, Error **errp)
51
}
52
53
/* Flush all IO requests so they don't interfere with the new state. */
54
- bdrv_drain_all();
55
+ bdrv_drain_all_begin();
56
57
ret = bdrv_all_goto_snapshot(name, &bs);
58
if (ret < 0) {
59
error_setg(errp, "Error %d while activating snapshot '%s' on '%s'",
60
ret, name, bdrv_get_device_name(bs));
61
- return ret;
62
+ goto err_drain;
63
}
64
65
/* restore the VM state */
66
f = qemu_fopen_bdrv(bs_vm_state, 0);
67
if (!f) {
68
error_setg(errp, "Could not open VM state file");
69
- return -EINVAL;
70
+ ret = -EINVAL;
71
+ goto err_drain;
72
}
73
74
qemu_system_reset(SHUTDOWN_CAUSE_NONE);
75
@@ -XXX,XX +XXX,XX @@ int load_snapshot(const char *name, Error **errp)
76
ret = qemu_loadvm_state(f);
77
aio_context_release(aio_context);
78
79
+ bdrv_drain_all_end();
80
+
81
migration_incoming_state_destroy();
82
if (ret < 0) {
83
error_setg(errp, "Error %d while loading VM state", ret);
84
@@ -XXX,XX +XXX,XX @@ int load_snapshot(const char *name, Error **errp)
85
}
86
87
return 0;
88
+
89
+err_drain:
90
+ bdrv_drain_all_end();
91
+ return ret;
92
}
93
94
void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
95
--
39
--
96
1.8.3.1
40
2.35.3
97
98
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Daniel P. Berrangé <berrange@redhat.com>
2
2
3
Old kvm.ko versions only supported a tiny number of ioeventfds so
3
When running I/O tests using TAP output mode, we get a single TAP test
4
virtio-pci avoids ioeventfds when kvm_has_many_ioeventfds() returns 0.
4
with a sub-test reported for each I/O test that is run. The output looks
5
something like this:
5
6
6
Do not check kvm_has_many_ioeventfds() when KVM is disabled since it
7
1..123
7
always returns 0. Since commit 8c56c1a592b5092d91da8d8943c17777d6462a6f
8
ok qcow2 011
8
("memory: emulate ioeventfd") it has been possible to use ioeventfds in
9
ok qcow2 012
9
qtest or TCG mode.
10
ok qcow2 013
11
ok qcow2 217
12
...
10
13
11
This patch makes -device virtio-blk-pci,iothread=iothread0 work even
14
If everything runs or fails normally this is fine, but periodically we
12
when KVM is disabled.
15
have been seeing the test harness abort early before all 123 tests have
16
been run, just leaving a fairly useless message like
13
17
14
I have tested that virtio-blk-pci works under TCG both with and without
18
TAP parsing error: Too few tests run (expected 123, got 107)
15
iothread.
16
19
17
Cc: Michael S. Tsirkin <mst@redhat.com>
20
we have no idea which tests were running at the time the test harness
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
21
abruptly exited. This change causes us to print a message about our
19
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
22
intent to run each test, so we have a record of what is active at the
23
time the harness exits abnormally.
24
25
1..123
26
# running qcow2 011
27
ok qcow2 011
28
# running qcow2 012
29
ok qcow2 012
30
# running qcow2 013
31
ok qcow2 013
32
# running qcow2 217
33
ok qcow2 217
34
...
35
36
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
37
Message-Id: <20220509124134.867431-2-berrange@redhat.com>
38
Reviewed-by: Thomas Huth <thuth@redhat.com>
20
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
39
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
21
---
40
---
22
hw/virtio/virtio-pci.c | 2 +-
41
tests/qemu-iotests/testrunner.py | 3 +++
23
1 file changed, 1 insertion(+), 1 deletion(-)
42
1 file changed, 3 insertions(+)
24
43
25
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
44
diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py
26
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/virtio/virtio-pci.c
46
--- a/tests/qemu-iotests/testrunner.py
28
+++ b/hw/virtio/virtio-pci.c
47
+++ b/tests/qemu-iotests/testrunner.py
29
@@ -XXX,XX +XXX,XX @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
48
@@ -XXX,XX +XXX,XX @@ def run_test(self, test: str,
30
bool pcie_port = pci_bus_is_express(pci_dev->bus) &&
49
starttime=start,
31
!pci_bus_is_root(pci_dev->bus);
50
lasttime=last_el,
32
51
end = '\n' if mp else '\r')
33
- if (!kvm_has_many_ioeventfds()) {
52
+ else:
34
+ if (kvm_enabled() && !kvm_has_many_ioeventfds()) {
53
+ testname = os.path.basename(test)
35
proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
54
+ print(f'# running {self.env.imgfmt} {testname}')
36
}
55
56
res = self.do_run_test(test, mp)
37
57
38
--
58
--
39
1.8.3.1
59
2.35.3
40
60
41
61
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Daniel P. Berrangé <berrange@redhat.com>
2
2
3
Perform the savevm/loadvm test with both iothread on and off. This
3
When running 'make check' we only get a summary of progress on the
4
covers the recently found savevm/loadvm hang when iothread is enabled.
4
console. Fortunately meson/ninja have saved the raw test output to a
5
logfile. Exposing this log will make it easier to debug failures that
6
happen in CI.
5
7
6
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
9
Message-Id: <20220509124134.867431-3-berrange@redhat.com>
10
Reviewed-by: Thomas Huth <thuth@redhat.com>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
13
---
9
tests/qemu-iotests/068 | 23 ++++++++++++++---------
14
.gitlab-ci.d/buildtest-template.yml | 12 ++++++++++--
10
tests/qemu-iotests/068.out | 11 ++++++++++-
15
1 file changed, 10 insertions(+), 2 deletions(-)
11
2 files changed, 24 insertions(+), 10 deletions(-)
12
16
13
diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068
17
diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
14
index XXXXXXX..XXXXXXX 100755
18
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/qemu-iotests/068
19
--- a/.gitlab-ci.d/buildtest-template.yml
16
+++ b/tests/qemu-iotests/068
20
+++ b/.gitlab-ci.d/buildtest-template.yml
17
@@ -XXX,XX +XXX,XX @@ _supported_os Linux
21
@@ -XXX,XX +XXX,XX @@
18
IMGOPTS="compat=1.1"
22
make -j"$JOBS" $MAKE_CHECK_ARGS ;
19
IMG_SIZE=128K
23
fi
20
24
21
-echo
25
-.native_test_job_template:
22
-echo "=== Saving and reloading a VM state to/from a qcow2 image ==="
26
+.common_test_job_template:
23
-echo
27
stage: test
24
-_make_test_img $IMG_SIZE
28
image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest
25
-
29
script:
26
case "$QEMU_DEFAULT_MACHINE" in
30
@@ -XXX,XX +XXX,XX @@
27
s390-ccw-virtio)
31
# Avoid recompiling by hiding ninja with NINJA=":"
28
platform_parm="-no-shutdown"
32
- make NINJA=":" $MAKE_CHECK_ARGS
29
@@ -XXX,XX +XXX,XX @@ _qemu()
33
30
_filter_qemu | _filter_hmp
34
+.native_test_job_template:
31
}
35
+ extends: .common_test_job_template
32
36
+ artifacts:
33
-# Give qemu some time to boot before saving the VM state
37
+ name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
34
-bash -c 'sleep 1; echo -e "savevm 0\nquit"' | _qemu
38
+ expire_in: 7 days
35
-# Now try to continue from that VM state (this should just work)
39
+ paths:
36
-echo quit | _qemu -loadvm 0
40
+ - build/meson-logs/testlog.txt
37
+for extra_args in \
38
+ "" \
39
+ "-object iothread,id=iothread0 -set device.hba0.iothread=iothread0"; do
40
+ echo
41
+ echo "=== Saving and reloading a VM state to/from a qcow2 image ($extra_args) ==="
42
+ echo
43
+
41
+
44
+ _make_test_img $IMG_SIZE
42
.avocado_test_job_template:
45
+
43
- extends: .native_test_job_template
46
+ # Give qemu some time to boot before saving the VM state
44
+ extends: .common_test_job_template
47
+ bash -c 'sleep 1; echo -e "savevm 0\nquit"' | _qemu $extra_args
45
cache:
48
+ # Now try to continue from that VM state (this should just work)
46
key: "${CI_JOB_NAME}-cache"
49
+ echo quit | _qemu $extra_args -loadvm 0
47
paths:
50
+done
51
52
# success, all done
53
echo "*** done"
54
diff --git a/tests/qemu-iotests/068.out b/tests/qemu-iotests/068.out
55
index XXXXXXX..XXXXXXX 100644
56
--- a/tests/qemu-iotests/068.out
57
+++ b/tests/qemu-iotests/068.out
58
@@ -XXX,XX +XXX,XX @@
59
QA output created by 068
60
61
-=== Saving and reloading a VM state to/from a qcow2 image ===
62
+=== Saving and reloading a VM state to/from a qcow2 image () ===
63
+
64
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072
65
+QEMU X.Y.Z monitor - type 'help' for more information
66
+(qemu) savevm 0
67
+(qemu) quit
68
+QEMU X.Y.Z monitor - type 'help' for more information
69
+(qemu) quit
70
+
71
+=== Saving and reloading a VM state to/from a qcow2 image (-object iothread,id=iothread0 -set device.hba0.iothread=iothread0) ===
72
73
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072
74
QEMU X.Y.Z monitor - type 'help' for more information
75
--
48
--
76
1.8.3.1
49
2.35.3
77
50
78
51
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
uri_parse(...)->scheme may be NULL. In fact, probably every field may be
3
Per the 82078 datasheet, if the end-of-track (EOT byte in
4
NULL, and the callers do test this for all of the other fields but not
4
the FIFO) is more than the number of sectors per side, the
5
for scheme (except for block/gluster.c; block/vxhs.c does not access
5
command is terminated unsuccessfully:
6
that field at all).
7
6
8
We can easily fix this by using g_strcmp0() instead of strcmp().
7
* 5.2.5 DATA TRANSFER TERMINATION
8
9
The 82078 supports terminal count explicitly through
10
the TC pin and implicitly through the underrun/over-
11
run and end-of-track (EOT) functions. For full sector
12
transfers, the EOT parameter can define the last
13
sector to be transferred in a single or multisector
14
transfer. If the last sector to be transferred is a par-
15
tial sector, the host can stop transferring the data in
16
mid-sector, and the 82078 will continue to complete
17
the sector as if a hardware TC was received. The
18
only difference between these implicit functions and
19
TC is that they return "abnormal termination" result
20
status. Such status indications can be ignored if they
21
were expected.
22
23
* 6.1.3 READ TRACK
24
25
This command terminates when the EOT specified
26
number of sectors have been read. If the 82078
27
does not find an I D Address Mark on the diskette
28
after the second· occurrence of a pulse on the
29
INDX# pin, then it sets the IC code in Status Regis-
30
ter 0 to "01" (Abnormal termination), sets the MA bit
31
in Status Register 1 to "1", and terminates the com-
32
mand.
33
34
* 6.1.6 VERIFY
35
36
Refer to Table 6-6 and Table 6-7 for information
37
concerning the values of MT and EC versus SC and
38
EOT value.
39
40
* Table 6·6. Result Phase Table
41
42
* Table 6-7. Verify Command Result Phase Table
43
44
Fix by aborting the transfer when EOT > # Sectors Per Side.
9
45
10
Cc: qemu-stable@nongnu.org
46
Cc: qemu-stable@nongnu.org
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
47
Cc: Hervé Poussineau <hpoussin@reactos.org>
12
Message-id: 20170613205726.13544-1-mreitz@redhat.com
48
Fixes: baca51faff0 ("floppy driver: disk geometry auto detect")
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
49
Reported-by: Alexander Bulekov <alxndr@bu.edu>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
50
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/339
51
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
52
Message-Id: <20211118115733.4038610-2-philmd@redhat.com>
53
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
54
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
55
---
16
block/nbd.c | 6 +++---
56
hw/block/fdc.c | 8 ++++++++
17
block/nfs.c | 2 +-
57
1 file changed, 8 insertions(+)
18
block/sheepdog.c | 6 +++---
19
block/ssh.c | 2 +-
20
4 files changed, 8 insertions(+), 8 deletions(-)
21
58
22
diff --git a/block/nbd.c b/block/nbd.c
59
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
23
index XXXXXXX..XXXXXXX 100644
60
index XXXXXXX..XXXXXXX 100644
24
--- a/block/nbd.c
61
--- a/hw/block/fdc.c
25
+++ b/block/nbd.c
62
+++ b/hw/block/fdc.c
26
@@ -XXX,XX +XXX,XX @@ static int nbd_parse_uri(const char *filename, QDict *options)
63
@@ -XXX,XX +XXX,XX @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
27
}
64
int tmp;
28
65
fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
29
/* transport */
66
tmp = (fdctrl->fifo[6] - ks + 1);
30
- if (!strcmp(uri->scheme, "nbd")) {
67
+ if (tmp < 0) {
31
+ if (!g_strcmp0(uri->scheme, "nbd")) {
68
+ FLOPPY_DPRINTF("invalid EOT: %d\n", tmp);
32
is_unix = false;
69
+ fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
33
- } else if (!strcmp(uri->scheme, "nbd+tcp")) {
70
+ fdctrl->fifo[3] = kt;
34
+ } else if (!g_strcmp0(uri->scheme, "nbd+tcp")) {
71
+ fdctrl->fifo[4] = kh;
35
is_unix = false;
72
+ fdctrl->fifo[5] = ks;
36
- } else if (!strcmp(uri->scheme, "nbd+unix")) {
73
+ return;
37
+ } else if (!g_strcmp0(uri->scheme, "nbd+unix")) {
74
+ }
38
is_unix = true;
75
if (fdctrl->fifo[0] & 0x80)
39
} else {
76
tmp += fdctrl->fifo[6];
40
ret = -EINVAL;
77
fdctrl->data_len *= tmp;
41
diff --git a/block/nfs.c b/block/nfs.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/block/nfs.c
44
+++ b/block/nfs.c
45
@@ -XXX,XX +XXX,XX @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
46
error_setg(errp, "Invalid URI specified");
47
goto out;
48
}
49
- if (strcmp(uri->scheme, "nfs") != 0) {
50
+ if (g_strcmp0(uri->scheme, "nfs") != 0) {
51
error_setg(errp, "URI scheme must be 'nfs'");
52
goto out;
53
}
54
diff --git a/block/sheepdog.c b/block/sheepdog.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/block/sheepdog.c
57
+++ b/block/sheepdog.c
58
@@ -XXX,XX +XXX,XX @@ static void sd_parse_uri(SheepdogConfig *cfg, const char *filename,
59
}
60
61
/* transport */
62
- if (!strcmp(uri->scheme, "sheepdog")) {
63
+ if (!g_strcmp0(uri->scheme, "sheepdog")) {
64
is_unix = false;
65
- } else if (!strcmp(uri->scheme, "sheepdog+tcp")) {
66
+ } else if (!g_strcmp0(uri->scheme, "sheepdog+tcp")) {
67
is_unix = false;
68
- } else if (!strcmp(uri->scheme, "sheepdog+unix")) {
69
+ } else if (!g_strcmp0(uri->scheme, "sheepdog+unix")) {
70
is_unix = true;
71
} else {
72
error_setg(&err, "URI scheme must be 'sheepdog', 'sheepdog+tcp',"
73
diff --git a/block/ssh.c b/block/ssh.c
74
index XXXXXXX..XXXXXXX 100644
75
--- a/block/ssh.c
76
+++ b/block/ssh.c
77
@@ -XXX,XX +XXX,XX @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
78
return -EINVAL;
79
}
80
81
- if (strcmp(uri->scheme, "ssh") != 0) {
82
+ if (g_strcmp0(uri->scheme, "ssh") != 0) {
83
error_setg(errp, "URI scheme must be 'ssh'");
84
goto err;
85
}
86
--
78
--
87
1.8.3.1
79
2.35.3
88
80
89
81
diff view generated by jsdifflib
1
From: Alberto Garcia <berto@igalia.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
This patch splits do_perform_cow() into three separate functions to
3
Add the reproducer from https://gitlab.com/qemu-project/qemu/-/issues/339
4
read, encrypt and write the COW regions.
5
4
6
perform_cow() can now read both regions first, then encrypt them and
5
Without the previous commit, when running 'make check-qtest-i386'
7
finally write them to disk. The memory allocation is also done in
6
with QEMU configured with '--enable-sanitizers' we get:
8
this function now, using one single buffer large enough to hold both
9
regions.
10
7
11
Signed-off-by: Alberto Garcia <berto@igalia.com>
8
==4028352==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000062a00 at pc 0x5626d03c491a bp 0x7ffdb4199410 sp 0x7ffdb4198bc0
12
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
READ of size 786432 at 0x619000062a00 thread T0
10
#0 0x5626d03c4919 in __asan_memcpy (qemu-system-i386+0x1e65919)
11
#1 0x5626d1c023cc in flatview_write_continue softmmu/physmem.c:2787:13
12
#2 0x5626d1bf0c0f in flatview_write softmmu/physmem.c:2822:14
13
#3 0x5626d1bf0798 in address_space_write softmmu/physmem.c:2914:18
14
#4 0x5626d1bf0f37 in address_space_rw softmmu/physmem.c:2924:16
15
#5 0x5626d1bf14c8 in cpu_physical_memory_rw softmmu/physmem.c:2933:5
16
#6 0x5626d0bd5649 in cpu_physical_memory_write include/exec/cpu-common.h:82:5
17
#7 0x5626d0bd0a07 in i8257_dma_write_memory hw/dma/i8257.c:452:9
18
#8 0x5626d09f825d in fdctrl_transfer_handler hw/block/fdc.c:1616:13
19
#9 0x5626d0a048b4 in fdctrl_start_transfer hw/block/fdc.c:1539:13
20
#10 0x5626d09f4c3e in fdctrl_write_data hw/block/fdc.c:2266:13
21
#11 0x5626d09f22f7 in fdctrl_write hw/block/fdc.c:829:9
22
#12 0x5626d1c20bc5 in portio_write softmmu/ioport.c:207:17
23
24
0x619000062a00 is located 0 bytes to the right of 512-byte region [0x619000062800,0x619000062a00)
25
allocated by thread T0 here:
26
#0 0x5626d03c66ec in posix_memalign (qemu-system-i386+0x1e676ec)
27
#1 0x5626d2b988d4 in qemu_try_memalign util/oslib-posix.c:210:11
28
#2 0x5626d2b98b0c in qemu_memalign util/oslib-posix.c:226:27
29
#3 0x5626d09fbaf0 in fdctrl_realize_common hw/block/fdc.c:2341:20
30
#4 0x5626d0a150ed in isabus_fdc_realize hw/block/fdc-isa.c:113:5
31
#5 0x5626d2367935 in device_set_realized hw/core/qdev.c:531:13
32
33
SUMMARY: AddressSanitizer: heap-buffer-overflow (qemu-system-i386+0x1e65919) in __asan_memcpy
34
Shadow bytes around the buggy address:
35
0x0c32800044f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
36
0x0c3280004500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
37
0x0c3280004510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
38
0x0c3280004520: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
39
0x0c3280004530: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
=>0x0c3280004540:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
41
0x0c3280004550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
42
0x0c3280004560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
43
0x0c3280004570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
44
0x0c3280004580: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
45
0x0c3280004590: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
46
Shadow byte legend (one shadow byte represents 8 application bytes):
47
Addressable: 00
48
Heap left redzone: fa
49
Freed heap region: fd
50
==4028352==ABORTING
51
52
[ kwolf: Added snapshot=on to prevent write file lock failure ]
53
54
Reported-by: Alexander Bulekov <alxndr@bu.edu>
55
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
56
Reviewed-by: Alexander Bulekov <alxndr@bu.edu>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
57
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
58
---
15
block/qcow2-cluster.c | 117 +++++++++++++++++++++++++++++++++++++-------------
59
tests/qtest/fdc-test.c | 21 +++++++++++++++++++++
16
1 file changed, 87 insertions(+), 30 deletions(-)
60
1 file changed, 21 insertions(+)
17
61
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
62
diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
19
index XXXXXXX..XXXXXXX 100644
63
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2-cluster.c
64
--- a/tests/qtest/fdc-test.c
21
+++ b/block/qcow2-cluster.c
65
+++ b/tests/qtest/fdc-test.c
22
@@ -XXX,XX +XXX,XX @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
66
@@ -XXX,XX +XXX,XX @@ static void test_cve_2021_20196(void)
23
return 0;
67
qtest_quit(s);
24
}
68
}
25
69
26
-static int coroutine_fn do_perform_cow(BlockDriverState *bs,
70
+static void test_cve_2021_3507(void)
27
- uint64_t src_cluster_offset,
71
+{
28
- uint64_t cluster_offset,
72
+ QTestState *s;
29
- unsigned offset_in_cluster,
73
+
30
- unsigned bytes)
74
+ s = qtest_initf("-nographic -m 32M -nodefaults "
31
+static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
75
+ "-drive file=%s,format=raw,if=floppy,snapshot=on",
32
+ uint64_t src_cluster_offset,
76
+ test_image);
33
+ unsigned offset_in_cluster,
77
+ qtest_outl(s, 0x9, 0x0a0206);
34
+ uint8_t *buffer,
78
+ qtest_outw(s, 0x3f4, 0x1600);
35
+ unsigned bytes)
79
+ qtest_outw(s, 0x3f4, 0x0000);
36
{
80
+ qtest_outw(s, 0x3f4, 0x0000);
37
- BDRVQcow2State *s = bs->opaque;
81
+ qtest_outw(s, 0x3f4, 0x0000);
38
QEMUIOVector qiov;
82
+ qtest_outw(s, 0x3f4, 0x0200);
39
- struct iovec iov;
83
+ qtest_outw(s, 0x3f4, 0x0200);
40
+ struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
84
+ qtest_outw(s, 0x3f4, 0x0000);
41
int ret;
85
+ qtest_outw(s, 0x3f4, 0x0000);
42
86
+ qtest_outw(s, 0x3f4, 0x0000);
43
if (bytes == 0) {
87
+ qtest_quit(s);
44
return 0;
45
}
46
47
- iov.iov_len = bytes;
48
- iov.iov_base = qemu_try_blockalign(bs, iov.iov_len);
49
- if (iov.iov_base == NULL) {
50
- return -ENOMEM;
51
- }
52
-
53
qemu_iovec_init_external(&qiov, &iov, 1);
54
55
BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
56
57
if (!bs->drv) {
58
- ret = -ENOMEDIUM;
59
- goto out;
60
+ return -ENOMEDIUM;
61
}
62
63
/* Call .bdrv_co_readv() directly instead of using the public block-layer
64
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn do_perform_cow(BlockDriverState *bs,
65
ret = bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_cluster,
66
bytes, &qiov, 0);
67
if (ret < 0) {
68
- goto out;
69
+ return ret;
70
}
71
72
- if (bs->encrypted) {
73
+ return 0;
74
+}
88
+}
75
+
89
+
76
+static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
90
int main(int argc, char **argv)
77
+ uint64_t src_cluster_offset,
91
{
78
+ unsigned offset_in_cluster,
92
int fd;
79
+ uint8_t *buffer,
93
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
80
+ unsigned bytes)
94
qtest_add_func("/fdc/read_no_dma_19", test_read_no_dma_19);
81
+{
95
qtest_add_func("/fdc/fuzz-registers", fuzz_registers);
82
+ if (bytes && bs->encrypted) {
96
qtest_add_func("/fdc/fuzz/cve_2021_20196", test_cve_2021_20196);
83
+ BDRVQcow2State *s = bs->opaque;
97
+ qtest_add_func("/fdc/fuzz/cve_2021_3507", test_cve_2021_3507);
84
int64_t sector = (src_cluster_offset + offset_in_cluster)
98
85
>> BDRV_SECTOR_BITS;
99
ret = g_test_run();
86
assert(s->cipher);
87
assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0);
88
assert((bytes & ~BDRV_SECTOR_MASK) == 0);
89
- if (qcow2_encrypt_sectors(s, sector, iov.iov_base, iov.iov_base,
90
+ if (qcow2_encrypt_sectors(s, sector, buffer, buffer,
91
bytes >> BDRV_SECTOR_BITS, true, NULL) < 0) {
92
- ret = -EIO;
93
- goto out;
94
+ return false;
95
}
96
}
97
+ return true;
98
+}
99
+
100
+static int coroutine_fn do_perform_cow_write(BlockDriverState *bs,
101
+ uint64_t cluster_offset,
102
+ unsigned offset_in_cluster,
103
+ uint8_t *buffer,
104
+ unsigned bytes)
105
+{
106
+ QEMUIOVector qiov;
107
+ struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
108
+ int ret;
109
+
110
+ if (bytes == 0) {
111
+ return 0;
112
+ }
113
+
114
+ qemu_iovec_init_external(&qiov, &iov, 1);
115
116
ret = qcow2_pre_write_overlap_check(bs, 0,
117
cluster_offset + offset_in_cluster, bytes);
118
if (ret < 0) {
119
- goto out;
120
+ return ret;
121
}
122
123
BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
124
ret = bdrv_co_pwritev(bs->file, cluster_offset + offset_in_cluster,
125
bytes, &qiov, 0);
126
if (ret < 0) {
127
- goto out;
128
+ return ret;
129
}
130
131
- ret = 0;
132
-out:
133
- qemu_vfree(iov.iov_base);
134
- return ret;
135
+ return 0;
136
}
137
138
139
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
140
BDRVQcow2State *s = bs->opaque;
141
Qcow2COWRegion *start = &m->cow_start;
142
Qcow2COWRegion *end = &m->cow_end;
143
+ unsigned buffer_size;
144
+ uint8_t *start_buffer, *end_buffer;
145
int ret;
146
147
+ assert(start->nb_bytes <= UINT_MAX - end->nb_bytes);
148
+
149
if (start->nb_bytes == 0 && end->nb_bytes == 0) {
150
return 0;
151
}
152
153
+ /* Reserve a buffer large enough to store the data from both the
154
+ * start and end COW regions. Add some padding in the middle if
155
+ * necessary to make sure that the end region is optimally aligned */
156
+ buffer_size = QEMU_ALIGN_UP(start->nb_bytes, bdrv_opt_mem_align(bs)) +
157
+ end->nb_bytes;
158
+ start_buffer = qemu_try_blockalign(bs, buffer_size);
159
+ if (start_buffer == NULL) {
160
+ return -ENOMEM;
161
+ }
162
+ /* The part of the buffer where the end region is located */
163
+ end_buffer = start_buffer + buffer_size - end->nb_bytes;
164
+
165
qemu_co_mutex_unlock(&s->lock);
166
- ret = do_perform_cow(bs, m->offset, m->alloc_offset,
167
- start->offset, start->nb_bytes);
168
+ /* First we read the existing data from both COW regions */
169
+ ret = do_perform_cow_read(bs, m->offset, start->offset,
170
+ start_buffer, start->nb_bytes);
171
if (ret < 0) {
172
goto fail;
173
}
174
175
- ret = do_perform_cow(bs, m->offset, m->alloc_offset,
176
- end->offset, end->nb_bytes);
177
+ ret = do_perform_cow_read(bs, m->offset, end->offset,
178
+ end_buffer, end->nb_bytes);
179
+ if (ret < 0) {
180
+ goto fail;
181
+ }
182
+
183
+ /* Encrypt the data if necessary before writing it */
184
+ if (bs->encrypted) {
185
+ if (!do_perform_cow_encrypt(bs, m->offset, start->offset,
186
+ start_buffer, start->nb_bytes) ||
187
+ !do_perform_cow_encrypt(bs, m->offset, end->offset,
188
+ end_buffer, end->nb_bytes)) {
189
+ ret = -EIO;
190
+ goto fail;
191
+ }
192
+ }
193
+
194
+ /* And now we can write everything */
195
+ ret = do_perform_cow_write(bs, m->alloc_offset, start->offset,
196
+ start_buffer, start->nb_bytes);
197
+ if (ret < 0) {
198
+ goto fail;
199
+ }
200
201
+ ret = do_perform_cow_write(bs, m->alloc_offset, end->offset,
202
+ end_buffer, end->nb_bytes);
203
fail:
204
qemu_co_mutex_lock(&s->lock);
205
206
@@ -XXX,XX +XXX,XX @@ fail:
207
qcow2_cache_depends_on_flush(s->l2_table_cache);
208
}
209
210
+ qemu_vfree(start_buffer);
211
return ret;
212
}
213
100
214
--
101
--
215
1.8.3.1
102
2.35.3
216
103
217
104
diff view generated by jsdifflib
1
From: Stephen Bates <sbates@raithlin.com>
1
From: Eric Blake <eblake@redhat.com>
2
2
3
Add the ability for the NVMe model to support both the RDS and WDS
3
The next patch wants to adjust whether the NBD server code advertises
4
modes in the Controller Memory Buffer.
4
MULTI_CONN based on whether it is known if the server limits to
5
exactly one client. For a server started by QMP, this information is
6
obtained through nbd_server_start (which can support more than one
7
export); but for qemu-nbd (which supports exactly one export), it is
8
controlled only by the command-line option -e/--shared. Since we
9
already have a hook function used by qemu-nbd, it's easiest to just
10
alter its signature to fit our needs.
5
11
6
Although not currently supported in the upstreamed Linux kernel a fork
12
Signed-off-by: Eric Blake <eblake@redhat.com>
7
with support exists [1] and user-space test programs that build on
13
Message-Id: <20220512004924.417153-2-eblake@redhat.com>
8
this also exist [2].
9
10
Useful for testing CMB functionality in preperation for real CMB
11
enabled NVMe devices (coming soon).
12
13
[1] https://github.com/sbates130272/linux-p2pmem
14
[2] https://github.com/sbates130272/p2pmem-test
15
16
Signed-off-by: Stephen Bates <sbates@raithlin.com>
17
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
18
Reviewed-by: Keith Busch <keith.busch@intel.com>
19
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
20
---
15
---
21
hw/block/nvme.c | 83 +++++++++++++++++++++++++++++++++++++++------------------
16
include/block/nbd.h | 2 +-
22
hw/block/nvme.h | 1 +
17
blockdev-nbd.c | 8 ++++----
23
2 files changed, 58 insertions(+), 26 deletions(-)
18
qemu-nbd.c | 2 +-
19
3 files changed, 6 insertions(+), 6 deletions(-)
24
20
25
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
21
diff --git a/include/block/nbd.h b/include/block/nbd.h
26
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/block/nvme.c
23
--- a/include/block/nbd.h
28
+++ b/hw/block/nvme.c
24
+++ b/include/block/nbd.h
29
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@ void nbd_client_new(QIOChannelSocket *sioc,
30
* cmb_size_mb=<cmb_size_mb[optional]>
26
void nbd_client_get(NBDClient *client);
31
*
27
void nbd_client_put(NBDClient *client);
32
* Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at
28
33
- * offset 0 in BAR2 and supports SQS only for now.
29
-void nbd_server_is_qemu_nbd(bool value);
34
+ * offset 0 in BAR2 and supports only WDS, RDS and SQS for now.
30
+void nbd_server_is_qemu_nbd(int max_connections);
35
*/
31
bool nbd_server_is_running(void);
36
32
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
37
#include "qemu/osdep.h"
33
const char *tls_authz, uint32_t max_connections,
38
@@ -XXX,XX +XXX,XX @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq)
34
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
39
}
35
index XXXXXXX..XXXXXXX 100644
36
--- a/blockdev-nbd.c
37
+++ b/blockdev-nbd.c
38
@@ -XXX,XX +XXX,XX @@ typedef struct NBDServerData {
39
} NBDServerData;
40
41
static NBDServerData *nbd_server;
42
-static bool is_qemu_nbd;
43
+static int qemu_nbd_connections = -1; /* Non-negative if this is qemu-nbd */
44
45
static void nbd_update_server_watch(NBDServerData *s);
46
47
-void nbd_server_is_qemu_nbd(bool value)
48
+void nbd_server_is_qemu_nbd(int max_connections)
49
{
50
- is_qemu_nbd = value;
51
+ qemu_nbd_connections = max_connections;
40
}
52
}
41
53
42
-static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
54
bool nbd_server_is_running(void)
43
- uint32_t len, NvmeCtrl *n)
44
+static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
45
+ uint64_t prp2, uint32_t len, NvmeCtrl *n)
46
{
55
{
47
hwaddr trans_len = n->page_size - (prp1 % n->page_size);
56
- return nbd_server || is_qemu_nbd;
48
trans_len = MIN(len, trans_len);
57
+ return nbd_server || qemu_nbd_connections >= 0;
49
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
50
51
if (!prp1) {
52
return NVME_INVALID_FIELD | NVME_DNR;
53
+ } else if (n->cmbsz && prp1 >= n->ctrl_mem.addr &&
54
+ prp1 < n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size)) {
55
+ qsg->nsg = 0;
56
+ qemu_iovec_init(iov, num_prps);
57
+ qemu_iovec_add(iov, (void *)&n->cmbuf[prp1 - n->ctrl_mem.addr], trans_len);
58
+ } else {
59
+ pci_dma_sglist_init(qsg, &n->parent_obj, num_prps);
60
+ qemu_sglist_add(qsg, prp1, trans_len);
61
}
62
-
63
- pci_dma_sglist_init(qsg, &n->parent_obj, num_prps);
64
- qemu_sglist_add(qsg, prp1, trans_len);
65
len -= trans_len;
66
if (len) {
67
if (!prp2) {
68
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
69
70
nents = (len + n->page_size - 1) >> n->page_bits;
71
prp_trans = MIN(n->max_prp_ents, nents) * sizeof(uint64_t);
72
- pci_dma_read(&n->parent_obj, prp2, (void *)prp_list, prp_trans);
73
+ nvme_addr_read(n, prp2, (void *)prp_list, prp_trans);
74
while (len != 0) {
75
uint64_t prp_ent = le64_to_cpu(prp_list[i]);
76
77
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
78
i = 0;
79
nents = (len + n->page_size - 1) >> n->page_bits;
80
prp_trans = MIN(n->max_prp_ents, nents) * sizeof(uint64_t);
81
- pci_dma_read(&n->parent_obj, prp_ent, (void *)prp_list,
82
+ nvme_addr_read(n, prp_ent, (void *)prp_list,
83
prp_trans);
84
prp_ent = le64_to_cpu(prp_list[i]);
85
}
86
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
87
}
88
89
trans_len = MIN(len, n->page_size);
90
- qemu_sglist_add(qsg, prp_ent, trans_len);
91
+ if (qsg->nsg){
92
+ qemu_sglist_add(qsg, prp_ent, trans_len);
93
+ } else {
94
+ qemu_iovec_add(iov, (void *)&n->cmbuf[prp_ent - n->ctrl_mem.addr], trans_len);
95
+ }
96
len -= trans_len;
97
i++;
98
}
99
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, uint64_t prp1, uint64_t prp2,
100
if (prp2 & (n->page_size - 1)) {
101
goto unmap;
102
}
103
- qemu_sglist_add(qsg, prp2, len);
104
+ if (qsg->nsg) {
105
+ qemu_sglist_add(qsg, prp2, len);
106
+ } else {
107
+ qemu_iovec_add(iov, (void *)&n->cmbuf[prp2 - n->ctrl_mem.addr], trans_len);
108
+ }
109
}
110
}
111
return NVME_SUCCESS;
112
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
113
uint64_t prp1, uint64_t prp2)
114
{
115
QEMUSGList qsg;
116
+ QEMUIOVector iov;
117
+ uint16_t status = NVME_SUCCESS;
118
119
- if (nvme_map_prp(&qsg, prp1, prp2, len, n)) {
120
+ if (nvme_map_prp(&qsg, &iov, prp1, prp2, len, n)) {
121
return NVME_INVALID_FIELD | NVME_DNR;
122
}
123
- if (dma_buf_read(ptr, len, &qsg)) {
124
+ if (qsg.nsg > 0) {
125
+ if (dma_buf_read(ptr, len, &qsg)) {
126
+ status = NVME_INVALID_FIELD | NVME_DNR;
127
+ }
128
qemu_sglist_destroy(&qsg);
129
- return NVME_INVALID_FIELD | NVME_DNR;
130
+ } else {
131
+ if (qemu_iovec_to_buf(&iov, 0, ptr, len) != len) {
132
+ status = NVME_INVALID_FIELD | NVME_DNR;
133
+ }
134
+ qemu_iovec_destroy(&iov);
135
}
136
- qemu_sglist_destroy(&qsg);
137
- return NVME_SUCCESS;
138
+ return status;
139
}
58
}
140
59
141
static void nvme_post_cqes(void *opaque)
60
static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
142
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
61
diff --git a/qemu-nbd.c b/qemu-nbd.c
143
return NVME_LBA_RANGE | NVME_DNR;
144
}
145
146
- if (nvme_map_prp(&req->qsg, prp1, prp2, data_size, n)) {
147
+ if (nvme_map_prp(&req->qsg, &req->iov, prp1, prp2, data_size, n)) {
148
block_acct_invalid(blk_get_stats(n->conf.blk), acct);
149
return NVME_INVALID_FIELD | NVME_DNR;
150
}
151
152
- assert((nlb << data_shift) == req->qsg.size);
153
-
154
- req->has_sg = true;
155
dma_acct_start(n->conf.blk, &req->acct, &req->qsg, acct);
156
- req->aiocb = is_write ?
157
- dma_blk_write(n->conf.blk, &req->qsg, data_offset, BDRV_SECTOR_SIZE,
158
- nvme_rw_cb, req) :
159
- dma_blk_read(n->conf.blk, &req->qsg, data_offset, BDRV_SECTOR_SIZE,
160
- nvme_rw_cb, req);
161
+ if (req->qsg.nsg > 0) {
162
+ req->has_sg = true;
163
+ req->aiocb = is_write ?
164
+ dma_blk_write(n->conf.blk, &req->qsg, data_offset, BDRV_SECTOR_SIZE,
165
+ nvme_rw_cb, req) :
166
+ dma_blk_read(n->conf.blk, &req->qsg, data_offset, BDRV_SECTOR_SIZE,
167
+ nvme_rw_cb, req);
168
+ } else {
169
+ req->has_sg = false;
170
+ req->aiocb = is_write ?
171
+ blk_aio_pwritev(n->conf.blk, data_offset, &req->iov, 0, nvme_rw_cb,
172
+ req) :
173
+ blk_aio_preadv(n->conf.blk, data_offset, &req->iov, 0, nvme_rw_cb,
174
+ req);
175
+ }
176
177
return NVME_NO_COMPLETE;
178
}
179
@@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev)
180
NVME_CMBSZ_SET_SQS(n->bar.cmbsz, 1);
181
NVME_CMBSZ_SET_CQS(n->bar.cmbsz, 0);
182
NVME_CMBSZ_SET_LISTS(n->bar.cmbsz, 0);
183
- NVME_CMBSZ_SET_RDS(n->bar.cmbsz, 0);
184
- NVME_CMBSZ_SET_WDS(n->bar.cmbsz, 0);
185
+ NVME_CMBSZ_SET_RDS(n->bar.cmbsz, 1);
186
+ NVME_CMBSZ_SET_WDS(n->bar.cmbsz, 1);
187
NVME_CMBSZ_SET_SZU(n->bar.cmbsz, 2); /* MBs */
188
NVME_CMBSZ_SET_SZ(n->bar.cmbsz, n->cmb_size_mb);
189
190
+ n->cmbloc = n->bar.cmbloc;
191
+ n->cmbsz = n->bar.cmbsz;
192
+
193
n->cmbuf = g_malloc0(NVME_CMBSZ_GETSIZE(n->bar.cmbsz));
194
memory_region_init_io(&n->ctrl_mem, OBJECT(n), &nvme_cmb_ops, n,
195
"nvme-cmb", NVME_CMBSZ_GETSIZE(n->bar.cmbsz));
196
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
197
index XXXXXXX..XXXXXXX 100644
62
index XXXXXXX..XXXXXXX 100644
198
--- a/hw/block/nvme.h
63
--- a/qemu-nbd.c
199
+++ b/hw/block/nvme.h
64
+++ b/qemu-nbd.c
200
@@ -XXX,XX +XXX,XX @@ typedef struct NvmeRequest {
65
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
201
NvmeCqe cqe;
66
202
BlockAcctCookie acct;
67
bs->detect_zeroes = detect_zeroes;
203
QEMUSGList qsg;
68
204
+ QEMUIOVector iov;
69
- nbd_server_is_qemu_nbd(true);
205
QTAILQ_ENTRY(NvmeRequest)entry;
70
+ nbd_server_is_qemu_nbd(shared);
206
} NvmeRequest;
71
207
72
export_opts = g_new(BlockExportOptions, 1);
73
*export_opts = (BlockExportOptions) {
208
--
74
--
209
1.8.3.1
75
2.35.3
210
211
diff view generated by jsdifflib
1
When qemu is exited, all running jobs should be cancelled successfully.
1
From: Eric Blake <eblake@redhat.com>
2
This adds a test for this for all types of block jobs that currently
2
3
exist in qemu.
3
According to the NBD spec, a server that advertises
4
4
NBD_FLAG_CAN_MULTI_CONN promises that multiple client connections will
5
not see any cache inconsistencies: when properly separated by a single
6
flush, actions performed by one client will be visible to another
7
client, regardless of which client did the flush.
8
9
We always satisfy these conditions in qemu - even when we support
10
multiple clients, ALL clients go through a single point of reference
11
into the block layer, with no local caching. The effect of one client
12
is instantly visible to the next client. Even if our backend were a
13
network device, we argue that any multi-path caching effects that
14
would cause inconsistencies in back-to-back actions not seeing the
15
effect of previous actions would be a bug in that backend, and not the
16
fault of caching in qemu. As such, it is safe to unconditionally
17
advertise CAN_MULTI_CONN for any qemu NBD server situation that
18
supports parallel clients.
19
20
Note, however, that we don't want to advertise CAN_MULTI_CONN when we
21
know that a second client cannot connect (for historical reasons,
22
qemu-nbd defaults to a single connection while nbd-server-add and QMP
23
commands default to unlimited connections; but we already have
24
existing means to let either style of NBD server creation alter those
25
defaults). This is visible by no longer advertising MULTI_CONN for
26
'qemu-nbd -r' without -e, as in the iotest nbd-qemu-allocation.
27
28
The harder part of this patch is setting up an iotest to demonstrate
29
behavior of multiple NBD clients to a single server. It might be
30
possible with parallel qemu-io processes, but I found it easier to do
31
in python with the help of libnbd, and help from Nir and Vladimir in
32
writing the test.
33
34
Signed-off-by: Eric Blake <eblake@redhat.com>
35
Suggested-by: Nir Soffer <nsoffer@redhat.com>
36
Suggested-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
37
Message-Id: <20220512004924.417153-3-eblake@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
38
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
39
---
8
tests/qemu-iotests/185 | 206 +++++++++++++++++++++++++++++++++++++++++++++
40
qapi/block-export.json | 8 +-
9
tests/qemu-iotests/185.out | 59 +++++++++++++
41
docs/interop/nbd.txt | 1 +
10
tests/qemu-iotests/group | 1 +
42
docs/tools/qemu-nbd.rst | 3 +-
11
3 files changed, 266 insertions(+)
43
include/block/nbd.h | 3 +-
12
create mode 100755 tests/qemu-iotests/185
44
blockdev-nbd.c | 5 +
13
create mode 100644 tests/qemu-iotests/185.out
45
nbd/server.c | 10 +-
14
46
MAINTAINERS | 1 +
15
diff --git a/tests/qemu-iotests/185 b/tests/qemu-iotests/185
47
tests/qemu-iotests/tests/nbd-multiconn | 145 ++++++++++++++++++
48
tests/qemu-iotests/tests/nbd-multiconn.out | 5 +
49
.../tests/nbd-qemu-allocation.out | 2 +-
50
10 files changed, 172 insertions(+), 11 deletions(-)
51
create mode 100755 tests/qemu-iotests/tests/nbd-multiconn
52
create mode 100644 tests/qemu-iotests/tests/nbd-multiconn.out
53
54
diff --git a/qapi/block-export.json b/qapi/block-export.json
55
index XXXXXXX..XXXXXXX 100644
56
--- a/qapi/block-export.json
57
+++ b/qapi/block-export.json
58
@@ -XXX,XX +XXX,XX @@
59
# recreated on the fly while the NBD server is active.
60
# If missing, it will default to denying access (since 4.0).
61
# @max-connections: The maximum number of connections to allow at the same
62
-# time, 0 for unlimited. (since 5.2; default: 0)
63
+# time, 0 for unlimited. Setting this to 1 also stops
64
+# the server from advertising multiple client support
65
+# (since 5.2; default: 0)
66
#
67
# Since: 4.2
68
##
69
@@ -XXX,XX +XXX,XX @@
70
# recreated on the fly while the NBD server is active.
71
# If missing, it will default to denying access (since 4.0).
72
# @max-connections: The maximum number of connections to allow at the same
73
-# time, 0 for unlimited. (since 5.2; default: 0)
74
+# time, 0 for unlimited. Setting this to 1 also stops
75
+# the server from advertising multiple client support
76
+# (since 5.2; default: 0).
77
#
78
# Returns: error if the server is already running.
79
#
80
diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt
81
index XXXXXXX..XXXXXXX 100644
82
--- a/docs/interop/nbd.txt
83
+++ b/docs/interop/nbd.txt
84
@@ -XXX,XX +XXX,XX @@ NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE
85
* 4.2: NBD_FLAG_CAN_MULTI_CONN for shareable read-only exports,
86
NBD_CMD_FLAG_FAST_ZERO
87
* 5.2: NBD_CMD_BLOCK_STATUS for "qemu:allocation-depth"
88
+* 7.1: NBD_FLAG_CAN_MULTI_CONN for shareable writable exports
89
diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst
90
index XXXXXXX..XXXXXXX 100644
91
--- a/docs/tools/qemu-nbd.rst
92
+++ b/docs/tools/qemu-nbd.rst
93
@@ -XXX,XX +XXX,XX @@ driver options if :option:`--image-opts` is specified.
94
.. option:: -e, --shared=NUM
95
96
Allow up to *NUM* clients to share the device (default
97
- ``1``), 0 for unlimited. Safe for readers, but for now,
98
- consistency is not guaranteed between multiple writers.
99
+ ``1``), 0 for unlimited.
100
101
.. option:: -t, --persistent
102
103
diff --git a/include/block/nbd.h b/include/block/nbd.h
104
index XXXXXXX..XXXXXXX 100644
105
--- a/include/block/nbd.h
106
+++ b/include/block/nbd.h
107
@@ -XXX,XX +XXX,XX @@
108
/*
109
- * Copyright (C) 2016-2020 Red Hat, Inc.
110
+ * Copyright (C) 2016-2022 Red Hat, Inc.
111
* Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
112
*
113
* Network Block Device
114
@@ -XXX,XX +XXX,XX @@ void nbd_client_put(NBDClient *client);
115
116
void nbd_server_is_qemu_nbd(int max_connections);
117
bool nbd_server_is_running(void);
118
+int nbd_server_max_connections(void);
119
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
120
const char *tls_authz, uint32_t max_connections,
121
Error **errp);
122
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
123
index XXXXXXX..XXXXXXX 100644
124
--- a/blockdev-nbd.c
125
+++ b/blockdev-nbd.c
126
@@ -XXX,XX +XXX,XX @@ bool nbd_server_is_running(void)
127
return nbd_server || qemu_nbd_connections >= 0;
128
}
129
130
+int nbd_server_max_connections(void)
131
+{
132
+ return nbd_server ? nbd_server->max_connections : qemu_nbd_connections;
133
+}
134
+
135
static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
136
{
137
nbd_client_put(client);
138
diff --git a/nbd/server.c b/nbd/server.c
139
index XXXXXXX..XXXXXXX 100644
140
--- a/nbd/server.c
141
+++ b/nbd/server.c
142
@@ -XXX,XX +XXX,XX @@
143
/*
144
- * Copyright (C) 2016-2021 Red Hat, Inc.
145
+ * Copyright (C) 2016-2022 Red Hat, Inc.
146
* Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
147
*
148
* Network Block Device Server Side
149
@@ -XXX,XX +XXX,XX @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args,
150
int64_t size;
151
uint64_t perm, shared_perm;
152
bool readonly = !exp_args->writable;
153
- bool shared = !exp_args->writable;
154
BlockDirtyBitmapOrStrList *bitmaps;
155
size_t i;
156
int ret;
157
@@ -XXX,XX +XXX,XX @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args,
158
exp->description = g_strdup(arg->description);
159
exp->nbdflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_FLUSH |
160
NBD_FLAG_SEND_FUA | NBD_FLAG_SEND_CACHE);
161
+
162
+ if (nbd_server_max_connections() != 1) {
163
+ exp->nbdflags |= NBD_FLAG_CAN_MULTI_CONN;
164
+ }
165
if (readonly) {
166
exp->nbdflags |= NBD_FLAG_READ_ONLY;
167
- if (shared) {
168
- exp->nbdflags |= NBD_FLAG_CAN_MULTI_CONN;
169
- }
170
} else {
171
exp->nbdflags |= (NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES |
172
NBD_FLAG_SEND_FAST_ZERO);
173
diff --git a/MAINTAINERS b/MAINTAINERS
174
index XXXXXXX..XXXXXXX 100644
175
--- a/MAINTAINERS
176
+++ b/MAINTAINERS
177
@@ -XXX,XX +XXX,XX @@ F: qemu-nbd.*
178
F: blockdev-nbd.c
179
F: docs/interop/nbd.txt
180
F: docs/tools/qemu-nbd.rst
181
+F: tests/qemu-iotests/tests/*nbd*
182
T: git https://repo.or.cz/qemu/ericb.git nbd
183
T: git https://src.openvz.org/scm/~vsementsov/qemu.git nbd
184
185
diff --git a/tests/qemu-iotests/tests/nbd-multiconn b/tests/qemu-iotests/tests/nbd-multiconn
16
new file mode 100755
186
new file mode 100755
17
index XXXXXXX..XXXXXXX
187
index XXXXXXX..XXXXXXX
18
--- /dev/null
188
--- /dev/null
19
+++ b/tests/qemu-iotests/185
189
+++ b/tests/qemu-iotests/tests/nbd-multiconn
20
@@ -XXX,XX +XXX,XX @@
190
@@ -XXX,XX +XXX,XX @@
21
+#!/bin/bash
191
+#!/usr/bin/env python3
22
+#
192
+# group: rw auto quick
23
+# Test exiting qemu while jobs are still running
193
+#
24
+#
194
+# Test cases for NBD multi-conn advertisement
25
+# Copyright (C) 2017 Red Hat, Inc.
195
+#
196
+# Copyright (C) 2022 Red Hat, Inc.
26
+#
197
+#
27
+# This program is free software; you can redistribute it and/or modify
198
+# This program is free software; you can redistribute it and/or modify
28
+# it under the terms of the GNU General Public License as published by
199
+# it under the terms of the GNU General Public License as published by
29
+# the Free Software Foundation; either version 2 of the License, or
200
+# the Free Software Foundation; either version 2 of the License, or
30
+# (at your option) any later version.
201
+# (at your option) any later version.
...
...
34
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
+# GNU General Public License for more details.
206
+# GNU General Public License for more details.
36
+#
207
+#
37
+# You should have received a copy of the GNU General Public License
208
+# You should have received a copy of the GNU General Public License
38
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
209
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
39
+#
210
+
40
+
211
+import os
41
+# creator
212
+from contextlib import contextmanager
42
+owner=kwolf@redhat.com
213
+import iotests
43
+
214
+from iotests import qemu_img_create, qemu_io
44
+seq=`basename $0`
215
+
45
+echo "QA output created by $seq"
216
+
46
+
217
+disk = os.path.join(iotests.test_dir, 'disk')
47
+here=`pwd`
218
+size = '4M'
48
+status=1 # failure is the default!
219
+nbd_sock = os.path.join(iotests.sock_dir, 'nbd_sock')
49
+
220
+nbd_uri = 'nbd+unix:///{}?socket=' + nbd_sock
50
+MIG_SOCKET="${TEST_DIR}/migrate"
221
+
51
+
222
+
52
+_cleanup()
223
+@contextmanager
53
+{
224
+def open_nbd(export_name):
54
+ rm -f "${TEST_IMG}.mid"
225
+ h = nbd.NBD()
55
+ rm -f "${TEST_IMG}.copy"
226
+ try:
56
+ _cleanup_test_img
227
+ h.connect_uri(nbd_uri.format(export_name))
57
+ _cleanup_qemu
228
+ yield h
58
+}
229
+ finally:
59
+trap "_cleanup; exit \$status" 0 1 2 3 15
230
+ h.shutdown()
60
+
231
+
61
+# get standard environment, filters and checks
232
+class TestNbdMulticonn(iotests.QMPTestCase):
62
+. ./common.rc
233
+ def setUp(self):
63
+. ./common.filter
234
+ qemu_img_create('-f', iotests.imgfmt, disk, size)
64
+. ./common.qemu
235
+ qemu_io('-c', 'w -P 1 0 2M', '-c', 'w -P 2 2M 2M', disk)
65
+
236
+
66
+_supported_fmt qcow2
237
+ self.vm = iotests.VM()
67
+_supported_proto file
238
+ self.vm.launch()
68
+_supported_os Linux
239
+ result = self.vm.qmp('blockdev-add', {
69
+
240
+ 'driver': 'qcow2',
70
+size=64M
241
+ 'node-name': 'n',
71
+TEST_IMG="${TEST_IMG}.base" _make_test_img $size
242
+ 'file': {'driver': 'file', 'filename': disk}
72
+
243
+ })
73
+echo
244
+ self.assert_qmp(result, 'return', {})
74
+echo === Starting VM ===
245
+
75
+echo
246
+ def tearDown(self):
76
+
247
+ self.vm.shutdown()
77
+qemu_comm_method="qmp"
248
+ os.remove(disk)
78
+
249
+ try:
79
+_launch_qemu \
250
+ os.remove(nbd_sock)
80
+ -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
251
+ except OSError:
81
+h=$QEMU_HANDLE
252
+ pass
82
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
253
+
83
+
254
+ @contextmanager
84
+echo
255
+ def run_server(self, max_connections=None):
85
+echo === Creating backing chain ===
256
+ args = {
86
+echo
257
+ 'addr': {
87
+
258
+ 'type': 'unix',
88
+_send_qemu_cmd $h \
259
+ 'data': {'path': nbd_sock}
89
+ "{ 'execute': 'blockdev-snapshot-sync',
260
+ }
90
+ 'arguments': { 'device': 'disk',
261
+ }
91
+ 'snapshot-file': '$TEST_IMG.mid',
262
+ if max_connections is not None:
92
+ 'format': '$IMGFMT',
263
+ args['max-connections'] = max_connections
93
+ 'mode': 'absolute-paths' } }" \
264
+
94
+ "return"
265
+ result = self.vm.qmp('nbd-server-start', args)
95
+
266
+ self.assert_qmp(result, 'return', {})
96
+_send_qemu_cmd $h \
267
+ yield
97
+ "{ 'execute': 'human-monitor-command',
268
+
98
+ 'arguments': { 'command-line':
269
+ result = self.vm.qmp('nbd-server-stop')
99
+ 'qemu-io disk \"write 0 4M\"' } }" \
270
+ self.assert_qmp(result, 'return', {})
100
+ "return"
271
+
101
+
272
+ def add_export(self, name, writable=None):
102
+_send_qemu_cmd $h \
273
+ args = {
103
+ "{ 'execute': 'blockdev-snapshot-sync',
274
+ 'type': 'nbd',
104
+ 'arguments': { 'device': 'disk',
275
+ 'id': name,
105
+ 'snapshot-file': '$TEST_IMG',
276
+ 'node-name': 'n',
106
+ 'format': '$IMGFMT',
277
+ 'name': name,
107
+ 'mode': 'absolute-paths' } }" \
278
+ }
108
+ "return"
279
+ if writable is not None:
109
+
280
+ args['writable'] = writable
110
+echo
281
+
111
+echo === Start commit job and exit qemu ===
282
+ result = self.vm.qmp('block-export-add', args)
112
+echo
283
+ self.assert_qmp(result, 'return', {})
113
+
284
+
114
+# Note that the reference output intentionally includes the 'offset' field in
285
+ def test_default_settings(self):
115
+# BLOCK_JOB_CANCELLED events for all of the following block jobs. They are
286
+ with self.run_server():
116
+# predictable and any change in the offsets would hint at a bug in the job
287
+ self.add_export('r')
117
+# throttling code.
288
+ self.add_export('w', writable=True)
118
+#
289
+ with open_nbd('r') as h:
119
+# In order to achieve these predictable offsets, all of the following tests
290
+ self.assertTrue(h.can_multi_conn())
120
+# use speed=65536. Each job will perform exactly one iteration before it has
291
+ with open_nbd('w') as h:
121
+# to sleep at least for a second, which is plenty of time for the 'quit' QMP
292
+ self.assertTrue(h.can_multi_conn())
122
+# command to be received (after receiving the command, the rest runs
293
+
123
+# synchronously, so jobs can arbitrarily continue or complete).
294
+ def test_limited_connections(self):
124
+#
295
+ with self.run_server(max_connections=1):
125
+# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
296
+ self.add_export('r')
126
+# the first request), for active commit and mirror it's large enough to cover
297
+ self.add_export('w', writable=True)
127
+# the full 4M, and for backup it's the qcow2 cluster size, which we know is
298
+ with open_nbd('r') as h:
128
+# 64k. As all of these are at least as large as the speed, we are sure that the
299
+ self.assertFalse(h.can_multi_conn())
129
+# offset doesn't advance after the first iteration before qemu exits.
300
+ with open_nbd('w') as h:
130
+
301
+ self.assertFalse(h.can_multi_conn())
131
+_send_qemu_cmd $h \
302
+
132
+ "{ 'execute': 'block-commit',
303
+ def test_parallel_writes(self):
133
+ 'arguments': { 'device': 'disk',
304
+ with self.run_server():
134
+ 'base':'$TEST_IMG.base',
305
+ self.add_export('w', writable=True)
135
+ 'top': '$TEST_IMG.mid',
306
+
136
+ 'speed': 65536 } }" \
307
+ clients = [nbd.NBD() for _ in range(3)]
137
+ "return"
308
+ for c in clients:
138
+
309
+ c.connect_uri(nbd_uri.format('w'))
139
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
310
+ self.assertTrue(c.can_multi_conn())
140
+wait=1 _cleanup_qemu
311
+
141
+
312
+ initial_data = clients[0].pread(1024 * 1024, 0)
142
+echo
313
+ self.assertEqual(initial_data, b'\x01' * 1024 * 1024)
143
+echo === Start active commit job and exit qemu ===
314
+
144
+echo
315
+ updated_data = b'\x03' * 1024 * 1024
145
+
316
+ clients[1].pwrite(updated_data, 0)
146
+_launch_qemu \
317
+ clients[2].flush()
147
+ -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
318
+ current_data = clients[0].pread(1024 * 1024, 0)
148
+h=$QEMU_HANDLE
319
+
149
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
320
+ self.assertEqual(updated_data, current_data)
150
+
321
+
151
+_send_qemu_cmd $h \
322
+ for i in range(3):
152
+ "{ 'execute': 'block-commit',
323
+ clients[i].shutdown()
153
+ 'arguments': { 'device': 'disk',
324
+
154
+ 'base':'$TEST_IMG.base',
325
+
155
+ 'speed': 65536 } }" \
326
+if __name__ == '__main__':
156
+ "return"
327
+ try:
157
+
328
+ # Easier to use libnbd than to try and set up parallel
158
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
329
+ # 'qemu-nbd --list' or 'qemu-io' processes, but not all systems
159
+wait=1 _cleanup_qemu
330
+ # have libnbd installed.
160
+
331
+ import nbd # type: ignore
161
+echo
332
+
162
+echo === Start mirror job and exit qemu ===
333
+ iotests.main(supported_fmts=['qcow2'])
163
+echo
334
+ except ImportError:
164
+
335
+ iotests.notrun('libnbd not installed')
165
+_launch_qemu \
336
diff --git a/tests/qemu-iotests/tests/nbd-multiconn.out b/tests/qemu-iotests/tests/nbd-multiconn.out
166
+ -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
167
+h=$QEMU_HANDLE
168
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
169
+
170
+_send_qemu_cmd $h \
171
+ "{ 'execute': 'drive-mirror',
172
+ 'arguments': { 'device': 'disk',
173
+ 'target': '$TEST_IMG.copy',
174
+ 'format': '$IMGFMT',
175
+ 'sync': 'full',
176
+ 'speed': 65536 } }" \
177
+ "return"
178
+
179
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
180
+wait=1 _cleanup_qemu
181
+
182
+echo
183
+echo === Start backup job and exit qemu ===
184
+echo
185
+
186
+_launch_qemu \
187
+ -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
188
+h=$QEMU_HANDLE
189
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
190
+
191
+_send_qemu_cmd $h \
192
+ "{ 'execute': 'drive-backup',
193
+ 'arguments': { 'device': 'disk',
194
+ 'target': '$TEST_IMG.copy',
195
+ 'format': '$IMGFMT',
196
+ 'sync': 'full',
197
+ 'speed': 65536 } }" \
198
+ "return"
199
+
200
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
201
+wait=1 _cleanup_qemu
202
+
203
+echo
204
+echo === Start streaming job and exit qemu ===
205
+echo
206
+
207
+_launch_qemu \
208
+ -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
209
+h=$QEMU_HANDLE
210
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
211
+
212
+_send_qemu_cmd $h \
213
+ "{ 'execute': 'block-stream',
214
+ 'arguments': { 'device': 'disk',
215
+ 'speed': 65536 } }" \
216
+ "return"
217
+
218
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
219
+wait=1 _cleanup_qemu
220
+
221
+_check_test_img
222
+
223
+# success, all done
224
+echo "*** done"
225
+rm -f $seq.full
226
+status=0
227
diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out
228
new file mode 100644
337
new file mode 100644
229
index XXXXXXX..XXXXXXX
338
index XXXXXXX..XXXXXXX
230
--- /dev/null
339
--- /dev/null
231
+++ b/tests/qemu-iotests/185.out
340
+++ b/tests/qemu-iotests/tests/nbd-multiconn.out
232
@@ -XXX,XX +XXX,XX @@
341
@@ -XXX,XX +XXX,XX @@
233
+QA output created by 185
342
+...
234
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
343
+----------------------------------------------------------------------
235
+
344
+Ran 3 tests
236
+=== Starting VM ===
345
+
237
+
346
+OK
238
+{"return": {}}
347
diff --git a/tests/qemu-iotests/tests/nbd-qemu-allocation.out b/tests/qemu-iotests/tests/nbd-qemu-allocation.out
239
+
348
index XXXXXXX..XXXXXXX 100644
240
+=== Creating backing chain ===
349
--- a/tests/qemu-iotests/tests/nbd-qemu-allocation.out
241
+
350
+++ b/tests/qemu-iotests/tests/nbd-qemu-allocation.out
242
+Formatting 'TEST_DIR/t.qcow2.mid', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.qcow2.base backing_fmt=qcow2 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
351
@@ -XXX,XX +XXX,XX @@ wrote 2097152/2097152 bytes at offset 1048576
243
+{"return": {}}
352
exports available: 1
244
+wrote 4194304/4194304 bytes at offset 0
353
export: ''
245
+4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
354
size: 4194304
246
+{"return": ""}
355
- flags: 0x58f ( readonly flush fua df multi cache )
247
+Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.qcow2.mid backing_fmt=qcow2 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
356
+ flags: 0x48f ( readonly flush fua df cache )
248
+{"return": {}}
357
min block: 1
249
+
358
opt block: 4096
250
+=== Start commit job and exit qemu ===
359
max block: 33554432
251
+
252
+{"return": {}}
253
+{"return": {}}
254
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
255
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "commit"}}
256
+
257
+=== Start active commit job and exit qemu ===
258
+
259
+{"return": {}}
260
+{"return": {}}
261
+{"return": {}}
262
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
263
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "commit"}}
264
+
265
+=== Start mirror job and exit qemu ===
266
+
267
+{"return": {}}
268
+Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
269
+{"return": {}}
270
+{"return": {}}
271
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
272
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
273
+
274
+=== Start backup job and exit qemu ===
275
+
276
+{"return": {}}
277
+Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
278
+{"return": {}}
279
+{"return": {}}
280
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
281
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 65536, "speed": 65536, "type": "backup"}}
282
+
283
+=== Start streaming job and exit qemu ===
284
+
285
+{"return": {}}
286
+{"return": {}}
287
+{"return": {}}
288
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
289
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "stream"}}
290
+No errors were found on the image.
291
+*** done
292
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
293
index XXXXXXX..XXXXXXX 100644
294
--- a/tests/qemu-iotests/group
295
+++ b/tests/qemu-iotests/group
296
@@ -XXX,XX +XXX,XX @@
297
181 rw auto migration
298
182 rw auto quick
299
183 rw auto migration
300
+185 rw auto
301
--
360
--
302
1.8.3.1
361
2.35.3
303
304
diff view generated by jsdifflib
Deleted patch
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
1
3
Calling aio_poll() directly may have been fine previously, but this is
4
the future, man! The difference between an aio_poll() loop and
5
BDRV_POLL_WHILE() is that BDRV_POLL_WHILE() releases the AioContext
6
around aio_poll().
7
8
This allows the IOThread to run fd handlers or BHs to complete the
9
request. Failure to release the AioContext causes deadlocks.
10
11
Using BDRV_POLL_WHILE() partially fixes a 'savevm' hang with -object
12
iothread.
13
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Reviewed-by: Eric Blake <eblake@redhat.com>
16
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
19
block/io.c | 4 +---
20
1 file changed, 1 insertion(+), 3 deletions(-)
21
22
diff --git a/block/io.c b/block/io.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/io.c
25
+++ b/block/io.c
26
@@ -XXX,XX +XXX,XX @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
27
Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data);
28
29
bdrv_coroutine_enter(bs, co);
30
- while (data.ret == -EINPROGRESS) {
31
- aio_poll(bdrv_get_aio_context(bs), true);
32
- }
33
+ BDRV_POLL_WHILE(bs, data.ret == -EINPROGRESS);
34
return data.ret;
35
}
36
}
37
--
38
1.8.3.1
39
40
diff view generated by jsdifflib
Deleted patch
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
1
3
AioContext was designed to allow nested acquire/release calls. It uses
4
a recursive mutex so callers don't need to worry about nesting...or so
5
we thought.
6
7
BDRV_POLL_WHILE() is used to wait for block I/O requests. It releases
8
the AioContext temporarily around aio_poll(). This gives IOThreads a
9
chance to acquire the AioContext to process I/O completions.
10
11
It turns out that recursive locking and BDRV_POLL_WHILE() don't mix.
12
BDRV_POLL_WHILE() only releases the AioContext once, so the IOThread
13
will not be able to acquire the AioContext if it was acquired
14
multiple times.
15
16
Instead of trying to release AioContext n times in BDRV_POLL_WHILE(),
17
this patch simply avoids nested locking in save_vmstate(). It's the
18
simplest fix and we should step back to consider the big picture with
19
all the recent changes to block layer threading.
20
21
This patch is the final fix to solve 'savevm' hanging with -object
22
iothread.
23
24
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
25
Reviewed-by: Eric Blake <eblake@redhat.com>
26
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
27
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
28
---
29
migration/savevm.c | 12 +++++++++++-
30
1 file changed, 11 insertions(+), 1 deletion(-)
31
32
diff --git a/migration/savevm.c b/migration/savevm.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/migration/savevm.c
35
+++ b/migration/savevm.c
36
@@ -XXX,XX +XXX,XX @@ int save_snapshot(const char *name, Error **errp)
37
goto the_end;
38
}
39
40
+ /* The bdrv_all_create_snapshot() call that follows acquires the AioContext
41
+ * for itself. BDRV_POLL_WHILE() does not support nested locking because
42
+ * it only releases the lock once. Therefore synchronous I/O will deadlock
43
+ * unless we release the AioContext before bdrv_all_create_snapshot().
44
+ */
45
+ aio_context_release(aio_context);
46
+ aio_context = NULL;
47
+
48
ret = bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs);
49
if (ret < 0) {
50
error_setg(errp, "Error while creating snapshot on '%s'",
51
@@ -XXX,XX +XXX,XX @@ int save_snapshot(const char *name, Error **errp)
52
ret = 0;
53
54
the_end:
55
- aio_context_release(aio_context);
56
+ if (aio_context) {
57
+ aio_context_release(aio_context);
58
+ }
59
if (saved_vm_running) {
60
vm_start();
61
}
62
--
63
1.8.3.1
64
65
diff view generated by jsdifflib
Deleted patch
1
This adds documentation for the -blockdev options that apply to all
2
nodes independent of the block driver used.
3
1
4
All options that are shared by -blockdev and -drive are now explained in
5
the section for -blockdev. The documentation of -drive mentions that all
6
-blockdev options are accepted as well.
7
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
---
12
qemu-options.hx | 108 +++++++++++++++++++++++++++++++++++++++++---------------
13
1 file changed, 79 insertions(+), 29 deletions(-)
14
15
diff --git a/qemu-options.hx b/qemu-options.hx
16
index XXXXXXX..XXXXXXX 100644
17
--- a/qemu-options.hx
18
+++ b/qemu-options.hx
19
@@ -XXX,XX +XXX,XX @@ DEF("blockdev", HAS_ARG, QEMU_OPTION_blockdev,
20
" [,read-only=on|off][,detect-zeroes=on|off|unmap]\n"
21
" [,driver specific parameters...]\n"
22
" configure a block backend\n", QEMU_ARCH_ALL)
23
+STEXI
24
+@item -blockdev @var{option}[,@var{option}[,@var{option}[,...]]]
25
+@findex -blockdev
26
+
27
+Define a new block driver node.
28
+
29
+@table @option
30
+@item Valid options for any block driver node:
31
+
32
+@table @code
33
+@item driver
34
+Specifies the block driver to use for the given node.
35
+@item node-name
36
+This defines the name of the block driver node by which it will be referenced
37
+later. The name must be unique, i.e. it must not match the name of a different
38
+block driver node, or (if you use @option{-drive} as well) the ID of a drive.
39
+
40
+If no node name is specified, it is automatically generated. The generated node
41
+name is not intended to be predictable and changes between QEMU invocations.
42
+For the top level, an explicit node name must be specified.
43
+@item read-only
44
+Open the node read-only. Guest write attempts will fail.
45
+@item cache.direct
46
+The host page cache can be avoided with @option{cache.direct=on}. This will
47
+attempt to do disk IO directly to the guest's memory. QEMU may still perform an
48
+internal copy of the data.
49
+@item cache.no-flush
50
+In case you don't care about data integrity over host failures, you can use
51
+@option{cache.no-flush=on}. This option tells QEMU that it never needs to write
52
+any data to the disk but can instead keep things in cache. If anything goes
53
+wrong, like your host losing power, the disk storage getting disconnected
54
+accidentally, etc. your image will most probably be rendered unusable.
55
+@item discard=@var{discard}
56
+@var{discard} is one of "ignore" (or "off") or "unmap" (or "on") and controls
57
+whether @code{discard} (also known as @code{trim} or @code{unmap}) requests are
58
+ignored or passed to the filesystem. Some machine types may not support
59
+discard requests.
60
+@item detect-zeroes=@var{detect-zeroes}
61
+@var{detect-zeroes} is "off", "on" or "unmap" and enables the automatic
62
+conversion of plain zero writes by the OS to driver specific optimized
63
+zero write commands. You may even choose "unmap" if @var{discard} is set
64
+to "unmap" to allow a zero write to be converted to an @code{unmap} operation.
65
+@end table
66
+
67
+@end table
68
+
69
+ETEXI
70
71
DEF("drive", HAS_ARG, QEMU_OPTION_drive,
72
"-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
73
@@ -XXX,XX +XXX,XX @@ STEXI
74
@item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
75
@findex -drive
76
77
-Define a new drive. Valid options are:
78
+Define a new drive. This includes creating a block driver node (the backend) as
79
+well as a guest device, and is mostly a shortcut for defining the corresponding
80
+@option{-blockdev} and @option{-device} options.
81
+
82
+@option{-drive} accepts all options that are accepted by @option{-blockdev}. In
83
+addition, it knows the following options:
84
85
@table @option
86
@item file=@var{file}
87
@@ -XXX,XX +XXX,XX @@ These options have the same definition as they have in @option{-hdachs}.
88
@var{snapshot} is "on" or "off" and controls snapshot mode for the given drive
89
(see @option{-snapshot}).
90
@item cache=@var{cache}
91
-@var{cache} is "none", "writeback", "unsafe", "directsync" or "writethrough" and controls how the host cache is used to access block data.
92
+@var{cache} is "none", "writeback", "unsafe", "directsync" or "writethrough"
93
+and controls how the host cache is used to access block data. This is a
94
+shortcut that sets the @option{cache.direct} and @option{cache.no-flush}
95
+options (as in @option{-blockdev}), and additionally @option{cache.writeback},
96
+which provides a default for the @option{write-cache} option of block guest
97
+devices (as in @option{-device}). The modes correspond to the following
98
+settings:
99
+
100
+@c Our texi2pod.pl script doesn't support @multitable, so fall back to using
101
+@c plain ASCII art (well, UTF-8 art really). This looks okay both in the manpage
102
+@c and the HTML output.
103
+@example
104
+@ │ cache.writeback cache.direct cache.no-flush
105
+─────────────┼─────────────────────────────────────────────────
106
+writeback │ on off off
107
+none │ on on off
108
+writethrough │ off off off
109
+directsync │ off on off
110
+unsafe │ on off on
111
+@end example
112
+
113
+The default mode is @option{cache=writeback}.
114
+
115
@item aio=@var{aio}
116
@var{aio} is "threads", or "native" and selects between pthread based disk I/O and native Linux AIO.
117
-@item discard=@var{discard}
118
-@var{discard} is one of "ignore" (or "off") or "unmap" (or "on") and controls whether @dfn{discard} (also known as @dfn{trim} or @dfn{unmap}) requests are ignored or passed to the filesystem. Some machine types may not support discard requests.
119
@item format=@var{format}
120
Specify which disk @var{format} will be used rather than detecting
121
the format. Can be used to specify format=raw to avoid interpreting
122
@@ -XXX,XX +XXX,XX @@ Specify which @var{action} to take on write and read errors. Valid actions are:
123
"report" (report the error to the guest), "enospc" (pause QEMU only if the
124
host disk is full; report the error to the guest otherwise).
125
The default setting is @option{werror=enospc} and @option{rerror=report}.
126
-@item readonly
127
-Open drive @option{file} as read-only. Guest write attempts will fail.
128
@item copy-on-read=@var{copy-on-read}
129
@var{copy-on-read} is "on" or "off" and enables whether to copy read backing
130
file sectors into the image file.
131
-@item detect-zeroes=@var{detect-zeroes}
132
-@var{detect-zeroes} is "off", "on" or "unmap" and enables the automatic
133
-conversion of plain zero writes by the OS to driver specific optimized
134
-zero write commands. You may even choose "unmap" if @var{discard} is set
135
-to "unmap" to allow a zero write to be converted to an UNMAP operation.
136
@item bps=@var{b},bps_rd=@var{r},bps_wr=@var{w}
137
Specify bandwidth throttling limits in bytes per second, either for all request
138
types or for reads or writes only. Small values can lead to timeouts or hangs
139
@@ -XXX,XX +XXX,XX @@ prevent guests from circumventing throttling limits by using many small disks
140
instead of a single larger disk.
141
@end table
142
143
-By default, the @option{cache=writeback} mode is used. It will report data
144
+By default, the @option{cache.writeback=on} mode is used. It will report data
145
writes as completed as soon as the data is present in the host page cache.
146
This is safe as long as your guest OS makes sure to correctly flush disk caches
147
where needed. If your guest OS does not handle volatile disk write caches
148
correctly and your host crashes or loses power, then the guest may experience
149
data corruption.
150
151
-For such guests, you should consider using @option{cache=writethrough}. This
152
+For such guests, you should consider using @option{cache.writeback=off}. This
153
means that the host page cache will be used to read and write data, but write
154
notification will be sent to the guest only after QEMU has made sure to flush
155
each write to the disk. Be aware that this has a major impact on performance.
156
157
-The host page cache can be avoided entirely with @option{cache=none}. This will
158
-attempt to do disk IO directly to the guest's memory. QEMU may still perform
159
-an internal copy of the data. Note that this is considered a writeback mode and
160
-the guest OS must handle the disk write cache correctly in order to avoid data
161
-corruption on host crashes.
162
-
163
-The host page cache can be avoided while only sending write notifications to
164
-the guest when the data has been flushed to the disk using
165
-@option{cache=directsync}.
166
-
167
-In case you don't care about data integrity over host failures, use
168
-@option{cache=unsafe}. This option tells QEMU that it never needs to write any
169
-data to the disk but can instead keep things in cache. If anything goes wrong,
170
-like your host losing power, the disk storage getting disconnected accidentally,
171
-etc. your image will most probably be rendered unusable. When using
172
-the @option{-snapshot} option, unsafe caching is always used.
173
+When using the @option{-snapshot} option, unsafe caching is always used.
174
175
Copy-on-read avoids accessing the same backing file sectors repeatedly and is
176
useful when the backing file is over a slow network. By default copy-on-read
177
--
178
1.8.3.1
179
180
diff view generated by jsdifflib
Deleted patch
1
This documents the driver-specific options for the raw, qcow2 and file
2
block drivers for the man page. For everything else, we refer to the
3
QAPI documentation.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
---
9
qemu-options.hx | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
10
1 file changed, 114 insertions(+), 1 deletion(-)
11
12
diff --git a/qemu-options.hx b/qemu-options.hx
13
index XXXXXXX..XXXXXXX 100644
14
--- a/qemu-options.hx
15
+++ b/qemu-options.hx
16
@@ -XXX,XX +XXX,XX @@ STEXI
17
@item -blockdev @var{option}[,@var{option}[,@var{option}[,...]]]
18
@findex -blockdev
19
20
-Define a new block driver node.
21
+Define a new block driver node. Some of the options apply to all block drivers,
22
+other options are only accepted for a specific block driver. See below for a
23
+list of generic options and options for the most common block drivers.
24
+
25
+Options that expect a reference to another node (e.g. @code{file}) can be
26
+given in two ways. Either you specify the node name of an already existing node
27
+(file=@var{node-name}), or you define a new node inline, adding options
28
+for the referenced node after a dot (file.filename=@var{path},file.aio=native).
29
+
30
+A block driver node created with @option{-blockdev} can be used for a guest
31
+device by specifying its node name for the @code{drive} property in a
32
+@option{-device} argument that defines a block device.
33
34
@table @option
35
@item Valid options for any block driver node:
36
@@ -XXX,XX +XXX,XX @@ zero write commands. You may even choose "unmap" if @var{discard} is set
37
to "unmap" to allow a zero write to be converted to an @code{unmap} operation.
38
@end table
39
40
+@item Driver-specific options for @code{file}
41
+
42
+This is the protocol-level block driver for accessing regular files.
43
+
44
+@table @code
45
+@item filename
46
+The path to the image file in the local filesystem
47
+@item aio
48
+Specifies the AIO backend (threads/native, default: threads)
49
+@end table
50
+Example:
51
+@example
52
+-blockdev driver=file,node-name=disk,filename=disk.img
53
+@end example
54
+
55
+@item Driver-specific options for @code{raw}
56
+
57
+This is the image format block driver for raw images. It is usually
58
+stacked on top of a protocol level block driver such as @code{file}.
59
+
60
+@table @code
61
+@item file
62
+Reference to or definition of the data source block driver node
63
+(e.g. a @code{file} driver node)
64
+@end table
65
+Example 1:
66
+@example
67
+-blockdev driver=file,node-name=disk_file,filename=disk.img
68
+-blockdev driver=raw,node-name=disk,file=disk_file
69
+@end example
70
+Example 2:
71
+@example
72
+-blockdev driver=raw,node-name=disk,file.driver=file,file.filename=disk.img
73
+@end example
74
+
75
+@item Driver-specific options for @code{qcow2}
76
+
77
+This is the image format block driver for qcow2 images. It is usually
78
+stacked on top of a protocol level block driver such as @code{file}.
79
+
80
+@table @code
81
+@item file
82
+Reference to or definition of the data source block driver node
83
+(e.g. a @code{file} driver node)
84
+
85
+@item backing
86
+Reference to or definition of the backing file block device (default is taken
87
+from the image file). It is allowed to pass an empty string here in order to
88
+disable the default backing file.
89
+
90
+@item lazy-refcounts
91
+Whether to enable the lazy refcounts feature (on/off; default is taken from the
92
+image file)
93
+
94
+@item cache-size
95
+The maximum total size of the L2 table and refcount block caches in bytes
96
+(default: 1048576 bytes or 8 clusters, whichever is larger)
97
+
98
+@item l2-cache-size
99
+The maximum size of the L2 table cache in bytes
100
+(default: 4/5 of the total cache size)
101
+
102
+@item refcount-cache-size
103
+The maximum size of the refcount block cache in bytes
104
+(default: 1/5 of the total cache size)
105
+
106
+@item cache-clean-interval
107
+Clean unused entries in the L2 and refcount caches. The interval is in seconds.
108
+The default value is 0 and it disables this feature.
109
+
110
+@item pass-discard-request
111
+Whether discard requests to the qcow2 device should be forwarded to the data
112
+source (on/off; default: on if discard=unmap is specified, off otherwise)
113
+
114
+@item pass-discard-snapshot
115
+Whether discard requests for the data source should be issued when a snapshot
116
+operation (e.g. deleting a snapshot) frees clusters in the qcow2 file (on/off;
117
+default: on)
118
+
119
+@item pass-discard-other
120
+Whether discard requests for the data source should be issued on other
121
+occasions where a cluster gets freed (on/off; default: off)
122
+
123
+@item overlap-check
124
+Which overlap checks to perform for writes to the image
125
+(none/constant/cached/all; default: cached). For details or finer
126
+granularity control refer to the QAPI documentation of @code{blockdev-add}.
127
+@end table
128
+
129
+Example 1:
130
+@example
131
+-blockdev driver=file,node-name=my_file,filename=/tmp/disk.qcow2
132
+-blockdev driver=qcow2,node-name=hda,file=my_file,overlap-check=none,cache-size=16777216
133
+@end example
134
+Example 2:
135
+@example
136
+-blockdev driver=qcow2,node-name=disk,file.driver=http,file.filename=http://example.com/image.qcow2
137
+@end example
138
+
139
+@item Driver-specific options for other drivers
140
+Please refer to the QAPI documentation of the @code{blockdev-add} QMP command.
141
+
142
@end table
143
144
ETEXI
145
--
146
1.8.3.1
147
148
diff view generated by jsdifflib
Deleted patch
1
From: Alberto Garcia <berto@igalia.com>
2
1
3
There used to be throttle_timers_{detach,attach}_aio_context() calls
4
in bdrv_set_aio_context(), but since 7ca7f0f6db1fedd28d490795d778cf239
5
they are now in blk_set_aio_context().
6
7
Signed-off-by: Alberto Garcia <berto@igalia.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
block/throttle-groups.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block/throttle-groups.c
17
+++ b/block/throttle-groups.c
18
@@ -XXX,XX +XXX,XX @@
19
* Again, all this is handled internally and is mostly transparent to
20
* the outside. The 'throttle_timers' field however has an additional
21
* constraint because it may be temporarily invalid (see for example
22
- * bdrv_set_aio_context()). Therefore in this file a thread will
23
+ * blk_set_aio_context()). Therefore in this file a thread will
24
* access some other BlockBackend's timers only after verifying that
25
* that BlockBackend has throttled requests in the queue.
26
*/
27
--
28
1.8.3.1
29
30
diff view generated by jsdifflib
Deleted patch
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
1
3
migration_incoming_state_destroy() uses qemu_fclose() on the vmstate
4
file. Make sure to call it inside an AioContext acquire/release region.
5
6
This fixes an 'qemu: qemu_mutex_unlock: Operation not permitted' abort
7
in loadvm.
8
9
This patch closes the vmstate file before ending the drained region.
10
Previously we closed the vmstate file after ending the drained region.
11
The order does not matter.
12
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
16
migration/savevm.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
18
19
diff --git a/migration/savevm.c b/migration/savevm.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/migration/savevm.c
22
+++ b/migration/savevm.c
23
@@ -XXX,XX +XXX,XX @@ int load_snapshot(const char *name, Error **errp)
24
25
aio_context_acquire(aio_context);
26
ret = qemu_loadvm_state(f);
27
+ migration_incoming_state_destroy();
28
aio_context_release(aio_context);
29
30
bdrv_drain_all_end();
31
32
- migration_incoming_state_destroy();
33
if (ret < 0) {
34
error_setg(errp, "Error %d while loading VM state", ret);
35
return ret;
36
--
37
1.8.3.1
38
39
diff view generated by jsdifflib
Deleted patch
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
1
3
Avoid duplicating the QEMU command-line.
4
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
tests/qemu-iotests/068 | 15 +++++++++------
9
1 file changed, 9 insertions(+), 6 deletions(-)
10
11
diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068
12
index XXXXXXX..XXXXXXX 100755
13
--- a/tests/qemu-iotests/068
14
+++ b/tests/qemu-iotests/068
15
@@ -XXX,XX +XXX,XX @@ case "$QEMU_DEFAULT_MACHINE" in
16
;;
17
esac
18
19
-# Give qemu some time to boot before saving the VM state
20
-bash -c 'sleep 1; echo -e "savevm 0\nquit"' |\
21
- $QEMU $platform_parm -nographic -monitor stdio -serial none -hda "$TEST_IMG" |\
22
+_qemu()
23
+{
24
+ $QEMU $platform_parm -nographic -monitor stdio -serial none -hda "$TEST_IMG" \
25
+ "$@" |\
26
_filter_qemu | _filter_hmp
27
+}
28
+
29
+# Give qemu some time to boot before saving the VM state
30
+bash -c 'sleep 1; echo -e "savevm 0\nquit"' | _qemu
31
# Now try to continue from that VM state (this should just work)
32
-echo quit |\
33
- $QEMU $platform_parm -nographic -monitor stdio -serial none -hda "$TEST_IMG" -loadvm 0 |\
34
- _filter_qemu | _filter_hmp
35
+echo quit | _qemu -loadvm 0
36
37
# success, all done
38
echo "*** done"
39
--
40
1.8.3.1
41
42
diff view generated by jsdifflib
Deleted patch
1
From: Alberto Garcia <berto@igalia.com>
2
1
3
Qcow2COWRegion has two attributes:
4
5
- The offset of the COW region from the start of the first cluster
6
touched by the I/O request. Since it's always going to be positive
7
and the maximum request size is at most INT_MAX, we can use a
8
regular unsigned int to store this offset.
9
10
- The size of the COW region in bytes. This is guaranteed to be >= 0,
11
so we should use an unsigned type instead.
12
13
In x86_64 this reduces the size of Qcow2COWRegion from 16 to 8 bytes.
14
It will also help keep some assertions simpler now that we know that
15
there are no negative numbers.
16
17
The prototype of do_perform_cow() is also updated to reflect these
18
changes.
19
20
Signed-off-by: Alberto Garcia <berto@igalia.com>
21
Reviewed-by: Eric Blake <eblake@redhat.com>
22
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
23
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
24
---
25
block/qcow2-cluster.c | 4 ++--
26
block/qcow2.h | 4 ++--
27
2 files changed, 4 insertions(+), 4 deletions(-)
28
29
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/block/qcow2-cluster.c
32
+++ b/block/qcow2-cluster.c
33
@@ -XXX,XX +XXX,XX @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
34
static int coroutine_fn do_perform_cow(BlockDriverState *bs,
35
uint64_t src_cluster_offset,
36
uint64_t cluster_offset,
37
- int offset_in_cluster,
38
- int bytes)
39
+ unsigned offset_in_cluster,
40
+ unsigned bytes)
41
{
42
BDRVQcow2State *s = bs->opaque;
43
QEMUIOVector qiov;
44
diff --git a/block/qcow2.h b/block/qcow2.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/block/qcow2.h
47
+++ b/block/qcow2.h
48
@@ -XXX,XX +XXX,XX @@ typedef struct Qcow2COWRegion {
49
* Offset of the COW region in bytes from the start of the first cluster
50
* touched by the request.
51
*/
52
- uint64_t offset;
53
+ unsigned offset;
54
55
/** Number of bytes to copy */
56
- int nb_bytes;
57
+ unsigned nb_bytes;
58
} Qcow2COWRegion;
59
60
/**
61
--
62
1.8.3.1
63
64
diff view generated by jsdifflib
Deleted patch
1
From: Alberto Garcia <berto@igalia.com>
2
1
3
Instead of passing a single buffer pointer to do_perform_cow_write(),
4
pass a QEMUIOVector. This will allow us to merge the write requests
5
for the COW regions and the actual data into a single one.
6
7
Although do_perform_cow_read() does not strictly need to change its
8
API, we're doing it here as well for consistency.
9
10
Signed-off-by: Alberto Garcia <berto@igalia.com>
11
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
14
block/qcow2-cluster.c | 51 ++++++++++++++++++++++++---------------------------
15
1 file changed, 24 insertions(+), 27 deletions(-)
16
17
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/qcow2-cluster.c
20
+++ b/block/qcow2-cluster.c
21
@@ -XXX,XX +XXX,XX @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
22
static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
23
uint64_t src_cluster_offset,
24
unsigned offset_in_cluster,
25
- uint8_t *buffer,
26
- unsigned bytes)
27
+ QEMUIOVector *qiov)
28
{
29
- QEMUIOVector qiov;
30
- struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
31
int ret;
32
33
- if (bytes == 0) {
34
+ if (qiov->size == 0) {
35
return 0;
36
}
37
38
- qemu_iovec_init_external(&qiov, &iov, 1);
39
-
40
BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);
41
42
if (!bs->drv) {
43
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
44
* which can lead to deadlock when block layer copy-on-read is enabled.
45
*/
46
ret = bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_cluster,
47
- bytes, &qiov, 0);
48
+ qiov->size, qiov, 0);
49
if (ret < 0) {
50
return ret;
51
}
52
@@ -XXX,XX +XXX,XX @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
53
static int coroutine_fn do_perform_cow_write(BlockDriverState *bs,
54
uint64_t cluster_offset,
55
unsigned offset_in_cluster,
56
- uint8_t *buffer,
57
- unsigned bytes)
58
+ QEMUIOVector *qiov)
59
{
60
- QEMUIOVector qiov;
61
- struct iovec iov = { .iov_base = buffer, .iov_len = bytes };
62
int ret;
63
64
- if (bytes == 0) {
65
+ if (qiov->size == 0) {
66
return 0;
67
}
68
69
- qemu_iovec_init_external(&qiov, &iov, 1);
70
-
71
ret = qcow2_pre_write_overlap_check(bs, 0,
72
- cluster_offset + offset_in_cluster, bytes);
73
+ cluster_offset + offset_in_cluster, qiov->size);
74
if (ret < 0) {
75
return ret;
76
}
77
78
BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
79
ret = bdrv_co_pwritev(bs->file, cluster_offset + offset_in_cluster,
80
- bytes, &qiov, 0);
81
+ qiov->size, qiov, 0);
82
if (ret < 0) {
83
return ret;
84
}
85
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
86
unsigned data_bytes = end->offset - (start->offset + start->nb_bytes);
87
bool merge_reads;
88
uint8_t *start_buffer, *end_buffer;
89
+ QEMUIOVector qiov;
90
int ret;
91
92
assert(start->nb_bytes <= UINT_MAX - end->nb_bytes);
93
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
94
/* The part of the buffer where the end region is located */
95
end_buffer = start_buffer + buffer_size - end->nb_bytes;
96
97
+ qemu_iovec_init(&qiov, 1);
98
+
99
qemu_co_mutex_unlock(&s->lock);
100
/* First we read the existing data from both COW regions. We
101
* either read the whole region in one go, or the start and end
102
* regions separately. */
103
if (merge_reads) {
104
- ret = do_perform_cow_read(bs, m->offset, start->offset,
105
- start_buffer, buffer_size);
106
+ qemu_iovec_add(&qiov, start_buffer, buffer_size);
107
+ ret = do_perform_cow_read(bs, m->offset, start->offset, &qiov);
108
} else {
109
- ret = do_perform_cow_read(bs, m->offset, start->offset,
110
- start_buffer, start->nb_bytes);
111
+ qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
112
+ ret = do_perform_cow_read(bs, m->offset, start->offset, &qiov);
113
if (ret < 0) {
114
goto fail;
115
}
116
117
- ret = do_perform_cow_read(bs, m->offset, end->offset,
118
- end_buffer, end->nb_bytes);
119
+ qemu_iovec_reset(&qiov);
120
+ qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
121
+ ret = do_perform_cow_read(bs, m->offset, end->offset, &qiov);
122
}
123
if (ret < 0) {
124
goto fail;
125
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
126
}
127
128
/* And now we can write everything */
129
- ret = do_perform_cow_write(bs, m->alloc_offset, start->offset,
130
- start_buffer, start->nb_bytes);
131
+ qemu_iovec_reset(&qiov);
132
+ qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
133
+ ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
134
if (ret < 0) {
135
goto fail;
136
}
137
138
- ret = do_perform_cow_write(bs, m->alloc_offset, end->offset,
139
- end_buffer, end->nb_bytes);
140
+ qemu_iovec_reset(&qiov);
141
+ qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
142
+ ret = do_perform_cow_write(bs, m->alloc_offset, end->offset, &qiov);
143
fail:
144
qemu_co_mutex_lock(&s->lock);
145
146
@@ -XXX,XX +XXX,XX @@ fail:
147
}
148
149
qemu_vfree(start_buffer);
150
+ qemu_iovec_destroy(&qiov);
151
return ret;
152
}
153
154
--
155
1.8.3.1
156
157
diff view generated by jsdifflib
Deleted patch
1
From: Alberto Garcia <berto@igalia.com>
2
1
3
If the guest tries to write data that results on the allocation of a
4
new cluster, instead of writing the guest data first and then the data
5
from the COW regions, write everything together using one single I/O
6
operation.
7
8
This can improve the write performance by 25% or more, depending on
9
several factors such as the media type, the cluster size and the I/O
10
request size.
11
12
Signed-off-by: Alberto Garcia <berto@igalia.com>
13
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
16
block/qcow2-cluster.c | 40 ++++++++++++++++++++++++--------
17
block/qcow2.c | 64 +++++++++++++++++++++++++++++++++++++++++++--------
18
block/qcow2.h | 7 ++++++
19
3 files changed, 91 insertions(+), 20 deletions(-)
20
21
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/qcow2-cluster.c
24
+++ b/block/qcow2-cluster.c
25
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
26
assert(start->nb_bytes <= UINT_MAX - end->nb_bytes);
27
assert(start->nb_bytes + end->nb_bytes <= UINT_MAX - data_bytes);
28
assert(start->offset + start->nb_bytes <= end->offset);
29
+ assert(!m->data_qiov || m->data_qiov->size == data_bytes);
30
31
if (start->nb_bytes == 0 && end->nb_bytes == 0) {
32
return 0;
33
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
34
/* The part of the buffer where the end region is located */
35
end_buffer = start_buffer + buffer_size - end->nb_bytes;
36
37
- qemu_iovec_init(&qiov, 1);
38
+ qemu_iovec_init(&qiov, 2 + (m->data_qiov ? m->data_qiov->niov : 0));
39
40
qemu_co_mutex_unlock(&s->lock);
41
/* First we read the existing data from both COW regions. We
42
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
43
}
44
}
45
46
- /* And now we can write everything */
47
- qemu_iovec_reset(&qiov);
48
- qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
49
- ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
50
- if (ret < 0) {
51
- goto fail;
52
+ /* And now we can write everything. If we have the guest data we
53
+ * can write everything in one single operation */
54
+ if (m->data_qiov) {
55
+ qemu_iovec_reset(&qiov);
56
+ if (start->nb_bytes) {
57
+ qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
58
+ }
59
+ qemu_iovec_concat(&qiov, m->data_qiov, 0, data_bytes);
60
+ if (end->nb_bytes) {
61
+ qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
62
+ }
63
+ /* NOTE: we have a write_aio blkdebug event here followed by
64
+ * a cow_write one in do_perform_cow_write(), but there's only
65
+ * one single I/O operation */
66
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
67
+ ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
68
+ } else {
69
+ /* If there's no guest data then write both COW regions separately */
70
+ qemu_iovec_reset(&qiov);
71
+ qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
72
+ ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
73
+ if (ret < 0) {
74
+ goto fail;
75
+ }
76
+
77
+ qemu_iovec_reset(&qiov);
78
+ qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
79
+ ret = do_perform_cow_write(bs, m->alloc_offset, end->offset, &qiov);
80
}
81
82
- qemu_iovec_reset(&qiov);
83
- qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);
84
- ret = do_perform_cow_write(bs, m->alloc_offset, end->offset, &qiov);
85
fail:
86
qemu_co_mutex_lock(&s->lock);
87
88
diff --git a/block/qcow2.c b/block/qcow2.c
89
index XXXXXXX..XXXXXXX 100644
90
--- a/block/qcow2.c
91
+++ b/block/qcow2.c
92
@@ -XXX,XX +XXX,XX @@ fail:
93
return ret;
94
}
95
96
+/* Check if it's possible to merge a write request with the writing of
97
+ * the data from the COW regions */
98
+static bool merge_cow(uint64_t offset, unsigned bytes,
99
+ QEMUIOVector *hd_qiov, QCowL2Meta *l2meta)
100
+{
101
+ QCowL2Meta *m;
102
+
103
+ for (m = l2meta; m != NULL; m = m->next) {
104
+ /* If both COW regions are empty then there's nothing to merge */
105
+ if (m->cow_start.nb_bytes == 0 && m->cow_end.nb_bytes == 0) {
106
+ continue;
107
+ }
108
+
109
+ /* The data (middle) region must be immediately after the
110
+ * start region */
111
+ if (l2meta_cow_start(m) + m->cow_start.nb_bytes != offset) {
112
+ continue;
113
+ }
114
+
115
+ /* The end region must be immediately after the data (middle)
116
+ * region */
117
+ if (m->offset + m->cow_end.offset != offset + bytes) {
118
+ continue;
119
+ }
120
+
121
+ /* Make sure that adding both COW regions to the QEMUIOVector
122
+ * does not exceed IOV_MAX */
123
+ if (hd_qiov->niov > IOV_MAX - 2) {
124
+ continue;
125
+ }
126
+
127
+ m->data_qiov = hd_qiov;
128
+ return true;
129
+ }
130
+
131
+ return false;
132
+}
133
+
134
static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
135
uint64_t bytes, QEMUIOVector *qiov,
136
int flags)
137
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
138
goto fail;
139
}
140
141
- qemu_co_mutex_unlock(&s->lock);
142
- BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
143
- trace_qcow2_writev_data(qemu_coroutine_self(),
144
- cluster_offset + offset_in_cluster);
145
- ret = bdrv_co_pwritev(bs->file,
146
- cluster_offset + offset_in_cluster,
147
- cur_bytes, &hd_qiov, 0);
148
- qemu_co_mutex_lock(&s->lock);
149
- if (ret < 0) {
150
- goto fail;
151
+ /* If we need to do COW, check if it's possible to merge the
152
+ * writing of the guest data together with that of the COW regions.
153
+ * If it's not possible (or not necessary) then write the
154
+ * guest data now. */
155
+ if (!merge_cow(offset, cur_bytes, &hd_qiov, l2meta)) {
156
+ qemu_co_mutex_unlock(&s->lock);
157
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
158
+ trace_qcow2_writev_data(qemu_coroutine_self(),
159
+ cluster_offset + offset_in_cluster);
160
+ ret = bdrv_co_pwritev(bs->file,
161
+ cluster_offset + offset_in_cluster,
162
+ cur_bytes, &hd_qiov, 0);
163
+ qemu_co_mutex_lock(&s->lock);
164
+ if (ret < 0) {
165
+ goto fail;
166
+ }
167
}
168
169
while (l2meta != NULL) {
170
diff --git a/block/qcow2.h b/block/qcow2.h
171
index XXXXXXX..XXXXXXX 100644
172
--- a/block/qcow2.h
173
+++ b/block/qcow2.h
174
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
175
*/
176
Qcow2COWRegion cow_end;
177
178
+ /**
179
+ * The I/O vector with the data from the actual guest write request.
180
+ * If non-NULL, this is meant to be merged together with the data
181
+ * from @cow_start and @cow_end into one single write operation.
182
+ */
183
+ QEMUIOVector *data_qiov;
184
+
185
/** Pointer to next L2Meta of the same write request */
186
struct QCowL2Meta *next;
187
188
--
189
1.8.3.1
190
191
diff view generated by jsdifflib
Deleted patch
1
From: Alberto Garcia <berto@igalia.com>
2
1
3
We already have functions for doing these calculations, so let's use
4
them instead of doing everything by hand. This makes the code a bit
5
more readable.
6
7
Signed-off-by: Alberto Garcia <berto@igalia.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
block/qcow2-cluster.c | 4 ++--
11
block/qcow2.c | 2 +-
12
2 files changed, 3 insertions(+), 3 deletions(-)
13
14
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block/qcow2-cluster.c
17
+++ b/block/qcow2-cluster.c
18
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
19
20
/* find the cluster offset for the given disk offset */
21
22
- l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
23
+ l2_index = offset_to_l2_index(s, offset);
24
*cluster_offset = be64_to_cpu(l2_table[l2_index]);
25
26
nb_clusters = size_to_clusters(s, bytes_needed);
27
@@ -XXX,XX +XXX,XX @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
28
29
/* find the cluster offset for the given disk offset */
30
31
- l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
32
+ l2_index = offset_to_l2_index(s, offset);
33
34
*new_l2_table = l2_table;
35
*new_l2_index = l2_index;
36
diff --git a/block/qcow2.c b/block/qcow2.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/block/qcow2.c
39
+++ b/block/qcow2.c
40
@@ -XXX,XX +XXX,XX @@ static int validate_table_offset(BlockDriverState *bs, uint64_t offset,
41
}
42
43
/* Tables must be cluster aligned */
44
- if (offset & (s->cluster_size - 1)) {
45
+ if (offset_into_cluster(s, offset) != 0) {
46
return -EINVAL;
47
}
48
49
--
50
1.8.3.1
51
52
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Eric Blake <eblake@redhat.com>
3
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
4
---
5
block/qed-cluster.c | 94 ++++++++++++++++++-----------------------------------
6
block/qed-table.c | 15 +++------
7
block/qed.h | 3 +-
8
3 files changed, 36 insertions(+), 76 deletions(-)
9
1
10
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/block/qed-cluster.c
13
+++ b/block/qed-cluster.c
14
@@ -XXX,XX +XXX,XX @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
15
return i - index;
16
}
17
18
-typedef struct {
19
- BDRVQEDState *s;
20
- uint64_t pos;
21
- size_t len;
22
-
23
- QEDRequest *request;
24
-
25
- /* User callback */
26
- QEDFindClusterFunc *cb;
27
- void *opaque;
28
-} QEDFindClusterCB;
29
-
30
-static void qed_find_cluster_cb(void *opaque, int ret)
31
-{
32
- QEDFindClusterCB *find_cluster_cb = opaque;
33
- BDRVQEDState *s = find_cluster_cb->s;
34
- QEDRequest *request = find_cluster_cb->request;
35
- uint64_t offset = 0;
36
- size_t len = 0;
37
- unsigned int index;
38
- unsigned int n;
39
-
40
- qed_acquire(s);
41
- if (ret) {
42
- goto out;
43
- }
44
-
45
- index = qed_l2_index(s, find_cluster_cb->pos);
46
- n = qed_bytes_to_clusters(s,
47
- qed_offset_into_cluster(s, find_cluster_cb->pos) +
48
- find_cluster_cb->len);
49
- n = qed_count_contiguous_clusters(s, request->l2_table->table,
50
- index, n, &offset);
51
-
52
- if (qed_offset_is_unalloc_cluster(offset)) {
53
- ret = QED_CLUSTER_L2;
54
- } else if (qed_offset_is_zero_cluster(offset)) {
55
- ret = QED_CLUSTER_ZERO;
56
- } else if (qed_check_cluster_offset(s, offset)) {
57
- ret = QED_CLUSTER_FOUND;
58
- } else {
59
- ret = -EINVAL;
60
- }
61
-
62
- len = MIN(find_cluster_cb->len, n * s->header.cluster_size -
63
- qed_offset_into_cluster(s, find_cluster_cb->pos));
64
-
65
-out:
66
- find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len);
67
- qed_release(s);
68
- g_free(find_cluster_cb);
69
-}
70
-
71
/**
72
* Find the offset of a data cluster
73
*
74
@@ -XXX,XX +XXX,XX @@ out:
75
void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
76
size_t len, QEDFindClusterFunc *cb, void *opaque)
77
{
78
- QEDFindClusterCB *find_cluster_cb;
79
uint64_t l2_offset;
80
+ uint64_t offset = 0;
81
+ unsigned int index;
82
+ unsigned int n;
83
+ int ret;
84
85
/* Limit length to L2 boundary. Requests are broken up at the L2 boundary
86
* so that a request acts on one L2 table at a time.
87
@@ -XXX,XX +XXX,XX @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
88
return;
89
}
90
91
- find_cluster_cb = g_malloc(sizeof(*find_cluster_cb));
92
- find_cluster_cb->s = s;
93
- find_cluster_cb->pos = pos;
94
- find_cluster_cb->len = len;
95
- find_cluster_cb->cb = cb;
96
- find_cluster_cb->opaque = opaque;
97
- find_cluster_cb->request = request;
98
+ ret = qed_read_l2_table(s, request, l2_offset);
99
+ qed_acquire(s);
100
+ if (ret) {
101
+ goto out;
102
+ }
103
+
104
+ index = qed_l2_index(s, pos);
105
+ n = qed_bytes_to_clusters(s,
106
+ qed_offset_into_cluster(s, pos) + len);
107
+ n = qed_count_contiguous_clusters(s, request->l2_table->table,
108
+ index, n, &offset);
109
+
110
+ if (qed_offset_is_unalloc_cluster(offset)) {
111
+ ret = QED_CLUSTER_L2;
112
+ } else if (qed_offset_is_zero_cluster(offset)) {
113
+ ret = QED_CLUSTER_ZERO;
114
+ } else if (qed_check_cluster_offset(s, offset)) {
115
+ ret = QED_CLUSTER_FOUND;
116
+ } else {
117
+ ret = -EINVAL;
118
+ }
119
+
120
+ len = MIN(len,
121
+ n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
122
123
- qed_read_l2_table(s, request, l2_offset,
124
- qed_find_cluster_cb, find_cluster_cb);
125
+out:
126
+ cb(opaque, ret, offset, len);
127
+ qed_release(s);
128
}
129
diff --git a/block/qed-table.c b/block/qed-table.c
130
index XXXXXXX..XXXXXXX 100644
131
--- a/block/qed-table.c
132
+++ b/block/qed-table.c
133
@@ -XXX,XX +XXX,XX @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
134
return ret;
135
}
136
137
-void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
138
- BlockCompletionFunc *cb, void *opaque)
139
+int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
140
{
141
int ret;
142
143
@@ -XXX,XX +XXX,XX @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
144
/* Check for cached L2 entry */
145
request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);
146
if (request->l2_table) {
147
- cb(opaque, 0);
148
- return;
149
+ return 0;
150
}
151
152
request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache);
153
@@ -XXX,XX +XXX,XX @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
154
}
155
qed_release(s);
156
157
- cb(opaque, ret);
158
+ return ret;
159
}
160
161
int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
162
{
163
- int ret = -EINPROGRESS;
164
-
165
- qed_read_l2_table(s, request, offset, qed_sync_cb, &ret);
166
- BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
167
-
168
- return ret;
169
+ return qed_read_l2_table(s, request, offset);
170
}
171
172
void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
173
diff --git a/block/qed.h b/block/qed.h
174
index XXXXXXX..XXXXXXX 100644
175
--- a/block/qed.h
176
+++ b/block/qed.h
177
@@ -XXX,XX +XXX,XX @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
178
unsigned int n);
179
int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
180
uint64_t offset);
181
-void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
182
- BlockCompletionFunc *cb, void *opaque);
183
+int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset);
184
void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
185
unsigned int index, unsigned int n, bool flush,
186
BlockCompletionFunc *cb, void *opaque);
187
--
188
1.8.3.1
189
190
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
3
---
4
block/qed-cluster.c | 39 ++++++++++++++++++++++-----------------
5
block/qed.c | 24 +++++++++++-------------
6
block/qed.h | 4 ++--
7
3 files changed, 35 insertions(+), 32 deletions(-)
8
1
9
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/block/qed-cluster.c
12
+++ b/block/qed-cluster.c
13
@@ -XXX,XX +XXX,XX @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
14
* @s: QED state
15
* @request: L2 cache entry
16
* @pos: Byte position in device
17
- * @len: Number of bytes
18
- * @cb: Completion function
19
- * @opaque: User data for completion function
20
+ * @len: Number of bytes (may be shortened on return)
21
+ * @img_offset: Contains offset in the image file on success
22
*
23
* This function translates a position in the block device to an offset in the
24
- * image file. It invokes the cb completion callback to report back the
25
- * translated offset or unallocated range in the image file.
26
+ * image file. The translated offset or unallocated range in the image file is
27
+ * reported back in *img_offset and *len.
28
*
29
* If the L2 table exists, request->l2_table points to the L2 table cache entry
30
* and the caller must free the reference when they are finished. The cache
31
* entry is exposed in this way to avoid callers having to read the L2 table
32
* again later during request processing. If request->l2_table is non-NULL it
33
* will be unreferenced before taking on the new cache entry.
34
+ *
35
+ * On success QED_CLUSTER_FOUND is returned and img_offset/len are a contiguous
36
+ * range in the image file.
37
+ *
38
+ * On failure QED_CLUSTER_L2 or QED_CLUSTER_L1 is returned for missing L2 or L1
39
+ * table offset, respectively. len is number of contiguous unallocated bytes.
40
*/
41
-void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
42
- size_t len, QEDFindClusterFunc *cb, void *opaque)
43
+int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
44
+ size_t *len, uint64_t *img_offset)
45
{
46
uint64_t l2_offset;
47
uint64_t offset = 0;
48
@@ -XXX,XX +XXX,XX @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
49
/* Limit length to L2 boundary. Requests are broken up at the L2 boundary
50
* so that a request acts on one L2 table at a time.
51
*/
52
- len = MIN(len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
53
+ *len = MIN(*len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos);
54
55
l2_offset = s->l1_table->offsets[qed_l1_index(s, pos)];
56
if (qed_offset_is_unalloc_cluster(l2_offset)) {
57
- cb(opaque, QED_CLUSTER_L1, 0, len);
58
- return;
59
+ *img_offset = 0;
60
+ return QED_CLUSTER_L1;
61
}
62
if (!qed_check_table_offset(s, l2_offset)) {
63
- cb(opaque, -EINVAL, 0, 0);
64
- return;
65
+ *img_offset = *len = 0;
66
+ return -EINVAL;
67
}
68
69
ret = qed_read_l2_table(s, request, l2_offset);
70
@@ -XXX,XX +XXX,XX @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
71
}
72
73
index = qed_l2_index(s, pos);
74
- n = qed_bytes_to_clusters(s,
75
- qed_offset_into_cluster(s, pos) + len);
76
+ n = qed_bytes_to_clusters(s, qed_offset_into_cluster(s, pos) + *len);
77
n = qed_count_contiguous_clusters(s, request->l2_table->table,
78
index, n, &offset);
79
80
@@ -XXX,XX +XXX,XX @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
81
ret = -EINVAL;
82
}
83
84
- len = MIN(len,
85
- n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
86
+ *len = MIN(*len,
87
+ n * s->header.cluster_size - qed_offset_into_cluster(s, pos));
88
89
out:
90
- cb(opaque, ret, offset, len);
91
+ *img_offset = offset;
92
qed_release(s);
93
+ return ret;
94
}
95
diff --git a/block/qed.c b/block/qed.c
96
index XXXXXXX..XXXXXXX 100644
97
--- a/block/qed.c
98
+++ b/block/qed.c
99
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,
100
.file = file,
101
};
102
QEDRequest request = { .l2_table = NULL };
103
+ uint64_t offset;
104
+ int ret;
105
106
- qed_find_cluster(s, &request, cb.pos, len, qed_is_allocated_cb, &cb);
107
+ ret = qed_find_cluster(s, &request, cb.pos, &len, &offset);
108
+ qed_is_allocated_cb(&cb, ret, offset, len);
109
110
- /* Now sleep if the callback wasn't invoked immediately */
111
- while (cb.status == BDRV_BLOCK_OFFSET_MASK) {
112
- cb.co = qemu_coroutine_self();
113
- qemu_coroutine_yield();
114
- }
115
+ /* The callback was invoked immediately */
116
+ assert(cb.status != BDRV_BLOCK_OFFSET_MASK);
117
118
qed_unref_l2_cache_entry(request.l2_table);
119
120
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
121
* or -errno
122
* @offset: Cluster offset in bytes
123
* @len: Length in bytes
124
- *
125
- * Callback from qed_find_cluster().
126
*/
127
static void qed_aio_write_data(void *opaque, int ret,
128
uint64_t offset, size_t len)
129
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_data(void *opaque, int ret,
130
* or -errno
131
* @offset: Cluster offset in bytes
132
* @len: Length in bytes
133
- *
134
- * Callback from qed_find_cluster().
135
*/
136
static void qed_aio_read_data(void *opaque, int ret,
137
uint64_t offset, size_t len)
138
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
139
BDRVQEDState *s = acb_to_s(acb);
140
QEDFindClusterFunc *io_fn = (acb->flags & QED_AIOCB_WRITE) ?
141
qed_aio_write_data : qed_aio_read_data;
142
+ uint64_t offset;
143
+ size_t len;
144
145
trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size);
146
147
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
148
}
149
150
/* Find next cluster and start I/O */
151
- qed_find_cluster(s, &acb->request,
152
- acb->cur_pos, acb->end_pos - acb->cur_pos,
153
- io_fn, acb);
154
+ len = acb->end_pos - acb->cur_pos;
155
+ ret = qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset);
156
+ io_fn(acb, ret, offset, len);
157
}
158
159
static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
160
diff --git a/block/qed.h b/block/qed.h
161
index XXXXXXX..XXXXXXX 100644
162
--- a/block/qed.h
163
+++ b/block/qed.h
164
@@ -XXX,XX +XXX,XX @@ int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
165
/**
166
* Cluster functions
167
*/
168
-void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
169
- size_t len, QEDFindClusterFunc *cb, void *opaque);
170
+int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
171
+ size_t *len, uint64_t *img_offset);
172
173
/**
174
* Consistency check
175
--
176
1.8.3.1
177
178
diff view generated by jsdifflib
Deleted patch
1
With this change, qed_aio_write_prefill() and qed_aio_write_postfill()
2
collapse into a single function. This is reflected by a rename of the
3
combined function to qed_aio_write_cow().
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
9
block/qed.c | 57 +++++++++++++++++++++++----------------------------------
10
1 file changed, 23 insertions(+), 34 deletions(-)
11
12
diff --git a/block/qed.c b/block/qed.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block/qed.c
15
+++ b/block/qed.c
16
@@ -XXX,XX +XXX,XX @@ static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
17
* @pos: Byte position in device
18
* @len: Number of bytes
19
* @offset: Byte offset in image file
20
- * @cb: Completion function
21
- * @opaque: User data for completion function
22
*/
23
-static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos,
24
- uint64_t len, uint64_t offset,
25
- BlockCompletionFunc *cb,
26
- void *opaque)
27
+static int qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos,
28
+ uint64_t len, uint64_t offset)
29
{
30
QEMUIOVector qiov;
31
QEMUIOVector *backing_qiov = NULL;
32
@@ -XXX,XX +XXX,XX @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos,
33
34
/* Skip copy entirely if there is no work to do */
35
if (len == 0) {
36
- cb(opaque, 0);
37
- return;
38
+ return 0;
39
}
40
41
iov = (struct iovec) {
42
@@ -XXX,XX +XXX,XX @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos,
43
ret = 0;
44
out:
45
qemu_vfree(iov.iov_base);
46
- cb(opaque, ret);
47
+ return ret;
48
}
49
50
/**
51
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_main(void *opaque, int ret)
52
}
53
54
/**
55
- * Populate back untouched region of new data cluster
56
+ * Populate untouched regions of new data cluster
57
*/
58
-static void qed_aio_write_postfill(void *opaque, int ret)
59
+static void qed_aio_write_cow(void *opaque, int ret)
60
{
61
QEDAIOCB *acb = opaque;
62
BDRVQEDState *s = acb_to_s(acb);
63
- uint64_t start = acb->cur_pos + acb->cur_qiov.size;
64
- uint64_t len =
65
- qed_start_of_cluster(s, start + s->header.cluster_size - 1) - start;
66
- uint64_t offset = acb->cur_cluster +
67
- qed_offset_into_cluster(s, acb->cur_pos) +
68
- acb->cur_qiov.size;
69
+ uint64_t start, len, offset;
70
+
71
+ /* Populate front untouched region of new data cluster */
72
+ start = qed_start_of_cluster(s, acb->cur_pos);
73
+ len = qed_offset_into_cluster(s, acb->cur_pos);
74
75
+ trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster);
76
+ ret = qed_copy_from_backing_file(s, start, len, acb->cur_cluster);
77
if (ret) {
78
qed_aio_complete(acb, ret);
79
return;
80
}
81
82
- trace_qed_aio_write_postfill(s, acb, start, len, offset);
83
- qed_copy_from_backing_file(s, start, len, offset,
84
- qed_aio_write_main, acb);
85
-}
86
+ /* Populate back untouched region of new data cluster */
87
+ start = acb->cur_pos + acb->cur_qiov.size;
88
+ len = qed_start_of_cluster(s, start + s->header.cluster_size - 1) - start;
89
+ offset = acb->cur_cluster +
90
+ qed_offset_into_cluster(s, acb->cur_pos) +
91
+ acb->cur_qiov.size;
92
93
-/**
94
- * Populate front untouched region of new data cluster
95
- */
96
-static void qed_aio_write_prefill(void *opaque, int ret)
97
-{
98
- QEDAIOCB *acb = opaque;
99
- BDRVQEDState *s = acb_to_s(acb);
100
- uint64_t start = qed_start_of_cluster(s, acb->cur_pos);
101
- uint64_t len = qed_offset_into_cluster(s, acb->cur_pos);
102
+ trace_qed_aio_write_postfill(s, acb, start, len, offset);
103
+ ret = qed_copy_from_backing_file(s, start, len, offset);
104
105
- trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster);
106
- qed_copy_from_backing_file(s, start, len, acb->cur_cluster,
107
- qed_aio_write_postfill, acb);
108
+ qed_aio_write_main(acb, ret);
109
}
110
111
/**
112
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
113
114
cb = qed_aio_write_zero_cluster;
115
} else {
116
- cb = qed_aio_write_prefill;
117
+ cb = qed_aio_write_cow;
118
acb->cur_cluster = qed_alloc_clusters(s, acb->cur_nclusters);
119
}
120
121
--
122
1.8.3.1
123
124
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
3
---
4
block/qed.c | 32 ++++++++++++--------------------
5
1 file changed, 12 insertions(+), 20 deletions(-)
6
1
7
diff --git a/block/qed.c b/block/qed.c
8
index XXXXXXX..XXXXXXX 100644
9
--- a/block/qed.c
10
+++ b/block/qed.c
11
@@ -XXX,XX +XXX,XX @@ int qed_write_header_sync(BDRVQEDState *s)
12
* This function only updates known header fields in-place and does not affect
13
* extra data after the QED header.
14
*/
15
-static void qed_write_header(BDRVQEDState *s, BlockCompletionFunc cb,
16
- void *opaque)
17
+static int qed_write_header(BDRVQEDState *s)
18
{
19
/* We must write full sectors for O_DIRECT but cannot necessarily generate
20
* the data following the header if an unrecognized compat feature is
21
@@ -XXX,XX +XXX,XX @@ static void qed_write_header(BDRVQEDState *s, BlockCompletionFunc cb,
22
ret = 0;
23
out:
24
qemu_vfree(buf);
25
- cb(opaque, ret);
26
+ return ret;
27
}
28
29
static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_size)
30
@@ -XXX,XX +XXX,XX @@ static void qed_unplug_allocating_write_reqs(BDRVQEDState *s)
31
}
32
}
33
34
-static void qed_finish_clear_need_check(void *opaque, int ret)
35
-{
36
- /* Do nothing */
37
-}
38
-
39
-static void qed_flush_after_clear_need_check(void *opaque, int ret)
40
-{
41
- BDRVQEDState *s = opaque;
42
-
43
- bdrv_aio_flush(s->bs, qed_finish_clear_need_check, s);
44
-
45
- /* No need to wait until flush completes */
46
- qed_unplug_allocating_write_reqs(s);
47
-}
48
-
49
static void qed_clear_need_check(void *opaque, int ret)
50
{
51
BDRVQEDState *s = opaque;
52
@@ -XXX,XX +XXX,XX @@ static void qed_clear_need_check(void *opaque, int ret)
53
}
54
55
s->header.features &= ~QED_F_NEED_CHECK;
56
- qed_write_header(s, qed_flush_after_clear_need_check, s);
57
+ ret = qed_write_header(s);
58
+ (void) ret;
59
+
60
+ qed_unplug_allocating_write_reqs(s);
61
+
62
+ ret = bdrv_flush(s->bs);
63
+ (void) ret;
64
}
65
66
static void qed_need_check_timer_cb(void *opaque)
67
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
68
{
69
BDRVQEDState *s = acb_to_s(acb);
70
BlockCompletionFunc *cb;
71
+ int ret;
72
73
/* Cancel timer when the first allocating request comes in */
74
if (QSIMPLEQ_EMPTY(&s->allocating_write_reqs)) {
75
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
76
77
if (qed_should_set_need_check(s)) {
78
s->header.features |= QED_F_NEED_CHECK;
79
- qed_write_header(s, cb, acb);
80
+ ret = qed_write_header(s);
81
+ cb(acb, ret);
82
} else {
83
cb(acb, 0);
84
}
85
--
86
1.8.3.1
87
88
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
3
---
4
block/qed-table.c | 47 ++++++++++++-----------------------------------
5
block/qed.c | 12 +++++++-----
6
block/qed.h | 8 +++-----
7
3 files changed, 22 insertions(+), 45 deletions(-)
8
1
9
diff --git a/block/qed-table.c b/block/qed-table.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/block/qed-table.c
12
+++ b/block/qed-table.c
13
@@ -XXX,XX +XXX,XX @@ out:
14
* @index: Index of first element
15
* @n: Number of elements
16
* @flush: Whether or not to sync to disk
17
- * @cb: Completion function
18
- * @opaque: Argument for completion function
19
*/
20
-static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
21
- unsigned int index, unsigned int n, bool flush,
22
- BlockCompletionFunc *cb, void *opaque)
23
+static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
24
+ unsigned int index, unsigned int n, bool flush)
25
{
26
unsigned int sector_mask = BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1;
27
unsigned int start, end, i;
28
@@ -XXX,XX +XXX,XX @@ static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
29
ret = 0;
30
out:
31
qemu_vfree(new_table);
32
- cb(opaque, ret);
33
-}
34
-
35
-/**
36
- * Propagate return value from async callback
37
- */
38
-static void qed_sync_cb(void *opaque, int ret)
39
-{
40
- *(int *)opaque = ret;
41
+ return ret;
42
}
43
44
int qed_read_l1_table_sync(BDRVQEDState *s)
45
@@ -XXX,XX +XXX,XX @@ int qed_read_l1_table_sync(BDRVQEDState *s)
46
return qed_read_table(s, s->header.l1_table_offset, s->l1_table);
47
}
48
49
-void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n,
50
- BlockCompletionFunc *cb, void *opaque)
51
+int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n)
52
{
53
BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE);
54
- qed_write_table(s, s->header.l1_table_offset,
55
- s->l1_table, index, n, false, cb, opaque);
56
+ return qed_write_table(s, s->header.l1_table_offset,
57
+ s->l1_table, index, n, false);
58
}
59
60
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
61
unsigned int n)
62
{
63
- int ret = -EINPROGRESS;
64
-
65
- qed_write_l1_table(s, index, n, qed_sync_cb, &ret);
66
- BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
67
-
68
- return ret;
69
+ return qed_write_l1_table(s, index, n);
70
}
71
72
int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
73
@@ -XXX,XX +XXX,XX @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset
74
return qed_read_l2_table(s, request, offset);
75
}
76
77
-void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
78
- unsigned int index, unsigned int n, bool flush,
79
- BlockCompletionFunc *cb, void *opaque)
80
+int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
81
+ unsigned int index, unsigned int n, bool flush)
82
{
83
BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE);
84
- qed_write_table(s, request->l2_table->offset,
85
- request->l2_table->table, index, n, flush, cb, opaque);
86
+ return qed_write_table(s, request->l2_table->offset,
87
+ request->l2_table->table, index, n, flush);
88
}
89
90
int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
91
unsigned int index, unsigned int n, bool flush)
92
{
93
- int ret = -EINPROGRESS;
94
-
95
- qed_write_l2_table(s, request, index, n, flush, qed_sync_cb, &ret);
96
- BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
97
-
98
- return ret;
99
+ return qed_write_l2_table(s, request, index, n, flush);
100
}
101
diff --git a/block/qed.c b/block/qed.c
102
index XXXXXXX..XXXXXXX 100644
103
--- a/block/qed.c
104
+++ b/block/qed.c
105
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_l1_update(void *opaque, int ret)
106
index = qed_l1_index(s, acb->cur_pos);
107
s->l1_table->offsets[index] = acb->request.l2_table->offset;
108
109
- qed_write_l1_table(s, index, 1, qed_commit_l2_update, acb);
110
+ ret = qed_write_l1_table(s, index, 1);
111
+ qed_commit_l2_update(acb, ret);
112
}
113
114
/**
115
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
116
117
if (need_alloc) {
118
/* Write out the whole new L2 table */
119
- qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true,
120
- qed_aio_write_l1_update, acb);
121
+ ret = qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true);
122
+ qed_aio_write_l1_update(acb, ret);
123
} else {
124
/* Write out only the updated part of the L2 table */
125
- qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters, false,
126
- qed_aio_next_io_cb, acb);
127
+ ret = qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters,
128
+ false);
129
+ qed_aio_next_io(acb, ret);
130
}
131
return;
132
133
diff --git a/block/qed.h b/block/qed.h
134
index XXXXXXX..XXXXXXX 100644
135
--- a/block/qed.h
136
+++ b/block/qed.h
137
@@ -XXX,XX +XXX,XX @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table);
138
* Table I/O functions
139
*/
140
int qed_read_l1_table_sync(BDRVQEDState *s);
141
-void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n,
142
- BlockCompletionFunc *cb, void *opaque);
143
+int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n);
144
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
145
unsigned int n);
146
int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
147
uint64_t offset);
148
int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset);
149
-void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
150
- unsigned int index, unsigned int n, bool flush,
151
- BlockCompletionFunc *cb, void *opaque);
152
+int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
153
+ unsigned int index, unsigned int n, bool flush);
154
int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
155
unsigned int index, unsigned int n, bool flush);
156
157
--
158
1.8.3.1
159
160
diff view generated by jsdifflib
Deleted patch
1
Note that this code is generally not running in coroutine context, so
2
this is an actual blocking synchronous operation. We'll fix this in a
3
moment.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
---
8
block/qed.c | 61 +++++++++++++++++++------------------------------------------
9
1 file changed, 19 insertions(+), 42 deletions(-)
10
11
diff --git a/block/qed.c b/block/qed.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/block/qed.c
14
+++ b/block/qed.c
15
@@ -XXX,XX +XXX,XX @@ static void qed_aio_start_io(QEDAIOCB *acb)
16
qed_aio_next_io(acb, 0);
17
}
18
19
-static void qed_aio_next_io_cb(void *opaque, int ret)
20
-{
21
- QEDAIOCB *acb = opaque;
22
-
23
- qed_aio_next_io(acb, ret);
24
-}
25
-
26
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
27
{
28
assert(!s->allocating_write_reqs_plugged);
29
@@ -XXX,XX +XXX,XX @@ err:
30
qed_aio_complete(acb, ret);
31
}
32
33
-static void qed_aio_write_l2_update_cb(void *opaque, int ret)
34
-{
35
- QEDAIOCB *acb = opaque;
36
- qed_aio_write_l2_update(acb, ret, acb->cur_cluster);
37
-}
38
-
39
-/**
40
- * Flush new data clusters before updating the L2 table
41
- *
42
- * This flush is necessary when a backing file is in use. A crash during an
43
- * allocating write could result in empty clusters in the image. If the write
44
- * only touched a subregion of the cluster, then backing image sectors have
45
- * been lost in the untouched region. The solution is to flush after writing a
46
- * new data cluster and before updating the L2 table.
47
- */
48
-static void qed_aio_write_flush_before_l2_update(void *opaque, int ret)
49
-{
50
- QEDAIOCB *acb = opaque;
51
- BDRVQEDState *s = acb_to_s(acb);
52
-
53
- if (!bdrv_aio_flush(s->bs->file->bs, qed_aio_write_l2_update_cb, opaque)) {
54
- qed_aio_complete(acb, -EIO);
55
- }
56
-}
57
-
58
/**
59
* Write data to the image file
60
*/
61
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_main(void *opaque, int ret)
62
BDRVQEDState *s = acb_to_s(acb);
63
uint64_t offset = acb->cur_cluster +
64
qed_offset_into_cluster(s, acb->cur_pos);
65
- BlockCompletionFunc *next_fn;
66
67
trace_qed_aio_write_main(s, acb, ret, offset, acb->cur_qiov.size);
68
69
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_main(void *opaque, int ret)
70
return;
71
}
72
73
+ BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
74
+ ret = bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov);
75
+ if (ret >= 0) {
76
+ ret = 0;
77
+ }
78
+
79
if (acb->find_cluster_ret == QED_CLUSTER_FOUND) {
80
- next_fn = qed_aio_next_io_cb;
81
+ qed_aio_next_io(acb, ret);
82
} else {
83
if (s->bs->backing) {
84
- next_fn = qed_aio_write_flush_before_l2_update;
85
- } else {
86
- next_fn = qed_aio_write_l2_update_cb;
87
+ /*
88
+ * Flush new data clusters before updating the L2 table
89
+ *
90
+ * This flush is necessary when a backing file is in use. A crash
91
+ * during an allocating write could result in empty clusters in the
92
+ * image. If the write only touched a subregion of the cluster,
93
+ * then backing image sectors have been lost in the untouched
94
+ * region. The solution is to flush after writing a new data
95
+ * cluster and before updating the L2 table.
96
+ */
97
+ ret = bdrv_flush(s->bs->file->bs);
98
}
99
+ qed_aio_write_l2_update(acb, ret, acb->cur_cluster);
100
}
101
-
102
- BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
103
- bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE,
104
- &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE,
105
- next_fn, acb);
106
}
107
108
/**
109
--
110
1.8.3.1
111
112
diff view generated by jsdifflib
Deleted patch
1
qed_commit_l2_update() is unconditionally called at the end of
2
qed_aio_write_l1_update(). Inline it.
3
1
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
7
block/qed.c | 36 ++++++++++++++----------------------
8
1 file changed, 14 insertions(+), 22 deletions(-)
9
10
diff --git a/block/qed.c b/block/qed.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/block/qed.c
13
+++ b/block/qed.c
14
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
15
}
16
17
/**
18
- * Commit the current L2 table to the cache
19
+ * Update L1 table with new L2 table offset and write it out
20
*/
21
-static void qed_commit_l2_update(void *opaque, int ret)
22
+static void qed_aio_write_l1_update(void *opaque, int ret)
23
{
24
QEDAIOCB *acb = opaque;
25
BDRVQEDState *s = acb_to_s(acb);
26
CachedL2Table *l2_table = acb->request.l2_table;
27
uint64_t l2_offset = l2_table->offset;
28
+ int index;
29
+
30
+ if (ret) {
31
+ qed_aio_complete(acb, ret);
32
+ return;
33
+ }
34
35
+ index = qed_l1_index(s, acb->cur_pos);
36
+ s->l1_table->offsets[index] = l2_table->offset;
37
+
38
+ ret = qed_write_l1_table(s, index, 1);
39
+
40
+ /* Commit the current L2 table to the cache */
41
qed_commit_l2_cache_entry(&s->l2_cache, l2_table);
42
43
/* This is guaranteed to succeed because we just committed the entry to the
44
@@ -XXX,XX +XXX,XX @@ static void qed_commit_l2_update(void *opaque, int ret)
45
qed_aio_next_io(acb, ret);
46
}
47
48
-/**
49
- * Update L1 table with new L2 table offset and write it out
50
- */
51
-static void qed_aio_write_l1_update(void *opaque, int ret)
52
-{
53
- QEDAIOCB *acb = opaque;
54
- BDRVQEDState *s = acb_to_s(acb);
55
- int index;
56
-
57
- if (ret) {
58
- qed_aio_complete(acb, ret);
59
- return;
60
- }
61
-
62
- index = qed_l1_index(s, acb->cur_pos);
63
- s->l1_table->offsets[index] = acb->request.l2_table->offset;
64
-
65
- ret = qed_write_l1_table(s, index, 1);
66
- qed_commit_l2_update(acb, ret);
67
-}
68
69
/**
70
* Update L2 table with new cluster offsets and write them out
71
--
72
1.8.3.1
73
74
diff view generated by jsdifflib
Deleted patch
1
Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
2
just return an error code and let the caller handle it.
3
1
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
7
block/qed.c | 19 +++++++++----------
8
1 file changed, 9 insertions(+), 10 deletions(-)
9
10
diff --git a/block/qed.c b/block/qed.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/block/qed.c
13
+++ b/block/qed.c
14
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
15
/**
16
* Update L1 table with new L2 table offset and write it out
17
*/
18
-static void qed_aio_write_l1_update(void *opaque, int ret)
19
+static int qed_aio_write_l1_update(QEDAIOCB *acb)
20
{
21
- QEDAIOCB *acb = opaque;
22
BDRVQEDState *s = acb_to_s(acb);
23
CachedL2Table *l2_table = acb->request.l2_table;
24
uint64_t l2_offset = l2_table->offset;
25
- int index;
26
-
27
- if (ret) {
28
- qed_aio_complete(acb, ret);
29
- return;
30
- }
31
+ int index, ret;
32
33
index = qed_l1_index(s, acb->cur_pos);
34
s->l1_table->offsets[index] = l2_table->offset;
35
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_l1_update(void *opaque, int ret)
36
acb->request.l2_table = qed_find_l2_cache_entry(&s->l2_cache, l2_offset);
37
assert(acb->request.l2_table != NULL);
38
39
- qed_aio_next_io(acb, ret);
40
+ return ret;
41
}
42
43
44
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
45
if (need_alloc) {
46
/* Write out the whole new L2 table */
47
ret = qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true);
48
- qed_aio_write_l1_update(acb, ret);
49
+ if (ret) {
50
+ goto err;
51
+ }
52
+ ret = qed_aio_write_l1_update(acb);
53
+ qed_aio_next_io(acb, ret);
54
+
55
} else {
56
/* Write out only the updated part of the L2 table */
57
ret = qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters,
58
--
59
1.8.3.1
60
61
diff view generated by jsdifflib
Deleted patch
1
Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
2
just return an error code and let the caller handle it.
3
1
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
7
block/qed.c | 43 ++++++++++++++++++++++++++-----------------
8
1 file changed, 26 insertions(+), 17 deletions(-)
9
10
diff --git a/block/qed.c b/block/qed.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/block/qed.c
13
+++ b/block/qed.c
14
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_l1_update(QEDAIOCB *acb)
15
/**
16
* Update L2 table with new cluster offsets and write them out
17
*/
18
-static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
19
+static int qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset)
20
{
21
BDRVQEDState *s = acb_to_s(acb);
22
bool need_alloc = acb->find_cluster_ret == QED_CLUSTER_L1;
23
- int index;
24
-
25
- if (ret) {
26
- goto err;
27
- }
28
+ int index, ret;
29
30
if (need_alloc) {
31
qed_unref_l2_cache_entry(acb->request.l2_table);
32
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
33
/* Write out the whole new L2 table */
34
ret = qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true);
35
if (ret) {
36
- goto err;
37
+ return ret;
38
}
39
- ret = qed_aio_write_l1_update(acb);
40
- qed_aio_next_io(acb, ret);
41
-
42
+ return qed_aio_write_l1_update(acb);
43
} else {
44
/* Write out only the updated part of the L2 table */
45
ret = qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters,
46
false);
47
- qed_aio_next_io(acb, ret);
48
+ if (ret) {
49
+ return ret;
50
+ }
51
}
52
- return;
53
-
54
-err:
55
- qed_aio_complete(acb, ret);
56
+ return 0;
57
}
58
59
/**
60
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_main(void *opaque, int ret)
61
*/
62
ret = bdrv_flush(s->bs->file->bs);
63
}
64
- qed_aio_write_l2_update(acb, ret, acb->cur_cluster);
65
+ if (ret) {
66
+ goto err;
67
+ }
68
+ ret = qed_aio_write_l2_update(acb, acb->cur_cluster);
69
+ if (ret) {
70
+ goto err;
71
+ }
72
+ qed_aio_next_io(acb, 0);
73
}
74
+ return;
75
+
76
+err:
77
+ qed_aio_complete(acb, ret);
78
}
79
80
/**
81
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_zero_cluster(void *opaque, int ret)
82
return;
83
}
84
85
- qed_aio_write_l2_update(acb, 0, 1);
86
+ ret = qed_aio_write_l2_update(acb, 1);
87
+ if (ret < 0) {
88
+ qed_aio_complete(acb, ret);
89
+ return;
90
+ }
91
+ qed_aio_next_io(acb, 0);
92
}
93
94
/**
95
--
96
1.8.3.1
97
98
diff view generated by jsdifflib
Deleted patch
1
Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
2
just return an error code and let the caller handle it.
3
1
4
While refactoring qed_aio_write_alloc() to accomodate the change,
5
qed_aio_write_zero_cluster() ended up with a single line, so I chose to
6
inline that line and remove the function completely.
7
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
11
block/qed.c | 58 +++++++++++++++++++++-------------------------------------
12
1 file changed, 21 insertions(+), 37 deletions(-)
13
14
diff --git a/block/qed.c b/block/qed.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block/qed.c
17
+++ b/block/qed.c
18
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_main(QEDAIOCB *acb)
19
/**
20
* Populate untouched regions of new data cluster
21
*/
22
-static void qed_aio_write_cow(void *opaque, int ret)
23
+static int qed_aio_write_cow(QEDAIOCB *acb)
24
{
25
- QEDAIOCB *acb = opaque;
26
BDRVQEDState *s = acb_to_s(acb);
27
uint64_t start, len, offset;
28
+ int ret;
29
30
/* Populate front untouched region of new data cluster */
31
start = qed_start_of_cluster(s, acb->cur_pos);
32
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_cow(void *opaque, int ret)
33
34
trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster);
35
ret = qed_copy_from_backing_file(s, start, len, acb->cur_cluster);
36
- if (ret) {
37
- qed_aio_complete(acb, ret);
38
- return;
39
+ if (ret < 0) {
40
+ return ret;
41
}
42
43
/* Populate back untouched region of new data cluster */
44
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_cow(void *opaque, int ret)
45
46
trace_qed_aio_write_postfill(s, acb, start, len, offset);
47
ret = qed_copy_from_backing_file(s, start, len, offset);
48
- if (ret) {
49
- qed_aio_complete(acb, ret);
50
- return;
51
- }
52
-
53
- ret = qed_aio_write_main(acb);
54
if (ret < 0) {
55
- qed_aio_complete(acb, ret);
56
- return;
57
+ return ret;
58
}
59
- qed_aio_next_io(acb, 0);
60
+
61
+ return qed_aio_write_main(acb);
62
}
63
64
/**
65
@@ -XXX,XX +XXX,XX @@ static bool qed_should_set_need_check(BDRVQEDState *s)
66
return !(s->header.features & QED_F_NEED_CHECK);
67
}
68
69
-static void qed_aio_write_zero_cluster(void *opaque, int ret)
70
-{
71
- QEDAIOCB *acb = opaque;
72
-
73
- if (ret) {
74
- qed_aio_complete(acb, ret);
75
- return;
76
- }
77
-
78
- ret = qed_aio_write_l2_update(acb, 1);
79
- if (ret < 0) {
80
- qed_aio_complete(acb, ret);
81
- return;
82
- }
83
- qed_aio_next_io(acb, 0);
84
-}
85
-
86
/**
87
* Write new data cluster
88
*
89
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_zero_cluster(void *opaque, int ret)
90
static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
91
{
92
BDRVQEDState *s = acb_to_s(acb);
93
- BlockCompletionFunc *cb;
94
int ret;
95
96
/* Cancel timer when the first allocating request comes in */
97
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
98
qed_aio_start_io(acb);
99
return;
100
}
101
-
102
- cb = qed_aio_write_zero_cluster;
103
} else {
104
- cb = qed_aio_write_cow;
105
acb->cur_cluster = qed_alloc_clusters(s, acb->cur_nclusters);
106
}
107
108
if (qed_should_set_need_check(s)) {
109
s->header.features |= QED_F_NEED_CHECK;
110
ret = qed_write_header(s);
111
- cb(acb, ret);
112
+ if (ret < 0) {
113
+ qed_aio_complete(acb, ret);
114
+ return;
115
+ }
116
+ }
117
+
118
+ if (acb->flags & QED_AIOCB_ZERO) {
119
+ ret = qed_aio_write_l2_update(acb, 1);
120
} else {
121
- cb(acb, 0);
122
+ ret = qed_aio_write_cow(acb);
123
}
124
+ if (ret < 0) {
125
+ qed_aio_complete(acb, ret);
126
+ return;
127
+ }
128
+ qed_aio_next_io(acb, 0);
129
}
130
131
/**
132
--
133
1.8.3.1
134
135
diff view generated by jsdifflib
Deleted patch
1
Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
2
just return an error code and let the caller handle it.
3
1
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
7
block/qed.c | 43 ++++++++++++++++++++-----------------------
8
1 file changed, 20 insertions(+), 23 deletions(-)
9
10
diff --git a/block/qed.c b/block/qed.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/block/qed.c
13
+++ b/block/qed.c
14
@@ -XXX,XX +XXX,XX @@ static bool qed_should_set_need_check(BDRVQEDState *s)
15
*
16
* This path is taken when writing to previously unallocated clusters.
17
*/
18
-static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
19
+static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
20
{
21
BDRVQEDState *s = acb_to_s(acb);
22
int ret;
23
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
24
}
25
if (acb != QSIMPLEQ_FIRST(&s->allocating_write_reqs) ||
26
s->allocating_write_reqs_plugged) {
27
- return; /* wait for existing request to finish */
28
+ return -EINPROGRESS; /* wait for existing request to finish */
29
}
30
31
acb->cur_nclusters = qed_bytes_to_clusters(s,
32
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
33
if (acb->flags & QED_AIOCB_ZERO) {
34
/* Skip ahead if the clusters are already zero */
35
if (acb->find_cluster_ret == QED_CLUSTER_ZERO) {
36
- qed_aio_start_io(acb);
37
- return;
38
+ return 0;
39
}
40
} else {
41
acb->cur_cluster = qed_alloc_clusters(s, acb->cur_nclusters);
42
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
43
s->header.features |= QED_F_NEED_CHECK;
44
ret = qed_write_header(s);
45
if (ret < 0) {
46
- qed_aio_complete(acb, ret);
47
- return;
48
+ return ret;
49
}
50
}
51
52
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
53
ret = qed_aio_write_cow(acb);
54
}
55
if (ret < 0) {
56
- qed_aio_complete(acb, ret);
57
- return;
58
+ return ret;
59
}
60
- qed_aio_next_io(acb, 0);
61
+ return 0;
62
}
63
64
/**
65
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
66
*
67
* This path is taken when writing to already allocated clusters.
68
*/
69
-static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
70
+static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
71
{
72
- int ret;
73
-
74
/* Allocate buffer for zero writes */
75
if (acb->flags & QED_AIOCB_ZERO) {
76
struct iovec *iov = acb->qiov->iov;
77
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
78
if (!iov->iov_base) {
79
iov->iov_base = qemu_try_blockalign(acb->common.bs, iov->iov_len);
80
if (iov->iov_base == NULL) {
81
- qed_aio_complete(acb, -ENOMEM);
82
- return;
83
+ return -ENOMEM;
84
}
85
memset(iov->iov_base, 0, iov->iov_len);
86
}
87
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
88
qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len);
89
90
/* Do the actual write */
91
- ret = qed_aio_write_main(acb);
92
- if (ret < 0) {
93
- qed_aio_complete(acb, ret);
94
- return;
95
- }
96
- qed_aio_next_io(acb, 0);
97
+ return qed_aio_write_main(acb);
98
}
99
100
/**
101
@@ -XXX,XX +XXX,XX @@ static void qed_aio_write_data(void *opaque, int ret,
102
103
switch (ret) {
104
case QED_CLUSTER_FOUND:
105
- qed_aio_write_inplace(acb, offset, len);
106
+ ret = qed_aio_write_inplace(acb, offset, len);
107
break;
108
109
case QED_CLUSTER_L2:
110
case QED_CLUSTER_L1:
111
case QED_CLUSTER_ZERO:
112
- qed_aio_write_alloc(acb, len);
113
+ ret = qed_aio_write_alloc(acb, len);
114
break;
115
116
default:
117
- qed_aio_complete(acb, ret);
118
+ assert(ret < 0);
119
break;
120
}
121
+
122
+ if (ret < 0) {
123
+ if (ret != -EINPROGRESS) {
124
+ qed_aio_complete(acb, ret);
125
+ }
126
+ return;
127
+ }
128
+ qed_aio_next_io(acb, 0);
129
}
130
131
/**
132
--
133
1.8.3.1
134
135
diff view generated by jsdifflib
Deleted patch
1
All callers pass ret = 0, so we can just remove it.
2
1
3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
5
---
6
block/qed.c | 17 ++++++-----------
7
1 file changed, 6 insertions(+), 11 deletions(-)
8
9
diff --git a/block/qed.c b/block/qed.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/block/qed.c
12
+++ b/block/qed.c
13
@@ -XXX,XX +XXX,XX @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s)
14
return l2_table;
15
}
16
17
-static void qed_aio_next_io(QEDAIOCB *acb, int ret);
18
+static void qed_aio_next_io(QEDAIOCB *acb);
19
20
static void qed_aio_start_io(QEDAIOCB *acb)
21
{
22
- qed_aio_next_io(acb, 0);
23
+ qed_aio_next_io(acb);
24
}
25
26
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
27
@@ -XXX,XX +XXX,XX @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
28
/**
29
* Begin next I/O or complete the request
30
*/
31
-static void qed_aio_next_io(QEDAIOCB *acb, int ret)
32
+static void qed_aio_next_io(QEDAIOCB *acb)
33
{
34
BDRVQEDState *s = acb_to_s(acb);
35
uint64_t offset;
36
size_t len;
37
+ int ret;
38
39
- trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size);
40
+ trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size);
41
42
if (acb->backing_qiov) {
43
qemu_iovec_destroy(acb->backing_qiov);
44
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
45
acb->backing_qiov = NULL;
46
}
47
48
- /* Handle I/O error */
49
- if (ret) {
50
- qed_aio_complete(acb, ret);
51
- return;
52
- }
53
-
54
acb->qiov_offset += acb->cur_qiov.size;
55
acb->cur_pos += acb->cur_qiov.size;
56
qemu_iovec_reset(&acb->cur_qiov);
57
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret)
58
}
59
return;
60
}
61
- qed_aio_next_io(acb, 0);
62
+ qed_aio_next_io(acb);
63
}
64
65
static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
66
--
67
1.8.3.1
68
69
diff view generated by jsdifflib
Deleted patch
1
Most of the qed code is now synchronous and matches the coroutine model.
2
One notable exception is the serialisation between requests which can
3
still schedule a callback. Before we can replace this with coroutine
4
locks, let's convert the driver's external interfaces to the coroutine
5
versions.
6
1
7
We need to be careful to handle both requests that call the completion
8
callback directly from the calling coroutine (i.e. fully synchronous
9
code) and requests that involve some callback, so that we need to yield
10
and wait for the completion callback coming from outside the coroutine.
11
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Reviewed-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
15
---
16
block/qed.c | 97 ++++++++++++++++++++++++++-----------------------------------
17
1 file changed, 42 insertions(+), 55 deletions(-)
18
19
diff --git a/block/qed.c b/block/qed.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/block/qed.c
22
+++ b/block/qed.c
23
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb)
24
}
25
}
26
27
-static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
28
- int64_t sector_num,
29
- QEMUIOVector *qiov, int nb_sectors,
30
- BlockCompletionFunc *cb,
31
- void *opaque, int flags)
32
+typedef struct QEDRequestCo {
33
+ Coroutine *co;
34
+ bool done;
35
+ int ret;
36
+} QEDRequestCo;
37
+
38
+static void qed_co_request_cb(void *opaque, int ret)
39
{
40
- QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, cb, opaque);
41
+ QEDRequestCo *co = opaque;
42
43
- trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors,
44
- opaque, flags);
45
+ co->done = true;
46
+ co->ret = ret;
47
+ qemu_coroutine_enter_if_inactive(co->co);
48
+}
49
+
50
+static int coroutine_fn qed_co_request(BlockDriverState *bs, int64_t sector_num,
51
+ QEMUIOVector *qiov, int nb_sectors,
52
+ int flags)
53
+{
54
+ QEDRequestCo co = {
55
+ .co = qemu_coroutine_self(),
56
+ .done = false,
57
+ };
58
+ QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb, &co);
59
+
60
+ trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flags);
61
62
acb->flags = flags;
63
acb->qiov = qiov;
64
@@ -XXX,XX +XXX,XX @@ static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
65
66
/* Start request */
67
qed_aio_start_io(acb);
68
- return &acb->common;
69
-}
70
71
-static BlockAIOCB *bdrv_qed_aio_readv(BlockDriverState *bs,
72
- int64_t sector_num,
73
- QEMUIOVector *qiov, int nb_sectors,
74
- BlockCompletionFunc *cb,
75
- void *opaque)
76
-{
77
- return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0);
78
+ if (!co.done) {
79
+ qemu_coroutine_yield();
80
+ }
81
+
82
+ return co.ret;
83
}
84
85
-static BlockAIOCB *bdrv_qed_aio_writev(BlockDriverState *bs,
86
- int64_t sector_num,
87
- QEMUIOVector *qiov, int nb_sectors,
88
- BlockCompletionFunc *cb,
89
- void *opaque)
90
+static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs,
91
+ int64_t sector_num, int nb_sectors,
92
+ QEMUIOVector *qiov)
93
{
94
- return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb,
95
- opaque, QED_AIOCB_WRITE);
96
+ return qed_co_request(bs, sector_num, qiov, nb_sectors, 0);
97
}
98
99
-typedef struct {
100
- Coroutine *co;
101
- int ret;
102
- bool done;
103
-} QEDWriteZeroesCB;
104
-
105
-static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret)
106
+static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs,
107
+ int64_t sector_num, int nb_sectors,
108
+ QEMUIOVector *qiov)
109
{
110
- QEDWriteZeroesCB *cb = opaque;
111
-
112
- cb->done = true;
113
- cb->ret = ret;
114
- if (cb->co) {
115
- aio_co_wake(cb->co);
116
- }
117
+ return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRITE);
118
}
119
120
static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
121
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
122
int count,
123
BdrvRequestFlags flags)
124
{
125
- BlockAIOCB *blockacb;
126
BDRVQEDState *s = bs->opaque;
127
- QEDWriteZeroesCB cb = { .done = false };
128
QEMUIOVector qiov;
129
struct iovec iov;
130
131
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
132
iov.iov_len = count;
133
134
qemu_iovec_init_external(&qiov, &iov, 1);
135
- blockacb = qed_aio_setup(bs, offset >> BDRV_SECTOR_BITS, &qiov,
136
- count >> BDRV_SECTOR_BITS,
137
- qed_co_pwrite_zeroes_cb, &cb,
138
- QED_AIOCB_WRITE | QED_AIOCB_ZERO);
139
- if (!blockacb) {
140
- return -EIO;
141
- }
142
- if (!cb.done) {
143
- cb.co = qemu_coroutine_self();
144
- qemu_coroutine_yield();
145
- }
146
- assert(cb.done);
147
- return cb.ret;
148
+ return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov,
149
+ count >> BDRV_SECTOR_BITS,
150
+ QED_AIOCB_WRITE | QED_AIOCB_ZERO);
151
}
152
153
static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
154
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qed = {
155
.bdrv_create = bdrv_qed_create,
156
.bdrv_has_zero_init = bdrv_has_zero_init_1,
157
.bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
158
- .bdrv_aio_readv = bdrv_qed_aio_readv,
159
- .bdrv_aio_writev = bdrv_qed_aio_writev,
160
+ .bdrv_co_readv = bdrv_qed_co_readv,
161
+ .bdrv_co_writev = bdrv_qed_co_writev,
162
.bdrv_co_pwrite_zeroes = bdrv_qed_co_pwrite_zeroes,
163
.bdrv_truncate = bdrv_qed_truncate,
164
.bdrv_getlength = bdrv_qed_getlength,
165
--
166
1.8.3.1
167
168
diff view generated by jsdifflib
Deleted patch
1
Now that we're running in coroutine context, the ad-hoc serialisation
2
code (which drops a request that has to wait out of coroutine context)
3
can be replaced by a CoQueue.
4
1
5
This means that when we resume a serialised request, it is running in
6
coroutine context again and its I/O isn't blocking any more.
7
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
11
block/qed.c | 49 +++++++++++++++++--------------------------------
12
block/qed.h | 3 ++-
13
2 files changed, 19 insertions(+), 33 deletions(-)
14
15
diff --git a/block/qed.c b/block/qed.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/qed.c
18
+++ b/block/qed.c
19
@@ -XXX,XX +XXX,XX @@ static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
20
21
static void qed_unplug_allocating_write_reqs(BDRVQEDState *s)
22
{
23
- QEDAIOCB *acb;
24
-
25
assert(s->allocating_write_reqs_plugged);
26
27
s->allocating_write_reqs_plugged = false;
28
-
29
- acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
30
- if (acb) {
31
- qed_aio_start_io(acb);
32
- }
33
+ qemu_co_enter_next(&s->allocating_write_reqs);
34
}
35
36
static void qed_clear_need_check(void *opaque, int ret)
37
@@ -XXX,XX +XXX,XX @@ static void qed_need_check_timer_cb(void *opaque)
38
BDRVQEDState *s = opaque;
39
40
/* The timer should only fire when allocating writes have drained */
41
- assert(!QSIMPLEQ_FIRST(&s->allocating_write_reqs));
42
+ assert(!s->allocating_acb);
43
44
trace_qed_need_check_timer_cb(s);
45
46
@@ -XXX,XX +XXX,XX @@ static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags,
47
int ret;
48
49
s->bs = bs;
50
- QSIMPLEQ_INIT(&s->allocating_write_reqs);
51
+ qemu_co_queue_init(&s->allocating_write_reqs);
52
53
ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header));
54
if (ret < 0) {
55
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete_bh(void *opaque)
56
qed_release(s);
57
}
58
59
-static void qed_resume_alloc_bh(void *opaque)
60
-{
61
- qed_aio_start_io(opaque);
62
-}
63
-
64
static void qed_aio_complete(QEDAIOCB *acb, int ret)
65
{
66
BDRVQEDState *s = acb_to_s(acb);
67
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
68
* next request in the queue. This ensures that we don't cycle through
69
* requests multiple times but rather finish one at a time completely.
70
*/
71
- if (acb == QSIMPLEQ_FIRST(&s->allocating_write_reqs)) {
72
- QEDAIOCB *next_acb;
73
- QSIMPLEQ_REMOVE_HEAD(&s->allocating_write_reqs, next);
74
- next_acb = QSIMPLEQ_FIRST(&s->allocating_write_reqs);
75
- if (next_acb) {
76
- aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
77
- qed_resume_alloc_bh, next_acb);
78
+ if (acb == s->allocating_acb) {
79
+ s->allocating_acb = NULL;
80
+ if (!qemu_co_queue_empty(&s->allocating_write_reqs)) {
81
+ qemu_co_enter_next(&s->allocating_write_reqs);
82
} else if (s->header.features & QED_F_NEED_CHECK) {
83
qed_start_need_check_timer(s);
84
}
85
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
86
int ret;
87
88
/* Cancel timer when the first allocating request comes in */
89
- if (QSIMPLEQ_EMPTY(&s->allocating_write_reqs)) {
90
+ if (s->allocating_acb == NULL) {
91
qed_cancel_need_check_timer(s);
92
}
93
94
/* Freeze this request if another allocating write is in progress */
95
- if (acb != QSIMPLEQ_FIRST(&s->allocating_write_reqs)) {
96
- QSIMPLEQ_INSERT_TAIL(&s->allocating_write_reqs, acb, next);
97
- }
98
- if (acb != QSIMPLEQ_FIRST(&s->allocating_write_reqs) ||
99
- s->allocating_write_reqs_plugged) {
100
- return -EINPROGRESS; /* wait for existing request to finish */
101
+ if (s->allocating_acb != acb || s->allocating_write_reqs_plugged) {
102
+ if (s->allocating_acb != NULL) {
103
+ qemu_co_queue_wait(&s->allocating_write_reqs, NULL);
104
+ assert(s->allocating_acb == NULL);
105
+ }
106
+ s->allocating_acb = acb;
107
+ return -EAGAIN; /* start over with looking up table entries */
108
}
109
110
acb->cur_nclusters = qed_bytes_to_clusters(s,
111
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb)
112
ret = qed_aio_read_data(acb, ret, offset, len);
113
}
114
115
- if (ret < 0) {
116
- if (ret != -EINPROGRESS) {
117
- qed_aio_complete(acb, ret);
118
- }
119
+ if (ret < 0 && ret != -EAGAIN) {
120
+ qed_aio_complete(acb, ret);
121
return;
122
}
123
}
124
diff --git a/block/qed.h b/block/qed.h
125
index XXXXXXX..XXXXXXX 100644
126
--- a/block/qed.h
127
+++ b/block/qed.h
128
@@ -XXX,XX +XXX,XX @@ typedef struct {
129
uint32_t l2_mask;
130
131
/* Allocating write request queue */
132
- QSIMPLEQ_HEAD(, QEDAIOCB) allocating_write_reqs;
133
+ QEDAIOCB *allocating_acb;
134
+ CoQueue allocating_write_reqs;
135
bool allocating_write_reqs_plugged;
136
137
/* Periodic flush and clear need check flag */
138
--
139
1.8.3.1
140
141
diff view generated by jsdifflib
1
Now that we process a request in the same coroutine from beginning to
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
end and don't drop out of it any more, we can look like a proper
3
coroutine-based driver and simply call qed_aio_next_io() and get a
4
return value from it instead of spawning an additional coroutine that
5
reenters the parent when it's done.
6
2
3
common.rc has some complicated logic to find the common.config that
4
dates back to xfstests and is completely unnecessary now. Just include
5
the contents of the file.
6
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Message-Id: <20220505094723.732116-1-pbonzini@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
10
---
10
block/qed.c | 101 +++++++++++++-----------------------------------------------
11
tests/qemu-iotests/common.config | 41 --------------------------------
11
block/qed.h | 3 +-
12
tests/qemu-iotests/common.rc | 31 ++++++++++++++----------
12
2 files changed, 22 insertions(+), 82 deletions(-)
13
2 files changed, 19 insertions(+), 53 deletions(-)
14
delete mode 100644 tests/qemu-iotests/common.config
13
15
14
diff --git a/block/qed.c b/block/qed.c
16
diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config
15
index XXXXXXX..XXXXXXX 100644
17
deleted file mode 100644
16
--- a/block/qed.c
18
index XXXXXXX..XXXXXXX
17
+++ b/block/qed.c
19
--- a/tests/qemu-iotests/common.config
20
+++ /dev/null
18
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
19
#include "qapi/qmp/qerror.h"
22
-#!/usr/bin/env bash
20
#include "sysemu/block-backend.h"
23
-#
21
24
-# Copyright (C) 2009 Red Hat, Inc.
22
-static const AIOCBInfo qed_aiocb_info = {
25
-# Copyright (c) 2000-2003,2006 Silicon Graphics, Inc. All Rights Reserved.
23
- .aiocb_size = sizeof(QEDAIOCB),
26
-#
24
-};
27
-# This program is free software; you can redistribute it and/or
28
-# modify it under the terms of the GNU General Public License as
29
-# published by the Free Software Foundation.
30
-#
31
-# This program is distributed in the hope that it would be useful,
32
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
33
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
-# GNU General Public License for more details.
35
-#
36
-# You should have received a copy of the GNU General Public License
37
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
38
-#
39
-# all tests should use a common language setting to prevent golden
40
-# output mismatches.
41
-export LANG=C
25
-
42
-
26
static int bdrv_qed_probe(const uint8_t *buf, int buf_size,
43
-PATH=".:$PATH"
27
const char *filename)
28
{
29
@@ -XXX,XX +XXX,XX @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s)
30
return l2_table;
31
}
32
33
-static void qed_aio_next_io(QEDAIOCB *acb);
34
-
44
-
35
-static void qed_aio_start_io(QEDAIOCB *acb)
45
-HOSTOS=$(uname -s)
46
-arch=$(uname -m)
47
-[[ "$arch" =~ "ppc64" ]] && qemu_arch=ppc64 || qemu_arch="$arch"
48
-
49
-# make sure we have a standard umask
50
-umask 022
51
-
52
-_optstr_add()
36
-{
53
-{
37
- qed_aio_next_io(acb);
54
- if [ -n "$1" ]; then
55
- echo "$1,$2"
56
- else
57
- echo "$2"
58
- fi
38
-}
59
-}
39
-
60
-
40
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
61
-# make sure this script returns success
62
-true
63
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
64
index XXXXXXX..XXXXXXX 100644
65
--- a/tests/qemu-iotests/common.rc
66
+++ b/tests/qemu-iotests/common.rc
67
@@ -XXX,XX +XXX,XX @@
68
# along with this program. If not, see <http://www.gnu.org/licenses/>.
69
#
70
71
+export LANG=C
72
+
73
+PATH=".:$PATH"
74
+
75
+HOSTOS=$(uname -s)
76
+arch=$(uname -m)
77
+[[ "$arch" =~ "ppc64" ]] && qemu_arch=ppc64 || qemu_arch="$arch"
78
+
79
+# make sure we have a standard umask
80
+umask 022
81
+
82
# bail out, setting up .notrun file
83
_notrun()
41
{
84
{
42
assert(!s->allocating_write_reqs_plugged);
85
@@ -XXX,XX +XXX,XX @@ peek_file_raw()
43
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,
86
dd if="$1" bs=1 skip="$2" count="$3" status=none
44
45
static BDRVQEDState *acb_to_s(QEDAIOCB *acb)
46
{
47
- return acb->common.bs->opaque;
48
+ return acb->bs->opaque;
49
}
87
}
50
88
51
/**
89
-config=common.config
52
@@ -XXX,XX +XXX,XX @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index,
90
-test -f $config || config=../common.config
53
}
91
-if ! test -f $config
54
}
92
-then
55
93
- echo "$0: failed to find common.config"
56
-static void qed_aio_complete_bh(void *opaque)
94
- exit 1
57
-{
95
-fi
58
- QEDAIOCB *acb = opaque;
96
-if ! . $config
59
- BDRVQEDState *s = acb_to_s(acb);
97
- then
60
- BlockCompletionFunc *cb = acb->common.cb;
98
- echo "$0: failed to source common.config"
61
- void *user_opaque = acb->common.opaque;
99
- exit 1
62
- int ret = acb->bh_ret;
100
-fi
63
-
101
+_optstr_add()
64
- qemu_aio_unref(acb);
102
+{
65
-
103
+ if [ -n "$1" ]; then
66
- /* Invoke callback */
104
+ echo "$1,$2"
67
- qed_acquire(s);
105
+ else
68
- cb(user_opaque, ret);
106
+ echo "$2"
69
- qed_release(s);
107
+ fi
70
-}
108
+}
71
-
109
72
-static void qed_aio_complete(QEDAIOCB *acb, int ret)
110
# Set the variables to the empty string to turn Valgrind off
73
+static void qed_aio_complete(QEDAIOCB *acb)
111
# for specific processes, e.g.
74
{
75
BDRVQEDState *s = acb_to_s(acb);
76
77
- trace_qed_aio_complete(s, acb, ret);
78
-
79
/* Free resources */
80
qemu_iovec_destroy(&acb->cur_qiov);
81
qed_unref_l2_cache_entry(acb->request.l2_table);
82
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete(QEDAIOCB *acb, int ret)
83
acb->qiov->iov[0].iov_base = NULL;
84
}
85
86
- /* Arrange for a bh to invoke the completion function */
87
- acb->bh_ret = ret;
88
- aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
89
- qed_aio_complete_bh, acb);
90
-
91
/* Start next allocating write request waiting behind this one. Note that
92
* requests enqueue themselves when they first hit an unallocated cluster
93
* but they wait until the entire request is finished before waking up the
94
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
95
struct iovec *iov = acb->qiov->iov;
96
97
if (!iov->iov_base) {
98
- iov->iov_base = qemu_try_blockalign(acb->common.bs, iov->iov_len);
99
+ iov->iov_base = qemu_try_blockalign(acb->bs, iov->iov_len);
100
if (iov->iov_base == NULL) {
101
return -ENOMEM;
102
}
103
@@ -XXX,XX +XXX,XX @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
104
{
105
QEDAIOCB *acb = opaque;
106
BDRVQEDState *s = acb_to_s(acb);
107
- BlockDriverState *bs = acb->common.bs;
108
+ BlockDriverState *bs = acb->bs;
109
110
/* Adjust offset into cluster */
111
offset += qed_offset_into_cluster(s, acb->cur_pos);
112
@@ -XXX,XX +XXX,XX @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
113
/**
114
* Begin next I/O or complete the request
115
*/
116
-static void qed_aio_next_io(QEDAIOCB *acb)
117
+static int qed_aio_next_io(QEDAIOCB *acb)
118
{
119
BDRVQEDState *s = acb_to_s(acb);
120
uint64_t offset;
121
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb)
122
123
/* Complete request */
124
if (acb->cur_pos >= acb->end_pos) {
125
- qed_aio_complete(acb, 0);
126
- return;
127
+ ret = 0;
128
+ break;
129
}
130
131
/* Find next cluster and start I/O */
132
len = acb->end_pos - acb->cur_pos;
133
ret = qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset);
134
if (ret < 0) {
135
- qed_aio_complete(acb, ret);
136
- return;
137
+ break;
138
}
139
140
if (acb->flags & QED_AIOCB_WRITE) {
141
@@ -XXX,XX +XXX,XX @@ static void qed_aio_next_io(QEDAIOCB *acb)
142
}
143
144
if (ret < 0 && ret != -EAGAIN) {
145
- qed_aio_complete(acb, ret);
146
- return;
147
+ break;
148
}
149
}
150
-}
151
152
-typedef struct QEDRequestCo {
153
- Coroutine *co;
154
- bool done;
155
- int ret;
156
-} QEDRequestCo;
157
-
158
-static void qed_co_request_cb(void *opaque, int ret)
159
-{
160
- QEDRequestCo *co = opaque;
161
-
162
- co->done = true;
163
- co->ret = ret;
164
- qemu_coroutine_enter_if_inactive(co->co);
165
+ trace_qed_aio_complete(s, acb, ret);
166
+ qed_aio_complete(acb);
167
+ return ret;
168
}
169
170
static int coroutine_fn qed_co_request(BlockDriverState *bs, int64_t sector_num,
171
QEMUIOVector *qiov, int nb_sectors,
172
int flags)
173
{
174
- QEDRequestCo co = {
175
- .co = qemu_coroutine_self(),
176
- .done = false,
177
+ QEDAIOCB acb = {
178
+ .bs = bs,
179
+ .cur_pos = (uint64_t) sector_num * BDRV_SECTOR_SIZE,
180
+ .end_pos = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE,
181
+ .qiov = qiov,
182
+ .flags = flags,
183
};
184
- QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb, &co);
185
-
186
- trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flags);
187
+ qemu_iovec_init(&acb.cur_qiov, qiov->niov);
188
189
- acb->flags = flags;
190
- acb->qiov = qiov;
191
- acb->qiov_offset = 0;
192
- acb->cur_pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE;
193
- acb->end_pos = acb->cur_pos + nb_sectors * BDRV_SECTOR_SIZE;
194
- acb->backing_qiov = NULL;
195
- acb->request.l2_table = NULL;
196
- qemu_iovec_init(&acb->cur_qiov, qiov->niov);
197
+ trace_qed_aio_setup(bs->opaque, &acb, sector_num, nb_sectors, NULL, flags);
198
199
/* Start request */
200
- qed_aio_start_io(acb);
201
-
202
- if (!co.done) {
203
- qemu_coroutine_yield();
204
- }
205
-
206
- return co.ret;
207
+ return qed_aio_next_io(&acb);
208
}
209
210
static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs,
211
diff --git a/block/qed.h b/block/qed.h
212
index XXXXXXX..XXXXXXX 100644
213
--- a/block/qed.h
214
+++ b/block/qed.h
215
@@ -XXX,XX +XXX,XX @@ enum {
216
};
217
218
typedef struct QEDAIOCB {
219
- BlockAIOCB common;
220
- int bh_ret; /* final return status for completion bh */
221
+ BlockDriverState *bs;
222
QSIMPLEQ_ENTRY(QEDAIOCB) next; /* next request */
223
int flags; /* QED_AIOCB_* bits ORed together */
224
uint64_t end_pos; /* request end on block device, in bytes */
225
--
112
--
226
1.8.3.1
113
2.35.3
227
228
diff view generated by jsdifflib
Deleted patch
1
This fixes the last place where we degraded from AIO to actual blocking
2
synchronous I/O requests. Putting it into a coroutine means that instead
3
of blocking, the coroutine simply yields while doing I/O.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
---
8
block/qed.c | 33 +++++++++++++++++----------------
9
1 file changed, 17 insertions(+), 16 deletions(-)
10
11
diff --git a/block/qed.c b/block/qed.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/block/qed.c
14
+++ b/block/qed.c
15
@@ -XXX,XX +XXX,XX @@ static void qed_unplug_allocating_write_reqs(BDRVQEDState *s)
16
qemu_co_enter_next(&s->allocating_write_reqs);
17
}
18
19
-static void qed_clear_need_check(void *opaque, int ret)
20
+static void qed_need_check_timer_entry(void *opaque)
21
{
22
BDRVQEDState *s = opaque;
23
+ int ret;
24
25
- if (ret) {
26
+ /* The timer should only fire when allocating writes have drained */
27
+ assert(!s->allocating_acb);
28
+
29
+ trace_qed_need_check_timer_cb(s);
30
+
31
+ qed_acquire(s);
32
+ qed_plug_allocating_write_reqs(s);
33
+
34
+ /* Ensure writes are on disk before clearing flag */
35
+ ret = bdrv_co_flush(s->bs->file->bs);
36
+ qed_release(s);
37
+ if (ret < 0) {
38
qed_unplug_allocating_write_reqs(s);
39
return;
40
}
41
@@ -XXX,XX +XXX,XX @@ static void qed_clear_need_check(void *opaque, int ret)
42
43
qed_unplug_allocating_write_reqs(s);
44
45
- ret = bdrv_flush(s->bs);
46
+ ret = bdrv_co_flush(s->bs);
47
(void) ret;
48
}
49
50
static void qed_need_check_timer_cb(void *opaque)
51
{
52
- BDRVQEDState *s = opaque;
53
-
54
- /* The timer should only fire when allocating writes have drained */
55
- assert(!s->allocating_acb);
56
-
57
- trace_qed_need_check_timer_cb(s);
58
-
59
- qed_acquire(s);
60
- qed_plug_allocating_write_reqs(s);
61
-
62
- /* Ensure writes are on disk before clearing flag */
63
- bdrv_aio_flush(s->bs->file->bs, qed_clear_need_check, s);
64
- qed_release(s);
65
+ Coroutine *co = qemu_coroutine_create(qed_need_check_timer_entry, opaque);
66
+ qemu_coroutine_enter(co);
67
}
68
69
void qed_acquire(BDRVQEDState *s)
70
--
71
1.8.3.1
72
73
diff view generated by jsdifflib
Deleted patch
1
Now that we stay in coroutine context for the whole request when doing
2
reads or writes, we can add coroutine_fn annotations to many functions
3
that can do I/O or yield directly.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
---
8
block/qed-cluster.c | 5 +++--
9
block/qed.c | 44 ++++++++++++++++++++++++--------------------
10
block/qed.h | 5 +++--
11
3 files changed, 30 insertions(+), 24 deletions(-)
12
13
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block/qed-cluster.c
16
+++ b/block/qed-cluster.c
17
@@ -XXX,XX +XXX,XX @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
18
* On failure QED_CLUSTER_L2 or QED_CLUSTER_L1 is returned for missing L2 or L1
19
* table offset, respectively. len is number of contiguous unallocated bytes.
20
*/
21
-int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
22
- size_t *len, uint64_t *img_offset)
23
+int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request,
24
+ uint64_t pos, size_t *len,
25
+ uint64_t *img_offset)
26
{
27
uint64_t l2_offset;
28
uint64_t offset = 0;
29
diff --git a/block/qed.c b/block/qed.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/block/qed.c
32
+++ b/block/qed.c
33
@@ -XXX,XX +XXX,XX @@ int qed_write_header_sync(BDRVQEDState *s)
34
* This function only updates known header fields in-place and does not affect
35
* extra data after the QED header.
36
*/
37
-static int qed_write_header(BDRVQEDState *s)
38
+static int coroutine_fn qed_write_header(BDRVQEDState *s)
39
{
40
/* We must write full sectors for O_DIRECT but cannot necessarily generate
41
* the data following the header if an unrecognized compat feature is
42
@@ -XXX,XX +XXX,XX @@ static void qed_unplug_allocating_write_reqs(BDRVQEDState *s)
43
qemu_co_enter_next(&s->allocating_write_reqs);
44
}
45
46
-static void qed_need_check_timer_entry(void *opaque)
47
+static void coroutine_fn qed_need_check_timer_entry(void *opaque)
48
{
49
BDRVQEDState *s = opaque;
50
int ret;
51
@@ -XXX,XX +XXX,XX @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb)
52
* This function reads qiov->size bytes starting at pos from the backing file.
53
* If there is no backing file then zeroes are read.
54
*/
55
-static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
56
- QEMUIOVector *qiov,
57
- QEMUIOVector **backing_qiov)
58
+static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
59
+ QEMUIOVector *qiov,
60
+ QEMUIOVector **backing_qiov)
61
{
62
uint64_t backing_length = 0;
63
size_t size;
64
@@ -XXX,XX +XXX,XX @@ static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
65
* @len: Number of bytes
66
* @offset: Byte offset in image file
67
*/
68
-static int qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos,
69
- uint64_t len, uint64_t offset)
70
+static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
71
+ uint64_t pos, uint64_t len,
72
+ uint64_t offset)
73
{
74
QEMUIOVector qiov;
75
QEMUIOVector *backing_qiov = NULL;
76
@@ -XXX,XX +XXX,XX @@ out:
77
* The cluster offset may be an allocated byte offset in the image file, the
78
* zero cluster marker, or the unallocated cluster marker.
79
*/
80
-static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index,
81
- unsigned int n, uint64_t cluster)
82
+static void coroutine_fn qed_update_l2_table(BDRVQEDState *s, QEDTable *table,
83
+ int index, unsigned int n,
84
+ uint64_t cluster)
85
{
86
int i;
87
for (i = index; i < index + n; i++) {
88
@@ -XXX,XX +XXX,XX @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index,
89
}
90
}
91
92
-static void qed_aio_complete(QEDAIOCB *acb)
93
+static void coroutine_fn qed_aio_complete(QEDAIOCB *acb)
94
{
95
BDRVQEDState *s = acb_to_s(acb);
96
97
@@ -XXX,XX +XXX,XX @@ static void qed_aio_complete(QEDAIOCB *acb)
98
/**
99
* Update L1 table with new L2 table offset and write it out
100
*/
101
-static int qed_aio_write_l1_update(QEDAIOCB *acb)
102
+static int coroutine_fn qed_aio_write_l1_update(QEDAIOCB *acb)
103
{
104
BDRVQEDState *s = acb_to_s(acb);
105
CachedL2Table *l2_table = acb->request.l2_table;
106
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_l1_update(QEDAIOCB *acb)
107
/**
108
* Update L2 table with new cluster offsets and write them out
109
*/
110
-static int qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset)
111
+static int coroutine_fn qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset)
112
{
113
BDRVQEDState *s = acb_to_s(acb);
114
bool need_alloc = acb->find_cluster_ret == QED_CLUSTER_L1;
115
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset)
116
/**
117
* Write data to the image file
118
*/
119
-static int qed_aio_write_main(QEDAIOCB *acb)
120
+static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb)
121
{
122
BDRVQEDState *s = acb_to_s(acb);
123
uint64_t offset = acb->cur_cluster +
124
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_main(QEDAIOCB *acb)
125
/**
126
* Populate untouched regions of new data cluster
127
*/
128
-static int qed_aio_write_cow(QEDAIOCB *acb)
129
+static int coroutine_fn qed_aio_write_cow(QEDAIOCB *acb)
130
{
131
BDRVQEDState *s = acb_to_s(acb);
132
uint64_t start, len, offset;
133
@@ -XXX,XX +XXX,XX @@ static bool qed_should_set_need_check(BDRVQEDState *s)
134
*
135
* This path is taken when writing to previously unallocated clusters.
136
*/
137
-static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
138
+static int coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
139
{
140
BDRVQEDState *s = acb_to_s(acb);
141
int ret;
142
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
143
*
144
* This path is taken when writing to already allocated clusters.
145
*/
146
-static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
147
+static int coroutine_fn qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset,
148
+ size_t len)
149
{
150
/* Allocate buffer for zero writes */
151
if (acb->flags & QED_AIOCB_ZERO) {
152
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len)
153
* @offset: Cluster offset in bytes
154
* @len: Length in bytes
155
*/
156
-static int qed_aio_write_data(void *opaque, int ret,
157
- uint64_t offset, size_t len)
158
+static int coroutine_fn qed_aio_write_data(void *opaque, int ret,
159
+ uint64_t offset, size_t len)
160
{
161
QEDAIOCB *acb = opaque;
162
163
@@ -XXX,XX +XXX,XX @@ static int qed_aio_write_data(void *opaque, int ret,
164
* @offset: Cluster offset in bytes
165
* @len: Length in bytes
166
*/
167
-static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
168
+static int coroutine_fn qed_aio_read_data(void *opaque, int ret,
169
+ uint64_t offset, size_t len)
170
{
171
QEDAIOCB *acb = opaque;
172
BDRVQEDState *s = acb_to_s(acb);
173
@@ -XXX,XX +XXX,XX @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len)
174
/**
175
* Begin next I/O or complete the request
176
*/
177
-static int qed_aio_next_io(QEDAIOCB *acb)
178
+static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb)
179
{
180
BDRVQEDState *s = acb_to_s(acb);
181
uint64_t offset;
182
diff --git a/block/qed.h b/block/qed.h
183
index XXXXXXX..XXXXXXX 100644
184
--- a/block/qed.h
185
+++ b/block/qed.h
186
@@ -XXX,XX +XXX,XX @@ int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
187
/**
188
* Cluster functions
189
*/
190
-int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
191
- size_t *len, uint64_t *img_offset);
192
+int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request,
193
+ uint64_t pos, size_t *len,
194
+ uint64_t *img_offset);
195
196
/**
197
* Consistency check
198
--
199
1.8.3.1
200
201
diff view generated by jsdifflib
Deleted patch
1
All functions that are marked coroutine_fn can directly call the
2
bdrv_co_* version of functions instead of going through the wrapper.
3
1
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
---
8
block/qed.c | 16 +++++++++-------
9
1 file changed, 9 insertions(+), 7 deletions(-)
10
11
diff --git a/block/qed.c b/block/qed.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/block/qed.c
14
+++ b/block/qed.c
15
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_write_header(BDRVQEDState *s)
16
};
17
qemu_iovec_init_external(&qiov, &iov, 1);
18
19
- ret = bdrv_preadv(s->bs->file, 0, &qiov);
20
+ ret = bdrv_co_preadv(s->bs->file, 0, qiov.size, &qiov, 0);
21
if (ret < 0) {
22
goto out;
23
}
24
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_write_header(BDRVQEDState *s)
25
/* Update header */
26
qed_header_cpu_to_le(&s->header, (QEDHeader *) buf);
27
28
- ret = bdrv_pwritev(s->bs->file, 0, &qiov);
29
+ ret = bdrv_co_pwritev(s->bs->file, 0, qiov.size, &qiov, 0);
30
if (ret < 0) {
31
goto out;
32
}
33
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
34
qemu_iovec_concat(*backing_qiov, qiov, 0, size);
35
36
BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
37
- ret = bdrv_preadv(s->bs->backing, pos, *backing_qiov);
38
+ ret = bdrv_co_preadv(s->bs->backing, pos, size, *backing_qiov, 0);
39
if (ret < 0) {
40
return ret;
41
}
42
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
43
}
44
45
BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE);
46
- ret = bdrv_pwritev(s->bs->file, offset, &qiov);
47
+ ret = bdrv_co_pwritev(s->bs->file, offset, qiov.size, &qiov, 0);
48
if (ret < 0) {
49
goto out;
50
}
51
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb)
52
trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size);
53
54
BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
55
- ret = bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov);
56
+ ret = bdrv_co_pwritev(s->bs->file, offset, acb->cur_qiov.size,
57
+ &acb->cur_qiov, 0);
58
if (ret < 0) {
59
return ret;
60
}
61
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb)
62
* region. The solution is to flush after writing a new data
63
* cluster and before updating the L2 table.
64
*/
65
- ret = bdrv_flush(s->bs->file->bs);
66
+ ret = bdrv_co_flush(s->bs->file->bs);
67
if (ret < 0) {
68
return ret;
69
}
70
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qed_aio_read_data(void *opaque, int ret,
71
}
72
73
BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
74
- ret = bdrv_preadv(bs->file, offset, &acb->cur_qiov);
75
+ ret = bdrv_co_preadv(bs->file, offset, acb->cur_qiov.size,
76
+ &acb->cur_qiov, 0);
77
if (ret < 0) {
78
return ret;
79
}
80
--
81
1.8.3.1
82
83
diff view generated by jsdifflib
Deleted patch
1
From: "sochin.jiang" <sochin.jiang@huawei.com>
2
1
3
img_commit could fall into an infinite loop calling run_block_job() if
4
its blockjob fails on any I/O error, fix this already known problem.
5
6
Signed-off-by: sochin.jiang <sochin.jiang@huawei.com>
7
Message-id: 1497509253-28941-1-git-send-email-sochin.jiang@huawei.com
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
10
blockjob.c | 4 ++--
11
include/block/blockjob.h | 18 ++++++++++++++++++
12
qemu-img.c | 20 +++++++++++++-------
13
3 files changed, 33 insertions(+), 9 deletions(-)
14
15
diff --git a/blockjob.c b/blockjob.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/blockjob.c
18
+++ b/blockjob.c
19
@@ -XXX,XX +XXX,XX @@ static void block_job_resume(BlockJob *job)
20
block_job_enter(job);
21
}
22
23
-static void block_job_ref(BlockJob *job)
24
+void block_job_ref(BlockJob *job)
25
{
26
++job->refcnt;
27
}
28
@@ -XXX,XX +XXX,XX @@ static void block_job_attached_aio_context(AioContext *new_context,
29
void *opaque);
30
static void block_job_detach_aio_context(void *opaque);
31
32
-static void block_job_unref(BlockJob *job)
33
+void block_job_unref(BlockJob *job)
34
{
35
if (--job->refcnt == 0) {
36
BlockDriverState *bs = blk_bs(job->blk);
37
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
38
index XXXXXXX..XXXXXXX 100644
39
--- a/include/block/blockjob.h
40
+++ b/include/block/blockjob.h
41
@@ -XXX,XX +XXX,XX @@ void block_job_iostatus_reset(BlockJob *job);
42
BlockJobTxn *block_job_txn_new(void);
43
44
/**
45
+ * block_job_ref:
46
+ *
47
+ * Add a reference to BlockJob refcnt, it will be decreased with
48
+ * block_job_unref, and then be freed if it comes to be the last
49
+ * reference.
50
+ */
51
+void block_job_ref(BlockJob *job);
52
+
53
+/**
54
+ * block_job_unref:
55
+ *
56
+ * Release a reference that was previously acquired with block_job_ref
57
+ * or block_job_create. If it's the last reference to the object, it will be
58
+ * freed.
59
+ */
60
+void block_job_unref(BlockJob *job);
61
+
62
+/**
63
* block_job_txn_unref:
64
*
65
* Release a reference that was previously acquired with block_job_txn_add_job
66
diff --git a/qemu-img.c b/qemu-img.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/qemu-img.c
69
+++ b/qemu-img.c
70
@@ -XXX,XX +XXX,XX @@ static void common_block_job_cb(void *opaque, int ret)
71
static void run_block_job(BlockJob *job, Error **errp)
72
{
73
AioContext *aio_context = blk_get_aio_context(job->blk);
74
+ int ret = 0;
75
76
- /* FIXME In error cases, the job simply goes away and we access a dangling
77
- * pointer below. */
78
aio_context_acquire(aio_context);
79
+ block_job_ref(job);
80
do {
81
aio_poll(aio_context, true);
82
qemu_progress_print(job->len ?
83
((float)job->offset / job->len * 100.f) : 0.0f, 0);
84
- } while (!job->ready);
85
+ } while (!job->ready && !job->completed);
86
87
- block_job_complete_sync(job, errp);
88
+ if (!job->completed) {
89
+ ret = block_job_complete_sync(job, errp);
90
+ } else {
91
+ ret = job->ret;
92
+ }
93
+ block_job_unref(job);
94
aio_context_release(aio_context);
95
96
- /* A block job may finish instantaneously without publishing any progress,
97
- * so just signal completion here */
98
- qemu_progress_print(100.f, 0);
99
+ /* publish completion progress only when success */
100
+ if (!ret) {
101
+ qemu_progress_print(100.f, 0);
102
+ }
103
}
104
105
static int img_commit(int argc, char **argv)
106
--
107
1.8.3.1
108
109
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
The bs->exact_filename field may not be sufficient to store the full
4
blkdebug node filename. In this case, we should not generate a filename
5
at all instead of an unusable one.
6
7
Cc: qemu-stable@nongnu.org
8
Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Message-id: 20170613172006.19685-2-mreitz@redhat.com
11
Reviewed-by: Alberto Garcia <berto@igalia.com>
12
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
15
block/blkdebug.c | 10 +++++++---
16
1 file changed, 7 insertions(+), 3 deletions(-)
17
18
diff --git a/block/blkdebug.c b/block/blkdebug.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/blkdebug.c
21
+++ b/block/blkdebug.c
22
@@ -XXX,XX +XXX,XX @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
23
}
24
25
if (!force_json && bs->file->bs->exact_filename[0]) {
26
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
27
- "blkdebug:%s:%s", s->config_file ?: "",
28
- bs->file->bs->exact_filename);
29
+ int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
30
+ "blkdebug:%s:%s", s->config_file ?: "",
31
+ bs->file->bs->exact_filename);
32
+ if (ret >= sizeof(bs->exact_filename)) {
33
+ /* An overflow makes the filename unusable, so do not report any */
34
+ bs->exact_filename[0] = 0;
35
+ }
36
}
37
38
opts = qdict_new();
39
--
40
1.8.3.1
41
42
diff view generated by jsdifflib